@jini-ai/db 0.7.2 → 0.7.3-next.1

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 (162) hide show
  1. package/CHANGELOG.md +1 -7
  2. package/README.md +33 -17
  3. package/dist/core/index.d.ts +1 -2
  4. package/dist/core/index.js +0 -1
  5. package/dist/core/pg-types.d.ts +4 -1
  6. package/dist/core/pg-types.js +1 -1
  7. package/dist/core/row-values.d.ts +0 -30
  8. package/dist/core/row-values.js +1 -41
  9. package/dist/data-modules/data-module.d.ts +260 -4
  10. package/dist/data-modules/data-module.js +105 -83
  11. package/dist/data-modules/disk-headroom.js +1 -1
  12. package/dist/data-modules/index.d.ts +2 -2
  13. package/dist/data-modules/index.js +2 -2
  14. package/dist/data-modules/migration-journal.js +6 -6
  15. package/dist/data-modules/migration-recovery.js +2 -2
  16. package/dist/data-modules/plugin-identity.js +5 -5
  17. package/dist/data-modules/plugin-store.d.ts +4 -4
  18. package/dist/data-modules/restore.js +5 -5
  19. package/dist/data-modules/snapshot.d.ts +1 -1
  20. package/dist/data-modules/snapshot.js +3 -3
  21. package/dist/events/change-set-repo.sql.d.ts +70 -0
  22. package/dist/events/change-set-repo.sql.js +72 -0
  23. package/dist/events/index.d.ts +4 -0
  24. package/dist/events/index.js +3 -0
  25. package/dist/events/outbox-repo.sql.d.ts +91 -0
  26. package/dist/events/outbox-repo.sql.js +108 -0
  27. package/dist/events/repo.rows.d.ts +44 -0
  28. package/dist/events/repo.rows.js +59 -0
  29. package/dist/gated-mutations/index.d.ts +3 -0
  30. package/dist/gated-mutations/index.js +2 -0
  31. package/dist/gated-mutations/repo.rows.d.ts +19 -0
  32. package/dist/gated-mutations/repo.rows.js +23 -0
  33. package/dist/gated-mutations/repo.sql.d.ts +67 -0
  34. package/dist/gated-mutations/repo.sql.js +71 -0
  35. package/dist/kernel/dialect.d.ts +53 -31
  36. package/dist/kernel/dialect.js +14 -36
  37. package/dist/kernel/index.d.ts +2 -2
  38. package/dist/kernel/index.js +1 -7
  39. package/dist/kernel/kernel-core.d.ts +7 -3
  40. package/dist/kernel/kernel-core.js +75 -66
  41. package/dist/kernel/ops.d.ts +9 -3
  42. package/dist/kernel/ops.js +2 -2
  43. package/dist/kernel/owned-transaction.d.ts +7 -7
  44. package/dist/kernel/owned-transaction.js +2 -2
  45. package/dist/kernel/pglite/driver.d.ts +2 -2
  46. package/dist/kernel/pglite/driver.js +18 -18
  47. package/dist/kernel/pglite/ops.d.ts +8 -3
  48. package/dist/kernel/pglite/ops.js +5 -5
  49. package/dist/kernel/port.d.ts +9 -76
  50. package/dist/kernel/port.js +1 -10
  51. package/dist/kernel/postgres/driver.d.ts +4 -2
  52. package/dist/kernel/postgres/driver.js +17 -17
  53. package/dist/kernel/postgres/ops.d.ts +5 -3
  54. package/dist/kernel/postgres/ops.js +3 -3
  55. package/dist/kernel/postgres/pglite-socket.d.ts +2 -2
  56. package/dist/kernel/postgres/pglite-socket.js +13 -13
  57. package/dist/kernel/schema-scope.d.ts +5 -2
  58. package/dist/kernel/schema-scope.js +1 -1
  59. package/dist/kernel/schema-shape.d.ts +7 -3
  60. package/dist/kernel/schema-shape.js +2 -2
  61. package/dist/kernel/session-lock.d.ts +6 -6
  62. package/dist/kernel/sqlite/driver.d.ts +16 -8
  63. package/dist/kernel/sqlite/driver.js +38 -38
  64. package/dist/kernel/sqlite/index.d.ts +1 -0
  65. package/dist/kernel/sqlite/index.js +1 -0
  66. package/dist/kernel/sqlite/ops.d.ts +4 -2
  67. package/dist/kernel/sqlite/ops.js +3 -3
  68. package/dist/kernel/sqlite/sqlite-only.d.ts +81 -0
  69. package/dist/kernel/sqlite/sqlite-only.js +58 -0
  70. package/dist/kernel/store-copy.d.ts +7 -7
  71. package/dist/kernel/store-copy.js +22 -14
  72. package/dist/kernel/typegen.d.ts +5 -3
  73. package/dist/kernel/typegen.js +1 -1
  74. package/dist/migrate/checksum.d.ts +3 -1
  75. package/dist/migrate/checksum.js +1 -1
  76. package/dist/migrate/index.d.ts +1 -1
  77. package/dist/migrate/legacy-ledger.d.ts +4 -4
  78. package/dist/migrate/runner.d.ts +12 -7
  79. package/dist/migrate/runner.js +7 -6
  80. package/dist/migrate/step.d.ts +3 -28
  81. package/dist/migrate/step.js +3 -3
  82. package/dist/owner-store/index.d.ts +47 -1
  83. package/dist/owner-store/index.js +28 -1
  84. package/dist/owner-store/migrations/0000_owner_store.d.ts +3 -2
  85. package/dist/owner-store/migrations/index.d.ts +1 -1
  86. package/dist/pglite/owner.d.ts +12 -4
  87. package/dist/pglite/owner.js +33 -27
  88. package/dist/pglite/socket-server.d.ts +5 -1
  89. package/dist/pglite/socket-server.js +5 -4
  90. package/dist/recovery/deep-link.d.ts +3 -3
  91. package/dist/recovery/degraded-banners.d.ts +3 -3
  92. package/dist/recovery/degraded-banners.js +3 -3
  93. package/dist/recovery/disclosure.d.ts +6 -6
  94. package/dist/recovery/disclosure.js +6 -6
  95. package/dist/recovery/evaluate-boot-migration-policy.d.ts +5 -5
  96. package/dist/recovery/evaluate-boot-migration-policy.js +5 -5
  97. package/dist/recovery/lookup-adapters.d.ts +1 -1
  98. package/dist/recovery/lookup-adapters.js +1 -1
  99. package/dist/recovery/migrate-forward-execute.d.ts +1 -1
  100. package/dist/recovery/migrate-forward-execute.js +5 -5
  101. package/dist/recovery/migrate-forward-hooks.d.ts +6 -6
  102. package/dist/recovery/migrate-forward-hooks.js +5 -5
  103. package/dist/recovery/operation-lock.d.ts +11 -11
  104. package/dist/recovery/operation-lock.js +3 -3
  105. package/dist/recovery/reconcile-interrupted-migration.d.ts +7 -7
  106. package/dist/recovery/reconcile-interrupted-migration.js +7 -7
  107. package/dist/recovery/recovery-orchestrator.d.ts +21 -21
  108. package/dist/recovery/recovery-orchestrator.js +9 -9
  109. package/dist/recovery/restore-hooks.d.ts +8 -8
  110. package/dist/recovery/restore-hooks.js +7 -7
  111. package/dist/recovery/restore-point-create.d.ts +3 -3
  112. package/dist/secrets-vault/repo.sql.d.ts +3 -3
  113. package/dist/secrets-vault/repo.sql.js +5 -4
  114. package/dist/settings/index.d.ts +3 -0
  115. package/dist/settings/index.js +2 -0
  116. package/dist/settings/repo.rows.d.ts +117 -0
  117. package/dist/settings/repo.rows.js +106 -0
  118. package/dist/settings/repo.sql.d.ts +99 -0
  119. package/dist/settings/repo.sql.js +219 -0
  120. package/dist/sqlite/checked-client.d.ts +1 -1
  121. package/dist/sqlite/checked-state.d.ts +3 -3
  122. package/dist/sqlite/db-ops.d.ts +1 -1
  123. package/dist/sqlite/db-ops.js +1 -1
  124. package/dist/sqlite/index.d.ts +1 -3
  125. package/dist/sqlite/index.js +2 -0
  126. package/dist/sqlite/inspect.d.ts +2 -2
  127. package/dist/sqlite/inspect.js +1 -1
  128. package/dist/sqlite/open.d.ts +1 -2
  129. package/dist/sqlite/stopped.d.ts +46 -0
  130. package/dist/sqlite/stopped.js +86 -0
  131. package/dist/sqlite/transaction.d.ts +2 -2
  132. package/dist/tools/database-catalog.d.ts +2 -2
  133. package/dist/tools/database-catalog.js +13 -3
  134. package/dist/tools/read-tools.js +70 -59
  135. package/dist/tools/restore-points.d.ts +1 -1
  136. package/dist/tools/transfer-tools.d.ts +0 -1
  137. package/dist/tools/transfer-tools.js +5 -4
  138. package/dist/transfer/copy-engine.js +10 -10
  139. package/dist/transfer/copy-order.d.ts +47 -0
  140. package/dist/transfer/copy-order.js +103 -0
  141. package/dist/transfer/index.d.ts +1 -0
  142. package/dist/transfer/index.js +1 -0
  143. package/dist/transfer/internal-ddl.d.ts +28 -6
  144. package/dist/transfer/internal-ddl.js +15 -15
  145. package/dist/transfer/postgres-ddl.js +6 -6
  146. package/dist/transfer/sqlite-source.d.ts +2 -3
  147. package/dist/transfer/sqlite-source.js +1 -1
  148. package/dist/verified-origin/index.d.ts +4 -0
  149. package/dist/verified-origin/index.js +3 -0
  150. package/dist/verified-origin/register.d.ts +43 -0
  151. package/dist/verified-origin/register.js +51 -0
  152. package/dist/verified-origin/repo.rows.d.ts +42 -0
  153. package/dist/verified-origin/repo.rows.js +47 -0
  154. package/dist/verified-origin/repo.sql.d.ts +67 -0
  155. package/dist/verified-origin/repo.sql.js +34 -0
  156. package/package.json +38 -11
  157. package/dist/sqlite/restore-types.d.ts +0 -46
  158. package/dist/sqlite/restore-types.js +0 -2
  159. package/dist/sqlite/sync-types.d.ts +0 -34
  160. package/dist/sqlite/sync-types.js +0 -2
  161. package/dist/sqlite/types.d.ts +0 -37
  162. package/dist/sqlite/types.js +0 -8
@@ -0,0 +1,4 @@
1
+ export { SqlOriginSettingRepo, type OriginSqlOptional, type OriginSqlRequired, type OriginTables } from "./repo.sql.js";
2
+ export { registerConfiguredOrigin, type ConfiguredOriginWriteResult } from "./register.js";
3
+ export type { OriginSettingsTable } from "./repo.rows.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { SqlOriginSettingRepo } from "./repo.sql.js";
2
+ export { registerConfiguredOrigin } from "./register.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,43 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { StorageKernel } from "@jini-ai/core/contracts/storage";
3
+ import { type VerifiedOrigin } from "@jini-ai/core/contracts/server/verified-origin";
4
+ import type { UUID } from "@jini-ai/core/primitives";
5
+ import type { OriginTables } from "./repo.sql.js";
6
+ /** What {@link registerConfiguredOriginOn} did, so the composition root can log it. */
7
+ export type ConfiguredOriginWriteResult = "inserted" | "updated" | "unchanged";
8
+ /**
9
+ * Registers the operator-declared public origin — insert-or-correct, NOT find-or-create.
10
+ *
11
+ * This is deliberately a different function with a different contract from
12
+ * {@link seedDevCapabilityOriginOn}, not a change to it. The certified idempotency test
13
+ * (`features/origin/__tests__/repo.contract.test.ts`) protects "a re-run of the boot seed can never
14
+ * clobber a real registered origin", and that assertion stands unchanged: the dev seed only refreshes its own loopback listener
15
+ * scheme and port. What this function adds is the one authority that IS allowed to correct the
16
+ * row — whoever can set this deployment's process environment (the host's secret store /
17
+ * the deploy workflow's non-secret env inputs to the hosting plugin), which is strictly more privileged than an admin-UI login and can already deploy
18
+ * arbitrary code. Without a correcting writer, production's `http://localhost:3000` row — durably
19
+ * persisted by the first production boot and immortal under find-or-create — could never be fixed without a
20
+ * hand-written migration against the live DB.
21
+ *
22
+ * WRITES THE ORIGIN COLUMNS ONLY. `redirect_allowlist_json` and `egress_allowlist_json` are left
23
+ * exactly as found. A blind full-row overwrite would silently empty both, which in production
24
+ * fail-closes every `isAllowedEgressTarget` check — a behavior change with no relationship to the
25
+ * origin it is here to fix. Pinned by that suite's "preserves both allowlists" test.
26
+ *
27
+ * The read and the write run in one kernel transaction under `lockKey` on the workspace's row, so
28
+ * two booting processes cannot both see "no row" and both insert.
29
+ *
30
+ * @param origin - Re-validated through `createVerifiedOrigin`, so the scheme/source
31
+ * invariant cannot be bypassed by a caller that hand-built the object.
32
+ * @returns which write happened, for the boot log.
33
+ * @throws {InsecureOriginSourceError} if `origin` violates the scheme/source invariant. Callers
34
+ * pass `resolveConfiguredOrigin`'s output, which can never produce that combination.
35
+ * @complexity O(1) — one indexed lookup plus at most one write.
36
+ */
37
+ export declare function registerConfiguredOrigin({ kernel, tables, workspaceId, origin }: {
38
+ kernel: StorageKernel<Kysely<unknown>, unknown>;
39
+ tables: OriginTables;
40
+ workspaceId: UUID;
41
+ origin: VerifiedOrigin;
42
+ }, _optional?: Record<string, never>): Promise<ConfiguredOriginWriteResult>;
43
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { createVerifiedOrigin } from "@jini-ai/core/contracts/server/verified-origin";
2
+ import { originColumns, sameOrigin } from "./repo.rows.js";
3
+ /**
4
+ * Registers the operator-declared public origin — insert-or-correct, NOT find-or-create.
5
+ *
6
+ * This is deliberately a different function with a different contract from
7
+ * {@link seedDevCapabilityOriginOn}, not a change to it. The certified idempotency test
8
+ * (`features/origin/__tests__/repo.contract.test.ts`) protects "a re-run of the boot seed can never
9
+ * clobber a real registered origin", and that assertion stands unchanged: the dev seed only refreshes its own loopback listener
10
+ * scheme and port. What this function adds is the one authority that IS allowed to correct the
11
+ * row — whoever can set this deployment's process environment (the host's secret store /
12
+ * the deploy workflow's non-secret env inputs to the hosting plugin), which is strictly more privileged than an admin-UI login and can already deploy
13
+ * arbitrary code. Without a correcting writer, production's `http://localhost:3000` row — durably
14
+ * persisted by the first production boot and immortal under find-or-create — could never be fixed without a
15
+ * hand-written migration against the live DB.
16
+ *
17
+ * WRITES THE ORIGIN COLUMNS ONLY. `redirect_allowlist_json` and `egress_allowlist_json` are left
18
+ * exactly as found. A blind full-row overwrite would silently empty both, which in production
19
+ * fail-closes every `isAllowedEgressTarget` check — a behavior change with no relationship to the
20
+ * origin it is here to fix. Pinned by that suite's "preserves both allowlists" test.
21
+ *
22
+ * The read and the write run in one kernel transaction under `lockKey` on the workspace's row, so
23
+ * two booting processes cannot both see "no row" and both insert.
24
+ *
25
+ * @param origin - Re-validated through `createVerifiedOrigin`, so the scheme/source
26
+ * invariant cannot be bypassed by a caller that hand-built the object.
27
+ * @returns which write happened, for the boot log.
28
+ * @throws {InsecureOriginSourceError} if `origin` violates the scheme/source invariant. Callers
29
+ * pass `resolveConfiguredOrigin`'s output, which can never produce that combination.
30
+ * @complexity O(1) — one indexed lookup plus at most one write.
31
+ */
32
+ export async function registerConfiguredOrigin({ kernel, tables, workspaceId, origin }, _optional = {}) {
33
+ const verified = createVerifiedOrigin(origin);
34
+ const view = (db) => db.withTables();
35
+ return kernel.transaction(async () => {
36
+ await kernel.lockKey(`origin_settings:${workspaceId}`);
37
+ const existing = await kernel.run((db) => view(db).selectFrom(tables.origins).selectAll().where("workspace_id", "=", workspaceId).executeTakeFirst());
38
+ if (!existing) {
39
+ await kernel.run((db) => view(db)
40
+ .insertInto(tables.origins)
41
+ .values({ workspace_id: workspaceId, ...originColumns({ origin: verified }), redirect_allowlist_json: "[]", egress_allowlist_json: "[]" })
42
+ .execute());
43
+ return "inserted";
44
+ }
45
+ if (sameOrigin({ row: existing, origin: verified }))
46
+ return "unchanged";
47
+ await kernel.run((db) => view(db).updateTable(tables.origins).set(originColumns({ origin: verified })).where("workspace_id", "=", workspaceId).execute());
48
+ return "updated";
49
+ });
50
+ }
51
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1,42 @@
1
+ import type { Generated, Selectable } from "kysely";
2
+ import { type OriginScheme, type OriginSource, type VerifiedOrigin } from "@jini-ai/core/contracts/server/verified-origin";
3
+ /** Stored column shape, copied without schema changes; the table name is host-owned (see `OriginTables`). */
4
+ export interface OriginSettingsTable {
5
+ workspace_id: string;
6
+ scheme: string;
7
+ host: string;
8
+ port: number | null;
9
+ base_path: string | null;
10
+ verified_at: string;
11
+ source: string;
12
+ redirect_allowlist_json: Generated<string>;
13
+ egress_allowlist_json: Generated<string>;
14
+ }
15
+ export type OriginRow = Selectable<OriginSettingsTable>;
16
+ export declare function toVerifiedOrigin({ row }: {
17
+ row: OriginRow;
18
+ }, _optional?: Record<string, never>): VerifiedOrigin;
19
+ /** The origin columns only — deliberately NOT the allowlist columns. See
20
+ * {@link registerConfiguredOriginOn}. */
21
+ export declare function originColumns({ origin }: {
22
+ origin: VerifiedOrigin;
23
+ }, _optional?: Record<string, never>): {
24
+ scheme: OriginScheme;
25
+ host: string;
26
+ port: number | null;
27
+ base_path: string | null;
28
+ verified_at: string;
29
+ source: OriginSource;
30
+ };
31
+ /**
32
+ * Whether the stored row already names the same origin. `verifiedAt` is excluded on purpose: it is
33
+ * a stamp, not part of the origin's identity, so including it would make every boot an UPDATE and
34
+ * churn the row forever.
35
+ *
36
+ * @complexity O(1).
37
+ */
38
+ export declare function sameOrigin({ row, origin }: {
39
+ row: OriginRow;
40
+ origin: VerifiedOrigin;
41
+ }, _optional?: Record<string, never>): boolean;
42
+ //# sourceMappingURL=repo.rows.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { createVerifiedOrigin, } from "@jini-ai/core/contracts/server/verified-origin";
2
+ export function toVerifiedOrigin({ row }, _optional = {}) {
3
+ // Built up conditionally, not `port: row.port ?? undefined` — an object literal with an
4
+ // explicit `undefined`-valued key is NOT deep-equal to one that never had the key at all
5
+ // (`assert.deepStrictEqual` is strict about this), and `VerifiedOrigin.port`/`.basePath` are
6
+ // genuinely optional fields the in-memory adapter simply omits when unset.
7
+ const candidate = {
8
+ scheme: row.scheme,
9
+ host: row.host,
10
+ verifiedAt: row.verified_at,
11
+ source: row.source,
12
+ };
13
+ if (row.port != null)
14
+ candidate.port = row.port;
15
+ if (row.base_path != null)
16
+ candidate.basePath = row.base_path;
17
+ return createVerifiedOrigin(candidate);
18
+ }
19
+ /** The origin columns only — deliberately NOT the allowlist columns. See
20
+ * {@link registerConfiguredOriginOn}. */
21
+ export function originColumns({ origin }, _optional = {}) {
22
+ return {
23
+ scheme: origin.scheme,
24
+ host: origin.host,
25
+ port: origin.port ?? null,
26
+ base_path: origin.basePath ?? null,
27
+ verified_at: origin.verifiedAt,
28
+ source: origin.source,
29
+ };
30
+ }
31
+ /**
32
+ * Whether the stored row already names the same origin. `verifiedAt` is excluded on purpose: it is
33
+ * a stamp, not part of the origin's identity, so including it would make every boot an UPDATE and
34
+ * churn the row forever.
35
+ *
36
+ * @complexity O(1).
37
+ */
38
+ export function sameOrigin({ row, origin }, _optional = {}) {
39
+ const sameAddress = row.scheme === origin.scheme &&
40
+ row.host === origin.host;
41
+ const port = origin.port ?? null;
42
+ const basePath = origin.basePath ?? null;
43
+ return (sameAddress && row.port === port &&
44
+ row.base_path === basePath &&
45
+ row.source === origin.source);
46
+ }
47
+ //# sourceMappingURL=repo.rows.js.map
@@ -0,0 +1,67 @@
1
+ import type { Kysely } from "kysely";
2
+ import type { StorageKernel } from "@jini-ai/core/contracts/storage";
3
+ import type { OriginSettingRepoPort, VerifiedOrigin } from "@jini-ai/core/contracts/server/verified-origin";
4
+ import type { UUID } from "@jini-ai/core/primitives";
5
+ /**
6
+ * @file Phase 1 — THE durable `OriginSettingRepoPort` adapter: one Kysely query body for
7
+ * every dialect (storage plan); rule-of-two "second adapter" half,
8
+ * `Jini packages/http-kit/src/verified-origin/repo.memory.ts`'s `InMemoryOriginSettingRepo` is the first.
9
+ * `sqlite/origin-repo.sqlite.ts` is the thin layer the composition root builds from the content db
10
+ * handle.
11
+ *
12
+ * Purpose:
13
+ * The workspace's verified origin and its two allowlists previously lived only in-memory in the
14
+ * real running server's composition root — worse, hardcoded fresh into the constructor's seed
15
+ * array on every boot, not even genuinely "seeded once." This adapter makes the row durable.
16
+ *
17
+ * The READ adapter is read-only by design (matches `OriginSettingRepoPort`, which declares no write
18
+ * method). Writes are two standalone boot-time functions below, not port methods — the
19
+ * rule-of-two says don't abstract before the second adapter needs it, and there is still only one
20
+ * durable adapter:
21
+ *
22
+ * 1. {@link seedDevCapabilityOriginOn} — the idempotent find-or-create dev default
23
+ * (the current loopback listener), preserving operator registrations.
24
+ * 2. {@link registerConfiguredOriginOn} — the operator-declared public origin, from
25
+ * `features/origin/configured-origin.ts`'s public-URL resolver (2026-09-18; design note:
26
+ * `ADS-memory/reports/2026-09-18-public-origin-registration-design.md`). This is what finally
27
+ * closes the "no way to register a real production origin" gap this header used to disclose as
28
+ * permanent, and it is why production's sitemap can emit absolute URLs again.
29
+ *
30
+ * Both writers are async (the kernel is), so the composition root hands the read adapter the boot
31
+ * write's promise as `after`: every read waits for it, and a boot write that failed fails the reads
32
+ * instead of letting them see a half-booted row.
33
+ *
34
+ * Still open, and still a real gap: no ADMIN route or reachability/ownership VERIFICATION flow
35
+ * exists (the original design keeps that as a v0.1 item). Registration authority today is
36
+ * "whoever can set this deployment's process environment", nothing weaker and nothing stronger.
37
+ */
38
+ /** Host-owned table name. No schema or product table default lives in the adapter. */
39
+ export interface OriginTables {
40
+ origins: string;
41
+ }
42
+ export interface OriginSqlRequired {
43
+ kernel: StorageKernel<Kysely<unknown>, unknown>;
44
+ tables: OriginTables;
45
+ }
46
+ export interface OriginSqlOptional {
47
+ /** Reads wait for it (the host's boot write); see the file header. */
48
+ after?: Promise<unknown>;
49
+ }
50
+ export declare class SqlOriginSettingRepo implements OriginSettingRepoPort {
51
+ /** @param options.after - Reads wait for it (the composition root's boot write); see the file header. */
52
+ protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
53
+ protected readonly tables: OriginTables;
54
+ private readonly after;
55
+ constructor({ kernel, tables }: OriginSqlRequired, optional?: OriginSqlOptional);
56
+ private row;
57
+ findByWorkspaceId({ workspaceId }: {
58
+ workspaceId: UUID;
59
+ }, _optional?: Record<string, never>): Promise<VerifiedOrigin | null>;
60
+ findRedirectAllowlist({ workspaceId }: {
61
+ workspaceId: UUID;
62
+ }, _optional?: Record<string, never>): Promise<string[]>;
63
+ findEgressAllowlist({ workspaceId }: {
64
+ workspaceId: UUID;
65
+ }, _optional?: Record<string, never>): Promise<string[]>;
66
+ }
67
+ //# sourceMappingURL=repo.sql.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { toVerifiedOrigin } from "./repo.rows.js";
2
+ export class SqlOriginSettingRepo {
3
+ /** @param options.after - Reads wait for it (the composition root's boot write); see the file header. */
4
+ kernel;
5
+ tables;
6
+ after;
7
+ constructor({ kernel, tables }, optional = {}) {
8
+ this.kernel = kernel;
9
+ this.tables = tables;
10
+ this.after = optional.after;
11
+ }
12
+ async row(workspaceId) {
13
+ await this.after;
14
+ return this.kernel.run((db) => db
15
+ .withTables()
16
+ .selectFrom(this.tables.origins)
17
+ .selectAll()
18
+ .where("workspace_id", "=", workspaceId)
19
+ .executeTakeFirst());
20
+ }
21
+ async findByWorkspaceId({ workspaceId }, _optional = {}) {
22
+ const row = await this.row(workspaceId);
23
+ return row ? toVerifiedOrigin({ row }) : null;
24
+ }
25
+ async findRedirectAllowlist({ workspaceId }, _optional = {}) {
26
+ const row = await this.row(workspaceId);
27
+ return row ? JSON.parse(row.redirect_allowlist_json) : [];
28
+ }
29
+ async findEgressAllowlist({ workspaceId }, _optional = {}) {
30
+ const row = await this.row(workspaceId);
31
+ return row ? JSON.parse(row.egress_allowlist_json) : [];
32
+ }
33
+ }
34
+ //# sourceMappingURL=repo.sql.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/db",
3
- "version": "0.7.2",
3
+ "version": "0.7.3-next.1",
4
4
  "description": "Database ports, connection helpers, ownership, isolated Kysely kernels and migrations. All peers are optional; drivers are injected.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -41,8 +41,7 @@
41
41
  "optionalPeers": {
42
42
  "better-sqlite3": "opt-in: sqlite storage — SQLite storage could not load better-sqlite3. Install better-sqlite3 to enable this feature, or check its installed version and native binaries.",
43
43
  "@electric-sql/pglite": "opt-in: embedded postgresql storage — Embedded PostgreSQL storage could not load @electric-sql/pglite. Install @electric-sql/pglite to enable this feature, or check its installed version and native binaries.",
44
- "pg": "opt-in: postgresql storage — PostgreSQL storage could not load pg. Install pg to enable this feature, or check its installed version and native binaries.",
45
- "@jini-ai/platform": "opt-in: platform-backed adapters; import @jini-ai/db/secrets-vault — Platform-backed adapters could not load @jini-ai/platform. Install @jini-ai/platform to enable this feature, or check its installed version and native binaries."
44
+ "pg": "opt-in: postgresql storage — PostgreSQL storage could not load pg. Install pg to enable this feature, or check its installed version and native binaries."
46
45
  }
47
46
  },
48
47
  "type": "module",
@@ -134,6 +133,26 @@
134
133
  "import": "./dist/secrets-vault/index.js",
135
134
  "default": "./dist/secrets-vault/index.js"
136
135
  },
136
+ "./settings": {
137
+ "types": "./dist/settings/index.d.ts",
138
+ "import": "./dist/settings/index.js",
139
+ "default": "./dist/settings/index.js"
140
+ },
141
+ "./events": {
142
+ "types": "./dist/events/index.d.ts",
143
+ "import": "./dist/events/index.js",
144
+ "default": "./dist/events/index.js"
145
+ },
146
+ "./gated-mutations": {
147
+ "types": "./dist/gated-mutations/index.d.ts",
148
+ "import": "./dist/gated-mutations/index.js",
149
+ "default": "./dist/gated-mutations/index.js"
150
+ },
151
+ "./verified-origin": {
152
+ "types": "./dist/verified-origin/index.d.ts",
153
+ "import": "./dist/verified-origin/index.js",
154
+ "default": "./dist/verified-origin/index.js"
155
+ },
137
156
  "./data-modules": {
138
157
  "types": "./dist/data-modules/index.d.ts",
139
158
  "import": "./dist/data-modules/index.js",
@@ -196,6 +215,18 @@
196
215
  "secrets-vault": [
197
216
  "./dist/secrets-vault/index.d.ts"
198
217
  ],
218
+ "settings": [
219
+ "./dist/settings/index.d.ts"
220
+ ],
221
+ "events": [
222
+ "./dist/events/index.d.ts"
223
+ ],
224
+ "gated-mutations": [
225
+ "./dist/gated-mutations/index.d.ts"
226
+ ],
227
+ "verified-origin": [
228
+ "./dist/verified-origin/index.d.ts"
229
+ ],
199
230
  "data-modules": [
200
231
  "./dist/data-modules/index.d.ts"
201
232
  ]
@@ -220,13 +251,12 @@
220
251
  },
221
252
  "dependencies": {
222
253
  "kysely": "^0.29.6",
223
- "@jini-ai/core": "^0.7.2"
254
+ "@jini-ai/core": "^0.7.3-next.1"
224
255
  },
225
256
  "peerDependencies": {
226
257
  "better-sqlite3": "^13.0.0",
227
258
  "@electric-sql/pglite": "0.5.8",
228
- "pg": "^8.23.0",
229
- "@jini-ai/platform": "^0.7.0"
259
+ "pg": "^8.23.0"
230
260
  },
231
261
  "devDependencies": {
232
262
  "@electric-sql/pglite": "0.5.8",
@@ -236,8 +266,8 @@
236
266
  "better-sqlite3": "13.0.3",
237
267
  "kysely": "0.29.6",
238
268
  "pg": "8.23.0",
239
- "@jini-ai/core": "0.7.2",
240
- "@jini-ai/platform": "0.7.2"
269
+ "@jini-ai/core": "0.7.3-next.1",
270
+ "@jini-ai/platform": "0.7.3-next.1"
241
271
  },
242
272
  "peerDependenciesMeta": {
243
273
  "better-sqlite3": {
@@ -248,9 +278,6 @@
248
278
  },
249
279
  "pg": {
250
280
  "optional": true
251
- },
252
- "@jini-ai/platform": {
253
- "optional": true
254
281
  }
255
282
  },
256
283
  "scripts": {
@@ -1,46 +0,0 @@
1
- /**
2
- * @file SQLite driver type surface. Types only — no runtime declarations, so this module erases
3
- * entirely at compile time.
4
- *
5
- * Nothing here references an ORM. That is the point: a type on this package's public surface must
6
- * be a plain structural shape, which crosses a
7
- * package boundary cleanly. See `open.ts`'s module doc for the measured failure that made this a
8
- * rule rather than a preference.
9
- */
10
- import type { SqliteClient } from './types.js';
11
- /**
12
- * A caller-injected hook run against `filePath` BEFORE the connection is opened.
13
- *
14
- * Dependency inversion on purpose: recovery policy (replaying a half-applied migration,
15
- * quarantining a corrupt file) is host knowledge, and a persistence package reaching up into host
16
- * feature code to fetch it would be a layer-direction violation. The hook is optional, but when
17
- * supplied it runs for every path, including `:memory:`. A host with file-only recovery must make
18
- * its hook a no-op for ephemeral connections and hermetic tests, where there is nothing to recover.
19
- */
20
- export type SqliteRecoveryHook = (required: {
21
- filePath: string;
22
- }, options?: Record<string, never>) => void;
23
- export interface OpenSqliteConnectionOptions<Connection extends SqliteClient = SqliteClient> {
24
- /** The consumer opens with its own driver copy. */
25
- readonly open: (required: {
26
- filePath: string;
27
- }, options: Record<string, never>) => Connection;
28
- /** Filesystem path, or `':memory:'` for an ephemeral connection. */
29
- readonly filePath: string;
30
- /**
31
- * Pragma statements applied immediately after open, **replacing** (not extending) the defaults.
32
- * Pass the full list you want; see `DEFAULT_PRAGMAS` for what you are replacing and why each
33
- * default is there.
34
- */
35
- readonly pragmas?: readonly string[];
36
- readonly recover?: SqliteRecoveryHook;
37
- }
38
- /**
39
- * The minimum a caller must supply for restore-point capture: the raw driver's online-backup
40
- * method and nothing else. Structurally minimal so a host can pass a real connection or a narrow
41
- * test double, and so this package never needs to name the host's ORM handle type.
42
- */
43
- export type SqliteBackupSource = {
44
- backup(destination: string): Promise<unknown>;
45
- };
46
- //# sourceMappingURL=restore-types.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=restore-types.js.map
@@ -1,34 +0,0 @@
1
- /** Structural synchronous SQLite contract for legacy CRUD; the host owns the driver. */
2
- import type { SqliteClient, SqliteOpenOptions } from './types.js';
3
- /** Prepared query preserving typed positional bindings and rows. */
4
- export interface SqliteSyncStatement<Parameters extends unknown[] = unknown[], Result = unknown> {
5
- readonly reader: boolean;
6
- run(...parameters: Parameters): {
7
- changes: number | bigint;
8
- lastInsertRowid: number | bigint;
9
- };
10
- get(...parameters: Parameters): Result | undefined;
11
- all(...parameters: Parameters): Result[];
12
- iterate(...parameters: Parameters): IterableIterator<Result>;
13
- }
14
- /** Callable transaction with the driver's explicit lock modes. */
15
- export interface SqliteSyncTransaction<Args extends unknown[], Result> {
16
- (...args: Args): Result;
17
- deferred(...args: Args): Result;
18
- immediate(...args: Args): Result;
19
- exclusive(...args: Args): Result;
20
- }
21
- /** Separate sync API; the kernel's minimal SqliteClient remains unchanged. */
22
- export interface SqliteSyncClient extends SqliteClient {
23
- readonly open: boolean;
24
- prepare<Parameters extends unknown[] | object = unknown[], Result = unknown>(source: string): Parameters extends unknown[] ? SqliteSyncStatement<Parameters, Result> : SqliteSyncStatement<[Parameters], Result>;
25
- pragma(source: string, options?: {
26
- simple?: boolean;
27
- }): unknown;
28
- transaction<Args extends unknown[], Result>(body: (...args: Args) => Result): SqliteSyncTransaction<Args, Result>;
29
- }
30
- /** Published 0.3.x alias, now structural rather than tied to a driver installation. */
31
- export type SqliteDb = SqliteSyncClient;
32
- /** Host acquisition seam, also preserving an actual driver's richer handle type. */
33
- export type SqliteSyncOpener<Connection extends SqliteSyncClient = SqliteSyncClient> = (file: string, options: SqliteOpenOptions) => Connection;
34
- //# sourceMappingURL=sync-types.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=sync-types.js.map
@@ -1,37 +0,0 @@
1
- /**
2
- * @file The slice of a better-sqlite3 connection this package uses, written structurally so the
3
- * package needs neither better-sqlite3 nor its types: a consumer's own `Database` instance satisfies
4
- * it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
5
- * and a linked dev copy of this package's) from becoming two incompatible nominal types.
6
- */
7
- /** A prepared statement, as much of one as the Kysely binding shim and the ops call. */
8
- export interface SqliteStatement {
9
- readonly reader: boolean;
10
- all(...parameters: unknown[]): unknown[];
11
- run(...parameters: unknown[]): {
12
- changes: number | bigint;
13
- lastInsertRowid: number | bigint;
14
- };
15
- iterate(...parameters: unknown[]): IterableIterator<unknown>;
16
- }
17
- /** A better-sqlite3 `Database`. */
18
- export interface SqliteClient {
19
- /** True for `:memory:` and other private in-memory databases. */
20
- readonly memory: boolean;
21
- /** The path it was opened with. */
22
- readonly name: string;
23
- readonly inTransaction: boolean;
24
- exec(source: string): unknown;
25
- prepare(source: string): SqliteStatement;
26
- pragma(source: string): unknown;
27
- backup(destinationFile: string): Promise<unknown>;
28
- close(): unknown;
29
- }
30
- /** better-sqlite3's constructor options this package passes. */
31
- export interface SqliteOpenOptions {
32
- readonly?: boolean;
33
- fileMustExist?: boolean;
34
- }
35
- /** The consumer's way to open a connection with ITS copy of better-sqlite3: `(p, o) => new Database(p, o)`. */
36
- export type SqliteOpener<Connection extends SqliteClient = SqliteClient> = (filePath: string, options: SqliteOpenOptions) => Connection;
37
- //# sourceMappingURL=types.d.ts.map
@@ -1,8 +0,0 @@
1
- /**
2
- * @file The slice of a better-sqlite3 connection this package uses, written structurally so the
3
- * package needs neither better-sqlite3 nor its types: a consumer's own `Database` instance satisfies
4
- * it as-is. Keeping the driver out of the type graph also keeps two installed copies (the consumer's
5
- * and a linked dev copy of this package's) from becoming two incompatible nominal types.
6
- */
7
- export {};
8
- //# sourceMappingURL=types.js.map