@promakeai/dbreact 1.0.7 → 1.0.8
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 +143 -145
- package/dist/adapters/SqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/SqliteAdapter.js +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +59 -59
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@ 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
|
-
- **React Query Integration** - Built-in caching, loading states, optimistic updates
|
|
11
|
-
- **Zero-Config Language Switching** - Change language, queries refetch automatically
|
|
12
|
-
- **MongoDB-Style Queries** - Intuitive filter syntax (`$gt`, `$in`, `$like`, `$contains`, etc.)
|
|
10
|
+
- **React Query Integration** - Built-in caching, loading states, optimistic updates
|
|
11
|
+
- **Zero-Config Language Switching** - Change language, queries refetch automatically
|
|
12
|
+
- **MongoDB-Style Queries** - Intuitive filter syntax (`$gt`, `$in`, `$like`, `$contains`, etc.)
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -26,16 +26,16 @@ npm install @promakeai/dbreact @tanstack/react-query
|
|
|
26
26
|
### 1. Setup Adapter
|
|
27
27
|
|
|
28
28
|
```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
|
-
});
|
|
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
|
+
});
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
### 2. Wrap App with Provider
|
|
@@ -103,27 +103,27 @@ Main provider component that wraps your application.
|
|
|
103
103
|
|
|
104
104
|
```tsx
|
|
105
105
|
<DbProvider
|
|
106
|
-
adapter={adapter}
|
|
107
|
-
schema={schema}
|
|
108
|
-
lang="tr"
|
|
109
|
-
fallbackLang="en"
|
|
110
|
-
autoConnect={true}
|
|
111
|
-
>
|
|
106
|
+
adapter={adapter}
|
|
107
|
+
schema={schema}
|
|
108
|
+
lang="tr"
|
|
109
|
+
fallbackLang="en"
|
|
110
|
+
autoConnect={true}
|
|
111
|
+
>
|
|
112
112
|
<App />
|
|
113
113
|
</DbProvider>
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
**Props:**
|
|
117
117
|
|
|
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 |
|
|
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 |
|
|
127
127
|
|
|
128
128
|
---
|
|
129
129
|
|
|
@@ -151,29 +151,29 @@ const { data, isLoading, error, refetch } = useDbList<Product>('products', {
|
|
|
151
151
|
| `orderBy` | `array` | Sort order `[{ field, direction }]` |
|
|
152
152
|
| `limit` | `number` | Max records to return |
|
|
153
153
|
| `offset` | `number` | Skip records |
|
|
154
|
-
| `populate` | `PopulateOption` | Resolve foreign key references (string, array, or object) |
|
|
154
|
+
| `populate` | `PopulateOption` | Resolve foreign key references (string, array, or object) |
|
|
155
155
|
| `enabled` | `boolean` | Enable/disable query |
|
|
156
156
|
|
|
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
|
-
```
|
|
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
|
+
```
|
|
177
177
|
|
|
178
178
|
---
|
|
179
179
|
|
|
@@ -200,13 +200,13 @@ createProduct.mutate(
|
|
|
200
200
|
Update an existing record.
|
|
201
201
|
|
|
202
202
|
```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
|
-
}
|
|
203
|
+
const updateProduct = useDbUpdate<Product>('products');
|
|
204
|
+
|
|
205
|
+
updateProduct.mutate(
|
|
206
|
+
{ id: productId, data: { price: 89.99 } },
|
|
207
|
+
{
|
|
208
|
+
onSuccess: () => console.log('Updated'),
|
|
209
|
+
}
|
|
210
210
|
);
|
|
211
211
|
```
|
|
212
212
|
|
|
@@ -215,11 +215,11 @@ updateProduct.mutate(
|
|
|
215
215
|
Delete a record.
|
|
216
216
|
|
|
217
217
|
```tsx
|
|
218
|
-
const deleteProduct = useDbDelete('products');
|
|
219
|
-
|
|
220
|
-
deleteProduct.mutate(productId, {
|
|
221
|
-
onSuccess: () => console.log('Deleted'),
|
|
222
|
-
});
|
|
218
|
+
const deleteProduct = useDbDelete('products');
|
|
219
|
+
|
|
220
|
+
deleteProduct.mutate(productId, {
|
|
221
|
+
onSuccess: () => console.log('Deleted'),
|
|
222
|
+
});
|
|
223
223
|
```
|
|
224
224
|
|
|
225
225
|
---
|
|
@@ -312,16 +312,16 @@ const adapter = new SqliteAdapter({
|
|
|
312
312
|
{ name: { $like: '%shirt%' } } // LIKE '%shirt%'
|
|
313
313
|
{ name: { $notLike: '%test%' } } // NOT LIKE '%test%'
|
|
314
314
|
|
|
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"] } }
|
|
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"] } }
|
|
325
325
|
|
|
326
326
|
// Logical
|
|
327
327
|
{ $and: [
|
|
@@ -340,18 +340,18 @@ const adapter = new SqliteAdapter({
|
|
|
340
340
|
### Query Interface
|
|
341
341
|
|
|
342
342
|
```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
|
-
}
|
|
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
|
+
}
|
|
355
355
|
```
|
|
356
356
|
|
|
357
357
|
---
|
|
@@ -360,20 +360,18 @@ interface QueryOptions {
|
|
|
360
360
|
|
|
361
361
|
### Schema with Translatable Fields
|
|
362
362
|
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
},
|
|
376
|
-
});
|
|
363
|
+
```json
|
|
364
|
+
{
|
|
365
|
+
"languages": ["en", "tr", "de"],
|
|
366
|
+
"tables": {
|
|
367
|
+
"products": {
|
|
368
|
+
"id": { "type": "id" },
|
|
369
|
+
"price": { "type": "decimal" },
|
|
370
|
+
"name": { "type": "string", "translatable": true },
|
|
371
|
+
"description": { "type": "text", "translatable": true }
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
377
375
|
```
|
|
378
376
|
|
|
379
377
|
### Automatic Translation
|
|
@@ -409,32 +407,32 @@ function LanguageSwitcher() {
|
|
|
409
407
|
|
|
410
408
|
---
|
|
411
409
|
|
|
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
|
-
```
|
|
410
|
+
## Generated Types + Generic Hooks
|
|
411
|
+
|
|
412
|
+
Generate runtime schema and TypeScript interfaces:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
dbcli generate --schema ./schema.json --output ./src/db
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
`dbcli generate` writes `schema.json` and `types.ts`. React hooks are imported from `@promakeai/dbreact`:
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
import { useDbList, useDbGet, useDbCreate } from '@promakeai/dbreact';
|
|
422
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
423
|
+
|
|
424
|
+
function ProductManager() {
|
|
425
|
+
const { data: products } = useDbList<DbProduct>('products', {
|
|
426
|
+
where: { stock: { $gt: 0 } },
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
const { data: product } = useDbGet<DbProduct>('products', 1);
|
|
430
|
+
|
|
431
|
+
const createProduct = useDbCreate<DbProduct, DbProductInput>('products');
|
|
432
|
+
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
```
|
|
438
436
|
|
|
439
437
|
---
|
|
440
438
|
|
|
@@ -443,10 +441,10 @@ function ProductManager() {
|
|
|
443
441
|
### Custom React Query Options
|
|
444
442
|
|
|
445
443
|
```tsx
|
|
446
|
-
const { data } = useDbList('products', {
|
|
447
|
-
where: { active: true },
|
|
448
|
-
limit: 50,
|
|
449
|
-
});
|
|
444
|
+
const { data } = useDbList('products', {
|
|
445
|
+
where: { active: true },
|
|
446
|
+
limit: 50,
|
|
447
|
+
});
|
|
450
448
|
```
|
|
451
449
|
|
|
452
450
|
### Direct Adapter Access
|
|
@@ -480,7 +478,7 @@ function AdvancedSearch() {
|
|
|
480
478
|
```tsx
|
|
481
479
|
function ProductPrice({ product }) {
|
|
482
480
|
const queryClient = useQueryClient();
|
|
483
|
-
const updateProduct = useDbUpdate('products');
|
|
481
|
+
const updateProduct = useDbUpdate('products');
|
|
484
482
|
|
|
485
483
|
const handlePriceChange = async (newPrice: number) => {
|
|
486
484
|
// Optimistic update
|
|
@@ -489,10 +487,10 @@ function ProductPrice({ product }) {
|
|
|
489
487
|
{ ...product, price: newPrice }
|
|
490
488
|
);
|
|
491
489
|
|
|
492
|
-
await updateProduct.mutateAsync({
|
|
493
|
-
id: product.id,
|
|
494
|
-
data: { price: newPrice },
|
|
495
|
-
});
|
|
490
|
+
await updateProduct.mutateAsync({
|
|
491
|
+
id: product.id,
|
|
492
|
+
data: { price: newPrice },
|
|
493
|
+
});
|
|
496
494
|
};
|
|
497
495
|
|
|
498
496
|
return <PriceInput value={product.price} onChange={handlePriceChange} />;
|
|
@@ -584,13 +582,13 @@ function ProductSearch() {
|
|
|
584
582
|
Full TypeScript support with generated types:
|
|
585
583
|
|
|
586
584
|
```typescript
|
|
587
|
-
import type { DbProduct, DbProductInput } from './db/types';
|
|
585
|
+
import type { DbProduct, DbProductInput } from './db/types';
|
|
588
586
|
|
|
589
587
|
// Type-safe queries
|
|
590
|
-
const products: DbProduct[] = await adapter.list('products');
|
|
588
|
+
const products: DbProduct[] = await adapter.list('products');
|
|
591
589
|
|
|
592
590
|
// Type-safe creates
|
|
593
|
-
const newProduct: DbProductInput = {
|
|
591
|
+
const newProduct: DbProductInput = {
|
|
594
592
|
sku: 'SHIRT-001',
|
|
595
593
|
price: 99.99,
|
|
596
594
|
};
|
|
@@ -622,14 +620,14 @@ await adapter.create('products', newProduct);
|
|
|
622
620
|
|
|
623
621
|
---
|
|
624
622
|
|
|
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
|
|
623
|
+
## Troubleshooting
|
|
624
|
+
|
|
625
|
+
**Production crash: `jsxDEV is not a function`**
|
|
626
|
+
- Run `bun run test:build-runtime` before publishing.
|
|
627
|
+
- This verifies `dist/index.js` does not include `react/jsx-dev-runtime`.
|
|
628
|
+
|
|
629
|
+
**"useDbLang must be used within a DbProvider"**
|
|
630
|
+
- Ensure component is wrapped in DbProvider
|
|
633
631
|
|
|
634
632
|
**Queries return empty results**
|
|
635
633
|
- Check adapter is connected: `const { isConnected } = useDb()`
|
|
@@ -645,7 +643,7 @@ await adapter.create('products', newProduct);
|
|
|
645
643
|
|
|
646
644
|
## Related Packages
|
|
647
645
|
|
|
648
|
-
- [@promakeai/orm](../orm) - Core ORM with
|
|
646
|
+
- [@promakeai/orm](../orm) - Core ORM with query builder
|
|
649
647
|
- [@promakeai/dbcli](../dbcli) - CLI tool for database operations
|
|
650
648
|
|
|
651
649
|
## 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,Q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E,CAAC;YAwC3C,8BAA8B;YAW9B,eAAe;IAUvB,UAAU,CACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,IAAI,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,7 +4,7 @@
|
|
|
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";
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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
|
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.6"
|
|
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.0.8",
|
|
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.6"
|
|
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
|
+
}
|