MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / tenantExecutorTable

Function tenantExecutorTable

packages/core/sdk/src/core-schema.ts:55–81  ·  view source on GitHub ↗
(
  name: string,
  columns: TColumns,
  uniqueKey: readonly string[],
)

Source from the content-addressed store, hash-verified

53
54/** A tenant-shared table (catalog / blobs) — partitioned only by `tenant`. */
55const tenantExecutorTable = <const TColumns extends UserColumns>(
56 name: string,
57 columns: TColumns,
58 uniqueKey: readonly string[],
59) => {
60 const out = table(name, {
61 ...columns,
62 row_id: idColumn("row_id", "varchar(255)").defaultTo$("auto"),
63 tenant: keyColumn("tenant"),
64 });
65 out.unique(`${name}_uidx`, [...uniqueKey]);
66 return out.policy<ExecutorOwnerPolicyContext>({
67 name: executorTenantPolicyName,
68 onRead: ({ builder, context }) => builder("tenant", "=", context.tenant),
69 onCreate: ({ values, context }) => {
70 if (values.tenant !== context.tenant) {
71 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: FumaDB table policy callbacks are promise callbacks, not Effect effects
72 throw new StorageError({
73 message: `Storage write on table "${name}" is outside the executor tenant.`,
74 cause: undefined,
75 });
76 }
77 },
78 onUpdate: ({ builder, context }) => builder("tenant", "=", context.tenant),
79 onDelete: ({ builder, context }) => builder("tenant", "=", context.tenant),
80 });
81};
82
83/** An owner-scoped table — partitioned by `(tenant, owner, subject)`, guarded by
84 * the executor owner policy. `uniqueKey` must include those three columns. */

Callers 1

core-schema.tsFile · 0.85

Calls 7

tableFunction · 0.90
idColumnFunction · 0.90
keyColumnFunction · 0.85
builderFunction · 0.85
policyMethod · 0.80
uniqueMethod · 0.65
defaultTo$Method · 0.45

Tested by

no test coverage detected