@rozenite/sqlite-plugin 1.7.0-rc.0
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/CHANGELOG.md +8 -0
- package/LICENSE +20 -0
- package/README.md +102 -0
- package/dist/devtools/assets/panel-B3paLkwG.js +82 -0
- package/dist/devtools/assets/panel-CIU0JBOs.css +1 -0
- package/dist/devtools/panel.html +31 -0
- package/dist/react-native/chunks/bridge-values.cjs +5 -0
- package/dist/react-native/chunks/bridge-values.js +258 -0
- package/dist/react-native/chunks/index.require.cjs +1 -0
- package/dist/react-native/chunks/index.require.js +118 -0
- package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.cjs +1 -0
- package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.js +189 -0
- package/dist/react-native/index.cjs +1 -0
- package/dist/react-native/index.d.ts +178 -0
- package/dist/react-native/index.js +16 -0
- package/dist/rozenite.json +1 -0
- package/package.json +83 -0
- package/postcss.config.js +6 -0
- package/react-native.ts +55 -0
- package/rozenite.config.ts +8 -0
- package/src/react-native/adapters/__tests__/expo-sqlite.test.ts +94 -0
- package/src/react-native/adapters/expo-sqlite.ts +230 -0
- package/src/react-native/adapters/generic.ts +88 -0
- package/src/react-native/adapters/index.ts +9 -0
- package/src/react-native/sqlite-view.ts +24 -0
- package/src/react-native/useRozeniteSqlitePlugin.ts +262 -0
- package/src/shared/__tests__/bridge-values.test.ts +34 -0
- package/src/shared/__tests__/sql.test.ts +55 -0
- package/src/shared/bridge-values.ts +170 -0
- package/src/shared/protocol.ts +41 -0
- package/src/shared/sql.ts +420 -0
- package/src/shared/types.ts +81 -0
- package/src/ui/__tests__/sql-editor-utils.test.ts +135 -0
- package/src/ui/__tests__/sqlite-row-edit-value.test.ts +22 -0
- package/src/ui/__tests__/sqlite-row-mutations.test.ts +310 -0
- package/src/ui/__tests__/sqlite-table-column-order.test.ts +83 -0
- package/src/ui/__tests__/value-utils.test.tsx +12 -0
- package/src/ui/cell-detail-drawer.tsx +65 -0
- package/src/ui/globals.css +1415 -0
- package/src/ui/panel.tsx +2815 -0
- package/src/ui/query-result-table.tsx +199 -0
- package/src/ui/sql-editor-utils.ts +352 -0
- package/src/ui/sql-editor.tsx +509 -0
- package/src/ui/sqlite-data-table.tsx +296 -0
- package/src/ui/sqlite-introspection.ts +189 -0
- package/src/ui/sqlite-modal-controls.tsx +32 -0
- package/src/ui/sqlite-row-delete-modal.tsx +130 -0
- package/src/ui/sqlite-row-edit-modal.tsx +487 -0
- package/src/ui/sqlite-row-edit-value.ts +53 -0
- package/src/ui/sqlite-row-mutations.ts +246 -0
- package/src/ui/sqlite-table-column-order.ts +154 -0
- package/src/ui/use-sqlite-requests.ts +205 -0
- package/src/ui/utils.ts +107 -0
- package/src/ui/value-utils.tsx +162 -0
- package/tsconfig.json +36 -0
- package/vite.config.ts +20 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>panel Panel</title>
|
|
7
|
+
<style>
|
|
8
|
+
html,
|
|
9
|
+
body {
|
|
10
|
+
height: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
body {
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#root {
|
|
18
|
+
display: flex;
|
|
19
|
+
height: 100%;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
<script>
|
|
23
|
+
var __ROZENITE_PANEL__ = true;
|
|
24
|
+
</script>
|
|
25
|
+
<script type="module" crossorigin src="../devtools/assets/panel-B3paLkwG.js"></script>
|
|
26
|
+
<link rel="stylesheet" crossorigin href="../devtools/assets/panel-CIU0JBOs.css">
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<div id="root"></div>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";const m=t=>/\s/.test(t),g=t=>{let n=0,c=!1,i=0,e=null;for(;i<t.length;){const o=t[i],u=t[i+1];if(e==="line-comment"){o===`
|
|
2
|
+
`&&(e=null),i+=1;continue}if(e==="block-comment"){if(o==="*"&&u==="/"){e=null,i+=2;continue}i+=1;continue}if(e==="single-quote"){if(o==="'"&&u==="'"){i+=2;continue}o==="'"&&(e=null),i+=1;continue}if(e==="double-quote"){if(o==='"'&&u==='"'){i+=2;continue}o==='"'&&(e=null),i+=1;continue}if(e==="backtick"){if(o==="`"&&u==="`"){i+=2;continue}o==="`"&&(e=null),i+=1;continue}if(e==="bracket"){if(o==="]"&&u==="]"){i+=2;continue}o==="]"&&(e=null),i+=1;continue}if(o==="-"&&u==="-"){e="line-comment",i+=2;continue}if(o==="/"&&u==="*"){e="block-comment",i+=2;continue}if(o==="'"){e="single-quote",c=!0,i+=1;continue}if(o==='"'){e="double-quote",c=!0,i+=1;continue}if(o==="`"){e="backtick",c=!0,i+=1;continue}if(o==="["){e="bracket",c=!0,i+=1;continue}if(o===";"){c&&(n+=1,c=!1),i+=1;continue}m(o)||(c=!0),i+=1}return c&&(n+=1),n},h=t=>{const n=[];let c=!1,i=0,e=0,o=null;const u=r=>{const s=t.slice(i,r).trim();s&&n.push({text:s,start:i,end:r}),i=r+1,c=!1};for(;e<t.length;){const r=t[e],s=t[e+1];if(o==="line-comment"){r===`
|
|
3
|
+
`&&(o=null),e+=1;continue}if(o==="block-comment"){if(r==="*"&&s==="/"){o=null,e+=2;continue}e+=1;continue}if(o==="single-quote"){if(r==="'"&&s==="'"){e+=2;continue}r==="'"&&(o=null),e+=1;continue}if(o==="double-quote"){if(r==='"'&&s==='"'){e+=2;continue}r==='"'&&(o=null),e+=1;continue}if(o==="backtick"){if(r==="`"&&s==="`"){e+=2;continue}r==="`"&&(o=null),e+=1;continue}if(o==="bracket"){if(r==="]"&&s==="]"){e+=2;continue}r==="]"&&(o=null),e+=1;continue}if(r==="-"&&s==="-"){o="line-comment",e+=2;continue}if(r==="/"&&s==="*"){o="block-comment",e+=2;continue}if(r==="'"){o="single-quote",c=!0,e+=1;continue}if(r==='"'){o="double-quote",c=!0,e+=1;continue}if(r==="`"){o="backtick",c=!0,e+=1;continue}if(r==="["){o="bracket",c=!0,e+=1;continue}if(r===";"){c?u(e):i=e+1,e+=1;continue}m(r)||(c=!0),e+=1}return c&&u(t.length),n},S=t=>{const n=g(t);if(n===0)throw new Error("Query cannot be empty.");if(n>1)throw new Error("Only a single SQL statement is supported in v1.");return t.trim().replace(/;\s*$/,"").trim()},b=t=>{let n=0;for(;n<t.length;){const i=t[n],e=t[n+1];if(m(i)){n+=1;continue}if(i==="-"&&e==="-"){for(n+=2;n<t.length&&t[n]!==`
|
|
4
|
+
`;)n+=1;continue}if(i==="/"&&e==="*"){for(n+=2;n<t.length&&!(t[n]==="*"&&t[n+1]==="/");)n+=1;n+=2;continue}break}const c=n;for(;n<t.length&&/[A-Za-z]/.test(t[n]);)n+=1;return t.slice(c,n).toLowerCase()},p=t=>{const n=b(t);return n==="select"||n==="insert"||n==="update"||n==="delete"||n==="pragma"||n==="create"||n==="alter"||n==="drop"||n==="explain"||n==="with"?n:"other"},y=t=>t==="select"||t==="pragma"||t==="explain"||t==="with",k="__rozeniteSqliteBinary",f=t=>!!t&&typeof t=="object",w=t=>f(t)&&t[k]===!0&&Array.isArray(t.data)&&t.data.every(n=>typeof n=="number"),a=t=>t==null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:w(t)?new Uint8Array(t.data):Array.isArray(t)?t.map(a):f(t)?Object.fromEntries(Object.entries(t).map(([n,c])=>[n,a(c)])):t,l=(t,n)=>{if(!f(t))return null;const c=t[n];if(typeof c!="string")return null;const i=c.trim();return i||null},d=t=>{try{return JSON.stringify(t)}catch{return String(t)}},E=t=>{if(t instanceof Error){const n=l(t,"code"),c=l(t,"reason"),o=[t.message.trim()||null,c].filter((u,r,s)=>!!u&&s.indexOf(u)===r).join(" | ")||t.name;return n?`[${n}] ${o}`:o}if(f(t)){const n=l(t,"code"),c=l(t,"message"),i=l(t,"reason"),e=c??i??d(t);return n?`[${n}] ${e}`:e}return typeof t=="string"?t.trim()||null:t==null?null:d(t)},x=t=>{if(f(t))return t.cause},A=t=>{const n=new Set,c=[];let i=t;for(;i!=null&&!n.has(i);){n.add(i);const e=E(i);e&&!c.includes(e)&&c.push(e),i=x(i)}return c.join(`
|
|
5
|
+
Caused by: `)||"Unknown SQLite error."};exports.classifySqlStatement=p;exports.decodeSqliteBridgeValue=a;exports.formatSqliteError=A;exports.normalizeSingleStatementSql=S;exports.splitSqlStatements=h;exports.statementReturnsRows=y;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const a = (t) => /\s/.test(t), g = (t) => {
|
|
2
|
+
let n = 0, c = !1, i = 0, e = null;
|
|
3
|
+
for (; i < t.length; ) {
|
|
4
|
+
const o = t[i], u = t[i + 1];
|
|
5
|
+
if (e === "line-comment") {
|
|
6
|
+
o === `
|
|
7
|
+
` && (e = null), i += 1;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (e === "block-comment") {
|
|
11
|
+
if (o === "*" && u === "/") {
|
|
12
|
+
e = null, i += 2;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
i += 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (e === "single-quote") {
|
|
19
|
+
if (o === "'" && u === "'") {
|
|
20
|
+
i += 2;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
o === "'" && (e = null), i += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (e === "double-quote") {
|
|
27
|
+
if (o === '"' && u === '"') {
|
|
28
|
+
i += 2;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
o === '"' && (e = null), i += 1;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (e === "backtick") {
|
|
35
|
+
if (o === "`" && u === "`") {
|
|
36
|
+
i += 2;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
o === "`" && (e = null), i += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (e === "bracket") {
|
|
43
|
+
if (o === "]" && u === "]") {
|
|
44
|
+
i += 2;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
o === "]" && (e = null), i += 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (o === "-" && u === "-") {
|
|
51
|
+
e = "line-comment", i += 2;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (o === "/" && u === "*") {
|
|
55
|
+
e = "block-comment", i += 2;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (o === "'") {
|
|
59
|
+
e = "single-quote", c = !0, i += 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (o === '"') {
|
|
63
|
+
e = "double-quote", c = !0, i += 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (o === "`") {
|
|
67
|
+
e = "backtick", c = !0, i += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (o === "[") {
|
|
71
|
+
e = "bracket", c = !0, i += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (o === ";") {
|
|
75
|
+
c && (n += 1, c = !1), i += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
a(o) || (c = !0), i += 1;
|
|
79
|
+
}
|
|
80
|
+
return c && (n += 1), n;
|
|
81
|
+
}, S = (t) => {
|
|
82
|
+
const n = [];
|
|
83
|
+
let c = !1, i = 0, e = 0, o = null;
|
|
84
|
+
const u = (r) => {
|
|
85
|
+
const s = t.slice(i, r).trim();
|
|
86
|
+
s && n.push({
|
|
87
|
+
text: s,
|
|
88
|
+
start: i,
|
|
89
|
+
end: r
|
|
90
|
+
}), i = r + 1, c = !1;
|
|
91
|
+
};
|
|
92
|
+
for (; e < t.length; ) {
|
|
93
|
+
const r = t[e], s = t[e + 1];
|
|
94
|
+
if (o === "line-comment") {
|
|
95
|
+
r === `
|
|
96
|
+
` && (o = null), e += 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (o === "block-comment") {
|
|
100
|
+
if (r === "*" && s === "/") {
|
|
101
|
+
o = null, e += 2;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
e += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (o === "single-quote") {
|
|
108
|
+
if (r === "'" && s === "'") {
|
|
109
|
+
e += 2;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
r === "'" && (o = null), e += 1;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (o === "double-quote") {
|
|
116
|
+
if (r === '"' && s === '"') {
|
|
117
|
+
e += 2;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
r === '"' && (o = null), e += 1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (o === "backtick") {
|
|
124
|
+
if (r === "`" && s === "`") {
|
|
125
|
+
e += 2;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
r === "`" && (o = null), e += 1;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (o === "bracket") {
|
|
132
|
+
if (r === "]" && s === "]") {
|
|
133
|
+
e += 2;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
r === "]" && (o = null), e += 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (r === "-" && s === "-") {
|
|
140
|
+
o = "line-comment", e += 2;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (r === "/" && s === "*") {
|
|
144
|
+
o = "block-comment", e += 2;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (r === "'") {
|
|
148
|
+
o = "single-quote", c = !0, e += 1;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (r === '"') {
|
|
152
|
+
o = "double-quote", c = !0, e += 1;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (r === "`") {
|
|
156
|
+
o = "backtick", c = !0, e += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (r === "[") {
|
|
160
|
+
o = "bracket", c = !0, e += 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (r === ";") {
|
|
164
|
+
c ? u(e) : i = e + 1, e += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
a(r) || (c = !0), e += 1;
|
|
168
|
+
}
|
|
169
|
+
return c && u(t.length), n;
|
|
170
|
+
}, w = (t) => {
|
|
171
|
+
const n = g(t);
|
|
172
|
+
if (n === 0)
|
|
173
|
+
throw new Error("Query cannot be empty.");
|
|
174
|
+
if (n > 1)
|
|
175
|
+
throw new Error("Only a single SQL statement is supported in v1.");
|
|
176
|
+
return t.trim().replace(/;\s*$/, "").trim();
|
|
177
|
+
}, h = (t) => {
|
|
178
|
+
let n = 0;
|
|
179
|
+
for (; n < t.length; ) {
|
|
180
|
+
const i = t[n], e = t[n + 1];
|
|
181
|
+
if (a(i)) {
|
|
182
|
+
n += 1;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (i === "-" && e === "-") {
|
|
186
|
+
for (n += 2; n < t.length && t[n] !== `
|
|
187
|
+
`; )
|
|
188
|
+
n += 1;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (i === "/" && e === "*") {
|
|
192
|
+
for (n += 2; n < t.length && !(t[n] === "*" && t[n + 1] === "/"); )
|
|
193
|
+
n += 1;
|
|
194
|
+
n += 2;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
const c = n;
|
|
200
|
+
for (; n < t.length && /[A-Za-z]/.test(t[n]); )
|
|
201
|
+
n += 1;
|
|
202
|
+
return t.slice(c, n).toLowerCase();
|
|
203
|
+
}, E = (t) => {
|
|
204
|
+
const n = h(t);
|
|
205
|
+
return n === "select" || n === "insert" || n === "update" || n === "delete" || n === "pragma" || n === "create" || n === "alter" || n === "drop" || n === "explain" || n === "with" ? n : "other";
|
|
206
|
+
}, x = (t) => t === "select" || t === "pragma" || t === "explain" || t === "with", b = "__rozeniteSqliteBinary", l = (t) => !!t && typeof t == "object", p = (t) => l(t) && t[b] === !0 && Array.isArray(t.data) && t.data.every((n) => typeof n == "number"), m = (t) => t == null || typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? t : p(t) ? new Uint8Array(t.data) : Array.isArray(t) ? t.map(m) : l(t) ? Object.fromEntries(
|
|
207
|
+
Object.entries(t).map(([n, c]) => [
|
|
208
|
+
n,
|
|
209
|
+
m(c)
|
|
210
|
+
])
|
|
211
|
+
) : t, f = (t, n) => {
|
|
212
|
+
if (!l(t))
|
|
213
|
+
return null;
|
|
214
|
+
const c = t[n];
|
|
215
|
+
if (typeof c != "string")
|
|
216
|
+
return null;
|
|
217
|
+
const i = c.trim();
|
|
218
|
+
return i || null;
|
|
219
|
+
}, d = (t) => {
|
|
220
|
+
try {
|
|
221
|
+
return JSON.stringify(t);
|
|
222
|
+
} catch {
|
|
223
|
+
return String(t);
|
|
224
|
+
}
|
|
225
|
+
}, k = (t) => {
|
|
226
|
+
if (t instanceof Error) {
|
|
227
|
+
const n = f(t, "code"), c = f(t, "reason"), o = [t.message.trim() || null, c].filter(
|
|
228
|
+
(u, r, s) => !!u && s.indexOf(u) === r
|
|
229
|
+
).join(" | ") || t.name;
|
|
230
|
+
return n ? `[${n}] ${o}` : o;
|
|
231
|
+
}
|
|
232
|
+
if (l(t)) {
|
|
233
|
+
const n = f(t, "code"), c = f(t, "message"), i = f(t, "reason"), e = c ?? i ?? d(t);
|
|
234
|
+
return n ? `[${n}] ${e}` : e;
|
|
235
|
+
}
|
|
236
|
+
return typeof t == "string" ? t.trim() || null : t == null ? null : d(t);
|
|
237
|
+
}, y = (t) => {
|
|
238
|
+
if (l(t))
|
|
239
|
+
return t.cause;
|
|
240
|
+
}, A = (t) => {
|
|
241
|
+
const n = /* @__PURE__ */ new Set(), c = [];
|
|
242
|
+
let i = t;
|
|
243
|
+
for (; i != null && !n.has(i); ) {
|
|
244
|
+
n.add(i);
|
|
245
|
+
const e = k(i);
|
|
246
|
+
e && !c.includes(e) && c.push(e), i = y(i);
|
|
247
|
+
}
|
|
248
|
+
return c.join(`
|
|
249
|
+
Caused by: `) || "Unknown SQLite error.";
|
|
250
|
+
};
|
|
251
|
+
export {
|
|
252
|
+
S as a,
|
|
253
|
+
E as c,
|
|
254
|
+
m as d,
|
|
255
|
+
A as f,
|
|
256
|
+
w as n,
|
|
257
|
+
x as s
|
|
258
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./bridge-values.cjs"),w=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"database",g=(e,a,t)=>`${e}__${w(a)}__${t.toString(36)}`,A=e=>typeof e=="function"?{executeStatements:e}:e,u=(e,a,t,r,n)=>{const o=A(t),s=o.name??n??a;return{id:g(e,`${a}-${s}`,r),name:s,executeStatements:o.executeStatements}},p=e=>{const{adapterId:a="sqlite",adapterName:t="SQLite"}=e,r="databases"in e?Object.entries(e.databases).map(([n,o],s)=>u(a,n,o,s)):[u(a,e.databaseName??"default",e.database,0,e.databaseName??"Default Database")];return{id:a,name:t,databases:r}},m=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),x=e=>c.formatSqliteError(e),I=(e,a={})=>Object.assign(new Error(e),a),l=e=>e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?e:e instanceof Uint8Array?Array.from(e):e instanceof ArrayBuffer?Array.from(new Uint8Array(e)):Array.isArray(e)?e.map(l):typeof e=="object"?Object.fromEntries(Object.entries(e).map(([a,t])=>[a,l(t)])):String(e),E=e=>e.map(a=>Object.fromEntries(Object.entries(a).map(([t,r])=>[t,l(r)]))),q=async(e,{sql:a,params:t})=>{const r=c.normalizeSingleStatementSql(a),n=c.classifySqlStatement(r),o=m(),s=t===void 0?void 0:c.decodeSqliteBridgeValue(t);if(c.statementReturnsRows(n)){const i=E(s===void 0?await e.getAllAsync(r):await e.getAllAsync(r,s)),y=m()-o;return{rows:i,columns:Object.keys(i[0]??{}),metadata:{statementType:n,rowCount:i.length,changes:null,lastInsertRowId:null,durationMs:y}}}const d=s===void 0?await e.runAsync(r):await e.runAsync(r,s),S=m()-o;return{rows:[],columns:[],metadata:{statementType:n,rowCount:0,changes:typeof d.changes=="number"?d.changes:null,lastInsertRowId:typeof d.lastInsertRowId=="number"?d.lastInsertRowId:null,durationMs:S}}},f=e=>async a=>{const t=[];for(let r=0;r<a.length;r+=1)try{t.push(await q(e,a[r]))}catch(n){throw I(x(n),{completedResults:t,failedStatementIndex:r,cause:n})}return t},b=e=>"database"in e?e:{database:e},j=e=>{const a="databases"in e?{adapterId:e.adapterId??"expo-sqlite",adapterName:e.adapterName??"Expo SQLite",databases:Object.fromEntries(Object.entries(e.databases).map(([t,r])=>{const n=b(r);return[t,{name:n.name??t,executeStatements:f(n.database)}]}))}:{adapterId:e.adapterId??"expo-sqlite",adapterName:e.adapterName??"Expo SQLite",databaseName:e.databaseName,database:(()=>{const t=b(e.database);return{name:t.name??e.databaseName,executeStatements:f(t.database)}})()};return p(a)};exports.createExpoSqliteAdapter=j;exports.createSqliteAdapter=p;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { f as S, n as y, c as w, d as g, s as x } from "./bridge-values.js";
|
|
2
|
+
const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "database", I = (e, a, t) => `${e}__${A(a)}__${t.toString(36)}`, E = (e) => typeof e == "function" ? { executeStatements: e } : e, l = (e, a, t, r, n) => {
|
|
3
|
+
const o = E(t), s = o.name ?? n ?? a;
|
|
4
|
+
return {
|
|
5
|
+
id: I(e, `${a}-${s}`, r),
|
|
6
|
+
name: s,
|
|
7
|
+
executeStatements: o.executeStatements
|
|
8
|
+
};
|
|
9
|
+
}, N = (e) => {
|
|
10
|
+
const { adapterId: a = "sqlite", adapterName: t = "SQLite" } = e, r = "databases" in e ? Object.entries(e.databases).map(
|
|
11
|
+
([n, o], s) => l(a, n, o, s)
|
|
12
|
+
) : [
|
|
13
|
+
l(
|
|
14
|
+
a,
|
|
15
|
+
e.databaseName ?? "default",
|
|
16
|
+
e.database,
|
|
17
|
+
0,
|
|
18
|
+
e.databaseName ?? "Default Database"
|
|
19
|
+
)
|
|
20
|
+
];
|
|
21
|
+
return {
|
|
22
|
+
id: a,
|
|
23
|
+
name: t,
|
|
24
|
+
databases: r
|
|
25
|
+
};
|
|
26
|
+
}, m = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), j = (e) => S(e), q = (e, a = {}) => Object.assign(new Error(e), a), i = (e) => e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : e instanceof Uint8Array ? Array.from(e) : e instanceof ArrayBuffer ? Array.from(new Uint8Array(e)) : Array.isArray(e) ? e.map(i) : typeof e == "object" ? Object.fromEntries(
|
|
27
|
+
Object.entries(e).map(([a, t]) => [
|
|
28
|
+
a,
|
|
29
|
+
i(t)
|
|
30
|
+
])
|
|
31
|
+
) : String(e), O = (e) => e.map(
|
|
32
|
+
(a) => Object.fromEntries(
|
|
33
|
+
Object.entries(a).map(([t, r]) => [
|
|
34
|
+
t,
|
|
35
|
+
i(r)
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
), h = async (e, { sql: a, params: t }) => {
|
|
39
|
+
const r = y(a), n = w(r), o = m(), s = t === void 0 ? void 0 : g(t);
|
|
40
|
+
if (x(n)) {
|
|
41
|
+
const d = O(
|
|
42
|
+
s === void 0 ? await e.getAllAsync(r) : await e.getAllAsync(r, s)
|
|
43
|
+
), p = m() - o;
|
|
44
|
+
return {
|
|
45
|
+
rows: d,
|
|
46
|
+
columns: Object.keys(d[0] ?? {}),
|
|
47
|
+
metadata: {
|
|
48
|
+
statementType: n,
|
|
49
|
+
rowCount: d.length,
|
|
50
|
+
changes: null,
|
|
51
|
+
lastInsertRowId: null,
|
|
52
|
+
durationMs: p
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const c = s === void 0 ? await e.runAsync(r) : await e.runAsync(r, s), b = m() - o;
|
|
57
|
+
return {
|
|
58
|
+
rows: [],
|
|
59
|
+
columns: [],
|
|
60
|
+
metadata: {
|
|
61
|
+
statementType: n,
|
|
62
|
+
rowCount: 0,
|
|
63
|
+
changes: typeof c.changes == "number" ? c.changes : null,
|
|
64
|
+
lastInsertRowId: typeof c.lastInsertRowId == "number" ? c.lastInsertRowId : null,
|
|
65
|
+
durationMs: b
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, u = (e) => async (a) => {
|
|
69
|
+
const t = [];
|
|
70
|
+
for (let r = 0; r < a.length; r += 1)
|
|
71
|
+
try {
|
|
72
|
+
t.push(await h(e, a[r]));
|
|
73
|
+
} catch (n) {
|
|
74
|
+
throw q(j(n), {
|
|
75
|
+
completedResults: t,
|
|
76
|
+
failedStatementIndex: r,
|
|
77
|
+
cause: n
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return t;
|
|
81
|
+
}, f = (e) => "database" in e ? e : { database: e }, D = (e) => {
|
|
82
|
+
const a = "databases" in e ? {
|
|
83
|
+
adapterId: e.adapterId ?? "expo-sqlite",
|
|
84
|
+
adapterName: e.adapterName ?? "Expo SQLite",
|
|
85
|
+
databases: Object.fromEntries(
|
|
86
|
+
Object.entries(e.databases).map(([t, r]) => {
|
|
87
|
+
const n = f(r);
|
|
88
|
+
return [
|
|
89
|
+
t,
|
|
90
|
+
{
|
|
91
|
+
name: n.name ?? t,
|
|
92
|
+
executeStatements: u(
|
|
93
|
+
n.database
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
} : {
|
|
100
|
+
adapterId: e.adapterId ?? "expo-sqlite",
|
|
101
|
+
adapterName: e.adapterName ?? "Expo SQLite",
|
|
102
|
+
databaseName: e.databaseName,
|
|
103
|
+
database: (() => {
|
|
104
|
+
const t = f(e.database);
|
|
105
|
+
return {
|
|
106
|
+
name: t.name ?? e.databaseName,
|
|
107
|
+
executeStatements: u(
|
|
108
|
+
t.database
|
|
109
|
+
)
|
|
110
|
+
};
|
|
111
|
+
})()
|
|
112
|
+
};
|
|
113
|
+
return N(a);
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
D as createExpoSqliteAdapter,
|
|
117
|
+
N as createSqliteAdapter
|
|
118
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@rozenite/plugin-bridge"),h=require("react"),f=require("./bridge-values.cjs"),v="@rozenite/sqlite-plugin",M=a=>a.flatMap(l=>l.databases.map(s=>({id:s.id,name:s.name,adapterId:l.id,adapterName:l.name,executeStatements:s.executeStatements}))),q=a=>f.formatSqliteError(a),b=a=>a instanceof Error&&("completedResults"in a||"failedStatementIndex"in a),z=({adapters:a})=>{const l=h.useMemo(()=>M(a),[a]),s=R.useRozeniteDevToolsClient({pluginId:v}),m=h.useRef([]),S=h.useRef(new Map);return h.useEffect(()=>{if(!s)return;const g=async(n,t)=>{const r=(S.current.get(n)??Promise.resolve()).catch(()=>{}).then(t);return S.current.set(n,r.then(()=>{},()=>{})),r},w=n=>{const t=l.find(o=>o.id===n);if(!t)throw new Error(`Unknown database "${n}".`);return t},y=async(n,t)=>{const o=w(n),r=t.map(({sql:i,params:u})=>({sql:f.normalizeSingleStatementSql(i),params:u})),e=await o.executeStatements(r);if(e.length!==r.length)throw new Error(`Expected ${r.length} statement result(s), received ${e.length}.`);return{inputs:r,results:e}},x=async(n,t,o)=>{const e=(await y(n,[{sql:t,params:o}])).results[0];if(!e)throw new Error("The query completed without a result payload.");return e};return s.send("sqlite:ready",{timestamp:Date.now()}),m.current.push(s.onMessage("sqlite:list-databases",({requestId:n})=>{s.send("sqlite:list-databases:result",{requestId:n,databases:l.map(({id:t,name:o,adapterId:r,adapterName:e})=>({id:t,name:o,adapterId:r,adapterName:e}))})})),m.current.push(s.onMessage("sqlite:query",async({requestId:n,databaseId:t,sql:o,params:r})=>{try{const e=await g(t,()=>x(t,o,r));s.send("sqlite:query:result",{requestId:n,databaseId:t,result:e})}catch(e){s.send("sqlite:query:result",{requestId:n,databaseId:t,error:q(e)})}})),m.current.push(s.onMessage("sqlite:execute-script",async({requestId:n,databaseId:t,sql:o})=>{try{const r=await g(t,async()=>{const e=f.splitSqlStatements(o);if(e.length===0)throw new Error("Query cannot be empty.");const i=e.map(u=>({sql:u.text}));try{const u=await y(t,i);return{statements:e.map((c,p)=>({index:p,start:c.start,end:c.end,input:u.inputs[p],execution:{input:u.inputs[p],result:u.results[p]}})),totalStatementCount:e.length,failedStatementIndex:null}}catch(u){if(!b(u))throw u;const c=Math.max(0,Math.min(typeof u.failedStatementIndex=="number"?u.failedStatementIndex:u.completedResults?.length??0,e.length-1));return{statements:[...(u.completedResults??[]).slice(0,c).map((E,d)=>({index:d,start:e[d].start,end:e[d].end,input:i[d],execution:{input:i[d],result:E}})),{index:c,start:e[c].start,end:e[c].end,input:i[c],error:q(u)}],totalStatementCount:e.length,failedStatementIndex:c}}});s.send("sqlite:execute-script:result",{requestId:n,databaseId:t,result:r})}catch(r){s.send("sqlite:execute-script:result",{requestId:n,databaseId:t,error:q(r)})}})),()=>{m.current.forEach(n=>n.remove()),m.current=[],S.current.clear()}},[s,l]),s};exports.useRozeniteSqlitePlugin=z;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { useRozeniteDevToolsClient as E } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useMemo as R, useRef as w, useEffect as v } from "react";
|
|
3
|
+
import { f as M, a as D, n as z } from "./bridge-values.js";
|
|
4
|
+
const b = "@rozenite/sqlite-plugin", C = (u) => u.flatMap(
|
|
5
|
+
(l) => l.databases.map((s) => ({
|
|
6
|
+
id: s.id,
|
|
7
|
+
name: s.name,
|
|
8
|
+
adapterId: l.id,
|
|
9
|
+
adapterName: l.name,
|
|
10
|
+
executeStatements: s.executeStatements
|
|
11
|
+
}))
|
|
12
|
+
), d = (u) => M(u), P = (u) => u instanceof Error && ("completedResults" in u || "failedStatementIndex" in u), N = ({
|
|
13
|
+
adapters: u
|
|
14
|
+
}) => {
|
|
15
|
+
const l = R(() => C(u), [u]), s = E({
|
|
16
|
+
pluginId: b
|
|
17
|
+
}), m = w([]), f = w(/* @__PURE__ */ new Map());
|
|
18
|
+
return v(() => {
|
|
19
|
+
if (!s)
|
|
20
|
+
return;
|
|
21
|
+
const S = async (n, t) => {
|
|
22
|
+
const r = (f.current.get(n) ?? Promise.resolve()).catch(() => {
|
|
23
|
+
}).then(t);
|
|
24
|
+
return f.current.set(
|
|
25
|
+
n,
|
|
26
|
+
r.then(
|
|
27
|
+
() => {
|
|
28
|
+
},
|
|
29
|
+
() => {
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
), r;
|
|
33
|
+
}, g = (n) => {
|
|
34
|
+
const t = l.find((a) => a.id === n);
|
|
35
|
+
if (!t)
|
|
36
|
+
throw new Error(`Unknown database "${n}".`);
|
|
37
|
+
return t;
|
|
38
|
+
}, q = async (n, t) => {
|
|
39
|
+
const a = g(n), r = t.map(({ sql: i, params: o }) => ({
|
|
40
|
+
sql: z(i),
|
|
41
|
+
params: o
|
|
42
|
+
})), e = await a.executeStatements(r);
|
|
43
|
+
if (e.length !== r.length)
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Expected ${r.length} statement result(s), received ${e.length}.`
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
inputs: r,
|
|
49
|
+
results: e
|
|
50
|
+
};
|
|
51
|
+
}, y = async (n, t, a) => {
|
|
52
|
+
const e = (await q(n, [
|
|
53
|
+
{
|
|
54
|
+
sql: t,
|
|
55
|
+
params: a
|
|
56
|
+
}
|
|
57
|
+
])).results[0];
|
|
58
|
+
if (!e)
|
|
59
|
+
throw new Error("The query completed without a result payload.");
|
|
60
|
+
return e;
|
|
61
|
+
};
|
|
62
|
+
return s.send("sqlite:ready", { timestamp: Date.now() }), m.current.push(
|
|
63
|
+
s.onMessage("sqlite:list-databases", ({ requestId: n }) => {
|
|
64
|
+
s.send("sqlite:list-databases:result", {
|
|
65
|
+
requestId: n,
|
|
66
|
+
databases: l.map(({ id: t, name: a, adapterId: r, adapterName: e }) => ({
|
|
67
|
+
id: t,
|
|
68
|
+
name: a,
|
|
69
|
+
adapterId: r,
|
|
70
|
+
adapterName: e
|
|
71
|
+
}))
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
), m.current.push(
|
|
75
|
+
s.onMessage(
|
|
76
|
+
"sqlite:query",
|
|
77
|
+
async ({ requestId: n, databaseId: t, sql: a, params: r }) => {
|
|
78
|
+
try {
|
|
79
|
+
const e = await S(
|
|
80
|
+
t,
|
|
81
|
+
() => y(t, a, r)
|
|
82
|
+
);
|
|
83
|
+
s.send("sqlite:query:result", {
|
|
84
|
+
requestId: n,
|
|
85
|
+
databaseId: t,
|
|
86
|
+
result: e
|
|
87
|
+
});
|
|
88
|
+
} catch (e) {
|
|
89
|
+
s.send("sqlite:query:result", {
|
|
90
|
+
requestId: n,
|
|
91
|
+
databaseId: t,
|
|
92
|
+
error: d(e)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
), m.current.push(
|
|
98
|
+
s.onMessage(
|
|
99
|
+
"sqlite:execute-script",
|
|
100
|
+
async ({ requestId: n, databaseId: t, sql: a }) => {
|
|
101
|
+
try {
|
|
102
|
+
const r = await S(t, async () => {
|
|
103
|
+
const e = D(a);
|
|
104
|
+
if (e.length === 0)
|
|
105
|
+
throw new Error("Query cannot be empty.");
|
|
106
|
+
const i = e.map((o) => ({
|
|
107
|
+
sql: o.text
|
|
108
|
+
}));
|
|
109
|
+
try {
|
|
110
|
+
const o = await q(
|
|
111
|
+
t,
|
|
112
|
+
i
|
|
113
|
+
);
|
|
114
|
+
return {
|
|
115
|
+
statements: e.map((c, p) => ({
|
|
116
|
+
index: p,
|
|
117
|
+
start: c.start,
|
|
118
|
+
end: c.end,
|
|
119
|
+
input: o.inputs[p],
|
|
120
|
+
execution: {
|
|
121
|
+
input: o.inputs[p],
|
|
122
|
+
result: o.results[p]
|
|
123
|
+
}
|
|
124
|
+
})),
|
|
125
|
+
totalStatementCount: e.length,
|
|
126
|
+
failedStatementIndex: null
|
|
127
|
+
};
|
|
128
|
+
} catch (o) {
|
|
129
|
+
if (!P(o))
|
|
130
|
+
throw o;
|
|
131
|
+
const c = Math.max(
|
|
132
|
+
0,
|
|
133
|
+
Math.min(
|
|
134
|
+
typeof o.failedStatementIndex == "number" ? o.failedStatementIndex : o.completedResults?.length ?? 0,
|
|
135
|
+
e.length - 1
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
return {
|
|
139
|
+
statements: [
|
|
140
|
+
...(o.completedResults ?? []).slice(
|
|
141
|
+
0,
|
|
142
|
+
c
|
|
143
|
+
).map(
|
|
144
|
+
(x, h) => ({
|
|
145
|
+
index: h,
|
|
146
|
+
start: e[h].start,
|
|
147
|
+
end: e[h].end,
|
|
148
|
+
input: i[h],
|
|
149
|
+
execution: {
|
|
150
|
+
input: i[h],
|
|
151
|
+
result: x
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
),
|
|
155
|
+
{
|
|
156
|
+
index: c,
|
|
157
|
+
start: e[c].start,
|
|
158
|
+
end: e[c].end,
|
|
159
|
+
input: i[c],
|
|
160
|
+
error: d(o)
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
totalStatementCount: e.length,
|
|
164
|
+
failedStatementIndex: c
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
s.send("sqlite:execute-script:result", {
|
|
169
|
+
requestId: n,
|
|
170
|
+
databaseId: t,
|
|
171
|
+
result: r
|
|
172
|
+
});
|
|
173
|
+
} catch (r) {
|
|
174
|
+
s.send("sqlite:execute-script:result", {
|
|
175
|
+
requestId: n,
|
|
176
|
+
databaseId: t,
|
|
177
|
+
error: d(r)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
), () => {
|
|
183
|
+
m.current.forEach((n) => n.remove()), m.current = [], f.current.clear();
|
|
184
|
+
};
|
|
185
|
+
}, [s, l]), s;
|
|
186
|
+
};
|
|
187
|
+
export {
|
|
188
|
+
N as useRozeniteSqlitePlugin
|
|
189
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.createSqliteAdapter=void 0;exports.createExpoSqliteAdapter=void 0;exports.useRozeniteSqlitePlugin=void 0;const t=typeof window<"u"&&window.navigator.product!=="ReactNative",i=process.env.NODE_ENV!=="production",a=typeof window>"u";i&&!t&&!a?(exports.createSqliteAdapter=require("./chunks/index.require.cjs").createSqliteAdapter,exports.createExpoSqliteAdapter=require("./chunks/index.require.cjs").createExpoSqliteAdapter,exports.useRozeniteSqlitePlugin=require("./chunks/useRozeniteSqlitePlugin.require.cjs").useRozeniteSqlitePlugin):(exports.createSqliteAdapter=e=>({id:e.adapterId??"sqlite",name:e.adapterName??"SQLite",databases:[]}),exports.createExpoSqliteAdapter=e=>({id:e.adapterId??"expo-sqlite",name:e.adapterName??"Expo SQLite",databases:[]}),exports.useRozeniteSqlitePlugin=()=>null);
|