@unchainedshop/mongodb 3.0.0-alpha3 → 3.0.0-alpha5
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/mongodb-index.d.ts +19 -0
- package/lib/mongodb-index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/mongodb-index.test.ts +26 -29
- package/src/mongodb-index.ts +19 -0
package/lib/mongodb-index.d.ts
CHANGED
|
@@ -35,4 +35,23 @@ export interface Contact {
|
|
|
35
35
|
telNumber?: string;
|
|
36
36
|
emailAddress?: string;
|
|
37
37
|
}
|
|
38
|
+
export interface Migration<Context = unknown> {
|
|
39
|
+
id: number;
|
|
40
|
+
name: string;
|
|
41
|
+
up: (params: {
|
|
42
|
+
logger: any | Console;
|
|
43
|
+
unchainedAPI: Context;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export interface MigrationRepository<Context = unknown> {
|
|
47
|
+
db: mongodb.Db;
|
|
48
|
+
migrations: Map<number, Migration<Context>>;
|
|
49
|
+
register: (migration: Migration<Context>) => void;
|
|
50
|
+
allMigrations: () => Array<Migration<Context>>;
|
|
51
|
+
}
|
|
52
|
+
export interface ModuleInput<Options extends Record<string, any>> {
|
|
53
|
+
db: mongodb.Db;
|
|
54
|
+
migrationRepository?: MigrationRepository;
|
|
55
|
+
options?: Options;
|
|
56
|
+
}
|
|
38
57
|
//# sourceMappingURL=mongodb-index.d.ts.map
|
|
@@ -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,CA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AY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,SAAS,CAAC,OAAO,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,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;CAChD;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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/mongodb",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-alpha5",
|
|
4
4
|
"description": "MongoDB provider for unchained platform",
|
|
5
5
|
"main": "lib/mongodb-index.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/utils": "^3.0.0-
|
|
34
|
+
"@unchainedshop/utils": "^3.0.0-alpha4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mongodb-js/zstd": "^1.2.2",
|
|
38
|
-
"mongodb": "^6.
|
|
38
|
+
"mongodb": "^6.10.0"
|
|
39
39
|
},
|
|
40
40
|
"optionalDependencies": {
|
|
41
41
|
"mongodb-memory-server": "^10.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^22.
|
|
44
|
+
"@types/node": "^22.8.1",
|
|
45
45
|
"jest": "^29.7.0",
|
|
46
|
-
"typescript": "^5.6.
|
|
46
|
+
"typescript": "^5.6.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
import { SortDirection } from '@unchainedshop/utils';
|
|
2
|
-
import {
|
|
3
|
-
buildSortOptions,
|
|
4
|
-
generateDbObjectId,
|
|
5
|
-
} from './mongodb-index.js';
|
|
2
|
+
import { buildSortOptions, generateDbObjectId } from './mongodb-index.js';
|
|
6
3
|
|
|
7
4
|
describe('Mongo', () => {
|
|
8
|
-
it('Init',
|
|
9
|
-
expect(true).toBeTruthy()
|
|
5
|
+
it('Init', () => {
|
|
6
|
+
expect(true).toBeTruthy();
|
|
10
7
|
});
|
|
11
8
|
|
|
12
9
|
describe('buildSortOptions', () => {
|
|
13
10
|
it('should return the correct db sort format', () => {
|
|
14
|
-
const sort = [
|
|
11
|
+
const sort = [
|
|
12
|
+
{ key: 'name', value: SortDirection.ASC },
|
|
13
|
+
{ key: 'age', value: SortDirection.DESC },
|
|
14
|
+
];
|
|
15
15
|
expect(buildSortOptions(sort)).toEqual({ name: 1, age: -1 });
|
|
16
|
-
})
|
|
17
|
-
|
|
16
|
+
});
|
|
18
17
|
});
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
describe('generateDbObjectId', () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
it('generateDbObjectId with default digits', () => {
|
|
21
|
+
const result = generateDbObjectId();
|
|
22
|
+
expect(typeof result).toBe('string');
|
|
23
|
+
expect(result.length).toBe(24);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('generateDbObjectId with odd digits', () => {
|
|
27
|
+
const result = generateDbObjectId(23);
|
|
28
|
+
expect(typeof result).toBe('string');
|
|
29
|
+
expect(result.length).toBe(23);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('generateDbObjectId with even digits', () => {
|
|
33
|
+
const result = generateDbObjectId(24);
|
|
34
|
+
expect(typeof result).toBe('string');
|
|
35
|
+
expect(result.length).toBe(24);
|
|
36
|
+
});
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
})
|
|
40
38
|
});
|
|
41
|
-
|
package/src/mongodb-index.ts
CHANGED
|
@@ -46,3 +46,22 @@ export interface Contact {
|
|
|
46
46
|
telNumber?: string;
|
|
47
47
|
emailAddress?: string;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
export interface Migration<Context = unknown> {
|
|
51
|
+
id: number;
|
|
52
|
+
name: string;
|
|
53
|
+
up: (params: { logger: any | Console; unchainedAPI: Context }) => Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface MigrationRepository<Context = unknown> {
|
|
57
|
+
db: mongodb.Db;
|
|
58
|
+
migrations: Map<number, Migration<Context>>;
|
|
59
|
+
register: (migration: Migration<Context>) => void;
|
|
60
|
+
allMigrations: () => Array<Migration<Context>>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ModuleInput<Options extends Record<string, any>> {
|
|
64
|
+
db: mongodb.Db;
|
|
65
|
+
migrationRepository?: MigrationRepository;
|
|
66
|
+
options?: Options;
|
|
67
|
+
}
|