@aiao/rxdb-adapter-pglite 0.0.4 → 0.0.6
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/PGliteClient.d.ts +1 -4
- package/dist/PGliteClient.d.ts.map +1 -1
- package/dist/RxDBAdapterPGlite.d.ts +173 -17
- package/dist/RxDBAdapterPGlite.d.ts.map +1 -1
- package/dist/entity/delete_sql.d.ts +13 -0
- package/dist/entity/delete_sql.d.ts.map +1 -0
- package/dist/entity/deletes_sql.d.ts +11 -0
- package/dist/entity/deletes_sql.d.ts.map +1 -0
- package/dist/entity/insert_sql.d.ts +14 -0
- package/dist/entity/insert_sql.d.ts.map +1 -0
- package/dist/entity/inserts_sql.d.ts +12 -0
- package/dist/entity/inserts_sql.d.ts.map +1 -0
- package/dist/entity/update_sql.d.ts +15 -0
- package/dist/entity/update_sql.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2600 -131
- package/dist/pglite.interface.d.ts +134 -2
- package/dist/pglite.interface.d.ts.map +1 -1
- package/dist/pglite.utils.d.ts +29 -1
- package/dist/pglite.utils.d.ts.map +1 -1
- package/dist/query/join_sql.d.ts +46 -0
- package/dist/query/join_sql.d.ts.map +1 -0
- package/dist/query/query_sql.d.ts +19 -0
- package/dist/query/query_sql.d.ts.map +1 -0
- package/dist/query/query_tree_sql.d.ts +36 -0
- package/dist/query/query_tree_sql.d.ts.map +1 -0
- package/dist/repository/PGliteRepository.d.ts +11 -0
- package/dist/repository/PGliteRepository.d.ts.map +1 -0
- package/dist/repository/PGliteRepositoryBase.d.ts +10 -0
- package/dist/repository/PGliteRepositoryBase.d.ts.map +1 -0
- package/dist/repository/PGliteTreeRepository.d.ts +13 -0
- package/dist/repository/PGliteTreeRepository.d.ts.map +1 -0
- package/dist/rxdb_adapter_create_branch.d.ts +7 -0
- package/dist/rxdb_adapter_create_branch.d.ts.map +1 -0
- package/dist/rxdb_adapter_switch_transaction_id.d.ts +18 -0
- package/dist/rxdb_adapter_switch_transaction_id.d.ts.map +1 -0
- package/dist/table/create_sql.d.ts +5 -0
- package/dist/table/create_sql.d.ts.map +1 -0
- package/dist/table/trigger_sql.d.ts +39 -0
- package/dist/table/trigger_sql.d.ts.map +1 -0
- package/package.json +6 -4
- package/dist/generate_table_create_sql.d.ts +0 -5
- package/dist/generate_table_create_sql.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,188 +1,2657 @@
|
|
|
1
|
-
import { PropertyType as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { PGlite as
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
1
|
+
import { PropertyType as W, RelationKind as _e, getEntityMetadata as ge, RepositoryBase as Kn, getEntityStatus as Pt, RxDBBranch as kt, RxDBChange as Wt, RxDBAdapterLocalBase as Qn } from "@aiao/rxdb";
|
|
2
|
+
import { pickBy as Gt, traverseObjectKeys as Xn, isFunction as Yt, isString as Zn, AsyncQueueExecutor as er } from "@aiao/utils";
|
|
3
|
+
import { firstValueFrom as $e, ReplaySubject as tr } from "rxjs";
|
|
4
|
+
import { PGlite as nr } from "@electric-sql/pglite";
|
|
5
|
+
class he extends Error {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
super(t), this.name = "RxDBError", Object.setPrototypeOf(this, he.prototype);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
switch (
|
|
12
|
-
case
|
|
10
|
+
const Vt = (e, t = "public") => `"${t}"."${e}"`, ue = (e) => Vt(e.name, e.namespace), Ht = (e) => {
|
|
11
|
+
switch (e.type) {
|
|
12
|
+
case W.uuid:
|
|
13
13
|
return "uuid";
|
|
14
|
-
case
|
|
14
|
+
case W.string:
|
|
15
15
|
return "varchar";
|
|
16
|
-
case
|
|
16
|
+
case W.json:
|
|
17
17
|
return "jsonb";
|
|
18
|
-
case
|
|
18
|
+
case W.number:
|
|
19
19
|
return "numeric";
|
|
20
|
-
case
|
|
20
|
+
case W.integer:
|
|
21
21
|
return "integer";
|
|
22
|
-
case
|
|
22
|
+
case W.boolean:
|
|
23
23
|
return "boolean";
|
|
24
|
-
case
|
|
24
|
+
case W.date:
|
|
25
25
|
return "timestamptz";
|
|
26
26
|
}
|
|
27
|
-
throw new
|
|
28
|
-
},
|
|
29
|
-
switch (
|
|
30
|
-
case
|
|
27
|
+
throw new he("rxDBColumnTypeToPGliteType: type '" + e.type + "' not support");
|
|
28
|
+
}, rr = (e) => {
|
|
29
|
+
switch (e.type) {
|
|
30
|
+
case W.uuid:
|
|
31
31
|
return "uuid_ops";
|
|
32
|
-
case
|
|
32
|
+
case W.string:
|
|
33
33
|
return "bpchar_ops";
|
|
34
|
-
case
|
|
34
|
+
case W.json:
|
|
35
35
|
return "jsonb_ops";
|
|
36
|
-
case
|
|
36
|
+
case W.number:
|
|
37
37
|
return "numeric_ops";
|
|
38
|
-
case
|
|
38
|
+
case W.integer:
|
|
39
39
|
return "int4_ops";
|
|
40
40
|
default:
|
|
41
|
-
throw new
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
throw new he(`rxDBColumnTypeToPGliteTypeIndexName: type '${e.type}' not support`);
|
|
42
|
+
}
|
|
43
|
+
}, Jt = (e, t) => `idx_${e.namespace}_${e.name}_${t.name}`, sr = (e, t) => {
|
|
44
|
+
if (e == null)
|
|
45
|
+
return null;
|
|
46
|
+
switch (t.type) {
|
|
47
|
+
case W.json:
|
|
48
|
+
case W.keyValue:
|
|
49
|
+
case W.stringArray:
|
|
50
|
+
case W.numberArray:
|
|
51
|
+
return JSON.stringify(e);
|
|
52
|
+
case W.date:
|
|
53
|
+
return e instanceof Date ? e.toISOString() : e;
|
|
54
|
+
case W.boolean:
|
|
55
|
+
return !!e;
|
|
56
|
+
case W.number:
|
|
57
|
+
case W.integer:
|
|
58
|
+
return Number(e);
|
|
59
|
+
case W.string:
|
|
60
|
+
case W.uuid:
|
|
61
|
+
default:
|
|
62
|
+
return String(e);
|
|
63
|
+
}
|
|
64
|
+
}, ot = (e, t) => {
|
|
65
|
+
const n = {}, i = Object.keys(t);
|
|
66
|
+
for (let s = 0; s < i.length; s++) {
|
|
67
|
+
const u = i[s];
|
|
68
|
+
if (u.endsWith("Id")) {
|
|
69
|
+
n[u] = t[u];
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const h = e.propertyMap.get(u);
|
|
73
|
+
h && (n[u] = sr(t[u], h));
|
|
74
|
+
}
|
|
75
|
+
return n;
|
|
76
|
+
}, zt = (e, t) => Gt(t, (n, i) => e.propertyMap.has(i) || e.foreignKeyNames.includes(i)), ir = (e, t) => Gt(t, (n, i) => e.propertyMap.get(i)?.readonly !== !0), ar = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Kt = (e) => {
|
|
77
|
+
if (typeof e == "string") {
|
|
78
|
+
const t = e.replaceAll("'", "''");
|
|
79
|
+
return ar.test(e) ? `'${t}'::uuid` : `'${t}'`;
|
|
80
|
+
}
|
|
81
|
+
return e == null ? "NULL" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : Array.isArray(e) ? `ARRAY[${e.map((n) => Kt(n)).join(", ")}]` : typeof e == "object" ? `'${JSON.stringify(e).replaceAll("'", "''")}'::jsonb` : String(e);
|
|
82
|
+
}, ze = (e, t) => {
|
|
83
|
+
const n = {};
|
|
84
|
+
return Object.keys(t).forEach((i) => {
|
|
85
|
+
const s = t[i];
|
|
86
|
+
if (e.isForeignKey(i))
|
|
87
|
+
n[i] = s;
|
|
88
|
+
else {
|
|
89
|
+
const u = e.propertyMap.get(i);
|
|
90
|
+
u ? u.type === W.number && typeof s == "string" ? n[i] = parseFloat(s) : u.type === W.integer && typeof s == "string" ? n[i] = parseInt(s, 10) : n[i] = s : n[i] = s;
|
|
91
|
+
}
|
|
92
|
+
}), n;
|
|
93
|
+
};
|
|
94
|
+
function or(e) {
|
|
95
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
96
|
+
}
|
|
97
|
+
function Se(e) {
|
|
98
|
+
throw new Error('Could not dynamically require "' + e + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
99
|
+
}
|
|
100
|
+
var Ye = { exports: {} }, mt;
|
|
101
|
+
function lr() {
|
|
102
|
+
return mt || (mt = 1, (function(e, t) {
|
|
103
|
+
(function(n) {
|
|
104
|
+
e.exports = n();
|
|
105
|
+
})(function() {
|
|
106
|
+
return (function n(i, s, u) {
|
|
107
|
+
function h(E, T) {
|
|
108
|
+
if (!s[E]) {
|
|
109
|
+
if (!i[E]) {
|
|
110
|
+
var L = typeof Se == "function" && Se;
|
|
111
|
+
if (!T && L) return L(E, !0);
|
|
112
|
+
if (m) return m(E, !0);
|
|
113
|
+
throw new Error("Cannot find module '" + E + "'");
|
|
114
|
+
}
|
|
115
|
+
T = s[E] = { exports: {} }, i[E][0].call(T.exports, function(D) {
|
|
116
|
+
var B = i[E][1][D];
|
|
117
|
+
return h(B || D);
|
|
118
|
+
}, T, T.exports, n, i, s, u);
|
|
119
|
+
}
|
|
120
|
+
return s[E].exports;
|
|
121
|
+
}
|
|
122
|
+
for (var m = typeof Se == "function" && Se, g = 0; g < u.length; g++) h(u[g]);
|
|
123
|
+
return h;
|
|
124
|
+
})({ 1: [function(n, i, s) {
|
|
125
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
126
|
+
var I = n("crypto");
|
|
127
|
+
function U(f, p) {
|
|
128
|
+
p = R(f, p);
|
|
129
|
+
var o;
|
|
130
|
+
return (o = p.algorithm !== "passthrough" ? I.createHash(p.algorithm) : new M()).write === void 0 && (o.write = o.update, o.end = o.update), b(p, o).dispatch(f), o.update || o.end(""), o.digest ? o.digest(p.encoding === "buffer" ? void 0 : p.encoding) : (f = o.read(), p.encoding !== "buffer" ? f.toString(p.encoding) : f);
|
|
131
|
+
}
|
|
132
|
+
(s = i.exports = U).sha1 = function(f) {
|
|
133
|
+
return U(f);
|
|
134
|
+
}, s.keys = function(f) {
|
|
135
|
+
return U(f, { excludeValues: !0, algorithm: "sha1", encoding: "hex" });
|
|
136
|
+
}, s.MD5 = function(f) {
|
|
137
|
+
return U(f, { algorithm: "md5", encoding: "hex" });
|
|
138
|
+
}, s.keysMD5 = function(f) {
|
|
139
|
+
return U(f, { algorithm: "md5", encoding: "hex", excludeValues: !0 });
|
|
140
|
+
};
|
|
141
|
+
var _ = I.getHashes ? I.getHashes().slice() : ["sha1", "md5"], N = (_.push("passthrough"), ["buffer", "hex", "binary", "base64"]);
|
|
142
|
+
function R(f, p) {
|
|
143
|
+
var o = {};
|
|
144
|
+
if (o.algorithm = (p = p || {}).algorithm || "sha1", o.encoding = p.encoding || "hex", o.excludeValues = !!p.excludeValues, o.algorithm = o.algorithm.toLowerCase(), o.encoding = o.encoding.toLowerCase(), o.ignoreUnknown = p.ignoreUnknown === !0, o.respectType = p.respectType !== !1, o.respectFunctionNames = p.respectFunctionNames !== !1, o.respectFunctionProperties = p.respectFunctionProperties !== !1, o.unorderedArrays = p.unorderedArrays === !0, o.unorderedSets = p.unorderedSets !== !1, o.unorderedObjects = p.unorderedObjects !== !1, o.replacer = p.replacer || void 0, o.excludeKeys = p.excludeKeys || void 0, f === void 0) throw new Error("Object argument required.");
|
|
145
|
+
for (var l = 0; l < _.length; ++l) _[l].toLowerCase() === o.algorithm.toLowerCase() && (o.algorithm = _[l]);
|
|
146
|
+
if (_.indexOf(o.algorithm) === -1) throw new Error('Algorithm "' + o.algorithm + '" not supported. supported values: ' + _.join(", "));
|
|
147
|
+
if (N.indexOf(o.encoding) === -1 && o.algorithm !== "passthrough") throw new Error('Encoding "' + o.encoding + '" not supported. supported values: ' + N.join(", "));
|
|
148
|
+
return o;
|
|
149
|
+
}
|
|
150
|
+
function v(f) {
|
|
151
|
+
if (typeof f == "function") return /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(f)) != null;
|
|
152
|
+
}
|
|
153
|
+
function b(f, p, o) {
|
|
154
|
+
o = o || [];
|
|
155
|
+
function l(a) {
|
|
156
|
+
return p.update ? p.update(a, "utf8") : p.write(a, "utf8");
|
|
157
|
+
}
|
|
158
|
+
return { dispatch: function(a) {
|
|
159
|
+
return this["_" + ((a = f.replacer ? f.replacer(a) : a) === null ? "null" : typeof a)](a);
|
|
160
|
+
}, _object: function(a) {
|
|
161
|
+
var y, w = Object.prototype.toString.call(a), x = /\[object (.*)\]/i.exec(w);
|
|
162
|
+
if (x = (x = x ? x[1] : "unknown:[" + w + "]").toLowerCase(), 0 <= (w = o.indexOf(a))) return this.dispatch("[CIRCULAR:" + w + "]");
|
|
163
|
+
if (o.push(a), m !== void 0 && m.isBuffer && m.isBuffer(a)) return l("buffer:"), l(a);
|
|
164
|
+
if (x === "object" || x === "function" || x === "asyncfunction") return w = Object.keys(a), f.unorderedObjects && (w = w.sort()), f.respectType === !1 || v(a) || w.splice(0, 0, "prototype", "__proto__", "constructor"), f.excludeKeys && (w = w.filter(function(j) {
|
|
165
|
+
return !f.excludeKeys(j);
|
|
166
|
+
})), l("object:" + w.length + ":"), y = this, w.forEach(function(j) {
|
|
167
|
+
y.dispatch(j), l(":"), f.excludeValues || y.dispatch(a[j]), l(",");
|
|
168
|
+
});
|
|
169
|
+
if (!this["_" + x]) {
|
|
170
|
+
if (f.ignoreUnknown) return l("[" + x + "]");
|
|
171
|
+
throw new Error('Unknown object type "' + x + '"');
|
|
172
|
+
}
|
|
173
|
+
this["_" + x](a);
|
|
174
|
+
}, _array: function(a, j) {
|
|
175
|
+
j = j !== void 0 ? j : f.unorderedArrays !== !1;
|
|
176
|
+
var w = this;
|
|
177
|
+
if (l("array:" + a.length + ":"), !j || a.length <= 1) return a.forEach(function(P) {
|
|
178
|
+
return w.dispatch(P);
|
|
179
|
+
});
|
|
180
|
+
var x = [], j = a.map(function(P) {
|
|
181
|
+
var q = new M(), H = o.slice();
|
|
182
|
+
return b(f, q, H).dispatch(P), x = x.concat(H.slice(o.length)), q.read().toString();
|
|
183
|
+
});
|
|
184
|
+
return o = o.concat(x), j.sort(), this._array(j, !1);
|
|
185
|
+
}, _date: function(a) {
|
|
186
|
+
return l("date:" + a.toJSON());
|
|
187
|
+
}, _symbol: function(a) {
|
|
188
|
+
return l("symbol:" + a.toString());
|
|
189
|
+
}, _error: function(a) {
|
|
190
|
+
return l("error:" + a.toString());
|
|
191
|
+
}, _boolean: function(a) {
|
|
192
|
+
return l("bool:" + a.toString());
|
|
193
|
+
}, _string: function(a) {
|
|
194
|
+
l("string:" + a.length + ":"), l(a.toString());
|
|
195
|
+
}, _function: function(a) {
|
|
196
|
+
l("fn:"), v(a) ? this.dispatch("[native]") : this.dispatch(a.toString()), f.respectFunctionNames !== !1 && this.dispatch("function-name:" + String(a.name)), f.respectFunctionProperties && this._object(a);
|
|
197
|
+
}, _number: function(a) {
|
|
198
|
+
return l("number:" + a.toString());
|
|
199
|
+
}, _xml: function(a) {
|
|
200
|
+
return l("xml:" + a.toString());
|
|
201
|
+
}, _null: function() {
|
|
202
|
+
return l("Null");
|
|
203
|
+
}, _undefined: function() {
|
|
204
|
+
return l("Undefined");
|
|
205
|
+
}, _regexp: function(a) {
|
|
206
|
+
return l("regex:" + a.toString());
|
|
207
|
+
}, _uint8array: function(a) {
|
|
208
|
+
return l("uint8array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
209
|
+
}, _uint8clampedarray: function(a) {
|
|
210
|
+
return l("uint8clampedarray:"), this.dispatch(Array.prototype.slice.call(a));
|
|
211
|
+
}, _int8array: function(a) {
|
|
212
|
+
return l("int8array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
213
|
+
}, _uint16array: function(a) {
|
|
214
|
+
return l("uint16array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
215
|
+
}, _int16array: function(a) {
|
|
216
|
+
return l("int16array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
217
|
+
}, _uint32array: function(a) {
|
|
218
|
+
return l("uint32array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
219
|
+
}, _int32array: function(a) {
|
|
220
|
+
return l("int32array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
221
|
+
}, _float32array: function(a) {
|
|
222
|
+
return l("float32array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
223
|
+
}, _float64array: function(a) {
|
|
224
|
+
return l("float64array:"), this.dispatch(Array.prototype.slice.call(a));
|
|
225
|
+
}, _arraybuffer: function(a) {
|
|
226
|
+
return l("arraybuffer:"), this.dispatch(new Uint8Array(a));
|
|
227
|
+
}, _url: function(a) {
|
|
228
|
+
return l("url:" + a.toString());
|
|
229
|
+
}, _map: function(a) {
|
|
230
|
+
return l("map:"), a = Array.from(a), this._array(a, f.unorderedSets !== !1);
|
|
231
|
+
}, _set: function(a) {
|
|
232
|
+
return l("set:"), a = Array.from(a), this._array(a, f.unorderedSets !== !1);
|
|
233
|
+
}, _file: function(a) {
|
|
234
|
+
return l("file:"), this.dispatch([a.name, a.size, a.type, a.lastModfied]);
|
|
235
|
+
}, _blob: function() {
|
|
236
|
+
if (f.ignoreUnknown) return l("[blob]");
|
|
237
|
+
throw Error(`Hashing Blob objects is currently not supported
|
|
238
|
+
(see https://github.com/puleos/object-hash/issues/26)
|
|
239
|
+
Use "options.replacer" or "options.ignoreUnknown"
|
|
240
|
+
`);
|
|
241
|
+
}, _domwindow: function() {
|
|
242
|
+
return l("domwindow");
|
|
243
|
+
}, _bigint: function(a) {
|
|
244
|
+
return l("bigint:" + a.toString());
|
|
245
|
+
}, _process: function() {
|
|
246
|
+
return l("process");
|
|
247
|
+
}, _timer: function() {
|
|
248
|
+
return l("timer");
|
|
249
|
+
}, _pipe: function() {
|
|
250
|
+
return l("pipe");
|
|
251
|
+
}, _tcp: function() {
|
|
252
|
+
return l("tcp");
|
|
253
|
+
}, _udp: function() {
|
|
254
|
+
return l("udp");
|
|
255
|
+
}, _tty: function() {
|
|
256
|
+
return l("tty");
|
|
257
|
+
}, _statwatcher: function() {
|
|
258
|
+
return l("statwatcher");
|
|
259
|
+
}, _securecontext: function() {
|
|
260
|
+
return l("securecontext");
|
|
261
|
+
}, _connection: function() {
|
|
262
|
+
return l("connection");
|
|
263
|
+
}, _zlib: function() {
|
|
264
|
+
return l("zlib");
|
|
265
|
+
}, _context: function() {
|
|
266
|
+
return l("context");
|
|
267
|
+
}, _nodescript: function() {
|
|
268
|
+
return l("nodescript");
|
|
269
|
+
}, _httpparser: function() {
|
|
270
|
+
return l("httpparser");
|
|
271
|
+
}, _dataview: function() {
|
|
272
|
+
return l("dataview");
|
|
273
|
+
}, _signal: function() {
|
|
274
|
+
return l("signal");
|
|
275
|
+
}, _fsevent: function() {
|
|
276
|
+
return l("fsevent");
|
|
277
|
+
}, _tlswrap: function() {
|
|
278
|
+
return l("tlswrap");
|
|
279
|
+
} };
|
|
280
|
+
}
|
|
281
|
+
function M() {
|
|
282
|
+
return { buf: "", write: function(f) {
|
|
283
|
+
this.buf += f;
|
|
284
|
+
}, end: function(f) {
|
|
285
|
+
this.buf += f;
|
|
286
|
+
}, read: function() {
|
|
287
|
+
return this.buf;
|
|
288
|
+
} };
|
|
289
|
+
}
|
|
290
|
+
s.writeToStream = function(f, p, o) {
|
|
291
|
+
return o === void 0 && (o = p, p = {}), b(p = R(f, p), o).dispatch(f);
|
|
292
|
+
};
|
|
293
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/fake_9a5aa49d.js", "/");
|
|
294
|
+
}, { buffer: 3, crypto: 5, lYpoI2: 11 }], 2: [function(n, i, s) {
|
|
295
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
296
|
+
(function(I) {
|
|
297
|
+
var U = typeof Uint8Array < "u" ? Uint8Array : Array, _ = 43, N = 47, R = 48, v = 97, b = 65, M = 45, f = 95;
|
|
298
|
+
function p(o) {
|
|
299
|
+
return o = o.charCodeAt(0), o === _ || o === M ? 62 : o === N || o === f ? 63 : o < R ? -1 : o < R + 10 ? o - R + 26 + 26 : o < b + 26 ? o - b : o < v + 26 ? o - v + 26 : void 0;
|
|
300
|
+
}
|
|
301
|
+
I.toByteArray = function(o) {
|
|
302
|
+
var l, a;
|
|
303
|
+
if (0 < o.length % 4) throw new Error("Invalid string. Length must be a multiple of 4");
|
|
304
|
+
var y = o.length, y = o.charAt(y - 2) === "=" ? 2 : o.charAt(y - 1) === "=" ? 1 : 0, w = new U(3 * o.length / 4 - y), x = 0 < y ? o.length - 4 : o.length, j = 0;
|
|
305
|
+
function P(q) {
|
|
306
|
+
w[j++] = q;
|
|
307
|
+
}
|
|
308
|
+
for (l = 0; l < x; l += 4, 0) P((16711680 & (a = p(o.charAt(l)) << 18 | p(o.charAt(l + 1)) << 12 | p(o.charAt(l + 2)) << 6 | p(o.charAt(l + 3)))) >> 16), P((65280 & a) >> 8), P(255 & a);
|
|
309
|
+
return y == 2 ? P(255 & (a = p(o.charAt(l)) << 2 | p(o.charAt(l + 1)) >> 4)) : y == 1 && (P((a = p(o.charAt(l)) << 10 | p(o.charAt(l + 1)) << 4 | p(o.charAt(l + 2)) >> 2) >> 8 & 255), P(255 & a)), w;
|
|
310
|
+
}, I.fromByteArray = function(o) {
|
|
311
|
+
var l, a, y, w, x = o.length % 3, j = "";
|
|
312
|
+
function P(q) {
|
|
313
|
+
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q);
|
|
314
|
+
}
|
|
315
|
+
for (l = 0, y = o.length - x; l < y; l += 3) a = (o[l] << 16) + (o[l + 1] << 8) + o[l + 2], j += P((w = a) >> 18 & 63) + P(w >> 12 & 63) + P(w >> 6 & 63) + P(63 & w);
|
|
316
|
+
switch (x) {
|
|
317
|
+
case 1:
|
|
318
|
+
j = (j += P((a = o[o.length - 1]) >> 2)) + P(a << 4 & 63) + "==";
|
|
319
|
+
break;
|
|
320
|
+
case 2:
|
|
321
|
+
j = (j = (j += P((a = (o[o.length - 2] << 8) + o[o.length - 1]) >> 10)) + P(a >> 4 & 63)) + P(a << 2 & 63) + "=";
|
|
322
|
+
}
|
|
323
|
+
return j;
|
|
324
|
+
};
|
|
325
|
+
})(s === void 0 ? this.base64js = {} : s);
|
|
326
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js", "/node_modules/gulp-browserify/node_modules/base64-js/lib");
|
|
327
|
+
}, { buffer: 3, lYpoI2: 11 }], 3: [function(n, i, s) {
|
|
328
|
+
(function(u, h, _, g, E, T, L, D, B) {
|
|
329
|
+
var I = n("base64-js"), U = n("ieee754");
|
|
330
|
+
function _(r, c, d) {
|
|
331
|
+
if (!(this instanceof _)) return new _(r, c, d);
|
|
332
|
+
var S, $, C, k, K = typeof r;
|
|
333
|
+
if (c === "base64" && K == "string") for (r = (k = r).trim ? k.trim() : k.replace(/^\s+|\s+$/g, ""); r.length % 4 != 0; ) r += "=";
|
|
334
|
+
if (K == "number") S = re(r);
|
|
335
|
+
else if (K == "string") S = _.byteLength(r, c);
|
|
336
|
+
else {
|
|
337
|
+
if (K != "object") throw new Error("First argument needs to be a number, array or string.");
|
|
338
|
+
S = re(r.length);
|
|
339
|
+
}
|
|
340
|
+
if (_._useTypedArrays ? $ = _._augment(new Uint8Array(S)) : (($ = this).length = S, $._isBuffer = !0), _._useTypedArrays && typeof r.byteLength == "number") $._set(r);
|
|
341
|
+
else if (z(k = r) || _.isBuffer(k) || k && typeof k == "object" && typeof k.length == "number") for (C = 0; C < S; C++) _.isBuffer(r) ? $[C] = r.readUInt8(C) : $[C] = r[C];
|
|
342
|
+
else if (K == "string") $.write(r, 0, c);
|
|
343
|
+
else if (K == "number" && !_._useTypedArrays && !d) for (C = 0; C < S; C++) $[C] = 0;
|
|
344
|
+
return $;
|
|
345
|
+
}
|
|
346
|
+
function N(r, c, d, S) {
|
|
347
|
+
return _._charsWritten = ve((function($) {
|
|
348
|
+
for (var C = [], k = 0; k < $.length; k++) C.push(255 & $.charCodeAt(k));
|
|
349
|
+
return C;
|
|
350
|
+
})(c), r, d, S);
|
|
351
|
+
}
|
|
352
|
+
function R(r, c, d, S) {
|
|
353
|
+
return _._charsWritten = ve((function($) {
|
|
354
|
+
for (var C, k, K = [], ee = 0; ee < $.length; ee++) k = $.charCodeAt(ee), C = k >> 8, k = k % 256, K.push(k), K.push(C);
|
|
355
|
+
return K;
|
|
356
|
+
})(c), r, d, S);
|
|
357
|
+
}
|
|
358
|
+
function v(r, c, d) {
|
|
359
|
+
var S = "";
|
|
360
|
+
d = Math.min(r.length, d);
|
|
361
|
+
for (var $ = c; $ < d; $++) S += String.fromCharCode(r[$]);
|
|
362
|
+
return S;
|
|
363
|
+
}
|
|
364
|
+
function b(r, c, d, C) {
|
|
365
|
+
C || (O(typeof d == "boolean", "missing or invalid endian"), O(c != null, "missing offset"), O(c + 1 < r.length, "Trying to read beyond buffer length"));
|
|
366
|
+
var $, C = r.length;
|
|
367
|
+
if (!(C <= c)) return d ? ($ = r[c], c + 1 < C && ($ |= r[c + 1] << 8)) : ($ = r[c] << 8, c + 1 < C && ($ |= r[c + 1])), $;
|
|
368
|
+
}
|
|
369
|
+
function M(r, c, d, C) {
|
|
370
|
+
C || (O(typeof d == "boolean", "missing or invalid endian"), O(c != null, "missing offset"), O(c + 3 < r.length, "Trying to read beyond buffer length"));
|
|
371
|
+
var $, C = r.length;
|
|
372
|
+
if (!(C <= c)) return d ? (c + 2 < C && ($ = r[c + 2] << 16), c + 1 < C && ($ |= r[c + 1] << 8), $ |= r[c], c + 3 < C && ($ += r[c + 3] << 24 >>> 0)) : (c + 1 < C && ($ = r[c + 1] << 16), c + 2 < C && ($ |= r[c + 2] << 8), c + 3 < C && ($ |= r[c + 3]), $ += r[c] << 24 >>> 0), $;
|
|
373
|
+
}
|
|
374
|
+
function f(r, c, d, S) {
|
|
375
|
+
if (S || (O(typeof d == "boolean", "missing or invalid endian"), O(c != null, "missing offset"), O(c + 1 < r.length, "Trying to read beyond buffer length")), !(r.length <= c)) return S = b(r, c, d, !0), 32768 & S ? -1 * (65535 - S + 1) : S;
|
|
376
|
+
}
|
|
377
|
+
function p(r, c, d, S) {
|
|
378
|
+
if (S || (O(typeof d == "boolean", "missing or invalid endian"), O(c != null, "missing offset"), O(c + 3 < r.length, "Trying to read beyond buffer length")), !(r.length <= c)) return S = M(r, c, d, !0), 2147483648 & S ? -1 * (4294967295 - S + 1) : S;
|
|
379
|
+
}
|
|
380
|
+
function o(r, c, d, S) {
|
|
381
|
+
return S || (O(typeof d == "boolean", "missing or invalid endian"), O(c + 3 < r.length, "Trying to read beyond buffer length")), U.read(r, c, d, 23, 4);
|
|
382
|
+
}
|
|
383
|
+
function l(r, c, d, S) {
|
|
384
|
+
return S || (O(typeof d == "boolean", "missing or invalid endian"), O(c + 7 < r.length, "Trying to read beyond buffer length")), U.read(r, c, d, 52, 8);
|
|
385
|
+
}
|
|
386
|
+
function a(r, c, d, S, $) {
|
|
387
|
+
if ($ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 1 < r.length, "trying to write beyond buffer length"), We(c, 65535)), $ = r.length, !($ <= d)) for (var C = 0, k = Math.min($ - d, 2); C < k; C++) r[d + C] = (c & 255 << 8 * (S ? C : 1 - C)) >>> 8 * (S ? C : 1 - C);
|
|
388
|
+
}
|
|
389
|
+
function y(r, c, d, S, $) {
|
|
390
|
+
if ($ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 3 < r.length, "trying to write beyond buffer length"), We(c, 4294967295)), $ = r.length, !($ <= d)) for (var C = 0, k = Math.min($ - d, 4); C < k; C++) r[d + C] = c >>> 8 * (S ? C : 3 - C) & 255;
|
|
391
|
+
}
|
|
392
|
+
function w(r, c, d, S, $) {
|
|
393
|
+
$ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 1 < r.length, "Trying to write beyond buffer length"), Ge(c, 32767, -32768)), r.length <= d || a(r, 0 <= c ? c : 65535 + c + 1, d, S, $);
|
|
394
|
+
}
|
|
395
|
+
function x(r, c, d, S, $) {
|
|
396
|
+
$ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 3 < r.length, "Trying to write beyond buffer length"), Ge(c, 2147483647, -2147483648)), r.length <= d || y(r, 0 <= c ? c : 4294967295 + c + 1, d, S, $);
|
|
397
|
+
}
|
|
398
|
+
function j(r, c, d, S, $) {
|
|
399
|
+
$ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 3 < r.length, "Trying to write beyond buffer length"), yt(c, 34028234663852886e22, -34028234663852886e22)), r.length <= d || U.write(r, c, d, S, 23, 4);
|
|
400
|
+
}
|
|
401
|
+
function P(r, c, d, S, $) {
|
|
402
|
+
$ || (O(c != null, "missing value"), O(typeof S == "boolean", "missing or invalid endian"), O(d != null, "missing offset"), O(d + 7 < r.length, "Trying to write beyond buffer length"), yt(c, 17976931348623157e292, -17976931348623157e292)), r.length <= d || U.write(r, c, d, S, 52, 8);
|
|
403
|
+
}
|
|
404
|
+
s.Buffer = _, s.SlowBuffer = _, s.INSPECT_MAX_BYTES = 50, _.poolSize = 8192, _._useTypedArrays = (function() {
|
|
405
|
+
try {
|
|
406
|
+
var r = new ArrayBuffer(0), c = new Uint8Array(r);
|
|
407
|
+
return c.foo = function() {
|
|
408
|
+
return 42;
|
|
409
|
+
}, c.foo() === 42 && typeof c.subarray == "function";
|
|
410
|
+
} catch {
|
|
411
|
+
return !1;
|
|
412
|
+
}
|
|
413
|
+
})(), _.isEncoding = function(r) {
|
|
414
|
+
switch (String(r).toLowerCase()) {
|
|
415
|
+
case "hex":
|
|
416
|
+
case "utf8":
|
|
417
|
+
case "utf-8":
|
|
418
|
+
case "ascii":
|
|
419
|
+
case "binary":
|
|
420
|
+
case "base64":
|
|
421
|
+
case "raw":
|
|
422
|
+
case "ucs2":
|
|
423
|
+
case "ucs-2":
|
|
424
|
+
case "utf16le":
|
|
425
|
+
case "utf-16le":
|
|
426
|
+
return !0;
|
|
427
|
+
default:
|
|
428
|
+
return !1;
|
|
429
|
+
}
|
|
430
|
+
}, _.isBuffer = function(r) {
|
|
431
|
+
return !(r == null || !r._isBuffer);
|
|
432
|
+
}, _.byteLength = function(r, c) {
|
|
433
|
+
var d;
|
|
434
|
+
switch (r += "", c || "utf8") {
|
|
435
|
+
case "hex":
|
|
436
|
+
d = r.length / 2;
|
|
437
|
+
break;
|
|
438
|
+
case "utf8":
|
|
439
|
+
case "utf-8":
|
|
440
|
+
d = me(r).length;
|
|
441
|
+
break;
|
|
442
|
+
case "ascii":
|
|
443
|
+
case "binary":
|
|
444
|
+
case "raw":
|
|
445
|
+
d = r.length;
|
|
446
|
+
break;
|
|
447
|
+
case "base64":
|
|
448
|
+
d = dt(r).length;
|
|
449
|
+
break;
|
|
450
|
+
case "ucs2":
|
|
451
|
+
case "ucs-2":
|
|
452
|
+
case "utf16le":
|
|
453
|
+
case "utf-16le":
|
|
454
|
+
d = 2 * r.length;
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
throw new Error("Unknown encoding");
|
|
458
|
+
}
|
|
459
|
+
return d;
|
|
460
|
+
}, _.concat = function(r, c) {
|
|
461
|
+
if (O(z(r), `Usage: Buffer.concat(list, [totalLength])
|
|
462
|
+
list should be an Array.`), r.length === 0) return new _(0);
|
|
463
|
+
if (r.length === 1) return r[0];
|
|
464
|
+
if (typeof c != "number") for ($ = c = 0; $ < r.length; $++) c += r[$].length;
|
|
465
|
+
for (var d = new _(c), S = 0, $ = 0; $ < r.length; $++) {
|
|
466
|
+
var C = r[$];
|
|
467
|
+
C.copy(d, S), S += C.length;
|
|
468
|
+
}
|
|
469
|
+
return d;
|
|
470
|
+
}, _.prototype.write = function(r, c, d, S) {
|
|
471
|
+
isFinite(c) ? isFinite(d) || (S = d, d = void 0) : (ee = S, S = c, c = d, d = ee), c = Number(c) || 0;
|
|
472
|
+
var $, C, k, K, ee = this.length - c;
|
|
473
|
+
switch ((!d || ee < (d = Number(d))) && (d = ee), S = String(S || "utf8").toLowerCase()) {
|
|
474
|
+
case "hex":
|
|
475
|
+
$ = (function(pe, ae, oe, te) {
|
|
476
|
+
oe = Number(oe) || 0;
|
|
477
|
+
var X = pe.length - oe;
|
|
478
|
+
(!te || X < (te = Number(te))) && (te = X), O((X = ae.length) % 2 == 0, "Invalid hex string"), X / 2 < te && (te = X / 2);
|
|
479
|
+
for (var Ee = 0; Ee < te; Ee++) {
|
|
480
|
+
var gt = parseInt(ae.substr(2 * Ee, 2), 16);
|
|
481
|
+
O(!isNaN(gt), "Invalid hex string"), pe[oe + Ee] = gt;
|
|
482
|
+
}
|
|
483
|
+
return _._charsWritten = 2 * Ee, Ee;
|
|
484
|
+
})(this, r, c, d);
|
|
485
|
+
break;
|
|
486
|
+
case "utf8":
|
|
487
|
+
case "utf-8":
|
|
488
|
+
C = this, k = c, K = d, $ = _._charsWritten = ve(me(r), C, k, K);
|
|
489
|
+
break;
|
|
490
|
+
case "ascii":
|
|
491
|
+
case "binary":
|
|
492
|
+
$ = N(this, r, c, d);
|
|
493
|
+
break;
|
|
494
|
+
case "base64":
|
|
495
|
+
C = this, k = c, K = d, $ = _._charsWritten = ve(dt(r), C, k, K);
|
|
496
|
+
break;
|
|
497
|
+
case "ucs2":
|
|
498
|
+
case "ucs-2":
|
|
499
|
+
case "utf16le":
|
|
500
|
+
case "utf-16le":
|
|
501
|
+
$ = R(this, r, c, d);
|
|
502
|
+
break;
|
|
503
|
+
default:
|
|
504
|
+
throw new Error("Unknown encoding");
|
|
505
|
+
}
|
|
506
|
+
return $;
|
|
507
|
+
}, _.prototype.toString = function(r, c, d) {
|
|
508
|
+
var S, $, C, k, K = this;
|
|
509
|
+
if (r = String(r || "utf8").toLowerCase(), c = Number(c) || 0, (d = d !== void 0 ? Number(d) : K.length) === c) return "";
|
|
510
|
+
switch (r) {
|
|
511
|
+
case "hex":
|
|
512
|
+
S = (function(ee, pe, ae) {
|
|
513
|
+
var oe = ee.length;
|
|
514
|
+
(!pe || pe < 0) && (pe = 0), (!ae || ae < 0 || oe < ae) && (ae = oe);
|
|
515
|
+
for (var te = "", X = pe; X < ae; X++) te += V(ee[X]);
|
|
516
|
+
return te;
|
|
517
|
+
})(K, c, d);
|
|
518
|
+
break;
|
|
519
|
+
case "utf8":
|
|
520
|
+
case "utf-8":
|
|
521
|
+
S = (function(ee, pe, ae) {
|
|
522
|
+
var oe = "", te = "";
|
|
523
|
+
ae = Math.min(ee.length, ae);
|
|
524
|
+
for (var X = pe; X < ae; X++) ee[X] <= 127 ? (oe += pt(te) + String.fromCharCode(ee[X]), te = "") : te += "%" + ee[X].toString(16);
|
|
525
|
+
return oe + pt(te);
|
|
526
|
+
})(K, c, d);
|
|
527
|
+
break;
|
|
528
|
+
case "ascii":
|
|
529
|
+
case "binary":
|
|
530
|
+
S = v(K, c, d);
|
|
531
|
+
break;
|
|
532
|
+
case "base64":
|
|
533
|
+
$ = K, k = d, S = (C = c) === 0 && k === $.length ? I.fromByteArray($) : I.fromByteArray($.slice(C, k));
|
|
534
|
+
break;
|
|
535
|
+
case "ucs2":
|
|
536
|
+
case "ucs-2":
|
|
537
|
+
case "utf16le":
|
|
538
|
+
case "utf-16le":
|
|
539
|
+
S = (function(ee, pe, ae) {
|
|
540
|
+
for (var oe = ee.slice(pe, ae), te = "", X = 0; X < oe.length; X += 2) te += String.fromCharCode(oe[X] + 256 * oe[X + 1]);
|
|
541
|
+
return te;
|
|
542
|
+
})(K, c, d);
|
|
543
|
+
break;
|
|
544
|
+
default:
|
|
545
|
+
throw new Error("Unknown encoding");
|
|
546
|
+
}
|
|
547
|
+
return S;
|
|
548
|
+
}, _.prototype.toJSON = function() {
|
|
549
|
+
return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
|
|
550
|
+
}, _.prototype.copy = function(r, c, d, S) {
|
|
551
|
+
if (c = c || 0, (S = S || S === 0 ? S : this.length) !== (d = d || 0) && r.length !== 0 && this.length !== 0) {
|
|
552
|
+
O(d <= S, "sourceEnd < sourceStart"), O(0 <= c && c < r.length, "targetStart out of bounds"), O(0 <= d && d < this.length, "sourceStart out of bounds"), O(0 <= S && S <= this.length, "sourceEnd out of bounds"), S > this.length && (S = this.length);
|
|
553
|
+
var $ = (S = r.length - c < S - d ? r.length - c + d : S) - d;
|
|
554
|
+
if ($ < 100 || !_._useTypedArrays) for (var C = 0; C < $; C++) r[C + c] = this[C + d];
|
|
555
|
+
else r._set(this.subarray(d, d + $), c);
|
|
556
|
+
}
|
|
557
|
+
}, _.prototype.slice = function(r, c) {
|
|
558
|
+
var d = this.length;
|
|
559
|
+
if (r = H(r, d, 0), c = H(c, d, d), _._useTypedArrays) return _._augment(this.subarray(r, c));
|
|
560
|
+
for (var S = c - r, $ = new _(S, void 0, !0), C = 0; C < S; C++) $[C] = this[C + r];
|
|
561
|
+
return $;
|
|
562
|
+
}, _.prototype.get = function(r) {
|
|
563
|
+
return console.log(".get() is deprecated. Access using array indexes instead."), this.readUInt8(r);
|
|
564
|
+
}, _.prototype.set = function(r, c) {
|
|
565
|
+
return console.log(".set() is deprecated. Access using array indexes instead."), this.writeUInt8(r, c);
|
|
566
|
+
}, _.prototype.readUInt8 = function(r, c) {
|
|
567
|
+
if (c || (O(r != null, "missing offset"), O(r < this.length, "Trying to read beyond buffer length")), !(r >= this.length)) return this[r];
|
|
568
|
+
}, _.prototype.readUInt16LE = function(r, c) {
|
|
569
|
+
return b(this, r, !0, c);
|
|
570
|
+
}, _.prototype.readUInt16BE = function(r, c) {
|
|
571
|
+
return b(this, r, !1, c);
|
|
572
|
+
}, _.prototype.readUInt32LE = function(r, c) {
|
|
573
|
+
return M(this, r, !0, c);
|
|
574
|
+
}, _.prototype.readUInt32BE = function(r, c) {
|
|
575
|
+
return M(this, r, !1, c);
|
|
576
|
+
}, _.prototype.readInt8 = function(r, c) {
|
|
577
|
+
if (c || (O(r != null, "missing offset"), O(r < this.length, "Trying to read beyond buffer length")), !(r >= this.length)) return 128 & this[r] ? -1 * (255 - this[r] + 1) : this[r];
|
|
578
|
+
}, _.prototype.readInt16LE = function(r, c) {
|
|
579
|
+
return f(this, r, !0, c);
|
|
580
|
+
}, _.prototype.readInt16BE = function(r, c) {
|
|
581
|
+
return f(this, r, !1, c);
|
|
582
|
+
}, _.prototype.readInt32LE = function(r, c) {
|
|
583
|
+
return p(this, r, !0, c);
|
|
584
|
+
}, _.prototype.readInt32BE = function(r, c) {
|
|
585
|
+
return p(this, r, !1, c);
|
|
586
|
+
}, _.prototype.readFloatLE = function(r, c) {
|
|
587
|
+
return o(this, r, !0, c);
|
|
588
|
+
}, _.prototype.readFloatBE = function(r, c) {
|
|
589
|
+
return o(this, r, !1, c);
|
|
590
|
+
}, _.prototype.readDoubleLE = function(r, c) {
|
|
591
|
+
return l(this, r, !0, c);
|
|
592
|
+
}, _.prototype.readDoubleBE = function(r, c) {
|
|
593
|
+
return l(this, r, !1, c);
|
|
594
|
+
}, _.prototype.writeUInt8 = function(r, c, d) {
|
|
595
|
+
d || (O(r != null, "missing value"), O(c != null, "missing offset"), O(c < this.length, "trying to write beyond buffer length"), We(r, 255)), c >= this.length || (this[c] = r);
|
|
596
|
+
}, _.prototype.writeUInt16LE = function(r, c, d) {
|
|
597
|
+
a(this, r, c, !0, d);
|
|
598
|
+
}, _.prototype.writeUInt16BE = function(r, c, d) {
|
|
599
|
+
a(this, r, c, !1, d);
|
|
600
|
+
}, _.prototype.writeUInt32LE = function(r, c, d) {
|
|
601
|
+
y(this, r, c, !0, d);
|
|
602
|
+
}, _.prototype.writeUInt32BE = function(r, c, d) {
|
|
603
|
+
y(this, r, c, !1, d);
|
|
604
|
+
}, _.prototype.writeInt8 = function(r, c, d) {
|
|
605
|
+
d || (O(r != null, "missing value"), O(c != null, "missing offset"), O(c < this.length, "Trying to write beyond buffer length"), Ge(r, 127, -128)), c >= this.length || (0 <= r ? this.writeUInt8(r, c, d) : this.writeUInt8(255 + r + 1, c, d));
|
|
606
|
+
}, _.prototype.writeInt16LE = function(r, c, d) {
|
|
607
|
+
w(this, r, c, !0, d);
|
|
608
|
+
}, _.prototype.writeInt16BE = function(r, c, d) {
|
|
609
|
+
w(this, r, c, !1, d);
|
|
610
|
+
}, _.prototype.writeInt32LE = function(r, c, d) {
|
|
611
|
+
x(this, r, c, !0, d);
|
|
612
|
+
}, _.prototype.writeInt32BE = function(r, c, d) {
|
|
613
|
+
x(this, r, c, !1, d);
|
|
614
|
+
}, _.prototype.writeFloatLE = function(r, c, d) {
|
|
615
|
+
j(this, r, c, !0, d);
|
|
616
|
+
}, _.prototype.writeFloatBE = function(r, c, d) {
|
|
617
|
+
j(this, r, c, !1, d);
|
|
618
|
+
}, _.prototype.writeDoubleLE = function(r, c, d) {
|
|
619
|
+
P(this, r, c, !0, d);
|
|
620
|
+
}, _.prototype.writeDoubleBE = function(r, c, d) {
|
|
621
|
+
P(this, r, c, !1, d);
|
|
622
|
+
}, _.prototype.fill = function(r, c, d) {
|
|
623
|
+
if (c = c || 0, d = d || this.length, O(typeof (r = typeof (r = r || 0) == "string" ? r.charCodeAt(0) : r) == "number" && !isNaN(r), "value is not a number"), O(c <= d, "end < start"), d !== c && this.length !== 0) {
|
|
624
|
+
O(0 <= c && c < this.length, "start out of bounds"), O(0 <= d && d <= this.length, "end out of bounds");
|
|
625
|
+
for (var S = c; S < d; S++) this[S] = r;
|
|
626
|
+
}
|
|
627
|
+
}, _.prototype.inspect = function() {
|
|
628
|
+
for (var r = [], c = this.length, d = 0; d < c; d++) if (r[d] = V(this[d]), d === s.INSPECT_MAX_BYTES) {
|
|
629
|
+
r[d + 1] = "...";
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
return "<Buffer " + r.join(" ") + ">";
|
|
633
|
+
}, _.prototype.toArrayBuffer = function() {
|
|
634
|
+
if (typeof Uint8Array > "u") throw new Error("Buffer.toArrayBuffer not supported in this browser");
|
|
635
|
+
if (_._useTypedArrays) return new _(this).buffer;
|
|
636
|
+
for (var r = new Uint8Array(this.length), c = 0, d = r.length; c < d; c += 1) r[c] = this[c];
|
|
637
|
+
return r.buffer;
|
|
638
|
+
};
|
|
639
|
+
var q = _.prototype;
|
|
640
|
+
function H(r, c, d) {
|
|
641
|
+
return typeof r != "number" ? d : c <= (r = ~~r) ? c : 0 <= r || 0 <= (r += c) ? r : 0;
|
|
642
|
+
}
|
|
643
|
+
function re(r) {
|
|
644
|
+
return (r = ~~Math.ceil(+r)) < 0 ? 0 : r;
|
|
645
|
+
}
|
|
646
|
+
function z(r) {
|
|
647
|
+
return (Array.isArray || function(c) {
|
|
648
|
+
return Object.prototype.toString.call(c) === "[object Array]";
|
|
649
|
+
})(r);
|
|
650
|
+
}
|
|
651
|
+
function V(r) {
|
|
652
|
+
return r < 16 ? "0" + r.toString(16) : r.toString(16);
|
|
653
|
+
}
|
|
654
|
+
function me(r) {
|
|
655
|
+
for (var c = [], d = 0; d < r.length; d++) {
|
|
656
|
+
var S = r.charCodeAt(d);
|
|
657
|
+
if (S <= 127) c.push(r.charCodeAt(d));
|
|
658
|
+
else for (var $ = d, C = (55296 <= S && S <= 57343 && d++, encodeURIComponent(r.slice($, d + 1)).substr(1).split("%")), k = 0; k < C.length; k++) c.push(parseInt(C[k], 16));
|
|
659
|
+
}
|
|
660
|
+
return c;
|
|
661
|
+
}
|
|
662
|
+
function dt(r) {
|
|
663
|
+
return I.toByteArray(r);
|
|
664
|
+
}
|
|
665
|
+
function ve(r, c, d, S) {
|
|
666
|
+
for (var $ = 0; $ < S && !($ + d >= c.length || $ >= r.length); $++) c[$ + d] = r[$];
|
|
667
|
+
return $;
|
|
668
|
+
}
|
|
669
|
+
function pt(r) {
|
|
670
|
+
try {
|
|
671
|
+
return decodeURIComponent(r);
|
|
672
|
+
} catch {
|
|
673
|
+
return "�";
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function We(r, c) {
|
|
677
|
+
O(typeof r == "number", "cannot write a non-number as a number"), O(0 <= r, "specified a negative value for writing an unsigned value"), O(r <= c, "value is larger than maximum value for type"), O(Math.floor(r) === r, "value has a fractional component");
|
|
678
|
+
}
|
|
679
|
+
function Ge(r, c, d) {
|
|
680
|
+
O(typeof r == "number", "cannot write a non-number as a number"), O(r <= c, "value larger than maximum allowed value"), O(d <= r, "value smaller than minimum allowed value"), O(Math.floor(r) === r, "value has a fractional component");
|
|
681
|
+
}
|
|
682
|
+
function yt(r, c, d) {
|
|
683
|
+
O(typeof r == "number", "cannot write a non-number as a number"), O(r <= c, "value larger than maximum allowed value"), O(d <= r, "value smaller than minimum allowed value");
|
|
684
|
+
}
|
|
685
|
+
function O(r, c) {
|
|
686
|
+
if (!r) throw new Error(c || "Failed assertion");
|
|
687
|
+
}
|
|
688
|
+
_._augment = function(r) {
|
|
689
|
+
return r._isBuffer = !0, r._get = r.get, r._set = r.set, r.get = q.get, r.set = q.set, r.write = q.write, r.toString = q.toString, r.toLocaleString = q.toString, r.toJSON = q.toJSON, r.copy = q.copy, r.slice = q.slice, r.readUInt8 = q.readUInt8, r.readUInt16LE = q.readUInt16LE, r.readUInt16BE = q.readUInt16BE, r.readUInt32LE = q.readUInt32LE, r.readUInt32BE = q.readUInt32BE, r.readInt8 = q.readInt8, r.readInt16LE = q.readInt16LE, r.readInt16BE = q.readInt16BE, r.readInt32LE = q.readInt32LE, r.readInt32BE = q.readInt32BE, r.readFloatLE = q.readFloatLE, r.readFloatBE = q.readFloatBE, r.readDoubleLE = q.readDoubleLE, r.readDoubleBE = q.readDoubleBE, r.writeUInt8 = q.writeUInt8, r.writeUInt16LE = q.writeUInt16LE, r.writeUInt16BE = q.writeUInt16BE, r.writeUInt32LE = q.writeUInt32LE, r.writeUInt32BE = q.writeUInt32BE, r.writeInt8 = q.writeInt8, r.writeInt16LE = q.writeInt16LE, r.writeInt16BE = q.writeInt16BE, r.writeInt32LE = q.writeInt32LE, r.writeInt32BE = q.writeInt32BE, r.writeFloatLE = q.writeFloatLE, r.writeFloatBE = q.writeFloatBE, r.writeDoubleLE = q.writeDoubleLE, r.writeDoubleBE = q.writeDoubleBE, r.fill = q.fill, r.inspect = q.inspect, r.toArrayBuffer = q.toArrayBuffer, r;
|
|
690
|
+
};
|
|
691
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/buffer/index.js", "/node_modules/gulp-browserify/node_modules/buffer");
|
|
692
|
+
}, { "base64-js": 2, buffer: 3, ieee754: 10, lYpoI2: 11 }], 4: [function(n, i, s) {
|
|
693
|
+
(function(u, h, I, g, E, T, L, D, B) {
|
|
694
|
+
var I = n("buffer").Buffer, U = 4, _ = new I(U);
|
|
695
|
+
_.fill(0), i.exports = { hash: function(N, R, v, b) {
|
|
696
|
+
for (var M = R((function(a, y) {
|
|
697
|
+
a.length % U != 0 && (w = a.length + (U - a.length % U), a = I.concat([a, _], w));
|
|
698
|
+
for (var w, x = [], j = y ? a.readInt32BE : a.readInt32LE, P = 0; P < a.length; P += U) x.push(j.call(a, P));
|
|
699
|
+
return x;
|
|
700
|
+
})(N = I.isBuffer(N) ? N : new I(N), b), 8 * N.length), R = b, f = new I(v), p = R ? f.writeInt32BE : f.writeInt32LE, o = 0; o < M.length; o++) p.call(f, M[o], 4 * o, !0);
|
|
701
|
+
return f;
|
|
702
|
+
} };
|
|
703
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
704
|
+
}, { buffer: 3, lYpoI2: 11 }], 5: [function(n, i, s) {
|
|
705
|
+
(function(u, h, I, g, E, T, L, D, B) {
|
|
706
|
+
var I = n("buffer").Buffer, U = n("./sha"), _ = n("./sha256"), N = n("./rng"), R = { sha1: U, sha256: _, md5: n("./md5") }, v = 64, b = new I(v);
|
|
707
|
+
function M(a, y) {
|
|
708
|
+
var w = R[a = a || "sha1"], x = [];
|
|
709
|
+
return w || f("algorithm:", a, "is not yet supported"), { update: function(j) {
|
|
710
|
+
return I.isBuffer(j) || (j = new I(j)), x.push(j), j.length, this;
|
|
711
|
+
}, digest: function(j) {
|
|
712
|
+
var P = I.concat(x), P = y ? (function(q, H, re) {
|
|
713
|
+
I.isBuffer(H) || (H = new I(H)), I.isBuffer(re) || (re = new I(re)), H.length > v ? H = q(H) : H.length < v && (H = I.concat([H, b], v));
|
|
714
|
+
for (var z = new I(v), V = new I(v), me = 0; me < v; me++) z[me] = 54 ^ H[me], V[me] = 92 ^ H[me];
|
|
715
|
+
return re = q(I.concat([z, re])), q(I.concat([V, re]));
|
|
716
|
+
})(w, y, P) : w(P);
|
|
717
|
+
return x = null, j ? P.toString(j) : P;
|
|
718
|
+
} };
|
|
719
|
+
}
|
|
720
|
+
function f() {
|
|
721
|
+
var a = [].slice.call(arguments).join(" ");
|
|
722
|
+
throw new Error([a, "we accept pull requests", "http://github.com/dominictarr/crypto-browserify"].join(`
|
|
723
|
+
`));
|
|
724
|
+
}
|
|
725
|
+
b.fill(0), s.createHash = function(a) {
|
|
726
|
+
return M(a);
|
|
727
|
+
}, s.createHmac = M, s.randomBytes = function(a, y) {
|
|
728
|
+
if (!y || !y.call) return new I(N(a));
|
|
729
|
+
try {
|
|
730
|
+
y.call(this, void 0, new I(N(a)));
|
|
731
|
+
} catch (w) {
|
|
732
|
+
y(w);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
var p, o = ["createCredentials", "createCipher", "createCipheriv", "createDecipher", "createDecipheriv", "createSign", "createVerify", "createDiffieHellman", "pbkdf2"], l = function(a) {
|
|
736
|
+
s[a] = function() {
|
|
737
|
+
f("sorry,", a, "is not implemented yet");
|
|
738
|
+
};
|
|
739
|
+
};
|
|
740
|
+
for (p in o) l(o[p]);
|
|
741
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
742
|
+
}, { "./md5": 6, "./rng": 7, "./sha": 8, "./sha256": 9, buffer: 3, lYpoI2: 11 }], 6: [function(n, i, s) {
|
|
743
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
744
|
+
var I = n("./helpers");
|
|
745
|
+
function U(f, p) {
|
|
746
|
+
f[p >> 5] |= 128 << p % 32, f[14 + (p + 64 >>> 9 << 4)] = p;
|
|
747
|
+
for (var o = 1732584193, l = -271733879, a = -1732584194, y = 271733878, w = 0; w < f.length; w += 16) {
|
|
748
|
+
var x = o, j = l, P = a, q = y, o = N(o, l, a, y, f[w + 0], 7, -680876936), y = N(y, o, l, a, f[w + 1], 12, -389564586), a = N(a, y, o, l, f[w + 2], 17, 606105819), l = N(l, a, y, o, f[w + 3], 22, -1044525330);
|
|
749
|
+
o = N(o, l, a, y, f[w + 4], 7, -176418897), y = N(y, o, l, a, f[w + 5], 12, 1200080426), a = N(a, y, o, l, f[w + 6], 17, -1473231341), l = N(l, a, y, o, f[w + 7], 22, -45705983), o = N(o, l, a, y, f[w + 8], 7, 1770035416), y = N(y, o, l, a, f[w + 9], 12, -1958414417), a = N(a, y, o, l, f[w + 10], 17, -42063), l = N(l, a, y, o, f[w + 11], 22, -1990404162), o = N(o, l, a, y, f[w + 12], 7, 1804603682), y = N(y, o, l, a, f[w + 13], 12, -40341101), a = N(a, y, o, l, f[w + 14], 17, -1502002290), o = R(o, l = N(l, a, y, o, f[w + 15], 22, 1236535329), a, y, f[w + 1], 5, -165796510), y = R(y, o, l, a, f[w + 6], 9, -1069501632), a = R(a, y, o, l, f[w + 11], 14, 643717713), l = R(l, a, y, o, f[w + 0], 20, -373897302), o = R(o, l, a, y, f[w + 5], 5, -701558691), y = R(y, o, l, a, f[w + 10], 9, 38016083), a = R(a, y, o, l, f[w + 15], 14, -660478335), l = R(l, a, y, o, f[w + 4], 20, -405537848), o = R(o, l, a, y, f[w + 9], 5, 568446438), y = R(y, o, l, a, f[w + 14], 9, -1019803690), a = R(a, y, o, l, f[w + 3], 14, -187363961), l = R(l, a, y, o, f[w + 8], 20, 1163531501), o = R(o, l, a, y, f[w + 13], 5, -1444681467), y = R(y, o, l, a, f[w + 2], 9, -51403784), a = R(a, y, o, l, f[w + 7], 14, 1735328473), o = v(o, l = R(l, a, y, o, f[w + 12], 20, -1926607734), a, y, f[w + 5], 4, -378558), y = v(y, o, l, a, f[w + 8], 11, -2022574463), a = v(a, y, o, l, f[w + 11], 16, 1839030562), l = v(l, a, y, o, f[w + 14], 23, -35309556), o = v(o, l, a, y, f[w + 1], 4, -1530992060), y = v(y, o, l, a, f[w + 4], 11, 1272893353), a = v(a, y, o, l, f[w + 7], 16, -155497632), l = v(l, a, y, o, f[w + 10], 23, -1094730640), o = v(o, l, a, y, f[w + 13], 4, 681279174), y = v(y, o, l, a, f[w + 0], 11, -358537222), a = v(a, y, o, l, f[w + 3], 16, -722521979), l = v(l, a, y, o, f[w + 6], 23, 76029189), o = v(o, l, a, y, f[w + 9], 4, -640364487), y = v(y, o, l, a, f[w + 12], 11, -421815835), a = v(a, y, o, l, f[w + 15], 16, 530742520), o = b(o, l = v(l, a, y, o, f[w + 2], 23, -995338651), a, y, f[w + 0], 6, -198630844), y = b(y, o, l, a, f[w + 7], 10, 1126891415), a = b(a, y, o, l, f[w + 14], 15, -1416354905), l = b(l, a, y, o, f[w + 5], 21, -57434055), o = b(o, l, a, y, f[w + 12], 6, 1700485571), y = b(y, o, l, a, f[w + 3], 10, -1894986606), a = b(a, y, o, l, f[w + 10], 15, -1051523), l = b(l, a, y, o, f[w + 1], 21, -2054922799), o = b(o, l, a, y, f[w + 8], 6, 1873313359), y = b(y, o, l, a, f[w + 15], 10, -30611744), a = b(a, y, o, l, f[w + 6], 15, -1560198380), l = b(l, a, y, o, f[w + 13], 21, 1309151649), o = b(o, l, a, y, f[w + 4], 6, -145523070), y = b(y, o, l, a, f[w + 11], 10, -1120210379), a = b(a, y, o, l, f[w + 2], 15, 718787259), l = b(l, a, y, o, f[w + 9], 21, -343485551), o = M(o, x), l = M(l, j), a = M(a, P), y = M(y, q);
|
|
750
|
+
}
|
|
751
|
+
return Array(o, l, a, y);
|
|
752
|
+
}
|
|
753
|
+
function _(f, p, o, l, a, y) {
|
|
754
|
+
return M((p = M(M(p, f), M(l, y))) << a | p >>> 32 - a, o);
|
|
755
|
+
}
|
|
756
|
+
function N(f, p, o, l, a, y, w) {
|
|
757
|
+
return _(p & o | ~p & l, f, p, a, y, w);
|
|
758
|
+
}
|
|
759
|
+
function R(f, p, o, l, a, y, w) {
|
|
760
|
+
return _(p & l | o & ~l, f, p, a, y, w);
|
|
761
|
+
}
|
|
762
|
+
function v(f, p, o, l, a, y, w) {
|
|
763
|
+
return _(p ^ o ^ l, f, p, a, y, w);
|
|
764
|
+
}
|
|
765
|
+
function b(f, p, o, l, a, y, w) {
|
|
766
|
+
return _(o ^ (p | ~l), f, p, a, y, w);
|
|
767
|
+
}
|
|
768
|
+
function M(f, p) {
|
|
769
|
+
var o = (65535 & f) + (65535 & p);
|
|
770
|
+
return (f >> 16) + (p >> 16) + (o >> 16) << 16 | 65535 & o;
|
|
771
|
+
}
|
|
772
|
+
i.exports = function(f) {
|
|
773
|
+
return I.hash(f, U, 16);
|
|
774
|
+
};
|
|
775
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
776
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 7: [function(n, i, s) {
|
|
777
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
778
|
+
i.exports = function(I) {
|
|
779
|
+
for (var U, _ = new Array(I), N = 0; N < I; N++) (3 & N) == 0 && (U = 4294967296 * Math.random()), _[N] = U >>> ((3 & N) << 3) & 255;
|
|
780
|
+
return _;
|
|
781
|
+
};
|
|
782
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
783
|
+
}, { buffer: 3, lYpoI2: 11 }], 8: [function(n, i, s) {
|
|
784
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
785
|
+
var I = n("./helpers");
|
|
786
|
+
function U(R, v) {
|
|
787
|
+
R[v >> 5] |= 128 << 24 - v % 32, R[15 + (v + 64 >> 9 << 4)] = v;
|
|
788
|
+
for (var b, M, f, p = Array(80), o = 1732584193, l = -271733879, a = -1732584194, y = 271733878, w = -1009589776, x = 0; x < R.length; x += 16) {
|
|
789
|
+
for (var j = o, P = l, q = a, H = y, re = w, z = 0; z < 80; z++) {
|
|
790
|
+
p[z] = z < 16 ? R[x + z] : N(p[z - 3] ^ p[z - 8] ^ p[z - 14] ^ p[z - 16], 1);
|
|
791
|
+
var V = _(_(N(o, 5), (V = l, M = a, f = y, (b = z) < 20 ? V & M | ~V & f : !(b < 40) && b < 60 ? V & M | V & f | M & f : V ^ M ^ f)), _(_(w, p[z]), (b = z) < 20 ? 1518500249 : b < 40 ? 1859775393 : b < 60 ? -1894007588 : -899497514)), w = y, y = a, a = N(l, 30), l = o, o = V;
|
|
792
|
+
}
|
|
793
|
+
o = _(o, j), l = _(l, P), a = _(a, q), y = _(y, H), w = _(w, re);
|
|
794
|
+
}
|
|
795
|
+
return Array(o, l, a, y, w);
|
|
796
|
+
}
|
|
797
|
+
function _(R, v) {
|
|
798
|
+
var b = (65535 & R) + (65535 & v);
|
|
799
|
+
return (R >> 16) + (v >> 16) + (b >> 16) << 16 | 65535 & b;
|
|
800
|
+
}
|
|
801
|
+
function N(R, v) {
|
|
802
|
+
return R << v | R >>> 32 - v;
|
|
803
|
+
}
|
|
804
|
+
i.exports = function(R) {
|
|
805
|
+
return I.hash(R, U, 20, !0);
|
|
806
|
+
};
|
|
807
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
808
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 9: [function(n, i, s) {
|
|
809
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
810
|
+
function I(v, b) {
|
|
811
|
+
var M = (65535 & v) + (65535 & b);
|
|
812
|
+
return (v >> 16) + (b >> 16) + (M >> 16) << 16 | 65535 & M;
|
|
813
|
+
}
|
|
814
|
+
function U(v, b) {
|
|
815
|
+
var M, f = new Array(1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298), p = new Array(1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225), o = new Array(64);
|
|
816
|
+
v[b >> 5] |= 128 << 24 - b % 32, v[15 + (b + 64 >> 9 << 4)] = b;
|
|
817
|
+
for (var l, a, y = 0; y < v.length; y += 16) {
|
|
818
|
+
for (var w = p[0], x = p[1], j = p[2], P = p[3], q = p[4], H = p[5], re = p[6], z = p[7], V = 0; V < 64; V++) o[V] = V < 16 ? v[V + y] : I(I(I((a = o[V - 2], N(a, 17) ^ N(a, 19) ^ R(a, 10)), o[V - 7]), (a = o[V - 15], N(a, 7) ^ N(a, 18) ^ R(a, 3))), o[V - 16]), M = I(I(I(I(z, N(a = q, 6) ^ N(a, 11) ^ N(a, 25)), q & H ^ ~q & re), f[V]), o[V]), l = I(N(l = w, 2) ^ N(l, 13) ^ N(l, 22), w & x ^ w & j ^ x & j), z = re, re = H, H = q, q = I(P, M), P = j, j = x, x = w, w = I(M, l);
|
|
819
|
+
p[0] = I(w, p[0]), p[1] = I(x, p[1]), p[2] = I(j, p[2]), p[3] = I(P, p[3]), p[4] = I(q, p[4]), p[5] = I(H, p[5]), p[6] = I(re, p[6]), p[7] = I(z, p[7]);
|
|
820
|
+
}
|
|
821
|
+
return p;
|
|
822
|
+
}
|
|
823
|
+
var _ = n("./helpers"), N = function(v, b) {
|
|
824
|
+
return v >>> b | v << 32 - b;
|
|
825
|
+
}, R = function(v, b) {
|
|
826
|
+
return v >>> b;
|
|
827
|
+
};
|
|
828
|
+
i.exports = function(v) {
|
|
829
|
+
return _.hash(v, U, 32, !0);
|
|
830
|
+
};
|
|
831
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
|
|
832
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 10: [function(n, i, s) {
|
|
833
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
834
|
+
s.read = function(I, U, _, N, y) {
|
|
835
|
+
var v, b, M = 8 * y - N - 1, f = (1 << M) - 1, p = f >> 1, o = -7, l = _ ? y - 1 : 0, a = _ ? -1 : 1, y = I[U + l];
|
|
836
|
+
for (l += a, v = y & (1 << -o) - 1, y >>= -o, o += M; 0 < o; v = 256 * v + I[U + l], l += a, o -= 8) ;
|
|
837
|
+
for (b = v & (1 << -o) - 1, v >>= -o, o += N; 0 < o; b = 256 * b + I[U + l], l += a, o -= 8) ;
|
|
838
|
+
if (v === 0) v = 1 - p;
|
|
839
|
+
else {
|
|
840
|
+
if (v === f) return b ? NaN : 1 / 0 * (y ? -1 : 1);
|
|
841
|
+
b += Math.pow(2, N), v -= p;
|
|
842
|
+
}
|
|
843
|
+
return (y ? -1 : 1) * b * Math.pow(2, v - N);
|
|
844
|
+
}, s.write = function(I, U, _, N, R, w) {
|
|
845
|
+
var b, M, f = 8 * w - R - 1, p = (1 << f) - 1, o = p >> 1, l = R === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, a = N ? 0 : w - 1, y = N ? 1 : -1, w = U < 0 || U === 0 && 1 / U < 0 ? 1 : 0;
|
|
846
|
+
for (U = Math.abs(U), isNaN(U) || U === 1 / 0 ? (M = isNaN(U) ? 1 : 0, b = p) : (b = Math.floor(Math.log(U) / Math.LN2), U * (N = Math.pow(2, -b)) < 1 && (b--, N *= 2), 2 <= (U += 1 <= b + o ? l / N : l * Math.pow(2, 1 - o)) * N && (b++, N /= 2), p <= b + o ? (M = 0, b = p) : 1 <= b + o ? (M = (U * N - 1) * Math.pow(2, R), b += o) : (M = U * Math.pow(2, o - 1) * Math.pow(2, R), b = 0)); 8 <= R; I[_ + a] = 255 & M, a += y, M /= 256, R -= 8) ;
|
|
847
|
+
for (b = b << R | M, f += R; 0 < f; I[_ + a] = 255 & b, a += y, b /= 256, f -= 8) ;
|
|
848
|
+
I[_ + a - y] |= 128 * w;
|
|
849
|
+
};
|
|
850
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/ieee754/index.js", "/node_modules/gulp-browserify/node_modules/ieee754");
|
|
851
|
+
}, { buffer: 3, lYpoI2: 11 }], 11: [function(n, i, s) {
|
|
852
|
+
(function(u, h, m, g, E, T, L, D, B) {
|
|
853
|
+
var I, U, _;
|
|
854
|
+
function N() {
|
|
855
|
+
}
|
|
856
|
+
(u = i.exports = {}).nextTick = (U = typeof window < "u" && window.setImmediate, _ = typeof window < "u" && window.postMessage && window.addEventListener, U ? function(R) {
|
|
857
|
+
return window.setImmediate(R);
|
|
858
|
+
} : _ ? (I = [], window.addEventListener("message", function(R) {
|
|
859
|
+
var v = R.source;
|
|
860
|
+
v !== window && v !== null || R.data !== "process-tick" || (R.stopPropagation(), 0 < I.length && I.shift()());
|
|
861
|
+
}, !0), function(R) {
|
|
862
|
+
I.push(R), window.postMessage("process-tick", "*");
|
|
863
|
+
}) : function(R) {
|
|
864
|
+
setTimeout(R, 0);
|
|
865
|
+
}), u.title = "browser", u.browser = !0, u.env = {}, u.argv = [], u.on = N, u.addListener = N, u.once = N, u.off = N, u.removeListener = N, u.removeAllListeners = N, u.emit = N, u.binding = function(R) {
|
|
866
|
+
throw new Error("process.binding is not supported");
|
|
867
|
+
}, u.cwd = function() {
|
|
868
|
+
return "/";
|
|
869
|
+
}, u.chdir = function(R) {
|
|
870
|
+
throw new Error("process.chdir is not supported");
|
|
871
|
+
};
|
|
872
|
+
}).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/process/browser.js", "/node_modules/gulp-browserify/node_modules/process");
|
|
873
|
+
}, { buffer: 3, lYpoI2: 11 }] }, {}, [1])(1);
|
|
874
|
+
});
|
|
875
|
+
})(Ye)), Ye.exports;
|
|
876
|
+
}
|
|
877
|
+
var ur = lr();
|
|
878
|
+
const cr = /* @__PURE__ */ or(ur), fr = (e, t) => {
|
|
879
|
+
const n = ue(e), i = t.map((s) => `'${s.id}'`).join(",");
|
|
880
|
+
return `DELETE FROM ${n} WHERE id IN (${i});`;
|
|
881
|
+
}, hr = (e, t, n) => {
|
|
882
|
+
const i = ue(e), s = n?.userId && e.propertyMap.has("createdBy"), u = n?.userId && e.propertyMap.has("updatedBy"), h = [...e.propertyMap.keys(), ...e.foreignKeyNames], m = [];
|
|
883
|
+
t.forEach((E) => {
|
|
884
|
+
const T = zt(e, E);
|
|
885
|
+
s && (T.createdBy = n.userId), u && (T.updatedBy = n.userId);
|
|
886
|
+
const L = ot(e, T), D = [];
|
|
887
|
+
h.forEach((B) => {
|
|
888
|
+
const I = L[B];
|
|
889
|
+
D.push(Kt(I));
|
|
890
|
+
}), m.push(`(${D.join(",")})`);
|
|
58
891
|
});
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
892
|
+
const g = h.map((E) => `"${E}"`).join(",");
|
|
893
|
+
return `INSERT INTO ${i} (${g}) VALUES ${m.join(",")};`;
|
|
894
|
+
}, dr = "pglite";
|
|
895
|
+
var pr = Object.defineProperty, Qt = (e) => {
|
|
896
|
+
throw TypeError(e);
|
|
897
|
+
}, yr = (e, t) => () => (e && (t = e(e = 0)), t), qe = (e, t) => {
|
|
898
|
+
for (var n in t) pr(e, n, { get: t[n], enumerable: !0 });
|
|
899
|
+
}, lt = (e, t, n) => t.has(e) || Qt("Cannot " + n), A = (e, t, n) => (lt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), ie = (e, t, n) => t.has(e) ? Qt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), Y = (e, t, n, i) => (lt(e, t, "write to private field"), t.set(e, n), n), G = (e, t, n) => (lt(e, t, "access private method"), n), Xt = (e, t, n, i) => ({ set _(s) {
|
|
900
|
+
Y(e, t, s);
|
|
901
|
+
}, get _() {
|
|
902
|
+
return A(e, t, i);
|
|
903
|
+
} }), de = yr(() => {
|
|
904
|
+
}), gr = {};
|
|
905
|
+
qe(gr, { ABSTIME: () => Lr, ACLITEM: () => jr, BIT: () => kr, BOOL: () => Ke, BPCHAR: () => sn, BYTEA: () => Qe, CHAR: () => wr, CID: () => Tr, CIDR: () => Rr, CIRCLE: () => Dr, DATE: () => on, FLOAT4: () => nn, FLOAT8: () => rn, GTSVECTOR: () => ss, INET: () => qr, INT2: () => Zt, INT4: () => en, INT8: () => Xe, INTERVAL: () => xr, JSON: () => Ze, JSONB: () => un, MACADDR: () => Br, MACADDR8: () => Mr, MONEY: () => Ur, NUMERIC: () => Gr, OID: () => tn, PATH: () => Sr, PG_DEPENDENCIES: () => ts, PG_LSN: () => Zr, PG_NDISTINCT: () => es, PG_NODE_TREE: () => vr, POLYGON: () => Nr, REFCURSOR: () => Yr, REGCLASS: () => zr, REGCONFIG: () => is, REGDICTIONARY: () => as, REGNAMESPACE: () => os, REGOPER: () => Hr, REGOPERATOR: () => Jr, REGPROC: () => Er, REGPROCEDURE: () => Vr, REGROLE: () => ls, REGTYPE: () => Kr, RELTIME: () => Or, SMGR: () => $r, TEXT: () => Oe, TID: () => br, TIME: () => Fr, TIMESTAMP: () => ln, TIMESTAMPTZ: () => et, TIMETZ: () => Pr, TINTERVAL: () => Cr, TSQUERY: () => rs, TSVECTOR: () => ns, TXID_SNAPSHOT: () => Xr, UUID: () => Qr, VARBIT: () => Wr, VARCHAR: () => an, XID: () => Ar, XML: () => Ir, arrayParser: () => ys, arraySerializer: () => fn, parseType: () => tt, parsers: () => us, serializers: () => cs, types: () => cn });
|
|
906
|
+
de();
|
|
907
|
+
var mr = globalThis.JSON.parse, _r = globalThis.JSON.stringify, Ke = 16, Qe = 17, wr = 18, Xe = 20, Zt = 21, en = 23, Er = 24, Oe = 25, tn = 26, br = 27, Ar = 28, Tr = 29, Ze = 114, Ir = 142, vr = 194, $r = 210, Sr = 602, Nr = 604, Rr = 650, nn = 700, rn = 701, Lr = 702, Or = 703, Cr = 704, Dr = 718, Mr = 774, Ur = 790, Br = 829, qr = 869, jr = 1033, sn = 1042, an = 1043, on = 1082, Fr = 1083, ln = 1114, et = 1184, xr = 1186, Pr = 1266, kr = 1560, Wr = 1562, Gr = 1700, Yr = 1790, Vr = 2202, Hr = 2203, Jr = 2204, zr = 2205, Kr = 2206, Qr = 2950, Xr = 2970, Zr = 3220, es = 3361, ts = 3402, ns = 3614, rs = 3615, ss = 3642, is = 3734, as = 3769, un = 3802, os = 4089, ls = 4096, cn = { string: { to: Oe, from: [Oe, an, sn], serialize: (e) => {
|
|
908
|
+
if (typeof e == "string") return e;
|
|
909
|
+
if (typeof e == "number") return e.toString();
|
|
910
|
+
throw new Error("Invalid input for string type");
|
|
911
|
+
}, parse: (e) => e }, number: { to: 0, from: [Zt, en, tn, nn, rn], serialize: (e) => e.toString(), parse: (e) => +e }, bigint: { to: Xe, from: [Xe], serialize: (e) => e.toString(), parse: (e) => {
|
|
912
|
+
let t = BigInt(e);
|
|
913
|
+
return t < Number.MIN_SAFE_INTEGER || t > Number.MAX_SAFE_INTEGER ? t : Number(t);
|
|
914
|
+
} }, json: { to: Ze, from: [Ze, un], serialize: (e) => typeof e == "string" ? e : _r(e), parse: (e) => mr(e) }, boolean: { to: Ke, from: [Ke], serialize: (e) => {
|
|
915
|
+
if (typeof e != "boolean") throw new Error("Invalid input for boolean type");
|
|
916
|
+
return e ? "t" : "f";
|
|
917
|
+
}, parse: (e) => e === "t" }, date: { to: et, from: [on, ln, et], serialize: (e) => {
|
|
918
|
+
if (typeof e == "string") return e;
|
|
919
|
+
if (typeof e == "number") return new Date(e).toISOString();
|
|
920
|
+
if (e instanceof Date) return e.toISOString();
|
|
921
|
+
throw new Error("Invalid input for date type");
|
|
922
|
+
}, parse: (e) => new Date(e) }, bytea: { to: Qe, from: [Qe], serialize: (e) => {
|
|
923
|
+
if (!(e instanceof Uint8Array)) throw new Error("Invalid input for bytea type");
|
|
924
|
+
return "\\x" + Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
925
|
+
}, parse: (e) => {
|
|
926
|
+
let t = e.slice(2);
|
|
927
|
+
return Uint8Array.from({ length: t.length / 2 }, (n, i) => parseInt(t.substring(i * 2, (i + 1) * 2), 16));
|
|
928
|
+
} } }, ut = fs(cn), us = ut.parsers, cs = ut.serializers;
|
|
929
|
+
function tt(e, t, n) {
|
|
930
|
+
if (e === null) return null;
|
|
931
|
+
let i = n?.[t] ?? ut.parsers[t];
|
|
932
|
+
return i ? i(e, t) : e;
|
|
933
|
+
}
|
|
934
|
+
function fs(e) {
|
|
935
|
+
return Object.keys(e).reduce(({ parsers: t, serializers: n }, i) => {
|
|
936
|
+
let { to: s, from: u, serialize: h, parse: m } = e[i];
|
|
937
|
+
return n[s] = h, n[i] = h, t[i] = m, Array.isArray(u) ? u.forEach((g) => {
|
|
938
|
+
t[g] = m, n[g] = h;
|
|
939
|
+
}) : (t[u] = m, n[u] = h), { parsers: t, serializers: n };
|
|
940
|
+
}, { parsers: {}, serializers: {} });
|
|
941
|
+
}
|
|
942
|
+
var hs = /\\/g, ds = /"/g;
|
|
943
|
+
function ps(e) {
|
|
944
|
+
return e.replace(hs, "\\\\").replace(ds, '\\"');
|
|
945
|
+
}
|
|
946
|
+
function fn(e, t, n) {
|
|
947
|
+
if (Array.isArray(e) === !1) return e;
|
|
948
|
+
if (!e.length) return "{}";
|
|
949
|
+
let i = e[0], s = n === 1020 ? ";" : ",";
|
|
950
|
+
return Array.isArray(i) ? `{${e.map((u) => fn(u, t, n)).join(s)}}` : `{${e.map((u) => (u === void 0 && (u = null), u === null ? "null" : '"' + ps(t ? t(u) : u.toString()) + '"')).join(s)}}`;
|
|
951
|
+
}
|
|
952
|
+
var Ve = { i: 0, char: null, str: "", quoted: !1, last: 0, p: null };
|
|
953
|
+
function ys(e, t, n) {
|
|
954
|
+
return Ve.i = Ve.last = 0, hn(Ve, e, t, n)[0];
|
|
955
|
+
}
|
|
956
|
+
function hn(e, t, n, i) {
|
|
957
|
+
let s = [], u = i === 1020 ? ";" : ",";
|
|
958
|
+
for (; e.i < t.length; e.i++) {
|
|
959
|
+
if (e.char = t[e.i], e.quoted) e.char === "\\" ? e.str += t[++e.i] : e.char === '"' ? (s.push(n ? n(e.str) : e.str), e.str = "", e.quoted = t[e.i + 1] === '"', e.last = e.i + 2) : e.str += e.char;
|
|
960
|
+
else if (e.char === '"') e.quoted = !0;
|
|
961
|
+
else if (e.char === "{") e.last = ++e.i, s.push(hn(e, t, n, i));
|
|
962
|
+
else if (e.char === "}") {
|
|
963
|
+
e.quoted = !1, e.last < e.i && s.push(n ? n(t.slice(e.last, e.i)) : t.slice(e.last, e.i)), e.last = e.i + 1;
|
|
964
|
+
break;
|
|
965
|
+
} else e.char === u && e.p !== "}" && e.p !== '"' && (s.push(n ? n(t.slice(e.last, e.i)) : t.slice(e.last, e.i)), e.last = e.i + 1);
|
|
966
|
+
e.p = e.char;
|
|
967
|
+
}
|
|
968
|
+
return e.last < e.i && s.push(n ? n(t.slice(e.last, e.i + 1)) : t.slice(e.last, e.i + 1)), s;
|
|
969
|
+
}
|
|
970
|
+
var gs = {};
|
|
971
|
+
qe(gs, { parseDescribeStatementResults: () => dn, parseResults: () => ms });
|
|
972
|
+
de();
|
|
973
|
+
function ms(e, t, n, i) {
|
|
974
|
+
let s = [], u = { rows: [], fields: [] }, h = 0, m = { ...t, ...n?.parsers };
|
|
975
|
+
return e.forEach((g) => {
|
|
976
|
+
switch (g.name) {
|
|
977
|
+
case "rowDescription": {
|
|
978
|
+
let E = g;
|
|
979
|
+
u.fields = E.fields.map((T) => ({ name: T.name, dataTypeID: T.dataTypeID }));
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
case "dataRow": {
|
|
983
|
+
if (!u) break;
|
|
984
|
+
let E = g;
|
|
985
|
+
n?.rowMode === "array" ? u.rows.push(E.fields.map((T, L) => tt(T, u.fields[L].dataTypeID, m))) : u.rows.push(Object.fromEntries(E.fields.map((T, L) => [u.fields[L].name, tt(T, u.fields[L].dataTypeID, m)])));
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
case "commandComplete": {
|
|
989
|
+
h += _s(g), s.push({ ...u, affectedRows: h, ...i ? { blob: i } : {} }), u = { rows: [], fields: [] };
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}), s.length === 0 && s.push({ affectedRows: 0, rows: [], fields: [] }), s;
|
|
994
|
+
}
|
|
995
|
+
function _s(e) {
|
|
996
|
+
let t = e.text.split(" ");
|
|
997
|
+
switch (t[0]) {
|
|
998
|
+
case "INSERT":
|
|
999
|
+
return parseInt(t[2], 10);
|
|
1000
|
+
case "UPDATE":
|
|
1001
|
+
case "DELETE":
|
|
1002
|
+
case "COPY":
|
|
1003
|
+
case "MERGE":
|
|
1004
|
+
return parseInt(t[1], 10);
|
|
1005
|
+
default:
|
|
1006
|
+
return 0;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function dn(e) {
|
|
1010
|
+
let t = e.find((n) => n.name === "parameterDescription");
|
|
1011
|
+
return t ? t.dataTypeIDs : [];
|
|
1012
|
+
}
|
|
1013
|
+
var pn = {};
|
|
1014
|
+
qe(pn, { AuthenticationCleartextPassword: () => In, AuthenticationMD5Password: () => vn, AuthenticationOk: () => Tn, AuthenticationSASL: () => $n, AuthenticationSASLContinue: () => Sn, AuthenticationSASLFinal: () => Nn, BackendKeyDataMessage: () => Un, CommandCompleteMessage: () => jn, CopyDataMessage: () => Rn, CopyResponse: () => Ln, DataRowMessage: () => Fn, DatabaseError: () => nt, Field: () => On, NoticeMessage: () => xn, NotificationResponseMessage: () => Bn, ParameterDescriptionMessage: () => Dn, ParameterStatusMessage: () => Mn, ReadyForQueryMessage: () => qn, RowDescriptionMessage: () => Cn, bindComplete: () => gn, closeComplete: () => mn, copyDone: () => An, emptyQuery: () => bn, noData: () => _n, parseComplete: () => yn, portalSuspended: () => wn, replicationStart: () => En });
|
|
1015
|
+
de();
|
|
1016
|
+
var yn = { name: "parseComplete", length: 5 }, gn = { name: "bindComplete", length: 5 }, mn = { name: "closeComplete", length: 5 }, _n = { name: "noData", length: 5 }, wn = { name: "portalSuspended", length: 5 }, En = { name: "replicationStart", length: 4 }, bn = { name: "emptyQuery", length: 4 }, An = { name: "copyDone", length: 4 }, Tn = class {
|
|
1017
|
+
constructor(t) {
|
|
1018
|
+
this.length = t, this.name = "authenticationOk";
|
|
1019
|
+
}
|
|
1020
|
+
}, In = class {
|
|
1021
|
+
constructor(e) {
|
|
1022
|
+
this.length = e, this.name = "authenticationCleartextPassword";
|
|
1023
|
+
}
|
|
1024
|
+
}, vn = class {
|
|
1025
|
+
constructor(e, t) {
|
|
1026
|
+
this.length = e, this.salt = t, this.name = "authenticationMD5Password";
|
|
1027
|
+
}
|
|
1028
|
+
}, $n = class {
|
|
1029
|
+
constructor(t, n) {
|
|
1030
|
+
this.length = t, this.mechanisms = n, this.name = "authenticationSASL";
|
|
1031
|
+
}
|
|
1032
|
+
}, Sn = class {
|
|
1033
|
+
constructor(e, t) {
|
|
1034
|
+
this.length = e, this.data = t, this.name = "authenticationSASLContinue";
|
|
1035
|
+
}
|
|
1036
|
+
}, Nn = class {
|
|
1037
|
+
constructor(e, t) {
|
|
1038
|
+
this.length = e, this.data = t, this.name = "authenticationSASLFinal";
|
|
1039
|
+
}
|
|
1040
|
+
}, nt = class extends Error {
|
|
1041
|
+
constructor(e, t, n) {
|
|
1042
|
+
super(e), this.length = t, this.name = n;
|
|
1043
|
+
}
|
|
1044
|
+
}, Rn = class {
|
|
1045
|
+
constructor(e, t) {
|
|
1046
|
+
this.length = e, this.chunk = t, this.name = "copyData";
|
|
1047
|
+
}
|
|
1048
|
+
}, Ln = class {
|
|
1049
|
+
constructor(e, t, n, i) {
|
|
1050
|
+
this.length = e, this.name = t, this.binary = n, this.columnTypes = new Array(i);
|
|
1051
|
+
}
|
|
1052
|
+
}, On = class {
|
|
1053
|
+
constructor(e, t, n, i, s, u, h) {
|
|
1054
|
+
this.name = e, this.tableID = t, this.columnID = n, this.dataTypeID = i, this.dataTypeSize = s, this.dataTypeModifier = u, this.format = h;
|
|
1055
|
+
}
|
|
1056
|
+
}, Cn = class {
|
|
1057
|
+
constructor(t, n) {
|
|
1058
|
+
this.length = t, this.fieldCount = n, this.name = "rowDescription", this.fields = new Array(this.fieldCount);
|
|
1059
|
+
}
|
|
1060
|
+
}, Dn = class {
|
|
1061
|
+
constructor(e, t) {
|
|
1062
|
+
this.length = e, this.parameterCount = t, this.name = "parameterDescription", this.dataTypeIDs = new Array(this.parameterCount);
|
|
1063
|
+
}
|
|
1064
|
+
}, Mn = class {
|
|
1065
|
+
constructor(e, t, n) {
|
|
1066
|
+
this.length = e, this.parameterName = t, this.parameterValue = n, this.name = "parameterStatus";
|
|
1067
|
+
}
|
|
1068
|
+
}, Un = class {
|
|
1069
|
+
constructor(e, t, n) {
|
|
1070
|
+
this.length = e, this.processID = t, this.secretKey = n, this.name = "backendKeyData";
|
|
1071
|
+
}
|
|
1072
|
+
}, Bn = class {
|
|
1073
|
+
constructor(e, t, n, i) {
|
|
1074
|
+
this.length = e, this.processId = t, this.channel = n, this.payload = i, this.name = "notification";
|
|
1075
|
+
}
|
|
1076
|
+
}, qn = class {
|
|
1077
|
+
constructor(e, t) {
|
|
1078
|
+
this.length = e, this.status = t, this.name = "readyForQuery";
|
|
1079
|
+
}
|
|
1080
|
+
}, jn = class {
|
|
1081
|
+
constructor(e, t) {
|
|
1082
|
+
this.length = e, this.text = t, this.name = "commandComplete";
|
|
1083
|
+
}
|
|
1084
|
+
}, Fn = class {
|
|
1085
|
+
constructor(e, t) {
|
|
1086
|
+
this.length = e, this.fields = t, this.name = "dataRow", this.fieldCount = t.length;
|
|
1087
|
+
}
|
|
1088
|
+
}, xn = class {
|
|
1089
|
+
constructor(e, t) {
|
|
1090
|
+
this.length = e, this.message = t, this.name = "notice";
|
|
1091
|
+
}
|
|
1092
|
+
}, ws = {};
|
|
1093
|
+
qe(ws, { Parser: () => Vs, messages: () => pn, serialize: () => Re });
|
|
1094
|
+
de();
|
|
1095
|
+
de();
|
|
1096
|
+
de();
|
|
1097
|
+
de();
|
|
1098
|
+
function je(e) {
|
|
1099
|
+
let t = e.length;
|
|
1100
|
+
for (let n = e.length - 1; n >= 0; n--) {
|
|
1101
|
+
let i = e.charCodeAt(n);
|
|
1102
|
+
i > 127 && i <= 2047 ? t++ : i > 2047 && i <= 65535 && (t += 2), i >= 56320 && i <= 57343 && n--;
|
|
1103
|
+
}
|
|
1104
|
+
return t;
|
|
1105
|
+
}
|
|
1106
|
+
var se, Z, Ie, rt, Te, ye, Ce, be, Pn, Fe = class {
|
|
1107
|
+
constructor(e = 256) {
|
|
1108
|
+
this.size = e, ie(this, ye), ie(this, se), ie(this, Z, 5), ie(this, Ie, !1), ie(this, rt, new TextEncoder()), ie(this, Te, 0), Y(this, se, G(this, ye, Ce).call(this, e));
|
|
1109
|
+
}
|
|
1110
|
+
addInt32(e) {
|
|
1111
|
+
return G(this, ye, be).call(this, 4), A(this, se).setInt32(A(this, Z), e, A(this, Ie)), Y(this, Z, A(this, Z) + 4), this;
|
|
1112
|
+
}
|
|
1113
|
+
addInt16(e) {
|
|
1114
|
+
return G(this, ye, be).call(this, 2), A(this, se).setInt16(A(this, Z), e, A(this, Ie)), Y(this, Z, A(this, Z) + 2), this;
|
|
1115
|
+
}
|
|
1116
|
+
addCString(e) {
|
|
1117
|
+
return e && this.addString(e), G(this, ye, be).call(this, 1), A(this, se).setUint8(A(this, Z), 0), Xt(this, Z)._++, this;
|
|
1118
|
+
}
|
|
1119
|
+
addString(e = "") {
|
|
1120
|
+
let t = je(e);
|
|
1121
|
+
return G(this, ye, be).call(this, t), A(this, rt).encodeInto(e, new Uint8Array(A(this, se).buffer, A(this, Z))), Y(this, Z, A(this, Z) + t), this;
|
|
1122
|
+
}
|
|
1123
|
+
add(e) {
|
|
1124
|
+
return G(this, ye, be).call(this, e.byteLength), new Uint8Array(A(this, se).buffer).set(new Uint8Array(e), A(this, Z)), Y(this, Z, A(this, Z) + e.byteLength), this;
|
|
1125
|
+
}
|
|
1126
|
+
flush(e) {
|
|
1127
|
+
let t = G(this, ye, Pn).call(this, e);
|
|
1128
|
+
return Y(this, Z, 5), Y(this, se, G(this, ye, Ce).call(this, this.size)), new Uint8Array(t);
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
se = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), Ie = /* @__PURE__ */ new WeakMap(), rt = /* @__PURE__ */ new WeakMap(), Te = /* @__PURE__ */ new WeakMap(), ye = /* @__PURE__ */ new WeakSet(), Ce = function(e) {
|
|
1132
|
+
return new DataView(new ArrayBuffer(e));
|
|
1133
|
+
}, be = function(e) {
|
|
1134
|
+
if (A(this, se).byteLength - A(this, Z) < e) {
|
|
1135
|
+
let t = A(this, se).buffer, n = t.byteLength + (t.byteLength >> 1) + e;
|
|
1136
|
+
Y(this, se, G(this, ye, Ce).call(this, n)), new Uint8Array(A(this, se).buffer).set(new Uint8Array(t));
|
|
1137
|
+
}
|
|
1138
|
+
}, Pn = function(e) {
|
|
1139
|
+
if (e) {
|
|
1140
|
+
A(this, se).setUint8(A(this, Te), e);
|
|
1141
|
+
let t = A(this, Z) - (A(this, Te) + 1);
|
|
1142
|
+
A(this, se).setInt32(A(this, Te) + 1, t, A(this, Ie));
|
|
1143
|
+
}
|
|
1144
|
+
return A(this, se).buffer.slice(e ? 0 : 5, A(this, Z));
|
|
1145
|
+
};
|
|
1146
|
+
var J = new Fe(), Es = (e) => {
|
|
1147
|
+
J.addInt16(3).addInt16(0);
|
|
1148
|
+
for (let i of Object.keys(e)) J.addCString(i).addCString(e[i]);
|
|
1149
|
+
J.addCString("client_encoding").addCString("UTF8");
|
|
1150
|
+
let t = J.addCString("").flush(), n = t.byteLength + 4;
|
|
1151
|
+
return new Fe().addInt32(n).add(t).flush();
|
|
1152
|
+
}, bs = () => {
|
|
1153
|
+
let e = new DataView(new ArrayBuffer(8));
|
|
1154
|
+
return e.setInt32(0, 8, !1), e.setInt32(4, 80877103, !1), new Uint8Array(e.buffer);
|
|
1155
|
+
}, As = (e) => J.addCString(e).flush(112), Ts = (e, t) => (J.addCString(e).addInt32(je(t)).addString(t), J.flush(112)), Is = (e) => J.addString(e).flush(112), vs = (e) => J.addCString(e).flush(81), $s = [], Ss = (e) => {
|
|
1156
|
+
let t = e.name ?? "";
|
|
1157
|
+
t.length > 63 && (console.error("Warning! Postgres only supports 63 characters for query names."), console.error("You supplied %s (%s)", t, t.length), console.error("This can cause conflicts and silent errors executing queries"));
|
|
1158
|
+
let n = J.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
|
|
1159
|
+
return e.types?.forEach((i) => n.addInt32(i)), J.flush(80);
|
|
1160
|
+
}, Ae = new Fe(), Ns = (e, t) => {
|
|
1161
|
+
for (let n = 0; n < e.length; n++) {
|
|
1162
|
+
let i = t ? t(e[n], n) : e[n];
|
|
1163
|
+
if (i === null) J.addInt16(0), Ae.addInt32(-1);
|
|
1164
|
+
else if (i instanceof ArrayBuffer || ArrayBuffer.isView(i)) {
|
|
1165
|
+
let s = ArrayBuffer.isView(i) ? i.buffer.slice(i.byteOffset, i.byteOffset + i.byteLength) : i;
|
|
1166
|
+
J.addInt16(1), Ae.addInt32(s.byteLength), Ae.add(s);
|
|
1167
|
+
} else J.addInt16(0), Ae.addInt32(je(i)), Ae.addString(i);
|
|
1168
|
+
}
|
|
1169
|
+
}, Rs = (e = {}) => {
|
|
1170
|
+
let t = e.portal ?? "", n = e.statement ?? "", i = e.binary ?? !1, s = e.values ?? $s, u = s.length;
|
|
1171
|
+
return J.addCString(t).addCString(n), J.addInt16(u), Ns(s, e.valueMapper), J.addInt16(u), J.add(Ae.flush()), J.addInt16(i ? 1 : 0), J.flush(66);
|
|
1172
|
+
}, Ls = new Uint8Array([69, 0, 0, 0, 9, 0, 0, 0, 0, 0]), Os = (e) => {
|
|
1173
|
+
if (!e || !e.portal && !e.rows) return Ls;
|
|
1174
|
+
let t = e.portal ?? "", n = e.rows ?? 0, i = je(t), s = 4 + i + 1 + 4, u = new DataView(new ArrayBuffer(1 + s));
|
|
1175
|
+
return u.setUint8(0, 69), u.setInt32(1, s, !1), new TextEncoder().encodeInto(t, new Uint8Array(u.buffer, 5)), u.setUint8(i + 5, 0), u.setUint32(u.byteLength - 4, n, !1), new Uint8Array(u.buffer);
|
|
1176
|
+
}, Cs = (e, t) => {
|
|
1177
|
+
let n = new DataView(new ArrayBuffer(16));
|
|
1178
|
+
return n.setInt32(0, 16, !1), n.setInt16(4, 1234, !1), n.setInt16(6, 5678, !1), n.setInt32(8, e, !1), n.setInt32(12, t, !1), new Uint8Array(n.buffer);
|
|
1179
|
+
}, ct = (e, t) => {
|
|
1180
|
+
let n = new Fe();
|
|
1181
|
+
return n.addCString(t), n.flush(e);
|
|
1182
|
+
}, Ds = J.addCString("P").flush(68), Ms = J.addCString("S").flush(68), Us = (e) => e.name ? ct(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? Ds : Ms, Bs = (e) => {
|
|
1183
|
+
let t = `${e.type}${e.name ?? ""}`;
|
|
1184
|
+
return ct(67, t);
|
|
1185
|
+
}, qs = (e) => J.add(e).flush(100), js = (e) => ct(102, e), xe = (e) => new Uint8Array([e, 0, 0, 0, 4]), Fs = xe(72), xs = xe(83), Ps = xe(88), ks = xe(99), Re = { startup: Es, password: As, requestSsl: bs, sendSASLInitialResponseMessage: Ts, sendSCRAMClientFinalMessage: Is, query: vs, parse: Ss, bind: Rs, execute: Os, describe: Us, close: Bs, flush: () => Fs, sync: () => xs, end: () => Ps, copyData: qs, copyDone: () => ks, copyFail: js, cancel: Cs };
|
|
1186
|
+
de();
|
|
1187
|
+
de();
|
|
1188
|
+
var _t = { text: 0, binary: 1 };
|
|
1189
|
+
de();
|
|
1190
|
+
var Ws = new ArrayBuffer(0), we, ne, st, it, Le, Gs = class {
|
|
1191
|
+
constructor(e = 0) {
|
|
1192
|
+
ie(this, we, new DataView(Ws)), ie(this, ne), ie(this, st, "utf-8"), ie(this, it, new TextDecoder(A(this, st))), ie(this, Le, !1), Y(this, ne, e);
|
|
1193
|
+
}
|
|
1194
|
+
setBuffer(e, t) {
|
|
1195
|
+
Y(this, ne, e), Y(this, we, new DataView(t));
|
|
1196
|
+
}
|
|
1197
|
+
int16() {
|
|
1198
|
+
let e = A(this, we).getInt16(A(this, ne), A(this, Le));
|
|
1199
|
+
return Y(this, ne, A(this, ne) + 2), e;
|
|
1200
|
+
}
|
|
1201
|
+
byte() {
|
|
1202
|
+
let e = A(this, we).getUint8(A(this, ne));
|
|
1203
|
+
return Xt(this, ne)._++, e;
|
|
1204
|
+
}
|
|
1205
|
+
int32() {
|
|
1206
|
+
let e = A(this, we).getInt32(A(this, ne), A(this, Le));
|
|
1207
|
+
return Y(this, ne, A(this, ne) + 4), e;
|
|
1208
|
+
}
|
|
1209
|
+
string(e) {
|
|
1210
|
+
return A(this, it).decode(this.bytes(e));
|
|
1211
|
+
}
|
|
1212
|
+
cstring() {
|
|
1213
|
+
let e = A(this, ne), t = e;
|
|
1214
|
+
for (; A(this, we).getUint8(t++) !== 0; ) ;
|
|
1215
|
+
let n = this.string(t - e - 1);
|
|
1216
|
+
return Y(this, ne, t), n;
|
|
1217
|
+
}
|
|
1218
|
+
bytes(e) {
|
|
1219
|
+
let t = A(this, we).buffer.slice(A(this, ne), A(this, ne) + e);
|
|
1220
|
+
return Y(this, ne, A(this, ne) + e), new Uint8Array(t);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
we = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new WeakMap(), st = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap();
|
|
1224
|
+
var at = 1, Ys = 4, wt = at + Ys, Et = new ArrayBuffer(0), le, ce, fe, F, Q, kn, Wn, bt, At, Tt, It, vt, He, $t, St, Nt, Rt, Lt, Ot, Ct, Dt, Je, Vs = class {
|
|
1225
|
+
constructor() {
|
|
1226
|
+
ie(this, Q), ie(this, le, new DataView(Et)), ie(this, ce, 0), ie(this, fe, 0), ie(this, F, new Gs());
|
|
1227
|
+
}
|
|
1228
|
+
parse(e, t) {
|
|
1229
|
+
G(this, Q, kn).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
|
|
1230
|
+
let n = A(this, fe) + A(this, ce), i = A(this, fe);
|
|
1231
|
+
for (; i + wt <= n; ) {
|
|
1232
|
+
let s = A(this, le).getUint8(i), u = A(this, le).getUint32(i + at, !1), h = at + u;
|
|
1233
|
+
if (h + i <= n && u > 0) {
|
|
1234
|
+
let m = G(this, Q, Wn).call(this, i + wt, s, u, A(this, le).buffer);
|
|
1235
|
+
t(m), i += h;
|
|
1236
|
+
} else break;
|
|
1237
|
+
}
|
|
1238
|
+
i === n ? (Y(this, le, new DataView(Et)), Y(this, ce, 0), Y(this, fe, 0)) : (Y(this, ce, n - i), Y(this, fe, i));
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
le = /* @__PURE__ */ new WeakMap(), ce = /* @__PURE__ */ new WeakMap(), fe = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakSet(), kn = function(e) {
|
|
1242
|
+
if (A(this, ce) > 0) {
|
|
1243
|
+
let t = A(this, ce) + e.byteLength;
|
|
1244
|
+
if (t + A(this, fe) > A(this, le).byteLength) {
|
|
1245
|
+
let n;
|
|
1246
|
+
if (t <= A(this, le).byteLength && A(this, fe) >= A(this, ce)) n = A(this, le).buffer;
|
|
1247
|
+
else {
|
|
1248
|
+
let i = A(this, le).byteLength * 2;
|
|
1249
|
+
for (; t >= i; ) i *= 2;
|
|
1250
|
+
n = new ArrayBuffer(i);
|
|
1251
|
+
}
|
|
1252
|
+
new Uint8Array(n).set(new Uint8Array(A(this, le).buffer, A(this, fe), A(this, ce))), Y(this, le, new DataView(n)), Y(this, fe, 0);
|
|
1253
|
+
}
|
|
1254
|
+
new Uint8Array(A(this, le).buffer).set(new Uint8Array(e), A(this, fe) + A(this, ce)), Y(this, ce, t);
|
|
1255
|
+
} else Y(this, le, new DataView(e)), Y(this, fe, 0), Y(this, ce, e.byteLength);
|
|
1256
|
+
}, Wn = function(e, t, n, i) {
|
|
1257
|
+
switch (t) {
|
|
1258
|
+
case 50:
|
|
1259
|
+
return gn;
|
|
1260
|
+
case 49:
|
|
1261
|
+
return yn;
|
|
1262
|
+
case 51:
|
|
1263
|
+
return mn;
|
|
1264
|
+
case 110:
|
|
1265
|
+
return _n;
|
|
1266
|
+
case 115:
|
|
1267
|
+
return wn;
|
|
1268
|
+
case 99:
|
|
1269
|
+
return An;
|
|
1270
|
+
case 87:
|
|
1271
|
+
return En;
|
|
1272
|
+
case 73:
|
|
1273
|
+
return bn;
|
|
1274
|
+
case 68:
|
|
1275
|
+
return G(this, Q, Lt).call(this, e, n, i);
|
|
1276
|
+
case 67:
|
|
1277
|
+
return G(this, Q, At).call(this, e, n, i);
|
|
1278
|
+
case 90:
|
|
1279
|
+
return G(this, Q, bt).call(this, e, n, i);
|
|
1280
|
+
case 65:
|
|
1281
|
+
return G(this, Q, $t).call(this, e, n, i);
|
|
1282
|
+
case 82:
|
|
1283
|
+
return G(this, Q, Dt).call(this, e, n, i);
|
|
1284
|
+
case 83:
|
|
1285
|
+
return G(this, Q, Ot).call(this, e, n, i);
|
|
1286
|
+
case 75:
|
|
1287
|
+
return G(this, Q, Ct).call(this, e, n, i);
|
|
1288
|
+
case 69:
|
|
1289
|
+
return G(this, Q, Je).call(this, e, n, i, "error");
|
|
1290
|
+
case 78:
|
|
1291
|
+
return G(this, Q, Je).call(this, e, n, i, "notice");
|
|
1292
|
+
case 84:
|
|
1293
|
+
return G(this, Q, St).call(this, e, n, i);
|
|
1294
|
+
case 116:
|
|
1295
|
+
return G(this, Q, Rt).call(this, e, n, i);
|
|
1296
|
+
case 71:
|
|
1297
|
+
return G(this, Q, It).call(this, e, n, i);
|
|
1298
|
+
case 72:
|
|
1299
|
+
return G(this, Q, vt).call(this, e, n, i);
|
|
1300
|
+
case 100:
|
|
1301
|
+
return G(this, Q, Tt).call(this, e, n, i);
|
|
1302
|
+
default:
|
|
1303
|
+
return new nt("received invalid response: " + t.toString(16), n, "error");
|
|
1304
|
+
}
|
|
1305
|
+
}, bt = function(e, t, n) {
|
|
1306
|
+
A(this, F).setBuffer(e, n);
|
|
1307
|
+
let i = A(this, F).string(1);
|
|
1308
|
+
return new qn(t, i);
|
|
1309
|
+
}, At = function(e, t, n) {
|
|
1310
|
+
A(this, F).setBuffer(e, n);
|
|
1311
|
+
let i = A(this, F).cstring();
|
|
1312
|
+
return new jn(t, i);
|
|
1313
|
+
}, Tt = function(e, t, n) {
|
|
1314
|
+
let i = n.slice(e, e + (t - 4));
|
|
1315
|
+
return new Rn(t, new Uint8Array(i));
|
|
1316
|
+
}, It = function(e, t, n) {
|
|
1317
|
+
return G(this, Q, He).call(this, e, t, n, "copyInResponse");
|
|
1318
|
+
}, vt = function(e, t, n) {
|
|
1319
|
+
return G(this, Q, He).call(this, e, t, n, "copyOutResponse");
|
|
1320
|
+
}, He = function(e, t, n, i) {
|
|
1321
|
+
A(this, F).setBuffer(e, n);
|
|
1322
|
+
let s = A(this, F).byte() !== 0, u = A(this, F).int16(), h = new Ln(t, i, s, u);
|
|
1323
|
+
for (let m = 0; m < u; m++) h.columnTypes[m] = A(this, F).int16();
|
|
1324
|
+
return h;
|
|
1325
|
+
}, $t = function(e, t, n) {
|
|
1326
|
+
A(this, F).setBuffer(e, n);
|
|
1327
|
+
let i = A(this, F).int32(), s = A(this, F).cstring(), u = A(this, F).cstring();
|
|
1328
|
+
return new Bn(t, i, s, u);
|
|
1329
|
+
}, St = function(e, t, n) {
|
|
1330
|
+
A(this, F).setBuffer(e, n);
|
|
1331
|
+
let i = A(this, F).int16(), s = new Cn(t, i);
|
|
1332
|
+
for (let u = 0; u < i; u++) s.fields[u] = G(this, Q, Nt).call(this);
|
|
1333
|
+
return s;
|
|
1334
|
+
}, Nt = function() {
|
|
1335
|
+
let e = A(this, F).cstring(), t = A(this, F).int32(), n = A(this, F).int16(), i = A(this, F).int32(), s = A(this, F).int16(), u = A(this, F).int32(), h = A(this, F).int16() === 0 ? _t.text : _t.binary;
|
|
1336
|
+
return new On(e, t, n, i, s, u, h);
|
|
1337
|
+
}, Rt = function(e, t, n) {
|
|
1338
|
+
A(this, F).setBuffer(e, n);
|
|
1339
|
+
let i = A(this, F).int16(), s = new Dn(t, i);
|
|
1340
|
+
for (let u = 0; u < i; u++) s.dataTypeIDs[u] = A(this, F).int32();
|
|
1341
|
+
return s;
|
|
1342
|
+
}, Lt = function(e, t, n) {
|
|
1343
|
+
A(this, F).setBuffer(e, n);
|
|
1344
|
+
let i = A(this, F).int16(), s = new Array(i);
|
|
1345
|
+
for (let u = 0; u < i; u++) {
|
|
1346
|
+
let h = A(this, F).int32();
|
|
1347
|
+
s[u] = h === -1 ? null : A(this, F).string(h);
|
|
1348
|
+
}
|
|
1349
|
+
return new Fn(t, s);
|
|
1350
|
+
}, Ot = function(e, t, n) {
|
|
1351
|
+
A(this, F).setBuffer(e, n);
|
|
1352
|
+
let i = A(this, F).cstring(), s = A(this, F).cstring();
|
|
1353
|
+
return new Mn(t, i, s);
|
|
1354
|
+
}, Ct = function(e, t, n) {
|
|
1355
|
+
A(this, F).setBuffer(e, n);
|
|
1356
|
+
let i = A(this, F).int32(), s = A(this, F).int32();
|
|
1357
|
+
return new Un(t, i, s);
|
|
1358
|
+
}, Dt = function(e, t, n) {
|
|
1359
|
+
A(this, F).setBuffer(e, n);
|
|
1360
|
+
let i = A(this, F).int32();
|
|
1361
|
+
switch (i) {
|
|
1362
|
+
case 0:
|
|
1363
|
+
return new Tn(t);
|
|
1364
|
+
case 3:
|
|
1365
|
+
return new In(t);
|
|
1366
|
+
case 5:
|
|
1367
|
+
return new vn(t, A(this, F).bytes(4));
|
|
1368
|
+
case 10: {
|
|
1369
|
+
let s = [];
|
|
1370
|
+
for (; ; ) {
|
|
1371
|
+
let u = A(this, F).cstring();
|
|
1372
|
+
if (u.length === 0) return new $n(t, s);
|
|
1373
|
+
s.push(u);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
case 11:
|
|
1377
|
+
return new Sn(t, A(this, F).string(t - 8));
|
|
1378
|
+
case 12:
|
|
1379
|
+
return new Nn(t, A(this, F).string(t - 8));
|
|
1380
|
+
default:
|
|
1381
|
+
throw new Error("Unknown authenticationOk message type " + i);
|
|
1382
|
+
}
|
|
1383
|
+
}, Je = function(e, t, n, i) {
|
|
1384
|
+
A(this, F).setBuffer(e, n);
|
|
1385
|
+
let s = {}, u = A(this, F).string(1);
|
|
1386
|
+
for (; u !== "\0"; ) s[u] = A(this, F).cstring(), u = A(this, F).string(1);
|
|
1387
|
+
let h = s.M, m = i === "notice" ? new xn(t, h) : new nt(h, t, i);
|
|
1388
|
+
return m.severity = s.S, m.code = s.C, m.detail = s.D, m.hint = s.H, m.position = s.P, m.internalPosition = s.p, m.internalQuery = s.q, m.where = s.W, m.schema = s.s, m.table = s.t, m.column = s.c, m.dataType = s.d, m.constraint = s.n, m.file = s.F, m.line = s.L, m.routine = s.R, m;
|
|
1389
|
+
};
|
|
1390
|
+
de();
|
|
1391
|
+
typeof process == "object" && typeof process.versions == "object" && process.versions.node;
|
|
1392
|
+
var Mt = () => {
|
|
1393
|
+
if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
|
|
1394
|
+
let e = new Uint8Array(16);
|
|
1395
|
+
if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(e);
|
|
1396
|
+
else for (let n = 0; n < e.length; n++) e[n] = Math.floor(Math.random() * 256);
|
|
1397
|
+
e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
|
|
1398
|
+
let t = [];
|
|
1399
|
+
return e.forEach((n) => {
|
|
1400
|
+
t.push(n.toString(16).padStart(2, "0"));
|
|
1401
|
+
}), t.slice(0, 4).join("") + "-" + t.slice(4, 6).join("") + "-" + t.slice(6, 8).join("") + "-" + t.slice(8, 10).join("") + "-" + t.slice(10).join("");
|
|
1402
|
+
};
|
|
1403
|
+
async function Ut(e, t, n, i) {
|
|
1404
|
+
if (!n || n.length === 0) return t;
|
|
1405
|
+
i = i ?? e;
|
|
1406
|
+
let s = [];
|
|
1407
|
+
try {
|
|
1408
|
+
await e.execProtocol(Re.parse({ text: t }), { syncToFs: !1 }), s.push(...(await e.execProtocol(Re.describe({ type: "S" }), { syncToFs: !1 })).messages);
|
|
1409
|
+
} finally {
|
|
1410
|
+
s.push(...(await e.execProtocol(Re.sync(), { syncToFs: !1 })).messages);
|
|
1411
|
+
}
|
|
1412
|
+
let u = dn(s), h = t.replace(/\$([0-9]+)/g, (m, g) => "%" + g + "L");
|
|
1413
|
+
return (await i.query(`SELECT format($1, ${n.map((m, g) => `$${g + 2}`).join(", ")}) as query`, [h, ...n], { paramTypes: [Oe, ...u] })).rows[0].query;
|
|
1414
|
+
}
|
|
1415
|
+
function Bt(e) {
|
|
1416
|
+
let t, n = !1, i = async () => {
|
|
1417
|
+
if (!t) {
|
|
1418
|
+
n = !1;
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
n = !0;
|
|
1422
|
+
let { args: s, resolve: u, reject: h } = t;
|
|
1423
|
+
t = void 0;
|
|
1424
|
+
try {
|
|
1425
|
+
let m = await e(...s);
|
|
1426
|
+
u(m);
|
|
1427
|
+
} catch (m) {
|
|
1428
|
+
h(m);
|
|
1429
|
+
} finally {
|
|
1430
|
+
i();
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
return async (...s) => {
|
|
1434
|
+
t && t.resolve(void 0);
|
|
1435
|
+
let u = new Promise((h, m) => {
|
|
1436
|
+
t = { args: s, resolve: h, reject: m };
|
|
1437
|
+
});
|
|
1438
|
+
return n || i(), u;
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
de();
|
|
1442
|
+
var Hs = 5, Js = async (e, t) => {
|
|
1443
|
+
let n = /* @__PURE__ */ new Set(), i = { async query(s, u, h) {
|
|
1444
|
+
let m, g, E;
|
|
1445
|
+
if (typeof s != "string" && (m = s.signal, u = s.params, h = s.callback, g = s.offset, E = s.limit, s = s.query), g === void 0 != (E === void 0)) throw new Error("offset and limit must be provided together");
|
|
1446
|
+
let T = g !== void 0 && E !== void 0, L;
|
|
1447
|
+
if (T && (typeof g != "number" || isNaN(g) || typeof E != "number" || isNaN(E))) throw new Error("offset and limit must be numbers");
|
|
1448
|
+
let D = h ? [h] : [], B = Mt().replace(/-/g, ""), I = !1, U, _, N, R = async () => {
|
|
1449
|
+
await e.transaction(async (f) => {
|
|
1450
|
+
let p = u && u.length > 0 ? await Ut(e, s, u, f) : s;
|
|
1451
|
+
await f.exec(`CREATE OR REPLACE TEMP VIEW live_query_${B}_view AS ${p}`), _ = await qt(f, `live_query_${B}_view`), await jt(f, _, n), T ? (await f.exec(`
|
|
1452
|
+
PREPARE live_query_${B}_get(int, int) AS
|
|
1453
|
+
SELECT * FROM live_query_${B}_view
|
|
1454
|
+
LIMIT $1 OFFSET $2;
|
|
1455
|
+
`), await f.exec(`
|
|
1456
|
+
PREPARE live_query_${B}_get_total_count AS
|
|
1457
|
+
SELECT COUNT(*) FROM live_query_${B}_view;
|
|
1458
|
+
`), L = (await f.query(`EXECUTE live_query_${B}_get_total_count;`)).rows[0].count, U = { ...await f.query(`EXECUTE live_query_${B}_get(${E}, ${g});`), offset: g, limit: E, totalCount: L }) : (await f.exec(`
|
|
1459
|
+
PREPARE live_query_${B}_get AS
|
|
1460
|
+
SELECT * FROM live_query_${B}_view;
|
|
1461
|
+
`), U = await f.query(`EXECUTE live_query_${B}_get;`)), N = await Promise.all(_.map((o) => f.listen(`"table_change__${o.schema_name}__${o.table_name}"`, async () => {
|
|
1462
|
+
v();
|
|
1463
|
+
})));
|
|
1464
|
+
});
|
|
1465
|
+
};
|
|
1466
|
+
await R();
|
|
1467
|
+
let v = Bt(async ({ offset: f, limit: p } = {}) => {
|
|
1468
|
+
if (!T && (f !== void 0 || p !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
|
|
1469
|
+
if (f && (typeof f != "number" || isNaN(f)) || p && (typeof p != "number" || isNaN(p))) throw new Error("offset and limit must be numbers");
|
|
1470
|
+
g = f ?? g, E = p ?? E;
|
|
1471
|
+
let o = async (l = 0) => {
|
|
1472
|
+
if (D.length !== 0) {
|
|
1473
|
+
try {
|
|
1474
|
+
T ? U = { ...await e.query(`EXECUTE live_query_${B}_get(${E}, ${g});`), offset: g, limit: E, totalCount: L } : U = await e.query(`EXECUTE live_query_${B}_get;`);
|
|
1475
|
+
} catch (a) {
|
|
1476
|
+
let y = a.message;
|
|
1477
|
+
if (y.startsWith(`prepared statement "live_query_${B}`) && y.endsWith("does not exist")) {
|
|
1478
|
+
if (l > Hs) throw a;
|
|
1479
|
+
await R(), o(l + 1);
|
|
1480
|
+
} else throw a;
|
|
1481
|
+
}
|
|
1482
|
+
if (Ne(D, U), T) {
|
|
1483
|
+
let a = (await e.query(`EXECUTE live_query_${B}_get_total_count;`)).rows[0].count;
|
|
1484
|
+
a !== L && (L = a, v());
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
await o();
|
|
1489
|
+
}), b = (f) => {
|
|
1490
|
+
if (I) throw new Error("Live query is no longer active and cannot be subscribed to");
|
|
1491
|
+
D.push(f);
|
|
1492
|
+
}, M = async (f) => {
|
|
1493
|
+
f ? D = D.filter((p) => p !== p) : D = [], D.length === 0 && !I && (I = !0, await e.transaction(async (p) => {
|
|
1494
|
+
await Promise.all(N.map((o) => o(p))), await p.exec(`
|
|
1495
|
+
DROP VIEW IF EXISTS live_query_${B}_view;
|
|
1496
|
+
DEALLOCATE live_query_${B}_get;
|
|
1497
|
+
`);
|
|
1498
|
+
}));
|
|
1499
|
+
};
|
|
1500
|
+
return m?.aborted ? await M() : m?.addEventListener("abort", () => {
|
|
1501
|
+
M();
|
|
1502
|
+
}, { once: !0 }), Ne(D, U), { initialResults: U, subscribe: b, unsubscribe: M, refresh: v };
|
|
1503
|
+
}, async changes(s, u, h, m) {
|
|
1504
|
+
let g;
|
|
1505
|
+
if (typeof s != "string" && (g = s.signal, u = s.params, h = s.key, m = s.callback, s = s.query), !h) throw new Error("key is required for changes queries");
|
|
1506
|
+
let E = m ? [m] : [], T = Mt().replace(/-/g, ""), L = !1, D, B = 1, I, U, _ = async () => {
|
|
1507
|
+
await e.transaction(async (b) => {
|
|
1508
|
+
let M = await Ut(e, s, u, b);
|
|
1509
|
+
await b.query(`CREATE OR REPLACE TEMP VIEW live_query_${T}_view AS ${M}`), D = await qt(b, `live_query_${T}_view`), await jt(b, D, n);
|
|
1510
|
+
let f = [...(await b.query(`
|
|
1511
|
+
SELECT column_name, data_type, udt_name
|
|
1512
|
+
FROM information_schema.columns
|
|
1513
|
+
WHERE table_name = 'live_query_${T}_view'
|
|
1514
|
+
`)).rows, { column_name: "__after__", data_type: "integer" }];
|
|
1515
|
+
await b.exec(`
|
|
1516
|
+
CREATE TEMP TABLE live_query_${T}_state1 (LIKE live_query_${T}_view INCLUDING ALL);
|
|
1517
|
+
CREATE TEMP TABLE live_query_${T}_state2 (LIKE live_query_${T}_view INCLUDING ALL);
|
|
1518
|
+
`);
|
|
1519
|
+
for (let p of [1, 2]) {
|
|
1520
|
+
let o = p === 1 ? 2 : 1;
|
|
1521
|
+
await b.exec(`
|
|
1522
|
+
PREPARE live_query_${T}_diff${p} AS
|
|
1523
|
+
WITH
|
|
1524
|
+
prev AS (SELECT LAG("${h}") OVER () as __after__, * FROM live_query_${T}_state${o}),
|
|
1525
|
+
curr AS (SELECT LAG("${h}") OVER () as __after__, * FROM live_query_${T}_state${p}),
|
|
1526
|
+
data_diff AS (
|
|
1527
|
+
-- INSERT operations: Include all columns
|
|
1528
|
+
SELECT
|
|
1529
|
+
'INSERT' AS __op__,
|
|
1530
|
+
${f.map(({ column_name: l }) => `curr."${l}" AS "${l}"`).join(`,
|
|
1531
|
+
`)},
|
|
1532
|
+
ARRAY[]::text[] AS __changed_columns__
|
|
1533
|
+
FROM curr
|
|
1534
|
+
LEFT JOIN prev ON curr.${h} = prev.${h}
|
|
1535
|
+
WHERE prev.${h} IS NULL
|
|
1536
|
+
UNION ALL
|
|
1537
|
+
-- DELETE operations: Include only the primary key
|
|
1538
|
+
SELECT
|
|
1539
|
+
'DELETE' AS __op__,
|
|
1540
|
+
${f.map(({ column_name: l, data_type: a, udt_name: y }) => l === h ? `prev."${l}" AS "${l}"` : `NULL${a === "USER-DEFINED" ? `::${y}` : ""} AS "${l}"`).join(`,
|
|
1541
|
+
`)},
|
|
1542
|
+
ARRAY[]::text[] AS __changed_columns__
|
|
1543
|
+
FROM prev
|
|
1544
|
+
LEFT JOIN curr ON prev.${h} = curr.${h}
|
|
1545
|
+
WHERE curr.${h} IS NULL
|
|
1546
|
+
UNION ALL
|
|
1547
|
+
-- UPDATE operations: Include only changed columns
|
|
1548
|
+
SELECT
|
|
1549
|
+
'UPDATE' AS __op__,
|
|
1550
|
+
${f.map(({ column_name: l, data_type: a, udt_name: y }) => l === h ? `curr."${l}" AS "${l}"` : `CASE
|
|
1551
|
+
WHEN curr."${l}" IS DISTINCT FROM prev."${l}"
|
|
1552
|
+
THEN curr."${l}"
|
|
1553
|
+
ELSE NULL${a === "USER-DEFINED" ? `::${y}` : ""}
|
|
1554
|
+
END AS "${l}"`).join(`,
|
|
1555
|
+
`)},
|
|
1556
|
+
ARRAY(SELECT unnest FROM unnest(ARRAY[${f.filter(({ column_name: l }) => l !== h).map(({ column_name: l }) => `CASE
|
|
1557
|
+
WHEN curr."${l}" IS DISTINCT FROM prev."${l}"
|
|
1558
|
+
THEN '${l}'
|
|
1559
|
+
ELSE NULL
|
|
1560
|
+
END`).join(", ")}]) WHERE unnest IS NOT NULL) AS __changed_columns__
|
|
1561
|
+
FROM curr
|
|
1562
|
+
INNER JOIN prev ON curr.${h} = prev.${h}
|
|
1563
|
+
WHERE NOT (curr IS NOT DISTINCT FROM prev)
|
|
1564
|
+
)
|
|
1565
|
+
SELECT * FROM data_diff;
|
|
1566
|
+
`);
|
|
1567
|
+
}
|
|
1568
|
+
U = await Promise.all(D.map((p) => b.listen(`"table_change__${p.schema_name}__${p.table_name}"`, async () => {
|
|
1569
|
+
N();
|
|
1570
|
+
})));
|
|
1571
|
+
});
|
|
1572
|
+
};
|
|
1573
|
+
await _();
|
|
1574
|
+
let N = Bt(async () => {
|
|
1575
|
+
if (E.length === 0 && I) return;
|
|
1576
|
+
let b = !1;
|
|
1577
|
+
for (let M = 0; M < 5; M++) try {
|
|
1578
|
+
await e.transaction(async (f) => {
|
|
1579
|
+
await f.exec(`
|
|
1580
|
+
INSERT INTO live_query_${T}_state${B}
|
|
1581
|
+
SELECT * FROM live_query_${T}_view;
|
|
1582
|
+
`), I = await f.query(`EXECUTE live_query_${T}_diff${B};`), B = B === 1 ? 2 : 1, await f.exec(`
|
|
1583
|
+
TRUNCATE live_query_${T}_state${B};
|
|
1584
|
+
`);
|
|
1585
|
+
});
|
|
1586
|
+
break;
|
|
1587
|
+
} catch (f) {
|
|
1588
|
+
if (f.message === `relation "live_query_${T}_state${B}" does not exist`) {
|
|
1589
|
+
b = !0, await _();
|
|
1590
|
+
continue;
|
|
1591
|
+
} else throw f;
|
|
1592
|
+
}
|
|
1593
|
+
Ks(E, [...b ? [{ __op__: "RESET" }] : [], ...I.rows]);
|
|
1594
|
+
}), R = (b) => {
|
|
1595
|
+
if (L) throw new Error("Live query is no longer active and cannot be subscribed to");
|
|
1596
|
+
E.push(b);
|
|
1597
|
+
}, v = async (b) => {
|
|
1598
|
+
b ? E = E.filter((M) => M !== M) : E = [], E.length === 0 && !L && (L = !0, await e.transaction(async (M) => {
|
|
1599
|
+
await Promise.all(U.map((f) => f(M))), await M.exec(`
|
|
1600
|
+
DROP VIEW IF EXISTS live_query_${T}_view;
|
|
1601
|
+
DROP TABLE IF EXISTS live_query_${T}_state1;
|
|
1602
|
+
DROP TABLE IF EXISTS live_query_${T}_state2;
|
|
1603
|
+
DEALLOCATE live_query_${T}_diff1;
|
|
1604
|
+
DEALLOCATE live_query_${T}_diff2;
|
|
1605
|
+
`);
|
|
1606
|
+
}));
|
|
1607
|
+
};
|
|
1608
|
+
return g?.aborted ? await v() : g?.addEventListener("abort", () => {
|
|
1609
|
+
v();
|
|
1610
|
+
}, { once: !0 }), await N(), { fields: I.fields.filter((b) => !["__after__", "__op__", "__changed_columns__"].includes(b.name)), initialChanges: I.rows, subscribe: R, unsubscribe: v, refresh: N };
|
|
1611
|
+
}, async incrementalQuery(s, u, h, m) {
|
|
1612
|
+
let g;
|
|
1613
|
+
if (typeof s != "string" && (g = s.signal, u = s.params, h = s.key, m = s.callback, s = s.query), !h) throw new Error("key is required for incremental queries");
|
|
1614
|
+
let E = m ? [m] : [], T = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map(), D = [], B = !0, { fields: I, unsubscribe: U, refresh: _ } = await i.changes(s, u, h, (v) => {
|
|
1615
|
+
for (let f of v) {
|
|
1616
|
+
let { __op__: p, __changed_columns__: o, ...l } = f;
|
|
1617
|
+
switch (p) {
|
|
1618
|
+
case "RESET":
|
|
1619
|
+
T.clear(), L.clear();
|
|
1620
|
+
break;
|
|
1621
|
+
case "INSERT":
|
|
1622
|
+
T.set(l[h], l), L.set(l.__after__, l[h]);
|
|
1623
|
+
break;
|
|
1624
|
+
case "DELETE": {
|
|
1625
|
+
let a = T.get(l[h]);
|
|
1626
|
+
T.delete(l[h]), a.__after__ !== null && L.delete(a.__after__);
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
case "UPDATE": {
|
|
1630
|
+
let a = { ...T.get(l[h]) ?? {} };
|
|
1631
|
+
for (let y of o) a[y] = l[y], y === "__after__" && L.set(l.__after__, l[h]);
|
|
1632
|
+
T.set(l[h], a);
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
let b = [], M = null;
|
|
1638
|
+
for (let f = 0; f < T.size; f++) {
|
|
1639
|
+
let p = L.get(M), o = T.get(p);
|
|
1640
|
+
if (!o) break;
|
|
1641
|
+
let l = { ...o };
|
|
1642
|
+
delete l.__after__, b.push(l), M = p;
|
|
1643
|
+
}
|
|
1644
|
+
D = b, B || Ne(E, { rows: b, fields: I });
|
|
1645
|
+
});
|
|
1646
|
+
B = !1, Ne(E, { rows: D, fields: I });
|
|
1647
|
+
let N = (v) => {
|
|
1648
|
+
E.push(v);
|
|
1649
|
+
}, R = async (v) => {
|
|
1650
|
+
v ? E = E.filter((b) => b !== b) : E = [], E.length === 0 && await U();
|
|
1651
|
+
};
|
|
1652
|
+
return g?.aborted ? await R() : g?.addEventListener("abort", () => {
|
|
1653
|
+
R();
|
|
1654
|
+
}, { once: !0 }), { initialResults: { rows: D, fields: I }, subscribe: N, unsubscribe: R, refresh: _ };
|
|
1655
|
+
} };
|
|
1656
|
+
return { namespaceObj: i };
|
|
1657
|
+
}, zs = { name: "Live Queries", setup: Js };
|
|
1658
|
+
async function qt(e, t) {
|
|
1659
|
+
return (await e.query(`
|
|
1660
|
+
WITH RECURSIVE view_dependencies AS (
|
|
1661
|
+
-- Base case: Get the initial view's dependencies
|
|
1662
|
+
SELECT DISTINCT
|
|
1663
|
+
cl.relname AS dependent_name,
|
|
1664
|
+
n.nspname AS schema_name,
|
|
1665
|
+
cl.relkind = 'v' AS is_view
|
|
1666
|
+
FROM pg_rewrite r
|
|
1667
|
+
JOIN pg_depend d ON r.oid = d.objid
|
|
1668
|
+
JOIN pg_class cl ON d.refobjid = cl.oid
|
|
1669
|
+
JOIN pg_namespace n ON cl.relnamespace = n.oid
|
|
1670
|
+
WHERE
|
|
1671
|
+
r.ev_class = (
|
|
1672
|
+
SELECT oid FROM pg_class WHERE relname = $1 AND relkind = 'v'
|
|
1673
|
+
)
|
|
1674
|
+
AND d.deptype = 'n'
|
|
1675
|
+
|
|
1676
|
+
UNION ALL
|
|
1677
|
+
|
|
1678
|
+
-- Recursive case: Traverse dependencies for views
|
|
1679
|
+
SELECT DISTINCT
|
|
1680
|
+
cl.relname AS dependent_name,
|
|
1681
|
+
n.nspname AS schema_name,
|
|
1682
|
+
cl.relkind = 'v' AS is_view
|
|
1683
|
+
FROM view_dependencies vd
|
|
1684
|
+
JOIN pg_rewrite r ON vd.dependent_name = (
|
|
1685
|
+
SELECT relname FROM pg_class WHERE oid = r.ev_class AND relkind = 'v'
|
|
1686
|
+
)
|
|
1687
|
+
JOIN pg_depend d ON r.oid = d.objid
|
|
1688
|
+
JOIN pg_class cl ON d.refobjid = cl.oid
|
|
1689
|
+
JOIN pg_namespace n ON cl.relnamespace = n.oid
|
|
1690
|
+
WHERE d.deptype = 'n'
|
|
1691
|
+
)
|
|
1692
|
+
SELECT DISTINCT
|
|
1693
|
+
dependent_name AS table_name,
|
|
1694
|
+
schema_name
|
|
1695
|
+
FROM view_dependencies
|
|
1696
|
+
WHERE NOT is_view; -- Exclude intermediate views
|
|
1697
|
+
`, [t])).rows.map((n) => ({ table_name: n.table_name, schema_name: n.schema_name }));
|
|
1698
|
+
}
|
|
1699
|
+
async function jt(e, t, n) {
|
|
1700
|
+
let i = t.filter((s) => !n.has(`${s.schema_name}_${s.table_name}`)).map((s) => `
|
|
1701
|
+
CREATE OR REPLACE FUNCTION "_notify_${s.schema_name}_${s.table_name}"() RETURNS TRIGGER AS $$
|
|
1702
|
+
BEGIN
|
|
1703
|
+
PERFORM pg_notify('table_change__${s.schema_name}__${s.table_name}', '');
|
|
1704
|
+
RETURN NULL;
|
|
1705
|
+
END;
|
|
1706
|
+
$$ LANGUAGE plpgsql;
|
|
1707
|
+
CREATE OR REPLACE TRIGGER "_notify_trigger_${s.schema_name}_${s.table_name}"
|
|
1708
|
+
AFTER INSERT OR UPDATE OR DELETE ON "${s.schema_name}"."${s.table_name}"
|
|
1709
|
+
FOR EACH STATEMENT EXECUTE FUNCTION "_notify_${s.schema_name}_${s.table_name}"();
|
|
1710
|
+
`).join(`
|
|
1711
|
+
`);
|
|
1712
|
+
i.trim() !== "" && await e.exec(i), t.map((s) => n.add(`${s.schema_name}_${s.table_name}`));
|
|
1713
|
+
}
|
|
1714
|
+
var Ne = (e, t) => {
|
|
1715
|
+
for (let n of e) n(t);
|
|
1716
|
+
}, Ks = (e, t) => {
|
|
1717
|
+
for (let n of e) n(t);
|
|
1718
|
+
};
|
|
1719
|
+
class Qs {
|
|
74
1720
|
#e;
|
|
75
|
-
async init(
|
|
76
|
-
return this.#e = new
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1721
|
+
async init(t, n) {
|
|
1722
|
+
return this.#e = new nr({
|
|
1723
|
+
...n,
|
|
1724
|
+
dataDir: n.store === "memory" ? void 0 : `idb://${t}`,
|
|
1725
|
+
database: t,
|
|
1726
|
+
extensions: {
|
|
1727
|
+
live: zs
|
|
1728
|
+
}
|
|
1729
|
+
}), await this.#e.waitReady;
|
|
80
1730
|
}
|
|
81
|
-
sql(
|
|
82
|
-
return this.#e.sql(
|
|
1731
|
+
sql(t, ...n) {
|
|
1732
|
+
return this.#e.sql(t, ...n);
|
|
83
1733
|
}
|
|
84
|
-
exec(
|
|
85
|
-
return this.#e.exec(
|
|
1734
|
+
exec(t, n) {
|
|
1735
|
+
return this.#e.exec(t, n);
|
|
86
1736
|
}
|
|
87
|
-
query(
|
|
88
|
-
return this.#e.query(
|
|
1737
|
+
query(t, n, i) {
|
|
1738
|
+
return this.#e.query(t, n, i);
|
|
89
1739
|
}
|
|
90
|
-
describeQuery(
|
|
91
|
-
return this.#e.describeQuery(
|
|
1740
|
+
describeQuery(t, n) {
|
|
1741
|
+
return this.#e.describeQuery(t, n);
|
|
92
1742
|
}
|
|
93
|
-
transaction(
|
|
94
|
-
return this.#e.transaction(
|
|
1743
|
+
transaction(t) {
|
|
1744
|
+
return this.#e.transaction(t);
|
|
95
1745
|
}
|
|
96
|
-
runExclusive(
|
|
97
|
-
return this.#e.runExclusive(
|
|
1746
|
+
runExclusive(t) {
|
|
1747
|
+
return this.#e.runExclusive(t);
|
|
98
1748
|
}
|
|
99
|
-
disconnect() {
|
|
100
|
-
|
|
1749
|
+
async disconnect() {
|
|
1750
|
+
await this.#e.close();
|
|
101
1751
|
}
|
|
102
1752
|
async version() {
|
|
103
1753
|
return (await this.#e.query("SELECT version()")).rows[0].version;
|
|
104
1754
|
}
|
|
105
1755
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
1756
|
+
const Xs = (e, t) => {
|
|
1757
|
+
const n = ue(e), i = [t.id];
|
|
1758
|
+
return {
|
|
1759
|
+
sql: `DELETE FROM ${n} WHERE id = $1;`,
|
|
1760
|
+
params: i
|
|
1761
|
+
};
|
|
1762
|
+
}, Zs = (e, t, n) => {
|
|
1763
|
+
const i = ue(e), s = zt(e, t);
|
|
1764
|
+
n?.userId && (e.propertyMap.has("createdBy") && (s.createdBy = n.userId), e.propertyMap.has("updatedBy") && (s.updatedBy = n.userId));
|
|
1765
|
+
const u = {};
|
|
1766
|
+
Object.keys(s).forEach((D) => {
|
|
1767
|
+
const B = s[D];
|
|
1768
|
+
B != null && (u[D] = B);
|
|
1769
|
+
});
|
|
1770
|
+
const h = Object.keys(u), m = ot(e, u), g = [], E = h.map((D, B) => (g.push(m[D]), `$${B + 1}`)), T = h.map((D) => `"${D}"`).join(",");
|
|
1771
|
+
let L = `INSERT INTO ${i} (${T}) VALUES (${E.join(",")})`;
|
|
1772
|
+
return n?.returning !== !1 ? L += " RETURNING *;" : L += ";", { sql: L, params: g };
|
|
1773
|
+
}, ei = (e, t, n, i) => {
|
|
1774
|
+
const s = ir(e, n);
|
|
1775
|
+
e.propertyMap.has("updatedAt") && (s.updatedAt = i?.updatedAt ?? /* @__PURE__ */ new Date()), i?.userId && e.propertyMap.has("updatedBy") && (s.updatedBy = i.userId);
|
|
1776
|
+
const u = ot(e, s), m = Object.keys(s).map((D, B) => `"${D}" = $${B + 1}`).join(","), g = [...Object.values(u)], E = ue(e), T = Array.isArray(t) ? t : [t];
|
|
1777
|
+
let L = `UPDATE ${E} SET ${m} WHERE id `;
|
|
1778
|
+
if (Array.isArray(t)) {
|
|
1779
|
+
const D = g.length + 1;
|
|
1780
|
+
L += `= ANY($${D})`, g.push(T.map((B) => B.id));
|
|
1781
|
+
} else {
|
|
1782
|
+
const D = g.length + 1;
|
|
1783
|
+
L += `= $${D}`, g.push(t.id);
|
|
1784
|
+
}
|
|
1785
|
+
return i?.returning !== !1 ? L += " RETURNING *;" : L += ";", {
|
|
1786
|
+
sql: L,
|
|
1787
|
+
params: g
|
|
1788
|
+
};
|
|
1789
|
+
}, ft = "_", Gn = (e) => e.replaceAll(".", "_"), De = (e, t) => {
|
|
1790
|
+
if (e.relationAliasMap.has(t)) return e.relationAliasMap.get(t);
|
|
1791
|
+
const n = t.includes("_") ? t : t.split("_")[0], i = Vn(e, Gn(n));
|
|
1792
|
+
return e.relationAliasMap.set(t, i), i;
|
|
1793
|
+
}, ti = (e, t, n, i) => {
|
|
1794
|
+
const s = n.slice(0, i);
|
|
1795
|
+
let u = t;
|
|
1796
|
+
const h = [];
|
|
1797
|
+
for (const m of s) {
|
|
1798
|
+
if (!u?.relationMap.has(m)) return { relPairs: [] };
|
|
1799
|
+
const g = u.relationMap.get(m);
|
|
1800
|
+
h.push({ metadata: u, relation: g }), u = e.rxdb.schemaManager.getEntityMetadata(g.mappedEntity, g.mappedNamespace);
|
|
1801
|
+
}
|
|
1802
|
+
return { metaWalker: u, relPairs: h };
|
|
1803
|
+
}, ni = (e, t, n, i, s) => {
|
|
1804
|
+
for (let u = s.length - 1; u > 0; u--) {
|
|
1805
|
+
const h = s.slice(u);
|
|
1806
|
+
if (h.length === 0) continue;
|
|
1807
|
+
const { metaWalker: m, relPairs: g } = ti(e, n, s, u);
|
|
1808
|
+
if (!m || g.length === 0) continue;
|
|
1809
|
+
const E = h[0], T = h.slice(1).join("."), L = m.propertyMap.get(E);
|
|
1810
|
+
if (L && L.type === W.keyValue) {
|
|
1811
|
+
const D = s.slice(0, u).join(".");
|
|
1812
|
+
Yn(e, t, g, D);
|
|
1813
|
+
const B = g[g.length - 1].relation, I = Ue(g, D, B), U = De(t, I), _ = T ? `$.${T}` : "$";
|
|
1814
|
+
return t.fieldAliasMap.set(i, `"${U}"."${E}" ->> '${_.replace("$.", "")}'`), !0;
|
|
1815
|
+
}
|
|
109
1816
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
1817
|
+
return !1;
|
|
1818
|
+
}, Yn = (e, t, n, i) => {
|
|
1819
|
+
n.forEach(({ metadata: s, relation: u }, h) => {
|
|
1820
|
+
const m = e.rxdb.schemaManager.findMappedRelation(s, u);
|
|
1821
|
+
if (!m) throw new he("mappedRelation not found");
|
|
1822
|
+
const g = Ue(n, i, u), E = De(t, g);
|
|
1823
|
+
let T = ft;
|
|
1824
|
+
if (h > 0) {
|
|
1825
|
+
const L = n[h - 1], D = Ue(n, i, L.relation);
|
|
1826
|
+
T = De(t, D);
|
|
1827
|
+
}
|
|
1828
|
+
switch (u.kind) {
|
|
1829
|
+
case _e.ONE_TO_MANY:
|
|
1830
|
+
ri(t, m, E, T);
|
|
1831
|
+
break;
|
|
1832
|
+
case _e.ONE_TO_ONE:
|
|
1833
|
+
case _e.MANY_TO_ONE:
|
|
1834
|
+
si(t, m, E, T, u);
|
|
1835
|
+
break;
|
|
1836
|
+
case _e.MANY_TO_MANY:
|
|
1837
|
+
ii(e, t, m, E, T, u);
|
|
1838
|
+
break;
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
}, ri = (e, t, n, i) => {
|
|
1842
|
+
Me(e, t.metadata).push({
|
|
1843
|
+
joinTableName: n,
|
|
1844
|
+
on: `"${n}"."${t.relation.name}Id" = ${ht(i)}."id"`
|
|
1845
|
+
});
|
|
1846
|
+
}, si = (e, t, n, i, s) => {
|
|
1847
|
+
Me(e, t.metadata).push({
|
|
1848
|
+
joinTableName: n,
|
|
1849
|
+
on: `"${n}"."id" = ${ht(i)}."${s.name}Id"`
|
|
1850
|
+
});
|
|
1851
|
+
}, ii = (e, t, n, i, s, u) => {
|
|
1852
|
+
const h = ge(u.junctionEntityType), m = Me(t, h), g = Vn(t, Gn(`${u.name}_m_n`));
|
|
1853
|
+
m.push({
|
|
1854
|
+
joinTableName: g,
|
|
1855
|
+
on: `"${g}"."${n.relation.name}Id" = ${ht(s)}."id"`
|
|
1856
|
+
}), Me(t, n.metadata).push({
|
|
1857
|
+
joinTableName: i,
|
|
1858
|
+
on: `"${i}"."id" = "${g}"."${u.name}Id"`
|
|
1859
|
+
});
|
|
1860
|
+
}, Me = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), Vn = (e, t) => {
|
|
1861
|
+
let n = t, i = 1;
|
|
1862
|
+
for (; e.usedAliases.has(n); )
|
|
1863
|
+
n = `${t}_${i++}`;
|
|
1864
|
+
return e.usedAliases.add(n), n;
|
|
1865
|
+
}, Ue = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, ht = (e) => e === ft ? e : `"${e}"`, Hn = (e, t, n) => {
|
|
1866
|
+
const i = {
|
|
1867
|
+
joinMap: /* @__PURE__ */ new Map(),
|
|
1868
|
+
usedAliases: /* @__PURE__ */ new Set(),
|
|
1869
|
+
fieldAliasMap: /* @__PURE__ */ new Map(),
|
|
1870
|
+
relationAliasMap: /* @__PURE__ */ new Map()
|
|
1871
|
+
};
|
|
1872
|
+
Xn(n, (u, h, m) => {
|
|
1873
|
+
const g = h;
|
|
1874
|
+
u !== "field" || !g.includes(".") || ai(e, i, t, g, m);
|
|
1875
|
+
});
|
|
1876
|
+
const s = [];
|
|
1877
|
+
for (const [u, h] of i.joinMap.entries()) {
|
|
1878
|
+
const m = ue(u);
|
|
1879
|
+
for (const g of h)
|
|
1880
|
+
s.push(` LEFT JOIN ${m} "${g.joinTableName}" ON ${g.on}`);
|
|
1881
|
+
}
|
|
1882
|
+
return { joinSQL: s.join(""), fieldAliasMap: i.fieldAliasMap };
|
|
1883
|
+
}, ai = (e, t, n, i, s) => {
|
|
1884
|
+
const u = i.split(".");
|
|
1885
|
+
try {
|
|
1886
|
+
const E = e.rxdb.schemaManager.getFieldRelations(n, i);
|
|
1887
|
+
if (E.isForeignKey) {
|
|
1888
|
+
s.field = E.propertyName;
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1891
|
+
const T = i.replace(`.${E.propertyName}`, "");
|
|
1892
|
+
Yn(e, t, E.relations, T);
|
|
1893
|
+
const L = E.relations[E.relations.length - 1], D = Ue(E.relations, T, L.relation), B = De(t, D);
|
|
1894
|
+
t.fieldAliasMap.set(i, `"${B}"."${E.propertyName}"`);
|
|
1895
|
+
return;
|
|
1896
|
+
} catch {
|
|
1897
|
+
}
|
|
1898
|
+
const [h, ...m] = u, g = n.propertyMap.get(h);
|
|
1899
|
+
if (g && g.type === W.keyValue && m.length > 0) {
|
|
1900
|
+
const E = m.join(".");
|
|
1901
|
+
t.fieldAliasMap.set(i, `"${ft}"."${h}" ->> '${E}'`);
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
ni(e, t, n, i, u);
|
|
1905
|
+
}, Be = "_", oi = {
|
|
1906
|
+
"=": "=",
|
|
1907
|
+
"!=": "!=",
|
|
1908
|
+
">": ">",
|
|
1909
|
+
">=": ">=",
|
|
1910
|
+
"<": "<",
|
|
1911
|
+
"<=": "<=",
|
|
1912
|
+
in: "IN",
|
|
1913
|
+
notIn: "NOT IN",
|
|
1914
|
+
between: "BETWEEN",
|
|
1915
|
+
notBetween: "NOT BETWEEN",
|
|
1916
|
+
contains: "LIKE",
|
|
1917
|
+
notContains: "NOT LIKE",
|
|
1918
|
+
startsWith: "LIKE",
|
|
1919
|
+
notStartsWith: "NOT LIKE",
|
|
1920
|
+
endsWith: "LIKE",
|
|
1921
|
+
notEndsWith: "NOT LIKE"
|
|
1922
|
+
}, li = (e) => {
|
|
1923
|
+
if (e?.length)
|
|
1924
|
+
return e.map((t) => `${Be}."${t.field}" ${t.sort.toUpperCase()}`).join(", ");
|
|
1925
|
+
}, ui = (e) => oi[e] || e, ci = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), fi = (e, t, n) => {
|
|
1926
|
+
if (t) return t;
|
|
1927
|
+
if (!e.includes(".")) return e;
|
|
1928
|
+
const i = e.split("."), s = i[0], u = n?.propertyMap.get(s);
|
|
1929
|
+
if (u && (u.type === W.json || u.type === W.keyValue) && i.length === 2)
|
|
1930
|
+
return `"${s}" ->> '${i[1]}'`;
|
|
1931
|
+
const h = e.lastIndexOf(".");
|
|
1932
|
+
return `"${e.slice(0, h)}".${e.slice(h + 1)}`;
|
|
1933
|
+
}, hi = (e, t, n = /* @__PURE__ */ new Map(), i) => {
|
|
1934
|
+
const s = String(e.field), u = n.get(s), h = fi(s, u, i), m = e.value, g = e.operator;
|
|
1935
|
+
if (m === null)
|
|
1936
|
+
return g === "=" ? `${h} IS NULL` : g === "!=" ? `${h} IS NOT NULL` : "";
|
|
1937
|
+
let E = s;
|
|
1938
|
+
u && s.includes(".") && (E = s.split(".").pop() || s);
|
|
1939
|
+
const T = i?.propertyMap.get(E.split(".")[0]);
|
|
1940
|
+
if (T && (T.type === W.json || T.type === W.keyValue)) {
|
|
1941
|
+
if (g === "contains" && typeof m == "object" && !Array.isArray(m))
|
|
1942
|
+
return t.push(JSON.stringify(m)), `${h} @> $${t.length}::jsonb`;
|
|
1943
|
+
if (g === "notContains" && typeof m == "object" && !Array.isArray(m))
|
|
1944
|
+
return t.push(JSON.stringify(m)), `NOT (${h} @> $${t.length}::jsonb)`;
|
|
1945
|
+
}
|
|
1946
|
+
if (T && (T.type === W.stringArray || T.type === W.numberArray) && (g === "in" || g === "notIn")) {
|
|
1947
|
+
if (!Array.isArray(m)) return "";
|
|
1948
|
+
t.push(JSON.stringify(m));
|
|
1949
|
+
const D = `${h} @> $${t.length}::jsonb`;
|
|
1950
|
+
return g === "notIn" ? `NOT ${D}` : D;
|
|
1951
|
+
}
|
|
1952
|
+
if (g === "in" || g === "notIn")
|
|
1953
|
+
return Array.isArray(m) ? m.length === 0 ? g === "in" ? "1=0" : "1=1" : (t.push(m), `${h} ${g === "in" ? "= ANY" : "!= ALL"}($${t.length})`) : "";
|
|
1954
|
+
if (g === "between" || g === "notBetween")
|
|
1955
|
+
return !Array.isArray(m) || m.length !== 2 ? "" : (t.push(m[0], m[1]), `${h} ${g === "between" ? "BETWEEN" : "NOT BETWEEN"} $${t.length - 1} AND $${t.length}`);
|
|
1956
|
+
if (["contains", "notContains", "startsWith", "notStartsWith", "endsWith", "notEndsWith"].includes(g)) {
|
|
1957
|
+
let D = "";
|
|
1958
|
+
g === "contains" || g === "notContains" ? D = `%${m}%` : g === "startsWith" || g === "notStartsWith" ? D = `${m}%` : (g === "endsWith" || g === "notEndsWith") && (D = `%${m}`), t.push(D);
|
|
1959
|
+
const B = g.startsWith("not") ? "NOT LIKE" : "LIKE";
|
|
1960
|
+
return `${h} ${B} $${t.length}`;
|
|
1961
|
+
}
|
|
1962
|
+
const L = ui(g);
|
|
1963
|
+
return t.push(m), T && T.type === W.uuid ? `${h}::uuid ${L} $${t.length}::uuid` : `${h} ${L} $${t.length}`;
|
|
1964
|
+
}, Pe = (e, t, n = /* @__PURE__ */ new Map(), i) => {
|
|
1965
|
+
const s = e.rules.map(
|
|
1966
|
+
(h) => ci(h) ? Pe(h, t, n, i) : hi(h, t, n, i)
|
|
1967
|
+
).filter(Boolean);
|
|
1968
|
+
if (!s.length) return "";
|
|
1969
|
+
if (s.length === 1) return s[0];
|
|
1970
|
+
const u = e.combinator.toUpperCase();
|
|
1971
|
+
return `(${s.join(` ${u} `)})`;
|
|
1972
|
+
}, di = (e, t) => {
|
|
1973
|
+
let n = `SELECT ${Be}.* FROM ${e.tableName} AS ${Be}`;
|
|
1974
|
+
return e.join && (n += ` ${e.join}`), e.where && (n += ` WHERE ${e.where}`), e.orderBy && (n += ` ORDER BY ${e.orderBy}`), e.limit !== void 0 && (t.push(e.limit), n += ` LIMIT $${t.length}`), e.offset !== void 0 && e.offset > 0 && (t.push(e.offset), n += ` OFFSET $${t.length}`), n;
|
|
1975
|
+
}, pi = (e) => {
|
|
1976
|
+
let t = `SELECT COUNT(*) as count FROM ${e.tableName} AS ${Be}`;
|
|
1977
|
+
return e.join && (t += ` ${e.join}`), e.where && (t += ` WHERE ${e.where}`), t;
|
|
1978
|
+
}, Ft = (e, t, n) => {
|
|
1979
|
+
const i = ue(t), s = [], { joinSQL: u, fieldAliasMap: h } = n.where ? Hn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, m = n.where ? Pe(n.where, s, h, t) : void 0, g = li(n.orderBy), E = "limit" in n ? n.limit : void 0, T = "offset" in n ? n.offset : void 0;
|
|
1980
|
+
return { sql: di(
|
|
1981
|
+
{
|
|
1982
|
+
tableName: i,
|
|
1983
|
+
where: m,
|
|
1984
|
+
join: u,
|
|
1985
|
+
orderBy: g,
|
|
1986
|
+
limit: E,
|
|
1987
|
+
offset: T
|
|
1988
|
+
},
|
|
1989
|
+
s
|
|
1990
|
+
), params: s };
|
|
1991
|
+
}, yi = (e, t, n) => {
|
|
1992
|
+
if (n.groupBy)
|
|
1993
|
+
throw new he("groupBy not supported in count queries");
|
|
1994
|
+
const i = ue(t), s = [], { joinSQL: u, fieldAliasMap: h } = n.where ? Hn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, m = n.where ? Pe(n.where, s, h, t) : void 0;
|
|
1995
|
+
return { sql: pi({
|
|
1996
|
+
tableName: i,
|
|
1997
|
+
where: m,
|
|
1998
|
+
join: u
|
|
1999
|
+
}), params: s };
|
|
2000
|
+
};
|
|
2001
|
+
class gi extends Kn {
|
|
2002
|
+
constructor(t, n) {
|
|
2003
|
+
super(t.rxdb, n), this.adapter = t, this.metadata = ge(n);
|
|
2004
|
+
}
|
|
2005
|
+
metadata;
|
|
2006
|
+
addQueryCache(t, n = !1) {
|
|
2007
|
+
return t.rows.map((i) => {
|
|
2008
|
+
const s = ze(this.metadata, i), u = s.id;
|
|
2009
|
+
let h;
|
|
2010
|
+
super.hasEntityRef(u) ? (h = super.getEntityRef(u), n && super.updateEntity(h, s)) : h = this.createEntityRef(s);
|
|
2011
|
+
const m = Pt(h);
|
|
2012
|
+
return m.local = !0, m.modified = !1, h;
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
class Jn extends gi {
|
|
2017
|
+
async find(t) {
|
|
2018
|
+
const { sql: n, params: i } = Ft(this.adapter, this.metadata, t), s = await this.adapter.query(n, i);
|
|
2019
|
+
return this.addQueryCache(s);
|
|
2020
|
+
}
|
|
2021
|
+
async findAll(t) {
|
|
2022
|
+
const { sql: n, params: i } = Ft(this.adapter, this.metadata, t), s = await this.adapter.query(n, i);
|
|
2023
|
+
return this.addQueryCache(s);
|
|
2024
|
+
}
|
|
2025
|
+
async count(t) {
|
|
2026
|
+
const { sql: n, params: i } = yi(this.adapter, this.metadata, t), s = await this.adapter.query(n, i);
|
|
2027
|
+
return parseInt(s.rows[0].count);
|
|
2028
|
+
}
|
|
2029
|
+
async create(t) {
|
|
2030
|
+
const { sql: n, params: i } = Zs(this.metadata, t, this.rxdb.context), s = await this.adapter.query(n, i);
|
|
2031
|
+
return this.addQueryCache(s, !0), t;
|
|
2032
|
+
}
|
|
2033
|
+
async update(t, n) {
|
|
2034
|
+
Object.assign(t, n);
|
|
2035
|
+
const { sql: i, params: s } = ei(this.metadata, t, n, this.rxdb.context);
|
|
2036
|
+
return await this.adapter.query(i, s), t;
|
|
2037
|
+
}
|
|
2038
|
+
async remove(t) {
|
|
2039
|
+
const { sql: n, params: i } = Xs(this.metadata, t);
|
|
2040
|
+
return await this.adapter.query(n, i), t;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
const ke = (e, t, n) => {
|
|
2044
|
+
const { isCount: i, isFindDescendants: s, entityId: u, where: h } = n, m = !u, g = ue(t);
|
|
2045
|
+
let E = "";
|
|
2046
|
+
const L = [`c.level < ${n.level || 0}`], D = [];
|
|
2047
|
+
if (m || D.push(u), h) {
|
|
2048
|
+
const N = /* @__PURE__ */ new Map(), R = (b) => {
|
|
2049
|
+
if ("rules" in b)
|
|
2050
|
+
return { ...b, rules: b.rules.map(R) };
|
|
2051
|
+
if (b.field && typeof b.field == "string" && b.field.startsWith("children.")) {
|
|
2052
|
+
const M = b.field.substring(9);
|
|
2053
|
+
N.set(b.field, `children."${M}"`);
|
|
2054
|
+
}
|
|
2055
|
+
return b;
|
|
2056
|
+
};
|
|
2057
|
+
R(h);
|
|
2058
|
+
const v = Pe(h, D, N, t);
|
|
2059
|
+
v && L.push(v);
|
|
2060
|
+
}
|
|
2061
|
+
const B = L.filter(Boolean).join(" AND ");
|
|
2062
|
+
B && (E = `WHERE ${B}`);
|
|
2063
|
+
let I = "*";
|
|
2064
|
+
return i && (m ? I = "count(*) AS count" : I = "(count(*) - 1) AS count"), {
|
|
2065
|
+
sql: `WITH RECURSIVE __children AS (
|
|
2066
|
+
SELECT *, 0 AS level
|
|
2067
|
+
FROM ${g}
|
|
2068
|
+
WHERE ${m ? '"parentId" IS NULL' : "id = $1"}
|
|
2069
|
+
UNION ALL
|
|
2070
|
+
SELECT children.*, c.level + 1 AS level
|
|
2071
|
+
FROM ${g} children
|
|
2072
|
+
JOIN __children c ON ${s ? 'children."parentId"::uuid = c.id::uuid' : 'children.id::uuid = c."parentId"::uuid'}
|
|
2073
|
+
${E}
|
|
2074
|
+
)
|
|
2075
|
+
|
|
2076
|
+
SELECT ${I} FROM __children${i ? "" : " ORDER BY level, id"};`,
|
|
2077
|
+
params: D
|
|
2078
|
+
};
|
|
2079
|
+
}, mi = (e, t, n) => ke(e, t, { ...n, isFindDescendants: !0 }), _i = (e, t, n) => ke(e, t, { ...n, isFindDescendants: !0, isCount: !0 }), wi = (e, t, n) => ke(e, t, { ...n, isFindDescendants: !1 }), Ei = (e, t, n) => ke(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
|
|
2080
|
+
class bi extends Jn {
|
|
2081
|
+
async findDescendants(t) {
|
|
2082
|
+
const { sql: n, params: i } = mi(this.adapter, this.metadata, t), s = await this.adapter.query(n, i);
|
|
2083
|
+
return !s.rows || s.rows.length === 0 ? [] : s.rows.map((h) => {
|
|
2084
|
+
const m = ze(this.metadata, h);
|
|
2085
|
+
return this.createEntityRef(m);
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
async countDescendants(t) {
|
|
2089
|
+
const { sql: n, params: i } = _i(this.adapter, this.metadata, t), u = (await this.adapter.query(n, i)).rows[0], h = u.count || u["?column?"];
|
|
2090
|
+
return parseInt(String(h), 10) || 0;
|
|
2091
|
+
}
|
|
2092
|
+
async findAncestors(t) {
|
|
2093
|
+
const { sql: n, params: i } = wi(this.adapter, this.metadata, t), s = await this.adapter.query(n, i);
|
|
2094
|
+
return !s.rows || s.rows.length === 0 ? [] : s.rows.map((h) => {
|
|
2095
|
+
const m = ze(this.metadata, h);
|
|
2096
|
+
return this.createEntityRef(m);
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
async countAncestors(t) {
|
|
2100
|
+
const { sql: n, params: i } = Ei(this.adapter, this.metadata, t), u = (await this.adapter.query(n, i)).rows[0], h = u.count || u["?column?"];
|
|
2101
|
+
return parseInt(String(h), 10) || 0;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
const Ai = async (e, t, n) => {
|
|
2105
|
+
const i = e.localRxDBBranch(), s = e.localRxDBChange();
|
|
2106
|
+
let u = !1;
|
|
2107
|
+
try {
|
|
2108
|
+
await $e(i.get(t)), u = !0;
|
|
2109
|
+
} catch {
|
|
2110
|
+
}
|
|
2111
|
+
if (u)
|
|
2112
|
+
throw new he(`Branch ID (${t}) already exists`);
|
|
2113
|
+
let h;
|
|
2114
|
+
if (n ? h = await $e(
|
|
2115
|
+
i.findOne({
|
|
2116
|
+
where: {
|
|
2117
|
+
combinator: "and",
|
|
2118
|
+
rules: [{ field: "changes.id", operator: "=", value: n }]
|
|
2119
|
+
}
|
|
2120
|
+
})
|
|
2121
|
+
) : h = await $e(
|
|
2122
|
+
i.findOne({
|
|
2123
|
+
where: {
|
|
2124
|
+
combinator: "and",
|
|
2125
|
+
rules: [{ field: "activated", operator: "=", value: !0 }]
|
|
2126
|
+
}
|
|
2127
|
+
})
|
|
2128
|
+
), !h)
|
|
2129
|
+
throw new he("Source branch not found");
|
|
2130
|
+
n || (n = (await $e(
|
|
2131
|
+
s.findOne({
|
|
2132
|
+
where: {
|
|
2133
|
+
combinator: "and",
|
|
2134
|
+
rules: [
|
|
2135
|
+
{ field: "branchId", operator: "=", value: h.id },
|
|
2136
|
+
{ field: "revertChangedAt", operator: "=", value: null }
|
|
2137
|
+
]
|
|
2138
|
+
},
|
|
2139
|
+
orderBy: [{ field: "id", sort: "desc" }]
|
|
2140
|
+
})
|
|
2141
|
+
))?.id);
|
|
2142
|
+
const m = new kt();
|
|
2143
|
+
m.id = t, m.activated = !1, await m.save();
|
|
2144
|
+
};
|
|
2145
|
+
function zn(e, t = {}) {
|
|
2146
|
+
const n = ue(e), i = ge(Wt), s = ue(i), { propertyMap: u, name: h, foreignKeyNames: m, namespace: g } = e, { branchId: E, transactionId: T, parentId: L } = t, D = `"${h}_change_trigger"`, B = [...u.keys(), ...m].filter((p) => p !== "id"), I = 'type, namespace, entity, "branchId", "transactionId", "parentId", "entityId", "inversePatch", patch', U = L != null && L >= 0 ? `${L}` : "NULL", _ = T ? `'${T}'` : "NULL", N = E || "main", R = `"${g}"."${h}_change_trigger_fn"`, v = `'${g}','${h}','${N}',${_},${U}`, b = `
|
|
2147
|
+
-- 创建或替换触发器函数
|
|
2148
|
+
CREATE OR REPLACE FUNCTION ${R}()
|
|
2149
|
+
RETURNS TRIGGER AS $$
|
|
2150
|
+
DECLARE
|
|
2151
|
+
old_values JSONB;
|
|
2152
|
+
new_values JSONB;
|
|
2153
|
+
BEGIN
|
|
2154
|
+
-- INSERT 操作
|
|
2155
|
+
IF (TG_OP = 'INSERT') THEN
|
|
2156
|
+
INSERT INTO ${s} (${I})
|
|
2157
|
+
VALUES (
|
|
2158
|
+
'INSERT',
|
|
2159
|
+
${v},
|
|
2160
|
+
NEW.id,
|
|
2161
|
+
NULL,
|
|
2162
|
+
jsonb_build_object(${B.map((p) => `'${p}', NEW."${p}"`).join(", ")})
|
|
2163
|
+
);
|
|
2164
|
+
RETURN NEW;
|
|
2165
|
+
|
|
2166
|
+
-- UPDATE 操作
|
|
2167
|
+
ELSIF (TG_OP = 'UPDATE') THEN
|
|
2168
|
+
-- 只在字段真正变更时记录
|
|
2169
|
+
IF (${B.map((p) => `OLD."${p}" IS DISTINCT FROM NEW."${p}"`).join(" OR ")}) THEN
|
|
2170
|
+
-- 构建变更前的值 (inversePatch - 只包含变更的字段)
|
|
2171
|
+
old_values := jsonb_build_object(${B.map((p) => `'${p}', CASE WHEN OLD."${p}" IS DISTINCT FROM NEW."${p}" THEN to_jsonb(OLD."${p}") ELSE NULL END`).join(", ")});
|
|
2172
|
+
old_values := jsonb_strip_nulls(old_values);
|
|
2173
|
+
|
|
2174
|
+
-- 构建变更后的值 (patch - 只包含变更的字段)
|
|
2175
|
+
new_values := jsonb_build_object(${B.map((p) => `'${p}', CASE WHEN OLD."${p}" IS DISTINCT FROM NEW."${p}" THEN to_jsonb(NEW."${p}") ELSE NULL END`).join(", ")});
|
|
2176
|
+
new_values := jsonb_strip_nulls(new_values);
|
|
2177
|
+
|
|
2178
|
+
INSERT INTO ${s} (${I})
|
|
2179
|
+
VALUES (
|
|
2180
|
+
'UPDATE',
|
|
2181
|
+
${v},
|
|
2182
|
+
NEW.id,
|
|
2183
|
+
old_values,
|
|
2184
|
+
new_values
|
|
2185
|
+
);
|
|
2186
|
+
END IF;
|
|
2187
|
+
RETURN NEW;
|
|
2188
|
+
|
|
2189
|
+
-- DELETE 操作
|
|
2190
|
+
ELSIF (TG_OP = 'DELETE') THEN
|
|
2191
|
+
INSERT INTO ${s} (${I})
|
|
2192
|
+
VALUES (
|
|
2193
|
+
'DELETE',
|
|
2194
|
+
${v},
|
|
2195
|
+
OLD.id,
|
|
2196
|
+
jsonb_build_object(${B.map((p) => `'${p}', OLD."${p}"`).join(", ")}),
|
|
2197
|
+
NULL
|
|
2198
|
+
);
|
|
2199
|
+
RETURN OLD;
|
|
2200
|
+
END IF;
|
|
2201
|
+
|
|
2202
|
+
RETURN NULL;
|
|
2203
|
+
END;
|
|
2204
|
+
$$ LANGUAGE plpgsql;`, M = `
|
|
2205
|
+
-- 删除已存在的触发器
|
|
2206
|
+
DROP TRIGGER IF EXISTS ${D} ON ${n}`, f = `
|
|
2207
|
+
-- 创建触发器 (监听 INSERT, UPDATE, DELETE)
|
|
2208
|
+
CREATE TRIGGER ${D}
|
|
2209
|
+
AFTER INSERT OR UPDATE OR DELETE ON ${n}
|
|
2210
|
+
FOR EACH ROW
|
|
2211
|
+
EXECUTE FUNCTION ${R}()`;
|
|
2212
|
+
return [b, M, f].join(`
|
|
2213
|
+
---STATEMENT_SEPARATOR---
|
|
2214
|
+
`);
|
|
2215
|
+
}
|
|
2216
|
+
function xt(e, t, n) {
|
|
2217
|
+
const i = [];
|
|
2218
|
+
return e.rxdb.options.entities.forEach((s) => {
|
|
2219
|
+
const u = ge(s);
|
|
2220
|
+
if (u.log !== !1) {
|
|
2221
|
+
const m = zn(u, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((g) => g.trim()).filter((g) => g.length > 0);
|
|
2222
|
+
i.push(...m);
|
|
2223
|
+
}
|
|
2224
|
+
}), i;
|
|
2225
|
+
}
|
|
2226
|
+
const Ti = (e, t) => {
|
|
2227
|
+
const n = ue(t);
|
|
2228
|
+
let i = `CREATE TABLE ${n} (`;
|
|
2229
|
+
const s = [], u = [], h = [];
|
|
2230
|
+
t.propertyMap.forEach((g) => {
|
|
2231
|
+
let E = "";
|
|
2232
|
+
E += `"${g.name}"`;
|
|
2233
|
+
const T = Ht(g);
|
|
2234
|
+
if (g.primary ? g.type === W.integer ? E += " serial PRIMARY KEY" : E += ` ${T} PRIMARY KEY` : E += ` ${T}`, Reflect.get(g, "default") !== void 0) {
|
|
2235
|
+
let L = g.default;
|
|
2236
|
+
Yt(g.default) && (L = g.default()), Zn(L) ? ["CURRENT_TIMESTAMP", "now()"].includes(L) ? E += " DEFAULT now()" : E += ` DEFAULT '${L}'` : L instanceof Date ? E += ` DEFAULT '${L.toISOString()}'` : typeof L == "boolean" || typeof L == "number" ? E += ` DEFAULT ${String(L)}` : E += ` DEFAULT '${String(L)}'`;
|
|
2237
|
+
}
|
|
2238
|
+
g.nullable || (E += " NOT NULL"), g.unique && s.push(
|
|
2239
|
+
`CREATE UNIQUE INDEX "${Jt(t, g)}" on ${n} ("${g.name}" ${rr(g)});`
|
|
2240
|
+
), h.push(E);
|
|
2241
|
+
});
|
|
2242
|
+
const m = [...h, ...u];
|
|
2243
|
+
if (m.length)
|
|
2244
|
+
i += m.map((g) => `
|
|
2245
|
+
${g}`).join(","), i += `
|
|
2246
|
+
);`;
|
|
2247
|
+
else
|
|
2248
|
+
throw new he("columns is empty!");
|
|
2249
|
+
return s.length && (i += `
|
|
2250
|
+
` + s.join(`
|
|
2251
|
+
`)), i;
|
|
2252
|
+
}, Ii = (e, t) => {
|
|
2253
|
+
let n = "";
|
|
2254
|
+
const i = ue(t);
|
|
2255
|
+
return Array.from(t.relationMap.values()).forEach((s) => {
|
|
2256
|
+
switch (s.kind) {
|
|
2257
|
+
case _e.ONE_TO_ONE:
|
|
2258
|
+
case _e.MANY_TO_ONE:
|
|
2259
|
+
{
|
|
2260
|
+
const u = `${s.name}Id`;
|
|
2261
|
+
let h = "uuid";
|
|
2262
|
+
if (s.mappedEntity)
|
|
2263
|
+
try {
|
|
2264
|
+
const g = e.rxdb.schemaManager.getEntityMetadata(
|
|
2265
|
+
s.mappedEntity,
|
|
2266
|
+
s.mappedNamespace
|
|
2267
|
+
);
|
|
2268
|
+
if (g) {
|
|
2269
|
+
const E = Array.from(g.propertyMap.values()).find((T) => T.primary);
|
|
2270
|
+
E && (h = Ht(E));
|
|
2271
|
+
}
|
|
2272
|
+
} catch {
|
|
2273
|
+
}
|
|
2274
|
+
if (n += `
|
|
2275
|
+
ALTER TABLE ${i} ADD COLUMN "${u}" ${h}`, s.nullable || (n += " NOT NULL"), s.kind === _e.MANY_TO_ONE && Reflect.get(s, "default") !== void 0) {
|
|
2276
|
+
const g = s;
|
|
2277
|
+
let E = g.default;
|
|
2278
|
+
Yt(g.default) && (E = g.default()), n += ` DEFAULT '${E}'`;
|
|
2279
|
+
}
|
|
2280
|
+
n += ";";
|
|
2281
|
+
const m = s.mappedEntity === t.name;
|
|
2282
|
+
if (s.mappedEntity && !m) {
|
|
2283
|
+
const g = Vt(s.mappedEntity, s.mappedNamespace || t.namespace), E = `${i}_${u}_fkey`.replace(/"/g, "");
|
|
2284
|
+
n += `
|
|
2285
|
+
ALTER TABLE ${i} ADD CONSTRAINT "${E}" FOREIGN KEY ("${u}") REFERENCES ${g}(id)`, s.kind === _e.MANY_TO_ONE && (n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
|
|
2286
|
+
}
|
|
2287
|
+
(s.unique || s.kind === _e.ONE_TO_ONE) && (n += `
|
|
2288
|
+
CREATE UNIQUE INDEX "${Jt(t, s)}" ON ${i}("${u}");`);
|
|
2289
|
+
}
|
|
2290
|
+
break;
|
|
2291
|
+
}
|
|
2292
|
+
}), n;
|
|
2293
|
+
}, vi = (e, t) => {
|
|
2294
|
+
let n = "";
|
|
2295
|
+
return n += Ti(e, t), n += Ii(e, t), n;
|
|
2296
|
+
};
|
|
2297
|
+
class Di extends Qn {
|
|
114
2298
|
/**
|
|
115
|
-
*
|
|
2299
|
+
* 构造函数
|
|
2300
|
+
*
|
|
2301
|
+
* @param rxdb - RxDB 实例
|
|
2302
|
+
* @param options - PGlite 客户端配置选项
|
|
116
2303
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
w(1)
|
|
120
|
-
);
|
|
121
|
-
name = C;
|
|
122
|
-
saveMany(e) {
|
|
123
|
-
throw new Error("Method not implemented.");
|
|
2304
|
+
constructor(t, n) {
|
|
2305
|
+
super(t), this.options = n;
|
|
124
2306
|
}
|
|
125
|
-
|
|
126
|
-
|
|
2307
|
+
/** 销毁信号主题,用于清理资源 */
|
|
2308
|
+
#e = new tr();
|
|
2309
|
+
/** 仓库实例缓存,避免重复创建 */
|
|
2310
|
+
#s = /* @__PURE__ */ new Map();
|
|
2311
|
+
/** PGlite 客户端缓存 */
|
|
2312
|
+
#i;
|
|
2313
|
+
/** 事务锁标志,防止事务嵌套 */
|
|
2314
|
+
#n = !1;
|
|
2315
|
+
/** 查询任务队列执行器,确保查询按顺序执行 */
|
|
2316
|
+
#u = new er(1);
|
|
2317
|
+
/** 客户端初始化 Promise,确保单例 */
|
|
2318
|
+
#a;
|
|
2319
|
+
/** 当前活跃的事务对象 */
|
|
2320
|
+
#r;
|
|
2321
|
+
/** 适配器名称 */
|
|
2322
|
+
name = dr;
|
|
2323
|
+
/**
|
|
2324
|
+
* 批量删除实体
|
|
2325
|
+
*
|
|
2326
|
+
* @param entities - 要删除的实体数组
|
|
2327
|
+
* @returns 已删除的实体数组
|
|
2328
|
+
*/
|
|
2329
|
+
async removeMany(t) {
|
|
2330
|
+
if (!t || t.length === 0) return Promise.resolve([]);
|
|
2331
|
+
const n = ge(t[0].constructor), i = fr(n, t);
|
|
2332
|
+
return await this.query(i), t;
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* 批量保存实体
|
|
2336
|
+
*
|
|
2337
|
+
* 将实体持久化到数据库:
|
|
2338
|
+
* 1. 按实体类型分组(避免混合不同表的数据)
|
|
2339
|
+
* 2. 为每个类型生成批量插入 SQL(使用 UPSERT)
|
|
2340
|
+
* 3. 在事务中执行(如果尚未在事务中)
|
|
2341
|
+
* 4. 更新实体状态标记
|
|
2342
|
+
*
|
|
2343
|
+
* @param entities - 要保存的实体数组
|
|
2344
|
+
* @returns 已保存的实体数组
|
|
2345
|
+
*/
|
|
2346
|
+
async saveMany(t) {
|
|
2347
|
+
if (!t || t.length === 0) return Promise.resolve([]);
|
|
2348
|
+
const n = /* @__PURE__ */ new Map();
|
|
2349
|
+
for (const s of t) {
|
|
2350
|
+
const u = s.constructor;
|
|
2351
|
+
n.has(u) || n.set(u, []), n.get(u).push(s);
|
|
2352
|
+
}
|
|
2353
|
+
const i = async () => {
|
|
2354
|
+
for (const [s, u] of n.entries()) {
|
|
2355
|
+
const h = ge(s), m = hr(h, u, this.rxdb.context);
|
|
2356
|
+
await this.query(m);
|
|
2357
|
+
for (const g of u) {
|
|
2358
|
+
const E = Pt(g);
|
|
2359
|
+
E.local = !0, E.modified = !1;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
return await (this.#n ? i() : this.transaction(i)), t;
|
|
127
2364
|
}
|
|
128
|
-
|
|
129
|
-
|
|
2365
|
+
/**
|
|
2366
|
+
* 连接到数据库
|
|
2367
|
+
*
|
|
2368
|
+
* @returns 适配器实例
|
|
2369
|
+
*/
|
|
2370
|
+
async connect() {
|
|
2371
|
+
return await this.#t(), this;
|
|
130
2372
|
}
|
|
131
|
-
|
|
132
|
-
|
|
2373
|
+
/**
|
|
2374
|
+
* 断开数据库连接
|
|
2375
|
+
*
|
|
2376
|
+
* 清理资源并发送销毁信号
|
|
2377
|
+
*/
|
|
2378
|
+
async disconnect() {
|
|
2379
|
+
this.#i && (await this.#i.disconnect(), this.#e.next(), this.#e.complete());
|
|
133
2380
|
}
|
|
134
|
-
|
|
135
|
-
|
|
2381
|
+
/**
|
|
2382
|
+
* 创建分支
|
|
2383
|
+
*
|
|
2384
|
+
* 分支用于管理数据的不同版本,类似 Git 分支:
|
|
2385
|
+
* 1. 验证分支 ID 不存在
|
|
2386
|
+
* 2. 确定源分支(从当前活跃分支或指定变更点)
|
|
2387
|
+
* 3. 创建新分支记录
|
|
2388
|
+
*
|
|
2389
|
+
* @param branchId - 新分支 ID
|
|
2390
|
+
* @param fromChangeId - 从指定变更 ID 创建分支(可选,默认从当前分支的最新状态)
|
|
2391
|
+
* @throws {RxdbAdapterPGliteError} 分支 ID 已存在或源分支未找到
|
|
2392
|
+
*/
|
|
2393
|
+
async createBranch(t, n) {
|
|
2394
|
+
return Ai(this, t, n);
|
|
136
2395
|
}
|
|
137
|
-
|
|
138
|
-
|
|
2396
|
+
/**
|
|
2397
|
+
* 切换分支
|
|
2398
|
+
*
|
|
2399
|
+
* 切换到不同的分支,使后续的变更记录到目标分支:
|
|
2400
|
+
* 1. 验证当前分支和目标分支
|
|
2401
|
+
* 2. 重建所有实体表的触发器(更新为新的分支 ID)
|
|
2402
|
+
* 3. 更新分支激活状态
|
|
2403
|
+
*
|
|
2404
|
+
* @param branchId - 目标分支 ID
|
|
2405
|
+
* @throws {RxdbAdapterPGliteError} 分支未找到
|
|
2406
|
+
*/
|
|
2407
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2408
|
+
async switchBranch(t) {
|
|
2409
|
+
throw new he("switchBranch is not yet implemented. ");
|
|
139
2410
|
}
|
|
140
2411
|
/**
|
|
141
|
-
*
|
|
2412
|
+
* 恢复实体到指定状态
|
|
2413
|
+
*
|
|
2414
|
+
* 从变更历史中恢复实体到指定的版本
|
|
2415
|
+
*
|
|
2416
|
+
* @param _entity - 要恢复的实体
|
|
2417
|
+
* @param _options - 恢复选项
|
|
2418
|
+
* @returns 恢复后的实体
|
|
2419
|
+
* @throws {RxdbAdapterPGliteError} 此功能尚未实现
|
|
142
2420
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
2421
|
+
restoreEntity(t, n) {
|
|
2422
|
+
throw new he("restoreEntity is not yet implemented. ");
|
|
145
2423
|
}
|
|
146
|
-
|
|
147
|
-
|
|
2424
|
+
/**
|
|
2425
|
+
* 获取 PostgreSQL 版本
|
|
2426
|
+
*
|
|
2427
|
+
* @returns PostgreSQL 版本字符串
|
|
2428
|
+
*/
|
|
2429
|
+
async version() {
|
|
2430
|
+
return await (await this.#t()).version();
|
|
148
2431
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
2432
|
+
/**
|
|
2433
|
+
* 获取实体类型的仓库实例
|
|
2434
|
+
*
|
|
2435
|
+
* 根据实体元数据中的仓库类型创建相应的仓库实例:
|
|
2436
|
+
* - Repository: 通用仓库
|
|
2437
|
+
* - TreeRepository: 树形仓库(用于层级数据)
|
|
2438
|
+
*
|
|
2439
|
+
* 仓库实例会被缓存,避免重复创建
|
|
2440
|
+
*
|
|
2441
|
+
* @param entity - 实体类型
|
|
2442
|
+
* @returns 仓库实例
|
|
2443
|
+
* @throws {RxdbAdapterPGliteError} 不支持的仓库类型
|
|
2444
|
+
*/
|
|
2445
|
+
getRepository(t) {
|
|
2446
|
+
if (!this.#s.has(t)) {
|
|
2447
|
+
const n = ge(t);
|
|
2448
|
+
let i;
|
|
2449
|
+
switch (n.repository) {
|
|
2450
|
+
case "Repository":
|
|
2451
|
+
i = new Jn(this, t);
|
|
2452
|
+
break;
|
|
2453
|
+
case "TreeRepository":
|
|
2454
|
+
i = new bi(this, t);
|
|
2455
|
+
break;
|
|
2456
|
+
default:
|
|
2457
|
+
throw new he("Unsupported repository type: " + n.repository);
|
|
2458
|
+
}
|
|
2459
|
+
return this.#s.set(t, i), i;
|
|
155
2460
|
}
|
|
156
|
-
return
|
|
2461
|
+
return this.#s.get(t);
|
|
157
2462
|
}
|
|
158
|
-
|
|
159
|
-
|
|
2463
|
+
/**
|
|
2464
|
+
* 创建数据库表
|
|
2465
|
+
*
|
|
2466
|
+
* 分三阶段创建表结构:
|
|
2467
|
+
* 1. 创建表和列(不含外键约束)
|
|
2468
|
+
* 2. 添加外键约束
|
|
2469
|
+
* 3. 创建触发器(用于变更追踪)
|
|
2470
|
+
*
|
|
2471
|
+
* 这样可以避免因表创建顺序导致的外键约束失败
|
|
2472
|
+
*
|
|
2473
|
+
* @param EntityTypes - 实体类型数组
|
|
2474
|
+
* @param entities - 初始化数据(可选)
|
|
2475
|
+
* @returns 是否成功创建
|
|
2476
|
+
*/
|
|
2477
|
+
async createTables(t, n) {
|
|
2478
|
+
const i = [], s = [];
|
|
2479
|
+
for (let u = 0; u < t.length; u++) {
|
|
2480
|
+
const h = t[u], m = ge(h), E = vi(this, m).split(/;\s*\n/).map((T) => T.trim()).filter((T) => T.length > 0 && !T.startsWith("--"));
|
|
2481
|
+
for (const T of E)
|
|
2482
|
+
T && (T.includes("ADD CONSTRAINT") && T.includes("FOREIGN KEY") ? i.push(T) : s.push(T));
|
|
2483
|
+
}
|
|
2484
|
+
if (s.length > 0) {
|
|
2485
|
+
const u = s.join(`;
|
|
2486
|
+
`) + ";";
|
|
2487
|
+
await this.#o(u);
|
|
2488
|
+
}
|
|
2489
|
+
if (i.length > 0) {
|
|
2490
|
+
const u = i.join(`;
|
|
2491
|
+
`) + ";";
|
|
2492
|
+
try {
|
|
2493
|
+
await this.#o(u);
|
|
2494
|
+
} catch (h) {
|
|
2495
|
+
console.warn("Failed to add foreign key constraints:", h);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
for (let u = 0; u < t.length; u++) {
|
|
2499
|
+
const h = t[u], m = ge(h);
|
|
2500
|
+
if (m.log !== !1) {
|
|
2501
|
+
const g = zn(m);
|
|
2502
|
+
await this.#o(g.replace(/---STATEMENT_SEPARATOR---/g, ";"));
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
if (n && n.length > 0) {
|
|
2506
|
+
const u = /* @__PURE__ */ new Map();
|
|
2507
|
+
for (const h of n) {
|
|
2508
|
+
const m = h.constructor;
|
|
2509
|
+
u.has(m) || u.set(m, []), u.get(m).push(h);
|
|
2510
|
+
}
|
|
2511
|
+
for (const [, h] of u)
|
|
2512
|
+
await this.saveMany(h);
|
|
2513
|
+
}
|
|
2514
|
+
return !0;
|
|
160
2515
|
}
|
|
161
2516
|
/**
|
|
162
2517
|
* 判断表是否存在
|
|
163
|
-
*
|
|
2518
|
+
*
|
|
2519
|
+
* @param EntityType - 实体类型
|
|
2520
|
+
* @returns 表是否存在
|
|
164
2521
|
*/
|
|
165
|
-
isTableExisted
|
|
166
|
-
const
|
|
167
|
-
return this.#
|
|
2522
|
+
async isTableExisted(t) {
|
|
2523
|
+
const n = ge(t);
|
|
2524
|
+
return (await this.#l(
|
|
168
2525
|
`SELECT EXISTS (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
2526
|
+
SELECT 1 FROM information_schema.tables
|
|
2527
|
+
WHERE
|
|
2528
|
+
table_schema = '${n.namespace}' AND
|
|
2529
|
+
table_name = '${n.name}');`
|
|
2530
|
+
)).rows[0]?.exists;
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* 获取表的列信息
|
|
2534
|
+
*
|
|
2535
|
+
* @param EntityType - 实体类型
|
|
2536
|
+
* @returns 列信息数组
|
|
2537
|
+
*/
|
|
2538
|
+
async getTableColumns(t) {
|
|
2539
|
+
const n = ge(t);
|
|
2540
|
+
return (await this.#l(
|
|
2541
|
+
`SELECT * FROM information_schema.columns
|
|
2542
|
+
WHERE table_schema = '${n.namespace}'
|
|
2543
|
+
AND table_name = '${n.name}'
|
|
2544
|
+
ORDER BY ordinal_position;`
|
|
2545
|
+
)).rows;
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* 获取本地分支仓库
|
|
2549
|
+
*
|
|
2550
|
+
* @returns 分支仓库实例
|
|
2551
|
+
*/
|
|
2552
|
+
localRxDBBranch() {
|
|
2553
|
+
return this.getRepository(kt);
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* 获取本地变更仓库
|
|
2557
|
+
*
|
|
2558
|
+
* @returns 变更仓库实例
|
|
2559
|
+
*/
|
|
2560
|
+
localRxDBChange() {
|
|
2561
|
+
return this.getRepository(Wt);
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* 执行事务
|
|
2565
|
+
*
|
|
2566
|
+
* 事务管理策略:
|
|
2567
|
+
* - 使用手动 BEGIN/COMMIT/ROLLBACK 控制事务边界
|
|
2568
|
+
* - 使用 SET CONSTRAINTS ALL DEFERRED 延迟外键约束检查到提交时
|
|
2569
|
+
* - 动态重建触发器以注入 transactionId(与 SQLite 方案一致)
|
|
2570
|
+
* - PostgreSQL 不允许在有 pending trigger events 时修改表结构,
|
|
2571
|
+
* 因此无法使用列默认值方案,必须重建触发器
|
|
2572
|
+
*
|
|
2573
|
+
* @param transactionFun - 事务函数
|
|
2574
|
+
* @param transactionLog - 是否启用事务日志(默认 true)
|
|
2575
|
+
* @returns 事务函数的返回值
|
|
2576
|
+
* @throws {RxdbAdapterPGliteError} 事务执行失败
|
|
2577
|
+
*/
|
|
2578
|
+
async transaction(t, n = !0) {
|
|
2579
|
+
await this.rxdb.connect(this.name);
|
|
2580
|
+
const i = await this.#t(), s = n ? crypto.randomUUID() : void 0;
|
|
2581
|
+
return await i.transaction(async (h) => {
|
|
2582
|
+
if (this.#n = !0, this.#r = h, await h.query("SET CONSTRAINTS ALL DEFERRED"), n && s) {
|
|
2583
|
+
const g = xt(this, "main", s);
|
|
2584
|
+
for (const E of g)
|
|
2585
|
+
await h.query(E);
|
|
2586
|
+
}
|
|
2587
|
+
const m = await t();
|
|
2588
|
+
if (n && s) {
|
|
2589
|
+
const g = xt(this, "main");
|
|
2590
|
+
for (const E of g)
|
|
2591
|
+
await h.query(E);
|
|
2592
|
+
}
|
|
2593
|
+
return this.#r = void 0, this.#n = !1, m;
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* 执行 SQL 查询
|
|
2598
|
+
*
|
|
2599
|
+
* 查询执行策略:
|
|
2600
|
+
* - 在事务中:直接在事务上下文中执行
|
|
2601
|
+
* - 非事务中:加入队列按顺序执行,避免并发冲突
|
|
2602
|
+
*
|
|
2603
|
+
* @param sql - SQL 语句
|
|
2604
|
+
* @param bindings - 参数绑定
|
|
2605
|
+
* @returns 查询结果
|
|
2606
|
+
*/
|
|
2607
|
+
query(t, n) {
|
|
2608
|
+
return this.#n && this.#r ? this.#r.query(t, n) : this.#u.addTask(
|
|
2609
|
+
async () => (await this.rxdb.connect(this.name), (await this.#t()).query(t, n)),
|
|
2610
|
+
cr([t, n])
|
|
2611
|
+
);
|
|
174
2612
|
}
|
|
175
|
-
|
|
176
|
-
|
|
2613
|
+
/**
|
|
2614
|
+
* 内部查询方法
|
|
2615
|
+
*
|
|
2616
|
+
* 直接在客户端上执行查询,不经过队列
|
|
2617
|
+
*
|
|
2618
|
+
* @param query - SQL 查询
|
|
2619
|
+
* @param params - 查询参数
|
|
2620
|
+
* @param options - 查询选项
|
|
2621
|
+
* @returns 查询结果
|
|
2622
|
+
*/
|
|
2623
|
+
async #l(t, n, i) {
|
|
2624
|
+
return (await this.#t()).query(t, n, i);
|
|
177
2625
|
}
|
|
178
|
-
|
|
179
|
-
|
|
2626
|
+
/**
|
|
2627
|
+
* 内部执行方法
|
|
2628
|
+
*
|
|
2629
|
+
* 执行 SQL 语句(可能包含多个语句)
|
|
2630
|
+
*
|
|
2631
|
+
* @param query - SQL 语句
|
|
2632
|
+
* @param options - 执行选项
|
|
2633
|
+
* @returns 执行结果数组
|
|
2634
|
+
*/
|
|
2635
|
+
async #o(t, n) {
|
|
2636
|
+
return (await this.#t()).exec(t, n);
|
|
180
2637
|
}
|
|
181
|
-
|
|
182
|
-
|
|
2638
|
+
/**
|
|
2639
|
+
* 获取 PGlite 客户端实例
|
|
2640
|
+
*
|
|
2641
|
+
* 使用单例模式,确保只创建一个客户端实例
|
|
2642
|
+
*
|
|
2643
|
+
* @returns PGlite 客户端 Promise
|
|
2644
|
+
*/
|
|
2645
|
+
#t() {
|
|
2646
|
+
if (!this.#a) {
|
|
2647
|
+
const t = new Qs();
|
|
2648
|
+
this.#a = t.init(this.rxdb.options.dbName, this.options).then(() => (this.#i = t, t));
|
|
2649
|
+
}
|
|
2650
|
+
return this.#a;
|
|
183
2651
|
}
|
|
184
2652
|
}
|
|
185
2653
|
export {
|
|
186
|
-
|
|
187
|
-
|
|
2654
|
+
Di as RxDBAdapterPGlite,
|
|
2655
|
+
he as RxdbAdapterPGliteError,
|
|
2656
|
+
zn as generate_trigger_sql
|
|
188
2657
|
};
|