@xlinklight/publishing 3.3.0 → 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 +23 -3
- package/dist/src/acceptance-delivery-binding.d.ts +20 -0
- package/dist/src/acceptance-delivery-binding.js +59 -0
- package/dist/src/acceptance.d.ts +49 -0
- package/dist/src/acceptance.js +79 -0
- package/dist/src/client.d.ts +71 -0
- package/dist/src/client.js +146 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +3 -0
- package/dist/src/node/acceptance-delivery.d.ts +34 -0
- package/dist/src/node/acceptance-delivery.js +88 -0
- package/dist/src/node/activation.d.ts +5 -0
- package/dist/src/node/activation.js +3 -0
- package/dist/src/node/authorization.d.ts +31 -0
- package/dist/src/node/authorization.js +76 -0
- package/dist/src/node/cli.d.ts +2 -0
- package/dist/src/node/cli.js +22 -0
- package/dist/src/node/index.d.ts +20 -0
- package/dist/src/node/index.js +11 -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 +280 -0
- 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 +268 -0
- package/dist/src/node/session.d.ts +95 -0
- package/dist/src/node/session.js +223 -0
- package/dist/src/node/solution-package.d.ts +55 -0
- package/dist/src/node/solution-package.js +217 -0
- package/dist/src/node/source-error.d.ts +10 -0
- package/dist/src/node/source-error.js +15 -0
- package/dist/src/node/source-producer.d.ts +5 -0
- package/dist/src/node/source-producer.js +145 -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 +467 -0
- package/dist/src/package.d.ts +38 -0
- package/dist/src/package.js +74 -0
- package/dist/src/protocol.d.ts +83 -0
- package/dist/src/protocol.js +105 -0
- 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/activation.js +111 -0
- package/dist/src/shared/records.d.ts +10 -0
- package/dist/src/shared/records.js +26 -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 +11 -0
- 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 +7 -0
- package/dist/src/worker/journal.d.ts +129 -0
- package/dist/src/worker/journal.js +328 -0
- package/dist/src/worker/package.d.ts +60 -0
- package/dist/src/worker/package.js +116 -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/release.js +59 -0
- package/dist/src/worker/runtime.d.ts +47 -0
- package/dist/src/worker/runtime.js +98 -0
- package/dist/src/worker/service.d.ts +128 -0
- package/dist/src/worker/service.js +520 -0
- package/package.json +23 -14
- package/src/acceptance-delivery-binding.mjs +0 -49
- package/src/acceptance.d.mts +0 -24
- package/src/acceptance.mjs +0 -67
- package/src/client.d.mts +0 -16
- package/src/client.mjs +0 -74
- package/src/index.d.mts +0 -6
- package/src/index.mjs +0 -3
- package/src/node/acceptance-delivery.d.mts +0 -11
- package/src/node/acceptance-delivery.mjs +0 -70
- package/src/node/activation.d.mts +0 -8
- package/src/node/activation.mjs +0 -3
- package/src/node/authorization.d.mts +0 -8
- package/src/node/authorization.mjs +0 -49
- package/src/node/cli.mjs +0 -12
- package/src/node/index.d.mts +0 -17
- package/src/node/index.mjs +0 -9
- package/src/node/journal.d.mts +0 -13
- package/src/node/journal.mjs +0 -135
- package/src/node/publishing-command.d.mts +0 -20
- package/src/node/publishing-command.mjs +0 -104
- package/src/node/session.d.mts +0 -25
- package/src/node/session.mjs +0 -134
- package/src/node/solution-package.d.mts +0 -15
- package/src/node/solution-package.mjs +0 -113
- package/src/node/source-error.d.mts +0 -5
- package/src/node/source-error.mjs +0 -9
- package/src/node/source-producer.mjs +0 -103
- package/src/node/workflow.d.mts +0 -37
- package/src/node/workflow.mjs +0 -320
- package/src/package.d.mts +0 -11
- package/src/package.mjs +0 -36
- package/src/protocol.d.mts +0 -27
- package/src/protocol.mjs +0 -50
- package/src/shared/activation.d.mts +0 -5
- package/src/shared/activation.mjs +0 -64
- package/src/worker/activation.d.mts +0 -7
- package/src/worker/activation.mjs +0 -4
- package/src/worker/index.d.mts +0 -6
- package/src/worker/index.mjs +0 -6
- package/src/worker/journal.d.mts +0 -21
- package/src/worker/journal.mjs +0 -151
- package/src/worker/package.d.mts +0 -16
- package/src/worker/package.mjs +0 -32
- package/src/worker/release.d.mts +0 -7
- package/src/worker/release.mjs +0 -21
- package/src/worker/runtime.d.mts +0 -4
- package/src/worker/runtime.mjs +0 -23
- package/src/worker/service.d.mts +0 -41
- package/src/worker/service.mjs +0 -251
|
@@ -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,59 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { publicPublisherMetadata, validateSolutionReleasePayload, solutionReleaseDigest } from '@xlinklight/platform/worker';
|
|
3
|
+
import { parsePublishingConfiguration, publishingError } from '../protocol.js';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { createArtifactContentManifest } from '@openge/forge-artifact-publish';
|
|
6
|
+
import { parseSolutionPackageDescriptor, parseSolutionPackageLimits } from '../package.js';
|
|
7
|
+
const fail = (code) => publishingError('RELEASE_' + code);
|
|
8
|
+
function address(value) { try {
|
|
9
|
+
if (typeof value !== 'string' || value.length > 2048 || value.includes('?') || value.includes('#'))
|
|
10
|
+
throw Error();
|
|
11
|
+
const url = new URL(value);
|
|
12
|
+
if (url.protocol !== 'https:' || url.href !== value || url.username || url.password)
|
|
13
|
+
throw Error();
|
|
14
|
+
return url;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw fail('URL_INVALID');
|
|
18
|
+
} }
|
|
19
|
+
/** The service has already verified this immutable lazy snapshot in bounded batches. */
|
|
20
|
+
export async function preparePublishingRelease({ prepared, configuration: config, serverUrl, uiUrl, serverReceiptPath, uiReceiptPath, limits: inputLimits, signal: inputSignal }) {
|
|
21
|
+
const limits = parseSolutionPackageLimits(inputLimits), signal = AbortSignal.any([inputSignal, AbortSignal.timeout(limits.timeoutMs)].filter(s => s !== undefined));
|
|
22
|
+
signal.throwIfAborted();
|
|
23
|
+
const configuration = parsePublishingConfiguration(config), server = address(serverUrl), ui = address(uiUrl);
|
|
24
|
+
if (server.origin === configuration.coreOrigin || ui.origin === configuration.coreOrigin || typeof prepared?.readFile !== 'function' || typeof serverReceiptPath !== 'string' || !serverReceiptPath.startsWith('server/') || typeof uiReceiptPath !== 'string' || !uiReceiptPath.startsWith('ui/'))
|
|
25
|
+
throw fail('BINDING_INVALID');
|
|
26
|
+
const { descriptor } = prepared;
|
|
27
|
+
if (descriptor.publisherId !== configuration.publisher.publisherId)
|
|
28
|
+
throw fail('BINDING_INVALID');
|
|
29
|
+
try {
|
|
30
|
+
if (!(prepared.manifestBytes instanceof Uint8Array) || prepared.manifestBytes.byteLength > limits.maximumManifestBytes || prepared.manifest.files.length > limits.maximumFiles || prepared.manifest.files.some(file => file.byteLength > limits.maximumFileBytes))
|
|
31
|
+
throw Error();
|
|
32
|
+
const canonical = await createArtifactContentManifest(prepared.manifest), total = prepared.manifest.files.reduce((sum, file) => sum + file.byteLength, 0);
|
|
33
|
+
if (!isDeepStrictEqual(canonical.content, prepared.content) || !Buffer.from(canonical.bytes).equals(prepared.manifestBytes) || total !== prepared.payloadBytes || total + canonical.bytes.byteLength > limits.maximumTotalBytes)
|
|
34
|
+
throw Error();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw fail('PACKAGE_INVALID');
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const original = parseSolutionPackageDescriptor(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(await prepared.readFile('solution.json', { maximumBytes: 1048576, signal }))));
|
|
41
|
+
if (!isDeepStrictEqual(original, descriptor))
|
|
42
|
+
throw Error();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw fail('PACKAGE_INVALID');
|
|
46
|
+
}
|
|
47
|
+
const receipt = async (path, role) => { if (prepared.manifest.files.find(file => file.path === path)?.role !== role)
|
|
48
|
+
throw fail('RECEIPT_INVALID'); return 'sha256:' + createHash('sha256').update(await prepared.readFile(path, { maximumBytes: 1048576, signal })).digest('hex'); };
|
|
49
|
+
const uiDigest = await receipt(uiReceiptPath, 'asset'), serverDigest = await receipt(serverReceiptPath, 'control');
|
|
50
|
+
signal?.throwIfAborted();
|
|
51
|
+
try {
|
|
52
|
+
const publisher = publicPublisherMetadata({ ...configuration.publisher, enabled: true, serverOrigins: [server.origin], uiOrigins: [ui.origin] }), { resourcesDigest, ...declarations } = descriptor.release;
|
|
53
|
+
const payload = validateSolutionReleasePayload({ schemaVersion: 1, solutionId: descriptor.solutionId, publisherId: descriptor.publisherId, version: descriptor.version, sdkApiVersion: descriptor.sdkApiVersion, server: { url: serverUrl, protocolVersion: descriptor.runtime.protocolVersion }, ui: { url: uiUrl, integrity: uiDigest, bridgeVersion: descriptor.ui.bridgeVersion }, artifacts: { server: serverDigest, resources: resourcesDigest }, ...declarations }, publisher);
|
|
54
|
+
return { payload, releaseDigest: solutionReleaseDigest(payload), publisher };
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw fail('DECLARATIONS_INVALID');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -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,98 @@
|
|
|
1
|
+
const fail = (code) => Error('PUBLISHING_RUNTIME_' + code);
|
|
2
|
+
/** One alarm owns one finite verification batch or original provider operation. */
|
|
3
|
+
export function createPublishingDurableRuntime({ ctx, journal, service, worker, now = Date.now, limits = { pollMs: 1000, jobMs: 60000 } }) {
|
|
4
|
+
const maximumPolls = limits.maximumPolls ?? 18;
|
|
5
|
+
if (!ctx?.storage || typeof ctx.abort !== 'function' || typeof service?.handle !== 'function' || typeof worker?.run !== 'function' || typeof journal?.take !== 'function' || !Number.isSafeInteger(limits.pollMs) || limits.pollMs < 1 || limits.pollMs > 30000 || !Number.isSafeInteger(limits.jobMs) || limits.jobMs < 1 || limits.jobMs > 300000 || !Number.isSafeInteger(maximumPolls) || maximumPolls < 1 || maximumPolls > 128)
|
|
6
|
+
throw fail('INPUT_INVALID');
|
|
7
|
+
let arming = Promise.resolve(), stepping = false, activeDeadline = 0;
|
|
8
|
+
const schedule = () => { const pending = arming.catch(() => { }).then(async () => { const next = journal.nextWake(), previous = await ctx.storage.getAlarm(); if (next === null) {
|
|
9
|
+
if (previous !== null) {
|
|
10
|
+
await ctx.storage.deleteAlarm();
|
|
11
|
+
await ctx.storage.sync();
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
} const wanted = Math.max(now() + 1, next, stepping ? activeDeadline : 0); if (previous === null || previous > wanted)
|
|
15
|
+
await ctx.storage.setAlarm(wanted); await ctx.storage.sync(); }); arming = pending; return pending; };
|
|
16
|
+
const reset = () => { if (journal.blocked)
|
|
17
|
+
ctx.abort('Publishing transport closure is unconfirmed; observe the durable original claim in a fresh actor'); };
|
|
18
|
+
const run = async () => {
|
|
19
|
+
if (stepping || journal.running)
|
|
20
|
+
return { state: 'busy' };
|
|
21
|
+
stepping = true;
|
|
22
|
+
activeDeadline = now() + limits.jobMs;
|
|
23
|
+
let job, completed, failure, failed = false;
|
|
24
|
+
try {
|
|
25
|
+
job = await journal.take();
|
|
26
|
+
if (!job)
|
|
27
|
+
return { state: 'idle' };
|
|
28
|
+
try {
|
|
29
|
+
completed = { value: await worker.run({ projectId: job.projectId, requestId: job.requestId, mode: job.mode, signal: AbortSignal.timeout(limits.jobMs) }) };
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
failed = true;
|
|
33
|
+
failure = error;
|
|
34
|
+
}
|
|
35
|
+
const value = completed?.value;
|
|
36
|
+
if (!journal.blocked) {
|
|
37
|
+
const progressing = value?.next === 'perform' || value?.next === 'verify', pending = value?.receipt?.outcome === 'pending' && value.state !== 'awaiting-acceptance', observations = pending ? (job.observations ?? 0) + (job.mode === 'observe' ? 1 : 0) : 0, next = job.continue && !failed && (progressing || pending && observations < maximumPolls);
|
|
38
|
+
try {
|
|
39
|
+
await journal.finish(job, { again: !!next, delayMs: limits.pollMs, mode: progressing ? 'perform' : 'observe', advance: job.continue, observations });
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
failure = failed ? new AggregateError([failure, error], 'PUBLISHING_RUNTIME_FINISH_FAILED', { cause: failure }) : error;
|
|
43
|
+
failed = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (failed || !completed)
|
|
47
|
+
throw failure;
|
|
48
|
+
return completed.value;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
stepping = false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
async function owned(work) {
|
|
55
|
+
let outcome;
|
|
56
|
+
try {
|
|
57
|
+
outcome = { ok: true, value: await work() };
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
outcome = { ok: false, failure: error };
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await schedule();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
outcome = { ok: false, failure: outcome.ok ? error : new AggregateError([outcome.failure, error], 'PUBLISHING_RUNTIME_SCHEDULE_FAILED', { cause: outcome.failure }) };
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
reset();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
outcome = { ok: false, failure: outcome.ok ? error : new AggregateError([outcome.failure, error], 'PUBLISHING_RUNTIME_RESET_FAILED', { cause: outcome.failure }) };
|
|
73
|
+
}
|
|
74
|
+
if (!outcome.ok)
|
|
75
|
+
throw outcome.failure;
|
|
76
|
+
return outcome.value;
|
|
77
|
+
}
|
|
78
|
+
return Object.freeze({ schedule, run: () => owned(run), alarm: () => owned(run), status: () => ({ running: stepping, blocked: journal.blocked, nextWake: journal.nextWake() }), fetch: request => owned(async () => {
|
|
79
|
+
if (request.method === 'GET' || request.method === 'HEAD')
|
|
80
|
+
return service.handle(request);
|
|
81
|
+
try {
|
|
82
|
+
return await journal.withIngress(() => service.handle(request));
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error instanceof Error && /BUSY$/.test(error.message)) {
|
|
86
|
+
let timer;
|
|
87
|
+
try {
|
|
88
|
+
await Promise.race([request.body?.cancel(), new Promise((_, reject) => { timer = setTimeout(() => reject(fail('BODY_CLOSE_UNCONFIRMED')), 1000); })]);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
}
|
|
93
|
+
return Response.json({ error: { code: 'BUSY' } }, { status: 409 });
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}) });
|
|
98
|
+
}
|
|
@@ -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 {};
|