@wentools/simmer 0.1.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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/esm/debounce/debounce.d.ts +15 -0
  4. package/esm/debounce/debounce.d.ts.map +1 -0
  5. package/esm/debounce/debounce.js +61 -0
  6. package/esm/debounce/mod.d.ts +2 -0
  7. package/esm/debounce/mod.d.ts.map +1 -0
  8. package/esm/debounce/mod.js +1 -0
  9. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts +38 -0
  10. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.js +38 -0
  12. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts +2 -0
  13. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.js +1 -0
  15. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts +11 -0
  16. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.js +14 -0
  18. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts +2 -0
  19. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.js +1 -0
  21. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts +156 -0
  22. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.js +65 -0
  24. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts +2 -0
  25. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts.map +1 -0
  26. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.js +1 -0
  27. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts +28 -0
  28. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts.map +1 -0
  29. package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.js +30 -0
  30. package/esm/eventual/eventual.d.ts +32 -0
  31. package/esm/eventual/eventual.d.ts.map +1 -0
  32. package/esm/eventual/eventual.js +47 -0
  33. package/esm/eventual/mod.d.ts +3 -0
  34. package/esm/eventual/mod.d.ts.map +1 -0
  35. package/esm/eventual/mod.js +1 -0
  36. package/esm/mod.d.ts +7 -0
  37. package/esm/mod.d.ts.map +1 -0
  38. package/esm/mod.js +4 -0
  39. package/esm/package.json +3 -0
  40. package/esm/retry/delay.d.ts +8 -0
  41. package/esm/retry/delay.d.ts.map +1 -0
  42. package/esm/retry/delay.js +28 -0
  43. package/esm/retry/mod.d.ts +5 -0
  44. package/esm/retry/mod.d.ts.map +1 -0
  45. package/esm/retry/mod.js +3 -0
  46. package/esm/retry/retry.d.ts +23 -0
  47. package/esm/retry/retry.d.ts.map +1 -0
  48. package/esm/retry/retry.js +128 -0
  49. package/esm/retry/types.d.ts +59 -0
  50. package/esm/retry/types.d.ts.map +1 -0
  51. package/esm/retry/types.js +8 -0
  52. package/esm/sleep/mod.d.ts +2 -0
  53. package/esm/sleep/mod.d.ts.map +1 -0
  54. package/esm/sleep/mod.js +1 -0
  55. package/esm/sleep/sleep.d.ts +6 -0
  56. package/esm/sleep/sleep.d.ts.map +1 -0
  57. package/esm/sleep/sleep.js +7 -0
  58. package/package.json +33 -0
  59. package/script/debounce/debounce.d.ts +15 -0
  60. package/script/debounce/debounce.d.ts.map +1 -0
  61. package/script/debounce/debounce.js +65 -0
  62. package/script/debounce/mod.d.ts +2 -0
  63. package/script/debounce/mod.d.ts.map +1 -0
  64. package/script/debounce/mod.js +6 -0
  65. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts +38 -0
  66. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts.map +1 -0
  67. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.js +41 -0
  68. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts +2 -0
  69. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts.map +1 -0
  70. package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.js +5 -0
  71. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts +11 -0
  72. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts.map +1 -0
  73. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.js +17 -0
  74. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts +2 -0
  75. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts.map +1 -0
  76. package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.js +5 -0
  77. package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts +156 -0
  78. package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts.map +1 -0
  79. package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.js +77 -0
  80. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts +2 -0
  81. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts.map +1 -0
  82. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.js +5 -0
  83. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts +28 -0
  84. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts.map +1 -0
  85. package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.js +33 -0
  86. package/script/eventual/eventual.d.ts +32 -0
  87. package/script/eventual/eventual.d.ts.map +1 -0
  88. package/script/eventual/eventual.js +53 -0
  89. package/script/eventual/mod.d.ts +3 -0
  90. package/script/eventual/mod.d.ts.map +1 -0
  91. package/script/eventual/mod.js +8 -0
  92. package/script/mod.d.ts +7 -0
  93. package/script/mod.d.ts.map +1 -0
  94. package/script/mod.js +20 -0
  95. package/script/package.json +3 -0
  96. package/script/retry/delay.d.ts +8 -0
  97. package/script/retry/delay.d.ts.map +1 -0
  98. package/script/retry/delay.js +32 -0
  99. package/script/retry/mod.d.ts +5 -0
  100. package/script/retry/mod.d.ts.map +1 -0
  101. package/script/retry/mod.js +12 -0
  102. package/script/retry/retry.d.ts +23 -0
  103. package/script/retry/retry.d.ts.map +1 -0
  104. package/script/retry/retry.js +134 -0
  105. package/script/retry/types.d.ts +59 -0
  106. package/script/retry/types.d.ts.map +1 -0
  107. package/script/retry/types.js +11 -0
  108. package/script/sleep/mod.d.ts +2 -0
  109. package/script/sleep/mod.d.ts.map +1 -0
  110. package/script/sleep/mod.js +5 -0
  111. package/script/sleep/sleep.d.ts +6 -0
  112. package/script/sleep/sleep.d.ts.map +1 -0
  113. package/script/sleep/sleep.js +10 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wentools
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @wentools/simmer
2
+
3
+ Async control flow primitives: debounce, retry, eventual, sleep.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # JSR (Deno)
9
+ deno add jsr:@wentools/simmer
10
+
11
+ # npm
12
+ npm install @wentools/simmer
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Sleep
18
+
19
+ ```typescript
20
+ import { sleep } from '@wentools/simmer'
21
+
22
+ await sleep(1000) // wait 1 second
23
+ ```
24
+
25
+ ### Debounce
26
+
27
+ ```typescript
28
+ import { debounce, debounceAsync } from '@wentools/simmer'
29
+
30
+ // Synchronous debounce
31
+ const debouncedSearch = debounce((query: string) => {
32
+ console.log('Searching:', query)
33
+ }, 300)
34
+
35
+ // Async debounce - cancels stale calls
36
+ const debouncedFetch = debounceAsync(async (query: string) => {
37
+ const response = await fetch(`/api/search?q=${query}`)
38
+ return response.json()
39
+ }, 300)
40
+ ```
41
+
42
+ ### Retry
43
+
44
+ ```typescript
45
+ import { withRetry, retryPromise } from '@wentools/simmer'
46
+
47
+ // Retry a Result-returning function
48
+ const result = await withRetry(
49
+ () => fetchUser(userId),
50
+ { maxAttempts: 3, initialDelayMs: 1000, backoffStrategy: 'exponential' }
51
+ )
52
+
53
+ // Retry a Promise-returning function
54
+ const result = await retryPromise(
55
+ () => fetch('/api/data').then(r => r.json()),
56
+ { maxAttempts: 3, initialDelayMs: 500 }
57
+ )
58
+ ```
59
+
60
+ ### Eventual (Stale-While-Revalidate)
61
+
62
+ ```typescript
63
+ import { eventual, mapEventual, combineEventual } from '@wentools/simmer'
64
+
65
+ // Return cached data immediately, refresh in background
66
+ const result = eventual(cachedData, fetchFreshData())
67
+
68
+ result.current // cached data (available now)
69
+ result.fresh // Promise<fresh data> | null
70
+ result.isStale // true if fresh !== null
71
+
72
+ // Transform values
73
+ const mapped = mapEventual(result, data => data.map(formatItem))
74
+
75
+ // Combine multiple
76
+ const combined = combineEventual({
77
+ users: eventual(cachedUsers, fetchUsers()),
78
+ count: eventual(cachedCount, fetchCount()),
79
+ })
80
+ ```
81
+
82
+ ## API
83
+
84
+ ### Sleep
85
+ - `sleep(ms)` - Promise that resolves after `ms` milliseconds
86
+
87
+ ### Debounce
88
+ - `debounce(fn, wait)` - Debounce a synchronous function
89
+ - `debounceAsync(fn, wait)` - Debounce an async function with promise cancellation
90
+
91
+ ### Retry
92
+ - `withRetry(fn, options?)` - Retry a `Result`-returning function
93
+ - `retryPromise(fn, options?)` - Retry a `Promise`-returning function
94
+ - `makeRetryable(fn, options?)` - Create a retryable wrapper
95
+ - `withRetryMetadata(fn, options?)` - Retry with full execution tracking
96
+ - `calculateDelay(attempt, options)` - Calculate delay for a retry attempt
97
+ - `defaultRetryOptions` - Default retry configuration
98
+
99
+ ### Eventual
100
+ - `eventual(current, fresh)` - Create an `EventualResult`
101
+ - `eventualIf(current, isStale, getFresh)` - Lazily create fresh promise
102
+ - `mapEventual(result, fn)` - Transform both current and fresh values
103
+ - `combineEventual(results)` - Combine multiple `EventualResult`s
104
+
105
+ ## License
106
+
107
+ MIT
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Creates a debounced version of a synchronous function, which delays invoking
3
+ * the function until after `wait` milliseconds have elapsed since the last invocation.
4
+ */
5
+ declare const debounce: <TDebounceCallback extends (...args: any[]) => void>(func: TDebounceCallback, wait: number) => ((...args: Parameters<TDebounceCallback>) => void);
6
+ /**
7
+ * Creates a debounced version of an asynchronous function, which delays invoking
8
+ * the function until after `waitTime` milliseconds have elapsed since the last time
9
+ * the debounced function was invoked. The debounced function returns a promise
10
+ * that resolves with the return value of the original function, but only for the
11
+ * latest invocation.
12
+ */
13
+ declare const debounceAsync: <TAsyncFunction extends (...args: any[]) => Promise<any>>(asyncFunction: TAsyncFunction, waitTime: number) => ((...args: Parameters<TAsyncFunction>) => Promise<Awaited<ReturnType<TAsyncFunction>>>);
14
+ export { debounce, debounceAsync };
15
+ //# sourceMappingURL=debounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/debounce/debounce.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAA,MAAM,QAAQ,GAAI,iBAAiB,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EACnE,MAAM,iBAAiB,EACvB,MAAM,MAAM,KACV,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAYnD,CAAA;AAED;;;;;;GAMG;AAEH,QAAA,MAAM,aAAa,GAAI,cAAc,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC7E,eAAe,cAAc,EAC7B,UAAU,MAAM,KACd,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CA2CxF,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Creates a debounced version of a synchronous function, which delays invoking
3
+ * the function until after `wait` milliseconds have elapsed since the last invocation.
4
+ */
5
+ // deno-lint-ignore no-explicit-any
6
+ const debounce = (func, wait) => {
7
+ let timeoutId = null;
8
+ return (...args) => {
9
+ if (timeoutId !== null) {
10
+ clearTimeout(timeoutId);
11
+ }
12
+ timeoutId = setTimeout(() => {
13
+ func(...args);
14
+ }, wait);
15
+ };
16
+ };
17
+ /**
18
+ * Creates a debounced version of an asynchronous function, which delays invoking
19
+ * the function until after `waitTime` milliseconds have elapsed since the last time
20
+ * the debounced function was invoked. The debounced function returns a promise
21
+ * that resolves with the return value of the original function, but only for the
22
+ * latest invocation.
23
+ */
24
+ // deno-lint-ignore no-explicit-any
25
+ const debounceAsync = (asyncFunction, waitTime) => {
26
+ let timeoutId = null;
27
+ let latestCallId = 0;
28
+ let pendingPromises = [];
29
+ return (...args) => {
30
+ const callId = ++latestCallId;
31
+ if (timeoutId !== null) {
32
+ clearTimeout(timeoutId);
33
+ }
34
+ // Cancel all pending promises from previous calls
35
+ const promisesToCancel = [...pendingPromises];
36
+ pendingPromises = [];
37
+ promisesToCancel.forEach(({ reject }) => {
38
+ reject(new Error('Debounced call was cancelled'));
39
+ });
40
+ return new Promise((resolve, reject) => {
41
+ pendingPromises.push({ callId, resolve, reject });
42
+ timeoutId = setTimeout(async () => {
43
+ const promiseIndex = pendingPromises.findIndex((p) => p.callId === callId);
44
+ if (promiseIndex === -1) {
45
+ return;
46
+ }
47
+ const currentPromise = pendingPromises.splice(promiseIndex, 1)[0];
48
+ if (!currentPromise)
49
+ return;
50
+ try {
51
+ const result = await asyncFunction(...args);
52
+ currentPromise.resolve(result);
53
+ }
54
+ catch (error) {
55
+ currentPromise.reject(error);
56
+ }
57
+ }, waitTime);
58
+ });
59
+ };
60
+ };
61
+ export { debounce, debounceAsync };
@@ -0,0 +1,2 @@
1
+ export { debounce, debounceAsync } from './debounce.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/debounce/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1 @@
1
+ export { debounce, debounceAsync } from './debounce.js';
@@ -0,0 +1,38 @@
1
+ import { type Err } from 'neverthrow';
2
+ /**
3
+ * Create an Err Result with automatic literal type preservation
4
+ *
5
+ * Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
6
+ * No need for 'as const' - the type parameter is inferred as a literal!
7
+ *
8
+ * Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
9
+ *
10
+ * @example
11
+ * // ✅ Simple error
12
+ * return err('not_found', 'User not found')
13
+ * // Type: Err<never, { type: 'not_found', message: string }>
14
+ *
15
+ * @example
16
+ * // ✅ Error with additional properties
17
+ * return err('not_found', 'User not found', { userId: '123' })
18
+ * // Type: Err<never, { type: 'not_found', message: string, userId: string }>
19
+ *
20
+ * @example
21
+ * // ✅ Direct .error access (no narrowing needed)
22
+ * const error = err('not_found', 'User not found').error
23
+ * // error.type is 'not_found'
24
+ *
25
+ * @example
26
+ * // ✅ Error with complex additional data
27
+ * return err('validation_failed', 'Invalid input', {
28
+ * field: 'email',
29
+ * errors: ['Invalid format']
30
+ * })
31
+ * // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
32
+ */
33
+ declare const err: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => Err<never, {
34
+ type: TType;
35
+ message: string;
36
+ } & TAdditional>;
37
+ export { err };
38
+ //# sourceMappingURL=err.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/err/err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,GAAG,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,QAAA,MAAM,GAAG,GACR,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnE,MAAM,KAAK,EACX,SAAS,MAAM,EACf,aAAa,WAAW,KACtB,GAAG,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAKP,CAAA;AAErD,OAAO,EAAE,GAAG,EAAE,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { err as _Err } from 'neverthrow';
2
+ /**
3
+ * Create an Err Result with automatic literal type preservation
4
+ *
5
+ * Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
6
+ * No need for 'as const' - the type parameter is inferred as a literal!
7
+ *
8
+ * Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
9
+ *
10
+ * @example
11
+ * // ✅ Simple error
12
+ * return err('not_found', 'User not found')
13
+ * // Type: Err<never, { type: 'not_found', message: string }>
14
+ *
15
+ * @example
16
+ * // ✅ Error with additional properties
17
+ * return err('not_found', 'User not found', { userId: '123' })
18
+ * // Type: Err<never, { type: 'not_found', message: string, userId: string }>
19
+ *
20
+ * @example
21
+ * // ✅ Direct .error access (no narrowing needed)
22
+ * const error = err('not_found', 'User not found').error
23
+ * // error.type is 'not_found'
24
+ *
25
+ * @example
26
+ * // ✅ Error with complex additional data
27
+ * return err('validation_failed', 'Invalid input', {
28
+ * field: 'email',
29
+ * errors: ['Invalid format']
30
+ * })
31
+ * // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
32
+ */
33
+ const err = (type, message, additional) => _Err({
34
+ ...additional,
35
+ type,
36
+ message,
37
+ });
38
+ export { err };
@@ -0,0 +1,2 @@
1
+ export { err } from './err.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1 @@
1
+ export { err } from './err.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Check if a value is a neverthrow Result type
3
+ *
4
+ * Uses duck typing to detect Result objects without importing neverthrow types.
5
+ */
6
+ declare const isResult: (value: unknown) => value is {
7
+ isOk: () => boolean;
8
+ isErr: () => boolean;
9
+ };
10
+ export { isResult };
11
+ //# sourceMappingURL=is_result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_result.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAA,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAA;CAStF,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Check if a value is a neverthrow Result type
3
+ *
4
+ * Uses duck typing to detect Result objects without importing neverthrow types.
5
+ */
6
+ const isResult = (value) => {
7
+ return (value !== null &&
8
+ typeof value === 'object' &&
9
+ 'isOk' in value &&
10
+ 'isErr' in value &&
11
+ typeof value.isOk === 'function' &&
12
+ typeof value.isErr === 'function');
13
+ };
14
+ export { isResult };
@@ -0,0 +1,2 @@
1
+ export { isResult } from './is_result.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1 @@
1
+ export { isResult } from './is_result.js';
@@ -0,0 +1,156 @@
1
+ import { err as _Err, ok, type Result, type Err, ResultAsync, okAsync as neverthrowOkAsync } from 'neverthrow';
2
+ /**
3
+ * Create an error object with literal type preservation
4
+ *
5
+ * @example
6
+ * const error = makeErr('not_found', 'User not found')
7
+ * // ✅ Type: { type: 'not_found', message: string }
8
+ *
9
+ * @example
10
+ * const error = makeErr('not_found', 'User not found', { userId: '123' })
11
+ * // ✅ Type: { type: 'not_found', message: string, userId: string }
12
+ */
13
+ declare const makeErr: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => {
14
+ type: TType;
15
+ message: string;
16
+ } & TAdditional;
17
+ /**
18
+ * Create an async Err ResultAsync with automatic literal type preservation
19
+ *
20
+ * Async version of err() - same signature, returns ResultAsync instead of Result.
21
+ * Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
22
+ *
23
+ * @example
24
+ * // ✅ Simple error
25
+ * return errAsync('not_found', 'User not found')
26
+ * // Type: ResultAsync<never, { type: 'not_found', message: string }>
27
+ *
28
+ * @example
29
+ * // ✅ Error with additional properties
30
+ * return errAsync('not_found', 'User not found', { userId: '123' })
31
+ * // Type: ResultAsync<never, { type: 'not_found', message: string, userId: string }>
32
+ *
33
+ * @example
34
+ * // ✅ Error with complex additional data
35
+ * return errAsync('validation_failed', 'Invalid input', {
36
+ * field: 'email',
37
+ * errors: ['Invalid format']
38
+ * })
39
+ * // Type: ResultAsync<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
40
+ */
41
+ declare const errAsync: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => ResultAsync<never, {
42
+ type: TType;
43
+ message: string;
44
+ } & TAdditional>;
45
+ /**
46
+ * Re-export okAsync from neverthrow for consistency
47
+ * Creates a successful ResultAsync
48
+ */
49
+ declare const okAsync: typeof neverthrowOkAsync;
50
+ /**
51
+ * Utility type for defining error types concisely
52
+ *
53
+ * @example
54
+ * // Instead of:
55
+ * type UserNotFoundError = {
56
+ * type: 'user_not_found'
57
+ * message: string
58
+ * userId: UserId
59
+ * }
60
+ *
61
+ * // Write:
62
+ * type UserNotFoundError = ErrorType<'user_not_found', { userId: UserId }>
63
+ *
64
+ * @example
65
+ * // Error without additional properties:
66
+ * type InvalidOperationError = ErrorType<'invalid_operation'>
67
+ */
68
+ type ErrorType<TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>> = {
69
+ type: TType;
70
+ message: string;
71
+ } & TAdditional;
72
+ /**
73
+ * Extract the error type from a Result or Promise<Result>
74
+ *
75
+ * @example
76
+ * // From async function
77
+ * const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
78
+ * type GetUserError = ExtractError<ReturnType<typeof getUser>>
79
+ * // Type: UserNotFoundError
80
+ *
81
+ * @example
82
+ * // From Result type directly
83
+ * type MyResult = Result<User, InvalidError>
84
+ * type MyError = ExtractError<MyResult>
85
+ * // Type: InvalidError
86
+ *
87
+ * @example
88
+ * // Works with composed errors
89
+ * const replaceVersion = async (): Promise<Result<Version, VersionNotFoundError | VersionExistsError>> => { ... }
90
+ * type ReplaceError = ExtractError<ReturnType<typeof replaceVersion>>
91
+ * // Type: VersionNotFoundError | VersionExistsError
92
+ */
93
+ type ExtractError<TResultOrPromise> = TResultOrPromise extends Promise<Result<unknown, infer TError>> ? TError : TResultOrPromise extends Result<unknown, infer TError> ? TError : never;
94
+ /**
95
+ * Extract the error type from a function that returns Result or Promise<Result>
96
+ *
97
+ * @example
98
+ * // Simple extraction
99
+ * const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
100
+ * type GetUserError = ExtractFnError<typeof getUser>
101
+ * // Type: UserNotFoundError
102
+ *
103
+ * @example
104
+ * // Compose errors from multiple functions
105
+ * const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
106
+ * const getImage = async (id: string): Promise<Result<Image, ImageNotFoundError>> => { ... }
107
+ * type CombinedError = ExtractFnError<typeof getUser> | ExtractFnError<typeof getImage>
108
+ * // Type: UserNotFoundError | ImageNotFoundError
109
+ */
110
+ type ExtractFnError<TFunction extends (...args: unknown[]) => unknown> = ExtractError<ReturnType<TFunction>>;
111
+ /**
112
+ * Extract and combine error types from multiple Result or Promise<Result> types
113
+ *
114
+ * @example
115
+ * type UserResult = Result<User, UserNotFoundError>
116
+ * type ImageResult = Promise<Result<Image, ImageNotFoundError>>
117
+ * type ProductResult = Result<Product, ProductNotFoundError>
118
+ *
119
+ * type CombinedError = ExtractErrors<[UserResult, ImageResult, ProductResult]>
120
+ * // Type: UserNotFoundError | ImageNotFoundError | ProductNotFoundError
121
+ */
122
+ type ExtractErrors<TResults extends readonly unknown[]> = TResults extends readonly [
123
+ infer TFirst,
124
+ ...infer TRest
125
+ ] ? ExtractError<TFirst> | ExtractErrors<TRest> : never;
126
+ /**
127
+ * Extract and combine error types from multiple functions that return Result or Promise<Result>
128
+ *
129
+ * @example
130
+ * const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
131
+ * const getImage = async (id: string): Promise<Result<Image, ImageNotFoundError>> => { ... }
132
+ * const deleteProduct = async (id: string): Promise<Result<void, ProductNotFoundError>> => { ... }
133
+ *
134
+ * type CombinedError = ExtractFnsError<[typeof getUser, typeof getImage, typeof deleteProduct]>
135
+ * // Type: UserNotFoundError | ImageNotFoundError | ProductNotFoundError
136
+ */
137
+ type ExtractFnsError<TFunctions extends readonly ((...args: unknown[]) => unknown)[]> = TFunctions extends readonly [
138
+ infer TFirst,
139
+ ...infer TRest extends readonly ((...args: unknown[]) => unknown)[]
140
+ ] ? ExtractFnError<TFirst & ((...args: unknown[]) => unknown)> | ExtractFnsError<TRest> : never;
141
+ /**
142
+ * Raw error function from neverthrow - use for lifting database errors directly
143
+ *
144
+ * @example
145
+ * const seedResult = await songSeeds.get.one.byId(songSeedId)
146
+ * if (seedResult.isErr()) {
147
+ * return rawErr(seedResult.error)
148
+ * }
149
+ */
150
+ declare const rawErr: typeof _Err;
151
+ export { makeErr, errAsync, ok, okAsync, rawErr, _Err, ResultAsync };
152
+ export type { Result, Err, ErrorType, ExtractError, ExtractFnError, ExtractErrors, ExtractFnsError };
153
+ export { err } from './err/mod.js';
154
+ export { isResult } from './is_result/mod.js';
155
+ export { propagateErr } from './propagate_err/mod.js';
156
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/mod.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,65 @@
1
+ import { err as _Err, ok, ResultAsync, errAsync as neverthrowErrAsync, okAsync as neverthrowOkAsync, } from 'neverthrow';
2
+ /**
3
+ * Create an error object with literal type preservation
4
+ *
5
+ * @example
6
+ * const error = makeErr('not_found', 'User not found')
7
+ * // ✅ Type: { type: 'not_found', message: string }
8
+ *
9
+ * @example
10
+ * const error = makeErr('not_found', 'User not found', { userId: '123' })
11
+ * // ✅ Type: { type: 'not_found', message: string, userId: string }
12
+ */
13
+ const makeErr = (type, message, additional) => ({
14
+ ...additional,
15
+ type,
16
+ message,
17
+ });
18
+ /**
19
+ * Create an async Err ResultAsync with automatic literal type preservation
20
+ *
21
+ * Async version of err() - same signature, returns ResultAsync instead of Result.
22
+ * Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
23
+ *
24
+ * @example
25
+ * // ✅ Simple error
26
+ * return errAsync('not_found', 'User not found')
27
+ * // Type: ResultAsync<never, { type: 'not_found', message: string }>
28
+ *
29
+ * @example
30
+ * // ✅ Error with additional properties
31
+ * return errAsync('not_found', 'User not found', { userId: '123' })
32
+ * // Type: ResultAsync<never, { type: 'not_found', message: string, userId: string }>
33
+ *
34
+ * @example
35
+ * // ✅ Error with complex additional data
36
+ * return errAsync('validation_failed', 'Invalid input', {
37
+ * field: 'email',
38
+ * errors: ['Invalid format']
39
+ * })
40
+ * // Type: ResultAsync<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
41
+ */
42
+ const errAsync = (type, message, additional) => neverthrowErrAsync({
43
+ ...additional,
44
+ type,
45
+ message,
46
+ });
47
+ /**
48
+ * Re-export okAsync from neverthrow for consistency
49
+ * Creates a successful ResultAsync
50
+ */
51
+ const okAsync = neverthrowOkAsync;
52
+ /**
53
+ * Raw error function from neverthrow - use for lifting database errors directly
54
+ *
55
+ * @example
56
+ * const seedResult = await songSeeds.get.one.byId(songSeedId)
57
+ * if (seedResult.isErr()) {
58
+ * return rawErr(seedResult.error)
59
+ * }
60
+ */
61
+ const rawErr = _Err;
62
+ export { makeErr, errAsync, ok, okAsync, rawErr, _Err, ResultAsync };
63
+ export { err } from './err/mod.js';
64
+ export { isResult } from './is_result/mod.js';
65
+ export { propagateErr } from './propagate_err/mod.js';
@@ -0,0 +1,2 @@
1
+ export { propagateErr } from './propagate_err.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1 @@
1
+ export { propagateErr } from './propagate_err.js';
@@ -0,0 +1,28 @@
1
+ import type { Result } from 'neverthrow';
2
+ /**
3
+ * Propagates an error Result to a different success type context.
4
+ *
5
+ * This is safe because error Results never contain the success value - only the error.
6
+ * TypeScript's structural typing prevents direct assignment of Result<T, E> to Result<U, E>
7
+ * even though the error type is identical and we're in the error branch.
8
+ *
9
+ * Common use case: Early return from a function that creates multiple items. If creating
10
+ * item 2 fails with Result<Item, DatabaseError>, we need to return Result<Item[], DatabaseError>.
11
+ *
12
+ * @example
13
+ * const result = await createUser(db, data) // Result<User, DatabaseError>
14
+ * if (result.isErr()) {
15
+ * // Need to return Result<Profile, DatabaseError> but have Result<User, DatabaseError>
16
+ * return propagateErr(result)
17
+ * }
18
+ *
19
+ * @example
20
+ * // In bulk creation, propagate single-item error to array context
21
+ * const itemResult = await createItem(data) // Result<Item, Error>
22
+ * if (itemResult.isErr()) {
23
+ * return propagateErr<Item[], Error>(itemResult) // Result<Item[], Error>
24
+ * }
25
+ */
26
+ declare const propagateErr: <TNew, E>(errorResult: Result<unknown, E>) => Result<TNew, E>;
27
+ export { propagateErr };
28
+ //# sourceMappingURL=propagate_err.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propagate_err.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,YAAY,GAAI,IAAI,EAAE,CAAC,EAAE,aAAa,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAI9E,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}