@unchainedshop/mongodb 4.3.3 → 4.4.0
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/README.md +88 -2
- package/lib/build-db-indexes.d.ts +1 -2
- package/lib/build-db-indexes.js +0 -2
- package/lib/build-sort-option.d.ts +2 -3
- package/lib/build-sort-option.js +0 -1
- package/lib/documentdb-compat-mode.d.ts +0 -1
- package/lib/documentdb-compat-mode.js +0 -1
- package/lib/find-localized-text.d.ts +1 -2
- package/lib/find-localized-text.js +0 -1
- package/lib/find-preserving-ids.d.ts +1 -2
- package/lib/find-preserving-ids.js +0 -1
- package/lib/generate-db-filter-by-id.d.ts +1 -2
- package/lib/generate-db-filter-by-id.js +1 -2
- package/lib/generate-db-object-id.d.ts +0 -1
- package/lib/generate-db-object-id.js +0 -7
- package/lib/initDb.d.ts +1 -2
- package/lib/initDb.js +0 -7
- package/lib/insensitive-trimmed-regex-operator.d.ts +0 -1
- package/lib/insensitive-trimmed-regex-operator.js +0 -1
- package/lib/mongodb-index.d.ts +9 -16
- package/lib/mongodb-index.js +9 -13
- package/package.json +9 -7
- package/lib/build-db-indexes.d.ts.map +0 -1
- package/lib/build-db-indexes.js.map +0 -1
- package/lib/build-sort-option.d.ts.map +0 -1
- package/lib/build-sort-option.js.map +0 -1
- package/lib/check-id.d.ts +0 -5
- package/lib/check-id.d.ts.map +0 -1
- package/lib/check-id.js +0 -6
- package/lib/check-id.js.map +0 -1
- package/lib/documentdb-compat-mode.d.ts.map +0 -1
- package/lib/documentdb-compat-mode.js.map +0 -1
- package/lib/email-regex-operator.d.ts +0 -4
- package/lib/email-regex-operator.d.ts.map +0 -1
- package/lib/email-regex-operator.js +0 -12
- package/lib/email-regex-operator.js.map +0 -1
- package/lib/find-localized-text.d.ts.map +0 -1
- package/lib/find-localized-text.js.map +0 -1
- package/lib/find-preserving-ids.d.ts.map +0 -1
- package/lib/find-preserving-ids.js.map +0 -1
- package/lib/generate-db-filter-by-id.d.ts.map +0 -1
- package/lib/generate-db-filter-by-id.js.map +0 -1
- package/lib/generate-db-mutations.d.ts +0 -11
- package/lib/generate-db-mutations.d.ts.map +0 -1
- package/lib/generate-db-mutations.js +0 -73
- package/lib/generate-db-mutations.js.map +0 -1
- package/lib/generate-db-object-id.d.ts.map +0 -1
- package/lib/generate-db-object-id.js.map +0 -1
- package/lib/initDb.d.ts.map +0 -1
- package/lib/initDb.js.map +0 -1
- package/lib/insensitive-trimmed-regex-operator.d.ts.map +0 -1
- package/lib/insensitive-trimmed-regex-operator.js.map +0 -1
- package/lib/mongodb-index.d.ts.map +0 -1
- package/lib/mongodb-index.js.map +0 -1
- package/src/build-db-indexes.ts +0 -60
- package/src/build-sort-option.ts +0 -17
- package/src/documentdb-compat-mode.ts +0 -6
- package/src/find-localized-text.ts +0 -41
- package/src/find-preserving-ids.ts +0 -38
- package/src/generate-db-filter-by-id.ts +0 -9
- package/src/generate-db-object-id.ts +0 -16
- package/src/initDb.ts +0 -69
- package/src/insensitive-trimmed-regex-operator.test.ts +0 -77
- package/src/insensitive-trimmed-regex-operator.ts +0 -11
- package/src/mongodb-index.test.ts +0 -40
- package/src/mongodb-index.ts +0 -81
- package/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://npmjs.com/package/@unchainedshop/mongodb)
|
|
2
|
+
[](https://opensource.org/licenses/EUPL-1.2)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# @unchainedshop/mongodb
|
|
5
|
+
|
|
6
|
+
MongoDB database abstraction layer for the Unchained Engine.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @unchainedshop/mongodb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { initDb, startDb, stopDb, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
18
|
+
|
|
19
|
+
// Initialize the database connection
|
|
20
|
+
const db = await initDb({
|
|
21
|
+
connectionString: 'mongodb://localhost:27017/unchained',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Start the database
|
|
25
|
+
await startDb(db);
|
|
26
|
+
|
|
27
|
+
// Generate a new ObjectId
|
|
28
|
+
const id = generateDbObjectId();
|
|
29
|
+
|
|
30
|
+
// Stop the database when shutting down
|
|
31
|
+
await stopDb(db);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Overview
|
|
35
|
+
|
|
36
|
+
### Database Lifecycle
|
|
37
|
+
|
|
38
|
+
| Export | Description |
|
|
39
|
+
|--------|-------------|
|
|
40
|
+
| `initDb` | Initialize MongoDB connection with connection string |
|
|
41
|
+
| `startDb` | Start the database connection |
|
|
42
|
+
| `stopDb` | Close the database connection |
|
|
43
|
+
|
|
44
|
+
### Query Utilities
|
|
45
|
+
|
|
46
|
+
| Export | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `generateDbObjectId` | Generate a new MongoDB ObjectId |
|
|
49
|
+
| `generateDbFilterById` | Create a filter object for querying by ID |
|
|
50
|
+
| `buildDbIndexes` | Create indexes for a collection |
|
|
51
|
+
| `findPreservingIds` | Find documents while preserving ID order |
|
|
52
|
+
| `buildSortOptions` | Build MongoDB sort options from SortOption array |
|
|
53
|
+
| `findLocalizedText` | Find localized text by locale with fallback |
|
|
54
|
+
| `insensitiveTrimmedRegexOperator` | Create case-insensitive trimmed regex for text search |
|
|
55
|
+
|
|
56
|
+
### DocumentDB Compatibility
|
|
57
|
+
|
|
58
|
+
| Export | Description |
|
|
59
|
+
|--------|-------------|
|
|
60
|
+
| `isDocumentDBCompatModeEnabled` | Check if AWS DocumentDB compatibility mode is enabled |
|
|
61
|
+
| `assertDocumentDBCompatMode` | Throw error if DocumentDB compat mode is enabled (for unsupported operations) |
|
|
62
|
+
|
|
63
|
+
### Re-exports
|
|
64
|
+
|
|
65
|
+
| Export | Description |
|
|
66
|
+
|--------|-------------|
|
|
67
|
+
| `mongodb` | Re-exported mongodb driver for direct access |
|
|
68
|
+
|
|
69
|
+
### Types
|
|
70
|
+
|
|
71
|
+
| Export | Description |
|
|
72
|
+
|--------|-------------|
|
|
73
|
+
| `LogFields` | Interface for document log entries |
|
|
74
|
+
| `TimestampFields` | Interface for created/updated/deleted timestamps |
|
|
75
|
+
| `Address` | Interface for postal address data |
|
|
76
|
+
| `Contact` | Interface for contact information |
|
|
77
|
+
| `Migration` | Interface for database migrations |
|
|
78
|
+
| `MigrationRepository` | Interface for managing migrations |
|
|
79
|
+
| `ModuleInput` | Interface for core module initialization input |
|
|
80
|
+
|
|
81
|
+
## Environment Variables
|
|
82
|
+
|
|
83
|
+
| Variable | Description |
|
|
84
|
+
|----------|-------------|
|
|
85
|
+
| `UNCHAINED_DOCUMENTDB_COMPAT_MODE` | Enable AWS DocumentDB compatibility mode |
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
EUPL-1.2
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, Document, CreateIndexesOptions, IndexSpecification } from 'mongodb';
|
|
1
|
+
import type { Collection, Document, CreateIndexesOptions, IndexSpecification } from 'mongodb';
|
|
2
2
|
export type Indexes = {
|
|
3
3
|
index: IndexSpecification;
|
|
4
4
|
options?: CreateIndexesOptions;
|
|
@@ -6,4 +6,3 @@ export type Indexes = {
|
|
|
6
6
|
export declare const buildDbIndexes: <T extends Document>(collection: Collection<T>, indexes: Indexes, { rebuild }?: {
|
|
7
7
|
rebuild?: boolean;
|
|
8
8
|
}) => Promise<boolean>;
|
|
9
|
-
//# sourceMappingURL=build-db-indexes.d.ts.map
|
package/lib/build-db-indexes.js
CHANGED
|
@@ -25,7 +25,6 @@ export const buildDbIndexes = async (collection, indexes, { rebuild } = {}) => {
|
|
|
25
25
|
await collection.dropIndexes();
|
|
26
26
|
}
|
|
27
27
|
catch {
|
|
28
|
-
/* */
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
const rebuildErrors = (await buildIndexes(collection, indexes)).filter(Boolean);
|
|
@@ -37,4 +36,3 @@ export const buildDbIndexes = async (collection, indexes, { rebuild } = {}) => {
|
|
|
37
36
|
}
|
|
38
37
|
return success;
|
|
39
38
|
};
|
|
40
|
-
//# sourceMappingURL=build-db-indexes.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SortOption } from '@unchainedshop/utils';
|
|
2
|
-
import { Sort } from 'mongodb';
|
|
1
|
+
import type { SortOption } from '@unchainedshop/utils';
|
|
2
|
+
import type { Sort } from 'mongodb';
|
|
3
3
|
export declare const buildSortOptions: (sort?: SortOption[]) => Sort;
|
|
4
4
|
export default buildSortOptions;
|
|
5
|
-
//# sourceMappingURL=build-sort-option.d.ts.map
|
package/lib/build-sort-option.js
CHANGED
|
@@ -3,4 +3,3 @@ export function assertDocumentDBCompatMode() {
|
|
|
3
3
|
throw new Error('Text search is not supported in DocumentDB Compatibility Mode');
|
|
4
4
|
}
|
|
5
5
|
export const isDocumentDBCompatModeEnabled = () => Boolean(process.env.UNCHAINED_DOCUMENTDB_COMPAT_MODE);
|
|
6
|
-
//# sourceMappingURL=documentdb-compat-mode.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Collection, Document, Filter } from 'mongodb';
|
|
1
|
+
import type { Collection, Document, Filter } from 'mongodb';
|
|
2
2
|
export declare const findLocalizedText: <T extends Document>(collection: Collection<T>, selector: Filter<T>, locale: Intl.Locale) => Promise<T>;
|
|
3
3
|
export default findLocalizedText;
|
|
4
|
-
//# sourceMappingURL=find-localized-text.d.ts.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Collection, FindOptions, Filter, Document } from 'mongodb';
|
|
1
|
+
import type { Collection, FindOptions, Filter, Document } from 'mongodb';
|
|
2
2
|
export declare const findPreservingIds: <T extends Document>(collection: Collection<T>) => ((selector: Filter<T>, ids: string[], options?: FindOptions) => Promise<T[]>);
|
|
3
|
-
//# sourceMappingURL=find-preserving-ids.d.ts.map
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name Random.hexString
|
|
3
|
-
* @summary Return a random string of `n` hexadecimal digits.
|
|
4
|
-
* @locus Anywhere
|
|
5
|
-
* @param {Number} n Length of the string
|
|
6
|
-
*/
|
|
7
1
|
function toHex(buffer) {
|
|
8
2
|
return Array.prototype.map.call(buffer, (x) => x.toString(16).padStart(2, '0')).join('');
|
|
9
3
|
}
|
|
@@ -13,4 +7,3 @@ export const generateDbObjectId = (digits = 24) => {
|
|
|
13
7
|
const result = toHex(bytes);
|
|
14
8
|
return result.substring(0, digits);
|
|
15
9
|
};
|
|
16
|
-
//# sourceMappingURL=generate-db-object-id.js.map
|
package/lib/initDb.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Db } from 'mongodb';
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
2
|
export declare const startDb: () => Promise<string>;
|
|
3
3
|
export declare const stopDb: () => Promise<void>;
|
|
4
4
|
declare const initDb: () => Promise<Db>;
|
|
5
5
|
export { initDb };
|
|
6
|
-
//# sourceMappingURL=initDb.d.ts.map
|
package/lib/initDb.js
CHANGED
|
@@ -4,13 +4,10 @@ let mongod;
|
|
|
4
4
|
let mongoClient;
|
|
5
5
|
const { PORT = '4010' } = process.env;
|
|
6
6
|
try {
|
|
7
|
-
// eslint-disable-next-line
|
|
8
|
-
// @ts-expect-error
|
|
9
7
|
await import('@mongodb-js/zstd');
|
|
10
8
|
zstdEnabled = true;
|
|
11
9
|
}
|
|
12
10
|
catch {
|
|
13
|
-
/* */
|
|
14
11
|
}
|
|
15
12
|
export const startDb = async () => {
|
|
16
13
|
const { mkdir } = await import('node:fs/promises');
|
|
@@ -19,7 +16,6 @@ export const startDb = async () => {
|
|
|
19
16
|
await mkdir(`${process.cwd()}/.db`);
|
|
20
17
|
}
|
|
21
18
|
catch {
|
|
22
|
-
/* */
|
|
23
19
|
}
|
|
24
20
|
try {
|
|
25
21
|
mongod = MongoMemoryServer.create({
|
|
@@ -37,7 +33,6 @@ export const startDb = async () => {
|
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
catch {
|
|
40
|
-
/* */
|
|
41
36
|
}
|
|
42
37
|
throw new Error("Can't connect to MongoDB: Could not start mongodb-memory-server and MONGO_URL env is not set");
|
|
43
38
|
};
|
|
@@ -47,7 +42,6 @@ export const stopDb = async () => {
|
|
|
47
42
|
await (await mongod)?.stop();
|
|
48
43
|
}
|
|
49
44
|
catch {
|
|
50
|
-
/* */
|
|
51
45
|
}
|
|
52
46
|
};
|
|
53
47
|
const initDb = async () => {
|
|
@@ -60,4 +54,3 @@ const initDb = async () => {
|
|
|
60
54
|
return db;
|
|
61
55
|
};
|
|
62
56
|
export { initDb };
|
|
63
|
-
//# sourceMappingURL=initDb.js.map
|
package/lib/mongodb-index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as mongodb from 'mongodb';
|
|
2
|
-
export { initDb, startDb, stopDb } from './initDb.
|
|
3
|
-
export { generateDbObjectId } from './generate-db-object-id.
|
|
4
|
-
export { generateDbFilterById } from './generate-db-filter-by-id.
|
|
5
|
-
export { buildDbIndexes } from './build-db-indexes.
|
|
6
|
-
export { findPreservingIds } from './find-preserving-ids.
|
|
7
|
-
export { buildSortOptions } from './build-sort-option.
|
|
8
|
-
export { findLocalizedText } from './find-localized-text.
|
|
9
|
-
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.
|
|
10
|
-
export * from './documentdb-compat-mode.
|
|
2
|
+
export { initDb, startDb, stopDb } from './initDb.ts';
|
|
3
|
+
export { generateDbObjectId } from './generate-db-object-id.ts';
|
|
4
|
+
export { generateDbFilterById } from './generate-db-filter-by-id.ts';
|
|
5
|
+
export { buildDbIndexes } from './build-db-indexes.ts';
|
|
6
|
+
export { findPreservingIds } from './find-preserving-ids.ts';
|
|
7
|
+
export { buildSortOptions } from './build-sort-option.ts';
|
|
8
|
+
export { findLocalizedText } from './find-localized-text.ts';
|
|
9
|
+
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.ts';
|
|
10
|
+
export * from './documentdb-compat-mode.ts';
|
|
11
11
|
export { mongodb };
|
|
12
12
|
export interface LogFields {
|
|
13
13
|
log: ({
|
|
@@ -41,12 +41,6 @@ export interface Contact {
|
|
|
41
41
|
emailAddress?: string;
|
|
42
42
|
}
|
|
43
43
|
export interface Migration<Context = unknown> {
|
|
44
|
-
/**
|
|
45
|
-
* Migration ID must be between 19700000000000 and 99999999999999
|
|
46
|
-
* YYYYMMDDHHMMSS format is recommended.
|
|
47
|
-
* @minimum 19700000000000
|
|
48
|
-
* @maximum 99999999999999
|
|
49
|
-
*/
|
|
50
44
|
id: number;
|
|
51
45
|
name: string;
|
|
52
46
|
up: (params: {
|
|
@@ -65,4 +59,3 @@ export interface ModuleInput<Options extends Record<string, any>> {
|
|
|
65
59
|
migrationRepository: MigrationRepository;
|
|
66
60
|
options?: Options;
|
|
67
61
|
}
|
|
68
|
-
//# sourceMappingURL=mongodb-index.d.ts.map
|
package/lib/mongodb-index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import * as mongodb from 'mongodb';
|
|
2
|
-
export { initDb, startDb, stopDb } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
export { findLocalizedText } from './find-localized-text.js';
|
|
12
|
-
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
13
|
-
export * from './documentdb-compat-mode.js';
|
|
2
|
+
export { initDb, startDb, stopDb } from "./initDb.js";
|
|
3
|
+
export { generateDbObjectId } from "./generate-db-object-id.js";
|
|
4
|
+
export { generateDbFilterById } from "./generate-db-filter-by-id.js";
|
|
5
|
+
export { buildDbIndexes } from "./build-db-indexes.js";
|
|
6
|
+
export { findPreservingIds } from "./find-preserving-ids.js";
|
|
7
|
+
export { buildSortOptions } from "./build-sort-option.js";
|
|
8
|
+
export { findLocalizedText } from "./find-localized-text.js";
|
|
9
|
+
export { insensitiveTrimmedRegexOperator } from "./insensitive-trimmed-regex-operator.js";
|
|
10
|
+
export * from "./documentdb-compat-mode.js";
|
|
14
11
|
export { mongodb };
|
|
15
|
-
//# sourceMappingURL=mongodb-index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/mongodb",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "MongoDB provider for unchained platform",
|
|
5
5
|
"main": "lib/mongodb-index.js",
|
|
6
6
|
"types": "lib/mongodb-index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"build": "tsc -b",
|
|
11
11
|
"prepublishOnly": "npm run clean && npm run build",
|
|
12
12
|
"watch": "tsc -w",
|
|
13
|
-
"test": "
|
|
14
|
-
"test:watch": "
|
|
13
|
+
"test": "node --test",
|
|
14
|
+
"test:watch": "node --test --watch"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
"ecommerce"
|
|
23
23
|
],
|
|
24
24
|
"authors": [
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"Pascal Kaufmann",
|
|
26
|
+
"Mikael Araya",
|
|
27
|
+
"Vedran Rudelj",
|
|
28
|
+
"Joël Meiller"
|
|
27
29
|
],
|
|
28
30
|
"license": "EUPL-1.2",
|
|
29
31
|
"bugs": {
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
},
|
|
32
34
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/utils": "^4.
|
|
36
|
+
"@unchainedshop/utils": "^4.4.0"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
39
|
"@mongodb-js/zstd": ">= 2 < 8",
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
}
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^
|
|
55
|
+
"@types/node": "^25.0.0",
|
|
54
56
|
"typescript": "^5.8.3"
|
|
55
57
|
}
|
|
56
58
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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;AAwBJ,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,QAAQ,EACrD,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,SAAS,OAAO,EAChB,cAAa;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,qBAwBxC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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,KAAK,EACxB,UAAyB,EACzB,OAAgB,EACE,EAAE;IACpB,MAAM,MAAM,GAAG,CACb,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACjC,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;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C"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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"}
|
package/lib/check-id.d.ts
DELETED
package/lib/check-id.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-id.d.ts","sourceRoot":"","sources":["../src/check-id.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UACX,MAAM,UAET;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,GACD,SAAS,KACZ,IAIF,CAAC"}
|
package/lib/check-id.js
DELETED
package/lib/check-id.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-id.js","sourceRoot":"","sources":["../src/check-id.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,KAKa,EACP,EAAE;IACR,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAC3C,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email-regex-operator.d.ts","sourceRoot":"","sources":["../src/email-regex-operator.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,KAAA;;EAUxC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function emailRegexOperator(string) {
|
|
2
|
-
if (typeof string !== 'string') {
|
|
3
|
-
throw new TypeError('Expected a string');
|
|
4
|
-
}
|
|
5
|
-
const escapped = string.trim().replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
6
|
-
if (escapped.length === 0)
|
|
7
|
-
throw new Error('String is empty after trimming');
|
|
8
|
-
if (escapped.length > 255)
|
|
9
|
-
throw new Error('String exceeds maximum allowed length');
|
|
10
|
-
return { $regex: new RegExp(`^${escapped}$`, 'i') };
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=email-regex-operator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email-regex-operator.js","sourceRoot":"","sources":["../src/email-regex-operator.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,MAAM;IACvC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC7E,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAEpF,OAAO,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,QAAQ,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-localized-text.d.ts","sourceRoot":"","sources":["../src/find-localized-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAUvD,eAAO,MAAM,iBAAiB,GAAU,CAAC,SAAS,QAAQ,EACxD,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,UAAU,MAAM,CAAC,CAAC,CAAC,EACnB,QAAQ,IAAI,CAAC,MAAM,KAClB,OAAO,CAAC,CAAC,CAwBX,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +0,0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,CAAC;AACxB,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQpE,eAAO,MAAM,iBAAiB,GAC3B,CAAC,SAAS,QAAQ,EACjB,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-preserving-ids.js","sourceRoot":"","sources":["../src/find-preserving-ids.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,WAAW,GAAG,WAAW,CAAC;AAEhC,MAAM,CAAC,MAAM,iBAAiB,GAC5B,CACE,UAAyB,EACsD,EAAE,CACnF,KAAK,EAAE,QAAmB,EAAE,GAAa,EAAE,OAAqB,EAAgB,EAAE;IAChF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,WAAW,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC1D,MAAM,gBAAgB,GAAG;QACvB,GAAG,QAAQ;QACX,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;KAClB,CAAC;IAEF,MAAM,gBAAgB,GAAQ;QAC5B;YACE,MAAM,EAAE,gBAAgB;SACzB;QACD,OAAO,IAAI,KAAK,QAAQ;YACtB,OAAO,IAAI,IAAI,IAAI;YACjB,UAAU,EAAE;gBACV,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE;aACxC;SACF;QACH,IAAI,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QACvB,IAAI,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;QACvB,KAAK,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;KAC3B,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,MAAM,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,CAAC;IACjD,OAAO,KAAY,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-filter-by-id.d.ts","sourceRoot":"","sources":["../src/generate-db-filter-by-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAC5D,IAAI,OAAO,EACX,QAAO,MAAM,CAAC,CAAC,CAAM,KACpB,MAAM,CAAC,CAAC,CAGV,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-filter-by-id.js","sourceRoot":"","sources":["../src/generate-db-filter-by-id.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAW,EACX,QAAmB,EAAE,EACV,EAAE;IACb,MAAM,GAAG,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,kDAAkD;IAC1E,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import SimpleSchema from 'simpl-schema';
|
|
2
|
-
import { TimestampFields } from '@unchainedshop/types/common.js';
|
|
3
|
-
import { ModuleCreateMutation, ModuleMutations } from '@unchainedshop/types/core.js';
|
|
4
|
-
import { Collection } from 'mongodb';
|
|
5
|
-
export declare const generateDbMutations: <T extends TimestampFields & {
|
|
6
|
-
_id?: string;
|
|
7
|
-
}>(collection: Collection<T>, schema: SimpleSchema, options?: {
|
|
8
|
-
hasCreateOnly?: boolean;
|
|
9
|
-
permanentlyDeleteByDefault?: boolean;
|
|
10
|
-
}) => ModuleMutations<T> | ModuleCreateMutation<T>;
|
|
11
|
-
//# sourceMappingURL=generate-db-mutations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-mutations.d.ts","sourceRoot":"","sources":["../src/generate-db-mutations.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAC;AAKnD,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,eAAe,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,cAClE,UAAU,CAAC,CAAC,CAAC,UACjB,YAAY,YACV;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC,KACA,eAAe,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CA6E7C,CAAC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { checkId } from './check-id.js';
|
|
2
|
-
import { generateDbObjectId } from './generate-db-object-id.js';
|
|
3
|
-
import { generateDbFilterById } from './generate-db-filter-by-id.js';
|
|
4
|
-
export const generateDbMutations = (collection, schema, options) => {
|
|
5
|
-
if (!collection)
|
|
6
|
-
throw new Error('Collection is missing');
|
|
7
|
-
if (!schema)
|
|
8
|
-
throw new Error('Schema is missing');
|
|
9
|
-
const { hasCreateOnly, permanentlyDeleteByDefault } = options || {
|
|
10
|
-
hasCreateOnly: false,
|
|
11
|
-
permanentlyDeleteByDefault: false,
|
|
12
|
-
};
|
|
13
|
-
const deletePermanently = async (_id) => {
|
|
14
|
-
checkId(_id);
|
|
15
|
-
const filter = generateDbFilterById(_id);
|
|
16
|
-
const result = await collection.deleteOne(filter);
|
|
17
|
-
return result.deletedCount;
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
create: async (doc) => {
|
|
21
|
-
const values = schema.clean(doc);
|
|
22
|
-
values.created = new Date();
|
|
23
|
-
schema.validate(values);
|
|
24
|
-
values._id = doc._id || generateDbObjectId();
|
|
25
|
-
const result = await collection.insertOne(values);
|
|
26
|
-
return result.insertedId;
|
|
27
|
-
},
|
|
28
|
-
update: hasCreateOnly
|
|
29
|
-
? undefined
|
|
30
|
-
: async (_id, doc) => {
|
|
31
|
-
checkId(_id);
|
|
32
|
-
let modifier;
|
|
33
|
-
if (doc?.$set) {
|
|
34
|
-
const values = schema.clean(doc, { isModifier: true });
|
|
35
|
-
modifier = {
|
|
36
|
-
...values,
|
|
37
|
-
$set: {
|
|
38
|
-
...(values.$set || {}),
|
|
39
|
-
updated: new Date(),
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const values = schema.clean(doc);
|
|
45
|
-
modifier = {
|
|
46
|
-
$set: {
|
|
47
|
-
...values,
|
|
48
|
-
updated: new Date(),
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
schema.validate(modifier, { modifier: true });
|
|
53
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
54
|
-
await collection.updateOne(filter, modifier);
|
|
55
|
-
return _id;
|
|
56
|
-
},
|
|
57
|
-
deletePermanently: hasCreateOnly ? undefined : deletePermanently,
|
|
58
|
-
delete: hasCreateOnly
|
|
59
|
-
? undefined
|
|
60
|
-
: async (_id) => {
|
|
61
|
-
if (permanentlyDeleteByDefault) {
|
|
62
|
-
return deletePermanently(_id);
|
|
63
|
-
}
|
|
64
|
-
checkId(_id);
|
|
65
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
66
|
-
const modifier = { $set: { deleted: new Date() } };
|
|
67
|
-
const values = schema.clean(modifier, { isModifier: true });
|
|
68
|
-
const result = await collection.updateOne(filter, values);
|
|
69
|
-
return result.modifiedCount;
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=generate-db-mutations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-mutations.js","sourceRoot":"","sources":["../src/generate-db-mutations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,UAAyB,EACzB,MAAoB,EACpB,OAGC,EAC6C,EAAE;IAChD,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAElD,MAAM,EAAE,aAAa,EAAE,0BAA0B,EAAE,GAAG,OAAO,IAAI;QAC/D,aAAa,EAAE,KAAK;QACpB,0BAA0B,EAAE,KAAK;KAClC,CAAC;IAEF,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,CAAC;QACb,MAAM,MAAM,GAAG,oBAAoB,CAAI,GAAG,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC,CAA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C9C,MAAM,MAAM,GAAG,oBAAoB,CAAI,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/D,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAE7C,OAAO,GAAG,CAAC;YACb,CAAC;QAEL,iBAAiB,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB;QAEhE,MAAM,EAAE,aAAa;YACnB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACZ,IAAI,0BAA0B,EAAE,CAAC;oBAC/B,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC;gBAChC,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,CAAC;gBACb,MAAM,MAAM,GAAG,oBAAoB,CAAI,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/D,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC;gBACnD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC5D,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE1D,OAAO,MAAM,CAAC,aAAa,CAAC;YAC9B,CAAC;KACN,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-object-id.d.ts","sourceRoot":"","sources":["../src/generate-db-object-id.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,GAAI,eAAW,KAAG,MAKhD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-object-id.js","sourceRoot":"","sources":["../src/generate-db-object-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,SAAS,KAAK,CAAC,MAAM;IACnB,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAM,GAAG,EAAE,EAAU,EAAE;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
package/lib/initDb.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.d.ts","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAiB1C,eAAO,MAAM,OAAO,uBA8BnB,CAAC;AAEF,eAAO,MAAM,MAAM,qBAOlB,CAAC;AAEF,QAAA,MAAM,MAAM,QAAa,OAAO,CAAC,EAAE,CAQlC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/initDb.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.js","sourceRoot":"","sources":["../src/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1C,IAAI,WAAW,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AAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC9F,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,KAAK;IACP,CAAC;IAED,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;IAC/B,IAAI,CAAC;QACH,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC;QAC3B,MAAM,CAAC,MAAM,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,KAAK;IACP,CAAC;AACH,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insensitive-trimmed-regex-operator.d.ts","sourceRoot":"","sources":["../src/insensitive-trimmed-regex-operator.ts"],"names":[],"mappings":"AAAA,wBAAgB,+BAA+B,CAAC,MAAM,KAAA;;EAUrD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insensitive-trimmed-regex-operator.js","sourceRoot":"","sources":["../src/insensitive-trimmed-regex-operator.ts"],"names":[],"mappings":"AAAA,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,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,EAAE,mBAAmB,CAAC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
package/lib/mongodb-index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/src/build-db-indexes.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Collection, Document, CreateIndexesOptions, IndexSpecification } from 'mongodb';
|
|
2
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
|
|
4
|
-
const logger = createLogger('unchained:mongodb');
|
|
5
|
-
|
|
6
|
-
export type Indexes = {
|
|
7
|
-
index: IndexSpecification;
|
|
8
|
-
options?: CreateIndexesOptions;
|
|
9
|
-
}[];
|
|
10
|
-
|
|
11
|
-
const buildIndexes = async <T extends Document>(
|
|
12
|
-
collection: Collection<T>,
|
|
13
|
-
indexes: Indexes,
|
|
14
|
-
): Promise<Error[]> => {
|
|
15
|
-
const errors = (
|
|
16
|
-
await Promise.all(
|
|
17
|
-
indexes.map(async (indexOptions) => {
|
|
18
|
-
if (!indexOptions) return null;
|
|
19
|
-
const { index, options } = indexOptions;
|
|
20
|
-
try {
|
|
21
|
-
await collection.createIndex(index, options);
|
|
22
|
-
return null;
|
|
23
|
-
} catch (e: any) {
|
|
24
|
-
logger.error(e);
|
|
25
|
-
return e as Error;
|
|
26
|
-
}
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
).filter(Boolean) as Error[];
|
|
30
|
-
return errors;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const buildDbIndexes = async <T extends Document>(
|
|
34
|
-
collection: Collection<T>,
|
|
35
|
-
indexes: Indexes,
|
|
36
|
-
{ rebuild }: { rebuild?: boolean } = {},
|
|
37
|
-
) => {
|
|
38
|
-
let success = true;
|
|
39
|
-
const buildErrors = (await buildIndexes<T>(collection, indexes)).filter(Boolean);
|
|
40
|
-
|
|
41
|
-
if (buildErrors.length) {
|
|
42
|
-
if (rebuild) {
|
|
43
|
-
try {
|
|
44
|
-
await collection.dropIndexes();
|
|
45
|
-
} catch {
|
|
46
|
-
/* */
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const rebuildErrors = (await buildIndexes<T>(collection, indexes)).filter(Boolean);
|
|
51
|
-
|
|
52
|
-
if (rebuildErrors.length) {
|
|
53
|
-
logger.error(`Error building some indexes for ${collection.collectionName}`);
|
|
54
|
-
logger.debug(rebuildErrors);
|
|
55
|
-
success = false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return success;
|
|
60
|
-
};
|
package/src/build-sort-option.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SortOption } from '@unchainedshop/utils';
|
|
2
|
-
import { Sort } from 'mongodb';
|
|
3
|
-
|
|
4
|
-
const SORT_DIRECTIONS = {
|
|
5
|
-
ASC: 1,
|
|
6
|
-
DESC: -1,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const buildSortOptions = (sort: SortOption[] = []): Sort => {
|
|
10
|
-
const sortBy = {};
|
|
11
|
-
sort?.forEach(({ key, value }) => {
|
|
12
|
-
sortBy[key] = SORT_DIRECTIONS[value];
|
|
13
|
-
});
|
|
14
|
-
return sortBy;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default buildSortOptions;
|
|
@@ -1,6 +0,0 @@
|
|
|
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);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Collection, Document, Filter } from 'mongodb';
|
|
2
|
-
import { systemLocale } from '@unchainedshop/utils';
|
|
3
|
-
|
|
4
|
-
const extendSelectorWithLocale = (selector, locale) => {
|
|
5
|
-
const localeSelector = {
|
|
6
|
-
locale: { $in: [locale.baseName, locale.language] },
|
|
7
|
-
};
|
|
8
|
-
return { ...localeSelector, ...selector };
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const findLocalizedText = async <T extends Document>(
|
|
12
|
-
collection: Collection<T>,
|
|
13
|
-
selector: Filter<T>,
|
|
14
|
-
locale: Intl.Locale,
|
|
15
|
-
): Promise<T> => {
|
|
16
|
-
const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale), {
|
|
17
|
-
sort: { updated: -1 },
|
|
18
|
-
});
|
|
19
|
-
if (exactTranslation) {
|
|
20
|
-
return exactTranslation as T;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (systemLocale.baseName !== locale.baseName) {
|
|
24
|
-
const fallbackTranslation = await collection.findOne(
|
|
25
|
-
extendSelectorWithLocale(selector, systemLocale),
|
|
26
|
-
{
|
|
27
|
-
sort: { updated: -1 },
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
if (fallbackTranslation) {
|
|
31
|
-
return fallbackTranslation as T;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const foundText = await collection.findOne(selector, {
|
|
36
|
-
sort: { updated: -1 },
|
|
37
|
-
});
|
|
38
|
-
return foundText as T;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default findLocalizedText;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Collection, FindOptions, Filter, Document } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
const sortByIndex = {
|
|
4
|
-
index: 1,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const defaultSort = sortByIndex;
|
|
8
|
-
|
|
9
|
-
export const findPreservingIds =
|
|
10
|
-
<T extends Document>(
|
|
11
|
-
collection: Collection<T>,
|
|
12
|
-
): ((selector: Filter<T>, ids: string[], options?: FindOptions) => Promise<T[]>) =>
|
|
13
|
-
async (selector: Filter<T>, ids: string[], options?: FindOptions): Promise<T[]> => {
|
|
14
|
-
const { skip, limit, sort = defaultSort } = options || {};
|
|
15
|
-
const filteredSelector = {
|
|
16
|
-
...selector,
|
|
17
|
-
_id: { $in: ids },
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const filteredPipeline: any = [
|
|
21
|
-
{
|
|
22
|
-
$match: filteredSelector,
|
|
23
|
-
},
|
|
24
|
-
typeof sort === 'object' &&
|
|
25
|
-
'index' in sort && {
|
|
26
|
-
$addFields: {
|
|
27
|
-
index: { $indexOfArray: [ids, '$_id'] },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
sort && { $sort: sort },
|
|
31
|
-
skip && { $skip: skip },
|
|
32
|
-
limit && { $limit: limit },
|
|
33
|
-
].filter(Boolean);
|
|
34
|
-
|
|
35
|
-
const aggregationPointer = collection.aggregate(filteredPipeline);
|
|
36
|
-
const items = await aggregationPointer.toArray();
|
|
37
|
-
return items as T[];
|
|
38
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Filter } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
export const generateDbFilterById = <T extends { _id: string }>(
|
|
4
|
-
id: unknown,
|
|
5
|
-
query: Filter<T> = {},
|
|
6
|
-
): Filter<T> => {
|
|
7
|
-
const _id = id || null; // never undefined, else it will get the first one
|
|
8
|
-
return { _id, ...query };
|
|
9
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name Random.hexString
|
|
3
|
-
* @summary Return a random string of `n` hexadecimal digits.
|
|
4
|
-
* @locus Anywhere
|
|
5
|
-
* @param {Number} n Length of the string
|
|
6
|
-
*/
|
|
7
|
-
function toHex(buffer) {
|
|
8
|
-
return Array.prototype.map.call(buffer, (x) => x.toString(16).padStart(2, '0')).join('');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const generateDbObjectId = (digits = 24): string => {
|
|
12
|
-
const numBytes = Math.ceil(digits / 2);
|
|
13
|
-
const bytes = crypto.getRandomValues(new Uint8Array(numBytes));
|
|
14
|
-
const result = toHex(bytes);
|
|
15
|
-
return result.substring(0, digits);
|
|
16
|
-
};
|
package/src/initDb.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Db, MongoClient } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
let zstdEnabled = false;
|
|
4
|
-
let mongod;
|
|
5
|
-
let mongoClient: MongoClient | null;
|
|
6
|
-
|
|
7
|
-
const { PORT = '4010' } = process.env;
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
await import('@mongodb-js/zstd');
|
|
13
|
-
zstdEnabled = true;
|
|
14
|
-
} catch {
|
|
15
|
-
/* */
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const startDb = async () => {
|
|
19
|
-
const { mkdir } = await import('node:fs/promises');
|
|
20
|
-
const { MongoMemoryServer } = await import('mongodb-memory-server');
|
|
21
|
-
try {
|
|
22
|
-
await mkdir(`${process.cwd()}/.db`);
|
|
23
|
-
} catch {
|
|
24
|
-
/* */
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
mongod = MongoMemoryServer.create({
|
|
28
|
-
instance:
|
|
29
|
-
process.env.NODE_ENV === 'test'
|
|
30
|
-
? { dbName: 'test', port: parseInt(PORT, 10) + 1 }
|
|
31
|
-
: {
|
|
32
|
-
dbPath: `${process.cwd()}/.db`,
|
|
33
|
-
storageEngine: 'wiredTiger',
|
|
34
|
-
port: parseInt(PORT, 10) + 1,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
const mongoInstance = await mongod;
|
|
38
|
-
if (mongoInstance) {
|
|
39
|
-
return `${mongoInstance.getUri()}${process.env.NODE_ENV === 'test' ? 'test' : 'unchained'}`;
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
/* */
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw new Error(
|
|
46
|
-
"Can't connect to MongoDB: Could not start mongodb-memory-server and MONGO_URL env is not set",
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const stopDb = async () => {
|
|
51
|
-
try {
|
|
52
|
-
await mongoClient?.close();
|
|
53
|
-
await (await mongod)?.stop();
|
|
54
|
-
} catch {
|
|
55
|
-
/* */
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const initDb = async (): Promise<Db> => {
|
|
60
|
-
const url = process.env.MONGO_URL || (await startDb());
|
|
61
|
-
mongoClient = new MongoClient(url, {
|
|
62
|
-
compressors: zstdEnabled ? 'zstd' : undefined,
|
|
63
|
-
});
|
|
64
|
-
await mongoClient.connect();
|
|
65
|
-
const db = mongoClient.db();
|
|
66
|
-
return db;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export { initDb };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
4
|
-
|
|
5
|
-
/* eslint-disable no-useless-escape */
|
|
6
|
-
|
|
7
|
-
describe('Insensitive Trimmed Regex Operator', () => {
|
|
8
|
-
it('should accept + mails', () => {
|
|
9
|
-
const input = 'test+test@test.com';
|
|
10
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
11
|
-
$regex: /^test\+test@test\.com$/i,
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should trim mails', () => {
|
|
16
|
-
const input = ' test-two+test@test.com';
|
|
17
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
18
|
-
$regex: /^test\-two\+test@test\.com$/i,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should not transform case', () => {
|
|
23
|
-
const input = ' tesT+tesT@test.com ';
|
|
24
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
25
|
-
$regex: /^tesT\+tesT@test\.com$/i,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// New tests to verify security improvements
|
|
30
|
-
|
|
31
|
-
it('should escape all regex special characters', () => {
|
|
32
|
-
const input = '.*+?^${}()|[]\\';
|
|
33
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
34
|
-
$regex: /^\.\*\+\?\^\$\{\}\(\)\|\[\]\\$/i,
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should properly escape hyphens', () => {
|
|
39
|
-
const input = 'range-a-z';
|
|
40
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
41
|
-
$regex: /^range\-a\-z$/i,
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should properly escape forward slashes', () => {
|
|
46
|
-
const input = 'path/to/file';
|
|
47
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
48
|
-
$regex: /^path\/to\/file$/i,
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should handle malicious pattern attempts', () => {
|
|
53
|
-
const input = '[a-z]|[0-9]';
|
|
54
|
-
assert.deepStrictEqual(insensitiveTrimmedRegexOperator(input), {
|
|
55
|
-
$regex: /^\[a\-z\]\|\[0\-9\]$/i,
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should reject empty strings after trimming', () => {
|
|
60
|
-
assert.throws(() => {
|
|
61
|
-
insensitiveTrimmedRegexOperator(' ');
|
|
62
|
-
}, /String is empty after trimming/);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should reject non-string inputs', () => {
|
|
66
|
-
assert.throws(() => {
|
|
67
|
-
insensitiveTrimmedRegexOperator(123);
|
|
68
|
-
}, /Expected a string/);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should reject strings exceeding maximum length', () => {
|
|
72
|
-
const longString = 'a'.repeat(256);
|
|
73
|
-
assert.throws(() => {
|
|
74
|
-
insensitiveTrimmedRegexOperator(longString);
|
|
75
|
-
}, /String exceeds maximum allowed length/);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function insensitiveTrimmedRegexOperator(string) {
|
|
2
|
-
if (typeof string !== 'string') {
|
|
3
|
-
throw new TypeError('Expected a string');
|
|
4
|
-
}
|
|
5
|
-
const escapped = string.trim().replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
6
|
-
|
|
7
|
-
if (escapped.length === 0) throw new Error('String is empty after trimming');
|
|
8
|
-
if (escapped.length > 255) throw new Error('String exceeds maximum allowed length');
|
|
9
|
-
|
|
10
|
-
return { $regex: new RegExp(`^${escapped}$`, 'i') };
|
|
11
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { SortDirection } from '@unchainedshop/utils';
|
|
4
|
-
import { buildSortOptions, generateDbObjectId } from './mongodb-index.js';
|
|
5
|
-
|
|
6
|
-
describe('Mongo', () => {
|
|
7
|
-
it('Init', () => {
|
|
8
|
-
assert(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
describe('buildSortOptions', () => {
|
|
12
|
-
it('should return the correct db sort format', () => {
|
|
13
|
-
const sort = [
|
|
14
|
-
{ key: 'name', value: SortDirection.ASC },
|
|
15
|
-
{ key: 'age', value: SortDirection.DESC },
|
|
16
|
-
];
|
|
17
|
-
assert.deepStrictEqual(buildSortOptions(sort), { name: 1, age: -1 });
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('generateDbObjectId', () => {
|
|
22
|
-
it('generateDbObjectId with default digits', () => {
|
|
23
|
-
const result = generateDbObjectId();
|
|
24
|
-
assert.strictEqual(typeof result, 'string');
|
|
25
|
-
assert.strictEqual(result.length, 24);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('generateDbObjectId with odd digits', () => {
|
|
29
|
-
const result = generateDbObjectId(23);
|
|
30
|
-
assert.strictEqual(typeof result, 'string');
|
|
31
|
-
assert.strictEqual(result.length, 23);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('generateDbObjectId with even digits', () => {
|
|
35
|
-
const result = generateDbObjectId(24);
|
|
36
|
-
assert.strictEqual(typeof result, 'string');
|
|
37
|
-
assert.strictEqual(result.length, 24);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
package/src/mongodb-index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as mongodb from 'mongodb';
|
|
2
|
-
|
|
3
|
-
export { initDb, startDb, stopDb } from './initDb.js';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Db utils
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export { generateDbObjectId } from './generate-db-object-id.js';
|
|
10
|
-
export { generateDbFilterById } from './generate-db-filter-by-id.js';
|
|
11
|
-
export { buildDbIndexes } from './build-db-indexes.js';
|
|
12
|
-
export { findPreservingIds } from './find-preserving-ids.js';
|
|
13
|
-
export { buildSortOptions } from './build-sort-option.js';
|
|
14
|
-
export { findLocalizedText } from './find-localized-text.js';
|
|
15
|
-
export { insensitiveTrimmedRegexOperator } from './insensitive-trimmed-regex-operator.js';
|
|
16
|
-
export * from './documentdb-compat-mode.js';
|
|
17
|
-
|
|
18
|
-
export { mongodb };
|
|
19
|
-
|
|
20
|
-
export interface LogFields {
|
|
21
|
-
log: (
|
|
22
|
-
| {
|
|
23
|
-
date: Date;
|
|
24
|
-
status: string | null;
|
|
25
|
-
info?: string;
|
|
26
|
-
}
|
|
27
|
-
| {
|
|
28
|
-
date: Date;
|
|
29
|
-
status?: string;
|
|
30
|
-
info: string;
|
|
31
|
-
}
|
|
32
|
-
)[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface TimestampFields {
|
|
36
|
-
created: Date;
|
|
37
|
-
updated?: Date;
|
|
38
|
-
deleted?: Date | null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface Address {
|
|
42
|
-
addressLine?: string;
|
|
43
|
-
addressLine2?: string;
|
|
44
|
-
city?: string;
|
|
45
|
-
company?: string;
|
|
46
|
-
countryCode?: string;
|
|
47
|
-
firstName?: string;
|
|
48
|
-
lastName?: string;
|
|
49
|
-
postalCode?: string;
|
|
50
|
-
regionCode?: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface Contact {
|
|
54
|
-
telNumber?: string;
|
|
55
|
-
emailAddress?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface Migration<Context = unknown> {
|
|
59
|
-
/**
|
|
60
|
-
* Migration ID must be between 19700000000000 and 99999999999999
|
|
61
|
-
* YYYYMMDDHHMMSS format is recommended.
|
|
62
|
-
* @minimum 19700000000000
|
|
63
|
-
* @maximum 99999999999999
|
|
64
|
-
*/
|
|
65
|
-
id: number;
|
|
66
|
-
name: string;
|
|
67
|
-
up: (params: { logger: any | Console; unchainedAPI: Context }) => Promise<void>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface MigrationRepository<Context = unknown> {
|
|
71
|
-
db: mongodb.Db;
|
|
72
|
-
migrations: Map<number, Migration<Context>>;
|
|
73
|
-
register: (migration: Migration<Context>) => void;
|
|
74
|
-
allMigrations: () => Migration<Context>[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface ModuleInput<Options extends Record<string, any>> {
|
|
78
|
-
db: mongodb.Db;
|
|
79
|
-
migrationRepository: MigrationRepository;
|
|
80
|
-
options?: Options;
|
|
81
|
-
}
|