ts-rules-composer 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.github/workflows/publish.yml +1 -1
  2. package/README.md +310 -42
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +335 -55
  6. package/dist/index.d.ts +335 -55
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/eslint.config.mjs +84 -0
  10. package/examples/financial-transaction.example.ts +188 -0
  11. package/examples/model-deployment.example.ts +136 -0
  12. package/examples/user-registration.example.ts +101 -0
  13. package/package.json +21 -6
  14. package/src/lib/combinators/logic/every.spec.ts +1 -1
  15. package/src/lib/combinators/logic/every.ts +17 -7
  16. package/src/lib/combinators/logic/if-else.spec.ts +11 -1
  17. package/src/lib/combinators/logic/if-else.ts +33 -8
  18. package/src/lib/combinators/logic/match.ts +20 -6
  19. package/src/lib/combinators/logic/not.spec.ts +3 -1
  20. package/src/lib/combinators/logic/not.ts +12 -3
  21. package/src/lib/combinators/logic/one-of.spec.ts +7 -7
  22. package/src/lib/combinators/logic/one-of.ts +11 -4
  23. package/src/lib/combinators/logic/unless.spec.ts +1 -1
  24. package/src/lib/combinators/logic/unless.ts +28 -5
  25. package/src/lib/combinators/logic/when.spec.ts +11 -15
  26. package/src/lib/combinators/logic/when.ts +29 -8
  27. package/src/lib/combinators/logic/with-fallback.ts +13 -4
  28. package/src/lib/combinators/utility/index.ts +5 -2
  29. package/src/lib/combinators/utility/inject.ts +1 -1
  30. package/src/lib/combinators/utility/map-error.ts +1 -1
  31. package/src/lib/combinators/utility/tap.spec.ts +63 -63
  32. package/src/lib/combinators/utility/tap.ts +18 -28
  33. package/src/lib/combinators/utility/validate-field.spec.ts +1 -1
  34. package/src/lib/combinators/utility/validate-field.ts +10 -3
  35. package/src/lib/combinators/utility/with-debug.spec.ts +1 -1
  36. package/src/lib/combinators/utility/with-debug.ts +1 -1
  37. package/src/lib/combinators/utility/with-memoize.spec.ts +1 -1
  38. package/src/lib/combinators/utility/with-memoize.ts +12 -4
  39. package/src/lib/combinators/utility/with-retry.spec.ts +1 -1
  40. package/src/lib/combinators/utility/with-retry.ts +4 -2
  41. package/src/lib/combinators/utility/with-safe-error.spec.ts +137 -0
  42. package/src/lib/combinators/utility/with-safe-error.ts +56 -0
  43. package/src/lib/combinators/utility/with-safe-predicate.spec.ts +176 -0
  44. package/src/lib/combinators/utility/with-safe-predicate.ts +64 -0
  45. package/src/lib/combinators/utility/with-tap.spec.ts +104 -0
  46. package/src/lib/combinators/utility/with-tap.ts +46 -0
  47. package/src/lib/combinators/utility/with-timeout.spec.ts +1 -1
  48. package/src/lib/combinators/utility/with-timeout.ts +10 -3
  49. package/src/lib/composition/compose-rules.spec.ts +1 -1
  50. package/src/lib/composition/compose-rules.ts +16 -8
  51. package/src/lib/composition/pipe-rules.spec.ts +1 -1
  52. package/src/lib/composition/pipe-rules.ts +15 -7
  53. package/src/lib/composition/pipe.ts +1 -0
  54. package/src/lib/helpers/clone/clone.ts +12 -0
  55. package/src/lib/helpers/clone/getCloneFn.ts +17 -0
  56. package/src/lib/helpers/clone/shallowClone.ts +12 -0
  57. package/src/lib/helpers/context/require-context.ts +1 -1
  58. package/src/lib/helpers/context/with-lazy-context.spec.ts +1 -1
  59. package/src/lib/helpers/context/with-lazy-context.ts +1 -1
  60. package/src/lib/helpers/index.ts +2 -0
  61. package/src/lib/helpers/result/fail.ts +1 -1
  62. package/src/lib/helpers/result/pass.ts +1 -1
  63. package/src/lib/helpers/retry/calculate-delay.ts +1 -1
  64. package/src/lib/helpers/safety/get-normalized-rule.spec.ts +209 -0
  65. package/src/lib/helpers/safety/get-normalized-rule.ts +14 -0
  66. package/src/lib/helpers/safety/get-normalized-rules.spec.ts +138 -0
  67. package/src/lib/helpers/safety/get-normalized-rules.ts +14 -0
  68. package/src/lib/index.ts +1 -1
  69. package/src/lib/types/composition-options.ts +28 -3
  70. package/src/lib/types/debug-options.ts +1 -1
  71. package/src/lib/types/index.ts +8 -4
  72. package/src/lib/types/predicate-result.ts +20 -0
  73. package/src/lib/types/predicate-safe.ts +10 -0
  74. package/src/lib/types/predicate-safety-options.ts +27 -0
  75. package/src/lib/types/predicate.ts +8 -0
  76. package/src/lib/types/prettify.ts +3 -0
  77. package/src/lib/types/rule-safety-options.ts +34 -0
  78. package/src/lib/types/rule.ts +1 -1
  79. package/src/lib/types/safety-options.ts +7 -0
  80. package/src/test/financial-transaction.spec.ts +251 -0
  81. package/src/test/helpers/get-rule-error.ts +1 -1
  82. package/src/test/integration.spec.ts +3 -3
  83. package/src/test/model-deployment.spec.ts +209 -0
  84. package/src/test/user-registration.spec.ts +164 -0
  85. package/tsconfig.json +5 -4
  86. package/tsup.config.ts +15 -15
  87. package/typedoc/tsconfig.typedoc.json +15 -0
  88. package/typedoc/typedoc.json +14 -0
  89. package/.eslintrc.json +0 -66
package/tsconfig.json CHANGED
@@ -3,7 +3,6 @@
3
3
  "incremental": false,
4
4
  "target": "ES2018",
5
5
  "outDir": "dist",
6
- "rootDir": "src",
7
6
  "sourceRoot": "src",
8
7
  "moduleResolution": "node",
9
8
  "module": "ES6",
@@ -44,12 +43,14 @@
44
43
  ]
45
44
  },
46
45
  "include": [
47
- "src/**/*.ts"
46
+ "src/**/*.ts",
47
+ "examples/**/*.ts"
48
48
  ],
49
49
  "exclude": [
50
50
  "dist/**",
51
51
  "build/**",
52
- "node_modules/**"
52
+ "node_modules/**",
53
+ "vitest.config.ts",
53
54
  ],
54
- "compileOnSave": false
55
+ "compileOnSave": false,
55
56
  }
package/tsup.config.ts CHANGED
@@ -1,36 +1,36 @@
1
1
  // tsup.config.ts
2
- import { defineConfig } from 'tsup'
2
+ import { defineConfig } from "tsup";
3
3
 
4
4
  export default defineConfig({
5
5
  // Entry file(s)
6
- entry: ['src/lib/index.ts'],
7
-
6
+ entry: ["src/lib/index.ts"],
7
+
8
8
  // Output formats
9
- format: ['cjs', 'esm'],
10
-
9
+ format: ["cjs", "esm"],
10
+
11
11
  // Generate declaration files
12
12
  dts: true,
13
-
13
+
14
14
  // Clean dist folder before build
15
15
  clean: true,
16
-
16
+
17
17
  // Target ES2018 for good balance
18
- target: 'es2018',
19
-
18
+ target: "es2018",
19
+
20
20
  // Bundle dependencies (adjust based on your needs)
21
21
  noExternal: [], // Bundle all dependencies
22
22
  // or
23
23
  // external: ['some-package'], // Mark specific packages as external
24
-
24
+
25
25
  // Enable sourcemaps
26
26
  sourcemap: true,
27
-
27
+
28
28
  // Optional: Splitting for ESM
29
29
  splitting: true,
30
-
30
+
31
31
  // Optional: Minification
32
32
  minify: true,
33
-
33
+
34
34
  // Optional: Tree-shaking
35
- treeshake: true,
36
- })
35
+ treeshake: true,
36
+ });
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "moduleResolution": "bundler"
5
+ },
6
+ "module": "ES6",
7
+ "exclude": [
8
+ "dist/**",
9
+ "build/**",
10
+ "node_modules/**",
11
+ "vitest.config.ts",
12
+ // workaround for https://github.com/rollup/rollup/issues/5199
13
+ "**/**spec.ts",
14
+ ],
15
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "githubPages": true,
3
+ "includeVersion": true,
4
+ "out": "../genDocs",
5
+ "entryPoints": [
6
+ "../src/lib/index.ts"
7
+ ],
8
+ "tsconfig": "./tsconfig.typedoc.json",
9
+ "exclude": ["/**/**.spec.ts", "vitest.config.ts"],
10
+ "plugin": [
11
+ "typedoc-plugin-mermaid",
12
+ "typedoc-github-theme",
13
+ ]
14
+ }
package/.eslintrc.json DELETED
@@ -1,66 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "project": "./tsconfig.json"
6
- },
7
- "env": {
8
- "es6": true
9
- },
10
- "ignorePatterns": [
11
- "node_modules",
12
- "build",
13
- "coverage",
14
- "vitest.config.js"
15
- ],
16
- "plugins": [
17
- "import",
18
- "eslint-comments"
19
- ],
20
- "extends": [
21
- "eslint:recommended",
22
- "plugin:eslint-comments/recommended",
23
- "plugin:@typescript-eslint/recommended",
24
- "plugin:import/typescript",
25
- "prettier",
26
- "prettier/@typescript-eslint"
27
- ],
28
- "globals": {
29
- "BigInt": true,
30
- "console": true,
31
- "WebAssembly": true
32
- },
33
- "rules": {
34
- "@typescript-eslint/explicit-module-boundary-types": "off",
35
- "@typescript-eslint/no-unused-vars": [
36
- 1,
37
- {
38
- "argsIgnorePattern": "^_",
39
- "varsIgnorePattern": "^_"
40
- }
41
- ],
42
- "eslint-comments/disable-enable-pair": [
43
- "error",
44
- {
45
- "allowWholeFile": true
46
- }
47
- ],
48
- "eslint-comments/no-unused-disable": "error",
49
- "import/order": [
50
- "error",
51
- {
52
- "newlines-between": "always",
53
- "alphabetize": {
54
- "order": "asc"
55
- }
56
- }
57
- ],
58
- "quotes": [
59
- "error",
60
- "single",
61
- {
62
- "allowTemplateLiterals": true
63
- }
64
- ]
65
- }
66
- }