@promakeai/dbreact 1.0.7 → 1.1.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/README.md +179 -145
- package/dist/adapters/SqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/SqliteAdapter.js +8 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/package.json +59 -59
package/README.md
CHANGED
|
@@ -4,12 +4,13 @@ React hooks and providers for schema-driven, multi-language databases. Type-safe
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Type-Safe Hooks** - Generic React hooks with generated TypeScript types
|
|
7
|
+
- **Type-Safe Hooks** - Generic React hooks with generated TypeScript types
|
|
8
8
|
- **Multi-Language Support** - Automatic translation queries with fallback
|
|
9
9
|
- **Browser SQLite** - sql.js WASM adapter for offline-first apps
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
10
|
+
- **REST API Adapter** - Remote database access with dynamic Bearer auth
|
|
11
|
+
- **React Query Integration** - Built-in caching, loading states, optimistic updates
|
|
12
|
+
- **Zero-Config Language Switching** - Change language, queries refetch automatically
|
|
13
|
+
- **MongoDB-Style Queries** - Intuitive filter syntax (`$gt`, `$in`, `$like`, `$contains`, etc.)
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
15
16
|
|
|
@@ -26,16 +27,16 @@ npm install @promakeai/dbreact @tanstack/react-query
|
|
|
26
27
|
### 1. Setup Adapter
|
|
27
28
|
|
|
28
29
|
```tsx
|
|
29
|
-
import { SqliteAdapter } from '@promakeai/dbreact';
|
|
30
|
-
import { parseJSONSchema } from '@promakeai/dbreact';
|
|
31
|
-
import schemaJson from './schema.json';
|
|
32
|
-
|
|
33
|
-
const schema = parseJSONSchema(schemaJson as any);
|
|
34
|
-
|
|
35
|
-
const adapter = new SqliteAdapter({
|
|
36
|
-
storageKey: 'myapp-db', // localStorage key for persistence
|
|
37
|
-
schema,
|
|
38
|
-
});
|
|
30
|
+
import { SqliteAdapter } from '@promakeai/dbreact';
|
|
31
|
+
import { parseJSONSchema } from '@promakeai/dbreact';
|
|
32
|
+
import schemaJson from './schema.json';
|
|
33
|
+
|
|
34
|
+
const schema = parseJSONSchema(schemaJson as any);
|
|
35
|
+
|
|
36
|
+
const adapter = new SqliteAdapter({
|
|
37
|
+
storageKey: 'myapp-db', // localStorage key for persistence
|
|
38
|
+
schema,
|
|
39
|
+
});
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
### 2. Wrap App with Provider
|
|
@@ -103,27 +104,27 @@ Main provider component that wraps your application.
|
|
|
103
104
|
|
|
104
105
|
```tsx
|
|
105
106
|
<DbProvider
|
|
106
|
-
adapter={adapter}
|
|
107
|
-
schema={schema}
|
|
108
|
-
lang="tr"
|
|
109
|
-
fallbackLang="en"
|
|
110
|
-
autoConnect={true}
|
|
111
|
-
>
|
|
107
|
+
adapter={adapter}
|
|
108
|
+
schema={schema}
|
|
109
|
+
lang="tr"
|
|
110
|
+
fallbackLang="en"
|
|
111
|
+
autoConnect={true}
|
|
112
|
+
>
|
|
112
113
|
<App />
|
|
113
114
|
</DbProvider>
|
|
114
115
|
```
|
|
115
116
|
|
|
116
117
|
**Props:**
|
|
117
118
|
|
|
118
|
-
| Prop | Type | Required | Default | Description |
|
|
119
|
-
|------|------|----------|---------|-------------|
|
|
120
|
-
| `adapter` | `IDataAdapter` | Yes | - | Database adapter instance |
|
|
121
|
-
| `schema` | `SchemaDefinition` | No | - | Enables populate + typed serialization |
|
|
122
|
-
| `lang` | `string` | No | `'en'` | Current language code |
|
|
123
|
-
| `fallbackLang` | `string` | No | `'en'` | Fallback language |
|
|
124
|
-
| `autoConnect` | `boolean` | No | `true` | Auto-connect on mount |
|
|
125
|
-
| `queryClient` | `QueryClient` | No | Internal | Provide a custom React Query client |
|
|
126
|
-
| `children` | `ReactNode` | Yes | - | Child components |
|
|
119
|
+
| Prop | Type | Required | Default | Description |
|
|
120
|
+
|------|------|----------|---------|-------------|
|
|
121
|
+
| `adapter` | `IDataAdapter` | Yes | - | Database adapter instance |
|
|
122
|
+
| `schema` | `SchemaDefinition` | No | - | Enables populate + typed serialization |
|
|
123
|
+
| `lang` | `string` | No | `'en'` | Current language code |
|
|
124
|
+
| `fallbackLang` | `string` | No | `'en'` | Fallback language |
|
|
125
|
+
| `autoConnect` | `boolean` | No | `true` | Auto-connect on mount |
|
|
126
|
+
| `queryClient` | `QueryClient` | No | Internal | Provide a custom React Query client |
|
|
127
|
+
| `children` | `ReactNode` | Yes | - | Child components |
|
|
127
128
|
|
|
128
129
|
---
|
|
129
130
|
|
|
@@ -151,29 +152,29 @@ const { data, isLoading, error, refetch } = useDbList<Product>('products', {
|
|
|
151
152
|
| `orderBy` | `array` | Sort order `[{ field, direction }]` |
|
|
152
153
|
| `limit` | `number` | Max records to return |
|
|
153
154
|
| `offset` | `number` | Skip records |
|
|
154
|
-
| `populate` | `PopulateOption` | Resolve foreign key references (string, array, or object) |
|
|
155
|
+
| `populate` | `PopulateOption` | Resolve foreign key references (string, array, or object) |
|
|
155
156
|
| `enabled` | `boolean` | Enable/disable query |
|
|
156
157
|
|
|
157
|
-
#### useDbGet
|
|
158
|
-
|
|
159
|
-
Fetch single record by ID.
|
|
160
|
-
|
|
161
|
-
```tsx
|
|
162
|
-
const { data: product, isLoading } = useDbGet<Product>('products', productId, {
|
|
163
|
-
populate: ['categoryId'],
|
|
164
|
-
enabled: !!productId,
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Find-one style (by where clause):
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
const { data: product } = useDbGet<Product>('products', {
|
|
172
|
-
where: { slug: 'my-product' },
|
|
173
|
-
enabled: !!slug,
|
|
174
|
-
populate: { categoryId: true },
|
|
175
|
-
});
|
|
176
|
-
```
|
|
158
|
+
#### useDbGet
|
|
159
|
+
|
|
160
|
+
Fetch single record by ID.
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
const { data: product, isLoading } = useDbGet<Product>('products', productId, {
|
|
164
|
+
populate: ['categoryId'],
|
|
165
|
+
enabled: !!productId,
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Find-one style (by where clause):
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
const { data: product } = useDbGet<Product>('products', {
|
|
173
|
+
where: { slug: 'my-product' },
|
|
174
|
+
enabled: !!slug,
|
|
175
|
+
populate: { categoryId: true },
|
|
176
|
+
});
|
|
177
|
+
```
|
|
177
178
|
|
|
178
179
|
---
|
|
179
180
|
|
|
@@ -200,13 +201,13 @@ createProduct.mutate(
|
|
|
200
201
|
Update an existing record.
|
|
201
202
|
|
|
202
203
|
```tsx
|
|
203
|
-
const updateProduct = useDbUpdate<Product>('products');
|
|
204
|
-
|
|
205
|
-
updateProduct.mutate(
|
|
206
|
-
{ id: productId, data: { price: 89.99 } },
|
|
207
|
-
{
|
|
208
|
-
onSuccess: () => console.log('Updated'),
|
|
209
|
-
}
|
|
204
|
+
const updateProduct = useDbUpdate<Product>('products');
|
|
205
|
+
|
|
206
|
+
updateProduct.mutate(
|
|
207
|
+
{ id: productId, data: { price: 89.99 } },
|
|
208
|
+
{
|
|
209
|
+
onSuccess: () => console.log('Updated'),
|
|
210
|
+
}
|
|
210
211
|
);
|
|
211
212
|
```
|
|
212
213
|
|
|
@@ -215,11 +216,11 @@ updateProduct.mutate(
|
|
|
215
216
|
Delete a record.
|
|
216
217
|
|
|
217
218
|
```tsx
|
|
218
|
-
const deleteProduct = useDbDelete('products');
|
|
219
|
-
|
|
220
|
-
deleteProduct.mutate(productId, {
|
|
221
|
-
onSuccess: () => console.log('Deleted'),
|
|
222
|
-
});
|
|
219
|
+
const deleteProduct = useDbDelete('products');
|
|
220
|
+
|
|
221
|
+
deleteProduct.mutate(productId, {
|
|
222
|
+
onSuccess: () => console.log('Deleted'),
|
|
223
|
+
});
|
|
223
224
|
```
|
|
224
225
|
|
|
225
226
|
---
|
|
@@ -289,6 +290,41 @@ const adapter = new SqliteAdapter({
|
|
|
289
290
|
- localStorage limit: ~5-10MB (browser dependent)
|
|
290
291
|
- Best for < 10,000 records
|
|
291
292
|
|
|
293
|
+
### RestAdapter
|
|
294
|
+
|
|
295
|
+
REST API adapter for remote database access. Supports static tokens and dynamic `getToken` callbacks.
|
|
296
|
+
|
|
297
|
+
```tsx
|
|
298
|
+
import { RestAdapter } from '@promakeai/dbreact';
|
|
299
|
+
|
|
300
|
+
const adapter = new RestAdapter({
|
|
301
|
+
baseUrl: 'https://api.example.com',
|
|
302
|
+
databasePrefix: '/database',
|
|
303
|
+
schema,
|
|
304
|
+
defaultLang: 'en',
|
|
305
|
+
// Dynamic token — called on every request
|
|
306
|
+
getToken: () => {
|
|
307
|
+
try {
|
|
308
|
+
const raw = localStorage.getItem('auth-storage');
|
|
309
|
+
return raw ? JSON.parse(raw)?.state?.tokens?.accessToken ?? null : null;
|
|
310
|
+
} catch { return null; }
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Config:**
|
|
316
|
+
|
|
317
|
+
| Option | Type | Required | Description |
|
|
318
|
+
|--------|------|----------|-------------|
|
|
319
|
+
| `baseUrl` | `string` | Yes | API base URL |
|
|
320
|
+
| `databasePrefix` | `string` | No | Endpoint prefix (default: `/database`) |
|
|
321
|
+
| `token` | `string` | No | Static Bearer token |
|
|
322
|
+
| `getToken` | `() => string \| null` | No | Dynamic token getter (priority over `token`) |
|
|
323
|
+
| `schema` | `SchemaDefinition` | No | Schema for translation support |
|
|
324
|
+
| `defaultLang` | `string` | No | Default language |
|
|
325
|
+
| `headers` | `Record<string, string>` | No | Custom headers |
|
|
326
|
+
| `timeout` | `number` | No | Request timeout in ms (default: 30000) |
|
|
327
|
+
|
|
292
328
|
---
|
|
293
329
|
|
|
294
330
|
## Query Options
|
|
@@ -312,16 +348,16 @@ const adapter = new SqliteAdapter({
|
|
|
312
348
|
{ name: { $like: '%shirt%' } } // LIKE '%shirt%'
|
|
313
349
|
{ name: { $notLike: '%test%' } } // NOT LIKE '%test%'
|
|
314
350
|
|
|
315
|
-
// Range
|
|
316
|
-
{ price: { $between: [10, 100] } } // BETWEEN 10 AND 100
|
|
317
|
-
|
|
318
|
-
// Null
|
|
319
|
-
{ description: { $isNull: true } } // IS NULL
|
|
320
|
-
{ description: { $isNull: false } } // IS NOT NULL
|
|
321
|
-
|
|
322
|
-
// JSON array contains
|
|
323
|
-
{ tags: { $contains: "sale" } }
|
|
324
|
-
{ tags: { $containsAny: ["sale", "new"] } }
|
|
351
|
+
// Range
|
|
352
|
+
{ price: { $between: [10, 100] } } // BETWEEN 10 AND 100
|
|
353
|
+
|
|
354
|
+
// Null
|
|
355
|
+
{ description: { $isNull: true } } // IS NULL
|
|
356
|
+
{ description: { $isNull: false } } // IS NOT NULL
|
|
357
|
+
|
|
358
|
+
// JSON array contains
|
|
359
|
+
{ tags: { $contains: "sale" } }
|
|
360
|
+
{ tags: { $containsAny: ["sale", "new"] } }
|
|
325
361
|
|
|
326
362
|
// Logical
|
|
327
363
|
{ $and: [
|
|
@@ -340,18 +376,18 @@ const adapter = new SqliteAdapter({
|
|
|
340
376
|
### Query Interface
|
|
341
377
|
|
|
342
378
|
```typescript
|
|
343
|
-
interface QueryOptions {
|
|
344
|
-
where?: Record<string, unknown>;
|
|
345
|
-
orderBy?: Array<{
|
|
346
|
-
field: string;
|
|
347
|
-
direction: 'ASC' | 'DESC';
|
|
348
|
-
}>;
|
|
349
|
-
limit?: number;
|
|
350
|
-
offset?: number;
|
|
351
|
-
populate?: PopulateOption;
|
|
352
|
-
lang?: string;
|
|
353
|
-
fallbackLang?: string;
|
|
354
|
-
}
|
|
379
|
+
interface QueryOptions {
|
|
380
|
+
where?: Record<string, unknown>;
|
|
381
|
+
orderBy?: Array<{
|
|
382
|
+
field: string;
|
|
383
|
+
direction: 'ASC' | 'DESC';
|
|
384
|
+
}>;
|
|
385
|
+
limit?: number;
|
|
386
|
+
offset?: number;
|
|
387
|
+
populate?: PopulateOption;
|
|
388
|
+
lang?: string;
|
|
389
|
+
fallbackLang?: string;
|
|
390
|
+
}
|
|
355
391
|
```
|
|
356
392
|
|
|
357
393
|
---
|
|
@@ -360,20 +396,18 @@ interface QueryOptions {
|
|
|
360
396
|
|
|
361
397
|
### Schema with Translatable Fields
|
|
362
398
|
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
},
|
|
376
|
-
});
|
|
399
|
+
```json
|
|
400
|
+
{
|
|
401
|
+
"languages": ["en", "tr", "de"],
|
|
402
|
+
"tables": {
|
|
403
|
+
"products": {
|
|
404
|
+
"id": { "type": "id" },
|
|
405
|
+
"price": { "type": "decimal" },
|
|
406
|
+
"name": { "type": "string", "translatable": true },
|
|
407
|
+
"description": { "type": "text", "translatable": true }
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
377
411
|
```
|
|
378
412
|
|
|
379
413
|
### Automatic Translation
|
|
@@ -409,32 +443,32 @@ function LanguageSwitcher() {
|
|
|
409
443
|
|
|
410
444
|
---
|
|
411
445
|
|
|
412
|
-
## Generated Types + Generic Hooks
|
|
413
|
-
|
|
414
|
-
Generate runtime schema and TypeScript interfaces:
|
|
415
|
-
|
|
416
|
-
```bash
|
|
417
|
-
dbcli generate --schema ./schema.json --output ./src/db
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
`dbcli generate` writes `schema.json` and `types.ts`. React hooks are imported from `@promakeai/dbreact`:
|
|
421
|
-
|
|
422
|
-
```tsx
|
|
423
|
-
import { useDbList, useDbGet, useDbCreate } from '@promakeai/dbreact';
|
|
424
|
-
import type { DbProduct, DbProductInput } from './db/types';
|
|
425
|
-
|
|
426
|
-
function ProductManager() {
|
|
427
|
-
const { data: products } = useDbList<DbProduct>('products', {
|
|
428
|
-
where: { stock: { $gt: 0 } },
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
const { data: product } = useDbGet<DbProduct>('products', 1);
|
|
432
|
-
|
|
433
|
-
const createProduct = useDbCreate<DbProduct, DbProductInput>('products');
|
|
434
|
-
|
|
435
|
-
return null;
|
|
436
|
-
}
|
|
437
|
-
```
|
|
446
|
+
## Generated Types + Generic Hooks
|
|
447
|
+
|
|
448
|
+
Generate runtime schema and TypeScript interfaces:
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
dbcli generate --schema ./schema.json --output ./src/db
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
`dbcli generate` writes `schema.json` and `types.ts`. React hooks are imported from `@promakeai/dbreact`:
|
|
455
|
+
|
|
456
|
+
```tsx
|
|
457
|
+
import { useDbList, useDbGet, useDbCreate } from '@promakeai/dbreact';
|
|
458
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
459
|
+
|
|
460
|
+
function ProductManager() {
|
|
461
|
+
const { data: products } = useDbList<DbProduct>('products', {
|
|
462
|
+
where: { stock: { $gt: 0 } },
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
const { data: product } = useDbGet<DbProduct>('products', 1);
|
|
466
|
+
|
|
467
|
+
const createProduct = useDbCreate<DbProduct, DbProductInput>('products');
|
|
468
|
+
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
```
|
|
438
472
|
|
|
439
473
|
---
|
|
440
474
|
|
|
@@ -443,10 +477,10 @@ function ProductManager() {
|
|
|
443
477
|
### Custom React Query Options
|
|
444
478
|
|
|
445
479
|
```tsx
|
|
446
|
-
const { data } = useDbList('products', {
|
|
447
|
-
where: { active: true },
|
|
448
|
-
limit: 50,
|
|
449
|
-
});
|
|
480
|
+
const { data } = useDbList('products', {
|
|
481
|
+
where: { active: true },
|
|
482
|
+
limit: 50,
|
|
483
|
+
});
|
|
450
484
|
```
|
|
451
485
|
|
|
452
486
|
### Direct Adapter Access
|
|
@@ -480,7 +514,7 @@ function AdvancedSearch() {
|
|
|
480
514
|
```tsx
|
|
481
515
|
function ProductPrice({ product }) {
|
|
482
516
|
const queryClient = useQueryClient();
|
|
483
|
-
const updateProduct = useDbUpdate('products');
|
|
517
|
+
const updateProduct = useDbUpdate('products');
|
|
484
518
|
|
|
485
519
|
const handlePriceChange = async (newPrice: number) => {
|
|
486
520
|
// Optimistic update
|
|
@@ -489,10 +523,10 @@ function ProductPrice({ product }) {
|
|
|
489
523
|
{ ...product, price: newPrice }
|
|
490
524
|
);
|
|
491
525
|
|
|
492
|
-
await updateProduct.mutateAsync({
|
|
493
|
-
id: product.id,
|
|
494
|
-
data: { price: newPrice },
|
|
495
|
-
});
|
|
526
|
+
await updateProduct.mutateAsync({
|
|
527
|
+
id: product.id,
|
|
528
|
+
data: { price: newPrice },
|
|
529
|
+
});
|
|
496
530
|
};
|
|
497
531
|
|
|
498
532
|
return <PriceInput value={product.price} onChange={handlePriceChange} />;
|
|
@@ -584,13 +618,13 @@ function ProductSearch() {
|
|
|
584
618
|
Full TypeScript support with generated types:
|
|
585
619
|
|
|
586
620
|
```typescript
|
|
587
|
-
import type { DbProduct, DbProductInput } from './db/types';
|
|
621
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
588
622
|
|
|
589
623
|
// Type-safe queries
|
|
590
|
-
const products: DbProduct[] = await adapter.list('products');
|
|
624
|
+
const products: DbProduct[] = await adapter.list('products');
|
|
591
625
|
|
|
592
626
|
// Type-safe creates
|
|
593
|
-
const newProduct: DbProductInput = {
|
|
627
|
+
const newProduct: DbProductInput = {
|
|
594
628
|
sku: 'SHIRT-001',
|
|
595
629
|
price: 99.99,
|
|
596
630
|
};
|
|
@@ -622,14 +656,14 @@ await adapter.create('products', newProduct);
|
|
|
622
656
|
|
|
623
657
|
---
|
|
624
658
|
|
|
625
|
-
## Troubleshooting
|
|
626
|
-
|
|
627
|
-
**Production crash: `jsxDEV is not a function`**
|
|
628
|
-
- Run `bun run test:build-runtime` before publishing.
|
|
629
|
-
- This verifies `dist/index.js` does not include `react/jsx-dev-runtime`.
|
|
630
|
-
|
|
631
|
-
**"useDbLang must be used within a DbProvider"**
|
|
632
|
-
- Ensure component is wrapped in DbProvider
|
|
659
|
+
## Troubleshooting
|
|
660
|
+
|
|
661
|
+
**Production crash: `jsxDEV is not a function`**
|
|
662
|
+
- Run `bun run test:build-runtime` before publishing.
|
|
663
|
+
- This verifies `dist/index.js` does not include `react/jsx-dev-runtime`.
|
|
664
|
+
|
|
665
|
+
**"useDbLang must be used within a DbProvider"**
|
|
666
|
+
- Ensure component is wrapped in DbProvider
|
|
633
667
|
|
|
634
668
|
**Queries return empty results**
|
|
635
669
|
- Check adapter is connected: `const { isConnected } = useDb()`
|
|
@@ -645,7 +679,7 @@ await adapter.create('products', newProduct);
|
|
|
645
679
|
|
|
646
680
|
## Related Packages
|
|
647
681
|
|
|
648
|
-
- [@promakeai/orm](../orm) - Core ORM with
|
|
682
|
+
- [@promakeai/orm](../orm) - Core ORM with query builder
|
|
649
683
|
- [@promakeai/dbcli](../dbcli) - CLI tool for database operations
|
|
650
684
|
|
|
651
685
|
## License
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteAdapter.d.ts","sourceRoot":"","sources":["../../adapters/SqliteAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAepG,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,gDAAgD;IAChD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,wCA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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAAE,GAChE,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAWzB,UAAU,CACd,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GACvB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAW/B;;OAEG;IACH,MAAM,IAAI,UAAU;IAIpB;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C;;OAEG;IACH,KAAK,IAAI,IAAI;CAQd"}
|
|
@@ -67,7 +67,14 @@ export class SqliteAdapter {
|
|
|
67
67
|
if (!this.db)
|
|
68
68
|
return;
|
|
69
69
|
const data = this.db.export();
|
|
70
|
-
|
|
70
|
+
// Convert Uint8Array to base64 in chunks to avoid call stack overflow
|
|
71
|
+
let binary = "";
|
|
72
|
+
const chunkSize = 8192;
|
|
73
|
+
for (let i = 0; i < data.length; i += chunkSize) {
|
|
74
|
+
const chunk = data.subarray(i, i + chunkSize);
|
|
75
|
+
binary += String.fromCharCode(...chunk);
|
|
76
|
+
}
|
|
77
|
+
const base64 = btoa(binary);
|
|
71
78
|
localStorage.setItem(this.config.storageKey, base64);
|
|
72
79
|
}
|
|
73
80
|
getDb() {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* React client for schema-driven multi-language database.
|
|
5
5
|
* Works with SQL.js (browser SQLite) or REST API backends.
|
|
6
6
|
*/
|
|
7
|
-
export { ORM,
|
|
7
|
+
export { ORM, buildWhereClause, resolvePopulate, getPopulatableFields, validatePopulate, parseJSONSchema, } from "@promakeai/orm";
|
|
8
8
|
export type { SchemaDefinition, TableDefinition, FieldDefinition, PopulateOption, PopulateNested, ORMConfig, QueryOptions, PaginatedResult, IDataAdapter, WhereResult, } from "@promakeai/orm";
|
|
9
9
|
export type { DbProviderConfig, DbLangContextValue, DbContextValue, } from "./types";
|
|
10
10
|
export { DbProvider, useDb, useAdapter, useDbLang, } from "./providers/DbProvider";
|
|
11
11
|
export { useDbList, useDbGet, useDbCreate, useDbUpdate, useDbDelete, type ListOptions, type FindOneOptions, } from "./hooks/useDbHooks";
|
|
12
12
|
export { SqliteAdapter, type SqliteAdapterConfig } from "./adapters/SqliteAdapter";
|
|
13
|
+
export { RestAdapter, type RestAdapterConfig } from "@promakeai/orm";
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,GAAG,EACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,GAAG,EACH,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,GACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* Works with SQL.js (browser SQLite) or REST API backends.
|
|
6
6
|
*/
|
|
7
7
|
// Re-export ORM core for browser usage
|
|
8
|
-
export { ORM,
|
|
8
|
+
export { ORM, buildWhereClause, resolvePopulate, getPopulatableFields, validatePopulate, parseJSONSchema, } from "@promakeai/orm";
|
|
9
9
|
// Provider
|
|
10
10
|
export { DbProvider, useDb, useAdapter, useDbLang, } from "./providers/DbProvider";
|
|
11
11
|
// Generic Hooks
|
|
12
12
|
export { useDbList, useDbGet, useDbCreate, useDbUpdate, useDbDelete, } from "./hooks/useDbHooks";
|
|
13
13
|
// Adapters
|
|
14
14
|
export { SqliteAdapter } from "./adapters/SqliteAdapter";
|
|
15
|
+
export { RestAdapter } from "@promakeai/orm";
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@promakeai/dbreact",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "React client for schema-driven multi-language database",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.js",
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build:js": "tsc --project tsconfig.json --declaration false --declarationMap false --emitDeclarationOnly false --outDir dist",
|
|
18
|
-
"build": "bun run build:js && bun run build:types",
|
|
19
|
-
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
20
|
-
"dev": "bun build index.ts --outdir dist --target browser --packages=external --watch",
|
|
21
|
-
"test": "bun test",
|
|
22
|
-
"test:build-runtime": "bun run build && bun test ./tests/build-runtime.test.ts",
|
|
23
|
-
"typecheck": "tsc --noEmit",
|
|
24
|
-
"release": "bun run build && npm publish --access public"
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist"
|
|
28
|
-
],
|
|
29
|
-
"keywords": [
|
|
30
|
-
"react",
|
|
31
|
-
"database",
|
|
32
|
-
"sqlite",
|
|
33
|
-
"multi-language",
|
|
34
|
-
"tanstack-query"
|
|
35
|
-
],
|
|
36
|
-
"author": "Promake Inc.",
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"react": ">=19.0.0",
|
|
40
|
-
"react-dom": ">=19.0.0",
|
|
41
|
-
"@tanstack/react-query": ">=5.0.0",
|
|
42
|
-
"sql.js": ">=1.11.0"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"@promakeai/orm": "1.0
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@tanstack/query-core": "5.90.20",
|
|
49
|
-
"@tanstack/react-query": "^5.66.0",
|
|
50
|
-
"@types/react": "^19.0.0",
|
|
51
|
-
"react": "^19.0.0",
|
|
52
|
-
"react-dom": "^19.0.0",
|
|
53
|
-
"sql.js": "^1.12.0",
|
|
54
|
-
"typescript": "^5.7.3"
|
|
55
|
-
},
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"access": "public"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@promakeai/dbreact",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "React client for schema-driven multi-language database",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build:js": "tsc --project tsconfig.json --declaration false --declarationMap false --emitDeclarationOnly false --outDir dist",
|
|
18
|
+
"build": "bun run build:js && bun run build:types",
|
|
19
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
20
|
+
"dev": "bun build index.ts --outdir dist --target browser --packages=external --watch",
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"test:build-runtime": "bun run build && bun test ./tests/build-runtime.test.ts",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"release": "bun run build && npm publish --access public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"react",
|
|
31
|
+
"database",
|
|
32
|
+
"sqlite",
|
|
33
|
+
"multi-language",
|
|
34
|
+
"tanstack-query"
|
|
35
|
+
],
|
|
36
|
+
"author": "Promake Inc.",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": ">=19.0.0",
|
|
40
|
+
"react-dom": ">=19.0.0",
|
|
41
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
42
|
+
"sql.js": ">=1.11.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@promakeai/orm": "1.2.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@tanstack/query-core": "5.90.20",
|
|
49
|
+
"@tanstack/react-query": "^5.66.0",
|
|
50
|
+
"@types/react": "^19.0.0",
|
|
51
|
+
"react": "^19.0.0",
|
|
52
|
+
"react-dom": "^19.0.0",
|
|
53
|
+
"sql.js": "^1.12.0",
|
|
54
|
+
"typescript": "^5.7.3"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|