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