@marktiderman/genesis-core 2.17.0 → 2.18.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.
Files changed (80) hide show
  1. package/dist/{aggregate-v_r-nZbH.d.ts → aggregate-CUirs7ka.d.ts} +1 -1
  2. package/dist/{chunk-UNEZF3ZP.js → chunk-5PCGMSDX.js} +209 -28
  3. package/dist/chunk-5PCGMSDX.js.map +1 -0
  4. package/dist/{chunk-JNWTHDGF.js → chunk-AOIVTOHX.js} +3 -3
  5. package/dist/{chunk-JNWTHDGF.js.map → chunk-AOIVTOHX.js.map} +1 -1
  6. package/dist/{chunk-FBMKI22S.js → chunk-ATVK3VYS.js} +3 -3
  7. package/dist/{chunk-FBMKI22S.js.map → chunk-ATVK3VYS.js.map} +1 -1
  8. package/dist/{chunk-NOPS5EIH.js → chunk-CJ5V6JES.js} +5 -114
  9. package/dist/chunk-CJ5V6JES.js.map +1 -0
  10. package/dist/{chunk-TWLPC4S3.js → chunk-DJRT4DUF.js} +3 -3
  11. package/dist/{chunk-TWLPC4S3.js.map → chunk-DJRT4DUF.js.map} +1 -1
  12. package/dist/{chunk-WNOCPV4A.js → chunk-DTVYCATJ.js} +3 -3
  13. package/dist/{chunk-WNOCPV4A.js.map → chunk-DTVYCATJ.js.map} +1 -1
  14. package/dist/chunk-LYNIHY3F.js +115 -0
  15. package/dist/chunk-LYNIHY3F.js.map +1 -0
  16. package/dist/{chunk-6B4CN2TC.js → chunk-OCMYW2YE.js} +3 -3
  17. package/dist/{chunk-6B4CN2TC.js.map → chunk-OCMYW2YE.js.map} +1 -1
  18. package/dist/{chunk-AQX5HQD6.js → chunk-OTUTSAZD.js} +3 -3
  19. package/dist/{chunk-AQX5HQD6.js.map → chunk-OTUTSAZD.js.map} +1 -1
  20. package/dist/{chunk-KRRESUXT.js → chunk-PH25HOAL.js} +6 -6
  21. package/dist/{chunk-KRRESUXT.js.map → chunk-PH25HOAL.js.map} +1 -1
  22. package/dist/{chunk-XIBQ5BTZ.js → chunk-RZVLUUMY.js} +4 -4
  23. package/dist/{chunk-XIBQ5BTZ.js.map → chunk-RZVLUUMY.js.map} +1 -1
  24. package/dist/{chunk-2ORQLYVW.js → chunk-SMEG63MO.js} +4 -4
  25. package/dist/{chunk-2ORQLYVW.js.map → chunk-SMEG63MO.js.map} +1 -1
  26. package/dist/{chunk-YMFJLBIZ.js → chunk-UKJCF2CM.js} +3 -3
  27. package/dist/{chunk-YMFJLBIZ.js.map → chunk-UKJCF2CM.js.map} +1 -1
  28. package/dist/{chunk-K33LWVUF.js → chunk-UKWM32CG.js} +3 -3
  29. package/dist/{chunk-K33LWVUF.js.map → chunk-UKWM32CG.js.map} +1 -1
  30. package/dist/csv.d.ts +1 -1
  31. package/dist/errors.js +2 -1
  32. package/dist/form-types.d.ts +1 -1
  33. package/dist/headless/index.d.ts +1 -1
  34. package/dist/hooks/index.d.ts +4 -4
  35. package/dist/hooks/index.js +13 -12
  36. package/dist/hooks/mutation-mode.d.ts +1 -1
  37. package/dist/hooks/mutation-mode.js +3 -2
  38. package/dist/hooks/related-keys.d.ts +1 -1
  39. package/dist/hooks/use-aggregate.d.ts +2 -2
  40. package/dist/hooks/use-board-columns.d.ts +1 -1
  41. package/dist/hooks/use-capabilities.d.ts +1 -1
  42. package/dist/hooks/use-infinite-resource.d.ts +1 -1
  43. package/dist/hooks/use-link-options.d.ts +1 -1
  44. package/dist/hooks/use-list-state.d.ts +3 -3
  45. package/dist/hooks/use-list-state.js +5 -4
  46. package/dist/hooks/use-live.d.ts +1 -1
  47. package/dist/hooks/use-one.d.ts +1 -1
  48. package/dist/hooks/use-relation-label.d.ts +1 -1
  49. package/dist/hooks/use-resource-form.d.ts +1 -1
  50. package/dist/hooks/use-resource-form.js +4 -3
  51. package/dist/hooks/use-resource.d.ts +1 -1
  52. package/dist/hooks/use-resource.js +4 -3
  53. package/dist/hooks/use-segment-counts.d.ts +2 -2
  54. package/dist/hooks/use-segment-counts.js +5 -4
  55. package/dist/hooks/use-view-board.d.ts +2 -2
  56. package/dist/hooks/use-view-board.js +8 -7
  57. package/dist/hooks/use-view-calendar-range.d.ts +2 -2
  58. package/dist/hooks/use-view-calendar-range.js +6 -5
  59. package/dist/hooks/use-write.d.ts +1 -1
  60. package/dist/index.d.ts +8 -8
  61. package/dist/index.js +15 -14
  62. package/dist/index.js.map +1 -1
  63. package/dist/provider/index.d.ts +7 -378
  64. package/dist/provider/index.js +3 -2
  65. package/dist/{write-outcome-DuwfsnyO.d.ts → read-outcome-Cq0h2oAG.d.ts} +31 -2
  66. package/dist/resource-view/index.d.ts +4 -4
  67. package/dist/resource-view/index.js +5 -4
  68. package/dist/resource-view/index.js.map +1 -1
  69. package/dist/{saved-views-C45lRm7i.d.ts → saved-views-Bcox3blZ.d.ts} +2 -2
  70. package/dist/schema/index.d.ts +3 -4
  71. package/dist/supabase-provider-D5ditkHi.d.ts +465 -0
  72. package/dist/testing/index.d.ts +87 -3
  73. package/dist/testing/index.js +88 -1
  74. package/dist/testing/index.js.map +1 -1
  75. package/dist/{types-CiQY6hUy.d.ts → types-BnOCVJzm.d.ts} +1 -1
  76. package/dist/{types-BAhcze_-.d.ts → types-CBtBvGw0.d.ts} +1 -1
  77. package/package.json +1 -1
  78. package/dist/chunk-NOPS5EIH.js.map +0 -1
  79. package/dist/chunk-UNEZF3ZP.js.map +0 -1
  80. package/dist/read-outcome-BnboMYOV.d.ts +0 -30
@@ -1,4 +1,4 @@
1
- import { A as AggregateParams, D as DataProvider, d as AggregateResult, k as AggregateMetric } from './types-CiQY6hUy.js';
1
+ import { A as AggregateParams, D as DataProvider, d as AggregateResult, k as AggregateMetric } from './types-BnOCVJzm.js';
2
2
 
3
3
  type Row = Record<string, unknown>;
4
4
  /**
@@ -1,5 +1,6 @@
1
1
  import { resolveAggregate } from './chunk-J54XXKQD.js';
2
- import { toDataWriteError, reportError, readOutcomeFromCode } from './chunk-NOPS5EIH.js';
2
+ import { reportError } from './chunk-CJ5V6JES.js';
3
+ import { toDataWriteError, readOutcomeFromCode } from './chunk-LYNIHY3F.js';
3
4
  import { DataReadError, readFailureMessage } from './chunk-HUNGCTRA.js';
4
5
  import { isDataWriteError, DataWriteError } from './chunk-WLDSIQJ2.js';
5
6
 
@@ -247,8 +248,8 @@ function createSupabaseProvider(client, options = {}) {
247
248
  const allowed = new Set(config.writeColumns);
248
249
  return Object.fromEntries(Object.entries(values).filter(([key]) => allowed.has(key)));
249
250
  }
250
- if (!config.source || id === void 0) return values;
251
- const row = await readBack(resource, id);
251
+ if (!config.source || id === void 0 || !tableAllowed(resource, "read")) return values;
252
+ const row = (await run(from(resource).select("*").eq("id", id)))[0];
252
253
  if (!row) return values;
253
254
  return Object.fromEntries(Object.entries(values).filter(([key]) => key in row));
254
255
  }
@@ -320,6 +321,104 @@ function createSupabaseProvider(client, options = {}) {
320
321
  }
321
322
  const configFor = (resource) => options.resources?.[resource] ?? options.resources?.[otherSpelling(resource)] ?? {};
322
323
  const nounFor = (resource) => configFor(resource).noun ?? "record";
324
+ const declared = options.access === "declared";
325
+ const anyActions = Object.values(options.resources ?? {}).some((r) => Object.keys(r.actions ?? {}).length > 0);
326
+ const warnedArgs = /* @__PURE__ */ new Set();
327
+ function warnArgsDropVersion(resource, use, call, contextAt) {
328
+ if (!call || typeof call === "string" || !call.args || !versionFor(resource)) return;
329
+ if (call.args.length >= contextAt) return;
330
+ const key = `${resource}\0${use}`;
331
+ if (warnedArgs.has(key)) return;
332
+ warnedArgs.add(key);
333
+ reportError(
334
+ new Error(
335
+ `[SupabaseProvider] "${resource}" has a version rule and its ${use} function's args takes no context. Take the context (argument ${contextAt}) and pass context.expectedVersion on as p_expected_version, or writes go unchecked.`
336
+ ),
337
+ { source: "core:versioned-writes", tags: { resource } }
338
+ );
339
+ }
340
+ function tableAllowed(resource, op) {
341
+ if (!declared) return true;
342
+ const table = configFor(resource).table;
343
+ if (!table) return false;
344
+ if (op === "read") return table.read === true;
345
+ return table.write === true || Array.isArray(table.write) && table.write.includes(op);
346
+ }
347
+ function undeclaredMessage(resource, op) {
348
+ const use = op === "read" ? "a `source` (a view, or a database function)" : `\`writes.${op}\` (a database function)`;
349
+ const optIn = op === "read" ? "read: true" : `write: ["${op}"]`;
350
+ return `[SupabaseProvider] "${resource}" declares no ${op === "read" ? "read" : op}. Give it ${use}, or opt in to its table with \`table: { ${optIn}, why: "\u2026" }\` (docs/DATA-ACCESS.md).`;
351
+ }
352
+ const readDeclared = (resource) => configFor(resource).source !== void 0 || tableAllowed(resource, "read");
353
+ async function assertReadDeclared(resource, operation) {
354
+ if (readDeclared(resource)) return;
355
+ await reportReadError(new DataReadError("forbidden", undeclaredMessage(resource, "read")), resource, operation);
356
+ }
357
+ function writeDeclared(resource, op) {
358
+ const config = configFor(resource);
359
+ if (config.writes?.[op]) return true;
360
+ if (op === "create" && config.create) return true;
361
+ if (op === "update" && config.update) return true;
362
+ return tableAllowed(resource, op);
363
+ }
364
+ function assertTableWrite(resource, op) {
365
+ if (tableAllowed(resource, op)) return;
366
+ throw new DataWriteError("forbidden", undeclaredMessage(resource, op));
367
+ }
368
+ function callFor(call, input, defaults) {
369
+ if (typeof call === "string") return { fn: call, args: defaults };
370
+ return { fn: call.fn, args: call.args ? call.args(...input) : defaults };
371
+ }
372
+ async function callWrite(resource, fn, args) {
373
+ if (!client.rpc) {
374
+ throw new DataWriteError("error", `[SupabaseProvider] "${resource}" writes through ${fn}(), but the client has no rpc.`);
375
+ }
376
+ let result;
377
+ try {
378
+ result = await client.rpc(fn, args);
379
+ } catch (error) {
380
+ throw toDataWriteError(error);
381
+ }
382
+ if (result.error) throw toDataWriteError(result.error);
383
+ if (Array.isArray(result.data)) return result.data.length > 0 ? result.data[0] : null;
384
+ return result.data;
385
+ }
386
+ const versionArgs = (expected) => expected === void 0 ? {} : { p_expected_version: expected };
387
+ async function readRecord(resource, id) {
388
+ if (!readDeclared(resource)) return void 0;
389
+ try {
390
+ return (await run(read(resource, void 0).eq("id", id)))[0];
391
+ } catch {
392
+ return void 0;
393
+ }
394
+ }
395
+ async function readAfterWrite(resource, id, throughFunction) {
396
+ if (declared || throughFunction) return readRecord(resource, id);
397
+ return readBack(resource, id).catch(() => void 0);
398
+ }
399
+ function createRule(resource) {
400
+ const config = configFor(resource);
401
+ if (config.create) return config.create;
402
+ const call = config.writes?.create;
403
+ if (!call) return void 0;
404
+ return async (row) => {
405
+ const { fn, args } = callFor(call, [row], { p_values: row });
406
+ const returned = await callWrite(resource, fn, args);
407
+ return returned;
408
+ };
409
+ }
410
+ function updateRule(resource) {
411
+ const config = configFor(resource);
412
+ if (config.update) return config.update;
413
+ const call = config.writes?.update;
414
+ if (!call) return void 0;
415
+ warnArgsDropVersion(resource, "update", call, 3);
416
+ return async (id, row, context) => {
417
+ const expected = context?.expectedVersion;
418
+ const { fn, args } = callFor(call, [id, row, context ?? {}], { p_id: id, p_values: row, ...versionArgs(expected) });
419
+ return await callWrite(resource, fn, args);
420
+ };
421
+ }
323
422
  const recentWrites = /* @__PURE__ */ new Map();
324
423
  function noteWrite(event) {
325
424
  const now = Date.now();
@@ -345,6 +444,7 @@ function createSupabaseProvider(client, options = {}) {
345
444
  }
346
445
  function realtimeEnabled(resource) {
347
446
  if (typeof client.channel !== "function") return false;
447
+ if (!readDeclared(resource)) return false;
348
448
  const own = configFor(resource).realtime;
349
449
  if (own !== void 0) return own;
350
450
  const all = options.realtime;
@@ -373,10 +473,21 @@ function createSupabaseProvider(client, options = {}) {
373
473
  return result.data == null ? [] : [result.data];
374
474
  }
375
475
  async function isVisible(resource, id) {
376
- return (await run(from(resource).select("id").eq("id", id))).length > 0;
476
+ if (!readDeclared(resource)) throw new DataWriteError("forbidden", undeclaredMessage(resource, "read"));
477
+ const query = tableAllowed(resource, "read") ? from(resource).select("id") : read(resource, "id");
478
+ return (await run(query.eq("id", id))).length > 0;
377
479
  }
378
480
  async function readBack(resource, id) {
379
- return (await run(from(resource).select("*").eq("id", id)))[0];
481
+ if (!readDeclared(resource)) throw new DataWriteError("forbidden", undeclaredMessage(resource, "read"));
482
+ const query = tableAllowed(resource, "read") ? from(resource).select("*") : read(resource, void 0);
483
+ return (await run(query.eq("id", id)))[0];
484
+ }
485
+ function unreadableNoRowsError(resource, verb) {
486
+ const done = verb === "change" ? "changed" : "deleted";
487
+ return new DataWriteError(
488
+ "forbidden",
489
+ `This ${nounFor(resource)} was not ${done}: you can't ${verb} it, it no longer exists, or someone changed it first.`
490
+ );
380
491
  }
381
492
  function goneError(resource) {
382
493
  return new DataWriteError(
@@ -385,6 +496,7 @@ function createSupabaseProvider(client, options = {}) {
385
496
  );
386
497
  }
387
498
  async function noRowsError(resource, id, verb) {
499
+ if (!readDeclared(resource)) return unreadableNoRowsError(resource, verb);
388
500
  let visible;
389
501
  try {
390
502
  visible = await isVisible(resource, id);
@@ -415,6 +527,7 @@ function createSupabaseProvider(client, options = {}) {
415
527
  }
416
528
  async function staleOrNoRowsError(resource, id, verb, expected, known) {
417
529
  if (expected === void 0) return noRowsError(resource, id, verb);
530
+ if (!readDeclared(resource)) return unreadableNoRowsError(resource, verb);
418
531
  const { field, kind } = versionFor(resource);
419
532
  let current = known;
420
533
  try {
@@ -551,6 +664,7 @@ function createSupabaseProvider(client, options = {}) {
551
664
  }
552
665
  const provider = {
553
666
  async getList(resource, params) {
667
+ await assertReadDeclared(resource, "getList");
554
668
  if (params.pagination && params.pagination.perPage > maxPerPage) {
555
669
  const { perPage } = params.pagination;
556
670
  await reportReadError(
@@ -620,6 +734,7 @@ function createSupabaseProvider(client, options = {}) {
620
734
  };
621
735
  },
622
736
  async aggregate(resource, params) {
737
+ await assertReadDeclared(resource, "getList");
623
738
  const entries = Object.entries(params.metrics);
624
739
  const counts = entries.filter(([, m]) => m.fn === "count");
625
740
  const others = entries.filter(([, m]) => m.fn !== "count");
@@ -676,11 +791,13 @@ function createSupabaseProvider(client, options = {}) {
676
791
  return isEstimate ? { values, isEstimate } : { values };
677
792
  },
678
793
  async getOne(resource, params) {
794
+ await assertReadDeclared(resource, "getOne");
679
795
  const result = await read(resource, params.select, void 0, params.scope).eq("id", params.id).single();
680
796
  await throwIfReadError(result, resource, "getOne");
681
797
  return { data: result.data };
682
798
  },
683
799
  async getMany(resource, params) {
800
+ await assertReadDeclared(resource, "getMany");
684
801
  if (params.ids.length === 0) return { data: [] };
685
802
  const result = await read(resource, void 0, void 0, params.scope).in("id", params.ids);
686
803
  await throwIfReadError(result, resource, "getMany");
@@ -696,8 +813,12 @@ function createSupabaseProvider(client, options = {}) {
696
813
  ...resource && versionFor(resource) ? { version: { ...versionFor(resource) } } : {},
697
814
  compositeKeys: false,
698
815
  multiSort: true,
699
- create: true,
700
- delete: true,
816
+ // A declared provider serves only the writes a resource declares.
817
+ create: resource ? writeDeclared(resource, "create") : true,
818
+ delete: resource ? writeDeclared(resource, "delete") : true,
819
+ // `runAction` serves the actions a resource declares. Said only when some resource declares
820
+ // one: a provider without any says nothing, as before, so an app's own runner still shows.
821
+ ...anyActions ? { actions: resource ? Object.keys(configFor(resource).actions ?? {}).length > 0 : true } : {},
701
822
  maxPerPage,
702
823
  softDelete: resource ? isBinTable(resource) : false,
703
824
  cursorPagination: resource ? configFor(resource).orderKey !== false : true,
@@ -709,7 +830,7 @@ function createSupabaseProvider(client, options = {}) {
709
830
  if (process.env.NODE_ENV !== "production" && !warnedRealtime.has(resource)) {
710
831
  warnedRealtime.add(resource);
711
832
  console.warn(
712
- typeof client.channel !== "function" ? `[SupabaseProvider] "${resource}" was subscribed to, but the client has no channel() (Supabase Realtime), so nothing will be reported.` : `[SupabaseProvider] "${resource}" was subscribed to, but realtime is off for it. Set resources.${resource}.realtime (or the realtime option) to true.`
833
+ !readDeclared(resource) ? `${undeclaredMessage(resource, "read")} Its changes aren't reported either.` : typeof client.channel !== "function" ? `[SupabaseProvider] "${resource}" was subscribed to, but the client has no channel() (Supabase Realtime), so nothing will be reported.` : `[SupabaseProvider] "${resource}" was subscribed to, but realtime is off for it. Set resources.${resource}.realtime (or the realtime option) to true.`
713
834
  );
714
835
  }
715
836
  return () => {
@@ -795,11 +916,11 @@ function createSupabaseProvider(client, options = {}) {
795
916
  };
796
917
  },
797
918
  async create(resource, params) {
798
- const row = await tableValues(
799
- resource,
800
- await prepare(resource, params.data, { resource, action: "create" })
801
- );
802
- const override = configFor(resource).create;
919
+ if (!writeDeclared(resource, "create")) throw new DataWriteError("forbidden", undeclaredMessage(resource, "create"));
920
+ const prepared = await prepare(resource, params.data, { resource, action: "create" });
921
+ const throughFunction = !configFor(resource).create && configFor(resource).writes?.create !== void 0;
922
+ const row = throughFunction ? { ...prepared } : await tableValues(resource, prepared);
923
+ const override = createRule(resource);
803
924
  let record;
804
925
  if (override) {
805
926
  let returned;
@@ -809,7 +930,7 @@ function createSupabaseProvider(client, options = {}) {
809
930
  throw toDataWriteError(error);
810
931
  }
811
932
  if (isIdentifier(returned)) {
812
- record = await readBack(resource, returned).catch(() => void 0) ?? { id: returned };
933
+ record = await readAfterWrite(resource, returned, throughFunction) ?? (declared || throughFunction ? { ...row, id: returned } : { id: returned });
813
934
  } else if (returned && typeof returned === "object" && isIdentifier(returned.id)) {
814
935
  record = returned;
815
936
  } else {
@@ -818,26 +939,36 @@ function createSupabaseProvider(client, options = {}) {
818
939
  `[SupabaseProvider] The create rule for "${resource}" returned neither the new row nor its id.`
819
940
  );
820
941
  }
821
- } else {
942
+ } else if (!declared) {
822
943
  const rows = await run(from(resource).insert(row).select("*").single());
823
944
  record = rows[0];
945
+ } else {
946
+ assertTableWrite(resource, "create");
947
+ const version = versionFor(resource);
948
+ const rows = await run(from(resource).insert(row).select(version ? `id,${version.field}` : "id").single());
949
+ const written = rows[0] ?? {};
950
+ const id = written.id;
951
+ if (!isIdentifier(id)) {
952
+ throw new DataWriteError("error", `[SupabaseProvider] The insert into "${resource}" returned no id.`);
953
+ }
954
+ record = await readRecord(resource, id) ?? { ...row, ...written, id };
955
+ if (version && record[version.field] == null && written[version.field] != null) {
956
+ record = { ...row, ...written, id };
957
+ }
824
958
  }
825
959
  await committed({ resource, kind: "create", id: record.id, record });
826
960
  return { data: record };
827
961
  },
828
962
  async update(resource, params) {
829
963
  const { id } = params;
830
- const row = {
831
- ...await tableValues(
832
- resource,
833
- await prepare(resource, params.data, { resource, action: "update", id }),
834
- id
835
- )
836
- };
964
+ if (!writeDeclared(resource, "update")) throw new DataWriteError("forbidden", undeclaredMessage(resource, "update"));
965
+ const throughFunction = !configFor(resource).update && configFor(resource).writes?.update !== void 0;
966
+ const prepared = await prepare(resource, params.data, { resource, action: "update", id });
967
+ const row = throughFunction ? { ...prepared } : { ...await tableValues(resource, prepared, id) };
837
968
  const version = versionFor(resource);
838
969
  const expected = expectedFor(resource, params.expectedVersion);
839
970
  if (version) delete row[version.field];
840
- const override = configFor(resource).update;
971
+ const override = updateRule(resource);
841
972
  let record;
842
973
  if (override && version && override.length < 3 && !warnedUncheckedOverride.has(resource)) {
843
974
  warnedUncheckedOverride.add(resource);
@@ -859,7 +990,7 @@ function createSupabaseProvider(client, options = {}) {
859
990
  if (result == null || result === false) throw await staleOrNoRowsError(resource, id, "change", expected);
860
991
  if (isIdentifier(result) || result === true) {
861
992
  const readId = result === true ? id : result;
862
- record = await readBack(resource, readId).catch(() => void 0) ?? { ...row, id: readId };
993
+ record = await readAfterWrite(resource, readId, throughFunction) ?? { ...row, id: readId };
863
994
  } else if (typeof result === "object") {
864
995
  record = { id, ...result };
865
996
  } else {
@@ -868,12 +999,30 @@ function createSupabaseProvider(client, options = {}) {
868
999
  `[SupabaseProvider] The update rule for "${resource}" returned neither the row, its id, nor nothing.`
869
1000
  );
870
1001
  }
871
- } else {
1002
+ } else if (!declared) {
872
1003
  let query = from(resource).update(row).eq("id", id);
873
1004
  if (expected !== void 0) query = query.eq(version.field, expected);
874
1005
  const rows = await run(query.select("*"));
875
1006
  if (rows.length === 0) throw await staleOrNoRowsError(resource, id, "change", expected);
876
1007
  record = rows[0];
1008
+ } else {
1009
+ assertTableWrite(resource, "update");
1010
+ const config = configFor(resource);
1011
+ if (config.source !== void 0 && !config.writeColumns && !tableAllowed(resource, "read")) {
1012
+ throw new DataWriteError(
1013
+ "error",
1014
+ `[SupabaseProvider] "${resource}" updates its table but reads ${typeof config.source === "string" ? config.source : `${config.source.rpc}()`}. Name the table's columns with \`writeColumns\`, or declare \`table: { read: true, \u2026 }\` (docs/DATA-ACCESS.md).`
1015
+ );
1016
+ }
1017
+ let query = from(resource).update(row).eq("id", id);
1018
+ if (expected !== void 0) query = query.eq(version.field, expected);
1019
+ const rows = await run(query.select(version ? `id,${version.field}` : "id"));
1020
+ if (rows.length === 0) throw await staleOrNoRowsError(resource, id, "change", expected);
1021
+ const written = rows[0];
1022
+ record = await readRecord(resource, id) ?? { ...row, ...written, id };
1023
+ if (version && record[version.field] == null && written[version.field] != null) {
1024
+ record = { ...row, ...written, id };
1025
+ }
877
1026
  }
878
1027
  await committed({ resource, kind: "update", id, record });
879
1028
  const newVersion = version && record[version.field] != null ? String(record[version.field]) : void 0;
@@ -883,7 +1032,19 @@ function createSupabaseProvider(client, options = {}) {
883
1032
  const { id } = params;
884
1033
  let deletedId = id;
885
1034
  const expected = expectedFor(resource, params.expectedVersion);
886
- if (isBinTable(resource)) {
1035
+ const deleteCall = configFor(resource).writes?.delete;
1036
+ if (deleteCall) {
1037
+ warnArgsDropVersion(resource, "delete", deleteCall, 2);
1038
+ const { fn, args } = callFor(deleteCall, [id, expected === void 0 ? {} : { expectedVersion: expected }], {
1039
+ p_id: id,
1040
+ ...versionArgs(expected)
1041
+ });
1042
+ const returned = await callWrite(resource, fn, args);
1043
+ if (returned == null || returned === false) throw await staleOrNoRowsError(resource, id, "delete", expected);
1044
+ const returnedId = isIdentifier(returned) ? returned : returned?.id;
1045
+ if (isIdentifier(returnedId)) deletedId = returnedId;
1046
+ } else if (isBinTable(resource)) {
1047
+ assertTableWrite(resource, "delete");
887
1048
  if (expected !== void 0) {
888
1049
  const current = await readBack(resource, id);
889
1050
  if (!current) throw goneError(resource);
@@ -911,6 +1072,7 @@ function createSupabaseProvider(client, options = {}) {
911
1072
  throw new DataWriteError("forbidden", `You can't delete this ${nounFor(resource)}.`);
912
1073
  }
913
1074
  } else {
1075
+ assertTableWrite(resource, "delete");
914
1076
  let query = from(resource).delete().eq("id", id);
915
1077
  if (expected !== void 0) query = query.eq(versionFor(resource).field, expected);
916
1078
  const rows = await run(query.select("id"));
@@ -921,6 +1083,24 @@ function createSupabaseProvider(client, options = {}) {
921
1083
  await committed({ resource, kind: "delete", id: deletedId });
922
1084
  return { data: { id: deletedId } };
923
1085
  },
1086
+ async runAction(resource, params) {
1087
+ const { id, action } = params;
1088
+ const call = configFor(resource).actions?.[action];
1089
+ if (!call) {
1090
+ throw new DataWriteError("invalid", `[SupabaseProvider] "${resource}" declares no action "${action}".`);
1091
+ }
1092
+ warnArgsDropVersion(resource, `action "${action}"`, call, 2);
1093
+ const expected = expectedFor(resource, params.expectedVersion);
1094
+ const { fn, args } = callFor(call, [id, expected === void 0 ? {} : { expectedVersion: expected }], {
1095
+ p_id: id,
1096
+ ...versionArgs(expected)
1097
+ });
1098
+ const returned = await callWrite(resource, fn, args);
1099
+ if (returned == null || returned === false) throw await staleOrNoRowsError(resource, id, "change", expected);
1100
+ const data = returned !== null && typeof returned === "object" ? { id, ...returned } : await readRecord(resource, isIdentifier(returned) ? returned : id) ?? null;
1101
+ await committed({ resource, kind: "update", id, ...data ? { record: data } : {} });
1102
+ return { data };
1103
+ },
924
1104
  toFormValues(resource, record) {
925
1105
  const map = configFor(resource).toFormValues;
926
1106
  return map ? map(record) : record;
@@ -931,6 +1111,7 @@ function createSupabaseProvider(client, options = {}) {
931
1111
  return typeof keys === "function" ? keys(event) : keys;
932
1112
  }
933
1113
  };
1114
+ if (!anyActions) delete provider.runAction;
934
1115
  Object.defineProperty(provider, "__recentWriteCount", { value: () => recentWrites.size, enumerable: false });
935
1116
  return provider;
936
1117
  }
@@ -998,5 +1179,5 @@ async function createOrAdopt(provider, resource, data, options) {
998
1179
  }
999
1180
 
1000
1181
  export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider };
1001
- //# sourceMappingURL=chunk-UNEZF3ZP.js.map
1002
- //# sourceMappingURL=chunk-UNEZF3ZP.js.map
1182
+ //# sourceMappingURL=chunk-5PCGMSDX.js.map
1183
+ //# sourceMappingURL=chunk-5PCGMSDX.js.map