@formaui-net/nexo 0.0.0-stage → 1.0.0-preview.1

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.
Files changed (49) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +152 -2
  4. package/package.json +34 -5
  5. package/src/common/ArrayUtils.mjs +16 -0
  6. package/src/common/ObjectUtils.mjs +33 -0
  7. package/src/language/DefinitionLocations.mjs +41 -0
  8. package/src/language/DefinitionValidator.mjs +1265 -0
  9. package/src/language/DefinitionWriter.mjs +475 -0
  10. package/src/language/Dictionary.mjs +52 -0
  11. package/src/language/Evaluator.mjs +3480 -0
  12. package/src/language/ImportedVocabulary.mjs +137 -0
  13. package/src/language/Imports.mjs +141 -0
  14. package/src/language/Index.mjs +29 -0
  15. package/src/language/LanguageResolver.mjs +4068 -0
  16. package/src/language/Limits.mjs +78 -0
  17. package/src/language/LineStructure.mjs +385 -0
  18. package/src/language/Lowering.mjs +453 -0
  19. package/src/language/MemberSelector.mjs +89 -0
  20. package/src/language/Names.mjs +65 -0
  21. package/src/language/NexoError.mjs +145 -0
  22. package/src/language/Pair.mjs +21 -0
  23. package/src/language/ParameterBindings.mjs +361 -0
  24. package/src/language/ParsedTexts.mjs +62 -0
  25. package/src/language/Parser.mjs +1817 -0
  26. package/src/language/Range.mjs +51 -0
  27. package/src/language/RecentlyUsed.mjs +50 -0
  28. package/src/language/ResolvedDefinition.mjs +219 -0
  29. package/src/language/ResultPath.mjs +101 -0
  30. package/src/language/ScopeLocals.mjs +102 -0
  31. package/src/language/StructureTypes.mjs +48 -0
  32. package/src/language/SyntaxTree.mjs +203 -0
  33. package/src/language/TextLocations.mjs +185 -0
  34. package/src/language/TextPositions.mjs +23 -0
  35. package/src/language/Tokenizer.mjs +917 -0
  36. package/src/language/Type.mjs +401 -0
  37. package/src/language/TypeChecker.mjs +449 -0
  38. package/src/language/ValueCapture.mjs +315 -0
  39. package/src/language/Versions.mjs +14 -0
  40. package/src/language/vocabulary/Declarations.mjs +64 -0
  41. package/src/language/vocabulary/ItemPositions.mjs +48 -0
  42. package/src/language/vocabulary/ListOrdering.mjs +145 -0
  43. package/src/language/vocabulary/MemberFailure.mjs +21 -0
  44. package/src/language/vocabulary/NexoModule.mjs +1119 -0
  45. package/src/language/vocabulary/NexoRegistry.mjs +1540 -0
  46. package/src/language/vocabulary/TypeNameScope.mjs +63 -0
  47. package/src/language/vocabulary/Vocabulary.mjs +640 -0
  48. package/src/nexo.d.ts +743 -0
  49. package/src/nexo.js +338 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Nexo, https://github.com/FormaUI/Nexo
2
+ Copyright 2026 Eyal Alon <eyal@formaui.net>
package/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # Temporary Holding Version
1
+ # Nexo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Nexo lets an application expose its own concepts through a typed scripting language, so people can express rules and produce structured results in those terms.
4
+
5
+ The application declares what scripts may use: its records, their properties and the operations it implements. Nexo checks each script against those declarations before it runs, and evaluates it into plain, immutable data.
6
+
7
+ ## An example
8
+
9
+ A billing application keeps customers and their invoices. It gives each script one `customer`, with a name, a credit limit and invoices. It declares what scripts can read: a customer's `invoices`, an invoice's `amount`, whether it is `paid`, and `daysOverdue`, which the application computes from the invoice's due date and the date it gives the evaluation.
10
+
11
+ This script summarizes what a customer owes, charging a 5% late fee on any invoice more than 30 days overdue:
12
+
13
+ ```nexo
14
+ import Billing
15
+
16
+ let outstanding = customer.invoices.where(not it.paid)
17
+ let lateFee = invoice => if invoice.daysOverdue > 30 then invoice.amount * 0.05 else 0 end
18
+ let owed = outstanding.sum(it.amount + lateFee(it))
19
+
20
+ return {
21
+ account = customer.name,
22
+ amountDue = owed,
23
+ status = if owed > customer.creditLimit then "on hold" else "in good standing" end,
24
+ overdue = outstanding.where(it.daysOverdue > 0) {
25
+ number = it.number,
26
+ daysOverdue = it.daysOverdue,
27
+ fee = lateFee(it)
28
+ },
29
+ summary = $"{outstanding.count} of {customer.invoices.count} invoices outstanding"
30
+ }
31
+ ```
32
+
33
+ The application evaluates the script on November 1, 2026. Northwind Traders then has four invoices: one paid, one 42 days overdue, one 7 days overdue and one not yet due. Its credit limit is 1,000. The script gives:
34
+
35
+ ```json
36
+ {
37
+ "account": "Northwind Traders",
38
+ "amountDue": 1015,
39
+ "status": "on hold",
40
+ "overdue": [
41
+ { "number": "INV-102", "daysOverdue": 42, "fee": 15 },
42
+ { "number": "INV-103", "daysOverdue": 7, "fee": 0 }
43
+ ],
44
+ "summary": "3 of 4 invoices outstanding"
45
+ }
46
+ ```
47
+
48
+ What the example shows:
49
+
50
+ - **The application's terms.** `customer.invoices` and `invoice.daysOverdue` are the billing application's concepts. `daysOverdue` runs the application's own code, and the script reads it as it reads any property.
51
+ - **A rule stated once.** `lateFee` is written once, and both the amount due and each overdue line apply it.
52
+ - **One readable place.** Filtering, the total, the credit check and the shape of the result are in one script, rather than spread through application code.
53
+ - **Plain data out.** The result has the shape the script writes, ready to send, store or compare.
54
+
55
+ ## Why embed Nexo
56
+
57
+ | Strength | Why it matters |
58
+ | --- | --- |
59
+ | The application's own vocabulary | The script works with `customer.invoices` and `daysOverdue`, the billing application's concepts, not a generic data model. `daysOverdue` is an operation the application implements. |
60
+ | Checked before it runs | Writing `it.amout` in the total is refused before anything runs: "'amout' is no member of the vocabulary", at line 5, column 28. Leaving out `import Billing`, or comparing `customer.name` with a number, is refused the same way, with its location. |
61
+ | Expressions, collections and structured output | One script filters the invoices, totals them, checks the credit limit, writes the summary's text and shapes the result. |
62
+ | Functions and composition | `lateFee` is written once, and both the total and each overdue line apply it, so the fee changes in one place. |
63
+ | An explicit host boundary | The script reads only the `customer` the application binds, as a frozen copy, through members `Billing` and Nexo declare. `daysOverdue` runs the application's code, and nothing the script does changes the application's data. |
64
+ | Definitions as data, with canonical text | `nexo.parse` gives the script as a JSON definition to store or inspect, and `nexo.format` gives the text above back from it, so a definition a tool generates reads as a script written by hand. |
65
+ | Reads reported as it evaluates | Hooks the application gives an evaluation are told of each member it invokes, `daysOverdue` among them, so the application knows what the summary read. Each member also declares how it changes: `daysOverdue` is `unobserved`, since nothing signals that a day has passed, so when to evaluate again is the application's choice. |
66
+
67
+ ## Run it
68
+
69
+ The application declares its vocabulary as a module, binds its data and evaluates the script. `script` holds the script's text above:
70
+
71
+ ```js
72
+ import { nexo } from '@formaui-net/nexo';
73
+
74
+ const { createPropertyDeclaration: property } = nexo.declarations;
75
+ const DAY = 24 * 60 * 60 * 1000;
76
+
77
+ const billing = nexo.createModule('Billing', {
78
+ types: [
79
+ {
80
+ name: 'Customer',
81
+ kind: 'structured',
82
+ members: [property('name', 'String'), property('creditLimit', 'Number'), property('invoices', 'List<Invoice>')],
83
+ },
84
+ {
85
+ name: 'Invoice',
86
+ kind: 'structured',
87
+ members: [
88
+ property('number', 'String'),
89
+ property('amount', 'Number'),
90
+ property('paid', 'Boolean'),
91
+ property('dueDate', 'String'),
92
+ // The application's code, reading the date it gives the evaluation. Nothing signals
93
+ // that the date has moved on, so the property is unobserved.
94
+ property('daysOverdue', 'Number', {
95
+ updates: { changes: 'unobserved', reads: 'fresh' },
96
+ impl: ({ receiver, env }) => Math.max(0, Math.round((env.today - Date.parse(receiver.dueDate)) / DAY)),
97
+ }),
98
+ ],
99
+ },
100
+ ],
101
+ });
102
+
103
+ const customer = {
104
+ name: 'Northwind Traders',
105
+ creditLimit: 1000,
106
+ invoices: [
107
+ { number: 'INV-101', amount: 450, paid: true, dueDate: '2026-09-15' },
108
+ { number: 'INV-102', amount: 300, paid: false, dueDate: '2026-09-20' },
109
+ { number: 'INV-103', amount: 520, paid: false, dueDate: '2026-10-25' },
110
+ { number: 'INV-104', amount: 180, paid: false, dueDate: '2026-11-20' },
111
+ ],
112
+ };
113
+
114
+ const registry = nexo.createRegistry([billing]);
115
+ const bindings = registry.createBindings({ customer }, { types: { customer: 'Billing.Customer' } });
116
+
117
+ // Resolving checks the script against the vocabulary, before anything runs.
118
+ const resolution = registry.resolve(script, bindings);
119
+
120
+ resolution.type; // '{ account: String, amountDue: Number, status: String, overdue: List<{ number: String, daysOverdue: Number, fee: Number }>, summary: String }'
121
+
122
+ const summary = resolution.createEvaluator(bindings, { today: Date.parse('2026-11-01') }).evaluate().value;
123
+ ```
124
+
125
+ `summary` is the result shown above, on any day, since the date comes from the evaluation and not the clock. A resolution serves any bindings of the same types, so the script is resolved once and evaluated for each customer. [Embedding Nexo](https://github.com/FormaUI/Nexo/blob/main/docs/embedding-guide.md) goes on to functions a module declares, calls the application carries out, and following what an evaluation reads.
126
+
127
+ ## Availability
128
+
129
+ > **Preview.** Until the first release candidate, a decision may be replaced where a host's experience, correctness or a measured cost justifies it, and a version that breaks what the one before it allowed says how to migrate; from `1.0.0-rc.1` on, nothing breaks before 2.0. Neither package is published yet: build them locally, as [Build](#build) shows, to try Nexo. The implementation, `1.0.0-preview.1`, implements language version `1.0.0-preview.1`. [The status overview](https://github.com/FormaUI/Nexo/blob/main/docs/features-status.md) says what is implemented, what remains, and [what 1.0 requires](https://github.com/FormaUI/Nexo/blob/main/docs/features-status.md#what-1-0-requires).
130
+
131
+ ## Documents
132
+
133
+ | Document | What it holds |
134
+ | --- | --- |
135
+ | [Guide](https://github.com/FormaUI/Nexo/blob/main/docs/embedding-guide.md) | Embedding Nexo in an application, by example |
136
+ | [Specification](https://github.com/FormaUI/Nexo/blob/main/spec/README.md) | The contract, in two parts: the language, what a script means, and the runtime, what an application provides to run it |
137
+ | [Language history](https://github.com/FormaUI/Nexo/blob/main/LANGUAGE-HISTORY.md) | Each language version and what it changed |
138
+ | [Changelog](https://github.com/FormaUI/Nexo/blob/main/CHANGELOG.md) | Each release of the packages and what it changed |
139
+ | [Status](https://github.com/FormaUI/Nexo/blob/main/docs/features-status.md) | What is implemented, and what remains |
140
+ | [Design](https://github.com/FormaUI/Nexo/blob/main/docs/nexo-design.md) | How Nexo is built: its stages, modules, evaluation and tooling |
141
+ | [Contributing](https://github.com/FormaUI/Nexo/blob/main/CONTRIBUTING.md) | Report a bug, develop a change and run the checks |
142
+
143
+ ## Build
144
+
145
+ ```powershell
146
+ ./build.ps1
147
+ ```
148
+
149
+ The gate runs the tests, bundles Nexo, builds the NuGet package project with no warnings and checks its formatting. The full gate, `./build.ps1 -Full`, runs it, then packs the npm package `@formaui-net/nexo` and the NuGet package `formaui-net.Nexo` into `artifacts/`, and verifies each as a consumer installs it.
150
+
151
+ ## License
152
+
153
+ Apache License 2.0; see [LICENSE](https://github.com/FormaUI/Nexo/blob/main/LICENSE) and [NOTICE](https://github.com/FormaUI/Nexo/blob/main/NOTICE).
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
- "name": "@formaui-net/nexo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@formaui-net/nexo",
3
+ "version": "1.0.0-preview.1",
4
+ "description": "Nexo is an embeddable language with no domain of its own: the host declares the typed vocabulary, and scripts use it to compute and shape data. Nexo checks every script against that vocabulary before it runs, and evaluates it, read-only, into immutable data.",
5
+ "license": "Apache-2.0",
6
+ "author": "Eyal Alon",
7
+ "homepage": "https://github.com/FormaUI/Nexo#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/FormaUI/Nexo.git"
11
+ },
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./src/nexo.d.ts",
16
+ "default": "./src/nexo.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "src",
21
+ "LICENSE",
22
+ "NOTICE",
23
+ "README.md"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "bundle": "node scripts/bundle.mjs",
30
+ "benchmark": "node benchmarks/run.mjs"
31
+ },
32
+ "devDependencies": {
33
+ "esbuild": "^0.25.0"
34
+ }
35
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * ArrayUtils — operations on JavaScript arrays that need no knowledge of the language
3
+ */
4
+
5
+ export class ArrayUtils {
6
+ /** The first index of the list that holds no value at all, a hole, or -1 where every index holds one; an index that holds `undefined` holds a value. */
7
+ static findMissingIndex(list) {
8
+ for (let index = 0; index < list.length; index++) {
9
+ if (!(index in list)) {
10
+ return index;
11
+ }
12
+ }
13
+
14
+ return -1;
15
+ }
16
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * ObjectUtils — tests and a write on JavaScript objects that need no knowledge of the language
3
+ */
4
+
5
+ export class ObjectUtils {
6
+ /** Whether the value is an object that is neither null nor an array, class instances included. */
7
+ static isNonArrayObject(value) {
8
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
9
+ }
10
+
11
+ /** Whether the value is an object whose prototype is `Object.prototype` or null, as an object literal, parsed JSON and `Object.create(null)` are. */
12
+ static isPlainObject(value) {
13
+ if (typeof value !== 'object' || value === null) {
14
+ return false;
15
+ }
16
+
17
+ const prototype = Object.getPrototypeOf(value);
18
+
19
+ return prototype === Object.prototype || prototype === null;
20
+ }
21
+
22
+ /**
23
+ * Writes the value to the object's field by assignment, as an ordinary data object takes one, and defines a field named `__proto__` as an own data property, which assigning it would not do,
24
+ * changing the object's prototype instead. It makes no promise about an object whose fields have setters of their own.
25
+ */
26
+ static defineDataProperty(object, name, value) {
27
+ if (name === '__proto__') {
28
+ Object.defineProperty(object, name, { value, writable: true, enumerable: true, configurable: true });
29
+ } else {
30
+ object[name] = value;
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * DefinitionLocations — where in a definition its caller supplied each part of its canonical copy came from, for one whose validation moved a part
3
+ */
4
+
5
+ export class DefinitionLocations {
6
+ #definition;
7
+ #partIndexes;
8
+
9
+ /**
10
+ * @param {object} definition The canonical copy.
11
+ * @param {WeakMap<object, number[]>} partIndexes The index each part of an interpolated string had in the caller's definition, by the canonical node, for each node whose parts validation moved.
12
+ */
13
+ constructor(definition, partIndexes) {
14
+ this.#definition = definition;
15
+ this.#partIndexes = partIndexes;
16
+ }
17
+
18
+ /** The pointer into the caller's definition of the part the pointer names in the canonical copy: the same pointer, but for each part of an interpolated string validation moved, which its original index names. */
19
+ locate(pointer) {
20
+ const segments = pointer.split('/').slice(1);
21
+ const original = [];
22
+ let node = this.#definition;
23
+
24
+ for (let index = 0; index < segments.length; index++) {
25
+ const segment = segments[index];
26
+
27
+ original.push(segment);
28
+
29
+ if (segment === 'parts' && this.#partIndexes.has(node) && index + 1 < segments.length) {
30
+ const part = Number(segments[++index]);
31
+
32
+ original.push(String(this.#partIndexes.get(node)[part] ?? part));
33
+ node = node.parts[part];
34
+ } else {
35
+ node = node?.[segment];
36
+ }
37
+ }
38
+
39
+ return { pointer: segments.length === 0 ? pointer : `/${original.join('/')}` };
40
+ }
41
+ }