@inventarch/session-system 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LANGUAGE.md +56 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +2 -2
- package/SPEC.md +3 -0
- package/dist/codec.d.ts +10 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +49 -0
- package/dist/codec.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +17 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +58 -0
- package/dist/memory.js.map +1 -0
- package/dist/native-selection.json +205 -0
- package/dist/native.ia.tgz +0 -0
- package/dist/reducer.d.ts +11 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +723 -0
- package/dist/reducer.js.map +1 -0
- package/dist/sqlite.d.ts +35 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/dist/sqlite.js +188 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/store.d.ts +19 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +97 -0
- package/dist/store.js.map +1 -0
- package/dist/system-package.json +330 -0
- package/dist/types.d.ts +411 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +78 -3
package/LANGUAGE.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Public IA language
|
|
2
|
+
|
|
3
|
+
IA records declare typed identities, fields and relationships. Owning canonical schemas define the structural contract; language syntax and reference resolution preserve those declarations.
|
|
4
|
+
|
|
5
|
+
The selected vocabulary below is shared by this release. Use `ia vocabulary --json` for its attributed catalogue and `ia vocabulary --schema` for canonical field schemas. `ia validate` reports structural and evaluated evidence separately. An admitted declaration does not establish semantic quality or grant execution authority.
|
|
6
|
+
|
|
7
|
+
Spec source locators do not load documents. Resource capture and disclosure require explicit selection, matching pins and a host-owned disclosure boundary. Model, operation, evaluator and authority callbacks belong to the application host.
|
|
8
|
+
|
|
9
|
+
| Word | Owner | Meaning |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| @agent | agent-system | Names a participant and the vocabulary to which its governance applies. It does not grant host permissions. |
|
|
12
|
+
| @agent-profile | agent-composition-system | Composes an agent, capabilities, optional mandate/voice/delegates and installed execution contracts. |
|
|
13
|
+
| @artifact-set | taxonomy | Defines a closed grouping of artifact genres. |
|
|
14
|
+
| @authoring-guide | authoring-system | Associates a vocabulary owner and schema with an authoring reference and usage guidance. |
|
|
15
|
+
| @axis | taxonomy | Defines a closed coordinate axis for selection. |
|
|
16
|
+
| @capability | agent-composition-system | Groups operations, procedures, templates, checks and included capabilities with declared execution bounds. |
|
|
17
|
+
| @cardinality | taxonomy | Defines relationship multiplicity constraints. |
|
|
18
|
+
| @case | compliance-system | Declares scenario inputs, expected behavior and evaluator attribution. A declaration is not an observed test result. |
|
|
19
|
+
| @category | taxonomy | Defines a closed concept classification used by record shapes and contextual selection. |
|
|
20
|
+
| @check | compliance-system | Names a check implementation and scope. Declaring an implementation name does not install or execute it. |
|
|
21
|
+
| @contract | compliance-system | Names versioned requirements that may be adopted by other records. Requirements need explicit evaluation evidence. |
|
|
22
|
+
| @convention | governance-system | Declares a convention in the shared governance shape. |
|
|
23
|
+
| @decision | work-system | Represents a choice that is needed or has been made: the question, options and decider, and once made, the choice and rationale. |
|
|
24
|
+
| @dimension | taxonomy | Defines a supported record dimension used by conditions and lookup. |
|
|
25
|
+
| @distribution | workspace-system | Declares root records from which a distributable closure is selected. |
|
|
26
|
+
| @execution-binding | agent-composition-system | Connects a native target to a host-installed entry or operation descriptor. |
|
|
27
|
+
| @harness | agent-composition-system | Composes profiles and execution bindings in a workspace under a host contract. |
|
|
28
|
+
| @hook | hook-authoring-system | Represents a host event, tool/path selection and guard message. Registration and executing a guard require a host adapter. |
|
|
29
|
+
| @improvement | learning-system | Represents a proposed change, review metadata and publication metadata. It does not authorize or apply the proposal. |
|
|
30
|
+
| @intent-shape | taxonomy | Defines a request framing and its retrieval defaults. |
|
|
31
|
+
| @kind | taxonomy | Defines a closed semantic role for records; lowering determines the role of each registered word. |
|
|
32
|
+
| @lane | taxonomy | Defines a retrieval lane associated with record kinds. |
|
|
33
|
+
| @law | governance-system | Declares a rule with severity. Structural admission cannot establish the truth or suitability of its prose. |
|
|
34
|
+
| @mandate | agent-system | States bounded authority and conditions for a participant. Host authorization remains independent. |
|
|
35
|
+
| @milestone | work-system | Represents an outcome with an exit criterion inside exactly one plan; it names a condition, not the work toward it. |
|
|
36
|
+
| @move | taxonomy | Defines the closed classification of an agent action or activity. |
|
|
37
|
+
| @observation | learning-system | Represents an attributed evidence account with interpretation and retention metadata. Evidence claims are not verified by field typing. |
|
|
38
|
+
| @operation | authoring-system | Binds a declared operation to an implementation/input/output/effect contract; the host installs implementations. |
|
|
39
|
+
| @phase | taxonomy | Defines a cognitive phase coordinate: orient, plan, act or learn. |
|
|
40
|
+
| @placement | taxonomy | Defines source authority and reach metadata. |
|
|
41
|
+
| @plan | work-system | Represents an arrangement of milestones toward an intent; it heads the work hierarchy and has no parent. Plans do not nest. |
|
|
42
|
+
| @playbook | governance-system | Represents a procedure as phase/primitive cells. Cell delivery is generic; the authored method belongs to its author. |
|
|
43
|
+
| @predicate | taxonomy | Defines a directed relationship and its inverse spelling. |
|
|
44
|
+
| @primitive | taxonomy | Defines a cognitive primitive coordinate; a cell is selected using its phase and primitive. |
|
|
45
|
+
| @principle | governance-system | Declares a governing rationale in the shared governance shape. |
|
|
46
|
+
| @run | session-system | Represents a governed run identity, declared phase, status and owner. Declaration does not start execution. |
|
|
47
|
+
| @schema | floor | Declares the structural contract for exactly one registered discriminator. |
|
|
48
|
+
| @spec | work-system | Represents a maintained specification with explicit status and at most one same-word supersession. Contents and document membership belong to its author; a source locator does not load a body or prove semantic quality. |
|
|
49
|
+
| @system | floor | Registers vocabulary, direct system dependencies, a local steward and consent for relationships. |
|
|
50
|
+
| @task | work-system | Represents one owner's action toward exactly one milestone. Whether it is ready to start is computed by a work evaluator, never stored on the record. |
|
|
51
|
+
| @template | template-system | Represents bounded rendering inputs and output structure. Rendering does not publish or install output. |
|
|
52
|
+
| @value-type | taxonomy | Defines the field types that schemas may require. |
|
|
53
|
+
| @voice | agent-composition-system | Declares communication attributes separate from authority and procedure. |
|
|
54
|
+
| @workspace | workspace-system | Groups systems into an explicit work boundary; relationships can describe dependencies between boundaries. |
|
|
55
|
+
|
|
56
|
+
This guide describes the selected structural vocabulary. Private expert procedures, live provider behavior and unobserved platform qualification are separate from the installed public contract.
|
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
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @inventarch/session-system
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
See [the package contract](SPEC.md) and the exported TypeScript declarations.
|
package/SPEC.md
ADDED
package/dist/codec.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SessionError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(code: string, message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function requireValue(condition: unknown, code: string, message: string): asserts condition;
|
|
6
|
+
export declare function canonical(value: unknown): string;
|
|
7
|
+
export declare function digest(value: unknown): string;
|
|
8
|
+
export declare function copy<T>(value: T): T;
|
|
9
|
+
export declare function identifier(value: string): string;
|
|
10
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAGA,qBAAa,YAAa,SAAQ,KAAK;IAEnC,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB;AACD,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAEjG;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAyBhD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE7C;AACD,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEnC;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAShD"}
|
package/dist/codec.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
export class SessionError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = 'SessionError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function requireValue(condition, code, message) {
|
|
11
|
+
if (!condition)
|
|
12
|
+
throw new SessionError(code, message);
|
|
13
|
+
}
|
|
14
|
+
export function canonical(value) {
|
|
15
|
+
const visit = (item, depth) => {
|
|
16
|
+
requireValue(depth <= 64, 'IA-SESSION-LIMIT-EXCEEDED', 'Structured data nesting exceeds 64');
|
|
17
|
+
if (item === null || typeof item === 'string' || typeof item === 'boolean')
|
|
18
|
+
return item;
|
|
19
|
+
if (typeof item === 'number' && Number.isFinite(item))
|
|
20
|
+
return item;
|
|
21
|
+
if (Array.isArray(item))
|
|
22
|
+
return item.map((v) => visit(v, depth + 1));
|
|
23
|
+
if (typeof item === 'object' &&
|
|
24
|
+
item !== null &&
|
|
25
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(item))) {
|
|
26
|
+
const out = Object.create(null);
|
|
27
|
+
for (const key of Object.keys(item).sort()) {
|
|
28
|
+
requireValue(!['__proto__', 'prototype', 'constructor'].includes(key), 'IA-SESSION-INPUT-INVALID', 'Unsafe object key');
|
|
29
|
+
out[key] = visit(item[key], depth + 1);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
throw new SessionError('IA-SESSION-INPUT-INVALID', 'Expected finite JSON data');
|
|
34
|
+
};
|
|
35
|
+
return JSON.stringify(visit(value, 0));
|
|
36
|
+
}
|
|
37
|
+
export function digest(value) {
|
|
38
|
+
return createHash('sha256').update(canonical(value)).digest('hex');
|
|
39
|
+
}
|
|
40
|
+
export function copy(value) {
|
|
41
|
+
return JSON.parse(canonical(value));
|
|
42
|
+
}
|
|
43
|
+
export function identifier(value) {
|
|
44
|
+
requireValue(typeof value === 'string' &&
|
|
45
|
+
/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(value) &&
|
|
46
|
+
!['__proto__', 'prototype', 'constructor'].includes(value), 'IA-SESSION-INPUT-INVALID', 'Expected a safe operational identifier');
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,OAAO,YAAa,SAAQ,KAAK;IAE1B;IADX,YACW,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAA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BAA0B,EAC1B,mBAAmB,CACpB,CAAC;gBACF,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAE,IAAgC,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM,IAAI,YAAY,CAAC,0BAA0B,EAAE,2BAA2B,CAAC,CAAC;IAClF,CAAC,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AACD,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AACD,MAAM,UAAU,IAAI,CAAI,KAAQ;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAC3C,CAAC;AACD,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,YAAY,CACV,OAAO,KAAK,KAAK,QAAQ;QACvB,oCAAoC,CAAC,IAAI,CAAC,KAAK,CAAC;QAChD,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC5D,0BAA0B,EAC1B,wCAAwC,CACzC,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export { SessionError, canonical, digest, copy, identifier } from './codec.js';
|
|
3
|
+
export { JournalStore, commandDigest } from './store.js';
|
|
4
|
+
export { MemoryBackend, memoryStore } from './memory.js';
|
|
5
|
+
export { replay, reduce, terminal, unresolved, humanWaitRuns } from './reducer.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export { SessionError, canonical, digest, copy, identifier } from './codec.js';
|
|
3
|
+
export { JournalStore, commandDigest } from './store.js';
|
|
4
|
+
export { MemoryBackend, memoryStore } from './memory.js';
|
|
5
|
+
export { replay, reduce, terminal, unresolved, humanWaitRuns } from './reducer.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JournalStore } from './store.js';
|
|
2
|
+
import type { Checkpoint, Command, CommandResult, Event, Journal, JournalBackend, Owner } from './types.js';
|
|
3
|
+
/** Deterministic conformance adapter; it makes no durability claim. */
|
|
4
|
+
export declare class MemoryBackend implements JournalBackend {
|
|
5
|
+
readonly journals: Map<string, Journal>;
|
|
6
|
+
private readonly owners;
|
|
7
|
+
private fence;
|
|
8
|
+
load(id: string): Promise<Journal | null>;
|
|
9
|
+
commit(command: Command, hash: string, events: Event[], owner?: Owner): Promise<CommandResult>;
|
|
10
|
+
checkpoint(id: string, checkpoint: Checkpoint, owner: Owner): Promise<void>;
|
|
11
|
+
acquire(id: string): Promise<Owner>;
|
|
12
|
+
validate(owner: Owner): Promise<void>;
|
|
13
|
+
release(owner: Owner): Promise<void>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare function memoryStore(): JournalStore;
|
|
17
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0B,YAAY,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE5G,uEAAuE;AACvE,qBAAa,aAAc,YAAW,cAAc;IAClD,QAAQ,CAAC,QAAQ,uBAA8B;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,KAAK,CAAK;IACZ,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAGzC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IAmB9F,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3E,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAMnC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AACD,wBAAgB,WAAW,IAAI,YAAY,CAE1C"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { copy, requireValue } from './codec.js';
|
|
3
|
+
import { assertOwner, duplicate, JournalStore } from './store.js';
|
|
4
|
+
/** Deterministic conformance adapter; it makes no durability claim. */
|
|
5
|
+
export class MemoryBackend {
|
|
6
|
+
journals = new Map();
|
|
7
|
+
owners = new Map();
|
|
8
|
+
fence = 0;
|
|
9
|
+
async load(id) {
|
|
10
|
+
return copy(this.journals.get(id) ?? null);
|
|
11
|
+
}
|
|
12
|
+
async commit(command, hash, events, owner) {
|
|
13
|
+
assertOwner(command, owner);
|
|
14
|
+
if (owner)
|
|
15
|
+
await this.validate(owner);
|
|
16
|
+
const journal = this.journals.get(command.sessionId) ?? { events: [], commands: {}, checkpoint: null };
|
|
17
|
+
const prior = duplicate(journal, command, hash);
|
|
18
|
+
if (prior)
|
|
19
|
+
return prior;
|
|
20
|
+
requireValue(journal.events.length === command.expected, 'IA-SESSION-REVISION-CONFLICT', 'Session changed');
|
|
21
|
+
const last = events.at(-1);
|
|
22
|
+
const result = { id: command.id, digest: hash, sequence: last.sequence, hash: last.hash };
|
|
23
|
+
this.journals.set(command.sessionId, copy({
|
|
24
|
+
...journal,
|
|
25
|
+
events: [...journal.events, ...events],
|
|
26
|
+
commands: { ...journal.commands, [command.id]: result },
|
|
27
|
+
}));
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
async checkpoint(id, checkpoint, owner) {
|
|
31
|
+
await this.validate(owner);
|
|
32
|
+
requireValue(owner.sessionId === id, 'IA-SESSION-OWNER-LOST', 'Wrong session owner');
|
|
33
|
+
const journal = this.journals.get(id);
|
|
34
|
+
requireValue(journal.events.length === checkpoint.sequence, 'IA-SESSION-REVISION-CONFLICT', 'Session changed');
|
|
35
|
+
journal.checkpoint = copy(checkpoint);
|
|
36
|
+
}
|
|
37
|
+
async acquire(id) {
|
|
38
|
+
requireValue(!this.owners.has(id), 'IA-SESSION-OWNER-BUSY', 'Session has an owner');
|
|
39
|
+
const owner = { sessionId: id, token: randomUUID(), fence: ++this.fence };
|
|
40
|
+
this.owners.set(id, owner);
|
|
41
|
+
return copy(owner);
|
|
42
|
+
}
|
|
43
|
+
async validate(owner) {
|
|
44
|
+
requireValue(this.owners.get(owner.sessionId)?.token === owner.token &&
|
|
45
|
+
this.owners.get(owner.sessionId)?.fence === owner.fence, 'IA-SESSION-OWNER-LOST', 'Session ownership lost');
|
|
46
|
+
}
|
|
47
|
+
async release(owner) {
|
|
48
|
+
await this.validate(owner);
|
|
49
|
+
this.owners.delete(owner.sessionId);
|
|
50
|
+
}
|
|
51
|
+
async close() {
|
|
52
|
+
this.owners.clear();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function memoryStore() {
|
|
56
|
+
return new JournalStore(new MemoryBackend());
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,WAAW,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