@ts-runtypes/core 0.9.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 +104 -0
- package/bin/skills.mjs +111 -0
- package/dist/cjs/createRTFBinary.js +100 -0
- package/dist/cjs/createRTFunctions.js +38 -0
- package/dist/cjs/enrich/createFriendlyText.js +256 -0
- package/dist/cjs/enrich/friendlyText.js +2 -0
- package/dist/cjs/enrich/mockData.js +2 -0
- package/dist/cjs/formats/bigintFormats.js +10 -0
- package/dist/cjs/formats/datetime/dateFormats.js +2 -0
- package/dist/cjs/formats/datetime/dateTime-pure-fns.js +316 -0
- package/dist/cjs/formats/datetime/dateTimeParams.js +2 -0
- package/dist/cjs/formats/datetime/stringDateTimeFormats.js +2 -0
- package/dist/cjs/formats/datetime/temporalFormats.js +23 -0
- package/dist/cjs/formats/index.js +65 -0
- package/dist/cjs/formats/numberFormats.js +16 -0
- package/dist/cjs/formats/scalars.js +30 -0
- package/dist/cjs/formats/string/string-formats-pure-fns.js +121 -0
- package/dist/cjs/formats/string/string-patterns.js +63 -0
- package/dist/cjs/formats/string/stringFormats.js +51 -0
- package/dist/cjs/getRunType.js +20 -0
- package/dist/cjs/index.js +65 -0
- package/dist/cjs/markers.js +14 -0
- package/dist/cjs/mocking/binarySize.js +43 -0
- package/dist/cjs/mocking/constants.mock.js +86 -0
- package/dist/cjs/mocking/createMockData.js +54 -0
- package/dist/cjs/mocking/mockBigIntFormat.js +40 -0
- package/dist/cjs/mocking/mockDateTimeBounds.js +277 -0
- package/dist/cjs/mocking/mockInvalid.js +222 -0
- package/dist/cjs/mocking/mockNumberFormat.js +46 -0
- package/dist/cjs/mocking/mockOversized.js +89 -0
- package/dist/cjs/mocking/mockRegistry.js +11 -0
- package/dist/cjs/mocking/mockStringFormat.js +192 -0
- package/dist/cjs/mocking/mockTemporal.js +234 -0
- package/dist/cjs/mocking/mockType.js +453 -0
- package/dist/cjs/mocking/mockTypes.js +2 -0
- package/dist/cjs/mocking/mockUtils.js +58 -0
- package/dist/cjs/overrideRTFunctions.js +25 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/runTypeKind.js +60 -0
- package/dist/cjs/runtypes/builderCore.js +39 -0
- package/dist/cjs/runtypes/builderTypes.js +2 -0
- package/dist/cjs/runtypes/circular.js +281 -0
- package/dist/cjs/runtypes/classSerializerRegistry.js +76 -0
- package/dist/cjs/runtypes/dataOnly.js +2 -0
- package/dist/cjs/runtypes/dataView.js +459 -0
- package/dist/cjs/runtypes/entryTuple.js +430 -0
- package/dist/cjs/runtypes/formatAnnotation.js +2 -0
- package/dist/cjs/runtypes/formatPattern.js +17 -0
- package/dist/cjs/runtypes/pure-fns-utils.js +80 -0
- package/dist/cjs/runtypes/pureFn.js +47 -0
- package/dist/cjs/runtypes/rtUtils.js +190 -0
- package/dist/cjs/runtypes/typeFormat.js +2 -0
- package/dist/cjs/runtypes/types.js +2 -0
- package/dist/cjs/schema/atomic.js +43 -0
- package/dist/cjs/schema/compose.js +97 -0
- package/dist/cjs/schema/index.js +46 -0
- package/dist/cjs/schema/static.js +2 -0
- package/dist/cjs/schema/utility.js +43 -0
- package/dist/cjs/standard/createStandardSchema.js +30 -0
- package/dist/cjs/standard/issueMapping.js +32 -0
- package/dist/cjs/standard/spec.js +2 -0
- package/dist/createRTFBinary.d.ts +37 -0
- package/dist/createRTFBinary.d.ts.map +1 -0
- package/dist/createRTFBinary.js +96 -0
- package/dist/createRTFBinary.js.map +1 -0
- package/dist/createRTFunctions.d.ts +63 -0
- package/dist/createRTFunctions.d.ts.map +1 -0
- package/dist/createRTFunctions.js +34 -0
- package/dist/createRTFunctions.js.map +1 -0
- package/dist/enrich/createFriendlyText.d.ts +26 -0
- package/dist/enrich/createFriendlyText.d.ts.map +1 -0
- package/dist/enrich/createFriendlyText.js +252 -0
- package/dist/enrich/createFriendlyText.js.map +1 -0
- package/dist/enrich/friendlyText.d.ts +51 -0
- package/dist/enrich/friendlyText.d.ts.map +1 -0
- package/dist/enrich/friendlyText.js +2 -0
- package/dist/enrich/friendlyText.js.map +1 -0
- package/dist/enrich/mockData.d.ts +47 -0
- package/dist/enrich/mockData.d.ts.map +1 -0
- package/dist/enrich/mockData.js +2 -0
- package/dist/enrich/mockData.js.map +1 -0
- package/dist/formats/bigintFormats.d.ts +38 -0
- package/dist/formats/bigintFormats.d.ts.map +1 -0
- package/dist/formats/bigintFormats.js +8 -0
- package/dist/formats/bigintFormats.js.map +1 -0
- package/dist/formats/datetime/dateFormats.d.ts +11 -0
- package/dist/formats/datetime/dateFormats.d.ts.map +1 -0
- package/dist/formats/datetime/dateFormats.js +2 -0
- package/dist/formats/datetime/dateFormats.js.map +1 -0
- package/dist/formats/datetime/dateTime-pure-fns.d.ts +2 -0
- package/dist/formats/datetime/dateTime-pure-fns.d.ts.map +1 -0
- package/dist/formats/datetime/dateTime-pure-fns.js +315 -0
- package/dist/formats/datetime/dateTime-pure-fns.js.map +1 -0
- package/dist/formats/datetime/dateTimeParams.d.ts +11 -0
- package/dist/formats/datetime/dateTimeParams.d.ts.map +1 -0
- package/dist/formats/datetime/dateTimeParams.js +2 -0
- package/dist/formats/datetime/dateTimeParams.js.map +1 -0
- package/dist/formats/datetime/stringDateTimeFormats.d.ts +34 -0
- package/dist/formats/datetime/stringDateTimeFormats.d.ts.map +1 -0
- package/dist/formats/datetime/stringDateTimeFormats.js +2 -0
- package/dist/formats/datetime/stringDateTimeFormats.js.map +1 -0
- package/dist/formats/datetime/temporalFormats.d.ts +59 -0
- package/dist/formats/datetime/temporalFormats.d.ts.map +1 -0
- package/dist/formats/datetime/temporalFormats.js +21 -0
- package/dist/formats/datetime/temporalFormats.js.map +1 -0
- package/dist/formats/index.d.ts +17 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +11 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/numberFormats.d.ts +78 -0
- package/dist/formats/numberFormats.d.ts.map +1 -0
- package/dist/formats/numberFormats.js +14 -0
- package/dist/formats/numberFormats.js.map +1 -0
- package/dist/formats/scalars.d.ts +33 -0
- package/dist/formats/scalars.d.ts.map +1 -0
- package/dist/formats/scalars.js +23 -0
- package/dist/formats/scalars.js.map +1 -0
- package/dist/formats/string/string-formats-pure-fns.d.ts +2 -0
- package/dist/formats/string/string-formats-pure-fns.d.ts.map +1 -0
- package/dist/formats/string/string-formats-pure-fns.js +120 -0
- package/dist/formats/string/string-formats-pure-fns.js.map +1 -0
- package/dist/formats/string/string-patterns.d.ts +60 -0
- package/dist/formats/string/string-patterns.d.ts.map +1 -0
- package/dist/formats/string/string-patterns.js +61 -0
- package/dist/formats/string/string-patterns.js.map +1 -0
- package/dist/formats/string/stringFormats.d.ts +273 -0
- package/dist/formats/string/stringFormats.d.ts.map +1 -0
- package/dist/formats/string/stringFormats.js +45 -0
- package/dist/formats/string/stringFormats.js.map +1 -0
- package/dist/getRunType.d.ts +5 -0
- package/dist/getRunType.d.ts.map +1 -0
- package/dist/getRunType.js +18 -0
- package/dist/getRunType.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/markers.d.ts +18 -0
- package/dist/markers.d.ts.map +1 -0
- package/dist/markers.js +12 -0
- package/dist/markers.js.map +1 -0
- package/dist/mocking/binarySize.d.ts +11 -0
- package/dist/mocking/binarySize.d.ts.map +1 -0
- package/dist/mocking/binarySize.js +38 -0
- package/dist/mocking/binarySize.js.map +1 -0
- package/dist/mocking/constants.mock.d.ts +8 -0
- package/dist/mocking/constants.mock.d.ts.map +1 -0
- package/dist/mocking/constants.mock.js +84 -0
- package/dist/mocking/constants.mock.js.map +1 -0
- package/dist/mocking/createMockData.d.ts +6 -0
- package/dist/mocking/createMockData.d.ts.map +1 -0
- package/dist/mocking/createMockData.js +52 -0
- package/dist/mocking/createMockData.js.map +1 -0
- package/dist/mocking/mockBigIntFormat.d.ts +2 -0
- package/dist/mocking/mockBigIntFormat.d.ts.map +1 -0
- package/dist/mocking/mockBigIntFormat.js +39 -0
- package/dist/mocking/mockBigIntFormat.js.map +1 -0
- package/dist/mocking/mockDateTimeBounds.d.ts +13 -0
- package/dist/mocking/mockDateTimeBounds.d.ts.map +1 -0
- package/dist/mocking/mockDateTimeBounds.js +272 -0
- package/dist/mocking/mockDateTimeBounds.js.map +1 -0
- package/dist/mocking/mockInvalid.d.ts +15 -0
- package/dist/mocking/mockInvalid.d.ts.map +1 -0
- package/dist/mocking/mockInvalid.js +217 -0
- package/dist/mocking/mockInvalid.js.map +1 -0
- package/dist/mocking/mockNumberFormat.d.ts +2 -0
- package/dist/mocking/mockNumberFormat.d.ts.map +1 -0
- package/dist/mocking/mockNumberFormat.js +45 -0
- package/dist/mocking/mockNumberFormat.js.map +1 -0
- package/dist/mocking/mockOversized.d.ts +4 -0
- package/dist/mocking/mockOversized.d.ts.map +1 -0
- package/dist/mocking/mockOversized.js +87 -0
- package/dist/mocking/mockOversized.js.map +1 -0
- package/dist/mocking/mockRegistry.d.ts +6 -0
- package/dist/mocking/mockRegistry.d.ts.map +1 -0
- package/dist/mocking/mockRegistry.js +8 -0
- package/dist/mocking/mockRegistry.js.map +1 -0
- package/dist/mocking/mockStringFormat.d.ts +2 -0
- package/dist/mocking/mockStringFormat.d.ts.map +1 -0
- package/dist/mocking/mockStringFormat.js +190 -0
- package/dist/mocking/mockStringFormat.js.map +1 -0
- package/dist/mocking/mockTemporal.d.ts +13 -0
- package/dist/mocking/mockTemporal.d.ts.map +1 -0
- package/dist/mocking/mockTemporal.js +230 -0
- package/dist/mocking/mockTemporal.js.map +1 -0
- package/dist/mocking/mockType.d.ts +4 -0
- package/dist/mocking/mockType.d.ts.map +1 -0
- package/dist/mocking/mockType.js +451 -0
- package/dist/mocking/mockType.js.map +1 -0
- package/dist/mocking/mockTypes.d.ts +59 -0
- package/dist/mocking/mockTypes.d.ts.map +1 -0
- package/dist/mocking/mockTypes.js +2 -0
- package/dist/mocking/mockTypes.js.map +1 -0
- package/dist/mocking/mockUtils.d.ts +11 -0
- package/dist/mocking/mockUtils.d.ts.map +1 -0
- package/dist/mocking/mockUtils.js +47 -0
- package/dist/mocking/mockUtils.js.map +1 -0
- package/dist/overrideRTFunctions.d.ts +16 -0
- package/dist/overrideRTFunctions.d.ts.map +1 -0
- package/dist/overrideRTFunctions.js +23 -0
- package/dist/overrideRTFunctions.js.map +1 -0
- package/dist/runTypeKind.d.ts +62 -0
- package/dist/runTypeKind.d.ts.map +1 -0
- package/dist/runTypeKind.js +58 -0
- package/dist/runTypeKind.js.map +1 -0
- package/dist/runtypes/builderCore.d.ts +8 -0
- package/dist/runtypes/builderCore.d.ts.map +1 -0
- package/dist/runtypes/builderCore.js +34 -0
- package/dist/runtypes/builderCore.js.map +1 -0
- package/dist/runtypes/builderTypes.d.ts +47 -0
- package/dist/runtypes/builderTypes.d.ts.map +1 -0
- package/dist/runtypes/builderTypes.js +2 -0
- package/dist/runtypes/builderTypes.js.map +1 -0
- package/dist/runtypes/circular.d.ts +12 -0
- package/dist/runtypes/circular.d.ts.map +1 -0
- package/dist/runtypes/circular.js +273 -0
- package/dist/runtypes/circular.js.map +1 -0
- package/dist/runtypes/classSerializerRegistry.d.ts +29 -0
- package/dist/runtypes/classSerializerRegistry.d.ts.map +1 -0
- package/dist/runtypes/classSerializerRegistry.js +68 -0
- package/dist/runtypes/classSerializerRegistry.js.map +1 -0
- package/dist/runtypes/dataOnly.d.ts +14 -0
- package/dist/runtypes/dataOnly.d.ts.map +1 -0
- package/dist/runtypes/dataOnly.js +2 -0
- package/dist/runtypes/dataOnly.js.map +1 -0
- package/dist/runtypes/dataView.d.ts +104 -0
- package/dist/runtypes/dataView.d.ts.map +1 -0
- package/dist/runtypes/dataView.js +454 -0
- package/dist/runtypes/dataView.js.map +1 -0
- package/dist/runtypes/entryTuple.d.ts +91 -0
- package/dist/runtypes/entryTuple.d.ts.map +1 -0
- package/dist/runtypes/entryTuple.js +422 -0
- package/dist/runtypes/entryTuple.js.map +1 -0
- package/dist/runtypes/formatAnnotation.d.ts +5 -0
- package/dist/runtypes/formatAnnotation.d.ts.map +1 -0
- package/dist/runtypes/formatAnnotation.js +2 -0
- package/dist/runtypes/formatAnnotation.js.map +1 -0
- package/dist/runtypes/formatPattern.d.ts +18 -0
- package/dist/runtypes/formatPattern.d.ts.map +1 -0
- package/dist/runtypes/formatPattern.js +15 -0
- package/dist/runtypes/formatPattern.js.map +1 -0
- package/dist/runtypes/pure-fns-utils.d.ts +7 -0
- package/dist/runtypes/pure-fns-utils.d.ts.map +1 -0
- package/dist/runtypes/pure-fns-utils.js +78 -0
- package/dist/runtypes/pure-fns-utils.js.map +1 -0
- package/dist/runtypes/pureFn.d.ts +5 -0
- package/dist/runtypes/pureFn.d.ts.map +1 -0
- package/dist/runtypes/pureFn.js +45 -0
- package/dist/runtypes/pureFn.js.map +1 -0
- package/dist/runtypes/rtUtils.d.ts +40 -0
- package/dist/runtypes/rtUtils.d.ts.map +1 -0
- package/dist/runtypes/rtUtils.js +181 -0
- package/dist/runtypes/rtUtils.js.map +1 -0
- package/dist/runtypes/typeFormat.d.ts +9 -0
- package/dist/runtypes/typeFormat.d.ts.map +1 -0
- package/dist/runtypes/typeFormat.js +2 -0
- package/dist/runtypes/typeFormat.js.map +1 -0
- package/dist/runtypes/types.d.ts +110 -0
- package/dist/runtypes/types.d.ts.map +1 -0
- package/dist/runtypes/types.js +2 -0
- package/dist/runtypes/types.js.map +1 -0
- package/dist/schema/atomic.d.ts +13 -0
- package/dist/schema/atomic.d.ts.map +1 -0
- package/dist/schema/atomic.js +32 -0
- package/dist/schema/atomic.js.map +1 -0
- package/dist/schema/compose.d.ts +37 -0
- package/dist/schema/compose.d.ts.map +1 -0
- package/dist/schema/compose.js +80 -0
- package/dist/schema/compose.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/static.d.ts +88 -0
- package/dist/schema/static.d.ts.map +1 -0
- package/dist/schema/static.js +2 -0
- package/dist/schema/static.js.map +1 -0
- package/dist/schema/utility.d.ts +13 -0
- package/dist/schema/utility.d.ts.map +1 -0
- package/dist/schema/utility.js +32 -0
- package/dist/schema/utility.js.map +1 -0
- package/dist/standard/createStandardSchema.d.ts +18 -0
- package/dist/standard/createStandardSchema.d.ts.map +1 -0
- package/dist/standard/createStandardSchema.js +28 -0
- package/dist/standard/createStandardSchema.js.map +1 -0
- package/dist/standard/issueMapping.d.ts +13 -0
- package/dist/standard/issueMapping.d.ts.map +1 -0
- package/dist/standard/issueMapping.js +30 -0
- package/dist/standard/issueMapping.js.map +1 -0
- package/dist/standard/spec.d.ts +31 -0
- package/dist/standard/spec.d.ts.map +1 -0
- package/dist/standard/spec.js +2 -0
- package/dist/standard/spec.js.map +1 -0
- package/package.json +87 -0
- package/skills/rt-enrich-types/SKILL.md +194 -0
- package/skills/runtypes-friendly-type/SKILL.md +433 -0
- package/skills/runtypes-mock-data/SKILL.md +195 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
RunTypes Small Organization License 1.0.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ma Jerez. All rights reserved except as expressly granted below.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This license lets individuals and smaller organizations use the software for
|
|
8
|
+
free, subject to the rules below. Larger organizations must obtain a paid
|
|
9
|
+
commercial license. This is a proprietary, source-available style license; it is
|
|
10
|
+
NOT an open source license.
|
|
11
|
+
|
|
12
|
+
## Acceptance
|
|
13
|
+
|
|
14
|
+
To exercise any rights under this license you must agree to its rules. Those
|
|
15
|
+
rules are both obligations under your agreement with the licensor and conditions
|
|
16
|
+
of your license. Do not do anything with the software that this license does not
|
|
17
|
+
expressly permit.
|
|
18
|
+
|
|
19
|
+
## Free License
|
|
20
|
+
|
|
21
|
+
The licensor grants you a non-exclusive, non-transferable, royalty-free,
|
|
22
|
+
worldwide license to install, run, and use the software, and to include it as a
|
|
23
|
+
dependency in your own applications and deploy those applications, provided that:
|
|
24
|
+
|
|
25
|
+
- you qualify as a Small Organization (see below), and
|
|
26
|
+
- you comply with the Limitations below.
|
|
27
|
+
|
|
28
|
+
## Small Organization
|
|
29
|
+
|
|
30
|
+
You qualify for the Free License only if you are:
|
|
31
|
+
|
|
32
|
+
- an individual using the software; or
|
|
33
|
+
- an organization whose total gross revenue, aggregated across the organization
|
|
34
|
+
and all of its affiliates, was less than 10,000,000 US dollars (USD) during its
|
|
35
|
+
most recently completed fiscal year.
|
|
36
|
+
|
|
37
|
+
"Affiliates" means all entities that control, are controlled by, or are under
|
|
38
|
+
common control with an organization.
|
|
39
|
+
|
|
40
|
+
If you do not qualify, you must obtain a Commercial License before using the
|
|
41
|
+
software.
|
|
42
|
+
|
|
43
|
+
## Limitations
|
|
44
|
+
|
|
45
|
+
The Free License does NOT permit you to:
|
|
46
|
+
|
|
47
|
+
- copy or reproduce the software, except as strictly necessary to install and run
|
|
48
|
+
it for your permitted use;
|
|
49
|
+
- modify the software or create derivative works from it;
|
|
50
|
+
- distribute, publish, sublicense, sell, rent, lease, or otherwise make the
|
|
51
|
+
software available to any third party, except as embedded in your own
|
|
52
|
+
applications for their normal operation;
|
|
53
|
+
- reverse engineer, decompile, or disassemble any part of the software provided
|
|
54
|
+
in compiled or binary form, except to the extent this restriction is prohibited
|
|
55
|
+
by applicable law;
|
|
56
|
+
- remove or alter any copyright, license, or other proprietary notices.
|
|
57
|
+
|
|
58
|
+
All rights not expressly granted here are reserved by the licensor.
|
|
59
|
+
|
|
60
|
+
## Commercial License
|
|
61
|
+
|
|
62
|
+
If you do not qualify as a Small Organization, or if you need rights beyond those
|
|
63
|
+
granted by the Free License, you must obtain a separate commercial license from
|
|
64
|
+
the licensor. To request one, contact: jerez.m82@gmail.com.
|
|
65
|
+
|
|
66
|
+
## Notices
|
|
67
|
+
|
|
68
|
+
You must keep this license file, and all copyright and other notices, with every
|
|
69
|
+
copy of the software.
|
|
70
|
+
|
|
71
|
+
## No Other Rights
|
|
72
|
+
|
|
73
|
+
This license does not grant you any rights in the licensor's trademarks, patents,
|
|
74
|
+
or other intellectual property, except the copyright rights expressly stated
|
|
75
|
+
above.
|
|
76
|
+
|
|
77
|
+
## Termination
|
|
78
|
+
|
|
79
|
+
If you violate this license, it terminates automatically. On termination you must
|
|
80
|
+
stop using the software and delete all copies in your possession or control. If
|
|
81
|
+
your violation is capable of cure, your license is reinstated if you cure the
|
|
82
|
+
violation within 30 days of first becoming aware of it, unless the licensor has
|
|
83
|
+
already notified you that your license has terminated.
|
|
84
|
+
|
|
85
|
+
## No Warranty
|
|
86
|
+
|
|
87
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
88
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
89
|
+
FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. YOU BEAR THE ENTIRE RISK OF USING
|
|
90
|
+
THE SOFTWARE.
|
|
91
|
+
|
|
92
|
+
## Limitation of Liability
|
|
93
|
+
|
|
94
|
+
TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
|
95
|
+
FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
96
|
+
TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR
|
|
97
|
+
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
98
|
+
|
|
99
|
+
## Definitions
|
|
100
|
+
|
|
101
|
+
- "Licensor" means Ma Jerez, the copyright holder.
|
|
102
|
+
- "Software" means the RunTypes packages published under the @ts-runtypes npm
|
|
103
|
+
scope, together with any files distributed with them under this license.
|
|
104
|
+
- "You" means the individual or entity exercising rights under this license.
|
package/bin/skills.mjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copies the ts-runtypes agent skills bundled in this package into your skills folder.
|
|
3
|
+
// Dependency-free; Node 18+ (relies on fs.cp). Ships as-is — never built.
|
|
4
|
+
|
|
5
|
+
import { cp, mkdir, readdir, stat } from 'node:fs/promises';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const USAGE = `ts-runtypes-skills — install the RunTypes agent skills into your project
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
npx ts-runtypes-skills --claude copy skills into ./.claude/skills
|
|
13
|
+
npx ts-runtypes-skills --agent copy skills into ./.agent/skills
|
|
14
|
+
npx ts-runtypes-skills --dir <path> copy skills into <path> (resolved from cwd)
|
|
15
|
+
npx ts-runtypes-skills -h | --help show this help
|
|
16
|
+
|
|
17
|
+
Once installed, your AI agent picks the right skill up automatically for enrichment tasks.`;
|
|
18
|
+
|
|
19
|
+
function printUsage(stream = process.stdout) {
|
|
20
|
+
stream.write(USAGE + '\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parseArgs(argv) {
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
if (arg === '-h' || arg === '--help') return { help: true };
|
|
27
|
+
if (arg === '--claude') return { target: resolve(process.cwd(), '.claude', 'skills') };
|
|
28
|
+
if (arg === '--agent') return { target: resolve(process.cwd(), '.agent', 'skills') };
|
|
29
|
+
if (arg === '--dir') {
|
|
30
|
+
const dir = argv[i + 1];
|
|
31
|
+
if (!dir) return { error: '--dir requires a path argument' };
|
|
32
|
+
return { target: resolve(process.cwd(), dir) };
|
|
33
|
+
}
|
|
34
|
+
return { error: `unknown argument: ${arg}` };
|
|
35
|
+
}
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function listSkillDirs(skillsDir) {
|
|
40
|
+
let entries;
|
|
41
|
+
try {
|
|
42
|
+
entries = await readdir(skillsDir, { withFileTypes: true });
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function main() {
|
|
50
|
+
const parsed = parseArgs(process.argv.slice(2));
|
|
51
|
+
|
|
52
|
+
if (parsed.help) {
|
|
53
|
+
printUsage();
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (parsed.error) {
|
|
58
|
+
process.stderr.write(`Error: ${parsed.error}\n\n`);
|
|
59
|
+
printUsage(process.stderr);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!parsed.target) {
|
|
64
|
+
printUsage();
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const bundledSkills = fileURLToPath(new URL('../skills', import.meta.url));
|
|
69
|
+
|
|
70
|
+
// Confirm the bundled skills directory exists and holds at least one skill.
|
|
71
|
+
let bundledStat;
|
|
72
|
+
try {
|
|
73
|
+
bundledStat = await stat(bundledSkills);
|
|
74
|
+
} catch {
|
|
75
|
+
process.stderr.write(`Error: no bundled skills found at ${bundledSkills}\n`);
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
if (!bundledStat.isDirectory()) {
|
|
79
|
+
process.stderr.write(`Error: bundled skills path is not a directory: ${bundledSkills}\n`);
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const skillNames = await listSkillDirs(bundledSkills);
|
|
84
|
+
if (!skillNames || skillNames.length === 0) {
|
|
85
|
+
process.stderr.write(`Error: no skills found inside ${bundledSkills}\n`);
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await mkdir(parsed.target, { recursive: true });
|
|
90
|
+
|
|
91
|
+
for (const skillName of skillNames) {
|
|
92
|
+
const from = resolve(bundledSkills, skillName);
|
|
93
|
+
const to = resolve(parsed.target, skillName);
|
|
94
|
+
await cp(from, to, { recursive: true });
|
|
95
|
+
process.stdout.write(`installed ${skillName} -> ${to}\n`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
process.stdout.write(
|
|
99
|
+
`Done. Copied ${skillNames.length} skill${skillNames.length === 1 ? '' : 's'} into ${parsed.target}\n`,
|
|
100
|
+
);
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
main()
|
|
105
|
+
.then((code) => {
|
|
106
|
+
process.exitCode = code;
|
|
107
|
+
})
|
|
108
|
+
.catch((err) => {
|
|
109
|
+
process.stderr.write(`Error: ${err && err.message ? err.message : err}\n`);
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBinaryEncoder = createBinaryEncoder;
|
|
4
|
+
exports.createBinarySizer = createBinarySizer;
|
|
5
|
+
exports.createBinaryDecoder = createBinaryDecoder;
|
|
6
|
+
const rtUtils_ts_1 = require("./runtypes/rtUtils.js");
|
|
7
|
+
const entryTuple_ts_1 = require("./runtypes/entryTuple.js");
|
|
8
|
+
const dataView_ts_1 = require("./runtypes/dataView.js");
|
|
9
|
+
const noopToBinaryFn = (_v, Ser) => Ser;
|
|
10
|
+
const noopFromBinaryFn = (ret) => ret;
|
|
11
|
+
function fixedBufferTooSmall(capacity) {
|
|
12
|
+
return new RangeError(`createBinaryEncoder: the payload does not fit in the ${capacity}-byte buffer. ` +
|
|
13
|
+
`Use createBinarySizer<T>() to compute the exact size, enlarge the buffer, or use sizeStrategy 'dynamic' / 'precalculate'.`);
|
|
14
|
+
}
|
|
15
|
+
function encodeFixed(encodeFn, value, ser, capacity) {
|
|
16
|
+
try {
|
|
17
|
+
encodeFn(value, ser);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (err instanceof RangeError)
|
|
21
|
+
throw fixedBufferTooSmall(capacity);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
if (ser.getLength() > capacity)
|
|
25
|
+
throw fixedBufferTooSmall(capacity);
|
|
26
|
+
return ser.getBufferView();
|
|
27
|
+
}
|
|
28
|
+
function binarySizingKey(schemaId, injected) {
|
|
29
|
+
if (schemaId !== undefined)
|
|
30
|
+
return schemaId;
|
|
31
|
+
if ((0, entryTuple_ts_1.isEntryTuple)(injected))
|
|
32
|
+
return (0, entryTuple_ts_1.entryTupleKey)(injected).slice(entryTuple_ts_1.FN_HASH_LEN + 1);
|
|
33
|
+
return 'unknown';
|
|
34
|
+
}
|
|
35
|
+
function createBinaryEncoder(valOrSchema, options, id) {
|
|
36
|
+
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
37
|
+
const cacheKey = options?.cacheKey ?? binarySizingKey(schemaId, id);
|
|
38
|
+
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinaryEncoder', noopToBinaryFn, schemaId, id, options?.rejectCircularRefs);
|
|
39
|
+
const sizeStrategy = options?.sizeStrategy ?? 'dynamic';
|
|
40
|
+
if (sizeStrategy === 'precalculate') {
|
|
41
|
+
const fn = (value) => {
|
|
42
|
+
const sizer = (0, dataView_ts_1.createSizingSerializer)(cacheKey);
|
|
43
|
+
encodeFn(value, sizer);
|
|
44
|
+
const ser = (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { size: sizer.getLength(), grow: false });
|
|
45
|
+
encodeFn(value, ser);
|
|
46
|
+
ser.markAsEnded();
|
|
47
|
+
return ser.getBufferView();
|
|
48
|
+
};
|
|
49
|
+
return fn;
|
|
50
|
+
}
|
|
51
|
+
if (sizeStrategy === 'initialSize') {
|
|
52
|
+
const fn = (value, size) => {
|
|
53
|
+
if (typeof size !== 'number')
|
|
54
|
+
throw new Error("createBinaryEncoder: sizeStrategy 'initialSize' requires a numeric `size` argument.");
|
|
55
|
+
return encodeFixed(encodeFn, value, (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { size, grow: false }), size);
|
|
56
|
+
};
|
|
57
|
+
return fn;
|
|
58
|
+
}
|
|
59
|
+
if (sizeStrategy === 'intoBuffer') {
|
|
60
|
+
const fn = (value, into) => {
|
|
61
|
+
if (!(into instanceof ArrayBuffer))
|
|
62
|
+
throw new Error("createBinaryEncoder: sizeStrategy 'intoBuffer' requires an ArrayBuffer `into` argument.");
|
|
63
|
+
return encodeFixed(encodeFn, value, (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { buffer: into }), into.byteLength);
|
|
64
|
+
};
|
|
65
|
+
return fn;
|
|
66
|
+
}
|
|
67
|
+
const coldStartSize = (0, entryTuple_ts_1.binarySizeEstimateFromTuple)(id);
|
|
68
|
+
const fn = (value) => {
|
|
69
|
+
const ser = (0, dataView_ts_1.createDataViewSerializer)(cacheKey, { grow: true, coldStartSize });
|
|
70
|
+
encodeFn(value, ser);
|
|
71
|
+
ser.markAsEnded();
|
|
72
|
+
return ser.getBufferView();
|
|
73
|
+
};
|
|
74
|
+
return fn;
|
|
75
|
+
}
|
|
76
|
+
function createBinarySizer(valOrSchema, id) {
|
|
77
|
+
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
78
|
+
const cacheKey = binarySizingKey(schemaId, id);
|
|
79
|
+
const encodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinarySizer', noopToBinaryFn, schemaId, id);
|
|
80
|
+
return (value) => {
|
|
81
|
+
const sizer = (0, dataView_ts_1.createSizingSerializer)(cacheKey);
|
|
82
|
+
encodeFn(value, sizer);
|
|
83
|
+
return sizer.getLength();
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createBinaryDecoder(valOrSchema, options, id) {
|
|
87
|
+
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(valOrSchema) ? valOrSchema.id : undefined;
|
|
88
|
+
const cacheKey = options?.cacheKey ?? binarySizingKey(schemaId, id);
|
|
89
|
+
const decodeFn = (0, entryTuple_ts_1.resolveEntryTupleFn)('createBinaryDecoder', noopFromBinaryFn, schemaId, id);
|
|
90
|
+
return ((input) => {
|
|
91
|
+
let des;
|
|
92
|
+
if (input && typeof input.desString === 'function') {
|
|
93
|
+
des = input;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
des = (0, dataView_ts_1.createDataViewDeserializer)(cacheKey, input);
|
|
97
|
+
}
|
|
98
|
+
return decodeFn(undefined, des);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFormatTransform = exports.createUnknownKeysToUndefined = exports.createUnknownKeyErrors = exports.createStripUnknownKeys = exports.createHasUnknownKeys = exports.createGetValidationErrors = exports.createValidate = void 0;
|
|
4
|
+
exports.createJsonEncoder = createJsonEncoder;
|
|
5
|
+
exports.createJsonDecoder = createJsonDecoder;
|
|
6
|
+
const rtUtils_ts_1 = require("./runtypes/rtUtils.js");
|
|
7
|
+
const entryTuple_ts_1 = require("./runtypes/entryTuple.js");
|
|
8
|
+
function resolveTupleEntry(fnName, identityFn, val, args, rejectCircularRefs) {
|
|
9
|
+
const schemaId = (0, rtUtils_ts_1.isRunTypeSchema)(val) ? val.id : undefined;
|
|
10
|
+
return (0, entryTuple_ts_1.resolveEntryTupleFn)(fnName, identityFn, schemaId, args, rejectCircularRefs);
|
|
11
|
+
}
|
|
12
|
+
function readRejectCircularRefs(options) {
|
|
13
|
+
return options?.rejectCircularRefs;
|
|
14
|
+
}
|
|
15
|
+
function createTypeFnArgsFunction(fnName, identityFn) {
|
|
16
|
+
return (val, options, args) => resolveTupleEntry(fnName, identityFn, val, args, readRejectCircularRefs(options));
|
|
17
|
+
}
|
|
18
|
+
function createRTFunction(fnName, identityFn) {
|
|
19
|
+
return (val, args) => resolveTupleEntry(fnName, identityFn, val, args);
|
|
20
|
+
}
|
|
21
|
+
const identityValueFn = (v) => v;
|
|
22
|
+
const getValidationErrorsIdentity = () => [];
|
|
23
|
+
const unknownKeyErrorsIdentity = () => [];
|
|
24
|
+
exports.createValidate = createTypeFnArgsFunction('createValidate', (() => true));
|
|
25
|
+
exports.createGetValidationErrors = createTypeFnArgsFunction('createGetValidationErrors', getValidationErrorsIdentity);
|
|
26
|
+
exports.createHasUnknownKeys = createRTFunction('createHasUnknownKeys', () => false);
|
|
27
|
+
exports.createStripUnknownKeys = createRTFunction('createStripUnknownKeys', identityValueFn);
|
|
28
|
+
exports.createUnknownKeyErrors = createRTFunction('createUnknownKeyErrors', unknownKeyErrorsIdentity);
|
|
29
|
+
exports.createUnknownKeysToUndefined = createRTFunction('createUnknownKeysToUndefined', identityValueFn);
|
|
30
|
+
exports.createFormatTransform = createRTFunction('createFormatTransform', identityValueFn);
|
|
31
|
+
const jsonStringifyFallback = (v) => JSON.stringify(v);
|
|
32
|
+
const jsonParseFallback = (s) => JSON.parse(s);
|
|
33
|
+
function createJsonEncoder(valOrSchema, options, id) {
|
|
34
|
+
return resolveTupleEntry('createJsonEncoder', jsonStringifyFallback, valOrSchema, id, options?.rejectCircularRefs);
|
|
35
|
+
}
|
|
36
|
+
function createJsonDecoder(valOrSchema, options, id) {
|
|
37
|
+
return resolveTupleEntry('createJsonDecoder', jsonParseFallback, valOrSchema, id);
|
|
38
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFriendlyText = createFriendlyText;
|
|
4
|
+
exports.resolveLocale = resolveLocale;
|
|
5
|
+
exports.createFriendlyTextI18n = createFriendlyTextI18n;
|
|
6
|
+
const PLACEHOLDER = /\$\[(\w+)\]/g;
|
|
7
|
+
const DEFAULT_LOCALE = 'en';
|
|
8
|
+
const pluralRulesCache = new Map();
|
|
9
|
+
const boundNumberFormatCache = new Map();
|
|
10
|
+
const boundDateFormatCache = new Map();
|
|
11
|
+
function cachedPluralRules(locale) {
|
|
12
|
+
let rules = pluralRulesCache.get(locale);
|
|
13
|
+
if (!rules) {
|
|
14
|
+
rules = new Intl.PluralRules(locale, { type: 'cardinal' });
|
|
15
|
+
pluralRulesCache.set(locale, rules);
|
|
16
|
+
}
|
|
17
|
+
return rules;
|
|
18
|
+
}
|
|
19
|
+
function cachedBoundNumberFormat(locale, currency) {
|
|
20
|
+
const key = locale + '\0' + (currency ?? '');
|
|
21
|
+
let format = boundNumberFormatCache.get(key);
|
|
22
|
+
if (!format) {
|
|
23
|
+
try {
|
|
24
|
+
format = currency ? new Intl.NumberFormat(locale, { style: 'currency', currency }) : new Intl.NumberFormat(locale);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
format = new Intl.NumberFormat(locale);
|
|
28
|
+
}
|
|
29
|
+
boundNumberFormatCache.set(key, format);
|
|
30
|
+
}
|
|
31
|
+
return format;
|
|
32
|
+
}
|
|
33
|
+
const DATE_BOUND_OPTIONS = {
|
|
34
|
+
date: { dateStyle: 'medium' },
|
|
35
|
+
temporalPlainDate: { dateStyle: 'medium' },
|
|
36
|
+
temporalPlainYearMonth: { year: 'numeric', month: 'long' },
|
|
37
|
+
dateTime: { dateStyle: 'medium', timeStyle: 'short' },
|
|
38
|
+
nativeDate: { dateStyle: 'medium', timeStyle: 'short' },
|
|
39
|
+
temporalInstant: { dateStyle: 'medium', timeStyle: 'short' },
|
|
40
|
+
temporalZonedDateTime: { dateStyle: 'medium', timeStyle: 'short' },
|
|
41
|
+
temporalPlainDateTime: { dateStyle: 'medium', timeStyle: 'short' },
|
|
42
|
+
time: { timeStyle: 'short' },
|
|
43
|
+
temporalPlainTime: { timeStyle: 'short' },
|
|
44
|
+
};
|
|
45
|
+
function cachedBoundDateFormat(locale, formatName) {
|
|
46
|
+
const key = locale + '\0' + formatName;
|
|
47
|
+
let format = boundDateFormatCache.get(key);
|
|
48
|
+
if (!format) {
|
|
49
|
+
format = new Intl.DateTimeFormat(locale, DATE_BOUND_OPTIONS[formatName]);
|
|
50
|
+
boundDateFormatCache.set(key, format);
|
|
51
|
+
}
|
|
52
|
+
return format;
|
|
53
|
+
}
|
|
54
|
+
function selectPlural(leaf, bound, locale) {
|
|
55
|
+
const count = Number(bound);
|
|
56
|
+
if (!Number.isFinite(count))
|
|
57
|
+
return leaf.other;
|
|
58
|
+
const category = cachedPluralRules(locale).select(count);
|
|
59
|
+
return leaf[category] || leaf.other;
|
|
60
|
+
}
|
|
61
|
+
function segmentKey(seg) {
|
|
62
|
+
if (typeof seg === 'string' || typeof seg === 'number')
|
|
63
|
+
return seg;
|
|
64
|
+
return seg.key;
|
|
65
|
+
}
|
|
66
|
+
function descend(node, seg) {
|
|
67
|
+
if (!node)
|
|
68
|
+
return undefined;
|
|
69
|
+
if (typeof seg === 'string')
|
|
70
|
+
return node[seg];
|
|
71
|
+
if (typeof seg === 'number')
|
|
72
|
+
return node.rt$slots ? node.rt$slots[seg] : node.rt$items;
|
|
73
|
+
return seg.failed === 'mapKey' ? node.rt$keys : node.rt$values;
|
|
74
|
+
}
|
|
75
|
+
function nodeAt(root, path) {
|
|
76
|
+
let node = root;
|
|
77
|
+
for (const seg of path)
|
|
78
|
+
node = descend(node, seg);
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
function rawLabel(path) {
|
|
82
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
83
|
+
if (typeof path[i] === 'string')
|
|
84
|
+
return path[i];
|
|
85
|
+
}
|
|
86
|
+
const tail = path.length ? segmentKey(path[path.length - 1]) : undefined;
|
|
87
|
+
return tail === undefined ? '' : String(tail);
|
|
88
|
+
}
|
|
89
|
+
function pathToString(path) {
|
|
90
|
+
return path.map((seg) => String(segmentKey(seg))).join('.');
|
|
91
|
+
}
|
|
92
|
+
function constraintKey(format) {
|
|
93
|
+
if (!format)
|
|
94
|
+
return 'type';
|
|
95
|
+
const tail = format.formatPath[format.formatPath.length - 1];
|
|
96
|
+
return tail !== undefined ? String(tail) : format.name;
|
|
97
|
+
}
|
|
98
|
+
function primitiveVal(val) {
|
|
99
|
+
const kind = typeof val;
|
|
100
|
+
if (kind === 'string' || kind === 'number' || kind === 'boolean' || kind === 'bigint') {
|
|
101
|
+
return val;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
function numericIndex(path) {
|
|
106
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
107
|
+
const key = segmentKey(path[i]);
|
|
108
|
+
if (typeof key === 'number')
|
|
109
|
+
return key;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
function interpolate(template, ctx) {
|
|
114
|
+
return template.replace(PLACEHOLDER, (whole, name) => {
|
|
115
|
+
if (name === 'label')
|
|
116
|
+
return ctx.label;
|
|
117
|
+
if (name === 'val')
|
|
118
|
+
return ctx.valText ?? '';
|
|
119
|
+
if (name === 'path')
|
|
120
|
+
return ctx.path;
|
|
121
|
+
if (name === 'index')
|
|
122
|
+
return ctx.index === undefined ? '' : String(ctx.index);
|
|
123
|
+
return whole;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function groupSignature(path) {
|
|
127
|
+
return path.map((seg) => (typeof seg === 'object' ? `${seg.key} ${seg.failed ?? ''}` : String(seg))).join('.');
|
|
128
|
+
}
|
|
129
|
+
function groupByPath(errs) {
|
|
130
|
+
const groups = [];
|
|
131
|
+
const bySignature = new Map();
|
|
132
|
+
for (const err of errs) {
|
|
133
|
+
const signature = groupSignature(err.path);
|
|
134
|
+
let group = bySignature.get(signature);
|
|
135
|
+
if (!group) {
|
|
136
|
+
group = { path: err.path, pathStr: pathToString(err.path), errors: [] };
|
|
137
|
+
bySignature.set(signature, group);
|
|
138
|
+
groups.push(group);
|
|
139
|
+
}
|
|
140
|
+
group.errors.push(err);
|
|
141
|
+
}
|
|
142
|
+
return groups;
|
|
143
|
+
}
|
|
144
|
+
function renderBoundText(state, format, val) {
|
|
145
|
+
if (val === undefined)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (!state.i18n || !format)
|
|
148
|
+
return String(val);
|
|
149
|
+
if (format.isCurrency) {
|
|
150
|
+
const numeric = Number(val);
|
|
151
|
+
if (!Number.isFinite(numeric))
|
|
152
|
+
return String(val);
|
|
153
|
+
return cachedBoundNumberFormat(state.rootLocale, state.currency).format(numeric);
|
|
154
|
+
}
|
|
155
|
+
if (DATE_BOUND_OPTIONS[format.name] && (typeof val === 'string' || typeof val === 'number')) {
|
|
156
|
+
const date = new Date(val);
|
|
157
|
+
if (Number.isNaN(date.getTime()))
|
|
158
|
+
return String(val);
|
|
159
|
+
return cachedBoundDateFormat(state.rootLocale, format.name).format(date);
|
|
160
|
+
}
|
|
161
|
+
return String(val);
|
|
162
|
+
}
|
|
163
|
+
const labelFor = (node, path) => node?.rt$label || rawLabel(path);
|
|
164
|
+
function resolveTemplate(node, key, val, mapLocale) {
|
|
165
|
+
const errorTemplates = node?.rt$errors;
|
|
166
|
+
if (!errorTemplates)
|
|
167
|
+
return undefined;
|
|
168
|
+
return leafTemplate(errorTemplates[key], val, mapLocale) ?? leafTemplate(errorTemplates.rt$default, val, mapLocale);
|
|
169
|
+
}
|
|
170
|
+
function leafTemplate(leaf, val, mapLocale) {
|
|
171
|
+
if (leaf === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
const template = typeof leaf === 'string' ? leaf : selectPlural(leaf, val, mapLocale);
|
|
174
|
+
return template || undefined;
|
|
175
|
+
}
|
|
176
|
+
function renderLabel(state, path) {
|
|
177
|
+
const segs = typeof path === 'string' ? (path === '' ? [] : path.split('.')) : path;
|
|
178
|
+
const node = nodeAt(state.root, segs);
|
|
179
|
+
if (node?.rt$label)
|
|
180
|
+
return node.rt$label;
|
|
181
|
+
const sourceNode = state.source ? nodeAt(state.source, segs) : undefined;
|
|
182
|
+
return labelFor(sourceNode, segs);
|
|
183
|
+
}
|
|
184
|
+
function renderErrors(state, errs) {
|
|
185
|
+
const out = [];
|
|
186
|
+
for (const group of groupByPath(errs)) {
|
|
187
|
+
const node = nodeAt(state.root, group.path);
|
|
188
|
+
const sourceNode = state.source ? nodeAt(state.source, group.path) : undefined;
|
|
189
|
+
const label = node?.rt$label || sourceNode?.rt$label || rawLabel(group.path);
|
|
190
|
+
const index = numericIndex(group.path);
|
|
191
|
+
for (const err of group.errors) {
|
|
192
|
+
const key = constraintKey(err.format);
|
|
193
|
+
const val = primitiveVal(err.format?.val);
|
|
194
|
+
const template = resolveTemplate(node, key, val, state.rootLocale) ?? resolveTemplate(sourceNode, key, val, state.sourceLocale);
|
|
195
|
+
const message = template
|
|
196
|
+
? interpolate(template, {
|
|
197
|
+
label,
|
|
198
|
+
valText: renderBoundText(state, err.format, val),
|
|
199
|
+
path: group.pathStr,
|
|
200
|
+
index,
|
|
201
|
+
})
|
|
202
|
+
: `${label || 'value'} is invalid`;
|
|
203
|
+
out.push({ path: group.pathStr, label, message });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
function createFriendlyText(map) {
|
|
209
|
+
const state = {
|
|
210
|
+
root: map,
|
|
211
|
+
rootLocale: DEFAULT_LOCALE,
|
|
212
|
+
sourceLocale: DEFAULT_LOCALE,
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
label: (path) => renderLabel(state, path),
|
|
216
|
+
errors: (errs) => renderErrors(state, errs),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function resolveLocale(locale, translations) {
|
|
220
|
+
if (!locale)
|
|
221
|
+
return undefined;
|
|
222
|
+
const have = (tag) => translations[tag] !== undefined;
|
|
223
|
+
const parts = locale.split('-');
|
|
224
|
+
for (let keep = parts.length; keep >= 1; keep--) {
|
|
225
|
+
const candidate = parts.slice(0, keep).join('-');
|
|
226
|
+
if (have(candidate))
|
|
227
|
+
return candidate;
|
|
228
|
+
}
|
|
229
|
+
const baseLanguage = parts[0].toLowerCase();
|
|
230
|
+
for (const tag of Object.keys(translations)) {
|
|
231
|
+
if (translations[tag] !== undefined && tag.split('-')[0].toLowerCase() === baseLanguage)
|
|
232
|
+
return tag;
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
function createFriendlyTextI18n(source, options) {
|
|
237
|
+
const sourceRoot = source;
|
|
238
|
+
const sourceLocale = options.sourceLocale ?? DEFAULT_LOCALE;
|
|
239
|
+
const state = () => {
|
|
240
|
+
const active = typeof options.locale === 'object' ? options.locale.value : options.locale;
|
|
241
|
+
const matched = resolveLocale(active, options.translations);
|
|
242
|
+
const translation = matched !== undefined ? options.translations[matched] : undefined;
|
|
243
|
+
return {
|
|
244
|
+
root: translation ?? sourceRoot,
|
|
245
|
+
rootLocale: translation ? matched : sourceLocale,
|
|
246
|
+
source: translation ? sourceRoot : undefined,
|
|
247
|
+
sourceLocale,
|
|
248
|
+
i18n: true,
|
|
249
|
+
currency: typeof options.currency === 'object' ? options.currency.value : options.currency,
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
label: (path) => renderLabel(state(), path),
|
|
254
|
+
errors: (errs) => renderErrors(state(), errs),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bigUInt64 = exports.bigInt64 = exports.bigNegativeInt = exports.bigPositiveInt = exports.bigNegative = exports.bigPositive = void 0;
|
|
4
|
+
const builderCore_ts_1 = require("../runtypes/builderCore.js");
|
|
5
|
+
exports.bigPositive = (0, builderCore_ts_1.presetBuilder)('bigint');
|
|
6
|
+
exports.bigNegative = (0, builderCore_ts_1.presetBuilder)('bigint');
|
|
7
|
+
exports.bigPositiveInt = (0, builderCore_ts_1.presetBuilder)('bigint');
|
|
8
|
+
exports.bigNegativeInt = (0, builderCore_ts_1.presetBuilder)('bigint');
|
|
9
|
+
exports.bigInt64 = (0, builderCore_ts_1.presetBuilder)('bigint');
|
|
10
|
+
exports.bigUInt64 = (0, builderCore_ts_1.presetBuilder)('bigint');
|