@lucern/contracts 1.0.0 → 1.0.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 (213) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/dist/dsl.d.ts +75 -4
  3. package/dist/dsl.values-rhsroqi0.d.ts +21 -0
  4. package/dist/dsl.values.d.ts +5 -0
  5. package/dist/dsl.values.js +675 -0
  6. package/dist/dsl.values.js.map +1 -0
  7. package/dist/function-registry/beliefs.d.ts +1 -17
  8. package/dist/function-registry/beliefs.js +155 -117
  9. package/dist/function-registry/beliefs.js.map +1 -1
  10. package/dist/function-registry/coding.d.ts +1 -17
  11. package/dist/function-registry/coding.js +155 -117
  12. package/dist/function-registry/coding.js.map +1 -1
  13. package/dist/function-registry/context.d.ts +1 -17
  14. package/dist/function-registry/context.js +155 -117
  15. package/dist/function-registry/context.js.map +1 -1
  16. package/dist/function-registry/contracts.d.ts +1 -17
  17. package/dist/function-registry/contracts.js +155 -117
  18. package/dist/function-registry/contracts.js.map +1 -1
  19. package/dist/function-registry/coordination.d.ts +1 -17
  20. package/dist/function-registry/coordination.js +155 -117
  21. package/dist/function-registry/coordination.js.map +1 -1
  22. package/dist/function-registry/edges.d.ts +1 -17
  23. package/dist/function-registry/edges.js +155 -117
  24. package/dist/function-registry/edges.js.map +1 -1
  25. package/dist/function-registry/evidence.d.ts +1 -17
  26. package/dist/function-registry/evidence.js +155 -117
  27. package/dist/function-registry/evidence.js.map +1 -1
  28. package/dist/function-registry/graph.d.ts +1 -17
  29. package/dist/function-registry/graph.js +155 -117
  30. package/dist/function-registry/graph.js.map +1 -1
  31. package/dist/function-registry/helpers.d.ts +1 -1
  32. package/dist/function-registry/helpers.js +155 -117
  33. package/dist/function-registry/helpers.js.map +1 -1
  34. package/dist/function-registry/identity.d.ts +1 -17
  35. package/dist/function-registry/identity.js +155 -117
  36. package/dist/function-registry/identity.js.map +1 -1
  37. package/dist/function-registry/index.d.ts +1 -1
  38. package/dist/function-registry/index.js +158 -118
  39. package/dist/function-registry/index.js.map +1 -1
  40. package/dist/function-registry/judgments.d.ts +1 -17
  41. package/dist/function-registry/judgments.js +155 -117
  42. package/dist/function-registry/judgments.js.map +1 -1
  43. package/dist/function-registry/legacy.d.ts +1 -17
  44. package/dist/function-registry/legacy.js +155 -117
  45. package/dist/function-registry/legacy.js.map +1 -1
  46. package/dist/function-registry/lenses.d.ts +1 -17
  47. package/dist/function-registry/lenses.js +155 -117
  48. package/dist/function-registry/lenses.js.map +1 -1
  49. package/dist/function-registry/manifest.d.ts +3 -3
  50. package/dist/function-registry/manifest.js +1 -0
  51. package/dist/function-registry/manifest.js.map +1 -1
  52. package/dist/function-registry/nodes.d.ts +1 -17
  53. package/dist/function-registry/nodes.js +155 -117
  54. package/dist/function-registry/nodes.js.map +1 -1
  55. package/dist/function-registry/ontologies.d.ts +1 -17
  56. package/dist/function-registry/ontologies.js +155 -117
  57. package/dist/function-registry/ontologies.js.map +1 -1
  58. package/dist/function-registry/pipeline.d.ts +1 -17
  59. package/dist/function-registry/pipeline.js +155 -117
  60. package/dist/function-registry/pipeline.js.map +1 -1
  61. package/dist/function-registry/questions.d.ts +1 -17
  62. package/dist/function-registry/questions.js +155 -117
  63. package/dist/function-registry/questions.js.map +1 -1
  64. package/dist/function-registry/tasks.d.ts +1 -17
  65. package/dist/function-registry/tasks.js +155 -117
  66. package/dist/function-registry/tasks.js.map +1 -1
  67. package/dist/function-registry/topics.d.ts +1 -17
  68. package/dist/function-registry/topics.js +155 -117
  69. package/dist/function-registry/topics.js.map +1 -1
  70. package/dist/function-registry/types.d.ts +2 -2
  71. package/dist/function-registry/worktrees.d.ts +41 -17
  72. package/dist/function-registry/worktrees.js +174 -117
  73. package/dist/function-registry/worktrees.js.map +1 -1
  74. package/dist/generated/lucernWebPublicEnv.js.map +1 -1
  75. package/dist/generated/lucernWebServerEnv.js.map +1 -1
  76. package/dist/{idOf-DR8tkhQS.d.ts → idOf-BmkVDhD8.d.ts} +1 -1
  77. package/dist/index.d.ts +47 -8
  78. package/dist/index.js +45072 -45005
  79. package/dist/index.js.map +1 -1
  80. package/dist/infisical-runtime.base.d.ts +444 -0
  81. package/dist/infisical-runtime.base.js +640 -0
  82. package/dist/infisical-runtime.base.js.map +1 -0
  83. package/dist/infisical-runtime.contract.d.ts +9 -440
  84. package/dist/infisical-runtime.contract.js +14 -1
  85. package/dist/infisical-runtime.contract.js.map +1 -1
  86. package/dist/infisical-runtime.platform-ops-secrets.d.ts +743 -0
  87. package/dist/infisical-runtime.platform-ops-secrets.js +962 -0
  88. package/dist/infisical-runtime.platform-ops-secrets.js.map +1 -0
  89. package/dist/infisical-runtime.platform-secrets.d.ts +598 -0
  90. package/dist/infisical-runtime.platform-secrets.js +726 -0
  91. package/dist/infisical-runtime.platform-secrets.js.map +1 -0
  92. package/dist/infisical-runtime.tenant-secrets.d.ts +486 -0
  93. package/dist/infisical-runtime.tenant-secrets.js +1131 -0
  94. package/dist/infisical-runtime.tenant-secrets.js.map +1 -0
  95. package/dist/manifests/edge-policy-manifest.d.ts +1 -1
  96. package/dist/manifests/infisical-runtime-manifest.d.ts +1 -1
  97. package/dist/manifests/infisical-runtime-manifest.js +14 -1
  98. package/dist/manifests/infisical-runtime-manifest.js.map +1 -1
  99. package/dist/manifests/tenant-client-manifest.d.ts +5 -1
  100. package/dist/manifests/tenant-client-manifest.js +5 -0
  101. package/dist/manifests/tenant-client-manifest.js.map +1 -1
  102. package/dist/proof-attestation.json +1 -1
  103. package/dist/schemas/index.d.ts +1 -1
  104. package/dist/schemas/index.js.map +1 -1
  105. package/dist/schemas/manifest.d.ts +61 -61
  106. package/dist/schemas/manifest.js.map +1 -1
  107. package/dist/schemas/tables/kernel/config.js.map +1 -1
  108. package/dist/schemas/tables/kernel/coordination.js.map +1 -1
  109. package/dist/schemas/tables/kernel/decision.d.ts +1 -1
  110. package/dist/schemas/tables/kernel/decision.js.map +1 -1
  111. package/dist/schemas/tables/kernel/embedding.d.ts +1 -1
  112. package/dist/schemas/tables/kernel/embedding.js.map +1 -1
  113. package/dist/schemas/tables/kernel/epistemic.d.ts +1 -1
  114. package/dist/schemas/tables/kernel/epistemic.js.map +1 -1
  115. package/dist/schemas/tables/kernel/idempotency.js.map +1 -1
  116. package/dist/schemas/tables/kernel/infra.js.map +1 -1
  117. package/dist/schemas/tables/kernel/intelligence.d.ts +1 -1
  118. package/dist/schemas/tables/kernel/intelligence.js.map +1 -1
  119. package/dist/schemas/tables/kernel/lens.d.ts +5 -5
  120. package/dist/schemas/tables/kernel/lens.js.map +1 -1
  121. package/dist/schemas/tables/kernel/ontology.d.ts +1 -1
  122. package/dist/schemas/tables/kernel/ontology.js.map +1 -1
  123. package/dist/schemas/tables/kernel/platform.js.map +1 -1
  124. package/dist/schemas/tables/kernel/spine.d.ts +1 -1
  125. package/dist/schemas/tables/kernel/spine.js.map +1 -1
  126. package/dist/schemas/tables/kernel/task.d.ts +1 -1
  127. package/dist/schemas/tables/kernel/task.js.map +1 -1
  128. package/dist/schemas/tables/kernel/topic.d.ts +1 -1
  129. package/dist/schemas/tables/kernel/topic.js.map +1 -1
  130. package/dist/schemas/tables/kernel/workflow.d.ts +1 -1
  131. package/dist/schemas/tables/kernel/workflow.js.map +1 -1
  132. package/dist/schemas/tables/kernel/worktree.d.ts +1 -1
  133. package/dist/schemas/tables/kernel/worktree.js.map +1 -1
  134. package/dist/schemas/tables/mc/identity.d.ts +1 -1
  135. package/dist/schemas/tables/mc/methodology.d.ts +1 -1
  136. package/dist/schemas/tables/mc/pack.d.ts +9 -9
  137. package/dist/schemas/tables/mc/policy.d.ts +1 -1
  138. package/dist/schemas/tables/mc/registry.d.ts +1 -1
  139. package/dist/schemas/tables/mc/runtime.d.ts +1 -1
  140. package/dist/schemas/tables/mc/tenant.d.ts +1 -1
  141. package/dist/schemas/tables/mc/workspace.d.ts +1 -1
  142. package/dist/schemas.values-5J5oIK7z.d.ts +26 -0
  143. package/dist/schemas.values.d.ts +7 -0
  144. package/dist/schemas.values.js +5324 -0
  145. package/dist/schemas.values.js.map +1 -0
  146. package/dist/sdk-tools.contract.analytics.d.ts +27 -0
  147. package/dist/sdk-tools.contract.analytics.js +616 -0
  148. package/dist/sdk-tools.contract.analytics.js.map +1 -0
  149. package/dist/sdk-tools.contract.d.ts +43 -2
  150. package/dist/sdk-tools.contract.graph.d.ts +11 -0
  151. package/dist/sdk-tools.contract.graph.js +156 -0
  152. package/dist/sdk-tools.contract.graph.js.map +1 -0
  153. package/dist/sdk-tools.contract.js +4107 -4062
  154. package/dist/sdk-tools.contract.js.map +1 -1
  155. package/dist/sdk-tools.contract.registry.d.ts +25 -0
  156. package/dist/sdk-tools.contract.registry.js +5504 -0
  157. package/dist/sdk-tools.contract.registry.js.map +1 -0
  158. package/dist/sdk-tools.contract.types.d.ts +15 -0
  159. package/dist/sdk-tools.contract.types.js +3 -0
  160. package/dist/sdk-tools.contract.types.js.map +1 -0
  161. package/dist/sdk-tools.contract.values-LuBh95zg.d.ts +58 -0
  162. package/dist/sdk-tools.contract.values.d.ts +7 -0
  163. package/dist/sdk-tools.contract.values.js +5581 -0
  164. package/dist/sdk-tools.contract.values.js.map +1 -0
  165. package/dist/sdk-tools.contract.workflow.d.ts +17 -0
  166. package/dist/sdk-tools.contract.workflow.js +287 -0
  167. package/dist/sdk-tools.contract.workflow.js.map +1 -0
  168. package/dist/tenant-client.contract.d.ts +5 -1
  169. package/dist/tenant-client.contract.js +5 -0
  170. package/dist/tenant-client.contract.js.map +1 -1
  171. package/dist/tool-contracts.d.ts +34 -1
  172. package/dist/tool-contracts.graph.d.ts +18 -0
  173. package/dist/tool-contracts.graph.js +378 -0
  174. package/dist/tool-contracts.graph.js.map +1 -0
  175. package/dist/tool-contracts.intelligence-evidence.d.ts +15 -0
  176. package/dist/tool-contracts.intelligence-evidence.js +303 -0
  177. package/dist/tool-contracts.intelligence-evidence.js.map +1 -0
  178. package/dist/tool-contracts.js +155 -118
  179. package/dist/tool-contracts.js.map +1 -1
  180. package/dist/tool-contracts.lifecycle.d.ts +13 -0
  181. package/dist/tool-contracts.lifecycle.js +410 -0
  182. package/dist/tool-contracts.lifecycle.js.map +1 -0
  183. package/dist/tool-contracts.nodes-lenses.d.ts +17 -0
  184. package/dist/tool-contracts.nodes-lenses.js +334 -0
  185. package/dist/tool-contracts.nodes-lenses.js.map +1 -0
  186. package/dist/tool-contracts.ontology.d.ts +16 -0
  187. package/dist/tool-contracts.ontology.js +344 -0
  188. package/dist/tool-contracts.ontology.js.map +1 -0
  189. package/dist/tool-contracts.pipeline-coordination.d.ts +25 -0
  190. package/dist/tool-contracts.pipeline-coordination.js +684 -0
  191. package/dist/tool-contracts.pipeline-coordination.js.map +1 -0
  192. package/dist/tool-contracts.policy-observation-task-topic.d.ts +25 -0
  193. package/dist/tool-contracts.policy-observation-task-topic.js +740 -0
  194. package/dist/tool-contracts.policy-observation-task-topic.js.map +1 -0
  195. package/dist/tool-contracts.questions-listing.d.ts +27 -0
  196. package/dist/tool-contracts.questions-listing.js +782 -0
  197. package/dist/tool-contracts.questions-listing.js.map +1 -0
  198. package/dist/tool-contracts.types.d.ts +34 -0
  199. package/dist/tool-contracts.types.js +3 -0
  200. package/dist/tool-contracts.types.js.map +1 -0
  201. package/dist/tool-contracts.values-DjctSW7S.d.ts +147 -0
  202. package/dist/tool-contracts.values.d.ts +11 -0
  203. package/dist/tool-contracts.values.js +4398 -0
  204. package/dist/tool-contracts.values.js.map +1 -0
  205. package/dist/tool-contracts.worktrees.d.ts +8 -0
  206. package/dist/tool-contracts.worktrees.js +280 -0
  207. package/dist/tool-contracts.worktrees.js.map +1 -0
  208. package/package.json +3 -11
  209. package/dist/dsl-DVPthQGY.d.ts +0 -110
  210. package/dist/index-CM1Pl_vI.d.ts +0 -28
  211. package/dist/sdk-tools.contract-CKmSsrZ2.d.ts +0 -146
  212. package/dist/tool-contracts-C_xvM9q2.d.ts +0 -326
  213. package/dist/{edge-policy-manifest-Dw5IhT1L.d.ts → edge-policy-manifest-4KOSP4nk.d.ts} +2 -2
@@ -0,0 +1,675 @@
1
+ import { z, ZodFirstPartyTypeKind } from 'zod';
2
+
3
+ // src/dsl/defineFunction.ts
4
+ function defineFunction(spec) {
5
+ return spec;
6
+ }
7
+
8
+ // src/dsl/defineTable.ts
9
+ function defineTable(spec) {
10
+ return spec;
11
+ }
12
+
13
+ // src/dsl/errors.ts
14
+ function formatPath(path) {
15
+ if (!path || path.length === 0) {
16
+ return "";
17
+ }
18
+ return path.join(".");
19
+ }
20
+ function formatLocation(context) {
21
+ const segments = [context.adapter];
22
+ if (context.purpose) {
23
+ segments.push(context.purpose);
24
+ }
25
+ if (context.location) {
26
+ segments.push(context.location);
27
+ }
28
+ const formattedPath = formatPath(context.path);
29
+ if (formattedPath) {
30
+ segments.push(formattedPath);
31
+ }
32
+ return segments.join(" :: ");
33
+ }
34
+ var SchemaAdapterError = class extends Error {
35
+ context;
36
+ constructor(message, context) {
37
+ super(`${message} [${formatLocation(context)}]`);
38
+ this.name = "SchemaAdapterError";
39
+ this.context = context;
40
+ }
41
+ };
42
+ function schemaAdapterError(message, context) {
43
+ return new SchemaAdapterError(message, context);
44
+ }
45
+ var CONVEX_ID_TABLE = /* @__PURE__ */ Symbol.for("lucern.contracts.convexIdTable");
46
+ function idOf(table) {
47
+ const schema = z.string().brand();
48
+ Object.defineProperty(schema, CONVEX_ID_TABLE, {
49
+ configurable: false,
50
+ enumerable: false,
51
+ value: table,
52
+ writable: false
53
+ });
54
+ return schema;
55
+ }
56
+ function getConvexIdTable(schema) {
57
+ return schema[CONVEX_ID_TABLE];
58
+ }
59
+ function unsupported(message, state, path) {
60
+ throw schemaAdapterError(message, {
61
+ adapter: "cli",
62
+ location: state.location,
63
+ path
64
+ });
65
+ }
66
+ function getObjectShape(schema) {
67
+ const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
68
+ return shape;
69
+ }
70
+ function unwrapField(schema, path) {
71
+ let current = schema;
72
+ let required = true;
73
+ let nullable = false;
74
+ let defaultValue;
75
+ while (true) {
76
+ switch (current._def.typeName) {
77
+ case ZodFirstPartyTypeKind.ZodOptional:
78
+ required = false;
79
+ current = current._def.innerType;
80
+ continue;
81
+ case ZodFirstPartyTypeKind.ZodDefault:
82
+ required = false;
83
+ defaultValue = current._def.defaultValue();
84
+ current = current._def.innerType;
85
+ continue;
86
+ case ZodFirstPartyTypeKind.ZodNullable:
87
+ nullable = true;
88
+ current = current._def.innerType;
89
+ continue;
90
+ default:
91
+ return {
92
+ schema: current,
93
+ required,
94
+ nullable,
95
+ defaultValue
96
+ };
97
+ }
98
+ }
99
+ }
100
+ function primitiveOption(name, kind, field, choices) {
101
+ return {
102
+ name,
103
+ kind,
104
+ required: field.required,
105
+ nullable: field.nullable || void 0,
106
+ defaultValue: field.defaultValue,
107
+ choices,
108
+ description: field.schema.description
109
+ };
110
+ }
111
+ function optionFromSchema(name, schema, state, path) {
112
+ const field = unwrapField(schema);
113
+ switch (field.schema._def.typeName) {
114
+ case ZodFirstPartyTypeKind.ZodString:
115
+ return primitiveOption(name, "string", field);
116
+ case ZodFirstPartyTypeKind.ZodNumber:
117
+ return primitiveOption(name, "number", field);
118
+ case ZodFirstPartyTypeKind.ZodBigInt:
119
+ return primitiveOption(name, "bigint", field);
120
+ case ZodFirstPartyTypeKind.ZodBoolean:
121
+ return primitiveOption(name, "boolean", field);
122
+ case ZodFirstPartyTypeKind.ZodEnum:
123
+ return primitiveOption(name, "string", field, field.schema._def.values);
124
+ case ZodFirstPartyTypeKind.ZodNativeEnum: {
125
+ const values = [...new Set(Object.values(field.schema._def.values))].filter(
126
+ (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean"
127
+ );
128
+ return primitiveOption(
129
+ name,
130
+ values.every((value) => typeof value === "number") ? "number" : "string",
131
+ field,
132
+ values
133
+ );
134
+ }
135
+ case ZodFirstPartyTypeKind.ZodLiteral:
136
+ return primitiveOption(name, "string", field, [field.schema._def.value]);
137
+ case ZodFirstPartyTypeKind.ZodArray: {
138
+ const item = unwrapField(field.schema._def.type, [...path, "[]"]);
139
+ switch (item.schema._def.typeName) {
140
+ case ZodFirstPartyTypeKind.ZodString:
141
+ return { ...primitiveOption(name, "string", field), variadic: true };
142
+ case ZodFirstPartyTypeKind.ZodNumber:
143
+ return { ...primitiveOption(name, "number", field), variadic: true };
144
+ case ZodFirstPartyTypeKind.ZodBigInt:
145
+ return { ...primitiveOption(name, "bigint", field), variadic: true };
146
+ case ZodFirstPartyTypeKind.ZodBoolean:
147
+ return { ...primitiveOption(name, "boolean", field), variadic: true };
148
+ default:
149
+ return {
150
+ ...primitiveOption(name, "json", field),
151
+ variadic: false
152
+ };
153
+ }
154
+ }
155
+ case ZodFirstPartyTypeKind.ZodLazy: {
156
+ const lazySchema = field.schema;
157
+ if (state.seenLazySchemas.has(lazySchema)) {
158
+ unsupported(
159
+ "Recursive z.lazy schemas are not supported by the CLI adapter",
160
+ state,
161
+ path
162
+ );
163
+ }
164
+ state.seenLazySchemas.add(lazySchema);
165
+ try {
166
+ return optionFromSchema(name, lazySchema._def.getter(), state, path);
167
+ } finally {
168
+ state.seenLazySchemas.delete(lazySchema);
169
+ }
170
+ }
171
+ case ZodFirstPartyTypeKind.ZodBranded:
172
+ return primitiveOption(name, "string", field);
173
+ case ZodFirstPartyTypeKind.ZodObject:
174
+ case ZodFirstPartyTypeKind.ZodUnion:
175
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
176
+ case ZodFirstPartyTypeKind.ZodRecord:
177
+ case ZodFirstPartyTypeKind.ZodAny:
178
+ case ZodFirstPartyTypeKind.ZodUnknown:
179
+ return primitiveOption(name, "json", field);
180
+ default:
181
+ unsupported(
182
+ `Unsupported Zod schema kind ${field.schema._def.typeName}`,
183
+ state,
184
+ path
185
+ );
186
+ }
187
+ }
188
+ function zodToCli(schema, options = {}) {
189
+ if (schema._def.typeName !== ZodFirstPartyTypeKind.ZodObject) {
190
+ throw schemaAdapterError("CLI generation requires a Zod object schema", {
191
+ adapter: "cli",
192
+ location: options.location,
193
+ path: []
194
+ });
195
+ }
196
+ const state = {
197
+ location: options.location,
198
+ seenLazySchemas: /* @__PURE__ */ new WeakSet()
199
+ };
200
+ const optionsList = Object.entries(getObjectShape(schema)).sort(([left], [right]) => left.localeCompare(right)).map(([name, value]) => optionFromSchema(name, value, state, [name]));
201
+ return {
202
+ options: optionsList
203
+ };
204
+ }
205
+ function encodeLiteral(value) {
206
+ if (typeof value === "bigint") {
207
+ return `${value}n`;
208
+ }
209
+ return JSON.stringify(value);
210
+ }
211
+ function sortEntries(entries) {
212
+ return [...entries].sort(([left], [right]) => left.localeCompare(right));
213
+ }
214
+ function getObjectShape2(schema) {
215
+ const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
216
+ return shape;
217
+ }
218
+ function unwrapOptionalLike(schema, state, path) {
219
+ const defaults = [];
220
+ let current = schema;
221
+ let isOptional = false;
222
+ while (true) {
223
+ switch (current._def.typeName) {
224
+ case ZodFirstPartyTypeKind.ZodOptional:
225
+ isOptional = true;
226
+ current = current._def.innerType;
227
+ continue;
228
+ case ZodFirstPartyTypeKind.ZodDefault: {
229
+ if (state.purpose === "table") {
230
+ throw schemaAdapterError(
231
+ "Zod defaults are not allowed in table contracts",
232
+ {
233
+ adapter: "convex",
234
+ purpose: state.purpose,
235
+ location: state.location,
236
+ path
237
+ }
238
+ );
239
+ }
240
+ isOptional = true;
241
+ defaults.push({
242
+ path,
243
+ value: current._def.defaultValue()
244
+ });
245
+ current = current._def.innerType;
246
+ continue;
247
+ }
248
+ default:
249
+ return {
250
+ schema: current,
251
+ isOptional,
252
+ defaults
253
+ };
254
+ }
255
+ }
256
+ }
257
+ function convertSchema(schema, state, path) {
258
+ const { schema: unwrapped, isOptional, defaults } = unwrapOptionalLike(
259
+ schema,
260
+ state,
261
+ path
262
+ );
263
+ const converted = convertSchemaInner(unwrapped, state, path);
264
+ return {
265
+ source: isOptional ? `v.optional(${converted.source})` : converted.source,
266
+ defaults: [...defaults, ...converted.defaults]
267
+ };
268
+ }
269
+ function enumToUnion(values) {
270
+ if (values.length === 0) {
271
+ return "v.never()";
272
+ }
273
+ if (values.length === 1) {
274
+ return `v.literal(${encodeLiteral(values[0])})`;
275
+ }
276
+ return `v.union(${values.map((value) => `v.literal(${encodeLiteral(value)})`).join(", ")})`;
277
+ }
278
+ function unsupported2(message, state, path) {
279
+ throw schemaAdapterError(message, {
280
+ adapter: "convex",
281
+ purpose: state.purpose,
282
+ location: state.location,
283
+ path
284
+ });
285
+ }
286
+ function convertLazy(schema, state, path) {
287
+ const lazySchema = schema;
288
+ if (state.seenLazySchemas.has(lazySchema)) {
289
+ unsupported2(
290
+ "Recursive z.lazy schemas are not supported by the Convex adapter",
291
+ state,
292
+ path
293
+ );
294
+ }
295
+ state.seenLazySchemas.add(lazySchema);
296
+ try {
297
+ return convertSchema(lazySchema._def.getter(), state, path);
298
+ } finally {
299
+ state.seenLazySchemas.delete(lazySchema);
300
+ }
301
+ }
302
+ function convertSchemaInner(schema, state, path) {
303
+ const idTable = getConvexIdTable(schema);
304
+ if (idTable) {
305
+ return {
306
+ source: `v.id(${JSON.stringify(idTable)})`,
307
+ defaults: []
308
+ };
309
+ }
310
+ switch (schema._def.typeName) {
311
+ case ZodFirstPartyTypeKind.ZodString:
312
+ return { source: "v.string()", defaults: [] };
313
+ case ZodFirstPartyTypeKind.ZodNumber:
314
+ return { source: "v.number()", defaults: [] };
315
+ case ZodFirstPartyTypeKind.ZodBigInt:
316
+ return { source: "v.int64()", defaults: [] };
317
+ case ZodFirstPartyTypeKind.ZodBoolean:
318
+ return { source: "v.boolean()", defaults: [] };
319
+ case ZodFirstPartyTypeKind.ZodNull:
320
+ return { source: "v.null()", defaults: [] };
321
+ case ZodFirstPartyTypeKind.ZodAny:
322
+ case ZodFirstPartyTypeKind.ZodUnknown:
323
+ return { source: "v.any()", defaults: [] };
324
+ case ZodFirstPartyTypeKind.ZodLiteral: {
325
+ return {
326
+ source: `v.literal(${encodeLiteral(schema._def.value)})`,
327
+ defaults: []
328
+ };
329
+ }
330
+ case ZodFirstPartyTypeKind.ZodEnum:
331
+ return {
332
+ source: enumToUnion(schema._def.values),
333
+ defaults: []
334
+ };
335
+ case ZodFirstPartyTypeKind.ZodNativeEnum: {
336
+ const values = Object.values(schema._def.values).filter(
337
+ (value) => typeof value === "string" || typeof value === "number"
338
+ );
339
+ return {
340
+ source: enumToUnion([...new Set(values)]),
341
+ defaults: []
342
+ };
343
+ }
344
+ case ZodFirstPartyTypeKind.ZodNullable: {
345
+ const inner = convertSchema(schema._def.innerType, state, path);
346
+ return {
347
+ source: `v.nullable(${inner.source})`,
348
+ defaults: inner.defaults
349
+ };
350
+ }
351
+ case ZodFirstPartyTypeKind.ZodArray: {
352
+ const inner = convertSchema(schema._def.type, state, [...path, "[]"]);
353
+ return {
354
+ source: `v.array(${inner.source})`,
355
+ defaults: inner.defaults
356
+ };
357
+ }
358
+ case ZodFirstPartyTypeKind.ZodObject: {
359
+ const objectSchema = schema;
360
+ if (objectSchema._def.catchall && objectSchema._def.catchall._def.typeName !== ZodFirstPartyTypeKind.ZodNever) {
361
+ unsupported2(
362
+ "Zod objects with catchall/passthrough fields cannot be lowered to Convex validators",
363
+ state,
364
+ path
365
+ );
366
+ }
367
+ const fields = sortEntries(Object.entries(getObjectShape2(objectSchema)));
368
+ const convertedFields = fields.map(([key, value]) => [
369
+ key,
370
+ convertSchema(value, state, [...path, key])
371
+ ]);
372
+ return {
373
+ source: `v.object({ ${convertedFields.map(([key, converted]) => `${JSON.stringify(key)}: ${converted.source}`).join(", ")} })`,
374
+ defaults: convertedFields.flatMap(([, converted]) => converted.defaults)
375
+ };
376
+ }
377
+ case ZodFirstPartyTypeKind.ZodUnion: {
378
+ const members = schema._def.options.map(
379
+ (option, index) => convertSchema(option, state, [...path, String(index)])
380
+ );
381
+ return {
382
+ source: `v.union(${members.map((member) => member.source).join(", ")})`,
383
+ defaults: members.flatMap((member) => member.defaults)
384
+ };
385
+ }
386
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
387
+ const discriminatedUnion = schema;
388
+ const options = discriminatedUnion.options instanceof Map ? [...discriminatedUnion.options.values()] : [...discriminatedUnion.options];
389
+ const members = options.map(
390
+ (option, index) => convertSchema(option, state, [...path, String(index)])
391
+ );
392
+ return {
393
+ source: `v.union(${members.map((member) => member.source).join(", ")})`,
394
+ defaults: members.flatMap((member) => member.defaults)
395
+ };
396
+ }
397
+ case ZodFirstPartyTypeKind.ZodRecord: {
398
+ const keyType = schema._def.keyType;
399
+ if (keyType && keyType._def.typeName !== ZodFirstPartyTypeKind.ZodString) {
400
+ unsupported2(
401
+ "Only string-keyed z.record schemas can be lowered to Convex validators",
402
+ state,
403
+ path
404
+ );
405
+ }
406
+ const value = convertSchema(schema._def.valueType, state, [...path, "{}"]);
407
+ return {
408
+ source: `v.record(v.string(), ${value.source})`,
409
+ defaults: value.defaults
410
+ };
411
+ }
412
+ case ZodFirstPartyTypeKind.ZodLazy:
413
+ return convertLazy(schema, state, path);
414
+ case ZodFirstPartyTypeKind.ZodBranded: {
415
+ return convertSchema(schema._def.type, state, path);
416
+ }
417
+ case ZodFirstPartyTypeKind.ZodEffects: {
418
+ return convertSchema(schema._def.schema, state, path);
419
+ }
420
+ default:
421
+ unsupported2(`Unsupported Zod schema kind ${schema._def.typeName}`, state, path);
422
+ }
423
+ }
424
+ function zodToConvex(schema, options = {}) {
425
+ const state = {
426
+ location: options.location,
427
+ purpose: options.purpose ?? "function_returns",
428
+ seenLazySchemas: /* @__PURE__ */ new WeakSet()
429
+ };
430
+ const converted = convertSchema(schema, state, []);
431
+ return {
432
+ source: converted.source,
433
+ defaults: converted.defaults
434
+ };
435
+ }
436
+ function tableIndexToConvexSource(index) {
437
+ switch (index.kind) {
438
+ case "index":
439
+ return `.index(${JSON.stringify(index.name)}, [${index.columns.map((column) => JSON.stringify(column)).join(", ")}])`;
440
+ case "search":
441
+ return `.searchIndex(${JSON.stringify(index.name)}, { searchField: ${JSON.stringify(
442
+ index.searchField
443
+ )}${index.filterFields?.length ? `, filterFields: [${index.filterFields.map((field) => JSON.stringify(field)).join(", ")}]` : ""} })`;
444
+ case "vector":
445
+ return `.vectorIndex(${JSON.stringify(index.name)}, { vectorField: ${JSON.stringify(
446
+ index.vectorField
447
+ )}, dimensions: ${index.dimensions}${index.filterFields?.length ? `, filterFields: [${index.filterFields.map((field) => JSON.stringify(field)).join(", ")}]` : ""} })`;
448
+ default: {
449
+ const exhaustive = index;
450
+ throw new SchemaAdapterError(
451
+ `Unsupported table index kind ${exhaustive.kind ?? "unknown"}`,
452
+ { adapter: "convex" }
453
+ );
454
+ }
455
+ }
456
+ }
457
+ function unsupported3(message, state, path) {
458
+ throw schemaAdapterError(message, {
459
+ adapter: "jsonschema",
460
+ location: state.location,
461
+ path
462
+ });
463
+ }
464
+ function getObjectShape3(schema) {
465
+ const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
466
+ return shape;
467
+ }
468
+ function unwrapOptionalLike2(schema, state, path) {
469
+ let current = schema;
470
+ let required = true;
471
+ let defaultValue;
472
+ while (true) {
473
+ switch (current._def.typeName) {
474
+ case ZodFirstPartyTypeKind.ZodOptional:
475
+ required = false;
476
+ current = current._def.innerType;
477
+ continue;
478
+ case ZodFirstPartyTypeKind.ZodDefault:
479
+ required = false;
480
+ defaultValue = current._def.defaultValue();
481
+ current = current._def.innerType;
482
+ continue;
483
+ default:
484
+ return {
485
+ schema: current,
486
+ required,
487
+ defaultValue
488
+ };
489
+ }
490
+ }
491
+ }
492
+ function convertLazy2(schema, state, path) {
493
+ if (state.seenLazySchemas.has(schema)) {
494
+ unsupported3(
495
+ "Recursive z.lazy schemas are not supported by the JSON Schema adapter",
496
+ state,
497
+ path
498
+ );
499
+ }
500
+ state.seenLazySchemas.add(schema);
501
+ try {
502
+ return convertSchema2(schema._def.getter(), state, path);
503
+ } finally {
504
+ state.seenLazySchemas.delete(schema);
505
+ }
506
+ }
507
+ function literalType(value) {
508
+ switch (typeof value) {
509
+ case "string":
510
+ return "string";
511
+ case "number":
512
+ return Number.isInteger(value) ? "integer" : "number";
513
+ case "boolean":
514
+ return "boolean";
515
+ case "bigint":
516
+ return "integer";
517
+ default:
518
+ return value === null ? "null" : void 0;
519
+ }
520
+ }
521
+ function convertField(schema, state, path) {
522
+ const { schema: unwrapped, required, defaultValue } = unwrapOptionalLike2(
523
+ schema);
524
+ const field = convertSchema2(unwrapped, state, path);
525
+ if (typeof field === "boolean") {
526
+ return {
527
+ schema: field,
528
+ required
529
+ };
530
+ }
531
+ return {
532
+ schema: defaultValue === void 0 ? field : { ...field, default: defaultValue },
533
+ required
534
+ };
535
+ }
536
+ function convertSchema2(schema, state, path) {
537
+ const idTable = getConvexIdTable(schema);
538
+ if (idTable) {
539
+ return {
540
+ type: "string",
541
+ "x-convex-id-table": idTable
542
+ };
543
+ }
544
+ switch (schema._def.typeName) {
545
+ case ZodFirstPartyTypeKind.ZodString:
546
+ return { type: "string" };
547
+ case ZodFirstPartyTypeKind.ZodNumber:
548
+ return { type: "number" };
549
+ case ZodFirstPartyTypeKind.ZodBigInt:
550
+ return { type: "integer", format: "int64" };
551
+ case ZodFirstPartyTypeKind.ZodBoolean:
552
+ return { type: "boolean" };
553
+ case ZodFirstPartyTypeKind.ZodNull:
554
+ return { type: "null" };
555
+ case ZodFirstPartyTypeKind.ZodAny:
556
+ case ZodFirstPartyTypeKind.ZodUnknown:
557
+ return {};
558
+ case ZodFirstPartyTypeKind.ZodLiteral:
559
+ return {
560
+ const: schema._def.value,
561
+ type: literalType(schema._def.value)
562
+ };
563
+ case ZodFirstPartyTypeKind.ZodEnum:
564
+ return {
565
+ type: "string",
566
+ enum: schema._def.values
567
+ };
568
+ case ZodFirstPartyTypeKind.ZodNativeEnum: {
569
+ const values = [...new Set(Object.values(schema._def.values))].filter(
570
+ (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean"
571
+ );
572
+ return {
573
+ type: values.every((value) => typeof value === "number") ? "number" : "string",
574
+ enum: values
575
+ };
576
+ }
577
+ case ZodFirstPartyTypeKind.ZodNullable: {
578
+ const inner = convertSchema2(schema._def.innerType, state, path);
579
+ return {
580
+ anyOf: [inner, { type: "null" }]
581
+ };
582
+ }
583
+ case ZodFirstPartyTypeKind.ZodArray:
584
+ return {
585
+ type: "array",
586
+ items: convertSchema2(schema._def.type, state, [...path, "[]"])
587
+ };
588
+ case ZodFirstPartyTypeKind.ZodObject: {
589
+ const objectSchema = schema;
590
+ if (objectSchema._def.catchall && objectSchema._def.catchall._def.typeName !== ZodFirstPartyTypeKind.ZodNever) {
591
+ unsupported3(
592
+ "Zod objects with catchall/passthrough fields cannot be lowered to JSON Schema",
593
+ state,
594
+ path
595
+ );
596
+ }
597
+ const entries = Object.entries(getObjectShape3(objectSchema)).sort(
598
+ ([a], [b]) => a.localeCompare(b)
599
+ );
600
+ const converted = entries.map(([key, value]) => [
601
+ key,
602
+ convertField(value, state, [...path, key])
603
+ ]);
604
+ const required = converted.filter(([, field]) => field.required).map(([key]) => key);
605
+ return {
606
+ type: "object",
607
+ properties: Object.fromEntries(
608
+ converted.map(([key, field]) => [key, field.schema])
609
+ ),
610
+ additionalProperties: false,
611
+ ...required.length > 0 ? { required } : {}
612
+ };
613
+ }
614
+ case ZodFirstPartyTypeKind.ZodUnion:
615
+ return {
616
+ anyOf: schema._def.options.map(
617
+ (option, index) => convertSchema2(option, state, [...path, String(index)])
618
+ )
619
+ };
620
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
621
+ const discriminatedUnion = schema;
622
+ const options = discriminatedUnion.options instanceof Map ? [...discriminatedUnion.options.values()] : [...discriminatedUnion.options];
623
+ return {
624
+ oneOf: options.map(
625
+ (option, index) => convertSchema2(option, state, [...path, String(index)])
626
+ )
627
+ };
628
+ }
629
+ case ZodFirstPartyTypeKind.ZodRecord: {
630
+ const keyType = schema._def.keyType;
631
+ if (keyType && keyType._def.typeName !== ZodFirstPartyTypeKind.ZodString) {
632
+ unsupported3(
633
+ "Only string-keyed z.record schemas can be lowered to JSON Schema",
634
+ state,
635
+ path
636
+ );
637
+ }
638
+ return {
639
+ type: "object",
640
+ additionalProperties: convertSchema2(
641
+ schema._def.valueType,
642
+ state,
643
+ [...path, "{}"]
644
+ )
645
+ };
646
+ }
647
+ case ZodFirstPartyTypeKind.ZodLazy:
648
+ return convertLazy2(schema, state, path);
649
+ case ZodFirstPartyTypeKind.ZodBranded:
650
+ return convertSchema2(schema._def.type, state, path);
651
+ default:
652
+ unsupported3(
653
+ `Unsupported Zod schema kind ${schema._def.typeName}`,
654
+ state,
655
+ path
656
+ );
657
+ }
658
+ }
659
+ function zodToJsonSchema(schema, options = {}) {
660
+ const converted = convertSchema2(schema, {
661
+ location: options.location,
662
+ seenLazySchemas: /* @__PURE__ */ new WeakSet()
663
+ }, []);
664
+ if (typeof converted === "boolean") {
665
+ return converted;
666
+ }
667
+ return {
668
+ $schema: "http://json-schema.org/draft-07/schema#",
669
+ ...converted
670
+ };
671
+ }
672
+
673
+ export { CONVEX_ID_TABLE, SchemaAdapterError, defineFunction, defineTable, getConvexIdTable, idOf, schemaAdapterError, tableIndexToConvexSource, zodToCli, zodToConvex, zodToJsonSchema };
674
+ //# sourceMappingURL=dsl.values.js.map
675
+ //# sourceMappingURL=dsl.values.js.map