@stryke/trpc-next 0.5.99 → 0.5.100
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/CHANGELOG.md +20 -0
- package/dist/_virtual/_rolldown/runtime.cjs +0 -14
- package/dist/action-handler.cjs +0 -7
- package/dist/action-handler.mjs +1 -3
- package/dist/action-handler.mjs.map +1 -1
- package/dist/client.cjs +0 -10
- package/dist/client.mjs +1 -6
- package/dist/client.mjs.map +1 -1
- package/dist/index.cjs +0 -22
- package/dist/index.mjs +1 -19
- package/dist/server.cjs +0 -11
- package/dist/server.mjs +1 -7
- package/dist/server.mjs.map +1 -1
- package/dist/shared.cjs +0 -11
- package/dist/shared.mjs +1 -7
- package/dist/shared.mjs.map +1 -1
- package/dist/shield/constructors.cjs +0 -17
- package/dist/shield/constructors.mjs +1 -12
- package/dist/shield/constructors.mjs.map +1 -1
- package/dist/shield/generator.cjs +1 -9
- package/dist/shield/generator.mjs +1 -4
- package/dist/shield/generator.mjs.map +1 -1
- package/dist/shield/index.cjs +1 -22
- package/dist/shield/index.mjs +1 -17
- package/dist/shield/rules.cjs +1 -19
- package/dist/shield/rules.mjs +1 -14
- package/dist/shield/rules.mjs.map +1 -1
- package/dist/shield/shield.cjs +1 -9
- package/dist/shield/shield.mjs +1 -3
- package/dist/shield/shield.mjs.map +1 -1
- package/dist/shield/types.cjs +0 -13
- package/dist/shield/types.mjs +0 -8
- package/dist/shield/utils.cjs +0 -15
- package/dist/shield/utils.mjs +1 -10
- package/dist/shield/utils.mjs.map +1 -1
- package/dist/shield/validation.cjs +1 -12
- package/dist/shield/validation.mjs +1 -6
- package/dist/shield/validation.mjs.map +1 -1
- package/dist/types.cjs +0 -13
- package/dist/types.mjs +0 -8
- package/package.json +10 -66
- package/dist/_virtual/_rolldown/runtime.mjs +0 -18
- package/dist/action-handler.test.cjs +0 -13
- package/dist/action-handler.test.d.cts +0 -1
- package/dist/action-handler.test.d.mts +0 -1
- package/dist/action-handler.test.mjs +0 -13
- package/dist/action-handler.test.mjs.map +0 -1
- package/dist/client.test.cjs +0 -13
- package/dist/client.test.d.cts +0 -1
- package/dist/client.test.d.mts +0 -1
- package/dist/client.test.mjs +0 -13
- package/dist/client.test.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/index.test.cjs +0 -13
- package/dist/index.test.d.cts +0 -1
- package/dist/index.test.d.mts +0 -1
- package/dist/index.test.mjs +0 -13
- package/dist/index.test.mjs.map +0 -1
- package/dist/server.test.cjs +0 -13
- package/dist/server.test.d.cts +0 -1
- package/dist/server.test.d.mts +0 -1
- package/dist/server.test.mjs +0 -13
- package/dist/server.test.mjs.map +0 -1
- package/dist/shared.test.cjs +0 -13
- package/dist/shared.test.d.cts +0 -1
- package/dist/shared.test.d.mts +0 -1
- package/dist/shared.test.mjs +0 -13
- package/dist/shared.test.mjs.map +0 -1
- package/dist/shield/constructors.test.cjs +0 -13
- package/dist/shield/constructors.test.d.cts +0 -1
- package/dist/shield/constructors.test.d.mts +0 -1
- package/dist/shield/constructors.test.mjs +0 -13
- package/dist/shield/constructors.test.mjs.map +0 -1
- package/dist/shield/generator.test.cjs +0 -13
- package/dist/shield/generator.test.d.cts +0 -1
- package/dist/shield/generator.test.d.mts +0 -1
- package/dist/shield/generator.test.mjs +0 -13
- package/dist/shield/generator.test.mjs.map +0 -1
- package/dist/shield/index.mjs.map +0 -1
- package/dist/shield/index.test.cjs +0 -13
- package/dist/shield/index.test.d.cts +0 -1
- package/dist/shield/index.test.d.mts +0 -1
- package/dist/shield/index.test.mjs +0 -13
- package/dist/shield/index.test.mjs.map +0 -1
- package/dist/shield/rules.test.cjs +0 -13
- package/dist/shield/rules.test.d.cts +0 -1
- package/dist/shield/rules.test.d.mts +0 -1
- package/dist/shield/rules.test.mjs +0 -13
- package/dist/shield/rules.test.mjs.map +0 -1
- package/dist/shield/shield.test.cjs +0 -13
- package/dist/shield/shield.test.d.cts +0 -1
- package/dist/shield/shield.test.d.mts +0 -1
- package/dist/shield/shield.test.mjs +0 -13
- package/dist/shield/shield.test.mjs.map +0 -1
- package/dist/shield/types.mjs.map +0 -1
- package/dist/shield/types.test.cjs +0 -13
- package/dist/shield/types.test.d.cts +0 -1
- package/dist/shield/types.test.d.mts +0 -1
- package/dist/shield/types.test.mjs +0 -13
- package/dist/shield/types.test.mjs.map +0 -1
- package/dist/shield/utils.test.cjs +0 -13
- package/dist/shield/utils.test.d.cts +0 -1
- package/dist/shield/utils.test.d.mts +0 -1
- package/dist/shield/utils.test.mjs +0 -13
- package/dist/shield/utils.test.mjs.map +0 -1
- package/dist/shield/validation.test.cjs +0 -13
- package/dist/shield/validation.test.d.cts +0 -1
- package/dist/shield/validation.test.d.mts +0 -1
- package/dist/shield/validation.test.mjs +0 -13
- package/dist/shield/validation.test.mjs.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/types.test.cjs +0 -13
- package/dist/types.test.d.cts +0 -1
- package/dist/types.test.d.mts +0 -1
- package/dist/types.test.mjs +0 -13
- package/dist/types.test.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.mjs","names":[],"sources":["../../src/shield/rules.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n LogicRuleInterface,\n OptionsInterface,\n RuleFunctionInterface,\n RuleInterface,\n RuleResultInterface,\n ShieldRule\n} from \"./types\";\n\nexport class Rule<\n TContext extends Record<string, any>\n> implements RuleInterface<TContext> {\n readonly name: string;\n\n func?: RuleFunctionInterface<TContext>;\n\n constructor(name: string, func?: RuleFunctionInterface<TContext>) {\n this.name = name;\n this.func = func;\n }\n\n async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n try {\n /* Resolve */\n const res = await this.executeRule(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (res instanceof Error) {\n return res;\n } else if (typeof res === \"string\") {\n return new Error(res);\n } else if (res === true) {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n if (options.debug) {\n throw err;\n } else {\n return false;\n }\n }\n }\n\n /**\n *\n * Compares a given rule with the current one\n * and checks whether their functions are equal.\n *\n */\n equals(rule: Rule<TContext>): boolean {\n return this.func === rule.func;\n }\n\n executeRule<TContext extends Record<string, any>>(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): string | boolean | Error | Promise<RuleResultInterface> {\n // @ts-ignore\n return this.func(ctx, type, path, input, rawInput, options);\n }\n}\n\nexport class LogicRule<TContext extends Record<string, any>>\n extends Rule<TContext>\n implements LogicRuleInterface<TContext>\n{\n private rules: ShieldRule<TContext>[];\n\n constructor(rules: ShieldRule<TContext>[]) {\n super(\"LogicRule\");\n\n this.rules = rules;\n }\n\n /**\n * By default logic rule resolves to false.\n */\n override async resolve(\n _ctx: TContext,\n _type: string,\n _path: string,\n _input: { [name: string]: any },\n _rawInput: unknown,\n _options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n return false;\n }\n\n /**\n * Evaluates all the rules.\n */\n async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n const tasks = rules.map(async rule =>\n rule.resolve(ctx, type, path, input, rawInput, options)\n );\n\n return Promise.all(tasks);\n }\n\n /**\n * Returns rules in a logic rule.\n */\n getRules() {\n return this.rules;\n }\n}\n\n// Extended Types\n\nexport class RuleOr<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that at least one of them has evaluated to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.every(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n}\n\nexport class RuleAnd<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that all of them have resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.some(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n}\n\nexport class RuleChain<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that all of them have resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.some(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n\n /**\n * Evaluates all the rules.\n */\n override async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n\n return iterate(rules);\n\n async function iterate([\n rule,\n ...otherRules\n ]: ShieldRule<TContext>[]): Promise<RuleResultInterface[]> {\n if (rule === undefined) return [];\n return rule\n .resolve(ctx, type, path, input, rawInput, options)\n .then(async res => {\n if (res !== true) {\n return [res];\n } else {\n return iterate(otherRules).then(ress => ress.concat(res));\n }\n });\n }\n }\n}\n\nexport class RuleRace<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that at least one of them resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.includes(true)) {\n return true;\n } else {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n }\n }\n\n /**\n * Evaluates all the rules.\n */\n override async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n\n return iterate(rules);\n\n async function iterate([\n rule,\n ...otherRules\n ]: ShieldRule<TContext>[]): Promise<RuleResultInterface[]> {\n if (rule === undefined) return [];\n return rule\n .resolve(ctx, type, path, input, rawInput, options)\n .then(async res => {\n if (res === true) {\n return [res];\n } else {\n return iterate(otherRules).then(ress => ress.concat(res));\n }\n });\n }\n }\n}\n\nexport class RuleNot<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n error?: Error;\n\n override name: string = \"RuleNot\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor(rule: ShieldRule<TContext>, error?: Error) {\n super([rule]);\n this.error = error;\n }\n\n /**\n * Negates the result.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const [res] = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (res instanceof Error) {\n return true;\n } else if (res !== true) {\n return true;\n } else {\n if (this.error) return this.error;\n return false;\n }\n }\n}\n\nexport class RuleTrue<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n override name: string = \"RuleTrue\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor() {\n super([]);\n }\n\n /**\n *\n * Always true.\n *\n */\n override async resolve(): Promise<RuleResultInterface> {\n return true;\n }\n}\n\nexport class RuleFalse<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n override name: string = \"RuleTrue\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor() {\n super([]);\n }\n\n /**\n *\n * Always false.\n *\n */\n override async resolve(): Promise<RuleResultInterface> {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,IAAa,OAAb,MAEqC;CACnC,AAAS;CAET;CAEA,YAAY,MAAc,MAAwC;AAChE,OAAK,OAAO;AACZ,OAAK,OAAO;;CAGd,MAAM,QACJ,KACA,MACA,MACA,OACA,UACA,SAC8B;AAC9B,MAAI;GAEF,MAAM,MAAM,MAAM,KAAK,YACrB,KACA,MACA,MACA,OACA,UACA,QACD;AAED,OAAI,eAAe,MACjB,QAAO;YACE,OAAO,QAAQ,SACxB,QAAO,IAAI,MAAM,IAAI;YACZ,QAAQ,KACjB,QAAO;OAEP,QAAO;WAEF,KAAK;AACZ,OAAI,QAAQ,MACV,OAAM;OAEN,QAAO;;;;;;;;;CAWb,OAAO,MAA+B;AACpC,SAAO,KAAK,SAAS,KAAK;;CAG5B,YACE,KACA,MACA,MACA,OACA,UACA,SACyD;AAEzD,SAAO,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AACrD,QAAM,CAAC,KAAK,CAAC;AACb,OAAK,QAAQ;;;;;CAMf,MAAe,QACb,KACA,MACA,MACA,OACA,UACA,SAC8B;EAC9B,MAAM,CAAC,OAAO,MAAM,KAAK,SACvB,KACA,MACA,MACA,OACA,UACA,QACD;AAED,MAAI,eAAe,MACjB,QAAO;WACE,QAAQ,KACjB,QAAO;OACF;AACL,OAAI,KAAK,MAAO,QAAO,KAAK;AAC5B,UAAO;;;;AAKb,IAAa,WAAb,cACU,UAEV;CACE,AAAS,OAAe;CAExB,AAAS;CAET,cAAc;AACZ,QAAM,EAAE,CAAC;;;;;;;CAQX,MAAe,UAAwC;AACrD,SAAO;;;AAIX,IAAa,YAAb,cACU,UAEV;CACE,AAAS,OAAe;CAExB,AAAS;CAET,cAAc;AACZ,QAAM,EAAE,CAAC;;;;;;;CAQX,MAAe,UAAwC;AACrD,SAAO"}
|
|
1
|
+
{"version":3,"file":"rules.mjs","names":[],"sources":["../../src/shield/rules.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n LogicRuleInterface,\n OptionsInterface,\n RuleFunctionInterface,\n RuleInterface,\n RuleResultInterface,\n ShieldRule\n} from \"./types\";\n\nexport class Rule<\n TContext extends Record<string, any>\n> implements RuleInterface<TContext> {\n readonly name: string;\n\n func?: RuleFunctionInterface<TContext>;\n\n constructor(name: string, func?: RuleFunctionInterface<TContext>) {\n this.name = name;\n this.func = func;\n }\n\n async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n try {\n /* Resolve */\n const res = await this.executeRule(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (res instanceof Error) {\n return res;\n } else if (typeof res === \"string\") {\n return new Error(res);\n } else if (res === true) {\n return true;\n } else {\n return false;\n }\n } catch (err) {\n if (options.debug) {\n throw err;\n } else {\n return false;\n }\n }\n }\n\n /**\n *\n * Compares a given rule with the current one\n * and checks whether their functions are equal.\n *\n */\n equals(rule: Rule<TContext>): boolean {\n return this.func === rule.func;\n }\n\n executeRule<TContext extends Record<string, any>>(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): string | boolean | Error | Promise<RuleResultInterface> {\n // @ts-ignore\n return this.func(ctx, type, path, input, rawInput, options);\n }\n}\n\nexport class LogicRule<TContext extends Record<string, any>>\n extends Rule<TContext>\n implements LogicRuleInterface<TContext>\n{\n private rules: ShieldRule<TContext>[];\n\n constructor(rules: ShieldRule<TContext>[]) {\n super(\"LogicRule\");\n\n this.rules = rules;\n }\n\n /**\n * By default logic rule resolves to false.\n */\n override async resolve(\n _ctx: TContext,\n _type: string,\n _path: string,\n _input: { [name: string]: any },\n _rawInput: unknown,\n _options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n return false;\n }\n\n /**\n * Evaluates all the rules.\n */\n async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n const tasks = rules.map(async rule =>\n rule.resolve(ctx, type, path, input, rawInput, options)\n );\n\n return Promise.all(tasks);\n }\n\n /**\n * Returns rules in a logic rule.\n */\n getRules() {\n return this.rules;\n }\n}\n\n// Extended Types\n\nexport class RuleOr<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that at least one of them has evaluated to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.every(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n}\n\nexport class RuleAnd<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that all of them have resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.some(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n}\n\nexport class RuleChain<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that all of them have resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.some(res => res !== true)) {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n } else {\n return true;\n }\n }\n\n /**\n * Evaluates all the rules.\n */\n override async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n\n return iterate(rules);\n\n async function iterate([\n rule,\n ...otherRules\n ]: ShieldRule<TContext>[]): Promise<RuleResultInterface[]> {\n if (rule === undefined) return [];\n return rule\n .resolve(ctx, type, path, input, rawInput, options)\n .then(async res => {\n if (res !== true) {\n return [res];\n } else {\n return iterate(otherRules).then(ress => ress.concat(res));\n }\n });\n }\n }\n}\n\nexport class RuleRace<\n TContext extends Record<string, any>\n> extends LogicRule<TContext> {\n constructor(rules: ShieldRule<TContext>[]) {\n super(rules);\n }\n\n /**\n * Makes sure that at least one of them resolved to true.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const result = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (result.includes(true)) {\n return true;\n } else {\n const customError = result.find(res => res instanceof Error);\n\n return customError ?? false;\n }\n }\n\n /**\n * Evaluates all the rules.\n */\n override async evaluate(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface[]> {\n const rules = this.getRules();\n\n return iterate(rules);\n\n async function iterate([\n rule,\n ...otherRules\n ]: ShieldRule<TContext>[]): Promise<RuleResultInterface[]> {\n if (rule === undefined) return [];\n return rule\n .resolve(ctx, type, path, input, rawInput, options)\n .then(async res => {\n if (res === true) {\n return [res];\n } else {\n return iterate(otherRules).then(ress => ress.concat(res));\n }\n });\n }\n }\n}\n\nexport class RuleNot<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n error?: Error;\n\n override name: string = \"RuleNot\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor(rule: ShieldRule<TContext>, error?: Error) {\n super([rule]);\n this.error = error;\n }\n\n /**\n * Negates the result.\n */\n override async resolve(\n ctx: TContext,\n type: string,\n path: string,\n input: { [name: string]: any },\n rawInput: unknown,\n options: OptionsInterface<TContext>\n ): Promise<RuleResultInterface> {\n const [res] = await this.evaluate(\n ctx,\n type,\n path,\n input,\n rawInput,\n options\n );\n\n if (res instanceof Error) {\n return true;\n } else if (res !== true) {\n return true;\n } else {\n if (this.error) return this.error;\n return false;\n }\n }\n}\n\nexport class RuleTrue<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n override name: string = \"RuleTrue\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor() {\n super([]);\n }\n\n /**\n *\n * Always true.\n *\n */\n override async resolve(): Promise<RuleResultInterface> {\n return true;\n }\n}\n\nexport class RuleFalse<TContext extends Record<string, any>>\n extends LogicRule<TContext>\n implements LogicRuleInterface<TContext>\n{\n override name: string = \"RuleTrue\";\n\n override equals!: (rule: RuleInterface<TContext>) => boolean;\n\n constructor() {\n super([]);\n }\n\n /**\n *\n * Always false.\n *\n */\n override async resolve(): Promise<RuleResultInterface> {\n return false;\n }\n}\n"],"mappings":";AA2BA,IAAa,OAAb,MAEqC;CACnC,AAAS;CAET;CAEA,YAAY,MAAc,MAAwC;AAChE,OAAK,OAAO;AACZ,OAAK,OAAO;;CAGd,MAAM,QACJ,KACA,MACA,MACA,OACA,UACA,SAC8B;AAC9B,MAAI;GAEF,MAAM,MAAM,MAAM,KAAK,YACrB,KACA,MACA,MACA,OACA,UACA,QACD;AAED,OAAI,eAAe,MACjB,QAAO;YACE,OAAO,QAAQ,SACxB,QAAO,IAAI,MAAM,IAAI;YACZ,QAAQ,KACjB,QAAO;OAEP,QAAO;WAEF,KAAK;AACZ,OAAI,QAAQ,MACV,OAAM;OAEN,QAAO;;;;;;;;;CAWb,OAAO,MAA+B;AACpC,SAAO,KAAK,SAAS,KAAK;;CAG5B,YACE,KACA,MACA,MACA,OACA,UACA,SACyD;AAEzD,SAAO,KAAK,KAAK,KAAK,MAAM,MAAM,OAAO,UAAU,QAAQ;;;AAI/D,IAAa,YAAb,cACU,KAEV;CACE,AAAQ;CAER,YAAY,OAA+B;AACzC,QAAM,YAAY;AAElB,OAA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ACvB,KACA,MACA,MACA,OACA,UACA,QACD;AAED,MAAI,eAAe,MACjB,QAAO;WACE,QAAQ,KACjB,QAAO;OACF;AACL,OAAI,KAAK,MAAO,QAAO,KAAK;AAC5B,UAAO;;;;AAKb,IAAa,WAAb,cACU,UAEV;CACE,AAAS,OAAe;CAExB,AAAS;CAET,cAAc;AACZ,QAAM,EAAE,CAAC;;;;;;;CAQX,MAAe,UAAwC;AACrD,SAAO;;;AAIX,IAAa,YAAb,cACU,UAEV;CACE,AAAS,OAAe;CAExB,AAAS;CAET,cAAc;AACZ,QAAM,EAAE,CAAC;;;;;;;CAQX,MAAe,UAAwC;AACrD,SAAO"}
|
package/dist/shield/shield.cjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_shield_constructors = require('./constructors.cjs');
|
|
4
3
|
const require_shield_generator = require('./generator.cjs');
|
|
5
4
|
const require_shield_utils = require('./utils.cjs');
|
|
6
5
|
const require_shield_validation = require('./validation.cjs');
|
|
7
6
|
|
|
8
7
|
//#region src/shield/shield.ts
|
|
9
|
-
var shield_exports = /* @__PURE__ */ require_runtime.__exportAll({ shield: () => shield });
|
|
10
8
|
/**
|
|
11
9
|
* Makes sure all of defined rules are in accord with the options
|
|
12
10
|
* shield can process.
|
|
@@ -31,10 +29,4 @@ function shield(ruleTree, options = {}) {
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
//#endregion
|
|
34
|
-
exports.shield = shield;
|
|
35
|
-
Object.defineProperty(exports, 'shield_exports', {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () {
|
|
38
|
-
return shield_exports;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
32
|
+
exports.shield = shield;
|
package/dist/shield/shield.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
1
|
import { allow } from "./constructors.mjs";
|
|
3
2
|
import { generateMiddlewareFromRuleTree } from "./generator.mjs";
|
|
4
3
|
import { withDefault } from "./utils.mjs";
|
|
5
4
|
import { ValidationError, validateRuleTree } from "./validation.mjs";
|
|
6
5
|
|
|
7
6
|
//#region src/shield/shield.ts
|
|
8
|
-
var shield_exports = /* @__PURE__ */ __exportAll({ shield: () => shield });
|
|
9
7
|
/**
|
|
10
8
|
* Makes sure all of defined rules are in accord with the options
|
|
11
9
|
* shield can process.
|
|
@@ -30,5 +28,5 @@ function shield(ruleTree, options = {}) {
|
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
//#endregion
|
|
33
|
-
export { shield
|
|
31
|
+
export { shield };
|
|
34
32
|
//# sourceMappingURL=shield.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shield.mjs","names":[],"sources":["../../src/shield/shield.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { MiddlewareFunction } from \"@trpc/server/unstable-core-do-not-import\";\nimport { allow } from \"./constructors\";\nimport { generateMiddlewareFromRuleTree } from \"./generator\";\nimport type {\n IFallbackErrorType,\n IRules,\n OptionsConstructorInterface,\n OptionsInterface,\n ShieldRule\n} from \"./types\";\nimport { withDefault } from \"./utils\";\nimport { ValidationError, validateRuleTree } from \"./validation\";\n\n/**\n * Makes sure all of defined rules are in accord with the options\n * shield can process.\n */\nfunction normalizeOptions<TContext extends Record<string, any>>(\n options: OptionsConstructorInterface<TContext>\n): OptionsInterface<TContext> {\n if (typeof options.fallbackError === \"string\") {\n options.fallbackError = new Error(options.fallbackError);\n }\n\n return {\n debug: options.debug ?? false,\n allowExternalErrors: withDefault(false)(options.allowExternalErrors),\n fallbackRule: withDefault<ShieldRule<TContext>>(\n allow as ShieldRule<TContext>\n )(options.fallbackRule),\n fallbackError: withDefault<IFallbackErrorType<TContext>>(\n new Error(\"Authorization error\")\n )(options.fallbackError)\n };\n}\n\n/**\n * Validates rules and generates middleware from defined rule tree.\n */\nexport function shield<\n TContext extends Record<string, any>,\n TMeta extends object = object\n>(\n ruleTree: IRules<TContext>,\n options: OptionsConstructorInterface<TContext> = {}\n): MiddlewareFunction<TContext, TMeta, TContext, TContext, unknown> {\n const normalizedOptions = normalizeOptions<TContext>(options);\n const ruleTreeValidity = validateRuleTree<TContext>(ruleTree);\n\n if (ruleTreeValidity.status === \"ok\") {\n return generateMiddlewareFromRuleTree<TContext>(\n ruleTree,\n normalizedOptions\n ) as any;\n } else {\n throw new ValidationError(ruleTreeValidity.message);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"shield.mjs","names":[],"sources":["../../src/shield/shield.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { MiddlewareFunction } from \"@trpc/server/unstable-core-do-not-import\";\nimport { allow } from \"./constructors\";\nimport { generateMiddlewareFromRuleTree } from \"./generator\";\nimport type {\n IFallbackErrorType,\n IRules,\n OptionsConstructorInterface,\n OptionsInterface,\n ShieldRule\n} from \"./types\";\nimport { withDefault } from \"./utils\";\nimport { ValidationError, validateRuleTree } from \"./validation\";\n\n/**\n * Makes sure all of defined rules are in accord with the options\n * shield can process.\n */\nfunction normalizeOptions<TContext extends Record<string, any>>(\n options: OptionsConstructorInterface<TContext>\n): OptionsInterface<TContext> {\n if (typeof options.fallbackError === \"string\") {\n options.fallbackError = new Error(options.fallbackError);\n }\n\n return {\n debug: options.debug ?? false,\n allowExternalErrors: withDefault(false)(options.allowExternalErrors),\n fallbackRule: withDefault<ShieldRule<TContext>>(\n allow as ShieldRule<TContext>\n )(options.fallbackRule),\n fallbackError: withDefault<IFallbackErrorType<TContext>>(\n new Error(\"Authorization error\")\n )(options.fallbackError)\n };\n}\n\n/**\n * Validates rules and generates middleware from defined rule tree.\n */\nexport function shield<\n TContext extends Record<string, any>,\n TMeta extends object = object\n>(\n ruleTree: IRules<TContext>,\n options: OptionsConstructorInterface<TContext> = {}\n): MiddlewareFunction<TContext, TMeta, TContext, TContext, unknown> {\n const normalizedOptions = normalizeOptions<TContext>(options);\n const ruleTreeValidity = validateRuleTree<TContext>(ruleTree);\n\n if (ruleTreeValidity.status === \"ok\") {\n return generateMiddlewareFromRuleTree<TContext>(\n ruleTree,\n normalizedOptions\n ) as any;\n } else {\n throw new ValidationError(ruleTreeValidity.message);\n }\n}\n"],"mappings":";;;;;;;;;;AAmCA,SAAS,iBACP,SAC4B;AAC5B,KAAI,OAAO,QAAQ,kBAAkB,SACnC,SAAQ,gBAAgB,IAAI,MAAM,QAAQ,cAAc;AAG1D,QAAO;EACL,OAAO,QAAQ,SAAS;EACxB,qBAAqB,YAAY,MAAM,CAAC,QAAQ,oBAAoB;EACpE,cAAc,YACZ,MACD,CAAC,QAAQ,aAAa;EACvB,eAAe,4BACb,IAAI,MAAM,sBAAsB,CACjC,CAAC,QAAQ,cAAc;EACzB;;;;;AAMH,SAAgB,OAId,UACA,UAAiD,EAAE,EACe;CAClE,MAAM,oBAAoB,iBAA2B,QAAQ;CAC7D,MAAM,mBAAmB,iBAA2B,SAAS;AAE7D,KAAI,iBAAiB,WAAW,KAC9B,QAAO,+BACL,UACA,kBACD;KAED,OAAM,IAAI,gBAAgB,iBAAiB,QAAQ"}
|
package/dist/shield/types.cjs
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/shield/types.ts
|
|
5
|
-
var types_exports = /* @__PURE__ */ require_runtime.__exportAll({});
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
Object.defineProperty(exports, 'types_exports', {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return types_exports;
|
|
12
|
-
}
|
|
13
|
-
});
|
package/dist/shield/types.mjs
CHANGED
package/dist/shield/utils.cjs
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_shield_rules = require('./rules.cjs');
|
|
4
3
|
|
|
5
4
|
//#region src/shield/utils.ts
|
|
6
|
-
var utils_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
7
|
-
flattenObjectOf: () => flattenObjectOf,
|
|
8
|
-
isLogicRule: () => isLogicRule,
|
|
9
|
-
isRule: () => isRule,
|
|
10
|
-
isRuleFieldMap: () => isRuleFieldMap,
|
|
11
|
-
isRuleFunction: () => isRuleFunction,
|
|
12
|
-
withDefault: () => withDefault
|
|
13
|
-
});
|
|
14
5
|
/**
|
|
15
6
|
* Makes sure that a certain field is a rule.
|
|
16
7
|
*/
|
|
@@ -63,10 +54,4 @@ exports.isLogicRule = isLogicRule;
|
|
|
63
54
|
exports.isRule = isRule;
|
|
64
55
|
exports.isRuleFieldMap = isRuleFieldMap;
|
|
65
56
|
exports.isRuleFunction = isRuleFunction;
|
|
66
|
-
Object.defineProperty(exports, 'utils_exports', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return utils_exports;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
57
|
exports.withDefault = withDefault;
|
package/dist/shield/utils.mjs
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
1
|
import { LogicRule, Rule } from "./rules.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/shield/utils.ts
|
|
5
|
-
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
-
flattenObjectOf: () => flattenObjectOf,
|
|
7
|
-
isLogicRule: () => isLogicRule,
|
|
8
|
-
isRule: () => isRule,
|
|
9
|
-
isRuleFieldMap: () => isRuleFieldMap,
|
|
10
|
-
isRuleFunction: () => isRuleFunction,
|
|
11
|
-
withDefault: () => withDefault
|
|
12
|
-
});
|
|
13
4
|
/**
|
|
14
5
|
* Makes sure that a certain field is a rule.
|
|
15
6
|
*/
|
|
@@ -57,5 +48,5 @@ function withDefault(fallback) {
|
|
|
57
48
|
}
|
|
58
49
|
|
|
59
50
|
//#endregion
|
|
60
|
-
export { flattenObjectOf, isLogicRule, isRule, isRuleFieldMap, isRuleFunction,
|
|
51
|
+
export { flattenObjectOf, isLogicRule, isRule, isRuleFieldMap, isRuleFunction, withDefault };
|
|
61
52
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/shield/utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogicRule, Rule } from \"./rules\";\nimport type {\n LogicRuleInterface,\n RuleFieldMapInterface,\n RuleInterface,\n ShieldRule\n} from \"./types\";\n\n/**\n * Makes sure that a certain field is a rule.\n */\nexport function isRule<TContext extends Record<string, any>>(\n x: any\n): x is RuleInterface<TContext> {\n return (\n x instanceof Rule || (x && x.constructor && x.constructor.name === \"Rule\")\n );\n}\n\n/**\n * Makes sure that a certain field is a logic rule.\n */\nexport function isLogicRule<TContext extends Record<string, any>>(\n x: any\n): x is LogicRuleInterface<TContext> {\n return (\n x instanceof LogicRule ||\n (x &&\n x.constructor &&\n (x.constructor.name === \"RuleOr\" ||\n x.constructor.name === \"RuleAnd\" ||\n x.constructor.name === \"RuleChain\" ||\n x.constructor.name === \"RuleRace\" ||\n x.constructor.name === \"RuleNot\" ||\n x.constructor.name === \"RuleTrue\" ||\n x.constructor.name === \"RuleFalse\"))\n );\n}\n\n/**\n * Makes sure that a certain field is a rule or a logic rule.\n */\nexport function isRuleFunction<TContext extends Record<string, any>>(\n x: any\n): x is ShieldRule<TContext> {\n return isRule(x) || isLogicRule(x);\n}\n\n/**\n * Determines whether a certain field is rule field map or not.\n */\nexport function isRuleFieldMap<TContext extends Record<string, any>>(\n x: any\n): x is RuleFieldMapInterface<TContext> {\n return (\n typeof x === \"object\" &&\n Object.values(x).every(rule => isRuleFunction(rule))\n );\n}\n\n/**\n * Flattens object of particular type by checking if the leaf\n * evaluates to true from particular function.\n */\nexport function flattenObjectOf<T>(\n obj: { [key: string]: any },\n f: (x: any) => boolean\n): T[] {\n const values = Object.keys(obj).reduce<T[]>((acc, key) => {\n const val = obj[key];\n if (f(val)) {\n return [...acc, val];\n } else if (typeof val === \"object\" && !f(val)) {\n return [...acc, ...flattenObjectOf(val, f)];\n } else {\n return acc;\n }\n }, []);\n\n return values;\n}\n\n/**\n * Returns fallback is provided value is undefined\n */\nexport function withDefault<T>(fallback: T): (value: T | undefined) => T {\n return value => {\n if (value === undefined) return fallback;\n return value;\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/shield/utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogicRule, Rule } from \"./rules\";\nimport type {\n LogicRuleInterface,\n RuleFieldMapInterface,\n RuleInterface,\n ShieldRule\n} from \"./types\";\n\n/**\n * Makes sure that a certain field is a rule.\n */\nexport function isRule<TContext extends Record<string, any>>(\n x: any\n): x is RuleInterface<TContext> {\n return (\n x instanceof Rule || (x && x.constructor && x.constructor.name === \"Rule\")\n );\n}\n\n/**\n * Makes sure that a certain field is a logic rule.\n */\nexport function isLogicRule<TContext extends Record<string, any>>(\n x: any\n): x is LogicRuleInterface<TContext> {\n return (\n x instanceof LogicRule ||\n (x &&\n x.constructor &&\n (x.constructor.name === \"RuleOr\" ||\n x.constructor.name === \"RuleAnd\" ||\n x.constructor.name === \"RuleChain\" ||\n x.constructor.name === \"RuleRace\" ||\n x.constructor.name === \"RuleNot\" ||\n x.constructor.name === \"RuleTrue\" ||\n x.constructor.name === \"RuleFalse\"))\n );\n}\n\n/**\n * Makes sure that a certain field is a rule or a logic rule.\n */\nexport function isRuleFunction<TContext extends Record<string, any>>(\n x: any\n): x is ShieldRule<TContext> {\n return isRule(x) || isLogicRule(x);\n}\n\n/**\n * Determines whether a certain field is rule field map or not.\n */\nexport function isRuleFieldMap<TContext extends Record<string, any>>(\n x: any\n): x is RuleFieldMapInterface<TContext> {\n return (\n typeof x === \"object\" &&\n Object.values(x).every(rule => isRuleFunction(rule))\n );\n}\n\n/**\n * Flattens object of particular type by checking if the leaf\n * evaluates to true from particular function.\n */\nexport function flattenObjectOf<T>(\n obj: { [key: string]: any },\n f: (x: any) => boolean\n): T[] {\n const values = Object.keys(obj).reduce<T[]>((acc, key) => {\n const val = obj[key];\n if (f(val)) {\n return [...acc, val];\n } else if (typeof val === \"object\" && !f(val)) {\n return [...acc, ...flattenObjectOf(val, f)];\n } else {\n return acc;\n }\n }, []);\n\n return values;\n}\n\n/**\n * Returns fallback is provided value is undefined\n */\nexport function withDefault<T>(fallback: T): (value: T | undefined) => T {\n return value => {\n if (value === undefined) return fallback;\n return value;\n };\n}\n"],"mappings":";;;;;;AA6BA,SAAgB,OACd,GAC8B;AAC9B,QACE,aAAa,QAAS,KAAK,EAAE,eAAe,EAAE,YAAY,SAAS;;;;;AAOvE,SAAgB,YACd,GACmC;AACnC,QACE,aAAa,aACZ,KACC,EAAE,gBACD,EAAE,YAAY,SAAS,YACtB,EAAE,YAAY,SAAS,aACvB,EAAE,YAAY,SAAS,eACvB,EAAE,YAAY,SAAS,cACvB,EAAE,YAAY,SAAS,aACvB,EAAE,YAAY,SAAS,cACvB,EAAE,YAAY,SAAS;;;;;AAO/B,SAAgB,eACd,GAC2B;AAC3B,QAAO,OAAO,EAAE,IAAI,YAAY,EAAE;;;;;AAMpC,SAAgB,eACd,GACsC;AACtC,QACE,OAAO,MAAM,YACb,OAAO,OAAO,EAAE,CAAC,OAAM,SAAQ,eAAe,KAAK,CAAC;;;;;;AAQxD,SAAgB,gBACd,KACA,GACK;AAYL,QAXe,OAAO,KAAK,IAAI,CAAC,QAAa,KAAK,QAAQ;EACxD,MAAM,MAAM,IAAI;AAChB,MAAI,EAAE,IAAI,CACR,QAAO,CAAC,GAAG,KAAK,IAAI;WACX,OAAO,QAAQ,YAAY,CAAC,EAAE,IAAI,CAC3C,QAAO,CAAC,GAAG,KAAK,GAAG,gBAAgB,KAAK,EAAE,CAAC;MAE3C,QAAO;IAER,EAAE,CAEQ;;;;;AAMf,SAAgB,YAAe,UAA0C;AACvE,SAAO,UAAS;AACd,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_shield_utils = require('./utils.cjs');
|
|
4
3
|
|
|
5
4
|
//#region src/shield/validation.ts
|
|
6
|
-
var validation_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
7
|
-
ValidationError: () => ValidationError,
|
|
8
|
-
validateRuleTree: () => validateRuleTree
|
|
9
|
-
});
|
|
10
5
|
/**
|
|
11
6
|
* Validates the rule tree declaration by checking references of rule
|
|
12
7
|
* functions. We deem rule tree valid if no two rules with the same name point
|
|
@@ -62,10 +57,4 @@ var ValidationError = class extends Error {
|
|
|
62
57
|
|
|
63
58
|
//#endregion
|
|
64
59
|
exports.ValidationError = ValidationError;
|
|
65
|
-
exports.validateRuleTree = validateRuleTree;
|
|
66
|
-
Object.defineProperty(exports, 'validation_exports', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return validation_exports;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
60
|
+
exports.validateRuleTree = validateRuleTree;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
1
|
import { flattenObjectOf, isLogicRule, isRuleFunction } from "./utils.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/shield/validation.ts
|
|
5
|
-
var validation_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
-
ValidationError: () => ValidationError,
|
|
7
|
-
validateRuleTree: () => validateRuleTree
|
|
8
|
-
});
|
|
9
4
|
/**
|
|
10
5
|
* Validates the rule tree declaration by checking references of rule
|
|
11
6
|
* functions. We deem rule tree valid if no two rules with the same name point
|
|
@@ -60,5 +55,5 @@ var ValidationError = class extends Error {
|
|
|
60
55
|
};
|
|
61
56
|
|
|
62
57
|
//#endregion
|
|
63
|
-
export { ValidationError, validateRuleTree
|
|
58
|
+
export { ValidationError, validateRuleTree };
|
|
64
59
|
//# sourceMappingURL=validation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.mjs","names":[],"sources":["../../src/shield/validation.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n IRules,\n LogicRuleInterface,\n RuleInterface,\n ShieldRule\n} from \"./types\";\nimport { flattenObjectOf, isLogicRule, isRuleFunction } from \"./utils\";\n\n/**\n * Validates the rule tree declaration by checking references of rule\n * functions. We deem rule tree valid if no two rules with the same name point\n * to different rules.\n */\nexport function validateRuleTree<TContext extends Record<string, any>>(\n ruleTree: IRules<TContext>\n): { status: \"ok\" } | { status: \"err\"; message: string } {\n const rules = extractRules(ruleTree);\n\n const valid = rules.reduce<{\n map: Map<string, RuleInterface<TContext>>;\n duplicates: string[];\n }>(\n ({ map, duplicates }, rule) => {\n if (!map.has(rule.name)) {\n return { map: map.set(rule.name, rule), duplicates };\n } else if (\n !map.get(rule.name)!.equals(rule) &&\n !duplicates.includes(rule.name)\n ) {\n return {\n map: map.set(rule.name, rule),\n duplicates: [...duplicates, rule.name]\n };\n } else {\n return { map, duplicates };\n }\n },\n { map: new Map<string, RuleInterface<TContext>>(), duplicates: [] }\n );\n\n if (valid.duplicates.length === 0) {\n return { status: \"ok\" };\n } else {\n const duplicates = valid.duplicates.join(\", \");\n\n return {\n status: \"err\",\n message: `There seem to be multiple definitions of these rules: ${duplicates}`\n };\n }\n\n /**\n * Extracts rules from rule tree.\n */\n function extractRules<TContext extends Record<string, any>>(\n ruleTree: IRules<TContext>\n ): RuleInterface<TContext>[] {\n const resolvers = flattenObjectOf<ShieldRule<TContext>>(\n ruleTree,\n isRuleFunction\n );\n\n const rules = resolvers.reduce<RuleInterface<TContext>[]>((rules, rule) => {\n if (isLogicRule(rule)) {\n return [\n ...rules,\n ...extractLogicRules(rule)\n ] as RuleInterface<TContext>[];\n } else {\n return [...rules, rule] as RuleInterface<TContext>[];\n }\n }, []);\n\n return rules;\n }\n\n /**\n * Recursively extracts Rules from LogicRule\n */\n function extractLogicRules<TContext extends Record<string, any>>(\n rule: LogicRuleInterface<TContext>\n ): RuleInterface<TContext>[] {\n return rule\n .getRules()\n .reduce<RuleInterface<TContext>[]>((acc, shieldRule) => {\n if (isLogicRule(shieldRule)) {\n return [\n ...acc,\n ...extractLogicRules(shieldRule)\n ] as RuleInterface<TContext>[];\n } else {\n return [...acc, shieldRule] as RuleInterface<TContext>[];\n }\n }, []);\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.mjs","names":[],"sources":["../../src/shield/validation.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n IRules,\n LogicRuleInterface,\n RuleInterface,\n ShieldRule\n} from \"./types\";\nimport { flattenObjectOf, isLogicRule, isRuleFunction } from \"./utils\";\n\n/**\n * Validates the rule tree declaration by checking references of rule\n * functions. We deem rule tree valid if no two rules with the same name point\n * to different rules.\n */\nexport function validateRuleTree<TContext extends Record<string, any>>(\n ruleTree: IRules<TContext>\n): { status: \"ok\" } | { status: \"err\"; message: string } {\n const rules = extractRules(ruleTree);\n\n const valid = rules.reduce<{\n map: Map<string, RuleInterface<TContext>>;\n duplicates: string[];\n }>(\n ({ map, duplicates }, rule) => {\n if (!map.has(rule.name)) {\n return { map: map.set(rule.name, rule), duplicates };\n } else if (\n !map.get(rule.name)!.equals(rule) &&\n !duplicates.includes(rule.name)\n ) {\n return {\n map: map.set(rule.name, rule),\n duplicates: [...duplicates, rule.name]\n };\n } else {\n return { map, duplicates };\n }\n },\n { map: new Map<string, RuleInterface<TContext>>(), duplicates: [] }\n );\n\n if (valid.duplicates.length === 0) {\n return { status: \"ok\" };\n } else {\n const duplicates = valid.duplicates.join(\", \");\n\n return {\n status: \"err\",\n message: `There seem to be multiple definitions of these rules: ${duplicates}`\n };\n }\n\n /**\n * Extracts rules from rule tree.\n */\n function extractRules<TContext extends Record<string, any>>(\n ruleTree: IRules<TContext>\n ): RuleInterface<TContext>[] {\n const resolvers = flattenObjectOf<ShieldRule<TContext>>(\n ruleTree,\n isRuleFunction\n );\n\n const rules = resolvers.reduce<RuleInterface<TContext>[]>((rules, rule) => {\n if (isLogicRule(rule)) {\n return [\n ...rules,\n ...extractLogicRules(rule)\n ] as RuleInterface<TContext>[];\n } else {\n return [...rules, rule] as RuleInterface<TContext>[];\n }\n }, []);\n\n return rules;\n }\n\n /**\n * Recursively extracts Rules from LogicRule\n */\n function extractLogicRules<TContext extends Record<string, any>>(\n rule: LogicRuleInterface<TContext>\n ): RuleInterface<TContext>[] {\n return rule\n .getRules()\n .reduce<RuleInterface<TContext>[]>((acc, shieldRule) => {\n if (isLogicRule(shieldRule)) {\n return [\n ...acc,\n ...extractLogicRules(shieldRule)\n ] as RuleInterface<TContext>[];\n } else {\n return [...acc, shieldRule] as RuleInterface<TContext>[];\n }\n }, []);\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n"],"mappings":";;;;;;;;AA+BA,SAAgB,iBACd,UACuD;CAGvD,MAAM,QAFQ,aAAa,SAER,CAAC,QAIjB,EAAE,KAAK,cAAc,SAAS;AAC7B,MAAI,CAAC,IAAI,IAAI,KAAK,KAAK,CACrB,QAAO;GAAE,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK;GAAE;GAAY;WAEpD,CAAC,IAAI,IAAI,KAAK,KAAK,CAAE,OAAO,KAAK,IACjC,CAAC,WAAW,SAAS,KAAK,KAAK,CAE/B,QAAO;GACL,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK;GAC7B,YAAY,CAAC,GAAG,YAAY,KAAK,KAAK;GACvC;MAED,QAAO;GAAE;GAAK;GAAY;IAG9B;EAAE,qBAAK,IAAI,KAAsC;EAAE,YAAY,EAAE;EAAE,CACpE;AAED,KAAI,MAAM,WAAW,WAAW,EAC9B,QAAO,EAAE,QAAQ,MAAM;KAIvB,QAAO;EACL,QAAQ;EACR,SAAS,yDAJQ,MAAM,WAAW,KAAK,KAIqC;EAC7E;;;;CAMH,SAAS,aACP,UAC2B;AAiB3B,SAhBkB,gBAChB,UACA,eAGqB,CAAC,QAAmC,OAAO,SAAS;AACzE,OAAI,YAAY,KAAK,CACnB,QAAO,CACL,GAAG,OACH,GAAG,kBAAkB,KAAK,CAC3B;OAED,QAAO,CAAC,GAAG,OAAO,KAAK;KAExB,EAAE,CAEO;;;;;CAMd,SAAS,kBACP,MAC2B;AAC3B,SAAO,KACJ,UAAU,CACV,QAAmC,KAAK,eAAe;AACtD,OAAI,YAAY,WAAW,CACzB,QAAO,CACL,GAAG,KACH,GAAG,kBAAkB,WAAW,CACjC;OAED,QAAO,CAAC,GAAG,KAAK,WAAW;KAE5B,EAAE,CAAC;;;AAIZ,IAAa,kBAAb,cAAqC,MAAM;CACzC,YAAY,SAAiB;AAC3B,QAAM,QAAQ"}
|
package/dist/types.cjs
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/types.ts
|
|
5
|
-
var types_exports = /* @__PURE__ */ require_runtime.__exportAll({});
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
Object.defineProperty(exports, 'types_exports', {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return types_exports;
|
|
12
|
-
}
|
|
13
|
-
});
|
package/dist/types.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/trpc-next",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.100",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package to help in using tRPC in modern NextJs applications.",
|
|
6
6
|
"repository": {
|
|
@@ -15,38 +15,18 @@
|
|
|
15
15
|
"import": "./dist/action-handler.mjs",
|
|
16
16
|
"require": "./dist/action-handler.cjs"
|
|
17
17
|
},
|
|
18
|
-
"./action-handler.test": {
|
|
19
|
-
"import": "./dist/action-handler.test.mjs",
|
|
20
|
-
"require": "./dist/action-handler.test.cjs"
|
|
21
|
-
},
|
|
22
18
|
"./client": {
|
|
23
19
|
"import": "./dist/client.mjs",
|
|
24
20
|
"require": "./dist/client.cjs"
|
|
25
21
|
},
|
|
26
|
-
"./client.test": {
|
|
27
|
-
"import": "./dist/client.test.mjs",
|
|
28
|
-
"require": "./dist/client.test.cjs"
|
|
29
|
-
},
|
|
30
|
-
"./index.test": {
|
|
31
|
-
"import": "./dist/index.test.mjs",
|
|
32
|
-
"require": "./dist/index.test.cjs"
|
|
33
|
-
},
|
|
34
22
|
"./server": {
|
|
35
23
|
"import": "./dist/server.mjs",
|
|
36
24
|
"require": "./dist/server.cjs"
|
|
37
25
|
},
|
|
38
|
-
"./server.test": {
|
|
39
|
-
"import": "./dist/server.test.mjs",
|
|
40
|
-
"require": "./dist/server.test.cjs"
|
|
41
|
-
},
|
|
42
26
|
"./shared": {
|
|
43
27
|
"import": "./dist/shared.mjs",
|
|
44
28
|
"require": "./dist/shared.cjs"
|
|
45
29
|
},
|
|
46
|
-
"./shared.test": {
|
|
47
|
-
"import": "./dist/shared.test.mjs",
|
|
48
|
-
"require": "./dist/shared.test.cjs"
|
|
49
|
-
},
|
|
50
30
|
"./shield": {
|
|
51
31
|
"import": "./dist/shield/index.mjs",
|
|
52
32
|
"require": "./dist/shield/index.cjs"
|
|
@@ -55,62 +35,30 @@
|
|
|
55
35
|
"import": "./dist/shield/constructors.mjs",
|
|
56
36
|
"require": "./dist/shield/constructors.cjs"
|
|
57
37
|
},
|
|
58
|
-
"./shield/constructors.test": {
|
|
59
|
-
"import": "./dist/shield/constructors.test.mjs",
|
|
60
|
-
"require": "./dist/shield/constructors.test.cjs"
|
|
61
|
-
},
|
|
62
38
|
"./shield/generator": {
|
|
63
39
|
"import": "./dist/shield/generator.mjs",
|
|
64
40
|
"require": "./dist/shield/generator.cjs"
|
|
65
41
|
},
|
|
66
|
-
"./shield/generator.test": {
|
|
67
|
-
"import": "./dist/shield/generator.test.mjs",
|
|
68
|
-
"require": "./dist/shield/generator.test.cjs"
|
|
69
|
-
},
|
|
70
|
-
"./shield/index.test": {
|
|
71
|
-
"import": "./dist/shield/index.test.mjs",
|
|
72
|
-
"require": "./dist/shield/index.test.cjs"
|
|
73
|
-
},
|
|
74
42
|
"./shield/rules": {
|
|
75
43
|
"import": "./dist/shield/rules.mjs",
|
|
76
44
|
"require": "./dist/shield/rules.cjs"
|
|
77
45
|
},
|
|
78
|
-
"./shield/rules.test": {
|
|
79
|
-
"import": "./dist/shield/rules.test.mjs",
|
|
80
|
-
"require": "./dist/shield/rules.test.cjs"
|
|
81
|
-
},
|
|
82
46
|
"./shield/shield": {
|
|
83
47
|
"import": "./dist/shield/shield.mjs",
|
|
84
48
|
"require": "./dist/shield/shield.cjs"
|
|
85
49
|
},
|
|
86
|
-
"./shield/shield.test": {
|
|
87
|
-
"import": "./dist/shield/shield.test.mjs",
|
|
88
|
-
"require": "./dist/shield/shield.test.cjs"
|
|
89
|
-
},
|
|
90
50
|
"./shield/types": {
|
|
91
51
|
"import": "./dist/shield/types.mjs",
|
|
92
52
|
"require": "./dist/shield/types.cjs"
|
|
93
53
|
},
|
|
94
|
-
"./shield/types.test": {
|
|
95
|
-
"import": "./dist/shield/types.test.mjs",
|
|
96
|
-
"require": "./dist/shield/types.test.cjs"
|
|
97
|
-
},
|
|
98
54
|
"./shield/utils": {
|
|
99
55
|
"import": "./dist/shield/utils.mjs",
|
|
100
56
|
"require": "./dist/shield/utils.cjs"
|
|
101
57
|
},
|
|
102
|
-
"./shield/utils.test": {
|
|
103
|
-
"import": "./dist/shield/utils.test.mjs",
|
|
104
|
-
"require": "./dist/shield/utils.test.cjs"
|
|
105
|
-
},
|
|
106
58
|
"./shield/validation": {
|
|
107
59
|
"import": "./dist/shield/validation.mjs",
|
|
108
60
|
"require": "./dist/shield/validation.cjs"
|
|
109
61
|
},
|
|
110
|
-
"./shield/validation.test": {
|
|
111
|
-
"import": "./dist/shield/validation.test.mjs",
|
|
112
|
-
"require": "./dist/shield/validation.test.cjs"
|
|
113
|
-
},
|
|
114
62
|
"./tanstack-query/client": {
|
|
115
63
|
"import": "./dist/tanstack-query/client.mjs",
|
|
116
64
|
"require": "./dist/tanstack-query/client.cjs"
|
|
@@ -120,24 +68,20 @@
|
|
|
120
68
|
"require": "./dist/tanstack-query/server.cjs"
|
|
121
69
|
},
|
|
122
70
|
"./types": { "import": "./dist/types.mjs", "require": "./dist/types.cjs" },
|
|
123
|
-
"./
|
|
124
|
-
"import": "./dist/types.test.mjs",
|
|
125
|
-
"require": "./dist/types.test.cjs"
|
|
126
|
-
},
|
|
127
|
-
"./*": "./*"
|
|
71
|
+
"./package.json": "./package.json"
|
|
128
72
|
},
|
|
129
73
|
"main": "./dist/index.cjs",
|
|
130
74
|
"module": "./dist/index.mjs",
|
|
131
75
|
"types": "./dist/index.d.cts",
|
|
132
76
|
"dependencies": {
|
|
133
77
|
"@js-temporal/polyfill": "^0.5.1",
|
|
134
|
-
"@stryke/env": "^0.20.
|
|
135
|
-
"@stryke/fs": "^0.33.
|
|
136
|
-
"@stryke/path": "^0.29.
|
|
137
|
-
"@stryke/string-format": "^0.17.
|
|
138
|
-
"@stryke/type-checks": "^0.6.
|
|
139
|
-
"@stryke/types": "^0.12.
|
|
140
|
-
"@stryke/url": "^0.4.
|
|
78
|
+
"@stryke/env": "^0.20.98",
|
|
79
|
+
"@stryke/fs": "^0.33.81",
|
|
80
|
+
"@stryke/path": "^0.29.8",
|
|
81
|
+
"@stryke/string-format": "^0.17.23",
|
|
82
|
+
"@stryke/type-checks": "^0.6.14",
|
|
83
|
+
"@stryke/types": "^0.12.9",
|
|
84
|
+
"@stryke/url": "^0.4.32",
|
|
141
85
|
"@tanstack/react-query": "^5.100.14",
|
|
142
86
|
"@trpc/client": "^11.17.0",
|
|
143
87
|
"@trpc/next": "^11.17.0",
|
|
@@ -164,5 +108,5 @@
|
|
|
164
108
|
"react-native": { "optional": true }
|
|
165
109
|
},
|
|
166
110
|
"publishConfig": { "access": "public" },
|
|
167
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "166741e285a7112dfc6dd34206b43578dc4d19ec"
|
|
168
112
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __exportAll };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
const require_action_handler = require('./action-handler.cjs');
|
|
3
|
-
let vitest = require("vitest");
|
|
4
|
-
|
|
5
|
-
//#region src/action-handler.test.ts
|
|
6
|
-
(0, vitest.describe)("action-handler.ts exports", () => {
|
|
7
|
-
(0, vitest.it)("loads module exports", () => {
|
|
8
|
-
(0, vitest.expect)(require_action_handler.action_handler_exports).toBeDefined();
|
|
9
|
-
(0, vitest.expect)(typeof require_action_handler.action_handler_exports).toBe("object");
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { action_handler_exports } from "./action-handler.mjs";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
//#region src/action-handler.test.ts
|
|
5
|
-
describe("action-handler.ts exports", () => {
|
|
6
|
-
it("loads module exports", () => {
|
|
7
|
-
expect(action_handler_exports).toBeDefined();
|
|
8
|
-
expect(typeof action_handler_exports).toBe("object");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//# sourceMappingURL=action-handler.test.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action-handler.test.mjs","names":["moduleExports"],"sources":["../src/action-handler.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./action-handler.ts\";\n\ndescribe(\"action-handler.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,mCAAmC;AAC1C,IAAG,8BAA8B;AAC/B,SAAOA,uBAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,uBAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
|
package/dist/client.test.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
const require_client = require('./client.cjs');
|
|
3
|
-
let vitest = require("vitest");
|
|
4
|
-
|
|
5
|
-
//#region src/client.test.ts
|
|
6
|
-
(0, vitest.describe)("client.ts exports", () => {
|
|
7
|
-
(0, vitest.it)("loads module exports", () => {
|
|
8
|
-
(0, vitest.expect)(require_client.client_exports).toBeDefined();
|
|
9
|
-
(0, vitest.expect)(typeof require_client.client_exports).toBe("object");
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
//#endregion
|
package/dist/client.test.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/client.test.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/client.test.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { client_exports } from "./client.mjs";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
//#region src/client.test.ts
|
|
5
|
-
describe("client.ts exports", () => {
|
|
6
|
-
it("loads module exports", () => {
|
|
7
|
-
expect(client_exports).toBeDefined();
|
|
8
|
-
expect(typeof client_exports).toBe("object");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//# sourceMappingURL=client.test.mjs.map
|
package/dist/client.test.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.mjs","names":["moduleExports"],"sources":["../src/client.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./client.ts\";\n\ndescribe(\"client.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,2BAA2B;AAClC,IAAG,8BAA8B;AAC/B,SAAOA,eAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,eAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * The trpc-next library used by Storm Software for building TypeScript applications.\n *\n * @remarks\n * A package to help in using tRPC in modern NextJs applications\n *\n * @packageDocumentation\n */\n\nexport * from \"./action-handler\";\nexport * from \"./client\";\nexport * from \"./server\";\nexport * from \"./shared\";\nexport * from \"./tanstack-query/client\";\nexport * from \"./tanstack-query/server\";\nexport * from \"./types\";\n"],"mappings":""}
|
package/dist/index.test.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
const require_index = require('./index.cjs');
|
|
3
|
-
let vitest = require("vitest");
|
|
4
|
-
|
|
5
|
-
//#region src/index.test.ts
|
|
6
|
-
(0, vitest.describe)("index.ts exports", () => {
|
|
7
|
-
(0, vitest.it)("loads module exports", () => {
|
|
8
|
-
(0, vitest.expect)(require_index.src_exports).toBeDefined();
|
|
9
|
-
(0, vitest.expect)(typeof require_index.src_exports).toBe("object");
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
//#endregion
|
package/dist/index.test.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/index.test.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/index.test.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { src_exports } from "./index.mjs";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
//#region src/index.test.ts
|
|
5
|
-
describe("index.ts exports", () => {
|
|
6
|
-
it("loads module exports", () => {
|
|
7
|
-
expect(src_exports).toBeDefined();
|
|
8
|
-
expect(typeof src_exports).toBe("object");
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//# sourceMappingURL=index.test.mjs.map
|
package/dist/index.test.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.mjs","names":["moduleExports"],"sources":["../src/index.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./index.ts\";\n\ndescribe(\"index.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,0BAA0B;AACjC,IAAG,8BAA8B;AAC/B,SAAOA,YAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,YAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
|