@stryke/trpc-next 0.5.7 → 0.5.9

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/README.md CHANGED
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŸŒŠī¸ Stryke** monorepo. Stryke pac
22
22
 
23
23
  <h3 align="center">đŸ’ģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
24
24
 
25
- [![Version](https://img.shields.io/badge/version-0.5.6-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
25
+ [![Version](https://img.shields.io/badge/version-0.5.7-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/stryke/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
26
 
27
27
  > [!IMPORTANT] Important
28
28
  > This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be available through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
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, t = 1) {
16
- return (0, _joinPaths.joinPaths)(typeof e == "string" ? e : e.host || "", "api", t ? `v${t}` : "", "trpc");
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: t => (0, _reactQuery.defaultShouldDehydrateQuery)(t) || t.state.status === "pending",
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 { StormURL } from "@stryke/http/types";
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 | StormURL, version?: number | null): any;
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 r}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,t=1){return i(typeof e=="string"?e:e.host||"","api",t?`v${t}`:"","trpc")}a.registerCustom({isApplicable:e=>e instanceof r.PlainDate,serialize:e=>e.toJSON(),deserialize:e=>r.PlainDate.from(e)},"Temporal.PlainDate"),a.registerCustom({isApplicable:e=>e instanceof r.PlainDateTime,serialize:e=>e.toJSON(),deserialize:e=>r.PlainDateTime.from(e)},"Temporal.PlainDateTime");export const transformer=a,createQueryClient=(e={})=>new n(s(e,{defaultOptions:{queries:{staleTime:1e3*30},dehydrate:{shouldDehydrateQuery:t=>o(t)||t.state.status==="pending",serializeData:transformer.serialize},hydrate:{deserializeData:transformer.deserialize}}}));
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 { IRuleConstructorOptions, IRuleFunction, ShieldRule } from "./types";
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?: IRuleConstructorOptions) => (func: IRuleFunction<TContext>) => Rule<TContext>;
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 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;
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: d,
10
+ ctx: f,
11
11
  type: t,
12
12
  path: c,
13
- input: f,
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(d, t, c, f, g, o).then(async e => {
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 { IOptions, IRules } from "./types";
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: IOptions<TContext>): ({ next, ctx, type, path, input, rawInput }: {
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: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()}}
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()}}
@@ -1,3 +1,3 @@
1
1
  export { allow, and, chain, deny, not, or, race, rule } from "./constructors";
2
2
  export { shield } from "./shield";
3
- export type { IRule, IRules } from "./types";
3
+ export type { RuleInterface as IRule, IRules } from "./types";
@@ -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 l => l.resolve(e, n, s, o, u, r));
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(l => l instanceof Error) ?? !1 : !0;
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(l => l instanceof Error) ?? !1 : !0;
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(l => l instanceof Error) ?? !1 : !0;
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([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)));
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(l => l instanceof Error) ?? !1;
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([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)));
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
  }
@@ -1,11 +1,11 @@
1
- import type { ILogicRule, IOptions, IRule, IRuleFunction, IRuleResult, ShieldRule } from "./types";
2
- export declare class Rule<TContext extends Record<string, any>> implements IRule<TContext> {
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?: IRuleFunction<TContext>;
5
- constructor(name: string, func?: IRuleFunction<TContext>);
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): string | boolean | Error | Promise<IRuleResult>;
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 ILogicRule<TContext> {
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): Promise<IRuleResult[]>;
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): Promise<IRuleResult[]>;
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: IOptions<TContext>): Promise<IRuleResult>;
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: IOptions<TContext>): Promise<IRuleResult[]>;
86
+ }, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface[]>;
87
87
  }
88
- export declare class RuleNot<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
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: IRule<TContext>) => boolean;
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: IOptions<TContext>): Promise<IRuleResult>;
98
+ }, rawInput: unknown, options: OptionsInterface<TContext>): Promise<RuleResultInterface>;
99
99
  }
100
- export declare class RuleTrue<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
100
+ export declare class RuleTrue<TContext extends Record<string, any>> extends LogicRule<TContext> implements LogicRuleInterface<TContext> {
101
101
  name: string;
102
- equals: (rule: IRule<TContext>) => boolean;
102
+ equals: (rule: RuleInterface<TContext>) => boolean;
103
103
  constructor();
104
104
  /**
105
105
  *
106
106
  * Always true.
107
107
  *
108
108
  */
109
- resolve(): Promise<IRuleResult>;
109
+ resolve(): Promise<RuleResultInterface>;
110
110
  }
111
- export declare class RuleFalse<TContext extends Record<string, any>> extends LogicRule<TContext> implements ILogicRule<TContext> {
111
+ export declare class RuleFalse<TContext extends Record<string, any>> extends LogicRule<TContext> implements LogicRuleInterface<TContext> {
112
112
  name: string;
113
- equals: (rule: IRule<TContext>) => boolean;
113
+ equals: (rule: RuleInterface<TContext>) => boolean;
114
114
  constructor();
115
115
  /**
116
116
  *
117
117
  * Always false.
118
118
  *
119
119
  */
120
- resolve(): Promise<IRuleResult>;
120
+ resolve(): Promise<RuleResultInterface>;
121
121
  }
@@ -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 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}}
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}}
@@ -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(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)
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(r, o = {}) {
20
- const n = u(o),
21
- t = (0, _validation.validateRuleTree)(r);
22
- if (t.status === "ok") return (0, _generator.generateMiddlewareFromRuleTree)(r, n);
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
  }
@@ -1,6 +1,6 @@
1
1
  import type { MiddlewareFunction } from "@trpc/server/unstable-core-do-not-import";
2
- import type { IOptionsConstructor, IRules } from "./types";
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?: IOptionsConstructor<TContext>): MiddlewareFunction<TContext, TMeta, TContext, TContext, unknown>;
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>;
@@ -1 +1 @@
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)}
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)}
@@ -1,52 +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>> {
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: IRule<TContext>) => boolean;
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: IOptions<TContext>) => Promise<IRuleResult>;
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: IOptions<TContext>) => string | boolean | Error | Promise<IRuleResult>;
10
+ }, rawInput: unknown, options: OptionsInterface<TContext>) => string | boolean | Error | Promise<RuleResultInterface>;
11
11
  }
12
- export interface IRuleOptions {
12
+ export interface RuleOptionsInterface {
13
13
  }
14
- export interface ILogicRule<TContext extends Record<string, any> = Record<string, any>> extends IRule<TContext> {
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: IOptions<TContext>) => Promise<IRuleResult[]>;
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: IOptions<TContext>) => Promise<IRuleResult>;
21
+ }, rawInput: unknown, options: OptionsInterface<TContext>) => Promise<RuleResultInterface>;
22
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: {
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: IOptions<TContext>) => IRuleResult | Promise<IRuleResult>;
27
- export interface IRuleConstructorOptions {
26
+ }, rawInput: unknown, options: OptionsInterface<TContext>) => RuleResultInterface | Promise<RuleResultInterface>;
27
+ export interface RuleConstructorOptionsInterface {
28
28
  }
29
- export interface IRuleTypeMap<TContext extends Record<string, any> = Record<string, any>> {
30
- [key: string]: ShieldRule<TContext> | IRuleFieldMap<TContext> | IRuleTypeMap<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 IRuleFieldMap<TContext extends Record<string, any> = Record<string, any>> {
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> | IRuleTypeMap<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 IOptions<TContext extends Record<string, any> = Record<string, any>> {
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 IOptionsConstructor<TContext extends Record<string, any> = Record<string, any>> {
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: IOptions<TContext>): any;
52
+ export declare function shield<TContext extends Record<string, any> = Record<string, any>>(ruleTree: IRules<TContext>, options: OptionsInterface<TContext>): any;
@@ -1,12 +1,12 @@
1
- import type { ILogicRule, IRule, IRuleFieldMap, ShieldRule } from "./types";
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 IRule<TContext>;
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 ILogicRule<TContext>;
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 IRuleFieldMap<TContext>;
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(r) {
10
- const u = c(r).reduce(({
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 (u.duplicates.length === 0) return {
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: ${u.duplicates.join(", ")}`
31
+ message: `There seem to be multiple definitions of these rules: ${a.duplicates.join(", ")}`
32
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], []);
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 i(t) {
37
- return t.getRules().reduce((n, e) => (0, _utils.isLogicRule)(e) ? [...n, ...i(e)] : [...n, e], []);
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 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)}}
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, r) {
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: e => _environmentChecks.isDevelopment || e.direction === "down" && e.result instanceof Error
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: r
38
+ queryClient: e
39
39
  }, React.createElement(_reactQuery.QueryClientProvider, {
40
- client: r
40
+ client: e
41
41
  }, c));
42
42
  }
43
43
  };
@@ -1,4 +1,4 @@
1
- import type { StormURL } from "@stryke/http/types";
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,7 +6,7 @@ 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 | StormURL, queryClient: QueryClient): {
9
+ export declare function createTRPCTanstackQueryClient<TRouter extends AnyTRPCRouter>(baseUrl: string | StormURLInterface, 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 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))}}}
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))}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/trpc-next",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "type": "module",
5
5
  "description": "A package to help in using tRPC in modern NextJs applications.",
6
6
  "repository": {
@@ -29,10 +29,10 @@
29
29
  "defu": "^6.1.4",
30
30
  "server-only": "^0.0.1",
31
31
  "superjson": "2.2.2",
32
- "@stryke/env": "^0.13.0",
33
- "@stryke/http": "^0.8.1",
34
- "@stryke/path": "^0.7.5",
35
- "@stryke/types": "^0.8.3"
32
+ "@stryke/env": "^0.15.10",
33
+ "@stryke/path": "^0.12.1",
34
+ "@stryke/types": "^0.8.6",
35
+ "@stryke/url": "^0.2.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/react": "^19.0.12",
@@ -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": "57da58e3434302b35f798674d9f18f92ca7f7ac9"
325
326
  }