@tearleads/client-sdk 0.1.115 → 0.1.117
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/client/containerContents/documentDiscovery.js +5 -3
- package/client/containerContents/documentDiscovery.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistence.js +14 -13
- package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
- package/data/persistence/documents/internal/ensureDocumentsSchema.js +10 -12
- package/data/persistence/documents/internal/ensureDocumentsSchema.js.map +1 -1
- package/data/sqlite/schema/containerSchema.d.ts +1 -0
- package/data/sqlite/schema/containerSchema.js +8 -1
- package/data/sqlite/schema/containerSchema.js.map +1 -1
- package/data/sqlite/schema/documentAttachmentSchema.d.ts +0 -2
- package/data/sqlite/schema/documentAttachmentSchema.js +0 -4
- package/data/sqlite/schema/documentAttachmentSchema.js.map +1 -1
- package/data/sqlite/schema/index.d.ts +2 -0
- package/data/sqlite/schema/index.js +10 -1
- package/data/sqlite/schema/index.js.map +1 -1
- package/data/sqlite/schema/principalPolicySchema.js +0 -1
- package/data/sqlite/schema/principalPolicySchema.js.map +1 -1
- package/data/sqlite/schema/verifiedManifestBundleSchema.js +4 -2
- package/data/sqlite/schema/verifiedManifestBundleSchema.js.map +1 -1
- package/data/sqlite/sqlExec.d.ts +12 -0
- package/data/sqlite/sqlExec.js +47 -3
- package/data/sqlite/sqlExec.js.map +1 -1
- package/data/sqlite/sqlTableSchema.js +40 -15
- package/data/sqlite/sqlTableSchema.js.map +1 -1
- package/data/sqlite/sqlitePersistenceRuntime.js +18 -10
- package/data/sqlite/sqlitePersistenceRuntime.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +118 -0
- package/internal/api-client/ApiClient.js +4 -0
- package/internal/api-client/ApiClient.js.map +1 -1
- package/internal/api-client/index.d.ts +1 -1
- package/internal/api-client/index.js.map +1 -1
- package/internal/api-client/principalPolicyPages.d.ts +15 -1
- package/internal/api-client/principalPolicyPages.js +48 -2
- package/internal/api-client/principalPolicyPages.js.map +1 -1
- package/internal/api-client/principalPolicyRequests.d.ts +118 -1
- package/internal/api-client/principalPolicyRequests.js +4 -1
- package/internal/api-client/principalPolicyRequests.js.map +1 -1
- package/internal/validators/operation/principalPolicyPageQuery.d.ts +9 -0
- package/internal/validators/operation/principalPolicyPageQuery.js +10 -0
- package/internal/validators/operation/principalPolicyPageQuery.js.map +1 -1
- package/internal/validators/operation/principals.d.ts +37 -4
- package/internal/validators/operation/principals.js +5 -3
- package/internal/validators/operation/principals.js.map +1 -1
- package/internal/validators/response/index.d.ts +1 -1
- package/internal/validators/response/index.js +1 -1
- package/internal/validators/response/index.js.map +1 -1
- package/internal/validators/response/principalPolicyPage.d.ts +497 -1
- package/internal/validators/response/principalPolicyPage.js +18 -0
- package/internal/validators/response/principalPolicyPage.js.map +1 -1
- package/package.json +1 -1
- package/workflows/container-contents/documentLinks/index.d.ts +4 -0
- package/workflows/container-contents/documentLinks/index.js +10 -3
- package/workflows/container-contents/documentLinks/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +7 -2
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/tombstones/documentTombstoneEvidence.js +6 -5
- package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -1
- package/workflows/principals/principalPolicyHistoryReader.d.ts +6 -1
- package/workflows/principals/principalPolicyHistoryReader.js +4 -1
- package/workflows/principals/principalPolicyHistoryReader.js.map +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js +108 -59
- package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js.map +1 -1
- package/workflows/principals/runtimePolicyRecovery.js +26 -14
- package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
- package/workflows/principals/runtimePolicyWarmer.d.ts +26 -0
- package/workflows/principals/runtimePolicyWarmer.js +8 -5
- package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { drizzle } from "drizzle-orm/sqlite-proxy";
|
|
2
2
|
import { clientSQLiteSchema } from "./schema/index.js";
|
|
3
|
+
import { closeTransactionSchemaMemoScope, openTransactionSchemaMemoScope, } from "./sqlExec.js";
|
|
3
4
|
import { assertClientSQLiteCommitAllowed, beginClientSQLiteCommitGuards, captureClientSQLiteCommitGuards, clearClientSQLiteCommitGuards, rethrowClientSQLiteCommitGuardFailure, } from "./sqliteCommitGuards.js";
|
|
4
|
-
import { createExecSql,
|
|
5
|
+
import { createExecSql, resolveCanonicalExecSql, runSerializedSqlMutation, } from "./sqlSchema.js";
|
|
5
6
|
const runtimeByExecSql = new WeakMap();
|
|
6
7
|
function transactionBeginStatement(config) {
|
|
7
8
|
if (config?.behavior === "immediate")
|
|
@@ -86,19 +87,23 @@ async function runNestedSavepointScope(canonical, lockedExecSql, operation) {
|
|
|
86
87
|
transactionDepthByCanonicalExecSql.set(canonical, depth + 1);
|
|
87
88
|
const savepoint = `runtime_transaction_sp_${depth}`;
|
|
88
89
|
const discardNestedGuards = captureClientSQLiteCommitGuards(canonical);
|
|
90
|
+
openTransactionSchemaMemoScope(canonical);
|
|
91
|
+
let released = false;
|
|
89
92
|
try {
|
|
90
93
|
await lockedExecSql(`SAVEPOINT ${savepoint}`);
|
|
91
94
|
const result = await operation();
|
|
92
95
|
await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`);
|
|
96
|
+
released = true;
|
|
93
97
|
return result;
|
|
94
98
|
}
|
|
95
99
|
catch (error) {
|
|
96
100
|
await lockedExecSql(`ROLLBACK TO SAVEPOINT ${savepoint}`).then(discardNestedGuards, () => undefined);
|
|
97
101
|
await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`).catch(() => undefined);
|
|
98
|
-
resetConnectionSchemaMemo(canonical);
|
|
99
102
|
throw error;
|
|
100
103
|
}
|
|
101
104
|
finally {
|
|
105
|
+
// The savepoint's rollback undid only the schema it first ensured.
|
|
106
|
+
closeTransactionSchemaMemoScope(canonical, released);
|
|
102
107
|
transactionDepthByCanonicalExecSql.set(canonical, depth);
|
|
103
108
|
if (chains.get(depthAtEntry) === tracked) {
|
|
104
109
|
chains.delete(depthAtEntry);
|
|
@@ -142,19 +147,20 @@ function createRuntimeForExecSql(execSql) {
|
|
|
142
147
|
}
|
|
143
148
|
transactionDepthByCanonicalExecSql.set(canonical, 1);
|
|
144
149
|
beginClientSQLiteCommitGuards(canonical);
|
|
150
|
+
openTransactionSchemaMemoScope(canonical);
|
|
151
|
+
let committed = false;
|
|
145
152
|
try {
|
|
146
|
-
|
|
153
|
+
const result = await db.transaction(operation, config);
|
|
154
|
+
committed = true;
|
|
155
|
+
return result;
|
|
147
156
|
}
|
|
148
157
|
catch (error) {
|
|
149
|
-
// The rollback undid any DDL this transaction ran, but the
|
|
150
|
-
// per-connection ensure memo still claims it exists — reset it
|
|
151
|
-
// so later operations re-ensure instead of hitting missing
|
|
152
|
-
// tables.
|
|
153
|
-
resetConnectionSchemaMemo(canonical);
|
|
154
158
|
rethrowClientSQLiteCommitGuardFailure(canonical);
|
|
155
159
|
throw error;
|
|
156
160
|
}
|
|
157
161
|
finally {
|
|
162
|
+
// A rollback forgets the ensures it undid (see sqlExec).
|
|
163
|
+
closeTransactionSchemaMemoScope(canonical, committed);
|
|
158
164
|
clearClientSQLiteCommitGuards(canonical);
|
|
159
165
|
transactionDepthByCanonicalExecSql.delete(canonical);
|
|
160
166
|
}
|
|
@@ -168,12 +174,13 @@ function createRuntimeForExecSql(execSql) {
|
|
|
168
174
|
}
|
|
169
175
|
transactionDepthByCanonicalExecSql.set(canonical, 1);
|
|
170
176
|
beginClientSQLiteCommitGuards(canonical);
|
|
177
|
+
openTransactionSchemaMemoScope(canonical);
|
|
178
|
+
let committed = false;
|
|
171
179
|
try {
|
|
172
180
|
await lockedExecSql(transactionBeginStatement(config));
|
|
173
181
|
const result = await operation(db);
|
|
174
182
|
if (!canCommit()) {
|
|
175
183
|
await lockedExecSql("ROLLBACK");
|
|
176
|
-
resetConnectionSchemaMemo(canonical);
|
|
177
184
|
return { committed: false, result: null };
|
|
178
185
|
}
|
|
179
186
|
// The guard passed in THIS synchronous slice and the COMMIT is
|
|
@@ -184,15 +191,16 @@ function createRuntimeForExecSql(execSql) {
|
|
|
184
191
|
assertClientSQLiteCommitAllowed(lockedExecSql);
|
|
185
192
|
const commit = lockedExecSql("COMMIT");
|
|
186
193
|
await commit;
|
|
194
|
+
committed = true;
|
|
187
195
|
return { committed: true, result };
|
|
188
196
|
}
|
|
189
197
|
catch (error) {
|
|
190
198
|
await lockedExecSql("ROLLBACK").catch(() => undefined);
|
|
191
|
-
resetConnectionSchemaMemo(canonical);
|
|
192
199
|
rethrowClientSQLiteCommitGuardFailure(canonical);
|
|
193
200
|
throw error;
|
|
194
201
|
}
|
|
195
202
|
finally {
|
|
203
|
+
closeTransactionSchemaMemoScope(canonical, committed);
|
|
196
204
|
clearClientSQLiteCommitGuards(canonical);
|
|
197
205
|
transactionDepthByCanonicalExecSql.delete(canonical);
|
|
198
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlitePersistenceRuntime.js","sourceRoot":"","sources":["sqlitePersistenceRuntime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,qCAAqC,GACtC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EAGb,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAqDrB,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA2C,CAAC;AAEhF,SAAS,yBAAyB,CAChC,MAAiD;IAEjD,IAAI,MAAM,EAAE,QAAQ,KAAK,WAAW;QAAE,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AED,MAAM,UAAU,oCAAoC,CAClD,MAAyB;IAEzB,IAAI,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,iCAAiC,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type {\n RemoteCallback,\n SqliteRemoteDatabase,\n} from \"drizzle-orm/sqlite-proxy\";\nimport { drizzle } from \"drizzle-orm/sqlite-proxy\";\nimport { clientSQLiteSchema } from \"./schema\";\nimport {\n assertClientSQLiteCommitAllowed,\n beginClientSQLiteCommitGuards,\n captureClientSQLiteCommitGuards,\n clearClientSQLiteCommitGuards,\n rethrowClientSQLiteCommitGuardFailure,\n} from \"./sqliteCommitGuards\";\nimport {\n createExecSql,\n type ExecSql,\n type ExecSqlClientLike,\n resetConnectionSchemaMemo,\n resolveCanonicalExecSql,\n runSerializedSqlMutation,\n type SqlArrayRow,\n type SqlRowValue,\n} from \"./sqlSchema\";\n\nexport type ClientSQLiteSchema = typeof clientSQLiteSchema;\nexport type ClientSQLiteDatabase = SqliteRemoteDatabase<ClientSQLiteSchema>;\nexport type ClientSQLiteTransactionConfig = NonNullable<\n Parameters<ClientSQLiteDatabase[\"transaction\"]>[1]\n>;\n/**\n * The handle a runtime transaction callback receives: the transaction's\n * query interface WITHOUT `rollback` (throw instead — every scope maps an\n * exception to its own rollback) and WITHOUT `transaction` (nest by calling\n * `runtime.transaction` again, which scopes to a savepoint). Narrowing the\n * contract here is what lets a nested scope share the connection-backed\n * database handle safely.\n */\nexport type ClientSQLiteTransactionScope = Pick<\n ClientSQLiteDatabase,\n | \"all\"\n | \"delete\"\n | \"get\"\n | \"insert\"\n | \"query\"\n | \"run\"\n | \"select\"\n | \"selectDistinct\"\n | \"update\"\n | \"values\"\n>;\n\nexport interface ClientSQLitePersistenceRuntime {\n db: ClientSQLiteDatabase;\n execSql: ExecSql;\n runMutation<T>(\n operation: (db: ClientSQLiteDatabase) => Promise<T> | T,\n ): Promise<T>;\n transaction<T>(\n operation: (tx: ClientSQLiteTransactionScope) => Promise<T>,\n config?: ClientSQLiteTransactionConfig,\n ): Promise<T>;\n /**\n * A transaction whose commit is gated on a SYNCHRONOUS guard: the guard\n * runs and — when it passes — the COMMIT is dispatched in the same\n * synchronous slice, so no JavaScript (an identity replacement included)\n * can interleave between the decision and the commit dispatch. Resolves\n * with `committed: false` (all writes rolled back) when the guard refuses.\n */\n guardedTransaction<T>(\n operation: (tx: ClientSQLiteTransactionScope) => Promise<T>,\n canCommit: () => boolean,\n config?: ClientSQLiteTransactionConfig,\n ): Promise<{ committed: boolean; result: T | null }>;\n}\n\nconst runtimeByExecSql = new WeakMap<ExecSql, ClientSQLitePersistenceRuntime>();\n\nfunction transactionBeginStatement(\n config: ClientSQLiteTransactionConfig | undefined,\n): \"BEGIN\" | \"BEGIN EXCLUSIVE\" | \"BEGIN IMMEDIATE\" {\n if (config?.behavior === \"immediate\") return \"BEGIN IMMEDIATE\";\n if (config?.behavior === \"exclusive\") return \"BEGIN EXCLUSIVE\";\n return \"BEGIN\";\n}\n\n// One transaction depth per underlying connection (canonical executor), so a\n// runtime.transaction call made while another transaction is already open on\n// the same connection degrades to a SAVEPOINT scope instead of issuing a\n// second BEGIN. Callers inside a serialized mutation get separate runtime\n// instances per locked executor, so the depth cannot live on the runtime.\nconst transactionDepthByCanonicalExecSql = new WeakMap<ExecSql, number>();\n// Sibling nested scopes on one connection must not interleave: SQLite\n// savepoints form a stack, so releasing an earlier savepoint would also\n// release a later sibling started concurrently. Scopes serialize per\n// NESTING DEPTH — siblings share a depth and queue behind each other, while\n// a descendant runs one level deeper and must NOT wait on its own enclosing\n// scope (that wait can never resolve).\nconst nestedScopeChainsByCanonicalExecSql = new WeakMap<\n ExecSql,\n Map<number, Promise<unknown>>\n>();\nconst execSqlByClient = new WeakMap<ExecSqlClientLike, ExecSql>();\n\nfunction toSqlRowValue(value: unknown): SqlRowValue {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\") {\n return value;\n }\n\n if (typeof value === \"boolean\") {\n return value ? 1 : 0;\n }\n\n throw new Error(`Unsupported SQLite bind value: ${String(value)}`);\n}\n\nfunction createRemoteCallback(getExecSql: () => ExecSql): RemoteCallback {\n type RemoteResult = Awaited<ReturnType<RemoteCallback>>;\n\n function getRemoteResult(rows: readonly SqlArrayRow[]): RemoteResult {\n const row = rows[0];\n if (row !== undefined) {\n return { rows: row } satisfies RemoteResult;\n }\n\n // Drizzle's RemoteCallback type requires rows, but sqlite-proxy's get()\n // mapper treats an undefined rows value as \"no row found\".\n return Object.defineProperty({ rows: [] } satisfies RemoteResult, \"rows\", {\n enumerable: true,\n value: undefined,\n });\n }\n\n return async (sql, params, method) => {\n const execSql = getExecSql();\n if (sql.trim().toLowerCase() === \"commit\")\n assertClientSQLiteCommitAllowed(execSql);\n const rows = await execSql(sql, params.map(toSqlRowValue), {\n rowMode: \"array\",\n });\n\n if (method === \"get\") {\n return getRemoteResult(rows);\n }\n\n return { rows } satisfies RemoteResult;\n };\n}\n\nfunction createClientSQLiteDatabase(\n getExecSql: () => ExecSql,\n): ClientSQLiteDatabase {\n return drizzle(createRemoteCallback(getExecSql), {\n schema: clientSQLiteSchema,\n });\n}\n\n// Serialize nested savepoint scopes per connection AND depth: a sibling\n// (same depth) queues behind the previous sibling so their savepoints\n// strictly nest instead of interleaving on the shared stack, while a\n// descendant (called from inside an executing scope, so one level deeper)\n// starts on its own depth's chain and never waits on its unresolved parent.\nasync function runNestedSavepointScope<T>(\n canonical: ExecSql,\n lockedExecSql: ExecSql,\n operation: () => Promise<T>,\n): Promise<T> {\n const depthAtEntry = transactionDepthByCanonicalExecSql.get(canonical) ?? 0;\n const chains =\n nestedScopeChainsByCanonicalExecSql.get(canonical) ??\n new Map<number, Promise<unknown>>();\n nestedScopeChainsByCanonicalExecSql.set(canonical, chains);\n const previous = chains.get(depthAtEntry) ?? Promise.resolve();\n let tracked: Promise<unknown> = Promise.resolve();\n const scope = previous\n .catch(() => undefined)\n .then(async () => {\n const depth = transactionDepthByCanonicalExecSql.get(canonical) ?? 0;\n transactionDepthByCanonicalExecSql.set(canonical, depth + 1);\n const savepoint = `runtime_transaction_sp_${depth}`;\n const discardNestedGuards = captureClientSQLiteCommitGuards(canonical);\n try {\n await lockedExecSql(`SAVEPOINT ${savepoint}`);\n const result = await operation();\n await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`);\n return result;\n } catch (error: unknown) {\n await lockedExecSql(`ROLLBACK TO SAVEPOINT ${savepoint}`).then(\n discardNestedGuards,\n () => undefined,\n );\n await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`).catch(\n () => undefined,\n );\n resetConnectionSchemaMemo(canonical);\n throw error;\n } finally {\n transactionDepthByCanonicalExecSql.set(canonical, depth);\n if (chains.get(depthAtEntry) === tracked) {\n chains.delete(depthAtEntry);\n }\n }\n });\n tracked = scope.catch(() => undefined);\n chains.set(depthAtEntry, tracked);\n return scope;\n}\n\nfunction createRuntimeForExecSql(\n execSql: ExecSql,\n): ClientSQLitePersistenceRuntime {\n let activeExecSql = execSql;\n const db = createClientSQLiteDatabase(() => activeExecSql);\n\n async function withActiveExecSql<T>(\n nextExecSql: ExecSql,\n operation: () => Promise<T> | T,\n ): Promise<T> {\n const previousExecSql = activeExecSql;\n activeExecSql = nextExecSql;\n\n try {\n return await operation();\n } finally {\n activeExecSql = previousExecSql;\n }\n }\n\n const runtime: ClientSQLitePersistenceRuntime = {\n db,\n execSql,\n runMutation(operation) {\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, () => operation(db)),\n );\n },\n transaction(operation, config) {\n // A caller already inside an open transaction on this connection MUST\n // reach us through the transaction's locked executor (the runtime that\n // executor resolves to detects the open transaction below and joins it\n // as a savepoint scope). Re-entering through the canonical executor\n // queues here for full isolation — the contract every persistence\n // helper follows by passing its received locked executor down.\n const canonical = resolveCanonicalExecSql(execSql);\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, async () => {\n if ((transactionDepthByCanonicalExecSql.get(canonical) ?? 0) > 0) {\n return runNestedSavepointScope(canonical, lockedExecSql, () =>\n operation(db),\n );\n }\n\n transactionDepthByCanonicalExecSql.set(canonical, 1);\n beginClientSQLiteCommitGuards(canonical);\n try {\n return await db.transaction(operation, config);\n } catch (error: unknown) {\n // The rollback undid any DDL this transaction ran, but the\n // per-connection ensure memo still claims it exists — reset it\n // so later operations re-ensure instead of hitting missing\n // tables.\n resetConnectionSchemaMemo(canonical);\n rethrowClientSQLiteCommitGuardFailure(canonical);\n throw error;\n } finally {\n clearClientSQLiteCommitGuards(canonical);\n transactionDepthByCanonicalExecSql.delete(canonical);\n }\n }),\n );\n },\n guardedTransaction(operation, canCommit, config) {\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, async () => {\n const canonical = resolveCanonicalExecSql(execSql);\n if ((transactionDepthByCanonicalExecSql.get(canonical) ?? 0) > 0) {\n throw new Error(\n \"guardedTransaction cannot nest inside an open transaction\",\n );\n }\n\n transactionDepthByCanonicalExecSql.set(canonical, 1);\n beginClientSQLiteCommitGuards(canonical);\n try {\n await lockedExecSql(transactionBeginStatement(config));\n const result = await operation(db);\n if (!canCommit()) {\n await lockedExecSql(\"ROLLBACK\");\n resetConnectionSchemaMemo(canonical);\n return { committed: false, result: null };\n }\n // The guard passed in THIS synchronous slice and the COMMIT is\n // dispatched in the same slice: no JavaScript can run between\n // the two, so the decision cannot go stale before dispatch. (A\n // host tearing the connection down concurrently is resolved by\n // SQLite's own commit atomicity, not by anything client-side.)\n assertClientSQLiteCommitAllowed(lockedExecSql);\n const commit = lockedExecSql(\"COMMIT\");\n await commit;\n return { committed: true, result };\n } catch (error: unknown) {\n await lockedExecSql(\"ROLLBACK\").catch(() => undefined);\n resetConnectionSchemaMemo(canonical);\n rethrowClientSQLiteCommitGuardFailure(canonical);\n throw error;\n } finally {\n clearClientSQLiteCommitGuards(canonical);\n transactionDepthByCanonicalExecSql.delete(canonical);\n }\n }),\n );\n },\n };\n\n runtimeByExecSql.set(execSql, runtime);\n return runtime;\n}\n\nexport function getClientSQLitePersistenceRuntime(\n execSql: ExecSql,\n): ClientSQLitePersistenceRuntime {\n return runtimeByExecSql.get(execSql) ?? createRuntimeForExecSql(execSql);\n}\n\nexport function createClientSQLitePersistenceRuntime(\n client: ExecSqlClientLike,\n): ClientSQLitePersistenceRuntime {\n let execSql = execSqlByClient.get(client);\n if (!execSql) {\n execSql = createExecSql(client);\n execSqlByClient.set(client, execSql);\n }\n\n return getClientSQLitePersistenceRuntime(execSql);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sqlitePersistenceRuntime.js","sourceRoot":"","sources":["sqlitePersistenceRuntime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,qCAAqC,GACtC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EAGb,uBAAuB,EACvB,wBAAwB,GAGzB,MAAM,aAAa,CAAC;AAqDrB,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA2C,CAAC;AAEhF,SAAS,yBAAyB,CAChC,MAAiD;IAEjD,IAAI,MAAM,EAAE,QAAQ,KAAK,WAAW;QAAE,OAAO,iBAAiB,CAAC;IAC/D,IAAI,MAAM,EAAE,QAAQ,KAAK,WAAW;QAAE,OAAO,iBAAiB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C;IAEF,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,OAAgB;IAEhB,OAAO,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,oCAAoC,CAClD,MAAyB;IAEzB,IAAI,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,iCAAiC,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type {\n RemoteCallback,\n SqliteRemoteDatabase,\n} from \"drizzle-orm/sqlite-proxy\";\nimport { drizzle } from \"drizzle-orm/sqlite-proxy\";\nimport { clientSQLiteSchema } from \"./schema\";\nimport {\n closeTransactionSchemaMemoScope,\n openTransactionSchemaMemoScope,\n} from \"./sqlExec\";\nimport {\n assertClientSQLiteCommitAllowed,\n beginClientSQLiteCommitGuards,\n captureClientSQLiteCommitGuards,\n clearClientSQLiteCommitGuards,\n rethrowClientSQLiteCommitGuardFailure,\n} from \"./sqliteCommitGuards\";\nimport {\n createExecSql,\n type ExecSql,\n type ExecSqlClientLike,\n resolveCanonicalExecSql,\n runSerializedSqlMutation,\n type SqlArrayRow,\n type SqlRowValue,\n} from \"./sqlSchema\";\n\nexport type ClientSQLiteSchema = typeof clientSQLiteSchema;\nexport type ClientSQLiteDatabase = SqliteRemoteDatabase<ClientSQLiteSchema>;\nexport type ClientSQLiteTransactionConfig = NonNullable<\n Parameters<ClientSQLiteDatabase[\"transaction\"]>[1]\n>;\n/**\n * The handle a runtime transaction callback receives: the transaction's\n * query interface WITHOUT `rollback` (throw instead — every scope maps an\n * exception to its own rollback) and WITHOUT `transaction` (nest by calling\n * `runtime.transaction` again, which scopes to a savepoint). Narrowing the\n * contract here is what lets a nested scope share the connection-backed\n * database handle safely.\n */\nexport type ClientSQLiteTransactionScope = Pick<\n ClientSQLiteDatabase,\n | \"all\"\n | \"delete\"\n | \"get\"\n | \"insert\"\n | \"query\"\n | \"run\"\n | \"select\"\n | \"selectDistinct\"\n | \"update\"\n | \"values\"\n>;\n\nexport interface ClientSQLitePersistenceRuntime {\n db: ClientSQLiteDatabase;\n execSql: ExecSql;\n runMutation<T>(\n operation: (db: ClientSQLiteDatabase) => Promise<T> | T,\n ): Promise<T>;\n transaction<T>(\n operation: (tx: ClientSQLiteTransactionScope) => Promise<T>,\n config?: ClientSQLiteTransactionConfig,\n ): Promise<T>;\n /**\n * A transaction whose commit is gated on a SYNCHRONOUS guard: the guard\n * runs and — when it passes — the COMMIT is dispatched in the same\n * synchronous slice, so no JavaScript (an identity replacement included)\n * can interleave between the decision and the commit dispatch. Resolves\n * with `committed: false` (all writes rolled back) when the guard refuses.\n */\n guardedTransaction<T>(\n operation: (tx: ClientSQLiteTransactionScope) => Promise<T>,\n canCommit: () => boolean,\n config?: ClientSQLiteTransactionConfig,\n ): Promise<{ committed: boolean; result: T | null }>;\n}\n\nconst runtimeByExecSql = new WeakMap<ExecSql, ClientSQLitePersistenceRuntime>();\n\nfunction transactionBeginStatement(\n config: ClientSQLiteTransactionConfig | undefined,\n): \"BEGIN\" | \"BEGIN EXCLUSIVE\" | \"BEGIN IMMEDIATE\" {\n if (config?.behavior === \"immediate\") return \"BEGIN IMMEDIATE\";\n if (config?.behavior === \"exclusive\") return \"BEGIN EXCLUSIVE\";\n return \"BEGIN\";\n}\n\n// One transaction depth per underlying connection (canonical executor), so a\n// runtime.transaction call made while another transaction is already open on\n// the same connection degrades to a SAVEPOINT scope instead of issuing a\n// second BEGIN. Callers inside a serialized mutation get separate runtime\n// instances per locked executor, so the depth cannot live on the runtime.\nconst transactionDepthByCanonicalExecSql = new WeakMap<ExecSql, number>();\n// Sibling nested scopes on one connection must not interleave: SQLite\n// savepoints form a stack, so releasing an earlier savepoint would also\n// release a later sibling started concurrently. Scopes serialize per\n// NESTING DEPTH — siblings share a depth and queue behind each other, while\n// a descendant runs one level deeper and must NOT wait on its own enclosing\n// scope (that wait can never resolve).\nconst nestedScopeChainsByCanonicalExecSql = new WeakMap<\n ExecSql,\n Map<number, Promise<unknown>>\n>();\nconst execSqlByClient = new WeakMap<ExecSqlClientLike, ExecSql>();\n\nfunction toSqlRowValue(value: unknown): SqlRowValue {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\") {\n return value;\n }\n\n if (typeof value === \"boolean\") {\n return value ? 1 : 0;\n }\n\n throw new Error(`Unsupported SQLite bind value: ${String(value)}`);\n}\n\nfunction createRemoteCallback(getExecSql: () => ExecSql): RemoteCallback {\n type RemoteResult = Awaited<ReturnType<RemoteCallback>>;\n\n function getRemoteResult(rows: readonly SqlArrayRow[]): RemoteResult {\n const row = rows[0];\n if (row !== undefined) {\n return { rows: row } satisfies RemoteResult;\n }\n\n // Drizzle's RemoteCallback type requires rows, but sqlite-proxy's get()\n // mapper treats an undefined rows value as \"no row found\".\n return Object.defineProperty({ rows: [] } satisfies RemoteResult, \"rows\", {\n enumerable: true,\n value: undefined,\n });\n }\n\n return async (sql, params, method) => {\n const execSql = getExecSql();\n if (sql.trim().toLowerCase() === \"commit\")\n assertClientSQLiteCommitAllowed(execSql);\n const rows = await execSql(sql, params.map(toSqlRowValue), {\n rowMode: \"array\",\n });\n\n if (method === \"get\") {\n return getRemoteResult(rows);\n }\n\n return { rows } satisfies RemoteResult;\n };\n}\n\nfunction createClientSQLiteDatabase(\n getExecSql: () => ExecSql,\n): ClientSQLiteDatabase {\n return drizzle(createRemoteCallback(getExecSql), {\n schema: clientSQLiteSchema,\n });\n}\n\n// Serialize nested savepoint scopes per connection AND depth: a sibling\n// (same depth) queues behind the previous sibling so their savepoints\n// strictly nest instead of interleaving on the shared stack, while a\n// descendant (called from inside an executing scope, so one level deeper)\n// starts on its own depth's chain and never waits on its unresolved parent.\nasync function runNestedSavepointScope<T>(\n canonical: ExecSql,\n lockedExecSql: ExecSql,\n operation: () => Promise<T>,\n): Promise<T> {\n const depthAtEntry = transactionDepthByCanonicalExecSql.get(canonical) ?? 0;\n const chains =\n nestedScopeChainsByCanonicalExecSql.get(canonical) ??\n new Map<number, Promise<unknown>>();\n nestedScopeChainsByCanonicalExecSql.set(canonical, chains);\n const previous = chains.get(depthAtEntry) ?? Promise.resolve();\n let tracked: Promise<unknown> = Promise.resolve();\n const scope = previous\n .catch(() => undefined)\n .then(async () => {\n const depth = transactionDepthByCanonicalExecSql.get(canonical) ?? 0;\n transactionDepthByCanonicalExecSql.set(canonical, depth + 1);\n const savepoint = `runtime_transaction_sp_${depth}`;\n const discardNestedGuards = captureClientSQLiteCommitGuards(canonical);\n openTransactionSchemaMemoScope(canonical);\n let released = false;\n try {\n await lockedExecSql(`SAVEPOINT ${savepoint}`);\n const result = await operation();\n await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`);\n released = true;\n return result;\n } catch (error: unknown) {\n await lockedExecSql(`ROLLBACK TO SAVEPOINT ${savepoint}`).then(\n discardNestedGuards,\n () => undefined,\n );\n await lockedExecSql(`RELEASE SAVEPOINT ${savepoint}`).catch(\n () => undefined,\n );\n throw error;\n } finally {\n // The savepoint's rollback undid only the schema it first ensured.\n closeTransactionSchemaMemoScope(canonical, released);\n transactionDepthByCanonicalExecSql.set(canonical, depth);\n if (chains.get(depthAtEntry) === tracked) {\n chains.delete(depthAtEntry);\n }\n }\n });\n tracked = scope.catch(() => undefined);\n chains.set(depthAtEntry, tracked);\n return scope;\n}\n\nfunction createRuntimeForExecSql(\n execSql: ExecSql,\n): ClientSQLitePersistenceRuntime {\n let activeExecSql = execSql;\n const db = createClientSQLiteDatabase(() => activeExecSql);\n\n async function withActiveExecSql<T>(\n nextExecSql: ExecSql,\n operation: () => Promise<T> | T,\n ): Promise<T> {\n const previousExecSql = activeExecSql;\n activeExecSql = nextExecSql;\n\n try {\n return await operation();\n } finally {\n activeExecSql = previousExecSql;\n }\n }\n\n const runtime: ClientSQLitePersistenceRuntime = {\n db,\n execSql,\n runMutation(operation) {\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, () => operation(db)),\n );\n },\n transaction(operation, config) {\n // A caller already inside an open transaction on this connection MUST\n // reach us through the transaction's locked executor (the runtime that\n // executor resolves to detects the open transaction below and joins it\n // as a savepoint scope). Re-entering through the canonical executor\n // queues here for full isolation — the contract every persistence\n // helper follows by passing its received locked executor down.\n const canonical = resolveCanonicalExecSql(execSql);\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, async () => {\n if ((transactionDepthByCanonicalExecSql.get(canonical) ?? 0) > 0) {\n return runNestedSavepointScope(canonical, lockedExecSql, () =>\n operation(db),\n );\n }\n\n transactionDepthByCanonicalExecSql.set(canonical, 1);\n beginClientSQLiteCommitGuards(canonical);\n openTransactionSchemaMemoScope(canonical);\n let committed = false;\n try {\n const result = await db.transaction(operation, config);\n committed = true;\n return result;\n } catch (error: unknown) {\n rethrowClientSQLiteCommitGuardFailure(canonical);\n throw error;\n } finally {\n // A rollback forgets the ensures it undid (see sqlExec).\n closeTransactionSchemaMemoScope(canonical, committed);\n clearClientSQLiteCommitGuards(canonical);\n transactionDepthByCanonicalExecSql.delete(canonical);\n }\n }),\n );\n },\n guardedTransaction(operation, canCommit, config) {\n return runSerializedSqlMutation(execSql, async (lockedExecSql) =>\n withActiveExecSql(lockedExecSql, async () => {\n const canonical = resolveCanonicalExecSql(execSql);\n if ((transactionDepthByCanonicalExecSql.get(canonical) ?? 0) > 0) {\n throw new Error(\n \"guardedTransaction cannot nest inside an open transaction\",\n );\n }\n\n transactionDepthByCanonicalExecSql.set(canonical, 1);\n beginClientSQLiteCommitGuards(canonical);\n openTransactionSchemaMemoScope(canonical);\n let committed = false;\n try {\n await lockedExecSql(transactionBeginStatement(config));\n const result = await operation(db);\n if (!canCommit()) {\n await lockedExecSql(\"ROLLBACK\");\n return { committed: false, result: null };\n }\n // The guard passed in THIS synchronous slice and the COMMIT is\n // dispatched in the same slice: no JavaScript can run between\n // the two, so the decision cannot go stale before dispatch. (A\n // host tearing the connection down concurrently is resolved by\n // SQLite's own commit atomicity, not by anything client-side.)\n assertClientSQLiteCommitAllowed(lockedExecSql);\n const commit = lockedExecSql(\"COMMIT\");\n await commit;\n committed = true;\n return { committed: true, result };\n } catch (error: unknown) {\n await lockedExecSql(\"ROLLBACK\").catch(() => undefined);\n rethrowClientSQLiteCommitGuardFailure(canonical);\n throw error;\n } finally {\n closeTransactionSchemaMemoScope(canonical, committed);\n clearClientSQLiteCommitGuards(canonical);\n transactionDepthByCanonicalExecSql.delete(canonical);\n }\n }),\n );\n },\n };\n\n runtimeByExecSql.set(execSql, runtime);\n return runtime;\n}\n\nexport function getClientSQLitePersistenceRuntime(\n execSql: ExecSql,\n): ClientSQLitePersistenceRuntime {\n return runtimeByExecSql.get(execSql) ?? createRuntimeForExecSql(execSql);\n}\n\nexport function createClientSQLitePersistenceRuntime(\n client: ExecSqlClientLike,\n): ClientSQLitePersistenceRuntime {\n let execSql = execSqlByClient.get(client);\n if (!execSql) {\n execSql = createExecSql(client);\n execSqlByClient.set(client, execSql);\n }\n\n return getClientSQLitePersistenceRuntime(execSql);\n}\n"]}
|
|
@@ -1134,6 +1134,124 @@ export declare class ApiClient {
|
|
|
1134
1134
|
version: number;
|
|
1135
1135
|
};
|
|
1136
1136
|
}>, void, any>;
|
|
1137
|
+
/** Unpinned discovery; `ifHead` asks for a bare head when it is still live. */
|
|
1138
|
+
getPrincipalPolicyDiscovery(...args: Parameters<PrincipalPolicyRequests["discover"]>): Promise<RequestResult<{
|
|
1139
|
+
previousStates: {
|
|
1140
|
+
grants: {
|
|
1141
|
+
accessLevel: "admin" | "read" | "write";
|
|
1142
|
+
containerId: string;
|
|
1143
|
+
}[];
|
|
1144
|
+
projection: {
|
|
1145
|
+
role: "member" | "admin";
|
|
1146
|
+
userId: string;
|
|
1147
|
+
}[];
|
|
1148
|
+
state: {
|
|
1149
|
+
createdAt: string;
|
|
1150
|
+
encapsulationPublicKey: string;
|
|
1151
|
+
externalAuthority: {
|
|
1152
|
+
keyEpoch: number;
|
|
1153
|
+
keyFingerprint: string;
|
|
1154
|
+
principalId: string;
|
|
1155
|
+
principalType: "group";
|
|
1156
|
+
stateHash: string;
|
|
1157
|
+
version: number;
|
|
1158
|
+
} | null;
|
|
1159
|
+
grantCount: number;
|
|
1160
|
+
grantRoot: string;
|
|
1161
|
+
keyEpoch: number;
|
|
1162
|
+
keyFingerprint: string;
|
|
1163
|
+
memberCount: number;
|
|
1164
|
+
memberEnvelopesRoot: string;
|
|
1165
|
+
membershipMode: "projection";
|
|
1166
|
+
membershipRoot: string;
|
|
1167
|
+
payloadCiphertextHash: string;
|
|
1168
|
+
prevStateHash: string | null;
|
|
1169
|
+
principalId: string;
|
|
1170
|
+
principalType: "group" | "organization";
|
|
1171
|
+
projectionRoot: string;
|
|
1172
|
+
signature: string;
|
|
1173
|
+
signedAt: string;
|
|
1174
|
+
signerUserId: string;
|
|
1175
|
+
signerUserKeyFingerprint: string;
|
|
1176
|
+
stateHash: string;
|
|
1177
|
+
version: number;
|
|
1178
|
+
};
|
|
1179
|
+
}[];
|
|
1180
|
+
historyPage: {
|
|
1181
|
+
afterVersion: number;
|
|
1182
|
+
nextAfterVersion: number | null;
|
|
1183
|
+
};
|
|
1184
|
+
currentGrants: {
|
|
1185
|
+
accessLevel: "admin" | "read" | "write";
|
|
1186
|
+
containerId: string;
|
|
1187
|
+
}[];
|
|
1188
|
+
currentMemberEnvelopes: {
|
|
1189
|
+
envelopes: {
|
|
1190
|
+
kemCipherText: string;
|
|
1191
|
+
memberKeyFingerprint: string;
|
|
1192
|
+
userId: string;
|
|
1193
|
+
wrappedKey: string;
|
|
1194
|
+
}[];
|
|
1195
|
+
epoch: number;
|
|
1196
|
+
principalId: string;
|
|
1197
|
+
principalType: "group" | "organization";
|
|
1198
|
+
stateHash: string;
|
|
1199
|
+
};
|
|
1200
|
+
currentPayload: {
|
|
1201
|
+
cipherSuite: "aes-256-gcm";
|
|
1202
|
+
ciphertext: string;
|
|
1203
|
+
ciphertextHash: string;
|
|
1204
|
+
createdAt: string;
|
|
1205
|
+
principalId: string;
|
|
1206
|
+
principalType: "group" | "organization";
|
|
1207
|
+
stateHash: string;
|
|
1208
|
+
};
|
|
1209
|
+
currentProjection: {
|
|
1210
|
+
role: "member" | "admin";
|
|
1211
|
+
userId: string;
|
|
1212
|
+
}[];
|
|
1213
|
+
currentState: {
|
|
1214
|
+
createdAt: string;
|
|
1215
|
+
encapsulationPublicKey: string;
|
|
1216
|
+
externalAuthority: {
|
|
1217
|
+
keyEpoch: number;
|
|
1218
|
+
keyFingerprint: string;
|
|
1219
|
+
principalId: string;
|
|
1220
|
+
principalType: "group";
|
|
1221
|
+
stateHash: string;
|
|
1222
|
+
version: number;
|
|
1223
|
+
} | null;
|
|
1224
|
+
grantCount: number;
|
|
1225
|
+
grantRoot: string;
|
|
1226
|
+
keyEpoch: number;
|
|
1227
|
+
keyFingerprint: string;
|
|
1228
|
+
memberCount: number;
|
|
1229
|
+
memberEnvelopesRoot: string;
|
|
1230
|
+
membershipMode: "projection";
|
|
1231
|
+
membershipRoot: string;
|
|
1232
|
+
payloadCiphertextHash: string;
|
|
1233
|
+
prevStateHash: string | null;
|
|
1234
|
+
principalId: string;
|
|
1235
|
+
principalType: "group" | "organization";
|
|
1236
|
+
projectionRoot: string;
|
|
1237
|
+
signature: string;
|
|
1238
|
+
signedAt: string;
|
|
1239
|
+
signerUserId: string;
|
|
1240
|
+
signerUserKeyFingerprint: string;
|
|
1241
|
+
stateHash: string;
|
|
1242
|
+
version: number;
|
|
1243
|
+
};
|
|
1244
|
+
} | {
|
|
1245
|
+
unchanged: true;
|
|
1246
|
+
head: {
|
|
1247
|
+
keyEpoch: number;
|
|
1248
|
+
keyFingerprint: string;
|
|
1249
|
+
principalId: string;
|
|
1250
|
+
principalType: "group" | "organization";
|
|
1251
|
+
stateHash: string;
|
|
1252
|
+
version: number;
|
|
1253
|
+
};
|
|
1254
|
+
}>>;
|
|
1137
1255
|
getProjectionPolicyHistoryPages(...args: Parameters<PrincipalPolicyRequests["publicPages"]>): AsyncGenerator<RequestResult<{
|
|
1138
1256
|
currentGrants: {
|
|
1139
1257
|
accessLevel: "admin" | "read" | "write";
|
|
@@ -271,6 +271,10 @@ export class ApiClient {
|
|
|
271
271
|
getPrincipalPolicyPages(principalType, principalId, options = {}) {
|
|
272
272
|
return this.principalPolicyRequests.pages(principalType, principalId, options);
|
|
273
273
|
}
|
|
274
|
+
/** Unpinned discovery; `ifHead` asks for a bare head when it is still live. */
|
|
275
|
+
getPrincipalPolicyDiscovery(...args) {
|
|
276
|
+
return this.principalPolicyRequests.discover(...args);
|
|
277
|
+
}
|
|
274
278
|
getProjectionPolicyHistoryPages(...args) {
|
|
275
279
|
return this.principalPolicyRequests.publicPages(...args);
|
|
276
280
|
}
|