@xyo-network/module-abstract-mongodb 2.75.6 → 2.75.7
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/browser/IndexDescription.cjs +19 -0
- package/dist/browser/IndexDescription.cjs.map +1 -0
- package/dist/browser/IndexDescription.d.cts +24 -0
- package/dist/browser/IndexDescription.d.cts.map +1 -0
- package/dist/browser/IndexDescription.d.mts +24 -0
- package/dist/browser/IndexDescription.d.mts.map +1 -0
- package/dist/browser/IndexDescription.d.ts +24 -0
- package/dist/browser/IndexDescription.d.ts.map +1 -0
- package/dist/browser/IndexDescription.js +1 -0
- package/dist/browser/IndexDescription.js.map +1 -0
- package/dist/browser/Module.cjs +21 -0
- package/dist/browser/Module.cjs.map +1 -1
- package/dist/browser/Module.d.cts +5 -0
- package/dist/browser/Module.d.cts.map +1 -1
- package/dist/browser/Module.d.mts +5 -0
- package/dist/browser/Module.d.mts.map +1 -1
- package/dist/browser/Module.d.ts +5 -0
- package/dist/browser/Module.d.ts.map +1 -1
- package/dist/browser/Module.js +21 -0
- package/dist/browser/Module.js.map +1 -1
- package/dist/browser/index.cjs +21 -0
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -0
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +21 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +691 -409
- package/dist/node/IndexDescription.d.cts +24 -0
- package/dist/node/IndexDescription.d.cts.map +1 -0
- package/dist/node/IndexDescription.d.mts +24 -0
- package/dist/node/IndexDescription.d.mts.map +1 -0
- package/dist/node/IndexDescription.d.ts +24 -0
- package/dist/node/IndexDescription.d.ts.map +1 -0
- package/dist/node/IndexDescription.js +19 -0
- package/dist/node/IndexDescription.js.map +1 -0
- package/dist/node/IndexDescription.mjs +1 -0
- package/dist/node/IndexDescription.mjs.map +1 -0
- package/dist/node/Module.d.cts +5 -0
- package/dist/node/Module.d.cts.map +1 -1
- package/dist/node/Module.d.mts +5 -0
- package/dist/node/Module.d.mts.map +1 -1
- package/dist/node/Module.d.ts +5 -0
- package/dist/node/Module.d.ts.map +1 -1
- package/dist/node/Module.js +28 -0
- package/dist/node/Module.js.map +1 -1
- package/dist/node/Module.mjs +28 -0
- package/dist/node/Module.mjs.map +1 -1
- package/dist/node/index.d.cts +1 -0
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +28 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +28 -0
- package/dist/node/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/IndexDescription.ts +26 -0
- package/src/Module.ts +21 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"@xylabs/exists": "^2.12.14",
|
|
15
15
|
"@xylabs/lodash": "^2.12.14",
|
|
16
16
|
"@xylabs/static-implements": "^2.12.14",
|
|
17
|
-
"@xyo-network/module-model": "~2.75.
|
|
18
|
-
"@xyo-network/module-model-mongodb": "~2.75.
|
|
19
|
-
"@xyo-network/node-core-model": "~2.75.
|
|
20
|
-
"@xyo-network/payload-model": "~2.75.
|
|
17
|
+
"@xyo-network/module-model": "~2.75.7",
|
|
18
|
+
"@xyo-network/module-model-mongodb": "~2.75.7",
|
|
19
|
+
"@xyo-network/node-core-model": "~2.75.7",
|
|
20
|
+
"@xyo-network/payload-model": "~2.75.7",
|
|
21
21
|
"mongodb": "^6.1.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@xyo-network/sdk-xyo-mongo-js": "~2.75.
|
|
24
|
+
"@xyo-network/sdk-xyo-mongo-js": "~2.75.7"
|
|
25
25
|
},
|
|
26
26
|
"peerDependenciesMeta": {
|
|
27
27
|
"@xyo-network/sdk-xyo-mongo-js": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@xylabs/ts-scripts-yarn3": "^3.0.
|
|
33
|
-
"@xylabs/tsconfig": "^3.0.
|
|
34
|
-
"@xyo-network/sdk-xyo-mongo-js": "~2.75.
|
|
32
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.82",
|
|
33
|
+
"@xylabs/tsconfig": "^3.0.82",
|
|
34
|
+
"@xyo-network/sdk-xyo-mongo-js": "~2.75.7",
|
|
35
35
|
"fake-indexeddb": "^4.0.2",
|
|
36
36
|
"typescript": "^5.2.2"
|
|
37
37
|
},
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
79
79
|
},
|
|
80
80
|
"sideEffects": false,
|
|
81
|
-
"version": "2.75.
|
|
81
|
+
"version": "2.75.7"
|
|
82
82
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The index direction (1 for ascending, -1 for descending)
|
|
3
|
+
*/
|
|
4
|
+
export type IndexDirection = -1 | 1
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Description of index(es) to be created on a store
|
|
8
|
+
*/
|
|
9
|
+
export type IndexDescription = {
|
|
10
|
+
/**
|
|
11
|
+
* The key(s) to index
|
|
12
|
+
*/
|
|
13
|
+
key:
|
|
14
|
+
| {
|
|
15
|
+
[key: string]: IndexDirection
|
|
16
|
+
}
|
|
17
|
+
| Map<string, IndexDirection>
|
|
18
|
+
/**
|
|
19
|
+
* The name of the index
|
|
20
|
+
*/
|
|
21
|
+
name?: string
|
|
22
|
+
/**
|
|
23
|
+
* If true, the index must enforce uniqueness on the key
|
|
24
|
+
*/
|
|
25
|
+
unique?: boolean
|
|
26
|
+
}
|
package/src/Module.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { BaseMongoSdk, BaseMongoSdkConfig } from '@xyo-network/sdk-xyo-mongo-js'
|
|
|
8
8
|
|
|
9
9
|
import { COLLECTIONS } from './Collections'
|
|
10
10
|
import { getBaseMongoSdkPrivateConfig } from './config'
|
|
11
|
+
import { IndexDescription } from './IndexDescription'
|
|
11
12
|
|
|
12
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
14
|
export type AnyAbstractModule<TParams extends MongoDBModuleParams = MongoDBModuleParams> = abstract new (...args: any[]) => Module<TParams>
|
|
@@ -51,6 +52,26 @@ export const MongoDBModuleMixin = <
|
|
|
51
52
|
this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMeta>(this.payloadSdkConfig)
|
|
52
53
|
return assertEx(this._payloadSdk)
|
|
53
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Ensures any indexes specified within the config are created. This method should be idempotent
|
|
58
|
+
* allowing for multiple calls without causing errors while ensuring the desired state.
|
|
59
|
+
*/
|
|
60
|
+
async ensureIndexes(): Promise<void> {
|
|
61
|
+
const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []
|
|
62
|
+
await this.boundWitnesses.useCollection(async (collection) => {
|
|
63
|
+
const collectionName = collection.collectionName.toLowerCase()
|
|
64
|
+
const indexes = configIndexes.filter((ix) => ix?.name?.toLowerCase().startsWith(collectionName))
|
|
65
|
+
if (indexes.length === 0) return
|
|
66
|
+
await collection.createIndexes(indexes)
|
|
67
|
+
})
|
|
68
|
+
await this.payloads.useCollection(async (collection) => {
|
|
69
|
+
const collectionName = collection.collectionName.toLowerCase()
|
|
70
|
+
const indexes = configIndexes.filter((ix) => ix?.name?.toLowerCase().startsWith(collectionName))
|
|
71
|
+
if (indexes.length === 0) return
|
|
72
|
+
await collection.createIndexes(indexes)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
54
75
|
}
|
|
55
76
|
return MongoModuleBase
|
|
56
77
|
}
|