@astrale-os/adapter-astrale 0.5.0-beta.21 → 0.5.0-beta.210

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.
Files changed (54) hide show
  1. package/README.md +161 -2
  2. package/dist/adapter.d.ts +7 -16
  3. package/dist/adapter.js +27 -266
  4. package/dist/admit.d.ts +7 -0
  5. package/dist/admit.js +44 -0
  6. package/dist/cli/commands/call.d.ts +15 -0
  7. package/dist/cli/commands/call.js +36 -0
  8. package/dist/cli/commands/version.d.ts +12 -0
  9. package/dist/cli/commands/version.js +56 -0
  10. package/dist/cli/diagnostic.d.ts +6 -0
  11. package/dist/cli/diagnostic.js +28 -0
  12. package/dist/cli/error.d.ts +7 -0
  13. package/dist/cli/error.js +29 -0
  14. package/dist/cli/executable.d.ts +2 -0
  15. package/dist/cli/executable.js +54 -0
  16. package/dist/cli/identity.d.ts +5 -0
  17. package/dist/cli/identity.js +11 -0
  18. package/dist/cli/json.d.ts +2 -0
  19. package/dist/cli/json.js +39 -0
  20. package/dist/cli/process.d.ts +18 -0
  21. package/dist/cli/process.js +109 -0
  22. package/dist/configure.d.ts +17 -0
  23. package/dist/configure.js +40 -0
  24. package/dist/deploy/deploy-release.d.ts +30 -0
  25. package/dist/deploy/deploy-release.js +168 -0
  26. package/dist/deploy/list.d.ts +22 -0
  27. package/dist/deploy/list.js +63 -0
  28. package/dist/deploy/readiness.d.ts +17 -0
  29. package/dist/deploy/readiness.js +56 -0
  30. package/dist/index.d.ts +21 -10
  31. package/dist/index.js +21 -10
  32. package/dist/params.d.ts +25 -36
  33. package/dist/services/api.d.ts +35 -0
  34. package/dist/services/api.js +39 -0
  35. package/dist/services/client.d.ts +93 -0
  36. package/dist/services/client.js +116 -0
  37. package/dist/services/directory.d.ts +16 -0
  38. package/dist/services/directory.js +78 -0
  39. package/dist/services/index.d.ts +44 -0
  40. package/dist/services/index.js +27 -0
  41. package/dist/services/request.d.ts +25 -0
  42. package/dist/services/request.js +71 -0
  43. package/package.json +18 -11
  44. package/template/astrale.config.ts +27 -38
  45. package/dist/cli.d.ts +0 -15
  46. package/dist/cli.js +0 -48
  47. package/dist/prerequisite.d.ts +0 -19
  48. package/dist/prerequisite.js +0 -59
  49. package/dist/service/addressing.d.ts +0 -3
  50. package/dist/service/addressing.js +0 -16
  51. package/dist/service/artifact.d.ts +0 -34
  52. package/dist/service/artifact.js +0 -122
  53. package/dist/service/readiness.d.ts +0 -3
  54. package/dist/service/readiness.js +0 -16
@@ -0,0 +1,78 @@
1
+ import { acceptWorkerCode, WORKER_BUILD_MANIFEST } from '@astrale-os/sdk/deployment/worker';
2
+ import { readdir, readFile } from 'node:fs/promises';
3
+ import { join, relative, sep } from 'node:path';
4
+ /** How Workers loads a module, by its extension, as Wrangler's default module rules read it. */
5
+ const MODULE_KINDS = Object.freeze({
6
+ '.js': 'esm',
7
+ '.mjs': 'esm',
8
+ '.wasm': 'wasm',
9
+ '.txt': 'text',
10
+ '.html': 'text',
11
+ '.sql': 'text',
12
+ '.bin': 'data',
13
+ });
14
+ /** The media type an asset is uploaded with, by its extension; none for any other. */
15
+ const MEDIA_TYPES = Object.freeze({
16
+ '.css': 'text/css',
17
+ '.html': 'text/html',
18
+ '.ico': 'image/x-icon',
19
+ '.jpg': 'image/jpeg',
20
+ '.js': 'text/javascript',
21
+ '.json': 'application/json',
22
+ '.mjs': 'text/javascript',
23
+ '.png': 'image/png',
24
+ '.svg': 'image/svg+xml',
25
+ '.txt': 'text/plain',
26
+ '.wasm': 'application/wasm',
27
+ '.webp': 'image/webp',
28
+ '.woff2': 'font/woff2',
29
+ });
30
+ /**
31
+ * Read one built Worker from disk: every file of `directory` is a module, named by its path
32
+ * relative to it (`/`-separated) and loaded by its extension (`.js` and `.mjs` as ES modules,
33
+ * `.wasm`, `.txt`, `.html` and `.sql` as their kind, `.bin` as data); source maps are left out, and
34
+ * any other file is refused. Every file of `assets`, when given, is a static asset served at its
35
+ * path relative to it. The code is admitted as Admin's Services admits it.
36
+ */
37
+ export async function readWorkerDirectory(directory, options) {
38
+ const modules = [];
39
+ for (const path of await files(directory)) {
40
+ if (path.endsWith('.map'))
41
+ continue;
42
+ const kind = MODULE_KINDS[extension(path)];
43
+ if (kind === undefined) {
44
+ throw new TypeError(`Worker module ${path} has no module kind; rename or remove it.`);
45
+ }
46
+ modules.push({ name: path, kind, bytes: await readFile(join(directory, path)) });
47
+ }
48
+ const assets = [];
49
+ if (options.assets !== undefined) {
50
+ for (const path of await files(options.assets)) {
51
+ const contentType = MEDIA_TYPES[extension(path)];
52
+ assets.push({
53
+ path: `/${path}`,
54
+ bytes: await readFile(join(options.assets, path)),
55
+ ...(contentType === undefined ? {} : { contentType }),
56
+ });
57
+ }
58
+ }
59
+ return acceptWorkerCode({
60
+ manifest: options.manifest ?? WORKER_BUILD_MANIFEST,
61
+ mainModule: options.mainModule,
62
+ modules,
63
+ ...(assets.length === 0 ? {} : { assets }),
64
+ });
65
+ }
66
+ /** Every file below `root`, by its `/`-separated path relative to it, sorted. */
67
+ async function files(root) {
68
+ const entries = await readdir(root, { recursive: true, withFileTypes: true });
69
+ return entries
70
+ .filter((entry) => entry.isFile())
71
+ .map((entry) => relative(root, join(entry.parentPath, entry.name)).split(sep).join('/'))
72
+ .sort();
73
+ }
74
+ function extension(path) {
75
+ const name = path.slice(path.lastIndexOf('/') + 1);
76
+ const dot = name.lastIndexOf('.');
77
+ return dot <= 0 ? '' : name.slice(dot).toLowerCase();
78
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `@astrale-os/adapter-astrale/services` — deploy any Cloudflare Worker (a cron job, an API, a
3
+ * scaffolded Service) on Admin's Services, the way `astrale()` deploys a Domain, with no Cloudflare
4
+ * account: the only credential is the astrale CLI's session (`astrale auth login`).
5
+ *
6
+ * import { deployWorker, readWorkerDirectory } from '@astrale-os/adapter-astrale/services'
7
+ *
8
+ * const worker = await readWorkerDirectory('.dist', { mainModule: 'worker.mjs' })
9
+ * const { state, deployment } = await deployWorker({
10
+ * project: 'nightly-report',
11
+ * environment: 'production',
12
+ * worker,
13
+ * configuration: { compatibilityDate: '2026-09-01', vars: { KERNEL: '…' } },
14
+ * secrets: { ACCOUNT_PRIVATE_JWK: '…' },
15
+ * readiness: ['/health'],
16
+ * })
17
+ *
18
+ * Each deploy is one immutable deployment of the Service of its project and environment, at
19
+ * `https://<label>.<routing domain>`; the Service's stable URL, `https://<service>.<routing
20
+ * domain>`, serves the deployment last promoted (by default, the latest). The same code and
21
+ * configuration reuse their deployment, and rewrite its secrets in place when they changed. Its
22
+ * Methods (`promote`, `setSecret`, `setSchedule`, `logs`, `delete`, ...) take the Service's id:
23
+ * `callService(deployment.serviceId, 'setSchedule', { crons: ['*\/5 * * * *'] })`. A scheduled
24
+ * Service is called `POST /__scheduled` on its current deployment, with the cron in
25
+ * `x-astrale-cron` and the time in `x-astrale-scheduled-time`; the public never reaches that path.
26
+ *
27
+ * The request and the answers are `@astrale-os/sdk/deployment/worker`'s contract.
28
+ */
29
+ import type { WorkerDeploymentListRequestV1, WorkerDeploymentSummary, WorkerHostingV1 } from '@astrale-os/sdk/deployment/worker';
30
+ import type { ServicesOptions, WorkerDeploy, WorkerDeployed } from './client.js';
31
+ export { deploymentCallPath, serviceCallPath } from './api.js';
32
+ export { ServicesRefusal, type ServicesOptions, type WorkerDeploy, type WorkerDeployed, } from './client.js';
33
+ export { readWorkerDirectory } from './directory.js';
34
+ /** Where Admin's Services addresses Services and deployments. Changes nothing. */
35
+ export declare function servicesHosting(options?: ServicesOptions): Promise<WorkerHostingV1>;
36
+ /**
37
+ * Deploy one Worker as a deployment of the Service of its project and environment, creating that
38
+ * Service on its first deploy, owned by the caller. A refusal throws a `ServicesRefusal`.
39
+ */
40
+ export declare function deployWorker(input: WorkerDeploy, options?: ServicesOptions): Promise<WorkerDeployed>;
41
+ /** The deployments of the caller's Services, of one project or environment when given. */
42
+ export declare function listWorkerDeployments(filter?: WorkerDeploymentListRequestV1, options?: ServicesOptions): Promise<readonly WorkerDeploymentSummary[]>;
43
+ /** Call one Method of a Service the caller owns, by the Service's node id. */
44
+ export declare function callService(serviceId: string, method: string, data?: unknown, options?: ServicesOptions): Promise<unknown>;
@@ -0,0 +1,27 @@
1
+ import { callAdmin } from '../cli/commands/call.js';
2
+ import { requireCliVersion } from '../cli/commands/version.js';
3
+ import { resolveCliExecutable } from '../cli/executable.js';
4
+ import { servicesClient } from './client.js';
5
+ export { deploymentCallPath, serviceCallPath } from './api.js';
6
+ export { ServicesRefusal, } from './client.js';
7
+ export { readWorkerDirectory } from './directory.js';
8
+ const client = servicesClient({ resolveCliExecutable, requireCliVersion, callAdmin });
9
+ /** Where Admin's Services addresses Services and deployments. Changes nothing. */
10
+ export function servicesHosting(options) {
11
+ return client.hosting(options);
12
+ }
13
+ /**
14
+ * Deploy one Worker as a deployment of the Service of its project and environment, creating that
15
+ * Service on its first deploy, owned by the caller. A refusal throws a `ServicesRefusal`.
16
+ */
17
+ export function deployWorker(input, options) {
18
+ return client.deploy(input, options);
19
+ }
20
+ /** The deployments of the caller's Services, of one project or environment when given. */
21
+ export function listWorkerDeployments(filter, options) {
22
+ return client.list(filter, options);
23
+ }
24
+ /** Call one Method of a Service the caller owns, by the Service's node id. */
25
+ export function callService(serviceId, method, data, options) {
26
+ return client.callService(serviceId, method, data, options);
27
+ }
@@ -0,0 +1,25 @@
1
+ import type { ReleaseDeployContext } from '@astrale-os/sdk/deployment/adapter';
2
+ import type { WorkerDeploymentInput, WorkerRecord } from '@astrale-os/sdk/deployment/worker';
3
+ /** What of one deploy the Worker deployment of a Domain carries. */
4
+ export type DomainDeploymentContext = Pick<ReleaseDeployContext, 'environment' | 'secrets' | 'bundle' | 'configuration' | 'placement' | 'label' | 'release' | 'commit'>;
5
+ /**
6
+ * The Worker deployment of one sealed Domain release, as Admin's Services hosts any Worker. Every
7
+ * Domain fact is the deployer's: the project is the Domain's origin, so its Service keeps the name
8
+ * of the Domain's opaque line; the build manifest members are the Bundle's own, so Services binds
9
+ * exactly the release's build digest; the record is the Domain's `DeploymentRecordV1` document,
10
+ * served byte for byte at `/.well-known/astrale/deployment.json`; the readiness paths are the ones
11
+ * the SDK verifies a release by. It names no `owner`, so a Service its first deploy creates is the
12
+ * caller's, and asks no `promote`, so the Service serves the deployment once it is active.
13
+ *
14
+ * The record names the label the SDK derived, which `acceptDeploymentRecord` checks against the
15
+ * build and the configuration: a deployment Services would address elsewhere is refused here,
16
+ * before any call.
17
+ */
18
+ export declare function domainWorkerDeployment(context: DomainDeploymentContext): WorkerDeploymentInput;
19
+ /**
20
+ * A published record as a listing returns it, unadmitted: its JSON value, its text when it is not
21
+ * JSON, and nothing when the deployment publishes none. The listing admits it.
22
+ */
23
+ export declare function listedRecord(record: WorkerRecord | undefined): {
24
+ readonly record?: unknown;
25
+ };
@@ -0,0 +1,71 @@
1
+ import { bundleUpload } from '@astrale-os/adapter-cloudflare/build';
2
+ import { acceptDeploymentRecord, DEPLOYMENT_RECORD_FORMAT, DEPLOYMENT_RECORD_VERSION, encodeDeploymentRecord, } from '@astrale-os/sdk/deployment/address';
3
+ import { readinessPaths } from '@astrale-os/sdk/deployment/verify';
4
+ import { isWorkerConfiguration, workerConfigurationDigest } from '@astrale-os/sdk/deployment/worker';
5
+ /**
6
+ * The Worker deployment of one sealed Domain release, as Admin's Services hosts any Worker. Every
7
+ * Domain fact is the deployer's: the project is the Domain's origin, so its Service keeps the name
8
+ * of the Domain's opaque line; the build manifest members are the Bundle's own, so Services binds
9
+ * exactly the release's build digest; the record is the Domain's `DeploymentRecordV1` document,
10
+ * served byte for byte at `/.well-known/astrale/deployment.json`; the readiness paths are the ones
11
+ * the SDK verifies a release by. It names no `owner`, so a Service its first deploy creates is the
12
+ * caller's, and asks no `promote`, so the Service serves the deployment once it is active.
13
+ *
14
+ * The record names the label the SDK derived, which `acceptDeploymentRecord` checks against the
15
+ * build and the configuration: a deployment Services would address elsewhere is refused here,
16
+ * before any call.
17
+ */
18
+ export function domainWorkerDeployment(context) {
19
+ const { configuration, release } = context;
20
+ if (!isWorkerConfiguration(configuration)) {
21
+ throw new TypeError('Admin Services hosts a Worker configuration only.');
22
+ }
23
+ // Services names every Service by its opaque fingerprint; placement never places another.
24
+ if (context.placement.addressing !== 'opaque') {
25
+ throw new TypeError('Admin Services hosts deployments on opaque lines only.');
26
+ }
27
+ const upload = bundleUpload(context.bundle);
28
+ const { document } = release;
29
+ const record = acceptDeploymentRecord({
30
+ format: DEPLOYMENT_RECORD_FORMAT,
31
+ version: DEPLOYMENT_RECORD_VERSION,
32
+ origin: document.origin,
33
+ environment: context.environment,
34
+ releaseDigest: document.digest,
35
+ buildDigest: context.bundle.digest,
36
+ schemaRevision: document.schema.revision,
37
+ configuration: workerConfigurationDigest(configuration),
38
+ providerScript: context.label,
39
+ commit: context.commit,
40
+ });
41
+ const { entrypoint: _entrypoint, files: _files, ...manifest } = context.bundle.manifest;
42
+ return Object.freeze({
43
+ project: document.origin,
44
+ environment: context.environment,
45
+ worker: Object.freeze({
46
+ manifest,
47
+ mainModule: upload.entry,
48
+ modules: upload.modules,
49
+ ...(upload.assets === undefined ? {} : { assets: upload.assets }),
50
+ }),
51
+ configuration,
52
+ record: encodeDeploymentRecord(record),
53
+ readiness: readinessPaths(release),
54
+ secrets: context.secrets,
55
+ });
56
+ }
57
+ /**
58
+ * A published record as a listing returns it, unadmitted: its JSON value, its text when it is not
59
+ * JSON, and nothing when the deployment publishes none. The listing admits it.
60
+ */
61
+ export function listedRecord(record) {
62
+ if (record === undefined)
63
+ return {};
64
+ const text = new TextDecoder().decode(record.bytes);
65
+ try {
66
+ return { record: JSON.parse(text) };
67
+ }
68
+ catch {
69
+ return { record: text };
70
+ }
71
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrale-os/adapter-astrale",
3
- "version": "0.5.0-beta.21",
4
- "description": "Deploy an Astrale domain as a managed service through the Astrale platform",
3
+ "version": "0.5.0-beta.210",
4
+ "description": "Deploy an Astrale domain, or any Cloudflare Worker, as managed deployments through the Astrale platform",
5
5
  "keywords": [
6
6
  "adapter",
7
7
  "astrale",
@@ -31,26 +31,33 @@
31
31
  "types": "./dist/index.d.ts",
32
32
  "import": "./dist/index.js"
33
33
  },
34
+ "./services": {
35
+ "types": "./dist/services/index.d.ts",
36
+ "import": "./dist/services/index.js"
37
+ },
34
38
  "./package.json": "./package.json"
35
39
  },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org/"
42
+ },
36
43
  "dependencies": {
37
- "@astrale-os/adapter-cloudflare": "^0.5.0-beta.28",
38
- "@astrale-os/sdk": "^0.5.0-beta.25"
44
+ "@astrale-os/adapter-cloudflare": "0.5.0-beta.217",
45
+ "@astrale-os/sdk": "0.6.0-beta.62"
39
46
  },
40
47
  "devDependencies": {
41
- "@astrale-os/ox": ">=0.1.0 <1.0.0",
42
- "@types/node": "^22.0.0",
43
- "oxfmt": "0.63.0",
48
+ "@astrale-os/ox": "0.1.4",
49
+ "@types/node": "^24.0.0",
50
+ "oxfmt": "0.67.0",
44
51
  "oxlint": "1.78.0",
45
52
  "typescript": "7.0.2",
46
- "vitest": "^4.1.10",
47
- "zod": "^4.4.3"
53
+ "vitest": "^5.0.5",
54
+ "zod": "4.6.7"
48
55
  },
49
56
  "engines": {
50
- "node": ">=22"
57
+ "node": ">=24"
51
58
  },
52
59
  "scripts": {
53
- "typecheck": "tsc --noEmit",
60
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
54
61
  "test": "vitest run",
55
62
  "lint": "oxlint .",
56
63
  "format": "pnpm exec oxfmt --write .",
@@ -1,46 +1,35 @@
1
1
  /**
2
- * astrale.config.ts — binds the authored Application and independently importable Runtime to the
3
- * managed
4
- * Astrale deploy adapter for the `astrale-domain` CLI. This is a NODE-only
5
- * module; the generated worker imports `runtime.ts` directly, never this file.
2
+ * One Project definition, with explicit software-factory Environments.
6
3
  *
7
- * This variant ships THROUGH the Astrale platform (the managed `astrale`
8
- * adapter) — no Cloudflare account needed.
4
+ * `astrale-domain deploy <environment>` makes one immutable deployment of this
5
+ * release on Admin's Services, at its own URL, with a signing key generated for
6
+ * it, and prints that URL. A deploy never installs the Domain: install the URL
7
+ * it prints with `astrale domain install <url> -i <instance>`.
8
+ * Redeploying the same release reuses its deployment; a changed secrets file is
9
+ * then rewritten in place on that deployment only.
9
10
  *
10
- * pnpm dev # wrangler dev → prints a local URL
11
- * astrale domain install <url> --direct # mount the dev URL on an instance
12
- * pnpm prod # managed deploy → prints a URL + installs
11
+ * Every Environment deploys through the Astrale CLI's authenticated identity.
13
12
  */
14
13
  import { astrale } from '@astrale-os/adapter-astrale'
15
- import { deploy, runtime } from '@astrale-os/sdk/deployment'
16
- // Have your own Cloudflare account and prefer deploying there directly? Swap
17
- // the adapter — same bundle, shipped with wrangler under YOUR account (then
18
- // mount it yourself: `astrale domain install <url> --direct`):
19
- //
20
- // import { cloudflare } from '@astrale-os/adapter-cloudflare'
21
- // export default deploy({ application, entrypoint: runtime('./runtime.ts'), adapter: cloudflare({
22
- // dev: { secrets: '.env.dev' },
23
- // prod: {
24
- // route: 'astrale-domain.example.dev', secrets: '.env.prod',
25
- // signingIdentity: '.astrale/identity.json',
26
- // },
27
- // }) })
14
+ import { defineProject } from '@astrale-os/sdk/project'
15
+ import { dataset, tests } from '@astrale-os/sdk/testing'
28
16
 
29
- import { application } from './application.js'
17
+ import { domain } from './domain.js'
30
18
 
31
- export default deploy({
32
- application,
33
- entrypoint: runtime('./runtime.ts'),
34
- adapter: astrale({
35
- // Local dev: `wrangler dev`. No route → URL is http://localhost:8787.
36
- dev: { secrets: '.env.dev' },
37
- // Managed deploy: `pnpm prod` publishes the bundle through the platform and
38
- // installs the domain on this instance. The slug comes from
39
- // `astrale instance create <slug>` / `astrale instance status`.
40
- // The scaffold creates this identity once. Retain it in managed secret
41
- // storage and restore it at this path in CI before every remote deploy.
42
- prod: { instance: 'my-instance-slug', signingIdentity: '.astrale/identity.json' },
43
- // Author secrets ship via `secrets: '.env.prod'` on any env (encrypted at
44
- // rest platform-side, re-applied on redeploys; omit = keep, `{}` = clear).
45
- }),
19
+ export default defineProject({
20
+ domain,
21
+
22
+ environments: {
23
+ development: {
24
+ deployment: astrale({ secrets: '.env.dev' }),
25
+ },
26
+
27
+ production: {
28
+ deployment: astrale(),
29
+ },
30
+ },
31
+
32
+ // Test resources belong to the Project. CI selects an Environment and named
33
+ // suite when a test execution needs a live deployment.
34
+ tests: tests({ datasets: [dataset('./tests/datasets/demo.ts')] }),
46
35
  })
package/dist/cli.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export interface RunAstraleInput {
2
- readonly projectDir: string;
3
- readonly input: readonly string[];
4
- readonly stdin?: string;
5
- }
6
- export interface CallAstraleInput {
7
- readonly projectDir: string;
8
- readonly instance: string;
9
- readonly path: string;
10
- readonly identity: readonly string[];
11
- readonly data: unknown;
12
- }
13
- export declare function callAstrale(input: CallAstraleInput): Promise<unknown>;
14
- export declare function runAstrale(input: RunAstraleInput): Promise<string>;
15
- export declare function identityArguments(identity: string | undefined): readonly string[];
package/dist/cli.js DELETED
@@ -1,48 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- export async function callAstrale(input) {
3
- const payload = JSON.stringify(input.data);
4
- const output = await runAstrale({
5
- projectDir: input.projectDir,
6
- input: [
7
- 'call',
8
- input.path,
9
- '-i',
10
- input.instance,
11
- '--json',
12
- '--timeout',
13
- '240000',
14
- ...input.identity,
15
- ],
16
- stdin: payload,
17
- });
18
- try {
19
- return JSON.parse(output);
20
- }
21
- catch (cause) {
22
- throw new Error(`astrale call ${input.path} returned invalid JSON.`, { cause });
23
- }
24
- }
25
- export async function runAstrale(input) {
26
- const result = await new Promise((resolve, reject) => {
27
- const child = spawn('astrale', [...input.input], {
28
- cwd: input.projectDir,
29
- stdio: [input.stdin === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],
30
- });
31
- let stdout = '';
32
- let stderr = '';
33
- child.stdout?.on('data', (bytes) => (stdout += bytes.toString()));
34
- child.stderr?.on('data', (bytes) => (stderr += bytes.toString()));
35
- child.once('error', reject);
36
- child.once('exit', (code) => resolve({ code: code ?? 1, stdout, stderr }));
37
- if (input.stdin !== undefined)
38
- child.stdin?.end(input.stdin);
39
- });
40
- if (result.code !== 0) {
41
- const diagnostics = `${result.stdout}\n${result.stderr}`.trim().slice(0, 800);
42
- throw new Error(`astrale ${input.input.slice(0, 2).join(' ')} failed: ${diagnostics}`);
43
- }
44
- return result.stdout;
45
- }
46
- export function identityArguments(identity) {
47
- return identity === undefined ? [] : ['--as', identity];
48
- }
@@ -1,19 +0,0 @@
1
- import type { RunAstraleInput } from './cli.js';
2
- export interface EnsureServicesInput {
3
- readonly projectDir: string;
4
- readonly instance: string;
5
- readonly servicesOrigin: string;
6
- readonly identity: readonly string[];
7
- readonly run: (input: RunAstraleInput) => Promise<string>;
8
- }
9
- export declare class ServicesPrerequisiteError extends Error {
10
- readonly mutation: 'unknown' | 'installed';
11
- constructor(message: string, mutation: 'unknown' | 'installed', options?: ErrorOptions);
12
- }
13
- export declare function ensureServices(input: EnsureServicesInput): Promise<Readonly<{
14
- origin: string;
15
- state: 'present';
16
- }> | Readonly<{
17
- origin: string;
18
- state: 'installed';
19
- }>>;
@@ -1,59 +0,0 @@
1
- export class ServicesPrerequisiteError extends Error {
2
- mutation;
3
- constructor(message, mutation, options) {
4
- super(message, options);
5
- this.mutation = mutation;
6
- this.name = 'ServicesPrerequisiteError';
7
- }
8
- }
9
- export async function ensureServices(input) {
10
- const probe = [
11
- 'get',
12
- `/:${input.servicesOrigin}`,
13
- '-i',
14
- input.instance,
15
- '--json',
16
- '--timeout',
17
- '60000',
18
- ...input.identity,
19
- ];
20
- try {
21
- await input.run({ projectDir: input.projectDir, input: probe });
22
- return Object.freeze({ origin: input.servicesOrigin, state: 'present' });
23
- }
24
- catch (cause) {
25
- if (!/\bNOT_FOUND\b|Path not found/iu.test(message(cause)))
26
- throw cause;
27
- }
28
- try {
29
- await input.run({
30
- projectDir: input.projectDir,
31
- input: [
32
- 'domain',
33
- 'install',
34
- input.servicesOrigin,
35
- '-i',
36
- input.instance,
37
- '--json',
38
- '--timeout',
39
- '240000',
40
- ...input.identity,
41
- ],
42
- });
43
- }
44
- catch (cause) {
45
- throw new ServicesPrerequisiteError('Services installation outcome is unknown.', 'unknown', {
46
- cause,
47
- });
48
- }
49
- try {
50
- await input.run({ projectDir: input.projectDir, input: probe });
51
- }
52
- catch (cause) {
53
- throw new ServicesPrerequisiteError('Services was installed but its verification probe failed.', 'installed', { cause });
54
- }
55
- return Object.freeze({ origin: input.servicesOrigin, state: 'installed' });
56
- }
57
- function message(input) {
58
- return input instanceof Error ? input.message : String(input);
59
- }
@@ -1,3 +0,0 @@
1
- export declare function servicesDeployMethod(servicesOrigin: string): string;
2
- export declare function serviceName(origin: string): string;
3
- export declare function servicePath(origin: string): string;
@@ -1,16 +0,0 @@
1
- export function servicesDeployMethod(servicesOrigin) {
2
- return `/:${servicesOrigin}:class.CloudflareWorker:deploy`;
3
- }
4
- export function serviceName(origin) {
5
- return origin
6
- .split('.')[0]
7
- .toLowerCase()
8
- .replace(/[^a-z0-9-]+/gu, '-');
9
- }
10
- export function servicePath(origin) {
11
- const slug = origin
12
- .toLowerCase()
13
- .replace(/[^a-z0-9]+/gu, '-')
14
- .replace(/^-+|-+$/gu, '');
15
- return `/${slug}`;
16
- }
@@ -1,34 +0,0 @@
1
- import type { PreparedArtifact } from '@astrale-os/sdk/deployment/adapter';
2
- export interface DeploymentPayloadInput {
3
- readonly origin: string;
4
- readonly name: string;
5
- readonly vars?: Readonly<Record<string, string>>;
6
- }
7
- export declare function deploymentPayload(artifact: Pick<PreparedArtifact, 'entrypoint' | 'files'>, input: DeploymentPayloadInput): Readonly<{
8
- path: string;
9
- name: string;
10
- entry: string;
11
- compatibilityDate?: string | undefined;
12
- compatibilityFlags?: readonly string[] | undefined;
13
- serviceBindings?: readonly Readonly<{
14
- name: string;
15
- service: string;
16
- }>[] | undefined;
17
- modules: readonly Readonly<{
18
- name: string;
19
- kind: 'esm';
20
- contentBase64: string;
21
- }>[];
22
- assets?: Readonly<{
23
- files: readonly Readonly<{
24
- path: string;
25
- contentBase64: string;
26
- contentType?: string | undefined;
27
- }>[];
28
- notFound: 'none';
29
- runWorkerFirst: true;
30
- }> | undefined;
31
- vars?: Readonly<{
32
- [x: string]: string;
33
- }> | undefined;
34
- }>;