icql-core 1.0.0 → 1.0.1
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/index.js +15 -12
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -66,10 +66,16 @@ export class ICQLEngine {
|
|
|
66
66
|
let attempts = 0;
|
|
67
67
|
while (attempts < maxAttempts) {
|
|
68
68
|
try {
|
|
69
|
-
|
|
69
|
+
let indexDoc = null;
|
|
70
70
|
let ids = [];
|
|
71
71
|
let currentVersion = undefined;
|
|
72
72
|
|
|
73
|
+
try {
|
|
74
|
+
indexDoc = await getDoc({ collection: "_indexes", key: indexKey });
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// Ignore Not Found, proceed with empty ids
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
if (indexDoc?.data) {
|
|
74
80
|
ids = Array.isArray(indexDoc.data) ? indexDoc.data : (indexDoc.data.data || []);
|
|
75
81
|
currentVersion = indexDoc.version;
|
|
@@ -85,14 +91,8 @@ export class ICQLEngine {
|
|
|
85
91
|
return true;
|
|
86
92
|
} catch (e) {
|
|
87
93
|
attempts++;
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const newIds = await updateFn([]);
|
|
92
|
-
await setDoc({ collection: "_indexes", doc: { key: indexKey, data: newIds } });
|
|
93
|
-
return true;
|
|
94
|
-
} catch (err) {}
|
|
95
|
-
}
|
|
94
|
+
// Check for version conflict or generic error
|
|
95
|
+
// If it's a version conflict, the loop will retry and fetch the new version.
|
|
96
96
|
|
|
97
97
|
// Exponential Backoff
|
|
98
98
|
if (attempts < maxAttempts) {
|
|
@@ -131,20 +131,23 @@ export class ICQLEngine {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// Update Indexes
|
|
134
|
-
|
|
134
|
+
const indexPromises = [];
|
|
135
|
+
indexPromises.push(this._updateIndexWithRetry(`idx__type_${type}`, ids => [...new Set([...ids, docId])]));
|
|
135
136
|
|
|
136
137
|
// Auto-index slug if present
|
|
137
138
|
if (data.slug) {
|
|
138
|
-
this._updateIndexWithRetry(`idx_slug_${data.slug}`, ids => [...new Set([...ids, docId])]);
|
|
139
|
+
indexPromises.push(this._updateIndexWithRetry(`idx_slug_${data.slug}`, ids => [...new Set([...ids, docId])]));
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
// Handle References (Foreign Keys)
|
|
142
143
|
for (const [key, value] of Object.entries(data)) {
|
|
143
144
|
if (value && typeof value === 'object' && value._ref) {
|
|
144
|
-
this._updateIndexWithRetry(`ref_reverse_${value._ref}`, ids => [...new Set([...ids, docId])]);
|
|
145
|
+
indexPromises.push(this._updateIndexWithRetry(`ref_reverse_${value._ref}`, ids => [...new Set([...ids, docId])]));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
await Promise.all(indexPromises);
|
|
150
|
+
|
|
148
151
|
return doc;
|
|
149
152
|
}
|
|
150
153
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icql-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Relational Layer and Query Engine for Juno (Internet Computer). Build decentralized databases with JS only.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"nanoid": "^5.0.9"
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|