@fusebase/fusebase-gate-sdk 2.2.2-sdk.34 → 2.2.2-sdk.36

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.
@@ -5,10 +5,23 @@
5
5
  * Domain: isolated-stores
6
6
  */
7
7
  import type { Client } from "../runtime/transport";
8
- import type { ApplyIsolatedStoreSqlMigrationsRequestContract, ApplyIsolatedStoreSqlMigrationsResponseContract, CountIsolatedStoreNoSqlDocumentsRequestContract, CountIsolatedStoreNoSqlDocumentsResponseContract, CreateIsolatedStoreCheckpointRequestContract, CreateIsolatedStoreCheckpointResponseContract, CreateIsolatedStoreNoSqlCollectionRequestContract, CreateIsolatedStoreNoSqlCollectionResponseContract, CreateIsolatedStoreRequestContract, CreateIsolatedStoreResponseContract, DeleteIsolatedStoreNoSqlDocumentResponseContract, DeleteIsolatedStoreResponseContract, DeleteIsolatedStoreStageResponseContract, GetIsolatedStoreSqlMigrationStatusRequestContract, ImportIsolatedStoreNoSqlDocumentsRequestContract, ImportIsolatedStoreNoSqlDocumentsResponseContract, InitIsolatedStoreStageRequestContract, InitIsolatedStoreStageResponseContract, IsolatedStoreIdInPathRequired, IsolatedStoreListResponseContract, IsolatedStoreNoSqlCollectionNameInPathRequired, IsolatedStoreNoSqlDocumentIdInPathRequired, IsolatedStoreNoSqlDocumentResponseContract, IsolatedStoreNoSqlListCollectionsResponseContract, IsolatedStoreNoSqlStatsResponseContract, IsolatedStoreResponseContract, IsolatedStoreRevisionIdInPathRequired, IsolatedStoreRevisionListResponseContract, IsolatedStoreSqlBatchInsertRequestContract, IsolatedStoreSqlBatchInsertResponseContract, IsolatedStoreSqlCountRequestContract, IsolatedStoreSqlCountResponseContract, IsolatedStoreSqlDeleteRequestContract, IsolatedStoreSqlDeleteResponseContract, IsolatedStoreSqlDescribeTableResponseContract, IsolatedStoreSqlExecuteRequestContract, IsolatedStoreSqlExecuteResponseContract, IsolatedStoreSqlImportRequestContract, IsolatedStoreSqlImportResponseContract, IsolatedStoreSqlInsertRequestContract, IsolatedStoreSqlInsertResponseContract, IsolatedStoreSqlListTablesResponseContract, IsolatedStoreSqlMigrationStatusContract, IsolatedStoreSqlQueryRequestContract, IsolatedStoreSqlQueryResponseContract, IsolatedStoreSqlSchemaNameInQueryOptional, IsolatedStoreSqlSelectRequestContract, IsolatedStoreSqlSelectResponseContract, IsolatedStoreSqlStatsResponseContract, IsolatedStoreSqlTableNameInPathRequired, IsolatedStoreSqlUpdateRequestContract, IsolatedStoreSqlUpdateResponseContract, IsolatedStoreStageInPathRequired, IsolatedStoreStageListResponseContract, ListIsolatedStoresClientIdInQueryOptional, orgIdInPathRequired, PutIsolatedStoreNoSqlDocumentRequestContract, PutIsolatedStoreNoSqlDocumentResponseContract, QueryIsolatedStoreNoSqlDocumentsRequestContract, QueryIsolatedStoreNoSqlDocumentsResponseContract, RestoreIsolatedStoreRevisionResponseContract } from "../types";
8
+ import type { AdoptIsolatedStoreSqlMigrationBaselineRequestContract, AdoptIsolatedStoreSqlMigrationBaselineResponseContract, ApplyIsolatedStoreSqlMigrationsRequestContract, ApplyIsolatedStoreSqlMigrationsResponseContract, CountIsolatedStoreNoSqlDocumentsRequestContract, CountIsolatedStoreNoSqlDocumentsResponseContract, CreateIsolatedStoreCheckpointRequestContract, CreateIsolatedStoreCheckpointResponseContract, CreateIsolatedStoreNoSqlCollectionRequestContract, CreateIsolatedStoreNoSqlCollectionResponseContract, CreateIsolatedStoreRequestContract, CreateIsolatedStoreResponseContract, DeleteIsolatedStoreNoSqlDocumentResponseContract, DeleteIsolatedStoreResponseContract, DeleteIsolatedStoreStageResponseContract, GetIsolatedStoreSqlMigrationStatusRequestContract, ImportIsolatedStoreNoSqlDocumentsRequestContract, ImportIsolatedStoreNoSqlDocumentsResponseContract, InitIsolatedStoreStageRequestContract, InitIsolatedStoreStageResponseContract, IsolatedStoreIdInPathRequired, IsolatedStoreListResponseContract, IsolatedStoreNoSqlCollectionNameInPathRequired, IsolatedStoreNoSqlDocumentIdInPathRequired, IsolatedStoreNoSqlDocumentResponseContract, IsolatedStoreNoSqlListCollectionsResponseContract, IsolatedStoreNoSqlStatsResponseContract, IsolatedStoreResponseContract, IsolatedStoreRevisionIdInPathRequired, IsolatedStoreRevisionListResponseContract, IsolatedStoreSqlBatchInsertRequestContract, IsolatedStoreSqlBatchInsertResponseContract, IsolatedStoreSqlCountRequestContract, IsolatedStoreSqlCountResponseContract, IsolatedStoreSqlDeleteRequestContract, IsolatedStoreSqlDeleteResponseContract, IsolatedStoreSqlDescribeTableResponseContract, IsolatedStoreSqlExecuteRequestContract, IsolatedStoreSqlExecuteResponseContract, IsolatedStoreSqlImportRequestContract, IsolatedStoreSqlImportResponseContract, IsolatedStoreSqlInsertRequestContract, IsolatedStoreSqlInsertResponseContract, IsolatedStoreSqlListTablesResponseContract, IsolatedStoreSqlMigrationStatusContract, IsolatedStoreSqlQueryRequestContract, IsolatedStoreSqlQueryResponseContract, IsolatedStoreSqlSchemaNameInQueryOptional, IsolatedStoreSqlSelectRequestContract, IsolatedStoreSqlSelectResponseContract, IsolatedStoreSqlStatsResponseContract, IsolatedStoreSqlTableNameInPathRequired, IsolatedStoreSqlUpdateRequestContract, IsolatedStoreSqlUpdateResponseContract, IsolatedStoreStageInPathRequired, IsolatedStoreStageListResponseContract, ListIsolatedStoresClientIdInQueryOptional, orgIdInPathRequired, PutIsolatedStoreNoSqlDocumentRequestContract, PutIsolatedStoreNoSqlDocumentResponseContract, QueryIsolatedStoreNoSqlDocumentsRequestContract, QueryIsolatedStoreNoSqlDocumentsResponseContract, RestoreIsolatedStoreRevisionResponseContract } from "../types";
9
9
  export declare class IsolatedStoresApi {
10
10
  private client;
11
11
  constructor(client: Client);
12
+ /**
13
+ * Adopt existing SQL schema as migration baseline
14
+ * Records the supplied ordered migration bundle as already applied in the stage journal without executing SQL. Use this only for legacy or demo-created stages where schema objects already exist but the migration journal is empty or missing.
15
+ */
16
+ adoptIsolatedStoreSqlMigrationBaseline(params: {
17
+ path: {
18
+ orgId: orgIdInPathRequired;
19
+ storeId: IsolatedStoreIdInPathRequired;
20
+ stage: IsolatedStoreStageInPathRequired;
21
+ };
22
+ headers?: Record<string, string>;
23
+ body: AdoptIsolatedStoreSqlMigrationBaselineRequestContract;
24
+ }): Promise<AdoptIsolatedStoreSqlMigrationBaselineResponseContract>;
12
25
  /**
13
26
  * Apply SQL migrations
14
27
  * Workflow: call `getIsolatedStoreSqlMigrationStatus` with the **same** bundle, confirm `canApply` and expected `pendingCount`, then apply. Applies pending postgres migrations from an ordered bundle into the selected stage database. For prod, gate creates a checkpoint automatically before applying pending migrations. Applied history must match the bundle prefix exactly; drift returns HTTP 409 with `data.issues` (version/name/checksum, journal vs bundle). Optional `dryRun: true` performs the same prefix + optimistic-lock checks as apply but does not run SQL or write the journal (returns `dryRun: true` and the computed status). Optional `expectedLastAppliedVersion` / `expectedLastAppliedChecksum` reject with HTTP 409 before migrations run when the journal tail changed since the client's last status snapshot. Never change name, checksum, or sql for migrations already in the journal — ship fixes as new higher versions (see MCP prompt isolatedSqlMigrationDiscipline). MCP clients often cap tool_call JSON body size (on the order of a few thousand characters); the request includes full SQL text for every bundle version cumulatively, so large bundles may fail or truncate in chat-only MCP. Keep canonical SQL plus a manifest for apply from SDK, CLI, or any non-MCP caller without a tight body-size limit.
@@ -11,6 +11,21 @@ class IsolatedStoresApi {
11
11
  constructor(client) {
12
12
  this.client = client;
13
13
  }
14
+ /**
15
+ * Adopt existing SQL schema as migration baseline
16
+ * Records the supplied ordered migration bundle as already applied in the stage journal without executing SQL. Use this only for legacy or demo-created stages where schema objects already exist but the migration journal is empty or missing.
17
+ */
18
+ async adoptIsolatedStoreSqlMigrationBaseline(params) {
19
+ return this.client.request({
20
+ method: "POST",
21
+ path: "/:orgId/isolated-stores/:storeId/stages/:stage/sql/migrations/adopt-baseline",
22
+ pathParams: params.path,
23
+ headers: params.headers,
24
+ body: params.body,
25
+ opId: "adoptIsolatedStoreSqlMigrationBaseline",
26
+ expectedContentType: "application/json",
27
+ });
28
+ }
14
29
  /**
15
30
  * Apply SQL migrations
16
31
  * Workflow: call `getIsolatedStoreSqlMigrationStatus` with the **same** bundle, confirm `canApply` and expected `pendingCount`, then apply. Applies pending postgres migrations from an ordered bundle into the selected stage database. For prod, gate creates a checkpoint automatically before applying pending migrations. Applied history must match the bundle prefix exactly; drift returns HTTP 409 with `data.issues` (version/name/checksum, journal vs bundle). Optional `dryRun: true` performs the same prefix + optimistic-lock checks as apply but does not run SQL or write the journal (returns `dryRun: true` and the computed status). Optional `expectedLastAppliedVersion` / `expectedLastAppliedChecksum` reject with HTTP 409 before migrations run when the journal tail changed since the client's last status snapshot. Never change name, checksum, or sql for migrations already in the journal — ship fixes as new higher versions (see MCP prompt isolatedSqlMigrationDiscipline). MCP clients often cap tool_call JSON body size (on the order of a few thousand characters); the request includes full SQL text for every bundle version cumulatively, so large bundles may fail or truncate in chat-only MCP. Keep canonical SQL plus a manifest for apply from SDK, CLI, or any non-MCP caller without a tight body-size limit.
@@ -0,0 +1,13 @@
1
+ import type { IsolatedStoreSqlMigrationBundleContract } from "../types";
2
+ export interface BuildSqlMigrationBundleEntryInput {
3
+ version: number;
4
+ name: string;
5
+ sql: string;
6
+ expectedChecksum?: string | null;
7
+ }
8
+ export interface BuildSqlMigrationBundleInput {
9
+ bundleVersion?: string | null;
10
+ migrations: BuildSqlMigrationBundleEntryInput[];
11
+ }
12
+ export declare function calculateSqlMigrationChecksum(sql: string): Promise<string>;
13
+ export declare function buildSqlMigrationBundle(input: BuildSqlMigrationBundleInput): Promise<IsolatedStoreSqlMigrationBundleContract>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateSqlMigrationChecksum = calculateSqlMigrationChecksum;
4
+ exports.buildSqlMigrationBundle = buildSqlMigrationBundle;
5
+ function normalizePositiveInteger(value, field) {
6
+ if (!Number.isInteger(value) || value <= 0) {
7
+ throw new Error(`${field} must be a positive integer`);
8
+ }
9
+ return value;
10
+ }
11
+ function normalizeNonEmptyString(value, field) {
12
+ const normalized = value.trim();
13
+ if (normalized.length === 0) {
14
+ throw new Error(`${field} must be a non-empty string`);
15
+ }
16
+ return normalized;
17
+ }
18
+ function toSha256Hex(buffer) {
19
+ return Array.from(new Uint8Array(buffer))
20
+ .map((byte) => byte.toString(16).padStart(2, "0"))
21
+ .join("");
22
+ }
23
+ async function calculateSqlMigrationChecksum(sql) {
24
+ if (typeof globalThis.crypto === "undefined" ||
25
+ typeof globalThis.crypto.subtle === "undefined") {
26
+ throw new Error("SQL migration checksum requires globalThis.crypto.subtle (available in modern browsers and Node.js 20+)");
27
+ }
28
+ const bytes = new TextEncoder().encode(sql);
29
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
30
+ return toSha256Hex(digest);
31
+ }
32
+ async function buildSqlMigrationBundle(input) {
33
+ const bundleVersion = input.bundleVersion == null ? undefined : input.bundleVersion.trim();
34
+ const entries = [...input.migrations].sort((left, right) => {
35
+ return left.version - right.version;
36
+ });
37
+ if (entries.length === 0) {
38
+ throw new Error("migrations must contain at least one entry");
39
+ }
40
+ let previousVersion = 0;
41
+ const migrations = [];
42
+ for (const [index, entry] of entries.entries()) {
43
+ const version = normalizePositiveInteger(entry.version, `migrations[${index}].version`);
44
+ if (version === previousVersion) {
45
+ throw new Error(`Duplicate migration version ${String(version)}`);
46
+ }
47
+ if (version < previousVersion) {
48
+ throw new Error(`Migrations must be strictly increasing by version; got ${String(version)} after ${String(previousVersion)}`);
49
+ }
50
+ const name = normalizeNonEmptyString(entry.name, `migrations[${index}].name`);
51
+ const sql = entry.sql;
52
+ const checksum = await calculateSqlMigrationChecksum(sql);
53
+ const expectedChecksum = entry.expectedChecksum == null ? null : entry.expectedChecksum.trim();
54
+ if (expectedChecksum !== null && expectedChecksum !== checksum) {
55
+ throw new Error(`Checksum mismatch for migration v${String(version)} ${name}: expected ${expectedChecksum}, got ${checksum}`);
56
+ }
57
+ migrations.push({
58
+ version,
59
+ name,
60
+ checksum,
61
+ sql,
62
+ });
63
+ previousVersion = version;
64
+ }
65
+ return {
66
+ ...(bundleVersion && bundleVersion.length > 0 ? { bundleVersion } : {}),
67
+ migrations,
68
+ };
69
+ }
package/dist/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export { SystemApi } from "./apis/SystemApi";
18
18
  export { TokensApi } from "./apis/TokensApi";
19
19
  export { WorkspacesApi } from "./apis/WorkspacesApi";
20
20
  export * from "./extras/fetchWithRetry";
21
+ export * from "./extras/sqlMigrationBundle";
package/dist/index.js CHANGED
@@ -47,3 +47,4 @@ Object.defineProperty(exports, "TokensApi", { enumerable: true, get: function ()
47
47
  var WorkspacesApi_1 = require("./apis/WorkspacesApi");
48
48
  Object.defineProperty(exports, "WorkspacesApi", { enumerable: true, get: function () { return WorkspacesApi_1.WorkspacesApi; } });
49
49
  __exportStar(require("./extras/fetchWithRetry"), exports);
50
+ __exportStar(require("./extras/sqlMigrationBundle"), exports);
@@ -133,8 +133,8 @@ export interface IsolatedStoreSqlAppliedMigrationContract {
133
133
  appliedAt: string;
134
134
  appliedBy: string;
135
135
  }
136
- export type IsolatedStoreSqlMigrationIssueCodeContract = "isolated_sql_journal_longer_than_bundle" | "isolated_sql_version_mismatch" | "isolated_sql_name_mismatch" | "isolated_sql_checksum_mismatch" | "isolated_sql_journal_head_mismatch";
137
- export type IsolatedStoreSqlMigrationIssueFieldContract = "history_length" | "version" | "name" | "checksum" | "journal_head";
136
+ export type IsolatedStoreSqlMigrationIssueCodeContract = "isolated_sql_journal_longer_than_bundle" | "isolated_sql_version_mismatch" | "isolated_sql_name_mismatch" | "isolated_sql_checksum_mismatch" | "isolated_sql_schema_exists_without_journal" | "isolated_sql_journal_head_mismatch";
137
+ export type IsolatedStoreSqlMigrationIssueFieldContract = "history_length" | "version" | "name" | "checksum" | "bootstrap" | "journal_head";
138
138
  /** Machine-readable drift detail; omits raw SQL (only safe fingerprints). */
139
139
  export interface IsolatedStoreSqlMigrationIssueContract {
140
140
  code: IsolatedStoreSqlMigrationIssueCodeContract;
@@ -173,6 +173,8 @@ export interface IsolatedStoreSqlMigrationStatusContract {
173
173
  appliedCount: number;
174
174
  pendingCount: number;
175
175
  isDrifted: boolean;
176
+ /** True when the stage already has schema objects but no matching journaled migration history. */
177
+ requiresBaselineAdoption: boolean;
176
178
  /** True when the bundle prefix matches the journal and pending migrations may run. */
177
179
  canApply: boolean;
178
180
  issues: string[];
@@ -214,6 +216,19 @@ export interface ApplyIsolatedStoreSqlMigrationsResponseContract {
214
216
  /** Present and true when the request used `dryRun` and no migrations were executed. */
215
217
  dryRun?: boolean | null;
216
218
  }
219
+ export interface AdoptIsolatedStoreSqlMigrationBaselineRequestContract {
220
+ schemaName?: IsolatedStoreSqlSchemaNameInQueryOptional;
221
+ bundle: IsolatedStoreSqlMigrationBundleContract;
222
+ /** Validate eligibility and return the projected post-adoption status without writing the journal. */
223
+ dryRun?: boolean | null;
224
+ }
225
+ export interface AdoptIsolatedStoreSqlMigrationBaselineResponseContract {
226
+ adoptedCount: number;
227
+ adoptedVersions: number[];
228
+ checkpointRevision?: IsolatedStoreRevisionContract | null;
229
+ status: IsolatedStoreSqlMigrationStatusContract;
230
+ dryRun?: boolean | null;
231
+ }
217
232
  /** Documented shape of JSON error responses for migration state conflicts (HTTP 409). */
218
233
  export interface IsolatedStoreSqlMigrationConflictErrorBodyContract {
219
234
  success: false;
@@ -524,6 +539,7 @@ export declare const IsolatedStoreSqlMigrationIssueCodeContract: {
524
539
  readonly IsolatedSqlVersionMismatch: "isolated_sql_version_mismatch";
525
540
  readonly IsolatedSqlNameMismatch: "isolated_sql_name_mismatch";
526
541
  readonly IsolatedSqlChecksumMismatch: "isolated_sql_checksum_mismatch";
542
+ readonly IsolatedSqlSchemaExistsWithoutJournal: "isolated_sql_schema_exists_without_journal";
527
543
  readonly IsolatedSqlJournalHeadMismatch: "isolated_sql_journal_head_mismatch";
528
544
  };
529
545
  export declare const IsolatedStoreSqlMigrationIssueFieldContract: {
@@ -531,6 +547,7 @@ export declare const IsolatedStoreSqlMigrationIssueFieldContract: {
531
547
  readonly Version: "version";
532
548
  readonly Name: "name";
533
549
  readonly Checksum: "checksum";
550
+ readonly Bootstrap: "bootstrap";
534
551
  readonly JournalHead: "journal_head";
535
552
  };
536
553
  export declare const IsolatedStoreSqlFilterOperatorContract: {
@@ -39,6 +39,7 @@ exports.IsolatedStoreSqlMigrationIssueCodeContract = {
39
39
  IsolatedSqlVersionMismatch: "isolated_sql_version_mismatch",
40
40
  IsolatedSqlNameMismatch: "isolated_sql_name_mismatch",
41
41
  IsolatedSqlChecksumMismatch: "isolated_sql_checksum_mismatch",
42
+ IsolatedSqlSchemaExistsWithoutJournal: "isolated_sql_schema_exists_without_journal",
42
43
  IsolatedSqlJournalHeadMismatch: "isolated_sql_journal_head_mismatch"
43
44
  };
44
45
  exports.IsolatedStoreSqlMigrationIssueFieldContract = {
@@ -46,6 +47,7 @@ exports.IsolatedStoreSqlMigrationIssueFieldContract = {
46
47
  Version: "version",
47
48
  Name: "name",
48
49
  Checksum: "checksum",
50
+ Bootstrap: "bootstrap",
49
51
  JournalHead: "journal_head"
50
52
  };
51
53
  exports.IsolatedStoreSqlFilterOperatorContract = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusebase/fusebase-gate-sdk",
3
- "version": "2.2.2-sdk.34",
3
+ "version": "2.2.2-sdk.36",
4
4
  "description": "TypeScript SDK for Fusebase Gate APIs - Generated from contract introspection",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -0,0 +1,9 @@
1
+ # Release Notes 2.2.2-sdk.36
2
+
3
+ - Current ref: `HEAD`
4
+ - Previous tag: `v2.2.2-sdk.36`
5
+ - Generated at: 2026-04-10T03:07:09.796Z
6
+
7
+ ## Included Drafts
8
+
9
+ - None
@@ -1,8 +1,8 @@
1
- # Release Notes 2.2.2-sdk.34
1
+ # Release Notes 2.2.2-sdk.36
2
2
 
3
3
  - Current ref: `HEAD`
4
- - Previous tag: `v2.2.2-sdk.34`
5
- - Generated at: 2026-04-08T11:54:01.164Z
4
+ - Previous tag: `v2.2.2-sdk.36`
5
+ - Generated at: 2026-04-10T03:07:09.796Z
6
6
 
7
7
  ## Included Drafts
8
8
 
@@ -1,9 +0,0 @@
1
- # Release Notes 2.2.2-sdk.34
2
-
3
- - Current ref: `HEAD`
4
- - Previous tag: `v2.2.2-sdk.34`
5
- - Generated at: 2026-04-08T11:54:01.164Z
6
-
7
- ## Included Drafts
8
-
9
- - None