sizuku 0.3.2 → 0.4.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 (204) hide show
  1. package/README.md +103 -0
  2. package/dist/config/index.d.mts +58 -0
  3. package/dist/config/index.mjs +95 -0
  4. package/dist/index.d.mts +10 -0
  5. package/dist/index.mjs +1615 -0
  6. package/package.json +31 -17
  7. package/dist/cli/main.d.ts +0 -10
  8. package/dist/cli/main.js +0 -61
  9. package/dist/cli.d.ts +0 -2
  10. package/dist/cli.js +0 -51
  11. package/dist/config/index.d.ts +0 -27
  12. package/dist/config/index.js +0 -85
  13. package/dist/config/loader.d.ts +0 -19
  14. package/dist/config/loader.js +0 -30
  15. package/dist/generator/engine.d.ts +0 -3
  16. package/dist/generator/engine.js +0 -63
  17. package/dist/generator/mermaid-er/config/index.d.ts +0 -10
  18. package/dist/generator/mermaid-er/config/index.js +0 -12
  19. package/dist/generator/mermaid-er/core/extract-relations.d.ts +0 -8
  20. package/dist/generator/mermaid-er/core/extract-relations.js +0 -17
  21. package/dist/generator/mermaid-er/core.d.ts +0 -6
  22. package/dist/generator/mermaid-er/core.js +0 -54
  23. package/dist/generator/mermaid-er/generator/er-content.d.ts +0 -20
  24. package/dist/generator/mermaid-er/generator/er-content.js +0 -23
  25. package/dist/generator/mermaid-er/generator/index.d.ts +0 -2
  26. package/dist/generator/mermaid-er/generator/index.js +0 -2
  27. package/dist/generator/mermaid-er/generator/relation-line.d.ts +0 -12
  28. package/dist/generator/mermaid-er/generator/relation-line.js +0 -13
  29. package/dist/generator/mermaid-er/generator.d.ts +0 -3
  30. package/dist/generator/mermaid-er/generator.js +0 -14
  31. package/dist/generator/mermaid-er/index.d.ts +0 -12
  32. package/dist/generator/mermaid-er/index.js +0 -33
  33. package/dist/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -14
  34. package/dist/generator/mermaid-er/relationship/build-relation-line.js +0 -34
  35. package/dist/generator/mermaid-er/types.d.ts +0 -21
  36. package/dist/generator/mermaid-er/types.js +0 -1
  37. package/dist/generator/mermaid-er/validator/index.d.ts +0 -8
  38. package/dist/generator/mermaid-er/validator/index.js +0 -74
  39. package/dist/generator/mermaid-er/validator/is-relationship.d.ts +0 -7
  40. package/dist/generator/mermaid-er/validator/is-relationship.js +0 -8
  41. package/dist/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -12
  42. package/dist/generator/mermaid-er/validator/parse-relation-line.js +0 -20
  43. package/dist/generator/mermaid-er/validator/parse-table-info.d.ts +0 -2
  44. package/dist/generator/mermaid-er/validator/parse-table-info.js +0 -71
  45. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
  46. package/dist/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
  47. package/dist/generator/valibot/config/index.d.ts +0 -7
  48. package/dist/generator/valibot/config/index.js +0 -13
  49. package/dist/generator/valibot/core/extract-schema.d.ts +0 -5
  50. package/dist/generator/valibot/core/extract-schema.js +0 -173
  51. package/dist/generator/valibot/core.d.ts +0 -5
  52. package/dist/generator/valibot/core.js +0 -39
  53. package/dist/generator/valibot/generator/infer-input.d.ts +0 -5
  54. package/dist/generator/valibot/generator/infer-input.js +0 -8
  55. package/dist/generator/valibot/generator/relation-valibot-code.d.ts +0 -13
  56. package/dist/generator/valibot/generator/relation-valibot-code.js +0 -19
  57. package/dist/generator/valibot/generator/valibot-code.d.ts +0 -15
  58. package/dist/generator/valibot/generator/valibot-code.js +0 -16
  59. package/dist/generator/valibot/generator/valibot.d.ts +0 -14
  60. package/dist/generator/valibot/generator/valibot.js +0 -15
  61. package/dist/generator/valibot/generator.d.ts +0 -3
  62. package/dist/generator/valibot/generator.js +0 -14
  63. package/dist/generator/valibot/index.d.ts +0 -14
  64. package/dist/generator/valibot/index.js +0 -50
  65. package/dist/generator/zod/config/index.d.ts +0 -8
  66. package/dist/generator/zod/config/index.js +0 -14
  67. package/dist/generator/zod/core/extract-schema.d.ts +0 -7
  68. package/dist/generator/zod/core/extract-schema.js +0 -243
  69. package/dist/generator/zod/core.d.ts +0 -5
  70. package/dist/generator/zod/core.js +0 -39
  71. package/dist/generator/zod/generator/infer.d.ts +0 -5
  72. package/dist/generator/zod/generator/infer.js +0 -8
  73. package/dist/generator/zod/generator/relation-zod-code.d.ts +0 -13
  74. package/dist/generator/zod/generator/relation-zod-code.js +0 -19
  75. package/dist/generator/zod/generator/zod-code.d.ts +0 -17
  76. package/dist/generator/zod/generator/zod-code.js +0 -18
  77. package/dist/generator/zod/generator/zod.d.ts +0 -16
  78. package/dist/generator/zod/generator/zod.js +0 -16
  79. package/dist/generator/zod/generator.d.ts +0 -3
  80. package/dist/generator/zod/generator.js +0 -14
  81. package/dist/generator/zod/index.d.ts +0 -15
  82. package/dist/generator/zod/index.js +0 -54
  83. package/dist/index.d.ts +0 -7
  84. package/dist/index.js +0 -73
  85. package/dist/shared/config/index.d.ts +0 -13
  86. package/dist/shared/config/index.js +0 -10
  87. package/dist/shared/format/index.d.ts +0 -13
  88. package/dist/shared/format/index.js +0 -24
  89. package/dist/shared/fs/index.d.ts +0 -7
  90. package/dist/shared/fs/index.js +0 -16
  91. package/dist/shared/fsp/index.d.ts +0 -27
  92. package/dist/shared/fsp/index.js +0 -38
  93. package/dist/shared/generator/field-definitions.d.ts +0 -12
  94. package/dist/shared/generator/field-definitions.js +0 -12
  95. package/dist/shared/helper/ast-parser.d.ts +0 -3
  96. package/dist/shared/helper/ast-parser.js +0 -202
  97. package/dist/shared/helper/build-schema-extractor.d.ts +0 -25
  98. package/dist/shared/helper/build-schema-extractor.js +0 -33
  99. package/dist/shared/helper/create-extract-field-from-property.d.ts +0 -15
  100. package/dist/shared/helper/create-extract-field-from-property.js +0 -20
  101. package/dist/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
  102. package/dist/shared/helper/create-extract-fields-from-call-expression.js +0 -14
  103. package/dist/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
  104. package/dist/shared/helper/create-extract-relation-field-from-property.js +0 -27
  105. package/dist/shared/helper/extract-schemas.d.ts +0 -133
  106. package/dist/shared/helper/extract-schemas.js +0 -445
  107. package/dist/shared/helper/file-writer.d.ts +0 -3
  108. package/dist/shared/helper/file-writer.js +0 -25
  109. package/dist/shared/helper/find-object-literal-expression.d.ts +0 -12
  110. package/dist/shared/helper/find-object-literal-expression.js +0 -31
  111. package/dist/shared/helper/find-object-literalIn-args.d.ts +0 -2
  112. package/dist/shared/helper/find-object-literalIn-args.js +0 -8
  113. package/dist/shared/helper/is-relation-function.d.ts +0 -10
  114. package/dist/shared/helper/is-relation-function.js +0 -16
  115. package/dist/shared/types.d.ts +0 -9
  116. package/dist/shared/types.js +0 -1
  117. package/dist/shared/utils/capitalize.d.ts +0 -18
  118. package/dist/shared/utils/capitalize.js +0 -20
  119. package/dist/shared/utils/compose.d.ts +0 -101
  120. package/dist/shared/utils/compose.js +0 -124
  121. package/dist/shared/utils/file.d.ts +0 -92
  122. package/dist/shared/utils/file.js +0 -177
  123. package/dist/shared/utils/functional.d.ts +0 -118
  124. package/dist/shared/utils/functional.js +0 -96
  125. package/dist/shared/utils/index.d.ts +0 -20
  126. package/dist/shared/utils/index.js +0 -48
  127. package/dist/shared/utils/string-utils.d.ts +0 -8
  128. package/dist/shared/utils/string-utils.js +0 -28
  129. package/dist/shared/utils/types.d.ts +0 -32
  130. package/dist/shared/utils/types.js +0 -2
  131. package/dist/shared/utils/validation-utils.d.ts +0 -8
  132. package/dist/shared/utils/validation-utils.js +0 -25
  133. package/dist/src/config/index.d.ts +0 -18
  134. package/dist/src/config/index.js +0 -13
  135. package/dist/src/generator/mermaid-er/core/extract-relations.d.ts +0 -8
  136. package/dist/src/generator/mermaid-er/core/extract-relations.js +0 -12
  137. package/dist/src/generator/mermaid-er/generator/er-content.d.ts +0 -9
  138. package/dist/src/generator/mermaid-er/generator/er-content.js +0 -25
  139. package/dist/src/generator/mermaid-er/generator/index.d.ts +0 -2
  140. package/dist/src/generator/mermaid-er/generator/index.js +0 -2
  141. package/dist/src/generator/mermaid-er/generator/relation-line.d.ts +0 -8
  142. package/dist/src/generator/mermaid-er/generator/relation-line.js +0 -14
  143. package/dist/src/generator/mermaid-er/index.d.ts +0 -6
  144. package/dist/src/generator/mermaid-er/index.js +0 -16
  145. package/dist/src/generator/mermaid-er/relationship/build-relation-line.d.ts +0 -15
  146. package/dist/src/generator/mermaid-er/relationship/build-relation-line.js +0 -35
  147. package/dist/src/generator/mermaid-er/types.d.ts +0 -21
  148. package/dist/src/generator/mermaid-er/types.js +0 -1
  149. package/dist/src/generator/mermaid-er/validator/index.d.ts +0 -4
  150. package/dist/src/generator/mermaid-er/validator/index.js +0 -4
  151. package/dist/src/generator/mermaid-er/validator/is-relationship.d.ts +0 -8
  152. package/dist/src/generator/mermaid-er/validator/is-relationship.js +0 -9
  153. package/dist/src/generator/mermaid-er/validator/parse-relation-line.d.ts +0 -13
  154. package/dist/src/generator/mermaid-er/validator/parse-relation-line.js +0 -21
  155. package/dist/src/generator/mermaid-er/validator/parse-table-info.d.ts +0 -8
  156. package/dist/src/generator/mermaid-er/validator/parse-table-info.js +0 -91
  157. package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.d.ts +0 -7
  158. package/dist/src/generator/mermaid-er/validator/remove-duplicate-relations.js +0 -9
  159. package/dist/src/generator/valibot/generator/infer-input.d.ts +0 -5
  160. package/dist/src/generator/valibot/generator/infer-input.js +0 -8
  161. package/dist/src/generator/valibot/generator/valibot-code.d.ts +0 -14
  162. package/dist/src/generator/valibot/generator/valibot-code.js +0 -16
  163. package/dist/src/generator/valibot/generator/valibot.d.ts +0 -13
  164. package/dist/src/generator/valibot/generator/valibot.js +0 -11
  165. package/dist/src/generator/valibot/index.d.ts +0 -9
  166. package/dist/src/generator/valibot/index.js +0 -34
  167. package/dist/src/generator/zod/generator/infer.d.ts +0 -5
  168. package/dist/src/generator/zod/generator/infer.js +0 -8
  169. package/dist/src/generator/zod/generator/zod-code.d.ts +0 -16
  170. package/dist/src/generator/zod/generator/zod-code.js +0 -18
  171. package/dist/src/generator/zod/generator/zod.d.ts +0 -15
  172. package/dist/src/generator/zod/generator/zod.js +0 -12
  173. package/dist/src/generator/zod/index.d.ts +0 -10
  174. package/dist/src/generator/zod/index.js +0 -40
  175. package/dist/src/index.d.ts +0 -10
  176. package/dist/src/index.js +0 -35
  177. package/dist/src/shared/format/index.d.ts +0 -2
  178. package/dist/src/shared/format/index.js +0 -10
  179. package/dist/src/shared/fs/index.d.ts +0 -2
  180. package/dist/src/shared/fs/index.js +0 -10
  181. package/dist/src/shared/fsp/index.d.ts +0 -3
  182. package/dist/src/shared/fsp/index.js +0 -8
  183. package/dist/src/shared/generator/field-definitions.d.ts +0 -12
  184. package/dist/src/shared/generator/field-definitions.js +0 -12
  185. package/dist/src/shared/helper/build-schema-extractor.d.ts +0 -25
  186. package/dist/src/shared/helper/build-schema-extractor.js +0 -33
  187. package/dist/src/shared/helper/create-extract-field-from-property.d.ts +0 -15
  188. package/dist/src/shared/helper/create-extract-field-from-property.js +0 -20
  189. package/dist/src/shared/helper/create-extract-fields-from-call-expression.d.ts +0 -14
  190. package/dist/src/shared/helper/create-extract-fields-from-call-expression.js +0 -14
  191. package/dist/src/shared/helper/create-extract-relation-field-from-property.d.ts +0 -12
  192. package/dist/src/shared/helper/create-extract-relation-field-from-property.js +0 -27
  193. package/dist/src/shared/helper/extract-schemas.d.ts +0 -16
  194. package/dist/src/shared/helper/extract-schemas.js +0 -19
  195. package/dist/src/shared/helper/find-object-literal-expression.d.ts +0 -12
  196. package/dist/src/shared/helper/find-object-literal-expression.js +0 -31
  197. package/dist/src/shared/helper/find-object-literalIn-args.d.ts +0 -2
  198. package/dist/src/shared/helper/find-object-literalIn-args.js +0 -8
  199. package/dist/src/shared/helper/is-relation-function.d.ts +0 -10
  200. package/dist/src/shared/helper/is-relation-function.js +0 -16
  201. package/dist/src/shared/utils/index.d.ts +0 -33
  202. package/dist/src/shared/utils/index.js +0 -61
  203. package/dist/utils/index.d.ts +0 -144
  204. package/dist/utils/index.js +0 -250
@@ -1,8 +0,0 @@
1
- export function findObjectLiteralInArgs(call, finder) {
2
- for (const arg of call.getArguments()) {
3
- const obj = finder(arg);
4
- if (obj)
5
- return obj;
6
- }
7
- return null;
8
- }
@@ -1,10 +0,0 @@
1
- import type { CallExpression } from 'ts-morph';
2
- /**
3
- * Determines whether a given `CallExpression` is a relation-related function call.
4
- *
5
- * This checks if the function name is either `"relations"` or contains the substring `"relation"`.
6
- *
7
- * @param callExpr - The call expression node to check.
8
- * @returns `true` if the function is a relation function; otherwise, `false`.
9
- */
10
- export declare function isRelationFunctionCall(callExpr: CallExpression): boolean;
@@ -1,16 +0,0 @@
1
- import { Node } from 'ts-morph';
2
- /**
3
- * Determines whether a given `CallExpression` is a relation-related function call.
4
- *
5
- * This checks if the function name is either `"relations"` or contains the substring `"relation"`.
6
- *
7
- * @param callExpr - The call expression node to check.
8
- * @returns `true` if the function is a relation function; otherwise, `false`.
9
- */
10
- export function isRelationFunctionCall(callExpr) {
11
- const expression = callExpr.getExpression();
12
- if (!Node.isIdentifier(expression))
13
- return false;
14
- const functionName = expression.getText();
15
- return functionName === 'relations' || functionName.includes('relation');
16
- }
@@ -1,9 +0,0 @@
1
- export type SchemaField = {
2
- name: string;
3
- definition: string;
4
- description?: string;
5
- };
6
- export type Schema = {
7
- name: string;
8
- fields: SchemaField[];
9
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- /**
2
- * Capitalizes the first letter of a string
3
- *
4
- * @function capitalize
5
- * @param str - String to capitalize
6
- * @returns String with first letter capitalized
7
- *
8
- * @example
9
- * capitalize('posts') // Returns: 'Posts'
10
- * capitalize('user') // Returns: 'User'
11
- * capitalize('api') // Returns: 'Api'
12
- *
13
- * @remarks
14
- * - Leaves rest of the string unchanged
15
- * - Returns empty string if input is empty
16
- * - Commonly used for generating type names and class names
17
- */
18
- export declare function capitalize(str: string): string;
@@ -1,20 +0,0 @@
1
- /**
2
- * Capitalizes the first letter of a string
3
- *
4
- * @function capitalize
5
- * @param str - String to capitalize
6
- * @returns String with first letter capitalized
7
- *
8
- * @example
9
- * capitalize('posts') // Returns: 'Posts'
10
- * capitalize('user') // Returns: 'User'
11
- * capitalize('api') // Returns: 'Api'
12
- *
13
- * @remarks
14
- * - Leaves rest of the string unchanged
15
- * - Returns empty string if input is empty
16
- * - Commonly used for generating type names and class names
17
- */
18
- export function capitalize(str) {
19
- return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
20
- }
@@ -1,101 +0,0 @@
1
- /**
2
- * Functional composition utilities for cleaner code
3
- *
4
- * @module compose
5
- */
6
- /**
7
- * Pipes a value through a series of functions from left to right
8
- *
9
- * @template T - Initial value type
10
- * @param value - The initial value
11
- * @param fns - Functions to apply in sequence
12
- * @returns The final transformed value
13
- *
14
- * @example
15
- * const result = pipe(
16
- * "hello",
17
- * str => str.toUpperCase(),
18
- * str => str + "!",
19
- * str => str.repeat(2)
20
- * ) // "HELLO!HELLO!"
21
- */
22
- export declare function pipe<T>(value: T, ...fns: Array<(arg: any) => any>): any
23
- /**
24
- * Composes functions from right to left
25
- *
26
- * @param fns - Functions to compose
27
- * @returns A new function that applies all functions in sequence
28
- *
29
- * @example
30
- * const transform = compose(
31
- * str => str.repeat(2),
32
- * str => str + "!",
33
- * str => str.toUpperCase()
34
- * )
35
- * transform("hello") // "HELLO!HELLO!"
36
- */
37
- export declare function compose<T>(...fns: Array<(arg: any) => any>): (arg: T) => any
38
- /**
39
- * Maybe monad for handling nullable values
40
- *
41
- * @template T - The wrapped value type
42
- */
43
- export declare class Maybe<T> {
44
- private value
45
- private constructor()
46
- /**
47
- * Creates a Maybe from a value
48
- */
49
- static of<T>(value: T | null | undefined): Maybe<T>
50
- /**
51
- * Creates a Maybe with no value
52
- */
53
- static none<T>(): Maybe<T>
54
- /**
55
- * Maps a function over the Maybe value
56
- */
57
- map<U>(fn: (value: T) => U): Maybe<U>
58
- /**
59
- * Flat maps a function that returns a Maybe
60
- */
61
- flatMap<U>(fn: (value: T) => Maybe<U>): Maybe<U>
62
- /**
63
- * Returns the value or a default
64
- */
65
- getOrElse(defaultValue: T): T
66
- /**
67
- * Returns the value or null
68
- */
69
- getOrNull(): T | null
70
- /**
71
- * Checks if the Maybe has a value
72
- */
73
- isSome(): boolean
74
- /**
75
- * Checks if the Maybe has no value
76
- */
77
- isNone(): boolean
78
- }
79
- /**
80
- * Helper function to create a Maybe
81
- */
82
- export declare const maybe: <T>(value: T | null | undefined) => Maybe<T>
83
- /**
84
- * Applies a function only if the condition is true
85
- *
86
- * @param condition - The condition to check
87
- * @param fn - The function to apply
88
- * @returns A function that conditionally applies the transformation
89
- */
90
- export declare function when<T>(condition: boolean, fn: (value: T) => T): (value: T) => T
91
- /**
92
- * Applies a function only if the predicate returns true
93
- *
94
- * @param predicate - The predicate function
95
- * @param fn - The function to apply
96
- * @returns A function that conditionally applies the transformation
97
- */
98
- export declare function whenPredicate<T>(
99
- predicate: (value: T) => boolean,
100
- fn: (value: T) => T,
101
- ): (value: T) => T
@@ -1,124 +0,0 @@
1
- /**
2
- * Functional composition utilities for cleaner code
3
- *
4
- * @module compose
5
- */
6
- /**
7
- * Pipes a value through a series of functions from left to right
8
- *
9
- * @template T - Initial value type
10
- * @param value - The initial value
11
- * @param fns - Functions to apply in sequence
12
- * @returns The final transformed value
13
- *
14
- * @example
15
- * const result = pipe(
16
- * "hello",
17
- * str => str.toUpperCase(),
18
- * str => str + "!",
19
- * str => str.repeat(2)
20
- * ) // "HELLO!HELLO!"
21
- */
22
- export function pipe(value, ...fns) {
23
- return fns.reduce((acc, fn) => fn(acc), value);
24
- }
25
- /**
26
- * Composes functions from right to left
27
- *
28
- * @param fns - Functions to compose
29
- * @returns A new function that applies all functions in sequence
30
- *
31
- * @example
32
- * const transform = compose(
33
- * str => str.repeat(2),
34
- * str => str + "!",
35
- * str => str.toUpperCase()
36
- * )
37
- * transform("hello") // "HELLO!HELLO!"
38
- */
39
- export function compose(...fns) {
40
- return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
41
- }
42
- /**
43
- * Maybe monad for handling nullable values
44
- *
45
- * @template T - The wrapped value type
46
- */
47
- export class Maybe {
48
- value;
49
- constructor(value) {
50
- this.value = value;
51
- }
52
- /**
53
- * Creates a Maybe from a value
54
- */
55
- static of(value) {
56
- return new Maybe(value);
57
- }
58
- /**
59
- * Creates a Maybe with no value
60
- */
61
- static none() {
62
- return new Maybe(null);
63
- }
64
- /**
65
- * Maps a function over the Maybe value
66
- */
67
- map(fn) {
68
- return this.value == null ? Maybe.none() : Maybe.of(fn(this.value));
69
- }
70
- /**
71
- * Flat maps a function that returns a Maybe
72
- */
73
- flatMap(fn) {
74
- return this.value == null ? Maybe.none() : fn(this.value);
75
- }
76
- /**
77
- * Returns the value or a default
78
- */
79
- getOrElse(defaultValue) {
80
- return this.value == null ? defaultValue : this.value;
81
- }
82
- /**
83
- * Returns the value or null
84
- */
85
- getOrNull() {
86
- return this.value == null ? null : this.value;
87
- }
88
- /**
89
- * Checks if the Maybe has a value
90
- */
91
- isSome() {
92
- return this.value != null;
93
- }
94
- /**
95
- * Checks if the Maybe has no value
96
- */
97
- isNone() {
98
- return this.value == null;
99
- }
100
- }
101
- /**
102
- * Helper function to create a Maybe
103
- */
104
- export const maybe = (value) => Maybe.of(value);
105
- /**
106
- * Applies a function only if the condition is true
107
- *
108
- * @param condition - The condition to check
109
- * @param fn - The function to apply
110
- * @returns A function that conditionally applies the transformation
111
- */
112
- export function when(condition, fn) {
113
- return condition ? fn : (value) => value;
114
- }
115
- /**
116
- * Applies a function only if the predicate returns true
117
- *
118
- * @param predicate - The predicate function
119
- * @param fn - The function to apply
120
- * @returns A function that conditionally applies the transformation
121
- */
122
- export function whenPredicate(predicate, fn) {
123
- return (value) => (predicate(value) ? fn(value) : value);
124
- }
@@ -1,92 +0,0 @@
1
- import { Result } from 'neverthrow'
2
- export type FileError =
3
- | {
4
- type: 'FILE_NOT_FOUND'
5
- message: string
6
- }
7
- | {
8
- type: 'PERMISSION_DENIED'
9
- message: string
10
- }
11
- | {
12
- type: 'WRITE_ERROR'
13
- message: string
14
- }
15
- | {
16
- type: 'READ_ERROR'
17
- message: string
18
- }
19
- | {
20
- type: 'DIRECTORY_ERROR'
21
- message: string
22
- }
23
- /**
24
- * Read file synchronously
25
- */
26
- export declare function readFileSync(filePath: string): Result<string, FileError>
27
- /**
28
- * Read file asynchronously
29
- */
30
- export declare function readFileAsync(filePath: string): Promise<Result<string, FileError>>
31
- /**
32
- * Write file synchronously
33
- */
34
- export declare function writeFileSync(filePath: string, content: string): Result<void, FileError>
35
- /**
36
- * Write file asynchronously
37
- */
38
- export declare function writeFileAsync(
39
- filePath: string,
40
- content: string,
41
- ): Promise<Result<void, FileError>>
42
- /**
43
- * Create directory
44
- */
45
- export declare function ensureDirectorySync(dirPath: string): Result<void, FileError>
46
- /**
47
- * Create directory asynchronously
48
- */
49
- export declare function ensureDirectoryAsync(dirPath: string): Promise<Result<void, FileError>>
50
- /**
51
- * Check if file exists
52
- */
53
- export declare function fileExists(filePath: string): boolean
54
- /**
55
- * Get directory path from file path
56
- */
57
- export declare function getDirectoryPath(filePath: string): string
58
- /**
59
- * Write file safely (including directory creation)
60
- */
61
- export declare function safeWriteFileSync(
62
- filePath: string,
63
- content: string,
64
- ): Result<void, FileError>
65
- /**
66
- * Write file safely asynchronously (including directory creation)
67
- */
68
- export declare function safeWriteFileAsync(
69
- filePath: string,
70
- content: string,
71
- ): Promise<Result<void, FileError>>
72
- /**
73
- * Function to transform file content
74
- */
75
- export declare function transformFileContent<T>(
76
- content: string,
77
- transformer: (content: string) => Result<T, FileError>,
78
- ): Result<T, FileError>
79
- /**
80
- * Read file, transform it, and return result
81
- */
82
- export declare function readAndTransformFileSync<T>(
83
- filePath: string,
84
- transformer: (content: string) => Result<T, FileError>,
85
- ): Result<T, FileError>
86
- /**
87
- * Read file asynchronously, transform it, and return result
88
- */
89
- export declare function readAndTransformFileAsync<T>(
90
- filePath: string,
91
- transformer: (content: string) => Promise<Result<T, FileError>>,
92
- ): Promise<Result<T, FileError>>
@@ -1,177 +0,0 @@
1
- // Test run
2
- // pnpm vitest run src/shared/utils/file.test.ts
3
- import fs from 'node:fs';
4
- import fsp from 'node:fs/promises';
5
- import path from 'node:path';
6
- import { Result, ok, err } from 'neverthrow';
7
- import { tryCatch, tryCatchAsync } from './functional.js';
8
- /**
9
- * Read file synchronously
10
- */
11
- export function readFileSync(filePath) {
12
- return tryCatch(() => fs.readFileSync(filePath, 'utf-8'), (error) => {
13
- const err = error;
14
- if (err.code === 'ENOENT') {
15
- return {
16
- type: 'FILE_NOT_FOUND',
17
- message: `File not found: ${filePath}`,
18
- };
19
- }
20
- if (err.code === 'EACCES') {
21
- return {
22
- type: 'PERMISSION_DENIED',
23
- message: `Permission denied: ${filePath}`,
24
- };
25
- }
26
- return {
27
- type: 'READ_ERROR',
28
- message: `Failed to read file: ${filePath} - ${err.message}`,
29
- };
30
- });
31
- }
32
- /**
33
- * Read file asynchronously
34
- */
35
- export async function readFileAsync(filePath) {
36
- return tryCatchAsync(() => fsp.readFile(filePath, 'utf-8'), (error) => {
37
- const err = error;
38
- if (err.code === 'ENOENT') {
39
- return {
40
- type: 'FILE_NOT_FOUND',
41
- message: `File not found: ${filePath}`,
42
- };
43
- }
44
- if (err.code === 'EACCES') {
45
- return {
46
- type: 'PERMISSION_DENIED',
47
- message: `Permission denied: ${filePath}`,
48
- };
49
- }
50
- return {
51
- type: 'READ_ERROR',
52
- message: `Failed to read file: ${filePath} - ${err.message}`,
53
- };
54
- });
55
- }
56
- /**
57
- * Write file synchronously
58
- */
59
- export function writeFileSync(filePath, content) {
60
- return tryCatch(() => fs.writeFileSync(filePath, content, 'utf-8'), (error) => {
61
- const err = error;
62
- if (err.code === 'EACCES') {
63
- return {
64
- type: 'PERMISSION_DENIED',
65
- message: `Permission denied: ${filePath}`,
66
- };
67
- }
68
- return {
69
- type: 'WRITE_ERROR',
70
- message: `Failed to write file: ${filePath} - ${err.message}`,
71
- };
72
- });
73
- }
74
- /**
75
- * Write file asynchronously
76
- */
77
- export async function writeFileAsync(filePath, content) {
78
- return tryCatchAsync(() => fsp.writeFile(filePath, content, 'utf-8'), (error) => {
79
- const err = error;
80
- if (err.code === 'EACCES') {
81
- return {
82
- type: 'PERMISSION_DENIED',
83
- message: `Permission denied: ${filePath}`,
84
- };
85
- }
86
- return {
87
- type: 'WRITE_ERROR',
88
- message: `Failed to write file: ${filePath} - ${err.message}`,
89
- };
90
- });
91
- }
92
- /**
93
- * Create directory
94
- */
95
- export function ensureDirectorySync(dirPath) {
96
- return tryCatch(() => {
97
- fs.mkdirSync(dirPath, { recursive: true });
98
- return undefined;
99
- }, (error) => {
100
- const err = error;
101
- return {
102
- type: 'DIRECTORY_ERROR',
103
- message: `Failed to create directory: ${dirPath} - ${err.message}`,
104
- };
105
- });
106
- }
107
- /**
108
- * Create directory asynchronously
109
- */
110
- export async function ensureDirectoryAsync(dirPath) {
111
- return tryCatchAsync(async () => {
112
- await fsp.mkdir(dirPath, { recursive: true });
113
- return undefined;
114
- }, (error) => {
115
- const err = error;
116
- return {
117
- type: 'DIRECTORY_ERROR',
118
- message: `Failed to create directory: ${dirPath} - ${err.message}`,
119
- };
120
- });
121
- }
122
- /**
123
- * Check if file exists
124
- */
125
- export function fileExists(filePath) {
126
- return fs.existsSync(filePath);
127
- }
128
- /**
129
- * Get directory path from file path
130
- */
131
- export function getDirectoryPath(filePath) {
132
- return path.dirname(filePath);
133
- }
134
- /**
135
- * Write file safely (including directory creation)
136
- */
137
- export function safeWriteFileSync(filePath, content) {
138
- const dirPath = getDirectoryPath(filePath);
139
- const createDirResult = ensureDirectorySync(dirPath);
140
- if (createDirResult.isErr()) {
141
- return createDirResult;
142
- }
143
- return writeFileSync(filePath, content);
144
- }
145
- /**
146
- * Write file safely asynchronously (including directory creation)
147
- */
148
- export async function safeWriteFileAsync(filePath, content) {
149
- const dirPath = getDirectoryPath(filePath);
150
- const createDirResult = await ensureDirectoryAsync(dirPath);
151
- if (createDirResult.isErr()) {
152
- return createDirResult;
153
- }
154
- return writeFileAsync(filePath, content);
155
- }
156
- /**
157
- * Function to transform file content
158
- */
159
- export function transformFileContent(content, transformer) {
160
- return transformer(content);
161
- }
162
- /**
163
- * Read file, transform it, and return result
164
- */
165
- export function readAndTransformFileSync(filePath, transformer) {
166
- return readFileSync(filePath).andThen(transformer);
167
- }
168
- /**
169
- * Read file asynchronously, transform it, and return result
170
- */
171
- export async function readAndTransformFileAsync(filePath, transformer) {
172
- const readResult = await readFileAsync(filePath);
173
- if (readResult.isErr()) {
174
- return err(readResult.error);
175
- }
176
- return transformer(readResult.value);
177
- }
@@ -1,118 +0,0 @@
1
- import { Result } from 'neverthrow'
2
- /**
3
- * Functional programming utility functions
4
- */
5
- /**
6
- * Compose functions (right to left)
7
- * compose(f, g)(x) = f(g(x))
8
- */
9
- export declare function compose<A, B, C>(f: (b: B) => C, g: (a: A) => B): (a: A) => C
10
- /**
11
- * Pipeline functions (left to right)
12
- * pipe(x, f, g) = g(f(x))
13
- */
14
- export declare function pipe<A>(value: A): A
15
- export declare function pipe<A, B>(value: A, f1: (a: A) => B): B
16
- export declare function pipe<A, B, C>(value: A, f1: (a: A) => B, f2: (b: B) => C): C
17
- export declare function pipe<A, B, C, D>(
18
- value: A,
19
- f1: (a: A) => B,
20
- f2: (b: B) => C,
21
- f3: (c: C) => D,
22
- ): D
23
- export declare function pipe<A, B, C, D, E>(
24
- value: A,
25
- f1: (a: A) => B,
26
- f2: (b: B) => C,
27
- f3: (c: C) => D,
28
- f4: (d: D) => E,
29
- ): E
30
- export declare function pipe<T>(value: T, ...fns: Array<(x: T) => T>): T
31
- export declare function pipe<T, U>(value: T, f1: (x: T) => U, ...fns: Array<(x: U) => U>): U
32
- /**
33
- * Function composition using Result type
34
- */
35
- export declare function composeResult<A, B, C, E>(
36
- f: (b: B) => Result<C, E>,
37
- g: (a: A) => Result<B, E>,
38
- ): (a: A) => Result<C, E>
39
- /**
40
- * Pipeline processing using Result type
41
- */
42
- export declare function pipeResult<A, E>(value: Result<A, E>): Result<A, E>
43
- export declare function pipeResult<A, B, E>(
44
- value: Result<A, E>,
45
- f1: (a: A) => Result<B, E>,
46
- ): Result<B, E>
47
- export declare function pipeResult<A, B, C, E>(
48
- value: Result<A, E>,
49
- f1: (a: A) => Result<B, E>,
50
- f2: (b: B) => Result<C, E>,
51
- ): Result<C, E>
52
- export declare function pipeResult<A, B, C, D, E>(
53
- value: Result<A, E>,
54
- f1: (a: A) => Result<B, E>,
55
- f2: (b: B) => Result<C, E>,
56
- f3: (c: C) => Result<D, E>,
57
- ): Result<D, E>
58
- export declare function pipeResult<A, B, C, D, F, E>(
59
- value: Result<A, E>,
60
- f1: (a: A) => Result<B, E>,
61
- f2: (b: B) => Result<C, E>,
62
- f3: (c: C) => Result<D, E>,
63
- f4: (d: D) => Result<F, E>,
64
- ): Result<F, E>
65
- /**
66
- * Wrap operations with side effects in Result type
67
- */
68
- export declare function tryCatch<T, E = Error>(
69
- fn: () => T,
70
- errorHandler?: (error: unknown) => E,
71
- ): Result<T, E>
72
- /**
73
- * Wrap asynchronous operations with side effects in Result type
74
- */
75
- export declare function tryCatchAsync<T, E = Error>(
76
- fn: () => Promise<T>,
77
- errorHandler?: (error: unknown) => E,
78
- ): Promise<Result<T, E>>
79
- /**
80
- * Apply Result type function to each element of array, return result only if all succeed
81
- */
82
- export declare function mapResult<A, B, E>(
83
- items: A[],
84
- fn: (item: A) => Result<B, E>,
85
- ): Result<B[], E>
86
- /**
87
- * Return Result type based on condition
88
- */
89
- export declare function fromPredicate<T, E>(
90
- predicate: (value: T) => boolean,
91
- value: T,
92
- errorFactory: (value: T) => E,
93
- ): Result<T, E>
94
- /**
95
- * Maybe-like null/undefined check
96
- */
97
- export declare function fromNullable<T, E>(
98
- value: T | null | undefined,
99
- errorFactory: () => E,
100
- ): Result<T, E>
101
- /**
102
- * Combine multiple Result types
103
- */
104
- export declare function combine<T1, T2, E>(
105
- r1: Result<T1, E>,
106
- r2: Result<T2, E>,
107
- ): Result<[T1, T2], E>
108
- export declare function combine<T1, T2, T3, E>(
109
- r1: Result<T1, E>,
110
- r2: Result<T2, E>,
111
- r3: Result<T3, E>,
112
- ): Result<[T1, T2, T3], E>
113
- export declare function combine<T1, T2, T3, T4, E>(
114
- r1: Result<T1, E>,
115
- r2: Result<T2, E>,
116
- r3: Result<T3, E>,
117
- r4: Result<T4, E>,
118
- ): Result<[T1, T2, T3, T4], E>