@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.
Files changed (54) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/devtools/assets/{panel-B2O8mY15.js → panel-CLyprPq_.js} +41 -41
  3. package/dist/devtools/panel.html +1 -1
  4. package/dist/react-native/cjs/package.json +3 -0
  5. package/dist/react-native/cjs/react-native.js +37 -0
  6. package/dist/react-native/cjs/src/react-native/adapters/expo-sqlite.js +121 -0
  7. package/dist/react-native/cjs/src/react-native/adapters/generic.js +33 -0
  8. package/dist/react-native/cjs/src/react-native/adapters/index.js +7 -0
  9. package/dist/react-native/cjs/src/react-native/sqlite-view.js +11 -0
  10. package/dist/react-native/cjs/src/react-native/useRozeniteSqlitePlugin.js +178 -0
  11. package/dist/react-native/cjs/src/react-native/useSqliteAgentTools.js +115 -0
  12. package/dist/react-native/cjs/src/shared/bridge-values.js +126 -0
  13. package/dist/react-native/cjs/src/shared/protocol.js +4 -0
  14. package/dist/react-native/cjs/src/shared/sql.js +339 -0
  15. package/dist/react-native/cjs/src/shared/types.js +2 -0
  16. package/dist/react-native/package.json +3 -0
  17. package/dist/react-native/react-native.d.ts +15 -0
  18. package/dist/react-native/react-native.js +43 -0
  19. package/dist/react-native/src/react-native/adapters/expo-sqlite.d.ts +28 -0
  20. package/dist/react-native/src/react-native/adapters/expo-sqlite.js +117 -0
  21. package/dist/react-native/src/react-native/adapters/generic.d.ts +19 -0
  22. package/dist/react-native/src/react-native/adapters/generic.js +29 -0
  23. package/dist/react-native/src/react-native/adapters/index.d.ts +2 -0
  24. package/dist/react-native/src/react-native/adapters/index.js +2 -0
  25. package/dist/react-native/src/react-native/sqlite-view.d.ts +5 -0
  26. package/dist/react-native/src/react-native/sqlite-view.js +7 -0
  27. package/dist/react-native/src/react-native/useRozeniteSqlitePlugin.d.ts +6 -0
  28. package/dist/react-native/src/react-native/useRozeniteSqlitePlugin.js +174 -0
  29. package/dist/react-native/src/react-native/useSqliteAgentTools.d.ts +2 -0
  30. package/dist/react-native/src/react-native/useSqliteAgentTools.js +111 -0
  31. package/dist/react-native/src/shared/bridge-values.d.ts +3 -0
  32. package/dist/react-native/src/shared/bridge-values.js +120 -0
  33. package/dist/react-native/src/shared/protocol.d.ts +38 -0
  34. package/dist/react-native/src/shared/protocol.js +1 -0
  35. package/dist/react-native/src/shared/sql.d.ts +14 -0
  36. package/dist/react-native/src/shared/sql.js +328 -0
  37. package/dist/react-native/src/shared/types.d.ts +56 -0
  38. package/dist/react-native/src/shared/types.js +1 -0
  39. package/dist/rozenite.json +1 -1
  40. package/package.json +12 -11
  41. package/react-native.ts +8 -1
  42. package/rozenite.config.ts +1 -0
  43. package/src/__tests__/release-bundle.test.ts +32 -0
  44. package/dist/react-native/chunks/bridge-values.require.cjs +0 -2
  45. package/dist/react-native/chunks/bridge-values.require.js +0 -61
  46. package/dist/react-native/chunks/index.require.cjs +0 -1
  47. package/dist/react-native/chunks/index.require.js +0 -107
  48. package/dist/react-native/chunks/sql.require.cjs +0 -4
  49. package/dist/react-native/chunks/sql.require.js +0 -219
  50. package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.cjs +0 -1
  51. package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.js +0 -283
  52. package/dist/react-native/index.cjs +0 -1
  53. package/dist/react-native/index.d.ts +0 -208
  54. package/dist/react-native/index.js +0 -22
@@ -0,0 +1,328 @@
1
+ const isWhitespace = (char) => /\s/.test(char);
2
+ export const countSqlStatements = (sql) => {
3
+ let count = 0;
4
+ let hasToken = false;
5
+ let i = 0;
6
+ let mode = null;
7
+ while (i < sql.length) {
8
+ const char = sql[i];
9
+ const next = sql[i + 1];
10
+ if (mode === 'line-comment') {
11
+ if (char === '\n') {
12
+ mode = null;
13
+ }
14
+ i += 1;
15
+ continue;
16
+ }
17
+ if (mode === 'block-comment') {
18
+ if (char === '*' && next === '/') {
19
+ mode = null;
20
+ i += 2;
21
+ continue;
22
+ }
23
+ i += 1;
24
+ continue;
25
+ }
26
+ if (mode === 'single-quote') {
27
+ if (char === "'" && next === "'") {
28
+ i += 2;
29
+ continue;
30
+ }
31
+ if (char === "'") {
32
+ mode = null;
33
+ }
34
+ i += 1;
35
+ continue;
36
+ }
37
+ if (mode === 'double-quote') {
38
+ if (char === '"' && next === '"') {
39
+ i += 2;
40
+ continue;
41
+ }
42
+ if (char === '"') {
43
+ mode = null;
44
+ }
45
+ i += 1;
46
+ continue;
47
+ }
48
+ if (mode === 'backtick') {
49
+ if (char === '`' && next === '`') {
50
+ i += 2;
51
+ continue;
52
+ }
53
+ if (char === '`') {
54
+ mode = null;
55
+ }
56
+ i += 1;
57
+ continue;
58
+ }
59
+ if (mode === 'bracket') {
60
+ if (char === ']' && next === ']') {
61
+ i += 2;
62
+ continue;
63
+ }
64
+ if (char === ']') {
65
+ mode = null;
66
+ }
67
+ i += 1;
68
+ continue;
69
+ }
70
+ if (char === '-' && next === '-') {
71
+ mode = 'line-comment';
72
+ i += 2;
73
+ continue;
74
+ }
75
+ if (char === '/' && next === '*') {
76
+ mode = 'block-comment';
77
+ i += 2;
78
+ continue;
79
+ }
80
+ if (char === "'") {
81
+ mode = 'single-quote';
82
+ hasToken = true;
83
+ i += 1;
84
+ continue;
85
+ }
86
+ if (char === '"') {
87
+ mode = 'double-quote';
88
+ hasToken = true;
89
+ i += 1;
90
+ continue;
91
+ }
92
+ if (char === '`') {
93
+ mode = 'backtick';
94
+ hasToken = true;
95
+ i += 1;
96
+ continue;
97
+ }
98
+ if (char === '[') {
99
+ mode = 'bracket';
100
+ hasToken = true;
101
+ i += 1;
102
+ continue;
103
+ }
104
+ if (char === ';') {
105
+ if (hasToken) {
106
+ count += 1;
107
+ hasToken = false;
108
+ }
109
+ i += 1;
110
+ continue;
111
+ }
112
+ if (!isWhitespace(char)) {
113
+ hasToken = true;
114
+ }
115
+ i += 1;
116
+ }
117
+ if (hasToken) {
118
+ count += 1;
119
+ }
120
+ return count;
121
+ };
122
+ export const splitSqlStatements = (sql) => {
123
+ const segments = [];
124
+ let hasToken = false;
125
+ let segmentStart = 0;
126
+ let i = 0;
127
+ let mode = null;
128
+ const pushSegment = (end) => {
129
+ const text = sql.slice(segmentStart, end).trim();
130
+ if (text) {
131
+ segments.push({
132
+ text,
133
+ start: segmentStart,
134
+ end,
135
+ });
136
+ }
137
+ segmentStart = end + 1;
138
+ hasToken = false;
139
+ };
140
+ while (i < sql.length) {
141
+ const char = sql[i];
142
+ const next = sql[i + 1];
143
+ if (mode === 'line-comment') {
144
+ if (char === '\n') {
145
+ mode = null;
146
+ }
147
+ i += 1;
148
+ continue;
149
+ }
150
+ if (mode === 'block-comment') {
151
+ if (char === '*' && next === '/') {
152
+ mode = null;
153
+ i += 2;
154
+ continue;
155
+ }
156
+ i += 1;
157
+ continue;
158
+ }
159
+ if (mode === 'single-quote') {
160
+ if (char === "'" && next === "'") {
161
+ i += 2;
162
+ continue;
163
+ }
164
+ if (char === "'") {
165
+ mode = null;
166
+ }
167
+ i += 1;
168
+ continue;
169
+ }
170
+ if (mode === 'double-quote') {
171
+ if (char === '"' && next === '"') {
172
+ i += 2;
173
+ continue;
174
+ }
175
+ if (char === '"') {
176
+ mode = null;
177
+ }
178
+ i += 1;
179
+ continue;
180
+ }
181
+ if (mode === 'backtick') {
182
+ if (char === '`' && next === '`') {
183
+ i += 2;
184
+ continue;
185
+ }
186
+ if (char === '`') {
187
+ mode = null;
188
+ }
189
+ i += 1;
190
+ continue;
191
+ }
192
+ if (mode === 'bracket') {
193
+ if (char === ']' && next === ']') {
194
+ i += 2;
195
+ continue;
196
+ }
197
+ if (char === ']') {
198
+ mode = null;
199
+ }
200
+ i += 1;
201
+ continue;
202
+ }
203
+ if (char === '-' && next === '-') {
204
+ mode = 'line-comment';
205
+ i += 2;
206
+ continue;
207
+ }
208
+ if (char === '/' && next === '*') {
209
+ mode = 'block-comment';
210
+ i += 2;
211
+ continue;
212
+ }
213
+ if (char === "'") {
214
+ mode = 'single-quote';
215
+ hasToken = true;
216
+ i += 1;
217
+ continue;
218
+ }
219
+ if (char === '"') {
220
+ mode = 'double-quote';
221
+ hasToken = true;
222
+ i += 1;
223
+ continue;
224
+ }
225
+ if (char === '`') {
226
+ mode = 'backtick';
227
+ hasToken = true;
228
+ i += 1;
229
+ continue;
230
+ }
231
+ if (char === '[') {
232
+ mode = 'bracket';
233
+ hasToken = true;
234
+ i += 1;
235
+ continue;
236
+ }
237
+ if (char === ';') {
238
+ if (hasToken) {
239
+ pushSegment(i);
240
+ }
241
+ else {
242
+ segmentStart = i + 1;
243
+ }
244
+ i += 1;
245
+ continue;
246
+ }
247
+ if (!isWhitespace(char)) {
248
+ hasToken = true;
249
+ }
250
+ i += 1;
251
+ }
252
+ if (hasToken) {
253
+ pushSegment(sql.length);
254
+ }
255
+ return segments;
256
+ };
257
+ export const getStatementAtCursor = (sql, cursor) => {
258
+ const segments = splitSqlStatements(sql);
259
+ if (segments.length === 0) {
260
+ return null;
261
+ }
262
+ const match = segments.find((segment) => cursor >= segment.start && cursor <= segment.end + 1);
263
+ return match ?? segments[0];
264
+ };
265
+ export const normalizeSingleStatementSql = (sql) => {
266
+ const statementCount = countSqlStatements(sql);
267
+ if (statementCount === 0) {
268
+ throw new Error('Query cannot be empty.');
269
+ }
270
+ if (statementCount > 1) {
271
+ throw new Error('Only a single SQL statement is supported in v1.');
272
+ }
273
+ return sql.trim().replace(/;\s*$/, '').trim();
274
+ };
275
+ const readLeadingKeyword = (sql) => {
276
+ let i = 0;
277
+ while (i < sql.length) {
278
+ const char = sql[i];
279
+ const next = sql[i + 1];
280
+ if (isWhitespace(char)) {
281
+ i += 1;
282
+ continue;
283
+ }
284
+ if (char === '-' && next === '-') {
285
+ i += 2;
286
+ while (i < sql.length && sql[i] !== '\n') {
287
+ i += 1;
288
+ }
289
+ continue;
290
+ }
291
+ if (char === '/' && next === '*') {
292
+ i += 2;
293
+ while (i < sql.length && !(sql[i] === '*' && sql[i + 1] === '/')) {
294
+ i += 1;
295
+ }
296
+ i += 2;
297
+ continue;
298
+ }
299
+ break;
300
+ }
301
+ const start = i;
302
+ while (i < sql.length && /[A-Za-z]/.test(sql[i])) {
303
+ i += 1;
304
+ }
305
+ return sql.slice(start, i).toLowerCase();
306
+ };
307
+ export const classifySqlStatement = (sql) => {
308
+ const keyword = readLeadingKeyword(sql);
309
+ if (keyword === 'select' ||
310
+ keyword === 'insert' ||
311
+ keyword === 'update' ||
312
+ keyword === 'delete' ||
313
+ keyword === 'pragma' ||
314
+ keyword === 'create' ||
315
+ keyword === 'alter' ||
316
+ keyword === 'drop' ||
317
+ keyword === 'explain' ||
318
+ keyword === 'with') {
319
+ return keyword;
320
+ }
321
+ return 'other';
322
+ };
323
+ export const statementReturnsRows = (statementType) => statementType === 'select' ||
324
+ statementType === 'pragma' ||
325
+ statementType === 'explain' ||
326
+ statementType === 'with';
327
+ export const quoteSqlIdentifier = (identifier) => `"${identifier.replace(/"/g, '""')}"`;
328
+ export const escapeSqlString = (value) => `'${value.replace(/'/g, "''")}'`;
@@ -0,0 +1,56 @@
1
+ export type SqliteStatementType = 'select' | 'insert' | 'update' | 'delete' | 'pragma' | 'create' | 'alter' | 'drop' | 'explain' | 'with' | 'other';
2
+ export type SqliteQueryParams = unknown[] | Record<string, unknown>;
3
+ export type SqliteStatementInput = {
4
+ sql: string;
5
+ params?: SqliteQueryParams;
6
+ };
7
+ export type SqliteQueryMetadata = {
8
+ statementType: SqliteStatementType;
9
+ rowCount: number;
10
+ changes: number | null;
11
+ lastInsertRowId: number | null;
12
+ durationMs: number;
13
+ };
14
+ export type SqliteQueryResult = {
15
+ rows: Record<string, unknown>[];
16
+ columns: string[];
17
+ metadata: SqliteQueryMetadata;
18
+ };
19
+ export type SqliteStatementExecutionResult = {
20
+ input: SqliteStatementInput;
21
+ result: SqliteQueryResult;
22
+ };
23
+ export type SqliteScriptStatementResult = {
24
+ index: number;
25
+ start: number;
26
+ end: number;
27
+ input: SqliteStatementInput;
28
+ execution?: SqliteStatementExecutionResult;
29
+ error?: string;
30
+ };
31
+ export type SqliteScriptResult = {
32
+ statements: SqliteScriptStatementResult[];
33
+ totalStatementCount: number;
34
+ failedStatementIndex: number | null;
35
+ };
36
+ export type SqliteExecuteStatementsRunner = (statements: SqliteStatementInput[]) => Promise<SqliteQueryResult[]>;
37
+ export type SqliteExecuteStatementsError = Error & {
38
+ completedResults?: SqliteQueryResult[];
39
+ failedStatementIndex?: number;
40
+ };
41
+ export type SqliteDatabaseNode = {
42
+ id: string;
43
+ name: string;
44
+ executeStatements: SqliteExecuteStatementsRunner;
45
+ };
46
+ export type SqliteAdapter = {
47
+ id: string;
48
+ name: string;
49
+ databases: SqliteDatabaseNode[];
50
+ };
51
+ export type SqliteDatabaseInfo = {
52
+ id: string;
53
+ name: string;
54
+ adapterId: string;
55
+ adapterName: string;
56
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- {"name":"@rozenite/sqlite-plugin","version":"2.2.0","description":"SQLite inspector for Rozenite.","panels":[{"name":"SQLite","source":"/devtools/panel.html"}]}
1
+ {"name":"@rozenite/sqlite-plugin","version":"2.3.0","description":"SQLite inspector for Rozenite.","panels":[{"name":"SQLite","source":"/devtools/panel.html"}],"integrations":["react-native"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rozenite/sqlite-plugin",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "SQLite inspector for Rozenite.",
5
5
  "homepage": "https://github.com/callstackincubator/rozenite#readme",
6
6
  "bugs": {
@@ -12,14 +12,14 @@
12
12
  "url": "https://github.com/callstackincubator/rozenite.git"
13
13
  },
14
14
  "type": "module",
15
- "main": "./dist/react-native/index.cjs",
16
- "module": "./dist/react-native/index.js",
17
- "types": "./dist/react-native/index.d.ts",
15
+ "main": "./dist/react-native/cjs/react-native.js",
16
+ "module": "./dist/react-native/react-native.js",
17
+ "types": "./dist/react-native/react-native.d.ts",
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./dist/react-native/index.d.ts",
21
- "import": "./dist/react-native/index.js",
22
- "require": "./dist/react-native/index.cjs"
20
+ "types": "./dist/react-native/react-native.d.ts",
21
+ "import": "./dist/react-native/react-native.js",
22
+ "require": "./dist/react-native/cjs/react-native.js"
23
23
  },
24
24
  "./package.json": "./package.json"
25
25
  },
@@ -27,8 +27,8 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@rozenite/agent-bridge": "2.2.0",
31
- "@rozenite/plugin-bridge": "2.2.0"
30
+ "@rozenite/agent-bridge": "2.3.0",
31
+ "@rozenite/plugin-bridge": "2.3.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@codemirror/autocomplete": "^6.20.1",
@@ -57,8 +57,9 @@
57
57
  "typescript": "~5.9.3",
58
58
  "vite": "^7.3.1",
59
59
  "vitest": "^3.2.4",
60
- "@rozenite/vite-plugin": "2.2.0",
61
- "rozenite": "2.2.0"
60
+ "@rozenite/test-utils": "2.3.0",
61
+ "@rozenite/vite-plugin": "2.3.0",
62
+ "rozenite": "2.3.0"
62
63
  },
63
64
  "peerDependencies": {
64
65
  "expo-sqlite": "*",
package/react-native.ts CHANGED
@@ -33,9 +33,16 @@ export let statementReturnsRows: typeof import('./src/shared/sql').statementRetu
33
33
  export let decodeSqliteBridgeValue: typeof import('./src/shared/bridge-values').decodeSqliteBridgeValue;
34
34
  export let formatSqliteError: typeof import('./src/shared/bridge-values').formatSqliteError;
35
35
 
36
+ // Neither Lynx runtime has a `window`, so `typeof window` alone reported
37
+ // every Lynx app as a server and installed the no-op stub below. `lynx` is
38
+ // a free binding in module scope, not a property of `globalThis`. Kept
39
+ // inline rather than imported so this stays a foldable expression and the
40
+ // `require`s below can still be dropped from production bundles.
41
+ declare const lynx: unknown;
42
+
36
43
  const isDev = process.env.NODE_ENV !== 'production';
37
44
  const isWeb = typeof window !== 'undefined' && window.navigator.product !== 'ReactNative';
38
- const isServer = typeof window === 'undefined';
45
+ const isServer = typeof window === 'undefined' && typeof lynx === 'undefined';
39
46
 
40
47
  if (isDev && !isWeb && !isServer) {
41
48
  createSqliteAdapter = require('./src/react-native/adapters').createSqliteAdapter;
@@ -1,4 +1,5 @@
1
1
  export default {
2
+ integrations: ['react-native'],
2
3
  panels: [
3
4
  {
4
5
  name: 'SQLite',
@@ -0,0 +1,32 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { bundleForRelease, RELEASE_BUNDLE_TIMEOUT } from '@rozenite/test-utils';
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ // An app importing this plugin ships its React Native code -- that much is
7
+ // the app's own choice. What must never follow it into the bundle is the
8
+ // panel: the DevTools UI, its React DOM tree and `@rozenite/ui`.
9
+ // See docs/agents/release-bundle-testing.md.
10
+ const packageRoot = path.resolve(fileURLToPath(import.meta.url), '../../..');
11
+ const reactNativeEntry = path.join(packageRoot, 'dist/react-native/cjs/react-native.js');
12
+
13
+ describe('@rozenite/sqlite-plugin in a release bundle', () => {
14
+ it(
15
+ 'ships no panel code when an app imports it',
16
+ async () => {
17
+ const result = await bundleForRelease({
18
+ resolveFrom: packageRoot,
19
+ files: {
20
+ 'index.js': `require(${JSON.stringify(reactNativeEntry)});\n`,
21
+ },
22
+ });
23
+
24
+ // Keeps the check below honest: the entry really did get bundled.
25
+ expect(result.rozeniteModules).toContain(
26
+ 'packages/sqlite-plugin/dist/react-native/cjs/react-native.js',
27
+ );
28
+ expect(result.panelModules).toEqual([]);
29
+ },
30
+ RELEASE_BUNDLE_TIMEOUT,
31
+ );
32
+ });
@@ -1,2 +0,0 @@
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;
@@ -1,61 +0,0 @@
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 +0,0 @@
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,107 +0,0 @@
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";
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) => {
4
- const o = E(t), s = o.name ?? n ?? a;
5
- return {
6
- id: I(e, `${a}-${s}`, r),
7
- name: s,
8
- executeStatements: o.executeStatements
9
- };
10
- }, N = (e) => {
11
- const { adapterId: a = "sqlite", adapterName: t = "SQLite" } = e, r = "databases" in e ? Object.entries(e.databases).map(
12
- ([n, o], s) => l(a, n, o, s)
13
- ) : [
14
- l(
15
- a,
16
- e.databaseName ?? "default",
17
- e.database,
18
- 0,
19
- e.databaseName ?? "Default Database"
20
- )
21
- ];
22
- return {
23
- id: a,
24
- name: t,
25
- databases: r
26
- };
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(
28
- Object.entries(e).map(([a, t]) => [a, i(t)])
29
- ) : String(e), O = (e) => e.map(
30
- (a) => Object.fromEntries(Object.entries(a).map(([t, r]) => [t, i(r)]))
31
- ), h = async (e, { sql: a, params: t }) => {
32
- const r = S(a), n = y(r), o = m(), s = t === void 0 ? void 0 : x(t);
33
- if (w(n)) {
34
- const d = O(
35
- s === void 0 ? await e.getAllAsync(r) : await e.getAllAsync(r, s)
36
- ), p = m() - o;
37
- return {
38
- rows: d,
39
- columns: Object.keys(d[0] ?? {}),
40
- metadata: {
41
- statementType: n,
42
- rowCount: d.length,
43
- changes: null,
44
- lastInsertRowId: null,
45
- durationMs: p
46
- }
47
- };
48
- }
49
- const c = s === void 0 ? await e.runAsync(r) : await e.runAsync(r, s), b = m() - o;
50
- return {
51
- rows: [],
52
- columns: [],
53
- metadata: {
54
- statementType: n,
55
- rowCount: 0,
56
- changes: typeof c.changes == "number" ? c.changes : null,
57
- lastInsertRowId: typeof c.lastInsertRowId == "number" ? c.lastInsertRowId : null,
58
- durationMs: b
59
- }
60
- };
61
- }, u = (e) => async (a) => {
62
- const t = [];
63
- for (let r = 0; r < a.length; r += 1)
64
- try {
65
- t.push(await h(e, a[r]));
66
- } catch (n) {
67
- throw q(j(n), {
68
- completedResults: t,
69
- failedStatementIndex: r,
70
- cause: n
71
- });
72
- }
73
- return t;
74
- }, f = (e) => "database" in e ? e : { database: e }, $ = (e) => {
75
- const a = "databases" in e ? {
76
- adapterId: e.adapterId ?? "expo-sqlite",
77
- adapterName: e.adapterName ?? "Expo SQLite",
78
- databases: Object.fromEntries(
79
- Object.entries(e.databases).map(([t, r]) => {
80
- const n = f(r);
81
- return [
82
- t,
83
- {
84
- name: n.name ?? t,
85
- executeStatements: u(n.database)
86
- }
87
- ];
88
- })
89
- )
90
- } : {
91
- adapterId: e.adapterId ?? "expo-sqlite",
92
- adapterName: e.adapterName ?? "Expo SQLite",
93
- databaseName: e.databaseName,
94
- database: (() => {
95
- const t = f(e.database);
96
- return {
97
- name: t.name ?? e.databaseName,
98
- executeStatements: u(t.database)
99
- };
100
- })()
101
- };
102
- return N(a);
103
- };
104
- export {
105
- $ as createExpoSqliteAdapter,
106
- N as createSqliteAdapter
107
- };