@atolljs/core 0.1.1 → 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/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 v = {
5
- number: c,
6
- string: u,
7
- boolean: n,
8
- bigint: t,
9
- object: l,
10
- array: e,
11
- instanceof: a,
12
- unknown: p,
13
- int32: o,
14
- uint32: d,
15
- float32: r,
16
- float64: i,
17
- int64: s,
18
- uint64: f,
19
- ZodType: _,
20
- ZodObject: h,
21
- ZodArray: m,
22
- ZodString: g
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 { v as z };
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 { z as e } from "./index3.js";
1
+ import { fluent as e, z as t } from "./index3.js";
2
2
  //#region src/contract/listSchema.ts
3
- var t = new TextEncoder(), n = {
4
- i8: e.number().int().min(-128).max(127),
5
- u8: e.number().int().min(0).max(255),
6
- i16: e.number().int().min(-32768).max(32767),
7
- u16: e.number().int().min(0).max(65535),
8
- i32: e.number().int().min(-2147483648).max(2147483647),
9
- u32: e.number().int().min(0).max(4294967295),
10
- f32: e.number(),
11
- f64: e.number(),
12
- i64: e.bigint(),
13
- u64: e.bigint().nonnegative()
14
- }, r = (n) => e.string().refine((e) => t.encode(e).byteLength <= n, `exceeds ${n} UTF-8 bytes`);
15
- function i(t) {
16
- let n = {};
17
- for (let e of Object.keys(t)) n[e] = a(t[e]);
18
- return e.object(n);
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 a(i) {
21
- if (i instanceof e.ZodType) {
22
- let e = i._zod.def?.type === "string" ? m(i) : void 0;
23
- return typeof e == "number" ? i.refine((n) => t.encode(n).byteLength <= e, `exceeds ${e} UTF-8 bytes`) : i;
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 i == "string" ? n[i] : "string" in i ? r(i.string) : e.boolean();
30
+ return typeof e == "string" ? i[e] : "string" in e ? a(e.string) : t.boolean();
26
31
  }
27
- var o = {
32
+ var l = {
28
33
  int32: "i32",
29
34
  uint32: "u32",
30
35
  float32: "f32",
31
36
  float64: "f64"
32
- }, s = {
37
+ }, u = {
33
38
  int64: "i64",
34
39
  uint64: "u64"
35
- }, c = [
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
- ], l = (e) => e.def ?? e._zod?.def;
67
- function u(e) {
68
- let t = [e.format, ...(e.checks ?? []).map((e) => l(e)?.format)], n = t.find((e) => !!e && e in o);
69
- if (n) return o[n];
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 = l(r);
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 c) if (t >= e.min && n <= e.max) return e.kind;
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 d(t, n) {
81
- if (typeof t == "string") return t;
82
- if (!(t instanceof e.ZodType)) {
83
- if (typeof t.string == "number" || t.bool === !0) return t;
84
- throw TypeError(`member "${n}": expected a scalar token, { string: n }, { bool: true }, or a zod schema`);
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 r = t._zod.def;
87
- if (r.type === "number") return u(r);
88
- if (r.type === "bigint") return s[r.format ?? ""] ?? "i64";
89
- if (r.type === "boolean") return { bool: !0 };
90
- if (r.type === "string") {
91
- let e = m(t);
92
- if (typeof e == "number") return { string: e };
93
- throw TypeError(`member "${n}": z.string() needs .meta({ bytes: n }) — inline strings are fixed-width`);
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 "${n}": zod "${r.type}" can't lay out as a fixed-width scalar — use number, bigint, boolean, or a bounded string`);
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 f(t) {
98
- return t instanceof e.ZodObject ? t._zod.def.shape : null;
102
+ function h(e) {
103
+ return !s(e) || e._zod.def.type !== "object" ? null : e._zod.def.shape;
99
104
  }
100
- function p(t) {
101
- if (!(t instanceof e.ZodArray)) return null;
102
- let n = t._zod.def, r = null;
103
- for (let e of n.checks ?? []) {
104
- let t = l(e);
105
- t?.check === "max_length" && typeof t.maximum == "number" && (r = t.maximum), t?.check === "length_equals" && typeof t.length == "number" && (r = t.length);
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: n.element,
109
- capacity: r
113
+ element: t.element,
114
+ capacity: n
110
115
  };
111
116
  }
112
- function m(e) {
113
- let t = e.meta?.();
114
- return typeof t?.bytes == "number" ? t.bytes : null;
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 h(t) {
117
- return t instanceof e.ZodString ? m(t) : null;
121
+ function v(e) {
122
+ return !s(e) || e._zod.def.type !== "string" ? null : _(e);
118
123
  }
119
124
  //#endregion
120
- export { i as listSchema, d as memberToSpec, p as zodArrayInfo, f as zodObjectShape, h as zodStringBytes };
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