desen-core 1.0.3-draft

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.
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > desen-core@1.0.3-draft build /Users/selmanay/Desktop/desen/packages/core
4
+ > tsc
5
+
@@ -0,0 +1,16 @@
1
+ export { bindingSourceEnum, bindingSpec, bindWrapper, modifiersSpec, } from "./schemas/binding";
2
+ export type { BindingSource, BindingSpec, BindWrapper, ModifiersSpec, } from "./schemas/binding";
3
+ export { telemetrySpec, telemetryEnvelopeSpec, } from "./schemas/telemetry";
4
+ export type { TelemetrySpec, TelemetryEnvelope, } from "./schemas/telemetry";
5
+ export { actionSpec } from "./schemas/action";
6
+ export type { ActionSpec } from "./schemas/action";
7
+ export { styleSpec } from "./schemas/style";
8
+ export type { StyleSpec } from "./schemas/style";
9
+ export { dtcgTokenLeaf, tokenThemeSchema } from "./schemas/token";
10
+ export type { DTCGTokenLeaf, DTCGTokenGroup, TokenTheme } from "./schemas/token";
11
+ export { elementSpec } from "./schemas/element";
12
+ export type { ElementSpec } from "./schemas/element";
13
+ export { positioningSpec, layoutSpec, nodeSpec, compositionSpec, repeaterSpec, } from "./schemas/composition";
14
+ export type { PositioningSpec, LayoutSpec, NodeSpec, CompositionSpec, RepeaterSpec, } from "./schemas/composition";
15
+ export { surfaceSpec } from "./schemas/surface";
16
+ export type { SurfaceSpec } from "./schemas/surface";
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // ─── desen-core ─────────────────────────────────────────────────
3
+ // DESEN Protocol Validation Engine
4
+ // Pure TypeScript + Zod — Zero UI dependencies
5
+ //
6
+ // All schemas and types adhere to SPEC.md v1.0.0-RC
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.surfaceSpec = exports.repeaterSpec = exports.compositionSpec = exports.nodeSpec = exports.layoutSpec = exports.positioningSpec = exports.elementSpec = exports.tokenThemeSchema = exports.dtcgTokenLeaf = exports.styleSpec = exports.actionSpec = exports.telemetryEnvelopeSpec = exports.telemetrySpec = exports.modifiersSpec = exports.bindWrapper = exports.bindingSpec = exports.bindingSourceEnum = void 0;
9
+ // ── Binding & Modifiers (§2.7, §2.11) ──
10
+ var binding_1 = require("./schemas/binding");
11
+ Object.defineProperty(exports, "bindingSourceEnum", { enumerable: true, get: function () { return binding_1.bindingSourceEnum; } });
12
+ Object.defineProperty(exports, "bindingSpec", { enumerable: true, get: function () { return binding_1.bindingSpec; } });
13
+ Object.defineProperty(exports, "bindWrapper", { enumerable: true, get: function () { return binding_1.bindWrapper; } });
14
+ Object.defineProperty(exports, "modifiersSpec", { enumerable: true, get: function () { return binding_1.modifiersSpec; } });
15
+ // ── Telemetry (§2.3, §4.5) ──
16
+ var telemetry_1 = require("./schemas/telemetry");
17
+ Object.defineProperty(exports, "telemetrySpec", { enumerable: true, get: function () { return telemetry_1.telemetrySpec; } });
18
+ Object.defineProperty(exports, "telemetryEnvelopeSpec", { enumerable: true, get: function () { return telemetry_1.telemetryEnvelopeSpec; } });
19
+ // ── Actions (§2.4) ──
20
+ var action_1 = require("./schemas/action");
21
+ Object.defineProperty(exports, "actionSpec", { enumerable: true, get: function () { return action_1.actionSpec; } });
22
+ // ── Style & Tokens (§2.6) ──
23
+ var style_1 = require("./schemas/style");
24
+ Object.defineProperty(exports, "styleSpec", { enumerable: true, get: function () { return style_1.styleSpec; } });
25
+ var token_1 = require("./schemas/token");
26
+ Object.defineProperty(exports, "dtcgTokenLeaf", { enumerable: true, get: function () { return token_1.dtcgTokenLeaf; } });
27
+ Object.defineProperty(exports, "tokenThemeSchema", { enumerable: true, get: function () { return token_1.tokenThemeSchema; } });
28
+ // ── Element (§2.2) ──
29
+ var element_1 = require("./schemas/element");
30
+ Object.defineProperty(exports, "elementSpec", { enumerable: true, get: function () { return element_1.elementSpec; } });
31
+ // ── Composition, Layout, Repeater, Node (§2.3, §2.5, §3.5) ──
32
+ var composition_1 = require("./schemas/composition");
33
+ Object.defineProperty(exports, "positioningSpec", { enumerable: true, get: function () { return composition_1.positioningSpec; } });
34
+ Object.defineProperty(exports, "layoutSpec", { enumerable: true, get: function () { return composition_1.layoutSpec; } });
35
+ Object.defineProperty(exports, "nodeSpec", { enumerable: true, get: function () { return composition_1.nodeSpec; } });
36
+ Object.defineProperty(exports, "compositionSpec", { enumerable: true, get: function () { return composition_1.compositionSpec; } });
37
+ Object.defineProperty(exports, "repeaterSpec", { enumerable: true, get: function () { return composition_1.repeaterSpec; } });
38
+ // ── Surface (§2.8) ──
39
+ var surface_1 = require("./schemas/surface");
40
+ Object.defineProperty(exports, "surfaceSpec", { enumerable: true, get: function () { return surface_1.surfaceSpec; } });
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ export declare const actionSpec: z.ZodType<any>;
3
+ export type ActionSpec = z.infer<typeof actionSpec>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actionSpec = void 0;
4
+ const zod_1 = require("zod");
5
+ // ─── ActionSpec ──────────────────────────────────────────────────
6
+ // SPEC.md §2.4: Standardized behavior primitives.
7
+ // kind is REQUIRED; target, params, actions are optional.
8
+ // "sequence" kind uses recursive `actions` array.
9
+ exports.actionSpec = zod_1.z.lazy(() => zod_1.z.object({
10
+ kind: zod_1.z.enum(["navigate", "mutate", "trigger_event", "sequence"]),
11
+ target: zod_1.z.string().optional(),
12
+ params: zod_1.z.record(zod_1.z.any()).optional(),
13
+ actions: zod_1.z.array(exports.actionSpec).optional(),
14
+ }).passthrough());
@@ -0,0 +1,91 @@
1
+ import { z } from "zod";
2
+ export declare const bindingSourceEnum: z.ZodEnum<["session", "backend", "local", "feature_flag"]>;
3
+ export declare const bindingSpec: z.ZodObject<{
4
+ source: z.ZodEnum<["session", "backend", "local", "feature_flag"]>;
5
+ path: z.ZodString;
6
+ fallback: z.ZodOptional<z.ZodAny>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ source: "session" | "backend" | "local" | "feature_flag";
9
+ path: string;
10
+ fallback?: any;
11
+ }, {
12
+ source: "session" | "backend" | "local" | "feature_flag";
13
+ path: string;
14
+ fallback?: any;
15
+ }>;
16
+ export declare const bindWrapper: z.ZodObject<{
17
+ bind: z.ZodObject<{
18
+ source: z.ZodEnum<["session", "backend", "local", "feature_flag"]>;
19
+ path: z.ZodString;
20
+ fallback: z.ZodOptional<z.ZodAny>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ source: "session" | "backend" | "local" | "feature_flag";
23
+ path: string;
24
+ fallback?: any;
25
+ }, {
26
+ source: "session" | "backend" | "local" | "feature_flag";
27
+ path: string;
28
+ fallback?: any;
29
+ }>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ bind: {
32
+ source: "session" | "backend" | "local" | "feature_flag";
33
+ path: string;
34
+ fallback?: any;
35
+ };
36
+ }, {
37
+ bind: {
38
+ source: "session" | "backend" | "local" | "feature_flag";
39
+ path: string;
40
+ fallback?: any;
41
+ };
42
+ }>;
43
+ export declare const modifiersSpec: z.ZodObject<{
44
+ visible: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
45
+ bind: z.ZodObject<{
46
+ source: z.ZodEnum<["session", "backend", "local", "feature_flag"]>;
47
+ path: z.ZodString;
48
+ fallback: z.ZodOptional<z.ZodAny>;
49
+ }, "strip", z.ZodTypeAny, {
50
+ source: "session" | "backend" | "local" | "feature_flag";
51
+ path: string;
52
+ fallback?: any;
53
+ }, {
54
+ source: "session" | "backend" | "local" | "feature_flag";
55
+ path: string;
56
+ fallback?: any;
57
+ }>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ bind: {
60
+ source: "session" | "backend" | "local" | "feature_flag";
61
+ path: string;
62
+ fallback?: any;
63
+ };
64
+ }, {
65
+ bind: {
66
+ source: "session" | "backend" | "local" | "feature_flag";
67
+ path: string;
68
+ fallback?: any;
69
+ };
70
+ }>]>>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ visible?: boolean | {
73
+ bind: {
74
+ source: "session" | "backend" | "local" | "feature_flag";
75
+ path: string;
76
+ fallback?: any;
77
+ };
78
+ } | undefined;
79
+ }, {
80
+ visible?: boolean | {
81
+ bind: {
82
+ source: "session" | "backend" | "local" | "feature_flag";
83
+ path: string;
84
+ fallback?: any;
85
+ };
86
+ } | undefined;
87
+ }>;
88
+ export type BindingSource = z.infer<typeof bindingSourceEnum>;
89
+ export type BindingSpec = z.infer<typeof bindingSpec>;
90
+ export type BindWrapper = z.infer<typeof bindWrapper>;
91
+ export type ModifiersSpec = z.infer<typeof modifiersSpec>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifiersSpec = exports.bindWrapper = exports.bindingSpec = exports.bindingSourceEnum = void 0;
4
+ const zod_1 = require("zod");
5
+ // ─── Binding Sources ─────────────────────────────────────────────
6
+ // SPEC.md §2.7: source MUST be an implementation-defined identifier
7
+ // for a trusted data source. Runtimes MUST maintain a fixed allowlist.
8
+ exports.bindingSourceEnum = zod_1.z.enum([
9
+ "session",
10
+ "backend",
11
+ "local",
12
+ "feature_flag",
13
+ ]);
14
+ // ─── bindingSpec ─────────────────────────────────────────────────
15
+ // SPEC.md §2.7: { source, path } required; fallback optional
16
+ exports.bindingSpec = zod_1.z.object({
17
+ source: exports.bindingSourceEnum,
18
+ path: zod_1.z.string().min(1),
19
+ fallback: zod_1.z.any().optional(),
20
+ });
21
+ // ─── Bind Wrapper ────────────────────────────────────────────────
22
+ // Standard wrapper: { bind: bindingSpec }
23
+ exports.bindWrapper = zod_1.z.object({
24
+ bind: exports.bindingSpec,
25
+ });
26
+ // ─── modifiersSpec ───────────────────────────────────────────────
27
+ // SPEC.md §2.11: visible can be a boolean or a bind reference.
28
+ // If binding fails and no fallback is present, default is false (fail-closed).
29
+ exports.modifiersSpec = zod_1.z.object({
30
+ visible: zod_1.z.union([zod_1.z.boolean(), exports.bindWrapper]).optional(),
31
+ });
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ export type NodeSpec = {
3
+ type: string;
4
+ [key: string]: any;
5
+ };
6
+ export declare const positioningSpec: z.ZodObject<{
7
+ type: z.ZodEnum<["relative", "sticky", "absolute"]>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ type: "relative" | "sticky" | "absolute";
10
+ }, {
11
+ type: "relative" | "sticky" | "absolute";
12
+ }>;
13
+ export declare const layoutSpec: z.ZodObject<{
14
+ kind: z.ZodEnum<["stack", "grid"]>;
15
+ direction: z.ZodOptional<z.ZodEnum<["vertical", "horizontal"]>>;
16
+ gap: z.ZodOptional<z.ZodNumber>;
17
+ columns: z.ZodOptional<z.ZodNumber>;
18
+ align: z.ZodOptional<z.ZodEnum<["start", "center", "end", "stretch"]>>;
19
+ positioning: z.ZodOptional<z.ZodObject<{
20
+ type: z.ZodEnum<["relative", "sticky", "absolute"]>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ type: "relative" | "sticky" | "absolute";
23
+ }, {
24
+ type: "relative" | "sticky" | "absolute";
25
+ }>>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ kind: "stack" | "grid";
28
+ direction?: "vertical" | "horizontal" | undefined;
29
+ gap?: number | undefined;
30
+ columns?: number | undefined;
31
+ align?: "start" | "center" | "end" | "stretch" | undefined;
32
+ positioning?: {
33
+ type: "relative" | "sticky" | "absolute";
34
+ } | undefined;
35
+ }, {
36
+ kind: "stack" | "grid";
37
+ direction?: "vertical" | "horizontal" | undefined;
38
+ gap?: number | undefined;
39
+ columns?: number | undefined;
40
+ align?: "start" | "center" | "end" | "stretch" | undefined;
41
+ positioning?: {
42
+ type: "relative" | "sticky" | "absolute";
43
+ } | undefined;
44
+ }>;
45
+ export declare const nodeSpec: z.ZodType<NodeSpec>;
46
+ export declare const compositionSpec: z.ZodType<any>;
47
+ export declare const repeaterSpec: z.ZodType<any>;
48
+ export type PositioningSpec = z.infer<typeof positioningSpec>;
49
+ export type LayoutSpec = z.infer<typeof layoutSpec>;
50
+ export type CompositionSpec = z.infer<typeof compositionSpec>;
51
+ export type RepeaterSpec = z.infer<typeof repeaterSpec>;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.repeaterSpec = exports.compositionSpec = exports.nodeSpec = exports.layoutSpec = exports.positioningSpec = void 0;
4
+ const zod_1 = require("zod");
5
+ const binding_1 = require("./binding");
6
+ const telemetry_1 = require("./telemetry");
7
+ // ─── Positioning ─────────────────────────────────────────────────
8
+ // SPEC.md §3.5: relative, sticky, absolute
9
+ exports.positioningSpec = zod_1.z.object({
10
+ type: zod_1.z.enum(["relative", "sticky", "absolute"]),
11
+ });
12
+ // ─── layoutSpec ──────────────────────────────────────────────────
13
+ // SPEC.md §2.3: kind REQUIRED, rest optional
14
+ exports.layoutSpec = zod_1.z.object({
15
+ kind: zod_1.z.enum(["stack", "grid"]),
16
+ direction: zod_1.z.enum(["vertical", "horizontal"]).optional(),
17
+ gap: zod_1.z.number().min(0).optional(),
18
+ columns: zod_1.z.number().int().min(1).optional(),
19
+ align: zod_1.z.enum(["start", "center", "end", "stretch"]).optional(),
20
+ positioning: exports.positioningSpec.optional(),
21
+ });
22
+ // ─── Composition types ───────────────────────────────────────────
23
+ const compositionTypeEnum = zod_1.z.enum(["Card", "Stack", "Grid", "Header", "Footer"]);
24
+ const compositionTypes = new Set(["Card", "Stack", "Grid", "Header", "Footer"]);
25
+ // ─── Constraints (shared) ────────────────────────────────────────
26
+ const constraintsSpec = zod_1.z.object({
27
+ a11y: zod_1.z.object({
28
+ aria_label: zod_1.z.string().optional(),
29
+ aria_role: zod_1.z.string().optional(),
30
+ min_contrast_ratio: zod_1.z.number().min(1).optional(),
31
+ focusable: zod_1.z.boolean().optional(),
32
+ }).optional(),
33
+ }).passthrough().optional();
34
+ // ─── nodeSpec (discriminated by type field) ───────────────────────
35
+ // SPEC.md §1.3: Node = Element | Composition | Repeater
36
+ //
37
+ // PERFORMANCE FIX: Instead of z.union() which tries all branches,
38
+ // we use a custom z.lazy() that checks the `type` field to
39
+ // dispatch to the correct schema — avoiding exponential backtracking.
40
+ exports.nodeSpec = zod_1.z.lazy(() => zod_1.z.any().superRefine((val, ctx) => {
41
+ if (typeof val !== "object" || val === null || typeof val.type !== "string") {
42
+ ctx.addIssue({
43
+ code: zod_1.z.ZodIssueCode.custom,
44
+ message: "Node must be an object with a 'type' string property.",
45
+ });
46
+ return;
47
+ }
48
+ let result;
49
+ if (val.type === "Repeater") {
50
+ result = exports.repeaterSpec.safeParse(val);
51
+ }
52
+ else if (compositionTypes.has(val.type)) {
53
+ result = exports.compositionSpec.safeParse(val);
54
+ }
55
+ else {
56
+ // Any other type is treated as an ElementSpec
57
+ result = elementSpecInternal.safeParse(val);
58
+ }
59
+ if (!result.success) {
60
+ for (const issue of result.error.issues) {
61
+ ctx.addIssue(issue);
62
+ }
63
+ }
64
+ }));
65
+ // ─── Internal ElementSpec (no refine to avoid double-checking in nodeSpec) ──
66
+ const elementSpecInternal = zod_1.z.object({
67
+ type: zod_1.z.string().min(1),
68
+ id: zod_1.z.string().min(1),
69
+ props: zod_1.z.record(zod_1.z.any()),
70
+ constraints: constraintsSpec,
71
+ modifiers: binding_1.modifiersSpec.optional(),
72
+ telemetry: telemetry_1.telemetrySpec.optional(),
73
+ }).passthrough()
74
+ .refine((data) => !("children" in data), { message: "ElementSpec MUST NOT contain 'children'. Use CompositionSpec for containers." })
75
+ .refine((data) => !("layout" in data), { message: "ElementSpec MUST NOT contain 'layout'. Use CompositionSpec for layout." });
76
+ // ─── CompositionSpec ─────────────────────────────────────────────
77
+ // SPEC.md §2.3: type (enum), id, layout, children, telemetry REQUIRED.
78
+ exports.compositionSpec = zod_1.z.lazy(() => zod_1.z.object({
79
+ type: compositionTypeEnum,
80
+ id: zod_1.z.string().min(1).regex(/^[A-Za-z][A-Za-z0-9_.:-]{0,127}$/),
81
+ layout: exports.layoutSpec,
82
+ children: zod_1.z.array(exports.nodeSpec).min(0),
83
+ constraints: constraintsSpec,
84
+ modifiers: binding_1.modifiersSpec.optional(),
85
+ telemetry: telemetry_1.telemetrySpec,
86
+ }).passthrough());
87
+ // ─── RepeaterSpec ────────────────────────────────────────────────
88
+ // SPEC.md §2.5: type MUST be "Repeater", data.bind REQUIRED,
89
+ // template MUST be a valid nodeSpec, telemetry REQUIRED.
90
+ exports.repeaterSpec = zod_1.z.lazy(() => zod_1.z.object({
91
+ type: zod_1.z.literal("Repeater"),
92
+ id: zod_1.z.string().min(1),
93
+ data: zod_1.z.object({
94
+ bind: binding_1.bindingSpec,
95
+ }),
96
+ template: exports.nodeSpec,
97
+ modifiers: binding_1.modifiersSpec.optional(),
98
+ telemetry: telemetry_1.telemetrySpec,
99
+ }).passthrough());