@wildo-ai/zod-decorators 1.0.1 → 1.1.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/LICENSE +34 -0
- package/dist/esm/.builder.pid +9 -0
- package/dist/esm/__mocks__/mime.d.ts.map +1 -1
- package/dist/esm/__mocks__/mime.js +1 -1
- package/dist/esm/__mocks__/mime.js.map +1 -1
- package/dist/esm/commons.d.ts.map +1 -1
- package/dist/esm/commons.js +1 -1
- package/dist/esm/commons.js.map +1 -1
- package/dist/esm/companion-exports.d.ts +8 -0
- package/dist/esm/companion-exports.d.ts.map +1 -0
- package/dist/esm/companion-exports.js +8 -0
- package/dist/esm/companion-exports.js.map +1 -0
- package/dist/esm/currencies.shared.schemas.d.ts.map +1 -1
- package/dist/esm/currencies.shared.schemas.js +1 -1
- package/dist/esm/currencies.shared.schemas.js.map +1 -1
- package/dist/esm/files/agent-file-formats.d.ts.map +1 -1
- package/dist/esm/files/agent-file-formats.js +1 -1
- package/dist/esm/files/agent-file-formats.js.map +1 -1
- package/dist/esm/files/extension-nature-map.d.ts +1 -1
- package/dist/esm/files/extension-nature-map.d.ts.map +1 -1
- package/dist/esm/files/extension-nature-map.js +1 -1
- package/dist/esm/files/extension-nature-map.js.map +1 -1
- package/dist/esm/files/file-extensions.enum.d.ts.map +1 -1
- package/dist/esm/files/file-extensions.enum.js +1 -1
- package/dist/esm/files/file-extensions.enum.js.map +1 -1
- package/dist/esm/files/mime-registry.d.ts +1 -1
- package/dist/esm/files/mime-registry.d.ts.map +1 -1
- package/dist/esm/files/mime-registry.js +1 -1
- package/dist/esm/files/mime-registry.js.map +1 -1
- package/dist/esm/files/unified-registry.d.ts +1 -1
- package/dist/esm/files/unified-registry.d.ts.map +1 -1
- package/dist/esm/files/unified-registry.js +1 -1
- package/dist/esm/files/unified-registry.js.map +1 -1
- package/dist/esm/index.d.ts +20 -19
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +10 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install-bigint-json-encoding.d.ts +80 -0
- package/dist/esm/install-bigint-json-encoding.d.ts.map +1 -0
- package/dist/esm/install-bigint-json-encoding.js +85 -0
- package/dist/esm/install-bigint-json-encoding.js.map +1 -0
- package/dist/esm/testing/decorated-test-schemas.d.ts +8 -8
- package/dist/esm/testing/decorated-test-schemas.d.ts.map +1 -1
- package/dist/esm/testing/decorated-test-schemas.js +1 -1
- package/dist/esm/testing/decorated-test-schemas.js.map +1 -1
- package/dist/esm/testing.d.ts +1 -1
- package/dist/esm/testing.d.ts.map +1 -1
- package/dist/esm/testing.js +1 -1
- package/dist/esm/testing.js.map +1 -1
- package/dist/esm/zod-bigdecimal.d.ts +5 -1
- package/dist/esm/zod-bigdecimal.d.ts.map +1 -1
- package/dist/esm/zod-bigdecimal.js +4 -1
- package/dist/esm/zod-bigdecimal.js.map +1 -1
- package/dist/esm/zod-code.d.ts +4 -1
- package/dist/esm/zod-code.d.ts.map +1 -1
- package/dist/esm/zod-code.js +4 -1
- package/dist/esm/zod-code.js.map +1 -1
- package/dist/esm/zod-color.d.ts.map +1 -1
- package/dist/esm/zod-color.js +1 -1
- package/dist/esm/zod-color.js.map +1 -1
- package/dist/esm/zod-decorators.types.d.ts +1410 -56
- package/dist/esm/zod-decorators.types.d.ts.map +1 -1
- package/dist/esm/zod-decorators.types.js +662 -16
- package/dist/esm/zod-decorators.types.js.map +1 -1
- package/dist/esm/zod-duration.d.ts +8 -4
- package/dist/esm/zod-duration.d.ts.map +1 -1
- package/dist/esm/zod-duration.js +2 -1
- package/dist/esm/zod-duration.js.map +1 -1
- package/dist/esm/zod-file.d.ts +75 -14
- package/dist/esm/zod-file.d.ts.map +1 -1
- package/dist/esm/zod-file.js +151 -8
- package/dist/esm/zod-file.js.map +1 -1
- package/dist/esm/zod-money.d.ts +18 -3
- package/dist/esm/zod-money.d.ts.map +1 -1
- package/dist/esm/zod-money.js +4 -1
- package/dist/esm/zod-money.js.map +1 -1
- package/dist/esm/zod-phone.d.ts +37 -1
- package/dist/esm/zod-phone.d.ts.map +1 -1
- package/dist/esm/zod-phone.js +66 -5
- package/dist/esm/zod-phone.js.map +1 -1
- package/dist/esm/zod-range.d.ts +4 -1
- package/dist/esm/zod-range.d.ts.map +1 -1
- package/dist/esm/zod-range.js +4 -1
- package/dist/esm/zod-range.js.map +1 -1
- package/dist/esm/zod-utils.shared.d.ts +411 -6
- package/dist/esm/zod-utils.shared.d.ts.map +1 -1
- package/dist/esm/zod-utils.shared.js +624 -9
- package/dist/esm/zod-utils.shared.js.map +1 -1
- package/dist/esm/zod-versioned.d.ts +1 -1
- package/dist/esm/zod-versioned.d.ts.map +1 -1
- package/dist/esm/zod-versioned.js +1 -1
- package/dist/esm/zod-versioned.js.map +1 -1
- package/dist/esm/zod.module-override.d.ts +458 -68
- package/dist/esm/zod.module-override.d.ts.map +1 -1
- package/dist/esm/zod.module-override.js +1214 -195
- package/dist/esm/zod.module-override.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +20 -11
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide JSON encoding for `bigint` — the type-level counterpart of
|
|
3
|
+
* `Date.prototype.toJSON`.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists
|
|
6
|
+
*
|
|
7
|
+
* `z_money` (`MoneyValue`) stores its `amount` as a `bigint` — deliberately, to
|
|
8
|
+
* avoid the >2^53 precision loss `number` would introduce for monetary amounts.
|
|
9
|
+
* But `bigint` is the one runtime type in the resource pipeline that has **no
|
|
10
|
+
* JSON representation**: `JSON.stringify(1999n)` throws
|
|
11
|
+
* `TypeError: Do not know how to serialize a BigInt`. `Date` never has this
|
|
12
|
+
* problem because `Date.prototype.toJSON` exists, so *every* serializer — Express
|
|
13
|
+
* `res.json`, `socket.io` emit, queue encoders, `redis` cache writes, HMAC
|
|
14
|
+
* integrity hashes, any third-party lib — inherits date→ISO-string encoding for
|
|
15
|
+
* free. `bigint` had no such method, so each of those boundaries had to opt in
|
|
16
|
+
* to a bigint-safe stringify individually — a treadmill where the next bare
|
|
17
|
+
* `JSON.stringify(payload)` silently reintroduces a 500 (and, worse, the
|
|
18
|
+
* `socket.io` encoder is a separate serialization path an Express `json replacer`
|
|
19
|
+
* can never reach).
|
|
20
|
+
*
|
|
21
|
+
* Installing `BigInt.prototype.toJSON` supplies the missing type-level encoding
|
|
22
|
+
* once, so bigint round-trips through *every* JSON boundary exactly as `Date`
|
|
23
|
+
* does — no per-boundary opt-in.
|
|
24
|
+
*
|
|
25
|
+
* ## Encoding choice: decimal STRING, not number
|
|
26
|
+
*
|
|
27
|
+
* `1999n → "1999"`. A string round-trips losslessly (`BigInt("1999")`), whereas
|
|
28
|
+
* `Number(1999n)` would reintroduce precisely the precision risk `bigint` exists
|
|
29
|
+
* to prevent. This matches the framework's documented money wire-contract: the
|
|
30
|
+
* response-parsing schema coerces the decimal-string form back to `bigint` on
|
|
31
|
+
* receive (`applyNetworkBoundaryCoercion` rewrites `z.bigint()` leaves to accept
|
|
32
|
+
* it). The provider-boundary `Number()` narrowing (e.g. Stripe's numeric amount
|
|
33
|
+
* API) stays a deliberate, explicit, local conversion in provider code and is
|
|
34
|
+
* unaffected by this default.
|
|
35
|
+
*
|
|
36
|
+
* ## Why a global built-in augmentation (and why it is safe)
|
|
37
|
+
*
|
|
38
|
+
* This mutates a built-in prototype — normally an anti-pattern. It is the
|
|
39
|
+
* correct choice here for the same reason `Date.prototype.toJSON` is: the JSON
|
|
40
|
+
* form of a value is a property of its *type*, not of each call site. It is
|
|
41
|
+
* additive (no method is being replaced — `BigInt.prototype.toJSON` does not
|
|
42
|
+
* otherwise exist), non-enumerable (invisible to `for...in` / `Object.keys`),
|
|
43
|
+
* and idempotent. No known library relies on `JSON.stringify(bigint)` throwing.
|
|
44
|
+
*
|
|
45
|
+
* Installed as a top-level side effect of `@wildo-ai/zod-decorators` (the package
|
|
46
|
+
* that owns `z_money` and therefore introduces bigint into resource payloads in
|
|
47
|
+
* the first place), so the encoding is guaranteed present wherever money can be —
|
|
48
|
+
* every backend/companion/worker/minion runtime AND the browser (which protects
|
|
49
|
+
* the frontend request-submit path too).
|
|
50
|
+
*
|
|
51
|
+
* ## Network-boundary mechanism map (the canonical trace)
|
|
52
|
+
*
|
|
53
|
+
* `bigint` (money) and `Date` are the two runtime types that do NOT survive a JSON
|
|
54
|
+
* round-trip as themselves. The framework handles BOTH with a symmetric two-half
|
|
55
|
+
* contract. This module is the OUTBOUND (serialize) half for `bigint`; the entries
|
|
56
|
+
* below are its counterparts. When editing any one, keep the pair coherent.
|
|
57
|
+
*
|
|
58
|
+
* | Concern | `Date` | money `bigint` |
|
|
59
|
+
* |---|---|---|
|
|
60
|
+
* | SERIALIZE (runtime type → wire string) — PRIMARY | `Date.prototype.toJSON` (built-in) | **this module** (`installBigIntJsonEncoding`) |
|
|
61
|
+
* | COERCE (wire string → runtime type, on receive) | `z.date()` → `z.coerce.date()` | `z.bigint()` → string-accepting `z.preprocess` |
|
|
62
|
+
* | — both coerce leaves rewritten by | `ResourcesConfigOperationsDtosBuilderUtils.applyNetworkBoundaryCoercion` (`@wildo-ai/saas-models`) — used by the SHARED `responseDto`/`requestDto`, so backend serialize-parse, frontend receive-parse, and worker re-hydration all coerce identically | (same) |
|
|
63
|
+
* | In-BODY pre-serialize normalization (backend) | `transformResponseDates` (Date→ISO string in the body) | **none by design** — bigint stays bigint in the body and relies on the SERIALIZE half above (a `transformResponseBigints` twin would be redundant with this `toJSON`) |
|
|
64
|
+
* | DEFENSE-IN-DEPTH serialize (belt-and-suspenders) | (n/a — `toJSON` is built-in) | `ResourceSerializationUtils.bigIntSafeJsonReplacer` / `stringifyWithBigInt` (queue, webhook), and the Express app-level `json replacer` (`http-server.backend.service`) |
|
|
65
|
+
*
|
|
66
|
+
* Type origin: `MoneyValue.amount` (`z_money`) in this package's `zod-money.ts`.
|
|
67
|
+
*/
|
|
68
|
+
declare global {
|
|
69
|
+
interface BigInt {
|
|
70
|
+
/** JSON representation of this bigint — its decimal string form (lossless). */
|
|
71
|
+
toJSON(): string;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Install `BigInt.prototype.toJSON` (bigint → decimal string) if not already
|
|
76
|
+
* present. Idempotent and safe to call from multiple bootstraps / duplicate
|
|
77
|
+
* package instances — the first install wins and later calls are no-ops.
|
|
78
|
+
*/
|
|
79
|
+
export declare function installBigIntJsonEncoding(): void;
|
|
80
|
+
//# sourceMappingURL=install-bigint-json-encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-bigint-json-encoding.d.ts","sourceRoot":"","sources":["../../../src/install-bigint-json-encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,OAAO,CAAC,MAAM,CAAC;IAGb,UAAU,MAAM;QACd,+EAA+E;QAC/E,MAAM,IAAI,MAAM,CAAC;KAClB;CACF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAUhD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide JSON encoding for `bigint` — the type-level counterpart of
|
|
3
|
+
* `Date.prototype.toJSON`.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists
|
|
6
|
+
*
|
|
7
|
+
* `z_money` (`MoneyValue`) stores its `amount` as a `bigint` — deliberately, to
|
|
8
|
+
* avoid the >2^53 precision loss `number` would introduce for monetary amounts.
|
|
9
|
+
* But `bigint` is the one runtime type in the resource pipeline that has **no
|
|
10
|
+
* JSON representation**: `JSON.stringify(1999n)` throws
|
|
11
|
+
* `TypeError: Do not know how to serialize a BigInt`. `Date` never has this
|
|
12
|
+
* problem because `Date.prototype.toJSON` exists, so *every* serializer — Express
|
|
13
|
+
* `res.json`, `socket.io` emit, queue encoders, `redis` cache writes, HMAC
|
|
14
|
+
* integrity hashes, any third-party lib — inherits date→ISO-string encoding for
|
|
15
|
+
* free. `bigint` had no such method, so each of those boundaries had to opt in
|
|
16
|
+
* to a bigint-safe stringify individually — a treadmill where the next bare
|
|
17
|
+
* `JSON.stringify(payload)` silently reintroduces a 500 (and, worse, the
|
|
18
|
+
* `socket.io` encoder is a separate serialization path an Express `json replacer`
|
|
19
|
+
* can never reach).
|
|
20
|
+
*
|
|
21
|
+
* Installing `BigInt.prototype.toJSON` supplies the missing type-level encoding
|
|
22
|
+
* once, so bigint round-trips through *every* JSON boundary exactly as `Date`
|
|
23
|
+
* does — no per-boundary opt-in.
|
|
24
|
+
*
|
|
25
|
+
* ## Encoding choice: decimal STRING, not number
|
|
26
|
+
*
|
|
27
|
+
* `1999n → "1999"`. A string round-trips losslessly (`BigInt("1999")`), whereas
|
|
28
|
+
* `Number(1999n)` would reintroduce precisely the precision risk `bigint` exists
|
|
29
|
+
* to prevent. This matches the framework's documented money wire-contract: the
|
|
30
|
+
* response-parsing schema coerces the decimal-string form back to `bigint` on
|
|
31
|
+
* receive (`applyNetworkBoundaryCoercion` rewrites `z.bigint()` leaves to accept
|
|
32
|
+
* it). The provider-boundary `Number()` narrowing (e.g. Stripe's numeric amount
|
|
33
|
+
* API) stays a deliberate, explicit, local conversion in provider code and is
|
|
34
|
+
* unaffected by this default.
|
|
35
|
+
*
|
|
36
|
+
* ## Why a global built-in augmentation (and why it is safe)
|
|
37
|
+
*
|
|
38
|
+
* This mutates a built-in prototype — normally an anti-pattern. It is the
|
|
39
|
+
* correct choice here for the same reason `Date.prototype.toJSON` is: the JSON
|
|
40
|
+
* form of a value is a property of its *type*, not of each call site. It is
|
|
41
|
+
* additive (no method is being replaced — `BigInt.prototype.toJSON` does not
|
|
42
|
+
* otherwise exist), non-enumerable (invisible to `for...in` / `Object.keys`),
|
|
43
|
+
* and idempotent. No known library relies on `JSON.stringify(bigint)` throwing.
|
|
44
|
+
*
|
|
45
|
+
* Installed as a top-level side effect of `@wildo-ai/zod-decorators` (the package
|
|
46
|
+
* that owns `z_money` and therefore introduces bigint into resource payloads in
|
|
47
|
+
* the first place), so the encoding is guaranteed present wherever money can be —
|
|
48
|
+
* every backend/companion/worker/minion runtime AND the browser (which protects
|
|
49
|
+
* the frontend request-submit path too).
|
|
50
|
+
*
|
|
51
|
+
* ## Network-boundary mechanism map (the canonical trace)
|
|
52
|
+
*
|
|
53
|
+
* `bigint` (money) and `Date` are the two runtime types that do NOT survive a JSON
|
|
54
|
+
* round-trip as themselves. The framework handles BOTH with a symmetric two-half
|
|
55
|
+
* contract. This module is the OUTBOUND (serialize) half for `bigint`; the entries
|
|
56
|
+
* below are its counterparts. When editing any one, keep the pair coherent.
|
|
57
|
+
*
|
|
58
|
+
* | Concern | `Date` | money `bigint` |
|
|
59
|
+
* |---|---|---|
|
|
60
|
+
* | SERIALIZE (runtime type → wire string) — PRIMARY | `Date.prototype.toJSON` (built-in) | **this module** (`installBigIntJsonEncoding`) |
|
|
61
|
+
* | COERCE (wire string → runtime type, on receive) | `z.date()` → `z.coerce.date()` | `z.bigint()` → string-accepting `z.preprocess` |
|
|
62
|
+
* | — both coerce leaves rewritten by | `ResourcesConfigOperationsDtosBuilderUtils.applyNetworkBoundaryCoercion` (`@wildo-ai/saas-models`) — used by the SHARED `responseDto`/`requestDto`, so backend serialize-parse, frontend receive-parse, and worker re-hydration all coerce identically | (same) |
|
|
63
|
+
* | In-BODY pre-serialize normalization (backend) | `transformResponseDates` (Date→ISO string in the body) | **none by design** — bigint stays bigint in the body and relies on the SERIALIZE half above (a `transformResponseBigints` twin would be redundant with this `toJSON`) |
|
|
64
|
+
* | DEFENSE-IN-DEPTH serialize (belt-and-suspenders) | (n/a — `toJSON` is built-in) | `ResourceSerializationUtils.bigIntSafeJsonReplacer` / `stringifyWithBigInt` (queue, webhook), and the Express app-level `json replacer` (`http-server.backend.service`) |
|
|
65
|
+
*
|
|
66
|
+
* Type origin: `MoneyValue.amount` (`z_money`) in this package's `zod-money.ts`.
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Install `BigInt.prototype.toJSON` (bigint → decimal string) if not already
|
|
70
|
+
* present. Idempotent and safe to call from multiple bootstraps / duplicate
|
|
71
|
+
* package instances — the first install wins and later calls are no-ops.
|
|
72
|
+
*/
|
|
73
|
+
export function installBigIntJsonEncoding() {
|
|
74
|
+
if (typeof BigInt.prototype.toJSON === 'function')
|
|
75
|
+
return;
|
|
76
|
+
Object.defineProperty(BigInt.prototype, 'toJSON', {
|
|
77
|
+
value: function toJSON() {
|
|
78
|
+
return this.toString();
|
|
79
|
+
},
|
|
80
|
+
writable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
enumerable: false,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=install-bigint-json-encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-bigint-json-encoding.js","sourceRoot":"","sources":["../../../src/install-bigint-json-encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAWH;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,KAAK,UAAU;QAAE,OAAO;IAC1D,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE;QAChD,KAAK,EAAE,SAAS,MAAM;YACpB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;QACD,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Process-wide JSON encoding for `bigint` — the type-level counterpart of\n * `Date.prototype.toJSON`.\n *\n * ## Why this exists\n *\n * `z_money` (`MoneyValue`) stores its `amount` as a `bigint` — deliberately, to\n * avoid the >2^53 precision loss `number` would introduce for monetary amounts.\n * But `bigint` is the one runtime type in the resource pipeline that has **no\n * JSON representation**: `JSON.stringify(1999n)` throws\n * `TypeError: Do not know how to serialize a BigInt`. `Date` never has this\n * problem because `Date.prototype.toJSON` exists, so *every* serializer — Express\n * `res.json`, `socket.io` emit, queue encoders, `redis` cache writes, HMAC\n * integrity hashes, any third-party lib — inherits date→ISO-string encoding for\n * free. `bigint` had no such method, so each of those boundaries had to opt in\n * to a bigint-safe stringify individually — a treadmill where the next bare\n * `JSON.stringify(payload)` silently reintroduces a 500 (and, worse, the\n * `socket.io` encoder is a separate serialization path an Express `json replacer`\n * can never reach).\n *\n * Installing `BigInt.prototype.toJSON` supplies the missing type-level encoding\n * once, so bigint round-trips through *every* JSON boundary exactly as `Date`\n * does — no per-boundary opt-in.\n *\n * ## Encoding choice: decimal STRING, not number\n *\n * `1999n → \"1999\"`. A string round-trips losslessly (`BigInt(\"1999\")`), whereas\n * `Number(1999n)` would reintroduce precisely the precision risk `bigint` exists\n * to prevent. This matches the framework's documented money wire-contract: the\n * response-parsing schema coerces the decimal-string form back to `bigint` on\n * receive (`applyNetworkBoundaryCoercion` rewrites `z.bigint()` leaves to accept\n * it). The provider-boundary `Number()` narrowing (e.g. Stripe's numeric amount\n * API) stays a deliberate, explicit, local conversion in provider code and is\n * unaffected by this default.\n *\n * ## Why a global built-in augmentation (and why it is safe)\n *\n * This mutates a built-in prototype — normally an anti-pattern. It is the\n * correct choice here for the same reason `Date.prototype.toJSON` is: the JSON\n * form of a value is a property of its *type*, not of each call site. It is\n * additive (no method is being replaced — `BigInt.prototype.toJSON` does not\n * otherwise exist), non-enumerable (invisible to `for...in` / `Object.keys`),\n * and idempotent. No known library relies on `JSON.stringify(bigint)` throwing.\n *\n * Installed as a top-level side effect of `@wildo-ai/zod-decorators` (the package\n * that owns `z_money` and therefore introduces bigint into resource payloads in\n * the first place), so the encoding is guaranteed present wherever money can be —\n * every backend/companion/worker/minion runtime AND the browser (which protects\n * the frontend request-submit path too).\n *\n * ## Network-boundary mechanism map (the canonical trace)\n *\n * `bigint` (money) and `Date` are the two runtime types that do NOT survive a JSON\n * round-trip as themselves. The framework handles BOTH with a symmetric two-half\n * contract. This module is the OUTBOUND (serialize) half for `bigint`; the entries\n * below are its counterparts. When editing any one, keep the pair coherent.\n *\n * | Concern | `Date` | money `bigint` |\n * |---|---|---|\n * | SERIALIZE (runtime type → wire string) — PRIMARY | `Date.prototype.toJSON` (built-in) | **this module** (`installBigIntJsonEncoding`) |\n * | COERCE (wire string → runtime type, on receive) | `z.date()` → `z.coerce.date()` | `z.bigint()` → string-accepting `z.preprocess` |\n * | — both coerce leaves rewritten by | `ResourcesConfigOperationsDtosBuilderUtils.applyNetworkBoundaryCoercion` (`@wildo-ai/saas-models`) — used by the SHARED `responseDto`/`requestDto`, so backend serialize-parse, frontend receive-parse, and worker re-hydration all coerce identically | (same) |\n * | In-BODY pre-serialize normalization (backend) | `transformResponseDates` (Date→ISO string in the body) | **none by design** — bigint stays bigint in the body and relies on the SERIALIZE half above (a `transformResponseBigints` twin would be redundant with this `toJSON`) |\n * | DEFENSE-IN-DEPTH serialize (belt-and-suspenders) | (n/a — `toJSON` is built-in) | `ResourceSerializationUtils.bigIntSafeJsonReplacer` / `stringifyWithBigInt` (queue, webhook), and the Express app-level `json replacer` (`http-server.backend.service`) |\n *\n * Type origin: `MoneyValue.amount` (`z_money`) in this package's `zod-money.ts`.\n */\n\ndeclare global {\n // The type-level encoding installed by `installBigIntJsonEncoding`. Declared so\n // `BigInt.prototype.toJSON` is typed rather than accessed through `any`.\n interface BigInt {\n /** JSON representation of this bigint — its decimal string form (lossless). */\n toJSON(): string;\n }\n}\n\n/**\n * Install `BigInt.prototype.toJSON` (bigint → decimal string) if not already\n * present. Idempotent and safe to call from multiple bootstraps / duplicate\n * package instances — the first install wins and later calls are no-ops.\n */\nexport function installBigIntJsonEncoding(): void {\n if (typeof BigInt.prototype.toJSON === 'function') return;\n Object.defineProperty(BigInt.prototype, 'toJSON', {\n value: function toJSON(this: bigint): string {\n return this.toString();\n },\n writable: true,\n configurable: true,\n enumerable: false,\n });\n}\n"]}
|
|
@@ -9,19 +9,19 @@ import { z } from 'zod';
|
|
|
9
9
|
* Minimal “resource row” with primary key, summary, FK, and backend-only fields.
|
|
10
10
|
*/
|
|
11
11
|
export declare const decoratedTestEntitySchema: z.ZodObject<{
|
|
12
|
-
_id: import("
|
|
13
|
-
title: import("
|
|
14
|
-
ownerId: import("
|
|
15
|
-
internalNote: import("
|
|
16
|
-
}, z.core.$strip
|
|
12
|
+
_id: import("..").DecoratedPrimitiveZodType<z.ZodString>;
|
|
13
|
+
title: import("..").DecoratedPrimitiveZodType<z.ZodString>;
|
|
14
|
+
ownerId: import("..").DecoratedPrimitiveZodType<z.ZodString>;
|
|
15
|
+
internalNote: import("..").DecoratedPrimitiveZodType<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
17
|
/**
|
|
18
18
|
* Variant-style row with a discriminator enum + summary field.
|
|
19
19
|
*/
|
|
20
20
|
export declare const decoratedTestVariantSchema: z.ZodObject<{
|
|
21
|
-
kind: import("
|
|
21
|
+
kind: import("..").DecoratedPrimitiveZodType<z.ZodEnum<{
|
|
22
22
|
B: "B";
|
|
23
23
|
A: "A";
|
|
24
24
|
}>>;
|
|
25
|
-
label: import("
|
|
26
|
-
}, z.core.$strip
|
|
25
|
+
label: import("..").DecoratedPrimitiveZodType<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
27
|
//# sourceMappingURL=decorated-test-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorated-test-schemas.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"decorated-test-schemas.d.ts","sourceRoot":"","sources":["../../../../src/testing/decorated-test-schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;iBAKpC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;iBAGrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorated-test-schemas.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"decorated-test-schemas.js","sourceRoot":"","sources":["../../../../src/testing/decorated-test-schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAE7B;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE;IAC9B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,cAAc,EAAE;IAClC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE;IAClC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE;CACzC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,cAAc,EAAE;CACnC,CAAC,CAAC","sourcesContent":["/**\n * Canonical decorated Zod shapes for cross-layer tests (engine packages, apps).\n *\n * Importing this file runs `ensureZodDecoratorsLoaded(z)` for the current `zod` instance,\n * then builds schemas using chainable decorators (same pattern as package tests).\n */\nimport { z } from 'zod';\nimport { ensureZodDecoratorsLoaded } from '../zod.module-override';\n\nensureZodDecoratorsLoaded(z);\n\n/**\n * Minimal “resource row” with primary key, summary, FK, and backend-only fields.\n */\nexport const decoratedTestEntitySchema = z.object({\n _id: z.string().isPrimaryKey(),\n title: z.string().isSummaryField(),\n ownerId: z.string().isForeignKey(),\n internalNote: z.string().isBackendOnly(),\n});\n\n/**\n * Variant-style row with a discriminator enum + summary field.\n */\nexport const decoratedTestVariantSchema = z.object({\n kind: z.enum(['A', 'B']).isDiscriminator(),\n label: z.string().isSummaryField(),\n});\n"]}
|
package/dist/esm/testing.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,kCAAkC,CAAC"}
|
package/dist/esm/testing.js
CHANGED
package/dist/esm/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,kCAAkC,CAAC","sourcesContent":["/**\n * Public testing surface for @wildo-ai/zod-decorators.\n * Import from `@wildo-ai/zod-decorators/testing`.\n */\nexport * from './testing/decorated-test-schemas';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DecoratorInput, BigDecimalSchemaOptions, ZodDecorator, ZodDecorator_ParamsType } from "./zod-decorators.types
|
|
1
|
+
import { DecoratorInput, BigDecimalSchemaOptions, ZodDecorator, ZodDecorator_ParamsType } from "./zod-decorators.types";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import Big from "big.js";
|
|
4
4
|
/**
|
|
@@ -35,6 +35,8 @@ export declare const BigDecimalValueSchema: z.ZodString;
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
/**
|
|
38
|
+
* @wildo_source:part:start zod.factories.bigdecimal facet:layer:shared facet:family:schema-factory
|
|
39
|
+
*
|
|
38
40
|
* Creates a bigdecimal schema with metadata for detection and form component rendering.
|
|
39
41
|
*
|
|
40
42
|
* @param options - Configuration options for bigdecimal field
|
|
@@ -67,6 +69,7 @@ export type DecoratedBigDecimalSchema = z.ZodString & {
|
|
|
67
69
|
[ZodDecorator.IS_DB_INDEXED](): DecoratedBigDecimalSchema;
|
|
68
70
|
[ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedBigDecimalSchema;
|
|
69
71
|
[ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedBigDecimalSchema;
|
|
72
|
+
[ZodDecorator.BIGDECIMAL_UI](params?: ZodDecorator_ParamsType[ZodDecorator.BIGDECIMAL_UI]): DecoratedBigDecimalSchema;
|
|
70
73
|
addDecorators(decorators: DecoratorInput[]): DecoratedBigDecimalSchema;
|
|
71
74
|
};
|
|
72
75
|
/**
|
|
@@ -102,6 +105,7 @@ export type DecoratedBigDecimalSchema = z.ZodString & {
|
|
|
102
105
|
* ```
|
|
103
106
|
*/
|
|
104
107
|
export declare function z_bigdecimal(options?: BigDecimalSchemaOptions): DecoratedBigDecimalSchema;
|
|
108
|
+
/** @wildo_source:part:end zod.factories.bigdecimal */
|
|
105
109
|
/**
|
|
106
110
|
* Add two bigdecimal values.
|
|
107
111
|
* @param a - First value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-bigdecimal.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"zod-bigdecimal.d.ts","sourceRoot":"","sources":["../../../src/zod-bigdecimal.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAkE,uBAAuB,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACxL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
44
|
/**
|
|
45
|
+
* @wildo_source:part:start zod.factories.bigdecimal facet:layer:shared facet:family:schema-factory
|
|
46
|
+
*
|
|
45
47
|
* Creates a bigdecimal schema with metadata for detection and form component rendering.
|
|
46
48
|
*
|
|
47
49
|
* @param options - Configuration options for bigdecimal field
|
|
@@ -154,6 +156,7 @@ export function createBigDecimalSchema(options = {}) {
|
|
|
154
156
|
export function z_bigdecimal(options) {
|
|
155
157
|
return createBigDecimalSchema(options);
|
|
156
158
|
}
|
|
159
|
+
/** @wildo_source:part:end zod.factories.bigdecimal */
|
|
157
160
|
// ============================================================================
|
|
158
161
|
// BIGDECIMAL UTILITY FUNCTIONS
|
|
159
162
|
// ============================================================================
|
|
@@ -271,4 +274,4 @@ export function toBigDecimal(value) {
|
|
|
271
274
|
export function fromBigDecimal(value) {
|
|
272
275
|
return new Big(value).toNumber();
|
|
273
276
|
}
|
|
274
|
-
//# sourceMappingURL=zod-bigdecimal.js.map
|
|
277
|
+
//# sourceMappingURL=zod-bigdecimal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-bigdecimal.js","sourceRoot":"","sources":["../../src/zod-bigdecimal.ts"],"names":[],"mappings":"AACA,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,OAAO,EAAkB,eAAe,EAA0E,YAAY,EAA2B,MAAM,wBAAwB,CAAC;AACxL,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,GAAG,MAAM,QAAQ,CAAC;AAYzB;;GAEG;AACH,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM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AsB;IACzD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB;IACnD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["\n// ============================================================================\n// BIGDECIMAL SCHEMA HELPER\n// ============================================================================\n\nimport { DecoratorInput, SCHEMA_METADATA, CustomFieldMetadata, BigDecimalSchemaMetadata, BigDecimalSchemaOptions, ZodDecorator, ZodDecorator_ParamsType } from \"./zod-decorators.types\";\nimport { z } from \"zod\";\nimport { addChainableMethods } from \"./zod.module-override\";\nimport Big from \"big.js\";\n\n/**\n * BigDecimal value type - represents a precise decimal number as a string.\n *\n * Using strings to store decimal values avoids JavaScript's floating-point\n * precision issues. The big.js library is used for precise arithmetic operations.\n *\n * Example: \"19.99\", \"0.00000001\", \"123456789.123456789\"\n */\nexport type BigDecimalValue = string;\n\n/**\n * Validates that a string represents a valid big decimal number.\n */\nfunction isValidBigDecimal(value: string): boolean {\n try {\n new Big(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Zod schema for BigDecimalValue.\n * Validates that the string represents a valid decimal number.\n */\nexport const BigDecimalValueSchema: z.ZodString = z.string().refine(\n isValidBigDecimal,\n { message: \"Invalid decimal number format\" }\n) as z.ZodString;\n\n/**\n * z_bigdecimal() - Creates bigdecimal schemas for precise decimal numbers.\n *\n * BigDecimal values are stored as strings to avoid floating-point precision issues.\n * The big.js library is used for arithmetic operations.\n *\n * @example\n * ```typescript\n * import { z_bigdecimal } from '@wildo-ai/zod-decorators';\n *\n * const price = z_bigdecimal();\n * const quantity = z_bigdecimal({ precision: 8 });\n * const percentage = z_bigdecimal({ min: '0', max: '100' });\n *\n * // With decorators (chainable)\n * z_bigdecimal().bigDecimalUI({ display: { decimalPlaces: 4 } })\n * z_bigdecimal({ precision: 2 }).isHidden({ edit: true })\n * ```\n */\n\n/**\n * @wildo_source:part:start zod.factories.bigdecimal facet:layer:shared facet:family:schema-factory\n *\n * Creates a bigdecimal schema with metadata for detection and form component rendering.\n *\n * @param options - Configuration options for bigdecimal field\n * @returns A Zod string schema with metadata for bigdecimal detection\n *\n * @example\n * ```typescript\n * // Simple bigdecimal\n * const price = z_bigdecimal();\n * // Infers: string\n *\n * // With precision constraint\n * const btcAmount = z_bigdecimal({ precision: 8 });\n *\n * // With min/max constraints\n * const percentage = z_bigdecimal({\n * min: '0',\n * max: '100',\n * precision: 2\n * });\n * ```\n */\nexport function createBigDecimalSchema(\n options: BigDecimalSchemaOptions = {}\n): DecoratedBigDecimalSchema {\n const {\n precision,\n min,\n max,\n } = options;\n\n // Create the base schema with validation\n let bigDecimalSchema = z.string().refine(\n (value) => {\n if (!isValidBigDecimal(value)) return false;\n\n try {\n const bigValue = new Big(value);\n\n // Check precision (decimal places)\n if (precision !== undefined) {\n const decimalPlaces = value.includes('.')\n ? value.split('.')[1]?.length ?? 0\n : 0;\n if (decimalPlaces > precision) return false;\n }\n\n // Check min\n if (min !== undefined) {\n const minValue = new Big(min);\n if (bigValue.lt(minValue)) return false;\n }\n\n // Check max\n if (max !== undefined) {\n const maxValue = new Big(max);\n if (bigValue.gt(maxValue)) return false;\n }\n\n return true;\n } catch {\n return false;\n }\n },\n {\n message: precision !== undefined\n ? `Invalid decimal number (max ${precision} decimal places${min !== undefined ? `, min: ${min}` : ''}${max !== undefined ? `, max: ${max}` : ''})`\n : `Invalid decimal number${min !== undefined ? ` (min: ${min}` : ''}${max !== undefined ? `${min !== undefined ? ', ' : ' ('}max: ${max})` : min !== undefined ? ')' : ''}`\n }\n );\n\n const bigDecimalMetadata: BigDecimalSchemaMetadata = {\n isBigDecimal: true,\n ...(precision !== undefined && { precision }),\n ...(min !== undefined && { min }),\n ...(max !== undefined && { max }),\n };\n\n // Initialize or extend SCHEMA_METADATA with bigdecimal config\n const existingMetadata: CustomFieldMetadata = (bigDecimalSchema as any)[SCHEMA_METADATA] || {};\n (bigDecimalSchema as any)[SCHEMA_METADATA] = {\n ...existingMetadata,\n bigDecimalConfig: bigDecimalMetadata,\n };\n\n // Add chainable decorator methods to the bigdecimal schema instance\n // This allows: z_bigdecimal().bigDecimalUI({ display: { decimalPlaces: 4 } }).isHidden()\n addChainableMethods(bigDecimalSchema);\n\n return bigDecimalSchema as unknown as DecoratedBigDecimalSchema;\n}\n\n/**\n * Return type for bigdecimal schemas - includes decorator methods.\n * Note: IS_FOREIGN_KEY is not applicable to bigdecimal values.\n * IS_DB_INDEXED indexes the string value directly for query optimization.\n */\nexport type DecoratedBigDecimalSchema = z.ZodString & {\n [ZodDecorator.IS_DB_INDEXED](): DecoratedBigDecimalSchema;\n [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedBigDecimalSchema;\n [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedBigDecimalSchema;\n [ZodDecorator.BIGDECIMAL_UI](params?: ZodDecorator_ParamsType[ZodDecorator.BIGDECIMAL_UI]): DecoratedBigDecimalSchema;\n addDecorators(decorators: DecoratorInput[]): DecoratedBigDecimalSchema;\n};\n\n/**\n * Creates a bigdecimal schema for precise decimal numbers stored as strings.\n * Named z_bigdecimal to indicate it's a Zod helper function exported standalone.\n *\n * BigDecimal values are stored as strings to avoid floating-point precision issues.\n * Use big.js for arithmetic operations on these values.\n *\n * @example\n * ```typescript\n * import { z_bigdecimal } from '@wildo-ai/zod-decorators';\n *\n * // Simple usage\n * z_bigdecimal() // Any valid decimal number as string\n *\n * // With options\n * z_bigdecimal({ precision: 2 }) // Max 2 decimal places\n * z_bigdecimal({ min: '0', max: '100' }) // Range constraint\n * z_bigdecimal({ precision: 8, min: '0' }) // Crypto amount\n *\n * // With decorators (chainable)\n * z_bigdecimal().bigDecimalUI({ display: { decimalPlaces: 4 } })\n * z_bigdecimal({ precision: 2 }).isHidden({ edit: true })\n *\n * // Usage example\n * const price: BigDecimalValue = \"19.99\";\n * const btcAmount: BigDecimalValue = \"0.00000001\";\n *\n * // Arithmetic with big.js\n * import Big from 'big.js';\n * const total = new Big(price).plus(\"10.01\").toString(); // \"30.00\"\n * ```\n */\nexport function z_bigdecimal(\n options?: BigDecimalSchemaOptions\n): DecoratedBigDecimalSchema {\n return createBigDecimalSchema(options) as DecoratedBigDecimalSchema;\n}\n/** @wildo_source:part:end zod.factories.bigdecimal */\n\n// ============================================================================\n// BIGDECIMAL UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Add two bigdecimal values.\n * @param a - First value\n * @param b - Second value\n * @returns Sum as string\n */\nexport function bigDecimalAdd(a: BigDecimalValue, b: BigDecimalValue): BigDecimalValue {\n return new Big(a).plus(b).toString();\n}\n\n/**\n * Subtract two bigdecimal values.\n * @param a - Value to subtract from\n * @param b - Value to subtract\n * @returns Difference as string\n */\nexport function bigDecimalSubtract(a: BigDecimalValue, b: BigDecimalValue): BigDecimalValue {\n return new Big(a).minus(b).toString();\n}\n\n/**\n * Multiply two bigdecimal values.\n * @param a - First value\n * @param b - Second value\n * @returns Product as string\n */\nexport function bigDecimalMultiply(a: BigDecimalValue, b: BigDecimalValue): BigDecimalValue {\n return new Big(a).times(b).toString();\n}\n\n/**\n * Divide two bigdecimal values.\n * @param a - Dividend\n * @param b - Divisor\n * @param precision - Number of decimal places for result (default: 20)\n * @returns Quotient as string\n */\nexport function bigDecimalDivide(a: BigDecimalValue, b: BigDecimalValue, precision: number = 20): BigDecimalValue {\n return new Big(a).div(b).round(precision).toString();\n}\n\n/**\n * Compare two bigdecimal values.\n * @param a - First value\n * @param b - Second value\n * @returns -1 if a < b, 0 if a === b, 1 if a > b\n */\nexport function bigDecimalCompare(a: BigDecimalValue, b: BigDecimalValue): -1 | 0 | 1 {\n return new Big(a).cmp(b) as -1 | 0 | 1;\n}\n\n/**\n * Round a bigdecimal value to specified precision.\n * @param value - Value to round\n * @param precision - Number of decimal places\n * @param roundingMode - big.js rounding mode (default: ROUND_HALF_UP)\n * @returns Rounded value as string\n */\nexport function bigDecimalRound(\n value: BigDecimalValue,\n precision: number,\n roundingMode: Big.RoundingMode = Big.roundHalfUp\n): BigDecimalValue {\n return new Big(value).round(precision, roundingMode).toString();\n}\n\n/**\n * Format a bigdecimal value for display with fixed decimal places.\n * @param value - Value to format\n * @param decimalPlaces - Number of decimal places to show\n * @returns Formatted string with trailing zeros if needed\n */\nexport function bigDecimalFormat(value: BigDecimalValue, decimalPlaces: number): string {\n return new Big(value).toFixed(decimalPlaces);\n}\n\n/**\n * Check if a bigdecimal value is zero.\n * @param value - Value to check\n * @returns true if value equals zero\n */\nexport function bigDecimalIsZero(value: BigDecimalValue): boolean {\n return new Big(value).eq(0);\n}\n\n/**\n * Check if a bigdecimal value is positive (> 0).\n * @param value - Value to check\n * @returns true if value is greater than zero\n */\nexport function bigDecimalIsPositive(value: BigDecimalValue): boolean {\n return new Big(value).gt(0);\n}\n\n/**\n * Check if a bigdecimal value is negative (< 0).\n * @param value - Value to check\n * @returns true if value is less than zero\n */\nexport function bigDecimalIsNegative(value: BigDecimalValue): boolean {\n return new Big(value).lt(0);\n}\n\n/**\n * Get the absolute value of a bigdecimal.\n * @param value - Value\n * @returns Absolute value as string\n */\nexport function bigDecimalAbs(value: BigDecimalValue): BigDecimalValue {\n return new Big(value).abs().toString();\n}\n\n/**\n * Convert a number to bigdecimal string.\n * @param value - Number to convert\n * @returns String representation\n */\nexport function toBigDecimal(value: number): BigDecimalValue {\n return new Big(value).toString();\n}\n\n/**\n * Convert a bigdecimal string to number.\n * Warning: May lose precision for very large or very precise numbers.\n * @param value - BigDecimal string\n * @returns Number value\n */\nexport function fromBigDecimal(value: BigDecimalValue): number {\n return new Big(value).toNumber();\n}\n\n"]}
|
package/dist/esm/zod-code.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DecoratorInput, CodeSchemaOptions, CodeLanguage, ZodDecorator, ZodDecorator_ParamsType } from "./zod-decorators.types
|
|
1
|
+
import { DecoratorInput, CodeSchemaOptions, CodeLanguage, ZodDecorator, ZodDecorator_ParamsType } from "./zod-decorators.types";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
/**
|
|
4
4
|
* Code value type - represents a code snippet with language information.
|
|
@@ -22,6 +22,8 @@ export declare const CodeValueSchema: z.ZodObject<{
|
|
|
22
22
|
language: z.ZodString;
|
|
23
23
|
}>;
|
|
24
24
|
/**
|
|
25
|
+
* @wildo_source:part:start zod.factories.code facet:layer:shared facet:family:schema-factory
|
|
26
|
+
*
|
|
25
27
|
* z_code() - Creates code schemas for code snippets with language.
|
|
26
28
|
*
|
|
27
29
|
* @example
|
|
@@ -84,6 +86,7 @@ export type DecoratedCodeSchema = z.ZodObject<{
|
|
|
84
86
|
* ```
|
|
85
87
|
*/
|
|
86
88
|
export declare function z_code(options?: CodeSchemaOptions): DecoratedCodeSchema;
|
|
89
|
+
/** @wildo_source:part:end zod.factories.code */
|
|
87
90
|
/**
|
|
88
91
|
* Get the display name for a code language.
|
|
89
92
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-code.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"zod-code.d.ts","sourceRoot":"","sources":["../../../src/zod-code.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAA4D,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,w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wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAoCrE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAEjG"}
|
package/dist/esm/zod-code.js
CHANGED
|
@@ -24,6 +24,8 @@ export const CodeValueSchema = z.object({
|
|
|
24
24
|
language: z.string(),
|
|
25
25
|
});
|
|
26
26
|
/**
|
|
27
|
+
* @wildo_source:part:start zod.factories.code facet:layer:shared facet:family:schema-factory
|
|
28
|
+
*
|
|
27
29
|
* z_code() - Creates code schemas for code snippets with language.
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
@@ -109,6 +111,7 @@ export function createCodeSchema(options = {}) {
|
|
|
109
111
|
export function z_code(options) {
|
|
110
112
|
return createCodeSchema(options);
|
|
111
113
|
}
|
|
114
|
+
/** @wildo_source:part:end zod.factories.code */
|
|
112
115
|
// ============================================================================
|
|
113
116
|
// UTILITY FUNCTIONS
|
|
114
117
|
// ============================================================================
|
|
@@ -157,4 +160,4 @@ export function getLanguageDisplayName(language) {
|
|
|
157
160
|
export function isCommonLanguage(language) {
|
|
158
161
|
return CommonCodeLanguages.includes(language);
|
|
159
162
|
}
|
|
160
|
-
//# sourceMappingURL=zod-code.js.map
|
|
163
|
+
//# sourceMappingURL=zod-code.js.map
|
package/dist/esm/zod-code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-code.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"zod-code.js","sourceRoot":"","sources":["../../../src/zod-code.ts"],"names":[],"mappings":"AACA,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,OAAO,EAAkB,eAAe,EAA4E,YAAY,EAA2B,MAAM,wBAAwB,CAAC;AAC1L,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EA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QAAQ;QAChB,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,SAAS;QAClB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE,YAAY;QACxB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,YAAY;KACxB,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AACvD,CAAC","sourcesContent":["\n// ============================================================================\n// CODE SCHEMA HELPER\n// ============================================================================\n\nimport { DecoratorInput, SCHEMA_METADATA, CustomFieldMetadata, CodeSchemaMetadata, CodeSchemaOptions, CodeLanguage, ZodDecorator, ZodDecorator_ParamsType } from \"./zod-decorators.types\";\nimport { z } from \"zod\";\nimport { addChainableMethods } from \"./zod.module-override\";\n\n/**\n * Code value type - represents a code snippet with language information.\n */\nexport interface CodeValue {\n /** The code content */\n content: string;\n /** Programming language for syntax highlighting and validation */\n language: string;\n}\n\n/**\n * Common programming languages for code schema language field.\n * Can be extended with any string value.\n */\nexport const CommonCodeLanguages = [\n 'javascript', 'typescript', 'python', 'java', 'csharp', 'cpp', 'c',\n 'go', 'rust', 'ruby', 'php', 'swift', 'kotlin', 'scala',\n 'html', 'css', 'scss', 'less', 'json', 'yaml', 'xml', 'markdown',\n 'sql', 'graphql', 'bash', 'shell', 'powershell',\n 'dockerfile', 'nginx', 'apache',\n 'plaintext'\n] as const;\n\n/**\n * Zod schema for CodeValue.\n */\nexport const CodeValueSchema: z.ZodObject<{ content: z.ZodString; language: z.ZodString }> = z.object({\n content: z.string(),\n language: z.string(),\n});\n\n/**\n * @wildo_source:part:start zod.factories.code facet:layer:shared facet:family:schema-factory\n *\n * z_code() - Creates code schemas for code snippets with language.\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * const snippet = z_code();\n * const restrictedCode = z_code({\n * allowedLanguages: ['javascript', 'typescript', 'python'],\n * maxLength: 10000\n * });\n *\n * // UI props are now set via .codeUI():\n * z_code().codeUI({ defaultLanguage: 'javascript', syntaxHighlighting: true })\n * z_code().codeUI({ display: { showLineNumbers: true }, edit: { showLineNumbers: false } })\n * ```\n */\n\n/**\n * Creates a code schema with metadata for detection and form component rendering.\n *\n * @param options - Configuration options for code field\n * @returns A Zod object schema with metadata for code detection\n */\nexport function createCodeSchema(\n options: CodeSchemaOptions = {}\n): DecoratedCodeSchema {\n const {\n allowedLanguages,\n maxLength,\n minLength,\n } = options;\n\n // Create the content schema with optional length constraints\n let contentSchema = z.string();\n if (minLength !== undefined) {\n contentSchema = contentSchema.min(minLength);\n }\n if (maxLength !== undefined) {\n contentSchema = contentSchema.max(maxLength);\n }\n\n // Language is stored as a string. Allowed languages restriction is enforced\n // through codeConfig.allowedLanguages metadata - UI components read this\n // to filter available options, same pattern as money currencies.\n const languageSchema = z.string();\n\n // Create the code object schema\n const codeSchema = z.object({\n content: contentSchema,\n language: languageSchema,\n });\n\n const codeMetadata: CodeSchemaMetadata = {\n isCode: true,\n ...(allowedLanguages !== undefined && { allowedLanguages }),\n ...(maxLength !== undefined && { maxLength }),\n ...(minLength !== undefined && { minLength }),\n };\n\n // Initialize or extend SCHEMA_METADATA with code config\n const existingMetadata: CustomFieldMetadata = (codeSchema as any)[SCHEMA_METADATA] || {};\n (codeSchema as any)[SCHEMA_METADATA] = {\n ...existingMetadata,\n codeConfig: codeMetadata,\n };\n\n // Add chainable decorator methods to the code schema instance\n addChainableMethods(codeSchema);\n\n return codeSchema as unknown as DecoratedCodeSchema;\n}\n\n/**\n * Return type for code schemas - includes decorator methods.\n * IS_DB_INDEXED will index internal fields (content, language) for query optimization.\n */\nexport type DecoratedCodeSchema = z.ZodObject<{\n content: z.ZodString;\n language: z.ZodString;\n}> & {\n [ZodDecorator.IS_DB_INDEXED](): DecoratedCodeSchema;\n [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedCodeSchema;\n [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedCodeSchema;\n addDecorators(decorators: DecoratorInput[]): DecoratedCodeSchema;\n};\n\n/**\n * Creates a code schema for code snippets with language information.\n * Named z_code to indicate it's a Zod helper function exported standalone.\n *\n * Code values are stored as: { content: string, language: string }\n * - content: The actual code text\n * - language: Programming language identifier for syntax highlighting\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * // Simple usage\n * z_code() // All languages, default 'plaintext'\n *\n * // With options (structural only)\n * z_code({ allowedLanguages: ['javascript', 'typescript'] })\n * z_code({ maxLength: 5000 })\n *\n * // UI props via .codeUI()\n * z_code().codeUI({ defaultLanguage: 'typescript' })\n * z_code().codeUI({ display: { showLineNumbers: false } })\n * ```\n */\nexport function z_code(options?: CodeSchemaOptions): DecoratedCodeSchema {\n return createCodeSchema(options);\n}\n/** @wildo_source:part:end zod.factories.code */\n\n// ============================================================================\n// UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Get the display name for a code language.\n */\nexport function getLanguageDisplayName(language: CodeLanguage): string {\n const displayNames: Record<string, string> = {\n javascript: 'JavaScript',\n typescript: 'TypeScript',\n python: 'Python',\n java: 'Java',\n csharp: 'C#',\n cpp: 'C++',\n c: 'C',\n go: 'Go',\n rust: 'Rust',\n ruby: 'Ruby',\n php: 'PHP',\n swift: 'Swift',\n kotlin: 'Kotlin',\n scala: 'Scala',\n html: 'HTML',\n css: 'CSS',\n scss: 'SCSS',\n less: 'Less',\n json: 'JSON',\n yaml: 'YAML',\n xml: 'XML',\n markdown: 'Markdown',\n sql: 'SQL',\n graphql: 'GraphQL',\n bash: 'Bash',\n shell: 'Shell',\n powershell: 'PowerShell',\n dockerfile: 'Dockerfile',\n nginx: 'Nginx',\n apache: 'Apache',\n plaintext: 'Plain Text',\n };\n\n return displayNames[language] || language;\n}\n\n/**\n * Check if a language is in the common languages list.\n */\nexport function isCommonLanguage(language: string): language is typeof CommonCodeLanguages[number] {\n return CommonCodeLanguages.includes(language as any);\n}\n\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-color.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"zod-color.d.ts","sourceRoot":"","sources":["../../../src/zod-color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,SAyFiB,CAAC;AAEnD,MAAM,MAAM,uBAAuB,GAAG,OAAO,gBAAgB,CAAC"}
|
package/dist/esm/zod-color.js
CHANGED
|
@@ -85,4 +85,4 @@ export const ZodTypeForColors = z.string().refine((color) => {
|
|
|
85
85
|
}, {
|
|
86
86
|
message: 'Invalid color format. Use hex (#fff, #ffffff), rgb(255,255,255), rgba(255,255,255,0.5), hsl(360,100%,50%), hsla(360,100%,50%,0.5), or named colors'
|
|
87
87
|
}).describe('color').brand('color');
|
|
88
|
-
//# sourceMappingURL=zod-color.js.map
|
|
88
|
+
//# sourceMappingURL=zod-color.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-color.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"zod-color.js","sourceRoot":"","sources":["../../../src/zod-color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CA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,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM;QAC1F,WAAW,EAAE,OAAO;QACpB,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc;QACrF,gBAAgB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB;QAC9F,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU;QACpD,aAAa,EAAE,MAAM;QACrB,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ;QAChE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW;QACzF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ;QAC9C,KAAK,EAAE,WAAW,EAAE,WAAW;QAC/B,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS;QAC5F,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW;QAC5D,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW;QAC/C,QAAQ;QACR,OAAO,EAAE,OAAO,EAAE,YAAY;QAC9B,QAAQ,EAAE,aAAa;KACxB,CAAC;IAEF,OAAO,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;AAC1D,CAAC,EAAE;IACD,OAAO,EAAE,oJAAoJ;CAC9J,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,CAAgB,CAAC","sourcesContent":["import { z } from \"zod\";\n\n/**\n * Color validation schema for various color formats\n * Supports: hex (3/6 digits), rgb, rgba, hsl, hsla, and named colors\n */\nexport const ZodTypeForColors: z.ZodString = z.string().refine((color) => {\n // Remove whitespace\n const trimmedColor = color.trim();\n \n // Hex colors: #fff, #ffffff, #FFF, #FFFFFF\n const hexRegex = /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/;\n if (hexRegex.test(trimmedColor)) {\n return true;\n }\n \n // RGB colors: rgb(255, 255, 255)\n const rgbRegex = /^rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)$/;\n const rgbMatch = trimmedColor.match(rgbRegex);\n if (rgbMatch) {\n const [, r, g, b] = rgbMatch;\n return [r, g, b].every(val => parseInt(val) >= 0 && parseInt(val) <= 255);\n }\n \n \n // RGBA colors: rgba(255, 255, 255, 0.5)\n const rgbaRegex = /^rgba\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(0|1|0?\\.\\d+)\\s*\\)$/;\n const rgbaMatch = trimmedColor.match(rgbaRegex);\n if (rgbaMatch) {\n const [, r, g, b, a] = rgbaMatch;\n const rgbValid = [r, g, b].every(val => parseInt(val) >= 0 && parseInt(val) <= 255);\n const alphaValid = parseFloat(a) >= 0 && parseFloat(a) <= 1;\n return rgbValid && alphaValid;\n }\n \n // HSL colors: hsl(360, 100%, 50%)\n const hslRegex = /^hsl\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})%\\s*,\\s*(\\d{1,3})%\\s*\\)$/;\n const hslMatch = trimmedColor.match(hslRegex);\n if (hslMatch) {\n const [, h, s, l] = hslMatch;\n const hValid = parseInt(h) >= 0 && parseInt(h) <= 360;\n const sValid = parseInt(s) >= 0 && parseInt(s) <= 100;\n const lValid = parseInt(l) >= 0 && parseInt(l) <= 100;\n return hValid && sValid && lValid;\n }\n \n // HSLA colors: hsla(360, 100%, 50%, 0.5)\n const hslaRegex = /^hsla\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})%\\s*,\\s*(\\d{1,3})%\\s*,\\s*(0|1|0?\\.\\d+)\\s*\\)$/;\n const hslaMatch = trimmedColor.match(hslaRegex);\n if (hslaMatch) {\n const [, h, s, l, a] = hslaMatch;\n const hValid = parseInt(h) >= 0 && parseInt(h) <= 360;\n const sValid = parseInt(s) >= 0 && parseInt(s) <= 100;\n const lValid = parseInt(l) >= 0 && parseInt(l) <= 100;\n const alphaValid = parseFloat(a) >= 0 && parseFloat(a) <= 1;\n return hValid && sValid && lValid && alphaValid;\n }\n \n // Named colors (basic set)\n const namedColors = [\n 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',\n 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood',\n 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',\n 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkkhaki', 'darkmagenta',\n 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen',\n 'darkslateblue', 'darkslategray', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue',\n 'dimgray', 'dodgerblue',\n 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia',\n 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow',\n 'honeydew', 'hotpink',\n 'indianred', 'indigo', 'ivory',\n 'khaki',\n 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral',\n 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightpink', 'lightsalmon',\n 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightsteelblue', 'lightyellow', 'lime',\n 'limegreen', 'linen',\n 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple',\n 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred',\n 'midnightblue', 'mintcream', 'mistyrose', 'moccasin',\n 'navajowhite', 'navy',\n 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid',\n 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff',\n 'peru', 'pink', 'plum', 'powderblue', 'purple',\n 'red', 'rosybrown', 'royalblue',\n 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue',\n 'slateblue', 'slategray', 'snow', 'springgreen', 'steelblue',\n 'tan', 'teal', 'thistle', 'tomato', 'turquoise',\n 'violet',\n 'wheat', 'white', 'whitesmoke',\n 'yellow', 'yellowgreen'\n ];\n \n return namedColors.includes(trimmedColor.toLowerCase());\n}, {\n message: 'Invalid color format. Use hex (#fff, #ffffff), rgb(255,255,255), rgba(255,255,255,0.5), hsl(360,100%,50%), hsla(360,100%,50%,0.5), or named colors'\n}).describe('color').brand('color') as z.ZodString;\n\nexport type ZodBrandedColorInstance = typeof ZodTypeForColors;\n"]}
|