@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
@@ -1,5 +1,411 @@
1
- import "./types.js";
2
- import { defineEntity, defineEntityEnum, field, index } from "./defineEntity.js";
3
- import { composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema } from "./generator.js";
1
+ // @bun
2
+ // src/entity/defineEntity.ts
3
+ import * as z from "zod";
4
+ function defineEntity(spec) {
5
+ return spec;
6
+ }
7
+ function defineEntityEnum(def) {
8
+ return def;
9
+ }
10
+ var field = {
11
+ string(opts) {
12
+ return { kind: "scalar", type: "String", ...opts };
13
+ },
14
+ int(opts) {
15
+ return { kind: "scalar", type: "Int", ...opts };
16
+ },
17
+ float(opts) {
18
+ return { kind: "scalar", type: "Float", ...opts };
19
+ },
20
+ boolean(opts) {
21
+ return { kind: "scalar", type: "Boolean", ...opts };
22
+ },
23
+ dateTime(opts) {
24
+ return { kind: "scalar", type: "DateTime", ...opts };
25
+ },
26
+ json(opts) {
27
+ return { kind: "scalar", type: "Json", ...opts };
28
+ },
29
+ bigInt(opts) {
30
+ return { kind: "scalar", type: "BigInt", ...opts };
31
+ },
32
+ decimal(opts) {
33
+ return { kind: "scalar", type: "Decimal", ...opts };
34
+ },
35
+ bytes(opts) {
36
+ return { kind: "scalar", type: "Bytes", ...opts };
37
+ },
38
+ id(opts) {
39
+ return {
40
+ kind: "scalar",
41
+ type: "String",
42
+ isId: true,
43
+ default: "cuid()",
44
+ ...opts
45
+ };
46
+ },
47
+ uuid(opts) {
48
+ return {
49
+ kind: "scalar",
50
+ type: "String",
51
+ isId: true,
52
+ default: "uuid()",
53
+ ...opts
54
+ };
55
+ },
56
+ autoIncrement(opts) {
57
+ return {
58
+ kind: "scalar",
59
+ type: "Int",
60
+ isId: true,
61
+ default: "autoincrement()",
62
+ ...opts
63
+ };
64
+ },
65
+ createdAt(opts) {
66
+ return { kind: "scalar", type: "DateTime", default: "now()", ...opts };
67
+ },
68
+ updatedAt(opts) {
69
+ return { kind: "scalar", type: "DateTime", updatedAt: true, ...opts };
70
+ },
71
+ email(opts) {
72
+ return {
73
+ kind: "scalar",
74
+ type: "String",
75
+ zod: z.email(),
76
+ ...opts
77
+ };
78
+ },
79
+ url(opts) {
80
+ return {
81
+ kind: "scalar",
82
+ type: "String",
83
+ zod: z.url(),
84
+ ...opts
85
+ };
86
+ },
87
+ enum(enumName, opts) {
88
+ return { kind: "enum", enumName, ...opts };
89
+ },
90
+ inlineEnum(enumName, values, opts) {
91
+ return { kind: "enum", enumName, values, ...opts };
92
+ },
93
+ hasOne(target, opts) {
94
+ return { kind: "relation", type: "hasOne", target, ...opts };
95
+ },
96
+ hasMany(target, opts) {
97
+ return { kind: "relation", type: "hasMany", target, ...opts };
98
+ },
99
+ belongsTo(target, fields, references, opts) {
100
+ return {
101
+ kind: "relation",
102
+ type: "belongsTo",
103
+ target,
104
+ fields,
105
+ references,
106
+ ...opts
107
+ };
108
+ },
109
+ foreignKey(opts) {
110
+ return { kind: "scalar", type: "String", ...opts };
111
+ }
112
+ };
113
+ var index = {
114
+ on(fields, opts) {
115
+ return { fields, ...opts };
116
+ },
117
+ unique(fields, opts) {
118
+ return { fields, unique: true, ...opts };
119
+ },
120
+ compound(fields, sort, opts) {
121
+ return { fields, sort, ...opts };
122
+ }
123
+ };
4
124
 
5
- export { composeModuleSchemas, defineEntity, defineEntityEnum, field, generateEntityFragment, generateEnumFragment, generatePrismaSchema, index };
125
+ // src/entity/generator.ts
126
+ function generatePrismaSchema(entities, options = {}) {
127
+ const {
128
+ provider = "postgresql",
129
+ clientOutput = "../../src/generated/prisma",
130
+ includePothos = true,
131
+ pothosOutput = "../../src/generated/pothos-types.ts"
132
+ } = options;
133
+ const lines = [];
134
+ const schemas = new Set;
135
+ entities.forEach((entity) => {
136
+ if (entity.schema) {
137
+ schemas.add(entity.schema);
138
+ }
139
+ });
140
+ const schemaList = schemas.size > 0 ? Array.from(schemas) : ["public"];
141
+ lines.push("datasource db {");
142
+ lines.push(` provider = "${provider}"`);
143
+ if (schemas.size > 0) {
144
+ lines.push(` schemas = [${schemaList.map((s) => `"${s}"`).join(", ")}]`);
145
+ }
146
+ lines.push("}");
147
+ lines.push("");
148
+ lines.push("generator client {");
149
+ lines.push(' provider = "prisma-client"');
150
+ lines.push(` output = "${clientOutput}"`);
151
+ lines.push("");
152
+ lines.push(' engineType = "client"');
153
+ lines.push(' runtime = "bun"');
154
+ lines.push(' moduleFormat = "esm"');
155
+ lines.push(' generatedFileExtension = "ts"');
156
+ lines.push(' importFileExtension = "ts"');
157
+ lines.push("}");
158
+ lines.push("");
159
+ if (includePothos) {
160
+ lines.push("generator pothos {");
161
+ lines.push(' provider = "prisma-pothos-types"');
162
+ lines.push(' clientOutput = "./prisma"');
163
+ lines.push(` output = "${pothosOutput}"`);
164
+ lines.push(" generateDatamodel = true");
165
+ lines.push(" documentation = false");
166
+ lines.push("}");
167
+ lines.push("");
168
+ }
169
+ const enumMap = new Map;
170
+ entities.forEach((entity) => {
171
+ entity.enums?.forEach((enumDef) => {
172
+ if (!enumMap.has(enumDef.name)) {
173
+ enumMap.set(enumDef.name, enumDef);
174
+ }
175
+ });
176
+ Object.values(entity.fields).forEach((field2) => {
177
+ if (field2.kind === "enum" && field2.values && !enumMap.has(field2.enumName)) {
178
+ enumMap.set(field2.enumName, {
179
+ name: field2.enumName,
180
+ values: field2.values,
181
+ schema: entity.schema
182
+ });
183
+ }
184
+ });
185
+ });
186
+ enumMap.forEach((enumDef) => {
187
+ lines.push(...generateEnumBlock(enumDef));
188
+ lines.push("");
189
+ });
190
+ entities.forEach((entity) => {
191
+ lines.push(...generateModelBlock(entity));
192
+ lines.push("");
193
+ });
194
+ return lines.join(`
195
+ `);
196
+ }
197
+ function generateEnumBlock(enumDef) {
198
+ const lines = [];
199
+ if (enumDef.description) {
200
+ lines.push(`/// ${enumDef.description}`);
201
+ }
202
+ lines.push(`enum ${enumDef.name} {`);
203
+ enumDef.values.forEach((value) => {
204
+ lines.push(` ${value}`);
205
+ });
206
+ lines.push("");
207
+ if (enumDef.schema) {
208
+ lines.push(` @@schema("${enumDef.schema}")`);
209
+ }
210
+ lines.push("}");
211
+ return lines;
212
+ }
213
+ function generateModelBlock(entity) {
214
+ const lines = [];
215
+ if (entity.description) {
216
+ lines.push(`/// ${entity.description}`);
217
+ }
218
+ lines.push(`model ${entity.name} {`);
219
+ Object.entries(entity.fields).forEach(([fieldName, field2]) => {
220
+ const fieldLine = generateFieldLine(fieldName, field2);
221
+ if (field2.description) {
222
+ lines.push(` /// ${field2.description}`);
223
+ }
224
+ lines.push(` ${fieldLine}`);
225
+ });
226
+ if (entity.indexes && entity.indexes.length > 0) {
227
+ lines.push("");
228
+ entity.indexes.forEach((idx) => {
229
+ lines.push(` ${generateIndexLine(idx)}`);
230
+ });
231
+ }
232
+ if (entity.map) {
233
+ lines.push(` @@map("${entity.map}")`);
234
+ }
235
+ if (entity.schema) {
236
+ lines.push(` @@schema("${entity.schema}")`);
237
+ }
238
+ lines.push("}");
239
+ return lines;
240
+ }
241
+ function generateFieldLine(fieldName, field2) {
242
+ if (field2.kind === "scalar") {
243
+ return generateScalarFieldLine(fieldName, field2);
244
+ } else if (field2.kind === "enum") {
245
+ return generateEnumFieldLine(fieldName, field2);
246
+ } else if (field2.kind === "relation") {
247
+ return generateRelationFieldLine(fieldName, field2);
248
+ }
249
+ throw new Error(`Unknown field kind: ${field2.kind}`);
250
+ }
251
+ function generateScalarFieldLine(fieldName, field2) {
252
+ const parts = [fieldName];
253
+ let typeStr = field2.type;
254
+ if (field2.isArray) {
255
+ typeStr += "[]";
256
+ }
257
+ if (field2.isOptional) {
258
+ typeStr += "?";
259
+ }
260
+ parts.push(typeStr);
261
+ const attrs = [];
262
+ if (field2.isId) {
263
+ attrs.push("@id");
264
+ }
265
+ if (field2.default !== undefined) {
266
+ if (typeof field2.default === "string" && field2.default.includes("(")) {
267
+ attrs.push(`@default(${field2.default})`);
268
+ } else if (typeof field2.default === "boolean") {
269
+ attrs.push(`@default(${field2.default})`);
270
+ } else if (typeof field2.default === "number") {
271
+ attrs.push(`@default(${field2.default})`);
272
+ } else {
273
+ attrs.push(`@default("${field2.default}")`);
274
+ }
275
+ }
276
+ if (field2.updatedAt) {
277
+ attrs.push("@updatedAt");
278
+ }
279
+ if (field2.isUnique) {
280
+ attrs.push("@unique");
281
+ }
282
+ if (field2.map) {
283
+ attrs.push(`@map("${field2.map}")`);
284
+ }
285
+ if (field2.dbType) {
286
+ attrs.push(`@db.${field2.dbType}`);
287
+ }
288
+ if (attrs.length > 0) {
289
+ parts.push(attrs.join(" "));
290
+ }
291
+ return parts.join(" ");
292
+ }
293
+ function generateEnumFieldLine(fieldName, field2) {
294
+ const parts = [fieldName];
295
+ let typeStr = field2.enumName;
296
+ if (field2.isArray) {
297
+ typeStr += "[]";
298
+ }
299
+ if (field2.isOptional) {
300
+ typeStr += "?";
301
+ }
302
+ parts.push(typeStr);
303
+ const attrs = [];
304
+ if (field2.default !== undefined) {
305
+ attrs.push(`@default(${field2.default})`);
306
+ }
307
+ if (field2.isUnique) {
308
+ attrs.push("@unique");
309
+ }
310
+ if (field2.map) {
311
+ attrs.push(`@map("${field2.map}")`);
312
+ }
313
+ if (attrs.length > 0) {
314
+ parts.push(attrs.join(" "));
315
+ }
316
+ return parts.join(" ");
317
+ }
318
+ function generateRelationFieldLine(fieldName, field2) {
319
+ const parts = [fieldName];
320
+ let typeStr = field2.target;
321
+ if (field2.type === "hasMany") {
322
+ typeStr += "[]";
323
+ }
324
+ if (field2.type === "hasOne") {
325
+ typeStr += "?";
326
+ }
327
+ parts.push(typeStr);
328
+ const relationParts = [];
329
+ if (field2.name) {
330
+ relationParts.push(`name: "${field2.name}"`);
331
+ }
332
+ if (field2.fields && field2.fields.length > 0) {
333
+ relationParts.push(`fields: [${field2.fields.join(", ")}]`);
334
+ }
335
+ if (field2.references && field2.references.length > 0) {
336
+ relationParts.push(`references: [${field2.references.join(", ")}]`);
337
+ }
338
+ if (field2.onDelete) {
339
+ relationParts.push(`onDelete: ${field2.onDelete}`);
340
+ }
341
+ if (field2.onUpdate) {
342
+ relationParts.push(`onUpdate: ${field2.onUpdate}`);
343
+ }
344
+ if (relationParts.length > 0) {
345
+ parts.push(`@relation(${relationParts.join(", ")})`);
346
+ }
347
+ return parts.join(" ");
348
+ }
349
+ function generateIndexLine(idx) {
350
+ const fieldList = idx.fields.join(", ");
351
+ const parts = [];
352
+ if (idx.unique) {
353
+ parts.push(`@@unique([${fieldList}]`);
354
+ } else {
355
+ parts.push(`@@index([${fieldList}]`);
356
+ }
357
+ const options = [];
358
+ if (idx.name) {
359
+ options.push(`name: "${idx.name}"`);
360
+ }
361
+ if (idx.type) {
362
+ options.push(`type: ${idx.type}`);
363
+ }
364
+ if (options.length > 0) {
365
+ parts[0] += `, ${options.join(", ")}`;
366
+ }
367
+ parts[0] += ")";
368
+ return parts.join("");
369
+ }
370
+ function composeModuleSchemas(contributions, options = {}) {
371
+ const allEntities = [];
372
+ const allEnums = new Map;
373
+ contributions.forEach((contrib) => {
374
+ contrib.entities.forEach((entity) => {
375
+ allEntities.push({
376
+ ...entity,
377
+ module: contrib.moduleId
378
+ });
379
+ });
380
+ contrib.enums?.forEach((enumDef) => {
381
+ if (!allEnums.has(enumDef.name)) {
382
+ allEnums.set(enumDef.name, enumDef);
383
+ }
384
+ });
385
+ });
386
+ if (allEntities[0] && allEnums.size > 0) {
387
+ allEntities[0] = {
388
+ ...allEntities[0],
389
+ enums: [...allEntities[0].enums ?? [], ...allEnums.values()]
390
+ };
391
+ }
392
+ return generatePrismaSchema(allEntities, options);
393
+ }
394
+ function generateEntityFragment(entity) {
395
+ return generateModelBlock(entity).join(`
396
+ `);
397
+ }
398
+ function generateEnumFragment(enumDef) {
399
+ return generateEnumBlock(enumDef).join(`
400
+ `);
401
+ }
402
+ export {
403
+ index,
404
+ generatePrismaSchema,
405
+ generateEnumFragment,
406
+ generateEntityFragment,
407
+ field,
408
+ defineEntityEnum,
409
+ defineEntity,
410
+ composeModuleSchemas
411
+ };
@@ -1,145 +1,141 @@
1
- import * as z$1 from "zod";
2
-
3
- //#region src/entity/types.d.ts
1
+ import * as z from 'zod';
4
2
  /**
5
3
  * Prisma scalar types that can be used in entity field definitions.
6
4
  */
7
- type PrismaScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'DateTime' | 'Json' | 'BigInt' | 'Decimal' | 'Bytes';
5
+ export type PrismaScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'DateTime' | 'Json' | 'BigInt' | 'Decimal' | 'Bytes';
8
6
  /**
9
7
  * Prisma field modifiers.
10
8
  */
11
- interface PrismaFieldModifiers {
12
- /** Field is optional (nullable) */
13
- isOptional?: boolean;
14
- /** Field is an array */
15
- isArray?: boolean;
16
- /** Field is unique */
17
- isUnique?: boolean;
18
- /** Field is the primary key (use @id) */
19
- isId?: boolean;
20
- /** Default value expression (e.g., 'cuid()', 'now()', 'autoincrement()') */
21
- default?: string | number | boolean;
22
- /** Field is auto-updated on record update (e.g., @updatedAt) */
23
- updatedAt?: boolean;
24
- /** Database column name override */
25
- map?: string;
26
- /** Database column type override */
27
- dbType?: string;
9
+ export interface PrismaFieldModifiers {
10
+ /** Field is optional (nullable) */
11
+ isOptional?: boolean;
12
+ /** Field is an array */
13
+ isArray?: boolean;
14
+ /** Field is unique */
15
+ isUnique?: boolean;
16
+ /** Field is the primary key (use @id) */
17
+ isId?: boolean;
18
+ /** Default value expression (e.g., 'cuid()', 'now()', 'autoincrement()') */
19
+ default?: string | number | boolean;
20
+ /** Field is auto-updated on record update (e.g., @updatedAt) */
21
+ updatedAt?: boolean;
22
+ /** Database column name override */
23
+ map?: string;
24
+ /** Database column type override */
25
+ dbType?: string;
28
26
  }
29
27
  /**
30
28
  * Scalar field definition for an entity.
31
29
  */
32
- interface EntityScalarField extends PrismaFieldModifiers {
33
- kind: 'scalar';
34
- type: PrismaScalarType;
35
- /** Zod schema for validation */
36
- zod?: z$1.ZodType;
37
- /** Human-readable description (becomes Prisma /// comment) */
38
- description?: string;
30
+ export interface EntityScalarField extends PrismaFieldModifiers {
31
+ kind: 'scalar';
32
+ type: PrismaScalarType;
33
+ /** Zod schema for validation */
34
+ zod?: z.ZodType;
35
+ /** Human-readable description (becomes Prisma /// comment) */
36
+ description?: string;
39
37
  }
40
38
  /**
41
39
  * Enum field definition for an entity.
42
40
  */
43
- interface EntityEnumField extends PrismaFieldModifiers {
44
- kind: 'enum';
45
- /** Name of the enum type */
46
- enumName: string;
47
- /** Enum values (for inline enum definition) */
48
- values?: readonly string[];
49
- /** Zod schema for validation */
50
- zod?: z$1.ZodType;
51
- /** Human-readable description */
52
- description?: string;
41
+ export interface EntityEnumField extends PrismaFieldModifiers {
42
+ kind: 'enum';
43
+ /** Name of the enum type */
44
+ enumName: string;
45
+ /** Enum values (for inline enum definition) */
46
+ values?: readonly string[];
47
+ /** Zod schema for validation */
48
+ zod?: z.ZodType;
49
+ /** Human-readable description */
50
+ description?: string;
53
51
  }
54
52
  /**
55
53
  * Relation types supported by Prisma.
56
54
  */
57
- type RelationType = 'hasOne' | 'hasMany' | 'belongsTo';
55
+ export type RelationType = 'hasOne' | 'hasMany' | 'belongsTo';
58
56
  /**
59
57
  * Relation field definition for an entity.
60
58
  */
61
- interface EntityRelationField {
62
- kind: 'relation';
63
- type: RelationType;
64
- /** Target entity name */
65
- target: string;
66
- /** Foreign key field(s) on this model (for belongsTo) */
67
- fields?: string[];
68
- /** Referenced field(s) on the target model */
69
- references?: string[];
70
- /** Relation name for disambiguation */
71
- name?: string;
72
- /** On delete action */
73
- onDelete?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
74
- /** On update action */
75
- onUpdate?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
76
- /** Human-readable description */
77
- description?: string;
59
+ export interface EntityRelationField {
60
+ kind: 'relation';
61
+ type: RelationType;
62
+ /** Target entity name */
63
+ target: string;
64
+ /** Foreign key field(s) on this model (for belongsTo) */
65
+ fields?: string[];
66
+ /** Referenced field(s) on the target model */
67
+ references?: string[];
68
+ /** Relation name for disambiguation */
69
+ name?: string;
70
+ /** On delete action */
71
+ onDelete?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
72
+ /** On update action */
73
+ onUpdate?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
74
+ /** Human-readable description */
75
+ description?: string;
78
76
  }
79
77
  /**
80
78
  * Union of all entity field types.
81
79
  */
82
- type EntityField = EntityScalarField | EntityEnumField | EntityRelationField;
80
+ export type EntityField = EntityScalarField | EntityEnumField | EntityRelationField;
83
81
  /**
84
82
  * Index definition for an entity.
85
83
  */
86
- interface EntityIndex {
87
- /** Fields included in the index */
88
- fields: string[];
89
- /** Index is unique constraint */
90
- unique?: boolean;
91
- /** Index name override */
92
- name?: string;
93
- /** Sort order per field */
94
- sort?: Record<string, 'Asc' | 'Desc'>;
95
- /** Index type */
96
- type?: 'BTree' | 'Hash' | 'Gist' | 'Gin';
84
+ export interface EntityIndex {
85
+ /** Fields included in the index */
86
+ fields: string[];
87
+ /** Index is unique constraint */
88
+ unique?: boolean;
89
+ /** Index name override */
90
+ name?: string;
91
+ /** Sort order per field */
92
+ sort?: Record<string, 'Asc' | 'Desc'>;
93
+ /** Index type */
94
+ type?: 'BTree' | 'Hash' | 'Gist' | 'Gin';
97
95
  }
98
96
  /**
99
97
  * Enum definition that can be shared across entities.
100
98
  */
101
- interface EntityEnumDef {
102
- /** Enum name */
103
- name: string;
104
- /** Enum values */
105
- values: readonly string[];
106
- /** Postgres schema where the enum is defined */
107
- schema?: string;
108
- /** Human-readable description */
109
- description?: string;
99
+ export interface EntityEnumDef {
100
+ /** Enum name */
101
+ name: string;
102
+ /** Enum values */
103
+ values: readonly string[];
104
+ /** Postgres schema where the enum is defined */
105
+ schema?: string;
106
+ /** Human-readable description */
107
+ description?: string;
110
108
  }
111
109
  /**
112
110
  * Complete entity specification for database-backed models.
113
111
  */
114
- interface EntitySpec<TFields extends Record<string, EntityField> = Record<string, EntityField>> {
115
- /** Entity/model name (PascalCase) */
116
- name: string;
117
- /** Human-readable description (becomes Prisma /// comment) */
118
- description?: string;
119
- /** Postgres schema name (default: 'public') */
120
- schema?: string;
121
- /** Database table name override */
122
- map?: string;
123
- /** Field definitions */
124
- fields: TFields;
125
- /** Index definitions */
126
- indexes?: EntityIndex[];
127
- /** Enum definitions used by this entity */
128
- enums?: EntityEnumDef[];
129
- /** Module/domain this entity belongs to (for schema composition) */
130
- module?: string;
112
+ export interface EntitySpec<TFields extends Record<string, EntityField> = Record<string, EntityField>> {
113
+ /** Entity/model name (PascalCase) */
114
+ name: string;
115
+ /** Human-readable description (becomes Prisma /// comment) */
116
+ description?: string;
117
+ /** Postgres schema name (default: 'public') */
118
+ schema?: string;
119
+ /** Database table name override */
120
+ map?: string;
121
+ /** Field definitions */
122
+ fields: TFields;
123
+ /** Index definitions */
124
+ indexes?: EntityIndex[];
125
+ /** Enum definitions used by this entity */
126
+ enums?: EntityEnumDef[];
127
+ /** Module/domain this entity belongs to (for schema composition) */
128
+ module?: string;
131
129
  }
132
130
  /**
133
131
  * Module schema contribution for composition.
134
132
  */
135
- interface ModuleSchemaContribution {
136
- /** Module identifier (e.g., '@contractspec/lib.identity-rbac') */
137
- moduleId: string;
138
- /** Entity specs provided by this module */
139
- entities: EntitySpec[];
140
- /** Shared enum definitions */
141
- enums?: EntityEnumDef[];
133
+ export interface ModuleSchemaContribution {
134
+ /** Module identifier (e.g., '@contractspec/lib.identity-rbac') */
135
+ moduleId: string;
136
+ /** Entity specs provided by this module */
137
+ entities: EntitySpec[];
138
+ /** Shared enum definitions */
139
+ enums?: EntityEnumDef[];
142
140
  }
143
- //#endregion
144
- export { EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, ModuleSchemaContribution, PrismaFieldModifiers, PrismaScalarType, RelationType };
145
141
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/entity/types.ts"],"mappings":";;;;;AAKA;KAAY,gBAAA;;;;UAcK,oBAAA;EAAoB;EAEnC,UAAA;EAFmC;EAInC,OAAA;EAAA;EAEA,QAAA;EAEA;EAAA,IAAA;EAIA;EAFA,OAAA;EAMA;EAJA,SAAA;EAIM;EAFN,GAAA;EAQiC;EANjC,MAAA;AAAA;;;;UAMe,iBAAA,SAA0B,oBAAA;EACzC,IAAA;EACA,IAAA,EAAM,gBAAA;EAAN;EAEA,GAAA,GAAM,GAAA,CAAE,OAAA;EAAR;EAEA,WAAA;AAAA;;;;UAMe,eAAA,SAAwB,oBAAA;EACvC,IAAA;;EAEA,QAAA;EAHuC;EAKvC,MAAA;EAFA;EAIA,GAAA,GAAM,GAAA,CAAE,OAAA;EAAR;EAEA,WAAA;AAAA;;;;KAMU,YAAA;;;;UAKK,mBAAA;EACf,IAAA;EACA,IAAA,EAAM,YAAA;;EAEN,MAAA;EAHA;EAKA,MAAA;EAJM;EAMN,UAAA;EAFA;EAIA,IAAA;EAAA;EAEA,QAAA;EAE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