@astrale-os/kernel-protocol 0.5.0-beta.10
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/dist/artifact/index.d.ts +1 -0
- package/dist/artifact/index.js +1 -0
- package/dist/artifact/ref.d.ts +10 -0
- package/dist/artifact/ref.js +70 -0
- package/dist/codecs/codec.d.ts +13 -0
- package/dist/codecs/codec.js +6 -0
- package/dist/codecs/index.d.ts +4 -0
- package/dist/codecs/index.js +4 -0
- package/dist/codecs/json.d.ts +2 -0
- package/dist/codecs/json.js +20 -0
- package/dist/codecs/media-types.d.ts +2 -0
- package/dist/codecs/media-types.js +2 -0
- package/dist/codecs/msgpack.d.ts +4 -0
- package/dist/codecs/msgpack.js +50 -0
- package/dist/errors/codes.d.ts +23 -0
- package/dist/errors/codes.js +22 -0
- package/dist/errors/http-status.d.ts +2 -0
- package/dist/errors/http-status.js +25 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/payload.d.ts +8 -0
- package/dist/errors/payload.js +37 -0
- package/dist/errors/protocol-error.d.ts +6 -0
- package/dist/errors/protocol-error.js +11 -0
- package/dist/errors/reason.d.ts +7 -0
- package/dist/errors/reason.js +43 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/invocation/admission.d.ts +23 -0
- package/dist/invocation/admission.js +177 -0
- package/dist/invocation/binary.d.ts +11 -0
- package/dist/invocation/binary.js +24 -0
- package/dist/invocation/binding-codecs.d.ts +8 -0
- package/dist/invocation/binding-codecs.js +27 -0
- package/dist/invocation/cancellation.d.ts +8 -0
- package/dist/invocation/cancellation.js +16 -0
- package/dist/invocation/correlation.d.ts +2 -0
- package/dist/invocation/correlation.js +7 -0
- package/dist/invocation/delegate.d.ts +24 -0
- package/dist/invocation/delegate.js +43 -0
- package/dist/invocation/http/binary.d.ts +12 -0
- package/dist/invocation/http/binary.js +132 -0
- package/dist/invocation/http/index.d.ts +4 -0
- package/dist/invocation/http/index.js +4 -0
- package/dist/invocation/http/negotiation.d.ts +3 -0
- package/dist/invocation/http/negotiation.js +207 -0
- package/dist/invocation/http/stream.d.ts +5 -0
- package/dist/invocation/http/stream.js +15 -0
- package/dist/invocation/http/trace.d.ts +6 -0
- package/dist/invocation/http/trace.js +24 -0
- package/dist/invocation/idempotency.d.ts +10 -0
- package/dist/invocation/idempotency.js +13 -0
- package/dist/invocation/identity.d.ts +16 -0
- package/dist/invocation/identity.js +55 -0
- package/dist/invocation/index.d.ts +20 -0
- package/dist/invocation/index.js +20 -0
- package/dist/invocation/miss.d.ts +9 -0
- package/dist/invocation/miss.js +17 -0
- package/dist/invocation/redirect.d.ts +40 -0
- package/dist/invocation/redirect.js +81 -0
- package/dist/invocation/request.d.ts +21 -0
- package/dist/invocation/request.js +54 -0
- package/dist/invocation/response.d.ts +19 -0
- package/dist/invocation/response.js +38 -0
- package/dist/invocation/routing.d.ts +14 -0
- package/dist/invocation/routing.js +34 -0
- package/dist/invocation/schema.d.ts +9 -0
- package/dist/invocation/schema.js +19 -0
- package/dist/invocation/service-reason.d.ts +48 -0
- package/dist/invocation/service-reason.js +85 -0
- package/dist/invocation/stale-route.d.ts +12 -0
- package/dist/invocation/stale-route.js +19 -0
- package/dist/invocation/stream.d.ts +27 -0
- package/dist/invocation/stream.js +44 -0
- package/dist/invocation/target.d.ts +3 -0
- package/dist/invocation/target.js +11 -0
- package/dist/invocation/trace.d.ts +9 -0
- package/dist/invocation/trace.js +86 -0
- package/dist/invocation/version.d.ts +2 -0
- package/dist/invocation/version.js +1 -0
- package/dist/invocation/websocket/binary.d.ts +3 -0
- package/dist/invocation/websocket/binary.js +71 -0
- package/dist/invocation/websocket/index.d.ts +2 -0
- package/dist/invocation/websocket/index.js +2 -0
- package/dist/invocation/websocket/subprotocol.d.ts +10 -0
- package/dist/invocation/websocket/subprotocol.js +29 -0
- package/dist/issuer/configuration.d.ts +14 -0
- package/dist/issuer/configuration.js +86 -0
- package/dist/issuer/error.d.ts +7 -0
- package/dist/issuer/error.js +11 -0
- package/dist/issuer/exchange.d.ts +25 -0
- package/dist/issuer/exchange.js +129 -0
- package/dist/issuer/hosted.d.ts +2 -0
- package/dist/issuer/hosted.js +7 -0
- package/dist/issuer/index.d.ts +6 -0
- package/dist/issuer/index.js +6 -0
- package/dist/issuer/key-set.d.ts +6 -0
- package/dist/issuer/key-set.js +48 -0
- package/dist/issuer/paths.d.ts +6 -0
- package/dist/issuer/paths.js +10 -0
- package/dist/issuer/url.d.ts +2 -0
- package/dist/issuer/url.js +34 -0
- package/dist/publication/bindings/callable.d.ts +8 -0
- package/dist/publication/bindings/callable.js +34 -0
- package/dist/publication/bindings/index.d.ts +3 -0
- package/dist/publication/bindings/index.js +3 -0
- package/dist/publication/bindings/invocation.d.ts +5 -0
- package/dist/publication/bindings/invocation.js +13 -0
- package/dist/publication/bindings/view.d.ts +7 -0
- package/dist/publication/bindings/view.js +28 -0
- package/dist/publication/bundle-admission.d.ts +4 -0
- package/dist/publication/bundle-admission.js +65 -0
- package/dist/publication/bundle-descriptor.d.ts +9 -0
- package/dist/publication/bundle-descriptor.js +19 -0
- package/dist/publication/bundle-evidence.d.ts +3 -0
- package/dist/publication/bundle-evidence.js +13 -0
- package/dist/publication/bundle.d.ts +9 -0
- package/dist/publication/bundle.js +44 -0
- package/dist/publication/content.d.ts +10 -0
- package/dist/publication/content.js +55 -0
- package/dist/publication/declaration.d.ts +11 -0
- package/dist/publication/declaration.js +1 -0
- package/dist/publication/delivery/attestation.d.ts +6 -0
- package/dist/publication/delivery/attestation.js +10 -0
- package/dist/publication/delivery/claims.d.ts +16 -0
- package/dist/publication/delivery/claims.js +61 -0
- package/dist/publication/delivery/delivery.d.ts +9 -0
- package/dist/publication/delivery/delivery.js +29 -0
- package/dist/publication/delivery/error.d.ts +7 -0
- package/dist/publication/delivery/error.js +11 -0
- package/dist/publication/delivery/index.d.ts +6 -0
- package/dist/publication/delivery/index.js +6 -0
- package/dist/publication/delivery/limits.d.ts +4 -0
- package/dist/publication/delivery/limits.js +4 -0
- package/dist/publication/delivery/request.d.ts +15 -0
- package/dist/publication/delivery/request.js +52 -0
- package/dist/publication/delivery-declaration.d.ts +4 -0
- package/dist/publication/delivery-declaration.js +25 -0
- package/dist/publication/delivery-endpoint.d.ts +11 -0
- package/dist/publication/delivery-endpoint.js +22 -0
- package/dist/publication/error.d.ts +7 -0
- package/dist/publication/error.js +11 -0
- package/dist/publication/etag.d.ts +6 -0
- package/dist/publication/etag.js +79 -0
- package/dist/publication/index.d.ts +17 -0
- package/dist/publication/index.js +10 -0
- package/dist/publication/manifest.d.ts +6 -0
- package/dist/publication/manifest.js +30 -0
- package/dist/publication/publication.d.ts +36 -0
- package/dist/publication/publication.js +133 -0
- package/dist/publication/reference.d.ts +17 -0
- package/dist/publication/reference.js +68 -0
- package/dist/publication/requirements.d.ts +26 -0
- package/dist/publication/requirements.js +180 -0
- package/dist/publication/route.d.ts +37 -0
- package/dist/publication/route.js +154 -0
- package/dist/publication/schema.d.ts +7 -0
- package/dist/publication/schema.js +15 -0
- package/dist/routes/admission.d.ts +3 -0
- package/dist/routes/admission.js +89 -0
- package/dist/routes/binding.d.ts +6 -0
- package/dist/routes/binding.js +27 -0
- package/dist/routes/collision.d.ts +2 -0
- package/dist/routes/collision.js +16 -0
- package/dist/routes/compiler.d.ts +8 -0
- package/dist/routes/compiler.js +50 -0
- package/dist/routes/credential.d.ts +8 -0
- package/dist/routes/credential.js +118 -0
- package/dist/routes/decode.d.ts +5 -0
- package/dist/routes/decode.js +147 -0
- package/dist/routes/encode.d.ts +4 -0
- package/dist/routes/encode.js +145 -0
- package/dist/routes/error-response.d.ts +5 -0
- package/dist/routes/error-response.js +31 -0
- package/dist/routes/error.d.ts +8 -0
- package/dist/routes/error.js +14 -0
- package/dist/routes/evidence.d.ts +5 -0
- package/dist/routes/evidence.js +38 -0
- package/dist/routes/index.d.ts +19 -0
- package/dist/routes/index.js +16 -0
- package/dist/routes/mapping.d.ts +5 -0
- package/dist/routes/mapping.js +126 -0
- package/dist/routes/match.d.ts +4 -0
- package/dist/routes/match.js +7 -0
- package/dist/routes/placement.d.ts +5 -0
- package/dist/routes/placement.js +18 -0
- package/dist/routes/plan.d.ts +24 -0
- package/dist/routes/plan.js +1 -0
- package/dist/routes/release-unavailable.d.ts +8 -0
- package/dist/routes/release-unavailable.js +32 -0
- package/dist/routes/request.d.ts +26 -0
- package/dist/routes/request.js +53 -0
- package/dist/routes/reservation.d.ts +3 -0
- package/dist/routes/reservation.js +37 -0
- package/dist/routes/routing.d.ts +22 -0
- package/dist/routes/routing.js +87 -0
- package/dist/routes/scalar.d.ts +7 -0
- package/dist/routes/scalar.js +61 -0
- package/dist/routes/select.d.ts +3 -0
- package/dist/routes/select.js +16 -0
- package/dist/routes/stream.d.ts +14 -0
- package/dist/routes/stream.js +50 -0
- package/dist/routes/table.d.ts +9 -0
- package/dist/routes/table.js +1 -0
- package/dist/routes/target.d.ts +13 -0
- package/dist/routes/target.js +3 -0
- package/dist/routes/template.d.ts +8 -0
- package/dist/routes/template.js +227 -0
- package/dist/runtime/artifact.d.ts +47 -0
- package/dist/runtime/artifact.js +176 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/installation/index.d.ts +1 -0
- package/dist/schema/installation/index.js +1 -0
- package/dist/schema/installation/introspection/codec.d.ts +5 -0
- package/dist/schema/installation/introspection/codec.js +272 -0
- package/dist/schema/installation/introspection/index.d.ts +2 -0
- package/dist/schema/installation/introspection/index.js +1 -0
- package/dist/schema/installation/introspection/result.d.ts +33 -0
- package/dist/schema/installation/introspection/result.js +1 -0
- package/package.json +163 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import * as bundle from '@astrale-os/kernel-dsl/v1/bundle/transport';
|
|
2
|
+
import * as artifact from '../../../artifact/index.js';
|
|
3
|
+
import { json } from '../../../codecs/index.js';
|
|
4
|
+
import * as publication from '../../../publication/index.js';
|
|
5
|
+
import * as runtime from '../../../runtime/index.js';
|
|
6
|
+
export const MEDIA_TYPE = 'application/vnd.astrale.schema-introspection.v1+msgpack';
|
|
7
|
+
export async function encode(input, result) {
|
|
8
|
+
const fields = selected(input);
|
|
9
|
+
const wire = result === null ? null : encodeResult(fields, result);
|
|
10
|
+
const { pack } = await import('msgpackr/pack');
|
|
11
|
+
return new Uint8Array(pack(wire));
|
|
12
|
+
}
|
|
13
|
+
export async function decode(input, bytes, limits) {
|
|
14
|
+
if (!(bytes instanceof Uint8Array))
|
|
15
|
+
invalid('Schema introspection evidence must be binary.');
|
|
16
|
+
admitLimit(limits.maximumPublicationBytes, 'Publication');
|
|
17
|
+
admitLimit(limits.maximumBundleBytes, 'Bundle');
|
|
18
|
+
if (bytes.byteLength > limits.maximumPublicationBytes + limits.maximumBundleBytes + 2_048) {
|
|
19
|
+
invalid('Schema introspection evidence exceeds its declared bounds.');
|
|
20
|
+
}
|
|
21
|
+
const { unpack } = await import('msgpackr/unpack');
|
|
22
|
+
let decoded;
|
|
23
|
+
try {
|
|
24
|
+
decoded = unpack(bytes);
|
|
25
|
+
}
|
|
26
|
+
catch (cause) {
|
|
27
|
+
throw new TypeError('Schema introspection evidence is malformed.', { cause });
|
|
28
|
+
}
|
|
29
|
+
if (decoded === null)
|
|
30
|
+
return null;
|
|
31
|
+
if (!isRecord(decoded))
|
|
32
|
+
invalid('Schema introspection result must be an object or null.');
|
|
33
|
+
const fields = selected(input);
|
|
34
|
+
exact(decoded, fields, 'Schema introspection result');
|
|
35
|
+
return decodeResult(fields, decoded, limits);
|
|
36
|
+
}
|
|
37
|
+
function encodeResult(fields, result) {
|
|
38
|
+
exact(result, fields, 'Schema introspection result');
|
|
39
|
+
const source = fields.includes('source') ? encodeSource(result.source) : undefined;
|
|
40
|
+
const output = {};
|
|
41
|
+
for (const field of fields) {
|
|
42
|
+
switch (field) {
|
|
43
|
+
case 'state':
|
|
44
|
+
output.state = state(result.state);
|
|
45
|
+
break;
|
|
46
|
+
case 'target':
|
|
47
|
+
output.target = digest(result.target, 'Installation target');
|
|
48
|
+
break;
|
|
49
|
+
case 'source':
|
|
50
|
+
output.source = source;
|
|
51
|
+
break;
|
|
52
|
+
case 'bundle':
|
|
53
|
+
output.bundle = encodeBundle(result.bundle, result.source);
|
|
54
|
+
break;
|
|
55
|
+
case 'readiness':
|
|
56
|
+
output.readiness =
|
|
57
|
+
result.readiness === null ? null : digest(result.readiness, 'Installation readiness');
|
|
58
|
+
break;
|
|
59
|
+
case 'capabilities':
|
|
60
|
+
output.capabilities = capabilities(result.capabilities);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Object.freeze(output);
|
|
65
|
+
}
|
|
66
|
+
function decodeResult(fields, input, limits) {
|
|
67
|
+
const source = fields.includes('source') ? decodeSource(input.source, limits) : undefined;
|
|
68
|
+
const output = {};
|
|
69
|
+
for (const field of fields) {
|
|
70
|
+
switch (field) {
|
|
71
|
+
case 'state':
|
|
72
|
+
output.state = state(input.state);
|
|
73
|
+
break;
|
|
74
|
+
case 'target':
|
|
75
|
+
output.target = digest(input.target, 'Installation target');
|
|
76
|
+
break;
|
|
77
|
+
case 'source':
|
|
78
|
+
output.source = source;
|
|
79
|
+
break;
|
|
80
|
+
case 'bundle':
|
|
81
|
+
output.bundle = decodeBundle(input.bundle, source, limits.maximumBundleBytes);
|
|
82
|
+
break;
|
|
83
|
+
case 'readiness':
|
|
84
|
+
output.readiness =
|
|
85
|
+
input.readiness === null ? null : digest(input.readiness, 'Installation readiness');
|
|
86
|
+
break;
|
|
87
|
+
case 'capabilities':
|
|
88
|
+
output.capabilities = capabilities(input.capabilities);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (output.state === 'ready' && Object.hasOwn(output, 'readiness') && output.readiness === null) {
|
|
93
|
+
invalid('A ready Installation requires readiness evidence.');
|
|
94
|
+
}
|
|
95
|
+
return Object.freeze(output);
|
|
96
|
+
}
|
|
97
|
+
function encodeSource(input) {
|
|
98
|
+
if (input?.kind === 'builtin') {
|
|
99
|
+
return Object.freeze({
|
|
100
|
+
kind: 'builtin',
|
|
101
|
+
bundle: ref(input.bundle, publication.BUNDLE_MEDIA_TYPE, 'Builtin schema Bundle'),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (input?.kind === 'local') {
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
kind: 'local',
|
|
107
|
+
artifact: ref(input.artifact, runtime.MEDIA_TYPE, 'Local Runtime Artifact'),
|
|
108
|
+
bundle: ref(input.bundle, publication.BUNDLE_MEDIA_TYPE, 'Local schema Bundle'),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (input?.kind === 'remote') {
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
kind: 'remote',
|
|
114
|
+
publication: publication.encode(publication.accept(input.publication)),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return invalid('Installation source is invalid.');
|
|
118
|
+
}
|
|
119
|
+
function decodeSource(input, limits) {
|
|
120
|
+
if (!isRecord(input))
|
|
121
|
+
invalid('Installation source is invalid.');
|
|
122
|
+
if (input.kind === 'builtin') {
|
|
123
|
+
exact(input, ['bundle', 'kind'], 'Builtin installation source');
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
kind: 'builtin',
|
|
126
|
+
bundle: ref(input.bundle, publication.BUNDLE_MEDIA_TYPE, 'Builtin schema Bundle'),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (input.kind === 'local') {
|
|
130
|
+
exact(input, ['artifact', 'bundle', 'kind'], 'Local installation source');
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
kind: 'local',
|
|
133
|
+
artifact: ref(input.artifact, runtime.MEDIA_TYPE, 'Local Runtime Artifact'),
|
|
134
|
+
bundle: ref(input.bundle, publication.BUNDLE_MEDIA_TYPE, 'Local schema Bundle'),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (input.kind === 'remote') {
|
|
138
|
+
exact(input, ['kind', 'publication'], 'Remote installation source');
|
|
139
|
+
const encoded = boundedBytes(input.publication, limits.maximumPublicationBytes, 'Publication');
|
|
140
|
+
let admitted;
|
|
141
|
+
try {
|
|
142
|
+
admitted = publication.accept(json.decode(encoded));
|
|
143
|
+
}
|
|
144
|
+
catch (cause) {
|
|
145
|
+
throw new TypeError('Remote installed Publication is invalid.', { cause });
|
|
146
|
+
}
|
|
147
|
+
if (!equal(encoded, publication.encode(admitted))) {
|
|
148
|
+
invalid('Remote installed Publication is not canonical.');
|
|
149
|
+
}
|
|
150
|
+
return Object.freeze({ kind: 'remote', publication: admitted });
|
|
151
|
+
}
|
|
152
|
+
return invalid('Installation source kind is invalid.');
|
|
153
|
+
}
|
|
154
|
+
function encodeBundle(input, source) {
|
|
155
|
+
if (source === undefined || input === undefined)
|
|
156
|
+
invalid('Bundle source evidence is missing.');
|
|
157
|
+
const admitted = source.kind === 'remote'
|
|
158
|
+
? publication.acceptBundle(source.publication, input)
|
|
159
|
+
: bundle.accept(input);
|
|
160
|
+
const encoded = bundle.encode(admitted);
|
|
161
|
+
if (source.kind !== 'remote' &&
|
|
162
|
+
!same(artifact.identify(encoded, publication.BUNDLE_MEDIA_TYPE), source.bundle)) {
|
|
163
|
+
invalid('Local schema Bundle does not match its source Ref.');
|
|
164
|
+
}
|
|
165
|
+
return encoded;
|
|
166
|
+
}
|
|
167
|
+
function decodeBundle(input, source, maximum) {
|
|
168
|
+
const encoded = boundedBytes(input, maximum, 'Bundle');
|
|
169
|
+
let admitted;
|
|
170
|
+
try {
|
|
171
|
+
admitted =
|
|
172
|
+
source.kind === 'remote'
|
|
173
|
+
? publication.decodeBundle(source.publication, encoded)
|
|
174
|
+
: bundle.decode(encoded);
|
|
175
|
+
}
|
|
176
|
+
catch (cause) {
|
|
177
|
+
throw new TypeError('Installed schema Bundle is invalid.', { cause });
|
|
178
|
+
}
|
|
179
|
+
if (!equal(encoded, bundle.encode(admitted)))
|
|
180
|
+
invalid('Installed schema Bundle is not canonical.');
|
|
181
|
+
if (source.kind !== 'remote' &&
|
|
182
|
+
!same(artifact.identify(encoded, publication.BUNDLE_MEDIA_TYPE), source.bundle)) {
|
|
183
|
+
invalid('Local schema Bundle does not match its source Ref.');
|
|
184
|
+
}
|
|
185
|
+
return admitted;
|
|
186
|
+
}
|
|
187
|
+
function selected(input) {
|
|
188
|
+
if (input === null ||
|
|
189
|
+
typeof input !== 'object' ||
|
|
190
|
+
input.from?.kind !== 'installation' ||
|
|
191
|
+
input.select === null ||
|
|
192
|
+
typeof input.select !== 'object') {
|
|
193
|
+
invalid('Schema introspection request is invalid.');
|
|
194
|
+
}
|
|
195
|
+
const allowed = ['state', 'target', 'source', 'bundle', 'readiness', 'capabilities'];
|
|
196
|
+
const fields = Object.keys(input.select);
|
|
197
|
+
if (fields.length === 0 ||
|
|
198
|
+
fields.some((field) => !allowed.includes(field) ||
|
|
199
|
+
input.select[field] !== true) ||
|
|
200
|
+
(input.select.bundle === true && input.select.source !== true)) {
|
|
201
|
+
invalid('Schema introspection selection is invalid.');
|
|
202
|
+
}
|
|
203
|
+
return Object.freeze(allowed.filter((field) => input.select[field] === true));
|
|
204
|
+
}
|
|
205
|
+
function capabilities(input) {
|
|
206
|
+
if (!isRecord(input))
|
|
207
|
+
invalid('Installation capabilities are invalid.');
|
|
208
|
+
exact(input, ['materialized', 'requested'], 'Installation capabilities');
|
|
209
|
+
try {
|
|
210
|
+
const requested = publication.admitRequirements({ capabilities: input.requested }).capabilities;
|
|
211
|
+
const materialized = publication.admitRequirements({
|
|
212
|
+
capabilities: input.materialized,
|
|
213
|
+
}).capabilities;
|
|
214
|
+
return Object.freeze({ requested, materialized });
|
|
215
|
+
}
|
|
216
|
+
catch (cause) {
|
|
217
|
+
throw new TypeError('Installation capabilities are invalid.', { cause });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function state(input) {
|
|
221
|
+
if (input !== 'installed' && input !== 'ready' && input !== 'removing') {
|
|
222
|
+
invalid('Installation state is invalid.');
|
|
223
|
+
}
|
|
224
|
+
return input;
|
|
225
|
+
}
|
|
226
|
+
function digest(input, label) {
|
|
227
|
+
if (typeof input !== 'string' || !/^sha256:[0-9a-f]{64}$/u.test(input)) {
|
|
228
|
+
invalid(`${label} digest is invalid.`);
|
|
229
|
+
}
|
|
230
|
+
return input;
|
|
231
|
+
}
|
|
232
|
+
function ref(input, mediaType, label) {
|
|
233
|
+
let admitted;
|
|
234
|
+
try {
|
|
235
|
+
admitted = artifact.accept(input);
|
|
236
|
+
}
|
|
237
|
+
catch (cause) {
|
|
238
|
+
throw new TypeError(`${label} Ref is invalid.`, { cause });
|
|
239
|
+
}
|
|
240
|
+
if (admitted.mediaType !== mediaType)
|
|
241
|
+
invalid(`${label} media type is invalid.`);
|
|
242
|
+
return admitted;
|
|
243
|
+
}
|
|
244
|
+
function same(left, right) {
|
|
245
|
+
return (left.digest === right.digest && left.mediaType === right.mediaType && left.size === right.size);
|
|
246
|
+
}
|
|
247
|
+
function boundedBytes(input, maximum, label) {
|
|
248
|
+
if (!(input instanceof Uint8Array) || input.byteLength === 0 || input.byteLength > maximum) {
|
|
249
|
+
invalid(`${label} evidence is invalid or exceeds its bound.`);
|
|
250
|
+
}
|
|
251
|
+
return Uint8Array.from(input);
|
|
252
|
+
}
|
|
253
|
+
function admitLimit(input, label) {
|
|
254
|
+
if (!Number.isSafeInteger(input) || input < 1)
|
|
255
|
+
invalid(`${label} evidence bound is invalid.`);
|
|
256
|
+
}
|
|
257
|
+
function exact(input, expected, label) {
|
|
258
|
+
const keys = Object.keys(input).sort();
|
|
259
|
+
const wanted = [...expected].sort();
|
|
260
|
+
if (keys.length !== wanted.length || keys.some((key, index) => key !== wanted[index])) {
|
|
261
|
+
invalid(`${label} fields are invalid.`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function equal(left, right) {
|
|
265
|
+
return left.byteLength === right.byteLength && left.every((byte, index) => byte === right[index]);
|
|
266
|
+
}
|
|
267
|
+
function isRecord(input) {
|
|
268
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input);
|
|
269
|
+
}
|
|
270
|
+
function invalid(message) {
|
|
271
|
+
throw new TypeError(message);
|
|
272
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MEDIA_TYPE, decode, encode } from './codec.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { introspection } from '@astrale-os/kernel-core/schema';
|
|
2
|
+
import type { bundle } from '@astrale-os/kernel-dsl/v1';
|
|
3
|
+
import type { Ref } from '../../../artifact/index.js';
|
|
4
|
+
import type { Publication } from '../../../publication/index.js';
|
|
5
|
+
import type { PublicationRequirements } from '../../../publication/index.js';
|
|
6
|
+
export type Digest = `sha256:${string}`;
|
|
7
|
+
export type Source = {
|
|
8
|
+
readonly kind: 'builtin';
|
|
9
|
+
readonly bundle: Ref;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'local';
|
|
12
|
+
readonly artifact: Ref;
|
|
13
|
+
readonly bundle: Ref;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'remote';
|
|
16
|
+
readonly publication: Publication;
|
|
17
|
+
};
|
|
18
|
+
export interface Installation {
|
|
19
|
+
readonly state: 'installed' | 'ready' | 'removing';
|
|
20
|
+
readonly target: Digest;
|
|
21
|
+
readonly source: Source;
|
|
22
|
+
readonly bundle: bundle.Bundle;
|
|
23
|
+
readonly readiness: Digest | null;
|
|
24
|
+
readonly capabilities: {
|
|
25
|
+
readonly requested: PublicationRequirements['capabilities'];
|
|
26
|
+
readonly materialized: PublicationRequirements['capabilities'];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export type ResultFor<Input extends introspection.Introspection> = Pick<Installation, Extract<keyof Input['select'], keyof Installation>> | null;
|
|
30
|
+
export interface Limits {
|
|
31
|
+
readonly maximumPublicationBytes: number;
|
|
32
|
+
readonly maximumBundleBytes: number;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@astrale-os/kernel-protocol",
|
|
3
|
+
"version": "0.5.0-beta.10",
|
|
4
|
+
"description": "Portable Astrale invocation, publication, installation, routing, and issuer protocols",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/astrale-os/kernel.git",
|
|
9
|
+
"directory": "protocol"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./codecs": {
|
|
23
|
+
"types": "./dist/codecs/index.d.ts",
|
|
24
|
+
"import": "./dist/codecs/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./errors": {
|
|
27
|
+
"types": "./dist/errors/index.d.ts",
|
|
28
|
+
"import": "./dist/errors/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./issuer/configuration": {
|
|
31
|
+
"types": "./dist/issuer/configuration.d.ts",
|
|
32
|
+
"import": "./dist/issuer/configuration.js"
|
|
33
|
+
},
|
|
34
|
+
"./issuer/exchange": {
|
|
35
|
+
"types": "./dist/issuer/exchange.d.ts",
|
|
36
|
+
"import": "./dist/issuer/exchange.js"
|
|
37
|
+
},
|
|
38
|
+
"./issuer/hosted": {
|
|
39
|
+
"types": "./dist/issuer/hosted.d.ts",
|
|
40
|
+
"import": "./dist/issuer/hosted.js"
|
|
41
|
+
},
|
|
42
|
+
"./issuer/key-set": {
|
|
43
|
+
"types": "./dist/issuer/key-set.d.ts",
|
|
44
|
+
"import": "./dist/issuer/key-set.js"
|
|
45
|
+
},
|
|
46
|
+
"./issuer/paths": {
|
|
47
|
+
"types": "./dist/issuer/paths.d.ts",
|
|
48
|
+
"import": "./dist/issuer/paths.js"
|
|
49
|
+
},
|
|
50
|
+
"./invocation": {
|
|
51
|
+
"types": "./dist/invocation/index.d.ts",
|
|
52
|
+
"import": "./dist/invocation/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./invocation/service-reason": {
|
|
55
|
+
"types": "./dist/invocation/service-reason.d.ts",
|
|
56
|
+
"import": "./dist/invocation/service-reason.js"
|
|
57
|
+
},
|
|
58
|
+
"./artifact": {
|
|
59
|
+
"types": "./dist/artifact/index.d.ts",
|
|
60
|
+
"import": "./dist/artifact/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./publication": {
|
|
63
|
+
"types": "./dist/publication/index.d.ts",
|
|
64
|
+
"import": "./dist/publication/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./publication/publication": {
|
|
67
|
+
"types": "./dist/publication/publication.d.ts",
|
|
68
|
+
"import": "./dist/publication/publication.js"
|
|
69
|
+
},
|
|
70
|
+
"./publication/reference": {
|
|
71
|
+
"types": "./dist/publication/reference.d.ts",
|
|
72
|
+
"import": "./dist/publication/reference.js"
|
|
73
|
+
},
|
|
74
|
+
"./publication/requirements": {
|
|
75
|
+
"types": "./dist/publication/requirements.d.ts",
|
|
76
|
+
"import": "./dist/publication/requirements.js"
|
|
77
|
+
},
|
|
78
|
+
"./publication/delivery": {
|
|
79
|
+
"types": "./dist/publication/delivery/index.d.ts",
|
|
80
|
+
"import": "./dist/publication/delivery/index.js"
|
|
81
|
+
},
|
|
82
|
+
"./publication/bundle": {
|
|
83
|
+
"types": "./dist/publication/bundle.d.ts",
|
|
84
|
+
"import": "./dist/publication/bundle.js"
|
|
85
|
+
},
|
|
86
|
+
"./publication/bundle-evidence": {
|
|
87
|
+
"types": "./dist/publication/bundle-evidence.d.ts",
|
|
88
|
+
"import": "./dist/publication/bundle-evidence.js"
|
|
89
|
+
},
|
|
90
|
+
"./publication/delivery-declaration": {
|
|
91
|
+
"types": "./dist/publication/delivery-declaration.d.ts",
|
|
92
|
+
"import": "./dist/publication/delivery-declaration.js"
|
|
93
|
+
},
|
|
94
|
+
"./routes": {
|
|
95
|
+
"types": "./dist/routes/index.d.ts",
|
|
96
|
+
"import": "./dist/routes/index.js"
|
|
97
|
+
},
|
|
98
|
+
"./schema": {
|
|
99
|
+
"types": "./dist/schema/index.d.ts",
|
|
100
|
+
"import": "./dist/schema/index.js"
|
|
101
|
+
},
|
|
102
|
+
"./routes/admission": {
|
|
103
|
+
"types": "./dist/routes/admission.d.ts",
|
|
104
|
+
"import": "./dist/routes/admission.js"
|
|
105
|
+
},
|
|
106
|
+
"./routes/binding": {
|
|
107
|
+
"types": "./dist/routes/binding.d.ts",
|
|
108
|
+
"import": "./dist/routes/binding.js"
|
|
109
|
+
},
|
|
110
|
+
"./routes/evidence": {
|
|
111
|
+
"types": "./dist/routes/evidence.d.ts",
|
|
112
|
+
"import": "./dist/routes/evidence.js"
|
|
113
|
+
},
|
|
114
|
+
"./routes/placement": {
|
|
115
|
+
"types": "./dist/routes/placement.d.ts",
|
|
116
|
+
"import": "./dist/routes/placement.js"
|
|
117
|
+
},
|
|
118
|
+
"./routes/release-unavailable": {
|
|
119
|
+
"types": "./dist/routes/release-unavailable.d.ts",
|
|
120
|
+
"import": "./dist/routes/release-unavailable.js"
|
|
121
|
+
},
|
|
122
|
+
"./routes/routing": {
|
|
123
|
+
"types": "./dist/routes/routing.d.ts",
|
|
124
|
+
"import": "./dist/routes/routing.js"
|
|
125
|
+
},
|
|
126
|
+
"./runtime": {
|
|
127
|
+
"types": "./dist/runtime/index.d.ts",
|
|
128
|
+
"import": "./dist/runtime/index.js"
|
|
129
|
+
},
|
|
130
|
+
"./package.json": "./package.json"
|
|
131
|
+
},
|
|
132
|
+
"publishConfig": {
|
|
133
|
+
"access": "public"
|
|
134
|
+
},
|
|
135
|
+
"dependencies": {
|
|
136
|
+
"@astrale-os/kernel-core": ">=0.9.0-beta.9 <1.0.0",
|
|
137
|
+
"@astrale-os/kernel-dsl": ">=0.2.0-beta.7 <1.0.0",
|
|
138
|
+
"@noble/hashes": "2.3.0"
|
|
139
|
+
},
|
|
140
|
+
"devDependencies": {
|
|
141
|
+
"@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
|
|
142
|
+
"msgpackr": "^2.0.5",
|
|
143
|
+
"typescript": "7.0.2",
|
|
144
|
+
"vitest": "^4.1.10"
|
|
145
|
+
},
|
|
146
|
+
"peerDependencies": {
|
|
147
|
+
"msgpackr": "^2.0.5"
|
|
148
|
+
},
|
|
149
|
+
"peerDependenciesMeta": {
|
|
150
|
+
"msgpackr": {
|
|
151
|
+
"optional": true
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"scripts": {
|
|
155
|
+
"build": "tsc",
|
|
156
|
+
"clean": "rm -rf dist",
|
|
157
|
+
"typecheck": "tsc --noEmit",
|
|
158
|
+
"test": "vitest run",
|
|
159
|
+
"test:file": "vitest run",
|
|
160
|
+
"test:watch": "vitest",
|
|
161
|
+
"preinstall": "node -e \"try{require('./.check-workspace.cjs')}catch{}\""
|
|
162
|
+
}
|
|
163
|
+
}
|