@pylo/node 0.0.7 → 0.0.8
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/cli.js +55 -4
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -76,6 +76,11 @@ query PyloSchemaFetch($pagination: PaginationInput) {
|
|
|
76
76
|
name
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
entity_field_enum_values {
|
|
80
|
+
data {
|
|
81
|
+
value
|
|
82
|
+
}
|
|
83
|
+
}
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
entity_relations {
|
|
@@ -185,14 +190,30 @@ function getMutationSuffixes(relType) {
|
|
|
185
190
|
function toEntityKey(pascalName) {
|
|
186
191
|
return pascalName.charAt(0).toLowerCase() + pascalName.slice(1);
|
|
187
192
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
193
|
+
function toPascalCase(snake) {
|
|
194
|
+
return snake.split("_").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
195
|
+
}
|
|
196
|
+
function analyzeField(field, entityPascalName) {
|
|
197
|
+
var _a, _b, _c, _d;
|
|
190
198
|
const hasVariants = ((_b = (_a = field.variant_entity_field) == null ? void 0 : _a.data) == null ? void 0 : _b.name) != null;
|
|
199
|
+
const enumValues = (_d = (_c = field.entity_field_enum_values) == null ? void 0 : _c.data) != null ? _d : [];
|
|
200
|
+
if (enumValues.length > 0) {
|
|
201
|
+
const typeName = `${entityPascalName}${toPascalCase(field.name)}`;
|
|
202
|
+
const values = enumValues.map((v) => v.value);
|
|
203
|
+
return {
|
|
204
|
+
name: field.name,
|
|
205
|
+
tsType: typeName,
|
|
206
|
+
nullable: isNullable(field),
|
|
207
|
+
variantFieldName: hasVariants ? `${field.name}_variants` : null,
|
|
208
|
+
enum: { typeName, values }
|
|
209
|
+
};
|
|
210
|
+
}
|
|
191
211
|
return {
|
|
192
212
|
name: field.name,
|
|
193
213
|
tsType: mapDataType(field.data_type),
|
|
194
214
|
nullable: isNullable(field),
|
|
195
|
-
variantFieldName: hasVariants ? `${field.name}_variants` : null
|
|
215
|
+
variantFieldName: hasVariants ? `${field.name}_variants` : null,
|
|
216
|
+
enum: null
|
|
196
217
|
};
|
|
197
218
|
}
|
|
198
219
|
function analyzeRelation(relation) {
|
|
@@ -224,7 +245,9 @@ function analyzeReverseRelation(relation) {
|
|
|
224
245
|
function analyzeEntities(rawEntities) {
|
|
225
246
|
return rawEntities.map((entity) => {
|
|
226
247
|
var _a, _b, _c, _d, _e, _f;
|
|
227
|
-
const fields = ((_b = (_a = entity.entity_fields) == null ? void 0 : _a.data) != null ? _b : []).map(
|
|
248
|
+
const fields = ((_b = (_a = entity.entity_fields) == null ? void 0 : _a.data) != null ? _b : []).map(
|
|
249
|
+
(f) => analyzeField(f, entity.name)
|
|
250
|
+
);
|
|
228
251
|
const forwardRelations = ((_d = (_c = entity.entity_relations) == null ? void 0 : _c.data) != null ? _d : []).map(analyzeRelation).filter((r) => r !== null);
|
|
229
252
|
const reverseRelations = ((_f = (_e = entity.entity_related) == null ? void 0 : _e.data) != null ? _f : []).map(analyzeReverseRelation).filter((r) => r !== null);
|
|
230
253
|
const seen = new Set(forwardRelations.map((r) => r.fieldName));
|
|
@@ -313,6 +336,17 @@ function generateUpdateInputType(entity) {
|
|
|
313
336
|
}
|
|
314
337
|
return lines.join("\n");
|
|
315
338
|
}
|
|
339
|
+
function collectEnumTypes(entities) {
|
|
340
|
+
const seen = /* @__PURE__ */ new Map();
|
|
341
|
+
for (const entity of entities) {
|
|
342
|
+
for (const field of entity.fields) {
|
|
343
|
+
if (field.enum && !seen.has(field.enum.typeName)) {
|
|
344
|
+
seen.set(field.enum.typeName, field.enum.values);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return Array.from(seen, ([typeName, values]) => ({ typeName, values }));
|
|
349
|
+
}
|
|
316
350
|
function generateIndexFile(entities, importSource) {
|
|
317
351
|
const lines = [];
|
|
318
352
|
lines.push(
|
|
@@ -333,6 +367,14 @@ function generateIndexFile(entities, importSource) {
|
|
|
333
367
|
`} from '${importSource}';`,
|
|
334
368
|
""
|
|
335
369
|
);
|
|
370
|
+
const enumTypes = collectEnumTypes(entities);
|
|
371
|
+
if (enumTypes.length > 0) {
|
|
372
|
+
for (const { typeName, values } of enumTypes) {
|
|
373
|
+
const union = values.map((v) => `'${v}'`).join(" | ");
|
|
374
|
+
lines.push(`export type ${typeName} = ${union};`);
|
|
375
|
+
}
|
|
376
|
+
lines.push("");
|
|
377
|
+
}
|
|
336
378
|
for (const entity of entities) {
|
|
337
379
|
lines.push(`export interface Create${entity.pascalName}Input {`);
|
|
338
380
|
lines.push(indent(generateCreateInputType(entity), 1));
|
|
@@ -408,6 +450,15 @@ function generateSchemaMetadataFile(entities, unknownFieldBehavior, importSource
|
|
|
408
450
|
const variantNamesStr = variantNames.map((n) => `'${n}'`).join(", ");
|
|
409
451
|
lines.push(` variantFieldNames: [${variantNamesStr}],`);
|
|
410
452
|
}
|
|
453
|
+
const enumFields = entity.fields.filter((f) => f.enum !== null);
|
|
454
|
+
if (enumFields.length > 0) {
|
|
455
|
+
lines.push(" enumFields: {");
|
|
456
|
+
for (const f of enumFields) {
|
|
457
|
+
const vals = f.enum.values.map((v) => `'${v}'`).join(", ");
|
|
458
|
+
lines.push(` ${f.name}: [${vals}],`);
|
|
459
|
+
}
|
|
460
|
+
lines.push(" },");
|
|
461
|
+
}
|
|
411
462
|
lines.push(" relations: {");
|
|
412
463
|
for (const rel of entity.relations) {
|
|
413
464
|
lines.push(
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pylo/node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Server-side Pylo SDK with API key authentication",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@types/node": "^22.15.21",
|
|
29
29
|
"tsup": "^8.5.1",
|
|
30
30
|
"typescript": "^5.9.3",
|
|
31
|
-
"@pylo/core": "0.0.
|
|
31
|
+
"@pylo/core": "0.0.10",
|
|
32
32
|
"@pylo/auth": "0.0.4"
|
|
33
33
|
},
|
|
34
34
|
"license": "ISC",
|