@unchainedshop/mongodb 3.1.11 → 4.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build-db-indexes.d.ts +2 -2
- package/lib/build-db-indexes.d.ts.map +1 -1
- package/lib/build-db-indexes.js +4 -1
- package/lib/build-db-indexes.js.map +1 -1
- package/lib/build-sort-option.d.ts +1 -1
- package/lib/build-sort-option.d.ts.map +1 -1
- package/lib/build-sort-option.js.map +1 -1
- package/lib/documentdb-compat-mode.d.ts +3 -0
- package/lib/documentdb-compat-mode.d.ts.map +1 -0
- package/lib/documentdb-compat-mode.js +6 -0
- package/lib/documentdb-compat-mode.js.map +1 -0
- package/lib/find-preserving-ids.d.ts +1 -1
- package/lib/find-preserving-ids.d.ts.map +1 -1
- package/lib/find-preserving-ids.js.map +1 -1
- package/lib/initDb.d.ts.map +1 -1
- package/lib/initDb.js +8 -6
- package/lib/initDb.js.map +1 -1
- package/lib/mongodb-index.d.ts +8 -7
- package/lib/mongodb-index.d.ts.map +1 -1
- package/lib/mongodb-index.js +1 -0
- package/lib/mongodb-index.js.map +1 -1
- package/package.json +4 -4
- package/src/build-db-indexes.ts +6 -4
- package/src/build-sort-option.ts +1 -1
- package/src/documentdb-compat-mode.ts +6 -0
- package/src/find-preserving-ids.ts +3 -3
- package/src/initDb.ts +9 -6
- package/src/mongodb-index.ts +8 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Collection, Document, CreateIndexesOptions, IndexSpecification } from 'mongodb';
|
|
2
|
-
export type Indexes =
|
|
2
|
+
export type Indexes = {
|
|
3
3
|
index: IndexSpecification;
|
|
4
4
|
options?: CreateIndexesOptions;
|
|
5
|
-
}
|
|
5
|
+
}[];
|
|
6
6
|
export declare const buildDbIndexes: <T extends Document>(collection: Collection<T>, indexes: Indexes) => Promise<boolean>;
|
|
7
7
|
//# sourceMappingURL=build-db-indexes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-db-indexes.d.ts","sourceRoot":"","sources":["../src/build-db-indexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKzF,MAAM,MAAM,OAAO,GAAG
|
|
1
|
+
{"version":3,"file":"build-db-indexes.d.ts","sourceRoot":"","sources":["../src/build-db-indexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKzF,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,EAAE,CAAC;AAiBJ,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,QAAQ,EACrD,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,SAAS,OAAO,qBAwBjB,CAAC"}
|
package/lib/build-db-indexes.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
2
|
const logger = createLogger('unchained:mongodb');
|
|
3
|
-
const buildIndexes = (collection, indexes) => Promise.all(indexes.map(async (
|
|
3
|
+
const buildIndexes = (collection, indexes) => Promise.all(indexes.map(async (indexOptions) => {
|
|
4
|
+
if (!indexOptions)
|
|
5
|
+
return;
|
|
6
|
+
const { index, options } = indexOptions;
|
|
4
7
|
try {
|
|
5
8
|
await collection.createIndex(index, options);
|
|
6
9
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-db-indexes.js","sourceRoot":"","sources":["../src/build-db-indexes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAOjD,MAAM,YAAY,GAAG,CAA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ACzB,MAAM,CAAC,KAAK,CAAC,mCAAmC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC;YAC7E,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAC5B,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QACD,IAAI;IACN,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortOption } from '@unchainedshop/utils';
|
|
2
2
|
import { Sort } from 'mongodb';
|
|
3
|
-
export declare const buildSortOptions: (sort?:
|
|
3
|
+
export declare const buildSortOptions: (sort?: SortOption[]) => Sort;
|
|
4
4
|
export default buildSortOptions;
|
|
5
5
|
//# sourceMappingURL=build-sort-option.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-sort-option.d.ts","sourceRoot":"","sources":["../src/build-sort-option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,eAAO,MAAM,gBAAgB,GAAI,OAAM,
|
|
1
|
+
{"version":3,"file":"build-sort-option.d.ts","sourceRoot":"","sources":["../src/build-sort-option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAO/B,eAAO,MAAM,gBAAgB,GAAI,OAAM,UAAU,EAAO,KAAG,IAM1D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-sort-option.js","sourceRoot":"","sources":["../src/build-sort-option.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"build-sort-option.js","sourceRoot":"","sources":["../src/build-sort-option.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAqB,EAAE,EAAQ,EAAE;IAChE,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;QAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentdb-compat-mode.d.ts","sourceRoot":"","sources":["../src/documentdb-compat-mode.ts"],"names":[],"mappings":"AAAA,wBAAgB,0BAA0B,SAGzC;AAED,eAAO,MAAM,6BAA6B,eAA8D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function assertDocumentDBCompatMode() {
|
|
2
|
+
if (isDocumentDBCompatModeEnabled())
|
|
3
|
+
throw new Error('Text search is not supported in DocumentDB Compatibility Mode');
|
|
4
|
+
}
|
|
5
|
+
export const isDocumentDBCompatModeEnabled = () => Boolean(process.env.UNCHAINED_DOCUMENTDB_COMPAT_MODE);
|
|
6
|
+
//# sourceMappingURL=documentdb-compat-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentdb-compat-mode.js","sourceRoot":"","sources":["../src/documentdb-compat-mode.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,0BAA0B;IACxC,IAAI,6BAA6B,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Collection, FindOptions, Filter } from 'mongodb';
|
|
2
|
-
export declare const findPreservingIds: <T>(collection: Collection<T>) => ((selector: Filter<T>, ids:
|
|
2
|
+
export declare const findPreservingIds: <T>(collection: Collection<T>) => ((selector: Filter<T>, ids: string[], options?: FindOptions) => Promise<T[]>);
|
|
3
3
|
//# sourceMappingURL=find-preserving-ids.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-preserving-ids.d.ts","sourceRoot":"","sources":["../src/find-preserving-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAQ1D,eAAO,MAAM,iBAAiB,GAC3B,CAAC,EACA,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"find-preserving-ids.d.ts","sourceRoot":"","sources":["../src/find-preserving-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAQ1D,eAAO,MAAM,iBAAiB,GAC3B,CAAC,EACA,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CA0B9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-preserving-ids.js","sourceRoot":"","sources":["../src/find-preserving-ids.ts"],"names":[],"mappings":"AAEA,MAA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CAAC"}
|
package/lib/initDb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.d.ts","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAe1C,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"initDb.d.ts","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAe1C,eAAO,MAAM,OAAO,uBA8BnB,CAAC;AAEF,eAAO,MAAM,MAAM,qBAIlB,CAAC;AAEF,QAAA,MAAM,MAAM,QAAa,OAAO,CAAC,EAAE,CAQlC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/initDb.js
CHANGED
|
@@ -21,11 +21,13 @@ export const startDb = async () => {
|
|
|
21
21
|
/* */
|
|
22
22
|
}
|
|
23
23
|
mongod = MongoMemoryServer.create({
|
|
24
|
-
instance:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
instance: process.env.NODE_ENV === 'test'
|
|
25
|
+
? { dbName: 'test', port: parseInt(process.env.PORT, 10) + 1 }
|
|
26
|
+
: {
|
|
27
|
+
dbPath: `${process.cwd()}/.db`,
|
|
28
|
+
storageEngine: 'wiredTiger',
|
|
29
|
+
port: parseInt(process.env.PORT, 10) + 1,
|
|
30
|
+
},
|
|
29
31
|
}).catch((e) => {
|
|
30
32
|
console.log(e);
|
|
31
33
|
// Drop error
|
|
@@ -35,7 +37,7 @@ export const startDb = async () => {
|
|
|
35
37
|
if (!mongoInstance) {
|
|
36
38
|
throw new Error("Can't connect to MongoDB: could not start mongodb-memory-server and MONGO_URL env is not set");
|
|
37
39
|
}
|
|
38
|
-
return `${mongoInstance.getUri()}unchained`;
|
|
40
|
+
return `${mongoInstance.getUri()}${process.env.NODE_ENV === 'test' ? 'test' : 'unchained'}`;
|
|
39
41
|
};
|
|
40
42
|
export const stopDb = async () => {
|
|
41
43
|
await mongoClient?.close();
|
package/lib/initDb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.js","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,MAAM,CAAC;AACX,IAAI,WAA+B,CAAC;AAEpC,IAAI,CAAC;IACH,2BAA2B;IAC3B,mBAAmB;IACnB,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACjC,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAAC,MAAM,CAAC;IACP,KAAK;AACP,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;IAChC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACnD,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,KAAK;IACP,CAAC;IACD,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;QAChC,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"initDb.js","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,MAAM,CAAC;AACX,IAAI,WAA+B,CAAC;AAEpC,IAAI,CAAC;IACH,2BAA2B;IAC3B,mBAAmB;IACnB,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACjC,WAAW,GAAG,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AC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC9F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;IAC/B,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC;IAC3B,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC;IACnC,MAAO,aAAqB,EAAE,IAAI,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,KAAK,IAAiB,EAAE;IACrC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC;IACvD,WAAW,GAAG,IAAI,WAAW,CAAC,GAAG,EAAE;QACjC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KAC9C,CAAC,CAAC;IACH,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAC5B,MAAM,EAAE,GAAG,WAAW,CAAC,EAAE,EAAE,CAAC;IAC5B,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/mongodb-index.d.ts
CHANGED
|
@@ -7,19 +7,20 @@ export { findPreservingIds } from './find-preserving-ids.js';
|
|
|
7
7
|
export { buildSortOptions } from './build-sort-option.js';
|
|
8
8
|
export { findLocalizedText } from './find-localized-text.js';
|
|
9
9
|
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
10
|
+
export * from './documentdb-compat-mode.js';
|
|
10
11
|
export { mongodb };
|
|
11
|
-
export
|
|
12
|
-
log:
|
|
12
|
+
export interface LogFields {
|
|
13
|
+
log: {
|
|
13
14
|
date: Date;
|
|
14
15
|
status?: string;
|
|
15
16
|
info: string;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
export interface TimestampFields {
|
|
19
20
|
created?: Date;
|
|
20
21
|
updated?: Date;
|
|
21
22
|
deleted?: Date;
|
|
22
|
-
}
|
|
23
|
+
}
|
|
23
24
|
export interface Address {
|
|
24
25
|
addressLine?: string;
|
|
25
26
|
addressLine2?: string;
|
|
@@ -47,7 +48,7 @@ export interface MigrationRepository<Context = unknown> {
|
|
|
47
48
|
db: mongodb.Db;
|
|
48
49
|
migrations: Map<number, Migration<Context>>;
|
|
49
50
|
register: (migration: Migration<Context>) => void;
|
|
50
|
-
allMigrations: () =>
|
|
51
|
+
allMigrations: () => Migration<Context>[];
|
|
51
52
|
}
|
|
52
53
|
export interface ModuleInput<Options extends Record<string, any>> {
|
|
53
54
|
db: mongodb.Db;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-index.d.ts","sourceRoot":"","sources":["../src/mongodb-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAMtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"mongodb-index.d.ts","sourceRoot":"","sources":["../src/mongodb-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM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AO,GAAG,OAAO;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC;QAAC,YAAY,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,mBAAmB,CAAC,OAAO,GAAG,OAAO;IACpD,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;IACf,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5C,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAClD,aAAa,EAAE,MAAM,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC9D,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;IACf,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
package/lib/mongodb-index.js
CHANGED
|
@@ -10,5 +10,6 @@ export { findPreservingIds } from './find-preserving-ids.js';
|
|
|
10
10
|
export { buildSortOptions } from './build-sort-option.js';
|
|
11
11
|
export { findLocalizedText } from './find-localized-text.js';
|
|
12
12
|
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
13
|
+
export * from './documentdb-compat-mode.js';
|
|
13
14
|
export { mongodb };
|
|
14
15
|
//# sourceMappingURL=mongodb-index.js.map
|
package/lib/mongodb-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-index.js","sourceRoot":"","sources":["../src/mongodb-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEtD;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"mongodb-index.js","sourceRoot":"","sources":["../src/mongodb-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEtD;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/mongodb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "MongoDB provider for unchained platform",
|
|
5
5
|
"main": "lib/mongodb-index.js",
|
|
6
6
|
"types": "lib/mongodb-index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/utils": "^
|
|
34
|
+
"@unchainedshop/utils": "^4.0.0-rc.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mongodb-js/zstd": ">= 2.0 < 3",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^22.
|
|
54
|
-
"typescript": "^5.8.
|
|
53
|
+
"@types/node": "^22.15.3",
|
|
54
|
+
"typescript": "^5.8.3"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/build-db-indexes.ts
CHANGED
|
@@ -3,14 +3,16 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
|
|
4
4
|
const logger = createLogger('unchained:mongodb');
|
|
5
5
|
|
|
6
|
-
export type Indexes =
|
|
6
|
+
export type Indexes = {
|
|
7
7
|
index: IndexSpecification;
|
|
8
8
|
options?: CreateIndexesOptions;
|
|
9
|
-
}
|
|
9
|
+
}[];
|
|
10
10
|
|
|
11
|
-
const buildIndexes = <T>(collection: Collection<T>, indexes: Indexes): Promise<
|
|
11
|
+
const buildIndexes = <T>(collection: Collection<T>, indexes: Indexes): Promise<(false | Error)[]> =>
|
|
12
12
|
Promise.all(
|
|
13
|
-
indexes.map(async (
|
|
13
|
+
indexes.map(async (indexOptions) => {
|
|
14
|
+
if (!indexOptions) return;
|
|
15
|
+
const { index, options } = indexOptions;
|
|
14
16
|
try {
|
|
15
17
|
await collection.createIndex(index, options);
|
|
16
18
|
return false;
|
package/src/build-sort-option.ts
CHANGED
|
@@ -6,7 +6,7 @@ const SORT_DIRECTIONS = {
|
|
|
6
6
|
DESC: -1,
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const buildSortOptions = (sort:
|
|
9
|
+
export const buildSortOptions = (sort: SortOption[] = []): Sort => {
|
|
10
10
|
const sortBy = {};
|
|
11
11
|
sort?.forEach(({ key, value }) => {
|
|
12
12
|
sortBy[key] = SORT_DIRECTIONS[value];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function assertDocumentDBCompatMode() {
|
|
2
|
+
if (isDocumentDBCompatModeEnabled())
|
|
3
|
+
throw new Error('Text search is not supported in DocumentDB Compatibility Mode');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const isDocumentDBCompatModeEnabled = () => Boolean(process.env.UNCHAINED_DOCUMENTDB_COMPAT_MODE);
|
|
@@ -9,8 +9,8 @@ const defaultSort = sortByIndex;
|
|
|
9
9
|
export const findPreservingIds =
|
|
10
10
|
<T>(
|
|
11
11
|
collection: Collection<T>,
|
|
12
|
-
): ((selector: Filter<T>, ids:
|
|
13
|
-
async (selector: Filter<T>, ids:
|
|
12
|
+
): ((selector: Filter<T>, ids: string[], options?: FindOptions) => Promise<T[]>) =>
|
|
13
|
+
async (selector: Filter<T>, ids: string[], options?: FindOptions): Promise<T[]> => {
|
|
14
14
|
const { skip, limit, sort = defaultSort } = options || {};
|
|
15
15
|
const filteredSelector = {
|
|
16
16
|
...selector,
|
|
@@ -34,5 +34,5 @@ export const findPreservingIds =
|
|
|
34
34
|
|
|
35
35
|
const aggregationPointer = collection.aggregate(filteredPipeline);
|
|
36
36
|
const items = await aggregationPointer.toArray();
|
|
37
|
-
return items as
|
|
37
|
+
return items as T[];
|
|
38
38
|
};
|
package/src/initDb.ts
CHANGED
|
@@ -22,11 +22,14 @@ export const startDb = async () => {
|
|
|
22
22
|
/* */
|
|
23
23
|
}
|
|
24
24
|
mongod = MongoMemoryServer.create({
|
|
25
|
-
instance:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
instance:
|
|
26
|
+
process.env.NODE_ENV === 'test'
|
|
27
|
+
? { dbName: 'test', port: parseInt(process.env.PORT, 10) + 1 }
|
|
28
|
+
: {
|
|
29
|
+
dbPath: `${process.cwd()}/.db`,
|
|
30
|
+
storageEngine: 'wiredTiger',
|
|
31
|
+
port: parseInt(process.env.PORT, 10) + 1,
|
|
32
|
+
},
|
|
30
33
|
}).catch((e) => {
|
|
31
34
|
console.log(e);
|
|
32
35
|
// Drop error
|
|
@@ -39,7 +42,7 @@ export const startDb = async () => {
|
|
|
39
42
|
"Can't connect to MongoDB: could not start mongodb-memory-server and MONGO_URL env is not set",
|
|
40
43
|
);
|
|
41
44
|
}
|
|
42
|
-
return `${mongoInstance.getUri()}unchained`;
|
|
45
|
+
return `${mongoInstance.getUri()}${process.env.NODE_ENV === 'test' ? 'test' : 'unchained'}`;
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
export const stopDb = async () => {
|
package/src/mongodb-index.ts
CHANGED
|
@@ -13,22 +13,23 @@ export { findPreservingIds } from './find-preserving-ids.js';
|
|
|
13
13
|
export { buildSortOptions } from './build-sort-option.js';
|
|
14
14
|
export { findLocalizedText } from './find-localized-text.js';
|
|
15
15
|
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
16
|
+
export * from './documentdb-compat-mode.js';
|
|
16
17
|
|
|
17
18
|
export { mongodb };
|
|
18
19
|
|
|
19
|
-
export
|
|
20
|
-
log:
|
|
20
|
+
export interface LogFields {
|
|
21
|
+
log: {
|
|
21
22
|
date: Date;
|
|
22
23
|
status?: string;
|
|
23
24
|
info: string;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
26
27
|
|
|
27
|
-
export
|
|
28
|
+
export interface TimestampFields {
|
|
28
29
|
created?: Date;
|
|
29
30
|
updated?: Date;
|
|
30
31
|
deleted?: Date;
|
|
31
|
-
}
|
|
32
|
+
}
|
|
32
33
|
|
|
33
34
|
export interface Address {
|
|
34
35
|
addressLine?: string;
|
|
@@ -57,7 +58,7 @@ export interface MigrationRepository<Context = unknown> {
|
|
|
57
58
|
db: mongodb.Db;
|
|
58
59
|
migrations: Map<number, Migration<Context>>;
|
|
59
60
|
register: (migration: Migration<Context>) => void;
|
|
60
|
-
allMigrations: () =>
|
|
61
|
+
allMigrations: () => Migration<Context>[];
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export interface ModuleInput<Options extends Record<string, any>> {
|