@eide/foir-cli 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen/fetch-models.d.ts +14 -0
- package/dist/codegen/fetch-models.d.ts.map +1 -1
- package/dist/codegen/fetch-models.js +42 -1
- package/dist/codegen/field-mapping.d.ts.map +1 -1
- package/dist/codegen/field-mapping.js +4 -10
- package/dist/codegen/generators/model-types.js +3 -5
- package/dist/codegen/swift-field-mapping.d.ts.map +1 -1
- package/dist/codegen/swift-field-mapping.js +0 -6
- package/package.json +1 -1
|
@@ -33,6 +33,20 @@ export interface CodegenModel {
|
|
|
33
33
|
config: CodegenModelConfig;
|
|
34
34
|
hooks?: Record<string, unknown>;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalize a field's item type reference into `options.itemType`.
|
|
38
|
+
*
|
|
39
|
+
* The platform stores the reference in different locations depending on
|
|
40
|
+
* how the field was created:
|
|
41
|
+
* - `options.itemType` (standard)
|
|
42
|
+
* - `config.itemType` (config variant)
|
|
43
|
+
* - `config.itemSchema` (inline model schema reference)
|
|
44
|
+
* - top-level `itemType` (inline model field definitions)
|
|
45
|
+
*
|
|
46
|
+
* We consolidate into `options.itemType` so downstream codegen has a
|
|
47
|
+
* single location to check.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizeField(raw: Record<string, unknown>): FieldSchemaForGen;
|
|
36
50
|
export declare function fetchModelsForCodegen(client: GraphQLClient): Promise<CodegenModel[]>;
|
|
37
51
|
/**
|
|
38
52
|
* Filter models based on pull config options.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-models.d.ts","sourceRoot":"","sources":["../../src/codegen/fetch-models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;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
|
|
|
20
20
|
embeddings: raw.embeddings,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Normalize a field's item type reference into `options.itemType`.
|
|
25
|
+
*
|
|
26
|
+
* The platform stores the reference in different locations depending on
|
|
27
|
+
* how the field was created:
|
|
28
|
+
* - `options.itemType` (standard)
|
|
29
|
+
* - `config.itemType` (config variant)
|
|
30
|
+
* - `config.itemSchema` (inline model schema reference)
|
|
31
|
+
* - top-level `itemType` (inline model field definitions)
|
|
32
|
+
*
|
|
33
|
+
* We consolidate into `options.itemType` so downstream codegen has a
|
|
34
|
+
* single location to check.
|
|
35
|
+
*/
|
|
36
|
+
export function normalizeField(raw) {
|
|
37
|
+
const field = raw;
|
|
38
|
+
const options = { ...(field.options ?? {}) };
|
|
39
|
+
// Resolve itemType from all possible locations (first wins)
|
|
40
|
+
if (!options.itemType) {
|
|
41
|
+
const resolved = field.itemType ??
|
|
42
|
+
field.config?.itemType ??
|
|
43
|
+
field.config?.itemSchema;
|
|
44
|
+
if (resolved) {
|
|
45
|
+
options.itemType = resolved;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Carry over minItems/maxItems from config
|
|
49
|
+
if (field.config?.minItems !== undefined && options.minItems === undefined) {
|
|
50
|
+
options.minItems = field.config.minItems;
|
|
51
|
+
}
|
|
52
|
+
if (field.config?.maxItems !== undefined && options.maxItems === undefined) {
|
|
53
|
+
options.maxItems = field.config.maxItems;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
key: field.key,
|
|
57
|
+
type: field.type,
|
|
58
|
+
label: field.label,
|
|
59
|
+
required: field.required,
|
|
60
|
+
helpText: field.helpText,
|
|
61
|
+
options: Object.keys(options).length > 0 ? options : undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
23
64
|
export async function fetchModelsForCodegen(client) {
|
|
24
65
|
const data = await client.request(MODELS_FOR_CODEGEN, {
|
|
25
66
|
limit: 500,
|
|
@@ -30,7 +71,7 @@ export async function fetchModelsForCodegen(client) {
|
|
|
30
71
|
pluralName: item.pluralName,
|
|
31
72
|
description: item.description,
|
|
32
73
|
category: item.category,
|
|
33
|
-
fields: item.fields ?? [],
|
|
74
|
+
fields: (item.fields ?? []).map((f) => normalizeField(f)),
|
|
34
75
|
config: normalizeConfig(item.config ?? {}),
|
|
35
76
|
hooks: item.hooks,
|
|
36
77
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/field-mapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/field-mapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,aAqBhC,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAyD1D,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,iBAAiB,EACxB,IAAI,GAAE,QAAQ,GAAG,OAAkB,GAClC,MAAM,CAqCR;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAY3E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,iBAAiB,EAAE,GAC1B,GAAG,CAAC,MAAM,CAAC,CAcb;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CA8EjE"}
|
|
@@ -19,7 +19,6 @@ export const PRIMITIVE_FIELD_TYPES = new Set([
|
|
|
19
19
|
'multiselect',
|
|
20
20
|
'json',
|
|
21
21
|
'list',
|
|
22
|
-
'tree',
|
|
23
22
|
'entity-reference',
|
|
24
23
|
'reference',
|
|
25
24
|
'link',
|
|
@@ -65,7 +64,6 @@ export const FIELD_TYPE_MAPPING = {
|
|
|
65
64
|
multiselect: { outputType: 'string[]', inputType: 'string[]' },
|
|
66
65
|
json: { outputType: 'unknown', inputType: 'unknown' },
|
|
67
66
|
list: { outputType: 'unknown[]', inputType: 'unknown[]' },
|
|
68
|
-
tree: { outputType: 'unknown[]', inputType: 'unknown[]' },
|
|
69
67
|
flexible: {
|
|
70
68
|
outputType: 'FlexibleFieldItem[]',
|
|
71
69
|
inputType: 'FlexibleFieldItem[]',
|
|
@@ -109,8 +107,7 @@ export function getFieldType(field, mode = 'output') {
|
|
|
109
107
|
tsType = `(${options.map((o) => `'${o.value}'`).join(' | ')})[]`;
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
|
-
if (
|
|
113
|
-
field.options?.itemType) {
|
|
110
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
114
111
|
const itemType = field.options.itemType;
|
|
115
112
|
const itemMapping = FIELD_TYPE_MAPPING[itemType];
|
|
116
113
|
if (itemMapping) {
|
|
@@ -128,8 +125,7 @@ export function getRequiredImports(fields) {
|
|
|
128
125
|
const mapping = FIELD_TYPE_MAPPING[field.type];
|
|
129
126
|
if (mapping?.needsImport)
|
|
130
127
|
imports.add(mapping.needsImport);
|
|
131
|
-
if (
|
|
132
|
-
field.options?.itemType) {
|
|
128
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
133
129
|
const itemMapping = FIELD_TYPE_MAPPING[field.options.itemType];
|
|
134
130
|
if (itemMapping?.needsImport)
|
|
135
131
|
imports.add(itemMapping.needsImport);
|
|
@@ -143,8 +139,7 @@ export function getInlineSchemaReferences(fields) {
|
|
|
143
139
|
if (!isPrimitiveFieldType(field.type) && !FIELD_TYPE_MAPPING[field.type]) {
|
|
144
140
|
refs.add(field.type);
|
|
145
141
|
}
|
|
146
|
-
if (
|
|
147
|
-
field.options?.itemType) {
|
|
142
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
148
143
|
const itemType = field.options.itemType;
|
|
149
144
|
if (!isPrimitiveFieldType(itemType) && !FIELD_TYPE_MAPPING[itemType]) {
|
|
150
145
|
refs.add(itemType);
|
|
@@ -223,8 +218,7 @@ export function generateFieldDef(field) {
|
|
|
223
218
|
if (field.options.multiple)
|
|
224
219
|
parts.push('multiple: true');
|
|
225
220
|
}
|
|
226
|
-
if (
|
|
227
|
-
field.options?.itemType) {
|
|
221
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
228
222
|
parts.push(`itemType: '${field.options.itemType}'`);
|
|
229
223
|
if (field.options.minItems !== undefined)
|
|
230
224
|
parts.push(`minItems: ${field.options.minItems}`);
|
|
@@ -118,9 +118,8 @@ function generateDataInterface(model, fields, interfaceName, allModels) {
|
|
|
118
118
|
if (refModel && !isInlineOnlyModel(refModel)) {
|
|
119
119
|
fieldType = toPascalCase(field.type) + 'Data';
|
|
120
120
|
}
|
|
121
|
-
// Handle list
|
|
122
|
-
if (
|
|
123
|
-
field.options?.itemType) {
|
|
121
|
+
// Handle list itemType refs
|
|
122
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
124
123
|
const itemRefModel = allModels.find((m) => m.key === field.options.itemType);
|
|
125
124
|
if (itemRefModel && !isInlineOnlyModel(itemRefModel)) {
|
|
126
125
|
fieldType = toPascalCase(field.options.itemType) + 'Data[]';
|
|
@@ -140,8 +139,7 @@ function getFieldTypeImportsForFields(fields) {
|
|
|
140
139
|
if (mapping?.needsImport === 'field-types') {
|
|
141
140
|
imports.add(mapping.outputType);
|
|
142
141
|
}
|
|
143
|
-
if (
|
|
144
|
-
field.options?.itemType) {
|
|
142
|
+
if (field.type === 'list' && field.options?.itemType) {
|
|
145
143
|
const itemMapping = FIELD_TYPE_MAPPING[field.options.itemType];
|
|
146
144
|
if (itemMapping?.needsImport === 'field-types') {
|
|
147
145
|
imports.add(itemMapping.outputType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swift-field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/swift-field-mapping.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,cAAc,EAAE,OAAO,CAAC;IACxB,gFAAgF;IAChF,YAAY,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,kEAAkE;IAClE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"swift-field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/swift-field-mapping.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,cAAc,EAAE,OAAO,CAAC;IACxB,gFAAgF;IAChF,YAAY,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,kEAAkE;IAClE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA8HrE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACvC,CAeA"}
|
|
@@ -105,12 +105,6 @@ export const SWIFT_FIELD_TYPE_MAPPING = {
|
|
|
105
105
|
defaultValue: '[]',
|
|
106
106
|
castExpression: 'as? [Any]',
|
|
107
107
|
},
|
|
108
|
-
tree: {
|
|
109
|
-
type: '[Any]',
|
|
110
|
-
alwaysOptional: true,
|
|
111
|
-
defaultValue: '[]',
|
|
112
|
-
castExpression: 'as? [Any]',
|
|
113
|
-
},
|
|
114
108
|
flexible: {
|
|
115
109
|
type: '[[String: Any]]',
|
|
116
110
|
alwaysOptional: true,
|