better-supabase 0.49.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-tables-D6Na4nwb.d.ts → app-tables-ByFny1cL.d.ts} +1 -1
- package/dist/{block-tables-Pd7nOPv3.d.ts → block-tables-CQHwZ9-v.d.ts} +1 -1
- package/dist/cli/{add-BXfK7N0H.js → add-BhQZHdAv.js} +2 -2
- package/dist/cli/add-C8CZuuRW.js +1 -0
- package/dist/cli/{add-Ca3FNbhm.js → add-yTy1CuMe.js} +10 -10
- package/dist/cli/{app-table-files-BR0zwJ7T.js → app-table-files-CSZU_cFC.js} +2 -2
- package/dist/cli/{app-tables-DAHcDTFh.js → app-tables-CmY2GVb3.js} +2 -2
- package/dist/cli/{backfill-DHD9e6XO.js → backfill-BUNIA-Vt.js} +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-C4J4d_Jx.js → blocks-BO-v5N1q.js} +1 -1
- package/dist/cli/{blocks-DtEsw6CG.js → blocks-CLaPv7TM.js} +1 -1
- package/dist/cli/{cache-DyhfGbUV.js → cache-VZU4FIOF.js} +1 -1
- package/dist/cli/{codemod-B7EdR7Fu.js → codemod-DgbHI_T7.js} +1 -1
- package/dist/cli/{content-mapper-BM9asZuL.js → content-mapper-5_KpJMOD.js} +2 -2
- package/dist/cli/{doctor-BuE0Ry7T.js → doctor-BsB5Sg9v.js} +142 -16
- package/dist/cli/{gen-DMAd__D1.js → gen-Dbtv-GLi.js} +11 -11
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +6 -6
- package/dist/cli/{init-BfpkhVgY.js → init-DbxcqUL_.js} +8 -8
- package/dist/cli/{live-XBM0kzT3.js → live-B86Xvfaj.js} +2 -2
- package/dist/cli/{mcp-C9HqqPIV.js → mcp-BjvRPCNn.js} +2 -2
- package/dist/cli/{metadata-dYoVRApT.js → metadata-BCKNATUX.js} +3 -3
- package/dist/cli/{migrate-DLWnaHNN.js → migrate-Ds8H9Vq6.js} +1 -1
- package/dist/cli/{migration-safety-Bh7VzARh.js → migration-safety-CVtbyZQ4.js} +1 -1
- package/dist/cli/{migrations-Cq5hkJsa.js → migrations-Dob5hF6K.js} +2 -2
- package/dist/cli/{module-migration-BUd_MAbE.js → module-migration-BSOn1xPx.js} +2 -2
- package/dist/cli/powersync-6wkF5mUR.js +1 -0
- package/dist/cli/{powersync-Cb8xtLDc.js → powersync-aGKsgFN9.js} +3 -3
- package/dist/cli/{print-BVeE5vr_.js → print-scQOZbuq.js} +2 -2
- package/dist/cli/{providers-xmyaROnG.js → providers-Dr7FyvN1.js} +1 -1
- package/dist/cli/{prune-workflows-DUOBOuHp.js → prune-workflows-DguQsnDA.js} +1 -1
- package/dist/cli/{remove-BuasHmdF.js → remove-BK_muhLi.js} +6 -6
- package/dist/cli/{render-Hvu_ZKtr.js → render-D8KGIoSK.js} +3 -3
- package/dist/cli/{run-KdsUN7Qj.js → run-BIAan13C.js} +9 -9
- package/dist/cli/{run-DMZQUy5b.js → run-aWo2fn_x.js} +29 -29
- package/dist/cli/{shared-3cetvs_N.js → shared-d7o6xxEZ.js} +1 -1
- package/dist/cli/{snapshot-D7h2oWfS.js → snapshot-BmBrjk2b.js} +2 -2
- package/dist/cli/{source-ENOc1zZ9.js → source-CEPki4I3.js} +1 -1
- package/dist/cli/{spec-CfKQ2Xxd.js → spec-36lt_pPC.js} +1 -1
- package/dist/cli/{spec-DGaKqtfR.js → spec-BKCoD-Ct.js} +2 -2
- package/dist/cli/{sql-layout-CGlyhvQ1.js → sql-layout-BevHhOrq.js} +2 -2
- package/dist/cli/{sync-DFJfT7dH.js → sync-x1M-Ywqf.js} +4 -4
- package/dist/cli/{upgrade-C2Kdvrj-.js → upgrade-BUDxM1EG.js} +5 -5
- package/dist/cli/{upgrade-DSi7r0MG.js → upgrade-Dqze3aEB.js} +2 -2
- package/dist/cli/{version-AGe2VWGm.js → version-CvNMxnwv.js} +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/{context-DNwBlpKo.d.ts → context-BlLvUNCj.d.ts} +22 -1
- package/dist/contract/index.d.ts +1 -1
- package/dist/create/index.d.ts +3 -3
- package/dist/create/index.js +1 -1
- package/dist/create/lite/index.d.ts +2 -2
- package/dist/create/lite/index.js +1 -1
- package/dist/{index-EHczIYa7.d.ts → index-CdtD8fqI.d.ts} +29 -2
- package/dist/{index-D6y6ojUX.d.ts → index-DxmiTJJ5.d.ts} +1 -1
- package/dist/mapper/bin.js +5 -5
- package/dist/otel/index.js +4 -4
- package/dist/preset/index.d.ts +3 -3
- package/dist/{project-CwZtBezd.js → project-C71Z2pg2.js} +1 -1
- package/dist/sql/index.d.ts +5 -5
- package/dist/sql/index.js +2 -2
- package/dist/{sql-BPU70zf9.js → sql-DPDvUadH.js} +363 -66
- package/dist/testing/index.d.ts +1 -1
- package/dist/{types-D9r3axee.d.ts → types-Dp1r6bih.d.ts} +1 -1
- package/package.json +1 -1
- package/schemas/doctor-report-v1.json +1 -0
- package/dist/cli/add-4-omCrbh.js +0 -1
- package/dist/cli/powersync-ZBM_emZL.js +0 -1
|
@@ -654,7 +654,7 @@ function registration(args) {
|
|
|
654
654
|
}
|
|
655
655
|
const CALL$1 = /\bbetter_supabase\s*\.\s*(un)?audit\s*\(/gi;
|
|
656
656
|
const IDENT$12 = String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`;
|
|
657
|
-
const TRIGGER$
|
|
657
|
+
const TRIGGER$3 = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?trigger\s+"?bsb?_audit"?\s+after\s+[\s\S]*?\bon\s+(${IDENT$12}(?:\s*\.\s*${IDENT$12})?)\s+for\s+each\s+row\s+execute\s+(?:function|procedure)\s+better_supabase\s*\.\s*audit_row_change\s*\(`, "gi");
|
|
658
658
|
const TABLE_NAME$5 = String.raw`${IDENT$12}(?:\s*\.\s*${IDENT$12})?`;
|
|
659
659
|
const DROP = /* @__PURE__ */ new RegExp(String.raw`\bdrop\s+table\s+(?:if\s+exists\s+)?(${TABLE_NAME$5}(?:\s*,\s*${TABLE_NAME$5})*)`, "gi");
|
|
660
660
|
const names$10 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
@@ -690,7 +690,7 @@ function auditRegistrations(files) {
|
|
|
690
690
|
match,
|
|
691
691
|
kind: "call"
|
|
692
692
|
})),
|
|
693
|
-
...[...text.matchAll(TRIGGER$
|
|
693
|
+
...[...text.matchAll(TRIGGER$3)].map((match) => ({
|
|
694
694
|
match,
|
|
695
695
|
kind: "trigger"
|
|
696
696
|
})),
|
|
@@ -16890,7 +16890,7 @@ function writtenPairs(ctx, table, pairs) {
|
|
|
16890
16890
|
* A `column = value,` line for each pair whose column `table` has, for an
|
|
16891
16891
|
* update's set list, each after the previous line's comma.
|
|
16892
16892
|
*/
|
|
16893
|
-
function assignments$
|
|
16893
|
+
function assignments$2(ctx, table, pairs, indent = " ") {
|
|
16894
16894
|
return pairs.filter(([column]) => ctx.has(table, column)).map(([column, value]) => `\n${indent}${ctx.col(table, column)} = ${value()},`).join("");
|
|
16895
16895
|
}
|
|
16896
16896
|
/**
|
|
@@ -23504,7 +23504,7 @@ begin
|
|
|
23504
23504
|
${raise$1("Approval % was already %", "P0001", "AI_APPROVAL_DECIDED", `v_row.${a.id}`, `v_row.${a.decision}`)}
|
|
23505
23505
|
end if;
|
|
23506
23506
|
update ${t.approvals} x set
|
|
23507
|
-
${a.decision} = ${ctx.cast("approvals", "decision", "v_decision")},${assignments$
|
|
23507
|
+
${a.decision} = ${ctx.cast("approvals", "decision", "v_decision")},${assignments$2(ctx, "approvals", [["reason", () => "apply_ai_tool_approval.reason"], ["decidedBy", () => "auth.uid()"]])}
|
|
23508
23508
|
${a.decidedAt} = now()
|
|
23509
23509
|
where x.${a.id} = v_row.${a.id}
|
|
23510
23510
|
returning * into v_row;
|
|
@@ -24162,7 +24162,7 @@ function harnessSandboxSave(ctx, names, fields) {
|
|
|
24162
24162
|
on conflict (${s.provider}, ${s.sandbox}) do update set
|
|
24163
24163
|
${s.chat} = excluded.${s.chat},
|
|
24164
24164
|
${s.harness} = excluded.${s.harness},
|
|
24165
|
-
${s.status} = ${ctx.cast("sandboxes", "status", "'running'")},${assignments$
|
|
24165
|
+
${s.status} = ${ctx.cast("sandboxes", "status", "'running'")},${assignments$2(ctx, "sandboxes", [["error", () => "null"]], " ")}
|
|
24166
24166
|
${s.stoppedAt} = null,
|
|
24167
24167
|
${s.lastUsedAt} = now(),
|
|
24168
24168
|
${s.updatedAt} = now()
|
|
@@ -24215,12 +24215,12 @@ begin
|
|
|
24215
24215
|
insert into ${sandboxes} as cur (${registerColumns})
|
|
24216
24216
|
values (${registerValues}
|
|
24217
24217
|
)
|
|
24218
|
-
on conflict (${s.provider}, ${s.sandbox}) do update set${assignments$
|
|
24218
|
+
on conflict (${s.provider}, ${s.sandbox}) do update set${assignments$2(ctx, "sandboxes", [["container", () => `coalesce(excluded.${s.container}, cur.${s.container})`]])}
|
|
24219
24219
|
${s.chat} = coalesce(excluded.${s.chat}, cur.${s.chat}),
|
|
24220
|
-
${s.harness} = coalesce(excluded.${s.harness}, cur.${s.harness}),${assignments$
|
|
24220
|
+
${s.harness} = coalesce(excluded.${s.harness}, cur.${s.harness}),${assignments$2(ctx, "sandboxes", [["metadata", () => `cur.${s.metadata} || excluded.${s.metadata}`]])}
|
|
24221
24221
|
${s.idleSeconds} = excluded.${s.idleSeconds},
|
|
24222
24222
|
${s.expiresAt} = coalesce(excluded.${s.expiresAt}, cur.${s.expiresAt}),
|
|
24223
|
-
${s.status} = ${as("'running'")},${assignments$
|
|
24223
|
+
${s.status} = ${as("'running'")},${assignments$2(ctx, "sandboxes", [["error", () => "null"]])}
|
|
24224
24224
|
${s.stoppedAt} = null,
|
|
24225
24225
|
${s.lastUsedAt} = now(),
|
|
24226
24226
|
${s.updatedAt} = now()
|
|
@@ -24315,7 +24315,7 @@ declare
|
|
|
24315
24315
|
begin
|
|
24316
24316
|
update ${sandboxes} x set
|
|
24317
24317
|
${s.status} = ${as("case when finish_ai_sandbox_stop.stopped then 'stopped' else 'running' end")},
|
|
24318
|
-
${s.stoppedAt} = case when finish_ai_sandbox_stop.stopped then now() else null end,${assignments$
|
|
24318
|
+
${s.stoppedAt} = case when finish_ai_sandbox_stop.stopped then now() else null end,${assignments$2(ctx, "sandboxes", [["error", () => "left(finish_ai_sandbox_stop.error, 4000)"]])}
|
|
24319
24319
|
${s.updatedAt} = now()
|
|
24320
24320
|
where x.${s.id} = finish_ai_sandbox_stop.id and ${status("x")} = 'stopping'
|
|
24321
24321
|
returning x.* into v_row;
|
|
@@ -24589,7 +24589,7 @@ begin
|
|
|
24589
24589
|
)
|
|
24590
24590
|
on conflict (${s.run}, ${s.key}) do update set
|
|
24591
24591
|
${s.label} = coalesce(nullif(record_ai_run_step.step ->> 'label', ''), ${t.steps}.${s.label}),
|
|
24592
|
-
${s.status} = excluded.${s.status},${assignments$
|
|
24592
|
+
${s.status} = excluded.${s.status},${assignments$2(ctx, "steps", [["detail", () => `${t.steps}.${s.detail} || excluded.${s.detail}`]])}
|
|
24593
24593
|
${s.endedAt} = case when ${asText$2(ctx, "steps", `excluded.${s.status}`)} <> 'running' then coalesce(${t.steps}.${s.endedAt}, now()) end
|
|
24594
24594
|
returning * into v_row;
|
|
24595
24595
|
perform ${fn("ai_chat_notify")}(v_run.${r.chat}, null, 'run.step', jsonb_build_object('runId', v_run.${r.id}, 'key', v_row.${s.key}, 'status', v_row.${s.status}), false);
|
|
@@ -24693,7 +24693,7 @@ begin
|
|
|
24693
24693
|
${raise$1("Harness session % is locked", "55P03", "AI_HARNESS_LOCKED", "save_ai_harness_session.harness")}
|
|
24694
24694
|
end if;
|
|
24695
24695
|
update ${t.harness} x set
|
|
24696
|
-
${h.resume} = case when save_ai_harness_session.fields ? 'resume_state' then save_ai_harness_session.fields -> 'resume_state' else x.${h.resume} end,${assignments$
|
|
24696
|
+
${h.resume} = case when save_ai_harness_session.fields ? 'resume_state' then save_ai_harness_session.fields -> 'resume_state' else x.${h.resume} end,${assignments$2(ctx, "harness", [["continue", () => `case when save_ai_harness_session.fields ? 'continue_state' then save_ai_harness_session.fields -> 'continue_state' else x.${h.continue} end`]])}
|
|
24697
24697
|
-- A save without a status is a turn using the sandbox: an idle session
|
|
24698
24698
|
-- turns active again.
|
|
24699
24699
|
${h.status} = coalesce(${ctx.cast("harness", "status", "v_status")}, case when ${asText$2(ctx, "harness", `x.${h.status}`)} = 'idle' then ${ctx.cast("harness", "status", "'active'")} else x.${h.status} end),
|
|
@@ -25323,7 +25323,7 @@ begin
|
|
|
25323
25323
|
values (${replyValues}${replyExtras.values}
|
|
25324
25324
|
)
|
|
25325
25325
|
on conflict (${m.chat}, ${m.id}) do update set
|
|
25326
|
-
${m.parts} = excluded.${m.parts},${assignments$
|
|
25326
|
+
${m.parts} = excluded.${m.parts},${assignments$2(ctx, "messages", [
|
|
25327
25327
|
["metadata", () => `excluded.${m.metadata}`],
|
|
25328
25328
|
["format", () => `excluded.${m.format}`],
|
|
25329
25329
|
["native", () => `excluded.${m.native}`],
|
|
@@ -25429,7 +25429,7 @@ begin
|
|
|
25429
25429
|
end if;
|
|
25430
25430
|
update ${t.runs} x set
|
|
25431
25431
|
${r.status} = ${ctx.cast("runs", "status", "v_status")},
|
|
25432
|
-
${r.usage} = coalesce(release_ai_chat_stream.usage, x.${r.usage}),${assignments$
|
|
25432
|
+
${r.usage} = coalesce(release_ai_chat_stream.usage, x.${r.usage}),${assignments$2(ctx, "runs", [
|
|
25433
25433
|
["generation", () => `coalesce(release_ai_chat_stream.generation_id, x.${r.generation})`],
|
|
25434
25434
|
["error", () => "release_ai_chat_stream.error"],
|
|
25435
25435
|
["cost", () => `coalesce(release_ai_chat_stream.cost_micro_usd, x.${r.cost})`]
|
|
@@ -25485,7 +25485,7 @@ begin
|
|
|
25485
25485
|
if not ${SERVICE_CALLER$1} then
|
|
25486
25486
|
${serviceOnly}
|
|
25487
25487
|
end if;
|
|
25488
|
-
update ${t.runs} x set${assignments$
|
|
25488
|
+
update ${t.runs} x set${assignments$2(ctx, "runs", [["cost", () => "set_ai_run_cost.cost_micro_usd"]])}
|
|
25489
25489
|
${r.usage} = x.${r.usage} || coalesce(set_ai_run_cost.usage, '{}'::jsonb)
|
|
25490
25490
|
where ${ctx.has("runs", "generation") ? `x.${r.generation} = set_ai_run_cost.generation_id` : "false"};
|
|
25491
25491
|
get diagnostics v_count = row_count;
|
|
@@ -25709,7 +25709,7 @@ function chats(ctx, names) {
|
|
|
25709
25709
|
["model", "\n v_fields ->> 'default_model'"],
|
|
25710
25710
|
["pinned", "coalesce((v_fields ->> 'pinned')::boolean, false)"]
|
|
25711
25711
|
]);
|
|
25712
|
-
const flags = (table, row) => assignments$
|
|
25712
|
+
const flags = (table, row) => assignments$2(ctx, table, [["pinned", () => PINNED.replace("%s", columnOr(ctx, table, row, "pinned"))], ["archivedAt", () => archivedValue(columnOr(ctx, table, row, "archivedAt"))]]);
|
|
25713
25713
|
const ownProject = (project, owner, tenant) => `exists (select 1 from ${t.projects} pr where pr.${p.id} = ${project} and pr.${p.owner} = ${owner} and pr.${p.tenant} is not distinct from ${tenant})`;
|
|
25714
25714
|
return `-- Whether the caller may read a chat: its owner, the service role, a
|
|
25715
25715
|
-- participant, or a member with ${perm.read} when the chat is shared with
|
|
@@ -25846,7 +25846,7 @@ begin
|
|
|
25846
25846
|
update ${t.chats} x set
|
|
25847
25847
|
${ch.title} = case when v_fields ? 'title' then coalesce(v_fields ->> 'title', '') else x.${ch.title} end,
|
|
25848
25848
|
${ch.model} = case when v_fields ? 'model' then v_fields ->> 'model' else x.${ch.model} end,
|
|
25849
|
-
${ch.project} = case when v_fields ? 'project_id' then v_project else x.${ch.project} end,${assignments$
|
|
25849
|
+
${ch.project} = case when v_fields ? 'project_id' then v_project else x.${ch.project} end,${assignments$2(ctx, "chats", [["agent", () => `case when v_fields ? 'agent_id' then v_fields ->> 'agent_id' else x.${ch.agent} end`]])}
|
|
25850
25850
|
${ch.visibility} = case when v_fields ? 'visibility' then ${ctx.cast("chats", "visibility", "coalesce(v_fields ->> 'visibility', 'private')")} else x.${ch.visibility} end,${flags("chats", "x")}
|
|
25851
25851
|
${ch.temporary} = x.${ch.temporary} and coalesce((v_fields ->> 'is_temporary')::boolean, true),
|
|
25852
25852
|
${ch.expiresAt} = case when x.${ch.temporary} and coalesce((v_fields ->> 'is_temporary')::boolean, true) then x.${ch.expiresAt} end,
|
|
@@ -28019,7 +28019,7 @@ const NAMES$137 = {
|
|
|
28019
28019
|
} }
|
|
28020
28020
|
};
|
|
28021
28021
|
const COLUMN$9 = /^[a-z_][a-z0-9_]*$/;
|
|
28022
|
-
const FUNCTION$
|
|
28022
|
+
const FUNCTION$4 = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)?$/;
|
|
28023
28023
|
const RESTORING = "better_supabase.restoring_version";
|
|
28024
28024
|
function versioned(ctx) {
|
|
28025
28025
|
const where = "blocks.versions.on";
|
|
@@ -28035,7 +28035,7 @@ function versioned(ctx) {
|
|
|
28035
28035
|
const columns = extra["columns"] ?? table["columns"] ?? [];
|
|
28036
28036
|
if (!isColumnList(columns)) throw new TypeError(`${where}.${type}.columns must be a list of column names`);
|
|
28037
28037
|
const apply = extra["apply"];
|
|
28038
|
-
if (apply !== void 0 && (typeof apply !== "string" || !FUNCTION$
|
|
28038
|
+
if (apply !== void 0 && (typeof apply !== "string" || !FUNCTION$4.test(apply))) throw new TypeError(`${where}.${type}.apply must name a function, such as public.apply_document_version`);
|
|
28039
28039
|
const auto = extra["auto"] ?? table["auto"] ?? false;
|
|
28040
28040
|
if (typeof auto !== "boolean") throw new TypeError(`${where}.${type}.auto must be true or false`);
|
|
28041
28041
|
const freeze = freezeOf(extra["freeze"], `${where}.${type}.freeze`);
|
|
@@ -41140,14 +41140,14 @@ const AUTOMATION_EVENTS = {
|
|
|
41140
41140
|
}
|
|
41141
41141
|
};
|
|
41142
41142
|
const SUBJECT_TYPE$1 = SUBJECT_TYPE_SQL_PATTERN;
|
|
41143
|
-
const TRIGGER$
|
|
41143
|
+
const TRIGGER$2 = "^[a-z][a-z0-9_]*([.:][a-z0-9_]+)*$";
|
|
41144
41144
|
const ACTION_KIND = "^[a-z][a-z0-9_]*([.][a-z0-9_]+)*$";
|
|
41145
41145
|
const FIELD_ID = "^[A-Za-z_][A-Za-z0-9_]*([.][A-Za-z_][A-Za-z0-9_]*)*$";
|
|
41146
41146
|
/**
|
|
41147
41147
|
* A logical column of `table`, quoted, or an empty string when the app's table
|
|
41148
41148
|
* lacks it; every use of a missing one is guarded with `ctx.has`.
|
|
41149
41149
|
*/
|
|
41150
|
-
const columnOf$
|
|
41150
|
+
const columnOf$3 = (ctx, table) => (column) => ctx.has(table, column) ? ctx.col(table, column) : "";
|
|
41151
41151
|
/**
|
|
41152
41152
|
* `create table` for `table` with the entries whose column it has; a null
|
|
41153
41153
|
* column is a table constraint.
|
|
@@ -41167,11 +41167,11 @@ function rulesTablesSql(ctx) {
|
|
|
41167
41167
|
const e = ctx.table("evaluations");
|
|
41168
41168
|
const f = ctx.table("fields");
|
|
41169
41169
|
const d = ctx.table("defaults");
|
|
41170
|
-
const r = columnOf$
|
|
41171
|
-
const rd = columnOf$
|
|
41172
|
-
const rv = columnOf$
|
|
41173
|
-
const re = columnOf$
|
|
41174
|
-
const rf = columnOf$
|
|
41170
|
+
const r = columnOf$3(ctx, "rules");
|
|
41171
|
+
const rd = columnOf$3(ctx, "defaults");
|
|
41172
|
+
const rv = columnOf$3(ctx, "versions");
|
|
41173
|
+
const re = columnOf$3(ctx, "evaluations");
|
|
41174
|
+
const rf = columnOf$3(ctx, "fields");
|
|
41175
41175
|
const byIndex = (column, name) => ctx.has("rules", column) ? `\ncreate index if not exists ${name} on ${t} (${r(column)}) where ${r(column)} is not null;` : "";
|
|
41176
41176
|
const defaultKey = ctx.has("rules", "defaultKey") ? `\nalter table ${t} add column if not exists ${r("defaultKey")} text;
|
|
41177
41177
|
create unique index if not exists ${sqlIdent$1(`${ctx.tableName("rules").name}_default_key_idx`)} on ${t} (${r("tenant")}, ${r("defaultKey")}) where ${r("defaultKey")} is not null;` : "";
|
|
@@ -41181,7 +41181,7 @@ ${createTable(ctx, "rules", [
|
|
|
41181
41181
|
["id", "uuid primary key default gen_random_uuid()"],
|
|
41182
41182
|
["tenant", `${id} not null`],
|
|
41183
41183
|
["subjectType", `text not null check (${r("subjectType")} ~ ${sqlString(SUBJECT_TYPE$1)})`],
|
|
41184
|
-
["trigger", `text not null check (length(${r("trigger")}) <= 128 and ${r("trigger")} ~ ${sqlString(TRIGGER$
|
|
41184
|
+
["trigger", `text not null check (length(${r("trigger")}) <= 128 and ${r("trigger")} ~ ${sqlString(TRIGGER$2)})`],
|
|
41185
41185
|
["name", `text not null check (length(${r("name")}) between 1 and 200)`],
|
|
41186
41186
|
["description", `text check (length(${r("description")}) <= 2000)`],
|
|
41187
41187
|
["conditions", "jsonb not null"],
|
|
@@ -41205,7 +41205,7 @@ ${createTable(ctx, "defaults", [
|
|
|
41205
41205
|
["key", `text primary key check (length(${rd("key")}) <= 128 and ${rd("key")} ~ ${sqlString(ACTION_KIND)})`],
|
|
41206
41206
|
["block", "text not null"],
|
|
41207
41207
|
["subjectType", `text not null check (${rd("subjectType")} ~ ${sqlString(SUBJECT_TYPE$1)})`],
|
|
41208
|
-
["trigger", `text not null check (length(${rd("trigger")}) <= 128 and ${rd("trigger")} ~ ${sqlString(TRIGGER$
|
|
41208
|
+
["trigger", `text not null check (length(${rd("trigger")}) <= 128 and ${rd("trigger")} ~ ${sqlString(TRIGGER$2)})`],
|
|
41209
41209
|
["name", `text not null check (length(${rd("name")}) between 1 and 200)`],
|
|
41210
41210
|
["description", `text check (length(${rd("description")}) <= 2000)`],
|
|
41211
41211
|
["conditions", `jsonb not null default '{"id": "root", "type": "group", "combinator": "and", "rules": []}'::jsonb`],
|
|
@@ -41276,8 +41276,8 @@ ${lockTable(f)}`;
|
|
|
41276
41276
|
* version already stored stays.
|
|
41277
41277
|
*/
|
|
41278
41278
|
function saveVersionSql(ctx) {
|
|
41279
|
-
const r = columnOf$
|
|
41280
|
-
const rv = columnOf$
|
|
41279
|
+
const r = columnOf$3(ctx, "rules");
|
|
41280
|
+
const rv = columnOf$3(ctx, "versions");
|
|
41281
41281
|
const saver = ctx.has("versions", "savedBy");
|
|
41282
41282
|
return `insert into ${ctx.table("versions")} (${rv("rule")}, ${rv("version")}, ${rv("tenant")}, ${rv("name")}, ${rv("conditions")}, ${rv("actions")}${saver ? `, ${rv("savedBy")}` : ""})
|
|
41283
41283
|
values (v_row.${r("id")}, v_row.${r("version")}, v_row.${r("tenant")}, v_row.${r("name")}, v_row.${r("conditions")}, v_row.${r("actions")}${saver ? ", auth.uid()" : ""})
|
|
@@ -41293,8 +41293,8 @@ function defaultRulesSql(helpers) {
|
|
|
41293
41293
|
const fn = (name) => ctx.fn(name);
|
|
41294
41294
|
const t = ctx.table("rules");
|
|
41295
41295
|
const d = ctx.table("defaults");
|
|
41296
|
-
const r = columnOf$
|
|
41297
|
-
const rd = columnOf$
|
|
41296
|
+
const r = columnOf$3(ctx, "rules");
|
|
41297
|
+
const rd = columnOf$3(ctx, "defaults");
|
|
41298
41298
|
const copied = [
|
|
41299
41299
|
["tenant", "install_default_rules.tenant"],
|
|
41300
41300
|
["subjectType", `x.${rd("subjectType")}`],
|
|
@@ -41997,10 +41997,10 @@ function build$129(ctx) {
|
|
|
41997
41997
|
const v = ctx.table("versions");
|
|
41998
41998
|
const e = ctx.table("evaluations");
|
|
41999
41999
|
const f = ctx.table("fields");
|
|
42000
|
-
const r = columnOf$
|
|
42001
|
-
const rv = columnOf$
|
|
42002
|
-
const re = columnOf$
|
|
42003
|
-
const rf = columnOf$
|
|
42000
|
+
const r = columnOf$3(ctx, "rules");
|
|
42001
|
+
const rv = columnOf$3(ctx, "versions");
|
|
42002
|
+
const re = columnOf$3(ctx, "evaluations");
|
|
42003
|
+
const rf = columnOf$3(ctx, "fields");
|
|
42004
42004
|
const columnOr = (table, row, column, missing) => ctx.has(table, column) ? `${row}.${ctx.col(table, column)}` : missing;
|
|
42005
42005
|
const present = (table, pairs) => pairs.filter(([column]) => ctx.has(table, column));
|
|
42006
42006
|
const values = (pairs) => pairs.map(([, value, before], index) => index === 0 ? value : `${before ?? ", "}${value}`).join("");
|
|
@@ -42341,7 +42341,7 @@ begin
|
|
|
42341
42341
|
if v_subject_type is null or v_subject_type !~ ${sqlString(SUBJECT_TYPE$1)} then
|
|
42342
42342
|
${fail$1("AUTOMATION_INVALID", "A rule needs a subject type", "22023")}
|
|
42343
42343
|
end if;
|
|
42344
|
-
if v_trigger is null or length(v_trigger) > 128 or v_trigger !~ ${sqlString(TRIGGER$
|
|
42344
|
+
if v_trigger is null or length(v_trigger) > 128 or v_trigger !~ ${sqlString(TRIGGER$2)} then
|
|
42345
42345
|
${fail$1("AUTOMATION_INVALID", "A rule needs a trigger such as expense.submitted", "22023")}
|
|
42346
42346
|
end if;
|
|
42347
42347
|
if v_name is null or length(v_name) > 200 then
|
|
@@ -105844,7 +105844,7 @@ const NAMES$85 = {
|
|
|
105844
105844
|
};
|
|
105845
105845
|
/** The buckets `form_nps` groups periods by. */
|
|
105846
105846
|
const FORM_KEY = /^[a-z][a-z0-9_-]{0,62}$/;
|
|
105847
|
-
const FUNCTION$
|
|
105847
|
+
const FUNCTION$3 = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)?$/;
|
|
105848
105848
|
const functionName = (name) => name.includes(".") ? name.split(".").map((part) => sqlIdent$1(part)).join(".") : `public.${sqlIdent$1(name)}`;
|
|
105849
105849
|
/**
|
|
105850
105850
|
* `options.handlers`: form key to `schema.function(submission_id uuid) returns
|
|
@@ -105856,7 +105856,7 @@ function handlersOf(ctx) {
|
|
|
105856
105856
|
if (!isRecord$1(raw)) throw new TypeError(`${WHERE$17}.handlers must map form keys to functions, such as { contact: "public.lead_from_submission" }`);
|
|
105857
105857
|
return Object.entries(raw).map(([key, fn]) => {
|
|
105858
105858
|
if (!FORM_KEY.test(key)) throw new TypeError(`${WHERE$17}.handlers: "${key}" is not a form key`);
|
|
105859
|
-
if (typeof fn !== "string" || !FUNCTION$
|
|
105859
|
+
if (typeof fn !== "string" || !FUNCTION$3.test(fn)) throw new TypeError(`${WHERE$17}.handlers.${key} must name a function, such as public.lead_from_submission`);
|
|
105860
105860
|
return [key, fn];
|
|
105861
105861
|
});
|
|
105862
105862
|
}
|
|
@@ -111265,16 +111265,16 @@ const OUTCOMES = [
|
|
|
111265
111265
|
"rejected",
|
|
111266
111266
|
"withdrawn"
|
|
111267
111267
|
];
|
|
111268
|
-
function columnOf$
|
|
111268
|
+
function columnOf$2(where, value) {
|
|
111269
111269
|
if (typeof value !== "string" || !COLUMN$4.test(value)) throw new TypeError(`${where} must be a column name`);
|
|
111270
111270
|
return sqlIdent$1(value);
|
|
111271
111271
|
}
|
|
111272
111272
|
function markerOf(where, value) {
|
|
111273
111273
|
if (value === void 0) return;
|
|
111274
|
-
if (typeof value === "string") return { column: columnOf$
|
|
111274
|
+
if (typeof value === "string") return { column: columnOf$2(where, value) };
|
|
111275
111275
|
if (!isRecord$1(value) || typeof value["value"] !== "string" || value["value"] === "") throw new TypeError(`${where} must be a boolean column or { column, value }`);
|
|
111276
111276
|
return {
|
|
111277
|
-
column: columnOf$
|
|
111277
|
+
column: columnOf$2(`${where}.column`, value["column"]),
|
|
111278
111278
|
value: value["value"]
|
|
111279
111279
|
};
|
|
111280
111280
|
}
|
|
@@ -111300,10 +111300,10 @@ function jobStages(ctx) {
|
|
|
111300
111300
|
}
|
|
111301
111301
|
return {
|
|
111302
111302
|
table: quotedTable(raw["table"]),
|
|
111303
|
-
id: columnOf$
|
|
111304
|
-
job: columnOf$
|
|
111305
|
-
rank: columnOf$
|
|
111306
|
-
...raw["archivedAt"] !== void 0 && { archivedAt: columnOf$
|
|
111303
|
+
id: columnOf$2(`${where}.id`, raw["id"] ?? "id"),
|
|
111304
|
+
job: columnOf$2(`${where}.job`, raw["job"]),
|
|
111305
|
+
rank: columnOf$2(`${where}.rank`, raw["rank"]),
|
|
111306
|
+
...raw["archivedAt"] !== void 0 && { archivedAt: columnOf$2(`${where}.archivedAt`, raw["archivedAt"]) },
|
|
111307
111307
|
markers
|
|
111308
111308
|
};
|
|
111309
111309
|
}
|
|
@@ -112371,10 +112371,10 @@ const NAMES$79 = { tables: { state: {
|
|
|
112371
112371
|
} } };
|
|
112372
112372
|
const JOB_NAME = /^[a-z][a-z0-9_.-]*$/u;
|
|
112373
112373
|
const INTERVAL = /^\d+ (?:seconds?|minutes?|hours?|days?)$/u;
|
|
112374
|
-
const FUNCTION$
|
|
112374
|
+
const FUNCTION$2 = /^"?[a-z_][a-z0-9_]*"?\."?[a-z_][a-z0-9_]*"?$/u;
|
|
112375
112375
|
function build$80(ctx) {
|
|
112376
112376
|
const jobs = uniqueContributions("housekeeping", ctx.contributions("housekeeping"), (job) => job.job);
|
|
112377
|
-
for (const job of jobs) if (!JOB_NAME.test(job.job) || !INTERVAL.test(job.every) || !FUNCTION$
|
|
112377
|
+
for (const job of jobs) if (!JOB_NAME.test(job.job) || !INTERVAL.test(job.every) || !FUNCTION$2.test(job.function)) throw new TypeError(`housekeeping job "${job.job}" needs a lowercase name, a qualified function and an interval such as "15 minutes" (got "${job.function}", "${job.every}")`);
|
|
112378
112378
|
const state = ctx.table("state");
|
|
112379
112379
|
const c = (column) => ctx.col("state", column);
|
|
112380
112380
|
const values = jobs.length === 0 ? "select null::text, null::text, null::interval where false" : jobs.toSorted((a, b) => a.job.localeCompare(b.job)).map((job) => ` (${sqlString(job.job)}, ${sqlString(job.function)}, interval ${sqlString(job.every)})`).join(",\n");
|
|
@@ -167925,7 +167925,7 @@ const PIPELINE_OUTCOMES = [
|
|
|
167925
167925
|
const NAME$2 = /^[a-z][a-z0-9_]{0,62}$/;
|
|
167926
167926
|
const VARIANT = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
167927
167927
|
const COLUMN$2 = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
167928
|
-
function columnOf(where, value, fallback) {
|
|
167928
|
+
function columnOf$1(where, value, fallback) {
|
|
167929
167929
|
if (value === void 0) return fallback;
|
|
167930
167930
|
if (typeof value !== "string" || !COLUMN$2.test(value)) throw new TypeError(`${where} must be a column name`);
|
|
167931
167931
|
return value;
|
|
@@ -167972,7 +167972,7 @@ function stagesOf(where, value, categories) {
|
|
|
167972
167972
|
function statusOf(where, value, categories) {
|
|
167973
167973
|
if (value === void 0) return;
|
|
167974
167974
|
if (!isRecord$1(value) || !isRecord$1(value["values"])) throw new TypeError(`${where}.status needs column and values`);
|
|
167975
|
-
const column = columnOf(`${where}.status.column`, value["column"]);
|
|
167975
|
+
const column = columnOf$1(`${where}.status.column`, value["column"]);
|
|
167976
167976
|
if (column === void 0) throw new TypeError(`${where}.status.column is required`);
|
|
167977
167977
|
const values = {};
|
|
167978
167978
|
for (const [category, status] of Object.entries(value["values"])) {
|
|
@@ -168021,7 +168021,7 @@ function pipelineBindings(ctx) {
|
|
|
168021
168021
|
if (subject.tenant === void 0) throw new TypeError(`${where}: config.subjects.${type} needs a tenant column`);
|
|
168022
168022
|
if (!isRecord$1(entry)) throw new TypeError(`${where} must be an object`);
|
|
168023
168023
|
const categories = categoriesOf(where, entry["categories"]);
|
|
168024
|
-
const optional = (key) => columnOf(`${where}.${key}`, entry[key]);
|
|
168024
|
+
const optional = (key) => columnOf$1(`${where}.${key}`, entry[key]);
|
|
168025
168025
|
const amount = optional("amount");
|
|
168026
168026
|
const currency = optional("currency");
|
|
168027
168027
|
if (amount === void 0 !== (currency === void 0)) throw new TypeError(`${where}: amount and currency go together`);
|
|
@@ -168035,8 +168035,8 @@ function pipelineBindings(ctx) {
|
|
|
168035
168035
|
return {
|
|
168036
168036
|
type,
|
|
168037
168037
|
subject,
|
|
168038
|
-
stage: columnOf(`${where}.stage`, entry["stage"], "stage_id") ?? "stage_id",
|
|
168039
|
-
pipeline: columnOf(`${where}.pipeline`, entry["pipeline"], "pipeline_id") ?? "pipeline_id",
|
|
168038
|
+
stage: columnOf$1(`${where}.stage`, entry["stage"], "stage_id") ?? "stage_id",
|
|
168039
|
+
pipeline: columnOf$1(`${where}.pipeline`, entry["pipeline"], "pipeline_id") ?? "pipeline_id",
|
|
168040
168040
|
categories,
|
|
168041
168041
|
stages: stagesOf(where, entry["stages"], categories),
|
|
168042
168042
|
...enteredAt !== void 0 && { enteredAt },
|
|
@@ -217542,6 +217542,10 @@ function built(definition) {
|
|
|
217542
217542
|
}
|
|
217543
217543
|
};
|
|
217544
217544
|
}
|
|
217545
|
+
function moduleSource(name, layout = {}, installed) {
|
|
217546
|
+
const module = SQL_MODULES[name];
|
|
217547
|
+
return module === void 0 ? void 0 : module.build(moduleContext(name, layout, installed), layout);
|
|
217548
|
+
}
|
|
217545
217549
|
const TENANT_PROVIDERS = /* @__PURE__ */ new Set(["memberships", "permissions"]);
|
|
217546
217550
|
/**
|
|
217547
217551
|
* The scope `name` runs in for `layout`: its own, then `sql.scope`, then
|
|
@@ -219859,8 +219863,8 @@ const TABLE = new RegExp(String.raw`^create table if not exists (${QUALIFIED}) \
|
|
|
219859
219863
|
const ADDED_COLUMN = new RegExp(String.raw`^alter table (?:if exists )?(${QUALIFIED})\s+add column if not exists (${IDENT})`, "gim");
|
|
219860
219864
|
const INDEX = new RegExp(String.raw`create (?:unique )?index (?:if not exists )?(${IDENT})\s+on (?:only )?(${QUALIFIED})`, "gi");
|
|
219861
219865
|
const POLICY = new RegExp(String.raw`create policy (${IDENT}) on (${QUALIFIED})`, "gi");
|
|
219862
|
-
const TRIGGER = new RegExp(String.raw`create (?:or replace )?(?:constraint )?trigger (${IDENT})\s[^;]*? on (${QUALIFIED})`, "gi");
|
|
219863
|
-
const FUNCTION = new RegExp(String.raw`create (?:or replace )?function (${QUALIFIED})\(`, "gi");
|
|
219866
|
+
const TRIGGER$1 = new RegExp(String.raw`create (?:or replace )?(?:constraint )?trigger (${IDENT})\s[^;]*? on (${QUALIFIED})`, "gi");
|
|
219867
|
+
const FUNCTION$1 = new RegExp(String.raw`create (?:or replace )?function (${QUALIFIED})\(`, "gi");
|
|
219864
219868
|
const NOT_COLUMN = /^(?:constraint|primary key|unique|foreign key|check|exclude)\b/i;
|
|
219865
219869
|
const unquote$1 = (ident) => ident.startsWith("\"") ? ident.slice(1, -1).replaceAll("\"\"", "\"") : ident;
|
|
219866
219870
|
const quote = (ident) => `"${ident.replaceAll("\"", "\"\"")}"`;
|
|
@@ -220345,8 +220349,8 @@ function created(body, schema) {
|
|
|
220345
220349
|
columns,
|
|
220346
220350
|
indexes: named(INDEX),
|
|
220347
220351
|
policies: named(POLICY),
|
|
220348
|
-
triggers: named(TRIGGER),
|
|
220349
|
-
functions: [...body.matchAll(FUNCTION)].map((match) => qualified(match[1], schema))
|
|
220352
|
+
triggers: named(TRIGGER$1),
|
|
220353
|
+
functions: [...body.matchAll(FUNCTION$1)].map((match) => qualified(match[1], schema))
|
|
220350
220354
|
};
|
|
220351
220355
|
}
|
|
220352
220356
|
/**
|
|
@@ -220721,8 +220725,8 @@ function instanceFunctions(layout, installed, instance) {
|
|
|
220721
220725
|
}
|
|
220722
220726
|
// src/sql/text-writes.ts
|
|
220723
220727
|
const TABLE_NAME$1 = String.raw`(${NAME$10}(?:\s*\.\s*${NAME$10})?)`;
|
|
220724
|
-
const INSERT = /* @__PURE__ */ new RegExp(String.raw`\binsert\s+into\s+${TABLE_NAME$1}(?:\s+as\s+${NAME$10})?\s*\(`, "gi");
|
|
220725
|
-
const UPDATE = /* @__PURE__ */ new RegExp(String.raw`\bupdate\s+(?:only\s+)?${TABLE_NAME$1}(?:\s+(?:as\s+)?(?!set\b)${NAME$10})?\s+set\b`, "gi");
|
|
220728
|
+
const INSERT$1 = /* @__PURE__ */ new RegExp(String.raw`\binsert\s+into\s+${TABLE_NAME$1}(?:\s+as\s+${NAME$10})?\s*\(`, "gi");
|
|
220729
|
+
const UPDATE$1 = /* @__PURE__ */ new RegExp(String.raw`\bupdate\s+(?:only\s+)?${TABLE_NAME$1}(?:\s+(?:as\s+)?(?!set\b)${NAME$10})?\s+set\b`, "gi");
|
|
220726
220730
|
const SELECT_END = [
|
|
220727
220731
|
"from",
|
|
220728
220732
|
"where",
|
|
@@ -220737,7 +220741,7 @@ const SET_END = [
|
|
|
220737
220741
|
"returning",
|
|
220738
220742
|
"on"
|
|
220739
220743
|
];
|
|
220740
|
-
const LITERAL = /^(?:'(?:[^']|'')*'|null|default)$/i;
|
|
220744
|
+
const LITERAL$2 = /^(?:'(?:[^']|'')*'|null|default)$/i;
|
|
220741
220745
|
const COPY = /* @__PURE__ */ new RegExp(String.raw`^(?:excluded|old|new)\s*\.\s*(${NAME$10})$`, "i");
|
|
220742
220746
|
function partEnd(text, start, ends) {
|
|
220743
220747
|
const keyword = new RegExp(`^(?:${ends.join("|")})\\b`, "i");
|
|
@@ -220760,12 +220764,12 @@ function partEnd(text, start, ends) {
|
|
|
220760
220764
|
function writes(found, table, column, value) {
|
|
220761
220765
|
const expression = value.trim();
|
|
220762
220766
|
const copied = COPY.exec(expression)?.[1];
|
|
220763
|
-
if (LITERAL.test(expression) || copied !== void 0 && unquote$5(copied) === column) return;
|
|
220767
|
+
if (LITERAL$2.test(expression) || copied !== void 0 && unquote$5(copied) === column) return;
|
|
220764
220768
|
const columns = found.get(table) ?? /* @__PURE__ */ new Set();
|
|
220765
220769
|
columns.add(column);
|
|
220766
220770
|
found.set(table, columns);
|
|
220767
220771
|
}
|
|
220768
|
-
function assignments(found, table, text) {
|
|
220772
|
+
function assignments$1(found, table, text) {
|
|
220769
220773
|
for (const part of splitTopLevel(text)) {
|
|
220770
220774
|
const assignment = new RegExp(`^\\s*(${NAME$10})\\s*=([\\s\\S]*)$`).exec(part);
|
|
220771
220775
|
if (assignment !== null) writes(found, table, unquote$5(assignment[1]), assignment[2]);
|
|
@@ -220780,7 +220784,7 @@ function assignments(found, table, text) {
|
|
|
220780
220784
|
function computedWrites(sql) {
|
|
220781
220785
|
const text = withoutComments(sql);
|
|
220782
220786
|
const found = /* @__PURE__ */ new Map();
|
|
220783
|
-
for (const match of text.matchAll(INSERT)) {
|
|
220787
|
+
for (const match of text.matchAll(INSERT$1)) {
|
|
220784
220788
|
const table = qualified$10(match[1]);
|
|
220785
220789
|
const open = match.index + match[0].length - 1;
|
|
220786
220790
|
const close = closingParen(text, open);
|
|
@@ -220796,13 +220800,13 @@ function computedWrites(sql) {
|
|
|
220796
220800
|
const conflict = /^[^;]*?\bon\s+conflict\b[^;]*?\bdo\s+update\s+set\b/i.exec(text.slice(end === -1 ? start : end));
|
|
220797
220801
|
if (conflict !== null) {
|
|
220798
220802
|
const from = (end === -1 ? start : end) + conflict[0].length;
|
|
220799
|
-
assignments(found, table, text.slice(from, partEnd(text, from, SET_END)));
|
|
220803
|
+
assignments$1(found, table, text.slice(from, partEnd(text, from, SET_END)));
|
|
220800
220804
|
}
|
|
220801
220805
|
}
|
|
220802
|
-
for (const match of text.matchAll(UPDATE)) {
|
|
220806
|
+
for (const match of text.matchAll(UPDATE$1)) {
|
|
220803
220807
|
const table = qualified$10(match[1]);
|
|
220804
220808
|
const start = match.index + match[0].length;
|
|
220805
|
-
assignments(found, table, text.slice(start, partEnd(text, start, SET_END)));
|
|
220809
|
+
assignments$1(found, table, text.slice(start, partEnd(text, start, SET_END)));
|
|
220806
220810
|
}
|
|
220807
220811
|
return found;
|
|
220808
220812
|
}
|
|
@@ -221126,6 +221130,299 @@ function blockReadRoles(module, layout, installed, instance) {
|
|
|
221126
221130
|
const key = ctx.permissionKey("read", moduleOperations(module).read);
|
|
221127
221131
|
return Object.entries(rolesOf(ctx)).flatMap(([role, keys]) => keys.some((granted) => permissionMatches(granted, key)) ? [role] : []);
|
|
221128
221132
|
}
|
|
221133
|
+
// src/sql/check-values.ts
|
|
221134
|
+
const CHECK = /^check\s*\(/i;
|
|
221135
|
+
const IN = /^([\s\S]+?)\s+in\s*\(([\s\S]*)\)$/i;
|
|
221136
|
+
const ANY = /^([\s\S]+?)\s*=\s*any\s*\(\s*(?:\(\s*)?array\s*\[([\s\S]*?)\]\s*\)?(?:\s*::\s*[\w." ]+(?:\[\])*)?\s*\)$/i;
|
|
221137
|
+
const EQUALS = /^([\s\S]+?)\s*=\s*([\s\S]+)$/;
|
|
221138
|
+
const CAST = /\s*::\s*[\w."]+(?:\s+[\w."]+)*(?:\s*\(\s*\d+(?:\s*,\s*\d+)?\s*\))?(?:\[\])*$/;
|
|
221139
|
+
const LITERAL$1 = /^'((?:[^']|'')*)'$/;
|
|
221140
|
+
/** `text` without balanced parentheses around it. */
|
|
221141
|
+
function unwrap(text) {
|
|
221142
|
+
let value = text.trim();
|
|
221143
|
+
while (value.startsWith("(") && closingParen(value, 0) === value.length - 1) value = value.slice(1, -1).trim();
|
|
221144
|
+
return value;
|
|
221145
|
+
}
|
|
221146
|
+
/** `text` without a trailing `::type` cast and the parentheses around it. */
|
|
221147
|
+
function withoutCast(text) {
|
|
221148
|
+
let value = unwrap(text);
|
|
221149
|
+
while (CAST.test(value)) value = unwrap(value.replace(CAST, ""));
|
|
221150
|
+
return value;
|
|
221151
|
+
}
|
|
221152
|
+
function columnOf(text) {
|
|
221153
|
+
const value = withoutCast(text);
|
|
221154
|
+
const match = new RegExp(`^${NAME$10}$`).exec(value);
|
|
221155
|
+
return match === null ? void 0 : unquote$5(match[0]);
|
|
221156
|
+
}
|
|
221157
|
+
function literalOf(text) {
|
|
221158
|
+
const match = LITERAL$1.exec(withoutCast(text));
|
|
221159
|
+
return match === null ? void 0 : match[1].replaceAll("''", "'");
|
|
221160
|
+
}
|
|
221161
|
+
function literals(list) {
|
|
221162
|
+
const values = splitTopLevel(list).map(literalOf);
|
|
221163
|
+
return values.every((value) => value !== void 0) ? values : void 0;
|
|
221164
|
+
}
|
|
221165
|
+
function membership(body) {
|
|
221166
|
+
const inMatch = IN.exec(body);
|
|
221167
|
+
if (inMatch !== null) {
|
|
221168
|
+
const column = columnOf(inMatch[1]);
|
|
221169
|
+
const values = literals(inMatch[2]);
|
|
221170
|
+
return column === void 0 || values === void 0 ? void 0 : {
|
|
221171
|
+
column,
|
|
221172
|
+
values
|
|
221173
|
+
};
|
|
221174
|
+
}
|
|
221175
|
+
const anyMatch = ANY.exec(body);
|
|
221176
|
+
if (anyMatch !== null) {
|
|
221177
|
+
const column = columnOf(anyMatch[1]);
|
|
221178
|
+
const values = literals(anyMatch[2]);
|
|
221179
|
+
return column === void 0 || values === void 0 ? void 0 : {
|
|
221180
|
+
column,
|
|
221181
|
+
values
|
|
221182
|
+
};
|
|
221183
|
+
}
|
|
221184
|
+
const equals = EQUALS.exec(body);
|
|
221185
|
+
if (equals !== null) {
|
|
221186
|
+
const column = columnOf(equals[1]);
|
|
221187
|
+
const value = literalOf(equals[2]);
|
|
221188
|
+
return column === void 0 || value === void 0 ? void 0 : {
|
|
221189
|
+
column,
|
|
221190
|
+
values: [value]
|
|
221191
|
+
};
|
|
221192
|
+
}
|
|
221193
|
+
}
|
|
221194
|
+
/**
|
|
221195
|
+
* The column and values a `check (column in (...))` or `check (column = any
|
|
221196
|
+
* (array[...]))` constraint accepts, as Postgres prints it or as a schema file
|
|
221197
|
+
* writes it. `undefined` for a check that constrains more than one column, a
|
|
221198
|
+
* negation, a pattern or an expression.
|
|
221199
|
+
*/
|
|
221200
|
+
function checkValues(definition) {
|
|
221201
|
+
const text = definition.trim().replace(/\s+not\s+valid$/i, "");
|
|
221202
|
+
const open = CHECK.exec(text);
|
|
221203
|
+
if (open === null) return;
|
|
221204
|
+
const close = closingParen(text, open[0].length - 1);
|
|
221205
|
+
return close === text.length - 1 ? membership(unwrap(text.slice(open[0].length, close))) : void 0;
|
|
221206
|
+
}
|
|
221207
|
+
/**
|
|
221208
|
+
* The membership checks of the `create table` statements in `files`, inline on
|
|
221209
|
+
* a column or as a table constraint, keyed by the table. Checks in `schemas`
|
|
221210
|
+
* only when `schemas` is given.
|
|
221211
|
+
*/
|
|
221212
|
+
function declaredCheckValues(files, schemas) {
|
|
221213
|
+
const found = [];
|
|
221214
|
+
for (const file of files) {
|
|
221215
|
+
const text = withoutComments(file.text);
|
|
221216
|
+
for (const match of text.matchAll(TABLE$2)) {
|
|
221217
|
+
const table = qualified$10(match[1]);
|
|
221218
|
+
if (schemas !== void 0 && !schemas.includes(table.slice(0, table.indexOf(".")))) continue;
|
|
221219
|
+
const open = match.index + match[0].length - 1;
|
|
221220
|
+
const close = closingParen(text, open);
|
|
221221
|
+
if (close === -1) continue;
|
|
221222
|
+
for (const part of splitTopLevel(text.slice(open + 1, close))) {
|
|
221223
|
+
const definition = part.trim();
|
|
221224
|
+
if (/^like\b/i.test(definition)) continue;
|
|
221225
|
+
for (const check of definition.matchAll(/\bcheck\s*\(/gi)) {
|
|
221226
|
+
const checkClose = closingParen(definition, check.index + check[0].length - 1);
|
|
221227
|
+
if (checkClose === -1) continue;
|
|
221228
|
+
const parsed = checkValues(definition.slice(check.index, checkClose + 1));
|
|
221229
|
+
if (parsed !== void 0) found.push({
|
|
221230
|
+
table,
|
|
221231
|
+
...parsed
|
|
221232
|
+
});
|
|
221233
|
+
}
|
|
221234
|
+
}
|
|
221235
|
+
}
|
|
221236
|
+
}
|
|
221237
|
+
return found;
|
|
221238
|
+
}
|
|
221239
|
+
// src/sql/written-values.ts
|
|
221240
|
+
const INSERT = /* @__PURE__ */ new RegExp(String.raw`\binsert\s+into\s+(${NAME$10}(?:\s*\.\s*${NAME$10})?)(?:\s+as\s+${NAME$10})?\s*\(`, "gi");
|
|
221241
|
+
const UPDATE = /* @__PURE__ */ new RegExp(String.raw`\bupdate\s+(?:only\s+)?(${NAME$10}(?:\s*\.\s*${NAME$10})?)`, "gi");
|
|
221242
|
+
const TRIGGER = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?(?:constraint\s+)?trigger\s+${NAME$10}\s+(?:before|instead\s+of)\b[^;]*?\bon\s+(${NAME$10}(?:\s*\.\s*${NAME$10})?)[^;]*?\bexecute\s+(?:function|procedure)\s+(${NAME$10}(?:\s*\.\s*${NAME$10})?)\s*\(`, "gi");
|
|
221243
|
+
const FUNCTION = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?function\s+(${NAME$10}(?:\s*\.\s*${NAME$10})?)\s*\(`, "gi");
|
|
221244
|
+
const NEW_ASSIGNMENT = /* @__PURE__ */ new RegExp(String.raw`\bnew\s*\.\s*(${NAME$10})\s*:=`, "gi");
|
|
221245
|
+
const LITERAL = /'((?:[^']|'')*)'/g;
|
|
221246
|
+
const UNSUPPORTED = "better_supabase.value_unsupported";
|
|
221247
|
+
const DO_UPDATE = /\bdo\s+update\s+set\b/i;
|
|
221248
|
+
function isWord(char) {
|
|
221249
|
+
return char !== void 0 && /[A-Za-z0-9_$]/.test(char);
|
|
221250
|
+
}
|
|
221251
|
+
function skipSpace(text, start) {
|
|
221252
|
+
let at = start;
|
|
221253
|
+
while (at < text.length && /\s/.test(text[at])) at += 1;
|
|
221254
|
+
return at;
|
|
221255
|
+
}
|
|
221256
|
+
function topLevelIndexOf(text, word, start) {
|
|
221257
|
+
const lower = word.toLowerCase();
|
|
221258
|
+
let depth = 0;
|
|
221259
|
+
let quote;
|
|
221260
|
+
for (let i = start; i < text.length; i += 1) {
|
|
221261
|
+
const char = text[i];
|
|
221262
|
+
if (quote !== void 0) {
|
|
221263
|
+
if (char === quote) quote = void 0;
|
|
221264
|
+
continue;
|
|
221265
|
+
}
|
|
221266
|
+
if (char === "'" || char === "\"") {
|
|
221267
|
+
quote = char;
|
|
221268
|
+
continue;
|
|
221269
|
+
}
|
|
221270
|
+
if (char === "(") {
|
|
221271
|
+
depth += 1;
|
|
221272
|
+
continue;
|
|
221273
|
+
}
|
|
221274
|
+
if (char === ")") {
|
|
221275
|
+
depth = Math.max(depth - 1, 0);
|
|
221276
|
+
continue;
|
|
221277
|
+
}
|
|
221278
|
+
if (depth === 0 && text.slice(i, i + lower.length).toLowerCase() === lower && !isWord(text[i - 1]) && !isWord(text[i + lower.length])) return i;
|
|
221279
|
+
}
|
|
221280
|
+
return -1;
|
|
221281
|
+
}
|
|
221282
|
+
function topLevelChar(text, char, start) {
|
|
221283
|
+
let depth = 0;
|
|
221284
|
+
let quote;
|
|
221285
|
+
for (let i = start; i < text.length; i += 1) {
|
|
221286
|
+
const current = text[i];
|
|
221287
|
+
if (quote !== void 0) {
|
|
221288
|
+
if (current === quote) quote = void 0;
|
|
221289
|
+
continue;
|
|
221290
|
+
}
|
|
221291
|
+
if (current === "'" || current === "\"") {
|
|
221292
|
+
quote = current;
|
|
221293
|
+
continue;
|
|
221294
|
+
}
|
|
221295
|
+
if (current === "(") {
|
|
221296
|
+
depth += 1;
|
|
221297
|
+
continue;
|
|
221298
|
+
}
|
|
221299
|
+
if (current === ")") {
|
|
221300
|
+
depth = Math.max(depth - 1, 0);
|
|
221301
|
+
continue;
|
|
221302
|
+
}
|
|
221303
|
+
if (depth === 0 && current === char) return i;
|
|
221304
|
+
}
|
|
221305
|
+
return -1;
|
|
221306
|
+
}
|
|
221307
|
+
function statementEnd(text, start) {
|
|
221308
|
+
const end = topLevelIndexOf(text, ";", start);
|
|
221309
|
+
return end === -1 ? text.length : end;
|
|
221310
|
+
}
|
|
221311
|
+
function lastName(text) {
|
|
221312
|
+
const last = text.match(new RegExp(NAME$10, "g"))?.at(-1);
|
|
221313
|
+
return last === void 0 ? void 0 : unquote$5(last);
|
|
221314
|
+
}
|
|
221315
|
+
function withoutUnsupported(text) {
|
|
221316
|
+
let out = text;
|
|
221317
|
+
for (;;) {
|
|
221318
|
+
const at = out.indexOf(UNSUPPORTED);
|
|
221319
|
+
if (at === -1) return out;
|
|
221320
|
+
const open = out.indexOf("(", at);
|
|
221321
|
+
const close = open === -1 ? -1 : closingParen(out, open);
|
|
221322
|
+
if (close === -1) return out;
|
|
221323
|
+
out = `${out.slice(0, at)}${out.slice(close + 1)}`;
|
|
221324
|
+
}
|
|
221325
|
+
}
|
|
221326
|
+
function collect(expression, found) {
|
|
221327
|
+
for (const match of withoutComparisons(withoutUnsupported(expression)).matchAll(LITERAL)) {
|
|
221328
|
+
const value = match[1].replaceAll("''", "'");
|
|
221329
|
+
if (!found.includes(value)) found.push(value);
|
|
221330
|
+
}
|
|
221331
|
+
}
|
|
221332
|
+
function withoutComparisons(text) {
|
|
221333
|
+
return text.replaceAll(/(?:<>|!=|=)\s*(?:\(\s*)?'(?:[^']|'')*'(?:\s*\))?/g, "").replaceAll(/\b(?:not\s+in|in|like|ilike)\s*\((?:(?!\))[\s\S])*\)/gi, "").replaceAll(/\b(?:not\s+in|in|like|ilike)\s*'(?:[^']|'')*'/gi, "");
|
|
221334
|
+
}
|
|
221335
|
+
function assignments(text, start, column, found) {
|
|
221336
|
+
const stops = [
|
|
221337
|
+
"from",
|
|
221338
|
+
"where",
|
|
221339
|
+
"returning"
|
|
221340
|
+
].map((word) => topLevelIndexOf(text, word, start)).filter((index) => index !== -1);
|
|
221341
|
+
const end = Math.min(statementEnd(text, start), ...stops);
|
|
221342
|
+
for (const part of splitTopLevel(text.slice(start, end))) {
|
|
221343
|
+
const equals = topLevelChar(part, "=", 0);
|
|
221344
|
+
if (equals === -1 || lastName(part.slice(0, equals)) !== column) continue;
|
|
221345
|
+
collect(part.slice(equals + 1), found);
|
|
221346
|
+
}
|
|
221347
|
+
}
|
|
221348
|
+
function functionBody(text, name) {
|
|
221349
|
+
for (const match of text.matchAll(FUNCTION)) {
|
|
221350
|
+
if (qualified$10(match[1]) !== name) continue;
|
|
221351
|
+
const rest = text.slice(match.index + match[0].length);
|
|
221352
|
+
const open = /\$([A-Za-z_]*)\$/.exec(rest);
|
|
221353
|
+
if (open === null) return;
|
|
221354
|
+
const start = open.index + open[0].length;
|
|
221355
|
+
const close = rest.indexOf(open[0], start);
|
|
221356
|
+
return close === -1 ? void 0 : rest.slice(start, close);
|
|
221357
|
+
}
|
|
221358
|
+
}
|
|
221359
|
+
function triggerWrites(text, target, column, found) {
|
|
221360
|
+
for (const match of text.matchAll(TRIGGER)) {
|
|
221361
|
+
if (qualified$10(match[1]) !== target) continue;
|
|
221362
|
+
const body = functionBody(text, qualified$10(match[2]));
|
|
221363
|
+
if (body === void 0) continue;
|
|
221364
|
+
for (const assignment of body.matchAll(NEW_ASSIGNMENT)) {
|
|
221365
|
+
if (unquote$5(assignment[1]) !== column) continue;
|
|
221366
|
+
const start = assignment.index + assignment[0].length;
|
|
221367
|
+
collect(body.slice(start, statementEnd(body, start)), found);
|
|
221368
|
+
}
|
|
221369
|
+
}
|
|
221370
|
+
}
|
|
221371
|
+
function writtenValues(sql, table, column) {
|
|
221372
|
+
const text = withoutComments(sql);
|
|
221373
|
+
const target = qualified$10(table);
|
|
221374
|
+
const found = [];
|
|
221375
|
+
for (const match of text.matchAll(INSERT)) {
|
|
221376
|
+
if (qualified$10(match[1]) !== target) continue;
|
|
221377
|
+
const open = match.index + match[0].length - 1;
|
|
221378
|
+
const close = closingParen(text, open);
|
|
221379
|
+
if (close === -1) continue;
|
|
221380
|
+
const index = splitTopLevel(text.slice(open + 1, close)).map(lastName).indexOf(column);
|
|
221381
|
+
if (index === -1) continue;
|
|
221382
|
+
let at = skipSpace(text, close + 1);
|
|
221383
|
+
if (/^values\b/i.test(text.slice(at))) {
|
|
221384
|
+
at += 6;
|
|
221385
|
+
for (;;) {
|
|
221386
|
+
at = skipSpace(text, at);
|
|
221387
|
+
if (text[at] !== "(") break;
|
|
221388
|
+
const tupleClose = closingParen(text, at);
|
|
221389
|
+
if (tupleClose === -1) break;
|
|
221390
|
+
const expression = splitTopLevel(text.slice(at + 1, tupleClose))[index];
|
|
221391
|
+
if (expression !== void 0) collect(expression, found);
|
|
221392
|
+
at = skipSpace(text, tupleClose + 1);
|
|
221393
|
+
if (text[at] !== ",") break;
|
|
221394
|
+
at += 1;
|
|
221395
|
+
}
|
|
221396
|
+
} else if (/^select\b/i.test(text.slice(at))) {
|
|
221397
|
+
const from = topLevelIndexOf(text, "from", at);
|
|
221398
|
+
const end = from === -1 ? statementEnd(text, at) : Math.min(from, statementEnd(text, at));
|
|
221399
|
+
const expression = splitTopLevel(text.slice(at + 6, end).replace(/^\s*(?:distinct|all)\b/i, ""))[index];
|
|
221400
|
+
if (expression !== void 0) collect(expression, found);
|
|
221401
|
+
}
|
|
221402
|
+
const conflict = text.slice(close, statementEnd(text, close)).search(DO_UPDATE);
|
|
221403
|
+
if (conflict !== -1) {
|
|
221404
|
+
const doUpdate = close + conflict;
|
|
221405
|
+
const set = text.toLowerCase().indexOf("set", doUpdate);
|
|
221406
|
+
if (set !== -1) assignments(text, set + 3, column, found);
|
|
221407
|
+
}
|
|
221408
|
+
}
|
|
221409
|
+
for (const match of text.matchAll(UPDATE)) {
|
|
221410
|
+
if (qualified$10(match[1]) !== target) continue;
|
|
221411
|
+
let at = skipSpace(text, match.index + match[0].length);
|
|
221412
|
+
if (!/^set\b/i.test(text.slice(at))) {
|
|
221413
|
+
if (/^as\b/i.test(text.slice(at))) at = skipSpace(text, at + 2);
|
|
221414
|
+
const alias = new RegExp(NAME$10, "g");
|
|
221415
|
+
alias.lastIndex = at;
|
|
221416
|
+
const name = alias.exec(text);
|
|
221417
|
+
if (name === null) continue;
|
|
221418
|
+
at = skipSpace(text, name.index + name[0].length);
|
|
221419
|
+
if (!/^set\b/i.test(text.slice(at))) continue;
|
|
221420
|
+
}
|
|
221421
|
+
assignments(text, at + 3, column, found);
|
|
221422
|
+
}
|
|
221423
|
+
triggerWrites(text, target, column, found);
|
|
221424
|
+
return found;
|
|
221425
|
+
}
|
|
221129
221426
|
// src/sql/audit-actions.ts
|
|
221130
221427
|
/**
|
|
221131
221428
|
* The categories module actions are audited under. An adopted log with its own
|
|
@@ -221769,4 +222066,4 @@ function setFeatureStatement(sql, schema, table, feature, enabled) {
|
|
|
221769
222066
|
if (enabled) return present ? sql : `${sql.replace(/\n*$/u, "")}\n\n${statement}\n`;
|
|
221770
222067
|
return present ? sql.replace(`\n${statement}`, "").replace(statement, "") : sql;
|
|
221771
222068
|
}
|
|
221772
|
-
export {
|
|
222069
|
+
export { appTablesFiles as $, sameTenantLayout as A, appValues as At, customContracts as B, extensionSchema as Bt, AUDIT_CATEGORIES as C, currentBlockName as Ct, blockReadRoles as D, isBlockSqlIdType as Dt, declaredCheckValues as E, MODULE_ID_TYPES as Et, instanceFunctions as F, declaredIndexes as Ft, upgradePlan as G, moduleTopics as H, rlsTables as Ht, blockTables as I, declaredTableColumns as It, widenedCommands as J, appTablePolicyNotes as K, seedDefaultsFunctions as L, declaredTables as Lt, adoptedTables as M, BLOCK_OPTION_SCHEMAS as Mt, adoptedViews as N, addedColumnTypes as Nt, tenantsQuery as O, moduleIdType as Ot, moduleWritesText as P, declaredColumnTypes as Pt, APP_TABLES_MODULE as Q, moduleLayout as R, declaredUpdatedAtTriggers as Rt, sharedRolesProblems as S, BLOCK_RENAMES as St, checkValues as T, renamedBlock as Tt, renderBlocks as U, auditRegistrations as Ut, moduleBody as V, policyGrants as Vt, moduleDeprecations as W, moduleFilePaths as X, moduleDataDir as Y, APP_TABLES_MARKER as Z, renderRule as _, SECRET_COLUMNS as _t, setTableFeature as a, sameBlockFile as at, compileReadSet as b, sameTenantTrigger as bt, commentOnTableSql as c, modulePermissionKeys as ct, setBsbTag as d, moduleSource as dt, scopePolicyName as et, POLICY_FUNCTIONS as f, resolveBlocks as ft, readRulePolicies as g, resolveExposeColumns as gt, policyFunctionsSql as h, excludedColumns as ht, setFeatureStatement as i, moduleFileVersion as it, adoptedColumnProblems as j, checkedValueMaps as jt, expiredFlagsQuery as k, contractSignature as kt, formatBsbComment as l, moduleSchemaExtensions as lt, isRule as m, TENANT_SCOPE_POLICY as mt, createsTable as n, blockFileState as nt, tableFeatures as o, moduleEventTriggers as ot, disallowedPolicyCalls as p, TENANT_SCOPE_NAMES as pt, declaredPolicies as q, isTableFeature as r, isModuleDataFile as rt, tableTagComments as s, moduleHidingColumns as st, TABLE_FEATURES as t, blockSqlVersion as tt, parseBsbComment as u, SQL_MODULES as ut, renderRulePolicy as v, dataExportPlan as vt, writtenValues as w, formerBlockName as wt, compileReadSets as x, migrationOptionUses as xt, rulePolicy as y, sameTenantColumn as yt, entityRenamePlan as z, declaredViews as zt };
|