@supabase/lite 0.2.1-next.2 → 0.3.1-next.1
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/README.md +1 -2
- package/STATUS.md +18 -30
- package/dist/{Connection-CSVCuMv-.d.ts → Connection-DF_xKWko.d.ts} +5 -1
- package/dist/cli/index.js +144 -117
- package/dist/cli/lib.js +38 -32
- package/dist/db/fallback.d.ts +1 -1
- package/dist/db/postgres/{BasePostgresConnection-B7zHDAib.d.ts → BasePostgresConnection-NlNmZWv1.d.ts} +5 -1
- package/dist/db/postgres/PostgresConnection.d.ts +1 -1
- package/dist/db/postgres/PostgresConnection.js +20 -23
- package/dist/db/postgres/pglite/PgliteConnection.d.ts +1 -1
- package/dist/db/postgres/pglite/PgliteConnection.js +26 -27
- package/dist/index.d.ts +3 -3
- package/dist/index.js +42 -50
- package/dist/vite/index.d.ts +1 -0
- package/package.json +3 -7
package/dist/db/fallback.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IConnectionConfig, C as Connection } from '../Connection-
|
|
1
|
+
import { I as IConnectionConfig, C as Connection } from '../Connection-DF_xKWko.js';
|
|
2
2
|
import 'kysely';
|
|
3
3
|
|
|
4
4
|
declare function createConnection<E extends IConnectionConfig = IConnectionConfig>(_config?: E): Promise<Connection>;
|
|
@@ -6,16 +6,20 @@ interface IBasePostgresConnectionConfig extends IConnectionConfig {
|
|
|
6
6
|
declare abstract class BasePostgresConnection<Driver = unknown, DB = any> extends Connection<Driver, DB> {
|
|
7
7
|
abstract driver: Driver;
|
|
8
8
|
dialect: "postgres";
|
|
9
|
+
/** REST spec harness sets this while a per-case `BEGIN` is open on the shared connection. */
|
|
10
|
+
harnessHoldingOuterTx: boolean;
|
|
9
11
|
constructor(options: IBasePostgresConnectionConfig);
|
|
10
12
|
introspect(options?: {
|
|
11
13
|
useCache?: boolean;
|
|
12
14
|
}): Promise<IntrospectResult>;
|
|
13
15
|
private rlsState;
|
|
14
16
|
/**
|
|
15
|
-
* Detect if any table has RLS enabled, and if so ensure
|
|
17
|
+
* Detect if any table has RLS enabled, and if so ensure Supabase request
|
|
16
18
|
* roles exist with default privileges. Runs once per connection.
|
|
17
19
|
*/
|
|
18
20
|
private ensureRlsContext;
|
|
21
|
+
private postgresTransactionActive;
|
|
22
|
+
private applyJwtSessionContext;
|
|
19
23
|
withContext<T>(vars: VarsContext | undefined, fn: (db: Kysely<any>) => Promise<T>, opts?: ConnectionContextOptions): Promise<T>;
|
|
20
24
|
onPostgrestAST(ast: AnyAST): Promise<AnyAST>;
|
|
21
25
|
transaction(statements: string[], opts?: TransactionOptions): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import postgres from 'postgres';
|
|
2
|
-
import { I as IBasePostgresConnectionConfig, B as BasePostgresConnection } from './BasePostgresConnection-
|
|
2
|
+
import { I as IBasePostgresConnectionConfig, B as BasePostgresConnection } from './BasePostgresConnection-NlNmZWv1.js';
|
|
3
3
|
import '@supabase/lite';
|
|
4
4
|
import 'kysely';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import F from'postgres';import {PostgresJSDialect}from'kysely-postgres-js';import {Kysely,sql}from'kysely';import {Connection,invariant,RelationNotFoundError}from'@supabase/lite';try {
|
|
2
2
|
/**
|
|
3
3
|
* Adding this to avoid warnings from node:sqlite being experimental
|
|
4
4
|
*/
|
|
@@ -8,7 +8,12 @@ import x from'postgres';import {PostgresJSDialect}from'kysely-postgres-js';impor
|
|
|
8
8
|
return emitWarning(warning, ...args);
|
|
9
9
|
};
|
|
10
10
|
} catch {}
|
|
11
|
-
var
|
|
11
|
+
var $=["anon","authenticated","service_role"];function v(c){return c==="service_role"?"NOLOGIN BYPASSRLS":"NOLOGIN"}function D(c){return c.size===0?"":`DO $$ BEGIN${[...c].map(s=>`
|
|
12
|
+
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${s}') THEN
|
|
13
|
+
CREATE ROLE ${s} ${v(s)};
|
|
14
|
+
END IF;`).join("")}
|
|
15
|
+
END $$;
|
|
16
|
+
`}var g=D(new Set($));var m="anon, authenticated, service_role",U=new Set(["anon","authenticated","service_role"]);function A(c){return `"${c.replace(/"/g,'""')}"`}var p=class extends Error{constructor(s){super("Force rollback");this.result=s;}},E=class extends Connection{dialect="postgres";harnessHoldingOuterTx=false;constructor(n){super({...n,baseSchema:`
|
|
12
17
|
${n.baseSchema??""}
|
|
13
18
|
|
|
14
19
|
CREATE SCHEMA IF NOT EXISTS auth;
|
|
@@ -35,7 +40,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
35
40
|
'{}'
|
|
36
41
|
)::jsonb;
|
|
37
42
|
$$ LANGUAGE SQL STABLE;
|
|
38
|
-
`});}async introspect(n){invariant(typeof n=="object"||n===void 0,"options must be an object");let
|
|
43
|
+
`});}async introspect(n){invariant(typeof n=="object"||n===void 0,"options must be an object");let s=n?.useCache??false,t=await this.readCachedIntrospection({useCache:s});if(t)return t;try{let i=(await sql`
|
|
39
44
|
SELECT
|
|
40
45
|
tbls.table_name AS "name",
|
|
41
46
|
tbls.table_schema AS "schema",
|
|
@@ -90,6 +95,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
90
95
|
END AS "is_identity",
|
|
91
96
|
COALESCE(cols.collation_name, '') AS "collation",
|
|
92
97
|
cols.udt_name AS "udt_name",
|
|
98
|
+
CASE WHEN pt.typtype = 'd' THEN pt.typname ELSE cols.udt_name END AS "domain_type",
|
|
93
99
|
CASE WHEN cols.is_generated = 'NEVER' THEN false ELSE true END AS "is_generated"
|
|
94
100
|
FROM information_schema.columns cols
|
|
95
101
|
LEFT JOIN pg_catalog.pg_class c ON c.relname = cols.table_name
|
|
@@ -100,7 +106,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
100
106
|
LEFT JOIN pg_catalog.pg_type pt ON pt.oid = attr.atttypid
|
|
101
107
|
WHERE cols.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
102
108
|
ORDER BY cols.table_schema, cols.table_name, cols.ordinal_position
|
|
103
|
-
`.execute(this.kysely)).rows.map(e=>({table:e.table,schema:e.schema,name:e.name,type:e.type,nullable:e.nullable,default_value:e.default_value,is_primary_key:!1,ordinal_position:Number(e.ordinal_position),character_maximum_length:e.character_maximum_length??null,precision:e.precision??null,is_identity:e.is_identity,collation:e.collation,pg_type:e.udt_name??void 0,is_generated:e.is_generated??!1})),
|
|
109
|
+
`.execute(this.kysely)).rows.map(e=>({table:e.table,schema:e.schema,name:e.name,type:e.type,nullable:e.nullable,default_value:e.default_value,is_primary_key:!1,ordinal_position:Number(e.ordinal_position),character_maximum_length:e.character_maximum_length??null,precision:e.precision??null,is_identity:e.is_identity,collation:e.collation,pg_type:e.domain_type??e.udt_name??void 0,is_generated:e.is_generated??!1})),r=(await sql`
|
|
104
110
|
SELECT
|
|
105
111
|
ns.nspname AS "schema",
|
|
106
112
|
cl.relname AS "table",
|
|
@@ -125,7 +131,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
125
131
|
'information_schema'
|
|
126
132
|
, 'pg_catalog')
|
|
127
133
|
ORDER BY ns.nspname, cl.relname, con.conname, cols.ord
|
|
128
|
-
`.execute(this.kysely)).rows.map(e=>({table:e.table,column:e.column,schema:e.schema,ref_table:e.ref_table,ref_column:e.ref_column,foreign_key_name:e.foreign_key_name,fk_def:e.fk_def,on_update:"",on_delete:""})),
|
|
134
|
+
`.execute(this.kysely)).rows.map(e=>({table:e.table,column:e.column,schema:e.schema,ref_table:e.ref_table,ref_column:e.ref_column,foreign_key_name:e.foreign_key_name,fk_def:e.fk_def,on_update:"",on_delete:""})),_=(await sql`
|
|
129
135
|
SELECT
|
|
130
136
|
ns.nspname AS "schema",
|
|
131
137
|
cl.relname AS "table",
|
|
@@ -142,7 +148,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
142
148
|
'information_schema'
|
|
143
149
|
, 'pg_catalog')
|
|
144
150
|
GROUP BY ns.nspname, cl.relname, con.oid
|
|
145
|
-
`.execute(this.kysely)).rows.map(e=>({table:e.table,columns:e.columns,schema:e.schema,field_count:e.columns.length})),
|
|
151
|
+
`.execute(this.kysely)).rows.map(e=>({table:e.table,columns:e.columns,schema:e.schema,field_count:e.columns.length})),h=new Set(_.flatMap(e=>e.columns.map(x=>`${e.schema}.${e.table}.${x}`)));for(let e of l)e.is_primary_key=h.has(`${e.schema}.${e.table}.${e.name}`);let R=(await sql`
|
|
146
152
|
SELECT
|
|
147
153
|
tnsp.nspname AS "schema",
|
|
148
154
|
cl.relname AS "table",
|
|
@@ -171,7 +177,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
171
177
|
FROM pg_views views
|
|
172
178
|
WHERE views.schemaname NOT IN ('information_schema', 'pg_catalog')
|
|
173
179
|
ORDER BY views.schemaname, views.viewname
|
|
174
|
-
`.execute(this.kysely)).rows.map(e=>({name:e.name,schema:e.schema,sql:e.sql??""})),
|
|
180
|
+
`.execute(this.kysely)).rows.map(e=>({name:e.name,schema:e.schema,sql:e.sql??""})),T=(await sql`
|
|
175
181
|
SELECT
|
|
176
182
|
n.nspname AS "schema",
|
|
177
183
|
cl.relname AS "table",
|
|
@@ -183,7 +189,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
183
189
|
c.contype = 'c'
|
|
184
190
|
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
185
191
|
ORDER BY n.nspname, cl.relname
|
|
186
|
-
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,expression:e.expression??""})),
|
|
192
|
+
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,expression:e.expression??""})),L=(await sql`
|
|
187
193
|
SELECT
|
|
188
194
|
n.nspname AS "schema",
|
|
189
195
|
cl.relname AS "table",
|
|
@@ -198,7 +204,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
198
204
|
c.contype = 'u'
|
|
199
205
|
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
200
206
|
GROUP BY n.nspname, cl.relname, c.conname, c.oid
|
|
201
|
-
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,name:e.name,columns:e.columns})),
|
|
207
|
+
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,name:e.name,columns:e.columns})),w=(await sql`
|
|
202
208
|
SELECT
|
|
203
209
|
n.nspname AS "schema",
|
|
204
210
|
cl.relname AS "table",
|
|
@@ -213,7 +219,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
213
219
|
n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
214
220
|
AND cl.relkind IN ('r', 'v', 'm', 'f', 'p')
|
|
215
221
|
AND d.description IS NOT NULL
|
|
216
|
-
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,column:e.column??void 0,text:e.text})),
|
|
222
|
+
`.execute(this.kysely)).rows.map(e=>({schema:e.schema,table:e.table,column:e.column??void 0,text:e.text})),b=await sql`
|
|
217
223
|
SELECT
|
|
218
224
|
n.nspname AS "schema",
|
|
219
225
|
t.typname AS "type",
|
|
@@ -224,7 +230,7 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
224
230
|
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
225
231
|
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
226
232
|
GROUP BY n.nspname, t.typname
|
|
227
|
-
`.execute(this.kysely),
|
|
233
|
+
`.execute(this.kysely),I=await sql`
|
|
228
234
|
SELECT
|
|
229
235
|
n.nspname AS "schema",
|
|
230
236
|
t.typname AS "type",
|
|
@@ -246,19 +252,10 @@ var E=class extends Error{constructor(o){super("Force rollback");this.result=o;}
|
|
|
246
252
|
AND NOT a.attisdropped
|
|
247
253
|
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
248
254
|
GROUP BY n.nspname, t.typname
|
|
249
|
-
`.execute(this.kysely),
|
|
255
|
+
`.execute(this.kysely),C=[...b.rows.map(e=>({schema:e.schema,type:e.type,kind:"enum",values:e.values})),...I.rows.map(e=>({schema:e.schema,type:e.type,kind:"composite",fields:e.fields}))],k=(await sql`SELECT current_database() AS "name"`.execute(this.kysely)).rows[0]?.name??"postgres",f={tables:i,columns:l,indexes:R,foreign_keys:r,primary_keys:_,views:O,triggers:[],check_constraints:T,unique_constraints:L,comments:w,custom_types:C,database_name:k,version:""};return await this.writeCachedIntrospection(f,{useDriver:s}),f}catch(o){return console.error("Introspection failed:",o),{tables:[],columns:[],indexes:[],foreign_keys:[],primary_keys:[],views:[],triggers:[],check_constraints:[],unique_constraints:[],comments:[],custom_types:[],database_name:"postgres",version:""}}}rlsState="unknown";async ensureRlsContext(){if(this.rlsState!=="unknown")return this.rlsState==="active";let n=await sql`
|
|
250
256
|
SELECT count(*) ::text as count FROM pg_class WHERE relrowsecurity = true
|
|
251
|
-
`.execute(this.kysely);if(!(Number(n.rows[0]?.count??0)>0))return this.rlsState="inactive",false;this.rlsState="active",await sql`
|
|
252
|
-
DO $$ BEGIN
|
|
253
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'anon') THEN
|
|
254
|
-
CREATE ROLE anon NOLOGIN;
|
|
255
|
-
END IF;
|
|
256
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'authenticated') THEN
|
|
257
|
-
CREATE ROLE authenticated NOLOGIN;
|
|
258
|
-
END IF;
|
|
259
|
-
END $$
|
|
260
|
-
`.execute(this.kysely);let t=await sql`
|
|
257
|
+
`.execute(this.kysely);if(!(Number(n.rows[0]?.count??0)>0))return this.rlsState="inactive",false;this.rlsState="active",await sql.raw(g).execute(this.kysely);let t=await sql`
|
|
261
258
|
SELECT DISTINCT n.nspname FROM pg_class c
|
|
262
259
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
263
260
|
WHERE c.relrowsecurity = true
|
|
264
|
-
`.execute(this.kysely);for(let{nspname:
|
|
261
|
+
`.execute(this.kysely);for(let{nspname:o}of t.rows){let i=A(o);await sql.raw(`GRANT USAGE ON SCHEMA ${i} TO ${m}`).execute(this.kysely),await sql.raw(`GRANT ALL ON ALL TABLES IN SCHEMA ${i} TO ${m}`).execute(this.kysely),await sql.raw(`GRANT ALL ON ALL SEQUENCES IN SCHEMA ${i} TO ${m}`).execute(this.kysely),await sql.raw(`ALTER DEFAULT PRIVILEGES IN SCHEMA ${i} GRANT ALL ON TABLES TO ${m}`).execute(this.kysely),await sql.raw(`ALTER DEFAULT PRIVILEGES IN SCHEMA ${i} GRANT ALL ON SEQUENCES TO ${m}`).execute(this.kysely);}return true}async postgresTransactionActive(n){try{return await sql`SAVEPOINT __supalite_outer_tx_check`.execute(n),await sql`RELEASE SAVEPOINT __supalite_outer_tx_check`.execute(n),!0}catch{return false}}async applyJwtSessionContext(n,s,t){let o=s.auth,i=o?.role||"anon",d=String(o?.uid??""),l=o?.jwt;await sql`SELECT set_config('role', ${i}, true)`.execute(n),await sql`SELECT set_config('request.jwt.claim.sub', ${d}, true)`.execute(n),await sql`SELECT set_config('request.jwt.claim.role', ${i}, true)`.execute(n),t&&await sql.raw(`SET LOCAL ROLE ${A(i)}`).execute(n),l&&typeof l=="object"&&await sql`SELECT set_config('request.jwt.claims', ${JSON.stringify(l)}, true)`.execute(n);}async withContext(n,s,t){let o=t?.forceRollback===true;if(!o&&!n)return s(this.kysely);let i=n?await this.ensureRlsContext():false,l=n?.auth?.role||"anon",u=typeof l=="string"&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)&&!U.has(l);if(!o&&!i&&!u)return s(this.kysely);if(!o&&u)return this.harnessHoldingOuterTx?(invariant(await this.postgresTransactionActive(this.kysely),"harnessHoldingOuterTx is set but the connection has no open PostgreSQL transaction; wrap REST requests in BEGIN/ROLLBACK in the spec harness"),await this.applyJwtSessionContext(this.kysely,n,true),s(this.kysely)):this.kysely.transaction().execute(async r=>(await this.applyJwtSessionContext(r,n,true),s(r)));if(!o&&i&&!u)return this.kysely.transaction().execute(async r=>(await this.applyJwtSessionContext(r,n,true),s(r)));try{return await this.kysely.transaction().execute(async r=>{n&&(i||u)&&await this.applyJwtSessionContext(r,n,u);let S=await s(r);if(o)throw new p(S);return S})}catch(r){if(r instanceof p)return r.result;throw r}}async onPostgrestAST(n){if(!n.from)return n;let s=n.schema??"public",t=n.from,o=await this.introspect({useCache:true});if(!o.tables.some(i=>i.name===t&&i.schema===s)&&!o.views.some(i=>i.name===t&&i.schema===s))throw new RelationNotFoundError(s,t);return n}async transaction(n,s){await this.exec("BEGIN");try{for(let t of n)await this.exec(t);await this.exec("COMMIT");}catch(t){throw await this.exec("ROLLBACK"),t}finally{s?.intent==="migration"&&await this.clearSchemaCache();}}};var N=class extends E{driver;dialect="postgres";constructor(n){super(n),this.driver=F(n.url??"",{types:{bigint:{to:20,from:[20],serialize:t=>t.toString(),parse:t=>{let o=Number(t);return Number.isSafeInteger(o)?o:BigInt(t)}},json:{to:114,from:[114],serialize:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},jsonb:{to:3802,from:[3802],serialize:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},numeric:{to:1700,from:[1700],serialize:t=>String(t),parse:t=>{let o=Number(t);return Number.isFinite(o)&&String(o)===t?o:t}},date:{to:1082,from:[1082],serialize:t=>t,parse:t=>t},time:{to:1083,from:[1083],serialize:t=>t,parse:t=>t},timestamp:{to:1114,from:[1114],serialize:t=>t,parse:t=>t},timestamptz:{to:1184,from:[1184],serialize:t=>t,parse:t=>t},timetz:{to:1266,from:[1266],serialize:t=>t,parse:t=>t}}});let s=new PostgresJSDialect({postgres:this.driver});this.kysely=new Kysely({dialect:s});}async close(){await this.driver.end();}};function ae(c){return new N(c)}export{N as PostgresConnection,ae as createPostgresConnection};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PGliteOptions, PGlite } from '@electric-sql/pglite';
|
|
2
2
|
export { PGlite } from '@electric-sql/pglite';
|
|
3
|
-
import { I as IBasePostgresConnectionConfig, B as BasePostgresConnection } from '../BasePostgresConnection-
|
|
3
|
+
import { I as IBasePostgresConnectionConfig, B as BasePostgresConnection } from '../BasePostgresConnection-NlNmZWv1.js';
|
|
4
4
|
import { ConnectionMigrator, SchemaDiffResult, PlanResult, PlanStep } from '@supabase/lite';
|
|
5
5
|
import 'kysely';
|
|
6
6
|
|
|
@@ -8,8 +8,14 @@ import {PGlite}from'@electric-sql/pglite';export{PGlite}from'@electric-sql/pglit
|
|
|
8
8
|
return emitWarning(warning, ...args);
|
|
9
9
|
};
|
|
10
10
|
} catch {}
|
|
11
|
-
async function
|
|
12
|
-
|
|
11
|
+
async function se(n){let t;if(typeof n=="string"&&(t=n),typeof n=="object"&&n.dataDir&&(t=n.dataDir),t){let{mkdir:e}=await import('node:fs');e(t,{recursive:true},s=>{if(s)throw s});}}var R=class{#e;#t;constructor(t,e){this.#e=t,this.#t=e;}async acquireConnection(){return new T(this.#e)}async beginTransaction(t,e){await t.executeQuery(CompiledQuery.raw("BEGIN"));}async commitTransaction(t){await t.executeQuery(CompiledQuery.raw("COMMIT"));}async rollbackTransaction(t){await t.executeQuery(CompiledQuery.raw("ROLLBACK"));}async destroy(){this.#t&&await this.#e.close();}async init(){}async releaseConnection(t){}},T=class{#e;constructor(t){this.#e=t;}async executeQuery(t){let e=await this.#e.query(t.sql,[...t.parameters]),s=e.affectedRows;return {rows:e.rows,numAffectedRows:typeof s=="number"?BigInt(s):void 0}}async*streamQuery(){throw new Error("PGlite does not support streaming.")}},g=class{client;#e=true;constructor(t,e){se(t);let s={...e};if(typeof t=="object"&&t instanceof PGlite){this.client=t,this.#e=false;return}typeof t=="string"?s={dataDir:t,...s}:s=t??{},this.client=new PGlite(s);}dialect={createAdapter:()=>new PostgresAdapter,createDriver:()=>new R(this.client,this.#e),createIntrospector:t=>new PostgresIntrospector(t),createQueryCompiler:()=>new PostgresQueryCompiler}};var E=["anon","authenticated","service_role"];function ae(n){return n==="service_role"?"NOLOGIN BYPASSRLS":"NOLOGIN"}function S(n){return n.size===0?"":`DO $$ BEGIN${[...n].map(e=>`
|
|
12
|
+
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${e}') THEN
|
|
13
|
+
CREATE ROLE ${e} ${ae(e)};
|
|
14
|
+
END IF;`).join("")}
|
|
15
|
+
END $$;
|
|
16
|
+
`}var B=S(new Set(E));function d(n,t){return n?n.quoted?n.value===t:n.value.toLowerCase()===t:false}function p(n){return n?.quoted?n.value:n?.value.toLowerCase()}function oe(n,t){let e="",s=t+1;for(;s<n.length;){if(n[s]==='"'&&n[s+1]==='"'){e+='"',s+=2;continue}if(n[s]==='"')return {token:{value:e,quoted:true},end:s+1};e+=n[s],s++;}return {token:{value:e,quoted:true},end:s}}function re(n,t){let e=t+1;for(;e<n.length;){if(n[e]==="'"&&n[e+1]==="'"){e+=2;continue}if(n[e]==="'")return e+1;e++;}return e}function ie(n,t){let e=/^\$[A-Za-z_][A-Za-z0-9_]*\$|^\$\$/.exec(n.slice(t))?.[0];if(!e)return;let s=t+e.length,a=n.indexOf(e,s);return a===-1?n.length:a+e.length}function O(n){let t=[],e=0;for(;e<n.length;){let s=n[e],a=n[e+1];if(/\s/.test(s)){e++;continue}if(s==="-"&&a==="-"){for(e+=2;e<n.length&&n[e]!==`
|
|
17
|
+
`;)e++;continue}if(s==="/"&&a==="*"){for(e+=2;e<n.length&&!(n[e]==="*"&&n[e+1]==="/");)e++;e=e<n.length?e+2:e;continue}if(s==="'"){e=re(n,e);continue}if(s==="$"){let r=ie(n,e);if(r!==void 0){e=r;continue}}if(s==='"'){let{token:r,end:c}=oe(n,e);t.push(r),e=c;continue}if(s===","||s===";"){t.push({value:s,quoted:false}),e++;continue}if(/[A-Za-z_]/.test(s)){let r=e;for(e++;e<n.length&&/[A-Za-z0-9_$]/.test(n[e]);)e++;t.push({value:n.slice(r,e).toLowerCase(),quoted:false});continue}e++;}return t}function $(n,t){let e=p(n[t]),s=p(n[t+1]);if((e==="create"||e==="alter")&&(s==="role"||s==="user"||s==="group"))return n[t+2]}function h(n){let t=new Set,e=O(n);for(let s=0;s<e.length;s++){if(p(e[s])!=="create")continue;let a=$(e,s);for(let r of E)d(a,r)&&t.add(r);}return t}function L(n,t,e){let s=new Set([";","as","by","check","for","granted","in","on","option","using","where","with"]);for(let a=t;a<n.length;a++){let r=p(n[a]);if(!r||s.has(r))return;for(let c of E)d(n[a],c)&&e.add(c);}}function ce(n){let t=[],e=[];for(let s of n){if(p(s)===";"){e.length>0&&t.push(e),e=[];continue}e.push(s);}return e.length>0&&t.push(e),t}function D(n,t){return n.some(e=>p(e)===t)}function le(n){let t=new Set,e=ce(O(n));for(let s of e){let a=p(s[0]);for(let i=0;i<s.length;i++){let u=p(s[i]);u==="to"&&(D(s,"grant")||D(s,"policy")||p(s[i-1])==="owner")&&L(s,i+1,t),u==="from"&&a==="revoke"&&L(s,i+1,t);}let r=s.findIndex(i=>p(i)==="to"),c=s.findIndex(i=>p(i)==="on");a==="grant"&&r>1&&(c===-1||r<c)&&L(s,1,t);}return t}function b(n){let t=h(n);return new Set([...le(n)].filter(e=>!t.has(e)))}function v(n){let t=h(n);return new Set(E.filter(e=>!t.has(e)))}function U(n,t){let e=O(n);if(e.length===0)return false;let s=$(e,0);if(s){for(let c of t)if(d(s,c))return true;return false}let a=p(e[0]),r=p(e[1]);if(a==="drop"&&(r==="role"||r==="user"||r==="group")){for(let c of e.slice(2))for(let i of t)if(d(c,i))return true}if(a==="comment"&&p(e[1])==="on"&&p(e[2])==="role"){for(let c of t)if(d(e[3],c))return true}return false}var y="anon, authenticated, service_role",pe=new Set(["anon","authenticated","service_role"]);function F(n){return `"${n.replace(/"/g,'""')}"`}var N=class extends Error{constructor(e){super("Force rollback");this.result=e;}},_=class extends Connection{dialect="postgres";harnessHoldingOuterTx=false;constructor(t){super({...t,baseSchema:`
|
|
18
|
+
${t.baseSchema??""}
|
|
13
19
|
|
|
14
20
|
CREATE SCHEMA IF NOT EXISTS auth;
|
|
15
21
|
|
|
@@ -35,7 +41,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
35
41
|
'{}'
|
|
36
42
|
)::jsonb;
|
|
37
43
|
$$ LANGUAGE SQL STABLE;
|
|
38
|
-
`});}async introspect(
|
|
44
|
+
`});}async introspect(t){invariant(typeof t=="object"||t===void 0,"options must be an object");let e=t?.useCache??false,s=await this.readCachedIntrospection({useCache:e});if(s)return s;try{let r=(await sql`
|
|
39
45
|
SELECT
|
|
40
46
|
tbls.table_name AS "name",
|
|
41
47
|
tbls.table_schema AS "schema",
|
|
@@ -48,7 +54,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
48
54
|
tbls.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
49
55
|
AND tbls.table_type IN ('BASE TABLE', 'FOREIGN TABLE')
|
|
50
56
|
ORDER BY tbls.table_schema, tbls.table_name
|
|
51
|
-
`.execute(this.kysely)).rows.map(
|
|
57
|
+
`.execute(this.kysely)).rows.map(o=>({name:o.name,schema:o.schema,type:"table",rows:Number(o.rows),sql:"",engine:"",collation:""})),i=(await sql`
|
|
52
58
|
SELECT
|
|
53
59
|
cols.table_name AS "table",
|
|
54
60
|
cols.table_schema AS "schema",
|
|
@@ -90,6 +96,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
90
96
|
END AS "is_identity",
|
|
91
97
|
COALESCE(cols.collation_name, '') AS "collation",
|
|
92
98
|
cols.udt_name AS "udt_name",
|
|
99
|
+
CASE WHEN pt.typtype = 'd' THEN pt.typname ELSE cols.udt_name END AS "domain_type",
|
|
93
100
|
CASE WHEN cols.is_generated = 'NEVER' THEN false ELSE true END AS "is_generated"
|
|
94
101
|
FROM information_schema.columns cols
|
|
95
102
|
LEFT JOIN pg_catalog.pg_class c ON c.relname = cols.table_name
|
|
@@ -100,7 +107,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
100
107
|
LEFT JOIN pg_catalog.pg_type pt ON pt.oid = attr.atttypid
|
|
101
108
|
WHERE cols.table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
102
109
|
ORDER BY cols.table_schema, cols.table_name, cols.ordinal_position
|
|
103
|
-
`.execute(this.kysely)).rows.map(
|
|
110
|
+
`.execute(this.kysely)).rows.map(o=>({table:o.table,schema:o.schema,name:o.name,type:o.type,nullable:o.nullable,default_value:o.default_value,is_primary_key:!1,ordinal_position:Number(o.ordinal_position),character_maximum_length:o.character_maximum_length??null,precision:o.precision??null,is_identity:o.is_identity,collation:o.collation,pg_type:o.domain_type??o.udt_name??void 0,is_generated:o.is_generated??!1})),m=(await sql`
|
|
104
111
|
SELECT
|
|
105
112
|
ns.nspname AS "schema",
|
|
106
113
|
cl.relname AS "table",
|
|
@@ -125,7 +132,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
125
132
|
'information_schema'
|
|
126
133
|
, 'pg_catalog')
|
|
127
134
|
ORDER BY ns.nspname, cl.relname, con.conname, cols.ord
|
|
128
|
-
`.execute(this.kysely)).rows.map(
|
|
135
|
+
`.execute(this.kysely)).rows.map(o=>({table:o.table,column:o.column,schema:o.schema,ref_table:o.ref_table,ref_column:o.ref_column,foreign_key_name:o.foreign_key_name,fk_def:o.fk_def,on_update:"",on_delete:""})),x=(await sql`
|
|
129
136
|
SELECT
|
|
130
137
|
ns.nspname AS "schema",
|
|
131
138
|
cl.relname AS "table",
|
|
@@ -142,7 +149,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
142
149
|
'information_schema'
|
|
143
150
|
, 'pg_catalog')
|
|
144
151
|
GROUP BY ns.nspname, cl.relname, con.oid
|
|
145
|
-
`.execute(this.kysely)).rows.map(
|
|
152
|
+
`.execute(this.kysely)).rows.map(o=>({table:o.table,columns:o.columns,schema:o.schema,field_count:o.columns.length})),q=new Set(x.flatMap(o=>o.columns.map(Z=>`${o.schema}.${o.table}.${Z}`)));for(let o of i)o.is_primary_key=q.has(`${o.schema}.${o.table}.${o.name}`);let W=(await sql`
|
|
146
153
|
SELECT
|
|
147
154
|
tnsp.nspname AS "schema",
|
|
148
155
|
cl.relname AS "table",
|
|
@@ -163,7 +170,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
163
170
|
'information_schema'
|
|
164
171
|
, 'pg_catalog')
|
|
165
172
|
GROUP BY tnsp.nspname, cl.relname, ic.relname, idx.indisunique
|
|
166
|
-
`.execute(this.kysely)).rows.map(
|
|
173
|
+
`.execute(this.kysely)).rows.map(o=>({table:o.table,name:o.name,unique:o.unique,columns:o.columns,schema:o.schema})),M=(await sql`
|
|
167
174
|
SELECT
|
|
168
175
|
views.schemaname AS "schema",
|
|
169
176
|
views.viewname AS "name",
|
|
@@ -171,7 +178,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
171
178
|
FROM pg_views views
|
|
172
179
|
WHERE views.schemaname NOT IN ('information_schema', 'pg_catalog')
|
|
173
180
|
ORDER BY views.schemaname, views.viewname
|
|
174
|
-
`.execute(this.kysely)).rows.map(
|
|
181
|
+
`.execute(this.kysely)).rows.map(o=>({name:o.name,schema:o.schema,sql:o.sql??""})),j=(await sql`
|
|
175
182
|
SELECT
|
|
176
183
|
n.nspname AS "schema",
|
|
177
184
|
cl.relname AS "table",
|
|
@@ -183,7 +190,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
183
190
|
c.contype = 'c'
|
|
184
191
|
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
185
192
|
ORDER BY n.nspname, cl.relname
|
|
186
|
-
`.execute(this.kysely)).rows.map(
|
|
193
|
+
`.execute(this.kysely)).rows.map(o=>({schema:o.schema,table:o.table,expression:o.expression??""})),Q=(await sql`
|
|
187
194
|
SELECT
|
|
188
195
|
n.nspname AS "schema",
|
|
189
196
|
cl.relname AS "table",
|
|
@@ -198,7 +205,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
198
205
|
c.contype = 'u'
|
|
199
206
|
AND n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
200
207
|
GROUP BY n.nspname, cl.relname, c.conname, c.oid
|
|
201
|
-
`.execute(this.kysely)).rows.map(
|
|
208
|
+
`.execute(this.kysely)).rows.map(o=>({schema:o.schema,table:o.table,name:o.name,columns:o.columns})),Y=(await sql`
|
|
202
209
|
SELECT
|
|
203
210
|
n.nspname AS "schema",
|
|
204
211
|
cl.relname AS "table",
|
|
@@ -213,7 +220,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
213
220
|
n.nspname NOT IN ('information_schema', 'pg_catalog')
|
|
214
221
|
AND cl.relkind IN ('r', 'v', 'm', 'f', 'p')
|
|
215
222
|
AND d.description IS NOT NULL
|
|
216
|
-
`.execute(this.kysely)).rows.map(
|
|
223
|
+
`.execute(this.kysely)).rows.map(o=>({schema:o.schema,table:o.table,column:o.column??void 0,text:o.text})),K=await sql`
|
|
217
224
|
SELECT
|
|
218
225
|
n.nspname AS "schema",
|
|
219
226
|
t.typname AS "type",
|
|
@@ -224,7 +231,7 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
224
231
|
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
225
232
|
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
226
233
|
GROUP BY n.nspname, t.typname
|
|
227
|
-
`.execute(this.kysely),
|
|
234
|
+
`.execute(this.kysely),V=await sql`
|
|
228
235
|
SELECT
|
|
229
236
|
n.nspname AS "schema",
|
|
230
237
|
t.typname AS "type",
|
|
@@ -246,23 +253,15 @@ async function B(n){let e;if(typeof n=="string"&&(e=n),typeof n=="object"&&n.dat
|
|
|
246
253
|
AND NOT a.attisdropped
|
|
247
254
|
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
248
255
|
GROUP BY n.nspname, t.typname
|
|
249
|
-
`.execute(this.kysely),
|
|
256
|
+
`.execute(this.kysely),z=[...K.rows.map(o=>({schema:o.schema,type:o.type,kind:"enum",values:o.values})),...V.rows.map(o=>({schema:o.schema,type:o.type,kind:"composite",fields:o.fields}))],X=(await sql`SELECT current_database() AS "name"`.execute(this.kysely)).rows[0]?.name??"postgres",k={tables:r,columns:i,indexes:W,foreign_keys:m,primary_keys:x,views:M,triggers:[],check_constraints:j,unique_constraints:Q,comments:Y,custom_types:z,database_name:X,version:""};return await this.writeCachedIntrospection(k,{useDriver:e}),k}catch(a){return console.error("Introspection failed:",a),{tables:[],columns:[],indexes:[],foreign_keys:[],primary_keys:[],views:[],triggers:[],check_constraints:[],unique_constraints:[],comments:[],custom_types:[],database_name:"postgres",version:""}}}rlsState="unknown";async ensureRlsContext(){if(this.rlsState!=="unknown")return this.rlsState==="active";let t=await sql`
|
|
250
257
|
SELECT count(*) ::text as count FROM pg_class WHERE relrowsecurity = true
|
|
251
|
-
`.execute(this.kysely);if(!(Number(
|
|
252
|
-
DO $$ BEGIN
|
|
253
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'anon') THEN
|
|
254
|
-
CREATE ROLE anon NOLOGIN;
|
|
255
|
-
END IF;
|
|
256
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'authenticated') THEN
|
|
257
|
-
CREATE ROLE authenticated NOLOGIN;
|
|
258
|
-
END IF;
|
|
259
|
-
END $$
|
|
260
|
-
`.execute(this.kysely);let o=await sql`
|
|
258
|
+
`.execute(this.kysely);if(!(Number(t.rows[0]?.count??0)>0))return this.rlsState="inactive",false;this.rlsState="active",await sql.raw(B).execute(this.kysely);let s=await sql`
|
|
261
259
|
SELECT DISTINCT n.nspname FROM pg_class c
|
|
262
260
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
263
261
|
WHERE c.relrowsecurity = true
|
|
264
|
-
`.execute(this.kysely);for(let{nspname:
|
|
262
|
+
`.execute(this.kysely);for(let{nspname:a}of s.rows){let r=F(a);await sql.raw(`GRANT USAGE ON SCHEMA ${r} TO ${y}`).execute(this.kysely),await sql.raw(`GRANT ALL ON ALL TABLES IN SCHEMA ${r} TO ${y}`).execute(this.kysely),await sql.raw(`GRANT ALL ON ALL SEQUENCES IN SCHEMA ${r} TO ${y}`).execute(this.kysely),await sql.raw(`ALTER DEFAULT PRIVILEGES IN SCHEMA ${r} GRANT ALL ON TABLES TO ${y}`).execute(this.kysely),await sql.raw(`ALTER DEFAULT PRIVILEGES IN SCHEMA ${r} GRANT ALL ON SEQUENCES TO ${y}`).execute(this.kysely);}return true}async postgresTransactionActive(t){try{return await sql`SAVEPOINT __supalite_outer_tx_check`.execute(t),await sql`RELEASE SAVEPOINT __supalite_outer_tx_check`.execute(t),!0}catch{return false}}async applyJwtSessionContext(t,e,s){let a=e.auth,r=a?.role||"anon",c=String(a?.uid??""),i=a?.jwt;await sql`SELECT set_config('role', ${r}, true)`.execute(t),await sql`SELECT set_config('request.jwt.claim.sub', ${c}, true)`.execute(t),await sql`SELECT set_config('request.jwt.claim.role', ${r}, true)`.execute(t),s&&await sql.raw(`SET LOCAL ROLE ${F(r)}`).execute(t),i&&typeof i=="object"&&await sql`SELECT set_config('request.jwt.claims', ${JSON.stringify(i)}, true)`.execute(t);}async withContext(t,e,s){let a=s?.forceRollback===true;if(!a&&!t)return e(this.kysely);let r=t?await this.ensureRlsContext():false,i=t?.auth?.role||"anon",u=typeof i=="string"&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&!pe.has(i);if(!a&&!r&&!u)return e(this.kysely);if(!a&&u)return this.harnessHoldingOuterTx?(invariant(await this.postgresTransactionActive(this.kysely),"harnessHoldingOuterTx is set but the connection has no open PostgreSQL transaction; wrap REST requests in BEGIN/ROLLBACK in the spec harness"),await this.applyJwtSessionContext(this.kysely,t,true),e(this.kysely)):this.kysely.transaction().execute(async m=>(await this.applyJwtSessionContext(m,t,true),e(m)));if(!a&&r&&!u)return this.kysely.transaction().execute(async m=>(await this.applyJwtSessionContext(m,t,true),e(m)));try{return await this.kysely.transaction().execute(async m=>{t&&(r||u)&&await this.applyJwtSessionContext(m,t,u);let f=await e(m);if(a)throw new N(f);return f})}catch(m){if(m instanceof N)return m.result;throw m}}async onPostgrestAST(t){if(!t.from)return t;let e=t.schema??"public",s=t.from,a=await this.introspect({useCache:true});if(!a.tables.some(r=>r.name===s&&r.schema===e)&&!a.views.some(r=>r.name===s&&r.schema===e))throw new RelationNotFoundError(e,s);return t}async transaction(t,e){await this.exec("BEGIN");try{for(let s of t)await this.exec(s);await this.exec("COMMIT");}catch(s){throw await this.exec("ROLLBACK"),s}finally{e?.intent==="migration"&&await this.clearSchemaCache();}}};var G=(n,t=e=>e)=>{if(!n||n==="{}")return [];let e=n.slice(1,-1);if(e==="")return [];let s=[],a="",r=false,c=0;for(let i=0;i<e.length;i++){let u=e[i];u==='"'&&e[i-1]!=="\\"?(r=!r,a+=u):u==="{"&&!r?(c++,a+=u):u==="}"&&!r?(c--,a+=u):u===","&&!r&&c===0?(s.push(t(a)),a=""):a+=u;}return a!==""&&s.push(t(a)),s},fe=n=>n==="NULL"?null:n.startsWith('"')&&n.endsWith('"')?n.slice(1,-1).replace(/\\(.)/g,"$1"):n,de=n=>n==="NULL"?null:Number.parseInt(n,10);function J(n){return typeof n=="object"&&n!==null&&"text"in n&&"values"in n}function ye(n,t){if(n==null)return n;switch(t){case 20:return typeof n=="bigint"?n:BigInt(n);case 22:return Array.isArray(n)?n:typeof n=="string"?n.split(" ").map(Number).filter(e=>!Number.isNaN(e)):n;case 1002:case 1009:case 1015:return typeof n=="string"?G(n,fe):n;case 1005:case 1007:case 1016:return typeof n=="string"?G(n,de):n;default:return n}}function C(n){return {async query(t,e){let s=J(t)?t.text:t,a=J(t)?t.values:e??[],r=await n.driver.query(s,[...a]);return {rows:r.rows.map(i=>Object.fromEntries(r.fields.map(u=>[u.name,ye(i[u.name],u.dataTypeID)])))}}}}async function Ee(){try{return await import('@supabase/pg-delta')}catch(n){throw new Error("Postgres/PGlite schema diffing now requires a Bun/Node-compatible runtime with pg-delta available.",{cause:n})}}function Se(n){let t=/^drop table (.+)$/.exec(n);if(t)return {table:t[1],reason:"drop table"};let e=/^drop column (.+) on (.+)$/.exec(n);if(e)return {table:e[2],reason:`drop column ${e[1]}`};let s=/^drop sequence (.+)$/.exec(n);return s?{table:s[1],reason:"drop sequence"}:{table:"unknown",reason:n}}var A=class{constructor(t,e){this.from=t;this.desiredSchema=e;}#e;async#t(t){if(this.#e)return this.#e;let e=new this.from.constructor;try{let s=S(b(this.desiredSchema));return s&&await e.exec(s),await e.exec(this.desiredSchema),this.#e=await t(C(e)),this.#e}finally{await e.close();}}async diff(){let{createPlan:t,extractCatalog:e}=await Ee(),s=C(this.from),a=await this.#t(e),r=await e(s),c=await t(r,a);if(!c)return {diff:"",plan:{steps:[],warnings:[],unsafe:false}};let i=c.plan.risk?.level==="data_loss"?c.plan.risk.statements.map(Se):[],u=v(this.desiredSchema),m=c.plan.statements.filter(f=>!U(f,u));return {diff:m.join(`
|
|
265
263
|
|
|
266
|
-
`),plan:{steps:
|
|
264
|
+
`),plan:{steps:m.map(f=>({sql:f})),warnings:i,unsafe:c.plan.risk?.level==="data_loss"}}}async migratePlan(t,e){if(t.steps.length===0)return;if(t.unsafe&&!e?.force)throw new DataLossError(t.warnings??[]);let s=t.steps.map(i=>i.sql).join(`
|
|
265
|
+
`),a=h(s),r=new Set(t.steps.flatMap(i=>[...b(i.sql)]).filter(i=>!a.has(i))),c=S(r);c&&await this.from.exec(c),await this.from.transaction(t.steps.map(i=>i.sql),{intent:"migration"});}async migrate(t){let e=await this.diff();return await this.migratePlan(e.plan,t),e}safeSortPlanSteps(t){return t}};var I=class extends _{driver;dialect="postgres";#e=false;constructor(t={}){let e=new PGlite({...t.pgliteOptions,dataDir:t.url??void 0,extensions:{...t.pgliteOptions?.extensions,isn:isn,ltree:ltree,file_fdw:file_fdw,pgcrypto:pgcrypto},parsers:{20:a=>{let r=Number(a);return Number.isSafeInteger(r)?r:BigInt(a)},114:a=>JSON.parse(a),3802:a=>JSON.parse(a),1700:a=>{let r=Number(a);return Number.isFinite(r)&&String(r)===a?r:a},1082:a=>a,1083:a=>a,1114:a=>a,1184:a=>a,1266:a=>a,...t.pgliteOptions?.parsers}}),{dialect:s}=new g(e);super(t),this.driver=e,this.kysely=new Kysely({dialect:s});}async exec(t,...e){try{if(e.length>0){let{rows:a}=await sql(t,...e??[]).execute(this.kysely);return {rows:a}}return {rows:(await this.driver.exec(t))[0].rows}}catch(s){throw console.error(s),new Error(`Failed to execute query: ${t}`)}}async close(){this.#e||(this.#e=true,await this.clearSchemaCache(),await this.kysely.destroy(),await this.driver.close());}createMigrator(t){let e=[this.config.baseSchema,t].filter(Boolean).join(`
|
|
267
266
|
|
|
268
|
-
`);return new
|
|
267
|
+
`);return new A(this,e)}};async function tt(n={}){return new I(n)}export{I as PgliteConnection,tt as createPgliteConnection};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { SupabaseClientOptions } from '@supabase/supabase-js';
|
|
|
3
3
|
import { D as DefaultSchema, S as Schema } from './index-xv_pDjEt.js';
|
|
4
4
|
import { Connection, ConnectionMigrator, MaybePromise as MaybePromise$1, SchemaDiffResult, PlanStep, PlanResult, IConnectionConfig, Dialect as Dialect$2, IntrospectResult as IntrospectResult$1, TransactionOptions } from '@supabase/lite';
|
|
5
5
|
import * as hono_hono_base from 'hono/hono-base';
|
|
6
|
-
import { W as Where, a as IntrospectResult, b as CacheDriver, c as CacheSetOptions, A as AnyAST, V as VarsContext, T as TransactionOptions$1 } from './Connection-
|
|
7
|
-
export { d as AST, e as ASTType, f as AggregateFunction, B as BaseAST, g as BodyResult, h as CheckConstraintInfo, i as ColumnDef, j as ColumnDiff, k as ColumnInfo, l as ColumnRef, m as CommentInfo, C as Connection, n as ConnectionContextOptions, o as ConnectionMigrator, p as CustomTypesInfo, D as DataLossError, q as DataLossWarning, r as DeleteAST, s as Dialect, t as DiffResult, E as EmbedDef, u as EmbedTransform, v as ExplainOptions, F as FiltersResult, w as ForeignKeyDiff, x as ForeignKeyInfo, H as HeadersResult, I as IConnectionConfig, y as IndexDiff, z as IndexInfo, G as InsertAST, J as IntrospectOptions, K as JoinDef, L as JoinMap, M as Meta, N as MigrationError, O as OrderEntry, P as PlanResult, Q as PlanStep, R as PlanStepType, S as PreferToken, U as PrimaryKeyInfo, X as Qb, Y as QbDelete, Z as QbInsert, _ as QbSelect, $ as QbUpdate, a0 as QueryAST, a1 as QueryParamsResult, a2 as RelationNotFoundError, a3 as RouteResult, a4 as RpcAST, a5 as RpcResult, a6 as SchemaDiffResult, a7 as SelectEntry, a8 as SelectResult, a9 as TableDiff, aa as TableInfo, ab as TextSearchValue, ac as TransformsResult, ad as TranslatorConfig, ae as TriggerInfo, af as UniqueConstraintInfo, ag as UpdateAST, ah as UpsertAST, ai as UpsertResult, aj as ViewInfo, ak as WhereValue, al as isRef } from './Connection-
|
|
6
|
+
import { W as Where, a as IntrospectResult, b as CacheDriver, c as CacheSetOptions, A as AnyAST, V as VarsContext, T as TransactionOptions$1 } from './Connection-DF_xKWko.js';
|
|
7
|
+
export { d as AST, e as ASTType, f as AggregateFunction, B as BaseAST, g as BodyResult, h as CheckConstraintInfo, i as ColumnDef, j as ColumnDiff, k as ColumnInfo, l as ColumnRef, m as CommentInfo, C as Connection, n as ConnectionContextOptions, o as ConnectionMigrator, p as CustomTypesInfo, D as DataLossError, q as DataLossWarning, r as DeleteAST, s as Dialect, t as DiffResult, E as EmbedDef, u as EmbedTransform, v as ExplainOptions, F as FiltersResult, w as ForeignKeyDiff, x as ForeignKeyInfo, H as HeadersResult, I as IConnectionConfig, y as IndexDiff, z as IndexInfo, G as InsertAST, J as IntrospectOptions, K as JoinDef, L as JoinMap, M as Meta, N as MigrationError, O as OrderEntry, P as PlanResult, Q as PlanStep, R as PlanStepType, S as PreferToken, U as PrimaryKeyInfo, X as Qb, Y as QbDelete, Z as QbInsert, _ as QbSelect, $ as QbUpdate, a0 as QueryAST, a1 as QueryParamsResult, a2 as RelationNotFoundError, a3 as RouteResult, a4 as RpcAST, a5 as RpcResult, a6 as SchemaDiffResult, a7 as SelectEntry, a8 as SelectResult, a9 as TableDiff, aa as TableInfo, ab as TextSearchValue, ac as TransformsResult, ad as TranslatorConfig, ae as TriggerInfo, af as UniqueConstraintInfo, ag as UpdateAST, ah as UpsertAST, ai as UpsertResult, aj as ViewInfo, ak as WhereValue, al as isRef } from './Connection-DF_xKWko.js';
|
|
8
8
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
9
9
|
import * as hono_utils_types from 'hono/utils/types';
|
|
10
10
|
import * as hono_types from 'hono/types';
|
|
@@ -2339,6 +2339,7 @@ declare function createServer(app: App, options?: ServerOptions): hono_hono_base
|
|
|
2339
2339
|
schema: string;
|
|
2340
2340
|
ref_schema?: string | undefined;
|
|
2341
2341
|
foreign_key_name: string;
|
|
2342
|
+
foreign_key_group?: string | undefined;
|
|
2342
2343
|
fk_def: string;
|
|
2343
2344
|
is_visible?: boolean | undefined;
|
|
2344
2345
|
}[];
|
|
@@ -2615,7 +2616,6 @@ declare abstract class SqliteConnection<Driver = unknown, DB = any, Config exten
|
|
|
2615
2616
|
* and comments.
|
|
2616
2617
|
*/
|
|
2617
2618
|
private mergeDeparseMetadata;
|
|
2618
|
-
private markForeignKeyVisibility;
|
|
2619
2619
|
/**
|
|
2620
2620
|
* Create a migrator for the given schema.
|
|
2621
2621
|
* @param desiredSchema The desired schema to migrate to. Input DDL is expected to be `config.ddlDialect`.
|