@arcote.tech/arc-react 0.0.26 → 0.0.28
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/dist/index.js +43 -12
- package/dist/reactModel.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -67,8 +67,31 @@ class IDBReadTransaction {
|
|
|
67
67
|
async findByIndex(store, index, data) {
|
|
68
68
|
return new Promise((resolve) => {
|
|
69
69
|
const idbIndex = this.transaction.objectStore(store).index(index);
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const keyPath = idbIndex.keyPath;
|
|
71
|
+
let keyRange;
|
|
72
|
+
const getKey = (obj) => {
|
|
73
|
+
const key = keyPath.map((key2) => obj[key2]);
|
|
74
|
+
if (key.some((value) => value === undefined))
|
|
75
|
+
return;
|
|
76
|
+
return key;
|
|
77
|
+
};
|
|
78
|
+
const simpleKey = getKey(data);
|
|
79
|
+
if (!simpleKey) {
|
|
80
|
+
const lower = "$gt" in data ? getKey(data.$gt) : getKey(data.$gte);
|
|
81
|
+
const upper = "$lt" in data ? getKey(data.$lt) : getKey(data.$lte);
|
|
82
|
+
const lowerOpen = "$gt" in data;
|
|
83
|
+
const upperOpen = "$lt" in data;
|
|
84
|
+
if (lower !== undefined && upper !== undefined) {
|
|
85
|
+
keyRange = IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen);
|
|
86
|
+
} else if (lower !== undefined) {
|
|
87
|
+
keyRange = IDBKeyRange.lowerBound(lower, lowerOpen);
|
|
88
|
+
} else {
|
|
89
|
+
keyRange = IDBKeyRange.upperBound(upper, upperOpen);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
keyRange = IDBKeyRange.only(simpleKey);
|
|
93
|
+
}
|
|
94
|
+
console.log(keyRange);
|
|
72
95
|
const result = idbIndex.getAll(keyRange);
|
|
73
96
|
result.onsuccess = (e) => {
|
|
74
97
|
resolve(e.target.result);
|
|
@@ -157,31 +180,37 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
157
180
|
return [
|
|
158
181
|
function LiveModelProvider(props) {
|
|
159
182
|
const dataStorage = useMemo(() => {
|
|
183
|
+
if (typeof window === "undefined")
|
|
184
|
+
return null;
|
|
160
185
|
const dbAdapterPromise = idbAdapterFactory(databaseName, arcContext.version)(arcContext);
|
|
161
|
-
const dataStorage2 = new MasterDataStorage(dbAdapterPromise, rtcClientFactory, arcContext);
|
|
186
|
+
const dataStorage2 = new MasterDataStorage(dbAdapterPromise, rtcClientFactory(props.token), arcContext);
|
|
162
187
|
modelMasterDataStorage = dataStorage2;
|
|
163
188
|
return dataStorage2;
|
|
164
189
|
}, [arcContext, databaseName, arcContext.version]);
|
|
165
190
|
const [syncProgress, setSyncProgress] = useState([]);
|
|
166
191
|
const [syncDone, setSyncDone] = useState(false);
|
|
167
192
|
useEffect(() => {
|
|
193
|
+
if (typeof window === "undefined" || !dataStorage)
|
|
194
|
+
return;
|
|
168
195
|
const sync = async () => {
|
|
169
|
-
await dataStorage
|
|
196
|
+
await dataStorage.sync(({ store, size }) => {
|
|
170
197
|
setSyncProgress((prev) => [...prev, { store, size }]);
|
|
171
198
|
});
|
|
172
199
|
setSyncDone(true);
|
|
173
200
|
};
|
|
174
201
|
sync();
|
|
175
|
-
}, []);
|
|
202
|
+
}, [dataStorage]);
|
|
203
|
+
if (!dataStorage || !syncDone)
|
|
204
|
+
return /* @__PURE__ */ jsx(props.syncView, {
|
|
205
|
+
progress: syncProgress
|
|
206
|
+
}, undefined, false, undefined, this);
|
|
176
207
|
return /* @__PURE__ */ jsx(LiveModelContext.Provider, {
|
|
177
208
|
value: {
|
|
178
209
|
dataStorage,
|
|
179
210
|
client: props.client,
|
|
180
211
|
catchErrorCallback: props.catchErrorCallback
|
|
181
212
|
},
|
|
182
|
-
children:
|
|
183
|
-
progress: syncProgress
|
|
184
|
-
}, undefined, false, undefined, this)
|
|
213
|
+
children: props.children
|
|
185
214
|
}, undefined, false, undefined, this);
|
|
186
215
|
},
|
|
187
216
|
function LocalModelProvider({ children }) {
|
|
@@ -238,12 +267,14 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
238
267
|
}
|
|
239
268
|
return arcContext.commandsClient(context.client, context.dataStorage, context.catchErrorCallback);
|
|
240
269
|
},
|
|
241
|
-
async function query(queryBuilderFn) {
|
|
270
|
+
async function query(queryBuilderFn, datastorage) {
|
|
271
|
+
if (!datastorage)
|
|
272
|
+
datastorage = modelMasterDataStorage;
|
|
242
273
|
const queryBuilder = arcContext.queryBuilder();
|
|
243
274
|
const query = queryBuilderFn(queryBuilder).toQuery();
|
|
244
|
-
if (!
|
|
275
|
+
if (!datastorage)
|
|
245
276
|
throw new Error("dataStorage not found");
|
|
246
|
-
const result = await query.run(
|
|
277
|
+
const result = await query.run(datastorage);
|
|
247
278
|
return result;
|
|
248
279
|
},
|
|
249
280
|
function useLocalDataStorage() {
|
|
@@ -261,4 +292,4 @@ export {
|
|
|
261
292
|
formResolver
|
|
262
293
|
};
|
|
263
294
|
|
|
264
|
-
//# debugId=
|
|
295
|
+
//# debugId=EB0E8168D4E98EF264756E2164756E21
|
package/dist/reactModel.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ForkedDataStorage, type ArcContextAny, type CommandsClient, type QueryBuilderFunctionResult, type QueryFactoryFunction } from "@arcote.tech/arc";
|
|
1
|
+
import { ForkedDataStorage, type ArcContextAny, type CommandsClient, type DataStorage, type QueryBuilderFunctionResult, type QueryFactoryFunction } from "@arcote.tech/arc";
|
|
2
2
|
export declare const reactModel: <C extends ArcContextAny>(arcContext: C, databaseName: string) => readonly [(props: {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
client: string;
|
|
5
|
+
token: string;
|
|
5
6
|
syncView: React.ComponentType<{
|
|
6
7
|
progress: {
|
|
7
8
|
store: string;
|
|
@@ -11,5 +12,5 @@ export declare const reactModel: <C extends ArcContextAny>(arcContext: C, databa
|
|
|
11
12
|
catchErrorCallback: (error: any) => void;
|
|
12
13
|
}) => import("react/jsx-dev-runtime").JSX.Element, ({ children }: {
|
|
13
14
|
children: React.ReactNode;
|
|
14
|
-
}) => import("react/jsx-dev-runtime").JSX.Element, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, dependencies?: any[]) => [QueryBuilderFunctionResult<QueryBuilderFn>, boolean], () => CommandsClient<C["commands"]>, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn) => Promise<QueryBuilderFunctionResult<QueryBuilderFn>>, () => ForkedDataStorage | null];
|
|
15
|
+
}) => import("react/jsx-dev-runtime").JSX.Element, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, dependencies?: any[]) => [QueryBuilderFunctionResult<QueryBuilderFn>, boolean], () => CommandsClient<C["commands"]>, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, datastorage?: DataStorage | null) => Promise<QueryBuilderFunctionResult<QueryBuilderFn>>, () => ForkedDataStorage | null];
|
|
15
16
|
//# sourceMappingURL=reactModel.d.ts.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.28",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"description": "React client for the Arc framework, providing utilities for querying data and executing commands, enhancing the development of reactive and efficient user interfaces.",
|