@prisma-next/extension-supabase 0.13.0-dev.2 → 0.13.0-dev.20
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/dist/pack.mjs +11 -13
- package/dist/pack.mjs.map +1 -1
- package/dist/package-4XSdICyq.mjs +6 -0
- package/dist/package-4XSdICyq.mjs.map +1 -0
- package/dist/runtime.d.mts +110 -3
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +278 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/test/utils.d.mts +7 -6
- package/dist/test/utils.d.mts.map +1 -1
- package/dist/test/utils.mjs +19 -6
- package/dist/test/utils.mjs.map +1 -1
- package/package.json +28 -25
- package/src/contract/contract.d.ts +22 -22
- package/src/contract/contract.json +10 -10
- package/src/exports/runtime.ts +17 -29
- package/src/runtime/descriptor.ts +26 -0
- package/src/runtime/supabase-runtime.ts +171 -0
- package/src/runtime/supabase.ts +323 -0
package/dist/pack.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { t as version } from "./package-4XSdICyq.mjs";
|
|
1
2
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
2
|
-
//#region package.json
|
|
3
|
-
var version = "0.13.0-dev.2";
|
|
4
|
-
//#endregion
|
|
5
3
|
//#region src/contract/contract.json
|
|
6
4
|
var contract_default = {
|
|
7
5
|
schemaVersion: "1",
|
|
@@ -40,7 +38,7 @@ var contract_default = {
|
|
|
40
38
|
"id": {
|
|
41
39
|
"nullable": false,
|
|
42
40
|
"type": {
|
|
43
|
-
"codecId": "pg/
|
|
41
|
+
"codecId": "pg/uuid@1",
|
|
44
42
|
"kind": "scalar"
|
|
45
43
|
}
|
|
46
44
|
},
|
|
@@ -61,7 +59,7 @@ var contract_default = {
|
|
|
61
59
|
"user_id": {
|
|
62
60
|
"nullable": false,
|
|
63
61
|
"type": {
|
|
64
|
-
"codecId": "pg/
|
|
62
|
+
"codecId": "pg/uuid@1",
|
|
65
63
|
"kind": "scalar"
|
|
66
64
|
}
|
|
67
65
|
}
|
|
@@ -98,7 +96,7 @@ var contract_default = {
|
|
|
98
96
|
"id": {
|
|
99
97
|
"nullable": false,
|
|
100
98
|
"type": {
|
|
101
|
-
"codecId": "pg/
|
|
99
|
+
"codecId": "pg/uuid@1",
|
|
102
100
|
"kind": "scalar"
|
|
103
101
|
}
|
|
104
102
|
},
|
|
@@ -186,7 +184,7 @@ var contract_default = {
|
|
|
186
184
|
"id": {
|
|
187
185
|
"nullable": false,
|
|
188
186
|
"type": {
|
|
189
|
-
"codecId": "pg/
|
|
187
|
+
"codecId": "pg/uuid@1",
|
|
190
188
|
"kind": "scalar"
|
|
191
189
|
}
|
|
192
190
|
},
|
|
@@ -238,7 +236,7 @@ var contract_default = {
|
|
|
238
236
|
"typeRef": "Timestamptz"
|
|
239
237
|
},
|
|
240
238
|
"id": {
|
|
241
|
-
"codecId": "pg/
|
|
239
|
+
"codecId": "pg/uuid@1",
|
|
242
240
|
"nativeType": "uuid",
|
|
243
241
|
"nullable": false,
|
|
244
242
|
"typeRef": "Uuid"
|
|
@@ -255,7 +253,7 @@ var contract_default = {
|
|
|
255
253
|
"typeRef": "Timestamptz"
|
|
256
254
|
},
|
|
257
255
|
"user_id": {
|
|
258
|
-
"codecId": "pg/
|
|
256
|
+
"codecId": "pg/uuid@1",
|
|
259
257
|
"nativeType": "uuid",
|
|
260
258
|
"nullable": false,
|
|
261
259
|
"typeRef": "Uuid"
|
|
@@ -280,7 +278,7 @@ var contract_default = {
|
|
|
280
278
|
"nullable": false
|
|
281
279
|
},
|
|
282
280
|
"id": {
|
|
283
|
-
"codecId": "pg/
|
|
281
|
+
"codecId": "pg/uuid@1",
|
|
284
282
|
"nativeType": "uuid",
|
|
285
283
|
"nullable": false,
|
|
286
284
|
"typeRef": "Uuid"
|
|
@@ -352,7 +350,7 @@ var contract_default = {
|
|
|
352
350
|
"typeRef": "Timestamptz"
|
|
353
351
|
},
|
|
354
352
|
"id": {
|
|
355
|
-
"codecId": "pg/
|
|
353
|
+
"codecId": "pg/uuid@1",
|
|
356
354
|
"nativeType": "uuid",
|
|
357
355
|
"nullable": false,
|
|
358
356
|
"typeRef": "Uuid"
|
|
@@ -379,7 +377,7 @@ var contract_default = {
|
|
|
379
377
|
"kind": "postgres-schema"
|
|
380
378
|
}
|
|
381
379
|
},
|
|
382
|
-
"storageHash": "sha256:
|
|
380
|
+
"storageHash": "sha256:27dcfcb121eec1827ff7464f6262582a413af76d4d86627d93db97bb2108410a",
|
|
383
381
|
"types": {
|
|
384
382
|
"Timestamptz": {
|
|
385
383
|
"codecId": "pg/timestamptz@1",
|
|
@@ -387,7 +385,7 @@ var contract_default = {
|
|
|
387
385
|
"nativeType": "timestamptz"
|
|
388
386
|
},
|
|
389
387
|
"Uuid": {
|
|
390
|
-
"codecId": "pg/
|
|
388
|
+
"codecId": "pg/uuid@1",
|
|
391
389
|
"kind": "codec-instance",
|
|
392
390
|
"nativeType": "uuid"
|
|
393
391
|
}
|
package/dist/pack.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.mjs","names":["contractJson","packageJson.version"],"sources":["../
|
|
1
|
+
{"version":3,"file":"pack.mjs","names":["contractJson","packageJson.version"],"sources":["../src/contract/contract.json","../src/pack/index.ts"],"sourcesContent":["","import type { SqlControlExtensionDescriptor } from '@prisma-next/family-sql/control';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport type { Contract } from '../contract/contract.d';\nimport contractJson from '../contract/contract.json' with { type: 'json' };\n\nconst SUPABASE_SPACE_ID = 'supabase' as const;\n\nfunction buildContractSpace(contractOverride?: unknown) {\n const contract = blindCast<\n Contract,\n 'JSON import narrowed to emitted Contract type; assertDescriptorSelfConsistency verifies the storageHash at load time'\n >(contractOverride ?? contractJson);\n return {\n contractJson: contract,\n migrations: [] as const,\n headRef: { hash: contract.storage.storageHash, invariants: [] as const },\n };\n}\n\nconst supabaseContractSpace = buildContractSpace();\n\nconst supabasePackBase = {\n kind: 'extension' as const,\n id: SUPABASE_SPACE_ID,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n version: packageJson.version,\n contractSpace: supabaseContractSpace,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n} satisfies SqlControlExtensionDescriptor<'postgres'>;\n\nexport const supabasePack: SqlControlExtensionDescriptor<'postgres'> = supabasePackBase;\n\n/**\n * Returns a pack using `contractOverride` in place of the shipped\n * `contract.json` when provided, otherwise returns the default pack.\n *\n * Intended for tests that need to drive the framework with a synthetic\n * contract while still exercising the full descriptor wiring.\n */\nexport function supabasePackWith(options?: {\n contractOverride?: unknown;\n}): SqlControlExtensionDescriptor<'postgres'> {\n if (options?.contractOverride === undefined) return supabasePack;\n return {\n ...supabasePackBase,\n contractSpace: buildContractSpace(options.contractOverride),\n };\n}\n\nexport default supabasePack;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACMA,MAAM,oBAAoB;AAE1B,SAAS,mBAAmB,kBAA4B;CACtD,MAAM,WAAW,UAGf,oBAAoBA,gBAAY;CAClC,OAAO;EACL,cAAc;EACd,YAAY,CAAC;EACb,SAAS;GAAE,MAAM,SAAS,QAAQ;GAAa,YAAY,CAAC;EAAW;CACzE;AACF;AAIA,MAAM,mBAAmB;CACvB,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACDC;CACT,eAR4B,mBAQb;CACf,eAAe;EACb,UAAU;EACV,UAAU;CACZ;AACF;AAEA,MAAa,eAA0D;;;;;;;;AASvE,SAAgB,iBAAiB,SAEa;CAC5C,IAAI,SAAS,qBAAqB,KAAA,GAAW,OAAO;CACpD,OAAO;EACL,GAAG;EACH,eAAe,mBAAmB,QAAQ,gBAAgB;CAC5D;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-4XSdICyq.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,7 +1,114 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { orm } from "@prisma-next/sql-orm-client";
|
|
2
|
+
import { RawSqlTag } from "@prisma-next/sql-relational-core/expression";
|
|
3
|
+
import { ExecutionContext, RuntimeConnection, SqlExecutionStackWithDriver, SqlMiddleware, SqlRuntimeExtensionDescriptor, TransactionContext, VerifyMarkerOption } from "@prisma-next/sql-runtime";
|
|
4
|
+
import { Client, Pool } from "pg";
|
|
5
|
+
import { AsyncIterableResult, RuntimeExecuteOptions } from "@prisma-next/framework-components/runtime";
|
|
6
|
+
import { PostgresRuntime, PostgresRuntimeImpl } from "@prisma-next/postgres/runtime";
|
|
7
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
8
|
+
import { Db } from "@prisma-next/sql-builder/types";
|
|
9
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
10
|
+
import { SqlExecutionPlan, SqlQueryPlan } from "@prisma-next/sql-relational-core/plan";
|
|
2
11
|
|
|
3
|
-
//#region src/
|
|
12
|
+
//#region src/runtime/descriptor.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Tells the runtime that the Supabase pack's runtime component is available.
|
|
15
|
+
*
|
|
16
|
+
* When a contract declares the Supabase pack, the runtime checks that a
|
|
17
|
+
* matching descriptor has been registered. Without this, loading a Supabase
|
|
18
|
+
* contract errors with "pack runtime component missing". The `supabase()`
|
|
19
|
+
* factory registers this descriptor automatically — app code never needs to
|
|
20
|
+
* reference it directly.
|
|
21
|
+
*/
|
|
4
22
|
declare const supabaseRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
|
|
5
23
|
//#endregion
|
|
6
|
-
|
|
24
|
+
//#region src/runtime/supabase.d.ts
|
|
25
|
+
type SupabaseTargetId = 'postgres';
|
|
26
|
+
type OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof orm<TContract>>;
|
|
27
|
+
declare class SupabaseConfigError extends Error {
|
|
28
|
+
readonly name = "SupabaseConfigError";
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
declare class InvalidJwtError extends Error {
|
|
32
|
+
readonly name = "InvalidJwtError";
|
|
33
|
+
readonly reason: string;
|
|
34
|
+
constructor(reason: string);
|
|
35
|
+
}
|
|
36
|
+
interface RoleBoundDb<TContract extends Contract<SqlStorage>> {
|
|
37
|
+
readonly sql: Db<TContract>;
|
|
38
|
+
readonly orm: OrmClient<TContract>;
|
|
39
|
+
readonly raw: RawSqlTag;
|
|
40
|
+
execute<Row>(plan: (SqlExecutionPlan<Row> | SqlQueryPlan<Row>) & {
|
|
41
|
+
readonly _row?: Row;
|
|
42
|
+
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
43
|
+
transaction<R>(fn: (tx: TransactionContext) => PromiseLike<R>): Promise<R>;
|
|
44
|
+
}
|
|
45
|
+
interface SupabaseDb<TContract extends Contract<SqlStorage>> {
|
|
46
|
+
readonly context: ExecutionContext<TContract>;
|
|
47
|
+
readonly stack: SqlExecutionStackWithDriver<SupabaseTargetId>;
|
|
48
|
+
asUser(jwt: string): Promise<RoleBoundDb<TContract>>;
|
|
49
|
+
asAnon(): RoleBoundDb<TContract>;
|
|
50
|
+
asServiceRole(): RoleBoundDb<TContract>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
interface SupabaseOptionsBase {
|
|
55
|
+
readonly extensions?: readonly SqlRuntimeExtensionDescriptor<SupabaseTargetId>[];
|
|
56
|
+
readonly middleware?: readonly SqlMiddleware[];
|
|
57
|
+
readonly verifyMarker?: VerifyMarkerOption;
|
|
58
|
+
readonly poolOptions?: {
|
|
59
|
+
readonly connectionTimeoutMillis?: number;
|
|
60
|
+
readonly idleTimeoutMillis?: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface SupabaseBindingOptions {
|
|
64
|
+
readonly url?: string;
|
|
65
|
+
readonly pg?: Pool | Client;
|
|
66
|
+
}
|
|
67
|
+
type JwtSecretOption = {
|
|
68
|
+
readonly jwtSecret: string;
|
|
69
|
+
readonly jwksUrl?: never;
|
|
70
|
+
};
|
|
71
|
+
type JwksUrlOption = {
|
|
72
|
+
readonly jwksUrl: string;
|
|
73
|
+
readonly jwtSecret?: never;
|
|
74
|
+
};
|
|
75
|
+
type SupabaseOptionsWithContract<TContract extends Contract<SqlStorage>> = SupabaseBindingOptions & SupabaseOptionsBase & (JwtSecretOption | JwksUrlOption) & {
|
|
76
|
+
readonly contract: TContract;
|
|
77
|
+
readonly contractJson?: never;
|
|
78
|
+
};
|
|
79
|
+
type SupabaseOptionsWithContractJson<TContract extends Contract<SqlStorage>> = SupabaseBindingOptions & SupabaseOptionsBase & (JwtSecretOption | JwksUrlOption) & {
|
|
80
|
+
readonly contractJson: unknown;
|
|
81
|
+
readonly contract?: never;
|
|
82
|
+
readonly _contract?: TContract;
|
|
83
|
+
};
|
|
84
|
+
type SupabaseOptions<TContract extends Contract<SqlStorage>> = SupabaseOptionsWithContract<TContract> | SupabaseOptionsWithContractJson<TContract>;
|
|
85
|
+
declare function supabase<TContract extends Contract<SqlStorage>>(options: SupabaseOptionsWithContract<TContract>): Promise<SupabaseDb<TContract>>;
|
|
86
|
+
declare function supabase<TContract extends Contract<SqlStorage>>(options: SupabaseOptionsWithContractJson<TContract>): Promise<SupabaseDb<TContract>>;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/runtime/supabase-runtime.d.ts
|
|
89
|
+
interface SupabaseRuntime extends PostgresRuntime {}
|
|
90
|
+
interface SupabaseRoleBinding {
|
|
91
|
+
readonly role: 'anon' | 'authenticated' | 'service_role';
|
|
92
|
+
readonly claims?: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A connection with a Supabase role already bound via session-scoped set_config.
|
|
96
|
+
* Implements `RuntimeConnection` so it plugs into ORM scope machinery and `withTransaction`.
|
|
97
|
+
*/
|
|
98
|
+
interface RoleSession extends RuntimeConnection {}
|
|
99
|
+
declare class SupabaseRuntimeImpl<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> extends PostgresRuntimeImpl<TContract> {
|
|
100
|
+
/**
|
|
101
|
+
* Opens a raw connection and applies role + JWT claims via session-scoped set_config.
|
|
102
|
+
* On bind failure, destroys the connection before rethrowing — no leaked connections.
|
|
103
|
+
* Not on the `SupabaseRuntime` interface; consumed by the facade, not by app code.
|
|
104
|
+
*/
|
|
105
|
+
openRoleSession(binding: SupabaseRoleBinding): Promise<RoleSession>;
|
|
106
|
+
/**
|
|
107
|
+
* Opens a role session, executes the plan, then releases after the stream drains.
|
|
108
|
+
* On mid-stream error, destroys the session instead of releasing.
|
|
109
|
+
*/
|
|
110
|
+
executeWithRole<Row>(plan: SqlExecutionPlan<Row> | SqlQueryPlan<Row>, binding: SupabaseRoleBinding, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { InvalidJwtError, type RoleBoundDb, type RoleSession, SupabaseConfigError, type SupabaseDb, type SupabaseOptions, type SupabaseOptionsWithContract, type SupabaseOptionsWithContractJson, type SupabaseRoleBinding, type SupabaseRuntime, SupabaseRuntimeImpl, type SupabaseTargetId, supabaseRuntimeDescriptor as default, supabase };
|
|
7
114
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/runtime/descriptor.ts","../src/runtime/supabase.ts","../src/runtime/supabase-runtime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;cAYa,yBAAA,EAA2B,6BAA6B;;;KC0BzD,gBAAA;AAAA,KAEP,SAAA,mBAA4B,QAAA,CAAS,UAAA,KAAe,UAAA,QAAkB,GAAA,CAAI,SAAA;AAAA,cAElE,mBAAA,SAA4B,KAAK;EAAA,SAC1B,IAAA;cACN,OAAA;AAAA;AAAA,cAKD,eAAA,SAAwB,KAAK;EAAA,SACtB,IAAA;EAAA,SACT,MAAA;cACG,MAAA;AAAA;AAAA,UAUG,WAAA,mBAA8B,QAAA,CAAS,UAAA;EAAA,SAC7C,GAAA,EAAK,EAAA,CAAG,SAAA;EAAA,SACR,GAAA,EAAK,SAAA,CAAU,SAAA;EAAA,SACf,GAAA,EAAK,SAAA;EACd,OAAA,MACE,IAAA,GAAO,gBAAA,CAAiB,GAAA,IAAO,YAAA,CAAa,GAAA;IAAA,SAAmB,IAAA,GAAO,GAAA;EAAA,GACtE,OAAA,GAAU,qBAAA,GACT,mBAAA,CAAoB,GAAA;EACvB,WAAA,IAAe,EAAA,GAAK,EAAA,EAAI,kBAAA,KAAuB,WAAA,CAAY,CAAA,IAAK,OAAA,CAAQ,CAAA;AAAA;AAAA,UAGzD,UAAA,mBAA6B,QAAA,CAAS,UAAA;EAAA,SAC5C,OAAA,EAAS,gBAAA,CAAiB,SAAA;EAAA,SAC1B,KAAA,EAAO,2BAAA,CAA4B,gBAAA;EAC5C,MAAA,CAAO,GAAA,WAA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L,eAAA,SAAwB,eAAe;AAAA,UAEvC,mBAAA;EAAA,SAEN,IAAA;EAAA,SACA,MAAA,GAAS,MAAM;AAAA;;;;AFP2C;UEcpD,WAAA,SAAoB,iBAAiB;AAAA,cAEzC,mBAAA,mBACO,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,WAC1C,mBAAA,CAAoB,SAAA;EDQlB;;;;AAAgB;ECFpB,eAAA,CAAgB,OAAA,EAAS,mBAAA,GAAsB,OAAA,CAAQ,WAAA;EDIjD;;;;ECuGZ,eAAA,MACE,IAAA,EAAM,gBAAA,CAAiB,GAAA,IAAO,YAAA,CAAa,GAAA,GAC3C,OAAA,EAAS,mBAAA,EACT,OAAA,GAAU,qBAAA,GACT,mBAAA,CAAoB,GAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import { t as version } from "./package-4XSdICyq.mjs";
|
|
2
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
3
|
+
import postgresAdapter from "@prisma-next/adapter-postgres/runtime";
|
|
4
|
+
import postgresDriver from "@prisma-next/driver-postgres/runtime";
|
|
5
|
+
import { instantiateExecutionStack } from "@prisma-next/framework-components/execution";
|
|
6
|
+
import { sql } from "@prisma-next/sql-builder/runtime";
|
|
7
|
+
import { orm } from "@prisma-next/sql-orm-client";
|
|
8
|
+
import { createRawSql } from "@prisma-next/sql-relational-core/expression";
|
|
9
|
+
import { createExecutionContext, createSqlExecutionStack, withTransaction } from "@prisma-next/sql-runtime";
|
|
10
|
+
import postgresTarget, { PostgresContractSerializer } from "@prisma-next/target-postgres/runtime";
|
|
11
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
12
|
+
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
13
|
+
import { Pool } from "pg";
|
|
14
|
+
import { AsyncIterableResult } from "@prisma-next/framework-components/runtime";
|
|
15
|
+
import { PostgresRuntimeImpl } from "@prisma-next/postgres/runtime";
|
|
16
|
+
//#region src/runtime/descriptor.ts
|
|
17
|
+
/**
|
|
18
|
+
* Tells the runtime that the Supabase pack's runtime component is available.
|
|
19
|
+
*
|
|
20
|
+
* When a contract declares the Supabase pack, the runtime checks that a
|
|
21
|
+
* matching descriptor has been registered. Without this, loading a Supabase
|
|
22
|
+
* contract errors with "pack runtime component missing". The `supabase()`
|
|
23
|
+
* factory registers this descriptor automatically — app code never needs to
|
|
24
|
+
* reference it directly.
|
|
25
|
+
*/
|
|
2
26
|
const supabaseRuntimeDescriptor = {
|
|
3
27
|
kind: "extension",
|
|
4
28
|
id: "supabase",
|
|
5
|
-
version
|
|
29
|
+
version,
|
|
6
30
|
familyId: "sql",
|
|
7
31
|
targetId: "postgres",
|
|
8
32
|
codecs: () => [],
|
|
@@ -14,6 +38,257 @@ const supabaseRuntimeDescriptor = {
|
|
|
14
38
|
}
|
|
15
39
|
};
|
|
16
40
|
//#endregion
|
|
17
|
-
|
|
41
|
+
//#region src/runtime/supabase-runtime.ts
|
|
42
|
+
var SupabaseRuntimeImpl = class extends PostgresRuntimeImpl {
|
|
43
|
+
/**
|
|
44
|
+
* Opens a raw connection and applies role + JWT claims via session-scoped set_config.
|
|
45
|
+
* On bind failure, destroys the connection before rethrowing — no leaked connections.
|
|
46
|
+
* Not on the `SupabaseRuntime` interface; consumed by the facade, not by app code.
|
|
47
|
+
*/
|
|
48
|
+
async openRoleSession(binding) {
|
|
49
|
+
const conn = await this.acquireRawConnection();
|
|
50
|
+
try {
|
|
51
|
+
await conn.query("SELECT set_config($1, $2, false)", ["role", binding.role]);
|
|
52
|
+
await conn.query("SELECT set_config($1, $2, false)", ["request.jwt.claims", JSON.stringify(binding.claims ?? {})]);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
await conn.destroy(err).catch(() => void 0);
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
const self = this;
|
|
58
|
+
return {
|
|
59
|
+
execute(plan, options) {
|
|
60
|
+
return self.executeAgainstQueryable(plan, conn, {
|
|
61
|
+
...options,
|
|
62
|
+
scope: "connection"
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
executePrepared(ps, params, options) {
|
|
66
|
+
return self.executePreparedAgainstQueryable(blindCast(ps), blindCast(params), conn, {
|
|
67
|
+
...options,
|
|
68
|
+
scope: "connection"
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
async transaction() {
|
|
72
|
+
const tx = await conn.beginTransaction();
|
|
73
|
+
return {
|
|
74
|
+
async commit() {
|
|
75
|
+
await tx.commit();
|
|
76
|
+
},
|
|
77
|
+
async rollback() {
|
|
78
|
+
await tx.rollback();
|
|
79
|
+
},
|
|
80
|
+
execute(plan, options) {
|
|
81
|
+
return self.executeAgainstQueryable(plan, tx, {
|
|
82
|
+
...options,
|
|
83
|
+
scope: "transaction"
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
executePrepared(ps, params, options) {
|
|
87
|
+
return self.executePreparedAgainstQueryable(blindCast(ps), blindCast(params), tx, {
|
|
88
|
+
...options,
|
|
89
|
+
scope: "transaction"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Resets all session-local config then releases the connection back to the pool.
|
|
96
|
+
* If RESET ALL fails, destroys the connection instead — pool-poisoning guarantee.
|
|
97
|
+
*/
|
|
98
|
+
async release() {
|
|
99
|
+
try {
|
|
100
|
+
await conn.query("RESET ALL");
|
|
101
|
+
await conn.release();
|
|
102
|
+
} catch (resetError) {
|
|
103
|
+
await conn.destroy(resetError).catch(() => void 0);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
async destroy(reason) {
|
|
107
|
+
await conn.destroy(reason);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Opens a role session, executes the plan, then releases after the stream drains.
|
|
113
|
+
* On mid-stream error, destroys the session instead of releasing.
|
|
114
|
+
*/
|
|
115
|
+
executeWithRole(plan, binding, options) {
|
|
116
|
+
const self = this;
|
|
117
|
+
const generator = async function* () {
|
|
118
|
+
const session = await self.openRoleSession(binding);
|
|
119
|
+
let errored = false;
|
|
120
|
+
try {
|
|
121
|
+
for await (const row of session.execute(plan, options)) yield row;
|
|
122
|
+
} catch (err) {
|
|
123
|
+
errored = true;
|
|
124
|
+
await session.destroy(err).catch(() => void 0);
|
|
125
|
+
throw err;
|
|
126
|
+
} finally {
|
|
127
|
+
if (!errored) await session.release();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return new AsyncIterableResult(generator());
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/runtime/supabase.ts
|
|
135
|
+
var SupabaseConfigError = class extends Error {
|
|
136
|
+
name = "SupabaseConfigError";
|
|
137
|
+
constructor(message) {
|
|
138
|
+
super(message);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var InvalidJwtError = class extends Error {
|
|
142
|
+
name = "InvalidJwtError";
|
|
143
|
+
reason;
|
|
144
|
+
constructor(reason) {
|
|
145
|
+
super(`Invalid JWT: ${reason}`);
|
|
146
|
+
this.reason = reason;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
function hasContractJson(options) {
|
|
150
|
+
return "contractJson" in options;
|
|
151
|
+
}
|
|
152
|
+
const contractSerializer = new PostgresContractSerializer();
|
|
153
|
+
function resolveContract(options) {
|
|
154
|
+
const contractInput = hasContractJson(options) ? options.contractJson : options.contract;
|
|
155
|
+
return blindCast(contractSerializer.deserializeContract(contractInput));
|
|
156
|
+
}
|
|
157
|
+
function resolveKeyMaterial(options) {
|
|
158
|
+
const jwtSecret = "jwtSecret" in options ? options.jwtSecret : void 0;
|
|
159
|
+
const jwksUrl = "jwksUrl" in options ? options.jwksUrl : void 0;
|
|
160
|
+
if (jwtSecret !== void 0 && jwksUrl !== void 0) throw new SupabaseConfigError("Provide either jwtSecret or jwksUrl, not both");
|
|
161
|
+
if (jwtSecret === void 0 && jwksUrl === void 0) throw new SupabaseConfigError("Either jwtSecret or jwksUrl is required");
|
|
162
|
+
if (jwtSecret !== void 0) return {
|
|
163
|
+
kind: "secret",
|
|
164
|
+
key: new TextEncoder().encode(jwtSecret)
|
|
165
|
+
};
|
|
166
|
+
if (jwksUrl !== void 0) return {
|
|
167
|
+
kind: "jwks",
|
|
168
|
+
keyset: createRemoteJWKSet(new URL(jwksUrl))
|
|
169
|
+
};
|
|
170
|
+
throw new SupabaseConfigError("Either jwtSecret or jwksUrl is required");
|
|
171
|
+
}
|
|
172
|
+
function toPool(options) {
|
|
173
|
+
if (options.pg instanceof Pool) return {
|
|
174
|
+
pool: options.pg,
|
|
175
|
+
owned: false
|
|
176
|
+
};
|
|
177
|
+
if (typeof options.url === "string") return {
|
|
178
|
+
pool: new Pool({
|
|
179
|
+
connectionString: options.url,
|
|
180
|
+
connectionTimeoutMillis: options.poolOptions?.connectionTimeoutMillis ?? 2e4,
|
|
181
|
+
idleTimeoutMillis: options.poolOptions?.idleTimeoutMillis ?? 3e4
|
|
182
|
+
}),
|
|
183
|
+
owned: true
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function withSupabaseDescriptor(extensions) {
|
|
187
|
+
const packs = extensions ?? [];
|
|
188
|
+
return packs.some((pack) => pack.id === supabaseRuntimeDescriptor.id) ? packs : [...packs, supabaseRuntimeDescriptor];
|
|
189
|
+
}
|
|
190
|
+
async function supabase(options) {
|
|
191
|
+
const keyMaterial = resolveKeyMaterial(options);
|
|
192
|
+
const contract = resolveContract(options);
|
|
193
|
+
const stack = createSqlExecutionStack({
|
|
194
|
+
target: postgresTarget,
|
|
195
|
+
adapter: postgresAdapter,
|
|
196
|
+
driver: postgresDriver,
|
|
197
|
+
extensionPacks: withSupabaseDescriptor(options.extensions)
|
|
198
|
+
});
|
|
199
|
+
const context = createExecutionContext({
|
|
200
|
+
contract,
|
|
201
|
+
stack
|
|
202
|
+
});
|
|
203
|
+
const rawCodecInferer = stack.adapter.rawCodecInferer;
|
|
204
|
+
const rawSqlTag = createRawSql(rawCodecInferer);
|
|
205
|
+
const poolEntry = toPool(options);
|
|
206
|
+
let closed = false;
|
|
207
|
+
const stackInstance = instantiateExecutionStack(stack);
|
|
208
|
+
const driverDescriptor = stack.driver;
|
|
209
|
+
if (!driverDescriptor) throw new Error("Driver descriptor missing from execution stack");
|
|
210
|
+
const driver = driverDescriptor.create({ cursor: { disabled: true } });
|
|
211
|
+
if (poolEntry) await driver.connect({
|
|
212
|
+
kind: "pgPool",
|
|
213
|
+
pool: poolEntry.pool
|
|
214
|
+
});
|
|
215
|
+
const runtime = new SupabaseRuntimeImpl({
|
|
216
|
+
context,
|
|
217
|
+
adapter: stackInstance.adapter,
|
|
218
|
+
driver,
|
|
219
|
+
...ifDefined("verifyMarker", options.verifyMarker),
|
|
220
|
+
...ifDefined("middleware", options.middleware)
|
|
221
|
+
});
|
|
222
|
+
async function verifyJwt(jwt) {
|
|
223
|
+
try {
|
|
224
|
+
if (keyMaterial.kind === "secret") return await jwtVerify(jwt, keyMaterial.key);
|
|
225
|
+
return await jwtVerify(jwt, keyMaterial.keyset);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
throw new InvalidJwtError(err instanceof Error ? err.message : String(err));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function buildRoleBoundDb(binding) {
|
|
231
|
+
return {
|
|
232
|
+
sql: sql({
|
|
233
|
+
context,
|
|
234
|
+
rawCodecInferer
|
|
235
|
+
}),
|
|
236
|
+
orm: orm({
|
|
237
|
+
runtime: {
|
|
238
|
+
execute(plan) {
|
|
239
|
+
return runtime.executeWithRole(plan, binding);
|
|
240
|
+
},
|
|
241
|
+
connection: () => runtime.openRoleSession(binding)
|
|
242
|
+
},
|
|
243
|
+
context
|
|
244
|
+
}),
|
|
245
|
+
raw: rawSqlTag,
|
|
246
|
+
execute(plan, execOptions) {
|
|
247
|
+
return runtime.executeWithRole(plan, binding, execOptions);
|
|
248
|
+
},
|
|
249
|
+
transaction(fn) {
|
|
250
|
+
return withTransaction({ connection: () => runtime.openRoleSession(binding) }, fn);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async function closeDb() {
|
|
255
|
+
if (closed) return;
|
|
256
|
+
closed = true;
|
|
257
|
+
await runtime.close();
|
|
258
|
+
if (poolEntry?.owned) await poolEntry.pool.end().catch(() => void 0);
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
context,
|
|
262
|
+
stack,
|
|
263
|
+
async asUser(jwt) {
|
|
264
|
+
const { payload } = await verifyJwt(jwt);
|
|
265
|
+
const rawRole = payload["role"];
|
|
266
|
+
const roleStr = typeof rawRole === "string" ? rawRole : "authenticated";
|
|
267
|
+
return buildRoleBoundDb({
|
|
268
|
+
role: roleStr === "anon" || roleStr === "authenticated" || roleStr === "service_role" ? roleStr : "authenticated",
|
|
269
|
+
claims: payload
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
asAnon() {
|
|
273
|
+
return buildRoleBoundDb({
|
|
274
|
+
role: "anon",
|
|
275
|
+
claims: {}
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
asServiceRole() {
|
|
279
|
+
return buildRoleBoundDb({
|
|
280
|
+
role: "service_role",
|
|
281
|
+
claims: {}
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
close: closeDb,
|
|
285
|
+
[Symbol.asyncDispose]: closeDb
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/exports/runtime.ts
|
|
290
|
+
var runtime_default = supabaseRuntimeDescriptor;
|
|
291
|
+
//#endregion
|
|
292
|
+
export { InvalidJwtError, SupabaseConfigError, SupabaseRuntimeImpl, runtime_default as default, supabase };
|
|
18
293
|
|
|
19
294
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["/**\n * Minimal M1 runtime descriptor for the Supabase extension.\n *\n * The Supabase pack contributes no runtime codec types or query operations in\n * M1 — `auth.*`/`storage.*` are external tables accessed via the stock\n * postgres runtime, not through a custom codec or operation surface. This\n * descriptor exists so the postgres runtime's contract-requirements check\n * (which verifies every `extensionPacks` entry in the emitted `contract.json`\n * has a matching runtime component) passes.\n *\n * TODO(M2): Replace with the real SupabaseRuntime that adds\n * `asUser()`/`asAnon()` role-binding and the Supabase auth surface.\n */\nimport type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';\n\nconst supabaseRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: 'supabase',\n version: '0.12.0',\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: () => [],\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport default supabaseRuntimeDescriptor;\n"],"mappings":";AAeA,MAAM,4BAAuE;CAC3E,MAAM;CACN,IAAI;CACJ,SAAS;CACT,UAAU;CACV,UAAU;CACV,cAAc,CAAC;CACf,SAAS;EACP,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["packageJson.version"],"sources":["../src/runtime/descriptor.ts","../src/runtime/supabase-runtime.ts","../src/runtime/supabase.ts","../src/exports/runtime.ts"],"sourcesContent":["import type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';\nimport packageJson from '../../package.json' with { type: 'json' };\n\n/**\n * Tells the runtime that the Supabase pack's runtime component is available.\n *\n * When a contract declares the Supabase pack, the runtime checks that a\n * matching descriptor has been registered. Without this, loading a Supabase\n * contract errors with \"pack runtime component missing\". The `supabase()`\n * factory registers this descriptor automatically — app code never needs to\n * reference it directly.\n */\nexport const supabaseRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: 'supabase',\n version: packageJson.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: () => [],\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { RuntimeExecuteOptions } from '@prisma-next/framework-components/runtime';\nimport { AsyncIterableResult } from '@prisma-next/framework-components/runtime';\nimport { type PostgresRuntime, PostgresRuntimeImpl } from '@prisma-next/postgres/runtime';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlExecutionPlan, SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n PreparedStatement,\n PreparedStatementImpl,\n RuntimeConnection,\n RuntimeTransaction,\n} from '@prisma-next/sql-runtime';\nimport { blindCast } from '@prisma-next/utils/casts';\n\nexport interface SupabaseRuntime extends PostgresRuntime {}\n\nexport interface SupabaseRoleBinding {\n // TODO(TML-2501): role names move to the Supabase extension contract (roles as first-class IR) when postgres-rls lands.\n readonly role: 'anon' | 'authenticated' | 'service_role';\n readonly claims?: Record<string, unknown>;\n}\n\n/**\n * A connection with a Supabase role already bound via session-scoped set_config.\n * Implements `RuntimeConnection` so it plugs into ORM scope machinery and `withTransaction`.\n */\nexport interface RoleSession extends RuntimeConnection {}\n\nexport class SupabaseRuntimeImpl<\n TContract extends Contract<SqlStorage> = Contract<SqlStorage>,\n> extends PostgresRuntimeImpl<TContract> {\n /**\n * Opens a raw connection and applies role + JWT claims via session-scoped set_config.\n * On bind failure, destroys the connection before rethrowing — no leaked connections.\n * Not on the `SupabaseRuntime` interface; consumed by the facade, not by app code.\n */\n async openRoleSession(binding: SupabaseRoleBinding): Promise<RoleSession> {\n const conn = await this.acquireRawConnection();\n\n try {\n await conn.query('SELECT set_config($1, $2, false)', ['role', binding.role]);\n await conn.query('SELECT set_config($1, $2, false)', [\n 'request.jwt.claims',\n JSON.stringify(binding.claims ?? {}),\n ]);\n } catch (err) {\n await conn.destroy(err).catch(() => undefined);\n throw err;\n }\n\n const self = this;\n\n const session: RoleSession = {\n execute<Row>(\n plan: (SqlExecutionPlan<unknown> | SqlQueryPlan<unknown>) & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n return self.executeAgainstQueryable<Row>(plan, conn, { ...options, scope: 'connection' });\n },\n\n executePrepared<Params, Row>(\n ps: PreparedStatement<Params, Row>,\n params: Params,\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n return self.executePreparedAgainstQueryable(\n blindCast<\n PreparedStatementImpl<Params, Row>,\n 'PreparedStatement is PreparedStatementImpl; the impl class is the only concrete form'\n >(ps),\n blindCast<\n Record<string, unknown>,\n 'params are structurally Record<string, unknown> at runtime'\n >(params),\n conn,\n { ...options, scope: 'connection' },\n );\n },\n\n async transaction(): Promise<RuntimeTransaction> {\n const tx = await conn.beginTransaction();\n return {\n async commit(): Promise<void> {\n await tx.commit();\n },\n async rollback(): Promise<void> {\n await tx.rollback();\n },\n execute<Row>(\n plan: (SqlExecutionPlan<unknown> | SqlQueryPlan<unknown>) & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n return self.executeAgainstQueryable<Row>(plan, tx, {\n ...options,\n scope: 'transaction',\n });\n },\n executePrepared<Params, Row>(\n ps: PreparedStatement<Params, Row>,\n params: Params,\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n return self.executePreparedAgainstQueryable(\n blindCast<\n PreparedStatementImpl<Params, Row>,\n 'PreparedStatement is PreparedStatementImpl; the impl class is the only concrete form'\n >(ps),\n blindCast<\n Record<string, unknown>,\n 'params are structurally Record<string, unknown> at runtime'\n >(params),\n tx,\n { ...options, scope: 'transaction' },\n );\n },\n };\n },\n\n /**\n * Resets all session-local config then releases the connection back to the pool.\n * If RESET ALL fails, destroys the connection instead — pool-poisoning guarantee.\n */\n async release(): Promise<void> {\n try {\n await conn.query('RESET ALL');\n await conn.release();\n } catch (resetError) {\n await conn.destroy(resetError).catch(() => undefined);\n }\n },\n\n async destroy(reason?: unknown): Promise<void> {\n await conn.destroy(reason);\n },\n };\n\n return session;\n }\n\n /**\n * Opens a role session, executes the plan, then releases after the stream drains.\n * On mid-stream error, destroys the session instead of releasing.\n */\n executeWithRole<Row>(\n plan: SqlExecutionPlan<Row> | SqlQueryPlan<Row>,\n binding: SupabaseRoleBinding,\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n const self = this;\n\n const generator = async function* (): AsyncGenerator<Row, void, unknown> {\n const session = await self.openRoleSession(binding);\n let errored = false;\n try {\n for await (const row of session.execute(plan, options)) {\n yield row;\n }\n } catch (err) {\n errored = true;\n await session.destroy(err).catch(() => undefined);\n throw err;\n } finally {\n if (!errored) {\n await session.release();\n }\n }\n };\n\n return new AsyncIterableResult(generator());\n }\n}\n","import postgresAdapter from '@prisma-next/adapter-postgres/runtime';\nimport type { Contract } from '@prisma-next/contract/types';\nimport postgresDriver from '@prisma-next/driver-postgres/runtime';\nimport { instantiateExecutionStack } from '@prisma-next/framework-components/execution';\nimport type {\n AsyncIterableResult,\n RuntimeExecuteOptions,\n} from '@prisma-next/framework-components/runtime';\nimport { sql } from '@prisma-next/sql-builder/runtime';\nimport type { Db } from '@prisma-next/sql-builder/types';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { orm } from '@prisma-next/sql-orm-client';\nimport type { RawSqlTag } from '@prisma-next/sql-relational-core/expression';\nimport { createRawSql } from '@prisma-next/sql-relational-core/expression';\nimport type { SqlExecutionPlan, SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n ExecutionContext,\n SqlExecutionStackWithDriver,\n SqlMiddleware,\n SqlRuntimeExtensionDescriptor,\n TransactionContext,\n VerifyMarkerOption,\n} from '@prisma-next/sql-runtime';\nimport {\n createExecutionContext,\n createSqlExecutionStack,\n withTransaction,\n} from '@prisma-next/sql-runtime';\nimport postgresTarget, { PostgresContractSerializer } from '@prisma-next/target-postgres/runtime';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { createRemoteJWKSet, type JWTVerifyResult, jwtVerify } from 'jose';\nimport type { Client } from 'pg';\nimport { Pool } from 'pg';\nimport { supabaseRuntimeDescriptor } from './descriptor';\nimport type { SupabaseRoleBinding, SupabaseRuntime } from './supabase-runtime';\nimport { SupabaseRuntimeImpl } from './supabase-runtime';\n\nexport type SupabaseTargetId = 'postgres';\n\ntype OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof orm<TContract>>;\n\nexport class SupabaseConfigError extends Error {\n override readonly name = 'SupabaseConfigError';\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class InvalidJwtError extends Error {\n override readonly name = 'InvalidJwtError';\n readonly reason: string;\n constructor(reason: string) {\n super(`Invalid JWT: ${reason}`);\n this.reason = reason;\n }\n}\n\ntype KeyMaterial =\n | { readonly kind: 'secret'; readonly key: Uint8Array }\n | { readonly kind: 'jwks'; readonly keyset: ReturnType<typeof createRemoteJWKSet> };\n\nexport interface RoleBoundDb<TContract extends Contract<SqlStorage>> {\n readonly sql: Db<TContract>;\n readonly orm: OrmClient<TContract>;\n readonly raw: RawSqlTag;\n execute<Row>(\n plan: (SqlExecutionPlan<Row> | SqlQueryPlan<Row>) & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row>;\n transaction<R>(fn: (tx: TransactionContext) => PromiseLike<R>): Promise<R>;\n}\n\nexport interface SupabaseDb<TContract extends Contract<SqlStorage>> {\n readonly context: ExecutionContext<TContract>;\n readonly stack: SqlExecutionStackWithDriver<SupabaseTargetId>;\n asUser(jwt: string): Promise<RoleBoundDb<TContract>>;\n asAnon(): RoleBoundDb<TContract>;\n asServiceRole(): RoleBoundDb<TContract>;\n close(): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\nexport interface SupabaseOptionsBase {\n readonly extensions?: readonly SqlRuntimeExtensionDescriptor<SupabaseTargetId>[];\n readonly middleware?: readonly SqlMiddleware[];\n readonly verifyMarker?: VerifyMarkerOption;\n readonly poolOptions?: {\n readonly connectionTimeoutMillis?: number;\n readonly idleTimeoutMillis?: number;\n };\n}\n\nexport interface SupabaseBindingOptions {\n readonly url?: string;\n readonly pg?: Pool | Client;\n}\n\ntype JwtSecretOption = {\n readonly jwtSecret: string;\n readonly jwksUrl?: never;\n};\n\ntype JwksUrlOption = {\n readonly jwksUrl: string;\n readonly jwtSecret?: never;\n};\n\nexport type SupabaseOptionsWithContract<TContract extends Contract<SqlStorage>> =\n SupabaseBindingOptions &\n SupabaseOptionsBase &\n (JwtSecretOption | JwksUrlOption) & {\n readonly contract: TContract;\n readonly contractJson?: never;\n };\n\nexport type SupabaseOptionsWithContractJson<TContract extends Contract<SqlStorage>> =\n SupabaseBindingOptions &\n SupabaseOptionsBase &\n (JwtSecretOption | JwksUrlOption) & {\n readonly contractJson: unknown;\n readonly contract?: never;\n readonly _contract?: TContract;\n };\n\nexport type SupabaseOptions<TContract extends Contract<SqlStorage>> =\n | SupabaseOptionsWithContract<TContract>\n | SupabaseOptionsWithContractJson<TContract>;\n\nfunction hasContractJson<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptions<TContract>,\n): options is SupabaseOptionsWithContractJson<TContract> {\n return 'contractJson' in options;\n}\n\nconst contractSerializer = new PostgresContractSerializer();\n\nfunction resolveContract<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptions<TContract>,\n): TContract {\n const contractInput = hasContractJson(options) ? options.contractJson : options.contract;\n return blindCast<\n TContract,\n 'contractSerializer.deserializeContract returns a validated TContract'\n >(contractSerializer.deserializeContract(contractInput));\n}\n\nfunction resolveKeyMaterial<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptions<TContract>,\n): KeyMaterial {\n const jwtSecret = 'jwtSecret' in options ? options.jwtSecret : undefined;\n const jwksUrl = 'jwksUrl' in options ? options.jwksUrl : undefined;\n\n if (jwtSecret !== undefined && jwksUrl !== undefined) {\n throw new SupabaseConfigError('Provide either jwtSecret or jwksUrl, not both');\n }\n if (jwtSecret === undefined && jwksUrl === undefined) {\n throw new SupabaseConfigError('Either jwtSecret or jwksUrl is required');\n }\n\n if (jwtSecret !== undefined) {\n return { kind: 'secret', key: new TextEncoder().encode(jwtSecret) };\n }\n\n if (jwksUrl !== undefined) {\n return { kind: 'jwks', keyset: createRemoteJWKSet(new URL(jwksUrl)) };\n }\n\n throw new SupabaseConfigError('Either jwtSecret or jwksUrl is required');\n}\n\nfunction toPool<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptions<TContract>,\n): { pool: Pool; owned: boolean } | undefined {\n if (options.pg instanceof Pool) {\n return { pool: options.pg, owned: false };\n }\n if (typeof options.url === 'string') {\n return {\n pool: new Pool({\n connectionString: options.url,\n connectionTimeoutMillis: options.poolOptions?.connectionTimeoutMillis ?? 20_000,\n idleTimeoutMillis: options.poolOptions?.idleTimeoutMillis ?? 30_000,\n }),\n owned: true,\n };\n }\n return undefined;\n}\n\nfunction withSupabaseDescriptor(\n extensions: readonly SqlRuntimeExtensionDescriptor<SupabaseTargetId>[] | undefined,\n): readonly SqlRuntimeExtensionDescriptor<SupabaseTargetId>[] {\n const packs = extensions ?? [];\n return packs.some((pack) => pack.id === supabaseRuntimeDescriptor.id)\n ? packs\n : [...packs, supabaseRuntimeDescriptor];\n}\n\nexport default async function supabase<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptionsWithContract<TContract>,\n): Promise<SupabaseDb<TContract>>;\nexport default async function supabase<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptionsWithContractJson<TContract>,\n): Promise<SupabaseDb<TContract>>;\nexport default async function supabase<TContract extends Contract<SqlStorage>>(\n options: SupabaseOptions<TContract>,\n): Promise<SupabaseDb<TContract>> {\n const keyMaterial = resolveKeyMaterial(options);\n const contract = resolveContract(options);\n\n const stack = createSqlExecutionStack({\n target: postgresTarget,\n adapter: postgresAdapter,\n driver: postgresDriver,\n extensionPacks: withSupabaseDescriptor(options.extensions),\n });\n\n const context = createExecutionContext({ contract, stack });\n const rawCodecInferer = stack.adapter.rawCodecInferer;\n const rawSqlTag: RawSqlTag = createRawSql(rawCodecInferer);\n\n const poolEntry = toPool(options);\n let closed = false;\n\n const stackInstance = instantiateExecutionStack(stack);\n const driverDescriptor = stack.driver;\n if (!driverDescriptor) {\n throw new Error('Driver descriptor missing from execution stack');\n }\n const driver = driverDescriptor.create({ cursor: { disabled: true } });\n\n if (poolEntry) {\n await driver.connect({ kind: 'pgPool', pool: poolEntry.pool });\n }\n\n const runtime: SupabaseRuntime & SupabaseRuntimeImpl<TContract> = new SupabaseRuntimeImpl({\n context,\n adapter: stackInstance.adapter,\n driver,\n ...ifDefined('verifyMarker', options.verifyMarker),\n ...ifDefined('middleware', options.middleware),\n });\n\n async function verifyJwt(jwt: string): Promise<JWTVerifyResult> {\n try {\n if (keyMaterial.kind === 'secret') {\n return await jwtVerify(jwt, keyMaterial.key);\n }\n return await jwtVerify(jwt, keyMaterial.keyset);\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err);\n throw new InvalidJwtError(reason);\n }\n }\n\n function buildRoleBoundDb(binding: SupabaseRoleBinding): RoleBoundDb<TContract> {\n const roleSql: Db<TContract> = sql<TContract>({ context, rawCodecInferer });\n const roleOrm: OrmClient<TContract> = orm({\n runtime: {\n execute(plan) {\n return runtime.executeWithRole(plan, binding);\n },\n // connection() returns a role session; this is the enforcement path for ORM scope\n // operations (mutations, includes) — every statement runs role-bound.\n connection: () => runtime.openRoleSession(binding),\n },\n context,\n });\n\n return {\n sql: roleSql,\n orm: roleOrm,\n raw: rawSqlTag,\n execute<Row>(\n plan: (SqlExecutionPlan<Row> | SqlQueryPlan<Row>) & { readonly _row?: Row },\n execOptions?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n return runtime.executeWithRole<Row>(plan, binding, execOptions);\n },\n transaction<R>(fn: (tx: TransactionContext) => PromiseLike<R>): Promise<R> {\n return withTransaction({ connection: () => runtime.openRoleSession(binding) }, fn);\n },\n };\n }\n\n async function closeDb(): Promise<void> {\n if (closed) return;\n closed = true;\n await runtime.close();\n if (poolEntry?.owned) {\n await poolEntry.pool.end().catch(() => undefined);\n }\n }\n\n return {\n context,\n stack,\n\n async asUser(jwt: string): Promise<RoleBoundDb<TContract>> {\n const { payload } = await verifyJwt(jwt);\n const rawRole = payload['role'];\n const roleStr = typeof rawRole === 'string' ? rawRole : 'authenticated';\n const role: SupabaseRoleBinding['role'] =\n roleStr === 'anon' || roleStr === 'authenticated' || roleStr === 'service_role'\n ? roleStr\n : 'authenticated';\n const binding: SupabaseRoleBinding = { role, claims: payload };\n return buildRoleBoundDb(binding);\n },\n\n asAnon(): RoleBoundDb<TContract> {\n return buildRoleBoundDb({ role: 'anon', claims: {} });\n },\n\n asServiceRole(): RoleBoundDb<TContract> {\n return buildRoleBoundDb({ role: 'service_role', claims: {} });\n },\n\n close: closeDb,\n [Symbol.asyncDispose]: closeDb,\n };\n}\n","import { supabaseRuntimeDescriptor } from '../runtime/descriptor';\n\nexport default supabaseRuntimeDescriptor;\n\nexport type {\n RoleBoundDb,\n SupabaseDb,\n SupabaseOptions,\n SupabaseOptionsWithContract,\n SupabaseOptionsWithContractJson,\n SupabaseTargetId,\n} from '../runtime/supabase';\nexport { default as supabase, InvalidJwtError, SupabaseConfigError } from '../runtime/supabase';\nexport type {\n RoleSession,\n SupabaseRoleBinding,\n SupabaseRuntime,\n} from '../runtime/supabase-runtime';\nexport { SupabaseRuntimeImpl } from '../runtime/supabase-runtime';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAa,4BAAuE;CAClF,MAAM;CACN,IAAI;CACKA;CACT,UAAU;CACV,UAAU;CACV,cAAc,CAAC;CACf,SAAS;EACP,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;AACF;;;ACGA,IAAa,sBAAb,cAEU,oBAA+B;;;;;;CAMvC,MAAM,gBAAgB,SAA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e,MAHrC,YAAY,UAAU,YAAY,mBAAmB,YAAY,iBAC7D,UACA;IACuC,QAAQ;GACvB,CAAC;EACjC;EAEA,SAAiC;GAC/B,OAAO,iBAAiB;IAAE,MAAM;IAAQ,QAAQ,CAAC;GAAE,CAAC;EACtD;EAEA,gBAAwC;GACtC,OAAO,iBAAiB;IAAE,MAAM;IAAgB,QAAQ,CAAC;GAAE,CAAC;EAC9D;EAEA,OAAO;GACN,OAAO,eAAe;CACzB;AACF;;;AChUA,IAAA,kBAAe"}
|
package/dist/test/utils.d.mts
CHANGED
|
@@ -2,10 +2,9 @@ import { Client } from "pg";
|
|
|
2
2
|
|
|
3
3
|
//#region test/supabase-bootstrap.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Seeds the database with the external Supabase schemas and
|
|
6
|
-
* caller passes an already-connected `pg.Client` — this function does not
|
|
7
|
-
* open or close connections
|
|
8
|
-
* test's other setup steps.
|
|
5
|
+
* Seeds the database with the external Supabase schemas, tables, roles, and grants.
|
|
6
|
+
* The caller passes an already-connected `pg.Client` — this function does not
|
|
7
|
+
* open or close connections.
|
|
9
8
|
*
|
|
10
9
|
* Creates two schemas (`auth`, `storage`) and four tables whose columns
|
|
11
10
|
* exactly match the `@prisma-next/extension-supabase` contract:
|
|
@@ -15,8 +14,10 @@ import { Client } from "pg";
|
|
|
15
14
|
* - `storage.buckets` — id text PK, name text, created_at timestamptz, updated_at timestamptz
|
|
16
15
|
* - `storage.objects` — id uuid PK, bucket_id text, name text, created_at timestamptz, updated_at timestamptz
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
* the `
|
|
17
|
+
* Creates the three Postgres roles and grants that mirror a real Supabase database.
|
|
18
|
+
* `ALTER DEFAULT PRIVILEGES` covers tables created after the shim runs (e.g. via `dbInit`).
|
|
19
|
+
* WAL grants are guarded by a schema-existence check — a PGlite single-connection
|
|
20
|
+
* accommodation so role-bound sessions can interleave with the WAL drain query.
|
|
20
21
|
*/
|
|
21
22
|
declare function bootstrapSupabaseShim(client: Client): Promise<void>;
|
|
22
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/supabase-bootstrap.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/supabase-bootstrap.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;iBAiDsB,qBAAA,CAAsB,MAAA,EAAQ,MAAA,GAAS,OAAO"}
|