@gahojin-inc/middy-appsync 2026.3.3 → 2026.5.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.
- package/dist/index.d.ts +19 -0
- package/dist/{index.mjs → index.js} +2 -2
- package/dist/index.js.map +1 -0
- package/package.json +10 -14
- package/dist/index.cjs +0 -54
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -26
- package/dist/index.d.mts +0 -26
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { default as middy } from '@middy/core';
|
|
2
|
+
import { AppSyncResolverEvent } from 'aws-lambda';
|
|
3
|
+
export declare class AppSyncError extends Error {
|
|
4
|
+
readonly type: string;
|
|
5
|
+
constructor(message: string, type?: string);
|
|
6
|
+
}
|
|
7
|
+
export type AppSyncBatchResponse<TData = any> = {
|
|
8
|
+
data?: TData | null;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
errorType?: string;
|
|
11
|
+
};
|
|
12
|
+
export type AppSyncResolverEvents<TArguments, TSource = Record<string, any> | null> = AppSyncResolverEvent<TArguments, TSource> | AppSyncResolverEvent<TArguments, TSource>[];
|
|
13
|
+
export type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined;
|
|
14
|
+
export type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>;
|
|
15
|
+
type Options<TData = any> = {
|
|
16
|
+
buildResponse?: BuildResponseFn<TData>;
|
|
17
|
+
};
|
|
18
|
+
declare const _default: <TArguments = any, TData = any, TSource = Record<string, any> | null>(opts?: Options<TData>) => middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>>;
|
|
19
|
+
export default _default;
|
|
@@ -6,7 +6,7 @@ var AppSyncError = class extends Error {
|
|
|
6
6
|
this.type = type;
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
var defaultBuildResponse = (response, batchInvoke) => {
|
|
10
10
|
if (batchInvoke) {
|
|
11
11
|
if (response instanceof AppSyncError) return {
|
|
12
12
|
errorMessage: response.message,
|
|
@@ -46,4 +46,4 @@ var src_default = (opts = {}) => {
|
|
|
46
46
|
//#endregion
|
|
47
47
|
export { AppSyncError, src_default as default };
|
|
48
48
|
|
|
49
|
-
//# sourceMappingURL=index.
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type middy from '@middy/core'\nimport type { AppSyncResolverEvent } from 'aws-lambda'\n\nexport class AppSyncError extends Error {\n readonly type: string\n\n constructor(message: string, type = 'UnknownError') {\n super(message)\n this.type = type\n }\n}\n\nexport type AppSyncBatchResponse<TData = any> = {\n data?: TData | null\n errorMessage?: string\n errorType?: string\n}\n\nexport type AppSyncResolverEvents<TArguments, TSource = Record<string, any> | null> =\n | AppSyncResolverEvent<TArguments, TSource>\n | AppSyncResolverEvent<TArguments, TSource>[]\n\nexport type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined\n\nexport type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>\n\ntype Options<TData = any> = {\n buildResponse?: BuildResponseFn<TData>\n}\n\nconst defaultBuildResponse = <TData>(response: TData | Error | null | undefined, batchInvoke: boolean): AppSyncResponse<TData> => {\n if (batchInvoke) {\n if (response instanceof AppSyncError) {\n return {\n errorMessage: response.message,\n errorType: response.type,\n }\n }\n if (response instanceof Error) {\n return {\n errorMessage: response.message,\n }\n }\n return {\n data: response,\n }\n }\n return response\n}\n\nexport default <TArguments = any, TData = any, TSource = Record<string, any> | null>(\n opts: Options<TData> = {},\n): middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>> => {\n const buildResponse: BuildResponseFn<TData> = opts.buildResponse ?? defaultBuildResponse\n\n const afterFn: middy.MiddlewareFn = (request) => {\n const { event, response } = request\n\n if (Array.isArray(event)) {\n // for BatchInvoke\n if (!Array.isArray(response) || event.length !== response.length) {\n throw new Error('BatchInvoke: The response does not match the request payload')\n }\n request.response = response.map((r) => buildResponse(r, true))\n } else {\n const resp = buildResponse(response, false)\n if (resp instanceof Error) {\n throw resp\n }\n request.response = resp\n }\n }\n\n const onErrorFn: middy.MiddlewareFn = (request) => {\n const { event, error, response } = request\n\n if (response !== undefined) {\n return\n }\n\n const isBatchInvoke = Array.isArray(event)\n const resp = buildResponse(error, isBatchInvoke)\n if (isBatchInvoke) {\n // 全てエラー扱いにする\n const tmp = new Array(event.length)\n request.response = tmp.fill(resp)\n } else if (!(resp instanceof Error)) {\n request.response = resp\n }\n }\n\n return {\n after: afterFn,\n onError: onErrorFn,\n }\n}\n"],"mappings":";AAGA,IAAa,eAAb,cAAkC,MAAM;CACtC;CAEA,YAAY,SAAiB,OAAO,gBAAgB;AAClD,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAsBhB,IAAM,wBAA+B,UAA4C,gBAAiD;AAChI,KAAI,aAAa;AACf,MAAI,oBAAoB,aACtB,QAAO;GACL,cAAc,SAAS;GACvB,WAAW,SAAS;GACrB;AAEH,MAAI,oBAAoB,MACtB,QAAO,EACL,cAAc,SAAS,SACxB;AAEH,SAAO,EACL,MAAM,UACP;;AAEH,QAAO;;AAGT,IAAA,eACE,OAAuB,EAAE,KACmE;CAC5F,MAAM,gBAAwC,KAAK,iBAAiB;CAEpE,MAAM,WAA+B,YAAY;EAC/C,MAAM,EAAE,OAAO,aAAa;AAE5B,MAAI,MAAM,QAAQ,MAAM,EAAE;AAExB,OAAI,CAAC,MAAM,QAAQ,SAAS,IAAI,MAAM,WAAW,SAAS,OACxD,OAAM,IAAI,MAAM,+DAA+D;AAEjF,WAAQ,WAAW,SAAS,KAAK,MAAM,cAAc,GAAG,KAAK,CAAC;SACzD;GACL,MAAM,OAAO,cAAc,UAAU,MAAM;AAC3C,OAAI,gBAAgB,MAClB,OAAM;AAER,WAAQ,WAAW;;;CAIvB,MAAM,aAAiC,YAAY;EACjD,MAAM,EAAE,OAAO,OAAO,aAAa;AAEnC,MAAI,aAAa,KAAA,EACf;EAGF,MAAM,gBAAgB,MAAM,QAAQ,MAAM;EAC1C,MAAM,OAAO,cAAc,OAAO,cAAc;AAChD,MAAI,cAGF,SAAQ,WAAW,IADH,MAAM,MAAM,OACT,CAAI,KAAK,KAAK;WACxB,EAAE,gBAAgB,OAC3B,SAAQ,WAAW;;AAIvB,QAAO;EACL,OAAO;EACP,SAAS;EACV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gahojin-inc/middy-appsync",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.5.0",
|
|
4
4
|
"description": "Middy appsync",
|
|
5
5
|
"author": "GAHOJIN, Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,36 +24,32 @@
|
|
|
24
24
|
"access": "public",
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
|
-
"main": "./dist/index.
|
|
28
|
-
"module": "./dist/index.
|
|
29
|
-
"types": "./dist/index.d.
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
30
|
"exports": {
|
|
31
31
|
"./package.json": "./package.json",
|
|
32
32
|
".": {
|
|
33
33
|
"import": {
|
|
34
|
-
"types": "./dist/index.d.
|
|
35
|
-
"default": "./dist/index.
|
|
36
|
-
},
|
|
37
|
-
"require": {
|
|
38
|
-
"types": "./dist/index.d.cts",
|
|
39
|
-
"default": "./dist/index.cjs"
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
|
-
"@gahojin-inc/aws-lambda-mock-context": "2026.
|
|
45
|
-
"@middy/core": "7.
|
|
40
|
+
"@gahojin-inc/aws-lambda-mock-context": "2026.4.0",
|
|
41
|
+
"@middy/core": "7.3.3",
|
|
46
42
|
"@types/aws-lambda": "8.10.161"
|
|
47
43
|
},
|
|
48
44
|
"peerDependencies": {
|
|
49
45
|
"@middy/core": "^5 || ^6 || ^7"
|
|
50
46
|
},
|
|
51
47
|
"scripts": {
|
|
52
|
-
"build": "
|
|
48
|
+
"build": "vite build",
|
|
53
49
|
"lint": "biome check --write .",
|
|
54
50
|
"lint:ci": "biome ci .",
|
|
55
51
|
"check": "tsc --noEmit",
|
|
56
|
-
"check:packagejson": "attw --pack .",
|
|
52
|
+
"check:packagejson": "attw --pack --profile esm-only .",
|
|
57
53
|
"test": "vitest --watch",
|
|
58
54
|
"test:unit": "vitest --passWithNoTests --run --coverage"
|
|
59
55
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
//#region src/index.ts
|
|
6
|
-
var AppSyncError = class extends Error {
|
|
7
|
-
type;
|
|
8
|
-
constructor(message, type = "UnknownError") {
|
|
9
|
-
super(message);
|
|
10
|
-
this.type = type;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const defaultBuildResponse = (response, batchInvoke) => {
|
|
14
|
-
if (batchInvoke) {
|
|
15
|
-
if (response instanceof AppSyncError) return {
|
|
16
|
-
errorMessage: response.message,
|
|
17
|
-
errorType: response.type
|
|
18
|
-
};
|
|
19
|
-
if (response instanceof Error) return { errorMessage: response.message };
|
|
20
|
-
return { data: response };
|
|
21
|
-
}
|
|
22
|
-
return response;
|
|
23
|
-
};
|
|
24
|
-
var src_default = (opts = {}) => {
|
|
25
|
-
const buildResponse = opts.buildResponse ?? defaultBuildResponse;
|
|
26
|
-
const afterFn = (request) => {
|
|
27
|
-
const { event, response } = request;
|
|
28
|
-
if (Array.isArray(event)) {
|
|
29
|
-
if (!Array.isArray(response) || event.length !== response.length) throw new Error("BatchInvoke: The response does not match the request payload");
|
|
30
|
-
request.response = response.map((r) => buildResponse(r, true));
|
|
31
|
-
} else {
|
|
32
|
-
const resp = buildResponse(response, false);
|
|
33
|
-
if (resp instanceof Error) throw resp;
|
|
34
|
-
request.response = resp;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const onErrorFn = (request) => {
|
|
38
|
-
const { event, error, response } = request;
|
|
39
|
-
if (response !== void 0) return;
|
|
40
|
-
const isBatchInvoke = Array.isArray(event);
|
|
41
|
-
const resp = buildResponse(error, isBatchInvoke);
|
|
42
|
-
if (isBatchInvoke) request.response = new Array(event.length).fill(resp);
|
|
43
|
-
else if (!(resp instanceof Error)) request.response = resp;
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
after: afterFn,
|
|
47
|
-
onError: onErrorFn
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
//#endregion
|
|
51
|
-
exports.AppSyncError = AppSyncError;
|
|
52
|
-
exports.default = src_default;
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type middy from '@middy/core'\nimport type { AppSyncResolverEvent } from 'aws-lambda'\n\nexport class AppSyncError extends Error {\n readonly type: string\n\n constructor(message: string, type = 'UnknownError') {\n super(message)\n this.type = type\n }\n}\n\nexport type AppSyncBatchResponse<TData = any> = {\n data?: TData | null\n errorMessage?: string\n errorType?: string\n}\n\nexport type AppSyncResolverEvents<TArguments, TSource = Record<string, any> | null> =\n | AppSyncResolverEvent<TArguments, TSource>\n | AppSyncResolverEvent<TArguments, TSource>[]\n\nexport type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined\n\nexport type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>\n\ntype Options<TData = any> = {\n buildResponse?: BuildResponseFn<TData>\n}\n\nconst defaultBuildResponse = <TData>(response: TData | Error | null | undefined, batchInvoke: boolean): AppSyncResponse<TData> => {\n if (batchInvoke) {\n if (response instanceof AppSyncError) {\n return {\n errorMessage: response.message,\n errorType: response.type,\n }\n }\n if (response instanceof Error) {\n return {\n errorMessage: response.message,\n }\n }\n return {\n data: response,\n }\n }\n return response\n}\n\nexport default <TArguments = any, TData = any, TSource = Record<string, any> | null>(\n opts: Options<TData> = {},\n): middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>> => {\n const buildResponse: BuildResponseFn<TData> = opts.buildResponse ?? defaultBuildResponse\n\n const afterFn: middy.MiddlewareFn = (request) => {\n const { event, response } = request\n\n if (Array.isArray(event)) {\n // for BatchInvoke\n if (!Array.isArray(response) || event.length !== response.length) {\n throw new Error('BatchInvoke: The response does not match the request payload')\n }\n request.response = response.map((r) => buildResponse(r, true))\n } else {\n const resp = buildResponse(response, false)\n if (resp instanceof Error) {\n throw resp\n }\n request.response = resp\n }\n }\n\n const onErrorFn: middy.MiddlewareFn = (request) => {\n const { event, error, response } = request\n\n if (response !== undefined) {\n return\n }\n\n const isBatchInvoke = Array.isArray(event)\n const resp = buildResponse(error, isBatchInvoke)\n if (isBatchInvoke) {\n // 全てエラー扱いにする\n const tmp = new Array(event.length)\n request.response = tmp.fill(resp)\n } else if (!(resp instanceof Error)) {\n request.response = resp\n }\n }\n\n return {\n after: afterFn,\n onError: onErrorFn,\n }\n}\n"],"mappings":";;;;;AAGA,IAAa,eAAb,cAAkC,MAAM;CACtC;CAEA,YAAY,SAAiB,OAAO,gBAAgB;AAClD,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAsBhB,MAAM,wBAA+B,UAA4C,gBAAiD;AAChI,KAAI,aAAa;AACf,MAAI,oBAAoB,aACtB,QAAO;GACL,cAAc,SAAS;GACvB,WAAW,SAAS;GACrB;AAEH,MAAI,oBAAoB,MACtB,QAAO,EACL,cAAc,SAAS,SACxB;AAEH,SAAO,EACL,MAAM,UACP;;AAEH,QAAO;;AAGT,IAAA,eACE,OAAuB,EAAE,KACmE;CAC5F,MAAM,gBAAwC,KAAK,iBAAiB;CAEpE,MAAM,WAA+B,YAAY;EAC/C,MAAM,EAAE,OAAO,aAAa;AAE5B,MAAI,MAAM,QAAQ,MAAM,EAAE;AAExB,OAAI,CAAC,MAAM,QAAQ,SAAS,IAAI,MAAM,WAAW,SAAS,OACxD,OAAM,IAAI,MAAM,+DAA+D;AAEjF,WAAQ,WAAW,SAAS,KAAK,MAAM,cAAc,GAAG,KAAK,CAAC;SACzD;GACL,MAAM,OAAO,cAAc,UAAU,MAAM;AAC3C,OAAI,gBAAgB,MAClB,OAAM;AAER,WAAQ,WAAW;;;CAIvB,MAAM,aAAiC,YAAY;EACjD,MAAM,EAAE,OAAO,OAAO,aAAa;AAEnC,MAAI,aAAa,KAAA,EACf;EAGF,MAAM,gBAAgB,MAAM,QAAQ,MAAM;EAC1C,MAAM,OAAO,cAAc,OAAO,cAAc;AAChD,MAAI,cAGF,SAAQ,WADI,IAAI,MAAM,MAAM,OAAO,CACZ,KAAK,KAAK;WACxB,EAAE,gBAAgB,OAC3B,SAAQ,WAAW;;AAIvB,QAAO;EACL,OAAO;EACP,SAAS;EACV"}
|
package/dist/index.d.cts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type middy from "@middy/core";
|
|
2
|
-
import type { AppSyncResolverEvent } from "aws-lambda";
|
|
3
|
-
export declare class AppSyncError extends Error {
|
|
4
|
-
readonly type: string;
|
|
5
|
-
constructor(message: string, type?: string);
|
|
6
|
-
}
|
|
7
|
-
export type AppSyncBatchResponse<TData = any> = {
|
|
8
|
-
data?: TData | null;
|
|
9
|
-
errorMessage?: string;
|
|
10
|
-
errorType?: string;
|
|
11
|
-
};
|
|
12
|
-
export type AppSyncResolverEvents<
|
|
13
|
-
TArguments,
|
|
14
|
-
TSource = Record<string, any> | null
|
|
15
|
-
> = AppSyncResolverEvent<TArguments, TSource> | AppSyncResolverEvent<TArguments, TSource>[];
|
|
16
|
-
export type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined;
|
|
17
|
-
export type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>;
|
|
18
|
-
type Options<TData = any> = {
|
|
19
|
-
buildResponse?: BuildResponseFn<TData>;
|
|
20
|
-
};
|
|
21
|
-
declare const _default: <
|
|
22
|
-
TArguments = any,
|
|
23
|
-
TData = any,
|
|
24
|
-
TSource = Record<string, any> | null
|
|
25
|
-
>(opts?: Options<TData>) => middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>>;
|
|
26
|
-
export default _default;
|
package/dist/index.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type middy from "@middy/core";
|
|
2
|
-
import type { AppSyncResolverEvent } from "aws-lambda";
|
|
3
|
-
export declare class AppSyncError extends Error {
|
|
4
|
-
readonly type: string;
|
|
5
|
-
constructor(message: string, type?: string);
|
|
6
|
-
}
|
|
7
|
-
export type AppSyncBatchResponse<TData = any> = {
|
|
8
|
-
data?: TData | null;
|
|
9
|
-
errorMessage?: string;
|
|
10
|
-
errorType?: string;
|
|
11
|
-
};
|
|
12
|
-
export type AppSyncResolverEvents<
|
|
13
|
-
TArguments,
|
|
14
|
-
TSource = Record<string, any> | null
|
|
15
|
-
> = AppSyncResolverEvent<TArguments, TSource> | AppSyncResolverEvent<TArguments, TSource>[];
|
|
16
|
-
export type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined;
|
|
17
|
-
export type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>;
|
|
18
|
-
type Options<TData = any> = {
|
|
19
|
-
buildResponse?: BuildResponseFn<TData>;
|
|
20
|
-
};
|
|
21
|
-
declare const _default: <
|
|
22
|
-
TArguments = any,
|
|
23
|
-
TData = any,
|
|
24
|
-
TSource = Record<string, any> | null
|
|
25
|
-
>(opts?: Options<TData>) => middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>>;
|
|
26
|
-
export default _default;
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type middy from '@middy/core'\nimport type { AppSyncResolverEvent } from 'aws-lambda'\n\nexport class AppSyncError extends Error {\n readonly type: string\n\n constructor(message: string, type = 'UnknownError') {\n super(message)\n this.type = type\n }\n}\n\nexport type AppSyncBatchResponse<TData = any> = {\n data?: TData | null\n errorMessage?: string\n errorType?: string\n}\n\nexport type AppSyncResolverEvents<TArguments, TSource = Record<string, any> | null> =\n | AppSyncResolverEvent<TArguments, TSource>\n | AppSyncResolverEvent<TArguments, TSource>[]\n\nexport type AppSyncResponse<TData> = AppSyncBatchResponse<TData> | TData | Error | null | undefined\n\nexport type BuildResponseFn<TData = any> = (response: TData | Error | null | undefined, batchInvoke: boolean) => AppSyncResponse<TData>\n\ntype Options<TData = any> = {\n buildResponse?: BuildResponseFn<TData>\n}\n\nconst defaultBuildResponse = <TData>(response: TData | Error | null | undefined, batchInvoke: boolean): AppSyncResponse<TData> => {\n if (batchInvoke) {\n if (response instanceof AppSyncError) {\n return {\n errorMessage: response.message,\n errorType: response.type,\n }\n }\n if (response instanceof Error) {\n return {\n errorMessage: response.message,\n }\n }\n return {\n data: response,\n }\n }\n return response\n}\n\nexport default <TArguments = any, TData = any, TSource = Record<string, any> | null>(\n opts: Options<TData> = {},\n): middy.MiddlewareObj<AppSyncResolverEvents<TArguments, TSource>, AppSyncResponse<TData>> => {\n const buildResponse: BuildResponseFn<TData> = opts.buildResponse ?? defaultBuildResponse\n\n const afterFn: middy.MiddlewareFn = (request) => {\n const { event, response } = request\n\n if (Array.isArray(event)) {\n // for BatchInvoke\n if (!Array.isArray(response) || event.length !== response.length) {\n throw new Error('BatchInvoke: The response does not match the request payload')\n }\n request.response = response.map((r) => buildResponse(r, true))\n } else {\n const resp = buildResponse(response, false)\n if (resp instanceof Error) {\n throw resp\n }\n request.response = resp\n }\n }\n\n const onErrorFn: middy.MiddlewareFn = (request) => {\n const { event, error, response } = request\n\n if (response !== undefined) {\n return\n }\n\n const isBatchInvoke = Array.isArray(event)\n const resp = buildResponse(error, isBatchInvoke)\n if (isBatchInvoke) {\n // 全てエラー扱いにする\n const tmp = new Array(event.length)\n request.response = tmp.fill(resp)\n } else if (!(resp instanceof Error)) {\n request.response = resp\n }\n }\n\n return {\n after: afterFn,\n onError: onErrorFn,\n }\n}\n"],"mappings":";AAGA,IAAa,eAAb,cAAkC,MAAM;CACtC;CAEA,YAAY,SAAiB,OAAO,gBAAgB;AAClD,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAsBhB,MAAM,wBAA+B,UAA4C,gBAAiD;AAChI,KAAI,aAAa;AACf,MAAI,oBAAoB,aACtB,QAAO;GACL,cAAc,SAAS;GACvB,WAAW,SAAS;GACrB;AAEH,MAAI,oBAAoB,MACtB,QAAO,EACL,cAAc,SAAS,SACxB;AAEH,SAAO,EACL,MAAM,UACP;;AAEH,QAAO;;AAGT,IAAA,eACE,OAAuB,EAAE,KACmE;CAC5F,MAAM,gBAAwC,KAAK,iBAAiB;CAEpE,MAAM,WAA+B,YAAY;EAC/C,MAAM,EAAE,OAAO,aAAa;AAE5B,MAAI,MAAM,QAAQ,MAAM,EAAE;AAExB,OAAI,CAAC,MAAM,QAAQ,SAAS,IAAI,MAAM,WAAW,SAAS,OACxD,OAAM,IAAI,MAAM,+DAA+D;AAEjF,WAAQ,WAAW,SAAS,KAAK,MAAM,cAAc,GAAG,KAAK,CAAC;SACzD;GACL,MAAM,OAAO,cAAc,UAAU,MAAM;AAC3C,OAAI,gBAAgB,MAClB,OAAM;AAER,WAAQ,WAAW;;;CAIvB,MAAM,aAAiC,YAAY;EACjD,MAAM,EAAE,OAAO,OAAO,aAAa;AAEnC,MAAI,aAAa,KAAA,EACf;EAGF,MAAM,gBAAgB,MAAM,QAAQ,MAAM;EAC1C,MAAM,OAAO,cAAc,OAAO,cAAc;AAChD,MAAI,cAGF,SAAQ,WADI,IAAI,MAAM,MAAM,OAAO,CACZ,KAAK,KAAK;WACxB,EAAE,gBAAgB,OAC3B,SAAQ,WAAW;;AAIvB,QAAO;EACL,OAAO;EACP,SAAS;EACV"}
|