@astrale-os/adapter-cloudflare 0.5.0-beta.218 → 0.5.0-beta.219

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 CHANGED
@@ -129,7 +129,8 @@ Node and inside a Worker (`fetch` and WebCrypto only).
129
129
  `observeScript`, `scriptSettings`, `scriptSecretNames`, `putScriptSecret`, `deleteScript`, and
130
130
  `createSigningIdentity` (WebCrypto Ed25519).
131
131
  - **Lifecycle.** `activateDeployment` (a label and its record, `WorkerRecord` of
132
- `@astrale-os/sdk/deployment/worker`, or `null`), `readRecord`, `promoteDeployment`,
132
+ `@astrale-os/sdk/deployment/worker`, or `null`; a withdrawn label is refused),
133
+ `readRecord`, `promoteDeployment`,
133
134
  `replaceSchedules`, two-phase retirement
134
135
  (`markRetired`, then `completeRetirement` once `retirementVisible` sees the dispatcher answer
135
136
  `DEPLOYMENT_RETIRED`), `waitForReadiness` through the public URL or a dispatch binding, and
@@ -1,14 +1,22 @@
1
1
  import type { WorkerRecord } from '@astrale-os/sdk/deployment/worker';
2
2
  import type { RoutingKv } from './kv.js';
3
+ import { WITHDRAWN } from './kv.js';
3
4
  /**
4
5
  * Activate one deployment: write `record:<label>`, which the dispatcher reads to route the label,
5
6
  * with the record its deployer publishes (opaque bytes and their media type, served verbatim at
6
7
  * `/.well-known/astrale/deployment.json`), or `null` for a deployment that publishes none. A
7
8
  * record never changes once published: one already there is kept and answered when it is the same
8
9
  * record (same media type, same bytes, or both none), and refused (`deployment-conflict`)
9
- * otherwise, without any write.
10
+ * otherwise, without any write. A withdrawn label is refused first (`deployment-retired`).
10
11
  */
11
12
  export declare function activateDeployment(kv: RoutingKv, label: string, record: WorkerRecord | null): Promise<WorkerRecord | null>;
13
+ /** The tombstone of a label: `withdrawn`, or undefined; any other value is refused. */
14
+ export declare function readRetirement(kv: RoutingKv, label: string): Promise<typeof WITHDRAWN | undefined>;
15
+ /**
16
+ * Refuse a withdrawn label (`deployment-retired`). A withdrawal is permanent and the tombstone
17
+ * outlives whatever else remembers the deployment, so a deploy asks it before writing anything.
18
+ */
19
+ export declare function refuseWithdrawn(kv: RoutingKv, label: string): Promise<void>;
12
20
  /**
13
21
  * The record a label was activated with: the record, `null` when the deployment publishes none,
14
22
  * or undefined when the label is not activated. A value whose metadata is not exactly
@@ -1,6 +1,6 @@
1
1
  import { parseDeploymentLabel } from '@astrale-os/sdk/deployment/address';
2
2
  import { acceptWorkerRecord, sameWorkerRecord } from '@astrale-os/sdk/deployment/worker';
3
- import { cronKey, currentKey, decodeCurrent, decodeSchedules, encodeSchedules, isLabelOf, recordKey, } from './kv.js';
3
+ import { cronKey, currentKey, decodeCurrent, decodeSchedules, encodeSchedules, isLabelOf, recordKey, retirementKey, WITHDRAWN, } from './kv.js';
4
4
  import { HostingRefusal } from './refusal.js';
5
5
  /** What `record:<label>` holds for a deployment that publishes no record: never served. */
6
6
  const NO_RECORD = new TextEncoder().encode('-');
@@ -10,11 +10,12 @@ const NO_RECORD = new TextEncoder().encode('-');
10
10
  * `/.well-known/astrale/deployment.json`), or `null` for a deployment that publishes none. A
11
11
  * record never changes once published: one already there is kept and answered when it is the same
12
12
  * record (same media type, same bytes, or both none), and refused (`deployment-conflict`)
13
- * otherwise, without any write.
13
+ * otherwise, without any write. A withdrawn label is refused first (`deployment-retired`).
14
14
  */
15
15
  export async function activateDeployment(kv, label, record) {
16
16
  parseDeploymentLabel(label);
17
17
  const published = record === null ? null : acceptWorkerRecord(record);
18
+ await refuseWithdrawn(kv, label);
18
19
  const stored = await readRecord(kv, label);
19
20
  if (stored !== undefined) {
20
21
  if (!sameRecord(stored, published)) {
@@ -27,6 +28,23 @@ export async function activateDeployment(kv, label, record) {
27
28
  });
28
29
  return published;
29
30
  }
31
+ /** The tombstone of a label: `withdrawn`, or undefined; any other value is refused. */
32
+ export async function readRetirement(kv, label) {
33
+ const value = await kv.get(retirementKey(label));
34
+ if (value === undefined || value === WITHDRAWN)
35
+ return value;
36
+ throw new HostingRefusal('retirement-invalid', `The tombstone of ${label} holds another value than ${WITHDRAWN}.`);
37
+ }
38
+ /**
39
+ * Refuse a withdrawn label (`deployment-retired`). A withdrawal is permanent and the tombstone
40
+ * outlives whatever else remembers the deployment, so a deploy asks it before writing anything.
41
+ */
42
+ export async function refuseWithdrawn(kv, label) {
43
+ if ((await readRetirement(kv, label)) === undefined)
44
+ return;
45
+ throw new HostingRefusal('deployment-retired', `${label} was withdrawn and is never served again; change the release to deploy another ` +
46
+ 'deployment.');
47
+ }
30
48
  /**
31
49
  * The record a label was activated with: the record, `null` when the deployment publishes none,
32
50
  * or undefined when the label is not activated. A value whose metadata is not exactly
@@ -20,8 +20,8 @@ export { CRON_PREFIX, cronKey, CURRENT_PREFIX, currentKey, decodeCurrent, decode
20
20
  export { ARTIFACT_TAG_PREFIX, artifactOf, ASSETS_BINDING, BUILD_DIGEST_BINDING, decodeScript, deleteScript, deploymentBindings, deploymentTags, isExistingScript, KEY_TAG_PREFIX, LINE_TAG_PREFIX, observeScript, putScriptSecret, ROUTER_BINDING, scriptPath, scriptSecretNames, scriptSettings, SETTINGS_BINDING, settingsBind, SIGNING_IDENTITY_BINDING, uploadDeploymentScript, VERSION_METADATA_BINDING, versionUuid, WORKER_URL_BINDING, type DeploymentBindingsInput, type NamespaceScript, type ScriptBinding, type ScriptModule, type ScriptSettings, type ScriptUpload, } from './script.js';
21
21
  export { uploadAssets, type ScriptAsset } from './assets.js';
22
22
  export { createSigningIdentity, type DeploymentSigningIdentity } from './identity.js';
23
- export { activateDeployment, promoteDeployment, readCurrent, readRecord, readSchedules, replaceSchedules, sameRecord, } from './activation.js';
24
- export { completeRetirement, markRetired, readRetirement, RETIREMENT_PROBE_PATH, RETIREMENT_PROBE_RETRY_MS, RETIREMENT_PROPAGATION_MS, retirementVisible, type RetirementCompletion, } from './retirement.js';
23
+ export { activateDeployment, promoteDeployment, readCurrent, readRecord, readRetirement, readSchedules, replaceSchedules, sameRecord, } from './activation.js';
24
+ export { completeRetirement, markRetired, RETIREMENT_PROBE_PATH, RETIREMENT_PROBE_RETRY_MS, RETIREMENT_PROPAGATION_MS, retirementVisible, type RetirementCompletion, } from './retirement.js';
25
25
  export { dispatchFetcher, publicFetcher, VERSION_HEADER, versionFetch, waitForReadiness, type ReadinessFetcher, } from './readiness.js';
26
26
  export { listLineDeployments, type LineDeployment } from './listing.js';
27
27
  export { createDispatcher } from './dispatcher/dispatcher.mjs';
@@ -20,8 +20,8 @@ export { CRON_PREFIX, cronKey, CURRENT_PREFIX, currentKey, decodeCurrent, decode
20
20
  export { ARTIFACT_TAG_PREFIX, artifactOf, ASSETS_BINDING, BUILD_DIGEST_BINDING, decodeScript, deleteScript, deploymentBindings, deploymentTags, isExistingScript, KEY_TAG_PREFIX, LINE_TAG_PREFIX, observeScript, putScriptSecret, ROUTER_BINDING, scriptPath, scriptSecretNames, scriptSettings, SETTINGS_BINDING, settingsBind, SIGNING_IDENTITY_BINDING, uploadDeploymentScript, VERSION_METADATA_BINDING, versionUuid, WORKER_URL_BINDING, } from './script.js';
21
21
  export { uploadAssets } from './assets.js';
22
22
  export { createSigningIdentity } from './identity.js';
23
- export { activateDeployment, promoteDeployment, readCurrent, readRecord, readSchedules, replaceSchedules, sameRecord, } from './activation.js';
24
- export { completeRetirement, markRetired, readRetirement, RETIREMENT_PROBE_PATH, RETIREMENT_PROBE_RETRY_MS, RETIREMENT_PROPAGATION_MS, retirementVisible, } from './retirement.js';
23
+ export { activateDeployment, promoteDeployment, readCurrent, readRecord, readRetirement, readSchedules, replaceSchedules, sameRecord, } from './activation.js';
24
+ export { completeRetirement, markRetired, RETIREMENT_PROBE_PATH, RETIREMENT_PROBE_RETRY_MS, RETIREMENT_PROPAGATION_MS, retirementVisible, } from './retirement.js';
25
25
  export { dispatchFetcher, publicFetcher, VERSION_HEADER, versionFetch, waitForReadiness, } from './readiness.js';
26
26
  export { listLineDeployments } from './listing.js';
27
27
  export { createDispatcher } from './dispatcher/dispatcher.mjs';
@@ -1,9 +1,8 @@
1
1
  import { parseDeploymentLabel } from '@astrale-os/sdk/deployment/address';
2
- import { readRecord } from './activation.js';
2
+ import { readRecord, readRetirement } from './activation.js';
3
3
  import { CLOUDFLARE_FAN_OUT, mapBounded } from './bounded.js';
4
4
  import { RECORD_PREFIX, RETIREMENT_PREFIX } from './kv.js';
5
5
  import { HostingRefusal } from './refusal.js';
6
- import { readRetirement } from './retirement.js';
7
6
  import { observeScript } from './script.js';
8
7
  /**
9
8
  * The deployments of one line, from the keys under `record:<line>-` and `retirement:<line>-` of
@@ -18,8 +18,6 @@ export declare const RETIREMENT_PROBE_RETRY_MS = 15000;
18
18
  export declare function markRetired(kv: RoutingKv, label: string): Promise<{
19
19
  readonly previous: 'absent' | typeof WITHDRAWN;
20
20
  }>;
21
- /** The tombstone of a label: `withdrawn`, or undefined; any other value is refused. */
22
- export declare function readRetirement(kv: RoutingKv, label: string): Promise<typeof WITHDRAWN | undefined>;
23
21
  /**
24
22
  * Whether the dispatcher answers `DEPLOYMENT_RETIRED` for the deployment at `url`, exactly as
25
23
  * kernel-protocol defines it: 410, `x-astrale-deployment-retired: 1`, and the envelope naming the
@@ -1,6 +1,5 @@
1
- import { readRecord, sameRecord } from './activation.js';
1
+ import { readRecord, readRetirement, sameRecord } from './activation.js';
2
2
  import { retirementKey, WITHDRAWN } from './kv.js';
3
- import { HostingRefusal } from './refusal.js';
4
3
  import { deleteScript, observeScript } from './script.js';
5
4
  /** The dispatcher's retirement probe path; it is never a call of the deployment. */
6
5
  export const RETIREMENT_PROBE_PATH = '/__services_retirement_probe__';
@@ -21,13 +20,6 @@ export async function markRetired(kv, label) {
21
20
  await kv.put(retirementKey(label), WITHDRAWN, 'text/plain');
22
21
  return Object.freeze({ previous: 'absent' });
23
22
  }
24
- /** The tombstone of a label: `withdrawn`, or undefined; any other value is refused. */
25
- export async function readRetirement(kv, label) {
26
- const value = await kv.get(retirementKey(label));
27
- if (value === undefined || value === WITHDRAWN)
28
- return value;
29
- throw new HostingRefusal('retirement-invalid', `The tombstone of ${label} holds another value than ${WITHDRAWN}.`);
30
- }
31
23
  /**
32
24
  * Whether the dispatcher answers `DEPLOYMENT_RETIRED` for the deployment at `url`, exactly as
33
25
  * kernel-protocol defines it: 410, `x-astrale-deployment-retired: 1`, and the envelope naming the
@@ -1,8 +1,8 @@
1
1
  import { acceptDeploymentRecord, configurationDigest, deploymentContent, deploymentLabel, deploymentLine, deploymentUrl, DEPLOYMENT_RECORD_FORMAT, DEPLOYMENT_RECORD_VERSION, encodeDeploymentRecord, isFrozenConfiguration, } from '@astrale-os/sdk/deployment/address';
2
2
  import { bundleUpload } from '../build/worker/upload.js';
3
- import { activateDeployment, readRecord } from '../hosting/activation.js';
3
+ import { activateDeployment, readRecord, refuseWithdrawn } from '../hosting/activation.js';
4
4
  import { CloudflareApiError, CloudflareClient } from '../hosting/client.js';
5
- import { retirementKey, RoutingKv } from '../hosting/kv.js';
5
+ import { RoutingKv } from '../hosting/kv.js';
6
6
  import { routingKvTitle } from '../hosting/names.js';
7
7
  import { HostingRefusal } from '../hosting/refusal.js';
8
8
  import { ASSETS_BINDING, artifactOf, deploymentBindings, deploymentTags, isExistingScript, observeScript, putScriptSecret, scriptSecretNames, scriptSettings, settingsBind, SIGNING_IDENTITY_BINDING, uploadDeploymentScript, versionUuid, } from '../hosting/script.js';
@@ -50,10 +50,7 @@ export async function deployNamespaceRelease(parameters, context, dependencies)
50
50
  const plan = deploymentPlan(parameters, context);
51
51
  const client = namespaceClient(plan.coordinates, context.signal, dependencies);
52
52
  const kv = await RoutingKv.open(client, { title: await routingKvTitle(plan.coordinates.name) });
53
- if ((await kv.get(retirementKey(plan.label))) !== undefined) {
54
- throw new HostingRefusal('deployment-retired', `${plan.label} was withdrawn and is never served again; change the release to deploy ` +
55
- 'another deployment.');
56
- }
53
+ await refuseWithdrawn(kv, plan.label);
57
54
  deployment = new NamespaceDeployment(plan, client, kv, context, dependencies);
58
55
  }
59
56
  catch (cause) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/adapter-cloudflare",
3
- "version": "0.5.0-beta.218",
3
+ "version": "0.5.0-beta.219",
4
4
  "description": "Deploy an Astrale Domain through Cloudflare Workers",
5
5
  "keywords": [
6
6
  "adapter",
@@ -61,7 +61,7 @@
61
61
  "registry": "https://registry.npmjs.org/"
62
62
  },
63
63
  "dependencies": {
64
- "@astrale-os/sdk": "0.6.0-beta.63",
64
+ "@astrale-os/sdk": "0.6.0-beta.64",
65
65
  "@noble/hashes": "2.3.0",
66
66
  "@restatedev/restate-sdk-cloudflare-workers": "1.17.0",
67
67
  "hono": "^4.13.11",