@mgarlik/datastore 0.1.0 → 0.1.2
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 +28 -1
- package/dist/chunk-7XDRKNJQ.js +14 -0
- package/dist/chunk-7XDRKNJQ.js.map +1 -0
- package/dist/expo-sqlite.cjs +210 -0
- package/dist/expo-sqlite.cjs.map +1 -0
- package/dist/expo-sqlite.d.cts +31 -0
- package/dist/expo-sqlite.d.ts +31 -0
- package/dist/expo-sqlite.js +166 -0
- package/dist/expo-sqlite.js.map +1 -0
- package/dist/index.cjs +990 -1097
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -75
- package/dist/index.d.ts +117 -75
- package/dist/index.js +1005 -1101
- package/dist/index.js.map +1 -1
- package/dist/storage-D_xv8gFb.d.cts +18 -0
- package/dist/storage-D_xv8gFb.d.ts +18 -0
- package/package.json +16 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import React, { ReactNode } from 'react';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
declare class SQLite$1 {
|
|
6
|
-
dbName: string;
|
|
7
|
-
private db;
|
|
8
|
-
constructor(name?: string);
|
|
9
|
-
private initDB;
|
|
10
|
-
private getDb;
|
|
11
|
-
private createTable;
|
|
12
|
-
private createTables;
|
|
13
|
-
/**
|
|
14
|
-
* Smazani starych logu
|
|
15
|
-
*/
|
|
16
|
-
private deleteLogs;
|
|
17
|
-
read<T>(query: string, args?: SQL.SQLiteBindParams): Promise<T[]>;
|
|
18
|
-
query<T>(query: string, args?: SQL.SQLiteBindParams): Promise<T[]>;
|
|
19
|
-
dropTable(table: string): Promise<SQL.SQLiteRunResult>;
|
|
20
|
-
emptyTable(table: string): Promise<SQL.SQLiteRunResult>;
|
|
21
|
-
getTables(): Promise<unknown[]>;
|
|
22
|
-
resetDatabase(): Promise<void>;
|
|
23
|
-
}
|
|
2
|
+
import { D as DataStoreStorage } from './storage-D_xv8gFb.cjs';
|
|
24
3
|
|
|
4
|
+
/**
|
|
5
|
+
* String identifikátor providera (např. "brands" nebo "categories").
|
|
6
|
+
*/
|
|
25
7
|
type ProviderTypes = string;
|
|
8
|
+
/**
|
|
9
|
+
* Definice zdroje popisující, odkud se mají data providera načítat.
|
|
10
|
+
*/
|
|
26
11
|
type ProviderDataSource = {
|
|
27
12
|
uri?: string;
|
|
28
13
|
crud?: {
|
|
@@ -43,6 +28,9 @@ type ProviderDataSource = {
|
|
|
43
28
|
select?: any;
|
|
44
29
|
file?: string;
|
|
45
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Definice providera používaná při runtime registraci v DataStoreProvideru.
|
|
33
|
+
*/
|
|
46
34
|
type DataProvider = {
|
|
47
35
|
id: ProviderTypes;
|
|
48
36
|
dataSource?: ProviderDataSource;
|
|
@@ -54,21 +42,30 @@ type DataProvider = {
|
|
|
54
42
|
editor?: Record<string, any>;
|
|
55
43
|
actions?: string[];
|
|
56
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Kolekce definic providerů indexovaná podle provider id.
|
|
47
|
+
*/
|
|
57
48
|
type DataProviders = Record<string, DataProvider>;
|
|
58
49
|
|
|
50
|
+
/** Kanonický UUID řetězec používaný pro dokumenty a providery. */
|
|
59
51
|
type Uuid = string;
|
|
52
|
+
/** JSON-kompatibilní hodnota používaná v payloadu, filtrech a update operacích. */
|
|
60
53
|
type JSONType = string | number | boolean | {
|
|
61
54
|
[x: string]: JSONType;
|
|
62
55
|
} | Array<JSONType>;
|
|
56
|
+
/** Konfigurace Socket.IO serveru používaná DataStoreProviderem. */
|
|
63
57
|
type SocketServerType = {
|
|
64
58
|
url: string;
|
|
65
59
|
params: Record<string, any>;
|
|
66
60
|
};
|
|
61
|
+
/** In-memory metadata aktivní socket místnosti. */
|
|
67
62
|
type SocketItem = {
|
|
68
63
|
listeners: number;
|
|
69
64
|
data: any[];
|
|
70
65
|
};
|
|
66
|
+
/** Podporované akce zpracovávané interní frontou dispatcheru. */
|
|
71
67
|
type DispatcherActionType = "registerProvider" | "unregisterProvider" | "updateDataStore" | "createDocument" | "updateDocument" | "updateDocuments" | "removeItem" | "deleteDocument" | "createProviderItem" | "deleteProviderItem";
|
|
68
|
+
/** Interní struktura async fronty pro serializované datastore akce. */
|
|
72
69
|
type DispatcherType = {
|
|
73
70
|
isBussy: Boolean;
|
|
74
71
|
actions: {
|
|
@@ -148,14 +145,22 @@ type ProductFiltersType = {
|
|
|
148
145
|
};
|
|
149
146
|
};
|
|
150
147
|
interface DataStoreProps {
|
|
148
|
+
/** Předdefinovaní provideři dostupní pro registraci a hooky. */
|
|
151
149
|
providers: DataProviders;
|
|
152
150
|
/** Adresa REST/CRUD serveru */
|
|
153
151
|
restServer: string;
|
|
152
|
+
/** Socket.IO server používaný pro live aktualizace. */
|
|
154
153
|
socketServer: SocketServerType;
|
|
154
|
+
/** Volitelná lokalizace pro hlavičku Accept-Language. Pokud chybí, použije se runtime locale. */
|
|
155
|
+
locale?: string;
|
|
156
|
+
/** Volitelný persistence adapter. Pokud není předán, balíček běží bez lokální persistence. */
|
|
157
|
+
storage?: DataStoreStorage | null;
|
|
155
158
|
/** false - provider nebude cist/ukladat data do persistentniho uloziste */
|
|
156
159
|
usePersistentStorage?: boolean;
|
|
160
|
+
/** React subtree obalená DataStoreProviderem. */
|
|
157
161
|
children: ReactNode;
|
|
158
162
|
}
|
|
163
|
+
/** Veřejné runtime API vystavené přes useDataStore a související hooky. */
|
|
159
164
|
interface DataStore {
|
|
160
165
|
providers: Record<string, any>;
|
|
161
166
|
documents: Record<string, any>;
|
|
@@ -184,7 +189,6 @@ interface DataStore {
|
|
|
184
189
|
unregisterProviderSockets: (sockets: string | string[]) => void;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
declare const SQLite: SQLite$1;
|
|
188
192
|
type DataStoreMetaType = Pick<DataStore, "isLive" | "isSynchronizing" | "sockets" | "counterProviders" | "counterDocuments">;
|
|
189
193
|
type DataStoreActionsType = Pick<DataStore, "dispatch" | "initProvider" | "resetProvider" | "registerProvider" | "unregisterProvider" | "updateProviderListeners" | "resetDataStore" | "startSockets" | "stopSockets" | "registerProviderSockets" | "unregisterProviderSockets" | "updateDocuments" | "presetProviders">;
|
|
190
194
|
type DataStoreStableType = {
|
|
@@ -196,17 +200,17 @@ type DataStoreStableType = {
|
|
|
196
200
|
getExternalDocuments: () => Record<string, any>;
|
|
197
201
|
getExternalProviders: () => Record<string, any>;
|
|
198
202
|
};
|
|
199
|
-
/** Meta (isLive, isSynchronizing, sockets,
|
|
203
|
+
/** Meta informace (isLive, isSynchronizing, sockets, čítače). */
|
|
200
204
|
declare const DataStoreContext: React.Context<DataStoreMetaType>;
|
|
201
|
-
/**
|
|
205
|
+
/** Surová mapa dokumentů */
|
|
202
206
|
declare const DataStoreDocumentsContext: React.Context<Record<string, any>>;
|
|
203
|
-
/**
|
|
207
|
+
/** Surová mapa providerů */
|
|
204
208
|
declare const DataStoreProvidersContext: React.Context<Record<string, any>>;
|
|
205
|
-
/**
|
|
209
|
+
/** Stabilní action callbacky */
|
|
206
210
|
declare const DataStoreActionsContext: React.Context<DataStoreActionsType>;
|
|
207
|
-
/**
|
|
211
|
+
/** Stabilní datastore API pro provider-scoped subscriptions */
|
|
208
212
|
declare const DataStoreStableContext: React.Context<DataStoreStableType>;
|
|
209
|
-
/**
|
|
213
|
+
/** Vrací všechny stabilní action callbacky. Komponenty s tímto hookem se nepřerenderují při změnách dokumentů. */
|
|
210
214
|
declare const useDataStoreActions: () => DataStoreActionsType;
|
|
211
215
|
/**
|
|
212
216
|
*
|
|
@@ -214,6 +218,9 @@ declare const useDataStoreActions: () => DataStoreActionsType;
|
|
|
214
218
|
* @param resultType - "object"(default) | "array"
|
|
215
219
|
* @returns {documents, filter}
|
|
216
220
|
*/
|
|
221
|
+
/**
|
|
222
|
+
* Vyfiltruje všechny datastore dokumenty podle matcher objektu a vrátí reaktivní výsledek.
|
|
223
|
+
*/
|
|
217
224
|
declare const useFilteredDocuments: (filter: Record<string, any>) => {
|
|
218
225
|
documents: any[] | Record<string, any>;
|
|
219
226
|
setFilter: React.Dispatch<React.SetStateAction<Record<string, any>>>;
|
|
@@ -230,7 +237,6 @@ declare const useDocuments: () => {
|
|
|
230
237
|
* Vrati object of documents daneho providera. Dokumenty lze vyfiltrovat
|
|
231
238
|
*
|
|
232
239
|
* @param {*} provider
|
|
233
|
-
* @param {*} filter
|
|
234
240
|
* @returns
|
|
235
241
|
*/
|
|
236
242
|
declare const useProviderDocuments: (provider: ProviderTypes, settings?: {
|
|
@@ -240,18 +246,72 @@ declare const useProviderDocuments: (provider: ProviderTypes, settings?: {
|
|
|
240
246
|
}) => {
|
|
241
247
|
[key: string]: any;
|
|
242
248
|
};
|
|
249
|
+
/** Vrací surový stav providera podle provider id. */
|
|
243
250
|
declare const useProvider: (val: ProviderTypes) => any;
|
|
244
|
-
/**
|
|
251
|
+
/** Kompletní DataStore - spojuje všechny sub-contexty. Komponenty s tímto hookem se přerenderují při jakékoliv změně stavu. */
|
|
245
252
|
declare const useDataStore: () => DataStore;
|
|
246
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Imperativní API `DataStoreProvider` vystavené přes `ref`.
|
|
255
|
+
*
|
|
256
|
+
* Umožňuje volat akce DataStore přímo z rodiče (např. `App.tsx`)
|
|
257
|
+
* bez nutnosti použití `useDataStoreActions` hooku uvnitř stromové hierarchie.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```tsx
|
|
261
|
+
* const dsRef = useRef<DataStoreRef>(null);
|
|
262
|
+
*
|
|
263
|
+
* <DataStoreProvider ref={dsRef} ...>
|
|
264
|
+
* <AppProvider
|
|
265
|
+
* onLogin={({ userId }) => {
|
|
266
|
+
* dsRef.current?.startSockets();
|
|
267
|
+
* dsRef.current?.registerProviderSockets(userId);
|
|
268
|
+
* }}
|
|
269
|
+
* onLogout={({ userId }) => {
|
|
270
|
+
* dsRef.current?.unregisterProviderSockets(userId);
|
|
271
|
+
* dsRef.current?.stopSockets();
|
|
272
|
+
* }}
|
|
273
|
+
* />
|
|
274
|
+
* </DataStoreProvider>
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
type DataStoreRef = DataStoreActionsType;
|
|
278
|
+
/**
|
|
279
|
+
* Kořenový provider, který propojuje DataStore contexty, REST načítání, sockety a volitelnou persistenci.
|
|
280
|
+
*
|
|
281
|
+
* Podporuje volitelný `ref` (`DataStoreRef`) pro imperativní přístup k akcím
|
|
282
|
+
* přímo z rodičovské komponenty bez použití kontextového hooku.
|
|
283
|
+
*/
|
|
284
|
+
declare const DataStoreProvider: React.ForwardRefExoticComponent<DataStoreProps & React.RefAttributes<DataStoreActionsType>>;
|
|
247
285
|
|
|
286
|
+
interface UseDataProviderResult {
|
|
287
|
+
/** Materializované dokumenty providera po vyhodnocení šablon a filtraci. */
|
|
288
|
+
documents: Array<Record<string, any>>;
|
|
289
|
+
/** Schéma providera, pokud je dostupné. */
|
|
290
|
+
schema?: Record<string, any>;
|
|
291
|
+
/** Aktualizuje data providera pomocí výchozí update varianty. */
|
|
292
|
+
update: (val: JSONType) => void;
|
|
293
|
+
/** Aktualizuje položku/položky providera s volitelnou variantou a route parametry. */
|
|
294
|
+
updateItem: (args: {
|
|
295
|
+
params?: JSONType;
|
|
296
|
+
data?: JSONType;
|
|
297
|
+
variant?: string;
|
|
298
|
+
documentId?: string;
|
|
299
|
+
}, callback?: (resp: JSONType) => void) => void;
|
|
300
|
+
/** Smaže položku/položky providera. */
|
|
301
|
+
deleteItem: (args: {
|
|
302
|
+
params?: JSONType;
|
|
303
|
+
data?: JSONType;
|
|
304
|
+
}, callback?: (resp: JSONType) => void) => void;
|
|
305
|
+
/** Vytvoří novou položku providera. */
|
|
306
|
+
createItem: (data: JSONType, callback?: () => void) => void;
|
|
307
|
+
}
|
|
248
308
|
/**
|
|
309
|
+
* Zaregistruje/zpřístupní providera a vrátí normalizované dokumenty spolu s CRUD helpery.
|
|
249
310
|
*
|
|
250
|
-
* @param id
|
|
251
|
-
* @param params
|
|
252
|
-
* @param dataFilter
|
|
253
|
-
* @param settings
|
|
254
|
-
* @returns void
|
|
311
|
+
* @param id Provider id nebo inline definice providera.
|
|
312
|
+
* @param params Parametry šablony používané při renderu URI/definice.
|
|
313
|
+
* @param dataFilter Volitelný client-side filtr dokumentů providera.
|
|
314
|
+
* @param settings Volitelný závislý dokument použitý pro přepočet dat.
|
|
255
315
|
*/
|
|
256
316
|
declare const useDataProvider: (
|
|
257
317
|
/**
|
|
@@ -276,26 +336,9 @@ dataFilter?: JSONType | null,
|
|
|
276
336
|
settings?: {
|
|
277
337
|
documentId?: string;
|
|
278
338
|
document?: JSONType;
|
|
279
|
-
}) =>
|
|
280
|
-
documents: any;
|
|
281
|
-
schema: any;
|
|
282
|
-
update: (val: JSONType) => void;
|
|
283
|
-
updateItem: ({ params, data, variant, documentId }: {
|
|
284
|
-
params?: JSONType;
|
|
285
|
-
data?: JSONType;
|
|
286
|
-
variant?: string;
|
|
287
|
-
documentId?: string;
|
|
288
|
-
}, callback?: (resp: JSONType) => void) => void;
|
|
289
|
-
deleteItem: ({ params, data }: {
|
|
290
|
-
params?: JSONType;
|
|
291
|
-
data?: JSONType;
|
|
292
|
-
}, callback?: (resp: JSONType) => void) => void;
|
|
293
|
-
createItem: (data: JSONType, callback?: () => void) => void;
|
|
294
|
-
};
|
|
339
|
+
}) => UseDataProviderResult;
|
|
295
340
|
|
|
296
|
-
/**
|
|
297
|
-
* blabla
|
|
298
|
-
*/
|
|
341
|
+
/** Vstupní parametry hooku useDocument. */
|
|
299
342
|
interface UseDocumentParams {
|
|
300
343
|
/**
|
|
301
344
|
* UUID dokumentu
|
|
@@ -316,41 +359,40 @@ interface UseDocumentParams {
|
|
|
316
359
|
allFields?: boolean;
|
|
317
360
|
}
|
|
318
361
|
interface UseDocumentResult {
|
|
319
|
-
/**
|
|
320
|
-
* Vraci neco
|
|
321
|
-
*/
|
|
362
|
+
/** Materializovaný payload dokumentu z DataStore. */
|
|
322
363
|
document: Record<string, any>;
|
|
323
364
|
}
|
|
324
365
|
/**
|
|
325
|
-
*
|
|
366
|
+
* Vrátí jeden dokument a volitelně spustí lazy načtení chybějících polí.
|
|
326
367
|
*
|
|
327
|
-
* Example: useDocument({documentId: "
|
|
328
|
-
*
|
|
329
|
-
* @param documentId - ID dokumentu
|
|
330
|
-
* @param model - nazev modelu
|
|
331
|
-
* @param provider - nazev providera
|
|
332
|
-
* @param fields - seznam polozek dokumentu ktere chceme ziskat
|
|
333
|
-
* @param allFields - kompletni dokument
|
|
334
|
-
*
|
|
335
|
-
* @returns - vraci dokument
|
|
368
|
+
* Example: useDocument({ documentId: "...", model: "products", fields: ["name", "image"] })
|
|
336
369
|
*/
|
|
337
370
|
declare const useDocument: ({ documentId, model, provider, fields, allFields }: UseDocumentParams) => UseDocumentResult;
|
|
338
371
|
|
|
339
|
-
|
|
340
|
-
|
|
372
|
+
interface UseProviderActionsResult {
|
|
373
|
+
/** Schéma providera, pokud je dostupné. */
|
|
374
|
+
schema?: Record<string, any>;
|
|
375
|
+
/** Aktualizuje data providera pomocí výchozí update varianty. */
|
|
341
376
|
update: (val: JSONType) => void;
|
|
342
|
-
|
|
377
|
+
/** Aktualizuje položku/položky providera s volitelnou route variantou a parametry. */
|
|
378
|
+
updateItem: (args: {
|
|
343
379
|
params?: JSONType;
|
|
344
380
|
data?: any;
|
|
345
381
|
variant?: string;
|
|
346
382
|
documentId?: Uuid;
|
|
347
383
|
}, callback?: (value: JSONType) => void) => void;
|
|
348
|
-
|
|
384
|
+
/** Smaže položku/položky providera. */
|
|
385
|
+
deleteItem: (args: {
|
|
349
386
|
params: JSONType;
|
|
350
387
|
data?: JSONType;
|
|
351
388
|
}, callback?: () => void) => void;
|
|
389
|
+
/** Vytvoří novou položku providera. */
|
|
352
390
|
createItem: (data: JSONType, callback?: (value: JSONType) => void) => void;
|
|
353
|
-
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Vrací action helpery pro známé provider id.
|
|
394
|
+
*/
|
|
395
|
+
declare const useProviderActions: (providerId: Uuid, data?: JSONType) => UseProviderActionsResult;
|
|
354
396
|
|
|
355
397
|
declare function recalculateObjectWithDocument(obj: any, document: any): any;
|
|
356
398
|
declare function getValueByRules(data: any, document: any, { mode, ruleId }: {
|
|
@@ -410,4 +452,4 @@ declare const COLOR_AXIOS = "\u001B[33m%s\u001B[0m";
|
|
|
410
452
|
declare const COLOR_APP = "\u001B[34m%s\u001B[0m";
|
|
411
453
|
declare const COLOR_DS = "\u001B[35m%s\u001B[0m";
|
|
412
454
|
|
|
413
|
-
export { COLOR_APP, COLOR_AXIOS, COLOR_BLUE, COLOR_CONTEXT, COLOR_CYAN, COLOR_DS, COLOR_ERROR, COLOR_FUNCTION, COLOR_GREEN, COLOR_MAGENTA, COLOR_ORANGE, COLOR_PROVIDER, COLOR_RED, COLOR_RENDER, COLOR_SCREEN, COLOR_SOCKET, COLOR_SOCKETS, COLOR_WARNING, COLOR_WHITE, COLOR_YELLOW, type DataProvider, type DataProviders, type DataStore, DataStoreActionsContext, DataStoreContext, DataStoreDocumentsContext, type DataStoreProps, DataStoreProvider, DataStoreProvidersContext, DataStoreStableContext, type DispatcherActionType, type DispatcherType, type FilterType, type JSONType, type ProductFiltersType, type ProviderDataSource, type ProviderTypes,
|
|
455
|
+
export { COLOR_APP, COLOR_AXIOS, COLOR_BLUE, COLOR_CONTEXT, COLOR_CYAN, COLOR_DS, COLOR_ERROR, COLOR_FUNCTION, COLOR_GREEN, COLOR_MAGENTA, COLOR_ORANGE, COLOR_PROVIDER, COLOR_RED, COLOR_RENDER, COLOR_SCREEN, COLOR_SOCKET, COLOR_SOCKETS, COLOR_WARNING, COLOR_WHITE, COLOR_YELLOW, type DataProvider, type DataProviders, type DataStore, DataStoreActionsContext, DataStoreContext, DataStoreDocumentsContext, type DataStoreProps, DataStoreProvider, DataStoreProvidersContext, type DataStoreRef, DataStoreStableContext, DataStoreStorage, type DispatcherActionType, type DispatcherType, type FilterType, type JSONType, type ProductFiltersType, type ProviderDataSource, type ProviderTypes, type SchemaType, type SocketItem, type SocketServerType, type UseDataProviderResult, type UseProviderActionsResult, type Uuid, dataStoreFilterObject, doesObjectMatchFilter, doesValueMatchFilter, filterDocuments, filterDocumentsAsync, type filterItemType, getValueByRules, isUuid, recalculateObjectWithDocument, useDataProvider, useDataStore, useDataStoreActions, useDocument, useDocuments, useFilteredDocuments, useProvider, useProviderActions, useProviderDocuments, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import React, { ReactNode } from 'react';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
declare class SQLite$1 {
|
|
6
|
-
dbName: string;
|
|
7
|
-
private db;
|
|
8
|
-
constructor(name?: string);
|
|
9
|
-
private initDB;
|
|
10
|
-
private getDb;
|
|
11
|
-
private createTable;
|
|
12
|
-
private createTables;
|
|
13
|
-
/**
|
|
14
|
-
* Smazani starych logu
|
|
15
|
-
*/
|
|
16
|
-
private deleteLogs;
|
|
17
|
-
read<T>(query: string, args?: SQL.SQLiteBindParams): Promise<T[]>;
|
|
18
|
-
query<T>(query: string, args?: SQL.SQLiteBindParams): Promise<T[]>;
|
|
19
|
-
dropTable(table: string): Promise<SQL.SQLiteRunResult>;
|
|
20
|
-
emptyTable(table: string): Promise<SQL.SQLiteRunResult>;
|
|
21
|
-
getTables(): Promise<unknown[]>;
|
|
22
|
-
resetDatabase(): Promise<void>;
|
|
23
|
-
}
|
|
2
|
+
import { D as DataStoreStorage } from './storage-D_xv8gFb.js';
|
|
24
3
|
|
|
4
|
+
/**
|
|
5
|
+
* String identifikátor providera (např. "brands" nebo "categories").
|
|
6
|
+
*/
|
|
25
7
|
type ProviderTypes = string;
|
|
8
|
+
/**
|
|
9
|
+
* Definice zdroje popisující, odkud se mají data providera načítat.
|
|
10
|
+
*/
|
|
26
11
|
type ProviderDataSource = {
|
|
27
12
|
uri?: string;
|
|
28
13
|
crud?: {
|
|
@@ -43,6 +28,9 @@ type ProviderDataSource = {
|
|
|
43
28
|
select?: any;
|
|
44
29
|
file?: string;
|
|
45
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Definice providera používaná při runtime registraci v DataStoreProvideru.
|
|
33
|
+
*/
|
|
46
34
|
type DataProvider = {
|
|
47
35
|
id: ProviderTypes;
|
|
48
36
|
dataSource?: ProviderDataSource;
|
|
@@ -54,21 +42,30 @@ type DataProvider = {
|
|
|
54
42
|
editor?: Record<string, any>;
|
|
55
43
|
actions?: string[];
|
|
56
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Kolekce definic providerů indexovaná podle provider id.
|
|
47
|
+
*/
|
|
57
48
|
type DataProviders = Record<string, DataProvider>;
|
|
58
49
|
|
|
50
|
+
/** Kanonický UUID řetězec používaný pro dokumenty a providery. */
|
|
59
51
|
type Uuid = string;
|
|
52
|
+
/** JSON-kompatibilní hodnota používaná v payloadu, filtrech a update operacích. */
|
|
60
53
|
type JSONType = string | number | boolean | {
|
|
61
54
|
[x: string]: JSONType;
|
|
62
55
|
} | Array<JSONType>;
|
|
56
|
+
/** Konfigurace Socket.IO serveru používaná DataStoreProviderem. */
|
|
63
57
|
type SocketServerType = {
|
|
64
58
|
url: string;
|
|
65
59
|
params: Record<string, any>;
|
|
66
60
|
};
|
|
61
|
+
/** In-memory metadata aktivní socket místnosti. */
|
|
67
62
|
type SocketItem = {
|
|
68
63
|
listeners: number;
|
|
69
64
|
data: any[];
|
|
70
65
|
};
|
|
66
|
+
/** Podporované akce zpracovávané interní frontou dispatcheru. */
|
|
71
67
|
type DispatcherActionType = "registerProvider" | "unregisterProvider" | "updateDataStore" | "createDocument" | "updateDocument" | "updateDocuments" | "removeItem" | "deleteDocument" | "createProviderItem" | "deleteProviderItem";
|
|
68
|
+
/** Interní struktura async fronty pro serializované datastore akce. */
|
|
72
69
|
type DispatcherType = {
|
|
73
70
|
isBussy: Boolean;
|
|
74
71
|
actions: {
|
|
@@ -148,14 +145,22 @@ type ProductFiltersType = {
|
|
|
148
145
|
};
|
|
149
146
|
};
|
|
150
147
|
interface DataStoreProps {
|
|
148
|
+
/** Předdefinovaní provideři dostupní pro registraci a hooky. */
|
|
151
149
|
providers: DataProviders;
|
|
152
150
|
/** Adresa REST/CRUD serveru */
|
|
153
151
|
restServer: string;
|
|
152
|
+
/** Socket.IO server používaný pro live aktualizace. */
|
|
154
153
|
socketServer: SocketServerType;
|
|
154
|
+
/** Volitelná lokalizace pro hlavičku Accept-Language. Pokud chybí, použije se runtime locale. */
|
|
155
|
+
locale?: string;
|
|
156
|
+
/** Volitelný persistence adapter. Pokud není předán, balíček běží bez lokální persistence. */
|
|
157
|
+
storage?: DataStoreStorage | null;
|
|
155
158
|
/** false - provider nebude cist/ukladat data do persistentniho uloziste */
|
|
156
159
|
usePersistentStorage?: boolean;
|
|
160
|
+
/** React subtree obalená DataStoreProviderem. */
|
|
157
161
|
children: ReactNode;
|
|
158
162
|
}
|
|
163
|
+
/** Veřejné runtime API vystavené přes useDataStore a související hooky. */
|
|
159
164
|
interface DataStore {
|
|
160
165
|
providers: Record<string, any>;
|
|
161
166
|
documents: Record<string, any>;
|
|
@@ -184,7 +189,6 @@ interface DataStore {
|
|
|
184
189
|
unregisterProviderSockets: (sockets: string | string[]) => void;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
declare const SQLite: SQLite$1;
|
|
188
192
|
type DataStoreMetaType = Pick<DataStore, "isLive" | "isSynchronizing" | "sockets" | "counterProviders" | "counterDocuments">;
|
|
189
193
|
type DataStoreActionsType = Pick<DataStore, "dispatch" | "initProvider" | "resetProvider" | "registerProvider" | "unregisterProvider" | "updateProviderListeners" | "resetDataStore" | "startSockets" | "stopSockets" | "registerProviderSockets" | "unregisterProviderSockets" | "updateDocuments" | "presetProviders">;
|
|
190
194
|
type DataStoreStableType = {
|
|
@@ -196,17 +200,17 @@ type DataStoreStableType = {
|
|
|
196
200
|
getExternalDocuments: () => Record<string, any>;
|
|
197
201
|
getExternalProviders: () => Record<string, any>;
|
|
198
202
|
};
|
|
199
|
-
/** Meta (isLive, isSynchronizing, sockets,
|
|
203
|
+
/** Meta informace (isLive, isSynchronizing, sockets, čítače). */
|
|
200
204
|
declare const DataStoreContext: React.Context<DataStoreMetaType>;
|
|
201
|
-
/**
|
|
205
|
+
/** Surová mapa dokumentů */
|
|
202
206
|
declare const DataStoreDocumentsContext: React.Context<Record<string, any>>;
|
|
203
|
-
/**
|
|
207
|
+
/** Surová mapa providerů */
|
|
204
208
|
declare const DataStoreProvidersContext: React.Context<Record<string, any>>;
|
|
205
|
-
/**
|
|
209
|
+
/** Stabilní action callbacky */
|
|
206
210
|
declare const DataStoreActionsContext: React.Context<DataStoreActionsType>;
|
|
207
|
-
/**
|
|
211
|
+
/** Stabilní datastore API pro provider-scoped subscriptions */
|
|
208
212
|
declare const DataStoreStableContext: React.Context<DataStoreStableType>;
|
|
209
|
-
/**
|
|
213
|
+
/** Vrací všechny stabilní action callbacky. Komponenty s tímto hookem se nepřerenderují při změnách dokumentů. */
|
|
210
214
|
declare const useDataStoreActions: () => DataStoreActionsType;
|
|
211
215
|
/**
|
|
212
216
|
*
|
|
@@ -214,6 +218,9 @@ declare const useDataStoreActions: () => DataStoreActionsType;
|
|
|
214
218
|
* @param resultType - "object"(default) | "array"
|
|
215
219
|
* @returns {documents, filter}
|
|
216
220
|
*/
|
|
221
|
+
/**
|
|
222
|
+
* Vyfiltruje všechny datastore dokumenty podle matcher objektu a vrátí reaktivní výsledek.
|
|
223
|
+
*/
|
|
217
224
|
declare const useFilteredDocuments: (filter: Record<string, any>) => {
|
|
218
225
|
documents: any[] | Record<string, any>;
|
|
219
226
|
setFilter: React.Dispatch<React.SetStateAction<Record<string, any>>>;
|
|
@@ -230,7 +237,6 @@ declare const useDocuments: () => {
|
|
|
230
237
|
* Vrati object of documents daneho providera. Dokumenty lze vyfiltrovat
|
|
231
238
|
*
|
|
232
239
|
* @param {*} provider
|
|
233
|
-
* @param {*} filter
|
|
234
240
|
* @returns
|
|
235
241
|
*/
|
|
236
242
|
declare const useProviderDocuments: (provider: ProviderTypes, settings?: {
|
|
@@ -240,18 +246,72 @@ declare const useProviderDocuments: (provider: ProviderTypes, settings?: {
|
|
|
240
246
|
}) => {
|
|
241
247
|
[key: string]: any;
|
|
242
248
|
};
|
|
249
|
+
/** Vrací surový stav providera podle provider id. */
|
|
243
250
|
declare const useProvider: (val: ProviderTypes) => any;
|
|
244
|
-
/**
|
|
251
|
+
/** Kompletní DataStore - spojuje všechny sub-contexty. Komponenty s tímto hookem se přerenderují při jakékoliv změně stavu. */
|
|
245
252
|
declare const useDataStore: () => DataStore;
|
|
246
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Imperativní API `DataStoreProvider` vystavené přes `ref`.
|
|
255
|
+
*
|
|
256
|
+
* Umožňuje volat akce DataStore přímo z rodiče (např. `App.tsx`)
|
|
257
|
+
* bez nutnosti použití `useDataStoreActions` hooku uvnitř stromové hierarchie.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```tsx
|
|
261
|
+
* const dsRef = useRef<DataStoreRef>(null);
|
|
262
|
+
*
|
|
263
|
+
* <DataStoreProvider ref={dsRef} ...>
|
|
264
|
+
* <AppProvider
|
|
265
|
+
* onLogin={({ userId }) => {
|
|
266
|
+
* dsRef.current?.startSockets();
|
|
267
|
+
* dsRef.current?.registerProviderSockets(userId);
|
|
268
|
+
* }}
|
|
269
|
+
* onLogout={({ userId }) => {
|
|
270
|
+
* dsRef.current?.unregisterProviderSockets(userId);
|
|
271
|
+
* dsRef.current?.stopSockets();
|
|
272
|
+
* }}
|
|
273
|
+
* />
|
|
274
|
+
* </DataStoreProvider>
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
type DataStoreRef = DataStoreActionsType;
|
|
278
|
+
/**
|
|
279
|
+
* Kořenový provider, který propojuje DataStore contexty, REST načítání, sockety a volitelnou persistenci.
|
|
280
|
+
*
|
|
281
|
+
* Podporuje volitelný `ref` (`DataStoreRef`) pro imperativní přístup k akcím
|
|
282
|
+
* přímo z rodičovské komponenty bez použití kontextového hooku.
|
|
283
|
+
*/
|
|
284
|
+
declare const DataStoreProvider: React.ForwardRefExoticComponent<DataStoreProps & React.RefAttributes<DataStoreActionsType>>;
|
|
247
285
|
|
|
286
|
+
interface UseDataProviderResult {
|
|
287
|
+
/** Materializované dokumenty providera po vyhodnocení šablon a filtraci. */
|
|
288
|
+
documents: Array<Record<string, any>>;
|
|
289
|
+
/** Schéma providera, pokud je dostupné. */
|
|
290
|
+
schema?: Record<string, any>;
|
|
291
|
+
/** Aktualizuje data providera pomocí výchozí update varianty. */
|
|
292
|
+
update: (val: JSONType) => void;
|
|
293
|
+
/** Aktualizuje položku/položky providera s volitelnou variantou a route parametry. */
|
|
294
|
+
updateItem: (args: {
|
|
295
|
+
params?: JSONType;
|
|
296
|
+
data?: JSONType;
|
|
297
|
+
variant?: string;
|
|
298
|
+
documentId?: string;
|
|
299
|
+
}, callback?: (resp: JSONType) => void) => void;
|
|
300
|
+
/** Smaže položku/položky providera. */
|
|
301
|
+
deleteItem: (args: {
|
|
302
|
+
params?: JSONType;
|
|
303
|
+
data?: JSONType;
|
|
304
|
+
}, callback?: (resp: JSONType) => void) => void;
|
|
305
|
+
/** Vytvoří novou položku providera. */
|
|
306
|
+
createItem: (data: JSONType, callback?: () => void) => void;
|
|
307
|
+
}
|
|
248
308
|
/**
|
|
309
|
+
* Zaregistruje/zpřístupní providera a vrátí normalizované dokumenty spolu s CRUD helpery.
|
|
249
310
|
*
|
|
250
|
-
* @param id
|
|
251
|
-
* @param params
|
|
252
|
-
* @param dataFilter
|
|
253
|
-
* @param settings
|
|
254
|
-
* @returns void
|
|
311
|
+
* @param id Provider id nebo inline definice providera.
|
|
312
|
+
* @param params Parametry šablony používané při renderu URI/definice.
|
|
313
|
+
* @param dataFilter Volitelný client-side filtr dokumentů providera.
|
|
314
|
+
* @param settings Volitelný závislý dokument použitý pro přepočet dat.
|
|
255
315
|
*/
|
|
256
316
|
declare const useDataProvider: (
|
|
257
317
|
/**
|
|
@@ -276,26 +336,9 @@ dataFilter?: JSONType | null,
|
|
|
276
336
|
settings?: {
|
|
277
337
|
documentId?: string;
|
|
278
338
|
document?: JSONType;
|
|
279
|
-
}) =>
|
|
280
|
-
documents: any;
|
|
281
|
-
schema: any;
|
|
282
|
-
update: (val: JSONType) => void;
|
|
283
|
-
updateItem: ({ params, data, variant, documentId }: {
|
|
284
|
-
params?: JSONType;
|
|
285
|
-
data?: JSONType;
|
|
286
|
-
variant?: string;
|
|
287
|
-
documentId?: string;
|
|
288
|
-
}, callback?: (resp: JSONType) => void) => void;
|
|
289
|
-
deleteItem: ({ params, data }: {
|
|
290
|
-
params?: JSONType;
|
|
291
|
-
data?: JSONType;
|
|
292
|
-
}, callback?: (resp: JSONType) => void) => void;
|
|
293
|
-
createItem: (data: JSONType, callback?: () => void) => void;
|
|
294
|
-
};
|
|
339
|
+
}) => UseDataProviderResult;
|
|
295
340
|
|
|
296
|
-
/**
|
|
297
|
-
* blabla
|
|
298
|
-
*/
|
|
341
|
+
/** Vstupní parametry hooku useDocument. */
|
|
299
342
|
interface UseDocumentParams {
|
|
300
343
|
/**
|
|
301
344
|
* UUID dokumentu
|
|
@@ -316,41 +359,40 @@ interface UseDocumentParams {
|
|
|
316
359
|
allFields?: boolean;
|
|
317
360
|
}
|
|
318
361
|
interface UseDocumentResult {
|
|
319
|
-
/**
|
|
320
|
-
* Vraci neco
|
|
321
|
-
*/
|
|
362
|
+
/** Materializovaný payload dokumentu z DataStore. */
|
|
322
363
|
document: Record<string, any>;
|
|
323
364
|
}
|
|
324
365
|
/**
|
|
325
|
-
*
|
|
366
|
+
* Vrátí jeden dokument a volitelně spustí lazy načtení chybějících polí.
|
|
326
367
|
*
|
|
327
|
-
* Example: useDocument({documentId: "
|
|
328
|
-
*
|
|
329
|
-
* @param documentId - ID dokumentu
|
|
330
|
-
* @param model - nazev modelu
|
|
331
|
-
* @param provider - nazev providera
|
|
332
|
-
* @param fields - seznam polozek dokumentu ktere chceme ziskat
|
|
333
|
-
* @param allFields - kompletni dokument
|
|
334
|
-
*
|
|
335
|
-
* @returns - vraci dokument
|
|
368
|
+
* Example: useDocument({ documentId: "...", model: "products", fields: ["name", "image"] })
|
|
336
369
|
*/
|
|
337
370
|
declare const useDocument: ({ documentId, model, provider, fields, allFields }: UseDocumentParams) => UseDocumentResult;
|
|
338
371
|
|
|
339
|
-
|
|
340
|
-
|
|
372
|
+
interface UseProviderActionsResult {
|
|
373
|
+
/** Schéma providera, pokud je dostupné. */
|
|
374
|
+
schema?: Record<string, any>;
|
|
375
|
+
/** Aktualizuje data providera pomocí výchozí update varianty. */
|
|
341
376
|
update: (val: JSONType) => void;
|
|
342
|
-
|
|
377
|
+
/** Aktualizuje položku/položky providera s volitelnou route variantou a parametry. */
|
|
378
|
+
updateItem: (args: {
|
|
343
379
|
params?: JSONType;
|
|
344
380
|
data?: any;
|
|
345
381
|
variant?: string;
|
|
346
382
|
documentId?: Uuid;
|
|
347
383
|
}, callback?: (value: JSONType) => void) => void;
|
|
348
|
-
|
|
384
|
+
/** Smaže položku/položky providera. */
|
|
385
|
+
deleteItem: (args: {
|
|
349
386
|
params: JSONType;
|
|
350
387
|
data?: JSONType;
|
|
351
388
|
}, callback?: () => void) => void;
|
|
389
|
+
/** Vytvoří novou položku providera. */
|
|
352
390
|
createItem: (data: JSONType, callback?: (value: JSONType) => void) => void;
|
|
353
|
-
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Vrací action helpery pro známé provider id.
|
|
394
|
+
*/
|
|
395
|
+
declare const useProviderActions: (providerId: Uuid, data?: JSONType) => UseProviderActionsResult;
|
|
354
396
|
|
|
355
397
|
declare function recalculateObjectWithDocument(obj: any, document: any): any;
|
|
356
398
|
declare function getValueByRules(data: any, document: any, { mode, ruleId }: {
|
|
@@ -410,4 +452,4 @@ declare const COLOR_AXIOS = "\u001B[33m%s\u001B[0m";
|
|
|
410
452
|
declare const COLOR_APP = "\u001B[34m%s\u001B[0m";
|
|
411
453
|
declare const COLOR_DS = "\u001B[35m%s\u001B[0m";
|
|
412
454
|
|
|
413
|
-
export { COLOR_APP, COLOR_AXIOS, COLOR_BLUE, COLOR_CONTEXT, COLOR_CYAN, COLOR_DS, COLOR_ERROR, COLOR_FUNCTION, COLOR_GREEN, COLOR_MAGENTA, COLOR_ORANGE, COLOR_PROVIDER, COLOR_RED, COLOR_RENDER, COLOR_SCREEN, COLOR_SOCKET, COLOR_SOCKETS, COLOR_WARNING, COLOR_WHITE, COLOR_YELLOW, type DataProvider, type DataProviders, type DataStore, DataStoreActionsContext, DataStoreContext, DataStoreDocumentsContext, type DataStoreProps, DataStoreProvider, DataStoreProvidersContext, DataStoreStableContext, type DispatcherActionType, type DispatcherType, type FilterType, type JSONType, type ProductFiltersType, type ProviderDataSource, type ProviderTypes,
|
|
455
|
+
export { COLOR_APP, COLOR_AXIOS, COLOR_BLUE, COLOR_CONTEXT, COLOR_CYAN, COLOR_DS, COLOR_ERROR, COLOR_FUNCTION, COLOR_GREEN, COLOR_MAGENTA, COLOR_ORANGE, COLOR_PROVIDER, COLOR_RED, COLOR_RENDER, COLOR_SCREEN, COLOR_SOCKET, COLOR_SOCKETS, COLOR_WARNING, COLOR_WHITE, COLOR_YELLOW, type DataProvider, type DataProviders, type DataStore, DataStoreActionsContext, DataStoreContext, DataStoreDocumentsContext, type DataStoreProps, DataStoreProvider, DataStoreProvidersContext, type DataStoreRef, DataStoreStableContext, DataStoreStorage, type DispatcherActionType, type DispatcherType, type FilterType, type JSONType, type ProductFiltersType, type ProviderDataSource, type ProviderTypes, type SchemaType, type SocketItem, type SocketServerType, type UseDataProviderResult, type UseProviderActionsResult, type Uuid, dataStoreFilterObject, doesObjectMatchFilter, doesValueMatchFilter, filterDocuments, filterDocumentsAsync, type filterItemType, getValueByRules, isUuid, recalculateObjectWithDocument, useDataProvider, useDataStore, useDataStoreActions, useDocument, useDocuments, useFilteredDocuments, useProvider, useProviderActions, useProviderDocuments, uuid };
|