@rozenite/sqlite-plugin 1.8.1 → 1.10.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @rozenite/sqlite-plugin
2
2
 
3
+ ## 1.10.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @rozenite/agent-bridge@1.10.0
9
+ - @rozenite/plugin-bridge@1.10.0
10
+
11
+ ## 1.9.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#259](https://github.com/callstackincubator/rozenite/pull/259) [`6fd13c0`](https://github.com/callstackincubator/rozenite/commit/6fd13c04108b5a49d0526223b0680b03a0bb6276) Thanks [@V3RON](https://github.com/V3RON)! - `classifySqlStatement`, `normalizeSingleStatementSql`, `splitSqlStatements`, `statementReturnsRows`, `decodeSqliteBridgeValue`, and `formatSqliteError` are now exported from `@rozenite/sqlite-plugin`. These are the building blocks you need when writing a custom SQLite adapter — to parse and classify SQL before execution, and to decode values coming back over the native bridge.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies []:
20
+ - @rozenite/agent-bridge@1.9.0
21
+ - @rozenite/plugin-bridge@1.9.0
22
+
3
23
  ## 1.8.1
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c="__rozeniteSqliteBinary",s=t=>!!t&&typeof t=="object",l=t=>s(t)&&t[c]===!0&&Array.isArray(t.data)&&t.data.every(n=>typeof n=="number"),f=t=>t==null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:t instanceof Uint8Array?{[c]:!0,data:Array.from(t)}:t instanceof ArrayBuffer?{[c]:!0,data:Array.from(new Uint8Array(t))}:Array.isArray(t)?t.map(f):s(t)?Object.fromEntries(Object.entries(t).map(([n,r])=>[n,f(r)])):String(t),d=t=>t==null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:l(t)?new Uint8Array(t.data):Array.isArray(t)?t.map(d):s(t)?Object.fromEntries(Object.entries(t).map(([n,r])=>[n,d(r)])):t,o=(t,n)=>{if(!s(t))return null;const r=t[n];if(typeof r!="string")return null;const e=r.trim();return e||null},m=t=>{try{return JSON.stringify(t)}catch{return String(t)}},p=t=>{if(t instanceof Error){const n=o(t,"code"),r=o(t,"reason"),a=[t.message.trim()||null,r].filter((y,u,g)=>!!y&&g.indexOf(y)===u).join(" | ")||t.name;return n?`[${n}] ${a}`:a}if(s(t)){const n=o(t,"code"),r=o(t,"message"),e=o(t,"reason"),i=r??e??m(t);return n?`[${n}] ${i}`:i}return typeof t=="string"?t.trim()||null:t==null?null:m(t)},S=t=>{if(s(t))return t.cause},b=t=>{const n=new Set,r=[];let e=t;for(;e!=null&&!n.has(e);){n.add(e);const i=p(e);i&&!r.includes(i)&&r.push(i),e=S(e)}return r.join(`
2
+ Caused by: `)||"Unknown SQLite error."};exports.decodeSqliteBridgeValue=d;exports.encodeSqliteBridgeValue=f;exports.formatSqliteError=b;
@@ -0,0 +1,61 @@
1
+ const c = "__rozeniteSqliteBinary", s = (t) => !!t && typeof t == "object", p = (t) => s(t) && t[c] === !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 : t instanceof Uint8Array ? {
2
+ [c]: !0,
3
+ data: Array.from(t)
4
+ } : t instanceof ArrayBuffer ? {
5
+ [c]: !0,
6
+ data: Array.from(new Uint8Array(t))
7
+ } : Array.isArray(t) ? t.map(a) : s(t) ? Object.fromEntries(
8
+ Object.entries(t).map(([n, r]) => [
9
+ n,
10
+ a(r)
11
+ ])
12
+ ) : String(t), y = (t) => t == null || typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? t : p(t) ? new Uint8Array(t.data) : Array.isArray(t) ? t.map(y) : s(t) ? Object.fromEntries(
13
+ Object.entries(t).map(([n, r]) => [
14
+ n,
15
+ y(r)
16
+ ])
17
+ ) : t, o = (t, n) => {
18
+ if (!s(t))
19
+ return null;
20
+ const r = t[n];
21
+ if (typeof r != "string")
22
+ return null;
23
+ const e = r.trim();
24
+ return e || null;
25
+ }, m = (t) => {
26
+ try {
27
+ return JSON.stringify(t);
28
+ } catch {
29
+ return String(t);
30
+ }
31
+ }, b = (t) => {
32
+ if (t instanceof Error) {
33
+ const n = o(t, "code"), r = o(t, "reason"), f = [t.message.trim() || null, r].filter(
34
+ (d, u, g) => !!d && g.indexOf(d) === u
35
+ ).join(" | ") || t.name;
36
+ return n ? `[${n}] ${f}` : f;
37
+ }
38
+ if (s(t)) {
39
+ const n = o(t, "code"), r = o(t, "message"), e = o(t, "reason"), i = r ?? e ?? m(t);
40
+ return n ? `[${n}] ${i}` : i;
41
+ }
42
+ return typeof t == "string" ? t.trim() || null : t == null ? null : m(t);
43
+ }, A = (t) => {
44
+ if (s(t))
45
+ return t.cause;
46
+ }, l = (t) => {
47
+ const n = /* @__PURE__ */ new Set(), r = [];
48
+ let e = t;
49
+ for (; e != null && !n.has(e); ) {
50
+ n.add(e);
51
+ const i = b(e);
52
+ i && !r.includes(i) && r.push(i), e = A(e);
53
+ }
54
+ return r.join(`
55
+ Caused by: `) || "Unknown SQLite error.";
56
+ };
57
+ export {
58
+ y as decodeSqliteBridgeValue,
59
+ a as encodeSqliteBridgeValue,
60
+ l as formatSqliteError
61
+ };
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./sql.require.cjs"),p=require("./bridge-values.require.cjs"),g=e=>e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"database",A=(e,a,t)=>`${e}__${g(a)}__${t.toString(36)}`,q=e=>typeof e=="function"?{executeStatements:e}:e,u=(e,a,t,r,n)=>{const o=q(t),s=o.name??n??a;return{id:A(e,`${a}-${s}`,r),name:s,executeStatements:o.executeStatements}},S=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=>p.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)]))),j=async(e,{sql:a,params:t})=>{const r=i.normalizeSingleStatementSql(a),n=i.classifySqlStatement(r),o=m(),s=t===void 0?void 0:p.decodeSqliteBridgeValue(t);if(i.statementReturnsRows(n)){const d=E(s===void 0?await e.getAllAsync(r):await e.getAllAsync(r,s)),w=m()-o;return{rows:d,columns:Object.keys(d[0]??{}),metadata:{statementType:n,rowCount:d.length,changes:null,lastInsertRowId:null,durationMs:w}}}const c=s===void 0?await e.runAsync(r):await e.runAsync(r,s),y=m()-o;return{rows:[],columns:[],metadata:{statementType:n,rowCount:0,changes:typeof c.changes=="number"?c.changes:null,lastInsertRowId:typeof c.lastInsertRowId=="number"?c.lastInsertRowId:null,durationMs:y}}},f=e=>async a=>{const t=[];for(let r=0;r<a.length;r+=1)try{t.push(await j(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},N=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 S(a)};exports.createExpoSqliteAdapter=N;exports.createSqliteAdapter=S;
@@ -1,4 +1,5 @@
1
- import { f as S, n as y, c as w, d as g, s as x } from "./bridge-values.js";
1
+ import { normalizeSingleStatementSql as S, classifySqlStatement as y, statementReturnsRows as w } from "./sql.require.js";
2
+ import { formatSqliteError as g, decodeSqliteBridgeValue as x } from "./bridge-values.require.js";
2
3
  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
4
  const o = E(t), s = o.name ?? n ?? a;
4
5
  return {
@@ -23,7 +24,7 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
23
24
  name: t,
24
25
  databases: r
25
26
  };
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
+ }, m = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), j = (e) => g(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
28
  Object.entries(e).map(([a, t]) => [
28
29
  a,
29
30
  i(t)
@@ -36,8 +37,8 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
36
37
  ])
37
38
  )
38
39
  ), 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)) {
40
+ const r = S(a), n = y(r), o = m(), s = t === void 0 ? void 0 : x(t);
41
+ if (w(n)) {
41
42
  const d = O(
42
43
  s === void 0 ? await e.getAllAsync(r) : await e.getAllAsync(r, s)
43
44
  ), p = m() - o;
@@ -78,7 +79,7 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
78
79
  });
79
80
  }
80
81
  return t;
81
- }, f = (e) => "database" in e ? e : { database: e }, D = (e) => {
82
+ }, f = (e) => "database" in e ? e : { database: e }, $ = (e) => {
82
83
  const a = "databases" in e ? {
83
84
  adapterId: e.adapterId ?? "expo-sqlite",
84
85
  adapterName: e.adapterName ?? "Expo SQLite",
@@ -113,6 +114,6 @@ const A = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+
113
114
  return N(a);
114
115
  };
115
116
  export {
116
- D as createExpoSqliteAdapter,
117
+ $ as createExpoSqliteAdapter,
117
118
  N as createSqliteAdapter
118
119
  };
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,221 @@
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(
173
+ (t) => e >= t.start && e <= t.end + 1
174
+ ) ?? c[0];
175
+ }, g = (n) => {
176
+ const e = a(n);
177
+ if (e === 0)
178
+ throw new Error("Query cannot be empty.");
179
+ if (e > 1)
180
+ throw new Error("Only a single SQL statement is supported in v1.");
181
+ return n.trim().replace(/;\s*$/, "").trim();
182
+ }, m = (n) => {
183
+ let e = 0;
184
+ for (; e < n.length; ) {
185
+ const o = n[e], t = n[e + 1];
186
+ if (f(o)) {
187
+ e += 1;
188
+ continue;
189
+ }
190
+ if (o === "-" && t === "-") {
191
+ for (e += 2; e < n.length && n[e] !== `
192
+ `; )
193
+ e += 1;
194
+ continue;
195
+ }
196
+ if (o === "/" && t === "*") {
197
+ for (e += 2; e < n.length && !(n[e] === "*" && n[e + 1] === "/"); )
198
+ e += 1;
199
+ e += 2;
200
+ continue;
201
+ }
202
+ break;
203
+ }
204
+ const c = e;
205
+ for (; e < n.length && /[A-Za-z]/.test(n[e]); )
206
+ e += 1;
207
+ return n.slice(c, e).toLowerCase();
208
+ }, k = (n) => {
209
+ const e = m(n);
210
+ return e === "select" || e === "insert" || e === "update" || e === "delete" || e === "pragma" || e === "create" || e === "alter" || e === "drop" || e === "explain" || e === "with" ? e : "other";
211
+ }, b = (n) => n === "select" || n === "pragma" || n === "explain" || n === "with", w = (n) => `"${n.replace(/"/g, '""')}"`, S = (n) => `'${n.replace(/'/g, "''")}'`;
212
+ export {
213
+ k as classifySqlStatement,
214
+ a as countSqlStatements,
215
+ S as escapeSqlString,
216
+ h as getStatementAtCursor,
217
+ g as normalizeSingleStatementSql,
218
+ w as quoteSqlIdentifier,
219
+ s as splitSqlStatements,
220
+ b as statementReturnsRows
221
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("@rozenite/plugin-bridge"),y=require("react"),g=require("./bridge-values.cjs"),E=require("@rozenite/agent-bridge"),M="@rozenite/sqlite-plugin",T=r=>r.flatMap(p=>p.databases.map(t=>({id:t.id,name:t.name,adapterId:p.id,adapterName:p.name,executeStatements:t.executeStatements}))),b="@rozenite/sqlite-plugin",v={name:"list-databases",description:"List all registered SQLite databases.",inputSchema:{type:"object",properties:{}}},z={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"]}},I=r=>r instanceof Error&&("completedResults"in r||"failedStatementIndex"in r),L=r=>{const p=y.useCallback(t=>{const u=r.find(m=>m.id===t);if(!u){const m=r.map(c=>c.id).join(", ");throw new Error(`Unknown databaseId "${t}". Available: ${m||"(none)"}`)}return u},[r]);E.useRozenitePluginAgentTool({pluginId:b,tool:v,handler:()=>({databases:r.map(({id:t,name:u,adapterId:m,adapterName:c})=>({id:t,name:u,adapterId:m,adapterName:c}))})}),E.useRozenitePluginAgentTool({pluginId:b,tool:z,handler:async({databaseId:t,sql:u})=>{const m=p(t),c=g.splitSqlStatements(u);if(c.length===0)throw new Error("SQL cannot be empty.");const q=c.map(i=>({sql:g.normalizeSingleStatementSql(i.text)}));try{const i=await m.executeStatements(q);return{databaseId:t,totalStatementCount:c.length,failedStatementIndex:null,statements:c.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(!I(i))throw new Error(g.formatSqliteError(i));const S=Math.max(0,Math.min(typeof i.failedStatementIndex=="number"?i.failedStatementIndex:i.completedResults?.length??0,c.length-1)),n=(i.completedResults??[]).slice(0,S);return{databaseId:t,totalStatementCount:c.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:g.formatSqliteError(i)}]}}}})},x=r=>g.formatSqliteError(r),P=r=>r instanceof Error&&("completedResults"in r||"failedStatementIndex"in r),A=({adapters:r})=>{const p=y.useMemo(()=>T(r),[r]);L(p);const t=D.useRozeniteDevToolsClient({pluginId:M}),u=y.useRef([]),m=y.useRef(new Map);return y.useEffect(()=>{if(!t)return;const c=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:h,params:l})=>({sql:g.normalizeSingleStatementSql(h),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()}),u.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}))})})),u.current.push(t.onMessage("sqlite:query",async({requestId:n,databaseId:e,sql:o,params:a})=>{try{const s=await c(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)})}})),u.current.push(t.onMessage("sqlite:execute-script",async({requestId:n,databaseId:e,sql:o})=>{try{const a=await c(e,async()=>{const s=g.splitSqlStatements(o);if(s.length===0)throw new Error("Query cannot be empty.");const h=s.map(l=>({sql:l.text}));try{const l=await i(e,h);return{statements:s.map((d,f)=>({index:f,start:d.start,end:d.end,input:l.inputs[f],execution:{input:l.inputs[f],result:l.results[f]}})),totalStatementCount:s.length,failedStatementIndex:null}}catch(l){if(!P(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((R,w)=>({index:w,start:s[w].start,end:s[w].end,input:h[w],execution:{input:h[w],result:R}})),{index:d,start:s[d].start,end:s[d].end,input:h[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)})}})),()=>{u.current.forEach(n=>n.remove()),u.current=[],m.current.clear()}},[t,p]),t};exports.useRozeniteSqlitePlugin=A;
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,6 +1,7 @@
1
1
  import { useRozeniteDevToolsClient as T } from "@rozenite/plugin-bridge";
2
2
  import { useCallback as v, useMemo as I, useRef as y, useEffect as L } from "react";
3
- import { a as R, n as D, f as x } from "./bridge-values.js";
3
+ import { formatSqliteError as x } from "./bridge-values.require.js";
4
+ import { splitSqlStatements as R, normalizeSingleStatementSql as D } from "./sql.require.js";
4
5
  import { useRozenitePluginAgentTool as E } from "@rozenite/agent-bridge";
5
6
  const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
6
7
  (p) => p.databases.map((e) => ({
@@ -118,7 +119,7 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
118
119
  }
119
120
  }
120
121
  });
121
- }, w = (a) => x(a), k = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), V = ({
122
+ }, w = (a) => x(a), k = (a) => a instanceof Error && ("completedResults" in a || "failedStatementIndex" in a), B = ({
122
123
  adapters: a
123
124
  }) => {
124
125
  const p = I(() => C(a), [a]);
@@ -296,5 +297,5 @@ const z = "@rozenite/sqlite-plugin", C = (a) => a.flatMap(
296
297
  }, [e, p]), e;
297
298
  };
298
299
  export {
299
- V as useRozeniteSqlitePlugin
300
+ B as useRozeniteSqlitePlugin
300
301
  };
@@ -1 +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=process.env.NODE_ENV!=="production",i=typeof window<"u"&&window.navigator.product!=="ReactNative",a=typeof window>"u";t&&!i&&!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);
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.");
@@ -1,6 +1,10 @@
1
1
  import { RozeniteDevToolsClient } from '@rozenite/plugin-bridge';
2
2
 
3
- declare type CreateExpoSqliteAdapter = createExpoSqliteAdapter_2;
3
+ export declare let classifySqlStatement: typeof classifySqlStatement_2;
4
+
5
+ declare const classifySqlStatement_2: (sql: string) => SqliteStatementType;
6
+
7
+ declare type CreateExpoSqliteAdapter = typeof createExpoSqliteAdapter_2;
4
8
 
5
9
  export declare let createExpoSqliteAdapter: CreateExpoSqliteAdapter;
6
10
 
@@ -8,7 +12,7 @@ declare const createExpoSqliteAdapter_2: (options: CreateExpoSqliteAdapterOption
8
12
 
9
13
  export declare type CreateExpoSqliteAdapterOptions = SingleDatabaseOptions_2 | MultiDatabaseOptions_2;
10
14
 
11
- declare type CreateSqliteAdapter = createSqliteAdapter_2;
15
+ declare type CreateSqliteAdapter = typeof createSqliteAdapter_2;
12
16
 
13
17
  export declare let createSqliteAdapter: CreateSqliteAdapter;
14
18
 
@@ -16,6 +20,10 @@ declare const createSqliteAdapter_2: (options: CreateSqliteAdapterOptions) => Sq
16
20
 
17
21
  export declare type CreateSqliteAdapterOptions = SingleDatabaseOptions | MultiDatabaseOptions;
18
22
 
23
+ export declare let decodeSqliteBridgeValue: typeof decodeSqliteBridgeValue_2;
24
+
25
+ declare const decodeSqliteBridgeValue_2: (value: unknown) => unknown;
26
+
19
27
  export declare type ExpoSqliteLike = {
20
28
  getAllAsync: (...args: any[]) => Promise<Record<string, unknown>[]>;
21
29
  runAsync: (...args: any[]) => Promise<{
@@ -24,6 +32,10 @@ export declare type ExpoSqliteLike = {
24
32
  }>;
25
33
  };
26
34
 
35
+ export declare let formatSqliteError: typeof formatSqliteError_2;
36
+
37
+ declare const formatSqliteError_2: (error: unknown) => string;
38
+
27
39
  declare type MultiDatabaseOptions = {
28
40
  databases: Record<string, SqliteExecuteStatementsRunner | SqliteDatabaseConfig>;
29
41
  adapterId?: string;
@@ -39,6 +51,10 @@ declare type MultiDatabaseOptions_2 = {
39
51
  adapterName?: string;
40
52
  };
41
53
 
54
+ export declare let normalizeSingleStatementSql: typeof normalizeSingleStatementSql_2;
55
+
56
+ declare const normalizeSingleStatementSql_2: (sql: string) => string;
57
+
42
58
  declare type RozeniteSqlitePluginOptions = {
43
59
  adapters: SqliteAdapter[];
44
60
  };
@@ -60,6 +76,10 @@ declare type SingleDatabaseOptions_2 = {
60
76
  databaseName?: string;
61
77
  };
62
78
 
79
+ export declare let splitSqlStatements: typeof splitSqlStatements_2;
80
+
81
+ declare const splitSqlStatements_2: (sql: string) => SqlStatementSegment[];
82
+
63
83
  export declare type SqliteAdapter = {
64
84
  id: string;
65
85
  name: string;
@@ -171,7 +191,17 @@ export declare type SqliteStatementInput = {
171
191
 
172
192
  export declare type SqliteStatementType = 'select' | 'insert' | 'update' | 'delete' | 'pragma' | 'create' | 'alter' | 'drop' | 'explain' | 'with' | 'other';
173
193
 
174
- export declare let useRozeniteSqlitePlugin: useRozeniteSqlitePlugin_2;
194
+ export declare type SqlStatementSegment = {
195
+ text: string;
196
+ start: number;
197
+ end: number;
198
+ };
199
+
200
+ export declare let statementReturnsRows: typeof statementReturnsRows_2;
201
+
202
+ declare const statementReturnsRows_2: (statementType: SqliteStatementType) => statementType is "select" | "pragma" | "explain" | "with";
203
+
204
+ export declare let useRozeniteSqlitePlugin: typeof useRozeniteSqlitePlugin_2;
175
205
 
176
206
  declare const useRozeniteSqlitePlugin_2: ({ adapters, }: RozeniteSqlitePluginOptions) => RozeniteDevToolsClient<SqliteEventMap> | null;
177
207
 
@@ -1,16 +1,22 @@
1
- let t, a, i;
2
- const r = process.env.NODE_ENV !== "production", d = typeof window < "u" && window.navigator.product !== "ReactNative", n = typeof window > "u";
3
- r && !d && !n ? (t = require("./chunks/index.require.js").createSqliteAdapter, a = require("./chunks/index.require.js").createExpoSqliteAdapter, i = require("./chunks/useRozeniteSqlitePlugin.require.js").useRozeniteSqlitePlugin) : (t = (e) => ({
1
+ let t, r, i, a, l, n, s, d, o;
2
+ const S = process.env.NODE_ENV !== "production", q = typeof window < "u" && window.navigator.product !== "ReactNative", u = typeof window > "u";
3
+ S && !q && !u ? (t = require("./chunks/index.require.js").createSqliteAdapter, r = require("./chunks/index.require.js").createExpoSqliteAdapter, i = require("./chunks/useRozeniteSqlitePlugin.require.js").useRozeniteSqlitePlugin, a = require("./chunks/sql.require.js").classifySqlStatement, l = require("./chunks/sql.require.js").normalizeSingleStatementSql, n = require("./chunks/sql.require.js").splitSqlStatements, s = require("./chunks/sql.require.js").statementReturnsRows, d = require("./chunks/bridge-values.require.js").decodeSqliteBridgeValue, o = require("./chunks/bridge-values.require.js").formatSqliteError) : (t = (e) => ({
4
4
  id: e.adapterId ?? "sqlite",
5
5
  name: e.adapterName ?? "SQLite",
6
6
  databases: []
7
- }), a = (e) => ({
7
+ }), r = (e) => ({
8
8
  id: e.adapterId ?? "expo-sqlite",
9
9
  name: e.adapterName ?? "Expo SQLite",
10
10
  databases: []
11
- }), i = () => null);
11
+ }), i = () => null, a = () => "other", l = (e) => e, n = () => [], s = (e) => !1, d = (e) => e, o = () => "Unknown SQLite error.");
12
12
  export {
13
- a as createExpoSqliteAdapter,
13
+ a as classifySqlStatement,
14
+ r as createExpoSqliteAdapter,
14
15
  t as createSqliteAdapter,
16
+ d as decodeSqliteBridgeValue,
17
+ o as formatSqliteError,
18
+ l as normalizeSingleStatementSql,
19
+ n as splitSqlStatements,
20
+ s as statementReturnsRows,
15
21
  i as useRozeniteSqlitePlugin
16
22
  };
@@ -1 +1 @@
1
- {"name":"@rozenite/sqlite-plugin","version":"1.8.1","description":"SQLite inspector for Rozenite.","panels":[{"name":"SQLite","source":"/devtools/panel.html"}]}
1
+ {"name":"@rozenite/sqlite-plugin","version":"1.10.0","description":"SQLite inspector for Rozenite.","panels":[{"name":"SQLite","source":"/devtools/panel.html"}]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rozenite/sqlite-plugin",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "description": "SQLite inspector for Rozenite.",
5
5
  "type": "module",
6
6
  "main": "./dist/react-native/index.cjs",
@@ -15,8 +15,8 @@
15
15
  "url": "https://github.com/callstackincubator/rozenite.git"
16
16
  },
17
17
  "dependencies": {
18
- "@rozenite/agent-bridge": "1.8.1",
19
- "@rozenite/plugin-bridge": "1.8.1"
18
+ "@rozenite/agent-bridge": "1.10.0",
19
+ "@rozenite/plugin-bridge": "1.10.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@dnd-kit/core": "^6.3.1",
@@ -49,8 +49,8 @@
49
49
  "typescript": "~5.9.3",
50
50
  "vite": "^7.3.1",
51
51
  "vitest": "^3.2.4",
52
- "@rozenite/vite-plugin": "1.8.1",
53
- "rozenite": "1.8.1"
52
+ "rozenite": "1.10.0",
53
+ "@rozenite/vite-plugin": "1.10.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "expo-sqlite": "*",
package/react-native.ts CHANGED
@@ -18,6 +18,7 @@ export type {
18
18
  CreateExpoSqliteAdapterOptions,
19
19
  ExpoSqliteLike,
20
20
  } from './src/react-native/adapters/expo-sqlite';
21
+ export type { SqlStatementSegment } from './src/shared/sql';
21
22
 
22
23
  type CreateSqliteAdapter =
23
24
  typeof import('./src/react-native/adapters').createSqliteAdapter;
@@ -27,6 +28,12 @@ type CreateExpoSqliteAdapter =
27
28
  export let createSqliteAdapter: CreateSqliteAdapter;
28
29
  export let createExpoSqliteAdapter: CreateExpoSqliteAdapter;
29
30
  export let useRozeniteSqlitePlugin: typeof import('./src/react-native/useRozeniteSqlitePlugin').useRozeniteSqlitePlugin;
31
+ export let classifySqlStatement: typeof import('./src/shared/sql').classifySqlStatement;
32
+ export let normalizeSingleStatementSql: typeof import('./src/shared/sql').normalizeSingleStatementSql;
33
+ export let splitSqlStatements: typeof import('./src/shared/sql').splitSqlStatements;
34
+ export let statementReturnsRows: typeof import('./src/shared/sql').statementReturnsRows;
35
+ export let decodeSqliteBridgeValue: typeof import('./src/shared/bridge-values').decodeSqliteBridgeValue;
36
+ export let formatSqliteError: typeof import('./src/shared/bridge-values').formatSqliteError;
30
37
 
31
38
  const isDev = process.env.NODE_ENV !== 'production';
32
39
  const isWeb =
@@ -40,6 +47,14 @@ if (isDev && !isWeb && !isServer) {
40
47
  require('./src/react-native/adapters').createExpoSqliteAdapter;
41
48
  useRozeniteSqlitePlugin =
42
49
  require('./src/react-native/useRozeniteSqlitePlugin').useRozeniteSqlitePlugin;
50
+ classifySqlStatement = require('./src/shared/sql').classifySqlStatement;
51
+ normalizeSingleStatementSql =
52
+ require('./src/shared/sql').normalizeSingleStatementSql;
53
+ splitSqlStatements = require('./src/shared/sql').splitSqlStatements;
54
+ statementReturnsRows = require('./src/shared/sql').statementReturnsRows;
55
+ decodeSqliteBridgeValue =
56
+ require('./src/shared/bridge-values').decodeSqliteBridgeValue;
57
+ formatSqliteError = require('./src/shared/bridge-values').formatSqliteError;
43
58
  } else {
44
59
  createSqliteAdapter = (options) => ({
45
60
  id: options.adapterId ?? 'sqlite',
@@ -52,4 +67,10 @@ if (isDev && !isWeb && !isServer) {
52
67
  databases: [],
53
68
  });
54
69
  useRozeniteSqlitePlugin = () => null;
70
+ classifySqlStatement = () => 'other';
71
+ normalizeSingleStatementSql = (sql) => sql;
72
+ splitSqlStatements = () => [];
73
+ statementReturnsRows = (_type): _type is never => false;
74
+ decodeSqliteBridgeValue = (value) => value;
75
+ formatSqliteError = () => 'Unknown SQLite error.';
55
76
  }
@@ -1,5 +0,0 @@
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;
@@ -1,258 +0,0 @@
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
- };