@conduit-client/service-pubsub 3.20.0 → 3.20.3

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,6 +1,2 @@
1
- /*!
2
- * Copyright (c) 2022, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
1
+
6
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/dist/v1/index.js CHANGED
@@ -1,10 +1,5 @@
1
- /*!
2
- * Copyright (c) 2022, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
1
  import { isPromiseLike, resolvedPromiseLike } from "@conduit-client/utils";
7
- const EventTypeWildcard = Symbol("EventTypeWildcard");
2
+ const EventTypeWildcard = /* @__PURE__ */ Symbol("EventTypeWildcard");
8
3
  class DefaultPubSubService {
9
4
  constructor() {
10
5
  this.subscriptions = /* @__PURE__ */ new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/v1/pubsub.ts","../../src/v1/pub-sub-service.ts"],"sourcesContent":["import type { SyncOrAsync, Unsubscribe } from '@conduit-client/utils';\n\nexport const EventTypeWildcard = Symbol('EventTypeWildcard');\n\nexport type Event<Data = unknown> = {\n type: string | typeof EventTypeWildcard;\n data: Data;\n};\n\nexport type EventSubscription<Data = unknown> = {\n type: Event['type'];\n callback: (event: Event<Data>) => void | PromiseLike<void>;\n predicate?: (event: Event<Data>) => boolean;\n};\n\n/**\n * A subscription callback function.\n *\n * @typeParam CallbackArg type of the single argument passed to the callback function\n * @typeParam ReturnVal expected return type of the callback function\n */\nexport type SubscriptionCallback<CallbackArgs extends Array<unknown>, ReturnVal = void> = (\n ...arg: CallbackArgs\n) => ReturnVal;\n\n/**\n * A PubSub is a simple pub/sub mechanism. Callers can subscribe a\n * callback function to be invoked when a token is published.\n *\n * @typeParam PublishType type of token that can be published\n * @typeParam CallbackArg type of the single argument passed to the callback\n * @typeParam SubscribeType type that can be subscribed to; defaults to\n * PublishType, but can be set to a different type in cases where broader\n * semantics would be useful (eg Set<PublishType>)\n * @typeParam PulishOptions options that can be passed during publish\n * @typeParam CallbackReturnVal return type expected from callbacks\n */\nexport interface PubSub {\n /**\n * Creates a subscription that will invoke the specified callback when\n * PublishTypes matching the subscription are published.\n *\n * @param options.subscription specification of PublishTypes to be matched\n * @param options.callback callback to be invoked\n * @returns function that can be invoked to cancel the subscription\n */\n subscribe<Data = unknown>(subscription: EventSubscription<Data>): Unsubscribe;\n\n /**\n * Publishes the specified PublishType and invokes the callbacks of all\n * matching subscriptions.\n *\n * @param publishData PublishType to be published\n * @param options\n * @returns SyncOrAsync that can be used to determine when all callbacks\n * have been called\n */\n publish(publishData: Event): SyncOrAsync<void>;\n}\n","import { isPromiseLike, resolvedPromiseLike } from '@conduit-client/utils';\nimport { type EventSubscription, type Event, type PubSub, EventTypeWildcard } from './pubsub';\nimport type { NamedService, ServiceDescriptor, Unsubscribe } from '@conduit-client/utils';\n\n/**\n * An PubSubService tracks event topics and calls callbacks when\n * a matching event is fired.\n */\nexport type PubSubService = PubSub;\n\nexport type NamedPubSubService<Name extends string = 'pubSub'> = NamedService<Name, PubSubService>;\n\nexport type PubSubServiceDescriptor = ServiceDescriptor<PubSubService, 'pubSub', '1.0'>;\n\n/**\n * A simple implementation of PubSubService.\n */\nclass DefaultPubSubService implements PubSubService {\n private subscriptions = new Map<\n Event['type'], // event type acts as an index so that we don't have to search every subscription\n EventSubscription[]\n >();\n\n subscribe(subscription: EventSubscription): Unsubscribe {\n let eventTypeSubscriptions = this.subscriptions.get(subscription.type);\n if (eventTypeSubscriptions === undefined) {\n eventTypeSubscriptions = [];\n this.subscriptions.set(subscription.type, eventTypeSubscriptions);\n }\n\n eventTypeSubscriptions!.push(subscription);\n\n return () => {\n this.subscriptions.set(\n subscription.type,\n this.subscriptions.get(subscription.type)!.filter((value) => value !== subscription)\n );\n };\n }\n\n publish(event: Event): PromiseLike<void> {\n const promises: PromiseLike<void>[] = [];\n const subscriptions = this.getSubscriptions(event);\n\n subscriptions.forEach((subscription) => {\n // need to check that the subscription hasn't been unsubscribed during one of the callbacks\n if (!this.getSubscriptions(event).includes(subscription)) {\n return;\n }\n // Ensure callback maintains its context\n const returnVal = subscription.callback.call(subscription, event);\n\n if (isPromiseLike(returnVal)) {\n promises.push(returnVal);\n }\n });\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => undefined);\n }\n\n return resolvedPromiseLike(undefined);\n }\n\n getSubscriptions(event: Event) {\n const eventTypeSubscriptions = this.subscriptions.get(event.type);\n const wildcardSubscriptions = this.subscriptions.get(EventTypeWildcard);\n if (eventTypeSubscriptions === undefined && wildcardSubscriptions === undefined) {\n return [];\n }\n let matchingSubscriptions: EventSubscription[] = [];\n\n if (eventTypeSubscriptions !== undefined) {\n matchingSubscriptions = eventTypeSubscriptions.filter((subscription) => {\n if (subscription.predicate) {\n return subscription.predicate(event);\n }\n\n return true;\n });\n }\n matchingSubscriptions = [...matchingSubscriptions, ...(wildcardSubscriptions || [])];\n return matchingSubscriptions;\n }\n}\n\n/**\n * Constructs a default PubSubService\n *\n * @returns default PubSubServiceDescriptor\n */\nexport function buildServiceDescriptor(): PubSubServiceDescriptor {\n return {\n type: 'pubSub',\n version: '1.0',\n service: new DefaultPubSubService(),\n };\n}\n"],"names":[],"mappings":";;;;;;AAEO,MAAM,oBAAoB,OAAO,mBAAmB;ACe3D,MAAM,qBAA8C;AAAA,EAApD,cAAA;AACI,SAAQ,oCAAoB,IAAA;AAAA,EAG1B;AAAA,EAEF,UAAU,cAA8C;AACpD,QAAI,yBAAyB,KAAK,cAAc,IAAI,aAAa,IAAI;AACrE,QAAI,2BAA2B,QAAW;AACtC,+BAAyB,CAAA;AACzB,WAAK,cAAc,IAAI,aAAa,MAA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,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,IAAI,qBAAA;AAAA,EAAqB;AAE1C;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/v1/pubsub.ts","../../src/v1/pub-sub-service.ts"],"sourcesContent":["import type { SyncOrAsync, Unsubscribe } from '@conduit-client/utils';\n\nexport const EventTypeWildcard = Symbol('EventTypeWildcard');\n\nexport type Event<Data = unknown> = {\n type: string | typeof EventTypeWildcard;\n data: Data;\n};\n\nexport type EventSubscription<Data = unknown> = {\n type: Event['type'];\n callback: (event: Event<Data>) => void | PromiseLike<void>;\n predicate?: (event: Event<Data>) => boolean;\n};\n\n/**\n * A subscription callback function.\n *\n * @typeParam CallbackArg type of the single argument passed to the callback function\n * @typeParam ReturnVal expected return type of the callback function\n */\nexport type SubscriptionCallback<CallbackArgs extends Array<unknown>, ReturnVal = void> = (\n ...arg: CallbackArgs\n) => ReturnVal;\n\n/**\n * A PubSub is a simple pub/sub mechanism. Callers can subscribe a\n * callback function to be invoked when a token is published.\n *\n * @typeParam PublishType type of token that can be published\n * @typeParam CallbackArg type of the single argument passed to the callback\n * @typeParam SubscribeType type that can be subscribed to; defaults to\n * PublishType, but can be set to a different type in cases where broader\n * semantics would be useful (eg Set<PublishType>)\n * @typeParam PulishOptions options that can be passed during publish\n * @typeParam CallbackReturnVal return type expected from callbacks\n */\nexport interface PubSub {\n /**\n * Creates a subscription that will invoke the specified callback when\n * PublishTypes matching the subscription are published.\n *\n * @param options.subscription specification of PublishTypes to be matched\n * @param options.callback callback to be invoked\n * @returns function that can be invoked to cancel the subscription\n */\n subscribe<Data = unknown>(subscription: EventSubscription<Data>): Unsubscribe;\n\n /**\n * Publishes the specified PublishType and invokes the callbacks of all\n * matching subscriptions.\n *\n * @param publishData PublishType to be published\n * @param options\n * @returns SyncOrAsync that can be used to determine when all callbacks\n * have been called\n */\n publish(publishData: Event): SyncOrAsync<void>;\n}\n","import { isPromiseLike, resolvedPromiseLike } from '@conduit-client/utils';\nimport { type EventSubscription, type Event, type PubSub, EventTypeWildcard } from './pubsub';\nimport type { NamedService, ServiceDescriptor, Unsubscribe } from '@conduit-client/utils';\n\n/**\n * An PubSubService tracks event topics and calls callbacks when\n * a matching event is fired.\n */\nexport type PubSubService = PubSub;\n\nexport type NamedPubSubService<Name extends string = 'pubSub'> = NamedService<Name, PubSubService>;\n\nexport type PubSubServiceDescriptor = ServiceDescriptor<PubSubService, 'pubSub', '1.0'>;\n\n/**\n * A simple implementation of PubSubService.\n */\nclass DefaultPubSubService implements PubSubService {\n private subscriptions = new Map<\n Event['type'], // event type acts as an index so that we don't have to search every subscription\n EventSubscription[]\n >();\n\n subscribe(subscription: EventSubscription): Unsubscribe {\n let eventTypeSubscriptions = this.subscriptions.get(subscription.type);\n if (eventTypeSubscriptions === undefined) {\n eventTypeSubscriptions = [];\n this.subscriptions.set(subscription.type, eventTypeSubscriptions);\n }\n\n eventTypeSubscriptions!.push(subscription);\n\n return () => {\n this.subscriptions.set(\n subscription.type,\n this.subscriptions.get(subscription.type)!.filter((value) => value !== subscription)\n );\n };\n }\n\n publish(event: Event): PromiseLike<void> {\n const promises: PromiseLike<void>[] = [];\n const subscriptions = this.getSubscriptions(event);\n\n subscriptions.forEach((subscription) => {\n // need to check that the subscription hasn't been unsubscribed during one of the callbacks\n if (!this.getSubscriptions(event).includes(subscription)) {\n return;\n }\n // Ensure callback maintains its context\n const returnVal = subscription.callback.call(subscription, event);\n\n if (isPromiseLike(returnVal)) {\n promises.push(returnVal);\n }\n });\n\n if (promises.length > 0) {\n return Promise.all(promises).then(() => undefined);\n }\n\n return resolvedPromiseLike(undefined);\n }\n\n getSubscriptions(event: Event) {\n const eventTypeSubscriptions = this.subscriptions.get(event.type);\n const wildcardSubscriptions = this.subscriptions.get(EventTypeWildcard);\n if (eventTypeSubscriptions === undefined && wildcardSubscriptions === undefined) {\n return [];\n }\n let matchingSubscriptions: EventSubscription[] = [];\n\n if (eventTypeSubscriptions !== undefined) {\n matchingSubscriptions = eventTypeSubscriptions.filter((subscription) => {\n if (subscription.predicate) {\n return subscription.predicate(event);\n }\n\n return true;\n });\n }\n matchingSubscriptions = [...matchingSubscriptions, ...(wildcardSubscriptions || [])];\n return matchingSubscriptions;\n }\n}\n\n/**\n * Constructs a default PubSubService\n *\n * @returns default PubSubServiceDescriptor\n */\nexport function buildServiceDescriptor(): PubSubServiceDescriptor {\n return {\n type: 'pubSub',\n version: '1.0',\n service: new DefaultPubSubService(),\n };\n}\n"],"names":[],"mappings":";AAEO,MAAM,2CAA2B,mBAAmB;ACe3D,MAAM,qBAA8C;AAAA,EAApD,cAAA;AACI,SAAQ,oCAAoB,IAAA;AAAA,EAG1B;AAAA,EAEF,UAAU,cAA8C;AACpD,QAAI,yBAAyB,KAAK,cAAc,IAAI,aAAa,IAAI;AACrE,QAAI,2BAA2B,QAAW;AACtC,+BAAyB,CAAA;AACzB,WAAK,cAAc,IAAI,aAAa,MAAM,sBAAsB;AAAA,IACpE;AAEA,2BAAwB,KAAK,YAAY;AAEzC,WAAO,MAAM;AACT,WAAK,cAAc;AAAA,QACf,aAAa;AAAA,QACb,KAAK,cAAc,IAAI,aAAa,IAAI,EAAG,OAAO,CAAC,UAAU,UAAU,YAAY;AAAA,MAAA;AAAA,IAE3F;AAAA,EACJ;AAAA,EAEA,QAAQ,OAAiC;AACrC,UAAM,WAAgC,CAAA;AACtC,UAAM,gBAAgB,KAAK,iBAAiB,KAAK;AAEjD,kBAAc,QAAQ,CAAC,iBAAiB;AAEpC,UAAI,CAAC,KAAK,iBAAiB,KAAK,EAAE,SAAS,YAAY,GAAG;AACtD;AAAA,MACJ;AAEA,YAAM,YAAY,aAAa,SAAS,KAAK,cAAc,KAAK;AAEhE,UAAI,cAAc,SAAS,GAAG;AAC1B,iBAAS,KAAK,SAAS;AAAA,MAC3B;AAAA,IACJ,CAAC;AAED,QAAI,SAAS,SAAS,GAAG;AACrB,aAAO,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM,MAAS;AAAA,IACrD;AAEA,WAAO,oBAAoB,MAAS;AAAA,EACxC;AAAA,EAEA,iBAAiB,OAAc;AAC3B,UAAM,yBAAyB,KAAK,cAAc,IAAI,MAAM,IAAI;AAChE,UAAM,wBAAwB,KAAK,cAAc,IAAI,iBAAiB;AACtE,QAAI,2BAA2B,UAAa,0BAA0B,QAAW;AAC7E,aAAO,CAAA;AAAA,IACX;AACA,QAAI,wBAA6C,CAAA;AAEjD,QAAI,2BAA2B,QAAW;AACtC,8BAAwB,uBAAuB,OAAO,CAAC,iBAAiB;AACpE,YAAI,aAAa,WAAW;AACxB,iBAAO,aAAa,UAAU,KAAK;AAAA,QACvC;AAEA,eAAO;AAAA,MACX,CAAC;AAAA,IACL;AACA,4BAAwB,CAAC,GAAG,uBAAuB,GAAI,yBAAyB,CAAA,CAAG;AACnF,WAAO;AAAA,EACX;AACJ;AAOO,SAAS,yBAAkD;AAC9D,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,IAAI,qBAAA;AAAA,EAAqB;AAE1C;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduit-client/service-pubsub",
3
- "version": "3.20.0",
3
+ "version": "3.20.3",
4
4
  "private": false,
5
5
  "description": "Luvio PubSub Service definition",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "watch": "npm run build --watch"
32
32
  },
33
33
  "dependencies": {
34
- "@conduit-client/utils": "3.20.0"
34
+ "@conduit-client/utils": "3.20.3"
35
35
  },
36
36
  "volta": {
37
37
  "extends": "../../../../package.json"