@sequenceholdings/orm 0.1.1 → 0.1.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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/authoring.cjs +794 -0
  3. package/dist/authoring.cjs.map +1 -0
  4. package/dist/authoring.d.cts +274 -0
  5. package/dist/authoring.d.ts +274 -0
  6. package/dist/authoring.js +763 -0
  7. package/dist/authoring.js.map +1 -0
  8. package/dist/canonical.cjs +146 -0
  9. package/dist/canonical.cjs.map +1 -0
  10. package/dist/canonical.d.cts +369 -0
  11. package/dist/canonical.d.ts +369 -0
  12. package/dist/canonical.js +131 -0
  13. package/dist/canonical.js.map +1 -0
  14. package/dist/cli.cjs +6172 -1683
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.d.cts +8 -1
  17. package/dist/cli.d.ts +8 -1
  18. package/dist/cli.js +6172 -1685
  19. package/dist/cli.js.map +1 -1
  20. package/dist/client.cjs +120 -0
  21. package/dist/client.cjs.map +1 -1
  22. package/dist/client.d.cts +74 -2
  23. package/dist/client.d.ts +74 -2
  24. package/dist/client.js +116 -1
  25. package/dist/client.js.map +1 -1
  26. package/dist/compiler.cjs +3001 -0
  27. package/dist/compiler.cjs.map +1 -0
  28. package/dist/compiler.d.cts +581 -0
  29. package/dist/compiler.d.ts +581 -0
  30. package/dist/compiler.js +2947 -0
  31. package/dist/compiler.js.map +1 -0
  32. package/dist/index.cjs +1705 -326
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +117 -56
  35. package/dist/index.d.ts +117 -56
  36. package/dist/index.js +1619 -323
  37. package/dist/index.js.map +1 -1
  38. package/dist/ir.cjs +407 -0
  39. package/dist/ir.cjs.map +1 -0
  40. package/dist/ir.d.cts +1179 -0
  41. package/dist/ir.d.ts +1179 -0
  42. package/dist/ir.js +388 -0
  43. package/dist/ir.js.map +1 -0
  44. package/dist/naming-CTvWSRTf.d.ts +79 -0
  45. package/dist/naming-DRyinU4u.d.cts +79 -0
  46. package/dist/sdl.cjs +833 -0
  47. package/dist/sdl.cjs.map +1 -0
  48. package/dist/sdl.d.cts +96 -0
  49. package/dist/sdl.d.ts +96 -0
  50. package/dist/sdl.js +809 -0
  51. package/dist/sdl.js.map +1 -0
  52. package/package.json +36 -3
  53. package/src/codegen-gql/apollo-hooks.cjs +98 -0
  54. package/src/codegen-gql/server-fns.cjs +101 -0
  55. package/templates/README.md +13 -0
  56. package/templates/orm-namespace/CLAUDE.md +81 -0
  57. package/templates/orm-namespace/codegen.ts +22 -0
  58. package/templates/orm-namespace/gitignore +5 -0
  59. package/templates/orm-namespace/graphql/example/queries.ts +56 -0
  60. package/templates/orm-namespace/package.json +24 -0
  61. package/templates/orm-namespace/schema/tables.ts +71 -0
  62. package/templates/orm-namespace/sequence.config.ts +32 -0
  63. package/templates/orm-namespace/tsconfig.json +15 -0
@@ -0,0 +1,369 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Canonical namespace definition v2 — the data-only JSON a consumer's
5
+ * TypeScript schema serializes to. This is v2's equivalent of the v1 YAML
6
+ * `NamespaceDefinition`: the CLI's jiti loader produces it, the content hash
7
+ * is computed over it, the server re-validates it (consumer TS never runs
8
+ * server-side), and the SDL generator / GraphQL compiler / migration engine
9
+ * all consume it.
10
+ *
11
+ * FROZEN CONTRACT (week 1): downstream tracks build against these shapes.
12
+ * Additive evolution only; `definition_format` discriminates on the wire.
13
+ */
14
+
15
+ declare const CANONICAL_FORMAT: 2;
16
+ /** Identifier grammar shared with v1 (`^[a-z][a-z0-9_]*$`, ≤63 bytes). */
17
+ declare const IDENTIFIER_RE: RegExp;
18
+ /** The 10 v1 column types, unchanged in v2. */
19
+ declare const COLUMN_TYPES: readonly ["uuid", "text", "integer", "bigint", "numeric", "double", "boolean", "timestamptz", "date", "jsonb"];
20
+ type ColumnType = (typeof COLUMN_TYPES)[number];
21
+ /** Enum columns reference a namespace-level `defineEnum` by name. */
22
+ declare const canonicalEnumSchema: z.ZodObject<{
23
+ name: z.ZodString;
24
+ values: z.ZodArray<z.ZodString>;
25
+ }, z.core.$strip>;
26
+ type CanonicalEnum = z.infer<typeof canonicalEnumSchema>;
27
+ declare const canonicalColumnSchema: z.ZodObject<{
28
+ name: z.ZodString;
29
+ columnName: z.ZodString;
30
+ type: z.ZodUnion<readonly [z.ZodEnum<{
31
+ bigint: "bigint";
32
+ boolean: "boolean";
33
+ uuid: "uuid";
34
+ text: "text";
35
+ integer: "integer";
36
+ numeric: "numeric";
37
+ double: "double";
38
+ timestamptz: "timestamptz";
39
+ date: "date";
40
+ jsonb: "jsonb";
41
+ }>, z.ZodObject<{
42
+ enum: z.ZodString;
43
+ }, z.core.$strip>]>;
44
+ nullable: z.ZodDefault<z.ZodBoolean>;
45
+ unique: z.ZodDefault<z.ZodBoolean>;
46
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
47
+ defaultFn: z.ZodOptional<z.ZodEnum<{
48
+ "gen_random_uuid()": "gen_random_uuid()";
49
+ "now()": "now()";
50
+ }>>;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ renamedFrom: z.ZodOptional<z.ZodString>;
53
+ cast: z.ZodOptional<z.ZodString>;
54
+ deprecated: z.ZodDefault<z.ZodBoolean>;
55
+ }, z.core.$strip>;
56
+ type CanonicalColumn = z.infer<typeof canonicalColumnSchema>;
57
+ declare const canonicalLinkSchema: z.ZodObject<{
58
+ name: z.ZodString;
59
+ kind: z.ZodEnum<{
60
+ toOne: "toOne";
61
+ toMany: "toMany";
62
+ toPlatformUser: "toPlatformUser";
63
+ }>;
64
+ target: z.ZodOptional<z.ZodString>;
65
+ on: z.ZodString;
66
+ references: z.ZodOptional<z.ZodString>;
67
+ enforce: z.ZodDefault<z.ZodBoolean>;
68
+ description: z.ZodOptional<z.ZodString>;
69
+ }, z.core.$strip>;
70
+ type CanonicalLink = z.infer<typeof canonicalLinkSchema>;
71
+ declare const canonicalIndexSchema: z.ZodObject<{
72
+ columns: z.ZodArray<z.ZodString>;
73
+ unique: z.ZodDefault<z.ZodBoolean>;
74
+ name: z.ZodOptional<z.ZodString>;
75
+ }, z.core.$strip>;
76
+ /**
77
+ * Policy expressions stay DSL SOURCE STRINGS in the canonical form — parsing
78
+ * and claim-key validation happen in both CLI and server via the shared
79
+ * predicate parser. Variants follow §4c permissive-union semantics.
80
+ */
81
+ declare const policyVariantSchema: z.ZodObject<{
82
+ when: z.ZodString;
83
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
84
+ policy: z.ZodOptional<z.ZodString>;
85
+ }, z.core.$strip>;
86
+ declare const policyExpressionSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
87
+ default: z.ZodString;
88
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
89
+ when: z.ZodString;
90
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
91
+ policy: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strip>>>;
93
+ }, z.core.$strip>]>;
94
+ type PolicyExpression = z.infer<typeof policyExpressionSchema>;
95
+ declare const canonicalPoliciesSchema: z.ZodObject<{
96
+ read: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
97
+ default: z.ZodString;
98
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
99
+ when: z.ZodString;
100
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
101
+ policy: z.ZodOptional<z.ZodString>;
102
+ }, z.core.$strip>>>;
103
+ }, z.core.$strip>]>>;
104
+ write: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
105
+ default: z.ZodString;
106
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
107
+ when: z.ZodString;
108
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
109
+ policy: z.ZodOptional<z.ZodString>;
110
+ }, z.core.$strip>>>;
111
+ }, z.core.$strip>]>>;
112
+ }, z.core.$strip>;
113
+ /** Actions carry over from v1 as compiled named-SQL ops (plan: resolved OQ-1). */
114
+ declare const canonicalActionSchema: z.ZodObject<{
115
+ name: z.ZodString;
116
+ requires: z.ZodOptional<z.ZodString>;
117
+ params: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
118
+ type: z.ZodEnum<{
119
+ bigint: "bigint";
120
+ boolean: "boolean";
121
+ uuid: "uuid";
122
+ text: "text";
123
+ integer: "integer";
124
+ numeric: "numeric";
125
+ double: "double";
126
+ timestamptz: "timestamptz";
127
+ date: "date";
128
+ jsonb: "jsonb";
129
+ }>;
130
+ nullable: z.ZodDefault<z.ZodBoolean>;
131
+ }, z.core.$strip>>>;
132
+ executes: z.ZodString;
133
+ returns: z.ZodDefault<z.ZodEnum<{
134
+ rows: "rows";
135
+ rowsAffected: "rowsAffected";
136
+ scalar: "scalar";
137
+ }>>;
138
+ audit: z.ZodOptional<z.ZodObject<{
139
+ action: z.ZodString;
140
+ resource: z.ZodString;
141
+ }, z.core.$strip>>;
142
+ }, z.core.$strip>;
143
+ declare const canonicalTableSchema: z.ZodObject<{
144
+ table: z.ZodString;
145
+ description: z.ZodOptional<z.ZodString>;
146
+ renamedFrom: z.ZodOptional<z.ZodString>;
147
+ source: z.ZodOptional<z.ZodString>;
148
+ columns: z.ZodDefault<z.ZodArray<z.ZodObject<{
149
+ name: z.ZodString;
150
+ columnName: z.ZodString;
151
+ type: z.ZodUnion<readonly [z.ZodEnum<{
152
+ bigint: "bigint";
153
+ boolean: "boolean";
154
+ uuid: "uuid";
155
+ text: "text";
156
+ integer: "integer";
157
+ numeric: "numeric";
158
+ double: "double";
159
+ timestamptz: "timestamptz";
160
+ date: "date";
161
+ jsonb: "jsonb";
162
+ }>, z.ZodObject<{
163
+ enum: z.ZodString;
164
+ }, z.core.$strip>]>;
165
+ nullable: z.ZodDefault<z.ZodBoolean>;
166
+ unique: z.ZodDefault<z.ZodBoolean>;
167
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
168
+ defaultFn: z.ZodOptional<z.ZodEnum<{
169
+ "gen_random_uuid()": "gen_random_uuid()";
170
+ "now()": "now()";
171
+ }>>;
172
+ description: z.ZodOptional<z.ZodString>;
173
+ renamedFrom: z.ZodOptional<z.ZodString>;
174
+ cast: z.ZodOptional<z.ZodString>;
175
+ deprecated: z.ZodDefault<z.ZodBoolean>;
176
+ }, z.core.$strip>>>;
177
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
178
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
179
+ name: z.ZodString;
180
+ kind: z.ZodEnum<{
181
+ toOne: "toOne";
182
+ toMany: "toMany";
183
+ toPlatformUser: "toPlatformUser";
184
+ }>;
185
+ target: z.ZodOptional<z.ZodString>;
186
+ on: z.ZodString;
187
+ references: z.ZodOptional<z.ZodString>;
188
+ enforce: z.ZodDefault<z.ZodBoolean>;
189
+ description: z.ZodOptional<z.ZodString>;
190
+ }, z.core.$strip>>>;
191
+ indexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
192
+ columns: z.ZodArray<z.ZodString>;
193
+ unique: z.ZodDefault<z.ZodBoolean>;
194
+ name: z.ZodOptional<z.ZodString>;
195
+ }, z.core.$strip>>>;
196
+ policies: z.ZodDefault<z.ZodObject<{
197
+ read: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
198
+ default: z.ZodString;
199
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
200
+ when: z.ZodString;
201
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
202
+ policy: z.ZodOptional<z.ZodString>;
203
+ }, z.core.$strip>>>;
204
+ }, z.core.$strip>]>>;
205
+ write: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
206
+ default: z.ZodString;
207
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
208
+ when: z.ZodString;
209
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
210
+ policy: z.ZodOptional<z.ZodString>;
211
+ }, z.core.$strip>>>;
212
+ }, z.core.$strip>]>>;
213
+ }, z.core.$strip>>;
214
+ actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
215
+ name: z.ZodString;
216
+ requires: z.ZodOptional<z.ZodString>;
217
+ params: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
218
+ type: z.ZodEnum<{
219
+ bigint: "bigint";
220
+ boolean: "boolean";
221
+ uuid: "uuid";
222
+ text: "text";
223
+ integer: "integer";
224
+ numeric: "numeric";
225
+ double: "double";
226
+ timestamptz: "timestamptz";
227
+ date: "date";
228
+ jsonb: "jsonb";
229
+ }>;
230
+ nullable: z.ZodDefault<z.ZodBoolean>;
231
+ }, z.core.$strip>>>;
232
+ executes: z.ZodString;
233
+ returns: z.ZodDefault<z.ZodEnum<{
234
+ rows: "rows";
235
+ rowsAffected: "rowsAffected";
236
+ scalar: "scalar";
237
+ }>>;
238
+ audit: z.ZodOptional<z.ZodObject<{
239
+ action: z.ZodString;
240
+ resource: z.ZodString;
241
+ }, z.core.$strip>>;
242
+ }, z.core.$strip>>>;
243
+ }, z.core.$strip>;
244
+ type CanonicalTable = z.infer<typeof canonicalTableSchema>;
245
+ declare const canonicalDefinitionSchema: z.ZodObject<{
246
+ definition_format: z.ZodLiteral<2>;
247
+ namespace: z.ZodString;
248
+ description: z.ZodOptional<z.ZodString>;
249
+ enums: z.ZodDefault<z.ZodArray<z.ZodObject<{
250
+ name: z.ZodString;
251
+ values: z.ZodArray<z.ZodString>;
252
+ }, z.core.$strip>>>;
253
+ tables: z.ZodArray<z.ZodObject<{
254
+ table: z.ZodString;
255
+ description: z.ZodOptional<z.ZodString>;
256
+ renamedFrom: z.ZodOptional<z.ZodString>;
257
+ source: z.ZodOptional<z.ZodString>;
258
+ columns: z.ZodDefault<z.ZodArray<z.ZodObject<{
259
+ name: z.ZodString;
260
+ columnName: z.ZodString;
261
+ type: z.ZodUnion<readonly [z.ZodEnum<{
262
+ bigint: "bigint";
263
+ boolean: "boolean";
264
+ uuid: "uuid";
265
+ text: "text";
266
+ integer: "integer";
267
+ numeric: "numeric";
268
+ double: "double";
269
+ timestamptz: "timestamptz";
270
+ date: "date";
271
+ jsonb: "jsonb";
272
+ }>, z.ZodObject<{
273
+ enum: z.ZodString;
274
+ }, z.core.$strip>]>;
275
+ nullable: z.ZodDefault<z.ZodBoolean>;
276
+ unique: z.ZodDefault<z.ZodBoolean>;
277
+ default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
278
+ defaultFn: z.ZodOptional<z.ZodEnum<{
279
+ "gen_random_uuid()": "gen_random_uuid()";
280
+ "now()": "now()";
281
+ }>>;
282
+ description: z.ZodOptional<z.ZodString>;
283
+ renamedFrom: z.ZodOptional<z.ZodString>;
284
+ cast: z.ZodOptional<z.ZodString>;
285
+ deprecated: z.ZodDefault<z.ZodBoolean>;
286
+ }, z.core.$strip>>>;
287
+ primaryKey: z.ZodOptional<z.ZodArray<z.ZodString>>;
288
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
289
+ name: z.ZodString;
290
+ kind: z.ZodEnum<{
291
+ toOne: "toOne";
292
+ toMany: "toMany";
293
+ toPlatformUser: "toPlatformUser";
294
+ }>;
295
+ target: z.ZodOptional<z.ZodString>;
296
+ on: z.ZodString;
297
+ references: z.ZodOptional<z.ZodString>;
298
+ enforce: z.ZodDefault<z.ZodBoolean>;
299
+ description: z.ZodOptional<z.ZodString>;
300
+ }, z.core.$strip>>>;
301
+ indexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
302
+ columns: z.ZodArray<z.ZodString>;
303
+ unique: z.ZodDefault<z.ZodBoolean>;
304
+ name: z.ZodOptional<z.ZodString>;
305
+ }, z.core.$strip>>>;
306
+ policies: z.ZodDefault<z.ZodObject<{
307
+ read: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
308
+ default: z.ZodString;
309
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
310
+ when: z.ZodString;
311
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
312
+ policy: z.ZodOptional<z.ZodString>;
313
+ }, z.core.$strip>>>;
314
+ }, z.core.$strip>]>>;
315
+ write: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
316
+ default: z.ZodString;
317
+ variants: z.ZodDefault<z.ZodArray<z.ZodObject<{
318
+ when: z.ZodString;
319
+ allow: z.ZodOptional<z.ZodLiteral<true>>;
320
+ policy: z.ZodOptional<z.ZodString>;
321
+ }, z.core.$strip>>>;
322
+ }, z.core.$strip>]>>;
323
+ }, z.core.$strip>>;
324
+ actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
325
+ name: z.ZodString;
326
+ requires: z.ZodOptional<z.ZodString>;
327
+ params: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
328
+ type: z.ZodEnum<{
329
+ bigint: "bigint";
330
+ boolean: "boolean";
331
+ uuid: "uuid";
332
+ text: "text";
333
+ integer: "integer";
334
+ numeric: "numeric";
335
+ double: "double";
336
+ timestamptz: "timestamptz";
337
+ date: "date";
338
+ jsonb: "jsonb";
339
+ }>;
340
+ nullable: z.ZodDefault<z.ZodBoolean>;
341
+ }, z.core.$strip>>>;
342
+ executes: z.ZodString;
343
+ returns: z.ZodDefault<z.ZodEnum<{
344
+ rows: "rows";
345
+ rowsAffected: "rowsAffected";
346
+ scalar: "scalar";
347
+ }>>;
348
+ audit: z.ZodOptional<z.ZodObject<{
349
+ action: z.ZodString;
350
+ resource: z.ZodString;
351
+ }, z.core.$strip>>;
352
+ }, z.core.$strip>>>;
353
+ }, z.core.$strip>>;
354
+ capabilities: z.ZodDefault<z.ZodObject<{
355
+ roles: z.ZodOptional<z.ZodUnknown>;
356
+ uses: z.ZodDefault<z.ZodArray<z.ZodString>>;
357
+ }, z.core.$strip>>;
358
+ }, z.core.$strip>;
359
+ type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>;
360
+ /**
361
+ * Deterministic serialization discipline: tables sorted by name, columns in
362
+ * declaration order (order is meaningful for DDL), links/indexes/actions
363
+ * sorted by name, object keys emitted in schema order. `serializeNamespace`
364
+ * (authoring layer) and the server-side re-validation both normalize through
365
+ * this function before hashing so CLI and server hash identical bytes.
366
+ */
367
+ declare function normalizeCanonical(definition: CanonicalDefinition): CanonicalDefinition;
368
+
369
+ export { CANONICAL_FORMAT, COLUMN_TYPES, type CanonicalColumn, type CanonicalDefinition, type CanonicalEnum, type CanonicalLink, type CanonicalTable, type ColumnType, IDENTIFIER_RE, type PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalTableSchema, normalizeCanonical, policyExpressionSchema, policyVariantSchema };