@graphorin/core 0.5.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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/channels/channels.d.ts +156 -0
- package/dist/channels/channels.d.ts.map +1 -0
- package/dist/channels/channels.js +90 -0
- package/dist/channels/channels.js.map +1 -0
- package/dist/channels/directive.d.ts +34 -0
- package/dist/channels/directive.d.ts.map +1 -0
- package/dist/channels/directive.js +29 -0
- package/dist/channels/directive.js.map +1 -0
- package/dist/channels/dispatch.d.ts +26 -0
- package/dist/channels/dispatch.d.ts.map +1 -0
- package/dist/channels/dispatch.js +32 -0
- package/dist/channels/dispatch.js.map +1 -0
- package/dist/channels/index.d.ts +5 -0
- package/dist/channels/index.js +6 -0
- package/dist/channels/pause.d.ts +84 -0
- package/dist/channels/pause.d.ts.map +1 -0
- package/dist/channels/pause.js +90 -0
- package/dist/channels/pause.js.map +1 -0
- package/dist/contracts/auth-token-store.d.ts +45 -0
- package/dist/contracts/auth-token-store.d.ts.map +1 -0
- package/dist/contracts/checkpoint-store.d.ts +90 -0
- package/dist/contracts/checkpoint-store.d.ts.map +1 -0
- package/dist/contracts/embedder.d.ts +45 -0
- package/dist/contracts/embedder.d.ts.map +1 -0
- package/dist/contracts/eval-scorer.d.ts +46 -0
- package/dist/contracts/eval-scorer.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +22 -0
- package/dist/contracts/index.js +6 -0
- package/dist/contracts/local-provider-trust.d.ts +36 -0
- package/dist/contracts/local-provider-trust.d.ts.map +1 -0
- package/dist/contracts/logger.d.ts +53 -0
- package/dist/contracts/logger.d.ts.map +1 -0
- package/dist/contracts/logger.js +21 -0
- package/dist/contracts/logger.js.map +1 -0
- package/dist/contracts/memory-store.d.ts +106 -0
- package/dist/contracts/memory-store.d.ts.map +1 -0
- package/dist/contracts/oauth-server-store.d.ts +81 -0
- package/dist/contracts/oauth-server-store.d.ts.map +1 -0
- package/dist/contracts/preferred-model.d.ts +60 -0
- package/dist/contracts/preferred-model.d.ts.map +1 -0
- package/dist/contracts/preferred-model.js +15 -0
- package/dist/contracts/preferred-model.js.map +1 -0
- package/dist/contracts/provider.d.ts +272 -0
- package/dist/contracts/provider.d.ts.map +1 -0
- package/dist/contracts/reasoning-retention.d.ts +53 -0
- package/dist/contracts/reasoning-retention.d.ts.map +1 -0
- package/dist/contracts/redaction-validator.d.ts +59 -0
- package/dist/contracts/redaction-validator.d.ts.map +1 -0
- package/dist/contracts/sandbox.d.ts +73 -0
- package/dist/contracts/sandbox.d.ts.map +1 -0
- package/dist/contracts/secret-ref.d.ts +26 -0
- package/dist/contracts/secret-ref.d.ts.map +1 -0
- package/dist/contracts/secret-value.d.ts +112 -0
- package/dist/contracts/secret-value.d.ts.map +1 -0
- package/dist/contracts/secret-value.js +24 -0
- package/dist/contracts/secret-value.js.map +1 -0
- package/dist/contracts/secrets-store.d.ts +87 -0
- package/dist/contracts/secrets-store.d.ts.map +1 -0
- package/dist/contracts/session-store.d.ts +142 -0
- package/dist/contracts/session-store.d.ts.map +1 -0
- package/dist/contracts/token-counter.d.ts +28 -0
- package/dist/contracts/token-counter.d.ts.map +1 -0
- package/dist/contracts/tool.d.ts +264 -0
- package/dist/contracts/tool.d.ts.map +1 -0
- package/dist/contracts/tracer.d.ts +84 -0
- package/dist/contracts/tracer.d.ts.map +1 -0
- package/dist/contracts/tracer.js +34 -0
- package/dist/contracts/tracer.js.map +1 -0
- package/dist/contracts/trigger-store.d.ts +43 -0
- package/dist/contracts/trigger-store.d.ts.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/types/agent-event.d.ts +449 -0
- package/dist/types/agent-event.d.ts.map +1 -0
- package/dist/types/handoff.d.ts +112 -0
- package/dist/types/handoff.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +6 -0
- package/dist/types/memory.d.ts +354 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/message.d.ts +162 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/run.d.ts +155 -0
- package/dist/types/run.d.ts.map +1 -0
- package/dist/types/run.js +31 -0
- package/dist/types/run.js.map +1 -0
- package/dist/types/sensitivity.d.ts +35 -0
- package/dist/types/sensitivity.d.ts.map +1 -0
- package/dist/types/sensitivity.js +29 -0
- package/dist/types/sensitivity.js.map +1 -0
- package/dist/types/session-scope.d.ts +22 -0
- package/dist/types/session-scope.d.ts.map +1 -0
- package/dist/types/stop-condition.d.ts +62 -0
- package/dist/types/stop-condition.d.ts.map +1 -0
- package/dist/types/stop-condition.js +81 -0
- package/dist/types/stop-condition.js.map +1 -0
- package/dist/types/tool-call.d.ts +27 -0
- package/dist/types/tool-call.d.ts.map +1 -0
- package/dist/types/tool.d.ts +260 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/usage.d.ts +82 -0
- package/dist/types/usage.d.ts.map +1 -0
- package/dist/types/usage.js +17 -0
- package/dist/types/usage.js.map +1 -0
- package/dist/types/workflow-event.d.ts +108 -0
- package/dist/types/workflow-event.d.ts.map +1 -0
- package/dist/utils/assert-never.d.ts +26 -0
- package/dist/utils/assert-never.d.ts.map +1 -0
- package/dist/utils/assert-never.js +29 -0
- package/dist/utils/assert-never.js.map +1 -0
- package/dist/utils/async-context.d.ts +37 -0
- package/dist/utils/async-context.d.ts.map +1 -0
- package/dist/utils/async-context.js +33 -0
- package/dist/utils/async-context.js.map +1 -0
- package/dist/utils/hash.d.ts +30 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +102 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/streams.d.ts +59 -0
- package/dist/utils/streams.d.ts.map +1 -0
- package/dist/utils/streams.js +169 -0
- package/dist/utils/streams.js.map +1 -0
- package/dist/utils/validation.d.ts +67 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +36 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
//#region src/utils/streams.ts
|
|
2
|
+
/**
|
|
3
|
+
* Stream / async-iterable helpers. All helpers honor `AbortSignal`
|
|
4
|
+
* propagation: when the supplied signal aborts, the underlying
|
|
5
|
+
* iterator's `return()` method is invoked so that resources held by the
|
|
6
|
+
* upstream generator are released cleanly.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Internal helper: detect whether `it` already has its own
|
|
12
|
+
* `AsyncIterator.return` so we know whether to forward cancellations.
|
|
13
|
+
*/
|
|
14
|
+
function hasReturn(iter) {
|
|
15
|
+
return typeof iter.return === "function";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Drain an `AsyncIterable` into an array.
|
|
19
|
+
*
|
|
20
|
+
* @stable
|
|
21
|
+
*/
|
|
22
|
+
async function collect(source, signal) {
|
|
23
|
+
const out = [];
|
|
24
|
+
for await (const item of withSignal(source, signal)) out.push(item);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Map every value of an async iterable. The mapper may be async.
|
|
29
|
+
* Cancellation via `signal` is honored.
|
|
30
|
+
*
|
|
31
|
+
* @stable
|
|
32
|
+
*/
|
|
33
|
+
async function* mapStream(source, fn, signal) {
|
|
34
|
+
let index = 0;
|
|
35
|
+
for await (const item of withSignal(source, signal)) yield await fn(item, index++);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Filter values produced by `source`. The predicate may be async.
|
|
39
|
+
*
|
|
40
|
+
* @stable
|
|
41
|
+
*/
|
|
42
|
+
async function* filter(source, pred, signal) {
|
|
43
|
+
let index = 0;
|
|
44
|
+
for await (const item of withSignal(source, signal)) if (await pred(item, index++)) yield item;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Take the first `n` items.
|
|
48
|
+
*
|
|
49
|
+
* @stable
|
|
50
|
+
*/
|
|
51
|
+
async function* take(source, n, signal) {
|
|
52
|
+
if (n <= 0) return;
|
|
53
|
+
let i = 0;
|
|
54
|
+
for await (const item of withSignal(source, signal)) {
|
|
55
|
+
yield item;
|
|
56
|
+
if (++i >= n) return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Take items as long as `pred` returns truthy. The first item for which
|
|
61
|
+
* `pred` returns falsy ends the stream.
|
|
62
|
+
*
|
|
63
|
+
* @stable
|
|
64
|
+
*/
|
|
65
|
+
async function* takeWhile(source, pred, signal) {
|
|
66
|
+
let index = 0;
|
|
67
|
+
for await (const item of withSignal(source, signal)) {
|
|
68
|
+
if (!await pred(item, index++)) return;
|
|
69
|
+
yield item;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Merge multiple async iterables into a single output iterable. Items
|
|
74
|
+
* are yielded in the order they arrive (interleaved), not in source
|
|
75
|
+
* order. Cancellation propagates to every upstream iterator.
|
|
76
|
+
*
|
|
77
|
+
* @stable
|
|
78
|
+
*/
|
|
79
|
+
async function* merge(sources, signal) {
|
|
80
|
+
if (sources.length === 0) return;
|
|
81
|
+
const pending = sources.map((s) => s[Symbol.asyncIterator]()).map((iter, index) => ({
|
|
82
|
+
iter,
|
|
83
|
+
index,
|
|
84
|
+
promise: iter.next()
|
|
85
|
+
}));
|
|
86
|
+
const onAbort = async () => {
|
|
87
|
+
await Promise.all(pending.map(async (p) => {
|
|
88
|
+
if (p && hasReturn(p.iter)) try {
|
|
89
|
+
await p.iter.return(void 0);
|
|
90
|
+
} catch {}
|
|
91
|
+
}));
|
|
92
|
+
};
|
|
93
|
+
if (signal?.aborted) {
|
|
94
|
+
await onAbort();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const abortListener = () => {
|
|
98
|
+
onAbort();
|
|
99
|
+
};
|
|
100
|
+
signal?.addEventListener("abort", abortListener, { once: true });
|
|
101
|
+
try {
|
|
102
|
+
while (pending.some((p) => p !== null)) {
|
|
103
|
+
if (signal?.aborted) return;
|
|
104
|
+
const live = pending.filter((p) => p !== null);
|
|
105
|
+
const winner = await Promise.race(live.map(async (p) => ({
|
|
106
|
+
p,
|
|
107
|
+
result: await p.promise
|
|
108
|
+
})));
|
|
109
|
+
if (winner.result.done) {
|
|
110
|
+
pending[winner.p.index] = null;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
yield winner.result.value;
|
|
114
|
+
pending[winner.p.index] = {
|
|
115
|
+
...winner.p,
|
|
116
|
+
promise: winner.p.iter.next()
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
} finally {
|
|
120
|
+
signal?.removeEventListener("abort", abortListener);
|
|
121
|
+
await Promise.all(pending.map(async (p) => {
|
|
122
|
+
if (p && hasReturn(p.iter)) try {
|
|
123
|
+
await p.iter.return(void 0);
|
|
124
|
+
} catch {}
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Wrap `source` with abort-signal propagation: when `signal` aborts the
|
|
130
|
+
* underlying iterator's `return()` is called and the loop exits cleanly.
|
|
131
|
+
*
|
|
132
|
+
* @stable
|
|
133
|
+
*/
|
|
134
|
+
async function* withSignal(source, signal) {
|
|
135
|
+
if (!signal) {
|
|
136
|
+
yield* source;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (signal.aborted) return;
|
|
140
|
+
const iter = source[Symbol.asyncIterator]();
|
|
141
|
+
let abortListener = null;
|
|
142
|
+
const abortPromise = new Promise((resolve) => {
|
|
143
|
+
abortListener = () => resolve({ aborted: true });
|
|
144
|
+
signal.addEventListener("abort", abortListener, { once: true });
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
while (true) {
|
|
148
|
+
const next = iter.next();
|
|
149
|
+
const winner = await Promise.race([next.then((r) => ({
|
|
150
|
+
aborted: false,
|
|
151
|
+
result: r
|
|
152
|
+
})), abortPromise]);
|
|
153
|
+
if (winner.aborted) {
|
|
154
|
+
if (hasReturn(iter)) try {
|
|
155
|
+
await iter.return(void 0);
|
|
156
|
+
} catch {}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (winner.result.done) return;
|
|
160
|
+
yield winner.result.value;
|
|
161
|
+
}
|
|
162
|
+
} finally {
|
|
163
|
+
if (abortListener) signal.removeEventListener("abort", abortListener);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
export { collect, filter, mapStream, merge, take, takeWhile, withSignal };
|
|
169
|
+
//# sourceMappingURL=streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.js","names":["out: T[]","pending: Array<Pending | null>","abortListener: (() => void) | null"],"sources":["../../src/utils/streams.ts"],"sourcesContent":["/**\n * Stream / async-iterable helpers. All helpers honor `AbortSignal`\n * propagation: when the supplied signal aborts, the underlying\n * iterator's `return()` method is invoked so that resources held by the\n * upstream generator are released cleanly.\n *\n * @packageDocumentation\n */\n\n/**\n * Internal helper: detect whether `it` already has its own\n * `AsyncIterator.return` so we know whether to forward cancellations.\n */\nfunction hasReturn<T>(\n iter: AsyncIterator<T>,\n): iter is AsyncIterator<T> & { return: NonNullable<AsyncIterator<T>['return']> } {\n return typeof iter.return === 'function';\n}\n\n/**\n * Drain an `AsyncIterable` into an array.\n *\n * @stable\n */\nexport async function collect<T>(source: AsyncIterable<T>, signal?: AbortSignal): Promise<T[]> {\n const out: T[] = [];\n for await (const item of withSignal(source, signal)) {\n out.push(item);\n }\n return out;\n}\n\n/**\n * Map every value of an async iterable. The mapper may be async.\n * Cancellation via `signal` is honored.\n *\n * @stable\n */\nexport async function* mapStream<T, U>(\n source: AsyncIterable<T>,\n fn: (value: T, index: number) => U | Promise<U>,\n signal?: AbortSignal,\n): AsyncIterable<U> {\n let index = 0;\n for await (const item of withSignal(source, signal)) {\n yield await fn(item, index++);\n }\n}\n\n/**\n * Filter values produced by `source`. The predicate may be async.\n *\n * @stable\n */\nexport async function* filter<T>(\n source: AsyncIterable<T>,\n pred: (value: T, index: number) => boolean | Promise<boolean>,\n signal?: AbortSignal,\n): AsyncIterable<T> {\n let index = 0;\n for await (const item of withSignal(source, signal)) {\n if (await pred(item, index++)) yield item;\n }\n}\n\n/**\n * Take the first `n` items.\n *\n * @stable\n */\nexport async function* take<T>(\n source: AsyncIterable<T>,\n n: number,\n signal?: AbortSignal,\n): AsyncIterable<T> {\n if (n <= 0) return;\n let i = 0;\n for await (const item of withSignal(source, signal)) {\n yield item;\n if (++i >= n) return;\n }\n}\n\n/**\n * Take items as long as `pred` returns truthy. The first item for which\n * `pred` returns falsy ends the stream.\n *\n * @stable\n */\nexport async function* takeWhile<T>(\n source: AsyncIterable<T>,\n pred: (value: T, index: number) => boolean | Promise<boolean>,\n signal?: AbortSignal,\n): AsyncIterable<T> {\n let index = 0;\n for await (const item of withSignal(source, signal)) {\n if (!(await pred(item, index++))) return;\n yield item;\n }\n}\n\n/**\n * Merge multiple async iterables into a single output iterable. Items\n * are yielded in the order they arrive (interleaved), not in source\n * order. Cancellation propagates to every upstream iterator.\n *\n * @stable\n */\nexport async function* merge<T>(\n sources: ReadonlyArray<AsyncIterable<T>>,\n signal?: AbortSignal,\n): AsyncIterable<T> {\n if (sources.length === 0) return;\n\n const iterators = sources.map((s) => s[Symbol.asyncIterator]());\n type Pending = { iter: AsyncIterator<T>; index: number; promise: Promise<IteratorResult<T>> };\n const pending: Array<Pending | null> = iterators.map((iter, index) => ({\n iter,\n index,\n promise: iter.next(),\n }));\n\n const onAbort = async (): Promise<void> => {\n await Promise.all(\n pending.map(async (p) => {\n if (p && hasReturn(p.iter)) {\n try {\n await p.iter.return(undefined);\n } catch {\n // Suppress: we are cancelling regardless.\n }\n }\n }),\n );\n };\n\n if (signal?.aborted) {\n await onAbort();\n return;\n }\n\n const abortListener = (): void => {\n void onAbort();\n };\n signal?.addEventListener('abort', abortListener, { once: true });\n\n try {\n while (pending.some((p) => p !== null)) {\n if (signal?.aborted) return;\n\n // Race only the still-active iterators.\n const live = pending.filter((p): p is Pending => p !== null);\n const winner = await Promise.race(live.map(async (p) => ({ p, result: await p.promise })));\n\n if (winner.result.done) {\n pending[winner.p.index] = null;\n continue;\n }\n\n yield winner.result.value;\n\n // Re-prime the winning iterator.\n pending[winner.p.index] = {\n ...winner.p,\n promise: winner.p.iter.next(),\n };\n }\n } finally {\n signal?.removeEventListener('abort', abortListener);\n // Flush any remaining iterators.\n await Promise.all(\n pending.map(async (p) => {\n if (p && hasReturn(p.iter)) {\n try {\n await p.iter.return(undefined);\n } catch {\n // Suppress.\n }\n }\n }),\n );\n }\n}\n\n/**\n * Wrap `source` with abort-signal propagation: when `signal` aborts the\n * underlying iterator's `return()` is called and the loop exits cleanly.\n *\n * @stable\n */\nexport async function* withSignal<T>(\n source: AsyncIterable<T>,\n signal?: AbortSignal,\n): AsyncIterable<T> {\n if (!signal) {\n yield* source;\n return;\n }\n if (signal.aborted) return;\n\n const iter = source[Symbol.asyncIterator]();\n let abortListener: (() => void) | null = null;\n\n const abortPromise = new Promise<{ aborted: true }>((resolve) => {\n abortListener = (): void => resolve({ aborted: true });\n signal.addEventListener('abort', abortListener, { once: true });\n });\n\n try {\n while (true) {\n const next = iter.next();\n const winner = await Promise.race([\n next.then((r) => ({ aborted: false as const, result: r })),\n abortPromise,\n ]);\n\n if (winner.aborted) {\n if (hasReturn(iter)) {\n try {\n await iter.return(undefined);\n } catch {\n // Suppress.\n }\n }\n return;\n }\n if (winner.result.done) return;\n yield winner.result.value;\n }\n } finally {\n if (abortListener) signal.removeEventListener('abort', abortListener);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,UACP,MACgF;AAChF,QAAO,OAAO,KAAK,WAAW;;;;;;;AAQhC,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AO,SAAS;AAClB,QAAI,UAAU,KAAK,CACjB,KAAI;AACF,WAAM,KAAK,OAAO,OAAU;YACtB;AAIV;;AAEF,OAAI,OAAO,OAAO,KAAM;AACxB,SAAM,OAAO,OAAO;;WAEd;AACR,MAAI,cAAe,QAAO,oBAAoB,SAAS,cAAc"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/utils/validation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type-only Zod compatibility shim. We declare a structural type for the
|
|
4
|
+
* subset of `zod` we depend on so that `@graphorin/core` can be type-
|
|
5
|
+
* checked without importing zod directly. Consumers that do `import {
|
|
6
|
+
* z } from 'zod'` get the real types via the user's `zod` install (the
|
|
7
|
+
* peer dependency).
|
|
8
|
+
*
|
|
9
|
+
* @stable
|
|
10
|
+
*/
|
|
11
|
+
interface ZodLikeSchema<TOutput = unknown, TInput = unknown> {
|
|
12
|
+
parse(data: unknown): TOutput;
|
|
13
|
+
safeParse(data: unknown): ZodLikeSafeParseResult<TOutput, TInput>;
|
|
14
|
+
/** Internal phantom used by Zod for inference. We don't dereference it. */
|
|
15
|
+
readonly _output?: TOutput;
|
|
16
|
+
readonly _input?: TInput;
|
|
17
|
+
}
|
|
18
|
+
/** @stable */
|
|
19
|
+
type ZodLikeSafeParseResult<TOutput, TInput> = {
|
|
20
|
+
readonly success: true;
|
|
21
|
+
readonly data: TOutput;
|
|
22
|
+
} | {
|
|
23
|
+
readonly success: false;
|
|
24
|
+
readonly error: ZodLikeError<TInput>;
|
|
25
|
+
};
|
|
26
|
+
/** @stable */
|
|
27
|
+
interface ZodLikeError<_TInput = unknown> {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
readonly issues: ReadonlyArray<{
|
|
31
|
+
readonly path: ReadonlyArray<string | number>;
|
|
32
|
+
readonly message: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validate `data` against `schema` and return a `Result` instead of
|
|
37
|
+
* throwing. Use this in code paths where you want explicit
|
|
38
|
+
* pattern-matching over success / failure.
|
|
39
|
+
*
|
|
40
|
+
* @stable
|
|
41
|
+
*/
|
|
42
|
+
type ValidationResult<T> = {
|
|
43
|
+
readonly ok: true;
|
|
44
|
+
readonly value: T;
|
|
45
|
+
} | {
|
|
46
|
+
readonly ok: false;
|
|
47
|
+
readonly error: ZodLikeError;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Synchronous validation wrapper. Does **not** swallow errors thrown by
|
|
51
|
+
* the schema's transformations — only normalizes the success / failure
|
|
52
|
+
* signal.
|
|
53
|
+
*
|
|
54
|
+
* @stable
|
|
55
|
+
*/
|
|
56
|
+
declare function validate<T>(schema: ZodLikeSchema<T>, data: unknown): ValidationResult<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Throwing variant of `validate(...)` that surfaces a `TypeError` carrying
|
|
59
|
+
* a stable, parser-style message. Useful at module-boundary entry points
|
|
60
|
+
* where a thrown error is the natural failure mode.
|
|
61
|
+
*
|
|
62
|
+
* @stable
|
|
63
|
+
*/
|
|
64
|
+
declare function validateOrThrow<T>(schema: ZodLikeSchema<T>, data: unknown, what?: string): T;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { ValidationResult, ZodLikeError, ZodLikeSafeParseResult, ZodLikeSchema, validate, validateOrThrow };
|
|
67
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","names":[],"sources":["../../src/utils/validation.ts"],"sourcesContent":[],"mappings":";;AASA;;;;;;;;AASY,UATK,aASiB,CAAA,UAAA,OAAA,EAAA,SAAA,OAAA,CAAA,CAAA;EACW,KAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EATrB,OASqB;EACe,SAAA,CAAA,IAAA,EAAA,OAAA,CAAA,EAThC,sBASgC,CATT,OASS,EATA,MASA,CAAA;EAAb;EAAY,SAAA,OAAA,CAAA,EAPtC,OAOsC;EAG1C,SAAA,MAAY,CAAA,EATT,MASS;AAgB7B;AAWA;AAAkD,KAhCtC,sBAgCsC,CAAA,OAAA,EAAA,MAAA,CAAA,GAAA;EAAd,SAAA,OAAA,EAAA,IAAA;EAAmD,SAAA,IAAA,EA/B1C,OA+B0C;CAAjB,GAAA;EAAgB,SAAA,OAAA,EAAA,KAAA;EAatE,SAAA,KAAA,EA3C+B,YA2ChB,CA3C6B,MA2C7B,CAAA;CAA0B;;AAAmC,UAxC3E,YAwC2E,CAAA,UAAA,OAAA,CAAA,CAAA;EAAC,SAAA,IAAA,EAAA,MAAA;;mBArC1E;mBACA;;;;;;;;;;;KAYP;;kBAC6B;;;kBACC;;;;;;;;;iBAS1B,oBAAoB,cAAc,oBAAoB,iBAAiB;;;;;;;;iBAavE,2BAA2B,cAAc,mCAAmC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/utils/validation.ts
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous validation wrapper. Does **not** swallow errors thrown by
|
|
4
|
+
* the schema's transformations — only normalizes the success / failure
|
|
5
|
+
* signal.
|
|
6
|
+
*
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
function validate(schema, data) {
|
|
10
|
+
const result = schema.safeParse(data);
|
|
11
|
+
if (result.success) return {
|
|
12
|
+
ok: true,
|
|
13
|
+
value: result.data
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
ok: false,
|
|
17
|
+
error: result.error
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Throwing variant of `validate(...)` that surfaces a `TypeError` carrying
|
|
22
|
+
* a stable, parser-style message. Useful at module-boundary entry points
|
|
23
|
+
* where a thrown error is the natural failure mode.
|
|
24
|
+
*
|
|
25
|
+
* @stable
|
|
26
|
+
*/
|
|
27
|
+
function validateOrThrow(schema, data, what) {
|
|
28
|
+
const r = validate(schema, data);
|
|
29
|
+
if (r.ok) return r.value;
|
|
30
|
+
const summary = r.error.issues.map((i) => `${i.path.join(".") || "."}: ${i.message}`).join("; ");
|
|
31
|
+
throw new TypeError(`graphorin: validation failed${what ? ` for ${what}` : ""}: ${summary}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { validate, validateOrThrow };
|
|
36
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","names":[],"sources":["../../src/utils/validation.ts"],"sourcesContent":["/**\n * Type-only Zod compatibility shim. We declare a structural type for the\n * subset of `zod` we depend on so that `@graphorin/core` can be type-\n * checked without importing zod directly. Consumers that do `import {\n * z } from 'zod'` get the real types via the user's `zod` install (the\n * peer dependency).\n *\n * @stable\n */\nexport interface ZodLikeSchema<TOutput = unknown, TInput = unknown> {\n parse(data: unknown): TOutput;\n safeParse(data: unknown): ZodLikeSafeParseResult<TOutput, TInput>;\n /** Internal phantom used by Zod for inference. We don't dereference it. */\n readonly _output?: TOutput;\n readonly _input?: TInput;\n}\n\n/** @stable */\nexport type ZodLikeSafeParseResult<TOutput, TInput> =\n | { readonly success: true; readonly data: TOutput }\n | { readonly success: false; readonly error: ZodLikeError<TInput> };\n\n/** @stable */\nexport interface ZodLikeError<_TInput = unknown> {\n readonly name: string;\n readonly message: string;\n readonly issues: ReadonlyArray<{\n readonly path: ReadonlyArray<string | number>;\n readonly message: string;\n }>;\n}\n\n/**\n * Validate `data` against `schema` and return a `Result` instead of\n * throwing. Use this in code paths where you want explicit\n * pattern-matching over success / failure.\n *\n * @stable\n */\nexport type ValidationResult<T> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly error: ZodLikeError };\n\n/**\n * Synchronous validation wrapper. Does **not** swallow errors thrown by\n * the schema's transformations — only normalizes the success / failure\n * signal.\n *\n * @stable\n */\nexport function validate<T>(schema: ZodLikeSchema<T>, data: unknown): ValidationResult<T> {\n const result = schema.safeParse(data);\n if (result.success) return { ok: true, value: result.data };\n return { ok: false, error: result.error };\n}\n\n/**\n * Throwing variant of `validate(...)` that surfaces a `TypeError` carrying\n * a stable, parser-style message. Useful at module-boundary entry points\n * where a thrown error is the natural failure mode.\n *\n * @stable\n */\nexport function validateOrThrow<T>(schema: ZodLikeSchema<T>, data: unknown, what?: string): T {\n const r = validate(schema, data);\n if (r.ok) return r.value;\n const summary = r.error.issues.map((i) => `${i.path.join('.') || '.'}: ${i.message}`).join('; ');\n throw new TypeError(`graphorin: validation failed${what ? ` for ${what}` : ''}: ${summary}`);\n}\n"],"mappings":";;;;;;;;AAkDA,SAAgB,SAAY,QAA0B,MAAoC;CACxF,MAAM,SAAS,OAAO,UAAU,KAAK;AACrC,KAAI,OAAO,QAAS,QAAO;EAAE,IAAI;EAAM,OAAO,OAAO;EAAM;AAC3D,QAAO;EAAE,IAAI;EAAO,OAAO,OAAO;EAAO;;;;;;;;;AAU3C,SAAgB,gBAAmB,QAA0B,MAAe,MAAkB;CAC5F,MAAM,IAAI,SAAS,QAAQ,KAAK;AAChC,KAAI,EAAE,GAAI,QAAO,EAAE;CACnB,MAAM,UAAU,EAAE,MAAM,OAAO,KAAK,MAAM,GAAG,EAAE,KAAK,KAAK,IAAI,IAAI,IAAI,IAAI,EAAE,UAAU,CAAC,KAAK,KAAK;AAChG,OAAM,IAAI,UAAU,+BAA+B,OAAO,QAAQ,SAAS,GAAG,IAAI,UAAU"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphorin/core",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Core types, contracts, and utilities for the Graphorin framework. Dependency-free root package every other @graphorin/* package depends on.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Oleksiy Stepurenko",
|
|
7
|
+
"homepage": "https://github.com/o-stepper/graphorin/tree/main/packages/core",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/o-stepper/graphorin.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/o-stepper/graphorin/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"graphorin",
|
|
18
|
+
"ai",
|
|
19
|
+
"agents",
|
|
20
|
+
"framework",
|
|
21
|
+
"types",
|
|
22
|
+
"contracts"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./types": {
|
|
37
|
+
"types": "./dist/types/index.d.ts",
|
|
38
|
+
"import": "./dist/types/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./contracts": {
|
|
41
|
+
"types": "./dist/contracts/index.d.ts",
|
|
42
|
+
"import": "./dist/contracts/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./utils": {
|
|
45
|
+
"types": "./dist/utils/index.d.ts",
|
|
46
|
+
"import": "./dist/utils/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./channels": {
|
|
49
|
+
"types": "./dist/channels/index.d.ts",
|
|
50
|
+
"import": "./dist/channels/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"README.md",
|
|
57
|
+
"CHANGELOG.md",
|
|
58
|
+
"LICENSE"
|
|
59
|
+
],
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"zod": "^3.23.0 || ^4.0.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"zod": {
|
|
65
|
+
"optional": false
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public",
|
|
70
|
+
"provenance": true
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"zod": "^3.25.0"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsdown",
|
|
77
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"lint": "biome check .",
|
|
80
|
+
"clean": "rimraf dist .turbo *.tsbuildinfo"
|
|
81
|
+
}
|
|
82
|
+
}
|