@sprucelabs/spruce-event-utils 40.1.248 → 40.1.249
Sign up to get free protection for your applications and to get access to all the features.
- package/build/errors/SpruceError.js +2 -3
- package/build/services/RemoteService.js +4 -5
- package/build/tests/utilities/eventErrorAssert.utility.js +2 -3
- package/build/utilities/buildEmitTargetAndPayloadSchema.js +3 -5
- package/build/utilities/eventContract.utility.js +3 -4
- package/build/utilities/eventDisk.utility.js +1 -1
- package/build/utilities/eventName.utility.js +2 -2
- package/build/utilities/eventResponse.utility.js +3 -6
- package/package.json +8 -8
- package/tsconfig.json +1 -1
@@ -7,10 +7,9 @@ const error_1 = __importDefault(require("@sprucelabs/error"));
|
|
7
7
|
class SpruceError extends error_1.default {
|
8
8
|
/** An easy to understand version of the errors */
|
9
9
|
friendlyMessage() {
|
10
|
-
var _a, _b, _c;
|
11
10
|
const { options } = this;
|
12
11
|
let message;
|
13
|
-
switch (options
|
12
|
+
switch (options?.code) {
|
14
13
|
case 'INVALID_EVENT_NAME':
|
15
14
|
message = `I couldn't find an event called ${options.fullyQualifiedEventName}. Next step is 'spruce create.event'!`;
|
16
15
|
break;
|
@@ -19,7 +18,7 @@ class SpruceError extends error_1.default {
|
|
19
18
|
message = `Got ${errors.length === 1 ? 'an error' : `${errors.length} errors`} from the server:\n\n`;
|
20
19
|
const errorMessages = [];
|
21
20
|
for (const err of errors) {
|
22
|
-
errorMessages.push(
|
21
|
+
errorMessages.push(err.stack ?? err.options?.friendlyMessage ?? err.message);
|
23
22
|
}
|
24
23
|
message += errorMessages.join('\n');
|
25
24
|
break;
|
@@ -22,17 +22,16 @@ class RemoteService {
|
|
22
22
|
return this.env.get('HOST');
|
23
23
|
}
|
24
24
|
getRemote() {
|
25
|
-
var _a, _b;
|
26
25
|
// move to constants or some better mapping?
|
27
26
|
const values = Object.entries(constants_1.REMOTES);
|
28
27
|
const host = this.getHost();
|
29
28
|
if (typeof host === 'undefined') {
|
30
29
|
return null;
|
31
30
|
}
|
32
|
-
const hostStr =
|
33
|
-
const match = values.find((v) =>
|
31
|
+
const hostStr = host?.toString?.();
|
32
|
+
const match = values.find((v) => hostStr?.indexOf?.(v[1]) > -1);
|
34
33
|
if (!match) {
|
35
|
-
if (
|
34
|
+
if (hostStr?.startsWith?.('http')) {
|
36
35
|
return 'custom';
|
37
36
|
}
|
38
37
|
throw new schema_1.SchemaError({
|
@@ -41,7 +40,7 @@ class RemoteService {
|
|
41
40
|
parameters: ['env.HOST'],
|
42
41
|
});
|
43
42
|
}
|
44
|
-
return match
|
43
|
+
return match?.[0];
|
45
44
|
}
|
46
45
|
}
|
47
46
|
exports.default = RemoteService;
|
@@ -7,10 +7,9 @@ const test_utils_1 = require("@sprucelabs/test-utils");
|
|
7
7
|
const eventResponse_utility_1 = __importDefault(require("../../utilities/eventResponse.utility"));
|
8
8
|
const eventAssertUtil = {
|
9
9
|
assertError(error, expectedCode, expectedPartialOptions) {
|
10
|
-
var _a, _b, _c;
|
11
10
|
test_utils_1.errorAssert.assertError(error, 'MERCURY_RESPONSE_ERROR');
|
12
|
-
if (
|
13
|
-
test_utils_1.assert.fail(`Mercury response has more than 1 error and I was expecting only 1.\n\nReceived:\n\n${test_utils_1.assertUtil.stringify(
|
11
|
+
if (error?.options?.responseErrors?.length > 1) {
|
12
|
+
test_utils_1.assert.fail(`Mercury response has more than 1 error and I was expecting only 1.\n\nReceived:\n\n${test_utils_1.assertUtil.stringify(error?.options?.responseErrors)}`);
|
14
13
|
}
|
15
14
|
test_utils_1.errorAssert.assertError(error.options.responseErrors[0], expectedCode, expectedPartialOptions);
|
16
15
|
return error.options.responseErrors[0];
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
7
7
|
const eventSource_schema_1 = __importDefault(require("./../.spruce/schemas/spruceEventUtils/v2021_09_13/eventSource.schema"));
|
8
8
|
function buildEmitTargetAndPayloadSchema(options) {
|
9
|
-
var _a, _b;
|
10
9
|
const { eventName, payloadSchema: emitPayloadSchema, targetSchema, } = options;
|
11
10
|
const targetField = {
|
12
11
|
type: 'schema',
|
@@ -27,13 +26,13 @@ function buildEmitTargetAndPayloadSchema(options) {
|
|
27
26
|
},
|
28
27
|
},
|
29
28
|
};
|
30
|
-
const hasTargetFields = targetSchema && Object.keys(
|
29
|
+
const hasTargetFields = targetSchema && Object.keys(targetSchema.fields ?? {}).length > 0;
|
31
30
|
if (hasTargetFields) {
|
32
31
|
//@ts-ignore
|
33
32
|
schema.fields.target = targetField;
|
34
33
|
}
|
35
34
|
const hasPayloadFields = emitPayloadSchema &&
|
36
|
-
Object.keys(
|
35
|
+
Object.keys(emitPayloadSchema.fields ?? {}).length > 0;
|
37
36
|
if (hasPayloadFields) {
|
38
37
|
const isRequired = hasAnyRequiredFields(emitPayloadSchema);
|
39
38
|
//@ts-ignore
|
@@ -49,6 +48,5 @@ function buildEmitTargetAndPayloadSchema(options) {
|
|
49
48
|
}
|
50
49
|
exports.default = buildEmitTargetAndPayloadSchema;
|
51
50
|
function hasAnyRequiredFields(schema) {
|
52
|
-
|
53
|
-
return !!Object.keys((_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : {}).find((f) => { var _a; return (_a = schema === null || schema === void 0 ? void 0 : schema.fields) === null || _a === void 0 ? void 0 : _a[f].isRequired; });
|
51
|
+
return !!Object.keys(schema?.fields ?? {}).find((f) => schema?.fields?.[f].isRequired);
|
54
52
|
}
|
@@ -22,7 +22,7 @@ const eventContractUtil = {
|
|
22
22
|
eventSignatures: {},
|
23
23
|
};
|
24
24
|
let existingNames = [];
|
25
|
-
for (const contract of contracts
|
25
|
+
for (const contract of contracts ?? []) {
|
26
26
|
const names = Object.keys(contract.eventSignatures);
|
27
27
|
for (const name of names) {
|
28
28
|
if (existingNames.indexOf(name) > -1) {
|
@@ -53,9 +53,8 @@ const eventContractUtil = {
|
|
53
53
|
return false;
|
54
54
|
});
|
55
55
|
matchesOnVersion.sort((a, b) => {
|
56
|
-
|
57
|
-
const
|
58
|
-
const v2 = (_b = b.split('::').pop()) !== null && _b !== void 0 ? _b : 0;
|
56
|
+
const v1 = a.split('::').pop() ?? 0;
|
57
|
+
const v2 = b.split('::').pop() ?? 0;
|
59
58
|
if (v1 > v2) {
|
60
59
|
return 1;
|
61
60
|
}
|
@@ -13,7 +13,7 @@ const eventDiskUtil = {
|
|
13
13
|
(0, schema_1.assertOptions)(e, ['eventName', 'version']);
|
14
14
|
const fqen = eventName_utility_1.default.join(e);
|
15
15
|
const { eventName, eventNamespace, version } = eventName_utility_1.default.split(fqen);
|
16
|
-
return spruce_skill_utils_1.diskUtil.resolvePath(destination, eventNamespace
|
16
|
+
return spruce_skill_utils_1.diskUtil.resolvePath(destination, eventNamespace ?? '', eventName + '.' + version + '.listener.ts');
|
17
17
|
},
|
18
18
|
splitPathToListener(match, seperator = '/') {
|
19
19
|
const matches = new RegExp(`([a-z0-9\\-]+)\\${seperator}([a-z0-9\\-]+)\\.(v[0-9]{4}_[0-9]{2}_[0-9]{2})\\.listener.[t|j]s`).exec(match);
|
@@ -27,8 +27,8 @@ const eventNameUtil = {
|
|
27
27
|
join(options) {
|
28
28
|
const { eventName: eventNameOptions, eventNamespace: eventNamespaceOptions, version: versionOptions, } = options;
|
29
29
|
let { eventName, eventNamespace, version } = this.split(eventNameOptions);
|
30
|
-
eventNamespace = eventNamespaceOptions
|
31
|
-
version = versionOptions
|
30
|
+
eventNamespace = eventNamespaceOptions ?? eventNamespace;
|
31
|
+
version = versionOptions ?? version;
|
32
32
|
function optionallyAttachversion(name) {
|
33
33
|
if (version) {
|
34
34
|
return name + constants_1.EVENT_VERSION_DIVIDER + version;
|
@@ -19,8 +19,7 @@ const eventResponseUtil = {
|
|
19
19
|
return response;
|
20
20
|
},
|
21
21
|
getFirstResponseOrThrow(emitResponse) {
|
22
|
-
|
23
|
-
if (!((_a = emitResponse === null || emitResponse === void 0 ? void 0 : emitResponse.responses) === null || _a === void 0 ? void 0 : _a[0])) {
|
22
|
+
if (!emitResponse?.responses?.[0]) {
|
24
23
|
throw new SpruceError_1.default({
|
25
24
|
code: 'MERCURY_RESPONSE_ERROR',
|
26
25
|
responseErrors: [
|
@@ -51,11 +50,9 @@ const eventResponseUtil = {
|
|
51
50
|
this.mutatingMapAggregateResponseErrorsToSpruceErrors(emitResponse, ClassRef);
|
52
51
|
results.errors = [];
|
53
52
|
emitResponse.responses.forEach((r) => {
|
54
|
-
|
55
|
-
(_a = r.errors) === null || _a === void 0 ? void 0 : _a.forEach((err) => {
|
56
|
-
var _a;
|
53
|
+
r.errors?.forEach((err) => {
|
57
54
|
//@ts-ignore
|
58
|
-
|
55
|
+
results.errors?.push(err);
|
59
56
|
});
|
60
57
|
});
|
61
58
|
}
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"publishConfig": {
|
4
4
|
"access": "public"
|
5
5
|
},
|
6
|
-
"version": "40.1.
|
6
|
+
"version": "40.1.249",
|
7
7
|
"files": [
|
8
8
|
"build/**/*",
|
9
9
|
"!build/__tests__",
|
@@ -56,21 +56,21 @@
|
|
56
56
|
"watch.tsc": "tsc -w"
|
57
57
|
},
|
58
58
|
"dependencies": {
|
59
|
-
"@sprucelabs/error": "^6.0.
|
59
|
+
"@sprucelabs/error": "^6.0.479",
|
60
60
|
"@sprucelabs/mercury-types": "^47.0.528",
|
61
|
-
"@sprucelabs/schema": "^30.0.
|
61
|
+
"@sprucelabs/schema": "^30.0.488",
|
62
62
|
"@sprucelabs/spruce-core-schemas": "^40.1.472",
|
63
|
-
"@sprucelabs/spruce-skill-utils": "^31.0.
|
64
|
-
"@sprucelabs/test-utils": "^5.1.
|
63
|
+
"@sprucelabs/spruce-skill-utils": "^31.0.547",
|
64
|
+
"@sprucelabs/test-utils": "^5.1.432"
|
65
65
|
},
|
66
66
|
"devDependencies": {
|
67
67
|
"@sprucelabs/esm-postbuild": "^6.0.461",
|
68
|
-
"@sprucelabs/jest-json-reporter": "^8.0.
|
68
|
+
"@sprucelabs/jest-json-reporter": "^8.0.479",
|
69
69
|
"@sprucelabs/resolve-path-aliases": "^2.0.456",
|
70
70
|
"@sprucelabs/semantic-release": "^5.0.2",
|
71
|
-
"@sprucelabs/test": "^9.0.
|
71
|
+
"@sprucelabs/test": "^9.0.51",
|
72
72
|
"@types/memoizee": "^0.4.11",
|
73
|
-
"@types/node": "^22.7.
|
73
|
+
"@types/node": "^22.7.6",
|
74
74
|
"chokidar-cli": "^3.0.0",
|
75
75
|
"eslint": "^9.12.0",
|
76
76
|
"eslint-config-spruce": "^11.2.26",
|