@sprucelabs/spruce-event-utils 40.1.394 → 40.2.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.
@@ -1,10 +1,12 @@
1
- import { EventContract, EventNames } from '@sprucelabs/mercury-types';
1
+ import { EventContract, EventName } from '@sprucelabs/mercury-types';
2
2
  import { NamedEventSignature } from '../types/event.types';
3
3
  declare const eventContractUtil: {
4
4
  getEventNames(contract: EventContract, namespace?: string): string[];
5
5
  getNamedEventSignatures(contract: EventContract): NamedEventSignature[];
6
- unifyContracts<Contract extends EventContract = import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventContract>(contracts: Contract[]): Contract | undefined;
6
+ unifyContracts<Contract extends EventContract = import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventContract>(contracts: Contract[], options?: {
7
+ shouldUpsert?: boolean;
8
+ }): Contract | undefined;
7
9
  resolveToLatestEventName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: string): string | undefined;
8
- getSignatureByName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: EventNames<Contract>): import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventSignature;
10
+ getSignatureByName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: EventName<Contract>): import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventSignature;
9
11
  };
10
12
  export default eventContractUtil;
@@ -9,25 +9,28 @@ const eventContractUtil = {
9
9
  getNamedEventSignatures(contract) {
10
10
  return getNamedEventSignatures(contract);
11
11
  },
12
- unifyContracts(contracts) {
12
+ unifyContracts(contracts, options) {
13
13
  if (!contracts || contracts.length === 0) {
14
14
  return undefined;
15
15
  }
16
+ const { shouldUpsert = false } = options !== null && options !== void 0 ? options : {};
16
17
  const unifiedContract = {
17
18
  eventSignatures: {},
18
19
  };
19
20
  let existingNames = [];
20
21
  for (const contract of contracts !== null && contracts !== void 0 ? contracts : []) {
21
- const names = Object.keys(contract.eventSignatures);
22
- for (const name of names) {
23
- if (existingNames.indexOf(name) > -1) {
24
- throw new SpruceError({
25
- code: 'DUPLICATE_EVENT',
26
- fullyQualifiedEventName: name,
27
- });
22
+ if (!shouldUpsert) {
23
+ const names = Object.keys(contract.eventSignatures);
24
+ for (const name of names) {
25
+ if (existingNames.indexOf(name) > -1) {
26
+ throw new SpruceError({
27
+ code: 'DUPLICATE_EVENT',
28
+ fullyQualifiedEventName: name,
29
+ });
30
+ }
28
31
  }
32
+ existingNames.push(...names);
29
33
  }
30
- existingNames.push(...names);
31
34
  unifiedContract.eventSignatures = Object.assign(Object.assign({}, unifiedContract.eventSignatures), contract.eventSignatures);
32
35
  }
33
36
  return unifiedContract;
@@ -1,10 +1,12 @@
1
- import { EventContract, EventNames } from '@sprucelabs/mercury-types';
1
+ import { EventContract, EventName } from '@sprucelabs/mercury-types';
2
2
  import { NamedEventSignature } from '../types/event.types';
3
3
  declare const eventContractUtil: {
4
4
  getEventNames(contract: EventContract, namespace?: string): string[];
5
5
  getNamedEventSignatures(contract: EventContract): NamedEventSignature[];
6
- unifyContracts<Contract extends EventContract = import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventContract>(contracts: Contract[]): Contract | undefined;
6
+ unifyContracts<Contract extends EventContract = import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventContract>(contracts: Contract[], options?: {
7
+ shouldUpsert?: boolean;
8
+ }): Contract | undefined;
7
9
  resolveToLatestEventName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: string): string | undefined;
8
- getSignatureByName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: EventNames<Contract>): import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventSignature;
10
+ getSignatureByName<Contract extends EventContract>(contract: Contract, fullyQualifiedEventName: EventName<Contract>): import("@sprucelabs/mercury-types").SpruceSchemas.Mercury.v2020_12_25.EventSignature;
9
11
  };
10
12
  export default eventContractUtil;
@@ -14,25 +14,28 @@ const eventContractUtil = {
14
14
  getNamedEventSignatures(contract) {
15
15
  return getNamedEventSignatures(contract);
16
16
  },
17
- unifyContracts(contracts) {
17
+ unifyContracts(contracts, options) {
18
18
  if (!contracts || contracts.length === 0) {
19
19
  return undefined;
20
20
  }
21
+ const { shouldUpsert = false } = options ?? {};
21
22
  const unifiedContract = {
22
23
  eventSignatures: {},
23
24
  };
24
25
  let existingNames = [];
25
26
  for (const contract of contracts ?? []) {
26
- const names = Object.keys(contract.eventSignatures);
27
- for (const name of names) {
28
- if (existingNames.indexOf(name) > -1) {
29
- throw new SpruceError_1.default({
30
- code: 'DUPLICATE_EVENT',
31
- fullyQualifiedEventName: name,
32
- });
27
+ if (!shouldUpsert) {
28
+ const names = Object.keys(contract.eventSignatures);
29
+ for (const name of names) {
30
+ if (existingNames.indexOf(name) > -1) {
31
+ throw new SpruceError_1.default({
32
+ code: 'DUPLICATE_EVENT',
33
+ fullyQualifiedEventName: name,
34
+ });
35
+ }
33
36
  }
37
+ existingNames.push(...names);
34
38
  }
35
- existingNames.push(...names);
36
39
  unifiedContract.eventSignatures = {
37
40
  ...unifiedContract.eventSignatures,
38
41
  ...contract.eventSignatures,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "40.1.394",
6
+ "version": "40.2.0",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",
@@ -60,7 +60,7 @@
60
60
  "@sprucelabs/mercury-types": "^47.2.0",
61
61
  "@sprucelabs/schema": "^31.0.19",
62
62
  "@sprucelabs/spruce-core-schemas": "^40.1.605",
63
- "@sprucelabs/spruce-skill-utils": "^31.2.16",
63
+ "@sprucelabs/spruce-skill-utils": "^31.2.18",
64
64
  "@sprucelabs/test-utils": "^5.1.546"
65
65
  },
66
66
  "devDependencies": {