@xyo-network/module-abstract-mongodb 3.14.14 → 3.14.15
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/index.mjs +33 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/index.mjs +33 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.mjs +33 -3
- package/dist/node/index.mjs.map +1 -1
- package/dist/types/Module.d.ts.map +1 -1
- package/dist/types/ModuleV2.d.ts.map +1 -1
- package/dist/types/merge.d.ts +2 -0
- package/dist/types/merge.d.ts.map +1 -0
- package/package.json +10 -11
- package/src/Module.ts +1 -1
- package/src/ModuleV2.ts +1 -1
- package/src/merge.ts +35 -0
package/dist/browser/index.mjs
CHANGED
|
@@ -74,12 +74,43 @@ var DefaultOrder = "desc";
|
|
|
74
74
|
|
|
75
75
|
// src/Module.ts
|
|
76
76
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
77
|
-
import { merge } from "@xylabs/lodash";
|
|
78
77
|
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
79
78
|
import { staticImplements } from "@xylabs/static-implements";
|
|
80
79
|
import {
|
|
81
80
|
MongoDBStorageClassLabels
|
|
82
81
|
} from "@xyo-network/module-model-mongodb";
|
|
82
|
+
|
|
83
|
+
// src/merge.ts
|
|
84
|
+
function isObject(val) {
|
|
85
|
+
return val !== null && typeof val === "object";
|
|
86
|
+
}
|
|
87
|
+
function merge(target, ...sources) {
|
|
88
|
+
if (!isObject(target)) {
|
|
89
|
+
throw new TypeError("Target must be an object");
|
|
90
|
+
}
|
|
91
|
+
for (const source of sources) {
|
|
92
|
+
if (!isObject(source)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const key of Object.keys(source)) {
|
|
96
|
+
const sourceVal = source[key];
|
|
97
|
+
const targetVal = target[key];
|
|
98
|
+
if (Array.isArray(sourceVal)) {
|
|
99
|
+
target[key] = [...sourceVal];
|
|
100
|
+
} else if (isObject(sourceVal)) {
|
|
101
|
+
if (!isObject(targetVal)) {
|
|
102
|
+
target[key] = {};
|
|
103
|
+
}
|
|
104
|
+
merge(target[key], sourceVal);
|
|
105
|
+
} else {
|
|
106
|
+
target[key] = sourceVal;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/Module.ts
|
|
83
114
|
var standardIndexes = [
|
|
84
115
|
{
|
|
85
116
|
name: "IX__hash",
|
|
@@ -173,7 +204,6 @@ var ensureIndexesExistOnCollection = async (sdk, configIndexes) => {
|
|
|
173
204
|
|
|
174
205
|
// src/ModuleV2.ts
|
|
175
206
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
176
|
-
import { merge as merge2 } from "@xylabs/lodash";
|
|
177
207
|
import { BaseMongoSdk as BaseMongoSdk3 } from "@xylabs/mongo";
|
|
178
208
|
import { staticImplements as staticImplements2 } from "@xylabs/static-implements";
|
|
179
209
|
import {
|
|
@@ -204,7 +234,7 @@ var MongoDBModuleMixinV2 = (ModuleBase) => {
|
|
|
204
234
|
}
|
|
205
235
|
get payloadSdkConfig() {
|
|
206
236
|
const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() };
|
|
207
|
-
return
|
|
237
|
+
return merge(
|
|
208
238
|
config,
|
|
209
239
|
this.params.payloadSdkConfig,
|
|
210
240
|
this.config.payloadSdkConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AAAA,EACnC;AACA,SAAO;AACT;;;ADVO,IAAM,+BAA+B,MAAiC;AAC3E,QAAM,MAAM,iBAAiB;AAC7B,SAAO;AAAA,IACL,oBAAoB,IAAI;AAAA,IACxB,UAAU,SAAS,IAAI,cAAc,MAAM,sBAAsB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AAQ,WAAW,EAAG;AAC1B,eAAW,MAAM,SAAS;AACxB,UAAI;AACF,cAAM,WAAW,cAAc,CAAC,EAAE,CAAC;AAAA,MACrC,SAAS,OAAO;AACd,cAAM,mBAAmB;AACzB,cAAM,EAAE,SAAS,IAAI;AACrB,YAAI,aAAa,2BAA2B,aAAa,wBAAwB;AAK/E;AAAA,QACF;AACA,gBAAQ,MAAM,wBAAwB,GAAG,IAAI,mBAAmB,cAAc,KAAK,KAAK,EAAE;AAC1F,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACvGO,IAAM,aAAa;AAEnB,IAAM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","merge","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","merge","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/merge.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction isObject(val: unknown): val is Record<string, any> {\n return val !== null && typeof val === 'object'\n}\n\nexport function merge<T extends object>(target: T, ...sources: any[]): T {\n if (!isObject(target)) {\n throw new TypeError('Target must be an object')\n }\n\n for (const source of sources) {\n if (!isObject(source)) {\n continue\n }\n\n for (const key of Object.keys(source)) {\n const sourceVal = source[key]\n const targetVal = (target as any)[key]\n\n if (Array.isArray(sourceVal)) {\n // Arrays are replaced, not deeply merged (lodash behavior)\n (target as any)[key] = [...sourceVal]\n } else if (isObject(sourceVal)) {\n if (!isObject(targetVal)) {\n (target as any)[key] = {}\n }\n merge((target as any)[key], sourceVal)\n } else {\n (target as any)[key] = sourceVal\n }\n }\n }\n\n return target\n}\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AA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AM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -74,12 +74,43 @@ var DefaultOrder = "desc";
|
|
|
74
74
|
|
|
75
75
|
// src/Module.ts
|
|
76
76
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
77
|
-
import { merge } from "@xylabs/lodash";
|
|
78
77
|
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
79
78
|
import { staticImplements } from "@xylabs/static-implements";
|
|
80
79
|
import {
|
|
81
80
|
MongoDBStorageClassLabels
|
|
82
81
|
} from "@xyo-network/module-model-mongodb";
|
|
82
|
+
|
|
83
|
+
// src/merge.ts
|
|
84
|
+
function isObject(val) {
|
|
85
|
+
return val !== null && typeof val === "object";
|
|
86
|
+
}
|
|
87
|
+
function merge(target, ...sources) {
|
|
88
|
+
if (!isObject(target)) {
|
|
89
|
+
throw new TypeError("Target must be an object");
|
|
90
|
+
}
|
|
91
|
+
for (const source of sources) {
|
|
92
|
+
if (!isObject(source)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const key of Object.keys(source)) {
|
|
96
|
+
const sourceVal = source[key];
|
|
97
|
+
const targetVal = target[key];
|
|
98
|
+
if (Array.isArray(sourceVal)) {
|
|
99
|
+
target[key] = [...sourceVal];
|
|
100
|
+
} else if (isObject(sourceVal)) {
|
|
101
|
+
if (!isObject(targetVal)) {
|
|
102
|
+
target[key] = {};
|
|
103
|
+
}
|
|
104
|
+
merge(target[key], sourceVal);
|
|
105
|
+
} else {
|
|
106
|
+
target[key] = sourceVal;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/Module.ts
|
|
83
114
|
var standardIndexes = [
|
|
84
115
|
{
|
|
85
116
|
name: "IX__hash",
|
|
@@ -173,7 +204,6 @@ var ensureIndexesExistOnCollection = async (sdk, configIndexes) => {
|
|
|
173
204
|
|
|
174
205
|
// src/ModuleV2.ts
|
|
175
206
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
176
|
-
import { merge as merge2 } from "@xylabs/lodash";
|
|
177
207
|
import { BaseMongoSdk as BaseMongoSdk3 } from "@xylabs/mongo";
|
|
178
208
|
import { staticImplements as staticImplements2 } from "@xylabs/static-implements";
|
|
179
209
|
import {
|
|
@@ -204,7 +234,7 @@ var MongoDBModuleMixinV2 = (ModuleBase) => {
|
|
|
204
234
|
}
|
|
205
235
|
get payloadSdkConfig() {
|
|
206
236
|
const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() };
|
|
207
|
-
return
|
|
237
|
+
return merge(
|
|
208
238
|
config,
|
|
209
239
|
this.params.payloadSdkConfig,
|
|
210
240
|
this.config.payloadSdkConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AAAA,EACnC;AACA,SAAO;AACT;;;ADVO,IAAM,+BAA+B,MAAiC;AAC3E,QAAM,MAAM,iBAAiB;AAC7B,SAAO;AAAA,IACL,oBAAoB,IAAI;AAAA,IACxB,UAAU,SAAS,IAAI,cAAc,MAAM,sBAAsB;AAAA,IACjE,QAAQ,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACnE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACvE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,EACzE;AACF;AAEO,IAAM,kBAAkB,C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a,wBAAwB;AAK/E;AAAA,QACF;AACA,gBAAQ,MAAM,wBAAwB,GAAG,IAAI,mBAAmB,cAAc,KAAK,KAAK,EAAE;AAC1F,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACvGO,IAAM,aAAa;AAEnB,IAAM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","merge","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","merge","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/merge.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction isObject(val: unknown): val is Record<string, any> {\n return val !== null && typeof val === 'object'\n}\n\nexport function merge<T extends object>(target: T, ...sources: any[]): T {\n if (!isObject(target)) {\n throw new TypeError('Target must be an object')\n }\n\n for (const source of sources) {\n if (!isObject(source)) {\n continue\n }\n\n for (const key of Object.keys(source)) {\n const sourceVal = source[key]\n const targetVal = (target as any)[key]\n\n if (Array.isArray(sourceVal)) {\n // Arrays are replaced, not deeply merged (lodash behavior)\n (target as any)[key] = [...sourceVal]\n } else if (isObject(sourceVal)) {\n if (!isObject(targetVal)) {\n (target as any)[key] = {}\n }\n merge((target as any)[key], sourceVal)\n } else {\n (target as any)[key] = sourceVal\n }\n }\n }\n\n return target\n}\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AAAA,EACnC;AACA,SAAO;AACT;;;ADVO,IAAM,+BAA+B,MAAiC;AAC3E,QAAM,MAAM,iBAAiB;AAC7B,SAAO;AAAA,IACL,oBAAoB,IAAI;AAAA,IACxB,UAAU,SAAS,IAAI,cAAc,MAAM,sBAAsB;AAAA,IACjE,QAAQ,SAAS,IA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C;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,gBAA+B;AACnC,YAAM,gBAAiB,KAAK,QAA2D,SAAS,WAAW,CAAC;AAC5G,YAAM,wBAAwB,KAAK,iBAAiB;AAEpD,YAAM,yBAAyBD,iBAAgB,IAAI,SAAO,EAAE,GAAG,IAAI,MAAM,GAAG,qBAAqB,IAAI,GAAG,IAAI,GAAG,EAAE;AACjH,YAAMG,gCAA+B,KAAK,UAAU,CAAC,GAAG,wBAAwB,GAAG,aAAa,CAAC;AAAA,IACnG;AAAA,EACF;AAjCE,gBADa,iBACG,UAASC;AADZ,oBAAf;AAAA,IADCC,kBAAsC;AAAA,KACxB;AAmCf,SAAO;AACT;AAOA,IAAMF,kCAAiC,OACrC,KACA,kBACG;AACH,QAAM,IAAI,cAAc,OAAO,eAAe;AAC5C,UAAM,iBAAiB,WAAW,eAAe,YAAY;AAC7D,UAAM,UAAU,cAAc,OAAO,QAAM,IAAI,MAAM,YAAY,EAAE,WAAW,cAAc,CAAC;AAC7F,QAAI,QAAQ,WAAW,EAAG;AAC1B,eAAW,MAAM,SAAS;AACxB,UAAI;AACF,cAAM,WAAW,cAAc,CAAC,EAAE,CAAC;AAAA,MACrC,SAAS,OAAO;AACd,cAAM,mBAAmB;AACzB,cAAM,EAAE,SAAS,IAAI;AACrB,YAAI,aAAa,2BAA2B,aAAa,wBAAwB;AAK/E;AAAA,QACF;AACA,gBAAQ,MAAM,wBAAwB,GAAG,IAAI,mBAAmB,cAAc,KAAK,KAAK,EAAE;AAC1F,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACvGO,IAAM,aAAa;AAEnB,IAAM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
package/dist/node/index.mjs
CHANGED
|
@@ -74,12 +74,43 @@ var DefaultOrder = "desc";
|
|
|
74
74
|
|
|
75
75
|
// src/Module.ts
|
|
76
76
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
77
|
-
import { merge } from "@xylabs/lodash";
|
|
78
77
|
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
79
78
|
import { staticImplements } from "@xylabs/static-implements";
|
|
80
79
|
import {
|
|
81
80
|
MongoDBStorageClassLabels
|
|
82
81
|
} from "@xyo-network/module-model-mongodb";
|
|
82
|
+
|
|
83
|
+
// src/merge.ts
|
|
84
|
+
function isObject(val) {
|
|
85
|
+
return val !== null && typeof val === "object";
|
|
86
|
+
}
|
|
87
|
+
function merge(target, ...sources) {
|
|
88
|
+
if (!isObject(target)) {
|
|
89
|
+
throw new TypeError("Target must be an object");
|
|
90
|
+
}
|
|
91
|
+
for (const source of sources) {
|
|
92
|
+
if (!isObject(source)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const key of Object.keys(source)) {
|
|
96
|
+
const sourceVal = source[key];
|
|
97
|
+
const targetVal = target[key];
|
|
98
|
+
if (Array.isArray(sourceVal)) {
|
|
99
|
+
target[key] = [...sourceVal];
|
|
100
|
+
} else if (isObject(sourceVal)) {
|
|
101
|
+
if (!isObject(targetVal)) {
|
|
102
|
+
target[key] = {};
|
|
103
|
+
}
|
|
104
|
+
merge(target[key], sourceVal);
|
|
105
|
+
} else {
|
|
106
|
+
target[key] = sourceVal;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/Module.ts
|
|
83
114
|
var standardIndexes = [
|
|
84
115
|
{
|
|
85
116
|
name: "IX__hash",
|
|
@@ -173,7 +204,6 @@ var ensureIndexesExistOnCollection = async (sdk, configIndexes) => {
|
|
|
173
204
|
|
|
174
205
|
// src/ModuleV2.ts
|
|
175
206
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
176
|
-
import { merge as merge2 } from "@xylabs/lodash";
|
|
177
207
|
import { BaseMongoSdk as BaseMongoSdk3 } from "@xylabs/mongo";
|
|
178
208
|
import { staticImplements as staticImplements2 } from "@xylabs/static-implements";
|
|
179
209
|
import {
|
|
@@ -204,7 +234,7 @@ var MongoDBModuleMixinV2 = (ModuleBase) => {
|
|
|
204
234
|
}
|
|
205
235
|
get payloadSdkConfig() {
|
|
206
236
|
const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() };
|
|
207
|
-
return
|
|
237
|
+
return merge(
|
|
208
238
|
config,
|
|
209
239
|
this.params.payloadSdkConfig,
|
|
210
240
|
this.config.payloadSdkConfig,
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AAAA,EACnC;AACA,SAAO;AACT;;;ADVO,IAAM,+BAA+B,MAAiC;AAC3E,QAAM,MAAM,iBAAiB;AAC7B,SAAO;AAAA,IACL,oBAAoB,IAAI;AAAA,IACxB,UAAU,SAAS,IAAI,cAAc,MAAM,sBAAsB;AAAA,IACjE,QAAQ,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACnE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACvE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,EACzE;AACF;AAEO,IAAM,kBAAkB,CAAqB,eAAuB;AACzE,SAAO,IAAI,aAAgB,EAAE,GAAG,6BAA6B,GAAG,WAAW,CAAC;AAC9E;;;AEpBA,SAAS,cAAc;AAIhB,IAAM,mBAAmB,MAAe;AAC7C,QAAM,MAAM,iBAAiB;AAC7B,QAAM,iB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a;AAEnB,IAAM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","merge","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","merge","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Collections.ts","../../src/config/getBaseMongoSdk.ts","../../src/config/getMongoDBConfig.ts","../../src/config/hasMongoDBConfig.ts","../../src/Databases.ts","../../src/Defaults.ts","../../src/Module.ts","../../src/merge.ts","../../src/ModuleV2.ts","../../src/util/dbProperty.ts"],"sourcesContent":["// TODO: By DB\nexport const COLLECTIONS = {\n AddressInfo: 'address_info' as const,\n ArchivistStats: 'archivist_stats' as const,\n BoundWitnesses: 'bound_witnesses' as const,\n Payloads: 'payloads' as const,\n Thumbnails: 'thumbnails' as const,\n Users: 'users' as const,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { BaseMongoSdkPrivateConfig } from '@xylabs/mongo'\nimport { BaseMongoSdk } from '@xylabs/mongo'\nimport type { Document } from 'mongodb'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const getBaseMongoSdkPrivateConfig = (): BaseMongoSdkPrivateConfig => {\n const env = getMongoDBConfig()\n return {\n dbConnectionString: env.MONGO_CONNECTION_STRING,\n dbDomain: assertEx(env.MONGO_DOMAIN, () => 'Missing Mongo Domain'),\n dbName: assertEx(env.MONGO_DATABASE, () => 'Missing Mongo Database'),\n dbPassword: assertEx(env.MONGO_PASSWORD, () => 'Missing Mongo Password'),\n dbUserName: assertEx(env.MONGO_USERNAME, () => 'Missing Mongo Username'),\n }\n}\n\nexport const getBaseMongoSdk = <T extends Document>(collection: string) => {\n return new BaseMongoSdk<T>({ ...getBaseMongoSdkPrivateConfig(), collection })\n}\n","export type MongoDbConnectionStringEnvVar = 'MONGO_CONNECTION_STRING'\nexport type MongoDbEnvVars = 'MONGO_DATABASE' | 'MONGO_DOMAIN' | 'MONGO_PASSWORD' | 'MONGO_USERNAME'\n\nexport type MongoEnv = Record<MongoDbEnvVars | MongoDbConnectionStringEnvVar, string | undefined>\n\nexport const getMongoDBConfig = (): MongoEnv => {\n const env: MongoEnv = {} as MongoEnv\n if (process.env.MONGO_CONNECTION_STRING) {\n env.MONGO_CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING\n }\n if (process.env.MONGO_DOMAIN) {\n env.MONGO_DATABASE = process.env.MONGO_DATABASE\n env.MONGO_DOMAIN = process.env.MONGO_DOMAIN\n env.MONGO_PASSWORD = process.env.MONGO_PASSWORD\n env.MONGO_USERNAME = process.env.MONGO_USERNAME\n }\n return env\n}\n","import { exists } from '@xylabs/exists'\n\nimport { getMongoDBConfig } from './getMongoDBConfig.ts'\n\nexport const hasMongoDBConfig = (): boolean => {\n const env = getMongoDBConfig()\n const requiredValues = [env.MONGO_CONNECTION_STRING, env.MONGO_DATABASE, env.MONGO_DOMAIN, env.MONGO_PASSWORD, env.MONGO_USERNAME]\n return requiredValues.every(exists)\n}\n","export const DATABASES = { Archivist: 'archivist' as const }\n","export const DefaultAggregateTimeoutMs = 10_000\nexport const DefaultLimit = 20\nexport const DefaultMaxTimeMS = 2000\nexport const DefaultOrder = 'desc'\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModule, MongoDBModuleParams, MongoDBModuleStatic, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { BoundWitnessWithMongoMeta, PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'IX__hash', key: { _hash: 1 }, unique: false,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'IX__sequence', key: { _sequence: 1 }, unique: false,\n },\n]\n\nexport const MongoDBModuleMixin = <\n TParams extends MongoDBModuleParams = MongoDBModuleParams,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModule {\n static readonly labels = MongoDBStorageClassLabels\n _boundWitnessSdk: BaseMongoSdk<BoundWitnessWithMongoMeta> | undefined\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get boundWitnessSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.BoundWitnesses, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.boundWitnessSdkConfig,\n this.config.boundWitnessSdkConfig,\n { collection: this.config.boundWitnessSdkConfig?.collection ?? this.params.boundWitnessSdkConfig?.collection ?? COLLECTIONS.BoundWitnesses },\n )\n }\n\n get boundWitnesses() {\n this._boundWitnessSdk = this._boundWitnessSdk ?? new BaseMongoSdk<BoundWitnessWithMongoMeta>(this.boundWitnessSdkConfig)\n return assertEx(this._boundWitnessSdk)\n }\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const boundWitnessesCollectionName = this.boundWitnessSdkConfig.collection\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const bwStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${boundWitnessesCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.boundWitnesses, [...bwStandardIndexes, ...configIndexes])\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta> | BaseMongoSdk<BoundWitnessWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction isObject(val: unknown): val is Record<string, any> {\n return val !== null && typeof val === 'object'\n}\n\nexport function merge<T extends object>(target: T, ...sources: any[]): T {\n if (!isObject(target)) {\n throw new TypeError('Target must be an object')\n }\n\n for (const source of sources) {\n if (!isObject(source)) {\n continue\n }\n\n for (const key of Object.keys(source)) {\n const sourceVal = source[key]\n const targetVal = (target as any)[key]\n\n if (Array.isArray(sourceVal)) {\n // Arrays are replaced, not deeply merged (lodash behavior)\n (target as any)[key] = [...sourceVal]\n } else if (isObject(sourceVal)) {\n if (!isObject(targetVal)) {\n (target as any)[key] = {}\n }\n merge((target as any)[key], sourceVal)\n } else {\n (target as any)[key] = sourceVal\n }\n }\n }\n\n return target\n}\n","import { assertEx } from '@xylabs/assert'\nimport { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'\nimport { staticImplements } from '@xylabs/static-implements'\nimport {\n MongoDBModuleParamsV2, MongoDBModuleStatic, MongoDBModuleV2, MongoDBStorageClassLabels,\n} from '@xyo-network/module-model-mongodb'\nimport { PayloadWithMongoMeta } from '@xyo-network/payload-mongodb'\nimport { MongoServerError } from 'mongodb'\n\nimport { AnyAbstractModule } from './AnyAbstractModule.ts'\nimport { COLLECTIONS } from './Collections.ts'\nimport { getBaseMongoSdkPrivateConfig } from './config/index.ts'\nimport { IndexDescription } from './IndexDescription.ts'\nimport { merge } from './merge.ts'\n\nconst standardIndexes: IndexDescription[] = [\n {\n name: 'UX__hash', key: { _hash: 1 }, unique: true,\n },\n {\n name: 'IX__dataHash', key: { _dataHash: 1 }, unique: false,\n },\n {\n name: 'UX__sequence', key: { _sequence: 1 }, unique: true,\n },\n]\n\nexport const MongoDBModuleMixinV2 = <\n TParams extends MongoDBModuleParamsV2 = MongoDBModuleParamsV2,\n TModule extends AnyAbstractModule<TParams> = AnyAbstractModule<TParams>,\n>(\n ModuleBase: TModule,\n) => {\n @staticImplements<MongoDBModuleStatic>()\n abstract class MongoModuleBase extends ModuleBase implements MongoDBModuleV2 {\n static readonly labels = MongoDBStorageClassLabels\n _payloadSdk: BaseMongoSdk<PayloadWithMongoMeta> | undefined\n\n get jobQueue() {\n return assertEx(this.params.jobQueue, () => 'MongoDBModule Error: jobQueue required for this module but is not defined')\n }\n\n get payloadSdkConfig(): BaseMongoSdkConfig {\n const config = { collection: COLLECTIONS.Payloads, ...getBaseMongoSdkPrivateConfig() }\n return merge(\n config,\n this.params.payloadSdkConfig,\n this.config.payloadSdkConfig,\n { collection: this.config.payloadSdkConfig?.collection ?? this.params.payloadSdkConfig?.collection ?? COLLECTIONS.Payloads },\n )\n }\n\n get payloads() {\n this._payloadSdk = this._payloadSdk ?? new BaseMongoSdk<PayloadWithMongoMeta>(this.payloadSdkConfig)\n return assertEx(this._payloadSdk)\n }\n\n /**\n * Ensures any indexes specified within the config are created. This method should be idempotent\n * allowing for multiple calls without causing errors while ensuring the desired state.\n */\n async ensureIndexes(): Promise<void> {\n const configIndexes = (this.config as { storage?: { indexes?: IndexDescription[] } })?.storage?.indexes ?? []\n const payloadCollectionName = this.payloadSdkConfig.collection\n\n const payloadStandardIndexes = standardIndexes.map(ix => ({ ...ix, name: `${payloadCollectionName}.${ix.name}` }))\n await ensureIndexesExistOnCollection(this.payloads, [...payloadStandardIndexes, ...configIndexes])\n }\n }\n return MongoModuleBase\n}\n\n/**\n * Ensures the specified indexes exist on the collection\n * @param sdk The sdk to use for the collection\n * @param configIndexes The indexes to ensure exist on the collection\n */\nconst ensureIndexesExistOnCollection = async (\n sdk: BaseMongoSdk<PayloadWithMongoMeta>,\n configIndexes: IndexDescription[],\n) => {\n await sdk.useCollection(async (collection) => {\n const collectionName = collection.collectionName.toLowerCase()\n const indexes = configIndexes.filter(ix => ix?.name?.toLowerCase().startsWith(collectionName))\n if (indexes.length === 0) return\n for (const ix of indexes) {\n try {\n await collection.createIndexes([ix])\n } catch (error) {\n const mongoServerError = error as MongoServerError\n const { codeName } = mongoServerError\n if (codeName === 'IndexKeySpecsConflict' || codeName === 'IndexOptionsConflict') {\n // Index already exists which is fine OR index exists with another name which is fine\n // TODO: For the latter case (IndexOptionsConflict) we could get into this case\n // if we change the TTL an existing index. We currently don't support TTLs so\n // we'll need to revisit this assumption if we do.\n continue\n }\n console.error(`Error creating index ${ix.name} for collection ${collectionName}: ${error}`)\n throw error\n }\n }\n })\n}\n","export const escapeChar = '#'\n\nexport const toDbProperty = (value: string) => value.replaceAll('.', escapeChar)\n\nexport const fromDbProperty = (value: string) => value.replaceAll(escapeChar, '.')\n"],"mappings":";;;;;;;;;;;;;;AACO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AACT;;;ACRA,SAAS,gBAAgB;AAEzB,SAAS,oBAAoB;;;ACGtB,IAAM,mBAAmB,MAAgB;AAC9C,QAAM,MAAgB,CAAC;AACvB,MAAI,QAAQ,IAAI,yBAAyB;AACvC,QAAI,0BAA0B,QAAQ,IAAI;AAAA,EAC5C;AACA,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,eAAe,QAAQ,IAAI;AAC/B,QAAI,iBAAiB,QAAQ,IAAI;AACjC,QAAI,iBAAiB,QAAQ,IAAI;AAAA,EACnC;AACA,SAAO;AACT;;;ADVO,IAAM,+BAA+B,MAAiC;AAC3E,QAAM,MAAM,iBAAiB;AAC7B,SAAO;AAAA,IACL,oBAAoB,IAAI;AAAA,IACxB,UAAU,SAAS,IAAI,cAAc,MAAM,sBAAsB;AAAA,IACjE,QAAQ,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACnE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,IACvE,YAAY,SAAS,IAAI,gBAAgB,MAAM,wBAAwB;AAAA,EACzE;AACF;AAEO,IAAM,kBAAkB,CAAqB,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,SAAO,EAAE,GAAG,IAAI,MAAM,GAAG,qBAAqB,IAAI,GAAG,IAAI,GAAG,EAAE;AACjH,YAAMG,gCAA+B,KAAK,UAAU,CAAC,GAAG,wBAAwB,GAAG,aAAa,CAAC;AAAA,IACnG;AAAA,EACF;AAjCE,gBADa,iBACG,UAASC;AADZ,oBAAf;AAAA,IADCC,kBAAsC;AAAA,KACxB;AAmCf,SAAO;AACT;AAOA,IAAMF,kCAAiC,OACrC,KACA,kBACG;AACH,QAAM,IAAI,cAAc,OAAO,eAAe;AAC5C,UAAM,iBAAiB,WAAW,eAAe,YAAY;AAC7D,UAAM,UAAU,cAAc,OAAO,QAAM,IAAI,MAAM,YAAY,EAAE,WAAW,cAAc,CAAC;AAC7F,QAAI,QAAQ,WAAW,EAAG;AAC1B,eAAW,MAAM,SAAS;AACxB,UAAI;AACF,cAAM,WAAW,cAAc,CAAC,EAAE,CAAC;AAAA,MACrC,SAAS,OAAO;AACd,cAAM,mBAAmB;AACzB,cAAM,EAAE,SAAS,IAAI;AACrB,YAAI,aAAa,2BAA2B,aAAa,wBAAwB;AAK/E;AAAA,QACF;AACA,gBAAQ,MAAM,wBAAwB,GAAG,IAAI,mBAAmB,cAAc,KAAK,KAAK,EAAE;AAC1F,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ACvGO,IAAM,aAAa;AAEnB,IAAM,eAAe,CAAC,UAAkB,MAAM,WAAW,KAAK,UAAU;AAExE,IAAM,iBAAiB,CAAC,UAAkB,MAAM,WAAW,YAAY,GAAG;","names":["assertEx","BaseMongoSdk","BaseMongoSdk","assertEx","assertEx","BaseMongoSdk","staticImplements","MongoDBStorageClassLabels","standardIndexes","assertEx","BaseMongoSdk","ensureIndexesExistOnCollection","MongoDBStorageClassLabels","staticImplements"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Module.d.ts","sourceRoot":"","sources":["../../src/Module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Module.d.ts","sourceRoot":"","sources":["../../src/Module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEhE,OAAO,EACU,mBAAmB,EAAuB,yBAAyB,EACnF,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAG9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAkB1D,eAAO,MAAM,kBAAkB,GAC7B,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,EACzD,OAAO,SAAS,iBAAiB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAEvE,YAAY,OAAO;sBAKC,YAAY,CAAC,yBAAyB,CAAC,GAAG,SAAS;iBACxD,YAAY,CAAC,oBAAoB,CAAC,GAAG,SAAS;oCAE9B,kBAAkB;;;+BAmBvB,kBAAkB;;IAe1C;;;OAGG;qBACoB,OAAO,CAAC,IAAI,CAAC;;;;;;;;sRAtDnB,CAAC,6DAAwB,CAAC;4RAMA,CAAC,6DAAwB,CAAC;;;;;;;;;;;;;;;YA4DxE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleV2.d.ts","sourceRoot":"","sources":["../../src/ModuleV2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModuleV2.d.ts","sourceRoot":"","sources":["../../src/ModuleV2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEhE,OAAO,EACL,qBAAqB,EAAwC,yBAAyB,EACvF,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAkB1D,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,EAC7D,OAAO,SAAS,iBAAiB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAEvE,YAAY,OAAO;iBAKJ,YAAY,CAAC,oBAAoB,CAAC,GAAG,SAAS;;+BAMnC,kBAAkB;;IAe1C;;;OAGG;qBACoB,OAAO,CAAC,IAAI,CAAC;;;;;;;;sRAtCM,CAAA,6DAI9C,CAAA;4RAEkE,CAAC,6DAErD,CAAA;;;;;;;;;;;;;;;YAuCb,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/merge.ts"],"names":[],"mappings":"AAKA,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CA6BvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/module-abstract-mongodb",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.15",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -37,19 +37,18 @@
|
|
|
37
37
|
"module": "dist/node/index.mjs",
|
|
38
38
|
"types": "dist/types/index.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@xylabs/assert": "^4.8.
|
|
41
|
-
"@xylabs/exists": "^4.8.
|
|
42
|
-
"@xylabs/
|
|
43
|
-
"@xylabs/
|
|
44
|
-
"@
|
|
45
|
-
"@xyo-network/module-model": "^3.14.
|
|
46
|
-
"@xyo-network/
|
|
47
|
-
"@xyo-network/payload-mongodb": "^3.14.14",
|
|
40
|
+
"@xylabs/assert": "^4.8.9",
|
|
41
|
+
"@xylabs/exists": "^4.8.9",
|
|
42
|
+
"@xylabs/mongo": "^4.8.9",
|
|
43
|
+
"@xylabs/static-implements": "^4.8.9",
|
|
44
|
+
"@xyo-network/module-model": "^3.14.15",
|
|
45
|
+
"@xyo-network/module-model-mongodb": "^3.14.15",
|
|
46
|
+
"@xyo-network/payload-mongodb": "^3.14.15",
|
|
48
47
|
"mongodb": "~6.13.1"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "^6.4.
|
|
52
|
-
"@xylabs/tsconfig": "^6.4.
|
|
50
|
+
"@xylabs/ts-scripts-yarn3": "^6.4.6",
|
|
51
|
+
"@xylabs/tsconfig": "^6.4.6",
|
|
53
52
|
"knip": "^5.50.5",
|
|
54
53
|
"tslib": "^2.8.1",
|
|
55
54
|
"typescript": "^5.8.3"
|
package/src/Module.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { merge } from '@xylabs/lodash'
|
|
3
2
|
import { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'
|
|
4
3
|
import { staticImplements } from '@xylabs/static-implements'
|
|
5
4
|
import {
|
|
@@ -12,6 +11,7 @@ import { AnyAbstractModule } from './AnyAbstractModule.ts'
|
|
|
12
11
|
import { COLLECTIONS } from './Collections.ts'
|
|
13
12
|
import { getBaseMongoSdkPrivateConfig } from './config/index.ts'
|
|
14
13
|
import { IndexDescription } from './IndexDescription.ts'
|
|
14
|
+
import { merge } from './merge.ts'
|
|
15
15
|
|
|
16
16
|
const standardIndexes: IndexDescription[] = [
|
|
17
17
|
{
|
package/src/ModuleV2.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { merge } from '@xylabs/lodash'
|
|
3
2
|
import { BaseMongoSdk, BaseMongoSdkConfig } from '@xylabs/mongo'
|
|
4
3
|
import { staticImplements } from '@xylabs/static-implements'
|
|
5
4
|
import {
|
|
@@ -12,6 +11,7 @@ import { AnyAbstractModule } from './AnyAbstractModule.ts'
|
|
|
12
11
|
import { COLLECTIONS } from './Collections.ts'
|
|
13
12
|
import { getBaseMongoSdkPrivateConfig } from './config/index.ts'
|
|
14
13
|
import { IndexDescription } from './IndexDescription.ts'
|
|
14
|
+
import { merge } from './merge.ts'
|
|
15
15
|
|
|
16
16
|
const standardIndexes: IndexDescription[] = [
|
|
17
17
|
{
|
package/src/merge.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
function isObject(val: unknown): val is Record<string, any> {
|
|
3
|
+
return val !== null && typeof val === 'object'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function merge<T extends object>(target: T, ...sources: any[]): T {
|
|
7
|
+
if (!isObject(target)) {
|
|
8
|
+
throw new TypeError('Target must be an object')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
for (const source of sources) {
|
|
12
|
+
if (!isObject(source)) {
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (const key of Object.keys(source)) {
|
|
17
|
+
const sourceVal = source[key]
|
|
18
|
+
const targetVal = (target as any)[key]
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(sourceVal)) {
|
|
21
|
+
// Arrays are replaced, not deeply merged (lodash behavior)
|
|
22
|
+
(target as any)[key] = [...sourceVal]
|
|
23
|
+
} else if (isObject(sourceVal)) {
|
|
24
|
+
if (!isObject(targetVal)) {
|
|
25
|
+
(target as any)[key] = {}
|
|
26
|
+
}
|
|
27
|
+
merge((target as any)[key], sourceVal)
|
|
28
|
+
} else {
|
|
29
|
+
(target as any)[key] = sourceVal
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return target
|
|
35
|
+
}
|