@runeditrun/rer 0.2.76 → 0.2.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/cli/README.md +55 -0
- package/cli/contract.mjs +1 -1
- package/cli/deploy-command.mjs +4 -2
- package/cli/deploy-inputs.mjs +15 -3
- package/cli/deploy-installation-key.mjs +71 -0
- package/cli/deploy-secrets.mjs +2 -0
- package/cli/deploy.mjs +13 -2
- package/cli/deployment-record.mjs +2 -0
- package/cli/export.mjs +1 -1
- package/cli/main.mjs +1 -1
- package/cli/parse.mjs +3 -2
- package/cli/portability-migrations.mjs +35 -14
- package/cli/portability-worker.mjs +2 -2
- package/cli/portability.mjs +2 -2
- package/cli/runtime-front-door.mjs +1 -1
- package/global/CHANGELOG.md +14 -0
- package/global/README.md +32 -0
- package/modules/dependencies/README.md +71 -1
- package/modules/dependencies/auth.mjs +4 -4
- package/modules/dependencies/crypto.mjs +6 -1
- package/modules/dependencies/custody.mjs +16 -0
- package/modules/dependencies/index.d.mts +1 -1
- package/modules/dependencies/index.mjs +6 -5
- package/modules/dependencies/schema/keys-sealed.sql +4 -0
- package/modules/dependencies/sealing.mjs +55 -0
- package/modules/dependencies/store.mjs +62 -9
- package/modules/deploy-kit/README.md +1 -0
- package/modules/deploy-kit/owner-cli.mjs +19 -7
- package/modules/deploy-kit/owner-rekey.mjs +69 -0
- package/modules/deploy-kit/provider.mjs +9 -4
- package/modules/import-kit/src/d1/README.md +1322 -0
- package/modules/import-kit/src/d1/apply.ts +115 -0
- package/modules/import-kit/src/d1/budget.ts +89 -0
- package/modules/import-kit/src/d1/compressed-plan.ts +63 -0
- package/modules/import-kit/src/d1/creation.ts +95 -0
- package/modules/import-kit/src/d1/custody-fence.ts +27 -0
- package/modules/import-kit/src/d1/custody-state-schema.ts +67 -0
- package/modules/import-kit/src/d1/database.ts +163 -0
- package/modules/import-kit/src/d1/entry-locator.ts +61 -0
- package/modules/import-kit/src/d1/erased-artifacts.ts +38 -0
- package/modules/import-kit/src/d1/erased-custody.ts +36 -0
- package/modules/import-kit/src/d1/erased-plan.ts +47 -0
- package/modules/import-kit/src/d1/erased-reversal.ts +19 -0
- package/modules/import-kit/src/d1/erasure-bounded.ts +22 -0
- package/modules/import-kit/src/d1/erasure-claims.ts +27 -0
- package/modules/import-kit/src/d1/erasure-compiler.ts +67 -0
- package/modules/import-kit/src/d1/erasure-disposition.ts +16 -0
- package/modules/import-kit/src/d1/erasure-fragments.ts +86 -0
- package/modules/import-kit/src/d1/erasure-index.ts +53 -0
- package/modules/import-kit/src/d1/erasure-pages.ts +62 -0
- package/modules/import-kit/src/d1/erasure-progress-schema.ts +8 -0
- package/modules/import-kit/src/d1/erasure-progress.ts +61 -0
- package/modules/import-kit/src/d1/erasure-related.ts +124 -0
- package/modules/import-kit/src/d1/erasure-report.ts +31 -0
- package/modules/import-kit/src/d1/erasure-schema.ts +24 -0
- package/modules/import-kit/src/d1/erasure-selection.ts +77 -0
- package/modules/import-kit/src/d1/erasure-snapshot.ts +15 -0
- package/modules/import-kit/src/d1/erasure-stage.ts +146 -0
- package/modules/import-kit/src/d1/erasure-step.ts +12 -0
- package/modules/import-kit/src/d1/erasure-superseded.ts +98 -0
- package/modules/import-kit/src/d1/erasure-values.ts +83 -0
- package/modules/import-kit/src/d1/erasure-writes.ts +46 -0
- package/modules/import-kit/src/d1/erasure.ts +170 -0
- package/modules/import-kit/src/d1/evolutions/0001-preserved-undo.ts +13 -0
- package/modules/import-kit/src/d1/expected-state.ts +91 -0
- package/modules/import-kit/src/d1/field-redaction.ts +86 -0
- package/modules/import-kit/src/d1/guards.ts +37 -0
- package/modules/import-kit/src/d1/history.ts +71 -0
- package/modules/import-kit/src/d1/index.ts +88 -0
- package/modules/import-kit/src/d1/integrity.ts +127 -0
- package/modules/import-kit/src/d1/inventory-snapshot.ts +84 -0
- package/modules/import-kit/src/d1/jobs.ts +97 -0
- package/modules/import-kit/src/d1/native-set.ts +48 -0
- package/modules/import-kit/src/d1/native-staging-admission.ts +19 -0
- package/modules/import-kit/src/d1/native-staging-context.ts +44 -0
- package/modules/import-kit/src/d1/native-staging-lifecycle.ts +33 -0
- package/modules/import-kit/src/d1/native-staging-offset.ts +74 -0
- package/modules/import-kit/src/d1/native-staging-publication.ts +18 -0
- package/modules/import-kit/src/d1/native-staging-rows.ts +72 -0
- package/modules/import-kit/src/d1/native-staging-schema.ts +28 -0
- package/modules/import-kit/src/d1/native-staging-state.ts +22 -0
- package/modules/import-kit/src/d1/native-staging.ts +64 -0
- package/modules/import-kit/src/d1/original-copies.ts +53 -0
- package/modules/import-kit/src/d1/original-storage.ts +56 -0
- package/modules/import-kit/src/d1/originals.ts +74 -0
- package/modules/import-kit/src/d1/plan-dictionary.ts +80 -0
- package/modules/import-kit/src/d1/plans.ts +121 -0
- package/modules/import-kit/src/d1/preparation-fingerprint.ts +57 -0
- package/modules/import-kit/src/d1/preparation-header.ts +33 -0
- package/modules/import-kit/src/d1/preparation-reader.ts +98 -0
- package/modules/import-kit/src/d1/preparation-schema.ts +16 -0
- package/modules/import-kit/src/d1/preparation-state.ts +56 -0
- package/modules/import-kit/src/d1/preparation-step-combine.ts +80 -0
- package/modules/import-kit/src/d1/preparation-step-control.ts +48 -0
- package/modules/import-kit/src/d1/preparation-step-hash.ts +131 -0
- package/modules/import-kit/src/d1/preparation-step-pages.ts +77 -0
- package/modules/import-kit/src/d1/preparation-steps-schema.ts +11 -0
- package/modules/import-kit/src/d1/preparation-steps.ts +102 -0
- package/modules/import-kit/src/d1/preparations.ts +87 -0
- package/modules/import-kit/src/d1/preserved-preview.ts +89 -0
- package/modules/import-kit/src/d1/preserved-reverse.ts +91 -0
- package/modules/import-kit/src/d1/provenance-set.ts +87 -0
- package/modules/import-kit/src/d1/publication-fence.ts +22 -0
- package/modules/import-kit/src/d1/publication-receipt-schema.ts +15 -0
- package/modules/import-kit/src/d1/published-stream.ts +11 -0
- package/modules/import-kit/src/d1/read-fence.ts +64 -0
- package/modules/import-kit/src/d1/read-results.ts +16 -0
- package/modules/import-kit/src/d1/redacted-custody.ts +76 -0
- package/modules/import-kit/src/d1/redaction-step.ts +125 -0
- package/modules/import-kit/src/d1/referenced-plans.ts +136 -0
- package/modules/import-kit/src/d1/retained-values.ts +35 -0
- package/modules/import-kit/src/d1/retirement-bounded.ts +71 -0
- package/modules/import-kit/src/d1/retirement-door.ts +105 -0
- package/modules/import-kit/src/d1/retirement-schema.ts +39 -0
- package/modules/import-kit/src/d1/retirement-scope.ts +94 -0
- package/modules/import-kit/src/d1/retirement-steps.ts +76 -0
- package/modules/import-kit/src/d1/retirement-tally.ts +74 -0
- package/modules/import-kit/src/d1/retirement.ts +136 -0
- package/modules/import-kit/src/d1/reversal-conversion-record.ts +19 -0
- package/modules/import-kit/src/d1/reversal-conversion-schema.ts +11 -0
- package/modules/import-kit/src/d1/reversal-conversion.ts +40 -0
- package/modules/import-kit/src/d1/reversal-fence-schema.ts +14 -0
- package/modules/import-kit/src/d1/reversal-fence.ts +106 -0
- package/modules/import-kit/src/d1/reversal-journal.ts +24 -0
- package/modules/import-kit/src/d1/reverse.ts +103 -0
- package/modules/import-kit/src/d1/reviewed-source.ts +23 -0
- package/modules/import-kit/src/d1/sets.ts +78 -0
- package/modules/import-kit/src/d1/staged-creation.ts +201 -0
- package/modules/import-kit/src/d1/staging-admission.ts +45 -0
- package/modules/import-kit/src/d1/staging-control.ts +43 -0
- package/modules/import-kit/src/d1/staging-erasure.ts +28 -0
- package/modules/import-kit/src/d1/staging-lifecycle.ts +49 -0
- package/modules/import-kit/src/d1/staging-plan.ts +15 -0
- package/modules/import-kit/src/d1/staging-privacy.ts +22 -0
- package/modules/import-kit/src/d1/staging-publication.ts +79 -0
- package/modules/import-kit/src/d1/staging-schema.ts +37 -0
- package/modules/import-kit/src/d1/staging-statements.ts +8 -0
- package/modules/import-kit/src/d1/staging-transport.ts +70 -0
- package/modules/import-kit/src/d1/stream-boundary.ts +11 -0
- package/modules/import-kit/src/d1/stream-create.ts +55 -0
- package/modules/import-kit/src/d1/stream-identity-admission.ts +37 -0
- package/modules/import-kit/src/d1/stream-input.ts +18 -0
- package/modules/import-kit/src/d1/stream-layout.ts +43 -0
- package/modules/import-kit/src/d1/stream-origin.ts +44 -0
- package/modules/import-kit/src/d1/stream-page-integrity.ts +18 -0
- package/modules/import-kit/src/d1/stream-partition.ts +50 -0
- package/modules/import-kit/src/d1/stream-plan.ts +133 -0
- package/modules/import-kit/src/d1/stream-receipt.ts +45 -0
- package/modules/import-kit/src/d1/stream-revision-schema.ts +35 -0
- package/modules/import-kit/src/d1/stream-snapshot.ts +26 -0
- package/modules/import-kit/src/d1/stream-stage.ts +79 -0
- package/modules/import-kit/src/d1/stream-state.ts +25 -0
- package/modules/import-kit/src/d1/stream-working-set.ts +30 -0
- package/modules/import-kit/src/d1/streams.ts +39 -0
- package/modules/import-kit/src/d1/target-guards.ts +9 -0
- package/modules/import-kit/src/d1/target-identities.ts +17 -0
- package/modules/import-kit/src/d1/transport.ts +10 -0
- package/modules/import-kit/src/d1/types.ts +162 -0
- package/modules/import-kit/src/d1/undo-observations.ts +39 -0
- package/modules/import-kit/src/d1/undo-report.ts +22 -0
- package/modules/import-kit/src/d1/undo-snapshot.ts +87 -0
- package/modules/import-kit/src/d1/undo-state.ts +84 -0
- package/modules/import-kit/src/d1/undo-types.ts +110 -0
- package/modules/import-kit/src/journal/authority.ts +12 -0
- package/modules/import-kit/src/plan/budget.ts +60 -0
- package/modules/import-kit/src/plan/index.ts +123 -0
- package/modules/import-kit/src/plan/size.ts +122 -0
- package/modules/import-kit/src/provenance/canonical-hash.ts +130 -0
- package/modules/import-kit/src/provenance/canonical-stream.ts +85 -0
- package/modules/import-kit/src/provenance/credential-names.ts +131 -0
- package/modules/import-kit/src/provenance/credentials.ts +317 -0
- package/modules/import-kit/src/provenance/identity.ts +51 -0
- package/modules/import-kit/src/provenance/json-snapshot.ts +21 -0
- package/modules/import-kit/src/provenance/resumable-sha256.ts +75 -0
- package/modules/import-kit/src/provenance/validate-json.ts +19 -0
- package/modules/import-kit/src/storage/originals.ts +87 -0
- package/modules/import-kit/src/storage/provenance.ts +64 -0
- package/modules/import-kit/src/storage/schema.ts +42 -0
- package/modules/import-kit/src/types.ts +47 -0
- package/modules/operator-auth/docs/native-accounts.md +4 -1
- package/modules/operator-auth/identity/oidc/aes-gcm.mjs +21 -0
- package/modules/operator-auth/identity/oidc/crypto.mjs +5 -12
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/portability/README.md +98 -2
- package/modules/portability/backfills.mjs +42 -15
- package/modules/portability/ledgers.mjs +7 -1
- package/modules/portability/transient-tables.mjs +40 -0
- package/onboarding/local/environment.mjs +2 -2
- package/package.json +3 -1
- package/scripts/publish-check/reviewed.py +3 -1
|
@@ -4,6 +4,7 @@ import { changesData, dataStatement, reachingTables, triggerBodies, schemaChange
|
|
|
4
4
|
import { splitStatements } from './sql-text.mjs';
|
|
5
5
|
import { preservingRebuilds } from './rebuilds.mjs';
|
|
6
6
|
import { replayViews, viewReads } from './replay-views.mjs';
|
|
7
|
+
import { transientTables } from './transient-tables.mjs';
|
|
7
8
|
|
|
8
9
|
// The data statements of later migrations, judged by the tables they write
|
|
9
10
|
// (bridge.mjs placement). Restored rows never pass through a later migration.
|
|
@@ -37,40 +38,66 @@ export function laterData({applied,unapplied,replay,catalogue,archived,empty,tab
|
|
|
37
38
|
const reached=reachingTables(statements,carried),writable=reachingTables(statements,restorable);
|
|
38
39
|
const later=unapplied.flatMap(migration=>split(migration).map((sql,index)=>({migration,index,sql,data:dataStatement(sql)})));
|
|
39
40
|
const {admitted,tables:rebuilt}=preservingRebuilds(later,manifest,tables,statements),views=replayViews(statements);
|
|
40
|
-
const
|
|
41
|
+
const {missing,plans:transients}=transientTables(statements,later,fold(tables),carried);
|
|
42
|
+
const current=fold(tables),known=[...current,...missing],outside=later.filter(s=>s.data && !writable.includes(s.data.target) && !transients.has(s.data.target)),tainted=new Set();
|
|
41
43
|
// Tables an admitted write fills from archived rows (directly, through its
|
|
42
44
|
// target's triggers, or from another such table) hold rows the restore lacks.
|
|
43
|
-
const taint=name=>{if(
|
|
45
|
+
const taint=name=>{if(current.includes(name) && !tainted.has(name)){tainted.add(name);triggerBodies(statements,name).forEach(taint);return true;}};
|
|
44
46
|
for(let grew=true;grew;)grew=outside.filter(s=>s.data.names.some(name=>carried.includes(name) || tainted.has(name))).map(s=>taint(s.data.target)).some(Boolean);
|
|
45
47
|
const refused=new Set(),writes=new Map();
|
|
46
48
|
for(const s of later) {
|
|
47
49
|
if(outside.includes(s) || admitted.has(s))continue;
|
|
48
50
|
s.today=changesData(s.sql,[...reached,...tainted],empty);
|
|
49
|
-
if(s.data && restorable.includes(s.data.target)){if(!writes.has(s.data.target))writes.set(s.data.target,[]);writes.get(s.data.target).push(s);}
|
|
51
|
+
if(s.data && (restorable.includes(s.data.target) || transients.has(s.data.target))){if(!writes.has(s.data.target))writes.set(s.data.target,[]);writes.get(s.data.target).push(s);}
|
|
50
52
|
else if(s.today)refused.add(s);
|
|
51
53
|
}
|
|
52
|
-
const
|
|
54
|
+
const choices=new Map(),required=new Set();
|
|
53
55
|
for(const [table,list] of writes) {
|
|
54
56
|
// Seed INSERTs into a new table replay too: the rows already present in a
|
|
55
57
|
// fresh destination must be reset and derived from the restored installation.
|
|
56
|
-
const
|
|
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).
|
|
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};
|
|
64
|
+
// Carried target rules must use the actual archive, not reconstructed reads.
|
|
65
|
+
const bad=carried.includes(table) && list.length>1?list:list.filter(s=>!replayable(s,{...options,targetCarried:carried.includes(table)}));
|
|
57
66
|
// Writes confined to tables created after the archive retain their
|
|
58
67
|
// admission. Replay eligible seeds, but do not turn a new-table-only
|
|
59
68
|
// upgrade into a refused backfill. View reads always require resolution.
|
|
60
|
-
const
|
|
61
|
-
if(
|
|
62
|
-
|
|
69
|
+
const needed=!transient && list.some(s=>s.today || s.data.names.some(name=>views.has(name)));
|
|
70
|
+
if(needed)required.add(table);
|
|
71
|
+
if(!needed && bad.length)continue;
|
|
72
|
+
const reach=reachingTables(statements,[table]),other=later.filter(s=>s!==transient?.create && s!==transient?.drop && !admitted.has(s) && !list.includes(s) && writesAnother(s,table,reach,list));
|
|
63
73
|
if(bad.length || other.length){[...bad,...other].forEach(s=>refused.add(s));continue;}
|
|
64
|
-
|
|
74
|
+
const dependencies=list.flatMap(s=>viewReads(s.data.names,s.data.words,{...options,table}) || []).filter(name=>name!==table && !carried.includes(name));
|
|
75
|
+
choices.set(table,{list,dependencies});
|
|
76
|
+
}
|
|
77
|
+
// Remove dependent plans together: skipping an unsupported transient must
|
|
78
|
+
// never leave its consumer scheduled against a table that no longer exists.
|
|
79
|
+
for(let changed=true;changed;) {
|
|
80
|
+
changed=false;
|
|
81
|
+
for(const [table,choice] of choices)if(choice.dependencies.some(name=>!choices.has(name))) {
|
|
82
|
+
choices.delete(table);changed=true;
|
|
83
|
+
if(required.has(table))choice.list.forEach(s=>refused.add(s));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const replays=[...choices.values()].flatMap(c=>c.list),schema=new Map();
|
|
87
|
+
for(const [table,{create,drop}] of transients)if(choices.has(table)) {
|
|
88
|
+
replays.push(create,drop);schema.set(create,table);schema.set(drop,table);
|
|
65
89
|
}
|
|
66
90
|
const first=later.find(s=>refused.has(s));
|
|
67
91
|
insist(!first,'schema_mismatch:migration_data:'+first?.migration);
|
|
68
92
|
const named=Object.fromEntries(catalogue.map(name=>[folded(name),name]));
|
|
69
|
-
return {rebuilt,replays:later.filter(s=>replays.includes(s)).map(s=>
|
|
93
|
+
return {rebuilt,replays:later.filter(s=>replays.includes(s)).map(s=>{
|
|
94
|
+
const table=s.data?.target??schema.get(s);
|
|
95
|
+
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
|
+
})};
|
|
70
97
|
}
|
|
71
|
-
function replayable({data},{table,statements,restorable,writable,carried,tables,secrets,views,manifest}) {
|
|
98
|
+
function replayable({data},{table,statements,restorable,writable,carried,targetCarried,tables,secrets,views,manifest}) {
|
|
72
99
|
if(!['insert','replace'].includes(data.verb) || data.star)return false;
|
|
73
|
-
if(
|
|
100
|
+
if(targetCarried) {
|
|
74
101
|
// sqlite_sequence's high-water mark is not archived, so replay cannot
|
|
75
102
|
// reproduce a carried AUTOINCREMENT table's live key allocation.
|
|
76
103
|
if(!data.columns || autoincrement(manifest.find(t=>folded(t.name)===table).sql))return false;
|
|
@@ -83,7 +110,7 @@ function replayable({data},{table,statements,restorable,writable,carried,tables,
|
|
|
83
110
|
}
|
|
84
111
|
}
|
|
85
112
|
// A carried target participates in secret checks, even through a view.
|
|
86
|
-
if(!viewReads(data.names,data.words,{views,tables,carried,table:
|
|
113
|
+
if(!viewReads(data.names,data.words,{views,tables,carried,table:targetCarried?undefined:table,secrets}))return false;
|
|
87
114
|
if(triggerBodies(statements,table).some(name=>writable.includes(name)))return false;
|
|
88
115
|
// Foreign key actions: a row the replay deletes or rekeys (REPLACE, upsert) must reach no other catalogue table.
|
|
89
116
|
return !reachingTables(statements,restorable.filter(name=>name!==table)).includes(table);
|
|
@@ -104,12 +131,12 @@ function writesAnother(s,table,reach,replays) {
|
|
|
104
131
|
// recording rows in the job's bridge record (`replayed[i].rows`) in the same transaction.
|
|
105
132
|
export function replayStatements(db,row) {
|
|
106
133
|
const replays=row.metadata.replays??[];
|
|
107
|
-
const reset=[...new Set(replays.filter(r=>!r.carried).map(r=>r.table))].flatMap(name=>{
|
|
134
|
+
const reset=[...new Set(replays.filter(r=>!r.carried && !r.transient).map(r=>r.table))].flatMap(name=>{
|
|
108
135
|
const target=row.metadata.targets.find(t=>t.name===name);
|
|
109
136
|
insist(target,'schema_mismatch:replay_table:'+name);
|
|
110
137
|
return [statement(db,`DELETE FROM ${quote(name)}`),...(autoincrement(target.sql)?[statement(db,'DELETE FROM sqlite_sequence WHERE name=?',name)]:[])];
|
|
111
138
|
});
|
|
112
139
|
return [...reset,...replays.flatMap((r,i)=>[db.prepare(r.sql),
|
|
113
|
-
statement(db,`UPDATE rer_portability_jobs SET metadata=json_set(metadata,'$.bridge.replayed[${i}].rows'
|
|
140
|
+
statement(db,`UPDATE rer_portability_jobs SET metadata=json_set(metadata,'$.bridge.replayed[${i}].rows',${r.schema?'0':'changes()'}) WHERE id=?`,row.id)])];
|
|
114
141
|
}
|
|
115
142
|
const autoincrement=sql=>tokens(sql).some(t=>!t.quoted && folded(t.text)==='autoincrement');
|
|
@@ -22,10 +22,13 @@ export async function destinationLedger(db) {
|
|
|
22
22
|
if(found.includes('_rer_deploy_migrations'))return (await all(db,"SELECT * FROM _rer_deploy_migrations WHERE state='applied' ORDER BY name")).map(entry);
|
|
23
23
|
if(found.includes('d1_migrations')) {
|
|
24
24
|
const columns=(await all(db,'PRAGMA table_info(d1_migrations)')).map(x=>x.name);
|
|
25
|
+
insist(['id','name','applied_at'].every(name=>columns.includes(name)),'schema_mismatch:migration_history',409);
|
|
25
26
|
const tracked=columns.includes('state') || columns.includes('sha256');
|
|
26
27
|
if(tracked)insist(columns.includes('state') && columns.includes('sha256'),'schema_mismatch:migration_history',409);
|
|
27
28
|
const rows=await all(db,`SELECT name${tracked?',state,sha256':''} FROM d1_migrations ORDER BY id`);
|
|
29
|
+
insist(rows.every(row=>typeof row.name==='string') && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
|
|
28
30
|
if(tracked)insist(rows.every(row=>row.state==='applied'),'schema_mismatch:uncertain_migrations',409);
|
|
31
|
+
if(tracked)insist(rows.every(row=>typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)),'schema_mismatch:migration_history',409);
|
|
29
32
|
return rows.map(entry);
|
|
30
33
|
}
|
|
31
34
|
if(!found.includes('rer_migrations'))return;
|
|
@@ -34,6 +37,7 @@ export async function destinationLedger(db) {
|
|
|
34
37
|
// cloudflare-migrations.ts:34-44), so rowid order is application order.
|
|
35
38
|
insist(shape(await all(db,'PRAGMA table_info(rer_migrations)'))===platformShape,'schema_mismatch:migration_history',409);
|
|
36
39
|
const rows=await all(db,'SELECT name,sha256 FROM rer_migrations ORDER BY rowid');
|
|
40
|
+
insist(rows.every(row=>typeof row.name==='string' && typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)) && new Set(rows.map(row=>row.name)).size===rows.length,'schema_mismatch:migration_history',409);
|
|
37
41
|
insist(!rows.some(row=>partial(row.name)),'schema_mismatch:uncertain_migrations',409);
|
|
38
42
|
return rows.map(entry);
|
|
39
43
|
}
|
|
@@ -44,7 +48,7 @@ const entry=row=>({name:row.name,...(typeof row.sha256==='string'?{sha256:row.sh
|
|
|
44
48
|
// confirm that file, but cannot point at another one. Hashless rows use exact
|
|
45
49
|
// names or seed-declared aliases. The caller keeps the destination replay order.
|
|
46
50
|
export function matchMigrationLedger(entries,files,{dataOnly=[]}={}) {
|
|
47
|
-
|
|
51
|
+
const matched=entries.flatMap(m=>{
|
|
48
52
|
const named=files.filter(file=>file.name===m.name || file.aliases?.includes(m.name));
|
|
49
53
|
insist(named.length<=1,'migration_ledger:ambiguous:'+m.name,409);
|
|
50
54
|
if(m.sha256===undefined) {
|
|
@@ -59,6 +63,8 @@ export function matchMigrationLedger(entries,files,{dataOnly=[]}={}) {
|
|
|
59
63
|
insist(!named.length || named[0]===matches[0],'migration_ledger:conflict:'+m.name,409);
|
|
60
64
|
return [matches[0].name];
|
|
61
65
|
});
|
|
66
|
+
insist(new Set(matched).size===matched.length,'migration_ledger:ambiguous',409);
|
|
67
|
+
return matched;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
/** The ledger tables an archive carries (old archives carried rer_migrations before it became bookkeeping). */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { tokens, identifier, folded } from './generated.mjs';
|
|
2
|
+
import { schemaChange, statementNames, triggerBodies } from './migration-statements.mjs';
|
|
3
|
+
|
|
4
|
+
// A missing historical table is still a real read dependency. Reconstruct only
|
|
5
|
+
// a single, bounded CREATE / INSERTs / DROP wholly after the archive. No schema
|
|
6
|
+
// mutation, FK or trigger effects may escape this temporary lifetime.
|
|
7
|
+
export function transientTables(statements,later,tables,carried) {
|
|
8
|
+
const history=new Map(),dropped=new Set();
|
|
9
|
+
for(const sql of statements) {
|
|
10
|
+
const words=tokens(sql).map(t=>t.quoted?undefined:folded(t.text));
|
|
11
|
+
if(words[0]==='drop' && words[1]==='table')statementNames(sql).forEach(name=>dropped.add(name));
|
|
12
|
+
const ddl=tableDDL(sql);
|
|
13
|
+
if(!ddl)continue;
|
|
14
|
+
if(!history.has(ddl.name))history.set(ddl.name,[]);
|
|
15
|
+
history.get(ddl.name).push({...ddl,sql});
|
|
16
|
+
}
|
|
17
|
+
const missing=[...new Set([...history.keys(),...dropped])].filter(name=>!tables.includes(name)),plans=new Map();
|
|
18
|
+
for(const name of missing) {
|
|
19
|
+
const life=history.get(name);
|
|
20
|
+
if(carried.includes(name) || life?.length!==2 || life[0].verb!=='create' || life[1].verb!=='drop')continue;
|
|
21
|
+
const create=later.find(s=>s.sql===life[0].sql),drop=later.find(s=>s.sql===life[1].sql);
|
|
22
|
+
if(!create || !drop || later.indexOf(create)>=later.indexOf(drop) || schemaChange(create.sql)!=='create table')continue;
|
|
23
|
+
if(tokens(create.sql).some(t=>!t.quoted && folded(t.text)==='references') || triggerBodies(statements,name).length)continue;
|
|
24
|
+
const touches=later.filter(s=>statementNames(s.sql).includes(name));
|
|
25
|
+
if(touches.some(s=>s!==create && s!==drop && (!s.data || later.indexOf(s)<=later.indexOf(create) || later.indexOf(s)>=later.indexOf(drop))))continue;
|
|
26
|
+
const fills=touches.filter(s=>s.data?.target===name);
|
|
27
|
+
if(!fills.length || fills.some(s=>!['insert','replace'].includes(s.data.verb)))continue;
|
|
28
|
+
plans.set(name,{create,drop,fills});
|
|
29
|
+
}
|
|
30
|
+
return {missing,plans};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function tableDDL(sql) {
|
|
34
|
+
const list=tokens(sql),words=list.map(t=>t.quoted?undefined:folded(t.text));
|
|
35
|
+
if(!['create','drop'].includes(words[0]) || words[1]!=='table')return;
|
|
36
|
+
const at=words[2]==='if'?(words[0]==='create'?5:4):2,token=list[at];
|
|
37
|
+
// Qualified names and unusual table syntax keep the previous admission.
|
|
38
|
+
if(!token || !token.quoted && !/^[a-z_][a-z0-9_$]*$/i.test(token.text))return;
|
|
39
|
+
return {name:folded(identifier(token)),verb:words[0]};
|
|
40
|
+
}
|
|
@@ -13,7 +13,7 @@ export function localVariables(text) {
|
|
|
13
13
|
|
|
14
14
|
// Inherited application bindings never reach a build or migration command.
|
|
15
15
|
// The default names are the Base operator-auth and mail bindings.
|
|
16
|
-
export const applicationBindings = /^(SESSION_SECRET|SETUP_TOKEN|OWNER_EMAIL|AUTH_|MAIL_|OIDC_|AI_|MODELS_|RER_MODELS_)/
|
|
16
|
+
export const applicationBindings = /^(SESSION_SECRET|INSTALLATION_KEY(?:_PREVIOUS)?$|SETUP_TOKEN|OWNER_EMAIL|AUTH_|MAIL_|OIDC_|AI_|MODELS_|RER_MODELS_)/
|
|
17
17
|
|
|
18
18
|
export function buildEnvironment(bindings = applicationBindings, inherited = process.env) {
|
|
19
19
|
const env = { ...inherited, CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: 'false', CLOUDFLARE_INCLUDE_PROCESS_ENV: 'false', WRANGLER_SEND_METRICS: 'false' }
|
|
@@ -23,7 +23,7 @@ export function buildEnvironment(bindings = applicationBindings, inherited = pro
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Values printed by a child are redacted when their name marks a credential.
|
|
26
|
-
export const secretValues = (vars) => Object.entries(vars).filter(([key]) => /SECRET|TOKEN|API_KEY
|
|
26
|
+
export const secretValues = (vars) => Object.entries(vars).filter(([key]) => /SECRET|TOKEN|API_KEY|^INSTALLATION_KEY(?:_PREVIOUS)?$/.test(key)).map(([, value]) => value).filter(Boolean)
|
|
27
27
|
|
|
28
28
|
export function localOrigin(vars) {
|
|
29
29
|
let url
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runeditrun/rer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.78",
|
|
4
4
|
"description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"./adapter": "./cli/adapter.mjs",
|
|
12
12
|
"./deploy": "./cli/deploy.mjs",
|
|
13
13
|
"./portability": "./cli/portability.mjs",
|
|
14
|
+
"./portability-migrations": "./cli/portability-migrations.mjs",
|
|
14
15
|
"./errors": "./cli/errors.mjs",
|
|
15
16
|
"./jsonc": "./cli/jsonc.mjs",
|
|
16
17
|
"./parse": "./cli/parse.mjs",
|
|
@@ -70,6 +71,7 @@
|
|
|
70
71
|
"./modules/portability/legacy-safety": "./modules/portability/legacy-safety.mjs",
|
|
71
72
|
"./modules/portability/migration-history": "./modules/portability/migration-history.mjs",
|
|
72
73
|
"./modules/portability/storage": "./modules/portability/storage.mjs",
|
|
74
|
+
"./modules/import-kit/d1": "./modules/import-kit/src/d1/index.ts",
|
|
73
75
|
"./modules/erasure/fence": "./modules/erasure/fence.mjs",
|
|
74
76
|
"./modules/deploy-kit/migration-ledger": "./modules/deploy-kit/migration-ledger.mjs",
|
|
75
77
|
"./modules/deploy-kit/owner": "./modules/deploy-kit/owner.mjs",
|
|
@@ -26,8 +26,10 @@ def load_reviewed(data):
|
|
|
26
26
|
result = {}
|
|
27
27
|
for entry in document['findings']:
|
|
28
28
|
fields = {'rule', 'path', 'blob', 'reason', 'reviewer', 'date'}
|
|
29
|
-
if not isinstance(entry, dict) or set(entry) not in (fields, fields | {'fixtureValuesSha256'}, fields | {'containedFixtures'})
|
|
29
|
+
if not isinstance(entry, dict) or set(entry) not in (fields, fields | {'fixtureValuesSha256'}, fields | {'containedFixtures'}):
|
|
30
30
|
raise ValueError('invalid reviewed entry')
|
|
31
|
+
if entry['rule'] not in RULES | SECRET_RULES | FORBIDDEN | {'license.holder'}:
|
|
32
|
+
raise ValueError(f"rule {entry['rule']} is non-reviewable; see scripts/publish-check-README.md#reviewed-findings for remediation")
|
|
31
33
|
if not all(isinstance(entry[k], str) and entry[k].strip() for k in fields):
|
|
32
34
|
raise ValueError('invalid reviewed entry')
|
|
33
35
|
if not re.fullmatch(r'[0-9a-f]{40}|[0-9a-f]{64}', entry['blob']):
|