( name: string, columns: TColumns, uniqueKey: readonly string[], )
| 53 | |
| 54 | /** A tenant-shared table (catalog / blobs) — partitioned only by `tenant`. */ |
| 55 | const 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. */ |
no test coverage detected