@bettercms-ai/db 0.4.5 → 0.4.6

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.js CHANGED
@@ -11654,18 +11654,18 @@ var require_common = __commonJS({
11654
11654
  if (typeof args[0] !== "string") {
11655
11655
  args.unshift("%O");
11656
11656
  }
11657
- let index106 = 0;
11657
+ let index108 = 0;
11658
11658
  args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
11659
11659
  if (match === "%%") {
11660
11660
  return "%";
11661
11661
  }
11662
- index106++;
11662
+ index108++;
11663
11663
  const formatter = createDebug.formatters[format];
11664
11664
  if (typeof formatter === "function") {
11665
- const val = args[index106];
11665
+ const val = args[index108];
11666
11666
  match = formatter.call(self2, val);
11667
- args.splice(index106, 1);
11668
- index106--;
11667
+ args.splice(index108, 1);
11668
+ index108--;
11669
11669
  }
11670
11670
  return match;
11671
11671
  });
@@ -11901,15 +11901,15 @@ var require_browser = __commonJS({
11901
11901
  }
11902
11902
  const c = "color: " + this.color;
11903
11903
  args.splice(1, 0, c, "color: inherit");
11904
- let index106 = 0;
11904
+ let index108 = 0;
11905
11905
  let lastC = 0;
11906
11906
  args[0].replace(/%[a-zA-Z%]/g, (match) => {
11907
11907
  if (match === "%%") {
11908
11908
  return;
11909
11909
  }
11910
- index106++;
11910
+ index108++;
11911
11911
  if (match === "%c") {
11912
- lastC = index106;
11912
+ lastC = index108;
11913
11913
  }
11914
11914
  });
11915
11915
  args.splice(lastC, 0, c);
@@ -14470,10 +14470,10 @@ var require_axios = __commonJS({
14470
14470
  value = stringifyWithDepthLimit(value, 1);
14471
14471
  } else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
14472
14472
  key = removeBrackets(key);
14473
- arr.forEach(function each(el, index106) {
14473
+ arr.forEach(function each(el, index108) {
14474
14474
  !(utils$1.isUndefined(el) || el === null) && formData.append(
14475
14475
  // eslint-disable-next-line no-nested-ternary
14476
- indexes === true ? renderKey([key], index106, dots) : indexes === null ? key : key + "[]",
14476
+ indexes === true ? renderKey([key], index108, dots) : indexes === null ? key : key + "[]",
14477
14477
  convertValue(el)
14478
14478
  );
14479
14479
  });
@@ -14774,9 +14774,9 @@ var require_axios = __commonJS({
14774
14774
  });
14775
14775
  }
14776
14776
  var MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
14777
- function throwIfDepthExceeded(index106) {
14778
- if (index106 > MAX_DEPTH) {
14779
- throw new AxiosError("FormData field is too deeply nested (" + index106 + " levels). Max depth: " + MAX_DEPTH, AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED);
14777
+ function throwIfDepthExceeded(index108) {
14778
+ if (index108 > MAX_DEPTH) {
14779
+ throw new AxiosError("FormData field is too deeply nested (" + index108 + " levels). Max depth: " + MAX_DEPTH, AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED);
14780
14780
  }
14781
14781
  }
14782
14782
  function parsePropPath(name) {
@@ -14802,12 +14802,12 @@ var require_axios = __commonJS({
14802
14802
  return obj;
14803
14803
  }
14804
14804
  function formDataToJSON(formData) {
14805
- function buildPath(path2, value, target, index106) {
14806
- throwIfDepthExceeded(index106);
14807
- let name = path2[index106++];
14805
+ function buildPath(path2, value, target, index108) {
14806
+ throwIfDepthExceeded(index108);
14807
+ let name = path2[index108++];
14808
14808
  if (name === "__proto__") return true;
14809
14809
  const isNumericKey = Number.isFinite(+name);
14810
- const isLast = index106 >= path2.length;
14810
+ const isLast = index108 >= path2.length;
14811
14811
  name = !name && utils$1.isArray(target) ? target.length : name;
14812
14812
  if (isLast) {
14813
14813
  if (utils$1.hasOwnProp(target, name)) {
@@ -14820,7 +14820,7 @@ var require_axios = __commonJS({
14820
14820
  if (!utils$1.hasOwnProp(target, name) || !utils$1.isObject(target[name])) {
14821
14821
  target[name] = [];
14822
14822
  }
14823
- const result = buildPath(path2, value, target[name], index106);
14823
+ const result = buildPath(path2, value, target[name], index108);
14824
14824
  if (result && utils$1.isArray(target[name])) {
14825
14825
  target[name] = arrayToObject(target[name]);
14826
14826
  }
@@ -15489,20 +15489,20 @@ var require_axios = __commonJS({
15489
15489
  if (parts[0] !== "127") return false;
15490
15490
  return parts.every((p) => /^\d+$/.test(p) && Number(p) >= 0 && Number(p) <= 255);
15491
15491
  };
15492
- var parseIPv4Octet = (text122) => {
15493
- if (/^0[xX][0-9a-fA-F]+$/.test(text122)) {
15494
- const n = parseInt(text122.slice(2), 16);
15492
+ var parseIPv4Octet = (text125) => {
15493
+ if (/^0[xX][0-9a-fA-F]+$/.test(text125)) {
15494
+ const n = parseInt(text125.slice(2), 16);
15495
15495
  return Number.isFinite(n) ? n : null;
15496
15496
  }
15497
- if (text122.length > 1 && /^0[0-7]+$/.test(text122)) {
15498
- const n = parseInt(text122, 8);
15497
+ if (text125.length > 1 && /^0[0-7]+$/.test(text125)) {
15498
+ const n = parseInt(text125, 8);
15499
15499
  return Number.isFinite(n) ? n : null;
15500
15500
  }
15501
- if (text122.length > 1 && /^0[0-9]+$/.test(text122)) {
15501
+ if (text125.length > 1 && /^0[0-9]+$/.test(text125)) {
15502
15502
  return null;
15503
15503
  }
15504
- if (/^[0-9]+$/.test(text122)) {
15505
- const n = parseInt(text122, 10);
15504
+ if (/^[0-9]+$/.test(text125)) {
15505
+ const n = parseInt(text125, 10);
15506
15506
  return Number.isFinite(n) ? n : null;
15507
15507
  }
15508
15508
  return null;
@@ -15840,12 +15840,12 @@ var require_axios = __commonJS({
15840
15840
  };
15841
15841
  }
15842
15842
  function throttle(fn, freq) {
15843
- let timestamp113 = 0;
15843
+ let timestamp116 = 0;
15844
15844
  let threshold = 1e3 / freq;
15845
15845
  let lastArgs;
15846
15846
  let timer;
15847
15847
  const invoke = (args, now = Date.now()) => {
15848
- timestamp113 = now;
15848
+ timestamp116 = now;
15849
15849
  lastArgs = null;
15850
15850
  if (timer) {
15851
15851
  clearTimeout(timer);
@@ -15855,7 +15855,7 @@ var require_axios = __commonJS({
15855
15855
  };
15856
15856
  const throttled = (...args) => {
15857
15857
  const now = Date.now();
15858
- const passed = now - timestamp113;
15858
+ const passed = now - timestamp116;
15859
15859
  if (passed >= threshold) {
15860
15860
  invoke(args, now);
15861
15861
  } else {
@@ -18242,9 +18242,9 @@ var require_axios = __commonJS({
18242
18242
  if (!this._listeners) {
18243
18243
  return;
18244
18244
  }
18245
- const index106 = this._listeners.indexOf(listener);
18246
- if (index106 !== -1) {
18247
- this._listeners.splice(index106, 1);
18245
+ const index108 = this._listeners.indexOf(listener);
18246
+ if (index108 !== -1) {
18247
+ this._listeners.splice(index108, 1);
18248
18248
  }
18249
18249
  }
18250
18250
  toAbortSignal() {
@@ -21986,6 +21986,7 @@ __export(index_exports, {
21986
21986
  branchColumns: () => branchColumns,
21987
21987
  branchPreviewGrants: () => branchPreviewGrants,
21988
21988
  branchPreviewShares: () => branchPreviewShares,
21989
+ branchRowSyncs: () => branchRowSyncs,
21989
21990
  brandKitVersions: () => brandKitVersions,
21990
21991
  buildTriggerRuns: () => buildTriggerRuns,
21991
21992
  buildTriggers: () => buildTriggers,
@@ -22087,6 +22088,10 @@ __export(index_exports, {
22087
22088
  pendingInvites: () => pendingInvites,
22088
22089
  planChanges: () => planChanges,
22089
22090
  planLimits: () => planLimits,
22091
+ platformIncidentUpdates: () => platformIncidentUpdates,
22092
+ platformIncidents: () => platformIncidents,
22093
+ platformTasks: () => platformTasks,
22094
+ platformVendors: () => platformVendors,
22090
22095
  previewTokenRevocations: () => previewTokenRevocations,
22091
22096
  projectBranches: () => projectBranches,
22092
22097
  projectEnvVars: () => projectEnvVars,
@@ -29317,6 +29322,7 @@ var cloneJobs = pgTable100(
29317
29322
 
29318
29323
  // src/schema/project_branches.ts
29319
29324
  import {
29325
+ primaryKey as primaryKey7,
29320
29326
  pgTable as pgTable101,
29321
29327
  text as text102,
29322
29328
  varchar as varchar76,
@@ -29337,6 +29343,8 @@ var projectBranches = pgTable101(
29337
29343
  status: varchar76("status", { length: 16 }).$type().notNull().default("open"),
29338
29344
  appliedAt: timestamp94("applied_at"),
29339
29345
  abandonedAt: timestamp94("abandoned_at"),
29346
+ /** Set while an Apply/Pull runs (0374); a second one is refused. Stale after five minutes. */
29347
+ applyingAt: timestamp94("applying_at"),
29340
29348
  ...auditColumns
29341
29349
  },
29342
29350
  (t) => [
@@ -29344,6 +29352,21 @@ var projectBranches = pgTable101(
29344
29352
  uniqueIndex46("project_branches_project_slug_open_idx").on(t.projectId, t.slug).where(sql32`${t.status} = 'open'`)
29345
29353
  ]
29346
29354
  );
29355
+ var branchRowSyncs = pgTable101(
29356
+ "branch_row_syncs",
29357
+ {
29358
+ workspaceId: text102("workspace_id").notNull(),
29359
+ projectId: text102("project_id").notNull(),
29360
+ branchId: text102("branch_id").notNull(),
29361
+ kind: text102("kind").notNull(),
29362
+ parentRowId: text102("parent_row_id").notNull(),
29363
+ syncedAt: timestamp94("synced_at").notNull().defaultNow()
29364
+ },
29365
+ (t) => [
29366
+ primaryKey7({ columns: [t.branchId, t.kind, t.parentRowId] }),
29367
+ index88("branch_row_syncs_project_idx").on(t.projectId)
29368
+ ]
29369
+ );
29347
29370
 
29348
29371
  // src/schema/branch_preview_share.ts
29349
29372
  import { pgTable as pgTable102, text as text103, boolean as boolean32, timestamp as timestamp95, index as index89, uniqueIndex as uniqueIndex47 } from "drizzle-orm/pg-core";
@@ -30069,6 +30092,109 @@ var formIntegrationDeliveries = pgTable120(
30069
30092
  ]
30070
30093
  );
30071
30094
 
30095
+ // src/schema/platform_incidents.ts
30096
+ import { check as check12, integer as integer60, pgTable as pgTable121, smallint as smallint2, text as text122, timestamp as timestamp113, index as index106 } from "drizzle-orm/pg-core";
30097
+ import { sql as sql38 } from "drizzle-orm";
30098
+ var STATUS_IN = sql38.raw("('investigating', 'identified', 'monitoring', 'resolved')");
30099
+ var platformIncidents = pgTable121(
30100
+ "platform_incidents",
30101
+ {
30102
+ id: text122("id").primaryKey(),
30103
+ number: integer60("number").generatedAlwaysAsIdentity().notNull().unique("platform_incidents_number_key"),
30104
+ title: text122("title").notNull(),
30105
+ severity: smallint2("severity").notNull(),
30106
+ // 1 (worst) … 4
30107
+ status: text122("status").notNull().default("investigating"),
30108
+ // investigating | identified | monitoring | resolved
30109
+ services: text122("services").array().notNull().default([]),
30110
+ commanderId: text122("commander_id"),
30111
+ startedAt: timestamp113("started_at", { withTimezone: true }).notNull().defaultNow(),
30112
+ resolvedAt: timestamp113("resolved_at", { withTimezone: true }),
30113
+ createdBy: text122("created_by"),
30114
+ createdAt: timestamp113("created_at", { withTimezone: true }).notNull().defaultNow(),
30115
+ updatedAt: timestamp113("updated_at", { withTimezone: true }).notNull().defaultNow()
30116
+ },
30117
+ // Mirrors 0375 exactly: drizzle-kit push builds fresh DBs before the migration runs.
30118
+ (t) => [
30119
+ index106("platform_incidents_started_idx").on(t.startedAt.desc()),
30120
+ check12("platform_incidents_severity_check", sql38`${t.severity} BETWEEN 1 AND 4`),
30121
+ check12("platform_incidents_status_check", sql38`${t.status} IN ${STATUS_IN}`)
30122
+ ]
30123
+ );
30124
+ var platformIncidentUpdates = pgTable121(
30125
+ "platform_incident_updates",
30126
+ {
30127
+ id: text122("id").primaryKey(),
30128
+ incidentId: text122("incident_id").notNull().references(() => platformIncidents.id, { onDelete: "cascade" }),
30129
+ status: text122("status").notNull(),
30130
+ note: text122("note").notNull(),
30131
+ createdBy: text122("created_by"),
30132
+ createdAt: timestamp113("created_at", { withTimezone: true }).notNull().defaultNow()
30133
+ },
30134
+ (t) => [
30135
+ index106("platform_incident_updates_incident_idx").on(t.incidentId, t.createdAt),
30136
+ check12("platform_incident_updates_status_check", sql38`${t.status} IN ${STATUS_IN}`)
30137
+ ]
30138
+ );
30139
+
30140
+ // src/schema/platform_vendors.ts
30141
+ import { date as date3, integer as integer61, pgTable as pgTable122, text as text123, timestamp as timestamp114, varchar as varchar92 } from "drizzle-orm/pg-core";
30142
+ var platformVendors = pgTable122("platform_vendors", {
30143
+ id: text123("id").primaryKey(),
30144
+ name: text123("name").notNull(),
30145
+ category: text123("category").notNull(),
30146
+ billingCycle: text123("billing_cycle").notNull().default("monthly"),
30147
+ // monthly | yearly | usage
30148
+ monthlyCents: integer61("monthly_cents").notNull().default(0),
30149
+ // normalised monthly cost
30150
+ currency: varchar92("currency", { length: 3 }).notNull().default("usd"),
30151
+ renewsOn: date3("renews_on"),
30152
+ // YYYY-MM-DD
30153
+ status: text123("status").notNull().default("active"),
30154
+ // active | trial | cancelling | unused
30155
+ ownerEmail: text123("owner_email"),
30156
+ notes: text123("notes"),
30157
+ createdBy: text123("created_by"),
30158
+ createdAt: timestamp114("created_at", { withTimezone: true }).notNull().defaultNow(),
30159
+ updatedAt: timestamp114("updated_at", { withTimezone: true }).notNull().defaultNow()
30160
+ });
30161
+
30162
+ // src/schema/platform_tasks.ts
30163
+ import { check as check13, date as date4, pgTable as pgTable123, text as text124, timestamp as timestamp115, index as index107 } from "drizzle-orm/pg-core";
30164
+ import { sql as sql39 } from "drizzle-orm";
30165
+ var platformTasks = pgTable123(
30166
+ "platform_tasks",
30167
+ {
30168
+ id: text124("id").primaryKey(),
30169
+ title: text124("title").notNull(),
30170
+ description: text124("description"),
30171
+ status: text124("status").notNull().default("open"),
30172
+ // open | in_progress | done
30173
+ priority: text124("priority").notNull().default("medium"),
30174
+ // low | medium | high | urgent
30175
+ assigneeId: text124("assignee_id"),
30176
+ dueOn: date4("due_on"),
30177
+ // YYYY-MM-DD
30178
+ entityType: text124("entity_type"),
30179
+ // user | workspace | incident | deal
30180
+ entityId: text124("entity_id"),
30181
+ entityLabel: text124("entity_label"),
30182
+ completedAt: timestamp115("completed_at", { withTimezone: true }),
30183
+ createdBy: text124("created_by"),
30184
+ createdAt: timestamp115("created_at", { withTimezone: true }).notNull().defaultNow(),
30185
+ updatedAt: timestamp115("updated_at", { withTimezone: true }).notNull().defaultNow()
30186
+ },
30187
+ // Mirrors 0377 exactly: drizzle-kit push builds fresh DBs before the migration runs.
30188
+ (t) => [
30189
+ index107("platform_tasks_open_idx").on(t.status, t.dueOn),
30190
+ index107("platform_tasks_entity_idx").on(t.entityType, t.entityId),
30191
+ check13("platform_tasks_status_check", sql39`${t.status} IN ('open', 'in_progress', 'done')`),
30192
+ check13("platform_tasks_priority_check", sql39`${t.priority} IN ('low', 'medium', 'high', 'urgent')`),
30193
+ check13("platform_tasks_entity_type_check", sql39`${t.entityType} IN ('user', 'workspace', 'incident', 'deal')`),
30194
+ check13("platform_tasks_entity_pair_check", sql39`(${t.entityType} IS NULL) = (${t.entityId} IS NULL)`)
30195
+ ]
30196
+ );
30197
+
30072
30198
  // src/lib/request-context.ts
30073
30199
  import { AsyncLocalStorage } from "async_hooks";
30074
30200
  import { drizzle } from "drizzle-orm/postgres-js";
@@ -30133,7 +30259,7 @@ async function reserveWithDeadline() {
30133
30259
  })
30134
30260
  ]);
30135
30261
  } catch (err) {
30136
- void pending.then((sql39) => sql39.release()).catch((cause) => console.error("[db-pool] orphaned acquire failed:", cause));
30262
+ void pending.then((sql41) => sql41.release()).catch((cause) => console.error("[db-pool] orphaned acquire failed:", cause));
30137
30263
  throw err;
30138
30264
  } finally {
30139
30265
  clearTimeout(timer);
@@ -30343,7 +30469,7 @@ var queries = {
30343
30469
  };
30344
30470
 
30345
30471
  // src/lib/workspace-context.ts
30346
- import { sql as sql38 } from "drizzle-orm";
30472
+ import { sql as sql40 } from "drizzle-orm";
30347
30473
  import { eq as eq2 } from "drizzle-orm";
30348
30474
  import { nanoid } from "nanoid";
30349
30475
  var writeOrigins = new Set(WRITE_ORIGINS);
@@ -30377,7 +30503,7 @@ async function getWorkspaceSlugById(workspaceId) {
30377
30503
  }
30378
30504
  async function lookupApiKeyByHash(keyHash) {
30379
30505
  const rows = await db.execute(
30380
- sql38`SELECT * FROM lookup_api_key_by_hash(${keyHash})`
30506
+ sql40`SELECT * FROM lookup_api_key_by_hash(${keyHash})`
30381
30507
  );
30382
30508
  const r = rows[0];
30383
30509
  if (!r) return null;
@@ -30408,7 +30534,7 @@ async function lookupApiKeyByHash(keyHash) {
30408
30534
  }
30409
30535
  async function publicWorkspaceBySlug(slug) {
30410
30536
  const rows = await db.execute(
30411
- sql38`SELECT id, slug FROM public_workspace_by_slug(${slug})`
30537
+ sql40`SELECT id, slug FROM public_workspace_by_slug(${slug})`
30412
30538
  );
30413
30539
  const r = rows[0];
30414
30540
  return r?.id ? { id: r.id, slug: r.slug ?? slug } : null;
@@ -30418,7 +30544,7 @@ async function getDefaultWorkspaceId(userId) {
30418
30544
  return row?.id ?? null;
30419
30545
  }
30420
30546
  async function resolveUserWorkspace(userId, workspaceId) {
30421
- const rows = await db.execute(sql38`
30547
+ const rows = await db.execute(sql40`
30422
30548
  SELECT workspace_id, role
30423
30549
  FROM resolve_user_workspace(${userId}, ${workspaceId ?? null})
30424
30550
  `);
@@ -30454,7 +30580,7 @@ async function ensureDefaultWorkspace(userId, name = "My Workspace", slug) {
30454
30580
  for (let attempt = 1; attempt <= MAX_SLUG_ATTEMPTS; attempt++) {
30455
30581
  console.log("[ensureDefaultWorkspace] Creating workspace + owner membership:", { workspaceId, slug: candidateSlug, attempt });
30456
30582
  try {
30457
- await db.execute(sql38`
30583
+ await db.execute(sql40`
30458
30584
  SELECT create_default_workspace(${workspaceId}, ${userId}, ${memberId}, ${name}, ${candidateSlug})
30459
30585
  `);
30460
30586
  console.log("[ensureDefaultWorkspace] Workspace + owner membership created with slug:", candidateSlug);
@@ -30661,6 +30787,7 @@ export {
30661
30787
  branchColumns,
30662
30788
  branchPreviewGrants,
30663
30789
  branchPreviewShares,
30790
+ branchRowSyncs,
30664
30791
  brandKitVersions,
30665
30792
  buildTriggerRuns,
30666
30793
  buildTriggers,
@@ -30775,6 +30902,10 @@ export {
30775
30902
  pendingInvites,
30776
30903
  planChanges,
30777
30904
  planLimits,
30905
+ platformIncidentUpdates,
30906
+ platformIncidents,
30907
+ platformTasks,
30908
+ platformVendors,
30778
30909
  poolStats,
30779
30910
  previewTokenRevocations,
30780
30911
  projectBranches,