@atolljs/core 0.1.2 → 0.1.3
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/LICENSE +21 -0
- package/README.md +4 -5
- package/dist/contract/listSchema.d.ts +4 -4
- package/dist/contract/reef.d.ts +377 -0
- package/dist/contract/sharedMemory.d.ts +13 -13
- package/dist/contract/zod.d.ts +263 -34
- package/dist/index.d.ts +1 -2
- package/dist/index.js +14 -15
- package/dist/index10.js +185 -14
- package/dist/index11.js +47 -188
- package/dist/index12.js +59 -45
- package/dist/index13.js +19 -58
- package/dist/index14.js +60 -24
- package/dist/index15.js +43 -56
- package/dist/index16.js +41 -45
- package/dist/index17.js +38 -42
- package/dist/index18.js +54 -35
- package/dist/index19.js +46 -51
- package/dist/index20.js +50 -47
- package/dist/index3.js +199 -22
- package/dist/index4.js +66 -61
- package/dist/index6.js +84 -84
- package/dist/index7.js +19 -19
- package/dist/index8.js +33 -6
- package/dist/index9.js +14 -29
- package/package.json +7 -6
- package/src/contract/listSchema.ts +51 -29
- package/src/contract/reef.ts +62 -0
- package/src/contract/sharedMemory.ts +25 -25
- package/src/contract/zod.ts +344 -32
- package/src/index.ts +1 -2
- package/dist/contract/msgpackCodec.d.ts +0 -7
- package/dist/contract/mz.d.ts +0 -43
- package/dist/index21.js +0 -59
- package/src/contract/msgpackCodec.ts +0 -9
- package/src/contract/mz.ts +0 -48
package/src/contract/zod.ts
CHANGED
|
@@ -1,44 +1,356 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The SDK's vendored
|
|
3
|
-
*
|
|
2
|
+
* The SDK's vendored schema engine — the slice of zod v4 the contract layer
|
|
3
|
+
* needs, implemented in-house so zod never lands in the dependency tree.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Schemas carry zod's `_zod.def` shape (`type`, `format`, `checks`,
|
|
6
|
+
* `shape`, `element`) and check defs use zod's names (`greater_than`,
|
|
7
|
+
* `number_format`, `max_length`, `length_equals`, …). The layout compiler
|
|
8
|
+
* reads those fields duck-typed — never `instanceof` — so consumer-supplied
|
|
9
|
+
* classic zod and zod/mini schemas introspect identically: `z.uint32()`,
|
|
10
|
+
* `z.object(...)`, `z.string().meta({ bytes: n })` all still work as
|
|
11
|
+
* members/field schemas.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `z.object(...)`.
|
|
13
|
+
* Chain methods mini omits (`.refine()`, `.meta()`, `.max()` …) are
|
|
14
|
+
* re-attached to atoll-minted schemas by `fluent()` — `reef`, `listSchema`,
|
|
15
|
+
* `memory.schemas`. Refines attach via `.check()` so the schema's
|
|
16
|
+
* `def.type` survives — a refined `reef.string` still lays out as a
|
|
17
|
+
* fixed-width string.
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
|
|
20
|
+
/* ------------------------------------------------------------------ */
|
|
21
|
+
/* Checks */
|
|
22
|
+
/* ------------------------------------------------------------------ */
|
|
23
|
+
|
|
24
|
+
/** Check def payloads mirror zod v4's `_zod.check.def` shapes. */
|
|
25
|
+
export interface CheckDef {
|
|
26
|
+
check: string;
|
|
27
|
+
value?: number | bigint;
|
|
28
|
+
inclusive?: boolean;
|
|
29
|
+
format?: string;
|
|
30
|
+
maximum?: number;
|
|
31
|
+
minimum?: number;
|
|
32
|
+
length?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Check {
|
|
36
|
+
readonly _zod: { readonly def: CheckDef };
|
|
37
|
+
/** Returns `true` or a failure message. */
|
|
38
|
+
evaluate(value: unknown): true | string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const check = (def: CheckDef, evaluate: Check['evaluate']): Check => ({
|
|
42
|
+
_zod: { def }, evaluate,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const int32min = -2147483648, int32max = 2147483647;
|
|
46
|
+
|
|
47
|
+
const int = () => check({ check: 'number_format', format: 'safeint' }, (v) =>
|
|
48
|
+
Number.isInteger(v) || 'expected an integer');
|
|
49
|
+
const gte = (value: number | bigint) =>
|
|
50
|
+
check({ check: 'greater_than', value, inclusive: true }, (v) =>
|
|
51
|
+
(v as number) >= value || `expected >= ${value}`);
|
|
52
|
+
const lte = (value: number | bigint) =>
|
|
53
|
+
check({ check: 'less_than', value, inclusive: true }, (v) =>
|
|
54
|
+
(v as number) <= value || `expected <= ${value}`);
|
|
55
|
+
const nonnegative = () => gte(0 as number | bigint);
|
|
56
|
+
const refine = (fn: (v: any) => unknown, message?: string) =>
|
|
57
|
+
check({ check: 'custom' }, (v) => !!fn(v) || (message ?? 'failed custom check'));
|
|
58
|
+
const length = (n: number) =>
|
|
59
|
+
check({ check: 'length_equals', length: n }, (v) =>
|
|
60
|
+
(v as { length: number }).length === n || `expected exactly ${n} items`);
|
|
61
|
+
const maxLength = (n: number) =>
|
|
62
|
+
check({ check: 'max_length', maximum: n }, (v) =>
|
|
63
|
+
(v as { length: number }).length <= n || `expected <=${n} items`);
|
|
64
|
+
const minLength = (n: number) =>
|
|
65
|
+
check({ check: 'min_length', minimum: n }, (v) =>
|
|
66
|
+
(v as { length: number }).length >= n || `expected >=${n} items`);
|
|
67
|
+
const intRange = (format: string, min: number, max: number) =>
|
|
68
|
+
check({ check: 'number_format', format }, (v) =>
|
|
69
|
+
(Number.isInteger(v) && (v as number) >= min && (v as number) <= max) ||
|
|
70
|
+
`expected a ${format}`);
|
|
71
|
+
const int64Range = (format: string, min: bigint, max: bigint) =>
|
|
72
|
+
check({ check: 'bigint_format', format }, (v) =>
|
|
73
|
+
((v as bigint) >= min && (v as bigint) <= max) || `expected a ${format}`);
|
|
74
|
+
|
|
75
|
+
/* ------------------------------------------------------------------ */
|
|
76
|
+
/* Registry — `.meta()` storage, mirrors zod's globalRegistry */
|
|
77
|
+
/* ------------------------------------------------------------------ */
|
|
78
|
+
|
|
79
|
+
const registryStore = new WeakMap<object, Record<string, unknown>>();
|
|
80
|
+
|
|
81
|
+
export const globalRegistry = {
|
|
82
|
+
add(schema: object, meta: Record<string, unknown>) {
|
|
83
|
+
registryStore.set(schema, meta);
|
|
84
|
+
},
|
|
85
|
+
get(schema: object): Record<string, unknown> | undefined {
|
|
86
|
+
return registryStore.get(schema);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
export type Registry = typeof globalRegistry;
|
|
90
|
+
|
|
91
|
+
/* ------------------------------------------------------------------ */
|
|
92
|
+
/* Schema base + concrete kinds */
|
|
93
|
+
/* ------------------------------------------------------------------ */
|
|
94
|
+
|
|
95
|
+
export interface SchemaDef {
|
|
96
|
+
type: string;
|
|
97
|
+
checks?: Check[];
|
|
98
|
+
format?: string;
|
|
99
|
+
shape?: Record<string, ZodLike>;
|
|
100
|
+
element?: ZodLike;
|
|
101
|
+
cls?: abstract new (...args: any[]) => unknown;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export class SchemaError extends Error {
|
|
105
|
+
override readonly name = 'SchemaError';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The minimal schema shape — satisfied by ours and by real zod schemas. */
|
|
109
|
+
export interface ZodLike<Output = unknown, Input = Output> {
|
|
110
|
+
readonly _zod: {
|
|
111
|
+
readonly output: Output;
|
|
112
|
+
readonly input: Input;
|
|
113
|
+
readonly def: { readonly type?: string; readonly checks?: readonly unknown[] };
|
|
114
|
+
};
|
|
115
|
+
parse(value: unknown): Output;
|
|
116
|
+
safeParse(value: unknown):
|
|
117
|
+
| { success: true; data: Output }
|
|
118
|
+
| { success: false; error: unknown };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export abstract class ZodType<Output = unknown, Input = Output>
|
|
122
|
+
implements ZodLike<Output, Input> {
|
|
123
|
+
readonly _zod: { output: Output; input: Input; def: SchemaDef };
|
|
124
|
+
|
|
125
|
+
constructor(def: SchemaDef) {
|
|
126
|
+
this._zod = { def } as { output: Output; input: Input; def: SchemaDef };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Base-kind check — subclasses enforce the primitive before checks run. */
|
|
130
|
+
abstract inner(value: unknown): Output;
|
|
131
|
+
|
|
132
|
+
parse(value: unknown): Output {
|
|
133
|
+
const parsed = this.inner(value);
|
|
134
|
+
for (const c of this._zod.def.checks ?? []) {
|
|
135
|
+
const r = c.evaluate(parsed);
|
|
136
|
+
if (r !== true) throw new SchemaError(r);
|
|
137
|
+
}
|
|
138
|
+
return parsed;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
safeParse(value: unknown):
|
|
142
|
+
| { success: true; data: Output }
|
|
143
|
+
| { success: false; error: unknown } {
|
|
144
|
+
try {
|
|
145
|
+
return { success: true, data: this.parse(value) };
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return { success: false, error };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Returns a new schema with the checks appended (def.type unchanged). */
|
|
152
|
+
check(...checks: Check[]): this {
|
|
153
|
+
const clone = Object.create(Object.getPrototypeOf(this)) as this;
|
|
154
|
+
const def = { ...this._zod.def, checks: [...(this._zod.def.checks ?? []), ...checks] };
|
|
155
|
+
(clone as { _zod: unknown })._zod = { def };
|
|
156
|
+
// Meta is per-instance but shouldn't die across a check-chain clone.
|
|
157
|
+
const meta = globalRegistry.get(this);
|
|
158
|
+
if (meta) globalRegistry.add(clone, meta);
|
|
159
|
+
return clone;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
register(registry: Registry, meta: Record<string, unknown>): this {
|
|
163
|
+
registry.add(this, meta);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const fail = (expected: string): never => {
|
|
169
|
+
throw new SchemaError(`expected ${expected}`);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
class ZodNumber extends ZodType<number> {
|
|
173
|
+
declare readonly _zod: { output: number; input: number; def: SchemaDef & { type: 'number' } };
|
|
174
|
+
inner(v: unknown): number {
|
|
175
|
+
return typeof v === 'number' && !Number.isNaN(v) ? v : fail('number');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
class ZodString extends ZodType<string> {
|
|
179
|
+
declare readonly _zod: { output: string; input: string; def: SchemaDef & { type: 'string' } };
|
|
180
|
+
inner(v: unknown): string {
|
|
181
|
+
return typeof v === 'string' ? v : fail('string');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
class ZodBoolean extends ZodType<boolean> {
|
|
185
|
+
declare readonly _zod: { output: boolean; input: boolean; def: SchemaDef & { type: 'boolean' } };
|
|
186
|
+
inner(v: unknown): boolean {
|
|
187
|
+
return typeof v === 'boolean' ? v : fail('boolean');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
class ZodBigint extends ZodType<bigint> {
|
|
191
|
+
declare readonly _zod: { output: bigint; input: bigint; def: SchemaDef & { type: 'bigint' } };
|
|
192
|
+
inner(v: unknown): bigint {
|
|
193
|
+
return typeof v === 'bigint' ? v : fail('bigint');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class ZodUnknown extends ZodType<unknown> {
|
|
197
|
+
inner(v: unknown): unknown {
|
|
198
|
+
return v;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
class ZodInstanceof<T> extends ZodType<T> {
|
|
202
|
+
inner(v: unknown): T {
|
|
203
|
+
const cls = this._zod.def.cls!;
|
|
204
|
+
return v instanceof cls ? (v as T) : fail(cls.name ?? 'instance');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
type ShapeOutput<S extends Record<string, ZodLike>> = {
|
|
209
|
+
[K in keyof S]: S[K] extends { _zod: { output: infer O } } ? O : never;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/** Strips unknown keys like zod's object parse — output is the shape only. */
|
|
213
|
+
class ZodObjectSchema<S extends Record<string, ZodLike>> extends ZodType<ShapeOutput<S>> {
|
|
214
|
+
declare readonly _zod: {
|
|
215
|
+
output: ShapeOutput<S>; input: ShapeOutput<S>;
|
|
216
|
+
def: SchemaDef & { type: 'object'; shape: S };
|
|
217
|
+
};
|
|
218
|
+
get shape(): S {
|
|
219
|
+
return this._zod.def.shape;
|
|
220
|
+
}
|
|
221
|
+
inner(v: unknown): ShapeOutput<S> {
|
|
222
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v)) fail('object');
|
|
223
|
+
const out: Record<string, unknown> = {};
|
|
224
|
+
for (const [k, member] of Object.entries(this.shape)) {
|
|
225
|
+
out[k] = member.parse((v as Record<string, unknown>)[k]);
|
|
226
|
+
}
|
|
227
|
+
return out as ShapeOutput<S>;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
class ZodArraySchema<E extends ZodLike> extends ZodType<OutputOf<E>[]> {
|
|
232
|
+
declare readonly _zod: {
|
|
233
|
+
output: OutputOf<E>[]; input: OutputOf<E>[];
|
|
234
|
+
def: SchemaDef & { type: 'array'; element: E };
|
|
235
|
+
};
|
|
236
|
+
inner(v: unknown): OutputOf<E>[] {
|
|
237
|
+
if (!Array.isArray(v)) return fail('array');
|
|
238
|
+
const el = this._zod.def.element;
|
|
239
|
+
return (v as unknown[]).map((item) => el.parse(item)) as OutputOf<E>[];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type OutputOf<S> = S extends { _zod: { output: infer O } } ? O : never;
|
|
244
|
+
|
|
245
|
+
/* ------------------------------------------------------------------ */
|
|
246
|
+
/* Factories — the vendored `zod/mini` spelling */
|
|
247
|
+
/* ------------------------------------------------------------------ */
|
|
248
|
+
|
|
249
|
+
const number = () => new ZodNumber({ type: 'number' });
|
|
250
|
+
const string = () => new ZodString({ type: 'string' });
|
|
251
|
+
const boolean_ = () => new ZodBoolean({ type: 'boolean' });
|
|
252
|
+
const bigint_ = () => new ZodBigint({ type: 'bigint' });
|
|
253
|
+
const unknown_ = () => new ZodUnknown({ type: 'unknown' });
|
|
254
|
+
const instanceof_ = <T extends abstract new (...args: any[]) => any>(cls: T) =>
|
|
255
|
+
new ZodInstanceof<InstanceType<T>>({ type: 'instanceof', cls });
|
|
256
|
+
const object_ = <S extends Record<string, ZodLike>>(shape: S) =>
|
|
257
|
+
new ZodObjectSchema<S>({ type: 'object', shape });
|
|
258
|
+
const array = <E extends ZodLike>(element: E) =>
|
|
259
|
+
new ZodArraySchema<E>({ type: 'array', element });
|
|
260
|
+
|
|
261
|
+
const int32 = () => new ZodNumber({ type: 'number', format: 'int32' }).check(intRange('int32', int32min, int32max));
|
|
262
|
+
const uint32 = () => new ZodNumber({ type: 'number', format: 'uint32' }).check(intRange('uint32', 0, 4294967295));
|
|
263
|
+
const float32 = () => new ZodNumber({ type: 'number', format: 'float32' });
|
|
264
|
+
const float64 = () => new ZodNumber({ type: 'number', format: 'float64' });
|
|
265
|
+
const int64 = () => new ZodBigint({ type: 'bigint', format: 'int64' }).check(int64Range('int64', -(2n ** 63n), 2n ** 63n - 1n));
|
|
266
|
+
const uint64 = () => new ZodBigint({ type: 'bigint', format: 'uint64' }).check(int64Range('uint64', 0n, 2n ** 64n - 1n));
|
|
267
|
+
|
|
268
|
+
/* ------------------------------------------------------------------ */
|
|
269
|
+
/* Fluent — the classic chain spellings, re-attached */
|
|
270
|
+
/* ------------------------------------------------------------------ */
|
|
271
|
+
|
|
272
|
+
/** Sized kinds take length checks; numerics take value bounds. */
|
|
273
|
+
const SIZED = new Set(['string', 'array', 'set']);
|
|
274
|
+
const boundCheck = (schema: ZodType, side: 'min' | 'max', v: number | bigint) => {
|
|
275
|
+
const sized = SIZED.has(schema._zod.def.type);
|
|
276
|
+
if (side === 'min') return sized ? minLength(v as number) : gte(v);
|
|
277
|
+
return sized ? maxLength(v as number) : lte(v);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/** The chainable spellings re-added to atoll-minted schemas. */
|
|
281
|
+
export type Fluent<S extends ZodLike> = S & {
|
|
282
|
+
/** Custom check via `.check()` — keeps `def.type`, unlike a wrapping refine. */
|
|
283
|
+
refine(fn: (value: S['_zod']['output']) => unknown, params?: string): Fluent<S>;
|
|
284
|
+
/** `meta()` reads, `meta(m)` writes — backed by the module registry. */
|
|
285
|
+
meta(): Record<string, unknown> | undefined;
|
|
286
|
+
meta(m: Record<string, unknown>): Fluent<S>;
|
|
287
|
+
min(value: number | bigint): Fluent<S>;
|
|
288
|
+
max(value: number | bigint): Fluent<S>;
|
|
289
|
+
length(n: number): Fluent<S>;
|
|
290
|
+
int(): Fluent<S>;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/** Attaches the `Fluent` methods as non-enumerable own properties. */
|
|
294
|
+
export function fluent<S extends ZodType>(schema: S): Fluent<S> {
|
|
295
|
+
const boundCheck_ = schema.check.bind(schema) as (...c: Check[]) => S;
|
|
296
|
+
const register = schema.register.bind(schema) as (r: Registry, m: Record<string, unknown>) => S;
|
|
297
|
+
const own: Record<string, unknown> = {
|
|
298
|
+
refine: (fn: (v: unknown) => unknown, params?: string) => fluent(boundCheck_(refine(fn, params))),
|
|
299
|
+
meta: (m?: Record<string, unknown>) =>
|
|
300
|
+
m === undefined ? globalRegistry.get(schema) : fluent(register(globalRegistry, m)),
|
|
301
|
+
min: (v: number | bigint) => fluent(boundCheck_(boundCheck(schema, 'min', v))),
|
|
302
|
+
max: (v: number | bigint) => fluent(boundCheck_(boundCheck(schema, 'max', v))),
|
|
303
|
+
length: (n: number) => fluent(boundCheck_(length(n))),
|
|
304
|
+
int: () => fluent(boundCheck_(int())),
|
|
305
|
+
};
|
|
306
|
+
for (const [key, fn] of Object.entries(own)) {
|
|
307
|
+
Object.defineProperty(schema, key, { value: fn, enumerable: false, configurable: true });
|
|
308
|
+
}
|
|
309
|
+
return schema as Fluent<S>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/* ------------------------------------------------------------------ */
|
|
313
|
+
/* Facade */
|
|
314
|
+
/* ------------------------------------------------------------------ */
|
|
24
315
|
|
|
25
316
|
export const z = {
|
|
26
|
-
number, string, boolean, bigint, object, array,
|
|
317
|
+
number, string, boolean: boolean_, bigint: bigint_, object: object_, array,
|
|
27
318
|
instanceof: instanceof_, unknown: unknown_,
|
|
28
319
|
int32, uint32, float32, float64, int64, uint64,
|
|
29
|
-
|
|
30
|
-
|
|
320
|
+
int, gte, lte, nonnegative, refine, length, maxLength, minLength,
|
|
321
|
+
globalRegistry,
|
|
322
|
+
/** Base classes — `instanceof` covers atoll-minted schemas. */
|
|
323
|
+
ZodType, ZodObject: ZodObjectSchema, ZodArray: ZodArraySchema, ZodString,
|
|
31
324
|
};
|
|
32
325
|
|
|
33
326
|
export namespace z {
|
|
34
|
-
/*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
export type
|
|
38
|
-
export type
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
327
|
+
/* Structural aliases — public signatures speak in these so classic zod,
|
|
328
|
+
* zod/mini, and atoll-minted schemas are all assignable. */
|
|
329
|
+
export type ZodTypeAny = ZodLike;
|
|
330
|
+
export type ZodType<Output = unknown, Input = unknown> = ZodLike<Output, Input>;
|
|
331
|
+
export type ZodRawShape = Record<string, ZodLike>;
|
|
332
|
+
export interface ZodObject<S extends ZodRawShape = ZodRawShape>
|
|
333
|
+
extends ZodLike<ShapeOutput<S>, ShapeOutput<S>> {
|
|
334
|
+
readonly _zod: {
|
|
335
|
+
output: ShapeOutput<S>;
|
|
336
|
+
input: ShapeOutput<S>;
|
|
337
|
+
def: { type: 'object'; shape: S; checks?: readonly unknown[] };
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export interface ZodArray<E extends ZodTypeAny = ZodTypeAny>
|
|
341
|
+
extends ZodLike<OutputOf<E>[]> {
|
|
342
|
+
readonly _zod: {
|
|
343
|
+
output: OutputOf<E>[];
|
|
344
|
+
input: OutputOf<E>[];
|
|
345
|
+
def: { type: 'array'; element: E; checks?: readonly unknown[] };
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
export interface ZodString extends ZodLike<string> {
|
|
349
|
+
readonly _zod: {
|
|
350
|
+
output: string; input: string;
|
|
351
|
+
def: { type: 'string'; checks?: readonly unknown[] };
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
export type ZodMiniObject<S extends ZodRawShape = ZodRawShape> = ZodObject<S>;
|
|
355
|
+
export type output<T extends ZodTypeAny> = OutputOf<T>;
|
|
44
356
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* ── Contract — shared memory declarations (both threads) ───────────────── */
|
|
2
2
|
|
|
3
3
|
export { bindSharedMemories, defineSharedMemory, field, getDefinedSharedMemoryCount, jsonCodec, registerConnectorFactory } from './contract/sharedMemory';
|
|
4
|
-
export {
|
|
4
|
+
export { reef } from './contract/reef';
|
|
5
5
|
export type {
|
|
6
6
|
Codec,
|
|
7
7
|
Connector,
|
|
@@ -30,7 +30,6 @@ export type {
|
|
|
30
30
|
ListRecord,
|
|
31
31
|
ListSpec,
|
|
32
32
|
} from './contract/sharedMemory';
|
|
33
|
-
export { msgpackCodec } from './contract/msgpackCodec';
|
|
34
33
|
export { msgpackrCodec } from './contract/msgpackrCodec';
|
|
35
34
|
export { listSchema } from './contract/listSchema';
|
|
36
35
|
export type { ListZodShape } from './contract/listSchema';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Codec } from './sharedMemory';
|
|
2
|
-
/**
|
|
3
|
-
* MessagePack transport codec: smaller payloads than JSON and supports types
|
|
4
|
-
* JSON can't express (Uint8Array, BigInt, etc.). Decoded values are still
|
|
5
|
-
* validated by each field's zod schema.
|
|
6
|
-
*/
|
|
7
|
-
export declare const msgpackCodec: Codec;
|
package/dist/contract/mz.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { z } from './zod';
|
|
2
|
-
/**
|
|
3
|
-
* Atoll zod — the fixed-width schema vocabulary. Every helper produces a
|
|
4
|
-
* plain zod schema the layout compiler can read a byte width from: number
|
|
5
|
-
* formats (`mz.u32()`), int bounds (`mz.int(0, 3)` → u8), byte budgets
|
|
6
|
-
* (`mz.string(10)`), or flags (`mz.boolean()` → u8). There are no unfixed
|
|
7
|
-
* members — `mz.number()`/`z.date()`/`z.enum()` aren't exposed because they
|
|
8
|
-
* can't promise a width.
|
|
9
|
-
*
|
|
10
|
-
* Width coverage: zod 4 provides int32/uint32/float32/float64/int64/uint64
|
|
11
|
-
* formats; mz fills the gaps (i8/u8/i16/u16 via bounded ints, which the
|
|
12
|
-
* compiler narrows identically) so all ten scalar kinds have one spelling.
|
|
13
|
-
*
|
|
14
|
-
* Composition derives byte width upward — `mz.object({...})` members lay out
|
|
15
|
-
* as a fixed record (field.object derives byteLength from it, no maxBytes),
|
|
16
|
-
* `mz.array(el).max(n)` bounds element capacity for field.array, and
|
|
17
|
-
* `mz.string(n)` carries the budget for field.string. The returned values are
|
|
18
|
-
* ordinary zod schemas — `.meta()`, `.refine()`, `.max()` all still work.
|
|
19
|
-
*/
|
|
20
|
-
export declare const mz: {
|
|
21
|
-
i8: () => import("zod").ZodNumber;
|
|
22
|
-
u8: () => import("zod").ZodNumber;
|
|
23
|
-
i16: () => import("zod").ZodNumber;
|
|
24
|
-
u16: () => import("zod").ZodNumber;
|
|
25
|
-
i32: () => import("zod").ZodInt32;
|
|
26
|
-
u32: () => import("zod").ZodUInt32;
|
|
27
|
-
f32: () => import("zod").ZodFloat32;
|
|
28
|
-
f64: () => import("zod").ZodFloat64;
|
|
29
|
-
i64: () => import("zod").ZodInt64;
|
|
30
|
-
u64: () => import("zod").ZodUInt64;
|
|
31
|
-
/** Bounded int — compiles to the narrowest covering kind (0..3 → u8). */
|
|
32
|
-
int: (min: number, max: number) => import("zod").ZodNumber;
|
|
33
|
-
/** A flag byte — reads and writes as boolean. */
|
|
34
|
-
boolean: () => import("zod").ZodBoolean;
|
|
35
|
-
/** Fixed-capacity inline UTF-8 string — `bytes` is the byte budget. The
|
|
36
|
-
* schema itself refuses over-budget values, so `.parse` and connector
|
|
37
|
-
* writes enforce the same limit. */
|
|
38
|
-
string: (bytes: number) => import("zod").ZodString;
|
|
39
|
-
/** A fixed-layout record shape — every member must be a fixed-width schema. */
|
|
40
|
-
object: <S extends z.ZodRawShape>(shape: S) => import("zod").ZodObject<{ -readonly [P in keyof S]: S[P]; }, import("zod/v4/core").$strip>;
|
|
41
|
-
/** A fixed-stride element — bound it with `.max(n)` or `.length(n)` before field.array. */
|
|
42
|
-
array: <E extends z.ZodTypeAny>(element: E) => import("zod").ZodArray<E>;
|
|
43
|
-
};
|
package/dist/index21.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { scoped as e } from "./index5.js";
|
|
2
|
-
//#region src/task.ts
|
|
3
|
-
var t = e("task");
|
|
4
|
-
function n(e) {
|
|
5
|
-
let n = 0, r = {
|
|
6
|
-
data: null,
|
|
7
|
-
pending: !1,
|
|
8
|
-
settled: !1,
|
|
9
|
-
elapsedMs: null,
|
|
10
|
-
error: null
|
|
11
|
-
}, i = /* @__PURE__ */ new Set(), a = (e) => {
|
|
12
|
-
r = e;
|
|
13
|
-
for (let t of i) t(e);
|
|
14
|
-
}, o = {
|
|
15
|
-
get: () => r,
|
|
16
|
-
subscribe(e) {
|
|
17
|
-
return i.add(e), () => {
|
|
18
|
-
i.delete(e);
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
run(i) {
|
|
22
|
-
let o = ++n, s = performance.now();
|
|
23
|
-
a({
|
|
24
|
-
...r,
|
|
25
|
-
pending: !0,
|
|
26
|
-
error: null
|
|
27
|
-
}), e(i).then((e) => {
|
|
28
|
-
o === n && a({
|
|
29
|
-
data: e,
|
|
30
|
-
pending: !1,
|
|
31
|
-
settled: !0,
|
|
32
|
-
elapsedMs: performance.now() - s,
|
|
33
|
-
error: null
|
|
34
|
-
});
|
|
35
|
-
}, (e) => {
|
|
36
|
-
o === n && a({
|
|
37
|
-
...r,
|
|
38
|
-
pending: !1,
|
|
39
|
-
settled: !0,
|
|
40
|
-
error: e
|
|
41
|
-
}), t.error("task run failed", e);
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
runOnce(e) {
|
|
45
|
-
r.pending || r.settled || o.run(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
return o;
|
|
49
|
-
}
|
|
50
|
-
function r(e) {
|
|
51
|
-
return typeof e == "object" && !!e && typeof e.run == "function" && typeof e.runOnce == "function" && typeof e.get == "function" && typeof e.subscribe == "function";
|
|
52
|
-
}
|
|
53
|
-
function i(e) {
|
|
54
|
-
return r(e) ? e : n(e);
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { n as defineTask, r as isAsyncTask, i as toTask };
|
|
58
|
-
|
|
59
|
-
//# sourceMappingURL=index21.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { decode, encode } from '@msgpack/msgpack';
|
|
2
|
-
import type { Codec } from './sharedMemory';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* MessagePack transport codec: smaller payloads than JSON and supports types
|
|
6
|
-
* JSON can't express (Uint8Array, BigInt, etc.). Decoded values are still
|
|
7
|
-
* validated by each field's zod schema.
|
|
8
|
-
*/
|
|
9
|
-
export const msgpackCodec: Codec = { encode, decode };
|
package/src/contract/mz.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { z } from './zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Atoll zod — the fixed-width schema vocabulary. Every helper produces a
|
|
5
|
-
* plain zod schema the layout compiler can read a byte width from: number
|
|
6
|
-
* formats (`mz.u32()`), int bounds (`mz.int(0, 3)` → u8), byte budgets
|
|
7
|
-
* (`mz.string(10)`), or flags (`mz.boolean()` → u8). There are no unfixed
|
|
8
|
-
* members — `mz.number()`/`z.date()`/`z.enum()` aren't exposed because they
|
|
9
|
-
* can't promise a width.
|
|
10
|
-
*
|
|
11
|
-
* Width coverage: zod 4 provides int32/uint32/float32/float64/int64/uint64
|
|
12
|
-
* formats; mz fills the gaps (i8/u8/i16/u16 via bounded ints, which the
|
|
13
|
-
* compiler narrows identically) so all ten scalar kinds have one spelling.
|
|
14
|
-
*
|
|
15
|
-
* Composition derives byte width upward — `mz.object({...})` members lay out
|
|
16
|
-
* as a fixed record (field.object derives byteLength from it, no maxBytes),
|
|
17
|
-
* `mz.array(el).max(n)` bounds element capacity for field.array, and
|
|
18
|
-
* `mz.string(n)` carries the budget for field.string. The returned values are
|
|
19
|
-
* ordinary zod schemas — `.meta()`, `.refine()`, `.max()` all still work.
|
|
20
|
-
*/
|
|
21
|
-
export const mz = {
|
|
22
|
-
i8: () => z.number().int().min(-128).max(127),
|
|
23
|
-
u8: () => z.number().int().min(0).max(255),
|
|
24
|
-
i16: () => z.number().int().min(-32768).max(32767),
|
|
25
|
-
u16: () => z.number().int().min(0).max(65535),
|
|
26
|
-
i32: () => z.int32(),
|
|
27
|
-
u32: () => z.uint32(),
|
|
28
|
-
f32: () => z.float32(),
|
|
29
|
-
f64: () => z.float64(),
|
|
30
|
-
i64: () => z.int64(),
|
|
31
|
-
u64: () => z.uint64(),
|
|
32
|
-
/** Bounded int — compiles to the narrowest covering kind (0..3 → u8). */
|
|
33
|
-
int: (min: number, max: number) => z.number().int().min(min).max(max),
|
|
34
|
-
/** A flag byte — reads and writes as boolean. */
|
|
35
|
-
boolean: () => z.boolean(),
|
|
36
|
-
/** Fixed-capacity inline UTF-8 string — `bytes` is the byte budget. The
|
|
37
|
-
* schema itself refuses over-budget values, so `.parse` and connector
|
|
38
|
-
* writes enforce the same limit. */
|
|
39
|
-
string: (bytes: number) =>
|
|
40
|
-
z.string().refine(
|
|
41
|
-
(s) => new TextEncoder().encode(s).byteLength <= bytes,
|
|
42
|
-
`exceeds ${bytes} UTF-8 bytes`
|
|
43
|
-
).meta({ bytes }),
|
|
44
|
-
/** A fixed-layout record shape — every member must be a fixed-width schema. */
|
|
45
|
-
object: <S extends z.ZodRawShape>(shape: S) => z.object(shape),
|
|
46
|
-
/** A fixed-stride element — bound it with `.max(n)` or `.length(n)` before field.array. */
|
|
47
|
-
array: <E extends z.ZodTypeAny>(element: E) => z.array(element),
|
|
48
|
-
};
|