@aiao/rxdb-adapter-sqlite 0.0.14 → 0.0.15
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/index.js +1971 -1187
- package/dist/rxdb_adapter_mutations.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import { getEntityMetadata as
|
|
2
|
-
import { isString as
|
|
3
|
-
import { wrap as
|
|
4
|
-
import { defer as
|
|
5
|
-
import { Factory as
|
|
6
|
-
const
|
|
1
|
+
import { getEntityMetadata as V, PropertyType as D, RelationKind as z, isRuleGroup as Ye, getEntityStatus as ae, RepositoryBase as Nt, RxDBChange as pe, EntityLocalCreatedEvent as Ee, EntityLocalRemovedEvent as qe, EntityLocalUpdatedEvent as Te, parseRxDBChangeKey as Re, RxDBBranch as _e, getEntityType as Ce, TransactionBeginEvent as At, TransactionRollbackEvent as It, TransactionCommitEvent as Tt, RxDBAdapterLocalBase as $t, getEntityMutations as Qe, uuid as St } from "@aiao/rxdb";
|
|
2
|
+
import { isString as vt, isNil as Rt, traverseObjectKeys as Ct, EventDispatcher as Lt, AsyncQueueExecutor as st, get as Mt, isFunction as Je } from "@aiao/utils";
|
|
3
|
+
import { wrap as Ge, proxy as Ot } from "comlink";
|
|
4
|
+
import { defer as Le, of as Me, from as Oe, map as xt } from "rxjs";
|
|
5
|
+
import { Factory as jt, SQLITE_ROW as Bt, SQLITE_UTF8 as ot, SQLITE_DETERMINISTIC as it } from "wa-sqlite";
|
|
6
|
+
const Dt = (t) => ({
|
|
7
7
|
sql: "SELECT * FROM sqlite_master WHERE type='table' AND name=? LIMIT 1;",
|
|
8
|
-
params: [
|
|
9
|
-
}),
|
|
10
|
-
switch (
|
|
11
|
-
case
|
|
12
|
-
case
|
|
13
|
-
case
|
|
14
|
-
case
|
|
15
|
-
case
|
|
16
|
-
case
|
|
17
|
-
case
|
|
8
|
+
params: [t]
|
|
9
|
+
}), qt = (t) => !!t.sql && (t.results.length === 0 || t.results[0].rows.length === 0), ie = "__rowid", kt = (t) => {
|
|
10
|
+
switch (t.type) {
|
|
11
|
+
case D.uuid:
|
|
12
|
+
case D.string:
|
|
13
|
+
case D.enum:
|
|
14
|
+
case D.json:
|
|
15
|
+
case D.keyValue:
|
|
16
|
+
case D.stringArray:
|
|
17
|
+
case D.numberArray:
|
|
18
18
|
return "TEXT";
|
|
19
|
-
case
|
|
19
|
+
case D.number:
|
|
20
20
|
return "REAL";
|
|
21
|
-
case
|
|
22
|
-
case
|
|
21
|
+
case D.integer:
|
|
22
|
+
case D.boolean:
|
|
23
23
|
return "INTEGER";
|
|
24
24
|
default:
|
|
25
25
|
return "TEXT";
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
27
|
+
}, we = (t, n) => {
|
|
28
|
+
if (t === null && n.nullable) return null;
|
|
29
|
+
if (t !== void 0)
|
|
30
30
|
switch (n.type) {
|
|
31
|
-
case
|
|
32
|
-
return
|
|
33
|
-
case
|
|
34
|
-
return
|
|
35
|
-
case
|
|
36
|
-
if (!
|
|
37
|
-
if (n.properties && typeof
|
|
38
|
-
const
|
|
31
|
+
case D.boolean:
|
|
32
|
+
return t ? 1 : 0;
|
|
33
|
+
case D.date:
|
|
34
|
+
return t instanceof Date ? t.toISOString() : t;
|
|
35
|
+
case D.keyValue: {
|
|
36
|
+
if (!t) return null;
|
|
37
|
+
if (n.properties && typeof t == "object" && !Array.isArray(t)) {
|
|
38
|
+
const e = { ...t };
|
|
39
39
|
return n.properties.forEach((s) => {
|
|
40
|
-
s.name in
|
|
41
|
-
}), JSON.stringify(
|
|
40
|
+
s.name in e && (e[s.name] = we(e[s.name], s));
|
|
41
|
+
}), JSON.stringify(e);
|
|
42
42
|
}
|
|
43
|
-
return JSON.stringify(
|
|
43
|
+
return JSON.stringify(t);
|
|
44
44
|
}
|
|
45
|
-
case
|
|
46
|
-
case
|
|
47
|
-
case
|
|
48
|
-
return JSON.stringify(
|
|
45
|
+
case D.stringArray:
|
|
46
|
+
case D.numberArray:
|
|
47
|
+
case D.json:
|
|
48
|
+
return JSON.stringify(t);
|
|
49
49
|
default:
|
|
50
|
-
return
|
|
50
|
+
return t;
|
|
51
51
|
}
|
|
52
|
-
},
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
52
|
+
}, ue = (t, n) => {
|
|
53
|
+
if (t === null && n.nullable) return null;
|
|
54
|
+
if (t !== void 0)
|
|
55
55
|
switch (n.type) {
|
|
56
|
-
case
|
|
57
|
-
return !!
|
|
58
|
-
case
|
|
59
|
-
return
|
|
60
|
-
case
|
|
61
|
-
if (!
|
|
62
|
-
const
|
|
63
|
-
return n.properties &&
|
|
64
|
-
s.name in
|
|
65
|
-
}),
|
|
56
|
+
case D.boolean:
|
|
57
|
+
return !!t;
|
|
58
|
+
case D.date:
|
|
59
|
+
return t instanceof Date ? t : typeof t == "string" ? new Date(t) : t;
|
|
60
|
+
case D.keyValue: {
|
|
61
|
+
if (!t) return null;
|
|
62
|
+
const e = typeof t == "object" ? t : JSON.parse(t);
|
|
63
|
+
return n.properties && e && typeof e == "object" && n.properties.forEach((s) => {
|
|
64
|
+
s.name in e && (e[s.name] = ue(e[s.name], s));
|
|
65
|
+
}), e;
|
|
66
66
|
}
|
|
67
|
-
case
|
|
68
|
-
case
|
|
69
|
-
return Array.isArray(
|
|
70
|
-
case
|
|
71
|
-
return
|
|
67
|
+
case D.stringArray:
|
|
68
|
+
case D.numberArray:
|
|
69
|
+
return Array.isArray(t) ? t : t ? JSON.parse(t) : null;
|
|
70
|
+
case D.json:
|
|
71
|
+
return t !== null && typeof t == "object" ? t : t ? JSON.parse(t) : null;
|
|
72
72
|
default:
|
|
73
|
-
return
|
|
73
|
+
return t;
|
|
74
74
|
}
|
|
75
|
-
},
|
|
76
|
-
const n =
|
|
77
|
-
return n === -1 ? ["",
|
|
78
|
-
},
|
|
79
|
-
class
|
|
80
|
-
constructor(n,
|
|
81
|
-
super(n,
|
|
75
|
+
}, le = (t, n) => `${n}$${t}`, Ut = (t) => {
|
|
76
|
+
const n = t.indexOf("$");
|
|
77
|
+
return n === -1 ? ["", t] : [t.substring(0, n), t.substring(n + 1)];
|
|
78
|
+
}, X = (t) => le(t.tableName, t.namespace), Xe = (t) => X(V(t)), ze = (t, n) => `idx_${t.name}_${n.name}`;
|
|
79
|
+
class ee extends Error {
|
|
80
|
+
constructor(n, e) {
|
|
81
|
+
super(n, e), this.name = "RxDBAdapterSqliteError", Object.setPrototypeOf(this, ee.prototype);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
for (let
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
84
|
+
const ke = (t, n) => {
|
|
85
|
+
const e = {}, s = Object.keys(n), o = t.foreignKeyNames || [], a = t.foreignKeyColumnNames || o;
|
|
86
|
+
for (let d = 0; d < s.length; d++) {
|
|
87
|
+
const p = s[d], f = o.indexOf(p);
|
|
88
|
+
if (f !== -1) {
|
|
89
|
+
e[a[f]] = n[p];
|
|
90
90
|
continue;
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
92
|
+
if (a.indexOf(p) !== -1) {
|
|
93
|
+
e[p] = n[p];
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
96
|
+
if (o.length === 0 && p.endsWith("Id")) {
|
|
97
|
+
e[p] = n[p];
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
|
|
100
|
+
const A = t.propertyMap.get(p);
|
|
101
|
+
if (A) {
|
|
102
|
+
e[A.columnName] = we(n[p], A);
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
|
|
105
|
+
const I = t.columnNameToPropertyName?.get(p);
|
|
106
|
+
if (I) {
|
|
107
|
+
const M = t.propertyMap.get(I);
|
|
108
|
+
M && (e[p] = we(n[p], M));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
return
|
|
112
|
-
},
|
|
113
|
-
const
|
|
114
|
-
for (const [
|
|
115
|
-
|
|
116
|
-
const s =
|
|
117
|
-
for (let
|
|
118
|
-
const
|
|
119
|
-
|
|
111
|
+
return e;
|
|
112
|
+
}, at = (t, n) => {
|
|
113
|
+
const e = {};
|
|
114
|
+
for (const [a, d] of t.propertyMap)
|
|
115
|
+
a in n && (e[d.columnName] = n[a]);
|
|
116
|
+
const s = t.foreignKeyNames || [], o = t.foreignKeyColumnNames || s;
|
|
117
|
+
for (let a = 0; a < s.length; a++) {
|
|
118
|
+
const d = s[a];
|
|
119
|
+
d in n && (e[o[a]] = n[d]);
|
|
120
120
|
}
|
|
121
|
-
return
|
|
122
|
-
},
|
|
123
|
-
const
|
|
124
|
-
for (const [
|
|
125
|
-
|
|
126
|
-
const s =
|
|
127
|
-
for (let
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
|
|
121
|
+
return e;
|
|
122
|
+
}, Pt = (t, n) => {
|
|
123
|
+
const e = {};
|
|
124
|
+
for (const [a, d] of t.propertyMap)
|
|
125
|
+
a in n && d.readonly !== !0 && (e[d.columnName] = n[a]);
|
|
126
|
+
const s = t.foreignKeyNames || [], o = t.foreignKeyColumnNames || s;
|
|
127
|
+
for (let a = 0; a < s.length; a++) {
|
|
128
|
+
const d = s[a];
|
|
129
|
+
if (d in n) {
|
|
130
|
+
const p = t.foreignKeyRelationMap.get(d);
|
|
131
|
+
p && p.readonly !== !0 && (e[o[a]] = n[d]);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
return
|
|
135
|
-
},
|
|
134
|
+
return e;
|
|
135
|
+
}, te = (t) => vt(t) ? `'${t.replaceAll("\0", "").replaceAll("'", "''")}'` : Rt(t) ? "NULL" : t, fe = (t, n = []) => t.replace(/\?/g, () => String(te(n.shift()))), je = (t, n, e) => {
|
|
136
136
|
const s = {};
|
|
137
|
-
return
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
s[
|
|
137
|
+
return e.forEach((o, a) => {
|
|
138
|
+
const d = n[a];
|
|
139
|
+
if (d.startsWith("__")) return;
|
|
140
|
+
const p = t.foreignKeyNames || [], b = (t.foreignKeyColumnNames || p).indexOf(d);
|
|
141
|
+
if (b !== -1) {
|
|
142
|
+
s[p[b]] = o;
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
const
|
|
148
|
-
|
|
145
|
+
const A = t.columnNameToPropertyName, T = A?.get(d);
|
|
146
|
+
if (T) {
|
|
147
|
+
const M = t.propertyMap.get(T);
|
|
148
|
+
M ? s[T] = ue(o, M) : console.warn(`Property ${T} not found in metadata ${t.name}`);
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
s[
|
|
151
|
+
const I = t.computedPropertyMap?.get(d);
|
|
152
|
+
if (I) {
|
|
153
|
+
s[d] = ue(o, I);
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
|
-
if (!
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
s[
|
|
156
|
+
if (!A) {
|
|
157
|
+
const M = t.propertyMap.get(d);
|
|
158
|
+
if (M) {
|
|
159
|
+
s[d] = ue(o, M);
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
console.warn(`Column ${
|
|
163
|
+
console.warn(`Column ${d}=${o} not found in metadata ${t.name}`);
|
|
164
164
|
}), s;
|
|
165
|
-
},
|
|
165
|
+
}, Q = "_", Ft = {
|
|
166
166
|
"=": "=",
|
|
167
167
|
"!=": "!=",
|
|
168
168
|
">": ">",
|
|
@@ -179,514 +179,514 @@ const le = (e, n) => {
|
|
|
179
179
|
notStartsWith: "NOT LIKE",
|
|
180
180
|
endsWith: "LIKE",
|
|
181
181
|
notEndsWith: "NOT LIKE"
|
|
182
|
-
},
|
|
183
|
-
if (n &&
|
|
184
|
-
const
|
|
185
|
-
if (!s) return
|
|
186
|
-
if (s.type ===
|
|
182
|
+
}, Be = (t, n) => {
|
|
183
|
+
if (n && t.includes(".")) {
|
|
184
|
+
const e = t.split("."), s = n.propertyMap.get(e[0]);
|
|
185
|
+
if (!s) return t;
|
|
186
|
+
if (s.type === D.keyValue)
|
|
187
187
|
return s.columnName;
|
|
188
|
-
for (let
|
|
189
|
-
const
|
|
190
|
-
if (!
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
188
|
+
for (let a = 0; a < e.length - 1; a++) {
|
|
189
|
+
const d = n.propertyMap.get(e[a]);
|
|
190
|
+
if (!d) return t;
|
|
191
|
+
if (d.type === D.keyValue)
|
|
192
|
+
return d.columnName;
|
|
193
193
|
}
|
|
194
|
-
const
|
|
195
|
-
return
|
|
194
|
+
const o = n.propertyMap.get(e[e.length - 1]);
|
|
195
|
+
return o ? o.columnName : t;
|
|
196
196
|
}
|
|
197
197
|
if (n) {
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
return
|
|
201
|
-
const s = n.foreignKeyNames || [],
|
|
202
|
-
if (
|
|
203
|
-
return
|
|
198
|
+
const e = n.propertyMap.get(t);
|
|
199
|
+
if (e)
|
|
200
|
+
return e.columnName;
|
|
201
|
+
const s = n.foreignKeyNames || [], o = n.foreignKeyColumnNames || s, a = s.indexOf(t);
|
|
202
|
+
if (a !== -1)
|
|
203
|
+
return o[a];
|
|
204
204
|
}
|
|
205
|
-
return
|
|
206
|
-
},
|
|
205
|
+
return t;
|
|
206
|
+
}, Ze = (t, n, e) => {
|
|
207
207
|
if (n) return n;
|
|
208
|
-
if (!
|
|
209
|
-
const
|
|
210
|
-
return `${
|
|
211
|
-
}
|
|
212
|
-
const s =
|
|
213
|
-
return `"${
|
|
214
|
-
},
|
|
215
|
-
const { operator: n, value:
|
|
208
|
+
if (!t.includes(".")) {
|
|
209
|
+
const p = Be(t, e);
|
|
210
|
+
return `${Q}."${p}"`;
|
|
211
|
+
}
|
|
212
|
+
const s = t.lastIndexOf("."), o = t.slice(0, s), a = t.slice(s + 1), d = Be(a, e);
|
|
213
|
+
return `"${o}"."${d}"`;
|
|
214
|
+
}, ct = (t) => {
|
|
215
|
+
const { operator: n, value: e } = t;
|
|
216
216
|
switch (n) {
|
|
217
217
|
case "in":
|
|
218
218
|
case "notIn":
|
|
219
|
-
return
|
|
219
|
+
return Kt(e);
|
|
220
220
|
case "between":
|
|
221
221
|
case "notBetween":
|
|
222
|
-
return
|
|
222
|
+
return Ht(e);
|
|
223
223
|
case "contains":
|
|
224
224
|
case "notContains":
|
|
225
|
-
return
|
|
225
|
+
return te(`%${e}%`);
|
|
226
226
|
case "startsWith":
|
|
227
227
|
case "notStartsWith":
|
|
228
|
-
return
|
|
228
|
+
return te(`${e}%`);
|
|
229
229
|
case "endsWith":
|
|
230
230
|
case "notEndsWith":
|
|
231
|
-
return
|
|
231
|
+
return te(`%${e}`);
|
|
232
232
|
default:
|
|
233
|
-
return
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
if (!Array.isArray(
|
|
237
|
-
const [n,
|
|
238
|
-
if (n == null ||
|
|
239
|
-
const s = n instanceof Date ? n.toISOString() : n,
|
|
240
|
-
return `${
|
|
241
|
-
},
|
|
242
|
-
const s =
|
|
243
|
-
if (!s || s.type !==
|
|
244
|
-
const
|
|
245
|
-
if (!
|
|
246
|
-
const
|
|
247
|
-
return `(${
|
|
248
|
-
const
|
|
249
|
-
return `json_extract(${
|
|
250
|
-
}).join(
|
|
251
|
-
},
|
|
252
|
-
const s =
|
|
253
|
-
if (!s || s.type !==
|
|
254
|
-
const
|
|
255
|
-
return
|
|
256
|
-
},
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
}),
|
|
233
|
+
return Vt(e);
|
|
234
|
+
}
|
|
235
|
+
}, Wt = (t) => Ft[t] || t, be = (t, n, e) => t.length === 1 ? e.name : `${n}_${e.name}`, Kt = (t) => !Array.isArray(t) || !t.length ? "(NULL)" : `(${t.map(te).join(", ")})`, Ht = (t) => {
|
|
236
|
+
if (!Array.isArray(t) || t.length < 2) return "";
|
|
237
|
+
const [n, e] = t;
|
|
238
|
+
if (n == null || e == null) return "";
|
|
239
|
+
const s = n instanceof Date ? n.toISOString() : n, o = e instanceof Date ? e.toISOString() : e;
|
|
240
|
+
return `${te(s)} and ${te(o)}`;
|
|
241
|
+
}, Vt = (t) => typeof t == "boolean" ? t ? "1" : "0" : typeof t == "string" ? te(t) : typeof t == "number" ? t.toString() : t instanceof Date ? te(t.toISOString()) : te(t), Yt = (t, n, e) => {
|
|
242
|
+
const s = t.propertyMap.get(n);
|
|
243
|
+
if (!s || s.type !== D.keyValue || typeof e.value != "object" || Array.isArray(e.value)) return null;
|
|
244
|
+
const o = Object.entries(e.value).filter(([, f]) => f != null);
|
|
245
|
+
if (!o.length) return "";
|
|
246
|
+
const a = e.operator === "notContains" ? "NOT LIKE" : "LIKE", d = e.operator === "contains" ? " OR " : " AND ";
|
|
247
|
+
return `(${o.map(([f, b]) => {
|
|
248
|
+
const A = b instanceof Date ? b.toISOString() : typeof b == "string" ? b : String(b), T = f.replace(/'/g, "''");
|
|
249
|
+
return `json_extract(${Q}."${s.columnName}", '$.${T}') ${a} ${te(`%${A}%`)}`;
|
|
250
|
+
}).join(d)})`;
|
|
251
|
+
}, Qt = (t, n, e) => {
|
|
252
|
+
const s = t.propertyMap.get(n);
|
|
253
|
+
if (!s || s.type !== D.stringArray && s.type !== D.numberArray) return null;
|
|
254
|
+
const o = ct(e), a = `EXISTS (SELECT 1 FROM json_each(${Q}."${s.columnName}") WHERE json_each.value IN ${o})`;
|
|
255
|
+
return e.operator === "notIn" ? `NOT ${a}` : a;
|
|
256
|
+
}, Jt = (t, n, e, s, o) => {
|
|
257
|
+
if (e && s && o && (t.operator === "exists" || t.operator === "notExists")) {
|
|
258
|
+
const I = en(t, e, s, (M, E) => {
|
|
259
|
+
const v = /* @__PURE__ */ new Map();
|
|
260
|
+
return E.propertyMap.forEach((m, N) => {
|
|
261
|
+
v.set(N, `"child"."${m.columnName}"`);
|
|
262
|
+
}), o(M, v, E, s);
|
|
263
263
|
});
|
|
264
|
-
if (
|
|
265
|
-
}
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
const
|
|
271
|
-
if (!
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
}
|
|
277
|
-
if (
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
280
|
-
}
|
|
281
|
-
return `${
|
|
282
|
-
},
|
|
283
|
-
if (
|
|
264
|
+
if (I !== null) return I;
|
|
265
|
+
}
|
|
266
|
+
if (t.operator === "null" || t.operator === "notNull") {
|
|
267
|
+
const T = String(t.field), I = n.get(T), M = Ze(T, I, e);
|
|
268
|
+
return t.operator === "null" ? `${M} IS NULL` : `${M} IS NOT NULL`;
|
|
269
|
+
}
|
|
270
|
+
const a = t.value === null, d = a ? "" : Wt(t.operator).toLowerCase(), p = a ? t.operator === "=" ? "IS NULL" : t.operator === "!=" ? "IS NOT NULL" : "" : ct(t);
|
|
271
|
+
if (!p && ["in", "notIn", "between", "notBetween"].includes(t.operator)) return "";
|
|
272
|
+
const f = String(t.field), b = n.get(f);
|
|
273
|
+
if (e && !f.includes(".") && (t.operator === "contains" || t.operator === "notContains")) {
|
|
274
|
+
const T = Yt(e, f, t);
|
|
275
|
+
if (T !== null) return T;
|
|
276
|
+
}
|
|
277
|
+
if (e && !f.includes(".") && (t.operator === "in" || t.operator === "notIn")) {
|
|
278
|
+
const T = Qt(e, f, t);
|
|
279
|
+
if (T !== null) return T;
|
|
280
|
+
}
|
|
281
|
+
return `${Ze(f, b, e)} ${d} ${p}`.replace(/\s+/g, " ").trim();
|
|
282
|
+
}, Ue = (t) => t === Q ? t : `"${t}"`, Gt = (t, n, e) => {
|
|
283
|
+
if (t.kind !== z.ONE_TO_MANY)
|
|
284
284
|
throw new Error("_build_one_to_many_exists requires ONE_TO_MANY relation");
|
|
285
|
-
const s =
|
|
286
|
-
if (!
|
|
285
|
+
const s = le(n.tableName, n.namespace), o = "child", a = n.relations.find((f) => f.name === t.mappedProperty);
|
|
286
|
+
if (!a)
|
|
287
287
|
throw new Error(
|
|
288
|
-
`Cannot find mappedProperty relation "${
|
|
288
|
+
`Cannot find mappedProperty relation "${t.mappedProperty}" in entity "${n.name}"`
|
|
289
289
|
);
|
|
290
|
-
const
|
|
291
|
-
let
|
|
292
|
-
return
|
|
293
|
-
},
|
|
294
|
-
const s =
|
|
295
|
-
if (!
|
|
296
|
-
return `${
|
|
297
|
-
const
|
|
298
|
-
let
|
|
299
|
-
return
|
|
300
|
-
},
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
303
|
-
const
|
|
304
|
-
let
|
|
305
|
-
return
|
|
290
|
+
const d = a.columnName;
|
|
291
|
+
let p = `EXISTS (SELECT 1 FROM "${s}" "${o}"`;
|
|
292
|
+
return p += ` WHERE "${o}"."${d}" = ${Q}."id"`, e && (p += ` AND ${e}`), p += ")", p;
|
|
293
|
+
}, Xt = (t, n, e) => {
|
|
294
|
+
const s = t.columnName;
|
|
295
|
+
if (!e)
|
|
296
|
+
return `${Q}."${s}" IS NOT NULL`;
|
|
297
|
+
const o = le(n.tableName, n.namespace), a = "child";
|
|
298
|
+
let d = `EXISTS (SELECT 1 FROM "${o}" "${a}"`;
|
|
299
|
+
return d += ` WHERE ${Q}."${s}" = "${a}"."id"`, d += ` AND ${e}`, d += ")", d;
|
|
300
|
+
}, zt = (t, n, e, s, o) => {
|
|
301
|
+
const a = s.rxdb.schemaManager.findMappedRelation(t, n);
|
|
302
|
+
if (a?.relation) {
|
|
303
|
+
const d = le(e.tableName, e.namespace), p = "child", f = a.relation.columnName;
|
|
304
|
+
let b = `EXISTS (SELECT 1 FROM "${d}" "${p}"`;
|
|
305
|
+
return b += ` WHERE "${p}"."${f}" = ${Q}."id"`, o && (b += ` AND ${o}`), b += ")", b;
|
|
306
306
|
} else {
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
309
|
-
return `${
|
|
310
|
-
const
|
|
311
|
-
let
|
|
312
|
-
return
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
const
|
|
316
|
-
if (!
|
|
307
|
+
const d = n.columnName;
|
|
308
|
+
if (!o)
|
|
309
|
+
return `${Q}."${d}" IS NOT NULL`;
|
|
310
|
+
const p = le(e.tableName, e.namespace), f = "child";
|
|
311
|
+
let b = `EXISTS (SELECT 1 FROM "${p}" "${f}"`;
|
|
312
|
+
return b += ` WHERE ${Q}."${d}" = "${f}"."id"`, b += ` AND ${o}`, b += ")", b;
|
|
313
|
+
}
|
|
314
|
+
}, Zt = (t, n, e, s) => {
|
|
315
|
+
const o = le(e.tableName, e.namespace), a = "child", d = n.junctionEntityType;
|
|
316
|
+
if (!d)
|
|
317
317
|
throw new Error(`MANY_TO_MANY relation "${n.name}" missing junctionEntityType`);
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
318
|
+
const p = V(d);
|
|
319
|
+
if (!p)
|
|
320
320
|
throw new Error("Cannot find metadata for junction entity");
|
|
321
|
-
const
|
|
322
|
-
(
|
|
321
|
+
const f = le(p.tableName, p.namespace), b = "junction", A = p.relations.find(
|
|
322
|
+
(v) => v.mappedEntity === t.name && v.mappedNamespace === t.namespace
|
|
323
323
|
);
|
|
324
|
-
if (!
|
|
324
|
+
if (!A)
|
|
325
325
|
throw new Error(
|
|
326
|
-
`Cannot find relation in junction entity ${
|
|
326
|
+
`Cannot find relation in junction entity ${p.name} pointing to ${t.name}`
|
|
327
327
|
);
|
|
328
|
-
const
|
|
329
|
-
(
|
|
328
|
+
const T = p.relations.find(
|
|
329
|
+
(v) => v.mappedEntity === e.name && v.mappedNamespace === e.namespace
|
|
330
330
|
);
|
|
331
|
-
if (!
|
|
331
|
+
if (!T)
|
|
332
332
|
throw new Error(
|
|
333
|
-
`Cannot find relation in junction entity ${
|
|
333
|
+
`Cannot find relation in junction entity ${p.name} pointing to ${e.name}`
|
|
334
334
|
);
|
|
335
|
-
const
|
|
336
|
-
let
|
|
337
|
-
return
|
|
338
|
-
},
|
|
339
|
-
if (
|
|
335
|
+
const I = A.columnName, M = T.columnName;
|
|
336
|
+
let E = `EXISTS (SELECT 1 FROM "${o}" "${a}"`;
|
|
337
|
+
return E += ` INNER JOIN "${f}" "${b}"`, E += ` ON "${b}"."${M}" = "${a}"."id"`, E += ` WHERE "${b}"."${I}" = ${Q}."id"`, s && (E += ` AND ${s}`), E += ")", E;
|
|
338
|
+
}, en = (t, n, e, s) => {
|
|
339
|
+
if (t.operator !== "exists" && t.operator !== "notExists")
|
|
340
340
|
return null;
|
|
341
|
-
const
|
|
342
|
-
if (!
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
341
|
+
const o = n.relationMap.get(t.field);
|
|
342
|
+
if (!o) return null;
|
|
343
|
+
const a = e.rxdb.schemaManager.getEntityMetadata(
|
|
344
|
+
o.mappedEntity,
|
|
345
|
+
o.mappedNamespace
|
|
346
346
|
);
|
|
347
|
-
if (!
|
|
348
|
-
throw new Error(`Cannot find metadata for entity: ${
|
|
349
|
-
let
|
|
350
|
-
|
|
351
|
-
let
|
|
352
|
-
switch (
|
|
353
|
-
case
|
|
354
|
-
|
|
347
|
+
if (!a)
|
|
348
|
+
throw new Error(`Cannot find metadata for entity: ${o.mappedNamespace}.${o.mappedEntity}`);
|
|
349
|
+
let d;
|
|
350
|
+
t.where && s && (d = s(t.where, a));
|
|
351
|
+
let p;
|
|
352
|
+
switch (o.kind) {
|
|
353
|
+
case z.ONE_TO_MANY:
|
|
354
|
+
p = Gt(o, a, d);
|
|
355
355
|
break;
|
|
356
|
-
case
|
|
357
|
-
|
|
356
|
+
case z.MANY_TO_ONE:
|
|
357
|
+
p = Xt(o, a, d);
|
|
358
358
|
break;
|
|
359
|
-
case
|
|
360
|
-
|
|
359
|
+
case z.ONE_TO_ONE:
|
|
360
|
+
p = zt(n, o, a, e, d);
|
|
361
361
|
break;
|
|
362
|
-
case
|
|
363
|
-
|
|
362
|
+
case z.MANY_TO_MANY:
|
|
363
|
+
p = Zt(n, o, a, d);
|
|
364
364
|
break;
|
|
365
365
|
}
|
|
366
|
-
return
|
|
367
|
-
},
|
|
368
|
-
if (
|
|
369
|
-
return
|
|
370
|
-
const
|
|
371
|
-
return
|
|
372
|
-
},
|
|
373
|
-
const
|
|
374
|
-
let
|
|
375
|
-
const
|
|
376
|
-
for (const
|
|
377
|
-
if (!
|
|
366
|
+
return t.operator === "notExists" ? `NOT ${p}` : p;
|
|
367
|
+
}, Ne = (t, n) => {
|
|
368
|
+
if (t.relationAliasMap.has(n))
|
|
369
|
+
return t.relationAliasMap.get(n);
|
|
370
|
+
const e = n.includes("_") ? n : n.split("_")[0], s = lt(t, e);
|
|
371
|
+
return t.relationAliasMap.set(n, s), s;
|
|
372
|
+
}, tn = (t, n, e, s) => {
|
|
373
|
+
const o = e.slice(0, s);
|
|
374
|
+
let a = n;
|
|
375
|
+
const d = [];
|
|
376
|
+
for (const p of o) {
|
|
377
|
+
if (!a?.relationMap.has(p))
|
|
378
378
|
return { relPairs: [] };
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
return { metaWalker:
|
|
383
|
-
},
|
|
384
|
-
for (let
|
|
385
|
-
const
|
|
386
|
-
if (
|
|
387
|
-
const { metaWalker:
|
|
388
|
-
if (!
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
return n.fieldAliasMap.set(s, `json_extract("${
|
|
379
|
+
const f = a.relationMap.get(p);
|
|
380
|
+
d.push({ metadata: a, relation: f }), a = t.rxdb.schemaManager.getEntityMetadata(f.mappedEntity, f.mappedNamespace);
|
|
381
|
+
}
|
|
382
|
+
return { metaWalker: a, relPairs: d };
|
|
383
|
+
}, nn = (t, n, e, s, o) => {
|
|
384
|
+
for (let a = o.length - 1; a > 0; a--) {
|
|
385
|
+
const d = o.slice(a);
|
|
386
|
+
if (d.length === 0) continue;
|
|
387
|
+
const { metaWalker: p, relPairs: f } = tn(t, e, o, a);
|
|
388
|
+
if (!p || f.length === 0) continue;
|
|
389
|
+
const b = d[0], A = d.slice(1).join("."), T = p.propertyMap.get(b);
|
|
390
|
+
if (T && T.type === D.keyValue) {
|
|
391
|
+
const I = o.slice(0, a).join(".");
|
|
392
|
+
ut(t, n, f, I);
|
|
393
|
+
const M = f[f.length - 1].relation, E = be(f, I, M), v = Ne(n, E), m = A ? `$.${A}` : "$";
|
|
394
|
+
return n.fieldAliasMap.set(s, `json_extract("${v}"."${T.columnName}", '${m}')`), !0;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
return !1;
|
|
398
|
-
},
|
|
399
|
-
|
|
400
|
-
let
|
|
401
|
-
if (!
|
|
402
|
-
if (
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
} else (
|
|
406
|
-
if (!
|
|
407
|
-
const
|
|
408
|
-
let
|
|
409
|
-
if (
|
|
410
|
-
const
|
|
411
|
-
|
|
398
|
+
}, ut = (t, n, e, s) => {
|
|
399
|
+
e.forEach(({ metadata: o, relation: a }, d) => {
|
|
400
|
+
let p = t.rxdb.schemaManager.findMappedRelation(o, a);
|
|
401
|
+
if (!p)
|
|
402
|
+
if (a.kind === z.ONE_TO_MANY || a.kind === z.MANY_TO_MANY) {
|
|
403
|
+
const T = o.relationMap.get(a.mappedProperty);
|
|
404
|
+
T && (p = { metadata: o, relation: T });
|
|
405
|
+
} else (a.kind === z.MANY_TO_ONE || a.kind === z.ONE_TO_ONE) && (p = { metadata: o, relation: a });
|
|
406
|
+
if (!p) throw new ee("mappedRelation not found");
|
|
407
|
+
const f = be(e, s, a), b = Ne(n, f);
|
|
408
|
+
let A = Q;
|
|
409
|
+
if (d > 0) {
|
|
410
|
+
const T = e[d - 1], I = be(e, s, T.relation);
|
|
411
|
+
A = Ne(n, I);
|
|
412
412
|
}
|
|
413
|
-
switch (
|
|
414
|
-
case
|
|
415
|
-
|
|
413
|
+
switch (a.kind) {
|
|
414
|
+
case z.ONE_TO_MANY:
|
|
415
|
+
rn(
|
|
416
416
|
n,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
417
|
+
p,
|
|
418
|
+
b,
|
|
419
|
+
A
|
|
420
420
|
);
|
|
421
421
|
break;
|
|
422
|
-
case
|
|
423
|
-
case
|
|
424
|
-
|
|
422
|
+
case z.ONE_TO_ONE:
|
|
423
|
+
case z.MANY_TO_ONE:
|
|
424
|
+
sn(
|
|
425
425
|
n,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
p,
|
|
427
|
+
b,
|
|
428
|
+
A,
|
|
429
|
+
a
|
|
430
430
|
);
|
|
431
431
|
break;
|
|
432
|
-
case
|
|
433
|
-
|
|
434
|
-
|
|
432
|
+
case z.MANY_TO_MANY:
|
|
433
|
+
on(
|
|
434
|
+
t,
|
|
435
435
|
n,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
p,
|
|
437
|
+
b,
|
|
438
|
+
A,
|
|
439
|
+
a
|
|
440
440
|
);
|
|
441
441
|
break;
|
|
442
442
|
}
|
|
443
443
|
});
|
|
444
|
-
},
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
joinTableName:
|
|
448
|
-
on:
|
|
444
|
+
}, rn = (t, n, e, s) => {
|
|
445
|
+
const o = Ae(t, n.metadata), a = `"${e}".${n.relation.columnName} = ${Ue(s)}.id`;
|
|
446
|
+
o.find((p) => p.joinTableName === e && p.on === a) || o.push({
|
|
447
|
+
joinTableName: e,
|
|
448
|
+
on: a
|
|
449
449
|
});
|
|
450
|
-
},
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
joinTableName:
|
|
454
|
-
on:
|
|
450
|
+
}, sn = (t, n, e, s, o) => {
|
|
451
|
+
const a = Ae(t, n.metadata), d = `"${e}".id = ${Ue(s)}.${o.columnName}`;
|
|
452
|
+
a.find((f) => f.joinTableName === e && f.on === d) || a.push({
|
|
453
|
+
joinTableName: e,
|
|
454
|
+
on: d
|
|
455
455
|
});
|
|
456
|
-
},
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
(
|
|
460
|
-
) ||
|
|
461
|
-
joinTableName:
|
|
462
|
-
on:
|
|
456
|
+
}, on = (t, n, e, s, o, a) => {
|
|
457
|
+
const d = V(a.junctionEntityType), p = Ae(n, d), f = lt(n, `${a.name}_m_n`), b = `"${f}".${e.relation.columnName} = ${Ue(o)}.id`;
|
|
458
|
+
p.find(
|
|
459
|
+
(E) => E.joinTableName === f && E.on === b
|
|
460
|
+
) || p.push({
|
|
461
|
+
joinTableName: f,
|
|
462
|
+
on: b
|
|
463
463
|
});
|
|
464
|
-
const
|
|
465
|
-
|
|
464
|
+
const T = Ae(n, e.metadata), I = `"${s}".id = "${f}".${a.columnName}`;
|
|
465
|
+
T.find((E) => E.joinTableName === s && E.on === I) || T.push({
|
|
466
466
|
joinTableName: s,
|
|
467
|
-
on:
|
|
467
|
+
on: I
|
|
468
468
|
});
|
|
469
|
-
},
|
|
470
|
-
let
|
|
471
|
-
for (;
|
|
472
|
-
|
|
473
|
-
return
|
|
474
|
-
},
|
|
475
|
-
if (
|
|
476
|
-
return
|
|
477
|
-
const s =
|
|
478
|
-
return `${
|
|
469
|
+
}, Ae = (t, n) => (t.joinMap.has(n) || t.joinMap.set(n, []), t.joinMap.get(n)), lt = (t, n) => {
|
|
470
|
+
let e = n, s = 1;
|
|
471
|
+
for (; t.usedAliases.has(e); )
|
|
472
|
+
e = `${n}_${s}`, s++;
|
|
473
|
+
return t.usedAliases.add(e), e;
|
|
474
|
+
}, an = (t, n) => {
|
|
475
|
+
if (t?.length)
|
|
476
|
+
return t.map((e) => {
|
|
477
|
+
const s = Be(e.field, n);
|
|
478
|
+
return `${Q}."${s}" ${e.sort}`;
|
|
479
479
|
}).join(", ");
|
|
480
|
-
},
|
|
481
|
-
if (!
|
|
482
|
-
const
|
|
483
|
-
(
|
|
480
|
+
}, he = (t, n = /* @__PURE__ */ new Map(), e, s) => {
|
|
481
|
+
if (!t?.rules) return "";
|
|
482
|
+
const o = t.rules.map(
|
|
483
|
+
(a) => Ye(a) ? he(a, n, e, s) : Jt(a, n, e, s, he)
|
|
484
484
|
).filter(Boolean);
|
|
485
|
-
return
|
|
486
|
-
},
|
|
487
|
-
const { tableName: n, where:
|
|
488
|
-
let
|
|
489
|
-
if (
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
const
|
|
494
|
-
return
|
|
495
|
-
},
|
|
485
|
+
return o.length ? o.length === 1 ? o[0] : `(${o.join(Ye(t) ? ` ${t.combinator} ` : " ")})` : "";
|
|
486
|
+
}, ft = (t) => {
|
|
487
|
+
const { tableName: n, where: e, limit: s, offset: o, orderBy: a, join: d, hasJoin: p, metadata: f } = t;
|
|
488
|
+
let b = `${Q}.rowid as ${ie}, ${Q}.*`;
|
|
489
|
+
if (f.features?.tree?.hasChildren && f.features?.tree?.type === "adjacency-list") {
|
|
490
|
+
const I = f.relationMap.get("parent").columnName;
|
|
491
|
+
b += `, EXISTS(SELECT 1 FROM "${n}" __sub WHERE __sub."${I}" = ${Q}."id") AS "hasChildren"`;
|
|
492
|
+
}
|
|
493
|
+
const A = [`SELECT ${p ? "DISTINCT " : ""}${b} FROM "${n}" ${Q}`];
|
|
494
|
+
return d && A.push(d), e && A.push(` WHERE ${e}`), a && A.push(` ORDER BY ${a}`), s && A.push(` LIMIT ${s}`), o && A.push(` OFFSET ${o}`), A.join("") + ";";
|
|
495
|
+
}, dt = (t, n, e) => {
|
|
496
496
|
const s = {
|
|
497
497
|
joinMap: /* @__PURE__ */ new Map(),
|
|
498
498
|
usedAliases: /* @__PURE__ */ new Set(),
|
|
499
499
|
fieldAliasMap: /* @__PURE__ */ new Map(),
|
|
500
500
|
relationAliasMap: /* @__PURE__ */ new Map()
|
|
501
501
|
};
|
|
502
|
-
|
|
503
|
-
const
|
|
504
|
-
|
|
502
|
+
Ct(e, (a, d, p) => {
|
|
503
|
+
const f = d;
|
|
504
|
+
a !== "field" || !f.includes(".") || un(t, s, n, f, p);
|
|
505
505
|
});
|
|
506
|
-
const
|
|
507
|
-
for (const [
|
|
508
|
-
const
|
|
509
|
-
for (const
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
return { joinSQL:
|
|
513
|
-
},
|
|
506
|
+
const o = [];
|
|
507
|
+
for (const [a, d] of s.joinMap.entries()) {
|
|
508
|
+
const p = X(a);
|
|
509
|
+
for (const f of d)
|
|
510
|
+
o.push(` LEFT JOIN "${p}" "${f.joinTableName}" ON ${f.on}`);
|
|
511
|
+
}
|
|
512
|
+
return { joinSQL: o.join(""), fieldAliasMap: s.fieldAliasMap };
|
|
513
|
+
}, cn = (t, n, e, s) => {
|
|
514
514
|
if (s.length <= 1) return !1;
|
|
515
|
-
const [
|
|
516
|
-
if (
|
|
517
|
-
const
|
|
518
|
-
return
|
|
515
|
+
const [o, ...a] = s, d = n.propertyMap.get(o);
|
|
516
|
+
if (d && d.type === D.keyValue && a.length > 0) {
|
|
517
|
+
const p = a.join(".");
|
|
518
|
+
return t.fieldAliasMap.set(e, `json_extract(${Q}."${d.columnName}", '$.${p}')`), !0;
|
|
519
519
|
}
|
|
520
520
|
return !1;
|
|
521
|
-
},
|
|
522
|
-
const
|
|
521
|
+
}, un = (t, n, e, s, o) => {
|
|
522
|
+
const a = s.split(".");
|
|
523
523
|
try {
|
|
524
|
-
const
|
|
525
|
-
if (
|
|
526
|
-
|
|
524
|
+
const d = t.rxdb.schemaManager.getFieldRelations(e, s);
|
|
525
|
+
if (d.isForeignKey) {
|
|
526
|
+
o.field = d.propertyName;
|
|
527
527
|
return;
|
|
528
528
|
}
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
const
|
|
532
|
-
n.fieldAliasMap.set(s, `"${
|
|
529
|
+
const p = s.replace(`.${d.propertyName}`, "");
|
|
530
|
+
ut(t, n, d.relations, p);
|
|
531
|
+
const f = d.relations[d.relations.length - 1], b = be(d.relations, p, f.relation), A = Ne(n, b);
|
|
532
|
+
n.fieldAliasMap.set(s, `"${A}"."${d.property.columnName}"`);
|
|
533
533
|
return;
|
|
534
534
|
} catch {
|
|
535
535
|
}
|
|
536
|
-
|
|
537
|
-
},
|
|
538
|
-
const
|
|
536
|
+
cn(n, e, s, a) || nn(t, n, e, s, a);
|
|
537
|
+
}, ln = (t, n) => {
|
|
538
|
+
const e = X(t), s = [n.id];
|
|
539
539
|
return {
|
|
540
|
-
sql: `DELETE FROM "${
|
|
540
|
+
sql: `DELETE FROM "${e}" WHERE id = ?;`,
|
|
541
541
|
params: s
|
|
542
542
|
};
|
|
543
|
-
},
|
|
544
|
-
const s =
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
const
|
|
549
|
-
let
|
|
550
|
-
return
|
|
551
|
-
sql:
|
|
552
|
-
params:
|
|
543
|
+
}, pt = (t, n, e) => {
|
|
544
|
+
const s = X(t), o = at(t, n);
|
|
545
|
+
e?.userId && (t.propertyMap.has("createdBy") && (o.createdBy = e.userId), t.propertyMap.has("updatedBy") && (o.updatedBy = e.userId));
|
|
546
|
+
const a = /* @__PURE__ */ new Date();
|
|
547
|
+
t.propertyMap.has("createdAt") && o.createdAt === void 0 && (o.createdAt = e?.createdAt ?? a), t.propertyMap.has("updatedAt") && o.updatedAt === void 0 && (o.updatedAt = e?.updatedAt ?? a);
|
|
548
|
+
const d = ke(t, o), p = Object.keys(d), f = Array(p.length).fill("?").join(","), b = Object.values(d);
|
|
549
|
+
let T = `${e?.useReplace ? "INSERT OR REPLACE" : "INSERT"} INTO "${s}" (${p.join(",")}) VALUES (${f})`;
|
|
550
|
+
return e?.returning !== !1 ? T += ` RETURNING rowid as ${ie}, *;` : T += ";", {
|
|
551
|
+
sql: T,
|
|
552
|
+
params: b
|
|
553
553
|
};
|
|
554
|
-
},
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
let
|
|
559
|
-
return
|
|
560
|
-
sql:
|
|
561
|
-
params:
|
|
554
|
+
}, Pe = (t, n, e, s) => {
|
|
555
|
+
const o = Pt(t, e);
|
|
556
|
+
t.propertyMap.has("updatedAt") && (o.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && t.propertyMap.has("updatedBy") && (o.updatedBy = s.userId);
|
|
557
|
+
const a = ke(t, o), d = Object.keys(a).map((I) => `${I} = ?`).join(","), p = [...Object.values(a)], f = X(t), b = Array.isArray(n), A = b ? n : [n];
|
|
558
|
+
let T = `UPDATE "${f}" SET ${d} WHERE id `;
|
|
559
|
+
return b ? T += `in (${A.map((I) => te(I.id)).join(",")})` : (p.push(n.id), T += "= ?"), s?.returning !== !1 ? T += ` RETURNING rowid as ${ie}, *;` : T += ";", {
|
|
560
|
+
sql: T,
|
|
561
|
+
params: p
|
|
562
562
|
};
|
|
563
|
-
},
|
|
564
|
-
if (
|
|
565
|
-
throw new
|
|
566
|
-
const { joinSQL: s, fieldAliasMap:
|
|
567
|
-
return s &&
|
|
568
|
-
},
|
|
569
|
-
const { joinSQL: s, fieldAliasMap:
|
|
570
|
-
return { sql:
|
|
571
|
-
tableName:
|
|
572
|
-
where:
|
|
573
|
-
orderBy:
|
|
563
|
+
}, fn = (t, n, e) => {
|
|
564
|
+
if (e.groupBy)
|
|
565
|
+
throw new ee("groupBy not supported yet");
|
|
566
|
+
const { joinSQL: s, fieldAliasMap: o } = dt(t, n, e.where), a = X(n), d = he(e.where, o, n, t), p = [`SELECT COUNT(${Q}.rowid) AS count FROM "${a}" ${Q}`];
|
|
567
|
+
return s && p.push(s), d && p.push(` WHERE ${d}`), { sql: p.join("") };
|
|
568
|
+
}, De = (t, n, e) => {
|
|
569
|
+
const { joinSQL: s, fieldAliasMap: o } = dt(t, n, e.where);
|
|
570
|
+
return { sql: ft({
|
|
571
|
+
tableName: X(n),
|
|
572
|
+
where: he(e.where, o, n, t),
|
|
573
|
+
orderBy: an(e.orderBy, n),
|
|
574
574
|
join: s,
|
|
575
575
|
hasJoin: !!s,
|
|
576
576
|
metadata: n,
|
|
577
|
-
limit:
|
|
578
|
-
offset:
|
|
577
|
+
limit: e.limit,
|
|
578
|
+
offset: e.offset
|
|
579
579
|
}) };
|
|
580
|
-
},
|
|
581
|
-
const
|
|
582
|
-
return { sql:
|
|
583
|
-
tableName:
|
|
584
|
-
where: `${
|
|
585
|
-
metadata:
|
|
580
|
+
}, dn = (t, n) => {
|
|
581
|
+
const e = n.map(() => "?").join(",");
|
|
582
|
+
return { sql: ft({
|
|
583
|
+
tableName: X(t),
|
|
584
|
+
where: `${ie} IN (${e})`,
|
|
585
|
+
metadata: t
|
|
586
586
|
}), params: n };
|
|
587
|
-
},
|
|
588
|
-
const
|
|
589
|
-
return
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
let
|
|
594
|
-
if (
|
|
595
|
-
|
|
596
|
-
const
|
|
597
|
-
if (
|
|
598
|
-
$ in
|
|
587
|
+
}, Ie = (t, n, e, s = !1, o = !1) => {
|
|
588
|
+
const a = [], d = V(n), p = t.rxdb.entityManager;
|
|
589
|
+
return e.results.forEach(({ columns: f, rows: b }) => {
|
|
590
|
+
const A = f.findIndex((I) => I === "id"), T = f.findIndex((I) => I === ie);
|
|
591
|
+
b.forEach((I) => {
|
|
592
|
+
const M = I[A];
|
|
593
|
+
let E;
|
|
594
|
+
if (t.rxdb.entityManager.hasEntityRef(n, M)) {
|
|
595
|
+
E = p.getEntityRef(n, M);
|
|
596
|
+
const N = je(d, f, I);
|
|
597
|
+
if (d.computedPropertyMap.forEach((S, $) => {
|
|
598
|
+
$ in N && (E[$] = N[$]);
|
|
599
599
|
}), s) {
|
|
600
|
-
const
|
|
601
|
-
|
|
600
|
+
const S = ae(E);
|
|
601
|
+
S.origin = { ...N }, Object.assign(E, N);
|
|
602
602
|
}
|
|
603
603
|
} else {
|
|
604
|
-
if (
|
|
604
|
+
if (o)
|
|
605
605
|
return;
|
|
606
606
|
{
|
|
607
|
-
const
|
|
608
|
-
|
|
607
|
+
const N = je(d, f, I);
|
|
608
|
+
E = p.createEntityRef(n, N);
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
|
-
|
|
612
|
-
const m =
|
|
613
|
-
if (m.local = !0, m.modified = !1,
|
|
614
|
-
const
|
|
615
|
-
|
|
611
|
+
a.push(E);
|
|
612
|
+
const m = ae(E);
|
|
613
|
+
if (m.local = !0, m.modified = !1, T !== -1) {
|
|
614
|
+
const N = BigInt(I[T]);
|
|
615
|
+
t.cacheRowIdEntity(N, E);
|
|
616
616
|
}
|
|
617
617
|
});
|
|
618
|
-
}),
|
|
619
|
-
},
|
|
620
|
-
|
|
621
|
-
if (
|
|
622
|
-
const
|
|
623
|
-
|
|
618
|
+
}), a;
|
|
619
|
+
}, pn = (t, n, e) => {
|
|
620
|
+
e.forEach((s) => {
|
|
621
|
+
if (t.rxdb.entityManager.hasEntityRef(n, s)) {
|
|
622
|
+
const o = t.rxdb.entityManager.getEntityRef(n, s), a = ae(o);
|
|
623
|
+
a.local = !1, a.removed = !0, a.modified = !1;
|
|
624
624
|
}
|
|
625
625
|
});
|
|
626
626
|
};
|
|
627
|
-
class
|
|
628
|
-
constructor(n,
|
|
629
|
-
super(n.rxdb,
|
|
627
|
+
class hn extends Nt {
|
|
628
|
+
constructor(n, e) {
|
|
629
|
+
super(n.rxdb, e), this.adapter = n, this.metadata = V(e);
|
|
630
630
|
}
|
|
631
631
|
metadata;
|
|
632
632
|
async findByRowIds(n) {
|
|
633
|
-
const { sql:
|
|
634
|
-
return this.addQueryCache(
|
|
633
|
+
const { sql: e, params: s } = dn(this.metadata, n), o = await this.adapter.query(e, s);
|
|
634
|
+
return this.addQueryCache(o);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* 添加缓存
|
|
638
638
|
* @param sqliteSuccessResult
|
|
639
639
|
* @param forcedUpdate 强制刷新,在数据有的情况下也会更新数据,在修改数据的情况下需要
|
|
640
640
|
*/
|
|
641
|
-
addQueryCache(n,
|
|
642
|
-
return
|
|
641
|
+
addQueryCache(n, e = !1) {
|
|
642
|
+
return Ie(this.adapter, this.EntityType, n, e);
|
|
643
643
|
}
|
|
644
644
|
}
|
|
645
|
-
class
|
|
645
|
+
class ht extends hn {
|
|
646
646
|
async get(n) {
|
|
647
|
-
const
|
|
647
|
+
const e = {
|
|
648
648
|
where: {
|
|
649
649
|
combinator: "and",
|
|
650
650
|
rules: [{ field: "id", operator: "=", value: n }]
|
|
651
651
|
}
|
|
652
|
-
}, s = await this.findOne(
|
|
653
|
-
if (!s) throw new
|
|
652
|
+
}, s = await this.findOne(e);
|
|
653
|
+
if (!s) throw new ee(`Entity (${n}) not found`);
|
|
654
654
|
return s;
|
|
655
655
|
}
|
|
656
656
|
async findOne(n) {
|
|
657
657
|
return (await this.find({ ...n, limit: 1, offset: 0 }))[0];
|
|
658
658
|
}
|
|
659
659
|
async find(n) {
|
|
660
|
-
const { sql:
|
|
661
|
-
return this.addQueryCache(
|
|
660
|
+
const { sql: e, params: s } = De(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
|
|
661
|
+
return this.addQueryCache(o);
|
|
662
662
|
}
|
|
663
663
|
async count(n) {
|
|
664
|
-
const { sql:
|
|
665
|
-
return (await this.adapter.query(
|
|
664
|
+
const { sql: e, params: s } = fn(this.adapter, this.metadata, n);
|
|
665
|
+
return (await this.adapter.query(e, s)).results[0].rows[0][0];
|
|
666
666
|
}
|
|
667
667
|
async create(n) {
|
|
668
|
-
const { sql:
|
|
669
|
-
return this.addQueryCache(r, !0), n;
|
|
670
|
-
}
|
|
671
|
-
async update(n, t) {
|
|
672
|
-
const { sql: s, params: r } = de(this.metadata, n, t, this.rxdb.context), o = await this.adapter.query(s, r);
|
|
668
|
+
const { sql: e, params: s } = pt(this.metadata, n, this.rxdb.context), o = await this.adapter.query(e, s);
|
|
673
669
|
return this.addQueryCache(o, !0), n;
|
|
674
670
|
}
|
|
671
|
+
async update(n, e) {
|
|
672
|
+
const { sql: s, params: o } = Pe(this.metadata, n, e, this.rxdb.context), a = await this.adapter.query(s, o);
|
|
673
|
+
return this.addQueryCache(a, !0), n;
|
|
674
|
+
}
|
|
675
675
|
async remove(n) {
|
|
676
|
-
const
|
|
677
|
-
|
|
676
|
+
const e = ae(n), s = () => {
|
|
677
|
+
e.origin = structuredClone({ ...n }), e.modified = !1, e.removed = !0;
|
|
678
678
|
};
|
|
679
|
-
if (
|
|
680
|
-
const { sql:
|
|
681
|
-
return await this.adapter.query(
|
|
679
|
+
if (e.local === !0) {
|
|
680
|
+
const { sql: a, params: d } = ln(this.metadata, n);
|
|
681
|
+
return await this.adapter.query(a, d), s(), n;
|
|
682
682
|
}
|
|
683
|
-
const
|
|
684
|
-
throw new
|
|
683
|
+
const o = V(n);
|
|
684
|
+
throw new ee(`Remove Error${o.name}(${n.id}) not saved local.`);
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
|
-
var
|
|
688
|
-
const
|
|
689
|
-
switch (
|
|
687
|
+
var ce = /* @__PURE__ */ ((t) => (t[t.SQLITE_DELETE = 9] = "SQLITE_DELETE", t[t.SQLITE_INSERT = 18] = "SQLITE_INSERT", t[t.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", t))(ce || {});
|
|
688
|
+
const mn = (t) => {
|
|
689
|
+
switch (t) {
|
|
690
690
|
case 18:
|
|
691
691
|
return "INSERT";
|
|
692
692
|
case 9:
|
|
@@ -694,10 +694,10 @@ const jt = (e) => {
|
|
|
694
694
|
case 23:
|
|
695
695
|
return "UPDATE";
|
|
696
696
|
}
|
|
697
|
-
},
|
|
697
|
+
}, yn = "sqlite", gn = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").then((t) => t.default), En = () => import("wa-sqlite/dist/wa-sqlite.mjs").then((t) => t.default), _n = [
|
|
698
698
|
{
|
|
699
699
|
name: "MemoryVFS",
|
|
700
|
-
vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((
|
|
700
|
+
vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((t) => t.MemoryVFS),
|
|
701
701
|
sync: !0,
|
|
702
702
|
async: !0,
|
|
703
703
|
worker: !0,
|
|
@@ -707,7 +707,7 @@ const jt = (e) => {
|
|
|
707
707
|
},
|
|
708
708
|
{
|
|
709
709
|
name: "MemoryAsyncVFS",
|
|
710
|
-
vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((
|
|
710
|
+
vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((t) => t.MemoryAsyncVFS),
|
|
711
711
|
sync: !1,
|
|
712
712
|
async: !0,
|
|
713
713
|
worker: !0,
|
|
@@ -717,7 +717,7 @@ const jt = (e) => {
|
|
|
717
717
|
},
|
|
718
718
|
{
|
|
719
719
|
name: "IDBBatchAtomicVFS",
|
|
720
|
-
vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((
|
|
720
|
+
vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((t) => t.IDBBatchAtomicVFS),
|
|
721
721
|
vfsOptions: { lockPolicy: "shared+hint" },
|
|
722
722
|
sync: !1,
|
|
723
723
|
async: !0,
|
|
@@ -728,7 +728,7 @@ const jt = (e) => {
|
|
|
728
728
|
},
|
|
729
729
|
{
|
|
730
730
|
name: "OPFSAdaptiveVFS",
|
|
731
|
-
vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((
|
|
731
|
+
vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((t) => t.OPFSAdaptiveVFS),
|
|
732
732
|
vfsOptions: { lockPolicy: "shared+hint" },
|
|
733
733
|
sync: !1,
|
|
734
734
|
async: !0,
|
|
@@ -739,7 +739,7 @@ const jt = (e) => {
|
|
|
739
739
|
},
|
|
740
740
|
{
|
|
741
741
|
name: "AccessHandlePoolVFS",
|
|
742
|
-
vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((
|
|
742
|
+
vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((t) => t.AccessHandlePoolVFS),
|
|
743
743
|
sync: !0,
|
|
744
744
|
async: !0,
|
|
745
745
|
worker: !0,
|
|
@@ -749,7 +749,7 @@ const jt = (e) => {
|
|
|
749
749
|
},
|
|
750
750
|
{
|
|
751
751
|
name: "OPFSAnyContextVFS",
|
|
752
|
-
vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((
|
|
752
|
+
vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((t) => t.OPFSAnyContextVFS),
|
|
753
753
|
vfsOptions: { lockPolicy: "shared+hint" },
|
|
754
754
|
sync: !1,
|
|
755
755
|
async: !0,
|
|
@@ -760,7 +760,7 @@ const jt = (e) => {
|
|
|
760
760
|
},
|
|
761
761
|
{
|
|
762
762
|
name: "OPFSCoopSyncVFS",
|
|
763
|
-
vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((
|
|
763
|
+
vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((t) => t.OPFSCoopSyncVFS),
|
|
764
764
|
sync: !0,
|
|
765
765
|
async: !0,
|
|
766
766
|
worker: !0,
|
|
@@ -770,7 +770,7 @@ const jt = (e) => {
|
|
|
770
770
|
},
|
|
771
771
|
{
|
|
772
772
|
name: "OPFSPermutedVFS",
|
|
773
|
-
vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((
|
|
773
|
+
vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((t) => t.OPFSPermutedVFS),
|
|
774
774
|
sync: !1,
|
|
775
775
|
async: !0,
|
|
776
776
|
worker: !0,
|
|
@@ -778,80 +778,80 @@ const jt = (e) => {
|
|
|
778
778
|
jsContext: !1,
|
|
779
779
|
multipleConnections: !0
|
|
780
780
|
}
|
|
781
|
-
],
|
|
782
|
-
const n =
|
|
783
|
-
if (!n) throw new
|
|
781
|
+
], mt = (t) => {
|
|
782
|
+
const n = _n.find((a) => a.name === t.vfs), { vfs: e, async: s, worker: o } = t;
|
|
783
|
+
if (!n) throw new ee(`vfs ${e} not found`);
|
|
784
784
|
if (s !== void 0) {
|
|
785
785
|
if (s && !n.async)
|
|
786
|
-
throw new
|
|
786
|
+
throw new ee(`vfs ${e} not support async: true`);
|
|
787
787
|
if (!s && !n.sync)
|
|
788
|
-
throw new
|
|
788
|
+
throw new ee(`vfs ${e} not support async: false`);
|
|
789
789
|
}
|
|
790
|
-
if (
|
|
791
|
-
if (!
|
|
790
|
+
if (o && !n.worker) throw new ee(`vfs ${e} not support worker`);
|
|
791
|
+
if (!o && !n.jsContext) throw new ee(`vfs ${e} only support worker`);
|
|
792
792
|
return n;
|
|
793
|
-
},
|
|
794
|
-
const n =
|
|
793
|
+
}, wn = async (t) => {
|
|
794
|
+
const n = mt(t), e = t.async ?? !0;
|
|
795
795
|
let s;
|
|
796
|
-
|
|
797
|
-
const [
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
return
|
|
796
|
+
e ? s = gn : s = En;
|
|
797
|
+
const [o, a] = await Promise.all([s(), n.vfsModule()]), d = {};
|
|
798
|
+
t.locateFile ? d.locateFile = t.locateFile : t.wasmPath && (d.locateFile = () => t.wasmPath);
|
|
799
|
+
const p = await o(d), f = jt(p), b = await a.create(t.vfs, p, n.vfsOptions);
|
|
800
|
+
return f.vfs_register(b, !0), f;
|
|
801
801
|
};
|
|
802
|
-
async function
|
|
803
|
-
const
|
|
804
|
-
let
|
|
805
|
-
const
|
|
806
|
-
sql:
|
|
807
|
-
results:
|
|
802
|
+
async function bn(t, n, e, s) {
|
|
803
|
+
const o = performance.now(), a = [];
|
|
804
|
+
let d = 0, p = s;
|
|
805
|
+
const f = {
|
|
806
|
+
sql: e,
|
|
807
|
+
results: a
|
|
808
808
|
};
|
|
809
|
-
for await (const
|
|
810
|
-
|
|
811
|
-
const
|
|
812
|
-
for (; await
|
|
813
|
-
const
|
|
814
|
-
|
|
809
|
+
for await (const b of t.statements(n, e)) {
|
|
810
|
+
p && (t.reset(b), t.bind_collection(b, p), p = void 0);
|
|
811
|
+
const A = [];
|
|
812
|
+
for (; await t.step(b) === Bt; ) {
|
|
813
|
+
const I = t.row(b);
|
|
814
|
+
A.push(I);
|
|
815
815
|
}
|
|
816
|
-
const
|
|
817
|
-
|
|
816
|
+
const T = t.column_names(b);
|
|
817
|
+
T.length && a.push({ columns: T, rows: A }), d += t.changes(n);
|
|
818
818
|
}
|
|
819
819
|
return {
|
|
820
|
-
...
|
|
821
|
-
rowsAffected:
|
|
822
|
-
elapsed: performance.now() -
|
|
820
|
+
...f,
|
|
821
|
+
rowsAffected: d,
|
|
822
|
+
elapsed: performance.now() - o
|
|
823
823
|
};
|
|
824
824
|
}
|
|
825
|
-
const
|
|
825
|
+
const Nn = {
|
|
826
826
|
BALANCED: 16
|
|
827
|
-
},
|
|
828
|
-
class
|
|
827
|
+
}, et = Nn.BALANCED, An = 50 * 1024, In = /* @__PURE__ */ new Set(["public$rxdb_change", "public$rxdb_branch", "public$rxdb_migration"]);
|
|
828
|
+
class Tn extends Lt {
|
|
829
829
|
#n;
|
|
830
830
|
#e;
|
|
831
|
-
#
|
|
831
|
+
#i = !1;
|
|
832
832
|
#o = !1;
|
|
833
833
|
#c;
|
|
834
|
-
#
|
|
834
|
+
#r = [];
|
|
835
835
|
#t;
|
|
836
|
-
#
|
|
836
|
+
#s = et;
|
|
837
837
|
/**
|
|
838
838
|
* 初始化数据库
|
|
839
839
|
*
|
|
840
840
|
* @param dbName - 数据库名称(不含 .sqlite 扩展名)
|
|
841
841
|
* @param options - 加载选项
|
|
842
842
|
*/
|
|
843
|
-
async init(n,
|
|
844
|
-
if (this.#
|
|
845
|
-
this.#
|
|
846
|
-
const s = await
|
|
847
|
-
this.#e = await s.open_v2(
|
|
848
|
-
const
|
|
843
|
+
async init(n, e) {
|
|
844
|
+
if (this.#i) return;
|
|
845
|
+
this.#i = !0, this.#c = new st(1);
|
|
846
|
+
const s = await wn(e), o = `${n}.sqlite`;
|
|
847
|
+
this.#e = await s.open_v2(o), this.#n = s, this.#l(s, this.#e), this.#s = e?.batchTimeout ?? et;
|
|
848
|
+
const a = e?.cacheSizeKb ?? An;
|
|
849
849
|
await this.execute(`
|
|
850
850
|
PRAGMA temp_store = memory;
|
|
851
851
|
PRAGMA foreign_keys = ON;
|
|
852
|
-
PRAGMA cache_size = -${
|
|
853
|
-
`), this.#n.update_hook(this.#e, (
|
|
854
|
-
!
|
|
852
|
+
PRAGMA cache_size = -${a};
|
|
853
|
+
`), this.#n.update_hook(this.#e, (d, p, f, b) => {
|
|
854
|
+
!p || !f || !In.has(f) || (this.#r.push({ type: d, dbName: p, tableName: f, rowId: b }), this.#a());
|
|
855
855
|
});
|
|
856
856
|
}
|
|
857
857
|
/**
|
|
@@ -861,7 +861,7 @@ class Wt extends Xe {
|
|
|
861
861
|
*/
|
|
862
862
|
async version() {
|
|
863
863
|
const n = await this.execute("SELECT sqlite_version()");
|
|
864
|
-
return
|
|
864
|
+
return Mt(n, "results[0].rows[0][0]");
|
|
865
865
|
}
|
|
866
866
|
/**
|
|
867
867
|
* 断开数据库连接
|
|
@@ -869,7 +869,7 @@ class Wt extends Xe {
|
|
|
869
869
|
* 等待所有待执行任务完成后关闭数据库连接
|
|
870
870
|
*/
|
|
871
871
|
async disconnect() {
|
|
872
|
-
this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#
|
|
872
|
+
this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#r.length = 0, this.#n.update_hook(this.#e, () => {
|
|
873
873
|
}), await this.#c.waitForAll(), await this.#n.close(this.#e);
|
|
874
874
|
}
|
|
875
875
|
/**
|
|
@@ -890,38 +890,38 @@ class Wt extends Xe {
|
|
|
890
890
|
* );
|
|
891
891
|
* ```
|
|
892
892
|
*/
|
|
893
|
-
async execute(n,
|
|
893
|
+
async execute(n, e) {
|
|
894
894
|
if (this.#o)
|
|
895
895
|
throw new Error("SqliteClient has been disconnected");
|
|
896
|
-
return this.#c.addTask(() =>
|
|
896
|
+
return this.#c.addTask(() => bn(this.#n, this.#e, n, e));
|
|
897
897
|
}
|
|
898
898
|
/**
|
|
899
899
|
* 调度批量发送
|
|
900
900
|
* 使用防抖机制合并连续的变更事件
|
|
901
901
|
*/
|
|
902
|
-
#
|
|
902
|
+
#a() {
|
|
903
903
|
this.#t && clearTimeout(this.#t), this.#t = setTimeout(() => {
|
|
904
|
-
this.#
|
|
905
|
-
}, this.#
|
|
904
|
+
this.#u(), this.#t = void 0;
|
|
905
|
+
}, this.#s);
|
|
906
906
|
}
|
|
907
907
|
/**
|
|
908
908
|
* 刷新待发送事件
|
|
909
909
|
* 将同类型、同表的事件合并后分发
|
|
910
910
|
*/
|
|
911
|
-
#
|
|
912
|
-
const n = Object.groupBy(this.#
|
|
913
|
-
for (const
|
|
914
|
-
if (!
|
|
915
|
-
const s =
|
|
911
|
+
#u() {
|
|
912
|
+
const n = Object.groupBy(this.#r, (e) => `${e.type}_${e.dbName}_${e.tableName}`);
|
|
913
|
+
for (const e of Object.values(n)) {
|
|
914
|
+
if (!e || e.length === 0) continue;
|
|
915
|
+
const s = e[0];
|
|
916
916
|
this.dispatchEvent(s.type, {
|
|
917
917
|
type: s.type,
|
|
918
918
|
dbName: s.dbName,
|
|
919
919
|
tableName: s.tableName,
|
|
920
|
-
rowIds:
|
|
920
|
+
rowIds: e.map((o) => o.rowId),
|
|
921
921
|
recordAt: /* @__PURE__ */ new Date()
|
|
922
922
|
});
|
|
923
923
|
}
|
|
924
|
-
this.#
|
|
924
|
+
this.#r.length = 0;
|
|
925
925
|
}
|
|
926
926
|
/**
|
|
927
927
|
* 注册自定义 SQL 函数
|
|
@@ -930,751 +930,1535 @@ class Wt extends Xe {
|
|
|
930
930
|
* - `regexp(pattern, text)` - 正则匹配
|
|
931
931
|
* - `regexp_replace(pattern, text, replacement[, flags])` - 正则替换
|
|
932
932
|
*/
|
|
933
|
-
#
|
|
934
|
-
|
|
933
|
+
#l(n, e) {
|
|
934
|
+
Sn(n, e), vn(n, e);
|
|
935
935
|
}
|
|
936
936
|
}
|
|
937
|
-
const
|
|
938
|
-
function
|
|
939
|
-
const
|
|
940
|
-
let s =
|
|
937
|
+
const ye = /* @__PURE__ */ new Map(), $n = 128;
|
|
938
|
+
function yt(t, n = "") {
|
|
939
|
+
const e = `${t}\0${n}`;
|
|
940
|
+
let s = ye.get(e);
|
|
941
941
|
if (!s) {
|
|
942
|
-
if (
|
|
943
|
-
s = new RegExp(
|
|
942
|
+
if (t.length > 1e3) throw new Error("regexp pattern too long");
|
|
943
|
+
s = new RegExp(t, n), ye.size >= $n && ye.clear(), ye.set(e, s);
|
|
944
944
|
}
|
|
945
945
|
return s;
|
|
946
946
|
}
|
|
947
|
-
function
|
|
948
|
-
|
|
947
|
+
function Sn(t, n) {
|
|
948
|
+
t.create_function(n, "regexp", 2, ot | it, 0, (e, s) => {
|
|
949
949
|
try {
|
|
950
|
-
const
|
|
951
|
-
|
|
950
|
+
const o = yt(t.value_text(s[0])), a = t.value_text(s[1]);
|
|
951
|
+
t.result(e, o.test(a) ? 1 : 0);
|
|
952
952
|
} catch {
|
|
953
|
-
|
|
953
|
+
t.result(e, 0);
|
|
954
954
|
}
|
|
955
955
|
});
|
|
956
956
|
}
|
|
957
|
-
function
|
|
958
|
-
|
|
957
|
+
function vn(t, n) {
|
|
958
|
+
t.create_function(n, "regexp_replace", -1, ot | it, 0, (e, s) => {
|
|
959
959
|
if (s.length < 3) {
|
|
960
|
-
|
|
960
|
+
t.result(e, "");
|
|
961
961
|
return;
|
|
962
962
|
}
|
|
963
963
|
try {
|
|
964
|
-
const
|
|
965
|
-
|
|
964
|
+
const o = t.value_text(s[0]), a = t.value_text(s[1]), d = t.value_text(s[2]), p = s.length > 3 ? t.value_text(s[3]) : "";
|
|
965
|
+
t.result(e, a.replace(yt(o, p), d));
|
|
966
966
|
} catch {
|
|
967
|
-
|
|
967
|
+
t.result(e, t.value_text(s[1]));
|
|
968
968
|
}
|
|
969
969
|
});
|
|
970
970
|
}
|
|
971
|
-
async function
|
|
972
|
-
const { vfs:
|
|
973
|
-
vfs:
|
|
971
|
+
async function Rn(t, n) {
|
|
972
|
+
const { vfs: e, async: s, worker: o, wasmPath: a, locateFile: d, workerInstance: p, sharedWorkerInstance: f, sharedWorker: b } = n, A = {
|
|
973
|
+
vfs: e,
|
|
974
974
|
async: s,
|
|
975
|
-
worker:
|
|
976
|
-
wasmPath:
|
|
977
|
-
locateFile:
|
|
975
|
+
worker: o,
|
|
976
|
+
wasmPath: a,
|
|
977
|
+
locateFile: d
|
|
978
978
|
};
|
|
979
|
-
|
|
980
|
-
let
|
|
981
|
-
return
|
|
979
|
+
mt(A);
|
|
980
|
+
let T;
|
|
981
|
+
return o && p ? T = Ge(p) : b && f ? T = Ge(f.port) : T = new Tn(), await T.init(t, A), T;
|
|
982
982
|
}
|
|
983
|
-
const
|
|
984
|
-
const s =
|
|
985
|
-
return s ? (
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
983
|
+
const Cn = (t, n) => n.map((e) => {
|
|
984
|
+
const s = t.rxdb.schemaManager.getEntityMetadata(e.entity, e.namespace);
|
|
985
|
+
return s ? (e.inversePatch && Object.keys(e.inversePatch).forEach((o) => {
|
|
986
|
+
const a = s.propertyMap.get(o);
|
|
987
|
+
a && (e.inversePatch[o] = ue(
|
|
988
|
+
e.inversePatch[o],
|
|
989
|
+
a
|
|
990
990
|
));
|
|
991
|
-
}),
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
991
|
+
}), e.patch && Object.keys(e.patch).forEach((o) => {
|
|
992
|
+
const a = s.propertyMap.get(o);
|
|
993
|
+
a && (e.patch[o] = ue(
|
|
994
|
+
e.patch[o],
|
|
995
|
+
a
|
|
996
996
|
));
|
|
997
|
-
})) : console.warn(`Entity metadata not found for ${
|
|
998
|
-
}),
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
1001
|
-
const s =
|
|
1002
|
-
(
|
|
1003
|
-
namespace:
|
|
1004
|
-
entity:
|
|
1005
|
-
type:
|
|
1006
|
-
id:
|
|
1007
|
-
patch:
|
|
997
|
+
})) : console.warn(`Entity metadata not found for ${e.namespace}.${e.entity}`), e;
|
|
998
|
+
}), Ln = (t, n) => {
|
|
999
|
+
const e = Object.groupBy(n, (s) => s.type);
|
|
1000
|
+
if (e.INSERT?.length) {
|
|
1001
|
+
const s = e.INSERT.map(
|
|
1002
|
+
(o) => ({
|
|
1003
|
+
namespace: o.namespace,
|
|
1004
|
+
entity: o.entity,
|
|
1005
|
+
type: o.type,
|
|
1006
|
+
id: o.entityId,
|
|
1007
|
+
patch: o.patch,
|
|
1008
1008
|
inversePatch: null,
|
|
1009
|
-
recordAt:
|
|
1009
|
+
recordAt: o.createdAt
|
|
1010
1010
|
})
|
|
1011
1011
|
);
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1014
|
-
if (
|
|
1015
|
-
const s =
|
|
1016
|
-
(
|
|
1017
|
-
namespace:
|
|
1018
|
-
entity:
|
|
1019
|
-
type:
|
|
1020
|
-
id:
|
|
1021
|
-
patch:
|
|
1022
|
-
inversePatch:
|
|
1023
|
-
recordAt:
|
|
1012
|
+
t.rxdb.dispatchEvent(new Ee(s));
|
|
1013
|
+
}
|
|
1014
|
+
if (e.UPDATE?.length) {
|
|
1015
|
+
const s = e.UPDATE.map(
|
|
1016
|
+
(o) => ({
|
|
1017
|
+
namespace: o.namespace,
|
|
1018
|
+
entity: o.entity,
|
|
1019
|
+
type: o.type,
|
|
1020
|
+
id: o.entityId,
|
|
1021
|
+
patch: o.patch,
|
|
1022
|
+
inversePatch: o.inversePatch,
|
|
1023
|
+
recordAt: o.createdAt
|
|
1024
1024
|
})
|
|
1025
1025
|
);
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
if (
|
|
1029
|
-
const s =
|
|
1030
|
-
(
|
|
1031
|
-
namespace:
|
|
1032
|
-
entity:
|
|
1033
|
-
type:
|
|
1034
|
-
id:
|
|
1026
|
+
t.rxdb.dispatchEvent(new Te(s));
|
|
1027
|
+
}
|
|
1028
|
+
if (e.DELETE?.length) {
|
|
1029
|
+
const s = e.DELETE.map(
|
|
1030
|
+
(o) => ({
|
|
1031
|
+
namespace: o.namespace,
|
|
1032
|
+
entity: o.entity,
|
|
1033
|
+
type: o.type,
|
|
1034
|
+
id: o.entityId,
|
|
1035
1035
|
patch: null,
|
|
1036
|
-
inversePatch:
|
|
1037
|
-
recordAt:
|
|
1036
|
+
inversePatch: o.inversePatch,
|
|
1037
|
+
recordAt: o.createdAt
|
|
1038
1038
|
})
|
|
1039
1039
|
);
|
|
1040
|
-
|
|
1040
|
+
t.rxdb.dispatchEvent(new qe(s));
|
|
1041
1041
|
}
|
|
1042
|
-
},
|
|
1043
|
-
const { tableName:
|
|
1044
|
-
if (!
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1042
|
+
}, Mn = (t, n) => {
|
|
1043
|
+
const { tableName: e } = n, [s, o] = Ut(e), a = t.rxdb.schemaManager.getEntityTypeByTableName(o, s);
|
|
1044
|
+
if (!a) return;
|
|
1045
|
+
const d = t.getRepository(a), p = V(a), f = V(pe);
|
|
1046
|
+
d.findByRowIds(n.rowIds).then((b) => {
|
|
1047
1047
|
try {
|
|
1048
|
-
let
|
|
1049
|
-
if (
|
|
1050
|
-
if (
|
|
1051
|
-
|
|
1052
|
-
const
|
|
1053
|
-
namespace:
|
|
1054
|
-
entity:
|
|
1055
|
-
type:
|
|
1056
|
-
id:
|
|
1057
|
-
patch: { ...
|
|
1048
|
+
let A = b;
|
|
1049
|
+
if (p === f) {
|
|
1050
|
+
if (A = Cn(t, b), n.type === ce.SQLITE_INSERT) {
|
|
1051
|
+
Ln(t, A);
|
|
1052
|
+
const T = A.map((I) => ({
|
|
1053
|
+
namespace: p.namespace,
|
|
1054
|
+
entity: p.name,
|
|
1055
|
+
type: I.type,
|
|
1056
|
+
id: I.id,
|
|
1057
|
+
patch: { ...I },
|
|
1058
1058
|
inversePatch: null,
|
|
1059
|
-
recordAt:
|
|
1059
|
+
recordAt: I.createdAt
|
|
1060
1060
|
}));
|
|
1061
|
-
|
|
1061
|
+
t.rxdb.dispatchEvent(new Ee(T));
|
|
1062
1062
|
}
|
|
1063
1063
|
} else {
|
|
1064
|
-
const
|
|
1065
|
-
const
|
|
1066
|
-
namespace:
|
|
1067
|
-
entity:
|
|
1068
|
-
type:
|
|
1069
|
-
id:
|
|
1070
|
-
recordAt:
|
|
1064
|
+
const T = mn(n.type), I = A.map((M) => {
|
|
1065
|
+
const E = {
|
|
1066
|
+
namespace: p.namespace,
|
|
1067
|
+
entity: p.name,
|
|
1068
|
+
type: T,
|
|
1069
|
+
id: M.id,
|
|
1070
|
+
recordAt: M.createdAt || /* @__PURE__ */ new Date()
|
|
1071
1071
|
};
|
|
1072
1072
|
switch (n.type) {
|
|
1073
|
-
case
|
|
1073
|
+
case ce.SQLITE_INSERT:
|
|
1074
1074
|
return {
|
|
1075
|
-
...
|
|
1076
|
-
patch: { ...
|
|
1075
|
+
...E,
|
|
1076
|
+
patch: { ...M },
|
|
1077
1077
|
inversePatch: null
|
|
1078
1078
|
};
|
|
1079
|
-
case
|
|
1079
|
+
case ce.SQLITE_DELETE:
|
|
1080
1080
|
return {
|
|
1081
|
-
...
|
|
1081
|
+
...E,
|
|
1082
1082
|
patch: null,
|
|
1083
|
-
inversePatch: { ...
|
|
1083
|
+
inversePatch: { ...M }
|
|
1084
1084
|
};
|
|
1085
|
-
case
|
|
1085
|
+
case ce.SQLITE_UPDATE:
|
|
1086
1086
|
return {
|
|
1087
|
-
...
|
|
1087
|
+
...E,
|
|
1088
1088
|
inversePatch: null,
|
|
1089
|
-
patch: { ...
|
|
1089
|
+
patch: { ...M }
|
|
1090
1090
|
};
|
|
1091
1091
|
}
|
|
1092
1092
|
});
|
|
1093
|
-
switch (
|
|
1093
|
+
switch (T) {
|
|
1094
1094
|
case "UPDATE":
|
|
1095
|
-
|
|
1096
|
-
new
|
|
1095
|
+
t.rxdb.dispatchEvent(
|
|
1096
|
+
new Te(I)
|
|
1097
1097
|
);
|
|
1098
1098
|
break;
|
|
1099
1099
|
case "DELETE":
|
|
1100
|
-
|
|
1101
|
-
new
|
|
1100
|
+
t.rxdb.dispatchEvent(
|
|
1101
|
+
new qe(I)
|
|
1102
1102
|
);
|
|
1103
1103
|
break;
|
|
1104
1104
|
case "INSERT":
|
|
1105
|
-
|
|
1106
|
-
new
|
|
1105
|
+
t.rxdb.dispatchEvent(
|
|
1106
|
+
new Ee(I)
|
|
1107
1107
|
);
|
|
1108
1108
|
break;
|
|
1109
1109
|
}
|
|
1110
1110
|
}
|
|
1111
|
-
} catch (
|
|
1112
|
-
console.error(`[rxdb-adapter-sqlite] Error processing ${
|
|
1111
|
+
} catch (A) {
|
|
1112
|
+
console.error(`[rxdb-adapter-sqlite] Error processing ${e} change event:`, A);
|
|
1113
1113
|
}
|
|
1114
|
-
}).catch((
|
|
1115
|
-
console.error(`[rxdb-adapter-sqlite] Failed to query ${
|
|
1114
|
+
}).catch((b) => {
|
|
1115
|
+
console.error(`[rxdb-adapter-sqlite] Failed to query ${e} change (rowIds: ${n.rowIds}):`, b);
|
|
1116
1116
|
});
|
|
1117
|
-
},
|
|
1118
|
-
const { isCount: s, isFindDescendants:
|
|
1119
|
-
let
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
let
|
|
1123
|
-
s ?
|
|
1124
|
-
const
|
|
1117
|
+
}, $e = (t, n, e) => {
|
|
1118
|
+
const { isCount: s, isFindDescendants: o, entityId: a, where: d } = e, p = !a, f = X(n), A = n.relationMap.get("parent").columnName;
|
|
1119
|
+
let T = "";
|
|
1120
|
+
const M = [`c.__level < ${e.level || 0}`, d && he(d, /* @__PURE__ */ new Map(), n, t)].filter(Boolean).join(" AND ");
|
|
1121
|
+
M && (T = `WHERE ${M}`);
|
|
1122
|
+
let E = "__children.*";
|
|
1123
|
+
s ? p ? E = "count(*)" : E = "count(*)-1" : e.hasChildren && (E += `, EXISTS(SELECT 1 FROM "${f}" __sub WHERE __sub."${A}" = __children.id) AS hasChildren`);
|
|
1124
|
+
const v = [];
|
|
1125
1125
|
let m;
|
|
1126
|
-
return
|
|
1127
|
-
SELECT *,rowid as ${
|
|
1128
|
-
FROM "${
|
|
1126
|
+
return p ? m = `"${A}" is null` : (m = "id = ?", v.push(a)), { sql: `WITH RECURSIVE __children AS (
|
|
1127
|
+
SELECT *,rowid as ${ie}, 0 AS __level
|
|
1128
|
+
FROM "${f}"
|
|
1129
1129
|
WHERE ${m}
|
|
1130
1130
|
UNION ALL
|
|
1131
|
-
SELECT children.*,children.rowid as ${
|
|
1132
|
-
FROM "${
|
|
1133
|
-
JOIN __children c ON ${
|
|
1134
|
-
${
|
|
1131
|
+
SELECT children.*,children.rowid as ${ie}, c.__level + 1 AS __level
|
|
1132
|
+
FROM "${f}" children
|
|
1133
|
+
JOIN __children c ON ${o ? `children."${A}" = c.id` : `children.id = c."${A}"`}
|
|
1134
|
+
${T}
|
|
1135
1135
|
)
|
|
1136
1136
|
|
|
1137
|
-
SELECT ${
|
|
1138
|
-
},
|
|
1139
|
-
...
|
|
1137
|
+
SELECT ${E} FROM __children ORDER BY __level, id;`, params: v };
|
|
1138
|
+
}, On = (t, n, e) => $e(t, n, {
|
|
1139
|
+
...e,
|
|
1140
1140
|
isFindDescendants: !0,
|
|
1141
1141
|
hasChildren: n.features?.tree?.hasChildren
|
|
1142
|
-
}),
|
|
1143
|
-
...
|
|
1142
|
+
}), xn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !0, isCount: !0 }), jn = (t, n, e) => $e(t, n, {
|
|
1143
|
+
...e,
|
|
1144
1144
|
isFindDescendants: !1,
|
|
1145
1145
|
hasChildren: n.features?.tree?.hasChildren
|
|
1146
|
-
}),
|
|
1147
|
-
class
|
|
1146
|
+
}), Bn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !1, isCount: !0 });
|
|
1147
|
+
class Dn extends ht {
|
|
1148
1148
|
async findDescendants(n) {
|
|
1149
|
-
const { sql:
|
|
1150
|
-
return this.addQueryCache(
|
|
1149
|
+
const { sql: e, params: s } = On(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
|
|
1150
|
+
return this.addQueryCache(o, !0);
|
|
1151
1151
|
}
|
|
1152
1152
|
async countDescendants(n) {
|
|
1153
|
-
const { sql:
|
|
1154
|
-
return (await this.adapter.query(
|
|
1153
|
+
const { sql: e, params: s } = xn(this.adapter, this.metadata, n);
|
|
1154
|
+
return (await this.adapter.query(e, s)).results[0].rows[0][0];
|
|
1155
1155
|
}
|
|
1156
1156
|
async findAncestors(n) {
|
|
1157
|
-
const { sql:
|
|
1158
|
-
return this.addQueryCache(
|
|
1157
|
+
const { sql: e, params: s } = jn(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
|
|
1158
|
+
return this.addQueryCache(o);
|
|
1159
1159
|
}
|
|
1160
1160
|
async countAncestors(n) {
|
|
1161
|
-
const { sql:
|
|
1162
|
-
return (await this.adapter.query(
|
|
1161
|
+
const { sql: e, params: s } = Bn(this.adapter, this.metadata, n);
|
|
1162
|
+
return (await this.adapter.query(e, s)).results[0].rows[0][0];
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
return
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1165
|
+
function qn(t) {
|
|
1166
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
1167
|
+
}
|
|
1168
|
+
function ge(t) {
|
|
1169
|
+
throw new Error('Could not dynamically require "' + t + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
1170
|
+
}
|
|
1171
|
+
var xe = { exports: {} }, tt;
|
|
1172
|
+
function kn() {
|
|
1173
|
+
return tt || (tt = 1, (function(t, n) {
|
|
1174
|
+
(function(e) {
|
|
1175
|
+
t.exports = e();
|
|
1176
|
+
})(function() {
|
|
1177
|
+
return (function e(s, o, a) {
|
|
1178
|
+
function d(b, A) {
|
|
1179
|
+
if (!o[b]) {
|
|
1180
|
+
if (!s[b]) {
|
|
1181
|
+
var T = typeof ge == "function" && ge;
|
|
1182
|
+
if (!A && T) return T(b, !0);
|
|
1183
|
+
if (p) return p(b, !0);
|
|
1184
|
+
throw new Error("Cannot find module '" + b + "'");
|
|
1185
|
+
}
|
|
1186
|
+
A = o[b] = { exports: {} }, s[b][0].call(A.exports, function(I) {
|
|
1187
|
+
var M = s[b][1][I];
|
|
1188
|
+
return d(M || I);
|
|
1189
|
+
}, A, A.exports, e, s, o, a);
|
|
1190
|
+
}
|
|
1191
|
+
return o[b].exports;
|
|
1192
|
+
}
|
|
1193
|
+
for (var p = typeof ge == "function" && ge, f = 0; f < a.length; f++) d(a[f]);
|
|
1194
|
+
return d;
|
|
1195
|
+
})({ 1: [function(e, s, o) {
|
|
1196
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1197
|
+
var E = e("crypto");
|
|
1198
|
+
function v(y, w) {
|
|
1199
|
+
w = S(y, w);
|
|
1200
|
+
var c;
|
|
1201
|
+
return (c = w.algorithm !== "passthrough" ? E.createHash(w.algorithm) : new B()).write === void 0 && (c.write = c.update, c.end = c.update), R(w, c).dispatch(y), c.update || c.end(""), c.digest ? c.digest(w.encoding === "buffer" ? void 0 : w.encoding) : (y = c.read(), w.encoding !== "buffer" ? y.toString(w.encoding) : y);
|
|
1202
|
+
}
|
|
1203
|
+
(o = s.exports = v).sha1 = function(y) {
|
|
1204
|
+
return v(y);
|
|
1205
|
+
}, o.keys = function(y) {
|
|
1206
|
+
return v(y, { excludeValues: !0, algorithm: "sha1", encoding: "hex" });
|
|
1207
|
+
}, o.MD5 = function(y) {
|
|
1208
|
+
return v(y, { algorithm: "md5", encoding: "hex" });
|
|
1209
|
+
}, o.keysMD5 = function(y) {
|
|
1210
|
+
return v(y, { algorithm: "md5", encoding: "hex", excludeValues: !0 });
|
|
1211
|
+
};
|
|
1212
|
+
var m = E.getHashes ? E.getHashes().slice() : ["sha1", "md5"], N = (m.push("passthrough"), ["buffer", "hex", "binary", "base64"]);
|
|
1213
|
+
function S(y, w) {
|
|
1214
|
+
var c = {};
|
|
1215
|
+
if (c.algorithm = (w = w || {}).algorithm || "sha1", c.encoding = w.encoding || "hex", c.excludeValues = !!w.excludeValues, c.algorithm = c.algorithm.toLowerCase(), c.encoding = c.encoding.toLowerCase(), c.ignoreUnknown = w.ignoreUnknown === !0, c.respectType = w.respectType !== !1, c.respectFunctionNames = w.respectFunctionNames !== !1, c.respectFunctionProperties = w.respectFunctionProperties !== !1, c.unorderedArrays = w.unorderedArrays === !0, c.unorderedSets = w.unorderedSets !== !1, c.unorderedObjects = w.unorderedObjects !== !1, c.replacer = w.replacer || void 0, c.excludeKeys = w.excludeKeys || void 0, y === void 0) throw new Error("Object argument required.");
|
|
1216
|
+
for (var u = 0; u < m.length; ++u) m[u].toLowerCase() === c.algorithm.toLowerCase() && (c.algorithm = m[u]);
|
|
1217
|
+
if (m.indexOf(c.algorithm) === -1) throw new Error('Algorithm "' + c.algorithm + '" not supported. supported values: ' + m.join(", "));
|
|
1218
|
+
if (N.indexOf(c.encoding) === -1 && c.algorithm !== "passthrough") throw new Error('Encoding "' + c.encoding + '" not supported. supported values: ' + N.join(", "));
|
|
1219
|
+
return c;
|
|
1220
|
+
}
|
|
1221
|
+
function $(y) {
|
|
1222
|
+
if (typeof y == "function") return /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(y)) != null;
|
|
1223
|
+
}
|
|
1224
|
+
function R(y, w, c) {
|
|
1225
|
+
c = c || [];
|
|
1226
|
+
function u(i) {
|
|
1227
|
+
return w.update ? w.update(i, "utf8") : w.write(i, "utf8");
|
|
1228
|
+
}
|
|
1229
|
+
return { dispatch: function(i) {
|
|
1230
|
+
return this["_" + ((i = y.replacer ? y.replacer(i) : i) === null ? "null" : typeof i)](i);
|
|
1231
|
+
}, _object: function(i) {
|
|
1232
|
+
var g, _ = Object.prototype.toString.call(i), k = /\[object (.*)\]/i.exec(_);
|
|
1233
|
+
if (k = (k = k ? k[1] : "unknown:[" + _ + "]").toLowerCase(), 0 <= (_ = c.indexOf(i))) return this.dispatch("[CIRCULAR:" + _ + "]");
|
|
1234
|
+
if (c.push(i), p !== void 0 && p.isBuffer && p.isBuffer(i)) return u("buffer:"), u(i);
|
|
1235
|
+
if (k === "object" || k === "function" || k === "asyncfunction") return _ = Object.keys(i), y.unorderedObjects && (_ = _.sort()), y.respectType === !1 || $(i) || _.splice(0, 0, "prototype", "__proto__", "constructor"), y.excludeKeys && (_ = _.filter(function(q) {
|
|
1236
|
+
return !y.excludeKeys(q);
|
|
1237
|
+
})), u("object:" + _.length + ":"), g = this, _.forEach(function(q) {
|
|
1238
|
+
g.dispatch(q), u(":"), y.excludeValues || g.dispatch(i[q]), u(",");
|
|
1239
|
+
});
|
|
1240
|
+
if (!this["_" + k]) {
|
|
1241
|
+
if (y.ignoreUnknown) return u("[" + k + "]");
|
|
1242
|
+
throw new Error('Unknown object type "' + k + '"');
|
|
1243
|
+
}
|
|
1244
|
+
this["_" + k](i);
|
|
1245
|
+
}, _array: function(i, q) {
|
|
1246
|
+
q = q !== void 0 ? q : y.unorderedArrays !== !1;
|
|
1247
|
+
var _ = this;
|
|
1248
|
+
if (u("array:" + i.length + ":"), !q || i.length <= 1) return i.forEach(function(U) {
|
|
1249
|
+
return _.dispatch(U);
|
|
1250
|
+
});
|
|
1251
|
+
var k = [], q = i.map(function(U) {
|
|
1252
|
+
var j = new B(), W = c.slice();
|
|
1253
|
+
return R(y, j, W).dispatch(U), k = k.concat(W.slice(c.length)), j.read().toString();
|
|
1254
|
+
});
|
|
1255
|
+
return c = c.concat(k), q.sort(), this._array(q, !1);
|
|
1256
|
+
}, _date: function(i) {
|
|
1257
|
+
return u("date:" + i.toJSON());
|
|
1258
|
+
}, _symbol: function(i) {
|
|
1259
|
+
return u("symbol:" + i.toString());
|
|
1260
|
+
}, _error: function(i) {
|
|
1261
|
+
return u("error:" + i.toString());
|
|
1262
|
+
}, _boolean: function(i) {
|
|
1263
|
+
return u("bool:" + i.toString());
|
|
1264
|
+
}, _string: function(i) {
|
|
1265
|
+
u("string:" + i.length + ":"), u(i.toString());
|
|
1266
|
+
}, _function: function(i) {
|
|
1267
|
+
u("fn:"), $(i) ? this.dispatch("[native]") : this.dispatch(i.toString()), y.respectFunctionNames !== !1 && this.dispatch("function-name:" + String(i.name)), y.respectFunctionProperties && this._object(i);
|
|
1268
|
+
}, _number: function(i) {
|
|
1269
|
+
return u("number:" + i.toString());
|
|
1270
|
+
}, _xml: function(i) {
|
|
1271
|
+
return u("xml:" + i.toString());
|
|
1272
|
+
}, _null: function() {
|
|
1273
|
+
return u("Null");
|
|
1274
|
+
}, _undefined: function() {
|
|
1275
|
+
return u("Undefined");
|
|
1276
|
+
}, _regexp: function(i) {
|
|
1277
|
+
return u("regex:" + i.toString());
|
|
1278
|
+
}, _uint8array: function(i) {
|
|
1279
|
+
return u("uint8array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1280
|
+
}, _uint8clampedarray: function(i) {
|
|
1281
|
+
return u("uint8clampedarray:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1282
|
+
}, _int8array: function(i) {
|
|
1283
|
+
return u("int8array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1284
|
+
}, _uint16array: function(i) {
|
|
1285
|
+
return u("uint16array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1286
|
+
}, _int16array: function(i) {
|
|
1287
|
+
return u("int16array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1288
|
+
}, _uint32array: function(i) {
|
|
1289
|
+
return u("uint32array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1290
|
+
}, _int32array: function(i) {
|
|
1291
|
+
return u("int32array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1292
|
+
}, _float32array: function(i) {
|
|
1293
|
+
return u("float32array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1294
|
+
}, _float64array: function(i) {
|
|
1295
|
+
return u("float64array:"), this.dispatch(Array.prototype.slice.call(i));
|
|
1296
|
+
}, _arraybuffer: function(i) {
|
|
1297
|
+
return u("arraybuffer:"), this.dispatch(new Uint8Array(i));
|
|
1298
|
+
}, _url: function(i) {
|
|
1299
|
+
return u("url:" + i.toString());
|
|
1300
|
+
}, _map: function(i) {
|
|
1301
|
+
return u("map:"), i = Array.from(i), this._array(i, y.unorderedSets !== !1);
|
|
1302
|
+
}, _set: function(i) {
|
|
1303
|
+
return u("set:"), i = Array.from(i), this._array(i, y.unorderedSets !== !1);
|
|
1304
|
+
}, _file: function(i) {
|
|
1305
|
+
return u("file:"), this.dispatch([i.name, i.size, i.type, i.lastModfied]);
|
|
1306
|
+
}, _blob: function() {
|
|
1307
|
+
if (y.ignoreUnknown) return u("[blob]");
|
|
1308
|
+
throw Error(`Hashing Blob objects is currently not supported
|
|
1309
|
+
(see https://github.com/puleos/object-hash/issues/26)
|
|
1310
|
+
Use "options.replacer" or "options.ignoreUnknown"
|
|
1311
|
+
`);
|
|
1312
|
+
}, _domwindow: function() {
|
|
1313
|
+
return u("domwindow");
|
|
1314
|
+
}, _bigint: function(i) {
|
|
1315
|
+
return u("bigint:" + i.toString());
|
|
1316
|
+
}, _process: function() {
|
|
1317
|
+
return u("process");
|
|
1318
|
+
}, _timer: function() {
|
|
1319
|
+
return u("timer");
|
|
1320
|
+
}, _pipe: function() {
|
|
1321
|
+
return u("pipe");
|
|
1322
|
+
}, _tcp: function() {
|
|
1323
|
+
return u("tcp");
|
|
1324
|
+
}, _udp: function() {
|
|
1325
|
+
return u("udp");
|
|
1326
|
+
}, _tty: function() {
|
|
1327
|
+
return u("tty");
|
|
1328
|
+
}, _statwatcher: function() {
|
|
1329
|
+
return u("statwatcher");
|
|
1330
|
+
}, _securecontext: function() {
|
|
1331
|
+
return u("securecontext");
|
|
1332
|
+
}, _connection: function() {
|
|
1333
|
+
return u("connection");
|
|
1334
|
+
}, _zlib: function() {
|
|
1335
|
+
return u("zlib");
|
|
1336
|
+
}, _context: function() {
|
|
1337
|
+
return u("context");
|
|
1338
|
+
}, _nodescript: function() {
|
|
1339
|
+
return u("nodescript");
|
|
1340
|
+
}, _httpparser: function() {
|
|
1341
|
+
return u("httpparser");
|
|
1342
|
+
}, _dataview: function() {
|
|
1343
|
+
return u("dataview");
|
|
1344
|
+
}, _signal: function() {
|
|
1345
|
+
return u("signal");
|
|
1346
|
+
}, _fsevent: function() {
|
|
1347
|
+
return u("fsevent");
|
|
1348
|
+
}, _tlswrap: function() {
|
|
1349
|
+
return u("tlswrap");
|
|
1350
|
+
} };
|
|
1351
|
+
}
|
|
1352
|
+
function B() {
|
|
1353
|
+
return { buf: "", write: function(y) {
|
|
1354
|
+
this.buf += y;
|
|
1355
|
+
}, end: function(y) {
|
|
1356
|
+
this.buf += y;
|
|
1357
|
+
}, read: function() {
|
|
1358
|
+
return this.buf;
|
|
1359
|
+
} };
|
|
1360
|
+
}
|
|
1361
|
+
o.writeToStream = function(y, w, c) {
|
|
1362
|
+
return c === void 0 && (c = w, w = {}), R(w = S(y, w), c).dispatch(y);
|
|
1363
|
+
};
|
|
1364
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/fake_9a5aa49d.js", "/");
|
|
1365
|
+
}, { buffer: 3, crypto: 5, lYpoI2: 11 }], 2: [function(e, s, o) {
|
|
1366
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1367
|
+
(function(E) {
|
|
1368
|
+
var v = typeof Uint8Array < "u" ? Uint8Array : Array, m = 43, N = 47, S = 48, $ = 97, R = 65, B = 45, y = 95;
|
|
1369
|
+
function w(c) {
|
|
1370
|
+
return c = c.charCodeAt(0), c === m || c === B ? 62 : c === N || c === y ? 63 : c < S ? -1 : c < S + 10 ? c - S + 26 + 26 : c < R + 26 ? c - R : c < $ + 26 ? c - $ + 26 : void 0;
|
|
1371
|
+
}
|
|
1372
|
+
E.toByteArray = function(c) {
|
|
1373
|
+
var u, i;
|
|
1374
|
+
if (0 < c.length % 4) throw new Error("Invalid string. Length must be a multiple of 4");
|
|
1375
|
+
var g = c.length, g = c.charAt(g - 2) === "=" ? 2 : c.charAt(g - 1) === "=" ? 1 : 0, _ = new v(3 * c.length / 4 - g), k = 0 < g ? c.length - 4 : c.length, q = 0;
|
|
1376
|
+
function U(j) {
|
|
1377
|
+
_[q++] = j;
|
|
1378
|
+
}
|
|
1379
|
+
for (u = 0; u < k; u += 4, 0) U((16711680 & (i = w(c.charAt(u)) << 18 | w(c.charAt(u + 1)) << 12 | w(c.charAt(u + 2)) << 6 | w(c.charAt(u + 3)))) >> 16), U((65280 & i) >> 8), U(255 & i);
|
|
1380
|
+
return g == 2 ? U(255 & (i = w(c.charAt(u)) << 2 | w(c.charAt(u + 1)) >> 4)) : g == 1 && (U((i = w(c.charAt(u)) << 10 | w(c.charAt(u + 1)) << 4 | w(c.charAt(u + 2)) >> 2) >> 8 & 255), U(255 & i)), _;
|
|
1381
|
+
}, E.fromByteArray = function(c) {
|
|
1382
|
+
var u, i, g, _, k = c.length % 3, q = "";
|
|
1383
|
+
function U(j) {
|
|
1384
|
+
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(j);
|
|
1385
|
+
}
|
|
1386
|
+
for (u = 0, g = c.length - k; u < g; u += 3) i = (c[u] << 16) + (c[u + 1] << 8) + c[u + 2], q += U((_ = i) >> 18 & 63) + U(_ >> 12 & 63) + U(_ >> 6 & 63) + U(63 & _);
|
|
1387
|
+
switch (k) {
|
|
1388
|
+
case 1:
|
|
1389
|
+
q = (q += U((i = c[c.length - 1]) >> 2)) + U(i << 4 & 63) + "==";
|
|
1390
|
+
break;
|
|
1391
|
+
case 2:
|
|
1392
|
+
q = (q = (q += U((i = (c[c.length - 2] << 8) + c[c.length - 1]) >> 10)) + U(i >> 4 & 63)) + U(i << 2 & 63) + "=";
|
|
1393
|
+
}
|
|
1394
|
+
return q;
|
|
1395
|
+
};
|
|
1396
|
+
})(o === void 0 ? this.base64js = {} : o);
|
|
1397
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1398
|
+
}, { buffer: 3, lYpoI2: 11 }], 3: [function(e, s, o) {
|
|
1399
|
+
(function(a, d, m, f, b, A, T, I, M) {
|
|
1400
|
+
var E = e("base64-js"), v = e("ieee754");
|
|
1401
|
+
function m(r, l, h) {
|
|
1402
|
+
if (!(this instanceof m)) return new m(r, l, h);
|
|
1403
|
+
var L, C, x, P, H = typeof r;
|
|
1404
|
+
if (l === "base64" && H == "string") for (r = (P = r).trim ? P.trim() : P.replace(/^\s+|\s+$/g, ""); r.length % 4 != 0; ) r += "=";
|
|
1405
|
+
if (H == "number") L = Z(r);
|
|
1406
|
+
else if (H == "string") L = m.byteLength(r, l);
|
|
1407
|
+
else {
|
|
1408
|
+
if (H != "object") throw new Error("First argument needs to be a number, array or string.");
|
|
1409
|
+
L = Z(r.length);
|
|
1410
|
+
}
|
|
1411
|
+
if (m._useTypedArrays ? C = m._augment(new Uint8Array(L)) : ((C = this).length = L, C._isBuffer = !0), m._useTypedArrays && typeof r.byteLength == "number") C._set(r);
|
|
1412
|
+
else if (K(P = r) || m.isBuffer(P) || P && typeof P == "object" && typeof P.length == "number") for (x = 0; x < L; x++) m.isBuffer(r) ? C[x] = r.readUInt8(x) : C[x] = r[x];
|
|
1413
|
+
else if (H == "string") C.write(r, 0, l);
|
|
1414
|
+
else if (H == "number" && !m._useTypedArrays && !h) for (x = 0; x < L; x++) C[x] = 0;
|
|
1415
|
+
return C;
|
|
1416
|
+
}
|
|
1417
|
+
function N(r, l, h, L) {
|
|
1418
|
+
return m._charsWritten = me((function(C) {
|
|
1419
|
+
for (var x = [], P = 0; P < C.length; P++) x.push(255 & C.charCodeAt(P));
|
|
1420
|
+
return x;
|
|
1421
|
+
})(l), r, h, L);
|
|
1422
|
+
}
|
|
1423
|
+
function S(r, l, h, L) {
|
|
1424
|
+
return m._charsWritten = me((function(C) {
|
|
1425
|
+
for (var x, P, H = [], J = 0; J < C.length; J++) P = C.charCodeAt(J), x = P >> 8, P = P % 256, H.push(P), H.push(x);
|
|
1426
|
+
return H;
|
|
1427
|
+
})(l), r, h, L);
|
|
1428
|
+
}
|
|
1429
|
+
function $(r, l, h) {
|
|
1430
|
+
var L = "";
|
|
1431
|
+
h = Math.min(r.length, h);
|
|
1432
|
+
for (var C = l; C < h; C++) L += String.fromCharCode(r[C]);
|
|
1433
|
+
return L;
|
|
1434
|
+
}
|
|
1435
|
+
function R(r, l, h, x) {
|
|
1436
|
+
x || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 1 < r.length, "Trying to read beyond buffer length"));
|
|
1437
|
+
var C, x = r.length;
|
|
1438
|
+
if (!(x <= l)) return h ? (C = r[l], l + 1 < x && (C |= r[l + 1] << 8)) : (C = r[l] << 8, l + 1 < x && (C |= r[l + 1])), C;
|
|
1439
|
+
}
|
|
1440
|
+
function B(r, l, h, x) {
|
|
1441
|
+
x || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 3 < r.length, "Trying to read beyond buffer length"));
|
|
1442
|
+
var C, x = r.length;
|
|
1443
|
+
if (!(x <= l)) return h ? (l + 2 < x && (C = r[l + 2] << 16), l + 1 < x && (C |= r[l + 1] << 8), C |= r[l], l + 3 < x && (C += r[l + 3] << 24 >>> 0)) : (l + 1 < x && (C = r[l + 1] << 16), l + 2 < x && (C |= r[l + 2] << 8), l + 3 < x && (C |= r[l + 3]), C += r[l] << 24 >>> 0), C;
|
|
1444
|
+
}
|
|
1445
|
+
function y(r, l, h, L) {
|
|
1446
|
+
if (L || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 1 < r.length, "Trying to read beyond buffer length")), !(r.length <= l)) return L = R(r, l, h, !0), 32768 & L ? -1 * (65535 - L + 1) : L;
|
|
1447
|
+
}
|
|
1448
|
+
function w(r, l, h, L) {
|
|
1449
|
+
if (L || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 3 < r.length, "Trying to read beyond buffer length")), !(r.length <= l)) return L = B(r, l, h, !0), 2147483648 & L ? -1 * (4294967295 - L + 1) : L;
|
|
1450
|
+
}
|
|
1451
|
+
function c(r, l, h, L) {
|
|
1452
|
+
return L || (O(typeof h == "boolean", "missing or invalid endian"), O(l + 3 < r.length, "Trying to read beyond buffer length")), v.read(r, l, h, 23, 4);
|
|
1453
|
+
}
|
|
1454
|
+
function u(r, l, h, L) {
|
|
1455
|
+
return L || (O(typeof h == "boolean", "missing or invalid endian"), O(l + 7 < r.length, "Trying to read beyond buffer length")), v.read(r, l, h, 52, 8);
|
|
1456
|
+
}
|
|
1457
|
+
function i(r, l, h, L, C) {
|
|
1458
|
+
if (C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 1 < r.length, "trying to write beyond buffer length"), Se(l, 65535)), C = r.length, !(C <= h)) for (var x = 0, P = Math.min(C - h, 2); x < P; x++) r[h + x] = (l & 255 << 8 * (L ? x : 1 - x)) >>> 8 * (L ? x : 1 - x);
|
|
1459
|
+
}
|
|
1460
|
+
function g(r, l, h, L, C) {
|
|
1461
|
+
if (C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "trying to write beyond buffer length"), Se(l, 4294967295)), C = r.length, !(C <= h)) for (var x = 0, P = Math.min(C - h, 4); x < P; x++) r[h + x] = l >>> 8 * (L ? x : 3 - x) & 255;
|
|
1462
|
+
}
|
|
1463
|
+
function _(r, l, h, L, C) {
|
|
1464
|
+
C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 1 < r.length, "Trying to write beyond buffer length"), ve(l, 32767, -32768)), r.length <= h || i(r, 0 <= l ? l : 65535 + l + 1, h, L, C);
|
|
1465
|
+
}
|
|
1466
|
+
function k(r, l, h, L, C) {
|
|
1467
|
+
C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "Trying to write beyond buffer length"), ve(l, 2147483647, -2147483648)), r.length <= h || g(r, 0 <= l ? l : 4294967295 + l + 1, h, L, C);
|
|
1468
|
+
}
|
|
1469
|
+
function q(r, l, h, L, C) {
|
|
1470
|
+
C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "Trying to write beyond buffer length"), He(l, 34028234663852886e22, -34028234663852886e22)), r.length <= h || v.write(r, l, h, L, 23, 4);
|
|
1471
|
+
}
|
|
1472
|
+
function U(r, l, h, L, C) {
|
|
1473
|
+
C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 7 < r.length, "Trying to write beyond buffer length"), He(l, 17976931348623157e292, -17976931348623157e292)), r.length <= h || v.write(r, l, h, L, 52, 8);
|
|
1474
|
+
}
|
|
1475
|
+
o.Buffer = m, o.SlowBuffer = m, o.INSPECT_MAX_BYTES = 50, m.poolSize = 8192, m._useTypedArrays = (function() {
|
|
1476
|
+
try {
|
|
1477
|
+
var r = new ArrayBuffer(0), l = new Uint8Array(r);
|
|
1478
|
+
return l.foo = function() {
|
|
1479
|
+
return 42;
|
|
1480
|
+
}, l.foo() === 42 && typeof l.subarray == "function";
|
|
1481
|
+
} catch {
|
|
1482
|
+
return !1;
|
|
1483
|
+
}
|
|
1484
|
+
})(), m.isEncoding = function(r) {
|
|
1485
|
+
switch (String(r).toLowerCase()) {
|
|
1486
|
+
case "hex":
|
|
1487
|
+
case "utf8":
|
|
1488
|
+
case "utf-8":
|
|
1489
|
+
case "ascii":
|
|
1490
|
+
case "binary":
|
|
1491
|
+
case "base64":
|
|
1492
|
+
case "raw":
|
|
1493
|
+
case "ucs2":
|
|
1494
|
+
case "ucs-2":
|
|
1495
|
+
case "utf16le":
|
|
1496
|
+
case "utf-16le":
|
|
1497
|
+
return !0;
|
|
1498
|
+
default:
|
|
1499
|
+
return !1;
|
|
1500
|
+
}
|
|
1501
|
+
}, m.isBuffer = function(r) {
|
|
1502
|
+
return !(r == null || !r._isBuffer);
|
|
1503
|
+
}, m.byteLength = function(r, l) {
|
|
1504
|
+
var h;
|
|
1505
|
+
switch (r += "", l || "utf8") {
|
|
1506
|
+
case "hex":
|
|
1507
|
+
h = r.length / 2;
|
|
1508
|
+
break;
|
|
1509
|
+
case "utf8":
|
|
1510
|
+
case "utf-8":
|
|
1511
|
+
h = oe(r).length;
|
|
1512
|
+
break;
|
|
1513
|
+
case "ascii":
|
|
1514
|
+
case "binary":
|
|
1515
|
+
case "raw":
|
|
1516
|
+
h = r.length;
|
|
1517
|
+
break;
|
|
1518
|
+
case "base64":
|
|
1519
|
+
h = We(r).length;
|
|
1520
|
+
break;
|
|
1521
|
+
case "ucs2":
|
|
1522
|
+
case "ucs-2":
|
|
1523
|
+
case "utf16le":
|
|
1524
|
+
case "utf-16le":
|
|
1525
|
+
h = 2 * r.length;
|
|
1526
|
+
break;
|
|
1527
|
+
default:
|
|
1528
|
+
throw new Error("Unknown encoding");
|
|
1529
|
+
}
|
|
1530
|
+
return h;
|
|
1531
|
+
}, m.concat = function(r, l) {
|
|
1532
|
+
if (O(K(r), `Usage: Buffer.concat(list, [totalLength])
|
|
1533
|
+
list should be an Array.`), r.length === 0) return new m(0);
|
|
1534
|
+
if (r.length === 1) return r[0];
|
|
1535
|
+
if (typeof l != "number") for (C = l = 0; C < r.length; C++) l += r[C].length;
|
|
1536
|
+
for (var h = new m(l), L = 0, C = 0; C < r.length; C++) {
|
|
1537
|
+
var x = r[C];
|
|
1538
|
+
x.copy(h, L), L += x.length;
|
|
1539
|
+
}
|
|
1540
|
+
return h;
|
|
1541
|
+
}, m.prototype.write = function(r, l, h, L) {
|
|
1542
|
+
isFinite(l) ? isFinite(h) || (L = h, h = void 0) : (J = L, L = l, l = h, h = J), l = Number(l) || 0;
|
|
1543
|
+
var C, x, P, H, J = this.length - l;
|
|
1544
|
+
switch ((!h || J < (h = Number(h))) && (h = J), L = String(L || "utf8").toLowerCase()) {
|
|
1545
|
+
case "hex":
|
|
1546
|
+
C = (function(se, ne, re, G) {
|
|
1547
|
+
re = Number(re) || 0;
|
|
1548
|
+
var Y = se.length - re;
|
|
1549
|
+
(!G || Y < (G = Number(G))) && (G = Y), O((Y = ne.length) % 2 == 0, "Invalid hex string"), Y / 2 < G && (G = Y / 2);
|
|
1550
|
+
for (var de = 0; de < G; de++) {
|
|
1551
|
+
var Ve = parseInt(ne.substr(2 * de, 2), 16);
|
|
1552
|
+
O(!isNaN(Ve), "Invalid hex string"), se[re + de] = Ve;
|
|
1553
|
+
}
|
|
1554
|
+
return m._charsWritten = 2 * de, de;
|
|
1555
|
+
})(this, r, l, h);
|
|
1556
|
+
break;
|
|
1557
|
+
case "utf8":
|
|
1558
|
+
case "utf-8":
|
|
1559
|
+
x = this, P = l, H = h, C = m._charsWritten = me(oe(r), x, P, H);
|
|
1560
|
+
break;
|
|
1561
|
+
case "ascii":
|
|
1562
|
+
case "binary":
|
|
1563
|
+
C = N(this, r, l, h);
|
|
1564
|
+
break;
|
|
1565
|
+
case "base64":
|
|
1566
|
+
x = this, P = l, H = h, C = m._charsWritten = me(We(r), x, P, H);
|
|
1567
|
+
break;
|
|
1568
|
+
case "ucs2":
|
|
1569
|
+
case "ucs-2":
|
|
1570
|
+
case "utf16le":
|
|
1571
|
+
case "utf-16le":
|
|
1572
|
+
C = S(this, r, l, h);
|
|
1573
|
+
break;
|
|
1574
|
+
default:
|
|
1575
|
+
throw new Error("Unknown encoding");
|
|
1576
|
+
}
|
|
1577
|
+
return C;
|
|
1578
|
+
}, m.prototype.toString = function(r, l, h) {
|
|
1579
|
+
var L, C, x, P, H = this;
|
|
1580
|
+
if (r = String(r || "utf8").toLowerCase(), l = Number(l) || 0, (h = h !== void 0 ? Number(h) : H.length) === l) return "";
|
|
1581
|
+
switch (r) {
|
|
1582
|
+
case "hex":
|
|
1583
|
+
L = (function(J, se, ne) {
|
|
1584
|
+
var re = J.length;
|
|
1585
|
+
(!se || se < 0) && (se = 0), (!ne || ne < 0 || re < ne) && (ne = re);
|
|
1586
|
+
for (var G = "", Y = se; Y < ne; Y++) G += F(J[Y]);
|
|
1587
|
+
return G;
|
|
1588
|
+
})(H, l, h);
|
|
1589
|
+
break;
|
|
1590
|
+
case "utf8":
|
|
1591
|
+
case "utf-8":
|
|
1592
|
+
L = (function(J, se, ne) {
|
|
1593
|
+
var re = "", G = "";
|
|
1594
|
+
ne = Math.min(J.length, ne);
|
|
1595
|
+
for (var Y = se; Y < ne; Y++) J[Y] <= 127 ? (re += Ke(G) + String.fromCharCode(J[Y]), G = "") : G += "%" + J[Y].toString(16);
|
|
1596
|
+
return re + Ke(G);
|
|
1597
|
+
})(H, l, h);
|
|
1598
|
+
break;
|
|
1599
|
+
case "ascii":
|
|
1600
|
+
case "binary":
|
|
1601
|
+
L = $(H, l, h);
|
|
1602
|
+
break;
|
|
1603
|
+
case "base64":
|
|
1604
|
+
C = H, P = h, L = (x = l) === 0 && P === C.length ? E.fromByteArray(C) : E.fromByteArray(C.slice(x, P));
|
|
1605
|
+
break;
|
|
1606
|
+
case "ucs2":
|
|
1607
|
+
case "ucs-2":
|
|
1608
|
+
case "utf16le":
|
|
1609
|
+
case "utf-16le":
|
|
1610
|
+
L = (function(J, se, ne) {
|
|
1611
|
+
for (var re = J.slice(se, ne), G = "", Y = 0; Y < re.length; Y += 2) G += String.fromCharCode(re[Y] + 256 * re[Y + 1]);
|
|
1612
|
+
return G;
|
|
1613
|
+
})(H, l, h);
|
|
1614
|
+
break;
|
|
1615
|
+
default:
|
|
1616
|
+
throw new Error("Unknown encoding");
|
|
1617
|
+
}
|
|
1618
|
+
return L;
|
|
1619
|
+
}, m.prototype.toJSON = function() {
|
|
1620
|
+
return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
|
|
1621
|
+
}, m.prototype.copy = function(r, l, h, L) {
|
|
1622
|
+
if (l = l || 0, (L = L || L === 0 ? L : this.length) !== (h = h || 0) && r.length !== 0 && this.length !== 0) {
|
|
1623
|
+
O(h <= L, "sourceEnd < sourceStart"), O(0 <= l && l < r.length, "targetStart out of bounds"), O(0 <= h && h < this.length, "sourceStart out of bounds"), O(0 <= L && L <= this.length, "sourceEnd out of bounds"), L > this.length && (L = this.length);
|
|
1624
|
+
var C = (L = r.length - l < L - h ? r.length - l + h : L) - h;
|
|
1625
|
+
if (C < 100 || !m._useTypedArrays) for (var x = 0; x < C; x++) r[x + l] = this[x + h];
|
|
1626
|
+
else r._set(this.subarray(h, h + C), l);
|
|
1627
|
+
}
|
|
1628
|
+
}, m.prototype.slice = function(r, l) {
|
|
1629
|
+
var h = this.length;
|
|
1630
|
+
if (r = W(r, h, 0), l = W(l, h, h), m._useTypedArrays) return m._augment(this.subarray(r, l));
|
|
1631
|
+
for (var L = l - r, C = new m(L, void 0, !0), x = 0; x < L; x++) C[x] = this[x + r];
|
|
1632
|
+
return C;
|
|
1633
|
+
}, m.prototype.get = function(r) {
|
|
1634
|
+
return console.log(".get() is deprecated. Access using array indexes instead."), this.readUInt8(r);
|
|
1635
|
+
}, m.prototype.set = function(r, l) {
|
|
1636
|
+
return console.log(".set() is deprecated. Access using array indexes instead."), this.writeUInt8(r, l);
|
|
1637
|
+
}, m.prototype.readUInt8 = function(r, l) {
|
|
1638
|
+
if (l || (O(r != null, "missing offset"), O(r < this.length, "Trying to read beyond buffer length")), !(r >= this.length)) return this[r];
|
|
1639
|
+
}, m.prototype.readUInt16LE = function(r, l) {
|
|
1640
|
+
return R(this, r, !0, l);
|
|
1641
|
+
}, m.prototype.readUInt16BE = function(r, l) {
|
|
1642
|
+
return R(this, r, !1, l);
|
|
1643
|
+
}, m.prototype.readUInt32LE = function(r, l) {
|
|
1644
|
+
return B(this, r, !0, l);
|
|
1645
|
+
}, m.prototype.readUInt32BE = function(r, l) {
|
|
1646
|
+
return B(this, r, !1, l);
|
|
1647
|
+
}, m.prototype.readInt8 = function(r, l) {
|
|
1648
|
+
if (l || (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];
|
|
1649
|
+
}, m.prototype.readInt16LE = function(r, l) {
|
|
1650
|
+
return y(this, r, !0, l);
|
|
1651
|
+
}, m.prototype.readInt16BE = function(r, l) {
|
|
1652
|
+
return y(this, r, !1, l);
|
|
1653
|
+
}, m.prototype.readInt32LE = function(r, l) {
|
|
1654
|
+
return w(this, r, !0, l);
|
|
1655
|
+
}, m.prototype.readInt32BE = function(r, l) {
|
|
1656
|
+
return w(this, r, !1, l);
|
|
1657
|
+
}, m.prototype.readFloatLE = function(r, l) {
|
|
1658
|
+
return c(this, r, !0, l);
|
|
1659
|
+
}, m.prototype.readFloatBE = function(r, l) {
|
|
1660
|
+
return c(this, r, !1, l);
|
|
1661
|
+
}, m.prototype.readDoubleLE = function(r, l) {
|
|
1662
|
+
return u(this, r, !0, l);
|
|
1663
|
+
}, m.prototype.readDoubleBE = function(r, l) {
|
|
1664
|
+
return u(this, r, !1, l);
|
|
1665
|
+
}, m.prototype.writeUInt8 = function(r, l, h) {
|
|
1666
|
+
h || (O(r != null, "missing value"), O(l != null, "missing offset"), O(l < this.length, "trying to write beyond buffer length"), Se(r, 255)), l >= this.length || (this[l] = r);
|
|
1667
|
+
}, m.prototype.writeUInt16LE = function(r, l, h) {
|
|
1668
|
+
i(this, r, l, !0, h);
|
|
1669
|
+
}, m.prototype.writeUInt16BE = function(r, l, h) {
|
|
1670
|
+
i(this, r, l, !1, h);
|
|
1671
|
+
}, m.prototype.writeUInt32LE = function(r, l, h) {
|
|
1672
|
+
g(this, r, l, !0, h);
|
|
1673
|
+
}, m.prototype.writeUInt32BE = function(r, l, h) {
|
|
1674
|
+
g(this, r, l, !1, h);
|
|
1675
|
+
}, m.prototype.writeInt8 = function(r, l, h) {
|
|
1676
|
+
h || (O(r != null, "missing value"), O(l != null, "missing offset"), O(l < this.length, "Trying to write beyond buffer length"), ve(r, 127, -128)), l >= this.length || (0 <= r ? this.writeUInt8(r, l, h) : this.writeUInt8(255 + r + 1, l, h));
|
|
1677
|
+
}, m.prototype.writeInt16LE = function(r, l, h) {
|
|
1678
|
+
_(this, r, l, !0, h);
|
|
1679
|
+
}, m.prototype.writeInt16BE = function(r, l, h) {
|
|
1680
|
+
_(this, r, l, !1, h);
|
|
1681
|
+
}, m.prototype.writeInt32LE = function(r, l, h) {
|
|
1682
|
+
k(this, r, l, !0, h);
|
|
1683
|
+
}, m.prototype.writeInt32BE = function(r, l, h) {
|
|
1684
|
+
k(this, r, l, !1, h);
|
|
1685
|
+
}, m.prototype.writeFloatLE = function(r, l, h) {
|
|
1686
|
+
q(this, r, l, !0, h);
|
|
1687
|
+
}, m.prototype.writeFloatBE = function(r, l, h) {
|
|
1688
|
+
q(this, r, l, !1, h);
|
|
1689
|
+
}, m.prototype.writeDoubleLE = function(r, l, h) {
|
|
1690
|
+
U(this, r, l, !0, h);
|
|
1691
|
+
}, m.prototype.writeDoubleBE = function(r, l, h) {
|
|
1692
|
+
U(this, r, l, !1, h);
|
|
1693
|
+
}, m.prototype.fill = function(r, l, h) {
|
|
1694
|
+
if (l = l || 0, h = h || this.length, O(typeof (r = typeof (r = r || 0) == "string" ? r.charCodeAt(0) : r) == "number" && !isNaN(r), "value is not a number"), O(l <= h, "end < start"), h !== l && this.length !== 0) {
|
|
1695
|
+
O(0 <= l && l < this.length, "start out of bounds"), O(0 <= h && h <= this.length, "end out of bounds");
|
|
1696
|
+
for (var L = l; L < h; L++) this[L] = r;
|
|
1697
|
+
}
|
|
1698
|
+
}, m.prototype.inspect = function() {
|
|
1699
|
+
for (var r = [], l = this.length, h = 0; h < l; h++) if (r[h] = F(this[h]), h === o.INSPECT_MAX_BYTES) {
|
|
1700
|
+
r[h + 1] = "...";
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1703
|
+
return "<Buffer " + r.join(" ") + ">";
|
|
1704
|
+
}, m.prototype.toArrayBuffer = function() {
|
|
1705
|
+
if (typeof Uint8Array > "u") throw new Error("Buffer.toArrayBuffer not supported in this browser");
|
|
1706
|
+
if (m._useTypedArrays) return new m(this).buffer;
|
|
1707
|
+
for (var r = new Uint8Array(this.length), l = 0, h = r.length; l < h; l += 1) r[l] = this[l];
|
|
1708
|
+
return r.buffer;
|
|
1709
|
+
};
|
|
1710
|
+
var j = m.prototype;
|
|
1711
|
+
function W(r, l, h) {
|
|
1712
|
+
return typeof r != "number" ? h : l <= (r = ~~r) ? l : 0 <= r || 0 <= (r += l) ? r : 0;
|
|
1713
|
+
}
|
|
1714
|
+
function Z(r) {
|
|
1715
|
+
return (r = ~~Math.ceil(+r)) < 0 ? 0 : r;
|
|
1716
|
+
}
|
|
1717
|
+
function K(r) {
|
|
1718
|
+
return (Array.isArray || function(l) {
|
|
1719
|
+
return Object.prototype.toString.call(l) === "[object Array]";
|
|
1720
|
+
})(r);
|
|
1721
|
+
}
|
|
1722
|
+
function F(r) {
|
|
1723
|
+
return r < 16 ? "0" + r.toString(16) : r.toString(16);
|
|
1724
|
+
}
|
|
1725
|
+
function oe(r) {
|
|
1726
|
+
for (var l = [], h = 0; h < r.length; h++) {
|
|
1727
|
+
var L = r.charCodeAt(h);
|
|
1728
|
+
if (L <= 127) l.push(r.charCodeAt(h));
|
|
1729
|
+
else for (var C = h, x = (55296 <= L && L <= 57343 && h++, encodeURIComponent(r.slice(C, h + 1)).substr(1).split("%")), P = 0; P < x.length; P++) l.push(parseInt(x[P], 16));
|
|
1730
|
+
}
|
|
1731
|
+
return l;
|
|
1732
|
+
}
|
|
1733
|
+
function We(r) {
|
|
1734
|
+
return E.toByteArray(r);
|
|
1735
|
+
}
|
|
1736
|
+
function me(r, l, h, L) {
|
|
1737
|
+
for (var C = 0; C < L && !(C + h >= l.length || C >= r.length); C++) l[C + h] = r[C];
|
|
1738
|
+
return C;
|
|
1739
|
+
}
|
|
1740
|
+
function Ke(r) {
|
|
1741
|
+
try {
|
|
1742
|
+
return decodeURIComponent(r);
|
|
1743
|
+
} catch {
|
|
1744
|
+
return "�";
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
function Se(r, l) {
|
|
1748
|
+
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 <= l, "value is larger than maximum value for type"), O(Math.floor(r) === r, "value has a fractional component");
|
|
1749
|
+
}
|
|
1750
|
+
function ve(r, l, h) {
|
|
1751
|
+
O(typeof r == "number", "cannot write a non-number as a number"), O(r <= l, "value larger than maximum allowed value"), O(h <= r, "value smaller than minimum allowed value"), O(Math.floor(r) === r, "value has a fractional component");
|
|
1752
|
+
}
|
|
1753
|
+
function He(r, l, h) {
|
|
1754
|
+
O(typeof r == "number", "cannot write a non-number as a number"), O(r <= l, "value larger than maximum allowed value"), O(h <= r, "value smaller than minimum allowed value");
|
|
1755
|
+
}
|
|
1756
|
+
function O(r, l) {
|
|
1757
|
+
if (!r) throw new Error(l || "Failed assertion");
|
|
1758
|
+
}
|
|
1759
|
+
m._augment = function(r) {
|
|
1760
|
+
return r._isBuffer = !0, r._get = r.get, r._set = r.set, r.get = j.get, r.set = j.set, r.write = j.write, r.toString = j.toString, r.toLocaleString = j.toString, r.toJSON = j.toJSON, r.copy = j.copy, r.slice = j.slice, r.readUInt8 = j.readUInt8, r.readUInt16LE = j.readUInt16LE, r.readUInt16BE = j.readUInt16BE, r.readUInt32LE = j.readUInt32LE, r.readUInt32BE = j.readUInt32BE, r.readInt8 = j.readInt8, r.readInt16LE = j.readInt16LE, r.readInt16BE = j.readInt16BE, r.readInt32LE = j.readInt32LE, r.readInt32BE = j.readInt32BE, r.readFloatLE = j.readFloatLE, r.readFloatBE = j.readFloatBE, r.readDoubleLE = j.readDoubleLE, r.readDoubleBE = j.readDoubleBE, r.writeUInt8 = j.writeUInt8, r.writeUInt16LE = j.writeUInt16LE, r.writeUInt16BE = j.writeUInt16BE, r.writeUInt32LE = j.writeUInt32LE, r.writeUInt32BE = j.writeUInt32BE, r.writeInt8 = j.writeInt8, r.writeInt16LE = j.writeInt16LE, r.writeInt16BE = j.writeInt16BE, r.writeInt32LE = j.writeInt32LE, r.writeInt32BE = j.writeInt32BE, r.writeFloatLE = j.writeFloatLE, r.writeFloatBE = j.writeFloatBE, r.writeDoubleLE = j.writeDoubleLE, r.writeDoubleBE = j.writeDoubleBE, r.fill = j.fill, r.inspect = j.inspect, r.toArrayBuffer = j.toArrayBuffer, r;
|
|
1761
|
+
};
|
|
1762
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1763
|
+
}, { "base64-js": 2, buffer: 3, ieee754: 10, lYpoI2: 11 }], 4: [function(e, s, o) {
|
|
1764
|
+
(function(a, d, E, f, b, A, T, I, M) {
|
|
1765
|
+
var E = e("buffer").Buffer, v = 4, m = new E(v);
|
|
1766
|
+
m.fill(0), s.exports = { hash: function(N, S, $, R) {
|
|
1767
|
+
for (var B = S((function(i, g) {
|
|
1768
|
+
i.length % v != 0 && (_ = i.length + (v - i.length % v), i = E.concat([i, m], _));
|
|
1769
|
+
for (var _, k = [], q = g ? i.readInt32BE : i.readInt32LE, U = 0; U < i.length; U += v) k.push(q.call(i, U));
|
|
1770
|
+
return k;
|
|
1771
|
+
})(N = E.isBuffer(N) ? N : new E(N), R), 8 * N.length), S = R, y = new E($), w = S ? y.writeInt32BE : y.writeInt32LE, c = 0; c < B.length; c++) w.call(y, B[c], 4 * c, !0);
|
|
1772
|
+
return y;
|
|
1773
|
+
} };
|
|
1774
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1775
|
+
}, { buffer: 3, lYpoI2: 11 }], 5: [function(e, s, o) {
|
|
1776
|
+
(function(a, d, E, f, b, A, T, I, M) {
|
|
1777
|
+
var E = e("buffer").Buffer, v = e("./sha"), m = e("./sha256"), N = e("./rng"), S = { sha1: v, sha256: m, md5: e("./md5") }, $ = 64, R = new E($);
|
|
1778
|
+
function B(i, g) {
|
|
1779
|
+
var _ = S[i = i || "sha1"], k = [];
|
|
1780
|
+
return _ || y("algorithm:", i, "is not yet supported"), { update: function(q) {
|
|
1781
|
+
return E.isBuffer(q) || (q = new E(q)), k.push(q), q.length, this;
|
|
1782
|
+
}, digest: function(q) {
|
|
1783
|
+
var U = E.concat(k), U = g ? (function(j, W, Z) {
|
|
1784
|
+
E.isBuffer(W) || (W = new E(W)), E.isBuffer(Z) || (Z = new E(Z)), W.length > $ ? W = j(W) : W.length < $ && (W = E.concat([W, R], $));
|
|
1785
|
+
for (var K = new E($), F = new E($), oe = 0; oe < $; oe++) K[oe] = 54 ^ W[oe], F[oe] = 92 ^ W[oe];
|
|
1786
|
+
return Z = j(E.concat([K, Z])), j(E.concat([F, Z]));
|
|
1787
|
+
})(_, g, U) : _(U);
|
|
1788
|
+
return k = null, q ? U.toString(q) : U;
|
|
1789
|
+
} };
|
|
1790
|
+
}
|
|
1791
|
+
function y() {
|
|
1792
|
+
var i = [].slice.call(arguments).join(" ");
|
|
1793
|
+
throw new Error([i, "we accept pull requests", "http://github.com/dominictarr/crypto-browserify"].join(`
|
|
1794
|
+
`));
|
|
1795
|
+
}
|
|
1796
|
+
R.fill(0), o.createHash = function(i) {
|
|
1797
|
+
return B(i);
|
|
1798
|
+
}, o.createHmac = B, o.randomBytes = function(i, g) {
|
|
1799
|
+
if (!g || !g.call) return new E(N(i));
|
|
1800
|
+
try {
|
|
1801
|
+
g.call(this, void 0, new E(N(i)));
|
|
1802
|
+
} catch (_) {
|
|
1803
|
+
g(_);
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
var w, c = ["createCredentials", "createCipher", "createCipheriv", "createDecipher", "createDecipheriv", "createSign", "createVerify", "createDiffieHellman", "pbkdf2"], u = function(i) {
|
|
1807
|
+
o[i] = function() {
|
|
1808
|
+
y("sorry,", i, "is not implemented yet");
|
|
1809
|
+
};
|
|
1810
|
+
};
|
|
1811
|
+
for (w in c) u(c[w]);
|
|
1812
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1813
|
+
}, { "./md5": 6, "./rng": 7, "./sha": 8, "./sha256": 9, buffer: 3, lYpoI2: 11 }], 6: [function(e, s, o) {
|
|
1814
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1815
|
+
var E = e("./helpers");
|
|
1816
|
+
function v(y, w) {
|
|
1817
|
+
y[w >> 5] |= 128 << w % 32, y[14 + (w + 64 >>> 9 << 4)] = w;
|
|
1818
|
+
for (var c = 1732584193, u = -271733879, i = -1732584194, g = 271733878, _ = 0; _ < y.length; _ += 16) {
|
|
1819
|
+
var k = c, q = u, U = i, j = g, c = N(c, u, i, g, y[_ + 0], 7, -680876936), g = N(g, c, u, i, y[_ + 1], 12, -389564586), i = N(i, g, c, u, y[_ + 2], 17, 606105819), u = N(u, i, g, c, y[_ + 3], 22, -1044525330);
|
|
1820
|
+
c = N(c, u, i, g, y[_ + 4], 7, -176418897), g = N(g, c, u, i, y[_ + 5], 12, 1200080426), i = N(i, g, c, u, y[_ + 6], 17, -1473231341), u = N(u, i, g, c, y[_ + 7], 22, -45705983), c = N(c, u, i, g, y[_ + 8], 7, 1770035416), g = N(g, c, u, i, y[_ + 9], 12, -1958414417), i = N(i, g, c, u, y[_ + 10], 17, -42063), u = N(u, i, g, c, y[_ + 11], 22, -1990404162), c = N(c, u, i, g, y[_ + 12], 7, 1804603682), g = N(g, c, u, i, y[_ + 13], 12, -40341101), i = N(i, g, c, u, y[_ + 14], 17, -1502002290), c = S(c, u = N(u, i, g, c, y[_ + 15], 22, 1236535329), i, g, y[_ + 1], 5, -165796510), g = S(g, c, u, i, y[_ + 6], 9, -1069501632), i = S(i, g, c, u, y[_ + 11], 14, 643717713), u = S(u, i, g, c, y[_ + 0], 20, -373897302), c = S(c, u, i, g, y[_ + 5], 5, -701558691), g = S(g, c, u, i, y[_ + 10], 9, 38016083), i = S(i, g, c, u, y[_ + 15], 14, -660478335), u = S(u, i, g, c, y[_ + 4], 20, -405537848), c = S(c, u, i, g, y[_ + 9], 5, 568446438), g = S(g, c, u, i, y[_ + 14], 9, -1019803690), i = S(i, g, c, u, y[_ + 3], 14, -187363961), u = S(u, i, g, c, y[_ + 8], 20, 1163531501), c = S(c, u, i, g, y[_ + 13], 5, -1444681467), g = S(g, c, u, i, y[_ + 2], 9, -51403784), i = S(i, g, c, u, y[_ + 7], 14, 1735328473), c = $(c, u = S(u, i, g, c, y[_ + 12], 20, -1926607734), i, g, y[_ + 5], 4, -378558), g = $(g, c, u, i, y[_ + 8], 11, -2022574463), i = $(i, g, c, u, y[_ + 11], 16, 1839030562), u = $(u, i, g, c, y[_ + 14], 23, -35309556), c = $(c, u, i, g, y[_ + 1], 4, -1530992060), g = $(g, c, u, i, y[_ + 4], 11, 1272893353), i = $(i, g, c, u, y[_ + 7], 16, -155497632), u = $(u, i, g, c, y[_ + 10], 23, -1094730640), c = $(c, u, i, g, y[_ + 13], 4, 681279174), g = $(g, c, u, i, y[_ + 0], 11, -358537222), i = $(i, g, c, u, y[_ + 3], 16, -722521979), u = $(u, i, g, c, y[_ + 6], 23, 76029189), c = $(c, u, i, g, y[_ + 9], 4, -640364487), g = $(g, c, u, i, y[_ + 12], 11, -421815835), i = $(i, g, c, u, y[_ + 15], 16, 530742520), c = R(c, u = $(u, i, g, c, y[_ + 2], 23, -995338651), i, g, y[_ + 0], 6, -198630844), g = R(g, c, u, i, y[_ + 7], 10, 1126891415), i = R(i, g, c, u, y[_ + 14], 15, -1416354905), u = R(u, i, g, c, y[_ + 5], 21, -57434055), c = R(c, u, i, g, y[_ + 12], 6, 1700485571), g = R(g, c, u, i, y[_ + 3], 10, -1894986606), i = R(i, g, c, u, y[_ + 10], 15, -1051523), u = R(u, i, g, c, y[_ + 1], 21, -2054922799), c = R(c, u, i, g, y[_ + 8], 6, 1873313359), g = R(g, c, u, i, y[_ + 15], 10, -30611744), i = R(i, g, c, u, y[_ + 6], 15, -1560198380), u = R(u, i, g, c, y[_ + 13], 21, 1309151649), c = R(c, u, i, g, y[_ + 4], 6, -145523070), g = R(g, c, u, i, y[_ + 11], 10, -1120210379), i = R(i, g, c, u, y[_ + 2], 15, 718787259), u = R(u, i, g, c, y[_ + 9], 21, -343485551), c = B(c, k), u = B(u, q), i = B(i, U), g = B(g, j);
|
|
1821
|
+
}
|
|
1822
|
+
return Array(c, u, i, g);
|
|
1823
|
+
}
|
|
1824
|
+
function m(y, w, c, u, i, g) {
|
|
1825
|
+
return B((w = B(B(w, y), B(u, g))) << i | w >>> 32 - i, c);
|
|
1826
|
+
}
|
|
1827
|
+
function N(y, w, c, u, i, g, _) {
|
|
1828
|
+
return m(w & c | ~w & u, y, w, i, g, _);
|
|
1829
|
+
}
|
|
1830
|
+
function S(y, w, c, u, i, g, _) {
|
|
1831
|
+
return m(w & u | c & ~u, y, w, i, g, _);
|
|
1832
|
+
}
|
|
1833
|
+
function $(y, w, c, u, i, g, _) {
|
|
1834
|
+
return m(w ^ c ^ u, y, w, i, g, _);
|
|
1835
|
+
}
|
|
1836
|
+
function R(y, w, c, u, i, g, _) {
|
|
1837
|
+
return m(c ^ (w | ~u), y, w, i, g, _);
|
|
1838
|
+
}
|
|
1839
|
+
function B(y, w) {
|
|
1840
|
+
var c = (65535 & y) + (65535 & w);
|
|
1841
|
+
return (y >> 16) + (w >> 16) + (c >> 16) << 16 | 65535 & c;
|
|
1842
|
+
}
|
|
1843
|
+
s.exports = function(y) {
|
|
1844
|
+
return E.hash(y, v, 16);
|
|
1845
|
+
};
|
|
1846
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1847
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 7: [function(e, s, o) {
|
|
1848
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1849
|
+
s.exports = function(E) {
|
|
1850
|
+
for (var v, m = new Array(E), N = 0; N < E; N++) (3 & N) == 0 && (v = 4294967296 * Math.random()), m[N] = v >>> ((3 & N) << 3) & 255;
|
|
1851
|
+
return m;
|
|
1852
|
+
};
|
|
1853
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1854
|
+
}, { buffer: 3, lYpoI2: 11 }], 8: [function(e, s, o) {
|
|
1855
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1856
|
+
var E = e("./helpers");
|
|
1857
|
+
function v(S, $) {
|
|
1858
|
+
S[$ >> 5] |= 128 << 24 - $ % 32, S[15 + ($ + 64 >> 9 << 4)] = $;
|
|
1859
|
+
for (var R, B, y, w = Array(80), c = 1732584193, u = -271733879, i = -1732584194, g = 271733878, _ = -1009589776, k = 0; k < S.length; k += 16) {
|
|
1860
|
+
for (var q = c, U = u, j = i, W = g, Z = _, K = 0; K < 80; K++) {
|
|
1861
|
+
w[K] = K < 16 ? S[k + K] : N(w[K - 3] ^ w[K - 8] ^ w[K - 14] ^ w[K - 16], 1);
|
|
1862
|
+
var F = m(m(N(c, 5), (F = u, B = i, y = g, (R = K) < 20 ? F & B | ~F & y : !(R < 40) && R < 60 ? F & B | F & y | B & y : F ^ B ^ y)), m(m(_, w[K]), (R = K) < 20 ? 1518500249 : R < 40 ? 1859775393 : R < 60 ? -1894007588 : -899497514)), _ = g, g = i, i = N(u, 30), u = c, c = F;
|
|
1863
|
+
}
|
|
1864
|
+
c = m(c, q), u = m(u, U), i = m(i, j), g = m(g, W), _ = m(_, Z);
|
|
1865
|
+
}
|
|
1866
|
+
return Array(c, u, i, g, _);
|
|
1867
|
+
}
|
|
1868
|
+
function m(S, $) {
|
|
1869
|
+
var R = (65535 & S) + (65535 & $);
|
|
1870
|
+
return (S >> 16) + ($ >> 16) + (R >> 16) << 16 | 65535 & R;
|
|
1871
|
+
}
|
|
1872
|
+
function N(S, $) {
|
|
1873
|
+
return S << $ | S >>> 32 - $;
|
|
1874
|
+
}
|
|
1875
|
+
s.exports = function(S) {
|
|
1876
|
+
return E.hash(S, v, 20, !0);
|
|
1877
|
+
};
|
|
1878
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1879
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 9: [function(e, s, o) {
|
|
1880
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1881
|
+
function E($, R) {
|
|
1882
|
+
var B = (65535 & $) + (65535 & R);
|
|
1883
|
+
return ($ >> 16) + (R >> 16) + (B >> 16) << 16 | 65535 & B;
|
|
1884
|
+
}
|
|
1885
|
+
function v($, R) {
|
|
1886
|
+
var B, y = 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), w = new Array(1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225), c = new Array(64);
|
|
1887
|
+
$[R >> 5] |= 128 << 24 - R % 32, $[15 + (R + 64 >> 9 << 4)] = R;
|
|
1888
|
+
for (var u, i, g = 0; g < $.length; g += 16) {
|
|
1889
|
+
for (var _ = w[0], k = w[1], q = w[2], U = w[3], j = w[4], W = w[5], Z = w[6], K = w[7], F = 0; F < 64; F++) c[F] = F < 16 ? $[F + g] : E(E(E((i = c[F - 2], N(i, 17) ^ N(i, 19) ^ S(i, 10)), c[F - 7]), (i = c[F - 15], N(i, 7) ^ N(i, 18) ^ S(i, 3))), c[F - 16]), B = E(E(E(E(K, N(i = j, 6) ^ N(i, 11) ^ N(i, 25)), j & W ^ ~j & Z), y[F]), c[F]), u = E(N(u = _, 2) ^ N(u, 13) ^ N(u, 22), _ & k ^ _ & q ^ k & q), K = Z, Z = W, W = j, j = E(U, B), U = q, q = k, k = _, _ = E(B, u);
|
|
1890
|
+
w[0] = E(_, w[0]), w[1] = E(k, w[1]), w[2] = E(q, w[2]), w[3] = E(U, w[3]), w[4] = E(j, w[4]), w[5] = E(W, w[5]), w[6] = E(Z, w[6]), w[7] = E(K, w[7]);
|
|
1891
|
+
}
|
|
1892
|
+
return w;
|
|
1893
|
+
}
|
|
1894
|
+
var m = e("./helpers"), N = function($, R) {
|
|
1895
|
+
return $ >>> R | $ << 32 - R;
|
|
1896
|
+
}, S = function($, R) {
|
|
1897
|
+
return $ >>> R;
|
|
1898
|
+
};
|
|
1899
|
+
s.exports = function($) {
|
|
1900
|
+
return m.hash($, v, 32, !0);
|
|
1901
|
+
};
|
|
1902
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1903
|
+
}, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 10: [function(e, s, o) {
|
|
1904
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1905
|
+
o.read = function(E, v, m, N, g) {
|
|
1906
|
+
var $, R, B = 8 * g - N - 1, y = (1 << B) - 1, w = y >> 1, c = -7, u = m ? g - 1 : 0, i = m ? -1 : 1, g = E[v + u];
|
|
1907
|
+
for (u += i, $ = g & (1 << -c) - 1, g >>= -c, c += B; 0 < c; $ = 256 * $ + E[v + u], u += i, c -= 8) ;
|
|
1908
|
+
for (R = $ & (1 << -c) - 1, $ >>= -c, c += N; 0 < c; R = 256 * R + E[v + u], u += i, c -= 8) ;
|
|
1909
|
+
if ($ === 0) $ = 1 - w;
|
|
1910
|
+
else {
|
|
1911
|
+
if ($ === y) return R ? NaN : 1 / 0 * (g ? -1 : 1);
|
|
1912
|
+
R += Math.pow(2, N), $ -= w;
|
|
1913
|
+
}
|
|
1914
|
+
return (g ? -1 : 1) * R * Math.pow(2, $ - N);
|
|
1915
|
+
}, o.write = function(E, v, m, N, S, _) {
|
|
1916
|
+
var R, B, y = 8 * _ - S - 1, w = (1 << y) - 1, c = w >> 1, u = S === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, i = N ? 0 : _ - 1, g = N ? 1 : -1, _ = v < 0 || v === 0 && 1 / v < 0 ? 1 : 0;
|
|
1917
|
+
for (v = Math.abs(v), isNaN(v) || v === 1 / 0 ? (B = isNaN(v) ? 1 : 0, R = w) : (R = Math.floor(Math.log(v) / Math.LN2), v * (N = Math.pow(2, -R)) < 1 && (R--, N *= 2), 2 <= (v += 1 <= R + c ? u / N : u * Math.pow(2, 1 - c)) * N && (R++, N /= 2), w <= R + c ? (B = 0, R = w) : 1 <= R + c ? (B = (v * N - 1) * Math.pow(2, S), R += c) : (B = v * Math.pow(2, c - 1) * Math.pow(2, S), R = 0)); 8 <= S; E[m + i] = 255 & B, i += g, B /= 256, S -= 8) ;
|
|
1918
|
+
for (R = R << S | B, y += S; 0 < y; E[m + i] = 255 & R, i += g, R /= 256, y -= 8) ;
|
|
1919
|
+
E[m + i - g] |= 128 * _;
|
|
1920
|
+
};
|
|
1921
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1922
|
+
}, { buffer: 3, lYpoI2: 11 }], 11: [function(e, s, o) {
|
|
1923
|
+
(function(a, d, p, f, b, A, T, I, M) {
|
|
1924
|
+
var E, v, m;
|
|
1925
|
+
function N() {
|
|
1926
|
+
}
|
|
1927
|
+
(a = s.exports = {}).nextTick = (v = typeof window < "u" && window.setImmediate, m = typeof window < "u" && window.postMessage && window.addEventListener, v ? function(S) {
|
|
1928
|
+
return window.setImmediate(S);
|
|
1929
|
+
} : m ? (E = [], window.addEventListener("message", function(S) {
|
|
1930
|
+
var $ = S.source;
|
|
1931
|
+
$ !== window && $ !== null || S.data !== "process-tick" || (S.stopPropagation(), 0 < E.length && E.shift()());
|
|
1932
|
+
}, !0), function(S) {
|
|
1933
|
+
E.push(S), window.postMessage("process-tick", "*");
|
|
1934
|
+
}) : function(S) {
|
|
1935
|
+
setTimeout(S, 0);
|
|
1936
|
+
}), a.title = "browser", a.browser = !0, a.env = {}, a.argv = [], a.on = N, a.addListener = N, a.once = N, a.off = N, a.removeListener = N, a.removeAllListeners = N, a.emit = N, a.binding = function(S) {
|
|
1937
|
+
throw new Error("process.binding is not supported");
|
|
1938
|
+
}, a.cwd = function() {
|
|
1939
|
+
return "/";
|
|
1940
|
+
}, a.chdir = function(S) {
|
|
1941
|
+
throw new Error("process.chdir is not supported");
|
|
1942
|
+
};
|
|
1943
|
+
}).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
|
|
1944
|
+
}, { buffer: 3, lYpoI2: 11 }] }, {}, [1])(1);
|
|
1945
|
+
});
|
|
1946
|
+
})(xe)), xe.exports;
|
|
1947
|
+
}
|
|
1948
|
+
var Un = kn();
|
|
1949
|
+
const Pn = /* @__PURE__ */ qn(Un), Fn = (t, n) => {
|
|
1950
|
+
const e = X(t), s = n.map((o) => te(o.id)).join(",");
|
|
1951
|
+
return `DELETE FROM "${e}" WHERE id in (${s});`;
|
|
1952
|
+
}, gt = (t, n, e) => {
|
|
1953
|
+
const s = X(t), o = e?.userId && t.propertyMap.has("createdBy"), a = e?.userId && t.propertyMap.has("updatedBy"), d = t.propertyMap.has("createdAt"), p = t.propertyMap.has("updatedAt"), f = /* @__PURE__ */ new Date(), b = [
|
|
1954
|
+
...Array.from(t.propertyMap.values()).map((M) => M.columnName),
|
|
1955
|
+
...t.foreignKeyColumnNames || t.foreignKeyNames
|
|
1956
|
+
], A = [], T = [];
|
|
1957
|
+
return n.forEach((M) => {
|
|
1958
|
+
const E = at(t, M);
|
|
1959
|
+
o && (E.createdBy = e.userId), a && (E.updatedBy = e.userId), d && E.createdAt === void 0 && (E.createdAt = f), p && E.updatedAt === void 0 && (E.updatedAt = f);
|
|
1960
|
+
const v = ke(t, E), m = [];
|
|
1961
|
+
b.forEach((N) => {
|
|
1962
|
+
m.push("?"), A.push(v[N] ?? null);
|
|
1963
|
+
}), T.push(`(${m.join(",")})`);
|
|
1964
|
+
}), { sql: `INSERT INTO "${s}" (${b.join(",")}) VALUES ${T.join(",")};`, params: A };
|
|
1965
|
+
}, nt = async (t, n) => {
|
|
1966
|
+
const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Date();
|
|
1967
|
+
let o = "";
|
|
1968
|
+
const a = /* @__PURE__ */ new Set();
|
|
1969
|
+
return n.create.forEach((d, p) => {
|
|
1970
|
+
const f = Array.from(d);
|
|
1971
|
+
f.forEach((m) => a.add(m));
|
|
1972
|
+
const b = V(p), A = gt(b, f, t.rxdb.context), T = fe(A.sql, A.params), I = f.map((m) => m.id);
|
|
1973
|
+
I.forEach((m) => e.set(m, p));
|
|
1974
|
+
const { sql: M, params: E } = De(t, b, {
|
|
1191
1975
|
where: {
|
|
1192
1976
|
combinator: "and",
|
|
1193
|
-
rules: [{ field: "id", operator: "in", value:
|
|
1977
|
+
rules: [{ field: "id", operator: "in", value: I }]
|
|
1194
1978
|
}
|
|
1195
|
-
}),
|
|
1196
|
-
|
|
1197
|
-
}), n.update.forEach((
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1202
|
-
return
|
|
1979
|
+
}), v = fe(M, E);
|
|
1980
|
+
o += T + v;
|
|
1981
|
+
}), n.update.forEach((d, p) => {
|
|
1982
|
+
const f = Array.from(d);
|
|
1983
|
+
f.forEach((T) => a.add(T));
|
|
1984
|
+
const b = V(p), A = Object.groupBy(f, (T) => {
|
|
1985
|
+
const I = ae(T);
|
|
1986
|
+
return Pn(I.patch);
|
|
1203
1987
|
});
|
|
1204
|
-
Object.values(
|
|
1205
|
-
const
|
|
1206
|
-
...
|
|
1988
|
+
Object.values(A).forEach((T) => {
|
|
1989
|
+
const I = T[0], M = ae(I), E = Pe(b, T, M.patch, {
|
|
1990
|
+
...t.rxdb.context,
|
|
1207
1991
|
returning: !1,
|
|
1208
1992
|
updatedAt: s
|
|
1209
|
-
}),
|
|
1210
|
-
|
|
1211
|
-
const m =
|
|
1212
|
-
m.forEach(($) =>
|
|
1213
|
-
const
|
|
1993
|
+
}), v = fe(E.sql, E.params);
|
|
1994
|
+
o += v;
|
|
1995
|
+
const m = T.map(($) => $.id);
|
|
1996
|
+
m.forEach(($) => e.set($, p));
|
|
1997
|
+
const N = De(t, b, {
|
|
1214
1998
|
where: {
|
|
1215
1999
|
combinator: "and",
|
|
1216
2000
|
rules: [{ field: "id", operator: "in", value: m }]
|
|
1217
2001
|
}
|
|
1218
|
-
}),
|
|
1219
|
-
|
|
2002
|
+
}), S = fe(N.sql, N.params);
|
|
2003
|
+
o += S;
|
|
1220
2004
|
});
|
|
1221
|
-
}), n.remove.forEach((
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
}),
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
const
|
|
1228
|
-
if (
|
|
1229
|
-
const m =
|
|
1230
|
-
|
|
1231
|
-
const
|
|
1232
|
-
if (
|
|
1233
|
-
const $ = BigInt(
|
|
1234
|
-
|
|
2005
|
+
}), n.remove.forEach((d, p) => {
|
|
2006
|
+
const f = Array.from(d), b = V(p), A = Fn(b, f);
|
|
2007
|
+
o += A;
|
|
2008
|
+
}), o && (await t.query(o)).results.forEach(({ columns: p, rows: f }) => {
|
|
2009
|
+
const b = p.findIndex((I) => I === "id"), A = p.findIndex((I) => I === ie), T = t.rxdb.entityManager;
|
|
2010
|
+
f.forEach((I) => {
|
|
2011
|
+
const M = I[b], E = e.get(M), v = V(E);
|
|
2012
|
+
if (T.hasEntityRef(E, M)) {
|
|
2013
|
+
const m = T.getEntityRef(E, M), N = je(v, p, I);
|
|
2014
|
+
t.getRepository(E).updateEntity(m, N);
|
|
2015
|
+
const S = ae(m);
|
|
2016
|
+
if (S.local = !0, A !== -1) {
|
|
2017
|
+
const $ = BigInt(I[A]);
|
|
2018
|
+
t.cacheRowIdEntity($, m);
|
|
1235
2019
|
}
|
|
1236
|
-
|
|
2020
|
+
S.modified = !1;
|
|
1237
2021
|
}
|
|
1238
2022
|
});
|
|
1239
2023
|
}), n.remove.forEach(
|
|
1240
|
-
(
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
2024
|
+
(d) => d.forEach((p) => {
|
|
2025
|
+
a.add(p);
|
|
2026
|
+
const f = ae(p);
|
|
2027
|
+
f.origin = structuredClone({ ...p }), f.modified = !1, f.removed = !0, f.local = !1;
|
|
1244
2028
|
})
|
|
1245
|
-
), Array.from(
|
|
1246
|
-
},
|
|
1247
|
-
const
|
|
1248
|
-
let s = `CREATE TABLE "${
|
|
1249
|
-
const
|
|
1250
|
-
n.propertyMap.forEach((
|
|
1251
|
-
const
|
|
1252
|
-
let
|
|
1253
|
-
if (
|
|
1254
|
-
let
|
|
1255
|
-
|
|
2029
|
+
), Array.from(a);
|
|
2030
|
+
}, Wn = (t, n) => {
|
|
2031
|
+
const e = X(n);
|
|
2032
|
+
let s = `CREATE TABLE "${e}" (`;
|
|
2033
|
+
const o = [], a = [], d = [];
|
|
2034
|
+
n.propertyMap.forEach((f) => {
|
|
2035
|
+
const b = f.columnName;
|
|
2036
|
+
let A = `"${b}" ${kt(f)}`;
|
|
2037
|
+
if (f.type === D.integer && f.primary ? A += " PRIMARY KEY AUTOINCREMENT" : (f.type === D.uuid || f.type === D.string) && f.primary && (A += " PRIMARY KEY", f.type === D.uuid && (A += " DEFAULT (lower(hex(randomblob(16))))")), !(f.type === D.uuid && f.primary) && f.default !== void 0) {
|
|
2038
|
+
let I = f.default;
|
|
2039
|
+
Je(f.default) && (I = f.default()), I === "CURRENT_TIMESTAMP" ? A += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : (I = we(I, f), f.type === D.boolean || f.type === D.integer || f.type === D.number ? A += ` DEFAULT ${I}` : A += ` DEFAULT '${I}'`);
|
|
1256
2040
|
}
|
|
1257
|
-
switch (
|
|
1258
|
-
case
|
|
1259
|
-
case
|
|
1260
|
-
case
|
|
1261
|
-
case
|
|
1262
|
-
|
|
2041
|
+
switch (f.nullable || (A += " NOT NULL"), f.type) {
|
|
2042
|
+
case D.json:
|
|
2043
|
+
case D.keyValue:
|
|
2044
|
+
case D.stringArray:
|
|
2045
|
+
case D.numberArray:
|
|
2046
|
+
a.push(`CHECK ( JSON_VALID(${b})=1 )`);
|
|
1263
2047
|
break;
|
|
1264
|
-
case
|
|
1265
|
-
|
|
2048
|
+
case D.boolean:
|
|
2049
|
+
a.push(`CHECK (${b} in(0,1))`);
|
|
1266
2050
|
break;
|
|
1267
|
-
case
|
|
1268
|
-
if ("enum" in
|
|
1269
|
-
const
|
|
1270
|
-
|
|
2051
|
+
case D.enum:
|
|
2052
|
+
if ("enum" in f && f.enum && f.enum.length > 0) {
|
|
2053
|
+
const I = f.enum.map((M) => `'${String(M).replace(/'/g, "''")}'`).join(",");
|
|
2054
|
+
a.push(`CHECK (${b} in(${I}))`);
|
|
1271
2055
|
}
|
|
1272
2056
|
break;
|
|
1273
2057
|
}
|
|
1274
|
-
|
|
1275
|
-
`CREATE UNIQUE INDEX ${
|
|
1276
|
-
),
|
|
1277
|
-
}), n.relationMap.forEach((
|
|
1278
|
-
if (
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
2058
|
+
f.unique && o.push(
|
|
2059
|
+
`CREATE UNIQUE INDEX ${ze(n, f)} on "${e}"(${b});`
|
|
2060
|
+
), d.push(A);
|
|
2061
|
+
}), n.relationMap.forEach((f) => {
|
|
2062
|
+
if (f.kind === z.ONE_TO_ONE || f.kind === z.MANY_TO_ONE) {
|
|
2063
|
+
const b = f.columnName, A = t.rxdb.schemaManager.getEntityMetadata(
|
|
2064
|
+
f.mappedEntity,
|
|
2065
|
+
f.mappedNamespace
|
|
1282
2066
|
);
|
|
1283
|
-
let
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
const
|
|
1287
|
-
let
|
|
1288
|
-
if (!
|
|
1289
|
-
const
|
|
1290
|
-
let m =
|
|
1291
|
-
|
|
2067
|
+
let T = "TEXT";
|
|
2068
|
+
const I = A.propertyMap.get("id");
|
|
2069
|
+
I.type === D.integer ? T = "INTEGER" : (I.type === D.uuid || I.type === D.string) && (T = "TEXT");
|
|
2070
|
+
const M = f.onDelete === "SET NULL" || f.onUpdate === "SET NULL";
|
|
2071
|
+
let E = `"${b}" ${T}`;
|
|
2072
|
+
if (!f.nullable && !M && (E += " NOT NULL"), f.kind === z.MANY_TO_ONE && f.default !== void 0) {
|
|
2073
|
+
const v = f;
|
|
2074
|
+
let m = v.default;
|
|
2075
|
+
Je(v.default) && (m = v.default()), E += ` DEFAULT ${m}`;
|
|
1292
2076
|
}
|
|
1293
|
-
if (
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
), m =
|
|
1298
|
-
|
|
1299
|
-
|
|
2077
|
+
if (f.mappedEntity) {
|
|
2078
|
+
const v = t.rxdb.schemaManager.getEntityMetadata(
|
|
2079
|
+
f.mappedEntity,
|
|
2080
|
+
f.mappedNamespace
|
|
2081
|
+
), m = le(
|
|
2082
|
+
v?.tableName ?? f.mappedEntity,
|
|
2083
|
+
f.mappedNamespace
|
|
1300
2084
|
);
|
|
1301
|
-
|
|
2085
|
+
E += ` REFERENCES ${m}(id)`, f.onDelete && (E += ` ON DELETE ${f.onDelete}`), f.onUpdate && (E += ` ON UPDATE ${f.onUpdate}`);
|
|
1302
2086
|
}
|
|
1303
|
-
|
|
1304
|
-
`CREATE UNIQUE INDEX ${
|
|
2087
|
+
d.push(E), (f.unique || f.kind === z.ONE_TO_ONE) && o.push(
|
|
2088
|
+
`CREATE UNIQUE INDEX ${ze(n, f)} on "${e}"(${b});`
|
|
1305
2089
|
);
|
|
1306
2090
|
}
|
|
1307
2091
|
});
|
|
1308
|
-
const
|
|
1309
|
-
if (
|
|
1310
|
-
s +=
|
|
1311
|
-
${
|
|
2092
|
+
const p = [...d, ...a];
|
|
2093
|
+
if (p.length)
|
|
2094
|
+
s += p.map((f) => `
|
|
2095
|
+
${f}`).join(","), s += `
|
|
1312
2096
|
);`;
|
|
1313
2097
|
else
|
|
1314
|
-
throw new
|
|
1315
|
-
return
|
|
1316
|
-
` +
|
|
1317
|
-
`)), n.indexes && n.indexes.length > 0 && n.indexes.forEach((
|
|
1318
|
-
const
|
|
1319
|
-
const
|
|
1320
|
-
if (
|
|
1321
|
-
const
|
|
1322
|
-
if (
|
|
1323
|
-
const m =
|
|
1324
|
-
if (m >= 0) return `"${
|
|
2098
|
+
throw new ee("columns is empty!");
|
|
2099
|
+
return o.length && (s += `
|
|
2100
|
+
` + o.join(`
|
|
2101
|
+
`)), n.indexes && n.indexes.length > 0 && n.indexes.forEach((f) => {
|
|
2102
|
+
const b = `idx_${n.name}_${f.name}`, A = f.properties?.map((I) => {
|
|
2103
|
+
const M = n.propertyMap.get(I);
|
|
2104
|
+
if (M) return `"${M.columnName}"`;
|
|
2105
|
+
const E = n.foreignKeyNames, v = n.foreignKeyColumnNames;
|
|
2106
|
+
if (E && v) {
|
|
2107
|
+
const m = E.indexOf(I);
|
|
2108
|
+
if (m >= 0) return `"${v[m]}"`;
|
|
1325
2109
|
}
|
|
1326
|
-
return `"${
|
|
1327
|
-
}).join(", ") || `"${
|
|
2110
|
+
return `"${I}"`;
|
|
2111
|
+
}).join(", ") || `"${f.name}"`, T = f.unique ? "UNIQUE " : "";
|
|
1328
2112
|
s += `
|
|
1329
|
-
CREATE ${
|
|
2113
|
+
CREATE ${T}INDEX "${b}" ON "${e}"(${A});`;
|
|
1330
2114
|
}), s;
|
|
1331
|
-
},
|
|
1332
|
-
const
|
|
1333
|
-
for (const [
|
|
1334
|
-
|
|
1335
|
-
const
|
|
1336
|
-
for (let
|
|
1337
|
-
|
|
1338
|
-
const
|
|
1339
|
-
const
|
|
1340
|
-
return
|
|
1341
|
-
},
|
|
1342
|
-
DROP TRIGGER IF EXISTS ${
|
|
1343
|
-
CREATE TRIGGER ${
|
|
2115
|
+
}, Kn = (t, n) => Wn(t, n), Fe = (t, n = {}) => {
|
|
2116
|
+
const e = X(t), s = V(pe), o = X(s), { propertyMap: a, name: d, foreignKeyNames: p, foreignKeyColumnNames: f, namespace: b } = t, A = [];
|
|
2117
|
+
for (const [u, i] of a)
|
|
2118
|
+
u !== "id" && A.push({ jsName: u, dbColumn: i.columnName });
|
|
2119
|
+
const T = f || p;
|
|
2120
|
+
for (let u = 0; u < p.length; u++)
|
|
2121
|
+
p[u] !== "id" && A.push({ jsName: p[u], dbColumn: T[u] });
|
|
2122
|
+
const I = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: M, branchId: E } = n, v = te(M), m = te(E || "main"), N = `'${b}','${d}',${m},${v}`, S = (u) => u === D.stringArray || u === D.numberArray || u === D.json || u === D.keyValue, $ = (u, i, g) => {
|
|
2123
|
+
const _ = a.get(i);
|
|
2124
|
+
return _?.type === D.boolean ? `CASE WHEN ${g}.${u} = 1 THEN 1 ELSE 0 END` : S(_?.type) ? `CASE WHEN ${g}.${u} IS NOT NULL THEN json(${g}.${u}) ELSE NULL END` : `${g}.${u}`;
|
|
2125
|
+
}, R = (u, i, g) => a.get(i)?.type === D.boolean ? `CASE WHEN ${g}.${u} = 1 THEN 1 ELSE 0 END` : `${g}.${u}`, B = `
|
|
2126
|
+
DROP TRIGGER IF EXISTS ${e}_insert;
|
|
2127
|
+
CREATE TRIGGER ${e}_insert AFTER INSERT ON "${e}"
|
|
1344
2128
|
BEGIN
|
|
1345
|
-
INSERT INTO ${
|
|
1346
|
-
'INSERT',${
|
|
1347
|
-
json_object(${
|
|
2129
|
+
INSERT INTO ${o} (${I}) VALUES (
|
|
2130
|
+
'INSERT',${N}, NEW.id, NULL,
|
|
2131
|
+
json_object(${A.map((u) => `'${u.jsName}', ${$(u.dbColumn, u.jsName, "NEW")}`).join(`,
|
|
1348
2132
|
`)})
|
|
1349
2133
|
);
|
|
1350
|
-
END;`,
|
|
1351
|
-
const
|
|
1352
|
-
return `SELECT '${
|
|
2134
|
+
END;`, y = (u) => A.map((i) => {
|
|
2135
|
+
const g = S(a.get(i.jsName)?.type) ? 1 : 0;
|
|
2136
|
+
return `SELECT '${i.jsName}' AS key, ${R(i.dbColumn, i.jsName, u)} AS value, ${g} AS is_json WHERE OLD.${i.dbColumn} IS NOT NEW.${i.dbColumn}`;
|
|
1353
2137
|
}).join(`
|
|
1354
|
-
UNION `),
|
|
1355
|
-
DROP TRIGGER IF EXISTS ${
|
|
1356
|
-
CREATE TRIGGER ${
|
|
1357
|
-
WHEN ( ${
|
|
2138
|
+
UNION `), w = `
|
|
2139
|
+
DROP TRIGGER IF EXISTS ${e}_update;
|
|
2140
|
+
CREATE TRIGGER ${e}_update AFTER UPDATE ON "${e}"
|
|
2141
|
+
WHEN ( ${A.map((u) => `OLD.${u.dbColumn} IS NOT NEW.${u.dbColumn}`).join(` OR
|
|
1358
2142
|
`)} )
|
|
1359
2143
|
BEGIN
|
|
1360
|
-
INSERT INTO ${
|
|
1361
|
-
'UPDATE',${
|
|
2144
|
+
INSERT INTO ${o} (${I}) VALUES (
|
|
2145
|
+
'UPDATE',${N}, NEW.id,
|
|
1362
2146
|
(
|
|
1363
2147
|
SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
|
|
1364
|
-
${
|
|
2148
|
+
${y("OLD")}
|
|
1365
2149
|
)
|
|
1366
2150
|
),
|
|
1367
2151
|
(
|
|
1368
2152
|
SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
|
|
1369
|
-
${
|
|
2153
|
+
${y("NEW")}
|
|
1370
2154
|
)
|
|
1371
2155
|
)
|
|
1372
2156
|
);
|
|
1373
|
-
END;`,
|
|
1374
|
-
DROP TRIGGER IF EXISTS ${
|
|
1375
|
-
CREATE TRIGGER ${
|
|
2157
|
+
END;`, c = `
|
|
2158
|
+
DROP TRIGGER IF EXISTS ${e}_delete;
|
|
2159
|
+
CREATE TRIGGER ${e}_delete AFTER DELETE ON "${e}"
|
|
1376
2160
|
BEGIN
|
|
1377
|
-
INSERT INTO ${
|
|
1378
|
-
'DELETE',${
|
|
1379
|
-
json_object(${
|
|
2161
|
+
INSERT INTO ${o} (${I}) VALUES (
|
|
2162
|
+
'DELETE',${N}, OLD.id,
|
|
2163
|
+
json_object(${A.map((u) => `'${u.jsName}', ${$(u.dbColumn, u.jsName, "OLD")}`).join(`,
|
|
1380
2164
|
`)}), NULL
|
|
1381
2165
|
);
|
|
1382
2166
|
END;`;
|
|
1383
|
-
return
|
|
1384
|
-
` +
|
|
1385
|
-
` +
|
|
1386
|
-
},
|
|
2167
|
+
return B + `
|
|
2168
|
+
` + w + `
|
|
2169
|
+
` + c;
|
|
2170
|
+
}, Hn = (t, n, e) => {
|
|
1387
2171
|
let s = "";
|
|
1388
|
-
for (let
|
|
1389
|
-
const
|
|
2172
|
+
for (let o = 0; o < n.length; o++) {
|
|
2173
|
+
const a = n[o], d = V(a);
|
|
1390
2174
|
if (s += `
|
|
1391
|
-
` +
|
|
1392
|
-
const
|
|
2175
|
+
` + Kn(t, d), d.log !== !1) {
|
|
2176
|
+
const p = Fe(d);
|
|
1393
2177
|
s += `
|
|
1394
|
-
` +
|
|
2178
|
+
` + p;
|
|
1395
2179
|
}
|
|
1396
2180
|
}
|
|
1397
|
-
if (
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1400
|
-
const
|
|
1401
|
-
|
|
2181
|
+
if (e) {
|
|
2182
|
+
const o = /* @__PURE__ */ new Map();
|
|
2183
|
+
e.forEach((a) => {
|
|
2184
|
+
const d = V(a);
|
|
2185
|
+
o.has(d) === !1 && o.set(d, /* @__PURE__ */ new Set()), o.get(d).add(a);
|
|
1402
2186
|
});
|
|
1403
|
-
for (const
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1406
|
-
Array.from(
|
|
1407
|
-
|
|
2187
|
+
for (const a of o.keys()) {
|
|
2188
|
+
const d = gt(
|
|
2189
|
+
a,
|
|
2190
|
+
Array.from(o.get(a)),
|
|
2191
|
+
t.rxdb.context
|
|
1408
2192
|
);
|
|
1409
2193
|
s += `
|
|
1410
|
-
` +
|
|
2194
|
+
` + fe(d.sql, d.params);
|
|
1411
2195
|
}
|
|
1412
2196
|
}
|
|
1413
2197
|
return s;
|
|
1414
|
-
},
|
|
1415
|
-
const n =
|
|
2198
|
+
}, Vn = (t) => {
|
|
2199
|
+
const n = X(t);
|
|
1416
2200
|
return `DROP TRIGGER IF EXISTS ${n}_insert;
|
|
1417
2201
|
DROP TRIGGER IF EXISTS ${n}_update;
|
|
1418
2202
|
DROP TRIGGER IF EXISTS ${n}_delete;`;
|
|
1419
|
-
},
|
|
2203
|
+
}, Et = (t) => {
|
|
1420
2204
|
let n = "";
|
|
1421
|
-
return
|
|
1422
|
-
const s =
|
|
1423
|
-
s.log !== !1 && (n +=
|
|
2205
|
+
return t.rxdb.config.entities.forEach((e) => {
|
|
2206
|
+
const s = V(e);
|
|
2207
|
+
s.log !== !1 && (n += Vn(s));
|
|
1424
2208
|
}), n;
|
|
1425
|
-
},
|
|
1426
|
-
const { deletes:
|
|
1427
|
-
for (const [
|
|
1428
|
-
const [
|
|
1429
|
-
|
|
1430
|
-
let $ =
|
|
1431
|
-
$ || ($ = /* @__PURE__ */ new Map(),
|
|
1432
|
-
patch:
|
|
1433
|
-
inversePatch:
|
|
2209
|
+
}, _t = (t, n) => {
|
|
2210
|
+
const { deletes: e, inserts: s, updates: o } = n, a = { deletes: [], inserts: [], updates: [] }, d = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
|
|
2211
|
+
for (const [I, M] of e.entries()) {
|
|
2212
|
+
const [E, v, m] = Re(I), N = `${E}:${v}`, S = d.get(N);
|
|
2213
|
+
S ? S.add(m) : d.set(N, /* @__PURE__ */ new Set([m]));
|
|
2214
|
+
let $ = p.get(N);
|
|
2215
|
+
$ || ($ = /* @__PURE__ */ new Map(), p.set(N, $)), $.set(m, {
|
|
2216
|
+
patch: M.patch,
|
|
2217
|
+
inversePatch: M.inversePatch
|
|
1434
2218
|
});
|
|
1435
2219
|
}
|
|
1436
|
-
for (const [
|
|
1437
|
-
const [
|
|
2220
|
+
for (const [I, M] of d) {
|
|
2221
|
+
const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E), N = X(m), S = m.propertyMap.get("id").type === "integer";
|
|
1438
2222
|
let $ = "";
|
|
1439
|
-
|
|
1440
|
-
const
|
|
1441
|
-
|
|
2223
|
+
S ? $ = Array.from(M).join(",") : $ = Array.from(M).map((B) => te(B)).join(",");
|
|
2224
|
+
const R = `DELETE FROM "${N}" WHERE id in (${$});`;
|
|
2225
|
+
a.deletes.push({
|
|
1442
2226
|
metadata: m,
|
|
1443
|
-
ids:
|
|
1444
|
-
sql:
|
|
1445
|
-
changes:
|
|
2227
|
+
ids: M,
|
|
2228
|
+
sql: R,
|
|
2229
|
+
changes: p.get(I)
|
|
1446
2230
|
});
|
|
1447
2231
|
}
|
|
1448
|
-
const
|
|
1449
|
-
for (const [
|
|
1450
|
-
const [
|
|
1451
|
-
|
|
1452
|
-
let
|
|
1453
|
-
|
|
1454
|
-
patch:
|
|
1455
|
-
inversePatch:
|
|
2232
|
+
const f = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map();
|
|
2233
|
+
for (const [I, M] of s.entries()) {
|
|
2234
|
+
const [E, v, m] = Re(I), N = `${E}:${v}`, S = f.get(N), $ = { ...M.patch, id: m };
|
|
2235
|
+
S ? S.push($) : f.set(N, [$]);
|
|
2236
|
+
let R = b.get(N);
|
|
2237
|
+
R || (R = /* @__PURE__ */ new Map(), b.set(N, R)), R.set(m, {
|
|
2238
|
+
patch: M.patch,
|
|
2239
|
+
inversePatch: M.inversePatch
|
|
1456
2240
|
});
|
|
1457
2241
|
}
|
|
1458
|
-
for (const [
|
|
1459
|
-
const [
|
|
1460
|
-
let
|
|
1461
|
-
|
|
1462
|
-
for (const [
|
|
1463
|
-
|
|
1464
|
-
const { sql: $, params:
|
|
2242
|
+
for (const [I, M] of f) {
|
|
2243
|
+
const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E);
|
|
2244
|
+
let N = "";
|
|
2245
|
+
M.forEach((S) => {
|
|
2246
|
+
for (const [y, w] of m.propertyMap)
|
|
2247
|
+
S[y] === void 0 && w.default !== void 0 && (typeof w.default == "function" ? S[y] = w.default() : S[y] = w.default);
|
|
2248
|
+
const { sql: $, params: R } = pt(m, S, {
|
|
1465
2249
|
useReplace: !0
|
|
1466
|
-
}),
|
|
1467
|
-
|
|
1468
|
-
}),
|
|
2250
|
+
}), B = fe($, R);
|
|
2251
|
+
N += B;
|
|
2252
|
+
}), a.inserts.push({
|
|
1469
2253
|
metadata: m,
|
|
1470
|
-
ids: new Set(
|
|
1471
|
-
sql:
|
|
1472
|
-
changes:
|
|
2254
|
+
ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
|
|
2255
|
+
sql: N,
|
|
2256
|
+
changes: b.get(I)
|
|
1473
2257
|
});
|
|
1474
2258
|
}
|
|
1475
|
-
const
|
|
1476
|
-
for (const [
|
|
1477
|
-
const [
|
|
1478
|
-
|
|
1479
|
-
let
|
|
1480
|
-
|
|
1481
|
-
const
|
|
1482
|
-
|
|
1483
|
-
const
|
|
1484
|
-
|
|
1485
|
-
}),
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
})),
|
|
1489
|
-
patch:
|
|
1490
|
-
inversePatch:
|
|
2259
|
+
const A = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
|
|
2260
|
+
for (const [I, M] of o.entries()) {
|
|
2261
|
+
const [E, v, m] = Re(I), N = `${E}:${v}`, S = A.get(N), $ = { ...M.patch, id: m };
|
|
2262
|
+
S ? S.push($) : A.set(N, [$]);
|
|
2263
|
+
let R = T.get(N);
|
|
2264
|
+
R || (R = /* @__PURE__ */ new Map(), T.set(N, R));
|
|
2265
|
+
const B = t.rxdb.schemaManager.getEntityMetadata(v, E), y = M.patch ? { ...M.patch } : null, w = M.inversePatch ? { ...M.inversePatch } : null;
|
|
2266
|
+
B && (y && Object.keys(y).forEach((c) => {
|
|
2267
|
+
const u = B.propertyMap.get(c);
|
|
2268
|
+
u && (y[c] = ue(y[c], u));
|
|
2269
|
+
}), w && Object.keys(w).forEach((c) => {
|
|
2270
|
+
const u = B.propertyMap.get(c);
|
|
2271
|
+
u && (w[c] = ue(w[c], u));
|
|
2272
|
+
})), R.set(m, {
|
|
2273
|
+
patch: y,
|
|
2274
|
+
inversePatch: w
|
|
1491
2275
|
});
|
|
1492
2276
|
}
|
|
1493
|
-
for (const [
|
|
1494
|
-
const [
|
|
1495
|
-
let
|
|
1496
|
-
|
|
2277
|
+
for (const [I, M] of A) {
|
|
2278
|
+
const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E);
|
|
2279
|
+
let N = "";
|
|
2280
|
+
M.forEach((S) => {
|
|
1497
2281
|
let $;
|
|
1498
|
-
m.propertyMap.has("updatedAt") && ($ =
|
|
1499
|
-
const { id:
|
|
2282
|
+
m.propertyMap.has("updatedAt") && ($ = S.updatedAt);
|
|
2283
|
+
const { id: R, ...B } = S, { sql: y, params: w } = Pe(m, { id: R }, B, {
|
|
1500
2284
|
updatedAt: $
|
|
1501
2285
|
});
|
|
1502
|
-
|
|
1503
|
-
}),
|
|
2286
|
+
N += fe(y, w);
|
|
2287
|
+
}), a.updates.push({
|
|
1504
2288
|
metadata: m,
|
|
1505
|
-
ids: new Set(
|
|
1506
|
-
sql:
|
|
1507
|
-
changes:
|
|
2289
|
+
ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
|
|
2290
|
+
sql: N,
|
|
2291
|
+
changes: T.get(I)
|
|
1508
2292
|
});
|
|
1509
2293
|
}
|
|
1510
|
-
return
|
|
1511
|
-
},
|
|
1512
|
-
let
|
|
1513
|
-
|
|
1514
|
-
const
|
|
1515
|
-
if (
|
|
2294
|
+
return a;
|
|
2295
|
+
}, wt = (t, n) => {
|
|
2296
|
+
let e = "";
|
|
2297
|
+
t.rxdb.config.entities.forEach((d) => {
|
|
2298
|
+
const p = V(d);
|
|
2299
|
+
if (p.log !== !1)
|
|
1516
2300
|
try {
|
|
1517
|
-
const
|
|
2301
|
+
const f = Fe(p, {
|
|
1518
2302
|
branchId: n
|
|
1519
2303
|
});
|
|
1520
|
-
|
|
1521
|
-
} catch (
|
|
1522
|
-
console.warn(`Failed to generate trigger SQL for entity ${
|
|
2304
|
+
f.trim() && (e += f);
|
|
2305
|
+
} catch (f) {
|
|
2306
|
+
console.warn(`Failed to generate trigger SQL for entity ${p.name}:`, f);
|
|
1523
2307
|
}
|
|
1524
2308
|
});
|
|
1525
|
-
const s =
|
|
1526
|
-
return
|
|
1527
|
-
UPDATE "${
|
|
2309
|
+
const s = V(_e), o = X(s), a = n.replace(/'/g, "''");
|
|
2310
|
+
return e += `
|
|
2311
|
+
UPDATE "${o}"
|
|
1528
2312
|
SET
|
|
1529
2313
|
activated = CASE
|
|
1530
|
-
WHEN id = '${
|
|
2314
|
+
WHEN id = '${a}' THEN 1
|
|
1531
2315
|
ELSE 0
|
|
1532
2316
|
END,
|
|
1533
2317
|
updatedAt = CASE
|
|
1534
|
-
WHEN (id = '${
|
|
2318
|
+
WHEN (id = '${a}' AND activated = 0) OR (id != '${a}' AND activated = 1) THEN CURRENT_TIMESTAMP
|
|
1535
2319
|
ELSE updatedAt
|
|
1536
2320
|
END
|
|
1537
|
-
WHERE id = '${
|
|
1538
|
-
RETURNING rowid as ${
|
|
1539
|
-
`,
|
|
1540
|
-
},
|
|
1541
|
-
const { branchId:
|
|
1542
|
-
let
|
|
2321
|
+
WHERE id = '${a}' OR activated = 1
|
|
2322
|
+
RETURNING rowid as ${ie},*;
|
|
2323
|
+
`, e;
|
|
2324
|
+
}, Yn = async (t, n) => {
|
|
2325
|
+
const { branchId: e, actions: s } = n, o = s && _t(t, s);
|
|
2326
|
+
let a;
|
|
1543
2327
|
try {
|
|
1544
|
-
await
|
|
1545
|
-
const
|
|
1546
|
-
if (
|
|
1547
|
-
if (
|
|
1548
|
-
for (const
|
|
1549
|
-
await
|
|
1550
|
-
if (
|
|
1551
|
-
for (const
|
|
1552
|
-
|
|
1553
|
-
if (
|
|
1554
|
-
for (const
|
|
1555
|
-
|
|
2328
|
+
await t.transaction(async (f) => {
|
|
2329
|
+
const b = Et(t);
|
|
2330
|
+
if (b && await f.execute(b), o) {
|
|
2331
|
+
if (o.deletes.length)
|
|
2332
|
+
for (const A of o.deletes)
|
|
2333
|
+
await f.execute(A.sql);
|
|
2334
|
+
if (o.inserts.length)
|
|
2335
|
+
for (const A of o.inserts)
|
|
2336
|
+
A.successResults = await f.execute(A.sql);
|
|
2337
|
+
if (o.updates.length)
|
|
2338
|
+
for (const A of o.updates)
|
|
2339
|
+
A.successResults = await f.execute(A.sql);
|
|
1556
2340
|
}
|
|
1557
|
-
s?.updateRxDBChangeSequence !== void 0 && await
|
|
2341
|
+
s?.updateRxDBChangeSequence !== void 0 && await t.setRxDBChangeSequence(s.updateRxDBChangeSequence);
|
|
1558
2342
|
}, !1);
|
|
1559
|
-
const
|
|
1560
|
-
|
|
1561
|
-
const
|
|
1562
|
-
if (
|
|
1563
|
-
const
|
|
1564
|
-
const
|
|
2343
|
+
const d = wt(t, e);
|
|
2344
|
+
a = await t.internalQuery(d);
|
|
2345
|
+
const p = (f, b) => {
|
|
2346
|
+
if (b.length === 0) return;
|
|
2347
|
+
const A = b.map((T) => {
|
|
2348
|
+
const I = { ...T };
|
|
1565
2349
|
return {
|
|
1566
|
-
namespace:
|
|
1567
|
-
entity:
|
|
2350
|
+
namespace: f.namespace,
|
|
2351
|
+
entity: f.name,
|
|
1568
2352
|
type: "UPDATE",
|
|
1569
|
-
id:
|
|
1570
|
-
patch:
|
|
1571
|
-
inversePatch:
|
|
1572
|
-
recordAt:
|
|
2353
|
+
id: T.id,
|
|
2354
|
+
patch: I,
|
|
2355
|
+
inversePatch: I,
|
|
2356
|
+
recordAt: T.createdAt
|
|
1573
2357
|
};
|
|
1574
2358
|
});
|
|
1575
|
-
|
|
2359
|
+
t.rxdb.dispatchEvent(new Te(A));
|
|
1576
2360
|
};
|
|
1577
|
-
if (
|
|
1578
|
-
const
|
|
1579
|
-
|
|
2361
|
+
if (a) {
|
|
2362
|
+
const f = Ie(t, _e, a, !0), b = V(_e);
|
|
2363
|
+
p(b, f);
|
|
1580
2364
|
}
|
|
1581
|
-
|
|
1582
|
-
} catch (
|
|
1583
|
-
throw new
|
|
2365
|
+
o && bt(t, o);
|
|
2366
|
+
} catch (d) {
|
|
2367
|
+
throw new ee(`switch branch ${e} failed`, { cause: d });
|
|
1584
2368
|
}
|
|
1585
2369
|
};
|
|
1586
|
-
async function
|
|
1587
|
-
if (await
|
|
1588
|
-
if (
|
|
1589
|
-
const
|
|
1590
|
-
|
|
2370
|
+
async function Qn(t, n, e = !1) {
|
|
2371
|
+
if (await t.transaction(async (s) => {
|
|
2372
|
+
if (e) {
|
|
2373
|
+
const o = Et(t);
|
|
2374
|
+
o && await s.execute(o);
|
|
1591
2375
|
}
|
|
1592
|
-
for (const
|
|
1593
|
-
await s.execute(
|
|
1594
|
-
for (const
|
|
1595
|
-
|
|
1596
|
-
for (const
|
|
1597
|
-
|
|
1598
|
-
}, !1),
|
|
1599
|
-
const s = await
|
|
1600
|
-
await
|
|
1601
|
-
}
|
|
1602
|
-
|
|
2376
|
+
for (const o of n.deletes)
|
|
2377
|
+
await s.execute(o.sql);
|
|
2378
|
+
for (const o of n.inserts)
|
|
2379
|
+
o.successResults = await s.execute(o.sql);
|
|
2380
|
+
for (const o of n.updates)
|
|
2381
|
+
o.successResults = await s.execute(o.sql);
|
|
2382
|
+
}, !1), e) {
|
|
2383
|
+
const s = await t.rxdb.versionManager.getCurrentBranch(), o = wt(t, s.id);
|
|
2384
|
+
await t.internalQuery(o);
|
|
2385
|
+
}
|
|
2386
|
+
bt(t, n);
|
|
1603
2387
|
}
|
|
1604
|
-
function
|
|
1605
|
-
for (const
|
|
1606
|
-
const s =
|
|
1607
|
-
|
|
1608
|
-
const
|
|
1609
|
-
const
|
|
2388
|
+
function bt(t, n) {
|
|
2389
|
+
for (const e of n.deletes) {
|
|
2390
|
+
const s = Ce(e.metadata);
|
|
2391
|
+
pn(t, s, Array.from(e.ids));
|
|
2392
|
+
const o = e.metadata, a = Array.from(e.ids).map((d) => {
|
|
2393
|
+
const p = e.changes.get(String(d));
|
|
1610
2394
|
return {
|
|
1611
|
-
namespace:
|
|
1612
|
-
entity:
|
|
2395
|
+
namespace: o.namespace,
|
|
2396
|
+
entity: o.name,
|
|
1613
2397
|
type: "DELETE",
|
|
1614
|
-
id:
|
|
2398
|
+
id: d,
|
|
1615
2399
|
patch: null,
|
|
1616
|
-
inversePatch:
|
|
2400
|
+
inversePatch: p?.inversePatch ?? null,
|
|
1617
2401
|
recordAt: /* @__PURE__ */ new Date()
|
|
1618
2402
|
};
|
|
1619
2403
|
});
|
|
1620
|
-
|
|
2404
|
+
t.rxdb.dispatchEvent(new qe(a));
|
|
1621
2405
|
}
|
|
1622
|
-
for (const
|
|
1623
|
-
const s =
|
|
1624
|
-
const
|
|
2406
|
+
for (const e of n.inserts) {
|
|
2407
|
+
const s = Ce(e.metadata), o = Ie(t, s, e.successResults), a = e.metadata, d = o.map((p) => {
|
|
2408
|
+
const f = e.changes.get(String(p.id));
|
|
1625
2409
|
return {
|
|
1626
|
-
namespace:
|
|
1627
|
-
entity:
|
|
2410
|
+
namespace: a.namespace,
|
|
2411
|
+
entity: a.name,
|
|
1628
2412
|
type: "INSERT",
|
|
1629
|
-
id:
|
|
1630
|
-
patch:
|
|
1631
|
-
inversePatch:
|
|
1632
|
-
recordAt:
|
|
2413
|
+
id: p.id,
|
|
2414
|
+
patch: f?.patch ?? { ...p },
|
|
2415
|
+
inversePatch: f?.inversePatch ?? null,
|
|
2416
|
+
recordAt: p.createdAt
|
|
1633
2417
|
};
|
|
1634
2418
|
});
|
|
1635
|
-
|
|
2419
|
+
t.rxdb.dispatchEvent(new Ee(d));
|
|
1636
2420
|
}
|
|
1637
|
-
for (const
|
|
1638
|
-
const s =
|
|
1639
|
-
const
|
|
2421
|
+
for (const e of n.updates) {
|
|
2422
|
+
const s = Ce(e.metadata), o = Ie(t, s, e.successResults, !0), a = e.metadata, d = o.map((p) => {
|
|
2423
|
+
const f = e.changes.get(String(p.id));
|
|
1640
2424
|
return {
|
|
1641
|
-
namespace:
|
|
1642
|
-
entity:
|
|
2425
|
+
namespace: a.namespace,
|
|
2426
|
+
entity: a.name,
|
|
1643
2427
|
type: "UPDATE",
|
|
1644
|
-
id:
|
|
1645
|
-
patch:
|
|
1646
|
-
inversePatch:
|
|
1647
|
-
recordAt:
|
|
2428
|
+
id: p.id,
|
|
2429
|
+
patch: f?.patch ?? { ...p },
|
|
2430
|
+
inversePatch: f?.inversePatch ?? null,
|
|
2431
|
+
recordAt: p.updatedAt || p.createdAt || /* @__PURE__ */ new Date()
|
|
1648
2432
|
};
|
|
1649
2433
|
});
|
|
1650
|
-
|
|
2434
|
+
t.rxdb.dispatchEvent(new Te(d));
|
|
1651
2435
|
}
|
|
1652
2436
|
}
|
|
1653
|
-
const
|
|
2437
|
+
const rt = (t, n, e) => {
|
|
1654
2438
|
let s = "";
|
|
1655
|
-
return
|
|
1656
|
-
const
|
|
1657
|
-
if (
|
|
1658
|
-
const
|
|
2439
|
+
return t.rxdb.config.entities.forEach((o) => {
|
|
2440
|
+
const a = V(o);
|
|
2441
|
+
if (a.log !== !1) {
|
|
2442
|
+
const d = Fe(a, {
|
|
1659
2443
|
branchId: n,
|
|
1660
|
-
transactionId:
|
|
2444
|
+
transactionId: e
|
|
1661
2445
|
});
|
|
1662
2446
|
s += `
|
|
1663
|
-
` +
|
|
2447
|
+
` + d;
|
|
1664
2448
|
}
|
|
1665
2449
|
}), s;
|
|
1666
2450
|
};
|
|
1667
|
-
class
|
|
1668
|
-
constructor(n,
|
|
1669
|
-
super(n), this.options =
|
|
1670
|
-
this.repository(
|
|
2451
|
+
class rr extends $t {
|
|
2452
|
+
constructor(n, e) {
|
|
2453
|
+
super(n), this.options = e, e.repositories && Object.keys(e.repositories).forEach((o) => {
|
|
2454
|
+
this.repository(o, e.repositories[o]);
|
|
1671
2455
|
});
|
|
1672
|
-
const s =
|
|
1673
|
-
this.#t ||
|
|
2456
|
+
const s = Ot((o) => {
|
|
2457
|
+
this.#t || Mn(this, o);
|
|
1674
2458
|
});
|
|
1675
|
-
this.#
|
|
1676
|
-
|
|
1677
|
-
}).catch((
|
|
2459
|
+
this.#s().then((o) => {
|
|
2460
|
+
o.addEventListener(ce.SQLITE_INSERT, s), o.addEventListener(ce.SQLITE_UPDATE, s), o.addEventListener(ce.SQLITE_DELETE, s);
|
|
2461
|
+
}).catch((o) => console.error("[RxDBAdapterSqlite] Failed to register event listeners", o)), this.repository("Repository", ht), this.repository("TreeRepository", Dn);
|
|
1678
2462
|
}
|
|
1679
2463
|
// SQLite 客户端缓存
|
|
1680
2464
|
#n;
|
|
@@ -1685,29 +2469,29 @@ class _n extends He {
|
|
|
1685
2469
|
* 存储数据库行ID到实体UUID的映射关系
|
|
1686
2470
|
* 用于在数据库操作中快速查找实体
|
|
1687
2471
|
*/
|
|
1688
|
-
#
|
|
2472
|
+
#i = /* @__PURE__ */ new Map();
|
|
1689
2473
|
#o = /* @__PURE__ */ new WeakMap();
|
|
1690
2474
|
// 查询任务队列执行器
|
|
1691
|
-
#c = new
|
|
2475
|
+
#c = new st(1);
|
|
1692
2476
|
// sqlite 客户端
|
|
1693
|
-
#
|
|
2477
|
+
#r;
|
|
1694
2478
|
// 是否已断开连接
|
|
1695
2479
|
#t = !1;
|
|
1696
2480
|
/**
|
|
1697
2481
|
* 适配器名称
|
|
1698
2482
|
*/
|
|
1699
|
-
name =
|
|
2483
|
+
name = yn;
|
|
1700
2484
|
/**
|
|
1701
2485
|
* 获取实体仓库
|
|
1702
2486
|
* @param EntityType 实体类
|
|
1703
2487
|
*/
|
|
1704
2488
|
getRepository(n) {
|
|
1705
2489
|
if (!this.repository_cache.has(n)) {
|
|
1706
|
-
const
|
|
2490
|
+
const e = V(n), s = this.repository_map.get(e.repository);
|
|
1707
2491
|
if (!s)
|
|
1708
|
-
throw new
|
|
1709
|
-
const
|
|
1710
|
-
return this.repository_cache.set(n,
|
|
2492
|
+
throw new ee(`Repository '${e.repository}' not found`);
|
|
2493
|
+
const o = new s(this, n);
|
|
2494
|
+
return this.repository_cache.set(n, o), o;
|
|
1711
2495
|
}
|
|
1712
2496
|
return this.repository_cache.get(n);
|
|
1713
2497
|
}
|
|
@@ -1715,7 +2499,7 @@ class _n extends He {
|
|
|
1715
2499
|
* 连接 wab sqlite
|
|
1716
2500
|
*/
|
|
1717
2501
|
async connect() {
|
|
1718
|
-
return await this.#
|
|
2502
|
+
return await this.#s(), this;
|
|
1719
2503
|
}
|
|
1720
2504
|
/**
|
|
1721
2505
|
* 断开连接
|
|
@@ -1727,18 +2511,18 @@ class _n extends He {
|
|
|
1727
2511
|
* 获取版本
|
|
1728
2512
|
*/
|
|
1729
2513
|
async version() {
|
|
1730
|
-
return await (await this.#
|
|
2514
|
+
return await (await this.#s()).version();
|
|
1731
2515
|
}
|
|
1732
2516
|
/**
|
|
1733
2517
|
* 保存多个实体
|
|
1734
2518
|
* @param entities
|
|
1735
2519
|
*/
|
|
1736
2520
|
async saveMany(n) {
|
|
1737
|
-
const
|
|
2521
|
+
const e = Qe({
|
|
1738
2522
|
need_save_entities: n,
|
|
1739
2523
|
need_remove_entities: []
|
|
1740
2524
|
});
|
|
1741
|
-
return this.mutations(
|
|
2525
|
+
return this.mutations(e);
|
|
1742
2526
|
}
|
|
1743
2527
|
/**
|
|
1744
2528
|
* 删除多个实例
|
|
@@ -1746,26 +2530,26 @@ class _n extends He {
|
|
|
1746
2530
|
* @returns
|
|
1747
2531
|
*/
|
|
1748
2532
|
async removeMany(n) {
|
|
1749
|
-
const
|
|
2533
|
+
const e = Qe({
|
|
1750
2534
|
need_save_entities: [],
|
|
1751
2535
|
need_remove_entities: n
|
|
1752
2536
|
});
|
|
1753
|
-
return this.mutations(
|
|
2537
|
+
return this.mutations(e);
|
|
1754
2538
|
}
|
|
1755
2539
|
/**
|
|
1756
2540
|
* 批量修改实体(创建/更新/删除)
|
|
1757
2541
|
* @param options
|
|
1758
2542
|
*/
|
|
1759
2543
|
async mutations(n) {
|
|
1760
|
-
return this.#e ? await
|
|
2544
|
+
return this.#e ? await nt(this, n) : await this.transaction(() => nt(this, n));
|
|
1761
2545
|
}
|
|
1762
2546
|
/**
|
|
1763
2547
|
* 判断表是否存在
|
|
1764
2548
|
* @param EntityType
|
|
1765
2549
|
*/
|
|
1766
2550
|
async isTableExisted(n) {
|
|
1767
|
-
const
|
|
1768
|
-
return
|
|
2551
|
+
const e = V(n), s = X(e), { sql: o, params: a } = Dt(s), d = await this.#a(o, a);
|
|
2552
|
+
return qt(d) === !1;
|
|
1769
2553
|
}
|
|
1770
2554
|
/**
|
|
1771
2555
|
* 创建表和初始化数据
|
|
@@ -1773,9 +2557,9 @@ class _n extends He {
|
|
|
1773
2557
|
* @param entities 视图数据
|
|
1774
2558
|
* @returns
|
|
1775
2559
|
*/
|
|
1776
|
-
async createTables(n,
|
|
1777
|
-
const s =
|
|
1778
|
-
return await this.#
|
|
2560
|
+
async createTables(n, e) {
|
|
2561
|
+
const s = Hn(this, n, e);
|
|
2562
|
+
return await this.#a(s), !0;
|
|
1779
2563
|
}
|
|
1780
2564
|
/**
|
|
1781
2565
|
* 切换分支
|
|
@@ -1783,7 +2567,7 @@ class _n extends He {
|
|
|
1783
2567
|
* @returns
|
|
1784
2568
|
*/
|
|
1785
2569
|
async switchBranch(n) {
|
|
1786
|
-
return
|
|
2570
|
+
return Yn(this, n);
|
|
1787
2571
|
}
|
|
1788
2572
|
/**
|
|
1789
2573
|
* 应用压缩后的变更到本地实体表
|
|
@@ -1794,33 +2578,33 @@ class _n extends He {
|
|
|
1794
2578
|
* @param _localChanges - (已废弃)不再使用
|
|
1795
2579
|
* @param disableTriggers - 是否禁用触发器(用于 pull 等操作,避免创建 RxDBChange)
|
|
1796
2580
|
*/
|
|
1797
|
-
async mergeChanges(n,
|
|
1798
|
-
const
|
|
1799
|
-
await
|
|
2581
|
+
async mergeChanges(n, e, s = !1) {
|
|
2582
|
+
const o = _t(this, n);
|
|
2583
|
+
await Qn(this, o, s);
|
|
1800
2584
|
}
|
|
1801
2585
|
/**
|
|
1802
2586
|
* 缓存 RowId 与实体映射
|
|
1803
2587
|
* @param rowId
|
|
1804
2588
|
* @param entity
|
|
1805
2589
|
*/
|
|
1806
|
-
cacheRowIdEntity(n,
|
|
1807
|
-
this.#
|
|
2590
|
+
cacheRowIdEntity(n, e) {
|
|
2591
|
+
this.#u(e.constructor).set(n, e), this.#o.set(e, n);
|
|
1808
2592
|
}
|
|
1809
2593
|
/**
|
|
1810
2594
|
* 移除缓存实体映射
|
|
1811
2595
|
* @param entity
|
|
1812
2596
|
*/
|
|
1813
2597
|
removeCacheEntity(n) {
|
|
1814
|
-
const
|
|
1815
|
-
|
|
2598
|
+
const e = this.#o.get(n);
|
|
2599
|
+
e !== void 0 && (this.#u(n.constructor).delete(e), this.#o.delete(n));
|
|
1816
2600
|
}
|
|
1817
2601
|
/**
|
|
1818
2602
|
* 根据 RowId 获取实体
|
|
1819
2603
|
* @param rowId
|
|
1820
2604
|
* @returns
|
|
1821
2605
|
*/
|
|
1822
|
-
getEntityByRowId(n,
|
|
1823
|
-
return this.#
|
|
2606
|
+
getEntityByRowId(n, e) {
|
|
2607
|
+
return this.#u(e).get(n);
|
|
1824
2608
|
}
|
|
1825
2609
|
/**
|
|
1826
2610
|
* 根据实体获取 RowId
|
|
@@ -1834,13 +2618,13 @@ class _n extends He {
|
|
|
1834
2618
|
* 清空所有缓存
|
|
1835
2619
|
*/
|
|
1836
2620
|
cleanAllCache() {
|
|
1837
|
-
this.#
|
|
2621
|
+
this.#i.clear(), this.#o = /* @__PURE__ */ new WeakMap();
|
|
1838
2622
|
}
|
|
1839
2623
|
/**
|
|
1840
2624
|
* 执行 SQL 语句
|
|
1841
2625
|
*/
|
|
1842
|
-
query(n,
|
|
1843
|
-
return this.#t ? Promise.reject(new
|
|
2626
|
+
query(n, e) {
|
|
2627
|
+
return this.#t ? Promise.reject(new ee("Adapter is disconnected")) : this.#c.addTask(async () => (await this.rxdb.connect(this.name), (await this.#s()).execute(n, e)));
|
|
1844
2628
|
}
|
|
1845
2629
|
/**
|
|
1846
2630
|
* 执行事务
|
|
@@ -1848,41 +2632,41 @@ class _n extends He {
|
|
|
1848
2632
|
* @param transactionLog 是否生成事务日志
|
|
1849
2633
|
* @returns
|
|
1850
2634
|
*/
|
|
1851
|
-
async transaction(n,
|
|
2635
|
+
async transaction(n, e = !0) {
|
|
1852
2636
|
await this.rxdb.connect(this.name);
|
|
1853
|
-
const s = await this.#
|
|
1854
|
-
this.#e = !0, this.rxdb.dispatchEvent(
|
|
1855
|
-
let
|
|
1856
|
-
if (
|
|
1857
|
-
const
|
|
1858
|
-
if (!
|
|
2637
|
+
const s = await this.#s();
|
|
2638
|
+
this.#e = !0, this.rxdb.dispatchEvent(Jn);
|
|
2639
|
+
let o = "", a = "";
|
|
2640
|
+
if (e) {
|
|
2641
|
+
const d = St(), p = await this.rxdb.versionManager.getCurrentBranch();
|
|
2642
|
+
if (!p)
|
|
1859
2643
|
throw new Error("currentBranch is undefined! Cannot start transaction with logging.");
|
|
1860
|
-
|
|
2644
|
+
o = rt(this, p.id, d), a = rt(this, p.id);
|
|
1861
2645
|
}
|
|
1862
2646
|
await s.execute(`
|
|
1863
2647
|
BEGIN;
|
|
1864
2648
|
PRAGMA defer_foreign_keys = ON;
|
|
1865
|
-
${
|
|
2649
|
+
${o}
|
|
1866
2650
|
`);
|
|
1867
2651
|
try {
|
|
1868
|
-
const
|
|
1869
|
-
return await s.execute(`${
|
|
1870
|
-
COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(
|
|
1871
|
-
} catch (
|
|
2652
|
+
const d = await n(s);
|
|
2653
|
+
return await s.execute(`${a}
|
|
2654
|
+
COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
|
|
2655
|
+
} catch (d) {
|
|
1872
2656
|
try {
|
|
1873
2657
|
await s.execute("ROLLBACK");
|
|
1874
2658
|
} finally {
|
|
1875
|
-
this.#e = !1, this.rxdb.dispatchEvent(
|
|
2659
|
+
this.#e = !1, this.rxdb.dispatchEvent(Gn);
|
|
1876
2660
|
}
|
|
1877
|
-
const
|
|
1878
|
-
throw new
|
|
2661
|
+
const p = d?.message || "Transaction Error";
|
|
2662
|
+
throw new ee(p, { cause: d });
|
|
1879
2663
|
}
|
|
1880
2664
|
}
|
|
1881
2665
|
/**
|
|
1882
2666
|
* 本地分支仓库
|
|
1883
2667
|
*/
|
|
1884
2668
|
localRxDBBranch() {
|
|
1885
|
-
return this.getRepository(
|
|
2669
|
+
return this.getRepository(_e);
|
|
1886
2670
|
}
|
|
1887
2671
|
/**
|
|
1888
2672
|
* 内部查询
|
|
@@ -1890,30 +2674,30 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
1890
2674
|
* @param sql
|
|
1891
2675
|
* @returns
|
|
1892
2676
|
*/
|
|
1893
|
-
internalQuery(n,
|
|
1894
|
-
return this.#
|
|
2677
|
+
internalQuery(n, e) {
|
|
2678
|
+
return this.#a(n, e);
|
|
1895
2679
|
}
|
|
1896
2680
|
/**
|
|
1897
2681
|
* 本地变更仓库
|
|
1898
2682
|
*/
|
|
1899
2683
|
localRxDBChange() {
|
|
1900
|
-
return this.getRepository(
|
|
2684
|
+
return this.getRepository(pe);
|
|
1901
2685
|
}
|
|
1902
2686
|
/**
|
|
1903
2687
|
* 获取 RxDBChange 表的当前序列值
|
|
1904
2688
|
* @returns
|
|
1905
2689
|
*/
|
|
1906
2690
|
async getRxDBChangeSequence() {
|
|
1907
|
-
const n =
|
|
1908
|
-
return (await this.#
|
|
2691
|
+
const n = Xe(pe);
|
|
2692
|
+
return (await this.#a("SELECT seq FROM sqlite_sequence WHERE name = ?", [n])).results[0]?.rows?.[0]?.[0] ?? 0;
|
|
1909
2693
|
}
|
|
1910
2694
|
/**
|
|
1911
2695
|
* 设置 RxDBChange 表的序列值
|
|
1912
2696
|
* @param sequence 序列值
|
|
1913
2697
|
*/
|
|
1914
2698
|
async setRxDBChangeSequence(n) {
|
|
1915
|
-
const
|
|
1916
|
-
await this.#
|
|
2699
|
+
const e = Xe(pe);
|
|
2700
|
+
await this.#a("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [n, e]);
|
|
1917
2701
|
}
|
|
1918
2702
|
// ============================================
|
|
1919
2703
|
// QueryCache 方法
|
|
@@ -1933,18 +2717,18 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
1933
2717
|
* .subscribe(map => console.log(map.get('id1')));
|
|
1934
2718
|
* ```
|
|
1935
2719
|
*/
|
|
1936
|
-
getMetadataByIds(n,
|
|
1937
|
-
return
|
|
1938
|
-
if (
|
|
1939
|
-
return
|
|
1940
|
-
const s =
|
|
1941
|
-
return
|
|
1942
|
-
|
|
1943
|
-
const
|
|
1944
|
-
if (
|
|
1945
|
-
for (const
|
|
1946
|
-
|
|
1947
|
-
return
|
|
2720
|
+
getMetadataByIds(n, e) {
|
|
2721
|
+
return Le(() => {
|
|
2722
|
+
if (e.length === 0)
|
|
2723
|
+
return Me(/* @__PURE__ */ new Map());
|
|
2724
|
+
const s = e.map(() => "?").join(", "), o = `SELECT id, updatedAt FROM "${n}" WHERE id IN (${s})`;
|
|
2725
|
+
return Oe(this.internalQuery(o, e)).pipe(
|
|
2726
|
+
xt((a) => {
|
|
2727
|
+
const d = /* @__PURE__ */ new Map();
|
|
2728
|
+
if (a.results?.[0]?.rows)
|
|
2729
|
+
for (const p of a.results[0].rows)
|
|
2730
|
+
d.set(p[0], p[1]);
|
|
2731
|
+
return d;
|
|
1948
2732
|
})
|
|
1949
2733
|
);
|
|
1950
2734
|
});
|
|
@@ -1964,11 +2748,11 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
1964
2748
|
* .subscribe(() => console.log('upserted'));
|
|
1965
2749
|
* ```
|
|
1966
2750
|
*/
|
|
1967
|
-
upsertMany(n,
|
|
1968
|
-
return
|
|
2751
|
+
upsertMany(n, e) {
|
|
2752
|
+
return Le(() => e.length === 0 ? Me(void 0) : Oe(
|
|
1969
2753
|
(async () => {
|
|
1970
|
-
const s = Object.keys(
|
|
1971
|
-
await this.internalQuery(
|
|
2754
|
+
const s = Object.keys(e[0]), o = `(${s.map(() => "?").join(", ")})`, a = e.map(() => o).join(", "), d = `INSERT OR REPLACE INTO "${n}" (${s.join(", ")}) VALUES ${a}`, p = e.flatMap((f) => s.map((b) => f[b]));
|
|
2755
|
+
await this.internalQuery(d, p);
|
|
1972
2756
|
})()
|
|
1973
2757
|
));
|
|
1974
2758
|
}
|
|
@@ -1985,12 +2769,12 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
1985
2769
|
* .subscribe(() => console.log('deleted'));
|
|
1986
2770
|
* ```
|
|
1987
2771
|
*/
|
|
1988
|
-
deleteByIds(n,
|
|
1989
|
-
return
|
|
1990
|
-
if (
|
|
1991
|
-
return
|
|
1992
|
-
const s =
|
|
1993
|
-
return
|
|
2772
|
+
deleteByIds(n, e) {
|
|
2773
|
+
return Le(() => {
|
|
2774
|
+
if (e.length === 0)
|
|
2775
|
+
return Me(void 0);
|
|
2776
|
+
const s = e.map(() => "?").join(", "), o = `DELETE FROM "${n}" WHERE id IN (${s})`;
|
|
2777
|
+
return Oe(this.internalQuery(o, e).then(() => {
|
|
1994
2778
|
}));
|
|
1995
2779
|
});
|
|
1996
2780
|
}
|
|
@@ -2000,13 +2784,13 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
2000
2784
|
/**
|
|
2001
2785
|
* 获取 SQLite 客户端
|
|
2002
2786
|
*/
|
|
2003
|
-
#
|
|
2004
|
-
return this.#
|
|
2787
|
+
#s() {
|
|
2788
|
+
return this.#r || (this.#r = Rn(this.rxdb.config.dbName, this.options).then(
|
|
2005
2789
|
(n) => (this.#n = n, n),
|
|
2006
2790
|
(n) => {
|
|
2007
|
-
throw this.#
|
|
2791
|
+
throw this.#r = void 0, n;
|
|
2008
2792
|
}
|
|
2009
|
-
)), this.#
|
|
2793
|
+
)), this.#r;
|
|
2010
2794
|
}
|
|
2011
2795
|
/**
|
|
2012
2796
|
* 内部执行 sql
|
|
@@ -2014,23 +2798,23 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
|
|
|
2014
2798
|
* @param sql
|
|
2015
2799
|
* @param bindings
|
|
2016
2800
|
*/
|
|
2017
|
-
async #
|
|
2018
|
-
return await (await this.#
|
|
2801
|
+
async #a(n, e) {
|
|
2802
|
+
return await (await this.#s()).execute(n, e);
|
|
2019
2803
|
}
|
|
2020
|
-
#
|
|
2021
|
-
return this.#
|
|
2804
|
+
#u(n) {
|
|
2805
|
+
return this.#i.has(n) === !1 && this.#i.set(n, /* @__PURE__ */ new Map()), this.#i.get(n);
|
|
2022
2806
|
}
|
|
2023
2807
|
}
|
|
2024
|
-
const
|
|
2808
|
+
const Jn = new At(), Gn = new It(), Xn = new Tt();
|
|
2025
2809
|
export {
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2810
|
+
ie as ROWID,
|
|
2811
|
+
rr as RxDBAdapterSqlite,
|
|
2812
|
+
ee as RxDBAdapterSqliteError,
|
|
2813
|
+
Tn as SqliteClient,
|
|
2814
|
+
ht as SqliteRepository,
|
|
2815
|
+
_n as WA_SQLITE_VFS_LIST,
|
|
2816
|
+
he as buildRuleGroup,
|
|
2817
|
+
le as sqliteGetTableName,
|
|
2818
|
+
X as sqliteGetTableNameByMetadata,
|
|
2819
|
+
wn as sqliteLoad
|
|
2036
2820
|
};
|