@vyriy/handler 0.7.8 → 0.8.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.
Files changed (168) hide show
  1. package/README.md +375 -253
  2. package/api/api.d.ts +10 -0
  3. package/api/api.js +19 -0
  4. package/api/http/compose/compose.d.ts +2 -0
  5. package/api/http/compose/compose.js +1 -0
  6. package/api/http/compose/index.d.ts +1 -0
  7. package/api/http/compose/index.js +1 -0
  8. package/api/http/factory/factory.d.ts +2 -0
  9. package/api/http/factory/factory.js +1 -0
  10. package/api/http/factory/index.d.ts +1 -0
  11. package/api/http/factory/index.js +1 -0
  12. package/api/http/http.d.ts +3 -0
  13. package/api/http/http.js +14 -0
  14. package/api/http/index.d.ts +3 -0
  15. package/api/http/index.js +2 -0
  16. package/api/http/types.d.ts +18 -0
  17. package/api/http/wrappers/cors.d.ts +1 -0
  18. package/api/http/wrappers/cors.js +9 -0
  19. package/api/http/wrappers/error.d.ts +3 -0
  20. package/api/http/wrappers/error.js +21 -0
  21. package/api/http/wrappers/headers.d.ts +1 -0
  22. package/api/http/wrappers/headers.js +8 -0
  23. package/api/http/wrappers/healthcheck.d.ts +5 -0
  24. package/api/http/wrappers/healthcheck.js +19 -0
  25. package/api/http/wrappers/index.d.ts +5 -0
  26. package/api/http/wrappers/index.js +5 -0
  27. package/api/http/wrappers/logger.d.ts +2 -0
  28. package/api/http/wrappers/logger.js +28 -0
  29. package/api/index.d.ts +3 -0
  30. package/api/index.js +2 -0
  31. package/api/stream/compose/compose.d.ts +2 -0
  32. package/api/stream/compose/compose.js +1 -0
  33. package/api/stream/compose/index.d.ts +1 -0
  34. package/api/stream/compose/index.js +1 -0
  35. package/api/stream/factory/factory.d.ts +5 -0
  36. package/api/stream/factory/factory.js +3 -0
  37. package/api/stream/factory/index.d.ts +1 -0
  38. package/api/stream/factory/index.js +1 -0
  39. package/api/stream/index.d.ts +3 -0
  40. package/api/stream/index.js +2 -0
  41. package/api/stream/stream.d.ts +3 -0
  42. package/api/stream/stream.js +13 -0
  43. package/api/stream/types.d.ts +36 -0
  44. package/api/stream/wrappers/chaos.d.ts +2 -0
  45. package/{wrapper → api/stream/wrappers}/chaos.js +1 -12
  46. package/api/stream/wrappers/context.d.ts +1 -0
  47. package/api/stream/wrappers/context.js +6 -0
  48. package/api/stream/wrappers/cors.d.ts +1 -0
  49. package/api/stream/wrappers/cors.js +10 -0
  50. package/api/stream/wrappers/error.d.ts +3 -0
  51. package/api/stream/wrappers/error.js +25 -0
  52. package/api/stream/wrappers/headers.d.ts +1 -0
  53. package/api/stream/wrappers/headers.js +7 -0
  54. package/api/stream/wrappers/healthcheck.d.ts +2 -0
  55. package/api/stream/wrappers/healthcheck.js +27 -0
  56. package/api/stream/wrappers/index.d.ts +10 -0
  57. package/api/stream/wrappers/index.js +10 -0
  58. package/api/stream/wrappers/logger.d.ts +2 -0
  59. package/api/stream/wrappers/logger.js +20 -0
  60. package/api/stream/wrappers/smoke.d.ts +2 -0
  61. package/{wrapper → api/stream/wrappers}/smoke.js +1 -5
  62. package/api/stream/wrappers/timeout.d.ts +1 -0
  63. package/api/stream/wrappers/timeout.js +6 -0
  64. package/api/types.d.ts +17 -0
  65. package/api/wrappers/chaos.d.ts +1 -0
  66. package/api/wrappers/chaos.js +1 -0
  67. package/api/wrappers/cors.d.ts +1 -0
  68. package/api/wrappers/cors.js +11 -0
  69. package/api/wrappers/error.d.ts +4 -0
  70. package/api/wrappers/error.js +18 -0
  71. package/api/wrappers/headers.d.ts +1 -0
  72. package/api/wrappers/headers.js +13 -0
  73. package/api/wrappers/healthcheck.d.ts +8 -0
  74. package/api/wrappers/healthcheck.js +22 -0
  75. package/api/wrappers/index.d.ts +5 -0
  76. package/api/wrappers/index.js +5 -0
  77. package/compose/compose.d.ts +2 -0
  78. package/compose/compose.js +1 -0
  79. package/compose/index.d.ts +1 -0
  80. package/compose/index.js +1 -0
  81. package/create/create.d.ts +12 -0
  82. package/create/create.js +22 -0
  83. package/create/index.d.ts +1 -0
  84. package/create/index.js +1 -0
  85. package/dynamodb/dynamodb.d.ts +4 -0
  86. package/dynamodb/dynamodb.js +8 -0
  87. package/dynamodb/index.d.ts +1 -0
  88. package/dynamodb/index.js +1 -0
  89. package/eventBridge/eventBridge.d.ts +4 -0
  90. package/eventBridge/eventBridge.js +8 -0
  91. package/eventBridge/index.d.ts +1 -0
  92. package/eventBridge/index.js +1 -0
  93. package/factory/factory.d.ts +4 -0
  94. package/factory/factory.js +2 -0
  95. package/factory/index.d.ts +1 -0
  96. package/factory/index.js +1 -0
  97. package/index.d.ts +21 -19
  98. package/index.js +21 -19
  99. package/package.json +731 -185
  100. package/s3/index.d.ts +1 -0
  101. package/s3/index.js +1 -0
  102. package/s3/s3.d.ts +4 -0
  103. package/s3/s3.js +8 -0
  104. package/schedule/index.d.ts +1 -0
  105. package/schedule/index.js +1 -0
  106. package/schedule/schedule.d.ts +4 -0
  107. package/schedule/schedule.js +8 -0
  108. package/ses/index.d.ts +1 -0
  109. package/ses/index.js +1 -0
  110. package/ses/ses.d.ts +4 -0
  111. package/ses/ses.js +8 -0
  112. package/sns/index.d.ts +1 -0
  113. package/sns/index.js +1 -0
  114. package/sns/sns.d.ts +4 -0
  115. package/sns/sns.js +8 -0
  116. package/sqs/index.d.ts +1 -0
  117. package/sqs/index.js +1 -0
  118. package/sqs/sqs.d.ts +4 -0
  119. package/sqs/sqs.js +8 -0
  120. package/types.d.ts +12 -29
  121. package/{wrapper → wrappers}/chaos.d.ts +0 -1
  122. package/wrappers/chaos.js +35 -0
  123. package/{wrapper → wrappers}/context.d.ts +0 -1
  124. package/wrappers/context.js +6 -0
  125. package/{wrapper → wrappers}/error.d.ts +1 -4
  126. package/wrappers/error.js +9 -0
  127. package/wrappers/index.d.ts +6 -0
  128. package/wrappers/index.js +6 -0
  129. package/wrappers/logger.d.ts +4 -0
  130. package/wrappers/logger.js +21 -0
  131. package/wrappers/smoke.d.ts +2 -0
  132. package/wrappers/smoke.js +5 -0
  133. package/{wrapper → wrappers}/timeout.d.ts +0 -1
  134. package/wrappers/timeout.js +6 -0
  135. package/api.d.ts +0 -3
  136. package/api.js +0 -30
  137. package/compose.d.ts +0 -4
  138. package/compose.js +0 -3
  139. package/dynamodb.d.ts +0 -2
  140. package/dynamodb.js +0 -7
  141. package/eventBridge.d.ts +0 -2
  142. package/eventBridge.js +0 -7
  143. package/factory.d.ts +0 -8
  144. package/factory.js +0 -6
  145. package/s3.d.ts +0 -2
  146. package/s3.js +0 -7
  147. package/schedule.d.ts +0 -2
  148. package/schedule.js +0 -7
  149. package/ses.d.ts +0 -2
  150. package/ses.js +0 -7
  151. package/sns.d.ts +0 -2
  152. package/sns.js +0 -7
  153. package/sqs.d.ts +0 -2
  154. package/sqs.js +0 -7
  155. package/wrapper/context.js +0 -11
  156. package/wrapper/cors.d.ts +0 -3
  157. package/wrapper/cors.js +0 -28
  158. package/wrapper/error.js +0 -62
  159. package/wrapper/headers.d.ts +0 -3
  160. package/wrapper/headers.js +0 -25
  161. package/wrapper/healthcheck.d.ts +0 -13
  162. package/wrapper/healthcheck.js +0 -49
  163. package/wrapper/logger.d.ts +0 -6
  164. package/wrapper/logger.js +0 -65
  165. package/wrapper/smoke.d.ts +0 -3
  166. package/wrapper/timeout.js +0 -10
  167. /package/{wrapper → api/stream/wrappers}/stream.d.ts +0 -0
  168. /package/{wrapper → api/stream/wrappers}/stream.js +0 -0
@@ -1,25 +0,0 @@
1
- import { factory, httpFactory, streamFactory } from '../factory.js';
2
- import { responseStream } from './stream.js';
3
- const normalizeHeaders = (headers) => Object.fromEntries(Object.entries(headers ?? {}).map(([key, value]) => [key.toLowerCase(), value]));
4
- const mergeHeaders = (result, options) => {
5
- result.headers = {
6
- ...normalizeHeaders(options),
7
- ...normalizeHeaders(result.headers),
8
- };
9
- return result;
10
- };
11
- export const withHeaders = factory(async (handler, args, options = {}) => {
12
- const result = await handler(...args);
13
- return mergeHeaders(result, options);
14
- });
15
- export const streamWithHeaders = streamFactory(async (handler, args, options = {}) => {
16
- const [event, stream, context] = args;
17
- await handler(event, responseStream(stream, { headers: normalizeHeaders(options) }), context);
18
- });
19
- export const httpWithHeaders = httpFactory(async (handler, args, options = {}) => {
20
- const [request, response] = args;
21
- for (const [name, value] of Object.entries(options)) {
22
- response.setHeader(name.toLowerCase(), value);
23
- }
24
- await handler(request, response);
25
- });
@@ -1,13 +0,0 @@
1
- export type HealthcheckOptions = {
2
- path?: string;
3
- action?: () => Promise<void>;
4
- };
5
- export type HttpHealthcheckOptions = HealthcheckOptions & {
6
- body?: unknown;
7
- };
8
- export declare const withHealthcheck: (options?: HealthcheckOptions | undefined) => import("../types.js").Decorator<import("aws-lambda").APIGatewayProxyEvent, import("aws-lambda").APIGatewayProxyResult | {
9
- statusCode: number;
10
- body: string;
11
- }>;
12
- export declare const streamWithHealthcheck: (options?: HealthcheckOptions | undefined) => import("../types.js").StreamDecorator<import("aws-lambda").APIGatewayProxyEvent>;
13
- export declare const httpWithHealthcheck: (options?: HttpHealthcheckOptions | undefined) => import("../types.js").HttpDecorator;
@@ -1,49 +0,0 @@
1
- import { STATUS_CODES } from 'node:http';
2
- import { factory, httpFactory, streamFactory } from '../factory.js';
3
- import { responseStream } from './stream.js';
4
- const getHealthcheckResult = async (event, options = {}) => {
5
- const { path = '/healthcheck', action } = options;
6
- if (event.path !== path) {
7
- return undefined;
8
- }
9
- if (action) {
10
- await action();
11
- }
12
- return {
13
- statusCode: 200,
14
- body: JSON.stringify({
15
- message: STATUS_CODES[200],
16
- }),
17
- };
18
- };
19
- export const withHealthcheck = factory(async (handler, args, options = {}) => {
20
- const [event] = args;
21
- const result = await getHealthcheckResult(event, options);
22
- return result ?? handler(...args);
23
- });
24
- export const streamWithHealthcheck = streamFactory(async (handler, args, options = {}) => {
25
- const [event, stream] = args;
26
- const result = await getHealthcheckResult(event, options);
27
- if (result) {
28
- responseStream(stream, { statusCode: result.statusCode }).end(result.body);
29
- return;
30
- }
31
- await handler(...args);
32
- });
33
- export const httpWithHealthcheck = httpFactory(async (handler, args, options = {}) => {
34
- const { path = '/healthcheck', action, body } = options;
35
- const [request, response] = args;
36
- const pathname = (request.url ?? '').split('?')[0];
37
- if (pathname !== path) {
38
- await handler(...args);
39
- return;
40
- }
41
- if (action) {
42
- await action();
43
- }
44
- response
45
- .writeHead(200, {
46
- 'content-type': 'application/json',
47
- })
48
- .end(JSON.stringify(body ?? { message: STATUS_CODES[200] }));
49
- });
@@ -1,6 +0,0 @@
1
- export type LoggerOptions = {
2
- logger?: typeof console;
3
- };
4
- export declare const withLogger: <Event, Result>(options?: LoggerOptions | undefined) => import("../types.js").Decorator<Event, Result>;
5
- export declare const streamWithLogger: <Event>(options?: LoggerOptions | undefined) => import("../types.js").StreamDecorator<Event>;
6
- export declare const httpWithLogger: (options?: LoggerOptions | undefined) => import("../types.js").HttpDecorator;
package/wrapper/logger.js DELETED
@@ -1,65 +0,0 @@
1
- import { createLogger } from '@vyriy/logger';
2
- import { factory, getContext, getStreamContext, httpFactory, streamFactory } from '../factory.js';
3
- export const withLogger = factory(async (handler, args, options = {}) => {
4
- const { logger = createLogger() } = options;
5
- const [event] = args;
6
- const context = getContext(args);
7
- logger.info('Event:', event);
8
- logger.info('Context:', context);
9
- try {
10
- const result = await handler(...args);
11
- logger.info('Result:', result);
12
- return result;
13
- }
14
- catch (error) {
15
- if (error instanceof Error) {
16
- logger.error('Error:', error.message);
17
- }
18
- logger.error(error);
19
- throw error;
20
- }
21
- });
22
- export const streamWithLogger = streamFactory(async (handler, args, options = {}) => {
23
- const { logger = createLogger() } = options;
24
- const [event] = args;
25
- const context = getStreamContext(args);
26
- logger.info('Event:', event);
27
- logger.info('Context:', context);
28
- try {
29
- await handler(...args);
30
- logger.info('Result:', undefined);
31
- }
32
- catch (error) {
33
- if (error instanceof Error) {
34
- logger.error('Error:', error.message);
35
- }
36
- logger.error(error);
37
- throw error;
38
- }
39
- });
40
- export const httpWithLogger = httpFactory(async (handler, args, options = {}) => {
41
- const { logger = createLogger() } = options;
42
- const [request, response] = args;
43
- logger.info('Request:', request.method, request.url);
44
- const cleanup = () => {
45
- response.off('close', logResult);
46
- response.off('finish', logResult);
47
- };
48
- const logResult = () => {
49
- cleanup();
50
- logger.info('Result:', response.statusCode);
51
- };
52
- response.once('close', logResult);
53
- response.once('finish', logResult);
54
- try {
55
- await handler(...args);
56
- }
57
- catch (error) {
58
- cleanup();
59
- if (error instanceof Error) {
60
- logger.error('Error:', error.message);
61
- }
62
- logger.error(error);
63
- throw error;
64
- }
65
- });
@@ -1,3 +0,0 @@
1
- import type { ApiResult, Decorator, StreamDecorator } from '../types.js';
2
- export declare const withSmoke: <Event, Result extends ApiResult | void = ApiResult>() => Decorator<Event, Result>;
3
- export declare const streamWithSmoke: <Event>() => StreamDecorator<Event>;
@@ -1,10 +0,0 @@
1
- import { timeout as error } from '@vyriy/timeout';
2
- import { factory, getContext, getStreamContext, streamFactory } from '../factory.js';
3
- export const withTimeout = factory(async (handler, args) => Promise.race([
4
- error(getContext(args).getRemainingTimeInMillis() - 1000),
5
- handler(...args),
6
- ]));
7
- export const streamWithTimeout = streamFactory(async (handler, args) => Promise.race([
8
- error(getStreamContext(args).getRemainingTimeInMillis() - 1000),
9
- handler(...args),
10
- ]));
File without changes
File without changes