@zixcel/projection-contracts 0.0.0-stage → 0.10.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.
- package/LICENSE +202 -0
- package/LICENSE-PREVIOUS +21 -0
- package/NOTICE +5 -0
- package/README.md +44 -2
- package/contract.json +26 -0
- package/package.json +55 -4
- package/src/client.d.mts +12 -0
- package/src/client.mjs +3 -0
- package/src/contract.mjs +59 -0
- package/src/hash-browser.mjs +5 -0
- package/src/hash-node.mjs +2 -0
- package/src/index.d.mts +27 -0
- package/src/index.mjs +3 -0
- package/src/producer.mjs +180 -0
- package/src/publication.mjs +36 -0
- package/src/types/input.d.mts +24 -0
- package/src/types/snapshot.d.mts +43 -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/LICENSE-PREVIOUS
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NuxtJP contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zixcel/projection-contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Validate and seal bounded, renderer-neutral Data and Scene snapshots from explicitly
|
|
4
|
+
selected owner-visible source revisions. Deterministic lineage and publication
|
|
5
|
+
fences keep presentation tied to the accepted source without owning its meaning.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @zixcel/projection-contracts@0.10.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { produce, scene, ProjectionSlot } from '@zixcel/projection-contracts'
|
|
13
|
+
|
|
14
|
+
const source = { owner: 'example', ref: 'selected', revision: 'revision-1', kind: 'example' }
|
|
15
|
+
const data = produce({
|
|
16
|
+
key: 'review', producer: { id: 'builtin', version: '0.10.0',
|
|
17
|
+
contract: 'projection/0.10.0', configuration: 'reviewed' },
|
|
18
|
+
sources: [source], focus: 'resources', purpose: 'review',
|
|
19
|
+
visibilityRef: 'owner-authorized', limits: {}
|
|
20
|
+
}, [{ source, items: [], relations: [], unresolved: [], truncated: false }])
|
|
21
|
+
const slot = new ProjectionSlot('review')
|
|
22
|
+
const receipt = slot.publish(slot.begin(), data)
|
|
23
|
+
const view = scene(data, { key: 'scene', focus: 'resources', purpose: 'review',
|
|
24
|
+
regions: [], actions: [] })
|
|
25
|
+
console.log(receipt.revision, view.revision)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`@zixcel/projection-contracts/client` exposes browser-safe validation helpers.
|
|
29
|
+
Node/browser hashing uses identical SHA-256 bytes; the dependency on
|
|
30
|
+
`@zixcel/interaction/input` validates explicit interaction declarations.
|
|
31
|
+
|
|
32
|
+
The producer owns authorization, visible data and exact source selection. Scene
|
|
33
|
+
labels and regions do not grant permissions. `ProjectionSlot` is an in-memory,
|
|
34
|
+
disposable fence: it does not promise durability across restart. Use
|
|
35
|
+
`@zixcel/projection-runtime` for bounded execution and durable publication.
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
Run the repository workspace install, type checks and behavioral tests described
|
|
40
|
+
in the root README. Public dependencies resolve from npm; no vendor archive or
|
|
41
|
+
private registry is required. [License](LICENSE) · [Notices](NOTICE).
|
|
42
|
+
|
|
43
|
+
## Release provenance
|
|
44
|
+
|
|
45
|
+
Starting with 0.10.1, releases use GitHub Actions OIDC trusted publishing from `zixcel/projection-runtime` (`publish-npm.yml`), without a stored npm publishing token. The workflow verifies reviewed archive hashes and requires npm provenance metadata. Check the published version on npm and verify registry signatures and provenance with `npm audit signatures` in an installed consumer project. Package runtime behavior and API contracts are unchanged by this release.
|
package/contract.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"owner": "NuxtJP Projection Platform",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"implementation": "src/index.mjs; pure producer and executable in-memory publication contract, no durable runtime or renderer",
|
|
5
|
+
"ProjectionSource": {"required": ["owner", "ref", "revision", "kind"], "revision": "opaque exact owner snapshot token; never read latest; owner must provide an accessible exact snapshot", "additionalProperties": false},
|
|
6
|
+
"ProjectionRequest": {"required": ["key", "producer", "sources", "focus", "purpose", "visibilityRef", "limits"], "producer": ["id", "version", "contract", "configuration"], "additionalProperties": false},
|
|
7
|
+
"DataProjection": {"required": ["contract", "kind", "key", "revision", "lineage", "data"], "data": ["items", "relations", "unresolved", "truncated", "omittedByPolicy"], "item": ["id", "semanticRef", "group", "value", "evidence", "provenance", "resolutionRefs", "visibility", "sourceRefs"], "meaning": "already adopted owner references only; no name/path/shape interpretation or value conflict resolution"},
|
|
8
|
+
"SceneProjection": {"base": "DataProjection", "extraData": ["focus", "purpose", "regions", "actions"], "region": ["id", "role", "itemIds"], "action": ["id", "targetOwner", "commandRef", "contextRefs", "sourceRefs", "label"], "roles": ["Primary", "Context", "Interpretation", "Evidence", "Provenance", "Resolution", "Inspector", "Actions", "Activity"], "lineage": "exact source tuple + producer/request + DataProjection key/revision + exact Scene configuration", "authority": "available action is not authorized; final command admission stays with its owner"},
|
|
9
|
+
"ProjectedInteraction": {"placement":"optional Scene action.interaction", "required":["ref","generation","inputContractRef","input"], "input":"owner-declared @zixcel/interaction InputDeclaration, unchanged; operation and contract references must equal the action binding", "authority":"descriptor only, never submitted values, source bindings or authorization; missing declaration means read-only/unavailable", "additionalProperties":false},
|
|
10
|
+
"ProjectionRevision": "pp: + SHA-256 of bounded canonical JSON contract/kind/key/exact lineage/data; minted by Projection Platform, never copied from source, Graph commit or delivery sequence",
|
|
11
|
+
"serialization": "plain JSON; keys lexically sorted, unordered sources/items/relations normalized, ordered Scene regions retained; finite safe integers, well-formed Unicode; no getters/toJSON/functions/prototypes; digest is content identity, not authenticity",
|
|
12
|
+
"stateLayers": {"ProjectionState": "server-derived Data/Scene snapshots and lineage", "PresentationState": "client scene selection, focus, selected item, expansion and navigation stack; separate from server ProjectionState", "RenderState": "renderer-local DOM/canvas/layout/animation/scroll; never serialized here"},
|
|
13
|
+
"grouping": "semantic group requires an exact owner semanticRef; structural source paths and presentation hints can group without becoming meaning; identical predicates group without merging or overwriting claim values",
|
|
14
|
+
"visibility": "input is owner-policy-filtered and carries visibilityRef; visible/redacted/omitted are owner decisions, not PP authorization. Redacted item value and semantic/evidence/provenance refs are removed. Owner must omit relations that would disclose hidden data. Source refs themselves must be safe to disclose.",
|
|
15
|
+
"bounds": {"sources":8,"items":256,"relations":512,"provenance":512,"unresolved":64,"regions":16,"actions":64,"snapshotBytes":524288,"inputBytes":2097152,"jsonDepth":16,"jsonNodes":32768},
|
|
16
|
+
"oversize": "typed ProjectionLimitExceeded, no silent truncation. Upstream truncated flag preserved. Large metadata+BULK payload is deferred to PP runtime; 512 KiB STATE limit unchanged.",
|
|
17
|
+
"rebuild": "readExact(ProjectionSource) must return exactly that snapshot; missing/reclaimed source yields ProjectionRebuildUnavailable, never latest substitution. Rebuild only from source owners, never previous cache.",
|
|
18
|
+
"retention": "rebuild guaranteed only while every exact source tuple member remains available under owner retention/in-flight claims. This pure slice adds no lease or retention policy. C4 Retained/InFlight external roots can protect owner objects; later runtime must acquire/release those through source owners before promising a retention window.",
|
|
19
|
+
"PendingProjectionRepair": {"fields": ["ticket", "request", "failure"], "rule": "exact source refs and original publication fence, no source body/cache as authority; source commit is not rolled back on projection failure"},
|
|
20
|
+
"publication": "one explicitly constructed in-memory slot per key, opaque CAS fence distinct from ProjectionRevision. Duplicate last accepted ticket is idempotent; older repair loses CAS after newer publication. Cache loss does not reset the fence. Durable CAS/scheduling/recovery stays PP1, no substitute Graph database here.",
|
|
21
|
+
"Crowsi": "recovery returns Snapshot bytes or exact NoChange with opaque ProjectionRevision; producer has no transport dependency. Peer ACK is bytes received, not semantic adoption/rendered/user saw it.",
|
|
22
|
+
"ProjectionDelta": {"status": "reserved contract only; not produced or accepted by this implementation", "fields": ["key", "baseProjectionRevision", "projectionRevision", "producerContract", "operations", "lineage"], "operations": "bounded owner-defined operations under exact producer contract; receiver validates exact base, target and lineage; never a Crowsi diff"},
|
|
23
|
+
"SSR": "serialize key/revision/exact lineage; adoptSnapshot checks the exact expected key/revision and closed payload/digest. No silent binding to latest. Source revision advancement requires an explicit owner recovery response.",
|
|
24
|
+
"outcomes": ["InvalidProjection", "InvalidSourceRevision", "SourceUnavailable", "ProjectionRebuildUnavailable", "ProjectionUnavailable", "ProjectionLimitExceeded", "StaleProjectionPublication"],
|
|
25
|
+
"forbidden": ["semantic or memory writer", "Grant issuer", "Invocation writer", "source restoration from cache", "HAT-supplied renderer code", "Vue/SFC/HTML fields", "DOM callbacks", "implicit provider refresh", "persistent session journal", "model scheduling"]
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zixcel/projection-contracts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.1",
|
|
4
|
+
"description": "Renderer-independent bounded projection, lineage and Scene contracts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"contract.json",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE",
|
|
16
|
+
"LICENSE-PREVIOUS"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./src/index.d.mts",
|
|
21
|
+
"import": "./src/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"types": "./src/client.d.mts",
|
|
25
|
+
"import": "./src/client.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"imports": {
|
|
29
|
+
"#hash": {
|
|
30
|
+
"browser": "./src/hash-browser.mjs",
|
|
31
|
+
"default": "./src/hash-node.mjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"ohash": "2.0.11",
|
|
36
|
+
"@zixcel/interaction": "0.10.1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --test test/*.test.mjs",
|
|
40
|
+
"typecheck": "tsc --noEmit --strict --module NodeNext --moduleResolution NodeNext --target ES2022 test/public-types.mts"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/zixcel/projection-runtime.git",
|
|
45
|
+
"directory": "packages/projection-contracts"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"registry": "https://registry.npmjs.org",
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"types": "./src/index.d.mts",
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"typescript": "5.9.3",
|
|
54
|
+
"@types/node": "24.12.0"
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "pnpm@10.29.3"
|
|
57
|
+
}
|
package/src/client.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Browser-safe exact projection wire types; owner meaning remains external. */
|
|
2
|
+
export type * from './types/snapshot.mjs';
|
|
3
|
+
import type { DataProjection, SceneProjection } from './types/snapshot.mjs';
|
|
4
|
+
export function validateSnapshot(value: unknown): DataProjection | SceneProjection;
|
|
5
|
+
export function canonical(value: unknown, maximum?: number): string;
|
|
6
|
+
export function copy<T>(value: T): T;
|
|
7
|
+
export function frozen<T>(value: T): Readonly<T>;
|
|
8
|
+
export function shape(value: unknown, required: string[], optional?: string[]): void;
|
|
9
|
+
export function text(value: unknown, maximum?: number): string;
|
|
10
|
+
export const roles: readonly import('./types/snapshot.mjs').RegionRole[];
|
|
11
|
+
export const LIMITS: Readonly<import('./types/input.mjs').ProjectionLimits>;
|
|
12
|
+
export class ProjectionError extends Error { readonly code: string; constructor(code: string) }
|
package/src/client.mjs
ADDED
package/src/contract.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {sha256} from '#hash'
|
|
2
|
+
const encoder=new TextEncoder()
|
|
3
|
+
const byteLength=value=>encoder.encode(value).length
|
|
4
|
+
export class ProjectionError extends Error {constructor(code){super(code);this.code=code}}
|
|
5
|
+
export const fail=code=>{throw new ProjectionError(code)}
|
|
6
|
+
export const LIMITS=Object.freeze({sources:8,items:256,relations:512,provenance:512,unresolved:64,regions:16,actions:64,snapshotBytes:524288})
|
|
7
|
+
export function limits(input={}){
|
|
8
|
+
shape(input,[],Object.keys(LIMITS));const result={...LIMITS,...input}
|
|
9
|
+
for(const key in result)if(!Number.isSafeInteger(result[key])||result[key]<1||result[key]>LIMITS[key])fail('ProjectionLimitExceeded')
|
|
10
|
+
return Object.freeze(result)
|
|
11
|
+
}
|
|
12
|
+
export function shape(v,required,optional=[]){
|
|
13
|
+
if(!v||Object.getPrototypeOf(v)!==Object.prototype||required.some(k=>!Object.hasOwn(v,k)))fail('InvalidProjection')
|
|
14
|
+
for(const k of Object.getOwnPropertyNames(v)){
|
|
15
|
+
const d=Object.getOwnPropertyDescriptor(v,k)
|
|
16
|
+
if(!d.enumerable||d.get||d.set||(!required.includes(k)&&!optional.includes(k)))fail('InvalidProjection')
|
|
17
|
+
}
|
|
18
|
+
if(Object.getOwnPropertySymbols(v).length)fail('InvalidProjection')
|
|
19
|
+
}
|
|
20
|
+
export function text(v,max=512){if(typeof v!=='string'||!v.length||v.length>max||byteLength(v)>max||!v.isWellFormed()||/[\x00-\x1f\x7f]/u.test(v))fail('InvalidProjection');return v}
|
|
21
|
+
export function list(v,max){if(!Array.isArray(v)||v.length>max)fail('ProjectionLimitExceeded');return v}
|
|
22
|
+
export function refs(v,max=32){return list(v,max).map(x=>text(x))}
|
|
23
|
+
// Bounded plain JSON only. No callbacks, toJSON, prototypes or renderer execution.
|
|
24
|
+
export function canonical(value,maximum=2097152){
|
|
25
|
+
let bytes=0,nodes=0
|
|
26
|
+
const add=n=>{bytes+=n;if(bytes>maximum)fail('ProjectionLimitExceeded')}
|
|
27
|
+
function walk(v,depth){
|
|
28
|
+
if(++nodes>32768||depth>16)fail('ProjectionLimitExceeded')
|
|
29
|
+
if(v===null||typeof v==='boolean'){add(5);return v}
|
|
30
|
+
if(typeof v==='number'){if(!Number.isSafeInteger(v))fail('InvalidProjection');add(24);return v}
|
|
31
|
+
if(typeof v==='string'){if(v.length>maximum)fail('ProjectionLimitExceeded');if(!v.isWellFormed())fail('InvalidProjection');add(byteLength(v)+2);return v}
|
|
32
|
+
if(Array.isArray(v)){add(v.length+2);if(v.length>4096)fail('ProjectionLimitExceeded');return v.map(x=>walk(x,depth+1))}
|
|
33
|
+
if(!v||Object.getPrototypeOf(v)!==Object.prototype)fail('InvalidProjection')
|
|
34
|
+
const keys=Object.getOwnPropertyNames(v);if(keys.length>1024||Object.getOwnPropertySymbols(v).length)fail('ProjectionLimitExceeded')
|
|
35
|
+
const out={};add(keys.length+2)
|
|
36
|
+
for(const k of keys.sort()){
|
|
37
|
+
const d=Object.getOwnPropertyDescriptor(v,k)
|
|
38
|
+
if(!d.enumerable||d.get||d.set||['__proto__','constructor','prototype','toJSON'].includes(k))fail('InvalidProjection')
|
|
39
|
+
text(k,512);add(byteLength(k)+3);out[k]=walk(v[k],depth+1)
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
43
|
+
const encoded=JSON.stringify(walk(value,0));if(byteLength(encoded)>maximum)fail('ProjectionLimitExceeded');return encoded
|
|
44
|
+
}
|
|
45
|
+
export const digest=value=>sha256(canonical(value))
|
|
46
|
+
export function frozen(v){if(v&&typeof v==='object'){Object.values(v).forEach(frozen);Object.freeze(v)}return v}
|
|
47
|
+
export function copy(v){return JSON.parse(canonical(v))}
|
|
48
|
+
export function sourceRef(v){shape(v,['owner','ref','revision','kind']);for(const k of ['owner','ref','revision','kind'])text(v[k]);return copy(v)}
|
|
49
|
+
export const sourceKey=v=>canonical(sourceRef(v))
|
|
50
|
+
export function unique(values,key=x=>x){const ids=new Set();for(const v of values){const id=key(v);if(ids.has(id))fail('InvalidProjection');ids.add(id)}return values}
|
|
51
|
+
export const roles=Object.freeze(['Primary','Context','Interpretation','Evidence','Provenance','Resolution','Inspector','Actions','Activity'])
|
|
52
|
+
export function request(v){
|
|
53
|
+
canonical(v);shape(v,['key','producer','sources','focus','purpose','visibilityRef','limits'])
|
|
54
|
+
text(v.key);text(v.focus);text(v.purpose);text(v.visibilityRef)
|
|
55
|
+
shape(v.producer,['id','version','contract','configuration']);text(v.producer.id);text(v.producer.version);text(v.producer.contract);text(v.producer.configuration)
|
|
56
|
+
const l=limits(v.limits),sources=unique(list(v.sources,l.sources).map(sourceRef),s=>canonical([s.owner,s.ref])).sort((a,b)=>sourceKey(a)<sourceKey(b)?-1:1)
|
|
57
|
+
if(!sources.length)fail('SourceUnavailable')
|
|
58
|
+
return frozen({...copy(v),sources,limits:l})
|
|
59
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Same SHA-256 UTF-8 bytes and hexadecimal identity as the Node contract.
|
|
2
|
+
// Reuse the already selected unjs primitive, never a second projection algorithm.
|
|
3
|
+
import {digest} from 'ohash/crypto'
|
|
4
|
+
export const sha256=value=>Array.from(atob(digest(value).replaceAll('-','+').replaceAll('_','/')+'='),
|
|
5
|
+
c=>c.charCodeAt(0).toString(16).padStart(2,'0')).join('')
|
package/src/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { ProjectionError, LIMITS, canonical } from './client.mjs';
|
|
2
|
+
export type * from './client.mjs';
|
|
3
|
+
export type * from './types/input.mjs';
|
|
4
|
+
import type { DataProjection, SceneProjection } from './client.mjs';
|
|
5
|
+
import type { ProjectionRequest, ExactSource, SceneConfiguration, ReadExact } from './types/input.mjs';
|
|
6
|
+
export type Snapshot = DataProjection | SceneProjection;
|
|
7
|
+
export interface PublicationTicket { readonly key: string; readonly expected: string }
|
|
8
|
+
export interface PublicationReceipt extends PublicationTicket { readonly publication: string; readonly revision: string }
|
|
9
|
+
export interface PendingRepair { readonly ticket: PublicationTicket; readonly request: ProjectionRequest; readonly failure: 'ProjectionUnavailable' | 'ProjectionLimitExceeded' }
|
|
10
|
+
/** Validate and deterministically seal explicitly selected owner-visible data. */
|
|
11
|
+
export function produce(input: ProjectionRequest, exactSources: readonly ExactSource[]): DataProjection;
|
|
12
|
+
export function scene(data: DataProjection, configuration: SceneConfiguration): SceneProjection;
|
|
13
|
+
export function validateSnapshot(value: unknown): Snapshot;
|
|
14
|
+
export function rebuild(input: ProjectionRequest, readExact: ReadExact): DataProjection;
|
|
15
|
+
export function recovery(snapshot: Snapshot, receiverRevision: string | null):
|
|
16
|
+
{ kind: 'NoChange'; revision: string } | { kind: 'Snapshot'; revision: string; payload: Uint8Array };
|
|
17
|
+
export function adoptSnapshot(snapshot: Snapshot, expected: { key: string; revision: string }): Readonly<Snapshot>;
|
|
18
|
+
/** Disposable in-memory publication fence; it does not survive process restart. */
|
|
19
|
+
export class ProjectionSlot {
|
|
20
|
+
constructor(key: string);
|
|
21
|
+
begin(): Readonly<PublicationTicket>;
|
|
22
|
+
publish(ticket: PublicationTicket, snapshot: Snapshot): Readonly<PublicationReceipt>;
|
|
23
|
+
read(): Readonly<Snapshot> | null;
|
|
24
|
+
dropCache(): void;
|
|
25
|
+
}
|
|
26
|
+
export function pendingRepair(ticket: PublicationTicket, input: ProjectionRequest, code: PendingRepair['failure']): Readonly<PendingRepair>;
|
|
27
|
+
export function repair(slot: ProjectionSlot, pending: PendingRepair, readExact: ReadExact): Readonly<PublicationReceipt>;
|
package/src/index.mjs
ADDED
package/src/producer.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Hatter 2026: temporal presentation reads only explicit paths in exact visible items.
|
|
2
|
+
import {canonical,copy,digest,fail,frozen,limits,list,refs,request,roles,shape,sourceKey,sourceRef,text,unique} from './contract.mjs'
|
|
3
|
+
import {validateInputDeclaration} from '@zixcel/interaction/input'
|
|
4
|
+
function item(v,source){
|
|
5
|
+
shape(v,['id','semanticRef','group','value','evidence','provenance','resolutionRefs','visibility'])
|
|
6
|
+
text(v.id);if(v.semanticRef!==null)text(v.semanticRef)
|
|
7
|
+
shape(v.group,['kind','ref']);if(!['semantic','structural','presentation'].includes(v.group.kind))fail('InvalidProjection');text(v.group.ref)
|
|
8
|
+
if(v.group.kind==='semantic'&&v.group.ref!==v.semanticRef)fail('InvalidProjection')
|
|
9
|
+
if(!['visible','redacted','omitted'].includes(v.visibility))fail('InvalidProjection')
|
|
10
|
+
refs(v.evidence);refs(v.provenance);refs(v.resolutionRefs)
|
|
11
|
+
if(v.visibility==='omitted')return null
|
|
12
|
+
if(v.visibility==='redacted')return {id:v.id,semanticRef:null,group:{kind:'presentation',ref:'redacted'},value:null,evidence:[],provenance:[],resolutionRefs:[],visibility:'redacted',sourceRefs:[source]}
|
|
13
|
+
return {...copy(v),sourceRefs:[source]}
|
|
14
|
+
}
|
|
15
|
+
function unresolved(v,source){
|
|
16
|
+
shape(v,['id','reason','evidence','contextRefs','actionRefs']);text(v.id);text(v.reason);refs(v.evidence);refs(v.contextRefs);refs(v.actionRefs)
|
|
17
|
+
return {...copy(v),sourceRefs:[source]}
|
|
18
|
+
}
|
|
19
|
+
function seal(kind,key,lineage,data,maximum){
|
|
20
|
+
const body={contract:'projection/0.10.0',kind,key,lineage,data}
|
|
21
|
+
const revision='pp:'+digest(body),snapshot={...body,revision}
|
|
22
|
+
canonical(snapshot,maximum);return frozen(snapshot)
|
|
23
|
+
}
|
|
24
|
+
export function produce(input,exactSources){
|
|
25
|
+
const r=request(input),l=r.limits
|
|
26
|
+
canonical(exactSources);list(exactSources,l.sources)
|
|
27
|
+
if(exactSources.length!==r.sources.length)fail('SourceUnavailable')
|
|
28
|
+
const sources=new Map()
|
|
29
|
+
for(const s of exactSources){
|
|
30
|
+
shape(s,['source','items','relations','unresolved','truncated']);sourceRef(s.source)
|
|
31
|
+
if(typeof s.truncated!=='boolean')fail('InvalidProjection')
|
|
32
|
+
const key=sourceKey(s.source);if(sources.has(key))fail('InvalidSourceRevision');sources.set(key,s)
|
|
33
|
+
}
|
|
34
|
+
const items=[],relations=[],unresolvedItems=[];let truncated=false,omitted=0
|
|
35
|
+
for(const ref of r.sources){
|
|
36
|
+
const s=sources.get(sourceKey(ref));if(!s)fail('InvalidSourceRevision')
|
|
37
|
+
for(const v of list(s.items,l.items)){const next=item(v,ref);if(next)items.push(next);else omitted++}
|
|
38
|
+
for(const v of list(s.unresolved,l.unresolved))unresolvedItems.push(unresolved(v,ref))
|
|
39
|
+
for(const v of list(s.relations,l.relations)){
|
|
40
|
+
shape(v,['id','from','to','relationRef']);Object.values(v).forEach(x=>text(x));relations.push({...copy(v),sourceRefs:[ref]})
|
|
41
|
+
}
|
|
42
|
+
truncated ||= s.truncated
|
|
43
|
+
}
|
|
44
|
+
list(items,l.items);list(relations,l.relations);list(unresolvedItems,l.unresolved)
|
|
45
|
+
unique([...items,...unresolvedItems],v=>v.id);unique(relations,v=>v.id)
|
|
46
|
+
const ids=new Set(items.filter(v=>v.visibility==='visible').map(v=>v.id))
|
|
47
|
+
// Owners must remove relationships to omitted/redacted data in their visibility view.
|
|
48
|
+
for(const v of relations)if(!ids.has(v.from)||!ids.has(v.to))fail('InvalidProjection')
|
|
49
|
+
const count=items.reduce((n,v)=>n+v.provenance.length,0)+unresolvedItems.reduce((n,v)=>n+v.evidence.length,0)
|
|
50
|
+
if(count>l.provenance)fail('ProjectionLimitExceeded')
|
|
51
|
+
for(const values of [items,relations,unresolvedItems])values.sort((a,b)=>a.id<b.id?-1:1)
|
|
52
|
+
return seal('Data',r.key,{sources:r.sources,producer:r.producer,request:r},
|
|
53
|
+
{items,relations,unresolved:unresolvedItems,truncated,omittedByPolicy:omitted},l.snapshotBytes)
|
|
54
|
+
}
|
|
55
|
+
export function validateSnapshot(v){
|
|
56
|
+
canonical(v,524288);shape(v,['contract','kind','key','lineage','data','revision'])
|
|
57
|
+
if(v.contract!=='projection/0.10.0'||!['Data','Scene'].includes(v.kind))fail('InvalidProjection')
|
|
58
|
+
const {revision,...body}=v;if(revision!=='pp:'+digest(body))fail('InvalidProjection')
|
|
59
|
+
// Wire objects originate from the closed producer contract. Re-run structure
|
|
60
|
+
// validation through its exact input contract; content hash alone is not enough.
|
|
61
|
+
shape(v.lineage,['sources','producer','request'],v.kind==='Scene'?['dataProjection','sceneConfiguration']:[])
|
|
62
|
+
const r=request(v.lineage.request),l=r.limits;text(v.key);canonical(v,l.snapshotBytes)
|
|
63
|
+
if(canonical(v.lineage.sources)!==canonical(v.lineage.request.sources)||canonical(v.lineage.producer)!==canonical(v.lineage.request.producer))fail('InvalidProjection')
|
|
64
|
+
const d=v.data
|
|
65
|
+
shape(d,['items','relations','unresolved','truncated','omittedByPolicy'],v.kind==='Scene'?['focus','purpose','regions','actions','temporal','presentation']:[])
|
|
66
|
+
if(typeof d.truncated!=='boolean'||!Number.isSafeInteger(d.omittedByPolicy)||d.omittedByPolicy<0||d.omittedByPolicy>l.sources*l.items)fail('InvalidProjection')
|
|
67
|
+
const known=new Set(r.sources.map(sourceKey))
|
|
68
|
+
const checkSource=x=>{list(x.sourceRefs,1);if(x.sourceRefs.length!==1||!known.has(sourceKey(x.sourceRefs[0])))fail('InvalidSourceRevision')}
|
|
69
|
+
for(const x of list(d.items,l.items)){
|
|
70
|
+
checkSource(x);const {sourceRefs,...body}=x
|
|
71
|
+
if(canonical(item(body,sourceRefs[0]))!==canonical(x))fail('InvalidProjection')
|
|
72
|
+
}
|
|
73
|
+
for(const x of list(d.unresolved,l.unresolved)){
|
|
74
|
+
checkSource(x);const {sourceRefs,...body}=x;unresolved(body,sourceRefs[0])
|
|
75
|
+
}
|
|
76
|
+
unique([...d.items,...d.unresolved],x=>x.id);unique(list(d.relations,l.relations),x=>x.id)
|
|
77
|
+
const ids=new Set(d.items.filter(x=>x.visibility==='visible').map(x=>x.id))
|
|
78
|
+
for(const x of d.relations){shape(x,['id','from','to','relationRef','sourceRefs']);checkSource(x)
|
|
79
|
+
for(const key of ['id','from','to','relationRef'])text(x[key]);if(!ids.has(x.from)||!ids.has(x.to))fail('InvalidProjection')}
|
|
80
|
+
if(d.items.reduce((n,x)=>n+x.provenance.length,0)+d.unresolved.reduce((n,x)=>n+x.evidence.length,0)>l.provenance)fail('ProjectionLimitExceeded')
|
|
81
|
+
if(v.kind==='Data'){if(v.key!==r.key)fail('InvalidProjection')}
|
|
82
|
+
else{
|
|
83
|
+
shape(v.lineage.dataProjection,['key','revision'])
|
|
84
|
+
const base=seal('Data',r.key,{sources:r.sources,producer:r.producer,request:r},
|
|
85
|
+
{items:d.items,relations:d.relations,unresolved:d.unresolved,truncated:d.truncated,omittedByPolicy:d.omittedByPolicy},l.snapshotBytes)
|
|
86
|
+
if(base.key!==v.lineage.dataProjection.key||base.revision!==v.lineage.dataProjection.revision)fail('InvalidProjection')
|
|
87
|
+
const rebuilt=scene(base,v.lineage.sceneConfiguration)
|
|
88
|
+
if(canonical(rebuilt)!==canonical(v))fail('InvalidProjection')
|
|
89
|
+
}
|
|
90
|
+
return v
|
|
91
|
+
}
|
|
92
|
+
export function scene(data,configuration){
|
|
93
|
+
validateSnapshot(data);if(data.kind!=='Data')fail('InvalidProjection')
|
|
94
|
+
canonical(configuration);shape(configuration,['key','focus','purpose','regions','actions'],['temporal','presentation'])
|
|
95
|
+
text(configuration.key);text(configuration.focus);text(configuration.purpose)
|
|
96
|
+
const l=limits(data.lineage.request.limits),ids=new Set([...data.data.items,...data.data.unresolved].map(x=>x.id))
|
|
97
|
+
const regions=unique(list(configuration.regions,l.regions).map(v=>{
|
|
98
|
+
shape(v,['id','role','itemIds']);text(v.id);if(!roles.includes(v.role))fail('InvalidProjection')
|
|
99
|
+
unique(refs(v.itemIds,l.items));if(v.itemIds.some(id=>!ids.has(id)))fail('InvalidProjection');return copy(v)
|
|
100
|
+
}),v=>v.id)
|
|
101
|
+
const actions=unique(list(configuration.actions,l.actions).map(v=>{
|
|
102
|
+
shape(v,['id','targetOwner','commandRef','contextRefs','sourceRefs','label'],['interaction'])
|
|
103
|
+
text(v.id);text(v.targetOwner);text(v.commandRef);text(v.label,1024);refs(v.contextRefs)
|
|
104
|
+
const expected=new Set(data.lineage.sources.map(sourceKey));list(v.sourceRefs,l.sources).forEach(s=>{if(!expected.has(sourceKey(s)))fail('InvalidSourceRevision')})
|
|
105
|
+
if(!v.sourceRefs.length)fail('InvalidSourceRevision')
|
|
106
|
+
if(v.interaction!==undefined){
|
|
107
|
+
const i=v.interaction
|
|
108
|
+
shape(i,['ref','generation','inputContractRef','input'])
|
|
109
|
+
text(i.ref);text(i.generation);text(i.inputContractRef)
|
|
110
|
+
if(validateInputDeclaration(i.input).length)fail('InvalidProjection')
|
|
111
|
+
if(i.input.action.contract_revision!==i.inputContractRef||i.input.action.operation_id!==v.commandRef)fail('InvalidProjection')
|
|
112
|
+
}
|
|
113
|
+
return copy(v)
|
|
114
|
+
}),v=>v.id)
|
|
115
|
+
const lineage={...copy(data.lineage),dataProjection:{key:data.key,revision:data.revision},sceneConfiguration:copy(configuration)}
|
|
116
|
+
const visibleValue=(itemId,valuePath)=>{
|
|
117
|
+
text(itemId);list(valuePath,16).forEach(key=>text(key,256))
|
|
118
|
+
const item=data.data.items.find(item=>item.id===itemId&&item.visibility==='visible')
|
|
119
|
+
if(!item)fail('InvalidProjection')
|
|
120
|
+
let value=item.value
|
|
121
|
+
for(const key of valuePath){if(value===null||typeof value!=='object'||!Object.hasOwn(value,key))fail('InvalidProjection');value=value[key]}
|
|
122
|
+
return value
|
|
123
|
+
}
|
|
124
|
+
let presentation
|
|
125
|
+
if(configuration.presentation!==undefined)presentation=unique(list(configuration.presentation,l.items).map(binding=>{
|
|
126
|
+
shape(binding,['itemId'],['titlePath','title','summaryPath','fields','symbol']);visibleValue(binding.itemId,[])
|
|
127
|
+
if(Object.hasOwn(binding,'title')===Object.hasOwn(binding,'titlePath'))fail('InvalidProjection')
|
|
128
|
+
const title=Object.hasOwn(binding,'titlePath')?visibleValue(binding.itemId,binding.titlePath):binding.title;text(title,1024)
|
|
129
|
+
// Presentation labels never become semantics or permission. Field values are exact visible source paths.
|
|
130
|
+
const fields=binding.fields===undefined?undefined:list(binding.fields,16).map(field=>{
|
|
131
|
+
shape(field,['label','valuePath']);text(field.label,256)
|
|
132
|
+
const value=visibleValue(binding.itemId,field.valuePath)
|
|
133
|
+
if(value!==null&&!['string','boolean','number'].includes(typeof value))fail('InvalidProjection')
|
|
134
|
+
if(typeof value==='string'&&value.length>4096)fail('ProjectionLimitExceeded')
|
|
135
|
+
return {label:field.label,value}
|
|
136
|
+
})
|
|
137
|
+
if(binding.symbol!==undefined)text(binding.symbol,64)
|
|
138
|
+
const summary=binding.summaryPath===undefined?undefined:visibleValue(binding.itemId,binding.summaryPath)
|
|
139
|
+
if(summary!==undefined)text(summary,2048)
|
|
140
|
+
return {itemId:binding.itemId,title,...(summary===undefined?{}:{summary}),...(fields===undefined?{}:{fields}),...(binding.symbol===undefined?{}:{symbol:binding.symbol})}
|
|
141
|
+
}),item=>item.itemId)
|
|
142
|
+
let temporal
|
|
143
|
+
if(configuration.temporal!==undefined){
|
|
144
|
+
const declaration=configuration.temporal;shape(declaration,['label','items']);text(declaration.label,256)
|
|
145
|
+
const items=unique(list(declaration.items,l.items).map(binding=>{
|
|
146
|
+
shape(binding,['itemId','valuePath','format']);text(binding.itemId);list(binding.valuePath,16).forEach(key=>text(key,256))
|
|
147
|
+
if(!['utcInstant','unixMilliseconds'].includes(binding.format))fail('InvalidProjection')
|
|
148
|
+
let at=visibleValue(binding.itemId,binding.valuePath)
|
|
149
|
+
if(binding.format==='unixMilliseconds'){
|
|
150
|
+
if(!Number.isSafeInteger(at)||at<0||at>253402300799999)fail('InvalidProjection')
|
|
151
|
+
at=new Date(at).toISOString()
|
|
152
|
+
}
|
|
153
|
+
// Declared encodings only: no field-name heuristic, coercion or inferred date.
|
|
154
|
+
if(typeof at!=='string'||!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(at)||!Number.isFinite(Date.parse(at))||new Date(at).toISOString()!==at)fail('InvalidProjection')
|
|
155
|
+
return {itemId:binding.itemId,at}
|
|
156
|
+
}),item=>item.itemId).sort((a,b)=>a.at===b.at?(a.itemId<b.itemId?-1:1):(a.at<b.at?-1:1))
|
|
157
|
+
temporal={label:declaration.label,items}
|
|
158
|
+
}
|
|
159
|
+
return seal('Scene',configuration.key,lineage,{...copy(data.data),focus:configuration.focus,purpose:configuration.purpose,regions,actions,...(temporal?{temporal}:{}),...(presentation?{presentation}:{})},l.snapshotBytes)
|
|
160
|
+
}
|
|
161
|
+
export function rebuild(input,readExact){
|
|
162
|
+
const r=request(input)
|
|
163
|
+
const sources=r.sources.map(ref=>{
|
|
164
|
+
let value;try{value=readExact(ref)}catch{fail('ProjectionRebuildUnavailable')}
|
|
165
|
+
if(value?.then){Promise.resolve(value).catch(()=>{});fail('ProjectionRebuildUnavailable')}
|
|
166
|
+
if(value==null)fail('ProjectionRebuildUnavailable');return value
|
|
167
|
+
})
|
|
168
|
+
return produce(r,sources)
|
|
169
|
+
}
|
|
170
|
+
export function recovery(snapshot,receiverRevision){
|
|
171
|
+
validateSnapshot(snapshot)
|
|
172
|
+
if(receiverRevision!==null)text(receiverRevision)
|
|
173
|
+
if(receiverRevision===snapshot.revision)return {kind:'NoChange',revision:snapshot.revision}
|
|
174
|
+
return {kind:'Snapshot',revision:snapshot.revision,payload:Buffer.from(canonical(snapshot,524288))}
|
|
175
|
+
}
|
|
176
|
+
export function adoptSnapshot(snapshot,expected){
|
|
177
|
+
shape(expected,['key','revision']);text(expected.key);text(expected.revision);validateSnapshot(snapshot)
|
|
178
|
+
if(snapshot.key!==expected.key||snapshot.revision!==expected.revision)fail('InvalidSourceRevision')
|
|
179
|
+
return frozen(copy(snapshot))
|
|
180
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto'
|
|
2
|
+
import {copy,fail,frozen,request,shape,text} from './contract.mjs'
|
|
3
|
+
import {rebuild,validateSnapshot} from './producer.mjs'
|
|
4
|
+
// Executable in-memory publication contract, not a durable scheduler or Graph CAS.
|
|
5
|
+
// Head fencing survives disposable cache loss within this slot. Restart requires
|
|
6
|
+
// a fresh exact owner rebuild; no durable publication guarantee is claimed here.
|
|
7
|
+
export class ProjectionSlot {
|
|
8
|
+
#key;#fence=randomUUID();#snapshot=null;#receipt=null
|
|
9
|
+
constructor(key){this.#key=text(key)}
|
|
10
|
+
begin(){return frozen({key:this.#key,expected:this.#fence})}
|
|
11
|
+
publish(ticket,snapshot){
|
|
12
|
+
shape(ticket,['key','expected']);validateSnapshot(snapshot)
|
|
13
|
+
if(ticket.key!==this.#key||snapshot.key!==this.#key)fail('InvalidProjection')
|
|
14
|
+
if(this.#receipt?.expected===ticket.expected&&this.#receipt.revision===snapshot.revision){
|
|
15
|
+
if(!this.#snapshot)this.#snapshot=frozen(copy(snapshot))
|
|
16
|
+
return this.#receipt
|
|
17
|
+
}
|
|
18
|
+
if(ticket.expected!==this.#fence)fail('StaleProjectionPublication')
|
|
19
|
+
this.#snapshot=frozen(copy(snapshot));this.#fence=randomUUID()
|
|
20
|
+
this.#receipt=frozen({key:this.#key,expected:ticket.expected,publication:this.#fence,revision:snapshot.revision})
|
|
21
|
+
return this.#receipt
|
|
22
|
+
}
|
|
23
|
+
read(){if(!this.#snapshot)return null;try{return frozen(copy(validateSnapshot(this.#snapshot)))}catch{fail('ProjectionUnavailable')}}
|
|
24
|
+
dropCache(){this.#snapshot=null}
|
|
25
|
+
}
|
|
26
|
+
export function pendingRepair(ticket,input,code){
|
|
27
|
+
shape(ticket,['key','expected']);text(ticket.key);text(ticket.expected)
|
|
28
|
+
if(!['ProjectionUnavailable','ProjectionLimitExceeded'].includes(code))fail('InvalidProjection')
|
|
29
|
+
const r=request(input);if(r.key!==ticket.key)fail('InvalidProjection')
|
|
30
|
+
return frozen({ticket:copy(ticket),request:r,failure:code})
|
|
31
|
+
}
|
|
32
|
+
export function repair(slot,pending,readExact){
|
|
33
|
+
shape(pending,['ticket','request','failure'])
|
|
34
|
+
const p=pendingRepair(pending.ticket,pending.request,pending.failure)
|
|
35
|
+
return slot.publish(p.ticket,rebuild(p.request,readExact))
|
|
36
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Item, SourceRef, Unresolved, Relation, Region, Action } from './snapshot.mjs';
|
|
2
|
+
/** Exact producer identity: no request-provided code or implicit latest revision. */
|
|
3
|
+
export interface ProducerIdentity { readonly id: string; readonly version: string; readonly contract: string; readonly configuration: string }
|
|
4
|
+
export interface ProjectionLimits { sources: number; items: number; relations: number; provenance: number; unresolved: number; regions: number; actions: number; snapshotBytes: number }
|
|
5
|
+
export interface ProjectionRequest {
|
|
6
|
+
readonly key: string; readonly producer: ProducerIdentity; readonly sources: readonly SourceRef[];
|
|
7
|
+
readonly focus: string; readonly purpose: string; readonly visibilityRef: string; readonly limits: Partial<ProjectionLimits>;
|
|
8
|
+
}
|
|
9
|
+
export interface ExactSource {
|
|
10
|
+
readonly source: SourceRef; readonly items: readonly (Omit<Item, 'sourceRefs' | 'visibility'> & { readonly visibility: 'visible' | 'redacted' | 'omitted' })[];
|
|
11
|
+
readonly unresolved: readonly Omit<Unresolved, 'sourceRefs'>[];
|
|
12
|
+
readonly relations: readonly Omit<Relation, 'sourceRefs'>[]; readonly truncated: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface SceneConfiguration {
|
|
15
|
+
readonly key: string; readonly focus: string; readonly purpose: string;
|
|
16
|
+
readonly regions: readonly Region[]; readonly actions: readonly Action[];
|
|
17
|
+
readonly temporal?: { readonly label: string; readonly items: readonly { readonly itemId: string; readonly valuePath: readonly string[]; readonly format: 'utcInstant' | 'unixMilliseconds' }[] };
|
|
18
|
+
readonly presentation?: readonly {
|
|
19
|
+
readonly itemId: string; readonly title?: string; readonly titlePath?: readonly string[];
|
|
20
|
+
readonly summaryPath?: readonly string[]; readonly symbol?: string;
|
|
21
|
+
readonly fields?: readonly { readonly label: string; readonly valuePath: readonly string[] }[];
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
export type ReadExact = (source: SourceRef) => ExactSource | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { InputDeclaration } from '@zixcel/interaction/input';
|
|
2
|
+
import type { ProducerIdentity, ProjectionRequest, SceneConfiguration } from './input.mjs';
|
|
3
|
+
export type Json = null | boolean | number | string | readonly Json[] | { readonly [key: string]: Json };
|
|
4
|
+
export interface SourceRef { readonly owner: string; readonly ref: string; readonly revision: string; readonly kind: string }
|
|
5
|
+
export interface Item {
|
|
6
|
+
readonly id: string; readonly semanticRef: string | null;
|
|
7
|
+
readonly group: { readonly kind: 'semantic' | 'structural' | 'presentation'; readonly ref: string };
|
|
8
|
+
readonly value: Json; readonly evidence: readonly string[]; readonly provenance: readonly string[];
|
|
9
|
+
readonly resolutionRefs: readonly string[]; readonly visibility: 'visible' | 'redacted'; readonly sourceRefs: readonly SourceRef[];
|
|
10
|
+
}
|
|
11
|
+
export interface Unresolved {
|
|
12
|
+
readonly id: string; readonly reason: string; readonly evidence: readonly string[];
|
|
13
|
+
readonly contextRefs: readonly string[]; readonly actionRefs: readonly string[]; readonly sourceRefs: readonly SourceRef[];
|
|
14
|
+
}
|
|
15
|
+
export type RegionRole = 'Primary' | 'Context' | 'Interpretation' | 'Evidence' | 'Provenance' | 'Resolution' | 'Inspector' | 'Actions' | 'Activity';
|
|
16
|
+
export interface Region { readonly id: string; readonly role: RegionRole; readonly itemIds: readonly string[] }
|
|
17
|
+
export interface ProjectedInteraction {
|
|
18
|
+
readonly ref: string; readonly generation: string; readonly inputContractRef: string; readonly input: InputDeclaration;
|
|
19
|
+
}
|
|
20
|
+
export interface Action {
|
|
21
|
+
readonly id: string; readonly targetOwner: string; readonly commandRef: string; readonly label: string;
|
|
22
|
+
readonly contextRefs: readonly string[]; readonly sourceRefs: readonly SourceRef[]; readonly interaction?: ProjectedInteraction;
|
|
23
|
+
}
|
|
24
|
+
export interface Relation { readonly id: string; readonly from: string; readonly to: string; readonly relationRef: string; readonly sourceRefs: readonly SourceRef[] }
|
|
25
|
+
export interface SourceLineage { readonly sources: readonly SourceRef[]; readonly producer: ProducerIdentity; readonly request: ProjectionRequest }
|
|
26
|
+
export interface ProjectionIdentity { readonly key: string; readonly revision: string; readonly lineage: SourceLineage }
|
|
27
|
+
export interface ProjectionData {
|
|
28
|
+
readonly items: readonly Item[]; readonly unresolved: readonly Unresolved[]; readonly relations: readonly Relation[];
|
|
29
|
+
readonly truncated: boolean; readonly omittedByPolicy: number;
|
|
30
|
+
}
|
|
31
|
+
export interface DataProjection extends ProjectionIdentity { readonly contract: 'projection/0.10.0'; readonly kind: 'Data'; readonly data: ProjectionData }
|
|
32
|
+
export interface SceneProjection extends ProjectionIdentity {
|
|
33
|
+
readonly contract: 'projection/0.10.0'; readonly kind: 'Scene';
|
|
34
|
+
readonly lineage: SourceLineage & { readonly dataProjection: { readonly key: string; readonly revision: string }; readonly sceneConfiguration: SceneConfiguration };
|
|
35
|
+
readonly data: ProjectionData & {
|
|
36
|
+
readonly regions: readonly Region[]; readonly actions: readonly Action[]; readonly focus: string; readonly purpose: string;
|
|
37
|
+
readonly temporal?: { readonly label: string; readonly items: readonly { readonly itemId: string; readonly at: string }[] };
|
|
38
|
+
readonly presentation?: readonly {
|
|
39
|
+
readonly itemId: string; readonly title: string; readonly summary?: string; readonly symbol?: string;
|
|
40
|
+
readonly fields?: readonly { readonly label: string; readonly value: string | number | boolean | null }[];
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
}
|