@stryke/trpc-next 0.4.0 → 0.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/server.cjs CHANGED
@@ -4,11 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createTRPCServer = createTRPCServer;
7
+ Object.defineProperty(exports, "notFound", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _nextAppDir.experimental_notFound;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "redirect", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _nextAppDir.experimental_redirect;
17
+ }
18
+ });
7
19
  var _client = require("@trpc/client");
8
20
  var _nextCache = require("@trpc/next/app-dir/links/nextCache");
9
21
  var _server = require("@trpc/next/app-dir/server");
10
22
  var _headers = require("next/headers");
11
23
  var _shared = require("./shared.cjs");
24
+ var _nextAppDir = require("@trpc/server/adapters/next-app-dir");
12
25
  function createTRPCServer(r, t = () => ({})) {
13
26
  return (0, _server.experimental_createTRPCNextAppDirServer)({
14
27
  config() {
package/dist/server.d.ts CHANGED
@@ -31,3 +31,4 @@ export type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord e
31
31
  * @param createContext - An optional function to generate a context
32
32
  */
33
33
  export declare function createTRPCServer<TRouter extends AnyTRPCRouter, TContext extends inferRouterContext<TRouter>>(router: TRouter, createContext?: () => MaybePromise<TContext>): NextAppDirDecorateRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
34
+ export { experimental_notFound as notFound, experimental_redirect as redirect } from "@trpc/server/adapters/next-app-dir";
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- import{loggerLink as o}from"@trpc/client";import{experimental_nextCacheLink as n}from"@trpc/next/app-dir/links/nextCache";import{experimental_createTRPCNextAppDirServer as p}from"@trpc/next/app-dir/server";import{cookies as u}from"next/headers";import{transformer as i}from"./shared";export function createTRPCServer(r,t=()=>({})){return p({config(){return{links:[o({enabled:e=>!0}),n({revalidate:5,router:r,transformer:i,createContext:async()=>{const e=await Promise.resolve(t());return e.headers??={},e.headers["x-trpc-source"]="rsc-invoke",e.headers.cookie=(await u()).toString(),e}})]}}})}
1
+ import{loggerLink as o}from"@trpc/client";import{experimental_nextCacheLink as n}from"@trpc/next/app-dir/links/nextCache";import{experimental_createTRPCNextAppDirServer as p}from"@trpc/next/app-dir/server";import{cookies as u}from"next/headers";import{transformer as i}from"./shared";export function createTRPCServer(r,t=()=>({})){return p({config(){return{links:[o({enabled:e=>!0}),n({revalidate:5,router:r,transformer:i,createContext:async()=>{const e=await Promise.resolve(t());return e.headers??={},e.headers["x-trpc-source"]="rsc-invoke",e.headers.cookie=(await u()).toString(),e}})]}}})}export{experimental_notFound as notFound,experimental_redirect as redirect}from"@trpc/server/adapters/next-app-dir";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.race = exports.or = exports.not = exports.deny = exports.chain = exports.and = exports.allow = void 0;
7
+ var _rules = require("./rules.cjs");
8
+ const rule = (e, t) => o => (typeof e == "object" ? (t = e, e = Math.random().toString()) : typeof e == "string" ? t = t ?? {} : (e = Math.random().toString(), t = {}), new _rules.Rule(e, o, {})),
9
+ and = (...e) => new _rules.RuleAnd(e),
10
+ chain = (...e) => new _rules.RuleChain(e),
11
+ race = (...e) => new _rules.RuleRace(e),
12
+ or = (...e) => new _rules.RuleOr(e),
13
+ not = (e, t) => typeof t == "string" ? new _rules.RuleNot(e, new Error(t)) : new _rules.RuleNot(e, t),
14
+ allow = exports.allow = new _rules.RuleTrue(),
15
+ deny = exports.deny = new _rules.RuleFalse();
16
+ exports.not = not;
17
+ exports.or = or;
18
+ exports.race = race;
19
+ exports.chain = chain;
20
+ exports.and = and;
21
+ exports.rule = rule;
@@ -0,0 +1,54 @@
1
+ import { Rule, RuleAnd, RuleChain, RuleFalse, RuleNot, RuleOr, RuleRace, RuleTrue } from "./rules";
2
+ import type { IRuleConstructorOptions, IRuleFunction, ShieldRule } from "./types";
3
+ /**
4
+ * Wraps a function into a Rule class. This way we can identify rules
5
+ * once we start generating middleware from our ruleTree.
6
+ *
7
+ * ```
8
+ * // 1.
9
+ * const auth = rule()(async (ctx, type, path, input, rawInput, options) => {
10
+ * return true
11
+ * })
12
+ *
13
+ * // 2.
14
+ * const auth = rule('name')(async (ctx, type, path, input, rawInput, options) => {
15
+ * return true
16
+ * })
17
+ *
18
+ * // 3.
19
+ * const auth = rule({
20
+ * name: 'name',
21
+ * })(async (ctx, type, path, input, rawInput, options) => {
22
+ * return true
23
+ * })
24
+ * ```
25
+ */
26
+ export declare const rule: <TContext extends Record<string, any>>(name?: string, options?: IRuleConstructorOptions) => (func: IRuleFunction<TContext>) => Rule<TContext>;
27
+ /**
28
+ * Logical operator and serves as a wrapper for and operation.
29
+ */
30
+ export declare const and: <TContext extends Record<string, any>>(...rules: ShieldRule<TContext>[]) => RuleAnd<TContext>;
31
+ /**
32
+ * Logical operator and serves as a wrapper for and operation.
33
+ */
34
+ export declare const chain: <TContext extends Record<string, any>>(...rules: ShieldRule<TContext>[]) => RuleChain<TContext>;
35
+ /**
36
+ * Logical operator and serves as a wrapper for and operation.
37
+ */
38
+ export declare const race: <TContext extends Record<string, any>>(...rules: ShieldRule<TContext>[]) => RuleRace<TContext>;
39
+ /**
40
+ * Logical operator or serves as a wrapper for or operation.
41
+ */
42
+ export declare const or: <TContext extends Record<string, any>>(...rules: ShieldRule<TContext>[]) => RuleOr<TContext>;
43
+ /**
44
+ * Logical operator not serves as a wrapper for not operation.
45
+ */
46
+ export declare const not: <TContext extends Record<string, any>>(rule: ShieldRule<TContext>, error?: string | Error) => RuleNot<TContext>;
47
+ /**
48
+ * Allow queries.
49
+ */
50
+ export declare const allow: RuleTrue<Record<string, any>>;
51
+ /**
52
+ * Deny queries.
53
+ */
54
+ export declare const deny: RuleFalse<Record<string, any>>;
@@ -0,0 +1 @@
1
+ import{Rule as r,RuleAnd as u,RuleChain as l,RuleFalse as x,RuleNot as n,RuleOr as R,RuleRace as s,RuleTrue as i}from"./rules";export const rule=(e,t)=>o=>(typeof e=="object"?(t=e,e=Math.random().toString()):typeof e=="string"?t=t??{}:(e=Math.random().toString(),t={}),new r(e,o,{})),and=(...e)=>new u(e),chain=(...e)=>new l(e),race=(...e)=>new s(e),or=(...e)=>new R(e),not=(e,t)=>typeof t=="string"?new n(e,new Error(t)):new n(e,t),allow=new i,deny=new x;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateMiddlewareFromRuleTree = generateMiddlewareFromRuleTree;
7
+ function generateMiddlewareFromRuleTree(r, o) {
8
+ return async ({
9
+ next: a,
10
+ ctx: d,
11
+ type: t,
12
+ path: c,
13
+ input: f,
14
+ rawInput: g
15
+ }) => {
16
+ const s = c.split("."),
17
+ i = s[s.length - 1],
18
+ l = Object.keys(r);
19
+ let n;
20
+ if (l.includes("query") || l.includes("mutation")) n = r?.[t]?.[i];else {
21
+ const e = s[0],
22
+ u = r[e];
23
+ u?.[t]?.[i] && (n = u?.[t]?.[i]);
24
+ }
25
+ return n = n ?? o.fallbackRule, n ? n?.resolve(d, t, c, f, g, o).then(async e => {
26
+ if (e instanceof Error) throw e;
27
+ if (!e) throw o.fallbackError;
28
+ return a();
29
+ }) : a();
30
+ };
31
+ }
@@ -0,0 +1,14 @@
1
+ import type { IOptions, IRules } from "./types";
2
+ /**
3
+ * Generates middleware from given rules.
4
+ */
5
+ export declare function generateMiddlewareFromRuleTree<TContext extends Record<string, unknown>>(ruleTree: IRules<TContext>, options: IOptions<TContext>): ({ next, ctx, type, path, input, rawInput }: {
6
+ next: () => Promise<any>;
7
+ ctx: TContext;
8
+ type: string;
9
+ path: string;
10
+ input: {
11
+ [name: string]: any;
12
+ };
13
+ rawInput: unknown;
14
+ }) => Promise<any>;
@@ -0,0 +1 @@
1
+ export function generateMiddlewareFromRuleTree(r,o){return async({next:a,ctx:d,type:t,path:c,input:f,rawInput:g})=>{const s=c.split("."),i=s[s.length-1],l=Object.keys(r);let n;if(l.includes("query")||l.includes("mutation"))n=r?.[t]?.[i];else{const e=s[0],u=r[e];u?.[t]?.[i]&&(n=u?.[t]?.[i])}return n=n??o.fallbackRule,n?n?.resolve(d,t,c,f,g,o).then(async e=>{if(e instanceof Error)throw e;if(!e)throw o.fallbackError;return a()}):a()}}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "allow", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _constructors.allow;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "and", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _constructors.and;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "chain", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _constructors.chain;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "deny", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _constructors.deny;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "not", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _constructors.not;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "or", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _constructors.or;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "race", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _constructors.race;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "rule", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _constructors.rule;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "shield", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _shield.shield;
58
+ }
59
+ });
60
+ var _constructors = require("./constructors.cjs");
61
+ var _shield = require("./shield.cjs");
@@ -0,0 +1,3 @@
1
+ export { allow, and, chain, deny, not, or, race, rule } from "./constructors";
2
+ export { shield } from "./shield";
3
+ export type { IRule, IRules } from "./types";
@@ -0,0 +1 @@
1
+ export{allow,and,chain,deny,not,or,race,rule}from"./constructors";export{shield}from"./shield";
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RuleTrue = exports.RuleRace = exports.RuleOr = exports.RuleNot = exports.RuleFalse = exports.RuleChain = exports.RuleAnd = exports.Rule = exports.LogicRule = void 0;
7
+ class Rule {
8
+ name;
9
+ func;
10
+ constructor(e, n) {
11
+ this.name = e, this.func = n;
12
+ }
13
+ async resolve(e, n, s, o, u, r) {
14
+ try {
15
+ const t = await this.executeRule(e, n, s, o, u, r);
16
+ return t instanceof Error ? t : typeof t == "string" ? new Error(t) : t === !0;
17
+ } catch (t) {
18
+ if (r.debug) throw t;
19
+ return !1;
20
+ }
21
+ }
22
+ equals(e) {
23
+ return this.func === e.func;
24
+ }
25
+ executeRule(e, n, s, o, u, r) {
26
+ return this.func(e, n, s, o, u, r);
27
+ }
28
+ }
29
+ exports.Rule = Rule;
30
+ class LogicRule extends Rule {
31
+ rules;
32
+ constructor(e) {
33
+ super("LogicRule"), this.rules = e;
34
+ }
35
+ async resolve(e, n, s, o, u, r) {
36
+ return !1;
37
+ }
38
+ async evaluate(e, n, s, o, u, r) {
39
+ const i = this.getRules().map(async l => l.resolve(e, n, s, o, u, r));
40
+ return Promise.all(i);
41
+ }
42
+ getRules() {
43
+ return this.rules;
44
+ }
45
+ }
46
+ exports.LogicRule = LogicRule;
47
+ class RuleOr extends LogicRule {
48
+ constructor(e) {
49
+ super(e);
50
+ }
51
+ async resolve(e, n, s, o, u, r) {
52
+ const t = await this.evaluate(e, n, s, o, u, r);
53
+ return t.every(i => i !== !0) ? t.find(l => l instanceof Error) ?? !1 : !0;
54
+ }
55
+ }
56
+ exports.RuleOr = RuleOr;
57
+ class RuleAnd extends LogicRule {
58
+ constructor(e) {
59
+ super(e);
60
+ }
61
+ async resolve(e, n, s, o, u, r) {
62
+ const t = await this.evaluate(e, n, s, o, u, r);
63
+ return t.some(i => i !== !0) ? t.find(l => l instanceof Error) ?? !1 : !0;
64
+ }
65
+ }
66
+ exports.RuleAnd = RuleAnd;
67
+ class RuleChain extends LogicRule {
68
+ constructor(e) {
69
+ super(e);
70
+ }
71
+ async resolve(e, n, s, o, u, r) {
72
+ const t = await this.evaluate(e, n, s, o, u, r);
73
+ return t.some(i => i !== !0) ? t.find(l => l instanceof Error) ?? !1 : !0;
74
+ }
75
+ async evaluate(e, n, s, o, u, r) {
76
+ const t = this.getRules();
77
+ return i(t);
78
+ async function i([l, ...x]) {
79
+ return l === void 0 ? [] : l.resolve(e, n, s, o, u, r).then(async c => c !== !0 ? [c] : i(x).then(R => R.concat(c)));
80
+ }
81
+ }
82
+ }
83
+ exports.RuleChain = RuleChain;
84
+ class RuleRace extends LogicRule {
85
+ constructor(e) {
86
+ super(e);
87
+ }
88
+ async resolve(e, n, s, o, u, r) {
89
+ const t = await this.evaluate(e, n, s, o, u, r);
90
+ return t.includes(!0) ? !0 : t.find(l => l instanceof Error) ?? !1;
91
+ }
92
+ async evaluate(e, n, s, o, u, r) {
93
+ const t = this.getRules();
94
+ return i(t);
95
+ async function i([l, ...x]) {
96
+ return l === void 0 ? [] : l.resolve(e, n, s, o, u, r).then(async c => c === !0 ? [c] : i(x).then(R => R.concat(c)));
97
+ }
98
+ }
99
+ }
100
+ exports.RuleRace = RuleRace;
101
+ class RuleNot extends LogicRule {
102
+ error;
103
+ name = "RuleNot";
104
+ equals;
105
+ constructor(e, n) {
106
+ super([e]), this.error = n;
107
+ }
108
+ async resolve(e, n, s, o, u, r) {
109
+ const [t] = await this.evaluate(e, n, s, o, u, r);
110
+ return t instanceof Error || t !== !0 ? !0 : this.error ? this.error : !1;
111
+ }
112
+ }
113
+ exports.RuleNot = RuleNot;
114
+ class RuleTrue extends LogicRule {
115
+ name = "RuleTrue";
116
+ equals;
117
+ constructor() {
118
+ super([]);
119
+ }
120
+ async resolve() {
121
+ return !0;
122
+ }
123
+ }
124
+ exports.RuleTrue = RuleTrue;
125
+ class RuleFalse extends LogicRule {
126
+ name = "RuleTrue";
127
+ equals;
128
+ constructor() {
129
+ super([]);
130
+ }
131
+ async resolve() {
132
+ return !1;
133
+ }
134
+ }
135
+ exports.RuleFalse = RuleFalse;
@@ -0,0 +1,121 @@
1
+ import type { ILogicRule, IOptions, IRule, IRuleFunction, IRuleResult, ShieldRule } from "./types";
2
+ export declare class Rule<TContext extends Record<string, any>> implements IRule<TContext> {
3
+ readonly name: string;
4
+ func?: IRuleFunction<TContext>;
5
+ constructor(name: string, func?: IRuleFunction<TContext>);
6
+ resolve(ctx: TContext, type: string, path: string, input: {
7
+ [name: string]: any;
8
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
9
+ /**
10
+ *
11
+ * Compares a given rule with the current one
12
+ * and checks whether their functions are equal.
13
+ *
14
+ */
15
+ equals(rule: Rule<TContext>): boolean;
16
+ executeRule<TContext extends Record<string, any>>(ctx: TContext, type: string, path: string, input: {
17
+ [name: string]: any;
18
+ }, rawInput: unknown, options: IOptions<TContext>): string | boolean | Error | Promise<IRuleResult>;
19
+ }
20
+ export declare class LogicRule<TContext extends Record<string, any>> extends Rule<TContext> implements ILogicRule<TContext> {
21
+ private rules;
22
+ constructor(rules: ShieldRule<TContext>[]);
23
+ /**
24
+ * By default logic rule resolves to false.
25
+ */
26
+ resolve(_ctx: TContext, _type: string, _path: string, _input: {
27
+ [name: string]: any;
28
+ }, _rawInput: unknown, _options: IOptions<TContext>): Promise<IRuleResult>;
29
+ /**
30
+ * Evaluates all the rules.
31
+ */
32
+ evaluate(ctx: TContext, type: string, path: string, input: {
33
+ [name: string]: any;
34
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult[]>;
35
+ /**
36
+ * Returns rules in a logic rule.
37
+ */
38
+ getRules(): ShieldRule<TContext>[];
39
+ }
40
+ export declare class RuleOr<TContext extends Record<string, any>> extends LogicRule<TContext> {
41
+ constructor(rules: ShieldRule<TContext>[]);
42
+ /**
43
+ * Makes sure that at least one of them has evaluated to true.
44
+ */
45
+ resolve(ctx: TContext, type: string, path: string, input: {
46
+ [name: string]: any;
47
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
48
+ }
49
+ export declare class RuleAnd<TContext extends Record<string, any>> extends LogicRule<TContext> {
50
+ constructor(rules: ShieldRule<TContext>[]);
51
+ /**
52
+ * Makes sure that all of them have resolved to true.
53
+ */
54
+ resolve(ctx: TContext, type: string, path: string, input: {
55
+ [name: string]: any;
56
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
57
+ }
58
+ export declare class RuleChain<TContext extends Record<string, any>> extends LogicRule<TContext> {
59
+ constructor(rules: ShieldRule<TContext>[]);
60
+ /**
61
+ * Makes sure that all of them have resolved to true.
62
+ */
63
+ resolve(ctx: TContext, type: string, path: string, input: {
64
+ [name: string]: any;
65
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
66
+ /**
67
+ * Evaluates all the rules.
68
+ */
69
+ evaluate(ctx: TContext, type: string, path: string, input: {
70
+ [name: string]: any;
71
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult[]>;
72
+ }
73
+ export declare class RuleRace<TContext extends Record<string, any>> extends LogicRule<TContext> {
74
+ constructor(rules: ShieldRule<TContext>[]);
75
+ /**
76
+ * Makes sure that at least one of them resolved to true.
77
+ */
78
+ resolve(ctx: TContext, type: string, path: string, input: {
79
+ [name: string]: any;
80
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
81
+ /**
82
+ * Evaluates all the rules.
83
+ */
84
+ evaluate(ctx: TContext, type: string, path: string, input: {
85
+ [name: string]: any;
86
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult[]>;
87
+ }
88
+ export declare class RuleNot<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
89
+ error?: Error;
90
+ name: string;
91
+ equals: (rule: IRule<TContext>) => boolean;
92
+ constructor(rule: ShieldRule<TContext>, error?: Error);
93
+ /**
94
+ * Negates the result.
95
+ */
96
+ resolve(ctx: TContext, type: string, path: string, input: {
97
+ [name: string]: any;
98
+ }, rawInput: unknown, options: IOptions<TContext>): Promise<IRuleResult>;
99
+ }
100
+ export declare class RuleTrue<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
101
+ name: string;
102
+ equals: (rule: IRule<TContext>) => boolean;
103
+ constructor();
104
+ /**
105
+ *
106
+ * Always true.
107
+ *
108
+ */
109
+ resolve(): Promise<IRuleResult>;
110
+ }
111
+ export declare class RuleFalse<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
112
+ name: string;
113
+ equals: (rule: IRule<TContext>) => boolean;
114
+ constructor();
115
+ /**
116
+ *
117
+ * Always false.
118
+ *
119
+ */
120
+ resolve(): Promise<IRuleResult>;
121
+ }
@@ -0,0 +1 @@
1
+ export class Rule{name;func;constructor(e,n){this.name=e,this.func=n}async resolve(e,n,s,o,u,r){try{const t=await this.executeRule(e,n,s,o,u,r);return t instanceof Error?t:typeof t=="string"?new Error(t):t===!0}catch(t){if(r.debug)throw t;return!1}}equals(e){return this.func===e.func}executeRule(e,n,s,o,u,r){return this.func(e,n,s,o,u,r)}}export class LogicRule extends Rule{rules;constructor(e){super("LogicRule"),this.rules=e}async resolve(e,n,s,o,u,r){return!1}async evaluate(e,n,s,o,u,r){const i=this.getRules().map(async l=>l.resolve(e,n,s,o,u,r));return Promise.all(i)}getRules(){return this.rules}}export class RuleOr extends LogicRule{constructor(e){super(e)}async resolve(e,n,s,o,u,r){const t=await this.evaluate(e,n,s,o,u,r);return t.every(i=>i!==!0)?t.find(l=>l instanceof Error)??!1:!0}}export class RuleAnd extends LogicRule{constructor(e){super(e)}async resolve(e,n,s,o,u,r){const t=await this.evaluate(e,n,s,o,u,r);return t.some(i=>i!==!0)?t.find(l=>l instanceof Error)??!1:!0}}export class RuleChain extends LogicRule{constructor(e){super(e)}async resolve(e,n,s,o,u,r){const t=await this.evaluate(e,n,s,o,u,r);return t.some(i=>i!==!0)?t.find(l=>l instanceof Error)??!1:!0}async evaluate(e,n,s,o,u,r){const t=this.getRules();return i(t);async function i([l,...x]){return l===void 0?[]:l.resolve(e,n,s,o,u,r).then(async c=>c!==!0?[c]:i(x).then(R=>R.concat(c)))}}}export class RuleRace extends LogicRule{constructor(e){super(e)}async resolve(e,n,s,o,u,r){const t=await this.evaluate(e,n,s,o,u,r);return t.includes(!0)?!0:t.find(l=>l instanceof Error)??!1}async evaluate(e,n,s,o,u,r){const t=this.getRules();return i(t);async function i([l,...x]){return l===void 0?[]:l.resolve(e,n,s,o,u,r).then(async c=>c===!0?[c]:i(x).then(R=>R.concat(c)))}}}export class RuleNot extends LogicRule{error;name="RuleNot";equals;constructor(e,n){super([e]),this.error=n}async resolve(e,n,s,o,u,r){const[t]=await this.evaluate(e,n,s,o,u,r);return t instanceof Error||t!==!0?!0:this.error?this.error:!1}}export class RuleTrue extends LogicRule{name="RuleTrue";equals;constructor(){super([])}async resolve(){return!0}}export class RuleFalse extends LogicRule{name="RuleTrue";equals;constructor(){super([])}async resolve(){return!1}}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shield = shield;
7
+ var _constructors = require("./constructors.cjs");
8
+ var _generator = require("./generator.cjs");
9
+ var _utils = require("./utils.cjs");
10
+ var _validation = require("./validation.cjs");
11
+ function u(e) {
12
+ return typeof e.fallbackError == "string" && (e.fallbackError = new Error(e.fallbackError)), {
13
+ debug: e.debug ?? !1,
14
+ allowExternalErrors: (0, _utils.withDefault)(!1)(e.allowExternalErrors),
15
+ fallbackRule: (0, _utils.withDefault)(_constructors.allow)(e.fallbackRule),
16
+ fallbackError: (0, _utils.withDefault)(new Error("Not Authorised!"))(e.fallbackError)
17
+ };
18
+ }
19
+ function shield(e, o = {}) {
20
+ const n = u(o),
21
+ r = (0, _validation.validateRuleTree)(e);
22
+ if (r.status === "ok") return (0, _generator.generateMiddlewareFromRuleTree)(e, n);
23
+ throw new _validation.ValidationError(r.message);
24
+ }
@@ -0,0 +1,6 @@
1
+ import type { MiddlewareFunction } from "@trpc/server/unstable-core-do-not-import";
2
+ import type { IOptionsConstructor, IRules } from "./types";
3
+ /**
4
+ * Validates rules and generates middleware from defined rule tree.
5
+ */
6
+ export declare function shield<TContext extends Record<string, any>, TMeta extends object = object, TContextOverridesIn = TContext, $ContextOverridesOut = TContext, TInputOut = unknown>(ruleTree: IRules<TContext>, options?: IOptionsConstructor<TContext>): MiddlewareFunction<TContext, TMeta, TContextOverridesIn, $ContextOverridesOut, TInputOut>;
@@ -0,0 +1 @@
1
+ import{allow as l}from"./constructors";import{generateMiddlewareFromRuleTree as a}from"./generator";import{withDefault as t}from"./utils";import{ValidationError as i,validateRuleTree as s}from"./validation";function u(e){return typeof e.fallbackError=="string"&&(e.fallbackError=new Error(e.fallbackError)),{debug:e.debug??!1,allowExternalErrors:t(!1)(e.allowExternalErrors),fallbackRule:t(l)(e.fallbackRule),fallbackError:t(new Error("Not Authorised!"))(e.fallbackError)}}export function shield(e,o={}){const n=u(o),r=s(e);if(r.status==="ok")return a(e,n);throw new i(r.message)}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,52 @@
1
+ export type ShieldRule<TContext extends Record<string, any> = Record<string, any>> = IRule<TContext> | ILogicRule<TContext>;
2
+ export interface IRule<TContext extends Record<string, any> = Record<string, any>> {
3
+ name: string;
4
+ equals: (rule: IRule<TContext>) => boolean;
5
+ resolve: (ctx: TContext, type: string, path: string, input: {
6
+ [name: string]: any;
7
+ }, rawInput: unknown, options: IOptions<TContext>) => Promise<IRuleResult>;
8
+ executeRule: <TContext extends Record<string, any>>(ctx: TContext, type: string, path: string, input: {
9
+ [name: string]: any;
10
+ }, rawInput: unknown, options: IOptions<TContext>) => string | boolean | Error | Promise<IRuleResult>;
11
+ }
12
+ export interface IRuleOptions {
13
+ }
14
+ export interface ILogicRule<TContext extends Record<string, any> = Record<string, any>> extends IRule<TContext> {
15
+ getRules: () => ShieldRule<TContext>[];
16
+ evaluate: (ctx: TContext, type: string, path: string, input: {
17
+ [name: string]: any;
18
+ }, rawInput: unknown, options: IOptions<TContext>) => Promise<IRuleResult[]>;
19
+ resolve: (ctx: TContext, type: string, path: string, input: {
20
+ [name: string]: any;
21
+ }, rawInput: unknown, options: IOptions<TContext>) => Promise<IRuleResult>;
22
+ }
23
+ export type IRuleResult = boolean | string | Error;
24
+ export type IRuleFunction<TContext extends Record<string, any> = Record<string, any>> = (ctx: TContext, type: string, path: string, input: {
25
+ [name: string]: any;
26
+ }, rawInput: unknown, options: IOptions<TContext>) => IRuleResult | Promise<IRuleResult>;
27
+ export interface IRuleConstructorOptions {
28
+ }
29
+ export interface IRuleTypeMap<TContext extends Record<string, any> = Record<string, any>> {
30
+ [key: string]: ShieldRule<TContext> | IRuleFieldMap<TContext> | IRuleTypeMap<TContext>;
31
+ }
32
+ export interface IRuleFieldMap<TContext extends Record<string, any> = Record<string, any>> {
33
+ [key: string]: ShieldRule<TContext>;
34
+ }
35
+ export type IRules<TContext extends Record<string, any> = Record<string, any>> = ShieldRule<TContext> | IRuleTypeMap<TContext>;
36
+ export type IFallbackErrorMapperType<TContext extends Record<string, any> = Record<string, any>> = (err: unknown, ctx: TContext, type: string, path: string, input: {
37
+ [name: string]: any;
38
+ }, rawInput: unknown) => Promise<Error> | Error;
39
+ export type IFallbackErrorType<TContext extends Record<string, any> = Record<string, any>> = Error | IFallbackErrorMapperType<TContext>;
40
+ export interface IOptions<TContext extends Record<string, any> = Record<string, any>> {
41
+ debug: boolean;
42
+ allowExternalErrors: boolean;
43
+ fallbackRule: ShieldRule<TContext>;
44
+ fallbackError?: IFallbackErrorType<TContext>;
45
+ }
46
+ export interface IOptionsConstructor<TContext extends Record<string, any> = Record<string, any>> {
47
+ debug?: boolean;
48
+ allowExternalErrors?: boolean;
49
+ fallbackRule?: ShieldRule<TContext>;
50
+ fallbackError?: string | IFallbackErrorType<TContext>;
51
+ }
52
+ export declare function shield<TContext extends Record<string, any> = Record<string, any>>(ruleTree: IRules<TContext>, options: IOptions<TContext>): any;
File without changes
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.flattenObjectOf = flattenObjectOf;
7
+ exports.isLogicRule = isLogicRule;
8
+ exports.isRule = isRule;
9
+ exports.isRuleFieldMap = isRuleFieldMap;
10
+ exports.isRuleFunction = isRuleFunction;
11
+ exports.withDefault = withDefault;
12
+ var _rules = require("./rules.cjs");
13
+ function isRule(e) {
14
+ return e instanceof _rules.Rule || e && e.constructor && e.constructor.name === "Rule";
15
+ }
16
+ function isLogicRule(e) {
17
+ return e instanceof _rules.LogicRule || e && e.constructor && (e.constructor.name === "RuleOr" || e.constructor.name === "RuleAnd" || e.constructor.name === "RuleChain" || e.constructor.name === "RuleRace" || e.constructor.name === "RuleNot" || e.constructor.name === "RuleTrue" || e.constructor.name === "RuleFalse");
18
+ }
19
+ function isRuleFunction(e) {
20
+ return isRule(e) || isLogicRule(e);
21
+ }
22
+ function isRuleFieldMap(e) {
23
+ return typeof e == "object" && Object.values(e).every(t => isRuleFunction(t));
24
+ }
25
+ function flattenObjectOf(e, t) {
26
+ return Object.keys(e).reduce((r, o) => {
27
+ const n = e[o];
28
+ return t(n) ? [...r, n] : typeof n == "object" && !t(n) ? [...r, ...flattenObjectOf(n, t)] : r;
29
+ }, []);
30
+ }
31
+ function withDefault(e) {
32
+ return t => t === void 0 ? e : t;
33
+ }
@@ -0,0 +1,28 @@
1
+ import type { ILogicRule, IRule, IRuleFieldMap, ShieldRule } from "./types";
2
+ /**
3
+ * Makes sure that a certain field is a rule.
4
+ */
5
+ export declare function isRule<TContext extends Record<string, any>>(x: any): x is IRule<TContext>;
6
+ /**
7
+ * Makes sure that a certain field is a logic rule.
8
+ */
9
+ export declare function isLogicRule<TContext extends Record<string, any>>(x: any): x is ILogicRule<TContext>;
10
+ /**
11
+ * Makes sure that a certain field is a rule or a logic rule.
12
+ */
13
+ export declare function isRuleFunction<TContext extends Record<string, any>>(x: any): x is ShieldRule<TContext>;
14
+ /**
15
+ * Determines whether a certain field is rule field map or not.
16
+ */
17
+ export declare function isRuleFieldMap<TContext extends Record<string, any>>(x: any): x is IRuleFieldMap<TContext>;
18
+ /**
19
+ * Flattens object of particular type by checking if the leaf
20
+ * evaluates to true from particular function.
21
+ */
22
+ export declare function flattenObjectOf<T>(obj: {
23
+ [key: string]: any;
24
+ }, f: (x: any) => boolean): T[];
25
+ /**
26
+ * Returns fallback is provided value is undefined
27
+ */
28
+ export declare function withDefault<T>(fallback: T): (value: T | undefined) => T;
@@ -0,0 +1 @@
1
+ import{LogicRule as u,Rule as c}from"./rules";export function isRule(e){return e instanceof c||e&&e.constructor&&e.constructor.name==="Rule"}export function isLogicRule(e){return e instanceof u||e&&e.constructor&&(e.constructor.name==="RuleOr"||e.constructor.name==="RuleAnd"||e.constructor.name==="RuleChain"||e.constructor.name==="RuleRace"||e.constructor.name==="RuleNot"||e.constructor.name==="RuleTrue"||e.constructor.name==="RuleFalse")}export function isRuleFunction(e){return isRule(e)||isLogicRule(e)}export function isRuleFieldMap(e){return typeof e=="object"&&Object.values(e).every(t=>isRuleFunction(t))}export function flattenObjectOf(e,t){return Object.keys(e).reduce((r,o)=>{const n=e[o];return t(n)?[...r,n]:typeof n=="object"&&!t(n)?[...r,...flattenObjectOf(n,t)]:r},[])}export function withDefault(e){return t=>t===void 0?e:t}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ValidationError = void 0;
7
+ exports.validateRuleTree = validateRuleTree;
8
+ var _utils = require("./utils.cjs");
9
+ function validateRuleTree(r) {
10
+ const u = c(r).reduce(({
11
+ map: t,
12
+ duplicates: n
13
+ }, e) => t.has(e.name) ? !t.get(e.name).equals(e) && !n.includes(e.name) ? {
14
+ map: t.set(e.name, e),
15
+ duplicates: [...n, e.name]
16
+ } : {
17
+ map: t,
18
+ duplicates: n
19
+ } : {
20
+ map: t.set(e.name, e),
21
+ duplicates: n
22
+ }, {
23
+ map: new Map(),
24
+ duplicates: []
25
+ });
26
+ if (u.duplicates.length === 0) return {
27
+ status: "ok"
28
+ };
29
+ return {
30
+ status: "err",
31
+ message: `There seem to be multiple definitions of these rules: ${u.duplicates.join(", ")}`
32
+ };
33
+ function c(t) {
34
+ return (0, _utils.flattenObjectOf)(t, _utils.isRuleFunction).reduce((l, s) => (0, _utils.isLogicRule)(s) ? [...l, ...i(s)] : [...l, s], []);
35
+ }
36
+ function i(t) {
37
+ return t.getRules().reduce((n, e) => (0, _utils.isLogicRule)(e) ? [...n, ...i(e)] : [...n, e], []);
38
+ }
39
+ }
40
+ class ValidationError extends Error {
41
+ constructor(o) {
42
+ super(o);
43
+ }
44
+ }
45
+ exports.ValidationError = ValidationError;
@@ -0,0 +1,15 @@
1
+ import type { IRules } from "./types";
2
+ /**
3
+ * Validates the rule tree declaration by checking references of rule
4
+ * functions. We deem rule tree valid if no two rules with the same name point
5
+ * to different rules.
6
+ */
7
+ export declare function validateRuleTree<TContext extends Record<string, any>>(ruleTree: IRules<TContext>): {
8
+ status: "ok";
9
+ } | {
10
+ status: "err";
11
+ message: string;
12
+ };
13
+ export declare class ValidationError extends Error {
14
+ constructor(message: string);
15
+ }
@@ -0,0 +1 @@
1
+ import{flattenObjectOf as x,isLogicRule as a,isRuleFunction as R}from"./utils";export function validateRuleTree(r){const u=c(r).reduce(({map:t,duplicates:n},e)=>t.has(e.name)?!t.get(e.name).equals(e)&&!n.includes(e.name)?{map:t.set(e.name,e),duplicates:[...n,e.name]}:{map:t,duplicates:n}:{map:t.set(e.name,e),duplicates:n},{map:new Map,duplicates:[]});if(u.duplicates.length===0)return{status:"ok"};return{status:"err",message:`There seem to be multiple definitions of these rules: ${u.duplicates.join(", ")}`};function c(t){return x(t,R).reduce((l,s)=>a(s)?[...l,...i(s)]:[...l,s],[])}function i(t){return t.getRules().reduce((n,e)=>a(e)?[...n,...i(e)]:[...n,e],[])}}export class ValidationError extends Error{constructor(o){super(o)}}
@@ -7,26 +7,24 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.createTRPCTanstackQueryClient = createTRPCTanstackQueryClient;
8
8
  var _environmentChecks = require("@stryke/env/environment-checks");
9
9
  var _reactQuery = require("@tanstack/react-query");
10
- var _reactQueryDevtools = require("@tanstack/react-query-devtools");
11
10
  var _client = require("@trpc/client");
12
11
  var _tanstackReactQuery = require("@trpc/tanstack-react-query");
13
12
  var _react = require("react");
14
13
  var _shared = require("../shared.cjs");
15
- function createTRPCTanstackQueryClient(t, o) {
14
+ function createTRPCTanstackQueryClient(t, r) {
16
15
  const {
17
- TRPCProvider: n,
18
- useTRPC: i
19
- } = (0, _tanstackReactQuery.createTRPCContext)(),
20
- e = (0, _shared.createQueryClient)(o);
16
+ TRPCProvider: o,
17
+ useTRPC: n
18
+ } = (0, _tanstackReactQuery.createTRPCContext)();
21
19
  return {
22
- useTRPCTanstackQuery: i,
23
- TRPCTanstackQueryProvider: c => {
20
+ useTRPCTanstackQuery: n,
21
+ TRPCTanstackQueryProvider: i => {
24
22
  const {
25
- children: u
26
- } = c,
27
- [a] = (0, _react.useState)(() => (0, _client.createTRPCClient)({
23
+ children: c
24
+ } = i,
25
+ [u] = (0, _react.useState)(() => (0, _client.createTRPCClient)({
28
26
  links: [(0, _client.loggerLink)({
29
- enabled: r => _environmentChecks.isDevelopment || r.direction === "down" && r.result instanceof Error
27
+ enabled: e => _environmentChecks.isDevelopment || e.direction === "down" && e.result instanceof Error
30
28
  }), (0, _client.httpBatchStreamLink)({
31
29
  transformer: _shared.transformer,
32
30
  url: (0, _shared.getTRPCServerUrl)(t),
@@ -35,12 +33,12 @@ function createTRPCTanstackQueryClient(t, o) {
35
33
  }
36
34
  })]
37
35
  }));
38
- return React.createElement(n, {
39
- trpcClient: a,
40
- queryClient: e
36
+ return React.createElement(o, {
37
+ trpcClient: u,
38
+ queryClient: r
41
39
  }, React.createElement(_reactQuery.QueryClientProvider, {
42
- client: e
43
- }, u, React.createElement(_reactQueryDevtools.ReactQueryDevtools, null)));
40
+ client: r
41
+ }, c));
44
42
  }
45
43
  };
46
44
  }
@@ -1,12 +1,12 @@
1
1
  import type { StormURL } from "@stryke/http/types";
2
- import type { QueryClientConfig } from "@tanstack/react-query";
2
+ import type { QueryClient } from "@tanstack/react-query";
3
3
  import type { AnyTRPCRouter } from "@trpc/server";
4
4
  /**
5
5
  * Create a TRPC Tanstack Query client.
6
6
  *
7
7
  * @returns The TRPC Tanstack Query client
8
8
  */
9
- export declare function createTRPCTanstackQueryClient<TRouter extends AnyTRPCRouter>(baseUrl: string | StormURL, config?: Partial<QueryClientConfig>): {
9
+ export declare function createTRPCTanstackQueryClient<TRouter extends AnyTRPCRouter>(baseUrl: string | StormURL, queryClient: QueryClient): {
10
10
  useTRPCTanstackQuery: () => import("@trpc/tanstack-react-query").TRPCOptionsProxy<TRouter>;
11
11
  TRPCTanstackQueryProvider: (props: {
12
12
  children: React.ReactNode;
@@ -1 +1 @@
1
- "use client";import{isDevelopment as s}from"@stryke/env/environment-checks";import{QueryClientProvider as m}from"@tanstack/react-query";import{ReactQueryDevtools as C}from"@tanstack/react-query-devtools";import{createTRPCClient as l,httpBatchStreamLink as R,loggerLink as p}from"@trpc/client";import{createTRPCContext as y}from"@trpc/tanstack-react-query";import{useState as T}from"react";import{createQueryClient as f,getTRPCServerUrl as P,transformer as d}from"../shared";export function createTRPCTanstackQueryClient(t,o){const{TRPCProvider:n,useTRPC:i}=y(),e=f(o);return{useTRPCTanstackQuery:i,TRPCTanstackQueryProvider:c=>{const{children:u}=c,[a]=T(()=>l({links:[p({enabled:r=>s||r.direction==="down"&&r.result instanceof Error}),R({transformer:d,url:P(t),headers:{"x-trpc-source":"react-query"}})]}));return React.createElement(n,{trpcClient:a,queryClient:e},React.createElement(m,{client:e},u,React.createElement(C,null)))}}}
1
+ "use client";import{isDevelopment as s}from"@stryke/env/environment-checks";import{QueryClientProvider as a}from"@tanstack/react-query";import{createTRPCClient as m,httpBatchStreamLink as R,loggerLink as p}from"@trpc/client";import{createTRPCContext as C}from"@trpc/tanstack-react-query";import{useState as l}from"react";import{getTRPCServerUrl as T,transformer as y}from"../shared";export function createTRPCTanstackQueryClient(t,r){const{TRPCProvider:o,useTRPC:n}=C();return{useTRPCTanstackQuery:n,TRPCTanstackQueryProvider:i=>{const{children:c}=i,[u]=l(()=>m({links:[p({enabled:e=>s||e.direction==="down"&&e.result instanceof Error}),R({transformer:y,url:T(t),headers:{"x-trpc-source":"react-query"}})]}));return React.createElement(o,{trpcClient:u,queryClient:r},React.createElement(a,{client:r},c))}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/trpc-next",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "A package to help in using tRPC in modern NextJs applications.",
6
6
  "repository": {
@@ -22,7 +22,6 @@
22
22
  "dependencies": {
23
23
  "@js-temporal/polyfill": "^0.5.0",
24
24
  "@tanstack/react-query": "^5.70.0",
25
- "@tanstack/react-query-devtools": "^5.70.0",
26
25
  "@trpc/client": "^11.0.1",
27
26
  "@trpc/next": "^11.0.1",
28
27
  "@trpc/server": "^11.0.1",
@@ -184,6 +183,118 @@
184
183
  "default": "./dist/tanstack-query/client.mjs"
185
184
  }
186
185
  },
186
+ "./shield/validation": {
187
+ "import": {
188
+ "types": "./dist/shield/validation.d.ts",
189
+ "default": "./dist/shield/validation.mjs"
190
+ },
191
+ "require": {
192
+ "types": "./dist/shield/validation.d.ts",
193
+ "default": "./dist/shield/validation.cjs"
194
+ },
195
+ "default": {
196
+ "types": "./dist/shield/validation.d.ts",
197
+ "default": "./dist/shield/validation.mjs"
198
+ }
199
+ },
200
+ "./shield/utils": {
201
+ "import": {
202
+ "types": "./dist/shield/utils.d.ts",
203
+ "default": "./dist/shield/utils.mjs"
204
+ },
205
+ "require": {
206
+ "types": "./dist/shield/utils.d.ts",
207
+ "default": "./dist/shield/utils.cjs"
208
+ },
209
+ "default": {
210
+ "types": "./dist/shield/utils.d.ts",
211
+ "default": "./dist/shield/utils.mjs"
212
+ }
213
+ },
214
+ "./shield/types": {
215
+ "import": {
216
+ "types": "./dist/shield/types.d.ts",
217
+ "default": "./dist/shield/types.mjs"
218
+ },
219
+ "require": {
220
+ "types": "./dist/shield/types.d.ts",
221
+ "default": "./dist/shield/types.cjs"
222
+ },
223
+ "default": {
224
+ "types": "./dist/shield/types.d.ts",
225
+ "default": "./dist/shield/types.mjs"
226
+ }
227
+ },
228
+ "./shield/shield": {
229
+ "import": {
230
+ "types": "./dist/shield/shield.d.ts",
231
+ "default": "./dist/shield/shield.mjs"
232
+ },
233
+ "require": {
234
+ "types": "./dist/shield/shield.d.ts",
235
+ "default": "./dist/shield/shield.cjs"
236
+ },
237
+ "default": {
238
+ "types": "./dist/shield/shield.d.ts",
239
+ "default": "./dist/shield/shield.mjs"
240
+ }
241
+ },
242
+ "./shield/rules": {
243
+ "import": {
244
+ "types": "./dist/shield/rules.d.ts",
245
+ "default": "./dist/shield/rules.mjs"
246
+ },
247
+ "require": {
248
+ "types": "./dist/shield/rules.d.ts",
249
+ "default": "./dist/shield/rules.cjs"
250
+ },
251
+ "default": {
252
+ "types": "./dist/shield/rules.d.ts",
253
+ "default": "./dist/shield/rules.mjs"
254
+ }
255
+ },
256
+ "./shield/index": {
257
+ "import": {
258
+ "types": "./dist/shield/index.d.ts",
259
+ "default": "./dist/shield/index.mjs"
260
+ },
261
+ "require": {
262
+ "types": "./dist/shield/index.d.ts",
263
+ "default": "./dist/shield/index.cjs"
264
+ },
265
+ "default": {
266
+ "types": "./dist/shield/index.d.ts",
267
+ "default": "./dist/shield/index.mjs"
268
+ }
269
+ },
270
+ "./shield/generator": {
271
+ "import": {
272
+ "types": "./dist/shield/generator.d.ts",
273
+ "default": "./dist/shield/generator.mjs"
274
+ },
275
+ "require": {
276
+ "types": "./dist/shield/generator.d.ts",
277
+ "default": "./dist/shield/generator.cjs"
278
+ },
279
+ "default": {
280
+ "types": "./dist/shield/generator.d.ts",
281
+ "default": "./dist/shield/generator.mjs"
282
+ }
283
+ },
284
+ "./shield/constructors": {
285
+ "import": {
286
+ "types": "./dist/shield/constructors.d.ts",
287
+ "default": "./dist/shield/constructors.mjs"
288
+ },
289
+ "require": {
290
+ "types": "./dist/shield/constructors.d.ts",
291
+ "default": "./dist/shield/constructors.cjs"
292
+ },
293
+ "default": {
294
+ "types": "./dist/shield/constructors.d.ts",
295
+ "default": "./dist/shield/constructors.mjs"
296
+ }
297
+ },
187
298
  ".": {
188
299
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
189
300
  "require": {
@@ -192,6 +303,20 @@
192
303
  },
193
304
  "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
194
305
  },
306
+ "./shield": {
307
+ "import": {
308
+ "types": "./dist/shield/index.d.ts",
309
+ "default": "./dist/shield/index.mjs"
310
+ },
311
+ "require": {
312
+ "types": "./dist/shield/index.d.ts",
313
+ "default": "./dist/shield/index.cjs"
314
+ },
315
+ "default": {
316
+ "types": "./dist/shield/index.d.ts",
317
+ "default": "./dist/shield/index.mjs"
318
+ }
319
+ },
195
320
  "./package.json": "./package.json"
196
321
  },
197
322
  "main": "./dist/index.cjs",