Skip to content

Commit 05eeb63

Browse files
committed
update tsconfig and add internal flag
1 parent 867f415 commit 05eeb63

15 files changed

+68
-106
lines changed

.eslintrc.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
"parserOptions": {
33
"ecmaVersion": 10,
44
"parser": "@typescript-eslint/parser",
5-
"project": "./tsconfig.json"
5+
"project": "./tsconfig.eslint.json"
66
},
77
"extends": [
88
"airbnb-typescript/base",
@@ -76,13 +76,21 @@ module.exports = {
7676
"@typescript-eslint/no-magic-numbers": 'off',
7777
"@typescript-eslint/no-floating-promises": ["error", { "ignoreIIFE": true }],
7878
"@typescript-eslint/no-duplicate-imports": "error",
79+
"@typescript-eslint/restrict-template-expressions": "off",
7980
"@typescript-eslint/no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions"}],
8081
// Function
8182
"func-style": "off"
8283
},
84+
"overrides":[
85+
{
86+
"files": ["./__tests__/**/*.ts"],
87+
"env": {
88+
"node": true,
89+
"jest": true
90+
}
91+
}
92+
],
8393
"env": {
84-
"node": true,
85-
"browser": true,
86-
"jest": true
94+
"node": true
8795
},
8896
};

__tests__/.eslintrc.js

+3-74
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,11 @@
11
module.exports = {
2-
"parserOptions": {
3-
"ecmaVersion": 10,
4-
"parser": "@typescript-eslint/parser",
5-
"project": "./tsconfig.json"
6-
},
72
"extends": [
8-
"airbnb-typescript/base",
9-
"hardcore/ts-for-js",
10-
"hardcore",
11-
"hardcore/fp"
12-
],
13-
"plugins": [
14-
"@typescript-eslint",
15-
"unicorn",
16-
"functional",
17-
"jest"
3+
"../.eslintrc.js",
184
],
19-
"settings": {
20-
"import/resolver": {
21-
"node": {
22-
"extensions": [
23-
".js",
24-
".ts",
25-
".d.ts"
26-
],
27-
"moduleDirectory": [
28-
"node_modules",
29-
"./src"
30-
]
31-
}
32-
}
33-
},
5+
346
"rules": {
35-
// Import
36-
"import/extensions": [
37-
"error",
38-
"ignorePackages",
39-
{
40-
"js": "never",
41-
"ts": "never",
42-
}
43-
],
44-
"import/order": "off",
45-
"import/no-cycle": "off",
46-
"import/unambiguous": "off",
47-
"import/no-namespace": "off",
48-
"import/group-exports": "off",
49-
"import/exports-last": "off",
50-
"import/prefer-default-export": "off",
51-
"import/no-unused-modules": "off",
7+
"import/no-extraneous-dependencies": "off",
528
"no-param-reassign": "off",
53-
// Eslint General
54-
"max-len": [
55-
"warn",
56-
{
57-
"code": 100,
58-
"ignoreStrings": true,
59-
"ignoreUrls": true,
60-
"ignoreComments": true,
61-
"ignoreTemplateLiterals": true,
62-
"ignoreRegExpLiterals": true
63-
}
64-
],
65-
"no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions"}],
66-
"no-underscore-dangle": "off",
67-
"no-console": "off",
68-
"no-magic-numbers": "off",
69-
"no-unused-vars": "off",
70-
"consistent-return": "off",
71-
"require-atomic-updates": "off",
72-
"lines-around-comment": "off",
73-
// Typescript
74-
"@typescript-eslint/ban-ts-comment": "off",
75-
"@typescript-eslint/naming-convention": "off",
76-
"@typescript-eslint/no-magic-numbers": "off",
77-
"@typescript-eslint/no-floating-promises": ["error", { "ignoreIIFE": true }],
78-
"@typescript-eslint/no-duplicate-imports": "error",
79-
"@typescript-eslint/no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions"}],
809
// Function
8110
"func-style": "off",
8211
// FP

__tests__/error.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
simpleResponse,
88
} from "../src";
99
import { lambdaExecutor } from "./fixtures/helpers";
10-
import createHttpError from "http-errors";
10+
import * as createHttpError from "http-errors";
1111

1212
it("If an error occur during the flow it is returned in the body", async () => {
1313
const flow = lambdaFlow((box) => {
@@ -251,7 +251,7 @@ it("If an error is attached to the box the other functions of the flow are not r
251251
return box;
252252
},
253253
(box) => {
254-
toMutate = "mutated";
254+
toMutate = "mutated2";
255255

256256
return box;
257257
}
@@ -292,7 +292,7 @@ it("If is compatible with http-error", async () => {
292292
return box;
293293
},
294294
(box) => {
295-
toMutate = "mutated";
295+
toMutate = "mutated3";
296296

297297
return box;
298298
}
@@ -312,11 +312,11 @@ it("If is compatible with http-error", async () => {
312312
let toMutate = "Not mutated";
313313

314314
const flow = lambdaFlow(
315-
(box) => {
315+
() => {
316316
throw new createHttpError.NotFound();
317317
},
318318
(box) => {
319-
toMutate = "mutated";
319+
toMutate = "mutated4";
320320

321321
return box;
322322
}

__tests__/fixtures/data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable unicorn/no-null */
12
import { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from "aws-lambda";
23

34
const lambdaContext = {

__tests__/flow.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ it("Does not return the FlowBox", async () => {
2020
const flow = lambdaFlow(simpleResponse())();
2121
const response = await lambdaExecutor(flow);
2222

23-
// @ts-ignore for test
23+
// @ts-expect-error
2424
expect(response.state).toBe(undefined);
2525
});
2626

__tests__/gard.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/* eslint-disable unicorn/consistent-function-scoping */
12
import { FlowBox } from "../src/types";
23
import { lambdaFlow } from "../src";
34
import { lambdaExecutor } from "./fixtures/helpers";
45

6+
// eslint-disable-next-line max-statements
57
it("A middleware has to return a box", async () => {
68
const originalLog = console.log;
79

@@ -17,7 +19,7 @@ it("A middleware has to return a box", async () => {
1719

1820
return box;
1921
},
20-
// @ts-ignore
22+
// @ts-expect-error
2123
wrongMiddleware
2224
)();
2325

@@ -49,7 +51,7 @@ it("Only allowed key of box can be mutated", async () => {
4951
const wrongMiddleware = (box: FlowBox) => {
5052
box.statusCode = 200;
5153
box.body = { name: true };
52-
// @ts-ignore
54+
// @ts-expect-error
5355
box.mutation = 9;
5456

5557
return box;

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
"type": "git",
1010
"url": "https://github.com/BjMrq/LambdaFlow"
1111
},
12-
"main": "dist/src/index.js",
13-
"types": "dist/src/index.d.ts",
12+
"main": "dist/index.js",
13+
"types": "dist/index.d.ts",
1414
"files": [
15-
"dist/src/**/*"
15+
"dist/**/*"
1616
],
17+
"volta": {
18+
"node": "12.20.0",
19+
"yarn": "1.22.10"
20+
},
1721
"scripts": {
1822
"prepare": "npm run build",
1923
"prepublishOnly": "npm test",
@@ -22,7 +26,7 @@
2226
"test": "jest -i --config jestconfig.json"
2327
},
2428
"dependencies": {
25-
"@bjmrq/utils": "^0.0.19",
29+
"@bjmrq/utils": "^0.0.20",
2630
"aws-lambda": "^1.0.6",
2731
"fp-ts": "^2.8.4",
2832
"ramda": "^0.27.1"
@@ -65,4 +69,4 @@
6569
"serverless",
6670
"apigateway"
6771
]
68-
}
72+
}

src/helpers/helpers-error.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const errorBuilder: ErrorBuilder = (expose = false) => (statusCode = 500) => (
1313
) => ({
1414
expose,
1515
statusCode,
16-
message: R.when(R.is(Object), R.prop("message"))(message),
17-
error: R.unless(R.is(Object), () => new Error(message as string))(message),
16+
message: R.when(R.is(Error), R.prop("message"))(message),
17+
error: R.unless(R.is(Error), () => new Error(message as string))(message),
1818
});
1919

2020
/**

src/lambda-flow.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from "./types";
2727
import enhancedErrors from "./utils/guards-reasons";
2828

29+
// @internal
2930
const createBox: CreateBox = (event, context, callback) =>
3031
Object.seal({
3132
state: {},
@@ -41,6 +42,7 @@ const createBox: CreateBox = (event, context, callback) =>
4142
multiValueHeaders: undefined,
4243
});
4344

45+
// @internal
4446
const errorResponse = flow(
4547
R.over(
4648
toBodyErrorResponseLens,
@@ -61,6 +63,7 @@ const errorResponse = flow(
6163
)
6264
);
6365

66+
// @internal
6467
const successResponse = flow(
6568
R.over(toIsEncodedResponseLens, R.identity),
6669
R.over(toStatusResponseLens, R.unless(R.is(Number), R.always(200))),
@@ -70,6 +73,7 @@ const successResponse = flow(
7073
)
7174
);
7275

76+
// @internal
7377
const returnResponse: ResponseMiddleware = async (box) =>
7478
flow(
7579
R.set(responseLens, {}),
@@ -84,6 +88,7 @@ const returnResponse: ResponseMiddleware = async (box) =>
8488
R.prop("response")
8589
)(await box) as Promise<APIGatewayProxyStructuredResultV2>;
8690

91+
// @internal
8792
const validateBoxState = (middleware: FlowMiddleware) =>
8893
R.unless(
8994
R.is(Object),
@@ -97,6 +102,7 @@ const validateBoxState = (middleware: FlowMiddleware) =>
97102
)
98103
);
99104

105+
// @internal
100106
const notCatchedErrors = (middleware: FlowMiddleware) => (
101107
error: Error,
102108
errorBox: FlowBoxWithError
@@ -107,30 +113,30 @@ const notCatchedErrors = (middleware: FlowMiddleware) => (
107113
R.tap(logError)
108114
);
109115

116+
// @internal
110117
const errorOut: ErrorOut = (middleware) => async (box) =>
111-
// @ts-ignore
118+
// @ts-expect-error
112119
flow(
113-
// @ts-ignore
114120
R.unless(
115121
flow(R.prop("error"), R.is(Object)),
116-
// @ts-ignore
117122
// TODO have a look at ramda otherwise
118123
tryCatchAsync(
119-
// @ts-ignore
124+
// @ts-expect-error
120125
flow(middleware, validateBoxState(middleware)),
121126
notCatchedErrors(middleware)
122127
)
123128
)
124-
// @ts-ignore
129+
// @ts-expect-error
125130
)(await box);
126131

132+
// @internal
127133
const errorCallbackHandler: ErrorCallbackHandler = (errorCallback) => async (
128134
box
129135
) =>
130-
// @ts-ignore
136+
// @ts-expect-error
131137
R.when(
132138
flow(R.prop("error"), R.is(Object)),
133-
// @ts-ignore
139+
// @ts-expect-error
134140
flow(R.clone, errorCallback, R.always(await box))
135141
)(await box);
136142

@@ -142,10 +148,10 @@ const errorCallbackHandler: ErrorCallbackHandler = (errorCallback) => async (
142148
const lambdaFlow: LambdaFlow = (...middlewares) => (
143149
errorCallback = R.identity
144150
) =>
145-
// @ts-ignore
151+
// @ts-expect-error
146152
flow(
147153
createBox,
148-
// @ts-ignore
154+
// @ts-expect-error
149155
...R.map(errorOut)(middlewares),
150156
errorCallbackHandler(errorCallback),
151157
returnResponse

src/types/error.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type ErrorBuilder = (
1313

1414
export type ErrorCallback = (box: FlowBoxWithError) => void;
1515

16+
// @internal
1617
export type ErrorCallbackHandler = (
1718
errorCallback: ErrorCallback
1819
) => (box: Promise<FlowBox>) => Promise<FlowBox>;

src/types/helpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
} from "./middleware";
77

88
// Middleware helpers
9+
// @internal
910
export type HandleAsyncMiddleware = <
1011
M extends FlowSyncMiddleware<M> | FlowAsyncMiddleware<M>
1112
>(
1213
middleware: M
1314
) => (box: Promise<FlowBox<M>>) => Promise<FlowBox<M>>;
1415

16+
// @internal
1517
export type ErrorOut = <M extends FlowMiddleware>(
1618
middleware: M
1719
) => (box: Promise<FlowBox>) => Promise<FlowBox>;

src/types/internals.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "aws-lambda";
77
import { FlowBox } from "./box";
88

9+
// @internal
910
export type CreateBox = (
1011
event: APIGatewayProxyEventV2,
1112
context: Context,

src/utils/guards-reasons.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { boxMutated } from "./guards-messages";
77
const enhancedErrors = (middleware: FlowMiddleware) =>
88
R.ifElse(
99
flow(
10-
// @ts-ignore
10+
// @ts-expect-error
1111
R.prop("message"),
1212
R.includes("object is not extensible")
1313
),

tsconfig.eslint.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": [
4+
"./src",
5+
"./__tests__"
6+
]
7+
}

0 commit comments

Comments
 (0)