@githolon/dsl 0.22.1 → 0.23.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.
- package/package.json +1 -1
- package/src/codegen_proof.ts +24 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@githolon/dsl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Nomos 2 domain-authoring DSL: aggregates + directives in TS, executed and encoded to the Rust kernel's wire shapes.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
package/src/codegen_proof.ts
CHANGED
|
@@ -69,11 +69,34 @@ export interface SynthesizedPayload {
|
|
|
69
69
|
readonly autoStamped: readonly string[];
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// Format-valid placeholders for TYPED-SUBJECT string fields. A directive payload field may REQUIRE a
|
|
73
|
+
// subject/key shape — `user:<uuid>`, `key:<64hex>`, an object `<type>:<id>`, or a bare 64-hex hash —
|
|
74
|
+
// via `.regex(...)` / `.refine(...)`. The readable `sample-<field>` fails such a schema, so the
|
|
75
|
+
// generated proof couldn't dispatch that directive (it threw at payload validation). Ordered most-
|
|
76
|
+
// specific first; probed by safeParse, so it tracks the field's ACTUAL constraint, not its name.
|
|
77
|
+
const ZERO_UUID = "00000000-0000-0000-0000-000000000000";
|
|
78
|
+
const HEX64 = "0".repeat(64);
|
|
79
|
+
const SUBJECT_CANDIDATES: readonly string[] = [`user:${ZERO_UUID}`, `key:${HEX64}`, `Type:${ZERO_UUID}`, HEX64];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Sample a string field, satisfying typed-subject constraints. Use the readable `sample-<field>` when
|
|
83
|
+
* it PASSES the field's own schema (plain / length-bounded strings — unchanged). When it does NOT — a
|
|
84
|
+
* `.regex`/`.refine` subject/key field — probe the known subject placeholders against the field's
|
|
85
|
+
* schema and return the first that validates. If none fits an exotic constraint, fall back to the
|
|
86
|
+
* readable placeholder (behaviour unchanged from before — that directive is proven by hand).
|
|
87
|
+
*/
|
|
88
|
+
function sampleString(zt: z.ZodTypeAny, field: string): string {
|
|
89
|
+
const readable = `sample-${field}`;
|
|
90
|
+
if (zt.safeParse(readable).success) return readable;
|
|
91
|
+
for (const cand of SUBJECT_CANDIDATES) if (zt.safeParse(cand).success) return cand;
|
|
92
|
+
return readable;
|
|
93
|
+
}
|
|
94
|
+
|
|
72
95
|
/** One sample value for one zod shape. NO FALLBACK: an unhandled shape throws, naming its remedy. */
|
|
73
96
|
function sampleOfZod(zt: z.ZodTypeAny, field: string, where: string): unknown {
|
|
74
97
|
switch (zodKind(zt)) {
|
|
75
98
|
case "string":
|
|
76
|
-
return
|
|
99
|
+
return sampleString(zt, field);
|
|
77
100
|
case "number":
|
|
78
101
|
return 1;
|
|
79
102
|
case "boolean":
|