@stryke/trpc-next 0.5.0 → 0.5.1
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/shield/shield.cjs +10 -10
- package/dist/shield/shield.d.ts +1 -1
- package/dist/shield/shield.mjs +1 -1
- package/package.json +1 -1
package/dist/shield/shield.cjs
CHANGED
|
@@ -8,17 +8,17 @@ var _constructors = require("./constructors.cjs");
|
|
|
8
8
|
var _generator = require("./generator.cjs");
|
|
9
9
|
var _utils = require("./utils.cjs");
|
|
10
10
|
var _validation = require("./validation.cjs");
|
|
11
|
-
function u(
|
|
12
|
-
return typeof
|
|
13
|
-
debug:
|
|
14
|
-
allowExternalErrors: (0, _utils.withDefault)(!1)(
|
|
15
|
-
fallbackRule: (0, _utils.withDefault)(_constructors.allow)(
|
|
16
|
-
fallbackError: (0, _utils.withDefault)(new Error("
|
|
11
|
+
function u(r) {
|
|
12
|
+
return typeof r.fallbackError == "string" && (r.fallbackError = new Error(r.fallbackError)), {
|
|
13
|
+
debug: r.debug ?? !1,
|
|
14
|
+
allowExternalErrors: (0, _utils.withDefault)(!1)(r.allowExternalErrors),
|
|
15
|
+
fallbackRule: (0, _utils.withDefault)(_constructors.allow)(r.fallbackRule),
|
|
16
|
+
fallbackError: (0, _utils.withDefault)(new Error("Authorization error"))(r.fallbackError)
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
function shield(
|
|
19
|
+
function shield(r, o = {}) {
|
|
20
20
|
const n = u(o),
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
throw new _validation.ValidationError(
|
|
21
|
+
t = (0, _validation.validateRuleTree)(r);
|
|
22
|
+
if (t.status === "ok") return (0, _generator.generateMiddlewareFromRuleTree)(r, n);
|
|
23
|
+
throw new _validation.ValidationError(t.message);
|
|
24
24
|
}
|
package/dist/shield/shield.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import type { IOptionsConstructor, IRules } from "./types";
|
|
|
3
3
|
/**
|
|
4
4
|
* Validates rules and generates middleware from defined rule tree.
|
|
5
5
|
*/
|
|
6
|
-
export declare function shield<TContext extends Record<string, any>, TMeta extends object = object
|
|
6
|
+
export declare function shield<TContext extends Record<string, any>, TMeta extends object = object>(ruleTree: IRules<TContext>, options?: IOptionsConstructor<TContext>): MiddlewareFunction<TContext, TMeta, TContext, TContext, unknown>;
|
package/dist/shield/shield.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{allow as l}from"./constructors";import{generateMiddlewareFromRuleTree as a}from"./generator";import{withDefault as
|
|
1
|
+
import{allow as l}from"./constructors";import{generateMiddlewareFromRuleTree as a}from"./generator";import{withDefault as e}from"./utils";import{ValidationError as i,validateRuleTree as s}from"./validation";function u(r){return typeof r.fallbackError=="string"&&(r.fallbackError=new Error(r.fallbackError)),{debug:r.debug??!1,allowExternalErrors:e(!1)(r.allowExternalErrors),fallbackRule:e(l)(r.fallbackRule),fallbackError:e(new Error("Authorization error"))(r.fallbackError)}}export function shield(r,o={}){const n=u(o),t=s(r);if(t.status==="ok")return a(r,n);throw new i(t.message)}
|