@zmdb/compiler 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +40 -0
  3. package/dist/codegen/index.d.ts +50 -0
  4. package/dist/codegen/index.d.ts.map +1 -0
  5. package/dist/codegen/index.js +364 -0
  6. package/dist/codegen/index.js.map +1 -0
  7. package/dist/codegen/scan.d.ts +105 -0
  8. package/dist/codegen/scan.d.ts.map +1 -0
  9. package/dist/codegen/scan.js +450 -0
  10. package/dist/codegen/scan.js.map +1 -0
  11. package/dist/codegen/witness.d.ts +76 -0
  12. package/dist/codegen/witness.d.ts.map +1 -0
  13. package/dist/codegen/witness.js +690 -0
  14. package/dist/codegen/witness.js.map +1 -0
  15. package/dist/config/contract.d.ts +41 -0
  16. package/dist/config/contract.d.ts.map +1 -0
  17. package/dist/config/contract.js +5 -0
  18. package/dist/config/contract.js.map +1 -0
  19. package/dist/config/index.d.ts +53 -0
  20. package/dist/config/index.d.ts.map +1 -0
  21. package/dist/config/index.js +277 -0
  22. package/dist/config/index.js.map +1 -0
  23. package/dist/config/index.zmdb.generated.d.ts +12 -0
  24. package/dist/config/index.zmdb.generated.js +28 -0
  25. package/dist/config/index.zmdb.witness.d.ts +3 -0
  26. package/dist/config/index.zmdb.witness.d.ts.map +1 -0
  27. package/dist/config/index.zmdb.witness.js +20 -0
  28. package/dist/config/index.zmdb.witness.js.map +1 -0
  29. package/dist/configured-plugin.d.ts +11 -0
  30. package/dist/configured-plugin.d.ts.map +1 -0
  31. package/dist/configured-plugin.js +27 -0
  32. package/dist/configured-plugin.js.map +1 -0
  33. package/dist/emit/index.d.ts +103 -0
  34. package/dist/emit/index.d.ts.map +1 -0
  35. package/dist/emit/index.js +1356 -0
  36. package/dist/emit/index.js.map +1 -0
  37. package/dist/errors.d.ts +7 -0
  38. package/dist/errors.d.ts.map +1 -0
  39. package/dist/errors.js +2 -0
  40. package/dist/errors.js.map +1 -0
  41. package/dist/index.d.ts +46 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +254 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/lint/ast.d.ts +17 -0
  46. package/dist/lint/ast.d.ts.map +1 -0
  47. package/dist/lint/ast.js +77 -0
  48. package/dist/lint/ast.js.map +1 -0
  49. package/dist/lint/host-types.d.ts +9 -0
  50. package/dist/lint/host-types.d.ts.map +1 -0
  51. package/dist/lint/host-types.js +2 -0
  52. package/dist/lint/host-types.js.map +1 -0
  53. package/dist/lint/index.d.ts +23 -0
  54. package/dist/lint/index.d.ts.map +1 -0
  55. package/dist/lint/index.js +53 -0
  56. package/dist/lint/index.js.map +1 -0
  57. package/dist/lint/rules/no-distributed-nullable-tags.d.ts +3 -0
  58. package/dist/lint/rules/no-distributed-nullable-tags.d.ts.map +1 -0
  59. package/dist/lint/rules/no-distributed-nullable-tags.js +71 -0
  60. package/dist/lint/rules/no-distributed-nullable-tags.js.map +1 -0
  61. package/dist/lint/rules/no-empty-patch.d.ts +3 -0
  62. package/dist/lint/rules/no-empty-patch.d.ts.map +1 -0
  63. package/dist/lint/rules/no-empty-patch.js +26 -0
  64. package/dist/lint/rules/no-empty-patch.js.map +1 -0
  65. package/dist/lint/rules/no-interpolated-sql.d.ts +3 -0
  66. package/dist/lint/rules/no-interpolated-sql.d.ts.map +1 -0
  67. package/dist/lint/rules/no-interpolated-sql.js +35 -0
  68. package/dist/lint/rules/no-interpolated-sql.js.map +1 -0
  69. package/dist/lint/rules/no-unbounded-find.d.ts +3 -0
  70. package/dist/lint/rules/no-unbounded-find.d.ts.map +1 -0
  71. package/dist/lint/rules/no-unbounded-find.js +26 -0
  72. package/dist/lint/rules/no-unbounded-find.js.map +1 -0
  73. package/dist/lint/rules/no-unknown-json-column.d.ts +3 -0
  74. package/dist/lint/rules/no-unknown-json-column.d.ts.map +1 -0
  75. package/dist/lint/rules/no-unknown-json-column.js +35 -0
  76. package/dist/lint/rules/no-unknown-json-column.js.map +1 -0
  77. package/dist/lint/rules/require-sql-on-number.d.ts +3 -0
  78. package/dist/lint/rules/require-sql-on-number.d.ts.map +1 -0
  79. package/dist/lint/rules/require-sql-on-number.js +34 -0
  80. package/dist/lint/rules/require-sql-on-number.js.map +1 -0
  81. package/dist/lint/types.d.ts +12 -0
  82. package/dist/lint/types.d.ts.map +1 -0
  83. package/dist/lint/types.js +2 -0
  84. package/dist/lint/types.js.map +1 -0
  85. package/dist/metro/metro.d.ts +22 -0
  86. package/dist/metro/metro.d.ts.map +1 -0
  87. package/dist/metro/metro.js +242 -0
  88. package/dist/metro/metro.js.map +1 -0
  89. package/dist/protobuf/decode.d.ts +20 -0
  90. package/dist/protobuf/decode.d.ts.map +1 -0
  91. package/dist/protobuf/decode.js +289 -0
  92. package/dist/protobuf/decode.js.map +1 -0
  93. package/dist/protobuf/descriptor.d.ts +16 -0
  94. package/dist/protobuf/descriptor.d.ts.map +1 -0
  95. package/dist/protobuf/descriptor.js +303 -0
  96. package/dist/protobuf/descriptor.js.map +1 -0
  97. package/dist/protobuf/encode.d.ts +20 -0
  98. package/dist/protobuf/encode.d.ts.map +1 -0
  99. package/dist/protobuf/encode.js +203 -0
  100. package/dist/protobuf/encode.js.map +1 -0
  101. package/dist/protobuf/grpc-ir.d.ts +16 -0
  102. package/dist/protobuf/grpc-ir.d.ts.map +1 -0
  103. package/dist/protobuf/grpc-ir.js +2 -0
  104. package/dist/protobuf/grpc-ir.js.map +1 -0
  105. package/dist/protobuf/plan.d.ts +42 -0
  106. package/dist/protobuf/plan.d.ts.map +1 -0
  107. package/dist/protobuf/plan.js +158 -0
  108. package/dist/protobuf/plan.js.map +1 -0
  109. package/dist/reflect/callsites.d.ts +40 -0
  110. package/dist/reflect/callsites.d.ts.map +1 -0
  111. package/dist/reflect/callsites.js +153 -0
  112. package/dist/reflect/callsites.js.map +1 -0
  113. package/dist/reflect/index.d.ts +106 -0
  114. package/dist/reflect/index.d.ts.map +1 -0
  115. package/dist/reflect/index.js +1421 -0
  116. package/dist/reflect/index.js.map +1 -0
  117. package/dist/reflect/session.d.ts +118 -0
  118. package/dist/reflect/session.d.ts.map +1 -0
  119. package/dist/reflect/session.js +228 -0
  120. package/dist/reflect/session.js.map +1 -0
  121. package/dist/testing/index.d.ts +69 -0
  122. package/dist/testing/index.d.ts.map +1 -0
  123. package/dist/testing/index.js +210 -0
  124. package/dist/testing/index.js.map +1 -0
  125. package/dist/transform/index.d.ts +74 -0
  126. package/dist/transform/index.d.ts.map +1 -0
  127. package/dist/transform/index.js +572 -0
  128. package/dist/transform/index.js.map +1 -0
  129. package/dist/unplugin/index.d.ts +53 -0
  130. package/dist/unplugin/index.d.ts.map +1 -0
  131. package/dist/unplugin/index.js +130 -0
  132. package/dist/unplugin/index.js.map +1 -0
  133. package/dist/unplugin/inline-bench.d.ts +29 -0
  134. package/dist/unplugin/inline-bench.d.ts.map +1 -0
  135. package/dist/unplugin/inline-bench.js +82 -0
  136. package/dist/unplugin/inline-bench.js.map +1 -0
  137. package/package.json +110 -0
  138. package/src/codegen/index.ts +451 -0
  139. package/src/codegen/scan.ts +574 -0
  140. package/src/codegen/witness.ts +819 -0
  141. package/src/config/contract.ts +48 -0
  142. package/src/config/index.ts +384 -0
  143. package/src/config/index.zmdb.generated.d.ts +12 -0
  144. package/src/config/index.zmdb.generated.js +28 -0
  145. package/src/config/index.zmdb.witness.ts +22 -0
  146. package/src/configured-plugin.ts +35 -0
  147. package/src/emit/index.ts +1496 -0
  148. package/src/errors.ts +6 -0
  149. package/src/index.ts +336 -0
  150. package/src/lint/ast.ts +96 -0
  151. package/src/lint/host-types.ts +9 -0
  152. package/src/lint/index.ts +80 -0
  153. package/src/lint/rules/no-distributed-nullable-tags.ts +76 -0
  154. package/src/lint/rules/no-empty-patch.ts +26 -0
  155. package/src/lint/rules/no-interpolated-sql.ts +45 -0
  156. package/src/lint/rules/no-unbounded-find.ts +26 -0
  157. package/src/lint/rules/no-unknown-json-column.ts +36 -0
  158. package/src/lint/rules/require-sql-on-number.ts +34 -0
  159. package/src/lint/types.ts +11 -0
  160. package/src/metro/metro.ts +313 -0
  161. package/src/protobuf/decode.ts +375 -0
  162. package/src/protobuf/descriptor.ts +353 -0
  163. package/src/protobuf/encode.ts +277 -0
  164. package/src/protobuf/grpc-ir.ts +17 -0
  165. package/src/protobuf/plan.ts +244 -0
  166. package/src/reflect/callsites.ts +198 -0
  167. package/src/reflect/index.ts +1723 -0
  168. package/src/reflect/session.ts +276 -0
  169. package/src/testing/index.ts +298 -0
  170. package/src/transform/index.ts +690 -0
  171. package/src/unplugin/index.ts +182 -0
  172. package/src/unplugin/inline-bench.ts +92 -0
@@ -0,0 +1,103 @@
1
+ import type { ToolProvider } from '@zmdb/ai';
2
+ import { type SchemaIR, type ShapeIR, type TypeIR } from '@zmdb/schema/ir';
3
+ import type { GrpcServiceIR } from '../protobuf/grpc-ir.js';
4
+ /** Sanitise a pattern before it goes between `/` delimiters in emitted source. */
5
+ export declare function escapePattern(pattern: string): string;
6
+ export type EmitTarget = 'check' | 'excess' | 'issues' | 'sample';
7
+ export interface EmitOptions {
8
+ /** Prefix for every emitted identifier. Default `_zmdb`. */
9
+ readonly prefix?: string;
10
+ /** Cap on hoisted helpers per file. Exceeding it is a refusal, not a hang. */
11
+ readonly maxHelpers?: number;
12
+ /** Module specifier the emitted prelude imports `AssertError` from. */
13
+ readonly errorModule?: string;
14
+ /** Module specifier the emitted prelude imports `ProtoReader`/`ProtoWriter` from. */
15
+ readonly protobufModule?: string;
16
+ }
17
+ /** A refusal. `path` is the property chain that reached it, as in the reflection. */
18
+ export interface EmitDiagnostic {
19
+ readonly path: string;
20
+ readonly reason: string;
21
+ readonly source?: string;
22
+ }
23
+ export declare class Emitter {
24
+ #private;
25
+ constructor(options?: EmitOptions);
26
+ get diagnostics(): readonly EmitDiagnostic[];
27
+ /** Record a build-time refusal discovered at the call-site boundary. */
28
+ refuse(path: string, reason: string): undefined;
29
+ /** True once anything has been hoisted, so a caller knows a prelude is needed. */
30
+ get hasPrelude(): boolean;
31
+ /**
32
+ * Everything that has to sit at the top of the module: the `AssertError` import when a
33
+ * throwing form was emitted, then the helpers in definition order.
34
+ */
35
+ prelude(): string;
36
+ /** `is<T>(expr)` → a boolean expression. */
37
+ emitIs(node: TypeIR, expr: string, maxDepth?: number): string | undefined;
38
+ /** `equals<T>(expr)` → `is<T>` plus a recursive no-excess-keys check. */
39
+ emitEquals(node: TypeIR, expr: string): string | undefined;
40
+ /** `assert<T>(expr)` / `assertEquals<T>(expr)` → the value, or a throw. */
41
+ emitAssert(node: TypeIR, expr: string, strict: boolean, maxDepth?: number): string | undefined;
42
+ /** `validate<T>(expr)` → a `ValidateResult<T>`, never a throw. */
43
+ emitValidate(node: TypeIR, expr: string, strict?: boolean, maxDepth?: number): string | undefined;
44
+ /** `random<T>()` → an expression producing a value that satisfies `T`. */
45
+ emitRandom(node: TypeIR): string | undefined;
46
+ /**
47
+ * `toJsonSchema<T>()` → a reference to the document, hoisted and frozen (REQ-TF-7).
48
+ *
49
+ * One of the two targets that is not a walk. The other four emit code that runs later;
50
+ * a JSON Schema document is *finished* at build time, so what gets emitted is the
51
+ * answer itself. `jsonSchemaFromShape` is the same function the value path calls, which
52
+ * is what makes the two documents identical rather than merely tested for equality.
53
+ */
54
+ emitJsonSchema(shape: ShapeIR): string | undefined;
55
+ /**
56
+ * `schemaOf<T>()` → a reference to the generated schema value, hoisted and frozen
57
+ * (REQ-TF-10).
58
+ *
59
+ * The other half of "one IR, several back-ends": the query compiler and the DDL emitter
60
+ * want the table and the column types as data, so what gets emitted is the projection
61
+ * `schemaFromIR` builds — and that includes the IR itself, on the value's `ir` field.
62
+ * Both are in the literal on purpose. The projection is what the query compiler reads on
63
+ * every call and wants flat; the IR is what the decoders, the wire codecs and the OpenAPI
64
+ * document read, and it says things no column map can hold. Emitting only the projection
65
+ * would mean recovering the rest by inference at runtime, which is the walk this design
66
+ * removed.
67
+ *
68
+ * Relations do not travel with the projection. A `CoreSchema` has no relation map — the
69
+ * repository takes one separately — so a `ManyToOne<…>` on the declaration is read, is
70
+ * not a column, and reaches a consumer only through `ir.relations`.
71
+ */
72
+ emitSchemaValue(ir: SchemaIR): string | undefined;
73
+ /**
74
+ * `toolFor<T>(provider, name, opts)` → the provider's frozen parameter document.
75
+ *
76
+ * The transformer supplies the framing expressions because `name` and `description`
77
+ * belong to the call site. The schema itself is complete here: a pure projection of the
78
+ * reflected table IR, shared with the runtime schema-value overload.
79
+ */
80
+ emitToolSchema(ir: SchemaIR, provider: ToolProvider): string | undefined;
81
+ /** `protoDescriptor<T>()` -> one compile-time-produced proto3 string literal. */
82
+ emitProtoDescriptor(node: TypeIR, name: string): string | undefined;
83
+ /** `grpcDescriptor<S>(service, package)` -> one complete proto3 file. */
84
+ emitGrpcDescriptor(node: GrpcServiceIR, service: string, pkg: string): string | undefined;
85
+ /**
86
+ * `loadGrpcService<S>(service, package)` -> a frozen descriptor plus generated
87
+ * request/response validators and codecs for every method.
88
+ */
89
+ emitGrpcService(node: GrpcServiceIR, service: string, pkg: string): string | undefined;
90
+ /** `protoEncode<T>(expr)` -> a call to a compile-time-produced straight-line encoder. */
91
+ emitProtoEncode(node: TypeIR, name: string, expr: string): string | undefined;
92
+ /** `protoDecode<T>(expr)` -> a field-number-dispatched decoder over a bounded reader. */
93
+ emitProtoDecode(node: TypeIR, name: string, expr: string): string | undefined;
94
+ /**
95
+ * The name of a hoisted function implementing `target` for `node`, for callers that
96
+ * want the function rather than an inlined call site — the differential suite and the
97
+ * emitted-output snapshots both do.
98
+ */
99
+ helper(node: TypeIR, target: EmitTarget): string | undefined;
100
+ }
101
+ export { discriminantOf, expectedForConstraint, expectedForDiscriminant, expectedOf, hasExcessCheck, messageFor, } from '@zmdb/schema/ir';
102
+ export { type ConstraintKeyword, type Discriminant, type DiscriminantArm } from '@zmdb/schema/ir';
103
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","s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