@contractspec/lib.schema 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/EnumType.d.ts +29 -31
  2. package/dist/EnumType.d.ts.map +1 -1
  3. package/dist/EnumType.js +38 -54
  4. package/dist/EnumType.test.d.ts +2 -0
  5. package/dist/EnumType.test.d.ts.map +1 -0
  6. package/dist/FieldType.d.ts +19 -23
  7. package/dist/FieldType.d.ts.map +1 -1
  8. package/dist/FieldType.js +41 -47
  9. package/dist/FieldType.test.d.ts +2 -0
  10. package/dist/FieldType.test.d.ts.map +1 -0
  11. package/dist/GraphQLSchemaType.d.ts +8 -12
  12. package/dist/GraphQLSchemaType.d.ts.map +1 -1
  13. package/dist/GraphQLSchemaType.js +16 -18
  14. package/dist/GraphQLSchemaType.test.d.ts +2 -0
  15. package/dist/GraphQLSchemaType.test.d.ts.map +1 -0
  16. package/dist/JsonSchemaType.d.ts +67 -63
  17. package/dist/JsonSchemaType.d.ts.map +1 -1
  18. package/dist/JsonSchemaType.js +73 -123
  19. package/dist/JsonSchemaType.test.d.ts +2 -0
  20. package/dist/JsonSchemaType.test.d.ts.map +1 -0
  21. package/dist/ScalarTypeEnum.d.ts +23 -27
  22. package/dist/ScalarTypeEnum.d.ts.map +1 -1
  23. package/dist/ScalarTypeEnum.js +235 -235
  24. package/dist/ScalarTypeEnum.test.d.ts +2 -0
  25. package/dist/ScalarTypeEnum.test.d.ts.map +1 -0
  26. package/dist/SchemaModel.d.ts +38 -39
  27. package/dist/SchemaModel.d.ts.map +1 -1
  28. package/dist/SchemaModel.js +28 -55
  29. package/dist/SchemaModel.test.d.ts +2 -0
  30. package/dist/SchemaModel.test.d.ts.map +1 -0
  31. package/dist/SchemaModelType.d.ts +28 -24
  32. package/dist/SchemaModelType.d.ts.map +1 -1
  33. package/dist/SchemaModelType.js +6 -19
  34. package/dist/SchemaModelType.test.d.ts +2 -0
  35. package/dist/SchemaModelType.test.d.ts.map +1 -0
  36. package/dist/ZodSchemaType.d.ts +44 -40
  37. package/dist/ZodSchemaType.d.ts.map +1 -1
  38. package/dist/ZodSchemaType.js +30 -101
  39. package/dist/ZodSchemaType.test.d.ts +2 -0
  40. package/dist/ZodSchemaType.test.d.ts.map +1 -0
  41. package/dist/browser/EnumType.js +40 -0
  42. package/dist/browser/FieldType.js +43 -0
  43. package/dist/browser/GraphQLSchemaType.js +18 -0
  44. package/dist/browser/JsonSchemaType.js +74 -0
  45. package/dist/browser/ScalarTypeEnum.js +236 -0
  46. package/dist/browser/SchemaModel.js +30 -0
  47. package/dist/browser/SchemaModelType.js +7 -0
  48. package/dist/browser/ZodSchemaType.js +31 -0
  49. package/dist/browser/entity/defineEntity.js +128 -0
  50. package/dist/browser/entity/generator.js +283 -0
  51. package/dist/browser/entity/index.js +410 -0
  52. package/dist/browser/entity/types.js +0 -0
  53. package/dist/browser/index.js +840 -0
  54. package/dist/entity/defineEntity.d.ts +55 -34
  55. package/dist/entity/defineEntity.d.ts.map +1 -1
  56. package/dist/entity/defineEntity.js +123 -231
  57. package/dist/entity/defineEntity.test.d.ts +2 -0
  58. package/dist/entity/defineEntity.test.d.ts.map +1 -0
  59. package/dist/entity/generator.d.ts +16 -20
  60. package/dist/entity/generator.d.ts.map +1 -1
  61. package/dist/entity/generator.js +262 -196
  62. package/dist/entity/generator.test.d.ts +2 -0
  63. package/dist/entity/generator.test.d.ts.map +1 -0
  64. package/dist/entity/index.d.ts +4 -4
  65. package/dist/entity/index.d.ts.map +1 -0
  66. package/dist/entity/index.js +410 -4
  67. package/dist/entity/types.d.ts +99 -103
  68. package/dist/entity/types.d.ts.map +1 -1
  69. package/dist/entity/types.js +1 -1
  70. package/dist/index.d.ts +10 -13
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +841 -13
  73. package/dist/node/EnumType.js +40 -0
  74. package/dist/node/FieldType.js +43 -0
  75. package/dist/node/GraphQLSchemaType.js +18 -0
  76. package/dist/node/JsonSchemaType.js +74 -0
  77. package/dist/node/ScalarTypeEnum.js +236 -0
  78. package/dist/node/SchemaModel.js +30 -0
  79. package/dist/node/SchemaModelType.js +7 -0
  80. package/dist/node/ZodSchemaType.js +31 -0
  81. package/dist/node/entity/defineEntity.js +128 -0
  82. package/dist/node/entity/generator.js +283 -0
  83. package/dist/node/entity/index.js +410 -0
  84. package/dist/node/entity/types.js +0 -0
  85. package/dist/node/index.js +840 -0
  86. package/package.json +123 -25
  87. package/dist/EnumType.js.map +0 -1
  88. package/dist/FieldType.js.map +0 -1
  89. package/dist/GraphQLSchemaType.js.map +0 -1
  90. package/dist/JsonSchemaType.js.map +0 -1
  91. package/dist/ScalarTypeEnum.js.map +0 -1
  92. package/dist/SchemaModel.js.map +0 -1
  93. package/dist/SchemaModelType.js.map +0 -1
  94. package/dist/ZodSchemaType.js.map +0 -1
  95. package/dist/entity/defineEntity.js.map +0 -1
  96. package/dist/entity/generator.js.map +0 -1
@@ -0,0 +1,40 @@
1
+ // src/EnumType.ts
2
+ import * as z from "zod";
3
+ import { GraphQLEnumType } from "graphql";
4
+
5
+ class EnumType {
6
+ name;
7
+ values;
8
+ gqlEnum;
9
+ constructor(name, values) {
10
+ this.name = name;
11
+ this.values = values;
12
+ this.gqlEnum = new GraphQLEnumType({
13
+ name: this.name,
14
+ values: Object.fromEntries(values.map((v) => [v, { value: v }]))
15
+ });
16
+ }
17
+ getName() {
18
+ return this.name;
19
+ }
20
+ getEnumValues() {
21
+ return this.values;
22
+ }
23
+ getPothos() {
24
+ return this.gqlEnum;
25
+ }
26
+ getZod() {
27
+ return z.enum(this.values);
28
+ }
29
+ getJson() {
30
+ return { type: "string", enum: this.values };
31
+ }
32
+ getJsonSchema() {
33
+ return this.getJson();
34
+ }
35
+ }
36
+ var defineEnum = (name, values) => new EnumType(name, values);
37
+ export {
38
+ defineEnum,
39
+ EnumType
40
+ };
@@ -0,0 +1,43 @@
1
+ // src/FieldType.ts
2
+ import { GraphQLScalarType } from "graphql";
3
+
4
+ class FieldType extends GraphQLScalarType {
5
+ zodSchema;
6
+ jsonSchemaDef;
7
+ constructor(config) {
8
+ super(config);
9
+ this.zodSchema = config.zod;
10
+ this.jsonSchemaDef = config.jsonSchema;
11
+ }
12
+ getZod() {
13
+ return this.zodSchema;
14
+ }
15
+ getPothos() {
16
+ return this;
17
+ }
18
+ getJson() {
19
+ return typeof this.jsonSchemaDef === "function" ? this.jsonSchemaDef() : this.jsonSchemaDef;
20
+ }
21
+ getJsonSchemaDef() {
22
+ return this.jsonSchemaDef;
23
+ }
24
+ getJsonSchema() {
25
+ const deepResolve = (v) => {
26
+ const value = typeof v === "function" ? v() : v;
27
+ if (Array.isArray(value))
28
+ return value.map((item) => deepResolve(item));
29
+ if (value && typeof value === "object") {
30
+ const obj = {};
31
+ for (const [k, val] of Object.entries(value)) {
32
+ obj[k] = deepResolve(val);
33
+ }
34
+ return obj;
35
+ }
36
+ return value;
37
+ };
38
+ return deepResolve(this.getJson());
39
+ }
40
+ }
41
+ export {
42
+ FieldType
43
+ };
@@ -0,0 +1,18 @@
1
+ // src/GraphQLSchemaType.ts
2
+ import { z } from "zod";
3
+
4
+ class GraphQLSchemaType {
5
+ typeDef;
6
+ name;
7
+ _isSchemaType = true;
8
+ constructor(typeDef, name) {
9
+ this.typeDef = typeDef;
10
+ this.name = name;
11
+ }
12
+ getZod() {
13
+ return z.unknown();
14
+ }
15
+ }
16
+ export {
17
+ GraphQLSchemaType
18
+ };
@@ -0,0 +1,74 @@
1
+ // src/JsonSchemaType.ts
2
+ import * as z from "zod";
3
+
4
+ class JsonSchemaType {
5
+ jsonSchema;
6
+ options;
7
+ constructor(jsonSchema, options = {}) {
8
+ this.jsonSchema = jsonSchema;
9
+ this.options = options;
10
+ }
11
+ getZod() {
12
+ if (this.jsonSchema.additionalProperties !== undefined) {
13
+ if (this.jsonSchema.additionalProperties === true) {
14
+ return z.record(z.string(), z.unknown());
15
+ }
16
+ if (typeof this.jsonSchema.additionalProperties === "object") {
17
+ return z.record(z.string(), z.unknown());
18
+ }
19
+ if (this.jsonSchema.additionalProperties === false) {
20
+ return z.object({}).strict();
21
+ }
22
+ }
23
+ if (this.jsonSchema.properties) {
24
+ const shape = {};
25
+ const required = new Set(this.jsonSchema.required ?? []);
26
+ for (const [key, propSchema] of Object.entries(this.jsonSchema.properties)) {
27
+ const fieldType = this.convertPropertyToZod(propSchema);
28
+ shape[key] = required.has(key) ? fieldType : fieldType.optional();
29
+ }
30
+ return z.object(shape).passthrough();
31
+ }
32
+ return z.object({}).passthrough();
33
+ }
34
+ getJsonSchema() {
35
+ return this.jsonSchema;
36
+ }
37
+ getPothos() {
38
+ return { type: "JSON", name: this.options.name };
39
+ }
40
+ getName() {
41
+ return this.options.name;
42
+ }
43
+ convertPropertyToZod(schema) {
44
+ const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
45
+ switch (type) {
46
+ case "string":
47
+ return z.string();
48
+ case "number":
49
+ case "integer":
50
+ return z.number();
51
+ case "boolean":
52
+ return z.boolean();
53
+ case "array":
54
+ if (schema.items && !Array.isArray(schema.items)) {
55
+ return z.array(this.convertPropertyToZod(schema.items));
56
+ }
57
+ return z.array(z.unknown());
58
+ case "object":
59
+ if (schema.properties) {
60
+ return new JsonSchemaType(schema).getZod();
61
+ }
62
+ return z.record(z.string(), z.unknown());
63
+ case "null":
64
+ return z.null();
65
+ default:
66
+ return z.unknown();
67
+ }
68
+ }
69
+ }
70
+ var fromJsonSchema = (schema, options) => new JsonSchemaType(schema, options);
71
+ export {
72
+ fromJsonSchema,
73
+ JsonSchemaType
74
+ };
@@ -0,0 +1,236 @@
1
+ // src/FieldType.ts
2
+ import { GraphQLScalarType } from "graphql";
3
+
4
+ class FieldType extends GraphQLScalarType {
5
+ zodSchema;
6
+ jsonSchemaDef;
7
+ constructor(config) {
8
+ super(config);
9
+ this.zodSchema = config.zod;
10
+ this.jsonSchemaDef = config.jsonSchema;
11
+ }
12
+ getZod() {
13
+ return this.zodSchema;
14
+ }
15
+ getPothos() {
16
+ return this;
17
+ }
18
+ getJson() {
19
+ return typeof this.jsonSchemaDef === "function" ? this.jsonSchemaDef() : this.jsonSchemaDef;
20
+ }
21
+ getJsonSchemaDef() {
22
+ return this.jsonSchemaDef;
23
+ }
24
+ getJsonSchema() {
25
+ const deepResolve = (v) => {
26
+ const value = typeof v === "function" ? v() : v;
27
+ if (Array.isArray(value))
28
+ return value.map((item) => deepResolve(item));
29
+ if (value && typeof value === "object") {
30
+ const obj = {};
31
+ for (const [k, val] of Object.entries(value)) {
32
+ obj[k] = deepResolve(val);
33
+ }
34
+ return obj;
35
+ }
36
+ return value;
37
+ };
38
+ return deepResolve(this.getJson());
39
+ }
40
+ }
41
+
42
+ // src/ScalarTypeEnum.ts
43
+ import * as z from "zod";
44
+ import { Kind } from "graphql";
45
+ var localeRegex = /^[A-Za-z]{2}(?:-[A-Za-z0-9]{2,8})*$/;
46
+ var timezoneRegex = /^(?:UTC|[A-Za-z_]+\/[A-Za-z_]+)$/;
47
+ var phoneRegex = /^[+]?\d[\d\s().-]{3,}$/;
48
+ var currencyRegex = /^[A-Z]{3}$/;
49
+ var countryRegex = /^[A-Z]{2}$/;
50
+ var latMin = -90;
51
+ var latMax = 90;
52
+ var lonMin = -180;
53
+ var lonMax = 180;
54
+ var ScalarTypeEnum = {
55
+ String_unsecure: () => new FieldType({
56
+ name: "String_unsecure",
57
+ description: "Unvalidated string scalar",
58
+ zod: z.string(),
59
+ parseValue: (v) => z.string().parse(v),
60
+ serialize: (v) => String(v),
61
+ parseLiteral: (ast) => {
62
+ if (ast.kind !== Kind.STRING)
63
+ throw new TypeError("Invalid literal");
64
+ return ast.value;
65
+ },
66
+ jsonSchema: { type: "string" }
67
+ }),
68
+ Int_unsecure: () => new FieldType({
69
+ name: "Int_unsecure",
70
+ description: "Unvalidated integer scalar",
71
+ zod: z.number().int(),
72
+ parseValue: (v) => {
73
+ const num = typeof v === "number" ? v : Number(v);
74
+ return z.number().int().parse(num);
75
+ },
76
+ serialize: (v) => Math.trunc(typeof v === "number" ? v : Number(v)),
77
+ parseLiteral: (ast) => {
78
+ if (ast.kind !== Kind.INT)
79
+ throw new TypeError("Invalid literal");
80
+ return Number(ast.value);
81
+ },
82
+ jsonSchema: { type: "integer" }
83
+ }),
84
+ Float_unsecure: () => new FieldType({
85
+ name: "Float_unsecure",
86
+ description: "Unvalidated float scalar",
87
+ zod: z.number(),
88
+ parseValue: (v) => {
89
+ const num = typeof v === "number" ? v : Number(v);
90
+ return z.number().parse(num);
91
+ },
92
+ serialize: (v) => Number(v),
93
+ parseLiteral: (ast) => {
94
+ if (ast.kind !== Kind.FLOAT && ast.kind !== Kind.INT)
95
+ throw new TypeError("Invalid literal");
96
+ return Number(ast.value);
97
+ },
98
+ jsonSchema: { type: "number" }
99
+ }),
100
+ Boolean: () => new FieldType({
101
+ name: "Boolean",
102
+ description: "Unvalidated boolean scalar",
103
+ zod: z.boolean(),
104
+ parseValue: (v) => z.coerce.boolean().parse(v),
105
+ serialize: (v) => Boolean(v),
106
+ parseLiteral: (ast) => {
107
+ if (ast.kind !== Kind.BOOLEAN)
108
+ throw new TypeError("Invalid literal");
109
+ return ast.value;
110
+ },
111
+ jsonSchema: { type: "boolean" }
112
+ }),
113
+ ID: () => new FieldType({
114
+ name: "ID",
115
+ description: "Unvalidated id scalar",
116
+ zod: z.string(),
117
+ parseValue: (v) => z.string().parse(v),
118
+ serialize: (v) => String(v),
119
+ parseLiteral: (ast) => {
120
+ if (ast.kind !== Kind.STRING)
121
+ throw new TypeError("Invalid literal");
122
+ return ast.value;
123
+ },
124
+ jsonSchema: { type: "string" }
125
+ }),
126
+ JSON: () => new FieldType({
127
+ name: "JSON",
128
+ zod: z.any(),
129
+ parseValue: (v) => v,
130
+ serialize: (v) => v,
131
+ jsonSchema: {}
132
+ }),
133
+ JSONObject: () => new FieldType({
134
+ name: "JSONObject",
135
+ zod: z.record(z.string(), z.any()),
136
+ parseValue: (v) => z.record(z.string(), z.any()).parse(v),
137
+ serialize: (v) => v ?? {},
138
+ jsonSchema: { type: "object" }
139
+ }),
140
+ Date: () => new FieldType({
141
+ name: "Date",
142
+ zod: z.date(),
143
+ parseValue: (v) => v instanceof Date ? v : new Date(String(v)),
144
+ serialize: (v) => v instanceof Date ? v.toISOString().split("T")[0] : String(v),
145
+ jsonSchema: { type: "string", format: "date" }
146
+ }),
147
+ DateTime: () => new FieldType({
148
+ name: "DateTime",
149
+ zod: z.date(),
150
+ parseValue: (v) => v instanceof Date ? v : new Date(String(v)),
151
+ serialize: (v) => {
152
+ return v instanceof Date ? v.toISOString() : String(v);
153
+ },
154
+ jsonSchema: { type: "string", format: "date-time" }
155
+ }),
156
+ Time: () => new FieldType({
157
+ name: "Time",
158
+ zod: z.string().regex(/^\d{2}:\d{2}(:\d{2})?$/),
159
+ parseValue: (v) => z.string().regex(/^\d{2}:\d{2}(:\d{2})?$/).parse(v),
160
+ serialize: (v) => String(v),
161
+ jsonSchema: { type: "string", pattern: "^\\d{2}:\\d{2}(:\\d{2})?$" }
162
+ }),
163
+ EmailAddress: () => new FieldType({
164
+ name: "EmailAddress",
165
+ zod: z.string().email(),
166
+ parseValue: (v) => z.string().email().parse(v),
167
+ serialize: (v) => String(v),
168
+ jsonSchema: { type: "string", format: "email" }
169
+ }),
170
+ URL: () => new FieldType({
171
+ name: "URL",
172
+ zod: z.string().url(),
173
+ parseValue: (v) => z.string().url().parse(v),
174
+ serialize: (v) => String(v),
175
+ jsonSchema: { type: "string", format: "uri" }
176
+ }),
177
+ PhoneNumber: () => new FieldType({
178
+ name: "PhoneNumber",
179
+ zod: z.string().regex(phoneRegex),
180
+ parseValue: (v) => z.string().regex(phoneRegex).parse(v),
181
+ serialize: (v) => String(v),
182
+ jsonSchema: { type: "string", pattern: phoneRegex.source }
183
+ }),
184
+ NonEmptyString: () => new FieldType({
185
+ name: "NonEmptyString",
186
+ zod: z.string().min(1),
187
+ parseValue: (v) => z.string().min(1).parse(v),
188
+ serialize: (v) => String(v),
189
+ jsonSchema: { type: "string", minLength: 1 }
190
+ }),
191
+ Locale: () => new FieldType({
192
+ name: "Locale",
193
+ zod: z.string().regex(localeRegex),
194
+ parseValue: (v) => z.string().regex(localeRegex).parse(v),
195
+ serialize: (v) => String(v),
196
+ jsonSchema: { type: "string", pattern: localeRegex.source }
197
+ }),
198
+ TimeZone: () => new FieldType({
199
+ name: "TimeZone",
200
+ zod: z.string().regex(timezoneRegex),
201
+ parseValue: (v) => z.string().regex(timezoneRegex).parse(v),
202
+ serialize: (v) => String(v),
203
+ jsonSchema: { type: "string", pattern: timezoneRegex.source }
204
+ }),
205
+ Latitude: () => new FieldType({
206
+ name: "Latitude",
207
+ zod: z.number().min(latMin).max(latMax),
208
+ parseValue: (v) => z.coerce.number().min(latMin).max(latMax).parse(v),
209
+ serialize: (v) => Number(v),
210
+ jsonSchema: { type: "number", minimum: latMin, maximum: latMax }
211
+ }),
212
+ Longitude: () => new FieldType({
213
+ name: "Longitude",
214
+ zod: z.number().min(lonMin).max(lonMax),
215
+ parseValue: (v) => z.coerce.number().min(lonMin).max(lonMax).parse(v),
216
+ serialize: (v) => Number(v),
217
+ jsonSchema: { type: "number", minimum: lonMin, maximum: lonMax }
218
+ }),
219
+ Currency: () => new FieldType({
220
+ name: "Currency",
221
+ zod: z.string().regex(currencyRegex),
222
+ parseValue: (v) => z.string().regex(currencyRegex).parse(v),
223
+ serialize: (v) => String(v),
224
+ jsonSchema: { type: "string", pattern: currencyRegex.source }
225
+ }),
226
+ CountryCode: () => new FieldType({
227
+ name: "CountryCode",
228
+ zod: z.string().regex(countryRegex),
229
+ parseValue: (v) => z.string().regex(countryRegex).parse(v),
230
+ serialize: (v) => String(v),
231
+ jsonSchema: { type: "string", pattern: countryRegex.source }
232
+ })
233
+ };
234
+ export {
235
+ ScalarTypeEnum
236
+ };
@@ -0,0 +1,30 @@
1
+ // src/SchemaModel.ts
2
+ import * as z from "zod";
3
+
4
+ class SchemaModel {
5
+ config;
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ getZod() {
10
+ const shape = Object.entries(this.config.fields).reduce((acc, [key, def]) => {
11
+ const base = def.type.getZod();
12
+ const withArray = def.isArray ? z.array(base) : base;
13
+ acc[key] = def.isOptional ? withArray.optional() : withArray;
14
+ return acc;
15
+ }, {});
16
+ return z.object(shape);
17
+ }
18
+ getPothosInput() {
19
+ return this.config.name;
20
+ }
21
+ }
22
+ function isSchemaModel(model) {
23
+ return model !== null && model !== undefined && "config" in model && typeof model.config === "object" && "name" in model.config;
24
+ }
25
+ var defineSchemaModel = (config) => new SchemaModel(config);
26
+ export {
27
+ isSchemaModel,
28
+ defineSchemaModel,
29
+ SchemaModel
30
+ };
@@ -0,0 +1,7 @@
1
+ // src/SchemaModelType.ts
2
+ function isSchemaType(value) {
3
+ return value !== null && typeof value === "object" && "getZod" in value && typeof value.getZod === "function";
4
+ }
5
+ export {
6
+ isSchemaType
7
+ };
@@ -0,0 +1,31 @@
1
+ // src/ZodSchemaType.ts
2
+ import * as z from "zod";
3
+
4
+ class ZodSchemaType {
5
+ schema;
6
+ options;
7
+ constructor(schema, options = {}) {
8
+ this.schema = schema;
9
+ this.options = options;
10
+ }
11
+ getZod() {
12
+ return this.schema;
13
+ }
14
+ getJsonSchema() {
15
+ return z.toJSONSchema(this.schema);
16
+ }
17
+ getPothos() {
18
+ return { type: "JSON", name: this.options.name };
19
+ }
20
+ getName() {
21
+ return this.options.name;
22
+ }
23
+ getDescription() {
24
+ return this.options.description;
25
+ }
26
+ }
27
+ var fromZod = (schema, options) => new ZodSchemaType(schema, options);
28
+ export {
29
+ fromZod,
30
+ ZodSchemaType
31
+ };
@@ -0,0 +1,128 @@
1
+ // src/entity/defineEntity.ts
2
+ import * as z from "zod";
3
+ function defineEntity(spec) {
4
+ return spec;
5
+ }
6
+ function defineEntityEnum(def) {
7
+ return def;
8
+ }
9
+ var field = {
10
+ string(opts) {
11
+ return { kind: "scalar", type: "String", ...opts };
12
+ },
13
+ int(opts) {
14
+ return { kind: "scalar", type: "Int", ...opts };
15
+ },
16
+ float(opts) {
17
+ return { kind: "scalar", type: "Float", ...opts };
18
+ },
19
+ boolean(opts) {
20
+ return { kind: "scalar", type: "Boolean", ...opts };
21
+ },
22
+ dateTime(opts) {
23
+ return { kind: "scalar", type: "DateTime", ...opts };
24
+ },
25
+ json(opts) {
26
+ return { kind: "scalar", type: "Json", ...opts };
27
+ },
28
+ bigInt(opts) {
29
+ return { kind: "scalar", type: "BigInt", ...opts };
30
+ },
31
+ decimal(opts) {
32
+ return { kind: "scalar", type: "Decimal", ...opts };
33
+ },
34
+ bytes(opts) {
35
+ return { kind: "scalar", type: "Bytes", ...opts };
36
+ },
37
+ id(opts) {
38
+ return {
39
+ kind: "scalar",
40
+ type: "String",
41
+ isId: true,
42
+ default: "cuid()",
43
+ ...opts
44
+ };
45
+ },
46
+ uuid(opts) {
47
+ return {
48
+ kind: "scalar",
49
+ type: "String",
50
+ isId: true,
51
+ default: "uuid()",
52
+ ...opts
53
+ };
54
+ },
55
+ autoIncrement(opts) {
56
+ return {
57
+ kind: "scalar",
58
+ type: "Int",
59
+ isId: true,
60
+ default: "autoincrement()",
61
+ ...opts
62
+ };
63
+ },
64
+ createdAt(opts) {
65
+ return { kind: "scalar", type: "DateTime", default: "now()", ...opts };
66
+ },
67
+ updatedAt(opts) {
68
+ return { kind: "scalar", type: "DateTime", updatedAt: true, ...opts };
69
+ },
70
+ email(opts) {
71
+ return {
72
+ kind: "scalar",
73
+ type: "String",
74
+ zod: z.email(),
75
+ ...opts
76
+ };
77
+ },
78
+ url(opts) {
79
+ return {
80
+ kind: "scalar",
81
+ type: "String",
82
+ zod: z.url(),
83
+ ...opts
84
+ };
85
+ },
86
+ enum(enumName, opts) {
87
+ return { kind: "enum", enumName, ...opts };
88
+ },
89
+ inlineEnum(enumName, values, opts) {
90
+ return { kind: "enum", enumName, values, ...opts };
91
+ },
92
+ hasOne(target, opts) {
93
+ return { kind: "relation", type: "hasOne", target, ...opts };
94
+ },
95
+ hasMany(target, opts) {
96
+ return { kind: "relation", type: "hasMany", target, ...opts };
97
+ },
98
+ belongsTo(target, fields, references, opts) {
99
+ return {
100
+ kind: "relation",
101
+ type: "belongsTo",
102
+ target,
103
+ fields,
104
+ references,
105
+ ...opts
106
+ };
107
+ },
108
+ foreignKey(opts) {
109
+ return { kind: "scalar", type: "String", ...opts };
110
+ }
111
+ };
112
+ var index = {
113
+ on(fields, opts) {
114
+ return { fields, ...opts };
115
+ },
116
+ unique(fields, opts) {
117
+ return { fields, unique: true, ...opts };
118
+ },
119
+ compound(fields, sort, opts) {
120
+ return { fields, sort, ...opts };
121
+ }
122
+ };
123
+ export {
124
+ index,
125
+ field,
126
+ defineEntityEnum,
127
+ defineEntity
128
+ };