@sprucelabs/spruce-event-utils 40.1.248 → 40.1.249

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.
@@ -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 === null || options === void 0 ? void 0 : options.code) {
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((_c = (_a = err.stack) !== null && _a !== void 0 ? _a : (_b = err.options) === null || _b === void 0 ? void 0 : _b.friendlyMessage) !== null && _c !== void 0 ? _c : err.message);
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 = (_a = host === null || host === void 0 ? void 0 : host.toString) === null || _a === void 0 ? void 0 : _a.call(host);
33
- const match = values.find((v) => { var _a; return ((_a = hostStr === null || hostStr === void 0 ? void 0 : hostStr.indexOf) === null || _a === void 0 ? void 0 : _a.call(hostStr, v[1])) > -1; });
31
+ const hostStr = host?.toString?.();
32
+ const match = values.find((v) => hostStr?.indexOf?.(v[1]) > -1);
34
33
  if (!match) {
35
- if ((_b = hostStr === null || hostStr === void 0 ? void 0 : hostStr.startsWith) === null || _b === void 0 ? void 0 : _b.call(hostStr, 'http')) {
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 === null || match === void 0 ? void 0 : match[0];
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 (((_b = (_a = error === null || error === void 0 ? void 0 : error.options) === null || _a === void 0 ? void 0 : _a.responseErrors) === null || _b === void 0 ? void 0 : _b.length) > 1) {
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((_c = error === null || error === void 0 ? void 0 : error.options) === null || _c === void 0 ? void 0 : _c.responseErrors)}`);
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((_a = targetSchema.fields) !== null && _a !== void 0 ? _a : {}).length > 0;
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((_b = emitPayloadSchema.fields) !== null && _b !== void 0 ? _b : {}).length > 0;
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
- var _a;
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 !== null && contracts !== void 0 ? 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
- var _a, _b;
57
- const v1 = (_a = a.split('::').pop()) !== null && _a !== void 0 ? _a : 0;
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 !== null && eventNamespace !== void 0 ? eventNamespace : '', eventName + '.' + version + '.listener.ts');
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 !== null && eventNamespaceOptions !== void 0 ? eventNamespaceOptions : eventNamespace;
31
- version = versionOptions !== null && versionOptions !== void 0 ? versionOptions : version;
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
- var _a;
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
- var _a;
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
- (_a = results.errors) === null || _a === void 0 ? void 0 : _a.push(err);
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.248",
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.477",
59
+ "@sprucelabs/error": "^6.0.479",
60
60
  "@sprucelabs/mercury-types": "^47.0.528",
61
- "@sprucelabs/schema": "^30.0.486",
61
+ "@sprucelabs/schema": "^30.0.488",
62
62
  "@sprucelabs/spruce-core-schemas": "^40.1.472",
63
- "@sprucelabs/spruce-skill-utils": "^31.0.545",
64
- "@sprucelabs/test-utils": "^5.1.427"
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.477",
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.50",
71
+ "@sprucelabs/test": "^9.0.51",
72
72
  "@types/memoizee": "^0.4.11",
73
- "@types/node": "^22.7.5",
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",
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "skipLibCheck": true,
4
4
  "module": "commonjs",
5
5
  "esModuleInterop": true,
6
- "target": "ES2019",
6
+ "target": "ES2020",
7
7
  "lib": [
8
8
  "DOM",
9
9
  "ES2022"