@unchainedshop/core-events 2.0.0-beta8 → 2.0.0-beta9
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/jest.config.js +9 -0
- package/lib/module/configureEventsModule.d.ts +6 -1
- package/lib/module/configureEventsModule.js +3 -2
- package/lib/module/configureEventsModule.js.map +1 -1
- package/package.json +9 -8
- package/src/module/configureEventsModule.ts +3 -2
- package/tests/events-index.test.ts +24 -27
package/jest.config.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import { EventsModule } from '@unchainedshop/types/events';
|
|
1
|
+
import { EventQuery, EventsModule } from '@unchainedshop/types/events';
|
|
2
2
|
import { ModuleInput } from '@unchainedshop/types/core';
|
|
3
|
+
export declare const buildFindSelector: ({ types, queryString, created }: EventQuery) => {
|
|
4
|
+
type?: any;
|
|
5
|
+
$text?: any;
|
|
6
|
+
created?: any;
|
|
7
|
+
};
|
|
3
8
|
export declare const configureEventsModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<EventsModule>;
|
|
@@ -4,7 +4,7 @@ import { SortDirection } from '@unchainedshop/types/api';
|
|
|
4
4
|
import { EventsCollection } from '../db/EventsCollection';
|
|
5
5
|
import { EventsSchema } from '../db/EventsSchema';
|
|
6
6
|
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter';
|
|
7
|
-
const buildFindSelector = ({ types, queryString, created }) => {
|
|
7
|
+
export const buildFindSelector = ({ types, queryString, created }) => {
|
|
8
8
|
const selector = {};
|
|
9
9
|
if (types && Array.isArray(types))
|
|
10
10
|
selector.type = { $in: types };
|
|
@@ -27,10 +27,11 @@ export const configureEventsModule = async ({ db, }) => {
|
|
|
27
27
|
return Events.findOne(selector, options);
|
|
28
28
|
},
|
|
29
29
|
findEvents: async ({ limit, offset, sort, ...query }) => {
|
|
30
|
+
const defaultSort = [{ key: 'created', value: SortDirection.DESC }];
|
|
30
31
|
return Events.find(buildFindSelector(query), {
|
|
31
32
|
skip: offset,
|
|
32
33
|
limit,
|
|
33
|
-
sort: buildSortOptions(sort ||
|
|
34
|
+
sort: buildSortOptions(sort || defaultSort),
|
|
34
35
|
}).toArray();
|
|
35
36
|
},
|
|
36
37
|
type: (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAc,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAc,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAc,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAc,EAAE,EAAE;IAC/E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CAAC,KAAK,CAAC,EAAE;gBAC3C,IAAI,EAAE,MAAM;gBACZ,KAAK;gBACL,IAAI,EAAE,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;aAC5C,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,CAAC;QAED,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,mBAAmB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBAC9C,OAAO,KAAK,CAAC,IAAI,CAAC;aACnB;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACrB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;YACpE,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-events",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta9",
|
|
4
4
|
"main": "lib/events-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/events-index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"clean": "rm -rf lib",
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"watch": "tsc -w",
|
|
15
|
-
"test": "jest --
|
|
15
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -30,16 +31,16 @@
|
|
|
30
31
|
},
|
|
31
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/events": "^2.0.0-
|
|
34
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
35
|
-
"simpl-schema": "^3.0
|
|
34
|
+
"@unchainedshop/events": "^2.0.0-beta9",
|
|
35
|
+
"@unchainedshop/utils": "^2.0.0-beta9",
|
|
36
|
+
"simpl-schema": "^3.2.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^18.11.
|
|
39
|
-
"@unchainedshop/types": "^2.0.0-
|
|
39
|
+
"@types/node": "^18.11.12",
|
|
40
|
+
"@unchainedshop/types": "^2.0.0-beta9",
|
|
40
41
|
"jest": "^29.3.1",
|
|
41
42
|
"mongodb": "^4.12.1",
|
|
42
43
|
"ts-jest": "^29.0.3",
|
|
43
|
-
"typescript": "^4.9.
|
|
44
|
+
"typescript": "^4.9.4"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -8,7 +8,7 @@ import { EventsCollection } from '../db/EventsCollection';
|
|
|
8
8
|
import { EventsSchema } from '../db/EventsSchema';
|
|
9
9
|
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter';
|
|
10
10
|
|
|
11
|
-
const buildFindSelector = ({ types, queryString, created }: EventQuery) => {
|
|
11
|
+
export const buildFindSelector = ({ types, queryString, created }: EventQuery) => {
|
|
12
12
|
const selector: { type?: any; $text?: any; created?: any } = {};
|
|
13
13
|
|
|
14
14
|
if (types && Array.isArray(types)) selector.type = { $in: types };
|
|
@@ -36,10 +36,11 @@ export const configureEventsModule = async ({
|
|
|
36
36
|
},
|
|
37
37
|
|
|
38
38
|
findEvents: async ({ limit, offset, sort, ...query }) => {
|
|
39
|
+
const defaultSort = [{ key: 'created', value: SortDirection.DESC }] as Array<SortOption>;
|
|
39
40
|
return Events.find(buildFindSelector(query), {
|
|
40
41
|
skip: offset,
|
|
41
42
|
limit,
|
|
42
|
-
sort: buildSortOptions(sort ||
|
|
43
|
+
sort: buildSortOptions(sort || defaultSort),
|
|
43
44
|
}).toArray();
|
|
44
45
|
},
|
|
45
46
|
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { initDb } from '@unchainedshop/mongodb';
|
|
3
|
-
import { configureEventsModule } from '@unchainedshop/events';
|
|
4
|
-
import { emit, registerEvents, getEmitHistoryAdapter } from '@unchainedshop/events';
|
|
1
|
+
import { buildFindSelector } from "../src/module/configureEventsModule";
|
|
5
2
|
|
|
6
|
-
describe('
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
it('Configure Events', () => {
|
|
15
|
-
assert.isDefined(configureEventsModule);
|
|
16
|
-
assert.ok(module);
|
|
17
|
-
assert.isFunction(module.findEvent);
|
|
3
|
+
describe('Event', () => {
|
|
4
|
+
describe('buildFindSelector', () => {
|
|
5
|
+
it('Return correct filter object when passed create, queryString, types', async () => {
|
|
6
|
+
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z"), queryString: "Hello world", types: ['PRODUCT_CREATED']})).toEqual({
|
|
7
|
+
type: { '$in': [ 'PRODUCT_CREATED' ] },
|
|
8
|
+
'$text': { '$search': 'Hello world' },
|
|
9
|
+
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )}
|
|
10
|
+
})
|
|
18
11
|
});
|
|
19
12
|
|
|
20
|
-
it('
|
|
21
|
-
|
|
13
|
+
it('Return correct filter object when passed create, queryString', async () => {
|
|
14
|
+
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z"), queryString: "Hello world"})).toEqual({
|
|
15
|
+
'$text': { '$search': 'Hello world' },
|
|
16
|
+
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )}
|
|
17
|
+
})
|
|
18
|
+
});
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
it('Return correct filter object when passed create', async () => {
|
|
21
|
+
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z")})).toEqual({
|
|
22
|
+
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )}
|
|
23
|
+
})
|
|
24
|
+
});
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
assert.isAtLeast(events.length, 1)
|
|
32
|
-
});
|
|
26
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
27
|
+
expect(buildFindSelector({})).toEqual({})
|
|
28
|
+
});
|
|
29
|
+
})
|
|
33
30
|
});
|