@okikio/observables 1.0.2

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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +578 -0
  3. package/esm/_dnt.polyfills.d.ts +20 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +12 -0
  6. package/esm/_spec.d.ts +260 -0
  7. package/esm/_spec.d.ts.map +1 -0
  8. package/esm/_spec.js +1 -0
  9. package/esm/_types.d.ts +141 -0
  10. package/esm/_types.d.ts.map +1 -0
  11. package/esm/_types.js +20 -0
  12. package/esm/error.d.ts +331 -0
  13. package/esm/error.d.ts.map +1 -0
  14. package/esm/error.js +408 -0
  15. package/esm/events.d.ts +320 -0
  16. package/esm/events.d.ts.map +1 -0
  17. package/esm/events.js +451 -0
  18. package/esm/helpers/_types.d.ts +188 -0
  19. package/esm/helpers/_types.d.ts.map +1 -0
  20. package/esm/helpers/_types.js +1 -0
  21. package/esm/helpers/mod.d.ts +90 -0
  22. package/esm/helpers/mod.d.ts.map +1 -0
  23. package/esm/helpers/mod.js +90 -0
  24. package/esm/helpers/operations/batch.d.ts +109 -0
  25. package/esm/helpers/operations/batch.d.ts.map +1 -0
  26. package/esm/helpers/operations/batch.js +140 -0
  27. package/esm/helpers/operations/combination.d.ts +162 -0
  28. package/esm/helpers/operations/combination.d.ts.map +1 -0
  29. package/esm/helpers/operations/combination.js +350 -0
  30. package/esm/helpers/operations/conditional.d.ts +211 -0
  31. package/esm/helpers/operations/conditional.d.ts.map +1 -0
  32. package/esm/helpers/operations/conditional.js +280 -0
  33. package/esm/helpers/operations/core.d.ts +198 -0
  34. package/esm/helpers/operations/core.d.ts.map +1 -0
  35. package/esm/helpers/operations/core.js +264 -0
  36. package/esm/helpers/operations/errors.d.ts +277 -0
  37. package/esm/helpers/operations/errors.d.ts.map +1 -0
  38. package/esm/helpers/operations/errors.js +378 -0
  39. package/esm/helpers/operations/mod.d.ts +26 -0
  40. package/esm/helpers/operations/mod.d.ts.map +1 -0
  41. package/esm/helpers/operations/mod.js +25 -0
  42. package/esm/helpers/operations/timing.d.ts +206 -0
  43. package/esm/helpers/operations/timing.d.ts.map +1 -0
  44. package/esm/helpers/operations/timing.js +457 -0
  45. package/esm/helpers/operators.d.ts +520 -0
  46. package/esm/helpers/operators.d.ts.map +1 -0
  47. package/esm/helpers/operators.js +563 -0
  48. package/esm/helpers/pipe.d.ts +118 -0
  49. package/esm/helpers/pipe.d.ts.map +1 -0
  50. package/esm/helpers/pipe.js +129 -0
  51. package/esm/helpers/utils.d.ts +142 -0
  52. package/esm/helpers/utils.d.ts.map +1 -0
  53. package/esm/helpers/utils.js +193 -0
  54. package/esm/mod.d.ts +863 -0
  55. package/esm/mod.d.ts.map +1 -0
  56. package/esm/mod.js +861 -0
  57. package/esm/observable.d.ts +1610 -0
  58. package/esm/observable.d.ts.map +1 -0
  59. package/esm/observable.js +1970 -0
  60. package/esm/package.json +3 -0
  61. package/esm/queue.d.ts +201 -0
  62. package/esm/queue.d.ts.map +1 -0
  63. package/esm/queue.js +273 -0
  64. package/esm/symbol.d.ts +60 -0
  65. package/esm/symbol.d.ts.map +1 -0
  66. package/esm/symbol.js +132 -0
  67. package/package.json +96 -0
  68. package/script/_dnt.polyfills.d.ts +20 -0
  69. package/script/_dnt.polyfills.d.ts.map +1 -0
  70. package/script/_dnt.polyfills.js +13 -0
  71. package/script/_spec.d.ts +260 -0
  72. package/script/_spec.d.ts.map +1 -0
  73. package/script/_spec.js +2 -0
  74. package/script/_types.d.ts +141 -0
  75. package/script/_types.d.ts.map +1 -0
  76. package/script/_types.js +22 -0
  77. package/script/error.d.ts +331 -0
  78. package/script/error.d.ts.map +1 -0
  79. package/script/error.js +414 -0
  80. package/script/events.d.ts +320 -0
  81. package/script/events.d.ts.map +1 -0
  82. package/script/events.js +458 -0
  83. package/script/helpers/_types.d.ts +188 -0
  84. package/script/helpers/_types.d.ts.map +1 -0
  85. package/script/helpers/_types.js +2 -0
  86. package/script/helpers/mod.d.ts +90 -0
  87. package/script/helpers/mod.d.ts.map +1 -0
  88. package/script/helpers/mod.js +106 -0
  89. package/script/helpers/operations/batch.d.ts +109 -0
  90. package/script/helpers/operations/batch.d.ts.map +1 -0
  91. package/script/helpers/operations/batch.js +144 -0
  92. package/script/helpers/operations/combination.d.ts +162 -0
  93. package/script/helpers/operations/combination.d.ts.map +1 -0
  94. package/script/helpers/operations/combination.js +355 -0
  95. package/script/helpers/operations/conditional.d.ts +211 -0
  96. package/script/helpers/operations/conditional.d.ts.map +1 -0
  97. package/script/helpers/operations/conditional.js +286 -0
  98. package/script/helpers/operations/core.d.ts +198 -0
  99. package/script/helpers/operations/core.d.ts.map +1 -0
  100. package/script/helpers/operations/core.js +272 -0
  101. package/script/helpers/operations/errors.d.ts +277 -0
  102. package/script/helpers/operations/errors.d.ts.map +1 -0
  103. package/script/helpers/operations/errors.js +387 -0
  104. package/script/helpers/operations/mod.d.ts +26 -0
  105. package/script/helpers/operations/mod.d.ts.map +1 -0
  106. package/script/helpers/operations/mod.js +41 -0
  107. package/script/helpers/operations/timing.d.ts +206 -0
  108. package/script/helpers/operations/timing.d.ts.map +1 -0
  109. package/script/helpers/operations/timing.js +464 -0
  110. package/script/helpers/operators.d.ts +520 -0
  111. package/script/helpers/operators.d.ts.map +1 -0
  112. package/script/helpers/operators.js +570 -0
  113. package/script/helpers/pipe.d.ts +118 -0
  114. package/script/helpers/pipe.d.ts.map +1 -0
  115. package/script/helpers/pipe.js +132 -0
  116. package/script/helpers/utils.d.ts +142 -0
  117. package/script/helpers/utils.d.ts.map +1 -0
  118. package/script/helpers/utils.js +200 -0
  119. package/script/mod.d.ts +863 -0
  120. package/script/mod.d.ts.map +1 -0
  121. package/script/mod.js +877 -0
  122. package/script/observable.d.ts +1610 -0
  123. package/script/observable.d.ts.map +1 -0
  124. package/script/observable.js +1984 -0
  125. package/script/package.json +3 -0
  126. package/script/queue.d.ts +201 -0
  127. package/script/queue.d.ts.map +1 -0
  128. package/script/queue.js +286 -0
  129. package/script/symbol.d.ts +60 -0
  130. package/script/symbol.d.ts.map +1 -0
  131. package/script/symbol.js +135 -0
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@okikio/observables",
3
+ "version": "1.0.2",
4
+ "description": "A spec-faithful yet ergonomic TC39-inspired Observable library with detailed types, tsdocs and examples.",
5
+ "keywords": [
6
+ "observable",
7
+ "observables",
8
+ "reactive",
9
+ "streams",
10
+ "tc39",
11
+ "web-streams",
12
+ "deno",
13
+ "node",
14
+ "bun"
15
+ ],
16
+ "author": "okikio",
17
+ "homepage": "https://github.com/okikio/observables#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/okikio/observables.git"
21
+ },
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/okikio/observables/issues"
25
+ },
26
+ "main": "./script/mod.js",
27
+ "module": "./esm/mod.js",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./esm/mod.js",
31
+ "require": "./script/mod.js"
32
+ },
33
+ "./error": {
34
+ "import": "./esm/error.js",
35
+ "require": "./script/error.js"
36
+ },
37
+ "./types": {
38
+ "import": "./esm/_types.js",
39
+ "require": "./script/_types.js"
40
+ },
41
+ "./events": {
42
+ "import": "./esm/events.js",
43
+ "require": "./script/events.js"
44
+ },
45
+ "./queue": {
46
+ "import": "./esm/queue.js",
47
+ "require": "./script/queue.js"
48
+ },
49
+ "./observable": {
50
+ "import": "./esm/observable.js",
51
+ "require": "./script/observable.js"
52
+ },
53
+ "./operators": {
54
+ "import": "./esm/helpers/mod.js",
55
+ "require": "./script/helpers/mod.js"
56
+ },
57
+ "./operations": {
58
+ "import": "./esm/helpers/operations/mod.js",
59
+ "require": "./script/helpers/operations/mod.js"
60
+ },
61
+ "./operations/batch": {
62
+ "import": "./esm/helpers/operations/batch.js",
63
+ "require": "./script/helpers/operations/batch.js"
64
+ },
65
+ "./operations/combination": {
66
+ "import": "./esm/helpers/operations/combination.js",
67
+ "require": "./script/helpers/operations/combination.js"
68
+ },
69
+ "./operations/conditional": {
70
+ "import": "./esm/helpers/operations/conditional.js",
71
+ "require": "./script/helpers/operations/conditional.js"
72
+ },
73
+ "./operations/errors": {
74
+ "import": "./esm/helpers/operations/errors.js",
75
+ "require": "./script/helpers/operations/errors.js"
76
+ },
77
+ "./operations/timing": {
78
+ "import": "./esm/helpers/operations/timing.js",
79
+ "require": "./script/helpers/operations/timing.js"
80
+ },
81
+ "./operations/core": {
82
+ "import": "./esm/helpers/operations/core.js",
83
+ "require": "./script/helpers/operations/core.js"
84
+ }
85
+ },
86
+ "scripts": {},
87
+ "sideEffects": false,
88
+ "publishConfig": {
89
+ "access": "public",
90
+ "provenance": true
91
+ },
92
+ "engines": {
93
+ "node": ">=20"
94
+ },
95
+ "_generatedBy": "dnt@dev"
96
+ }
@@ -0,0 +1,20 @@
1
+ declare global {
2
+ interface Error {
3
+ cause?: unknown;
4
+ }
5
+ }
6
+ export {};
7
+ declare global {
8
+ interface PromiseConstructor {
9
+ /**
10
+ * Creates a Promise that can be resolved or rejected using provided functions.
11
+ * @returns An object containing `promise` promise object, `resolve` and `reject` functions.
12
+ */
13
+ withResolvers<T>(): {
14
+ promise: Promise<T>;
15
+ resolve: (value: T | PromiseLike<T>) => void;
16
+ reject: (reason?: any) => void;
17
+ };
18
+ }
19
+ }
20
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,kBAAkB;QAC1B;;;WAGG;QACH,aAAa,CAAC,CAAC,KAAK;YAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;SAAE,CAAC;KAC3H;CACF"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // https://github.com/tc39/proposal-promise-with-resolvers/blob/3a78801e073e99217dbeb2c43ba7212f3bdc8b83/polyfills.js#L1C1-L9C2
4
+ if (Promise.withResolvers === undefined) {
5
+ Promise.withResolvers = () => {
6
+ const out = {};
7
+ out.promise = new Promise((resolve_, reject_) => {
8
+ out.resolve = resolve_;
9
+ out.reject = reject_;
10
+ });
11
+ return out;
12
+ };
13
+ }
@@ -0,0 +1,260 @@
1
+ import type { Symbol } from "./symbol.js";
2
+ /**
3
+ * Defines the minimal contract for subscribable objects in the Observable ecosystem.
4
+ *
5
+ * ObservableProtocol is the core interface that all Observable-like objects must
6
+ * implement. It represents the object returned by `[Symbol.observable]()` that
7
+ * consumers actually call `.subscribe()` on.
8
+ *
9
+ * This interface is designed for interoperability between different Observable
10
+ * implementations, allowing libraries to work with any object that conforms to
11
+ * this protocol.
12
+ *
13
+ * In the TC39 proposal, this is the interface that the object returned by
14
+ * `[Symbol.observable]()` must satisfy.
15
+ *
16
+ * @typeParam T - Type of values emitted by this Observable.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // Example of an object implementing ObservableProtocol
21
+ * const source: ObservableProtocol<number> = {
22
+ * subscribe(observer) {
23
+ * observer.next?.(1);
24
+ * observer.next?.(2);
25
+ * observer.complete?.();
26
+ * return { unsubscribe() {} };
27
+ * }
28
+ * };
29
+ *
30
+ * // Using the protocol
31
+ * const subscription = source.subscribe({
32
+ * next: value => console.log(value)
33
+ * });
34
+ * ```
35
+ */
36
+ export interface ObservableProtocol<T> {
37
+ /**
38
+ * Subscribes to this Observable with an observer object.
39
+ *
40
+ * This method is the primary way to consume values from an Observable.
41
+ * It begins the subscription process, connecting the consumer (observer)
42
+ * to the producer, and returns a subscription object that can be used
43
+ * to cancel the subscription.
44
+ *
45
+ * @param observer - Object with callback methods to handle notifications
46
+ * @returns A subscription object for cancellation
47
+ *
48
+ * @specref § 3.1 Observable.prototype.subscribe
49
+ */
50
+ subscribe(observer: SpecObserver<T>): SpecSubscription;
51
+ /**
52
+ * Subscribes to this Observable with individual callback functions.
53
+ *
54
+ * This is a convenience overload that allows subscribing with individual
55
+ * functions instead of an observer object. Internally, these callbacks
56
+ * are wrapped into an observer object.
57
+ *
58
+ * @param next - Function to handle each emitted value
59
+ * @param error - Optional function to handle errors
60
+ * @param complete - Optional function to handle completion
61
+ * @returns A subscription object for cancellation
62
+ *
63
+ * @specref § 3.1 Observable.prototype.subscribe
64
+ */
65
+ subscribe(next: (value: T) => void, error?: (error: unknown) => void, complete?: () => void): SpecSubscription;
66
+ }
67
+ /**
68
+ * Represents a cancellable connection to an Observable.
69
+ *
70
+ * A SpecSubscription is returned by the `subscribe` method and provides
71
+ * a way to cancel the subscription, stopping the delivery of values and
72
+ * releasing any resources associated with it.
73
+ *
74
+ * This interface is intentionally minimal, matching the TC39 proposal's
75
+ * requirements for subscription objects.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const subscription = observable.subscribe({
80
+ * next: value => console.log(value)
81
+ * });
82
+ *
83
+ * // Later, to cancel:
84
+ * subscription.unsubscribe();
85
+ * ```
86
+ */
87
+ export interface SpecSubscription {
88
+ /**
89
+ * Cancels the subscription and releases associated resources.
90
+ *
91
+ * When called:
92
+ * - Execution of the Observable is stopped
93
+ * - No further notifications are delivered to the observer
94
+ * - Resources associated with the subscription are released
95
+ * - If already closed (unsubscribed, errored, or completed), this is a no-op
96
+ *
97
+ * This method is idempotent - calling it multiple times has the same
98
+ * effect as calling it once.
99
+ *
100
+ * @specref § 4.2.2 %SubscriptionPrototype%.unsubscribe
101
+ */
102
+ unsubscribe(): void;
103
+ }
104
+ /**
105
+ * Defines a consumer of Observable notifications.
106
+ *
107
+ * An Observer is an object with optional callback methods that receive
108
+ * notifications from an Observable:
109
+ * - `next`: Called for each value emitted by the Observable
110
+ * - `error`: Called when an error occurs (terminal)
111
+ * - `complete`: Called when the Observable finishes normally (terminal)
112
+ * - `start`: Called immediately after subscription is established
113
+ *
114
+ * All methods are optional. If a method is missing, the corresponding
115
+ * notification is effectively ignored.
116
+ *
117
+ * @typeParam T - Type of values this observer can receive.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const observer: SpecObserver<number> = {
122
+ * start(subscription) {
123
+ * console.log('Starting subscription');
124
+ * // Save subscription reference if needed later
125
+ * },
126
+ * next(value) {
127
+ * console.log('Received value:', value);
128
+ * },
129
+ * error(err) {
130
+ * console.error('Error occurred:', err);
131
+ * },
132
+ * complete() {
133
+ * console.log('Observable completed');
134
+ * }
135
+ * };
136
+ *
137
+ * observable.subscribe(observer);
138
+ * ```
139
+ */
140
+ export interface SpecObserver<T> {
141
+ /**
142
+ * Called immediately after subscription is established.
143
+ *
144
+ * This callback:
145
+ * - Receives the subscription object as a parameter
146
+ * - Runs before any other observer methods
147
+ * - Allows the observer to store the subscription for later cancellation
148
+ * - Can throw exceptions, which are reported but don't prevent subscription
149
+ *
150
+ * If this method throws, the error is reported to the host environment
151
+ * but the subscription is still established.
152
+ *
153
+ * @param subscription - The subscription object created by this subscribe call
154
+ * @specref § 4.2 CreateSubscription
155
+ */
156
+ start?(subscription: SpecSubscription): void;
157
+ /**
158
+ * Receives the next value in the sequence.
159
+ *
160
+ * This is the main data channel of an Observable. It:
161
+ * - Is called zero or more times, once per emitted value
162
+ * - Receives each value as its only parameter
163
+ * - Is never called after error or complete
164
+ * - Is never called after unsubscribe
165
+ *
166
+ * If this method throws, the error is delivered to the `error` method.
167
+ *
168
+ * @param value - The value emitted by the Observable
169
+ * @specref § 5.2.4 %SubscriptionObserverPrototype%.next
170
+ */
171
+ next?(value: T): void;
172
+ /**
173
+ * Handles an error notification.
174
+ *
175
+ * This is called when:
176
+ * - The Observable encounters an error during execution
177
+ * - The observer's next or complete methods throw
178
+ *
179
+ * After this method is called:
180
+ * - The subscription is considered closed
181
+ * - No more notifications will be delivered
182
+ * - Resources associated with the subscription are released
183
+ *
184
+ * If this method throws, the error is reported to the host environment.
185
+ *
186
+ * @param error - The error that occurred
187
+ * @specref § 5.2.5 %SubscriptionObserverPrototype%.error
188
+ */
189
+ error?(error: unknown): void;
190
+ /**
191
+ * Handles successful completion of the Observable.
192
+ *
193
+ * This is called when:
194
+ * - The Observable has finished emitting values normally
195
+ * - No more values will be emitted
196
+ *
197
+ * After this method is called:
198
+ * - The subscription is considered closed
199
+ * - No more notifications will be delivered
200
+ * - Resources associated with the subscription are released
201
+ *
202
+ * If this method throws, the error is delivered to the `error` method.
203
+ *
204
+ * @specref § 5.2.6 %SubscriptionObserverPrototype%.complete
205
+ */
206
+ complete?(): void;
207
+ }
208
+ /**
209
+ * Defines an object that can be converted to an Observable.
210
+ *
211
+ * This interface represents anything that has a `[Symbol.observable]()` method,
212
+ * making it interoperable with the Observable ecosystem. It's the TypeScript
213
+ * equivalent of the TC39 proposal's "Observable-like" concept.
214
+ *
215
+ * The method must return an ObservableProtocol that can be subscribed to.
216
+ * This enables interoperability between different Observable implementations
217
+ * and allows conversion of custom types to Observables.
218
+ *
219
+ * @typeParam T - Type of values the resulting Observable will emit.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * // A simple string sequence as an Observable-like
224
+ * const greetings: SpecObservable<string> = {
225
+ * [Symbol.observable]() {
226
+ * return {
227
+ * subscribe(observer) {
228
+ * observer.next?.('Hello');
229
+ * observer.next?.('World');
230
+ * observer.complete?.();
231
+ * return { unsubscribe() {} };
232
+ * }
233
+ * };
234
+ * }
235
+ * };
236
+ *
237
+ * // Convert to an Observable
238
+ * const observable = Observable.from(greetings);
239
+ * ```
240
+ *
241
+ * @see https://tc39.es/proposal-observable/#observable-interface
242
+ * @specref § 3.3 Observable.prototype[@@observable]
243
+ */
244
+ export interface SpecObservable<T> {
245
+ /**
246
+ * Returns an object that conforms to the ObservableProtocol.
247
+ *
248
+ * This method acts as a conversion point that transforms any object
249
+ * into an Observable-like entity that can be subscribed to.
250
+ *
251
+ * When called:
252
+ * - It should return an object with a `subscribe` method
253
+ * - That object must conform to the ObservableProtocol interface
254
+ * - The returned object becomes the actual subscription target
255
+ *
256
+ * @returns An ObservableProtocol that can be subscribed to
257
+ */
258
+ [Symbol.observable](): ObservableProtocol<T>;
259
+ }
260
+ //# sourceMappingURL=_spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_spec.d.ts","sourceRoot":"","sources":["../src/_spec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;IAEvD;;;;;;;;;;;;;OAaG;IACH,SAAS,CACP,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EACxB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EAChC,QAAQ,CAAC,EAAE,MAAM,IAAI,GACpB,gBAAgB,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;OAaG;IACH,WAAW,IAAI,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,CAAC,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE7C;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtB;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAE7B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,IAAI,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B;;;;;;;;;;;;OAYG;IACH,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAC9C"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Public observer and subscription types for the Observable entrypoints.
3
+ *
4
+ * This module collects the runtime-facing interfaces that show up whenever you
5
+ * subscribe to an Observable. It defines the enhanced `Observer<T>` and
6
+ * `Subscription` shapes used by this package, then re-exports the lower-level
7
+ * spec types from `./_spec.ts` for callers that need proposal-aligned building
8
+ * blocks.
9
+ *
10
+ * Use this entrypoint when you are writing libraries, adapters, or tests that
11
+ * need to talk about Observable contracts without importing the full runtime
12
+ * implementation. In day-to-day app code, you will usually consume these types
13
+ * indirectly through `Observable`, `EventBus`, or operator helpers. They live
14
+ * here so the public type surface stays easy to find and stable across
15
+ * entrypoints.
16
+ *
17
+ * @module
18
+ */
19
+ import "./_dnt.polyfills.js";
20
+ import type { SpecObserver, SpecSubscription } from "./_spec.js";
21
+ import type { Symbol } from "./symbol.js";
22
+ /**
23
+ * Enhanced Observer interface for our implementation.
24
+ *
25
+ * This extends the minimal SpecObserver with additional capabilities and
26
+ * type-safety for our specific Observable implementation. It provides:
27
+ *
28
+ * 1. Type-safe access to our enhanced Subscription object
29
+ * 2. Consistent method signatures for notification handling
30
+ * 3. Same optional methods as the spec but with our own types
31
+ *
32
+ * While the base spec only requires minimal functionality, our extended
33
+ * Observer provides more guarantees and features.
34
+ *
35
+ * @typeParam T - Type of values this observer can receive.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { Observable } from './observable.ts';
40
+ * import type { Observer, Subscription } from './_types.ts';
41
+ *
42
+ * const timerObserver: Observer<number> = {
43
+ * start(subscription) {
44
+ * console.log('Timer started');
45
+ * // Can access enhanced subscription properties
46
+ * console.log('Subscription active:', !subscription.closed);
47
+ * },
48
+ * next(value) {
49
+ * console.log('Tick:', value);
50
+ * },
51
+ * complete() {
52
+ * console.log('Timer completed');
53
+ * }
54
+ * };
55
+ * ```
56
+ */
57
+ export interface Observer<T> extends SpecObserver<T> {
58
+ /**
59
+ * Called immediately after subscribing with our enhanced Subscription type.
60
+ *
61
+ * This override ensures the subscription passed to start() is our
62
+ * enhanced Subscription type with additional properties and methods,
63
+ * not just the minimal SpecSubscription.
64
+ *
65
+ * @param subscription - Our enhanced Subscription object
66
+ * @specref § 4.2 CreateSubscription
67
+ */
68
+ start?(subscription: Subscription): void;
69
+ }
70
+ /**
71
+ * Enhanced Subscription interface with additional features.
72
+ *
73
+ * Extends the minimal SpecSubscription with:
74
+ * 1. A `closed` property to check subscription state
75
+ * 2. Support for `using` blocks via Symbol.dispose
76
+ * 3. Support for async cleanup via Symbol.asyncDispose
77
+ * 4. String tag for proper toString() behavior
78
+ *
79
+ * These enhancements make subscriptions more useful and ergonomic
80
+ * while maintaining compatibility with the core specification.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { Observable } from './observable.ts';
85
+ *
86
+ * const source = Observable.of(1, 2, 3);
87
+ *
88
+ * // Standard usage
89
+ * const sub = source.subscribe((value) => console.log(value));
90
+ * console.log('Active:', !sub.closed);
91
+ * sub.unsubscribe();
92
+ *
93
+ * // With using blocks (automatically unsubscribes at block end)
94
+ * {
95
+ * using sub = source.subscribe((value) => console.log(value));
96
+ * // Use subscription here...
97
+ * } // Subscription cleaned up here
98
+ *
99
+ * // With async using blocks
100
+ * async function example() {
101
+ * await using sub = source.subscribe((value) => console.log(value));
102
+ * // Use subscription here...
103
+ * } // Awaits cleanup here
104
+ * ```
105
+ */
106
+ export interface Subscription extends SpecSubscription, Disposable, AsyncDisposable {
107
+ /**
108
+ * Indicates whether this subscription is closed.
109
+ *
110
+ * A subscription becomes closed when:
111
+ * - `unsubscribe()` is called explicitly
112
+ * - The Observable calls observer.error()
113
+ * - The Observable calls observer.complete()
114
+ *
115
+ * Once closed, a subscription cannot be reopened, and no further
116
+ * notifications will be delivered to the observer.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { Observable } from './observable.ts';
121
+ *
122
+ * const obs = Observable.of(1, 2, 3);
123
+ * const sub = obs.subscribe(() => {});
124
+ * console.log(sub.closed); // false
125
+ *
126
+ * sub.unsubscribe();
127
+ * console.log(sub.closed); // true
128
+ * ```
129
+ */
130
+ readonly closed: boolean;
131
+ /**
132
+ * Provides a standard string tag for the object.
133
+ *
134
+ * Used by Object.prototype.toString to identify this object type.
135
+ * This ensures that `Object.prototype.toString.call(subscription)`
136
+ * returns "[object Subscription]".
137
+ */
138
+ readonly [Symbol.toStringTag]: "Subscription";
139
+ }
140
+ export type * from "./_spec.js";
141
+ //# sourceMappingURL=_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_types.d.ts","sourceRoot":"","sources":["../src/_types.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAClD;;;;;;;;;OASG;IACH,KAAK,CAAC,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,YACf,SAAQ,gBAAgB,EAAE,UAAU,EAAE,eAAe;IACrD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAwBzB;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @filename: _types.ts
4
+ /**
5
+ * Public observer and subscription types for the Observable entrypoints.
6
+ *
7
+ * This module collects the runtime-facing interfaces that show up whenever you
8
+ * subscribe to an Observable. It defines the enhanced `Observer<T>` and
9
+ * `Subscription` shapes used by this package, then re-exports the lower-level
10
+ * spec types from `./_spec.ts` for callers that need proposal-aligned building
11
+ * blocks.
12
+ *
13
+ * Use this entrypoint when you are writing libraries, adapters, or tests that
14
+ * need to talk about Observable contracts without importing the full runtime
15
+ * implementation. In day-to-day app code, you will usually consume these types
16
+ * indirectly through `Observable`, `EventBus`, or operator helpers. They live
17
+ * here so the public type surface stays easy to find and stable across
18
+ * entrypoints.
19
+ *
20
+ * @module
21
+ */
22
+ require("./_dnt.polyfills.js");