@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zFieldPropertyDefaultValue = exports.zFieldPropertyPlaceholder = exports.zFieldSeed = exports.zScalarValue = exports.zFieldFaker = exports.zFieldPropertyMax = exports.zFieldPropertyMin = exports.zFieldPropertyMaxLength = exports.zFieldPropertyIsUpdatedAt = exports.zFieldPropertyIsCreatedAt = exports.zFieldPropertyHasIndex = exports.zFieldPropertyIsUnique = exports.zFieldPropertyIsReadonly = exports.zFieldPropertyDescription = exports.zFieldPropertyLabel = exports.zFieldPropertyExcelName = exports.zFieldPropertyDatabaseName = exports.zFieldPropertyType = exports.zFieldPropertyName = void 0;
|
|
3
|
+
exports.zFieldPropertyDefaultValue = exports.zFieldPropertyPlaceholder = exports.zFieldSeed = exports.zScalarValue = exports.zFieldFaker = exports.zFieldPropertyMax = exports.zFieldPropertyMin = exports.zFieldPropertyMaxLength = exports.zFieldPropertyIsUpdatedAt = exports.zFieldPropertyIsCreatedAt = exports.zFieldPropertyHasIndex = exports.zFieldPropertyIsUnique = exports.zFieldPropertyIsSystemManaged = exports.zFieldPropertyIsReadonly = exports.zFieldPropertyDescription = exports.zFieldPropertyLabel = exports.zFieldPropertyExcelName = exports.zFieldPropertyDatabaseName = exports.zFieldPropertyType = exports.zFieldPropertyName = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const utils_1 = require("@postxl/utils");
|
|
6
6
|
exports.zFieldPropertyName = zod_1.z
|
|
@@ -46,6 +46,11 @@ exports.zFieldPropertyIsReadonly = zod_1.z
|
|
|
46
46
|
.boolean()
|
|
47
47
|
.optional()
|
|
48
48
|
.describe('If true, the field is readonly, ie. it cannot be changed by the user.');
|
|
49
|
+
exports.zFieldPropertyIsSystemManaged = zod_1.z
|
|
50
|
+
//
|
|
51
|
+
.boolean()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe('If true, the field is owned by the runtime, not the user: it disappears from every human-facing write surface (admin table (bulk) edit, the `updateField`/`updateFieldMany` write unions, the update form, Excel import) but stays in the whole-object `update` decoder so code can still persist it. Use `isReadonly` instead when nothing may write the field after creation.');
|
|
49
54
|
exports.zFieldPropertyIsUnique = zod_1.z
|
|
50
55
|
//
|
|
51
56
|
.boolean()
|
|
@@ -52,6 +52,16 @@ export type FieldCommon<T extends string> = FieldCore<T> & {
|
|
|
52
52
|
* If true, the field is readonly, ie. it cannot be changed by the user.
|
|
53
53
|
*/
|
|
54
54
|
isReadonly: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* If true, the field is owned by the runtime rather than by the user.
|
|
57
|
+
*
|
|
58
|
+
* It is dropped from every human-facing write surface - the admin table is not editable on it,
|
|
59
|
+
* it is not a member of the `updateField` / `updateFieldMany` write unions, the update form does
|
|
60
|
+
* not render it, and an Excel import never produces a delta for it - but, unlike `isReadonly`, it
|
|
61
|
+
* *stays* in the whole-object `update` decoder and in the repository's update statement, so the
|
|
62
|
+
* code that owns it can keep persisting it.
|
|
63
|
+
*/
|
|
64
|
+
isSystemManaged: boolean;
|
|
55
65
|
/**
|
|
56
66
|
* If true, uniqueness is enforced for the field, ie no two items can have the same value for this field.
|
|
57
67
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const zModelName: z.core.$ZodBranded<z.ZodString, "PXL.ModelName", "out">;
|
|
3
3
|
export type ModelName = z.infer<typeof zModelName>;
|
|
4
|
-
export declare const toModelName: (input: string) => string & z
|
|
4
|
+
export declare const toModelName: (input: string) => string & z.$brand<"PXL.ModelName">;
|
|
5
5
|
export declare const zDatabaseModelName: z.core.$ZodBranded<z.ZodString, "PXL.DatabaseModelName", "out">;
|
|
6
6
|
export type DatabaseModelName = z.infer<typeof zDatabaseModelName>;
|
|
7
|
-
export declare const toDatabaseModelName: (input: string) => string & z
|
|
7
|
+
export declare const toDatabaseModelName: (input: string) => string & z.$brand<"PXL.DatabaseModelName">;
|
|
@@ -10,19 +10,19 @@ export declare const zModelNameJSON: z.ZodString;
|
|
|
10
10
|
* `@@index`), with optional `map` to pin the database constraint name.
|
|
11
11
|
*/
|
|
12
12
|
export declare const zModelIndexJSON: z.ZodUnion<readonly [z.ZodPipe<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>, z.ZodTransform<{
|
|
13
|
-
fields: (string & z
|
|
13
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
14
14
|
unique: boolean;
|
|
15
15
|
map: string | undefined;
|
|
16
|
-
}, (string & z
|
|
16
|
+
}, (string & z.$brand<"PXL.FieldName">)[]>>, z.ZodPipe<z.ZodObject<{
|
|
17
17
|
fields: z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>;
|
|
18
18
|
unique: z.ZodOptional<z.ZodBoolean>;
|
|
19
19
|
map: z.ZodOptional<z.ZodString>;
|
|
20
20
|
}, z.core.$strip>, z.ZodTransform<{
|
|
21
|
-
fields: (string & z
|
|
21
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
22
22
|
unique: boolean;
|
|
23
23
|
map: string | undefined;
|
|
24
24
|
}, {
|
|
25
|
-
fields: (string & z
|
|
25
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
26
26
|
unique?: boolean | undefined;
|
|
27
27
|
map?: string | undefined;
|
|
28
28
|
}>>]>;
|
|
@@ -63,22 +63,26 @@ export declare const zModelJSON: z.ZodPreprocess<z.ZodObject<{
|
|
|
63
63
|
standardFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
64
|
defaultField: z.ZodOptional<z.ZodString>;
|
|
65
65
|
labelField: z.ZodOptional<z.ZodString>;
|
|
66
|
+
labelQualifier: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
67
|
+
relation: z.ZodString;
|
|
68
|
+
separator: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, z.core.$strip>]>>;
|
|
66
70
|
keyField: z.ZodOptional<z.ZodString>;
|
|
67
71
|
defaultSort: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>>;
|
|
68
72
|
indexes: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>, z.ZodTransform<{
|
|
69
|
-
fields: (string & z
|
|
73
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
70
74
|
unique: boolean;
|
|
71
75
|
map: string | undefined;
|
|
72
|
-
}, (string & z
|
|
76
|
+
}, (string & z.$brand<"PXL.FieldName">)[]>>, z.ZodPipe<z.ZodObject<{
|
|
73
77
|
fields: z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>;
|
|
74
78
|
unique: z.ZodOptional<z.ZodBoolean>;
|
|
75
79
|
map: z.ZodOptional<z.ZodString>;
|
|
76
80
|
}, z.core.$strip>, z.ZodTransform<{
|
|
77
|
-
fields: (string & z
|
|
81
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
78
82
|
unique: boolean;
|
|
79
83
|
map: string | undefined;
|
|
80
84
|
}, {
|
|
81
|
-
fields: (string & z
|
|
85
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
82
86
|
unique?: boolean | undefined;
|
|
83
87
|
map?: string | undefined;
|
|
84
88
|
}>>]>>>;
|
|
@@ -121,6 +121,27 @@ Example use case: default language, root region in region tree.`),
|
|
|
121
121
|
.string()
|
|
122
122
|
.optional().describe(`The name of the field that is used in the UI as the label of the entity.
|
|
123
123
|
The label field must be a string field. If not provided, the \`name\` field is used as the label.`),
|
|
124
|
+
labelQualifier: zod_1.z
|
|
125
|
+
.union([
|
|
126
|
+
zod_1.z.string(),
|
|
127
|
+
zod_1.z.object({
|
|
128
|
+
relation: zod_1.z.string(),
|
|
129
|
+
separator: zod_1.z.string().optional(),
|
|
130
|
+
}),
|
|
131
|
+
])
|
|
132
|
+
.optional().describe(`Qualifies this model's label with the label of a related parent entity.
|
|
133
|
+
|
|
134
|
+
Use this when a label is only unique *within* a parent — e.g. most projects have a session
|
|
135
|
+
named "main", so a session picker would otherwise show a list of identical entries.
|
|
136
|
+
|
|
137
|
+
Shorthand form names the relation field: "labelQualifier": "projectId"
|
|
138
|
+
Object form additionally sets a separator: { "relation": "projectId", "separator": ": " }
|
|
139
|
+
|
|
140
|
+
The value is the name of a relation field on this model. It must not be a self-relation, and
|
|
141
|
+
the chain of qualifiers across models must not be circular. The parent's own qualified label
|
|
142
|
+
is used, so qualifiers chain transitively.
|
|
143
|
+
|
|
144
|
+
When omitted, the label is just \`labelField\` and nothing about the model's output changes.`),
|
|
124
145
|
keyField: zod_1.z
|
|
125
146
|
//
|
|
126
147
|
.string()
|
|
@@ -1,36 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ModelJSON } from './model.json-decoder';
|
|
3
3
|
export declare function modelJSONTransformer(input: ModelJSON, ctx: z.RefinementCtx): {
|
|
4
|
-
fields: Record<string & z.core.$brand<"PXL.FieldName">, unknown>;
|
|
5
|
-
/**
|
|
6
|
-
* We also provide a list of field names to keep the original order
|
|
7
|
-
*/
|
|
8
|
-
fieldNames: (string & z.core.$brand<"PXL.FieldName">)[];
|
|
9
|
-
name: string & z.core.$brand<"PXL.ModelName">;
|
|
10
|
-
schema: (string & z.core.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
11
|
-
databaseName: string & z.core.$brand<"PXL.DatabaseModelName">;
|
|
12
|
-
defaultFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
13
|
-
labelFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
14
|
-
keyFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
15
|
-
defaultSort: (string & z.core.$brand<"PXL.FieldName">)[] | undefined;
|
|
16
|
-
isReadonly: boolean;
|
|
17
|
-
exposeRestApi: boolean;
|
|
18
|
-
excelName: string;
|
|
19
|
-
description: string;
|
|
20
|
-
indexes: ({
|
|
21
|
-
fields: (string & z.core.$brand<"PXL.FieldName">)[];
|
|
22
|
-
unique: boolean;
|
|
23
|
-
map: string | undefined;
|
|
24
|
-
} | {
|
|
25
|
-
fields: (string & z.core.$brand<"PXL.FieldName">)[];
|
|
26
|
-
unique: boolean;
|
|
27
|
-
map: string | undefined;
|
|
28
|
-
})[];
|
|
29
|
-
seed: any[];
|
|
30
|
-
faker: {
|
|
31
|
-
seed: number;
|
|
32
|
-
items: number;
|
|
33
|
-
};
|
|
34
4
|
auth?: {
|
|
35
5
|
read?: {
|
|
36
6
|
anyRole: string[];
|
|
@@ -55,25 +25,16 @@ export declare function modelJSONTransformer(input: ModelJSON, ctx: z.Refinement
|
|
|
55
25
|
} | undefined;
|
|
56
26
|
} | undefined;
|
|
57
27
|
source?: Record<string, unknown> | undefined;
|
|
58
|
-
};
|
|
59
|
-
export type ModelEnriched = ReturnType<typeof modelJSONTransformer>;
|
|
60
|
-
declare function addDefaults({ description, fields, standardFields, seed, faker, ...input }: ModelJSON): {
|
|
61
28
|
isReadonly: boolean;
|
|
62
29
|
exposeRestApi: boolean;
|
|
63
|
-
databaseName: string;
|
|
64
30
|
excelName: string;
|
|
65
31
|
description: string;
|
|
66
|
-
fields: {
|
|
67
|
-
[x: string]: unknown;
|
|
68
|
-
name: string;
|
|
69
|
-
}[];
|
|
70
|
-
standardFields: string[];
|
|
71
32
|
indexes: ({
|
|
72
|
-
fields: (string & z
|
|
33
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
73
34
|
unique: boolean;
|
|
74
35
|
map: string | undefined;
|
|
75
36
|
} | {
|
|
76
|
-
fields: (string & z
|
|
37
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
77
38
|
unique: boolean;
|
|
78
39
|
map: string | undefined;
|
|
79
40
|
})[];
|
|
@@ -82,6 +43,25 @@ declare function addDefaults({ description, fields, standardFields, seed, faker,
|
|
|
82
43
|
seed: number;
|
|
83
44
|
items: number;
|
|
84
45
|
};
|
|
46
|
+
name: string & z.$brand<"PXL.ModelName">;
|
|
47
|
+
schema: (string & z.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
48
|
+
databaseName: string & z.$brand<"PXL.DatabaseModelName">;
|
|
49
|
+
defaultFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
50
|
+
labelFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
51
|
+
labelQualifier: {
|
|
52
|
+
relationFieldName: string & z.$brand<"PXL.FieldName">;
|
|
53
|
+
separator: string | undefined;
|
|
54
|
+
} | undefined;
|
|
55
|
+
keyFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
56
|
+
defaultSort: (string & z.$brand<"PXL.FieldName">)[] | undefined;
|
|
57
|
+
fields: Record<string & z.$brand<"PXL.FieldName">, unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* We also provide a list of field names to keep the original order
|
|
60
|
+
*/
|
|
61
|
+
fieldNames: (string & z.$brand<"PXL.FieldName">)[];
|
|
62
|
+
};
|
|
63
|
+
export type ModelEnriched = ReturnType<typeof modelJSONTransformer>;
|
|
64
|
+
declare function addDefaults({ description, fields, standardFields, seed, faker, ...input }: ModelJSON): {
|
|
85
65
|
name: string;
|
|
86
66
|
auth?: {
|
|
87
67
|
read?: {
|
|
@@ -110,41 +90,39 @@ declare function addDefaults({ description, fields, standardFields, seed, faker,
|
|
|
110
90
|
defaultField?: string | undefined;
|
|
111
91
|
labelField?: string | undefined;
|
|
112
92
|
keyField?: string | undefined;
|
|
113
|
-
defaultSort?: (string & z
|
|
93
|
+
defaultSort?: (string & z.$brand<"PXL.FieldName">)[] | undefined;
|
|
114
94
|
source?: Record<string, unknown> | undefined;
|
|
115
|
-
};
|
|
116
|
-
type WithDefaults = ReturnType<typeof addDefaults>;
|
|
117
|
-
declare function brandModel({ name, schema, databaseName, standardFields, defaultField, labelField, keyField, defaultSort, ...input }: WithDefaults): {
|
|
118
|
-
name: string & z.core.$brand<"PXL.ModelName">;
|
|
119
|
-
schema: (string & z.core.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
120
|
-
databaseName: string & z.core.$brand<"PXL.DatabaseModelName">;
|
|
121
|
-
standardFields: (string & z.core.$brand<"PXL.FieldName">)[];
|
|
122
|
-
defaultFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
123
|
-
labelFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
124
|
-
keyFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
125
|
-
defaultSort: (string & z.core.$brand<"PXL.FieldName">)[] | undefined;
|
|
126
95
|
isReadonly: boolean;
|
|
127
96
|
exposeRestApi: boolean;
|
|
97
|
+
databaseName: string;
|
|
128
98
|
excelName: string;
|
|
129
99
|
description: string;
|
|
130
100
|
fields: {
|
|
131
101
|
[x: string]: unknown;
|
|
132
102
|
name: string;
|
|
133
103
|
}[];
|
|
104
|
+
standardFields: string[];
|
|
134
105
|
indexes: ({
|
|
135
|
-
fields: (string & z
|
|
106
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
136
107
|
unique: boolean;
|
|
137
108
|
map: string | undefined;
|
|
138
109
|
} | {
|
|
139
|
-
fields: (string & z
|
|
110
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
140
111
|
unique: boolean;
|
|
141
112
|
map: string | undefined;
|
|
142
113
|
})[];
|
|
143
114
|
seed: any[];
|
|
115
|
+
labelQualifier: {
|
|
116
|
+
relation: string;
|
|
117
|
+
separator: string | undefined;
|
|
118
|
+
} | undefined;
|
|
144
119
|
faker: {
|
|
145
120
|
seed: number;
|
|
146
121
|
items: number;
|
|
147
122
|
};
|
|
123
|
+
};
|
|
124
|
+
type WithDefaults = ReturnType<typeof addDefaults>;
|
|
125
|
+
declare function brandModel({ name, schema, databaseName, standardFields, defaultField, labelField, labelQualifier, keyField, defaultSort, ...input }: WithDefaults): {
|
|
148
126
|
auth?: {
|
|
149
127
|
read?: {
|
|
150
128
|
anyRole: string[];
|
|
@@ -169,31 +147,20 @@ declare function brandModel({ name, schema, databaseName, standardFields, defaul
|
|
|
169
147
|
} | undefined;
|
|
170
148
|
} | undefined;
|
|
171
149
|
source?: Record<string, unknown> | undefined;
|
|
172
|
-
};
|
|
173
|
-
type BrandedModel = ReturnType<typeof brandModel>;
|
|
174
|
-
declare function combineFields({ fields, standardFields, ...model }: BrandedModel, ctx: z.RefinementCtx): {
|
|
175
|
-
fields: Record<string & z.core.$brand<"PXL.FieldName">, unknown>;
|
|
176
|
-
/**
|
|
177
|
-
* We also provide a list of field names to keep the original order
|
|
178
|
-
*/
|
|
179
|
-
fieldNames: (string & z.core.$brand<"PXL.FieldName">)[];
|
|
180
|
-
name: string & z.core.$brand<"PXL.ModelName">;
|
|
181
|
-
schema: (string & z.core.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
182
|
-
databaseName: string & z.core.$brand<"PXL.DatabaseModelName">;
|
|
183
|
-
defaultFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
184
|
-
labelFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
185
|
-
keyFieldName: (string & z.core.$brand<"PXL.FieldName">) | undefined;
|
|
186
|
-
defaultSort: (string & z.core.$brand<"PXL.FieldName">)[] | undefined;
|
|
187
150
|
isReadonly: boolean;
|
|
188
151
|
exposeRestApi: boolean;
|
|
189
152
|
excelName: string;
|
|
190
153
|
description: string;
|
|
154
|
+
fields: {
|
|
155
|
+
[x: string]: unknown;
|
|
156
|
+
name: string;
|
|
157
|
+
}[];
|
|
191
158
|
indexes: ({
|
|
192
|
-
fields: (string & z
|
|
159
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
193
160
|
unique: boolean;
|
|
194
161
|
map: string | undefined;
|
|
195
162
|
} | {
|
|
196
|
-
fields: (string & z
|
|
163
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
197
164
|
unique: boolean;
|
|
198
165
|
map: string | undefined;
|
|
199
166
|
})[];
|
|
@@ -202,6 +169,21 @@ declare function combineFields({ fields, standardFields, ...model }: BrandedMode
|
|
|
202
169
|
seed: number;
|
|
203
170
|
items: number;
|
|
204
171
|
};
|
|
172
|
+
name: string & z.$brand<"PXL.ModelName">;
|
|
173
|
+
schema: (string & z.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
174
|
+
databaseName: string & z.$brand<"PXL.DatabaseModelName">;
|
|
175
|
+
standardFields: (string & z.$brand<"PXL.FieldName">)[];
|
|
176
|
+
defaultFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
177
|
+
labelFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
178
|
+
labelQualifier: {
|
|
179
|
+
relationFieldName: string & z.$brand<"PXL.FieldName">;
|
|
180
|
+
separator: string | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
keyFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
183
|
+
defaultSort: (string & z.$brand<"PXL.FieldName">)[] | undefined;
|
|
184
|
+
};
|
|
185
|
+
type BrandedModel = ReturnType<typeof brandModel>;
|
|
186
|
+
declare function combineFields({ fields, standardFields, ...model }: BrandedModel, ctx: z.RefinementCtx): {
|
|
205
187
|
auth?: {
|
|
206
188
|
read?: {
|
|
207
189
|
anyRole: string[];
|
|
@@ -226,6 +208,40 @@ declare function combineFields({ fields, standardFields, ...model }: BrandedMode
|
|
|
226
208
|
} | undefined;
|
|
227
209
|
} | undefined;
|
|
228
210
|
source?: Record<string, unknown> | undefined;
|
|
211
|
+
isReadonly: boolean;
|
|
212
|
+
exposeRestApi: boolean;
|
|
213
|
+
excelName: string;
|
|
214
|
+
description: string;
|
|
215
|
+
indexes: ({
|
|
216
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
217
|
+
unique: boolean;
|
|
218
|
+
map: string | undefined;
|
|
219
|
+
} | {
|
|
220
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
221
|
+
unique: boolean;
|
|
222
|
+
map: string | undefined;
|
|
223
|
+
})[];
|
|
224
|
+
seed: any[];
|
|
225
|
+
faker: {
|
|
226
|
+
seed: number;
|
|
227
|
+
items: number;
|
|
228
|
+
};
|
|
229
|
+
name: string & z.$brand<"PXL.ModelName">;
|
|
230
|
+
schema: (string & z.$brand<"PXL.DatabaseSchemaName">) | undefined;
|
|
231
|
+
databaseName: string & z.$brand<"PXL.DatabaseModelName">;
|
|
232
|
+
defaultFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
233
|
+
labelFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
234
|
+
labelQualifier: {
|
|
235
|
+
relationFieldName: string & z.$brand<"PXL.FieldName">;
|
|
236
|
+
separator: string | undefined;
|
|
237
|
+
} | undefined;
|
|
238
|
+
keyFieldName: (string & z.$brand<"PXL.FieldName">) | undefined;
|
|
239
|
+
defaultSort: (string & z.$brand<"PXL.FieldName">)[] | undefined;
|
|
240
|
+
fields: Record<string & z.$brand<"PXL.FieldName">, unknown>;
|
|
241
|
+
/**
|
|
242
|
+
* We also provide a list of field names to keep the original order
|
|
243
|
+
*/
|
|
244
|
+
fieldNames: (string & z.$brand<"PXL.FieldName">)[];
|
|
229
245
|
};
|
|
230
246
|
export type CombinedFields = ReturnType<typeof combineFields>;
|
|
231
247
|
export {};
|
|
@@ -47,6 +47,14 @@ function modelJSONTransformer(input, ctx) {
|
|
|
47
47
|
validateSeedData(withCombinedFields, ctx);
|
|
48
48
|
return withCombinedFields;
|
|
49
49
|
}
|
|
50
|
+
function normalizeLabelQualifier(input) {
|
|
51
|
+
if (input === undefined) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return typeof input === 'string'
|
|
55
|
+
? { relation: input, separator: undefined }
|
|
56
|
+
: { relation: input.relation, separator: input.separator };
|
|
57
|
+
}
|
|
50
58
|
function addDefaults({ description, fields, standardFields, seed, faker, ...input }) {
|
|
51
59
|
return {
|
|
52
60
|
...input,
|
|
@@ -59,6 +67,7 @@ function addDefaults({ description, fields, standardFields, seed, faker, ...inpu
|
|
|
59
67
|
standardFields: standardFields ?? Field.standardFieldNames,
|
|
60
68
|
indexes: input.indexes ?? [],
|
|
61
69
|
seed: seed ?? [],
|
|
70
|
+
labelQualifier: normalizeLabelQualifier(input.labelQualifier),
|
|
62
71
|
faker: {
|
|
63
72
|
seed: faker?.seed ?? 0,
|
|
64
73
|
// We use the provided number of faker items - if nothing is provided, we default to 10 - unless a seed is provided, then we default to 0
|
|
@@ -66,7 +75,7 @@ function addDefaults({ description, fields, standardFields, seed, faker, ...inpu
|
|
|
66
75
|
},
|
|
67
76
|
};
|
|
68
77
|
}
|
|
69
|
-
function brandModel({ name, schema, databaseName, standardFields, defaultField, labelField, keyField, defaultSort, ...input }) {
|
|
78
|
+
function brandModel({ name, schema, databaseName, standardFields, defaultField, labelField, labelQualifier, keyField, defaultSort, ...input }) {
|
|
70
79
|
return {
|
|
71
80
|
...input,
|
|
72
81
|
name: (0, model_brands_1.toModelName)(name),
|
|
@@ -75,6 +84,9 @@ function brandModel({ name, schema, databaseName, standardFields, defaultField,
|
|
|
75
84
|
standardFields: standardFields.map((f) => Field.toFieldName(f)),
|
|
76
85
|
defaultFieldName: defaultField ? Field.toFieldName(defaultField) : undefined,
|
|
77
86
|
labelFieldName: labelField ? Field.toFieldName(labelField) : undefined,
|
|
87
|
+
labelQualifier: labelQualifier
|
|
88
|
+
? { relationFieldName: Field.toFieldName(labelQualifier.relation), separator: labelQualifier.separator }
|
|
89
|
+
: undefined,
|
|
78
90
|
keyFieldName: keyField ? Field.toFieldName(keyField) : undefined,
|
|
79
91
|
defaultSort: defaultSort?.map((fieldName) => Field.toFieldName(fieldName)),
|
|
80
92
|
};
|
|
@@ -3,6 +3,17 @@ import { AuthRuleSet } from '../project-schema/project-schema.auth';
|
|
|
3
3
|
import { DatabaseSchemaName } from '../project-schema/project-schema.brands';
|
|
4
4
|
import * as Branded from './model.brands';
|
|
5
5
|
export type Models = Map<Branded.ModelName, Model>;
|
|
6
|
+
/**
|
|
7
|
+
* Qualifies a model's label with the label of a related parent entity, so that labels which are
|
|
8
|
+
* only unique within a parent stay distinguishable when the entity is referenced from elsewhere.
|
|
9
|
+
*/
|
|
10
|
+
export type LabelQualifier = {
|
|
11
|
+
/** The to-one relation field on this model whose parent supplies the qualifying label. */
|
|
12
|
+
relationField: Field.FieldRelation;
|
|
13
|
+
referencedModelName: Branded.ModelName;
|
|
14
|
+
/** Fully resolved at schema time — consumers never re-resolve it against project defaults. */
|
|
15
|
+
separator: string;
|
|
16
|
+
};
|
|
6
17
|
export type Model = {
|
|
7
18
|
name: Branded.ModelName;
|
|
8
19
|
description: string;
|
|
@@ -18,6 +29,12 @@ export type Model = {
|
|
|
18
29
|
idField: Field.FieldId;
|
|
19
30
|
defaultField: Field.FieldDatabaseNative | undefined;
|
|
20
31
|
labelField: Field.FieldDatabaseNative;
|
|
32
|
+
/**
|
|
33
|
+
* When set, generated view models expose a `displayLabel` computed field that prefixes this
|
|
34
|
+
* model's label with the referenced parent's label. Undefined for models that do not opt in,
|
|
35
|
+
* which generate exactly the same output as before this feature existed.
|
|
36
|
+
*/
|
|
37
|
+
labelQualifier: LabelQualifier | undefined;
|
|
21
38
|
/**
|
|
22
39
|
* The field used as the key/unique identifier for the entity.
|
|
23
40
|
* Used in navigation, Excel import, and other places where a human-readable identifier is needed.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const zProjectSchemaName: z.core.$ZodBranded<z.ZodString, "PXL.ProjectSchemaName", "out">;
|
|
3
3
|
export type ProjectSchemaName = z.infer<typeof zProjectSchemaName>;
|
|
4
|
-
export declare const toProjectSchemaName: (input: string) => string & z
|
|
4
|
+
export declare const toProjectSchemaName: (input: string) => string & z.$brand<"PXL.ProjectSchemaName">;
|
|
5
5
|
export declare const zProjectSlug: z.core.$ZodBranded<z.ZodString, "PXL.ProjectSlug", "out">;
|
|
6
6
|
export type ProjectSlug = z.infer<typeof zProjectSlug>;
|
|
7
|
-
export declare const toProjectSlug: (input: string) => string & z
|
|
7
|
+
export declare const toProjectSlug: (input: string) => string & z.$brand<"PXL.ProjectSlug">;
|
|
8
8
|
export declare const zDatabaseSchemaName: z.core.$ZodBranded<z.ZodString, "PXL.DatabaseSchemaName", "out">;
|
|
9
9
|
export type DatabaseSchemaName = z.infer<typeof zDatabaseSchemaName>;
|
|
10
|
-
export declare const toDatabaseSchemaName: (input: string) => string & z
|
|
10
|
+
export declare const toDatabaseSchemaName: (input: string) => string & z.$brand<"PXL.DatabaseSchemaName">;
|
|
@@ -10,7 +10,7 @@ export declare const databaseSchemaNameConfig: string & import("zod").$brand<"PX
|
|
|
10
10
|
/**
|
|
11
11
|
* The default project roles. Can be overridden via `defaultRoles` in the project schema.
|
|
12
12
|
*/
|
|
13
|
-
export declare const defaultProjectRoles: readonly [
|
|
13
|
+
export declare const defaultProjectRoles: readonly ['superadmin', 'admin', 'editor', 'viewer'];
|
|
14
14
|
export declare const defaultSystemUser: {
|
|
15
15
|
id: string;
|
|
16
16
|
sub: null;
|
|
@@ -59,6 +59,7 @@ export declare const zProjectSchemaJSON: z.ZodPreprocess<z.ZodObject<{
|
|
|
59
59
|
}, z.core.$strip>>;
|
|
60
60
|
}, z.core.$strip>]>>>;
|
|
61
61
|
defaultSchema: z.ZodOptional<z.ZodString>;
|
|
62
|
+
defaultLabelSeparator: z.ZodOptional<z.ZodString>;
|
|
62
63
|
auth: z.ZodOptional<z.ZodObject<{
|
|
63
64
|
provider: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"keycloak">>>;
|
|
64
65
|
roleClaimPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -109,22 +110,26 @@ export declare const zProjectSchemaJSON: z.ZodPreprocess<z.ZodObject<{
|
|
|
109
110
|
standardFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
110
111
|
defaultField: z.ZodOptional<z.ZodString>;
|
|
111
112
|
labelField: z.ZodOptional<z.ZodString>;
|
|
113
|
+
labelQualifier: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
114
|
+
relation: z.ZodString;
|
|
115
|
+
separator: z.ZodOptional<z.ZodString>;
|
|
116
|
+
}, z.core.$strip>]>>;
|
|
112
117
|
keyField: z.ZodOptional<z.ZodString>;
|
|
113
118
|
defaultSort: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>>;
|
|
114
119
|
indexes: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>, z.ZodTransform<{
|
|
115
|
-
fields: (string & z
|
|
120
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
116
121
|
unique: boolean;
|
|
117
122
|
map: string | undefined;
|
|
118
|
-
}, (string & z
|
|
123
|
+
}, (string & z.$brand<"PXL.FieldName">)[]>>, z.ZodPipe<z.ZodObject<{
|
|
119
124
|
fields: z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>;
|
|
120
125
|
unique: z.ZodOptional<z.ZodBoolean>;
|
|
121
126
|
map: z.ZodOptional<z.ZodString>;
|
|
122
127
|
}, z.core.$strip>, z.ZodTransform<{
|
|
123
|
-
fields: (string & z
|
|
128
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
124
129
|
unique: boolean;
|
|
125
130
|
map: string | undefined;
|
|
126
131
|
}, {
|
|
127
|
-
fields: (string & z
|
|
132
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
128
133
|
unique?: boolean | undefined;
|
|
129
134
|
map?: string | undefined;
|
|
130
135
|
}>>]>>>;
|
|
@@ -116,6 +116,11 @@ exports.zProjectSchemaJSON = zod_1.z
|
|
|
116
116
|
//
|
|
117
117
|
.optional()
|
|
118
118
|
.describe(`The default database schema that is used if model/enum does not specify a schema. If not provided, the default schema "Data" is used.`),
|
|
119
|
+
defaultLabelSeparator: zod_1.z
|
|
120
|
+
//
|
|
121
|
+
.string()
|
|
122
|
+
.optional()
|
|
123
|
+
.describe(`Separator inserted between a parent label and a child label when a model declares a \`labelQualifier\` without its own separator. Defaults to " – " (space, en dash, space).`),
|
|
119
124
|
auth: project_schema_auth_1.zProjectAuthJSON
|
|
120
125
|
.optional()
|
|
121
126
|
.describe('Project-level authentication settings (provider, role claim path, and default behavior).'),
|
|
@@ -38,6 +38,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
38
38
|
}, z.core.$strip>>;
|
|
39
39
|
}, z.core.$strip>]>>>;
|
|
40
40
|
defaultSchema: z.ZodOptional<z.ZodString>;
|
|
41
|
+
defaultLabelSeparator: z.ZodOptional<z.ZodString>;
|
|
41
42
|
auth: z.ZodOptional<z.ZodObject<{
|
|
42
43
|
provider: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"keycloak">>>;
|
|
43
44
|
roleClaimPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -88,22 +89,26 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
88
89
|
standardFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
90
|
defaultField: z.ZodOptional<z.ZodString>;
|
|
90
91
|
labelField: z.ZodOptional<z.ZodString>;
|
|
92
|
+
labelQualifier: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
93
|
+
relation: z.ZodString;
|
|
94
|
+
separator: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, z.core.$strip>]>>;
|
|
91
96
|
keyField: z.ZodOptional<z.ZodString>;
|
|
92
97
|
defaultSort: z.ZodOptional<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>>;
|
|
93
98
|
indexes: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>, z.ZodTransform<{
|
|
94
|
-
fields: (string & z
|
|
99
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
95
100
|
unique: boolean;
|
|
96
101
|
map: string | undefined;
|
|
97
|
-
}, (string & z
|
|
102
|
+
}, (string & z.$brand<"PXL.FieldName">)[]>>, z.ZodPipe<z.ZodObject<{
|
|
98
103
|
fields: z.ZodArray<z.core.$ZodBranded<z.ZodString, "PXL.FieldName", "out">>;
|
|
99
104
|
unique: z.ZodOptional<z.ZodBoolean>;
|
|
100
105
|
map: z.ZodOptional<z.ZodString>;
|
|
101
106
|
}, z.core.$strip>, z.ZodTransform<{
|
|
102
|
-
fields: (string & z
|
|
107
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
103
108
|
unique: boolean;
|
|
104
109
|
map: string | undefined;
|
|
105
110
|
}, {
|
|
106
|
-
fields: (string & z
|
|
111
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
107
112
|
unique?: boolean | undefined;
|
|
108
113
|
map?: string | undefined;
|
|
109
114
|
}>>]>>>;
|
|
@@ -131,9 +136,8 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
131
136
|
}, z.core.$strip>>, z.ZodTransform<ProjectSchema, {
|
|
132
137
|
name: string;
|
|
133
138
|
slug: string;
|
|
134
|
-
projectType: "standalone" | "workspace";
|
|
135
|
-
source: Record<string, unknown>;
|
|
136
139
|
description?: string | undefined;
|
|
140
|
+
projectType: "standalone" | "workspace";
|
|
137
141
|
version?: string | undefined;
|
|
138
142
|
schemas?: (string | {
|
|
139
143
|
name: string;
|
|
@@ -162,6 +166,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
162
166
|
} | undefined;
|
|
163
167
|
})[] | undefined;
|
|
164
168
|
defaultSchema?: string | undefined;
|
|
169
|
+
defaultLabelSeparator?: string | undefined;
|
|
165
170
|
auth?: {
|
|
166
171
|
provider: "keycloak";
|
|
167
172
|
roleClaimPath: string;
|
|
@@ -213,14 +218,18 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
213
218
|
standardFields?: string[] | undefined;
|
|
214
219
|
defaultField?: string | undefined;
|
|
215
220
|
labelField?: string | undefined;
|
|
221
|
+
labelQualifier?: string | {
|
|
222
|
+
relation: string;
|
|
223
|
+
separator?: string | undefined;
|
|
224
|
+
} | undefined;
|
|
216
225
|
keyField?: string | undefined;
|
|
217
|
-
defaultSort?: (string & z
|
|
226
|
+
defaultSort?: (string & z.$brand<"PXL.FieldName">)[] | undefined;
|
|
218
227
|
indexes?: ({
|
|
219
|
-
fields: (string & z
|
|
228
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
220
229
|
unique: boolean;
|
|
221
230
|
map: string | undefined;
|
|
222
231
|
} | {
|
|
223
|
-
fields: (string & z
|
|
232
|
+
fields: (string & z.$brand<"PXL.FieldName">)[];
|
|
224
233
|
unique: boolean;
|
|
225
234
|
map: string | undefined;
|
|
226
235
|
})[] | undefined;
|
|
@@ -235,13 +244,14 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
|
235
244
|
enums?: {
|
|
236
245
|
name: string;
|
|
237
246
|
description: string;
|
|
247
|
+
schema?: string | undefined;
|
|
248
|
+
databaseName?: string | undefined;
|
|
238
249
|
members: (string | {
|
|
239
250
|
value: string;
|
|
240
251
|
description?: string | undefined;
|
|
241
252
|
})[];
|
|
242
|
-
schema?: string | undefined;
|
|
243
|
-
databaseName?: string | undefined;
|
|
244
253
|
}[] | undefined;
|
|
245
254
|
modelFiles?: string[] | undefined;
|
|
246
255
|
enumFiles?: string[] | undefined;
|
|
256
|
+
source: Record<string, unknown>;
|
|
247
257
|
}>>;
|