@pikku/lambda 0.6.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +3 -0
  3. package/dist/http/anywhere-http.d.ts +3 -0
  4. package/dist/http/anywhere-http.js +13 -0
  5. package/dist/http/anywhere-http.js.map +1 -0
  6. package/dist/http/cors-http.d.ts +3 -0
  7. package/dist/http/cors-http.js +35 -0
  8. package/dist/http/cors-http.js.map +1 -0
  9. package/dist/http/corsless-http.d.ts +3 -0
  10. package/dist/http/corsless-http.js +9 -0
  11. package/dist/http/corsless-http.js.map +1 -0
  12. package/dist/http/general-http-handler.d.ts +5 -0
  13. package/dist/http/general-http-handler.js +28 -0
  14. package/dist/http/general-http-handler.js.map +1 -0
  15. package/dist/http/index.d.ts +3 -0
  16. package/dist/http/index.js +4 -0
  17. package/dist/http/index.js.map +1 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/pikku-api-gateway-lambda-request.d.ts +12 -0
  22. package/dist/pikku-api-gateway-lambda-request.js +24 -0
  23. package/dist/pikku-api-gateway-lambda-request.js.map +1 -0
  24. package/dist/pikku-api-gateway-lambda-response.d.ts +15 -0
  25. package/dist/pikku-api-gateway-lambda-response.js +32 -0
  26. package/dist/pikku-api-gateway-lambda-response.js.map +1 -0
  27. package/dist/websocket/index.d.ts +4 -0
  28. package/dist/websocket/index.js +5 -0
  29. package/dist/websocket/index.js.map +1 -0
  30. package/dist/websocket/lambda-channel-handler.d.ts +4 -0
  31. package/dist/websocket/lambda-channel-handler.js +29 -0
  32. package/dist/websocket/lambda-channel-handler.js.map +1 -0
  33. package/dist/websocket/lambda-eventhub-service.d.ts +14 -0
  34. package/dist/websocket/lambda-eventhub-service.js +27 -0
  35. package/dist/websocket/lambda-eventhub-service.js.map +1 -0
  36. package/dist/websocket/utils.d.ts +13 -0
  37. package/dist/websocket/utils.js +59 -0
  38. package/dist/websocket/utils.js.map +1 -0
  39. package/dist/websocket/websocket-connect.d.ts +4 -0
  40. package/dist/websocket/websocket-connect.js +19 -0
  41. package/dist/websocket/websocket-connect.js.map +1 -0
  42. package/dist/websocket/websocket-disconnect.d.ts +4 -0
  43. package/dist/websocket/websocket-disconnect.js +12 -0
  44. package/dist/websocket/websocket-disconnect.js.map +1 -0
  45. package/dist/websocket/websocket-message.d.ts +4 -0
  46. package/dist/websocket/websocket-message.js +22 -0
  47. package/dist/websocket/websocket-message.js.map +1 -0
  48. package/dist/websocket/websocket-types.d.ts +7 -0
  49. package/dist/websocket/websocket-types.js +2 -0
  50. package/dist/websocket/websocket-types.js.map +1 -0
  51. package/package.json +37 -0
  52. package/run-tests.sh +53 -0
  53. package/src/http/anywhere-http.ts +39 -0
  54. package/src/http/cors-http.ts +70 -0
  55. package/src/http/corsless-http.ts +33 -0
  56. package/src/http/general-http-handler.ts +59 -0
  57. package/src/http/index.ts +3 -0
  58. package/src/index.ts +1 -0
  59. package/src/pikku-api-gateway-lambda-request.ts +31 -0
  60. package/src/pikku-api-gateway-lambda-response.ts +41 -0
  61. package/src/websocket/index.ts +4 -0
  62. package/src/websocket/lambda-channel-handler.ts +63 -0
  63. package/src/websocket/lambda-eventhub-service.ts +59 -0
  64. package/src/websocket/utils.ts +95 -0
  65. package/src/websocket/websocket-connect.ts +41 -0
  66. package/src/websocket/websocket-disconnect.ts +35 -0
  67. package/src/websocket/websocket-message.ts +48 -0
  68. package/src/websocket/websocket-types.ts +22 -0
  69. package/tsconfig.json +17 -0
  70. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,48 @@
1
+ import {
2
+ CoreSingletonServices,
3
+ CoreServices,
4
+ CoreUserSession,
5
+ } from '@pikku/core'
6
+ import { runChannelMessage } from '@pikku/core/channel/serverless'
7
+ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
8
+ import { PikkuAPIGatewayLambdaResponse } from '../pikku-api-gateway-lambda-response.js'
9
+ import { getServerlessDependencies } from './utils.js'
10
+ import { WebsocketParams } from './websocket-types.js'
11
+
12
+ export const processWebsocketMessage = async <
13
+ SingletonServices extends CoreSingletonServices,
14
+ Services extends CoreServices<SingletonServices>,
15
+ UserSession extends CoreUserSession,
16
+ >(
17
+ event: APIGatewayProxyEvent,
18
+ {
19
+ singletonServices,
20
+ createSessionServices,
21
+ channelStore,
22
+ }: WebsocketParams<SingletonServices, Services, UserSession>
23
+ ): Promise<APIGatewayProxyResult> => {
24
+ const runnerParams = getServerlessDependencies(
25
+ singletonServices.logger,
26
+ channelStore,
27
+ event
28
+ )
29
+ const response = new PikkuAPIGatewayLambdaResponse()
30
+ try {
31
+ const result = await runChannelMessage(
32
+ {
33
+ ...runnerParams,
34
+ singletonServices: singletonServices as any,
35
+ createSessionServices: createSessionServices as any,
36
+ },
37
+ event.body
38
+ )
39
+ if (result) {
40
+ // TODO: Support non json
41
+ response.setJson(result as any)
42
+ }
43
+ } catch (e) {
44
+ // Error should have already been handled by runHTTPRoute
45
+ console.error(e)
46
+ }
47
+ return response.getLambdaResponse()
48
+ }
@@ -0,0 +1,22 @@
1
+ import {
2
+ CoreSingletonServices,
3
+ CoreServices,
4
+ CoreUserSession,
5
+ CreateSessionServices,
6
+ MakeRequired,
7
+ } from '@pikku/core'
8
+ import { ChannelStore } from '@pikku/core/channel'
9
+
10
+ export type WebsocketParams<
11
+ SingletonServices extends CoreSingletonServices,
12
+ Services extends CoreServices<SingletonServices>,
13
+ UserSession extends CoreUserSession,
14
+ > = {
15
+ channelStore: ChannelStore
16
+ singletonServices: MakeRequired<SingletonServices, 'eventHub'>
17
+ createSessionServices?: CreateSessionServices<
18
+ SingletonServices,
19
+ Services,
20
+ UserSession
21
+ >
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "module": "Node16",
6
+ "outDir": "dist",
7
+ "target": "esnext",
8
+ "declaration": true
9
+ },
10
+ "include": ["bin/**/*.ts", "src/**/*.ts"],
11
+ "exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
12
+ "references": [
13
+ {
14
+ "path": "../../core/tsconfig.json"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/index.ts","./src/pikku-api-gateway-lambda-request.ts","./src/pikku-api-gateway-lambda-response.ts","./src/http/anywhere-http.ts","./src/http/cors-http.ts","./src/http/corsless-http.ts","./src/http/general-http-handler.ts","./src/http/index.ts","./src/websocket/index.ts","./src/websocket/lambda-channel-handler.ts","./src/websocket/lambda-eventhub-service.ts","./src/websocket/utils.ts","./src/websocket/websocket-connect.ts","./src/websocket/websocket-disconnect.ts","./src/websocket/websocket-message.ts","./src/websocket/websocket-types.ts"],"version":"5.7.3"}