@ai-matrx/records 0.72.12 → 0.72.23

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 (34) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/app-table/index.d.cts +3 -3
  3. package/dist/app-table/index.d.ts +3 -3
  4. package/dist/core/index.d.cts +5 -5
  5. package/dist/core/index.d.ts +5 -5
  6. package/dist/{declareTable-Br8pE4fr.d.cts → declareTable-CLvpMdgJ.d.cts} +2 -2
  7. package/dist/{declareTable-DM6z1tc-.d.ts → declareTable-DY3oN4rq.d.ts} +2 -2
  8. package/dist/index.d.cts +3 -3
  9. package/dist/index.d.ts +3 -3
  10. package/dist/memory/index.cjs +2681 -0
  11. package/dist/memory/index.cjs.map +1 -0
  12. package/dist/memory/index.d.cts +126 -0
  13. package/dist/memory/index.d.ts +126 -0
  14. package/dist/memory/index.js +2658 -0
  15. package/dist/memory/index.js.map +1 -0
  16. package/dist/{ports-DKBvsoya.d.cts → ports-DKOk7AT2.d.cts} +1 -1
  17. package/dist/{ports-Bhu2Q3V0.d.ts → ports-Df3VghxK.d.ts} +1 -1
  18. package/dist/{table-kind-D6Lz7ebE.d.ts → table-kind-CD9B1vtx.d.ts} +1 -1
  19. package/dist/{table-kind-D6VOew74.d.cts → table-kind-e-g5kGXV.d.cts} +1 -1
  20. package/dist/templates/index.cjs +59 -24
  21. package/dist/templates/index.cjs.map +1 -1
  22. package/dist/templates/index.d.cts +18 -1176
  23. package/dist/templates/index.d.ts +18 -1176
  24. package/dist/templates/index.js +59 -24
  25. package/dist/templates/index.js.map +1 -1
  26. package/dist/{validate-QtFxMmJc.d.ts → types-Ba11aOEO.d.ts} +1 -42
  27. package/dist/{validate-DUSrx-9E.d.cts → types-BtEKp3ot.d.cts} +1 -42
  28. package/dist/types-DxVoKKpL.d.ts +1186 -0
  29. package/dist/types-dlj1-2t2.d.cts +1186 -0
  30. package/dist/use-cases/index.d.cts +3 -2
  31. package/dist/use-cases/index.d.ts +3 -2
  32. package/dist/validate-CMb7R_ke.d.cts +44 -0
  33. package/dist/validate-E-g4LAZ6.d.ts +44 -0
  34. package/package.json +13 -1
@@ -0,0 +1,2658 @@
1
+ // src/templates/payloads.ts
2
+ var ACTOR = "user";
3
+ var COMPUTED = /* @__PURE__ */ new Set(["lookup", "rollup", "formula"]);
4
+ var isTimedField = (f) => f.parityType === "datetime" && f.format === "datetime";
5
+ var isSelfDeclaredField = (f) => f.parityType !== "relation" && !COMPUTED.has(f.parityType) && (isTimedField(f) || f.default !== void 0 || f.parityType === "entity_reference");
6
+ function choiceDisplayFormat(field) {
7
+ if (!field.choices?.length || !field.choiceColors) return void 0;
8
+ return {
9
+ id: field.parityType === "multi_select" ? "multi_choice" : "choice",
10
+ options: {
11
+ choices: field.choices.filter((c) => field.choiceColors?.[c]).map((c) => ({ value: c, color: field.choiceColors[c] }))
12
+ }
13
+ };
14
+ }
15
+ function foundationTokens(spec) {
16
+ const main = spec.tables?.[0]?.token;
17
+ return new Set((spec.foundation ?? []).map((f) => f.table).filter((token) => token && token !== main));
18
+ }
19
+ function tableShellPayload(spec, t) {
20
+ return {
21
+ business: spec.business.name,
22
+ tables: [
23
+ {
24
+ token: t.token,
25
+ ...foundationTokens(spec).has(t.token) ? { foundation: true } : {},
26
+ name: t.name,
27
+ labelSingular: t.labelSingular,
28
+ labelPlural: t.labelPlural,
29
+ type: t.type,
30
+ display: t.display,
31
+ weight: t.weight,
32
+ ordered: t.ordered,
33
+ titleField: t.titleField,
34
+ describes: t.describes,
35
+ fields: t.fields.filter((f) => !COMPUTED.has(f.parityType) && f.parityType !== "relation" && !isSelfDeclaredField(f)).map((f) => {
36
+ const displayFormat = choiceDisplayFormat(f);
37
+ return {
38
+ key: f.key,
39
+ label: f.label,
40
+ parityType: f.parityType,
41
+ multi: f.multi,
42
+ dated: f.dated,
43
+ required: f.required,
44
+ unit: f.unit ?? void 0,
45
+ rules: f.rules,
46
+ choices: f.choices,
47
+ source: f.source,
48
+ computeOn: f.computeOn,
49
+ sensitivity: f.sensitivity,
50
+ contextPolicy: f.contextPolicy,
51
+ ...displayFormat ? { displayFormat } : {}
52
+ };
53
+ }),
54
+ rows: []
55
+ }
56
+ ]
57
+ };
58
+ }
59
+ function timedFieldSpec(field) {
60
+ return {
61
+ key: field.key,
62
+ label: field.label,
63
+ type: "datetime",
64
+ kind: "datetime",
65
+ ...field.required ? { required: true } : {},
66
+ ...field.rules ? { rules: field.rules } : {},
67
+ sensitivity: field.sensitivity,
68
+ context_policy: field.contextPolicy
69
+ };
70
+ }
71
+ function selfDeclaredFieldSpec(field) {
72
+ if (isTimedField(field)) return { ...timedFieldSpec(field), ...field.default !== void 0 ? { default: field.default } : {} };
73
+ const allowed = field.parityType === "entity_reference" ? { allowed_types: field.allowedTypes ?? [] } : {};
74
+ const displayFormat = choiceDisplayFormat(field);
75
+ return {
76
+ key: field.key,
77
+ label: field.label,
78
+ type: field.parityType,
79
+ ...field.multi ? { multi: true } : {},
80
+ ...field.required ? { required: true } : {},
81
+ ...field.unit ? { unit: field.unit } : {},
82
+ ...field.rules ? { rules: field.rules } : {},
83
+ ...field.choices ? { options: field.choices } : {},
84
+ ...displayFormat ? { display_format: displayFormat } : {},
85
+ ...field.default !== void 0 ? { default: field.default } : {},
86
+ ...allowed,
87
+ sensitivity: field.sensitivity,
88
+ context_policy: field.contextPolicy
89
+ };
90
+ }
91
+ function relationFieldSpec(field, targetTableId) {
92
+ return {
93
+ key: field.key,
94
+ label: field.label,
95
+ type: "relation",
96
+ relation_target: targetTableId,
97
+ ...field.multi ? { multi: true } : {},
98
+ ...field.relationMax ? { relation_max: field.relationMax } : {},
99
+ ...field.required ? { required: true } : {},
100
+ sensitivity: field.sensitivity,
101
+ context_policy: field.contextPolicy
102
+ };
103
+ }
104
+ function rowLevels(tables) {
105
+ const done = /* @__PURE__ */ new Set();
106
+ const levels = [];
107
+ let left = [...tables];
108
+ while (left.length) {
109
+ let ready = left.filter(
110
+ (t) => t.fields.every((f) => f.parityType !== "relation" || !f.relationTarget || f.relationTarget === t.token || done.has(f.relationTarget))
111
+ );
112
+ if (!ready.length) {
113
+ const optionalOnly = left.find(
114
+ (t) => t.fields.every(
115
+ (f) => f.parityType !== "relation" || !f.relationTarget || f.relationTarget === t.token || done.has(f.relationTarget) || !f.required
116
+ )
117
+ );
118
+ ready = [optionalOnly ?? left[0]];
119
+ }
120
+ for (const t of ready) done.add(t.token);
121
+ levels.push(ready);
122
+ left = left.filter((t) => !done.has(t.token));
123
+ }
124
+ return levels;
125
+ }
126
+ function deferredRelations(tables) {
127
+ const levelOf = /* @__PURE__ */ new Map();
128
+ rowLevels(tables).forEach((level, i) => level.forEach((t) => levelOf.set(t.token, i)));
129
+ const out = /* @__PURE__ */ new Map();
130
+ for (const t of tables) {
131
+ const mine = levelOf.get(t.token) ?? 0;
132
+ for (const f of t.fields) {
133
+ if (f.parityType !== "relation" || !f.relationTarget) continue;
134
+ if (f.relationTarget === t.token || (levelOf.get(f.relationTarget) ?? -1) >= mine) {
135
+ out.set(t.token, /* @__PURE__ */ new Set([...out.get(t.token) ?? [], f.key]));
136
+ }
137
+ }
138
+ }
139
+ return out;
140
+ }
141
+ function relationPatches(table, ids, deferred) {
142
+ if (!deferred?.size) return [];
143
+ const rel = new Map(table.fields.filter((f) => deferred.has(f.key)).map((f) => [f.key, f.relationTarget]));
144
+ const out = [];
145
+ for (const r of table.rows) {
146
+ const patch = {};
147
+ for (const [key, target] of rel) {
148
+ const v = r.values?.[key];
149
+ if (v === null || v === void 0) continue;
150
+ const idOf = (k) => {
151
+ const id = ids.get(`${target}.${String(k)}`);
152
+ if (!id) throw new Error(`A row points at "${String(k)}" in "${target}", which the template does not have.`);
153
+ return id;
154
+ };
155
+ patch[key] = Array.isArray(v) ? v.map(idOf) : idOf(v);
156
+ }
157
+ if (Object.keys(patch).length) out.push({ op: "update", record_id: ids.get(`${table.token}.${r.key}`), patch: { ...patch, _actor: ACTOR } });
158
+ }
159
+ return out;
160
+ }
161
+ function rowsFor(table, ids, deferred) {
162
+ const relation = new Map(table.fields.filter((f) => f.parityType === "relation").map((f) => [f.key, f]));
163
+ const derived = new Set(table.fields.filter((f) => COMPUTED.has(f.parityType)).map((f) => f.key));
164
+ const idOf = (target, key) => {
165
+ const id = ids.get(`${target}.${String(key)}`);
166
+ if (!id) throw new Error(`A row points at "${String(key)}" in "${target}", which the template does not have.`);
167
+ return id;
168
+ };
169
+ const rows = table.rows.map((r) => {
170
+ const values = {};
171
+ for (const [key, value] of Object.entries(r.values ?? {})) {
172
+ if (derived.has(key) || deferred?.has(key) || value === null || value === void 0) continue;
173
+ const rel = relation.get(key);
174
+ if (!rel?.relationTarget) {
175
+ values[key] = value;
176
+ continue;
177
+ }
178
+ values[key] = Array.isArray(value) ? value.map((v) => idOf(rel.relationTarget, v)) : idOf(rel.relationTarget, value);
179
+ }
180
+ values["_actor"] = ACTOR;
181
+ return values;
182
+ });
183
+ return { rows, ids: table.rows.map((r) => ids.get(`${table.token}.${r.key}`)) };
184
+ }
185
+ function derivedFieldSpec(field) {
186
+ const base = {
187
+ key: field.key,
188
+ label: field.label,
189
+ type: field.parityType,
190
+ via: field.via,
191
+ sensitivity: field.sensitivity,
192
+ context_policy: field.contextPolicy,
193
+ ...field.unit ? { unit: field.unit } : {}
194
+ };
195
+ return field.parityType === "rollup" ? { ...base, agg: field.agg, of: field.pick, ...field.filter ? { filter: field.filter } : {} } : { ...base, pick: field.pick };
196
+ }
197
+ function viewSpec(view, fieldIds = {}) {
198
+ const definition = { layout: view.kind };
199
+ const where = anyOfWhere(view.anyOf, fieldIds);
200
+ if (where) definition["where"] = where;
201
+ if (view.sorts?.length) definition["sorts"] = view.sorts;
202
+ if (view.isDefault) definition["is_default"] = true;
203
+ if (view.hiddenFields?.length) definition["presentation"] = { hiddenFields: view.hiddenFields };
204
+ switch (view.kind) {
205
+ case "kanban":
206
+ definition["group_field"] = view.groupBy;
207
+ if (view.swimlaneBy) definition["swimlane_field"] = view.swimlaneBy;
208
+ if (view.measure) definition["measure"] = view.measure;
209
+ break;
210
+ case "calendar":
211
+ definition["date_field"] = view.dateField;
212
+ break;
213
+ case "gallery":
214
+ definition["image_field"] = view.coverField;
215
+ break;
216
+ case "grid":
217
+ if (view.groupBy) {
218
+ definition["presentation"] = { ...definition["presentation"] ?? {}, grouping: { field: view.groupBy } };
219
+ }
220
+ break;
221
+ case "timeline":
222
+ definition["start_field"] = view.startField;
223
+ definition["end_field"] = view.endField;
224
+ if (view.groupBy) definition["group_field"] = view.groupBy;
225
+ break;
226
+ }
227
+ return { name: view.name, definition, ...view.filters ? { filters: view.filters } : {} };
228
+ }
229
+ function anyOfWhere(anyOf, fieldIds) {
230
+ const entries = Object.entries(anyOf ?? {}).filter(([, vals]) => vals.length);
231
+ if (!entries.length) return void 0;
232
+ return {
233
+ op: "and",
234
+ args: entries.map(([key, vals]) => {
235
+ const id = fieldIds[key];
236
+ if (!id) throw new Error(`The view filters on "${key}", which the install has no field id for.`);
237
+ return { op: "or", args: vals.map((v) => ({ op: "eq", args: [{ field: id }, { const: v }] })) };
238
+ })
239
+ };
240
+ }
241
+ function formulaFieldSpec(field) {
242
+ return {
243
+ key: field.key,
244
+ label: field.label,
245
+ type: "formula",
246
+ formula_text: field.formula,
247
+ ...field.unit ? { unit: field.unit } : {},
248
+ sensitivity: field.sensitivity,
249
+ context_policy: field.contextPolicy
250
+ };
251
+ }
252
+ function formulaOrder(table) {
253
+ const formulas = table.fields.filter((f) => f.parityType === "formula");
254
+ const out = [];
255
+ const left = [...formulas];
256
+ while (left.length) {
257
+ const i = left.findIndex((f) => !left.some((g) => g !== f && (f.formula ?? "").includes(`{${g.label}}`)));
258
+ out.push(...left.splice(i < 0 ? 0 : i, 1));
259
+ }
260
+ return out;
261
+ }
262
+ function question(q) {
263
+ return { field: q.fieldKey, ask: q.ask, ...q.help ? { help: q.help } : {}, ...q.required ? { required: true } : {} };
264
+ }
265
+ function formArgs(org, tableId, form) {
266
+ return {
267
+ p_organization_id: org,
268
+ p_table_id: tableId,
269
+ p_title: form.name,
270
+ p_questions: form.fields.map(question),
271
+ p_presentation: { submit_label: form.submitLabel, thank_you: { title: "Thank you", body: form.confirmation } },
272
+ p_submission_cap: null,
273
+ p_quarantine_rule_id: null,
274
+ p_notify_rule_id: null,
275
+ p_form_id: null,
276
+ p_slug: null
277
+ };
278
+ }
279
+ function bookingArgs(org, tableId, booking) {
280
+ const a = booking.availability;
281
+ return {
282
+ p_organization_id: org,
283
+ p_table_id: tableId,
284
+ p_title: booking.title,
285
+ p_questions: booking.questions.map(question),
286
+ p_availability: {
287
+ timezone: a.timezone,
288
+ slot_minutes: a.slotMinutes,
289
+ buffer_minutes: a.bufferMinutes,
290
+ lead_minutes: a.leadMinutes,
291
+ max_per_day: a.maxPerDay,
292
+ days: a.days,
293
+ windows: a.windows
294
+ },
295
+ p_presentation: {},
296
+ p_submission_cap: null,
297
+ p_quarantine_rule_id: null,
298
+ p_notify_rule_id: null,
299
+ p_form_id: null,
300
+ p_slug: booking.slug ?? null,
301
+ p_home_id: null
302
+ };
303
+ }
304
+ function dashboardBlocks(dashboard, tables) {
305
+ return dashboard.blocks.map((b) => ({
306
+ title: b.title,
307
+ kind: b.kind,
308
+ ...b.table && b.table !== dashboard.table ? { table_id: tables[b.table] } : {},
309
+ ...b.groupBy ? { group_by: b.groupBy } : {},
310
+ ...b.measures ? { measures: b.measures } : {},
311
+ ...b.bucket ? { bucket: b.bucket } : {},
312
+ ...b.filter ? { filter: b.filter } : {},
313
+ ...b.span ? { span: b.span } : {},
314
+ ...b.stateKey ? { state_key: b.stateKey } : {},
315
+ ...b.days ? { days: b.days } : {}
316
+ }));
317
+ }
318
+ function stageRulesSpec(rules) {
319
+ return {
320
+ stage_field: { key: rules.stageField },
321
+ ...rules.transitions ? { transitions: rules.transitions } : {},
322
+ ...rules.requires ? { requires: rules.requires } : {},
323
+ ...rules.limits ? { limits: rules.limits } : {},
324
+ ...rules.movesMessage ? { moves_message: rules.movesMessage } : {}
325
+ };
326
+ }
327
+ function documentBody(doc, fieldIds, businessName) {
328
+ return doc.body.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g, (whole, key) => {
329
+ if (key === "business") return businessName;
330
+ const id = fieldIds[key];
331
+ return id ? `{{field:${id}}}` : whole;
332
+ });
333
+ }
334
+ function rowActionList(actions, fieldIds) {
335
+ return actions.map(
336
+ (a) => a.actionKind === "agent" ? { name: a.name, kind: "agent", prompt: a.prompt, ...a.color ? { color: a.color } : {}, confirm: !!a.confirm } : {
337
+ name: a.name,
338
+ kind: "update",
339
+ ...a.color ? { color: a.color } : {},
340
+ confirm: !!a.confirm,
341
+ steps: (a.steps ?? []).map(
342
+ (s) => s.set === "value" ? { field: fieldIds[s.field] ?? s.field, set: "value", value: s.value } : { field: fieldIds[s.field] ?? s.field, set: "clear" }
343
+ )
344
+ }
345
+ );
346
+ }
347
+ function stageFieldOf(tables, table, stage) {
348
+ if (!stage) return null;
349
+ const t = tables.find((x) => x.token === table);
350
+ return t?.fields.find((f) => (f.parityType === "select" || f.parityType === "multi_select") && f.choices?.includes(stage))?.key ?? null;
351
+ }
352
+ function drillDownDashboard(drill, dimensions) {
353
+ const path = dimensions.find((d) => d.table === drill.table)?.paths?.find((p) => p.key === drill.path);
354
+ if (!path?.levels.length) throw new Error(`The drill-down "${drill.name}" names the path "${drill.path}", which the Dimensions of "${drill.table}" do not declare.`);
355
+ const [key, grain] = path.levels[0].split(":");
356
+ const block = { title: drill.name, kind: grain ? "line" : "bar", measures: [{ op: "count" }] };
357
+ if (grain) block["bucket"] = { key, by: grain };
358
+ else block["group_by"] = [key];
359
+ return { name: drill.name, blocks: [block] };
360
+ }
361
+ function digestSpec(digest, viewId) {
362
+ return {
363
+ name: digest.name,
364
+ saved_view_id: viewId,
365
+ cadence: digest.cadence,
366
+ ...digest.schedule ? { schedule: digest.schedule } : {},
367
+ channel: digest.channel ?? "in_app",
368
+ event_key: "records.changed"
369
+ };
370
+ }
371
+ function checklistSpec(checklist, tables, forms, documents) {
372
+ const trigger = checklist.trigger ?? { kind: "manual" };
373
+ return {
374
+ name: checklist.name,
375
+ about_table_id: tables[checklist.aboutTable],
376
+ roles: (checklist.roles ?? []).map((r) => ({ role: r.role, ...r.label ? { label: r.label } : {} })),
377
+ steps: checklist.steps.map((st) => {
378
+ const req = st.requires;
379
+ const requires = !req ? void 0 : req.kind === "form" ? { kind: "form", form_id: forms[req.form] } : req.kind === "document" ? { kind: "document", template_id: documents[req.document] } : req;
380
+ return {
381
+ ref: st.ref,
382
+ title: st.title,
383
+ ...st.role ? { role: st.role } : {},
384
+ ...st.dueDays !== void 0 ? { due_days: st.dueDays } : {},
385
+ ...st.dependsOn?.length ? { depends_on: st.dependsOn } : {},
386
+ ...requires ? { requires } : {}
387
+ };
388
+ }),
389
+ trigger: trigger.kind === "manual" ? { kind: "manual" } : trigger.kind === "record_created" ? { kind: "record_created", table_id: tables[trigger.table] } : { kind: "status_reached", table_id: tables[trigger.table], status: trigger.status }
390
+ };
391
+ }
392
+ function automationHeld(a) {
393
+ return `The automation "${a.name}" is held for lane 11: no store door runs automations yet, so a template carrying one is held, never installed without it.`;
394
+ }
395
+ function bookingColumnsProblem(tables, booking) {
396
+ const t = tables.find((x) => x.token === booking.table);
397
+ if (!t) return `The booking page "${booking.title}" takes bookings into "${booking.table}", which the template does not have.`;
398
+ const slot = t.fields.find((f) => f.key === "slot");
399
+ if (!slot) {
400
+ return `The booking page "${booking.title}" writes each booked time into a column keyed "slot" on "${t.name}", and that table has none. Declare it (a required date-and-time, like "Visit time") so the seeded rows carry it; the door would add it after the rows and leave every seeded row missing a required value.`;
401
+ }
402
+ if (!slot.required) return `"${t.name}"'s "slot" column holds the booked time and the door requires it; declare it required and seed it on every row.`;
403
+ const missing = t.rows.filter((r) => r.values?.["slot"] === void 0 || r.values?.["slot"] === null || r.values?.["slot"] === "");
404
+ if (missing.length) return `"${t.name}" has ${missing.length} seeded row(s) with no "slot" (${missing[0].key}); the booking page makes it required, so those rows could never be edited.`;
405
+ for (const [key, label] of [["status", "Status"], ["booked_with", "With"]]) {
406
+ if (t.fields.some((f) => f.key === key)) continue;
407
+ const clash = t.fields.find((f) => f.label.trim().toLowerCase() === label.toLowerCase());
408
+ if (clash) return `The booking page adds a "${label}" column to "${t.name}", which already has one ("${clash.key}"). Rename that column, or key it "${key}".`;
409
+ }
410
+ const status = t.fields.find((f) => f.key === "status");
411
+ const words = new Set((status?.choices ?? []).map((c) => c.toLowerCase()));
412
+ if (status && (!words.has("booked") || !words.has("cancelled"))) {
413
+ return `The booking page writes "booked" and "cancelled" into "${t.name}"'s status, and its choices do not hold both.`;
414
+ }
415
+ return null;
416
+ }
417
+ function notificationParts(n, stageField) {
418
+ const filters = {};
419
+ if (n.when.event === "stage_entered" && n.when.stage && stageField) filters[stageField] = n.when.stage;
420
+ return {
421
+ view: { name: n.name, definition: { layout: "grid" }, filters },
422
+ subscription: { name: n.name, cadence: "instant", channel: n.channel, event_key: "records.changed" }
423
+ };
424
+ }
425
+ function portalArgs(org, portal, tables) {
426
+ return {
427
+ p_organization_id: org,
428
+ p_title: portal.title,
429
+ p_client_table_id: tables[portal.clientTable],
430
+ p_tables: portal.tables.map((t) => ({
431
+ table_id: tables[t.table],
432
+ names_via: t.namesVia,
433
+ visible_fields: t.visibleFields,
434
+ editable_fields: t.editableFields ?? [],
435
+ comments: !!t.comments
436
+ })),
437
+ p_portal_id: null,
438
+ p_slug: portal.slug ?? null,
439
+ p_sign_in_method: "magic_link",
440
+ p_config: null
441
+ };
442
+ }
443
+
444
+ // src/templates/types.ts
445
+ var RELATIVE_DATE = /^@(today|(?:last-|next-)?(?:mon|tue|wed|thu|fri|sat|sun))(?:([+-])(\d{1,4})([dwmyb]))?(~b)?(?: ([01]\d|2[0-3]):([0-5]\d))?$/;
446
+ var SHARED_BLOCKS = {
447
+ team_member: {
448
+ table: "team_member",
449
+ name: "Team",
450
+ labelSingular: "Team member",
451
+ labelPlural: "Team",
452
+ titleField: "full_name",
453
+ describes: "The people on the business's own team \u2014 who is assigned, who answers, who signs.",
454
+ fields: [
455
+ { key: "full_name", label: "Name", parityType: "text", sensitivity: "internal", contextPolicy: "include", required: true, sameAs: ["name", "full name", "employee name", "staff name"] },
456
+ { key: "role", label: "Role", parityType: "text", sensitivity: "internal", contextPolicy: "include", sameAs: ["role", "job title", "title", "position"] },
457
+ { key: "work_email", label: "Work email", parityType: "email", sensitivity: "confidential", contextPolicy: "summarize", sameAs: ["email", "work email", "email address"] },
458
+ { key: "mobile", label: "Mobile", parityType: "phone", sensitivity: "confidential", contextPolicy: "exclude", sameAs: ["phone", "mobile", "work phone", "cell", "phone number"] },
459
+ { key: "start_date", label: "Start date", parityType: "datetime", sensitivity: "internal", contextPolicy: "include", sameAs: ["start date", "hire date", "started", "date hired"] }
460
+ ],
461
+ copyThreshold: 3
462
+ }
463
+ };
464
+ var SHARED_BLOCK_IDS = Object.keys(SHARED_BLOCKS);
465
+
466
+ // src/templates/confidential.ts
467
+ var TABLE_KERNEL_ID = "11111111-0000-4000-8000-000000000001";
468
+ function membersAddRowsSteps(spec, tableRef) {
469
+ return (spec.membersAddRows ?? []).map((token) => ({
470
+ label: `members_add_rows.${token}`,
471
+ door: "record_change_many",
472
+ args: {
473
+ p_organization_id: "${org}",
474
+ p_table_id: TABLE_KERNEL_ID,
475
+ p_changes: [{ op: "update", record_id: tableRef(token), patch: { members_add_rows: true } }]
476
+ }
477
+ }));
478
+ }
479
+
480
+ // src/templates/extras.ts
481
+ function tablesOf(spec) {
482
+ return new Map((spec.tables ?? []).map((t) => [t.token, t]));
483
+ }
484
+ function planBinding(b, tables) {
485
+ const { rowIndex, ...rest } = b;
486
+ if (rowIndex === void 0) return rest;
487
+ const row = tables.get(b.table)?.rows?.[rowIndex];
488
+ if (!row) throw new Error(`The binding points at seed row ${rowIndex} of "${b.table}", which has no such row.`);
489
+ return { ...rest, rowKey: row.key };
490
+ }
491
+ function compileHostExtras(spec) {
492
+ const tables = tablesOf(spec);
493
+ const agentBindings = /* @__PURE__ */ new Map();
494
+ for (const v of spec.agent?.variables ?? []) if (v.binding) agentBindings.set(v.name, planBinding(v.binding, tables));
495
+ const extras = {};
496
+ if (spec.extraAgents?.length) {
497
+ extras.extraAgents = spec.extraAgents.map((a) => ({
498
+ key: a.key,
499
+ platformAgent: a.platformAgent,
500
+ name: a.name,
501
+ bindings: a.variables.map((v) => ({ variable: v.name, describes: v.describes, binding: planBinding(v.binding, tables) })),
502
+ ...a.tryIt ? { tryIt: a.tryIt } : {}
503
+ }));
504
+ }
505
+ if (spec.workflows?.length) extras.workflows = spec.workflows;
506
+ return { agentBindings, extras };
507
+ }
508
+
509
+ // src/store.generated.ts
510
+ var PARITY_FIELD_TYPES = [
511
+ { parity_type: "attachment", behavior: "relation", made_of: "REC-31: a File record reached through a relation, target the kernel `File` Table" },
512
+ { parity_type: "checkbox", behavior: "boolean", made_of: "a ticked or unticked answer, stored as a REAL boolean \u2014 and a record that never answered holds neither, so filters and group-by see three states, not two" },
513
+ { parity_type: "currency", behavior: "range", made_of: "FLD-N-1: a number whose UNIT is the currency and whose format is currency \u2014 on the Field, never in presentation" },
514
+ { parity_type: "datetime", behavior: "range", made_of: "a range of kind date or datetime \u2014 the dated modifier says the VALUES are dated, which is a different question" },
515
+ { parity_type: "email", behavior: "text", made_of: "text whose format is email" },
516
+ { parity_type: "formula", behavior: "formula", made_of: "FLD-9: a declared computation, on read or on write, evaluated by custom.rule_eval" },
517
+ { parity_type: "lookup", behavior: "formula", made_of: "a Value read THROUGH a relation \u2014 config.via names the relation field, config.pick the Value on the far side" },
518
+ { parity_type: "member", behavior: "relation", made_of: "a person: a relation whose target is the kernel `Person` Table" },
519
+ { parity_type: "multi_select", behavior: "list", made_of: "many choices from the same Table \u2014 the multi modifier, never a second behaviour" },
520
+ { parity_type: "percent", behavior: "range", made_of: "a number whose unit is % and whose format is percent" },
521
+ { parity_type: "phone", behavior: "text", made_of: "text whose format is phone" },
522
+ { parity_type: "rollup", behavior: "formula", made_of: "an aggregate ALONG a relation \u2014 config.via, config.of, config.agg; far-side ids are taken DISTINCT, so nothing is counted twice" },
523
+ { parity_type: "select", behavior: "list", made_of: "one choice from a Table shown as a list (FLD-5/FLD-6)" },
524
+ { parity_type: "url", behavior: "text", made_of: "text whose format is url, with the pattern Rule that makes the format enforceable" }
525
+ ];
526
+ var DECLARABLE_FIELD_KINDS = [
527
+ { kind: "address", behavior: "text", parity: false, made_of: "P4: behaviour text, format address; the value is {street, city, region, postal_code, country}, every part optional, at least one filled" },
528
+ { kind: "attachment", behavior: "relation", parity: true, made_of: "REC-31: a File record reached through a relation, target the kernel `File` Table" },
529
+ { kind: "barcode", behavior: "text", parity: false, made_of: "P4: behaviour text, format barcode; one printable line a scanner reads, config.symbology optional (custom.barcode_symbologies()), EAN/UPC digits and check digit enforced" },
530
+ { kind: "checkbox", behavior: "boolean", parity: true, made_of: "a ticked or unticked answer, stored as a REAL boolean \u2014 and a record that never answered holds neither, so filters and group-by see three states, not two" },
531
+ { kind: "count", behavior: "formula", parity: false, made_of: "P4: a roll-up whose config.agg is count, with format count: how many records a many-relation points at, as a number of its own" },
532
+ { kind: "created_by", behavior: "formula", parity: false, made_of: "P4: a formula Field whose config.system is created_by: who made the record, {id, name}, filled by the store from the record's writer on read and never typed" },
533
+ { kind: "currency", behavior: "range", parity: true, made_of: "FLD-N-1: a number whose UNIT is the currency and whose format is currency \u2014 on the Field, never in presentation" },
534
+ { kind: "datetime", behavior: "range", parity: true, made_of: "a range of kind date or datetime \u2014 the dated modifier says the VALUES are dated, which is a different question" },
535
+ { kind: "duration", behavior: "range", parity: false, made_of: "P4: behaviour range, format duration, unit seconds; a length of time kept as seconds, never below zero" },
536
+ { kind: "email", behavior: "text", parity: true, made_of: "text whose format is email" },
537
+ { kind: "entity_reference", behavior: "relation", parity: false, made_of: "SC-R / P12: a relation whose target mode is any (REL-8), restricted by config.allowed_types to the platform kinds it may name (custom.entity_reference_kinds() \u2014 agents, notes, web sites, workbooks, datasets, conversations \u2026); each value is {token, id}, the edge a platform.associations row record \u2192 <token>. File and Person stay relations to their kernel Tables" },
538
+ { kind: "formula", behavior: "formula", parity: true, made_of: "FLD-9: a declared computation, on read or on write, evaluated by custom.rule_eval" },
539
+ { kind: "long_text", behavior: "text", parity: false, made_of: "behaviour text with format long and config.multiline, for several lines rather than one" },
540
+ { kind: "lookup", behavior: "formula", parity: true, made_of: "a Value read THROUGH a relation \u2014 config.via names the relation field, config.pick the Value on the far side" },
541
+ { kind: "member", behavior: "relation", parity: true, made_of: "a person: a relation whose target is the kernel `Person` Table" },
542
+ { kind: "modified_by", behavior: "formula", parity: false, made_of: "P4: a formula Field whose config.system is modified_by: who last changed the record, {id, name}, filled by the store on read and never typed" },
543
+ { kind: "multi_select", behavior: "list", parity: true, made_of: "many choices from the same Table \u2014 the multi modifier, never a second behaviour" },
544
+ { kind: "number", behavior: "range", parity: false, made_of: "a plain number: behaviour range with no date kind and neither the currency nor the percent format" },
545
+ { kind: "percent", behavior: "range", parity: true, made_of: "a number whose unit is % and whose format is percent" },
546
+ { kind: "phone", behavior: "text", parity: true, made_of: "text whose format is phone" },
547
+ { kind: "rating", behavior: "range", parity: false, made_of: "P4: behaviour range, format rating; a whole number of stars from 0 to its max Rule (1 to 10, default 5), shown as stars" },
548
+ { kind: "relation", behavior: "relation", parity: false, made_of: "REL / FLD-11: a relation a person aims themselves \u2014 relation_target names a Table of this organization, and it is a BEHAVIOUR, never a parity type of its own" },
549
+ { kind: "rich_text", behavior: "text", parity: false, made_of: "P4: behaviour text, format rich_text; Markdown with no raw HTML and no script links, shown formatted" },
550
+ { kind: "rollup", behavior: "formula", parity: true, made_of: "an aggregate ALONG a relation \u2014 config.via, config.of, config.agg; far-side ids are taken DISTINCT, so nothing is counted twice" },
551
+ { kind: "select", behavior: "list", parity: true, made_of: "one choice from a Table shown as a list (FLD-5/FLD-6)" },
552
+ { kind: "signature", behavior: "text", parity: false, made_of: "VAL-10: behaviour text whose format is signature \u2014 the one shape custom.doc_sign accepts, sealed by custom.doc_signature_write and checked by custom.doc_signature_intact" },
553
+ { kind: "status", behavior: "list", parity: false, made_of: "P4: a single-choice list with format status; config.status_groups puts each choice key in todo, in_progress or done (Notion's Status)" },
554
+ { kind: "text", behavior: "text", parity: false, made_of: "plain text: behaviour text with no format \u2014 it carries no parity type, which is exactly what custom.parity_type answers for it" },
555
+ { kind: "url", behavior: "text", parity: true, made_of: "text whose format is url, with the pattern Rule that makes the format enforceable" }
556
+ ];
557
+ var STORE_DOORS = [
558
+ { name: "absence_reasons", args: "", returns: "text[]", security: "invoker" },
559
+ { name: "action_declare", args: "p_organization_id uuid, p_table_id uuid, p_actions jsonb", returns: "jsonb", security: "definer" },
560
+ { name: "action_run", args: "p_organization_id uuid, p_action_id uuid, p_record_ids uuid[]", returns: "jsonb", security: "definer" },
561
+ { name: "actor_vocabulary", args: "", returns: "text[]", security: "invoker" },
562
+ { name: "actor_word", args: "p_declared text", returns: "text", security: "invoker" },
563
+ { name: "addressed_cap", args: "p_user_id uuid, p_type text, p_id uuid, p_organization_id uuid DEFAULT NULL::uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "permission_level", security: "definer" },
564
+ { name: "addressed_cap_specific", args: "p_user_id uuid, p_type text, p_id uuid, p_organization_id uuid DEFAULT NULL::uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "permission_level", security: "definer" },
565
+ { name: "agent_change_approval", args: "p_organization uuid, p_conversation uuid DEFAULT NULL::uuid, p_table uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
566
+ { name: "agent_change_trust", args: "p_organization_id uuid, p_approval_id uuid", returns: "jsonb", security: "definer" },
567
+ { name: "agent_context", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 50", returns: "jsonb", security: "invoker" },
568
+ { name: "agent_context_value", args: "p_doc jsonb, p_key text, p_type text, p_organization_id uuid, p_record_id uuid, p_cap bigint", returns: "jsonb", security: "invoker" },
569
+ { name: "agent_context_value_cap", args: "p_organization_id uuid", returns: "bigint", security: "invoker" },
570
+ { name: "agent_table_claim", args: "p_organization uuid, p_table uuid, p_conversation uuid DEFAULT NULL::uuid", returns: "void", security: "definer" },
571
+ { name: "agg_assert_key", args: "p_key text", returns: "text", security: "invoker" },
572
+ { name: "agg_bucket_ordinal", args: "p_by text, p_window_from timestamp without time zone, p_at timestamp without time zone, p_week_start text", returns: "integer", security: "invoker" },
573
+ { name: "agg_buckets", args: "", returns: "text[]", security: "invoker" },
574
+ { name: "agg_cadence_normalize", args: "p_cadence text", returns: "text", security: "invoker" },
575
+ { name: "agg_calendar", args: "p_organization_id uuid", returns: "jsonb", security: "invoker" },
576
+ { name: "agg_compare_kinds", args: "", returns: "text[]", security: "invoker" },
577
+ { name: "agg_compare_windows", args: "p_organization_id uuid, p_compare jsonb, p_bucket jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "invoker" },
578
+ { name: "agg_deliver", args: "p_organization_id uuid, p_rule_id uuid, p_record_id uuid, p_channel text, p_recipient_user_id uuid, p_event_key text, p_subject text, p_body text, p_payload jsonb DEFAULT '{}'::jsonb, p_dedupe_suffix text DEFAULT NULL::text", returns: "uuid", security: "invoker" },
579
+ { name: "agg_deliver_quietly", args: "p_organization_id uuid, p_rule_id uuid, p_subject_id uuid, p_channel text, p_recipient_user_id uuid, p_event_key text, p_subject text, p_body text, p_payload jsonb, p_quiet_hours jsonb, p_link text, p_dedupe_suffix text DEFAULT NULL::text", returns: "uuid", security: "invoker" },
580
+ { name: "agg_delta", args: "p_current jsonb, p_prior jsonb", returns: "jsonb", security: "invoker" },
581
+ { name: "agg_digest_assemble", args: "p_organization_id uuid, p_rule_id uuid, p_since timestamp with time zone DEFAULT NULL::timestamp with time zone, p_until timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "jsonb", security: "invoker" },
582
+ { name: "agg_digest_due_at", args: "p_cadence text, p_schedule text, p_quiet jsonb, p_after timestamp with time zone", returns: "timestamp with time zone", security: "invoker" },
583
+ { name: "agg_digest_judged_at", args: "p_organization_id uuid, p_rule_id uuid", returns: "timestamp with time zone", security: "invoker" },
584
+ { name: "agg_digest_run", args: "p_organization_id uuid, p_rule_id uuid DEFAULT NULL::uuid, p_since timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "integer", security: "invoker" },
585
+ { name: "agg_digest_run_at", args: "p_organization_id uuid, p_rule_id uuid, p_since timestamp with time zone, p_now timestamp with time zone", returns: "integer", security: "invoker" },
586
+ { name: "agg_digest_tick", args: "", returns: "integer", security: "invoker" },
587
+ { name: "agg_digest_tick_at", args: "p_now timestamp with time zone, p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
588
+ { name: "agg_explain", args: "p_organization_id uuid, p_table_id uuid, p_group_by jsonb DEFAULT '[]'::jsonb, p_measures jsonb DEFAULT '[]'::jsonb, p_bucket jsonb DEFAULT NULL::jsonb, p_filter jsonb DEFAULT '{}'::jsonb, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "definer" },
589
+ { name: "agg_field_kind", args: "p_organization_id uuid, p_table_id uuid, p_key text", returns: "text", security: "invoker" },
590
+ { name: "agg_field_value_sql", args: "p_organization_id uuid, p_table_id uuid, p_key text", returns: "text", security: "invoker" },
591
+ { name: "agg_fields_readable_assert", args: "p_organization_id uuid, p_table_id uuid, p_keys text[], p_required text DEFAULT 'viewer'::text", returns: "void", security: "invoker" },
592
+ { name: "agg_last_digest_at", args: "p_organization_id uuid, p_rule_id uuid", returns: "timestamp with time zone", security: "invoker" },
593
+ { name: "agg_local_label", args: "p_local timestamp without time zone, p_tz text", returns: "text", security: "invoker" },
594
+ { name: "agg_moment_sql", args: "p_key text, p_tz text", returns: "text", security: "invoker" },
595
+ { name: "agg_operations", args: "", returns: "text[]", security: "invoker" },
596
+ { name: "agg_parse_moment", args: "p_raw text, p_tz text, p_what text", returns: "timestamp with time zone", security: "invoker" },
597
+ { name: "agg_period_start", args: "p_local timestamp without time zone, p_by text, p_week_start text DEFAULT 'monday'::text", returns: "timestamp without time zone", security: "invoker" },
598
+ { name: "agg_period_step", args: "p_by text", returns: "interval", security: "invoker" },
599
+ { name: "agg_quiet_until", args: "p_quiet jsonb, p_at timestamp with time zone", returns: "timestamp with time zone", security: "invoker" },
600
+ { name: "agg_record_name", args: "p_organization_id uuid, p_record_id uuid, p_state jsonb DEFAULT NULL::jsonb", returns: "text", security: "invoker" },
601
+ { name: "agg_sql", args: "p_organization_id uuid, p_table_id uuid, p_group_by jsonb DEFAULT '[]'::jsonb, p_measures jsonb DEFAULT '[]'::jsonb, p_bucket jsonb DEFAULT NULL::jsonb, p_filter jsonb DEFAULT '{}'::jsonb, p_limit integer DEFAULT 200, p_required text DEFAULT 'viewer'::text, p_window jsonb DEFAULT NULL::jsonb, p_search text DEFAULT NULL::text, p_time_zone text DEFAULT NULL::text", returns: "text", security: "invoker" },
602
+ { name: "agg_subscription_cadences", args: "", returns: "text[]", security: "invoker" },
603
+ { name: "agg_subscription_fire", args: "p_organization_id uuid, p_record_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_changed_field_ids jsonb DEFAULT '[]'::jsonb", returns: "integer", security: "invoker" },
604
+ { name: "agg_subscription_fire_entered", args: "p_organization_id uuid, p_record_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_since timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "integer", security: "invoker" },
605
+ { name: "agg_subscription_tick", args: "p_window interval DEFAULT '00:15:00'::interval", returns: "integer", security: "invoker" },
606
+ { name: "agg_subscriptions", args: "p_organization_id uuid, p_saved_view_id uuid DEFAULT NULL::uuid, p_cadence text DEFAULT NULL::text", returns: "TABLE(rule_id uuid, saved_view_id uuid, table_id uuid, cadence text, schedule text, quiet_hours jsonb, channel text, recipient_user_id uuid, event_key text, name text)", security: "invoker" },
607
+ { name: "agg_value_sql", args: "p_key text", returns: "text", security: "invoker" },
608
+ { name: "agg_value_text", args: "p_value jsonb", returns: "text", security: "invoker" },
609
+ { name: "agg_view_admits", args: "p_organization_id uuid, p_saved_view_id uuid, p_record_id uuid", returns: "boolean", security: "invoker" },
610
+ { name: "agg_view_admits_state", args: "p_definition jsonb, p_state jsonb", returns: "boolean", security: "invoker" },
611
+ { name: "agg_withheld_marker", args: "p_organization_id uuid, p_table_id uuid, p_key text, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "invoker" },
612
+ { name: "agg_zero", args: "p_measures jsonb", returns: "jsonb", security: "invoker" },
613
+ { name: "anon_capture", args: "p_organization_id uuid, p_client_key text, p_table_id uuid, p_payload jsonb, p_device text DEFAULT NULL::text, p_captured_at timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "uuid", security: "definer" },
614
+ { name: "anon_clear", args: "p_organization_id uuid, p_submission_id uuid", returns: "uuid", security: "definer" },
615
+ { name: "anon_inbound_land", args: "p_address text, p_secret text, p_payload jsonb, p_raw_payload jsonb DEFAULT '{}'::jsonb, p_client_key text DEFAULT NULL::text", returns: "uuid", security: "definer" },
616
+ { name: "anon_publish", args: "p_organization_id uuid, p_form_id uuid, p_published boolean DEFAULT true", returns: "timestamp with time zone", security: "definer" },
617
+ { name: "anon_rate_take", args: "p_organization_id uuid, p_form_id uuid, p_bucket text, p_token_id uuid DEFAULT NULL::uuid", returns: "integer", security: "definer" },
618
+ { name: "anon_submissions", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_state text DEFAULT NULL::text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, form_id uuid, inbound_id uuid, table_id uuid, source text, state text, payload jsonb, raw_payload jsonb, client_key text, record_id uuid, remote_origin text, rejection_reason text, created_at timestamp with time zone, cleared_at timestamp with time zone)", security: "definer" },
619
+ { name: "anon_token_issue", args: "p_organization_id uuid, p_mode text, p_allowed_origins jsonb, p_form_id uuid DEFAULT NULL::uuid, p_saved_view_id uuid DEFAULT NULL::uuid, p_record_id uuid DEFAULT NULL::uuid, p_expires_at timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "TABLE(token_id uuid, secret text)", security: "definer" },
620
+ { name: "anon_token_revoke", args: "p_organization_id uuid, p_token_id uuid", returns: "boolean", security: "definer" },
621
+ { name: "anon_token_verify", args: "p_secret text, p_origin text, p_required_mode text", returns: "TABLE(token_id uuid, organization_id uuid, form_id uuid, saved_view_id uuid, record_id uuid, mode text)", security: "definer" },
622
+ { name: "anon_write", args: "p_secret text, p_origin text, p_payload jsonb, p_client_key text DEFAULT NULL::text, p_raw_payload jsonb DEFAULT '{}'::jsonb", returns: "uuid", security: "definer" },
623
+ { name: "applicable_fields", args: "p_organization_id uuid, p_table_id uuid, p_record_type text DEFAULT NULL::text", returns: "SETOF custom.record", security: "definer" },
624
+ { name: "archive_event_of", args: "p_organization_id uuid, p_record_id uuid", returns: "history.migration_log", security: "definer" },
625
+ { name: "archived_tables_everywhere", args: "p_lane text DEFAULT 'org'::text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0, p_sort text DEFAULT 'archived_at'::text, p_desc boolean DEFAULT true", returns: "jsonb", security: "definer" },
626
+ { name: "assert_client_may_change", args: "p_organization_id uuid, p_subject_id uuid, p_door text, p_required permission_level DEFAULT 'editor'::permission_level, p_subject_word text DEFAULT 'record'::text", returns: "void", security: "invoker" },
627
+ { name: "assert_client_may_open", args: "p_organization_id uuid, p_subject_id uuid, p_door text, p_required permission_level DEFAULT 'viewer'::permission_level, p_subject_word text DEFAULT 'record'::text", returns: "void", security: "invoker" },
628
+ { name: "assert_client_may_reach", args: "p_organization_id uuid, p_door text", returns: "void", security: "invoker" },
629
+ { name: "assert_columns_are_defined", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb", returns: "void", security: "definer" },
630
+ { name: "assert_entity_door", args: "p_organization_id uuid, p_door text", returns: "void", security: "definer" },
631
+ { name: "assert_entity_is_organization_scoped", args: "p_token text, p_label text, p_scoped boolean", returns: "void", security: "invoker" },
632
+ { name: "assert_may_know_table", args: "p_organization_id uuid, p_table_id uuid, p_door text", returns: "void", security: "invoker" },
633
+ { name: "assert_organization_admin", args: "p_organization_id uuid, p_door text, p_what text", returns: "void", security: "invoker" },
634
+ { name: "assert_organization_wall", args: "p_kind text, p_organization_id uuid, p_row jsonb", returns: "void", security: "invoker" },
635
+ { name: "assert_scope_door", args: "p_organization_id uuid, p_door text", returns: "void", security: "definer" },
636
+ { name: "assert_store_door", args: "p_organization_id uuid, p_door text", returns: "void", security: "invoker" },
637
+ { name: "autonumber_backfill", args: "p_organization_id uuid, p_field_id uuid", returns: "jsonb", security: "definer" },
638
+ { name: "barcode_symbologies", args: "", returns: "text[]", security: "invoker" },
639
+ { name: "booking_cancel", args: "p_booking_ref text, p_origin text DEFAULT NULL::text", returns: "TABLE(booking_ref text, record_id uuid, slot_key text, state text, message text)", security: "definer" },
640
+ { name: "booking_confirm", args: "p_form_id uuid, p_hold_id uuid, p_origin text, p_payload jsonb, p_bucket text, p_honeypot text DEFAULT NULL::text, p_client_key text DEFAULT NULL::text", returns: "TABLE(booking_ref text, record_id uuid, submission_id uuid, slot_key text, slot_at timestamp with time zone, state text, message text)", security: "definer" },
641
+ { name: "booking_declare", args: "p_organization_id uuid, p_table_id uuid, p_title text, p_questions jsonb, p_availability jsonb DEFAULT '{}'::jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_submission_cap integer DEFAULT NULL::integer, p_quarantine_rule_id uuid DEFAULT NULL::uuid, p_notify_rule_id uuid DEFAULT NULL::uuid, p_form_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text, p_home_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
642
+ { name: "booking_hold", args: "p_form_id uuid, p_slot_key text, p_origin text, p_bucket text, p_client_key text DEFAULT NULL::text", returns: "TABLE(hold_id uuid, slot_key text, expires_at timestamp with time zone, member_user_id uuid, state text, message text)", security: "definer" },
643
+ { name: "booking_manage", args: "p_booking_ref text, p_days integer DEFAULT NULL::integer", returns: "TABLE(booking_ref text, form_id uuid, title text, slot_key text, slot_at timestamp with time zone, status text, slots jsonb, availability jsonb, state text, message text)", security: "definer" },
644
+ { name: "booking_notify", args: "p_organization_id uuid, p_form_id uuid, p_record_id uuid, p_submission_id uuid, p_event text, p_when text", returns: "uuid", security: "invoker" },
645
+ { name: "booking_public", args: "p_form_id uuid, p_days integer DEFAULT NULL::integer", returns: "TABLE(form_id uuid, organization_id uuid, table_id uuid, title text, presentation jsonb, fields jsonb, honeypot_key text, availability jsonb, slots jsonb, state text, message text)", security: "definer" },
646
+ { name: "booking_reschedule", args: "p_booking_ref text, p_slot_key text, p_origin text, p_bucket text DEFAULT NULL::text", returns: "TABLE(booking_ref text, record_id uuid, slot_key text, slot_at timestamp with time zone, state text, message text)", security: "definer" },
647
+ { name: "bookings", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(form_id uuid, table_id uuid, title text, slug text, published_at timestamp with time zone, closed_at timestamp with time zone, slot_minutes integer, timezone text, slot_table_id uuid, booked bigint, cancelled bigint, upcoming bigint, held bigint, next_at timestamp with time zone, state text)", security: "definer" },
648
+ { name: "bump_epoch", args: "p_entity_type text, p_entity_id uuid, p_organization_id uuid DEFAULT NULL::uuid", returns: "bigint", security: "definer" },
649
+ { name: "cache_lookup", args: "p_container_type text, p_container_id uuid, p_item_type text, p_item_id uuid", returns: "permission_level", security: "definer" },
650
+ { name: "caller_role", args: "", returns: "name", security: "invoker" },
651
+ { name: "capture_open", args: "p_organization_id uuid, p_sheet_id uuid", returns: "TABLE(sheet_id uuid, organization_id uuid, table_id uuid, title text, presentation jsonb, fields jsonb, state text, may_capture boolean, message text)", security: "definer" },
652
+ { name: "capture_publish", args: "p_organization_id uuid, p_sheet_id uuid, p_open boolean DEFAULT true", returns: "timestamp with time zone", security: "definer" },
653
+ { name: "capture_sheet_declare", args: "p_organization_id uuid, p_table_id uuid, p_title text, p_questions jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_sheet_id uuid DEFAULT NULL::uuid, p_notify_rule_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
654
+ { name: "capture_sheets", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(sheet_id uuid, table_id uuid, title text, slug text, state text, opened_at timestamp with time zone, captures bigint, replays bigint, last_capture_at timestamp with time zone, presentation jsonb)", security: "definer" },
655
+ { name: "capture_submit", args: "p_organization_id uuid, p_sheet_id uuid, p_client_key text, p_payload jsonb, p_files jsonb DEFAULT '[]'::jsonb, p_device text DEFAULT NULL::text, p_captured_at timestamp with time zone DEFAULT NULL::timestamp with time zone, p_location jsonb DEFAULT NULL::jsonb", returns: "TABLE(record_id uuid, state text, message text, replay boolean, file_ids uuid[])", security: "definer" },
656
+ { name: "carry_unchanged_value_stamps", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
657
+ { name: "carrying_edges_in", args: "p_organization_id uuid", returns: "TABLE(container_type text, container_id uuid, item_type text, item_id uuid, conveys_max permission_level)", security: "definer" },
658
+ { name: "carrying_edges_of", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, conveys_max permission_level)", security: "definer" },
659
+ { name: "checklist_declare", args: "p_organization_id uuid, p_spec jsonb, p_template_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
660
+ { name: "checklist_refusal", args: "p_spec jsonb", returns: "text", security: "invoker" },
661
+ { name: "checklist_run", args: "p_organization_id uuid, p_run_id uuid", returns: "TABLE(step_id uuid, step_order integer, ref text, title text, role text, assignee_name text, assignee_user_id uuid, due_on timestamp with time zone, due_state text, status text, finished boolean, requires text, requires_key text, requires_label text, requires_id uuid, evidence jsonb, blocked_by text[], may_complete boolean, refusal text)", security: "definer" },
662
+ { name: "checklist_runs", args: "p_organization_id uuid, p_about_table_id uuid DEFAULT NULL::uuid, p_about_record_id uuid DEFAULT NULL::uuid, p_include_closed boolean DEFAULT true, p_limit integer DEFAULT 100", returns: "TABLE(run_id uuid, name text, template_id uuid, template text, about_record_id uuid, about text, about_table_id uuid, started_at timestamp with time zone, started_by uuid, origin text, step_count integer, done integer, overdue integer, next_step text, next_due timestamp with time zone, closed_at timestamp with time zone)", security: "definer" },
663
+ { name: "checklist_start", args: "p_organization_id uuid, p_template_id uuid, p_about_record_id uuid DEFAULT NULL::uuid, p_roles jsonb DEFAULT '{}'::jsonb, p_starting_at timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "jsonb", security: "definer" },
664
+ { name: "checklist_step_complete", args: "p_organization_id uuid, p_step_id uuid, p_evidence jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
665
+ { name: "checklist_step_refusal", args: "p_organization_id uuid, p_step_id uuid", returns: "text", security: "definer" },
666
+ { name: "checklist_steps_table", args: "p_organization_id uuid", returns: "uuid", security: "definer" },
667
+ { name: "checklist_template_shape", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
668
+ { name: "checklist_templates", args: "p_organization_id uuid, p_about_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(template_id uuid, name text, about_table_id uuid, about_table text, steps integer, roles integer, trigger_kind text, trigger_status text, open_runs integer, total_runs integer, updated_at timestamp with time zone)", security: "definer" },
669
+ { name: "checklist_templates_archived", args: "p_organization_id uuid, p_about_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(template_id uuid, name text, about_table_id uuid, about_table text, steps integer, archived_at timestamp with time zone, archived_by uuid, table_archived boolean)", security: "definer" },
670
+ { name: "choice_census", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
671
+ { name: "choice_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
672
+ { name: "choice_filter_normalize", args: "p_map jsonb, p_filter jsonb", returns: "jsonb", security: "invoker" },
673
+ { name: "choice_key_for", args: "p_organization_id uuid, p_options_table_id uuid, p_title text, p_exclude uuid DEFAULT NULL::uuid", returns: "text", security: "invoker" },
674
+ { name: "choice_key_of", args: "p_field jsonb, p_token text", returns: "text", security: "invoker" },
675
+ { name: "choice_nudge", args: "p_organization_id uuid", returns: "text", security: "definer" },
676
+ { name: "choice_options", args: "p_organization_id uuid, p_options_table_id uuid", returns: "jsonb", security: "invoker" },
677
+ { name: "choice_render", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb", returns: "jsonb", security: "invoker" },
678
+ { name: "choice_render_groups", args: "p_map jsonb, p_groups jsonb", returns: "jsonb", security: "invoker" },
679
+ { name: "choice_render_note", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
680
+ { name: "choice_render_plan", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
681
+ { name: "choice_render_value", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
682
+ { name: "choice_render_with", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb, p_plan jsonb", returns: "jsonb", security: "invoker" },
683
+ { name: "choice_slug", args: "p_word text", returns: "text", security: "invoker" },
684
+ { name: "choice_synonyms", args: "p_organization_id uuid, p_table_id uuid, p_token text", returns: "text[]", security: "invoker" },
685
+ { name: "choice_synonyms_in", args: "p_map jsonb, p_token text", returns: "text[]", security: "invoker" },
686
+ { name: "choice_words", args: "p_field jsonb", returns: "text", security: "invoker" },
687
+ { name: "client_write_grants", args: "", returns: "TABLE(role_name text, object_name text, privilege text)", security: "invoker" },
688
+ { name: "comment_mention_deliver", args: "p_organization_id uuid, p_record_id uuid, p_table_id uuid, p_comment_id uuid, p_recipient uuid, p_author_name text, p_record_title text, p_body text", returns: "uuid", security: "definer" },
689
+ { name: "comment_thread", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "jsonb", security: "definer" },
690
+ { name: "comment_write", args: "p_organization_id uuid, p_record_id uuid, p_body text, p_anchor jsonb DEFAULT '{}'::jsonb, p_parent_comment_id uuid DEFAULT NULL::uuid, p_mentions uuid[] DEFAULT NULL::uuid[]", returns: "jsonb", security: "definer" },
691
+ { name: "computed_block", args: "p_block jsonb", returns: "jsonb", security: "invoker" },
692
+ { name: "computed_provenance", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, value jsonb, rule_id uuid, rule_version integer, computed_at timestamp with time zone)", security: "definer" },
693
+ { name: "confidential_anchor", args: "p_id uuid", returns: "uuid", security: "definer" },
694
+ { name: "confidential_answer", args: "p_user uuid, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
695
+ { name: "confidential_header", args: "p_user uuid, p_id uuid", returns: "jsonb", security: "invoker" },
696
+ { name: "confidential_names", args: "p_organization_id uuid, p_value jsonb, p_user uuid", returns: "boolean", security: "definer" },
697
+ { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
698
+ { name: "containment_depth_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
699
+ { name: "containment_edges", args: "p_organization_id uuid", returns: "TABLE(parent_id uuid, child_id uuid, via text)", security: "invoker" },
700
+ { name: "containment_parent", args: "p_data jsonb", returns: "uuid", security: "invoker" },
701
+ { name: "context_archived_types", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
702
+ { name: "context_class_for_checkout", args: "p_scope_id uuid", returns: "jsonb", security: "definer" },
703
+ { name: "context_compare_facts", args: "p_user_id uuid, p_record_ids uuid[], p_item_ids uuid[] DEFAULT NULL::uuid[], p_cells jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "definer" },
704
+ { name: "context_item_archive", args: "p_item_id uuid", returns: "jsonb", security: "definer" },
705
+ { name: "context_item_restore", args: "p_item_id uuid", returns: "jsonb", security: "definer" },
706
+ { name: "context_item_row_of", args: "p_field custom.record", returns: "jsonb", security: "invoker" },
707
+ { name: "context_item_write", args: "p_item_id uuid, p_scope_type_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
708
+ { name: "context_items", args: "p_scope_type_ids uuid[]", returns: "jsonb", security: "definer" },
709
+ { name: "context_policy_rank", args: "p_policy text", returns: "integer", security: "invoker" },
710
+ { name: "context_resolve", args: "p_bindings jsonb", returns: "jsonb", security: "definer" },
711
+ { name: "context_scope_archive", args: "p_scope_id uuid", returns: "jsonb", security: "definer" },
712
+ { name: "context_scope_restore", args: "p_scope_id uuid", returns: "jsonb", security: "definer" },
713
+ { name: "context_scope_write", args: "p_organization_id uuid, p_scope_id uuid, p_type_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
714
+ { name: "context_scopes", args: "p_scope_ids uuid[]", returns: "jsonb", security: "definer" },
715
+ { name: "context_system_items", args: "", returns: "jsonb", security: "definer" },
716
+ { name: "context_tags_set", args: "p_entity_type text, p_entity_id uuid, p_scope_ids uuid[]", returns: "jsonb", security: "definer" },
717
+ { name: "context_template_define", args: "p_organization_id uuid, p_definition jsonb", returns: "jsonb", security: "invoker" },
718
+ { name: "context_templates", args: "", returns: "SETOF jsonb", security: "invoker" },
719
+ { name: "context_tree", args: "p_organization_ids uuid[]", returns: "jsonb", security: "definer" },
720
+ { name: "context_tree_search", args: "p_organization_ids uuid[], p_query text, p_limit integer DEFAULT 100", returns: "jsonb", security: "definer" },
721
+ { name: "context_tree_type_scopes", args: "p_scope_type_id uuid, p_offset integer DEFAULT 0, p_limit integer DEFAULT 200", returns: "jsonb", security: "definer" },
722
+ { name: "context_tree_types", args: "p_organization_ids uuid[], p_with_counts boolean DEFAULT true", returns: "jsonb", security: "definer" },
723
+ { name: "context_type_archive", args: "p_type_id uuid", returns: "jsonb", security: "definer" },
724
+ { name: "context_type_restore", args: "p_type_id uuid", returns: "jsonb", security: "definer" },
725
+ { name: "context_type_write", args: "p_organization_id uuid, p_type_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
726
+ { name: "context_value_write", args: "p_payload jsonb", returns: "jsonb", security: "invoker" },
727
+ { name: "context_values", args: "p_scope_ids uuid[]", returns: "jsonb", security: "definer" },
728
+ { name: "context_writer", args: "p_organization_id uuid", returns: "text", security: "definer" },
729
+ { name: "conversation_scope", args: "p_organization_id uuid, p_conversation_id uuid", returns: "jsonb", security: "definer" },
730
+ { name: "conversation_scope_bind", args: "p_organization_id uuid, p_conversation_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
731
+ { name: "conversation_scope_context", args: "p_organization_id uuid, p_conversation_id uuid, p_relations integer DEFAULT 12, p_history integer DEFAULT 15, p_siblings integer DEFAULT 8", returns: "jsonb", security: "definer" },
732
+ { name: "conversation_scope_unbind", args: "p_organization_id uuid, p_conversation_id uuid", returns: "jsonb", security: "definer" },
733
+ { name: "count_records_archived", args: "p_organization_id uuid, p_table_ids uuid[], p_lane text DEFAULT 'org'::text", returns: "TABLE(table_id uuid, n integer)", security: "definer" },
734
+ { name: "cross_organization_links_open", args: "p_source_organization_id uuid, p_target_organization_id uuid", returns: "boolean", security: "invoker" },
735
+ { name: "custom_fields_tables", args: "", returns: "TABLE(token text, schema_name text, table_name text)", security: "invoker" },
736
+ { name: "dashboard_block_normalize", args: "p_organization_id uuid, p_subject_table_id uuid, p_block jsonb", returns: "jsonb", security: "definer" },
737
+ { name: "dashboard_class", args: "", returns: "text", security: "invoker" },
738
+ { name: "dashboard_declare", args: "p_organization_id uuid, p_table_id uuid, p_name text, p_blocks jsonb DEFAULT '[]'::jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_dashboard_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
739
+ { name: "dashboard_delete", args: "p_organization_id uuid, p_dashboard_id uuid", returns: "boolean", security: "definer" },
740
+ { name: "dashboard_field_keys", args: "p_organization_id uuid, p_table_id uuid", returns: "text[]", security: "definer" },
741
+ { name: "dashboard_kinds", args: "", returns: "text[]", security: "invoker" },
742
+ { name: "dashboard_moment_sql", args: "p_key text", returns: "text", security: "invoker" },
743
+ { name: "dashboard_restore", args: "p_organization_id uuid, p_dashboard_id uuid", returns: "boolean", security: "definer" },
744
+ { name: "dashboard_run", args: "p_organization_id uuid, p_dashboard_id uuid, p_filter jsonb DEFAULT '{}'::jsonb, p_compare jsonb DEFAULT NULL::jsonb, p_grain text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
745
+ { name: "dashboard_stuck", args: "p_organization_id uuid, p_table_id uuid, p_state_key text, p_days integer DEFAULT 14, p_filter jsonb DEFAULT '{}'::jsonb, p_limit integer DEFAULT 50, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, title text, state text, last_changed_at timestamp with time zone, days_unchanged numeric, measured_from text)", security: "definer" },
746
+ { name: "dashboard_target_field_assert", args: "p_organization_id uuid, p_table_id uuid, p_field_key text", returns: "void", security: "invoker" },
747
+ { name: "dashboard_window_sql", args: "p_key text, p_window jsonb", returns: "text", security: "invoker" },
748
+ { name: "dashboards", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(dashboard_id uuid, table_id uuid, name text, blocks jsonb, presentation jsonb, block_count integer, version integer, created_at timestamp with time zone, updated_at timestamp with time zone)", security: "definer" },
749
+ { name: "data_home", args: "p_organization_id uuid DEFAULT NULL::uuid, p_search text DEFAULT NULL::text, p_include_app_tables boolean DEFAULT false", returns: "jsonb", security: "definer" },
750
+ { name: "data_home_changed_by", args: "p_asks jsonb", returns: "TABLE(organization_id uuid, id uuid, at timestamp with time zone, who text)", security: "definer" },
751
+ { name: "data_home_items", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(kind text, organization_id uuid, organization_name text, item_id uuid, table_id uuid, table_name text, item_row jsonb)", security: "definer" },
752
+ { name: "data_home_tables", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(table_id uuid, table_name text, organization_id uuid, organization_name text, member boolean, visibility text, updated_at timestamp with time zone, mine boolean, shared_with_me boolean, kept_by_the_app boolean, kind text, team boolean, system boolean, created_by uuid)", security: "definer" },
753
+ { name: "data_home_tables", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "TABLE(table_id uuid, table_name text, organization_id uuid, organization_name text, member boolean, visibility text, updated_at timestamp with time zone, mine boolean, shared_with_me boolean, kept_by_the_app boolean, kind text, team boolean, system boolean, created_by uuid)", security: "invoker" },
754
+ { name: "declared_conversation", args: "", returns: "uuid", security: "invoker" },
755
+ { name: "decoration_colors", args: "", returns: "text[]", security: "invoker" },
756
+ { name: "decoration_rule_ops", args: "", returns: "TABLE(op text, takes_value boolean, label text)", security: "invoker" },
757
+ { name: "delete_cascade_closure", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid[]", security: "invoker" },
758
+ { name: "delete_preview", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
759
+ { name: "delete_rule", args: "p_organization_id uuid, p_record_id uuid, p_apply boolean DEFAULT true", returns: "jsonb", security: "definer" },
760
+ { name: "dependency_cycle", args: "p_organization_id uuid, p_row custom.record", returns: "text[]", security: "invoker" },
761
+ { name: "dependency_label", args: "p_organization_id uuid, p_node text", returns: "text", security: "invoker" },
762
+ { name: "derive_visibility", args: "p_container_type text, p_container_id uuid", returns: "TABLE(item_type text, item_id uuid, depth integer, max_level permission_level)", security: "definer" },
763
+ { name: "derived_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb, p_values jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "invoker" },
764
+ { name: "derived_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
765
+ { name: "derived_values_of", args: "v_rec custom.record", returns: "jsonb", security: "invoker" },
766
+ { name: "display_format_ids", args: "", returns: "text[]", security: "invoker" },
767
+ { name: "doc_content_hash", args: "p_body text", returns: "text", security: "invoker" },
768
+ { name: "doc_format_value", args: "p_field_data jsonb, p_value jsonb", returns: "text", security: "invoker" },
769
+ { name: "doc_letterhead", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
770
+ { name: "doc_name_token_pattern", args: "", returns: "text", security: "invoker" },
771
+ { name: "doc_name_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text)", security: "invoker" },
772
+ { name: "doc_render_body", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "text", security: "invoker" },
773
+ { name: "doc_render_document", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
774
+ { name: "doc_render_read", args: "p_organization_id uuid, p_render_id uuid", returns: "jsonb", security: "definer" },
775
+ { name: "doc_render_write", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid, p_table_id uuid, p_template_version integer, p_body text, p_content_hash text", returns: "uuid", security: "definer" },
776
+ { name: "doc_renders", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(render_id uuid, template_id uuid, record_id uuid, table_id uuid, template_version integer, body text, content_hash text, rendered_at timestamp with time zone)", security: "definer" },
777
+ { name: "doc_sign", args: "p_organization_id uuid, p_render_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
778
+ { name: "doc_signature_field_ok", args: "p_field_data jsonb", returns: "boolean", security: "invoker" },
779
+ { name: "doc_signature_intact", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "invoker" },
780
+ { name: "doc_signature_read", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "definer" },
781
+ { name: "doc_signature_write", args: "p_organization_id uuid, p_render_id uuid, p_record_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid, p_document_hash text, p_document_version integer", returns: "uuid", security: "definer" },
782
+ { name: "doc_signatures", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(signature_id uuid, render_id uuid, record_id uuid, field_key text, signer_name text, signer_user_id uuid, signed_at timestamp with time zone, document_hash text, document_version integer)", security: "definer" },
783
+ { name: "doc_template_delete", args: "p_organization_id uuid, p_template_id uuid", returns: "boolean", security: "definer" },
784
+ { name: "doc_template_read", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
785
+ { name: "doc_template_restore", args: "p_organization_id uuid, p_template_id uuid", returns: "boolean", security: "definer" },
786
+ { name: "doc_template_save", args: "p_organization_id uuid, p_table_id uuid, p_name text, p_body text, p_template_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
787
+ { name: "doc_templates", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(template_id uuid, renders_table_id uuid, name text, body text, template_version integer, token_count bigint, updated_at timestamp with time zone)", security: "definer" },
788
+ { name: "doc_token_pattern", args: "", returns: "text", security: "invoker" },
789
+ { name: "doc_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text, field_id uuid)", security: "invoker" },
790
+ { name: "doc_unresolved_tokens", args: "p_organization_id uuid, p_table_id uuid, p_body text", returns: "TABLE(raw text, field_id uuid, why text)", security: "invoker" },
791
+ { name: "doors_not_deciding_the_caller", args: "", returns: "TABLE(function_name text, identity_args text)", security: "invoker" },
792
+ { name: "doors_not_deciding_the_record", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
793
+ { name: "doors_not_masking_fields", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
794
+ { name: "doors_not_on_one_ladder", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
795
+ { name: "doors_refusing_in_another_doors_name", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
796
+ { name: "drill_resolve", args: "p_organization_id uuid, p_table_id uuid, p_group_by jsonb, p_measures jsonb, p_bucket jsonb", returns: "jsonb", security: "invoker" },
797
+ { name: "effective_level", args: "p_user_id uuid, p_organization_id uuid, p_id uuid, p_type text DEFAULT 'record'::text", returns: "permission_level", security: "definer" },
798
+ { name: "enrich_cells", args: "p_organization_id uuid, p_table_id uuid, p_field_keys text[] DEFAULT NULL::text[], p_record_ids uuid[] DEFAULT NULL::uuid[]", returns: "TABLE(record_id uuid, field_key text, agent_owned boolean, value jsonb, value_version integer, actor text, on_behalf_of text, written_at timestamp with time zone, source jsonb, absent_reason text, alternates jsonb, pinned boolean, stale boolean, due_at timestamp with time zone)", security: "definer" },
799
+ { name: "enrich_declare", args: "p_organization_id uuid, p_field_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
800
+ { name: "enrich_due", args: "p_organization_id uuid, p_field_id uuid, p_limit integer DEFAULT 50, p_include_fresh boolean DEFAULT false, p_record_ids uuid[] DEFAULT NULL::uuid[]", returns: "TABLE(record_id uuid, title text, inputs jsonb, current_value jsonb, written_at timestamp with time zone, reason text, trimmed_to integer)", security: "definer" },
801
+ { name: "enrich_land", args: "p_organization_id uuid, p_field_id uuid, p_results jsonb, p_run jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
802
+ { name: "enrich_normalize", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_spec jsonb", returns: "jsonb", security: "definer" },
803
+ { name: "enrich_pin", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_pinned boolean DEFAULT true", returns: "jsonb", security: "definer" },
804
+ { name: "enrich_run_class", args: "", returns: "text", security: "invoker" },
805
+ { name: "enrich_runs", args: "p_organization_id uuid, p_field_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 50", returns: "TABLE(run_id uuid, field_id uuid, field_key text, model text, trigger_word text, rows_seen integer, rows_written integer, rows_absent integer, rows_below_floor integer, rows_pinned integer, rows_refused integer, cost_cents numeric, cost_per_row_cents numeric, ran_at timestamp with time zone)", security: "definer" },
806
+ { name: "enrich_sensitivity_rank", args: "p_word text", returns: "integer", security: "invoker" },
807
+ { name: "enrich_triggers", args: "", returns: "text[]", security: "invoker" },
808
+ { name: "enrichments", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(field_id uuid, table_id uuid, field_key text, label text, enrichment jsonb, enabled boolean, review_interval_days integer, rows_total integer, rows_filled integer, rows_stale integer, rows_pinned integer, rows_absent integer, runs integer, cost_cents numeric, cost_per_row_cents numeric, last_run_at timestamp with time zone, last_run jsonb)", security: "definer" },
809
+ { name: "entity_field_declare", args: "p_organization_id uuid, p_token text, p_spec jsonb", returns: "uuid", security: "definer" },
810
+ { name: "entity_field_protect_arman_explicitly_approved", args: "p_field_id uuid, p_readers jsonb, p_arman_words text, p_approved_on date", returns: "jsonb", security: "definer" },
811
+ { name: "entity_field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "uuid", security: "definer" },
812
+ { name: "entity_field_rights", args: "p_organization_id uuid, p_token text", returns: "jsonb", security: "definer" },
813
+ { name: "entity_field_update", args: "p_organization_id uuid, p_field_id uuid, p_patch jsonb", returns: "uuid", security: "definer" },
814
+ { name: "entity_fields", args: "p_organization_id uuid, p_token text", returns: "SETOF custom.record", security: "definer" },
815
+ { name: "entity_fields_across", args: "p_token text, p_organization_ids uuid[]", returns: "jsonb", security: "definer" },
816
+ { name: "entity_read_mask", args: "p_organization_id uuid, p_token text, p_level permission_level, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "definer" },
817
+ { name: "entity_record_home", args: "p_token text, p_record_id uuid", returns: "jsonb", security: "invoker" },
818
+ { name: "entity_record_read", args: "p_organization_id uuid, p_token text, p_record_id uuid", returns: "jsonb", security: "invoker" },
819
+ { name: "entity_records_find", args: "p_organization_id uuid, p_token text, p_key text, p_value jsonb DEFAULT NULL::jsonb, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0", returns: "jsonb", security: "invoker" },
820
+ { name: "entity_reference_fields", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
821
+ { name: "entity_reference_kinds", args: "", returns: "TABLE(token text, label text, category text)", security: "definer" },
822
+ { name: "entity_reference_render", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb", returns: "jsonb", security: "invoker" },
823
+ { name: "entity_reference_render_with", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb, p_fields jsonb", returns: "jsonb", security: "invoker" },
824
+ { name: "entity_reference_rows", args: "p_organization_id uuid, p_token text, p_ids uuid[]", returns: "jsonb", security: "invoker" },
825
+ { name: "entity_reference_search", args: "p_organization_id uuid, p_tokens text[], p_search text DEFAULT NULL::text, p_limit integer DEFAULT 20", returns: "jsonb", security: "definer" },
826
+ { name: "entity_reference_target", args: "p_token text", returns: "jsonb", security: "definer" },
827
+ { name: "entity_reference_words", args: "p_organization_id uuid, p_refs jsonb", returns: "jsonb", security: "definer" },
828
+ { name: "entity_row_propose", args: "p_organization_id uuid, p_token text, p_record_id uuid, p_columns jsonb DEFAULT '{}'::jsonb, p_custom jsonb DEFAULT '{}'::jsonb, p_expected_version integer DEFAULT NULL::integer, p_archive boolean DEFAULT NULL::boolean, p_note text DEFAULT NULL::text, p_conversation_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "invoker" },
829
+ { name: "entity_row_write", args: "p_organization_id uuid, p_token text, p_record_id uuid, p_columns jsonb DEFAULT '{}'::jsonb, p_custom jsonb DEFAULT '{}'::jsonb, p_expected_version integer DEFAULT NULL::integer, p_archive boolean DEFAULT NULL::boolean", returns: "jsonb", security: "invoker" },
830
+ { name: "entity_seat_level", args: "p_organization_id uuid, p_token text, p_record_id uuid", returns: "permission_level", security: "invoker" },
831
+ { name: "entity_table", args: "p_token text", returns: "TABLE(token text, schema_name text, table_name text, type text, title_column text, label text, has_organization boolean, has_deleted_at boolean)", security: "definer" },
832
+ { name: "entity_value_write", args: "p_organization_id uuid, p_token text, p_record_id uuid, p_patch jsonb", returns: "jsonb", security: "invoker" },
833
+ { name: "export_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
834
+ { name: "export_records", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 1000", returns: "TABLE(id uuid, document jsonb)", security: "invoker" },
835
+ { name: "external_foreign_table_findings", args: "", returns: "SETOF text", security: "definer" },
836
+ { name: "external_history_event", args: "p_organization_id uuid, p_link_id uuid, p_operation text", returns: "bigint", security: "definer" },
837
+ { name: "external_rows", args: "p_organization_id uuid, p_source_id uuid", returns: "SETOF jsonb", security: "definer" },
838
+ { name: "external_source_declare", args: "p_organization_id uuid, p_tier text, p_connection_token text, p_external_schema text, p_external_table text, p_link_template text", returns: "uuid", security: "definer" },
839
+ { name: "external_stub_upsert", args: "p_organization_id uuid, p_source_id uuid, p_table_id uuid, p_external_key text, p_link_url text, p_cached_title text", returns: "uuid", security: "definer" },
840
+ { name: "external_tier_contract", args: "", returns: "jsonb", security: "definer" },
841
+ { name: "external_write_through", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb", returns: "void", security: "definer" },
842
+ { name: "external_writes_set", args: "p_organization_id uuid, p_source_id uuid, p_enabled boolean", returns: "boolean", security: "definer" },
843
+ { name: "far_value", args: "p_organization_id uuid, p_record_id uuid, p_key text, p_reader jsonb", returns: "jsonb", security: "invoker" },
844
+ { name: "field_access", args: "p_user uuid, p_field_id uuid, p_token text, p_row_id uuid, p_action text, p_audit boolean DEFAULT true", returns: "jsonb", security: "definer" },
845
+ { name: "field_add_rung", args: "p_organization_id uuid, p_table_id uuid", returns: "permission_level", security: "invoker" },
846
+ { name: "field_behaviour", args: "p_field_data jsonb", returns: "text", security: "invoker" },
847
+ { name: "field_choice_usage", args: "p_organization_id uuid, p_field_id uuid", returns: "jsonb", security: "definer" },
848
+ { name: "field_context_policy_floor", args: "p_organization_id uuid, p_field_data jsonb, p_self uuid DEFAULT NULL::uuid", returns: "TABLE(context_policy text, reads jsonb)", security: "definer" },
849
+ { name: "field_cycle", args: "p_organization_id uuid, p_field_data jsonb, p_self uuid", returns: "text[]", security: "definer" },
850
+ { name: "field_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
851
+ { name: "field_dependants", args: "p_organization_id uuid, p_field_id uuid", returns: "TABLE(kind text, dependant_id uuid, label text, how text)", security: "definer" },
852
+ { name: "field_history", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0, p_record_id uuid DEFAULT NULL::uuid", returns: "TABLE(record_id uuid, record_title text, version integer, occurred_at timestamp with time zone, operation_label text, actor jsonb, before jsonb, after jsonb)", security: "definer" },
853
+ { name: "field_input_closure", args: "p_organization_id uuid, p_field_data jsonb, p_self uuid DEFAULT NULL::uuid", returns: "TABLE(input_id uuid, input_key text, input_label text, input_table uuid, sensitivity text, retired boolean, depth integer)", security: "definer" },
854
+ { name: "field_inputs_of", args: "p_organization_id uuid, p_field_data jsonb", returns: "TABLE(input_id uuid, input_key text, input_label text, input_table uuid, sensitivity text, retired boolean, how text)", security: "definer" },
855
+ { name: "field_is_protected", args: "p_data jsonb", returns: "boolean", security: "invoker" },
856
+ { name: "field_kernel_id", args: "", returns: "uuid", security: "invoker" },
857
+ { name: "field_kind_of", args: "p_field_data jsonb", returns: "text", security: "invoker" },
858
+ { name: "field_kinds", args: "", returns: "TABLE(kind text, behavior text, parity boolean, made_of text)", security: "invoker" },
859
+ { name: "field_options", args: "p_organization_id uuid, p_field_id uuid", returns: "SETOF custom.record", security: "definer" },
860
+ { name: "field_protection_refusal", args: "p_op text, p_old jsonb, p_new jsonb, p_field_id uuid", returns: "text", security: "invoker" },
861
+ { name: "field_restore", args: "p_organization_id uuid, p_field_id uuid", returns: "boolean", security: "definer" },
862
+ { name: "field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "boolean", security: "definer" },
863
+ { name: "field_rules", args: "p_field_data jsonb", returns: "TABLE(kind text, spec jsonb)", security: "invoker" },
864
+ { name: "field_sensitivity_floor", args: "p_organization_id uuid, p_field_data jsonb, p_self uuid DEFAULT NULL::uuid", returns: "TABLE(sensitivity text, reads jsonb)", security: "definer" },
865
+ { name: "field_source_archived", args: "p_organization_id uuid, p_field_id uuid", returns: "jsonb", security: "definer" },
866
+ { name: "field_update", args: "p_organization_id uuid, p_field_id uuid, p_patch jsonb", returns: "uuid", security: "definer" },
867
+ { name: "field_update_rehoming_choices", args: "p_organization_id uuid, p_field_id uuid, p_patch jsonb, p_rehome jsonb DEFAULT NULL::jsonb, p_cells_back jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "definer" },
868
+ { name: "field_value_convert", args: "p_to jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
869
+ { name: "field_value_kind", args: "p_organization_id uuid, p_field_data jsonb", returns: "text", security: "invoker" },
870
+ { name: "field_words", args: "p_organization_id uuid, p_field_id uuid, p_value jsonb", returns: "text", security: "invoker" },
871
+ { name: "file_kernel_id", args: "", returns: "uuid", security: "invoker" },
872
+ { name: "filter_is_rule", args: "p_filter jsonb", returns: "boolean", security: "invoker" },
873
+ { name: "form_archive", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
874
+ { name: "form_declare", args: "p_organization_id uuid, p_table_id uuid, p_title text, p_questions jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_submission_cap integer DEFAULT NULL::integer, p_quarantine_rule_id uuid DEFAULT NULL::uuid, p_notify_rule_id uuid DEFAULT NULL::uuid, p_form_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text", returns: "uuid", security: "definer" },
875
+ { name: "form_draft_read", args: "p_form_id uuid, p_secret text", returns: "TABLE(answers jsonb, saved_at timestamp with time zone, expires_at timestamp with time zone, state text, message text)", security: "definer" },
876
+ { name: "form_draft_save", args: "p_form_id uuid, p_answers jsonb, p_secret text DEFAULT NULL::text, p_bucket text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "TABLE(draft_secret text, saved_at timestamp with time zone, expires_at timestamp with time zone, state text, message text)", security: "definer" },
877
+ { name: "form_look_options", args: "p_organization_id uuid, p_presentation jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
878
+ { name: "form_notify", args: "p_organization_id uuid, p_form_id uuid, p_record_id uuid, p_submission_id uuid", returns: "uuid", security: "invoker" },
879
+ { name: "form_preview_asks", args: "p_organization_id uuid, p_table_id uuid, p_questions jsonb, p_values jsonb", returns: "TABLE(field_key text, asked boolean, decided boolean, said text)", security: "definer" },
880
+ { name: "form_public", args: "p_form_id uuid", returns: "TABLE(form_id uuid, organization_id uuid, table_id uuid, title text, presentation jsonb, fields jsonb, honeypot_key text, state text, message text)", security: "definer" },
881
+ { name: "form_public_asks", args: "p_form_id uuid, p_values jsonb, p_secret text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "TABLE(field_key text, asked boolean, decided boolean, said text)", security: "definer" },
882
+ { name: "form_redirect_domains", args: "p_organization_id uuid", returns: "text[]", security: "invoker" },
883
+ { name: "form_redirect_refusal", args: "p_organization_id uuid, p_url text", returns: "text", security: "invoker" },
884
+ { name: "form_restore", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
885
+ { name: "form_slug", args: "p_organization_id uuid, p_title text, p_form_id uuid DEFAULT NULL::uuid", returns: "text", security: "invoker" },
886
+ { name: "form_submit", args: "p_form_id uuid, p_origin text, p_payload jsonb, p_bucket text, p_honeypot text DEFAULT NULL::text, p_client_key text DEFAULT NULL::text", returns: "TABLE(submission_id uuid, record_id uuid, state text, message text)", security: "definer" },
887
+ { name: "forms", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(form_id uuid, table_id uuid, title text, slug text, published_at timestamp with time zone, closed_at timestamp with time zone, submission_cap integer, responses bigint, in_table bigint, held bigint, rejected bigint, state text, quarantine_rule_id uuid, notify_rule_id uuid, presentation jsonb)", security: "definer" },
888
+ { name: "forms_archived", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(form_id uuid, table_id uuid, table_name text, kind text, title text, slug text, archived_at timestamp with time zone, archived_by uuid, table_archived boolean, can_restore boolean)", security: "definer" },
889
+ { name: "formula_compile_sql", args: "p_organization_id uuid, p_expr jsonb, p_values_sql text", returns: "text", security: "invoker" },
890
+ { name: "formula_eval", args: "p_organization_id uuid, p_expr jsonb, p_values jsonb, p_context jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
891
+ { name: "formula_field_keys", args: "p_organization_id uuid, p_expr jsonb", returns: "text[]", security: "invoker" },
892
+ { name: "formula_node_kinds", args: "", returns: "TABLE(node text, min_args integer, max_args integer, result text, signature text, says text)", security: "invoker" },
893
+ { name: "formula_parse", args: "p_organization_id uuid, p_table_id uuid, p_text text", returns: "jsonb", security: "definer" },
894
+ { name: "formula_result_kind", args: "p_organization_id uuid, p_expr jsonb", returns: "text", security: "invoker" },
895
+ { name: "formula_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb, p_values jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "invoker" },
896
+ { name: "freshness_verdict", args: "p_written_at timestamp with time zone, p_ceiling_seconds numeric", returns: "jsonb", security: "definer" },
897
+ { name: "grid_layout", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
898
+ { name: "grid_layout_check", args: "p_layout jsonb, p_scope text DEFAULT 'view'::text", returns: "jsonb", security: "invoker" },
899
+ { name: "guard_refusals_are_complete", args: "", returns: "TABLE(guard text, said text)", security: "invoker" },
900
+ { name: "has_visibility", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
901
+ { name: "has_visibility_at", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, p_organization_id uuid DEFAULT NULL::uuid, p_min_version bigint DEFAULT NULL::bigint", returns: "boolean", security: "definer" },
902
+ { name: "hidden_field_notice", args: "p_field custom.record, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "invoker" },
903
+ { name: "history_actor", args: "p_tier text, p_document jsonb, p_actor_id uuid, p_people jsonb", returns: "jsonb", security: "invoker" },
904
+ { name: "history_changes", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
905
+ { name: "history_people", args: "p_organization_id uuid, p_ids uuid[]", returns: "jsonb", security: "definer" },
906
+ { name: "history_prune", args: "p_organization_id uuid, p_scope text DEFAULT 'values'::text, p_table_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
907
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "invoker" },
908
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text, p_author jsonb", returns: "jsonb", security: "invoker" },
909
+ { name: "history_retention", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
910
+ { name: "history_retention_floor_raise", args: "p_organization_id uuid, p_days integer", returns: "integer", security: "definer" },
911
+ { name: "history_retention_set", args: "p_organization_id uuid, p_table_id uuid, p_days integer", returns: "integer", security: "definer" },
912
+ { name: "home_add", args: "p_organization_id uuid, p_table_id uuid, p_home_record_id uuid", returns: "uuid", security: "definer" },
913
+ { name: "home_relations", args: "", returns: "TABLE(table_id uuid, home_record_id uuid, organization_id uuid, relation_id uuid)", security: "invoker" },
914
+ { name: "hub_changed_by", args: "p_organization_id uuid, p_kind text, p_ids uuid[]", returns: "TABLE(id uuid, at timestamp with time zone, who text)", security: "definer" },
915
+ { name: "inbound_addresses", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
916
+ { name: "inbound_declare", args: "p_organization_id uuid, p_table_id uuid, p_label text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
917
+ { name: "inbound_domain", args: "p_organization_id uuid", returns: "text", security: "invoker" },
918
+ { name: "inbound_mail_land", args: "p_address text, p_mail jsonb, p_secret text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
919
+ { name: "inbound_mail_map", args: "p_organization_id uuid, p_table_id uuid, p_mail jsonb", returns: "jsonb", security: "invoker" },
920
+ { name: "inbound_set", args: "p_organization_id uuid, p_inbound_id uuid, p_enabled boolean", returns: "jsonb", security: "definer" },
921
+ { name: "inbox_clear", args: "p_organization_id uuid, p_item_id uuid", returns: "jsonb", security: "definer" },
922
+ { name: "inbox_counts", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(organization_id uuid, organization_name text, waiting integer, snoozed integer, cleared integer, overdue integer, oldest_waiting_at timestamp with time zone)", security: "definer" },
923
+ { name: "inbox_remind_tick", args: "", returns: "jsonb", security: "invoker" },
924
+ { name: "inbox_snooze", args: "p_organization_id uuid, p_item_id uuid, p_until timestamp with time zone", returns: "jsonb", security: "definer" },
925
+ { name: "inbox_unclear", args: "p_organization_id uuid, p_item_id uuid", returns: "jsonb", security: "definer" },
926
+ { name: "inbox_unsnooze", args: "p_organization_id uuid, p_item_id uuid", returns: "jsonb", security: "definer" },
927
+ { name: "index_payload", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 1000", returns: "TABLE(id uuid, searchable text)", security: "invoker" },
928
+ { name: "intern_provenance", args: "p_data jsonb", returns: "jsonb", security: "invoker" },
929
+ { name: "io_cell", args: "p_organization_id uuid, p_field jsonb, p_word text, p_date_order text DEFAULT 'mdy'::text", returns: "jsonb", security: "invoker" },
930
+ { name: "io_change_actor", args: "", returns: "jsonb", security: "invoker" },
931
+ { name: "io_change_fields", args: "p_keys text[], p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
932
+ { name: "io_change_via", args: "", returns: "text", security: "invoker" },
933
+ { name: "io_changed_field_ids", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
934
+ { name: "io_changed_keys", args: "p_old jsonb, p_new jsonb", returns: "text[]", security: "invoker" },
935
+ { name: "io_comment_resolve", args: "p_organization_id uuid, p_comment_id uuid, p_resolved boolean DEFAULT true", returns: "boolean", security: "definer" },
936
+ { name: "io_comment_write", args: "p_organization_id uuid, p_record_id uuid, p_body text, p_anchor jsonb DEFAULT '{}'::jsonb, p_parent_comment_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
937
+ { name: "io_comments", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "TABLE(id uuid, body text, anchor jsonb, parent_comment_id uuid, created_by uuid, created_at timestamp with time zone, resolved_at timestamp with time zone, resolved_by uuid)", security: "definer" },
938
+ { name: "io_csv_escape", args: "p_value text, p_delimiter text DEFAULT ','::text", returns: "text", security: "invoker" },
939
+ { name: "io_csv_parse", args: "p_text text, p_delimiter text DEFAULT NULL::text", returns: "TABLE(row_number integer, cells text[])", security: "invoker" },
940
+ { name: "io_export", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "definer" },
941
+ { name: "io_export_csv", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_delimiter text DEFAULT chr(44), p_required text DEFAULT 'viewer'::text", returns: "text", security: "definer" },
942
+ { name: "io_import_begin", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb, p_file_hash text DEFAULT NULL::text, p_policy jsonb DEFAULT '{}'::jsonb, p_dedupe_key text DEFAULT NULL::text, p_file_bytes bigint DEFAULT NULL::bigint, p_force boolean DEFAULT false", returns: "jsonb", security: "definer" },
943
+ { name: "io_import_declare_columns", args: "p_organization_id uuid, p_table_id uuid, p_rows jsonb, p_mapping jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
944
+ { name: "io_import_finish", args: "p_organization_id uuid, p_import_id uuid, p_unmapped text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
945
+ { name: "io_import_forget", args: "p_organization_id uuid, p_import_id uuid", returns: "boolean", security: "definer" },
946
+ { name: "io_import_open", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb", returns: "uuid", security: "definer" },
947
+ { name: "io_import_plan", args: "p_organization_id uuid, p_table_id uuid, p_columns jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
948
+ { name: "io_import_report", args: "p_organization_id uuid, p_import_id uuid, p_state text DEFAULT NULL::text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0", returns: "jsonb", security: "definer" },
949
+ { name: "io_import_rows", args: "p_organization_id uuid, p_import_id uuid, p_rows jsonb, p_mapping jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
950
+ { name: "io_imports", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 25", returns: "jsonb", security: "definer" },
951
+ { name: "io_infer_column", args: "p_organization_id uuid, p_table_id uuid, p_header text, p_samples jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
952
+ { name: "io_infer_type", args: "p_samples jsonb", returns: "text", security: "invoker" },
953
+ { name: "io_money_unit", args: "p_word text", returns: "text", security: "invoker" },
954
+ { name: "io_outbox_announce", args: "", returns: "trigger", security: "definer" },
955
+ { name: "io_outbox_backlog", args: "p_consumer text, p_event_key text, p_older_than interval DEFAULT '00:00:00'::interval", returns: "TABLE(organization_id uuid, waiting bigint, oldest timestamp with time zone, last_carried timestamp with time zone)", security: "definer" },
956
+ { name: "io_outbox_broadcast_stmt", args: "", returns: "trigger", security: "definer" },
957
+ { name: "io_outbox_consumed_by", args: "p_event_id uuid, p_consumer text, p_consumed_at timestamp with time zone", returns: "boolean", security: "invoker" },
958
+ { name: "io_outbox_drain", args: "p_organization_id uuid, p_consumer text, p_limit integer DEFAULT 100, p_event_key text DEFAULT 'records.changed'::text", returns: "TABLE(outbox_id uuid, record_id uuid, table_id uuid, operation text, changed_field_ids jsonb, actor jsonb, occurred_at timestamp with time zone)", security: "definer" },
959
+ { name: "io_outbox_last_consumed", args: "p_consumer text, p_event_key text, p_organization_id uuid", returns: "timestamp with time zone", security: "invoker" },
960
+ { name: "io_outbox_pending_organizations", args: "p_consumer text, p_event_key text", returns: "SETOF uuid", security: "definer" },
961
+ { name: "io_outbox_per_consumer", args: "", returns: "boolean", security: "invoker" },
962
+ { name: "io_outbox_rearm", args: "p_organization_id uuid, p_dedupe_key text", returns: "void", security: "definer" },
963
+ { name: "io_outbox_release", args: "p_organization_id uuid, p_consumer text, p_older_than interval DEFAULT '00:15:00'::interval", returns: "integer", security: "definer" },
964
+ { name: "io_outbox_release_claimed", args: "p_organization_id uuid, p_consumer text, p_ids uuid[]", returns: "integer", security: "definer" },
965
+ { name: "io_outbox_subscribe", args: "p_consumer text, p_event_key text", returns: "timestamp with time zone", security: "definer" },
966
+ { name: "io_proposal_accept", args: "p_organization_id uuid, p_import_id uuid, p_column text, p_type text DEFAULT NULL::text, p_label text DEFAULT NULL::text", returns: "uuid", security: "definer" },
967
+ { name: "io_proposal_reject", args: "p_organization_id uuid, p_import_id uuid, p_column text", returns: "boolean", security: "definer" },
968
+ { name: "io_proposal_spec", args: "p_proposal jsonb", returns: "jsonb", security: "invoker" },
969
+ { name: "io_record_changed", args: "", returns: "trigger", security: "definer" },
970
+ { name: "io_record_changed_stmt_delete", args: "", returns: "trigger", security: "definer" },
971
+ { name: "io_record_changed_stmt_insert", args: "", returns: "trigger", security: "definer" },
972
+ { name: "io_record_changed_stmt_update", args: "", returns: "trigger", security: "definer" },
973
+ { name: "io_relation_candidate", args: "p_organization_id uuid, p_table_id uuid, p_words text[]", returns: "uuid", security: "invoker" },
974
+ { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
975
+ { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "integer", security: "definer" },
976
+ { name: "io_revisions", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(version integer, changed_at timestamp with time zone, changed_by uuid, summary text, operation text, changed_fields jsonb)", security: "definer" },
977
+ { name: "io_sample_words", args: "p_samples jsonb", returns: "TABLE(word text)", security: "invoker" },
978
+ { name: "io_value_shape", args: "p_envelope jsonb", returns: "jsonb", security: "invoker" },
979
+ { name: "io_workflow_chain", args: "", returns: "jsonb", security: "invoker" },
980
+ { name: "is_a_retirement", args: "p_old_deleted timestamp with time zone, p_new_deleted timestamp with time zone, p_old_data jsonb, p_new_data jsonb, p_old_table uuid, p_new_table uuid, p_old_org uuid, p_new_org uuid, p_old_class text, p_new_class text", returns: "boolean", security: "invoker" },
981
+ { name: "ladder_replanners", args: "p_roots text[] DEFAULT ARRAY['custom.has_visibility'::text, 'custom.effective_level'::text, 'custom.reaches_directly'::text, 'custom.visible_set'::text]", returns: "TABLE(fn text, lang text, why text, remedy text)", security: "definer" },
982
+ { name: "level_floor", args: "", returns: "permission_level", security: "definer" },
983
+ { name: "levels_of", args: "p_user_id uuid, p_ids uuid[]", returns: "jsonb", security: "definer" },
984
+ { name: "levels_raised_by_a_less_specific_rung", args: "", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, member_email text, record_id uuid, addressed_level permission_level, answered_level permission_level)", security: "definer" },
985
+ { name: "list_door_disagreements", args: "p_pretend text DEFAULT NULL::text, p_only_organization uuid DEFAULT NULL::uuid, p_sample integer DEFAULT 200", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
986
+ { name: "list_door_disagreements", args: "p_pretend text, p_only_organization uuid, p_sample integer, p_exhaustive boolean", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
987
+ { name: "list_portals", args: "p_organization_id uuid, p_archived text DEFAULT 'active'::text", returns: "TABLE(portal_id uuid, title text, slug text, client_table_id uuid, client_table text, is_active boolean, tables integer, invited integer, signed_in integer, sign_in_method text, opened_at timestamp with time zone)", security: "definer" },
988
+ { name: "list_portals_everywhere", args: "p_archived text DEFAULT 'active'::text", returns: "jsonb", security: "invoker" },
989
+ { name: "listed_predicate_sql", args: "p_user uuid, p_organization_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, p_alias text DEFAULT 'r'::text", returns: "text", security: "invoker" },
990
+ { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
991
+ { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
992
+ { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb, p_declared_keys text[] DEFAULT NULL::text[]", returns: "jsonb", security: "invoker" },
993
+ { name: "mask_history_data", args: "p_data jsonb, p_mask jsonb", returns: "jsonb", security: "invoker" },
994
+ { name: "mask_says_withheld", args: "p_mask jsonb, p_key text", returns: "boolean", security: "invoker" },
995
+ { name: "may_invite_outside", args: "p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
996
+ { name: "member_personal_tables", args: "p_organization_id uuid, p_person uuid", returns: "jsonb", security: "definer" },
997
+ { name: "member_records_take_over", args: "p_organization_id uuid, p_from uuid, p_to uuid, p_reason text", returns: "jsonb", security: "definer" },
998
+ { name: "merge_field_kernel_id", args: "", returns: "uuid", security: "invoker" },
999
+ { name: "migrate_choice_keys", args: "p_organization_id uuid, p_table_id uuid, p_dry_run boolean DEFAULT false", returns: "jsonb", security: "definer" },
1000
+ { name: "migrate_delete", args: "p_organization_id uuid, p_record_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1001
+ { name: "migrate_demote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1002
+ { name: "migrate_extract_parent", args: "p_organization_id uuid, p_id uuid, p_parent_table_id uuid, p_moved_keys text[], p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1003
+ { name: "migrate_merge", args: "p_organization_id uuid, p_winner_id uuid, p_loser_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1004
+ { name: "migrate_promote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1005
+ { name: "migrate_purge", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
1006
+ { name: "migrate_purge_hard", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_compliance_reason text DEFAULT NULL::text, p_chunk integer DEFAULT 200, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
1007
+ { name: "migrate_purge_hard_request", args: "p_organization_id uuid, p_table_id uuid, p_compliance_reason text", returns: "void", security: "definer" },
1008
+ { name: "migrate_reclass", args: "p_organization_id uuid, p_id uuid, p_to text DEFAULT 'field'::text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1009
+ { name: "migrate_rename", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1010
+ { name: "migrate_reparent", args: "p_organization_id uuid, p_id uuid, p_parent_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1011
+ { name: "migrate_retype", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1012
+ { name: "migrate_split", args: "p_organization_id uuid, p_record_id uuid, p_moved_keys text[], p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1013
+ { name: "migrate_undo", args: "p_organization_id uuid, p_log_id uuid", returns: "jsonb", security: "definer" },
1014
+ { name: "migrations", args: "p_organization_id uuid, p_target_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(id uuid, verb text, target_kind text, target_id uuid, note text, applied_at timestamp with time zone, applied_by uuid, undone_at timestamp with time zone)", security: "definer" },
1015
+ { name: "mirror_asks_the_whole_database", args: "", returns: "TABLE(schema_name text, table_name text, policy_name text, why text)", security: "invoker" },
1016
+ { name: "my_level", args: "p_organization_id uuid, p_id uuid, p_type text DEFAULT 'record'::text", returns: "permission_level", security: "definer" },
1017
+ { name: "my_levels", args: "p_organization_id uuid, p_ids jsonb, p_type text DEFAULT 'record'::text", returns: "TABLE(id uuid, level permission_level)", security: "definer" },
1018
+ { name: "organization_clear", args: "p_organization_id uuid, p_confirm text, p_and_destroy boolean DEFAULT false", returns: "jsonb", security: "definer" },
1019
+ { name: "organization_contents", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
1020
+ { name: "organization_home_id", args: "p_organization_id uuid", returns: "uuid", security: "invoker" },
1021
+ { name: "organization_kernel_id", args: "", returns: "uuid", security: "invoker" },
1022
+ { name: "organization_pick_lists", args: "p_organization_id uuid", returns: "TABLE(id uuid, list_name text, description text, updated_at timestamp with time zone, lives_in text)", security: "definer" },
1023
+ { name: "organization_references", args: "p_kind text, p_organization_id uuid, p_row jsonb", returns: "TABLE(site text, what text, ref_id uuid, openable boolean)", security: "invoker" },
1024
+ { name: "owning_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "invoker" },
1025
+ { name: "owning_table_gone", args: "p_organization_id uuid, p_record_id uuid", returns: "boolean", security: "invoker" },
1026
+ { name: "page_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
1027
+ { name: "page_contract", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
1028
+ { name: "page_size", args: "p_organization_id uuid, p_door text, p_limit integer, p_default integer DEFAULT NULL::integer, p_ceiling integer DEFAULT NULL::integer", returns: "integer", security: "invoker" },
1029
+ { name: "parity_field_types", args: "", returns: "TABLE(parity_type text, behavior text, made_of text)", security: "invoker" },
1030
+ { name: "parity_type", args: "p_field_data jsonb", returns: "text", security: "invoker" },
1031
+ { name: "parity_values", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, parity_type text, behavior text, unit text, format text, value jsonb, value_version integer, actor text, written_at timestamp with time zone)", security: "invoker" },
1032
+ { name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
1033
+ { name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
1034
+ { name: "phone_canonical", args: "p_text text", returns: "text", security: "invoker" },
1035
+ { name: "phone_display", args: "p_text text", returns: "text", security: "invoker" },
1036
+ { name: "phone_pattern", args: "", returns: "text", security: "invoker" },
1037
+ { name: "pick_list_create", args: "p_organization_id uuid, p_list_name text, p_description text DEFAULT NULL::text, p_items jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
1038
+ { name: "pick_list_index", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
1039
+ { name: "pick_list_index_everywhere", args: "", returns: "jsonb", security: "definer" },
1040
+ { name: "pin_agent_cells", args: "p_new jsonb, p_old jsonb, p_agent_keys text[]", returns: "jsonb", security: "invoker" },
1041
+ { name: "pipeline_board", args: "p_organization_id uuid, p_table_id uuid, p_measure text DEFAULT NULL::text", returns: "TABLE(stage_key text, stage_label text, stage_position integer, cards bigint, total numeric, wip_limit integer, over_limit boolean)", security: "definer" },
1042
+ { name: "pipeline_board", args: "p_organization_id uuid, p_table_id uuid, p_measure text, p_filter jsonb", returns: "TABLE(stage_key text, stage_label text, stage_position integer, cards bigint, total numeric, wip_limit integer, over_limit boolean)", security: "definer" },
1043
+ { name: "pipeline_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
1044
+ { name: "pipeline_gate_preview", args: "p_organization_id uuid, p_table_id uuid, p_stage text, p_gate jsonb", returns: "jsonb", security: "definer" },
1045
+ { name: "pipeline_move", args: "p_organization_id uuid, p_record_id uuid, p_to text, p_also jsonb DEFAULT '{}'::jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1046
+ { name: "pipeline_move_many", args: "p_organization_id uuid, p_moves jsonb", returns: "jsonb", security: "definer" },
1047
+ { name: "pipeline_pending", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1048
+ { name: "pipeline_read", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1049
+ { name: "pipeline_transition_refusal", args: "p_organization_id uuid, p_record_id uuid, p_to text", returns: "jsonb", security: "definer" },
1050
+ { name: "pipelines", args: "p_organization_id uuid", returns: "TABLE(table_id uuid, table_name text, stage_field text, stage_label text, stages integer, rules integer, broken text, updated_at timestamp with time zone, updated_by uuid)", security: "definer" },
1051
+ { name: "plural_of", args: "p_word text", returns: "text", security: "invoker" },
1052
+ { name: "portal_accents", args: "", returns: "text[]", security: "invoker" },
1053
+ { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
1054
+ { name: "portal_archive", args: "p_organization_id uuid, p_portal_id uuid, p_confirm_title text, p_reason text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1055
+ { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
1056
+ { name: "portal_declare", args: "p_organization_id uuid, p_title text, p_client_table_id uuid, p_tables jsonb, p_portal_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text, p_sign_in_method text DEFAULT 'magic_link'::text, p_config jsonb DEFAULT NULL::jsonb", returns: "uuid", security: "definer" },
1057
+ { name: "portal_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(field_id uuid, field_key text, field_type text, points_at uuid)", security: "definer" },
1058
+ { name: "portal_form", args: "p_organization_id uuid, p_portal_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
1059
+ { name: "portal_form_submit", args: "p_organization_id uuid, p_portal_id uuid, p_form_id uuid, p_payload jsonb, p_client_key text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1060
+ { name: "portal_invitation", args: "p_slug text, p_email text", returns: "jsonb", security: "definer" },
1061
+ { name: "portal_invite", args: "p_organization_id uuid, p_portal_id uuid, p_client_record_id uuid, p_email text, p_user_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1062
+ { name: "portal_invite_accept", args: "p_token text", returns: "jsonb", security: "definer" },
1063
+ { name: "portal_me", args: "", returns: "jsonb", security: "definer" },
1064
+ { name: "portal_preview", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, title text)", security: "definer" },
1065
+ { name: "portal_principal_bind", args: "p_organization_id uuid, p_principal_id uuid, p_user_id uuid", returns: "jsonb", security: "definer" },
1066
+ { name: "portal_public", args: "p_slug text", returns: "jsonb", security: "definer" },
1067
+ { name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
1068
+ { name: "portal_restore", args: "p_organization_id uuid, p_portal_id uuid, p_confirm_title text", returns: "jsonb", security: "definer" },
1069
+ { name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
1070
+ { name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
1071
+ { name: "portal_tables", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, table_id uuid, name text)", security: "definer" },
1072
+ { name: "portals", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, title text, slug text, client_table_id uuid, client_table text, is_active boolean, tables integer, invited integer, signed_in integer, sign_in_method text, opened_at timestamp with time zone)", security: "definer" },
1073
+ { name: "presentation_kernel_id", args: "", returns: "uuid", security: "invoker" },
1074
+ { name: "promote_field", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid", returns: "jsonb", security: "invoker" },
1075
+ { name: "promote_table", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1076
+ { name: "promoted_field_cap", args: "", returns: "integer", security: "invoker" },
1077
+ { name: "promoted_fields", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(field_id uuid, field_key text, parity_type text, is_unique boolean, value_path text, index_arm text, index_expr text, index_name text, indexable boolean, why_not text)", security: "invoker" },
1078
+ { name: "promoted_index_arm", args: "p_field_data jsonb", returns: "text", security: "invoker" },
1079
+ { name: "promoted_index_ddl", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(step integer, purpose text, statement text)", security: "invoker" },
1080
+ { name: "promoted_index_expr", args: "p_field_data jsonb", returns: "text", security: "invoker" },
1081
+ { name: "promoted_index_name", args: "p_table_id uuid, p_field_key text, p_unique boolean", returns: "text", security: "invoker" },
1082
+ { name: "promoted_query_sql", args: "p_organization_id uuid, p_table_id uuid, p_field_key text", returns: "text", security: "invoker" },
1083
+ { name: "promoted_read", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_value text", returns: "SETOF uuid", security: "invoker" },
1084
+ { name: "promoted_value_path", args: "p_field_data jsonb", returns: "text", security: "invoker" },
1085
+ { name: "promotion_inline_ceiling", args: "", returns: "integer", security: "invoker" },
1086
+ { name: "protected_field_notice", args: "p_field custom.record", returns: "jsonb", security: "invoker" },
1087
+ { name: "protected_field_query_refusal", args: "p_field_id uuid, p_verb text", returns: "text", security: "definer" },
1088
+ { name: "protected_field_rule", args: "p_token text", returns: "jsonb", security: "invoker" },
1089
+ { name: "protected_matches", args: "p_field_id uuid, p_value jsonb DEFAULT NULL::jsonb", returns: "TABLE(row_id uuid, value jsonb)", security: "definer" },
1090
+ { name: "protected_readers_problem", args: "p_token text, p_readers jsonb", returns: "text", security: "invoker" },
1091
+ { name: "protected_value", args: "p_token text, p_row_id uuid, p_field_id uuid", returns: "jsonb", security: "definer" },
1092
+ { name: "protected_value_leaks", args: "p_field_id uuid DEFAULT NULL::uuid", returns: "TABLE(place text, table_token text, field_key text, row_id uuid, ref text)", security: "definer" },
1093
+ { name: "protected_values", args: "p_organization_id uuid, p_token text, p_row_id uuid", returns: "jsonb", security: "definer" },
1094
+ { name: "provenance_prune", args: "p_organization_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true, p_limit integer DEFAULT 200000", returns: "jsonb", security: "definer" },
1095
+ { name: "provenance_retention_days", args: "p_organization_id uuid", returns: "integer", security: "definer" },
1096
+ { name: "provenance_write", args: "p_organization_id uuid, p_conversation_id uuid, p_turn_id text, p_rows jsonb", returns: "integer", security: "definer" },
1097
+ { name: "publish_bind", args: "p_organization_id uuid, p_kind text, p_resource_id uuid, p_slug text, p_render_mode text DEFAULT 'page'::text", returns: "jsonb", security: "definer" },
1098
+ { name: "query_access_ids", args: "p_organization_id uuid, p_required text DEFAULT 'viewer'::text", returns: "uuid[]", security: "invoker" },
1099
+ { name: "query_across_homes", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, home_record_id uuid, data jsonb, created_at timestamp with time zone)", security: "definer" },
1100
+ { name: "query_by_coordinates", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_coordinates jsonb DEFAULT '[]'::jsonb, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, table_id uuid, data jsonb, coordinates_matched integer)", security: "definer" },
1101
+ { name: "query_can_see", args: "p_organization_id uuid, p_record_id uuid, p_required text DEFAULT 'viewer'::text", returns: "boolean", security: "definer" },
1102
+ { name: "query_hot_paths", args: "", returns: "TABLE(name text, statement text)", security: "invoker" },
1103
+ { name: "query_hot_paths_prepared", args: "", returns: "TABLE(name text, prepared boolean, generic_plans bigint)", security: "invoker" },
1104
+ { name: "query_is_store_owner", args: "", returns: "boolean", security: "invoker" },
1105
+ { name: "query_prepare_hot", args: "", returns: "integer", security: "invoker" },
1106
+ { name: "query_principal", args: "", returns: "uuid", security: "invoker" },
1107
+ { name: "query_record_as_of", args: "p_organization_id uuid, p_record_id uuid, p_recorded_at timestamp with time zone DEFAULT NULL::timestamp with time zone, p_world_on date DEFAULT NULL::date, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "definer" },
1108
+ { name: "query_record_document", args: "p_principal uuid, p_row custom.record", returns: "jsonb", security: "invoker" },
1109
+ { name: "query_relation_edges", args: "p_organization_id uuid, p_flavor text DEFAULT NULL::text, p_role text DEFAULT NULL::text", returns: "TABLE(parent_id uuid, child_id uuid, role text, flavor text)", security: "definer" },
1110
+ { name: "query_rollup", args: "p_organization_id uuid, p_roots uuid[], p_flavor text DEFAULT NULL::text, p_role text DEFAULT NULL::text, p_max_depth integer DEFAULT 33, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, depth integer)", security: "definer" },
1111
+ { name: "query_rollup_sum", args: "p_organization_id uuid, p_roots uuid[], p_field_key text, p_flavor text DEFAULT NULL::text, p_role text DEFAULT NULL::text, p_max_depth integer DEFAULT 33, p_required text DEFAULT 'viewer'::text", returns: "numeric", security: "definer" },
1112
+ { name: "query_table_as_of", args: "p_organization_id uuid, p_table_id uuid, p_recorded_at timestamp with time zone DEFAULT NULL::timestamp with time zone, p_world_on date DEFAULT NULL::date, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, data jsonb)", security: "definer" },
1113
+ { name: "query_table_homes", args: "p_organization_id uuid, p_table_id uuid", returns: "SETOF uuid", security: "definer" },
1114
+ { name: "query_visibility_parity", args: "p_organization_id uuid", returns: "TABLE(side text, container_type text, container_id uuid, item_type text, item_id uuid, stored_level permission_level, derived_level permission_level, reason text)", security: "definer" },
1115
+ { name: "query_visible_ids", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_required text DEFAULT 'viewer'::text", returns: "SETOF uuid", security: "definer" },
1116
+ { name: "reachable_from", args: "p_organization_id uuid, p_roots uuid[]", returns: "TABLE(record_id uuid, depth integer, via text)", security: "invoker" },
1117
+ { name: "reaches_directly", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
1118
+ { name: "read_door_carried_ids", args: "p_user uuid, p_organization_id uuid, p_table_id uuid, p_required permission_level, OUT o_ids uuid[], OUT o_containers integer", returns: "record", security: "definer" },
1119
+ { name: "read_door_granted_ids", args: "p_organization_id uuid, p_table_id uuid", returns: "uuid[]", security: "definer" },
1120
+ { name: "read_door_ladder_ceiling", args: "", returns: "integer", security: "invoker" },
1121
+ { name: "read_door_parity", args: "p_organization_id uuid, p_table_id uuid, p_user uuid, p_required permission_level, p_sample integer", returns: "TABLE(record_id uuid, set_based boolean, per_row boolean, verdict text)", security: "definer" },
1122
+ { name: "read_mask", args: "p_organization_id uuid, p_record_id uuid, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "definer" },
1123
+ { name: "read_mask_at", args: "p_record_id uuid, p_level_given boolean, p_level permission_level, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "definer" },
1124
+ { name: "read_mask_for", args: "p_user_id uuid, p_organization_id uuid, p_table_id uuid, p_level permission_level, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "definer" },
1125
+ { name: "read_paths_outside_the_door", args: "", returns: "TABLE(object_name text, why text)", security: "invoker" },
1126
+ { name: "read_record", args: "p_organization_id uuid, p_record_id uuid, p_by_id boolean DEFAULT false", returns: "jsonb", security: "definer" },
1127
+ { name: "read_records", args: "p_organization_id uuid, p_table_id uuid, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, document jsonb, level permission_level)", security: "definer" },
1128
+ { name: "read_records_archived", args: "p_organization_id uuid, p_table_id uuid, p_lane text DEFAULT 'org'::text, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, document jsonb, level permission_level, archived_at timestamp with time zone, archived_by uuid, archived_by_name text)", security: "definer" },
1129
+ { name: "read_records_by_ids", args: "p_organization_id uuid, p_table_id uuid, p_record_ids uuid[], p_by_id boolean DEFAULT false", returns: "TABLE(id uuid, document jsonb, level permission_level)", security: "definer" },
1130
+ { name: "read_records_in_view_order", args: "p_organization_id uuid, p_view_id uuid, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0, p_filter jsonb DEFAULT NULL::jsonb", returns: 'TABLE(id uuid, document jsonb, level permission_level, "position" numeric)', security: "definer" },
1131
+ { name: "read_records_matching", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb DEFAULT '{}'::jsonb, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, document jsonb, level permission_level)", security: "definer" },
1132
+ { name: "read_records_page", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb DEFAULT '{}'::jsonb, p_search text DEFAULT NULL::text, p_sort jsonb DEFAULT '[]'::jsonb, p_view_id uuid DEFAULT NULL::uuid, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_time_zone text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1133
+ { name: "realtime_topic_admits", args: "p_topic text", returns: "boolean", security: "definer" },
1134
+ { name: "record_aggregate", args: "p_organization_id uuid, p_table_id uuid, p_group_by jsonb DEFAULT '[]'::jsonb, p_measures jsonb DEFAULT '[]'::jsonb, p_bucket jsonb DEFAULT NULL::jsonb, p_filter jsonb DEFAULT '{}'::jsonb, p_limit integer DEFAULT 200, p_required text DEFAULT 'viewer'::text, p_compare jsonb DEFAULT NULL::jsonb, p_search text DEFAULT NULL::text, p_time_zone text DEFAULT NULL::text", returns: "TABLE(groups jsonb, measures jsonb, row_count bigint, prior_groups jsonb, prior_measures jsonb, prior_row_count bigint, delta jsonb, compare jsonb)", security: "definer" },
1135
+ { name: "record_aggregate_as_of", args: "p_organization_id uuid, p_table_id uuid, p_recorded_at timestamp with time zone, p_measure text DEFAULT 'count'::text, p_field_key text DEFAULT NULL::text, p_group_by text DEFAULT NULL::text, p_match jsonb DEFAULT '{}'::jsonb", returns: "TABLE(bucket text, result numeric, row_count bigint, not_numbers bigint, a_non_number text)", security: "definer" },
1136
+ { name: "record_applicability", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(rule_id uuid, rule_name text, rule_version integer, applies boolean, answer jsonb)", security: "invoker" },
1137
+ { name: "record_archiver", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
1138
+ { name: "record_as_of", args: "p_organization_id uuid, p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
1139
+ { name: "record_card", args: "p_viewer uuid, p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
1140
+ { name: "record_carrying_edges", args: "p_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(container_id uuid, item_id uuid, edge_role text)", security: "invoker" },
1141
+ { name: "record_change_actions", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1142
+ { name: "record_change_many", args: "p_organization_id uuid, p_table_id uuid, p_changes jsonb", returns: "jsonb", security: "definer" },
1143
+ { name: "record_changes_drain", args: "p_organization_id uuid, p_consumer text, p_limit integer DEFAULT 100", returns: "TABLE(event_id uuid, organization_id uuid, table_id uuid, record_id uuid, kind text, operation text, version integer, fields jsonb, changed_field_ids jsonb, actor jsonb, chain jsonb, op_id uuid, occurred_at timestamp with time zone, via text)", security: "definer" },
1144
+ { name: "record_delete", args: "p_organization_id uuid, p_record_id uuid", returns: "timestamp with time zone", security: "definer" },
1145
+ { name: "record_entity_edges", args: "p_organization_id uuid, p_id uuid, p_table_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(target_type text, target_id uuid, edge_role text, field_id uuid, ord integer)", security: "invoker" },
1146
+ { name: "record_filter_sql", args: "p_filter jsonb", returns: "text", security: "invoker" },
1147
+ { name: "record_filter_sql", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb", returns: "text", security: "invoker" },
1148
+ { name: "record_headers", args: "p_organization_id uuid, p_ids uuid[]", returns: "TABLE(id uuid, table_id uuid, created_at timestamp with time zone, updated_at timestamp with time zone, version integer, deleted_at timestamp with time zone, mine boolean, created_by uuid)", security: "definer" },
1149
+ { name: "record_history", args: "p_organization_id uuid, p_record_id uuid, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(version integer, occurred_at timestamp with time zone, operation text, operation_label text, actor jsonb, changes jsonb, migration_id uuid, undoable boolean)", security: "definer" },
1150
+ { name: "record_platform_keys", args: "", returns: "text[]", security: "invoker" },
1151
+ { name: "record_relation_edges", args: "p_organization_id uuid, p_id uuid, p_table_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(target_id uuid, edge_role text, field_id uuid, ord integer)", security: "invoker" },
1152
+ { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
1153
+ { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
1154
+ { name: "record_restore", args: "p_organization_id uuid, p_record_id uuid", returns: "void", security: "definer" },
1155
+ { name: "record_restore_preview", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1156
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "jsonb", security: "definer" },
1157
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
1158
+ { name: "record_row_controls", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
1159
+ { name: "record_row_controls_set", args: "p_organization_id uuid, p_record_id uuid, p_controls jsonb", returns: "jsonb", security: "definer" },
1160
+ { name: "record_runs", args: "p_organization_id uuid, p_record_id uuid, p_limit integer DEFAULT 50", returns: "TABLE(run_id uuid, kind text, name text, trigger_name text, status text, started_at timestamp with time zone, finished_at timestamp with time zone, steps integer, says text, ran_by uuid)", security: "definer" },
1161
+ { name: "record_scope_context", args: "p_organization_id uuid, p_record_id uuid, p_relations integer DEFAULT 12, p_history integer DEFAULT 15, p_siblings integer DEFAULT 8", returns: "jsonb", security: "definer" },
1162
+ { name: "record_search_sql", args: "p_organization_id uuid, p_table_id uuid, p_search text, p_alias text DEFAULT 'r'::text, p_time_zone text DEFAULT NULL::text", returns: "text", security: "invoker" },
1163
+ { name: "record_source_key", args: "p_table_id uuid", returns: "text", security: "invoker" },
1164
+ { name: "record_source_keys", args: "p_table_id uuid", returns: "text[]", security: "invoker" },
1165
+ { name: "record_source_table", args: "p_key text", returns: "uuid", security: "invoker" },
1166
+ { name: "record_stage_pending", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
1167
+ { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
1168
+ { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
1169
+ { name: "record_triggers", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(trigger_id uuid, name text, definition_id uuid, definition_name text, table_id uuid, event text, operations jsonb, field_ids jsonb, via jsonb, is_active boolean, last_fired_at timestamp with time zone, fire_count integer, updated_at timestamp with time zone)", security: "definer" },
1170
+ { name: "record_update", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "integer", security: "definer" },
1171
+ { name: "record_update_adding_choices", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb, p_add jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "integer", security: "definer" },
1172
+ { name: "record_upsert", args: "p_organization_id uuid, p_table_id uuid, p_key text[], p_data jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "uuid", security: "definer" },
1173
+ { name: "record_value_one", args: "p_organization_id uuid, p_record_id uuid, p_key text", returns: "jsonb", security: "invoker" },
1174
+ { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1175
+ { name: "record_values_of", args: "p_row custom.record", returns: "jsonb", security: "invoker" },
1176
+ { name: "record_values_step", args: "p_row custom.record, p_cache jsonb DEFAULT '{}'::jsonb, OUT o_doc jsonb, OUT o_cache jsonb", returns: "record", security: "invoker" },
1177
+ { name: "record_values_versioned", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, value jsonb, value_version integer, source jsonb, absent_reason text, actor text, on_behalf_of text, written_at timestamp with time zone, alternates jsonb)", security: "definer" },
1178
+ { name: "record_words", args: "p_organization_id uuid, p_record_id uuid, p_noun text DEFAULT NULL::text", returns: "text", security: "definer" },
1179
+ { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
1180
+ { name: "record_write_graph", args: "p_organization_id uuid, p_table_id uuid, p_parent jsonb, p_edges jsonb DEFAULT '[]'::jsonb, p_children jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
1181
+ { name: "record_write_graph_superseding", args: `p_organization_id uuid, p_table_id uuid, p_lock_key text, p_idempotence jsonb DEFAULT NULL::jsonb, p_parent jsonb DEFAULT NULL::jsonb, p_edges jsonb DEFAULT '[]'::jsonb, p_children jsonb DEFAULT '[]'::jsonb, p_chain jsonb DEFAULT '{"mode": "first"}'::jsonb, p_rows_state jsonb DEFAULT NULL::jsonb`, returns: "jsonb", security: "definer" },
1182
+ { name: "record_write_many", args: "p_organization_id uuid, p_table_id uuid, p_rows jsonb[], p_ids uuid[] DEFAULT NULL::uuid[]", returns: "uuid[]", security: "definer" },
1183
+ { name: "records_search", args: "p_search text, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_table_ids uuid[] DEFAULT NULL::uuid[], p_organization_ids uuid[] DEFAULT NULL::uuid[], p_include_app_tables boolean DEFAULT false", returns: "TABLE(record_id uuid, table_id uuid, table_name text, name text, organization_id uuid, updated_at timestamp with time zone)", security: "definer" },
1184
+ { name: "refusals_claiming_a_level_never_asked", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
1185
+ { name: "relation_carry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "uuid", security: "definer" },
1186
+ { name: "relation_edges_withdraw", args: "p_organization_id uuid, p_field_ids uuid[], p_why text", returns: "integer", security: "definer" },
1187
+ { name: "relation_halves_disagreements", args: "p_organization_id uuid DEFAULT NULL::uuid, p_record_id uuid DEFAULT NULL::uuid", returns: "TABLE(organization_id uuid, record_id uuid, field_key text, field_id uuid, target_id uuid, direction text, remedy text, why text)", security: "definer" },
1188
+ { name: "relation_halves_repair", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
1189
+ { name: "relation_kernel_record", args: "p_organization_id uuid, p_kernel_table_id uuid, p_id uuid", returns: "uuid", security: "definer" },
1190
+ { name: "relation_name_key", args: "p_text text", returns: "text", security: "invoker" },
1191
+ { name: "relation_names_match", args: "p_organization_id uuid, p_table_id uuid, p_names text[]", returns: "jsonb", security: "definer" },
1192
+ { name: "relation_own", args: "p_organization_id uuid, p_owner_id uuid, p_target_id uuid", returns: "uuid", security: "definer" },
1193
+ { name: "relation_restore", args: "p_organization_id uuid, p_relation_id uuid", returns: "boolean", security: "definer" },
1194
+ { name: "relation_target_card", args: "p_organization_id uuid, p_record_id uuid, p_via_key text DEFAULT NULL::text", returns: "TABLE(target_id uuid, target_organization_id uuid, is_foreign boolean, masked boolean, reader_level permission_level, card jsonb, why text)", security: "definer" },
1195
+ { name: "relation_target_external", args: "p_connection_token text, p_external_table text, p_external_key text", returns: "jsonb", security: "definer" },
1196
+ { name: "relation_target_ours", args: "p_entity_token text, p_row_id uuid", returns: "jsonb", security: "definer" },
1197
+ { name: "relation_targets", args: "p_organization_id uuid, p_record_id uuid, p_via_key text", returns: "SETOF uuid", security: "definer" },
1198
+ { name: "relation_uncarry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "integer", security: "definer" },
1199
+ { name: "relation_value_target_ok", args: "p_organization_id uuid, p_field_id uuid, p_field_data jsonb, p_target_id uuid", returns: "boolean", security: "invoker" },
1200
+ { name: "relation_words", args: "p_organization_id uuid, p_field_id uuid, p_value text", returns: "text", security: "definer" },
1201
+ { name: "relation_words_many", args: "p_organization_id uuid, p_field_id uuid, p_record_ids uuid[]", returns: "TABLE(record_id uuid, words text, archived boolean)", security: "definer" },
1202
+ { name: "reopen_declared_doors", args: "", returns: "TABLE(reopened text)", security: "definer" },
1203
+ { name: "required_epoch", args: "p_container_type text, p_container_id uuid, p_item_type text, p_item_id uuid", returns: "bigint", security: "definer" },
1204
+ { name: "resolve_context", args: "p_entity_type text, p_entity_id uuid, p_record_ids uuid[] DEFAULT NULL::uuid[], p_table_ids uuid[] DEFAULT NULL::uuid[], p_system_item_refs text[] DEFAULT NULL::text[]", returns: "jsonb", security: "definer" },
1205
+ { name: "resolve_first_match", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1206
+ { name: "resolve_id", args: "p_organization_id uuid, p_id uuid", returns: "uuid", security: "invoker" },
1207
+ { name: "retired_actor_words", args: "", returns: "jsonb", security: "invoker" },
1208
+ { name: "reverse_columns", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(key text, label text, source_field_id uuid, source_field_key text, source_field_label text, source_table_id uuid, source_table_name text, cardinality text, read_only boolean)", security: "definer" },
1209
+ { name: "reverse_links_many", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid, p_record_ids uuid[], p_limit integer DEFAULT 10, p_offset integer DEFAULT 0", returns: "TABLE(record_id uuid, total integer, links jsonb)", security: "definer" },
1210
+ { name: "rollup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
1211
+ { name: "row_actions", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1212
+ { name: "row_sits_in_a_personal_table", args: "p_type text, p_organization_id uuid, p_id uuid", returns: "boolean", security: "invoker" },
1213
+ { name: "row_template_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1214
+ { name: "row_templates", args: "p_organization_id uuid, p_table_id uuid", returns: 'TABLE(template_id uuid, name text, table_id uuid, "values" jsonb, created_at timestamp with time zone, updated_at timestamp with time zone)', security: "definer" },
1215
+ { name: "rule_applies", args: "p_organization_id uuid, p_rule_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1216
+ { name: "rule_context", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1217
+ { name: "rule_declare", args: "p_organization_id uuid, p_spec jsonb, p_rule_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
1218
+ { name: "rule_dependency_edges", args: "p_organization_id uuid, p_row custom.record DEFAULT NULL::custom.record", returns: "TABLE(needs text, needed text)", security: "invoker" },
1219
+ { name: "rule_eval", args: "p_organization_id uuid, p_expr jsonb, p_values jsonb, p_context jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
1220
+ { name: "rule_field_key", args: "p_organization_id uuid, p_field_id uuid", returns: "text", security: "invoker" },
1221
+ { name: "rule_field_label", args: "p_organization_id uuid, p_field_id uuid", returns: "text", security: "invoker" },
1222
+ { name: "rule_filter_node_sql", args: "p_organization_id uuid, p_table_id uuid, p_node jsonb, p_map jsonb, p_visible text[]", returns: "text", security: "invoker" },
1223
+ { name: "rule_kernel_id", args: "", returns: "uuid", security: "invoker" },
1224
+ { name: "rule_members", args: "p_organization_id uuid, p_rule_id uuid", returns: "SETOF custom.record", security: "invoker" },
1225
+ { name: "rule_members_visible", args: "p_organization_id uuid, p_rule_id uuid, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, document jsonb, level permission_level)", security: "definer" },
1226
+ { name: "rule_membership", args: "p_organization_id uuid, p_rule_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1227
+ { name: "rule_node_kinds", args: "", returns: "TABLE(node text, evaluated_by text, note text)", security: "invoker" },
1228
+ { name: "rule_restore", args: "p_organization_id uuid, p_rule_id uuid", returns: "boolean", security: "definer" },
1229
+ { name: "rule_run", args: "p_organization_id uuid, p_rule_id uuid, p_values jsonb, p_context jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
1230
+ { name: "rule_sql_op", args: "p_op text, p_a jsonb, p_b jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "invoker" },
1231
+ { name: "rule_truth", args: "p_answer jsonb", returns: "boolean", security: "invoker" },
1232
+ { name: "rule_uses", args: "", returns: "text[]", security: "invoker" },
1233
+ { name: "rule_version", args: "p_organization_id uuid, p_rule_id uuid", returns: "integer", security: "invoker" },
1234
+ { name: "said", args: "p_value text, p_when_there_is_none text", returns: "text", security: "invoker" },
1235
+ { name: "scope_item_row_of", args: "p_field custom.record", returns: "jsonb", security: "invoker" },
1236
+ { name: "scope_item_value_type", args: "p_field jsonb, p_carried jsonb", returns: "text", security: "invoker" },
1237
+ { name: "scope_items_of", args: "p_org uuid, p_table uuid", returns: "SETOF custom.record", security: "invoker" },
1238
+ { name: "scope_member_reaches", args: "p_user_id uuid, p_record_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "invoker" },
1239
+ { name: "scope_row_of", args: "p_rec custom.record", returns: "jsonb", security: "invoker" },
1240
+ { name: "scope_rows_of", args: "p_org uuid, p_types uuid[] DEFAULT NULL::uuid[]", returns: "TABLE(id uuid, table_id uuid, type_sort integer, sort_order integer, name text, type_doc jsonb, row_doc jsonb)", security: "invoker" },
1241
+ { name: "scope_setting_back", args: "p_value jsonb, p_behavior text", returns: "jsonb", security: "invoker" },
1242
+ { name: "scope_table_provision", args: "p_organization_id uuid, p_item_id uuid, p_scope_id uuid, p_home_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
1243
+ { name: "scope_type_row_of", args: "p_table custom.record", returns: "jsonb", security: "invoker" },
1244
+ { name: "scope_value_columns", args: "p_org uuid, p_field jsonb, p_value_type text, p_value jsonb", returns: "jsonb", security: "invoker" },
1245
+ { name: "seen_among", args: "p_user_id uuid, p_ids uuid[]", returns: "uuid[]", security: "definer" },
1246
+ { name: "sensitivity_rank", args: "p_sensitivity text", returns: "integer", security: "invoker" },
1247
+ { name: "set_table_confidential_arman_explicitly_approved", args: "p_table_id uuid, p_readers jsonb, p_arman_words text, p_approved_on date, p_maker_is_reader boolean DEFAULT NULL::boolean", returns: "jsonb", security: "definer" },
1248
+ { name: "share_access", args: "p_organization_id uuid, p_subject_id uuid", returns: "TABLE(principal_kind text, principal_id uuid, principal_label text, level permission_level, reason text, reason_detail text, via_type text, via_id uuid, revocable boolean)", security: "definer" },
1249
+ { name: "share_grant", args: "p_organization_id uuid, p_subject_id uuid, p_principal_kind text, p_principal_id uuid, p_level permission_level DEFAULT 'viewer'::permission_level", returns: "jsonb", security: "definer" },
1250
+ { name: "share_lane_set", args: "p_organization_id uuid, p_subject_id uuid, p_choice text, p_level permission_level DEFAULT NULL::permission_level", returns: "jsonb", security: "definer" },
1251
+ { name: "share_lanes", args: "", returns: "TABLE(choice text, lane text, discoverable boolean, label text, means text)", security: "definer" },
1252
+ { name: "share_levels", args: "", returns: "TABLE(level permission_level, ordinal integer, label text, means text)", security: "definer" },
1253
+ { name: "share_people", args: "p_organization_id uuid, p_subject_id uuid DEFAULT NULL::uuid, p_query text DEFAULT NULL::text, p_limit integer DEFAULT 25", returns: "TABLE(user_id uuid, email text, display_name text, membership text, already_at permission_level, already_why text)", security: "definer" },
1254
+ { name: "share_revoke", args: "p_organization_id uuid, p_subject_id uuid, p_principal_kind text, p_principal_id uuid", returns: "jsonb", security: "definer" },
1255
+ { name: "share_subject_name", args: "p_organization_id uuid, p_type text, p_id uuid", returns: "text", security: "definer" },
1256
+ { name: "shared_only_disagreements", args: "p_pretend text DEFAULT NULL::text", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, record_id uuid, table_id uuid, ladder boolean, read_door boolean, rls_mirror boolean, why text)", security: "invoker" },
1257
+ { name: "shares_outside", args: "p_organization_id uuid", returns: "TABLE(invitation_id uuid, table_id uuid, table_name text, email text, level text, level_label text, status text, joined boolean, expired boolean, invited_at timestamp with time zone, expires_at timestamp with time zone, say text)", security: "definer" },
1258
+ { name: "sign_request_cancel", args: "p_organization_id uuid, p_request_id uuid, p_reason text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1259
+ { name: "sign_request_create", args: "p_organization_id uuid, p_render_id uuid, p_field_key text, p_signer_email text, p_signer_name text, p_expires_in interval DEFAULT '14 days'::interval", returns: "jsonb", security: "definer" },
1260
+ { name: "sign_request_decline", args: "p_token text, p_reason text DEFAULT NULL::text, p_ip text DEFAULT NULL::text, p_user_agent text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1261
+ { name: "sign_request_public", args: "p_token text, p_origin text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1262
+ { name: "sign_request_remind", args: "p_organization_id uuid, p_request_id uuid", returns: "jsonb", security: "definer" },
1263
+ { name: "sign_request_sentence", args: "p_data jsonb", returns: "text", security: "invoker" },
1264
+ { name: "sign_request_sign", args: "p_token text, p_signed_name text, p_mark text, p_image text DEFAULT NULL::text, p_ip text DEFAULT NULL::text, p_user_agent text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1265
+ { name: "sign_request_state", args: "p_data jsonb", returns: "text", security: "invoker" },
1266
+ { name: "sign_request_unchanged", args: "p_organization_id uuid, p_request_id uuid", returns: "boolean", security: "definer" },
1267
+ { name: "sign_requests", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(request_id uuid, render_id uuid, record_id uuid, field_key text, document_title text, signer_name text, signer_email text, signer_has_account boolean, state text, sentence text, document_version integer, document_hash text, sent_at timestamp with time zone, expires_at timestamp with time zone, viewed_at timestamp with time zone, signed_at timestamp with time zone, declined_at timestamp with time zone, invalidated_at timestamp with time zone, signature_id uuid, signature_mark text, reminder_count integer)", security: "definer" },
1268
+ { name: "sign_token_decode", args: "p_token text", returns: "bytea", security: "invoker" },
1269
+ { name: "sign_token_encode", args: "p_bytes bytea", returns: "text", security: "invoker" },
1270
+ { name: "silent_page_doors", args: "", returns: "TABLE(door text, why text)", security: "definer" },
1271
+ { name: "size_refusal", args: "p_organization_id uuid, p_data jsonb", returns: "text", security: "invoker" },
1272
+ { name: "source_next_pointer", args: "p_sources jsonb", returns: "text", security: "invoker" },
1273
+ { name: "source_pointer", args: "p_sources jsonb, p_source jsonb", returns: "text", security: "invoker" },
1274
+ { name: "stage_rule_enforcement", args: "p_organization_id uuid", returns: "text", security: "invoker" },
1275
+ { name: "stage_rule_on_fail_kinds", args: "", returns: "TABLE(behaviour text, note text)", security: "invoker" },
1276
+ { name: "stamp_value_envelopes", args: "p_data jsonb, p_actor text, p_on_behalf_of text, p_at timestamp with time zone", returns: "jsonb", security: "invoker" },
1277
+ { name: "status_groups_keyed", args: "p_organization_id uuid, p_options_table_id uuid, p_groups jsonb, p_kept jsonb, p_label text", returns: "jsonb", security: "invoker" },
1278
+ { name: "status_groups_of", args: "p_groups jsonb", returns: "jsonb", security: "invoker" },
1279
+ { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
1280
+ { name: "store_census_pair_ceiling", args: "", returns: "integer", security: "invoker" },
1281
+ { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
1282
+ { name: "store_off_sentence", args: "p_organization_id uuid", returns: "text", security: "invoker" },
1283
+ { name: "subscription_cadences", args: "p_organization_id uuid", returns: "text[]", security: "definer" },
1284
+ { name: "subscription_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1285
+ { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
1286
+ { name: "subscription_preview", args: "p_organization_id uuid, p_rule_id uuid", returns: "jsonb", security: "definer" },
1287
+ { name: "subscriptions", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(rule_id uuid, name text, table_id uuid, saved_view_id uuid, cadence text, schedule text, quiet_hours jsonb, channel text, recipient_user_id uuid, event_key text, muted boolean, mine boolean, i_may_mute boolean, last_sent_at timestamp with time zone, next_digest_at timestamp with time zone)", security: "definer" },
1288
+ { name: "table_add_rung", args: "p_organization_id uuid, p_table_id uuid", returns: "permission_level", security: "invoker" },
1289
+ { name: "table_archive", args: "p_organization_id uuid, p_table_id uuid, p_chunk integer DEFAULT 50, p_include_table boolean DEFAULT true", returns: "jsonb", security: "definer" },
1290
+ { name: "table_archive_deliberately", args: "p_organization_id uuid, p_table_id uuid, p_typed_slug text, p_reason text", returns: "jsonb", security: "definer" },
1291
+ { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1292
+ { name: "table_carries_its_rows", args: "p_user_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
1293
+ { name: "table_column_source", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "invoker" },
1294
+ { name: "table_contents", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, kind text, goes_at integer)", security: "invoker" },
1295
+ { name: "table_copies_in_progress", args: "", returns: "jsonb", security: "definer" },
1296
+ { name: "table_declare", args: "p_organization_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1297
+ { name: "table_decorate", args: "p_organization_id uuid, p_table_id uuid, p_path text[], p_value jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "definer" },
1298
+ { name: "table_decorations", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1299
+ { name: "table_dimensions", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1300
+ { name: "table_dimensions_set", args: "p_organization_id uuid, p_table_id uuid, p_overrides jsonb", returns: "jsonb", security: "definer" },
1301
+ { name: "table_duplicate", args: "p_table_id uuid, p_with_records boolean DEFAULT false, p_name text DEFAULT NULL::text, p_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1302
+ { name: "table_duplicate_continue", args: "p_table_id uuid", returns: "jsonb", security: "definer" },
1303
+ { name: "table_ensure", args: "p_organization_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
1304
+ { name: "table_facts", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(table_id uuid, visibility text, mine boolean, kept_by_the_app boolean, kept_for text, offered_as_context boolean, keeper_group text, keeper_says text, used_in_kind text, used_in_id uuid, used_in_table_id uuid, foundation boolean)", security: "definer" },
1305
+ { name: "table_find", args: "p_organization_id uuid, p_slug text DEFAULT NULL::text, p_name text DEFAULT NULL::text, p_kept_for text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1306
+ { name: "table_from_example", args: "p_organization_id uuid, p_home_id uuid, p_example jsonb", returns: "jsonb", security: "definer" },
1307
+ { name: "table_has_a_visible_record", args: "p_user uuid, p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
1308
+ { name: "table_home", args: "p_table_id uuid, p_to_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1309
+ { name: "table_is_foundation", args: "p_data jsonb", returns: "boolean", security: "invoker" },
1310
+ { name: "table_is_live", args: "p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "invoker" },
1311
+ { name: "table_is_options_table", args: "p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "invoker" },
1312
+ { name: "table_is_platform_context", args: "p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "invoker" },
1313
+ { name: "table_kept_for_derived", args: "p_data jsonb, p_is_kernel boolean, p_is_options boolean", returns: "text", security: "invoker" },
1314
+ { name: "table_kept_out_of_lists", args: "p_kept_for text", returns: "boolean", security: "invoker" },
1315
+ { name: "table_kernel_id", args: "", returns: "uuid", security: "invoker" },
1316
+ { name: "table_kind_facts", args: "p_table_id uuid", returns: "jsonb", security: "definer" },
1317
+ { name: "table_list_everywhere", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1318
+ { name: "table_list_everywhere", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "jsonb", security: "invoker" },
1319
+ { name: "table_move", args: "p_table_id uuid, p_to_organization_id uuid, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1320
+ { name: "table_placement", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb, p_is_kernel boolean DEFAULT false", returns: "jsonb", security: "invoker" },
1321
+ { name: "table_record_ceiling", args: "", returns: "integer", security: "invoker" },
1322
+ { name: "table_record_ceiling", args: "p_organization_id uuid", returns: "integer", security: "invoker" },
1323
+ { name: "table_restore", args: "p_organization_id uuid, p_table_id uuid, p_chunk integer DEFAULT 20", returns: "jsonb", security: "definer" },
1324
+ { name: "table_row_counts", args: "p_organization_id uuid, p_table_ids uuid[]", returns: "TABLE(table_id uuid, visible_rows bigint)", security: "definer" },
1325
+ { name: "table_row_defaults", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1326
+ { name: "table_row_defaults_apply", args: "p_organization_id uuid, p_table_id uuid, p_after uuid DEFAULT NULL::uuid, p_budget_ms integer DEFAULT 4000", returns: "jsonb", security: "definer" },
1327
+ { name: "table_row_defaults_set", args: "p_organization_id uuid, p_table_id uuid, p_defaults jsonb", returns: "jsonb", security: "definer" },
1328
+ { name: "table_rules", args: "p_organization_id uuid, p_table_id uuid, p_use text, p_record_type text DEFAULT NULL::text", returns: "SETOF custom.record", security: "invoker" },
1329
+ { name: "table_share_outside", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1330
+ { name: "table_share_outside_accept", args: "p_token text", returns: "jsonb", security: "definer" },
1331
+ { name: "table_share_outside_for_me", args: "", returns: "TABLE(invitation_id uuid, organization_id uuid, organization text, table_id uuid, table_name text, level text, level_label text, token text, expires_at timestamp with time zone, say text)", security: "definer" },
1332
+ { name: "table_share_outside_grant", args: "p_organization_id uuid, p_table_id uuid, p_person text, p_level permission_level DEFAULT 'viewer'::permission_level", returns: "jsonb", security: "definer" },
1333
+ { name: "table_share_outside_invite", args: "p_organization_id uuid, p_table_id uuid, p_email text, p_level permission_level DEFAULT 'viewer'::permission_level", returns: "jsonb", security: "definer" },
1334
+ { name: "table_share_outside_resend", args: "p_organization_id uuid, p_invitation_id uuid", returns: "jsonb", security: "definer" },
1335
+ { name: "table_share_outside_revoke", args: "p_organization_id uuid, p_invitation_id uuid", returns: "jsonb", security: "definer" },
1336
+ { name: "table_stage_field", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "definer" },
1337
+ { name: "table_storage", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "invoker" },
1338
+ { name: "table_sync", args: "p_organization_id uuid, p_home_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
1339
+ { name: "table_transfer_owner", args: "p_table_id uuid, p_to_person uuid, p_reason text", returns: "jsonb", security: "definer" },
1340
+ { name: "table_type_field", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "definer" },
1341
+ { name: "table_unique_rule_fields", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
1342
+ { name: "table_webhook_archive", args: "p_organization_id uuid, p_webhook_id uuid", returns: "boolean", security: "definer" },
1343
+ { name: "table_webhook_declare", args: "p_organization_id uuid, p_table_id uuid, p_target_url text, p_events text[] DEFAULT NULL::text[], p_description text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1344
+ { name: "table_webhooks", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(webhook_id uuid, target_url text, description text, events text[], is_active boolean, last_attempt_at timestamp with time zone, last_success_at timestamp with time zone, consecutive_failures integer, owner_id uuid, created_at timestamp with time zone)", security: "definer" },
1345
+ { name: "table_work_kind", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "invoker" },
1346
+ { name: "tables_at_home", args: "p_organization_id uuid, p_home_ids uuid[]", returns: "TABLE(table_id uuid, home_record_id uuid, kind text)", security: "definer" },
1347
+ { name: "tables_described_without_asking", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
1348
+ { name: "tables_i_can_open", args: "", returns: "TABLE(table_id uuid, table_name text, organization_id uuid, organization_name text, member boolean, visibility text, updated_at timestamp with time zone)", security: "definer" },
1349
+ { name: "tables_listed_among", args: "p_organization_id uuid, p_tables uuid[]", returns: "SETOF uuid", security: "invoker" },
1350
+ { name: "tables_seen_among", args: "p_user_id uuid, p_organization_ids uuid[], p_among uuid[]", returns: "TABLE(organization_id uuid, id uuid, seen boolean)", security: "definer" },
1351
+ { name: "tables_seen_once_per_group", args: "p_user_id uuid, p_organization_ids uuid[]", returns: "TABLE(organization_id uuid, id uuid, seen boolean)", security: "definer" },
1352
+ { name: "tables_shared_with_me", args: "", returns: "TABLE(table_id uuid, organization_id uuid, organization text, table_name text, level text, level_label text, shared_at timestamp with time zone, opens boolean, say text)", security: "definer" },
1353
+ { name: "template_declare", args: "p_scope text, p_spec jsonb", returns: "jsonb", security: "definer" },
1354
+ { name: "template_from_tables", args: "p_organization_id uuid, p_table_ids uuid[], p_include_rows boolean DEFAULT false, p_rows_per_table integer DEFAULT 25", returns: "jsonb", security: "definer" },
1355
+ { name: "template_install", args: "p_organization_id uuid, p_template_id uuid, p_budget_ms integer DEFAULT 4000", returns: "jsonb", security: "definer" },
1356
+ { name: "template_install_claim", args: "p_organization_id uuid, p_install_id uuid, p_kind text, p_label text, p_source_id uuid DEFAULT NULL::uuid, p_lease_seconds integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1357
+ { name: "template_install_note", args: "p_organization_id uuid, p_install_id uuid, p_kind text, p_id uuid, p_label text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1358
+ { name: "template_restore", args: "p_organization_id uuid, p_install_id uuid, p_budget_ms integer DEFAULT 4000", returns: "jsonb", security: "definer" },
1359
+ { name: "template_uninstall", args: "p_organization_id uuid, p_install_id uuid, p_budget_ms integer DEFAULT 4000", returns: "jsonb", security: "definer" },
1360
+ { name: "templates", args: "p_filter jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
1361
+ { name: "text_head_bytes", args: "p_text text, p_bytes bigint", returns: "text", security: "invoker" },
1362
+ { name: "trg_associations_bump_visibility", args: "", returns: "trigger", security: "definer" },
1363
+ { name: "undeclared_keys", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "text[]", security: "invoker" },
1364
+ { name: "unresolved_sources_of", args: "p_sources jsonb, p_visible text[], p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
1365
+ { name: "validate_custom_fields", args: "p_token text, p_organization_id uuid, p_values jsonb", returns: "void", security: "invoker" },
1366
+ { name: "validate_value_envelope", args: "p_organization_id uuid, p_fields custom.record[], p_data jsonb", returns: "void", security: "invoker" },
1367
+ { name: "validate_values", args: "p_organization_id uuid, p_fields custom.record[], p_values jsonb, p_record_type text DEFAULT NULL::text", returns: "void", security: "invoker" },
1368
+ { name: "value_alternate_keys", args: "", returns: "text[]", security: "invoker" },
1369
+ { name: "value_envelope_keys", args: "", returns: "text[]", security: "invoker" },
1370
+ { name: "value_envelope_ok", args: "p_data jsonb", returns: "boolean", security: "invoker" },
1371
+ { name: "value_envelope_refusal", args: "p_data jsonb", returns: "text", security: "invoker" },
1372
+ { name: "value_read", args: "p_organization_id uuid, p_record_id uuid, p_key text", returns: "TABLE(field_key text, field_id uuid, value jsonb, value_version integer, source jsonb, absent_reason text, actor text, on_behalf_of text, written_at timestamp with time zone, alternates jsonb)", security: "definer" },
1373
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer", returns: "jsonb", security: "definer" },
1374
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
1375
+ { name: "value_versions", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
1376
+ { name: "view_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1377
+ { name: "view_designate", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid, p_layout text DEFAULT NULL::text", returns: "uuid", security: "definer" },
1378
+ { name: "view_keys", args: "", returns: "TABLE(path text, shape text, layouts text[], writer text, sentence text)", security: "invoker" },
1379
+ { name: "view_keys_check", args: "p_organization_id uuid, p_table_id uuid, p_set jsonb, p_old jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
1380
+ { name: "view_look_read", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1381
+ { name: "view_look_set", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid, p_look jsonb", returns: "jsonb", security: "definer" },
1382
+ { name: "view_record_order_set", args: "p_organization_id uuid, p_view_id uuid, p_record_ids uuid[]", returns: "jsonb", security: "definer" },
1383
+ { name: "views", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(view_id uuid, name text, table_id uuid, filters jsonb, definition jsonb, created_at timestamp with time zone)", security: "definer" },
1384
+ { name: "visibility_ancestors", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, depth integer, max_level permission_level)", security: "definer" },
1385
+ { name: "visibility_as_of", args: "p_organization_id uuid, p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(principal_kind text, principal_id uuid, level permission_level, through_kind text, through_id uuid, reason text, replayed boolean, held_from timestamp with time zone, held_to timestamp with time zone)", security: "definer" },
1386
+ { name: "visibility_cache_rebuild", args: "", returns: "integer", security: "definer" },
1387
+ { name: "visibility_parity", args: "", returns: "TABLE(side text, container_type text, container_id uuid, item_type text, item_id uuid, stored_level permission_level, derived_level permission_level, reason text)", security: "definer" },
1388
+ { name: "visibility_warm", args: "p_container_type text, p_container_id uuid", returns: "integer", security: "definer" },
1389
+ { name: "visible_predicate_sql", args: "p_user uuid, p_organization_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, p_alias text DEFAULT 'r'::text", returns: "text", security: "definer" },
1390
+ { name: "visible_record_ids", args: "p_user_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "TABLE(id uuid)", security: "definer" },
1391
+ { name: "visible_set", args: "p_user uuid, p_organization_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, OUT o_all_visible boolean, OUT o_true_visibility platform.visibility[], OUT o_granted_all uuid[], OUT o_granted_visible uuid[], OUT o_carried_visible uuid[], OUT o_ladder_calls integer, OUT o_fallback boolean, OUT o_note text", returns: "record", security: "definer" },
1392
+ { name: "where_id_opens", args: "p_id uuid", returns: "jsonb", security: "definer" },
1393
+ { name: "where_lists_live", args: "p_list_ids uuid[]", returns: "TABLE(list_id uuid, lives_in text, address text, why text)", security: "definer" },
1394
+ { name: "where_tables_live", args: "p_table_ids uuid[]", returns: "TABLE(table_id uuid, lives_in text, why text)", security: "definer" },
1395
+ { name: "whole_value_ceiling", args: "p_organization_id uuid", returns: "bigint", security: "invoker" },
1396
+ { name: "whole_value_complete", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_file_id uuid", returns: "jsonb", security: "definer" },
1397
+ { name: "whole_value_head", args: "p_text text", returns: "text", security: "invoker" },
1398
+ { name: "whole_value_park", args: "p_organization_id uuid, p_table_id uuid, p_record_id uuid, p_owner_id uuid, p_visibility platform.visibility, p_data jsonb, p_park jsonb", returns: "void", security: "invoker" },
1399
+ { name: "whole_value_pointer_of", args: "p_values jsonb, p_sources jsonb, p_key text", returns: "jsonb", security: "invoker" },
1400
+ { name: "whole_value_source", args: "p_text text, p_writer_src jsonb", returns: "jsonb", security: "invoker" },
1401
+ { name: "whole_values_waiting", args: "p_organization_id uuid, p_record_ids uuid[]", returns: "TABLE(record_id uuid, field_key text, pointer text, value_version integer, sha256 text, bytes bigint, chars bigint, owner_id uuid, record_visibility text, table_id uuid, table_name text)", security: "definer" },
1402
+ { name: "widget_kernel_id", args: "", returns: "uuid", security: "invoker" },
1403
+ { name: "with_whole_value_pointers", args: "p_document jsonb, p_values jsonb, p_sources jsonb, p_visible text[], p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
1404
+ { name: "withheld_marker", args: "p_mask jsonb, p_key text", returns: "jsonb", security: "invoker" },
1405
+ { name: "withheld_sentence", args: "p_mask jsonb, p_key text", returns: "text", security: "invoker" },
1406
+ { name: "work_approval_approvers", args: "p_organization_id uuid, p_subject_id uuid, p_approver_id uuid DEFAULT NULL::uuid", returns: "TABLE(user_id uuid, name text, why text)", security: "definer" },
1407
+ { name: "work_approval_decide", args: "p_organization_id uuid, p_approval_id uuid, p_approve boolean, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
1408
+ { name: "work_approval_kinds", args: "", returns: "text[]", security: "invoker" },
1409
+ { name: "work_approval_may_decide", args: "p_organization_id uuid, p_approval_id uuid", returns: "boolean", security: "definer" },
1410
+ { name: "work_approval_read", args: "p_organization_id uuid, p_approval_id uuid", returns: "jsonb", security: "definer" },
1411
+ { name: "work_approval_request", args: "p_organization_id uuid, p_subject_id uuid, p_change jsonb, p_note text DEFAULT NULL::text, p_approver_id uuid DEFAULT NULL::uuid, p_origin text DEFAULT 'person'::text, p_conversation_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1412
+ { name: "work_approval_withdrawal", args: "p_organization_id uuid, p_data jsonb", returns: "text", security: "invoker" },
1413
+ { name: "work_assign", args: "p_organization_id uuid, p_record_id uuid, p_assignee_user_id uuid, p_due_date timestamp with time zone DEFAULT NULL::timestamp with time zone, p_clear_due boolean DEFAULT false", returns: "jsonb", security: "definer" },
1414
+ { name: "work_assignment_fields", args: "p_options_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(key text, label text, spec jsonb)", security: "invoker" },
1415
+ { name: "work_decide_many", args: "p_organization_id uuid, p_decisions jsonb", returns: "jsonb", security: "definer" },
1416
+ { name: "work_has_assignment", args: "p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
1417
+ { name: "work_inbox", args: "p_organization_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0, p_include_decided boolean DEFAULT false, p_view text DEFAULT 'inbox'::text", returns: "TABLE(item_id uuid, kind text, origin text, title text, subject_id uuid, subject_kind text, summary text, state text, due_on timestamp with time zone, due_state text, actionable boolean, requested_by uuid, requested_by_name text, at timestamp with time zone, table_id uuid, table_name text, decided_by uuid, decided_by_name text, decided_at timestamp with time zone, outcome text, snoozed_until timestamp with time zone, cleared_at timestamp with time zone, snoozed_count integer, cleared_count integer, undo_seconds integer, undo_refusal text)", security: "definer" },
1418
+ { name: "work_instantiation_shape", args: "p_organization_id uuid, p_instantiation_id uuid", returns: "jsonb", security: "definer" },
1419
+ { name: "work_list", args: "p_organization_id uuid DEFAULT NULL::uuid, p_flavour text DEFAULT 'mine'::text, p_include_finished boolean DEFAULT false, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0", returns: "TABLE(record_id uuid, table_id uuid, table_name text, title text, assignee_id uuid, assignee_name text, assignee_user_id uuid, due_on timestamp with time zone, due_state text, status text, terminal boolean, assigned_by uuid, updated_at timestamp with time zone)", security: "definer" },
1420
+ { name: "work_person", args: "p_organization_id uuid, p_user_id uuid, p_create boolean DEFAULT true", returns: "uuid", security: "definer" },
1421
+ { name: "work_record_states", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(state_id uuid, name text, sort integer, terminal boolean, is_current boolean, allowed boolean, refusal text)", security: "definer" },
1422
+ { name: "work_relation_kinds", args: "", returns: "TABLE(kind text, available boolean, why text)", security: "invoker" },
1423
+ { name: "work_set_state", args: "p_organization_id uuid, p_record_id uuid, p_state_id uuid", returns: "jsonb", security: "definer" },
1424
+ { name: "work_slot_expire", args: "p_organization_id uuid, p_table_id uuid", returns: "integer", security: "definer" },
1425
+ { name: "work_slot_hold", args: "p_organization_id uuid, p_table_id uuid, p_slot_key text, p_holder text, p_ttl interval DEFAULT '00:15:00'::interval", returns: "jsonb", security: "definer" },
1426
+ { name: "work_slot_holds", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(hold_id uuid, slot_key text, holder text, expires_at timestamp with time zone, expired boolean)", security: "definer" },
1427
+ { name: "work_slot_index_name", args: "p_table_id uuid", returns: "text", security: "invoker" },
1428
+ { name: "work_slot_release", args: "p_organization_id uuid, p_hold_id uuid", returns: "boolean", security: "definer" },
1429
+ { name: "work_slots_declare", args: "p_organization_id uuid, p_name text, p_slug text, p_home_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1430
+ { name: "work_state_id", args: "p_organization_id uuid, p_table_id uuid, p_value text", returns: "uuid", security: "invoker" },
1431
+ { name: "work_states", args: "", returns: "TABLE(sort integer, name text, terminal boolean, next text[])", security: "invoker" },
1432
+ { name: "work_take_assignment", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1433
+ { name: "work_template_declare", args: "p_organization_id uuid, p_name text, p_graph jsonb", returns: "uuid", security: "definer" },
1434
+ { name: "work_template_instantiate", args: "p_organization_id uuid, p_template_id uuid, p_overrides jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
1435
+ { name: "work_template_refusal", args: "p_graph jsonb", returns: "text", security: "invoker" },
1436
+ { name: "work_template_shape", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
1437
+ { name: "work_templates", args: "p_organization_id uuid, p_limit integer DEFAULT 100", returns: "TABLE(template_id uuid, name text, nodes integer, relations integer, created_at timestamp with time zone)", security: "definer" },
1438
+ { name: "work_transition_refusal", args: "p_organization_id uuid, p_from_state_id uuid, p_to_state_id uuid", returns: "text", security: "definer" },
1439
+ { name: "work_whose_turn", args: "p_organization_id uuid, p_table_id uuid, p_include_finished boolean DEFAULT false", returns: "TABLE(record_id uuid, title text, assignee_id uuid, turn text, due_on timestamp with time zone, state text, status text, terminal boolean)", security: "definer" }
1440
+ ];
1441
+
1442
+ // src/templates/validate.ts
1443
+ var pad = (n, w = 2) => String(n).padStart(w, "0");
1444
+ function zoneOffset(localIso, timeZone) {
1445
+ const [d, t = "00:00"] = localIso.split("T");
1446
+ const [y, mo, da] = (d ?? "").split("-").map(Number);
1447
+ const [h, mi] = t.split(":").map(Number);
1448
+ const guess = Date.UTC(y ?? 1970, (mo ?? 1) - 1, da ?? 1, h ?? 0, mi ?? 0);
1449
+ const read = (at) => {
1450
+ const part = new Intl.DateTimeFormat("en-US", { timeZone, timeZoneName: "longOffset" }).formatToParts(new Date(at)).find((p) => p.type === "timeZoneName")?.value;
1451
+ const m = /GMT([+-])(\d{2}):?(\d{2})?/.exec(part ?? "");
1452
+ return m ? (m[1] === "-" ? -1 : 1) * (Number(m[2]) * 60 + Number(m[3] ?? 0)) : 0;
1453
+ };
1454
+ const minutes = read(guess - read(guess) * 6e4);
1455
+ const sign = minutes < 0 ? "-" : "+";
1456
+ return `${sign}${pad(Math.floor(Math.abs(minutes) / 60))}:${pad(Math.abs(minutes) % 60)}`;
1457
+ }
1458
+ function addToDay(today, sign, n, unit) {
1459
+ const [y, m, d] = today.split("-").map(Number);
1460
+ const k = sign === "-" ? -n : n;
1461
+ if (unit === "d" || unit === "w") {
1462
+ const at = new Date(Date.UTC(y, m - 1, d + (unit === "w" ? 7 * k : k)));
1463
+ return `${at.getUTCFullYear()}-${pad(at.getUTCMonth() + 1)}-${pad(at.getUTCDate())}`;
1464
+ }
1465
+ const months = unit === "y" ? 12 * k : k;
1466
+ const first = new Date(Date.UTC(y, m - 1 + months, 1));
1467
+ const last = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth() + 1, 0)).getUTCDate();
1468
+ return `${first.getUTCFullYear()}-${pad(first.getUTCMonth() + 1)}-${pad(Math.min(d, last))}`;
1469
+ }
1470
+ var WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
1471
+ var dayOfWeek = (day) => (/* @__PURE__ */ new Date(`${day}T00:00:00Z`)).getUTCDay();
1472
+ var shiftDays = (day, n) => addToDay(day, n < 0 ? "-" : "+", Math.abs(n), "d");
1473
+ function addBusinessDays(day, n) {
1474
+ let d = day;
1475
+ let left = Math.abs(n);
1476
+ while (left > 0) {
1477
+ d = shiftDays(d, n < 0 ? -1 : 1);
1478
+ const w = dayOfWeek(d);
1479
+ if (w !== 0 && w !== 6) left -= 1;
1480
+ }
1481
+ return d;
1482
+ }
1483
+ function resolveDateToken(token, today, timeZone) {
1484
+ const m = RELATIVE_DATE.exec(token);
1485
+ if (!m) return null;
1486
+ let day = today;
1487
+ const anchor = m[1] ?? "today";
1488
+ if (anchor !== "today") {
1489
+ const name = anchor.replace(/^(last|next)-/, "");
1490
+ const monday = shiftDays(today, -((dayOfWeek(today) + 6) % 7));
1491
+ day = shiftDays(monday, (WEEKDAYS.indexOf(name) + 6) % 7 + (anchor.startsWith("last-") ? -7 : anchor.startsWith("next-") ? 7 : 0));
1492
+ }
1493
+ if (m[2]) {
1494
+ const n = Number(m[3]) * (m[2] === "-" ? -1 : 1);
1495
+ day = m[4] === "b" ? addBusinessDays(day, n) : addToDay(day, m[2], Number(m[3]), m[4] ?? "d");
1496
+ }
1497
+ if (m[5]) {
1498
+ const w = dayOfWeek(day);
1499
+ if (w === 6) day = shiftDays(day, 2);
1500
+ if (w === 0) day = shiftDays(day, 1);
1501
+ }
1502
+ if (m[6] === void 0) return day;
1503
+ const local = `${day}T${m[6]}:${m[7]}`;
1504
+ return `${local}:00${zoneOffset(local, timeZone)}`;
1505
+ }
1506
+ var BEHAVIOR_OF = new Map([
1507
+ ...PARITY_FIELD_TYPES.map((t) => [t.parity_type, t.behavior]),
1508
+ ...DECLARABLE_FIELD_KINDS.map((k) => [k.kind, k.behavior]),
1509
+ ["number", "range"],
1510
+ ["integer", "range"],
1511
+ ["decimal", "range"],
1512
+ ["float", "range"],
1513
+ ["long_text", "text"],
1514
+ ["string", "text"],
1515
+ ["text", "text"]
1516
+ ]);
1517
+ function blockTable(block, rows) {
1518
+ const b = SHARED_BLOCKS[block];
1519
+ return {
1520
+ token: b.table,
1521
+ name: b.name,
1522
+ labelSingular: b.labelSingular,
1523
+ labelPlural: b.labelPlural,
1524
+ type: "entity",
1525
+ display: "grid",
1526
+ weight: "light",
1527
+ ordered: false,
1528
+ titleField: b.titleField,
1529
+ describes: b.describes,
1530
+ fields: b.fields.map(({ sameAs: _sameAs, ...f }) => ({ ...f })),
1531
+ rows
1532
+ };
1533
+ }
1534
+ function allTables(spec) {
1535
+ return [...spec.tables ?? [], ...(spec.sharedBlocks ?? []).filter((s) => SHARED_BLOCKS[s.block]).map((s) => blockTable(s.block, s.rows ?? []))];
1536
+ }
1537
+ var STORE_DOOR_NAMES = new Set(STORE_DOORS.map((d) => d.name));
1538
+ var STORE_FIELD_KINDS = new Set(BEHAVIOR_OF.keys());
1539
+
1540
+ // src/templates/plan.ts
1541
+ var INSTALL_PLAN_VERSION = 1;
1542
+ var ROW_BATCH = 10;
1543
+ var DERIVED = /* @__PURE__ */ new Set(["lookup", "rollup"]);
1544
+ var FILE_VALUE = /^@file:([A-Za-z0-9_.-]+)$/;
1545
+ var TOKEN_NAME = /^[A-Za-z0-9_.:-]+$/;
1546
+ var ref = (name) => {
1547
+ if (!TOKEN_NAME.test(name)) throw new Error(`"${name}" cannot be an id name in an install plan (letters, digits, _ . : - only).`);
1548
+ return `\${ref:${name}}`;
1549
+ };
1550
+ var minted = (name) => {
1551
+ if (!TOKEN_NAME.test(name)) throw new Error(`"${name}" cannot be an id name in an install plan (letters, digits, _ . : - only).`);
1552
+ return `\${new:${name}}`;
1553
+ };
1554
+ function tokenizeValues(value, attachments) {
1555
+ const walk = (v) => {
1556
+ if (typeof v === "string") {
1557
+ if (RELATIVE_DATE.test(v)) return `\${date:${v}}`;
1558
+ const f = FILE_VALUE.exec(v);
1559
+ if (f) {
1560
+ if (!attachments.has(f[1])) throw new Error(`A row points at the file "${f[1]}", which the template's attachments do not list.`);
1561
+ return ref(`files.${f[1]}`);
1562
+ }
1563
+ return v;
1564
+ }
1565
+ if (Array.isArray(v)) return v.map(walk);
1566
+ if (v && typeof v === "object") return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));
1567
+ return v;
1568
+ };
1569
+ return walk(value);
1570
+ }
1571
+ function compileInstallPlan(written) {
1572
+ const attachments = written.attachments ?? [];
1573
+ const attachmentKeys = new Set(attachments.map((a) => a.key));
1574
+ const spec = tokenizeValues({ ...written, attachments: void 0 }, attachmentKeys);
1575
+ const bound = new Map(allTables(spec).filter((t) => t.bindsTo?.tableId).map((t) => [t.token, t.bindsTo]));
1576
+ const has = (token, key) => bound.get(token)?.fields.includes(key) ?? false;
1577
+ const tables = allTables(spec).map((t) => {
1578
+ if (bound.has(t.token)) return { ...t, rows: [] };
1579
+ const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget)).map((f) => f.key);
1580
+ if (!toBound.length) return t;
1581
+ return { ...t, rows: t.rows.map((r) => ({ ...r, values: Object.fromEntries(Object.entries(r.values ?? {}).filter(([k]) => !toBound.includes(k))) })) };
1582
+ });
1583
+ const steps = [];
1584
+ const tableRef = (token) => {
1585
+ if (!tables.some((t) => t.token === token)) throw new Error(`The template names a table "${token}" it does not have.`);
1586
+ return ref(`tables.${token}`);
1587
+ };
1588
+ const tableTokens = Object.fromEntries(tables.map((t) => [t.token, ref(`tables.${t.token}`)]));
1589
+ const bookingProblem = spec.extras.filter((e) => e.kind === "booking").map((b) => bookingColumnsProblem(tables, b)).find((p) => p);
1590
+ if (bookingProblem) throw new Error(bookingProblem);
1591
+ steps.push({ label: "home.kernel", door: "person_kernel_id", args: {}, save: { "kernel.person": [] } });
1592
+ steps.push({
1593
+ label: "home",
1594
+ door: "record_write",
1595
+ args: { p_organization_id: "${org}", p_table_id: ref("kernel.person"), p_data: { name: `${spec.business.name} Home` } },
1596
+ save: { home: [] },
1597
+ made: [{ kind: "record", ref: "home", title: `${spec.business.name} Home` }]
1598
+ });
1599
+ if (attachments.length) {
1600
+ steps.push({ label: "files.kernel", door: "file_kernel_id", args: {}, save: { "kernel.file": [] } });
1601
+ for (const a of attachments) {
1602
+ steps.push({
1603
+ label: `files.${a.key}`,
1604
+ door: "record_write",
1605
+ args: { p_organization_id: "${org}", p_table_id: ref("kernel.file"), p_data: { file_id: a.fileId, name: a.name, mime: a.mime, bytes: a.bytes } },
1606
+ save: { [`files.${a.key}`]: [] },
1607
+ made: [{ kind: "record", ref: `files.${a.key}`, title: a.name }]
1608
+ });
1609
+ }
1610
+ }
1611
+ for (const t of tables) {
1612
+ if (bound.has(t.token)) {
1613
+ for (const f of t.fields.filter((x) => !DERIVED.has(x.parityType) && x.parityType !== "formula" && x.parityType !== "relation" && !isSelfDeclaredField(x) && !has(t.token, x.key))) {
1614
+ steps.push({
1615
+ label: `bound.${t.token}.${f.key}`,
1616
+ door: "field_declare",
1617
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: selfDeclaredFieldSpec(f) },
1618
+ save: { [`fields.${t.token}.${f.key}`]: [] },
1619
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
1620
+ });
1621
+ }
1622
+ continue;
1623
+ }
1624
+ steps.push({
1625
+ label: `tables.${t.token}`,
1626
+ door: "table_from_example",
1627
+ args: { p_organization_id: "${org}", p_home_id: ref("home"), p_example: tableShellPayload(spec, t) },
1628
+ saveEach: { array: ["tables"], key: ["token"], value: ["table_id"], prefix: "tables." },
1629
+ made: [{ kind: "table", ref: `tables.${t.token}`, title: t.name }]
1630
+ });
1631
+ }
1632
+ steps.push(...membersAddRowsSteps(spec, tableRef));
1633
+ for (const t of tables) {
1634
+ for (const f of t.fields.filter((x) => x.parityType === "relation" && x.relationTarget && !has(t.token, x.key))) {
1635
+ steps.push({
1636
+ label: `relations.${t.token}.${f.key}`,
1637
+ door: "field_declare",
1638
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: relationFieldSpec(f, tableRef(f.relationTarget)) },
1639
+ save: { [`fields.${t.token}.${f.key}`]: [] },
1640
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
1641
+ });
1642
+ }
1643
+ }
1644
+ for (const t of tables) {
1645
+ for (const f of t.fields.filter((x) => isSelfDeclaredField(x) && !has(t.token, x.key))) {
1646
+ steps.push({
1647
+ label: `self_declared.${t.token}.${f.key}`,
1648
+ door: "field_declare",
1649
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: selfDeclaredFieldSpec(f) },
1650
+ save: { [`fields.${t.token}.${f.key}`]: [] },
1651
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
1652
+ });
1653
+ }
1654
+ }
1655
+ const rowIds = /* @__PURE__ */ new Map();
1656
+ for (const t of tables) for (const r of t.rows) rowIds.set(`${t.token}.${r.key}`, minted(`row.${t.token}.${r.key}`));
1657
+ const deferred = deferredRelations(tables);
1658
+ for (const level of rowLevels(tables)) {
1659
+ for (const t of level) {
1660
+ const { rows, ids } = rowsFor(t, rowIds, deferred.get(t.token));
1661
+ for (let i = 0; i < rows.length; i += ROW_BATCH) {
1662
+ steps.push({
1663
+ label: `rows.${t.token}.${i / ROW_BATCH + 1}`,
1664
+ door: "record_write_many",
1665
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_rows: rows.slice(i, i + ROW_BATCH), p_ids: ids.slice(i, i + ROW_BATCH) }
1666
+ });
1667
+ }
1668
+ }
1669
+ }
1670
+ for (const t of tables) {
1671
+ const changes = relationPatches(t, rowIds, deferred.get(t.token));
1672
+ for (let i = 0; i < changes.length; i += ROW_BATCH) {
1673
+ steps.push({
1674
+ label: `links.${t.token}.${i / ROW_BATCH + 1}`,
1675
+ door: "record_change_many",
1676
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_changes: changes.slice(i, i + ROW_BATCH) }
1677
+ });
1678
+ }
1679
+ }
1680
+ for (const t of tables) {
1681
+ for (const f of t.fields.filter((x) => DERIVED.has(x.parityType) && !has(t.token, x.key))) {
1682
+ steps.push({
1683
+ label: `derived.${t.token}.${f.key}`,
1684
+ door: "field_declare",
1685
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: derivedFieldSpec(f) },
1686
+ save: { [`fields.${t.token}.${f.key}`]: [] },
1687
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
1688
+ });
1689
+ }
1690
+ }
1691
+ for (const t of tables) {
1692
+ for (const f of formulaOrder(t).filter((x) => !has(t.token, x.key))) {
1693
+ steps.push({
1694
+ label: `formula.${t.token}.${f.key}`,
1695
+ door: "field_declare",
1696
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: formulaFieldSpec(f) },
1697
+ save: { [`fields.${t.token}.${f.key}`]: [] },
1698
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
1699
+ });
1700
+ }
1701
+ }
1702
+ const needIds = /* @__PURE__ */ new Set([
1703
+ ...spec.extras.filter((e) => e.kind === "document" || e.kind === "row_action").map((e) => e.table),
1704
+ ...spec.views.filter((v) => v.anyOf && Object.keys(v.anyOf).length).map((v) => v.table)
1705
+ ]);
1706
+ const fieldRefs = (token) => {
1707
+ const t = tables.find((x) => x.token === token);
1708
+ return Object.fromEntries((t?.fields ?? []).map((f) => [f.key, ref(`fields.${token}.${f.key}`)]));
1709
+ };
1710
+ for (const token of needIds) {
1711
+ steps.push({
1712
+ label: `field_ids.${token}`,
1713
+ door: "applicable_fields",
1714
+ args: { p_organization_id: "${org}", p_table_id: tableRef(token), p_record_type: null },
1715
+ saveEach: { array: [], key: ["data", "key"], value: ["id"], prefix: `fields.${token}.` }
1716
+ });
1717
+ }
1718
+ for (const d of spec.dimensions.filter((x) => !bound.has(x.table))) {
1719
+ const overrides = {};
1720
+ if (d.dimensions) overrides["dimensions"] = d.dimensions;
1721
+ if (d.measures) overrides["measures"] = d.measures;
1722
+ if (d.paths) overrides["paths"] = d.paths;
1723
+ if (d.default) overrides["default"] = d.default;
1724
+ steps.push({
1725
+ label: `dimensions.${d.table}`,
1726
+ door: "table_dimensions_set",
1727
+ args: { p_organization_id: "${org}", p_table_id: tableRef(d.table), p_overrides: overrides }
1728
+ });
1729
+ }
1730
+ for (const v of spec.views) {
1731
+ steps.push({
1732
+ label: `views.${v.token}`,
1733
+ door: "view_declare",
1734
+ args: { p_organization_id: "${org}", p_table_id: tableRef(v.table), p_spec: viewSpec(v, fieldRefs(v.table)) },
1735
+ save: { [`views.${v.token}`]: [] },
1736
+ made: [{ kind: "view", ref: `views.${v.token}`, title: v.name, table: `tables.${v.table}` }]
1737
+ });
1738
+ }
1739
+ for (const f of spec.forms) {
1740
+ steps.push({
1741
+ label: `forms.${f.token}`,
1742
+ door: "form_declare",
1743
+ args: formArgs("${org}", tableRef(f.table), f),
1744
+ save: { [`forms.${f.token}`]: [] },
1745
+ made: [{ kind: "form", ref: `forms.${f.token}`, title: f.name, table: `tables.${f.table}` }]
1746
+ });
1747
+ }
1748
+ const actionsByTable = /* @__PURE__ */ new Map();
1749
+ const formRefs = Object.fromEntries(spec.forms.map((f) => [f.token, ref(`forms.${f.token}`)]));
1750
+ const documentRefs = Object.fromEntries(
1751
+ spec.extras.filter((e) => e.kind === "document").map((e) => [e.token, ref(`documents.${e.token}`)])
1752
+ );
1753
+ const extrasInOrder = [...spec.extras.filter((e) => e.kind === "document"), ...spec.extras.filter((e) => e.kind !== "document")];
1754
+ for (const e of extrasInOrder) {
1755
+ switch (e.kind) {
1756
+ case "booking":
1757
+ steps.push({
1758
+ label: `bookings.${e.token}`,
1759
+ door: "booking_declare",
1760
+ args: bookingArgs("${org}", tableRef(e.table), e),
1761
+ save: { [`bookings.${e.token}.form`]: ["form_id"], [`bookings.${e.token}.slots`]: ["slot_table_id"] },
1762
+ made: [
1763
+ { kind: "form", ref: `bookings.${e.token}.form`, title: e.title, table: `tables.${e.table}` },
1764
+ { kind: "table", ref: `bookings.${e.token}.slots`, title: `${e.title} slots` }
1765
+ ]
1766
+ });
1767
+ break;
1768
+ case "dashboard":
1769
+ steps.push({
1770
+ label: `dashboards.${e.token}`,
1771
+ door: "dashboard_declare",
1772
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.table), p_name: e.name, p_blocks: dashboardBlocks(e, tableTokens), p_presentation: {}, p_dashboard_id: null },
1773
+ save: { [`dashboards.${e.token}`]: [] },
1774
+ made: [{ kind: "dashboard", ref: `dashboards.${e.token}`, title: e.name, table: `tables.${e.table}` }]
1775
+ });
1776
+ break;
1777
+ case "drill_down": {
1778
+ const d = drillDownDashboard(e, spec.dimensions);
1779
+ steps.push({
1780
+ label: `dashboards.${e.token}`,
1781
+ door: "dashboard_declare",
1782
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.table), p_name: d.name, p_blocks: d.blocks, p_presentation: {}, p_dashboard_id: null },
1783
+ save: { [`dashboards.${e.token}`]: [] },
1784
+ made: [{ kind: "dashboard", ref: `dashboards.${e.token}`, title: e.name, table: `tables.${e.table}` }]
1785
+ });
1786
+ break;
1787
+ }
1788
+ case "digest": {
1789
+ const view = spec.views.find((v) => v.token === e.view);
1790
+ if (!view) throw new Error(`The digest "${e.name}" sends the view "${e.view}", which this template does not declare.`);
1791
+ steps.push({
1792
+ label: `digests.${e.token}`,
1793
+ door: "subscription_declare",
1794
+ args: { p_organization_id: "${org}", p_table_id: tableRef(view.table), p_spec: digestSpec(e, ref(`views.${e.view}`)) },
1795
+ save: { [`digests.${e.token}`]: [] },
1796
+ made: [{ kind: "rule", ref: `digests.${e.token}`, title: e.name, table: `tables.${view.table}` }]
1797
+ });
1798
+ break;
1799
+ }
1800
+ case "stage_rules":
1801
+ steps.push({
1802
+ label: `stage_rules.${e.token}`,
1803
+ door: "pipeline_declare",
1804
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.table), p_spec: stageRulesSpec(e) }
1805
+ });
1806
+ break;
1807
+ case "document":
1808
+ steps.push({
1809
+ label: `documents.${e.token}`,
1810
+ door: "doc_template_save",
1811
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.table), p_name: e.name, p_body: documentBody(e, fieldRefs(e.table), spec.business.name), p_template_id: null },
1812
+ save: { [`documents.${e.token}`]: [] },
1813
+ made: [{ kind: "document", ref: `documents.${e.token}`, title: e.name, table: `tables.${e.table}` }]
1814
+ });
1815
+ break;
1816
+ case "row_action":
1817
+ actionsByTable.set(e.table, [...actionsByTable.get(e.table) ?? [], e]);
1818
+ break;
1819
+ case "notification": {
1820
+ const n = notificationParts(e, stageFieldOf(tables, e.when.table, e.when.stage));
1821
+ steps.push({
1822
+ label: `notifications.${e.token}.view`,
1823
+ door: "view_declare",
1824
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.when.table), p_spec: n.view },
1825
+ save: { [`notifications.${e.token}.view`]: [] },
1826
+ made: [{ kind: "view", ref: `notifications.${e.token}.view`, title: e.name, table: `tables.${e.when.table}` }]
1827
+ });
1828
+ steps.push({
1829
+ label: `notifications.${e.token}`,
1830
+ door: "subscription_declare",
1831
+ args: { p_organization_id: "${org}", p_table_id: tableRef(e.when.table), p_spec: { ...n.subscription, saved_view_id: ref(`notifications.${e.token}.view`) } },
1832
+ save: { [`notifications.${e.token}`]: [] },
1833
+ made: [{ kind: "rule", ref: `notifications.${e.token}`, title: e.name, table: `tables.${e.when.table}` }]
1834
+ });
1835
+ break;
1836
+ }
1837
+ case "portal":
1838
+ steps.push({
1839
+ label: `portals.${e.token}`,
1840
+ door: "portal_declare",
1841
+ args: portalArgs("${org}", e, tableTokens),
1842
+ save: { [`portals.${e.token}`]: [] },
1843
+ made: [{ kind: "portal", ref: `portals.${e.token}`, title: e.title, table: `tables.${e.clientTable}` }]
1844
+ });
1845
+ break;
1846
+ case "checklist":
1847
+ for (const t of [e.aboutTable, ...e.trigger && e.trigger.kind !== "manual" ? [e.trigger.table] : []]) tableRef(t);
1848
+ for (const st of e.steps) {
1849
+ const r = st.requires;
1850
+ if (r?.kind === "form" && !formRefs[r.form]) throw new Error(`The checklist "${e.name}" asks for the form "${r.form}", which this template does not declare.`);
1851
+ if (r?.kind === "document" && !documentRefs[r.document]) throw new Error(`The checklist "${e.name}" asks for the document "${r.document}", which this template does not declare.`);
1852
+ }
1853
+ steps.push({
1854
+ label: `checklists.${e.token}`,
1855
+ door: "checklist_declare",
1856
+ args: { p_organization_id: "${org}", p_spec: checklistSpec(e, tableTokens, formRefs, documentRefs), p_template_id: null },
1857
+ save: { [`checklists.${e.token}`]: ["template_id"] },
1858
+ made: [{ kind: "record", ref: `checklists.${e.token}`, title: e.name }]
1859
+ });
1860
+ break;
1861
+ case "automation":
1862
+ throw new Error(automationHeld(e));
1863
+ default:
1864
+ throw new Error(`The install plan has no door for a ${e.kind} yet ("${e.token ?? "?"}"), so this template cannot be declared until it does.`);
1865
+ }
1866
+ }
1867
+ for (const [token, actions] of actionsByTable) {
1868
+ steps.push({
1869
+ label: `row_actions.${token}`,
1870
+ door: "action_declare",
1871
+ args: { p_organization_id: "${org}", p_table_id: tableRef(token), p_actions: rowActionList(actions, fieldRefs(token)) }
1872
+ });
1873
+ }
1874
+ const host = compileHostExtras(spec);
1875
+ const agent = spec.agent;
1876
+ return {
1877
+ planVersion: INSTALL_PLAN_VERSION,
1878
+ timezone: spec.business.timezone || "UTC",
1879
+ steps,
1880
+ ...agent?.platformAgent ? {
1881
+ agent: {
1882
+ platformAgent: agent.platformAgent,
1883
+ name: agent.name,
1884
+ bindings: (agent.variables ?? []).map((v) => {
1885
+ const binding = host.agentBindings.get(v.name);
1886
+ return { variable: v.name, tableToken: v.table, describes: v.describes, ...binding ? { binding } : {} };
1887
+ })
1888
+ }
1889
+ } : {},
1890
+ ...bound.size ? { ids: Object.fromEntries([...bound].map(([token, b]) => [`ref:tables.${token}`, b.tableId])) } : {},
1891
+ ...host.extras
1892
+ };
1893
+ }
1894
+
1895
+ // src/choice.ts
1896
+ import { isUuidShape } from "@ai-matrx/kit/uuid";
1897
+ function choiceSlug(word) {
1898
+ const slug = word.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 55);
1899
+ return slug === "" ? "choice" : slug;
1900
+ }
1901
+
1902
+ // src/memory/world.ts
1903
+ var MEMORY_KERNEL = {
1904
+ table: "11111111-0000-4000-8000-000000000001",
1905
+ field: "11111111-0000-4000-8000-000000000002",
1906
+ person: "11111111-0000-4000-8000-000000000005",
1907
+ file: "11111111-0000-4000-8000-000000000006",
1908
+ rule: "11111111-0000-4000-8000-000000000003"
1909
+ };
1910
+ function stableId(name) {
1911
+ const lanes = [2166136261, 16777619, 2654435769, 2246822507];
1912
+ for (let i = 0; i < name.length; i += 1) {
1913
+ const c = name.charCodeAt(i);
1914
+ for (let l = 0; l < 4; l += 1) lanes[l] = Math.imul((lanes[l] ^ c) >>> 0, 16777619 + l * 2) >>> 0;
1915
+ }
1916
+ const hex = lanes.map((n) => n.toString(16).padStart(8, "0")).join("");
1917
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${"89ab"[parseInt(hex[16], 16) % 4]}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
1918
+ }
1919
+ var COMPUTED2 = /* @__PURE__ */ new Set(["lookup", "rollup", "formula"]);
1920
+ function storedField(spec, tableId, tableToken, sort, idOf) {
1921
+ const key = String(spec["key"]);
1922
+ const parity = String(spec["parityType"] ?? spec["type"] ?? "text");
1923
+ const base = {
1924
+ key,
1925
+ label: spec["label"] ?? key,
1926
+ sort,
1927
+ dated: Boolean(spec["dated"]),
1928
+ multi: Boolean(spec["multi"]),
1929
+ required: Boolean(spec["required"]),
1930
+ rules: Array.isArray(spec["rules"]) ? spec["rules"] : [],
1931
+ config: {},
1932
+ source: COMPUTED2.has(parity) ? "formula" : "manual",
1933
+ depends_on: [],
1934
+ sensitivity: spec["sensitivity"] ?? "internal",
1935
+ context_policy: spec["contextPolicy"] ?? spec["context_policy"] ?? "include",
1936
+ applies_to_types: [],
1937
+ entity_definition_id: tableId,
1938
+ parity_type: parity
1939
+ };
1940
+ const unit = spec["unit"];
1941
+ if (typeof unit === "string" && unit) base["unit"] = unit;
1942
+ const display = spec["displayFormat"] ?? spec["display_format"];
1943
+ if (display && typeof display === "object") base["display_format"] = display;
1944
+ const config = base["config"];
1945
+ switch (parity) {
1946
+ case "text":
1947
+ base["type"] = "text";
1948
+ break;
1949
+ case "long_text":
1950
+ base["type"] = "text";
1951
+ base["format"] = "long";
1952
+ config["multiline"] = true;
1953
+ break;
1954
+ case "email":
1955
+ case "phone":
1956
+ case "url":
1957
+ case "signature":
1958
+ base["type"] = "text";
1959
+ base["format"] = parity;
1960
+ break;
1961
+ case "number":
1962
+ case "integer":
1963
+ case "decimal":
1964
+ base["type"] = "range";
1965
+ break;
1966
+ case "currency":
1967
+ base["type"] = "range";
1968
+ base["format"] = "currency";
1969
+ if (!base["unit"]) base["unit"] = "USD";
1970
+ break;
1971
+ case "percent":
1972
+ base["type"] = "range";
1973
+ base["format"] = "percent";
1974
+ break;
1975
+ case "datetime": {
1976
+ base["type"] = "range";
1977
+ const timed = spec["kind"] === "datetime" || spec["format"] === "datetime";
1978
+ config["kind"] = timed ? "datetime" : "date";
1979
+ if (timed) base["format"] = "datetime";
1980
+ break;
1981
+ }
1982
+ case "checkbox":
1983
+ base["type"] = "boolean";
1984
+ break;
1985
+ case "select":
1986
+ case "multi_select":
1987
+ base["type"] = "list";
1988
+ config["options_table_id"] = idOf(`options.${tableToken}.${key}`);
1989
+ if (parity === "multi_select") base["multi"] = true;
1990
+ break;
1991
+ case "relation":
1992
+ base["type"] = "relation";
1993
+ base["relation_target"] = spec["relation_target"] ?? (spec["relationTarget"] ? idOf(`tables.${String(spec["relationTarget"])}`) : null);
1994
+ if (spec["relation_max"] ?? spec["relationMax"]) base["relation_max"] = spec["relation_max"] ?? spec["relationMax"];
1995
+ break;
1996
+ case "member":
1997
+ base["type"] = "relation";
1998
+ base["relation_target"] = MEMORY_KERNEL.person;
1999
+ break;
2000
+ case "attachment":
2001
+ base["type"] = "relation";
2002
+ base["relation_target"] = MEMORY_KERNEL.file;
2003
+ break;
2004
+ case "lookup":
2005
+ base["type"] = "formula";
2006
+ config["via"] = spec["via"];
2007
+ config["pick"] = spec["pick"];
2008
+ break;
2009
+ case "rollup":
2010
+ base["type"] = "formula";
2011
+ config["via"] = spec["via"];
2012
+ config["agg"] = spec["agg"];
2013
+ config["of"] = spec["of"] ?? spec["pick"];
2014
+ if (spec["filter"]) config["filter"] = spec["filter"];
2015
+ break;
2016
+ case "formula":
2017
+ base["type"] = "formula";
2018
+ config["formula_text"] = spec["formula_text"] ?? spec["formula"];
2019
+ break;
2020
+ default:
2021
+ base["type"] = "text";
2022
+ }
2023
+ if (parity !== "datetime" && typeof spec["format"] === "string" && !base["format"] && parity !== "lookup" && parity !== "rollup") {
2024
+ base["format"] = spec["format"];
2025
+ }
2026
+ return { id: idOf(`fields.${tableToken}.${key}`), table_id: tableId, data: base };
2027
+ }
2028
+ var PLACEHOLDER = /\$\{(org|ref:[^}]+|new:[^}]+|date:[^}]+)\}/g;
2029
+ function templateWorld(spec, options = {}) {
2030
+ const plan = compileInstallPlan(spec);
2031
+ const today = options.today ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
2032
+ const tz = plan.timezone || spec.business?.timezone || "UTC";
2033
+ const seed = `template:${spec.id ?? spec.business?.name ?? "preview"}`;
2034
+ const idOf = (name) => {
2035
+ if (name === "kernel.person") return MEMORY_KERNEL.person;
2036
+ if (name === "kernel.file") return MEMORY_KERNEL.file;
2037
+ return plan.ids?.[`ref:${name}`] ?? stableId(`${seed}:${name}`);
2038
+ };
2039
+ const org = stableId(`${seed}:organization`);
2040
+ const resolveString = (s) => {
2041
+ const whole = /^\$\{(org|ref:[^}]+|new:[^}]+|date:[^}]+)\}$/.exec(s);
2042
+ const one = (tok) => {
2043
+ if (tok === "org") return org;
2044
+ if (tok.startsWith("date:")) return resolveDateToken(tok.slice(5), today, tz) ?? tok.slice(5);
2045
+ return idOf(tok.slice(4));
2046
+ };
2047
+ if (whole) return one(whole[1]);
2048
+ return s.replace(PLACEHOLDER, (_m, tok) => one(tok));
2049
+ };
2050
+ const resolve = (v) => {
2051
+ if (typeof v === "string") return resolveString(v);
2052
+ if (Array.isArray(v)) return v.map(resolve);
2053
+ if (v && typeof v === "object") return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolve(x)]));
2054
+ return v;
2055
+ };
2056
+ const world = {
2057
+ organization_id: org,
2058
+ user_id: stableId(`${seed}:viewer`),
2059
+ timezone: tz,
2060
+ today,
2061
+ businessName: spec.business?.name ?? "",
2062
+ tables: [],
2063
+ tableById: /* @__PURE__ */ new Map(),
2064
+ views: [],
2065
+ forms: [],
2066
+ dashboards: [],
2067
+ recordTable: /* @__PURE__ */ new Map(),
2068
+ stageField: /* @__PURE__ */ new Map()
2069
+ };
2070
+ const tokenOfTable = /* @__PURE__ */ new Map();
2071
+ const addField = (table, raw) => {
2072
+ const key = String(raw["key"]);
2073
+ const existing = table.fields.findIndex((f) => f.data["key"] === key);
2074
+ const field = storedField(raw, table.id, table.token, (existing >= 0 ? existing : table.fields.length) * 10 + 10, idOf);
2075
+ if (existing >= 0) table.fields[existing] = field;
2076
+ else table.fields.push(field);
2077
+ const choices = raw["choices"] ?? raw["options"];
2078
+ if (Array.isArray(choices)) {
2079
+ const colors = /* @__PURE__ */ new Map();
2080
+ const display = raw["displayFormat"] ?? raw["display_format"];
2081
+ for (const c of display?.options?.choices ?? []) colors.set(c.value, c.color);
2082
+ table.options.set(
2083
+ key,
2084
+ choices.map((label) => ({
2085
+ id: idOf(`options.${table.token}.${key}.${String(label)}`),
2086
+ key: choiceSlug(String(label)),
2087
+ label: String(label),
2088
+ color: colors.get(String(label)) ?? null
2089
+ }))
2090
+ );
2091
+ }
2092
+ table.document["fields"].push(key);
2093
+ };
2094
+ const writeRow = (table, id, data) => {
2095
+ const doc = {};
2096
+ for (const [k, v] of Object.entries(data)) if (!k.startsWith("_")) doc[k] = v;
2097
+ for (const [key, opts] of table.options) {
2098
+ const v = doc[key];
2099
+ const toKey = (x) => opts.find((o) => o.label === x || o.key === x || o.id === x)?.key ?? x;
2100
+ if (Array.isArray(v)) doc[key] = v.map(toKey);
2101
+ else if (v !== void 0 && v !== null) doc[key] = toKey(v);
2102
+ }
2103
+ const before = table.rows.get(id);
2104
+ if (!before) table.order.push(id);
2105
+ table.rows.set(id, { ...before ?? {}, ...doc });
2106
+ world.recordTable.set(id, table);
2107
+ };
2108
+ for (const step of plan.steps) {
2109
+ const args = resolve(step.args);
2110
+ const tableId = typeof args["p_table_id"] === "string" ? args["p_table_id"] : null;
2111
+ const table = tableId ? world.tableById.get(tableId) : void 0;
2112
+ switch (step.door) {
2113
+ case "table_from_example":
2114
+ case "table_declare": {
2115
+ const example = args["p_example"] ?? { tables: [args["p_spec"]] };
2116
+ for (const t of example.tables ?? []) {
2117
+ const token = String(t["token"]);
2118
+ const id = idOf(`tables.${token}`);
2119
+ const made = {
2120
+ id,
2121
+ token,
2122
+ document: {
2123
+ name: t["name"],
2124
+ slug: token,
2125
+ label_singular: t["labelSingular"] ?? null,
2126
+ label_plural: t["labelPlural"] ?? null,
2127
+ description: t["describes"] ?? null,
2128
+ title_field: t["titleField"] ?? null,
2129
+ type: t["type"] ?? "entity",
2130
+ display: t["display"] ?? "grid",
2131
+ icon: t["icon"] ?? null,
2132
+ fields: []
2133
+ },
2134
+ fields: [],
2135
+ options: /* @__PURE__ */ new Map(),
2136
+ rows: /* @__PURE__ */ new Map(),
2137
+ order: []
2138
+ };
2139
+ world.tables.push(made);
2140
+ world.tableById.set(id, made);
2141
+ tokenOfTable.set(id, token);
2142
+ for (const f of t["fields"] ?? []) addField(made, f);
2143
+ }
2144
+ break;
2145
+ }
2146
+ case "field_declare":
2147
+ if (table) addField(table, args["p_spec"]);
2148
+ break;
2149
+ case "record_write":
2150
+ if (table) writeRow(table, idOf(step.save ? Object.keys(step.save)[0] : `${step.label}`), args["p_data"]);
2151
+ break;
2152
+ case "record_write_many":
2153
+ if (table) {
2154
+ const rows = args["p_rows"] ?? [];
2155
+ const ids = args["p_ids"] ?? [];
2156
+ rows.forEach((r, i) => writeRow(table, ids[i] ?? idOf(`${step.label}.${i}`), r));
2157
+ }
2158
+ break;
2159
+ case "record_change_many":
2160
+ if (table) {
2161
+ for (const change of args["p_changes"] ?? []) {
2162
+ if (change["op"] === "update" && typeof change["record_id"] === "string") writeRow(table, change["record_id"], change["patch"]);
2163
+ }
2164
+ }
2165
+ break;
2166
+ case "view_declare": {
2167
+ if (!tableId) break;
2168
+ const s = args["p_spec"];
2169
+ const token = step.label.replace(/^views\./, "");
2170
+ world.views.push({
2171
+ view_id: idOf(`views.${token}`),
2172
+ token,
2173
+ table_id: tableId,
2174
+ name: String(s["name"] ?? token),
2175
+ definition: { table_id: tableId, ...s["definition"] ?? {} },
2176
+ filters: s["filters"] ?? {}
2177
+ });
2178
+ break;
2179
+ }
2180
+ case "form_declare":
2181
+ case "booking_declare": {
2182
+ if (!tableId) break;
2183
+ const save = step.save ? Object.keys(step.save)[0] : step.label;
2184
+ world.forms.push({
2185
+ form_id: idOf(save),
2186
+ token: step.label.replace(/^(forms|bookings|extras)\./, ""),
2187
+ table_id: tableId,
2188
+ title: String(args["p_title"] ?? ""),
2189
+ questions: args["p_questions"] ?? [],
2190
+ presentation: args["p_presentation"] ?? {},
2191
+ booking: step.door === "booking_declare" ? args["p_availability"] ?? {} : null
2192
+ });
2193
+ break;
2194
+ }
2195
+ case "dashboard_declare": {
2196
+ if (!tableId) break;
2197
+ const save = step.save ? Object.keys(step.save)[0] : step.label;
2198
+ world.dashboards.push({
2199
+ dashboard_id: idOf(save),
2200
+ token: step.label.replace(/^(dashboards|extras)\./, ""),
2201
+ table_id: tableId,
2202
+ name: String(args["p_name"] ?? ""),
2203
+ blocks: args["p_blocks"] ?? []
2204
+ });
2205
+ break;
2206
+ }
2207
+ case "pipeline_declare": {
2208
+ const stage = args["p_spec"]?.["stage_field"]?.["key"];
2209
+ if (tableId && typeof stage === "string") world.stageField.set(tableId, stage);
2210
+ break;
2211
+ }
2212
+ default:
2213
+ break;
2214
+ }
2215
+ }
2216
+ return world;
2217
+ }
2218
+
2219
+ // src/memory/doors.ts
2220
+ var PREVIEW_REFUSAL = {
2221
+ code: "42501",
2222
+ message: "This is a preview of a template. Nothing here is saved \u2014 use the template to make it yours.",
2223
+ details: null,
2224
+ hint: null
2225
+ };
2226
+ var WRITE_DOOR = /(^|_)(write|writes|declare|delete|update|upsert|archive|restore|set|move|save|submit|insert|merge|retype|undo|retire|assign|claim|clear|snooze|unsnooze|publish|invite|revoke|issue|pin|duplicate|designate|bind|unbind|change|start|complete|decide|request|hold|release|expire|forget|begin|finish|rows|take|nudge|import|mute|sign|render|instantiate|ensure)(_|$)/;
2227
+ function ok(data) {
2228
+ return { data, error: null };
2229
+ }
2230
+ function refuse(message, code = "PGRST202") {
2231
+ return { data: null, error: { code, message, details: null, hint: null } };
2232
+ }
2233
+ function stamp(world) {
2234
+ const at = `${world.today}T09:00:00+00:00`;
2235
+ return { created_at: at, updated_at: at, created_by: world.user_id, updated_by: world.user_id };
2236
+ }
2237
+ function readDocument(world, table, id) {
2238
+ const stored = table.rows.get(id) ?? {};
2239
+ const doc = { ...stored };
2240
+ const choices = {};
2241
+ for (const [key, opts] of table.options) {
2242
+ const v = stored[key];
2243
+ if (v === void 0 || v === null) continue;
2244
+ const one = (k) => opts.find((o) => o.key === k);
2245
+ if (Array.isArray(v)) {
2246
+ const picked = v.map(one).filter((o) => o !== void 0);
2247
+ doc[key] = picked.map((o) => o.label);
2248
+ choices[key] = picked.map((o) => ({ key: o.key, label: o.label, id: o.id, retired: false, reason: null }));
2249
+ } else {
2250
+ const o = one(v);
2251
+ if (o) {
2252
+ doc[key] = o.label;
2253
+ choices[key] = { key: o.key, label: o.label, id: o.id, retired: false, reason: null };
2254
+ }
2255
+ }
2256
+ }
2257
+ if (Object.keys(choices).length) doc["_choices"] = choices;
2258
+ for (const f of table.fields) {
2259
+ if (f.data["type"] !== "formula") continue;
2260
+ const key = String(f.data["key"]);
2261
+ const config = f.data["config"] ?? {};
2262
+ const parity = f.data["parity_type"];
2263
+ if (parity === "lookup") doc[key] = lookup(world, table, stored, config);
2264
+ else if (parity === "rollup") doc[key] = rollup(world, table, id, config);
2265
+ }
2266
+ return doc;
2267
+ }
2268
+ function lookup(world, table, stored, config) {
2269
+ const via = String(config["via"] ?? "");
2270
+ const pick = String(config["pick"] ?? "");
2271
+ const target = stored[via];
2272
+ const first = Array.isArray(target) ? target[0] : target;
2273
+ if (typeof first !== "string") return null;
2274
+ const far = world.recordTable.get(first);
2275
+ if (!far) return null;
2276
+ const value = readDocument(world, far, first)[pick];
2277
+ void table;
2278
+ return value ?? null;
2279
+ }
2280
+ function rollup(world, table, id, config) {
2281
+ const via = String(config["via"] ?? "");
2282
+ const [maybeTable, maybeField] = via.includes(".") ? via.split(".") : [null, via];
2283
+ const of = config["of"] ? String(config["of"]) : null;
2284
+ const agg = String(config["agg"] ?? "count");
2285
+ const filter = config["filter"] ?? null;
2286
+ const values = [];
2287
+ let count = 0;
2288
+ for (const other of world.tables) {
2289
+ if (maybeTable && other.token !== maybeTable) continue;
2290
+ const rel = other.fields.find((f) => f.data["key"] === maybeField && f.data["type"] === "relation" && f.data["relation_target"] === table.id);
2291
+ if (!rel) continue;
2292
+ for (const rid of other.order) {
2293
+ const row = other.rows.get(rid);
2294
+ const link = row[maybeField];
2295
+ const linked = Array.isArray(link) ? link.includes(id) : link === id;
2296
+ if (!linked) continue;
2297
+ if (filter && !admits(world, other, rid, filter)) continue;
2298
+ count += 1;
2299
+ if (of) values.push(readDocument(world, other, rid)[of]);
2300
+ }
2301
+ }
2302
+ const nums = values.filter((v) => typeof v === "number");
2303
+ switch (agg) {
2304
+ case "count":
2305
+ return count;
2306
+ case "sum":
2307
+ return nums.reduce((a, b) => a + b, 0);
2308
+ case "avg":
2309
+ return nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : null;
2310
+ case "min":
2311
+ return nums.length ? Math.min(...nums) : values.filter((v) => typeof v === "string").sort()[0] ?? null;
2312
+ case "max":
2313
+ return nums.length ? Math.max(...nums) : values.filter((v) => typeof v === "string").sort().at(-1) ?? null;
2314
+ default:
2315
+ return count;
2316
+ }
2317
+ }
2318
+ function admits(world, table, id, filter) {
2319
+ if (!filter || typeof filter !== "object") return true;
2320
+ const doc = readDocument(world, table, id);
2321
+ const stored = table.rows.get(id) ?? {};
2322
+ const f = filter;
2323
+ if (typeof f["op"] === "string") return rule(table, doc, stored, f) !== false;
2324
+ for (const [key, want] of Object.entries(f)) {
2325
+ const got = doc[key];
2326
+ const raw = stored[key];
2327
+ if (want === null) {
2328
+ if (!(got === null || got === void 0 || got === "")) return false;
2329
+ } else if (typeof want === "object" && !Array.isArray(want)) {
2330
+ const w = want;
2331
+ if (typeof got !== "string" && typeof got !== "number") return false;
2332
+ const g = String(got);
2333
+ const at = new Date(g.length === 10 ? `${g}T00:00:00Z` : g).getTime();
2334
+ if (w.to && at >= new Date(w.to).getTime()) return false;
2335
+ if (w.from && at < new Date(w.from).getTime()) return false;
2336
+ } else {
2337
+ const list = Array.isArray(got) ? got : [got];
2338
+ const rawList = Array.isArray(raw) ? raw : [raw];
2339
+ if (!list.some((x) => x === want) && !rawList.some((x) => x === want)) return false;
2340
+ }
2341
+ }
2342
+ return true;
2343
+ }
2344
+ function rule(table, doc, stored, node) {
2345
+ if ("const" in node) return node["const"];
2346
+ if (typeof node["field"] === "string") {
2347
+ const field = table.fields.find((f) => f.id === node["field"] || f.data["key"] === node["field"]);
2348
+ return field ? doc[String(field.data["key"])] ?? stored[String(field.data["key"])] ?? null : null;
2349
+ }
2350
+ const args = (node["args"] ?? []).map((a) => rule(table, doc, stored, a));
2351
+ switch (node["op"]) {
2352
+ case "and":
2353
+ case "all":
2354
+ return args.every((a) => a !== false);
2355
+ case "or":
2356
+ case "any":
2357
+ return args.some((a) => a !== false && a !== null);
2358
+ case "not":
2359
+ return args[0] === false;
2360
+ case "eq":
2361
+ return Array.isArray(args[0]) ? args[0].includes(args[1]) : args[0] === args[1];
2362
+ case "neq":
2363
+ return args[0] !== args[1];
2364
+ case "is_empty":
2365
+ return args[0] === null || args[0] === void 0 || args[0] === "";
2366
+ case "not_empty":
2367
+ return !(args[0] === null || args[0] === void 0 || args[0] === "");
2368
+ default:
2369
+ return true;
2370
+ }
2371
+ }
2372
+ function sortRows(world, table, ids, sort) {
2373
+ const sorts = Array.isArray(sort) ? sort : [];
2374
+ if (!sorts.length) return ids;
2375
+ const docs = new Map(ids.map((id) => [id, readDocument(world, table, id)]));
2376
+ return [...ids].sort((a, b) => {
2377
+ for (const s of sorts) {
2378
+ const key = s.field ?? "";
2379
+ const x = docs.get(a)[key];
2380
+ const y = docs.get(b)[key];
2381
+ if (x === y) continue;
2382
+ if (x === void 0 || x === null) return 1;
2383
+ if (y === void 0 || y === null) return -1;
2384
+ const c = typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y));
2385
+ if (c !== 0) return s.direction === "desc" ? -c : c;
2386
+ }
2387
+ return 0;
2388
+ });
2389
+ }
2390
+ function matching(world, table, args) {
2391
+ const search = typeof args["p_search"] === "string" ? args["p_search"].trim().toLowerCase() : "";
2392
+ let ids = table.order.filter((id) => admits(world, table, id, args["p_filter"]));
2393
+ if (search) ids = ids.filter((id) => JSON.stringify(readDocument(world, table, id)).toLowerCase().includes(search));
2394
+ return sortRows(world, table, ids, args["p_sort"]);
2395
+ }
2396
+ var VIEWER = "viewer";
2397
+ function memoryDataSource(world) {
2398
+ const looks = /* @__PURE__ */ new Map();
2399
+ const tableRow = (t) => ({ id: t.id, document: { ...t.document }, level: VIEWER });
2400
+ const row = (t, id) => ({ id, document: readDocument(world, t, id), level: VIEWER });
2401
+ const tableOf = (args) => world.tableById.get(String(args["p_table_id"] ?? ""));
2402
+ const fieldById = (id) => {
2403
+ for (const t of world.tables) for (const f of t.fields) if (f.id === id) return { t, f };
2404
+ return null;
2405
+ };
2406
+ const nameOf = (id) => {
2407
+ const t = world.recordTable.get(id);
2408
+ if (!t) return null;
2409
+ const title = String(t.document["title_field"] ?? "");
2410
+ const v = readDocument(world, t, id)[title];
2411
+ return typeof v === "string" ? v : v === void 0 || v === null ? null : String(v);
2412
+ };
2413
+ const doors = {
2414
+ table_kernel_id: () => ok(MEMORY_KERNEL.table),
2415
+ field_kernel_id: () => ok(MEMORY_KERNEL.field),
2416
+ person_kernel_id: () => ok(MEMORY_KERNEL.person),
2417
+ file_kernel_id: () => ok(MEMORY_KERNEL.file),
2418
+ rule_kernel_id: () => ok(MEMORY_KERNEL.rule),
2419
+ store_is_open: () => ok(true),
2420
+ read_records: (args) => {
2421
+ const limit = Number(args["p_limit"] ?? 50);
2422
+ const offset = Number(args["p_offset"] ?? 0);
2423
+ if (args["p_table_id"] === MEMORY_KERNEL.table) return ok(world.tables.slice(offset, offset + limit).map(tableRow));
2424
+ const t = tableOf(args);
2425
+ if (!t) return ok([]);
2426
+ return ok(t.order.slice(offset, offset + limit).map((id) => row(t, id)));
2427
+ },
2428
+ read_records_by_ids: (args) => {
2429
+ const ids = args["p_record_ids"] ?? [];
2430
+ if (args["p_table_id"] === MEMORY_KERNEL.table) return ok(world.tables.filter((t2) => ids.includes(t2.id)).map(tableRow));
2431
+ const t = tableOf(args);
2432
+ if (!t) return ok([]);
2433
+ return ok(ids.filter((id) => t.rows.has(id)).map((id) => row(t, id)));
2434
+ },
2435
+ read_records_matching: (args) => {
2436
+ const t = tableOf(args);
2437
+ if (!t) return ok([]);
2438
+ const limit = Number(args["p_limit"] ?? 50);
2439
+ const offset = Number(args["p_offset"] ?? 0);
2440
+ return ok(matching(world, t, args).slice(offset, offset + limit).map((id) => row(t, id)));
2441
+ },
2442
+ read_records_page: (args) => {
2443
+ const t = tableOf(args);
2444
+ const limit = Number(args["p_limit"] ?? 50);
2445
+ const offset = Number(args["p_offset"] ?? 0);
2446
+ if (!t) return ok({ rows: [], total: 0, limit, offset, sort_ignored: [] });
2447
+ const ids = matching(world, t, args);
2448
+ return ok({ rows: ids.slice(offset, offset + limit).map((id) => row(t, id)), total: ids.length, limit, offset, sort_ignored: [] });
2449
+ },
2450
+ read_record: (args) => {
2451
+ const id = String(args["p_record_id"] ?? "");
2452
+ const t = world.recordTable.get(id);
2453
+ if (!t) return refuse("That record is not in this template.", "P0002");
2454
+ return ok(readDocument(world, t, id));
2455
+ },
2456
+ record_headers: (args) => ok(
2457
+ (args["p_ids"] ?? []).filter((id) => world.recordTable.has(id)).map((id) => ({ id, mine: false, version: 1, table_id: world.recordTable.get(id).id, deleted_at: null, ...stamp(world) }))
2458
+ ),
2459
+ applicable_fields: (args) => {
2460
+ const t = tableOf(args);
2461
+ if (!t) return ok([]);
2462
+ return ok(
2463
+ t.fields.map((f) => ({
2464
+ id: f.id,
2465
+ data: f.data,
2466
+ version: 1,
2467
+ metadata: {},
2468
+ shown_to: null,
2469
+ table_id: MEMORY_KERNEL.field,
2470
+ data_class: "field",
2471
+ deleted_at: null,
2472
+ visibility: "internal",
2473
+ custom_fields: {},
2474
+ organization_id: world.organization_id,
2475
+ ...stamp(world)
2476
+ }))
2477
+ );
2478
+ },
2479
+ field_options: (args) => {
2480
+ const hit = fieldById(args["p_field_id"]);
2481
+ if (!hit) return ok([]);
2482
+ const opts = hit.t.options.get(String(hit.f.data["key"])) ?? [];
2483
+ return ok(
2484
+ opts.map((o, i) => ({
2485
+ id: o.id,
2486
+ organization_id: world.organization_id,
2487
+ table_id: hit.f.data["config"]["options_table_id"] ?? null,
2488
+ data_class: "record",
2489
+ data: { name: o.label, sort: (i + 1) * 10, ...o.color ? { color: o.color } : {} },
2490
+ version: 1,
2491
+ metadata: { option_key: o.key },
2492
+ custom_fields: {},
2493
+ visibility: "internal",
2494
+ deleted_at: null,
2495
+ ...stamp(world)
2496
+ }))
2497
+ );
2498
+ },
2499
+ my_levels: (args) => ok((args["p_ids"] ?? []).map((id) => ({ id, level: VIEWER }))),
2500
+ views: (args) => ok(
2501
+ world.views.filter((v) => !args["p_table_id"] || v.table_id === args["p_table_id"]).map((v) => ({ view_id: v.view_id, name: v.name, table_id: v.table_id, filters: v.filters, definition: v.definition, created_at: `${world.today}T09:00:00Z` }))
2502
+ ),
2503
+ view_look_read: (args) => {
2504
+ const out = {};
2505
+ for (const [key, look] of looks) if (key.startsWith(`${String(args["p_table_id"])}:`)) out[key.split(":")[1]] = look;
2506
+ return ok(out);
2507
+ },
2508
+ view_look_set: (args) => {
2509
+ const key = `${String(args["p_table_id"])}:${String(args["p_view_id"])}`;
2510
+ const look = args["p_look"] ?? null;
2511
+ if (look) looks.set(key, { look, updated_at: (/* @__PURE__ */ new Date()).toISOString() });
2512
+ else looks.delete(key);
2513
+ return ok(look);
2514
+ },
2515
+ grid_layout: (args) => ok({
2516
+ layout: { mode: "auto", wrap: false, row_height: "normal", fit_max_columns: 8, freeze_first_column: false },
2517
+ source: { mode: "platform", wrap: "platform", row_height: "platform", fit_max_columns: "platform", freeze_first_column: "platform" },
2518
+ refused: [],
2519
+ view_id: args["p_view_id"] ?? null
2520
+ }),
2521
+ table_decorations: () => ok({ rows: {}, cells: {}, rules: [], stale: [], colors: ["slate", "green", "amber", "red", "blue", "violet", "teal"], columns: {}, version: 1, rule_ops: [] }),
2522
+ row_actions: () => ok({ stale: [], actions: [] }),
2523
+ table_stage_field: (args) => ok(world.stageField.get(String(args["p_table_id"])) ?? null),
2524
+ pipeline_read: (args) => {
2525
+ const t = tableOf(args);
2526
+ const stage = t ? world.stageField.get(t.id) : void 0;
2527
+ const field = stage ? t.fields.find((f) => f.data["key"] === stage) : void 0;
2528
+ if (!t || !stage || !field) return ok({ is_pipeline: false, why: "This table has no stage column." });
2529
+ const stages = (t.options.get(stage) ?? []).map((o) => ({ key: o.key, label: o.label, retired: false }));
2530
+ return ok({ is_pipeline: true, table_id: t.id, stage_field: stage, field_id: field.id, stage_label: field.data["label"], stages, rules: [] });
2531
+ },
2532
+ pipeline_board: (args) => {
2533
+ const t = tableOf(args);
2534
+ const stage = t ? world.stageField.get(t.id) : void 0;
2535
+ if (!t || !stage) return ok([]);
2536
+ const measure = typeof args["p_measure"] === "string" ? args["p_measure"] : null;
2537
+ const ids = t.order.filter((id) => admits(world, t, id, args["p_filter"]));
2538
+ return ok(
2539
+ (t.options.get(stage) ?? []).map((o, i) => {
2540
+ const inIt = ids.filter((id) => t.rows.get(id)[stage] === o.key);
2541
+ const total = measure ? inIt.reduce((sum, id) => sum + (typeof t.rows.get(id)[measure] === "number" ? t.rows.get(id)[measure] : 0), 0) : null;
2542
+ return { stage_key: o.key, stage_label: o.label, stage_position: i + 1, cards: inIt.length, total, wip_limit: null, over_limit: false };
2543
+ })
2544
+ );
2545
+ },
2546
+ relation_words_many: (args) => ok((args["p_record_ids"] ?? []).map((id) => ({ record_id: id, words: nameOf(id), archived: false }))),
2547
+ reverse_columns: (args) => {
2548
+ const target = String(args["p_table_id"] ?? "");
2549
+ const out = [];
2550
+ for (const t of world.tables) {
2551
+ for (const f of t.fields) {
2552
+ if (f.data["type"] !== "relation" || f.data["relation_target"] !== target) continue;
2553
+ out.push({
2554
+ key: `${t.token}__${String(f.data["key"])}`,
2555
+ label: String(t.document["name"] ?? t.token),
2556
+ source_field_id: f.id,
2557
+ source_field_key: f.data["key"],
2558
+ source_field_label: f.data["label"],
2559
+ source_table_id: t.id,
2560
+ source_table_name: t.document["name"],
2561
+ cardinality: "many",
2562
+ read_only: true
2563
+ });
2564
+ }
2565
+ }
2566
+ return ok(out);
2567
+ },
2568
+ reverse_links_many: (args) => {
2569
+ const hit = fieldById(args["p_field_id"]);
2570
+ return ok(
2571
+ (args["p_record_ids"] ?? []).map((rid) => {
2572
+ if (!hit) return { record_id: rid, total: 0, links: [] };
2573
+ const key = String(hit.f.data["key"]);
2574
+ const links = hit.t.order.filter((id) => {
2575
+ const v = hit.t.rows.get(id)[key];
2576
+ return Array.isArray(v) ? v.includes(rid) : v === rid;
2577
+ }).map((id) => ({ id, words: nameOf(id) ?? "" }));
2578
+ return { record_id: rid, total: links.length, links };
2579
+ })
2580
+ );
2581
+ },
2582
+ // A template's own record has no history, comments, checklists or worked-out provenance yet:
2583
+ // these are the answers an installed template gives on its first day.
2584
+ record_history: () => ok([]),
2585
+ field_history: () => ok([]),
2586
+ computed_provenance: () => ok([]),
2587
+ comment_thread: (args) => ok({ record_id: args["p_record_id"] ?? null, comments: [], may_comment: false, may_resolve: false }),
2588
+ checklist_runs: () => ok([]),
2589
+ checklist_templates: () => ok([]),
2590
+ doc_templates: () => ok([]),
2591
+ doc_renders: () => ok([]),
2592
+ doc_signatures: () => ok([]),
2593
+ record_row_controls: () => ok({
2594
+ shown_to: { value: null, effective: "everyone", type_default: null, table_default: null, allowed: ["everyone"], is_child: false, can_change: false },
2595
+ published_to_web: { available: false, value: false, table_default: null, can_change: false },
2596
+ indexed: { available: false, value: null, table_default: null, effective: false, can_change: false }
2597
+ }),
2598
+ enrich_cells: () => ok([]),
2599
+ enrichments: () => ok([]),
2600
+ pipeline_pending: () => ok([]),
2601
+ record_stage_pending: () => ok([]),
2602
+ io_imports: () => ok([]),
2603
+ relation_words: (args) => ok(nameOf(String(args["p_value"] ?? ""))),
2604
+ forms: (args) => ok(
2605
+ world.forms.filter((f) => !f.booking && (!args["p_table_id"] || f.table_id === args["p_table_id"])).map((f) => ({ form_id: f.form_id, table_id: f.table_id, title: f.title, questions: f.questions, presentation: f.presentation, published_at: null, slug: null }))
2606
+ ),
2607
+ bookings: (args) => ok(
2608
+ world.forms.filter((f) => f.booking && (!args["p_table_id"] || f.table_id === args["p_table_id"])).map((f) => ({ form_id: f.form_id, table_id: f.table_id, title: f.title, questions: f.questions, availability: f.booking, presentation: f.presentation, slug: null }))
2609
+ ),
2610
+ dashboards: (args) => ok(
2611
+ world.dashboards.filter((d) => !args["p_table_id"] || d.table_id === args["p_table_id"]).map((d) => ({ dashboard_id: d.dashboard_id, table_id: d.table_id, name: d.name, blocks: d.blocks, presentation: {} }))
2612
+ )
2613
+ };
2614
+ const source = {
2615
+ world,
2616
+ rpc(fn, args) {
2617
+ const name = fn.replace(/^custom\./, "");
2618
+ const door = doors[name];
2619
+ if (door) return Promise.resolve(door(args ?? {}));
2620
+ if (WRITE_DOOR.test(name)) return Promise.resolve({ data: null, error: PREVIEW_REFUSAL });
2621
+ return Promise.resolve(refuse(`A template preview does not answer ${name}.`));
2622
+ },
2623
+ schema() {
2624
+ return {
2625
+ from() {
2626
+ throw new Error("A template preview reads through the store's doors, never a table.");
2627
+ }
2628
+ };
2629
+ }
2630
+ };
2631
+ return source;
2632
+ }
2633
+
2634
+ // src/memory/index.ts
2635
+ function templatePreview(spec, options = {}) {
2636
+ const world = templateWorld(spec, options);
2637
+ const config = {
2638
+ dataSource: memoryDataSource(world),
2639
+ actor: { actor: "user", user_id: world.user_id },
2640
+ organizationId: world.organization_id
2641
+ };
2642
+ return {
2643
+ config,
2644
+ world,
2645
+ tables: world.tables.map((t) => ({ id: t.id, token: t.token, name: String(t.document["name"] ?? t.token), rows: t.order.length })),
2646
+ forms: world.forms.map((f) => ({ id: f.form_id, token: f.token, title: f.title, tableId: f.table_id, booking: f.booking !== null })),
2647
+ dashboards: world.dashboards.map((d) => ({ id: d.dashboard_id, token: d.token, name: d.name, tableId: d.table_id }))
2648
+ };
2649
+ }
2650
+ export {
2651
+ MEMORY_KERNEL,
2652
+ PREVIEW_REFUSAL,
2653
+ memoryDataSource,
2654
+ stableId,
2655
+ templatePreview,
2656
+ templateWorld
2657
+ };
2658
+ //# sourceMappingURL=index.js.map