@columnus/api-cli 0.1.62 → 0.1.63

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.
Files changed (2) hide show
  1. package/dist/cli.js +1075 -992
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3033,129 +3033,6 @@ async function fetchIntrospect(convexUrl, apiToken, options) {
3033
3033
  import { promises as fs } from "node:fs";
3034
3034
  import path3 from "node:path";
3035
3035
 
3036
- // ../shared/src/apiProfileSlug.ts
3037
- function apiProfileSlugToConvexModuleSegment(slug) {
3038
- return slug.replace(/-/g, "_");
3039
- }
3040
-
3041
- // ../shared/src/readApiQuery.ts
3042
- function readApiQueryExportName(kind, tableName) {
3043
- return `${kind}${tableName}`;
3044
- }
3045
- function proposeApiExportName(op, tableName) {
3046
- return `propose${op[0].toUpperCase()}${op.slice(1)}${tableName}`;
3047
- }
3048
- function readApiQueryModuleSegment(profileSlug) {
3049
- return apiProfileSlugToConvexModuleSegment(profileSlug);
3050
- }
3051
- function readApiAnyApiPath(profileSlug, kind, tableName) {
3052
- const segment = readApiQueryModuleSegment(profileSlug);
3053
- const exportName = readApiQueryExportName(kind, tableName);
3054
- return `anyApi.columnus.read.${segment}.${exportName}.${exportName}`;
3055
- }
3056
-
3057
- // ../shared/src/fieldValueShape.ts
3058
- function enumOptions(type) {
3059
- if (type.kind !== "union") return null;
3060
- const values = [];
3061
- for (const option of type.options) {
3062
- if (option.kind !== "literal") return null;
3063
- values.push(option.value);
3064
- }
3065
- return values;
3066
- }
3067
-
3068
- // ../shared/src/fieldTypeMeta.ts
3069
- function leafOnly(_type) {
3070
- }
3071
- function fieldShape(type) {
3072
- if (enumOptions(type)) return "enum";
3073
- if (type.kind === "array" && type.element.kind === "id") return "idList";
3074
- if (type.kind === "array" && hasKindTrait(type.element, "chipItem")) return "scalarList";
3075
- return type.kind;
3076
- }
3077
- var SHAPE_TRAITS = {
3078
- string: ["inline", "editable", "textScalar", "previewLabel", "chipItem"],
3079
- markdown: ["editable", "previewLabel"],
3080
- number: ["inline", "editable", "textScalar", "commitsOnChange", "previewLabel", "chipItem"],
3081
- boolean: ["inline", "editable", "commitsOnChange"],
3082
- bigint: ["inline", "editable", "textScalar", "previewLabel", "chipItem"],
3083
- null: ["inline"],
3084
- any: ["inline", "editable"],
3085
- bytes: ["inline", "editable"],
3086
- file: ["editable", "storage", "tallEditor"],
3087
- image: ["editable", "storage", "tallEditor"],
3088
- date: ["inline", "editable", "commitsOnChange", "previewLabel", "chipItem"],
3089
- datetime: ["inline", "editable", "commitsOnChange", "previewLabel", "chipItem"],
3090
- id: ["inline", "editable", "textScalar", "commitsOnChange"],
3091
- literal: ["inline", "previewLabel"],
3092
- array: ["editable", "tallEditor"],
3093
- // Edited through a summary popover / variant picker, so edits commit as they happen.
3094
- object: ["editable", "commitsOnChange"],
3095
- union: ["editable", "commitsOnChange"],
3096
- enum: ["inline", "editable", "commitsOnChange", "chipItem"],
3097
- idList: ["editable", "commitsOnChange", "wrapsInline"],
3098
- scalarList: ["editable", "wrapsInline"]
3099
- };
3100
- function hasKindTrait(type, trait) {
3101
- return SHAPE_TRAITS[fieldShape(type)].includes(trait);
3102
- }
3103
-
3104
- // ../shared/src/refGraph.ts
3105
- function isLeaf(type, leaf) {
3106
- return leaf === "document" ? type.kind === "id" : hasKindTrait(type, "storage");
3107
- }
3108
- function typeLeaves(type, leaf, at, out) {
3109
- if (isLeaf(type, leaf)) {
3110
- out.push({ type, ...at });
3111
- return out;
3112
- }
3113
- switch (type.kind) {
3114
- case "array":
3115
- typeLeaves(type.element, leaf, { ...at, path: `${at.path}[]`, many: true }, out);
3116
- break;
3117
- case "object":
3118
- for (const f of type.fields) {
3119
- const path5 = `${at.path}.${f.name}`;
3120
- typeLeaves(f.type, leaf, { ...at, path: path5, depth: at.depth + 1, binding: f.asset }, out);
3121
- }
3122
- break;
3123
- case "union":
3124
- for (const option of type.options)
3125
- typeLeaves(option, leaf, { ...at, depth: at.depth + 1 }, out);
3126
- break;
3127
- default:
3128
- leafOnly(type);
3129
- }
3130
- return out;
3131
- }
3132
- var ROOT = { path: "", depth: 0, many: false, binding: void 0 };
3133
- function compareEdges(a, b) {
3134
- return a.field.localeCompare(b.field) || a.path.localeCompare(b.path) || a.targetTable.localeCompare(b.targetTable);
3135
- }
3136
- function fieldEdges(field) {
3137
- return typeLeaves(field.type, "document", ROOT, []).map(({ type, path: path5, depth, many }) => ({
3138
- field: field.name,
3139
- path: path5,
3140
- targetTable: type.table,
3141
- many,
3142
- depth
3143
- }));
3144
- }
3145
- function refEdges(table) {
3146
- const seen = /* @__PURE__ */ new Set();
3147
- const edges = [];
3148
- for (const field of table.fields) {
3149
- for (const edge of fieldEdges(field)) {
3150
- const key = `${edge.field}\0${edge.path}\0${edge.targetTable}`;
3151
- if (seen.has(key)) continue;
3152
- seen.add(key);
3153
- edges.push(edge);
3154
- }
3155
- }
3156
- return edges.sort(compareEdges);
3157
- }
3158
-
3159
3036
  // ../../../node_modules/zod/v4/classic/external.js
3160
3037
  var external_exports = {};
3161
3038
  __export(external_exports, {
@@ -3832,8 +3709,8 @@ function assertNever(_x) {
3832
3709
  function assert(_) {
3833
3710
  }
3834
3711
  function getEnumValues(entries) {
3835
- const numericValues = Object.values(entries).filter((v3) => typeof v3 === "number");
3836
- const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v3]) => v3);
3712
+ const numericValues = Object.values(entries).filter((v4) => typeof v4 === "number");
3713
+ const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v4]) => v4);
3837
3714
  return values;
3838
3715
  }
3839
3716
  function joinValues(array2, separator = "|") {
@@ -3891,9 +3768,9 @@ function defineLazy(object2, key, getter) {
3891
3768
  }
3892
3769
  return value;
3893
3770
  },
3894
- set(v3) {
3771
+ set(v4) {
3895
3772
  Object.defineProperty(object2, key, {
3896
- value: v3
3773
+ value: v4
3897
3774
  // configurable: true,
3898
3775
  });
3899
3776
  },
@@ -5920,10 +5797,10 @@ var $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
5920
5797
  v7: 7,
5921
5798
  v8: 8
5922
5799
  };
5923
- const v3 = versionMap[def.version];
5924
- if (v3 === void 0)
5800
+ const v4 = versionMap[def.version];
5801
+ if (v4 === void 0)
5925
5802
  throw new Error(`Invalid UUID version: "${def.version}"`);
5926
- def.pattern ?? (def.pattern = uuid(v3));
5803
+ def.pattern ?? (def.pattern = uuid(v4));
5927
5804
  } else
5928
5805
  def.pattern ?? (def.pattern = uuid());
5929
5806
  $ZodStringFormat.init(inst, def);
@@ -6671,8 +6548,8 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
6671
6548
  if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
6672
6549
  assignProp(propValues, key, /* @__PURE__ */ new Set());
6673
6550
  }
6674
- for (const v3 of field.values)
6675
- propValues[key].add(v3);
6551
+ for (const v4 of field.values)
6552
+ propValues[key].add(v4);
6676
6553
  if (field.optin !== void 0)
6677
6554
  propValues[key].add(void 0);
6678
6555
  }
@@ -7018,11 +6895,11 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
7018
6895
  throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
7019
6896
  if (pv[zod.def.discriminator]?.has(void 0))
7020
6897
  undefinedCount++;
7021
- for (const [k, v3] of Object.entries(pv)) {
6898
+ for (const [k, v4] of Object.entries(pv)) {
7022
6899
  if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
7023
6900
  assignProp(propValues, k, /* @__PURE__ */ new Set());
7024
6901
  }
7025
- for (const val of v3) {
6902
+ for (const val of v4) {
7026
6903
  propValues[k].add(val);
7027
6904
  }
7028
6905
  }
@@ -7752,8 +7629,8 @@ var $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
7752
7629
  var $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
7753
7630
  $ZodType.init(inst, def);
7754
7631
  defineLazyInternal(inst, "values", (zod) => {
7755
- const v3 = zod.def.innerType._zod.values;
7756
- return v3 ? new Set([...v3].filter((x) => x !== void 0)) : void 0;
7632
+ const v4 = zod.def.innerType._zod.values;
7633
+ return v4 ? new Set([...v4].filter((x) => x !== void 0)) : void 0;
7757
7634
  });
7758
7635
  inst._zod.parse = (payload, ctx) => {
7759
7636
  const result = def.innerType._zod.run(payload, ctx);
@@ -10930,7 +10807,7 @@ var error20 = () => {
10930
10807
  if (issue2.values.length === 1) {
10931
10808
  return `\u05E2\u05E8\u05DA \u05DC\u05D0 \u05EA\u05E7\u05D9\u05DF: \u05D4\u05E2\u05E8\u05DA \u05D7\u05D9\u05D9\u05D1 \u05DC\u05D4\u05D9\u05D5\u05EA ${stringifyPrimitive(issue2.values[0])}`;
10932
10809
  }
10933
- const stringified = issue2.values.map((v3) => stringifyPrimitive(v3));
10810
+ const stringified = issue2.values.map((v4) => stringifyPrimitive(v4));
10934
10811
  if (issue2.values.length === 2) {
10935
10812
  return `\u05E2\u05E8\u05DA \u05DC\u05D0 \u05EA\u05E7\u05D9\u05DF: \u05D4\u05D0\u05E4\u05E9\u05E8\u05D5\u05D9\u05D5\u05EA \u05D4\u05DE\u05EA\u05D0\u05D9\u05DE\u05D5\u05EA \u05D4\u05DF ${stringified[0]} \u05D0\u05D5 ${stringified[1]}`;
10936
10813
  }
@@ -16188,8 +16065,8 @@ ${code}
16188
16065
  return fn;
16189
16066
  }
16190
16067
  function addConstant(ctx, value) {
16191
- for (const [name2, v3] of ctx.constants) {
16192
- if (v3 === value)
16068
+ for (const [name2, v4] of ctx.constants) {
16069
+ if (v4 === value)
16193
16070
  return name2;
16194
16071
  }
16195
16072
  const name = `c${ctx.constantCounter++}`;
@@ -16332,9 +16209,9 @@ function generateChecks(doc, ctx, schema, accessor) {
16332
16209
  }
16333
16210
  function codePointLengthVar(doc, ctx, accessor, inDoubt) {
16334
16211
  const cpLen = addConstant(ctx, codePointLength);
16335
- const v3 = newVar(ctx);
16336
- doc.write(`const ${v3} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
16337
- return v3;
16212
+ const v4 = newVar(ctx);
16213
+ doc.write(`const ${v4} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
16214
+ return v4;
16338
16215
  }
16339
16216
  function numericOperand(value, label) {
16340
16217
  if (typeof value !== "number" || !Number.isFinite(value)) {
@@ -18447,7 +18324,7 @@ function _set(Class2, valueType, params) {
18447
18324
  }
18448
18325
  // @__NO_SIDE_EFFECTS__
18449
18326
  function _enum(Class2, values, params) {
18450
- const entries = Array.isArray(values) ? Object.fromEntries(values.map((v3) => [v3, v3])) : values;
18327
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v4) => [v4, v4])) : values;
18451
18328
  return new Class2({
18452
18329
  type: "enum",
18453
18330
  entries,
@@ -18653,8 +18530,8 @@ function _stringbool(Classes, _params) {
18653
18530
  let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
18654
18531
  let falsyArray = params.falsy ?? ["false", "0", "no", "off", "n", "disabled"];
18655
18532
  if (params.case !== "sensitive") {
18656
- truthyArray = truthyArray.map((v3) => typeof v3 === "string" ? v3.toLowerCase() : v3);
18657
- falsyArray = falsyArray.map((v3) => typeof v3 === "string" ? v3.toLowerCase() : v3);
18533
+ truthyArray = truthyArray.map((v4) => typeof v4 === "string" ? v4.toLowerCase() : v4);
18534
+ falsyArray = falsyArray.map((v4) => typeof v4 === "string" ? v4.toLowerCase() : v4);
18658
18535
  }
18659
18536
  const truthySet = new Set(truthyArray);
18660
18537
  const falsySet = new Set(falsyArray);
@@ -19465,9 +19342,9 @@ var enumProcessor = (schema, _ctx, json2, _params) => {
19465
19342
  json2.not = {};
19466
19343
  return;
19467
19344
  }
19468
- if (values.every((v3) => typeof v3 === "number"))
19345
+ if (values.every((v4) => typeof v4 === "number"))
19469
19346
  json2.type = "number";
19470
- if (values.every((v3) => typeof v3 === "string"))
19347
+ if (values.every((v4) => typeof v4 === "string"))
19471
19348
  json2.type = "string";
19472
19349
  json2.enum = values;
19473
19350
  };
@@ -19500,13 +19377,13 @@ var literalProcessor = (schema, ctx, json2, params) => {
19500
19377
  json2.const = val;
19501
19378
  }
19502
19379
  } else {
19503
- if (vals.every((v3) => typeof v3 === "number"))
19380
+ if (vals.every((v4) => typeof v4 === "number"))
19504
19381
  json2.type = "number";
19505
- if (vals.every((v3) => typeof v3 === "string"))
19382
+ if (vals.every((v4) => typeof v4 === "string"))
19506
19383
  json2.type = "string";
19507
- if (vals.every((v3) => typeof v3 === "boolean"))
19384
+ if (vals.every((v4) => typeof v4 === "boolean"))
19508
19385
  json2.type = "boolean";
19509
- if (vals.every((v3) => v3 === null))
19386
+ if (vals.every((v4) => v4 === null))
19510
19387
  json2.type = "null";
19511
19388
  json2.enum = vals;
19512
19389
  }
@@ -19738,11 +19615,11 @@ function stringifyKeyNames(bySchema, json2, visited) {
19738
19615
  const types = Array.isArray(json2.type) ? json2.type : [json2.type];
19739
19616
  const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
19740
19617
  const values = json2.enum ?? (json2.const !== void 0 ? [json2.const] : void 0);
19741
- if (!numericType && !values?.some((v3) => typeof v3 === "number"))
19618
+ if (!numericType && !values?.some((v4) => typeof v4 === "number"))
19742
19619
  return json2;
19743
19620
  const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json2;
19744
19621
  if (rest.enum)
19745
- rest.enum = rest.enum.map((v3) => typeof v3 === "number" ? String(v3) : v3);
19622
+ rest.enum = rest.enum.map((v4) => typeof v4 === "number" ? String(v4) : v4);
19746
19623
  else if (typeof rest.const === "number")
19747
19624
  rest.const = String(rest.const);
19748
19625
  if (!numericType)
@@ -19816,7 +19693,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
19816
19693
  const keyValues = keyType._zod.values;
19817
19694
  const omittableOnInput = ctx.io === "input" && inputOptin(def.valueType) !== void 0;
19818
19695
  if (keyValues && !def.partial && !omittableOnInput) {
19819
- const validKeyValues = [...keyValues].filter((v3) => typeof v3 === "string" || typeof v3 === "number");
19696
+ const validKeyValues = [...keyValues].filter((v4) => typeof v4 === "string" || typeof v4 === "number");
19820
19697
  if (validKeyValues.length > 0) {
19821
19698
  json2.required = validKeyValues.map(String);
19822
19699
  }
@@ -21441,7 +21318,7 @@ var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
21441
21318
  };
21442
21319
  });
21443
21320
  function _enum2(values, params) {
21444
- const entries = Array.isArray(values) ? Object.fromEntries(values.map((v3) => [v3, v3])) : values;
21321
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v4) => [v4, v4])) : values;
21445
21322
  return new ZodEnum({
21446
21323
  type: "enum",
21447
21324
  entries,
@@ -22225,10 +22102,10 @@ function convertBaseSchema(schema, ctx) {
22225
22102
  if (enumValues.length === 1) {
22226
22103
  return z.literal(enumValues[0]);
22227
22104
  }
22228
- if (enumValues.every((v3) => typeof v3 === "string")) {
22105
+ if (enumValues.every((v4) => typeof v4 === "string")) {
22229
22106
  return z.enum(enumValues);
22230
22107
  }
22231
- const literalSchemas = enumValues.map((v3) => z.literal(v3));
22108
+ const literalSchemas = enumValues.map((v4) => z.literal(v4));
22232
22109
  if (literalSchemas.length < 2) {
22233
22110
  return literalSchemas[0];
22234
22111
  }
@@ -22824,6 +22701,53 @@ function date4(params) {
22824
22701
  return _coercedDate(ZodDate, params);
22825
22702
  }
22826
22703
 
22704
+ // ../shared/src/fieldValueShape.ts
22705
+ function enumOptions(type) {
22706
+ if (type.kind !== "union") return null;
22707
+ const values = [];
22708
+ for (const option of type.options) {
22709
+ if (option.kind !== "literal") return null;
22710
+ values.push(option.value);
22711
+ }
22712
+ return values;
22713
+ }
22714
+
22715
+ // ../shared/src/fieldTypeMeta.ts
22716
+ function leafOnly(_type) {
22717
+ }
22718
+ function fieldShape(type) {
22719
+ if (enumOptions(type)) return "enum";
22720
+ if (type.kind === "array" && type.element.kind === "id") return "idList";
22721
+ if (type.kind === "array" && hasKindTrait(type.element, "chipItem")) return "scalarList";
22722
+ return type.kind;
22723
+ }
22724
+ var SHAPE_TRAITS = {
22725
+ string: ["inline", "editable", "textScalar", "previewLabel", "chipItem"],
22726
+ markdown: ["editable", "previewLabel"],
22727
+ number: ["inline", "editable", "textScalar", "commitsOnChange", "previewLabel", "chipItem"],
22728
+ boolean: ["inline", "editable", "commitsOnChange"],
22729
+ bigint: ["inline", "editable", "textScalar", "previewLabel", "chipItem"],
22730
+ null: ["inline"],
22731
+ any: ["inline", "editable"],
22732
+ bytes: ["inline", "editable"],
22733
+ file: ["editable", "storage", "tallEditor"],
22734
+ image: ["editable", "storage", "tallEditor"],
22735
+ date: ["inline", "editable", "commitsOnChange", "previewLabel", "chipItem"],
22736
+ datetime: ["inline", "editable", "commitsOnChange", "previewLabel", "chipItem"],
22737
+ id: ["inline", "editable", "textScalar", "commitsOnChange"],
22738
+ literal: ["inline", "previewLabel"],
22739
+ array: ["editable", "tallEditor"],
22740
+ // Edited through a summary popover / variant picker, so edits commit as they happen.
22741
+ object: ["editable", "commitsOnChange"],
22742
+ union: ["editable", "commitsOnChange"],
22743
+ enum: ["inline", "editable", "commitsOnChange", "chipItem"],
22744
+ idList: ["editable", "commitsOnChange", "wrapsInline"],
22745
+ scalarList: ["editable", "wrapsInline"]
22746
+ };
22747
+ function hasKindTrait(type, trait) {
22748
+ return SHAPE_TRAITS[fieldShape(type)].includes(trait);
22749
+ }
22750
+
22827
22751
  // ../shared/src/queryFieldOps.ts
22828
22752
  var PREDICATE_VARIANTS = [
22829
22753
  {
@@ -22946,298 +22870,705 @@ var listMetaSchema = external_exports.object({
22946
22870
  truncated: external_exports.boolean().optional()
22947
22871
  });
22948
22872
 
22949
- // ../shared/src/richDoc.ts
22950
- var RICH_DOC_FORMAT = "blocknote";
22951
- var RICH_DOC_VERSION = 1;
22952
- var EMPTY_BLOCK_ID = "00000000-0000-4000-8000-000000000001";
22953
- function emptyParagraphBlock() {
22954
- return {
22955
- id: EMPTY_BLOCK_ID,
22956
- type: "paragraph",
22957
- props: {
22958
- backgroundColor: "default",
22959
- textColor: "default",
22960
- textAlignment: "left"
22961
- },
22962
- content: [],
22963
- children: []
22964
- };
22965
- }
22966
- var EMPTY_RICH_DOC = JSON.stringify({
22967
- format: RICH_DOC_FORMAT,
22968
- version: RICH_DOC_VERSION,
22969
- blocks: [emptyParagraphBlock()]
22873
+ // ../shared/src/apiProfile.ts
22874
+ var apiTableAccessSchema = external_exports.object({
22875
+ table: external_exports.string(),
22876
+ read: external_exports.boolean(),
22877
+ /** Push to enabled webhook outputs. Missing/undefined = false (opt-in). */
22878
+ sync: external_exports.boolean().optional(),
22879
+ /**
22880
+ * Authenticated Studio/CMS editor write access for this table.
22881
+ * Missing/undefined = false (opt-in). Independent of public API-token propose.
22882
+ */
22883
+ editorAccess: external_exports.boolean().optional(),
22884
+ propose: external_exports.object({
22885
+ ops: external_exports.object({ insert: external_exports.boolean(), update: external_exports.boolean(), delete: external_exports.boolean() }),
22886
+ allowedFields: external_exports.array(external_exports.string()).optional(),
22887
+ recordIds: external_exports.array(external_exports.string()).optional()
22888
+ }).optional(),
22889
+ autoAccept: external_exports.boolean().optional(),
22890
+ /**
22891
+ * Opaque row clamp: AND-merged with caller Query on Read API / guest lists.
22892
+ * Sync membership uses `rowQuery.predicates` only (order/search ignored; maxScanLimit ignored).
22893
+ */
22894
+ rowQuery: clampQuerySchema.optional(),
22895
+ /** Scan ceiling for Read/guest list plans; callers may only lower. Not applied to Sync/Resync. */
22896
+ maxScanLimit: external_exports.number().int().positive().optional(),
22897
+ /**
22898
+ * Media source scope for the fixed `columnus_assets` source. Omit for all
22899
+ * live Media; an empty list intentionally grants no Media assets.
22900
+ */
22901
+ assetProfiles: external_exports.array(external_exports.string().min(1)).max(100).optional(),
22902
+ /**
22903
+ * Media profiles an API token may attach to in-scope Media items
22904
+ * (`columnus_assets` only). Missing/empty = no token assignment.
22905
+ */
22906
+ assignProfiles: external_exports.array(external_exports.string().min(1)).max(100).optional(),
22907
+ /**
22908
+ * Create new Media assets (upload/import) on the fixed `columnus_assets`
22909
+ * source. Missing/undefined = false. Does not imply Read, deletion, same-id
22910
+ * replacement, metadata edits, or assigning existing assets.
22911
+ */
22912
+ write: external_exports.boolean().optional()
22913
+ });
22914
+ var apiProfileSnapshotSchema = external_exports.object({
22915
+ id: external_exports.string(),
22916
+ name: external_exports.string(),
22917
+ slug: external_exports.string(),
22918
+ tables: external_exports.array(external_exports.string()),
22919
+ tableAccess: external_exports.array(apiTableAccessSchema).optional(),
22920
+ autoAcceptProposals: external_exports.boolean().optional(),
22921
+ /** Hosted MCP endpoint for this profile. Missing/undefined = disabled (opt-in). */
22922
+ mcpEnabled: external_exports.boolean().optional(),
22923
+ apiVersion: external_exports.number(),
22924
+ updatedAt: external_exports.number()
22970
22925
  });
22926
+ var apiProfilesSchema = external_exports.array(apiProfileSnapshotSchema);
22927
+ function editorAccessEnabled(access2) {
22928
+ return access2.editorAccess === true;
22929
+ }
22930
+ var MEDIA_LIBRARY_JOURNAL_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
22971
22931
 
22972
- // ../shared/src/schemaTypes.ts
22973
- var IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
22974
- var RESERVED_TABLE_NAMES = /* @__PURE__ */ new Set([
22975
- "columnus_audit_log",
22976
- "columnus_spaces",
22977
- "columnus_manifest",
22978
- "columnus_display_values",
22979
- "columnus_api_profiles",
22980
- "columnus_api_tokens",
22981
- "columnus_api_outputs",
22982
- "columnus_api_output_secrets",
22983
- "columnus_api_sync_routes",
22984
- "columnus_api_outbox",
22985
- "columnus_api_delivery",
22986
- "columnus_assets",
22987
- "columnus_asset_versions",
22988
- "columnus_asset_refs",
22989
- "columnus_asset_profiles",
22990
- "columnus_asset_settings",
22991
- "columnus_asset_jobs"
22992
- ]);
22993
- var displayTemplatesSchema = external_exports.object({
22994
- id: external_exports.string().optional(),
22995
- preview: external_exports.string().optional()
22996
- });
22997
- var TABLE_COLORS = [
22998
- "brown",
22999
- "muted-red",
23000
- "red",
23001
- "coral",
23002
- "orange",
23003
- "amber",
23004
- "yellow",
23005
- "gold",
23006
- "blue",
23007
- "light-blue",
23008
- "cyan",
23009
- "mint",
23010
- "green",
23011
- "dark-green",
23012
- "lime",
23013
- "light-green",
23014
- "charcoal",
23015
- "gray",
23016
- "mauve",
23017
- "pink",
23018
- "purple",
23019
- "deep-purple",
23020
- "periwinkle",
23021
- "lavender"
23022
- ];
23023
- var tableColorSchema = external_exports.enum(TABLE_COLORS);
23024
- var TABLE_KINDS = ["record", "asset"];
23025
- var tableKindSchema = external_exports.enum(TABLE_KINDS);
23026
- var assetBindingSchema = external_exports.object({
23027
- profile: external_exports.string().min(1),
23028
- enforced: external_exports.boolean().optional()
23029
- });
23030
- var fieldTypeSchema = external_exports.lazy(
23031
- () => external_exports.discriminatedUnion("kind", [
23032
- external_exports.object({ kind: external_exports.literal("string") }),
23033
- external_exports.object({ kind: external_exports.literal("markdown") }),
23034
- external_exports.object({ kind: external_exports.literal("number") }),
23035
- external_exports.object({ kind: external_exports.literal("boolean") }),
23036
- external_exports.object({ kind: external_exports.literal("bigint") }),
23037
- external_exports.object({ kind: external_exports.literal("null") }),
23038
- external_exports.object({ kind: external_exports.literal("any") }),
23039
- external_exports.object({ kind: external_exports.literal("bytes") }),
23040
- external_exports.object({ kind: external_exports.literal("file") }),
23041
- external_exports.object({ kind: external_exports.literal("image") }),
23042
- external_exports.object({ kind: external_exports.literal("date") }),
23043
- external_exports.object({ kind: external_exports.literal("datetime") }),
23044
- external_exports.object({ kind: external_exports.literal("id"), table: external_exports.string().regex(IDENT) }),
23045
- external_exports.object({
23046
- kind: external_exports.literal("literal"),
23047
- value: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()])
23048
- }),
23049
- external_exports.object({ kind: external_exports.literal("array"), element: fieldTypeSchema }),
23050
- external_exports.object({
23051
- kind: external_exports.literal("object"),
23052
- fields: external_exports.array(
23053
- external_exports.object({
23054
- name: external_exports.string().regex(IDENT),
23055
- label: external_exports.string().optional(),
23056
- type: fieldTypeSchema,
23057
- optional: external_exports.boolean(),
23058
- /** Nested image/file placements bind a Media profile like top-level ones. */
23059
- asset: assetBindingSchema.optional()
23060
- })
23061
- )
23062
- }),
23063
- external_exports.object({
23064
- kind: external_exports.literal("union"),
23065
- options: external_exports.array(fieldTypeSchema).min(2)
23066
- })
23067
- ])
23068
- );
23069
- var fieldSchema = external_exports.object({
23070
- name: external_exports.string().regex(IDENT, "must be a valid identifier"),
23071
- label: external_exports.string().optional(),
23072
- type: fieldTypeSchema,
23073
- optional: external_exports.boolean(),
23074
- /** Image/file fields may pin a Media profile; existence is enforced at upload/pick. */
23075
- asset: assetBindingSchema.optional()
23076
- });
23077
- var indexSchema = external_exports.object({
23078
- name: external_exports.string().regex(IDENT),
23079
- fields: external_exports.array(external_exports.string().regex(IDENT)).min(1)
23080
- });
23081
- var searchIndexSchema = external_exports.object({
23082
- name: external_exports.string().regex(IDENT),
23083
- searchField: external_exports.string().regex(IDENT),
23084
- filterFields: external_exports.array(external_exports.string().regex(IDENT)).optional()
23085
- });
23086
- var tableSchema = external_exports.object({
23087
- name: external_exports.string().regex(IDENT).refine((n) => !RESERVED_TABLE_NAMES.has(n), {
23088
- message: "table name is reserved by the studio"
23089
- }),
23090
- label: external_exports.string().optional(),
23091
- color: tableColorSchema.optional(),
23092
- /** Asset metadata tables are typed root tables but never ordinary user records. */
23093
- kind: tableKindSchema.optional().default("record"),
23094
- fields: external_exports.array(fieldSchema),
23095
- indexes: external_exports.array(indexSchema).default([]),
23096
- searchIndexes: external_exports.array(searchIndexSchema).default([]),
23097
- displayTemplates: displayTemplatesSchema.optional()
23098
- });
23099
- var manifestSchema = external_exports.object({
23100
- tables: external_exports.array(tableSchema)
23101
- }).superRefine((manifest, ctx) => {
23102
- const tableNames = /* @__PURE__ */ new Set();
23103
- const tablesByName = /* @__PURE__ */ new Map();
23104
- for (const t of manifest.tables) {
23105
- if (tableNames.has(t.name)) {
23106
- ctx.addIssue({
23107
- code: external_exports.ZodIssueCode.custom,
23108
- message: `duplicate table: ${t.name}`,
23109
- path: ["tables"]
23110
- });
23111
- }
23112
- tableNames.add(t.name);
23113
- tablesByName.set(t.name, t);
23114
- if (tableKind(t) === "asset") {
23115
- if (t.indexes.length > 0) {
23116
- ctx.addIssue({
23117
- code: external_exports.ZodIssueCode.custom,
23118
- message: `${t.name} is an asset metadata table and cannot define indexes`,
23119
- path: ["tables"]
23120
- });
23121
- }
23122
- if (t.searchIndexes.length > 0) {
23123
- ctx.addIssue({
23124
- code: external_exports.ZodIssueCode.custom,
23125
- message: `${t.name} is an asset metadata table and cannot define search indexes`,
23126
- path: ["tables"]
23127
- });
23128
- }
23129
- if (t.displayTemplates !== void 0) {
23130
- ctx.addIssue({
23131
- code: external_exports.ZodIssueCode.custom,
23132
- message: `${t.name} is an asset metadata table and cannot define display templates`,
23133
- path: ["tables"]
23134
- });
23135
- }
23136
- if (t.color !== void 0) {
23137
- ctx.addIssue({
23138
- code: external_exports.ZodIssueCode.custom,
23139
- message: `${t.name} is an asset metadata table and cannot define a color`,
23140
- path: ["tables"]
23141
- });
23142
- }
23143
- }
23144
- const fieldNames = /* @__PURE__ */ new Set();
23145
- for (const f of t.fields) {
23146
- if (fieldNames.has(f.name)) {
23147
- ctx.addIssue({
23148
- code: external_exports.ZodIssueCode.custom,
23149
- message: `duplicate field in ${t.name}: ${f.name}`,
23150
- path: ["tables"]
23151
- });
23152
- }
23153
- fieldNames.add(f.name);
23154
- assertAssetBindingAllowed(ctx, t, f);
23155
- }
23156
- }
23157
- for (const t of manifest.tables) {
23158
- for (const f of t.fields) {
23159
- const invalidRef = findInvalidReference(f, tablesByName);
23160
- if (invalidRef) {
23161
- ctx.addIssue({
23162
- code: external_exports.ZodIssueCode.custom,
23163
- message: `${t.name}.${f.name} ${invalidRef}`,
23164
- path: ["tables"]
23165
- });
23166
- }
23167
- }
23168
- }
23169
- });
23170
- function findInvalidReference(field, tablesByName) {
23171
- for (const { targetTable } of refEdges({ fields: [field] })) {
23172
- const target = tablesByName.get(targetTable);
23173
- if (!target) return `references unknown table: ${targetTable}`;
23174
- if (tableKind(target) === "asset") {
23175
- return `cannot reference asset metadata table: ${targetTable}`;
23176
- }
23177
- }
23178
- return null;
23179
- }
23180
- function tableKind(table) {
23181
- return table.kind ?? "record";
23182
- }
23183
- function isAssetTable(table) {
23184
- return tableKind(table) === "asset";
23185
- }
23186
- function mediaKind(t) {
23187
- const leaf = t.kind === "array" ? t.element : t;
23188
- return leaf.kind === "file" || leaf.kind === "image" ? leaf.kind : null;
23189
- }
23190
- function isStorageFieldType(t) {
23191
- return mediaKind(t) !== null;
22932
+ // ../shared/src/refGraph.ts
22933
+ function isLeaf(type, leaf) {
22934
+ return leaf === "document" ? type.kind === "id" : hasKindTrait(type, "storage");
23192
22935
  }
23193
- function assertAssetBindingAllowed(ctx, table, field) {
23194
- if (field.asset && tableKind(table) === "asset") {
23195
- ctx.addIssue({
23196
- code: external_exports.ZodIssueCode.custom,
23197
- message: `${table.name}.${field.name} asset metadata fields cannot define a Media profile`,
23198
- path: ["tables"]
23199
- });
23200
- } else if (field.asset && !isStorageFieldType(field.type)) {
23201
- ctx.addIssue({
23202
- code: external_exports.ZodIssueCode.custom,
23203
- message: `${table.name}.${field.name} asset profile can only be set on image/file fields`,
23204
- path: ["tables"]
23205
- });
22936
+ function typeLeaves(type, leaf, at, out) {
22937
+ if (isLeaf(type, leaf)) {
22938
+ out.push({ type, ...at });
22939
+ return out;
23206
22940
  }
23207
- assertAssetBindingsInType(ctx, table, field.type);
23208
- }
23209
- function assertAssetBindingsInType(ctx, table, type) {
23210
22941
  switch (type.kind) {
23211
22942
  case "array":
23212
- assertAssetBindingsInType(ctx, table, type.element);
22943
+ typeLeaves(type.element, leaf, { ...at, path: `${at.path}[]`, many: true }, out);
23213
22944
  break;
23214
22945
  case "object":
23215
- for (const f of type.fields) assertAssetBindingAllowed(ctx, table, f);
22946
+ for (const f of type.fields) {
22947
+ const path5 = `${at.path}.${f.name}`;
22948
+ typeLeaves(f.type, leaf, { ...at, path: path5, depth: at.depth + 1, binding: f.asset }, out);
22949
+ }
23216
22950
  break;
23217
22951
  case "union":
23218
- for (const o of type.options) assertAssetBindingsInType(ctx, table, o);
22952
+ for (const option of type.options)
22953
+ typeLeaves(option, leaf, { ...at, depth: at.depth + 1 }, out);
23219
22954
  break;
23220
22955
  default:
23221
22956
  leafOnly(type);
23222
22957
  }
22958
+ return out;
23223
22959
  }
23224
-
23225
- // ../shared/src/fieldTypeText.ts
23226
- function foldFieldType(type, fold) {
23227
- switch (type.kind) {
23228
- case "array":
23229
- return fold.array(foldFieldType(type.element, fold), type);
23230
- case "object":
23231
- return fold.object(
23232
- type.fields.map((field) => ({ field, value: foldFieldType(field.type, fold) })),
23233
- type
23234
- );
23235
- case "union":
23236
- return fold.union(
23237
- type.options.map((option) => foldFieldType(option, fold)),
23238
- type
23239
- );
23240
- default:
22960
+ var ROOT = { path: "", depth: 0, many: false, binding: void 0 };
22961
+ function compareEdges(a, b) {
22962
+ return a.field.localeCompare(b.field) || a.path.localeCompare(b.path) || a.targetTable.localeCompare(b.targetTable);
22963
+ }
22964
+ function fieldEdges(field) {
22965
+ return typeLeaves(field.type, "document", ROOT, []).map(({ type, path: path5, depth, many }) => ({
22966
+ field: field.name,
22967
+ path: path5,
22968
+ targetTable: type.table,
22969
+ many,
22970
+ depth
22971
+ }));
22972
+ }
22973
+ function refEdges(table) {
22974
+ const seen = /* @__PURE__ */ new Set();
22975
+ const edges = [];
22976
+ for (const field of table.fields) {
22977
+ for (const edge of fieldEdges(field)) {
22978
+ const key = `${edge.field}\0${edge.path}\0${edge.targetTable}`;
22979
+ if (seen.has(key)) continue;
22980
+ seen.add(key);
22981
+ edges.push(edge);
22982
+ }
22983
+ }
22984
+ return edges.sort(compareEdges);
22985
+ }
22986
+
22987
+ // ../shared/src/dataTransfer.ts
22988
+ var COLUMNUS_DATA_TRANSFER_VERSION = 1;
22989
+ var MAX_TRANSFER_BYTES = 50 * 1024 * 1024;
22990
+ function isProtectedTransferTable(table) {
22991
+ return table.startsWith("_") || table.startsWith("columnus_") || table.startsWith("studio_");
22992
+ }
22993
+
22994
+ // ../shared/src/bffProtocol.ts
22995
+ var COLUMNUS_BFF_PROTOCOL_VERSION = 1;
22996
+ var COLUMNUS_BFF_API_PREFIX = "/api/columnus/v1";
22997
+ var OPERATION_ID_RE = /^[A-Za-z0-9_-]{16,128}$/;
22998
+ var TRANSFER_ID_RE = /^[A-Za-z0-9_-]{16,64}$/;
22999
+ var MANIFEST_HASH_RE = /^[0-9a-f]{64}$/;
23000
+ var TABLE_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
23001
+ var operationIdSchema = external_exports.string().regex(OPERATION_ID_RE);
23002
+ var transferIdSchema = external_exports.string().regex(TRANSFER_ID_RE);
23003
+ var manifestHashSchema = external_exports.string().regex(MANIFEST_HASH_RE);
23004
+ var bffPrepareOperationTypeSchema = external_exports.enum([
23005
+ "schemaDeploy",
23006
+ "dataExport",
23007
+ "dataImportPrepare",
23008
+ "dataImportCommit"
23009
+ ]);
23010
+ var transferOperationSchema = external_exports.enum(["export", "import"]);
23011
+ var transferSessionStateSchema = external_exports.enum([
23012
+ "exportReady",
23013
+ "importAwaitingUpload",
23014
+ "importUploaded",
23015
+ "importCommitted",
23016
+ "importFailed",
23017
+ "expired"
23018
+ ]);
23019
+ var schemaDeployPhaseSchema = external_exports.enum([
23020
+ "cleaning",
23021
+ "ready",
23022
+ "deploying",
23023
+ "succeeded",
23024
+ "failed"
23025
+ ]);
23026
+ var SCHEMA_DEPLOY_OPERATION_LEASE_MS = 20 * 60 * 1e3;
23027
+ var transferTableSchema = external_exports.string().regex(TABLE_NAME_RE).refine((name) => !isProtectedTransferTable(name), {
23028
+ message: "Protected table cannot be transferred"
23029
+ });
23030
+ var dataTransferManifestSchema = external_exports.object({
23031
+ version: external_exports.literal(COLUMNUS_DATA_TRANSFER_VERSION),
23032
+ tables: external_exports.array(transferTableSchema).min(1),
23033
+ schemaHash: manifestHashSchema,
23034
+ includeFileStorage: external_exports.boolean()
23035
+ }).superRefine((value, ctx) => {
23036
+ if (new Set(value.tables).size !== value.tables.length) {
23037
+ ctx.addIssue({
23038
+ code: external_exports.ZodIssueCode.custom,
23039
+ message: "dataTransfer.tables must not contain duplicates",
23040
+ path: ["tables"]
23041
+ });
23042
+ }
23043
+ });
23044
+ var bffSchemaDeployRequestSchema = external_exports.object({
23045
+ operationId: operationIdSchema,
23046
+ manifestJson: external_exports.string().min(2).max(2e6)
23047
+ });
23048
+ var bffTransferScopeRequestSchema = external_exports.object({
23049
+ operationId: operationIdSchema,
23050
+ tables: external_exports.array(transferTableSchema).min(1),
23051
+ schemaHash: manifestHashSchema,
23052
+ includeFileStorage: external_exports.boolean()
23053
+ });
23054
+ var bffTransferCommitRequestSchema = external_exports.object({
23055
+ operationId: operationIdSchema,
23056
+ /** Client echo; server also rechecks the transfer-bound hash. */
23057
+ schemaHash: manifestHashSchema
23058
+ });
23059
+ var bffHealthResponseSchema = external_exports.object({
23060
+ ok: external_exports.boolean(),
23061
+ commit: external_exports.string(),
23062
+ executor: external_exports.object({
23063
+ ok: external_exports.boolean(),
23064
+ commit: external_exports.string().optional(),
23065
+ error: external_exports.string().optional()
23066
+ })
23067
+ });
23068
+ var bffActiveOperationMetaSchema = external_exports.object({
23069
+ operationId: operationIdSchema,
23070
+ desiredManifestHash: manifestHashSchema.optional(),
23071
+ phase: schemaDeployPhaseSchema.optional(),
23072
+ startedAt: external_exports.number().optional()
23073
+ });
23074
+ var bffSchemaDeployResponseSchema = external_exports.object({
23075
+ ok: external_exports.boolean(),
23076
+ operationId: operationIdSchema,
23077
+ phase: schemaDeployPhaseSchema,
23078
+ desiredManifestHash: manifestHashSchema.optional(),
23079
+ deployedManifestHash: manifestHashSchema.optional(),
23080
+ error: external_exports.string().optional(),
23081
+ logTail: external_exports.string().optional(),
23082
+ activeOperation: bffActiveOperationMetaSchema.optional()
23083
+ });
23084
+ var bffTransferCreateResponseSchema = external_exports.object({
23085
+ ok: external_exports.literal(true),
23086
+ transferId: transferIdSchema,
23087
+ expiresAt: external_exports.number().int().positive(),
23088
+ bytes: external_exports.number().int().nonnegative().optional()
23089
+ });
23090
+ var bffTransferCommitResponseSchema = external_exports.object({
23091
+ ok: external_exports.boolean(),
23092
+ transferId: transferIdSchema,
23093
+ error: external_exports.string().optional(),
23094
+ logTail: external_exports.string().optional()
23095
+ });
23096
+ var bffTransferUploadResponseSchema = external_exports.object({
23097
+ ok: external_exports.literal(true),
23098
+ bytes: external_exports.number().int().nonnegative()
23099
+ });
23100
+ var bffErrorCodeSchema = external_exports.enum([
23101
+ "unauthorized",
23102
+ "forbidden",
23103
+ "unknown_host",
23104
+ "disabled_host",
23105
+ "conflict",
23106
+ "executor_mismatch",
23107
+ "executor_unavailable",
23108
+ "validation_error",
23109
+ "not_found",
23110
+ "payload_too_large",
23111
+ "gone",
23112
+ "internal_error"
23113
+ ]);
23114
+ var bffErrorResponseSchema = external_exports.object({
23115
+ ok: external_exports.literal(false),
23116
+ error: external_exports.string(),
23117
+ code: bffErrorCodeSchema.optional(),
23118
+ logTail: external_exports.string().optional(),
23119
+ activeOperation: bffActiveOperationMetaSchema.optional()
23120
+ });
23121
+ var bffPrepareOperationSchema = external_exports.discriminatedUnion("type", [
23122
+ external_exports.object({
23123
+ type: external_exports.literal("schemaDeploy"),
23124
+ operationId: operationIdSchema,
23125
+ manifestJson: external_exports.string().min(2).max(2e6)
23126
+ }),
23127
+ external_exports.object({
23128
+ type: external_exports.literal("dataExport"),
23129
+ operationId: operationIdSchema,
23130
+ transferManifest: dataTransferManifestSchema
23131
+ }),
23132
+ external_exports.object({
23133
+ type: external_exports.literal("dataImportPrepare"),
23134
+ operationId: operationIdSchema,
23135
+ transferManifest: dataTransferManifestSchema
23136
+ }),
23137
+ external_exports.object({
23138
+ type: external_exports.literal("dataImportCommit"),
23139
+ operationId: operationIdSchema,
23140
+ transferId: transferIdSchema,
23141
+ schemaHash: manifestHashSchema
23142
+ })
23143
+ ]);
23144
+ var bffPrepareRequestSchema = external_exports.object({
23145
+ protocolVersion: external_exports.literal(COLUMNUS_BFF_PROTOCOL_VERSION),
23146
+ /** Trusted hostname only (already extracted by BFF). */
23147
+ host: external_exports.string().min(1),
23148
+ correlationId: external_exports.string().min(1).max(128).optional(),
23149
+ operation: bffPrepareOperationSchema
23150
+ });
23151
+ var bffPreparedTenantSchema = external_exports.object({
23152
+ slug: external_exports.string().min(1),
23153
+ convexUrl: external_exports.string().url(),
23154
+ authIssuer: external_exports.string().url().optional(),
23155
+ deploymentName: external_exports.string().optional()
23156
+ });
23157
+ var deployInternalSchemaDeployPayloadSchema = external_exports.object({
23158
+ manifestJson: external_exports.string().min(2),
23159
+ convexDeployKey: external_exports.string().min(1),
23160
+ convexUrl: external_exports.string().url(),
23161
+ authIssuer: external_exports.string().url().optional(),
23162
+ previewName: external_exports.string().nullable().optional(),
23163
+ operationId: operationIdSchema.optional()
23164
+ });
23165
+ var deployInternalTransferExportPayloadSchema = external_exports.object({
23166
+ transferManifest: dataTransferManifestSchema,
23167
+ convexDeployKey: external_exports.string().min(1),
23168
+ convexUrl: external_exports.string().url(),
23169
+ tenantSlug: external_exports.string().min(1),
23170
+ operationId: operationIdSchema
23171
+ });
23172
+ var deployInternalTransferImportPreparePayloadSchema = external_exports.object({
23173
+ transferManifest: dataTransferManifestSchema,
23174
+ convexDeployKey: external_exports.string().min(1),
23175
+ convexUrl: external_exports.string().url(),
23176
+ tenantSlug: external_exports.string().min(1),
23177
+ operationId: operationIdSchema
23178
+ });
23179
+ var deployInternalTransferCommitPayloadSchema = external_exports.object({
23180
+ transferId: transferIdSchema,
23181
+ convexDeployKey: external_exports.string().min(1),
23182
+ convexUrl: external_exports.string().url(),
23183
+ tenantSlug: external_exports.string().min(1),
23184
+ operationId: operationIdSchema,
23185
+ schemaHash: manifestHashSchema
23186
+ });
23187
+ var bffPreparedBodyEnvelopeBaseSchema = external_exports.object({
23188
+ protocolVersion: external_exports.literal(COLUMNUS_BFF_PROTOCOL_VERSION),
23189
+ tenant: bffPreparedTenantSchema,
23190
+ correlationId: external_exports.string().min(1).max(128).optional()
23191
+ });
23192
+ var bffPreparedBodyEnvelopeSchema = external_exports.discriminatedUnion("operation", [
23193
+ bffPreparedBodyEnvelopeBaseSchema.extend({
23194
+ operation: external_exports.literal("schemaDeploy"),
23195
+ payload: deployInternalSchemaDeployPayloadSchema
23196
+ }),
23197
+ bffPreparedBodyEnvelopeBaseSchema.extend({
23198
+ operation: external_exports.literal("dataExport"),
23199
+ payload: deployInternalTransferExportPayloadSchema
23200
+ }),
23201
+ bffPreparedBodyEnvelopeBaseSchema.extend({
23202
+ operation: external_exports.literal("dataImportPrepare"),
23203
+ payload: deployInternalTransferImportPreparePayloadSchema
23204
+ }),
23205
+ bffPreparedBodyEnvelopeBaseSchema.extend({
23206
+ operation: external_exports.literal("dataImportCommit"),
23207
+ payload: deployInternalTransferCommitPayloadSchema
23208
+ })
23209
+ ]);
23210
+ var bffPreviewRegisterRequestSchema = external_exports.object({
23211
+ hostname: external_exports.string().min(1),
23212
+ convexUrl: external_exports.string().url(),
23213
+ deployKey: external_exports.string().min(1),
23214
+ expectedCommit: external_exports.string().min(7).max(64),
23215
+ expiresAt: external_exports.number().int().positive()
23216
+ });
23217
+ var bffPreviewRemoveRequestSchema = external_exports.object({
23218
+ hostname: external_exports.string().min(1)
23219
+ });
23220
+ var transferSessionRecordSchema = external_exports.object({
23221
+ transferId: transferIdSchema,
23222
+ tenantSlug: external_exports.string().min(1),
23223
+ convexUrl: external_exports.string().url(),
23224
+ operation: transferOperationSchema,
23225
+ tables: external_exports.array(transferTableSchema).min(1),
23226
+ schemaHash: manifestHashSchema,
23227
+ includeFileStorage: external_exports.boolean(),
23228
+ maxBytes: external_exports.number().int().positive().max(MAX_TRANSFER_BYTES),
23229
+ expiresAt: external_exports.number().int().positive(),
23230
+ state: transferSessionStateSchema,
23231
+ operationId: operationIdSchema.optional(),
23232
+ bytes: external_exports.number().int().nonnegative().optional(),
23233
+ commitResult: external_exports.object({
23234
+ ok: external_exports.boolean(),
23235
+ error: external_exports.string().optional(),
23236
+ logTail: external_exports.string().optional()
23237
+ }).optional()
23238
+ });
23239
+ var deployInternalTransferCreateResponseSchema = external_exports.object({
23240
+ ok: external_exports.literal(true),
23241
+ transferId: transferIdSchema,
23242
+ expiresAt: external_exports.number().int().positive(),
23243
+ bytes: external_exports.number().int().nonnegative().optional()
23244
+ });
23245
+ var deployInternalSchemaDeployResponseSchema = external_exports.object({
23246
+ ok: external_exports.boolean(),
23247
+ durationMs: external_exports.number(),
23248
+ prepareMs: external_exports.number().optional(),
23249
+ cliMs: external_exports.number().optional(),
23250
+ kernelCommit: external_exports.string().optional(),
23251
+ error: external_exports.string().optional(),
23252
+ logTail: external_exports.string().optional()
23253
+ });
23254
+ var deployHealthResponseSchema = external_exports.object({
23255
+ ok: external_exports.boolean(),
23256
+ commit: external_exports.string().optional(),
23257
+ /** ISO-8601 Coolify/image bake time (BRU-76 preview supersede). */
23258
+ deployedAt: external_exports.string().optional()
23259
+ });
23260
+ var BFF_JSON_BODY_LIMIT_BYTES = 2 * 1024 * 1024;
23261
+
23262
+ // ../shared/src/apiProfileSlug.ts
23263
+ function apiProfileSlugToConvexModuleSegment(slug) {
23264
+ return slug.replace(/-/g, "_");
23265
+ }
23266
+
23267
+ // ../shared/src/mcpOAuth.ts
23268
+ var MINUTE = 6e4;
23269
+ var MCP_OAUTH_REQUEST_TTL_MS = 10 * MINUTE;
23270
+ var MCP_OAUTH_CODE_TTL_MS = 10 * MINUTE;
23271
+ var MCP_OAUTH_ACCESS_TOKEN_TTL_MS = 60 * MINUTE;
23272
+ var MCP_OAUTH_REFRESH_TOKEN_TTL_MS = 30 * 24 * 60 * MINUTE;
23273
+ var MCP_OAUTH_UNUSED_CLIENT_TTL_MS = 7 * 24 * 60 * MINUTE;
23274
+ var MCP_ENDPOINT_PATH_PREFIX = `${COLUMNUS_BFF_API_PREFIX}/mcp/`;
23275
+ var MCP_OAUTH_PATH_PREFIX = `${COLUMNUS_BFF_API_PREFIX}/oauth`;
23276
+
23277
+ // ../shared/src/queryPlan.ts
23278
+ import { compareValues } from "convex/values";
23279
+
23280
+ // ../shared/src/richDoc.ts
23281
+ var RICH_DOC_FORMAT = "blocknote";
23282
+ var RICH_DOC_VERSION = 1;
23283
+ var EMPTY_BLOCK_ID = "00000000-0000-4000-8000-000000000001";
23284
+ function emptyParagraphBlock() {
23285
+ return {
23286
+ id: EMPTY_BLOCK_ID,
23287
+ type: "paragraph",
23288
+ props: {
23289
+ backgroundColor: "default",
23290
+ textColor: "default",
23291
+ textAlignment: "left"
23292
+ },
23293
+ content: [],
23294
+ children: []
23295
+ };
23296
+ }
23297
+ var EMPTY_RICH_DOC = JSON.stringify({
23298
+ format: RICH_DOC_FORMAT,
23299
+ version: RICH_DOC_VERSION,
23300
+ blocks: [emptyParagraphBlock()]
23301
+ });
23302
+
23303
+ // ../shared/src/schemaTypes.ts
23304
+ var IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
23305
+ var RESERVED_TABLE_NAMES = /* @__PURE__ */ new Set([
23306
+ "columnus_audit_log",
23307
+ "columnus_spaces",
23308
+ "columnus_manifest",
23309
+ "columnus_display_values",
23310
+ "columnus_api_profiles",
23311
+ "columnus_api_tokens",
23312
+ "columnus_api_outputs",
23313
+ "columnus_api_output_secrets",
23314
+ "columnus_api_sync_routes",
23315
+ "columnus_api_outbox",
23316
+ "columnus_api_delivery",
23317
+ "columnus_assets",
23318
+ "columnus_asset_versions",
23319
+ "columnus_asset_refs",
23320
+ "columnus_asset_profiles",
23321
+ "columnus_asset_settings",
23322
+ "columnus_asset_jobs"
23323
+ ]);
23324
+ var displayTemplatesSchema = external_exports.object({
23325
+ id: external_exports.string().optional(),
23326
+ preview: external_exports.string().optional()
23327
+ });
23328
+ var TABLE_COLORS = [
23329
+ "brown",
23330
+ "muted-red",
23331
+ "red",
23332
+ "coral",
23333
+ "orange",
23334
+ "amber",
23335
+ "yellow",
23336
+ "gold",
23337
+ "blue",
23338
+ "light-blue",
23339
+ "cyan",
23340
+ "mint",
23341
+ "green",
23342
+ "dark-green",
23343
+ "lime",
23344
+ "light-green",
23345
+ "charcoal",
23346
+ "gray",
23347
+ "mauve",
23348
+ "pink",
23349
+ "purple",
23350
+ "deep-purple",
23351
+ "periwinkle",
23352
+ "lavender"
23353
+ ];
23354
+ var tableColorSchema = external_exports.enum(TABLE_COLORS);
23355
+ var TABLE_KINDS = ["record", "asset"];
23356
+ var tableKindSchema = external_exports.enum(TABLE_KINDS);
23357
+ var assetBindingSchema = external_exports.object({
23358
+ profile: external_exports.string().min(1),
23359
+ enforced: external_exports.boolean().optional()
23360
+ });
23361
+ var fieldTypeSchema = external_exports.lazy(
23362
+ () => external_exports.discriminatedUnion("kind", [
23363
+ external_exports.object({ kind: external_exports.literal("string") }),
23364
+ external_exports.object({ kind: external_exports.literal("markdown") }),
23365
+ external_exports.object({ kind: external_exports.literal("number") }),
23366
+ external_exports.object({ kind: external_exports.literal("boolean") }),
23367
+ external_exports.object({ kind: external_exports.literal("bigint") }),
23368
+ external_exports.object({ kind: external_exports.literal("null") }),
23369
+ external_exports.object({ kind: external_exports.literal("any") }),
23370
+ external_exports.object({ kind: external_exports.literal("bytes") }),
23371
+ external_exports.object({ kind: external_exports.literal("file") }),
23372
+ external_exports.object({ kind: external_exports.literal("image") }),
23373
+ external_exports.object({ kind: external_exports.literal("date") }),
23374
+ external_exports.object({ kind: external_exports.literal("datetime") }),
23375
+ external_exports.object({ kind: external_exports.literal("id"), table: external_exports.string().regex(IDENT) }),
23376
+ external_exports.object({
23377
+ kind: external_exports.literal("literal"),
23378
+ value: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()])
23379
+ }),
23380
+ external_exports.object({ kind: external_exports.literal("array"), element: fieldTypeSchema }),
23381
+ external_exports.object({
23382
+ kind: external_exports.literal("object"),
23383
+ fields: external_exports.array(
23384
+ external_exports.object({
23385
+ name: external_exports.string().regex(IDENT),
23386
+ label: external_exports.string().optional(),
23387
+ type: fieldTypeSchema,
23388
+ optional: external_exports.boolean(),
23389
+ /** Nested image/file placements bind a Media profile like top-level ones. */
23390
+ asset: assetBindingSchema.optional()
23391
+ })
23392
+ )
23393
+ }),
23394
+ external_exports.object({
23395
+ kind: external_exports.literal("union"),
23396
+ options: external_exports.array(fieldTypeSchema).min(2)
23397
+ })
23398
+ ])
23399
+ );
23400
+ var fieldSchema = external_exports.object({
23401
+ name: external_exports.string().regex(IDENT, "must be a valid identifier"),
23402
+ label: external_exports.string().optional(),
23403
+ type: fieldTypeSchema,
23404
+ optional: external_exports.boolean(),
23405
+ /** Image/file fields may pin a Media profile; existence is enforced at upload/pick. */
23406
+ asset: assetBindingSchema.optional()
23407
+ });
23408
+ var indexSchema = external_exports.object({
23409
+ name: external_exports.string().regex(IDENT),
23410
+ fields: external_exports.array(external_exports.string().regex(IDENT)).min(1)
23411
+ });
23412
+ var searchIndexSchema = external_exports.object({
23413
+ name: external_exports.string().regex(IDENT),
23414
+ searchField: external_exports.string().regex(IDENT),
23415
+ filterFields: external_exports.array(external_exports.string().regex(IDENT)).optional()
23416
+ });
23417
+ var tableSchema = external_exports.object({
23418
+ name: external_exports.string().regex(IDENT).refine((n) => !RESERVED_TABLE_NAMES.has(n), {
23419
+ message: "table name is reserved by the studio"
23420
+ }),
23421
+ label: external_exports.string().optional(),
23422
+ color: tableColorSchema.optional(),
23423
+ /** Asset metadata tables are typed root tables but never ordinary user records. */
23424
+ kind: tableKindSchema.optional().default("record"),
23425
+ fields: external_exports.array(fieldSchema),
23426
+ indexes: external_exports.array(indexSchema).default([]),
23427
+ searchIndexes: external_exports.array(searchIndexSchema).default([]),
23428
+ displayTemplates: displayTemplatesSchema.optional()
23429
+ });
23430
+ var manifestSchema = external_exports.object({
23431
+ tables: external_exports.array(tableSchema)
23432
+ }).superRefine((manifest, ctx) => {
23433
+ const tableNames = /* @__PURE__ */ new Set();
23434
+ const tablesByName = /* @__PURE__ */ new Map();
23435
+ for (const t of manifest.tables) {
23436
+ if (tableNames.has(t.name)) {
23437
+ ctx.addIssue({
23438
+ code: external_exports.ZodIssueCode.custom,
23439
+ message: `duplicate table: ${t.name}`,
23440
+ path: ["tables"]
23441
+ });
23442
+ }
23443
+ tableNames.add(t.name);
23444
+ tablesByName.set(t.name, t);
23445
+ if (tableKind(t) === "asset") {
23446
+ if (t.indexes.length > 0) {
23447
+ ctx.addIssue({
23448
+ code: external_exports.ZodIssueCode.custom,
23449
+ message: `${t.name} is an asset metadata table and cannot define indexes`,
23450
+ path: ["tables"]
23451
+ });
23452
+ }
23453
+ if (t.searchIndexes.length > 0) {
23454
+ ctx.addIssue({
23455
+ code: external_exports.ZodIssueCode.custom,
23456
+ message: `${t.name} is an asset metadata table and cannot define search indexes`,
23457
+ path: ["tables"]
23458
+ });
23459
+ }
23460
+ if (t.displayTemplates !== void 0) {
23461
+ ctx.addIssue({
23462
+ code: external_exports.ZodIssueCode.custom,
23463
+ message: `${t.name} is an asset metadata table and cannot define display templates`,
23464
+ path: ["tables"]
23465
+ });
23466
+ }
23467
+ if (t.color !== void 0) {
23468
+ ctx.addIssue({
23469
+ code: external_exports.ZodIssueCode.custom,
23470
+ message: `${t.name} is an asset metadata table and cannot define a color`,
23471
+ path: ["tables"]
23472
+ });
23473
+ }
23474
+ }
23475
+ const fieldNames = /* @__PURE__ */ new Set();
23476
+ for (const f of t.fields) {
23477
+ if (fieldNames.has(f.name)) {
23478
+ ctx.addIssue({
23479
+ code: external_exports.ZodIssueCode.custom,
23480
+ message: `duplicate field in ${t.name}: ${f.name}`,
23481
+ path: ["tables"]
23482
+ });
23483
+ }
23484
+ fieldNames.add(f.name);
23485
+ assertAssetBindingAllowed(ctx, t, f);
23486
+ }
23487
+ }
23488
+ for (const t of manifest.tables) {
23489
+ for (const f of t.fields) {
23490
+ const invalidRef = findInvalidReference(f, tablesByName);
23491
+ if (invalidRef) {
23492
+ ctx.addIssue({
23493
+ code: external_exports.ZodIssueCode.custom,
23494
+ message: `${t.name}.${f.name} ${invalidRef}`,
23495
+ path: ["tables"]
23496
+ });
23497
+ }
23498
+ }
23499
+ }
23500
+ });
23501
+ function findInvalidReference(field, tablesByName) {
23502
+ for (const { targetTable } of refEdges({ fields: [field] })) {
23503
+ const target = tablesByName.get(targetTable);
23504
+ if (!target) return `references unknown table: ${targetTable}`;
23505
+ if (tableKind(target) === "asset") {
23506
+ return `cannot reference asset metadata table: ${targetTable}`;
23507
+ }
23508
+ }
23509
+ return null;
23510
+ }
23511
+ function tableKind(table) {
23512
+ return table.kind ?? "record";
23513
+ }
23514
+ function isAssetTable(table) {
23515
+ return tableKind(table) === "asset";
23516
+ }
23517
+ function mediaKind(t) {
23518
+ const leaf = t.kind === "array" ? t.element : t;
23519
+ return leaf.kind === "file" || leaf.kind === "image" ? leaf.kind : null;
23520
+ }
23521
+ function isStorageFieldType(t) {
23522
+ return mediaKind(t) !== null;
23523
+ }
23524
+ function assertAssetBindingAllowed(ctx, table, field) {
23525
+ if (field.asset && tableKind(table) === "asset") {
23526
+ ctx.addIssue({
23527
+ code: external_exports.ZodIssueCode.custom,
23528
+ message: `${table.name}.${field.name} asset metadata fields cannot define a Media profile`,
23529
+ path: ["tables"]
23530
+ });
23531
+ } else if (field.asset && !isStorageFieldType(field.type)) {
23532
+ ctx.addIssue({
23533
+ code: external_exports.ZodIssueCode.custom,
23534
+ message: `${table.name}.${field.name} asset profile can only be set on image/file fields`,
23535
+ path: ["tables"]
23536
+ });
23537
+ }
23538
+ assertAssetBindingsInType(ctx, table, field.type);
23539
+ }
23540
+ function assertAssetBindingsInType(ctx, table, type) {
23541
+ switch (type.kind) {
23542
+ case "array":
23543
+ assertAssetBindingsInType(ctx, table, type.element);
23544
+ break;
23545
+ case "object":
23546
+ for (const f of type.fields) assertAssetBindingAllowed(ctx, table, f);
23547
+ break;
23548
+ case "union":
23549
+ for (const o of type.options) assertAssetBindingsInType(ctx, table, o);
23550
+ break;
23551
+ default:
23552
+ leafOnly(type);
23553
+ }
23554
+ }
23555
+
23556
+ // ../shared/src/fieldTypeText.ts
23557
+ function foldFieldType(type, fold) {
23558
+ switch (type.kind) {
23559
+ case "array":
23560
+ return fold.array(foldFieldType(type.element, fold), type);
23561
+ case "object":
23562
+ return fold.object(
23563
+ type.fields.map((field) => ({ field, value: foldFieldType(field.type, fold) })),
23564
+ type
23565
+ );
23566
+ case "union":
23567
+ return fold.union(
23568
+ type.options.map((option) => foldFieldType(option, fold)),
23569
+ type
23570
+ );
23571
+ default:
23241
23572
  return fold.leaf(type);
23242
23573
  }
23243
23574
  }
@@ -23533,57 +23864,22 @@ function renderType(t) {
23533
23864
  union: (options) => `v.union(${options.join(", ")})`
23534
23865
  });
23535
23866
  }
23536
-
23537
- // ../shared/src/apiProfile.ts
23538
- var apiTableAccessSchema = external_exports.object({
23539
- table: external_exports.string(),
23540
- read: external_exports.boolean(),
23541
- /** Push to enabled webhook outputs. Missing/undefined = false (opt-in). */
23542
- sync: external_exports.boolean().optional(),
23543
- /**
23544
- * Authenticated Studio/CMS editor write access for this table.
23545
- * Missing/undefined = false (opt-in). Independent of public API-token propose.
23546
- */
23547
- editorAccess: external_exports.boolean().optional(),
23548
- propose: external_exports.object({
23549
- ops: external_exports.object({ insert: external_exports.boolean(), update: external_exports.boolean(), delete: external_exports.boolean() }),
23550
- allowedFields: external_exports.array(external_exports.string()).optional(),
23551
- recordIds: external_exports.array(external_exports.string()).optional()
23552
- }).optional(),
23553
- autoAccept: external_exports.boolean().optional(),
23554
- /**
23555
- * Opaque row clamp: AND-merged with caller Query on Read API / guest lists.
23556
- * Sync membership uses `rowQuery.predicates` only (order/search ignored; maxScanLimit ignored).
23557
- */
23558
- rowQuery: clampQuerySchema.optional(),
23559
- /** Scan ceiling for Read/guest list plans; callers may only lower. Not applied to Sync/Resync. */
23560
- maxScanLimit: external_exports.number().int().positive().optional(),
23561
- /**
23562
- * Media source scope for the fixed `columnus_assets` source. Omit for all
23563
- * live Media; an empty list intentionally grants no Media assets.
23564
- */
23565
- assetProfiles: external_exports.array(external_exports.string().min(1)).max(100).optional(),
23566
- /**
23567
- * Media profiles an API token may attach to in-scope Media items
23568
- * (`columnus_assets` only). Missing/empty = no token assignment.
23569
- */
23570
- assignProfiles: external_exports.array(external_exports.string().min(1)).max(100).optional()
23571
- });
23572
- var apiProfileSnapshotSchema = external_exports.object({
23573
- id: external_exports.string(),
23574
- name: external_exports.string(),
23575
- slug: external_exports.string(),
23576
- tables: external_exports.array(external_exports.string()),
23577
- tableAccess: external_exports.array(apiTableAccessSchema).optional(),
23578
- autoAcceptProposals: external_exports.boolean().optional(),
23579
- apiVersion: external_exports.number(),
23580
- updatedAt: external_exports.number()
23581
- });
23582
- var apiProfilesSchema = external_exports.array(apiProfileSnapshotSchema);
23583
- function editorAccessEnabled(access2) {
23584
- return access2.editorAccess === true;
23867
+
23868
+ // ../shared/src/readApiQuery.ts
23869
+ function readApiQueryExportName(kind, tableName) {
23870
+ return `${kind}${tableName}`;
23871
+ }
23872
+ function proposeApiExportName(op, tableName) {
23873
+ return `propose${op[0].toUpperCase()}${op.slice(1)}${tableName}`;
23874
+ }
23875
+ function readApiQueryModuleSegment(profileSlug) {
23876
+ return apiProfileSlugToConvexModuleSegment(profileSlug);
23877
+ }
23878
+ function readApiAnyApiPath(profileSlug, kind, tableName) {
23879
+ const segment = readApiQueryModuleSegment(profileSlug);
23880
+ const exportName = readApiQueryExportName(kind, tableName);
23881
+ return `anyApi.columnus.read.${segment}.${exportName}.${exportName}`;
23585
23882
  }
23586
- var MEDIA_LIBRARY_JOURNAL_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
23587
23883
 
23588
23884
  // ../api-codegen/src/generate-documents.ts
23589
23885
  function fieldToTsProperty(field) {
@@ -23897,20 +24193,31 @@ export type ProfileProposalSummary = {
23897
24193
  createdByUserId?: string;
23898
24194
  baselineManifestHash: string;
23899
24195
  createdAt: number;
24196
+ /** Revision of a protected shared draft; pass it back when publishing. */
24197
+ draftRevision?: number;
23900
24198
  patches: ProfileProposalPatchSummary[];
23901
24199
  };
23902
24200
 
24201
+ export type ProfileDraftSaveResult = {
24202
+ proposalId: string;
24203
+ status: "active" | "withdrawn";
24204
+ revision?: number;
24205
+ };
24206
+
23903
24207
  export type ProfileProposalOutcome = {
23904
24208
  id: string;
23905
24209
  outcome: "accepted" | "rejected" | "skipped_stale" | "skipped_overlap";
23906
24210
  message?: string;
23907
24211
  };
23908
24212
 
23909
- export const proposeProfileBatchRef = anyApi.columnus.share.proposeProfileBatch as FunctionReference<"mutation", "public", { profileSlug: string; patches: ProfileProposalPatch[] }, { proposalId: string; status: "active" }>;
24213
+ export const proposeProfileBatchRef = anyApi.columnus.share.proposeProfileBatch as FunctionReference<"mutation", "public", { profileSlug: string; patches: ProfileProposalPatch[]; expectedRevision?: number }, ProfileDraftSaveResult>;
24214
+
24215
+ /** Merge changed rows into the caller's shared draft (concurrent-safe Save). */
24216
+ export const saveMyProfileDraftRef = anyApi.columnus.share.saveMyProfileDraft as FunctionReference<"mutation", "public", { profileSlug: string; patches: Array<ProfileProposalPatch & { clearFields?: string[] }>; discard?: Array<{ table: string; rowId: string }> }, ProfileDraftSaveResult>;
23910
24217
 
23911
24218
  export const listProfileProposalsRef = anyApi.columnus.share.listProfileProposals as FunctionReference<"query", "public", { profileSlug: string }, ProfileProposalSummary[]>;
23912
24219
 
23913
- export const publishMyProfileProposalRef = anyApi.columnus.share.publishMyProfileProposal as FunctionReference<"mutation", "public", { profileSlug: string }, ProfileProposalOutcome[]>;
24220
+ export const publishMyProfileProposalRef = anyApi.columnus.share.publishMyProfileProposal as FunctionReference<"mutation", "public", { profileSlug: string; expectedRevision?: number }, ProfileProposalOutcome[]>;
23914
24221
 
23915
24222
  export const withdrawMyProfileProposalRef = anyApi.columnus.share.withdrawMyProfileProposal as FunctionReference<"mutation", "public", { profileSlug: string }, { id: string; status: "withdrawn" }>;
23916
24223
 
@@ -24040,6 +24347,7 @@ export const getRowsByIdsRef = anyApi.columnus.rows.getRowsByIds as FunctionRefe
24040
24347
 
24041
24348
  export const cmsHostRefs = {
24042
24349
  proposeProfileBatch: proposeProfileBatchRef,
24350
+ saveMyProfileDraft: saveMyProfileDraftRef,
24043
24351
  listProfileProposals: listProfileProposalsRef,
24044
24352
  publishMyProfileProposal: publishMyProfileProposalRef,
24045
24353
  withdrawMyProfileProposal: withdrawMyProfileProposalRef,
@@ -24112,528 +24420,303 @@ export function toDocumentId(value: unknown): string | undefined {
24112
24420
  if (value === undefined || value === null || value === "") return undefined;
24113
24421
  return typeof value === "string" ? value : String(value);
24114
24422
  }
24115
-
24116
- function isAssetFieldType(type: ManifestFieldType): boolean {
24117
- return type.kind === "file" || type.kind === "image";
24118
- }
24119
-
24120
- function isAssetArrayFieldType(type: ManifestFieldType): boolean {
24121
- return type.kind === "array" && (type.element.kind === "file" || type.element.kind === "image");
24122
- }
24123
-
24124
- function isAssetFieldOrArray(type: ManifestFieldType): boolean {
24125
- return isAssetFieldType(type) || isAssetArrayFieldType(type);
24126
- }
24127
-
24128
- export function collectAssetIds(
24129
- value: unknown,
24130
- type: ManifestFieldType,
24131
- out: Set<string> = new Set(),
24132
- ): Set<string> {
24133
- if (isAssetFieldType(type)) {
24134
- const id = toDocumentId(value);
24135
- if (id) out.add(id);
24136
- return out;
24137
- }
24138
- if (isAssetArrayFieldType(type) && Array.isArray(value)) {
24139
- for (const item of value) {
24140
- const id = toDocumentId(item);
24141
- if (id) out.add(id);
24142
- }
24143
- }
24144
- return out;
24145
- }
24146
-
24147
- export function collectAssetIdsFromRow<T extends TableName>(
24148
- row: DocByTable[T] | undefined,
24149
- fields: readonly ManifestField[],
24150
- out: Set<string> = new Set(),
24151
- ): Set<string> {
24152
- if (!row) return out;
24153
- const values = row as Record<string, unknown>;
24154
- for (const field of fields) {
24155
- if (!isAssetFieldOrArray(field.type)) continue;
24156
- collectAssetIds(values[field.name], field.type, out);
24157
- }
24158
- return out;
24159
- }
24160
- `;
24161
- }
24162
- function generateReadApiMetaTs(profileSlug, apiVersion, manifestHash) {
24163
- return `${READ_API_BANNER}/** Compile-time snapshot from the last \`columnus-api pull\`. */
24164
- export const PULLED_PROFILE_SLUG = ${JSON.stringify(profileSlug)} as const;
24165
- export const PULLED_API_VERSION = ${apiVersion} as const;
24166
- export const PULLED_MANIFEST_HASH = ${JSON.stringify(manifestHash)} as const;
24167
- `;
24168
- }
24169
- function generateReadApiTokenTs() {
24170
- return `${READ_API_BANNER}export function readApiToken(): string {
24171
- const token = import.meta.env.VITE_COLUMNUS_API_TOKEN;
24172
- if (!token || typeof token !== "string") {
24173
- throw new Error("VITE_COLUMNUS_API_TOKEN is required");
24174
- }
24175
- return token;
24176
- }
24177
- `;
24178
- }
24179
- function generateHooksTs(tables, pageSize) {
24180
- const sorted = [...tables].sort((a, b) => a.name.localeCompare(b.name));
24181
- const listHooks = sorted.map((table) => {
24182
- const hookName = `use${table.name}List`;
24183
- const ref = `list${table.name}Ref`;
24184
- return `
24185
- export function ${hookName}(query?: Query | null) {
24186
- const apiToken = readApiToken();
24187
- return usePaginatedQuery(
24188
- ${ref},
24189
- query ? { apiToken, query } : { apiToken },
24190
- { initialNumItems: ${pageSize} },
24191
- );
24192
- }`;
24193
- }).join("\n");
24194
- const getHooks = sorted.map((table) => {
24195
- const hookName = `use${table.name}ById`;
24196
- const doc = docTypeName(table.name);
24197
- const ref = `get${table.name}Ref`;
24198
- return `
24199
- export function ${hookName}(id: ${doc}["_id"] | undefined) {
24200
- const apiToken = readApiToken();
24201
- return useQuery(${ref}, id ? { apiToken, id } : "skip");
24202
- }`;
24203
- }).join("\n");
24204
- const docImports = sorted.map((t) => ` ${docTypeName(t.name)},`).join("\n");
24205
- const refImports = sorted.flatMap((t) => [` list${t.name}Ref,`, ` get${t.name}Ref,`]).join("\n");
24206
- return `${READ_API_BANNER}import { usePaginatedQuery, useQuery } from "convex/react";
24207
- import { anyApi } from "convex/server";
24208
- import type { Query } from "./query.js";
24209
- import type {
24210
- ${docImports}
24211
- } from "./documents.js";
24212
- import {
24213
- ${refImports}
24214
- } from "./read-api-refs.js";
24215
- import { readApiToken } from "./read-api-token.js";
24216
- ${listHooks}
24217
-
24218
- ${getHooks}
24219
-
24220
- export function useAssetOriginals(assetIds: string[]) {
24221
- const apiToken = readApiToken();
24222
- const ids = assetIds.filter(Boolean);
24223
- const results = useQuery(
24224
- anyApi.columnus.read.assets.getAssetOriginals,
24225
- ids.length > 0 ? { apiToken, assetIds: ids } : "skip",
24226
- );
24227
- return results ?? [];
24228
- }
24229
-
24230
- export function useAssetExpansions(assetIds: string[]) {
24231
- const apiToken = readApiToken();
24232
- const ids = assetIds.filter(Boolean);
24233
- const results = useQuery(
24234
- anyApi.columnus.read.assets.getAssetExpansions,
24235
- ids.length > 0 ? { apiToken, assetIds: ids } : "skip",
24236
- );
24237
- return results ?? [];
24238
- }
24239
- `;
24240
- }
24241
- function generateEnvExample(convexUrl) {
24242
- return `# Copy to .env.local and fill in your read API token from Columnus /api.
24243
- VITE_CONVEX_URL=${convexUrl}
24244
- VITE_COLUMNUS_API_TOKEN=col_your_token_here
24245
- `;
24246
- }
24247
-
24248
- // ../shared/src/apiToken.ts
24249
- var TOKEN_BODY_RE = /^col_[A-Za-z0-9_-]{20,}$/;
24250
- function isApiTokenFormat(token) {
24251
- return TOKEN_BODY_RE.test(token.trim());
24252
- }
24253
-
24254
- // src/pull-codegen.ts
24255
- import { access, writeFile } from "node:fs/promises";
24256
- import path2 from "node:path";
24257
-
24258
- // ../shared/src/fieldValueText.ts
24259
- var INT64_MIN = -(2n ** 63n);
24260
- var INT64_MAX = 2n ** 63n - 1n;
24261
-
24262
- // ../shared/src/schemaShrinkValidators.ts
24263
- import { v } from "convex/values";
24264
- var cleanupStateValidator = v.object({
24265
- targetManifestJson: v.string(),
24266
- beforeManifestJson: v.string(),
24267
- tasks: v.array(
24268
- v.union(
24269
- v.object({ kind: v.literal("delete_table"), table: v.string() }),
24270
- v.object({
24271
- kind: v.literal("strip_field"),
24272
- table: v.string(),
24273
- field: v.string(),
24274
- fieldType: v.any()
24275
- })
24276
- )
24277
- ),
24278
- taskIndex: v.number(),
24279
- cursor: v.union(v.string(), v.null()),
24280
- stats: v.object({
24281
- rowsDeleted: v.number(),
24282
- fieldsStripped: v.number(),
24283
- storageDeleted: v.number()
24284
- }),
24285
- bffOperationId: v.string(),
24286
- desiredManifestHash: v.string()
24287
- });
24288
-
24289
- // ../shared/src/assetJobs.ts
24290
- var ASSET_JOB_LEASE_MS = 15 * 6e4;
24291
- var ASSET_JOB_BACKOFF_MS = [15e3, 6e4, 5 * 6e4, 60 * 6e4];
24292
-
24293
- // ../shared/src/assetSettings.ts
24294
- var DEFAULT_MEDIA_WARN_BYTES = 10 * 1024 * 1024 * 1024;
24295
- var DEFAULT_MEDIA_REJECT_BYTES = 100 * 1024 * 1024 * 1024;
24296
-
24297
- // ../shared/src/csv.ts
24298
- var import_papaparse = __toESM(require_papaparse(), 1);
24299
-
24300
- // ../shared/src/queryValidators.ts
24301
- import { v as v2 } from "convex/values";
24302
- var predicateValidators = PREDICATE_VARIANTS.flatMap(
24303
- (variant) => variant.ops.map(
24304
- ({ op }) => v2.object({
24305
- field: v2.string(),
24306
- op: v2.literal(op),
24307
- value: variant.value === "unknownArray" ? v2.array(v2.any()) : variant.value === "between" ? v2.object({ min: v2.any(), max: v2.any() }) : variant.value === "none" ? v2.null() : v2.any()
24308
- })
24309
- )
24310
- );
24311
- var predicateValidator = v2.union(
24312
- ...predicateValidators
24313
- );
24314
- var queryOrderValidator = v2.object({
24315
- field: v2.string(),
24316
- direction: v2.union(v2.literal("asc"), v2.literal("desc"))
24317
- });
24318
- var querySearchValidator = v2.object({
24319
- index: v2.string(),
24320
- query: v2.string()
24321
- });
24322
- var queryValidator = v2.object({
24323
- predicates: v2.optional(v2.array(predicateValidator)),
24324
- order: v2.optional(queryOrderValidator),
24325
- search: v2.optional(querySearchValidator),
24326
- maxScan: v2.optional(v2.number()),
24327
- indexHint: v2.optional(v2.string()),
24328
- vector: v2.optional(v2.any())
24329
- });
24330
- var clampQueryValidator = v2.object({
24331
- predicates: v2.optional(v2.array(predicateValidator)),
24332
- order: v2.optional(queryOrderValidator),
24333
- search: v2.optional(querySearchValidator)
24334
- });
24335
- var queryArgValidator = v2.optional(queryValidator);
24336
- var maxScanLimitValidator = v2.optional(v2.number());
24337
-
24338
- // ../shared/src/useDebouncedValue.ts
24339
- var import_react = __toESM(require_react(), 1);
24340
-
24341
- // ../shared/src/useDebouncedCommit.ts
24342
- var import_react2 = __toESM(require_react(), 1);
24343
-
24344
- // ../shared/src/useModifierHeld.ts
24345
- var import_react3 = __toESM(require_react(), 1);
24346
-
24347
- // ../shared/src/convexSiteUrl.ts
24348
- function convexDeploymentSlug(url2) {
24349
- const match = url2.match(/https:\/\/([^.]+)\.convex\.(?:cloud|site)/);
24350
- return match?.[1];
24351
- }
24352
- function deriveConvexDeploymentFromCloudUrl(cloudUrl) {
24353
- const slug = convexDeploymentSlug(cloudUrl);
24354
- return slug ? `dev:${slug}` : void 0;
24423
+
24424
+ function isAssetFieldType(type: ManifestFieldType): boolean {
24425
+ return type.kind === "file" || type.kind === "image";
24355
24426
  }
24356
24427
 
24357
- // ../shared/src/refsRecompute.ts
24358
- var REFS_RECOMPUTE_STALE_MS = 10 * 60 * 1e3;
24428
+ function isAssetArrayFieldType(type: ManifestFieldType): boolean {
24429
+ return type.kind === "array" && (type.element.kind === "file" || type.element.kind === "image");
24430
+ }
24359
24431
 
24360
- // ../shared/src/dataTransfer.ts
24361
- var COLUMNUS_DATA_TRANSFER_VERSION = 1;
24362
- var MAX_TRANSFER_BYTES = 50 * 1024 * 1024;
24363
- function isProtectedTransferTable(table) {
24364
- return table.startsWith("_") || table.startsWith("columnus_") || table.startsWith("studio_");
24432
+ function isAssetFieldOrArray(type: ManifestFieldType): boolean {
24433
+ return isAssetFieldType(type) || isAssetArrayFieldType(type);
24365
24434
  }
24366
24435
 
24367
- // ../shared/src/tenantHosts.ts
24368
- var RESERVED_TENANT_SLUGS = ["manage", "deploy", "www"];
24369
- var RESERVED_SLUG_SET = new Set(RESERVED_TENANT_SLUGS);
24436
+ export function collectAssetIds(
24437
+ value: unknown,
24438
+ type: ManifestFieldType,
24439
+ out: Set<string> = new Set(),
24440
+ ): Set<string> {
24441
+ if (isAssetFieldType(type)) {
24442
+ const id = toDocumentId(value);
24443
+ if (id) out.add(id);
24444
+ return out;
24445
+ }
24446
+ if (isAssetArrayFieldType(type) && Array.isArray(value)) {
24447
+ for (const item of value) {
24448
+ const id = toDocumentId(item);
24449
+ if (id) out.add(id);
24450
+ }
24451
+ }
24452
+ return out;
24453
+ }
24370
24454
 
24371
- // ../shared/src/bffProtocol.ts
24372
- var COLUMNUS_BFF_PROTOCOL_VERSION = 1;
24373
- var OPERATION_ID_RE = /^[A-Za-z0-9_-]{16,128}$/;
24374
- var TRANSFER_ID_RE = /^[A-Za-z0-9_-]{16,64}$/;
24375
- var MANIFEST_HASH_RE = /^[0-9a-f]{64}$/;
24376
- var TABLE_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
24377
- var operationIdSchema = external_exports.string().regex(OPERATION_ID_RE);
24378
- var transferIdSchema = external_exports.string().regex(TRANSFER_ID_RE);
24379
- var manifestHashSchema = external_exports.string().regex(MANIFEST_HASH_RE);
24380
- var bffPrepareOperationTypeSchema = external_exports.enum([
24381
- "schemaDeploy",
24382
- "dataExport",
24383
- "dataImportPrepare",
24384
- "dataImportCommit"
24385
- ]);
24386
- var transferOperationSchema = external_exports.enum(["export", "import"]);
24387
- var transferSessionStateSchema = external_exports.enum([
24388
- "exportReady",
24389
- "importAwaitingUpload",
24390
- "importUploaded",
24391
- "importCommitted",
24392
- "importFailed",
24393
- "expired"
24394
- ]);
24395
- var schemaDeployPhaseSchema = external_exports.enum([
24396
- "cleaning",
24397
- "ready",
24398
- "deploying",
24399
- "succeeded",
24400
- "failed"
24401
- ]);
24402
- var SCHEMA_DEPLOY_OPERATION_LEASE_MS = 20 * 60 * 1e3;
24403
- var transferTableSchema = external_exports.string().regex(TABLE_NAME_RE).refine((name) => !isProtectedTransferTable(name), {
24404
- message: "Protected table cannot be transferred"
24405
- });
24406
- var dataTransferManifestSchema = external_exports.object({
24407
- version: external_exports.literal(COLUMNUS_DATA_TRANSFER_VERSION),
24408
- tables: external_exports.array(transferTableSchema).min(1),
24409
- schemaHash: manifestHashSchema,
24410
- includeFileStorage: external_exports.boolean()
24411
- }).superRefine((value, ctx) => {
24412
- if (new Set(value.tables).size !== value.tables.length) {
24413
- ctx.addIssue({
24414
- code: external_exports.ZodIssueCode.custom,
24415
- message: "dataTransfer.tables must not contain duplicates",
24416
- path: ["tables"]
24417
- });
24455
+ export function collectAssetIdsFromRow<T extends TableName>(
24456
+ row: DocByTable[T] | undefined,
24457
+ fields: readonly ManifestField[],
24458
+ out: Set<string> = new Set(),
24459
+ ): Set<string> {
24460
+ if (!row) return out;
24461
+ const values = row as Record<string, unknown>;
24462
+ for (const field of fields) {
24463
+ if (!isAssetFieldOrArray(field.type)) continue;
24464
+ collectAssetIds(values[field.name], field.type, out);
24418
24465
  }
24419
- });
24420
- var bffSchemaDeployRequestSchema = external_exports.object({
24421
- operationId: operationIdSchema,
24422
- manifestJson: external_exports.string().min(2).max(2e6)
24423
- });
24424
- var bffTransferScopeRequestSchema = external_exports.object({
24425
- operationId: operationIdSchema,
24426
- tables: external_exports.array(transferTableSchema).min(1),
24427
- schemaHash: manifestHashSchema,
24428
- includeFileStorage: external_exports.boolean()
24429
- });
24430
- var bffTransferCommitRequestSchema = external_exports.object({
24431
- operationId: operationIdSchema,
24432
- /** Client echo; server also rechecks the transfer-bound hash. */
24433
- schemaHash: manifestHashSchema
24434
- });
24435
- var bffHealthResponseSchema = external_exports.object({
24436
- ok: external_exports.boolean(),
24437
- commit: external_exports.string(),
24438
- executor: external_exports.object({
24439
- ok: external_exports.boolean(),
24440
- commit: external_exports.string().optional(),
24441
- error: external_exports.string().optional()
24442
- })
24443
- });
24444
- var bffActiveOperationMetaSchema = external_exports.object({
24445
- operationId: operationIdSchema,
24446
- desiredManifestHash: manifestHashSchema.optional(),
24447
- phase: schemaDeployPhaseSchema.optional(),
24448
- startedAt: external_exports.number().optional()
24449
- });
24450
- var bffSchemaDeployResponseSchema = external_exports.object({
24451
- ok: external_exports.boolean(),
24452
- operationId: operationIdSchema,
24453
- phase: schemaDeployPhaseSchema,
24454
- desiredManifestHash: manifestHashSchema.optional(),
24455
- deployedManifestHash: manifestHashSchema.optional(),
24456
- error: external_exports.string().optional(),
24457
- logTail: external_exports.string().optional(),
24458
- activeOperation: bffActiveOperationMetaSchema.optional()
24459
- });
24460
- var bffTransferCreateResponseSchema = external_exports.object({
24461
- ok: external_exports.literal(true),
24462
- transferId: transferIdSchema,
24463
- expiresAt: external_exports.number().int().positive(),
24464
- bytes: external_exports.number().int().nonnegative().optional()
24465
- });
24466
- var bffTransferCommitResponseSchema = external_exports.object({
24467
- ok: external_exports.boolean(),
24468
- transferId: transferIdSchema,
24469
- error: external_exports.string().optional(),
24470
- logTail: external_exports.string().optional()
24471
- });
24472
- var bffTransferUploadResponseSchema = external_exports.object({
24473
- ok: external_exports.literal(true),
24474
- bytes: external_exports.number().int().nonnegative()
24475
- });
24476
- var bffErrorCodeSchema = external_exports.enum([
24477
- "unauthorized",
24478
- "forbidden",
24479
- "unknown_host",
24480
- "disabled_host",
24481
- "conflict",
24482
- "executor_mismatch",
24483
- "executor_unavailable",
24484
- "validation_error",
24485
- "not_found",
24486
- "payload_too_large",
24487
- "gone",
24488
- "internal_error"
24489
- ]);
24490
- var bffErrorResponseSchema = external_exports.object({
24491
- ok: external_exports.literal(false),
24492
- error: external_exports.string(),
24493
- code: bffErrorCodeSchema.optional(),
24494
- logTail: external_exports.string().optional(),
24495
- activeOperation: bffActiveOperationMetaSchema.optional()
24496
- });
24497
- var bffPrepareOperationSchema = external_exports.discriminatedUnion("type", [
24498
- external_exports.object({
24499
- type: external_exports.literal("schemaDeploy"),
24500
- operationId: operationIdSchema,
24501
- manifestJson: external_exports.string().min(2).max(2e6)
24502
- }),
24503
- external_exports.object({
24504
- type: external_exports.literal("dataExport"),
24505
- operationId: operationIdSchema,
24506
- transferManifest: dataTransferManifestSchema
24507
- }),
24508
- external_exports.object({
24509
- type: external_exports.literal("dataImportPrepare"),
24510
- operationId: operationIdSchema,
24511
- transferManifest: dataTransferManifestSchema
24466
+ return out;
24467
+ }
24468
+ `;
24469
+ }
24470
+ function generateReadApiMetaTs(profileSlug, apiVersion, manifestHash) {
24471
+ return `${READ_API_BANNER}/** Compile-time snapshot from the last \`columnus-api pull\`. */
24472
+ export const PULLED_PROFILE_SLUG = ${JSON.stringify(profileSlug)} as const;
24473
+ export const PULLED_API_VERSION = ${apiVersion} as const;
24474
+ export const PULLED_MANIFEST_HASH = ${JSON.stringify(manifestHash)} as const;
24475
+ `;
24476
+ }
24477
+ function generateReadApiTokenTs() {
24478
+ return `${READ_API_BANNER}export function readApiToken(): string {
24479
+ const token = import.meta.env.VITE_COLUMNUS_API_TOKEN;
24480
+ if (!token || typeof token !== "string") {
24481
+ throw new Error("VITE_COLUMNUS_API_TOKEN is required");
24482
+ }
24483
+ return token;
24484
+ }
24485
+ `;
24486
+ }
24487
+ function generateHooksTs(tables, pageSize) {
24488
+ const sorted = [...tables].sort((a, b) => a.name.localeCompare(b.name));
24489
+ const listHooks = sorted.map((table) => {
24490
+ const hookName = `use${table.name}List`;
24491
+ const ref = `list${table.name}Ref`;
24492
+ return `
24493
+ export function ${hookName}(query?: Query | null) {
24494
+ const apiToken = readApiToken();
24495
+ return usePaginatedQuery(
24496
+ ${ref},
24497
+ query ? { apiToken, query } : { apiToken },
24498
+ { initialNumItems: ${pageSize} },
24499
+ );
24500
+ }`;
24501
+ }).join("\n");
24502
+ const getHooks = sorted.map((table) => {
24503
+ const hookName = `use${table.name}ById`;
24504
+ const doc = docTypeName(table.name);
24505
+ const ref = `get${table.name}Ref`;
24506
+ return `
24507
+ export function ${hookName}(id: ${doc}["_id"] | undefined) {
24508
+ const apiToken = readApiToken();
24509
+ return useQuery(${ref}, id ? { apiToken, id } : "skip");
24510
+ }`;
24511
+ }).join("\n");
24512
+ const docImports = sorted.map((t) => ` ${docTypeName(t.name)},`).join("\n");
24513
+ const refImports = sorted.flatMap((t) => [` list${t.name}Ref,`, ` get${t.name}Ref,`]).join("\n");
24514
+ return `${READ_API_BANNER}import { usePaginatedQuery, useQuery } from "convex/react";
24515
+ import { anyApi } from "convex/server";
24516
+ import type { Query } from "./query.js";
24517
+ import type {
24518
+ ${docImports}
24519
+ } from "./documents.js";
24520
+ import {
24521
+ ${refImports}
24522
+ } from "./read-api-refs.js";
24523
+ import { readApiToken } from "./read-api-token.js";
24524
+ ${listHooks}
24525
+
24526
+ ${getHooks}
24527
+
24528
+ export function useAssetOriginals(assetIds: string[]) {
24529
+ const apiToken = readApiToken();
24530
+ const ids = assetIds.filter(Boolean);
24531
+ const results = useQuery(
24532
+ anyApi.columnus.read.assets.getAssetOriginals,
24533
+ ids.length > 0 ? { apiToken, assetIds: ids } : "skip",
24534
+ );
24535
+ return results ?? [];
24536
+ }
24537
+
24538
+ export function useAssetExpansions(assetIds: string[]) {
24539
+ const apiToken = readApiToken();
24540
+ const ids = assetIds.filter(Boolean);
24541
+ const results = useQuery(
24542
+ anyApi.columnus.read.assets.getAssetExpansions,
24543
+ ids.length > 0 ? { apiToken, assetIds: ids } : "skip",
24544
+ );
24545
+ return results ?? [];
24546
+ }
24547
+ `;
24548
+ }
24549
+ function generateEnvExample(convexUrl) {
24550
+ return `# Copy to .env.local and fill in your read API token from Columnus /api.
24551
+ VITE_CONVEX_URL=${convexUrl}
24552
+ VITE_COLUMNUS_API_TOKEN=col_your_token_here
24553
+ `;
24554
+ }
24555
+
24556
+ // ../shared/src/apiToken.ts
24557
+ var TOKEN_BODY_RE = /^col_[A-Za-z0-9_-]{20,}$/;
24558
+ function isApiTokenFormat(token) {
24559
+ return TOKEN_BODY_RE.test(token.trim());
24560
+ }
24561
+
24562
+ // src/pull-codegen.ts
24563
+ import { access, writeFile } from "node:fs/promises";
24564
+ import path2 from "node:path";
24565
+
24566
+ // ../shared/src/fieldValueText.ts
24567
+ var INT64_MIN = -(2n ** 63n);
24568
+ var INT64_MAX = 2n ** 63n - 1n;
24569
+
24570
+ // ../shared/src/schemaShrinkValidators.ts
24571
+ import { v } from "convex/values";
24572
+ var cleanupStateValidator = v.object({
24573
+ targetManifestJson: v.string(),
24574
+ beforeManifestJson: v.string(),
24575
+ tasks: v.array(
24576
+ v.union(
24577
+ v.object({ kind: v.literal("delete_table"), table: v.string() }),
24578
+ v.object({
24579
+ kind: v.literal("strip_field"),
24580
+ table: v.string(),
24581
+ field: v.string(),
24582
+ fieldType: v.any()
24583
+ })
24584
+ )
24585
+ ),
24586
+ taskIndex: v.number(),
24587
+ cursor: v.union(v.string(), v.null()),
24588
+ stats: v.object({
24589
+ rowsDeleted: v.number(),
24590
+ fieldsStripped: v.number(),
24591
+ storageDeleted: v.number()
24512
24592
  }),
24513
- external_exports.object({
24514
- type: external_exports.literal("dataImportCommit"),
24515
- operationId: operationIdSchema,
24516
- transferId: transferIdSchema,
24517
- schemaHash: manifestHashSchema
24518
- })
24519
- ]);
24520
- var bffPrepareRequestSchema = external_exports.object({
24521
- protocolVersion: external_exports.literal(COLUMNUS_BFF_PROTOCOL_VERSION),
24522
- /** Trusted hostname only (already extracted by BFF). */
24523
- host: external_exports.string().min(1),
24524
- correlationId: external_exports.string().min(1).max(128).optional(),
24525
- operation: bffPrepareOperationSchema
24593
+ bffOperationId: v.string(),
24594
+ desiredManifestHash: v.string()
24526
24595
  });
24527
- var bffPreparedTenantSchema = external_exports.object({
24528
- slug: external_exports.string().min(1),
24529
- convexUrl: external_exports.string().url(),
24530
- authIssuer: external_exports.string().url().optional(),
24531
- deploymentName: external_exports.string().optional()
24596
+
24597
+ // ../shared/src/assetJobs.ts
24598
+ var ASSET_JOB_LEASE_MS = 15 * 6e4;
24599
+ var ASSET_JOB_BACKOFF_MS = [15e3, 6e4, 5 * 6e4, 60 * 6e4];
24600
+
24601
+ // ../shared/src/assetSettings.ts
24602
+ var DEFAULT_MEDIA_WARN_BYTES = 10 * 1024 * 1024 * 1024;
24603
+ var DEFAULT_MEDIA_REJECT_BYTES = 100 * 1024 * 1024 * 1024;
24604
+
24605
+ // ../shared/src/csv.ts
24606
+ var import_papaparse = __toESM(require_papaparse(), 1);
24607
+
24608
+ // ../shared/src/queryValidators.ts
24609
+ import { v as v2 } from "convex/values";
24610
+ var predicateValidators = PREDICATE_VARIANTS.flatMap(
24611
+ (variant) => variant.ops.map(
24612
+ ({ op }) => v2.object({
24613
+ field: v2.string(),
24614
+ op: v2.literal(op),
24615
+ value: variant.value === "unknownArray" ? v2.array(v2.any()) : variant.value === "between" ? v2.object({ min: v2.any(), max: v2.any() }) : variant.value === "none" ? v2.null() : v2.any()
24616
+ })
24617
+ )
24618
+ );
24619
+ var predicateValidator = v2.union(
24620
+ ...predicateValidators
24621
+ );
24622
+ var queryOrderValidator = v2.object({
24623
+ field: v2.string(),
24624
+ direction: v2.union(v2.literal("asc"), v2.literal("desc"))
24532
24625
  });
24533
- var deployInternalSchemaDeployPayloadSchema = external_exports.object({
24534
- manifestJson: external_exports.string().min(2),
24535
- convexDeployKey: external_exports.string().min(1),
24536
- convexUrl: external_exports.string().url(),
24537
- authIssuer: external_exports.string().url().optional(),
24538
- previewName: external_exports.string().nullable().optional(),
24539
- operationId: operationIdSchema.optional()
24626
+ var querySearchValidator = v2.object({
24627
+ index: v2.string(),
24628
+ query: v2.string()
24540
24629
  });
24541
- var deployInternalTransferExportPayloadSchema = external_exports.object({
24542
- transferManifest: dataTransferManifestSchema,
24543
- convexDeployKey: external_exports.string().min(1),
24544
- convexUrl: external_exports.string().url(),
24545
- tenantSlug: external_exports.string().min(1),
24546
- operationId: operationIdSchema
24630
+ var queryValidator = v2.object({
24631
+ predicates: v2.optional(v2.array(predicateValidator)),
24632
+ order: v2.optional(queryOrderValidator),
24633
+ search: v2.optional(querySearchValidator),
24634
+ maxScan: v2.optional(v2.number()),
24635
+ indexHint: v2.optional(v2.string()),
24636
+ vector: v2.optional(v2.any())
24547
24637
  });
24548
- var deployInternalTransferImportPreparePayloadSchema = external_exports.object({
24549
- transferManifest: dataTransferManifestSchema,
24550
- convexDeployKey: external_exports.string().min(1),
24551
- convexUrl: external_exports.string().url(),
24552
- tenantSlug: external_exports.string().min(1),
24553
- operationId: operationIdSchema
24638
+ var clampQueryValidator = v2.object({
24639
+ predicates: v2.optional(v2.array(predicateValidator)),
24640
+ order: v2.optional(queryOrderValidator),
24641
+ search: v2.optional(querySearchValidator)
24554
24642
  });
24555
- var deployInternalTransferCommitPayloadSchema = external_exports.object({
24556
- transferId: transferIdSchema,
24557
- convexDeployKey: external_exports.string().min(1),
24558
- convexUrl: external_exports.string().url(),
24559
- tenantSlug: external_exports.string().min(1),
24560
- operationId: operationIdSchema,
24561
- schemaHash: manifestHashSchema
24643
+ var queryArgValidator = v2.optional(queryValidator);
24644
+ var maxScanLimitValidator = v2.optional(v2.number());
24645
+
24646
+ // ../shared/src/useDebouncedValue.ts
24647
+ var import_react = __toESM(require_react(), 1);
24648
+
24649
+ // ../shared/src/useDebouncedCommit.ts
24650
+ var import_react2 = __toESM(require_react(), 1);
24651
+
24652
+ // ../shared/src/useModifierHeld.ts
24653
+ var import_react3 = __toESM(require_react(), 1);
24654
+
24655
+ // ../shared/src/convexSiteUrl.ts
24656
+ function convexDeploymentSlug(url2) {
24657
+ const match = url2.match(/https:\/\/([^.]+)\.convex\.(?:cloud|site)/);
24658
+ return match?.[1];
24659
+ }
24660
+ function deriveConvexDeploymentFromCloudUrl(cloudUrl) {
24661
+ const slug = convexDeploymentSlug(cloudUrl);
24662
+ return slug ? `dev:${slug}` : void 0;
24663
+ }
24664
+
24665
+ // ../shared/src/proposeRateLimit.ts
24666
+ var DEFAULT_PROPOSE_RATE_LIMITS = {
24667
+ api_token: { max: 30, windowMs: 6e4 },
24668
+ share_invite: { max: 120, windowMs: 6e4 },
24669
+ public_form: { max: 10, windowMs: 6e4 },
24670
+ client_key: { max: 60, windowMs: 6e4 },
24671
+ oauth_register: { max: 60, windowMs: 60 * 6e4 }
24672
+ };
24673
+
24674
+ // ../shared/src/apiProfileValidators.ts
24675
+ import { v as v3 } from "convex/values";
24676
+ var apiProposeAccessValidator = v3.object({
24677
+ ops: v3.object({ insert: v3.boolean(), update: v3.boolean(), delete: v3.boolean() }),
24678
+ allowedFields: v3.optional(v3.array(v3.string())),
24679
+ recordIds: v3.optional(v3.array(v3.string()))
24562
24680
  });
24563
- var bffPreparedBodyEnvelopeBaseSchema = external_exports.object({
24564
- protocolVersion: external_exports.literal(COLUMNUS_BFF_PROTOCOL_VERSION),
24565
- tenant: bffPreparedTenantSchema,
24566
- correlationId: external_exports.string().min(1).max(128).optional()
24681
+ var apiTableAccessValidator = v3.object({
24682
+ table: v3.string(),
24683
+ read: v3.boolean(),
24684
+ sync: v3.optional(v3.boolean()),
24685
+ propose: v3.optional(apiProposeAccessValidator),
24686
+ autoAccept: v3.optional(v3.boolean()),
24687
+ editorAccess: v3.optional(v3.boolean()),
24688
+ rowQuery: v3.optional(clampQueryValidator),
24689
+ maxScanLimit: maxScanLimitValidator,
24690
+ assetProfiles: v3.optional(v3.array(v3.string())),
24691
+ assignProfiles: v3.optional(v3.array(v3.string())),
24692
+ write: v3.optional(v3.boolean())
24567
24693
  });
24568
- var bffPreparedBodyEnvelopeSchema = external_exports.discriminatedUnion("operation", [
24569
- bffPreparedBodyEnvelopeBaseSchema.extend({
24570
- operation: external_exports.literal("schemaDeploy"),
24571
- payload: deployInternalSchemaDeployPayloadSchema
24572
- }),
24573
- bffPreparedBodyEnvelopeBaseSchema.extend({
24574
- operation: external_exports.literal("dataExport"),
24575
- payload: deployInternalTransferExportPayloadSchema
24576
- }),
24577
- bffPreparedBodyEnvelopeBaseSchema.extend({
24578
- operation: external_exports.literal("dataImportPrepare"),
24579
- payload: deployInternalTransferImportPreparePayloadSchema
24580
- }),
24581
- bffPreparedBodyEnvelopeBaseSchema.extend({
24582
- operation: external_exports.literal("dataImportCommit"),
24583
- payload: deployInternalTransferCommitPayloadSchema
24694
+ var stagedApiAccessValidator = v3.array(
24695
+ v3.object({
24696
+ profile: v3.string(),
24697
+ profileId: v3.optional(v3.string()),
24698
+ tableAccess: v3.array(apiTableAccessValidator)
24584
24699
  })
24585
- ]);
24586
- var bffPreviewRegisterRequestSchema = external_exports.object({
24587
- hostname: external_exports.string().min(1),
24588
- convexUrl: external_exports.string().url(),
24589
- deployKey: external_exports.string().min(1),
24590
- expectedCommit: external_exports.string().min(7).max(64),
24591
- expiresAt: external_exports.number().int().positive()
24592
- });
24593
- var bffPreviewRemoveRequestSchema = external_exports.object({
24594
- hostname: external_exports.string().min(1)
24595
- });
24596
- var transferSessionRecordSchema = external_exports.object({
24597
- transferId: transferIdSchema,
24598
- tenantSlug: external_exports.string().min(1),
24599
- convexUrl: external_exports.string().url(),
24600
- operation: transferOperationSchema,
24601
- tables: external_exports.array(transferTableSchema).min(1),
24602
- schemaHash: manifestHashSchema,
24603
- includeFileStorage: external_exports.boolean(),
24604
- maxBytes: external_exports.number().int().positive().max(MAX_TRANSFER_BYTES),
24605
- expiresAt: external_exports.number().int().positive(),
24606
- state: transferSessionStateSchema,
24607
- operationId: operationIdSchema.optional(),
24608
- bytes: external_exports.number().int().nonnegative().optional(),
24609
- commitResult: external_exports.object({
24610
- ok: external_exports.boolean(),
24611
- error: external_exports.string().optional(),
24612
- logTail: external_exports.string().optional()
24613
- }).optional()
24614
- });
24615
- var deployInternalTransferCreateResponseSchema = external_exports.object({
24616
- ok: external_exports.literal(true),
24617
- transferId: transferIdSchema,
24618
- expiresAt: external_exports.number().int().positive(),
24619
- bytes: external_exports.number().int().nonnegative().optional()
24620
- });
24621
- var deployInternalSchemaDeployResponseSchema = external_exports.object({
24622
- ok: external_exports.boolean(),
24623
- durationMs: external_exports.number(),
24624
- prepareMs: external_exports.number().optional(),
24625
- cliMs: external_exports.number().optional(),
24626
- kernelCommit: external_exports.string().optional(),
24627
- error: external_exports.string().optional(),
24628
- logTail: external_exports.string().optional()
24629
- });
24630
- var deployHealthResponseSchema = external_exports.object({
24631
- ok: external_exports.boolean(),
24632
- commit: external_exports.string().optional(),
24633
- /** ISO-8601 Coolify/image bake time (BRU-76 preview supersede). */
24634
- deployedAt: external_exports.string().optional()
24635
- });
24636
- var BFF_JSON_BODY_LIMIT_BYTES = 2 * 1024 * 1024;
24700
+ );
24701
+
24702
+ // ../shared/src/refsRecompute.ts
24703
+ var REFS_RECOMPUTE_STALE_MS = 10 * 60 * 1e3;
24704
+
24705
+ // ../shared/src/stagedApiAccess.ts
24706
+ var stagedApiAccessSchema = external_exports.array(
24707
+ external_exports.object({
24708
+ profile: external_exports.string().min(1),
24709
+ tableAccess: external_exports.array(apiTableAccessSchema).min(1)
24710
+ }).strict()
24711
+ );
24712
+
24713
+ // ../shared/src/tenantHosts.ts
24714
+ var RESERVED_TENANT_SLUGS = ["manage", "deploy", "www"];
24715
+ var RESERVED_SLUG_SET = new Set(RESERVED_TENANT_SLUGS);
24716
+
24717
+ // ../shared/src/studioBoot.ts
24718
+ import { makeFunctionReference } from "convex/server";
24719
+ var resolveTenantByHostRef = makeFunctionReference("tenants:resolveTenantByHost");
24637
24720
 
24638
24721
  // ../shared/src/bffRedact.ts
24639
24722
  var encoder = new TextEncoder();