@runeditrun/rer 0.2.77 → 0.2.79

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 (167) hide show
  1. package/README.md +32 -0
  2. package/cli/export.mjs +1 -1
  3. package/cli/portability-migrations.mjs +35 -14
  4. package/cli/portability-worker.mjs +2 -2
  5. package/cli/portability.mjs +2 -2
  6. package/cli/server-proxy.mjs +30 -8
  7. package/cli/upstream-agent.mjs +14 -0
  8. package/global/CHANGELOG.md +13 -0
  9. package/global/README.md +32 -0
  10. package/modules/demo-host/native/visitor.mjs +1 -1
  11. package/modules/deploy-kit/owner-cli.mjs +15 -5
  12. package/modules/deploy-kit/provider.mjs +9 -4
  13. package/modules/import-kit/src/d1/README.md +1322 -0
  14. package/modules/import-kit/src/d1/apply.ts +115 -0
  15. package/modules/import-kit/src/d1/budget.ts +89 -0
  16. package/modules/import-kit/src/d1/compressed-plan.ts +63 -0
  17. package/modules/import-kit/src/d1/creation.ts +95 -0
  18. package/modules/import-kit/src/d1/custody-fence.ts +27 -0
  19. package/modules/import-kit/src/d1/custody-state-schema.ts +67 -0
  20. package/modules/import-kit/src/d1/database.ts +163 -0
  21. package/modules/import-kit/src/d1/entry-locator.ts +61 -0
  22. package/modules/import-kit/src/d1/erased-artifacts.ts +38 -0
  23. package/modules/import-kit/src/d1/erased-custody.ts +36 -0
  24. package/modules/import-kit/src/d1/erased-plan.ts +47 -0
  25. package/modules/import-kit/src/d1/erased-reversal.ts +19 -0
  26. package/modules/import-kit/src/d1/erasure-bounded.ts +22 -0
  27. package/modules/import-kit/src/d1/erasure-claims.ts +27 -0
  28. package/modules/import-kit/src/d1/erasure-compiler.ts +67 -0
  29. package/modules/import-kit/src/d1/erasure-disposition.ts +16 -0
  30. package/modules/import-kit/src/d1/erasure-fragments.ts +86 -0
  31. package/modules/import-kit/src/d1/erasure-index.ts +53 -0
  32. package/modules/import-kit/src/d1/erasure-pages.ts +62 -0
  33. package/modules/import-kit/src/d1/erasure-progress-schema.ts +8 -0
  34. package/modules/import-kit/src/d1/erasure-progress.ts +61 -0
  35. package/modules/import-kit/src/d1/erasure-related.ts +124 -0
  36. package/modules/import-kit/src/d1/erasure-report.ts +31 -0
  37. package/modules/import-kit/src/d1/erasure-schema.ts +24 -0
  38. package/modules/import-kit/src/d1/erasure-selection.ts +77 -0
  39. package/modules/import-kit/src/d1/erasure-snapshot.ts +15 -0
  40. package/modules/import-kit/src/d1/erasure-stage.ts +146 -0
  41. package/modules/import-kit/src/d1/erasure-step.ts +12 -0
  42. package/modules/import-kit/src/d1/erasure-superseded.ts +98 -0
  43. package/modules/import-kit/src/d1/erasure-values.ts +83 -0
  44. package/modules/import-kit/src/d1/erasure-writes.ts +46 -0
  45. package/modules/import-kit/src/d1/erasure.ts +170 -0
  46. package/modules/import-kit/src/d1/evolutions/0001-preserved-undo.ts +13 -0
  47. package/modules/import-kit/src/d1/expected-state.ts +91 -0
  48. package/modules/import-kit/src/d1/field-redaction.ts +86 -0
  49. package/modules/import-kit/src/d1/guards.ts +37 -0
  50. package/modules/import-kit/src/d1/history.ts +71 -0
  51. package/modules/import-kit/src/d1/index.ts +88 -0
  52. package/modules/import-kit/src/d1/integrity.ts +127 -0
  53. package/modules/import-kit/src/d1/inventory-snapshot.ts +84 -0
  54. package/modules/import-kit/src/d1/jobs.ts +97 -0
  55. package/modules/import-kit/src/d1/native-set.ts +48 -0
  56. package/modules/import-kit/src/d1/native-staging-admission.ts +19 -0
  57. package/modules/import-kit/src/d1/native-staging-context.ts +44 -0
  58. package/modules/import-kit/src/d1/native-staging-lifecycle.ts +33 -0
  59. package/modules/import-kit/src/d1/native-staging-offset.ts +74 -0
  60. package/modules/import-kit/src/d1/native-staging-publication.ts +18 -0
  61. package/modules/import-kit/src/d1/native-staging-rows.ts +72 -0
  62. package/modules/import-kit/src/d1/native-staging-schema.ts +28 -0
  63. package/modules/import-kit/src/d1/native-staging-state.ts +22 -0
  64. package/modules/import-kit/src/d1/native-staging.ts +64 -0
  65. package/modules/import-kit/src/d1/original-copies.ts +53 -0
  66. package/modules/import-kit/src/d1/original-storage.ts +56 -0
  67. package/modules/import-kit/src/d1/originals.ts +74 -0
  68. package/modules/import-kit/src/d1/plan-dictionary.ts +80 -0
  69. package/modules/import-kit/src/d1/plans.ts +121 -0
  70. package/modules/import-kit/src/d1/preparation-fingerprint.ts +57 -0
  71. package/modules/import-kit/src/d1/preparation-header.ts +33 -0
  72. package/modules/import-kit/src/d1/preparation-reader.ts +98 -0
  73. package/modules/import-kit/src/d1/preparation-schema.ts +16 -0
  74. package/modules/import-kit/src/d1/preparation-state.ts +56 -0
  75. package/modules/import-kit/src/d1/preparation-step-combine.ts +80 -0
  76. package/modules/import-kit/src/d1/preparation-step-control.ts +48 -0
  77. package/modules/import-kit/src/d1/preparation-step-hash.ts +131 -0
  78. package/modules/import-kit/src/d1/preparation-step-pages.ts +77 -0
  79. package/modules/import-kit/src/d1/preparation-steps-schema.ts +11 -0
  80. package/modules/import-kit/src/d1/preparation-steps.ts +102 -0
  81. package/modules/import-kit/src/d1/preparations.ts +87 -0
  82. package/modules/import-kit/src/d1/preserved-preview.ts +89 -0
  83. package/modules/import-kit/src/d1/preserved-reverse.ts +91 -0
  84. package/modules/import-kit/src/d1/provenance-set.ts +87 -0
  85. package/modules/import-kit/src/d1/publication-fence.ts +22 -0
  86. package/modules/import-kit/src/d1/publication-receipt-schema.ts +15 -0
  87. package/modules/import-kit/src/d1/published-stream.ts +11 -0
  88. package/modules/import-kit/src/d1/read-fence.ts +64 -0
  89. package/modules/import-kit/src/d1/read-results.ts +16 -0
  90. package/modules/import-kit/src/d1/redacted-custody.ts +76 -0
  91. package/modules/import-kit/src/d1/redaction-step.ts +125 -0
  92. package/modules/import-kit/src/d1/referenced-plans.ts +136 -0
  93. package/modules/import-kit/src/d1/retained-values.ts +35 -0
  94. package/modules/import-kit/src/d1/retirement-bounded.ts +71 -0
  95. package/modules/import-kit/src/d1/retirement-door.ts +105 -0
  96. package/modules/import-kit/src/d1/retirement-schema.ts +39 -0
  97. package/modules/import-kit/src/d1/retirement-scope.ts +94 -0
  98. package/modules/import-kit/src/d1/retirement-steps.ts +76 -0
  99. package/modules/import-kit/src/d1/retirement-tally.ts +74 -0
  100. package/modules/import-kit/src/d1/retirement.ts +136 -0
  101. package/modules/import-kit/src/d1/reversal-conversion-record.ts +19 -0
  102. package/modules/import-kit/src/d1/reversal-conversion-schema.ts +11 -0
  103. package/modules/import-kit/src/d1/reversal-conversion.ts +40 -0
  104. package/modules/import-kit/src/d1/reversal-fence-schema.ts +14 -0
  105. package/modules/import-kit/src/d1/reversal-fence.ts +106 -0
  106. package/modules/import-kit/src/d1/reversal-journal.ts +24 -0
  107. package/modules/import-kit/src/d1/reverse.ts +103 -0
  108. package/modules/import-kit/src/d1/reviewed-source.ts +23 -0
  109. package/modules/import-kit/src/d1/sets.ts +78 -0
  110. package/modules/import-kit/src/d1/staged-creation.ts +201 -0
  111. package/modules/import-kit/src/d1/staging-admission.ts +45 -0
  112. package/modules/import-kit/src/d1/staging-control.ts +43 -0
  113. package/modules/import-kit/src/d1/staging-erasure.ts +28 -0
  114. package/modules/import-kit/src/d1/staging-lifecycle.ts +49 -0
  115. package/modules/import-kit/src/d1/staging-plan.ts +15 -0
  116. package/modules/import-kit/src/d1/staging-privacy.ts +22 -0
  117. package/modules/import-kit/src/d1/staging-publication.ts +79 -0
  118. package/modules/import-kit/src/d1/staging-schema.ts +37 -0
  119. package/modules/import-kit/src/d1/staging-statements.ts +8 -0
  120. package/modules/import-kit/src/d1/staging-transport.ts +70 -0
  121. package/modules/import-kit/src/d1/stream-boundary.ts +11 -0
  122. package/modules/import-kit/src/d1/stream-create.ts +55 -0
  123. package/modules/import-kit/src/d1/stream-identity-admission.ts +37 -0
  124. package/modules/import-kit/src/d1/stream-input.ts +18 -0
  125. package/modules/import-kit/src/d1/stream-layout.ts +43 -0
  126. package/modules/import-kit/src/d1/stream-origin.ts +44 -0
  127. package/modules/import-kit/src/d1/stream-page-integrity.ts +18 -0
  128. package/modules/import-kit/src/d1/stream-partition.ts +50 -0
  129. package/modules/import-kit/src/d1/stream-plan.ts +133 -0
  130. package/modules/import-kit/src/d1/stream-receipt.ts +45 -0
  131. package/modules/import-kit/src/d1/stream-revision-schema.ts +35 -0
  132. package/modules/import-kit/src/d1/stream-snapshot.ts +26 -0
  133. package/modules/import-kit/src/d1/stream-stage.ts +79 -0
  134. package/modules/import-kit/src/d1/stream-state.ts +25 -0
  135. package/modules/import-kit/src/d1/stream-working-set.ts +30 -0
  136. package/modules/import-kit/src/d1/streams.ts +39 -0
  137. package/modules/import-kit/src/d1/target-guards.ts +9 -0
  138. package/modules/import-kit/src/d1/target-identities.ts +17 -0
  139. package/modules/import-kit/src/d1/transport.ts +10 -0
  140. package/modules/import-kit/src/d1/types.ts +162 -0
  141. package/modules/import-kit/src/d1/undo-observations.ts +39 -0
  142. package/modules/import-kit/src/d1/undo-report.ts +22 -0
  143. package/modules/import-kit/src/d1/undo-snapshot.ts +87 -0
  144. package/modules/import-kit/src/d1/undo-state.ts +84 -0
  145. package/modules/import-kit/src/d1/undo-types.ts +110 -0
  146. package/modules/import-kit/src/journal/authority.ts +12 -0
  147. package/modules/import-kit/src/plan/budget.ts +60 -0
  148. package/modules/import-kit/src/plan/index.ts +123 -0
  149. package/modules/import-kit/src/plan/size.ts +122 -0
  150. package/modules/import-kit/src/provenance/canonical-hash.ts +130 -0
  151. package/modules/import-kit/src/provenance/canonical-stream.ts +85 -0
  152. package/modules/import-kit/src/provenance/credential-names.ts +131 -0
  153. package/modules/import-kit/src/provenance/credentials.ts +317 -0
  154. package/modules/import-kit/src/provenance/identity.ts +51 -0
  155. package/modules/import-kit/src/provenance/json-snapshot.ts +21 -0
  156. package/modules/import-kit/src/provenance/resumable-sha256.ts +75 -0
  157. package/modules/import-kit/src/provenance/validate-json.ts +19 -0
  158. package/modules/import-kit/src/storage/originals.ts +87 -0
  159. package/modules/import-kit/src/storage/provenance.ts +64 -0
  160. package/modules/import-kit/src/storage/schema.ts +42 -0
  161. package/modules/import-kit/src/types.ts +47 -0
  162. package/modules/portability/README.md +98 -2
  163. package/modules/portability/backfills.mjs +42 -15
  164. package/modules/portability/ledgers.mjs +7 -1
  165. package/modules/portability/transient-tables.mjs +40 -0
  166. package/package.json +3 -1
  167. package/scripts/publish-check/reviewed.py +3 -1
package/README.md CHANGED
@@ -291,6 +291,7 @@ line that still names it. A later refresh is a version bump:
291
291
  | `@runeditrun/rer/adapter` | `commandAdapter` | `scripts/base-cli/cli/adapter.mjs` |
292
292
  | `@runeditrun/rer/deploy` | `ownerDeploy` | `scripts/base-cli/cli/deploy.mjs` |
293
293
  | `@runeditrun/rer/portability` | `localPortability` | `scripts/base-cli/cli/portability.mjs` |
294
+ | `@runeditrun/rer/portability-migrations` | `nativeMigrationPreflight`, before an adapter's Wrangler apply (contract in `modules/portability/README.md`) | `scripts/base-cli/cli/portability-migrations.mjs` |
294
295
  | `@runeditrun/rer/errors` | the CLI's error helpers | `scripts/base-cli/cli/errors.mjs` |
295
296
  | `@runeditrun/rer/jsonc` | JSONC reading | `scripts/base-cli/cli/jsonc.mjs` |
296
297
  | `@runeditrun/rer/parse`, `/scheduled` | CLI argument parsing, scheduled-job helpers | `scripts/base-cli/cli/parse.mjs`, `scheduled.mjs` |
@@ -321,10 +322,41 @@ line that still names it. A later refresh is a version bump:
321
322
  | `@runeditrun/rer/modules/release/export`, `/publication-scan`, `/source`, `/signature` | release export, publication scan and shared signature verifier | `scripts/base-cli/modules/release/*.mjs` |
322
323
  | `@runeditrun/rer/modules/deploy-kit/owner`, `/owner-cli`, `/prepare`, `/provider` | deploy kit | `scripts/base-cli/modules/deploy-kit/*.mjs` |
323
324
  | `@runeditrun/rer/modules/operator-auth`, `/dev`, `/dev-admission`, `/accounts/native`, `/identity/email-link` | operator auth | `scripts/base-cli/modules/operator-auth/index.mjs`, `dev/index.mjs`, `dev-admission.mjs`, `accounts/native.mjs`, `identity/email-link/index.mjs` |
325
+ | `@runeditrun/rer/modules/import-kit/d1` | asynchronous D1 import, reviewed reversal-policy conversion and preserved-undo preview (TypeScript Worker entry) | `scripts/base-cli/modules/import-kit/src/d1/index.ts` |
324
326
  | `@runeditrun/rer/modules/erasure/fence` | erasure fence statements | `scripts/base-cli/modules/erasure/fence.mjs` |
325
327
  | `@runeditrun/rer/modules/owner-claim`, `/modules/dependencies` | owner claim, dependency links | `scripts/base-cli/modules/owner-claim/index.mjs`, `dependencies/index.mjs` |
326
328
  | `@runeditrun/rer/internal/PATH` | any other package file, for tests | `scripts/base-cli/PATH`, and `scripts/base-onboarding/PATH` with PATH under `onboarding/` |
327
329
 
330
+ ### D1 import kit
331
+
332
+ In a TypeScript Worker with `nodejs_compat`, import the D1 API from the package:
333
+
334
+ ```ts
335
+ import {
336
+ convertD1ReversalPolicy,
337
+ previewD1PreservedUndo,
338
+ d1ReversalPolicyConversionSchema,
339
+ } from '@runeditrun/rer/modules/import-kit/d1';
340
+ ```
341
+
342
+ This is a TypeScript source entry for the Worker's bundler. Node's built-in type
343
+ stripping does not compile TypeScript dependencies inside `node_modules`; a Node
344
+ consumer must compile or bundle the entry with TypeScript support too. The package
345
+ includes its shared D1 transport and D1 runtime dependencies, without the synchronous
346
+ SQLite engine, optional readers or import UI.
347
+
348
+ Apply the additive `d1ReversalPolicyConversionSchema` in a new numbered migration
349
+ before converting an existing strict job; never rewrite an applied migration.
350
+ Preview the completed or undoing job with its current authorized context, review
351
+ the dispositions, then pass that preview's `reviewedFingerprint` to
352
+ `convertD1ReversalPolicy(jobId, context, { to: 'preserve-conflicts',
353
+ reviewedFingerprint })`. Preview is read-only. Conversion requires current undo
354
+ authority and preserves custody; repeated conversion refuses. Native adapters must
355
+ supply the complete dependency observations and guards described in the packaged
356
+ `modules/import-kit/src/d1/README.md`. Use `readD1ImportUndoReport().outcome` for the
357
+ later result (`undone` or `compensated`). This entry first ships in a supplying
358
+ release after rer 0.2.77; adopters still need their own public-door proof.
359
+
328
360
  ## Verbs
329
361
 
330
362
  In a checkout, every verb runs that checkout's own pinned `rer`; `rer VERB --help`
package/cli/export.mjs CHANGED
@@ -6,7 +6,7 @@ import { cliVersion } from './version.mjs';
6
6
 
7
7
  // Copy whole maintained source/tooling directories. Python publication scans
8
8
  // load sibling modules and data dynamically; they belong in the inventory too.
9
- export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs', 'foundation/runtime/seed-contract.mjs'];
9
+ export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs', 'foundation/runtime/seed-contract.mjs'];
10
10
  export async function inventory(base, roots = sourceRoots) {
11
11
  const files = [];
12
12
  async function walk(path) {
@@ -2,8 +2,8 @@ import { join } from 'node:path';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { readFile, readdir } from 'node:fs/promises';
4
4
  import { migrationStatements } from '../modules/portability/migration-sql.mjs';
5
- import { destinationLedger, matchMigrationLedger } from '../modules/portability/ledgers.mjs';
6
- import { all, insist } from '../modules/portability/storage.mjs';
5
+ import { destinationLedger, ledgerNames, matchMigrationLedger } from '../modules/portability/ledgers.mjs';
6
+ import { all, insist, PortabilityError } from '../modules/portability/storage.mjs';
7
7
  import { parseJsonc } from './jsonc.mjs';
8
8
 
9
9
  // Seed-owned declarations, never archive metadata: the deploymentSpec prefix
@@ -20,10 +20,12 @@ export function platformMigrationDeclaration(input={}) {
20
20
  // boundaries (migration-sql.mjs).
21
21
  async function inventory(root,binding,{prefix},split) {
22
22
  const config=parseJsonc(await readFile(join(root,'wrangler.jsonc'),'utf8'));
23
- const directory=join(root,config.d1_databases.find(entry=>entry.binding===binding).migrations_dir ?? 'migrations');
23
+ const bindings=config.d1_databases?.filter(entry=>entry.binding===binding) ?? [];
24
+ insist(bindings.length===1,'migration_ledger:binding',409);
25
+ const directory=join(root,bindings[0].migrations_dir ?? 'migrations');
24
26
  return Promise.all((await readdir(directory)).filter(name=>name.endsWith('.sql')).sort().map(async name=>{
25
27
  const bytes=await readFile(join(directory,name));
26
- return {name,statements:migrationStatements(bytes.toString('utf8'),split),sha256:createHash('sha256').update(bytes).digest('hex'),...(prefix===undefined?{}:{aliases:[prefix+name]})};
28
+ return {name,...(split?{statements:migrationStatements(bytes.toString('utf8'),split)}:{}),sha256:createHash('sha256').update(bytes).digest('hex'),...(prefix===undefined?{}:{aliases:[prefix+name]})};
27
29
  }));
28
30
  }
29
31
 
@@ -33,14 +35,33 @@ export async function appliedMigrations(root,db,binding,declaration,split) {
33
35
  return matchMigrationLedger(ledger,files,declaration).map(name=>files.find(file=>file.name===name));
34
36
  }
35
37
 
36
- // Wrangler cannot see Platform's ledger. Keep Platform as the sole authority;
37
- // pending files must be applied by that runner before a local transfer.
38
- export async function platformMigrationPreflight(root,db,binding,declaration,split) {
39
- const tables=(await all(db,"SELECT name FROM sqlite_master WHERE type='table' AND name IN ('rer_migrations','d1_migrations','_rer_deploy_migrations')")).map(row=>row.name);
40
- if(!tables.includes('rer_migrations'))return {platformLedger:false};
41
- insist(tables.length===1,'migration_ledger:multiple:rer_migrations',409);
42
- const files=await inventory(root,binding,declaration,split),ledger=await destinationLedger(db);
43
- const applied=matchMigrationLedger(ledger,files,declaration);
44
- for(const file of files)insist(applied.includes(file.name),'migration_ledger:unapplied:'+file.name,409);
45
- return {platformLedger:true};
38
+ // Adapter entry point, before *any* native Wrangler apply. The caller supplies
39
+ // the real target binding and keeps its writers stopped through apply/transfer.
40
+ // This only reads: it never repairs history or creates a second ledger.
41
+ export async function nativeMigrationPreflight({root,db,binding='DB',platformMigrations}) {
42
+ const declaration=platformMigrationDeclaration(platformMigrations);
43
+ const tables=await all(db,`SELECT type,name FROM sqlite_master WHERE lower(name) IN (${ledgerNames.map(name=>`'${name}'`).join(',')})`);
44
+ insist(tables.length<=1,'migration_ledger:multiple',409);
45
+ insist(tables.every(row=>row.type==='table' && ledgerNames.includes(row.name)),'migration_ledger:incompatible',409);
46
+ const table=tables[0]?.name;
47
+ if(!table)return {nativeApply:true};
48
+ // This runner's history cannot authorize Wrangler to apply the same files.
49
+ insist(table!=='_rer_deploy_migrations','migration_ledger:runner',409);
50
+ const files=await inventory(root,binding,declaration);
51
+ try {
52
+ const ledger=await destinationLedger(db),applied=matchMigrationLedger(ledger,files,declaration);
53
+ // Wrangler skips only literal filenames, not transfer aliases or hashes.
54
+ if(table==='d1_migrations')insist(ledger.every(row=>files.some(file=>file.name===row.name)),'migration_ledger:incompatible',409);
55
+ if(table==='rer_migrations')for(const file of files)insist(applied.includes(file.name),'migration_ledger:unapplied',409);
56
+ } catch(error) {
57
+ // Ledger contents can contain private values. Report constant categories,
58
+ // retaining the transfer's canonical compatibility and hash-matching policy.
59
+ if(error instanceof PortabilityError) {
60
+ const code=error.code.startsWith('migration_ledger:')?error.code.split(':').slice(0,2).join(':')
61
+ :error.code==='schema_mismatch:uncertain_migrations'?'migration_ledger:uncertain':'migration_ledger:incompatible';
62
+ throw new PortabilityError(code,409);
63
+ }
64
+ throw error;
65
+ }
66
+ return {nativeApply:table==='d1_migrations'};
46
67
  }
@@ -12,7 +12,7 @@ import { transferProgress } from '../modules/portability/progress.mjs';
12
12
  import { nativeFailure, stateBytes } from './portability-progress.mjs';
13
13
  import { parseJsonc } from './jsonc.mjs';
14
14
  import { loadPolicy } from './portability-policy.mjs';
15
- import { appliedMigrations, platformMigrationDeclaration, platformMigrationPreflight } from './portability-migrations.mjs';
15
+ import { appliedMigrations, platformMigrationDeclaration, nativeMigrationPreflight } from './portability-migrations.mjs';
16
16
 
17
17
  // Transfers read only the D1 database and R2 buckets. A configuration with just
18
18
  // those keeps the app's other bindings out of the proxy: a Durable Object class
@@ -45,7 +45,7 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
45
45
  let proxy;
46
46
  try {
47
47
  proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
48
- if(direction==='migration-preflight')return await platformMigrationPreflight(root,proxy.env[binding],binding,declaration,unstable_splitSqlQuery);
48
+ if(direction==='migration-preflight')return await nativeMigrationPreflight({root,db:proxy.env[binding],binding,platformMigrations});
49
49
  const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding,declaration,unstable_splitSqlQuery),policy,declaration);
50
50
  const options={ db: proxy.env[binding], buckets: Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]])), policy, migrations };
51
51
  if(direction==='legacy-preflight') {
@@ -53,12 +53,12 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
53
53
  // Do not apply pending product migrations to a populated recovery target.
54
54
  // Check real existing bindings first; finalize repeats this under the lock.
55
55
  if(legacyRecovery)await nativeWorker(store,'legacy-preflight',input,signal);
56
- const {platformLedger}=await nativeWorker(store,'migration-preflight',input,signal);
56
+ const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
57
57
  // Local migrations need no provider account: wrangler runs without credentials.
58
58
  // Its info lines (the local location and "Use --remote if you want to access
59
59
  // the remote instance") only confuse a local backup; warnings and errors print.
60
60
  const { dependencyEnvironment } = await shared('dependency-environment.mjs');
61
- if(!platformLedger)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
61
+ if(nativeApply)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
62
62
  cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false', WRANGLER_LOG: 'warn' },
63
63
  });
64
64
  const receipt=await nativeWorker(store,direction,input,signal);
@@ -5,11 +5,12 @@ import { posix } from 'node:path';
5
5
  import { listen } from './listen.mjs';
6
6
  import { loopback } from './parse.mjs';
7
7
  import { fontResponseHeaders } from './font-cache.mjs';
8
+ import { UpstreamAgent } from './upstream-agent.mjs';
8
9
 
9
10
  // The public listener observes transport lifetime without buffering or replacing
10
11
  // application responses. Preserve Host, Origin, cookies, status and streaming.
11
- // Each request opens its own loopback connection: a pooled keep-alive socket
12
- // that the runtime has already dropped would otherwise fail a fresh request.
12
+ // Share bounded upstream connections. A runtime closing an idle socket races
13
+ // reuse; retry only a bodyless read, once, before any response bytes arrive.
13
14
  // In door mode (`door`: {host, header, secret}) it answers only requests whose
14
15
  // Host is its own `<name>.localhost:<port>` (or a subdomain) and that carry the
15
16
  // per-start secret the front door adds; cookies are not scoped by port, so
@@ -24,17 +25,25 @@ import { fontResponseHeaders } from './font-cache.mjs';
24
25
  // anyway, and an auth check that throws on it must not answer with a crash page.
25
26
  export async function trafficProxy({host,port,target,activity,door,devKey,origin}) {
26
27
  const probe=randomUUID(),sockets=new Set(),keyed=keyHolder(devKey),configured=origin?new URL(origin).host:null;
28
+ const agent=new UpstreamAgent();let closing=false;
27
29
  const server=http.createServer((req,res)=>{
28
30
  if(door&&!doorAdmits(req,door)){req.resume();res.writeHead(403,{'content-type':'text/plain; charset=utf-8'});res.end('This checkout answers only through its front door.');return;}
29
31
  if(!hostAdmits(req,configured)){req.resume();res.writeHead(421,{'content-type':'text/plain; charset=utf-8'});res.end('This local server answers only its own host.');return;}
30
32
  if(!publicPath(req.url)||fsPath(req.url)&&!keyed(req)){req.resume();notFound(res);return;}
31
33
  const internal=req.headers['x-rer-probe']===probe;delete req.headers['x-rer-probe'];
32
- const finish=internal?()=>{}:activity.begin();
34
+ const endActivity=internal?()=>{}:activity.begin();let finished=false;
35
+ const finish=()=>{if(!finished){finished=true;endActivity();}};
33
36
  let requestEnded=req.complete,responseEnded=false;
34
37
  const completed=()=>{if(requestEnded&&responseEnded)finish();};
35
38
  req.once('end',()=>{requestEnded=true;completed();});req.once('aborted',finish);
36
39
  res.once('close',()=>{responseEnded=true;if(req.destroyed)finish();else completed();});res.once('finish',()=>{responseEnded=true;completed();});
37
- const upstream=http.request({host:'127.0.0.1',port:target,path:req.url,method:req.method,headers:req.headers,agent:false},reply=>{
40
+ let upstream,bodyStarted=false;
41
+ req.on('data',()=>{bodyStarted=true;});
42
+ const bodyless=['GET','HEAD','OPTIONS'].includes(req.method)&&!req.headers['transfer-encoding']&&(!req.headers['content-length']||req.headers['content-length']==='0');
43
+ function send(retried=false){
44
+ let responseStarted=false,readAtStart;
45
+ const attempt=http.request({host:'127.0.0.1',port:target,path:req.url,method:req.method,headers:req.headers,agent:retried?false:agent},reply=>{
46
+ responseStarted=true;
38
47
  // Vite answers a path outside its serving allow list with a 403 page that lists the
39
48
  // allow list (checkout and home paths); a request without the dev key gets 404 instead.
40
49
  // Any other 403 is the application's own and passes through.
@@ -51,8 +60,21 @@ export async function trafficProxy({host,port,target,activity,door,devKey,origin
51
60
  }
52
61
  res.writeHead(reply.statusCode,fontResponseHeaders(req.url,reply.statusCode,reply.rawHeaders,req.headers));reply.pipe(res);
53
62
  });
54
- req.once('aborted',()=>upstream.destroy());res.once('close',()=>upstream.destroy());
55
- upstream.on('error',()=>{if(!res.headersSent)notFound(res);else res.destroy();});req.pipe(upstream);
63
+ upstream=attempt;
64
+ attempt.once('socket',socket=>{readAtStart=socket.bytesRead;});
65
+ attempt.on('error',error=>{
66
+ if(closing||req.aborted||res.destroyed)return;
67
+ const dropped=['ECONNRESET','EPIPE'].includes(error.code)||error.message==='socket hang up';
68
+ if(!retried&&dropped&&attempt.reusedSocket&&!responseStarted&&attempt.socket?.bytesRead===readAtStart&&bodyless&&!bodyStarted&&req.readableEnded){
69
+ req.unpipe(attempt);send(true);return;
70
+ }
71
+ if(!res.headersSent)notFound(res);else res.destroy();
72
+ });
73
+ if(retried)attempt.end();else req.pipe(attempt);
74
+ }
75
+ req.once('aborted',()=>upstream.destroy());
76
+ res.once('close',()=>{if(!res.writableFinished)upstream.destroy();});
77
+ send();
56
78
  });
57
79
  server.on('connection',socket=>{sockets.add(socket);socket.on('close',()=>sockets.delete(socket));});
58
80
  server.on('upgrade',(req,socket,head)=>{
@@ -79,8 +101,8 @@ export async function trafficProxy({host,port,target,activity,door,devKey,origin
79
101
  }
80
102
  upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>upstream.destroy());upstream.on('close',()=>socket.destroy());
81
103
  });
82
- await listen(server,host,port);
83
- return {probe,port:server.address().port,async close(){for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
104
+ try{await listen(server,host,port);}catch(error){agent.destroy();throw error;}
105
+ return {probe,port:server.address().port,async close(){closing=true;agent.destroy();for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
84
106
  }
85
107
  function doorAdmits(req,door){
86
108
  const host=String(req.headers.host??'').toLowerCase(),given=Buffer.from(String(req.headers[door.header]??'')),secret=Buffer.from(door.secret);
@@ -0,0 +1,14 @@
1
+ import http from 'node:http';
2
+
3
+ // Expire only idle connections, well before Vite's 5 s keep-alive timeout.
4
+ // Keep a browser's six HTTP/1 connections free between module bursts.
5
+ // Active streams have no deadline imposed by the pool.
6
+ export class UpstreamAgent extends http.Agent {
7
+ constructor(){super({keepAlive:true,maxSockets:16,maxFreeSockets:6});}
8
+ keepSocketAlive(socket){
9
+ if(!super.keepSocketAlive(socket))return false;
10
+ socket.setTimeout(1000);
11
+ return true;
12
+ }
13
+ reuseSocket(socket,request){socket.setTimeout(0);super.reuseSocket(socket,request);}
14
+ }
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.79
4
+
5
+ - Reuse bounded keep-alive connections in the local dev proxy and retry stale connections for bodyless reads.
6
+ - Give each native demo visitor a separate 64-hex installation key so dependency signing works.
7
+
8
+ ## 0.2.78
9
+
10
+ - Add signed seed test delivery to the optional mail relay, with public Worker routing, bounded target checks and invocation logs.
11
+ - Restore transient migration tables when replaying installation archives.
12
+ - Expose native migration preflight and refuse replay through relocated ledger identities.
13
+ - Convert reviewed completed D1 import jobs to preserve-conflicts reversal with a durable journal; ordinary previews stay SELECT-only.
14
+ - Package the D1 import kit at `@runeditrun/rer/modules/import-kit/d1` for adopting Workers.
15
+
3
16
  ## 0.2.77
4
17
 
5
18
  - **Dependency signing keys are sealed at rest with a rotatable installation key (#367, #382).** Each interface's private signing key is stored as an AES-256-GCM envelope under a key derived from the generated `INSTALLATION_KEY` setting, which setup and hosted deploys keep beside `SESSION_SECRET` and archives never carry. Legacy plaintext keys upgrade once. `rer deploy --rotate-secret INSTALLATION_KEY` re-seals every row and retires the previous binding; `rer deploy --reopen-installation-key KID` reopens a D1 restore from before a rotation with retained private custody, reporting the D1 key history first. Missing or wrong keys fail closed with `installation_key_missing` or `installation_key_unavailable`.
package/global/README.md CHANGED
@@ -291,6 +291,7 @@ line that still names it. A later refresh is a version bump:
291
291
  | `@runeditrun/rer/adapter` | `commandAdapter` | `scripts/base-cli/cli/adapter.mjs` |
292
292
  | `@runeditrun/rer/deploy` | `ownerDeploy` | `scripts/base-cli/cli/deploy.mjs` |
293
293
  | `@runeditrun/rer/portability` | `localPortability` | `scripts/base-cli/cli/portability.mjs` |
294
+ | `@runeditrun/rer/portability-migrations` | `nativeMigrationPreflight`, before an adapter's Wrangler apply (contract in `modules/portability/README.md`) | `scripts/base-cli/cli/portability-migrations.mjs` |
294
295
  | `@runeditrun/rer/errors` | the CLI's error helpers | `scripts/base-cli/cli/errors.mjs` |
295
296
  | `@runeditrun/rer/jsonc` | JSONC reading | `scripts/base-cli/cli/jsonc.mjs` |
296
297
  | `@runeditrun/rer/parse`, `/scheduled` | CLI argument parsing, scheduled-job helpers | `scripts/base-cli/cli/parse.mjs`, `scheduled.mjs` |
@@ -321,10 +322,41 @@ line that still names it. A later refresh is a version bump:
321
322
  | `@runeditrun/rer/modules/release/export`, `/publication-scan`, `/source`, `/signature` | release export, publication scan and shared signature verifier | `scripts/base-cli/modules/release/*.mjs` |
322
323
  | `@runeditrun/rer/modules/deploy-kit/owner`, `/owner-cli`, `/prepare`, `/provider` | deploy kit | `scripts/base-cli/modules/deploy-kit/*.mjs` |
323
324
  | `@runeditrun/rer/modules/operator-auth`, `/dev`, `/dev-admission`, `/accounts/native`, `/identity/email-link` | operator auth | `scripts/base-cli/modules/operator-auth/index.mjs`, `dev/index.mjs`, `dev-admission.mjs`, `accounts/native.mjs`, `identity/email-link/index.mjs` |
325
+ | `@runeditrun/rer/modules/import-kit/d1` | asynchronous D1 import, reviewed reversal-policy conversion and preserved-undo preview (TypeScript Worker entry) | `scripts/base-cli/modules/import-kit/src/d1/index.ts` |
324
326
  | `@runeditrun/rer/modules/erasure/fence` | erasure fence statements | `scripts/base-cli/modules/erasure/fence.mjs` |
325
327
  | `@runeditrun/rer/modules/owner-claim`, `/modules/dependencies` | owner claim, dependency links | `scripts/base-cli/modules/owner-claim/index.mjs`, `dependencies/index.mjs` |
326
328
  | `@runeditrun/rer/internal/PATH` | any other package file, for tests | `scripts/base-cli/PATH`, and `scripts/base-onboarding/PATH` with PATH under `onboarding/` |
327
329
 
330
+ ### D1 import kit
331
+
332
+ In a TypeScript Worker with `nodejs_compat`, import the D1 API from the package:
333
+
334
+ ```ts
335
+ import {
336
+ convertD1ReversalPolicy,
337
+ previewD1PreservedUndo,
338
+ d1ReversalPolicyConversionSchema,
339
+ } from '@runeditrun/rer/modules/import-kit/d1';
340
+ ```
341
+
342
+ This is a TypeScript source entry for the Worker's bundler. Node's built-in type
343
+ stripping does not compile TypeScript dependencies inside `node_modules`; a Node
344
+ consumer must compile or bundle the entry with TypeScript support too. The package
345
+ includes its shared D1 transport and D1 runtime dependencies, without the synchronous
346
+ SQLite engine, optional readers or import UI.
347
+
348
+ Apply the additive `d1ReversalPolicyConversionSchema` in a new numbered migration
349
+ before converting an existing strict job; never rewrite an applied migration.
350
+ Preview the completed or undoing job with its current authorized context, review
351
+ the dispositions, then pass that preview's `reviewedFingerprint` to
352
+ `convertD1ReversalPolicy(jobId, context, { to: 'preserve-conflicts',
353
+ reviewedFingerprint })`. Preview is read-only. Conversion requires current undo
354
+ authority and preserves custody; repeated conversion refuses. Native adapters must
355
+ supply the complete dependency observations and guards described in the packaged
356
+ `modules/import-kit/src/d1/README.md`. Use `readD1ImportUndoReport().outcome` for the
357
+ later result (`undone` or `compensated`). This entry first ships in a supplying
358
+ release after rer 0.2.77; adopters still need their own public-door proof.
359
+
328
360
  ## Verbs
329
361
 
330
362
  In a checkout, every verb runs that checkout's own pinned `rer`; `rer VERB --help`
@@ -34,7 +34,7 @@ export class NativeDemo extends DurableObject {
34
34
  // Short TTLs are usable only on the guarded testing host.
35
35
  if (/^[123]x0{31}AA$/.test(this.env.TURNSTILE_SECRET_KEY ?? '') && this.env.NATIVE_TEST_TTL_MS) ends = Math.min(ends, started + Number(this.env.NATIVE_TEST_TTL_MS));
36
36
  const runtime = { ...bundle.vars, ...settings, RER_DEMO: '1', [originVar]: origin,
37
- RER_NATIVE_KEY: random(), SESSION_SECRET: random(), SETUP_TOKEN: random(), OWNER_EMAIL: this.env.DEMO_OWNER_EMAIL || 'owner@demo.invalid',
37
+ RER_NATIVE_KEY: random(), SESSION_SECRET: random(), INSTALLATION_KEY: random(), SETUP_TOKEN: random(), OWNER_EMAIL: this.env.DEMO_OWNER_EMAIL || 'owner@demo.invalid',
38
38
  RER_OWNER_CLAIM_ISSUER: origin, RER_OWNER_CLAIM_INSTALLATION_ID: id,
39
39
  RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(keys.publicKeys), RER_DEMO_EXPIRES: endsLocal };
40
40
  this.state = { phase: 'starting', runtime, ends, seen: started, savedSeen: started, lastCron: Math.floor(started / 60_000), correlation };
@@ -58,14 +58,24 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
58
58
  // Bound each response, not the owner's bucket size; failures retain ownership.
59
59
  let requestWindow = propagation?.uploaded ? propagation.window : undefined;
60
60
  const request = fetch;
61
- fetch = (input, init = {}) => {
62
- if (!requestWindow?.active) return request(input, init);
61
+ const guardedRequest = (input, init = {}) => {
62
+ init.signal?.throwIfAborted();
63
+ // The window clock can expire before its shared abort timer fires.
64
+ assert(!requestWindow?.active || requestWindow.remaining() > 0, 'deployment-readiness-timeout');
65
+ return request(input, init);
66
+ };
67
+ const requestSignal = () => {
68
+ if (!requestWindow?.active) return undefined;
63
69
  const remaining = requestWindow.remaining();
64
70
  assert(remaining > 0, 'deployment-readiness-timeout');
65
- const deadline = AbortSignal.timeout(Math.max(1, Math.ceil(remaining)));
66
- return request(input, {...init,signal:init.signal ? AbortSignal.any([init.signal,deadline]) : deadline});
71
+ return AbortSignal.timeout(Math.max(1, Math.ceil(remaining)));
72
+ };
73
+ fetch = (input, init = {}) => {
74
+ const deadline = requestSignal();
75
+ return request(input, {...init,...(deadline ? {signal:init.signal ? AbortSignal.any([init.signal,deadline]) : deadline} : {})});
67
76
  };
68
- const api = deploymentDiagnostics(cloudflare({accountId:env.CLOUDFLARE_ACCOUNT_ID,token:env.CLOUDFLARE_API_TOKEN,fetch,budgetMigrations:command === 'deploy',...(command === 'remove' ? {maxRequests:Infinity,removal:true} : {})}),{onCreated});
77
+ // Transport must see the same outer signal when deciding whether to retry.
78
+ const api = deploymentDiagnostics(cloudflare({accountId:env.CLOUDFLARE_ACCOUNT_ID,token:env.CLOUDFLARE_API_TOKEN,fetch:guardedRequest,requestSignal,budgetMigrations:command === 'deploy',...(command === 'remove' ? {maxRequests:Infinity,removal:true} : {})}),{onCreated});
69
79
  // Removal needs the recorded account/name identity, not a workers.dev route.
70
80
  const target = command === 'remove'
71
81
  ? {accountId:api.accountId,project:declaration.project,environment:values.environment,worker:ownerWorkerName(declaration.project,values.environment)}
@@ -28,9 +28,14 @@ export async function boundedJSON(response, limit) {
28
28
  }
29
29
  const redactValues = (text, values) => values.filter(Boolean).flatMap(value=>[value,encodeURIComponent(value),JSON.stringify(value).slice(1,-1)]).sort((a,b)=>b.length-a.length).reduce((value,secret)=>value.split(secret).join('[REDACTED]'),text);
30
30
  /** Only this fixed origin and the explicitly selected account ever receive the token. */
31
- export function cloudflare({ accountId, token, fetch: request = globalThis.fetch, objectDelete = deleteR2Object, timeoutMs = 30000, maxRequests = 500, removal = false, budgetMigrations = false }) {
31
+ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch, objectDelete = deleteR2Object, timeoutMs = 30000, maxRequests = 500, removal = false, budgetMigrations = false, requestSignal = () => undefined }) {
32
32
  assert(hexId(accountId), 'invalid-cloudflare-account-id');
33
33
  assert(typeof token === 'string' && token.trim() && !/[\r\n]/.test(token), 'invalid-cloudflare-api-token');
34
+ // Capture an outer deadline once per operation, before transport retries.
35
+ const deadlineSignal = caller => {
36
+ const deadline = requestSignal();
37
+ return caller && deadline ? AbortSignal.any([caller,deadline]) : caller ?? deadline;
38
+ };
34
39
  let requests = 0;
35
40
  const migrationBudgets = new Set();
36
41
  function reserveMigrationRequests(id, pending) {
@@ -64,7 +69,7 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
64
69
  error.providerTransport = {operation:redactCredentials(operation),endpoint,attempts,status,reason:transportReason(cause)};
65
70
  return recordDeployFailure(error,{output:redactAuth(transportOutput(cause))});
66
71
  };
67
- const {response,output = ''} = await providerResponse({method,timeoutMs,callerSignal,removal,
72
+ const {response,output = ''} = await providerResponse({method,timeoutMs,callerSignal:deadlineSignal(callerSignal),removal,
68
73
  replayableAsset:method === 'POST' && (/^\/workers\/scripts\/[^/]+\/assets-upload-session$/.test(path) || path === '/workers/assets/upload?base64=true'),
69
74
  reserveRetry:() => requests < maxRequests && (++requests, true),failure:transportFailure,
70
75
  consume:(response,attempts) => response.body ? boundedText(response,undefined,cause => transportFailure(cause,attempts,response.status)) : '',
@@ -135,7 +140,7 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
135
140
  assert(/^[a-z0-9-]{1,63}$/.test(worker) && /^[0-9a-f-]{36}$/.test(versionId), 'invalid-provider-path');
136
141
  assert(++requests <= maxRequests, 'provider-request-budget');
137
142
  const operation = 'GET /workers/scripts/[worker]/content/v2';
138
- const {response,output} = await providerResponse({method:'GET',timeoutMs,reserveRetry:() => requests < maxRequests && (++requests, true),
143
+ const {response,output} = await providerResponse({method:'GET',timeoutMs,callerSignal:deadlineSignal(),reserveRetry:() => requests < maxRequests && (++requests, true),
139
144
  send:signal => request(`https://api.cloudflare.com/client/v4/accounts/${accountId}/workers/scripts/${worker}/content/v2?version=${versionId}`, {method:'GET',redirect:'error',signal,headers:{Authorization:`Bearer ${token}`}}),
140
145
  consume:response => response.body ? boundedBytes(response, 64 * 1024 * 1024) : Buffer.alloc(0),
141
146
  failure:(cause,attempts) => Object.assign(new Error('provider-transport-failed'), {providerTransport:{operation,endpoint:`https://api.cloudflare.com/client/v4/accounts/[REDACTED]/workers/scripts/${worker}/content/v2`,attempts,status:null,reason:transportReason(cause)}})});
@@ -149,7 +154,7 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
149
154
  async function upload(url, bytes, etag) {
150
155
  const destination = importUploadURL(url);
151
156
  assert(++requests <= maxRequests, 'provider-request-budget');
152
- const {response} = await providerResponse({method:'PUT',timeoutMs,
157
+ const {response} = await providerResponse({method:'PUT',timeoutMs,callerSignal:deadlineSignal(),
153
158
  reserveRetry:() => requests < maxRequests && (++requests, true),
154
159
  send:signal => request(destination, { method:'PUT', redirect:'error', signal, headers:{'Content-Length':String(bytes.length)}, body:bytes }),
155
160
  failure:(cause,attempts) => Object.assign(new Error('d1-import-upload-transport-failed'), {providerTransport:{operation:'PUT D1 import upload',endpoint:'https://[REDACTED].r2.cloudflarestorage.com/[D1 import upload]',attempts,status:null,reason:transportReason(cause)}}),