@rozenite/sqlite-plugin 1.7.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +20 -0
  3. package/README.md +102 -0
  4. package/dist/devtools/assets/panel-B3paLkwG.js +82 -0
  5. package/dist/devtools/assets/panel-CIU0JBOs.css +1 -0
  6. package/dist/devtools/panel.html +31 -0
  7. package/dist/react-native/chunks/bridge-values.cjs +5 -0
  8. package/dist/react-native/chunks/bridge-values.js +258 -0
  9. package/dist/react-native/chunks/index.require.cjs +1 -0
  10. package/dist/react-native/chunks/index.require.js +118 -0
  11. package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.cjs +1 -0
  12. package/dist/react-native/chunks/useRozeniteSqlitePlugin.require.js +189 -0
  13. package/dist/react-native/index.cjs +1 -0
  14. package/dist/react-native/index.d.ts +178 -0
  15. package/dist/react-native/index.js +16 -0
  16. package/dist/rozenite.json +1 -0
  17. package/package.json +83 -0
  18. package/postcss.config.js +6 -0
  19. package/react-native.ts +55 -0
  20. package/rozenite.config.ts +8 -0
  21. package/src/react-native/adapters/__tests__/expo-sqlite.test.ts +94 -0
  22. package/src/react-native/adapters/expo-sqlite.ts +230 -0
  23. package/src/react-native/adapters/generic.ts +88 -0
  24. package/src/react-native/adapters/index.ts +9 -0
  25. package/src/react-native/sqlite-view.ts +24 -0
  26. package/src/react-native/useRozeniteSqlitePlugin.ts +262 -0
  27. package/src/shared/__tests__/bridge-values.test.ts +34 -0
  28. package/src/shared/__tests__/sql.test.ts +55 -0
  29. package/src/shared/bridge-values.ts +170 -0
  30. package/src/shared/protocol.ts +41 -0
  31. package/src/shared/sql.ts +420 -0
  32. package/src/shared/types.ts +81 -0
  33. package/src/ui/__tests__/sql-editor-utils.test.ts +135 -0
  34. package/src/ui/__tests__/sqlite-row-edit-value.test.ts +22 -0
  35. package/src/ui/__tests__/sqlite-row-mutations.test.ts +310 -0
  36. package/src/ui/__tests__/sqlite-table-column-order.test.ts +83 -0
  37. package/src/ui/__tests__/value-utils.test.tsx +12 -0
  38. package/src/ui/cell-detail-drawer.tsx +65 -0
  39. package/src/ui/globals.css +1415 -0
  40. package/src/ui/panel.tsx +2815 -0
  41. package/src/ui/query-result-table.tsx +199 -0
  42. package/src/ui/sql-editor-utils.ts +352 -0
  43. package/src/ui/sql-editor.tsx +509 -0
  44. package/src/ui/sqlite-data-table.tsx +296 -0
  45. package/src/ui/sqlite-introspection.ts +189 -0
  46. package/src/ui/sqlite-modal-controls.tsx +32 -0
  47. package/src/ui/sqlite-row-delete-modal.tsx +130 -0
  48. package/src/ui/sqlite-row-edit-modal.tsx +487 -0
  49. package/src/ui/sqlite-row-edit-value.ts +53 -0
  50. package/src/ui/sqlite-row-mutations.ts +246 -0
  51. package/src/ui/sqlite-table-column-order.ts +154 -0
  52. package/src/ui/use-sqlite-requests.ts +205 -0
  53. package/src/ui/utils.ts +107 -0
  54. package/src/ui/value-utils.tsx +162 -0
  55. package/tsconfig.json +36 -0
  56. package/vite.config.ts +20 -0
@@ -0,0 +1,162 @@
1
+ import { JSONTree } from 'react-json-tree';
2
+ import type {
3
+ SqliteQueryMetadata,
4
+ SqliteQueryResult,
5
+ SqliteScriptResult,
6
+ } from '../shared/types';
7
+ import { truncateText } from './utils';
8
+
9
+ const jsonTreeTheme = {
10
+ base00: 'transparent',
11
+ base01: '#10233c',
12
+ base02: '#173150',
13
+ base03: '#7b94b6',
14
+ base04: '#bfd0e5',
15
+ base05: '#eef5ff',
16
+ base06: '#ffffff',
17
+ base07: '#ffffff',
18
+ base08: '#fb7185',
19
+ base09: '#f59e0b',
20
+ base0A: '#facc15',
21
+ base0B: '#34d399',
22
+ base0C: '#22d3ee',
23
+ base0D: '#60a5fa',
24
+ base0E: '#78b8ff',
25
+ base0F: '#f97316',
26
+ };
27
+
28
+ export const isStructuredValue = (
29
+ value: unknown,
30
+ ): value is Record<string, unknown> | unknown[] => {
31
+ return Array.isArray(value) || (!!value && typeof value === 'object');
32
+ };
33
+
34
+ export const getValueKind = (value: unknown) => {
35
+ if (value === null) {
36
+ return 'null';
37
+ }
38
+
39
+ if (Array.isArray(value)) {
40
+ return value.every((item) => typeof item === 'number')
41
+ ? 'blob-ish'
42
+ : 'array';
43
+ }
44
+
45
+ return typeof value;
46
+ };
47
+
48
+ export const stringifyValue = (value: unknown) => {
49
+ if (value === null) {
50
+ return 'null';
51
+ }
52
+
53
+ if (value === undefined) {
54
+ return 'undefined';
55
+ }
56
+
57
+ if (typeof value === 'string') {
58
+ return value;
59
+ }
60
+
61
+ if (typeof value === 'number' || typeof value === 'boolean') {
62
+ return String(value);
63
+ }
64
+
65
+ try {
66
+ return JSON.stringify(value, null, 2);
67
+ } catch {
68
+ return String(value);
69
+ }
70
+ };
71
+
72
+ export const getValuePreview = (value: unknown, maxLength = 120) => {
73
+ if (value === null) {
74
+ return 'null';
75
+ }
76
+
77
+ if (typeof value === 'string') {
78
+ return truncateText(value.replace(/\s+/g, ' '), maxLength);
79
+ }
80
+
81
+ if (typeof value === 'number' || typeof value === 'boolean') {
82
+ return String(value);
83
+ }
84
+
85
+ if (Array.isArray(value) && value.every((item) => typeof item === 'number')) {
86
+ return `byte[${value.length}] ${truncateText(JSON.stringify(value), maxLength)}`;
87
+ }
88
+
89
+ return truncateText(stringifyValue(value).replace(/\s+/g, ' '), maxLength);
90
+ };
91
+
92
+ export const getMetadataBadgeClassName = (metadata: SqliteQueryMetadata) => {
93
+ if (
94
+ metadata.statementType === 'select' ||
95
+ metadata.statementType === 'pragma' ||
96
+ metadata.statementType === 'with' ||
97
+ metadata.statementType === 'explain'
98
+ ) {
99
+ return 'sqlite-badge sqlite-badge-success';
100
+ }
101
+
102
+ if (
103
+ metadata.statementType === 'insert' ||
104
+ metadata.statementType === 'update' ||
105
+ metadata.statementType === 'delete'
106
+ ) {
107
+ return 'sqlite-badge sqlite-badge-warning';
108
+ }
109
+
110
+ return 'sqlite-badge sqlite-badge-neutral';
111
+ };
112
+
113
+ export const renderStructuredValue = (value: unknown) => {
114
+ if (!isStructuredValue(value)) {
115
+ return null;
116
+ }
117
+
118
+ return (
119
+ <JSONTree
120
+ data={value}
121
+ theme={jsonTreeTheme}
122
+ invertTheme={false}
123
+ shouldExpandNodeInitially={(keyPath) => keyPath.length <= 2}
124
+ />
125
+ );
126
+ };
127
+
128
+ export const getResultSummary = (result: SqliteQueryResult | null) => {
129
+ if (!result) {
130
+ return null;
131
+ }
132
+
133
+ const { metadata } = result;
134
+
135
+ if (metadata.rowCount > 0) {
136
+ return `${metadata.rowCount} rows returned`;
137
+ }
138
+
139
+ if (metadata.changes != null) {
140
+ return `${metadata.changes} rows changed`;
141
+ }
142
+
143
+ return 'Statement executed';
144
+ };
145
+
146
+ export const getScriptResultSummary = (result: SqliteScriptResult | null) => {
147
+ if (!result) {
148
+ return null;
149
+ }
150
+
151
+ const executedCount = result.statements.length;
152
+
153
+ if (result.failedStatementIndex != null) {
154
+ return `Executed ${executedCount} of ${result.totalStatementCount} statements before failing`;
155
+ }
156
+
157
+ if (result.totalStatementCount === 1) {
158
+ return 'Executed 1 statement';
159
+ }
160
+
161
+ return `Executed ${result.totalStatementCount} statements`;
162
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "esModuleInterop": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "module": "ESNext",
13
+ "moduleResolution": "bundler",
14
+ "baseUrl": ".",
15
+ "paths": {
16
+ "@rozenite/plugin-bridge": ["../plugin-bridge/src/index.ts"]
17
+ },
18
+ "resolveJsonModule": true,
19
+ "isolatedModules": true,
20
+ "noEmit": true,
21
+ "jsx": "react-jsx"
22
+ },
23
+ "include": ["src/**/*", "react-native.ts", "rozenite.config.ts"],
24
+ "exclude": ["node_modules", "dist", "build"],
25
+ "references": [
26
+ {
27
+ "path": "../plugin-bridge"
28
+ },
29
+ {
30
+ "path": "../cli"
31
+ },
32
+ {
33
+ "path": "../vite-plugin"
34
+ }
35
+ ]
36
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,20 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+ import { rozenitePlugin } from '@rozenite/vite-plugin';
4
+
5
+ export default defineConfig({
6
+ root: __dirname,
7
+ plugins: [rozenitePlugin()],
8
+ base: './',
9
+ build: {
10
+ outDir: './dist',
11
+ emptyOutDir: false,
12
+ reportCompressedSize: false,
13
+ minify: true,
14
+ sourcemap: false,
15
+ },
16
+ server: {
17
+ port: 3000,
18
+ open: true,
19
+ },
20
+ });