@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/dist/index3.js
CHANGED
|
@@ -1,27 +1,204 @@
|
|
|
1
|
-
import { array as e, bigint as t, boolean as n, float32 as r, float64 as i, instanceof as a, int32 as o, int64 as s, number as c, object as l, string as u, uint32 as d, uint64 as f, unknown as p } from "zod";
|
|
2
|
-
import { $ZodArray as m, $ZodObject as h, $ZodString as g, $ZodType as _ } from "zod/v4/core";
|
|
3
1
|
//#region src/contract/zod.ts
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
var e = (e, t) => ({
|
|
3
|
+
_zod: { def: e },
|
|
4
|
+
evaluate: t
|
|
5
|
+
}), t = -2147483648, n = 2147483647, r = () => e({
|
|
6
|
+
check: "number_format",
|
|
7
|
+
format: "safeint"
|
|
8
|
+
}, (e) => Number.isInteger(e) || "expected an integer"), i = (t) => e({
|
|
9
|
+
check: "greater_than",
|
|
10
|
+
value: t,
|
|
11
|
+
inclusive: !0
|
|
12
|
+
}, (e) => e >= t || `expected >= ${t}`), a = (t) => e({
|
|
13
|
+
check: "less_than",
|
|
14
|
+
value: t,
|
|
15
|
+
inclusive: !0
|
|
16
|
+
}, (e) => e <= t || `expected <= ${t}`), o = () => i(0), s = (t, n) => e({ check: "custom" }, (e) => !!t(e) || (n ?? "failed custom check")), c = (t) => e({
|
|
17
|
+
check: "length_equals",
|
|
18
|
+
length: t
|
|
19
|
+
}, (e) => e.length === t || `expected exactly ${t} items`), l = (t) => e({
|
|
20
|
+
check: "max_length",
|
|
21
|
+
maximum: t
|
|
22
|
+
}, (e) => e.length <= t || `expected <=${t} items`), u = (t) => e({
|
|
23
|
+
check: "min_length",
|
|
24
|
+
minimum: t
|
|
25
|
+
}, (e) => e.length >= t || `expected >=${t} items`), d = (t, n, r) => e({
|
|
26
|
+
check: "number_format",
|
|
27
|
+
format: t
|
|
28
|
+
}, (e) => Number.isInteger(e) && e >= n && e <= r || `expected a ${t}`), f = (t, n, r) => e({
|
|
29
|
+
check: "bigint_format",
|
|
30
|
+
format: t
|
|
31
|
+
}, (e) => e >= n && e <= r || `expected a ${t}`), p = /* @__PURE__ */ new WeakMap(), m = {
|
|
32
|
+
add(e, t) {
|
|
33
|
+
p.set(e, t);
|
|
34
|
+
},
|
|
35
|
+
get(e) {
|
|
36
|
+
return p.get(e);
|
|
37
|
+
}
|
|
38
|
+
}, h = class extends Error {
|
|
39
|
+
name = "SchemaError";
|
|
40
|
+
}, g = class {
|
|
41
|
+
_zod;
|
|
42
|
+
constructor(e) {
|
|
43
|
+
this._zod = { def: e };
|
|
44
|
+
}
|
|
45
|
+
parse(e) {
|
|
46
|
+
let t = this.inner(e);
|
|
47
|
+
for (let e of this._zod.def.checks ?? []) {
|
|
48
|
+
let n = e.evaluate(t);
|
|
49
|
+
if (n !== !0) throw new h(n);
|
|
50
|
+
}
|
|
51
|
+
return t;
|
|
52
|
+
}
|
|
53
|
+
safeParse(e) {
|
|
54
|
+
try {
|
|
55
|
+
return {
|
|
56
|
+
success: !0,
|
|
57
|
+
data: this.parse(e)
|
|
58
|
+
};
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return {
|
|
61
|
+
success: !1,
|
|
62
|
+
error: e
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
check(...e) {
|
|
67
|
+
let t = Object.create(Object.getPrototypeOf(this));
|
|
68
|
+
t._zod = { def: {
|
|
69
|
+
...this._zod.def,
|
|
70
|
+
checks: [...this._zod.def.checks ?? [], ...e]
|
|
71
|
+
} };
|
|
72
|
+
let n = m.get(this);
|
|
73
|
+
return n && m.add(t, n), t;
|
|
74
|
+
}
|
|
75
|
+
register(e, t) {
|
|
76
|
+
return e.add(this, t), this;
|
|
77
|
+
}
|
|
78
|
+
}, _ = (e) => {
|
|
79
|
+
throw new h(`expected ${e}`);
|
|
80
|
+
}, v = class extends g {
|
|
81
|
+
inner(e) {
|
|
82
|
+
return typeof e == "number" && !Number.isNaN(e) ? e : _("number");
|
|
83
|
+
}
|
|
84
|
+
}, y = class extends g {
|
|
85
|
+
inner(e) {
|
|
86
|
+
return typeof e == "string" ? e : _("string");
|
|
87
|
+
}
|
|
88
|
+
}, b = class extends g {
|
|
89
|
+
inner(e) {
|
|
90
|
+
return typeof e == "boolean" ? e : _("boolean");
|
|
91
|
+
}
|
|
92
|
+
}, x = class extends g {
|
|
93
|
+
inner(e) {
|
|
94
|
+
return typeof e == "bigint" ? e : _("bigint");
|
|
95
|
+
}
|
|
96
|
+
}, S = class extends g {
|
|
97
|
+
inner(e) {
|
|
98
|
+
return e;
|
|
99
|
+
}
|
|
100
|
+
}, C = class extends g {
|
|
101
|
+
inner(e) {
|
|
102
|
+
let t = this._zod.def.cls;
|
|
103
|
+
return e instanceof t ? e : _(t.name ?? "instance");
|
|
104
|
+
}
|
|
105
|
+
}, w = class extends g {
|
|
106
|
+
get shape() {
|
|
107
|
+
return this._zod.def.shape;
|
|
108
|
+
}
|
|
109
|
+
inner(e) {
|
|
110
|
+
(typeof e != "object" || !e || Array.isArray(e)) && _("object");
|
|
111
|
+
let t = {};
|
|
112
|
+
for (let [n, r] of Object.entries(this.shape)) t[n] = r.parse(e[n]);
|
|
113
|
+
return t;
|
|
114
|
+
}
|
|
115
|
+
}, T = class extends g {
|
|
116
|
+
inner(e) {
|
|
117
|
+
if (!Array.isArray(e)) return _("array");
|
|
118
|
+
let t = this._zod.def.element;
|
|
119
|
+
return e.map((e) => t.parse(e));
|
|
120
|
+
}
|
|
121
|
+
}, E = () => new v({ type: "number" }), D = () => new y({ type: "string" }), O = () => new b({ type: "boolean" }), k = () => new x({ type: "bigint" }), A = () => new S({ type: "unknown" }), j = (e) => new C({
|
|
122
|
+
type: "instanceof",
|
|
123
|
+
cls: e
|
|
124
|
+
}), M = (e) => new w({
|
|
125
|
+
type: "object",
|
|
126
|
+
shape: e
|
|
127
|
+
}), N = (e) => new T({
|
|
128
|
+
type: "array",
|
|
129
|
+
element: e
|
|
130
|
+
}), P = () => new v({
|
|
131
|
+
type: "number",
|
|
132
|
+
format: "int32"
|
|
133
|
+
}).check(d("int32", t, n)), F = () => new v({
|
|
134
|
+
type: "number",
|
|
135
|
+
format: "uint32"
|
|
136
|
+
}).check(d("uint32", 0, 4294967295)), I = () => new v({
|
|
137
|
+
type: "number",
|
|
138
|
+
format: "float32"
|
|
139
|
+
}), L = () => new v({
|
|
140
|
+
type: "number",
|
|
141
|
+
format: "float64"
|
|
142
|
+
}), R = () => new x({
|
|
143
|
+
type: "bigint",
|
|
144
|
+
format: "int64"
|
|
145
|
+
}).check(f("int64", -(2n ** 63n), 2n ** 63n - 1n)), z = () => new x({
|
|
146
|
+
type: "bigint",
|
|
147
|
+
format: "uint64"
|
|
148
|
+
}).check(f("uint64", 0n, 2n ** 64n - 1n)), B = /* @__PURE__ */ new Set([
|
|
149
|
+
"string",
|
|
150
|
+
"array",
|
|
151
|
+
"set"
|
|
152
|
+
]), V = (e, t, n) => {
|
|
153
|
+
let r = B.has(e._zod.def.type);
|
|
154
|
+
return t === "min" ? r ? u(n) : i(n) : r ? l(n) : a(n);
|
|
155
|
+
};
|
|
156
|
+
function H(e) {
|
|
157
|
+
let t = e.check.bind(e), n = e.register.bind(e), i = {
|
|
158
|
+
refine: (e, n) => H(t(s(e, n))),
|
|
159
|
+
meta: (t) => t === void 0 ? m.get(e) : H(n(m, t)),
|
|
160
|
+
min: (n) => H(t(V(e, "min", n))),
|
|
161
|
+
max: (n) => H(t(V(e, "max", n))),
|
|
162
|
+
length: (e) => H(t(c(e))),
|
|
163
|
+
int: () => H(t(r()))
|
|
164
|
+
};
|
|
165
|
+
for (let [t, n] of Object.entries(i)) Object.defineProperty(e, t, {
|
|
166
|
+
value: n,
|
|
167
|
+
enumerable: !1,
|
|
168
|
+
configurable: !0
|
|
169
|
+
});
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
var U = {
|
|
173
|
+
number: E,
|
|
174
|
+
string: D,
|
|
175
|
+
boolean: O,
|
|
176
|
+
bigint: k,
|
|
177
|
+
object: M,
|
|
178
|
+
array: N,
|
|
179
|
+
instanceof: j,
|
|
180
|
+
unknown: A,
|
|
181
|
+
int32: P,
|
|
182
|
+
uint32: F,
|
|
183
|
+
float32: I,
|
|
184
|
+
float64: L,
|
|
185
|
+
int64: R,
|
|
186
|
+
uint64: z,
|
|
187
|
+
int: r,
|
|
188
|
+
gte: i,
|
|
189
|
+
lte: a,
|
|
190
|
+
nonnegative: o,
|
|
191
|
+
refine: s,
|
|
192
|
+
length: c,
|
|
193
|
+
maxLength: l,
|
|
194
|
+
minLength: u,
|
|
195
|
+
globalRegistry: m,
|
|
196
|
+
ZodType: g,
|
|
197
|
+
ZodObject: w,
|
|
198
|
+
ZodArray: T,
|
|
199
|
+
ZodString: y
|
|
23
200
|
};
|
|
24
201
|
//#endregion
|
|
25
|
-
export {
|
|
202
|
+
export { h as SchemaError, g as ZodType, H as fluent, m as globalRegistry, U as z };
|
|
26
203
|
|
|
27
204
|
//# sourceMappingURL=index3.js.map
|
package/dist/index4.js
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fluent as e, z as t } from "./index3.js";
|
|
2
2
|
//#region src/contract/listSchema.ts
|
|
3
|
-
var
|
|
4
|
-
i8:
|
|
5
|
-
u8:
|
|
6
|
-
i16:
|
|
7
|
-
u16:
|
|
8
|
-
i32: e
|
|
9
|
-
u32: e
|
|
10
|
-
f32: e.number(),
|
|
11
|
-
f64: e.number(),
|
|
12
|
-
i64: e.bigint(),
|
|
13
|
-
u64: e.bigint().nonnegative()
|
|
14
|
-
},
|
|
15
|
-
function
|
|
16
|
-
let
|
|
17
|
-
for (let e of Object.keys(
|
|
18
|
-
return e.object(
|
|
3
|
+
var n = new TextEncoder(), r = (n, r) => e(t.number().check(t.int(), t.gte(n), t.lte(r))), i = {
|
|
4
|
+
i8: r(-128, 127),
|
|
5
|
+
u8: r(0, 255),
|
|
6
|
+
i16: r(-32768, 32767),
|
|
7
|
+
u16: r(0, 65535),
|
|
8
|
+
i32: e(t.int32()),
|
|
9
|
+
u32: e(t.uint32()),
|
|
10
|
+
f32: e(t.number()),
|
|
11
|
+
f64: e(t.number()),
|
|
12
|
+
i64: e(t.bigint()),
|
|
13
|
+
u64: e(t.bigint().check(t.nonnegative()))
|
|
14
|
+
}, a = (r) => e(t.string().check(t.refine((e) => n.encode(e).byteLength <= r, `exceeds ${r} UTF-8 bytes`)));
|
|
15
|
+
function o(n) {
|
|
16
|
+
let r = {};
|
|
17
|
+
for (let e of Object.keys(n)) r[e] = c(n[e]);
|
|
18
|
+
return e(t.object(r));
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
function s(e) {
|
|
21
|
+
return typeof e == "object" && !!e && typeof e._zod?.def == "object";
|
|
22
|
+
}
|
|
23
|
+
function c(e) {
|
|
24
|
+
if (s(e)) {
|
|
25
|
+
let r = e._zod.def?.type === "string" ? _(e) : void 0;
|
|
26
|
+
if (typeof r != "number") return e;
|
|
27
|
+
let i = (e) => n.encode(e).byteLength <= r, a = `exceeds ${r} UTF-8 bytes`;
|
|
28
|
+
return typeof e.refine == "function" ? e.refine(i, a) : e.check(t.refine(i, a));
|
|
24
29
|
}
|
|
25
|
-
return typeof
|
|
30
|
+
return typeof e == "string" ? i[e] : "string" in e ? a(e.string) : t.boolean();
|
|
26
31
|
}
|
|
27
|
-
var
|
|
32
|
+
var l = {
|
|
28
33
|
int32: "i32",
|
|
29
34
|
uint32: "u32",
|
|
30
35
|
float32: "f32",
|
|
31
36
|
float64: "f64"
|
|
32
|
-
},
|
|
37
|
+
}, u = {
|
|
33
38
|
int64: "i64",
|
|
34
39
|
uint64: "u64"
|
|
35
|
-
},
|
|
40
|
+
}, d = [
|
|
36
41
|
{
|
|
37
42
|
kind: "u8",
|
|
38
43
|
min: 0,
|
|
@@ -63,60 +68,60 @@ var o = {
|
|
|
63
68
|
min: -2147483648,
|
|
64
69
|
max: 2147483647
|
|
65
70
|
}
|
|
66
|
-
],
|
|
67
|
-
function
|
|
68
|
-
let t = [e.format, ...(e.checks ?? []).map((e) =>
|
|
69
|
-
if (n) return
|
|
71
|
+
], f = (e) => e.def ?? e._zod?.def;
|
|
72
|
+
function p(e) {
|
|
73
|
+
let t = [e.format, ...(e.checks ?? []).map((e) => f(e)?.format)], n = t.find((e) => !!e && e in l);
|
|
74
|
+
if (n) return l[n];
|
|
70
75
|
if (t.includes("safeint")) {
|
|
71
76
|
let t = -Infinity, n = Infinity;
|
|
72
77
|
for (let r of e.checks ?? []) {
|
|
73
|
-
let e =
|
|
78
|
+
let e = f(r);
|
|
74
79
|
e?.check === "greater_than" && e.inclusive && (t = e.value ?? t), e?.check === "less_than" && e.inclusive && (n = e.value ?? n);
|
|
75
80
|
}
|
|
76
|
-
for (let e of
|
|
81
|
+
for (let e of d) if (t >= e.min && n <= e.max) return e.kind;
|
|
77
82
|
}
|
|
78
83
|
return "f64";
|
|
79
84
|
}
|
|
80
|
-
function
|
|
81
|
-
if (typeof
|
|
82
|
-
if (!(
|
|
83
|
-
if (typeof
|
|
84
|
-
throw TypeError(`member "${
|
|
85
|
+
function m(e, t) {
|
|
86
|
+
if (typeof e == "string") return e;
|
|
87
|
+
if (!s(e)) {
|
|
88
|
+
if (typeof e.string == "number" || e.bool === !0) return e;
|
|
89
|
+
throw TypeError(`member "${t}": expected a scalar token, { string: n }, { bool: true }, or a zod schema`);
|
|
85
90
|
}
|
|
86
|
-
let
|
|
87
|
-
if (
|
|
88
|
-
if (
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
91
|
-
let
|
|
92
|
-
if (typeof
|
|
93
|
-
throw TypeError(`member "${
|
|
91
|
+
let n = e._zod.def;
|
|
92
|
+
if (n.type === "number") return p(n);
|
|
93
|
+
if (n.type === "bigint") return u[n.format ?? ""] ?? "i64";
|
|
94
|
+
if (n.type === "boolean") return { bool: !0 };
|
|
95
|
+
if (n.type === "string") {
|
|
96
|
+
let n = _(e);
|
|
97
|
+
if (typeof n == "number") return { string: n };
|
|
98
|
+
throw TypeError(`member "${t}": z.string() needs .meta({ bytes: n }) — inline strings are fixed-width`);
|
|
94
99
|
}
|
|
95
|
-
throw TypeError(`member "${
|
|
100
|
+
throw TypeError(`member "${t}": zod "${n.type}" can't lay out as a fixed-width scalar — use number, bigint, boolean, or a bounded string`);
|
|
96
101
|
}
|
|
97
|
-
function
|
|
98
|
-
return
|
|
102
|
+
function h(e) {
|
|
103
|
+
return !s(e) || e._zod.def.type !== "object" ? null : e._zod.def.shape;
|
|
99
104
|
}
|
|
100
|
-
function
|
|
101
|
-
if (!(
|
|
102
|
-
let
|
|
103
|
-
for (let e of
|
|
104
|
-
let t =
|
|
105
|
-
t?.check === "max_length" && typeof t.maximum == "number" && (
|
|
105
|
+
function g(e) {
|
|
106
|
+
if (!s(e) || e._zod.def.type !== "array") return null;
|
|
107
|
+
let t = e._zod.def, n = null;
|
|
108
|
+
for (let e of t.checks ?? []) {
|
|
109
|
+
let t = f(e);
|
|
110
|
+
t?.check === "max_length" && typeof t.maximum == "number" && (n = t.maximum), t?.check === "length_equals" && typeof t.length == "number" && (n = t.length);
|
|
106
111
|
}
|
|
107
112
|
return {
|
|
108
|
-
element:
|
|
109
|
-
capacity:
|
|
113
|
+
element: t.element,
|
|
114
|
+
capacity: n
|
|
110
115
|
};
|
|
111
116
|
}
|
|
112
|
-
function
|
|
113
|
-
let
|
|
114
|
-
return typeof
|
|
117
|
+
function _(e) {
|
|
118
|
+
let n = t.globalRegistry.get(e) ?? e.meta?.();
|
|
119
|
+
return typeof n?.bytes == "number" ? n.bytes : null;
|
|
115
120
|
}
|
|
116
|
-
function
|
|
117
|
-
return
|
|
121
|
+
function v(e) {
|
|
122
|
+
return !s(e) || e._zod.def.type !== "string" ? null : _(e);
|
|
118
123
|
}
|
|
119
124
|
//#endregion
|
|
120
|
-
export {
|
|
125
|
+
export { o as listSchema, m as memberToSpec, g as zodArrayInfo, h as zodObjectShape, v as zodStringBytes };
|
|
121
126
|
|
|
122
127
|
//# sourceMappingURL=index4.js.map
|