@postxl/schema 2.3.0 → 2.5.0
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/enum/enum.brands.d.ts +3 -3
- package/dist/enum/enum.d.ts +2 -2
- package/dist/enum/enum.defaults.d.ts +8 -8
- package/dist/enum/enum.transformer.d.ts +4 -4
- package/dist/field/enum.d.ts +14 -5
- package/dist/field/enum.js +23 -0
- package/dist/field/field.d.ts +38 -29
- package/dist/field/id.d.ts +14 -12
- package/dist/field/id.js +3 -0
- package/dist/field/json.d.ts +4 -1
- package/dist/field/json.js +2 -0
- package/dist/field/relation.d.ts +11 -9
- package/dist/field/relation.js +2 -0
- package/dist/field/scalar.d.ts +5 -2
- package/dist/field/scalar.js +2 -0
- package/dist/field/shared/brands.d.ts +11 -11
- package/dist/field/shared/decoders.d.ts +1 -0
- package/dist/field/shared/decoders.js +6 -1
- package/dist/field/shared/types.d.ts +10 -0
- package/dist/model/model.brands.d.ts +2 -2
- package/dist/model/model.json-decoder.d.ts +12 -8
- package/dist/model/model.json-decoder.js +21 -0
- package/dist/model/model.transformer.d.ts +88 -72
- package/dist/model/model.transformer.js +13 -1
- package/dist/model/model.types.d.ts +17 -0
- package/dist/project-schema/project-schema.brands.d.ts +3 -3
- package/dist/project-schema/project-schema.defaults.d.ts +1 -1
- package/dist/project-schema/project-schema.json-decoder.d.ts +9 -4
- package/dist/project-schema/project-schema.json-decoder.js +5 -0
- package/dist/project-schema/project-schema.transformer.d.ts +21 -11
- package/dist/project-schema/project-schema.transformer.js +73 -2
- package/dist/samples/sample-schemas.d.ts +5947 -853
- package/dist/samples/sample-schemas.js +4 -0
- package/dist/samples/skaile-platform.schema.json +5362 -639
- package/dist/samples/skaile-store.schema.json +1077 -0
- package/dist/samples/titans-prototype.schema.json +1978 -0
- package/package.json +2 -2
|
@@ -95,6 +95,7 @@ function addDefaults(input) {
|
|
|
95
95
|
schemas,
|
|
96
96
|
schemaAuth,
|
|
97
97
|
defaultSchema,
|
|
98
|
+
defaultLabelSeparator: input.defaultLabelSeparator,
|
|
98
99
|
...(input.auth ? { auth: input.auth } : {}),
|
|
99
100
|
systemUser: {
|
|
100
101
|
...project_schema_defaults_1.defaultSystemUser,
|
|
@@ -287,7 +288,11 @@ function transformModels(projectSchema, ctx) {
|
|
|
287
288
|
const model = transformModel(inputModel, projectSchema, ctx);
|
|
288
289
|
models.set(model.name, model);
|
|
289
290
|
}
|
|
290
|
-
|
|
291
|
+
validateLabelQualifierCycles(models, ctx);
|
|
292
|
+
// `defaultLabelSeparator` is only a fallback consulted while resolving each model's
|
|
293
|
+
// `labelQualifier.separator` above; it is fully resolved by this point and must not leak
|
|
294
|
+
// into the output (consumers never re-resolve it against project defaults).
|
|
295
|
+
const { auth, defaultLabelSeparator: _defaultLabelSeparatorInput, ...remainingProjectSchema } = projectSchema;
|
|
291
296
|
// Keep optional field shape clean: only include `auth` when it is actually set,
|
|
292
297
|
// instead of returning `auth: undefined`.
|
|
293
298
|
return auth
|
|
@@ -301,15 +306,47 @@ function transformModels(projectSchema, ctx) {
|
|
|
301
306
|
models,
|
|
302
307
|
};
|
|
303
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Rejects circular label-qualifier chains (e.g. Session qualified by Project qualified by
|
|
311
|
+
* Session), which would otherwise recurse forever when the view services resolve display
|
|
312
|
+
* labels. Each distinct cycle is reported once, however many models enter it.
|
|
313
|
+
*/
|
|
314
|
+
function validateLabelQualifierCycles(models, ctx) {
|
|
315
|
+
const reported = new Set();
|
|
316
|
+
for (const startName of models.keys()) {
|
|
317
|
+
const path = [];
|
|
318
|
+
let current = startName;
|
|
319
|
+
while (current !== undefined && !path.includes(current)) {
|
|
320
|
+
path.push(current);
|
|
321
|
+
current = models.get(current)?.labelQualifier?.referencedModelName;
|
|
322
|
+
}
|
|
323
|
+
if (current === undefined) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const cycle = path.slice(path.indexOf(current));
|
|
327
|
+
// Sorted only to canonicalise the key, so the same cycle reported from a different starting
|
|
328
|
+
// model dedupes against itself. An explicit comparator keeps the order locale-independent.
|
|
329
|
+
const key = [...cycle].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)).join('|');
|
|
330
|
+
if (reported.has(key)) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
reported.add(key);
|
|
334
|
+
ctx.addIssue({
|
|
335
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
336
|
+
message: `Label qualifier cycle detected: ${[...cycle, current].join(' → ')}. A model's label qualifier chain must not be circular.`,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
304
340
|
function transformModel(model, projectSchema, ctx) {
|
|
305
341
|
const fields = transformFields(model, projectSchema, ctx);
|
|
306
342
|
validateFields(fields, ctx);
|
|
307
343
|
const idField = extractIdField(fields, model, ctx);
|
|
308
344
|
const defaultField = extractDefaultField(model, fields, ctx);
|
|
309
345
|
const labelField = extractLabelField(model, fields, ctx);
|
|
346
|
+
const labelQualifier = extractLabelQualifier(model, fields, projectSchema.defaultLabelSeparator ?? ' – ', ctx);
|
|
310
347
|
const keyField = extractKeyField(model, fields, idField, ctx);
|
|
311
348
|
const defaultSort = extractDefaultSort(model, fields, ctx);
|
|
312
|
-
const { defaultFieldName, labelFieldName, keyFieldName, auth, ...remainingModel } = model;
|
|
349
|
+
const { defaultFieldName, labelFieldName, keyFieldName, labelQualifier: _labelQualifierInput, auth, ...remainingModel } = model;
|
|
313
350
|
return {
|
|
314
351
|
...remainingModel,
|
|
315
352
|
...(auth ? { auth } : {}),
|
|
@@ -317,6 +354,7 @@ function transformModel(model, projectSchema, ctx) {
|
|
|
317
354
|
fields,
|
|
318
355
|
defaultField,
|
|
319
356
|
labelField,
|
|
357
|
+
labelQualifier,
|
|
320
358
|
keyField,
|
|
321
359
|
defaultSort,
|
|
322
360
|
idField,
|
|
@@ -471,6 +509,39 @@ function extractLabelField({ labelFieldName, ...model }, fields, ctx) {
|
|
|
471
509
|
}
|
|
472
510
|
return labelField;
|
|
473
511
|
}
|
|
512
|
+
function extractLabelQualifier(model, fields, defaultLabelSeparator, ctx) {
|
|
513
|
+
const { labelQualifier } = model;
|
|
514
|
+
if (labelQualifier === undefined) {
|
|
515
|
+
return undefined;
|
|
516
|
+
}
|
|
517
|
+
const field = fields.get(labelQualifier.relationFieldName);
|
|
518
|
+
if (field === undefined) {
|
|
519
|
+
ctx.addIssue({
|
|
520
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
521
|
+
message: `Label qualifier ${labelQualifier.relationFieldName} is not defined in model ${model.name}!`,
|
|
522
|
+
});
|
|
523
|
+
return zod_1.z.NEVER;
|
|
524
|
+
}
|
|
525
|
+
if (field.kind !== 'relation') {
|
|
526
|
+
ctx.addIssue({
|
|
527
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
528
|
+
message: `Label qualifier ${labelQualifier.relationFieldName} in model ${model.name} must be a relation field, but is of type \`${Field.getFieldType(field)}\`.`,
|
|
529
|
+
});
|
|
530
|
+
return zod_1.z.NEVER;
|
|
531
|
+
}
|
|
532
|
+
if (field.referencedModelName === model.name) {
|
|
533
|
+
ctx.addIssue({
|
|
534
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
535
|
+
message: `Label qualifier ${labelQualifier.relationFieldName} in model ${model.name} is a self-relation. Hierarchical labels are not supported.`,
|
|
536
|
+
});
|
|
537
|
+
return zod_1.z.NEVER;
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
relationField: field,
|
|
541
|
+
referencedModelName: field.referencedModelName,
|
|
542
|
+
separator: labelQualifier.separator ?? defaultLabelSeparator,
|
|
543
|
+
};
|
|
544
|
+
}
|
|
474
545
|
function extractLabelFieldFromNameOrIdField({ name }, fields, ctx) {
|
|
475
546
|
// If no label field is provided, try name field first, then label field, then id field
|
|
476
547
|
const fallbackField = fields.get(Field.standardFieldName_name) ??
|