@medyll/idae-idbql 0.67.0 → 0.69.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.
|
@@ -15,10 +15,10 @@ export class Schema {
|
|
|
15
15
|
* @returns The created object store or null if creation fails.
|
|
16
16
|
*/
|
|
17
17
|
createStore(db, storeName, keyPath, autoIncrement = false) {
|
|
18
|
-
if (db.objectStoreNames.contains(storeName)) {
|
|
18
|
+
/* if (db.objectStoreNames.contains(storeName)) {
|
|
19
19
|
console.warn(`Store ${storeName} already exists, skipping creation.`);
|
|
20
20
|
return db.transaction(storeName, 'readwrite').objectStore(storeName);
|
|
21
|
-
}
|
|
21
|
+
} */
|
|
22
22
|
try {
|
|
23
23
|
return db.createObjectStore(storeName, { keyPath, autoIncrement });
|
|
24
24
|
}
|
|
@@ -41,14 +41,7 @@ export class Schema {
|
|
|
41
41
|
const declaredIndex = fields.find((field) => field.startsWith('&'))?.replace('&', '');
|
|
42
42
|
const keyPath = incrementField || declaredIndex || fields[0];
|
|
43
43
|
const increment = Boolean(incrementField);
|
|
44
|
-
|
|
45
|
-
if (db.objectStoreNames.contains(storeName)) {
|
|
46
|
-
console.warn(`Store ${storeName} already exists, skipping creation.`);
|
|
47
|
-
store = db.transaction(storeName, 'readwrite').objectStore(storeName);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
store = this.createStore(db, storeName, keyPath, increment);
|
|
51
|
-
}
|
|
44
|
+
const store = this.createStore(db, storeName, keyPath, increment);
|
|
52
45
|
if (store) {
|
|
53
46
|
for (const field of fields) {
|
|
54
47
|
await this.createIndexes(store, field, field);
|
|
@@ -27,7 +27,7 @@ export type TplCollectionFields = Record<string, string>;
|
|
|
27
27
|
export type TplFieldPrimitive<T = {}> = keyof typeof enumPrimitive | `text-${'tiny' | 'short' | 'medium' | 'long' | 'area'}` | `${string}.${string}` | `fk-${string}.${string}`;
|
|
28
28
|
export type TplObjectFieldPrimitive = IdbObjectify<TplFieldPrimitive>;
|
|
29
29
|
export type TplFieldFk = `fk-${string}.${string}`;
|
|
30
|
-
export type TplFkObject = IdbObjectify
|
|
30
|
+
export type TplFkObject = IdbObjectify<TplFieldFk>;
|
|
31
31
|
export type TplTypes = TplFieldPrimitive | TplObjectFieldPrimitive | TplFieldFk | TplFkObject;
|
|
32
32
|
export type TplFieldArgs = `${TplTypes} (${CombinedArgs})`;
|
|
33
33
|
/** rules */
|
package/dist/idbqlCore/types.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IdbqlIndexedCore } from
|
|
1
|
+
import type { IdbqlIndexedCore } from '../idbqlCore/idbqlCore.js';
|
|
2
2
|
interface IdbqlIndexedCore {
|
|
3
3
|
[key: string]: CollectionCore<any>;
|
|
4
4
|
}
|
|
5
|
-
import type { CollectionCore } from
|
|
6
|
-
import { type Where, type ResultSet, type ResultsetOptions } from
|
|
5
|
+
import type { CollectionCore } from '../collection/collection.svelte.js';
|
|
6
|
+
import { type Where, type ResultSet, type ResultsetOptions } from '@medyll/idae-query';
|
|
7
7
|
/**
|
|
8
8
|
* Main entry point.
|
|
9
9
|
* Creates a state object with indexedDB synchronization.
|
|
@@ -11,11 +11,11 @@ import { type Where, type ResultSet, type ResultsetOptions } from "@medyll/idae-
|
|
|
11
11
|
* @returns {object} - The state object.
|
|
12
12
|
*/
|
|
13
13
|
export declare const createIdbqlState: (idbBase: IdbqlIndexedCore) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get:
|
|
14
|
+
collectionState: Record<string, CollectionState<any>>;
|
|
15
|
+
qolie: (collection: string) => {
|
|
16
|
+
get: any;
|
|
17
17
|
getBy: (value: any, pathKey?: string) => ResultSet<any>;
|
|
18
|
-
getOne:
|
|
18
|
+
getOne: any;
|
|
19
19
|
getAll: () => ResultSet<any>;
|
|
20
20
|
create: (value: Partial<any>) => Promise<any>;
|
|
21
21
|
delete: (keyPathValue: string | number) => Promise<boolean | undefined>;
|
|
@@ -73,9 +73,9 @@ export declare class CollectionState<T> {
|
|
|
73
73
|
* Gets items from the collection by a specific value and key.
|
|
74
74
|
* @param {any} value - The value to search for.
|
|
75
75
|
* @param {string} [pathKey="id"] - The key to search by.
|
|
76
|
-
* @returns {
|
|
76
|
+
* @returns {T | undefined} The item found, or undefined if not found.
|
|
77
77
|
*/
|
|
78
|
-
get(
|
|
78
|
+
get get(): T | undefined;
|
|
79
79
|
/**
|
|
80
80
|
* Gets items from the collection by a specific value and key using a "where" query.
|
|
81
81
|
* @param {any} value - The value to search for.
|
|
@@ -90,7 +90,7 @@ export declare class CollectionState<T> {
|
|
|
90
90
|
* @param {string} [pathKey="id"] - The key to search by.
|
|
91
91
|
* @returns {T | undefined} The item found, or undefined if not found.
|
|
92
92
|
*/
|
|
93
|
-
getOne(
|
|
93
|
+
get getOne(): T | undefined;
|
|
94
94
|
/**
|
|
95
95
|
* Gets all items from the collection.
|
|
96
96
|
* @returns {ResultSet<T>} The result set of all items.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { idbqlEvent } from
|
|
1
|
+
import { idbqlEvent } from './idbqlEvent.svelte.js';
|
|
2
2
|
//
|
|
3
|
-
import { Operators, getResultset
|
|
3
|
+
import { Operators, getResultset } from '@medyll/idae-query';
|
|
4
4
|
/**
|
|
5
5
|
* Main entry point.
|
|
6
6
|
* Creates a state object with indexedDB synchronization.
|
|
@@ -25,7 +25,7 @@ export const createIdbqlState = (idbBase) => {
|
|
|
25
25
|
deleteWhere: collections[collection].deleteWhere,
|
|
26
26
|
update: collections[collection].update,
|
|
27
27
|
where: collections[collection].where,
|
|
28
|
-
updateWhere: collections[collection].updateWhere
|
|
28
|
+
updateWhere: collections[collection].updateWhere
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
function addCollection(collectionName) {
|
|
@@ -38,14 +38,10 @@ export const createIdbqlState = (idbBase) => {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
get qolie() {
|
|
45
|
-
return qolie;
|
|
46
|
-
},
|
|
41
|
+
collectionState: collections,
|
|
42
|
+
qolie: qolie,
|
|
47
43
|
onCollection: addCollection,
|
|
48
|
-
addCollection: addCollection
|
|
44
|
+
addCollection: addCollection
|
|
49
45
|
};
|
|
50
46
|
};
|
|
51
47
|
/**
|
|
@@ -122,10 +118,12 @@ export class CollectionState {
|
|
|
122
118
|
* Gets items from the collection by a specific value and key.
|
|
123
119
|
* @param {any} value - The value to search for.
|
|
124
120
|
* @param {string} [pathKey="id"] - The key to search by.
|
|
125
|
-
* @returns {
|
|
121
|
+
* @returns {T | undefined} The item found, or undefined if not found.
|
|
126
122
|
*/
|
|
127
|
-
get(
|
|
128
|
-
return
|
|
123
|
+
get get() {
|
|
124
|
+
return (value, pathKey = 'id') => {
|
|
125
|
+
return this.where({ [pathKey]: value })?.[0];
|
|
126
|
+
};
|
|
129
127
|
}
|
|
130
128
|
/**
|
|
131
129
|
* Gets items from the collection by a specific value and key using a "where" query.
|
|
@@ -133,7 +131,7 @@ export class CollectionState {
|
|
|
133
131
|
* @param {string} [pathKey="id"] - The key to search by.
|
|
134
132
|
* @returns {ResultSet<T>} The result set of the query.
|
|
135
133
|
*/
|
|
136
|
-
getBy(value, pathKey =
|
|
134
|
+
getBy(value, pathKey = 'id') {
|
|
137
135
|
return this.where({ [pathKey]: value });
|
|
138
136
|
}
|
|
139
137
|
/**
|
|
@@ -143,8 +141,10 @@ export class CollectionState {
|
|
|
143
141
|
* @param {string} [pathKey="id"] - The key to search by.
|
|
144
142
|
* @returns {T | undefined} The item found, or undefined if not found.
|
|
145
143
|
*/
|
|
146
|
-
getOne(
|
|
147
|
-
return
|
|
144
|
+
get getOne() {
|
|
145
|
+
return (value, pathKey = 'id') => {
|
|
146
|
+
return this.where({ [pathKey]: value })?.[0];
|
|
147
|
+
};
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Gets all items from the collection.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-idbql",
|
|
3
3
|
"scope": "@medyll",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.69.0",
|
|
5
5
|
"description": "A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications, offering a MongoDB-like query interface, strong TypeScript support, reactive state management, and easy integration with front-end frameworks like Svelte.",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
45
|
"type": "module",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@medyll/idae-query": "^0.
|
|
47
|
+
"@medyll/idae-query": "^0.70.0"
|
|
48
48
|
}
|
|
49
49
|
}
|