@camstack/system 1.2.423 → 1.2.424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  2. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  3. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/alerts/alerts.addon.js +1 -1
  6. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  7. package/dist/builtins/autotrack/index.js +1 -1
  8. package/dist/builtins/autotrack/index.mjs +1 -1
  9. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  10. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  11. package/dist/builtins/calendars/calendars.addon.js +1 -1
  12. package/dist/builtins/calendars/calendars.addon.mjs +1 -1
  13. package/dist/builtins/camera-grid/index.js +1 -1
  14. package/dist/builtins/camera-grid/index.mjs +1 -1
  15. package/dist/builtins/composer/composer.addon.js +2 -2
  16. package/dist/builtins/composer/composer.addon.mjs +2 -2
  17. package/dist/builtins/console-logging/index.js +1 -1
  18. package/dist/builtins/console-logging/index.mjs +1 -1
  19. package/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
  20. package/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
  21. package/dist/builtins/device-manager/device-manager.addon.js +2 -2
  22. package/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
  23. package/dist/builtins/hub-forwarder/index.js +1 -1
  24. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  25. package/dist/builtins/keychain/index.js +3 -3
  26. package/dist/builtins/keychain/index.mjs +3 -3
  27. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  28. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  29. package/dist/builtins/local-auth/local-auth.addon.js +2 -2
  30. package/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  31. package/dist/builtins/local-network/local-network.addon.js +1 -1
  32. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  33. package/dist/builtins/loki-logging/index.js +1 -1
  34. package/dist/builtins/loki-logging/index.mjs +1 -1
  35. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  36. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  37. package/dist/builtins/platform-probe/index.js +1 -1
  38. package/dist/builtins/platform-probe/index.mjs +1 -1
  39. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  40. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  41. package/dist/builtins/snapshot/index.js +1 -1
  42. package/dist/builtins/snapshot/index.mjs +1 -1
  43. package/dist/builtins/sqlite-storage/file-host-client.d.ts +59 -0
  44. package/dist/builtins/sqlite-storage/file-host-handlers.d.ts +23 -0
  45. package/dist/builtins/sqlite-storage/file-host-protocol.d.ts +151 -0
  46. package/dist/builtins/sqlite-storage/file-host-worker.d.ts +1 -0
  47. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  48. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  49. package/dist/builtins/sqlite-storage/index.js +21 -20
  50. package/dist/builtins/sqlite-storage/index.mjs +2 -1
  51. package/dist/builtins/sqlite-storage/owned-sqlite-file.d.ts +136 -0
  52. package/dist/builtins/sqlite-storage/placement-errors.d.ts +60 -0
  53. package/dist/builtins/sqlite-storage/placement-router.d.ts +80 -0
  54. package/dist/builtins/sqlite-storage/retired-collections.d.ts +7 -0
  55. package/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +68 -8
  56. package/dist/builtins/sqlite-storage/sqlite-settings.addon.d.ts +23 -26
  57. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  58. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  59. package/dist/builtins/sqlite-storage/vector-provider.d.ts +24 -0
  60. package/dist/builtins/sqlite-storage/wal-maintenance.d.ts +17 -0
  61. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +3 -1
  62. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +3 -1
  63. package/dist/builtins/system-config/system-config.addon.js +2 -2
  64. package/dist/builtins/system-config/system-config.addon.mjs +2 -2
  65. package/dist/builtins/winston-logging/index.js +1 -1
  66. package/dist/builtins/winston-logging/index.mjs +1 -1
  67. package/dist/{composition-sources-CgiAeG-2.js → composition-sources-BWNs-ZeH.js} +1 -1
  68. package/dist/{composition-sources-BXDchWFn.mjs → composition-sources-tRG7nKWK.mjs} +1 -1
  69. package/dist/{constants-1_7QtPNo.js → constants-BBWZlnpQ.js} +1 -1
  70. package/dist/{constants-C2dhkIuF.mjs → constants-DHhhVjkt.mjs} +1 -1
  71. package/dist/{dist-DimotS8e.mjs → dist-B-NmfvVC.mjs} +94 -14
  72. package/dist/{dist-VIIxVsBW.js → dist-CiUKtVkX.js} +99 -13
  73. package/dist/file-host-worker.js +144 -0
  74. package/dist/file-host-worker.mjs +144 -0
  75. package/dist/index.js +9 -8
  76. package/dist/index.mjs +6 -5
  77. package/dist/{jwt-signing-key-C8nMdNYW.mjs → jwt-signing-key-CUpweD22.mjs} +1 -1
  78. package/dist/{jwt-signing-key-C8s9syVg.js → jwt-signing-key-nwRpRgf_.js} +1 -1
  79. package/dist/{restore-archive-bOMZwY0D.mjs → restore-archive-CFmPVlWQ.mjs} +1 -1
  80. package/dist/{restore-archive-DjppfrIB.js → restore-archive-DA-aJtg7.js} +1 -1
  81. package/dist/{retired-settings-keys-_muTvNyh.js → retired-settings-keys-D62kN_hT.js} +1 -1
  82. package/dist/{retired-settings-keys-BYnjMBE-.mjs → retired-settings-keys-DCGEI4Vi.mjs} +1 -1
  83. package/dist/sqlite-snapshot-worker.js +1 -1
  84. package/dist/sqlite-snapshot-worker.mjs +1 -1
  85. package/dist/wal-checkpoint-worker.js +1 -1
  86. package/dist/wal-checkpoint-worker.mjs +1 -1
  87. package/dist/wal-maintenance-BlqNqaQ3.mjs +0 -0
  88. package/dist/wal-maintenance-BzdCQGjH.js +0 -0
  89. package/package.json +1 -1
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The vocabulary between the engine's main thread and the thread that serves
3
+ * one database file (D851). Pure: no driver, no kernel — the worker bundle
4
+ * imports it, and so does the main thread.
5
+ *
6
+ * ## The shape
7
+ *
8
+ * A request is `{ id, kind, op, input }`; the answer is `{ id, ok: true,
9
+ * result }` or `{ id, ok: false, error }`. `kind` is `data` (the
10
+ * `data-store-provider` surface), `vector` (the `vector-store` surface) or
11
+ * `control` (what the placement router needs to ask a file that no cap
12
+ * method covers). Errors cross by NAME (`placement-errors.ts`).
13
+ *
14
+ * ## The type boundary
15
+ *
16
+ * A message is `unknown` the moment it crosses `postMessage`. `trustInput` and
17
+ * `trustResult` are the only two places the engine asserts a type it cannot
18
+ * prove: the message was built by {@link OwnedSqliteFile.call} /
19
+ * {@link OwnedSqliteFile.vector}, whose signature IS the typing. Everything
20
+ * else on either side of the boundary is typed.
21
+ */
22
+ import type { IDataStoreProvider, IVectorStoreProvider } from "@camstack/types";
23
+ import type { DataStoreDatabase, LogTags } from "@camstack/types";
24
+ import type { SerializedError } from "./placement-errors.js";
25
+ /** Every `data-store-provider` method a file serves (all but self-description). */
26
+ export type DataStoreMethods = Omit<IDataStoreProvider, "getEngineInfo">;
27
+ export type DataStoreOp = keyof DataStoreMethods;
28
+ export type DataStoreInput<K extends DataStoreOp> = Parameters<DataStoreMethods[K]>[0];
29
+ export type DataStoreOutput<K extends DataStoreOp> = Awaited<ReturnType<DataStoreMethods[K]>>;
30
+ export type VectorOp = keyof IVectorStoreProvider;
31
+ export type VectorInput<K extends VectorOp> = Parameters<IVectorStoreProvider[K]>[0];
32
+ export type VectorOutput<K extends VectorOp> = Awaited<ReturnType<IVectorStoreProvider[K]>>;
33
+ /** Questions about a file that are not cap methods. */
34
+ export interface ControlOps {
35
+ /** Does a table of this name exist in the file? */
36
+ readonly hasTable: {
37
+ readonly input: {
38
+ readonly name: string;
39
+ };
40
+ readonly output: boolean;
41
+ };
42
+ /** Drop a retired table, reporting the rows that went with it (`null`: not there). */
43
+ readonly dropRetiredTable: {
44
+ readonly input: {
45
+ readonly name: string;
46
+ };
47
+ readonly output: {
48
+ readonly rows: number;
49
+ } | null;
50
+ };
51
+ /** Which thread serves this file. */
52
+ readonly threadId: {
53
+ readonly input: Record<string, never>;
54
+ readonly output: number;
55
+ };
56
+ }
57
+ export type ControlOp = keyof ControlOps;
58
+ /** At most this many calls in flight per worker; beyond it a call is refused, never queued. */
59
+ export declare const FILE_HOST_MAX_IN_FLIGHT = 512;
60
+ /** A refusal for being busy is logged at most once per this many ms. */
61
+ export declare const FILE_HOST_BUSY_LOG_INTERVAL_MS = 6e4;
62
+ /** How one file is opened. */
63
+ export interface OwnedSqliteFileSpec {
64
+ readonly databaseId: DataStoreDatabase;
65
+ /** `<dataDir>/<file>`, absolute. */
66
+ readonly livePath: string;
67
+ /** `settings` is served on the engine's main thread; `events`, `history` each on a worker. */
68
+ readonly thread: "main" | "worker";
69
+ /** `incremental` only takes effect on a file this open CREATES. */
70
+ readonly autoVacuum: "none" | "incremental";
71
+ /** Load sqlite-vec and serve `vector` calls (`events` only). */
72
+ readonly loadVectorExtension: boolean;
73
+ }
74
+ /** `workerData` of one file-host thread. */
75
+ export interface FileHostWorkerData {
76
+ readonly kind: "file-host";
77
+ readonly spec: OwnedSqliteFileSpec;
78
+ }
79
+ export type FileHostRequest = {
80
+ readonly id: number;
81
+ readonly kind: "data";
82
+ readonly op: DataStoreOp;
83
+ readonly input: unknown;
84
+ } | {
85
+ readonly id: number;
86
+ readonly kind: "vector";
87
+ readonly op: VectorOp;
88
+ readonly input: unknown;
89
+ } | {
90
+ readonly id: number;
91
+ readonly kind: "control";
92
+ readonly op: ControlOp;
93
+ readonly input: unknown;
94
+ } | {
95
+ readonly id: number;
96
+ readonly kind: "stop";
97
+ };
98
+ export type FileHostLogLevel = "debug" | "info" | "warn" | "error";
99
+ export type FileHostMessage = {
100
+ readonly kind: "ready";
101
+ readonly declared: readonly string[];
102
+ } | {
103
+ readonly kind: "log";
104
+ readonly level: FileHostLogLevel;
105
+ readonly message: string;
106
+ readonly scope: string;
107
+ readonly tags?: LogTags;
108
+ readonly meta?: Record<string, unknown>;
109
+ } | {
110
+ readonly kind: "result";
111
+ readonly id: number;
112
+ readonly ok: true;
113
+ readonly result: unknown;
114
+ } | {
115
+ readonly kind: "result";
116
+ readonly id: number;
117
+ readonly ok: false;
118
+ readonly error: SerializedError;
119
+ } | {
120
+ readonly kind: "boot-failed";
121
+ readonly error: SerializedError;
122
+ };
123
+ export declare const DATA_STORE_OPS: readonly DataStoreOp[];
124
+ export declare const VECTOR_OPS: readonly VectorOp[];
125
+ export declare const CONTROL_OPS: readonly ControlOp[];
126
+ export declare function isDataStoreOp(op: string): op is DataStoreOp;
127
+ export declare function isVectorOp(op: string): op is VectorOp;
128
+ export declare function isControlOp(op: string): op is ControlOp;
129
+ /** Narrow an incoming worker message. */
130
+ export declare function isFileHostMessage(value: unknown): value is FileHostMessage;
131
+ /** Narrow an incoming request on the worker side. */
132
+ export declare function isFileHostRequest(value: unknown): value is FileHostRequest;
133
+ export declare function isFileHostWorkerData(value: unknown): value is FileHostWorkerData;
134
+ /**
135
+ * Type boundary (see the file header): the request was built by a typed
136
+ * `call`/`vector`, so its `input` is the op's input.
137
+ */
138
+ export declare function trustInput<T>(input: unknown): T;
139
+ /** Type boundary (see the file header): the answer was produced by the op's handler. */
140
+ export declare function trustResult<T>(result: unknown): T;
141
+ /**
142
+ * The `ArrayBuffer`s a payload carries within three levels (a typed array,
143
+ * a `Buffer`, or an array/record of them, e.g. `{ items: [{ vector }] }`) — what `postMessage` should TRANSFER
144
+ * rather than clone. A transferred buffer is detached on the sender: ownership
145
+ * passes with the message, and a caller must not reuse a buffer it sent.
146
+ *
147
+ * Only plain, non-shared `ArrayBuffer`s qualify; a view over a pooled
148
+ * `Buffer` slab is cloned instead, because transferring the slab would detach
149
+ * every other `Buffer` carved from it.
150
+ */
151
+ export declare function collectTransferables(payload: unknown): readonly ArrayBuffer[];
@@ -0,0 +1 @@
1
+ export {};
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-VIIxVsBW.js");
6
+ const require_dist = require("../../dist-CiUKtVkX.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  let node_fs_promises = require("node:fs/promises");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Fn as storageProviderCapability, cr as BaseAddon, jt as filesystemBrowseCapability } from "../../dist-DimotS8e.mjs";
1
+ import { In as storageProviderCapability, Mt as filesystemBrowseCapability, lr as BaseAddon } from "../../dist-B-NmfvVC.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { mkdir, readdir, realpath, statfs } from "node:fs/promises";
4
4
  import * as path$1 from "node:path";
@@ -4,6 +4,7 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
6
  const require_builtins_sqlite_storage_filesystem_storage_addon = require("./filesystem-storage.addon.js");
7
+ const require_wal_maintenance = require("../../wal-maintenance-BzdCQGjH.js");
7
8
  const require_builtins_sqlite_storage_sqlite_settings_addon = require("./sqlite-settings.addon.js");
8
9
  //#region src/builtins/sqlite-storage/config-store.ts
9
10
  var ConfigStore = class {
@@ -57,25 +58,25 @@ exports.DeviceStore = DeviceStore;
57
58
  exports.DeviceStore$1 = DeviceStore;
58
59
  exports.FilesystemStorageAddon = require_builtins_sqlite_storage_filesystem_storage_addon.FilesystemStorageAddon;
59
60
  exports.FilesystemStorageProvider = require_builtins_sqlite_storage_filesystem_storage_addon.FilesystemStorageProvider;
60
- exports.SQLITE_ENGINE_STORM_WALL_SHARE = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_ENGINE_STORM_WALL_SHARE;
61
- exports.SQLITE_JOURNAL_SIZE_LIMIT_BYTES = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_JOURNAL_SIZE_LIMIT_BYTES;
62
- exports.SQLITE_MMAP_CEILING_BYTES = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_MMAP_CEILING_BYTES;
63
- exports.SQLITE_MMAP_FLOOR_BYTES = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_MMAP_FLOOR_BYTES;
64
- exports.SQLITE_PAGE_CACHE_CEILING_KIB = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_PAGE_CACHE_CEILING_KIB;
65
- exports.SQLITE_PAGE_CACHE_FLOOR_KIB = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_PAGE_CACHE_FLOOR_KIB;
66
- exports.SQLITE_PROFILE_REPORT_FLOOR_MS = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_PROFILE_REPORT_FLOOR_MS;
67
- exports.SQLITE_PROFILE_REPORT_INTERVAL_MS = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_PROFILE_REPORT_INTERVAL_MS;
68
- exports.SQLITE_PROFILE_TOP_N = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_PROFILE_TOP_N;
69
- exports.SQLITE_SLOW_CALL_MS = require_builtins_sqlite_storage_sqlite_settings_addon.SQLITE_SLOW_CALL_MS;
70
- exports.SqliteOpProfiler = require_builtins_sqlite_storage_sqlite_settings_addon.SqliteOpProfiler;
61
+ exports.SQLITE_ENGINE_STORM_WALL_SHARE = require_wal_maintenance.SQLITE_ENGINE_STORM_WALL_SHARE;
62
+ exports.SQLITE_JOURNAL_SIZE_LIMIT_BYTES = require_wal_maintenance.SQLITE_JOURNAL_SIZE_LIMIT_BYTES;
63
+ exports.SQLITE_MMAP_CEILING_BYTES = require_wal_maintenance.SQLITE_MMAP_CEILING_BYTES;
64
+ exports.SQLITE_MMAP_FLOOR_BYTES = require_wal_maintenance.SQLITE_MMAP_FLOOR_BYTES;
65
+ exports.SQLITE_PAGE_CACHE_CEILING_KIB = require_wal_maintenance.SQLITE_PAGE_CACHE_CEILING_KIB;
66
+ exports.SQLITE_PAGE_CACHE_FLOOR_KIB = require_wal_maintenance.SQLITE_PAGE_CACHE_FLOOR_KIB;
67
+ exports.SQLITE_PROFILE_REPORT_FLOOR_MS = require_wal_maintenance.SQLITE_PROFILE_REPORT_FLOOR_MS;
68
+ exports.SQLITE_PROFILE_REPORT_INTERVAL_MS = require_wal_maintenance.SQLITE_PROFILE_REPORT_INTERVAL_MS;
69
+ exports.SQLITE_PROFILE_TOP_N = require_wal_maintenance.SQLITE_PROFILE_TOP_N;
70
+ exports.SQLITE_SLOW_CALL_MS = require_wal_maintenance.SQLITE_SLOW_CALL_MS;
71
+ exports.SqliteOpProfiler = require_wal_maintenance.SqliteOpProfiler;
71
72
  exports.SqliteSettingsAddon = require_builtins_sqlite_storage_sqlite_settings_addon.SqliteSettingsAddon;
72
- exports.SqliteSettingsBackend = require_builtins_sqlite_storage_sqlite_settings_addon.SqliteSettingsBackend;
73
- exports.WAL_CHECKPOINT_BUSY_TIMEOUT_MS = require_builtins_sqlite_storage_sqlite_settings_addon.WAL_CHECKPOINT_BUSY_TIMEOUT_MS;
74
- exports.WAL_HIGH_WATER_BYTES = require_builtins_sqlite_storage_sqlite_settings_addon.WAL_HIGH_WATER_BYTES;
75
- exports.WAL_IDLE_QUIET_MS = require_builtins_sqlite_storage_sqlite_settings_addon.WAL_IDLE_QUIET_MS;
76
- exports.WAL_MAINTENANCE_INTERVAL_MS = require_builtins_sqlite_storage_sqlite_settings_addon.WAL_MAINTENANCE_INTERVAL_MS;
77
- exports.WalMaintenance = require_builtins_sqlite_storage_sqlite_settings_addon.WalMaintenance;
73
+ exports.SqliteSettingsBackend = require_wal_maintenance.SqliteSettingsBackend;
74
+ exports.WAL_CHECKPOINT_BUSY_TIMEOUT_MS = require_wal_maintenance.WAL_CHECKPOINT_BUSY_TIMEOUT_MS;
75
+ exports.WAL_HIGH_WATER_BYTES = require_wal_maintenance.WAL_HIGH_WATER_BYTES;
76
+ exports.WAL_IDLE_QUIET_MS = require_wal_maintenance.WAL_IDLE_QUIET_MS;
77
+ exports.WAL_MAINTENANCE_INTERVAL_MS = require_wal_maintenance.WAL_MAINTENANCE_INTERVAL_MS;
78
+ exports.WalMaintenance = require_wal_maintenance.WalMaintenance;
78
79
  exports.default = require_builtins_sqlite_storage_filesystem_storage_addon.FilesystemStorageAddon;
79
- exports.sqliteEngineStorm = require_builtins_sqlite_storage_sqlite_settings_addon.sqliteEngineStorm;
80
- exports.sqliteMmapSizeFor = require_builtins_sqlite_storage_sqlite_settings_addon.sqliteMmapSizeFor;
81
- exports.sqlitePageCacheKibFor = require_builtins_sqlite_storage_sqlite_settings_addon.sqlitePageCacheKibFor;
80
+ exports.sqliteEngineStorm = require_wal_maintenance.sqliteEngineStorm;
81
+ exports.sqliteMmapSizeFor = require_wal_maintenance.sqliteMmapSizeFor;
82
+ exports.sqlitePageCacheKibFor = require_wal_maintenance.sqlitePageCacheKibFor;
@@ -1,5 +1,6 @@
1
1
  import { FilesystemStorageAddon, t as FilesystemStorageProvider } from "./filesystem-storage.addon.mjs";
2
- import { SqliteSettingsAddon, _ as SQLITE_PROFILE_REPORT_INTERVAL_MS, a as WalMaintenance, b as SqliteOpProfiler, c as SQLITE_JOURNAL_SIZE_LIMIT_BYTES, d as SQLITE_PAGE_CACHE_CEILING_KIB, f as SQLITE_PAGE_CACHE_FLOOR_KIB, g as SQLITE_PROFILE_REPORT_FLOOR_MS, h as SQLITE_ENGINE_STORM_WALL_SHARE, i as WAL_MAINTENANCE_INTERVAL_MS, l as SQLITE_MMAP_CEILING_BYTES, m as sqlitePageCacheKibFor, n as WAL_HIGH_WATER_BYTES, o as SqliteSettingsBackend, p as sqliteMmapSizeFor, r as WAL_IDLE_QUIET_MS, t as WAL_CHECKPOINT_BUSY_TIMEOUT_MS, u as SQLITE_MMAP_FLOOR_BYTES, v as SQLITE_PROFILE_TOP_N, x as sqliteEngineStorm, y as SQLITE_SLOW_CALL_MS } from "./sqlite-settings.addon.mjs";
2
+ import { A as SQLITE_PAGE_CACHE_CEILING_KIB, B as sqliteEngineStorm, D as SQLITE_JOURNAL_SIZE_LIMIT_BYTES, F as SQLITE_PROFILE_REPORT_FLOOR_MS, I as SQLITE_PROFILE_REPORT_INTERVAL_MS, L as SQLITE_PROFILE_TOP_N, M as sqliteMmapSizeFor, N as sqlitePageCacheKibFor, O as SQLITE_MMAP_CEILING_BYTES, P as SQLITE_ENGINE_STORM_WALL_SHARE, R as SQLITE_SLOW_CALL_MS, a as WalMaintenance, c as SqliteSettingsBackend, i as WAL_MAINTENANCE_INTERVAL_MS, j as SQLITE_PAGE_CACHE_FLOOR_KIB, k as SQLITE_MMAP_FLOOR_BYTES, n as WAL_HIGH_WATER_BYTES, r as WAL_IDLE_QUIET_MS, t as WAL_CHECKPOINT_BUSY_TIMEOUT_MS, z as SqliteOpProfiler } from "../../wal-maintenance-BlqNqaQ3.mjs";
3
+ import { SqliteSettingsAddon } from "./sqlite-settings.addon.mjs";
3
4
  //#region src/builtins/sqlite-storage/config-store.ts
4
5
  var ConfigStore = class {
5
6
  db;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * One database FILE of the `sqlite-settings` engine, with everything D447,
3
+ * D452, D679 and D693 already require per file (D851):
4
+ *
5
+ * - a serving thread — the engine's main thread for `settings`, a dedicated
6
+ * worker for `events` and `history`;
7
+ * - a WAL checkpointer, a `-shm` lock canary and the idle-gated WAL
8
+ * maintenance;
9
+ * - a verified snapshot written by the owner, never a file copy.
10
+ *
11
+ * The router (`placement-router.ts`) holds one of these per open file and
12
+ * sends each call to the file its collection lives in. Nothing outside this
13
+ * package knows a file path.
14
+ */
15
+ import type { DatabaseSnapshotResult, DataStoreDatabase, IScopedLogger } from "@camstack/types";
16
+ import { type FileHostThreadFactory } from "./file-host-client.js";
17
+ import type { DataStoreInput, DataStoreOp, DataStoreOutput, OwnedSqliteFileSpec, VectorInput, VectorOp, VectorOutput } from "./file-host-protocol.js";
18
+ import { SqliteSettingsBackend } from "./sqlite-settings-backend.js";
19
+ import type { SqliteVecVectorIndex } from "./vector-index-vec.js";
20
+ export type { OwnedSqliteFileSpec } from "./file-host-protocol.js";
21
+ /** A table a retired-collection purge dropped, and the rows that went with it. */
22
+ export interface DroppedRetiredTable {
23
+ readonly rows: number;
24
+ }
25
+ export interface OwnedSqliteFile {
26
+ readonly databaseId: DataStoreDatabase;
27
+ readonly livePath: string;
28
+ call<K extends DataStoreOp>(op: K, input: DataStoreInput<K>): Promise<DataStoreOutput<K>>;
29
+ /** `vector-store` calls; refused on a file that does not load sqlite-vec. */
30
+ vector<K extends VectorOp>(op: K, input: VectorInput<K>): Promise<VectorOutput<K>>;
31
+ /** The collections this file's own `_collection_declarations` names. */
32
+ declaredCollections(): ReadonlySet<string>;
33
+ /** Does a table of this name exist in this file (declared or not)? */
34
+ hasTable(name: string): Promise<boolean>;
35
+ dropRetiredTable(name: string): Promise<DroppedRetiredTable | null>;
36
+ /** Which thread serves this file: 0 is the engine's main thread. */
37
+ servingThreadId(): Promise<number>;
38
+ /** The owner's verified copy of this file (D693). */
39
+ snapshot(): Promise<DatabaseSnapshotResult>;
40
+ /** Checkpointer, canary, maintenance, then the connection. */
41
+ stop(): Promise<void>;
42
+ }
43
+ /** What the per-file lifecycle needs, injectable so a spec can count and substitute. */
44
+ export interface FileLifecycle {
45
+ readonly checkpointer: {
46
+ start(): void;
47
+ stop(): Promise<void>;
48
+ };
49
+ readonly canary: {
50
+ start(): void;
51
+ stop(): void;
52
+ };
53
+ readonly snapshotter: {
54
+ sweep(): Promise<unknown>;
55
+ write(): Promise<DatabaseSnapshotResult>;
56
+ };
57
+ }
58
+ export interface OwnedFileDeps {
59
+ /** The runner's logger; per-file loggers are derived from it. */
60
+ readonly logger: IScopedLogger;
61
+ /** The runner is respawned on a serving thread's death (D5/D6). Production: `process.exit(1)`. */
62
+ readonly onFatal: (reason: string) => void;
63
+ /** Runtime defaults seeded into a fresh `settings` file. */
64
+ readonly runtimeDefaults?: Record<string, unknown>;
65
+ readonly workerPath?: string;
66
+ readonly workerExecArgv?: readonly string[];
67
+ readonly threadFactory?: FileHostThreadFactory;
68
+ readonly maxInFlight?: number;
69
+ /** Replaces the real checkpointer / canary / snapshotter (specs). */
70
+ readonly lifecycle?: (spec: OwnedSqliteFileSpec, logger: (scope: string) => IScopedLogger) => FileLifecycle;
71
+ /**
72
+ * Runs once the file is open and BEFORE its lifecycle is armed — the slot
73
+ * for the boot-time purges, which must happen before anything can read.
74
+ */
75
+ readonly afterOpen?: (file: OwnedSqliteFile) => Promise<void>;
76
+ }
77
+ /** Shared by both thread flavours: the per-file lifecycle. */
78
+ declare abstract class OwnedFileBase implements OwnedSqliteFile {
79
+ protected readonly spec: OwnedSqliteFileSpec;
80
+ protected readonly deps: OwnedFileDeps;
81
+ readonly databaseId: DataStoreDatabase;
82
+ readonly livePath: string;
83
+ protected readonly log: (scope: string) => IScopedLogger;
84
+ protected lifecycle: FileLifecycle | null;
85
+ constructor(spec: OwnedSqliteFileSpec, deps: OwnedFileDeps);
86
+ abstract call<K extends DataStoreOp>(op: K, input: DataStoreInput<K>): Promise<DataStoreOutput<K>>;
87
+ abstract vector<K extends VectorOp>(op: K, input: VectorInput<K>): Promise<VectorOutput<K>>;
88
+ abstract declaredCollections(): ReadonlySet<string>;
89
+ abstract hasTable(name: string): Promise<boolean>;
90
+ abstract dropRetiredTable(name: string): Promise<DroppedRetiredTable | null>;
91
+ abstract servingThreadId(): Promise<number>;
92
+ protected abstract stopConnection(): Promise<void>;
93
+ protected abstract stopMaintenance(): void;
94
+ /**
95
+ * Arm the checkpointer, the canary and the snapshotter. Called after the
96
+ * connection is open and the boot purges have run.
97
+ */
98
+ protected armLifecycle(): Promise<void>;
99
+ snapshot(): Promise<DatabaseSnapshotResult>;
100
+ stop(): Promise<void>;
101
+ }
102
+ /** `camstack.db`: served in place on the engine's main thread. */
103
+ export declare class InlineOwnedFile extends OwnedFileBase {
104
+ readonly backend: SqliteSettingsBackend;
105
+ private declared;
106
+ private vectorIndex;
107
+ private vectorProvider;
108
+ private maintenance;
109
+ constructor(spec: OwnedSqliteFileSpec, deps: OwnedFileDeps);
110
+ open(): Promise<void>;
111
+ getVectorIndex(): SqliteVecVectorIndex | null;
112
+ call<K extends DataStoreOp>(op: K, input: DataStoreInput<K>): Promise<DataStoreOutput<K>>;
113
+ vector<K extends VectorOp>(op: K, input: VectorInput<K>): Promise<VectorOutput<K>>;
114
+ declaredCollections(): ReadonlySet<string>;
115
+ hasTable(name: string): Promise<boolean>;
116
+ dropRetiredTable(name: string): Promise<DroppedRetiredTable | null>;
117
+ servingThreadId(): Promise<number>;
118
+ protected stopMaintenance(): void;
119
+ protected stopConnection(): Promise<void>;
120
+ }
121
+ /** `events.db`, `history.db`: served by a dedicated worker thread. */
122
+ export declare class WorkerOwnedFile extends OwnedFileBase {
123
+ private readonly client;
124
+ constructor(spec: OwnedSqliteFileSpec, deps: OwnedFileDeps);
125
+ open(): Promise<void>;
126
+ call<K extends DataStoreOp>(op: K, input: DataStoreInput<K>): Promise<DataStoreOutput<K>>;
127
+ vector<K extends VectorOp>(op: K, input: VectorInput<K>): Promise<VectorOutput<K>>;
128
+ declaredCollections(): ReadonlySet<string>;
129
+ hasTable(name: string): Promise<boolean>;
130
+ dropRetiredTable(name: string): Promise<DroppedRetiredTable | null>;
131
+ servingThreadId(): Promise<number>;
132
+ protected stopMaintenance(): void;
133
+ protected stopConnection(): Promise<void>;
134
+ }
135
+ /** Open a file on the thread its spec names. */
136
+ export declare function openOwnedSqliteFile(spec: OwnedSqliteFileSpec, deps: OwnedFileDeps): Promise<InlineOwnedFile | WorkerOwnedFile>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The typed errors of the owned-file layer (D851).
3
+ *
4
+ * They cross a thread boundary by NAME: a worker serialises `{ name, message,
5
+ * code? }` and the main thread rebuilds the class with {@link rehydrateError},
6
+ * so a caller's `instanceof CollectionPlacementError` survives the hop.
7
+ */
8
+ import type { DataStoreDatabase } from "@camstack/types";
9
+ /**
10
+ * A collection was declared for one file while its table already lives in
11
+ * another. The engine never moves a table: moving is the offline split
12
+ * script's job (D853). This is the safety net that turns an accidental deploy
13
+ * to an unconverted hub into a loud failure of ONE addon instead of a silent
14
+ * empty file beside the real rows.
15
+ */
16
+ export declare class CollectionPlacementError extends Error {
17
+ readonly table: string;
18
+ readonly livesIn: DataStoreDatabase;
19
+ readonly declaredFor: DataStoreDatabase;
20
+ constructor(table: string, livesIn: DataStoreDatabase, declaredFor: DataStoreDatabase);
21
+ }
22
+ /** A collection declared in two files at boot: the layout is corrupt and is not served. */
23
+ export declare class DuplicatePlacementError extends Error {
24
+ readonly table: string;
25
+ readonly first: DataStoreDatabase;
26
+ readonly second: DataStoreDatabase;
27
+ constructor(table: string, first: DataStoreDatabase, second: DataStoreDatabase);
28
+ }
29
+ /** A `transact` whose ops resolve to more than one database file. */
30
+ export declare class CrossDatabaseTransactError extends Error {
31
+ readonly databases: readonly DataStoreDatabase[];
32
+ constructor(databases: readonly DataStoreDatabase[]);
33
+ }
34
+ /** A worker already has its in-flight bound of calls queued; the call is refused, never queued. */
35
+ export declare class DatabaseBusyError extends Error {
36
+ readonly databaseId: DataStoreDatabase;
37
+ readonly inFlight: number;
38
+ constructor(databaseId: DataStoreDatabase, inFlight: number);
39
+ }
40
+ /** An id-addressed call (get/set/update/delete/insert/upsert/guard) on a composite-keyed collection. */
41
+ export declare class CompositeKeyError extends Error {
42
+ readonly table: string;
43
+ readonly op: string;
44
+ readonly keyColumns: readonly string[];
45
+ constructor(table: string, op: string, keyColumns: readonly string[]);
46
+ }
47
+ /** The wire form of an error that crossed the worker boundary. */
48
+ export interface SerializedError {
49
+ readonly name: string;
50
+ readonly message: string;
51
+ readonly code?: string;
52
+ }
53
+ /** Flatten any thrown value for `postMessage`. */
54
+ export declare function serializeError(err: unknown): SerializedError;
55
+ /**
56
+ * Rebuild an error on the main thread. A name this module knows comes back as
57
+ * an instance of its class (`instanceof` works); anything else comes back as a
58
+ * plain Error with the name and code preserved.
59
+ */
60
+ export declare function rehydrateError(serialized: SerializedError): Error;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * PLACEMENT (D851): which database file serves a collection.
3
+ *
4
+ * The router IS the engine's `data-store-provider`: the storage orchestrator
5
+ * dispatches to one engine, and this engine fans out to the files it owns.
6
+ * The rule it enforces is small and absolute:
7
+ *
8
+ * - a collection's file is declared by its owner on `declareCollection`
9
+ * (`database`, absent = `settings`) and persisted in THAT file's own
10
+ * `_collection_declarations`;
11
+ * - at boot the router rebuilds `collection → file` from those tables, and a
12
+ * collection declared in two files is a boot ERROR naming both — a corrupt
13
+ * layout is not served;
14
+ * - a declaration for a file other than the one the table already lives in is
15
+ * REFUSED ({@link CollectionPlacementError}), never moved. Moving is the
16
+ * offline split script's job, once (D853). This is the safety net that turns
17
+ * an accidental deploy to an unconverted hub into a loud failure of ONE
18
+ * addon instead of a silent empty file beside the real rows;
19
+ * - every other op resolves its file from the map; an undeclared collection
20
+ * (the canonical KV set and its `<addonId>:<canonical>` variants) is
21
+ * `settings`;
22
+ * - a `transact` spans ONE file ({@link CrossDatabaseTransactError}).
23
+ *
24
+ * A file other than `settings` is created on the FIRST declaration that names
25
+ * it, so an installation where nothing names `events` / `history` grows no new
26
+ * file.
27
+ */
28
+ import type { DataStoreDatabase, DataStoreEngineInfo, IDataStoreProvider, IScopedLogger } from "@camstack/types";
29
+ import type { DataStoreInput, DataStoreOutput } from "./file-host-protocol.js";
30
+ import type { OwnedSqliteFile } from "./owned-sqlite-file.js";
31
+ /** Opens (creating it if needed) the file for a database id. Called at most once per id. */
32
+ export type OpenDatabaseFile = (databaseId: DataStoreDatabase) => Promise<OwnedSqliteFile>;
33
+ export interface PlacementRouterOptions {
34
+ /** Files already open at boot — `settings` always, `events` / `history` if they exist on disk. */
35
+ readonly files: readonly OwnedSqliteFile[];
36
+ /** How a not-yet-open file is created on first declaration. */
37
+ readonly open: OpenDatabaseFile;
38
+ readonly logger: IScopedLogger;
39
+ }
40
+ export declare class PlacementRouter implements IDataStoreProvider {
41
+ private readonly files;
42
+ private readonly opening;
43
+ /** `events` / `history` collections only; absence means `settings`. */
44
+ private readonly placement;
45
+ private readonly open;
46
+ private readonly logger;
47
+ constructor(options: PlacementRouterOptions);
48
+ /**
49
+ * Rebuild `collection → file` from each file's own declarations. A table
50
+ * declared in two files is refused: nothing downstream could tell which is
51
+ * the real one.
52
+ */
53
+ private rebuildPlacement;
54
+ /** The open file of an id; `settings` is always there. */
55
+ private fileOf;
56
+ /** The database a table is served from. */
57
+ databaseOf(table: string): DataStoreDatabase;
58
+ /** The files currently open, settings first. */
59
+ openFiles(): readonly OwnedSqliteFile[];
60
+ private openFile;
61
+ private route;
62
+ declareCollection(input: DataStoreInput<"declareCollection">): Promise<void>;
63
+ transact(input: DataStoreInput<"transact">): Promise<DataStoreOutput<"transact">>;
64
+ getEngineInfo(): Promise<DataStoreEngineInfo>;
65
+ get(input: DataStoreInput<"get">): Promise<DataStoreOutput<"get">>;
66
+ set(input: DataStoreInput<"set">): Promise<DataStoreOutput<"set">>;
67
+ query(input: DataStoreInput<"query">): Promise<DataStoreOutput<"query">>;
68
+ insert(input: DataStoreInput<"insert">): Promise<DataStoreOutput<"insert">>;
69
+ upsert(input: DataStoreInput<"upsert">): Promise<DataStoreOutput<"upsert">>;
70
+ insertMany(input: DataStoreInput<"insertMany">): Promise<DataStoreOutput<"insertMany">>;
71
+ upsertMany(input: DataStoreInput<"upsertMany">): Promise<DataStoreOutput<"upsertMany">>;
72
+ update(input: DataStoreInput<"update">): Promise<DataStoreOutput<"update">>;
73
+ delete(input: DataStoreInput<"delete">): Promise<DataStoreOutput<"delete">>;
74
+ deleteWhere(input: DataStoreInput<"deleteWhere">): Promise<DataStoreOutput<"deleteWhere">>;
75
+ updateWhere(input: DataStoreInput<"updateWhere">): Promise<DataStoreOutput<"updateWhere">>;
76
+ count(input: DataStoreInput<"count">): Promise<DataStoreOutput<"count">>;
77
+ aggregate(input: DataStoreInput<"aggregate">): Promise<DataStoreOutput<"aggregate">>;
78
+ histogram(input: DataStoreInput<"histogram">): Promise<DataStoreOutput<"histogram">>;
79
+ isEmpty(input: DataStoreInput<"isEmpty">): Promise<DataStoreOutput<"isEmpty">>;
80
+ }
@@ -67,6 +67,7 @@
67
67
  * here — this module drops TABLES, and deleting somebody's database file is a
68
68
  * different kind of act.
69
69
  */
70
+ import type { OwnedSqliteFile } from "./owned-sqlite-file.js";
70
71
  import type { RetiredKeyLogger } from "./retired-settings-keys.js";
71
72
  import type { DroppedTable, SqliteSettingsBackend } from "./sqlite-settings-backend.js";
72
73
  /** One retired-table declaration. */
@@ -132,6 +133,12 @@ export declare const RETIRED_COLLECTIONS: readonly RetiredCollectionSpec[];
132
133
  */
133
134
  export declare function retiredCollectionStoreOf(backend: SqliteSettingsBackend): RetiredCollectionStore;
134
135
  /**
136
+ * The same adapter over an {@link OwnedSqliteFile} — the purge runs against
137
+ * EVERY open database file (D851), and a file served by a worker answers the
138
+ * drop through its thread.
139
+ */
140
+ export declare function retiredCollectionStoreOfFile(file: OwnedSqliteFile): RetiredCollectionStore;
141
+ /**
135
142
  * Drop every retired table that is still present. Returns one entry per table
136
143
  * actually dropped — empty when the schema is already clean, which is the
137
144
  * steady state after the first boot that ran it.