@rozenite/sqlite-plugin 2.2.0 → 2.3.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 +14 -0
- package/dist/devtools/assets/{panel-B2O8mY15.js → panel-CLyprPq_.js} +41 -41
- package/dist/devtools/panel.html +1 -1
- package/dist/react-native/cjs/package.json +3 -0
- package/dist/react-native/cjs/react-native.js +37 -0
- package/dist/react-native/cjs/src/react-native/adapters/expo-sqlite.js +121 -0
- package/dist/react-native/cjs/src/react-native/adapters/generic.js +33 -0
- package/dist/react-native/cjs/src/react-native/adapters/index.js +7 -0
- package/dist/react-native/cjs/src/react-native/sqlite-view.js +11 -0
- package/dist/react-native/cjs/src/react-native/useRozeniteSqlitePlugin.js +178 -0
- package/dist/react-native/cjs/src/react-native/useSqliteAgentTools.js +115 -0
- package/dist/react-native/cjs/src/shared/bridge-values.js +126 -0
- package/dist/react-native/cjs/src/shared/protocol.js +4 -0
- package/dist/react-native/cjs/src/shared/sql.js +339 -0
- package/dist/react-native/cjs/src/shared/types.js +2 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/react-native.d.ts +15 -0
- package/dist/react-native/react-native.js +43 -0
- package/dist/react-native/src/react-native/adapters/expo-sqlite.d.ts +28 -0
- package/dist/react-native/src/react-native/adapters/expo-sqlite.js +117 -0
- package/dist/react-native/src/react-native/adapters/generic.d.ts +19 -0
- package/dist/react-native/src/react-native/adapters/generic.js +29 -0
- package/dist/react-native/src/react-native/adapters/index.d.ts +2 -0
- package/dist/react-native/src/react-native/adapters/index.js +2 -0
- package/dist/react-native/src/react-native/sqlite-view.d.ts +5 -0
- package/dist/react-native/src/react-native/sqlite-view.js +7 -0
- package/dist/react-native/src/react-native/useRozeniteSqlitePlugin.d.ts +6 -0
- package/dist/react-native/src/react-native/useRozeniteSqlitePlugin.js +174 -0
- package/dist/react-native/src/react-native/useSqliteAgentTools.d.ts +2 -0
- package/dist/react-native/src/react-native/useSqliteAgentTools.js +111 -0
- package/dist/react-native/src/shared/bridge-values.d.ts +3 -0
- package/dist/react-native/src/shared/bridge-values.js +120 -0
- package/dist/react-native/src/shared/protocol.d.ts +38 -0
- package/dist/react-native/src/shared/protocol.js +1 -0
- package/dist/react-native/src/shared/sql.d.ts +14 -0
- package/dist/react-native/src/shared/sql.js +328 -0
- package/dist/react-native/src/shared/types.d.ts +56 -0
- package/dist/react-native/src/shared/types.js +1 -0
- package/dist/rozenite.json +1 -1
- package/package.json +12 -11
- package/react-native.ts +8 -1
- package/rozenite.config.ts +1 -0
- package/src/__tests__/release-bundle.test.ts +32 -0
- package/dist/react-native/chunks/bridge-values.require.cjs +0 -2
- package/dist/react-native/chunks/bridge-values.require.js +0 -61
- package/dist/react-native/chunks/index.require.cjs +0 -1
- package/dist/react-native/chunks/index.require.js +0 -107
- package/dist/react-native/chunks/sql.require.cjs +0 -4
- package/dist/react-native/chunks/sql.require.js +0 -219
- package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.cjs +0 -1
- package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.js +0 -283
- package/dist/react-native/index.cjs +0 -1
- package/dist/react-native/index.d.ts +0 -208
- package/dist/react-native/index.js +0 -22
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=n=>/\s/.test(n),a=n=>{let e=0,c=!1,o=0,t=null;for(;o<n.length;){const i=n[o],l=n[o+1];if(t==="line-comment"){i===`
|
|
2
|
-
`&&(t=null),o+=1;continue}if(t==="block-comment"){if(i==="*"&&l==="/"){t=null,o+=2;continue}o+=1;continue}if(t==="single-quote"){if(i==="'"&&l==="'"){o+=2;continue}i==="'"&&(t=null),o+=1;continue}if(t==="double-quote"){if(i==='"'&&l==='"'){o+=2;continue}i==='"'&&(t=null),o+=1;continue}if(t==="backtick"){if(i==="`"&&l==="`"){o+=2;continue}i==="`"&&(t=null),o+=1;continue}if(t==="bracket"){if(i==="]"&&l==="]"){o+=2;continue}i==="]"&&(t=null),o+=1;continue}if(i==="-"&&l==="-"){t="line-comment",o+=2;continue}if(i==="/"&&l==="*"){t="block-comment",o+=2;continue}if(i==="'"){t="single-quote",c=!0,o+=1;continue}if(i==='"'){t="double-quote",c=!0,o+=1;continue}if(i==="`"){t="backtick",c=!0,o+=1;continue}if(i==="["){t="bracket",c=!0,o+=1;continue}if(i===";"){c&&(e+=1,c=!1),o+=1;continue}f(i)||(c=!0),o+=1}return c&&(e+=1),e},s=n=>{const e=[];let c=!1,o=0,t=0,i=null;const l=u=>{const r=n.slice(o,u).trim();r&&e.push({text:r,start:o,end:u}),o=u+1,c=!1};for(;t<n.length;){const u=n[t],r=n[t+1];if(i==="line-comment"){u===`
|
|
3
|
-
`&&(i=null),t+=1;continue}if(i==="block-comment"){if(u==="*"&&r==="/"){i=null,t+=2;continue}t+=1;continue}if(i==="single-quote"){if(u==="'"&&r==="'"){t+=2;continue}u==="'"&&(i=null),t+=1;continue}if(i==="double-quote"){if(u==='"'&&r==='"'){t+=2;continue}u==='"'&&(i=null),t+=1;continue}if(i==="backtick"){if(u==="`"&&r==="`"){t+=2;continue}u==="`"&&(i=null),t+=1;continue}if(i==="bracket"){if(u==="]"&&r==="]"){t+=2;continue}u==="]"&&(i=null),t+=1;continue}if(u==="-"&&r==="-"){i="line-comment",t+=2;continue}if(u==="/"&&r==="*"){i="block-comment",t+=2;continue}if(u==="'"){i="single-quote",c=!0,t+=1;continue}if(u==='"'){i="double-quote",c=!0,t+=1;continue}if(u==="`"){i="backtick",c=!0,t+=1;continue}if(u==="["){i="bracket",c=!0,t+=1;continue}if(u===";"){c?l(t):o=t+1,t+=1;continue}f(u)||(c=!0),t+=1}return c&&l(n.length),e},m=(n,e)=>{const c=s(n);return c.length===0?null:c.find(t=>e>=t.start&&e<=t.end+1)??c[0]},S=n=>{const e=a(n);if(e===0)throw new Error("Query cannot be empty.");if(e>1)throw new Error("Only a single SQL statement is supported in v1.");return n.trim().replace(/;\s*$/,"").trim()},g=n=>{let e=0;for(;e<n.length;){const o=n[e],t=n[e+1];if(f(o)){e+=1;continue}if(o==="-"&&t==="-"){for(e+=2;e<n.length&&n[e]!==`
|
|
4
|
-
`;)e+=1;continue}if(o==="/"&&t==="*"){for(e+=2;e<n.length&&!(n[e]==="*"&&n[e+1]==="/");)e+=1;e+=2;continue}break}const c=e;for(;e<n.length&&/[A-Za-z]/.test(n[e]);)e+=1;return n.slice(c,e).toLowerCase()},h=n=>{const e=g(n);return e==="select"||e==="insert"||e==="update"||e==="delete"||e==="pragma"||e==="create"||e==="alter"||e==="drop"||e==="explain"||e==="with"?e:"other"},b=n=>n==="select"||n==="pragma"||n==="explain"||n==="with",k=n=>`"${n.replace(/"/g,'""')}"`,d=n=>`'${n.replace(/'/g,"''")}'`;exports.classifySqlStatement=h;exports.countSqlStatements=a;exports.escapeSqlString=d;exports.getStatementAtCursor=m;exports.normalizeSingleStatementSql=S;exports.quoteSqlIdentifier=k;exports.splitSqlStatements=s;exports.statementReturnsRows=b;
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
const f = (n) => /\s/.test(n), a = (n) => {
|
|
2
|
-
let e = 0, c = !1, o = 0, t = null;
|
|
3
|
-
for (; o < n.length; ) {
|
|
4
|
-
const i = n[o], l = n[o + 1];
|
|
5
|
-
if (t === "line-comment") {
|
|
6
|
-
i === `
|
|
7
|
-
` && (t = null), o += 1;
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
if (t === "block-comment") {
|
|
11
|
-
if (i === "*" && l === "/") {
|
|
12
|
-
t = null, o += 2;
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
o += 1;
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (t === "single-quote") {
|
|
19
|
-
if (i === "'" && l === "'") {
|
|
20
|
-
o += 2;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
i === "'" && (t = null), o += 1;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (t === "double-quote") {
|
|
27
|
-
if (i === '"' && l === '"') {
|
|
28
|
-
o += 2;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
i === '"' && (t = null), o += 1;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (t === "backtick") {
|
|
35
|
-
if (i === "`" && l === "`") {
|
|
36
|
-
o += 2;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
i === "`" && (t = null), o += 1;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (t === "bracket") {
|
|
43
|
-
if (i === "]" && l === "]") {
|
|
44
|
-
o += 2;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
i === "]" && (t = null), o += 1;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (i === "-" && l === "-") {
|
|
51
|
-
t = "line-comment", o += 2;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (i === "/" && l === "*") {
|
|
55
|
-
t = "block-comment", o += 2;
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (i === "'") {
|
|
59
|
-
t = "single-quote", c = !0, o += 1;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (i === '"') {
|
|
63
|
-
t = "double-quote", c = !0, o += 1;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (i === "`") {
|
|
67
|
-
t = "backtick", c = !0, o += 1;
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (i === "[") {
|
|
71
|
-
t = "bracket", c = !0, o += 1;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (i === ";") {
|
|
75
|
-
c && (e += 1, c = !1), o += 1;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
f(i) || (c = !0), o += 1;
|
|
79
|
-
}
|
|
80
|
-
return c && (e += 1), e;
|
|
81
|
-
}, s = (n) => {
|
|
82
|
-
const e = [];
|
|
83
|
-
let c = !1, o = 0, t = 0, i = null;
|
|
84
|
-
const l = (u) => {
|
|
85
|
-
const r = n.slice(o, u).trim();
|
|
86
|
-
r && e.push({
|
|
87
|
-
text: r,
|
|
88
|
-
start: o,
|
|
89
|
-
end: u
|
|
90
|
-
}), o = u + 1, c = !1;
|
|
91
|
-
};
|
|
92
|
-
for (; t < n.length; ) {
|
|
93
|
-
const u = n[t], r = n[t + 1];
|
|
94
|
-
if (i === "line-comment") {
|
|
95
|
-
u === `
|
|
96
|
-
` && (i = null), t += 1;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (i === "block-comment") {
|
|
100
|
-
if (u === "*" && r === "/") {
|
|
101
|
-
i = null, t += 2;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
t += 1;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (i === "single-quote") {
|
|
108
|
-
if (u === "'" && r === "'") {
|
|
109
|
-
t += 2;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
u === "'" && (i = null), t += 1;
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (i === "double-quote") {
|
|
116
|
-
if (u === '"' && r === '"') {
|
|
117
|
-
t += 2;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
u === '"' && (i = null), t += 1;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (i === "backtick") {
|
|
124
|
-
if (u === "`" && r === "`") {
|
|
125
|
-
t += 2;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
u === "`" && (i = null), t += 1;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (i === "bracket") {
|
|
132
|
-
if (u === "]" && r === "]") {
|
|
133
|
-
t += 2;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
u === "]" && (i = null), t += 1;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (u === "-" && r === "-") {
|
|
140
|
-
i = "line-comment", t += 2;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (u === "/" && r === "*") {
|
|
144
|
-
i = "block-comment", t += 2;
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
if (u === "'") {
|
|
148
|
-
i = "single-quote", c = !0, t += 1;
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (u === '"') {
|
|
152
|
-
i = "double-quote", c = !0, t += 1;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (u === "`") {
|
|
156
|
-
i = "backtick", c = !0, t += 1;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (u === "[") {
|
|
160
|
-
i = "bracket", c = !0, t += 1;
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if (u === ";") {
|
|
164
|
-
c ? l(t) : o = t + 1, t += 1;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
f(u) || (c = !0), t += 1;
|
|
168
|
-
}
|
|
169
|
-
return c && l(n.length), e;
|
|
170
|
-
}, h = (n, e) => {
|
|
171
|
-
const c = s(n);
|
|
172
|
-
return c.length === 0 ? null : c.find((t) => e >= t.start && e <= t.end + 1) ?? c[0];
|
|
173
|
-
}, g = (n) => {
|
|
174
|
-
const e = a(n);
|
|
175
|
-
if (e === 0)
|
|
176
|
-
throw new Error("Query cannot be empty.");
|
|
177
|
-
if (e > 1)
|
|
178
|
-
throw new Error("Only a single SQL statement is supported in v1.");
|
|
179
|
-
return n.trim().replace(/;\s*$/, "").trim();
|
|
180
|
-
}, m = (n) => {
|
|
181
|
-
let e = 0;
|
|
182
|
-
for (; e < n.length; ) {
|
|
183
|
-
const o = n[e], t = n[e + 1];
|
|
184
|
-
if (f(o)) {
|
|
185
|
-
e += 1;
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
if (o === "-" && t === "-") {
|
|
189
|
-
for (e += 2; e < n.length && n[e] !== `
|
|
190
|
-
`; )
|
|
191
|
-
e += 1;
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
if (o === "/" && t === "*") {
|
|
195
|
-
for (e += 2; e < n.length && !(n[e] === "*" && n[e + 1] === "/"); )
|
|
196
|
-
e += 1;
|
|
197
|
-
e += 2;
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
const c = e;
|
|
203
|
-
for (; e < n.length && /[A-Za-z]/.test(n[e]); )
|
|
204
|
-
e += 1;
|
|
205
|
-
return n.slice(c, e).toLowerCase();
|
|
206
|
-
}, k = (n) => {
|
|
207
|
-
const e = m(n);
|
|
208
|
-
return e === "select" || e === "insert" || e === "update" || e === "delete" || e === "pragma" || e === "create" || e === "alter" || e === "drop" || e === "explain" || e === "with" ? e : "other";
|
|
209
|
-
}, b = (n) => n === "select" || n === "pragma" || n === "explain" || n === "with", w = (n) => `"${n.replace(/"/g, '""')}"`, S = (n) => `'${n.replace(/'/g, "''")}'`;
|
|
210
|
-
export {
|
|
211
|
-
k as classifySqlStatement,
|
|
212
|
-
a as countSqlStatements,
|
|
213
|
-
S as escapeSqlString,
|
|
214
|
-
h as getStatementAtCursor,
|
|
215
|
-
g as normalizeSingleStatementSql,
|
|
216
|
-
w as quoteSqlIdentifier,
|
|
217
|
-
s as splitSqlStatements,
|
|
218
|
-
b as statementReturnsRows
|
|
219
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("@rozenite/plugin-bridge"),w=require("react"),E=require("./bridge-values.require.cjs"),y=require("./sql.require.cjs"),b=require("@rozenite/agent-bridge"),T="@rozenite/sqlite-plugin",v=r=>r.flatMap(p=>p.databases.map(t=>({id:t.id,name:t.name,adapterId:p.id,adapterName:p.name,executeStatements:t.executeStatements}))),R="@rozenite/sqlite-plugin",z={name:"list-databases",description:"List all registered SQLite databases.",inputSchema:{type:"object",properties:{}}},I={name:"execute-sql",description:"Execute one or more SQL statements against a database. Supports SELECT, INSERT, UPDATE, DELETE, PRAGMA, DDL, and multi-statement scripts. Returns per-statement results including rows, columns, and metadata. Statements are executed in order and stop on first error.",inputSchema:{type:"object",properties:{databaseId:{type:"string",description:"Database ID from list-databases."},sql:{type:"string",description:"SQL to execute. May contain multiple semicolon-separated statements."}},required:["databaseId","sql"]}},L=r=>r instanceof Error&&("completedResults"in r||"failedStatementIndex"in r),P=r=>{const p=w.useCallback(t=>{const c=r.find(m=>m.id===t);if(!c){const m=r.map(u=>u.id).join(", ");throw new Error(`Unknown databaseId "${t}". Available: ${m||"(none)"}`)}return c},[r]);b.useRozenitePluginAgentTool({pluginId:R,tool:z,handler:()=>({databases:r.map(({id:t,name:c,adapterId:m,adapterName:u})=>({id:t,name:c,adapterId:m,adapterName:u}))})}),b.useRozenitePluginAgentTool({pluginId:R,tool:I,handler:async({databaseId:t,sql:c})=>{const m=p(t),u=y.splitSqlStatements(c);if(u.length===0)throw new Error("SQL cannot be empty.");const q=u.map(i=>({sql:y.normalizeSingleStatementSql(i.text)}));try{const i=await m.executeStatements(q);return{databaseId:t,totalStatementCount:u.length,failedStatementIndex:null,statements:u.map((S,n)=>{const e=i[n];return{index:n,sql:q[n].sql,rows:e.rows,columns:e.columns,metadata:e.metadata}})}}catch(i){if(!L(i))throw new Error(E.formatSqliteError(i));const S=Math.max(0,Math.min(typeof i.failedStatementIndex=="number"?i.failedStatementIndex:i.completedResults?.length??0,u.length-1)),n=(i.completedResults??[]).slice(0,S);return{databaseId:t,totalStatementCount:u.length,failedStatementIndex:S,statements:[...n.map((e,o)=>({index:o,sql:q[o].sql,rows:e.rows,columns:e.columns,metadata:e.metadata})),{index:S,sql:q[S].sql,error:E.formatSqliteError(i)}]}}}})},x=r=>E.formatSqliteError(r),A=r=>r instanceof Error&&("completedResults"in r||"failedStatementIndex"in r),C=({adapters:r})=>{const p=w.useMemo(()=>v(r),[r]);P(p);const t=M.useRozeniteDevToolsClient({pluginId:T}),c=w.useRef([]),m=w.useRef(new Map);return w.useEffect(()=>{if(!t)return;const u=async(n,e)=>{const a=(m.current.get(n)??Promise.resolve()).catch(()=>{}).then(e);return m.current.set(n,a.then(()=>{},()=>{})),a},q=n=>{const e=p.find(o=>o.id===n);if(!e)throw new Error(`Unknown database "${n}".`);return e},i=async(n,e)=>{const o=q(n),a=e.map(({sql:g,params:l})=>({sql:y.normalizeSingleStatementSql(g),params:l})),s=await o.executeStatements(a);if(s.length!==a.length)throw new Error(`Expected ${a.length} statement result(s), received ${s.length}.`);return{inputs:a,results:s}},S=async(n,e,o)=>{const s=(await i(n,[{sql:e,params:o}])).results[0];if(!s)throw new Error("The query completed without a result payload.");return s};return t.send("sqlite:ready",{timestamp:Date.now()}),c.current.push(t.onMessage("sqlite:list-databases",({requestId:n})=>{t.send("sqlite:list-databases:result",{requestId:n,databases:p.map(({id:e,name:o,adapterId:a,adapterName:s})=>({id:e,name:o,adapterId:a,adapterName:s}))})})),c.current.push(t.onMessage("sqlite:query",async({requestId:n,databaseId:e,sql:o,params:a})=>{try{const s=await u(e,()=>S(e,o,a));t.send("sqlite:query:result",{requestId:n,databaseId:e,result:s})}catch(s){t.send("sqlite:query:result",{requestId:n,databaseId:e,error:x(s)})}})),c.current.push(t.onMessage("sqlite:execute-script",async({requestId:n,databaseId:e,sql:o})=>{try{const a=await u(e,async()=>{const s=y.splitSqlStatements(o);if(s.length===0)throw new Error("Query cannot be empty.");const g=s.map(l=>({sql:l.text}));try{const l=await i(e,g);return{statements:s.map((d,h)=>({index:h,start:d.start,end:d.end,input:l.inputs[h],execution:{input:l.inputs[h],result:l.results[h]}})),totalStatementCount:s.length,failedStatementIndex:null}}catch(l){if(!A(l))throw l;const d=Math.max(0,Math.min(typeof l.failedStatementIndex=="number"?l.failedStatementIndex:l.completedResults?.length??0,s.length-1));return{statements:[...(l.completedResults??[]).slice(0,d).map((D,f)=>({index:f,start:s[f].start,end:s[f].end,input:g[f],execution:{input:g[f],result:D}})),{index:d,start:s[d].start,end:s[d].end,input:g[d],error:x(l)}],totalStatementCount:s.length,failedStatementIndex:d}}});t.send("sqlite:execute-script:result",{requestId:n,databaseId:e,result:a})}catch(a){t.send("sqlite:execute-script:result",{requestId:n,databaseId:e,error:x(a)})}})),()=>{c.current.forEach(n=>n.remove()),c.current=[],m.current.clear()}},[t,p]),t};exports.useRozeniteSqlitePlugin=C;
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as T } from "@rozenite/plugin-bridge";
|
|
2
|
-
import { useCallback as v, useMemo as I, useRef as y, useEffect as L } from "react";
|
|
3
|
-
import { formatSqliteError as x } from "./bridge-values.require.js";
|
|
4
|
-
import { splitSqlStatements as R, normalizeSingleStatementSql as D } from "./sql.require.js";
|
|
5
|
-
import { useRozenitePluginAgentTool as E } from "@rozenite/agent-bridge";
|
|
6
|
-
const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
|
|
7
|
-
(p) => p.databases.map((e) => ({
|
|
8
|
-
id: e.id,
|
|
9
|
-
name: e.name,
|
|
10
|
-
adapterId: p.id,
|
|
11
|
-
adapterName: p.name,
|
|
12
|
-
executeStatements: e.executeStatements
|
|
13
|
-
}))
|
|
14
|
-
), b = "@rozenite/sqlite-plugin", Q = {
|
|
15
|
-
name: "list-databases",
|
|
16
|
-
description: "List all registered SQLite databases.",
|
|
17
|
-
inputSchema: { type: "object", properties: {} }
|
|
18
|
-
}, A = {
|
|
19
|
-
name: "execute-sql",
|
|
20
|
-
description: "Execute one or more SQL statements against a database. Supports SELECT, INSERT, UPDATE, DELETE, PRAGMA, DDL, and multi-statement scripts. Returns per-statement results including rows, columns, and metadata. Statements are executed in order and stop on first error.",
|
|
21
|
-
inputSchema: {
|
|
22
|
-
type: "object",
|
|
23
|
-
properties: {
|
|
24
|
-
databaseId: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: "Database ID from list-databases."
|
|
27
|
-
},
|
|
28
|
-
sql: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "SQL to execute. May contain multiple semicolon-separated statements."
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
required: ["databaseId", "sql"]
|
|
34
|
-
}
|
|
35
|
-
}, P = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), $ = (a) => {
|
|
36
|
-
const p = v(
|
|
37
|
-
(e) => {
|
|
38
|
-
const u = a.find((m) => m.id === e);
|
|
39
|
-
if (!u) {
|
|
40
|
-
const m = a.map((i) => i.id).join(", ");
|
|
41
|
-
throw new Error(`Unknown databaseId "${e}". Available: ${m || "(none)"}`);
|
|
42
|
-
}
|
|
43
|
-
return u;
|
|
44
|
-
},
|
|
45
|
-
[a]
|
|
46
|
-
);
|
|
47
|
-
E({
|
|
48
|
-
pluginId: b,
|
|
49
|
-
tool: Q,
|
|
50
|
-
handler: () => ({
|
|
51
|
-
databases: a.map(({ id: e, name: u, adapterId: m, adapterName: i }) => ({
|
|
52
|
-
id: e,
|
|
53
|
-
name: u,
|
|
54
|
-
adapterId: m,
|
|
55
|
-
adapterName: i
|
|
56
|
-
}))
|
|
57
|
-
})
|
|
58
|
-
}), E({
|
|
59
|
-
pluginId: b,
|
|
60
|
-
tool: A,
|
|
61
|
-
handler: async ({ databaseId: e, sql: u }) => {
|
|
62
|
-
const m = p(e), i = R(u);
|
|
63
|
-
if (i.length === 0)
|
|
64
|
-
throw new Error("SQL cannot be empty.");
|
|
65
|
-
const h = i.map((c) => ({
|
|
66
|
-
sql: D(c.text)
|
|
67
|
-
}));
|
|
68
|
-
try {
|
|
69
|
-
const c = await m.executeStatements(h);
|
|
70
|
-
return {
|
|
71
|
-
databaseId: e,
|
|
72
|
-
totalStatementCount: i.length,
|
|
73
|
-
failedStatementIndex: null,
|
|
74
|
-
statements: i.map((S, n) => {
|
|
75
|
-
const t = c[n];
|
|
76
|
-
return {
|
|
77
|
-
index: n,
|
|
78
|
-
sql: h[n].sql,
|
|
79
|
-
rows: t.rows,
|
|
80
|
-
columns: t.columns,
|
|
81
|
-
metadata: t.metadata
|
|
82
|
-
};
|
|
83
|
-
})
|
|
84
|
-
};
|
|
85
|
-
} catch (c) {
|
|
86
|
-
if (!P(c))
|
|
87
|
-
throw new Error(x(c));
|
|
88
|
-
const S = Math.max(
|
|
89
|
-
0,
|
|
90
|
-
Math.min(
|
|
91
|
-
typeof c.failedStatementIndex == "number" ? c.failedStatementIndex : c.completedResults?.length ?? 0,
|
|
92
|
-
i.length - 1
|
|
93
|
-
)
|
|
94
|
-
), n = (c.completedResults ?? []).slice(0, S);
|
|
95
|
-
return {
|
|
96
|
-
databaseId: e,
|
|
97
|
-
totalStatementCount: i.length,
|
|
98
|
-
failedStatementIndex: S,
|
|
99
|
-
statements: [
|
|
100
|
-
...n.map((t, o) => ({
|
|
101
|
-
index: o,
|
|
102
|
-
sql: h[o].sql,
|
|
103
|
-
rows: t.rows,
|
|
104
|
-
columns: t.columns,
|
|
105
|
-
metadata: t.metadata
|
|
106
|
-
})),
|
|
107
|
-
{
|
|
108
|
-
index: S,
|
|
109
|
-
sql: h[S].sql,
|
|
110
|
-
error: x(c)
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}, w = (a) => x(a), k = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), B = ({ adapters: a }) => {
|
|
118
|
-
const p = I(() => C(a), [a]);
|
|
119
|
-
$(p);
|
|
120
|
-
const e = T({
|
|
121
|
-
pluginId: z
|
|
122
|
-
}), u = y([]), m = y(/* @__PURE__ */ new Map());
|
|
123
|
-
return L(() => {
|
|
124
|
-
if (!e)
|
|
125
|
-
return;
|
|
126
|
-
const i = async (n, t) => {
|
|
127
|
-
const r = (m.current.get(n) ?? Promise.resolve()).catch(() => {
|
|
128
|
-
}).then(t);
|
|
129
|
-
return m.current.set(
|
|
130
|
-
n,
|
|
131
|
-
r.then(
|
|
132
|
-
() => {
|
|
133
|
-
},
|
|
134
|
-
() => {
|
|
135
|
-
}
|
|
136
|
-
)
|
|
137
|
-
), r;
|
|
138
|
-
}, h = (n) => {
|
|
139
|
-
const t = p.find((o) => o.id === n);
|
|
140
|
-
if (!t)
|
|
141
|
-
throw new Error(`Unknown database "${n}".`);
|
|
142
|
-
return t;
|
|
143
|
-
}, c = async (n, t) => {
|
|
144
|
-
const o = h(n), r = t.map(({ sql: f, params: l }) => ({
|
|
145
|
-
sql: D(f),
|
|
146
|
-
params: l
|
|
147
|
-
})), s = await o.executeStatements(r);
|
|
148
|
-
if (s.length !== r.length)
|
|
149
|
-
throw new Error(
|
|
150
|
-
`Expected ${r.length} statement result(s), received ${s.length}.`
|
|
151
|
-
);
|
|
152
|
-
return {
|
|
153
|
-
inputs: r,
|
|
154
|
-
results: s
|
|
155
|
-
};
|
|
156
|
-
}, S = async (n, t, o) => {
|
|
157
|
-
const s = (await c(n, [
|
|
158
|
-
{
|
|
159
|
-
sql: t,
|
|
160
|
-
params: o
|
|
161
|
-
}
|
|
162
|
-
])).results[0];
|
|
163
|
-
if (!s)
|
|
164
|
-
throw new Error("The query completed without a result payload.");
|
|
165
|
-
return s;
|
|
166
|
-
};
|
|
167
|
-
return e.send("sqlite:ready", { timestamp: Date.now() }), u.current.push(
|
|
168
|
-
e.onMessage("sqlite:list-databases", ({ requestId: n }) => {
|
|
169
|
-
e.send("sqlite:list-databases:result", {
|
|
170
|
-
requestId: n,
|
|
171
|
-
databases: p.map(({ id: t, name: o, adapterId: r, adapterName: s }) => ({
|
|
172
|
-
id: t,
|
|
173
|
-
name: o,
|
|
174
|
-
adapterId: r,
|
|
175
|
-
adapterName: s
|
|
176
|
-
}))
|
|
177
|
-
});
|
|
178
|
-
})
|
|
179
|
-
), u.current.push(
|
|
180
|
-
e.onMessage("sqlite:query", async ({ requestId: n, databaseId: t, sql: o, params: r }) => {
|
|
181
|
-
try {
|
|
182
|
-
const s = await i(
|
|
183
|
-
t,
|
|
184
|
-
() => S(t, o, r)
|
|
185
|
-
);
|
|
186
|
-
e.send("sqlite:query:result", {
|
|
187
|
-
requestId: n,
|
|
188
|
-
databaseId: t,
|
|
189
|
-
result: s
|
|
190
|
-
});
|
|
191
|
-
} catch (s) {
|
|
192
|
-
e.send("sqlite:query:result", {
|
|
193
|
-
requestId: n,
|
|
194
|
-
databaseId: t,
|
|
195
|
-
error: w(s)
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
), u.current.push(
|
|
200
|
-
e.onMessage("sqlite:execute-script", async ({ requestId: n, databaseId: t, sql: o }) => {
|
|
201
|
-
try {
|
|
202
|
-
const r = await i(t, async () => {
|
|
203
|
-
const s = R(o);
|
|
204
|
-
if (s.length === 0)
|
|
205
|
-
throw new Error("Query cannot be empty.");
|
|
206
|
-
const f = s.map((l) => ({
|
|
207
|
-
sql: l.text
|
|
208
|
-
}));
|
|
209
|
-
try {
|
|
210
|
-
const l = await c(t, f);
|
|
211
|
-
return {
|
|
212
|
-
statements: s.map((d, q) => ({
|
|
213
|
-
index: q,
|
|
214
|
-
start: d.start,
|
|
215
|
-
end: d.end,
|
|
216
|
-
input: l.inputs[q],
|
|
217
|
-
execution: {
|
|
218
|
-
input: l.inputs[q],
|
|
219
|
-
result: l.results[q]
|
|
220
|
-
}
|
|
221
|
-
})),
|
|
222
|
-
totalStatementCount: s.length,
|
|
223
|
-
failedStatementIndex: null
|
|
224
|
-
};
|
|
225
|
-
} catch (l) {
|
|
226
|
-
if (!k(l))
|
|
227
|
-
throw l;
|
|
228
|
-
const d = Math.max(
|
|
229
|
-
0,
|
|
230
|
-
Math.min(
|
|
231
|
-
typeof l.failedStatementIndex == "number" ? l.failedStatementIndex : l.completedResults?.length ?? 0,
|
|
232
|
-
s.length - 1
|
|
233
|
-
)
|
|
234
|
-
);
|
|
235
|
-
return {
|
|
236
|
-
statements: [
|
|
237
|
-
...(l.completedResults ?? []).slice(
|
|
238
|
-
0,
|
|
239
|
-
d
|
|
240
|
-
).map((M, g) => ({
|
|
241
|
-
index: g,
|
|
242
|
-
start: s[g].start,
|
|
243
|
-
end: s[g].end,
|
|
244
|
-
input: f[g],
|
|
245
|
-
execution: {
|
|
246
|
-
input: f[g],
|
|
247
|
-
result: M
|
|
248
|
-
}
|
|
249
|
-
})),
|
|
250
|
-
{
|
|
251
|
-
index: d,
|
|
252
|
-
start: s[d].start,
|
|
253
|
-
end: s[d].end,
|
|
254
|
-
input: f[d],
|
|
255
|
-
error: w(l)
|
|
256
|
-
}
|
|
257
|
-
],
|
|
258
|
-
totalStatementCount: s.length,
|
|
259
|
-
failedStatementIndex: d
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
e.send("sqlite:execute-script:result", {
|
|
264
|
-
requestId: n,
|
|
265
|
-
databaseId: t,
|
|
266
|
-
result: r
|
|
267
|
-
});
|
|
268
|
-
} catch (r) {
|
|
269
|
-
e.send("sqlite:execute-script:result", {
|
|
270
|
-
requestId: n,
|
|
271
|
-
databaseId: t,
|
|
272
|
-
error: w(r)
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
), () => {
|
|
277
|
-
u.current.forEach((n) => n.remove()), u.current = [], m.current.clear();
|
|
278
|
-
};
|
|
279
|
-
}, [e, p]), e;
|
|
280
|
-
};
|
|
281
|
-
export {
|
|
282
|
-
B as useRozeniteSqlitePlugin
|
|
283
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.createSqliteAdapter=void 0;exports.createExpoSqliteAdapter=void 0;exports.useRozeniteSqlitePlugin=void 0;exports.classifySqlStatement=void 0;exports.normalizeSingleStatementSql=void 0;exports.splitSqlStatements=void 0;exports.statementReturnsRows=void 0;exports.decodeSqliteBridgeValue=void 0;exports.formatSqliteError=void 0;const t=process.env.NODE_ENV!=="production",i=typeof window<"u"&&window.navigator.product!=="ReactNative",r=typeof window>"u";t&&!i&&!r?(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.classifySqlStatement=require("./chunks/sql.require.cjs").classifySqlStatement,exports.normalizeSingleStatementSql=require("./chunks/sql.require.cjs").normalizeSingleStatementSql,exports.splitSqlStatements=require("./chunks/sql.require.cjs").splitSqlStatements,exports.statementReturnsRows=require("./chunks/sql.require.cjs").statementReturnsRows,exports.decodeSqliteBridgeValue=require("./chunks/bridge-values.require.cjs").decodeSqliteBridgeValue,exports.formatSqliteError=require("./chunks/bridge-values.require.cjs").formatSqliteError):(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,exports.classifySqlStatement=()=>"other",exports.normalizeSingleStatementSql=e=>e,exports.splitSqlStatements=()=>[],exports.statementReturnsRows=e=>!1,exports.decodeSqliteBridgeValue=e=>e,exports.formatSqliteError=()=>"Unknown SQLite error.");
|