@pikku/lambda 0.8.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## 0.8.0
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fdb1593: core: bumping everything with a patch to sync up the major release inconsistencies in dependencies
8
+ - Updated dependencies [fdb1593]
9
+ - @pikku/core@0.9.1
10
+
11
+ ## 0.9.0
12
+
13
+ ### Breaking Changes
14
+
15
+ - Normalized all transports to use "wirings" instead of events/routes/transports for consistency across the framework
16
+
3
17
  ### Major Features
4
18
 
5
19
  - **SQS Queue Support**: Added SQS queue worker support
@@ -1,14 +1,14 @@
1
1
  import { ChannelStore, EventHubService, EventHubStore } from '@pikku/core/channel';
2
2
  import { Logger } from '@pikku/core/services';
3
3
  import { APIGatewayEvent } from 'aws-lambda';
4
- export declare class LambdaEventHubService<Out = unknown> implements EventHubService<Out> {
4
+ export declare class LambdaEventHubService<EventTopics extends Record<string, any> = {}> implements EventHubService<EventTopics> {
5
5
  private logger;
6
6
  private channelStore;
7
7
  private eventHubStore;
8
8
  private callbackAPI;
9
- constructor(logger: Logger, event: APIGatewayEvent, channelStore: ChannelStore, eventHubStore: EventHubStore);
10
- subscribe(topic: string, channelId: string): Promise<void>;
11
- unsubscribe(topic: string, channelId: string): Promise<void>;
12
- publish(topic: string, fromChannelId: string, data: Out, isBinary?: boolean): Promise<void>;
9
+ constructor(logger: Logger, event: APIGatewayEvent, channelStore: ChannelStore, eventHubStore: EventHubStore<EventTopics>);
10
+ subscribe<T extends keyof EventTopics>(topic: T, channelId: string): Promise<void>;
11
+ unsubscribe<T extends keyof EventTopics>(topic: T, channelId: string): Promise<void>;
12
+ publish<T extends keyof EventTopics>(topic: T, channelId: string | null, data: EventTopics[T], isBinary?: boolean): Promise<void>;
13
13
  private sendMessages;
14
14
  }
@@ -16,9 +16,11 @@ export class LambdaEventHubService {
16
16
  async unsubscribe(topic, channelId) {
17
17
  await this.eventHubStore.unsubscribe(topic, channelId);
18
18
  }
19
- async publish(topic, fromChannelId, data, isBinary) {
19
+ async publish(topic, channelId, data, isBinary) {
20
20
  const channelIds = await this.eventHubStore.getChannelIdsForTopic(topic);
21
- await this.sendMessages(channelIds, fromChannelId, data);
21
+ if (channelId) {
22
+ await this.sendMessages(channelIds, channelId, data, isBinary);
23
+ }
22
24
  }
23
25
  async sendMessages(channelIds, fromChannelId, data, isBinary) {
24
26
  await sendMessages(this.logger, this.channelStore, this.callbackAPI, fromChannelId, channelIds, data, isBinary);
@@ -1 +1 @@
1
- {"version":3,"file":"lambda-eventhub-service.js","sourceRoot":"","sources":["../../src/websocket/lambda-eventhub-service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gCAAgC,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAI3E,MAAM,OAAO,qBAAqB;IAMtB;IAEA;IACA;IANF,WAAW,CAA+B;IAElD,YACU,MAAc,EACtB,KAAsB,EACd,YAA0B,EAC1B,aAA4B;QAH5B,WAAM,GAAN,MAAM,CAAQ;QAEd,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAEpC,IAAI,CAAC,WAAW,GAAG,gCAAgC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,SAAiB;QAC9C,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,SAAiB;QAChD,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAa,EACb,aAAqB,EACrB,IAAS,EACT,QAAkB;QAElB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;QACxE,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IAC1D,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,UAAoB,EACpB,aAAqB,EACrB,IAAS,EACT,QAAkB;QAElB,MAAM,YAAY,CAChB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,aAAa,EACb,UAAU,EACV,IAAI,EACJ,QAAQ,CACT,CAAA;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"lambda-eventhub-service.js","sourceRoot":"","sources":["../../src/websocket/lambda-eventhub-service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gCAAgC,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAI3E,MAAM,OAAO,qBAAqB;IAMtB;IAEA;IACA;IANF,WAAW,CAA+B;IAElD,YACU,MAAc,EACtB,KAAsB,EACd,YAA0B,EAC1B,aAAyC;QAHzC,WAAM,GAAN,MAAM,CAAQ;QAEd,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAA4B;QAEjD,IAAI,CAAC,WAAW,GAAG,gCAAgC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,SAAS,CACb,KAAQ,EACR,SAAiB;QAEjB,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,WAAW,CACf,KAAQ,EACR,SAAiB;QAEjB,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAQ,EACR,SAAwB,EACxB,IAAoB,EACpB,QAAkB;QAElB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAC/D,KAAe,CAChB,CAAA;QACD,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;QAChE,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,YAAY,CACxB,UAAoB,EACpB,aAAqB,EACrB,IAAoC,EACpC,QAAkB;QAElB,MAAM,YAAY,CAChB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,aAAa,EACb,UAAU,EACV,IAAI,EACJ,QAAQ,CACT,CAAA;IACH,CAAC;CACF"}
@@ -9,5 +9,5 @@ export declare const getServerlessDependencies: (logger: Logger, channelStore: C
9
9
  channelId: string;
10
10
  callbackAPI: ApiGatewayManagementApiClient;
11
11
  channelHandlerFactory: import("@pikku/core/channel").PikkuChannelHandlerFactory;
12
- channelStore: ChannelStore<unknown, unknown, import("@pikku/core/dist/index.js").CoreUserSession, import("@pikku/core/channel").Channel<unknown, unknown>>;
12
+ channelStore: ChannelStore<unknown, unknown, import("@pikku/core/src/index.js").CoreUserSession, import("@pikku/core/channel").Channel<unknown, unknown>>;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/lambda",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "license": "MIT",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "module": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@aws-sdk/client-apigatewaymanagementapi": "^3.713.0",
27
- "@pikku/core": "^0.8.0",
27
+ "@pikku/core": "^0.9.1",
28
28
  "@types/aws-lambda": "^8.10.146"
29
29
  },
30
30
  "devDependencies": {
@@ -8,8 +8,8 @@ import { getApiGatewayManagementApiClient, sendMessages } from './utils.js'
8
8
  import { Logger } from '@pikku/core/services'
9
9
  import { APIGatewayEvent } from 'aws-lambda'
10
10
 
11
- export class LambdaEventHubService<Out = unknown>
12
- implements EventHubService<Out>
11
+ export class LambdaEventHubService<EventTopics extends Record<string, any> = {}>
12
+ implements EventHubService<EventTopics>
13
13
  {
14
14
  private callbackAPI: ApiGatewayManagementApiClient
15
15
 
@@ -17,33 +17,43 @@ export class LambdaEventHubService<Out = unknown>
17
17
  private logger: Logger,
18
18
  event: APIGatewayEvent,
19
19
  private channelStore: ChannelStore,
20
- private eventHubStore: EventHubStore
20
+ private eventHubStore: EventHubStore<EventTopics>
21
21
  ) {
22
22
  this.callbackAPI = getApiGatewayManagementApiClient(logger, event)
23
23
  }
24
24
 
25
- async subscribe(topic: string, channelId: string): Promise<void> {
25
+ async subscribe<T extends keyof EventTopics>(
26
+ topic: T,
27
+ channelId: string
28
+ ): Promise<void> {
26
29
  await this.eventHubStore.subscribe(topic, channelId)
27
30
  }
28
31
 
29
- async unsubscribe(topic: string, channelId: string): Promise<void> {
32
+ async unsubscribe<T extends keyof EventTopics>(
33
+ topic: T,
34
+ channelId: string
35
+ ): Promise<void> {
30
36
  await this.eventHubStore.unsubscribe(topic, channelId)
31
37
  }
32
38
 
33
- async publish(
34
- topic: string,
35
- fromChannelId: string,
36
- data: Out,
39
+ async publish<T extends keyof EventTopics>(
40
+ topic: T,
41
+ channelId: string | null,
42
+ data: EventTopics[T],
37
43
  isBinary?: boolean
38
44
  ): Promise<void> {
39
- const channelIds = await this.eventHubStore.getChannelIdsForTopic(topic)
40
- await this.sendMessages(channelIds, fromChannelId, data)
45
+ const channelIds = await this.eventHubStore.getChannelIdsForTopic(
46
+ topic as string
47
+ )
48
+ if (channelId) {
49
+ await this.sendMessages(channelIds, channelId, data, isBinary)
50
+ }
41
51
  }
42
52
 
43
53
  private async sendMessages(
44
54
  channelIds: string[],
45
55
  fromChannelId: string,
46
- data: Out,
56
+ data: EventTopics[keyof EventTopics],
47
57
  isBinary?: boolean
48
58
  ): Promise<void> {
49
59
  await sendMessages(