axiodb 13.0.1 → 13.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.
@@ -65,7 +65,7 @@ class TransactionIndexManager {
65
65
  this.Converter = new Converter_helper_1.default();
66
66
  this.ResponseHelper = new response_helper_1.default();
67
67
  this.ReadIndexService = new ReadIndex_service_1.ReadIndex(collectionPath);
68
- // Same shared cache InsertIndex/DeleteIndex/ReadIndex use - staging reads and
68
+ // Same shared cache ReadIndex uses - staging reads and
69
69
  // committing writes through it (instead of raw file I/O) keeps transactional
70
70
  // index changes visible to every other index consumer instead of leaving the
71
71
  // cache holding a stale pre-transaction copy.
@@ -133,6 +133,15 @@ class TransactionIndexManager {
133
133
  const oldFieldValue = op.oldData[fieldName];
134
134
  const newFieldValue = op.data[fieldName];
135
135
  const fileName = `${op.documentId}${Keys_1.General.DBMS_File_EXT}`;
136
+ // Field value didn't actually change (the common case - e.g. updating
137
+ // `status` shouldn't touch the `name`/`age`/documentId indexes at all).
138
+ // Skipping this avoids a pointless remove+re-add that reorders the
139
+ // bucket's file array for every other document sharing this same value -
140
+ // which would silently change which document a later "first match" query
141
+ // (e.g. UpdateOne, or a plain query with no .Sort()) resolves to.
142
+ if (oldFieldValue === newFieldValue) {
143
+ continue;
144
+ }
136
145
  if (oldFieldValue !== undefined && indexEntries[oldFieldValue]) {
137
146
  indexEntries[oldFieldValue] = indexEntries[oldFieldValue].filter((f) => f !== fileName);
138
147
  if (indexEntries[oldFieldValue].length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionIndexManager.service.js","sourceRoot":"","sources":["../../../source/Services/Transaction/TransactionIndexManager.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,iDAAiD;AACjD,sFAA8D;AAC9D,qFAAsD;AACtD,mFAA0D;AAC1D,kEAAuD;AACvD,oEAAyD;AACzD,qGAAsE;AACtE,kFAAoD;A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":3,"file":"TransactionIndexManager.service.js","sourceRoot":"","sources":["../../../source/Services/Transaction/TransactionIndexManager.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,iDAAiD;AACjD,sFAA8D;AAC9D,qFAAsD;AACtD,mFAA0D;AAC1D,kEAAuD;AACvD,oEAAyD;AACzD,qGAAsE;AACtE,kFAAoD;AACpD,8GAA0E;AAE1E;IAYE,YAAY,cAAsB;QAHlC,qFAAqF;QAC7E,uBAAkB,GAAqB,IAAI,GAAG,EAAE,CAAC;QAGvD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,GAAG,cAAc,UAAU,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,GAAG,IAAI,CAAC,eAAe,kBAAkB,CAAC;QAC/D,IAAI,CAAC,WAAW,GAAG,IAAI,qBAAW,EAAE,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,EAAE,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,IAAI,yBAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,IAAI,6BAAS,CAAC,cAAc,CAAC,CAAC;QACtD,uDAAuD;QACvD,6EAA6E;QAC7E,6EAA6E;QAC7E,8CAA8C;QAC9C,IAAI,CAAC,UAAU,GAAG,+BAAU,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAC3D,CAAC;IAEY,yBAAyB,CAAC,KAAa;;YAClD,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAEtE,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtC,MAAM,QAAQ,GAAG,MAAM,IAAA,sCAAgB,EAAC,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;oBA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,EAAE,CAAC;QAClC,CAAC;KAAA;IAEa,mBAAmB;;YAC/B,IAAI,CAAC;gBACH,MAAM,EAAE,GAAG,wDAAa,aAAa,GAAC,CAAC;gBACvC,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBACpD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAO,CAAC,aAAa,CAAC,CAAC,CAAC;YACtE,CAAC;uBAAO,CAAC;gBACP,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;KAAA;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axiodb",
3
- "version": "13.0.1",
3
+ "version": "13.1.2",
4
4
  "description": "The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platform issues—pure JavaScript from npm install to production.",
5
5
  "main": "./lib/config/DB.js",
6
6
  "types": "./lib/config/DB.d.ts",
@@ -1,41 +0,0 @@
1
- import { IndexManager } from "./Index.service";
2
- /**
3
- * Service for removing documents from indexes
4
- *
5
- * When a document is deleted, this service removes its reference from all
6
- * relevant index entries to prevent stale references and maintain index integrity.
7
- *
8
- * @example
9
- * ```typescript
10
- * const deleteIndex = new DeleteIndex('/path/to/collection');
11
- * await deleteIndex.RemoveFromIndex('doc123', { email: 'test@example.com' });
12
- * ```
13
- */
14
- export default class DeleteIndex extends IndexManager {
15
- private indexCache;
16
- constructor(path: string);
17
- /**
18
- * Removes a document from all matching indexes
19
- *
20
- * For each indexed field present in the document:
21
- * 1. Loads the index data from cache (or disk if not cached)
22
- * 2. Removes the document filename from indexEntries[fieldValue]
23
- * 3. Deletes the entry key if array becomes empty
24
- * 4. Updates both memory cache and disk atomically
25
- *
26
- * @param documentId - The document ID to remove (without file extension)
27
- * @param document - The document data containing indexed field values
28
- * @returns True if at least one index was updated, false otherwise
29
- */
30
- RemoveFromIndex(documentId: string, document: any): Promise<boolean>;
31
- /**
32
- * Removes multiple documents from all matching indexes (batch operation)
33
- *
34
- * @param documents - Array of { documentId, document } pairs to remove
35
- * @returns True if at least one index was updated, false otherwise
36
- */
37
- RemoveMultipleFromIndex(documents: Array<{
38
- documentId: string;
39
- document: any;
40
- }>): Promise<boolean>;
41
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- /* eslint-disable @typescript-eslint/no-explicit-any */
16
- const Keys_1 = require("../../config/Keys/Keys");
17
- const Index_service_1 = require("./Index.service");
18
- const IndexCache_service_1 = require("./IndexCache.service");
19
- const SortedIndexValues_helper_1 = __importDefault(require("../../Helper/SortedIndexValues.helper"));
20
- /**
21
- * Service for removing documents from indexes
22
- *
23
- * When a document is deleted, this service removes its reference from all
24
- * relevant index entries to prevent stale references and maintain index integrity.
25
- *
26
- * @example
27
- * ```typescript
28
- * const deleteIndex = new DeleteIndex('/path/to/collection');
29
- * await deleteIndex.RemoveFromIndex('doc123', { email: 'test@example.com' });
30
- * ```
31
- */
32
- class DeleteIndex extends Index_service_1.IndexManager {
33
- constructor(path) {
34
- super(path);
35
- this.indexCache = IndexCache_service_1.IndexCache.getInstance(path);
36
- }
37
- /**
38
- * Removes a document from all matching indexes
39
- *
40
- * For each indexed field present in the document:
41
- * 1. Loads the index data from cache (or disk if not cached)
42
- * 2. Removes the document filename from indexEntries[fieldValue]
43
- * 3. Deletes the entry key if array becomes empty
44
- * 4. Updates both memory cache and disk atomically
45
- *
46
- * @param documentId - The document ID to remove (without file extension)
47
- * @param document - The document data containing indexed field values
48
- * @returns True if at least one index was updated, false otherwise
49
- */
50
- RemoveFromIndex(documentId, document) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const matchedIndex = yield this.findMatchingIndexMeta(document);
53
- if (!matchedIndex || matchedIndex.length === 0) {
54
- return false;
55
- }
56
- let status = false;
57
- const documentFileName = `${documentId}${Keys_1.General.DBMS_File_EXT}`;
58
- for (const indexes of matchedIndex) {
59
- const indexName = indexes.indexFieldName;
60
- // Get current index data from memory cache (or load from disk)
61
- let indexData = yield this.indexCache.getIndex(indexName);
62
- if (!indexData) {
63
- // Fallback: Load from disk if not in cache
64
- const indexContent = yield this.fileManager.ReadFile(indexes.path);
65
- if (indexContent.status) {
66
- indexData = this.converter.ToObject(indexContent.data);
67
- }
68
- else {
69
- continue;
70
- }
71
- }
72
- if (!indexData) {
73
- continue;
74
- }
75
- const fieldValue = document[indexName];
76
- // Check if this field value exists in the index
77
- if (indexData.indexEntries[fieldValue]) {
78
- // Remove the document from the array
79
- const docIndex = indexData.indexEntries[fieldValue].indexOf(documentFileName);
80
- if (docIndex !== -1) {
81
- indexData.indexEntries[fieldValue].splice(docIndex, 1);
82
- // Remove the key entirely if array is now empty
83
- if (indexData.indexEntries[fieldValue].length === 0) {
84
- delete indexData.indexEntries[fieldValue];
85
- if (indexData.sortedValues) {
86
- const numericValue = Number(fieldValue);
87
- if (!Number.isNaN(numericValue)) {
88
- SortedIndexValues_helper_1.default.removeSorted(indexData.sortedValues, numericValue);
89
- }
90
- }
91
- }
92
- // Update disk first (must await for data integrity)
93
- const updateSuccess = yield this.indexCache.updateIndex(indexName, indexData);
94
- // Fire-and-forget: Invalidate cache asynchronously
95
- this.indexCache.invalidateIndex(indexName).catch(() => { });
96
- status = status || updateSuccess;
97
- }
98
- }
99
- }
100
- return status;
101
- });
102
- }
103
- /**
104
- * Removes multiple documents from all matching indexes (batch operation)
105
- *
106
- * @param documents - Array of { documentId, document } pairs to remove
107
- * @returns True if at least one index was updated, false otherwise
108
- */
109
- RemoveMultipleFromIndex(documents) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- let status = false;
112
- for (const { documentId, document } of documents) {
113
- const result = yield this.RemoveFromIndex(documentId, document);
114
- status = status || result;
115
- }
116
- return status;
117
- });
118
- }
119
- }
120
- exports.default = DeleteIndex;
121
- //# sourceMappingURL=DeleteIndex.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeleteIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/DeleteIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,iDAAiD;AACjD,mDAA+C;AAC/C,6DAAkD;AAClD,qGAAsE;AAEtE;;;;;;;;;;;GAWG;AACH,iBAAiC,SAAQ,4BAAY;IAGnD,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,+BAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;;OAYG;IACU,eAAe,CAAC,UAAkB,EAAE,QAAa;;YAC5D,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAEhE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC/C,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,MAAM,GAAG,KAAK,CAAC;YACnB,MAAM,gBAAgB,GAAG,GAAG,UAAU,GAAG,cAAO,CAAC,aAAa,EAAE,CAAC;YAEjE,KAAK,MAA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,CAAC,CAAC;gCACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;oCAChC,kCAAiB,CAAC,YAAY,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;gCACvE,CAAC;4BACH,CAAC;wBACH,CAAC;wBAED,oDAAoD;wBACpD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;wBAE9E,mDAAmD;wBACnD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;wBAE3D,MAAM,GAAG,MAAM,IAAI,aAAa,CAAC;oBACnC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAED;;;;;OAKG;IACU,uBAAuB,CAClC,SAAuD;;YAEvD,IAAI,MAAM,GAAG,KAAK,CAAC;YAEnB,KAAK,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;gBACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBAChE,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC;YAC5B,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF"}
@@ -1,35 +0,0 @@
1
- import { IndexManager } from "./Index.service";
2
- export default class InsertIndex extends IndexManager {
3
- private indexCache;
4
- constructor(path: string);
5
- /**
6
- * Inserts a document identifier into one or more index files as defined by the global index meta.
7
- *
8
- * OPTIMIZED: Uses in-memory index cache for fast reads and atomic dual-write (memory + disk).
9
- *
10
- * The method:
11
- * 1. Calls `this.findMatchingIndexMeta(document)` to determine which index files should be updated.
12
- * 2. For each matched index entry:
13
- * - Gets current index data from memory cache (or loads from disk if not cached)
14
- * - Appends `${document.documentId}${General.DBMS_File_EXT}` to `indexEntries`
15
- * - Updates both memory cache and disk atomically via indexCache.updateIndex()
16
- *
17
- * @param document - Object representing the document to index. Must contain a `documentId` property (string | number).
18
- * @returns A Promise that resolves to:
19
- * - `true` if the last index file write operation returned a success status,
20
- * - `false` if the global index meta could not be read, no matching index meta entries were found, or the final write returned a falsy status.
21
- *
22
- * @throws Propagates any exceptions thrown by file reads/writes or conversion (e.g., IO or parse/serialize errors).
23
- *
24
- * @remarks
25
- * - Updates both memory cache and disk atomically
26
- * - Thread-safe via index cache locking mechanism
27
- * - Falls back to disk read on cache miss (cold start recovery)
28
- *
29
- * @example
30
- * // document must include documentId:
31
- * // { documentId: "abc123", ... }
32
- * const success = await indexService.InsertToIndex({ documentId: "abc123" });
33
- */
34
- InsertToIndex(document: any): Promise<boolean>;
35
- }
@@ -1,109 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- /* eslint-disable @typescript-eslint/no-explicit-any */
16
- const Keys_1 = require("../../config/Keys/Keys");
17
- const Index_service_1 = require("./Index.service");
18
- const IndexCache_service_1 = require("./IndexCache.service");
19
- const SortedIndexValues_helper_1 = __importDefault(require("../../Helper/SortedIndexValues.helper"));
20
- class InsertIndex extends Index_service_1.IndexManager {
21
- constructor(path) {
22
- super(path);
23
- this.indexCache = IndexCache_service_1.IndexCache.getInstance(path);
24
- }
25
- /**
26
- * Inserts a document identifier into one or more index files as defined by the global index meta.
27
- *
28
- * OPTIMIZED: Uses in-memory index cache for fast reads and atomic dual-write (memory + disk).
29
- *
30
- * The method:
31
- * 1. Calls `this.findMatchingIndexMeta(document)` to determine which index files should be updated.
32
- * 2. For each matched index entry:
33
- * - Gets current index data from memory cache (or loads from disk if not cached)
34
- * - Appends `${document.documentId}${General.DBMS_File_EXT}` to `indexEntries`
35
- * - Updates both memory cache and disk atomically via indexCache.updateIndex()
36
- *
37
- * @param document - Object representing the document to index. Must contain a `documentId` property (string | number).
38
- * @returns A Promise that resolves to:
39
- * - `true` if the last index file write operation returned a success status,
40
- * - `false` if the global index meta could not be read, no matching index meta entries were found, or the final write returned a falsy status.
41
- *
42
- * @throws Propagates any exceptions thrown by file reads/writes or conversion (e.g., IO or parse/serialize errors).
43
- *
44
- * @remarks
45
- * - Updates both memory cache and disk atomically
46
- * - Thread-safe via index cache locking mechanism
47
- * - Falls back to disk read on cache miss (cold start recovery)
48
- *
49
- * @example
50
- * // document must include documentId:
51
- * // { documentId: "abc123", ... }
52
- * const success = await indexService.InsertToIndex({ documentId: "abc123" });
53
- */
54
- InsertToIndex(document) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const matchedIndex = yield this.findMatchingIndexMeta(document);
57
- if (matchedIndex) {
58
- if (matchedIndex.length == 0) {
59
- return false;
60
- }
61
- let status = false;
62
- for (const indexes of matchedIndex) {
63
- const indexName = indexes.indexFieldName;
64
- const documentFileName = `${document.documentId}${Keys_1.General.DBMS_File_EXT}`;
65
- // Get current index data from memory cache (or load from disk if not cached)
66
- let indexData = yield this.indexCache.getIndex(indexName);
67
- if (!indexData) {
68
- // Fallback: Load from disk if not in cache (cold start recovery)
69
- const indexContent = yield this.fileManager.ReadFile(indexes.path);
70
- if (indexContent.status) {
71
- indexData = this.converter.ToObject(indexContent.data);
72
- }
73
- else {
74
- // Index file doesn't exist - skip this index
75
- continue;
76
- }
77
- }
78
- if (!indexData) {
79
- continue;
80
- }
81
- const fieldValue = document[indexName];
82
- // Lazily backfill sortedValues for indexes written before range support existed
83
- if (!indexData.sortedValues) {
84
- indexData.sortedValues = SortedIndexValues_helper_1.default.backfillFromKeys(Object.keys(indexData.indexEntries));
85
- }
86
- // Add document to index entries
87
- const alreadyhave = Object.keys(indexData.indexEntries).some(keys => keys == fieldValue);
88
- if (alreadyhave) {
89
- indexData.indexEntries[fieldValue].push(documentFileName);
90
- }
91
- else {
92
- indexData.indexEntries[fieldValue] = [documentFileName];
93
- const numericValue = Number(fieldValue);
94
- if (!Number.isNaN(numericValue)) {
95
- SortedIndexValues_helper_1.default.insertSorted(indexData.sortedValues, numericValue);
96
- }
97
- }
98
- // Update both memory cache and disk atomically
99
- const updateSuccess = yield this.indexCache.updateIndex(indexName, indexData);
100
- status = updateSuccess;
101
- }
102
- return status;
103
- }
104
- return false;
105
- });
106
- }
107
- }
108
- exports.default = InsertIndex;
109
- //# sourceMappingURL=InsertIndex.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InsertIndex.service.js","sourceRoot":"","sources":["../../../source/Services/Index/InsertIndex.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,iDAAiD;AACjD,mDAA+C;AAC/C,6DAAkD;AAClD,qGAAsE;AAEtE,iBAAiC,SAAQ,4BAAY;IAGnD,YAAa,IAAY;QACvB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,+BAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BC;IACY,aAAa,CAAC,QAAa;;YACpC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAEhE,IAAI,YAAY,EAAC,CAAC;gBAElB,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE,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