@unchainedshop/core-events 2.5.12 → 2.6.1
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/db/EventsCollection.d.ts +9 -3
- package/lib/db/EventsCollection.js +1 -1
- package/lib/db/EventsCollection.js.map +1 -1
- package/lib/events-index.d.ts +1 -0
- package/lib/events-index.js.map +1 -1
- package/lib/module/configureEventHistoryAdapter.d.ts +1 -1
- package/lib/module/configureEventHistoryAdapter.js.map +1 -1
- package/lib/module/configureEventsModule.d.ts +21 -2
- package/lib/module/configureEventsModule.js +1 -1
- package/lib/module/configureEventsModule.js.map +1 -1
- package/package.json +7 -7
- package/src/db/EventsCollection.ts +11 -4
- package/src/events-index.ts +2 -0
- package/src/module/configureEventHistoryAdapter.ts +2 -2
- package/src/module/configureEventsModule.ts +33 -7
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
1
|
+
import type { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
import { TimestampFields } from '@unchainedshop/types/common.js';
|
|
3
|
+
export type Event = {
|
|
4
|
+
_id?: string;
|
|
5
|
+
type: string;
|
|
6
|
+
context?: Record<string, unknown>;
|
|
7
|
+
payload?: Record<string, unknown>;
|
|
8
|
+
} & TimestampFields;
|
|
9
|
+
export declare const EventsCollection: (db: mongodb.Db) => Promise<mongodb.Collection<Event>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventsCollection.js","sourceRoot":"","sources":["../../src/db/EventsCollection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EventsCollection.js","sourceRoot":"","sources":["../../src/db/EventsCollection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,MAAM,YAAY,GAAG,MAAM,CAAC;AAS5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IACvD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAQ,QAAQ,CAAC,CAAC;IAE9C,MAAM,cAAc,CAAC,MAAM,EAAE;QAC3B;YACE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YACtB,OAAO,EAAE,EAAE,kBAAkB,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE;SAC/D;QACD,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QACjD;YACE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;YACpC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC;oBACN,IAAI,EAAE,CAAC;iBACR;gBACD,IAAI,EAAE,wBAAwB;aAC/B;SACF;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/lib/events-index.d.ts
CHANGED
package/lib/events-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-index.js","sourceRoot":"","sources":["../src/events-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"events-index.js","sourceRoot":"","sources":["../src/events-index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventHistoryAdapter.js","sourceRoot":"","sources":["../../src/module/configureEventHistoryAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureEventHistoryAdapter.js","sourceRoot":"","sources":["../../src/module/configureEventHistoryAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAe,MAAM,uBAAuB,CAAC;AAGlG,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,SAAiC,EAAE,EAAE;IAChF,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAgB;YAC3B,SAAS,EAAE,GAAG,EAAE;gBACd,aAAa;YACf,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,EAAE;gBACtD,MAAM,SAAS,CAAC,MAAM,CAAC;oBACrB,IAAI,EAAE,SAAS;oBACf,OAAO;oBACP,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;SACF,CAAC;QACF,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
import { SortOption } from '@unchainedshop/types/api.js';
|
|
3
|
+
import { ModuleCreateMutation, ModuleInput } from '@unchainedshop/types/core.js';
|
|
4
|
+
import { Event } from '../db/EventsCollection.js';
|
|
5
|
+
export type EventQuery = {
|
|
6
|
+
types?: Array<string>;
|
|
7
|
+
queryString?: string;
|
|
8
|
+
created?: Date;
|
|
9
|
+
};
|
|
3
10
|
export declare const buildFindSelector: ({ types, queryString, created }: EventQuery) => {
|
|
4
11
|
type?: any;
|
|
5
12
|
$text?: any;
|
|
6
13
|
created?: any;
|
|
7
14
|
};
|
|
15
|
+
export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
16
|
+
findEvent: (params: mongodb.Filter<Event> & {
|
|
17
|
+
eventId: string;
|
|
18
|
+
}, options?: mongodb.FindOptions) => Promise<Event>;
|
|
19
|
+
findEvents: (params: EventQuery & {
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
sort?: Array<SortOption>;
|
|
23
|
+
}, options?: mongodb.FindOptions) => Promise<Array<Event>>;
|
|
24
|
+
type: (event: Event) => string;
|
|
25
|
+
count: (query: EventQuery) => Promise<number>;
|
|
26
|
+
}
|
|
8
27
|
export declare const configureEventsModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<EventsModule>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/
|
|
1
|
+
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/mongodb';
|
|
2
2
|
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
3
3
|
import { SortDirection } from '@unchainedshop/types/api.js';
|
|
4
4
|
import { EventsCollection } from '../db/EventsCollection.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAS,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAQjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAc,EAAE,EAAE;IAC/E,MAAM,QAAQ,GAA+C,EAAE,CAAC;IAEhE,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,QAAQ,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAClE,IAAI,WAAW;QAAE,QAAQ,CAAC,KAAK,G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EAAE;YACd,IAAI,mBAAmB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/C,OAAO,KAAK,CAAC,IAAI,CAAC;YACpB,CAAC;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.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"main": "lib/events-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/events-index.js",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^2.
|
|
35
|
-
"@unchainedshop/utils": "^2.
|
|
34
|
+
"@unchainedshop/events": "^2.6.1",
|
|
35
|
+
"@unchainedshop/utils": "^2.6.1",
|
|
36
36
|
"simpl-schema": "=3.2.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^20.10
|
|
40
|
-
"@unchainedshop/types": "^2.
|
|
39
|
+
"@types/node": "^20.11.10",
|
|
40
|
+
"@unchainedshop/types": "^2.6.1",
|
|
41
41
|
"jest": "^29.7.0",
|
|
42
|
-
"ts-jest": "^29.1.
|
|
43
|
-
"typescript": "^5.3.
|
|
42
|
+
"ts-jest": "^29.1.2",
|
|
43
|
+
"typescript": "^5.3.3"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
3
|
+
import { TimestampFields } from '@unchainedshop/types/common.js';
|
|
4
4
|
|
|
5
5
|
const TWO_DAYS_SEC = 172800;
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export type Event = {
|
|
8
|
+
_id?: string;
|
|
9
|
+
type: string;
|
|
10
|
+
context?: Record<string, unknown>;
|
|
11
|
+
payload?: Record<string, unknown>;
|
|
12
|
+
} & TimestampFields;
|
|
13
|
+
|
|
14
|
+
export const EventsCollection = async (db: mongodb.Db) => {
|
|
8
15
|
const Events = db.collection<Event>('events');
|
|
9
16
|
|
|
10
17
|
await buildDbIndexes(Events, [
|
package/src/events-index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModuleMutations } from '@unchainedshop/types/core.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { getEmitHistoryAdapter, setEmitHistoryAdapter, EmitAdapter } from '@unchainedshop/events';
|
|
3
|
+
import { Event } from '../db/EventsCollection.js';
|
|
4
4
|
|
|
5
5
|
export const configureEventHistoryAdapter = (mutations: ModuleMutations<Event>) => {
|
|
6
6
|
if (!getEmitHistoryAdapter()) {
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import type { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
|
|
3
|
+
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/mongodb';
|
|
4
4
|
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
5
5
|
import { SortDirection, SortOption } from '@unchainedshop/types/api.js';
|
|
6
|
-
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core.js';
|
|
7
|
-
import { EventsCollection } from '../db/EventsCollection.js';
|
|
6
|
+
import { ModuleCreateMutation, ModuleInput, ModuleMutations } from '@unchainedshop/types/core.js';
|
|
7
|
+
import { EventsCollection, Event } from '../db/EventsCollection.js';
|
|
8
8
|
import { EventsSchema } from '../db/EventsSchema.js';
|
|
9
9
|
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter.js';
|
|
10
10
|
|
|
11
|
+
export type EventQuery = {
|
|
12
|
+
types?: Array<string>;
|
|
13
|
+
queryString?: string;
|
|
14
|
+
created?: Date;
|
|
15
|
+
};
|
|
16
|
+
|
|
11
17
|
export const buildFindSelector = ({ types, queryString, created }: EventQuery) => {
|
|
12
18
|
const selector: { type?: any; $text?: any; created?: any } = {};
|
|
13
19
|
|
|
@@ -17,6 +23,26 @@ export const buildFindSelector = ({ types, queryString, created }: EventQuery) =
|
|
|
17
23
|
return selector;
|
|
18
24
|
};
|
|
19
25
|
|
|
26
|
+
export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
27
|
+
findEvent: (
|
|
28
|
+
params: mongodb.Filter<Event> & { eventId: string },
|
|
29
|
+
options?: mongodb.FindOptions,
|
|
30
|
+
) => Promise<Event>;
|
|
31
|
+
|
|
32
|
+
findEvents: (
|
|
33
|
+
params: EventQuery & {
|
|
34
|
+
limit?: number;
|
|
35
|
+
offset?: number;
|
|
36
|
+
sort?: Array<SortOption>;
|
|
37
|
+
},
|
|
38
|
+
options?: mongodb.FindOptions,
|
|
39
|
+
) => Promise<Array<Event>>;
|
|
40
|
+
|
|
41
|
+
type: (event: Event) => string;
|
|
42
|
+
|
|
43
|
+
count: (query: EventQuery) => Promise<number>;
|
|
44
|
+
}
|
|
45
|
+
|
|
20
46
|
export const configureEventsModule = async ({
|
|
21
47
|
db,
|
|
22
48
|
}: ModuleInput<Record<string, never>>): Promise<EventsModule> => {
|
|
@@ -31,8 +57,8 @@ export const configureEventsModule = async ({
|
|
|
31
57
|
return {
|
|
32
58
|
...mutations,
|
|
33
59
|
findEvent: async ({ eventId, ...rest }, options) => {
|
|
34
|
-
const selector = eventId ? generateDbFilterById(eventId) : rest;
|
|
35
|
-
return Events.findOne(selector
|
|
60
|
+
const selector = eventId ? generateDbFilterById<Event>(eventId) : rest;
|
|
61
|
+
return Events.findOne(selector, options);
|
|
36
62
|
},
|
|
37
63
|
|
|
38
64
|
findEvents: async ({ limit, offset, sort, ...query }) => {
|