@moltzap/client 2026.812.0 → 2026.902.0
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/LICENSE +202 -21
- package/NOTICE +19 -0
- package/README.md +50 -0
- package/bin/moltzapd +9 -0
- package/dist/client-runtime.d.ts +10 -0
- package/dist/client-runtime.d.ts.map +1 -0
- package/dist/client-runtime.js +218 -0
- package/dist/client-runtime.js.map +1 -0
- package/dist/contract.d.ts +338 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +213 -0
- package/dist/contract.js.map +1 -0
- package/dist/contract.types-check.d.ts +99 -0
- package/dist/contract.types-check.d.ts.map +1 -0
- package/dist/contract.types-check.js +7 -0
- package/dist/contract.types-check.js.map +1 -0
- package/dist/daemon/configuration.d.ts +46 -0
- package/dist/daemon/configuration.d.ts.map +1 -0
- package/dist/daemon/configuration.js +69 -0
- package/dist/daemon/configuration.js.map +1 -0
- package/dist/daemon/management.d.ts +23 -0
- package/dist/daemon/management.d.ts.map +1 -0
- package/dist/daemon/management.js +489 -0
- package/dist/daemon/management.js.map +1 -0
- package/dist/daemon/registration.d.ts +72 -0
- package/dist/daemon/registration.d.ts.map +1 -0
- package/dist/daemon/registration.js +109 -0
- package/dist/daemon/registration.js.map +1 -0
- package/dist/daemon/runtime/activation.d.ts +95 -0
- package/dist/daemon/runtime/activation.d.ts.map +1 -0
- package/dist/daemon/runtime/activation.js +99 -0
- package/dist/daemon/runtime/activation.js.map +1 -0
- package/dist/daemon/runtime/controller.d.ts +34 -0
- package/dist/daemon/runtime/controller.d.ts.map +1 -0
- package/dist/daemon/runtime/controller.js +106 -0
- package/dist/daemon/runtime/controller.js.map +1 -0
- package/dist/daemon/runtime/history-export.d.ts +23 -0
- package/dist/daemon/runtime/history-export.d.ts.map +1 -0
- package/dist/daemon/runtime/history-export.js +47 -0
- package/dist/daemon/runtime/history-export.js.map +1 -0
- package/dist/daemon/runtime/index.d.ts +24 -0
- package/dist/daemon/runtime/index.d.ts.map +1 -0
- package/dist/daemon/runtime/index.js +65 -0
- package/dist/daemon/runtime/index.js.map +1 -0
- package/dist/daemon/runtime/protocol.d.ts +63 -0
- package/dist/daemon/runtime/protocol.d.ts.map +1 -0
- package/dist/daemon/runtime/protocol.js +133 -0
- package/dist/daemon/runtime/protocol.js.map +1 -0
- package/dist/endpoint/addressing/index.d.ts +39 -0
- package/dist/endpoint/addressing/index.d.ts.map +1 -0
- package/dist/endpoint/addressing/index.js +114 -0
- package/dist/endpoint/addressing/index.js.map +1 -0
- package/dist/endpoint/engine-dissemination.d.ts +11 -0
- package/dist/endpoint/engine-dissemination.d.ts.map +1 -0
- package/dist/endpoint/engine-dissemination.js +71 -0
- package/dist/endpoint/engine-dissemination.js.map +1 -0
- package/dist/endpoint/engine-durability.d.ts +69 -0
- package/dist/endpoint/engine-durability.d.ts.map +1 -0
- package/dist/endpoint/engine-durability.js +210 -0
- package/dist/endpoint/engine-durability.js.map +1 -0
- package/dist/endpoint/engine-send.d.ts +50 -0
- package/dist/endpoint/engine-send.d.ts.map +1 -0
- package/dist/endpoint/engine-send.js +422 -0
- package/dist/endpoint/engine-send.js.map +1 -0
- package/dist/endpoint/engine-types.d.ts +132 -0
- package/dist/endpoint/engine-types.d.ts.map +1 -0
- package/dist/endpoint/engine-types.js +13 -0
- package/dist/endpoint/engine-types.js.map +1 -0
- package/dist/endpoint/engine.d.ts +14 -0
- package/dist/endpoint/engine.d.ts.map +1 -0
- package/dist/endpoint/engine.js +280 -0
- package/dist/endpoint/engine.js.map +1 -0
- package/dist/endpoint/protocol/evidence.d.ts +37 -0
- package/dist/endpoint/protocol/evidence.d.ts.map +1 -0
- package/dist/endpoint/protocol/evidence.js +80 -0
- package/dist/endpoint/protocol/evidence.js.map +1 -0
- package/dist/endpoint/protocol/index.d.ts +26 -0
- package/dist/endpoint/protocol/index.d.ts.map +1 -0
- package/dist/endpoint/protocol/index.js +543 -0
- package/dist/endpoint/protocol/index.js.map +1 -0
- package/dist/endpoint/recovery/barrier.d.ts +23 -0
- package/dist/endpoint/recovery/barrier.d.ts.map +1 -0
- package/dist/endpoint/recovery/barrier.js +47 -0
- package/dist/endpoint/recovery/barrier.js.map +1 -0
- package/dist/endpoint/recovery/index.d.ts +29 -0
- package/dist/endpoint/recovery/index.d.ts.map +1 -0
- package/dist/endpoint/recovery/index.js +489 -0
- package/dist/endpoint/recovery/index.js.map +1 -0
- package/dist/endpoint/recovery/reanchor/empty.d.ts +22 -0
- package/dist/endpoint/recovery/reanchor/empty.d.ts.map +1 -0
- package/dist/endpoint/recovery/reanchor/empty.js +163 -0
- package/dist/endpoint/recovery/reanchor/empty.js.map +1 -0
- package/dist/endpoint/recovery/reanchor/index.d.ts +30 -0
- package/dist/endpoint/recovery/reanchor/index.d.ts.map +1 -0
- package/dist/endpoint/recovery/reanchor/index.js +479 -0
- package/dist/endpoint/recovery/reanchor/index.js.map +1 -0
- package/dist/endpoint/recovery/state.d.ts +130 -0
- package/dist/endpoint/recovery/state.d.ts.map +1 -0
- package/dist/endpoint/recovery/state.js +296 -0
- package/dist/endpoint/recovery/state.js.map +1 -0
- package/dist/endpoint/recovery/store-evidence.d.ts +17 -0
- package/dist/endpoint/recovery/store-evidence.d.ts.map +1 -0
- package/dist/endpoint/recovery/store-evidence.js +79 -0
- package/dist/endpoint/recovery/store-evidence.js.map +1 -0
- package/dist/endpoint/recovery/store.d.ts +56 -0
- package/dist/endpoint/recovery/store.d.ts.map +1 -0
- package/dist/endpoint/recovery/store.js +499 -0
- package/dist/endpoint/recovery/store.js.map +1 -0
- package/dist/endpoint/representation-canonical.d.ts +17 -0
- package/dist/endpoint/representation-canonical.d.ts.map +1 -0
- package/dist/endpoint/representation-canonical.js +48 -0
- package/dist/endpoint/representation-canonical.js.map +1 -0
- package/dist/endpoint/representation-codec.d.ts +51 -0
- package/dist/endpoint/representation-codec.d.ts.map +1 -0
- package/dist/endpoint/representation-codec.js +159 -0
- package/dist/endpoint/representation-codec.js.map +1 -0
- package/dist/endpoint/representation-schemas.d.ts +1831 -0
- package/dist/endpoint/representation-schemas.d.ts.map +1 -0
- package/dist/endpoint/representation-schemas.js +195 -0
- package/dist/endpoint/representation-schemas.js.map +1 -0
- package/dist/endpoint/representation-verification.d.ts +79 -0
- package/dist/endpoint/representation-verification.d.ts.map +1 -0
- package/dist/endpoint/representation-verification.js +420 -0
- package/dist/endpoint/representation-verification.js.map +1 -0
- package/dist/endpoint/representation.d.ts +6 -0
- package/dist/endpoint/representation.d.ts.map +1 -0
- package/dist/endpoint/representation.js +8 -0
- package/dist/endpoint/representation.js.map +1 -0
- package/dist/endpoint/router-worker/index.d.ts +16 -0
- package/dist/endpoint/router-worker/index.d.ts.map +1 -0
- package/dist/endpoint/router-worker/index.js +547 -0
- package/dist/endpoint/router-worker/index.js.map +1 -0
- package/dist/endpoint/router-worker/types.d.ts +183 -0
- package/dist/endpoint/router-worker/types.d.ts.map +1 -0
- package/dist/endpoint/router-worker/types.js +31 -0
- package/dist/endpoint/router-worker/types.js.map +1 -0
- package/dist/endpoint/store/anchors.d.ts +83 -0
- package/dist/endpoint/store/anchors.d.ts.map +1 -0
- package/dist/endpoint/store/anchors.js +471 -0
- package/dist/endpoint/store/anchors.js.map +1 -0
- package/dist/endpoint/store/database/index.d.ts +6 -0
- package/dist/endpoint/store/database/index.d.ts.map +1 -0
- package/dist/endpoint/store/database/index.js +6 -0
- package/dist/endpoint/store/database/index.js.map +1 -0
- package/dist/endpoint/store/database/schema.d.ts +44 -0
- package/dist/endpoint/store/database/schema.d.ts.map +1 -0
- package/dist/endpoint/store/database/schema.js +345 -0
- package/dist/endpoint/store/database/schema.js.map +1 -0
- package/dist/endpoint/store/database/values.d.ts +119 -0
- package/dist/endpoint/store/database/values.d.ts.map +1 -0
- package/dist/endpoint/store/database/values.js +194 -0
- package/dist/endpoint/store/database/values.js.map +1 -0
- package/dist/endpoint/store/deliveries.d.ts +38 -0
- package/dist/endpoint/store/deliveries.d.ts.map +1 -0
- package/dist/endpoint/store/deliveries.js +124 -0
- package/dist/endpoint/store/deliveries.js.map +1 -0
- package/dist/endpoint/store/dissemination.d.ts +27 -0
- package/dist/endpoint/store/dissemination.d.ts.map +1 -0
- package/dist/endpoint/store/dissemination.js +139 -0
- package/dist/endpoint/store/dissemination.js.map +1 -0
- package/dist/endpoint/store/index.d.ts +15 -0
- package/dist/endpoint/store/index.d.ts.map +1 -0
- package/dist/endpoint/store/index.js +76 -0
- package/dist/endpoint/store/index.js.map +1 -0
- package/dist/endpoint/store/management.d.ts +42 -0
- package/dist/endpoint/store/management.d.ts.map +1 -0
- package/dist/endpoint/store/management.js +259 -0
- package/dist/endpoint/store/management.js.map +1 -0
- package/dist/endpoint/store/outbound.d.ts +62 -0
- package/dist/endpoint/store/outbound.d.ts.map +1 -0
- package/dist/endpoint/store/outbound.js +278 -0
- package/dist/endpoint/store/outbound.js.map +1 -0
- package/dist/endpoint/store/records.d.ts +56 -0
- package/dist/endpoint/store/records.d.ts.map +1 -0
- package/dist/endpoint/store/records.js +352 -0
- package/dist/endpoint/store/records.js.map +1 -0
- package/dist/endpoint/store/rows/index.d.ts +138 -0
- package/dist/endpoint/store/rows/index.d.ts.map +1 -0
- package/dist/endpoint/store/rows/index.js +307 -0
- package/dist/endpoint/store/rows/index.js.map +1 -0
- package/dist/endpoint/store/types.d.ts +223 -0
- package/dist/endpoint/store/types.d.ts.map +1 -0
- package/dist/endpoint/store/types.js +15 -0
- package/dist/endpoint/store/types.js.map +1 -0
- package/dist/endpoint/store.d.ts +10 -0
- package/dist/endpoint/store.d.ts.map +1 -0
- package/dist/endpoint/store.js +6 -0
- package/dist/endpoint/store.js.map +1 -0
- package/dist/harness-mcp-contract.d.ts +101 -0
- package/dist/harness-mcp-contract.d.ts.map +1 -0
- package/dist/harness-mcp-contract.js +61 -0
- package/dist/harness-mcp-contract.js.map +1 -0
- package/dist/{harness-mcp-server.d.ts → harness-mcp-http.d.ts} +9 -8
- package/dist/harness-mcp-http.d.ts.map +1 -0
- package/dist/{harness-mcp-server.js → harness-mcp-http.js} +38 -60
- package/dist/harness-mcp-http.js.map +1 -0
- package/dist/harness-mcp-subscription.d.ts +12 -7
- package/dist/harness-mcp-subscription.d.ts.map +1 -1
- package/dist/harness-mcp-subscription.js +113 -100
- package/dist/harness-mcp-subscription.js.map +1 -1
- package/dist/harness-mcp-wire.d.ts +24 -49
- package/dist/harness-mcp-wire.d.ts.map +1 -1
- package/dist/harness-mcp-wire.js +381 -124
- package/dist/harness-mcp-wire.js.map +1 -1
- package/dist/index.d.ts +4 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -1
- package/dist/management-runtime.d.ts +217 -0
- package/dist/management-runtime.d.ts.map +1 -0
- package/dist/management-runtime.js +127 -0
- package/dist/management-runtime.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +46 -0
- package/dist/server.js.map +1 -0
- package/dist/server.types-check.d.ts +23 -0
- package/dist/server.types-check.d.ts.map +1 -0
- package/dist/server.types-check.js +7 -0
- package/dist/server.types-check.js.map +1 -0
- package/package.json +24 -52
- package/dist/agent-client.d.ts +0 -5
- package/dist/agent-client.d.ts.map +0 -1
- package/dist/agent-client.js +0 -3
- package/dist/agent-client.js.map +0 -1
- package/dist/auth.d.ts +0 -37
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -79
- package/dist/auth.js.map +0 -1
- package/dist/bounded-map.d.ts +0 -32
- package/dist/bounded-map.d.ts.map +0 -1
- package/dist/bounded-map.js +0 -79
- package/dist/bounded-map.js.map +0 -1
- package/dist/channel-base/format-cross-conv.d.ts +0 -43
- package/dist/channel-base/format-cross-conv.d.ts.map +0 -1
- package/dist/channel-base/format-cross-conv.js +0 -65
- package/dist/channel-base/format-cross-conv.js.map +0 -1
- package/dist/channel-base/format-group-block.d.ts +0 -48
- package/dist/channel-base/format-group-block.d.ts.map +0 -1
- package/dist/channel-base/format-group-block.js +0 -62
- package/dist/channel-base/format-group-block.js.map +0 -1
- package/dist/channel-base/index.d.ts +0 -12
- package/dist/channel-base/index.d.ts.map +0 -1
- package/dist/channel-base/index.js +0 -16
- package/dist/channel-base/index.js.map +0 -1
- package/dist/channel-core-enrichment.d.ts +0 -38
- package/dist/channel-core-enrichment.d.ts.map +0 -1
- package/dist/channel-core-enrichment.js +0 -217
- package/dist/channel-core-enrichment.js.map +0 -1
- package/dist/channel-core-test-support.d.ts +0 -75
- package/dist/channel-core-test-support.d.ts.map +0 -1
- package/dist/channel-core-test-support.js +0 -74
- package/dist/channel-core-test-support.js.map +0 -1
- package/dist/channel-core.d.ts +0 -306
- package/dist/channel-core.d.ts.map +0 -1
- package/dist/channel-core.js +0 -365
- package/dist/channel-core.js.map +0 -1
- package/dist/config.d.ts +0 -33
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -51
- package/dist/config.js.map +0 -1
- package/dist/config.test-utils.d.ts +0 -24
- package/dist/config.test-utils.d.ts.map +0 -1
- package/dist/config.test-utils.js +0 -57
- package/dist/config.test-utils.js.map +0 -1
- package/dist/harness/client-runtime.d.ts +0 -31
- package/dist/harness/client-runtime.d.ts.map +0 -1
- package/dist/harness/client-runtime.js +0 -121
- package/dist/harness/client-runtime.js.map +0 -1
- package/dist/harness/index.d.ts +0 -5
- package/dist/harness/index.d.ts.map +0 -1
- package/dist/harness/index.js +0 -5
- package/dist/harness/index.js.map +0 -1
- package/dist/harness/runtime.d.ts +0 -301
- package/dist/harness/runtime.d.ts.map +0 -1
- package/dist/harness/runtime.js +0 -165
- package/dist/harness/runtime.js.map +0 -1
- package/dist/harness-client.d.ts +0 -47
- package/dist/harness-client.d.ts.map +0 -1
- package/dist/harness-client.js +0 -76
- package/dist/harness-client.js.map +0 -1
- package/dist/harness-context-projection.d.ts +0 -35
- package/dist/harness-context-projection.d.ts.map +0 -1
- package/dist/harness-context-projection.js +0 -123
- package/dist/harness-context-projection.js.map +0 -1
- package/dist/harness-mcp-server.d.ts.map +0 -1
- package/dist/harness-mcp-server.js.map +0 -1
- package/dist/local-paths.d.ts +0 -11
- package/dist/local-paths.d.ts.map +0 -1
- package/dist/local-paths.js +0 -21
- package/dist/local-paths.js.map +0 -1
- package/dist/message-rendering.d.ts +0 -4
- package/dist/message-rendering.d.ts.map +0 -1
- package/dist/message-rendering.js +0 -8
- package/dist/message-rendering.js.map +0 -1
- package/dist/moltzapd-catalog.d.ts +0 -35
- package/dist/moltzapd-catalog.d.ts.map +0 -1
- package/dist/moltzapd-catalog.js +0 -117
- package/dist/moltzapd-catalog.js.map +0 -1
- package/dist/moltzapd-child-ipc.d.ts +0 -26
- package/dist/moltzapd-child-ipc.d.ts.map +0 -1
- package/dist/moltzapd-child-ipc.js +0 -31
- package/dist/moltzapd-child-ipc.js.map +0 -1
- package/dist/moltzapd-child.d.ts +0 -55
- package/dist/moltzapd-child.d.ts.map +0 -1
- package/dist/moltzapd-child.js +0 -225
- package/dist/moltzapd-child.js.map +0 -1
- package/dist/moltzapd-main.d.ts +0 -3
- package/dist/moltzapd-main.d.ts.map +0 -1
- package/dist/moltzapd-main.js +0 -18
- package/dist/moltzapd-main.js.map +0 -1
- package/dist/moltzapd-registration.d.ts +0 -40
- package/dist/moltzapd-registration.d.ts.map +0 -1
- package/dist/moltzapd-registration.js +0 -59
- package/dist/moltzapd-registration.js.map +0 -1
- package/dist/moltzapd.d.ts +0 -85
- package/dist/moltzapd.d.ts.map +0 -1
- package/dist/moltzapd.js +0 -150
- package/dist/moltzapd.js.map +0 -1
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts +0 -53
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts.map +0 -1
- package/dist/notification/__tests__/subscribe-signatures.types-check.js +0 -29
- package/dist/notification/__tests__/subscribe-signatures.types-check.js.map +0 -1
- package/dist/notification/errors.d.ts +0 -41
- package/dist/notification/errors.d.ts.map +0 -1
- package/dist/notification/errors.js +0 -24
- package/dist/notification/errors.js.map +0 -1
- package/dist/notification/index.d.ts +0 -6
- package/dist/notification/index.d.ts.map +0 -1
- package/dist/notification/index.js +0 -6
- package/dist/notification/index.js.map +0 -1
- package/dist/notification/stream.d.ts +0 -75
- package/dist/notification/stream.d.ts.map +0 -1
- package/dist/notification/stream.js +0 -30
- package/dist/notification/stream.js.map +0 -1
- package/dist/notification/trace.d.ts +0 -10
- package/dist/notification/trace.d.ts.map +0 -1
- package/dist/notification/trace.js +0 -34
- package/dist/notification/trace.js.map +0 -1
- package/dist/pagination.d.ts +0 -52
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js +0 -51
- package/dist/pagination.js.map +0 -1
- package/dist/presentation/index.d.ts +0 -3
- package/dist/presentation/index.d.ts.map +0 -1
- package/dist/presentation/index.js +0 -3
- package/dist/presentation/index.js.map +0 -1
- package/dist/presentation/state.d.ts +0 -77
- package/dist/presentation/state.d.ts.map +0 -1
- package/dist/presentation/state.js +0 -211
- package/dist/presentation/state.js.map +0 -1
- package/dist/profile.d.ts +0 -106
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -171
- package/dist/profile.js.map +0 -1
- package/dist/service-event-trace.d.ts +0 -15
- package/dist/service-event-trace.d.ts.map +0 -1
- package/dist/service-event-trace.js +0 -35
- package/dist/service-event-trace.js.map +0 -1
- package/dist/service.d.ts +0 -228
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -485
- package/dist/service.js.map +0 -1
- package/dist/test-utils/channel-service-fixture.d.ts +0 -53
- package/dist/test-utils/channel-service-fixture.d.ts.map +0 -1
- package/dist/test-utils/channel-service-fixture.js +0 -178
- package/dist/test-utils/channel-service-fixture.js.map +0 -1
- package/dist/test-utils/fake-service.d.ts +0 -82
- package/dist/test-utils/fake-service.d.ts.map +0 -1
- package/dist/test-utils/fake-service.js +0 -108
- package/dist/test-utils/fake-service.js.map +0 -1
- package/dist/test-utils/harness.d.ts +0 -27
- package/dist/test-utils/harness.d.ts.map +0 -1
- package/dist/test-utils/harness.js +0 -33
- package/dist/test-utils/harness.js.map +0 -1
- package/dist/test-utils/ids.d.ts +0 -21
- package/dist/test-utils/ids.d.ts.map +0 -1
- package/dist/test-utils/ids.js +0 -68
- package/dist/test-utils/ids.js.map +0 -1
- package/dist/test-utils/index.d.ts +0 -56
- package/dist/test-utils/index.d.ts.map +0 -1
- package/dist/test-utils/index.js +0 -67
- package/dist/test-utils/index.js.map +0 -1
- package/dist/test-utils/process/reserve-port.d.ts +0 -20
- package/dist/test-utils/process/reserve-port.d.ts.map +0 -1
- package/dist/test-utils/process/reserve-port.js +0 -41
- package/dist/test-utils/process/reserve-port.js.map +0 -1
- package/dist/test-utils/standalone-provisioning.d.ts +0 -22
- package/dist/test-utils/standalone-provisioning.d.ts.map +0 -1
- package/dist/test-utils/standalone-provisioning.js +0 -17
- package/dist/test-utils/standalone-provisioning.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/** @file SQLite ownership, exact-version preflight, and closed persistence primitives. */
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
// eslint-disable-next-line agent-code-guard/prefer-effect-platform -- Ownership requires synchronous permission changes before the database escapes acquisition.
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { DatabaseSync } from "node:sqlite";
|
|
7
|
+
import { mapStoreFailure, readInteger, readText, requireText, StoreSignal, } from "./values.js";
|
|
8
|
+
const DATABASE_NAME = "moltzapd.sqlite3";
|
|
9
|
+
const SCHEMA_VERSION = 2;
|
|
10
|
+
/**
|
|
11
|
+
* Acquires and exclusively locks one exact-version endpoint database.
|
|
12
|
+
* @param stateDirectory Exclusive persistent state directory.
|
|
13
|
+
* @returns Acquired database state after integrity and compatibility checks.
|
|
14
|
+
*/
|
|
15
|
+
export const openStoreState = (stateDirectory) => Effect.try({
|
|
16
|
+
try: () => initializeStoreState(stateDirectory),
|
|
17
|
+
catch: (failure) => mapStoreFailure(failure, "persistence"),
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Closes exactly the SQLite and volatile snapshot state in this scope.
|
|
21
|
+
* @param state Acquired database and process-local snapshots.
|
|
22
|
+
* @returns An infallible finalizer effect.
|
|
23
|
+
*/
|
|
24
|
+
export const closeStoreState = (state) => Effect.sync(() => {
|
|
25
|
+
if (state.closed) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
state.closed = true;
|
|
29
|
+
state.snapshots.clear();
|
|
30
|
+
try {
|
|
31
|
+
state.database.close();
|
|
32
|
+
// eslint-disable-next-line agent-code-guard/bare-catch -- Finalization must remain infallible and disclose no SQLite diagnostic. #ignore-sloppy-code-next-line[bare-catch]: Store finalization preserves its infallible persistence boundary.
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Scope finalization cannot disclose or override the operation result.
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Converts a synchronous store operation into the closed Effect channel.
|
|
40
|
+
* @param state Acquired database and process-local snapshots.
|
|
41
|
+
* @param operation Synchronous operation inside the ownership boundary.
|
|
42
|
+
* @returns The operation in the closed store error channel.
|
|
43
|
+
*/
|
|
44
|
+
export function runStoreOperation(state, operation) {
|
|
45
|
+
return Effect.try({
|
|
46
|
+
try: () => {
|
|
47
|
+
if (state.closed) {
|
|
48
|
+
throw new StoreSignal("closed");
|
|
49
|
+
}
|
|
50
|
+
return operation();
|
|
51
|
+
},
|
|
52
|
+
catch: (failure) => mapStoreFailure(failure, "persistence"),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs one non-yielding SQLite transaction and preserves its first failure.
|
|
57
|
+
* @param database Exclusively owned endpoint database.
|
|
58
|
+
* @param operation Non-yielding transition to commit atomically.
|
|
59
|
+
* @param mode SQLite write-lock mode.
|
|
60
|
+
* @returns The committed transition result.
|
|
61
|
+
*/
|
|
62
|
+
export function transaction(database, operation, mode = "IMMEDIATE") {
|
|
63
|
+
database.exec(`BEGIN ${mode}`);
|
|
64
|
+
try {
|
|
65
|
+
const value = operation();
|
|
66
|
+
database.exec("COMMIT");
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
catch (failure) {
|
|
70
|
+
try {
|
|
71
|
+
database.exec("ROLLBACK");
|
|
72
|
+
// eslint-disable-next-line agent-code-guard/bare-catch -- Rollback failure cannot replace or expose the original failure. #ignore-sloppy-code-next-line[bare-catch]: The original persistence failure remains authoritative.
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// The original closed failure remains authoritative.
|
|
76
|
+
}
|
|
77
|
+
throw failure;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function initializeStoreState(stateDirectory) {
|
|
81
|
+
requireText(stateDirectory);
|
|
82
|
+
mkdirSync(stateDirectory, { recursive: true, mode: 0o700 });
|
|
83
|
+
const databasePath = resolve(stateDirectory, DATABASE_NAME);
|
|
84
|
+
const expected = existsSync(databasePath)
|
|
85
|
+
? inspectExistingDatabase(databasePath)
|
|
86
|
+
: undefined;
|
|
87
|
+
let database;
|
|
88
|
+
try {
|
|
89
|
+
database = openWritableDatabase(databasePath);
|
|
90
|
+
const disposition = preflightDatabase(database);
|
|
91
|
+
if (expected !== undefined && disposition !== expected) {
|
|
92
|
+
throw new StoreSignal("incompatible");
|
|
93
|
+
}
|
|
94
|
+
chmodSync(stateDirectory, 0o700);
|
|
95
|
+
chmodSync(databasePath, 0o600);
|
|
96
|
+
configureDatabase(database);
|
|
97
|
+
if (disposition === "initialize") {
|
|
98
|
+
initializeDatabase(database);
|
|
99
|
+
}
|
|
100
|
+
return { database, snapshots: new Map(), closed: false };
|
|
101
|
+
}
|
|
102
|
+
catch (failure) {
|
|
103
|
+
try {
|
|
104
|
+
database?.close();
|
|
105
|
+
// eslint-disable-next-line agent-code-guard/bare-catch -- Failed acquisition closes best-effort without replacing the startup failure. #ignore-sloppy-code-next-line[bare-catch]: The original persistence startup failure remains authoritative.
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Initialization reports only the original closed failure category.
|
|
109
|
+
}
|
|
110
|
+
throw failure;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function inspectExistingDatabase(databasePath) {
|
|
114
|
+
const database = new DatabaseSync(databasePath, {
|
|
115
|
+
readOnly: true,
|
|
116
|
+
enableForeignKeyConstraints: false,
|
|
117
|
+
enableDoubleQuotedStringLiterals: false,
|
|
118
|
+
allowExtension: false,
|
|
119
|
+
timeout: 0,
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
return preflightDatabase(database);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
database.close();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function openWritableDatabase(databasePath) {
|
|
129
|
+
return new DatabaseSync(databasePath, {
|
|
130
|
+
enableForeignKeyConstraints: true,
|
|
131
|
+
enableDoubleQuotedStringLiterals: false,
|
|
132
|
+
allowExtension: false,
|
|
133
|
+
timeout: 0,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function preflightDatabase(database) {
|
|
137
|
+
const versionRow = database.prepare("PRAGMA user_version").get();
|
|
138
|
+
if (versionRow === undefined) {
|
|
139
|
+
throw new StoreSignal("corrupt");
|
|
140
|
+
}
|
|
141
|
+
const version = readInteger(versionRow, "user_version");
|
|
142
|
+
if (version !== 0 && version !== SCHEMA_VERSION) {
|
|
143
|
+
throw new StoreSignal("incompatible");
|
|
144
|
+
}
|
|
145
|
+
if (version === 0) {
|
|
146
|
+
if (hasUserSchemaObjects(database)) {
|
|
147
|
+
throw new StoreSignal("incompatible");
|
|
148
|
+
}
|
|
149
|
+
requireHealthyDatabase(database);
|
|
150
|
+
return "initialize";
|
|
151
|
+
}
|
|
152
|
+
requireHealthyDatabase(database);
|
|
153
|
+
return "reopen";
|
|
154
|
+
}
|
|
155
|
+
function hasUserSchemaObjects(database) {
|
|
156
|
+
return (database
|
|
157
|
+
.prepare(`SELECT 1 AS retained FROM sqlite_schema
|
|
158
|
+
WHERE type IN ('table', 'index', 'view', 'trigger')
|
|
159
|
+
AND name NOT LIKE 'sqlite_%'
|
|
160
|
+
LIMIT 1`)
|
|
161
|
+
.get() !== undefined);
|
|
162
|
+
}
|
|
163
|
+
function requireHealthyDatabase(database) {
|
|
164
|
+
const check = database.prepare("PRAGMA quick_check").all();
|
|
165
|
+
const checkRow = check[0];
|
|
166
|
+
if (check.length !== 1 ||
|
|
167
|
+
checkRow === undefined ||
|
|
168
|
+
readText(checkRow, "quick_check") !== "ok") {
|
|
169
|
+
throw new StoreSignal("corrupt");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function configureDatabase(database) {
|
|
173
|
+
database.exec("PRAGMA busy_timeout = 0");
|
|
174
|
+
database.exec("PRAGMA foreign_keys = ON");
|
|
175
|
+
const journal = database.prepare("PRAGMA journal_mode = WAL").get();
|
|
176
|
+
const locking = database.prepare("PRAGMA locking_mode = EXCLUSIVE").get();
|
|
177
|
+
database.exec("PRAGMA synchronous = FULL");
|
|
178
|
+
const foreignKeys = database.prepare("PRAGMA foreign_keys").get();
|
|
179
|
+
const synchronous = database.prepare("PRAGMA synchronous").get();
|
|
180
|
+
requireTextPragma("journal_mode", "wal", journal);
|
|
181
|
+
requireTextPragma("locking_mode", "exclusive", locking);
|
|
182
|
+
requireIntegerPragma("foreign_keys", 1, foreignKeys);
|
|
183
|
+
requireIntegerPragma("synchronous", 2, synchronous);
|
|
184
|
+
}
|
|
185
|
+
function requireTextPragma(key, expected, row) {
|
|
186
|
+
if (row === undefined) {
|
|
187
|
+
throw new StoreSignal("persistence");
|
|
188
|
+
}
|
|
189
|
+
if (readText(row, key) !== expected) {
|
|
190
|
+
throw new StoreSignal("persistence");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function requireIntegerPragma(key, expected, row) {
|
|
194
|
+
if (row === undefined) {
|
|
195
|
+
throw new StoreSignal("persistence");
|
|
196
|
+
}
|
|
197
|
+
if (readInteger(row, key) !== expected) {
|
|
198
|
+
throw new StoreSignal("persistence");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const schemaSql = `
|
|
202
|
+
CREATE TABLE identity_binding (
|
|
203
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
204
|
+
agent_id TEXT NOT NULL,
|
|
205
|
+
canonical_agent_card BLOB NOT NULL
|
|
206
|
+
) STRICT;
|
|
207
|
+
CREATE TABLE post_intents (
|
|
208
|
+
author_agent_id TEXT NOT NULL,
|
|
209
|
+
post_id TEXT NOT NULL,
|
|
210
|
+
conversation_id TEXT NOT NULL,
|
|
211
|
+
membership_hash TEXT NOT NULL,
|
|
212
|
+
canonical_intent BLOB NOT NULL,
|
|
213
|
+
completed_record_hash TEXT,
|
|
214
|
+
PRIMARY KEY (author_agent_id, post_id),
|
|
215
|
+
FOREIGN KEY (conversation_id, membership_hash)
|
|
216
|
+
REFERENCES memberships(conversation_id, membership_hash)
|
|
217
|
+
) STRICT;
|
|
218
|
+
CREATE TABLE memberships (
|
|
219
|
+
conversation_id TEXT PRIMARY KEY,
|
|
220
|
+
membership_hash TEXT NOT NULL,
|
|
221
|
+
canonical_membership BLOB NOT NULL,
|
|
222
|
+
UNIQUE (conversation_id, membership_hash)
|
|
223
|
+
) STRICT;
|
|
224
|
+
CREATE TABLE anchors (
|
|
225
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
226
|
+
anchor_hash TEXT NOT NULL,
|
|
227
|
+
previous_anchor_hash TEXT,
|
|
228
|
+
selected_record_hash TEXT,
|
|
229
|
+
canonical_anchor BLOB NOT NULL,
|
|
230
|
+
PRIMARY KEY (conversation_id, anchor_hash)
|
|
231
|
+
) STRICT;
|
|
232
|
+
CREATE TABLE conversation_state (
|
|
233
|
+
conversation_id TEXT PRIMARY KEY REFERENCES memberships(conversation_id),
|
|
234
|
+
membership_hash TEXT NOT NULL,
|
|
235
|
+
current_anchor_hash TEXT NOT NULL,
|
|
236
|
+
head_record_hash TEXT,
|
|
237
|
+
head_ordinal INTEGER NOT NULL CHECK (head_ordinal >= -1),
|
|
238
|
+
FOREIGN KEY (conversation_id, current_anchor_hash)
|
|
239
|
+
REFERENCES anchors(conversation_id, anchor_hash)
|
|
240
|
+
) STRICT;
|
|
241
|
+
CREATE TABLE proposal_locks (
|
|
242
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
243
|
+
predecessor_key TEXT NOT NULL,
|
|
244
|
+
previous_record_hash TEXT,
|
|
245
|
+
action_hash TEXT NOT NULL,
|
|
246
|
+
canonical_action_core BLOB NOT NULL,
|
|
247
|
+
PRIMARY KEY (conversation_id, predecessor_key),
|
|
248
|
+
CHECK (
|
|
249
|
+
(previous_record_hash IS NULL AND predecessor_key = '') OR
|
|
250
|
+
(previous_record_hash IS NOT NULL AND predecessor_key = previous_record_hash)
|
|
251
|
+
)
|
|
252
|
+
) STRICT;
|
|
253
|
+
CREATE TABLE staged_records (
|
|
254
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
255
|
+
record_hash TEXT NOT NULL,
|
|
256
|
+
previous_record_hash TEXT,
|
|
257
|
+
membership_hash TEXT NOT NULL,
|
|
258
|
+
anchor_hash TEXT NOT NULL,
|
|
259
|
+
action_hash TEXT NOT NULL,
|
|
260
|
+
author_agent_id TEXT NOT NULL,
|
|
261
|
+
post_id TEXT NOT NULL,
|
|
262
|
+
canonical_record_core BLOB NOT NULL,
|
|
263
|
+
PRIMARY KEY (conversation_id, record_hash),
|
|
264
|
+
FOREIGN KEY (conversation_id, anchor_hash)
|
|
265
|
+
REFERENCES anchors(conversation_id, anchor_hash)
|
|
266
|
+
) STRICT;
|
|
267
|
+
CREATE TABLE protocol_evidence (
|
|
268
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
269
|
+
evidence_kind TEXT NOT NULL CHECK (
|
|
270
|
+
evidence_kind IN ('action', 'durability', 'catch-up', 'reanchor')
|
|
271
|
+
),
|
|
272
|
+
subject_id TEXT NOT NULL,
|
|
273
|
+
evidence_key TEXT NOT NULL,
|
|
274
|
+
canonical_evidence BLOB NOT NULL,
|
|
275
|
+
PRIMARY KEY (conversation_id, evidence_kind, subject_id, evidence_key)
|
|
276
|
+
) STRICT;
|
|
277
|
+
CREATE TABLE certified_records (
|
|
278
|
+
conversation_id TEXT NOT NULL,
|
|
279
|
+
record_hash TEXT NOT NULL,
|
|
280
|
+
ordinal INTEGER NOT NULL CHECK (ordinal >= 0),
|
|
281
|
+
PRIMARY KEY (conversation_id, record_hash),
|
|
282
|
+
UNIQUE (conversation_id, ordinal),
|
|
283
|
+
FOREIGN KEY (conversation_id, record_hash)
|
|
284
|
+
REFERENCES staged_records(conversation_id, record_hash)
|
|
285
|
+
) STRICT;
|
|
286
|
+
CREATE TABLE reanchors (
|
|
287
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
288
|
+
anchor_hash TEXT NOT NULL,
|
|
289
|
+
previous_anchor_hash TEXT NOT NULL,
|
|
290
|
+
router_instance_id TEXT NOT NULL,
|
|
291
|
+
selected_record_hash TEXT NOT NULL,
|
|
292
|
+
canonical_body BLOB NOT NULL,
|
|
293
|
+
canonical_completed_reanchor BLOB,
|
|
294
|
+
PRIMARY KEY (conversation_id, anchor_hash),
|
|
295
|
+
UNIQUE (conversation_id, previous_anchor_hash, router_instance_id),
|
|
296
|
+
FOREIGN KEY (conversation_id, previous_anchor_hash)
|
|
297
|
+
REFERENCES anchors(conversation_id, anchor_hash),
|
|
298
|
+
FOREIGN KEY (conversation_id, selected_record_hash)
|
|
299
|
+
REFERENCES certified_records(conversation_id, record_hash)
|
|
300
|
+
) STRICT;
|
|
301
|
+
CREATE TABLE pending_deliveries (
|
|
302
|
+
delivery_sequence INTEGER PRIMARY KEY,
|
|
303
|
+
delivery_token TEXT NOT NULL UNIQUE,
|
|
304
|
+
conversation_id TEXT NOT NULL,
|
|
305
|
+
record_hash TEXT NOT NULL,
|
|
306
|
+
recipient_agent_id TEXT NOT NULL,
|
|
307
|
+
canonical_message BLOB NOT NULL,
|
|
308
|
+
acknowledged INTEGER NOT NULL DEFAULT 0 CHECK (acknowledged IN (0, 1)),
|
|
309
|
+
UNIQUE (conversation_id, record_hash, recipient_agent_id),
|
|
310
|
+
FOREIGN KEY (conversation_id, record_hash)
|
|
311
|
+
REFERENCES certified_records(conversation_id, record_hash)
|
|
312
|
+
) STRICT;
|
|
313
|
+
CREATE TABLE outbound_messages (
|
|
314
|
+
outbound_sequence INTEGER PRIMARY KEY,
|
|
315
|
+
outbound_id TEXT NOT NULL UNIQUE,
|
|
316
|
+
conversation_id TEXT NOT NULL REFERENCES memberships(conversation_id),
|
|
317
|
+
current_message_id TEXT NOT NULL UNIQUE,
|
|
318
|
+
canonical_initial_signed_message BLOB NOT NULL,
|
|
319
|
+
canonical_current_signed_message BLOB NOT NULL,
|
|
320
|
+
attempted INTEGER NOT NULL CHECK (attempted IN (0, 1)),
|
|
321
|
+
disposition TEXT NOT NULL CHECK (
|
|
322
|
+
disposition IN ('pending', 'accepted', 'discarded')
|
|
323
|
+
)
|
|
324
|
+
) STRICT;
|
|
325
|
+
CREATE TABLE dissemination_obligations (
|
|
326
|
+
obligation_sequence INTEGER PRIMARY KEY,
|
|
327
|
+
conversation_id TEXT NOT NULL,
|
|
328
|
+
record_hash TEXT NOT NULL,
|
|
329
|
+
packet_kind TEXT NOT NULL CHECK (
|
|
330
|
+
packet_kind IN ('action-certified-record', 'certified-record')
|
|
331
|
+
),
|
|
332
|
+
outbound_id TEXT UNIQUE,
|
|
333
|
+
UNIQUE (conversation_id, record_hash, packet_kind),
|
|
334
|
+
FOREIGN KEY (conversation_id, record_hash)
|
|
335
|
+
REFERENCES staged_records(conversation_id, record_hash),
|
|
336
|
+
FOREIGN KEY (outbound_id) REFERENCES outbound_messages(outbound_id)
|
|
337
|
+
) STRICT;
|
|
338
|
+
`;
|
|
339
|
+
function initializeDatabase(database) {
|
|
340
|
+
transaction(database, () => {
|
|
341
|
+
database.exec(schemaSql);
|
|
342
|
+
database.exec(`PRAGMA user_version = ${SCHEMA_VERSION}`);
|
|
343
|
+
}, "EXCLUSIVE");
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/endpoint/store/database/schema.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,iKAAiK;AACjK,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAEL,eAAe,EACf,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AAerB,MAAM,aAAa,GAAG,kBAAkB,CAAC;AACzC,MAAM,cAAc,GAAG,CAAC,CAAC;AAIzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,cAAsB,EACyB,EAAE,CACjD,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,cAAc,CAAC;IAC/C,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC;CAC5D,CAAC,CAAC;AAEL;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAuB,EAAE,CACxE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IACf,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO;IACT,CAAC;IACD,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IAC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AAS,iBAAiB,CACxB,GAAW,EACX,QAAgB,EAChB,GAAuC;IAEvC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,GAAW,EACX,QAAgB,EAChB,GAAuC;IAEvC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyIjB,CAAC;AAEF,SAAS,kBAAkB,CAAC,QAAsB;IAChD,WAAW,CACT,QAAQ,EACR,GAAG,EAAE;QACH,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,yBAAyB,cAAc,EAAE,CAAC,CAAC;IAC3D,CAAC,EACD,WAAW,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** @file Closed store errors, canonical value checks, and row projections. */
|
|
2
|
+
/** Closed storage failures that never expose SQLite diagnostics. */
|
|
3
|
+
export type EndpointStoreFailure = "closed" | "conflict" | "corrupt" | "incompatible" | "invalid-continuation" | "invalid-input" | "not-found" | "persistence";
|
|
4
|
+
declare const EndpointStoreError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly _tag: "EndpointStoreError";
|
|
6
|
+
} & Readonly<A>;
|
|
7
|
+
/** One closed endpoint-store failure. */
|
|
8
|
+
export declare class EndpointStoreError extends EndpointStoreError_base<{
|
|
9
|
+
readonly reason: EndpointStoreFailure;
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
/** Internal control-flow signal mapped to the closed store error. */
|
|
13
|
+
export declare class StoreSignal extends Error {
|
|
14
|
+
readonly reason: EndpointStoreFailure;
|
|
15
|
+
constructor(reason: EndpointStoreFailure);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Maps every internal failure to the store's closed error channel.
|
|
19
|
+
*
|
|
20
|
+
* @param failure Internal failure or closed control-flow signal.
|
|
21
|
+
* @param fallback Closed category for unexpected implementation failures.
|
|
22
|
+
* @returns A non-diagnostic endpoint-store error.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mapStoreFailure(failure: unknown, fallback: EndpointStoreFailure): EndpointStoreError;
|
|
25
|
+
/**
|
|
26
|
+
* Validates a process-local continuation's exact external form.
|
|
27
|
+
*
|
|
28
|
+
* @param continuation Candidate unpadded base64url authority.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateContinuation(continuation: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Mints one collision-checked 32-byte volatile continuation.
|
|
33
|
+
*
|
|
34
|
+
* @param retained Existing process-local continuation keys.
|
|
35
|
+
* @returns One fresh canonical unpadded base64url value.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mintContinuation(retained: ReadonlySet<string>): string;
|
|
38
|
+
/**
|
|
39
|
+
* Mints one collision-checked durable delivery token.
|
|
40
|
+
*
|
|
41
|
+
* @param retained Existing durable token keys.
|
|
42
|
+
* @returns One fresh `dlv_` token over 32 random bytes.
|
|
43
|
+
*/
|
|
44
|
+
export declare function mintDeliveryToken(retained: ReadonlySet<string>): string;
|
|
45
|
+
/**
|
|
46
|
+
* Reads and copies one nullable SQLite BLOB.
|
|
47
|
+
*
|
|
48
|
+
* @param row SQLite result row.
|
|
49
|
+
* @param key Selected column name.
|
|
50
|
+
* @returns An isolated byte copy, or undefined for SQL NULL.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readOptionalBytes(row: Readonly<Record<string, unknown>>, key: string): Uint8Array | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Reads and copies one required SQLite BLOB.
|
|
55
|
+
*
|
|
56
|
+
* @param row SQLite result row.
|
|
57
|
+
* @param key Selected column name.
|
|
58
|
+
* @returns An isolated nonempty byte copy.
|
|
59
|
+
*/
|
|
60
|
+
export declare function readBytes(row: Readonly<Record<string, unknown>>, key: string): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Returns an isolated copy of canonical bytes.
|
|
63
|
+
*
|
|
64
|
+
* @param value Canonical bytes crossing the storage boundary.
|
|
65
|
+
* @returns A detached copy suitable for SQLite or a caller.
|
|
66
|
+
*/
|
|
67
|
+
export declare function copyBytes(value: Uint8Array): Uint8Array;
|
|
68
|
+
/**
|
|
69
|
+
* Reads one nullable nonempty SQLite TEXT.
|
|
70
|
+
*
|
|
71
|
+
* @param row SQLite result row.
|
|
72
|
+
* @param key Selected column name.
|
|
73
|
+
* @returns The exact text, or undefined for SQL NULL.
|
|
74
|
+
*/
|
|
75
|
+
export declare function readOptionalText(row: Readonly<Record<string, unknown>>, key: string): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Reads one required nonempty SQLite TEXT.
|
|
78
|
+
*
|
|
79
|
+
* @param row SQLite result row when one was selected.
|
|
80
|
+
* @param key Selected column name.
|
|
81
|
+
* @returns The exact nonempty text.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readText(row: Readonly<Record<string, unknown>>, key: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Reads one safe SQLite INTEGER.
|
|
86
|
+
*
|
|
87
|
+
* @param row SQLite result row when one was selected.
|
|
88
|
+
* @param key Selected column name.
|
|
89
|
+
* @returns The exact safe integer.
|
|
90
|
+
*/
|
|
91
|
+
export declare function readInteger(row: Readonly<Record<string, unknown>>, key: string): number;
|
|
92
|
+
/**
|
|
93
|
+
* Requires canonical byte equality for idempotent state.
|
|
94
|
+
*
|
|
95
|
+
* @param left Previously retained canonical bytes.
|
|
96
|
+
* @param right Candidate canonical bytes.
|
|
97
|
+
*/
|
|
98
|
+
export declare function requireSameBytes(left: Uint8Array, right: Uint8Array): void;
|
|
99
|
+
/**
|
|
100
|
+
* Requires two exact bindings, including optional bindings, to agree.
|
|
101
|
+
*
|
|
102
|
+
* @param left Previously retained binding.
|
|
103
|
+
* @param right Candidate binding.
|
|
104
|
+
*/
|
|
105
|
+
export declare function requireEqual<Value>(left: Value, right: Value): void;
|
|
106
|
+
/**
|
|
107
|
+
* Rejects empty and NUL-bearing values before they reach SQLite.
|
|
108
|
+
*
|
|
109
|
+
* @param value Opaque private identifier or hash.
|
|
110
|
+
*/
|
|
111
|
+
export declare function requireText(value: string): void;
|
|
112
|
+
/**
|
|
113
|
+
* Rejects empty or non-byte canonical values before persistence.
|
|
114
|
+
*
|
|
115
|
+
* @param value Canonical representation bytes.
|
|
116
|
+
*/
|
|
117
|
+
export declare function requireBytes(value: Uint8Array): void;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../../src/endpoint/store/database/values.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAK9E,oEAAoE;AACpE,MAAM,MAAM,oBAAoB,GAC5B,QAAQ,GACR,UAAU,GACV,SAAS,GACT,cAAc,GACd,sBAAsB,GACtB,eAAe,GACf,WAAW,GACX,aAAa,CAAC;;;;AAElB,yCAAyC;AACzC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B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACtC,GAAG,EAAE,MAAM,GACV,MAAM,CAMR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACtC,GAAG,EAAE,MAAM,GACV,MAAM,CAMR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAO1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAInE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAIpD"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/** @file Closed store errors, canonical value checks, and row projections. */
|
|
2
|
+
import { Data } from "effect";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
/** One closed endpoint-store failure. */
|
|
5
|
+
export class EndpointStoreError extends Data.TaggedError("EndpointStoreError") {
|
|
6
|
+
}
|
|
7
|
+
/** Internal control-flow signal mapped to the closed store error. */
|
|
8
|
+
export class StoreSignal extends Error {
|
|
9
|
+
reason;
|
|
10
|
+
constructor(reason) {
|
|
11
|
+
super(reason);
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Maps every internal failure to the store's closed error channel.
|
|
17
|
+
*
|
|
18
|
+
* @param failure Internal failure or closed control-flow signal.
|
|
19
|
+
* @param fallback Closed category for unexpected implementation failures.
|
|
20
|
+
* @returns A non-diagnostic endpoint-store error.
|
|
21
|
+
*/
|
|
22
|
+
export function mapStoreFailure(failure, fallback) {
|
|
23
|
+
return new EndpointStoreError({
|
|
24
|
+
reason: failure instanceof StoreSignal ? failure.reason : fallback,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates a process-local continuation's exact external form.
|
|
29
|
+
*
|
|
30
|
+
* @param continuation Candidate unpadded base64url authority.
|
|
31
|
+
*/
|
|
32
|
+
export function validateContinuation(continuation) {
|
|
33
|
+
if (!/^[A-Za-z0-9_-]{43}$/u.test(continuation)) {
|
|
34
|
+
throw new StoreSignal("invalid-continuation");
|
|
35
|
+
}
|
|
36
|
+
const decoded = Buffer.from(continuation, "base64url");
|
|
37
|
+
if (decoded.byteLength !== 32 ||
|
|
38
|
+
decoded.toString("base64url") !== continuation) {
|
|
39
|
+
throw new StoreSignal("invalid-continuation");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Mints one collision-checked 32-byte volatile continuation.
|
|
44
|
+
*
|
|
45
|
+
* @param retained Existing process-local continuation keys.
|
|
46
|
+
* @returns One fresh canonical unpadded base64url value.
|
|
47
|
+
*/
|
|
48
|
+
export function mintContinuation(retained) {
|
|
49
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
50
|
+
const continuation = randomBytes(32).toString("base64url");
|
|
51
|
+
if (!retained.has(continuation)) {
|
|
52
|
+
return continuation;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new StoreSignal("persistence");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Mints one collision-checked durable delivery token.
|
|
59
|
+
*
|
|
60
|
+
* @param retained Existing durable token keys.
|
|
61
|
+
* @returns One fresh `dlv_` token over 32 random bytes.
|
|
62
|
+
*/
|
|
63
|
+
export function mintDeliveryToken(retained) {
|
|
64
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
65
|
+
const deliveryToken = `dlv_${randomBytes(32).toString("base64url")}`;
|
|
66
|
+
if (!retained.has(deliveryToken)) {
|
|
67
|
+
return deliveryToken;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new StoreSignal("persistence");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads and copies one nullable SQLite BLOB.
|
|
74
|
+
*
|
|
75
|
+
* @param row SQLite result row.
|
|
76
|
+
* @param key Selected column name.
|
|
77
|
+
* @returns An isolated byte copy, or undefined for SQL NULL.
|
|
78
|
+
*/
|
|
79
|
+
export function readOptionalBytes(row, key) {
|
|
80
|
+
const value = row[key];
|
|
81
|
+
if (value === null) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return readBytes(row, key);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Reads and copies one required SQLite BLOB.
|
|
88
|
+
*
|
|
89
|
+
* @param row SQLite result row.
|
|
90
|
+
* @param key Selected column name.
|
|
91
|
+
* @returns An isolated nonempty byte copy.
|
|
92
|
+
*/
|
|
93
|
+
export function readBytes(row, key) {
|
|
94
|
+
const value = row[key];
|
|
95
|
+
if (!(value instanceof Uint8Array) || value.byteLength === 0) {
|
|
96
|
+
throw new StoreSignal("corrupt");
|
|
97
|
+
}
|
|
98
|
+
return copyBytes(value);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns an isolated copy of canonical bytes.
|
|
102
|
+
*
|
|
103
|
+
* @param value Canonical bytes crossing the storage boundary.
|
|
104
|
+
* @returns A detached copy suitable for SQLite or a caller.
|
|
105
|
+
*/
|
|
106
|
+
export function copyBytes(value) {
|
|
107
|
+
return Uint8Array.from(value);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Reads one nullable nonempty SQLite TEXT.
|
|
111
|
+
*
|
|
112
|
+
* @param row SQLite result row.
|
|
113
|
+
* @param key Selected column name.
|
|
114
|
+
* @returns The exact text, or undefined for SQL NULL.
|
|
115
|
+
*/
|
|
116
|
+
export function readOptionalText(row, key) {
|
|
117
|
+
const value = row[key];
|
|
118
|
+
if (value === null) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return readText(row, key);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reads one required nonempty SQLite TEXT.
|
|
125
|
+
*
|
|
126
|
+
* @param row SQLite result row when one was selected.
|
|
127
|
+
* @param key Selected column name.
|
|
128
|
+
* @returns The exact nonempty text.
|
|
129
|
+
*/
|
|
130
|
+
export function readText(row, key) {
|
|
131
|
+
const value = row[key];
|
|
132
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
133
|
+
throw new StoreSignal("corrupt");
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reads one safe SQLite INTEGER.
|
|
139
|
+
*
|
|
140
|
+
* @param row SQLite result row when one was selected.
|
|
141
|
+
* @param key Selected column name.
|
|
142
|
+
* @returns The exact safe integer.
|
|
143
|
+
*/
|
|
144
|
+
export function readInteger(row, key) {
|
|
145
|
+
const value = row[key];
|
|
146
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
147
|
+
throw new StoreSignal("corrupt");
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Requires canonical byte equality for idempotent state.
|
|
153
|
+
*
|
|
154
|
+
* @param left Previously retained canonical bytes.
|
|
155
|
+
* @param right Candidate canonical bytes.
|
|
156
|
+
*/
|
|
157
|
+
export function requireSameBytes(left, right) {
|
|
158
|
+
if (left.byteLength !== right.byteLength ||
|
|
159
|
+
!left.every((value, index) => value === right[index])) {
|
|
160
|
+
throw new StoreSignal("conflict");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Requires two exact bindings, including optional bindings, to agree.
|
|
165
|
+
*
|
|
166
|
+
* @param left Previously retained binding.
|
|
167
|
+
* @param right Candidate binding.
|
|
168
|
+
*/
|
|
169
|
+
export function requireEqual(left, right) {
|
|
170
|
+
if (left !== right) {
|
|
171
|
+
throw new StoreSignal("conflict");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Rejects empty and NUL-bearing values before they reach SQLite.
|
|
176
|
+
*
|
|
177
|
+
* @param value Opaque private identifier or hash.
|
|
178
|
+
*/
|
|
179
|
+
export function requireText(value) {
|
|
180
|
+
if (value.length === 0 || value.includes("\u0000")) {
|
|
181
|
+
throw new StoreSignal("invalid-input");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Rejects empty or non-byte canonical values before persistence.
|
|
186
|
+
*
|
|
187
|
+
* @param value Canonical representation bytes.
|
|
188
|
+
*/
|
|
189
|
+
export function requireBytes(value) {
|
|
190
|
+
if (!(value instanceof Uint8Array) || value.byteLength === 0) {
|
|
191
|
+
throw new StoreSignal("invalid-input");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../../../src/endpoint/store/database/values.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa1C,yCAAyC;AACzC,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAE3E;CAAG;AAEL,qEAAqE;AACrE,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,MAAM,CAAuB;IAEtC,YAAY,MAA4B;QACtC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAgB,EAChB,QAA8B;IAE9B,OAAO,IAAI,kBAAkB,CAAC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