@aeriajs/common 0.0.50 → 0.0.52
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/either.d.ts +0 -2
- package/dist/either.js +1 -3
- package/dist/either.mjs +0 -2
- package/dist/error.d.ts +6 -0
- package/dist/error.js +18 -0
- package/dist/error.mjs +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/isGranted.js +1 -1
- package/dist/isGranted.mjs +1 -1
- package/dist/schema.d.ts +15 -1
- package/dist/schema.js +18 -1
- package/dist/schema.mjs +16 -0
- package/package.json +2 -2
- package/dist/endpointError.d.ts +0 -2
- package/dist/endpointError.js +0 -11
- package/dist/endpointError.mjs +0 -8
package/dist/either.d.ts
CHANGED
|
@@ -4,6 +4,4 @@ export declare const right: <const T>(value: T) => Right<T>;
|
|
|
4
4
|
export declare const isLeft: <L>(either: Either<L, any>) => either is Left<L>;
|
|
5
5
|
export declare const isRight: <R>(either: Either<any, R>) => either is Right<R>;
|
|
6
6
|
export declare const unwrapEither: <L, R>(either: Either<L, R>) => L | R;
|
|
7
|
-
export declare const error: <const T>(value: T) => Left<T>;
|
|
8
|
-
export declare const ok: <const T>(value: T) => Right<T>;
|
|
9
7
|
export declare const unsafe: <L, R>(either: Either<L, R>, message?: any) => R;
|
package/dist/either.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsafe = exports.
|
|
3
|
+
exports.unsafe = exports.unwrapEither = exports.isRight = exports.isLeft = exports.right = exports.left = void 0;
|
|
4
4
|
const left = (value) => ({
|
|
5
5
|
_tag: 'Left',
|
|
6
6
|
value,
|
|
@@ -23,8 +23,6 @@ const unwrapEither = (either) => {
|
|
|
23
23
|
return either.value;
|
|
24
24
|
};
|
|
25
25
|
exports.unwrapEither = unwrapEither;
|
|
26
|
-
exports.error = exports.left;
|
|
27
|
-
exports.ok = exports.right;
|
|
28
26
|
const unsafe = (either, message) => {
|
|
29
27
|
if (either._tag !== 'Right') {
|
|
30
28
|
if (process.env.NODE_ENV !== 'production') {
|
package/dist/either.mjs
CHANGED
|
@@ -16,8 +16,6 @@ export const isRight = (either) => {
|
|
|
16
16
|
export const unwrapEither = (either) => {
|
|
17
17
|
return either.value;
|
|
18
18
|
};
|
|
19
|
-
export const error = left;
|
|
20
|
-
export const ok = right;
|
|
21
19
|
export const unsafe = (either, message) => {
|
|
22
20
|
if (either._tag !== "Right") {
|
|
23
21
|
if (true) {
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EndpointError, EndpointErrorContent, RouteContext } from '@aeriajs/types';
|
|
2
|
+
export declare const error: <TEndpointErrorContent extends EndpointErrorContent>(error: TEndpointErrorContent, context: Pick<RouteContext, 'response'>) => {
|
|
3
|
+
readonly _tag: "Error";
|
|
4
|
+
readonly error: TEndpointErrorContent;
|
|
5
|
+
};
|
|
6
|
+
export declare const isError: (object: any) => object is EndpointError<any>;
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isError = exports.error = void 0;
|
|
4
|
+
const error = (error, context) => {
|
|
5
|
+
const { httpCode = 500 } = error;
|
|
6
|
+
context.response.writeHead(httpCode, {
|
|
7
|
+
'content-type': 'application/json',
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
_tag: 'Error',
|
|
11
|
+
error,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.error = error;
|
|
15
|
+
const isError = (object) => {
|
|
16
|
+
return object._tag === 'Error';
|
|
17
|
+
};
|
|
18
|
+
exports.isError = isError;
|
package/dist/error.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export const error = (error2, context) => {
|
|
3
|
+
const { httpCode = 500 } = error2;
|
|
4
|
+
context.response.writeHead(httpCode, {
|
|
5
|
+
"content-type": "application/json"
|
|
6
|
+
});
|
|
7
|
+
return {
|
|
8
|
+
_tag: "Error",
|
|
9
|
+
error: error2
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export const isError = (object) => {
|
|
13
|
+
return object._tag === "Error";
|
|
14
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './deepClone.js';
|
|
|
6
6
|
export * from './deepMerge.js';
|
|
7
7
|
export * from './dynamicImport.js';
|
|
8
8
|
export * from './either.js';
|
|
9
|
-
export * from './
|
|
9
|
+
export * from './error.js';
|
|
10
10
|
export * from './evaluateCondition.js';
|
|
11
11
|
export * from './formatValue.js';
|
|
12
12
|
export * from './freshItem.js';
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ __exportStar(require("./deepClone.js"), exports);
|
|
|
22
22
|
__exportStar(require("./deepMerge.js"), exports);
|
|
23
23
|
__exportStar(require("./dynamicImport.js"), exports);
|
|
24
24
|
__exportStar(require("./either.js"), exports);
|
|
25
|
-
__exportStar(require("./
|
|
25
|
+
__exportStar(require("./error.js"), exports);
|
|
26
26
|
__exportStar(require("./evaluateCondition.js"), exports);
|
|
27
27
|
__exportStar(require("./formatValue.js"), exports);
|
|
28
28
|
__exportStar(require("./freshItem.js"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./deepClone.mjs";
|
|
|
7
7
|
export * from "./deepMerge.mjs";
|
|
8
8
|
export * from "./dynamicImport.mjs";
|
|
9
9
|
export * from "./either.mjs";
|
|
10
|
-
export * from "./
|
|
10
|
+
export * from "./error.mjs";
|
|
11
11
|
export * from "./evaluateCondition.mjs";
|
|
12
12
|
export * from "./formatValue.mjs";
|
|
13
13
|
export * from "./freshItem.mjs";
|
package/dist/isGranted.js
CHANGED
|
@@ -6,7 +6,7 @@ const isGranted = (condition, token) => {
|
|
|
6
6
|
if (Array.isArray(condition)) {
|
|
7
7
|
return token.authenticated
|
|
8
8
|
? (0, arraysIntersects_js_1.arraysIntersects)(token.roles, condition)
|
|
9
|
-
: condition.includes('
|
|
9
|
+
: condition.includes('unauthenticated');
|
|
10
10
|
}
|
|
11
11
|
switch (condition) {
|
|
12
12
|
case false: return false;
|
package/dist/isGranted.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { arraysIntersects } from "./arraysIntersects.mjs";
|
|
3
3
|
export const isGranted = (condition, token) => {
|
|
4
4
|
if (Array.isArray(condition)) {
|
|
5
|
-
return token.authenticated ? arraysIntersects(token.roles, condition) : condition.includes("
|
|
5
|
+
return token.authenticated ? arraysIntersects(token.roles, condition) : condition.includes("unauthenticated");
|
|
6
6
|
}
|
|
7
7
|
switch (condition) {
|
|
8
8
|
case false:
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Property, ObjectToSchema, EndpointErrorContent } from '@aeriajs/types';
|
|
2
2
|
export declare const fromLiteral: <const TObject, TRequired extends (keyof TObject & string)[]>(object: TObject, required?: TRequired) => ObjectToSchema<TObject, TRequired>;
|
|
3
3
|
export declare const leftSchema: <const TObject extends Property>(object: TObject) => {
|
|
4
4
|
readonly type: "object";
|
|
@@ -18,3 +18,17 @@ export declare const rightSchema: <const TObject extends Property>(object: TObje
|
|
|
18
18
|
readonly value: Property;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
+
export declare const endpointErrorSchema: (error: EndpointErrorContent) => {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {
|
|
24
|
+
readonly httpCode: {
|
|
25
|
+
readonly const: string;
|
|
26
|
+
};
|
|
27
|
+
readonly code: {
|
|
28
|
+
readonly const: string;
|
|
29
|
+
};
|
|
30
|
+
readonly message: {
|
|
31
|
+
readonly const: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
package/dist/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rightSchema = exports.leftSchema = exports.fromLiteral = void 0;
|
|
3
|
+
exports.endpointErrorSchema = exports.rightSchema = exports.leftSchema = exports.fromLiteral = void 0;
|
|
4
4
|
const mapValueToProperty = (value) => {
|
|
5
5
|
if (value.constructor === Object) {
|
|
6
6
|
return Object.assign({
|
|
@@ -72,3 +72,20 @@ const rightSchema = (object) => {
|
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
exports.rightSchema = rightSchema;
|
|
75
|
+
const endpointErrorSchema = (error) => {
|
|
76
|
+
return {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
httpCode: {
|
|
80
|
+
const: error.code,
|
|
81
|
+
},
|
|
82
|
+
code: {
|
|
83
|
+
const: error.code,
|
|
84
|
+
},
|
|
85
|
+
message: {
|
|
86
|
+
const: error.message,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.endpointErrorSchema = endpointErrorSchema;
|
package/dist/schema.mjs
CHANGED
|
@@ -67,3 +67,19 @@ export const rightSchema = (object) => {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
+
export const endpointErrorSchema = (error) => {
|
|
71
|
+
return {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
httpCode: {
|
|
75
|
+
const: error.code
|
|
76
|
+
},
|
|
77
|
+
code: {
|
|
78
|
+
const: error.code
|
|
79
|
+
},
|
|
80
|
+
message: {
|
|
81
|
+
const: error.message
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.52",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bson": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
+
"@aeriajs/types": "^0.0.49",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
package/dist/endpointError.d.ts
DELETED
package/dist/endpointError.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.endpointError = void 0;
|
|
4
|
-
const endpointError = (error, context) => {
|
|
5
|
-
const { httpCode = 500 } = error;
|
|
6
|
-
context.response.writeHead(httpCode, {
|
|
7
|
-
'content-type': 'application/json',
|
|
8
|
-
});
|
|
9
|
-
return error;
|
|
10
|
-
};
|
|
11
|
-
exports.endpointError = endpointError;
|