@raoh/core 0.9.0-dev.15.20261004151401.ge5893e0cc07d

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 ADDED
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and
27
+ configuration files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object
31
+ code, generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original
46
+ version of the Work and any modifications or additions to that Work or
47
+ Derivative Works thereof, that is intentionally submitted to Licensor for
48
+ inclusion in the Work by the copyright owner or by an individual or Legal
49
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal, or
51
+ written communication sent to the Licensor or its representatives, including
52
+ but not limited to communication on electronic mailing lists, source code
53
+ control systems, and issue tracking systems that are managed by, or on behalf
54
+ of, the Licensor for the purpose of discussing and improving the Work, but
55
+ excluding communication that is conspicuously marked or otherwise designated in
56
+ writing by the copyright owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this
70
+ License, each Contributor hereby grants to You a perpetual, worldwide,
71
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
72
+ section) patent license to make, have made, use, offer to sell, sell, import,
73
+ and otherwise transfer the Work, where such license applies only to those
74
+ patent claims licensable by such Contributor that are necessarily infringed by
75
+ their Contribution(s) alone or by combination of their Contribution(s) with the
76
+ Work to which such Contribution(s) was submitted. If You institute patent
77
+ litigation against any entity (including a cross-claim or counterclaim in a
78
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent
80
+ licenses granted to You under this License for that Work shall terminate as of
81
+ the date such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy
88
+ of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any
96
+ part of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents
106
+ of the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a
115
+ whole, provided Your use, reproduction, and distribution of the Work otherwise
116
+ complies with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties
134
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any
144
+ character arising as a result of this License or out of the use or inability to
145
+ use the Work (including but not limited to damages for loss of goodwill, work
146
+ stoppage, computer failure or malfunction, or any and all other commercial
147
+ damages or losses), even if such Contributor has been advised of the
148
+ possibility of such damages.
149
+
150
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
151
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
152
+ acceptance of support, warranty, indemnity, or other liability obligations
153
+ and/or rights consistent with this License. However, in accepting such
154
+ obligations, You may act only on Your own behalf and on Your sole
155
+ responsibility, not on behalf of any other Contributor, and only if You agree
156
+ to indemnify, defend, and hold each Contributor harmless for any liability
157
+ incurred by, or claims asserted against, such Contributor by reason of your
158
+ accepting any such warranty or additional liability.
159
+
160
+ END OF TERMS AND CONDITIONS
161
+
162
+ APPENDIX: How to apply the Apache License to your work.
163
+
164
+ To apply the Apache License to your work, attach the following boilerplate
165
+ notice, with the fields enclosed by brackets "[]" replaced with your own
166
+ identifying information. (Don't include the brackets.) The text should be
167
+ enclosed in the appropriate comment syntax for the file format. We also
168
+ recommend that a file or class name and description of purpose be included on
169
+ the same "printed page" as the copyright notice for easier identification
170
+ within third-party archives.
171
+
172
+ Copyright [yyyy] [name of copyright owner]
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # raoh-ts
2
+
3
+ TypeScript implementation of [Raoh](https://github.com/raoh-project/raoh-specification), a decoder
4
+ library for turning untyped boundary input into typed domain values. It is published to npm as
5
+ `@raoh/core`.
6
+
7
+ It is built around a parse-don't-validate approach:
8
+
9
+ - decode at the boundary
10
+ - keep invalid states out of the domain model
11
+ - return failures as values instead of throwing
12
+ - attach structured errors to precise paths
13
+
14
+ When the input is wrong, a decoder reports every problem it found, each with the JSON Pointer of
15
+ where it was, instead of stopping at the first one.
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ npm install @raoh/core
21
+ ```
22
+
23
+ It is an ES module with no dependencies, and runs on Node 22 and later and in current browsers.
24
+ Working on raoh-ts itself takes Node 22.18.0 or later, which runs the tests as the TypeScript they
25
+ are written in; `package.json` says the first in `engines` and the second in `devEngines`.
26
+
27
+ ## Quick start
28
+
29
+ ```ts
30
+ import { field, int, object, string } from "@raoh/core";
31
+
32
+ class User {
33
+ constructor(readonly email: string, readonly age: number) {}
34
+ }
35
+
36
+ const user = object(
37
+ field("email", string().email()),
38
+ field("age", int().range(0, 150)),
39
+ ).map(([email, age]) => new User(email, age));
40
+
41
+ const read = user.decode({ email: "not an email", age: 200 });
42
+ if (read.issues !== undefined) {
43
+ console.log(JSON.stringify(read.issues));
44
+ // [{"path":"/email","code":"invalid_format","messageKey":"invalid_format.email",
45
+ // "message":"not a valid email","meta":{}},
46
+ // {"path":"/age","code":"out_of_range","messageKey":"out_of_range.range",
47
+ // "message":"must be between 0 and 150","meta":{"min":0,"max":150,"actual":200}}]
48
+ } else {
49
+ read.value; // a User
50
+ }
51
+ ```
52
+
53
+ ## The model
54
+
55
+ ### `Decoder<T>`
56
+
57
+ A decoder is a value that describes how to read an input. What it gives depends on the input
58
+ alone, so it can be kept in a module-level constant and shared.
59
+
60
+ ```ts
61
+ abstract class Decoder<T> {
62
+ decode(input: unknown): Result<T>;
63
+ decodeJson(text: string): Result<T>;
64
+ decodeAt(input: unknown, path: Path): Result<T>;
65
+ map, flatMap, refine, nullable, withDefault, recover, recoverWith
66
+ }
67
+ ```
68
+
69
+ `Result<T>` is `{ value: T }` or `{ issues: Issues }`; checking `issues` narrows it.
70
+
71
+ The operations of each kind of value are methods of its decoder and give a decoder of the same
72
+ kind, so they chain: `string().minLength(3).maxLength(20)`, `int().positive()`,
73
+ `list(string()).nonempty().unique()`. Each operation that checks something takes an optional last
74
+ argument, a sentence to give in place of the catalogue's.
75
+
76
+ ### `Issue` and `Issues`
77
+
78
+ Each issue has a `path` (a `Path`, written as a JSON Pointer), a `code` such as `out_of_range`, a
79
+ `messageKey` such as `out_of_range.minimum`, and `meta`, what else it says, such as `min` and
80
+ `actual`. An issue carries no sentence of its own: `issue.message()` writes one from the English
81
+ catalogue and `issue.message(Messages.japanese)` from the Japanese one. The only sentence an issue
82
+ carries is one its maker gave, which every catalogue leaves as it is.
83
+
84
+ A catalogue has a template for the issues of the Raoh Specification. A library that gives issues
85
+ of its own, which no catalogue knows, says what to write for them with
86
+ `Messages.english.withFallback((issue) => ...)`; a catalogue that does have a template for such an
87
+ issue still wins over it.
88
+
89
+ The codes, message keys and metadata are those of the Raoh Specification, which Raoh for Java, Go,
90
+ Rust and PHP follow too, so the same client-side handling works for all of them.
91
+
92
+ `Issues` keeps them in the order they were found. `flatten()` groups the sentences by path, and
93
+ `at(path)` gives the issues at one path, what a form shows beside the field it names:
94
+ `issues.at(["lines", 0, "sku"])` is those of the first line's `sku`, and none of those above or
95
+ below it.
96
+
97
+ A path is a JSON Pointer's reference tokens, each kept as its text. RFC 6901 leaves it to the
98
+ value a token is applied to whether `0` names a member or an index, and a `Path` says no more
99
+ than its pointer does, so `Path.parse(path.toString())` is always the same path.
100
+
101
+ ### Issues as JSON
102
+
103
+ `JSON.stringify(issues)` writes `[{path, code, messageKey, message, meta}]`, with the English
104
+ sentence; `issues.toWire(Messages.japanese)` gives the same with another catalogue's. Each
105
+ metadata value is written as the Raoh Specification observes it
106
+ ([observation.md](https://github.com/raoh-project/raoh-specification/blob/main/spec/observation.md)):
107
+
108
+ | Value | JSON |
109
+ |-------|------|
110
+ | int32, int64 | a number, all its digits |
111
+ | float32, float64 | its canonical decimal as a number (`0.1` for the float32 nearest 0.1, `1.0E7`), or `{"float": "-0"}`, `{"float": "NaN"}`, `{"float": "+Infinity"}`, `{"float": "-Infinity"}` |
112
+ | decimal | a string, at its scale (`"1.50"`, `"1E+3"`) |
113
+ | list | an array |
114
+ | the candidates of `one_of_failed` | an array of `{candidate, issues}`, each issue `{path, code, message, meta}` with no `messageKey`, as the specification observes the issues type |
115
+
116
+ No number is rounded on the way out: an int64 beyond 2⁵³ is written with all its digits through
117
+ `JSON.rawJSON`. On an engine that has no `JSON.rawJSON`, a number that a JavaScript number would
118
+ change makes `JSON.stringify` throw a `RangeError`, rather than write another number.
119
+
120
+ ## Combining decoders
121
+
122
+ `object` reads its fields from the same input and gives their values as a tuple, in order. Every
123
+ field is read, so every failing one is reported.
124
+
125
+ ```ts
126
+ const point = object(field("x", int()), field("y", int())).strict();
127
+ point.decode({ x: "1", y: 2, z: 3 }).issues?.list.map((i) => i.path.toString()); // ["/x", "/z"]
128
+ ```
129
+
130
+ A rule that relates the parts runs once the parts exist, with `flatMap`. The paths of the issues it
131
+ gives are read below where the decoder is:
132
+
133
+ ```ts
134
+ const period = object(field("start", int()), field("end", int())).flatMap(([start, end]) =>
135
+ start <= end
136
+ ? ok({ start, end })
137
+ : failed(new Issue("invalid_value", { message: "must not be before start", path: ["end"] })),
138
+ );
139
+ ```
140
+
141
+ `discriminate("type", { circle, square })` reads the variant a tag names, and its type is the
142
+ union of the variants'. `oneOf(a, b)` gives the first candidate that succeeds. `enumOf`,
143
+ `literal`, `list`, `dict`, `optionalField`, `optionalNullableField`, `flat`, `nullable`,
144
+ `withDefault` and `recover` are as the specification describes them.
145
+
146
+ ## Input
147
+
148
+ A decoder reads the input model of the specification: what a JSON text denotes, with every number
149
+ kept as it is written. `parse(text)` and `decoder.decodeJson(text)` read a JSON text into it, every
150
+ number a `JsonNumber` holding its lexeme and every object a `Map` holding its members in order.
151
+
152
+ A decoder also reads what an application already has: plain objects, arrays, strings, booleans,
153
+ `null`, and numbers as JavaScript `number` or `bigint`, as a `Decimal`, which is read at its scale,
154
+ or as `JSON.rawJSON` makes them, which keeps their text. `undefined` is an absent value. An object is a `Map` of string keys, or an object
155
+ whose data are its own properties. What the input model has no place for — a string holding an
156
+ unpaired surrogate, an array with a hole, a `Date`, a `Set`, a `String` object — is refused with a
157
+ `TypeError` rather than read as some other value. Such a
158
+ number has already been converted, so a decoder reads the number it is, not the text it was:
159
+ `1.50` read by `JSON.parse` is 1.5, and `decimal()` gives it with scale 1; an integer beyond 2⁵³
160
+ has already been rounded. Read the text with `parse` where that matters.
161
+
162
+ `stringify(value)` writes a value of the input model back as JSON text, reading it by the same
163
+ rule, so that whatever it writes `parse` reads back as the value it was:
164
+ each number as its lexeme and each object's members in order. It is how a value is handed on to
165
+ something that reads JSON text, without a number rounded or a member moved, which
166
+ `JSON.stringify` does to a `Map` and to an object's integer-like member names.
167
+
168
+ The values a decoder gives are a `number` for `int`, `float` and `double`, a `bigint` for `long`, a
169
+ `Decimal` (a coefficient and a scale) for `decimal`, a `ValueSet` for `toSet`, which tells +0 from
170
+ -0 as a JavaScript `Set` does not, and a `Map` for `dict`.
171
+
172
+ ## A library built on Raoh
173
+
174
+ A library whose decoders, issues or paths an application combines with its own, as Souther's
175
+ `@souther/wasm` offers each type of a model as a `Decoder`, depends on `@raoh/core` as a peer
176
+ dependency, so that the library and the application share one copy. A value one copy made is no
177
+ instance of another copy's classes; where one is met anyway, such as a `Path` or a `JsonNumber` of
178
+ another copy, it is refused with a `TypeError` that says so, rather than read as some other value.
179
+
180
+ ## Conformance
181
+
182
+ raoh-ts is checked against the [Raoh Specification](https://github.com/raoh-project/raoh-specification)
183
+ at the commit `conformance/spec.lock` pins, with the verifier of that commit:
184
+
185
+ ```sh
186
+ scripts/conformance.sh
187
+ ```
188
+
189
+ Raoh Specification 0.9.0-dev — core: partially conformant (314 unsupported); encode: conformant;
190
+ messages-en: conformant; messages-ja: conformant.
191
+
192
+ The unsupported features are the ones that read text by the rules
193
+ [199x-notation](https://github.com/raoh-project/199x-notation) gives: `trim`, `nonBlank`,
194
+ `toLowerCase`, `toUpperCase`, `normalize`, `pattern`, and the temporal decoders and their
195
+ operations. JavaScript's own `normalize`, case mapping and `RegExp` follow whichever Unicode
196
+ version the engine has, so they are left out until raoh-ts reads text with 199x-notation, rather
197
+ than given with answers that differ from one engine to another. `conformance/conformance.json`
198
+ lists them.
199
+
200
+ ## Releasing
201
+
202
+ `@raoh/core` is published by the `Publish` workflow and by nothing else. `package.json` on `develop`
203
+ holds the next version as `X.Y.Z-dev`. A push to `develop` publishes the commit it brings, once CI
204
+ has passed on it, as `X.Y.Z-dev.N.YYYYMMDDHHMMSS.gHHHHHHHHHHHH` under the dist-tag `dev`: `N` is how
205
+ many commits the commit holds, itself and every one before it, then the time of the commit, then the
206
+ commit. npm takes a version once and never again, so a development version is a commit, as a
207
+ timestamped Maven snapshot is. A later commit on `develop` holds every one before it, so its `N` is
208
+ greater and SemVer orders the versions as `develop` does; the time does not, since a commit can be
209
+ dated before its parent, and two can be made in one second.
210
+
211
+ `dev` names the newest state of `develop`, and not whichever run happened to publish last. Just
212
+ before it publishes, a run asks `develop` as it is then whether a later commit has reached it, and
213
+ where one has, it publishes nothing and leaves `dev` to that commit's run; one run publishes at a
214
+ time, so the run that finds itself newest publishes before any later commit's run asks, whatever
215
+ order GitHub starts the runs in. So the commits of one push but the last, and a push a later one
216
+ overtakes before its run publishes, have no version of their own; and where the later commit's run
217
+ fails, `dev` stays where it was until a push whose run passes.
218
+
219
+ `npm install @raoh/core` takes `latest`, which is a release, and a range written for releases,
220
+ `^0.9.0`, takes no development version: npm takes a prerelease only for a range that names one of the
221
+ same `X.Y.Z`, and `^0.9.0-dev.1` takes every later one. So a project that means one
222
+ commit writes its version exactly, `npm install --save-exact @raoh/core@<version>`, as `npm install`
223
+ otherwise saves a range.
224
+
225
+ `scripts/publish.sh` says what version a ref makes, under which dist-tag, and publishes it, and CI
226
+ takes each path it can take as a dry run on every pull request (`scripts/try-publish.sh`), so each
227
+ is taken before a push takes it. A release is a tag:
228
+
229
+ 1. On a branch from `develop`, set `package.json`'s version to `X.Y.Z` and open a pull request to
230
+ `main`.
231
+ 2. Merge it, and tag the merge commit on `main` `vX.Y.Z`. The workflow fails a tag that is not `v`
232
+ and a version, that is not the version `package.json` holds, or that names a commit not on
233
+ `main`. It runs the whole of CI on the commit, and only once that passes publishes `X.Y.Z`: under
234
+ `latest` where it is newer than what `latest` names as it is published, and otherwise, as a patch
235
+ of an older line or one whose run comes after a newer release's, under `release-X.Y.Z`, which
236
+ names it and nothing else. `latest` only ever moves to a newer release, so once every run has run
237
+ it names the newest release published, whatever order the runs ran in. What it names is asked of
238
+ the registry, which holds what was published, so a tag the workflow refused, or whose run failed,
239
+ has no say in it.
240
+ 3. Merge `main` back into `develop`, and set `package.json` there to `<next version>-dev`.
241
+
242
+ The workflow logs in with nothing: npm proves to the registry that it runs in this workflow of this
243
+ repository, which the package's settings on npmjs.com name as its trusted publisher, and the
244
+ registry records with each version the commit and the run it was built in. A trusted publisher is
245
+ named for a package that exists, so the package's first version is published by hand from a
246
+ checkout, and the trusted publisher named after it: repository `raoh-project/raoh-ts`, workflow
247
+ `publish.yml`, with `npm publish` allowed. A trusted publisher named since September 3, 2026 allows
248
+ `npm stage publish` and allows `npm publish` only where it is chosen, and the workflow publishes with
249
+ `npm publish`. It needs nothing else: it reads what `latest` names from the registry without
250
+ logging in, as anyone can of a public package.
251
+
252
+ ## License
253
+
254
+ Apache License 2.0
@@ -0,0 +1,5 @@
1
+ /** Each locale's catalogue, as the text of its `.properties` file. */
2
+ export declare const CATALOG: {
3
+ readonly en: "raoh.required=is required\nraoh.blank=must not be blank\nraoh.too_short=must be at least {min} characters\nraoh.too_long=must be at most {max} characters\nraoh.invalid_length=must be exactly {expected} characters\nraoh.out_of_range=must be between {min} and {max}\nraoh.out_of_range.minimum=must be at least {min}\nraoh.out_of_range.maximum=must be at most {max}\nraoh.out_of_range.range=must be between {min} and {max}\nraoh.out_of_range.positive=must be positive\nraoh.out_of_range.negative=must be negative\nraoh.out_of_range.non_negative=must be non-negative\nraoh.out_of_range.non_positive=must be non-positive\nraoh.out_of_range.before=must be before {before}\nraoh.out_of_range.after=must be after {after}\nraoh.out_of_range.between=must be between {from} and {to}\nraoh.not_multiple_of=must be a multiple of {divisor}\nraoh.invalid_scale=too many decimal places (max {maxScale})\nraoh.too_small=must have at least {min} elements\nraoh.too_small.nonempty=must not be empty\nraoh.too_big=must have at most {max} elements\nraoh.invalid_size=must have exactly {expected} elements\nraoh.invalid_value=must be {expected}\nraoh.missing_element=must contain {expected}\nraoh.missing_elements=must contain all of {expected} (missing: {missing})\nraoh.duplicate_element=must not contain duplicates: {duplicates}\nraoh.not_allowed=must be one of {allowed}\nraoh.invalid_format=invalid format\nraoh.invalid_format.email=not a valid email\nraoh.invalid_format.url=not a valid URL\nraoh.invalid_format.uri=not a valid URI\nraoh.invalid_format.uuid=not a valid UUID\nraoh.invalid_format.ip=not a valid IP address\nraoh.invalid_format.ipv4=not a valid IPv4 address\nraoh.invalid_format.ipv6=not a valid IPv6 address\nraoh.invalid_format.ulid=not a valid ULID\nraoh.invalid_format.cuid=not a valid CUID\nraoh.invalid_format.starts_with=must start with \"{prefix}\"\nraoh.invalid_format.ends_with=must end with \"{suffix}\"\nraoh.invalid_format.includes=must include \"{substring}\"\nraoh.invalid_format.enum=invalid value\nraoh.invalid_format.literal=invalid value\nraoh.invalid_format.instant=not a valid ISO 8601 instant\nraoh.invalid_format.date=not a valid ISO-8601 date (e.g., 2024-01-15)\nraoh.invalid_format.time=not a valid ISO-8601 local time (e.g., 10:30 or 10:30:45)\nraoh.invalid_format.date_time=not a valid ISO-8601 local date-time (e.g., 2024-01-15T10:30 or 2024-01-15T10:30:45)\nraoh.invalid_format.offset_date_time=not a valid ISO-8601 offset date-time (e.g., 2024-01-15T10:30:00+09:00)\nraoh.type_mismatch=expected {expected}\nraoh.type_mismatch.string_keys=expected object with string keys, found {actual} key\nraoh.type_mismatch.numeric_range=value is outside the {expected} range\nraoh.unknown_field=unknown field\nraoh.one_of_failed=no variant matched\nraoh.missing_field=field is missing\n";
4
+ readonly ja: "raoh.required=必須です\nraoh.blank=空白は許可されていません\nraoh.too_short={min}文字以上で入力してください\nraoh.too_long={max}文字以内で入力してください\nraoh.invalid_length={expected}文字で入力してください\nraoh.out_of_range={min}以上{max}以下で入力してください\nraoh.out_of_range.minimum={min}以上で入力してください\nraoh.out_of_range.maximum={max}以下で入力してください\nraoh.out_of_range.range={min}以上{max}以下で入力してください\nraoh.out_of_range.positive=正の値で入力してください\nraoh.out_of_range.negative=負の値で入力してください\nraoh.out_of_range.non_negative=0以上で入力してください\nraoh.out_of_range.non_positive=0以下で入力してください\nraoh.out_of_range.before={before}より前で入力してください\nraoh.out_of_range.after={after}より後で入力してください\nraoh.out_of_range.between={from}から{to}の範囲で入力してください\nraoh.not_multiple_of={divisor}の倍数で入力してください\nraoh.invalid_scale=小数点以下は{maxScale}桁までです\nraoh.too_small={min}個以上の要素が必要です\nraoh.too_small.nonempty=空にはできません\nraoh.too_big={max}個以内の要素が必要です\nraoh.invalid_size={expected}個の要素が必要です\nraoh.invalid_value={expected}でなければなりません\nraoh.missing_element={expected}を含む必要があります\nraoh.missing_elements={expected}をすべて含む必要があります(不足: {missing})\nraoh.duplicate_element=重複があります: {duplicates}\nraoh.not_allowed={allowed}のいずれかで入力してください\nraoh.invalid_format=形式が不正です\nraoh.invalid_format.email=メールアドレスの形式が不正です\nraoh.invalid_format.url=URLの形式が不正です\nraoh.invalid_format.uri=URIの形式が不正です\nraoh.invalid_format.uuid=UUIDの形式が不正です\nraoh.invalid_format.ip=IPアドレスの形式が不正です\nraoh.invalid_format.ipv4=IPv4アドレスの形式が不正です\nraoh.invalid_format.ipv6=IPv6アドレスの形式が不正です\nraoh.invalid_format.ulid=ULIDの形式が不正です\nraoh.invalid_format.cuid=CUIDの形式が不正です\nraoh.invalid_format.starts_with=「{prefix}」で始まる必要があります\nraoh.invalid_format.ends_with=「{suffix}」で終わる必要があります\nraoh.invalid_format.includes=「{substring}」を含む必要があります\nraoh.invalid_format.enum=値が不正です\nraoh.invalid_format.literal=値が不正です\nraoh.invalid_format.instant=日時の形式が不正です(例: 2024-01-15T01:30:00Z)\nraoh.invalid_format.date=日付の形式が不正です(例: 2024-01-15)\nraoh.invalid_format.time=時刻の形式が不正です(例: 10:30 または 10:30:45)\nraoh.invalid_format.date_time=日時の形式が不正です(例: 2024-01-15T10:30 または 2024-01-15T10:30:45)\nraoh.invalid_format.offset_date_time=オフセット付き日時の形式が不正です(例: 2024-01-15T10:30:00+09:00)\nraoh.type_mismatch={expected}型が必要です\nraoh.type_mismatch.string_keys=キーがすべて文字列のオブジェクトが必要です(キーの型: {actual})\nraoh.type_mismatch.numeric_range={expected}型の範囲外の値です\nraoh.unknown_field=不明なフィールドです\nraoh.one_of_failed=いずれのバリアントにも一致しませんでした\nraoh.missing_field=フィールドが見つかりません\n";
5
+ };
@@ -0,0 +1,7 @@
1
+ // Generated by scripts/catalog.ts from the message catalogues of the Raoh Specification at
2
+ // b38ded05f2a68e45849d38494ddc2aa34640aad1. Do not edit: regenerate it instead.
3
+ /** Each locale's catalogue, as the text of its `.properties` file. */
4
+ export const CATALOG = {
5
+ en: "raoh.required=is required\nraoh.blank=must not be blank\nraoh.too_short=must be at least {min} characters\nraoh.too_long=must be at most {max} characters\nraoh.invalid_length=must be exactly {expected} characters\nraoh.out_of_range=must be between {min} and {max}\nraoh.out_of_range.minimum=must be at least {min}\nraoh.out_of_range.maximum=must be at most {max}\nraoh.out_of_range.range=must be between {min} and {max}\nraoh.out_of_range.positive=must be positive\nraoh.out_of_range.negative=must be negative\nraoh.out_of_range.non_negative=must be non-negative\nraoh.out_of_range.non_positive=must be non-positive\nraoh.out_of_range.before=must be before {before}\nraoh.out_of_range.after=must be after {after}\nraoh.out_of_range.between=must be between {from} and {to}\nraoh.not_multiple_of=must be a multiple of {divisor}\nraoh.invalid_scale=too many decimal places (max {maxScale})\nraoh.too_small=must have at least {min} elements\nraoh.too_small.nonempty=must not be empty\nraoh.too_big=must have at most {max} elements\nraoh.invalid_size=must have exactly {expected} elements\nraoh.invalid_value=must be {expected}\nraoh.missing_element=must contain {expected}\nraoh.missing_elements=must contain all of {expected} (missing: {missing})\nraoh.duplicate_element=must not contain duplicates: {duplicates}\nraoh.not_allowed=must be one of {allowed}\nraoh.invalid_format=invalid format\nraoh.invalid_format.email=not a valid email\nraoh.invalid_format.url=not a valid URL\nraoh.invalid_format.uri=not a valid URI\nraoh.invalid_format.uuid=not a valid UUID\nraoh.invalid_format.ip=not a valid IP address\nraoh.invalid_format.ipv4=not a valid IPv4 address\nraoh.invalid_format.ipv6=not a valid IPv6 address\nraoh.invalid_format.ulid=not a valid ULID\nraoh.invalid_format.cuid=not a valid CUID\nraoh.invalid_format.starts_with=must start with \"{prefix}\"\nraoh.invalid_format.ends_with=must end with \"{suffix}\"\nraoh.invalid_format.includes=must include \"{substring}\"\nraoh.invalid_format.enum=invalid value\nraoh.invalid_format.literal=invalid value\nraoh.invalid_format.instant=not a valid ISO 8601 instant\nraoh.invalid_format.date=not a valid ISO-8601 date (e.g., 2024-01-15)\nraoh.invalid_format.time=not a valid ISO-8601 local time (e.g., 10:30 or 10:30:45)\nraoh.invalid_format.date_time=not a valid ISO-8601 local date-time (e.g., 2024-01-15T10:30 or 2024-01-15T10:30:45)\nraoh.invalid_format.offset_date_time=not a valid ISO-8601 offset date-time (e.g., 2024-01-15T10:30:00+09:00)\nraoh.type_mismatch=expected {expected}\nraoh.type_mismatch.string_keys=expected object with string keys, found {actual} key\nraoh.type_mismatch.numeric_range=value is outside the {expected} range\nraoh.unknown_field=unknown field\nraoh.one_of_failed=no variant matched\nraoh.missing_field=field is missing\n",
6
+ ja: "raoh.required=必須です\nraoh.blank=空白は許可されていません\nraoh.too_short={min}文字以上で入力してください\nraoh.too_long={max}文字以内で入力してください\nraoh.invalid_length={expected}文字で入力してください\nraoh.out_of_range={min}以上{max}以下で入力してください\nraoh.out_of_range.minimum={min}以上で入力してください\nraoh.out_of_range.maximum={max}以下で入力してください\nraoh.out_of_range.range={min}以上{max}以下で入力してください\nraoh.out_of_range.positive=正の値で入力してください\nraoh.out_of_range.negative=負の値で入力してください\nraoh.out_of_range.non_negative=0以上で入力してください\nraoh.out_of_range.non_positive=0以下で入力してください\nraoh.out_of_range.before={before}より前で入力してください\nraoh.out_of_range.after={after}より後で入力してください\nraoh.out_of_range.between={from}から{to}の範囲で入力してください\nraoh.not_multiple_of={divisor}の倍数で入力してください\nraoh.invalid_scale=小数点以下は{maxScale}桁までです\nraoh.too_small={min}個以上の要素が必要です\nraoh.too_small.nonempty=空にはできません\nraoh.too_big={max}個以内の要素が必要です\nraoh.invalid_size={expected}個の要素が必要です\nraoh.invalid_value={expected}でなければなりません\nraoh.missing_element={expected}を含む必要があります\nraoh.missing_elements={expected}をすべて含む必要があります(不足: {missing})\nraoh.duplicate_element=重複があります: {duplicates}\nraoh.not_allowed={allowed}のいずれかで入力してください\nraoh.invalid_format=形式が不正です\nraoh.invalid_format.email=メールアドレスの形式が不正です\nraoh.invalid_format.url=URLの形式が不正です\nraoh.invalid_format.uri=URIの形式が不正です\nraoh.invalid_format.uuid=UUIDの形式が不正です\nraoh.invalid_format.ip=IPアドレスの形式が不正です\nraoh.invalid_format.ipv4=IPv4アドレスの形式が不正です\nraoh.invalid_format.ipv6=IPv6アドレスの形式が不正です\nraoh.invalid_format.ulid=ULIDの形式が不正です\nraoh.invalid_format.cuid=CUIDの形式が不正です\nraoh.invalid_format.starts_with=「{prefix}」で始まる必要があります\nraoh.invalid_format.ends_with=「{suffix}」で終わる必要があります\nraoh.invalid_format.includes=「{substring}」を含む必要があります\nraoh.invalid_format.enum=値が不正です\nraoh.invalid_format.literal=値が不正です\nraoh.invalid_format.instant=日時の形式が不正です(例: 2024-01-15T01:30:00Z)\nraoh.invalid_format.date=日付の形式が不正です(例: 2024-01-15)\nraoh.invalid_format.time=時刻の形式が不正です(例: 10:30 または 10:30:45)\nraoh.invalid_format.date_time=日時の形式が不正です(例: 2024-01-15T10:30 または 2024-01-15T10:30:45)\nraoh.invalid_format.offset_date_time=オフセット付き日時の形式が不正です(例: 2024-01-15T10:30:00+09:00)\nraoh.type_mismatch={expected}型が必要です\nraoh.type_mismatch.string_keys=キーがすべて文字列のオブジェクトが必要です(キーの型: {actual})\nraoh.type_mismatch.numeric_range={expected}型の範囲外の値です\nraoh.unknown_field=不明なフィールドです\nraoh.one_of_failed=いずれのバリアントにも一致しませんでした\nraoh.missing_field=フィールドが見つかりません\n",
7
+ };
package/dist/copy.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /** The `Symbol.toStringTag` of this library's class `name`, the same in every copy of it. */
2
+ export declare function tagOf(name: string): string;
3
+ /**
4
+ * Whether `value` is an instance of `type`, this copy's class `name`. The class is typed by its
5
+ * prototype, since a class with a private constructor is no type `new` can be asked of.
6
+ *
7
+ * @throws {TypeError} where it is an instance of the class of that name another copy has
8
+ */
9
+ export declare function ofThisCopy<T extends object>(value: unknown, type: Function & {
10
+ readonly prototype: T;
11
+ }, name: string): value is T;
package/dist/copy.js ADDED
@@ -0,0 +1,30 @@
1
+ // Telling a value of this copy of the library from one of another copy.
2
+ //
3
+ // A program can come to hold two copies of @raoh/core: a library built on Raoh that brings its own,
4
+ // and the application's. A value one copy made is then no instance of the other's class, and a
5
+ // check by `instanceof` would read it as some other value without a word: a JsonNumber written as
6
+ // an object, a Path walked as if it were a list. Every class here carries its name as its
7
+ // `Symbol.toStringTag`, which a copy shares with every other, so a value of the same class from
8
+ // another copy is refused where it is met, as the mistake in how the program was installed that it
9
+ // is. One copy is what a peer dependency on @raoh/core gives a library and its application.
10
+ const PREFIX = "@raoh/core ";
11
+ /** The `Symbol.toStringTag` of this library's class `name`, the same in every copy of it. */
12
+ export function tagOf(name) {
13
+ return PREFIX + name;
14
+ }
15
+ /**
16
+ * Whether `value` is an instance of `type`, this copy's class `name`. The class is typed by its
17
+ * prototype, since a class with a private constructor is no type `new` can be asked of.
18
+ *
19
+ * @throws {TypeError} where it is an instance of the class of that name another copy has
20
+ */
21
+ export function ofThisCopy(value, type, name) {
22
+ if (value instanceof type) {
23
+ return true;
24
+ }
25
+ if (typeof value === "object" && value !== null && value[Symbol.toStringTag] === PREFIX + name) {
26
+ throw new TypeError(`a ${name} made by another copy of @raoh/core: a library built on Raoh and the application using it have to `
27
+ + "share one, which the library's peer dependency on @raoh/core gives them");
28
+ }
29
+ return false;
30
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A coefficient and a scale: the number coefficient × 10^-scale.
3
+ *
4
+ * Two decimals are the same value only when both are equal, so 1.5 and 1.50 are different values;
5
+ * {@link Decimal.compare} orders them by the number they denote, in which they are equal. The
6
+ * scale is an int32, as the value model's is.
7
+ */
8
+ export declare class Decimal {
9
+ readonly coefficient: bigint;
10
+ readonly scale: number;
11
+ constructor(coefficient: bigint, scale: number);
12
+ /**
13
+ * The decimal a number written as `[+-]?(digits[.digits]|.digits)([eE][+-]?digits)?` denotes,
14
+ * at the scale it is written with: the digits after the point, less the exponent. `undefined`
15
+ * where the text is not such a number, or its scale is not an int32.
16
+ */
17
+ static parse(text: string): Decimal | undefined;
18
+ get [Symbol.toStringTag](): string;
19
+ /** The decimal of an integer, at scale 0. */
20
+ static of(value: bigint | number): Decimal;
21
+ /** -1, 0 or 1 as this denotes a number less than, equal to or greater than `other`'s. */
22
+ compare(other: Decimal): number;
23
+ /** Whether the two are the same value: the same coefficient and the same scale. */
24
+ equals(other: Decimal): boolean;
25
+ /** -1, 0 or 1 as the number is negative, zero or positive. */
26
+ get signum(): number;
27
+ /** Whether this is an integer multiple of `divisor`, which is not zero. */
28
+ isMultipleOf(divisor: Decimal): boolean;
29
+ /**
30
+ * The decimal as Java's `BigDecimal.toString` writes it, which is the message form the Raoh
31
+ * Specification gives: plain where the scale is not negative and the first digit's exponent is
32
+ * at least -6, and otherwise one digit before the point and an exponent (`1E+3`, `1.5E-7`).
33
+ */
34
+ toString(): string;
35
+ toJSON(): string;
36
+ }