@xlinklight/publishing 3.3.1 → 3.4.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/README.md +22 -2
- package/dist/src/acceptance-delivery-binding.d.ts +20 -0
- package/dist/src/acceptance.d.ts +49 -0
- package/dist/src/client.d.ts +71 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/node/acceptance-delivery.d.ts +34 -0
- package/dist/src/node/activation.d.ts +5 -0
- package/dist/src/node/authorization.d.ts +31 -0
- package/dist/src/node/cli.d.ts +2 -0
- package/dist/src/node/cli.js +4 -2
- package/dist/src/node/index.d.ts +20 -0
- package/dist/src/node/index.js +2 -0
- package/dist/src/node/journal-directory.d.ts +2 -0
- package/dist/src/node/journal-directory.js +121 -0
- package/dist/src/node/journal.d.ts +49 -0
- package/dist/src/node/journal.js +6 -8
- package/dist/src/node/local-json-file.d.ts +3 -0
- package/dist/src/node/local-json-file.js +49 -0
- package/dist/src/node/publishing-command.d.ts +46 -0
- package/dist/src/node/publishing-command.js +64 -16
- package/dist/src/node/session.d.ts +95 -0
- package/dist/src/node/solution-package.d.ts +55 -0
- package/dist/src/node/source-error.d.ts +10 -0
- package/dist/src/node/source-producer.d.ts +5 -0
- package/dist/src/node/terminal-network.d.ts +23 -0
- package/dist/src/node/terminal-network.js +122 -0
- package/dist/src/node/workflow.d.ts +74 -0
- package/dist/src/node/workflow.js +46 -34
- package/dist/src/package.d.ts +38 -0
- package/dist/src/protocol.d.ts +83 -0
- package/dist/src/protocol.js +1 -1
- package/dist/src/shared/activation-types.d.ts +37 -0
- package/dist/src/shared/activation-types.js +1 -0
- package/dist/src/shared/activation.d.ts +17 -0
- package/dist/src/shared/records.d.ts +10 -0
- package/dist/src/shared/release-version.d.ts +4 -0
- package/dist/src/shared/release-version.js +15 -0
- package/dist/src/worker/activation.d.ts +12 -0
- package/dist/src/worker/activation.js +2 -1
- package/dist/src/worker/durable-retention.d.ts +9 -0
- package/dist/src/worker/durable-retention.js +96 -0
- package/dist/src/worker/index.d.ts +12 -0
- package/dist/src/worker/index.js +1 -0
- package/dist/src/worker/journal.d.ts +129 -0
- package/dist/src/worker/journal.js +33 -6
- package/dist/src/worker/package.d.ts +60 -0
- package/dist/src/worker/release-retention.d.ts +34 -0
- package/dist/src/worker/release-retention.js +27 -0
- package/dist/src/worker/release.d.ts +22 -0
- package/dist/src/worker/runtime.d.ts +47 -0
- package/dist/src/worker/service.d.ts +128 -0
- package/dist/src/worker/service.js +38 -12
- package/package.json +13 -7
- package/types/acceptance.d.ts +0 -24
- package/types/client.d.ts +0 -16
- package/types/index.d.ts +0 -6
- package/types/node/acceptance-delivery.d.ts +0 -11
- package/types/node/activation.d.ts +0 -8
- package/types/node/authorization.d.ts +0 -8
- package/types/node/index.d.ts +0 -17
- package/types/node/journal.d.ts +0 -13
- package/types/node/publishing-command.d.ts +0 -20
- package/types/node/session.d.ts +0 -25
- package/types/node/solution-package.d.ts +0 -15
- package/types/node/source-error.d.ts +0 -5
- package/types/node/workflow.d.ts +0 -37
- package/types/package.d.ts +0 -11
- package/types/protocol.d.ts +0 -27
- package/types/shared/activation.d.ts +0 -5
- package/types/worker/activation.d.ts +0 -7
- package/types/worker/index.d.ts +0 -6
- package/types/worker/journal.d.ts +0 -21
- package/types/worker/package.d.ts +0 -16
- package/types/worker/release.d.ts +0 -7
- package/types/worker/runtime.d.ts +0 -4
- package/types/worker/service.d.ts +0 -41
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { JsonValue } from '@xlinklight/contracts';
|
|
2
|
+
import type { ArtifactOperationJournal, ArtifactTransportClosure } from '@openge/forge-artifact-publish';
|
|
3
|
+
export interface PublishingDurableStorage {
|
|
4
|
+
readonly sql: {
|
|
5
|
+
readonly databaseSize: number;
|
|
6
|
+
exec(query: string, ...values: (string | number | ArrayBuffer | null)[]): {
|
|
7
|
+
toArray(): Record<string, unknown>[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
transactionSync<T>(work: () => T): T;
|
|
11
|
+
sync(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface PublishingDurableLimits {
|
|
14
|
+
maximumBytes: number;
|
|
15
|
+
maximumRecords: number;
|
|
16
|
+
maximumRecordBytes: number;
|
|
17
|
+
maximumBlobs: number;
|
|
18
|
+
maximumBlobBytes: number;
|
|
19
|
+
recoveryReserveBytes: number;
|
|
20
|
+
}
|
|
21
|
+
export interface PublishingDispatch {
|
|
22
|
+
projectId: string;
|
|
23
|
+
requestId: string;
|
|
24
|
+
mode: 'perform' | 'observe';
|
|
25
|
+
continue: boolean;
|
|
26
|
+
acceptanceReceipt?: true;
|
|
27
|
+
}
|
|
28
|
+
export interface PublishingQueueLease extends PublishingDispatch {
|
|
29
|
+
revision: number;
|
|
30
|
+
observations: number;
|
|
31
|
+
}
|
|
32
|
+
export interface PublishingMutationAuthority {
|
|
33
|
+
kind: 'configure' | 'request' | 'worker';
|
|
34
|
+
projectId: string;
|
|
35
|
+
requestId?: string;
|
|
36
|
+
policyRevision?: number;
|
|
37
|
+
credentialSha256?: string;
|
|
38
|
+
revision?: number;
|
|
39
|
+
owner?: string;
|
|
40
|
+
mode?: 'perform' | 'observe';
|
|
41
|
+
}
|
|
42
|
+
export interface PublishingRecordIdentity {
|
|
43
|
+
key: string;
|
|
44
|
+
revision: number;
|
|
45
|
+
}
|
|
46
|
+
export interface PublishingClosedRequestReplacement {
|
|
47
|
+
requestIds: readonly string[];
|
|
48
|
+
auxiliaryRecords: readonly PublishingRecordIdentity[];
|
|
49
|
+
}
|
|
50
|
+
export interface PublishingDurableJournal {
|
|
51
|
+
readonly supportsClosedReleaseReplacement?: true;
|
|
52
|
+
listRecordIdentities?(input: {
|
|
53
|
+
prefix: string;
|
|
54
|
+
limit: number;
|
|
55
|
+
after?: string;
|
|
56
|
+
}, options?: {
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}): Promise<readonly PublishingRecordIdentity[]>;
|
|
59
|
+
recordCapacity(): {
|
|
60
|
+
used: number;
|
|
61
|
+
maximum: number;
|
|
62
|
+
};
|
|
63
|
+
load(key: string, options?: {
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
revision: number;
|
|
67
|
+
payload: JsonValue;
|
|
68
|
+
} | undefined>;
|
|
69
|
+
readBlob(input: {
|
|
70
|
+
sha256: string;
|
|
71
|
+
byteLength: number;
|
|
72
|
+
}, options?: {
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
}): Promise<Uint8Array | undefined>;
|
|
75
|
+
compareAndSet(input: {
|
|
76
|
+
key: string;
|
|
77
|
+
expectedRevision: number;
|
|
78
|
+
payload: JsonValue;
|
|
79
|
+
blobs?: readonly {
|
|
80
|
+
sha256: string;
|
|
81
|
+
bytes: Uint8Array;
|
|
82
|
+
}[];
|
|
83
|
+
replaceClosed?: PublishingClosedRequestReplacement;
|
|
84
|
+
}, options?: {
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
authority?: PublishingMutationAuthority;
|
|
87
|
+
dispatch?: PublishingDispatch;
|
|
88
|
+
}): Promise<'stored' | 'conflict'>;
|
|
89
|
+
operationJournal(): ArtifactOperationJournal;
|
|
90
|
+
enqueue(input: PublishingDispatch, options?: {
|
|
91
|
+
signal?: AbortSignal;
|
|
92
|
+
authority?: PublishingMutationAuthority;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
nextWake(): number | null;
|
|
95
|
+
take(): Promise<PublishingQueueLease | null>;
|
|
96
|
+
finish(job: PublishingQueueLease, options?: {
|
|
97
|
+
again?: boolean;
|
|
98
|
+
delayMs?: number;
|
|
99
|
+
mode?: 'perform' | 'observe';
|
|
100
|
+
advance?: boolean;
|
|
101
|
+
observations?: number;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
withIngress<T>(work: () => Promise<T>): Promise<T>;
|
|
104
|
+
withProjectLock<T>(input: {
|
|
105
|
+
projectId: string;
|
|
106
|
+
requestId: string;
|
|
107
|
+
mode?: 'perform' | 'observe';
|
|
108
|
+
signal?: AbortSignal;
|
|
109
|
+
}, work: (lease: {
|
|
110
|
+
signal: AbortSignal;
|
|
111
|
+
assertHeld(): Promise<void>;
|
|
112
|
+
beginOperation(): void;
|
|
113
|
+
confirmClosure(closure: ArtifactTransportClosure | undefined): void;
|
|
114
|
+
}) => Promise<T>): Promise<T>;
|
|
115
|
+
readonly blocked: boolean;
|
|
116
|
+
readonly running: boolean;
|
|
117
|
+
close(): void;
|
|
118
|
+
}
|
|
119
|
+
type PublishingJournalOptions = {
|
|
120
|
+
storage: PublishingDurableStorage;
|
|
121
|
+
identity: string;
|
|
122
|
+
limits: PublishingDurableLimits;
|
|
123
|
+
now?: () => number;
|
|
124
|
+
leaseMs?: number;
|
|
125
|
+
increaseMaximumRecordsTo?: number;
|
|
126
|
+
};
|
|
127
|
+
/** The platform owns storage. This adapter owns opaque immutable chunks, real SQL CAS and fenced turns. */
|
|
128
|
+
export declare function openPublishingDurableJournal({ storage, identity, limits: inputLimits, now, leaseMs, increaseMaximumRecordsTo }: PublishingJournalOptions): Promise<PublishingDurableJournal>;
|
|
129
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsonSnapshot, objectRecord, operationRecord } from '../shared/records.js';
|
|
2
|
+
import { reclaimClosedRecords, reclaimUnreferencedPackageBlobs } from './durable-retention.js';
|
|
2
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
5
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -70,6 +71,8 @@ export async function openPublishingDurableJournal({ storage, identity, limits:
|
|
|
70
71
|
'CREATE TABLE IF NOT EXISTS publishing_metadata(id INTEGER PRIMARY KEY CHECK(id=1),configuration TEXT NOT NULL)',
|
|
71
72
|
'CREATE TABLE IF NOT EXISTS publishing_records(key TEXT PRIMARY KEY,revision INTEGER NOT NULL,payload TEXT NOT NULL,checksum TEXT NOT NULL,size INTEGER NOT NULL)',
|
|
72
73
|
'CREATE TABLE IF NOT EXISTS publishing_blobs(sha256 TEXT PRIMARY KEY,length INTEGER NOT NULL,bytes BLOB NOT NULL,size INTEGER NOT NULL)',
|
|
74
|
+
'CREATE TABLE IF NOT EXISTS publishing_managed_blobs(sha256 TEXT PRIMARY KEY)',
|
|
75
|
+
'CREATE TRIGGER IF NOT EXISTS publishing_blob_release AFTER DELETE ON publishing_blobs BEGIN DELETE FROM publishing_managed_blobs WHERE sha256=OLD.sha256; END',
|
|
73
76
|
'CREATE TABLE IF NOT EXISTS publishing_queue(project TEXT PRIMARY KEY,request TEXT NOT NULL,mode TEXT NOT NULL,advance INTEGER NOT NULL,revision INTEGER NOT NULL,next_at INTEGER NOT NULL,lease_until INTEGER,observations INTEGER NOT NULL,receipt_wake INTEGER NOT NULL DEFAULT 0)',
|
|
74
77
|
'CREATE TABLE IF NOT EXISTS publishing_leases(project TEXT PRIMARY KEY,request TEXT NOT NULL,intent TEXT NOT NULL,revision INTEGER NOT NULL,owner TEXT NOT NULL,until_ms INTEGER NOT NULL)'
|
|
75
78
|
])
|
|
@@ -149,6 +152,18 @@ export async function openPublishingDurableJournal({ storage, identity, limits:
|
|
|
149
152
|
const queuedState = (state, mode) => state !== undefined && (['queued', 'deploying'].includes(state) || mode === 'observe' && ['unknown', 'awaiting-acceptance'].includes(state));
|
|
150
153
|
const admissible = (row) => { const project = projectFor(row.project), item = project?.requests.find(item => item.intent.requestId === row.request); return !!project && !!item && !project.policy.disabled && project.policy.policyRevision === item.intent.policyRevision && queuedState(item.state, row.mode); };
|
|
151
154
|
const api = {
|
|
155
|
+
supportsClosedReleaseReplacement: true,
|
|
156
|
+
async listRecordIdentities({ prefix, limit, after }, { signal } = {}) {
|
|
157
|
+
check(signal);
|
|
158
|
+
if (!keyValid(prefix) || !positive(limit, 256) || after !== undefined && (!keyValid(after) || !after.startsWith(prefix)))
|
|
159
|
+
throw fail('KEY_INVALID');
|
|
160
|
+
const selected = rows('SELECT key,revision FROM publishing_records WHERE key>=? AND key<? AND key>? ORDER BY key LIMIT ?', prefix, prefix + '\uffff', after ?? '', limit);
|
|
161
|
+
return selected.map(row => {
|
|
162
|
+
if (typeof row.key !== 'string')
|
|
163
|
+
throw fail('CORRUPT');
|
|
164
|
+
return { key: row.key, revision: numberField(row, 'revision') };
|
|
165
|
+
});
|
|
166
|
+
},
|
|
152
167
|
recordCapacity() { ready(); return { used: usage().records, maximum: limits.maximumRecords }; },
|
|
153
168
|
async load(key, { signal } = {}) { check(signal); if (!keyValid(key))
|
|
154
169
|
throw fail('KEY_INVALID'); return read(key); },
|
|
@@ -156,7 +171,7 @@ export async function openPublishingDurableJournal({ storage, identity, limits:
|
|
|
156
171
|
throw fail('BLOB_INVALID'); const row = one('SELECT length,bytes FROM publishing_blobs WHERE sha256=?', sha256); if (!row)
|
|
157
172
|
return; const bytes = blobBytes(row.bytes); if (row.length !== byteLength || bytes.length !== byteLength || hash(bytes) !== sha256)
|
|
158
173
|
throw fail('BLOB_CHANGED'); return bytes; },
|
|
159
|
-
async compareAndSet({ key, expectedRevision, payload, blobs = [] }, { signal, authority = context.getStore(), dispatch } = {}) {
|
|
174
|
+
async compareAndSet({ key, expectedRevision, payload, blobs = [], replaceClosed }, { signal, authority = context.getStore(), dispatch } = {}) {
|
|
160
175
|
check(signal);
|
|
161
176
|
if (!keyValid(key) || !Number.isSafeInteger(expectedRevision) || expectedRevision < 0 || expectedRevision >= Number.MAX_SAFE_INTEGER || !Array.isArray(blobs) || blobs.length > limits.maximumBlobs)
|
|
162
177
|
throw fail('RECORD_INVALID');
|
|
@@ -172,22 +187,34 @@ export async function openPublishingDurableJournal({ storage, identity, limits:
|
|
|
172
187
|
if ((previous?.revision ?? 0) !== expectedRevision)
|
|
173
188
|
return 'conflict';
|
|
174
189
|
authorize(authority, key, snapshot);
|
|
190
|
+
const projectUpload = authority?.kind === 'request' && key === 'project:' + authority.projectId;
|
|
191
|
+
let retiredDigests = [];
|
|
192
|
+
if (replaceClosed !== undefined) {
|
|
193
|
+
if (!projectUpload || !previous || dispatch)
|
|
194
|
+
throw fail('AUTHORITY_REQUIRED');
|
|
195
|
+
retiredDigests = reclaimClosedRecords(sql, authority.projectId, previous.payload, snapshot, replaceClosed, now(), limits.maximumRecords);
|
|
196
|
+
}
|
|
175
197
|
for (const part of parts) {
|
|
176
198
|
const existing = one('SELECT length,bytes FROM publishing_blobs WHERE sha256=?', part.sha256);
|
|
177
199
|
if (existing) {
|
|
178
200
|
const bytes = blobBytes(existing.bytes);
|
|
179
201
|
if (existing.length !== part.bytes.length || !Buffer.from(bytes).equals(part.bytes))
|
|
180
202
|
throw fail('BLOB_CHANGED');
|
|
203
|
+
if (!projectUpload)
|
|
204
|
+
sql.exec('DELETE FROM publishing_managed_blobs WHERE sha256=?', part.sha256);
|
|
181
205
|
}
|
|
182
|
-
else
|
|
206
|
+
else {
|
|
183
207
|
sql.exec('INSERT INTO publishing_blobs VALUES(?,?,?,?)', part.sha256, part.bytes.length, part.bytes.buffer, part.bytes.length + 128);
|
|
208
|
+
if (projectUpload)
|
|
209
|
+
sql.exec('INSERT INTO publishing_managed_blobs VALUES(?)', part.sha256);
|
|
210
|
+
}
|
|
184
211
|
}
|
|
185
|
-
|
|
186
|
-
if (counts.blobs > limits.maximumBlobs)
|
|
187
|
-
throw fail('BLOB_LIMIT');
|
|
188
|
-
if (!previous && counts.records >= limits.maximumRecords)
|
|
212
|
+
if (!previous && usage().records >= limits.maximumRecords)
|
|
189
213
|
throw fail('RECORD_LIMIT');
|
|
190
214
|
sql.exec('INSERT INTO publishing_records VALUES(?,?,?,?,?) ON CONFLICT(key) DO UPDATE SET revision=excluded.revision,payload=excluded.payload,checksum=excluded.checksum,size=excluded.size', key, expectedRevision + 1, text, hash(text), Buffer.byteLength(text) + Buffer.byteLength(key) + 128);
|
|
215
|
+
reclaimUnreferencedPackageBlobs(sql, retiredDigests);
|
|
216
|
+
if (usage().blobs > limits.maximumBlobs)
|
|
217
|
+
throw fail('BLOB_LIMIT');
|
|
191
218
|
if (dispatch)
|
|
192
219
|
enqueueInside(dispatch, authority);
|
|
193
220
|
return 'stored';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ArtifactContentIdentity, ArtifactContentManifest, ArtifactContentManifestFile } from '@openge/forge-artifact-publish';
|
|
2
|
+
import type { SolutionPackageDescriptor, SolutionPackageLimits } from '../package.js';
|
|
3
|
+
import type { PublishingIntent } from '../protocol.js';
|
|
4
|
+
export interface PublishingContentReader {
|
|
5
|
+
readFile(path: string, input: {
|
|
6
|
+
maximumBytes: number;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}): Promise<Uint8Array>;
|
|
9
|
+
streamFile(path: string, input?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}): AsyncIterable<Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
export interface PreparedPublishingPackage extends PublishingContentReader {
|
|
14
|
+
readonly descriptor: SolutionPackageDescriptor;
|
|
15
|
+
readonly content: ArtifactContentIdentity;
|
|
16
|
+
readonly manifest: ArtifactContentManifest;
|
|
17
|
+
readonly manifestBytes: Uint8Array;
|
|
18
|
+
readonly files: readonly ArtifactContentManifestFile[];
|
|
19
|
+
readonly payloadBytes: number;
|
|
20
|
+
verifyBatch(input?: {
|
|
21
|
+
cursor?: number;
|
|
22
|
+
maximumFiles?: number;
|
|
23
|
+
maximumBytes?: number;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
cursor: number;
|
|
27
|
+
complete: boolean;
|
|
28
|
+
verifiedBytes: number;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export interface PublishingPackageRecord {
|
|
32
|
+
intent: PublishingIntent;
|
|
33
|
+
manifestByteLength: number;
|
|
34
|
+
files: {
|
|
35
|
+
sha256: string;
|
|
36
|
+
byteLength: number;
|
|
37
|
+
receivedBytes: number;
|
|
38
|
+
chunks: {
|
|
39
|
+
sha256: string;
|
|
40
|
+
byteLength: number;
|
|
41
|
+
}[];
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
type OpenPackageOptions = {
|
|
45
|
+
journal: {
|
|
46
|
+
readBlob(input: {
|
|
47
|
+
sha256: string;
|
|
48
|
+
byteLength: number;
|
|
49
|
+
}, options?: {
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}): Promise<Uint8Array | undefined>;
|
|
52
|
+
};
|
|
53
|
+
item: PublishingPackageRecord;
|
|
54
|
+
limits: SolutionPackageLimits;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
};
|
|
57
|
+
export declare const publishingChunkBytes = 1048576, publishingReadFileBytes = 16777216;
|
|
58
|
+
/** A declaration-only snapshot. Only one bounded chunk is loaded by the stream at a time. */
|
|
59
|
+
export declare function openPreparedPublishingPackage({ journal, item, limits: inputLimits, signal }: OpenPackageOptions): Promise<PreparedPublishingPackage>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JsonValue } from '@xlinklight/contracts';
|
|
2
|
+
import type { PublishingPackageRecord } from './package.js';
|
|
3
|
+
type Mutable<T> = T extends readonly (infer E)[] ? Mutable<E>[] : T extends object ? {
|
|
4
|
+
[K in keyof T]: Mutable<T[K]>;
|
|
5
|
+
} : T;
|
|
6
|
+
type Validation = {
|
|
7
|
+
manifestSha256: string;
|
|
8
|
+
intentSha256: string;
|
|
9
|
+
policySha256: string;
|
|
10
|
+
cursor: number;
|
|
11
|
+
};
|
|
12
|
+
export type Execution = {
|
|
13
|
+
schemaVersion: 1;
|
|
14
|
+
planSha256: string;
|
|
15
|
+
completed: {
|
|
16
|
+
name: string;
|
|
17
|
+
output: JsonValue;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
export type StoredRequest = Mutable<PublishingPackageRecord> & {
|
|
21
|
+
intentSha256: string;
|
|
22
|
+
state: string;
|
|
23
|
+
sideEffects: string;
|
|
24
|
+
validation?: Validation;
|
|
25
|
+
execution?: Execution;
|
|
26
|
+
activation?: JsonValue;
|
|
27
|
+
error?: {
|
|
28
|
+
code: string;
|
|
29
|
+
};
|
|
30
|
+
receiptOnly?: true;
|
|
31
|
+
};
|
|
32
|
+
export declare function closedRelease(request: StoredRequest): boolean;
|
|
33
|
+
export declare function releaseReceipts(requests: readonly StoredRequest[]): StoredRequest[];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { publishingError } from '../protocol.js';
|
|
2
|
+
import { newerVersion } from '../shared/release-version.js';
|
|
3
|
+
export function closedRelease(request) {
|
|
4
|
+
return request.sideEffects === 'closed' && ['active', 'failed', 'superseded', 'abandoned'].includes(request.state);
|
|
5
|
+
}
|
|
6
|
+
export function releaseReceipts(requests) {
|
|
7
|
+
let active, latest;
|
|
8
|
+
for (const request of requests) {
|
|
9
|
+
if (!closedRelease(request))
|
|
10
|
+
throw publishingError('CONFLICT');
|
|
11
|
+
if (request.state === 'active') {
|
|
12
|
+
if (!request.activation)
|
|
13
|
+
throw publishingError('UNKNOWN_EFFECTS');
|
|
14
|
+
if (!active || newerVersion(request.intent.package.version, active.intent.package.version))
|
|
15
|
+
active = request;
|
|
16
|
+
}
|
|
17
|
+
if (!latest || newerVersion(request.intent.package.version, latest.intent.package.version))
|
|
18
|
+
latest = request;
|
|
19
|
+
}
|
|
20
|
+
// Keep the live activation while its successor is checked. The latest
|
|
21
|
+
// closed attempt also supplies the version floor if that attempt failed.
|
|
22
|
+
const retained = [...new Set([active, latest])].filter((item) => item !== undefined);
|
|
23
|
+
return retained.map(({ intent, intentSha256, state, sideEffects, activation, error }) => ({
|
|
24
|
+
intent, intentSha256, state, sideEffects, manifestByteLength: 0, files: [], receiptOnly: true,
|
|
25
|
+
...(state === 'active' ? { activation } : {}), ...(error ? { error } : {})
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SolutionReleasePayload, TrustedPublisher, Digest } from '@xlinklight/contracts';
|
|
2
|
+
import type { PublishingConfiguration } from '../protocol.js';
|
|
3
|
+
import type { SolutionPackageLimits } from '../package.js';
|
|
4
|
+
import type { PreparedPublishingPackage } from './package.js';
|
|
5
|
+
type PrepareReleaseOptions = {
|
|
6
|
+
prepared: Pick<PreparedPublishingPackage, 'descriptor' | 'content' | 'manifest' | 'manifestBytes' | 'payloadBytes' | 'readFile' | 'streamFile'>;
|
|
7
|
+
configuration: PublishingConfiguration;
|
|
8
|
+
serverUrl: string;
|
|
9
|
+
uiUrl: string;
|
|
10
|
+
serverReceiptPath: string;
|
|
11
|
+
uiReceiptPath: string;
|
|
12
|
+
limits: SolutionPackageLimits;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
};
|
|
15
|
+
type PreparedRelease = Promise<{
|
|
16
|
+
payload: Readonly<SolutionReleasePayload>;
|
|
17
|
+
releaseDigest: Digest;
|
|
18
|
+
publisher: TrustedPublisher;
|
|
19
|
+
}>;
|
|
20
|
+
/** The service has already verified this immutable lazy snapshot in bounded batches. */
|
|
21
|
+
export declare function preparePublishingRelease({ prepared, configuration: config, serverUrl, uiUrl, serverReceiptPath, uiReceiptPath, limits: inputLimits, signal: inputSignal }: PrepareReleaseOptions): PreparedRelease;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PublishingDurableJournal, PublishingDurableStorage } from './journal.js';
|
|
2
|
+
import type { PublishingService, PublishingWorkerResult } from './service.js';
|
|
3
|
+
export interface PublishingDurableContext {
|
|
4
|
+
storage: PublishingDurableStorage & {
|
|
5
|
+
getAlarm(): Promise<number | null>;
|
|
6
|
+
setAlarm(time: number): Promise<void>;
|
|
7
|
+
deleteAlarm(): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
abort(message: string): void;
|
|
10
|
+
}
|
|
11
|
+
type DurableRuntimeOptions = {
|
|
12
|
+
ctx: PublishingDurableContext;
|
|
13
|
+
journal: PublishingDurableJournal;
|
|
14
|
+
service: PublishingService;
|
|
15
|
+
worker: {
|
|
16
|
+
run(input: {
|
|
17
|
+
projectId: string;
|
|
18
|
+
requestId: string;
|
|
19
|
+
mode: 'perform' | 'observe';
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
}): Promise<PublishingWorkerResult>;
|
|
22
|
+
};
|
|
23
|
+
now?: () => number;
|
|
24
|
+
limits?: {
|
|
25
|
+
pollMs: number;
|
|
26
|
+
jobMs: number;
|
|
27
|
+
maximumPolls?: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
type DurableRuntime = {
|
|
31
|
+
schedule(): Promise<void>;
|
|
32
|
+
run(): Promise<PublishingWorkerResult | {
|
|
33
|
+
state: 'idle' | 'busy';
|
|
34
|
+
}>;
|
|
35
|
+
alarm(): Promise<PublishingWorkerResult | {
|
|
36
|
+
state: 'idle' | 'busy';
|
|
37
|
+
}>;
|
|
38
|
+
fetch(request: Request): Promise<Response>;
|
|
39
|
+
status(): {
|
|
40
|
+
running: boolean;
|
|
41
|
+
blocked: boolean;
|
|
42
|
+
nextWake: number | null;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** One alarm owns one finite verification batch or original provider operation. */
|
|
46
|
+
export declare function createPublishingDurableRuntime({ ctx, journal, service, worker, now, limits }: DurableRuntimeOptions): DurableRuntime;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { JsonValue } from '@xlinklight/contracts';
|
|
2
|
+
import type { ArtifactOperationTransport, ArtifactOperationRecord, ArtifactOperationReceipt, ArtifactOperationCapability } from '@openge/forge-artifact-publish';
|
|
3
|
+
import type { PublishingConfiguration, PublishingIntent, PublishingMetadataTransport } from '../protocol.js';
|
|
4
|
+
import type { SolutionPackageLimits } from '../package.js';
|
|
5
|
+
import type { PublishingDurableJournal, PublishingDispatch, PublishingRecordIdentity } from './journal.js';
|
|
6
|
+
import type { PreparedPublishingPackage } from './package.js';
|
|
7
|
+
export interface PublishingProjectPolicy {
|
|
8
|
+
schemaVersion: 1;
|
|
9
|
+
configuration: PublishingConfiguration;
|
|
10
|
+
policyRevision: number;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
solutionId: string;
|
|
13
|
+
packageName: string;
|
|
14
|
+
limits: SolutionPackageLimits;
|
|
15
|
+
maximumRequests: number;
|
|
16
|
+
}
|
|
17
|
+
export interface PublishingServiceLimits {
|
|
18
|
+
requestMs: number;
|
|
19
|
+
maximumChunkBytes: number;
|
|
20
|
+
maximumChunks: number;
|
|
21
|
+
}
|
|
22
|
+
export interface PublishingService {
|
|
23
|
+
handle(request: Request): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
/** A trusted hosting adapter may identify additional private records exclusively
|
|
26
|
+
* owned by this closed request. Read their exact revisions before returning them. */
|
|
27
|
+
export interface PublishingClosedReleaseRetention {
|
|
28
|
+
recordsForRequest(input: {
|
|
29
|
+
intent: PublishingIntent;
|
|
30
|
+
completedStages: readonly {
|
|
31
|
+
name: string;
|
|
32
|
+
output: JsonValue;
|
|
33
|
+
}[];
|
|
34
|
+
}): readonly PublishingRecordIdentity[] | Promise<readonly PublishingRecordIdentity[]>;
|
|
35
|
+
}
|
|
36
|
+
export interface PublishingProjectLease {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
assertHeld(): Promise<void>;
|
|
39
|
+
beginOperation?(): void;
|
|
40
|
+
confirmClosure?(closure: import('@openge/forge-artifact-publish').ArtifactTransportClosure | undefined): void;
|
|
41
|
+
}
|
|
42
|
+
export interface PublishingDeploymentStage {
|
|
43
|
+
name: string;
|
|
44
|
+
capability: ArtifactOperationCapability;
|
|
45
|
+
configurationSha256: string;
|
|
46
|
+
/** A pending observation is woken by an authenticated completion receipt. */
|
|
47
|
+
waitForSignal?: boolean;
|
|
48
|
+
/** Synchronous pure factory: no resource or external effect may start before execute/observe. */
|
|
49
|
+
createDeployment(input: {
|
|
50
|
+
policy: PublishingProjectPolicy;
|
|
51
|
+
intent: PublishingIntent;
|
|
52
|
+
prepared: PreparedPublishingPackage;
|
|
53
|
+
previous: {
|
|
54
|
+
name: string;
|
|
55
|
+
output: unknown;
|
|
56
|
+
}[];
|
|
57
|
+
assertAuthorized(): Promise<void>;
|
|
58
|
+
signal: AbortSignal;
|
|
59
|
+
}): {
|
|
60
|
+
transport: ArtifactOperationTransport;
|
|
61
|
+
/** Synchronously extract a <=64 KiB JSON snapshot already observed inside
|
|
62
|
+
* the transport lifecycle. No additional I/O or asynchronous work. The final
|
|
63
|
+
* activation requires actual acceptance before its owner signs it. */
|
|
64
|
+
readResult(input: {
|
|
65
|
+
record: ArtifactOperationRecord;
|
|
66
|
+
}): unknown;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export interface PublishingWorkerOptions {
|
|
70
|
+
journal: PublishingDurableJournal;
|
|
71
|
+
/** Actual exclusive cross-process project lock, held through callback closure.
|
|
72
|
+
* Abort/fence the lease if storage ownership or connection is lost. */
|
|
73
|
+
withProjectLock<T>(input: {
|
|
74
|
+
projectId: string;
|
|
75
|
+
requestId: string;
|
|
76
|
+
mode: 'perform' | 'observe';
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}, work: (lease: PublishingProjectLease) => Promise<T>): Promise<T>;
|
|
79
|
+
stages: readonly PublishingDeploymentStage[];
|
|
80
|
+
allowLoopback?: boolean;
|
|
81
|
+
metadataTransport?: PublishingMetadataTransport;
|
|
82
|
+
verifyActivation?: typeof import('./activation.js').verifyPublishingActivation;
|
|
83
|
+
operationLimits?: {
|
|
84
|
+
timeoutMilliseconds: number;
|
|
85
|
+
closeTimeoutMilliseconds: number;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface PublishingWorkerResult {
|
|
89
|
+
requestId: string;
|
|
90
|
+
state: string;
|
|
91
|
+
sideEffects: string;
|
|
92
|
+
receipt?: ArtifactOperationReceipt;
|
|
93
|
+
next?: 'perform' | 'verify';
|
|
94
|
+
}
|
|
95
|
+
type ConfigureProjectOptions = {
|
|
96
|
+
journal: PublishingDurableJournal;
|
|
97
|
+
policy: PublishingProjectPolicy;
|
|
98
|
+
credential: string;
|
|
99
|
+
expectedRevision: number;
|
|
100
|
+
allowLoopback?: boolean;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
};
|
|
103
|
+
type PublishingServiceOptions = {
|
|
104
|
+
journal: PublishingDurableJournal;
|
|
105
|
+
allowLoopback?: boolean;
|
|
106
|
+
limits?: PublishingServiceLimits;
|
|
107
|
+
onDispatch?: (input: PublishingDispatch) => void | Promise<void>;
|
|
108
|
+
replaceClosedReleases?: boolean | PublishingClosedReleaseRetention;
|
|
109
|
+
};
|
|
110
|
+
type PublishingWorker = {
|
|
111
|
+
run(input: {
|
|
112
|
+
projectId: string;
|
|
113
|
+
requestId: string;
|
|
114
|
+
mode?: 'perform' | 'observe';
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
}): Promise<PublishingWorkerResult>;
|
|
117
|
+
};
|
|
118
|
+
export declare function configurePublishingProject({ journal, policy: input, credential, expectedRevision, allowLoopback, signal }: ConfigureProjectOptions): Promise<{
|
|
119
|
+
revision: number;
|
|
120
|
+
}>;
|
|
121
|
+
/** HTTP admission and upload queue only. A separately fenced worker owns deployments. */
|
|
122
|
+
export declare function createPublishingService({ journal, allowLoopback, limits, onDispatch, replaceClosedReleases }: PublishingServiceOptions): PublishingService;
|
|
123
|
+
/** One explicitly invoked worker operation. The host supplies a real distributed
|
|
124
|
+
* project lock and an installed deployment adapter; uploaded code stays opaque.
|
|
125
|
+
* Factories and readResult are read-only. Each external step has its own public
|
|
126
|
+
* Foundation operation; recovering a step never dispatches a later step. */
|
|
127
|
+
export declare function createPublishingWorker({ journal, withProjectLock, stages: inputStages, allowLoopback, metadataTransport, verifyActivation, operationLimits }: PublishingWorkerOptions): PublishingWorker;
|
|
128
|
+
export {};
|