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