synstate 1.0.1 → 2.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 (194) hide show
  1. package/README.md +9 -10
  2. package/dist/core/class/child-observable-class.d.mts.map +1 -1
  3. package/dist/core/class/child-observable-class.mjs +148 -140
  4. package/dist/core/class/child-observable-class.mjs.map +1 -1
  5. package/dist/core/class/observable-base-class.d.mts.map +1 -1
  6. package/dist/core/class/observable-base-class.mjs +111 -107
  7. package/dist/core/class/observable-base-class.mjs.map +1 -1
  8. package/dist/core/class/root-observable-class.d.mts.map +1 -1
  9. package/dist/core/class/root-observable-class.mjs +32 -24
  10. package/dist/core/class/root-observable-class.mjs.map +1 -1
  11. package/dist/core/combine/combine.d.mts +3 -3
  12. package/dist/core/combine/combine.d.mts.map +1 -1
  13. package/dist/core/combine/combine.mjs +31 -113
  14. package/dist/core/combine/combine.mjs.map +1 -1
  15. package/dist/core/combine/merge.d.mts +2 -2
  16. package/dist/core/combine/merge.d.mts.map +1 -1
  17. package/dist/core/combine/merge.mjs +21 -69
  18. package/dist/core/combine/merge.mjs.map +1 -1
  19. package/dist/core/combine/zip.d.mts +2 -2
  20. package/dist/core/combine/zip.d.mts.map +1 -1
  21. package/dist/core/combine/zip.mjs +34 -79
  22. package/dist/core/combine/zip.mjs.map +1 -1
  23. package/dist/core/create/counter.d.mts +1 -1
  24. package/dist/core/create/counter.d.mts.map +1 -1
  25. package/dist/core/create/counter.mjs +45 -84
  26. package/dist/core/create/counter.mjs.map +1 -1
  27. package/dist/core/create/from-abortable-promise.d.mts.map +1 -1
  28. package/dist/core/create/from-abortable-promise.mjs +29 -61
  29. package/dist/core/create/from-abortable-promise.mjs.map +1 -1
  30. package/dist/core/create/from-promise.d.mts.map +1 -1
  31. package/dist/core/create/from-promise.mjs +17 -66
  32. package/dist/core/create/from-promise.mjs.map +1 -1
  33. package/dist/core/create/from-subscribable.d.mts.map +1 -1
  34. package/dist/core/create/from-subscribable.mjs +18 -69
  35. package/dist/core/create/from-subscribable.mjs.map +1 -1
  36. package/dist/core/create/just.d.mts.map +1 -1
  37. package/dist/core/create/just.mjs +5 -35
  38. package/dist/core/create/just.mjs.map +1 -1
  39. package/dist/core/create/source.mjs +10 -13
  40. package/dist/core/create/source.mjs.map +1 -1
  41. package/dist/core/create/timer.d.mts.map +1 -1
  42. package/dist/core/create/timer.mjs +32 -68
  43. package/dist/core/create/timer.mjs.map +1 -1
  44. package/dist/core/operators/audit.d.mts.map +1 -1
  45. package/dist/core/operators/audit.mjs +39 -133
  46. package/dist/core/operators/audit.mjs.map +1 -1
  47. package/dist/core/operators/debounce.d.mts.map +1 -1
  48. package/dist/core/operators/debounce.mjs +36 -119
  49. package/dist/core/operators/debounce.mjs.map +1 -1
  50. package/dist/core/operators/filter.mjs +22 -25
  51. package/dist/core/operators/filter.mjs.map +1 -1
  52. package/dist/core/operators/map.d.mts.map +1 -1
  53. package/dist/core/operators/map.mjs +28 -61
  54. package/dist/core/operators/map.mjs.map +1 -1
  55. package/dist/core/operators/merge-map.d.mts +1 -1
  56. package/dist/core/operators/merge-map.d.mts.map +1 -1
  57. package/dist/core/operators/merge-map.mjs +34 -130
  58. package/dist/core/operators/merge-map.mjs.map +1 -1
  59. package/dist/core/operators/pairwise.d.mts +3 -2
  60. package/dist/core/operators/pairwise.d.mts.map +1 -1
  61. package/dist/core/operators/pairwise.mjs +19 -75
  62. package/dist/core/operators/pairwise.mjs.map +1 -1
  63. package/dist/core/operators/scan.d.mts.map +1 -1
  64. package/dist/core/operators/scan.mjs +16 -67
  65. package/dist/core/operators/scan.mjs.map +1 -1
  66. package/dist/core/operators/skip-if-no-change.d.mts +1 -1
  67. package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
  68. package/dist/core/operators/skip-if-no-change.mjs +28 -92
  69. package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
  70. package/dist/core/operators/skip-until.d.mts.map +1 -1
  71. package/dist/core/operators/skip-until.mjs +23 -72
  72. package/dist/core/operators/skip-until.mjs.map +1 -1
  73. package/dist/core/operators/skip-while.d.mts.map +1 -1
  74. package/dist/core/operators/skip-while.mjs +26 -88
  75. package/dist/core/operators/skip-while.mjs.map +1 -1
  76. package/dist/core/operators/switch-map.d.mts.map +1 -1
  77. package/dist/core/operators/switch-map.mjs +31 -124
  78. package/dist/core/operators/switch-map.mjs.map +1 -1
  79. package/dist/core/operators/take-until.d.mts.map +1 -1
  80. package/dist/core/operators/take-until.mjs +28 -69
  81. package/dist/core/operators/take-until.mjs.map +1 -1
  82. package/dist/core/operators/take-while.d.mts.map +1 -1
  83. package/dist/core/operators/take-while.mjs +23 -83
  84. package/dist/core/operators/take-while.mjs.map +1 -1
  85. package/dist/core/operators/throttle.d.mts.map +1 -1
  86. package/dist/core/operators/throttle.mjs +38 -115
  87. package/dist/core/operators/throttle.mjs.map +1 -1
  88. package/dist/core/operators/with-buffered-from.d.mts +1 -1
  89. package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
  90. package/dist/core/operators/with-buffered-from.mjs +37 -90
  91. package/dist/core/operators/with-buffered-from.mjs.map +1 -1
  92. package/dist/core/operators/with-current-value-from.d.mts +1 -1
  93. package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
  94. package/dist/core/operators/with-current-value-from.mjs +23 -84
  95. package/dist/core/operators/with-current-value-from.mjs.map +1 -1
  96. package/dist/core/operators/with-initial-value.d.mts.map +1 -1
  97. package/dist/core/operators/with-initial-value.mjs +13 -58
  98. package/dist/core/operators/with-initial-value.mjs.map +1 -1
  99. package/dist/core/predefined/operators/attach-index.d.mts +1 -1
  100. package/dist/core/predefined/operators/attach-index.d.mts.map +1 -1
  101. package/dist/core/predefined/operators/attach-index.mjs +0 -53
  102. package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
  103. package/dist/core/predefined/operators/map-optional.d.mts.map +1 -1
  104. package/dist/core/predefined/operators/map-optional.mjs +1 -48
  105. package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
  106. package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -1
  107. package/dist/core/predefined/operators/map-result-err.mjs +1 -48
  108. package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
  109. package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -1
  110. package/dist/core/predefined/operators/map-result-ok.mjs +1 -48
  111. package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
  112. package/dist/core/predefined/operators/map-to.d.mts.map +1 -1
  113. package/dist/core/predefined/operators/map-to.mjs +0 -40
  114. package/dist/core/predefined/operators/map-to.mjs.map +1 -1
  115. package/dist/core/predefined/operators/pluck.d.mts +1 -1
  116. package/dist/core/predefined/operators/pluck.d.mts.map +1 -1
  117. package/dist/core/predefined/operators/pluck.mjs +0 -43
  118. package/dist/core/predefined/operators/pluck.mjs.map +1 -1
  119. package/dist/core/predefined/operators/skip.d.mts.map +1 -1
  120. package/dist/core/predefined/operators/skip.mjs +0 -47
  121. package/dist/core/predefined/operators/skip.mjs.map +1 -1
  122. package/dist/core/predefined/operators/take.d.mts.map +1 -1
  123. package/dist/core/predefined/operators/take.mjs +0 -41
  124. package/dist/core/predefined/operators/take.mjs.map +1 -1
  125. package/dist/core/predefined/operators/unwrap-optional.mjs +4 -43
  126. package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
  127. package/dist/core/predefined/operators/unwrap-result-err.mjs +0 -40
  128. package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
  129. package/dist/core/predefined/operators/unwrap-result-ok.mjs +4 -43
  130. package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
  131. package/dist/core/types/observable-family.d.mts +10 -10
  132. package/dist/core/types/observable-family.d.mts.map +1 -1
  133. package/dist/core/types/observable.d.mts.map +1 -1
  134. package/dist/core/types/observable.mjs +3 -5
  135. package/dist/core/types/observable.mjs.map +1 -1
  136. package/dist/core/types/types.d.mts +2 -1
  137. package/dist/core/types/types.d.mts.map +1 -1
  138. package/dist/core/utils/id-maker.mjs +5 -6
  139. package/dist/core/utils/id-maker.mjs.map +1 -1
  140. package/dist/core/utils/max-depth.d.mts.map +1 -1
  141. package/dist/core/utils/max-depth.mjs +1 -3
  142. package/dist/core/utils/max-depth.mjs.map +1 -1
  143. package/dist/core/utils/observable-utils.d.mts.map +1 -1
  144. package/dist/core/utils/observable-utils.mjs +3 -2
  145. package/dist/core/utils/observable-utils.mjs.map +1 -1
  146. package/dist/core/utils/utils.d.mts.map +1 -1
  147. package/dist/core/utils/utils.mjs +23 -30
  148. package/dist/core/utils/utils.mjs.map +1 -1
  149. package/dist/utils/collect-to-array.d.mts.map +1 -1
  150. package/dist/utils/collect-to-array.mjs +9 -6
  151. package/dist/utils/collect-to-array.mjs.map +1 -1
  152. package/dist/utils/create-boolean-state.d.mts +1 -1
  153. package/dist/utils/create-boolean-state.d.mts.map +1 -1
  154. package/dist/utils/create-boolean-state.mjs +18 -46
  155. package/dist/utils/create-boolean-state.mjs.map +1 -1
  156. package/dist/utils/create-event-emitter.mjs +10 -64
  157. package/dist/utils/create-event-emitter.mjs.map +1 -1
  158. package/dist/utils/create-reducer.d.mts +1 -1
  159. package/dist/utils/create-reducer.d.mts.map +1 -1
  160. package/dist/utils/create-reducer.mjs +8 -52
  161. package/dist/utils/create-reducer.mjs.map +1 -1
  162. package/dist/utils/create-state.d.mts +1 -1
  163. package/dist/utils/create-state.d.mts.map +1 -1
  164. package/dist/utils/create-state.mjs +23 -53
  165. package/dist/utils/create-state.mjs.map +1 -1
  166. package/package.json +16 -16
  167. package/src/core/class/child-observable-class.mts +1 -1
  168. package/src/core/class/observable-base-class.mts +16 -16
  169. package/src/core/combine/combine.mts +38 -16
  170. package/src/core/combine/merge.mts +3 -3
  171. package/src/core/combine/zip.mts +24 -13
  172. package/src/core/create/counter.mts +11 -9
  173. package/src/core/create/counter.test.mts +11 -0
  174. package/src/core/create/timer.mts +6 -6
  175. package/src/core/create/timer.test.mts +11 -0
  176. package/src/core/operators/audit-throttle-teardown.test.mts +21 -0
  177. package/src/core/operators/audit.mts +6 -6
  178. package/src/core/operators/debounce.mts +6 -6
  179. package/src/core/operators/pairwise.mts +10 -5
  180. package/src/core/operators/skip-while.mts +1 -5
  181. package/src/core/operators/skip-while.test.mts +20 -0
  182. package/src/core/operators/throttle.mts +6 -6
  183. package/src/core/operators/with-buffered-from.mts +4 -4
  184. package/src/core/predefined/operators/map-optional.mts +1 -2
  185. package/src/core/predefined/operators/map-result-err.mts +1 -1
  186. package/src/core/predefined/operators/map-result-ok.mts +1 -1
  187. package/src/core/types/observable-family.mts +12 -11
  188. package/src/core/types/observable.mts +5 -7
  189. package/src/core/types/types.mts +2 -1
  190. package/src/core/utils/max-depth.mts +5 -1
  191. package/src/core/utils/utils.mts +1 -1
  192. package/src/utils/create-boolean-state.mts +1 -1
  193. package/src/utils/create-reducer.mts +1 -1
  194. package/src/utils/create-state.mts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"zip.mjs","sources":["../../../src/core/combine/zip.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDG;AACI,MAAM,GAAG,GAAG,CACjB,OAAW;AAEX;AACA,IAAI,kBAAkB,CAAC,OAAO;AAEhC,MAAM,kBACJ,SAAQ,wBAA8B,CAAA;AAG7B,IAAA,OAAO;AAEhB,IAAA,WAAA,CAAY,OAAgB,EAAA;AAC1B,QAAA,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAEzD,QAAA,KAAK,CAAC;YACJ,OAAO;YACP,YAAY,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM;kBAC7C,QAAQ,CAAC,IAAI;;AAEX,gBAAA,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAM;kBAE7C,QAAQ,CAAC,IAAI;AAClB,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,MAC9B,WAAW,EAAE,CACiB;;AAGzB,IAAA,SAAS,CAAC,WAAwB,EAAA;AACzC,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO;AAE3B,QAAA,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE;AACjD,YAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,YAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;gBAC1D,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC;;;AAIpC,QAAA,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;AACzC,YAAA,MAAM,SAAS;;YAEb,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAM;AAE3D,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;;;AAGzC;;;;"}
1
+ {"version":3,"file":"zip.mjs","sources":["../../../src/core/combine/zip.mts"],"sourcesContent":["import { Arr, Optional, createQueue, expectType } from 'ts-data-forge';\nimport { type NonEmptyTuple, type Tuple } from 'ts-type-forge';\nimport { SyncChildObservableClass } from '../class/index.mjs';\nimport { source } from '../create/index.mjs';\nimport { withInitialValue } from '../operators/index.mjs';\nimport {\n type InitializedObservable,\n type InitializedSyncChildObservable,\n type NonEmptyUnknownList,\n type Observable,\n type SyncChildObservable,\n type TupleToQueueTuple,\n type UpdateToken,\n type Wrap,\n type ZipObservable,\n type ZipObservableRefined,\n} from '../types/index.mjs';\n\n/**\n * Combines multiple observables by pairing their emissions by index.\n * Waits for all sources to emit their nth value before emitting the nth tuple.\n * Completes when any source completes.\n *\n * @template OS - Tuple type of source observables\n * @param parents - Array of observables to zip\n * @returns A zipped observable emitting tuples of values\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // letters$ 'A' 'B' 'C'\n * // numbers$ 1 2 3\n * // zipped$ ['A',1] ['B',2] ['C',3]\n * //\n * // Explanation:\n * // - zip pairs values by their index from multiple sources\n * // - Waits for all sources to emit at the same index\n * // - Completes when any source completes\n *\n * const [letters$, setLetter] = createState<string>('A');\n *\n * const [numbers$, setNumber] = createState<number>(1);\n *\n * const zipped$ = zip([letters$, numbers$]);\n *\n * const valueHistory: (readonly [string, number])[] = [];\n *\n * zipped$.subscribe(([letter, num]) => {\n * valueHistory.push([letter, num]);\n * });\n *\n * for (const letter of ['B', 'C']) {\n * setLetter(letter);\n * }\n *\n * for (const num of [2, 3]) {\n * setNumber(num);\n * }\n *\n * assert.deepStrictEqual(valueHistory, [\n * ['A', 1],\n * ['B', 2],\n * ['C', 3],\n * ]);\n * ```\n */\nexport const zip = <const OS extends NonEmptyTuple<Observable<unknown>>>(\n parents: OS,\n): ZipObservableRefined<OS> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n new ZipObservableClass(parents) as unknown as ZipObservableRefined<OS>;\n\nclass ZipObservableClass<const A extends NonEmptyUnknownList>\n extends SyncChildObservableClass<A, A>\n implements ZipObservable<A>\n{\n readonly #queues: TupleToQueueTuple<A>;\n\n constructor(parents: Wrap<A>) {\n const parentsValues: Tuple.MapTo<Optional<A[number]>, A> = Arr.map(\n parents,\n (p) => p.getSnapshot(),\n );\n\n // The annotation on `initialValue` is what replaces the type assertion.\n // `Arr.map` carries a single result element type, so it reports `A[number]`\n // at every position, and `Tuple.MapTo<A[number], A>` — the uniform mapping\n // — is *not* assignable back to `A`. The positional\n // `Readonly<{ [K in keyof A]: A[K] }>` is, and TypeScript accepts the\n // uniform result into it because the two mapped types share `keyof A`. So\n // it is the annotation, not an assertion, that records the position-wise\n // fact the checker cannot derive on its own.\n const initialValue: Optional<Readonly<{ [K in keyof A]: A[K] }>> =\n Arr.every(parentsValues, Optional.isSome)\n ? Optional.some(Arr.map(parentsValues, (c) => c.value))\n : Optional.none;\n\n super({\n parents,\n initialValue,\n });\n\n this.#queues = Arr.map(parents, () => createQueue());\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const queues = this.#queues;\n\n for (const [index, par] of this.parents.entries()) {\n const sn = par.getSnapshot();\n\n if (par.updateToken === updateToken && Optional.isSome(sn)) {\n queues[index]?.enqueue(sn.value);\n }\n }\n\n if (queues.every((list) => !list.isEmpty)) {\n const nextValue =\n // `Arr.map` has a single result element type, so it reports\n // `A[number] | undefined` per position rather than `A[P]`.\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Arr.map(queues, (q) => Optional.unwrap(q.dequeue())) as A;\n\n this.setNext(nextValue, updateToken);\n }\n }\n}\n\nif (import.meta.vitest !== undefined) {\n test('type test', () => {\n expect(1).toBe(1); // dummy\n });\n\n {\n const s1: Observable<1> = source<1>();\n\n const s2: Observable<2> = source<2>();\n\n const _d = zip([s1, s2]);\n\n expectType<typeof _d, ZipObservable<readonly [1, 2]>>('=');\n\n expectType<typeof _d, Observable<readonly [1, 2]>>('<=');\n }\n\n {\n const s1: InitializedObservable<1> = source<1>().pipe(withInitialValue(1));\n\n const s2: Observable<2> = source<2>();\n\n const _d = zip([s1, s2]);\n\n expectType<typeof _d, ZipObservable<readonly [1, 2]>>('=');\n\n expectType<typeof _d, Observable<readonly [1, 2]>>('<=');\n }\n\n {\n const s1: InitializedObservable<1> = source<1>().pipe(withInitialValue(1));\n\n const s2: InitializedObservable<2> = source<2>().pipe(withInitialValue(2));\n\n const _d = zip([s1, s2]);\n\n // Returns InitializedObservable if all OS are InitializedObservable\n expectType<typeof _d, InitializedObservable<readonly [1, 2]>>('<=');\n }\n\n const r1 = source(1);\n\n const r2 = source('a');\n\n const _z = zip([r1, r2]);\n\n const _zi = zip([\n r1.pipe(withInitialValue(0)),\n r2.pipe(withInitialValue('0')),\n ] as const);\n\n expectType<typeof _z, SyncChildObservable<readonly [number, string]>>('<=');\n\n expectType<\n typeof _zi,\n InitializedSyncChildObservable<readonly [number, string]>\n >('<=');\n}\n"],"names":[],"mappings":";;;;AAmEO,MAAM,MAAM,CACjB,OAAA;AAAA;AAAA,EAGA,IAAI,mBAAmB,OAAO;AAAA;AAEhC,MAAM,2BACI,wBAAA,CAEV;AAAA,EACW,OAAA;AAAA,EAET,YAAY,OAAA,EAAkB;AAC5B,IAAA,MAAM,gBAAqD,GAAA,CAAI,GAAA;AAAA,MAC7D,OAAA;AAAA,MACA,CAAC,CAAA,KAAM,CAAA,CAAE,WAAA;AAAY,KACvB;AAUA,IAAA,MAAM,eACJ,GAAA,CAAI,KAAA,CAAM,eAAe,QAAA,CAAS,MAAM,IACpC,QAAA,CAAS,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,eAAe,CAAC,CAAA,KAAM,EAAE,KAAK,CAAC,IACpD,QAAA,CAAS,IAAA;AAEf,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA;AAAA,MACA;AAAA,KACD,CAAA;AAED,IAAA,IAAA,CAAK,UAAU,GAAA,CAAI,GAAA,CAAI,OAAA,EAAS,MAAM,aAAa,CAAA;AAAA,EAAA;AACrD,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,SAAS,IAAA,CAAK,OAAA;AAEpB,IAAA,KAAA,MAAW,CAAC,KAAA,EAAO,GAAG,KAAK,IAAA,CAAK,OAAA,CAAQ,SAAQ,EAAG;AACjD,MAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,MAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,QAAA,MAAA,CAAO,KAAK,CAAA,EAAG,OAAA,CAAQ,EAAA,CAAG,KAAK,CAAA;AAAA,MAAA;AACjC,IAAA;AAGF,IAAA,IAAI,OAAO,KAAA,CAAM,CAAC,SAAS,CAAC,IAAA,CAAK,OAAO,CAAA,EAAG;AACzC,MAAA,MAAM,SAAA;AAAA;AAAA;AAAA;AAAA,QAIJ,GAAA,CAAI,GAAA,CAAI,MAAA,EAAQ,CAAC,CAAA,KAAM,SAAS,MAAA,CAAO,CAAA,CAAE,OAAA,EAAS,CAAC;AAAA,OAAA;AAErD,MAAA,IAAA,CAAK,OAAA,CAAQ,WAAW,WAAW,CAAA;AAAA,IAAA;AACrC,EAAA;AAEJ;;;;"}
@@ -33,7 +33,7 @@ import { type CounterObservable } from '../types/index.mjs';
33
33
  *
34
34
  * subscription.unsubscribe();
35
35
  *
36
- * assert.isTrue(Arr.isArrayAtLeastLength(valueHistory, 3));
36
+ * assert.isTrue(Arr.isMinLengthArray(3, valueHistory));
37
37
  *
38
38
  * assert.deepStrictEqual(valueHistory[0], 0);
39
39
  *
@@ -1 +1 @@
1
- {"version":3,"file":"counter.d.mts","sourceRoot":"","sources":["../../../src/core/create/counter.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,oBAAoB,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,OAAO,GAClB,sBAAsB,MAAM,EAC5B,UAAU,QAAQ,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC,KACD,iBAIA,CAAC"}
1
+ {"version":3,"file":"counter.d.mts","sourceRoot":"","sources":["../../../src/core/create/counter.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,oBAAoB,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,OAAO,yBACI,MAAM,YAClB,QAAQ,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC,KACD,iBAIA,CAAC"}
@@ -2,95 +2,56 @@ import { Optional, asSafeUint, SafeUint } from 'ts-data-forge';
2
2
  import '../utils/id-maker.mjs';
3
3
  import { RootObservableClass } from '../class/root-observable-class.mjs';
4
4
 
5
- /**
6
- * Creates an observable that emits incremental numbers at a specified interval.
7
- * Starts with 0 immediately after subscription, then emits 1, 2, 3, ... every interval.
8
- *
9
- * @param intervalMilliSeconds - The interval duration in milliseconds
10
- * @param startManually - If true, waits for manual start (default: false)
11
- * @returns An observable that emits sequential numbers
12
- *
13
- * @example
14
- * ```ts
15
- * // Timeline:
16
- * //
17
- * // Time(s) 0 1 2 3 4 5
18
- * // tick$ 0 1 2 3 4 5 ...
19
- * //
20
- * // Explanation:
21
- * // - counter emits incrementing numbers at specified intervals
22
- * // - Starts at 0 and continues indefinitely
23
- * // - Useful for periodic tasks or animations
24
- *
25
- * const tick$ = counter(100);
26
- *
27
- * const valueHistory: number[] = [];
28
- *
29
- * const subscription = tick$.subscribe((count) => {
30
- * valueHistory.push(count);
31
- * });
32
- *
33
- * await new Promise((resolve) => {
34
- * setTimeout(resolve, 350);
35
- * });
36
- *
37
- * subscription.unsubscribe();
38
- *
39
- * assert.isTrue(Arr.isArrayAtLeastLength(valueHistory, 3));
40
- *
41
- * assert.deepStrictEqual(valueHistory[0], 0);
42
- *
43
- * assert.deepStrictEqual(valueHistory[1], 1);
44
- *
45
- * assert.deepStrictEqual(valueHistory[2], 2);
46
- * ```
47
- */
48
- const counter = (intervalMilliSeconds, options) => new CounterObservableClass(intervalMilliSeconds, options?.startManually ?? false);
5
+ const counter = (intervalMilliSeconds, options) => new CounterObservableClass(
6
+ intervalMilliSeconds,
7
+ options?.startManually ?? false
8
+ );
49
9
  class CounterObservableClass extends RootObservableClass {
50
- #intervalMilliSeconds;
51
- #mut_counter;
52
- #mut_timerId0;
53
- #mut_timerId;
54
- #mut_isStarted;
55
- constructor(intervalMilliSeconds, startManually) {
56
- super({ initialValue: Optional.none });
57
- this.#intervalMilliSeconds = intervalMilliSeconds;
58
- this.#mut_counter = asSafeUint(0);
59
- this.#mut_timerId0 = undefined;
60
- this.#mut_timerId = undefined;
61
- this.#mut_isStarted = false;
62
- if (!startManually) {
63
- this.start();
64
- }
10
+ #intervalMilliSeconds;
11
+ #mut_counter;
12
+ #mut_timerId0;
13
+ #mut_timerId;
14
+ #mut_isStarted;
15
+ constructor(intervalMilliSeconds, startManually) {
16
+ super({ initialValue: Optional.none });
17
+ this.#intervalMilliSeconds = intervalMilliSeconds;
18
+ this.#mut_counter = asSafeUint(0);
19
+ this.#mut_timerId0 = void 0;
20
+ this.#mut_timerId = void 0;
21
+ this.#mut_isStarted = false;
22
+ if (!startManually) {
23
+ this.start();
65
24
  }
66
- start() {
67
- if (this.#mut_isStarted) {
68
- console.warn('cannot start twice');
69
- return;
70
- }
71
- this.#mut_isStarted = true;
72
- if (this.isCompleted) {
73
- console.warn('cannot restart stopped CounterObservable');
74
- return;
75
- }
76
- this.#mut_timerId0 = setTimeout(() => {
77
- this.startUpdate(this.#mut_counter);
78
- }, 0);
79
- this.#mut_timerId = setInterval(() => {
80
- this.#mut_counter = SafeUint.add(1, this.#mut_counter);
81
- this.startUpdate(this.#mut_counter);
82
- }, this.#intervalMilliSeconds);
25
+ }
26
+ #resetTimer() {
27
+ if (this.#mut_timerId0 === void 0 || this.#mut_timerId === void 0) {
28
+ return;
83
29
  }
84
- #resetTimer() {
85
- if (this.#mut_timerId0 !== undefined && this.#mut_timerId !== undefined) {
86
- clearInterval(this.#mut_timerId0);
87
- clearInterval(this.#mut_timerId);
88
- }
30
+ clearInterval(this.#mut_timerId0);
31
+ clearInterval(this.#mut_timerId);
32
+ }
33
+ start() {
34
+ if (this.#mut_isStarted) {
35
+ console.warn("cannot start twice");
36
+ return;
89
37
  }
90
- complete() {
91
- this.#resetTimer();
92
- super.complete();
38
+ this.#mut_isStarted = true;
39
+ if (this.isCompleted) {
40
+ console.warn("cannot restart stopped CounterObservable");
41
+ return;
93
42
  }
43
+ this.#mut_timerId0 = setTimeout(() => {
44
+ this.startUpdate(this.#mut_counter);
45
+ }, 0);
46
+ this.#mut_timerId = setInterval(() => {
47
+ this.#mut_counter = SafeUint.add(1, this.#mut_counter);
48
+ this.startUpdate(this.#mut_counter);
49
+ }, this.#intervalMilliSeconds);
50
+ }
51
+ complete() {
52
+ this.#resetTimer();
53
+ super.complete();
54
+ }
94
55
  }
95
56
 
96
57
  export { counter };
@@ -1 +1 @@
1
- {"version":3,"file":"counter.mjs","sources":["../../../src/core/create/counter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CG;MACU,OAAO,GAAG,CACrB,oBAA4B,EAC5B,OAEE,KAEF,IAAI,sBAAsB,CACxB,oBAAoB,EACpB,OAAO,EAAE,aAAa,IAAI,KAAK;AAGnC,MAAM,sBACJ,SAAQ,mBAA6B,CAAA;AAG5B,IAAA,qBAAqB;AAC9B,IAAA,YAAY;AACZ,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,cAAc;IAEd,WAAA,CAAY,oBAA4B,EAAE,aAAsB,EAAA;QAC9D,KAAK,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAEtC,QAAA,IAAI,CAAC,qBAAqB,GAAG,oBAAoB;AAEjD,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,CAAC,CAAC;AAEjC,QAAA,IAAI,CAAC,aAAa,GAAG,SAAS;AAE9B,QAAA,IAAI,CAAC,YAAY,GAAG,SAAS;AAE7B,QAAA,IAAI,CAAC,cAAc,GAAG,KAAK;QAE3B,IAAI,CAAC,aAAa,EAAE;YAClB,IAAI,CAAC,KAAK,EAAE;QACd;IACF;IAEA,KAAK,GAAA;AACH,QAAA,IAAI,IAAI,CAAC,cAAc,EAAE;AACvB,YAAA,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC;YAElC;QACF;AAEA,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI;AAE1B,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AACpB,YAAA,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC;YAExD;QACF;AAEA,QAAA,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,MAAK;AACnC,YAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QACrC,CAAC,EAAE,CAAC,CAAC;AAEL,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,MAAK;AACnC,YAAA,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;AAEtD,YAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;AACrC,QAAA,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;IAChC;IAEA,WAAW,GAAA;AACT,QAAA,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;AACvE,YAAA,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC;AAEjC,YAAA,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC;QAClC;IACF;IAES,QAAQ,GAAA;QACf,IAAI,CAAC,WAAW,EAAE;QAElB,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
1
+ {"version":3,"file":"counter.mjs","sources":["../../../src/core/create/counter.mts"],"sourcesContent":["import { asSafeUint, Optional, SafeUint } from 'ts-data-forge';\nimport { RootObservableClass } from '../class/index.mjs';\nimport { type CounterObservable, type TimerId } from '../types/index.mjs';\n\n/**\n * Creates an observable that emits incremental numbers at a specified interval.\n * Starts with 0 immediately after subscription, then emits 1, 2, 3, ... every interval.\n *\n * @param intervalMilliSeconds - The interval duration in milliseconds\n * @param startManually - If true, waits for manual start (default: false)\n * @returns An observable that emits sequential numbers\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // Time(s) 0 1 2 3 4 5\n * // tick$ 0 1 2 3 4 5 ...\n * //\n * // Explanation:\n * // - counter emits incrementing numbers at specified intervals\n * // - Starts at 0 and continues indefinitely\n * // - Useful for periodic tasks or animations\n *\n * const tick$ = counter(100);\n *\n * const valueHistory: number[] = [];\n *\n * const subscription = tick$.subscribe((count) => {\n * valueHistory.push(count);\n * });\n *\n * await new Promise((resolve) => {\n * setTimeout(resolve, 350);\n * });\n *\n * subscription.unsubscribe();\n *\n * assert.isTrue(Arr.isMinLengthArray(3, valueHistory));\n *\n * assert.deepStrictEqual(valueHistory[0], 0);\n *\n * assert.deepStrictEqual(valueHistory[1], 1);\n *\n * assert.deepStrictEqual(valueHistory[2], 2);\n * ```\n */\nexport const counter = (\n intervalMilliSeconds: number,\n options?: Readonly<{\n startManually?: boolean;\n }>,\n): CounterObservable =>\n new CounterObservableClass(\n intervalMilliSeconds,\n options?.startManually ?? false,\n );\n\nclass CounterObservableClass\n extends RootObservableClass<SafeUint>\n implements CounterObservable\n{\n readonly #intervalMilliSeconds: number;\n #mut_counter: SafeUint;\n #mut_timerId0: TimerId | undefined;\n #mut_timerId: TimerId | undefined;\n #mut_isStarted: boolean;\n\n constructor(intervalMilliSeconds: number, startManually: boolean) {\n super({ initialValue: Optional.none });\n\n this.#intervalMilliSeconds = intervalMilliSeconds;\n\n this.#mut_counter = asSafeUint(0);\n\n this.#mut_timerId0 = undefined;\n\n this.#mut_timerId = undefined;\n\n this.#mut_isStarted = false;\n\n if (!startManually) {\n this.start();\n }\n }\n\n #resetTimer(): void {\n if (this.#mut_timerId0 === undefined || this.#mut_timerId === undefined) {\n return;\n }\n\n clearInterval(this.#mut_timerId0);\n\n clearInterval(this.#mut_timerId);\n }\n\n start(): void {\n if (this.#mut_isStarted) {\n console.warn('cannot start twice');\n\n return;\n }\n\n this.#mut_isStarted = true;\n\n if (this.isCompleted) {\n console.warn('cannot restart stopped CounterObservable');\n\n return;\n }\n\n this.#mut_timerId0 = setTimeout(() => {\n this.startUpdate(this.#mut_counter);\n }, 0);\n\n this.#mut_timerId = setInterval(() => {\n this.#mut_counter = SafeUint.add(1, this.#mut_counter);\n\n this.startUpdate(this.#mut_counter);\n }, this.#intervalMilliSeconds);\n }\n\n override complete(): void {\n this.#resetTimer();\n\n super.complete();\n }\n}\n"],"names":[],"mappings":";;;;AA+CO,MAAM,OAAA,GAAU,CACrB,oBAAA,EACA,OAAA,KAIA,IAAI,sBAAA;AAAA,EACF,oBAAA;AAAA,EACA,SAAS,aAAA,IAAiB;AAC5B;AAEF,MAAM,+BACI,mBAAA,CAEV;AAAA,EACW,qBAAA;AAAA,EACT,YAAA;AAAA,EACA,aAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EAEA,WAAA,CAAY,sBAA8B,aAAA,EAAwB;AAChE,IAAA,KAAA,CAAM,EAAE,YAAA,EAAc,QAAA,CAAS,IAAA,EAAM,CAAA;AAErC,IAAA,IAAA,CAAK,qBAAA,GAAwB,oBAAA;AAE7B,IAAA,IAAA,CAAK,YAAA,GAAe,WAAW,CAAC,CAAA;AAEhC,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AAErB,IAAA,IAAA,CAAK,YAAA,GAAe,MAAA;AAEpB,IAAA,IAAA,CAAK,cAAA,GAAiB,KAAA;AAEtB,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,IAAA,CAAK,KAAA,EAAM;AAAA,IACb;AAAA,EACF;AAAA,EAEA,WAAA,GAAoB;AAClB,IAAA,IAAI,IAAA,CAAK,aAAA,KAAkB,MAAA,IAAa,IAAA,CAAK,iBAAiB,MAAA,EAAW;AACvE,MAAA;AAAA,IACF;AAEA,IAAA,aAAA,CAAc,KAAK,aAAa,CAAA;AAEhC,IAAA,aAAA,CAAc,KAAK,YAAY,CAAA;AAAA,EACjC;AAAA,EAEA,KAAA,GAAc;AACZ,IAAA,IAAI,KAAK,cAAA,EAAgB;AACvB,MAAA,OAAA,CAAQ,KAAK,oBAAoB,CAAA;AAEjC,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,cAAA,GAAiB,IAAA;AAEtB,IAAA,IAAI,KAAK,WAAA,EAAa;AACpB,MAAA,OAAA,CAAQ,KAAK,0CAA0C,CAAA;AAEvD,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,aAAA,GAAgB,WAAW,MAAM;AACpC,MAAA,IAAA,CAAK,WAAA,CAAY,KAAK,YAAY,CAAA;AAAA,IACpC,GAAG,CAAC,CAAA;AAEJ,IAAA,IAAA,CAAK,YAAA,GAAe,YAAY,MAAM;AACpC,MAAA,IAAA,CAAK,YAAA,GAAe,QAAA,CAAS,GAAA,CAAI,CAAA,EAAG,KAAK,YAAY,CAAA;AAErD,MAAA,IAAA,CAAK,WAAA,CAAY,KAAK,YAAY,CAAA;AAAA,IACpC,CAAA,EAAG,KAAK,qBAAqB,CAAA;AAAA,EAC/B;AAAA,EAES,QAAA,GAAiB;AACxB,IAAA,IAAA,CAAK,WAAA,EAAY;AAEjB,IAAA,KAAA,CAAM,QAAA,EAAS;AAAA,EACjB;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"from-abortable-promise.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-abortable-promise.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EAEjD,SAAS,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,KAC3C,qBAAqB,CAAC,CAAC,EAAE,CAAC,CACqB,CAAC"}
1
+ {"version":3,"file":"from-abortable-promise.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-abortable-promise.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,WAExC,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,KAC3C,qBAAqB,CAAC,CAAC,EAAE,CAAC,CACqB,CAAC"}
@@ -2,68 +2,36 @@ import { Optional, Result } from 'ts-data-forge';
2
2
  import '../utils/id-maker.mjs';
3
3
  import { RootObservableClass } from '../class/root-observable-class.mjs';
4
4
 
5
- /**
6
- * Creates an observable from a Promise factory that receives an `AbortSignal`.
7
- * When the observable is completed (e.g., by `switchMap` switching to a new
8
- * inner observable), the `AbortController` is automatically aborted, cancelling
9
- * the in-flight request.
10
- *
11
- * Emits `Result.ok(value)` when the promise resolves, or `Result.err(error)`
12
- * when it rejects. Rejections caused by abort (`AbortError`) are silently
13
- * ignored and do not emit.
14
- *
15
- * @template A - The type of the resolved value
16
- * @template E - The type of the error (excluding AbortError)
17
- * @param factory - A function that receives an `AbortSignal` and returns a Promise
18
- * @returns An observable that emits the promise result
19
- *
20
- * @example
21
- * ```ts
22
- * const results$ = query.pipe(
23
- * switchMap((q) =>
24
- * fromAbortablePromise((signal) =>
25
- * fetch(`/api/search?q=${q}`, { signal }).then((r) => r.json()),
26
- * ),
27
- * ),
28
- * );
29
- * ```
30
- */
31
- const fromAbortablePromise = (
32
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
33
- factory) => new FromAbortablePromiseObservableClass(factory);
5
+ const fromAbortablePromise = (factory) => new FromAbortablePromiseObservableClass(factory);
34
6
  class FromAbortablePromiseObservableClass extends RootObservableClass {
35
- #abortController;
36
- // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
37
- constructor(factory) {
38
- super({ initialValue: Optional.none });
39
- this.#abortController = new AbortController();
40
- const promise = factory(this.#abortController.signal);
41
- promise
42
- .then((value) => {
43
- if (this.isCompleted)
44
- return;
45
- this.startUpdate(Result.ok(value));
46
- })
47
- .catch((error) => {
48
- if (this.isCompleted)
49
- return;
50
- // Silently ignore AbortError — it means the observable was
51
- // intentionally completed (e.g., by switchMap).
52
- if (error instanceof DOMException && error.name === 'AbortError') {
53
- return;
54
- }
55
- this.startUpdate(Result.err(
56
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
57
- error));
58
- })
59
- .finally(() => {
60
- this.complete();
61
- });
62
- }
63
- complete() {
64
- this.#abortController.abort();
65
- super.complete();
66
- }
7
+ #abortController;
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ constructor(factory) {
10
+ super({ initialValue: Optional.none });
11
+ this.#abortController = new AbortController();
12
+ const promise = factory(this.#abortController.signal);
13
+ promise.then((value) => {
14
+ if (this.isCompleted) return;
15
+ this.startUpdate(Result.ok(value));
16
+ }).catch((error) => {
17
+ if (this.isCompleted) return;
18
+ if (error instanceof DOMException && error.name === "AbortError") {
19
+ return;
20
+ }
21
+ this.startUpdate(
22
+ Result.err(
23
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
24
+ error
25
+ )
26
+ );
27
+ }).finally(() => {
28
+ this.complete();
29
+ });
30
+ }
31
+ complete() {
32
+ this.#abortController.abort();
33
+ super.complete();
34
+ }
67
35
  }
68
36
 
69
37
  export { fromAbortablePromise };
@@ -1 +1 @@
1
- {"version":3,"file":"from-abortable-promise.mjs","sources":["../../../src/core/create/from-abortable-promise.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACI,MAAM,oBAAoB,GAAG;AAClC;AACA,OAA4C,KAE5C,IAAI,mCAAmC,CAAC,OAAO;AAEjD,MAAM,mCACJ,SAAQ,mBAAiC,CAAA;AAGhC,IAAA,gBAAgB;;AAGzB,IAAA,WAAA,CAAY,OAA4C,EAAA;QACtD,KAAK,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAEtC,QAAA,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,EAAE;QAE7C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;QAErD;AACG,aAAA,IAAI,CAAC,CAAC,KAAK,KAAI;YACd,IAAI,IAAI,CAAC,WAAW;gBAAE;YAEtB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACpC,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,CAAC,KAAc,KAAI;YACxB,IAAI,IAAI,CAAC,WAAW;gBAAE;;;YAItB,IAAI,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAChE;YACF;AAEA,YAAA,IAAI,CAAC,WAAW,CACd,MAAM,CAAC,GAAG;;YAER,KAAU,CACX,CACF;AACH,QAAA,CAAC;aACA,OAAO,CAAC,MAAK;YACZ,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAA,CAAC,CAAC;IACN;IAES,QAAQ,GAAA;AACf,QAAA,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE;QAE7B,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
1
+ {"version":3,"file":"from-abortable-promise.mjs","sources":["../../../src/core/create/from-abortable-promise.mts"],"sourcesContent":["import { Optional, Result } from 'ts-data-forge';\nimport { RootObservableClass } from '../class/index.mjs';\nimport { type FromPromiseObservable } from '../types/index.mjs';\n\n/**\n * Creates an observable from a Promise factory that receives an `AbortSignal`.\n * When the observable is completed (e.g., by `switchMap` switching to a new\n * inner observable), the `AbortController` is automatically aborted, cancelling\n * the in-flight request.\n *\n * Emits `Result.ok(value)` when the promise resolves, or `Result.err(error)`\n * when it rejects. Rejections caused by abort (`AbortError`) are silently\n * ignored and do not emit.\n *\n * @template A - The type of the resolved value\n * @template E - The type of the error (excluding AbortError)\n * @param factory - A function that receives an `AbortSignal` and returns a Promise\n * @returns An observable that emits the promise result\n *\n * @example\n * ```ts\n * const results$ = query.pipe(\n * switchMap((q) =>\n * fromAbortablePromise((signal) =>\n * fetch(`/api/search?q=${q}`, { signal }).then((r) => r.json()),\n * ),\n * ),\n * );\n * ```\n */\nexport const fromAbortablePromise = <A, E = unknown>(\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n factory: (signal: AbortSignal) => Promise<A>,\n): FromPromiseObservable<A, E> =>\n new FromAbortablePromiseObservableClass(factory);\n\nclass FromAbortablePromiseObservableClass<A, E = unknown>\n extends RootObservableClass<Result<A, E>>\n implements FromPromiseObservable<A, E>\n{\n readonly #abortController: AbortController;\n\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\n constructor(factory: (signal: AbortSignal) => Promise<A>) {\n super({ initialValue: Optional.none });\n\n this.#abortController = new AbortController();\n\n const promise = factory(this.#abortController.signal);\n\n promise\n .then((value) => {\n if (this.isCompleted) return;\n\n this.startUpdate(Result.ok(value));\n })\n .catch((error: unknown) => {\n if (this.isCompleted) return;\n\n // Silently ignore AbortError — it means the observable was\n // intentionally completed (e.g., by switchMap).\n if (error instanceof DOMException && error.name === 'AbortError') {\n return;\n }\n\n this.startUpdate(\n Result.err(\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n error as E,\n ),\n );\n })\n .finally(() => {\n this.complete();\n });\n }\n\n override complete(): void {\n this.#abortController.abort();\n\n super.complete();\n }\n}\n"],"names":[],"mappings":";;;;AA8BO,MAAM,oBAAA,GAAuB,CAElC,OAAA,KAEA,IAAI,oCAAoC,OAAO;AAEjD,MAAM,4CACI,mBAAA,CAEV;AAAA,EACW,gBAAA;AAAA;AAAA,EAGT,YAAY,OAAA,EAA8C;AACxD,IAAA,KAAA,CAAM,EAAE,YAAA,EAAc,QAAA,CAAS,IAAA,EAAM,CAAA;AAErC,IAAA,IAAA,CAAK,gBAAA,GAAmB,IAAI,eAAA,EAAgB;AAE5C,IAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,IAAA,CAAK,gBAAA,CAAiB,MAAM,CAAA;AAEpD,IAAA,OAAA,CACG,IAAA,CAAK,CAAC,KAAA,KAAU;AACf,MAAA,IAAI,KAAK,WAAA,EAAa;AAEtB,MAAA,IAAA,CAAK,WAAA,CAAY,MAAA,CAAO,EAAA,CAAG,KAAK,CAAC,CAAA;AAAA,IACnC,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,KAAA,KAAmB;AACzB,MAAA,IAAI,KAAK,WAAA,EAAa;AAItB,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AAChE,QAAA;AAAA,MACF;AAEA,MAAA,IAAA,CAAK,WAAA;AAAA,QACH,MAAA,CAAO,GAAA;AAAA;AAAA,UAEL;AAAA;AACF,OACF;AAAA,IACF,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,MAAA,IAAA,CAAK,QAAA,EAAS;AAAA,IAChB,CAAC,CAAA;AAAA,EACL;AAAA,EAES,QAAA,GAAiB;AACxB,IAAA,IAAA,CAAK,iBAAiB,KAAA,EAAM;AAE5B,IAAA,KAAA,CAAM,QAAA,EAAS;AAAA,EACjB;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"from-promise.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-promise.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EACxC,SAAS,OAAO,CAAC,CAAC,CAAC,KAClB,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAA4C,CAAC"}
1
+ {"version":3,"file":"from-promise.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-promise.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,WAC/B,OAAO,CAAC,CAAC,CAAC,KAClB,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAA4C,CAAC"}
@@ -2,74 +2,25 @@ import { Optional, Result } from 'ts-data-forge';
2
2
  import '../utils/id-maker.mjs';
3
3
  import { RootObservableClass } from '../class/root-observable-class.mjs';
4
4
 
5
- /**
6
- * Creates an observable from a Promise.
7
- * Emits Result.ok when the promise resolves, or Result.err when it rejects.
8
- *
9
- * @template A - The type of the resolved value
10
- * @template E - The type of the error
11
- * @param promise - The promise to convert to observable
12
- * @returns An observable that emits the promise result
13
- *
14
- * @example
15
- * ```ts
16
- * // Timeline:
17
- * //
18
- * // promise [pending...] -> resolved/rejected
19
- * // data$ Ok(value) or Err(error)
20
- * //
21
- * // Explanation:
22
- * // - fromPromise converts a Promise into an observable
23
- * // - Emits a Result type: Ok(value) on success, Err(error) on failure
24
- * // - Completes after emitting the result
25
- * // - Useful for integrating async operations into reactive flows
26
- *
27
- * const fetchData = async (): Promise<Readonly<{ value: number }>> =>
28
- * ({
29
- * value: 42,
30
- * }) as const;
31
- *
32
- * const data$ = fromPromise(fetchData());
33
- *
34
- * const valueHistory: Readonly<{ value: number }>[] = [];
35
- *
36
- * await new Promise<void>((resolve) => {
37
- * data$.subscribe(
38
- * (result) => {
39
- * if (Result.isOk(result)) {
40
- * valueHistory.push(result.value);
41
- * }
42
- * },
43
- * () => {
44
- * resolve();
45
- * },
46
- * );
47
- * });
48
- *
49
- * assert.deepStrictEqual(valueHistory, [{ value: 42 }]);
50
- * ```
51
- */
52
5
  const fromPromise = (promise) => new FromPromiseObservableClass(promise);
53
6
  class FromPromiseObservableClass extends RootObservableClass {
54
- constructor(promise) {
55
- super({ initialValue: Optional.none });
56
- promise
57
- .then((value) => {
58
- if (this.isCompleted)
59
- return;
60
- this.startUpdate(Result.ok(value));
61
- })
62
- .catch((error) => {
63
- if (this.isCompleted)
64
- return;
65
- this.startUpdate(Result.err(
66
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
67
- error));
68
- })
69
- .finally(() => {
70
- this.complete();
71
- });
72
- }
7
+ constructor(promise) {
8
+ super({ initialValue: Optional.none });
9
+ promise.then((value) => {
10
+ if (this.isCompleted) return;
11
+ this.startUpdate(Result.ok(value));
12
+ }).catch((error) => {
13
+ if (this.isCompleted) return;
14
+ this.startUpdate(
15
+ Result.err(
16
+ // eslint-disable-next-line total-functions/no-unsafe-type-assertion
17
+ error
18
+ )
19
+ );
20
+ }).finally(() => {
21
+ this.complete();
22
+ });
23
+ }
73
24
  }
74
25
 
75
26
  export { fromPromise };
@@ -1 +1 @@
1
- {"version":3,"file":"from-promise.mjs","sources":["../../../src/core/create/from-promise.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CG;AACI,MAAM,WAAW,GAAG,CACzB,OAAmB,KACa,IAAI,0BAA0B,CAAC,OAAO;AAExE,MAAM,0BACJ,SAAQ,mBAAiC,CAAA;AAGzC,IAAA,WAAA,CAAY,OAAmB,EAAA;QAC7B,KAAK,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEtC;AACG,aAAA,IAAI,CAAC,CAAC,KAAK,KAAI;YACd,IAAI,IAAI,CAAC,WAAW;gBAAE;YAEtB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AACpC,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,CAAC,KAAc,KAAI;YACxB,IAAI,IAAI,CAAC,WAAW;gBAAE;AAEtB,YAAA,IAAI,CAAC,WAAW,CACd,MAAM,CAAC,GAAG;;YAER,KAAU,CACX,CACF;AACH,QAAA,CAAC;aACA,OAAO,CAAC,MAAK;YACZ,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAA,CAAC,CAAC;IACN;AACD;;;;"}
1
+ {"version":3,"file":"from-promise.mjs","sources":["../../../src/core/create/from-promise.mts"],"sourcesContent":["import { Optional, Result } from 'ts-data-forge';\nimport { RootObservableClass } from '../class/index.mjs';\nimport { type FromPromiseObservable } from '../types/index.mjs';\n\n/**\n * Creates an observable from a Promise.\n * Emits Result.ok when the promise resolves, or Result.err when it rejects.\n *\n * @template A - The type of the resolved value\n * @template E - The type of the error\n * @param promise - The promise to convert to observable\n * @returns An observable that emits the promise result\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // promise [pending...] -> resolved/rejected\n * // data$ Ok(value) or Err(error)\n * //\n * // Explanation:\n * // - fromPromise converts a Promise into an observable\n * // - Emits a Result type: Ok(value) on success, Err(error) on failure\n * // - Completes after emitting the result\n * // - Useful for integrating async operations into reactive flows\n *\n * const fetchData = async (): Promise<Readonly<{ value: number }>> =>\n * ({\n * value: 42,\n * }) as const;\n *\n * const data$ = fromPromise(fetchData());\n *\n * const valueHistory: Readonly<{ value: number }>[] = [];\n *\n * await new Promise<void>((resolve) => {\n * data$.subscribe(\n * (result) => {\n * if (Result.isOk(result)) {\n * valueHistory.push(result.value);\n * }\n * },\n * () => {\n * resolve();\n * },\n * );\n * });\n *\n * assert.deepStrictEqual(valueHistory, [{ value: 42 }]);\n * ```\n */\nexport const fromPromise = <A, E = unknown>(\n promise: Promise<A>,\n): FromPromiseObservable<A, E> => new FromPromiseObservableClass(promise);\n\nclass FromPromiseObservableClass<A, E = unknown>\n extends RootObservableClass<Result<A, E>>\n implements FromPromiseObservable<A, E>\n{\n constructor(promise: Promise<A>) {\n super({ initialValue: Optional.none });\n\n promise\n .then((value) => {\n if (this.isCompleted) return;\n\n this.startUpdate(Result.ok(value));\n })\n .catch((error: unknown) => {\n if (this.isCompleted) return;\n\n this.startUpdate(\n Result.err(\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n error as E,\n ),\n );\n })\n .finally(() => {\n this.complete();\n });\n }\n}\n"],"names":[],"mappings":";;;;AAmDO,MAAM,WAAA,GAAc,CACzB,OAAA,KACgC,IAAI,2BAA2B,OAAO;AAExE,MAAM,mCACI,mBAAA,CAEV;AAAA,EACE,YAAY,OAAA,EAAqB;AAC/B,IAAA,KAAA,CAAM,EAAE,YAAA,EAAc,QAAA,CAAS,IAAA,EAAM,CAAA;AAErC,IAAA,OAAA,CACG,IAAA,CAAK,CAAC,KAAA,KAAU;AACf,MAAA,IAAI,KAAK,WAAA,EAAa;AAEtB,MAAA,IAAA,CAAK,WAAA,CAAY,MAAA,CAAO,EAAA,CAAG,KAAK,CAAC,CAAA;AAAA,IACnC,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,KAAA,KAAmB;AACzB,MAAA,IAAI,KAAK,WAAA,EAAa;AAEtB,MAAA,IAAA,CAAK,WAAA;AAAA,QACH,MAAA,CAAO,GAAA;AAAA;AAAA,UAEL;AAAA;AACF,OACF;AAAA,IACF,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,MAAA,IAAA,CAAK,QAAA,EAAS;AAAA,IAChB,CAAC,CAAA;AAAA,EACL;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"from-subscribable.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-subscribable.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EAC7C,cAAc,YAAY,CAAC,CAAC,CAAC,KAC5B,0BAA0B,CAAC,CAAC,EAAE,CAAC,CACiB,CAAC"}
1
+ {"version":3,"file":"from-subscribable.d.mts","sourceRoot":"","sources":["../../../src/core/create/from-subscribable.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,gBAC/B,YAAY,CAAC,CAAC,CAAC,KAC5B,0BAA0B,CAAC,CAAC,EAAE,CAAC,CACiB,CAAC"}
@@ -2,78 +2,27 @@ import { Optional, Result } from 'ts-data-forge';
2
2
  import '../utils/id-maker.mjs';
3
3
  import { RootObservableClass } from '../class/root-observable-class.mjs';
4
4
 
5
- /**
6
- * Converts any subscribable object into a SynState Observable.
7
- * Works with objects that have a subscribe(onNext, onError, onComplete) method.
8
- *
9
- * @template A - The type of values from the subscribable
10
- * @template E - The type of errors from the subscribable
11
- * @param subscribable - An object with a subscribe method
12
- * @returns An observable that wraps values in Result type
13
- *
14
- * @example
15
- * ```ts
16
- * // Explanation:
17
- * // - fromSubscribable converts any subscribable object into a SynState Observable
18
- * // - Works with objects that have a subscribe(onNext, onError, onComplete) method
19
- * // - Wraps values in Result type for error handling
20
- * // - Useful for integrating with other reactive libraries or custom subscribables
21
- *
22
- * // Example: Converting a custom subscribable
23
- * const customSubscribable = {
24
- * subscribe: (
25
- * onNext: (value: number) => void,
26
- * _onError?: (error: unknown) => void,
27
- * onComplete?: () => void,
28
- * ) => {
29
- * setTimeout(() => {
30
- * onNext(1);
31
- *
32
- * onNext(2);
33
- *
34
- * onNext(3);
35
- *
36
- * onComplete?.();
37
- * }, 0);
38
- *
39
- * return { unsubscribe: () => {} };
40
- * },
41
- * } as const;
42
- *
43
- * const observable$ = fromSubscribable<number>(customSubscribable);
44
- *
45
- * const valueHistory: number[] = [];
46
- *
47
- * await new Promise<void>((resolve) => {
48
- * observable$.subscribe(
49
- * (result) => {
50
- * if (Result.isOk(result)) {
51
- * valueHistory.push(result.value);
52
- * }
53
- * },
54
- * () => {
55
- * resolve();
56
- * },
57
- * );
58
- * });
59
- *
60
- * assert.deepStrictEqual(valueHistory, [1, 2, 3]);
61
- * ```
62
- */
63
5
  const fromSubscribable = (subscribable) => new FromSubscribableObservableClass(subscribable);
64
6
  class FromSubscribableObservableClass extends RootObservableClass {
65
- constructor(subscribable) {
66
- super({ initialValue: Optional.none });
67
- subscribable.subscribe((nextValue) => {
68
- this.startUpdate(Result.ok(nextValue));
69
- }, (error) => {
70
- this.startUpdate(Result.err(
7
+ constructor(subscribable) {
8
+ super({ initialValue: Optional.none });
9
+ subscribable.subscribe(
10
+ (nextValue) => {
11
+ this.startUpdate(Result.ok(nextValue));
12
+ },
13
+ (error) => {
14
+ this.startUpdate(
15
+ Result.err(
71
16
  // eslint-disable-next-line total-functions/no-unsafe-type-assertion
72
- error));
73
- }, () => {
74
- this.complete();
75
- });
76
- }
17
+ error
18
+ )
19
+ );
20
+ },
21
+ () => {
22
+ this.complete();
23
+ }
24
+ );
25
+ }
77
26
  }
78
27
 
79
28
  export { fromSubscribable };
@@ -1 +1 @@
1
- {"version":3,"file":"from-subscribable.mjs","sources":["../../../src/core/create/from-subscribable.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDG;AACI,MAAM,gBAAgB,GAAG,CAC9B,YAA6B,KAE7B,IAAI,+BAA+B,CAAC,YAAY;AAElD,MAAM,+BACJ,SAAQ,mBAAiC,CAAA;AAGzC,IAAA,WAAA,CAAY,YAA6B,EAAA;QACvC,KAAK,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAEtC,QAAA,YAAY,CAAC,SAAS,CACpB,CAAC,SAAS,KAAI;YACZ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AACxC,QAAA,CAAC,EACD,CAAC,KAAe,KAAI;AAClB,YAAA,IAAI,CAAC,WAAW,CACd,MAAM,CAAC,GAAG;;YAER,KAAU,CACX,CACF;QACH,CAAC,EACD,MAAK;YACH,IAAI,CAAC,QAAQ,EAAE;AACjB,QAAA,CAAC,CACF;IACH;AACD;;;;"}
1
+ {"version":3,"file":"from-subscribable.mjs","sources":["../../../src/core/create/from-subscribable.mts"],"sourcesContent":["import { Optional, Result } from 'ts-data-forge';\nimport { RootObservableClass } from '../class/index.mjs';\nimport {\n type FromSubscribableObservable,\n type Subscribable,\n} from '../types/index.mjs';\n\n/**\n * Converts any subscribable object into a SynState Observable.\n * Works with objects that have a subscribe(onNext, onError, onComplete) method.\n *\n * @template A - The type of values from the subscribable\n * @template E - The type of errors from the subscribable\n * @param subscribable - An object with a subscribe method\n * @returns An observable that wraps values in Result type\n *\n * @example\n * ```ts\n * // Explanation:\n * // - fromSubscribable converts any subscribable object into a SynState Observable\n * // - Works with objects that have a subscribe(onNext, onError, onComplete) method\n * // - Wraps values in Result type for error handling\n * // - Useful for integrating with other reactive libraries or custom subscribables\n *\n * // Example: Converting a custom subscribable\n * const customSubscribable = {\n * subscribe: (\n * onNext: (value: number) => void,\n * _onError?: (error: unknown) => void,\n * onComplete?: () => void,\n * ) => {\n * setTimeout(() => {\n * onNext(1);\n *\n * onNext(2);\n *\n * onNext(3);\n *\n * onComplete?.();\n * }, 0);\n *\n * return { unsubscribe: () => {} };\n * },\n * } as const;\n *\n * const observable$ = fromSubscribable<number>(customSubscribable);\n *\n * const valueHistory: number[] = [];\n *\n * await new Promise<void>((resolve) => {\n * observable$.subscribe(\n * (result) => {\n * if (Result.isOk(result)) {\n * valueHistory.push(result.value);\n * }\n * },\n * () => {\n * resolve();\n * },\n * );\n * });\n *\n * assert.deepStrictEqual(valueHistory, [1, 2, 3]);\n * ```\n */\nexport const fromSubscribable = <A, E = unknown>(\n subscribable: Subscribable<A>,\n): FromSubscribableObservable<A, E> =>\n new FromSubscribableObservableClass(subscribable);\n\nclass FromSubscribableObservableClass<A, E = unknown>\n extends RootObservableClass<Result<A, E>>\n implements FromSubscribableObservable<A, E>\n{\n constructor(subscribable: Subscribable<A>) {\n super({ initialValue: Optional.none });\n\n subscribable.subscribe(\n (nextValue) => {\n this.startUpdate(Result.ok(nextValue));\n },\n (error?: unknown) => {\n this.startUpdate(\n Result.err(\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n error as E,\n ),\n );\n },\n () => {\n this.complete();\n },\n );\n }\n}\n"],"names":[],"mappings":";;;;AAiEO,MAAM,gBAAA,GAAmB,CAC9B,YAAA,KAEA,IAAI,gCAAgC,YAAY;AAElD,MAAM,wCACI,mBAAA,CAEV;AAAA,EACE,YAAY,YAAA,EAA+B;AACzC,IAAA,KAAA,CAAM,EAAE,YAAA,EAAc,QAAA,CAAS,IAAA,EAAM,CAAA;AAErC,IAAA,YAAA,CAAa,SAAA;AAAA,MACX,CAAC,SAAA,KAAc;AACb,QAAA,IAAA,CAAK,WAAA,CAAY,MAAA,CAAO,EAAA,CAAG,SAAS,CAAC,CAAA;AAAA,MACvC,CAAA;AAAA,MACA,CAAC,KAAA,KAAoB;AACnB,QAAA,IAAA,CAAK,WAAA;AAAA,UACH,MAAA,CAAO,GAAA;AAAA;AAAA,YAEL;AAAA;AACF,SACF;AAAA,MACF,CAAA;AAAA,MACA,MAAM;AACJ,QAAA,IAAA,CAAK,QAAA,EAAS;AAAA,MAChB;AAAA,KACF;AAAA,EACF;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"just.d.mts","sourceRoot":"","sources":["../../../src/core/create/just.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,CAAC,EAAG,OAAO,CAAC,KAAG,yBAAyB,CAAC,CAAC,CASpE,CAAC"}
1
+ {"version":3,"file":"just.d.mts","sourceRoot":"","sources":["../../../src/core/create/just.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,CAAC,SAAU,CAAC,KAAG,yBAAyB,CAAC,CAAC,CASpE,CAAC"}
@@ -2,42 +2,12 @@ import { Optional } from 'ts-data-forge';
2
2
  import '../utils/id-maker.mjs';
3
3
  import { RootObservableClass } from '../class/root-observable-class.mjs';
4
4
 
5
- /**
6
- * Creates an Observable that holds a single static value and immediately
7
- * completes. Useful inside `switchMap` to emit a fallback value when no
8
- * asynchronous work is needed.
9
- *
10
- * @template A - The type of the value
11
- * @param value - The value to emit
12
- * @returns An initialized Observable that holds the value and is already completed
13
- *
14
- * @example
15
- * ```ts
16
- * const greeting$ = just('hello');
17
- *
18
- * const valueHistory: string[] = [];
19
- *
20
- * greeting$.subscribe(
21
- * (value) => {
22
- * valueHistory.push(value);
23
- * },
24
- * () => {
25
- * // onComplete — called immediately since just() completes right away
26
- * },
27
- * );
28
- *
29
- * assert.deepStrictEqual(valueHistory, ['hello']);
30
- *
31
- * assert.strictEqual(greeting$.isCompleted, true);
32
- * ```
33
- */
34
5
  const just = (value) => {
35
- const obs = new RootObservableClass({
36
- initialValue: Optional.some(value),
37
- });
38
- obs.complete();
39
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
40
- return obs;
6
+ const obs = new RootObservableClass({
7
+ initialValue: Optional.some(value)
8
+ });
9
+ obs.complete();
10
+ return obs;
41
11
  };
42
12
 
43
13
  export { just };
@@ -1 +1 @@
1
- {"version":3,"file":"just.mjs","sources":["../../../src/core/create/just.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACI,MAAM,IAAI,GAAG,CAAW,KAAQ,KAAkC;AACvE,IAAA,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAI;AACrC,QAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;AACnC,KAAA,CAAC;IAEF,GAAG,CAAC,QAAQ,EAAE;;AAGd,IAAA,OAAO,GAAmC;AAC5C;;;;"}
1
+ {"version":3,"file":"just.mjs","sources":["../../../src/core/create/just.mts"],"sourcesContent":["import { Optional } from 'ts-data-forge';\nimport { RootObservableClass } from '../class/index.mjs';\nimport { type InitializedRootObservable } from '../types/index.mjs';\n\n/**\n * Creates an Observable that holds a single static value and immediately\n * completes. Useful inside `switchMap` to emit a fallback value when no\n * asynchronous work is needed.\n *\n * @template A - The type of the value\n * @param value - The value to emit\n * @returns An initialized Observable that holds the value and is already completed\n *\n * @example\n * ```ts\n * const greeting$ = just('hello');\n *\n * const valueHistory: string[] = [];\n *\n * greeting$.subscribe(\n * (value) => {\n * valueHistory.push(value);\n * },\n * () => {\n * // onComplete — called immediately since just() completes right away\n * },\n * );\n *\n * assert.deepStrictEqual(valueHistory, ['hello']);\n *\n * assert.strictEqual(greeting$.isCompleted, true);\n * ```\n */\nexport const just = <const A,>(value: A): InitializedRootObservable<A> => {\n const obs = new RootObservableClass<A>({\n initialValue: Optional.some(value),\n });\n\n obs.complete();\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return obs as InitializedRootObservable<A>;\n};\n"],"names":[],"mappings":";;;;AAiCO,MAAM,IAAA,GAAO,CAAW,KAAA,KAA2C;AACxE,EAAA,MAAM,GAAA,GAAM,IAAI,mBAAA,CAAuB;AAAA,IACrC,YAAA,EAAc,QAAA,CAAS,IAAA,CAAK,KAAK;AAAA,GAClC,CAAA;AAED,EAAA,GAAA,CAAI,QAAA,EAAS;AAGb,EAAA,OAAO,GAAA;AACT;;;;"}