@cruba/crubal 0.0.0-stage → 0.2.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.
Files changed (99) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +97 -2
  3. package/dist/bin/crubal.d.ts +2 -0
  4. package/dist/bin/crubal.js +103 -0
  5. package/dist/bin/crubal.js.map +1 -0
  6. package/dist/src/access.d.ts +126 -0
  7. package/dist/src/access.js +517 -0
  8. package/dist/src/access.js.map +1 -0
  9. package/dist/src/arrival.d.ts +55 -0
  10. package/dist/src/arrival.js +124 -0
  11. package/dist/src/arrival.js.map +1 -0
  12. package/dist/src/browser.d.ts +10 -0
  13. package/dist/src/browser.js +13 -0
  14. package/dist/src/browser.js.map +1 -0
  15. package/dist/src/bundle.d.ts +66 -0
  16. package/dist/src/bundle.js +753 -0
  17. package/dist/src/bundle.js.map +1 -0
  18. package/dist/src/canonical.d.ts +6 -0
  19. package/dist/src/canonical.js +47 -0
  20. package/dist/src/canonical.js.map +1 -0
  21. package/dist/src/conditions.d.ts +28 -0
  22. package/dist/src/conditions.js +216 -0
  23. package/dist/src/conditions.js.map +1 -0
  24. package/dist/src/corpus.d.ts +8 -0
  25. package/dist/src/corpus.js +1207 -0
  26. package/dist/src/corpus.js.map +1 -0
  27. package/dist/src/defs.d.ts +151 -0
  28. package/dist/src/defs.js +611 -0
  29. package/dist/src/defs.js.map +1 -0
  30. package/dist/src/dictionary.d.ts +65 -0
  31. package/dist/src/dictionary.js +557 -0
  32. package/dist/src/dictionary.js.map +1 -0
  33. package/dist/src/exchange.d.ts +236 -0
  34. package/dist/src/exchange.js +1035 -0
  35. package/dist/src/exchange.js.map +1 -0
  36. package/dist/src/forms.d.ts +16 -0
  37. package/dist/src/forms.js +169 -0
  38. package/dist/src/forms.js.map +1 -0
  39. package/dist/src/index.d.ts +27 -0
  40. package/dist/src/index.js +29 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/lex.d.ts +21 -0
  43. package/dist/src/lex.js +142 -0
  44. package/dist/src/lex.js.map +1 -0
  45. package/dist/src/lifecycle.d.ts +84 -0
  46. package/dist/src/lifecycle.js +415 -0
  47. package/dist/src/lifecycle.js.map +1 -0
  48. package/dist/src/log.d.ts +78 -0
  49. package/dist/src/log.js +506 -0
  50. package/dist/src/log.js.map +1 -0
  51. package/dist/src/migrate.d.ts +111 -0
  52. package/dist/src/migrate.js +286 -0
  53. package/dist/src/migrate.js.map +1 -0
  54. package/dist/src/model.d.ts +68 -0
  55. package/dist/src/model.js +188 -0
  56. package/dist/src/model.js.map +1 -0
  57. package/dist/src/packages.d.ts +69 -0
  58. package/dist/src/packages.js +232 -0
  59. package/dist/src/packages.js.map +1 -0
  60. package/dist/src/print-text.d.ts +7 -0
  61. package/dist/src/print-text.js +216 -0
  62. package/dist/src/print-text.js.map +1 -0
  63. package/dist/src/publish.d.ts +27 -0
  64. package/dist/src/publish.js +275 -0
  65. package/dist/src/publish.js.map +1 -0
  66. package/dist/src/read-text.d.ts +10 -0
  67. package/dist/src/read-text.js +385 -0
  68. package/dist/src/read-text.js.map +1 -0
  69. package/dist/src/records.d.ts +31 -0
  70. package/dist/src/records.js +72 -0
  71. package/dist/src/records.js.map +1 -0
  72. package/dist/src/review.d.ts +22 -0
  73. package/dist/src/review.js +198 -0
  74. package/dist/src/review.js.map +1 -0
  75. package/dist/src/rules.d.ts +96 -0
  76. package/dist/src/rules.js +611 -0
  77. package/dist/src/rules.js.map +1 -0
  78. package/dist/src/schedule.d.ts +24 -0
  79. package/dist/src/schedule.js +126 -0
  80. package/dist/src/schedule.js.map +1 -0
  81. package/dist/src/std-packages.d.ts +9 -0
  82. package/dist/src/std-packages.js +268 -0
  83. package/dist/src/std-packages.js.map +1 -0
  84. package/dist/src/store.d.ts +164 -0
  85. package/dist/src/store.js +538 -0
  86. package/dist/src/store.js.map +1 -0
  87. package/dist/src/tree.d.ts +35 -0
  88. package/dist/src/tree.js +159 -0
  89. package/dist/src/tree.js.map +1 -0
  90. package/dist/src/units-table.d.ts +1 -0
  91. package/dist/src/units-table.js +200 -0
  92. package/dist/src/units-table.js.map +1 -0
  93. package/dist/src/units.d.ts +42 -0
  94. package/dist/src/units.js +98 -0
  95. package/dist/src/units.js.map +1 -0
  96. package/dist/src/views.d.ts +216 -0
  97. package/dist/src/views.js +761 -0
  98. package/dist/src/views.js.map +1 -0
  99. package/package.json +60 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
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,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Chris Thompson
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md CHANGED
@@ -1,3 +1,98 @@
1
- # Temporary Holding Version
1
+ # @cruba/crubal
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
+ The CRUBAL reference implementation. Pure functions, JSON in and JSON out, so a compiled core can replace
4
+ the internals later behind the same API.
5
+
6
+ **Level reached: Views**, every chapter of the spec (1–14). Conformance claim: `CRUBAL 2 · Views · corpus 2026-10-19` (the gate, 2026-10-19; `CLAIM.md`).
7
+
8
+ - **Reader:** the text form and JSON both ways, facet types, unknown keys kept exactly, plain-words refusals
9
+ with line numbers.
10
+ - **Dictionary:** full definitions, publish checks on facets and classes, resolution by meet, alias and unit
11
+ folding, value checks against facets and worn classes.
12
+ - **Rules:** rule blocks and facet shortcuts, publish checks (layered by address, no contradictions, one
13
+ spelling), and an engine that runs writes in order: refused, held, filled (including a failing gate's
14
+ `-`), derived (templates with `??` and `?`, rollups), flagged, incomplete, complete and completeness, with
15
+ value-state tests and global uniqueness.
16
+
17
+ - **Store:** hash-linked logs with redaction, intake through receive contracts (map, value maps, aliases,
18
+ shapes, ignore, keep-raw; raw bytes and their hash kept), landing by the trust order with alternatives,
19
+ matching parts before minting rows, evidence validation (independent witnesses, vetoes, version-split
20
+ proposals), and migration recipes with restamping and a review queue.
21
+
22
+ - **Exchange:** contract publish checks (parts per kind, defined facets, real values in value maps,
23
+ credentials as names only), runs in steps (`who` with roles, needs, map out with nested paths, value maps
24
+ and literals, act once per payload), receive runs that compare with the record and land by trust or as
25
+ suggestions, offer and take where only the overlap flows and a person's values are never overridden,
26
+ border wrappers verified against the presenter's key and its log, and package checks (prefixes, trust
27
+ entries, extending without changing).
28
+
29
+ - **Views:** shapes as maps into slots (addresses, aggregates over lower levels, templates, required
30
+ slots), views with selection, context (`of`), pins, hides, order and pages, filters as sub-indexes with
31
+ range and value buckets and counts that follow the other picks, indexable landing pages, audiences and
32
+ `shown to` rules (new and unknown values never public), roles that narrow an audience, the portable shape,
33
+ and read sets that decide which rows a write makes stale.
34
+
35
+ - **The backbone (chapters 1.12, 8.5, 9.2a, 10.7, 12.6, 14):** the log as effects, rebuild from the log
36
+ alone, `define` writes for the working package, and the journal that makes entries the only way state
37
+ changes (`log.ts`); arrival with bindings and strong and weak keys (`arrival.ts`); folded and owned keys
38
+ with attach, detach, archive, merge and instructions (`lifecycle.ts`); owners, edges, modes, the grantor
39
+ chain, permission menus, gates and emergency access (`access.ts`); partitioned views, the projection
40
+ stream and stream subscriptions with cursors and resets (`views.ts`, `exchange.ts`); the record set every
41
+ module reads through, so a backend that loads only what an operation needs can stand in for the memory
42
+ one (`records.ts`, docs/design/store.md); a package as one JSON document, printed back to the text form so
43
+ the text readers stay the one parser, hashed and signed (`bundle.ts`), and cut as a version with members by
44
+ diff, the change classifier of 4.8 and 5.11 and the recipe requirement (`publish.ts`, `crubal publish`;
45
+ docs/design/publishing.md); review decisions as writes, each one entry with the define, value or release it causes (`review.ts`); a held value
46
+ coming back when its verdict changes again; adopt, give back, clone and split (`lifecycle.ts`); a measurement contract landing observations, the first filling an empty
47
+ value, and the version split proposed at the threshold, never made (`exchange.ts`, `proposeSplit` in `store.ts`); hand-made lists (`select: list:` over the core facet `crubal:items`), page shapes whose slots hold
48
+ other views run with the page's record as context, dependent counts inside a filter's buckets, further
49
+ shapes under `shapes` and the core `crubal:jsonld` structured data for the public (`views.ts`); offer and take by the offer's mode: dump copies once, observed stores a link and no value, gathered takes
50
+ the presenter's updates over its own earlier values and never over the consumer's, controlled copies under
51
+ the presenter's terms (expires, reshare, revocable) and withdraws what the presenter stops giving; an
52
+ offer builder and an expiry sweep (`exchange.ts`); a person's arrival owned `domain:id` when the package lets a person
53
+ own that kind (14.1); dated keys, `keyFor` picking the key whose span holds an entry's moment (11.7); a form as data from a contract's needs, the record's answers and states and the caller's edges
54
+ (`forms.ts`, docs/design/index-and-forms.md); and a border that
55
+ consults access, journals every run, and grants a consumer's edge (`exchange.ts`).
56
+
57
+ A run applies the rules (7.4 step 6): a value a `must` rule won't have is parked as a contradiction citing
58
+ the rule and never lands, a `suggest` fills and a derivation lands with `origin: derived` and the rule as
59
+ its `via`, a changed verdict holds, and each is a logged effect.
60
+
61
+ It passes every corpus folder (198 cases; `crubal claim <corpus> --out CLAIM.md` runs every level and writes the claim, 13.3). The corpus and this package name no adopter and no third party:
62
+ `test.example` owns the data, `market:` stands for any marketplace, `bench` for any in-house tool, and
63
+ product, unit and the like are the test package's own kinds, never the core's.
64
+
65
+ Store also checks Ed25519 signatures against the owner's published key, replays intake records from their
66
+ kept bytes (deterministically, keeping earlier outcomes), reviews unknown and new values by key across all
67
+ records and proposes candidate facets by recurrence, keeps non-UTF-8 payloads as base64, and lands values by
68
+ the package's own trust order and facets' orders.
69
+
70
+ ```sh
71
+ npm test # unit tests and the Reader corpus
72
+ node bin/crubal.ts test ../../corpus --level views # the corpus runner, case by case
73
+ node bin/crubal.ts read data.crubal --defs facets.crubal
74
+ node bin/crubal.ts print data.json --defs facets.crubal [--plain]
75
+ ```
76
+
77
+ Needs Node 23.6 or later (it runs the TypeScript directly).
78
+
79
+ | File | Does |
80
+ |---|---|
81
+ | `src/tree.ts` | lines, comments, indentation, the pair separator (chapter 2.1) |
82
+ | `src/lex.ts` | quoting, details and short lists (2.5–2.7) |
83
+ | `src/defs.ts` | what the Reader needs from definitions: types, how many, units, rows, levels (4.2, 4.5, 11.2) |
84
+ | `src/read-text.ts` | text to the JSON form (2, 3) |
85
+ | `src/print-text.ts` | the JSON form to canonical text (2.9) |
86
+ | `src/canonical.ts` | canonical JSON with sets sorted (3.9) |
87
+ | `src/dictionary.ts` | definitions as JSON, publish checks, resolution, folding, value checks (4, 5) |
88
+ | `src/conditions.ts` | conditions with three-valued empties (6.3) |
89
+ | `src/units.ts` | a starter units table, until the standard units package exists |
90
+ | `src/rules.ts` | rules, shortcuts, rule-set checks and the write engine (6) |
91
+ | `src/store.ts` | logs, receive contracts and intake, landing and trust, part matching, evidence (8, 9) |
92
+ | `src/migrate.ts` | migration recipes, checks and restamping (10) |
93
+ | `src/exchange.ts` | contract checks, runs, offer and take, borders (7, 8.5.1) |
94
+ | `src/packages.ts` | package files: prefixes, trust entries, extending (11) |
95
+ | `src/views.ts` | shapes, views, filters, audiences and roles, projections and staleness (12) |
96
+ | `src/corpus.ts` | the conformance runner (13) |
97
+
98
+ Next: make the repo public, publish `@cruba/crubal`, and start crubal.com.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ // crubal: read, print and test CRUBAL.
3
+ // crubal test <corpus> [--level reader] run a level's corpus folders
4
+ // crubal claim <corpus> [--level views] [--out CLAIM.md] run every level up to one and print the claim (13.3)
5
+ // crubal read <file> --defs <file>... text to JSON
6
+ // crubal print <file.json> --defs <file>... JSON to text
7
+ // crubal publish <dir> [--previous <package.json>] [--date YYYY-MM-DD] [--key <file>] [--out <dir>]
8
+ // cut a version: members by diff, recipes required, hash, signature
9
+ import { parseJson } from "../src/model.js";
10
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { canonical, emptyDictionary, printText, publish, readDefinitions, readText, runCorpus } from "../src/index.js";
13
+ const [cmd, target, ...rest] = process.argv.slice(2);
14
+ const flag = (name) => rest.flatMap((a, i) => (a === name ? [rest[i + 1]] : []));
15
+ function dictionary() {
16
+ const dict = emptyDictionary();
17
+ for (const f of flag("--defs"))
18
+ readDefinitions(readFileSync(f, "utf8"), dict);
19
+ return dict;
20
+ }
21
+ if (cmd === "test" && target) {
22
+ const level = flag("--level")[0] ?? "reader";
23
+ const results = runCorpus(target, level);
24
+ for (const r of results)
25
+ console.log(`${r.pass ? "pass" : "FAIL"} ${r.folder}/${r.name}${r.detail ? ` ${r.detail}` : ""}`);
26
+ const failed = results.filter((r) => !r.pass).length;
27
+ console.log(`\n${results.length - failed}/${results.length} passed (${level})`);
28
+ process.exit(failed ? 1 : 0);
29
+ }
30
+ else if (cmd === "claim" && target) {
31
+ // A claim names the language version, the level and the corpus version it passed (13.3), and links the run.
32
+ const LEVELS = ["reader", "dictionary", "rules", "store", "exchange", "views"];
33
+ const upTo = flag("--level")[0] ?? "views";
34
+ if (!LEVELS.includes(upTo)) {
35
+ console.log(`unknown level ${upTo}; one of ${LEVELS.join(", ")}`);
36
+ process.exit(2);
37
+ }
38
+ const version = existsSync(join(target, "VERSION")) ? readFileSync(join(target, "VERSION"), "utf8").trim() : "unversioned";
39
+ const lines = [];
40
+ let failed = 0;
41
+ for (const level of LEVELS.slice(0, LEVELS.indexOf(upTo) + 1)) {
42
+ const results = runCorpus(target, level);
43
+ const bad = results.filter((r) => !r.pass);
44
+ failed += bad.length;
45
+ const name = level.charAt(0).toUpperCase() + level.slice(1);
46
+ lines.push(`${bad.length ? "FAILED" : "CRUBAL 2"} · ${name} · corpus ${version} (${results.length - bad.length}/${results.length})`);
47
+ for (const r of bad)
48
+ lines.push(` FAIL ${r.folder}/${r.name}${r.detail ? ` ${r.detail}` : ""}`);
49
+ }
50
+ for (const l of lines)
51
+ console.log(l);
52
+ const out = flag("--out")[0];
53
+ if (out && !failed) {
54
+ const today = new Date().toISOString().slice(0, 10);
55
+ writeFileSync(out, `# Conformance claim\n\n${lines.map((l) => `- ${l}`).join("\n")}\n\nRun on ${today} with \`crubal claim\` from this package against the corpus tagged \`corpus/${version}\` (spec 13.3, 13.4).\n`);
56
+ console.log(`written ${out}`);
57
+ }
58
+ process.exit(failed ? 1 : 0);
59
+ }
60
+ else if (cmd === "read" && target) {
61
+ const dict = dictionary();
62
+ const w = readText(readFileSync(target, "utf8"), dict);
63
+ console.log(rest.includes("--canonical") ? canonical(w, dict) : JSON.stringify(w, null, 2));
64
+ }
65
+ else if (cmd === "publish" && target) {
66
+ const dir = target;
67
+ const src = readFileSync(join(dir, "package.crubal"), "utf8");
68
+ const dict = emptyDictionary();
69
+ readDefinitions(src, dict);
70
+ // Reference records (11.1): every other .crubal file in the directory.
71
+ const records = readdirSync(dir).filter((f) => f.endsWith(".crubal") && f !== "package.crubal").flatMap((f) => readText(readFileSync(join(dir, f), "utf8"), dict).records);
72
+ const previousFile = flag("--previous")[0];
73
+ const previous = previousFile ? parseJson(readFileSync(previousFile, "utf8")) : undefined;
74
+ const keyFile = flag("--key")[0];
75
+ const keyJson = keyFile ? JSON.parse(readFileSync(keyFile, "utf8")) : undefined;
76
+ const date = flag("--date")[0] ?? new Date().toISOString().slice(0, 10);
77
+ const { bundle, changes } = publish(src, { date, ...(previous ? { previous } : {}), ...(records.length ? { records } : {}), ...(keyJson ? { key: { d: keyJson.private, x: keyJson.public } } : {}) });
78
+ for (const ch of changes)
79
+ if (ch.kind !== "unchanged")
80
+ console.error(` ${ch.kind.padEnd(9)} ${ch.member}${ch.why.length ? ` (${ch.why.join("; ")})` : ""}`);
81
+ const out = flag("--out")[0];
82
+ if (out) {
83
+ const at = join(out, String(bundle.package), String(bundle.version));
84
+ mkdirSync(at, { recursive: true });
85
+ writeFileSync(join(at, "package.json"), `${JSON.stringify(bundle, null, 2)}\n`);
86
+ writeFileSync(join(at, "package.crubal"), src);
87
+ const latest = join(out, String(bundle.package));
88
+ writeFileSync(join(latest, "package.json"), `${JSON.stringify(bundle, null, 2)}\n`);
89
+ writeFileSync(join(latest, "package.crubal"), src);
90
+ console.error(`published ${bundle.id} /${bundle.version} to ${at}${bundle.sig ? " (signed)" : " (unsigned)"}`);
91
+ }
92
+ else
93
+ console.log(JSON.stringify(bundle, null, 2));
94
+ void existsSync;
95
+ }
96
+ else if (cmd === "print" && target) {
97
+ console.log(printText(parseJson(readFileSync(target, "utf8")), dictionary(), rest.includes("--plain") ? "plain" : "full"));
98
+ }
99
+ else {
100
+ console.log("usage: crubal test <corpus> [--level reader] | crubal claim <corpus> [--level views] [--out CLAIM.md] | crubal read <file> --defs <file> | crubal print <file.json> --defs <file> | crubal publish <dir> [--previous <package.json>] [--date YYYY-MM-DD] [--key <file>] [--out <dir>]");
101
+ process.exit(2);
102
+ }
103
+ //# sourceMappingURL=crubal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crubal.js","sourceRoot":"","sources":["../../bin/crubal.ts"],"names":[],"mappings":";AACA,uCAAuC;AACvC,yEAAyE;AACzE,kHAAkH;AAClH,0DAA0D;AAC1D,2DAA2D;AAC3D,sGAAsG;AACtG,+GAA+G;AAE/G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGvH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrD,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAW,CAAC,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CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACxI,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,uRAAuR,CAAC,CAAC;IACrS,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,126 @@
1
+ import type { Dictionary } from "./defs.ts";
2
+ import type { JsonObject, Record } from "./model.ts";
3
+ import type { RecordSet } from "./records.ts";
4
+ import { type ViewSet } from "./views.ts";
5
+ export declare const MODES: readonly ["none", "view", "consume", "control", "admin"];
6
+ export type Mode = (typeof MODES)[number];
7
+ export declare const VERBS: readonly ["see", "edit", "run", "review", "archive", "merge", "apply", "install", "grant"];
8
+ export type MenuItem = {
9
+ name: string;
10
+ verbs: {
11
+ [verb: string]: string[];
12
+ };
13
+ on?: string;
14
+ line: number;
15
+ };
16
+ export type Preset = {
17
+ name: string;
18
+ items: string[];
19
+ audience: string;
20
+ line: number;
21
+ };
22
+ export type Permissions = {
23
+ name?: string;
24
+ menu: Map<string, MenuItem>;
25
+ presets: Map<string, Preset>;
26
+ relations: Map<string, {
27
+ only: boolean;
28
+ }>;
29
+ /** `person` → the kinds and classes a person may own (14.1) */
30
+ ownership: Map<string, string[]>;
31
+ /** A platform's published emergency terms (11.7, 14.13). */
32
+ emergency?: {
33
+ approvers: number;
34
+ longest: string;
35
+ };
36
+ };
37
+ export type Edge = {
38
+ edge: string;
39
+ who: string;
40
+ relation: string;
41
+ mode: Mode;
42
+ on: string;
43
+ grants: string[];
44
+ where?: string;
45
+ until?: string;
46
+ gate?: string;
47
+ reviewer?: string;
48
+ by: string;
49
+ emergency?: JsonObject;
50
+ /** The package line an edge was declared on; an edge written to the log has none. */
51
+ line?: number;
52
+ };
53
+ export declare function emptyPermissions(): Permissions;
54
+ /** Read `permissions:`, `ownership:`, `emergency:` and `edge:` blocks. */
55
+ export declare function readAccess(source: string): {
56
+ perms: Permissions;
57
+ edges: Edge[];
58
+ };
59
+ /** Is `who` a caller of another owner? Local callers are bare IDs; foreign ones carry their owner's domain. */
60
+ export declare function foreign(who: string, owner: string): boolean;
61
+ export type Effective = {
62
+ mode: Mode;
63
+ items: Set<string>;
64
+ relations: Set<string>;
65
+ gated: boolean;
66
+ edges: Edge[];
67
+ };
68
+ export declare class Access {
69
+ /** The package's show rules (12.4), when the caller has them; without them every facet counts as public. */
70
+ views?: Pick<ViewSet, "shown" | "shownFor">;
71
+ /**
72
+ * May the caller see a facet of a record without an item: what the show rules give their audience,
73
+ * capped at member (12.4, default deny above member: a staff facet takes an item; admin and the owner see
74
+ * everything). A rule with a `for` covering the record decides over one for everywhere.
75
+ */
76
+ visible(callerId: string, facet: string, recordId?: string): boolean;
77
+ /** The edges; a store that journals (chapter 8.5) points this at its draft's edges. */
78
+ edges: Map<string, Edge>;
79
+ readonly dict: Dictionary;
80
+ readonly perms: Permissions;
81
+ readonly records: RecordSet;
82
+ readonly owner: string;
83
+ readonly now: string | undefined;
84
+ constructor(dict: Dictionary, perms: Permissions, records: RecordSet, edges: Edge[], owner: string, now?: string);
85
+ /** The records up a record's `within` chain, nearest first (14.2). */
86
+ ancestors(id: string): string[];
87
+ /** Refuse a `within` cycle (14.12). `lineOf` names the line a record was written at, for the refusal. */
88
+ checkWithin(lineOf?: (id: string) => number | undefined): void;
89
+ /** A merged record resolves through `into` (1.12), for edges on it and reaches into it. */
90
+ surviving(id: string): string;
91
+ covers(e: Edge, recordId: string): boolean;
92
+ /** Does the edge's `where` hold for this record (14.4)? It narrows per record covered. */
93
+ holds(e: Edge, recordId: string): boolean;
94
+ /** Is an edge live (14.4, 14.5): not lapsed, and its grantor live and covering it? */
95
+ live(e: Edge, seen?: Set<string>): boolean;
96
+ /** Does the caller hold the key to this record: the owner, or a hosted person over a record they own? */
97
+ owns(callerId: string, recordId: string): boolean;
98
+ /**
99
+ * The audience a caller belongs to (12.4, 14.4): the owner; staff for anyone with a control or admin
100
+ * edge, or an emergency edge; member for anyone the owner has admitted by any live edge; else public.
101
+ */
102
+ audienceOf(callerId: string): string;
103
+ /** The menu items a list of grants expands to (presets open up). */
104
+ expand(grants: string[]): Set<string>;
105
+ /** A caller's access to a record from every live edge on it or an ancestor (14.4). */
106
+ effective(callerId: string, recordId: string): Effective;
107
+ /** Does the caller stand in a view's partition to the record (12.6, 14.10)? */
108
+ standsIn(callerId: string, recordId: string, partition: string): boolean;
109
+ private scopeOk;
110
+ /** May the caller do `verb` to `target` on the record (14.4, 14.6)? */
111
+ may(callerId: string, verb: string, target: string, recordId: string): boolean;
112
+ /** May the caller do `verb` to `target` on any record at all: by a live admin edge, or a control edge carrying it? */
113
+ mayAnywhere(callerId: string, verb: string, target: string): boolean;
114
+ /** The live gated edge a caller's access comes through, when every granting edge is gated (14.7). */
115
+ gated(callerId: string, recordId: string): Edge | null;
116
+ /** Refuse an edge the store may not write (14.12, 14.13). */
117
+ checkEdge(e: Edge): void;
118
+ /** Refuse an emergency edge outside the platform's published terms (14.13). */
119
+ checkEmergency(e: Edge): void;
120
+ /** Refuse a write that makes a record wear a class not for its kind, or classes whose meet is empty (5.5). */
121
+ checkWears(r: Record, line?: number): void;
122
+ /** Refuse a person owning a record the package doesn't let a person own (14.1, 14.12). */
123
+ checkOwnership(r: Record, line?: number): void;
124
+ }
125
+ /** Publish checks for a permission block (14.6). */
126
+ export declare function checkPermissions(perms: Permissions, dict: Dictionary, contracts?: Set<string>, views?: Set<string>): void;