@mearie/core 0.1.0 → 0.1.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.
package/dist/index.d.cts CHANGED
@@ -1,36 +1,6 @@
1
+ import { k as Source } from "./index-CrxalFAt.cjs";
1
2
  import { Artifact, Artifact as Artifact$1, ArtifactKind, ArtifactKind as ArtifactKind$1, DataOf, FragmentRefs, FragmentRefs as FragmentRefs$1, SchemaMeta, SchemaMeta as SchemaMeta$1, VariablesOf, VariablesOf as VariablesOf$1 } from "@mearie/shared";
2
3
 
3
- //#region src/stream/types.d.ts
4
- /**
5
- * Subscription allows cancelling a stream and cleaning up resources.
6
- */
7
- type Subscription = {
8
- /**
9
- * Cancel the stream and clean up resources.
10
- */
11
- unsubscribe(): void;
12
- };
13
- /**
14
- * Sink receives values from a Source.
15
- */
16
- type Sink<T> = {
17
- /**
18
- * Receive a data value.
19
- * @param value - The data value.
20
- */
21
- next(value: T): void;
22
- /**
23
- * Receive completion signal.
24
- */
25
- complete(): void;
26
- };
27
- /**
28
- * Source is a function that accepts a Sink and returns a Subscription.
29
- * When called, it starts pushing values to the sink.
30
- * @returns A subscription that can be used to cancel the stream.
31
- */
32
- type Source<T> = (sink: Sink<T>) => Subscription;
33
- //#endregion
34
4
  //#region src/errors.d.ts
35
5
  /**
36
6
  *
package/dist/index.d.ts CHANGED
@@ -1,36 +1,6 @@
1
+ import { k as Source } from "./index-BJ3Ktp8q.js";
1
2
  import { Artifact, Artifact as Artifact$1, ArtifactKind, ArtifactKind as ArtifactKind$1, DataOf, FragmentRefs, FragmentRefs as FragmentRefs$1, SchemaMeta, SchemaMeta as SchemaMeta$1, VariablesOf, VariablesOf as VariablesOf$1 } from "@mearie/shared";
2
3
 
3
- //#region src/stream/types.d.ts
4
- /**
5
- * Subscription allows cancelling a stream and cleaning up resources.
6
- */
7
- type Subscription = {
8
- /**
9
- * Cancel the stream and clean up resources.
10
- */
11
- unsubscribe(): void;
12
- };
13
- /**
14
- * Sink receives values from a Source.
15
- */
16
- type Sink<T> = {
17
- /**
18
- * Receive a data value.
19
- * @param value - The data value.
20
- */
21
- next(value: T): void;
22
- /**
23
- * Receive completion signal.
24
- */
25
- complete(): void;
26
- };
27
- /**
28
- * Source is a function that accepts a Sink and returns a Subscription.
29
- * When called, it starts pushing values to the sink.
30
- * @returns A subscription that can be used to cancel the stream.
31
- */
32
- type Source<T> = (sink: Sink<T>) => Subscription;
33
- //#endregion
34
4
  //#region src/errors.d.ts
35
5
  /**
36
6
  *
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { C as share, S as mergeMap, _ as fromArray, a as finalize, b as fromPromise, c as takeUntil, i as fromValue, n as fromSubscription, o as initialize, r as makeSubject, s as switchMap, t as make, u as map, v as tap, w as pipe, x as filter, y as merge } from "./stream-DiNE6b2z.js";
2
+
1
3
  //#region src/errors.ts
2
4
  /**
3
5
  *
@@ -72,68 +74,6 @@ const isAggregatedError = (error) => {
72
74
  return error instanceof AggregatedError;
73
75
  };
74
76
 
75
- //#endregion
76
- //#region src/stream/pipe.ts
77
- /**
78
- * @param source - The source stream.
79
- * @param operators - The operators to apply.
80
- * @returns The result of the last operator.
81
- */
82
- function pipe(source, ...operators) {
83
- return operators.reduce((src, operator) => operator(src), source);
84
- }
85
-
86
- //#endregion
87
- //#region src/stream/operators/share.ts
88
- /**
89
- * Shares a single source across multiple subscribers (multicast).
90
- * The source is only executed once, and all subscribers receive the same values.
91
- * This is essential for deduplication and caching scenarios.
92
- * @returns An operator that shares the source.
93
- */
94
- const share = () => {
95
- return (source) => {
96
- const sinks = [];
97
- let subscription = null;
98
- let started = false;
99
- let completed = false;
100
- return (sink) => {
101
- if (completed) {
102
- sink.complete();
103
- return { unsubscribe() {} };
104
- }
105
- sinks.push(sink);
106
- if (!started) {
107
- started = true;
108
- subscription = source({
109
- next(value) {
110
- for (const s of [...sinks]) {
111
- if (completed) break;
112
- s.next(value);
113
- }
114
- },
115
- complete() {
116
- if (!completed) {
117
- completed = true;
118
- for (const s of [...sinks]) s.complete();
119
- sinks.length = 0;
120
- }
121
- }
122
- });
123
- }
124
- return { unsubscribe() {
125
- const idx = sinks.indexOf(sink);
126
- if (idx !== -1) sinks.splice(idx, 1);
127
- if (sinks.length === 0 && subscription) {
128
- subscription.unsubscribe();
129
- subscription = null;
130
- started = false;
131
- }
132
- } };
133
- };
134
- };
135
- };
136
-
137
77
  //#endregion
138
78
  //#region src/exchanges/compose.ts
139
79
  const composeExchange = (options) => {
@@ -150,167 +90,6 @@ const composeExchange = (options) => {
150
90
  };
151
91
  };
152
92
 
153
- //#endregion
154
- //#region src/stream/operators/merge-map.ts
155
- /**
156
- * Maps each value to a source and flattens all sources into a single output source.
157
- * Similar to flatMap. Values from all inner sources are merged concurrently.
158
- * @param fn - Function that returns a source for each value.
159
- * @returns An operator that flattens mapped sources.
160
- */
161
- const mergeMap = (fn) => {
162
- return (source) => {
163
- return (sink) => {
164
- let outerCompleted = false;
165
- let activeInner = 0;
166
- let ended = false;
167
- const innerSubscriptions = [];
168
- const checkComplete = () => {
169
- if (outerCompleted && activeInner === 0 && !ended) {
170
- ended = true;
171
- sink.complete();
172
- }
173
- };
174
- const outerSubscription = source({
175
- next(value) {
176
- if (ended) return;
177
- activeInner++;
178
- const innerSubscription = fn(value)({
179
- next(innerValue) {
180
- if (!ended) sink.next(innerValue);
181
- },
182
- complete() {
183
- activeInner--;
184
- checkComplete();
185
- }
186
- });
187
- innerSubscriptions.push(innerSubscription);
188
- },
189
- complete() {
190
- outerCompleted = true;
191
- checkComplete();
192
- }
193
- });
194
- return { unsubscribe() {
195
- ended = true;
196
- outerSubscription.unsubscribe();
197
- for (const sub of innerSubscriptions) sub.unsubscribe();
198
- innerSubscriptions.length = 0;
199
- } };
200
- };
201
- };
202
- };
203
-
204
- //#endregion
205
- //#region src/stream/operators/filter.ts
206
- function filter(predicate) {
207
- return (source) => {
208
- return (sink) => {
209
- return source({
210
- next(value) {
211
- if (predicate(value)) sink.next(value);
212
- },
213
- complete() {
214
- sink.complete();
215
- }
216
- });
217
- };
218
- };
219
- }
220
-
221
- //#endregion
222
- //#region src/stream/sources/from-promise.ts
223
- const fromPromise = (promise) => {
224
- return (sink) => {
225
- let cancelled = false;
226
- promise.then((value) => {
227
- if (!cancelled) {
228
- sink.next(value);
229
- sink.complete();
230
- }
231
- }, () => {
232
- if (!cancelled) sink.complete();
233
- });
234
- return { unsubscribe() {
235
- cancelled = true;
236
- } };
237
- };
238
- };
239
-
240
- //#endregion
241
- //#region src/stream/operators/merge.ts
242
- /**
243
- * Merges multiple sources into a single source.
244
- * Values are emitted as soon as they arrive from any source.
245
- * Completes when all sources complete.
246
- * @param sources - The sources to merge.
247
- * @returns A merged source.
248
- */
249
- const merge = (...sources) => {
250
- return (sink) => {
251
- if (sources.length === 0) {
252
- sink.complete();
253
- return { unsubscribe() {} };
254
- }
255
- let activeCount = sources.length;
256
- const subscriptions = [];
257
- let ended = false;
258
- let ready = false;
259
- const buffer = [];
260
- const checkComplete = () => {
261
- if (activeCount === 0 && !ended) {
262
- ended = true;
263
- sink.complete();
264
- }
265
- };
266
- for (const source of sources) {
267
- const subscription = source({
268
- next(value) {
269
- if (!ended) if (ready) sink.next(value);
270
- else buffer.push(value);
271
- },
272
- complete() {
273
- activeCount--;
274
- if (ready) checkComplete();
275
- }
276
- });
277
- subscriptions.push(subscription);
278
- }
279
- ready = true;
280
- for (const value of buffer) if (!ended) sink.next(value);
281
- buffer.length = 0;
282
- checkComplete();
283
- return { unsubscribe() {
284
- ended = true;
285
- for (const sub of subscriptions) sub.unsubscribe();
286
- } };
287
- };
288
- };
289
-
290
- //#endregion
291
- //#region src/stream/operators/tap.ts
292
- /**
293
- * Executes a side effect for each value without modifying the stream.
294
- * Useful for debugging, logging, or triggering side effects.
295
- * @param fn - The side effect function.
296
- * @returns An operator that taps into the stream.
297
- */
298
- const tap = (fn) => {
299
- return (source) => {
300
- return (sink) => {
301
- return source({
302
- next(value) {
303
- fn(value);
304
- sink.next(value);
305
- },
306
- complete() {
307
- sink.complete();
308
- }
309
- });
310
- };
311
- };
312
- };
313
-
314
93
  //#endregion
315
94
  //#region src/exchanges/http.ts
316
95
  const executeFetch = async ({ url, fetchOptions, operation, signal }) => {
@@ -440,27 +219,6 @@ const delay = (ms) => {
440
219
  };
441
220
  };
442
221
 
443
- //#endregion
444
- //#region src/stream/sources/from-array.ts
445
- /**
446
- * Creates a source that emits values from an array and completes.
447
- * @param values - The array of values to emit.
448
- * @returns A source containing the array values.
449
- */
450
- const fromArray = (values) => {
451
- return (sink) => {
452
- let cancelled = false;
453
- for (const value of values) {
454
- if (cancelled) break;
455
- sink.next(value);
456
- }
457
- if (!cancelled) sink.complete();
458
- return { unsubscribe() {
459
- cancelled = true;
460
- } };
461
- };
462
- };
463
-
464
222
  //#endregion
465
223
  //#region src/utils.ts
466
224
  /**
@@ -493,302 +251,6 @@ const isNullish = (value) => {
493
251
  return value === void 0 || value === null;
494
252
  };
495
253
 
496
- //#endregion
497
- //#region src/stream/operators/map.ts
498
- /**
499
- * Maps each value from the source through a transformation function.
500
- * @param fn - The transformation function.
501
- * @returns An operator that maps values.
502
- */
503
- const map = (fn) => {
504
- return (source) => {
505
- return (sink) => {
506
- return source({
507
- next(value) {
508
- sink.next(fn(value));
509
- },
510
- complete() {
511
- sink.complete();
512
- }
513
- });
514
- };
515
- };
516
- };
517
-
518
- //#endregion
519
- //#region src/stream/operators/take-until.ts
520
- /**
521
- * Emits values from the source until the notifier source emits a value.
522
- * When the notifier emits, the source is cancelled and completes immediately.
523
- * @param notifier - Source that signals when to complete.
524
- * @returns Operator that completes when notifier emits.
525
- */
526
- const takeUntil = (notifier) => {
527
- return (source) => {
528
- return (sink) => {
529
- let sourceSubscription = null;
530
- let notifierSubscription = null;
531
- let completed = false;
532
- const complete = () => {
533
- if (completed) return;
534
- completed = true;
535
- if (sourceSubscription) sourceSubscription.unsubscribe();
536
- if (notifierSubscription) notifierSubscription.unsubscribe();
537
- sink.complete();
538
- };
539
- notifierSubscription = notifier({
540
- next() {
541
- complete();
542
- },
543
- complete() {}
544
- });
545
- sourceSubscription = source({
546
- next(value) {
547
- if (!completed) sink.next(value);
548
- },
549
- complete() {
550
- complete();
551
- }
552
- });
553
- return { unsubscribe() {
554
- complete();
555
- } };
556
- };
557
- };
558
- };
559
-
560
- //#endregion
561
- //#region src/stream/operators/switch-map.ts
562
- const switchMap = (fn) => {
563
- return (source) => {
564
- return (sink) => {
565
- let outerCompleted = false;
566
- let ended = false;
567
- let innerSubscription = null;
568
- let hasInner = false;
569
- const checkComplete = () => {
570
- if (outerCompleted && !hasInner && !ended) {
571
- ended = true;
572
- sink.complete();
573
- }
574
- };
575
- const outerSubscription = source({
576
- next(value) {
577
- if (ended) return;
578
- if (innerSubscription) {
579
- innerSubscription.unsubscribe();
580
- innerSubscription = null;
581
- }
582
- hasInner = true;
583
- innerSubscription = fn(value)({
584
- next(innerValue) {
585
- if (!ended) sink.next(innerValue);
586
- },
587
- complete() {
588
- hasInner = false;
589
- innerSubscription = null;
590
- checkComplete();
591
- }
592
- });
593
- },
594
- complete() {
595
- outerCompleted = true;
596
- checkComplete();
597
- }
598
- });
599
- return { unsubscribe() {
600
- ended = true;
601
- outerSubscription.unsubscribe();
602
- if (innerSubscription) {
603
- innerSubscription.unsubscribe();
604
- innerSubscription = null;
605
- }
606
- } };
607
- };
608
- };
609
- };
610
-
611
- //#endregion
612
- //#region src/stream/operators/initialize.ts
613
- /**
614
- * Executes a side effect when the source is initialized (being subscribed to).
615
- * @param fn - The side effect function.
616
- * @returns An operator that executes the side effect when the source is initialized.
617
- */
618
- const initialize = (fn) => {
619
- return (source) => {
620
- return (sink) => {
621
- let completed = false;
622
- const subscription = source({
623
- next(value) {
624
- if (!completed) sink.next(value);
625
- },
626
- complete() {
627
- if (!completed) {
628
- completed = true;
629
- sink.complete();
630
- }
631
- }
632
- });
633
- fn();
634
- return { unsubscribe() {
635
- completed = true;
636
- subscription.unsubscribe();
637
- } };
638
- };
639
- };
640
- };
641
-
642
- //#endregion
643
- //#region src/stream/operators/finalize.ts
644
- /**
645
- * Executes a side effect when the source terminates (completes or unsubscribes).
646
- * @param fn - The side effect function.
647
- * @returns An operator that executes the side effect when the source terminates.
648
- */
649
- const finalize = (fn) => {
650
- return (source) => {
651
- return (sink) => {
652
- let completed = false;
653
- const subscription = source({
654
- next(value) {
655
- if (!completed) sink.next(value);
656
- },
657
- complete() {
658
- if (!completed) {
659
- completed = true;
660
- fn();
661
- sink.complete();
662
- }
663
- }
664
- });
665
- return { unsubscribe() {
666
- if (!completed) {
667
- completed = true;
668
- fn();
669
- }
670
- subscription.unsubscribe();
671
- } };
672
- };
673
- };
674
- };
675
-
676
- //#endregion
677
- //#region src/stream/sources/from-value.ts
678
- /**
679
- * Creates a source that emits a single value and completes.
680
- * @param value - The value to emit.
681
- * @returns A source containing the single value.
682
- */
683
- const fromValue = (value) => {
684
- return (sink) => {
685
- let cancelled = false;
686
- if (!cancelled) {
687
- sink.next(value);
688
- sink.complete();
689
- }
690
- return { unsubscribe() {
691
- cancelled = true;
692
- } };
693
- };
694
- };
695
-
696
- //#endregion
697
- //#region src/stream/sources/make-subject.ts
698
- /**
699
- * Creates a new Subject which can be used as an IO event hub.
700
- * @returns A new Subject.
701
- */
702
- const makeSubject = () => {
703
- const sinks = [];
704
- const source = (sink) => {
705
- sinks.push(sink);
706
- return { unsubscribe() {
707
- const idx = sinks.indexOf(sink);
708
- if (idx !== -1) sinks.splice(idx, 1);
709
- } };
710
- };
711
- const next = (value) => {
712
- for (const sink of [...sinks]) sink.next(value);
713
- };
714
- const complete = () => {
715
- for (const sink of [...sinks]) sink.complete();
716
- sinks.length = 0;
717
- };
718
- return {
719
- source,
720
- next,
721
- complete
722
- };
723
- };
724
-
725
- //#endregion
726
- //#region src/stream/sources/from-subscription.ts
727
- const fromSubscription = (pull, poke) => {
728
- return (sink) => {
729
- let teardown = null;
730
- let cancelled = false;
731
- const initialValue = pull();
732
- sink.next(initialValue);
733
- if (cancelled) return { unsubscribe() {
734
- cancelled = true;
735
- } };
736
- teardown = poke(() => {
737
- if (!cancelled) {
738
- const value = pull();
739
- sink.next(value);
740
- }
741
- });
742
- return { unsubscribe() {
743
- cancelled = true;
744
- if (teardown) {
745
- teardown();
746
- teardown = null;
747
- }
748
- } };
749
- };
750
- };
751
-
752
- //#endregion
753
- //#region src/stream/sources/make.ts
754
- /**
755
- * Creates a new Source from scratch from a passed subscriber function.
756
- *
757
- * The subscriber function receives an observer with next and complete callbacks.
758
- * It must return a teardown function which is called when the source is cancelled.
759
- * @internal
760
- * @param subscriber - A callback that is called when the Source is subscribed to.
761
- * @returns A Source created from the subscriber parameter.
762
- */
763
- const make = (subscriber) => {
764
- return (sink) => {
765
- let cancelled = false;
766
- let teardown = null;
767
- teardown = subscriber({
768
- next: (value) => {
769
- if (!cancelled) sink.next(value);
770
- },
771
- complete: () => {
772
- if (!cancelled) {
773
- cancelled = true;
774
- if (teardown) {
775
- teardown();
776
- teardown = null;
777
- }
778
- sink.complete();
779
- }
780
- }
781
- });
782
- return { unsubscribe() {
783
- cancelled = true;
784
- if (teardown) {
785
- teardown();
786
- teardown = null;
787
- }
788
- } };
789
- };
790
- };
791
-
792
254
  //#endregion
793
255
  //#region src/exchanges/dedup.ts
794
256
  const makeDedupKey = (op) => {
@@ -0,0 +1,26 @@
1
+ const require_stream = require('../stream-DXHFB0xP.cjs');
2
+
3
+ exports.collect = require_stream.collect;
4
+ exports.collectAll = require_stream.collectAll;
5
+ exports.compose = require_stream.compose;
6
+ exports.filter = require_stream.filter;
7
+ exports.finalize = require_stream.finalize;
8
+ exports.fromArray = require_stream.fromArray;
9
+ exports.fromPromise = require_stream.fromPromise;
10
+ exports.fromSubscription = require_stream.fromSubscription;
11
+ exports.fromValue = require_stream.fromValue;
12
+ exports.initialize = require_stream.initialize;
13
+ exports.make = require_stream.make;
14
+ exports.makeSubject = require_stream.makeSubject;
15
+ exports.map = require_stream.map;
16
+ exports.merge = require_stream.merge;
17
+ exports.mergeMap = require_stream.mergeMap;
18
+ exports.peek = require_stream.peek;
19
+ exports.pipe = require_stream.pipe;
20
+ exports.publish = require_stream.publish;
21
+ exports.share = require_stream.share;
22
+ exports.subscribe = require_stream.subscribe;
23
+ exports.switchMap = require_stream.switchMap;
24
+ exports.take = require_stream.take;
25
+ exports.takeUntil = require_stream.takeUntil;
26
+ exports.tap = require_stream.tap;
@@ -0,0 +1,2 @@
1
+ import { A as Subscription, C as Observer, D as Operator, E as pipe, O as Sink, S as publish, T as compose, _ as filter, a as makeSubject, b as collectAll, c as finalize, d as switchMap, f as mergeMap, g as take, h as takeUntil, i as Subject, k as Source, l as initialize, m as share, n as fromPromise, o as fromArray, p as merge, r as fromSubscription, s as fromValue, t as make, u as tap, v as map, w as subscribe, x as collect, y as peek } from "../index-CrxalFAt.cjs";
2
+ export { Observer, Operator, Sink, Source, Subject, Subscription, collect, collectAll, compose, filter, finalize, fromArray, fromPromise, fromSubscription, fromValue, initialize, make, makeSubject, map, merge, mergeMap, peek, pipe, publish, share, subscribe, switchMap, take, takeUntil, tap };
@@ -0,0 +1,2 @@
1
+ import { A as Subscription, C as Observer, D as Operator, E as pipe, O as Sink, S as publish, T as compose, _ as filter, a as makeSubject, b as collectAll, c as finalize, d as switchMap, f as mergeMap, g as take, h as takeUntil, i as Subject, k as Source, l as initialize, m as share, n as fromPromise, o as fromArray, p as merge, r as fromSubscription, s as fromValue, t as make, u as tap, v as map, w as subscribe, x as collect, y as peek } from "../index-BJ3Ktp8q.js";
2
+ export { Observer, Operator, Sink, Source, Subject, Subscription, collect, collectAll, compose, filter, finalize, fromArray, fromPromise, fromSubscription, fromValue, initialize, make, makeSubject, map, merge, mergeMap, peek, pipe, publish, share, subscribe, switchMap, take, takeUntil, tap };
@@ -0,0 +1,3 @@
1
+ import { C as share, S as mergeMap, _ as fromArray, a as finalize, b as fromPromise, c as takeUntil, d as peek, f as collectAll, g as compose, h as subscribe, i as fromValue, l as take, m as publish, n as fromSubscription, o as initialize, p as collect, r as makeSubject, s as switchMap, t as make, u as map, v as tap, w as pipe, x as filter, y as merge } from "../stream-DiNE6b2z.js";
2
+
3
+ export { collect, collectAll, compose, filter, finalize, fromArray, fromPromise, fromSubscription, fromValue, initialize, make, makeSubject, map, merge, mergeMap, peek, pipe, publish, share, subscribe, switchMap, take, takeUntil, tap };