@runeditrun/rer 0.2.100 → 0.2.101
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 +30 -102
- package/cli/README.md +16 -89
- package/cli/app-address.mjs +2 -0
- package/cli/business/api.mjs +2 -1
- package/cli/business/choices.mjs +1 -1
- package/cli/business/command.mjs +36 -30
- package/cli/business/connect.mjs +1 -1
- package/cli/business/lease.mjs +0 -9
- package/cli/business/local-commands.mjs +1 -27
- package/cli/business/outbound.mjs +2 -14
- package/cli/business/questions.mjs +85 -48
- package/cli/business/service.mjs +1 -24
- package/cli/business/setup-command.mjs +33 -26
- package/cli/business/state.mjs +1 -1
- package/cli/business/supervisor.mjs +26 -91
- package/cli/companion/command.mjs +2 -0
- package/cli/demo-native.mjs +1 -1
- package/cli/parse.mjs +2 -1
- package/global/CHANGELOG.md +24 -0
- package/global/README.md +30 -102
- package/global/main.mjs +2 -0
- package/modules/container/adapters/d1-limits.mjs +2 -10
- package/modules/d1-transport/limits.d.mts +10 -0
- package/modules/d1-transport/limits.mjs +10 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/import-kit/schema/importers.schema.json +104 -2
- package/modules/import-kit/src/d1/README.md +13 -0
- package/modules/import-kit/src/d1/apply-reads.ts +48 -0
- package/modules/import-kit/src/d1/apply.ts +21 -8
- package/modules/import-kit/src/d1/history.ts +2 -2
- package/modules/import-kit/src/d1/types.ts +11 -0
- package/modules/import-kit/src/door/ADOPTING.md +0 -37
- package/modules/import-kit/src/door/README.md +0 -66
- package/modules/import-kit/src/door/admission.ts +3 -13
- package/modules/import-kit/src/door/authority.ts +0 -1
- package/modules/import-kit/src/door/failures.ts +1 -1
- package/modules/import-kit/src/door/grants.ts +5 -19
- package/modules/import-kit/src/door/handler.ts +1 -12
- package/modules/import-kit/src/door/index.ts +0 -6
- package/modules/import-kit/src/door/planning.ts +19 -44
- package/modules/import-kit/src/door/protocol.ts +2 -4
- package/modules/import-kit/src/door/schema.ts +0 -2
- package/modules/import-kit/src/door/store.ts +2 -2
- package/modules/import-kit/src/door/types.ts +1 -24
- package/modules/import-kit/src/provenance/credentials.ts +14 -5
- package/modules/import-kit/src/status/evidence.ts +3 -1
- package/modules/import-kit/src/status/index.ts +17 -2
- package/modules/import-kit/src/status/schema.ts +8 -0
- package/modules/import-kit/src/status/types.ts +25 -4
- package/package.json +1 -1
- package/cli/business/archive-task.mjs +0 -32
- package/cli/business/bounded-waves.d.mts +0 -23
- package/cli/business/bounded-waves.mjs +0 -57
- package/cli/business/catchup-task.mjs +0 -49
- package/cli/business/export-inputs.mjs +0 -79
- package/cli/business/export-task.mjs +0 -24
- package/cli/business/legacy-package.mjs +0 -117
- package/cli/business/package-transfer.mjs +0 -127
- package/cli/business/setup-demo.mjs +0 -95
- package/cli/business/vendor-door.mjs +0 -303
- package/cli/business/vendors/README.md +0 -215
- package/cli/business/vendors/calendly.mjs +0 -80
- package/cli/business/vendors/common.mjs +0 -280
- package/cli/business/vendors/credential-names.mjs +0 -124
- package/cli/business/vendors/index.mjs +0 -96
- package/cli/business/vendors/pagerduty.mjs +0 -61
- package/cli/business/vendors/sentry.mjs +0 -85
- package/cli/business/vendors/sorry.mjs +0 -106
- package/cli/business/vendors/uptimerobot.mjs +0 -21
- package/cli/business/vendors/zendesk-attachments.mjs +0 -57
- package/cli/business/vendors/zendesk-encode.mjs +0 -133
- package/cli/business/vendors/zendesk-guide.mjs +0 -34
- package/cli/business/vendors/zendesk-package.mjs +0 -28
- package/cli/business/vendors/zendesk-pages.mjs +0 -61
- package/cli/business/vendors/zendesk-people.mjs +0 -7
- package/cli/business/vendors/zendesk-store.mjs +0 -154
- package/cli/business/vendors/zendesk-tickets.mjs +0 -21
- package/cli/business/vendors/zendesk-token.mjs +0 -31
- package/cli/business/vendors/zendesk-transport.mjs +0 -48
- package/cli/business/vendors/zendesk.mjs +0 -61
- package/modules/import-kit/src/door/package.ts +0 -121
- package/modules/import-kit/src/door/waves/README.md +0 -158
- package/modules/import-kit/src/door/waves/digests.ts +0 -38
- package/modules/import-kit/src/door/waves/inventory.ts +0 -84
- package/modules/import-kit/src/door/waves/journal.ts +0 -19
- package/modules/import-kit/src/door/waves/lifecycle.ts +0 -242
- package/modules/import-kit/src/door/waves/preparation.ts +0 -190
- package/modules/import-kit/src/door/waves/schema.ts +0 -73
- package/modules/import-kit/src/door/waves/store.ts +0 -112
- package/modules/import-kit/src/door/waves/types.ts +0 -76
package/global/README.md
CHANGED
|
@@ -432,31 +432,24 @@ formats and syntax may yield no signals.
|
|
|
432
432
|
rer business setup --origin https://app.runeditrun.com --session-file /private/path/owner.session --confirm-demo
|
|
433
433
|
```
|
|
434
434
|
|
|
435
|
-
This
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
`
|
|
439
|
-
|
|
440
|
-
|
|
435
|
+
This creates the Business for the synthetic Juniper Harbor Software company in
|
|
436
|
+
`cli/business/setup-company.json` and saves its profile, through the platform's
|
|
437
|
+
owner routes (`GET` and `POST /api/business`, then `GET` and `PUT
|
|
438
|
+
/api/business/ID/profile`) using the signed-in person's session. It provisions
|
|
439
|
+
no seeds. The session file must be an owned regular file with mode `0600`,
|
|
440
|
+
containing only `rer_session=VALUE` or `__Host-rer_session=VALUE`. Symbolic links
|
|
441
|
+
are refused. The session is read in process, sent only as the platform Cookie
|
|
442
|
+
header, and never printed or placed in argv, local Business state or a receipt.
|
|
443
|
+
`--confirm-demo` is required.
|
|
441
444
|
|
|
442
445
|
Hosting defaults to `managed`; `--hosting assisted` and `--hosting self_host`
|
|
443
|
-
are also supported. There is no `hosted` alias. `--
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
receipt includes each seed's state and a top-level `complete` flag. Exit 0
|
|
451
|
-
requires `complete: true`: every required seed must be provisioned, token-issued,
|
|
452
|
-
policy-confirmed, settings-delivered and have its door proofs recorded.
|
|
453
|
-
Missing adoptions remain `not yet on the agent door` and exit nonzero.
|
|
454
|
-
|
|
455
|
-
The route order, policy, synthetic company profile and receipt are mirrored from
|
|
456
|
-
the RER platform at commit `0261033177e8e05284c037369ee9c3a85922a8aa`,
|
|
457
|
-
`scripts/business/demo.mjs` and `demo/company.json`. The platform owns the seed
|
|
458
|
-
catalogue, fixture data and door proofs. This command does not pair the computer
|
|
459
|
-
or use its stored device credential.
|
|
446
|
+
are also supported. There is no `hosted` alias. Both normal output and `--json`
|
|
447
|
+
print the receipt: `business_id`, `name`, `default_hosting`, `created` and
|
|
448
|
+
`profile` (`saved` or `unchanged`). Run it again to reuse the same Business: a
|
|
449
|
+
repeat whose profile matches changes nothing, and a Business of that name with
|
|
450
|
+
other hosting is refused (`existing_demo_hosting_differs`). Errors print a named
|
|
451
|
+
`{code}` to stderr and exit 1. This command does not pair the computer or use
|
|
452
|
+
its stored device credential.
|
|
460
453
|
|
|
461
454
|
## Business device commands
|
|
462
455
|
|
|
@@ -506,8 +499,7 @@ The install.sh form still passes either connect command through unchanged.
|
|
|
506
499
|
|
|
507
500
|
The owner chooses three things on the computer's row in the browser: "Add rules
|
|
508
501
|
so Claude Code never reads your secret files" (Claude Code user Read deny
|
|
509
|
-
rules), "Keep this computer awake while it works" (
|
|
510
|
-
prevention) and "Install the background service" (a launchd or systemd user
|
|
502
|
+
rules), "Keep this computer awake while it works" (recorded; nothing keeps the computer awake now that rer runs no exports) and "Install the background service" (a launchd or systemd user
|
|
511
503
|
service). Connect, run and next read them as `optIns` from device-authenticated
|
|
512
504
|
`GET /api/business/executors/self`, with keys `installPermissions`,
|
|
513
505
|
`awakeConsent` and `installService`; the CLI prints only the sentences. Only
|
|
@@ -540,29 +532,18 @@ refuses to remove the Keychain item (`security` exits 161 and leaves it), so
|
|
|
540
532
|
local credential is still stored" and names the one command that removes it when
|
|
541
533
|
run outside the sandbox; until then `status` says revoked, never paired.
|
|
542
534
|
|
|
543
|
-
`rer business vendor-key add sentry` requires hidden credential entry in a
|
|
544
|
-
terminal, stores it in the OS keychain and prints only `sentry:read`.
|
|
545
|
-
`remove` deletes it. The same commands support `uptimerobot`, `pagerduty` and
|
|
546
|
-
`calendly`. Sorry's export reads its public status page and needs no key. Never
|
|
547
|
-
put a key in command arguments, chat or a URL.
|
|
548
|
-
|
|
549
535
|
`rer business next` returns, within 60 seconds, one locally templated
|
|
550
536
|
classification, owner link or agent step, or says what `run` would start, and
|
|
551
|
-
says `Nothing yet` only when no agent step waits.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
a `rollback.*` card, `switchoff.cancel`) are named as the owner's, with the
|
|
562
|
-
move's page (`/business/:id/moves/:toolId` when the summary names its
|
|
563
|
-
`tool_id`, else the switch-over board `/business/:id`), never as agent work. It
|
|
564
|
-
never reflects server instructions or raw evidence. Owner items cannot be
|
|
565
|
-
answered from this CLI.
|
|
537
|
+
says `Nothing yet` only when no agent step waits. A seed's **Move in** step is
|
|
538
|
+
the agent's step: `next` names the seed's Move in page, what the seed takes (a
|
|
539
|
+
file export, a read-only key or the old tool's public address), how to export
|
|
540
|
+
from the old tool and, for a tool the seed has no importer for, the seed's own
|
|
541
|
+
import format, all from the seed's `importers.json` row. The seed's Move in page
|
|
542
|
+
does the import (a dry run with counts, the import and undo) and rer imports
|
|
543
|
+
nothing itself; `rer business done ID --note "what moved"` finishes the step once
|
|
544
|
+
the data is in the seed. A step kind this rer does not know is reported by its
|
|
545
|
+
kind and never claimed or failed. It never reflects server instructions or raw
|
|
546
|
+
evidence. Owner items cannot be answered from this CLI.
|
|
566
547
|
`rer business answer ID VENDOR uses|sells|both|product-dependency [CONFIDENCE]`
|
|
567
548
|
submits a task-scoped classification through MCP. Choose a vendor ID from the
|
|
568
549
|
question's displayed answer schema, or `none`; the suggested vendor can be
|
|
@@ -574,12 +555,12 @@ a headers helper. That output is a short-lived credential: connect it directly
|
|
|
574
555
|
to the MCP client and do not paste it into an agent transcript.
|
|
575
556
|
|
|
576
557
|
`rer business status` shows local pairing, service state and progress without
|
|
577
|
-
printing checkpoints
|
|
558
|
+
printing checkpoints. Device credentials are stored separately
|
|
578
559
|
for each Business on an origin; disconnect also finds an older per-origin
|
|
579
560
|
credential through its original pairing record and revokes it once.
|
|
580
561
|
`rer business disconnect` revokes this
|
|
581
562
|
device through device-authenticated `DELETE /api/business/executors/self` before
|
|
582
|
-
removing its service, device
|
|
563
|
+
removing its service, device credential, any read-only key an earlier rer stored, state and introduced Claude
|
|
583
564
|
rules, preserving preexisting settings and unrelated edits. It says "Device
|
|
584
565
|
revoked" only after the server confirms (`{"revoked":true}`, or 401 for a device
|
|
585
566
|
already revoked). If this session may not remove the credential, a key, the
|
|
@@ -614,60 +595,7 @@ It removes `run.lock` on every exit, including Ctrl-C,
|
|
|
614
595
|
SIGTERM and a closed terminal (SIGHUP); a lock whose process is gone, or that
|
|
615
596
|
has not been refreshed for two minutes, is cleared on the next start.
|
|
616
597
|
|
|
617
|
-
|
|
618
|
-
import door. The claim's grant names the door (`/api/rer/import/uploads` on the
|
|
619
|
-
app's HTTPS origin) and `import_grants`; every door request asks
|
|
620
|
-
`POST /api/business/tasks/:taskId/import-grants` for its own short-lived
|
|
621
|
-
RER-signed grant (`uploads` or `plan`; apply is the server's alone after the
|
|
622
|
-
owner's wave approval), and the first grant's namespace names the vendor. The
|
|
623
|
-
read-only vendor key is read from OS credential storage, never from arguments,
|
|
624
|
-
the environment or a file. The shipped adapter runs into a private 0600
|
|
625
|
-
`export-<id>.bundle` file in the state folder, each item checked by the outbound
|
|
626
|
-
detector; the bundle is sent in 64 KiB chunks, then planned, which leaves a
|
|
627
|
-
zero-write preview in the door. Run then completes the task with outputs
|
|
628
|
-
`{upload_id, plan_id, bundle_sha256}` (identifiers only); Business reads that
|
|
629
|
-
plan from the door with its own grants and completes the task only if it is the
|
|
630
|
-
plan of exactly that bundle. Run prints only counts and removes the bundle on
|
|
631
|
-
every exit. Without the key, run
|
|
632
|
-
releases the task as `paused` after an `owner_required` event and names the
|
|
633
|
-
owner's command; a running supervisor picks the export up once the key is
|
|
634
|
-
stored. A door that is not ready releases it as `paused` after a
|
|
635
|
-
`connected_runner_required` event, naming the reason. UptimeRobot needs no
|
|
636
|
-
other input. Sentry, PagerDuty and Sorry use the leased task's `export_inputs`;
|
|
637
|
-
when those inputs are missing they release as `paused` after a
|
|
638
|
-
`configuration_required` event. Calendly's folder of files has no single-bundle
|
|
639
|
-
door format yet and releases with the same event. While an agent step waits (an export, or a
|
|
640
|
-
question for `next`, or the lease an earlier run on this computer still holds),
|
|
641
|
-
run says what it waits for instead of `Nothing yet`; otherwise it names a move's
|
|
642
|
-
owner step with its link before `Nothing yet`.
|
|
643
|
-
|
|
644
|
-
`rer business run` performs claimed `catchup.vendor` and `switchoff.archive`
|
|
645
|
-
tasks the same way: the claim's grant names the door, the key comes from OS
|
|
646
|
-
credential storage, and the shipped adapter's bundle goes up in 64 KiB chunks,
|
|
647
|
-
each with its own grant, from a private 0600 file removed on every exit.
|
|
648
|
-
|
|
649
|
-
- A catch-up then plans the upload with `{uploadId, catchup: true}`. Business
|
|
650
|
-
mints its plan grant under the owner's standing catch-up approval when one
|
|
651
|
-
covers the tool, and says so with `catchup: "bounded"` on the grant. If the
|
|
652
|
-
door refuses that with `catchup_requires_proposal:<reason>` (gone, conflicting
|
|
653
|
-
or rejected records, or a change of 5% or more), run asks
|
|
654
|
-
`import-grants` for `{action: "plan", review: true}` and plans the same upload
|
|
655
|
-
again for the owner's review. Run completes with
|
|
656
|
-
`{upload_id, plan_id, bundle_sha256}`; Business applies a bounded plan under
|
|
657
|
-
the standing approval and any other only after the owner approves it.
|
|
658
|
-
- An archive calls the door's `archive` action with `{uploadId, tool, takenAt}`
|
|
659
|
-
(the tool is the vendor's namespace), then `restore-check` with the
|
|
660
|
-
`archiveId`, and requires both answers to carry the bundle's SHA-256 and size,
|
|
661
|
-
the key `business-archive/<tool>/<takenAt>` and the same counts. Run completes
|
|
662
|
-
with `{archive_id, bundle_sha256}`; Business runs its own `restore-check`
|
|
663
|
-
before the task is done. Archive grants are `uploads`, `archive` and
|
|
664
|
-
`restore-check`; catch-up grants are `uploads`, `plan` and `status`.
|
|
665
|
-
|
|
666
|
-
Run prints only counts and the archive key. When an owner summary is supplied,
|
|
667
|
-
the CLI displays its browser link and refuses to answer it.
|
|
668
|
-
|
|
669
|
-
The five deterministic adapter implementations and their native output formats
|
|
670
|
-
are described in [the adapter guide](https://github.com/runeditrun/base/blob/main/cli/business/vendors/README.md).
|
|
598
|
+
Run prints only counts. When an owner summary is supplied, the CLI displays its browser link and refuses to answer it.
|
|
671
599
|
|
|
672
600
|
## Local engineering companion
|
|
673
601
|
|
package/global/main.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { localDefaults } from './launch/local-defaults.mjs';
|
|
|
6
6
|
import { handleBrokenPipes } from './output.mjs';
|
|
7
7
|
import { repositoryCommands, repositoryHelp } from './cli/repository-contract.mjs';
|
|
8
8
|
import { repoArguments } from './cli/repository.mjs';
|
|
9
|
+
import { appSignInHelp } from '../cli/app-address.mjs';
|
|
9
10
|
|
|
10
11
|
const help = `Usage: rer VERB [FLAGS]
|
|
11
12
|
|
|
@@ -48,6 +49,7 @@ else its vendored scripts/rer.mjs.
|
|
|
48
49
|
of a checkout that pins the rer package use it).
|
|
49
50
|
|
|
50
51
|
Checkout verbs: ${Object.keys(checkoutVerbs).join(', ')}, listing. Run rer VERB --help in a checkout for its flags.
|
|
52
|
+
${appSignInHelp}
|
|
51
53
|
`;
|
|
52
54
|
|
|
53
55
|
export async function main(argv) {
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* native D1 rejected a concatenation tree of depth 101 on 27 Oct 2026.
|
|
4
|
-
* Node 22.20.0 ignores DatabaseSync limits options: preflight is mandatory.
|
|
5
|
-
* Queries per Worker invocation (Paid 1000, Free 50, batch counts once) and
|
|
6
|
-
* the 30 second query deadline are NOT-ENFORCEABLE-LOCALLY here: a database
|
|
7
|
-
* connection has neither the invocation boundary nor the provider scheduler.
|
|
8
|
-
*/
|
|
9
|
-
export const d1NativeLimits = Object.freeze({ length: 2_000_000, sqlLength: 100_000,
|
|
10
|
-
column: 100, variableNumber: 100, functionArg: 32, likePatternLength: 50, exprDepth: 100 });
|
|
1
|
+
import { d1NativeLimits } from '../../d1-transport/limits.mjs';
|
|
2
|
+
export { d1NativeLimits } from '../../d1-transport/limits.mjs';
|
|
11
3
|
|
|
12
4
|
/** ENFORCED-BY-PREFLIGHT. Self-contained so workerd can run the same code.
|
|
13
5
|
* Depth is an estimate, not a complete SQLite parser. Parentheses, function
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Shared native D1 ceilings used by SQL adapters and selected-key readers. */
|
|
2
|
+
export const d1NativeLimits: Readonly<{
|
|
3
|
+
length: number;
|
|
4
|
+
sqlLength: number;
|
|
5
|
+
column: number;
|
|
6
|
+
variableNumber: number;
|
|
7
|
+
functionArg: number;
|
|
8
|
+
likePatternLength: number;
|
|
9
|
+
exprDepth: number;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Cloudflare D1 per-query limits, supplied from the platform limits page
|
|
2
|
+
* (updated 24 Oct 2026). Expression depth 100 is OBSERVED-NOT-DOCUMENTED:
|
|
3
|
+
* native D1 rejected a concatenation tree of depth 101 on 27 Oct 2026.
|
|
4
|
+
* Node 22.20.0 ignores DatabaseSync limits options: preflight is mandatory.
|
|
5
|
+
* Queries per Worker invocation (Paid 1000, Free 50, batch counts once) and
|
|
6
|
+
* the 30 second query deadline are NOT-ENFORCEABLE-LOCALLY here: a database
|
|
7
|
+
* connection has neither the invocation boundary nor the provider scheduler.
|
|
8
|
+
*/
|
|
9
|
+
export const d1NativeLimits = Object.freeze({ length: 2_000_000, sqlLength: 100_000,
|
|
10
|
+
column: 100, variableNumber: 100, functionArg: 32, likePatternLength: 50, exprDepth: 100 });
|
|
@@ -32,7 +32,8 @@ export async function prepareNative(folder) {
|
|
|
32
32
|
modules['_rer/isolate.js'] = { js: (await readFile(new URL('./isolate.mjs', import.meta.url), 'utf8')).replace('__RER_APP_ENTRY__', entry)
|
|
33
33
|
+ objectExports(bindings) };
|
|
34
34
|
for (const file of ISOLATE_FILES) modules[`_rer/${file}.js`] = { js: (await readFile(new URL(`./${file}.mjs`, import.meta.url), 'utf8')).replace('../../container/adapters/d1-limits.mjs', './d1-limits.js') };
|
|
35
|
-
modules['_rer/d1-limits.js'] = { js: await readFile(new URL('../../
|
|
35
|
+
modules['_rer/d1-native-limits.js'] = { js: await readFile(new URL('../../d1-transport/limits.mjs', import.meta.url), 'utf8') };
|
|
36
|
+
modules['_rer/d1-limits.js'] = { js: (await readFile(new URL('../../container/adapters/d1-limits.mjs', import.meta.url), 'utf8')).replaceAll('../../d1-transport/limits.mjs', './d1-native-limits.js') };
|
|
36
37
|
const assets = await collectFiles(join(app, 'dist/client'));
|
|
37
38
|
await cp(join(app, 'dist/client'), join(folder, 'assets'), { recursive: true });
|
|
38
39
|
const theme = await prepareTheme(folder, assets);
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
"required": ["$schema", "schemaVersion", "importers"],
|
|
7
7
|
"properties": {
|
|
8
8
|
"$schema": { "const": "./schema/importers.schema.json" },
|
|
9
|
-
"schemaVersion": { "
|
|
9
|
+
"schemaVersion": { "enum": [1, 2] },
|
|
10
|
+
"format": { "$ref": "#/$defs/format" },
|
|
10
11
|
"importers": {
|
|
11
12
|
"type": "array",
|
|
12
13
|
"minItems": 1,
|
|
@@ -14,13 +15,21 @@
|
|
|
14
15
|
"oneOf": [
|
|
15
16
|
{ "$ref": "#/$defs/verifiedImporter" },
|
|
16
17
|
{ "$ref": "#/$defs/documentedImporter" },
|
|
17
|
-
{ "$ref": "#/$defs/noneImporter" }
|
|
18
|
+
{ "$ref": "#/$defs/noneImporter" },
|
|
19
|
+
{ "$ref": "#/$defs/moveIn" },
|
|
20
|
+
{ "$ref": "#/$defs/moveInVerifiedImporter" },
|
|
21
|
+
{ "$ref": "#/$defs/moveInDocumentedImporter" },
|
|
22
|
+
{ "$ref": "#/$defs/moveInNoneImporter" }
|
|
18
23
|
]
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"additionalProperties": false,
|
|
23
28
|
"$defs": {
|
|
29
|
+
"format": { "type": "string", "minLength": 1, "maxLength": 300, "pattern": "^(?!.*(?:^|/)\\.\\.(?:/|$))[A-Za-z0-9._][A-Za-z0-9._/-]*$" },
|
|
30
|
+
"moveInPath": { "type": "string", "minLength": 1, "maxLength": 300, "pattern": "^/(?:[^/\\s][^\\s]*)?$" },
|
|
31
|
+
"accepts": { "type": "array", "minItems": 1, "maxItems": 3, "uniqueItems": true, "items": { "enum": ["file", "key", "address"] } },
|
|
32
|
+
"export": { "type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^\\r\\n]+$" },
|
|
24
33
|
"artifact": {
|
|
25
34
|
"type": "object",
|
|
26
35
|
"required": ["link", "sha256", "size"],
|
|
@@ -102,6 +111,99 @@
|
|
|
102
111
|
}
|
|
103
112
|
},
|
|
104
113
|
"additionalProperties": false
|
|
114
|
+
},
|
|
115
|
+
"moveIn": {
|
|
116
|
+
"type": "object",
|
|
117
|
+
"required": ["incumbent", "product", "moveIn", "accepts", "export"],
|
|
118
|
+
"properties": {
|
|
119
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
120
|
+
"product": { "type": "string", "minLength": 1 },
|
|
121
|
+
"moveIn": { "$ref": "#/$defs/moveInPath" },
|
|
122
|
+
"accepts": { "$ref": "#/$defs/accepts" },
|
|
123
|
+
"export": { "$ref": "#/$defs/export" }
|
|
124
|
+
},
|
|
125
|
+
"additionalProperties": false
|
|
126
|
+
},
|
|
127
|
+
"moveInVerifiedImporter": {
|
|
128
|
+
"type": "object",
|
|
129
|
+
"required": ["incumbent", "product", "moveIn", "accepts", "export", "status", "evidence"],
|
|
130
|
+
"properties": {
|
|
131
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
132
|
+
"product": { "type": "string", "minLength": 1 },
|
|
133
|
+
"moveIn": { "$ref": "#/$defs/moveInPath" },
|
|
134
|
+
"accepts": { "$ref": "#/$defs/accepts" },
|
|
135
|
+
"export": { "$ref": "#/$defs/export" },
|
|
136
|
+
"status": { "const": "verified" },
|
|
137
|
+
"evidence": {
|
|
138
|
+
"type": "object",
|
|
139
|
+
"required": ["link", "sha256", "size", "research"],
|
|
140
|
+
"properties": {
|
|
141
|
+
"link": { "type": "string", "minLength": 1 },
|
|
142
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
143
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
144
|
+
"research": { "$ref": "#/$defs/artifact" }
|
|
145
|
+
},
|
|
146
|
+
"additionalProperties": false
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"additionalProperties": false
|
|
150
|
+
},
|
|
151
|
+
"moveInDocumentedImporter": {
|
|
152
|
+
"type": "object",
|
|
153
|
+
"required": ["incumbent", "product", "moveIn", "accepts", "export", "status", "evidence"],
|
|
154
|
+
"properties": {
|
|
155
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
156
|
+
"product": { "type": "string", "minLength": 1 },
|
|
157
|
+
"moveIn": { "$ref": "#/$defs/moveInPath" },
|
|
158
|
+
"accepts": { "$ref": "#/$defs/accepts" },
|
|
159
|
+
"export": { "$ref": "#/$defs/export" },
|
|
160
|
+
"status": { "const": "documented format" },
|
|
161
|
+
"evidence": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"required": [
|
|
164
|
+
"link", "sha256", "size", "sourceRepository", "sourceRevision",
|
|
165
|
+
"sourcePath", "sourceSha256", "validation", "realExport"
|
|
166
|
+
],
|
|
167
|
+
"properties": {
|
|
168
|
+
"link": { "type": "string", "minLength": 1 },
|
|
169
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
170
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
171
|
+
"sourceRepository": { "type": "string", "minLength": 1 },
|
|
172
|
+
"sourceRevision": { "type": "string", "pattern": "^[a-f0-9]{40,64}$" },
|
|
173
|
+
"sourcePath": { "type": "string", "minLength": 1 },
|
|
174
|
+
"sourceSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
175
|
+
"validation": { "const": "synthetic-only" },
|
|
176
|
+
"realExport": { "const": "not-supplied" }
|
|
177
|
+
},
|
|
178
|
+
"additionalProperties": false
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"additionalProperties": false
|
|
182
|
+
},
|
|
183
|
+
"moveInNoneImporter": {
|
|
184
|
+
"type": "object",
|
|
185
|
+
"required": ["incumbent", "product", "moveIn", "accepts", "export", "status", "evidence"],
|
|
186
|
+
"properties": {
|
|
187
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
188
|
+
"product": { "type": "string", "minLength": 1 },
|
|
189
|
+
"moveIn": { "$ref": "#/$defs/moveInPath" },
|
|
190
|
+
"accepts": { "$ref": "#/$defs/accepts" },
|
|
191
|
+
"export": { "$ref": "#/$defs/export" },
|
|
192
|
+
"status": { "const": "none" },
|
|
193
|
+
"evidence": {
|
|
194
|
+
"type": "object",
|
|
195
|
+
"required": ["link", "sha256", "size", "reason", "checkedAt"],
|
|
196
|
+
"properties": {
|
|
197
|
+
"link": { "type": "string", "minLength": 1 },
|
|
198
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
199
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
200
|
+
"reason": { "type": "string", "minLength": 1 },
|
|
201
|
+
"checkedAt": { "type": "string", "format": "date-time" }
|
|
202
|
+
},
|
|
203
|
+
"additionalProperties": false
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"additionalProperties": false
|
|
105
207
|
}
|
|
106
208
|
}
|
|
107
209
|
}
|
|
@@ -153,6 +153,14 @@ are local runtime receipts, not hosted capacity evidence.
|
|
|
153
153
|
The product implements `D1TargetAdapter`:
|
|
154
154
|
|
|
155
155
|
- `read(database, destination, kind, id)` returns the complete native `TargetRow`.
|
|
156
|
+
- Optional `readMany(database, destination, keys)` returns the same complete rows
|
|
157
|
+
as individual reads, in key order, including duplicate keys and missing rows.
|
|
158
|
+
Query only selected keys and preserve native decoding. With private transport,
|
|
159
|
+
adapters that implement `stagingRead` can also provide `stagingReadMany`, with
|
|
160
|
+
the same exact before-read guards for each key. Missing bulk methods retain
|
|
161
|
+
individual reads; any bulk-read error discards the snapshot and uses that path.
|
|
162
|
+
An inherited bulk method must preserve an overridden single read or throw.
|
|
163
|
+
Bulk observations belong only to the current publication.
|
|
156
164
|
- `matches(rowOrNull, destination, kind, id)` returns an exact SQL boolean snapshot
|
|
157
165
|
predicate covering the native values, revision, attachment and related evidence,
|
|
158
166
|
or complete absence for null. This is the optimistic concurrency fence. Checking
|
|
@@ -194,6 +202,11 @@ per request. The port does not retry failed SQL, conflicts or revoked authority.
|
|
|
194
202
|
A failed batch leaves its prior committed checkpoint intact; the product can fix
|
|
195
203
|
the condition and explicitly call `resumeD1Import`, or `rollbackD1Import`.
|
|
196
204
|
|
|
205
|
+
Saved read budget can advance a budget-limited call's checkpoint or surface a
|
|
206
|
+
later entry's refusal one call earlier, with the same error code and text.
|
|
207
|
+
Such a refusal publishes none of the gathered entries and leaves the job at its
|
|
208
|
+
last consistent durable checkpoint.
|
|
209
|
+
|
|
197
210
|
Each batch guards the immutable plan, actor binding, checkpoint and durable fence
|
|
198
211
|
inside the same D1 transaction as native rows, originals, source ownership,
|
|
199
212
|
provenance and journal. Successful batches increment the fence. Unlike Node's
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { d1NativeLimits } from '../../../d1-transport/limits.mjs';
|
|
2
|
+
import type { PlanEntry, TargetRow } from '../types.ts';
|
|
3
|
+
import type { D1ImportContext, D1Sql } from './types.ts';
|
|
4
|
+
|
|
5
|
+
const key = (kind: string, id: string): string => JSON.stringify([kind, id]);
|
|
6
|
+
export interface ApplyReads {
|
|
7
|
+
sources: Map<string, any>;
|
|
8
|
+
predecessors: Map<string, any>;
|
|
9
|
+
targets: Map<string, { row: TargetRow | undefined; guards?: D1Sql[] }>;
|
|
10
|
+
}
|
|
11
|
+
export const targetReadKey = key;
|
|
12
|
+
|
|
13
|
+
/** Only this publication's candidate entries. No observation survives atomic().
|
|
14
|
+
* Failure discards the entire snapshot, including any earlier successful set. */
|
|
15
|
+
export async function applyReads(entries: PlanEntry[], context: D1ImportContext): Promise<ApplyReads | undefined> {
|
|
16
|
+
const { database: db, targets } = context.storage;
|
|
17
|
+
const staged = context.maxBatchBytes !== undefined && !!targets.stagingRead;
|
|
18
|
+
if (staged ? !targets.stagingReadMany : !targets.readMany) return;
|
|
19
|
+
try {
|
|
20
|
+
const sources = new Map<string, any>(), predecessors = new Map<string, any>();
|
|
21
|
+
const identities = [...new Set(entries.map(entry => entry.identity))];
|
|
22
|
+
for (let i = 0; i < identities.length; i += d1NativeLimits.variableNumber) {
|
|
23
|
+
const part = identities.slice(i, i + d1NativeLimits.variableNumber);
|
|
24
|
+
const { results } = await db.prepare(`SELECT * FROM ik_sources WHERE identity IN (${part.map(() => '?').join(',')})`).bind(...part).all();
|
|
25
|
+
for (const row of results) sources.set(row.identity, row);
|
|
26
|
+
}
|
|
27
|
+
const keys = [...new Map(entries.flatMap(entry => entry.effects.map(effect => [key(effect.targetKind, effect.targetId), { kind: effect.targetKind, id: effect.targetId }] as const))).values()];
|
|
28
|
+
const snapshots: { row: TargetRow | undefined; guards?: D1Sql[] }[] = staged
|
|
29
|
+
? await targets.stagingReadMany!(db, context.destination, keys)
|
|
30
|
+
: (await targets.readMany!(db, context.destination, keys)).map(row => ({ row }));
|
|
31
|
+
if (snapshots.length !== keys.length) throw new Error('IMPORT_NATIVE_STAGING_GUARD_REQUIRED');
|
|
32
|
+
const native = new Map<string, { row: TargetRow | undefined; guards?: D1Sql[] }>();
|
|
33
|
+
for (const [i, selected] of keys.entries()) {
|
|
34
|
+
const snapshot = snapshots[i];
|
|
35
|
+
if (staged && !snapshot.guards?.length) throw new Error('IMPORT_NATIVE_STAGING_GUARD_REQUIRED');
|
|
36
|
+
native.set(key(selected.kind, selected.id), snapshot);
|
|
37
|
+
}
|
|
38
|
+
const size = Math.floor((d1NativeLimits.variableNumber - 1) / 2);
|
|
39
|
+
for (let i = 0; i < keys.length; i += size) {
|
|
40
|
+
const part = keys.slice(i, i + size);
|
|
41
|
+
const { results } = await db.prepare(`SELECT * FROM ik_provenance WHERE destination=? AND (target_kind,target_id) IN (${part.map(() => '(?,?)').join(',')}) AND reversed=0`).bind(context.destination, ...part.flatMap(k => [k.kind, k.id])).all();
|
|
42
|
+
for (const row of results) predecessors.set(key(row.target_kind, row.target_id), row);
|
|
43
|
+
}
|
|
44
|
+
return { sources, predecessors, targets: native };
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -15,6 +15,7 @@ import { custodyGuards, validatedProvenance, inventoryGuards, reusedSourceGuards
|
|
|
15
15
|
import { supersedeTarget } from './history.ts';
|
|
16
16
|
import { readOriginals } from './originals.ts';
|
|
17
17
|
import { changed, putRow, updateRows } from './expected-state.ts';
|
|
18
|
+
import { applyReads, targetReadKey, type ApplyReads } from './apply-reads.ts';
|
|
18
19
|
|
|
19
20
|
export async function applyD1ImportBatches(jobOrId: ImportJob | string, context: D1ImportContext): Promise<ImportJob> {
|
|
20
21
|
context = requestContext(context);
|
|
@@ -35,16 +36,19 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
|
|
|
35
36
|
let effects = 0, scope = nativeStagingScope(job, plan);
|
|
36
37
|
let prefix = atomicPrefix(context, 'apply', statements, scope);
|
|
37
38
|
let planned = prefix ? prefix.count(progress(job, 0), returnReads) : cost(context, publication(job, 0, statements, scope), returnReads);
|
|
38
|
-
|
|
39
|
+
const pending = plan.entries.slice(job.checkpoint, job.checkpoint + batchSize);
|
|
40
|
+
let reads: ApplyReads | undefined, loaded = false;
|
|
41
|
+
for (const entry of pending) {
|
|
39
42
|
if (entries.length && effects + entry.effects.length > 1000) break;
|
|
40
43
|
if (entry.effects.length > 1000) throw new Error('SOURCE_EFFECT_LIMIT');
|
|
41
44
|
// Stop before an entry's own reads could exhaust the request. The exact
|
|
42
45
|
// request, as atomic will send it, is counted again once the entry is built.
|
|
43
46
|
const reserve = 40 + entry.effects.length * 16;
|
|
44
47
|
if (remaining(context) - planned < reserve) { if (!entries.length) { if (count > 0) return job; throw new D1RequestLimitError(); } break; }
|
|
48
|
+
if (!loaded) { reads = await applyReads(pending, context); loaded = true; }
|
|
45
49
|
const candidate: D1Sql[] = [], nextScope = { ...scope, nativeGuards:[...scope.nativeGuards], postGuards:[...scope.postGuards], targets:[...scope.targets] };
|
|
46
50
|
const candidateUndo: D1UndoEffect[] | undefined = undoEffects && [];
|
|
47
|
-
await publishEntry(id, entry, job.checkpoint + entries.length, context, candidate, nextScope, candidateUndo);
|
|
51
|
+
await publishEntry(id, entry, job.checkpoint + entries.length, context, candidate, nextScope, candidateUndo, reads);
|
|
48
52
|
const nextPrefix = prefix?.extend(candidate);
|
|
49
53
|
const next = nextPrefix ? undefined : publication(job, entries.length + 1, [...statements, ...candidate], nextScope);
|
|
50
54
|
const spent = nextPrefix ? nextPrefix.count(progress(job, entries.length + 1), returnReads) : cost(context, next!, returnReads);
|
|
@@ -90,18 +94,19 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
|
|
|
90
94
|
}
|
|
91
95
|
return current.job;
|
|
92
96
|
}
|
|
93
|
-
async function publishEntry(id: string, entry: PlanEntry, ordinal: number, context: D1ImportContext, statements: D1Sql[], scope: NativeStagingScope, undoEffects?: D1UndoEffect[]): Promise<void> {
|
|
97
|
+
async function publishEntry(id: string, entry: PlanEntry, ordinal: number, context: D1ImportContext, statements: D1Sql[], scope: NativeStagingScope, undoEffects?: D1UndoEffect[], reads?: ApplyReads): Promise<void> {
|
|
94
98
|
const { database: db, targets } = context.storage, effectsHash = sha256(canonicalJson(entry.effects));
|
|
95
|
-
const prior = await db.prepare('SELECT * FROM ik_sources WHERE identity=?').bind(entry.identity).first();
|
|
99
|
+
const prior = reads ? reads.sources.get(entry.identity) : await db.prepare('SELECT * FROM ik_sources WHERE identity=?').bind(entry.identity).first();
|
|
96
100
|
if (prior) {
|
|
97
101
|
if (prior.source_hash !== entry.source.payloadHash || prior.mapping_version !== context.mappingVersion || prior.effects_hash !== effectsHash) throw new Error('SOURCE_ID_CONTENT_CONFLICT');
|
|
98
102
|
await reusedSourceGuards(entry, prior.job_id, context, statements);
|
|
99
103
|
statements.push(guard(sql('EXISTS(SELECT 1 FROM ik_sources WHERE identity=? AND source_hash=? AND mapping_version=? AND effects_hash=? AND job_id=?)', entry.identity, prior.source_hash, prior.mapping_version, prior.effects_hash, prior.job_id)));
|
|
100
104
|
for (const effect of entry.effects) {
|
|
101
|
-
const
|
|
105
|
+
const predecessor = reads?.predecessors.get(targetReadKey(effect.targetKind, effect.targetId));
|
|
106
|
+
const raw = reads ? (predecessor?.source_identity === entry.identity ? predecessor : null) : await db.prepare('SELECT * FROM ik_provenance WHERE source_identity=? AND destination=? AND target_kind=? AND target_id=? AND reversed=0').bind(entry.identity, context.destination, effect.targetKind, effect.targetId).first();
|
|
102
107
|
if (!raw) throw new Error('PROVENANCE_MISSING');
|
|
103
108
|
const p = await validatedProvenance(raw, context, statements);
|
|
104
|
-
const current = await
|
|
109
|
+
const current = await readTarget(context, scope, effect.targetKind, effect.targetId, reads);
|
|
105
110
|
if (!current || current.revision !== p.appliedRevision || sha256(canonicalJson(current.value)) !== p.valueHash || attachmentHash(current.attachment) !== p.attachmentHash) throw new Error('NATIVE_EDIT_CONFLICT');
|
|
106
111
|
const post = targetGuards(targets,current,context.destination,effect.targetKind,effect.targetId);
|
|
107
112
|
scope.postGuards.push(...post);
|
|
@@ -113,7 +118,7 @@ async function publishEntry(id: string, entry: PlanEntry, ordinal: number, conte
|
|
|
113
118
|
statements.push(guard(sql('NOT EXISTS(SELECT 1 FROM ik_sources WHERE identity=?)', entry.identity)));
|
|
114
119
|
for (const [index, effect] of entry.effects.entries()) {
|
|
115
120
|
validateEffect(effect);
|
|
116
|
-
const before = await
|
|
121
|
+
const before = await readTarget(context, scope, effect.targetKind, effect.targetId, reads);
|
|
117
122
|
if (before ? effect.expectedRevision !== before.revision : effect.expectedRevision !== undefined) throw new Error('TARGET_REVISION_CONFLICT');
|
|
118
123
|
const prospective = prospectiveEffect(id, entry, index, before, context.destination);
|
|
119
124
|
const { expected: row, provenance: p } = prospective;
|
|
@@ -121,7 +126,7 @@ async function publishEntry(id: string, entry: PlanEntry, ordinal: number, conte
|
|
|
121
126
|
const post = targetGuards(targets, row, context.destination, effect.targetKind, effect.targetId);
|
|
122
127
|
scope.postGuards.push(...post);
|
|
123
128
|
undoEffects?.push(prospective);
|
|
124
|
-
await supersedeTarget(p, before, context, statements);
|
|
129
|
+
await supersedeTarget(p, before, context, statements, reads ? reads.predecessors.get(targetReadKey(effect.targetKind, effect.targetId)) ?? null : undefined);
|
|
125
130
|
const record_json=canonicalJson(p);
|
|
126
131
|
statements.push(...targetGuards(targets,before ?? null, context.destination, effect.targetKind, effect.targetId), ...targets.write(row), ...post, changed(retainedSql(['INSERT INTO ik_provenance(id,job_id,ordinal,effect_ordinal,source_identity,destination,target_kind,target_id,record_json) VALUES(', ',', ',', ',', ',', ',', ',', ',', ',', ')'], [p.id, id, ordinal, index, entry.identity, context.destination, effect.targetKind, effect.targetId, record_json], [8]),putRow('ik_provenance',{id:p.id,job_id:id,ordinal,effect_ordinal:index,source_identity:entry.identity,destination:context.destination,target_kind:effect.targetKind,target_id:effect.targetId,reversed:0,record_json})));
|
|
127
132
|
}
|
|
@@ -129,6 +134,14 @@ async function publishEntry(id: string, entry: PlanEntry, ordinal: number, conte
|
|
|
129
134
|
statements.push(changed(sql('INSERT INTO ik_sources(identity,source_hash,mapping_version,effects_hash,job_id) VALUES(?,?,?,?,?)', entry.identity, entry.source.payloadHash, context.mappingVersion, effectsHash, id),putRow('ik_sources',{identity:entry.identity,source_hash:entry.source.payloadHash,mapping_version:context.mappingVersion,effects_hash:effectsHash,job_id:id})));
|
|
130
135
|
}
|
|
131
136
|
|
|
137
|
+
async function readTarget(context: D1ImportContext, scope: NativeStagingScope, kind: string, id: string, reads?: ApplyReads) {
|
|
138
|
+
if (!reads) return readStagedTarget(context, scope, kind, id);
|
|
139
|
+
const snapshot = reads.targets.get(targetReadKey(kind, id))!;
|
|
140
|
+
scope.nativeGuards.push(...(snapshot.guards ?? []).map(guard));
|
|
141
|
+
scope.targets.push({ kind, id, present: !!snapshot.row });
|
|
142
|
+
return snapshot.row;
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
function entryWrite(job_id:string,ordinal:number,source_identity:string,owner_job_id:string,effects_hash:string):D1Sql{
|
|
133
146
|
return changed(sql('INSERT INTO ik_d1_entries(job_id,ordinal,source_identity,owner_job_id,effects_hash) VALUES(?,?,?,?,?)',job_id,ordinal,source_identity,owner_job_id,effects_hash),putRow('ik_d1_entries',{job_id,ordinal,source_identity,owner_job_id,effects_hash}));
|
|
134
147
|
}
|
|
@@ -10,9 +10,9 @@ export const provenanceColumns = 'id,job_id,ordinal,effect_ordinal,source_identi
|
|
|
10
10
|
|
|
11
11
|
/** Transfer only a currently attributed exact native snapshot, explicitly reviewed
|
|
12
12
|
* through expectedRevision. Original attribution remains unchanged in history. */
|
|
13
|
-
export async function supersedeTarget(successor: D1ProvenanceRow, before: TargetRow | undefined, context: D1ImportContext, statements: D1Sql[]): Promise<void> {
|
|
13
|
+
export async function supersedeTarget(successor: D1ProvenanceRow, before: TargetRow | undefined, context: D1ImportContext, statements: D1Sql[], snapshot?: any): Promise<void> {
|
|
14
14
|
const db = context.storage.database;
|
|
15
|
-
const prior = await db.prepare('SELECT * FROM ik_provenance WHERE destination=? AND target_kind=? AND target_id=? AND reversed=0').bind(successor.destination, successor.targetKind, successor.targetId).first();
|
|
15
|
+
const prior = snapshot === undefined ? await db.prepare('SELECT * FROM ik_provenance WHERE destination=? AND target_kind=? AND target_id=? AND reversed=0').bind(successor.destination, successor.targetKind, successor.targetId).first() : snapshot;
|
|
16
16
|
if (!prior) {
|
|
17
17
|
statements.push(guard(sql('NOT EXISTS(SELECT 1 FROM ik_provenance WHERE destination=? AND target_kind=? AND target_id=? AND reversed=0)', successor.destination, successor.targetKind, successor.targetId)));
|
|
18
18
|
return;
|
|
@@ -34,11 +34,22 @@ export interface D1TargetAdapter extends Partial<D1PreservedUndoAdapter> {
|
|
|
34
34
|
/** Optional transport staging support. Guards must fence every native field
|
|
35
35
|
* from before the first read, including same-revision edits and absence. */
|
|
36
36
|
stagingRead?(db: D1Database, destination: string, kind: string, id: string): Promise<{ row: TargetRow | undefined; guards: D1Sql[] }>;
|
|
37
|
+
/** Optional selected-key equivalent of N stagingRead calls. Return exactly one
|
|
38
|
+
* {row, guards} per key in input order, repeating duplicate keys and preserving
|
|
39
|
+
* absence. Fence every native field from before its first read, including
|
|
40
|
+
* same-revision edits. Read only selected keys, never list the destination.
|
|
41
|
+
* Preserve overridden stagingRead/read behavior or throw for single-read fallback. */
|
|
42
|
+
stagingReadMany?(db: D1Database, destination: string, keys: readonly { kind: string; id: string }[]): Promise<{ row: TargetRow | undefined; guards: D1Sql[] }[]>;
|
|
37
43
|
/** Protect exact post-state during cleanup, install a known invalidatable
|
|
38
44
|
* receipt after exact checks, then release. Final scalar predicates run
|
|
39
45
|
* read-only after every mutation and must bind the expected post-state. */
|
|
40
46
|
stagingPublication?(stageId: string, destination: string, targets: { kind: string; id: string; present: boolean }[]): { protect: D1Sql[]; seal: D1Sql[]; release: D1Sql[]; final: D1Sql[] };
|
|
41
47
|
read(db: D1Database, destination: string, kind: string, id: string): Promise<TargetRow | undefined>;
|
|
48
|
+
/** Optional selected-key equivalent of N read calls. Return exactly one result
|
|
49
|
+
* per key in input order, repeating duplicate keys and preserving undefined
|
|
50
|
+
* for absence. Read only selected keys, never list the destination. Preserve
|
|
51
|
+
* overridden read behavior or throw so the caller can fall back to singles. */
|
|
52
|
+
readMany?(db: D1Database, destination: string, keys: readonly { kind: string; id: string }[]): Promise<(TargetRow | undefined)[]>;
|
|
42
53
|
matches(row: TargetRow | null, destination: string, kind: string, id: string): D1Sql;
|
|
43
54
|
/** Optional exact row snapshot split into conjunctive predicates. All parts,
|
|
44
55
|
* including absence/cardinality, commit in the same native transaction. */
|