@astrale-os/adapter-cloudflare 0.5.0-beta.2 → 0.5.0-beta.200

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 (249) hide show
  1. package/README.md +256 -0
  2. package/dist/adapter.d.ts +11 -0
  3. package/dist/adapter.js +54 -0
  4. package/dist/build/bundle/admit.d.ts +3 -0
  5. package/dist/build/bundle/admit.js +47 -0
  6. package/dist/build/bundle/compiled-wasm-loader.d.ts +8 -0
  7. package/dist/build/bundle/compiled-wasm-loader.js +21 -0
  8. package/dist/build/bundler.d.ts +21 -0
  9. package/dist/build/bundler.js +96 -0
  10. package/dist/build/closure.d.ts +5 -0
  11. package/dist/build/closure.js +28 -0
  12. package/dist/build/codegen/execution.d.ts +3 -0
  13. package/dist/build/codegen/execution.js +2 -0
  14. package/dist/build/codegen/merge.d.ts +0 -1
  15. package/dist/build/codegen/merge.js +0 -1
  16. package/dist/build/codegen/wrangler.d.ts +32 -5
  17. package/dist/build/codegen/wrangler.js +77 -21
  18. package/dist/build/configuration/invocation-timeout.d.ts +2 -0
  19. package/dist/build/configuration/invocation-timeout.js +9 -0
  20. package/dist/build/configuration/request-limit.d.ts +2 -0
  21. package/dist/build/configuration/request-limit.js +9 -0
  22. package/dist/build/configuration/router.d.ts +7 -0
  23. package/dist/build/configuration/router.js +17 -0
  24. package/dist/build/configuration/settings.d.ts +6 -0
  25. package/dist/build/configuration/settings.js +40 -0
  26. package/dist/build/configuration.d.ts +4 -0
  27. package/dist/build/configuration.js +4 -0
  28. package/dist/build/frontend/files.d.ts +19 -0
  29. package/dist/build/frontend/files.js +99 -0
  30. package/dist/build/frontend/readiness.d.ts +16 -0
  31. package/dist/build/frontend/readiness.js +21 -0
  32. package/dist/build/frontend/revision.d.ts +5 -0
  33. package/dist/build/frontend/revision.js +14 -0
  34. package/dist/build/frontend/vite.d.ts +14 -0
  35. package/dist/build/frontend/vite.js +42 -0
  36. package/dist/build/frontend/vite.process.d.ts +7 -0
  37. package/dist/build/frontend/vite.process.js +65 -0
  38. package/dist/build/frontend/vite.runner.d.ts +1 -0
  39. package/dist/build/frontend/vite.runner.js +155 -0
  40. package/dist/build/index.d.ts +12 -16
  41. package/dist/build/index.js +12 -16
  42. package/dist/build/material.d.ts +10 -0
  43. package/dist/build/material.js +25 -0
  44. package/dist/build/metafile.d.ts +5 -0
  45. package/dist/build/metafile.js +14 -0
  46. package/dist/build/qualification.d.ts +5 -0
  47. package/dist/build/qualification.js +7 -0
  48. package/dist/build/roots.d.ts +2 -0
  49. package/dist/build/roots.js +34 -0
  50. package/dist/build/worker/codegen/entry.d.ts +9 -0
  51. package/dist/build/worker/codegen/entry.js +65 -0
  52. package/dist/build/worker/codegen/literal.d.ts +28 -0
  53. package/dist/build/worker/codegen/literal.js +136 -0
  54. package/dist/build/worker/codegen/service.d.ts +14 -0
  55. package/dist/build/worker/codegen/service.js +57 -0
  56. package/dist/build/worker/execution.prepare.d.ts +20 -0
  57. package/dist/build/worker/execution.prepare.js +129 -0
  58. package/dist/build/worker/media-type.d.ts +1 -0
  59. package/dist/build/worker/media-type.js +20 -0
  60. package/dist/build/worker/modules.d.ts +20 -0
  61. package/dist/build/worker/modules.js +32 -0
  62. package/dist/build/worker/specifier.d.ts +5 -0
  63. package/dist/build/worker/specifier.js +15 -0
  64. package/dist/build/worker/upload.d.ts +23 -0
  65. package/dist/build/worker/upload.js +42 -0
  66. package/dist/cloudflare.d.ts +1 -34
  67. package/dist/cloudflare.js +1 -205
  68. package/dist/hosting/activation.d.ts +38 -0
  69. package/dist/hosting/activation.js +109 -0
  70. package/dist/hosting/assets.d.ts +14 -0
  71. package/dist/hosting/assets.js +53 -0
  72. package/dist/hosting/bounded.d.ts +10 -0
  73. package/dist/hosting/bounded.js +32 -0
  74. package/dist/hosting/bytes.d.ts +6 -0
  75. package/dist/hosting/bytes.js +25 -0
  76. package/dist/hosting/client.d.ts +144 -0
  77. package/dist/hosting/client.js +491 -0
  78. package/dist/hosting/dispatcher/cron.d.mts +10 -0
  79. package/dist/hosting/dispatcher/cron.mjs +135 -0
  80. package/dist/hosting/dispatcher/deployments.d.mts +26 -0
  81. package/dist/hosting/dispatcher/deployments.mjs +158 -0
  82. package/dist/hosting/dispatcher/dispatcher.d.mts +17 -0
  83. package/dist/hosting/dispatcher/dispatcher.mjs +76 -0
  84. package/dist/hosting/dispatcher/env.d.mts +51 -0
  85. package/dist/hosting/dispatcher/failure.d.mts +4 -0
  86. package/dist/hosting/dispatcher/failure.mjs +15 -0
  87. package/dist/hosting/dispatcher/index.d.mts +4 -0
  88. package/dist/hosting/dispatcher/index.mjs +8 -0
  89. package/dist/hosting/dispatcher/modules.d.ts +24 -0
  90. package/dist/hosting/dispatcher/modules.js +55 -0
  91. package/dist/hosting/dispatcher/services.d.mts +23 -0
  92. package/dist/hosting/dispatcher/services.mjs +202 -0
  93. package/dist/hosting/identity.d.ts +15 -0
  94. package/dist/hosting/identity.js +36 -0
  95. package/dist/hosting/index.d.ts +34 -0
  96. package/dist/hosting/index.js +32 -0
  97. package/dist/hosting/kv.d.ts +90 -0
  98. package/dist/hosting/kv.js +207 -0
  99. package/dist/hosting/listing.d.ts +34 -0
  100. package/dist/hosting/listing.js +50 -0
  101. package/dist/hosting/names.d.ts +16 -0
  102. package/dist/hosting/names.js +28 -0
  103. package/dist/hosting/provision/account.d.ts +11 -0
  104. package/dist/hosting/provision/account.js +86 -0
  105. package/dist/hosting/provision/dispatcher.d.ts +42 -0
  106. package/dist/hosting/provision/dispatcher.js +99 -0
  107. package/dist/hosting/provision/ingress.d.ts +12 -0
  108. package/dist/hosting/provision/ingress.js +31 -0
  109. package/dist/hosting/provision/plan.d.ts +143 -0
  110. package/dist/hosting/provision/plan.js +246 -0
  111. package/dist/hosting/provision/routing.d.ts +82 -0
  112. package/dist/hosting/provision/routing.js +226 -0
  113. package/dist/hosting/readiness.d.ts +53 -0
  114. package/dist/hosting/readiness.js +82 -0
  115. package/dist/hosting/refusal.d.ts +28 -0
  116. package/dist/hosting/refusal.js +13 -0
  117. package/dist/hosting/retirement.d.ts +70 -0
  118. package/dist/hosting/retirement.js +107 -0
  119. package/dist/hosting/retry-after.d.ts +6 -0
  120. package/dist/hosting/retry-after.js +55 -0
  121. package/dist/hosting/script.d.ts +186 -0
  122. package/dist/hosting/script.js +324 -0
  123. package/dist/hosting/testing/fake-cloudflare.d.ts +212 -0
  124. package/dist/hosting/testing/fake-cloudflare.js +757 -0
  125. package/dist/hosting/testing/index.d.ts +6 -0
  126. package/dist/hosting/testing/index.js +6 -0
  127. package/dist/hosting/time.d.ts +4 -0
  128. package/dist/hosting/time.js +20 -0
  129. package/dist/identity/binding.d.ts +2 -0
  130. package/dist/identity/binding.js +2 -0
  131. package/dist/identity/material.d.ts +6 -0
  132. package/dist/identity/material.js +29 -0
  133. package/dist/index.d.ts +14 -13
  134. package/dist/index.js +13 -12
  135. package/dist/namespace/configure.d.ts +22 -0
  136. package/dist/namespace/configure.js +199 -0
  137. package/dist/namespace/coordinates.d.ts +15 -0
  138. package/dist/namespace/coordinates.js +49 -0
  139. package/dist/namespace/deploy-release.d.ts +53 -0
  140. package/dist/namespace/deploy-release.js +389 -0
  141. package/dist/namespace/hosting.d.ts +29 -0
  142. package/dist/namespace/hosting.js +120 -0
  143. package/dist/namespace/index.d.ts +12 -0
  144. package/dist/namespace/index.js +12 -0
  145. package/dist/namespace/list.d.ts +18 -0
  146. package/dist/namespace/list.js +63 -0
  147. package/dist/namespace/readiness.d.ts +30 -0
  148. package/dist/namespace/readiness.js +31 -0
  149. package/dist/namespace/record.d.ts +21 -0
  150. package/dist/namespace/record.js +53 -0
  151. package/dist/params.d.ts +63 -66
  152. package/dist/params.js +0 -1
  153. package/dist/release/build.d.ts +35 -0
  154. package/dist/release/build.js +44 -0
  155. package/dist/release/deployment.d.ts +44 -0
  156. package/dist/release/deployment.js +141 -0
  157. package/dist/release/index.d.ts +2 -0
  158. package/dist/release/index.js +2 -0
  159. package/dist/worker/binary.d.ts +21 -0
  160. package/dist/worker/binary.js +31 -0
  161. package/dist/worker/build-digest.d.ts +10 -0
  162. package/dist/worker/build-digest.js +22 -0
  163. package/dist/worker/cache.d.ts +28 -0
  164. package/dist/worker/cache.js +70 -0
  165. package/dist/worker/durable.d.ts +3 -0
  166. package/dist/worker/durable.js +5 -0
  167. package/dist/worker/entry.d.ts +47 -0
  168. package/dist/worker/entry.js +135 -0
  169. package/dist/worker/fetch.d.ts +11 -0
  170. package/dist/worker/fetch.js +31 -0
  171. package/dist/worker/front.d.ts +56 -0
  172. package/dist/worker/front.js +59 -0
  173. package/dist/worker/frontend.d.ts +4 -0
  174. package/dist/worker/frontend.js +83 -0
  175. package/dist/worker/identity.d.ts +7 -0
  176. package/dist/worker/identity.js +23 -0
  177. package/dist/worker/index.d.ts +6 -48
  178. package/dist/worker/index.js +6 -186
  179. package/dist/worker/restate.d.ts +6 -0
  180. package/dist/worker/restate.js +6 -0
  181. package/dist/worker/settings.d.ts +47 -0
  182. package/dist/worker/settings.js +163 -0
  183. package/dist/wrangler/bundle.d.ts +10 -0
  184. package/dist/wrangler/bundle.js +27 -0
  185. package/dist/wrangler/index.d.ts +3 -0
  186. package/dist/wrangler/index.js +3 -0
  187. package/dist/wrangler/process.d.ts +15 -0
  188. package/dist/wrangler/process.js +113 -0
  189. package/dist/wrangler/type-generation.d.ts +6 -0
  190. package/dist/wrangler/type-generation.js +19 -0
  191. package/package.json +47 -22
  192. package/template/astrale.config.ts +43 -29
  193. package/dist/build/codegen/identity.d.ts +0 -10
  194. package/dist/build/codegen/identity.d.ts.map +0 -1
  195. package/dist/build/codegen/identity.js +0 -32
  196. package/dist/build/codegen/identity.js.map +0 -1
  197. package/dist/build/codegen/merge.d.ts.map +0 -1
  198. package/dist/build/codegen/merge.js.map +0 -1
  199. package/dist/build/codegen/worker.d.ts +0 -12
  200. package/dist/build/codegen/worker.d.ts.map +0 -1
  201. package/dist/build/codegen/worker.js +0 -40
  202. package/dist/build/codegen/worker.js.map +0 -1
  203. package/dist/build/codegen/wrangler.d.ts.map +0 -1
  204. package/dist/build/codegen/wrangler.js.map +0 -1
  205. package/dist/build/frontend.d.ts +0 -26
  206. package/dist/build/frontend.d.ts.map +0 -1
  207. package/dist/build/frontend.js +0 -263
  208. package/dist/build/frontend.js.map +0 -1
  209. package/dist/build/index.d.ts.map +0 -1
  210. package/dist/build/index.js.map +0 -1
  211. package/dist/build/parse-output.d.ts +0 -27
  212. package/dist/build/parse-output.d.ts.map +0 -1
  213. package/dist/build/parse-output.js +0 -58
  214. package/dist/build/parse-output.js.map +0 -1
  215. package/dist/build/prepare.d.ts +0 -18
  216. package/dist/build/prepare.d.ts.map +0 -1
  217. package/dist/build/prepare.js +0 -117
  218. package/dist/build/prepare.js.map +0 -1
  219. package/dist/build/worker.d.ts +0 -15
  220. package/dist/build/worker.d.ts.map +0 -1
  221. package/dist/build/worker.js +0 -21
  222. package/dist/build/worker.js.map +0 -1
  223. package/dist/build/wrangler-cli.d.ts +0 -86
  224. package/dist/build/wrangler-cli.d.ts.map +0 -1
  225. package/dist/build/wrangler-cli.js +0 -275
  226. package/dist/build/wrangler-cli.js.map +0 -1
  227. package/dist/cloudflare.d.ts.map +0 -1
  228. package/dist/cloudflare.js.map +0 -1
  229. package/dist/index.d.ts.map +0 -1
  230. package/dist/index.js.map +0 -1
  231. package/dist/params.d.ts.map +0 -1
  232. package/dist/params.js.map +0 -1
  233. package/dist/worker/index.d.ts.map +0 -1
  234. package/dist/worker/index.js.map +0 -1
  235. package/src/build/codegen/identity.ts +0 -40
  236. package/src/build/codegen/merge.ts +0 -92
  237. package/src/build/codegen/worker.ts +0 -53
  238. package/src/build/codegen/wrangler.ts +0 -127
  239. package/src/build/frontend.ts +0 -324
  240. package/src/build/index.ts +0 -29
  241. package/src/build/parse-output.ts +0 -60
  242. package/src/build/prepare.ts +0 -161
  243. package/src/build/worker.ts +0 -37
  244. package/src/build/wrangler-cli.ts +0 -362
  245. package/src/cloudflare.ts +0 -251
  246. package/src/index.ts +0 -21
  247. package/src/params.ts +0 -92
  248. package/src/worker/index.ts +0 -276
  249. package/src/worker/tsconfig.json +0 -10
@@ -0,0 +1,19 @@
1
+ import { dirname, join } from 'node:path';
2
+ import { runCapture, wranglerCommand } from './process.js';
3
+ export async function runWranglerTypes(args) {
4
+ const { cmd, prefix } = wranglerCommand(args.projectDir);
5
+ const outputPath = join(dirname(args.configPath), 'worker-configuration.d.ts');
6
+ const { code, out } = await runCapture(cmd, [
7
+ ...prefix,
8
+ 'types',
9
+ outputPath,
10
+ '--env-interface',
11
+ 'CloudflareEnv',
12
+ '--config',
13
+ args.configPath,
14
+ ], args.projectDir, args.onLog, args.signal);
15
+ if (code !== 0) {
16
+ throw new Error(`wrangler types failed (code ${code}):\n${out.slice(-2000)}`);
17
+ }
18
+ return outputPath;
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrale-os/adapter-cloudflare",
3
- "version": "0.5.0-beta.2",
4
- "description": "Deploy an Astrale domain as a standalone Cloudflare Worker",
3
+ "version": "0.5.0-beta.200",
4
+ "description": "Deploy an Astrale Domain through Cloudflare Workers",
5
5
  "keywords": [
6
6
  "adapter",
7
7
  "astrale",
@@ -11,16 +11,21 @@
11
11
  ],
12
12
  "license": "Apache-2.0",
13
13
  "author": "Astrale",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/astrale-os/sdk.git"
17
+ },
14
18
  "files": [
15
19
  "dist",
16
- "src",
20
+ "!dist/**/*.map",
17
21
  "template",
18
- "!template/node_modules",
19
- "!template/pnpm-lock.yaml"
22
+ "!template/**/node_modules",
23
+ "!template/**/node_modules/**",
24
+ "!template/**/pnpm-lock.yaml"
20
25
  ],
21
26
  "type": "module",
22
- "main": "./src/index.ts",
23
- "types": "./src/index.ts",
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
24
29
  "exports": {
25
30
  ".": {
26
31
  "types": "./dist/index.d.ts",
@@ -34,34 +39,54 @@
34
39
  "types": "./dist/worker/index.d.ts",
35
40
  "import": "./dist/worker/index.js"
36
41
  },
37
- "./package.json": "./package.json"
42
+ "./worker/front": {
43
+ "types": "./dist/worker/front.d.ts",
44
+ "import": "./dist/worker/front.js"
45
+ },
46
+ "./hosting": {
47
+ "types": "./dist/hosting/index.d.ts",
48
+ "import": "./dist/hosting/index.js"
49
+ },
50
+ "./hosting/testing": {
51
+ "types": "./dist/hosting/testing/index.d.ts",
52
+ "import": "./dist/hosting/testing/index.js"
53
+ },
54
+ "./package.json": "./package.json",
55
+ "./worker/restate": {
56
+ "types": "./dist/worker/restate.d.ts",
57
+ "import": "./dist/worker/restate.js"
58
+ }
59
+ },
60
+ "publishConfig": {
61
+ "registry": "https://registry.npmjs.org/"
38
62
  },
39
63
  "dependencies": {
40
- "@astrale-os/kernel-core": "0.9.0-beta.1",
41
- "@astrale-os/kernel-dsl": "0.2.0-beta.1",
64
+ "@astrale-os/sdk": "0.6.0-beta.45",
65
+ "@noble/hashes": "2.3.0",
66
+ "@restatedev/restate-sdk-cloudflare-workers": "1.17.0",
42
67
  "hono": "^4.6.20",
43
68
  "jose": "^6.1.3",
44
- "@astrale-os/sdk": "^0.5.0-beta.1"
69
+ "wrangler": "4.123.0"
45
70
  },
46
71
  "devDependencies": {
47
- "@astrale-os/ox": ">=0.1.0 <1.0.0",
48
- "@types/node": "^22.0.0",
49
- "@typescript/native-preview": "latest",
50
- "oxfmt": "0.52.0",
51
- "oxlint": "latest",
52
- "typescript": "~6.0.1-rc",
53
- "vitest": "^3.0.0",
54
- "wrangler": "4.121.0"
72
+ "@astrale-os/ox": "0.1.4",
73
+ "@cloudflare/workers-types": "^5.20260820.1",
74
+ "@types/node": "^24.0.0",
75
+ "oxfmt": "0.63.0",
76
+ "oxlint": "1.78.0",
77
+ "typescript": "7.0.2",
78
+ "vitest": "^5.0.1",
79
+ "zod": "4.4.3"
55
80
  },
56
81
  "engines": {
57
- "node": ">=22"
82
+ "node": ">=24"
58
83
  },
59
84
  "scripts": {
60
- "typecheck": "tsgo --noEmit",
85
+ "typecheck": "tsc --noEmit && tsc --noEmit -p src/worker/tsconfig.json && tsc --noEmit -p src/hosting/tsconfig.json && tsc --noEmit -p src/hosting/dispatcher/tsconfig.json && tsc --noEmit -p tsconfig.test.json && tsc --noEmit -p __tests__/tsconfig.types.json",
61
86
  "test": "vitest run",
62
87
  "lint": "oxlint --disable-nested-config .",
63
88
  "format": "pnpm exec oxfmt --write .",
64
89
  "format:check": "pnpm exec oxfmt --check .",
65
- "build": "rm -rf dist && tsgo"
90
+ "build": "rm -rf dist && tsc && node scripts/copy-dispatcher.mjs && node ../scripts/verify-no-source-maps.mjs dist && node scripts/check-pack.mjs"
66
91
  }
67
92
  }
@@ -1,37 +1,51 @@
1
1
  /**
2
- * astrale.config.ts — binds the worker-safe composition (`implementation.ts`) to its deploy
3
- * adapter for the `astrale-domain` CLI. This is a NODE-only module: it imports
4
- * the adapter (wrangler + filesystem). The generated worker never imports this
5
- * file — it imports `implementation.ts` directly — so the adapter stays out of the bundle.
2
+ * One Project definition, with explicit software-factory Environments.
6
3
  *
7
- * This variant deploys to YOUR OWN Cloudflare account (the `cloudflare` adapter).
4
+ * Every Environment deploys into a Workers for Platforms dispatch namespace
5
+ * (namespace mode), on your own Cloudflare account and domain once
6
+ * `astrale-domain cloudflare init <environment>` provisioned it, or on a platform
7
+ * namespace you are given. `astrale-domain deploy <environment>` makes one immutable
8
+ * deployment of this release, at its own URL under the namespace's routing
9
+ * domain, with a signing key generated for it, and prints that URL. A deploy
10
+ * never installs the Domain: install the URL it prints with
11
+ * `astrale domain install <url> -i <instance>`. Redeploying the same
12
+ * release reuses its deployment; a changed secrets file is then rewritten in
13
+ * place on that deployment only.
8
14
  *
9
- * pnpm dev # wrangler dev → prints a local URL
10
- * astrale domain install <url> --direct # mount the dev URL on an instance
11
- * pnpm prod # deploy to your Cloudflare account
15
+ * `CLOUDFLARE_API_TOKEN` must edit the namespace's scripts and its routing KV,
16
+ * and `CLOUDFLARE_ACCOUNT_ID` names the account that holds it unless
17
+ * `namespace.account` does. Neither token nor secret is written here.
12
18
  */
13
19
  import { cloudflare } from '@astrale-os/adapter-cloudflare'
14
- import { deploy } from '@astrale-os/sdk'
15
- // No Cloudflare account? Swap the adapter for the Astrale-managed one — it
16
- // publishes the same bundle THROUGH the platform and installs it on your
17
- // instance (auth = your `astrale auth login` session):
18
- //
19
- // import { astrale } from '@astrale-os/adapter-astrale'
20
- // export default deploy(domain, astrale({
21
- // dev: { secrets: '.env.dev' }, // local wrangler dev
22
- // prod: { instance: '<your-instance-slug>' }, // managed deploy
23
- // }))
20
+ import { defineProject } from '@astrale-os/sdk/project'
21
+ import { dataset, tests } from '@astrale-os/sdk/testing'
24
22
 
25
- import { domain } from './implementation'
23
+ import { domain } from './domain.js'
26
24
 
27
- export default deploy(
25
+ /**
26
+ * The dispatch namespace and the DNS name its dispatcher answers under. Replace
27
+ * both placeholders, then provision them once on your account with
28
+ * `astrale-domain cloudflare init production` (a domain on Cloudflare dedicated
29
+ * to the deployments, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`). A deploy
30
+ * finds the namespace's routing KV from its name and refuses, before any
31
+ * effect, a namespace without one.
32
+ */
33
+ const namespace = { name: 'your-platform-namespace', routingDomain: 'deployments.example.dev' }
34
+
35
+ export default defineProject({
28
36
  domain,
29
- cloudflare({
30
- // Local dev: `wrangler dev`. No route → URL is http://localhost:8787.
31
- dev: { secrets: '.env.dev' },
32
- // Custom-domain prod. Drop `route` to ship to *.workers.dev instead.
33
- prod: { route: 'astrale-domain.example.dev', secrets: '.env.prod' },
34
- // Author secrets ship via `secrets: '.env.prod'` on any env. Extra bindings
35
- // (KV, R2, D1, queues, …) ride a `wrangler` block on any env (deep-merged).
36
- }),
37
- )
37
+
38
+ environments: {
39
+ development: {
40
+ deployment: cloudflare({ namespace, secrets: '.env.dev' }),
41
+ },
42
+
43
+ production: {
44
+ deployment: cloudflare({ namespace }),
45
+ },
46
+ },
47
+
48
+ // Test resources belong to the Project. CI selects an Environment and named
49
+ // suite when a test execution needs a live deployment.
50
+ tests: tests({ datasets: [dataset('./tests/datasets/demo.ts')] }),
51
+ })
@@ -1,10 +0,0 @@
1
- /**
2
- * Ensure the domain has a stable Ed25519 signing identity at
3
- * `.astrale/identity.ts`. Generated ONCE (first `dev`/`deploy` or by the
4
- * scaffolder) and never regenerated — the private key IS the domain's identity,
5
- * so rotating it would orphan every instance that installed the old key. The
6
- * file is gitignored; for real production this key should graduate to a managed
7
- * secret.
8
- */
9
- export declare function ensureIdentity(astraleDir: string, origin: string): Promise<void>;
10
- //# sourceMappingURL=identity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/build/codegen/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBtF"}
@@ -1,32 +0,0 @@
1
- /**
2
- * Ensure the domain has a stable Ed25519 signing identity at
3
- * `.astrale/identity.ts`. Generated ONCE (first `dev`/`deploy` or by the
4
- * scaffolder) and never regenerated — the private key IS the domain's identity,
5
- * so rotating it would orphan every instance that installed the old key. The
6
- * file is gitignored; for real production this key should graduate to a managed
7
- * secret.
8
- */
9
- import { exportJWK, generateKeyPair } from 'jose';
10
- import { existsSync } from 'node:fs';
11
- import { mkdir, writeFile } from 'node:fs/promises';
12
- import { join } from 'node:path';
13
- export async function ensureIdentity(astraleDir, origin) {
14
- const file = join(astraleDir, 'identity.ts');
15
- if (existsSync(file))
16
- return;
17
- const { privateKey } = await generateKeyPair('EdDSA', { extractable: true });
18
- const jwk = (await exportJWK(privateKey));
19
- jwk.alg = 'EdDSA';
20
- jwk.kid = `${origin}-key`;
21
- await mkdir(astraleDir, { recursive: true });
22
- await writeFile(file, `// AUTO-GENERATED stable signing identity for "${origin}" — do not edit, do not commit.\n` +
23
- `export const PRIVATE_JWK = ${JSON.stringify(jwk, null, 2)} as const\n`);
24
- // Loud on purpose: the file is gitignored, so a fresh clone / CI runner
25
- // silently mints a NEW key — and a redeploy with a new key breaks JWKS
26
- // verification on every instance that installed the old one, with no hint
27
- // why. Make the lifecycle visible the one time it happens.
28
- process.stderr.write(`\x1b[33m!\x1b[0m new signing identity generated at .astrale/identity.ts (kid ${String(jwk.kid)}).\n` +
29
- ` This key IS "${origin}"'s identity: back it up (or move it to a managed secret) —\n` +
30
- ` deploying from another machine without it re-keys the domain and breaks existing installs.\n`);
31
- }
32
- //# sourceMappingURL=identity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../src/build/codegen/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,UAAkB,EAAE,MAAc;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;IAC5C,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAM;IAE5B,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5E,MAAM,GAAG,GAAG,CAAC,MAAM,SAAS,CAAC,UAAU,CAAC,CAA4B,CAAA;IACpE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAA;IACjB,GAAG,CAAC,GAAG,GAAG,GAAG,MAAM,MAAM,CAAA;IAEzB,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5C,MAAM,SAAS,CACb,IAAI,EACJ,kDAAkD,MAAM,mCAAmC;QACzF,8BAA8B,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,aAAa,CAC1E,CAAA;IAED,wEAAwE;IACxE,uEAAuE;IACvE,0EAA0E;IAC1E,2DAA2D;IAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,gFAAgF,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM;QACnG,kBAAkB,MAAM,+DAA+D;QACvF,gGAAgG,CACnG,CAAA;AACH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/build/codegen/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/build/codegen/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA6B,EAC7B,OAAgC;IAEhC,MAAM,GAAG,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAA;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACrB,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,IAAI,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B,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,IAAa;IAChC,MAAM,GAAG,GAAG,IAA+B,CAAA;IAC3C,KAAK,MAAM,KAAK,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;QAC5D,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,QAAQ;YAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,KAAK,CAAW,EAAE,CAAA;IAC/E,CAAC;IACD,IAAI,CAAC;QACH,OAAO,QAAQ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AACjE,CAAC;AAED,SAAS,WAAW,CAAC,CAAU;IAC7B,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,UAAU,CAAC,CAAA;AACzE,CAAC"}
@@ -1,12 +0,0 @@
1
- /** Codegen for the Cloudflare module entry owned by the adapter. */
2
- export interface WorkerCodegenOptions {
3
- readonly origin: string;
4
- /** Optional same-zone routing service selected by the adapter environment. */
5
- readonly router?: {
6
- readonly binding: string;
7
- readonly hostSuffix: string;
8
- readonly minLabels: number;
9
- };
10
- }
11
- export declare function generateWorkerEntry(options: WorkerCodegenOptions): string;
12
- //# sourceMappingURL=worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/build/codegen/worker.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;QAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAC3B,CAAA;CACF;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAwCzE"}
@@ -1,40 +0,0 @@
1
- /** Codegen for the Cloudflare module entry owned by the adapter. */
2
- export function generateWorkerEntry(options) {
3
- const router = options.router;
4
- const routerPredicate = router === undefined
5
- ? ''
6
- : `
7
- function isInstanceHost(host: string): boolean {
8
- return host.endsWith('${router.hostSuffix}') && host.split('.').length >= ${router.minLabels}
9
- }
10
- `;
11
- const routeSubrequest = router === undefined
12
- ? ''
13
- : `
14
- routeSubrequest: (url, env) => {
15
- const labels = url.hostname.split('.')
16
- if (env.DISPATCHER && labels[1] === 'svc') return env.DISPATCHER.get(labels[0]!)
17
- if (env.${router.binding} && isInstanceHost(url.hostname)) return env.${router.binding}
18
- return null
19
- },`;
20
- return `// AUTO-GENERATED by @astrale-os/adapter-cloudflare — do not edit.
21
- // Regenerated by every Astrale Domain build, dev, and deploy operation.
22
- // Domain origin: ${options.origin}
23
- import type { CloudflareAdapterBindings } from '@astrale-os/adapter-cloudflare/worker'
24
- import type { ApplicationEnvironment } from '../implementation.js'
25
-
26
- import { cloudflareWorkerEntry } from '@astrale-os/adapter-cloudflare/worker'
27
- import { domain } from '../implementation.js'
28
- import { PRIVATE_JWK } from './identity.js'
29
-
30
- type WorkerEnv = CloudflareEnv & ApplicationEnvironment & CloudflareAdapterBindings
31
- ${routerPredicate}
32
- export default cloudflareWorkerEntry<WorkerEnv>()({
33
- definition: domain,
34
- privateKey: PRIVATE_JWK,
35
- resolveUrl: (env, requestOrigin) => env.WORKER_URL ?? requestOrigin,
36
- selfBinding: (env) => env.SELF,${routeSubrequest}
37
- })
38
- `;
39
- }
40
- //# sourceMappingURL=worker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/build/codegen/worker.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAYpE,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC7B,MAAM,eAAe,GACnB,MAAM,KAAK,SAAS;QAClB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;;0BAEkB,MAAM,CAAC,UAAU,mCAAmC,MAAM,CAAC,SAAS;;CAE7F,CAAA;IACC,MAAM,eAAe,GACnB,MAAM,KAAK,SAAS;QAClB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;;;;cAIM,MAAM,CAAC,OAAO,gDAAgD,MAAM,CAAC,OAAO;;KAErF,CAAA;IAEH,OAAO;;oBAEW,OAAO,CAAC,MAAM;;;;;;;;;EAShC,eAAe;;;;;mCAKkB,eAAe;;CAEjD,CAAA;AACD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../../src/build/codegen/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0EAA0E;IAC1E,QAAQ,CAAC,EAAE;QACT,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;QAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;KACnC,CAAA;IACD,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,kDAAkD;IAClD,WAAW,EAAE,OAAO,CAAA;IACpB;;;;OAI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,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAA;IAC9D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qDAAqD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC5E,gEAAgE;YAChE,mDAAmD,CACtD,CAAA;IACH,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACpC,CAAC"}
@@ -1,26 +0,0 @@
1
- import type { CompiledFrontendArtifact, DomainDefinition } from '@astrale-os/sdk';
2
- export declare const FRONTEND_STAGE_DIR = ".astrale/frontend";
3
- /** Materialize one Domain-owned frontend recipe into an immutable adapter artifact. */
4
- export declare function buildFrontend(input: {
5
- readonly definition: DomainDefinition;
6
- readonly projectDir: string;
7
- readonly onLog?: (line: string) => void;
8
- }): Promise<CompiledFrontendArtifact | undefined>;
9
- export interface FrontendWatchHandle {
10
- stop(): Promise<void>;
11
- }
12
- export interface FrontendWatchSubscription {
13
- close(): void;
14
- }
15
- export type FrontendWatchSubscribe = (root: string, onChange: (path?: string) => void, onError: (error: Error) => void) => FrontendWatchSubscription;
16
- /** Keep Wrangler's materialized frontend stage current without owning config regeneration. */
17
- export declare function watchFrontend(input: {
18
- readonly definition: DomainDefinition;
19
- readonly projectDir: string;
20
- readonly onLog?: (line: string) => void;
21
- readonly onRebuild?: () => void;
22
- readonly delayMs?: number;
23
- readonly build?: typeof buildFrontend;
24
- readonly subscribe?: FrontendWatchSubscribe;
25
- }): FrontendWatchHandle | undefined;
26
- //# sourceMappingURL=frontend.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../src/build/frontend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAA;AAU/F,eAAO,MAAM,kBAAkB,sBAAsB,CAAA;AAKrD,uFAAuF;AACvF,wBAAsB,aAAa,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAA;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC,GAAG,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAgBhD;AAgED,MAAM,WAAW,mBAAmB;IAClC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,IAAI,IAAI,CAAA;CACd;AAED,MAAM,MAAM,sBAAsB,GAAG,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,EACjC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAC5B,yBAAyB,CAAA;AAE9B,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAA;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,aAAa,CAAA;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAA;CAC5C,GAAG,mBAAmB,GAAG,SAAS,CAwElC"}
@@ -1,263 +0,0 @@
1
- import { compileFrontend } from '@astrale-os/sdk';
2
- import { compileReactEntrypoint } from '@astrale-os/sdk/react';
3
- import { spawn } from 'node:child_process';
4
- import { watch } from 'node:fs';
5
- import { mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
6
- import { dirname, join, resolve, sep } from 'node:path';
7
- export const FRONTEND_STAGE_DIR = '.astrale/frontend';
8
- const FRONTEND_REBUILD_DELAY_MS = 75;
9
- let stageGeneration = 0;
10
- const buildQueues = new Map();
11
- /** Materialize one Domain-owned frontend recipe into an immutable adapter artifact. */
12
- export async function buildFrontend(input) {
13
- const key = resolve(input.projectDir);
14
- const previous = buildQueues.get(key) ?? Promise.resolve();
15
- let release = () => { };
16
- const current = new Promise((resolveBuild) => {
17
- release = resolveBuild;
18
- });
19
- const tail = previous.then(() => current);
20
- buildQueues.set(key, tail);
21
- await previous;
22
- try {
23
- return await buildFrontendUnlocked(input);
24
- }
25
- finally {
26
- release();
27
- if (buildQueues.get(key) === tail)
28
- buildQueues.delete(key);
29
- }
30
- }
31
- async function buildFrontendUnlocked(input) {
32
- const artifact = input.definition.frontend;
33
- if (artifact === undefined)
34
- return undefined;
35
- if (artifact.source.kind === 'external') {
36
- return compileFrontend({
37
- artifact,
38
- files: [],
39
- provenance: { adapter: 'cloudflare', source: 'external' },
40
- });
41
- }
42
- let files;
43
- if (artifact.source.kind === 'generated') {
44
- files = artifact.source.files.map((file) => ({
45
- path: file.path,
46
- content: typeof file.content === 'string' ? new TextEncoder().encode(file.content) : file.content,
47
- ...(file.mediaType === undefined ? {} : { mediaType: file.mediaType }),
48
- }));
49
- }
50
- else if (artifact.source.kind === 'prebuilt') {
51
- files = await readFiles(contained(input.projectDir, artifact.source.directory, 'prebuilt frontend'));
52
- }
53
- else {
54
- if (isReactFrontend(artifact)) {
55
- const root = contained(input.projectDir, artifact.source.root, 'React frontend root');
56
- for (const file of compileReactEntrypoint(artifact)) {
57
- const path = contained(root, file.path, 'generated React entrypoint');
58
- await mkdir(dirname(path), { recursive: true });
59
- await writeFile(path, file.content);
60
- }
61
- }
62
- const output = contained(input.projectDir, artifact.source.outDir, 'Vite frontend output');
63
- await rm(output, { recursive: true, force: true });
64
- await runBuild(artifact.source.command[0], [
65
- ...artifact.source.command.slice(1),
66
- artifact.source.root,
67
- '--outDir',
68
- output,
69
- '--emptyOutDir',
70
- ], input.projectDir, input.onLog);
71
- files = await readFiles(output);
72
- }
73
- const compiled = await compileFrontend({
74
- artifact,
75
- baseHref: 'https://frontend.invalid/',
76
- files,
77
- provenance: { adapter: 'cloudflare', source: artifact.source.kind },
78
- });
79
- await replaceStage(input.projectDir, compiled.files);
80
- return compiled;
81
- }
82
- /** Keep Wrangler's materialized frontend stage current without owning config regeneration. */
83
- export function watchFrontend(input) {
84
- const artifact = input.definition.frontend;
85
- if (artifact === undefined ||
86
- artifact.source.kind === 'external' ||
87
- artifact.source.kind === 'generated')
88
- return undefined;
89
- const source = artifact.source;
90
- const root = source.kind === 'prebuilt'
91
- ? contained(input.projectDir, source.directory, 'prebuilt frontend watch root')
92
- : resolve(input.projectDir);
93
- const build = input.build ?? buildFrontend;
94
- const subscribe = input.subscribe ?? subscribeToFrontend;
95
- const delayMs = input.delayMs ?? FRONTEND_REBUILD_DELAY_MS;
96
- let stopped = false;
97
- let pending = false;
98
- let timer;
99
- let running;
100
- const drain = async () => {
101
- if (stopped || running !== undefined || !pending)
102
- return;
103
- pending = false;
104
- running = (async () => {
105
- try {
106
- await build({
107
- definition: input.definition,
108
- projectDir: input.projectDir,
109
- onLog: input.onLog,
110
- });
111
- if (!stopped)
112
- input.onRebuild?.();
113
- }
114
- catch (error) {
115
- input.onLog?.(`frontend rebuild failed; keeping the last good stage: ${error instanceof Error ? error.message : String(error)}`);
116
- }
117
- })();
118
- await running;
119
- running = undefined;
120
- if (!stopped && pending) {
121
- timer = setTimeout(() => {
122
- timer = undefined;
123
- void drain();
124
- }, delayMs);
125
- }
126
- };
127
- const schedule = (path) => {
128
- if (stopped || !rebuildsFor(source, path))
129
- return;
130
- pending = true;
131
- if (timer !== undefined)
132
- clearTimeout(timer);
133
- timer = setTimeout(() => {
134
- timer = undefined;
135
- void drain();
136
- }, delayMs);
137
- };
138
- const subscription = subscribe(root, schedule, (error) => {
139
- input.onLog?.(`frontend watcher failed: ${error.message}`);
140
- });
141
- return Object.freeze({
142
- async stop() {
143
- if (stopped)
144
- return;
145
- stopped = true;
146
- pending = false;
147
- if (timer !== undefined)
148
- clearTimeout(timer);
149
- timer = undefined;
150
- subscription.close();
151
- await running;
152
- },
153
- });
154
- }
155
- function isReactFrontend(artifact) {
156
- return (artifact !== undefined && artifact.framework === 'react');
157
- }
158
- async function readFiles(root, current = '') {
159
- const directory = join(root, current);
160
- const entries = await readdir(directory, { withFileTypes: true });
161
- const files = [];
162
- for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
163
- const path = current === '' ? entry.name : `${current}/${entry.name}`;
164
- if (entry.isDirectory())
165
- files.push(...(await readFiles(root, path)));
166
- else if (entry.isFile())
167
- files.push({ path, content: new Uint8Array(await readFile(join(root, path))) });
168
- }
169
- return files;
170
- }
171
- async function replaceStage(projectDir, files) {
172
- const stage = contained(projectDir, FRONTEND_STAGE_DIR, 'frontend stage');
173
- const generation = `${process.pid}-${++stageGeneration}`;
174
- const next = `${stage}.next-${generation}`;
175
- const previous = `${stage}.previous-${generation}`;
176
- await rm(next, { recursive: true, force: true });
177
- await mkdir(next, { recursive: true });
178
- try {
179
- for (const file of files) {
180
- const path = contained(next, file.path, 'staged frontend file');
181
- await mkdir(dirname(path), { recursive: true });
182
- await writeFile(path, file.content);
183
- }
184
- await rm(previous, { recursive: true, force: true });
185
- let retainedPrevious = false;
186
- try {
187
- await rename(stage, previous);
188
- retainedPrevious = true;
189
- }
190
- catch (error) {
191
- if (!isMissing(error))
192
- throw error;
193
- }
194
- try {
195
- await rename(next, stage);
196
- }
197
- catch (error) {
198
- if (retainedPrevious)
199
- await rename(previous, stage);
200
- throw error;
201
- }
202
- if (retainedPrevious)
203
- await rm(previous, { recursive: true, force: true });
204
- }
205
- finally {
206
- await rm(next, { recursive: true, force: true });
207
- }
208
- }
209
- function subscribeToFrontend(root, onChange, onError) {
210
- const watcher = watch(root, { recursive: true }, (_event, path) => {
211
- onChange(path === null ? undefined : String(path));
212
- });
213
- watcher.on('error', onError);
214
- return watcher;
215
- }
216
- function rebuildsFor(source, path) {
217
- if (path === undefined || source.kind === 'prebuilt')
218
- return true;
219
- const normalized = path.replaceAll('\\', '/');
220
- if (normalized === '.astrale' ||
221
- normalized.startsWith('.astrale/') ||
222
- normalized === 'node_modules' ||
223
- normalized.startsWith('node_modules/') ||
224
- normalized === '.git' ||
225
- normalized.startsWith('.git/'))
226
- return false;
227
- const outDir = source.outDir.replace(/^\.\//u, '');
228
- if (normalized === outDir || normalized.startsWith(`${outDir}/`))
229
- return false;
230
- const root = source.root.replace(/^\.\//u, '');
231
- return normalized !== `${root}/astrale.generated.tsx` && normalized !== `${root}/index.html`;
232
- }
233
- function isMissing(error) {
234
- return error instanceof Error && 'code' in error && error.code === 'ENOENT';
235
- }
236
- function contained(root, input, label) {
237
- const base = resolve(root);
238
- const target = resolve(base, input);
239
- if (target !== base && !target.startsWith(`${base}${sep}`)) {
240
- throw new TypeError(`${label} must remain within the Domain project root.`);
241
- }
242
- return target;
243
- }
244
- function runBuild(command, args, cwd, onLog) {
245
- return new Promise((resolveBuild, reject) => {
246
- const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
247
- let output = '';
248
- const collect = (buffer) => {
249
- const value = buffer.toString();
250
- output += value;
251
- for (const line of value.split('\n'))
252
- if (line.trim() !== '')
253
- onLog?.(line);
254
- };
255
- child.stdout?.on('data', collect);
256
- child.stderr?.on('data', collect);
257
- child.on('error', reject);
258
- child.on('exit', (code) => code === 0
259
- ? resolveBuild()
260
- : reject(new Error(`frontend build failed (code ${code ?? 1}):\n${output.slice(-1500)}`)));
261
- });
262
- }
263
- //# sourceMappingURL=frontend.js.map