@stryke/trpc-next 0.5.8 → 0.5.10
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/action-handler.d.ts +4 -4
- package/dist/server.d.ts +2 -1
- package/dist/server.mjs +1 -1
- package/dist/shared.cjs +3 -3
- package/dist/shared.d.ts +2 -2
- package/dist/shared.mjs +1 -1
- package/dist/shield/constructors.d.ts +2 -2
- package/dist/shield/constructors.mjs +1 -1
- package/dist/shield/generator.cjs +3 -3
- package/dist/shield/generator.d.ts +2 -2
- package/dist/shield/generator.mjs +1 -1
- package/dist/shield/index.d.ts +1 -1
- package/dist/shield/rules.cjs +9 -9
- package/dist/shield/rules.d.ts +24 -24
- package/dist/shield/rules.mjs +1 -1
- package/dist/shield/shield.cjs +10 -10
- package/dist/shield/shield.d.ts +2 -2
- package/dist/shield/shield.mjs +1 -1
- package/dist/shield/types.d.ts +20 -20
- package/dist/shield/utils.d.ts +4 -4
- package/dist/shield/validation.cjs +8 -8
- package/dist/shield/validation.mjs +1 -1
- package/dist/tanstack-query/client.cjs +4 -4
- package/dist/tanstack-query/client.d.ts +5 -3
- package/dist/tanstack-query/client.mjs +1 -1
- package/dist/tanstack-query/server.d.ts +3 -1
- package/package.json +18 -17
package/dist/action-handler.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import type { BaseContext } from "./types";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function createTRPCServerActionHandler<TInstance extends {
|
|
12
12
|
_config: RootConfig<AnyRootTypes>;
|
|
13
|
-
}, TContext extends BaseContext = BaseContext>(cookies: () => Promise<ReadonlyRequestCookies>, t: TInstance, createContext?: () => MaybePromise<TContext>): <TProc extends import("@trpc/server/unstable-core-do-not-import").AnyProcedure>(proc: TProc) => import("@trpc/next/
|
|
14
|
-
input: import("@trpc/server/unstable-core-do-not-import").inferProcedureInput<TProc>;
|
|
15
|
-
output: import("@trpc/server/unstable-core-do-not-import").inferProcedureOutput<TProc>;
|
|
16
|
-
errorShape: import("@trpc/server/unstable-core-do-not-import").inferClientTypes<TInstance>["errorShape"];
|
|
13
|
+
}, TContext extends BaseContext = BaseContext>(cookies: () => Promise<ReadonlyRequestCookies>, t: TInstance, createContext?: () => MaybePromise<TContext>): <TProc extends import("@trpc/server/dist/unstable-core-do-not-import.d-BJCeJk5P.d.cts").AnyProcedure>(proc: TProc) => import("@trpc/next/dist/server.d-DLnegS7F.d.cts").TRPCActionHandler<{
|
|
14
|
+
input: import("@trpc/server/dist/unstable-core-do-not-import.d-BJCeJk5P.d.cts").inferProcedureInput<TProc>;
|
|
15
|
+
output: import("@trpc/server/dist/unstable-core-do-not-import.d-BJCeJk5P.d.cts").inferProcedureOutput<TProc>;
|
|
16
|
+
errorShape: import("@trpc/server/dist/unstable-core-do-not-import.d-BJCeJk5P.d.cts").inferClientTypes<TInstance>["errorShape"];
|
|
17
17
|
}>;
|
package/dist/server.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { MaybePromise } from "@stryke/types";
|
|
|
2
2
|
import type { Resolver } from "@trpc/client";
|
|
3
3
|
import type { AnyTRPCRouter, inferRouterContext } from "@trpc/server";
|
|
4
4
|
import type { AnyProcedure, AnyRootTypes, inferProcedureInput, inferTransformedProcedureOutput, ProcedureType, RouterRecord } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
-
import type { ResolverDef } from "@trpc/tanstack-react-query";
|
|
5
|
+
import type { FeatureFlags, ResolverDef } from "@trpc/tanstack-react-query";
|
|
6
6
|
import type { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
|
|
7
7
|
export type DecorateProcedureServer<TType extends ProcedureType, TDef extends ResolverDef> = TType extends "query" ? {
|
|
8
8
|
query: Resolver<TDef>;
|
|
@@ -23,6 +23,7 @@ export type NextAppDirDecorateRouterRecord<TRoot extends AnyRootTypes, TRecord e
|
|
|
23
23
|
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
24
24
|
errorShape: TRoot["errorShape"];
|
|
25
25
|
transformer: TRoot["transformer"];
|
|
26
|
+
featureFlags: FeatureFlags;
|
|
26
27
|
}> : $Value extends RouterRecord ? NextAppDirDecorateRouterRecord<TRoot, $Value> : never : never;
|
|
27
28
|
};
|
|
28
29
|
/**
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loggerLink as n}from"@trpc/client";import{experimental_nextCacheLink as s}from"@trpc/next/app-dir/links/nextCache";import{experimental_createTRPCNextAppDirServer as u}from"@trpc/next/app-dir/server";import{transformer as
|
|
1
|
+
import{loggerLink as n}from"@trpc/client";import{experimental_nextCacheLink as s}from"@trpc/next/app-dir/links/nextCache";import{experimental_createTRPCNextAppDirServer as u}from"@trpc/next/app-dir/server";import{transformer as a}from"./shared";export function createTRPCServer(r,t,o=()=>({})){return u({config(){return{links:[n({enabled:e=>!0}),s({revalidate:5,router:t,transformer:a,createContext:async()=>{const e=await Promise.resolve(o());return e.headers??={},e.headers["x-trpc-source"]="rsc-invoke",e.headers.cookie=(await r()).toString(),e}})]}}})}export{experimental_notFound as notFound,experimental_redirect as redirect}from"@trpc/server/adapters/next-app-dir";
|
package/dist/shared.cjs
CHANGED
|
@@ -12,8 +12,8 @@ var _reactQuery = require("@tanstack/react-query");
|
|
|
12
12
|
var _defu = _interopRequireDefault(require("defu"));
|
|
13
13
|
var _superjson = _interopRequireDefault(require("superjson"));
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
function getTRPCServerUrl(e,
|
|
16
|
-
return (0, _joinPaths.joinPaths)(typeof e == "string" ? e : e.host || "", "api",
|
|
15
|
+
function getTRPCServerUrl(e, r = 1) {
|
|
16
|
+
return (0, _joinPaths.joinPaths)(typeof e == "string" ? e : e.host || "", "api", r ? `v${r}` : "", "trpc");
|
|
17
17
|
}
|
|
18
18
|
_superjson.default.registerCustom({
|
|
19
19
|
isApplicable: e => e instanceof _polyfill.Temporal.PlainDate,
|
|
@@ -31,7 +31,7 @@ const transformer = exports.transformer = _superjson.default,
|
|
|
31
31
|
staleTime: 1e3 * 30
|
|
32
32
|
},
|
|
33
33
|
dehydrate: {
|
|
34
|
-
shouldDehydrateQuery:
|
|
34
|
+
shouldDehydrateQuery: r => (0, _reactQuery.defaultShouldDehydrateQuery)(r) || r.state.status === "pending",
|
|
35
35
|
serializeData: transformer.serialize
|
|
36
36
|
},
|
|
37
37
|
hydrate: {
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StormURLInterface } from "@stryke/url/types";
|
|
2
2
|
import type { QueryClientConfig } from "@tanstack/react-query";
|
|
3
3
|
import { QueryClient } from "@tanstack/react-query";
|
|
4
4
|
import type { DataTransformer } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
-
export declare function getTRPCServerUrl(baseUrl: string |
|
|
5
|
+
export declare function getTRPCServerUrl(baseUrl: string | StormURLInterface, version?: number | null): any;
|
|
6
6
|
export declare const transformer: DataTransformer;
|
|
7
7
|
/**
|
|
8
8
|
* Create a TRPC Tanstack Query client.
|
package/dist/shared.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Temporal as
|
|
1
|
+
import{Temporal as t}from"@js-temporal/polyfill";import{joinPaths as i}from"@stryke/path/join-paths";import{defaultShouldDehydrateQuery as o,QueryClient as n}from"@tanstack/react-query";import s from"defu";import a from"superjson";export function getTRPCServerUrl(e,r=1){return i(typeof e=="string"?e:e.host||"","api",r?`v${r}`:"","trpc")}a.registerCustom({isApplicable:e=>e instanceof t.PlainDate,serialize:e=>e.toJSON(),deserialize:e=>t.PlainDate.from(e)},"Temporal.PlainDate"),a.registerCustom({isApplicable:e=>e instanceof t.PlainDateTime,serialize:e=>e.toJSON(),deserialize:e=>t.PlainDateTime.from(e)},"Temporal.PlainDateTime");export const transformer=a,createQueryClient=(e={})=>new n(s(e,{defaultOptions:{queries:{staleTime:1e3*30},dehydrate:{shouldDehydrateQuery:r=>o(r)||r.state.status==="pending",serializeData:transformer.serialize},hydrate:{deserializeData:transformer.deserialize}}}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Rule, RuleAnd, RuleChain, RuleFalse, RuleNot, RuleOr, RuleRace, RuleTrue } from "./rules";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RuleConstructorOptionsInterface, RuleFunctionInterface, ShieldRule } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Wraps a function into a Rule class. This way we can identify rules
|
|
5
5
|
* once we start generating middleware from our ruleTree.
|
|
@@ -23,7 +23,7 @@ import type { IRuleConstructorOptions, IRuleFunction, ShieldRule } from "./types
|
|
|
23
23
|
* })
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export declare const rule: <TContext extends Record<string, any>>(name?: string, options?:
|
|
26
|
+
export declare const rule: <TContext extends Record<string, any>>(name?: string, options?: RuleConstructorOptionsInterface) => (func: RuleFunctionInterface<TContext>) => Rule<TContext>;
|
|
27
27
|
/**
|
|
28
28
|
* Logical operator and serves as a wrapper for and operation.
|
|
29
29
|
*/
|
|
@@ -1 +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
|
|
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 c}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 c,deny=new x;
|
|
@@ -7,10 +7,10 @@ exports.generateMiddlewareFromRuleTree = generateMiddlewareFromRuleTree;
|
|
|
7
7
|
function generateMiddlewareFromRuleTree(r, o) {
|
|
8
8
|
return async ({
|
|
9
9
|
next: a,
|
|
10
|
-
ctx:
|
|
10
|
+
ctx: f,
|
|
11
11
|
type: t,
|
|
12
12
|
path: c,
|
|
13
|
-
input:
|
|
13
|
+
input: d,
|
|
14
14
|
rawInput: g
|
|
15
15
|
}) => {
|
|
16
16
|
const s = c.split("."),
|
|
@@ -22,7 +22,7 @@ function generateMiddlewareFromRuleTree(r, o) {
|
|
|
22
22
|
u = r[e];
|
|
23
23
|
u?.[t]?.[i] && (n = u?.[t]?.[i]);
|
|
24
24
|
}
|
|
25
|
-
return n = n ?? o.fallbackRule, n ? n?.resolve(
|
|
25
|
+
return n = n ?? o.fallbackRule, n ? n?.resolve(f, t, c, d, g, o).then(async e => {
|
|
26
26
|
if (e instanceof Error) throw e;
|
|
27
27
|
if (!e) throw o.fallbackError;
|
|
28
28
|
return a();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IRules, OptionsInterface } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Generates middleware from given rules.
|
|
4
4
|
*/
|
|
5
|
-
export declare function generateMiddlewareFromRuleTree<TContext extends Record<string, unknown>>(ruleTree: IRules<TContext>, options:
|
|
5
|
+
export declare function generateMiddlewareFromRuleTree<TContext extends Record<string, unknown>>(ruleTree: IRules<TContext>, options: OptionsInterface<TContext>): ({ next, ctx, type, path, input, rawInput }: {
|
|
6
6
|
next: () => Promise<any>;
|
|
7
7
|
ctx: TContext;
|
|
8
8
|
type: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function generateMiddlewareFromRuleTree(r,o){return async({next:a,ctx:
|
|
1
|
+
export function generateMiddlewareFromRuleTree(r,o){return async({next:a,ctx:f,type:t,path:c,input:d,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(f,t,c,d,g,o).then(async e=>{if(e instanceof Error)throw e;if(!e)throw o.fallbackError;return a()}):a()}}
|
package/dist/shield/index.d.ts
CHANGED
package/dist/shield/rules.cjs
CHANGED
|
@@ -36,7 +36,7 @@ class LogicRule extends Rule {
|
|
|
36
36
|
return !1;
|
|
37
37
|
}
|
|
38
38
|
async evaluate(e, n, s, o, u, r) {
|
|
39
|
-
const i = this.getRules().map(async
|
|
39
|
+
const i = this.getRules().map(async a => a.resolve(e, n, s, o, u, r));
|
|
40
40
|
return Promise.all(i);
|
|
41
41
|
}
|
|
42
42
|
getRules() {
|
|
@@ -50,7 +50,7 @@ class RuleOr extends LogicRule {
|
|
|
50
50
|
}
|
|
51
51
|
async resolve(e, n, s, o, u, r) {
|
|
52
52
|
const t = await this.evaluate(e, n, s, o, u, r);
|
|
53
|
-
return t.every(i => i !== !0) ? t.find(
|
|
53
|
+
return t.every(i => i !== !0) ? t.find(a => a instanceof Error) ?? !1 : !0;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
exports.RuleOr = RuleOr;
|
|
@@ -60,7 +60,7 @@ class RuleAnd extends LogicRule {
|
|
|
60
60
|
}
|
|
61
61
|
async resolve(e, n, s, o, u, r) {
|
|
62
62
|
const t = await this.evaluate(e, n, s, o, u, r);
|
|
63
|
-
return t.some(i => i !== !0) ? t.find(
|
|
63
|
+
return t.some(i => i !== !0) ? t.find(a => a instanceof Error) ?? !1 : !0;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
exports.RuleAnd = RuleAnd;
|
|
@@ -70,13 +70,13 @@ class RuleChain extends LogicRule {
|
|
|
70
70
|
}
|
|
71
71
|
async resolve(e, n, s, o, u, r) {
|
|
72
72
|
const t = await this.evaluate(e, n, s, o, u, r);
|
|
73
|
-
return t.some(i => i !== !0) ? t.find(
|
|
73
|
+
return t.some(i => i !== !0) ? t.find(a => a instanceof Error) ?? !1 : !0;
|
|
74
74
|
}
|
|
75
75
|
async evaluate(e, n, s, o, u, r) {
|
|
76
76
|
const t = this.getRules();
|
|
77
77
|
return i(t);
|
|
78
|
-
async function i([
|
|
79
|
-
return
|
|
78
|
+
async function i([a, ...x]) {
|
|
79
|
+
return a === void 0 ? [] : a.resolve(e, n, s, o, u, r).then(async c => c !== !0 ? [c] : i(x).then(f => f.concat(c)));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -87,13 +87,13 @@ class RuleRace extends LogicRule {
|
|
|
87
87
|
}
|
|
88
88
|
async resolve(e, n, s, o, u, r) {
|
|
89
89
|
const t = await this.evaluate(e, n, s, o, u, r);
|
|
90
|
-
return t.includes(!0) ? !0 : t.find(
|
|
90
|
+
return t.includes(!0) ? !0 : t.find(a => a instanceof Error) ?? !1;
|
|
91
91
|
}
|
|
92
92
|
async evaluate(e, n, s, o, u, r) {
|
|
93
93
|
const t = this.getRules();
|
|
94
94
|
return i(t);
|
|
95
|
-
async function i([
|
|
96
|
-
return
|
|
95
|
+
async function i([a, ...x]) {
|
|
96
|
+
return a === void 0 ? [] : a.resolve(e, n, s, o, u, r).then(async c => c === !0 ? [c] : i(x).then(f => f.concat(c)));
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
package/dist/shield/rules.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare class Rule<TContext extends Record<string, any>> implements
|
|
1
|
+
import type { LogicRuleInterface, OptionsInterface, RuleFunctionInterface, RuleInterface, RuleResultInterface, ShieldRule } from "./types";
|
|
2
|
+
export declare class Rule<TContext extends Record<string, any>> implements RuleInterface<TContext> {
|
|
3
3
|
readonly name: string;
|
|
4
|
-
func?:
|
|
5
|
-
constructor(name: string, func?:
|
|
4
|
+
func?: RuleFunctionInterface<TContext>;
|
|
5
|
+
constructor(name: string, func?: RuleFunctionInterface<TContext>);
|
|
6
6
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
7
7
|
[name: string]: any;
|
|
8
|
-
}, rawInput: unknown, options:
|
|
8
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* Compares a given rule with the current one
|
|
@@ -15,9 +15,9 @@ export declare class Rule<TContext extends Record<string, any>> implements IRule
|
|
|
15
15
|
equals(rule: Rule<TContext>): boolean;
|
|
16
16
|
executeRule<TContext extends Record<string, any>>(ctx: TContext, type: string, path: string, input: {
|
|
17
17
|
[name: string]: any;
|
|
18
|
-
}, rawInput: unknown, options:
|
|
18
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): string | boolean | Error | Promise<RuleResultInterface>;
|
|
19
19
|
}
|
|
20
|
-
export declare class LogicRule<TContext extends Record<string, any>> extends Rule<TContext> implements
|
|
20
|
+
export declare class LogicRule<TContext extends Record<string, any>> extends Rule<TContext> implements LogicRuleInterface<TContext> {
|
|
21
21
|
private rules;
|
|
22
22
|
constructor(rules: ShieldRule<TContext>[]);
|
|
23
23
|
/**
|
|
@@ -25,13 +25,13 @@ export declare class LogicRule<TContext extends Record<string, any>> extends Rul
|
|
|
25
25
|
*/
|
|
26
26
|
resolve(_ctx: TContext, _type: string, _path: string, _input: {
|
|
27
27
|
[name: string]: any;
|
|
28
|
-
}, _rawInput: unknown, _options:
|
|
28
|
+
}, _rawInput: unknown, _options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
29
29
|
/**
|
|
30
30
|
* Evaluates all the rules.
|
|
31
31
|
*/
|
|
32
32
|
evaluate(ctx: TContext, type: string, path: string, input: {
|
|
33
33
|
[name: string]: any;
|
|
34
|
-
}, rawInput: unknown, options:
|
|
34
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface[]>;
|
|
35
35
|
/**
|
|
36
36
|
* Returns rules in a logic rule.
|
|
37
37
|
*/
|
|
@@ -44,7 +44,7 @@ export declare class RuleOr<TContext extends Record<string, any>> extends LogicR
|
|
|
44
44
|
*/
|
|
45
45
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
46
46
|
[name: string]: any;
|
|
47
|
-
}, rawInput: unknown, options:
|
|
47
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
48
48
|
}
|
|
49
49
|
export declare class RuleAnd<TContext extends Record<string, any>> extends LogicRule<TContext> {
|
|
50
50
|
constructor(rules: ShieldRule<TContext>[]);
|
|
@@ -53,7 +53,7 @@ export declare class RuleAnd<TContext extends Record<string, any>> extends Logic
|
|
|
53
53
|
*/
|
|
54
54
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
55
55
|
[name: string]: any;
|
|
56
|
-
}, rawInput: unknown, options:
|
|
56
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
57
57
|
}
|
|
58
58
|
export declare class RuleChain<TContext extends Record<string, any>> extends LogicRule<TContext> {
|
|
59
59
|
constructor(rules: ShieldRule<TContext>[]);
|
|
@@ -62,13 +62,13 @@ export declare class RuleChain<TContext extends Record<string, any>> extends Log
|
|
|
62
62
|
*/
|
|
63
63
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
64
64
|
[name: string]: any;
|
|
65
|
-
}, rawInput: unknown, options:
|
|
65
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
66
66
|
/**
|
|
67
67
|
* Evaluates all the rules.
|
|
68
68
|
*/
|
|
69
69
|
evaluate(ctx: TContext, type: string, path: string, input: {
|
|
70
70
|
[name: string]: any;
|
|
71
|
-
}, rawInput: unknown, options:
|
|
71
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface[]>;
|
|
72
72
|
}
|
|
73
73
|
export declare class RuleRace<TContext extends Record<string, any>> extends LogicRule<TContext> {
|
|
74
74
|
constructor(rules: ShieldRule<TContext>[]);
|
|
@@ -77,45 +77,45 @@ export declare class RuleRace<TContext extends Record<string, any>> extends Logi
|
|
|
77
77
|
*/
|
|
78
78
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
79
79
|
[name: string]: any;
|
|
80
|
-
}, rawInput: unknown, options:
|
|
80
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
81
81
|
/**
|
|
82
82
|
* Evaluates all the rules.
|
|
83
83
|
*/
|
|
84
84
|
evaluate(ctx: TContext, type: string, path: string, input: {
|
|
85
85
|
[name: string]: any;
|
|
86
|
-
}, rawInput: unknown, options:
|
|
86
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface[]>;
|
|
87
87
|
}
|
|
88
|
-
export declare class RuleNot<TContext extends Record<string, any>> extends LogicRule<TContext> implements
|
|
88
|
+
export declare class RuleNot<TContext extends Record<string, any>> extends LogicRule<TContext> implements LogicRuleInterface<TContext> {
|
|
89
89
|
error?: Error;
|
|
90
90
|
name: string;
|
|
91
|
-
equals: (rule:
|
|
91
|
+
equals: (rule: RuleInterface<TContext>) => boolean;
|
|
92
92
|
constructor(rule: ShieldRule<TContext>, error?: Error);
|
|
93
93
|
/**
|
|
94
94
|
* Negates the result.
|
|
95
95
|
*/
|
|
96
96
|
resolve(ctx: TContext, type: string, path: string, input: {
|
|
97
97
|
[name: string]: any;
|
|
98
|
-
}, rawInput: unknown, options:
|
|
98
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
|
|
99
99
|
}
|
|
100
|
-
export declare class RuleTrue<TContext extends Record<string, any>> extends LogicRule<TContext> implements
|
|
100
|
+
export declare class RuleTrue<TContext extends Record<string, any>> extends LogicRule<TContext> implements LogicRuleInterface<TContext> {
|
|
101
101
|
name: string;
|
|
102
|
-
equals: (rule:
|
|
102
|
+
equals: (rule: RuleInterface<TContext>) => boolean;
|
|
103
103
|
constructor();
|
|
104
104
|
/**
|
|
105
105
|
*
|
|
106
106
|
* Always true.
|
|
107
107
|
*
|
|
108
108
|
*/
|
|
109
|
-
resolve(): Promise<
|
|
109
|
+
resolve(): Promise<RuleResultInterface>;
|
|
110
110
|
}
|
|
111
|
-
export declare class RuleFalse<TContext extends Record<string, any>> extends LogicRule<TContext> implements
|
|
111
|
+
export declare class RuleFalse<TContext extends Record<string, any>> extends LogicRule<TContext> implements LogicRuleInterface<TContext> {
|
|
112
112
|
name: string;
|
|
113
|
-
equals: (rule:
|
|
113
|
+
equals: (rule: RuleInterface<TContext>) => boolean;
|
|
114
114
|
constructor();
|
|
115
115
|
/**
|
|
116
116
|
*
|
|
117
117
|
* Always false.
|
|
118
118
|
*
|
|
119
119
|
*/
|
|
120
|
-
resolve(): Promise<
|
|
120
|
+
resolve(): Promise<RuleResultInterface>;
|
|
121
121
|
}
|
package/dist/shield/rules.mjs
CHANGED
|
@@ -1 +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
|
|
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 a=>a.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(a=>a 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(a=>a 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(a=>a instanceof Error)??!1:!0}async evaluate(e,n,s,o,u,r){const t=this.getRules();return i(t);async function i([a,...x]){return a===void 0?[]:a.resolve(e,n,s,o,u,r).then(async c=>c!==!0?[c]:i(x).then(f=>f.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(a=>a instanceof Error)??!1}async evaluate(e,n,s,o,u,r){const t=this.getRules();return i(t);async function i([a,...x]){return a===void 0?[]:a.resolve(e,n,s,o,u,r).then(async c=>c===!0?[c]:i(x).then(f=>f.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}}
|
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
|
|
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("Authorization error"))(
|
|
11
|
+
function s(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("Authorization error"))(e.fallbackError)
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
function shield(
|
|
20
|
-
const n =
|
|
21
|
-
t = (0, _validation.validateRuleTree)(
|
|
22
|
-
if (t.status === "ok") return (0, _generator.generateMiddlewareFromRuleTree)(
|
|
19
|
+
function shield(e, o = {}) {
|
|
20
|
+
const n = s(o),
|
|
21
|
+
t = (0, _validation.validateRuleTree)(e);
|
|
22
|
+
if (t.status === "ok") return (0, _generator.generateMiddlewareFromRuleTree)(e, n);
|
|
23
23
|
throw new _validation.ValidationError(t.message);
|
|
24
24
|
}
|
package/dist/shield/shield.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MiddlewareFunction } from "@trpc/server/unstable-core-do-not-import";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IRules, OptionsConstructorInterface } 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>(ruleTree: IRules<TContext>, options?:
|
|
6
|
+
export declare function shield<TContext extends Record<string, any>, TMeta extends object = object>(ruleTree: IRules<TContext>, options?: OptionsConstructorInterface<TContext>): MiddlewareFunction<TContext, TMeta, TContext, TContext, unknown>;
|
package/dist/shield/shield.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{allow as
|
|
1
|
+
import{allow as a}from"./constructors";import{generateMiddlewareFromRuleTree as l}from"./generator";import{withDefault as r}from"./utils";import{ValidationError as i,validateRuleTree as c}from"./validation";function s(e){return typeof e.fallbackError=="string"&&(e.fallbackError=new Error(e.fallbackError)),{debug:e.debug??!1,allowExternalErrors:r(!1)(e.allowExternalErrors),fallbackRule:r(a)(e.fallbackRule),fallbackError:r(new Error("Authorization error"))(e.fallbackError)}}export function shield(e,o={}){const n=s(o),t=c(e);if(t.status==="ok")return l(e,n);throw new i(t.message)}
|
package/dist/shield/types.d.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
export type ShieldRule<TContext extends Record<string, any> = Record<string, any>> =
|
|
2
|
-
export interface
|
|
1
|
+
export type ShieldRule<TContext extends Record<string, any> = Record<string, any>> = RuleInterface<TContext> | LogicRuleInterface<TContext>;
|
|
2
|
+
export interface RuleInterface<TContext extends Record<string, any> = Record<string, any>> {
|
|
3
3
|
name: string;
|
|
4
|
-
equals: (rule:
|
|
4
|
+
equals: (rule: RuleInterface<TContext>) => boolean;
|
|
5
5
|
resolve: (ctx: TContext, type: string, path: string, input: {
|
|
6
6
|
[name: string]: any;
|
|
7
|
-
}, rawInput: unknown, options:
|
|
7
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>) => Promise<RuleResultInterface>;
|
|
8
8
|
executeRule: <TContext extends Record<string, any>>(ctx: TContext, type: string, path: string, input: {
|
|
9
9
|
[name: string]: any;
|
|
10
|
-
}, rawInput: unknown, options:
|
|
10
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>) => string | boolean | Error | Promise<RuleResultInterface>;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
12
|
+
export interface RuleOptionsInterface {
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface LogicRuleInterface<TContext extends Record<string, any> = Record<string, any>> extends RuleInterface<TContext> {
|
|
15
15
|
getRules: () => ShieldRule<TContext>[];
|
|
16
16
|
evaluate: (ctx: TContext, type: string, path: string, input: {
|
|
17
17
|
[name: string]: any;
|
|
18
|
-
}, rawInput: unknown, options:
|
|
18
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>) => Promise<RuleResultInterface[]>;
|
|
19
19
|
resolve: (ctx: TContext, type: string, path: string, input: {
|
|
20
20
|
[name: string]: any;
|
|
21
|
-
}, rawInput: unknown, options:
|
|
21
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>) => Promise<RuleResultInterface>;
|
|
22
22
|
}
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
23
|
+
export type RuleResultInterface = boolean | string | Error;
|
|
24
|
+
export type RuleFunctionInterface<TContext extends Record<string, any> = Record<string, any>> = (ctx: TContext, type: string, path: string, input: {
|
|
25
25
|
[name: string]: any;
|
|
26
|
-
}, rawInput: unknown, options:
|
|
27
|
-
export interface
|
|
26
|
+
}, rawInput: unknown, options: OptionsInterface<TContext>) => RuleResultInterface | Promise<RuleResultInterface>;
|
|
27
|
+
export interface RuleConstructorOptionsInterface {
|
|
28
28
|
}
|
|
29
|
-
export interface
|
|
30
|
-
[key: string]: ShieldRule<TContext> |
|
|
29
|
+
export interface RuleTypeMapInterface<TContext extends Record<string, any> = Record<string, any>> {
|
|
30
|
+
[key: string]: ShieldRule<TContext> | RuleFieldMapInterface<TContext> | RuleTypeMapInterface<TContext>;
|
|
31
31
|
}
|
|
32
|
-
export interface
|
|
32
|
+
export interface RuleFieldMapInterface<TContext extends Record<string, any> = Record<string, any>> {
|
|
33
33
|
[key: string]: ShieldRule<TContext>;
|
|
34
34
|
}
|
|
35
|
-
export type IRules<TContext extends Record<string, any> = Record<string, any>> = ShieldRule<TContext> |
|
|
35
|
+
export type IRules<TContext extends Record<string, any> = Record<string, any>> = ShieldRule<TContext> | RuleTypeMapInterface<TContext>;
|
|
36
36
|
export type IFallbackErrorMapperType<TContext extends Record<string, any> = Record<string, any>> = (err: unknown, ctx: TContext, type: string, path: string, input: {
|
|
37
37
|
[name: string]: any;
|
|
38
38
|
}, rawInput: unknown) => Promise<Error> | Error;
|
|
39
39
|
export type IFallbackErrorType<TContext extends Record<string, any> = Record<string, any>> = Error | IFallbackErrorMapperType<TContext>;
|
|
40
|
-
export interface
|
|
40
|
+
export interface OptionsInterface<TContext extends Record<string, any> = Record<string, any>> {
|
|
41
41
|
debug: boolean;
|
|
42
42
|
allowExternalErrors: boolean;
|
|
43
43
|
fallbackRule: ShieldRule<TContext>;
|
|
44
44
|
fallbackError?: IFallbackErrorType<TContext>;
|
|
45
45
|
}
|
|
46
|
-
export interface
|
|
46
|
+
export interface OptionsConstructorInterface<TContext extends Record<string, any> = Record<string, any>> {
|
|
47
47
|
debug?: boolean;
|
|
48
48
|
allowExternalErrors?: boolean;
|
|
49
49
|
fallbackRule?: ShieldRule<TContext>;
|
|
50
50
|
fallbackError?: string | IFallbackErrorType<TContext>;
|
|
51
51
|
}
|
|
52
|
-
export declare function shield<TContext extends Record<string, any> = Record<string, any>>(ruleTree: IRules<TContext>, options:
|
|
52
|
+
export declare function shield<TContext extends Record<string, any> = Record<string, any>>(ruleTree: IRules<TContext>, options: OptionsInterface<TContext>): any;
|
package/dist/shield/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LogicRuleInterface, RuleFieldMapInterface, RuleInterface, ShieldRule } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Makes sure that a certain field is a rule.
|
|
4
4
|
*/
|
|
5
|
-
export declare function isRule<TContext extends Record<string, any>>(x: any): x is
|
|
5
|
+
export declare function isRule<TContext extends Record<string, any>>(x: any): x is RuleInterface<TContext>;
|
|
6
6
|
/**
|
|
7
7
|
* Makes sure that a certain field is a logic rule.
|
|
8
8
|
*/
|
|
9
|
-
export declare function isLogicRule<TContext extends Record<string, any>>(x: any): x is
|
|
9
|
+
export declare function isLogicRule<TContext extends Record<string, any>>(x: any): x is LogicRuleInterface<TContext>;
|
|
10
10
|
/**
|
|
11
11
|
* Makes sure that a certain field is a rule or a logic rule.
|
|
12
12
|
*/
|
|
@@ -14,7 +14,7 @@ export declare function isRuleFunction<TContext extends Record<string, any>>(x:
|
|
|
14
14
|
/**
|
|
15
15
|
* Determines whether a certain field is rule field map or not.
|
|
16
16
|
*/
|
|
17
|
-
export declare function isRuleFieldMap<TContext extends Record<string, any>>(x: any): x is
|
|
17
|
+
export declare function isRuleFieldMap<TContext extends Record<string, any>>(x: any): x is RuleFieldMapInterface<TContext>;
|
|
18
18
|
/**
|
|
19
19
|
* Flattens object of particular type by checking if the leaf
|
|
20
20
|
* evaluates to true from particular function.
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ValidationError = void 0;
|
|
7
7
|
exports.validateRuleTree = validateRuleTree;
|
|
8
8
|
var _utils = require("./utils.cjs");
|
|
9
|
-
function validateRuleTree(
|
|
10
|
-
const
|
|
9
|
+
function validateRuleTree(s) {
|
|
10
|
+
const a = l(s).reduce(({
|
|
11
11
|
map: t,
|
|
12
12
|
duplicates: n
|
|
13
13
|
}, e) => t.has(e.name) ? !t.get(e.name).equals(e) && !n.includes(e.name) ? {
|
|
@@ -23,18 +23,18 @@ function validateRuleTree(r) {
|
|
|
23
23
|
map: new Map(),
|
|
24
24
|
duplicates: []
|
|
25
25
|
});
|
|
26
|
-
if (
|
|
26
|
+
if (a.duplicates.length === 0) return {
|
|
27
27
|
status: "ok"
|
|
28
28
|
};
|
|
29
29
|
return {
|
|
30
30
|
status: "err",
|
|
31
|
-
message: `There seem to be multiple definitions of these rules: ${
|
|
31
|
+
message: `There seem to be multiple definitions of these rules: ${a.duplicates.join(", ")}`
|
|
32
32
|
};
|
|
33
|
-
function
|
|
34
|
-
return (0, _utils.flattenObjectOf)(t, _utils.isRuleFunction).reduce((
|
|
33
|
+
function l(t) {
|
|
34
|
+
return (0, _utils.flattenObjectOf)(t, _utils.isRuleFunction).reduce((c, r) => (0, _utils.isLogicRule)(r) ? [...c, ...u(r)] : [...c, r], []);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
return t.getRules().reduce((n, e) => (0, _utils.isLogicRule)(e) ? [...n, ...
|
|
36
|
+
function u(t) {
|
|
37
|
+
return t.getRules().reduce((n, e) => (0, _utils.isLogicRule)(e) ? [...n, ...u(e)] : [...n, e], []);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
class ValidationError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{flattenObjectOf as
|
|
1
|
+
import{flattenObjectOf as f,isLogicRule as i,isRuleFunction as x}from"./utils";export function validateRuleTree(s){const a=l(s).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(a.duplicates.length===0)return{status:"ok"};return{status:"err",message:`There seem to be multiple definitions of these rules: ${a.duplicates.join(", ")}`};function l(t){return f(t,x).reduce((c,r)=>i(r)?[...c,...u(r)]:[...c,r],[])}function u(t){return t.getRules().reduce((n,e)=>i(e)?[...n,...u(e)]:[...n,e],[])}}export class ValidationError extends Error{constructor(o){super(o)}}
|
|
@@ -11,7 +11,7 @@ var _client = require("@trpc/client");
|
|
|
11
11
|
var _tanstackReactQuery = require("@trpc/tanstack-react-query");
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
var _shared = require("../shared.cjs");
|
|
14
|
-
function createTRPCTanstackQueryClient(t,
|
|
14
|
+
function createTRPCTanstackQueryClient(t, e) {
|
|
15
15
|
const {
|
|
16
16
|
TRPCProvider: o,
|
|
17
17
|
useTRPC: n
|
|
@@ -24,7 +24,7 @@ function createTRPCTanstackQueryClient(t, r) {
|
|
|
24
24
|
} = i,
|
|
25
25
|
[u] = (0, _react.useState)(() => (0, _client.createTRPCClient)({
|
|
26
26
|
links: [(0, _client.loggerLink)({
|
|
27
|
-
enabled:
|
|
27
|
+
enabled: r => _environmentChecks.isDevelopment || r.direction === "down" && r.result instanceof Error
|
|
28
28
|
}), (0, _client.httpBatchStreamLink)({
|
|
29
29
|
transformer: _shared.transformer,
|
|
30
30
|
url: (0, _shared.getTRPCServerUrl)(t),
|
|
@@ -35,9 +35,9 @@ function createTRPCTanstackQueryClient(t, r) {
|
|
|
35
35
|
}));
|
|
36
36
|
return React.createElement(o, {
|
|
37
37
|
trpcClient: u,
|
|
38
|
-
queryClient:
|
|
38
|
+
queryClient: e
|
|
39
39
|
}, React.createElement(_reactQuery.QueryClientProvider, {
|
|
40
|
-
client:
|
|
40
|
+
client: e
|
|
41
41
|
}, c));
|
|
42
42
|
}
|
|
43
43
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StormURLInterface } from "@stryke/url/types";
|
|
2
2
|
import type { QueryClient } from "@tanstack/react-query";
|
|
3
3
|
import type { AnyTRPCRouter } from "@trpc/server";
|
|
4
4
|
/**
|
|
@@ -6,8 +6,10 @@ import type { AnyTRPCRouter } from "@trpc/server";
|
|
|
6
6
|
*
|
|
7
7
|
* @returns The TRPC Tanstack Query client
|
|
8
8
|
*/
|
|
9
|
-
export declare function createTRPCTanstackQueryClient<TRouter extends AnyTRPCRouter>(baseUrl: string |
|
|
10
|
-
useTRPCTanstackQuery: () => import("@trpc/tanstack-react-query").TRPCOptionsProxy<TRouter
|
|
9
|
+
export declare function createTRPCTanstackQueryClient<TRouter extends AnyTRPCRouter>(baseUrl: string | StormURLInterface, queryClient: QueryClient): {
|
|
10
|
+
useTRPCTanstackQuery: () => import("@trpc/tanstack-react-query").TRPCOptionsProxy<TRouter, {
|
|
11
|
+
keyPrefix: false;
|
|
12
|
+
}>;
|
|
11
13
|
TRPCTanstackQueryProvider: (props: {
|
|
12
14
|
children: React.ReactNode;
|
|
13
15
|
}) => import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{isDevelopment as
|
|
1
|
+
"use client";import{isDevelopment as a}from"@stryke/env/environment-checks";import{QueryClientProvider as s}from"@tanstack/react-query";import{createTRPCClient as m,httpBatchStreamLink as R,loggerLink as l}from"@trpc/client";import{createTRPCContext as p}from"@trpc/tanstack-react-query";import{useState as C}from"react";import{getTRPCServerUrl as T,transformer as y}from"../shared";export function createTRPCTanstackQueryClient(t,e){const{TRPCProvider:o,useTRPC:n}=p();return{useTRPCTanstackQuery:n,TRPCTanstackQueryProvider:i=>{const{children:c}=i,[u]=C(()=>m({links:[l({enabled:r=>a||r.direction==="down"&&r.result instanceof Error}),R({transformer:y,url:T(t),headers:{"x-trpc-source":"react-query"}})]}));return React.createElement(o,{trpcClient:u,queryClient:e},React.createElement(s,{client:e},c))}}}
|
|
@@ -13,7 +13,9 @@ import "server-only";
|
|
|
13
13
|
* @returns The TRPC Tanstack Query server
|
|
14
14
|
*/
|
|
15
15
|
export declare function createTRPCTanstackQueryServer<TRouter extends AnyTRPCRouter, TContext extends inferRouterContext<TRouter> = inferRouterContext<TRouter>>(headers: () => Promise<Headers>, router: TRouter, createContext?: () => MaybePromise<TContext>, queryClientConfig?: Partial<QueryClientConfig>): {
|
|
16
|
-
trpc: import("@trpc/tanstack-react-query").TRPCOptionsProxy<TRouter
|
|
16
|
+
trpc: import("@trpc/tanstack-react-query").TRPCOptionsProxy<TRouter, {
|
|
17
|
+
keyPrefix: false;
|
|
18
|
+
}>;
|
|
17
19
|
HydrateClient: (props: {
|
|
18
20
|
children: React.ReactNode;
|
|
19
21
|
}) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/trpc-next",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package to help in using tRPC in modern NextJs applications.",
|
|
6
6
|
"repository": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"react": "^19.
|
|
14
|
-
"react-dom": "^19.
|
|
15
|
-
"react-native": "^0.77.
|
|
13
|
+
"react": "^19.2.0",
|
|
14
|
+
"react-dom": "^19.2.0",
|
|
15
|
+
"react-native": "^0.77.3"
|
|
16
16
|
},
|
|
17
17
|
"peerDependenciesMeta": {
|
|
18
18
|
"react": { "optional": false },
|
|
@@ -20,23 +20,23 @@
|
|
|
20
20
|
"react-native": { "optional": true }
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@js-temporal/polyfill": "^0.5.
|
|
24
|
-
"@tanstack/react-query": "^5.
|
|
25
|
-
"@trpc/client": "
|
|
26
|
-
"@trpc/next": "
|
|
27
|
-
"@trpc/server": "
|
|
28
|
-
"@trpc/tanstack-react-query": "
|
|
23
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
24
|
+
"@tanstack/react-query": "^5.90.5",
|
|
25
|
+
"@trpc/client": "^11.7.1",
|
|
26
|
+
"@trpc/next": "^11.7.1",
|
|
27
|
+
"@trpc/server": "^11.7.1",
|
|
28
|
+
"@trpc/tanstack-react-query": "^11.7.1",
|
|
29
29
|
"defu": "^6.1.4",
|
|
30
30
|
"server-only": "^0.0.1",
|
|
31
31
|
"superjson": "2.2.2",
|
|
32
|
-
"@stryke/env": "^0.
|
|
33
|
-
"@stryke/
|
|
34
|
-
"@stryke/
|
|
35
|
-
"@stryke/
|
|
32
|
+
"@stryke/env": "^0.20.5",
|
|
33
|
+
"@stryke/path": "^0.18.0",
|
|
34
|
+
"@stryke/types": "^0.10.0",
|
|
35
|
+
"@stryke/url": "^0.2.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/react": "^19.
|
|
39
|
-
"@types/react-dom": "^19.
|
|
38
|
+
"@types/react": "^19.2.2",
|
|
39
|
+
"@types/react-dom": "^19.2.2",
|
|
40
40
|
"@types/react-native": "0.72.8"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": { "access": "public" },
|
|
@@ -321,5 +321,6 @@
|
|
|
321
321
|
},
|
|
322
322
|
"main": "./dist/index.cjs",
|
|
323
323
|
"module": "./dist/index.mjs",
|
|
324
|
-
"types": "./dist/index.d.ts"
|
|
324
|
+
"types": "./dist/index.d.ts",
|
|
325
|
+
"gitHead": "1764a8373c1db0b1c11bed7439292236edfd9e4e"
|
|
325
326
|
}
|