Skip to content

Commit 92e740c

Browse files
committed
WIP
1 parent 4c37964 commit 92e740c

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"dependencies": {
2929
"@bjmrq/utils": "^0.0.20",
3030
"aws-lambda": "^1.0.6",
31-
"fp-ts": "^2.8.4",
3231
"ramda": "^0.27.1"
3332
},
3433
"devDependencies": {
@@ -69,4 +68,4 @@
6968
"serverless",
7069
"apigateway"
7170
]
72-
}
71+
}

src/helpers/helpers-middlewares.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { flow } from "fp-ts/lib/function";
21
import * as R from "ramda";
32
import { FlowMiddleware } from "../types/middleware";
43

@@ -8,6 +7,6 @@ import { FlowMiddleware } from "../types/middleware";
87
* @returns {FlowMiddleware} The middleware that will attach the status code you passed on the box with a {status = "success"} on the body
98
*/
109
const simpleResponse = (status = 200): FlowMiddleware =>
11-
flow(R.assoc("statusCode", status), R.assoc("body", { status: "success" }));
10+
R.pipe(R.assoc("statusCode", status), R.assoc("body", { status: "success" }));
1211

1312
export { simpleResponse };

src/lambda-flow.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { APIGatewayProxyStructuredResultV2 } from "aws-lambda";
2-
import { flow, pipe } from "fp-ts/lib/function";
32
import * as R from "ramda";
43
import { ErrorCallbackHandler } from "./types/error";
54
import { tryCatchAsync } from "@bjmrq/utils";
@@ -43,10 +42,10 @@ const createBox: CreateBox = (event, context, callback) =>
4342
});
4443

4544
// @internal
46-
const errorResponse = flow(
45+
const errorResponse = R.pipe(
4746
R.over(
4847
toBodyErrorResponseLens,
49-
flow(
48+
R.pipe(
5049
R.ifElse(
5150
isErrorExposed,
5251
R.prop("message"),
@@ -64,7 +63,7 @@ const errorResponse = flow(
6463
);
6564

6665
// @internal
67-
const successResponse = flow(
66+
const successResponse = R.pipe(
6867
R.over(toIsEncodedResponseLens, R.identity),
6968
R.over(toStatusResponseLens, R.unless(R.is(Number), R.always(200))),
7069
R.over(
@@ -75,13 +74,13 @@ const successResponse = flow(
7574

7675
// @internal
7776
const returnResponse: ResponseMiddleware = async (box) =>
78-
flow(
77+
R.pipe(
7978
R.set(responseLens, {}),
8079
R.over(toCookiesResponseLens, R.identity),
8180
R.over(toHeadersResponseLens, R.identity),
8281
R.over(toMultiValueHeadersResponseLens, R.identity),
8382
R.ifElse(
84-
flow(R.prop("error"), R.is(Object)),
83+
R.pipe(R.prop("error"), R.is(Object)),
8584
errorResponse,
8685
successResponse
8786
),
@@ -92,7 +91,7 @@ const returnResponse: ResponseMiddleware = async (box) =>
9291
const validateBoxState = (middleware: FlowMiddleware) =>
9392
R.unless(
9493
R.is(Object),
95-
flow(
94+
R.pipe(
9695
R.tap(bodyNotReturned(middleware)),
9796
R.always({
9897
error: {
@@ -107,26 +106,27 @@ const notCatchedErrors = (middleware: FlowMiddleware) => (
107106
error: Error,
108107
errorBox: FlowBoxWithError
109108
) =>
110-
pipe(
111-
errorBox,
109+
R.pipe(
110+
// @ts-expect-error
112111
R.assoc("error", enhancedErrors(middleware)(error)),
113112
R.tap(logError)
114-
);
113+
// @ts-expect-error
114+
)(errorBox);
115115

116116
// @internal
117117
const errorOut: ErrorOut = (middleware) => async (box) =>
118118
// @ts-expect-error
119-
flow(
119+
R.pipe(
120120
R.unless(
121-
flow(R.prop("error"), R.is(Object)),
121+
// @ts-expect-error
122+
R.pipe(R.prop("error"), R.is(Object)),
122123
// TODO have a look at ramda otherwise
123124
tryCatchAsync(
124125
// @ts-expect-error
125-
flow(middleware, validateBoxState(middleware)),
126+
R.pipe(middleware, validateBoxState(middleware)),
126127
notCatchedErrors(middleware)
127128
)
128129
)
129-
// @ts-expect-error
130130
)(await box);
131131

132132
// @internal
@@ -135,9 +135,10 @@ const errorCallbackHandler: ErrorCallbackHandler = (errorCallback) => async (
135135
) =>
136136
// @ts-expect-error
137137
R.when(
138-
flow(R.prop("error"), R.is(Object)),
139138
// @ts-expect-error
140-
flow(R.clone, errorCallback, R.always(await box))
139+
R.pipe(R.prop("error"), R.is(Object)),
140+
R.pipe(R.clone, errorCallback, R.always(await box))
141+
// @ts-expect-error
141142
)(await box);
142143

143144
/**

src/utils/guards-reasons.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import { flow } from "fp-ts/lib/function";
21
import * as R from "ramda";
32
import { FlowMiddleware } from "../types";
43
import { simpleError } from "../helpers/helpers-error";
54
import { boxMutated } from "./guards-messages";
65

76
const enhancedErrors = (middleware: FlowMiddleware) =>
87
R.ifElse(
9-
flow(
10-
// @ts-expect-error
11-
R.prop("message"),
12-
R.includes("object is not extensible")
13-
),
14-
flow(R.tap(boxMutated(middleware)), simpleError),
8+
R.pipe(R.prop("message"), R.includes("object is not extensible")),
9+
R.pipe(R.tap(boxMutated(middleware)), simpleError),
1510
simpleError
1611
);
1712

0 commit comments

Comments
 (0)