@axiom-lattice/pg-stores 3.1.16 → 3.1.18

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/dist/index.mjs CHANGED
@@ -8817,6 +8817,34 @@ var addFileContentType = {
8817
8817
  }
8818
8818
  };
8819
8819
 
8820
+ // src/migrations/menu_items_add_mcp_app_type.ts
8821
+ var addMcpAppContentType = {
8822
+ version: 181,
8823
+ name: "add_mcp_app_content_type_to_menu_items",
8824
+ up: async (client) => {
8825
+ await client.query(`
8826
+ ALTER TABLE lattice_menu_items
8827
+ DROP CONSTRAINT IF EXISTS lattice_menu_items_content_type_check
8828
+ `);
8829
+ await client.query(`
8830
+ ALTER TABLE lattice_menu_items
8831
+ ADD CONSTRAINT lattice_menu_items_content_type_check
8832
+ CHECK (content_type IN ('agent', 'html', 'custom', 'file', 'mcpApp'))
8833
+ `);
8834
+ },
8835
+ down: async (client) => {
8836
+ await client.query(`
8837
+ ALTER TABLE lattice_menu_items
8838
+ DROP CONSTRAINT IF EXISTS lattice_menu_items_content_type_check
8839
+ `);
8840
+ await client.query(`
8841
+ ALTER TABLE lattice_menu_items
8842
+ ADD CONSTRAINT lattice_menu_items_content_type_check
8843
+ CHECK (content_type IN ('agent', 'html', 'custom', 'file'))
8844
+ `);
8845
+ }
8846
+ };
8847
+
8820
8848
  // src/stores/MenuStore.ts
8821
8849
  var MenuStore = class {
8822
8850
  constructor(options) {
@@ -8835,6 +8863,7 @@ var MenuStore = class {
8835
8863
  this.migrationManager = new MigrationManager(this.pool);
8836
8864
  this.migrationManager.register(createMenuItemsTable);
8837
8865
  this.migrationManager.register(addFileContentType);
8866
+ this.migrationManager.register(addMcpAppContentType);
8838
8867
  if (options.autoMigrate !== false) {
8839
8868
  this.initialize().catch((error) => {
8840
8869
  console.error("Failed to initialize MenuStore:", error);
@@ -10054,6 +10083,10 @@ var PostgreSQLCapabilityBundleStore = class {
10054
10083
  }
10055
10084
  async update(tenantId, id, input) {
10056
10085
  await this.ready();
10086
+ const expectedUpdatedAt = input.expectedUpdatedAt;
10087
+ if (typeof expectedUpdatedAt !== "string" || expectedUpdatedAt.trim().length === 0) {
10088
+ return this.resolveCasMiss(tenantId, id);
10089
+ }
10057
10090
  const fields = [];
10058
10091
  const values = [];
10059
10092
  const add = (field, value) => {
@@ -10068,37 +10101,46 @@ var PostgreSQLCapabilityBundleStore = class {
10068
10101
  add("capabilities", JSON.stringify(input.capabilities));
10069
10102
  }
10070
10103
  if (fields.length === 0) {
10071
- const expectedUpdatedAt2 = input.expectedUpdatedAt;
10072
10104
  const result = await this.pool.query(
10073
10105
  `SELECT id, tenant_id, bundle_key, name, description, capabilities, created_at, updated_at::text AS updated_at
10074
10106
  FROM lattice_capability_bundles
10075
- WHERE tenant_id = $1 AND id = $2${expectedUpdatedAt2 === void 0 ? "" : " AND updated_at::text = $3"}`,
10076
- expectedUpdatedAt2 === void 0 ? [tenantId, id] : [tenantId, id, expectedUpdatedAt2]
10107
+ WHERE tenant_id = $1 AND id = $2 AND updated_at::text = $3`,
10108
+ [tenantId, id, expectedUpdatedAt]
10077
10109
  );
10078
10110
  if (result.rows[0]) return map(result.rows[0]);
10079
- return expectedUpdatedAt2 === void 0 ? null : { status: "conflict" };
10111
+ return this.resolveCasMiss(tenantId, id);
10080
10112
  }
10081
- const expectedUpdatedAt = input.expectedUpdatedAt;
10082
- values.push(tenantId, id);
10083
- if (expectedUpdatedAt !== void 0) values.push(expectedUpdatedAt);
10084
- const tenantParam = values.length - (expectedUpdatedAt === void 0 ? 1 : 2);
10113
+ values.push(tenantId, id, expectedUpdatedAt);
10114
+ const tenantParam = values.length - 2;
10085
10115
  const idParam = tenantParam + 1;
10086
- const revisionPredicate = expectedUpdatedAt === void 0 ? "" : ` AND updated_at::text = $${values.length}`;
10116
+ const revisionParam = values.length;
10087
10117
  try {
10088
10118
  const result = await this.pool.query(
10089
10119
  `UPDATE lattice_capability_bundles
10090
- SET ${fields.join(", ")}, updated_at = GREATEST(updated_at + interval '1 microsecond', clock_timestamp())
10091
- WHERE tenant_id = $${tenantParam} AND id = $${idParam}${revisionPredicate}
10120
+ SET ${fields.join(", ")}, updated_at = GREATEST(updated_at + interval '1 microsecond', clock_timestamp())
10121
+ WHERE tenant_id = $${tenantParam} AND id = $${idParam} AND updated_at::text = $${revisionParam}
10092
10122
  RETURNING id, tenant_id, bundle_key, name, description, capabilities, created_at, updated_at::text AS updated_at`,
10093
10123
  values
10094
10124
  );
10095
10125
  if (result.rows[0]) return map(result.rows[0]);
10096
- return expectedUpdatedAt === void 0 ? null : { status: "conflict" };
10126
+ return this.resolveCasMiss(tenantId, id);
10097
10127
  } catch (error) {
10098
10128
  if (isDuplicate(error)) throw new Error(duplicateMessage);
10099
10129
  throw error;
10100
10130
  }
10101
10131
  }
10132
+ /**
10133
+ * Distinguishes a stale-revision CAS miss from a missing bundle.
10134
+ *
10135
+ * @returns `null` when no such bundle exists, otherwise a conflict marker.
10136
+ */
10137
+ async resolveCasMiss(tenantId, id) {
10138
+ const result = await this.pool.query(
10139
+ "SELECT id FROM lattice_capability_bundles WHERE tenant_id = $1 AND id = $2",
10140
+ [tenantId, id]
10141
+ );
10142
+ return result.rows[0] ? { status: "conflict" } : null;
10143
+ }
10102
10144
  async deleteIfUnreferenced(tenantId, id) {
10103
10145
  await this.ready();
10104
10146
  const client = await this.pool.connect();
@@ -10928,6 +10970,7 @@ async function createPgStoreConfig(connectionString) {
10928
10970
  mm.register(createMenuItemsTable);
10929
10971
  mm.register(createSharedResourcesTable);
10930
10972
  mm.register(addFileContentType);
10973
+ mm.register(addMcpAppContentType);
10931
10974
  mm.register(createCollectionsTable);
10932
10975
  mm.register(createTaskWorkItemsMigration);
10933
10976
  mm.register(addWorkItemProjectFieldsMigration);
@@ -11588,6 +11631,7 @@ export {
11588
11631
  addHoldoutToEvalRuns,
11589
11632
  addInterruptColumnsToEval,
11590
11633
  addInterruptPolicyToEvalCases,
11634
+ addMcpAppContentType,
11591
11635
  addProjectConfigColumn,
11592
11636
  addScheduleTenantId,
11593
11637
  addSkillTenantId,