@magek/common 0.0.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/dist/app.d.ts +17 -0
- package/dist/app.js +2 -0
- package/dist/concepts/authorizers.d.ts +7 -0
- package/dist/concepts/authorizers.js +2 -0
- package/dist/concepts/command.d.ts +14 -0
- package/dist/concepts/command.js +2 -0
- package/dist/concepts/data-migration.d.ts +19 -0
- package/dist/concepts/data-migration.js +8 -0
- package/dist/concepts/entity.d.ts +12 -0
- package/dist/concepts/entity.js +2 -0
- package/dist/concepts/event-handler.d.ts +6 -0
- package/dist/concepts/event-handler.js +2 -0
- package/dist/concepts/event-stream-configuration.d.ts +14 -0
- package/dist/concepts/event-stream-configuration.js +2 -0
- package/dist/concepts/event.d.ts +12 -0
- package/dist/concepts/event.js +2 -0
- package/dist/concepts/filter-hooks.d.ts +15 -0
- package/dist/concepts/filter-hooks.js +2 -0
- package/dist/concepts/global-error-handler-metadata.d.ts +24 -0
- package/dist/concepts/global-error-handler-metadata.js +2 -0
- package/dist/concepts/index.d.ts +21 -0
- package/dist/concepts/index.js +24 -0
- package/dist/concepts/migration.d.ts +8 -0
- package/dist/concepts/migration.js +2 -0
- package/dist/concepts/notification.d.ts +12 -0
- package/dist/concepts/notification.js +2 -0
- package/dist/concepts/projection-metadata.d.ts +15 -0
- package/dist/concepts/projection-metadata.js +8 -0
- package/dist/concepts/query.d.ts +21 -0
- package/dist/concepts/query.js +2 -0
- package/dist/concepts/read-model.d.ts +33 -0
- package/dist/concepts/read-model.js +8 -0
- package/dist/concepts/reducer-metadata.d.ts +5 -0
- package/dist/concepts/reducer-metadata.js +2 -0
- package/dist/concepts/register.d.ts +91 -0
- package/dist/concepts/register.js +84 -0
- package/dist/concepts/role.d.ts +27 -0
- package/dist/concepts/role.js +2 -0
- package/dist/concepts/scheduled-command.d.ts +10 -0
- package/dist/concepts/scheduled-command.js +2 -0
- package/dist/concepts/sequence-metadata.d.ts +5 -0
- package/dist/concepts/sequence-metadata.js +2 -0
- package/dist/concepts/token-verifier.d.ts +25 -0
- package/dist/concepts/token-verifier.js +2 -0
- package/dist/concepts/uuid.d.ts +18 -0
- package/dist/concepts/uuid.js +28 -0
- package/dist/config.d.ts +122 -0
- package/dist/config.js +180 -0
- package/dist/data-migration-parameters.d.ts +3 -0
- package/dist/data-migration-parameters.js +2 -0
- package/dist/envelope.d.ts +188 -0
- package/dist/envelope.js +2 -0
- package/dist/errors/command-handler-global-error.d.ts +8 -0
- package/dist/errors/command-handler-global-error.js +12 -0
- package/dist/errors/event-global-error.d.ts +6 -0
- package/dist/errors/event-global-error.js +11 -0
- package/dist/errors/event-handler-global-error.d.ts +9 -0
- package/dist/errors/event-handler-global-error.js +13 -0
- package/dist/errors/global-error-container.d.ts +4 -0
- package/dist/errors/global-error-container.js +9 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/projection-global-error.d.ts +10 -0
- package/dist/errors/projection-global-error.js +14 -0
- package/dist/errors/query-handler-global-error.d.ts +6 -0
- package/dist/errors/query-handler-global-error.js +11 -0
- package/dist/errors/reducer-global-error.d.ts +10 -0
- package/dist/errors/reducer-global-error.js +14 -0
- package/dist/errors/schedule-command-global-error.d.ts +8 -0
- package/dist/errors/schedule-command-global-error.js +12 -0
- package/dist/errors/snapshot-persist-handler-global-error.d.ts +16 -0
- package/dist/errors/snapshot-persist-handler-global-error.js +21 -0
- package/dist/errors.d.ts +30 -0
- package/dist/errors.js +60 -0
- package/dist/event-store-adapter.d.ts +123 -0
- package/dist/event-store-adapter.js +2 -0
- package/dist/field-decorator.d.ts +63 -0
- package/dist/field-decorator.js +122 -0
- package/dist/graphql-websocket-messages.d.ts +65 -0
- package/dist/graphql-websocket-messages.js +55 -0
- package/dist/groups.d.ts +4 -0
- package/dist/groups.js +9 -0
- package/dist/http-service.d.ts +10 -0
- package/dist/http-service.js +50 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +33 -0
- package/dist/instances.d.ts +47 -0
- package/dist/instances.js +136 -0
- package/dist/instrumentation/trace-types.d.ts +52 -0
- package/dist/instrumentation/trace-types.js +34 -0
- package/dist/internal-info.d.ts +2 -0
- package/dist/internal-info.js +6 -0
- package/dist/logger.d.ts +14 -0
- package/dist/logger.js +33 -0
- package/dist/metadata-types.d.ts +28 -0
- package/dist/metadata-types.js +12 -0
- package/dist/promises.d.ts +25 -0
- package/dist/promises.js +42 -0
- package/dist/provider/azure-configuration.d.ts +12 -0
- package/dist/provider/azure-configuration.js +4 -0
- package/dist/provider.d.ts +83 -0
- package/dist/provider.js +2 -0
- package/dist/read-model-store-adapter.d.ts +84 -0
- package/dist/read-model-store-adapter.js +2 -0
- package/dist/retrier.d.ts +12 -0
- package/dist/retrier.js +36 -0
- package/dist/rocket-loader.d.ts +7 -0
- package/dist/rocket-loader.js +21 -0
- package/dist/rockets.d.ts +10 -0
- package/dist/rockets.js +4 -0
- package/dist/run-command.d.ts +5 -0
- package/dist/run-command.js +48 -0
- package/dist/schedule.d.ts +8 -0
- package/dist/schedule.js +2 -0
- package/dist/searcher.d.ts +98 -0
- package/dist/searcher.js +79 -0
- package/dist/sensor/health-indicator-configuration.d.ts +60 -0
- package/dist/sensor/health-indicator-configuration.js +31 -0
- package/dist/session-store-adapter.d.ts +103 -0
- package/dist/session-store-adapter.js +2 -0
- package/dist/stream-types.d.ts +1 -0
- package/dist/stream-types.js +2 -0
- package/dist/super-kind.d.ts +2 -0
- package/dist/super-kind.js +5 -0
- package/dist/typelevel.d.ts +28 -0
- package/dist/typelevel.js +9 -0
- package/dist/user-app.d.ts +18 -0
- package/dist/user-app.js +2 -0
- package/package.json +66 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.graphQLWebsocketSubprotocolHeaders = exports.GraphQLComplete = exports.GraphQLError = exports.GraphQLData = exports.GraphQLInitAck = exports.GraphQLInitError = exports.MessageTypes = void 0;
|
|
4
|
+
var MessageTypes;
|
|
5
|
+
(function (MessageTypes) {
|
|
6
|
+
MessageTypes["GQL_CONNECTION_INIT"] = "connection_init";
|
|
7
|
+
MessageTypes["GQL_CONNECTION_ACK"] = "connection_ack";
|
|
8
|
+
MessageTypes["GQL_CONNECTION_ERROR"] = "connection_error";
|
|
9
|
+
// GQL_CONNECTION_KEEP_ALIVE = 'ka', // Not used on server side. Socket remains open until client decides to close it
|
|
10
|
+
MessageTypes["GQL_CONNECTION_TERMINATE"] = "connection_terminate";
|
|
11
|
+
MessageTypes["GQL_START"] = "start";
|
|
12
|
+
MessageTypes["GQL_DATA"] = "data";
|
|
13
|
+
MessageTypes["GQL_ERROR"] = "error";
|
|
14
|
+
MessageTypes["GQL_COMPLETE"] = "complete";
|
|
15
|
+
MessageTypes["GQL_STOP"] = "stop";
|
|
16
|
+
})(MessageTypes || (exports.MessageTypes = MessageTypes = {}));
|
|
17
|
+
class GraphQLInitError {
|
|
18
|
+
constructor(payload) {
|
|
19
|
+
this.payload = payload;
|
|
20
|
+
this.type = MessageTypes.GQL_CONNECTION_ERROR;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.GraphQLInitError = GraphQLInitError;
|
|
24
|
+
class GraphQLInitAck {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.type = MessageTypes.GQL_CONNECTION_ACK;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.GraphQLInitAck = GraphQLInitAck;
|
|
30
|
+
class GraphQLData {
|
|
31
|
+
constructor(id, payload) {
|
|
32
|
+
this.id = id;
|
|
33
|
+
this.payload = payload;
|
|
34
|
+
this.type = MessageTypes.GQL_DATA;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.GraphQLData = GraphQLData;
|
|
38
|
+
class GraphQLError {
|
|
39
|
+
constructor(id, payload) {
|
|
40
|
+
this.id = id;
|
|
41
|
+
this.payload = payload;
|
|
42
|
+
this.type = MessageTypes.GQL_ERROR;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.GraphQLError = GraphQLError;
|
|
46
|
+
class GraphQLComplete {
|
|
47
|
+
constructor(id) {
|
|
48
|
+
this.id = id;
|
|
49
|
+
this.type = MessageTypes.GQL_COMPLETE;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.GraphQLComplete = GraphQLComplete;
|
|
53
|
+
exports.graphQLWebsocketSubprotocolHeaders = {
|
|
54
|
+
'Sec-WebSocket-Protocol': 'graphql-ws',
|
|
55
|
+
};
|
package/dist/groups.d.ts
ADDED
package/dist/groups.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface PostConfiguration {
|
|
2
|
+
contentType?: string;
|
|
3
|
+
timeout?: number;
|
|
4
|
+
acceptedStatusCodes?: number[];
|
|
5
|
+
}
|
|
6
|
+
export interface PostResult {
|
|
7
|
+
status: number;
|
|
8
|
+
body: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare function request(url: string, method?: 'GET' | 'POST', data?: string, config?: PostConfiguration): Promise<PostResult>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.request = request;
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
async function request(url, method = 'GET', data = '', config = {}) {
|
|
7
|
+
const { contentType = 'application/json', timeout = 10000, acceptedStatusCodes = [] } = config;
|
|
8
|
+
const options = {
|
|
9
|
+
method: method,
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': contentType,
|
|
12
|
+
// Content-Length will be added below if needed
|
|
13
|
+
},
|
|
14
|
+
timeout: timeout,
|
|
15
|
+
};
|
|
16
|
+
if (data) {
|
|
17
|
+
;
|
|
18
|
+
options.headers['Content-Length'] = data.length;
|
|
19
|
+
}
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const method = url.startsWith('https') ? https.request : http.request;
|
|
22
|
+
const request = method(url, options, (res) => {
|
|
23
|
+
const body = [];
|
|
24
|
+
res.on('data', (chunk) => body.push(chunk));
|
|
25
|
+
res.on('end', () => {
|
|
26
|
+
if (!(res === null || res === void 0 ? void 0 : res.statusCode)) {
|
|
27
|
+
return reject(new Error('Unknown HTTP status code'));
|
|
28
|
+
}
|
|
29
|
+
// Accept 2xx codes or any explicitly accepted status codes
|
|
30
|
+
if ((res.statusCode < 200 || res.statusCode > 299) && !acceptedStatusCodes.includes(res.statusCode)) {
|
|
31
|
+
return reject(new Error(`HTTP status code ${res.statusCode}`));
|
|
32
|
+
}
|
|
33
|
+
const buffer = Buffer.concat(body).toString();
|
|
34
|
+
resolve({
|
|
35
|
+
status: res === null || res === void 0 ? void 0 : res.statusCode,
|
|
36
|
+
body: buffer,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
request.on('error', (err) => {
|
|
41
|
+
reject(err);
|
|
42
|
+
});
|
|
43
|
+
request.on('timeout', () => {
|
|
44
|
+
request.destroy();
|
|
45
|
+
reject(new Error('Request time out'));
|
|
46
|
+
});
|
|
47
|
+
request.write(data);
|
|
48
|
+
request.end();
|
|
49
|
+
});
|
|
50
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from './groups';
|
|
2
|
+
export * from './promises';
|
|
3
|
+
export * from './retrier';
|
|
4
|
+
export * from './instances';
|
|
5
|
+
export * from './run-command';
|
|
6
|
+
export * from './logger';
|
|
7
|
+
export * from './http-service';
|
|
8
|
+
export * from './app';
|
|
9
|
+
export * from './envelope';
|
|
10
|
+
export * from './config';
|
|
11
|
+
export * from './concepts';
|
|
12
|
+
export * from './typelevel';
|
|
13
|
+
export * from './errors';
|
|
14
|
+
export * from './errors/index';
|
|
15
|
+
export * from './user-app';
|
|
16
|
+
export * from './searcher';
|
|
17
|
+
export * from './graphql-websocket-messages';
|
|
18
|
+
export * from './schedule';
|
|
19
|
+
export * from './data-migration-parameters';
|
|
20
|
+
export * from './super-kind';
|
|
21
|
+
export * from './instrumentation/trace-types';
|
|
22
|
+
export * from './sensor/health-indicator-configuration';
|
|
23
|
+
export * from './internal-info';
|
|
24
|
+
export * from './stream-types';
|
|
25
|
+
export * from './provider';
|
|
26
|
+
export * from './event-store-adapter';
|
|
27
|
+
export * from './read-model-store-adapter';
|
|
28
|
+
export * from './session-store-adapter';
|
|
29
|
+
export * from './field-decorator';
|
|
30
|
+
export * from './metadata-types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./groups"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./promises"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./retrier"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./instances"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./run-command"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./logger"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./http-service"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./app"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./envelope"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./config"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./concepts"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./typelevel"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./errors/index"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./user-app"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./searcher"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./graphql-websocket-messages"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./schedule"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./data-migration-parameters"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./super-kind"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./instrumentation/trace-types"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./sensor/health-indicator-configuration"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./internal-info"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./stream-types"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./provider"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./event-store-adapter"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./read-model-store-adapter"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./session-store-adapter"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./field-decorator"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./metadata-types"), exports);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Class } from './typelevel';
|
|
2
|
+
import { ProjectionFor } from './searcher';
|
|
3
|
+
import { ReadModelInterface } from './concepts';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an instance of the given class from the given raw object.
|
|
6
|
+
*
|
|
7
|
+
* @param instanceClass The class of the instance to create
|
|
8
|
+
* @param rawObject The raw object to use as source
|
|
9
|
+
*
|
|
10
|
+
* @returns An instance of the given class
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createInstance } from '@magek/common'
|
|
15
|
+
* import { User } from './entities/user'
|
|
16
|
+
*
|
|
17
|
+
* const rawUser = {
|
|
18
|
+
* id: '123',
|
|
19
|
+
* name: 'John Doe',
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const user = createInstance(User, rawUser)
|
|
23
|
+
*
|
|
24
|
+
* console.log(user.id) // Prints '123'
|
|
25
|
+
* console.log(user.name) // Prints 'John Doe'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createInstance<T>(instanceClass: Class<T>, rawObject: Record<string, any>): T;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an array of instances of the given class from the given array of raw objects.
|
|
31
|
+
*
|
|
32
|
+
* @param instanceClass The class of the instances to create
|
|
33
|
+
* @param rawObjects The array of raw objects to use as source
|
|
34
|
+
*
|
|
35
|
+
* @returns An array of instances of the given class
|
|
36
|
+
*
|
|
37
|
+
* @see {@link createInstance}
|
|
38
|
+
*/
|
|
39
|
+
export declare function createInstances<T>(instanceClass: Class<T>, rawObjects: Array<Record<string, any>>): T[];
|
|
40
|
+
/**
|
|
41
|
+
* Creates an instance of the read model class with the calculated properties included
|
|
42
|
+
* @param instanceClass The read model class
|
|
43
|
+
* @param raw The raw read model data
|
|
44
|
+
* @param propertiesToInclude The properties to include in the response
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
export declare function createInstanceWithCalculatedProperties<T extends ReadModelInterface>(instanceClass: Class<T>, raw: Partial<T>, propertiesToInclude: ProjectionFor<T>): Promise<T>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInstance = createInstance;
|
|
4
|
+
exports.createInstances = createInstances;
|
|
5
|
+
exports.createInstanceWithCalculatedProperties = createInstanceWithCalculatedProperties;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an instance of the given class from the given raw object.
|
|
8
|
+
*
|
|
9
|
+
* @param instanceClass The class of the instance to create
|
|
10
|
+
* @param rawObject The raw object to use as source
|
|
11
|
+
*
|
|
12
|
+
* @returns An instance of the given class
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { createInstance } from '@magek/common'
|
|
17
|
+
* import { User } from './entities/user'
|
|
18
|
+
*
|
|
19
|
+
* const rawUser = {
|
|
20
|
+
* id: '123',
|
|
21
|
+
* name: 'John Doe',
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const user = createInstance(User, rawUser)
|
|
25
|
+
*
|
|
26
|
+
* console.log(user.id) // Prints '123'
|
|
27
|
+
* console.log(user.name) // Prints 'John Doe'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function createInstance(instanceClass, rawObject) {
|
|
31
|
+
const instance = new instanceClass();
|
|
32
|
+
return Object.assign(instance, rawObject);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an array of instances of the given class from the given array of raw objects.
|
|
36
|
+
*
|
|
37
|
+
* @param instanceClass The class of the instances to create
|
|
38
|
+
* @param rawObjects The array of raw objects to use as source
|
|
39
|
+
*
|
|
40
|
+
* @returns An array of instances of the given class
|
|
41
|
+
*
|
|
42
|
+
* @see {@link createInstance}
|
|
43
|
+
*/
|
|
44
|
+
function createInstances(instanceClass, rawObjects) {
|
|
45
|
+
return rawObjects.map((rawObject) => createInstance(instanceClass, rawObject));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates an instance of the read model class with the calculated properties included
|
|
49
|
+
* @param instanceClass The read model class
|
|
50
|
+
* @param raw The raw read model data
|
|
51
|
+
* @param propertiesToInclude The properties to include in the response
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
async function createInstanceWithCalculatedProperties(instanceClass, raw, propertiesToInclude) {
|
|
55
|
+
const instance = new instanceClass();
|
|
56
|
+
Object.assign(instance, raw);
|
|
57
|
+
const result = {};
|
|
58
|
+
const propertiesMap = buildPropertiesMap(propertiesToInclude);
|
|
59
|
+
await processProperties(instance, result, propertiesMap);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Builds a map of properties to include in the response
|
|
64
|
+
* @param properties The properties to include in the response
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
function buildPropertiesMap(properties) {
|
|
68
|
+
const map = {};
|
|
69
|
+
properties.forEach((property) => {
|
|
70
|
+
const parts = property.split('.');
|
|
71
|
+
let current = map;
|
|
72
|
+
parts.forEach((part) => {
|
|
73
|
+
const isArray = part.endsWith('[]');
|
|
74
|
+
const key = isArray ? part.slice(0, -2) : part;
|
|
75
|
+
if (!Object.prototype.hasOwnProperty.call(current, key)) {
|
|
76
|
+
current[key] = isArray ? { __isArray: true, __children: {} } : {};
|
|
77
|
+
}
|
|
78
|
+
current = isArray ? current[key].__children : current[key];
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return map;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Processes the properties of the source object and adds them to the result object
|
|
85
|
+
* @param source The source object
|
|
86
|
+
* @param result The result object
|
|
87
|
+
* @param propertiesMap The map of properties to include in the response
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
async function processProperties(source, result, propertiesMap) {
|
|
91
|
+
for (const key of Object.keys(propertiesMap)) {
|
|
92
|
+
if (key === '__isArray' || key === '__children')
|
|
93
|
+
continue;
|
|
94
|
+
if (source[key] !== undefined) {
|
|
95
|
+
if (propertiesMap[key].__isArray) {
|
|
96
|
+
result[key] = [];
|
|
97
|
+
const value = source[key];
|
|
98
|
+
const resolvedValue = isPromise(value) ? await value : value;
|
|
99
|
+
for (const item of resolvedValue) {
|
|
100
|
+
const newItem = {};
|
|
101
|
+
await processProperties(item, newItem, propertiesMap[key].__children);
|
|
102
|
+
if (Object.keys(newItem).length > 0) {
|
|
103
|
+
result[key].push(newItem);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (typeof propertiesMap[key] === 'object' && Object.keys(propertiesMap[key]).length > 0) {
|
|
108
|
+
const value = source[key];
|
|
109
|
+
const resolvedValue = isPromise(value) ? await value : value;
|
|
110
|
+
if (resolvedValue === undefined || resolvedValue === null) {
|
|
111
|
+
result[key] = null;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
result[key] = {};
|
|
115
|
+
await processProperties(resolvedValue, result[key], propertiesMap[key]);
|
|
116
|
+
if (Object.keys(result[key]).length === 0) {
|
|
117
|
+
result[key] = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const value = source[key];
|
|
123
|
+
result[key] = isPromise(value) ? await value : value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Handle the case when the source property is undefined
|
|
128
|
+
if (typeof propertiesMap[key] === 'object' && Object.keys(propertiesMap[key]).length > 0) {
|
|
129
|
+
result[key] = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function isPromise(obj) {
|
|
135
|
+
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
136
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { UUID } from '../concepts';
|
|
2
|
+
import { MagekConfig } from '../config';
|
|
3
|
+
export declare enum TraceTypes {
|
|
4
|
+
START = 0,
|
|
5
|
+
END = 1
|
|
6
|
+
}
|
|
7
|
+
export declare enum TraceActionTypes {
|
|
8
|
+
CUSTOM = "CUSTOM",
|
|
9
|
+
EVENT_HANDLERS_PROCESS = "EVENT_HANDLERS_PROCESS",
|
|
10
|
+
HANDLE_EVENT = "HANDLE_EVENT",
|
|
11
|
+
DISPATCH_ENTITY_TO_EVENT_HANDLERS = "DISPATCH_ENTITY_TO_EVENT_HANDLERS",
|
|
12
|
+
DISPATCH_EVENTS = "DISPATCH_EVENTS",
|
|
13
|
+
CONSUME_STREAM_EVENTS = "CONSUME_STREAM_EVENTS",
|
|
14
|
+
PRODUCE_STREAM_EVENTS = "PRODUCE_STREAM_EVENTS",
|
|
15
|
+
FETCH_ENTITY_SNAPSHOT = "FETCH_ENTITY_SNAPSHOT",
|
|
16
|
+
STORE_SNAPSHOT = "STORE_SNAPSHOT",
|
|
17
|
+
LOAD_LATEST_SNAPSHOT = "LOAD_LATEST_SNAPSHOT",
|
|
18
|
+
LOAD_EVENT_STREAM_SINCE = "LOAD_EVENT_STREAM_SINCE",
|
|
19
|
+
ENTITY_REDUCER = "ENTITY_REDUCER",
|
|
20
|
+
READ_MODEL_FIND_BY_ID = "READ_MODEL_FIND_BY_ID",
|
|
21
|
+
GRAPHQL_READ_MODEL_SEARCH = "GRAPHQL_READ_MODEL_SEARCH",
|
|
22
|
+
READ_MODEL_SEARCH = "READ_MODEL_SEARCH",
|
|
23
|
+
COMMAND_HANDLER = "COMMAND_HANDLER",
|
|
24
|
+
MIGRATION_RUN = "MIGRATION_RUN",
|
|
25
|
+
GRAPHQL_DISPATCH = "GRAPHQL_DISPATCH",
|
|
26
|
+
GRAPHQL_RUN_OPERATION = "GRAPHQL_RUN_OPERATION",
|
|
27
|
+
SCHEDULED_COMMAND_HANDLER = "SCHEDULED_COMMAND_HANDLER",
|
|
28
|
+
DISPATCH_SUBSCRIBER_NOTIFIER = "DISPATCH_SUBSCRIBER_NOTIFIER",
|
|
29
|
+
READ_MODEL_SCHEMA_MIGRATOR_MIGRATE = "READ_MODEL_SCHEMA_MIGRATOR_MIGRATE",
|
|
30
|
+
SCHEMA_MIGRATOR_MIGRATE = "SCHEMA_MIGRATOR_MIGRATE"
|
|
31
|
+
}
|
|
32
|
+
export interface TraceInfo {
|
|
33
|
+
className: string;
|
|
34
|
+
methodName: string;
|
|
35
|
+
args: Array<unknown>;
|
|
36
|
+
traceId: UUID;
|
|
37
|
+
elapsedInvocationMillis?: number;
|
|
38
|
+
internal?: {
|
|
39
|
+
target: unknown;
|
|
40
|
+
descriptor: PropertyDescriptor;
|
|
41
|
+
};
|
|
42
|
+
description?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TraceHandler {
|
|
45
|
+
(config: MagekConfig, actionType: string, traceInfo: TraceInfo): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export interface TraceConfiguration {
|
|
48
|
+
enableTraceNotification: boolean | Array<string>;
|
|
49
|
+
includeInternal?: boolean;
|
|
50
|
+
onStart: TraceHandler;
|
|
51
|
+
onEnd: TraceHandler;
|
|
52
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceActionTypes = exports.TraceTypes = void 0;
|
|
4
|
+
var TraceTypes;
|
|
5
|
+
(function (TraceTypes) {
|
|
6
|
+
TraceTypes[TraceTypes["START"] = 0] = "START";
|
|
7
|
+
TraceTypes[TraceTypes["END"] = 1] = "END";
|
|
8
|
+
})(TraceTypes || (exports.TraceTypes = TraceTypes = {}));
|
|
9
|
+
var TraceActionTypes;
|
|
10
|
+
(function (TraceActionTypes) {
|
|
11
|
+
TraceActionTypes["CUSTOM"] = "CUSTOM";
|
|
12
|
+
TraceActionTypes["EVENT_HANDLERS_PROCESS"] = "EVENT_HANDLERS_PROCESS";
|
|
13
|
+
TraceActionTypes["HANDLE_EVENT"] = "HANDLE_EVENT";
|
|
14
|
+
TraceActionTypes["DISPATCH_ENTITY_TO_EVENT_HANDLERS"] = "DISPATCH_ENTITY_TO_EVENT_HANDLERS";
|
|
15
|
+
TraceActionTypes["DISPATCH_EVENTS"] = "DISPATCH_EVENTS";
|
|
16
|
+
TraceActionTypes["CONSUME_STREAM_EVENTS"] = "CONSUME_STREAM_EVENTS";
|
|
17
|
+
TraceActionTypes["PRODUCE_STREAM_EVENTS"] = "PRODUCE_STREAM_EVENTS";
|
|
18
|
+
TraceActionTypes["FETCH_ENTITY_SNAPSHOT"] = "FETCH_ENTITY_SNAPSHOT";
|
|
19
|
+
TraceActionTypes["STORE_SNAPSHOT"] = "STORE_SNAPSHOT";
|
|
20
|
+
TraceActionTypes["LOAD_LATEST_SNAPSHOT"] = "LOAD_LATEST_SNAPSHOT";
|
|
21
|
+
TraceActionTypes["LOAD_EVENT_STREAM_SINCE"] = "LOAD_EVENT_STREAM_SINCE";
|
|
22
|
+
TraceActionTypes["ENTITY_REDUCER"] = "ENTITY_REDUCER";
|
|
23
|
+
TraceActionTypes["READ_MODEL_FIND_BY_ID"] = "READ_MODEL_FIND_BY_ID";
|
|
24
|
+
TraceActionTypes["GRAPHQL_READ_MODEL_SEARCH"] = "GRAPHQL_READ_MODEL_SEARCH";
|
|
25
|
+
TraceActionTypes["READ_MODEL_SEARCH"] = "READ_MODEL_SEARCH";
|
|
26
|
+
TraceActionTypes["COMMAND_HANDLER"] = "COMMAND_HANDLER";
|
|
27
|
+
TraceActionTypes["MIGRATION_RUN"] = "MIGRATION_RUN";
|
|
28
|
+
TraceActionTypes["GRAPHQL_DISPATCH"] = "GRAPHQL_DISPATCH";
|
|
29
|
+
TraceActionTypes["GRAPHQL_RUN_OPERATION"] = "GRAPHQL_RUN_OPERATION";
|
|
30
|
+
TraceActionTypes["SCHEDULED_COMMAND_HANDLER"] = "SCHEDULED_COMMAND_HANDLER";
|
|
31
|
+
TraceActionTypes["DISPATCH_SUBSCRIBER_NOTIFIER"] = "DISPATCH_SUBSCRIBER_NOTIFIER";
|
|
32
|
+
TraceActionTypes["READ_MODEL_SCHEMA_MIGRATOR_MIGRATE"] = "READ_MODEL_SCHEMA_MIGRATOR_MIGRATE";
|
|
33
|
+
TraceActionTypes["SCHEMA_MIGRATOR_MIGRATE"] = "SCHEMA_MIGRATOR_MIGRATE";
|
|
34
|
+
})(TraceActionTypes || (exports.TraceActionTypes = TraceActionTypes = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.localPort = exports.MAGEK_LOCAL_PORT = void 0;
|
|
4
|
+
exports.MAGEK_LOCAL_PORT = 'INTERNAL_LOCAL_PORT';
|
|
5
|
+
const localPort = () => process.env[exports.MAGEK_LOCAL_PORT] || '3000';
|
|
6
|
+
exports.localPort = localPort;
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MagekConfig } from './config';
|
|
2
|
+
export declare enum Level {
|
|
3
|
+
debug = 0,
|
|
4
|
+
info = 1,
|
|
5
|
+
warn = 2,
|
|
6
|
+
error = 3
|
|
7
|
+
}
|
|
8
|
+
export interface Logger {
|
|
9
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
10
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
12
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function getLogger(config: MagekConfig, location?: string, overridenLogPrefix?: string): Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Level = void 0;
|
|
4
|
+
exports.getLogger = getLogger;
|
|
5
|
+
var Level;
|
|
6
|
+
(function (Level) {
|
|
7
|
+
Level[Level["debug"] = 0] = "debug";
|
|
8
|
+
Level[Level["info"] = 1] = "info";
|
|
9
|
+
Level[Level["warn"] = 2] = "warn";
|
|
10
|
+
Level[Level["error"] = 3] = "error";
|
|
11
|
+
})(Level || (exports.Level = Level = {}));
|
|
12
|
+
const defaultLogPrefix = 'Magek';
|
|
13
|
+
function getLogger(config, location, overridenLogPrefix) {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
15
|
+
const debug = (_b = (_a = config.logger) === null || _a === void 0 ? void 0 : _a.debug) !== null && _b !== void 0 ? _b : console.debug;
|
|
16
|
+
const info = (_d = (_c = config.logger) === null || _c === void 0 ? void 0 : _c.info) !== null && _d !== void 0 ? _d : console.info;
|
|
17
|
+
const warn = (_f = (_e = config.logger) === null || _e === void 0 ? void 0 : _e.warn) !== null && _f !== void 0 ? _f : console.warn;
|
|
18
|
+
const error = (_h = (_g = config.logger) === null || _g === void 0 ? void 0 : _g.error) !== null && _h !== void 0 ? _h : console.error;
|
|
19
|
+
const logPrefix = (_j = overridenLogPrefix !== null && overridenLogPrefix !== void 0 ? overridenLogPrefix : config === null || config === void 0 ? void 0 : config.logPrefix) !== null && _j !== void 0 ? _j : defaultLogPrefix;
|
|
20
|
+
const locationStr = location ? `|${location}: ` : ': ';
|
|
21
|
+
const prefix = `[${logPrefix}]${locationStr}`;
|
|
22
|
+
const prefixedDebugFunction = debug.bind(null, prefix);
|
|
23
|
+
const prefixedInfoFunction = info.bind(null, prefix);
|
|
24
|
+
const prefixedWarnFunction = warn.bind(null, prefix);
|
|
25
|
+
const prefixedErrFunction = error.bind(null, prefix);
|
|
26
|
+
return {
|
|
27
|
+
debug: config.logLevel <= Level.debug ? prefixedDebugFunction : noopLog,
|
|
28
|
+
info: config.logLevel <= Level.info ? prefixedInfoFunction : noopLog,
|
|
29
|
+
warn: config.logLevel <= Level.warn ? prefixedWarnFunction : noopLog,
|
|
30
|
+
error: prefixedErrFunction,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function noopLog() { }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export type ClassType = {
|
|
3
|
+
new (...args: unknown[]): unknown;
|
|
4
|
+
};
|
|
5
|
+
export type TypeGroup = 'String' | 'Number' | 'Boolean' | 'Enum' | 'Union' | 'Intersection' | 'Function' | 'Class' | 'Interface' | 'Type' | 'Array' | 'Object' | 'ReadonlyArray' | 'Other';
|
|
6
|
+
export interface TypeMetadata {
|
|
7
|
+
name: string;
|
|
8
|
+
typeGroup: TypeGroup;
|
|
9
|
+
parameters: Array<TypeMetadata>;
|
|
10
|
+
isNullable: boolean;
|
|
11
|
+
isGetAccessor: boolean;
|
|
12
|
+
typeName?: string;
|
|
13
|
+
importPath?: string;
|
|
14
|
+
type?: ClassType;
|
|
15
|
+
}
|
|
16
|
+
export interface PropertyMetadata {
|
|
17
|
+
name: string;
|
|
18
|
+
typeInfo: TypeMetadata;
|
|
19
|
+
dependencies: Array<string>;
|
|
20
|
+
}
|
|
21
|
+
export interface ClassMetadata {
|
|
22
|
+
name: string;
|
|
23
|
+
type: ClassType;
|
|
24
|
+
fields: Array<PropertyMetadata>;
|
|
25
|
+
methods: Array<PropertyMetadata>;
|
|
26
|
+
}
|
|
27
|
+
export declare function defineMetadata(metadataKey: string | symbol, metadataValue: unknown, target: object): void;
|
|
28
|
+
export declare function getMetadata<T>(metadataKey: string | symbol, target: object): T | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineMetadata = defineMetadata;
|
|
4
|
+
exports.getMetadata = getMetadata;
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
// Metadata helper functions
|
|
7
|
+
function defineMetadata(metadataKey, metadataValue, target) {
|
|
8
|
+
Reflect.defineMetadata(metadataKey, metadataValue, target);
|
|
9
|
+
}
|
|
10
|
+
function getMetadata(metadataKey, target) {
|
|
11
|
+
return Reflect.getMetadata(metadataKey, target);
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class Promises {
|
|
2
|
+
/**
|
|
3
|
+
* Waits until all the passed promise-like values are settled, no matter if they were fulfilled or rejected.
|
|
4
|
+
* If some rejected were found, an array with all the rejected promises is thrown.
|
|
5
|
+
* If all were fulfilled, an array of PromiseFulfilledResult is returned
|
|
6
|
+
* @param values Array of promise-like values to be wait for
|
|
7
|
+
* @throws an array of PromiseRejectedResult with all the rejected promises, if any
|
|
8
|
+
*
|
|
9
|
+
* Comparison with other similar Promise methods:
|
|
10
|
+
* - `Promise.all`: This has an "all-or-nothing" behavior. As long as one of the promises is rejected, the result is
|
|
11
|
+
* rejected. More importantly, **it does not wait for al the promises to finish**, which could lead to undesired behaviors
|
|
12
|
+
* - `Promise.allSettled`: This method waits for all the promises to finish and then returns an array of results. Some
|
|
13
|
+
* of them will be fulfilled and some rejected. More importantly, **it never throws an error**, which could lead to
|
|
14
|
+
* unexpected consequences. For example if you do "await Promise.allSettle(...)" expecting it to throw if some of them
|
|
15
|
+
* failed, you won't get that.
|
|
16
|
+
*
|
|
17
|
+
* In brief, `Promises.allSettledAndFulfilled` behaves exactly the same way as `Promise.allSettle` but it throws with
|
|
18
|
+
* an array of the failed promises, only if there are any.
|
|
19
|
+
*/
|
|
20
|
+
static allSettledAndFulfilled<TValue>(values: Iterable<TValue>): ReturnType<PromiseConstructor['allSettled']>;
|
|
21
|
+
}
|
|
22
|
+
export declare class PromisesError extends Error {
|
|
23
|
+
readonly failedReasons: Array<unknown>;
|
|
24
|
+
constructor(rejectedResults: Array<PromiseRejectedResult>);
|
|
25
|
+
}
|
package/dist/promises.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromisesError = exports.Promises = void 0;
|
|
4
|
+
class Promises {
|
|
5
|
+
/**
|
|
6
|
+
* Waits until all the passed promise-like values are settled, no matter if they were fulfilled or rejected.
|
|
7
|
+
* If some rejected were found, an array with all the rejected promises is thrown.
|
|
8
|
+
* If all were fulfilled, an array of PromiseFulfilledResult is returned
|
|
9
|
+
* @param values Array of promise-like values to be wait for
|
|
10
|
+
* @throws an array of PromiseRejectedResult with all the rejected promises, if any
|
|
11
|
+
*
|
|
12
|
+
* Comparison with other similar Promise methods:
|
|
13
|
+
* - `Promise.all`: This has an "all-or-nothing" behavior. As long as one of the promises is rejected, the result is
|
|
14
|
+
* rejected. More importantly, **it does not wait for al the promises to finish**, which could lead to undesired behaviors
|
|
15
|
+
* - `Promise.allSettled`: This method waits for all the promises to finish and then returns an array of results. Some
|
|
16
|
+
* of them will be fulfilled and some rejected. More importantly, **it never throws an error**, which could lead to
|
|
17
|
+
* unexpected consequences. For example if you do "await Promise.allSettle(...)" expecting it to throw if some of them
|
|
18
|
+
* failed, you won't get that.
|
|
19
|
+
*
|
|
20
|
+
* In brief, `Promises.allSettledAndFulfilled` behaves exactly the same way as `Promise.allSettle` but it throws with
|
|
21
|
+
* an array of the failed promises, only if there are any.
|
|
22
|
+
*/
|
|
23
|
+
static async allSettledAndFulfilled(values) {
|
|
24
|
+
const results = await Promise.allSettled(values); // Promise.allSettled never throws
|
|
25
|
+
// Get all the failed promises
|
|
26
|
+
const failed = results.filter((result) => result.status === 'rejected');
|
|
27
|
+
// Throw if we found any failed ones
|
|
28
|
+
if (failed.length > 0) {
|
|
29
|
+
throw new PromisesError(failed);
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Promises = Promises;
|
|
35
|
+
class PromisesError extends Error {
|
|
36
|
+
constructor(rejectedResults) {
|
|
37
|
+
const reasons = rejectedResults.map((res) => res.reason);
|
|
38
|
+
super(reasons.join('. '));
|
|
39
|
+
this.failedReasons = reasons;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.PromisesError = PromisesError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_CHUNK_SIZE = 100;
|
|
2
|
+
export interface AzureConfiguration {
|
|
3
|
+
enableEventBatching: boolean;
|
|
4
|
+
cosmos: {
|
|
5
|
+
batchSize: number;
|
|
6
|
+
requestOptions?: {
|
|
7
|
+
consistencyLevel?: 'Strong' | 'BoundedStaleness' | 'Session' | 'Eventual' | 'ConsistentPrefix';
|
|
8
|
+
disableRUPerMinuteUsage?: boolean;
|
|
9
|
+
indexingDirective?: 'Include' | 'Exclude';
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|