@modular-rest/server 1.14.1 → 1.16.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 +1 -1
- package/dist/class/cms_trigger.d.ts +4 -13
- package/dist/class/cms_trigger.js +1 -1
- package/dist/class/database_trigger.d.ts +10 -4
- package/dist/class/user.d.ts +1 -1
- package/dist/services/data_provider/router.js +3 -2
- package/package.json +1 -1
- package/src/class/cms_trigger.ts +8 -14
- package/src/class/database_trigger.ts +10 -4
- package/src/class/user.ts +1 -1
- package/src/services/data_provider/router.ts +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DatabaseTriggerContext } from './database_trigger';
|
|
1
2
|
/**
|
|
2
3
|
* Type for CMS operations that can trigger a callback
|
|
3
4
|
* @typedef {('update-one' | 'insert-one' | 'remove-one')} CmsOperation
|
|
@@ -7,16 +8,6 @@
|
|
|
7
8
|
* - 'remove-one': Triggered when removing a document from the CMS
|
|
8
9
|
*/
|
|
9
10
|
export type CmsOperation = 'update-one' | 'insert-one' | 'remove-one';
|
|
10
|
-
/**
|
|
11
|
-
* Context interface for CMS trigger callbacks
|
|
12
|
-
* @interface CmsTriggerContext
|
|
13
|
-
* @property {Record<string, any>} query - The query parameters used in the CMS operation
|
|
14
|
-
* @property {any} queryResult - The result of the CMS operation
|
|
15
|
-
*/
|
|
16
|
-
export interface CmsTriggerContext {
|
|
17
|
-
query: Record<string, any>;
|
|
18
|
-
queryResult: any;
|
|
19
|
-
}
|
|
20
11
|
/**
|
|
21
12
|
* Defines a callback to be executed on specific CMS operations
|
|
22
13
|
* @class CmsTrigger
|
|
@@ -26,7 +17,7 @@ export interface CmsTriggerContext {
|
|
|
26
17
|
* ```typescript
|
|
27
18
|
* const trigger = new CmsTrigger('insert-one', (context) => {
|
|
28
19
|
* console.log('New CMS document inserted:', context.queryResult);
|
|
29
|
-
* // Perform additional actions after CMS document insertion
|
|
20
|
+
* // Perform additional actions after CMS document insertion.
|
|
30
21
|
* });
|
|
31
22
|
*
|
|
32
23
|
* // Use the trigger in RestOptions
|
|
@@ -38,7 +29,7 @@ export interface CmsTriggerContext {
|
|
|
38
29
|
*/
|
|
39
30
|
export declare class CmsTrigger {
|
|
40
31
|
operation: CmsOperation;
|
|
41
|
-
callback: (context:
|
|
32
|
+
callback: (context: DatabaseTriggerContext) => void;
|
|
42
33
|
/**
|
|
43
34
|
* Creates a new CmsTrigger instance
|
|
44
35
|
* @param {CmsOperation} operation - The CMS operation to trigger on
|
|
@@ -56,6 +47,6 @@ export declare class CmsTrigger {
|
|
|
56
47
|
* });
|
|
57
48
|
* ```
|
|
58
49
|
*/
|
|
59
|
-
constructor(operation: CmsOperation, callback?: (context:
|
|
50
|
+
constructor(operation: CmsOperation, callback?: (context: DatabaseTriggerContext) => void);
|
|
60
51
|
}
|
|
61
52
|
export default CmsTrigger;
|
|
@@ -10,7 +10,7 @@ exports.CmsTrigger = void 0;
|
|
|
10
10
|
* ```typescript
|
|
11
11
|
* const trigger = new CmsTrigger('insert-one', (context) => {
|
|
12
12
|
* console.log('New CMS document inserted:', context.queryResult);
|
|
13
|
-
* // Perform additional actions after CMS document insertion
|
|
13
|
+
* // Perform additional actions after CMS document insertion.
|
|
14
14
|
* });
|
|
15
15
|
*
|
|
16
16
|
* // Use the trigger in RestOptions
|
|
@@ -5,12 +5,18 @@ export type DatabaseOperation = 'find' | 'find-one' | 'count' | 'update-one' | '
|
|
|
5
5
|
/**
|
|
6
6
|
* Context interface for database trigger callbacks
|
|
7
7
|
* @interface DatabaseTriggerContext
|
|
8
|
-
* @property {Record<string, any>}
|
|
9
|
-
* @property {
|
|
8
|
+
* @property {Record<string, any>} doc - The document data for insert/update operations
|
|
9
|
+
* @property {Record<string, any>} query - The query data for find/find-one operations
|
|
10
|
+
* @property {Record<string, any>} update - The update data for update operations
|
|
11
|
+
* @property {Record<string, any>[]} pipelines - The aggregation pipelines for aggregate operations
|
|
12
|
+
* @property {Record<string, any> } queryResult - The result of the database operation
|
|
10
13
|
*/
|
|
11
14
|
export interface DatabaseTriggerContext {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
doc?: Record<string, any>;
|
|
16
|
+
query?: Record<string, any>;
|
|
17
|
+
update?: Record<string, any>;
|
|
18
|
+
pipelines?: Record<string, any>[];
|
|
19
|
+
queryResult: Record<string, any>;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* The callback function to be executed on specific database operations
|
package/dist/class/user.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class User {
|
|
|
37
37
|
*
|
|
38
38
|
* @hidden
|
|
39
39
|
*/
|
|
40
|
-
constructor(id: string, permissionGroup: string, phone: string, email: string, password: string, type:
|
|
40
|
+
constructor(id: string, permissionGroup: string, phone: string, email: string, password: string, type: 'user' | 'anonymous', model: any);
|
|
41
41
|
/**
|
|
42
42
|
* Get brief user information
|
|
43
43
|
* @returns Brief user info object
|
|
@@ -227,6 +227,7 @@ dataProvider.post('/update-one', async (ctx) => {
|
|
|
227
227
|
// Call trigger
|
|
228
228
|
service.triggers.call('update-one', body.database, body.collection, {
|
|
229
229
|
query: body.query,
|
|
230
|
+
update: body.update,
|
|
230
231
|
queryResult: writeOpResult,
|
|
231
232
|
});
|
|
232
233
|
ctx.body = { data: writeOpResult };
|
|
@@ -261,7 +262,7 @@ dataProvider.post('/insert-one', async (ctx) => {
|
|
|
261
262
|
.then(async (newDoc) => {
|
|
262
263
|
// Call trigger
|
|
263
264
|
service.triggers.call('insert-one', body.database, body.collection, {
|
|
264
|
-
|
|
265
|
+
doc: body.doc,
|
|
265
266
|
queryResult: newDoc,
|
|
266
267
|
});
|
|
267
268
|
ctx.body = { data: newDoc };
|
|
@@ -329,7 +330,7 @@ dataProvider.post('/aggregate', async (ctx) => {
|
|
|
329
330
|
.then(async (result) => {
|
|
330
331
|
// Call trigger
|
|
331
332
|
service.triggers.call('aggregate', body.database, body.collection, {
|
|
332
|
-
|
|
333
|
+
pipelines: body.pipelines,
|
|
333
334
|
queryResult: result,
|
|
334
335
|
});
|
|
335
336
|
ctx.body = { data: result };
|
package/package.json
CHANGED
package/src/class/cms_trigger.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DatabaseTriggerContext } from './database_trigger';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Type for CMS operations that can trigger a callback
|
|
3
5
|
* @typedef {('update-one' | 'insert-one' | 'remove-one')} CmsOperation
|
|
@@ -8,17 +10,6 @@
|
|
|
8
10
|
*/
|
|
9
11
|
export type CmsOperation = 'update-one' | 'insert-one' | 'remove-one';
|
|
10
12
|
|
|
11
|
-
/**
|
|
12
|
-
* Context interface for CMS trigger callbacks
|
|
13
|
-
* @interface CmsTriggerContext
|
|
14
|
-
* @property {Record<string, any>} query - The query parameters used in the CMS operation
|
|
15
|
-
* @property {any} queryResult - The result of the CMS operation
|
|
16
|
-
*/
|
|
17
|
-
export interface CmsTriggerContext {
|
|
18
|
-
query: Record<string, any>;
|
|
19
|
-
queryResult: any;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
13
|
/**
|
|
23
14
|
* Defines a callback to be executed on specific CMS operations
|
|
24
15
|
* @class CmsTrigger
|
|
@@ -28,7 +19,7 @@ export interface CmsTriggerContext {
|
|
|
28
19
|
* ```typescript
|
|
29
20
|
* const trigger = new CmsTrigger('insert-one', (context) => {
|
|
30
21
|
* console.log('New CMS document inserted:', context.queryResult);
|
|
31
|
-
* // Perform additional actions after CMS document insertion
|
|
22
|
+
* // Perform additional actions after CMS document insertion.
|
|
32
23
|
* });
|
|
33
24
|
*
|
|
34
25
|
* // Use the trigger in RestOptions
|
|
@@ -40,7 +31,7 @@ export interface CmsTriggerContext {
|
|
|
40
31
|
*/
|
|
41
32
|
export class CmsTrigger {
|
|
42
33
|
operation: CmsOperation;
|
|
43
|
-
callback: (context:
|
|
34
|
+
callback: (context: DatabaseTriggerContext) => void;
|
|
44
35
|
|
|
45
36
|
/**
|
|
46
37
|
* Creates a new CmsTrigger instance
|
|
@@ -59,7 +50,10 @@ export class CmsTrigger {
|
|
|
59
50
|
* });
|
|
60
51
|
* ```
|
|
61
52
|
*/
|
|
62
|
-
constructor(
|
|
53
|
+
constructor(
|
|
54
|
+
operation: CmsOperation,
|
|
55
|
+
callback: (context: DatabaseTriggerContext) => void = () => {}
|
|
56
|
+
) {
|
|
63
57
|
this.operation = operation;
|
|
64
58
|
this.callback = callback;
|
|
65
59
|
}
|
|
@@ -13,12 +13,18 @@ export type DatabaseOperation =
|
|
|
13
13
|
/**
|
|
14
14
|
* Context interface for database trigger callbacks
|
|
15
15
|
* @interface DatabaseTriggerContext
|
|
16
|
-
* @property {Record<string, any>}
|
|
17
|
-
* @property {
|
|
16
|
+
* @property {Record<string, any>} doc - The document data for insert/update operations
|
|
17
|
+
* @property {Record<string, any>} query - The query data for find/find-one operations
|
|
18
|
+
* @property {Record<string, any>} update - The update data for update operations
|
|
19
|
+
* @property {Record<string, any>[]} pipelines - The aggregation pipelines for aggregate operations
|
|
20
|
+
* @property {Record<string, any> } queryResult - The result of the database operation
|
|
18
21
|
*/
|
|
19
22
|
export interface DatabaseTriggerContext {
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
doc?: Record<string, any>;
|
|
24
|
+
query?: Record<string, any>;
|
|
25
|
+
update?: Record<string, any>;
|
|
26
|
+
pipelines?: Record<string, any>[];
|
|
27
|
+
queryResult: Record<string, any>;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
/**
|
package/src/class/user.ts
CHANGED
|
@@ -244,6 +244,7 @@ dataProvider.post('/update-one', async (ctx: Context) => {
|
|
|
244
244
|
// Call trigger
|
|
245
245
|
service.triggers.call('update-one', body.database, body.collection, {
|
|
246
246
|
query: body.query,
|
|
247
|
+
update: body.update,
|
|
247
248
|
queryResult: writeOpResult,
|
|
248
249
|
});
|
|
249
250
|
|
|
@@ -290,7 +291,7 @@ dataProvider.post('/insert-one', async (ctx: Context) => {
|
|
|
290
291
|
.then(async newDoc => {
|
|
291
292
|
// Call trigger
|
|
292
293
|
service.triggers.call('insert-one', body.database, body.collection, {
|
|
293
|
-
|
|
294
|
+
doc: body.doc,
|
|
294
295
|
queryResult: newDoc,
|
|
295
296
|
});
|
|
296
297
|
|
|
@@ -381,7 +382,7 @@ dataProvider.post('/aggregate', async (ctx: Context) => {
|
|
|
381
382
|
.then(async (result: any) => {
|
|
382
383
|
// Call trigger
|
|
383
384
|
service.triggers.call('aggregate', body.database, body.collection, {
|
|
384
|
-
|
|
385
|
+
pipelines: body.pipelines,
|
|
385
386
|
queryResult: result,
|
|
386
387
|
});
|
|
387
388
|
|