@postxl/schema 1.8.2 → 1.10.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/field/field.d.ts +15 -0
- package/dist/field/relation.d.ts +22 -0
- package/dist/field/relation.js +15 -1
- package/dist/field/scalar.d.ts +8 -0
- package/dist/field/scalar.js +51 -1
- package/dist/field/shared/decoders.d.ts +1 -0
- package/dist/field/shared/decoders.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/project-schema/project-schema.defaults.d.ts +4 -0
- package/dist/project-schema/project-schema.defaults.js +5 -1
- package/dist/project-schema/project-schema.json-decoder.d.ts +1 -0
- package/dist/project-schema/project-schema.json-decoder.js +6 -0
- package/dist/project-schema/project-schema.transformer.d.ts +2 -0
- package/dist/project-schema/project-schema.transformer.js +1 -0
- package/dist/project-schema/project-schema.types.d.ts +5 -0
- package/package.json +1 -1
package/dist/field/field.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
66
66
|
faker: z.ZodOptional<z.ZodString>;
|
|
67
67
|
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>>]>>;
|
|
68
68
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
69
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
69
70
|
}, z.core.$strict>, z.ZodTransform<FieldScalarEnriched, {
|
|
70
71
|
name: string;
|
|
71
72
|
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Bytes?" | "BigInt?";
|
|
@@ -82,6 +83,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
82
83
|
faker?: string | undefined;
|
|
83
84
|
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
84
85
|
placeholder?: string | undefined;
|
|
86
|
+
defaultValue?: string | number | boolean | undefined;
|
|
85
87
|
}>>, z.ZodPipe<z.ZodObject<{
|
|
86
88
|
name: z.ZodString;
|
|
87
89
|
type: z.ZodUnion<readonly [z.ZodLiteral<"Json">, z.ZodLiteral<"JSON">, z.ZodLiteral<"Json?">, z.ZodLiteral<"JSON?">]>;
|
|
@@ -155,6 +157,11 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
155
157
|
excelName: z.ZodOptional<z.ZodString>;
|
|
156
158
|
prismaRelationFieldName: z.ZodOptional<z.ZodString>;
|
|
157
159
|
deepClone: z.ZodOptional<z.ZodBoolean>;
|
|
160
|
+
onDelete: z.ZodOptional<z.ZodEnum<{
|
|
161
|
+
cascade: "cascade";
|
|
162
|
+
setNull: "setNull";
|
|
163
|
+
restrict: "restrict";
|
|
164
|
+
}>>;
|
|
158
165
|
label: z.ZodOptional<z.ZodString>;
|
|
159
166
|
description: z.ZodOptional<z.ZodString>;
|
|
160
167
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -169,6 +176,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
169
176
|
prismaRelationFieldName: (string & z.core.$brand<"PXL.DatabaseFieldName">) | undefined;
|
|
170
177
|
excelName: string & z.core.$brand<"PXL.ExcelColumnName">;
|
|
171
178
|
deepClone: boolean;
|
|
179
|
+
onDelete: "cascade" | "setNull" | "restrict";
|
|
172
180
|
description: string | undefined;
|
|
173
181
|
isReadonly: boolean;
|
|
174
182
|
isRequired: boolean;
|
|
@@ -182,6 +190,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
182
190
|
excelName?: string | undefined;
|
|
183
191
|
prismaRelationFieldName?: string | undefined;
|
|
184
192
|
deepClone?: boolean | undefined;
|
|
193
|
+
onDelete?: "cascade" | "setNull" | "restrict" | undefined;
|
|
185
194
|
label?: string | undefined;
|
|
186
195
|
description?: string | undefined;
|
|
187
196
|
isReadonly?: boolean | undefined;
|
|
@@ -248,6 +257,7 @@ export declare const zFieldJSONInput: (params: {
|
|
|
248
257
|
faker: z.ZodOptional<z.ZodString>;
|
|
249
258
|
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>>]>>;
|
|
250
259
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
260
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
251
261
|
}, z.core.$strict>, z.ZodObject<{
|
|
252
262
|
name: z.ZodString;
|
|
253
263
|
type: z.ZodUnion<readonly [z.ZodLiteral<"Json">, z.ZodLiteral<"JSON">, z.ZodLiteral<"Json?">, z.ZodLiteral<"JSON?">]>;
|
|
@@ -266,6 +276,11 @@ export declare const zFieldJSONInput: (params: {
|
|
|
266
276
|
excelName: z.ZodOptional<z.ZodString>;
|
|
267
277
|
prismaRelationFieldName: z.ZodOptional<z.ZodString>;
|
|
268
278
|
deepClone: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
+
onDelete: z.ZodOptional<z.ZodEnum<{
|
|
280
|
+
cascade: "cascade";
|
|
281
|
+
setNull: "setNull";
|
|
282
|
+
restrict: "restrict";
|
|
283
|
+
}>>;
|
|
269
284
|
label: z.ZodOptional<z.ZodString>;
|
|
270
285
|
description: z.ZodOptional<z.ZodString>;
|
|
271
286
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
package/dist/field/relation.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import * as Branded from './shared/brands';
|
|
|
4
4
|
import { FieldCommon, FieldTransformer } from './shared/types';
|
|
5
5
|
export type FieldKindRelation = 'relation';
|
|
6
6
|
export declare const fieldKindRelation: FieldKindRelation;
|
|
7
|
+
/**
|
|
8
|
+
* Behavior applied to entities carrying this relation when the referenced
|
|
9
|
+
* entity is deleted. Cascade deletion is handled in the update service,
|
|
10
|
+
* not in the database, so it also works with in-memory repositories and
|
|
11
|
+
* keeps internal caches consistent.
|
|
12
|
+
*/
|
|
13
|
+
export type OnDeleteBehavior = 'cascade' | 'setNull' | 'restrict';
|
|
14
|
+
export declare const onDeleteBehaviors: readonly ["cascade", "setNull", "restrict"];
|
|
7
15
|
export type FieldRelation = FieldCommon<FieldKindRelation> & {
|
|
8
16
|
type: Branded.IdType;
|
|
9
17
|
referencedModelName: ModelName;
|
|
@@ -20,6 +28,14 @@ export type FieldRelation = FieldCommon<FieldKindRelation> & {
|
|
|
20
28
|
* Note: Setting this to true on a relation to a readonly model will cause a validation error.
|
|
21
29
|
*/
|
|
22
30
|
deepClone: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Behavior when the referenced entity is deleted.
|
|
33
|
+
*
|
|
34
|
+
* - `cascade` (default): this entity is also deleted.
|
|
35
|
+
* - `setNull`: the foreign key is set to null. Only valid for optional relations.
|
|
36
|
+
* - `restrict`: the parent deletion is rejected if any referencing entities exist.
|
|
37
|
+
*/
|
|
38
|
+
onDelete: OnDeleteBehavior;
|
|
23
39
|
/**
|
|
24
40
|
* Name of the unbranded TypeScript type of the field, e.g. string
|
|
25
41
|
*
|
|
@@ -39,6 +55,11 @@ export declare const createRelationJSONDecoder: ({ modelNames }: {
|
|
|
39
55
|
excelName: z.ZodOptional<z.ZodString>;
|
|
40
56
|
prismaRelationFieldName: z.ZodOptional<z.ZodString>;
|
|
41
57
|
deepClone: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
onDelete: z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
cascade: "cascade";
|
|
60
|
+
setNull: "setNull";
|
|
61
|
+
restrict: "restrict";
|
|
62
|
+
}>>;
|
|
42
63
|
label: z.ZodOptional<z.ZodString>;
|
|
43
64
|
description: z.ZodOptional<z.ZodString>;
|
|
44
65
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -55,6 +76,7 @@ export declare function fieldRelationJSONTransformer(fieldInput: FieldRelationJS
|
|
|
55
76
|
prismaRelationFieldName: (string & z.core.$brand<"PXL.DatabaseFieldName">) | undefined;
|
|
56
77
|
excelName: string & z.core.$brand<"PXL.ExcelColumnName">;
|
|
57
78
|
deepClone: boolean;
|
|
79
|
+
onDelete: "cascade" | "setNull" | "restrict";
|
|
58
80
|
description: string | undefined;
|
|
59
81
|
isReadonly: boolean;
|
|
60
82
|
isRequired: boolean;
|
package/dist/field/relation.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.fieldRelationTransformer = exports.createRelationJSONDecoder = exports.fieldKindRelation = void 0;
|
|
36
|
+
exports.fieldRelationTransformer = exports.createRelationJSONDecoder = exports.onDeleteBehaviors = exports.fieldKindRelation = void 0;
|
|
37
37
|
exports.fieldRelationJSONTransformer = fieldRelationJSONTransformer;
|
|
38
38
|
const zod_1 = require("zod");
|
|
39
39
|
const utils_1 = require("@postxl/utils");
|
|
@@ -42,6 +42,7 @@ const Branded = __importStar(require("./shared/brands"));
|
|
|
42
42
|
const Decoders = __importStar(require("./shared/decoders"));
|
|
43
43
|
const utils_2 = require("./shared/utils");
|
|
44
44
|
exports.fieldKindRelation = 'relation';
|
|
45
|
+
exports.onDeleteBehaviors = ['cascade', 'setNull', 'restrict'];
|
|
45
46
|
const createRelationJSONDecoder = ({ modelNames }) => {
|
|
46
47
|
return zod_1.z.object({
|
|
47
48
|
name: Decoders.zFieldPropertyName.refine((name) => name.endsWith('Id'), {
|
|
@@ -72,6 +73,10 @@ const createRelationJSONDecoder = ({ modelNames }) => {
|
|
|
72
73
|
.boolean()
|
|
73
74
|
.optional()
|
|
74
75
|
.describe('If true, when cloning an entity, this relation will be deep cloned. If false or undefined, the clone will reference the same entity.'),
|
|
76
|
+
onDelete: zod_1.z
|
|
77
|
+
.enum(exports.onDeleteBehaviors)
|
|
78
|
+
.optional()
|
|
79
|
+
.describe('Behavior when the referenced entity is deleted: "cascade" (default) deletes this entity too, "setNull" nulls the foreign key (optional relations only), "restrict" rejects the deletion if any referencing entities exist.'),
|
|
75
80
|
label: Decoders.zFieldPropertyLabel,
|
|
76
81
|
description: Decoders.zFieldPropertyDescription,
|
|
77
82
|
isReadonly: Decoders.zFieldPropertyIsReadonly,
|
|
@@ -95,6 +100,7 @@ function fieldRelationJSONTransformer(fieldInput) {
|
|
|
95
100
|
: undefined,
|
|
96
101
|
excelName: Branded.toExcelColumnName(fieldInput.excelName ?? fieldInput.label ?? fieldInput.name),
|
|
97
102
|
deepClone: fieldInput.deepClone ?? false,
|
|
103
|
+
onDelete: fieldInput.onDelete ?? 'cascade',
|
|
98
104
|
description: fieldInput.description,
|
|
99
105
|
isReadonly: fieldInput.isReadonly ?? false,
|
|
100
106
|
isRequired,
|
|
@@ -120,6 +126,14 @@ const fieldRelationTransformer = ({ fieldInput, model, projectSchema }, ctx) =>
|
|
|
120
126
|
});
|
|
121
127
|
return zod_1.z.NEVER;
|
|
122
128
|
}
|
|
129
|
+
// Validate that onDelete 'setNull' is only used on optional relations
|
|
130
|
+
if (fieldInput.onDelete === 'setNull' && fieldInput.isRequired) {
|
|
131
|
+
ctx.addIssue({
|
|
132
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
133
|
+
message: `Field ${model.name}.${fieldInput.name} has onDelete='setNull' but the relation is required. Only optional relations (e.g. "${referencedModel.name}?") can have their foreign key set to null.`,
|
|
134
|
+
});
|
|
135
|
+
return zod_1.z.NEVER;
|
|
136
|
+
}
|
|
123
137
|
const idField = (0, utils_2.getIdField)(model);
|
|
124
138
|
if (idField === undefined) {
|
|
125
139
|
ctx.addIssue({
|
package/dist/field/scalar.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ type FieldCommonScalar = {
|
|
|
33
33
|
type FieldScalarStringWithValidations = {
|
|
34
34
|
type: 'string';
|
|
35
35
|
validations: ValidationString;
|
|
36
|
+
defaultValue: string | undefined;
|
|
36
37
|
};
|
|
37
38
|
type ValidationString = {
|
|
38
39
|
maxLength: number | undefined;
|
|
@@ -40,6 +41,7 @@ type ValidationString = {
|
|
|
40
41
|
type FieldScalarNumberWithValidations = {
|
|
41
42
|
type: 'number';
|
|
42
43
|
validations: ValidationNumber;
|
|
44
|
+
defaultValue: number | undefined;
|
|
43
45
|
};
|
|
44
46
|
type ValidationNumber = {
|
|
45
47
|
type: 'int' | 'float';
|
|
@@ -48,9 +50,11 @@ type ValidationNumber = {
|
|
|
48
50
|
};
|
|
49
51
|
type FieldScalarBooleanNoValidation = {
|
|
50
52
|
type: 'boolean';
|
|
53
|
+
defaultValue: boolean | undefined;
|
|
51
54
|
};
|
|
52
55
|
type FieldScalarDateNoValidation = {
|
|
53
56
|
type: 'Date';
|
|
57
|
+
defaultValue: string | undefined;
|
|
54
58
|
};
|
|
55
59
|
/**
|
|
56
60
|
* JSON Schema for an scalar field
|
|
@@ -71,12 +75,14 @@ export declare const zFieldScalarJSON: z.ZodObject<{
|
|
|
71
75
|
faker: z.ZodOptional<z.ZodString>;
|
|
72
76
|
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>>]>>;
|
|
73
77
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
78
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
74
79
|
}, z.core.$strict>;
|
|
75
80
|
export type FieldScalarJSON = z.infer<typeof zFieldScalarJSON>;
|
|
76
81
|
export declare function fieldScalarJSONTransformer(fieldInput: FieldScalarJSON, ctx: z.RefinementCtx): FieldScalarEnriched;
|
|
77
82
|
export type FieldScalarEnriched = Omit<FieldCommon<FieldKindScalar>, 'modelName'> & FieldCommonScalar & {
|
|
78
83
|
type: Branded.ScalarType;
|
|
79
84
|
validations: Partial<ValidationString & ValidationNumber>;
|
|
85
|
+
defaultValue: string | number | boolean | undefined;
|
|
80
86
|
};
|
|
81
87
|
export declare const zFieldScalar: z.ZodPipe<z.ZodObject<{
|
|
82
88
|
name: z.ZodString;
|
|
@@ -94,6 +100,7 @@ export declare const zFieldScalar: z.ZodPipe<z.ZodObject<{
|
|
|
94
100
|
faker: z.ZodOptional<z.ZodString>;
|
|
95
101
|
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>>]>>;
|
|
96
102
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
103
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
97
104
|
}, z.core.$strict>, z.ZodTransform<FieldScalarEnriched, {
|
|
98
105
|
name: string;
|
|
99
106
|
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Bytes?" | "BigInt?";
|
|
@@ -110,6 +117,7 @@ export declare const zFieldScalar: z.ZodPipe<z.ZodObject<{
|
|
|
110
117
|
faker?: string | undefined;
|
|
111
118
|
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
112
119
|
placeholder?: string | undefined;
|
|
120
|
+
defaultValue?: string | number | boolean | undefined;
|
|
113
121
|
}>>;
|
|
114
122
|
export declare const fieldScalarTransformer: FieldTransformer<FieldKindScalar, FieldScalarEnriched, FieldScalar>;
|
|
115
123
|
export {};
|
package/dist/field/scalar.js
CHANGED
|
@@ -105,6 +105,7 @@ exports.zFieldScalarJSON = zod_1.z
|
|
|
105
105
|
faker: Decoders.zFieldFaker,
|
|
106
106
|
seed: Decoders.zFieldSeed,
|
|
107
107
|
placeholder: Decoders.zFieldPropertyPlaceholder,
|
|
108
|
+
defaultValue: Decoders.zFieldPropertyDefaultValue,
|
|
108
109
|
})
|
|
109
110
|
.strict();
|
|
110
111
|
const defaultPlaceholders = {
|
|
@@ -128,6 +129,50 @@ function fieldScalarJSONTransformer(fieldInput, ctx) {
|
|
|
128
129
|
const label = fieldInput.label ?? (0, utils_1.toHumanReadable)(fieldInput.name);
|
|
129
130
|
const placeholderFactory = defaultPlaceholders[scalarDatabaseType];
|
|
130
131
|
const placeholder = fieldInput.placeholder ?? placeholderFactory?.(label) ?? `${label} here...`;
|
|
132
|
+
// Validate defaultValue type matches the field type
|
|
133
|
+
const defaultValue = fieldInput.defaultValue;
|
|
134
|
+
if (defaultValue !== undefined) {
|
|
135
|
+
switch (type) {
|
|
136
|
+
case 'string':
|
|
137
|
+
if (typeof defaultValue !== 'string') {
|
|
138
|
+
ctx.addIssue({
|
|
139
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
140
|
+
message: `Default value for String field "${fieldInput.name}" must be a string, but got ${typeof defaultValue}.`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case 'number':
|
|
145
|
+
if (typeof defaultValue !== 'number') {
|
|
146
|
+
ctx.addIssue({
|
|
147
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
148
|
+
message: `Default value for numeric field "${fieldInput.name}" must be a number, but got ${typeof defaultValue}.`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'boolean':
|
|
153
|
+
if (typeof defaultValue !== 'boolean') {
|
|
154
|
+
ctx.addIssue({
|
|
155
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
156
|
+
message: `Default value for Boolean field "${fieldInput.name}" must be a boolean, but got ${typeof defaultValue}.`,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'Date':
|
|
161
|
+
if (typeof defaultValue !== 'string') {
|
|
162
|
+
ctx.addIssue({
|
|
163
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
164
|
+
message: `Default value for DateTime field "${fieldInput.name}" must be an ISO date string, but got ${typeof defaultValue}.`,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else if (isNaN(Date.parse(defaultValue))) {
|
|
168
|
+
ctx.addIssue({
|
|
169
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
170
|
+
message: `Default value for DateTime field "${fieldInput.name}" must be a valid ISO 8601 date string, but got "${defaultValue}".`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
131
176
|
return {
|
|
132
177
|
type,
|
|
133
178
|
kind: exports.fieldKindScalar,
|
|
@@ -149,12 +194,13 @@ function fieldScalarJSONTransformer(fieldInput, ctx) {
|
|
|
149
194
|
min: undefined,
|
|
150
195
|
max: undefined,
|
|
151
196
|
},
|
|
197
|
+
defaultValue,
|
|
152
198
|
seed: (0, seed_1.seedTransformer)(fieldInput, ctx),
|
|
153
199
|
placeholder,
|
|
154
200
|
};
|
|
155
201
|
}
|
|
156
202
|
exports.zFieldScalar = exports.zFieldScalarJSON.transform(fieldScalarJSONTransformer);
|
|
157
|
-
const fieldScalarTransformer = ({ fieldInput: { type, validations, ...shared }, model: { name: modelName }, }) => {
|
|
203
|
+
const fieldScalarTransformer = ({ fieldInput: { type, validations, defaultValue, ...shared }, model: { name: modelName }, }) => {
|
|
158
204
|
switch (type) {
|
|
159
205
|
case 'string':
|
|
160
206
|
return {
|
|
@@ -162,6 +208,7 @@ const fieldScalarTransformer = ({ fieldInput: { type, validations, ...shared },
|
|
|
162
208
|
validations: {
|
|
163
209
|
maxLength: validations.maxLength,
|
|
164
210
|
},
|
|
211
|
+
defaultValue: defaultValue,
|
|
165
212
|
...shared,
|
|
166
213
|
modelName,
|
|
167
214
|
};
|
|
@@ -173,18 +220,21 @@ const fieldScalarTransformer = ({ fieldInput: { type, validations, ...shared },
|
|
|
173
220
|
min: validations.min,
|
|
174
221
|
max: validations.max,
|
|
175
222
|
},
|
|
223
|
+
defaultValue: defaultValue,
|
|
176
224
|
...shared,
|
|
177
225
|
modelName,
|
|
178
226
|
};
|
|
179
227
|
case 'boolean':
|
|
180
228
|
return {
|
|
181
229
|
type,
|
|
230
|
+
defaultValue: defaultValue,
|
|
182
231
|
...shared,
|
|
183
232
|
modelName,
|
|
184
233
|
};
|
|
185
234
|
case 'Date':
|
|
186
235
|
return {
|
|
187
236
|
type,
|
|
237
|
+
defaultValue: defaultValue,
|
|
188
238
|
...shared,
|
|
189
239
|
modelName,
|
|
190
240
|
};
|
|
@@ -15,3 +15,4 @@ export declare const zFieldFaker: z.ZodOptional<z.ZodString>;
|
|
|
15
15
|
export declare const zScalarValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>;
|
|
16
16
|
export declare const zFieldSeed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>>]>>;
|
|
17
17
|
export declare const zFieldPropertyPlaceholder: z.ZodOptional<z.ZodString>;
|
|
18
|
+
export declare const zFieldPropertyDefaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zFieldPropertyPlaceholder = exports.zFieldSeed = exports.zScalarValue = exports.zFieldFaker = 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.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;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const utils_1 = require("@postxl/utils");
|
|
6
6
|
exports.zFieldPropertyName = zod_1.z
|
|
@@ -88,3 +88,7 @@ exports.zFieldPropertyPlaceholder = zod_1.z
|
|
|
88
88
|
.string()
|
|
89
89
|
.optional()
|
|
90
90
|
.describe('A generic placeholder that is used to pre-populate empty fields.');
|
|
91
|
+
exports.zFieldPropertyDefaultValue = zod_1.z
|
|
92
|
+
.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()])
|
|
93
|
+
.optional()
|
|
94
|
+
.describe('An optional default value for the field. Must match the field type: string for String fields, number for numeric fields, boolean for Boolean fields, ISO date string for DateTime fields.');
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { zProjectSchema } from './project-schema/project-schema.transformer';
|
|
|
2
2
|
export * from './project-schema/project-schema.auth';
|
|
3
3
|
export * from './project-schema/project-schema.brands';
|
|
4
4
|
export * from './project-schema/project-schema.types';
|
|
5
|
+
export { defaultProjectRoles } from './project-schema/project-schema.defaults';
|
|
5
6
|
export type { ProjectSchemaJSON } from './project-schema/project-schema.json-decoder';
|
|
6
7
|
export type * from './enum/enum.brands';
|
|
7
8
|
export * from './enum/enum.defaults';
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.zProjectSchema = void 0;
|
|
17
|
+
exports.defaultProjectRoles = exports.zProjectSchema = void 0;
|
|
18
18
|
var project_schema_transformer_1 = require("./project-schema/project-schema.transformer");
|
|
19
19
|
Object.defineProperty(exports, "zProjectSchema", { enumerable: true, get: function () { return project_schema_transformer_1.zProjectSchema; } });
|
|
20
20
|
__exportStar(require("./project-schema/project-schema.auth"), exports);
|
|
21
21
|
__exportStar(require("./project-schema/project-schema.brands"), exports);
|
|
22
22
|
__exportStar(require("./project-schema/project-schema.types"), exports);
|
|
23
|
+
var project_schema_defaults_1 = require("./project-schema/project-schema.defaults");
|
|
24
|
+
Object.defineProperty(exports, "defaultProjectRoles", { enumerable: true, get: function () { return project_schema_defaults_1.defaultProjectRoles; } });
|
|
23
25
|
__exportStar(require("./enum/enum.defaults"), exports);
|
|
24
26
|
__exportStar(require("./field"), exports);
|
|
25
27
|
__exportStar(require("./model/model.defaults"), exports);
|
|
@@ -7,6 +7,10 @@ export declare const databaseSchemaNameData: string & import("zod").$brand<"PXL.
|
|
|
7
7
|
* The name of the schema that contains the configuration of the project.
|
|
8
8
|
*/
|
|
9
9
|
export declare const databaseSchemaNameConfig: string & import("zod").$brand<"PXL.DatabaseSchemaName">;
|
|
10
|
+
/**
|
|
11
|
+
* The default project roles. Can be overridden via `defaultRoles` in the project schema.
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultProjectRoles: readonly ["superadmin", "admin", "editor", "viewer"];
|
|
10
14
|
export declare const defaultSystemUser: {
|
|
11
15
|
id: string;
|
|
12
16
|
sub: null;
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.defaultSystemUser = exports.databaseSchemaNameConfig = exports.databaseSchemaNameData = void 0;
|
|
36
|
+
exports.defaultSystemUser = exports.defaultProjectRoles = exports.databaseSchemaNameConfig = exports.databaseSchemaNameData = void 0;
|
|
37
37
|
const Branded = __importStar(require("./project-schema.brands"));
|
|
38
38
|
/**
|
|
39
39
|
* The name of the default data schema of the project.
|
|
@@ -44,6 +44,10 @@ exports.databaseSchemaNameData = Branded.toDatabaseSchemaName('Data');
|
|
|
44
44
|
* The name of the schema that contains the configuration of the project.
|
|
45
45
|
*/
|
|
46
46
|
exports.databaseSchemaNameConfig = Branded.toDatabaseSchemaName('PXL');
|
|
47
|
+
/**
|
|
48
|
+
* The default project roles. Can be overridden via `defaultRoles` in the project schema.
|
|
49
|
+
*/
|
|
50
|
+
exports.defaultProjectRoles = ['superadmin', 'admin', 'editor', 'viewer'];
|
|
47
51
|
exports.defaultSystemUser = {
|
|
48
52
|
id: 'root',
|
|
49
53
|
sub: null,
|
|
@@ -70,6 +70,7 @@ export declare const zProjectSchemaJSON: z.ZodPipe<z.ZodTransform<unknown, unkno
|
|
|
70
70
|
}, z.core.$strip>>>;
|
|
71
71
|
}, z.core.$strip>>;
|
|
72
72
|
systemUser: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
73
|
+
defaultRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
74
|
standardModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
74
75
|
models: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
75
76
|
name: z.ZodString;
|
|
@@ -124,6 +124,12 @@ exports.zProjectSchemaJSON = zod_1.z
|
|
|
124
124
|
.record(zod_1.z.string(), zod_1.z.any())
|
|
125
125
|
.optional()
|
|
126
126
|
.describe('The system user that is used for root/system tasks, e.g. data seeding.'),
|
|
127
|
+
defaultRoles: zod_1.z
|
|
128
|
+
//
|
|
129
|
+
.array(zod_1.z.string().min(1, { error: 'Role must not be empty.' }))
|
|
130
|
+
.min(1, { error: 'defaultRoles must contain at least one role.' })
|
|
131
|
+
.optional()
|
|
132
|
+
.describe(`Override the default project roles. If not provided, the default roles ["superadmin", "admin", "editor", "viewer"] are used. Roles from auth rules are added on top of these defaults.`),
|
|
127
133
|
standardModels: zod_1.z
|
|
128
134
|
//
|
|
129
135
|
.array(Model.zModelNameJSON)
|
|
@@ -49,6 +49,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown,
|
|
|
49
49
|
}, z.core.$strip>>>;
|
|
50
50
|
}, z.core.$strip>>;
|
|
51
51
|
systemUser: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
52
|
+
defaultRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
52
53
|
standardModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
54
|
models: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
54
55
|
name: z.ZodString;
|
|
@@ -153,6 +154,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown,
|
|
|
153
154
|
}> | undefined;
|
|
154
155
|
} | undefined;
|
|
155
156
|
systemUser?: Record<string, any> | undefined;
|
|
157
|
+
defaultRoles?: string[] | undefined;
|
|
156
158
|
standardModels?: string[] | undefined;
|
|
157
159
|
models?: {
|
|
158
160
|
name: string;
|
|
@@ -100,6 +100,7 @@ function addDefaults(input) {
|
|
|
100
100
|
...project_schema_defaults_1.defaultSystemUser,
|
|
101
101
|
...input.systemUser,
|
|
102
102
|
},
|
|
103
|
+
defaultRoles: input.defaultRoles ?? [...project_schema_defaults_1.defaultProjectRoles],
|
|
103
104
|
standardModels: input.standardModels ?? Array.from(Object.values(Model.defaultModelNames)),
|
|
104
105
|
models: input.models ?? new Map(),
|
|
105
106
|
standardEnums: input.standardEnums ?? Array.from(Object.values(Enum.defaultEnumNames)),
|
|
@@ -40,6 +40,11 @@ export type ProjectSchema = {
|
|
|
40
40
|
* If not provided, the default schema "Data" is used.
|
|
41
41
|
*/
|
|
42
42
|
defaultDatabaseSchema: Branded.DatabaseSchemaName;
|
|
43
|
+
/**
|
|
44
|
+
* The default roles for this project. Roles from auth rules are added on top of these.
|
|
45
|
+
* If not provided in the schema, defaults to ['superadmin', 'admin', 'editor', 'viewer'].
|
|
46
|
+
*/
|
|
47
|
+
defaultRoles: string[];
|
|
43
48
|
/**
|
|
44
49
|
* Global authorization configuration for this project.
|
|
45
50
|
*/
|
package/package.json
CHANGED