@postxl/schema 0.0.2
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/LICENSE +50 -0
- package/README.md +320 -0
- package/dist/enum/enum.brands.d.ts +11 -0
- package/dist/enum/enum.brands.js +19 -0
- package/dist/enum/enum.d.ts +49 -0
- package/dist/enum/enum.defaults.d.ts +41 -0
- package/dist/enum/enum.defaults.js +105 -0
- package/dist/enum/enum.js +6 -0
- package/dist/enum/enum.json-decoder.d.ts +61 -0
- package/dist/enum/enum.json-decoder.js +51 -0
- package/dist/enum/enum.transformer.d.ts +12 -0
- package/dist/enum/enum.transformer.js +76 -0
- package/dist/enum/enum.types.d.ts +14 -0
- package/dist/enum/enum.types.js +2 -0
- package/dist/enum/index.d.ts +6 -0
- package/dist/enum/index.js +22 -0
- package/dist/field/defaults.d.ts +12 -0
- package/dist/field/defaults.js +78 -0
- package/dist/field/discriminated-union.d.ts +125 -0
- package/dist/field/discriminated-union.js +207 -0
- package/dist/field/enum.d.ts +65 -0
- package/dist/field/enum.js +111 -0
- package/dist/field/field.d.ts +483 -0
- package/dist/field/field.js +68 -0
- package/dist/field/id.d.ts +152 -0
- package/dist/field/id.js +104 -0
- package/dist/field/index.d.ts +11 -0
- package/dist/field/index.js +27 -0
- package/dist/field/relation.d.ts +88 -0
- package/dist/field/relation.js +138 -0
- package/dist/field/scalar.d.ts +179 -0
- package/dist/field/scalar.js +197 -0
- package/dist/field/shared/brands.d.ts +38 -0
- package/dist/field/shared/brands.js +109 -0
- package/dist/field/shared/decoders.d.ts +17 -0
- package/dist/field/shared/decoders.js +88 -0
- package/dist/field/shared/seed.d.ts +32 -0
- package/dist/field/shared/seed.js +63 -0
- package/dist/field/shared/types.d.ts +73 -0
- package/dist/field/shared/types.js +2 -0
- package/dist/field/shared/utils.d.ts +26 -0
- package/dist/field/shared/utils.js +52 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +25 -0
- package/dist/model/index.d.ts +5 -0
- package/dist/model/index.js +21 -0
- package/dist/model/model.brands.d.ts +7 -0
- package/dist/model/model.brands.js +10 -0
- package/dist/model/model.defaults.d.ts +28 -0
- package/dist/model/model.defaults.js +304 -0
- package/dist/model/model.json-decoder.d.ts +94 -0
- package/dist/model/model.json-decoder.js +107 -0
- package/dist/model/model.transformer.d.ts +93 -0
- package/dist/model/model.transformer.js +183 -0
- package/dist/model/model.types.d.ts +37 -0
- package/dist/model/model.types.js +2 -0
- package/dist/project-schema/project-schema.brands.d.ts +10 -0
- package/dist/project-schema/project-schema.brands.js +17 -0
- package/dist/project-schema/project-schema.defaults.d.ts +16 -0
- package/dist/project-schema/project-schema.defaults.js +53 -0
- package/dist/project-schema/project-schema.json-decoder.d.ts +285 -0
- package/dist/project-schema/project-schema.json-decoder.js +145 -0
- package/dist/project-schema/project-schema.transformer.d.ts +284 -0
- package/dist/project-schema/project-schema.transformer.js +444 -0
- package/dist/project-schema/project-schema.types.d.ts +77 -0
- package/dist/project-schema/project-schema.types.js +2 -0
- package/dist/samples/la.schema.json +2055 -0
- package/dist/samples/mca.schema.json +830 -0
- package/dist/samples/ring.schema.json +879 -0
- package/dist/samples/sample-schemas.d.ts +1896 -0
- package/dist/samples/sample-schemas.js +20 -0
- package/dist/samples/simple.schema.json +250 -0
- package/dist/samples/subex.schema.json +1188 -0
- package/dist/samples/usp-msm.schema.json +2515 -0
- package/package.json +57 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as Branded from './shared/brands';
|
|
3
|
+
import { FieldSeedConfig } from './shared/seed';
|
|
4
|
+
import { FieldCommon, FieldTransformer } from './shared/types';
|
|
5
|
+
export type FieldKindScalar = 'scalar';
|
|
6
|
+
export declare const fieldKindScalar: FieldKindScalar;
|
|
7
|
+
export type FieldScalar = FieldScalarString | FieldScalarNumber | FieldScalarBoolean | FieldScalarDate;
|
|
8
|
+
export type FieldScalarString = FieldCommon<FieldKindScalar> & FieldCommonScalar & FieldScalarStringWithValidations;
|
|
9
|
+
export type FieldScalarNumber = FieldCommon<FieldKindScalar> & FieldCommonScalar & FieldScalarNumberWithValidations;
|
|
10
|
+
export type FieldScalarBoolean = FieldCommon<FieldKindScalar> & FieldCommonScalar & FieldScalarBooleanNoValidation;
|
|
11
|
+
export type FieldScalarDate = FieldCommon<FieldKindScalar> & FieldCommonScalar & FieldScalarDateNoValidation;
|
|
12
|
+
type FieldCommonScalar = {
|
|
13
|
+
kind: 'scalar';
|
|
14
|
+
generation: string;
|
|
15
|
+
/**
|
|
16
|
+
* If true, the repository will expose an index for the field.
|
|
17
|
+
*/
|
|
18
|
+
hasIndex: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If true, the field is automatically set to the current date and time when the item is created.
|
|
21
|
+
*/
|
|
22
|
+
isCreatedAt: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* If true, the field is automatically set to the current date and time when the item is updated.
|
|
25
|
+
*/
|
|
26
|
+
isUpdatedAt: boolean;
|
|
27
|
+
seed: FieldSeedConfig;
|
|
28
|
+
/**
|
|
29
|
+
* A generic placeholder that is used to pre-populate empty fields.
|
|
30
|
+
*/
|
|
31
|
+
placeholder: string;
|
|
32
|
+
};
|
|
33
|
+
type FieldScalarStringWithValidations = {
|
|
34
|
+
type: 'string';
|
|
35
|
+
validations: ValidationString;
|
|
36
|
+
};
|
|
37
|
+
type ValidationString = {
|
|
38
|
+
maxLength: number | undefined;
|
|
39
|
+
};
|
|
40
|
+
type FieldScalarNumberWithValidations = {
|
|
41
|
+
type: 'number';
|
|
42
|
+
validations: ValidationNumber;
|
|
43
|
+
};
|
|
44
|
+
type ValidationNumber = {
|
|
45
|
+
type: 'int' | 'float';
|
|
46
|
+
min: number | undefined;
|
|
47
|
+
max: number | undefined;
|
|
48
|
+
};
|
|
49
|
+
type FieldScalarBooleanNoValidation = {
|
|
50
|
+
type: 'boolean';
|
|
51
|
+
};
|
|
52
|
+
type FieldScalarDateNoValidation = {
|
|
53
|
+
type: 'Date';
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* JSON Schema for an scalar field
|
|
57
|
+
*/
|
|
58
|
+
export declare const zFieldScalarJSON: z.ZodObject<{
|
|
59
|
+
name: z.ZodEffects<z.ZodString, string, string>;
|
|
60
|
+
type: z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"String">, z.ZodLiteral<"String?">]>, z.ZodUnion<[z.ZodLiteral<"Boolean">, z.ZodLiteral<"Boolean?">]>, z.ZodUnion<[z.ZodLiteral<"DateTime">, z.ZodLiteral<"DateTime?">]>, z.ZodUnion<[z.ZodLiteral<"Decimal">, z.ZodLiteral<"Decimal?">]>, z.ZodUnion<[z.ZodLiteral<"Float">, z.ZodLiteral<"Float?">]>, z.ZodUnion<[z.ZodLiteral<"Int">, z.ZodLiteral<"Int?">]>, z.ZodUnion<[z.ZodLiteral<"Json">, z.ZodLiteral<"Json?">]>, z.ZodUnion<[z.ZodLiteral<"Bytes">, z.ZodLiteral<"Bytes?">]>, z.ZodUnion<[z.ZodLiteral<"BigInt">, z.ZodLiteral<"BigInt?">]>]>;
|
|
61
|
+
databaseName: z.ZodOptional<z.ZodString>;
|
|
62
|
+
excelName: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
63
|
+
label: z.ZodOptional<z.ZodString>;
|
|
64
|
+
description: z.ZodOptional<z.ZodString>;
|
|
65
|
+
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
isUnique: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
hasIndex: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
isCreatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
isUpdatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
faker: z.ZodOptional<z.ZodString>;
|
|
72
|
+
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, "many">]>>;
|
|
73
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, "strict", z.ZodTypeAny, {
|
|
75
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Json?" | "Bytes?" | "BigInt?";
|
|
76
|
+
name: string;
|
|
77
|
+
description?: string | undefined;
|
|
78
|
+
databaseName?: string | undefined;
|
|
79
|
+
excelName?: string | undefined;
|
|
80
|
+
label?: string | undefined;
|
|
81
|
+
isReadonly?: boolean | undefined;
|
|
82
|
+
faker?: string | undefined;
|
|
83
|
+
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
84
|
+
isUnique?: boolean | undefined;
|
|
85
|
+
hasIndex?: boolean | undefined;
|
|
86
|
+
isCreatedAt?: boolean | undefined;
|
|
87
|
+
isUpdatedAt?: boolean | undefined;
|
|
88
|
+
maxLength?: number | undefined;
|
|
89
|
+
placeholder?: string | undefined;
|
|
90
|
+
}, {
|
|
91
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Json?" | "Bytes?" | "BigInt?";
|
|
92
|
+
name: string;
|
|
93
|
+
description?: string | undefined;
|
|
94
|
+
databaseName?: string | undefined;
|
|
95
|
+
excelName?: string | undefined;
|
|
96
|
+
label?: string | undefined;
|
|
97
|
+
isReadonly?: boolean | undefined;
|
|
98
|
+
faker?: string | undefined;
|
|
99
|
+
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
100
|
+
isUnique?: boolean | undefined;
|
|
101
|
+
hasIndex?: boolean | undefined;
|
|
102
|
+
isCreatedAt?: boolean | undefined;
|
|
103
|
+
isUpdatedAt?: boolean | undefined;
|
|
104
|
+
maxLength?: number | undefined;
|
|
105
|
+
placeholder?: string | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
export type FieldScalarJSON = z.infer<typeof zFieldScalarJSON>;
|
|
108
|
+
export declare function fieldScalarJSONTransformer(fieldInput: FieldScalarJSON, ctx: z.RefinementCtx): FieldScalarEnriched;
|
|
109
|
+
export type FieldScalarEnriched = Omit<FieldCommon<FieldKindScalar>, 'modelName'> & FieldCommonScalar & {
|
|
110
|
+
type: Branded.ScalarType;
|
|
111
|
+
validations: Partial<ValidationString & ValidationNumber>;
|
|
112
|
+
};
|
|
113
|
+
export declare const zFieldScalar: z.ZodEffects<z.ZodObject<{
|
|
114
|
+
name: z.ZodEffects<z.ZodString, string, string>;
|
|
115
|
+
type: z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"String">, z.ZodLiteral<"String?">]>, z.ZodUnion<[z.ZodLiteral<"Boolean">, z.ZodLiteral<"Boolean?">]>, z.ZodUnion<[z.ZodLiteral<"DateTime">, z.ZodLiteral<"DateTime?">]>, z.ZodUnion<[z.ZodLiteral<"Decimal">, z.ZodLiteral<"Decimal?">]>, z.ZodUnion<[z.ZodLiteral<"Float">, z.ZodLiteral<"Float?">]>, z.ZodUnion<[z.ZodLiteral<"Int">, z.ZodLiteral<"Int?">]>, z.ZodUnion<[z.ZodLiteral<"Json">, z.ZodLiteral<"Json?">]>, z.ZodUnion<[z.ZodLiteral<"Bytes">, z.ZodLiteral<"Bytes?">]>, z.ZodUnion<[z.ZodLiteral<"BigInt">, z.ZodLiteral<"BigInt?">]>]>;
|
|
116
|
+
databaseName: z.ZodOptional<z.ZodString>;
|
|
117
|
+
excelName: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
118
|
+
label: z.ZodOptional<z.ZodString>;
|
|
119
|
+
description: z.ZodOptional<z.ZodString>;
|
|
120
|
+
isReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
isUnique: z.ZodOptional<z.ZodBoolean>;
|
|
122
|
+
hasIndex: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
isCreatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
isUpdatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
125
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
faker: z.ZodOptional<z.ZodString>;
|
|
127
|
+
seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, "many">]>>;
|
|
128
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
129
|
+
}, "strict", z.ZodTypeAny, {
|
|
130
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Json?" | "Bytes?" | "BigInt?";
|
|
131
|
+
name: string;
|
|
132
|
+
description?: string | undefined;
|
|
133
|
+
databaseName?: string | undefined;
|
|
134
|
+
excelName?: string | undefined;
|
|
135
|
+
label?: string | undefined;
|
|
136
|
+
isReadonly?: boolean | undefined;
|
|
137
|
+
faker?: string | undefined;
|
|
138
|
+
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
139
|
+
isUnique?: boolean | undefined;
|
|
140
|
+
hasIndex?: boolean | undefined;
|
|
141
|
+
isCreatedAt?: boolean | undefined;
|
|
142
|
+
isUpdatedAt?: boolean | undefined;
|
|
143
|
+
maxLength?: number | undefined;
|
|
144
|
+
placeholder?: string | undefined;
|
|
145
|
+
}, {
|
|
146
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Json?" | "Bytes?" | "BigInt?";
|
|
147
|
+
name: string;
|
|
148
|
+
description?: string | undefined;
|
|
149
|
+
databaseName?: string | undefined;
|
|
150
|
+
excelName?: string | undefined;
|
|
151
|
+
label?: string | undefined;
|
|
152
|
+
isReadonly?: boolean | undefined;
|
|
153
|
+
faker?: string | undefined;
|
|
154
|
+
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
155
|
+
isUnique?: boolean | undefined;
|
|
156
|
+
hasIndex?: boolean | undefined;
|
|
157
|
+
isCreatedAt?: boolean | undefined;
|
|
158
|
+
isUpdatedAt?: boolean | undefined;
|
|
159
|
+
maxLength?: number | undefined;
|
|
160
|
+
placeholder?: string | undefined;
|
|
161
|
+
}>, FieldScalarEnriched, {
|
|
162
|
+
type: "BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes" | "String?" | "Boolean?" | "DateTime?" | "Decimal?" | "Float?" | "Int?" | "Json?" | "Bytes?" | "BigInt?";
|
|
163
|
+
name: string;
|
|
164
|
+
description?: string | undefined;
|
|
165
|
+
databaseName?: string | undefined;
|
|
166
|
+
excelName?: string | undefined;
|
|
167
|
+
label?: string | undefined;
|
|
168
|
+
isReadonly?: boolean | undefined;
|
|
169
|
+
faker?: string | undefined;
|
|
170
|
+
seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
|
|
171
|
+
isUnique?: boolean | undefined;
|
|
172
|
+
hasIndex?: boolean | undefined;
|
|
173
|
+
isCreatedAt?: boolean | undefined;
|
|
174
|
+
isUpdatedAt?: boolean | undefined;
|
|
175
|
+
maxLength?: number | undefined;
|
|
176
|
+
placeholder?: string | undefined;
|
|
177
|
+
}>;
|
|
178
|
+
export declare const fieldScalarTransformer: FieldTransformer<FieldKindScalar, FieldScalarEnriched, FieldScalar>;
|
|
179
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
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.fieldScalarTransformer = exports.zFieldScalar = exports.zFieldScalarJSON = exports.fieldKindScalar = void 0;
|
|
37
|
+
exports.fieldScalarJSONTransformer = fieldScalarJSONTransformer;
|
|
38
|
+
const zod_1 = require("zod");
|
|
39
|
+
const utils_1 = require("@postxl/utils");
|
|
40
|
+
const Branded = __importStar(require("./shared/brands"));
|
|
41
|
+
const Decoders = __importStar(require("./shared/decoders"));
|
|
42
|
+
const seed_1 = require("./shared/seed");
|
|
43
|
+
const utils_2 = require("./shared/utils");
|
|
44
|
+
exports.fieldKindScalar = 'scalar';
|
|
45
|
+
const zDatabaseType = zod_1.z
|
|
46
|
+
.union([
|
|
47
|
+
zod_1.z.literal('String').or(zod_1.z.literal('String?')),
|
|
48
|
+
zod_1.z.literal('Boolean').or(zod_1.z.literal('Boolean?')),
|
|
49
|
+
zod_1.z.literal('DateTime').or(zod_1.z.literal('DateTime?')),
|
|
50
|
+
zod_1.z.literal('Decimal').or(zod_1.z.literal('Decimal?')),
|
|
51
|
+
zod_1.z.literal('Float').or(zod_1.z.literal('Float?')),
|
|
52
|
+
zod_1.z.literal('Int').or(zod_1.z.literal('Int?')),
|
|
53
|
+
zod_1.z.literal('Json').or(zod_1.z.literal('Json?')),
|
|
54
|
+
zod_1.z.literal('Bytes').or(zod_1.z.literal('Bytes?')),
|
|
55
|
+
zod_1.z.literal('BigInt').or(zod_1.z.literal('BigInt?')),
|
|
56
|
+
])
|
|
57
|
+
.describe('The type of the field. Should be a native database type.');
|
|
58
|
+
function databaseTypeToFieldTypeScalar(input, ctx) {
|
|
59
|
+
switch (input) {
|
|
60
|
+
case 'String':
|
|
61
|
+
case 'String?':
|
|
62
|
+
return Branded.toScalarType('string');
|
|
63
|
+
case 'Boolean':
|
|
64
|
+
case 'Boolean?':
|
|
65
|
+
return Branded.toScalarType('boolean');
|
|
66
|
+
case 'DateTime':
|
|
67
|
+
case 'DateTime?':
|
|
68
|
+
return Branded.toScalarType('Date');
|
|
69
|
+
case 'Decimal':
|
|
70
|
+
case 'Decimal?':
|
|
71
|
+
case 'Float':
|
|
72
|
+
case 'Float?':
|
|
73
|
+
case 'Int':
|
|
74
|
+
case 'Int?':
|
|
75
|
+
return Branded.toScalarType('number');
|
|
76
|
+
case 'Json':
|
|
77
|
+
case 'Json?':
|
|
78
|
+
case 'Bytes':
|
|
79
|
+
case 'Bytes?':
|
|
80
|
+
case 'BigInt':
|
|
81
|
+
case 'BigInt?':
|
|
82
|
+
ctx.addIssue({
|
|
83
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
84
|
+
message: `Support for DatabaseType ${input} is not implemented yet!`,
|
|
85
|
+
});
|
|
86
|
+
return zod_1.z.NEVER;
|
|
87
|
+
default:
|
|
88
|
+
throw new utils_1.ExhaustiveSwitchCheck(input);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* JSON Schema for an scalar field
|
|
93
|
+
*/
|
|
94
|
+
exports.zFieldScalarJSON = zod_1.z
|
|
95
|
+
.object({
|
|
96
|
+
name: Decoders.zFieldPropertyName,
|
|
97
|
+
type: zDatabaseType,
|
|
98
|
+
databaseName: Decoders.zFieldPropertyDatabaseName,
|
|
99
|
+
excelName: Decoders.zFieldPropertyExcelName,
|
|
100
|
+
label: Decoders.zFieldPropertyLabel,
|
|
101
|
+
description: Decoders.zFieldPropertyDescription,
|
|
102
|
+
isReadonly: Decoders.zFieldPropertyIsReadonly,
|
|
103
|
+
isUnique: Decoders.zFieldPropertyIsUnique,
|
|
104
|
+
hasIndex: Decoders.zFieldPropertyHasIndex,
|
|
105
|
+
isCreatedAt: Decoders.zFieldPropertyIsCreatedAt,
|
|
106
|
+
isUpdatedAt: Decoders.zFieldPropertyIsUpdatedAt,
|
|
107
|
+
maxLength: Decoders.zFieldPropertyMaxLength,
|
|
108
|
+
faker: Decoders.zFieldFaker,
|
|
109
|
+
seed: Decoders.zFieldSeed,
|
|
110
|
+
placeholder: Decoders.zFieldPropertyPlaceholder,
|
|
111
|
+
})
|
|
112
|
+
.strict();
|
|
113
|
+
const defaultPlaceholders = {
|
|
114
|
+
String: (label) => `${label} here...`,
|
|
115
|
+
Boolean: () => 'true',
|
|
116
|
+
DateTime: () => '2025-03-01T12: () =>00: () =>00.000Z',
|
|
117
|
+
Decimal: () => '1234.56',
|
|
118
|
+
Float: () => '1234.56',
|
|
119
|
+
Int: () => '1234',
|
|
120
|
+
Json: () => '{}',
|
|
121
|
+
Bytes: () => '1234',
|
|
122
|
+
BigInt: () => '1234',
|
|
123
|
+
};
|
|
124
|
+
function fieldScalarJSONTransformer(fieldInput, ctx) {
|
|
125
|
+
const isCreatedAt = fieldInput.isCreatedAt ?? false;
|
|
126
|
+
const isUpdatedAt = fieldInput.isUpdatedAt ?? false;
|
|
127
|
+
const required = (0, utils_2.isFieldRequired)(fieldInput.type);
|
|
128
|
+
const isRequired = isCreatedAt || isUpdatedAt ? false : required.isRequired;
|
|
129
|
+
const databaseType = Branded.toDatabaseFieldType(required.type);
|
|
130
|
+
const type = databaseTypeToFieldTypeScalar(databaseType, ctx);
|
|
131
|
+
const label = fieldInput.label ?? (0, utils_1.toHumanReadable)(fieldInput.name);
|
|
132
|
+
const placeholder = fieldInput.placeholder ?? defaultPlaceholders[databaseType](label);
|
|
133
|
+
return {
|
|
134
|
+
type,
|
|
135
|
+
kind: exports.fieldKindScalar,
|
|
136
|
+
name: Branded.toFieldName(fieldInput.name),
|
|
137
|
+
databaseType,
|
|
138
|
+
databaseName: Branded.toDatabaseFieldName(fieldInput.databaseName ?? (0, utils_1.toSnakeCase)(fieldInput.name)),
|
|
139
|
+
excelName: Branded.toExcelColumnName(fieldInput.excelName ?? fieldInput.label ?? fieldInput.name),
|
|
140
|
+
description: fieldInput.description,
|
|
141
|
+
label,
|
|
142
|
+
hasIndex: fieldInput.hasIndex ?? false,
|
|
143
|
+
isReadonly: fieldInput.isReadonly ?? (isCreatedAt || isUpdatedAt),
|
|
144
|
+
isRequired,
|
|
145
|
+
isUnique: fieldInput.isUnique ?? false,
|
|
146
|
+
isCreatedAt,
|
|
147
|
+
isUpdatedAt,
|
|
148
|
+
generation: '',
|
|
149
|
+
validations: {
|
|
150
|
+
maxLength: fieldInput.maxLength,
|
|
151
|
+
min: undefined,
|
|
152
|
+
max: undefined,
|
|
153
|
+
},
|
|
154
|
+
seed: (0, seed_1.seedTransformer)(fieldInput, ctx),
|
|
155
|
+
placeholder,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
exports.zFieldScalar = exports.zFieldScalarJSON.transform(fieldScalarJSONTransformer);
|
|
159
|
+
const fieldScalarTransformer = ({ fieldInput: { type, validations, ...shared }, model: { name: modelName }, }) => {
|
|
160
|
+
switch (type) {
|
|
161
|
+
case 'string':
|
|
162
|
+
return {
|
|
163
|
+
type,
|
|
164
|
+
validations: {
|
|
165
|
+
maxLength: validations.maxLength,
|
|
166
|
+
},
|
|
167
|
+
...shared,
|
|
168
|
+
modelName,
|
|
169
|
+
};
|
|
170
|
+
case 'number':
|
|
171
|
+
return {
|
|
172
|
+
type,
|
|
173
|
+
validations: {
|
|
174
|
+
type: shared.databaseType === 'Int' ? 'int' : 'float',
|
|
175
|
+
min: validations.min,
|
|
176
|
+
max: validations.max,
|
|
177
|
+
},
|
|
178
|
+
...shared,
|
|
179
|
+
modelName,
|
|
180
|
+
};
|
|
181
|
+
case 'boolean':
|
|
182
|
+
return {
|
|
183
|
+
type,
|
|
184
|
+
...shared,
|
|
185
|
+
modelName,
|
|
186
|
+
};
|
|
187
|
+
case 'Date':
|
|
188
|
+
return {
|
|
189
|
+
type,
|
|
190
|
+
...shared,
|
|
191
|
+
modelName,
|
|
192
|
+
};
|
|
193
|
+
default:
|
|
194
|
+
throw new utils_1.ExhaustiveSwitchCheck(type);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
exports.fieldScalarTransformer = fieldScalarTransformer;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ModelName } from '../../model/model.brands';
|
|
3
|
+
export declare const zFieldName: z.ZodBranded<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, "PXL.FieldName">;
|
|
4
|
+
export type FieldName = z.infer<typeof zFieldName>;
|
|
5
|
+
export declare const toFieldName: (input: string) => string & z.BRAND<"PXL.FieldName">;
|
|
6
|
+
export declare const zFieldIdName: z.ZodBranded<z.ZodBranded<z.ZodLiteral<"id">, "PXL.FieldName">, "PXL.FieldName.Id">;
|
|
7
|
+
export type FieldIdName = z.infer<typeof zFieldIdName>;
|
|
8
|
+
export declare const toFieldIdName: (input: string) => "id" & z.BRAND<"PXL.FieldName"> & z.BRAND<"PXL.FieldName.Id">;
|
|
9
|
+
export declare const zDatabaseFieldName: z.ZodBranded<z.ZodString, "PXL.DatabaseFieldName">;
|
|
10
|
+
export type DatabaseFieldName = z.infer<typeof zDatabaseFieldName>;
|
|
11
|
+
export declare const toDatabaseFieldName: (input: string) => string & z.BRAND<"PXL.DatabaseFieldName">;
|
|
12
|
+
export declare const zExcelColumnName: z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.ExcelColumnName">;
|
|
13
|
+
export type ExcelColumnName = z.infer<typeof zExcelColumnName>;
|
|
14
|
+
export declare const toExcelColumnName: (input: string) => string & z.BRAND<"PXL.ExcelColumnName">;
|
|
15
|
+
export declare const zFieldLabel: z.ZodBranded<z.ZodString, "PXL.FieldLabel">;
|
|
16
|
+
export type FieldLabel = z.infer<typeof zFieldLabel>;
|
|
17
|
+
export declare const toFieldLabel: (input: string) => string & z.BRAND<"PXL.FieldLabel">;
|
|
18
|
+
export declare const zType: z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.Type">;
|
|
19
|
+
export type Type = z.infer<typeof zType>;
|
|
20
|
+
export declare const toType: (input: string) => string & z.BRAND<"PXL.Type">;
|
|
21
|
+
export declare const zIdType: z.ZodBranded<z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.IdType">, "PXL.Type">;
|
|
22
|
+
export type IdType = z.infer<typeof zIdType>;
|
|
23
|
+
export declare const toIdType: (input: ModelName) => string & z.BRAND<"PXL.IdType"> & z.BRAND<"PXL.Type">;
|
|
24
|
+
export declare const zScalarType: z.ZodBranded<z.ZodBranded<z.ZodUnion<[z.ZodLiteral<"string">, z.ZodLiteral<"number">, z.ZodLiteral<"boolean">, z.ZodLiteral<"Date">]>, "PXL.ScalarType">, "PXL.Type">;
|
|
25
|
+
export type ScalarType = z.infer<typeof zScalarType>;
|
|
26
|
+
export declare const toScalarType: (input: string) => (("string" | "number" | "boolean" | "Date") & z.BRAND<"PXL.ScalarType">) & z.BRAND<"PXL.Type">;
|
|
27
|
+
export declare const zScalarIdType: z.ZodBranded<z.ZodBranded<z.ZodBranded<z.ZodUnion<[z.ZodLiteral<"string">, z.ZodLiteral<"number">]>, "PXL.ScalarIdType">, "PXL.ScalarType">, "PXL.Type">;
|
|
28
|
+
export type ScalarIdType = z.infer<typeof zScalarIdType>;
|
|
29
|
+
export declare const toScalarIdType: (input: string) => ((("string" | "number") & z.BRAND<"PXL.ScalarIdType">) & z.BRAND<"PXL.ScalarType">) & z.BRAND<"PXL.Type">;
|
|
30
|
+
export declare const zEnumType: z.ZodBranded<z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.EnumType">, "PXL.Type">;
|
|
31
|
+
export type EnumType = z.infer<typeof zEnumType>;
|
|
32
|
+
export declare const toEnumType: (input: string) => string & z.BRAND<"PXL.EnumType"> & z.BRAND<"PXL.Type">;
|
|
33
|
+
export declare const zDiscriminatedUnionType: z.ZodBranded<z.ZodBranded<z.ZodEffects<z.ZodString, string, string>, "PXL.DiscriminatedUnionType">, "PXL.Type">;
|
|
34
|
+
export type DiscriminatedUnionType = z.infer<typeof zDiscriminatedUnionType>;
|
|
35
|
+
export declare const toDiscriminatedUnionType: (input: string) => string & z.BRAND<"PXL.DiscriminatedUnionType"> & z.BRAND<"PXL.Type">;
|
|
36
|
+
export declare const zDatabaseFieldType: z.ZodBranded<z.ZodUnion<[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">;
|
|
37
|
+
export type DatabaseFieldType = z.infer<typeof zDatabaseFieldType>;
|
|
38
|
+
export declare const toDatabaseFieldType: (input: string) => ("BigInt" | "String" | "Boolean" | "DateTime" | "Decimal" | "Float" | "Int" | "Json" | "Bytes") & z.BRAND<"PXL.DatabaseFieldType">;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDatabaseFieldType = exports.zDatabaseFieldType = exports.toDiscriminatedUnionType = exports.zDiscriminatedUnionType = 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
|
+
const zod_1 = require("zod");
|
|
5
|
+
const utils_1 = require("@postxl/utils");
|
|
6
|
+
// --- Names ---------------------------------------------------------------------------------------
|
|
7
|
+
exports.zFieldName = zod_1.z
|
|
8
|
+
.string()
|
|
9
|
+
.refine(utils_1.isCamelCase, (s) => ({ message: `Field name must be camelCase - received ${s}, expected ${(0, utils_1.toCamelCase)(s)}` }))
|
|
10
|
+
.refine((s) => !s.endsWith('?'), (s) => ({
|
|
11
|
+
message: `Field name "${s}" must not end with '?'! If you want to make a field optional, add "?" to the 'type' property, not to 'name'!`,
|
|
12
|
+
}))
|
|
13
|
+
.brand('PXL.FieldName');
|
|
14
|
+
const toFieldName = (input) => exports.zFieldName.parse(input);
|
|
15
|
+
exports.toFieldName = toFieldName;
|
|
16
|
+
exports.zFieldIdName = zod_1.z.literal('id').brand('PXL.FieldName').brand('PXL.FieldName.Id');
|
|
17
|
+
const toFieldIdName = (input) => exports.zFieldIdName.parse(input);
|
|
18
|
+
exports.toFieldIdName = toFieldIdName;
|
|
19
|
+
exports.zDatabaseFieldName = zod_1.z.string().brand('PXL.DatabaseFieldName');
|
|
20
|
+
const toDatabaseFieldName = (input) => exports.zDatabaseFieldName.parse(input);
|
|
21
|
+
exports.toDatabaseFieldName = toDatabaseFieldName;
|
|
22
|
+
exports.zExcelColumnName = zod_1.z
|
|
23
|
+
.string()
|
|
24
|
+
.transform((name) => (0, utils_1.toExcelColumnName)(name))
|
|
25
|
+
.brand('PXL.ExcelColumnName');
|
|
26
|
+
const toExcelColumnName = (input) => exports.zExcelColumnName.parse(input);
|
|
27
|
+
exports.toExcelColumnName = toExcelColumnName;
|
|
28
|
+
exports.zFieldLabel = zod_1.z.string().brand('PXL.FieldLabel');
|
|
29
|
+
const toFieldLabel = (input) => exports.zFieldLabel.parse(input);
|
|
30
|
+
exports.toFieldLabel = toFieldLabel;
|
|
31
|
+
// --- Types ---------------------------------------------------------------------------------------
|
|
32
|
+
exports.zType = zod_1.z
|
|
33
|
+
.string()
|
|
34
|
+
.refine(utils_1.isPascalCase, (s) => ({ message: `Type must be PascalCase - received ${s}, expected ${(0, utils_1.toPascalCase)(s)}` }))
|
|
35
|
+
.brand('PXL.Type')
|
|
36
|
+
.describe('The name of the TypeScript type');
|
|
37
|
+
const toType = (input) => exports.zType.parse(input);
|
|
38
|
+
exports.toType = toType;
|
|
39
|
+
exports.zIdType = zod_1.z
|
|
40
|
+
.string()
|
|
41
|
+
.refine(utils_1.isPascalCase, (s) => ({ message: `Id type must be PascalCase - received ${s}, expected ${(0, utils_1.toPascalCase)(s)}` }))
|
|
42
|
+
.brand('PXL.IdType')
|
|
43
|
+
.brand('PXL.Type')
|
|
44
|
+
.describe('The name of the TypeScript type that represents an id field of a model, e.g. `UserId`');
|
|
45
|
+
const toIdType = (input) => {
|
|
46
|
+
const name = `${input}Id`;
|
|
47
|
+
return exports.zIdType.parse(name);
|
|
48
|
+
};
|
|
49
|
+
exports.toIdType = toIdType;
|
|
50
|
+
exports.zScalarType = zod_1.z
|
|
51
|
+
.union([
|
|
52
|
+
//
|
|
53
|
+
zod_1.z.literal('string'),
|
|
54
|
+
zod_1.z.literal('number'),
|
|
55
|
+
zod_1.z.literal('boolean'),
|
|
56
|
+
zod_1.z.literal('Date'),
|
|
57
|
+
])
|
|
58
|
+
.brand('PXL.ScalarType')
|
|
59
|
+
.brand('PXL.Type')
|
|
60
|
+
.describe('The name of the TypeScript type that represents a scalar field, e.g. `string`');
|
|
61
|
+
const toScalarType = (input) => exports.zScalarType.parse(input);
|
|
62
|
+
exports.toScalarType = toScalarType;
|
|
63
|
+
exports.zScalarIdType = zod_1.z
|
|
64
|
+
.union([
|
|
65
|
+
//
|
|
66
|
+
zod_1.z.literal('string'),
|
|
67
|
+
zod_1.z.literal('number'),
|
|
68
|
+
])
|
|
69
|
+
.brand('PXL.ScalarIdType')
|
|
70
|
+
.brand('PXL.ScalarType')
|
|
71
|
+
.brand('PXL.Type')
|
|
72
|
+
.describe('The name of the TypeScript type that represents a scalar Id field, i.e. `string` or `number`');
|
|
73
|
+
const toScalarIdType = (input) => exports.zScalarIdType.parse(input);
|
|
74
|
+
exports.toScalarIdType = toScalarIdType;
|
|
75
|
+
exports.zEnumType = zod_1.z
|
|
76
|
+
.string()
|
|
77
|
+
.refine(utils_1.isPascalCase, (s) => ({
|
|
78
|
+
message: `Enum name must be PascalCase - received ${s}, expected ${(0, utils_1.toPascalCase)(s)}`,
|
|
79
|
+
}))
|
|
80
|
+
.brand('PXL.EnumType')
|
|
81
|
+
.brand('PXL.Type')
|
|
82
|
+
.describe('The name of the TypeScript type that represents an enum, e.g. `ActionStatus`');
|
|
83
|
+
const toEnumType = (input) => exports.zEnumType.parse(input);
|
|
84
|
+
exports.toEnumType = toEnumType;
|
|
85
|
+
exports.zDiscriminatedUnionType = zod_1.z
|
|
86
|
+
.string()
|
|
87
|
+
.refine(utils_1.isPascalCase, { message: 'Discriminated union name must be PascalCase' })
|
|
88
|
+
.brand('PXL.DiscriminatedUnionType')
|
|
89
|
+
.brand('PXL.Type')
|
|
90
|
+
.describe('The name of the TypeScript type that represents a discriminated union, e.g. `ActionStatus`');
|
|
91
|
+
const toDiscriminatedUnionType = (input) => exports.zDiscriminatedUnionType.parse(input);
|
|
92
|
+
exports.toDiscriminatedUnionType = toDiscriminatedUnionType;
|
|
93
|
+
// --- Database ---------------------------------------------------------------------------------------
|
|
94
|
+
exports.zDatabaseFieldType = zod_1.z
|
|
95
|
+
.union([
|
|
96
|
+
zod_1.z.literal('BigInt'),
|
|
97
|
+
zod_1.z.literal('String'),
|
|
98
|
+
zod_1.z.literal('Boolean'),
|
|
99
|
+
zod_1.z.literal('DateTime'),
|
|
100
|
+
zod_1.z.literal('Decimal'),
|
|
101
|
+
zod_1.z.literal('Float'),
|
|
102
|
+
zod_1.z.literal('Int'),
|
|
103
|
+
zod_1.z.literal('Json'),
|
|
104
|
+
zod_1.z.literal('Bytes'),
|
|
105
|
+
])
|
|
106
|
+
.brand('PXL.DatabaseFieldType')
|
|
107
|
+
.describe('The name of the database type, e.g. `BigInt`, `String`, `Boolean`, `DateTime`');
|
|
108
|
+
const toDatabaseFieldType = (input) => exports.zDatabaseFieldType.parse(input);
|
|
109
|
+
exports.toDatabaseFieldType = toDatabaseFieldType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const zFieldPropertyName: z.ZodEffects<z.ZodString, string, string>;
|
|
3
|
+
export declare const zFieldPropertyType: z.ZodString;
|
|
4
|
+
export declare const zFieldPropertyDatabaseName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
export declare const zFieldPropertyExcelName: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
6
|
+
export declare const zFieldPropertyLabel: z.ZodOptional<z.ZodString>;
|
|
7
|
+
export declare const zFieldPropertyDescription: z.ZodOptional<z.ZodString>;
|
|
8
|
+
export declare const zFieldPropertyIsReadonly: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
+
export declare const zFieldPropertyIsUnique: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
export declare const zFieldPropertyHasIndex: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
export declare const zFieldPropertyIsCreatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
export declare const zFieldPropertyIsUpdatedAt: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
export declare const zFieldPropertyMaxLength: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
export declare const zFieldFaker: z.ZodOptional<z.ZodString>;
|
|
15
|
+
export declare const zScalarValue: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>;
|
|
16
|
+
export declare const zFieldSeed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, "many">]>>;
|
|
17
|
+
export declare const zFieldPropertyPlaceholder: z.ZodOptional<z.ZodString>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const utils_1 = require("@postxl/utils");
|
|
6
|
+
exports.zFieldPropertyName = zod_1.z
|
|
7
|
+
//
|
|
8
|
+
.string()
|
|
9
|
+
.min(1, 'Name of the field must not be empty')
|
|
10
|
+
.refine((name) => (0, utils_1.toCamelCase)(name) === name, (name) => ({ message: `Field name must be camelCased, but is ${(0, utils_1.red)(name)}!` }))
|
|
11
|
+
.describe('Name of the field. Must be camelCased.');
|
|
12
|
+
exports.zFieldPropertyType = zod_1.z
|
|
13
|
+
.string()
|
|
14
|
+
.min(1, 'Type of the field must not be empty')
|
|
15
|
+
.describe(`The type of the field. This should either be:
|
|
16
|
+
* \`String\` or \`Int\` in case name is \`id\
|
|
17
|
+
* \`String\`, \`Int\`, \`Float\` or \`DateTime\` for scalar fields
|
|
18
|
+
* A model name for relation fields
|
|
19
|
+
* An enum name for enum fields
|
|
20
|
+
|
|
21
|
+
Note: If type ends with an \`?\`, the field is optional, else it is required.`);
|
|
22
|
+
exports.zFieldPropertyDatabaseName = zod_1.z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Mapping of the field to the database column. If not provided, we use the snakecase of `name` field.');
|
|
26
|
+
exports.zFieldPropertyExcelName = zod_1.z
|
|
27
|
+
.string()
|
|
28
|
+
.optional()
|
|
29
|
+
.refine((val) => val === undefined || val === (0, utils_1.toExcelColumnName)(val), (val) => ({
|
|
30
|
+
message: `Excel column name "${(0, utils_1.red)(val ?? '')}" is not a valid Excel table name. It must start with a letter or underscore and can only contain letters, numbers, and underscores.`,
|
|
31
|
+
}))
|
|
32
|
+
.describe('Mapping of the field to an Excel column name. If not provided, we use the `label` field.');
|
|
33
|
+
exports.zFieldPropertyLabel = zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('The human readable label/name of the field. Used for instance in generated forms to label fields.\n\nIf not provided, we use the `name` field.');
|
|
37
|
+
exports.zFieldPropertyDescription = zod_1.z
|
|
38
|
+
.string()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('A helpful description of the field. Will be used as JSDoc documentation in the generated type.');
|
|
41
|
+
// Flags
|
|
42
|
+
exports.zFieldPropertyIsReadonly = zod_1.z
|
|
43
|
+
//
|
|
44
|
+
.boolean()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('If true, the field is readonly, ie. it cannot be changed by the user.');
|
|
47
|
+
exports.zFieldPropertyIsUnique = zod_1.z
|
|
48
|
+
//
|
|
49
|
+
.boolean()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('If true, uniqueness is enforced for the field, ie no two items can have the same value for this field.');
|
|
52
|
+
exports.zFieldPropertyHasIndex = zod_1.z
|
|
53
|
+
//
|
|
54
|
+
.boolean()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('If true, the repository will expose an index for the field.');
|
|
57
|
+
exports.zFieldPropertyIsCreatedAt = zod_1.z
|
|
58
|
+
//
|
|
59
|
+
.boolean()
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('If true, the field is automatically set to the current date and time when the item is created.');
|
|
62
|
+
exports.zFieldPropertyIsUpdatedAt = zod_1.z
|
|
63
|
+
//
|
|
64
|
+
.boolean()
|
|
65
|
+
.optional()
|
|
66
|
+
.describe('If true, the field is automatically set to the current date and time when the item is updated.');
|
|
67
|
+
exports.zFieldPropertyMaxLength = zod_1.z
|
|
68
|
+
//
|
|
69
|
+
.number()
|
|
70
|
+
.positive()
|
|
71
|
+
.int()
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('If provided, the maximum length of the field. Only applicable for `String` fields.');
|
|
74
|
+
exports.zFieldFaker = zod_1.z
|
|
75
|
+
//
|
|
76
|
+
.string()
|
|
77
|
+
.optional()
|
|
78
|
+
.describe('The faker function to use for the field. If neither faker nor seed is provided, we use the default faker function for the field type.');
|
|
79
|
+
exports.zScalarValue = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.date()]);
|
|
80
|
+
exports.zFieldSeed = exports.zScalarValue
|
|
81
|
+
.or(zod_1.z.array(exports.zScalarValue))
|
|
82
|
+
.optional()
|
|
83
|
+
.describe('The seed data for the field. If not provided, we use the faker function for the field type.');
|
|
84
|
+
exports.zFieldPropertyPlaceholder = zod_1.z
|
|
85
|
+
//
|
|
86
|
+
.string()
|
|
87
|
+
.optional()
|
|
88
|
+
.describe('A generic placeholder that is used to pre-populate empty fields.');
|