@plures/praxis 1.4.4 → 2.0.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/dist/browser/chunk-6MVRT7CK.js +363 -0
- package/dist/browser/factory/index.d.ts +2 -1
- package/dist/browser/index.d.ts +7 -4
- package/dist/browser/index.js +18 -6
- package/dist/browser/integrations/svelte.d.ts +4 -3
- package/dist/browser/project/index.d.ts +2 -1
- package/dist/browser/{reactive-engine.svelte-DgVTqHLc.d.ts → reactive-engine.svelte-BwWadvAW.d.ts} +2 -1
- package/dist/browser/rule-result-DcXWe9tn.d.ts +206 -0
- package/dist/browser/{rules-i1LHpnGd.d.ts → rules-BaWMqxuG.d.ts} +2 -205
- package/dist/browser/unified/index.d.ts +239 -0
- package/dist/browser/unified/index.js +20 -0
- package/dist/node/chunk-6MVRT7CK.js +363 -0
- package/dist/node/cli/index.js +1 -1
- package/dist/node/index.cjs +367 -0
- package/dist/node/index.d.cts +4 -2
- package/dist/node/index.d.ts +4 -2
- package/dist/node/index.js +19 -7
- package/dist/node/integrations/svelte.d.cts +3 -2
- package/dist/node/integrations/svelte.d.ts +3 -2
- package/dist/node/integrations/svelte.js +2 -2
- package/dist/node/{reactive-engine.svelte-DekxqFu0.d.ts → reactive-engine.svelte-BBZLMzus.d.ts} +3 -79
- package/dist/node/{reactive-engine.svelte-Cg0Yc2Hs.d.cts → reactive-engine.svelte-Cbq_V20o.d.cts} +3 -79
- package/dist/node/rule-result-B9GMivAn.d.cts +80 -0
- package/dist/node/rule-result-Bo3sFMmN.d.ts +80 -0
- package/dist/node/unified/index.cjs +484 -0
- package/dist/node/unified/index.d.cts +240 -0
- package/dist/node/unified/index.d.ts +240 -0
- package/dist/node/unified/index.js +21 -0
- package/package.json +7 -1
- package/src/index.browser.ts +20 -0
- package/src/index.ts +21 -0
- package/src/unified/__tests__/unified.test.ts +396 -0
- package/src/unified/core.ts +517 -0
- package/src/unified/index.ts +32 -0
- package/src/unified/rules.ts +66 -0
- package/src/unified/types.ts +148 -0
- package/dist/node/{chunk-ZO2LU4G4.js → chunk-WFRHXZBP.js} +3 -3
- package/dist/node/{validate-5PSWJTIC.js → validate-BY7JNY7H.js} +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Praxis Unified Reactive Layer — Types
|
|
3
|
+
*
|
|
4
|
+
* The types that define the unified state/rules/logging surface.
|
|
5
|
+
* Developers interact with query() and mutate() — everything else is internal.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PraxisFact, PraxisDiagnostics } from '../core/protocol.js';
|
|
9
|
+
|
|
10
|
+
// ── Store Contract ──────────────────────────────────────────────────────────
|
|
11
|
+
// Any reactive store that supports subscribe(). Works with Svelte writable,
|
|
12
|
+
// Solid signals, or any framework with a subscribe pattern.
|
|
13
|
+
|
|
14
|
+
/** Minimal store contract — anything with subscribe() */
|
|
15
|
+
export interface Subscribable<T> {
|
|
16
|
+
subscribe(cb: (value: T) => void): (() => void) | { unsubscribe(): void };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Writable store contract — subscribe + set + update */
|
|
20
|
+
export interface WritableStore<T> extends Subscribable<T> {
|
|
21
|
+
set(value: T): void;
|
|
22
|
+
update(updater: (current: T) => T): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ── Graph Schema ────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
/** Schema definition for a graph path */
|
|
28
|
+
export interface PathSchema<T = unknown> {
|
|
29
|
+
/** The graph path (e.g., 'sprint/current') */
|
|
30
|
+
path: string;
|
|
31
|
+
/** Default/initial value */
|
|
32
|
+
initial: T;
|
|
33
|
+
/** Optional TTL for staleness detection (ms) */
|
|
34
|
+
staleTtl?: number;
|
|
35
|
+
/** Whether this path is a collection (maps over children) */
|
|
36
|
+
collection?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Define a typed graph path.
|
|
41
|
+
* This is the primary API for declaring what data exists in your app.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const Sprint = definePath<SprintInfo | null>('sprint/current', null);
|
|
45
|
+
* const Items = definePath<WorkItem[]>('sprint/items', [], { collection: true });
|
|
46
|
+
* const Loading = definePath<boolean>('sprint/loading', false);
|
|
47
|
+
*/
|
|
48
|
+
export function definePath<T>(
|
|
49
|
+
path: string,
|
|
50
|
+
initial: T,
|
|
51
|
+
opts?: Omit<PathSchema<T>, 'path' | 'initial'>
|
|
52
|
+
): PathSchema<T> {
|
|
53
|
+
return { path, initial, ...opts };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── Query Options ───────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export interface QueryOptions<T> {
|
|
59
|
+
/** Filter function for collections */
|
|
60
|
+
where?: (item: T extends (infer U)[] ? U : T) => boolean;
|
|
61
|
+
/** Select/map function */
|
|
62
|
+
select?: (item: T) => unknown;
|
|
63
|
+
/** Sort comparator */
|
|
64
|
+
sort?: (a: any, b: any) => number;
|
|
65
|
+
/** Limit results */
|
|
66
|
+
limit?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ── Reactive Query Result ───────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A reactive reference returned by query().
|
|
73
|
+
* Has a Svelte-compatible subscribe() and a .current getter.
|
|
74
|
+
*/
|
|
75
|
+
export interface ReactiveRef<T> extends Subscribable<T> {
|
|
76
|
+
/** Current value (synchronous read) */
|
|
77
|
+
readonly current: T;
|
|
78
|
+
/** Svelte store contract — subscribe returns unsubscribe fn */
|
|
79
|
+
subscribe(cb: (value: T) => void): () => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── Mutation Result ─────────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
export interface MutationResult {
|
|
85
|
+
/** Whether the mutation was accepted */
|
|
86
|
+
accepted: boolean;
|
|
87
|
+
/** Constraint violations that blocked the mutation (if any) */
|
|
88
|
+
violations: PraxisDiagnostics[];
|
|
89
|
+
/** Facts emitted by rules triggered by this mutation */
|
|
90
|
+
facts: PraxisFact[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Rule Definition (v2) ────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
export interface UnifiedRule {
|
|
96
|
+
/** Unique rule ID */
|
|
97
|
+
id: string;
|
|
98
|
+
/** Human-readable description */
|
|
99
|
+
description?: string;
|
|
100
|
+
/** Graph paths this rule watches — auto-subscribed */
|
|
101
|
+
watch: string[];
|
|
102
|
+
/** Rule evaluation function — receives watched values by path */
|
|
103
|
+
evaluate: (values: Record<string, any>, facts: PraxisFact[]) => import('../core/rule-result.js').RuleResult;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── Constraint Definition (v2) ──────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
export interface UnifiedConstraint {
|
|
109
|
+
/** Unique constraint ID */
|
|
110
|
+
id: string;
|
|
111
|
+
/** Human-readable description */
|
|
112
|
+
description?: string;
|
|
113
|
+
/** Graph paths this constraint reads */
|
|
114
|
+
watch: string[];
|
|
115
|
+
/** Validation function — return true if valid, string if violated */
|
|
116
|
+
validate: (values: Record<string, any>) => true | string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── Liveness Monitor ────────────────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
export interface LivenessConfig {
|
|
122
|
+
/** Paths that must update within `timeoutMs` after init */
|
|
123
|
+
expect: string[];
|
|
124
|
+
/** Milliseconds to wait before flagging staleness (default: 5000) */
|
|
125
|
+
timeoutMs?: number;
|
|
126
|
+
/** Callback when a path is stale */
|
|
127
|
+
onStale?: (path: string, elapsed: number) => void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── App Definition ──────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
export interface PraxisAppConfig {
|
|
133
|
+
/** App name (used in Chronos context) */
|
|
134
|
+
name: string;
|
|
135
|
+
/** Graph schema — all paths the app uses */
|
|
136
|
+
schema: PathSchema[];
|
|
137
|
+
/** Business rules */
|
|
138
|
+
rules?: UnifiedRule[];
|
|
139
|
+
/** Constraints */
|
|
140
|
+
constraints?: UnifiedConstraint[];
|
|
141
|
+
/** Liveness monitoring */
|
|
142
|
+
liveness?: LivenessConfig;
|
|
143
|
+
/** Chronos options */
|
|
144
|
+
chronos?: {
|
|
145
|
+
batchMs?: number;
|
|
146
|
+
maxBatch?: number;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createPraxisEngine
|
|
3
|
-
} from "./chunk-JZDJU2DO.js";
|
|
4
1
|
import {
|
|
5
2
|
PraxisRegistry
|
|
6
3
|
} from "./chunk-TEMFJOIH.js";
|
|
4
|
+
import {
|
|
5
|
+
createPraxisEngine
|
|
6
|
+
} from "./chunk-JZDJU2DO.js";
|
|
7
7
|
|
|
8
8
|
// src/core/reactive-engine.svelte.ts
|
|
9
9
|
import * as $ from "svelte/internal/client";
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
writeLogicLedgerEntry
|
|
10
10
|
} from "./chunk-7CSWBDFL.js";
|
|
11
11
|
import "./chunk-PGVSB6NR.js";
|
|
12
|
-
import "./chunk-IG5BJ2MT.js";
|
|
13
12
|
import {
|
|
14
13
|
PraxisRegistry
|
|
15
14
|
} from "./chunk-TEMFJOIH.js";
|
|
15
|
+
import "./chunk-IG5BJ2MT.js";
|
|
16
16
|
import "./chunk-QGM4M3NI.js";
|
|
17
17
|
|
|
18
18
|
// src/cli/commands/validate.ts
|