Skip to content

Commit

Permalink
Merge branch 'beta' into milestone/v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Apr 12, 2024
2 parents 81fc03f + 823176f commit 3a78661
Show file tree
Hide file tree
Showing 33 changed files with 3,036 additions and 508 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Release
on:
push:
branches: [ main, beta ]
branches: [ main, beta, prerelease ]
pull_request:
branches: [ main ]
jobs:
Expand Down
3 changes: 2 additions & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"branches": [
{ "name": "main", "channel": "latest" },
"+([0-9])?(.{+([0-9]),x}).x",
{ "name": "beta", "prerelease": true }
{ "name": "beta", "prerelease": true },
{ "name": "prerelease", "prerelease": "rc" }
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down
18 changes: 13 additions & 5 deletions gen/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ const generateResource = (type: string, name: string, resource: Resource): strin
res = res.replace(/##__IMPORT_RESOURCE_COMMON__##/, Array.from(declaredImportsCommon).join(', '))
res = res.replace(/##__MODEL_SORTABLE_INTERFACE__##/, (resModelType === 'ApiSingleton') ? '' : `, ${resModelInterface}Sort`)

const importQueryModels = (qryMod.size > 0)? `import type { ${Array.from(qryMod).sort().reverse().join(', ')} } from '../query'` : ''
const importQueryModels = (qryMod.size > 0) ? `import type { ${Array.from(qryMod).sort().reverse().join(', ')} } from '../query'` : ''
res = res.replace(/##__IMPORT_QUERY_MODELS__##/, importQueryModels)


Expand All @@ -720,6 +720,7 @@ const generateResource = (type: string, name: string, resource: Resource): strin
const relationshipTypes: Set<string> = new Set()
const sortableFields: string[] = []
const filterableFields: string[] = []
let nullables = false

typesArray.forEach(t => {
const cudSuffix = getCUDSuffix(t)
Expand All @@ -733,6 +734,7 @@ const generateResource = (type: string, name: string, resource: Resource): strin
sortableFields.push('id', ...Object.values(component.attributes).filter(f => (f.sortable && !RESOURCE_COMMON_FIELDS.includes(f.name))).map(f => f.name))
filterableFields.push('id', ...Object.values(component.attributes).filter(f => (f.filterable && !RESOURCE_COMMON_FIELDS.includes(f.name))).map(f => f.name))
}
nullables ||= tplCmp.nullables
})
res = res.replace(/##__MODEL_INTERFACES__##/g, modelInterfaces.join('\n\n\n'))
res = res.replace(/##__IMPORT_RESOURCE_INTERFACES__##/g, resourceInterfaces.join(', '))
Expand All @@ -757,6 +759,10 @@ const generateResource = (type: string, name: string, resource: Resource): strin

// Enum types definitions

// Nullable type import
console.log(type + ' - ' + nullables)
if (!nullables) res = res.replace(/import type { Nullable/, '// import type { Nullable')


return res

Expand Down Expand Up @@ -876,7 +882,7 @@ const nullable = (type: string): string => {

type ComponentEnums = { [key: string]: string }

const templatedComponent = (res: string, name: string, cmp: Component): { component: string, models: string[], enums: ComponentEnums } => {
const templatedComponent = (res: string, name: string, cmp: Component): { component: string, models: string[], enums: ComponentEnums, nullables: boolean } => {

const cudModel = isCUDModel(name)

Expand All @@ -886,13 +892,15 @@ const templatedComponent = (res: string, name: string, cmp: Component): { compon
// Attributes
const attributes = Object.values(cmp.attributes)
const fields: string[] = []
let nullables = false
attributes.forEach(a => {
if (!RESOURCE_COMMON_FIELDS.includes(a.name)) {
if (cudModel || a.fetchable) {
let attrType = fixAttributeType(a)
if (a.enum) enums[a.name] = attrType
// fields.push('/**\n* Unique identifier for the resource (hash).\n* @example ```"XAyRWNUzyN"```\n*/')
if (a.description || a.example) fields.push(`/** ${a.description? `\n\t * ${a.description}.` : ''}${a.example? `\n\t * @example \`\`\`"${(typeof a.example === 'object')? JSON.stringify(a.example) : a.example}"\`\`\``: ''}\n\t */`)
fields.push(`${a.name}${a.required ? '' : '?'}: ${a.required ? attrType : nullable(attrType)}`)
nullables ||= (!a.required && !RESOURCE_COMMON_FIELDS.includes(a.name))
}
}
})
Expand Down Expand Up @@ -931,6 +939,7 @@ const templatedComponent = (res: string, name: string, cmp: Component): { compon
}

rels.push(`${r.name}${r.required ? '' : '?'}: ${r.required ? resName : nullable(resName)}`)
nullables ||= !r.required

}
})
Expand All @@ -946,8 +955,7 @@ const templatedComponent = (res: string, name: string, cmp: Component): { compon
component = component.replace(/##__RESOURCE_MODEL_FIELDS__##/g, fieldsStr)
component = component.replace(/##__RESOURCE_MODEL_RELATIONSHIPS__##/g, relsStr)


return { component, models, enums }
return { component, models, enums, nullables }

}

Expand Down
130 changes: 0 additions & 130 deletions gen/resources copy.json

This file was deleted.

Loading

0 comments on commit 3a78661

Please sign in to comment.