@atolljs/core 0.1.2 → 0.1.4
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 +10 -8
- 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 +8 -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Justin Henry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
<picture>
|
|
2
|
-
<source media="(prefers-color-scheme: dark)" srcset="assets/atoll-dark.svg" />
|
|
3
|
-
<source media="(prefers-color-scheme: light)" srcset="assets/atoll-light.svg" />
|
|
4
|
-
<img src="assets/atoll-light.svg" alt="Atoll — islands of framework workers around a shared core" width="
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/atoll-horizontal-dark.svg" />
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="assets/atoll-horizontal-light.svg" />
|
|
4
|
+
<img src="assets/atoll-horizontal-light.svg" alt="Atoll — islands of framework workers around a shared core" width="420" />
|
|
5
5
|
</picture>
|
|
6
6
|
|
|
7
|
-
# AtollJS
|
|
8
|
-
|
|
9
7
|
[](https://github.com/jwhenry3/atolljs/actions/workflows/ci.yml)
|
|
10
8
|
[](https://codecov.io/gh/jwhenry3/atolljs)
|
|
9
|
+
[](https://badge.socket.dev/npm/package/@atolljs/core)
|
|
11
10
|
|
|
12
11
|
Typed shared-memory worker pools for TypeScript — deterministic `SharedArrayBuffer`
|
|
13
12
|
layouts, first-class task methods, and cross-thread reactive state. A worker
|
|
@@ -182,8 +181,11 @@ manifest also pins `publishConfig.registry` to `registry.npmjs.org`, so the
|
|
|
182
181
|
destination is declared in the repo rather than resolved from the
|
|
183
182
|
publisher's local npmrc.
|
|
184
183
|
|
|
185
|
-
Staging needs each package to already exist on the registry
|
|
186
|
-
|
|
184
|
+
Staging needs each package to already exist on the registry — the script
|
|
185
|
+
pre-flights `npm view` on every package and aborts before anything stages
|
|
186
|
+
if one is missing, so a new package can never leave a release half-staged.
|
|
187
|
+
The first release (and any release adding a package) is therefore a manual
|
|
188
|
+
bootstrap — from the repo root:
|
|
187
189
|
|
|
188
190
|
```bash
|
|
189
191
|
npm login # once
|
|
@@ -202,7 +204,7 @@ even if compromised. Configure per package (needs the package to exist on
|
|
|
202
204
|
npm, and npm CLI ≥ 11.10):
|
|
203
205
|
|
|
204
206
|
```bash
|
|
205
|
-
for p in core node react vue solidjs svelte angular nextjs nestjs \
|
|
207
|
+
for p in core node react vue solidjs svelte angular nextjs nestjs cli \
|
|
206
208
|
islands react-island vue-island svelte-island solid-island angular-island; do
|
|
207
209
|
npm trust github "@atolljs/$p" --repo jwhenry3/atolljs --file publish.yml --allow-stage-publish -y
|
|
208
210
|
sleep 2
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from './zod';
|
|
1
|
+
import { z, type Fluent } from './zod';
|
|
2
2
|
import type { ListFieldSpec, ListFields, ListMember } from './sharedMemory';
|
|
3
3
|
/** Maps a list member to the zod shape whose inferred output type is
|
|
4
4
|
* identical to `ListRecord<F>[K]` — zod members pass through as
|
|
@@ -12,7 +12,7 @@ export type ListZodShape<F extends ListFields> = {
|
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Builds a zod object schema from a member map — the shape you would pass
|
|
15
|
-
* to `
|
|
15
|
+
* to `reef.object(...)` for `field.list({ schema, count })`. Members may be
|
|
16
16
|
* spec tokens or zod schemas; the result's `z.infer` is the record type:
|
|
17
17
|
*
|
|
18
18
|
* ```ts
|
|
@@ -25,7 +25,7 @@ export type ListZodShape<F extends ListFields> = {
|
|
|
25
25
|
* capacity the connector enforces; zod `z.string().meta({ bytes: n })`
|
|
26
26
|
* members get the same bound attached to the declared schema.
|
|
27
27
|
*/
|
|
28
|
-
export declare function listSchema<F extends ListFields>(fields: F): z.
|
|
28
|
+
export declare function listSchema<F extends ListFields>(fields: F): Fluent<z.ZodMiniObject<ListZodShape<F>>>;
|
|
29
29
|
/**
|
|
30
30
|
* Compiles one fixed-layout member — a spec token or a zod schema — to its
|
|
31
31
|
* binary layout form. Throws for members that can't express a fixed-width
|
|
@@ -43,5 +43,5 @@ export declare function zodArrayInfo(schema: unknown): {
|
|
|
43
43
|
element: z.ZodTypeAny;
|
|
44
44
|
capacity: number | null;
|
|
45
45
|
} | null;
|
|
46
|
-
/** The byte budget carried by `
|
|
46
|
+
/** The byte budget carried by `reef.string(n)` / `z.string().meta({ bytes: n })` — null otherwise. */
|
|
47
47
|
export declare function zodStringBytes(schema: unknown): number | null;
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { z } from './zod';
|
|
2
|
+
/**
|
|
3
|
+
* Reef — the atoll's structural barrier: the fixed-width schema
|
|
4
|
+
* vocabulary standing between your data and the raw buffer. Every helper
|
|
5
|
+
* mints a schema the layout compiler can read a byte width from: number
|
|
6
|
+
* formats (`reef.u32()`), int bounds (`reef.int(0, 3)` → u8), byte budgets
|
|
7
|
+
* (`reef.string(10)`), or flags (`reef.boolean()` → u8). There are no unfixed
|
|
8
|
+
* members — `reef.number()`/`z.date()`/`z.enum()` aren't exposed because they
|
|
9
|
+
* can't promise a width.
|
|
10
|
+
*
|
|
11
|
+
* Schemas are minted by the vendored engine in `./zod.ts` — a zod-shaped
|
|
12
|
+
* `_zod.def` surface (`type`/`format`/`checks`/`shape`/`element`), so no
|
|
13
|
+
* zod dependency ships. Width coverage: int32/uint32/float32/float64/
|
|
14
|
+
* int64/uint64 are format-tagged; reef fills the gaps (i8/u8/i16/u16 via
|
|
15
|
+
* bounded ints, which the compiler narrows identically) so all ten scalar
|
|
16
|
+
* kinds have one spelling.
|
|
17
|
+
*
|
|
18
|
+
* Composition derives byte width upward — `reef.object({...})` members lay out
|
|
19
|
+
* as a fixed record (field.object derives byteLength from it, no maxBytes),
|
|
20
|
+
* `reef.array(el).max(n)` bounds element capacity for field.array, and
|
|
21
|
+
* `reef.string(n)` carries the budget for field.string. Schemas keep the
|
|
22
|
+
* classic chain spellings — `.meta()`, `.refine()`, `.max()`/`.length()` —
|
|
23
|
+
* and consumer-supplied zod schemas introspect identically through their
|
|
24
|
+
* `_zod.def`, so `reef.object({ id: z.uint32() })` mixes freely.
|
|
25
|
+
*/
|
|
26
|
+
export declare const reef: {
|
|
27
|
+
i8: () => import("./zod").Fluent<{
|
|
28
|
+
readonly _zod: {
|
|
29
|
+
output: number;
|
|
30
|
+
input: number;
|
|
31
|
+
def: import("./zod").SchemaDef & {
|
|
32
|
+
type: 'number';
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
inner(v: unknown): number;
|
|
36
|
+
parse(value: unknown): number;
|
|
37
|
+
safeParse(value: unknown): {
|
|
38
|
+
success: true;
|
|
39
|
+
data: number;
|
|
40
|
+
} | {
|
|
41
|
+
success: false;
|
|
42
|
+
error: unknown;
|
|
43
|
+
};
|
|
44
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
45
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
46
|
+
}>;
|
|
47
|
+
u8: () => import("./zod").Fluent<{
|
|
48
|
+
readonly _zod: {
|
|
49
|
+
output: number;
|
|
50
|
+
input: number;
|
|
51
|
+
def: import("./zod").SchemaDef & {
|
|
52
|
+
type: 'number';
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
inner(v: unknown): number;
|
|
56
|
+
parse(value: unknown): number;
|
|
57
|
+
safeParse(value: unknown): {
|
|
58
|
+
success: true;
|
|
59
|
+
data: number;
|
|
60
|
+
} | {
|
|
61
|
+
success: false;
|
|
62
|
+
error: unknown;
|
|
63
|
+
};
|
|
64
|
+
check(...checks: import("./zod").Check[]): any;
|
|
65
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
66
|
+
}>;
|
|
67
|
+
i16: () => import("./zod").Fluent<{
|
|
68
|
+
readonly _zod: {
|
|
69
|
+
output: number;
|
|
70
|
+
input: number;
|
|
71
|
+
def: import("./zod").SchemaDef & {
|
|
72
|
+
type: 'number';
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
inner(v: unknown): number;
|
|
76
|
+
parse(value: unknown): number;
|
|
77
|
+
safeParse(value: unknown): {
|
|
78
|
+
success: true;
|
|
79
|
+
data: number;
|
|
80
|
+
} | {
|
|
81
|
+
success: false;
|
|
82
|
+
error: unknown;
|
|
83
|
+
};
|
|
84
|
+
check(...checks: import("./zod").Check[]): any;
|
|
85
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
86
|
+
}>;
|
|
87
|
+
u16: () => import("./zod").Fluent<{
|
|
88
|
+
readonly _zod: {
|
|
89
|
+
output: number;
|
|
90
|
+
input: number;
|
|
91
|
+
def: import("./zod").SchemaDef & {
|
|
92
|
+
type: 'number';
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
inner(v: unknown): number;
|
|
96
|
+
parse(value: unknown): number;
|
|
97
|
+
safeParse(value: unknown): {
|
|
98
|
+
success: true;
|
|
99
|
+
data: number;
|
|
100
|
+
} | {
|
|
101
|
+
success: false;
|
|
102
|
+
error: unknown;
|
|
103
|
+
};
|
|
104
|
+
check(...checks: import("./zod").Check[]): any;
|
|
105
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
106
|
+
}>;
|
|
107
|
+
i32: () => import("./zod").Fluent<{
|
|
108
|
+
readonly _zod: {
|
|
109
|
+
output: number;
|
|
110
|
+
input: number;
|
|
111
|
+
def: import("./zod").SchemaDef & {
|
|
112
|
+
type: 'number';
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
inner(v: unknown): number;
|
|
116
|
+
parse(value: unknown): number;
|
|
117
|
+
safeParse(value: unknown): {
|
|
118
|
+
success: true;
|
|
119
|
+
data: number;
|
|
120
|
+
} | {
|
|
121
|
+
success: false;
|
|
122
|
+
error: unknown;
|
|
123
|
+
};
|
|
124
|
+
check(...checks: import("./zod").Check[]): any;
|
|
125
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
126
|
+
}>;
|
|
127
|
+
u32: () => import("./zod").Fluent<{
|
|
128
|
+
readonly _zod: {
|
|
129
|
+
output: number;
|
|
130
|
+
input: number;
|
|
131
|
+
def: import("./zod").SchemaDef & {
|
|
132
|
+
type: 'number';
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
inner(v: unknown): number;
|
|
136
|
+
parse(value: unknown): number;
|
|
137
|
+
safeParse(value: unknown): {
|
|
138
|
+
success: true;
|
|
139
|
+
data: number;
|
|
140
|
+
} | {
|
|
141
|
+
success: false;
|
|
142
|
+
error: unknown;
|
|
143
|
+
};
|
|
144
|
+
check(...checks: import("./zod").Check[]): any;
|
|
145
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
146
|
+
}>;
|
|
147
|
+
f32: () => import("./zod").Fluent<{
|
|
148
|
+
readonly _zod: {
|
|
149
|
+
output: number;
|
|
150
|
+
input: number;
|
|
151
|
+
def: import("./zod").SchemaDef & {
|
|
152
|
+
type: 'number';
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
inner(v: unknown): number;
|
|
156
|
+
parse(value: unknown): number;
|
|
157
|
+
safeParse(value: unknown): {
|
|
158
|
+
success: true;
|
|
159
|
+
data: number;
|
|
160
|
+
} | {
|
|
161
|
+
success: false;
|
|
162
|
+
error: unknown;
|
|
163
|
+
};
|
|
164
|
+
check(...checks: import("./zod").Check[]): any;
|
|
165
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
166
|
+
}>;
|
|
167
|
+
f64: () => import("./zod").Fluent<{
|
|
168
|
+
readonly _zod: {
|
|
169
|
+
output: number;
|
|
170
|
+
input: number;
|
|
171
|
+
def: import("./zod").SchemaDef & {
|
|
172
|
+
type: 'number';
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
inner(v: unknown): number;
|
|
176
|
+
parse(value: unknown): number;
|
|
177
|
+
safeParse(value: unknown): {
|
|
178
|
+
success: true;
|
|
179
|
+
data: number;
|
|
180
|
+
} | {
|
|
181
|
+
success: false;
|
|
182
|
+
error: unknown;
|
|
183
|
+
};
|
|
184
|
+
check(...checks: import("./zod").Check[]): any;
|
|
185
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
186
|
+
}>;
|
|
187
|
+
i64: () => import("./zod").Fluent<{
|
|
188
|
+
readonly _zod: {
|
|
189
|
+
output: bigint;
|
|
190
|
+
input: bigint;
|
|
191
|
+
def: import("./zod").SchemaDef & {
|
|
192
|
+
type: 'bigint';
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
inner(v: unknown): bigint;
|
|
196
|
+
parse(value: unknown): bigint;
|
|
197
|
+
safeParse(value: unknown): {
|
|
198
|
+
success: true;
|
|
199
|
+
data: bigint;
|
|
200
|
+
} | {
|
|
201
|
+
success: false;
|
|
202
|
+
error: unknown;
|
|
203
|
+
};
|
|
204
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
205
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
206
|
+
}>;
|
|
207
|
+
u64: () => import("./zod").Fluent<{
|
|
208
|
+
readonly _zod: {
|
|
209
|
+
output: bigint;
|
|
210
|
+
input: bigint;
|
|
211
|
+
def: import("./zod").SchemaDef & {
|
|
212
|
+
type: 'bigint';
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
inner(v: unknown): bigint;
|
|
216
|
+
parse(value: unknown): bigint;
|
|
217
|
+
safeParse(value: unknown): {
|
|
218
|
+
success: true;
|
|
219
|
+
data: bigint;
|
|
220
|
+
} | {
|
|
221
|
+
success: false;
|
|
222
|
+
error: unknown;
|
|
223
|
+
};
|
|
224
|
+
check(...checks: import("./zod").Check[]): any;
|
|
225
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): any;
|
|
226
|
+
}>;
|
|
227
|
+
/** Bounded int — compiles to the narrowest covering kind (0..3 → u8). */
|
|
228
|
+
int: (min: number, max: number) => import("./zod").Fluent<{
|
|
229
|
+
readonly _zod: {
|
|
230
|
+
output: number;
|
|
231
|
+
input: number;
|
|
232
|
+
def: import("./zod").SchemaDef & {
|
|
233
|
+
type: 'number';
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
inner(v: unknown): number;
|
|
237
|
+
parse(value: unknown): number;
|
|
238
|
+
safeParse(value: unknown): {
|
|
239
|
+
success: true;
|
|
240
|
+
data: number;
|
|
241
|
+
} | {
|
|
242
|
+
success: false;
|
|
243
|
+
error: unknown;
|
|
244
|
+
};
|
|
245
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
246
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
247
|
+
}>;
|
|
248
|
+
/** A flag byte — reads and writes as boolean. */
|
|
249
|
+
boolean: () => import("./zod").Fluent<{
|
|
250
|
+
readonly _zod: {
|
|
251
|
+
output: boolean;
|
|
252
|
+
input: boolean;
|
|
253
|
+
def: import("./zod").SchemaDef & {
|
|
254
|
+
type: 'boolean';
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
inner(v: unknown): boolean;
|
|
258
|
+
parse(value: unknown): boolean;
|
|
259
|
+
safeParse(value: unknown): {
|
|
260
|
+
success: true;
|
|
261
|
+
data: boolean;
|
|
262
|
+
} | {
|
|
263
|
+
success: false;
|
|
264
|
+
error: unknown;
|
|
265
|
+
};
|
|
266
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
267
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
268
|
+
}>;
|
|
269
|
+
/** Fixed-capacity inline UTF-8 string — `bytes` is the byte budget. The
|
|
270
|
+
* schema itself refuses over-budget values, so `.parse` and connector
|
|
271
|
+
* writes enforce the same limit. */
|
|
272
|
+
string: (bytes: number) => import("./zod").Fluent<{
|
|
273
|
+
readonly _zod: {
|
|
274
|
+
output: string;
|
|
275
|
+
input: string;
|
|
276
|
+
def: import("./zod").SchemaDef & {
|
|
277
|
+
type: 'string';
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
inner(v: unknown): string;
|
|
281
|
+
parse(value: unknown): string;
|
|
282
|
+
safeParse(value: unknown): {
|
|
283
|
+
success: true;
|
|
284
|
+
data: string;
|
|
285
|
+
} | {
|
|
286
|
+
success: false;
|
|
287
|
+
error: unknown;
|
|
288
|
+
};
|
|
289
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
290
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
291
|
+
}>;
|
|
292
|
+
/** A fixed-layout record shape — every member must be a fixed-width schema. */
|
|
293
|
+
object: <S extends z.ZodRawShape>(shape: S) => import("./zod").Fluent<{
|
|
294
|
+
readonly _zod: {
|
|
295
|
+
output: { [K in keyof S]: S[K] extends {
|
|
296
|
+
_zod: {
|
|
297
|
+
output: infer O;
|
|
298
|
+
};
|
|
299
|
+
} ? O : never; };
|
|
300
|
+
input: { [K in keyof S]: S[K] extends {
|
|
301
|
+
_zod: {
|
|
302
|
+
output: infer O;
|
|
303
|
+
};
|
|
304
|
+
} ? O : never; };
|
|
305
|
+
def: import("./zod").SchemaDef & {
|
|
306
|
+
type: 'object';
|
|
307
|
+
shape: S;
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
get shape(): S;
|
|
311
|
+
inner(v: unknown): { [K in keyof S]: S[K] extends {
|
|
312
|
+
_zod: {
|
|
313
|
+
output: infer O;
|
|
314
|
+
};
|
|
315
|
+
} ? O : never; };
|
|
316
|
+
parse(value: unknown): { [K in keyof S]: S[K] extends {
|
|
317
|
+
_zod: {
|
|
318
|
+
output: infer O;
|
|
319
|
+
};
|
|
320
|
+
} ? O : never; };
|
|
321
|
+
safeParse(value: unknown): {
|
|
322
|
+
success: true;
|
|
323
|
+
data: { [K in keyof S]: S[K] extends {
|
|
324
|
+
_zod: {
|
|
325
|
+
output: infer O;
|
|
326
|
+
};
|
|
327
|
+
} ? O : never; };
|
|
328
|
+
} | {
|
|
329
|
+
success: false;
|
|
330
|
+
error: unknown;
|
|
331
|
+
};
|
|
332
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
333
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
334
|
+
}>;
|
|
335
|
+
/** A fixed-stride element — bound it with `.max(n)` or `.length(n)` before field.array. */
|
|
336
|
+
array: <E extends z.ZodTypeAny>(element: E) => import("./zod").Fluent<{
|
|
337
|
+
readonly _zod: {
|
|
338
|
+
output: (E extends {
|
|
339
|
+
_zod: {
|
|
340
|
+
output: infer O;
|
|
341
|
+
};
|
|
342
|
+
} ? O : never)[];
|
|
343
|
+
input: (E extends {
|
|
344
|
+
_zod: {
|
|
345
|
+
output: infer O;
|
|
346
|
+
};
|
|
347
|
+
} ? O : never)[];
|
|
348
|
+
def: import("./zod").SchemaDef & {
|
|
349
|
+
type: 'array';
|
|
350
|
+
element: E;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
inner(v: unknown): (E extends {
|
|
354
|
+
_zod: {
|
|
355
|
+
output: infer O;
|
|
356
|
+
};
|
|
357
|
+
} ? O : never)[];
|
|
358
|
+
parse(value: unknown): (E extends {
|
|
359
|
+
_zod: {
|
|
360
|
+
output: infer O;
|
|
361
|
+
};
|
|
362
|
+
} ? O : never)[];
|
|
363
|
+
safeParse(value: unknown): {
|
|
364
|
+
success: true;
|
|
365
|
+
data: (E extends {
|
|
366
|
+
_zod: {
|
|
367
|
+
output: infer O;
|
|
368
|
+
};
|
|
369
|
+
} ? O : never)[];
|
|
370
|
+
} | {
|
|
371
|
+
success: false;
|
|
372
|
+
error: unknown;
|
|
373
|
+
};
|
|
374
|
+
check(...checks: import("./zod").Check[]): /*elided*/ any;
|
|
375
|
+
register(registry: import("./zod").Registry, meta: Record<string, unknown>): /*elided*/ any;
|
|
376
|
+
}>;
|
|
377
|
+
};
|
|
@@ -91,7 +91,7 @@ export type ListSpec = Record<string, ListFieldSpec>;
|
|
|
91
91
|
/**
|
|
92
92
|
* A fixed-width member inside a record or element position — a binary spec
|
|
93
93
|
* token (`'u32'`, `{ string: n }`, `{ bool: true }`) or a zod schema that
|
|
94
|
-
* expresses the same thing (`
|
|
94
|
+
* expresses the same thing (`reef.u32()`, `reef.int(0, 3)`, `reef.string(n)`).
|
|
95
95
|
* Schemas are compiled to tokens for layout and kept as the field's
|
|
96
96
|
* validation schema — one declaration.
|
|
97
97
|
*/
|
|
@@ -102,7 +102,7 @@ export type ListRecord<S extends z.ZodObject> = z.output<S>;
|
|
|
102
102
|
export interface ListDescriptor<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> extends Omit<FieldDescriptor<ListRecord<S>[]>, 'schema'> {
|
|
103
103
|
readonly kind: 'list';
|
|
104
104
|
/**
|
|
105
|
-
* The declared record schema —
|
|
105
|
+
* The declared record schema — a `reef.object` of fixed-width members. It
|
|
106
106
|
* IS the layout source AND the record validator (`schemas.lists.x` is this
|
|
107
107
|
* same object). Note it parses one record, not the whole array.
|
|
108
108
|
*/
|
|
@@ -173,7 +173,7 @@ export interface FixedArrayDescriptor<T = unknown> extends FieldDescriptor<T[]>
|
|
|
173
173
|
interface ObjectFieldFactory {
|
|
174
174
|
/**
|
|
175
175
|
* Inline fixed layout — the schema is a zod object of fixed-width members
|
|
176
|
-
* (`
|
|
176
|
+
* (`reef` helpers, `z.uint32()`, bounded ints, `reef.string(n)`, `z.boolean()`);
|
|
177
177
|
* `byteLength` derives from the member widths. Compile fails loudly for
|
|
178
178
|
* members with no fixed width (unbounded strings, nested objects).
|
|
179
179
|
*/
|
|
@@ -193,9 +193,9 @@ interface ObjectFieldFactory {
|
|
|
193
193
|
interface ArrayFieldFactory {
|
|
194
194
|
/**
|
|
195
195
|
* Inline fixed layout — the schema is a bounded zod array
|
|
196
|
-
* (`
|
|
196
|
+
* (`reef.array(reef.u32()).max(n)`, `.length(n)`); `byteLength` derives from
|
|
197
197
|
* the element width × the bound. Elements must be fixed-width members
|
|
198
|
-
* (scalars, `
|
|
198
|
+
* (scalars, `reef.string(n)`, booleans) — use `field.list` for record arrays.
|
|
199
199
|
*/
|
|
200
200
|
<S extends z.ZodArray>(options: {
|
|
201
201
|
schema: S;
|
|
@@ -216,7 +216,7 @@ interface StringFieldFactory {
|
|
|
216
216
|
maxBytes: number;
|
|
217
217
|
schema?: Schema<string>;
|
|
218
218
|
}): FieldDescriptor<string>;
|
|
219
|
-
/** Budget derived from the schema — `
|
|
219
|
+
/** Budget derived from the schema — `reef.string(n)` / `z.string().meta({ bytes: n })`. */
|
|
220
220
|
(options: {
|
|
221
221
|
schema: Schema<string>;
|
|
222
222
|
}): FieldDescriptor<string>;
|
|
@@ -243,9 +243,9 @@ export declare const field: {
|
|
|
243
243
|
length: number;
|
|
244
244
|
}) => FieldDescriptor<Uint8Array>;
|
|
245
245
|
/**
|
|
246
|
-
* A fixed-layout array of `count` records. `schema` is
|
|
247
|
-
* fixed-width members (`
|
|
248
|
-
* `
|
|
246
|
+
* A fixed-layout array of `count` records. `schema` is a `reef.object` of
|
|
247
|
+
* fixed-width members (`reef.u32()`, `reef.int(0, 3)`, `reef.string(n)`,
|
|
248
|
+
* `reef.boolean()`) — the same schema `field.object` takes, repeated `count`
|
|
249
249
|
* times. Every record occupies `recordSize` bytes at a computable offset:
|
|
250
250
|
* reads and writes are direct memory access, no serialization.
|
|
251
251
|
*/
|
|
@@ -255,13 +255,13 @@ export declare const field: {
|
|
|
255
255
|
}) => ListDescriptor<S>;
|
|
256
256
|
};
|
|
257
257
|
/**
|
|
258
|
-
* The
|
|
258
|
+
* The schema for a field's logical unit: the declared `schema` for
|
|
259
259
|
* object/array/list fields (for lists, the record schema), and a derived
|
|
260
260
|
* scalar/typed-array schema for everything else.
|
|
261
261
|
*/
|
|
262
262
|
export type FieldSchema<D> = 'schema' extends keyof D ? NonNullable<D['schema']> : z.ZodType<InferField<D>>;
|
|
263
263
|
/**
|
|
264
|
-
* A
|
|
264
|
+
* A schema per field — `memory.schemas.<field>` re-exports what the spec
|
|
265
265
|
* declared inline. Intent groups mirror their spec shape:
|
|
266
266
|
* `memory.schemas.lists.incidents` is the record schema.
|
|
267
267
|
*/
|
|
@@ -280,9 +280,9 @@ export declare class SharedMemory<S extends SharedSpec = SharedSpec> {
|
|
|
280
280
|
/** The field descriptors the contract was defined with — the inline spec. */
|
|
281
281
|
readonly spec: S;
|
|
282
282
|
/**
|
|
283
|
-
* One
|
|
283
|
+
* One schema per field, derived from the spec: declared schemas on
|
|
284
284
|
* object/array fields, the record schema on list fields, and derived
|
|
285
|
-
* scalar schemas
|
|
285
|
+
* scalar schemas elsewhere.
|
|
286
286
|
*/
|
|
287
287
|
readonly schemas: SpecSchemas<S>;
|
|
288
288
|
private readonly codec;
|