better-supabase 0.1.0 → 0.2.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/bin/better-supabase.js +2 -1
- package/dist/claims-CoTobNC-.js +25 -0
- package/dist/cli/bin.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/{cli-CoByWYja.js → cli-DrSgDOQC.js} +333 -159
- package/dist/client/index.d.ts +1 -1
- package/dist/{compiler-DL18ukPe.d.ts → compiler-CZ9nIuqy.d.ts} +2 -2
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +2 -2
- package/dist/{config-D-aR2ZoN.js → config-ClDXmVtY.js} +11 -10
- package/dist/{define-QGkq04oe.js → define-BXMYD9AY.js} +65 -62
- package/dist/{define-CTfWw-SS.d.ts → define-e3zI4_4g.d.ts} +27 -10
- package/dist/edge/index.d.ts +4 -4
- package/dist/edge/index.js +3 -3
- package/dist/entitlements-CTEBm7IB.js +20 -0
- package/dist/entitlements-Dng-ctuT.d.ts +42 -0
- package/dist/events/index.d.ts +1 -1
- package/dist/{events-2OJsVG_d.d.ts → events-DOt3nSO-.d.ts} +2 -2
- package/dist/{executor-Bje4suQF.d.ts → executor-BYXQ9AGn.d.ts} +1 -1
- package/dist/{executor-Bazhgsgq.d.ts → executor-CGdNQ27g.d.ts} +1 -1
- package/dist/{executor-Ceq60hPM.js → executor-DeppvirK.js} +1 -1
- package/dist/guards-BnzDvFrz.js +10 -0
- package/dist/hono/index.d.ts +5 -5
- package/dist/hono/index.js +3 -3
- package/dist/{index-JXHBuS53.d.ts → index-Bw1bwtC0.d.ts} +3 -3
- package/dist/{index-Hf8PP9sP.d.ts → index-CBDufH1M.d.ts} +15 -11
- package/dist/{index-cEeweTeM.d.ts → index-CG69s15v.d.ts} +3 -3
- package/dist/{index-DQVvHzjW.d.ts → index-Ciu5Xlml.d.ts} +3 -3
- package/dist/{index-Sw43J8HG.d.ts → index-D4v7sncu.d.ts} +6 -6
- package/dist/{index-BD6wKthp.d.ts → index-DOsjFvMf.d.ts} +28 -7
- package/dist/{index-DRid0qIv.d.ts → index-DbxFr7XG.d.ts} +2 -2
- package/dist/{index-Nxo3TJcm.d.ts → index-DuP14VHo.d.ts} +11 -3
- package/dist/{index-Dup-nSe9.d.ts → index-K-3WM2Hp.d.ts} +2 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +7 -6
- package/dist/jobs/index.d.ts +1 -1
- package/dist/jobs/index.js +6 -5
- package/dist/{json-schema-BbwO2mZg.js → json-schema-BpYqkCKf.js} +2 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/{live-6b9i72Ux.d.ts → live-DJyZMD6w.d.ts} +14 -3
- package/dist/logger-glM28NVN.js +21 -0
- package/dist/mcp/index.d.ts +41 -4
- package/dist/mcp/index.js +194 -61
- package/dist/{mfa-CpogP66z.js → mfa-CpLfJSde.js} +23 -3
- package/dist/next/index.d.ts +23 -23
- package/dist/next/index.js +9 -8
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +3 -3
- package/dist/orpc/index.d.ts +4 -4
- package/dist/orpc/index.js +2 -2
- package/dist/otel/index.d.ts +3 -3
- package/dist/otel/index.js +1 -1
- package/dist/{template-BeOGnynM.js → permdock-sql-CghlHPuH.js} +25 -1
- package/dist/{plugin-HvGqCurB.d.ts → plugin-C4TR9J0Z.d.ts} +2 -2
- package/dist/plugins/actor/index.d.ts +1 -1
- package/dist/plugins/rules/index.d.ts +4 -3
- package/dist/plugins/rules/index.js +4 -11
- package/dist/plugins/soft-delete/index.d.ts +2 -2
- package/dist/plugins/tenant/index.d.ts +10 -4
- package/dist/plugins/tenant/index.js +15 -13
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/validation/index.d.ts +1 -1
- package/dist/{pool-BFeqzwQS.d.ts → pool-R2m_DkXi.d.ts} +1 -1
- package/dist/postgres/index.d.ts +4 -4
- package/dist/postgres/index.js +2 -2
- package/dist/{postgrest-Dm-vhY6R.d.ts → postgrest-cAEQ_IQN.d.ts} +1 -1
- package/dist/{problem-DPu6Fh-t.js → problem-BTkTtRV9.js} +4 -4
- package/dist/query/index.d.ts +1 -1
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +3 -3
- package/dist/react/server.d.ts +5 -5
- package/dist/react/server.js +1 -1
- package/dist/react/session.d.ts +1 -1
- package/dist/react/session.js +1 -1
- package/dist/{react-CrOvrnIP.js → react-C83BdBGt.js} +9 -8
- package/dist/{read-set-DhX2d04c.js → read-set-4lI3W_gZ.js} +1 -1
- package/dist/realtime/index.d.ts +3 -2
- package/dist/realtime/index.js +26 -11
- package/dist/{resolve-DW8h9NPm.d.ts → resolve-CjHILk2w.d.ts} +21 -6
- package/dist/{resource-CYiu6Ygi.js → resource-BHEWmQJK.js} +1 -1
- package/dist/{resource-SkPTRJDD.d.ts → resource-CgZa3YG_.d.ts} +4 -4
- package/dist/{respond-4-dhoV7x.js → respond-DMcbQwfN.js} +7 -4
- package/dist/{respond-PoTpy5DT.d.ts → respond-Dne1ARSa.d.ts} +14 -14
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +5 -5
- package/dist/{session-C3osL21k.d.ts → session-C3LxnQ0e.d.ts} +4 -3
- package/dist/{session-CD-3orO_.js → session-CqEwzVup.js} +2 -1
- package/dist/{simplify-oHiDKRVQ.js → simplify-bwJpLnaS.js} +12 -12
- package/dist/{spec-pins-t6sPaHvl.js → spec-pins-C3oc-Tdp.js} +1 -1
- package/dist/{spec-pins-CJPVghHy.d.ts → spec-pins-CqorWDnO.d.ts} +1 -1
- package/dist/{sql-M8l3fnS0.js → sql-DTjA1LPj.js} +1 -1
- package/dist/ssr/index.d.ts +5 -5
- package/dist/ssr/index.js +3 -3
- package/dist/{stats-3iy8u3_P.js → stats-C5W-rBfR.js} +1 -1
- package/dist/storage/index.d.ts +3 -2
- package/dist/storage/index.js +1 -1
- package/dist/{storage-BWXVUXGk.js → storage-DuGn38fr.js} +72 -6
- package/dist/testing/index.d.ts +46 -15
- package/dist/testing/index.js +111 -43
- package/dist/{types-C2fslP1z.d.ts → types-C83v5SQz.d.ts} +55 -2
- package/dist/{view-B0ltUmTi.d.ts → view-D1s0wa0T.d.ts} +9 -3
- package/dist/{view-B6F9QbG-.js → view-aOYizTeE.js} +2 -1
- package/dist/webhooks/index.d.ts +3 -3
- package/dist/webhooks/index.js +1 -1
- package/dist/{webhooks-DbMTJJX2.js → webhooks-DMipjhSP.js} +1 -1
- package/package.json +8 -4
- package/schemas/config-v1.json +49 -4
- package/schemas/doctor-report-v1.json +1 -0
- package/schemas/snapshot-v2.json +4 -0
- package/skills/better-supabase/references/plugins.md +9 -0
- package/skills/better-supabase-api/SKILL.md +2 -2
- package/skills/better-supabase-testing/SKILL.md +4 -3
- package/dist/entitlements-BBg61DQZ.d.ts +0 -20
- package/dist/entitlements-BC_khwRy.js +0 -17
package/dist/client/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as BrowserOptions, i as BrowserAuth, n as AuthUser, o as createBrowser, r as BetterBrowser, t as AuthSnapshot } from "../index-
|
|
1
|
+
import { a as BrowserOptions, i as BrowserAuth, n as AuthUser, o as createBrowser, r as BetterBrowser, t as AuthSnapshot } from "../index-D4v7sncu.js";
|
|
2
2
|
export { AuthSnapshot, AuthUser, BetterBrowser, BrowserAuth, BrowserOptions, createBrowser };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as Operation } from "./executor-
|
|
2
|
-
import { i as PostgrestPlan } from "./postgrest-
|
|
1
|
+
import { g as Operation } from "./executor-CGdNQ27g.js";
|
|
2
|
+
import { i as PostgrestPlan } from "./postgrest-cAEQ_IQN.js";
|
|
3
3
|
//#region src/core/compiler.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Turns an IR operation into something a backend runs. An `Executor` for a
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
export { ActorConfig, BetterSupabaseConfig, BucketConfig, CONFIG_SCHEMA_URL, type Casing, CodecsConfig, DoctorConfig, EntitlementsConfig, ExposeConfig, GeneratedFile, Generator, GeneratorInput, type JsonSchemaGeneratorOptions, JsonSchemaSource, JsonTypeConfig, OpenApiConfig, PluginFlagsConfig, Privilege, RealtimeConfig, ResolvedConfig, ResolvedExpose, SeedConfig, SoftDeleteConfig, SourceConfig, SqlConfig, TableConfig, TenantConfig, TimestampsConfig, type ValibotGeneratorOptions, VectorDistance, VectorSearchConfig, type ZodGeneratorOptions, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, valibot, zod };
|
|
1
|
+
import { A as defineConfig, C as SourceConfig, D as TimestampsConfig, E as TenantConfig, F as ValibotGeneratorOptions, I as valibot, L as JsonSchemaGeneratorOptions, M as resolveJsonSchema, N as ZodGeneratorOptions, O as VectorDistance, P as zod, R as buildJsonSchema, S as SoftDeleteConfig, T as TableConfig, _ as Privilege, a as ClaimsConfig, b as ResolvedExpose, c as EntitlementsConfig, d as Generator, f as GeneratorInput, g as PluginFlagsConfig, h as OpenApiConfig, i as CONFIG_SCHEMA_URL, j as resolveConfig, k as VectorSearchConfig, l as ExposeConfig, m as JsonTypeConfig, n as BetterSupabaseConfig, o as CodecsConfig, p as JsonSchemaSource, r as BucketConfig, s as DoctorConfig, t as ActorConfig, u as GeneratedFile, v as RealtimeConfig, w as SqlConfig, x as SeedConfig, y as ResolvedConfig, z as jsonSchema } from "../index-DOsjFvMf.js";
|
|
2
|
+
import { a as Casing } from "../types-C83v5SQz.js";
|
|
3
|
+
export { ActorConfig, BetterSupabaseConfig, BucketConfig, CONFIG_SCHEMA_URL, type Casing, ClaimsConfig, CodecsConfig, DoctorConfig, EntitlementsConfig, ExposeConfig, GeneratedFile, Generator, GeneratorInput, type JsonSchemaGeneratorOptions, JsonSchemaSource, JsonTypeConfig, OpenApiConfig, PluginFlagsConfig, Privilege, RealtimeConfig, ResolvedConfig, ResolvedExpose, SeedConfig, SoftDeleteConfig, SourceConfig, SqlConfig, TableConfig, TenantConfig, TimestampsConfig, type ValibotGeneratorOptions, VectorDistance, VectorSearchConfig, type ZodGeneratorOptions, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, valibot, zod };
|
package/dist/config/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as jsonSchema, t as buildJsonSchema } from "../json-schema-
|
|
2
|
-
import { a as zod, i as resolveJsonSchema, n as defineConfig, o as valibot, r as resolveConfig, t as CONFIG_SCHEMA_URL } from "../config-
|
|
1
|
+
import { n as jsonSchema, t as buildJsonSchema } from "../json-schema-BpYqkCKf.js";
|
|
2
|
+
import { a as zod, i as resolveJsonSchema, n as defineConfig, o as valibot, r as resolveConfig, t as CONFIG_SCHEMA_URL } from "../config-ClDXmVtY.js";
|
|
3
3
|
export { CONFIG_SCHEMA_URL, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, valibot, zod };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as DEFAULT_CLAIMS } from "./claims-CoTobNC-.js";
|
|
2
|
+
import { a as parseImport, c as schemaName, d as variantsFor, i as fieldsFor, l as siblingPath, o as propertyKey, r as HEADER, s as rowType, u as tableEntries } from "./json-schema-BpYqkCKf.js";
|
|
2
3
|
//#region src/generators/valibot.ts
|
|
3
4
|
function scalar$1(kind) {
|
|
4
5
|
switch (kind.kind) {
|
|
@@ -18,8 +19,7 @@ function scalar$1(kind) {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
function field$1(table, plan, jsonImports) {
|
|
21
|
-
|
|
22
|
-
let expr = imported ? imported : plan.customJson ? `v.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(v.string() as unknown as v.GenericSchema<${rowType(table, plan)}>)` : scalar$1(plan.scalar);
|
|
22
|
+
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `v.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(v.string() as unknown as v.GenericSchema<${rowType(table, plan)}>)` : scalar$1(plan.scalar));
|
|
23
23
|
if (plan.column.array) expr = `v.array(${expr})`;
|
|
24
24
|
if (plan.nullable) expr = `v.nullable(${expr})`;
|
|
25
25
|
if (plan.optional) expr = `v.exactOptional(${expr})`;
|
|
@@ -96,8 +96,7 @@ function scalar(kind) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
function field(table, plan, jsonImports) {
|
|
99
|
-
|
|
100
|
-
let expr = imported ? imported : plan.customJson ? `z.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(z.string() as unknown as z.ZodType<${rowType(table, plan)}>)` : scalar(plan.scalar);
|
|
99
|
+
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `z.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(z.string() as unknown as z.ZodType<${rowType(table, plan)}>)` : scalar(plan.scalar));
|
|
101
100
|
if (plan.column.array) expr = `z.array(${expr})`;
|
|
102
101
|
if (plan.nullable) expr = `${expr}.nullable()`;
|
|
103
102
|
if (plan.optional) expr = `${expr}.exactOptional()`;
|
|
@@ -236,15 +235,16 @@ function resolveConfig(config, root) {
|
|
|
236
235
|
updatedAt: "updated_at"
|
|
237
236
|
}),
|
|
238
237
|
softDelete: pick(config.plugins?.softDelete, { column: "deleted_at" }),
|
|
239
|
-
tenant: pick(config.plugins?.tenant, {
|
|
240
|
-
column: "organization_id",
|
|
241
|
-
claim: "org_id"
|
|
242
|
-
}),
|
|
238
|
+
tenant: pick(config.plugins?.tenant, { column: "organization_id" }),
|
|
243
239
|
actor: pick(config.plugins?.actor, {
|
|
244
240
|
createdBy: "created_by",
|
|
245
241
|
updatedBy: "updated_by"
|
|
246
242
|
})
|
|
247
243
|
},
|
|
244
|
+
claims: {
|
|
245
|
+
...DEFAULT_CLAIMS,
|
|
246
|
+
...config.claims
|
|
247
|
+
},
|
|
248
248
|
buckets: config.buckets ?? {},
|
|
249
249
|
topics: config.topics ?? {},
|
|
250
250
|
realtime: { tables: config.realtime?.tables ?? [] },
|
|
@@ -268,7 +268,8 @@ function resolveConfig(config, root) {
|
|
|
268
268
|
ignore: config.doctor?.ignore ?? [],
|
|
269
269
|
strict: config.doctor?.strict ?? false,
|
|
270
270
|
sources: config.doctor?.sources ?? ["src/**/*.{ts,tsx}"],
|
|
271
|
-
policyHelperLimit: config.doctor?.policyHelperLimit ?? 5
|
|
271
|
+
policyHelperLimit: config.doctor?.policyHelperLimit ?? 5,
|
|
272
|
+
...config.doctor?.claimsLimit === void 0 ? {} : { claimsLimit: config.doctor.claimsLimit }
|
|
272
273
|
}
|
|
273
274
|
};
|
|
274
275
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { n as dbError, t as DbException } from "./errors-Bl3rkOzo.js";
|
|
2
|
-
import { a as invalidRequest, c as needsDecoding, o as decodeRows, r as IrBuilder, s as encodeValue } from "./simplify-
|
|
2
|
+
import { a as invalidRequest, c as needsDecoding, o as decodeRows, r as IrBuilder, s as encodeValue } from "./simplify-bwJpLnaS.js";
|
|
3
3
|
import { i as or, t as and } from "./types-6cYK9pbJ.js";
|
|
4
4
|
import { i as ok, n as err, o as toDbError, s as withErrorMapper, t as AsyncResult } from "./result-DWXatkd6.js";
|
|
5
5
|
import { t as invalidationTargets } from "./tables-rZxRxNPW.js";
|
|
6
|
+
import { t as consoleLogger } from "./logger-glM28NVN.js";
|
|
6
7
|
import { r as orderPlugins } from "./plugin-BqR6wKMB.js";
|
|
7
|
-
import { a as postgrestExecutor, n as StatsRecorder, r as recordStats } from "./stats-
|
|
8
|
-
import { d as isQuerySpec, f as specTables, n as checkParams, o as isReadSet, r as containsPlaceholder, t as bindParams, u as createSpecs } from "./read-set-
|
|
8
|
+
import { a as postgrestExecutor, n as StatsRecorder, r as recordStats } from "./stats-C5W-rBfR.js";
|
|
9
|
+
import { d as isQuerySpec, f as specTables, n as checkParams, o as isReadSet, r as containsPlaceholder, t as bindParams, u as createSpecs } from "./read-set-4lI3W_gZ.js";
|
|
9
10
|
import { t as validate } from "./standard-FUi3Z3-7.js";
|
|
10
11
|
//#region src/core/batch.ts
|
|
11
12
|
/**
|
|
@@ -91,26 +92,6 @@ function memoryCache() {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
//#endregion
|
|
94
|
-
//#region src/core/logger.ts
|
|
95
|
-
const log = (method) => (message, fields) => {
|
|
96
|
-
if (fields === void 0) console[method](`better-supabase: ${message}`);
|
|
97
|
-
else console[method](`better-supabase: ${message}`, fields);
|
|
98
|
-
};
|
|
99
|
-
/** The default: `console`, with a `better-supabase:` prefix. */
|
|
100
|
-
const consoleLogger = {
|
|
101
|
-
debug: log("debug"),
|
|
102
|
-
info: log("info"),
|
|
103
|
-
warn: log("warn"),
|
|
104
|
-
error: log("error")
|
|
105
|
-
};
|
|
106
|
-
const noop = () => {};
|
|
107
|
-
const silentLogger = {
|
|
108
|
-
debug: noop,
|
|
109
|
-
info: noop,
|
|
110
|
-
warn: noop,
|
|
111
|
-
error: noop
|
|
112
|
-
};
|
|
113
|
-
//#endregion
|
|
114
95
|
//#region src/core/events.ts
|
|
115
96
|
/**
|
|
116
97
|
* Observers only: a handler that throws is reported to the logger and never
|
|
@@ -208,7 +189,7 @@ function optionsOf(args) {
|
|
|
208
189
|
return options;
|
|
209
190
|
}
|
|
210
191
|
function signalOf(args) {
|
|
211
|
-
const signal = args?.signal;
|
|
192
|
+
const signal = args?.["signal"];
|
|
212
193
|
return signal instanceof AbortSignal ? signal : void 0;
|
|
213
194
|
}
|
|
214
195
|
function mutationKind(op) {
|
|
@@ -315,21 +296,21 @@ var OperationRunner = class {
|
|
|
315
296
|
/** Creates the runtime repository object for one table. */
|
|
316
297
|
function createRepository(runner, table) {
|
|
317
298
|
const { builder } = runner.runtime;
|
|
318
|
-
const selection = (args) => builder.selection(table, args?.select, args?.include);
|
|
299
|
+
const selection = (args) => builder.selection(table, args?.["select"], args?.["include"]);
|
|
319
300
|
const selectOp = (args, patch = {}) => ({
|
|
320
301
|
kind: "select",
|
|
321
302
|
table,
|
|
322
303
|
selection: selection(args),
|
|
323
|
-
where: builder.where(table, args?.where),
|
|
324
|
-
orderBy: builder.orderBy(table, args?.orderBy),
|
|
325
|
-
limit: typeof args?.limit === "number" ? args
|
|
326
|
-
offset: typeof args?.offset === "number" ? args
|
|
304
|
+
where: builder.where(table, args?.["where"]),
|
|
305
|
+
orderBy: builder.orderBy(table, args?.["orderBy"]),
|
|
306
|
+
limit: typeof args?.["limit"] === "number" ? args["limit"] : void 0,
|
|
307
|
+
offset: typeof args?.["offset"] === "number" ? args["offset"] : void 0,
|
|
327
308
|
count: void 0,
|
|
328
309
|
head: false,
|
|
329
310
|
single: void 0,
|
|
330
311
|
...patch
|
|
331
312
|
});
|
|
332
|
-
const returning = (args) => args?.returning === false ? void 0 : selection(args);
|
|
313
|
+
const returning = (args) => args?.["returning"] === false ? void 0 : selection(args);
|
|
333
314
|
const run = (op, args) => runner.run(op, optionsOf(args), signalOf(args));
|
|
334
315
|
const notFound = () => runner.fail(table, dbError("not_found", `No ${table.key} row matched`));
|
|
335
316
|
const base = {
|
|
@@ -358,7 +339,7 @@ function createRepository(runner, table) {
|
|
|
358
339
|
findUnique(args) {
|
|
359
340
|
return AsyncResult.from(async () => {
|
|
360
341
|
const op = selectOp(args, {
|
|
361
|
-
where: builder.uniqueKey(table, args
|
|
342
|
+
where: builder.uniqueKey(table, args["where"]),
|
|
362
343
|
limit: 1
|
|
363
344
|
});
|
|
364
345
|
const result = await run(op, args);
|
|
@@ -379,8 +360,8 @@ function createRepository(runner, table) {
|
|
|
379
360
|
},
|
|
380
361
|
count(args) {
|
|
381
362
|
return AsyncResult.from(async () => {
|
|
382
|
-
const mode = args?.mode;
|
|
383
|
-
const op = selectOp({ where: args?.where }, {
|
|
363
|
+
const mode = args?.["mode"];
|
|
364
|
+
const op = selectOp({ where: args?.["where"] }, {
|
|
384
365
|
selection: {
|
|
385
366
|
columns: [],
|
|
386
367
|
includes: []
|
|
@@ -395,28 +376,28 @@ function createRepository(runner, table) {
|
|
|
395
376
|
aggregate(args) {
|
|
396
377
|
return AsyncResult.from(async () => {
|
|
397
378
|
const aggregation = builder.aggregation(table, args);
|
|
398
|
-
const orderBy = builder.orderBy(table, args
|
|
379
|
+
const orderBy = builder.orderBy(table, args["orderBy"]);
|
|
399
380
|
const grouped = new Set(aggregation.columns.map((c) => c.column));
|
|
400
381
|
const loose = orderBy.find((term) => !grouped.has(term.column));
|
|
401
382
|
if (loose) return runner.fail(table, dbError("invalid_request", `aggregate on "${table.key}" can only sort by groupBy columns, not "${loose.column}"`));
|
|
402
383
|
const op = selectOp({
|
|
403
|
-
where: args
|
|
404
|
-
limit: args
|
|
405
|
-
offset: args
|
|
384
|
+
where: args["where"],
|
|
385
|
+
limit: args["limit"],
|
|
386
|
+
offset: args["offset"]
|
|
406
387
|
}, {
|
|
407
388
|
selection: aggregation,
|
|
408
389
|
orderBy
|
|
409
390
|
});
|
|
410
391
|
const result = await run(op, args);
|
|
411
392
|
if (!result.ok) return result;
|
|
412
|
-
if (args
|
|
393
|
+
if (args["groupBy"] !== void 0) return ok(result.data.rows);
|
|
413
394
|
return ok(result.data.rows[0] ?? decodeRows(aggregation, [{}])[0] ?? {});
|
|
414
395
|
});
|
|
415
396
|
},
|
|
416
397
|
exists(args) {
|
|
417
398
|
return AsyncResult.from(async () => {
|
|
418
399
|
const columns = table.primaryKey.slice(0, 1).map((alias) => builder.selectColumn(table, alias));
|
|
419
|
-
const op = selectOp({ where: args?.where }, {
|
|
400
|
+
const op = selectOp({ where: args?.["where"] }, {
|
|
420
401
|
selection: {
|
|
421
402
|
columns,
|
|
422
403
|
includes: []
|
|
@@ -435,21 +416,21 @@ function createRepository(runner, table) {
|
|
|
435
416
|
const op = insertOp([data], args, void 0);
|
|
436
417
|
const result = await run(op, args);
|
|
437
418
|
if (!result.ok) return result;
|
|
438
|
-
return ok(args?.returning === false ? null : result.data.rows[0] ?? null);
|
|
419
|
+
return ok(args?.["returning"] === false ? null : result.data.rows[0] ?? null);
|
|
439
420
|
});
|
|
440
421
|
},
|
|
441
422
|
createMany(rows, args) {
|
|
442
423
|
return AsyncResult.from(async () => {
|
|
443
|
-
if (rows.length === 0) return ok(args?.returning === false ? { count: 0 } : []);
|
|
424
|
+
if (rows.length === 0) return ok(args?.["returning"] === false ? { count: 0 } : []);
|
|
444
425
|
const result = await run(insertOp(rows, args, void 0), args);
|
|
445
426
|
if (!result.ok) return result;
|
|
446
|
-
return ok(args?.returning === false ? { count: result.data.count ?? rows.length } : result.data.rows);
|
|
427
|
+
return ok(args?.["returning"] === false ? { count: result.data.count ?? rows.length } : result.data.rows);
|
|
447
428
|
});
|
|
448
429
|
},
|
|
449
430
|
update(id, patch, args) {
|
|
450
431
|
return AsyncResult.from(async () => {
|
|
451
432
|
const key = builder.primaryKey(table, id);
|
|
452
|
-
const expect = args?.expect ? builder.where(table, args
|
|
433
|
+
const expect = args?.["expect"] ? builder.where(table, args["expect"]) : void 0;
|
|
453
434
|
const op = {
|
|
454
435
|
kind: "update",
|
|
455
436
|
table,
|
|
@@ -481,8 +462,8 @@ function createRepository(runner, table) {
|
|
|
481
462
|
const op = {
|
|
482
463
|
kind: "update",
|
|
483
464
|
table,
|
|
484
|
-
set: builder.row(table, args
|
|
485
|
-
where: builder.where(table, args
|
|
465
|
+
set: builder.row(table, args["data"], "update"),
|
|
466
|
+
where: builder.where(table, args["where"]),
|
|
486
467
|
returning: void 0
|
|
487
468
|
};
|
|
488
469
|
const result = await run(op, args);
|
|
@@ -491,19 +472,19 @@ function createRepository(runner, table) {
|
|
|
491
472
|
},
|
|
492
473
|
upsert(data, args) {
|
|
493
474
|
return AsyncResult.from(async () => {
|
|
494
|
-
const op = insertOp([data], args, conflictColumns(args?.onConflict));
|
|
475
|
+
const op = insertOp([data], args, conflictColumns(args?.["onConflict"]));
|
|
495
476
|
const result = await run(op, args);
|
|
496
477
|
if (!result.ok) return result;
|
|
497
|
-
return ok(args?.returning === false ? null : result.data.rows[0] ?? null);
|
|
478
|
+
return ok(args?.["returning"] === false ? null : result.data.rows[0] ?? null);
|
|
498
479
|
});
|
|
499
480
|
},
|
|
500
481
|
upsertMany(rows, args) {
|
|
501
482
|
return AsyncResult.from(async () => {
|
|
502
|
-
if (rows.length === 0) return ok(args?.returning === false ? { count: 0 } : []);
|
|
503
|
-
const op = insertOp(rows, args, conflictColumns(args?.onConflict));
|
|
483
|
+
if (rows.length === 0) return ok(args?.["returning"] === false ? { count: 0 } : []);
|
|
484
|
+
const op = insertOp(rows, args, conflictColumns(args?.["onConflict"]));
|
|
504
485
|
const result = await run(op, args);
|
|
505
486
|
if (!result.ok) return result;
|
|
506
|
-
return ok(args?.returning === false ? { count: result.data.count ?? rows.length } : result.data.rows);
|
|
487
|
+
return ok(args?.["returning"] === false ? { count: result.data.count ?? rows.length } : result.data.rows);
|
|
507
488
|
});
|
|
508
489
|
},
|
|
509
490
|
delete(id, args) {
|
|
@@ -521,7 +502,7 @@ function createRepository(runner, table) {
|
|
|
521
502
|
},
|
|
522
503
|
deleteMany(args) {
|
|
523
504
|
return AsyncResult.from(async () => {
|
|
524
|
-
const where = builder.where(table, args
|
|
505
|
+
const where = builder.where(table, args["where"]);
|
|
525
506
|
if (!where) return runner.fail(table, dbError("invalid_request", "deleteMany needs a non-empty \"where\""));
|
|
526
507
|
const result = await run({
|
|
527
508
|
kind: "delete",
|
|
@@ -541,7 +522,7 @@ function createRepository(runner, table) {
|
|
|
541
522
|
returning: returning(args),
|
|
542
523
|
onConflict: conflict ? {
|
|
543
524
|
columns: conflict,
|
|
544
|
-
action: args?.ignoreDuplicates === true ? "ignore" : "update"
|
|
525
|
+
action: args?.["ignoreDuplicates"] === true ? "ignore" : "update"
|
|
545
526
|
} : void 0,
|
|
546
527
|
defaultToNull: false
|
|
547
528
|
};
|
|
@@ -557,11 +538,11 @@ function createRepository(runner, table) {
|
|
|
557
538
|
return invalidRequest(`Invalid onConflict on "${table.key}"`, table.key);
|
|
558
539
|
}
|
|
559
540
|
async function offsetPage(args) {
|
|
560
|
-
const size = Number(args
|
|
541
|
+
const size = Number(args["size"]);
|
|
561
542
|
if (!Number.isInteger(size) || size < 1) return runner.fail(table, dbError("invalid_request", "\"size\" must be a positive integer"));
|
|
562
|
-
const number = args
|
|
543
|
+
const number = args["page"] === void 0 ? 1 : Number(args["page"]);
|
|
563
544
|
if (!Number.isInteger(number) || number < 1) return runner.fail(table, dbError("invalid_request", "\"page\" must be a positive integer"));
|
|
564
|
-
const count = args
|
|
545
|
+
const count = args["count"];
|
|
565
546
|
const op = selectOp(args, {
|
|
566
547
|
limit: size + 1,
|
|
567
548
|
offset: (number - 1) * size,
|
|
@@ -583,19 +564,19 @@ function createRepository(runner, table) {
|
|
|
583
564
|
});
|
|
584
565
|
}
|
|
585
566
|
async function cursorPage(args) {
|
|
586
|
-
const size = Number(args
|
|
567
|
+
const size = Number(args["size"]);
|
|
587
568
|
if (!Number.isInteger(size) || size < 1) return runner.fail(table, dbError("invalid_request", "\"size\" must be a positive integer"));
|
|
588
|
-
const orderBy = withTieBreaker(builder.orderBy(table, args
|
|
569
|
+
const orderBy = withTieBreaker(builder.orderBy(table, args["orderBy"]));
|
|
589
570
|
const { selection: withSort, added } = ensureColumns(selection(args), orderBy);
|
|
590
571
|
let after;
|
|
591
|
-
if (typeof args
|
|
592
|
-
const values = decodeCursor(args
|
|
572
|
+
if (typeof args["after"] === "string") {
|
|
573
|
+
const values = decodeCursor(args["after"]);
|
|
593
574
|
if (!values || values.length !== orderBy.length) return runner.fail(table, dbError("invalid_request", "Invalid cursor"));
|
|
594
575
|
after = keysetCondition(orderBy, values);
|
|
595
576
|
}
|
|
596
577
|
const op = selectOp(args, {
|
|
597
578
|
selection: withSort,
|
|
598
|
-
where: and(builder.where(table, args
|
|
579
|
+
where: and(builder.where(table, args["where"]), after),
|
|
599
580
|
orderBy,
|
|
600
581
|
limit: size + 1,
|
|
601
582
|
offset: void 0
|
|
@@ -707,6 +688,10 @@ var BetterSupabase = class BetterSupabase {
|
|
|
707
688
|
get claimsSchema() {
|
|
708
689
|
return this.options.claims;
|
|
709
690
|
}
|
|
691
|
+
/** The schema set by `userMetadata()`; its output types `session.profile`. */
|
|
692
|
+
get userMetadataSchema() {
|
|
693
|
+
return this.options.userMetadata;
|
|
694
|
+
}
|
|
710
695
|
/**
|
|
711
696
|
* Returns a new instance whose servers validate verified JWT claims (custom
|
|
712
697
|
* access token hook output) with `schema`, and whose sessions are typed by it.
|
|
@@ -723,6 +708,24 @@ var BetterSupabase = class BetterSupabase {
|
|
|
723
708
|
}, this.events);
|
|
724
709
|
}
|
|
725
710
|
/**
|
|
711
|
+
* Returns a new instance whose sessions parse `user_metadata` with
|
|
712
|
+
* `schema` into a typed `session.profile`. Users can change their metadata
|
|
713
|
+
* with `auth.updateUser()`, so a failure only leaves `profile` undefined
|
|
714
|
+
* (with one warning), and no authorization code reads it. It is for
|
|
715
|
+
* display only: roles, memberships, the tenant and entitlements come from
|
|
716
|
+
* the verified claims, never from `profile`.
|
|
717
|
+
*
|
|
718
|
+
* ```ts
|
|
719
|
+
* const sb = defineSupabase(schema).userMetadata(z.object({ display_name: z.string() }));
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
userMetadata(schema) {
|
|
723
|
+
return new BetterSupabase(this.schema, this.plugins, {
|
|
724
|
+
...this.options,
|
|
725
|
+
userMetadata: schema
|
|
726
|
+
}, this.events);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
726
729
|
* Returns a new instance whose `.orThrow()` throws `mapper(error)` instead
|
|
727
730
|
* of a `DbException`, and whose results `toBetterResult` maps the same way.
|
|
728
731
|
* Results themselves keep their `DbError`.
|
|
@@ -1011,7 +1014,7 @@ var BetterSupabase = class BetterSupabase {
|
|
|
1011
1014
|
repository[name] = method;
|
|
1012
1015
|
}
|
|
1013
1016
|
}
|
|
1014
|
-
repository
|
|
1017
|
+
repository["extend"] = (build) => ({
|
|
1015
1018
|
...repository,
|
|
1016
1019
|
...build(repository)
|
|
1017
1020
|
});
|
|
@@ -1065,4 +1068,4 @@ function defineSupabase(schema, options) {
|
|
|
1065
1068
|
return new BetterSupabase(schema, [], options);
|
|
1066
1069
|
}
|
|
1067
1070
|
//#endregion
|
|
1068
|
-
export { EventHub as a,
|
|
1071
|
+
export { EventHub as a, rowKey as c, encodeCursor as i, rpcCacheTargets as l, defineSupabase as n, cacheTargetOf as o, decodeCursor as r, memoryCache as s, BetterSupabase as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { g as Operation, l as CountMode, r as Executor } from "./executor-
|
|
1
|
+
import { A as SchemaMeta, C as PrimaryKeyValue, D as Relations, E as RelationShape, I as UniqueKeyName, L as UniqueWhere, N as TableKey, O as Row, P as TableMeta, R as Update, _ as Insert, j as Simplify, k as Schema, n as AnyModels, t as AnyFunctions } from "./types-C83v5SQz.js";
|
|
2
|
+
import { g as Operation, l as CountMode, r as Executor } from "./executor-CGdNQ27g.js";
|
|
3
3
|
import { p as DbError, s as ThrowMapper, t as AsyncResult, v as ErrorMapper } from "./result-CTkCZ6JA.js";
|
|
4
|
-
import { a as EventHub, f as Logger, i as EventHandler, o as EventName, s as MutationNotice, u as RpcNotice } from "./events-
|
|
5
|
-
import { a as ExtensionOf, g as WithExtension, h as RequestContext, n as AnyPlugin, r as ApplyExtension } from "./plugin-
|
|
4
|
+
import { a as EventHub, f as Logger, i as EventHandler, o as EventName, s as MutationNotice, u as RpcNotice } from "./events-DOt3nSO-.js";
|
|
5
|
+
import { a as ExtensionOf, g as WithExtension, h as RequestContext, n as AnyPlugin, r as ApplyExtension } from "./plugin-C4TR9J0Z.js";
|
|
6
6
|
import { t as StandardSchemaV1 } from "./standard-CyhRzctb.js";
|
|
7
|
-
import { i as PostgrestPlan } from "./postgrest-
|
|
7
|
+
import { i as PostgrestPlan } from "./postgrest-cAEQ_IQN.js";
|
|
8
8
|
//#region src/ir/args.d.ts
|
|
9
9
|
interface BaseOps<V> {
|
|
10
10
|
readonly eq?: V;
|
|
@@ -562,6 +562,8 @@ interface DefineSupabaseOptions {
|
|
|
562
562
|
readonly throwAs?: ThrowMapper;
|
|
563
563
|
/** Validates verified JWT claims on the server. Prefer `sb.claims()`, which also types them. */
|
|
564
564
|
readonly claims?: StandardSchemaV1;
|
|
565
|
+
/** Parses `user_metadata` into `session.profile`. Prefer `sb.userMetadata()`, which also types it. */
|
|
566
|
+
readonly userMetadata?: StandardSchemaV1;
|
|
565
567
|
/**
|
|
566
568
|
* PostgREST's `db-max-rows`: the most rows one read returns. An unbounded
|
|
567
569
|
* `findMany` that returns this many sets `truncated` on the `query` event
|
|
@@ -586,7 +588,7 @@ interface RpcDefinition {
|
|
|
586
588
|
* The isomorphic definition of your data layer: schema plus plugins. Holds no
|
|
587
589
|
* secrets and no connection; `connect()` binds it to a client per request.
|
|
588
590
|
*/
|
|
589
|
-
declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F extends AnyFunctions = AnyFunctions, E = unknown, C = unknown> {
|
|
591
|
+
declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F extends AnyFunctions = AnyFunctions, E = unknown, C = unknown, P = unknown> {
|
|
590
592
|
#private;
|
|
591
593
|
readonly schema: Schema<M, D, F>;
|
|
592
594
|
readonly plugins: readonly AnyPlugin[];
|
|
@@ -596,6 +598,8 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
|
|
|
596
598
|
get meta(): SchemaMeta;
|
|
597
599
|
/** The schema set by `claims()`; its output types `session.claims`. */
|
|
598
600
|
get claimsSchema(): StandardSchemaV1<unknown, C> | undefined;
|
|
601
|
+
/** The schema set by `userMetadata()`; its output types `session.profile`. */
|
|
602
|
+
get userMetadataSchema(): StandardSchemaV1<unknown, P> | undefined;
|
|
599
603
|
/**
|
|
600
604
|
* Returns a new instance whose servers validate verified JWT claims (custom
|
|
601
605
|
* access token hook output) with `schema`, and whose sessions are typed by it.
|
|
@@ -605,7 +609,20 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
|
|
|
605
609
|
* const sb = defineSupabase(schema).claims(z.object({ tenant_id: z.uuid() }));
|
|
606
610
|
* ```
|
|
607
611
|
*/
|
|
608
|
-
claims<S extends StandardSchemaV1>(schema: S): BetterSupabase<M, D, F, E, StandardSchemaV1.InferOutput<S
|
|
612
|
+
claims<S extends StandardSchemaV1>(schema: S): BetterSupabase<M, D, F, E, StandardSchemaV1.InferOutput<S>, P>;
|
|
613
|
+
/**
|
|
614
|
+
* Returns a new instance whose sessions parse `user_metadata` with
|
|
615
|
+
* `schema` into a typed `session.profile`. Users can change their metadata
|
|
616
|
+
* with `auth.updateUser()`, so a failure only leaves `profile` undefined
|
|
617
|
+
* (with one warning), and no authorization code reads it. It is for
|
|
618
|
+
* display only: roles, memberships, the tenant and entitlements come from
|
|
619
|
+
* the verified claims, never from `profile`.
|
|
620
|
+
*
|
|
621
|
+
* ```ts
|
|
622
|
+
* const sb = defineSupabase(schema).userMetadata(z.object({ display_name: z.string() }));
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
userMetadata<S extends StandardSchemaV1>(schema: S): BetterSupabase<M, D, F, E, C, StandardSchemaV1.InferOutput<S>>;
|
|
609
626
|
/**
|
|
610
627
|
* Returns a new instance whose `.orThrow()` throws `mapper(error)` instead
|
|
611
628
|
* of a `DbException`, and whose results `toBetterResult` maps the same way.
|
|
@@ -615,7 +632,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
|
|
|
615
632
|
* const sb = defineSupabase(schema).mapError((error) => new AppError(error));
|
|
616
633
|
* ```
|
|
617
634
|
*/
|
|
618
|
-
mapError(mapper: (error: DbError) => unknown): BetterSupabase<M, D, F, E, C>;
|
|
635
|
+
mapError(mapper: (error: DbError) => unknown): BetterSupabase<M, D, F, E, C, P>;
|
|
619
636
|
/**
|
|
620
637
|
* Builds serializable `QuerySpec`s with the same arguments and result types
|
|
621
638
|
* as the repository: `sb.spec.customers.findMany({ select: ['id'] })`.
|
|
@@ -624,7 +641,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
|
|
|
624
641
|
/** App keys of every table a spec reads; mutations of any of them make it stale. */
|
|
625
642
|
tablesOf(spec: QuerySpec): string[];
|
|
626
643
|
/** Returns a new instance with the plugin appended. */
|
|
627
|
-
use<
|
|
644
|
+
use<Q extends AnyPlugin>(plugin: Q): BetterSupabase<M, D, F, WithExtension<E, ExtensionOf<Q>>, C, P>;
|
|
628
645
|
/**
|
|
629
646
|
* Declares the tables an RPC writes, so cache adapters and live queries
|
|
630
647
|
* invalidate them after it succeeds.
|
|
@@ -635,7 +652,7 @@ declare class BetterSupabase<M extends AnyModels = AnyModels, D = unknown, F ext
|
|
|
635
652
|
*/
|
|
636
653
|
defineRpc(name: Extract<keyof F, string>, options: {
|
|
637
654
|
readonly invalidates: readonly TableKey<M>[];
|
|
638
|
-
}): BetterSupabase<M, D, F, E, C>;
|
|
655
|
+
}): BetterSupabase<M, D, F, E, C, P>;
|
|
639
656
|
/** Observes queries, mutations, errors, auth and refreshes. */
|
|
640
657
|
on<K extends EventName>(name: K, handler: EventHandler<K>): () => void;
|
|
641
658
|
/**
|
package/dist/edge/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as BetterSupabase } from "../define-
|
|
3
|
-
import { d as ServerContext, f as ServerOptions, l as BetterServer, n as GuardOptions } from "../respond-
|
|
4
|
-
import { i as ResourceRouteOptions } from "../resource-
|
|
1
|
+
import { N as TableKey, n as AnyModels, t as AnyFunctions } from "../types-C83v5SQz.js";
|
|
2
|
+
import { t as BetterSupabase } from "../define-e3zI4_4g.js";
|
|
3
|
+
import { d as ServerContext, f as ServerOptions, l as BetterServer, n as GuardOptions } from "../respond-Dne1ARSa.js";
|
|
4
|
+
import { i as ResourceRouteOptions } from "../resource-CgZa3YG_.js";
|
|
5
5
|
//#region src/edge/index.d.ts
|
|
6
6
|
export interface CorsOptions {
|
|
7
7
|
/** Allowed origins, or `*`. Defaults to `*`. */
|
package/dist/edge/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as dbError } from "../errors-Bl3rkOzo.js";
|
|
2
|
-
import { a as problemResponse } from "../problem-
|
|
3
|
-
import { i as respond, n as guard, o as createServer, s as extendServer, t as defaultExpose } from "../respond-
|
|
4
|
-
import { t as defineResource } from "../resource-
|
|
2
|
+
import { a as problemResponse } from "../problem-BTkTtRV9.js";
|
|
3
|
+
import { i as respond, n as guard, o as createServer, s as extendServer, t as defaultExpose } from "../respond-DMcbQwfN.js";
|
|
4
|
+
import { t as defineResource } from "../resource-BHEWmQJK.js";
|
|
5
5
|
//#region src/edge/index.ts
|
|
6
6
|
const SUPABASE_CORS_HEADERS = [
|
|
7
7
|
"authorization",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/auth/entitlements.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether the session's plan-features claim grants `key` in `tenantId`.
|
|
4
|
+
* `claim` is `config.claims.features` (default `features`), the claim
|
|
5
|
+
* `better_supabase.feature_claims()` fills. The claim is as fresh as the
|
|
6
|
+
* token: enforce it in RLS with `better_supabase.has_entitlement()`, and
|
|
7
|
+
* refresh the session after checkout.
|
|
8
|
+
*/
|
|
9
|
+
function hasEntitlement(session, tenantId, key, claim = "features") {
|
|
10
|
+
if (session.kind !== "user") return false;
|
|
11
|
+
const claims = session.claims;
|
|
12
|
+
if (!isRecord(claims)) return false;
|
|
13
|
+
const features = claims[claim];
|
|
14
|
+
if (!isRecord(features) || !Object.hasOwn(features, tenantId)) return false;
|
|
15
|
+
const keys = features[tenantId];
|
|
16
|
+
return Array.isArray(keys) && keys.includes(key);
|
|
17
|
+
}
|
|
18
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { hasEntitlement as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { t as AuthSession } from "./view-D1s0wa0T.js";
|
|
2
|
+
//#region src/auth/entitlements.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* One entry of the `memberships` claim, in PermDock's shape. PermDock strips
|
|
5
|
+
* `null`s, so optional fields are absent rather than `null`.
|
|
6
|
+
*/
|
|
7
|
+
interface MembershipClaim {
|
|
8
|
+
/** The scope the membership is in, e.g. `tenant` or `organization`. */
|
|
9
|
+
readonly scope: string;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
/** Parent scopes, e.g. `{ organization: '...' }` for a project membership. */
|
|
12
|
+
readonly within?: Readonly<Record<string, string>>;
|
|
13
|
+
readonly roles: readonly string[];
|
|
14
|
+
readonly via?: string;
|
|
15
|
+
/** Unix seconds. */
|
|
16
|
+
readonly expiresAt?: number;
|
|
17
|
+
readonly grantedBy?: string;
|
|
18
|
+
readonly reason?: string;
|
|
19
|
+
readonly member?: {
|
|
20
|
+
readonly group: string;
|
|
21
|
+
};
|
|
22
|
+
readonly managedBy?: "idp";
|
|
23
|
+
/** Seats, not plan features: those are in the `features` claim. */
|
|
24
|
+
readonly entitlements?: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Entitlement keys of the `features` claim: the literal union when
|
|
28
|
+
* `sb.claims(schema)` declares one (`z.enum([...])`), otherwise `string`.
|
|
29
|
+
*/
|
|
30
|
+
type EntitlementKey<C> = C extends {
|
|
31
|
+
readonly features?: infer F;
|
|
32
|
+
} ? NonNullable<F> extends Readonly<Record<string, readonly (infer K)[]>> ? K extends string ? K : string : string : string;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the session's plan-features claim grants `key` in `tenantId`.
|
|
35
|
+
* `claim` is `config.claims.features` (default `features`), the claim
|
|
36
|
+
* `better_supabase.feature_claims()` fills. The claim is as fresh as the
|
|
37
|
+
* token: enforce it in RLS with `better_supabase.has_entitlement()`, and
|
|
38
|
+
* refresh the session after checkout.
|
|
39
|
+
*/
|
|
40
|
+
declare function hasEntitlement<C>(session: AuthSession<C>, tenantId: string, key: EntitlementKey<C>, claim?: string): boolean;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { MembershipClaim as n, hasEntitlement as r, EntitlementKey as t };
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as HttpMode, c as RowEventData, d as httpSink, f as isCloudEvent, i as ForwardOptions, l as forwardMutations, m as toHttp, n as CloudEventOptions, o as HttpSinkOptions, p as toCloudEvents, r as EventSink, s as ROW_EVENT_TYPES, t as CloudEvent, u as fromHttp } from "../index-
|
|
1
|
+
import { a as HttpMode, c as RowEventData, d as httpSink, f as isCloudEvent, i as ForwardOptions, l as forwardMutations, m as toHttp, n as CloudEventOptions, o as HttpSinkOptions, p as toCloudEvents, r as EventSink, s as ROW_EVENT_TYPES, t as CloudEvent, u as fromHttp } from "../index-Ciu5Xlml.js";
|
|
2
2
|
export { CloudEvent, CloudEventOptions, EventSink, ForwardOptions, HttpMode, HttpSinkOptions, ROW_EVENT_TYPES, RowEventData, forwardMutations, fromHttp, httpSink, isCloudEvent, toCloudEvents, toHttp };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as Operation } from "./executor-
|
|
1
|
+
import { g as Operation } from "./executor-CGdNQ27g.js";
|
|
2
2
|
import { p as DbError } from "./result-CTkCZ6JA.js";
|
|
3
|
-
import { h as RequestContext, l as MutationKind } from "./plugin-
|
|
3
|
+
import { h as RequestContext, l as MutationKind } from "./plugin-C4TR9J0Z.js";
|
|
4
4
|
//#region src/core/logger.d.ts
|
|
5
5
|
type LogFields = Readonly<Record<string, unknown>>;
|
|
6
6
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as TableMeta, T as RelationMeta, c as Codec } from "./types-C83v5SQz.js";
|
|
2
2
|
import { o as Result, v as ErrorMapper } from "./result-CTkCZ6JA.js";
|
|
3
3
|
//#region src/ir/types.d.ts
|
|
4
4
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as mapDbError, n as dbError } from "./errors-Bl3rkOzo.js";
|
|
2
2
|
import { i as ok, n as err, o as toDbError } from "./result-DWXatkd6.js";
|
|
3
|
-
import { t as compileSql } from "./sql-
|
|
3
|
+
import { t as compileSql } from "./sql-DTjA1LPj.js";
|
|
4
4
|
//#region src/postgres/executor.ts
|
|
5
5
|
function isPgError(value) {
|
|
6
6
|
return typeof value === "object" && value !== null && typeof value.code === "string";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/core/guards.ts
|
|
2
|
+
/**
|
|
3
|
+
* `Array.isArray` narrows `unknown` and readonly arrays to `any[]`; this keeps
|
|
4
|
+
* the element type (or `unknown`).
|
|
5
|
+
*/
|
|
6
|
+
function isList(value) {
|
|
7
|
+
return Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { isList as t };
|