@pylo/node 0.0.7 → 0.0.9

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 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 analyzeField(field) {
189
- var _a, _b;
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(analyzeField);
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
@@ -42,6 +42,7 @@ interface EntityMetadata {
42
42
  pascalName: string;
43
43
  scalarFieldNames: string[];
44
44
  variantFieldNames?: string[];
45
+ enumFields?: Record<string, string[]>;
45
46
  relations: Record<string, {
46
47
  type: "hasOne" | "hasMany";
47
48
  entity: string;
@@ -135,7 +136,10 @@ interface ListResult<T> {
135
136
  interface RequestOptions {
136
137
  headers?: Record<string, string>;
137
138
  }
138
-
139
+ interface MutationRequestOptions extends RequestOptions {
140
+ dryRun?: boolean;
141
+ doNotTriggerFlows?: boolean;
142
+ }
139
143
  declare class PyloError extends Error {
140
144
  graphqlErrors: unknown;
141
145
  constructor(message: string, graphqlErrors?: unknown);
@@ -153,10 +157,10 @@ interface ClientOptions {
153
157
  interface EntityClient<S, E extends EntityName<S>> {
154
158
  list<Sel extends EntitySelect<S, E> | undefined = undefined>(options?: ListOptions<S, E, Sel> & RequestOptions): Promise<ListResult<EntityResult<S, E, Sel>>>;
155
159
  byId<Sel extends EntitySelect<S, E> | undefined = undefined>(id: string, options?: ByIdOptions<S, E, Sel> & RequestOptions): Promise<EntityResult<S, E, Sel> | null>;
156
- upsert(input: UpsertInput<S, E>, options?: RequestOptions): Promise<{
160
+ upsert(input: UpsertInput<S, E>, options?: MutationRequestOptions): Promise<{
157
161
  id: string;
158
162
  }>;
159
- delete(ids: string[], options?: RequestOptions): Promise<{
163
+ delete(ids: string[], options?: MutationRequestOptions): Promise<{
160
164
  success: boolean;
161
165
  }>;
162
166
  }
package/dist/index.js CHANGED
@@ -234,6 +234,15 @@ function buildDeleteMutation(_entityKey, pascalName, ids) {
234
234
  variables: { ids }
235
235
  };
236
236
  }
237
+ var PYLO_DRY_RUN_HEADER = "pylo-dry-run";
238
+ var PYLO_DO_NOT_TRIGGER_FLOWS_HEADER = "pylo-do-not-trigger-flow";
239
+ function flagsToHeaders(flags) {
240
+ if (!flags.dryRun && !flags.doNotTriggerFlows) return void 0;
241
+ const headers = {};
242
+ if (flags.dryRun) headers[PYLO_DRY_RUN_HEADER] = "1";
243
+ if (flags.doNotTriggerFlows) headers[PYLO_DO_NOT_TRIGGER_FLOWS_HEADER] = "1";
244
+ return headers;
245
+ }
237
246
  var PyloError = class extends Error {
238
247
  constructor(message, graphqlErrors) {
239
248
  super(message);
@@ -318,7 +327,10 @@ function createEntityClient(entityKey, endpoint, metadata, auth, globalHeaders)
318
327
  query,
319
328
  variables,
320
329
  auth,
321
- mergeHeaders(globalHeaders, options == null ? void 0 : options.headers)
330
+ mergeHeaders(
331
+ mergeHeaders(globalHeaders, options == null ? void 0 : options.headers),
332
+ flagsToHeaders(options != null ? options : {})
333
+ )
322
334
  );
323
335
  const mutationKey = `update${entityMeta.pascalName}`;
324
336
  const result = data[mutationKey];
@@ -342,7 +354,10 @@ function createEntityClient(entityKey, endpoint, metadata, auth, globalHeaders)
342
354
  query,
343
355
  variables,
344
356
  auth,
345
- mergeHeaders(globalHeaders, options == null ? void 0 : options.headers)
357
+ mergeHeaders(
358
+ mergeHeaders(globalHeaders, options == null ? void 0 : options.headers),
359
+ flagsToHeaders(options != null ? options : {})
360
+ )
346
361
  );
347
362
  const mutationKey = `delete${entityMeta.pascalName}`;
348
363
  const result = data[mutationKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylo/node",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
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.9",
31
+ "@pylo/core": "0.0.11",
32
32
  "@pylo/auth": "0.0.4"
33
33
  },
34
34
  "license": "ISC",