@jini-ai/db 0.3.2 → 0.3.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.3.4 — 2026-10-13
2
+
3
+ - Vault SQL repo imports `@jini-ai/platform/secrets/credential-sets/contracts`; requires @jini-ai/platform >=0.5.6 (credential-sets/contracts); publish platform first.
4
+ - `@jini-ai/platform` is now an optional peer: only `./secrets-vault` loads it. Hosts using the vault list platform themselves.
5
+
6
+ ## 0.3.3 — 2026-10-12
7
+
8
+ - Vault `findDefault` restates the default group in the normalized expressions and binds `is_default` as a dialect literal, so a host's partial default index is matched (SQLite and Postgres). Raw-column filters stay; results are unchanged.
9
+
1
10
  ## 0.3.1 — 2026-10-08
2
11
 
3
12
  - Tovu clean-up release: code Tovu moved into Jini, plus the Jini clean-up (see the commit log).
package/README.md CHANGED
@@ -29,6 +29,12 @@ the tsx CommonJS bootstrap can resolve the subpaths without an active `import` c
29
29
 
30
30
  ## Import and driver isolation
31
31
 
32
+ `@jini-ai/db/secrets-vault` requires the optional `@jini-ai/platform` peer at import
33
+ time for the canonical credential validation and error contracts, plus Kysely for
34
+ SQL. Install platform explicitly when using this subpath; existing vault consumers
35
+ that relied on transitive installation must add it before upgrading. Other database
36
+ entries do not load platform.
37
+
32
38
  `kysely` is an optional peer (`^0.29.6`), imported as a value or type only under `src/kernel/`
33
39
  and `src/migrate/`. `better-sqlite3`, `pg` and `@electric-sql/pglite` are also optional peers.
34
40
  Production code never imports a driver at runtime. PGlite type imports are confined to
@@ -1,8 +1,9 @@
1
- import { type VaultBatchOp, type VaultBatchResult, type VaultDefaultQuery, type VaultSingletonQuery, type VaultMeta, type VaultOptions, type VaultQuery, type VaultRecord, type VaultRepoPort } from "@jini-ai/platform/secrets/credential-sets";
1
+ import { type VaultBatchOp, type VaultBatchResult, type VaultDefaultQuery, type VaultSingletonQuery, type VaultMeta, type VaultOptions, type VaultQuery, type VaultRecord, type VaultRepoPort } from "@jini-ai/platform/secrets/credential-sets/contracts";
2
2
  import type { StorageKernel } from "../kernel/port.js";
3
3
  /** Fixed columns consumed by the adapter; hosts own DDL, foreign keys and migration provenance.
4
4
  * A partial unique default index and label index use the same scope as VaultRepoPort.
5
- * Nullable principal/provider scope columns must be normalized in those index expressions.
5
+ * Nullable principal/provider scope columns must be normalized in those index expressions, spelled
6
+ * as findDefault spells them, and the default index's predicate is `is_default = 1` on SQLite, `= true` on Postgres.
6
7
  * Read indexes: (workspace_id,kind,owner_key,principal_id,provider,is_default), and the same
7
8
  * group prefix plus (updated_at DESC,id DESC) with binary/C ID collation for promotion.
8
9
  * Singleton reads use the lookup index's (workspace_id,kind) prefix, optionally owner/principal.
@@ -56,7 +57,10 @@ export declare class SqlSecretsVaultRepo implements VaultRepoPort {
56
57
  applyBatch({ ops }: {
57
58
  ops: readonly VaultBatchOp[];
58
59
  }, _options?: VaultOptions): Promise<VaultBatchResult[]>;
59
- /** One indexed exact-group lookup; ciphertext is loaded only for the chosen default. */
60
+ /** One indexed exact-group lookup; ciphertext is loaded only for the chosen default.
61
+ * The group is restated in the default index's normalized expressions and `is_default` is a
62
+ * literal, else neither SQLite nor a generic Postgres plan can match the partial index (host
63
+ * EXPLAIN 2026-10-12: SQLite fell back to a raw-column index, Postgres to the label index). */
60
64
  findDefault(input: VaultDefaultQuery, _options?: VaultOptions): Promise<VaultRecord | null>;
61
65
  list(input: VaultQuery, _options?: VaultOptions): Promise<VaultRecord[]>;
62
66
  put(input: {
@@ -1,5 +1,5 @@
1
1
  import { sql } from "kysely";
2
- import { assertVaultReplacement, VaultError } from "@jini-ai/platform/secrets/credential-sets";
2
+ import { assertVaultReplacement, VaultError } from "@jini-ai/platform/secrets/credential-sets/contracts";
3
3
  import { jsonSet, toBool } from "../kernel/dialect.js";
4
4
  function fromRow(row) {
5
5
  const parts = [row.sealed_key_id, row.sealed_ciphertext, row.sealed_nonce, row.sealed_alg];
@@ -86,10 +86,15 @@ export class SqlSecretsVaultRepo {
86
86
  return results;
87
87
  });
88
88
  }
89
- /** One indexed exact-group lookup; ciphertext is loaded only for the chosen default. */
89
+ /** One indexed exact-group lookup; ciphertext is loaded only for the chosen default.
90
+ * The group is restated in the default index's normalized expressions and `is_default` is a
91
+ * literal, else neither SQLite nor a generic Postgres plan can match the partial index (host
92
+ * EXPLAIN 2026-10-12: SQLite fell back to a raw-column index, Postgres to the label index). */
90
93
  async findDefault(input, _options = {}) {
91
94
  const row = await this.kernel.run(db => this.scoped({ db, input }).selectAll()
92
- .where("is_default", "=", true).limit(1).executeTakeFirst());
95
+ .where(sql `(principal_id IS NULL)`, "=", input.principalId === null).where(sql `coalesce(principal_id,'')`, "=", input.principalId ?? "")
96
+ .where(sql `(provider IS NULL)`, "=", input.provider === null).where(sql `coalesce(provider,'')`, "=", input.provider ?? "")
97
+ .where(sql `is_default = ${sql.raw(this.kernel.dialect === "sqlite" ? "1" : "true")}`).limit(1).executeTakeFirst());
93
98
  return row ? fromRow(row) : null;
94
99
  }
95
100
  async list(input, _options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/db",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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": {
@@ -192,14 +192,14 @@
192
192
  "registry": "https://registry.npmjs.org"
193
193
  },
194
194
  "dependencies": {
195
- "@jini-ai/core": "^0.4.3",
196
- "@jini-ai/platform": "^0.5.3"
195
+ "@jini-ai/core": "^0.4.4"
197
196
  },
198
197
  "peerDependencies": {
199
198
  "kysely": "^0.29.6",
200
199
  "better-sqlite3": "^13.0.0",
201
200
  "@electric-sql/pglite": "0.5.8",
202
- "pg": "^8.23.0"
201
+ "pg": "^8.23.0",
202
+ "@jini-ai/platform": "^0.5.6"
203
203
  },
204
204
  "peerDependenciesMeta": {
205
205
  "better-sqlite3": {
@@ -213,6 +213,9 @@
213
213
  },
214
214
  "kysely": {
215
215
  "optional": true
216
+ },
217
+ "@jini-ai/platform": {
218
+ "optional": true
216
219
  }
217
220
  },
218
221
  "devDependencies": {
@@ -223,7 +226,8 @@
223
226
  "better-sqlite3": "13.0.3",
224
227
  "kysely": "0.29.6",
225
228
  "pg": "8.23.0",
226
- "@jini-ai/core": "0.4.3"
229
+ "@jini-ai/platform": "0.5.6",
230
+ "@jini-ai/core": "0.4.4"
227
231
  },
228
232
  "scripts": {
229
233
  "build": "tsc -p tsconfig.build.json",