@postxl/schema 1.11.0 → 2.0.1
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.d.ts +1 -1
- package/dist/enum/enum.defaults.d.ts +12 -0
- package/dist/enum/enum.defaults.js +13 -1
- package/dist/enum/enum.json-decoder.d.ts +1 -1
- package/dist/field/field.d.ts +4 -50
- package/dist/field/field.js +0 -9
- package/dist/field/index.d.ts +0 -1
- package/dist/field/index.js +0 -1
- package/dist/field/scalar.d.ts +1 -1
- package/dist/field/shared/brands.d.ts +0 -3
- package/dist/field/shared/brands.js +1 -9
- package/dist/field/shared/utils.js +0 -2
- package/dist/model/model.defaults.js +28 -39
- package/dist/model/model.json-decoder.d.ts +1 -1
- package/dist/project-schema/project-schema.json-decoder.d.ts +3 -3
- package/dist/project-schema/project-schema.json-decoder.js +1 -1
- package/dist/project-schema/project-schema.transformer.d.ts +3 -3
- package/dist/samples/sample-schemas.d.ts +2 -61
- package/dist/samples/simple.schema.json +2 -35
- package/dist/samples/steerex.schema.json +2 -23
- package/dist/samples/usp-msm.schema.json +28 -39
- package/package.json +2 -2
- package/dist/field/discriminated-union.d.ts +0 -89
- package/dist/field/discriminated-union.js +0 -253
package/dist/enum/enum.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const zEnum: import("zod").ZodPipe<import("zod").
|
|
1
|
+
export declare const zEnum: import("zod").ZodPipe<import("zod").ZodPreprocess<import("zod").ZodObject<{
|
|
2
2
|
name: import("zod").ZodString;
|
|
3
3
|
description: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
|
|
4
4
|
schema: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -3,10 +3,12 @@ import { EnumJSON } from './enum.json-decoder';
|
|
|
3
3
|
export declare const defaultEnumName_ActionStatus: string & import("zod").$brand<"PXL.EnumName">;
|
|
4
4
|
export declare const defaultEnumName_MutationStatus: string & import("zod").$brand<"PXL.EnumName">;
|
|
5
5
|
export declare const defaultEnumName_MutationKind: string & import("zod").$brand<"PXL.EnumName">;
|
|
6
|
+
export declare const defaultEnumName_ActionOperationKind: string & import("zod").$brand<"PXL.EnumName">;
|
|
6
7
|
export declare const defaultEnumNames: {
|
|
7
8
|
actionStatus: string & import("zod").$brand<"PXL.EnumName">;
|
|
8
9
|
mutationStatus: string & import("zod").$brand<"PXL.EnumName">;
|
|
9
10
|
mutationKind: string & import("zod").$brand<"PXL.EnumName">;
|
|
11
|
+
actionOperationKind: string & import("zod").$brand<"PXL.EnumName">;
|
|
10
12
|
};
|
|
11
13
|
export declare const defaultEnumJson_ActionStatus: {
|
|
12
14
|
name: string;
|
|
@@ -38,4 +40,14 @@ export declare const defaultEnumJson_MutationKind: {
|
|
|
38
40
|
schema?: string | undefined;
|
|
39
41
|
databaseName?: string | undefined;
|
|
40
42
|
};
|
|
43
|
+
export declare const defaultEnumJson_ActionOperationKind: {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
members: (string | {
|
|
47
|
+
value: string;
|
|
48
|
+
description?: string | undefined;
|
|
49
|
+
})[];
|
|
50
|
+
schema?: string | undefined;
|
|
51
|
+
databaseName?: string | undefined;
|
|
52
|
+
};
|
|
41
53
|
export declare const defaultEnumsJson: Record<Branded.EnumName, EnumJSON>;
|
|
@@ -33,17 +33,19 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.defaultEnumsJson = exports.defaultEnumJson_MutationKind = exports.defaultEnumJson_MutationStatus = exports.defaultEnumJson_ActionStatus = exports.defaultEnumNames = exports.defaultEnumName_MutationKind = exports.defaultEnumName_MutationStatus = exports.defaultEnumName_ActionStatus = void 0;
|
|
36
|
+
exports.defaultEnumsJson = exports.defaultEnumJson_ActionOperationKind = exports.defaultEnumJson_MutationKind = exports.defaultEnumJson_MutationStatus = exports.defaultEnumJson_ActionStatus = exports.defaultEnumNames = exports.defaultEnumName_ActionOperationKind = exports.defaultEnumName_MutationKind = exports.defaultEnumName_MutationStatus = exports.defaultEnumName_ActionStatus = void 0;
|
|
37
37
|
const project_schema_defaults_1 = require("../project-schema/project-schema.defaults");
|
|
38
38
|
const Branded = __importStar(require("./enum.brands"));
|
|
39
39
|
const enum_json_decoder_1 = require("./enum.json-decoder");
|
|
40
40
|
exports.defaultEnumName_ActionStatus = Branded.toEnumName('ActionStatus');
|
|
41
41
|
exports.defaultEnumName_MutationStatus = Branded.toEnumName('MutationStatus');
|
|
42
42
|
exports.defaultEnumName_MutationKind = Branded.toEnumName('MutationKind');
|
|
43
|
+
exports.defaultEnumName_ActionOperationKind = Branded.toEnumName('ActionOperationKind');
|
|
43
44
|
exports.defaultEnumNames = {
|
|
44
45
|
actionStatus: exports.defaultEnumName_ActionStatus,
|
|
45
46
|
mutationStatus: exports.defaultEnumName_MutationStatus,
|
|
46
47
|
mutationKind: exports.defaultEnumName_MutationKind,
|
|
48
|
+
actionOperationKind: exports.defaultEnumName_ActionOperationKind,
|
|
47
49
|
};
|
|
48
50
|
exports.defaultEnumJson_ActionStatus = enum_json_decoder_1.zEnumJSON.parse({
|
|
49
51
|
name: exports.defaultEnumName_ActionStatus,
|
|
@@ -98,8 +100,18 @@ exports.defaultEnumJson_MutationKind = enum_json_decoder_1.zEnumJSON.parse({
|
|
|
98
100
|
{ value: 'CloneMany', description: 'Clone multiple existing items.' },
|
|
99
101
|
],
|
|
100
102
|
});
|
|
103
|
+
exports.defaultEnumJson_ActionOperationKind = enum_json_decoder_1.zEnumJSON.parse({
|
|
104
|
+
name: exports.defaultEnumName_ActionOperationKind,
|
|
105
|
+
description: 'The kind of an action operation.',
|
|
106
|
+
schema: project_schema_defaults_1.databaseSchemaNameConfig,
|
|
107
|
+
members: [
|
|
108
|
+
{ value: 'Transformation', description: 'A transformation step that reshapes the payload.' },
|
|
109
|
+
{ value: 'Mutation', description: 'A mutation step that creates, updates or deletes data.' },
|
|
110
|
+
],
|
|
111
|
+
});
|
|
101
112
|
exports.defaultEnumsJson = {
|
|
102
113
|
[exports.defaultEnumName_ActionStatus]: exports.defaultEnumJson_ActionStatus,
|
|
103
114
|
[exports.defaultEnumName_MutationStatus]: exports.defaultEnumJson_MutationStatus,
|
|
104
115
|
[exports.defaultEnumName_MutationKind]: exports.defaultEnumJson_MutationKind,
|
|
116
|
+
[exports.defaultEnumName_ActionOperationKind]: exports.defaultEnumJson_ActionOperationKind,
|
|
105
117
|
};
|
|
@@ -12,7 +12,7 @@ export declare const zEnumMemberJSON: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>, z.ZodString]>;
|
|
13
13
|
export type EnumMemberJSON = z.infer<typeof zEnumMemberJSON>;
|
|
14
14
|
export declare const zEnumNameJSON: z.ZodString;
|
|
15
|
-
export declare const zEnumJSON: z.
|
|
15
|
+
export declare const zEnumJSON: z.ZodPreprocess<z.ZodObject<{
|
|
16
16
|
name: z.ZodString;
|
|
17
17
|
description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
18
|
schema: z.ZodOptional<z.ZodString>;
|
package/dist/field/field.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { z } from 'zod';
|
|
|
2
2
|
import * as Enum from '../enum';
|
|
3
3
|
import * as Model from '../model';
|
|
4
4
|
import * as Branded from './shared/brands';
|
|
5
|
-
import { FieldDiscriminatedUnion, FieldDiscriminatedUnionEnriched } from './discriminated-union';
|
|
6
5
|
import { FieldEnum, FieldEnumEnriched } from './enum';
|
|
7
6
|
import { FieldId, FieldIdEnriched } from './id';
|
|
8
7
|
import { FieldJson, FieldJsonEnriched } from './json';
|
|
@@ -69,7 +68,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
69
68
|
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
70
69
|
}, z.core.$strict>, z.ZodTransform<FieldScalarEnriched, {
|
|
71
70
|
name: string;
|
|
72
|
-
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "
|
|
71
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "Int?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Bytes?" | "BigInt?";
|
|
73
72
|
databaseName?: string | undefined;
|
|
74
73
|
excelName?: string | undefined;
|
|
75
74
|
label?: string | undefined;
|
|
@@ -106,50 +105,6 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
106
105
|
isUnique?: boolean | undefined;
|
|
107
106
|
hasIndex?: boolean | undefined;
|
|
108
107
|
placeholder?: string | undefined;
|
|
109
|
-
}>>, z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
110
|
-
name: z.ZodString;
|
|
111
|
-
type: z.ZodUnion<[z.ZodLiteral<"DiscriminatedUnion">, z.ZodLiteral<"DiscriminatedUnion?">]>;
|
|
112
|
-
label: z.ZodOptional<z.ZodString>;
|
|
113
|
-
description: z.ZodOptional<z.ZodString>;
|
|
114
|
-
databaseName: z.ZodOptional<z.ZodString>;
|
|
115
|
-
excelName: z.ZodOptional<z.ZodString>;
|
|
116
|
-
members: z.ZodArray<z.ZodObject<{
|
|
117
|
-
type: z.ZodString;
|
|
118
|
-
label: z.ZodOptional<z.ZodString>;
|
|
119
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
120
|
-
}, z.core.$strip>>;
|
|
121
|
-
commonFields: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
122
|
-
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
-
}, z.core.$strip>>, z.ZodTransform<{
|
|
124
|
-
kind: "discriminatedUnion";
|
|
125
|
-
name: string & z.core.$brand<"PXL.FieldName">;
|
|
126
|
-
discriminatorFieldName: string & z.core.$brand<"PXL.FieldName">;
|
|
127
|
-
label: string;
|
|
128
|
-
databaseName: string & z.core.$brand<"PXL.DatabaseFieldName">;
|
|
129
|
-
excelName: string & z.core.$brand<"PXL.ExcelColumnName">;
|
|
130
|
-
description: string | undefined;
|
|
131
|
-
members: {
|
|
132
|
-
type: string;
|
|
133
|
-
label?: string | undefined;
|
|
134
|
-
fields?: Record<string, any>[] | undefined;
|
|
135
|
-
}[];
|
|
136
|
-
commonFields: Record<string, any>[] | undefined;
|
|
137
|
-
isReadonly: boolean;
|
|
138
|
-
isRequired: boolean;
|
|
139
|
-
}, {
|
|
140
|
-
name: string;
|
|
141
|
-
type: "DiscriminatedUnion" | "DiscriminatedUnion?";
|
|
142
|
-
members: {
|
|
143
|
-
type: string;
|
|
144
|
-
label?: string | undefined;
|
|
145
|
-
fields?: Record<string, any>[] | undefined;
|
|
146
|
-
}[];
|
|
147
|
-
label?: string | undefined;
|
|
148
|
-
description?: string | undefined;
|
|
149
|
-
databaseName?: string | undefined;
|
|
150
|
-
excelName?: string | undefined;
|
|
151
|
-
commonFields?: Record<string, any>[] | undefined;
|
|
152
|
-
isReadonly?: boolean | undefined;
|
|
153
108
|
}>>, z.ZodPipe<z.ZodObject<{
|
|
154
109
|
name: z.ZodString;
|
|
155
110
|
type: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
@@ -226,7 +181,7 @@ export declare const createFieldJSONDecoder: (params: {
|
|
|
226
181
|
isReadonly?: boolean | undefined;
|
|
227
182
|
isUnique?: boolean | undefined;
|
|
228
183
|
}>>]>;
|
|
229
|
-
export type FieldEnriched = FieldIdEnriched | FieldScalarEnriched | FieldJsonEnriched | FieldRelationEnriched | FieldEnumEnriched
|
|
184
|
+
export type FieldEnriched = FieldIdEnriched | FieldScalarEnriched | FieldJsonEnriched | FieldRelationEnriched | FieldEnumEnriched;
|
|
230
185
|
export type FieldEnrichedNativeDatabase = FieldIdEnriched | FieldScalarEnriched | FieldJsonEnriched | FieldRelationEnriched | FieldEnumEnriched;
|
|
231
186
|
export declare const zFieldJSONInput: (params: {
|
|
232
187
|
modelNames: Model.ModelName[];
|
|
@@ -305,8 +260,7 @@ export declare const fieldTransformer: (fieldInput: FieldEnriched, model: {
|
|
|
305
260
|
name: Model.ModelName;
|
|
306
261
|
isReadonly?: boolean;
|
|
307
262
|
}>;
|
|
308
|
-
}, ctx: z.RefinementCtx) =>
|
|
263
|
+
}, ctx: z.RefinementCtx) => FieldId | FieldScalar | FieldJson | FieldRelation | FieldEnum;
|
|
309
264
|
export type FieldDatabaseNative = FieldId | FieldScalar | FieldJson | FieldRelation | FieldEnum;
|
|
310
|
-
export
|
|
311
|
-
export type Field = FieldDatabaseNative | FieldDiscriminatedUnion;
|
|
265
|
+
export type Field = FieldDatabaseNative;
|
|
312
266
|
export type Fields<FIELD = Field> = Map<Branded.FieldName, FIELD>;
|
package/dist/field/field.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fieldTransformer = exports.zFieldJSONInput = exports.createFieldJSONDecoder = void 0;
|
|
4
|
-
exports.isFieldDatabaseNative = isFieldDatabaseNative;
|
|
5
4
|
const zod_1 = require("zod");
|
|
6
5
|
const utils_1 = require("@postxl/utils");
|
|
7
|
-
const discriminated_union_1 = require("./discriminated-union");
|
|
8
6
|
const enum_1 = require("./enum");
|
|
9
7
|
const id_1 = require("./id");
|
|
10
8
|
const json_1 = require("./json");
|
|
@@ -19,7 +17,6 @@ const scalar_1 = require("./scalar");
|
|
|
19
17
|
- json: a JSON field stored as database Json and typed as unknown
|
|
20
18
|
- relation: a field that is a relation to another model
|
|
21
19
|
- enum: a field that is an enum
|
|
22
|
-
- discriminatedUnion: a field that is a discriminated union
|
|
23
20
|
|
|
24
21
|
To differentiate between these kinds, we check the `type` of the field:
|
|
25
22
|
- if `name` is `id`, we know that it is an id field
|
|
@@ -34,7 +31,6 @@ const createFieldJSONDecoder = (params) => zod_1.z.union([
|
|
|
34
31
|
id_1.zFieldIdJSON.transform(id_1.fieldIdJSONTransformer),
|
|
35
32
|
scalar_1.zFieldScalarJSON.transform(scalar_1.fieldScalarJSONTransformer),
|
|
36
33
|
json_1.zFieldJsonJSON.transform(json_1.fieldJsonJSONTransformer),
|
|
37
|
-
discriminated_union_1.zFieldDiscriminatedUnionJSON.transform(discriminated_union_1.fieldDiscriminatedUnionJSONTransformer),
|
|
38
34
|
// As relation and enum fields have flexible type names (i.e. the names of the referenced model/enum) and we use the
|
|
39
35
|
// type property to determine the type of the field, we need to handle these last
|
|
40
36
|
(0, relation_1.createRelationJSONDecoder)(params).transform(relation_1.fieldRelationJSONTransformer),
|
|
@@ -58,8 +54,6 @@ const fieldTransformer = (fieldInput, model, projectSchema, ctx) => {
|
|
|
58
54
|
return (0, scalar_1.fieldScalarTransformer)({ fieldInput, model, projectSchema }, ctx);
|
|
59
55
|
case 'json':
|
|
60
56
|
return (0, json_1.fieldJsonTransformer)({ fieldInput, model, projectSchema }, ctx);
|
|
61
|
-
case 'discriminatedUnion':
|
|
62
|
-
return (0, discriminated_union_1.fieldDiscriminatedUnionTransformer)({ fieldInput, model, projectSchema }, ctx);
|
|
63
57
|
case 'relation':
|
|
64
58
|
return (0, relation_1.fieldRelationTransformer)({ fieldInput, model, projectSchema }, ctx);
|
|
65
59
|
case 'enum':
|
|
@@ -69,6 +63,3 @@ const fieldTransformer = (fieldInput, model, projectSchema, ctx) => {
|
|
|
69
63
|
}
|
|
70
64
|
};
|
|
71
65
|
exports.fieldTransformer = fieldTransformer;
|
|
72
|
-
function isFieldDatabaseNative(field) {
|
|
73
|
-
return field.kind !== 'discriminatedUnion';
|
|
74
|
-
}
|
package/dist/field/index.d.ts
CHANGED
package/dist/field/index.js
CHANGED
|
@@ -14,7 +14,6 @@ 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
|
-
__exportStar(require("./discriminated-union"), exports);
|
|
18
17
|
__exportStar(require("./defaults"), exports);
|
|
19
18
|
__exportStar(require("./enum"), exports);
|
|
20
19
|
__exportStar(require("./field"), exports);
|
package/dist/field/scalar.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export declare const zFieldScalar: z.ZodPipe<z.ZodObject<{
|
|
|
103
103
|
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
104
104
|
}, z.core.$strict>, z.ZodTransform<FieldScalarEnriched, {
|
|
105
105
|
name: string;
|
|
106
|
-
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "
|
|
106
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Bytes" | "String?" | "Int?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Bytes?" | "BigInt?";
|
|
107
107
|
databaseName?: string | undefined;
|
|
108
108
|
excelName?: string | undefined;
|
|
109
109
|
label?: string | undefined;
|
|
@@ -30,9 +30,6 @@ export declare const toScalarIdType: (input: string) => ("string" & z.core.$bran
|
|
|
30
30
|
export declare const zEnumType: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.EnumType", "out">, "PXL.Type", "out">;
|
|
31
31
|
export type EnumType = z.infer<typeof zEnumType>;
|
|
32
32
|
export declare const toEnumType: (input: string) => string & z.core.$brand<"PXL.EnumType"> & z.core.$brand<"PXL.Type">;
|
|
33
|
-
export declare const zDiscriminatedUnionType: z.core.$ZodBranded<z.core.$ZodBranded<z.ZodString, "PXL.DiscriminatedUnionType", "out">, "PXL.Type", "out">;
|
|
34
|
-
export type DiscriminatedUnionType = z.infer<typeof zDiscriminatedUnionType>;
|
|
35
|
-
export declare const toDiscriminatedUnionType: (input: string) => string & z.core.$brand<"PXL.DiscriminatedUnionType"> & z.core.$brand<"PXL.Type">;
|
|
36
33
|
export declare const zDatabaseFieldType: z.core.$ZodBranded<z.ZodUnion<readonly [z.ZodLiteral<"BigInt">, z.ZodLiteral<"String">, z.ZodLiteral<"Boolean">, z.ZodLiteral<"DateTime">, z.ZodLiteral<"Decimal">, z.ZodLiteral<"Float">, z.ZodLiteral<"Int">, z.ZodLiteral<"Json">, z.ZodLiteral<"Bytes">]>, "PXL.DatabaseFieldType", "out">;
|
|
37
34
|
export type DatabaseFieldType = z.infer<typeof zDatabaseFieldType>;
|
|
38
35
|
export declare const toDatabaseFieldType: (input: string) => ("BigInt" & z.core.$brand<"PXL.DatabaseFieldType">) | ("String" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Boolean" & z.core.$brand<"PXL.DatabaseFieldType">) | ("DateTime" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Decimal" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Float" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Int" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Json" & z.core.$brand<"PXL.DatabaseFieldType">) | ("Bytes" & z.core.$brand<"PXL.DatabaseFieldType">);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDatabaseFieldType = exports.zDatabaseFieldType = exports.
|
|
3
|
+
exports.toDatabaseFieldType = exports.zDatabaseFieldType = exports.toEnumType = exports.zEnumType = exports.toScalarIdType = exports.zScalarIdType = exports.toScalarType = exports.zScalarType = exports.toIdType = exports.zIdType = exports.toType = exports.zType = exports.toFieldLabel = exports.zFieldLabel = exports.toExcelColumnName = exports.zExcelColumnName = exports.toDatabaseFieldName = exports.zDatabaseFieldName = exports.toFieldIdName = exports.zFieldIdName = exports.toFieldName = exports.zFieldName = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const utils_1 = require("@postxl/utils");
|
|
6
6
|
// --- Names ---------------------------------------------------------------------------------------
|
|
@@ -100,14 +100,6 @@ exports.zEnumType = zod_1.z
|
|
|
100
100
|
.describe('The name of the TypeScript type that represents an enum, e.g. `ActionStatus`');
|
|
101
101
|
const toEnumType = (input) => exports.zEnumType.parse(input);
|
|
102
102
|
exports.toEnumType = toEnumType;
|
|
103
|
-
exports.zDiscriminatedUnionType = zod_1.z
|
|
104
|
-
.string()
|
|
105
|
-
.refine(utils_1.isPascalCase, { error: 'Discriminated union name must be PascalCase' })
|
|
106
|
-
.brand('PXL.DiscriminatedUnionType')
|
|
107
|
-
.brand('PXL.Type')
|
|
108
|
-
.describe('The name of the TypeScript type that represents a discriminated union, e.g. `ActionStatus`');
|
|
109
|
-
const toDiscriminatedUnionType = (input) => exports.zDiscriminatedUnionType.parse(input);
|
|
110
|
-
exports.toDiscriminatedUnionType = toDiscriminatedUnionType;
|
|
111
103
|
// --- Database ---------------------------------------------------------------------------------------
|
|
112
104
|
exports.zDatabaseFieldType = zod_1.z
|
|
113
105
|
.union([
|
|
@@ -219,45 +219,34 @@ Transformation: Depends on the transformation`,
|
|
|
219
219
|
description: 'In case of an error: JSON string with the error details.',
|
|
220
220
|
},
|
|
221
221
|
{
|
|
222
|
-
name: '
|
|
223
|
-
type: '
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
type: 'String?',
|
|
251
|
-
description: "The id of the affected entity. Depending on the type of the mutation, this is the following:\n\t'Create': the newly created entity's ID\n\t'CreateMany': A stringified array of all created entities' IDs\n\t'Update' & 'Delete': id that was provided as input.",
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
name: 'sourceEntity',
|
|
255
|
-
type: 'String?',
|
|
256
|
-
description: 'The original entity before the mutation was executed. Null in case of a create mutation.',
|
|
257
|
-
},
|
|
258
|
-
],
|
|
259
|
-
},
|
|
260
|
-
],
|
|
222
|
+
name: 'contentKind',
|
|
223
|
+
type: 'ActionOperationKind?',
|
|
224
|
+
description: "The kind of operation: 'Transformation' or 'Mutation'.",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: 'contentTransformationOperation',
|
|
228
|
+
type: 'String?',
|
|
229
|
+
description: 'For transformation operations: the operation that is executed on the payload.',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'contentMutationModel',
|
|
233
|
+
type: 'String?',
|
|
234
|
+
description: 'For mutation operations: which model is affected by the mutation.',
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'contentMutationKind',
|
|
238
|
+
type: 'MutationKind?',
|
|
239
|
+
description: "For mutation operations: the type of the mutation: 'Create' | 'CreateMany' | 'Update' | 'Upsert' | 'Delete' | ...",
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'contentMutationEntityId',
|
|
243
|
+
type: 'String?',
|
|
244
|
+
description: "For mutation operations: the id of the affected entity. Depending on the type of the mutation, this is the following:\n\t'Create': the newly created entity's ID\n\t'CreateMany': A stringified array of all created entities' IDs\n\t'Update' & 'Delete': id that was provided as input.",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'contentMutationSourceEntity',
|
|
248
|
+
type: 'String?',
|
|
249
|
+
description: 'For mutation operations: the original entity before the mutation was executed. Null in case of a create mutation.',
|
|
261
250
|
},
|
|
262
251
|
],
|
|
263
252
|
repository: { type: 'DatabaseDirect' },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const zModelNameJSON: z.ZodString;
|
|
3
|
-
export declare const zModelJSON: z.
|
|
3
|
+
export declare const zModelJSON: z.ZodPreprocess<z.ZodObject<{
|
|
4
4
|
name: z.ZodString;
|
|
5
5
|
description: z.ZodOptional<z.ZodString>;
|
|
6
6
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -26,7 +26,7 @@ export declare const zSchemaJSON: z.ZodObject<{
|
|
|
26
26
|
}, z.core.$strip>>;
|
|
27
27
|
}, z.core.$strip>>;
|
|
28
28
|
}, z.core.$strip>;
|
|
29
|
-
export declare const zProjectSchemaJSON: z.
|
|
29
|
+
export declare const zProjectSchemaJSON: z.ZodPreprocess<z.ZodObject<{
|
|
30
30
|
name: z.ZodString;
|
|
31
31
|
slug: z.ZodString;
|
|
32
32
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -72,7 +72,7 @@ export declare const zProjectSchemaJSON: z.ZodPipe<z.ZodTransform<unknown, unkno
|
|
|
72
72
|
systemUser: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
73
73
|
defaultRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
74
74
|
standardModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
-
models: z.ZodOptional<z.ZodArray<z.
|
|
75
|
+
models: z.ZodOptional<z.ZodArray<z.ZodPreprocess<z.ZodObject<{
|
|
76
76
|
name: z.ZodString;
|
|
77
77
|
description: z.ZodOptional<z.ZodString>;
|
|
78
78
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -119,7 +119,7 @@ export declare const zProjectSchemaJSON: z.ZodPipe<z.ZodTransform<unknown, unkno
|
|
|
119
119
|
}, z.core.$strip>>;
|
|
120
120
|
}, z.core.$strip>>>>;
|
|
121
121
|
standardEnums: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
122
|
-
enums: z.ZodOptional<z.ZodArray<z.
|
|
122
|
+
enums: z.ZodOptional<z.ZodArray<z.ZodPreprocess<z.ZodObject<{
|
|
123
123
|
name: z.ZodString;
|
|
124
124
|
description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
125
125
|
schema: z.ZodOptional<z.ZodString>;
|
|
@@ -147,7 +147,7 @@ If any of the standard models are also provided in the \`models\` array, the cus
|
|
|
147
147
|
//
|
|
148
148
|
.array(Enum.zEnumNameJSON)
|
|
149
149
|
.optional().describe(`Names of standard enums that should be included in the project.
|
|
150
|
-
Currently, the following fields are supported: ActionStatus, MutationStatus, MutationKind.
|
|
150
|
+
Currently, the following fields are supported: ActionStatus, MutationStatus, MutationKind, ActionOperationKind.
|
|
151
151
|
If not provided, all enums are included by default.
|
|
152
152
|
|
|
153
153
|
If any of the standard enums are also provided in the \`enums\` array, the custom enums will take precedence.`),
|
|
@@ -5,7 +5,7 @@ export declare function transformProjectSchemaJSON(input: ProjectSchemaJSON, ctx
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod decoder that converts JSON (see `ProjectSchemaJSON`) to a `ProjectSchema`
|
|
7
7
|
*/
|
|
8
|
-
export declare const zProjectSchema: z.ZodPipe<z.
|
|
8
|
+
export declare const zProjectSchema: z.ZodPipe<z.ZodPreprocess<z.ZodObject<{
|
|
9
9
|
name: z.ZodString;
|
|
10
10
|
slug: z.ZodString;
|
|
11
11
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -51,7 +51,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown,
|
|
|
51
51
|
systemUser: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
52
52
|
defaultRoles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
53
|
standardModels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
54
|
-
models: z.ZodOptional<z.ZodArray<z.
|
|
54
|
+
models: z.ZodOptional<z.ZodArray<z.ZodPreprocess<z.ZodObject<{
|
|
55
55
|
name: z.ZodString;
|
|
56
56
|
description: z.ZodOptional<z.ZodString>;
|
|
57
57
|
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -98,7 +98,7 @@ export declare const zProjectSchema: z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown,
|
|
|
98
98
|
}, z.core.$strip>>;
|
|
99
99
|
}, z.core.$strip>>>>;
|
|
100
100
|
standardEnums: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
101
|
-
enums: z.ZodOptional<z.ZodArray<z.
|
|
101
|
+
enums: z.ZodOptional<z.ZodArray<z.ZodPreprocess<z.ZodObject<{
|
|
102
102
|
name: z.ZodString;
|
|
103
103
|
description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
104
104
|
schema: z.ZodOptional<z.ZodString>;
|
|
@@ -1786,39 +1786,6 @@ export declare const sampleSchemas: {
|
|
|
1786
1786
|
type: string;
|
|
1787
1787
|
label: string;
|
|
1788
1788
|
faker: string;
|
|
1789
|
-
commonFields?: never;
|
|
1790
|
-
members?: never;
|
|
1791
|
-
description?: never;
|
|
1792
|
-
} | {
|
|
1793
|
-
name: string;
|
|
1794
|
-
type: string;
|
|
1795
|
-
label: string;
|
|
1796
|
-
commonFields: {
|
|
1797
|
-
name: string;
|
|
1798
|
-
type: string;
|
|
1799
|
-
faker: string;
|
|
1800
|
-
}[];
|
|
1801
|
-
members: ({
|
|
1802
|
-
type: string;
|
|
1803
|
-
label: string;
|
|
1804
|
-
fields: {
|
|
1805
|
-
name: string;
|
|
1806
|
-
type: string;
|
|
1807
|
-
}[];
|
|
1808
|
-
} | {
|
|
1809
|
-
type: string;
|
|
1810
|
-
label: string;
|
|
1811
|
-
fields: {
|
|
1812
|
-
name: string;
|
|
1813
|
-
type: string;
|
|
1814
|
-
faker: string;
|
|
1815
|
-
}[];
|
|
1816
|
-
} | {
|
|
1817
|
-
type: string;
|
|
1818
|
-
label: string;
|
|
1819
|
-
fields?: never;
|
|
1820
|
-
})[];
|
|
1821
|
-
faker?: never;
|
|
1822
1789
|
description?: never;
|
|
1823
1790
|
} | {
|
|
1824
1791
|
name: string;
|
|
@@ -1826,8 +1793,6 @@ export declare const sampleSchemas: {
|
|
|
1826
1793
|
label: string;
|
|
1827
1794
|
description: string;
|
|
1828
1795
|
faker?: never;
|
|
1829
|
-
commonFields?: never;
|
|
1830
|
-
members?: never;
|
|
1831
1796
|
})[];
|
|
1832
1797
|
standardFields: string[];
|
|
1833
1798
|
labelField: string;
|
|
@@ -3300,21 +3265,10 @@ export declare const sampleSchemas: {
|
|
|
3300
3265
|
name: string;
|
|
3301
3266
|
type: string;
|
|
3302
3267
|
label?: never;
|
|
3303
|
-
commonFields?: never;
|
|
3304
|
-
members?: never;
|
|
3305
3268
|
} | {
|
|
3306
3269
|
name: string;
|
|
3307
3270
|
type: string;
|
|
3308
3271
|
label: string;
|
|
3309
|
-
commonFields: never[];
|
|
3310
|
-
members: {
|
|
3311
|
-
type: string;
|
|
3312
|
-
label: string;
|
|
3313
|
-
fields: {
|
|
3314
|
-
name: string;
|
|
3315
|
-
type: string;
|
|
3316
|
-
}[];
|
|
3317
|
-
}[];
|
|
3318
3272
|
})[];
|
|
3319
3273
|
standardFields?: never;
|
|
3320
3274
|
labelField?: never;
|
|
@@ -4010,24 +3964,11 @@ export declare const sampleSchemas: {
|
|
|
4010
3964
|
schema: string;
|
|
4011
3965
|
standardFields: string[];
|
|
4012
3966
|
labelField: string;
|
|
4013
|
-
fields:
|
|
3967
|
+
fields: {
|
|
4014
3968
|
name: string;
|
|
4015
3969
|
type: string;
|
|
4016
3970
|
description: string;
|
|
4017
|
-
|
|
4018
|
-
} | {
|
|
4019
|
-
name: string;
|
|
4020
|
-
type: string;
|
|
4021
|
-
members: {
|
|
4022
|
-
type: string;
|
|
4023
|
-
fields: {
|
|
4024
|
-
name: string;
|
|
4025
|
-
type: string;
|
|
4026
|
-
description: string;
|
|
4027
|
-
}[];
|
|
4028
|
-
}[];
|
|
4029
|
-
description?: never;
|
|
4030
|
-
})[];
|
|
3971
|
+
}[];
|
|
4031
3972
|
repository: {
|
|
4032
3973
|
type: string;
|
|
4033
3974
|
};
|
|
@@ -84,42 +84,9 @@
|
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
"name": "author",
|
|
87
|
-
"type": "
|
|
87
|
+
"type": "String?",
|
|
88
88
|
"label": "Blog Author",
|
|
89
|
-
"
|
|
90
|
-
{
|
|
91
|
-
"name": "email",
|
|
92
|
-
"type": "String",
|
|
93
|
-
"faker": "internet.email"
|
|
94
|
-
}
|
|
95
|
-
],
|
|
96
|
-
"members": [
|
|
97
|
-
{
|
|
98
|
-
"type": "user",
|
|
99
|
-
"label": "existing user",
|
|
100
|
-
"fields": [
|
|
101
|
-
{
|
|
102
|
-
"name": "userId",
|
|
103
|
-
"type": "User"
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"type": "anonymous",
|
|
109
|
-
"label": "Anonymous user",
|
|
110
|
-
"fields": [
|
|
111
|
-
{
|
|
112
|
-
"name": "name",
|
|
113
|
-
"type": "String?",
|
|
114
|
-
"faker": "person.fullName"
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
"type": "guest",
|
|
120
|
-
"label": "Guest user"
|
|
121
|
-
}
|
|
122
|
-
]
|
|
89
|
+
"faker": "internet.email"
|
|
123
90
|
},
|
|
124
91
|
{
|
|
125
92
|
"name": "nextPostId",
|
|
@@ -333,29 +333,8 @@
|
|
|
333
333
|
"schema": "Config",
|
|
334
334
|
"fields": [
|
|
335
335
|
{ "name": "pnlStructureId", "type": "PnlStructure" },
|
|
336
|
-
{
|
|
337
|
-
|
|
338
|
-
"type": "DiscriminatedUnion",
|
|
339
|
-
"label": "Row type",
|
|
340
|
-
"commonFields": [],
|
|
341
|
-
"members": [
|
|
342
|
-
{
|
|
343
|
-
"type": "optionalInput",
|
|
344
|
-
"label": "Optional input",
|
|
345
|
-
"fields": []
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
"type": "input",
|
|
349
|
-
"label": "Input",
|
|
350
|
-
"fields": []
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
"type": "subtotal",
|
|
354
|
-
"label": "Subtotal",
|
|
355
|
-
"fields": [{ "name": "rowAboveCount", "type": "Int" }]
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
},
|
|
336
|
+
{ "name": "rowType", "type": "String", "label": "Row type" },
|
|
337
|
+
{ "name": "rowAboveCount", "type": "Int?", "label": "Row above count" },
|
|
359
338
|
{ "name": "name", "type": "String" },
|
|
360
339
|
{ "name": "order", "type": "Int" }
|
|
361
340
|
]
|
|
@@ -417,45 +417,34 @@
|
|
|
417
417
|
"description": "In case of an error: JSON string with the error details."
|
|
418
418
|
},
|
|
419
419
|
{
|
|
420
|
-
"name": "
|
|
421
|
-
"type": "
|
|
422
|
-
"
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
"type": "String?",
|
|
449
|
-
"description": "The id of the affected entity. Depending on the type of the mutation, this is the following:\n\t'Create': the newly created entity's ID\n\t'CreateMany': A stringified array of all created entities' IDs\n\t'Update' & 'Delete': id that was provided as input."
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
"name": "sourceEntity",
|
|
453
|
-
"type": "String?",
|
|
454
|
-
"description": "The original entity before the mutation was executed. Null in case of a create mutation."
|
|
455
|
-
}
|
|
456
|
-
]
|
|
457
|
-
}
|
|
458
|
-
]
|
|
420
|
+
"name": "contentKind",
|
|
421
|
+
"type": "ActionOperationKind?",
|
|
422
|
+
"description": "The kind of operation: 'Transformation' or 'Mutation'."
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"name": "contentTransformationOperation",
|
|
426
|
+
"type": "String?",
|
|
427
|
+
"description": "For transformation operations: the operation that is executed on the payload."
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"name": "contentMutationModel",
|
|
431
|
+
"type": "String?",
|
|
432
|
+
"description": "For mutation operations: which model is affected by the mutation."
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
"name": "contentMutationKind",
|
|
436
|
+
"type": "MutationKind?",
|
|
437
|
+
"description": "For mutation operations: the type of the mutation: 'Create' | 'CreateMany' | 'Update' | 'Upsert' | 'Delete' | ..."
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
"name": "contentMutationEntityId",
|
|
441
|
+
"type": "String?",
|
|
442
|
+
"description": "For mutation operations: the id of the affected entity. Depending on the type of the mutation, this is the following:\n\t'Create': the newly created entity's ID\n\t'CreateMany': A stringified array of all created entities' IDs\n\t'Update' & 'Delete': id that was provided as input."
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
"name": "contentMutationSourceEntity",
|
|
446
|
+
"type": "String?",
|
|
447
|
+
"description": "For mutation operations: the original entity before the mutation was executed. Null in case of a create mutation."
|
|
459
448
|
}
|
|
460
449
|
],
|
|
461
450
|
"repository": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Decoders for PXL Schema definitions and validation for PXL code generation framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"directory": "packages/schema"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@postxl/utils": "^1.4.
|
|
39
|
+
"@postxl/utils": "^1.4.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {},
|
|
42
42
|
"wallaby": {
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import * as Branded from './shared/brands';
|
|
3
|
-
import { FieldCommon, FieldTransformer } from './shared/types';
|
|
4
|
-
import * as Fields from './field';
|
|
5
|
-
export type FieldKindDiscriminatedUnion = 'discriminatedUnion';
|
|
6
|
-
export declare const fieldKindDiscriminatedUnion: FieldKindDiscriminatedUnion;
|
|
7
|
-
export type DiscriminatedUnionMember = {
|
|
8
|
-
/**
|
|
9
|
-
* The discriminator value that is used to identify the member.
|
|
10
|
-
*/
|
|
11
|
-
type: Discriminator;
|
|
12
|
-
/**
|
|
13
|
-
* A human readable label for the member.
|
|
14
|
-
*/
|
|
15
|
-
label: DiscriminatorLabel;
|
|
16
|
-
/**
|
|
17
|
-
* The fields that are part of the member.
|
|
18
|
-
*/
|
|
19
|
-
fields: Fields.Fields<PartOfDiscriminatedUnionMember<Fields.FieldDatabaseNative>>;
|
|
20
|
-
};
|
|
21
|
-
type PartOfDiscriminatedUnion<T extends Fields.FieldDatabaseNative> = T & {
|
|
22
|
-
discriminatedUnionFieldName: Branded.FieldName;
|
|
23
|
-
};
|
|
24
|
-
export declare function isPartOfDiscriminatedUnion<T extends Fields.FieldDatabaseNative>(field: Fields.FieldDatabaseNative): field is PartOfDiscriminatedUnion<T>;
|
|
25
|
-
type PartOfDiscriminatedUnionMember<T extends Fields.FieldDatabaseNative> = PartOfDiscriminatedUnion<T> & {
|
|
26
|
-
discriminatedUnionMemberType: Discriminator;
|
|
27
|
-
};
|
|
28
|
-
export declare function isPartOfDiscriminatedUnionMember<T extends Fields.FieldDatabaseNative>(field: Fields.FieldDatabaseNative): field is PartOfDiscriminatedUnionMember<T>;
|
|
29
|
-
export type FieldDiscriminatedUnion = FieldCommon<FieldKindDiscriminatedUnion> & {
|
|
30
|
-
type: Branded.DiscriminatedUnionType;
|
|
31
|
-
/**
|
|
32
|
-
* The name of the field that is used to discriminate the union.
|
|
33
|
-
*
|
|
34
|
-
* This is a constant name `type`.
|
|
35
|
-
*/
|
|
36
|
-
discriminatorFieldName: Branded.FieldName;
|
|
37
|
-
/**
|
|
38
|
-
* The common fields that are shared by all members.
|
|
39
|
-
*/
|
|
40
|
-
commonFields: Fields.Fields<PartOfDiscriminatedUnion<Fields.FieldDatabaseNative>>;
|
|
41
|
-
/**
|
|
42
|
-
* The members of the discriminated union.
|
|
43
|
-
*/
|
|
44
|
-
members: Map<Discriminator, DiscriminatedUnionMember>;
|
|
45
|
-
};
|
|
46
|
-
export type FieldDiscriminatedUnionEnriched = ReturnType<typeof fieldDiscriminatedUnionJSONTransformer>;
|
|
47
|
-
declare const zDiscriminator: z.core.$ZodBranded<z.ZodString, "PXL.Discriminator", "out">;
|
|
48
|
-
export type Discriminator = z.infer<typeof zDiscriminator>;
|
|
49
|
-
declare const zDiscriminatorLabel: z.core.$ZodBranded<z.ZodString, "PXL.DiscriminatorLabel", "out">;
|
|
50
|
-
type DiscriminatorLabel = z.infer<typeof zDiscriminatorLabel>;
|
|
51
|
-
export declare const zField: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
52
|
-
/**
|
|
53
|
-
* JSON Schema for an Discriminated Union field
|
|
54
|
-
*/
|
|
55
|
-
export declare const zFieldDiscriminatedUnionJSON: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
56
|
-
name: z.ZodString;
|
|
57
|
-
type: z.ZodUnion<[z.ZodLiteral<"DiscriminatedUnion">, z.ZodLiteral<"DiscriminatedUnion?">]>;
|
|
58
|
-
label: z.ZodOptional<z.ZodString>;
|
|
59
|
-
description: z.ZodOptional<z.ZodString>;
|
|
60
|
-
databaseName: z.ZodOptional<z.ZodString>;
|
|
61
|
-
excelName: z.ZodOptional<z.ZodString>;
|
|
62
|
-
members: z.ZodArray<z.ZodObject<{
|
|
63
|
-
type: z.ZodString;
|
|
64
|
-
label: z.ZodOptional<z.ZodString>;
|
|
65
|
-
fields: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
66
|
-
}, z.core.$strip>>;
|
|
67
|
-
commonFields: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
68
|
-
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
-
}, z.core.$strip>>;
|
|
70
|
-
export type FieldDiscriminatedUnionJSON = z.infer<typeof zFieldDiscriminatedUnionJSON>;
|
|
71
|
-
export declare function fieldDiscriminatedUnionJSONTransformer(fieldInput: FieldDiscriminatedUnionJSON): {
|
|
72
|
-
kind: "discriminatedUnion";
|
|
73
|
-
name: string & z.core.$brand<"PXL.FieldName">;
|
|
74
|
-
discriminatorFieldName: string & z.core.$brand<"PXL.FieldName">;
|
|
75
|
-
label: string;
|
|
76
|
-
databaseName: string & z.core.$brand<"PXL.DatabaseFieldName">;
|
|
77
|
-
excelName: string & z.core.$brand<"PXL.ExcelColumnName">;
|
|
78
|
-
description: string | undefined;
|
|
79
|
-
members: {
|
|
80
|
-
type: string;
|
|
81
|
-
label?: string | undefined;
|
|
82
|
-
fields?: Record<string, any>[] | undefined;
|
|
83
|
-
}[];
|
|
84
|
-
commonFields: Record<string, any>[] | undefined;
|
|
85
|
-
isReadonly: boolean;
|
|
86
|
-
isRequired: boolean;
|
|
87
|
-
};
|
|
88
|
-
export declare const fieldDiscriminatedUnionTransformer: FieldTransformer<FieldKindDiscriminatedUnion, FieldDiscriminatedUnionEnriched, FieldDiscriminatedUnion>;
|
|
89
|
-
export {};
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.fieldDiscriminatedUnionTransformer = exports.zFieldDiscriminatedUnionJSON = exports.zField = exports.fieldKindDiscriminatedUnion = void 0;
|
|
37
|
-
exports.isPartOfDiscriminatedUnion = isPartOfDiscriminatedUnion;
|
|
38
|
-
exports.isPartOfDiscriminatedUnionMember = isPartOfDiscriminatedUnionMember;
|
|
39
|
-
exports.fieldDiscriminatedUnionJSONTransformer = fieldDiscriminatedUnionJSONTransformer;
|
|
40
|
-
const zod_1 = require("zod");
|
|
41
|
-
const utils_1 = require("@postxl/utils");
|
|
42
|
-
const enum_1 = require("../enum");
|
|
43
|
-
const model_1 = require("../model");
|
|
44
|
-
const normalize_named_collection_1 = require("../normalize-named-collection");
|
|
45
|
-
const Branded = __importStar(require("./shared/brands"));
|
|
46
|
-
const Decoders = __importStar(require("./shared/decoders"));
|
|
47
|
-
const utils_2 = require("./shared/utils");
|
|
48
|
-
const Fields = __importStar(require("./field"));
|
|
49
|
-
exports.fieldKindDiscriminatedUnion = 'discriminatedUnion';
|
|
50
|
-
function isPartOfDiscriminatedUnion(field) {
|
|
51
|
-
return 'discriminatedUnionFieldName' in field;
|
|
52
|
-
}
|
|
53
|
-
function isPartOfDiscriminatedUnionMember(field) {
|
|
54
|
-
return 'discriminatedUnionMemberType' in field;
|
|
55
|
-
}
|
|
56
|
-
const zDiscriminator = zod_1.z.string().brand('PXL.Discriminator');
|
|
57
|
-
const toDiscriminator = (input) => zDiscriminator.parse(input);
|
|
58
|
-
const zDiscriminatorLabel = zod_1.z.string().brand('PXL.DiscriminatorLabel');
|
|
59
|
-
const toDiscriminatorLabel = (input) => zDiscriminatorLabel.parse(input);
|
|
60
|
-
exports.zField = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
61
|
-
/**
|
|
62
|
-
* JSON Schema for an Discriminated Union field
|
|
63
|
-
*/
|
|
64
|
-
exports.zFieldDiscriminatedUnionJSON = zod_1.z.preprocess((input) => {
|
|
65
|
-
if (typeof input === 'object' && input !== null) {
|
|
66
|
-
const original = input;
|
|
67
|
-
return {
|
|
68
|
-
...original,
|
|
69
|
-
...(original.commonFields !== undefined
|
|
70
|
-
? { commonFields: (0, normalize_named_collection_1.normalizeNamedCollection)(original.commonFields) }
|
|
71
|
-
: {}),
|
|
72
|
-
members: Array.isArray(original.members)
|
|
73
|
-
? original.members.map((member) => {
|
|
74
|
-
if (typeof member === 'object' && member !== null && 'fields' in member) {
|
|
75
|
-
return { ...member, fields: (0, normalize_named_collection_1.normalizeNamedCollection)(member.fields) };
|
|
76
|
-
}
|
|
77
|
-
return member;
|
|
78
|
-
})
|
|
79
|
-
: original.members,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return input;
|
|
83
|
-
}, zod_1.z.object({
|
|
84
|
-
name: Decoders.zFieldPropertyName,
|
|
85
|
-
type: zod_1.z //
|
|
86
|
-
.literal('DiscriminatedUnion')
|
|
87
|
-
.or(zod_1.z.literal('DiscriminatedUnion?'))
|
|
88
|
-
.describe('The kind of the field. This should always be `discriminatedUnion`.'),
|
|
89
|
-
label: Decoders.zFieldPropertyLabel,
|
|
90
|
-
description: Decoders.zFieldPropertyDescription,
|
|
91
|
-
databaseName: Decoders.zFieldPropertyDatabaseName,
|
|
92
|
-
excelName: Decoders.zFieldPropertyExcelName,
|
|
93
|
-
members: zod_1.z.array(zod_1.z.object({
|
|
94
|
-
type: zod_1.z
|
|
95
|
-
.string()
|
|
96
|
-
.regex(/^[a-zA-Z0-9]*$/, 'Type name shall only contain letters and numbers.')
|
|
97
|
-
.refine((v) => v !== 'type', {
|
|
98
|
-
message: 'Element field name cannot be "type" as this is reserved for the discriminator.',
|
|
99
|
-
}),
|
|
100
|
-
label: zod_1.z.string().optional(),
|
|
101
|
-
fields: zod_1.z.array(exports.zField).optional(),
|
|
102
|
-
})),
|
|
103
|
-
commonFields: zod_1.z.array(exports.zField).optional(),
|
|
104
|
-
isReadonly: Decoders.zFieldPropertyIsReadonly,
|
|
105
|
-
}));
|
|
106
|
-
function fieldDiscriminatedUnionJSONTransformer(fieldInput) {
|
|
107
|
-
const { isRequired } = (0, utils_2.isFieldRequired)(fieldInput.type);
|
|
108
|
-
return {
|
|
109
|
-
kind: exports.fieldKindDiscriminatedUnion,
|
|
110
|
-
name: Branded.toFieldName(fieldInput.name),
|
|
111
|
-
discriminatorFieldName: Branded.toFieldName('type'),
|
|
112
|
-
label: (0, utils_1.toHumanReadable)(fieldInput.label ?? fieldInput.name),
|
|
113
|
-
databaseName: Branded.toDatabaseFieldName(fieldInput.databaseName ?? (0, utils_1.toSnakeCase)(fieldInput.name)),
|
|
114
|
-
excelName: Branded.toExcelColumnName(fieldInput.excelName ?? fieldInput.label ?? fieldInput.name),
|
|
115
|
-
description: fieldInput.description,
|
|
116
|
-
members: fieldInput.members,
|
|
117
|
-
commonFields: fieldInput.commonFields,
|
|
118
|
-
isReadonly: fieldInput.isReadonly ?? false,
|
|
119
|
-
isRequired,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const fieldDiscriminatedUnionTransformer = ({ fieldInput, model, projectSchema }, ctx) => {
|
|
123
|
-
const modelNames = [...projectSchema.models.keys()].map((name) => (0, model_1.toModelName)(name));
|
|
124
|
-
const enumNames = [...projectSchema.enums.keys()].map((name) => (0, enum_1.toEnumName)(name));
|
|
125
|
-
// The field decoder for the fields in the discriminated union. It ensures that discriminated unions cannot be nested.
|
|
126
|
-
const zFieldDecoder = Fields.createFieldJSONDecoder({
|
|
127
|
-
modelNames,
|
|
128
|
-
enumNames,
|
|
129
|
-
}).transform((f) => {
|
|
130
|
-
if (f.kind === 'discriminatedUnion') {
|
|
131
|
-
ctx.addIssue({
|
|
132
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
133
|
-
message: `Discriminated union ${model.name}.${fieldInput.name} cannot contain a discriminated unions as a field!`,
|
|
134
|
-
});
|
|
135
|
-
return zod_1.z.NEVER;
|
|
136
|
-
}
|
|
137
|
-
if (f.kind === 'json') {
|
|
138
|
-
ctx.addIssue({
|
|
139
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
140
|
-
message: `Discriminated union ${model.name}.${fieldInput.name} cannot contain JSON fields yet.`,
|
|
141
|
-
});
|
|
142
|
-
return zod_1.z.NEVER;
|
|
143
|
-
}
|
|
144
|
-
return f;
|
|
145
|
-
});
|
|
146
|
-
const commonFields = new Map();
|
|
147
|
-
for (const field of fieldInput.commonFields ?? []) {
|
|
148
|
-
const decodedFieldResult = zFieldDecoder.safeParse(field);
|
|
149
|
-
if (!decodedFieldResult.success) {
|
|
150
|
-
ctx.addIssue({
|
|
151
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
152
|
-
message: `Error decoding common field in ${model.name}.${fieldInput.name}: ${decodedFieldResult.error.message}`,
|
|
153
|
-
});
|
|
154
|
-
return zod_1.z.NEVER;
|
|
155
|
-
}
|
|
156
|
-
const decodedField = decodedFieldResult.data;
|
|
157
|
-
const transformedField = Fields.fieldTransformer(decodedField, model, projectSchema, ctx);
|
|
158
|
-
commonFields.set(transformedField.name, addDiscriminatedUnionParent(transformedField, fieldInput.name, fieldInput.excelName));
|
|
159
|
-
}
|
|
160
|
-
const members = new Map();
|
|
161
|
-
for (const memberInput of fieldInput.members) {
|
|
162
|
-
const discriminator = toDiscriminator(memberInput.type);
|
|
163
|
-
const label = toDiscriminatorLabel(memberInput.label ?? memberInput.type);
|
|
164
|
-
const memberFields = new Map();
|
|
165
|
-
for (const field of memberInput.fields ?? []) {
|
|
166
|
-
const decodedFieldResult = zFieldDecoder.safeParse(field);
|
|
167
|
-
if (!decodedFieldResult.success) {
|
|
168
|
-
ctx.addIssue({
|
|
169
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
170
|
-
message: `Error decoding field in ${model.name}.${fieldInput.name}: ${decodedFieldResult.error.message}`,
|
|
171
|
-
});
|
|
172
|
-
return zod_1.z.NEVER;
|
|
173
|
-
}
|
|
174
|
-
const decodedField = decodedFieldResult.data;
|
|
175
|
-
if (decodedField.name === 'type') {
|
|
176
|
-
ctx.addIssue({
|
|
177
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
178
|
-
message: `Field name "type" is reserved for the discriminator in discriminated union ${model.name}.${fieldInput.name}`,
|
|
179
|
-
});
|
|
180
|
-
return zod_1.z.NEVER;
|
|
181
|
-
}
|
|
182
|
-
const transformedField = Fields.fieldTransformer(decodedField, model, projectSchema, ctx);
|
|
183
|
-
memberFields.set(transformedField.name, addDiscriminatedUnionParentMember(transformedField, fieldInput.name, fieldInput.excelName, discriminator));
|
|
184
|
-
}
|
|
185
|
-
members.set(discriminator, {
|
|
186
|
-
type: discriminator,
|
|
187
|
-
label,
|
|
188
|
-
fields: memberFields,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
const result = {
|
|
192
|
-
...fieldInput,
|
|
193
|
-
modelName: model.name,
|
|
194
|
-
databaseType: Branded.toDatabaseFieldType('String'),
|
|
195
|
-
isUnique: false,
|
|
196
|
-
type: Branded.toDiscriminatedUnionType((0, utils_1.toPascalCase)(fieldInput.name)),
|
|
197
|
-
kind: 'discriminatedUnion',
|
|
198
|
-
commonFields,
|
|
199
|
-
members,
|
|
200
|
-
};
|
|
201
|
-
return result;
|
|
202
|
-
};
|
|
203
|
-
exports.fieldDiscriminatedUnionTransformer = fieldDiscriminatedUnionTransformer;
|
|
204
|
-
function addDiscriminatedUnionParent(field, duFieldName, duExcelName) {
|
|
205
|
-
const result = {
|
|
206
|
-
...field,
|
|
207
|
-
discriminatedUnionFieldName: duFieldName,
|
|
208
|
-
databaseName: ensureCustomDatabaseName({
|
|
209
|
-
name: field.name,
|
|
210
|
-
databaseName: field.databaseName,
|
|
211
|
-
newName: `${duFieldName}${(0, utils_1.toPascalCase)(field.name)}`,
|
|
212
|
-
}),
|
|
213
|
-
excelName: ensureCustomExcelName({
|
|
214
|
-
name: field.name,
|
|
215
|
-
label: field.label,
|
|
216
|
-
excelName: field.excelName,
|
|
217
|
-
newName: `${duExcelName} ${field.excelName}`,
|
|
218
|
-
}),
|
|
219
|
-
};
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
function addDiscriminatedUnionParentMember(field, duFieldName, duExcelName, duMemberType) {
|
|
223
|
-
const result = {
|
|
224
|
-
...field,
|
|
225
|
-
discriminatedUnionFieldName: duFieldName,
|
|
226
|
-
discriminatedUnionMemberType: duMemberType,
|
|
227
|
-
databaseName: ensureCustomDatabaseName({
|
|
228
|
-
name: field.name,
|
|
229
|
-
databaseName: field.databaseName,
|
|
230
|
-
newName: `${duFieldName}${(0, utils_1.toPascalCase)(duMemberType)}${(0, utils_1.toPascalCase)(field.name)}`,
|
|
231
|
-
}),
|
|
232
|
-
excelName: ensureCustomExcelName({
|
|
233
|
-
name: field.name,
|
|
234
|
-
label: field.label,
|
|
235
|
-
excelName: field.excelName,
|
|
236
|
-
newName: `${duExcelName} ${(0, utils_1.toPascalCase)(duMemberType)} ${field.excelName}`,
|
|
237
|
-
}),
|
|
238
|
-
};
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
function ensureCustomExcelName({ excelName, name, label, newName, }) {
|
|
242
|
-
// If the user explicitly set a custom excelName (different from the defaults), keep it
|
|
243
|
-
if (excelName !== name && excelName !== label && excelName !== (0, utils_1.toHumanReadable)(name)) {
|
|
244
|
-
return excelName;
|
|
245
|
-
}
|
|
246
|
-
return Branded.toExcelColumnName(newName);
|
|
247
|
-
}
|
|
248
|
-
function ensureCustomDatabaseName({ databaseName, name, newName, }) {
|
|
249
|
-
if (databaseName !== name && databaseName !== (0, utils_1.toSnakeCase)(name)) {
|
|
250
|
-
return databaseName;
|
|
251
|
-
}
|
|
252
|
-
return Branded.toDatabaseFieldName((0, utils_1.toSnakeCase)(newName));
|
|
253
|
-
}
|