@runeditrun/rer 0.2.83 → 0.2.85

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 (269) hide show
  1. package/README.md +21 -24
  2. package/cli/README.md +17 -1
  3. package/cli/authoring.mjs +1 -0
  4. package/cli/bounded.mjs +1 -1
  5. package/cli/business/carry.mjs +149 -0
  6. package/cli/business/command.mjs +6 -1
  7. package/cli/business/connect.mjs +1 -1
  8. package/cli/business/local-commands.mjs +2 -0
  9. package/cli/business/opt-ins.mjs +8 -4
  10. package/cli/business/questions.mjs +4 -1
  11. package/cli/business/state.mjs +1 -1
  12. package/cli/business/supervisor.mjs +7 -1
  13. package/cli/container-transfer.mjs +2 -2
  14. package/cli/contract.mjs +7 -7
  15. package/cli/demo-host.mjs +5 -1
  16. package/cli/demo-native.mjs +2 -1
  17. package/cli/demo.mjs +6 -1
  18. package/cli/deploy-command.mjs +6 -4
  19. package/cli/deploy.mjs +9 -7
  20. package/cli/errors.mjs +1 -1
  21. package/cli/export.mjs +1 -1
  22. package/cli/human-error.mjs +20 -0
  23. package/cli/lifecycle.mjs +23 -5
  24. package/cli/main.mjs +1 -1
  25. package/cli/managed-data-schema.mjs +114 -0
  26. package/cli/managed-data-zip.mjs +116 -0
  27. package/cli/managed-data.mjs +110 -0
  28. package/cli/managed-server.mjs +25 -14
  29. package/cli/native-owner-entry.mjs +86 -0
  30. package/cli/output.mjs +3 -2
  31. package/cli/parse.mjs +3 -3
  32. package/cli/portability-empty.mjs +59 -0
  33. package/cli/portability-migrations.mjs +7 -5
  34. package/cli/portability-policy.mjs +5 -2
  35. package/cli/portability-worker.mjs +15 -6
  36. package/cli/portability.mjs +30 -8
  37. package/cli/ready-summary.mjs +9 -0
  38. package/cli/run-transfers.mjs +37 -0
  39. package/cli/runtime-front-door.mjs +4 -4
  40. package/cli/server-proxy.mjs +4 -3
  41. package/cli/server-registry.mjs +13 -8
  42. package/cli/site.mjs +6 -1
  43. package/cli/transfers.mjs +17 -4
  44. package/edition-authoring/base-copies.mjs +125 -30
  45. package/edition-authoring/copy-checkout.mjs +7 -120
  46. package/edition-authoring/edition-migrations.mjs +41 -0
  47. package/edition-authoring/files.mjs +67 -0
  48. package/edition-authoring/lock.mjs +2 -2
  49. package/edition-authoring/module-closure.mjs +232 -0
  50. package/edition-authoring/module-edges.mjs +100 -0
  51. package/edition-authoring/module-resolution.mjs +66 -0
  52. package/edition-authoring/module-syntax.mjs +57 -0
  53. package/edition-authoring/package-target.mjs +92 -0
  54. package/edition-authoring/runtime-dependencies.mjs +74 -97
  55. package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
  56. package/edition-authoring/vendor/babel-parser/README.md +21 -0
  57. package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
  58. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
  59. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
  60. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
  61. package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
  62. package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
  63. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
  64. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
  65. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
  66. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
  67. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
  68. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
  69. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
  70. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
  71. package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
  72. package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
  73. package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
  74. package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
  75. package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
  76. package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
  77. package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
  78. package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
  79. package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
  80. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
  81. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
  82. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
  83. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
  84. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
  85. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
  86. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
  87. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
  88. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
  89. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
  90. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
  91. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
  92. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
  93. package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
  94. package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
  95. package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
  96. package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
  97. package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
  98. package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
  99. package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
  100. package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
  101. package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
  102. package/edition-authoring/vendor/yaml/LICENSE +13 -0
  103. package/edition-authoring/vendor/yaml/README.md +11 -0
  104. package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
  105. package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
  106. package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
  107. package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
  108. package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
  109. package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
  110. package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
  111. package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
  112. package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
  113. package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
  114. package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
  115. package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
  116. package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
  117. package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
  118. package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
  119. package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
  120. package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
  121. package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
  122. package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
  123. package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
  124. package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
  125. package/edition-authoring/vendor/yaml/errors.mjs +57 -0
  126. package/edition-authoring/vendor/yaml/index.mjs +17 -0
  127. package/edition-authoring/vendor/yaml/log.mjs +11 -0
  128. package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
  129. package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
  130. package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
  131. package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
  132. package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
  133. package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
  134. package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
  135. package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
  136. package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
  137. package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
  138. package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
  139. package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
  140. package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
  141. package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
  142. package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
  143. package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
  144. package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
  145. package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
  146. package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
  147. package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
  148. package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
  149. package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
  150. package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
  151. package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
  152. package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
  153. package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
  154. package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
  155. package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
  156. package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
  157. package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
  158. package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
  159. package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
  160. package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
  161. package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
  162. package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
  163. package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
  164. package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
  165. package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
  166. package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
  167. package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
  168. package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
  169. package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
  170. package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
  171. package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
  172. package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
  173. package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
  174. package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
  175. package/edition-authoring/vendor/yaml/util.mjs +11 -0
  176. package/edition-authoring/vendor/yaml/visit.mjs +233 -0
  177. package/edition-authoring/workflow-copies.mjs +125 -0
  178. package/edition-authoring/workflow-scripts.mjs +112 -0
  179. package/foundation/runtime/contract-docs.mjs +754 -0
  180. package/foundation/runtime/run-data.d.mts +1 -0
  181. package/foundation/runtime/run-data.mjs +2 -0
  182. package/global/CHANGELOG.md +55 -3
  183. package/global/README.md +21 -24
  184. package/global/cli/command.mjs +8 -2
  185. package/global/cli/install.mjs +4 -5
  186. package/global/cli/path-link.mjs +3 -2
  187. package/global/cli/repo-command.mjs +3 -7
  188. package/global/launch/dev.mjs +12 -2
  189. package/global/launch/facts.mjs +2 -2
  190. package/global/launch/render.mjs +16 -9
  191. package/global/launch/state.mjs +4 -4
  192. package/global/main.mjs +12 -7
  193. package/install.sh +17 -6
  194. package/modules/container/README.md +6 -1
  195. package/modules/container/adapters/d1-limits.mjs +286 -0
  196. package/modules/container/adapters/d1-sqlite.mjs +95 -0
  197. package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
  198. package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
  199. package/modules/container/adapters/d1-workerd.mjs +5 -0
  200. package/modules/container/adapters/sqlite-worker.mjs +5 -3
  201. package/modules/container/build.mjs +1 -0
  202. package/modules/container/image-variables.mjs +8 -3
  203. package/modules/container/transfer.mjs +14 -4
  204. package/modules/container/worker-engine.mjs +3 -3
  205. package/modules/demo/declaration.mjs +1 -4
  206. package/modules/demo/vite.mjs +1 -1
  207. package/modules/demo-host/build.mjs +1 -0
  208. package/modules/demo-host/native/prepare.mjs +2 -1
  209. package/modules/demo-host/native/sql.mjs +7 -2
  210. package/modules/deploy-kit/README.md +23 -3
  211. package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
  212. package/modules/deploy-kit/d1-import.mjs +17 -5
  213. package/modules/deploy-kit/diagnostics.mjs +29 -3
  214. package/modules/deploy-kit/owner-cli.mjs +20 -7
  215. package/modules/deploy-kit/provider-transport.mjs +19 -4
  216. package/modules/deploy-kit/provider.mjs +57 -22
  217. package/modules/deploy-kit/readiness-window.mjs +1 -1
  218. package/modules/deploy-kit/site.mjs +8 -3
  219. package/modules/deploy-kit/templates.mjs +3 -3
  220. package/modules/deploy-kit/worker.mjs +4 -4
  221. package/modules/import-kit/src/d1/README.md +23 -4
  222. package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
  223. package/modules/import-kit/src/d1/budget.ts +15 -7
  224. package/modules/import-kit/src/d1/column-layout.ts +5 -0
  225. package/modules/import-kit/src/d1/creation.ts +15 -8
  226. package/modules/import-kit/src/d1/database.ts +3 -3
  227. package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
  228. package/modules/import-kit/src/d1/erasure.ts +2 -2
  229. package/modules/import-kit/src/d1/jobs.ts +10 -6
  230. package/modules/import-kit/src/d1/plans.ts +14 -8
  231. package/modules/import-kit/src/d1/retirement.ts +2 -2
  232. package/modules/import-kit/src/d1/sets.ts +1 -3
  233. package/modules/import-kit/src/d1/staged-creation.ts +3 -3
  234. package/modules/import-kit/src/door/limits.ts +1 -1
  235. package/modules/import-kit/src/door/refusals.ts +1 -1
  236. package/modules/portability/README.md +112 -4
  237. package/modules/portability/backfills.mjs +9 -8
  238. package/modules/portability/bridge.mjs +12 -5
  239. package/modules/portability/catalogue.mjs +12 -5
  240. package/modules/portability/files.mjs +4 -3
  241. package/modules/portability/http.mjs +3 -3
  242. package/modules/portability/import.mjs +18 -9
  243. package/modules/portability/index.d.mts +4 -3
  244. package/modules/portability/index.mjs +1 -1
  245. package/modules/portability/ledgers.mjs +3 -2
  246. package/modules/portability/legacy-safety.mjs +11 -2
  247. package/modules/portability/migration-history.mjs +2 -2
  248. package/modules/portability/progress.mjs +1 -0
  249. package/modules/portability/restore-empty.mjs +12 -0
  250. package/modules/release/github-verify.mjs +11 -2
  251. package/onboarding/adapter.mjs +35 -6
  252. package/onboarding/app-fetch.mjs +6 -4
  253. package/onboarding/development-runtime.mjs +19 -0
  254. package/onboarding/local/operation.mjs +45 -27
  255. package/onboarding/loopback-fetch.mjs +16 -0
  256. package/onboarding/operator-installer.mjs +4 -6
  257. package/onboarding/process-diagnostics.mjs +6 -2
  258. package/onboarding/production-runtime.mjs +4 -2
  259. package/onboarding/readiness.mjs +1 -0
  260. package/package.json +1 -1
  261. package/scripts/publish-check/README.md +6 -0
  262. package/scripts/publish-check/history_scan.py +5 -3
  263. package/scripts/publish-check/hygiene_config.py +2 -1
  264. package/scripts/publish-check/public_hygiene.py +1 -1
  265. package/scripts/publish-check/report.py +9 -3
  266. package/scripts/publish-check/third-party-notices.json +13 -0
  267. package/scripts/publish-check/third_party_notices.py +38 -0
  268. package/scripts/publish-check/tree_scan.py +6 -0
  269. package/scripts/publish-check.mjs +1 -1
@@ -102,7 +102,19 @@ The runner validates the module/export before applying data migrations. The
102
102
  native transfer worker imports that same seed-owned entry point, preserving
103
103
  functions and module-local closures. Modules should have no top-level effects:
104
104
  preflight and transfer each load them in a separate process. Archive metadata
105
- never selects executable policy. Invalid paths, missing/invalid default exports,
105
+ never selects executable policy. A module may also export
106
+ `createPolicy({db, buckets})` to bind payload producers and consumers to the
107
+ current transfer's database and buckets. Its default policy is validated during
108
+ preflight; the factory's policy is validated when the bindings are available.
109
+ Managed intake supplies its disposable source bindings to the same factory, so
110
+ its payloads come from the ZIP's own staged data. Intake compares source schema
111
+ objects with a fresh replay of the destination migrations. Portable tables must
112
+ exist there; retired or replaced objects require a matching historical definition
113
+ and the migration that removes it. The receipt groups those objects by type and
114
+ migration, with counts and hashes of sorted names. Unknown objects refuse before
115
+ native restore; the destination retains its own schema. Native runners can use
116
+ `requireEmptyTables` before creating a restore job; finalization still enforces
117
+ the atomic empty-table guards. Invalid paths, missing/invalid default exports,
106
118
  and declaring both `policy` and `policyModule` fail closed. Serializable object
107
119
  `policy` declarations remain supported; inline functions (including nested
108
120
  schema-upgrade and payload callbacks) are refused instead of being dropped by
@@ -367,9 +379,13 @@ source identity, job ids and boundaries do not affect equivalence.
367
379
 
368
380
  Schema identity covers table definitions (including constraints and generated
369
381
  expressions), explicit indexes (including uniqueness and partial predicates),
370
- views and triggers. Indexes and triggers on excluded tables are excluded with
371
- their tables, including platform bookkeeping tables. The complete additional
372
- definitions travel in `schemaObjects`. A single SQLite lexer reads the original
382
+ views and triggers. Row exclusions do not omit indexes and triggers attached
383
+ to excluded tables, including platform bookkeeping tables. Names with the literal
384
+ internal prefixes `sqlite_` and `_cf_` remain exempt. The complete additional
385
+ definitions travel in `schemaObjects`. Explicitly acknowledged v1 recovery uses
386
+ the historical exclusion projection only when placing its old backup within
387
+ native migration history; the live destination and ordinary v2 inventories
388
+ still use the complete catalogue. A single SQLite lexer reads the original
373
389
  SQL before removing trivia. Identity records each token's class and canonical
374
390
  value, plus a deterministic spelling: a single space separates neighbours
375
391
  exactly when concatenating them would change their tokenization. The complete
@@ -417,6 +433,7 @@ Re-export from the original installation to carry the complete definitions.
417
433
  A new archive explicitly records even an empty object inventory, so later
418
434
  additive migrations can still be placed normally. The separate acknowledged
419
435
  v1 recovery path remains an explicitly unverified recovery, as documented below.
436
+ Version 2 backups without that inventory have their own acknowledged recovery below.
420
437
 
421
438
  New exports use archive version 2. The closing `archiveHash` is SHA-256 of
422
439
  canonical JSON `{manifest,parts}`, where `manifest` is the complete manifest
@@ -451,6 +468,50 @@ authenticate it. If the original installation is unavailable, use the explicit
451
468
  [backup-only v1 recovery](#backup-only-v1-recovery) below. Normal import still
452
469
  requires version 2 integrity.
453
470
 
471
+ ## Acknowledged recovery of older version 2 backups
472
+
473
+ A fresh export from a current rer is preferred whenever the original installation
474
+ is available. Current archives carry the complete schema inventory and restore
475
+ without any acknowledgment. Version 2 backups written by rer 0.2.79 or earlier
476
+ can lack `schemaObjects`. If only such a backup remains, the owner can explicitly
477
+ accept that its schema objects are unverified:
478
+
479
+ ```sh
480
+ rer import --input exports/retained.rer --yes --acknowledge-unverified-schema-objects
481
+ ```
482
+
483
+ This accepts only the missing inventory. Ordinary import still refuses
484
+ `schema_mismatch:legacy_schema` before staging. The acknowledgment never accepts
485
+ version 1 metadata; that separate recovery still needs both v1 flags below.
486
+ The destination must be empty under the existing product emptiness rule:
487
+ non-migration rows in product tables refuse `target_not_empty:<table>` before
488
+ staging, including before a local runner applies pending product migrations.
489
+ Finalization repeats the normal emptiness check and atomic guards.
490
+ The normal restore maintenance lock remains held throughout staging and restore.
491
+
492
+ The destination runner must replay its own applied migration files. Every
493
+ archived table, column, dependency and table definition must match a compatible
494
+ point in that history, with only the supported later additive changes. Recorded
495
+ migration names must form an ordered compatible subset of the destination's
496
+ history; unknown names, incompatible columns or definitions, uncertain migrations
497
+ and unsafe later data changes refuse before staging, naming the mismatch.
498
+ Older name-only migration ledger rows are accepted for this acknowledged path;
499
+ ledger hashes, when present, must still match. Platform ledger rows are verified
500
+ against the archive parts and skipped, never installed over destination history.
501
+
502
+ Indexes, views and triggers come only from the destination's migrations, never
503
+ from archive SQL. Recovery writes rows and assets through the normal integrity,
504
+ authentication, explicit confirmation, safety and final erasure-fencing checks.
505
+ Seed-owned authority checks, including private-key matching, remain the seed's
506
+ responsibility and are unchanged.
507
+
508
+ The completed restore job and returned receipt carry `schemaUnverified`, with
509
+ its reason (acknowledged recovery of a version 2 archive without schemaObjects),
510
+ source identity, export time, acknowledgment time and archive hash. The local
511
+ command prints this secret-free receipt. A current archive records no such
512
+ receipt, even when the flag was supplied. Preserve the original backup and the
513
+ receipt; export a new current archive after recovery.
514
+
454
515
  ## Archives across later additive migrations
455
516
 
456
517
  An archive restores into an installation whose schema differs only by migrations
@@ -1009,3 +1070,50 @@ Base's default-seed and composed foundation CLI adapters adopt direct local D1
1009
1070
  bindings with explicit identity/configuration exclusions. Their CLI journeys
1010
1071
  exercise archive/reset/restore/archive equivalence. Remote transfer and deployed
1011
1072
  product acceptance remain outside this local adoption.
1073
+
1074
+
1075
+ ### Optional Managed data intake
1076
+
1077
+ Platform's data download is a stored ZIP with kind `runeditrun-app-data` and
1078
+ schema 1. It is distinct from an installation archive. The reference adapter
1079
+ opts in with `localPortability({database, policy, buckets, managedData: true})`.
1080
+ Existing adapters retain their native archive and legacy JSON readers.
1081
+
1082
+ Adapters with their own native archive format can keep their existing `import`
1083
+ method and add `managedDataImport` from an opted-in `localPortability`
1084
+ declaration. The CLI selects that method only for ZIP input; all other inputs
1085
+ continue through the adapter's original reader. This requires the seed's real
1086
+ native Workers database name, binding and portability policy.
1087
+
1088
+ Adapters that already consume Base's native format can import `withManagedDataImport`
1089
+ from the package's portability entry point and call
1090
+ `withManagedDataImport(context, declaration, restoreNative)` before their native
1091
+ reader. The declaration supplies the real `binding`, `buckets`, `policy` or
1092
+ `policyModule`, and optional `platformMigrations`. The callback receives the
1093
+ context with a private native archive path for a Managed ZIP, or the original
1094
+ context for other inputs. Authentication, explicit confirmation, custody and
1095
+ empty-target checks remain the caller's responsibility. The callback must await
1096
+ its native restore before returning; staging is deleted on success or failure.
1097
+ This helper emits Base's native portability format; an adapter with a different
1098
+ format must provide a callback that adopts that native restore contract.
1099
+
1100
+ The intake checks the complete ZIP and manifest, required members, checksums,
1101
+ bindings and Platform ledger before native restore. Source SQL runs in a private
1102
+ workerd D1 sandbox. The existing exporter preserves its erasure journal, excludes
1103
+ identity and secret data, maps migration identities using the same hash matching
1104
+ as native Platform-ledger archives, and emits a verified native archive. Native
1105
+ restore still checks emptiness, migration compatibility, erasure and row safety.
1106
+ No source SQL runs against the destination. The intake accounts every non-internal
1107
+ source table, index, trigger and view against native schema or a named retirement
1108
+ in destination migrations, including objects attached to excluded tables. Internal
1109
+ prefixes are compared literally. A scratch native import preflight checks the
1110
+ projected archive before native restore can open the destination.
1111
+
1112
+ The current intake supports one database and declared buckets, local Workers
1113
+ transport, stored ZIP members, at most 10,000 entries and statements, a 128 MiB
1114
+ archive, 64 MiB members, 4 MiB metadata members and 16 MiB of SQL, with each SQL
1115
+ statement at most 100,000 bytes after binding string literals, with at most 100
1116
+ parameters of at most 2 MiB each. It refuses compressed or encrypted entries,
1117
+ unsafe paths, duplicate or unexpected members, missing ledgers, other versions,
1118
+ container transport, later-journal and legacy-recovery options. Refusals use
1119
+ constant `managed_data_*` reasons and do not print source values.
@@ -15,8 +15,8 @@ import { transientTables } from './transient-tables.mjs';
15
15
  // - An eligible seed or backfill of a catalogue table replays at finalize.
16
16
  // A carried table keeps its archived rows and admits only one later writer,
17
17
  // naming its target columns. An absent table is reset first; each later write is a
18
- // replayable INSERT: they run in migration order, exactly as written, after
19
- // the archived rows are inserted and with the destination's triggers still
18
+ // replayable INSERT or a bounded UPDATE of a newly reconstructed table. They
19
+ // run in migration order, exactly as written, after archived rows are inserted and with the destination's triggers still
20
20
  // dropped, so the table holds what the live upgrade gave it. A replay may read
21
21
  // only archived tables (complete by then), views over those tables and the
22
22
  // table itself, by named
@@ -56,11 +56,12 @@ export function laterData({applied,unapplied,replay,catalogue,archived,empty,tab
56
56
  // Seed INSERTs into a new table replay too: the rows already present in a
57
57
  // fresh destination must be reset and derived from the restored installation.
58
58
  const transient=transients.get(table);
59
- // A transient fill can also read new catalogue tables whose INSERTs the
60
- // same plan reconstructs (or whose reset leaves them empty at this point).
59
+ // A new target can read other new catalogue tables that the same plan
60
+ // reconstructs. Carried targets still read only archived tables.
61
61
  // Dependencies are checked below before any of the plan is selected.
62
- const available=[...transients.keys(),...(transient?[...writes.keys()].filter(name=>!carried.includes(name)):[])];
63
- const options={table,statements,restorable,writable,carried:[...carried,...available],tables:known,secrets,views,manifest};
62
+ const available=[...transients.keys(),...(!carried.includes(table)?[...writes.keys()].filter(name=>!carried.includes(name)):[])];
63
+ const allowUpdate=!transient && !carried.includes(table) && list.some(s=>['insert','replace'].includes(s.data.verb));
64
+ const options={table,allowUpdate,statements,restorable,writable,carried:[...carried,...available],tables:known,secrets,views,manifest};
64
65
  // Carried target rules must use the actual archive, not reconstructed reads.
65
66
  const bad=carried.includes(table) && list.length>1?list:list.filter(s=>!replayable(s,{...options,targetCarried:carried.includes(table)}));
66
67
  // Writes confined to tables created after the archive retain their
@@ -95,8 +96,8 @@ export function laterData({applied,unapplied,replay,catalogue,archived,empty,tab
95
96
  return {migration:s.migration,statement:s.index,table:named[table]??table,sql:s.sql,...(carried.includes(table)?{carried:true}:{}),...(transients.has(table)?{transient:true}:{}),...(schema.has(s)?{schema:true}:{})};
96
97
  })};
97
98
  }
98
- function replayable({data},{table,statements,restorable,writable,carried,targetCarried,tables,secrets,views,manifest}) {
99
- if(!['insert','replace'].includes(data.verb) || data.star)return false;
99
+ function replayable({data},{table,allowUpdate,statements,restorable,writable,carried,targetCarried,tables,secrets,views,manifest}) {
100
+ if(!['insert','replace',...(allowUpdate?['update']:[])].includes(data.verb) || data.star)return false;
100
101
  if(targetCarried) {
101
102
  // sqlite_sequence's high-water mark is not archived, so replay cannot
102
103
  // reproduce a carried AUTOINCREMENT table's live key allocation.
@@ -22,7 +22,7 @@ export async function appliedMigrations(db) {
22
22
  // Restored rows never pass through a later migration, so one that writes or
23
23
  // rewrites restorable data is refused, whether or not it changes the schema,
24
24
  // unless its statement is replayed at finalize (backfills.mjs).
25
- async function placement(db,manifest,cat,replay,ledger,history) {
25
+ async function placement(db,manifest,cat,replay,ledger,history,legacyRecovery,unverified=false) {
26
26
  const files=replay.names.map(name=>({name,sha256:replay.sha256?.(name),aliases:replay.aliases?.(name)}));
27
27
  // An aligned replayer keeps its existing contract: hashes are optional.
28
28
  // Resolve destination aliases only when its ledger uses different names.
@@ -32,10 +32,17 @@ async function placement(db,manifest,cat,replay,ledger,history) {
32
32
  const archived=history?.();
33
33
  const historyEntries=manifest.migrations?.map(name=>archived?.find(entry=>entry.name===name) ?? {name}) ?? archived;
34
34
  const recorded=historyEntries && matchMigrationLedger(historyEntries,files,replay);
35
+ // Only explicitly acknowledged v1 recovery may use the old projection for
36
+ // archive placement. The live destination check above remains complete, and
37
+ // ordinary v2 imports still require their authenticated object inventory;
38
+ // acknowledged v2 recovery without that inventory places by tables only.
39
+ const schemaAfter=names=>replay.schemaAfter(names,legacyRecovery && manifest.schemaObjects===undefined?{legacyExcludedObjects:true}:unverified?{tablesOnly:true}:undefined);
40
+ if(unverified && archived && manifest.migrations)insist(canonicalJson(matchMigrationLedger(archived,files,replay))===canonicalJson(recorded),'schema_mismatch:migration_history',409);
35
41
  let earlier,unapplied;
36
42
  if(recorded) {
43
+ if(unverified)insist(recorded.every((name,i)=>applied.indexOf(name)>(i?applied.indexOf(recorded[i-1]):-1)),'schema_mismatch:migration_history',409);
37
44
  earlier=applied.filter(name=>recorded.includes(name));
38
- insist(await replay.schemaAfter(earlier)===manifest.schema,'schema_mismatch');
45
+ insist(await schemaAfter(earlier)===manifest.schema,'schema_mismatch');
39
46
  unapplied=applied.filter(name=>!earlier.includes(name));
40
47
  }else{
41
48
  // Unrecorded: the latest matching prefix. Migrations that change no archived
@@ -43,7 +50,7 @@ async function placement(db,manifest,cat,replay,ledger,history) {
43
50
  // and count as later. The source may have stopped at any matching prefix,
44
51
  // so every migration after the earliest one may be missing from its rows.
45
52
  const matching=[];
46
- for(let k=0;k<=applied.length;k++)if(await replay.schemaAfter(applied.slice(0,k))===manifest.schema)matching.push(k);
53
+ for(let k=0;k<=applied.length;k++)if(await schemaAfter(applied.slice(0,k))===manifest.schema)matching.push(k);
47
54
  insist(matching.length,'schema_mismatch');
48
55
  earlier=applied.slice(0,matching.at(-1));
49
56
  unapplied=applied.slice(matching[0]);
@@ -85,10 +92,10 @@ export async function sameSchemaMigrations(db,manifest,cat,migrations,history) {
85
92
  // are additive, or a proven row-preserving CHECK rebuild: new tables, new
86
93
  // columns that take a default, or later schema objects established by replay.
87
94
  // Anything else stays a schema_mismatch refusal.
88
- export async function additiveBridge(db,manifest,cat,migrations,history) {
95
+ export async function additiveBridge(db,manifest,cat,migrations,history,legacyRecovery,unverified=false) {
89
96
  insist(migrations,'schema_mismatch');
90
97
  const replay=await migrations(),ledger=await destinationLedger(db)??[];
91
- const {applied,earlier,replays,rebuilt}=await placement(db,manifest,cat,replay,ledger,history);
98
+ const {applied,earlier,replays,rebuilt}=await placement(db,manifest,cat,replay,ledger,history,legacyRecovery,unverified);
92
99
  const columns={};
93
100
  for(const table of manifest.tables) {
94
101
  const target=cat.tables.find(t=>t.name===table.name),label=':'+table.name;
@@ -53,19 +53,26 @@ export function policy(input) {
53
53
  /** Platform tables are always excluded; explicit includes override only optional exclusions. */
54
54
  export const excludedTable=(table,input={})=>platformTable(table) || (!(input.includeTables??[]).includes(table) && [...excludedTables,...(input.excludeTables??[])].some(pattern=>matches(table,pattern)));
55
55
  async function archived(db,config) {
56
- const objects=await all(db,"SELECT name,sql,type,tbl_name FROM sqlite_master WHERE sql IS NOT NULL ORDER BY name");
56
+ const objects=await all(db,"SELECT name,sql,type,tbl_name FROM sqlite_master WHERE sql IS NOT NULL AND substr(lower(name),1,7) <> 'sqlite_' AND substr(lower(name),1,4) <> '_cf_' ORDER BY name");
57
57
  const kinds=await all(db,'PRAGMA table_list');
58
58
  const derived=config.derivedTables;
59
59
  const excluded=objects.filter(x=>x.type==='table' && (excludedTable(x.name,config) || (!config.includeTables.includes(x.name) &&
60
60
  derived.some(p=>x.name===p || (kinds.find(k=>k.name===x.name)?.type==='shadow' && x.name.startsWith(p+'_'))))));
61
61
  objects.sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:a.type<b.type?-1:a.type>b.type?1:0);
62
- const schemaObjects=objects.filter(x=>['index','view','trigger'].includes(x.type)
63
- && !excluded.some(t=>t.name===x.tbl_name)).map(({name,type,tbl_name,sql})=>({name,type,table:tbl_name,sql}));
62
+ // Row exclusions never erase behavioral schema evidence, even for objects
63
+ // attached to excluded tables. Only literal engine-internal names are exempt.
64
+ const schemaObjects=objects.filter(x=>['index','view','trigger'].includes(x.type)).map(({name,type,tbl_name,sql})=>({name,type,table:tbl_name,sql}));
64
65
  return {objects,kinds,excluded,schemaObjects,entries:objects.filter(x=>x.type==='table' && !excluded.some(y=>y.name===x.name))};
65
66
  }
66
67
  // The archive schema identity alone, for databases that need not satisfy the policy.
67
- export async function schemaIdentity(db,config) {
68
- const {entries,schemaObjects}=await archived(db,config);return schemaIdentityOf(entries,schemaObjects);
68
+ export async function schemaIdentity(db,config,{legacyExcludedObjects=false,tablesOnly=false}={}) {
69
+ const {entries,excluded,schemaObjects}=await archived(db,config);
70
+ // Acknowledged v1 recovery places an old backup using its historical
71
+ // projection; acknowledged recovery of a version 2 archive without an object
72
+ // inventory compares tables only. Current archives always retain the
73
+ // complete object inventory.
74
+ const objects=tablesOnly?[]:legacyExcludedObjects?schemaObjects.filter(object=>!excluded.some(table=>table.name===object.table)):schemaObjects;
75
+ return schemaIdentityOf(entries,objects);
69
76
  }
70
77
  export async function catalogue(db,config) {
71
78
  const {objects,kinds,excluded,entries,schemaObjects}=await archived(db,config);
@@ -60,7 +60,7 @@ export async function exportArchive(service, path, transient, progress) {
60
60
  if (id) await service.exports.abort(id);
61
61
  }
62
62
  }
63
- export async function importArchive(service, path, transient, journal, progress) {
63
+ export async function importArchive(service, path, transient, journal, progress, options={}) {
64
64
  let id, manifest, closing, complete = false, staged = 0;
65
65
  try {
66
66
  // Validate both complete archives before creating any restore state. An old
@@ -76,7 +76,7 @@ export async function importArchive(service, path, transient, journal, progress)
76
76
  const ledgers = ledger.ledgers();
77
77
  for await (const record of fileRecords(path)) {
78
78
  if (record.kind === 'manifest') {
79
- manifest = record; id = await service.imports.create(manifest, undefined, ledgers ? { ledgers } : {});
79
+ manifest = record; id = await service.imports.create(manifest, undefined, {...options,...(ledgers?{ledgers}:{})});
80
80
  const { skippedTables } = await service.imports.status(id);
81
81
  if (skippedTables?.length) progress?.({ phase: 'skipped', tables: skippedTables });
82
82
  }
@@ -89,6 +89,7 @@ export async function importArchive(service, path, transient, journal, progress)
89
89
  }
90
90
  progress?.({ phase: 'finishing', total: manifest.partCount });
91
91
  const status = await service.imports.finalize(id, { contentHash: closing.contentHash, archiveHash: closing.archiveHash, ...(later ? { laterJournal: later } : {}) }); complete = true;
92
- return { ...receipt(manifest, closing, transient), ...(status.bridged ? { bridged: status.bridged } : {}), ...(status.skippedTables ? { skippedTables: status.skippedTables } : {}), ...(status.safetyChanges ? { safetyChanges: status.safetyChanges } : {}) };
92
+ if(status.schemaUnverified)progress?.({phase:'schema-unverified',receipt:status.schemaUnverified});
93
+ return { ...receipt(manifest, closing, transient), ...(status.schemaUnverified?{schemaUnverified:status.schemaUnverified}:{}), ...(status.bridged ? { bridged: status.bridged } : {}), ...(status.skippedTables ? { skippedTables: status.skippedTables } : {}), ...(status.safetyChanges ? { safetyChanges: status.safetyChanges } : {}) };
93
94
  } finally { if (id && !complete) await service.imports.abort(id); }
94
95
  }
@@ -11,10 +11,10 @@ export async function boundedJson(request,limit) {
11
11
  try{return JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(bytes));}catch{throw new PortabilityError('invalid_json');}
12
12
  }
13
13
  const json=(value,status=200)=>new Response(JSON.stringify(value),{status,headers:{'Content-Type':'application/json','Cache-Control':'no-store'}});
14
- export async function createPortabilityHandler({db,buckets,policy,appOrigin,basePath='/api/portability',authorize,maxBodyBytes=MAX_LINE_BYTES}) {
14
+ export async function createPortabilityHandler({db,buckets,policy,migrations,appOrigin,basePath='/api/portability',authorize,maxBodyBytes=MAX_LINE_BYTES}) {
15
15
  insist(typeof authorize==='function' && new URL(appOrigin).origin===appOrigin,'invalid_handler_configuration');
16
16
  insist(/^\/[A-Za-z0-9/_-]+$/.test(basePath) && !basePath.endsWith('/') && Number.isSafeInteger(maxBodyBytes) && maxBodyBytes>0,'invalid_handler_configuration');
17
- const service=await createPortability({db,buckets,policy});
17
+ const service=await createPortability({db,buckets,policy,migrations});
18
18
  return async request=>{
19
19
  const url=new URL(request.url);
20
20
  if(url.pathname!==basePath && !url.pathname.startsWith(basePath+'/'))return null;
@@ -31,7 +31,7 @@ export async function createPortabilityHandler({db,buckets,policy,appOrigin,base
31
31
  if(collection==='imports' && request.method==='GET' && !id)return json({active:await api.active(actor)});
32
32
  if(request.method==='POST' && !id) {
33
33
  const body=await boundedJson(request,maxBodyBytes);
34
- if(collection==='imports'){insist(body.confirmed===true,'confirmation_required');return json({id:await api.create(body.manifest,actor)},201);}
34
+ if(collection==='imports'){insist(body.confirmed===true,'confirmation_required');return json({id:await api.create(body.manifest,actor,{ledgers:body.ledgers,acknowledgeUnverifiedSchemaObjects:body.acknowledgeUnverifiedSchemaObjects===true})},201);}
35
35
  return json({id:await api.create(actor)},201);
36
36
  }
37
37
  if(request.method==='GET' && id && !action)return json(await api.status(id));
@@ -20,19 +20,26 @@ import { legacyEmptyGuards, legacyAuditStatements, requireLegacyEmpty } from './
20
20
  import { checkReferences } from './references.mjs';
21
21
  // ledgers: the rows of each migration ledger table the archive carries, as the
22
22
  // caller read them from it ({table:rows}); uploadPart binds them to its parts.
23
- export async function createImport(context,manifest,actor='direct',legacyRecovery,ledgers) {
23
+ export async function createImport(context,manifest,actor='direct',legacyRecovery,ledgers,acknowledgeUnverifiedSchemaObjects=false) {
24
24
  const {db,config,buckets}=context;await checkManifest(manifest);checkArchivedLedgers(manifest,ledgers);
25
25
  insist(manifest.product===config.product,'wrong_product');
26
26
  // Explicit schema upgrades can reconcile rows, but cannot attest an interrupted deployment.
27
- await appliedMigrations(db);await state(db);
27
+ await appliedMigrations(db);
28
28
  const original=manifest;manifest=await restorableManifest(original);
29
29
  const skippedTables=original.tables.filter(table=>platformTable(table.name)).map(table=>table.name);
30
30
  const cat=await catalogue(db,config),upgrade=config.acceptedSchemas[original.schema];
31
31
  // Table SQL and migration names cannot establish missing trigger/view/index
32
32
  // definitions. Never infer that an old archive's absent inventory is empty.
33
- insist(manifest.schemaObjects!==undefined || legacyRecovery,'schema_mismatch:legacy_schema',409);
34
- const same=manifest.schema===cat.identity,history=()=>archivedHistory(original,ledgers);
35
- const {replays,...bridge}=upgrade?{}:same?(await sameSchemaMigrations(db,manifest,cat,context.migrations,history)??{}):await additiveBridge(db,manifest,cat,context.migrations,history);
33
+ const unverified=original.version===2 && manifest.schemaObjects===undefined && acknowledgeUnverifiedSchemaObjects===true;
34
+ insist(manifest.schemaObjects!==undefined || legacyRecovery || unverified,'schema_mismatch:legacy_schema',409);
35
+ if(unverified)for(const table of manifest.tables) {
36
+ const target=cat.tables.find(t=>t.name===table.name);
37
+ insist(target,'schema_mismatch:table:'+table.name,409);
38
+ for(const column of table.columns)insist(target.columns.some(c=>canonicalJson(c)===canonicalJson(column)),'schema_mismatch:column:'+table.name+':'+column.name,409);
39
+ insist(table.dependencies.every(d=>target.dependencies.includes(d)),'schema_mismatch:dependencies:'+table.name,409);
40
+ }
41
+ const same=manifest.schema===cat.identity,history=()=>archivedHistory(original,ledgers,{allowOlderShape:unverified});
42
+ const {replays,...bridge}=unverified?await additiveBridge(db,manifest,cat,context.migrations,history,legacyRecovery,true):upgrade?{}:same?(await sameSchemaMigrations(db,manifest,cat,context.migrations,history)??{}):await additiveBridge(db,manifest,cat,context.migrations,history,legacyRecovery);
36
43
  // Finalize checks object references on the staged rows; a later migration
37
44
  // replayed into a reference table would publish rows that check never saw.
38
45
  const referenced=replays?.find(r=>Object.values(config.buckets).some(spec=>spec.objectReferences?.table===r.table));
@@ -49,6 +56,7 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
49
56
  insist(canonicalJson(manifest.requiredConfiguration)===canonicalJson(config.requiredConfiguration),'configuration_inventory');
50
57
  for(const o of manifest.objects) insist(buckets[o.bucket] && config.buckets[o.bucket] && o.key.startsWith(config.buckets[o.bucket].prefix??''),'bucket_inventory');
51
58
  insist(canonicalJson(manifest.payloads.map(x=>x.name))===canonicalJson(Object.keys(config.extraPayloads).sort()),'payload_inventory');
59
+ if(unverified)await destinationState(context,{metadata:{targets:cat.tables,manifest:original}});
52
60
  await ensureImportLeases(db);
53
61
  const previous=(await state(db)).import_job;
54
62
  if(previous) {
@@ -56,10 +64,10 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
56
64
  await abortImport(context,previous,{staleOnly:true});
57
65
  }
58
66
  const id=crypto.randomUUID(),copies=Object.fromEntries(targets.map((t,i)=>[t.name,'rer_portability_stage_'+id.replaceAll('-','')+'_'+i]));
59
- const row={id,kind:'import',actor,phase:'staging',completed:0,metadata:{manifest:original,...(skippedTables.length?{restoreManifest:manifest,skippedTables}:{}),copies,targets,triggers:cat.triggers,...(bridge.fromSchema?{bridge}:{}),...(replays?{replays}:{}),...(legacyRecovery?{legacyRecovery}: {}),...(ledgers?{ledgers}:{})}};
67
+ const row={id,kind:'import',actor,phase:'staging',completed:0,metadata:{manifest:original,...(unverified?{schemaUnverified:{reason:'acknowledged recovery of a version 2 archive without schemaObjects',sourceIdentity:original.sourceIdentity,exportedAt:original.exportedAt,acknowledgedAt:new Date().toISOString()}}:{}),...(skippedTables.length?{restoreManifest:manifest,skippedTables}:{}),copies,targets,triggers:cat.triggers,...(bridge.fromSchema?{bridge}:{}),...(replays?{replays}:{}),...(legacyRecovery?{legacyRecovery}: {}),...(ledgers?{ledgers}:{})}};
60
68
  try {
61
69
  await db.batch([guard(db,'(SELECT import_job FROM rer_portability_state WHERE id=1) IS NULL'),
62
- statement(db,'UPDATE rer_portability_state SET import_job=? WHERE id=1',id),
70
+ statement(db,'UPDATE rer_portability_state SET import_job=?,applying=? WHERE id=1',id,unverified?1:0),
63
71
  ...targets.flatMap(t=>createCopy(db,t,copies[t.name])),
64
72
  statement(db,'INSERT INTO rer_portability_jobs(id,kind,actor,phase,metadata) VALUES(?,?,?,?,?)',id,'import',actor,row.phase,canonicalJson(row.metadata)),createImportLease(db,id),db.prepare('DELETE FROM rer_portability_guard')]);
65
73
  }catch(e){const running=(await state(db)).import_job;if(running)throw await importRunning(db,running);throw e;}
@@ -209,6 +217,7 @@ async function finalizeLeasedImport(context,id,{contentHash,archiveHash,laterJou
209
217
  }
210
218
  for(const payload of manifest.payloads)await config.extraPayloads[payload.name].consume(binaryStream(context,id,payload,binaryIndexes),payload);
211
219
  row.phase='complete';row.metadata.contentHash=digest;
220
+ if(row.metadata.schemaUnverified)row.metadata.schemaUnverified.archiveHash=archiveHash;
212
221
  await db.batch([db.prepare('PRAGMA defer_foreign_keys=ON'),...emptyGuards(context,row,seeded),...seeded.map(t=>guard(db,...seededCondition(t))),...dependentGuards,...legacyEmptyGuards(db,row),
213
222
  guard(db,'NOT EXISTS(SELECT 1 FROM rer_portability_epochs WHERE source=? AND epoch>?) AND NOT EXISTS(SELECT 1 FROM rer_portability_state WHERE source_identity=? AND epoch>?)',manifest.sourceIdentity,checked.epoch,manifest.sourceIdentity,checked.epoch),
214
223
  ...row.metadata.targets.map(t=>guard(db,`NOT EXISTS(SELECT 1 FROM ${quote(sidecar(row.metadata.copies[t.name]))} s JOIN rer_portability_journal j ON j.source=? AND j.tombstone=s.rer_portability_tombstone)`,manifest.sourceIdentity)),
@@ -224,14 +233,14 @@ async function finalizeLeasedImport(context,id,{contentHash,archiveHash,laterJou
224
233
  // D1 may have committed even when its acknowledgement failed.
225
234
  if((await job(db,id)).phase==='complete')return importStatus(context,id);
226
235
  if(!await context.importLease.owned())throw new (await import('./storage.mjs')).PortabilityError('import_lease_expired',409);
227
- await removeOwned(context,id);row.phase='staging';await db.batch([save(db,row),db.prepare('UPDATE rer_portability_state SET applying=0 WHERE id=1')]);throw e;
236
+ await removeOwned(context,id);row.phase='staging';await db.batch([save(db,row),statement(db,'UPDATE rer_portability_state SET applying=? WHERE id=1',row.metadata.schemaUnverified?1:0)]);throw e;
228
237
  }
229
238
  return importStatus(context,id);
230
239
  }
231
240
  // Upload receipts stay idempotent; the status door exposes the moving lease.
232
241
  export async function importStatus(context,id,{includeLease=true}={}) {
233
242
  const row=await job(context.db,id,'import');return {id,kind:'import',phase:row.phase,completed:row.completed,total:row.metadata.manifest.partCount,...(includeLease?await importLeaseStatus(context.db,row):{}),
234
- contentHash:row.metadata.contentHash??null,requiredConfiguration:row.phase==='complete'?row.metadata.manifest.requiredConfiguration:[],...(row.metadata.bridge?{bridged:row.metadata.bridge}:{}),...(row.metadata.skippedTables?{skippedTables:row.metadata.skippedTables}:{}),...(row.metadata.safetyChanges?{safetyChanges:row.metadata.safetyChanges}:{})};
243
+ contentHash:row.metadata.contentHash??null,...(row.phase==='complete' && row.metadata.schemaUnverified?{schemaUnverified:row.metadata.schemaUnverified}:{}),requiredConfiguration:row.phase==='complete'?row.metadata.manifest.requiredConfiguration:[],...(row.metadata.bridge?{bridged:row.metadata.bridge}:{}),...(row.metadata.skippedTables?{skippedTables:row.metadata.skippedTables}:{}),...(row.metadata.safetyChanges?{safetyChanges:row.metadata.safetyChanges}:{})};
235
244
  }
236
245
  export async function activeImport(context,actor='direct') {
237
246
  const id=(await state(context.db)).import_job;
@@ -39,11 +39,12 @@ export interface ArchivePolicy {
39
39
  }
40
40
  /** Actual changed rows grouped by table, column and safe replacement value; never original values. */
41
41
  export interface SafetyChange {table:string;column:string;value:Cell;rows:number}
42
- export interface Status {id:string;kind:'export'|'import';phase:'building'|'staging'|'applying'|'complete'|'aborted';completed:number;total:number|null;/** Import only: inactivity deadline and whether it has passed. */abortableAt?:string|null;stale?:boolean;/** Export only: bytes of the parts built so far. */bytes?:number;contentHash:string|null;requiredConfiguration?:string[];bridged?:Bridge;/** Platform bookkeeping ignored in an older archive. */skippedTables?:string[];/** Durable summary of bounded import normalization. */safetyChanges?:SafetyChange[]}
42
+ export interface SchemaUnverifiedReceipt {reason:string;sourceIdentity:string;exportedAt:string;acknowledgedAt:string;archiveHash:string}
43
+ export interface Status {schemaUnverified?:SchemaUnverifiedReceipt;id:string;kind:'export'|'import';phase:'building'|'staging'|'applying'|'complete'|'aborted';completed:number;total:number|null;/** Import only: inactivity deadline and whether it has passed. */abortableAt?:string|null;stale?:boolean;/** Export only: bytes of the parts built so far. */bytes?:number;contentHash:string|null;requiredConfiguration?:string[];bridged?:Bridge;/** Platform bookkeeping ignored in an older archive. */skippedTables?:string[];/** Durable summary of bounded import normalization. */safetyChanges?:SafetyChange[]}
43
44
  /** Later additive migrations an older archive was restored across. */
44
45
  export interface Bridge {fromSchema:string;toSchema:string;migrations:string[];tables:string[];columns:Record<string,string[]>;/** Later backfills of tables the archive lacks, replayed at finalize in this order; rows is null until the apply commits. */replayed?:{migration:string;statement:number;table:string;rows:number|null}[]}
45
46
  /** A runner's replay of the destination's applied migrations: the archive schema identity after a chosen set, and each migration's statements. */
46
- export interface MigrationReplay {names:string[];/** Seed-declared data-only Platform entries without migration files. */dataOnly?:string[];/** Names generated by the seed's deployment specification for this file. */aliases?(name:string):string[]|undefined;statements(name:string):string[];/** The migration file's SHA-256 hex, where the runner read the file. */sha256?(name:string):string|undefined;schemaAfter(names:string[]):Promise<string>}
47
+ export interface MigrationReplay {names:string[];/** Seed-declared data-only Platform entries without migration files. */dataOnly?:string[];/** Names generated by the seed's deployment specification for this file. */aliases?(name:string):string[]|undefined;statements(name:string):string[];/** The migration file's SHA-256 hex, where the runner read the file. */sha256?(name:string):string|undefined;schemaAfter(names:string[],options?:{tablesOnly?:boolean}):Promise<string>}
47
48
  /** Export job creation only; no record data, object keys or file paths. */
48
49
  export interface ExportEvent {id:string;/** Opaque caller id; the direct/CLI sentinel is normalized to null. */actor:string|null;scope:'installation'}
49
50
  export interface PortabilityOptions {
@@ -53,7 +54,7 @@ export interface PortabilityOptions {
53
54
  }
54
55
  export interface Portability {
55
56
  exports: {create(actor?:string):Promise<string>;advance(id:string,options?:{expectedPart?:number;maxParts?:number}):Promise<Status>;status(id:string):Promise<Status>;download(id:string):Promise<ReadableStream<Uint8Array>>;abort(id:string):Promise<Status>};
56
- imports: {active(actor?:string):Promise<Status|null>;/** ledgers: the rows of each migration ledger table an old archive carries, as read from it; they place it in the destination's history and must equal its parts. */create(manifest:Manifest,actor?:string,options?:{ledgers?:Record<string,Row[]>}):Promise<string>;uploadPart(id:string,index:number,part:Part):Promise<Status>;finalize(id:string,options:{archiveHash:string;contentHash?:string;laterJournal?:LaterJournal}):Promise<Status>;status(id:string):Promise<Status>;abort(id:string):Promise<Status>;/** Aborts the import left staged by a crashed restore and returns its id; call only as the destination's sole operator. */abortAbandoned():Promise<string|null>};
57
+ imports: {active(actor?:string):Promise<Status|null>;/** ledgers: the rows of each migration ledger table an old archive carries, as read from it; they place it in the destination's history and must equal its parts. */create(manifest:Manifest,actor?:string,options?:{ledgers?:Record<string,Row[]>;acknowledgeUnverifiedSchemaObjects?:boolean}):Promise<string>;uploadPart(id:string,index:number,part:Part):Promise<Status>;finalize(id:string,options:{archiveHash:string;contentHash?:string;laterJournal?:LaterJournal}):Promise<Status>;status(id:string):Promise<Status>;abort(id:string):Promise<Status>;/** Aborts the import left staged by a crashed restore and returns its id; call only as the destination's sole operator. */abortAbandoned():Promise<string|null>};
57
58
  status(id:string):Promise<Status>;actor(id:string):Promise<string>;
58
59
  erasureStatements(table:string,primaryKey:Record<string,Cell>):Promise<D1PreparedStatement[]>;
59
60
  redactionStatements():Promise<D1PreparedStatement[]>;
@@ -20,7 +20,7 @@ export async function createPortability({db,buckets={},policy:input,migrations,o
20
20
  const context={db,buckets,config,migrations,onExport};
21
21
  return {
22
22
  exports:{create:actor=>createExport(context,actor),advance:(id,options)=>advanceExport(context,id,options),status:id=>exportStatus(context,id),download:id=>downloadExport(context,id),abort:id=>abortExport(context,id)},
23
- imports:{active:actor=>activeImport(context,actor),create:(manifest,actor,options={})=>createImport(context,manifest,actor,undefined,options.ledgers),uploadPart:(id,index,part)=>uploadPart(context,id,index,part),finalize:(id,options)=>finalizeImport(context,id,options),status:id=>importStatus(context,id),abort:id=>abortImport(context,id),abortAbandoned:()=>abortAbandonedImport(context)},
23
+ imports:{active:actor=>activeImport(context,actor),create:(manifest,actor,options={})=>createImport(context,manifest,actor,undefined,options.ledgers,options.acknowledgeUnverifiedSchemaObjects),uploadPart:(id,index,part)=>uploadPart(context,id,index,part),finalize:(id,options)=>finalizeImport(context,id,options),status:id=>importStatus(context,id),abort:id=>abortImport(context,id),abortAbandoned:()=>abortAbandonedImport(context)},
24
24
  status:async id=>(await job(db,id)).kind==='export'?exportStatus(context,id):importStatus(context,id),
25
25
  actor:async id=>(await job(db,id)).actor,
26
26
  erasureStatements:(table,key)=>erasureStatements(db,table,key),redactionStatements:()=>redactionStatements(db),invalidateTransfersStatements:()=>invalidateTransfersStatements(db),
@@ -115,7 +115,7 @@ export function checkArchivedLedgers(manifest,ledgers) {
115
115
  }
116
116
 
117
117
  /** The applied migrations an archive's own ledger records, [{name,sha256?}]; undefined when it carries no ledger. */
118
- export function archivedHistory(manifest,ledgers) {
118
+ export function archivedHistory(manifest,ledgers,{allowOlderShape=false}={}) {
119
119
  const tables=archivedLedgerTables(manifest);
120
120
  // A Platform-origin export records its ledger in the manifest, never as a table.
121
121
  if(manifest.migrationLedger)insist(!tables.length,'schema_mismatch:migration_history');
@@ -123,7 +123,8 @@ export function archivedHistory(manifest,ledgers) {
123
123
  insist(tables.length===1 && ledgers?.[tables[0].name],'schema_mismatch:migration_history');
124
124
  const [table]=tables,rows=ledgers[table.name],columns=table.columns.map(c=>c.name);
125
125
  if(identifier(table.name)==='rer_migrations') {
126
- insist(shape(table.columns)===platformShape,'schema_mismatch:migration_history');
126
+ const older=canonicalJson([{name:'name',type:'TEXT',notnull:0,pk:1},{name:'applied_at',type:'TEXT',notnull:1,pk:0}]);
127
+ insist(shape(table.columns)===platformShape || (allowOlderShape && shape(table.columns)===older),'schema_mismatch:migration_history');
127
128
  insist(!rows.some(row=>partial(row.name)),'schema_mismatch:uncertain_migrations');
128
129
  }else{
129
130
  insist(columns.includes('name') && columns.includes('state')===columns.includes('sha256'),'schema_mismatch:migration_history');
@@ -1,5 +1,6 @@
1
1
  import { all, statement, guard, quote, insist } from './storage.mjs';
2
2
  import { canonicalJson } from './hash.mjs';
3
+ import { excludedTable } from './catalogue.mjs';
3
4
  import { migrationSeeded, seededCondition } from './restore-safety.mjs';
4
5
 
5
6
  // Recovery requires a new installation, including excluded identity tables and
@@ -22,14 +23,22 @@ function shadowTables(tables) {
22
23
  /** What the destination must still hold when the restore commits: `emptyTables` stay empty and
23
24
  * each of `seededTables` keeps exactly the rows its migrations put there. A table with other rows
24
25
  * is listed as to-be-empty, so the preflight refuses it. */
25
- export async function legacyTargetState(db,migrations) {
26
+ export async function legacyTargetState(db,migrations,include=()=>true) {
26
27
  const tables=await all(db,"SELECT name,sql FROM sqlite_master WHERE type='table' AND sql IS NOT NULL ORDER BY name"),shadows=shadowTables(tables);
27
- const names=tables.map(t=>t.name).filter(name=>!bookkeeping(name) && !shadows.has(name.toLowerCase()));
28
+ const names=tables.map(t=>t.name).filter(name=>!bookkeeping(name) && !shadows.has(name.toLowerCase()) && include(name));
28
29
  const filled=[];
29
30
  for(const name of names)if(await statement(db,`SELECT 1 FROM ${quote(name)} LIMIT 1`).first())filled.push(name);
30
31
  const seeded=await migrationSeeded(db,filled,migrations);
31
32
  return {emptyTables:names.filter(name=>!seeded.some(s=>s.name===name)),seededTables:seeded};
32
33
  }
34
+ // Before a runner applies pending migrations, use the normal product emptiness
35
+ // rule against the existing tables. Identity exclusions and replaceable rows
36
+ // retain their normal meaning; only the already-applied history can vouch for seeds.
37
+ export async function requireProductEmpty({db,policy,migrations}) {
38
+ const {emptyTables}=await legacyTargetState(db,migrations,name=>!excludedTable(name,policy)
39
+ && !(policy.derivedTables??[]).includes(name) && !(policy.replaceableTables??[]).includes(name));
40
+ for(const name of emptyTables)insist(!(await statement(db,`SELECT 1 FROM ${quote(name)} LIMIT 1`).first()),'target_not_empty:'+name,409);
41
+ }
33
42
  export async function requireLegacyEmpty({db,buckets},{emptyTables,seededTables=[]}) {
34
43
  for(const table of emptyTables)insist(!(await statement(db,`SELECT 1 FROM ${quote(table)} LIMIT 1`).first()),'legacy_target_not_empty:'+table,409);
35
44
  for(const table of seededTables){const [condition,...values]=seededCondition(table);insist((await statement(db,`SELECT CASE WHEN (${condition}) THEN 1 ELSE 0 END AS ok`,...values).first()).ok===1,'legacy_target_not_empty:'+table.name,409);}
@@ -8,12 +8,12 @@ import { policy, schemaIdentity } from './catalogue.mjs';
8
8
  // sha256 being the migration file's hash where the runner read the file.
9
9
  export function migrationReplay(plan,input,{dataOnly=[]}={}) {
10
10
  const config=policy(input);
11
- return {names:plan.map(migration=>migration.name),dataOnly,aliases:name=>plan.find(m=>m.name===name).aliases,statements:name=>plan.find(m=>m.name===name).statements,sha256:name=>plan.find(m=>m.name===name).sha256,async schemaAfter(names) {
11
+ return {names:plan.map(migration=>migration.name),dataOnly,aliases:name=>plan.find(m=>m.name===name).aliases,statements:name=>plan.find(m=>m.name===name).statements,sha256:name=>plan.find(m=>m.name===name).sha256,async schemaAfter(names,options) {
12
12
  const scratch=new DatabaseSync(':memory:');
13
13
  const db={prepare:sql=>{const query=scratch.prepare(sql);let values=[];return {bind(...args){values=args;return this;},async all(){return {results:query.all(...values)};}};}};
14
14
  try {
15
15
  for(const migration of plan.filter(m=>names.includes(m.name)))for(const sql of migration.statements)scratch.exec(sql);
16
- return await schemaIdentity(db,config);
16
+ return await schemaIdentity(db,config,options);
17
17
  }finally{scratch.close();}
18
18
  },
19
19
  // The rows the whole replay leaves in each requested table, as sorted images (legacy-safety.mjs).
@@ -39,6 +39,7 @@ export function transferProgress(report, { interval = 3000, now = () => performa
39
39
  }
40
40
  };
41
41
  return event => {
42
+ if(event.phase==='schema-unverified') { report('Schema unverified: '+JSON.stringify(event.receipt)); return; }
42
43
  if (event.phase === 'skipped') { report(skippedTablesLine(event.tables)); return; }
43
44
  if (event.phase === 'start') {
44
45
  const noun = event.direction === 'export' ? `Exporting about ${formatBytes(event.bytes)} of local data` : `Restoring a ${formatBytes(event.bytes)} archive`;
@@ -0,0 +1,12 @@
1
+ import { all, quote, insist } from './storage.mjs';
2
+ import { catalogue, policy } from './catalogue.mjs';
3
+ import { migrationSeeded } from './restore-safety.mjs';
4
+
5
+ // Runner preflight before creating a restore job. Finalize repeats its atomic
6
+ // empty-table guards; this early read keeps an occupied destination untouched.
7
+ export async function requireEmptyTables({ db, policy: input, migrations }) {
8
+ const config = policy(input), cat = await catalogue(db, config), filled = [];
9
+ for (const table of cat.tables) if (!config.replaceableTables.includes(table.name) && (await all(db, `SELECT 1 FROM ${quote(table.name)} LIMIT 1`)).length) filled.push(table.name);
10
+ const seeded = await migrationSeeded(db, filled, migrations);
11
+ for (const name of filled) insist(seeded.some(table => table.name === name), 'target_not_empty:' + name, 409);
12
+ }
@@ -1,6 +1,9 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { git } from './source.mjs';
3
3
  import { verifyWorkflow } from './verify-workflow.mjs';
4
+ import { shared } from '../../cli/shared.mjs';
5
+
6
+ const { createRedaction } = await shared('redaction.mjs');
4
7
 
5
8
  const same = (left, right) => typeof left === 'string' && left.toLowerCase() === right.toLowerCase();
6
9
  function identity(value) {
@@ -101,9 +104,15 @@ export function githubVerify(source, repository, selector) {
101
104
  }
102
105
  if (tagUnavailable) throw Error('tag');
103
106
  result.details = rejected.size ? [...rejected].join('; ') : 'No runs found for this SHA.';
104
- } catch {
107
+ } catch (error) {
105
108
  result.reason = 'github-verify-unavailable';
106
- result.details = 'GitHub Verify could not be resolved. Check gh authentication and repository access, then try again; no local verification was substituted.';
109
+ const fallback = 'GitHub Verify could not be resolved. Check gh authentication and repository access, then try again; no local verification was substituted.';
110
+ const stderr = typeof error.stderr === 'string' || Buffer.isBuffer(error.stderr)
111
+ ? createRedaction().redact(error.stderr.toString()).trim() : '';
112
+ // Redact the complete diagnostic before bounding it, including long tokens.
113
+ const diagnostic = stderr ? stderr.slice(0, 8192) : fallback;
114
+ result.details = Number.isInteger(error.status)
115
+ ? `gh exited with status ${error.status}: ${diagnostic}` : diagnostic;
107
116
  }
108
117
  return result;
109
118
  }