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