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

Function ownedExecutorTable

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

Source from the content-addressed store, hash-verified

83/** An owner-scoped table — partitioned by `(tenant, owner, subject)`, guarded by
84 * the executor owner policy. `uniqueKey` must include those three columns. */
85const ownedExecutorTable = <const TColumns extends UserColumns>(
86 name: string,
87 columns: TColumns,
88 uniqueKey: readonly string[],
89) => {
90 const out = table(name, {
91 ...columns,
92 row_id: idColumn("row_id", "varchar(255)").defaultTo$("auto"),
93 tenant: keyColumn("tenant"),
94 owner: keyColumn("owner"),
95 subject: keyColumn("subject"),
96 });
97 out.unique(`${name}_uidx`, [...uniqueKey]);
98 return out.policy<ExecutorOwnerPolicyContext>({
99 name: executorOwnerPolicyName,
100 onRead: ({ builder, context }) => ownerVisibility(builder, context),
101 onCreate: ({ values, context }) => assertOwnerWritable(name, values, context),
102 onUpdate: ({ builder, set, create, context }) => {
103 assertOwnerPatch(name, set, context);
104 assertOwnerPatch(name, create, context);
105 return ownerVisibility(builder, context);
106 },
107 onDelete: ({ builder, context }) => ownerVisibility(builder, context),
108 });
109};
110
111const defineTables = <const TTables extends Record<string, AnyTable>>(tables: TTables): TTables =>
112 tables;

Callers 1

core-schema.tsFile · 0.85

Calls 9

tableFunction · 0.90
idColumnFunction · 0.90
assertOwnerWritableFunction · 0.90
assertOwnerPatchFunction · 0.90
keyColumnFunction · 0.85
ownerVisibilityFunction · 0.85
policyMethod · 0.80
uniqueMethod · 0.65
defaultTo$Method · 0.45

Tested by

no test coverage detected