@zixcel/projection-runtime 0.0.0-stage → 0.10.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/LICENSE +202 -0
- package/LICENSE-PREVIOUS +21 -0
- package/NOTICE +5 -0
- package/README.md +71 -2
- package/package.json +46 -4
- package/src/common.mjs +15 -0
- package/src/exact-sources.mjs +84 -0
- package/src/private-files.mjs +21 -0
- package/src/producer-worker.mjs +14 -0
- package/src/runtime.d.mts +28 -0
- package/src/runtime.mjs +168 -0
- package/src/store-process.mjs +104 -0
- package/src/store.d.mts +17 -0
- package/src/store.mjs +82 -0
- package/src/types/runtime.d.mts +37 -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,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zixcel/projection-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Execute explicitly registered projection producers in bounded Node.js workers and
|
|
4
|
+
publish disposable read-only snapshots with durable fencing and exact owner leases.
|
|
5
|
+
The runtime never chooses a latest source, loads request-supplied code or owns
|
|
6
|
+
application authorization. Owner adapters decide visibility and retention.
|
|
7
|
+
|
|
8
|
+
## Install and use
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @zixcel/projection-runtime@0.10.0
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { ProducerRegistry, ProjectionRuntime, ExactSourceReader } from '@zixcel/projection-runtime'
|
|
16
|
+
import { FileProjectionStore } from '@zixcel/projection-runtime/store'
|
|
17
|
+
|
|
18
|
+
const registry = new ProducerRegistry()
|
|
19
|
+
const producer = registry.register({ id: 'review', kind: 'data' })
|
|
20
|
+
// Provision this existing parent as mode 0700 before creating the store once.
|
|
21
|
+
const store = FileProjectionStore.create('/private/application/projections')
|
|
22
|
+
// adapters is a Map of owner IDs to bounded acquire/read/release/releaseHolder APIs.
|
|
23
|
+
const reader = new ExactSourceReader(adapters)
|
|
24
|
+
const runtime = new ProjectionRuntime({ store, registry, reader })
|
|
25
|
+
try {
|
|
26
|
+
const { snapshot } = await runtime.submit({
|
|
27
|
+
key: 'review', producer, sources: exactOwnerReferences,
|
|
28
|
+
focus: 'selected-resources', purpose: 'review', visibilityRef: acceptedVisibility,
|
|
29
|
+
limits: {}
|
|
30
|
+
}, { accessRef: acceptedOwnerAccess })
|
|
31
|
+
console.log(snapshot.revision)
|
|
32
|
+
} finally {
|
|
33
|
+
await runtime.close()
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The application supplies `adapters`, `exactOwnerReferences`, `acceptedVisibility`
|
|
38
|
+
and `acceptedOwnerAccess`; these are explicit authorization bindings, not defaults.
|
|
39
|
+
A producer must be registered before requests can reference its returned identity.
|
|
40
|
+
|
|
41
|
+
## Boundaries and operating environment
|
|
42
|
+
|
|
43
|
+
The file store requires Linux/WSL, Node.js 22 or newer, `/usr/bin/flock` and
|
|
44
|
+
`/usr/bin/setpriv`. It rejects non-private directories, foreign ownership, symbolic
|
|
45
|
+
links and hard-linked state files. It runs local transaction helpers and built-in
|
|
46
|
+
producer workers; it does not execute arbitrary owner commands. It does not provide
|
|
47
|
+
an OS sandbox against another process running as the same user.
|
|
48
|
+
|
|
49
|
+
Store hints are wakeups, not revision authorities. Read/inspect never initializes
|
|
50
|
+
state. Repair leases preserve exact source identity, and cancelled or timed-out
|
|
51
|
+
work must drain before protection is released. Owner IO must honor its deadline
|
|
52
|
+
and AbortSignal, including independently bounded lost-response cleanup.
|
|
53
|
+
|
|
54
|
+
`@zixcel/projection-contracts` owns wire validation and deterministic sealing;
|
|
55
|
+
projection-client owns disposable browser adoption; dom-renderer owns presentation.
|
|
56
|
+
This package owns execution/publication and no product-specific meaning.
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
pnpm install --frozen-lockfile --ignore-scripts
|
|
62
|
+
pnpm -r --include-workspace-root typecheck
|
|
63
|
+
pnpm -r --include-workspace-root test
|
|
64
|
+
pnpm audit --audit-level=low
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Production manifests use registry versions. Numeric workspace linking is only a
|
|
68
|
+
local development convenience. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
69
|
+
|
|
70
|
+
## Package ownership and scope migration
|
|
71
|
+
|
|
72
|
+
[保守正本と移行条件](docs/package-ownership.ja.md)。The maintained source and npm scope are owned by Zixcel. New `@zixcel` names require their first registry publication before downstream dependency migration. Existing `@hathq` releases remain historical distributions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zixcel/projection-runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"description": "Bounded read-only producer execution and disposable durable projection publication",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"NOTICE",
|
|
15
|
+
"LICENSE-PREVIOUS"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./src/runtime.d.mts",
|
|
20
|
+
"import": "./src/runtime.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./store": {
|
|
23
|
+
"types": "./src/store.d.mts",
|
|
24
|
+
"import": "./src/store.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@zixcel/projection-contracts": "0.10.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test test/*.test.mjs",
|
|
32
|
+
"typecheck": "tsc --noEmit --strict --module NodeNext --moduleResolution NodeNext --target ES2022 test/public-types.mts"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/zixcel/projection-runtime.git"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"registry": "https://registry.npmjs.org",
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"types": "./src/runtime.d.mts",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "5.9.3",
|
|
45
|
+
"@types/node": "24.12.0"
|
|
46
|
+
},
|
|
47
|
+
"packageManager": "pnpm@10.29.3"
|
|
48
|
+
}
|
package/src/common.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto'
|
|
2
|
+
import {canonical,ProjectionError} from '@zixcel/projection-contracts'
|
|
3
|
+
export const fail=code=>{throw new ProjectionError(code)}
|
|
4
|
+
export const hash=bytes=>createHash('sha256').update(bytes).digest('hex')
|
|
5
|
+
export const clone=value=>JSON.parse(canonical(value))
|
|
6
|
+
export function check(ok,code='InvalidProjection'){if(!ok)fail(code)}
|
|
7
|
+
export function shape(value,keys){check(value&&Object.getPrototypeOf(value)===Object.prototype&&Object.keys(value).length===keys.length&&keys.every(k=>Object.hasOwn(value,k)))}
|
|
8
|
+
export function token(value){check(typeof value==='string'&&value.length>0&&Buffer.byteLength(value)<=512&&!/[\x00-\x1f\x7f]/u.test(value));return value}
|
|
9
|
+
export const ceilings=Object.freeze({concurrent:2,queued:16,inputBytes:2097152,executionMs:5000,keys:8,snapshots:2,repairs:16,attempts:3,repairMs:300000})
|
|
10
|
+
export function bounds(input={}){
|
|
11
|
+
check(input&&Object.getPrototypeOf(input)===Object.prototype)
|
|
12
|
+
const b={...ceilings,...input}
|
|
13
|
+
for(const k of Object.keys(b))check(Object.hasOwn(ceilings,k)&&Number.isSafeInteger(b[k])&&b[k]>=1&&b[k]<=ceilings[k],'ProjectionLimitExceeded')
|
|
14
|
+
return Object.freeze(b)
|
|
15
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {canonical,produce} from '@zixcel/projection-contracts'
|
|
2
|
+
import {check,clone,token} from './common.mjs'
|
|
3
|
+
|
|
4
|
+
// Generic lifecycle orchestration only. Owners decide visibility, exact payload,
|
|
5
|
+
// closure (including []), physical protection and expiry. No Graph/sem-lang API.
|
|
6
|
+
// Adapter IO must honor deadline/signal and drain before resolving/rejecting.
|
|
7
|
+
// releaseHolder must be independently bounded and work after a lost response.
|
|
8
|
+
// A holder identifies one durable, fenced job attempt; owners must never reuse
|
|
9
|
+
// it for unrelated work. Exact release must reject/subsume stale generations.
|
|
10
|
+
export class ExactSourceReader {
|
|
11
|
+
#owners
|
|
12
|
+
constructor(owners){
|
|
13
|
+
check(owners instanceof Map&&owners.size>0&&owners.size<=8,'ProjectionLimitExceeded')
|
|
14
|
+
this.#owners=new Map()
|
|
15
|
+
for(const [id,adapter] of owners){
|
|
16
|
+
token(id)
|
|
17
|
+
check(['acquire','read','release','releaseHolder'].every(k=>typeof adapter?.[k]==='function'))
|
|
18
|
+
this.#owners.set(id,Object.freeze(Object.fromEntries(['acquire','read','release','releaseHolder'].map(k=>[k,adapter[k].bind(adapter)]))))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async acquireExact(refs,options){
|
|
22
|
+
const {holder,accessRef,until,deadline,signal}=options
|
|
23
|
+
token(holder);token(accessRef)
|
|
24
|
+
check(Number.isSafeInteger(until)&&Number.isSafeInteger(deadline)&&deadline<=until&&signal instanceof AbortSignal)
|
|
25
|
+
check(Array.isArray(refs)&&refs.length>0&&refs.length<=8,'ProjectionLimitExceeded')
|
|
26
|
+
// PP0 owns source contract validation and uniqueness; never duplicate it here.
|
|
27
|
+
const request={key:'source-validation',producer:{id:'source-validation',version:'0.10.0',contract:'projection/0.10.0',configuration:'source-validation'},sources:refs,focus:'source',purpose:'read',visibilityRef:accessRef,limits:{}}
|
|
28
|
+
const ordered=produce(request,refs.map(source=>({source,items:[],relations:[],unresolved:[],truncated:false}))).lineage.sources
|
|
29
|
+
.toSorted((a,b)=>{const x=canonical([a.owner,a.ref,a.revision,a.kind]),y=canonical([b.owner,b.ref,b.revision,b.kind]);return x<y?-1:x>y?1:0})
|
|
30
|
+
ordered.forEach(r=>check(this.#owners.has(r.owner),'SourceUnavailable'))
|
|
31
|
+
const running=()=>{
|
|
32
|
+
check(!signal.aborted,signal.reason?.code==='ProjectionExecutionTimeout'?'ProjectionExecutionTimeout':'ProjectionCancelled')
|
|
33
|
+
check(Date.now()<deadline,'ProjectionExecutionTimeout')
|
|
34
|
+
}
|
|
35
|
+
const acquired=[]
|
|
36
|
+
try{
|
|
37
|
+
for(const source of ordered){
|
|
38
|
+
running()
|
|
39
|
+
const lease=token(await this.#owners.get(source.owner).acquire(clone(source),options))
|
|
40
|
+
acquired.push({source,lease});running()
|
|
41
|
+
}
|
|
42
|
+
const sources=[]
|
|
43
|
+
for(const {source,lease} of acquired){
|
|
44
|
+
running()
|
|
45
|
+
const value=await this.#owners.get(source.owner).read(clone(source),lease,options)
|
|
46
|
+
running();check(canonical(value?.source)===canonical(source),'SourceRevisionMismatch')
|
|
47
|
+
sources.push(value)
|
|
48
|
+
}
|
|
49
|
+
// The isolated producer validates payload contracts; do not build a second
|
|
50
|
+
// projection here just to discard it. Bound bytes before handing them off.
|
|
51
|
+
canonical(sources)
|
|
52
|
+
return {sources,leaseRefs:acquired.map(({source,lease})=>token(canonical([source.owner,lease])))}
|
|
53
|
+
}catch(error){
|
|
54
|
+
// Include the owner whose acquire response was lost. Do not release only
|
|
55
|
+
// the leases successfully returned to this process.
|
|
56
|
+
await this.release([],holder)
|
|
57
|
+
throw error
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async release(leaseRefs,holder){
|
|
61
|
+
token(holder);check(Array.isArray(leaseRefs)&&leaseRefs.length<=8,'ProjectionLimitExceeded')
|
|
62
|
+
// Known generations are released exactly; holder cleanup is only the recovery
|
|
63
|
+
// path when acquisition responses were not durably recorded. No ABA release.
|
|
64
|
+
let failure
|
|
65
|
+
if(leaseRefs.length){
|
|
66
|
+
const selected=leaseRefs.map(ref=>{
|
|
67
|
+
token(ref);let value
|
|
68
|
+
try{value=JSON.parse(ref)}catch{check(false)}
|
|
69
|
+
check(Array.isArray(value)&&value.length===2);value.forEach(token)
|
|
70
|
+
check(this.#owners.has(value[0]),'SourceUnavailable');return value
|
|
71
|
+
})
|
|
72
|
+
for(const [owner,lease] of selected.reverse()){
|
|
73
|
+
try{await this.#owners.get(owner).release(lease,holder)}catch(error){failure??=error}
|
|
74
|
+
}
|
|
75
|
+
if(failure)throw failure
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
// Try every owner even if one fails. PP retains its repair intent on failure.
|
|
79
|
+
for(const [,owner] of [...this.#owners].sort(([a],[b])=>a<b?-1:a>b?1:0)){
|
|
80
|
+
try{await owner.releaseHolder(holder)}catch(error){failure??=error}
|
|
81
|
+
}
|
|
82
|
+
if(failure)throw failure
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import {check} from './common.mjs'
|
|
3
|
+
|
|
4
|
+
/** Refuse shared state, symlinks and hard links before reading or truncating. */
|
|
5
|
+
export function privateDirectory(directory) {
|
|
6
|
+
const stat = fs.lstatSync(directory)
|
|
7
|
+
check(stat.isDirectory() && stat.uid === process.getuid()
|
|
8
|
+
&& (stat.mode & 0o077) === 0, 'ProjectionStoreCorrupt')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function privateFile(stat) {
|
|
12
|
+
check(stat.isFile() && stat.nlink === 1 && stat.uid === process.getuid()
|
|
13
|
+
&& (stat.mode & 0o077) === 0, 'ProjectionStoreCorrupt')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Remove only an owner-private stale file; exclusive creation prevents clobbering. */
|
|
17
|
+
export function removeStaleTemporary(filename) {
|
|
18
|
+
try { privateFile(fs.lstatSync(filename)) }
|
|
19
|
+
catch (error) { if (error.code === 'ENOENT') return; throw error }
|
|
20
|
+
fs.unlinkSync(filename)
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {parentPort,workerData} from 'node:worker_threads'
|
|
2
|
+
import {produce,scene} from '@zixcel/projection-contracts'
|
|
3
|
+
try{
|
|
4
|
+
// A visible value alone exceeding the entire output ceiling is a resource
|
|
5
|
+
// failure, before PP0's strict per-value serializer can classify its shape.
|
|
6
|
+
const ceiling=workerData.request.limits.snapshotBytes??524288
|
|
7
|
+
for(const source of workerData.sources)for(const item of source.items){
|
|
8
|
+
if(item.visibility==='visible'&&Buffer.byteLength(JSON.stringify(item.value))>ceiling)throw Object.assign(new Error('ProjectionLimitExceeded'),{code:'ProjectionLimitExceeded'})
|
|
9
|
+
}
|
|
10
|
+
const data=produce(workerData.request,workerData.sources)
|
|
11
|
+
const snapshot=workerData.entry.kind==='scene'?scene(data,workerData.entry.configuration):data
|
|
12
|
+
parentPort.postMessage({snapshot})
|
|
13
|
+
}catch(e){parentPort.postMessage({error:e.code??'ProjectionProducerFailed'})}
|
|
14
|
+
parentPort.close()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ProducerIdentity, ProjectionRequest, Snapshot } from '@zixcel/projection-contracts';
|
|
2
|
+
import type { RuntimeLimits, ProjectionStore, SourceAdapter, SourceReadOptions, SourceReader, ProducerConfiguration, SubmissionOptions, StoreReceipt, StoreInspection } from './types/runtime.mjs';
|
|
3
|
+
export type * from './types/runtime.mjs';
|
|
4
|
+
/** Register installed built-in producers; requests cannot supply executable code. */
|
|
5
|
+
export class ProducerRegistry {
|
|
6
|
+
register(definition: { id: string; kind: 'data' | 'scene'; configuration?: ProducerConfiguration }): ProducerIdentity;
|
|
7
|
+
exact(identity: ProducerIdentity): Readonly<{ identity: ProducerIdentity; kind: 'data' | 'scene'; configuration: ProducerConfiguration }>;
|
|
8
|
+
unregister(identity: ProducerIdentity): void;
|
|
9
|
+
readonly artifactDigest: string;
|
|
10
|
+
}
|
|
11
|
+
export class ExactSourceReader implements SourceReader {
|
|
12
|
+
constructor(owners: Map<string, SourceAdapter>);
|
|
13
|
+
acquireExact(refs: readonly import('@zixcel/projection-contracts').SourceRef[], options: SourceReadOptions): ReturnType<SourceReader['acquireExact']>;
|
|
14
|
+
release(leaseRefs: readonly string[], holder: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** Bounded isolated execution with explicit source ownership and publication fencing. */
|
|
17
|
+
export class ProjectionRuntime {
|
|
18
|
+
constructor(options: { store: ProjectionStore; registry: ProducerRegistry; reader: SourceReader; limits?: Partial<RuntimeLimits> });
|
|
19
|
+
inspect(): { active: number; queued: number; closed: boolean; limits: Readonly<RuntimeLimits>; store: StoreInspection };
|
|
20
|
+
submit(request: ProjectionRequest, options: SubmissionOptions): Promise<{ snapshot: Snapshot; receipt: StoreReceipt }>;
|
|
21
|
+
retry(id: string, options?: Omit<SubmissionOptions, 'accessRef' | 'id'>): ReturnType<ProjectionRuntime['submit']>;
|
|
22
|
+
expire(id: string): Promise<void>;
|
|
23
|
+
recoverState(input: { key: string; revision?: string | null }):
|
|
24
|
+
{ kind: 'RecoveryUnavailable'; reason: string } |
|
|
25
|
+
{ kind: 'NoChange'; revision: string } |
|
|
26
|
+
{ kind: 'Snapshot'; revision: string; payload: Uint8Array };
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
package/src/runtime.mjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import {Worker} from 'node:worker_threads'
|
|
3
|
+
import {randomUUID} from 'node:crypto'
|
|
4
|
+
import {canonical,produce,recovery,validateSnapshot} from '@zixcel/projection-contracts'
|
|
5
|
+
import {bounds,check,clone,fail,hash,shape,token} from './common.mjs'
|
|
6
|
+
export {ExactSourceReader} from './exact-sources.mjs'
|
|
7
|
+
|
|
8
|
+
const workerUrl=new URL('./producer-worker.mjs',import.meta.url)
|
|
9
|
+
const implementation=hash(Buffer.concat([
|
|
10
|
+
fs.readFileSync(workerUrl),fs.readFileSync(import.meta.filename),
|
|
11
|
+
fs.readFileSync(new URL('./common.mjs',import.meta.url)),
|
|
12
|
+
...['index.mjs','contract.mjs','producer.mjs','publication.mjs','hash-node.mjs','../package.json'].map(name=>fs.readFileSync(new URL(name,import.meta.resolve('@zixcel/projection-contracts')))),
|
|
13
|
+
]))
|
|
14
|
+
// Explicit installed built-ins only. No request-supplied path/module/code is loaded.
|
|
15
|
+
export class ProducerRegistry {
|
|
16
|
+
#entries=new Map()
|
|
17
|
+
register({id,kind,configuration={}}){
|
|
18
|
+
token(id);check(['data','scene'].includes(kind));check(this.#entries.size<8,'ProjectionLimitExceeded');check(!this.#entries.has(id),'ProjectionIdentityConflict')
|
|
19
|
+
canonical(configuration,16384)
|
|
20
|
+
const identity={id,version:'0.10.0',contract:'projection/0.10.0',configuration:hash(canonical({implementation,kind,configuration}))}
|
|
21
|
+
const entry=Object.freeze({identity:Object.freeze(identity),kind,configuration:clone(configuration)})
|
|
22
|
+
this.#entries.set(id,entry);return clone(identity)
|
|
23
|
+
}
|
|
24
|
+
exact(identity){const entry=this.#entries.get(identity?.id);check(entry&&canonical(entry.identity)===canonical(identity),'ProjectionProducerUnavailable');return clone(entry)}
|
|
25
|
+
// Unregister only the exact installed definition. Submitted jobs already own
|
|
26
|
+
// an immutable copy; stale cleanup cannot remove a different configuration.
|
|
27
|
+
unregister(identity){this.exact(identity);this.#entries.delete(identity.id)}
|
|
28
|
+
get artifactDigest(){return implementation}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validatedRequest(r){
|
|
32
|
+
// Reuse PP0 validation, without exposing an implicit reader or duplicating schema.
|
|
33
|
+
return produce(r,r.sources.map(source=>({source,items:[],relations:[],unresolved:[],truncated:false}))).lineage.request
|
|
34
|
+
}
|
|
35
|
+
function execute(entry,request,sources,signal,ms){
|
|
36
|
+
return new Promise((resolve,reject)=>{
|
|
37
|
+
let settled=false
|
|
38
|
+
const worker=new Worker(workerUrl,{workerData:{entry,request,sources},resourceLimits:{maxOldGenerationSizeMb:32,maxYoungGenerationSizeMb:8,stackSizeMb:2}})
|
|
39
|
+
const finish=async(error,value)=>{
|
|
40
|
+
if(settled)return;settled=true;clearTimeout(timer);signal.removeEventListener('abort',aborted)
|
|
41
|
+
// Await termination before releasing slot/source holds, including timeout.
|
|
42
|
+
try{await worker.terminate()}catch(e){error??=e}
|
|
43
|
+
if(error)reject(error);else resolve(value)
|
|
44
|
+
}
|
|
45
|
+
const error=code=>Object.assign(new Error(code),{code})
|
|
46
|
+
const aborted=()=>void finish(error(signal.reason?.code==='ProjectionExecutionTimeout'?'ProjectionExecutionTimeout':'ProjectionCancelled'))
|
|
47
|
+
const timer=setTimeout(()=>void finish(error('ProjectionExecutionTimeout')),ms)
|
|
48
|
+
worker.once('error',e=>void finish(error(e.code==='ERR_WORKER_OUT_OF_MEMORY'?'ProjectionLimitExceeded':'ProjectionProducerFailed')))
|
|
49
|
+
worker.once('message',m=>void finish(m.error?error(m.error):null,m.snapshot))
|
|
50
|
+
worker.once('exit',code=>{if(!settled)void finish(error('ProjectionProducerFailed'))})
|
|
51
|
+
signal.addEventListener('abort',aborted,{once:true});if(signal.aborted)aborted()
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Reader contract: acquireExact(refs, {accessRef, holder, until, signal}) returns
|
|
56
|
+
// {sources, leaseRefs}; release(leaseRefs) is idempotent; holds survive process exit
|
|
57
|
+
// until explicit release/owner expiry. Reader must bound/cancel its own IO and never
|
|
58
|
+
// invoke canonical creation, latest, provider refresh or source-body restoration.
|
|
59
|
+
export class ProjectionRuntime {
|
|
60
|
+
#store;#registry;#reader;#limits;#active=new Map();#queue=[];#closed=false
|
|
61
|
+
constructor({store,registry,reader,limits={}}){
|
|
62
|
+
check(store&®istry instanceof ProducerRegistry&&typeof reader?.acquireExact==='function'&&typeof reader.release==='function')
|
|
63
|
+
this.#store=store;this.#registry=registry;this.#reader=reader;this.#limits=bounds(limits)
|
|
64
|
+
}
|
|
65
|
+
inspect(){return {active:this.#active.size,queued:this.#queue.length,closed:this.#closed,limits:this.#limits,store:this.#store.inspect()}}
|
|
66
|
+
submit(input,{accessRef,signal=new AbortController().signal,id=randomUUID()}={}){
|
|
67
|
+
check(!this.#closed,'ProjectionRuntimeClosed');token(accessRef);token(id)
|
|
68
|
+
const request=clone(input);validatedRequest(request);const entry=this.#registry.exact(request.producer)
|
|
69
|
+
check(entry.kind==='data'||entry.configuration.key===request.key)
|
|
70
|
+
if(this.#active.size>=this.#limits.concurrent&&this.#queue.length>=this.#limits.queued)fail('ProjectionQueueFull')
|
|
71
|
+
check(!this.#active.has(id)&&!this.#queue.some(j=>j.id===id),'ProjectionIdentityConflict')
|
|
72
|
+
const pending=this.#store.repair(id)
|
|
73
|
+
if(pending){check(canonical(pending.request)===canonical(request)&&pending.accessRef===accessRef,'ProjectionIdentityConflict')}
|
|
74
|
+
const job={id,request,entry,accessRef,controller:new AbortController(),pending,signal}
|
|
75
|
+
return new Promise((resolve,reject)=>{
|
|
76
|
+
job.resolve=resolve;job.reject=reject
|
|
77
|
+
job.abort=()=>{job.controller.abort();const index=this.#queue.indexOf(job);if(index>=0){this.#queue.splice(index,1);job.signal.removeEventListener('abort',job.abort);reject(Object.assign(new Error('ProjectionCancelled'),{code:'ProjectionCancelled'}))}}
|
|
78
|
+
signal.addEventListener('abort',job.abort,{once:true})
|
|
79
|
+
if(signal.aborted){signal.removeEventListener('abort',job.abort);reject(Object.assign(new Error('ProjectionCancelled'),{code:'ProjectionCancelled'}));return}
|
|
80
|
+
this.#queue.push(job);this.#pump()
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
retry(id,options={}){
|
|
84
|
+
const r=this.#store.repair(token(id));check(r,'ProjectionRepairUnavailable')
|
|
85
|
+
return this.submit(r.request,{...options,accessRef:r.accessRef,id})
|
|
86
|
+
}
|
|
87
|
+
async expire(id){
|
|
88
|
+
check(!this.#active.has(id)&&!this.#queue.some(j=>j.id===id),'ProjectionStoreBusy')
|
|
89
|
+
const r=this.#store.repair(token(id));if(!r)return
|
|
90
|
+
await this.#store.withAttempt(id,async()=>{
|
|
91
|
+
const current=this.#store.repair(id);if(!current)return
|
|
92
|
+
await this.#cleanup([{holder:current.holder,leases:current.leases},...current.previous]);this.#store.finish(id)
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
#pump(){
|
|
96
|
+
while(!this.#closed&&this.#active.size<this.#limits.concurrent&&this.#queue.length){
|
|
97
|
+
const j=this.#queue.shift();this.#active.set(j.id,j)
|
|
98
|
+
const finished=()=>{
|
|
99
|
+
this.#active.delete(j.id);j.signal.removeEventListener('abort',j.abort);this.#pump()
|
|
100
|
+
}
|
|
101
|
+
j.done=this.#store.withAttempt(j.id,()=>this.#run(j)).then(value=>{finished();j.resolve(value)},error=>{finished();j.reject(error)})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async #cleanup(sets){
|
|
105
|
+
let failure
|
|
106
|
+
for(const {holder,leases} of sets){try{await this.#reader.release(leases,holder)}catch(error){failure??=error}}
|
|
107
|
+
if(failure)throw failure
|
|
108
|
+
}
|
|
109
|
+
async #run(j){
|
|
110
|
+
// Re-read after acquiring the process-wide attempt fence, not before queueing.
|
|
111
|
+
const signal=j.controller.signal,now=Date.now(),p=this.#store.repair(j.id),holder=randomUUID()
|
|
112
|
+
if(p)check(canonical(p.request)===canonical(j.request)&&p.accessRef===j.accessRef,'ProjectionIdentityConflict')
|
|
113
|
+
let ticket=p?.ticket
|
|
114
|
+
const expiresAt=p?.expiresAt??now+this.#limits.repairMs,attempts=(p?.attempts??0)+1
|
|
115
|
+
if(expiresAt<=now||attempts>this.#limits.attempts){if(p)await this.#cleanup([{holder:p.holder,leases:p.leases},...p.previous]);this.#store.finish(j.id);fail('ProjectionRepairExpired')}
|
|
116
|
+
// One deadline covers source acquisition/read, producer and publication.
|
|
117
|
+
// Abort is cooperative: await actual owner IO/worker termination, never race
|
|
118
|
+
// away from an acquisition which could still create a durable hold later.
|
|
119
|
+
const deadline=Math.min(now+this.#limits.executionMs,expiresAt)
|
|
120
|
+
const timeout=()=>j.controller.abort(Object.assign(new Error('ProjectionExecutionTimeout'),{code:'ProjectionExecutionTimeout'}))
|
|
121
|
+
const timer=setTimeout(timeout,Math.max(1,deadline-Date.now()))
|
|
122
|
+
const running=()=>{
|
|
123
|
+
if(Date.now()>=deadline&&!signal.aborted)timeout()
|
|
124
|
+
check(!signal.aborted,signal.reason?.code==='ProjectionExecutionTimeout'?'ProjectionExecutionTimeout':'ProjectionCancelled')
|
|
125
|
+
}
|
|
126
|
+
let leases=[],previous=p?[...p.previous,{holder:p.holder,leases:p.leases}]:[],saved=false,published=false,cleaned=false
|
|
127
|
+
try{
|
|
128
|
+
running();ticket??=this.#store.begin(j.request.key,{deadline});running()
|
|
129
|
+
// Exact hold metadata is recorded BEFORE acquisition so interrupted readers
|
|
130
|
+
// can be reconciled by deterministic holder identity, never source bodies.
|
|
131
|
+
const base={id:j.id,holder,previous,ticket,request:j.request,producer:j.entry.identity,accessRef:j.accessRef,expiresAt,attempts,failure:null,leases}
|
|
132
|
+
this.#store.pending(base,{deadline,previousHolder:p?.holder});saved=true;running()
|
|
133
|
+
const result=await this.#reader.acquireExact(j.request.sources,{accessRef:j.accessRef,holder,until:expiresAt,deadline,signal})
|
|
134
|
+
shape(result,['sources','leaseRefs']);check(Array.isArray(result.leaseRefs)&&result.leaseRefs.length<=8,'ProjectionLimitExceeded');result.leaseRefs.forEach(token)
|
|
135
|
+
leases=result.leaseRefs;this.#store.pending({...base,leases},{deadline})
|
|
136
|
+
// Transfer physical protection only AFTER replacement exact leases are
|
|
137
|
+
// durable. A crash preserves both generations for idempotent cleanup.
|
|
138
|
+
await this.#cleanup(previous);previous=[]
|
|
139
|
+
this.#store.pending({...base,leases,previous},{deadline})
|
|
140
|
+
running();canonical(result.sources,this.#limits.inputBytes);running()
|
|
141
|
+
const snapshot=await execute(j.entry,j.request,result.sources,signal,Math.max(1,deadline-Date.now()))
|
|
142
|
+
running();validateSnapshot(snapshot)
|
|
143
|
+
check(canonical(snapshot.lineage.sources)===canonical(produce(j.request,result.sources).lineage.sources),'SourceRevisionMismatch')
|
|
144
|
+
running();const receipt=this.#store.publish(ticket,snapshot,j.id,{deadline});published=true
|
|
145
|
+
running()
|
|
146
|
+
return {snapshot,receipt}
|
|
147
|
+
}catch(error){
|
|
148
|
+
if(signal.aborted&&signal.reason?.code==='ProjectionExecutionTimeout')error=signal.reason
|
|
149
|
+
if(saved){
|
|
150
|
+
const terminal=attempts>=this.#limits.attempts||['ProjectionCancelled','ProjectionExecutionTimeout','StaleProjectionPublication','SourceNotRetained','VisibilityDenied','SourceRevisionMismatch','SourceCorrupt'].includes(error.code)
|
|
151
|
+
if(terminal){await this.#cleanup([{holder,leases},...previous]);cleaned=true;this.#store.finish(j.id);saved=false}
|
|
152
|
+
else this.#store.pending({id:j.id,holder,previous,ticket,request:j.request,producer:j.entry.identity,accessRef:j.accessRef,expiresAt,attempts,failure:error.code??'ProjectionProducerFailed',leases})
|
|
153
|
+
}
|
|
154
|
+
throw error
|
|
155
|
+
}finally{
|
|
156
|
+
clearTimeout(timer)
|
|
157
|
+
if(!cleaned&&(published||!saved))await this.#cleanup([{holder,leases},...previous])
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
recoverState({key,revision=null}){
|
|
161
|
+
try{const snapshot=this.#store.read(token(key));return snapshot?recovery(snapshot,revision):{kind:'RecoveryUnavailable',reason:'ProjectionUnavailable'}}
|
|
162
|
+
catch(error){return {kind:'RecoveryUnavailable',reason:error.code??'ProjectionUnavailable'}}
|
|
163
|
+
}
|
|
164
|
+
async close(){
|
|
165
|
+
this.#closed=true;for(const j of [...this.#queue])j.abort();for(const j of this.#active.values())j.controller.abort()
|
|
166
|
+
await Promise.all([...this.#active.values()].map(j=>j.done))
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// One short-lived process per transaction, protected by inherited kernel lock.
|
|
2
|
+
// One atomic bounded image; no DAG, source data, general journal or commit theory.
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import {randomUUID} from 'node:crypto'
|
|
6
|
+
import {validateSnapshot,canonical,produce} from '@zixcel/projection-contracts'
|
|
7
|
+
import {bounds,check,clone,hash,shape,token} from './common.mjs'
|
|
8
|
+
import {privateDirectory,privateFile,removeStaleTemporary} from './private-files.mjs'
|
|
9
|
+
const directory=process.argv[2],operation=process.argv[3],image=path.join(directory,'projection.json'),temporary=path.join(directory,'projection.next')
|
|
10
|
+
const MAX=12*1024*1024
|
|
11
|
+
function readBounded(file,max){
|
|
12
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW)
|
|
13
|
+
try{privateFile(fs.fstatSync(fd));check(fs.fstatSync(fd).size<=max,'ProjectionStoreCorrupt');const bytes=Buffer.alloc(max+1);const n=fs.readSync(fd,bytes,0,max+1,0);check(n<=max,'ProjectionLimitExceeded');return bytes.subarray(0,n)}finally{fs.closeSync(fd)}
|
|
14
|
+
}
|
|
15
|
+
function load(){
|
|
16
|
+
const envelope=JSON.parse(readBounded(image,MAX));shape(envelope,['digest','state'])
|
|
17
|
+
check(hash(JSON.stringify(envelope.state))===envelope.digest,'ProjectionStoreCorrupt')
|
|
18
|
+
const s=envelope.state;shape(s,['format','instance','limits','keys','repairs']);check(s.format==='projection-runtime/0.10.0','ProjectionStoreCorrupt');token(s.instance);bounds(s.limits)
|
|
19
|
+
check(Array.isArray(s.keys)&&s.keys.length<=s.limits.keys&&Array.isArray(s.repairs)&&s.repairs.length<=s.limits.repairs,'ProjectionStoreCorrupt')
|
|
20
|
+
check(new Set(s.keys.map(k=>k.key)).size===s.keys.length&&new Set(s.repairs.map(r=>r.id)).size===s.repairs.length,'ProjectionStoreCorrupt')
|
|
21
|
+
for(const k of s.keys){shape(k,['key','fence','current','snapshots','receipts']);token(k.key);token(k.fence);check(k.current===null||typeof k.current==='string','ProjectionStoreCorrupt');check(k.snapshots.length<=s.limits.snapshots&&k.receipts.length<=s.limits.snapshots,'ProjectionStoreCorrupt')}
|
|
22
|
+
for(const r of s.repairs)record(r)
|
|
23
|
+
return s
|
|
24
|
+
}
|
|
25
|
+
function save(s){
|
|
26
|
+
const bytes=JSON.stringify({digest:hash(JSON.stringify(s)),state:s});check(Buffer.byteLength(bytes)<=MAX,'ProjectionLimitExceeded')
|
|
27
|
+
// Same lock covers stale temp cleanup, write/fsync/rename and directory fsync.
|
|
28
|
+
removeStaleTemporary(temporary)
|
|
29
|
+
const fd=fs.openSync(temporary,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_NOFOLLOW,0o600)
|
|
30
|
+
try{fs.writeFileSync(fd,bytes);fs.fsyncSync(fd)}finally{fs.closeSync(fd)}
|
|
31
|
+
fs.renameSync(temporary,image);const dir=fs.openSync(directory,'r');try{fs.fsyncSync(dir)}finally{fs.closeSync(dir)}
|
|
32
|
+
}
|
|
33
|
+
function record(r){
|
|
34
|
+
shape(r,['id','holder','previous','ticket','request','producer','accessRef','expiresAt','attempts','failure','leases'])
|
|
35
|
+
canonical(r,65536);token(r.id);token(r.holder);token(r.accessRef);shape(r.ticket,['key','expected']);token(r.ticket.key);token(r.ticket.expected)
|
|
36
|
+
check(r.request.key===r.ticket.key&&Number.isSafeInteger(r.expiresAt)&&r.expiresAt>0&&Number.isSafeInteger(r.attempts)&&r.attempts>=0,'InvalidProjection')
|
|
37
|
+
check(Array.isArray(r.request.sources)&&r.request.sources.length<=8&&Array.isArray(r.leases)&&r.leases.length<=8,'ProjectionLimitExceeded')
|
|
38
|
+
produce(r.request,r.request.sources.map(source=>({source,items:[],relations:[],unresolved:[],truncated:false})))
|
|
39
|
+
check(canonical(r.producer)===canonical(r.request.producer))
|
|
40
|
+
for(const ref of r.request.sources)shape(ref,['owner','ref','revision','kind'])
|
|
41
|
+
for(const ref of r.leases)token(ref)
|
|
42
|
+
check(Array.isArray(r.previous)&&r.previous.length<=2,'ProjectionLimitExceeded')
|
|
43
|
+
for(const old of r.previous){shape(old,['holder','leases']);token(old.holder);check(old.holder!==r.holder&&Array.isArray(old.leases)&&old.leases.length<=8);old.leases.forEach(token)}
|
|
44
|
+
check(new Set(r.previous.map(p=>p.holder)).size===r.previous.length)
|
|
45
|
+
return r
|
|
46
|
+
}
|
|
47
|
+
try{
|
|
48
|
+
// setpriv installed PDEATHSIG before exec. If the caller died before that
|
|
49
|
+
// installation, its exact parent identity must still reject BEFORE any IO.
|
|
50
|
+
check(Number(process.argv[4])===process.ppid&&process.ppid>1,'ProjectionUnavailable')
|
|
51
|
+
privateDirectory(directory)
|
|
52
|
+
// The parent bounds all requests; limit stdin independently for adapter callers.
|
|
53
|
+
const chunks=[];let n=0;for await(const b of process.stdin){n+=b.length;check(n<=MAX,'ProjectionLimitExceeded');chunks.push(b)}
|
|
54
|
+
const input=JSON.parse(Buffer.concat(chunks));let s
|
|
55
|
+
if(operation==='create'){check(!fs.existsSync(image),'ProjectionStoreExists');s={format:'projection-runtime/0.10.0',instance:randomUUID(),limits:bounds(input.limits),keys:[],repairs:[]};save(s)}
|
|
56
|
+
else s=load()
|
|
57
|
+
let value=null,changed=false
|
|
58
|
+
const find=key=>s.keys.find(k=>k.key===key)
|
|
59
|
+
const initial=key=>hash(s.instance+'\0'+token(key))
|
|
60
|
+
switch(operation){
|
|
61
|
+
case 'create':break
|
|
62
|
+
case 'inspect':value={keys:s.keys.map(({key,current,fence,snapshots})=>({key,current,fence,snapshots:snapshots.length})),repairs:clone(s.repairs),limits:s.limits};break
|
|
63
|
+
case 'begin':value={key:input.key,expected:find(input.key)?.fence??initial(input.key)};break
|
|
64
|
+
case 'read':{const k=find(input.key);const rev=input.revision??k?.current;value=k?.snapshots.find(p=>p.revision===rev)??null;if(value)validateSnapshot(value);break}
|
|
65
|
+
case 'publish':{
|
|
66
|
+
const {ticket,snapshot,jobId}=input;shape(ticket,['key','expected']);token(jobId);validateSnapshot(snapshot);check(snapshot.key===ticket.key)
|
|
67
|
+
let k=find(ticket.key);const prior=k?.receipts.find(r=>r.jobId===jobId)
|
|
68
|
+
if(prior){
|
|
69
|
+
check(prior.revision===snapshot.revision,'ProjectionIdentityConflict');value=prior
|
|
70
|
+
if(!k.snapshots.some(p=>p.revision===snapshot.revision)){k.snapshots.push(snapshot);k.snapshots=k.snapshots.slice(-s.limits.snapshots);changed=true}
|
|
71
|
+
if(s.repairs.some(r=>r.id===jobId)){s.repairs=s.repairs.filter(r=>r.id!==jobId);changed=true}
|
|
72
|
+
break
|
|
73
|
+
}
|
|
74
|
+
check((k?.fence??initial(ticket.key))===ticket.expected,'StaleProjectionPublication')
|
|
75
|
+
if(!k){check(s.keys.length<s.limits.keys,'ProjectionLimitExceeded');k={key:ticket.key,fence:ticket.expected,current:null,snapshots:[],receipts:[]};s.keys.push(k)}
|
|
76
|
+
if(!k.snapshots.some(p=>p.revision===snapshot.revision))k.snapshots.push(snapshot)
|
|
77
|
+
k.snapshots=k.snapshots.slice(-s.limits.snapshots);k.fence=randomUUID();k.current=snapshot.revision
|
|
78
|
+
value={key:k.key,expected:ticket.expected,publication:k.fence,revision:k.current,jobId}
|
|
79
|
+
k.receipts.push(value);k.receipts=k.receipts.slice(-s.limits.snapshots)
|
|
80
|
+
// Result and removal of pending repair have one durable boundary.
|
|
81
|
+
s.repairs=s.repairs.filter(r=>r.id!==jobId);changed=true;break
|
|
82
|
+
}
|
|
83
|
+
case 'pending':{
|
|
84
|
+
const r=record(input.record),prior=s.repairs.find(p=>p.id===r.id)
|
|
85
|
+
if(prior){
|
|
86
|
+
check(canonical({...prior,holder:null,previous:[],attempts:0,failure:null,leases:[]})===canonical({...r,holder:null,previous:[],attempts:0,failure:null,leases:[]}),'ProjectionIdentityConflict')
|
|
87
|
+
check(prior.holder===r.holder||input.previousHolder===prior.holder,'ProjectionAttemptConflict')
|
|
88
|
+
check(r.attempts===prior.attempts+(prior.holder===r.holder?0:1),'ProjectionAttemptConflict')
|
|
89
|
+
prior.holder=r.holder;prior.previous=r.previous;prior.attempts=r.attempts;prior.failure=r.failure;prior.leases=r.leases
|
|
90
|
+
}
|
|
91
|
+
else{check(s.repairs.length<s.limits.repairs,'ProjectionLimitExceeded');s.repairs.push(r)}
|
|
92
|
+
changed=true;value=r;break
|
|
93
|
+
}
|
|
94
|
+
case 'repair':value=s.repairs.find(r=>r.id===input.id)??null;break
|
|
95
|
+
case 'finish':s.repairs=s.repairs.filter(r=>r.id!==input.id);changed=true;break
|
|
96
|
+
case 'drop':{const k=find(input.key);if(k){k.snapshots=[];changed=true}break}
|
|
97
|
+
default:check(false)
|
|
98
|
+
}
|
|
99
|
+
if(changed)save(s)
|
|
100
|
+
// No extra durable notification store. This existing file's metadata is only
|
|
101
|
+
// a wakeup hint after the atomic publication, never a cursor or receipt.
|
|
102
|
+
if(changed&&['publish','drop'].includes(operation))fs.utimesSync(path.join(directory,'lock'),new Date(),new Date())
|
|
103
|
+
process.stdout.write(JSON.stringify({value}))
|
|
104
|
+
}catch(error){process.stdout.write(JSON.stringify({error:error.code?.startsWith('Projection')||['InvalidProjection','StaleProjectionPublication'].includes(error.code)?error.code:error.code==='ENOENT'?'ProjectionUnavailable':'ProjectionStoreCorrupt'}))}
|
package/src/store.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Snapshot, PublicationTicket } from '@zixcel/projection-contracts';
|
|
2
|
+
import type { RuntimeLimits, ProjectionStore, StoreOptions, StoreInspection, StoreReceipt, RepairRecord } from './types/runtime.mjs';
|
|
3
|
+
/** Linux/WSL kernel-flock adapter. Call create once inside an existing private parent. */
|
|
4
|
+
export class FileProjectionStore implements ProjectionStore {
|
|
5
|
+
constructor(directory: string);
|
|
6
|
+
static create(directory: string, limits?: Partial<RuntimeLimits>): FileProjectionStore;
|
|
7
|
+
inspect(): StoreInspection;
|
|
8
|
+
watch(onChange: () => void): () => void;
|
|
9
|
+
withAttempt<T>(id: string, operation: () => T | PromiseLike<T>): Promise<T>;
|
|
10
|
+
begin(key: string, options?: StoreOptions): PublicationTicket;
|
|
11
|
+
read(key: string, revision?: string | null): Snapshot | null;
|
|
12
|
+
publish(ticket: PublicationTicket, snapshot: Snapshot, jobId: string, options?: StoreOptions): StoreReceipt;
|
|
13
|
+
pending(record: RepairRecord, options?: StoreOptions): RepairRecord;
|
|
14
|
+
repair(id: string): RepairRecord | null;
|
|
15
|
+
finish(id: string): null;
|
|
16
|
+
dropSnapshots(key: string): null;
|
|
17
|
+
}
|
package/src/store.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Linux projection-local adapter. Kernel flock, not PID/TTL lock stealing.
|
|
2
|
+
// Generic runtime depends only on this adapter's method contract.
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import {fileURLToPath} from 'node:url'
|
|
6
|
+
import {spawnSync} from 'node:child_process'
|
|
7
|
+
import {bounds,check,fail,token} from './common.mjs'
|
|
8
|
+
import {privateDirectory,privateFile} from './private-files.mjs'
|
|
9
|
+
const helper=fileURLToPath(new URL('./store-process.mjs',import.meta.url))
|
|
10
|
+
export class FileProjectionStore {
|
|
11
|
+
#directory
|
|
12
|
+
constructor(directory){this.#directory=path.resolve(directory)}
|
|
13
|
+
static create(directory,limits={}){
|
|
14
|
+
check(process.platform==='linux','ProjectionStoreUnsupported')
|
|
15
|
+
privateDirectory(path.dirname(path.resolve(directory)))
|
|
16
|
+
const store=new FileProjectionStore(directory)
|
|
17
|
+
// Caller supplies an existing private parent. Never implicitly initializes on read.
|
|
18
|
+
fs.mkdirSync(store.#directory,{mode:0o700})
|
|
19
|
+
const fd=fs.openSync(path.join(store.#directory,'lock'),'wx',0o600);fs.fsyncSync(fd);fs.closeSync(fd)
|
|
20
|
+
// Fixed stripes bound physical lock files. Collisions return Busy, never steal
|
|
21
|
+
// a live attempt by PID or wall-clock expiry. The parent retains the OFD lock.
|
|
22
|
+
for(let n=0;n<16;n++){const fd=fs.openSync(path.join(store.#directory,`attempt-${n}`),'wx',0o600);fs.fsyncSync(fd);fs.closeSync(fd)}
|
|
23
|
+
store.#call('create',{limits:bounds(limits)})
|
|
24
|
+
return store
|
|
25
|
+
}
|
|
26
|
+
#call(operation,input,{deadline=null}={}){
|
|
27
|
+
check(deadline===null||Number.isSafeInteger(deadline),'InvalidProjection')
|
|
28
|
+
const remaining=deadline===null?10000:deadline-Date.now()
|
|
29
|
+
check(remaining>0,'ProjectionExecutionTimeout')
|
|
30
|
+
const lock=path.join(this.#directory,'lock')
|
|
31
|
+
try{privateDirectory(this.#directory);privateFile(fs.lstatSync(lock))}
|
|
32
|
+
catch(e){if(e.code==='ENOENT')fail('ProjectionUnavailable');throw e}
|
|
33
|
+
// Pass a pre-opened existing lock FD: flock can never create a missing file.
|
|
34
|
+
const fd=fs.openSync(lock,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW)
|
|
35
|
+
try{privateFile(fs.fstatSync(fd))}catch(error){fs.closeSync(fd);throw error}
|
|
36
|
+
let result
|
|
37
|
+
const mode=['read','inspect','repair','begin'].includes(operation)?'--shared':'--exclusive'
|
|
38
|
+
// Short reads/publications serialize within a bounded kernel wait. Attempt
|
|
39
|
+
// ownership remains nonblocking below; this never retries an effect or CAS.
|
|
40
|
+
const waitSeconds=String(Math.min(250,remaining)/1000)
|
|
41
|
+
try{result=spawnSync('/usr/bin/setpriv',['--pdeathsig','SIGKILL','--','/usr/bin/flock',mode,'--timeout',waitSeconds,'--no-fork','--conflict-exit-code','73','/proc/self/fd/3',process.execPath,helper,this.#directory,operation,String(process.pid)],
|
|
42
|
+
{input:JSON.stringify(input),stdio:['pipe','pipe','pipe',fd],maxBuffer:13*1024*1024,timeout:Math.min(10000,remaining),killSignal:'SIGKILL'})}
|
|
43
|
+
finally{fs.closeSync(fd)}
|
|
44
|
+
if(result.status===73)fail('ProjectionStoreBusy')
|
|
45
|
+
if(result.error?.code==='ETIMEDOUT'&&deadline!==null)fail('ProjectionExecutionTimeout')
|
|
46
|
+
if(result.error||result.status!==0)fail('ProjectionUnavailable')
|
|
47
|
+
let output;try{output=JSON.parse(result.stdout)}catch{fail('ProjectionStoreCorrupt')}
|
|
48
|
+
if(output.error)fail(output.error)
|
|
49
|
+
return output.value
|
|
50
|
+
}
|
|
51
|
+
inspect(){return this.#call('inspect',{})}
|
|
52
|
+
// Hints only: readers validate the durable image under the existing lock.
|
|
53
|
+
// Its mtime is touched only after publication/drop, never pending lease writes.
|
|
54
|
+
// Neither this timestamp nor event delivery is a state/revision authority.
|
|
55
|
+
watch(onChange){
|
|
56
|
+
let timer,closed=false
|
|
57
|
+
const notify=()=>{if(closed||timer)return;timer=setTimeout(()=>{timer=null;if(!closed)onChange()},20)}
|
|
58
|
+
const watcher=fs.watch(this.#directory,(_event,name)=>{if(name===null||String(name)==='lock')notify()})
|
|
59
|
+
watcher.on('error',notify)
|
|
60
|
+
return ()=>{if(closed)return;closed=true;clearTimeout(timer);watcher.close()}
|
|
61
|
+
}
|
|
62
|
+
async withAttempt(id,operation){
|
|
63
|
+
token(id);privateDirectory(this.#directory);let stripe=0;for(const byte of Buffer.from(id))stripe=(stripe*31+byte)%16
|
|
64
|
+
let fd
|
|
65
|
+
try{fd=fs.openSync(path.join(this.#directory,`attempt-${stripe}`),fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW)}
|
|
66
|
+
catch(error){if(error.code==='ENOENT')fail('ProjectionUnavailable');throw error}
|
|
67
|
+
try{
|
|
68
|
+
privateFile(fs.fstatSync(fd))
|
|
69
|
+
const result=spawnSync('/usr/bin/flock',['--exclusive','--nonblock','--conflict-exit-code','73','3'],{stdio:['ignore','pipe','pipe',fd],timeout:1000})
|
|
70
|
+
if(result.status===73)fail('ProjectionStoreBusy')
|
|
71
|
+
check(!result.error&&result.status===0,'ProjectionUnavailable')
|
|
72
|
+
return await operation()
|
|
73
|
+
}finally{fs.closeSync(fd)}
|
|
74
|
+
}
|
|
75
|
+
begin(key,options){return this.#call('begin',{key:token(key)},options)}
|
|
76
|
+
read(key,revision=null){return this.#call('read',{key:token(key),revision})}
|
|
77
|
+
publish(ticket,snapshot,jobId,options){return this.#call('publish',{ticket,snapshot,jobId:token(jobId)},options)}
|
|
78
|
+
pending(record,options={}){return this.#call('pending',{record,previousHolder:options.previousHolder??null},options)}
|
|
79
|
+
repair(id){return this.#call('repair',{id:token(id)})}
|
|
80
|
+
finish(id){return this.#call('finish',{id:token(id)})}
|
|
81
|
+
dropSnapshots(key){return this.#call('drop',{key:token(key)})}
|
|
82
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ExactSource, ProjectionRequest, ProducerIdentity, SceneConfiguration, SourceRef, Snapshot, PublicationTicket, PublicationReceipt } from '@zixcel/projection-contracts';
|
|
2
|
+
export interface RuntimeLimits { concurrent: number; queued: number; inputBytes: number; executionMs: number; keys: number; snapshots: number; repairs: number; attempts: number; repairMs: number }
|
|
3
|
+
export interface StoreOptions { deadline?: number | null; previousHolder?: string | null }
|
|
4
|
+
export interface RepairRecord {
|
|
5
|
+
id: string; holder: string; previous: readonly { holder: string; leases: readonly string[] }[];
|
|
6
|
+
ticket: PublicationTicket; request: ProjectionRequest; producer: ProducerIdentity;
|
|
7
|
+
accessRef: string; expiresAt: number; attempts: number; failure: string | null; leases: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface StoreReceipt extends PublicationReceipt { readonly jobId: string }
|
|
10
|
+
export interface StoreInspection {
|
|
11
|
+
keys: readonly { key: string; current: string | null; fence: string; snapshots: number }[];
|
|
12
|
+
repairs: readonly RepairRecord[]; limits: Readonly<RuntimeLimits>;
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectionStore {
|
|
15
|
+
inspect(): StoreInspection;
|
|
16
|
+
withAttempt<T>(id: string, operation: () => T | PromiseLike<T>): Promise<T>;
|
|
17
|
+
begin(key: string, options?: StoreOptions): PublicationTicket;
|
|
18
|
+
read(key: string, revision?: string | null): Snapshot | null;
|
|
19
|
+
publish(ticket: PublicationTicket, snapshot: Snapshot, jobId: string, options?: StoreOptions): StoreReceipt;
|
|
20
|
+
pending(record: RepairRecord, options?: StoreOptions): RepairRecord;
|
|
21
|
+
repair(id: string): RepairRecord | null;
|
|
22
|
+
finish(id: string): null;
|
|
23
|
+
}
|
|
24
|
+
export interface SourceReadOptions { accessRef: string; holder: string; until: number; deadline: number; signal: AbortSignal }
|
|
25
|
+
export interface SourceReader {
|
|
26
|
+
acquireExact(refs: readonly SourceRef[], options: SourceReadOptions): Promise<{ sources: readonly ExactSource[]; leaseRefs: readonly string[] }>;
|
|
27
|
+
release(leaseRefs: readonly string[], holder: string): void | Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/** Owner adapters retain authorization, durable leases and bounded/cancellable IO. */
|
|
30
|
+
export interface SourceAdapter {
|
|
31
|
+
acquire(source: SourceRef, options: SourceReadOptions): string | Promise<string>;
|
|
32
|
+
read(source: SourceRef, lease: string, options: SourceReadOptions): ExactSource | Promise<ExactSource>;
|
|
33
|
+
release(lease: string, holder: string): void | Promise<void>;
|
|
34
|
+
releaseHolder(holder: string): void | Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface SubmissionOptions { accessRef: string; signal?: AbortSignal; id?: string }
|
|
37
|
+
export type ProducerConfiguration = Readonly<Record<string, import('@zixcel/projection-contracts').Json>> | SceneConfiguration;
|