zen-code 4.6.0 → 4.6.2

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.
@@ -1,211 +0,0 @@
1
- import { aS as p, ah as h, F as r, bb as l, bi as d, bc as y, bj as w, c } from "./sql-CJsUpKEQ.mjs";
2
- import { D as g, b as _, c as f, a as b, C as o } from "./migrator-BatO36Tk.mjs";
3
- function i(n, e) {
4
- return p.createWithChildren([
5
- p.createWithSql(`${n} `),
6
- h.create(e)
7
- // ensures savepointName gets sanitized
8
- ]);
9
- }
10
- const T = /"/g;
11
- class E extends g {
12
- sanitizeIdentifier(e) {
13
- return e.replace(T, '""');
14
- }
15
- }
16
- class C {
17
- #e;
18
- constructor(e) {
19
- this.#e = e;
20
- }
21
- async getSchemas() {
22
- return (await this.#e.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((a) => ({ name: a.nspname }));
23
- }
24
- async getTables(e = { withInternalKyselyTables: !1 }) {
25
- let a = this.#e.selectFrom("pg_catalog.pg_attribute as a").innerJoin("pg_catalog.pg_class as c", "a.attrelid", "c.oid").innerJoin("pg_catalog.pg_namespace as ns", "c.relnamespace", "ns.oid").innerJoin("pg_catalog.pg_type as typ", "a.atttypid", "typ.oid").innerJoin("pg_catalog.pg_namespace as dtns", "typ.typnamespace", "dtns.oid").select([
26
- "a.attname as column",
27
- "a.attnotnull as not_null",
28
- "a.atthasdef as has_default",
29
- "c.relname as table",
30
- "c.relkind as table_type",
31
- "ns.nspname as schema",
32
- "typ.typname as type",
33
- "dtns.nspname as type_schema",
34
- r`col_description(a.attrelid, a.attnum)`.as("column_description"),
35
- r`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as("auto_incrementing")
36
- ]).where("c.relkind", "in", [
37
- "r",
38
- "v",
39
- "p"
40
- ]).where("ns.nspname", "!~", "^pg_").where("ns.nspname", "!=", "information_schema").where("ns.nspname", "!=", "crdb_internal").where(r`has_schema_privilege(ns.nspname, 'USAGE')`).where("a.attnum", ">=", 0).where("a.attisdropped", "!=", !0).orderBy("ns.nspname").orderBy("c.relname").orderBy("a.attnum").$castTo();
41
- e.withInternalKyselyTables || (a = a.where("c.relname", "!=", _).where("c.relname", "!=", f));
42
- const t = await a.execute();
43
- return this.#a(t);
44
- }
45
- async getMetadata(e) {
46
- return {
47
- tables: await this.getTables(e)
48
- };
49
- }
50
- #a(e) {
51
- return e.reduce((a, t) => {
52
- let s = a.find((u) => u.name === t.table && u.schema === t.schema);
53
- return s || (s = l({
54
- name: t.table,
55
- isView: t.table_type === "v",
56
- schema: t.schema,
57
- columns: []
58
- }), a.push(s)), s.columns.push(l({
59
- name: t.column,
60
- dataType: t.type,
61
- dataTypeSchema: t.type_schema,
62
- isNullable: !t.not_null,
63
- isAutoIncrementing: t.auto_incrementing !== null,
64
- hasDefaultValue: t.has_default,
65
- comment: t.column_description ?? void 0
66
- })), a;
67
- }, []);
68
- }
69
- }
70
- const I = BigInt("3853314791062309107");
71
- class k extends b {
72
- get supportsTransactionalDdl() {
73
- return !0;
74
- }
75
- get supportsReturning() {
76
- return !0;
77
- }
78
- async acquireMigrationLock(e, a) {
79
- await r`select pg_advisory_xact_lock(${r.lit(I)})`.execute(e);
80
- }
81
- async releaseMigrationLock(e, a) {
82
- }
83
- }
84
- function v(n, e) {
85
- if (x(n) && e.stack) {
86
- const a = e.stack.split(`
87
- `).slice(1).join(`
88
- `);
89
- return n.stack += `
90
- ${a}`, n;
91
- }
92
- return n;
93
- }
94
- function x(n) {
95
- return d(n) && y(n.stack);
96
- }
97
- const m = /* @__PURE__ */ Symbol();
98
- class A {
99
- #e;
100
- #a = /* @__PURE__ */ new WeakMap();
101
- #t;
102
- constructor(e) {
103
- this.#e = l({ ...e });
104
- }
105
- async init() {
106
- this.#t = w(this.#e.pool) ? await this.#e.pool() : this.#e.pool;
107
- }
108
- async acquireConnection() {
109
- const e = await this.#t.connect();
110
- let a = this.#a.get(e);
111
- return a || (a = new D(e, {
112
- cursor: this.#e.cursor ?? null
113
- }), this.#a.set(e, a), this.#e.onCreateConnection && await this.#e.onCreateConnection(a)), this.#e.onReserveConnection && await this.#e.onReserveConnection(a), a;
114
- }
115
- async beginTransaction(e, a) {
116
- if (a.isolationLevel || a.accessMode) {
117
- let t = "start transaction";
118
- a.isolationLevel && (t += ` isolation level ${a.isolationLevel}`), a.accessMode && (t += ` ${a.accessMode}`), await e.executeQuery(o.raw(t));
119
- } else
120
- await e.executeQuery(o.raw("begin"));
121
- }
122
- async commitTransaction(e) {
123
- await e.executeQuery(o.raw("commit"));
124
- }
125
- async rollbackTransaction(e) {
126
- await e.executeQuery(o.raw("rollback"));
127
- }
128
- async savepoint(e, a, t) {
129
- await e.executeQuery(t(i("savepoint", a), c()));
130
- }
131
- async rollbackToSavepoint(e, a, t) {
132
- await e.executeQuery(t(i("rollback to", a), c()));
133
- }
134
- async releaseSavepoint(e, a, t) {
135
- await e.executeQuery(t(i("release", a), c()));
136
- }
137
- async releaseConnection(e) {
138
- e[m]();
139
- }
140
- async destroy() {
141
- if (this.#t) {
142
- const e = this.#t;
143
- this.#t = void 0, await e.end();
144
- }
145
- }
146
- }
147
- class D {
148
- #e;
149
- #a;
150
- constructor(e, a) {
151
- this.#e = e, this.#a = a;
152
- }
153
- async executeQuery(e) {
154
- try {
155
- const { command: a, rowCount: t, rows: s } = await this.#e.query(e.sql, [...e.parameters]);
156
- return {
157
- numAffectedRows: a === "INSERT" || a === "UPDATE" || a === "DELETE" || a === "MERGE" ? BigInt(t) : void 0,
158
- rows: s ?? []
159
- };
160
- } catch (a) {
161
- throw v(a, new Error());
162
- }
163
- }
164
- async *streamQuery(e, a) {
165
- if (!this.#a.cursor)
166
- throw new Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");
167
- if (!Number.isInteger(a) || a <= 0)
168
- throw new Error("chunkSize must be a positive integer");
169
- const t = this.#e.query(new this.#a.cursor(e.sql, e.parameters.slice()));
170
- try {
171
- for (; ; ) {
172
- const s = await t.read(a);
173
- if (s.length === 0)
174
- break;
175
- yield {
176
- rows: s
177
- };
178
- }
179
- } finally {
180
- await t.close();
181
- }
182
- }
183
- [m]() {
184
- this.#e.release();
185
- }
186
- }
187
- class L {
188
- #e;
189
- constructor(e) {
190
- this.#e = e;
191
- }
192
- createDriver() {
193
- return new A(this.#e);
194
- }
195
- createQueryCompiler() {
196
- return new E();
197
- }
198
- createAdapter() {
199
- return new k();
200
- }
201
- createIntrospector(e) {
202
- return new C(e);
203
- }
204
- }
205
- export {
206
- E as P,
207
- C as a,
208
- k as b,
209
- A as c,
210
- L as d
211
- };