@stryke/trpc-next 0.5.98 → 0.5.99

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +14 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +18 -0
  4. package/dist/action-handler.cjs +7 -0
  5. package/dist/action-handler.mjs +3 -1
  6. package/dist/action-handler.mjs.map +1 -1
  7. package/dist/action-handler.test.cjs +13 -0
  8. package/dist/action-handler.test.d.cts +1 -0
  9. package/dist/action-handler.test.d.mts +1 -0
  10. package/dist/action-handler.test.mjs +13 -0
  11. package/dist/action-handler.test.mjs.map +1 -0
  12. package/dist/client.cjs +10 -0
  13. package/dist/client.mjs +6 -1
  14. package/dist/client.mjs.map +1 -1
  15. package/dist/client.test.cjs +13 -0
  16. package/dist/client.test.d.cts +1 -0
  17. package/dist/client.test.d.mts +1 -0
  18. package/dist/client.test.mjs +13 -0
  19. package/dist/client.test.mjs.map +1 -0
  20. package/dist/index.cjs +22 -0
  21. package/dist/index.mjs +19 -1
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/index.test.cjs +13 -0
  24. package/dist/index.test.d.cts +1 -0
  25. package/dist/index.test.d.mts +1 -0
  26. package/dist/index.test.mjs +13 -0
  27. package/dist/index.test.mjs.map +1 -0
  28. package/dist/server.cjs +11 -0
  29. package/dist/server.mjs +7 -1
  30. package/dist/server.mjs.map +1 -1
  31. package/dist/server.test.cjs +13 -0
  32. package/dist/server.test.d.cts +1 -0
  33. package/dist/server.test.d.mts +1 -0
  34. package/dist/server.test.mjs +13 -0
  35. package/dist/server.test.mjs.map +1 -0
  36. package/dist/shared.cjs +11 -0
  37. package/dist/shared.mjs +7 -1
  38. package/dist/shared.mjs.map +1 -1
  39. package/dist/shared.test.cjs +13 -0
  40. package/dist/shared.test.d.cts +1 -0
  41. package/dist/shared.test.d.mts +1 -0
  42. package/dist/shared.test.mjs +13 -0
  43. package/dist/shared.test.mjs.map +1 -0
  44. package/dist/shield/constructors.cjs +17 -0
  45. package/dist/shield/constructors.mjs +12 -1
  46. package/dist/shield/constructors.mjs.map +1 -1
  47. package/dist/shield/constructors.test.cjs +13 -0
  48. package/dist/shield/constructors.test.d.cts +1 -0
  49. package/dist/shield/constructors.test.d.mts +1 -0
  50. package/dist/shield/constructors.test.mjs +13 -0
  51. package/dist/shield/constructors.test.mjs.map +1 -0
  52. package/dist/shield/generator.cjs +9 -1
  53. package/dist/shield/generator.mjs +4 -1
  54. package/dist/shield/generator.mjs.map +1 -1
  55. package/dist/shield/generator.test.cjs +13 -0
  56. package/dist/shield/generator.test.d.cts +1 -0
  57. package/dist/shield/generator.test.d.mts +1 -0
  58. package/dist/shield/generator.test.mjs +13 -0
  59. package/dist/shield/generator.test.mjs.map +1 -0
  60. package/dist/shield/index.cjs +22 -1
  61. package/dist/shield/index.mjs +17 -1
  62. package/dist/shield/index.mjs.map +1 -0
  63. package/dist/shield/index.test.cjs +13 -0
  64. package/dist/shield/index.test.d.cts +1 -0
  65. package/dist/shield/index.test.d.mts +1 -0
  66. package/dist/shield/index.test.mjs +13 -0
  67. package/dist/shield/index.test.mjs.map +1 -0
  68. package/dist/shield/rules.cjs +19 -1
  69. package/dist/shield/rules.mjs +14 -1
  70. package/dist/shield/rules.mjs.map +1 -1
  71. package/dist/shield/rules.test.cjs +13 -0
  72. package/dist/shield/rules.test.d.cts +1 -0
  73. package/dist/shield/rules.test.d.mts +1 -0
  74. package/dist/shield/rules.test.mjs +13 -0
  75. package/dist/shield/rules.test.mjs.map +1 -0
  76. package/dist/shield/shield.cjs +9 -1
  77. package/dist/shield/shield.mjs +3 -1
  78. package/dist/shield/shield.mjs.map +1 -1
  79. package/dist/shield/shield.test.cjs +13 -0
  80. package/dist/shield/shield.test.d.cts +1 -0
  81. package/dist/shield/shield.test.d.mts +1 -0
  82. package/dist/shield/shield.test.mjs +13 -0
  83. package/dist/shield/shield.test.mjs.map +1 -0
  84. package/dist/shield/types.cjs +13 -0
  85. package/dist/shield/types.mjs +8 -0
  86. package/dist/shield/types.mjs.map +1 -0
  87. package/dist/shield/types.test.cjs +13 -0
  88. package/dist/shield/types.test.d.cts +1 -0
  89. package/dist/shield/types.test.d.mts +1 -0
  90. package/dist/shield/types.test.mjs +13 -0
  91. package/dist/shield/types.test.mjs.map +1 -0
  92. package/dist/shield/utils.cjs +15 -0
  93. package/dist/shield/utils.mjs +10 -1
  94. package/dist/shield/utils.mjs.map +1 -1
  95. package/dist/shield/utils.test.cjs +13 -0
  96. package/dist/shield/utils.test.d.cts +1 -0
  97. package/dist/shield/utils.test.d.mts +1 -0
  98. package/dist/shield/utils.test.mjs +13 -0
  99. package/dist/shield/utils.test.mjs.map +1 -0
  100. package/dist/shield/validation.cjs +12 -1
  101. package/dist/shield/validation.mjs +6 -1
  102. package/dist/shield/validation.mjs.map +1 -1
  103. package/dist/shield/validation.test.cjs +13 -0
  104. package/dist/shield/validation.test.d.cts +1 -0
  105. package/dist/shield/validation.test.d.mts +1 -0
  106. package/dist/shield/validation.test.mjs +13 -0
  107. package/dist/shield/validation.test.mjs.map +1 -0
  108. package/dist/types.cjs +13 -0
  109. package/dist/types.mjs +8 -0
  110. package/dist/types.mjs.map +1 -0
  111. package/dist/types.test.cjs +13 -0
  112. package/dist/types.test.d.cts +1 -0
  113. package/dist/types.test.d.mts +1 -0
  114. package/dist/types.test.mjs +13 -0
  115. package/dist/types.test.mjs.map +1 -0
  116. package/package.json +65 -9
@@ -1,7 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
  const require_shield_rules = require('./rules.cjs');
3
4
 
4
5
  //#region src/shield/constructors.ts
6
+ var constructors_exports = /* @__PURE__ */ require_runtime.__exportAll({
7
+ allow: () => allow,
8
+ and: () => and,
9
+ chain: () => chain,
10
+ deny: () => deny,
11
+ not: () => not,
12
+ or: () => or,
13
+ race: () => race,
14
+ rule: () => rule
15
+ });
5
16
  /**
6
17
  * Wraps a function into a Rule class. This way we can identify rules
7
18
  * once we start generating middleware from our ruleTree.
@@ -80,6 +91,12 @@ const deny = new require_shield_rules.RuleFalse();
80
91
  exports.allow = allow;
81
92
  exports.and = and;
82
93
  exports.chain = chain;
94
+ Object.defineProperty(exports, 'constructors_exports', {
95
+ enumerable: true,
96
+ get: function () {
97
+ return constructors_exports;
98
+ }
99
+ });
83
100
  exports.deny = deny;
84
101
  exports.not = not;
85
102
  exports.or = or;
@@ -1,6 +1,17 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
1
2
  import { Rule, RuleAnd, RuleChain, RuleFalse, RuleNot, RuleOr, RuleRace, RuleTrue } from "./rules.mjs";
2
3
 
3
4
  //#region src/shield/constructors.ts
5
+ var constructors_exports = /* @__PURE__ */ __exportAll({
6
+ allow: () => allow,
7
+ and: () => and,
8
+ chain: () => chain,
9
+ deny: () => deny,
10
+ not: () => not,
11
+ or: () => or,
12
+ race: () => race,
13
+ rule: () => rule
14
+ });
4
15
  /**
5
16
  * Wraps a function into a Rule class. This way we can identify rules
6
17
  * once we start generating middleware from our ruleTree.
@@ -76,5 +87,5 @@ const allow = new RuleTrue();
76
87
  const deny = new RuleFalse();
77
88
 
78
89
  //#endregion
79
- export { allow, and, chain, deny, not, or, race, rule };
90
+ export { allow, and, chain, constructors_exports, deny, not, or, race, rule };
80
91
  //# sourceMappingURL=constructors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constructors.mjs","names":[],"sources":["../../src/shield/constructors.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 {\n Rule,\n RuleAnd,\n RuleChain,\n RuleFalse,\n RuleNot,\n RuleOr,\n RuleRace,\n RuleTrue\n} from \"./rules\";\nimport type {\n RuleConstructorOptionsInterface,\n RuleFunctionInterface,\n ShieldRule\n} from \"./types\";\n\n/**\n * Wraps a function into a Rule class. This way we can identify rules\n * once we start generating middleware from our ruleTree.\n *\n * ```\n * // 1.\n * const auth = rule()(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n *\n * // 2.\n * const auth = rule('name')(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n *\n * // 3.\n * const auth = rule({\n * name: 'name',\n * })(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n * ```\n */\nexport const rule =\n <TContext extends Record<string, any>>(\n name?: string,\n options?: RuleConstructorOptionsInterface\n ) =>\n (func: RuleFunctionInterface<TContext>): Rule<TContext> => {\n if (typeof name === \"object\") {\n options = name;\n name = Math.random().toString();\n } else if (typeof name === \"string\") {\n options = options ?? {};\n } else {\n name = Math.random().toString();\n options = {};\n }\n\n // @ts-ignore\n return new Rule(name, func, {});\n };\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const and = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleAnd<TContext> => {\n return new RuleAnd(rules);\n};\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const chain = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleChain<TContext> => {\n return new RuleChain(rules);\n};\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const race = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleRace<TContext> => {\n return new RuleRace(rules);\n};\n\n/**\n * Logical operator or serves as a wrapper for or operation.\n */\nexport const or = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleOr<TContext> => {\n return new RuleOr(rules);\n};\n\n/**\n * Logical operator not serves as a wrapper for not operation.\n */\nexport const not = <TContext extends Record<string, any>>(\n rule: ShieldRule<TContext>,\n error?: string | Error\n): RuleNot<TContext> => {\n if (typeof error === \"string\") return new RuleNot(rule, new Error(error));\n return new RuleNot(rule, error);\n};\n\n/**\n * Allow queries.\n */\nexport const allow = new RuleTrue();\n\n/**\n * Deny queries.\n */\nexport const deny = new RuleFalse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,QAET,MACA,aAED,SAA0D;AACzD,KAAI,OAAO,SAAS,UAAU;AAC5B,YAAU;AACV,SAAO,KAAK,QAAQ,CAAC,UAAU;YACtB,OAAO,SAAS,SACzB,WAAU,WAAW,EAAE;MAClB;AACL,SAAO,KAAK,QAAQ,CAAC,UAAU;AAC/B,YAAU,EAAE;;AAId,QAAO,IAAI,KAAK,MAAM,MAAM,EAAE,CAAC;;;;;AAMnC,MAAa,OACX,GAAG,UACmB;AACtB,QAAO,IAAI,QAAQ,MAAM;;;;;AAM3B,MAAa,SACX,GAAG,UACqB;AACxB,QAAO,IAAI,UAAU,MAAM;;;;;AAM7B,MAAa,QACX,GAAG,UACoB;AACvB,QAAO,IAAI,SAAS,MAAM;;;;;AAM5B,MAAa,MACX,GAAG,UACkB;AACrB,QAAO,IAAI,OAAO,MAAM;;;;;AAM1B,MAAa,OACX,MACA,UACsB;AACtB,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,QAAQ,MAAM,IAAI,MAAM,MAAM,CAAC;AACzE,QAAO,IAAI,QAAQ,MAAM,MAAM;;;;;AAMjC,MAAa,QAAQ,IAAI,UAAU;;;;AAKnC,MAAa,OAAO,IAAI,WAAW"}
1
+ {"version":3,"file":"constructors.mjs","names":[],"sources":["../../src/shield/constructors.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 {\n Rule,\n RuleAnd,\n RuleChain,\n RuleFalse,\n RuleNot,\n RuleOr,\n RuleRace,\n RuleTrue\n} from \"./rules\";\nimport type {\n RuleConstructorOptionsInterface,\n RuleFunctionInterface,\n ShieldRule\n} from \"./types\";\n\n/**\n * Wraps a function into a Rule class. This way we can identify rules\n * once we start generating middleware from our ruleTree.\n *\n * ```\n * // 1.\n * const auth = rule()(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n *\n * // 2.\n * const auth = rule('name')(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n *\n * // 3.\n * const auth = rule({\n * name: 'name',\n * })(async (ctx, type, path, input, rawInput, options) => {\n * return true\n * })\n * ```\n */\nexport const rule =\n <TContext extends Record<string, any>>(\n name?: string,\n options?: RuleConstructorOptionsInterface\n ) =>\n (func: RuleFunctionInterface<TContext>): Rule<TContext> => {\n if (typeof name === \"object\") {\n options = name;\n name = Math.random().toString();\n } else if (typeof name === \"string\") {\n options = options ?? {};\n } else {\n name = Math.random().toString();\n options = {};\n }\n\n // @ts-ignore\n return new Rule(name, func, {});\n };\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const and = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleAnd<TContext> => {\n return new RuleAnd(rules);\n};\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const chain = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleChain<TContext> => {\n return new RuleChain(rules);\n};\n\n/**\n * Logical operator and serves as a wrapper for and operation.\n */\nexport const race = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleRace<TContext> => {\n return new RuleRace(rules);\n};\n\n/**\n * Logical operator or serves as a wrapper for or operation.\n */\nexport const or = <TContext extends Record<string, any>>(\n ...rules: ShieldRule<TContext>[]\n): RuleOr<TContext> => {\n return new RuleOr(rules);\n};\n\n/**\n * Logical operator not serves as a wrapper for not operation.\n */\nexport const not = <TContext extends Record<string, any>>(\n rule: ShieldRule<TContext>,\n error?: string | Error\n): RuleNot<TContext> => {\n if (typeof error === \"string\") return new RuleNot(rule, new Error(error));\n return new RuleNot(rule, error);\n};\n\n/**\n * Allow queries.\n */\nexport const allow = new RuleTrue();\n\n/**\n * Deny queries.\n */\nexport const deny = new RuleFalse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,QAET,MACA,aAED,SAA0D;AACzD,KAAI,OAAO,SAAS,UAAU;AAC5B,YAAU;AACV,SAAO,KAAK,QAAQ,CAAC,UAAU;YACtB,OAAO,SAAS,SACzB,WAAU,WAAW,EAAE;MAClB;AACL,SAAO,KAAK,QAAQ,CAAC,UAAU;AAC/B,YAAU,EAAE;;AAId,QAAO,IAAI,KAAK,MAAM,MAAM,EAAE,CAAC;;;;;AAMnC,MAAa,OACX,GAAG,UACmB;AACtB,QAAO,IAAI,QAAQ,MAAM;;;;;AAM3B,MAAa,SACX,GAAG,UACqB;AACxB,QAAO,IAAI,UAAU,MAAM;;;;;AAM7B,MAAa,QACX,GAAG,UACoB;AACvB,QAAO,IAAI,SAAS,MAAM;;;;;AAM5B,MAAa,MACX,GAAG,UACkB;AACrB,QAAO,IAAI,OAAO,MAAM;;;;;AAM1B,MAAa,OACX,MACA,UACsB;AACtB,KAAI,OAAO,UAAU,SAAU,QAAO,IAAI,QAAQ,MAAM,IAAI,MAAM,MAAM,CAAC;AACzE,QAAO,IAAI,QAAQ,MAAM,MAAM;;;;;AAMjC,MAAa,QAAQ,IAAI,UAAU;;;;AAKnC,MAAa,OAAO,IAAI,WAAW"}
@@ -0,0 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_shield_constructors = require('./constructors.cjs');
3
+ let vitest = require("vitest");
4
+
5
+ //#region src/shield/constructors.test.ts
6
+ (0, vitest.describe)("shield/constructors.ts exports", () => {
7
+ (0, vitest.it)("loads module exports", () => {
8
+ (0, vitest.expect)(require_shield_constructors.constructors_exports).toBeDefined();
9
+ (0, vitest.expect)(typeof require_shield_constructors.constructors_exports).toBe("object");
10
+ });
11
+ });
12
+
13
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,13 @@
1
+ import { constructors_exports } from "./constructors.mjs";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ //#region src/shield/constructors.test.ts
5
+ describe("shield/constructors.ts exports", () => {
6
+ it("loads module exports", () => {
7
+ expect(constructors_exports).toBeDefined();
8
+ expect(typeof constructors_exports).toBe("object");
9
+ });
10
+ });
11
+
12
+ //#endregion
13
+ //# sourceMappingURL=constructors.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructors.test.mjs","names":["moduleExports"],"sources":["../../src/shield/constructors.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./constructors.ts\";\n\ndescribe(\"shield/constructors.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,wCAAwC;AAC/C,IAAG,8BAA8B;AAC/B,SAAOA,qBAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,qBAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
 
3
4
  //#region src/shield/generator.ts
5
+ var generator_exports = /* @__PURE__ */ require_runtime.__exportAll({ generateMiddlewareFromRuleTree: () => generateMiddlewareFromRuleTree });
4
6
  /**
5
7
  * Generates middleware from given rules.
6
8
  */
@@ -26,4 +28,10 @@ function generateMiddlewareFromRuleTree(ruleTree, options) {
26
28
  }
27
29
 
28
30
  //#endregion
29
- exports.generateMiddlewareFromRuleTree = generateMiddlewareFromRuleTree;
31
+ exports.generateMiddlewareFromRuleTree = generateMiddlewareFromRuleTree;
32
+ Object.defineProperty(exports, 'generator_exports', {
33
+ enumerable: true,
34
+ get: function () {
35
+ return generator_exports;
36
+ }
37
+ });
@@ -1,4 +1,7 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+
1
3
  //#region src/shield/generator.ts
4
+ var generator_exports = /* @__PURE__ */ __exportAll({ generateMiddlewareFromRuleTree: () => generateMiddlewareFromRuleTree });
2
5
  /**
3
6
  * Generates middleware from given rules.
4
7
  */
@@ -24,5 +27,5 @@ function generateMiddlewareFromRuleTree(ruleTree, options) {
24
27
  }
25
28
 
26
29
  //#endregion
27
- export { generateMiddlewareFromRuleTree };
30
+ export { generateMiddlewareFromRuleTree, generator_exports };
28
31
  //# sourceMappingURL=generator.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"generator.mjs","names":[],"sources":["../../src/shield/generator.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 { IRules, OptionsInterface, ShieldRule } from \"./types\";\n\n/**\n * Generates middleware from given rules.\n */\nexport function generateMiddlewareFromRuleTree<\n TContext extends Record<string, unknown>\n>(ruleTree: IRules<TContext>, options: OptionsInterface<TContext>) {\n return async ({\n next,\n ctx,\n type,\n path,\n input,\n rawInput\n }: {\n next: () => Promise<any>;\n ctx: TContext;\n type: string;\n path: string;\n input: { [name: string]: any };\n rawInput: unknown;\n }) => {\n const opWithPath: Array<string> = path.split(\".\");\n const opName: string = opWithPath[opWithPath.length - 1]!;\n const keys = Object.keys(ruleTree);\n let rule: ShieldRule<TContext> | undefined;\n if (keys.includes(\"query\") || keys.includes(\"mutation\")) {\n // @ts-ignore\n rule = ruleTree?.[type]?.[opName];\n } else {\n const namespace = opWithPath[0];\n\n const tree = (ruleTree as Record<string, any>)[namespace!];\n if (tree?.[type]?.[opName]) {\n rule = tree?.[type]?.[opName];\n }\n }\n rule = rule ?? options.fallbackRule;\n\n if (rule) {\n return rule\n ?.resolve(ctx, type, path, input, rawInput, options)\n .then(async result => {\n if (result instanceof Error) {\n throw result;\n }\n if (!result) {\n throw options.fallbackError;\n }\n\n return next();\n });\n }\n\n return next();\n };\n}\n"],"mappings":";;;;AAuBA,SAAgB,+BAEd,UAA4B,SAAqC;AACjE,QAAO,OAAO,EACZ,MACA,KACA,MACA,MACA,OACA,eAQI;EACJ,MAAM,aAA4B,KAAK,MAAM,IAAI;EACjD,MAAM,SAAiB,WAAW,WAAW,SAAS;EACtD,MAAM,OAAO,OAAO,KAAK,SAAS;EAClC,IAAI;AACJ,MAAI,KAAK,SAAS,QAAQ,IAAI,KAAK,SAAS,WAAW,CAErD,QAAO,WAAW,QAAQ;OACrB;GAGL,MAAM,OAAQ,SAFI,WAAW;AAG7B,OAAI,OAAO,QAAQ,QACjB,QAAO,OAAO,QAAQ;;AAG1B,SAAO,QAAQ,QAAQ;AAEvB,MAAI,KACF,QAAO,MACH,QAAQ,KAAK,MAAM,MAAM,OAAO,UAAU,QAAQ,CACnD,KAAK,OAAM,WAAU;AACpB,OAAI,kBAAkB,MACpB,OAAM;AAER,OAAI,CAAC,OACH,OAAM,QAAQ;AAGhB,UAAO,MAAM;IACb;AAGN,SAAO,MAAM"}
1
+ {"version":3,"file":"generator.mjs","names":[],"sources":["../../src/shield/generator.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 { IRules, OptionsInterface, ShieldRule } from \"./types\";\n\n/**\n * Generates middleware from given rules.\n */\nexport function generateMiddlewareFromRuleTree<\n TContext extends Record<string, unknown>\n>(ruleTree: IRules<TContext>, options: OptionsInterface<TContext>) {\n return async ({\n next,\n ctx,\n type,\n path,\n input,\n rawInput\n }: {\n next: () => Promise<any>;\n ctx: TContext;\n type: string;\n path: string;\n input: { [name: string]: any };\n rawInput: unknown;\n }) => {\n const opWithPath: Array<string> = path.split(\".\");\n const opName: string = opWithPath[opWithPath.length - 1]!;\n const keys = Object.keys(ruleTree);\n let rule: ShieldRule<TContext> | undefined;\n if (keys.includes(\"query\") || keys.includes(\"mutation\")) {\n // @ts-ignore\n rule = ruleTree?.[type]?.[opName];\n } else {\n const namespace = opWithPath[0];\n\n const tree = (ruleTree as Record<string, any>)[namespace!];\n if (tree?.[type]?.[opName]) {\n rule = tree?.[type]?.[opName];\n }\n }\n rule = rule ?? options.fallbackRule;\n\n if (rule) {\n return rule\n ?.resolve(ctx, type, path, input, rawInput, options)\n .then(async result => {\n if (result instanceof Error) {\n throw result;\n }\n if (!result) {\n throw options.fallbackError;\n }\n\n return next();\n });\n }\n\n return next();\n };\n}\n"],"mappings":";;;;;;;AAuBA,SAAgB,+BAEd,UAA4B,SAAqC;AACjE,QAAO,OAAO,EACZ,MACA,KACA,MACA,MACA,OACA,eAQI;EACJ,MAAM,aAA4B,KAAK,MAAM,IAAI;EACjD,MAAM,SAAiB,WAAW,WAAW,SAAS;EACtD,MAAM,OAAO,OAAO,KAAK,SAAS;EAClC,IAAI;AACJ,MAAI,KAAK,SAAS,QAAQ,IAAI,KAAK,SAAS,WAAW,CAErD,QAAO,WAAW,QAAQ;OACrB;GAGL,MAAM,OAAQ,SAFI,WAAW;AAG7B,OAAI,OAAO,QAAQ,QACjB,QAAO,OAAO,QAAQ;;AAG1B,SAAO,QAAQ,QAAQ;AAEvB,MAAI,KACF,QAAO,MACH,QAAQ,KAAK,MAAM,MAAM,OAAO,UAAU,QAAQ,CACnD,KAAK,OAAM,WAAU;AACpB,OAAI,kBAAkB,MACpB,OAAM;AAER,OAAI,CAAC,OACH,OAAM,QAAQ;AAGhB,UAAO,MAAM;IACb;AAGN,SAAO,MAAM"}
@@ -0,0 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_shield_generator = require('./generator.cjs');
3
+ let vitest = require("vitest");
4
+
5
+ //#region src/shield/generator.test.ts
6
+ (0, vitest.describe)("shield/generator.ts exports", () => {
7
+ (0, vitest.it)("loads module exports", () => {
8
+ (0, vitest.expect)(require_shield_generator.generator_exports).toBeDefined();
9
+ (0, vitest.expect)(typeof require_shield_generator.generator_exports).toBe("object");
10
+ });
11
+ });
12
+
13
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,13 @@
1
+ import { generator_exports } from "./generator.mjs";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ //#region src/shield/generator.test.ts
5
+ describe("shield/generator.ts exports", () => {
6
+ it("loads module exports", () => {
7
+ expect(generator_exports).toBeDefined();
8
+ expect(typeof generator_exports).toBe("object");
9
+ });
10
+ });
11
+
12
+ //#endregion
13
+ //# sourceMappingURL=generator.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.test.mjs","names":["moduleExports"],"sources":["../../src/shield/generator.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./generator.ts\";\n\ndescribe(\"shield/generator.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,qCAAqC;AAC5C,IAAG,8BAA8B;AAC/B,SAAOA,kBAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,kBAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
@@ -1,7 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
  const require_shield_constructors = require('./constructors.cjs');
3
4
  const require_shield_shield = require('./shield.cjs');
4
5
 
6
+ //#region src/shield/index.ts
7
+ var shield_exports = /* @__PURE__ */ require_runtime.__exportAll({
8
+ allow: () => require_shield_constructors.allow,
9
+ and: () => require_shield_constructors.and,
10
+ chain: () => require_shield_constructors.chain,
11
+ deny: () => require_shield_constructors.deny,
12
+ not: () => require_shield_constructors.not,
13
+ or: () => require_shield_constructors.or,
14
+ race: () => require_shield_constructors.race,
15
+ rule: () => require_shield_constructors.rule,
16
+ shield: () => require_shield_shield.shield
17
+ });
18
+
19
+ //#endregion
5
20
  exports.allow = require_shield_constructors.allow;
6
21
  exports.and = require_shield_constructors.and;
7
22
  exports.chain = require_shield_constructors.chain;
@@ -10,4 +25,10 @@ exports.not = require_shield_constructors.not;
10
25
  exports.or = require_shield_constructors.or;
11
26
  exports.race = require_shield_constructors.race;
12
27
  exports.rule = require_shield_constructors.rule;
13
- exports.shield = require_shield_shield.shield;
28
+ exports.shield = require_shield_shield.shield;
29
+ Object.defineProperty(exports, 'shield_exports', {
30
+ enumerable: true,
31
+ get: function () {
32
+ return shield_exports;
33
+ }
34
+ });
@@ -1,4 +1,20 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
1
2
  import { allow, and, chain, deny, not, or, race, rule } from "./constructors.mjs";
2
3
  import { shield } from "./shield.mjs";
3
4
 
4
- export { allow, and, chain, deny, not, or, race, rule, shield };
5
+ //#region src/shield/index.ts
6
+ var shield_exports = /* @__PURE__ */ __exportAll({
7
+ allow: () => allow,
8
+ and: () => and,
9
+ chain: () => chain,
10
+ deny: () => deny,
11
+ not: () => not,
12
+ or: () => or,
13
+ race: () => race,
14
+ rule: () => rule,
15
+ shield: () => shield
16
+ });
17
+
18
+ //#endregion
19
+ export { allow, and, chain, deny, not, or, race, rule, shield, shield_exports };
20
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/shield/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\nexport { allow, and, chain, deny, not, or, race, rule } from \"./constructors\";\nexport { shield } from \"./shield\";\nexport type { RuleInterface as IRule, IRules } from \"./types\";\n"],"mappings":""}
@@ -0,0 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_shield_index = require('./index.cjs');
3
+ let vitest = require("vitest");
4
+
5
+ //#region src/shield/index.test.ts
6
+ (0, vitest.describe)("shield/index.ts exports", () => {
7
+ (0, vitest.it)("loads module exports", () => {
8
+ (0, vitest.expect)(require_shield_index.shield_exports).toBeDefined();
9
+ (0, vitest.expect)(typeof require_shield_index.shield_exports).toBe("object");
10
+ });
11
+ });
12
+
13
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,13 @@
1
+ import { shield_exports } from "./index.mjs";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ //#region src/shield/index.test.ts
5
+ describe("shield/index.ts exports", () => {
6
+ it("loads module exports", () => {
7
+ expect(shield_exports).toBeDefined();
8
+ expect(typeof shield_exports).toBe("object");
9
+ });
10
+ });
11
+
12
+ //#endregion
13
+ //# sourceMappingURL=index.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.mjs","names":["moduleExports"],"sources":["../../src/shield/index.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./index.ts\";\n\ndescribe(\"shield/index.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,iCAAiC;AACxC,IAAG,8BAA8B;AAC/B,SAAOA,eAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,eAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
@@ -1,6 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
 
3
4
  //#region src/shield/rules.ts
5
+ var rules_exports = /* @__PURE__ */ require_runtime.__exportAll({
6
+ LogicRule: () => LogicRule,
7
+ Rule: () => Rule,
8
+ RuleAnd: () => RuleAnd,
9
+ RuleChain: () => RuleChain,
10
+ RuleFalse: () => RuleFalse,
11
+ RuleNot: () => RuleNot,
12
+ RuleOr: () => RuleOr,
13
+ RuleRace: () => RuleRace,
14
+ RuleTrue: () => RuleTrue
15
+ });
4
16
  var Rule = class {
5
17
  name;
6
18
  func;
@@ -198,4 +210,10 @@ exports.RuleFalse = RuleFalse;
198
210
  exports.RuleNot = RuleNot;
199
211
  exports.RuleOr = RuleOr;
200
212
  exports.RuleRace = RuleRace;
201
- exports.RuleTrue = RuleTrue;
213
+ exports.RuleTrue = RuleTrue;
214
+ Object.defineProperty(exports, 'rules_exports', {
215
+ enumerable: true,
216
+ get: function () {
217
+ return rules_exports;
218
+ }
219
+ });
@@ -1,4 +1,17 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+
1
3
  //#region src/shield/rules.ts
4
+ var rules_exports = /* @__PURE__ */ __exportAll({
5
+ LogicRule: () => LogicRule,
6
+ Rule: () => Rule,
7
+ RuleAnd: () => RuleAnd,
8
+ RuleChain: () => RuleChain,
9
+ RuleFalse: () => RuleFalse,
10
+ RuleNot: () => RuleNot,
11
+ RuleOr: () => RuleOr,
12
+ RuleRace: () => RuleRace,
13
+ RuleTrue: () => RuleTrue
14
+ });
2
15
  var Rule = class {
3
16
  name;
4
17
  func;
@@ -188,5 +201,5 @@ var RuleFalse = class extends LogicRule {
188
201
  };
189
202
 
190
203
  //#endregion
191
- export { LogicRule, Rule, RuleAnd, RuleChain, RuleFalse, RuleNot, RuleOr, RuleRace, RuleTrue };
204
+ export { LogicRule, Rule, RuleAnd, RuleChain, RuleFalse, RuleNot, RuleOr, RuleRace, RuleTrue, rules_exports };
192
205
  //# sourceMappingURL=rules.mjs.map
@@ -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,OAA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E3D;;;;AAKV,IAAa,UAAb,cACU,UAEV;CACE;CAEA,AAAS,OAAe;CAExB,AAAS;CAET,YAAY,MAA4B,OAAe;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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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"}
@@ -0,0 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_shield_rules = require('./rules.cjs');
3
+ let vitest = require("vitest");
4
+
5
+ //#region src/shield/rules.test.ts
6
+ (0, vitest.describe)("shield/rules.ts exports", () => {
7
+ (0, vitest.it)("loads module exports", () => {
8
+ (0, vitest.expect)(require_shield_rules.rules_exports).toBeDefined();
9
+ (0, vitest.expect)(typeof require_shield_rules.rules_exports).toBe("object");
10
+ });
11
+ });
12
+
13
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,13 @@
1
+ import { rules_exports } from "./rules.mjs";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ //#region src/shield/rules.test.ts
5
+ describe("shield/rules.ts exports", () => {
6
+ it("loads module exports", () => {
7
+ expect(rules_exports).toBeDefined();
8
+ expect(typeof rules_exports).toBe("object");
9
+ });
10
+ });
11
+
12
+ //#endregion
13
+ //# sourceMappingURL=rules.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.test.mjs","names":["moduleExports"],"sources":["../../src/shield/rules.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./rules.ts\";\n\ndescribe(\"shield/rules.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,iCAAiC;AACxC,IAAG,8BAA8B;AAC/B,SAAOA,cAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,cAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
@@ -1,10 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
  const require_shield_constructors = require('./constructors.cjs');
3
4
  const require_shield_generator = require('./generator.cjs');
4
5
  const require_shield_utils = require('./utils.cjs');
5
6
  const require_shield_validation = require('./validation.cjs');
6
7
 
7
8
  //#region src/shield/shield.ts
9
+ var shield_exports = /* @__PURE__ */ require_runtime.__exportAll({ shield: () => shield });
8
10
  /**
9
11
  * Makes sure all of defined rules are in accord with the options
10
12
  * shield can process.
@@ -29,4 +31,10 @@ function shield(ruleTree, options = {}) {
29
31
  }
30
32
 
31
33
  //#endregion
32
- exports.shield = shield;
34
+ exports.shield = shield;
35
+ Object.defineProperty(exports, 'shield_exports', {
36
+ enumerable: true,
37
+ get: function () {
38
+ return shield_exports;
39
+ }
40
+ });
@@ -1,9 +1,11 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
1
2
  import { allow } from "./constructors.mjs";
2
3
  import { generateMiddlewareFromRuleTree } from "./generator.mjs";
3
4
  import { withDefault } from "./utils.mjs";
4
5
  import { ValidationError, validateRuleTree } from "./validation.mjs";
5
6
 
6
7
  //#region src/shield/shield.ts
8
+ var shield_exports = /* @__PURE__ */ __exportAll({ shield: () => shield });
7
9
  /**
8
10
  * Makes sure all of defined rules are in accord with the options
9
11
  * shield can process.
@@ -28,5 +30,5 @@ function shield(ruleTree, options = {}) {
28
30
  }
29
31
 
30
32
  //#endregion
31
- export { shield };
33
+ export { shield, shield_exports };
32
34
  //# 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":";;;;;;;;;;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"}
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"}
@@ -0,0 +1,13 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_shield_shield = require('./shield.cjs');
3
+ let vitest = require("vitest");
4
+
5
+ //#region src/shield/shield.test.ts
6
+ (0, vitest.describe)("shield/shield.ts exports", () => {
7
+ (0, vitest.it)("loads module exports", () => {
8
+ (0, vitest.expect)(require_shield_shield.shield_exports).toBeDefined();
9
+ (0, vitest.expect)(typeof require_shield_shield.shield_exports).toBe("object");
10
+ });
11
+ });
12
+
13
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,13 @@
1
+ import { shield_exports } from "./shield.mjs";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ //#region src/shield/shield.test.ts
5
+ describe("shield/shield.ts exports", () => {
6
+ it("loads module exports", () => {
7
+ expect(shield_exports).toBeDefined();
8
+ expect(typeof shield_exports).toBe("object");
9
+ });
10
+ });
11
+
12
+ //#endregion
13
+ //# sourceMappingURL=shield.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shield.test.mjs","names":["moduleExports"],"sources":["../../src/shield/shield.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./shield.ts\";\n\ndescribe(\"shield/shield.ts exports\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n});\n"],"mappings":";;;;AAGA,SAAS,kCAAkC;AACzC,IAAG,8BAA8B;AAC/B,SAAOA,eAAc,CAAC,aAAa;AACnC,SAAO,OAAOA,eAAc,CAAC,KAAK,SAAS;GAC3C;EACF"}
@@ -0,0 +1,13 @@
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
+ });
@@ -0,0 +1,8 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+
3
+ //#region src/shield/types.ts
4
+ var types_exports = /* @__PURE__ */ __exportAll({});
5
+
6
+ //#endregion
7
+ export { types_exports };
8
+ //# sourceMappingURL=types.mjs.map