@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-BJ3Ktp8q.d.ts +405 -0
- package/dist/index-CrxalFAt.d.cts +405 -0
- package/dist/index.cjs +47 -586
- package/dist/index.d.cts +1 -31
- package/dist/index.d.ts +1 -31
- package/dist/index.js +2 -540
- package/dist/stream/index.cjs +26 -0
- package/dist/stream/index.d.cts +2 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.js +3 -0
- package/dist/stream-DXHFB0xP.cjs +856 -0
- package/dist/stream-DiNE6b2z.js +712 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_stream = require('./stream-DXHFB0xP.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/errors.ts
|
|
3
4
|
/**
|
|
@@ -73,68 +74,6 @@ const isAggregatedError = (error) => {
|
|
|
73
74
|
return error instanceof AggregatedError;
|
|
74
75
|
};
|
|
75
76
|
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/stream/pipe.ts
|
|
78
|
-
/**
|
|
79
|
-
* @param source - The source stream.
|
|
80
|
-
* @param operators - The operators to apply.
|
|
81
|
-
* @returns The result of the last operator.
|
|
82
|
-
*/
|
|
83
|
-
function pipe(source, ...operators) {
|
|
84
|
-
return operators.reduce((src, operator) => operator(src), source);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/stream/operators/share.ts
|
|
89
|
-
/**
|
|
90
|
-
* Shares a single source across multiple subscribers (multicast).
|
|
91
|
-
* The source is only executed once, and all subscribers receive the same values.
|
|
92
|
-
* This is essential for deduplication and caching scenarios.
|
|
93
|
-
* @returns An operator that shares the source.
|
|
94
|
-
*/
|
|
95
|
-
const share = () => {
|
|
96
|
-
return (source) => {
|
|
97
|
-
const sinks = [];
|
|
98
|
-
let subscription = null;
|
|
99
|
-
let started = false;
|
|
100
|
-
let completed = false;
|
|
101
|
-
return (sink) => {
|
|
102
|
-
if (completed) {
|
|
103
|
-
sink.complete();
|
|
104
|
-
return { unsubscribe() {} };
|
|
105
|
-
}
|
|
106
|
-
sinks.push(sink);
|
|
107
|
-
if (!started) {
|
|
108
|
-
started = true;
|
|
109
|
-
subscription = source({
|
|
110
|
-
next(value) {
|
|
111
|
-
for (const s of [...sinks]) {
|
|
112
|
-
if (completed) break;
|
|
113
|
-
s.next(value);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
complete() {
|
|
117
|
-
if (!completed) {
|
|
118
|
-
completed = true;
|
|
119
|
-
for (const s of [...sinks]) s.complete();
|
|
120
|
-
sinks.length = 0;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return { unsubscribe() {
|
|
126
|
-
const idx = sinks.indexOf(sink);
|
|
127
|
-
if (idx !== -1) sinks.splice(idx, 1);
|
|
128
|
-
if (sinks.length === 0 && subscription) {
|
|
129
|
-
subscription.unsubscribe();
|
|
130
|
-
subscription = null;
|
|
131
|
-
started = false;
|
|
132
|
-
}
|
|
133
|
-
} };
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
|
|
138
77
|
//#endregion
|
|
139
78
|
//#region src/exchanges/compose.ts
|
|
140
79
|
const composeExchange = (options) => {
|
|
@@ -142,176 +81,15 @@ const composeExchange = (options) => {
|
|
|
142
81
|
return ({ forward, client }) => {
|
|
143
82
|
return exchanges.reduceRight((forward$1, exchange) => {
|
|
144
83
|
return (ops$) => {
|
|
145
|
-
return pipe(ops$, share(), exchange({
|
|
84
|
+
return require_stream.pipe(ops$, require_stream.share(), exchange({
|
|
146
85
|
forward: forward$1,
|
|
147
86
|
client
|
|
148
|
-
}), share());
|
|
87
|
+
}), require_stream.share());
|
|
149
88
|
};
|
|
150
89
|
}, forward);
|
|
151
90
|
};
|
|
152
91
|
};
|
|
153
92
|
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/stream/operators/merge-map.ts
|
|
156
|
-
/**
|
|
157
|
-
* Maps each value to a source and flattens all sources into a single output source.
|
|
158
|
-
* Similar to flatMap. Values from all inner sources are merged concurrently.
|
|
159
|
-
* @param fn - Function that returns a source for each value.
|
|
160
|
-
* @returns An operator that flattens mapped sources.
|
|
161
|
-
*/
|
|
162
|
-
const mergeMap = (fn) => {
|
|
163
|
-
return (source) => {
|
|
164
|
-
return (sink) => {
|
|
165
|
-
let outerCompleted = false;
|
|
166
|
-
let activeInner = 0;
|
|
167
|
-
let ended = false;
|
|
168
|
-
const innerSubscriptions = [];
|
|
169
|
-
const checkComplete = () => {
|
|
170
|
-
if (outerCompleted && activeInner === 0 && !ended) {
|
|
171
|
-
ended = true;
|
|
172
|
-
sink.complete();
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const outerSubscription = source({
|
|
176
|
-
next(value) {
|
|
177
|
-
if (ended) return;
|
|
178
|
-
activeInner++;
|
|
179
|
-
const innerSubscription = fn(value)({
|
|
180
|
-
next(innerValue) {
|
|
181
|
-
if (!ended) sink.next(innerValue);
|
|
182
|
-
},
|
|
183
|
-
complete() {
|
|
184
|
-
activeInner--;
|
|
185
|
-
checkComplete();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
innerSubscriptions.push(innerSubscription);
|
|
189
|
-
},
|
|
190
|
-
complete() {
|
|
191
|
-
outerCompleted = true;
|
|
192
|
-
checkComplete();
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return { unsubscribe() {
|
|
196
|
-
ended = true;
|
|
197
|
-
outerSubscription.unsubscribe();
|
|
198
|
-
for (const sub of innerSubscriptions) sub.unsubscribe();
|
|
199
|
-
innerSubscriptions.length = 0;
|
|
200
|
-
} };
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/stream/operators/filter.ts
|
|
207
|
-
function filter(predicate) {
|
|
208
|
-
return (source) => {
|
|
209
|
-
return (sink) => {
|
|
210
|
-
return source({
|
|
211
|
-
next(value) {
|
|
212
|
-
if (predicate(value)) sink.next(value);
|
|
213
|
-
},
|
|
214
|
-
complete() {
|
|
215
|
-
sink.complete();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/stream/sources/from-promise.ts
|
|
224
|
-
const fromPromise = (promise) => {
|
|
225
|
-
return (sink) => {
|
|
226
|
-
let cancelled = false;
|
|
227
|
-
promise.then((value) => {
|
|
228
|
-
if (!cancelled) {
|
|
229
|
-
sink.next(value);
|
|
230
|
-
sink.complete();
|
|
231
|
-
}
|
|
232
|
-
}, () => {
|
|
233
|
-
if (!cancelled) sink.complete();
|
|
234
|
-
});
|
|
235
|
-
return { unsubscribe() {
|
|
236
|
-
cancelled = true;
|
|
237
|
-
} };
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/stream/operators/merge.ts
|
|
243
|
-
/**
|
|
244
|
-
* Merges multiple sources into a single source.
|
|
245
|
-
* Values are emitted as soon as they arrive from any source.
|
|
246
|
-
* Completes when all sources complete.
|
|
247
|
-
* @param sources - The sources to merge.
|
|
248
|
-
* @returns A merged source.
|
|
249
|
-
*/
|
|
250
|
-
const merge = (...sources) => {
|
|
251
|
-
return (sink) => {
|
|
252
|
-
if (sources.length === 0) {
|
|
253
|
-
sink.complete();
|
|
254
|
-
return { unsubscribe() {} };
|
|
255
|
-
}
|
|
256
|
-
let activeCount = sources.length;
|
|
257
|
-
const subscriptions = [];
|
|
258
|
-
let ended = false;
|
|
259
|
-
let ready = false;
|
|
260
|
-
const buffer = [];
|
|
261
|
-
const checkComplete = () => {
|
|
262
|
-
if (activeCount === 0 && !ended) {
|
|
263
|
-
ended = true;
|
|
264
|
-
sink.complete();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
for (const source of sources) {
|
|
268
|
-
const subscription = source({
|
|
269
|
-
next(value) {
|
|
270
|
-
if (!ended) if (ready) sink.next(value);
|
|
271
|
-
else buffer.push(value);
|
|
272
|
-
},
|
|
273
|
-
complete() {
|
|
274
|
-
activeCount--;
|
|
275
|
-
if (ready) checkComplete();
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
subscriptions.push(subscription);
|
|
279
|
-
}
|
|
280
|
-
ready = true;
|
|
281
|
-
for (const value of buffer) if (!ended) sink.next(value);
|
|
282
|
-
buffer.length = 0;
|
|
283
|
-
checkComplete();
|
|
284
|
-
return { unsubscribe() {
|
|
285
|
-
ended = true;
|
|
286
|
-
for (const sub of subscriptions) sub.unsubscribe();
|
|
287
|
-
} };
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
//#endregion
|
|
292
|
-
//#region src/stream/operators/tap.ts
|
|
293
|
-
/**
|
|
294
|
-
* Executes a side effect for each value without modifying the stream.
|
|
295
|
-
* Useful for debugging, logging, or triggering side effects.
|
|
296
|
-
* @param fn - The side effect function.
|
|
297
|
-
* @returns An operator that taps into the stream.
|
|
298
|
-
*/
|
|
299
|
-
const tap = (fn) => {
|
|
300
|
-
return (source) => {
|
|
301
|
-
return (sink) => {
|
|
302
|
-
return source({
|
|
303
|
-
next(value) {
|
|
304
|
-
fn(value);
|
|
305
|
-
sink.next(value);
|
|
306
|
-
},
|
|
307
|
-
complete() {
|
|
308
|
-
sink.complete();
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
|
|
315
93
|
//#endregion
|
|
316
94
|
//#region src/exchanges/http.ts
|
|
317
95
|
const executeFetch = async ({ url, fetchOptions, operation, signal }) => {
|
|
@@ -378,11 +156,11 @@ const httpExchange = (options) => {
|
|
|
378
156
|
return ({ forward }) => {
|
|
379
157
|
return (ops$) => {
|
|
380
158
|
const inflight = /* @__PURE__ */ new Map();
|
|
381
|
-
return merge(pipe(ops$, filter((op) => op.variant === "request" && (op.artifact.kind === "query" || op.artifact.kind === "mutation")), mergeMap((op) => {
|
|
159
|
+
return require_stream.merge(require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && (op.artifact.kind === "query" || op.artifact.kind === "mutation")), require_stream.mergeMap((op) => {
|
|
382
160
|
inflight.get(op.key)?.abort();
|
|
383
161
|
const controller = new AbortController();
|
|
384
162
|
inflight.set(op.key, controller);
|
|
385
|
-
return fromPromise(executeFetch({
|
|
163
|
+
return require_stream.fromPromise(executeFetch({
|
|
386
164
|
url,
|
|
387
165
|
fetchOptions: {
|
|
388
166
|
mode,
|
|
@@ -395,7 +173,7 @@ const httpExchange = (options) => {
|
|
|
395
173
|
inflight.delete(op.key);
|
|
396
174
|
return result;
|
|
397
175
|
}));
|
|
398
|
-
}), filter((result) => result !== null)), pipe(ops$, filter((op) => op.variant === "teardown" || op.variant === "request" && (op.artifact.kind === "subscription" || op.artifact.kind === "fragment")), tap((op) => {
|
|
176
|
+
}), require_stream.filter((result) => result !== null)), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown" || op.variant === "request" && (op.artifact.kind === "subscription" || op.artifact.kind === "fragment")), require_stream.tap((op) => {
|
|
399
177
|
if (op.variant === "teardown") {
|
|
400
178
|
inflight.get(op.key)?.abort();
|
|
401
179
|
inflight.delete(op.key);
|
|
@@ -441,27 +219,6 @@ const delay = (ms) => {
|
|
|
441
219
|
};
|
|
442
220
|
};
|
|
443
221
|
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region src/stream/sources/from-array.ts
|
|
446
|
-
/**
|
|
447
|
-
* Creates a source that emits values from an array and completes.
|
|
448
|
-
* @param values - The array of values to emit.
|
|
449
|
-
* @returns A source containing the array values.
|
|
450
|
-
*/
|
|
451
|
-
const fromArray = (values) => {
|
|
452
|
-
return (sink) => {
|
|
453
|
-
let cancelled = false;
|
|
454
|
-
for (const value of values) {
|
|
455
|
-
if (cancelled) break;
|
|
456
|
-
sink.next(value);
|
|
457
|
-
}
|
|
458
|
-
if (!cancelled) sink.complete();
|
|
459
|
-
return { unsubscribe() {
|
|
460
|
-
cancelled = true;
|
|
461
|
-
} };
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
|
|
465
222
|
//#endregion
|
|
466
223
|
//#region src/utils.ts
|
|
467
224
|
/**
|
|
@@ -494,302 +251,6 @@ const isNullish = (value) => {
|
|
|
494
251
|
return value === void 0 || value === null;
|
|
495
252
|
};
|
|
496
253
|
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region src/stream/operators/map.ts
|
|
499
|
-
/**
|
|
500
|
-
* Maps each value from the source through a transformation function.
|
|
501
|
-
* @param fn - The transformation function.
|
|
502
|
-
* @returns An operator that maps values.
|
|
503
|
-
*/
|
|
504
|
-
const map = (fn) => {
|
|
505
|
-
return (source) => {
|
|
506
|
-
return (sink) => {
|
|
507
|
-
return source({
|
|
508
|
-
next(value) {
|
|
509
|
-
sink.next(fn(value));
|
|
510
|
-
},
|
|
511
|
-
complete() {
|
|
512
|
-
sink.complete();
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
};
|
|
516
|
-
};
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
//#endregion
|
|
520
|
-
//#region src/stream/operators/take-until.ts
|
|
521
|
-
/**
|
|
522
|
-
* Emits values from the source until the notifier source emits a value.
|
|
523
|
-
* When the notifier emits, the source is cancelled and completes immediately.
|
|
524
|
-
* @param notifier - Source that signals when to complete.
|
|
525
|
-
* @returns Operator that completes when notifier emits.
|
|
526
|
-
*/
|
|
527
|
-
const takeUntil = (notifier) => {
|
|
528
|
-
return (source) => {
|
|
529
|
-
return (sink) => {
|
|
530
|
-
let sourceSubscription = null;
|
|
531
|
-
let notifierSubscription = null;
|
|
532
|
-
let completed = false;
|
|
533
|
-
const complete = () => {
|
|
534
|
-
if (completed) return;
|
|
535
|
-
completed = true;
|
|
536
|
-
if (sourceSubscription) sourceSubscription.unsubscribe();
|
|
537
|
-
if (notifierSubscription) notifierSubscription.unsubscribe();
|
|
538
|
-
sink.complete();
|
|
539
|
-
};
|
|
540
|
-
notifierSubscription = notifier({
|
|
541
|
-
next() {
|
|
542
|
-
complete();
|
|
543
|
-
},
|
|
544
|
-
complete() {}
|
|
545
|
-
});
|
|
546
|
-
sourceSubscription = source({
|
|
547
|
-
next(value) {
|
|
548
|
-
if (!completed) sink.next(value);
|
|
549
|
-
},
|
|
550
|
-
complete() {
|
|
551
|
-
complete();
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
return { unsubscribe() {
|
|
555
|
-
complete();
|
|
556
|
-
} };
|
|
557
|
-
};
|
|
558
|
-
};
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
//#endregion
|
|
562
|
-
//#region src/stream/operators/switch-map.ts
|
|
563
|
-
const switchMap = (fn) => {
|
|
564
|
-
return (source) => {
|
|
565
|
-
return (sink) => {
|
|
566
|
-
let outerCompleted = false;
|
|
567
|
-
let ended = false;
|
|
568
|
-
let innerSubscription = null;
|
|
569
|
-
let hasInner = false;
|
|
570
|
-
const checkComplete = () => {
|
|
571
|
-
if (outerCompleted && !hasInner && !ended) {
|
|
572
|
-
ended = true;
|
|
573
|
-
sink.complete();
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
const outerSubscription = source({
|
|
577
|
-
next(value) {
|
|
578
|
-
if (ended) return;
|
|
579
|
-
if (innerSubscription) {
|
|
580
|
-
innerSubscription.unsubscribe();
|
|
581
|
-
innerSubscription = null;
|
|
582
|
-
}
|
|
583
|
-
hasInner = true;
|
|
584
|
-
innerSubscription = fn(value)({
|
|
585
|
-
next(innerValue) {
|
|
586
|
-
if (!ended) sink.next(innerValue);
|
|
587
|
-
},
|
|
588
|
-
complete() {
|
|
589
|
-
hasInner = false;
|
|
590
|
-
innerSubscription = null;
|
|
591
|
-
checkComplete();
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
},
|
|
595
|
-
complete() {
|
|
596
|
-
outerCompleted = true;
|
|
597
|
-
checkComplete();
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
return { unsubscribe() {
|
|
601
|
-
ended = true;
|
|
602
|
-
outerSubscription.unsubscribe();
|
|
603
|
-
if (innerSubscription) {
|
|
604
|
-
innerSubscription.unsubscribe();
|
|
605
|
-
innerSubscription = null;
|
|
606
|
-
}
|
|
607
|
-
} };
|
|
608
|
-
};
|
|
609
|
-
};
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region src/stream/operators/initialize.ts
|
|
614
|
-
/**
|
|
615
|
-
* Executes a side effect when the source is initialized (being subscribed to).
|
|
616
|
-
* @param fn - The side effect function.
|
|
617
|
-
* @returns An operator that executes the side effect when the source is initialized.
|
|
618
|
-
*/
|
|
619
|
-
const initialize = (fn) => {
|
|
620
|
-
return (source) => {
|
|
621
|
-
return (sink) => {
|
|
622
|
-
let completed = false;
|
|
623
|
-
const subscription = source({
|
|
624
|
-
next(value) {
|
|
625
|
-
if (!completed) sink.next(value);
|
|
626
|
-
},
|
|
627
|
-
complete() {
|
|
628
|
-
if (!completed) {
|
|
629
|
-
completed = true;
|
|
630
|
-
sink.complete();
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
fn();
|
|
635
|
-
return { unsubscribe() {
|
|
636
|
-
completed = true;
|
|
637
|
-
subscription.unsubscribe();
|
|
638
|
-
} };
|
|
639
|
-
};
|
|
640
|
-
};
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
//#endregion
|
|
644
|
-
//#region src/stream/operators/finalize.ts
|
|
645
|
-
/**
|
|
646
|
-
* Executes a side effect when the source terminates (completes or unsubscribes).
|
|
647
|
-
* @param fn - The side effect function.
|
|
648
|
-
* @returns An operator that executes the side effect when the source terminates.
|
|
649
|
-
*/
|
|
650
|
-
const finalize = (fn) => {
|
|
651
|
-
return (source) => {
|
|
652
|
-
return (sink) => {
|
|
653
|
-
let completed = false;
|
|
654
|
-
const subscription = source({
|
|
655
|
-
next(value) {
|
|
656
|
-
if (!completed) sink.next(value);
|
|
657
|
-
},
|
|
658
|
-
complete() {
|
|
659
|
-
if (!completed) {
|
|
660
|
-
completed = true;
|
|
661
|
-
fn();
|
|
662
|
-
sink.complete();
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
return { unsubscribe() {
|
|
667
|
-
if (!completed) {
|
|
668
|
-
completed = true;
|
|
669
|
-
fn();
|
|
670
|
-
}
|
|
671
|
-
subscription.unsubscribe();
|
|
672
|
-
} };
|
|
673
|
-
};
|
|
674
|
-
};
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
//#endregion
|
|
678
|
-
//#region src/stream/sources/from-value.ts
|
|
679
|
-
/**
|
|
680
|
-
* Creates a source that emits a single value and completes.
|
|
681
|
-
* @param value - The value to emit.
|
|
682
|
-
* @returns A source containing the single value.
|
|
683
|
-
*/
|
|
684
|
-
const fromValue = (value) => {
|
|
685
|
-
return (sink) => {
|
|
686
|
-
let cancelled = false;
|
|
687
|
-
if (!cancelled) {
|
|
688
|
-
sink.next(value);
|
|
689
|
-
sink.complete();
|
|
690
|
-
}
|
|
691
|
-
return { unsubscribe() {
|
|
692
|
-
cancelled = true;
|
|
693
|
-
} };
|
|
694
|
-
};
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
//#endregion
|
|
698
|
-
//#region src/stream/sources/make-subject.ts
|
|
699
|
-
/**
|
|
700
|
-
* Creates a new Subject which can be used as an IO event hub.
|
|
701
|
-
* @returns A new Subject.
|
|
702
|
-
*/
|
|
703
|
-
const makeSubject = () => {
|
|
704
|
-
const sinks = [];
|
|
705
|
-
const source = (sink) => {
|
|
706
|
-
sinks.push(sink);
|
|
707
|
-
return { unsubscribe() {
|
|
708
|
-
const idx = sinks.indexOf(sink);
|
|
709
|
-
if (idx !== -1) sinks.splice(idx, 1);
|
|
710
|
-
} };
|
|
711
|
-
};
|
|
712
|
-
const next = (value) => {
|
|
713
|
-
for (const sink of [...sinks]) sink.next(value);
|
|
714
|
-
};
|
|
715
|
-
const complete = () => {
|
|
716
|
-
for (const sink of [...sinks]) sink.complete();
|
|
717
|
-
sinks.length = 0;
|
|
718
|
-
};
|
|
719
|
-
return {
|
|
720
|
-
source,
|
|
721
|
-
next,
|
|
722
|
-
complete
|
|
723
|
-
};
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
//#endregion
|
|
727
|
-
//#region src/stream/sources/from-subscription.ts
|
|
728
|
-
const fromSubscription = (pull, poke) => {
|
|
729
|
-
return (sink) => {
|
|
730
|
-
let teardown = null;
|
|
731
|
-
let cancelled = false;
|
|
732
|
-
const initialValue = pull();
|
|
733
|
-
sink.next(initialValue);
|
|
734
|
-
if (cancelled) return { unsubscribe() {
|
|
735
|
-
cancelled = true;
|
|
736
|
-
} };
|
|
737
|
-
teardown = poke(() => {
|
|
738
|
-
if (!cancelled) {
|
|
739
|
-
const value = pull();
|
|
740
|
-
sink.next(value);
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
return { unsubscribe() {
|
|
744
|
-
cancelled = true;
|
|
745
|
-
if (teardown) {
|
|
746
|
-
teardown();
|
|
747
|
-
teardown = null;
|
|
748
|
-
}
|
|
749
|
-
} };
|
|
750
|
-
};
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
//#endregion
|
|
754
|
-
//#region src/stream/sources/make.ts
|
|
755
|
-
/**
|
|
756
|
-
* Creates a new Source from scratch from a passed subscriber function.
|
|
757
|
-
*
|
|
758
|
-
* The subscriber function receives an observer with next and complete callbacks.
|
|
759
|
-
* It must return a teardown function which is called when the source is cancelled.
|
|
760
|
-
* @internal
|
|
761
|
-
* @param subscriber - A callback that is called when the Source is subscribed to.
|
|
762
|
-
* @returns A Source created from the subscriber parameter.
|
|
763
|
-
*/
|
|
764
|
-
const make = (subscriber) => {
|
|
765
|
-
return (sink) => {
|
|
766
|
-
let cancelled = false;
|
|
767
|
-
let teardown = null;
|
|
768
|
-
teardown = subscriber({
|
|
769
|
-
next: (value) => {
|
|
770
|
-
if (!cancelled) sink.next(value);
|
|
771
|
-
},
|
|
772
|
-
complete: () => {
|
|
773
|
-
if (!cancelled) {
|
|
774
|
-
cancelled = true;
|
|
775
|
-
if (teardown) {
|
|
776
|
-
teardown();
|
|
777
|
-
teardown = null;
|
|
778
|
-
}
|
|
779
|
-
sink.complete();
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
return { unsubscribe() {
|
|
784
|
-
cancelled = true;
|
|
785
|
-
if (teardown) {
|
|
786
|
-
teardown();
|
|
787
|
-
teardown = null;
|
|
788
|
-
}
|
|
789
|
-
} };
|
|
790
|
-
};
|
|
791
|
-
};
|
|
792
|
-
|
|
793
254
|
//#endregion
|
|
794
255
|
//#region src/exchanges/dedup.ts
|
|
795
256
|
const makeDedupKey = (op) => {
|
|
@@ -814,13 +275,13 @@ const dedupExchange = () => {
|
|
|
814
275
|
return ({ forward }) => {
|
|
815
276
|
return (ops$) => {
|
|
816
277
|
const operations = /* @__PURE__ */ new Map();
|
|
817
|
-
return pipe(merge(pipe(ops$, filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "fragment"))), pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind !== "mutation" && op.artifact.kind !== "fragment"), filter((op) => {
|
|
278
|
+
return require_stream.pipe(require_stream.merge(require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "fragment"))), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && op.artifact.kind !== "mutation" && op.artifact.kind !== "fragment"), require_stream.filter((op) => {
|
|
818
279
|
const dedupKey = makeDedupKey(op);
|
|
819
280
|
const isInflight = operations.has(dedupKey);
|
|
820
281
|
if (isInflight) operations.get(dedupKey).add(op.key);
|
|
821
282
|
else operations.set(dedupKey, new Set([op.key]));
|
|
822
283
|
return (op.metadata.dedup?.skip ?? false) || !isInflight;
|
|
823
|
-
}), delay(0)), pipe(ops$, filter((op) => op.variant === "teardown"), filter((teardown) => {
|
|
284
|
+
}), delay(0)), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown"), require_stream.filter((teardown) => {
|
|
824
285
|
for (const [dedupKey, subs] of operations.entries()) if (subs.delete(teardown.key)) {
|
|
825
286
|
if (subs.size === 0) {
|
|
826
287
|
operations.delete(dedupKey);
|
|
@@ -829,10 +290,10 @@ const dedupExchange = () => {
|
|
|
829
290
|
return false;
|
|
830
291
|
}
|
|
831
292
|
return true;
|
|
832
|
-
}))), forward, mergeMap((result) => {
|
|
833
|
-
if (result.operation.variant !== "request" || result.operation.artifact.kind === "mutation" || result.operation.artifact.kind === "fragment") return fromValue(result);
|
|
293
|
+
}))), forward, require_stream.mergeMap((result) => {
|
|
294
|
+
if (result.operation.variant !== "request" || result.operation.artifact.kind === "mutation" || result.operation.artifact.kind === "fragment") return require_stream.fromValue(result);
|
|
834
295
|
const dedupKey = makeDedupKey(result.operation);
|
|
835
|
-
return fromArray([...operations.get(dedupKey) ?? /* @__PURE__ */ new Set()].map((key) => ({
|
|
296
|
+
return require_stream.fromArray([...operations.get(dedupKey) ?? /* @__PURE__ */ new Set()].map((key) => ({
|
|
836
297
|
...result,
|
|
837
298
|
operation: {
|
|
838
299
|
...result.operation,
|
|
@@ -1133,47 +594,47 @@ const cacheExchange = (options = {}) => {
|
|
|
1133
594
|
return ({ forward, client }) => {
|
|
1134
595
|
const cache = new Cache(client.schema);
|
|
1135
596
|
return (ops$) => {
|
|
1136
|
-
const fragment$ = pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind === "fragment"), mergeMap((op) => {
|
|
597
|
+
const fragment$ = require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && op.artifact.kind === "fragment"), require_stream.mergeMap((op) => {
|
|
1137
598
|
const fragmentRef = op.metadata?.fragmentRef;
|
|
1138
|
-
if (!fragmentRef) return fromValue({
|
|
599
|
+
if (!fragmentRef) return require_stream.fromValue({
|
|
1139
600
|
operation: op,
|
|
1140
601
|
errors: [new ExchangeError("Fragment operation missing fragmentRef in metadata. This usually happens when the wrong fragment reference was passed.", { exchangeName: "cache" })]
|
|
1141
602
|
});
|
|
1142
|
-
if (!isFragmentRef(fragmentRef)) return fromValue({
|
|
603
|
+
if (!isFragmentRef(fragmentRef)) return require_stream.fromValue({
|
|
1143
604
|
operation: op,
|
|
1144
605
|
data: fragmentRef,
|
|
1145
606
|
errors: []
|
|
1146
607
|
});
|
|
1147
|
-
const trigger = makeSubject();
|
|
1148
|
-
const teardown$ = pipe(ops$, filter((operation) => operation.variant === "teardown" && operation.key === op.key), tap(() => trigger.complete()));
|
|
1149
|
-
return pipe(merge(fromValue(void 0), trigger.source), switchMap(() => fromSubscription(() => cache.readFragment(op.artifact, fragmentRef), () => cache.subscribeFragment(op.artifact, fragmentRef, async () => {
|
|
608
|
+
const trigger = require_stream.makeSubject();
|
|
609
|
+
const teardown$ = require_stream.pipe(ops$, require_stream.filter((operation) => operation.variant === "teardown" && operation.key === op.key), require_stream.tap(() => trigger.complete()));
|
|
610
|
+
return require_stream.pipe(require_stream.merge(require_stream.fromValue(void 0), trigger.source), require_stream.switchMap(() => require_stream.fromSubscription(() => cache.readFragment(op.artifact, fragmentRef), () => cache.subscribeFragment(op.artifact, fragmentRef, async () => {
|
|
1150
611
|
await Promise.resolve();
|
|
1151
612
|
trigger.next();
|
|
1152
|
-
}))), takeUntil(teardown$), map((data) => ({
|
|
613
|
+
}))), require_stream.takeUntil(teardown$), require_stream.map((data) => ({
|
|
1153
614
|
operation: op,
|
|
1154
615
|
data,
|
|
1155
616
|
errors: []
|
|
1156
617
|
})));
|
|
1157
618
|
}));
|
|
1158
|
-
const nonCache$ = pipe(ops$, filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "subscription" || op.artifact.kind === "query" && fetchPolicy === "network-only")));
|
|
1159
|
-
const query$ = pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind === "query" && fetchPolicy !== "network-only"), share());
|
|
1160
|
-
return merge(fragment$, pipe(query$, mergeMap((op) => {
|
|
1161
|
-
const trigger = makeSubject();
|
|
1162
|
-
const teardown$ = pipe(ops$, filter((operation) => operation.variant === "teardown" && operation.key === op.key), tap(() => trigger.complete()));
|
|
1163
|
-
return pipe(merge(fromValue(void 0), trigger.source), switchMap(() => fromSubscription(() => cache.readQuery(op.artifact, op.variables), () => cache.subscribeQuery(op.artifact, op.variables, async () => {
|
|
619
|
+
const nonCache$ = require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "subscription" || op.artifact.kind === "query" && fetchPolicy === "network-only")));
|
|
620
|
+
const query$ = require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && op.artifact.kind === "query" && fetchPolicy !== "network-only"), require_stream.share());
|
|
621
|
+
return require_stream.merge(fragment$, require_stream.pipe(query$, require_stream.mergeMap((op) => {
|
|
622
|
+
const trigger = require_stream.makeSubject();
|
|
623
|
+
const teardown$ = require_stream.pipe(ops$, require_stream.filter((operation) => operation.variant === "teardown" && operation.key === op.key), require_stream.tap(() => trigger.complete()));
|
|
624
|
+
return require_stream.pipe(require_stream.merge(require_stream.fromValue(void 0), trigger.source), require_stream.switchMap(() => require_stream.fromSubscription(() => cache.readQuery(op.artifact, op.variables), () => cache.subscribeQuery(op.artifact, op.variables, async () => {
|
|
1164
625
|
await Promise.resolve();
|
|
1165
626
|
trigger.next();
|
|
1166
|
-
}))), takeUntil(teardown$), map((data) => ({
|
|
627
|
+
}))), require_stream.takeUntil(teardown$), require_stream.map((data) => ({
|
|
1167
628
|
operation: op,
|
|
1168
629
|
data,
|
|
1169
630
|
errors: []
|
|
1170
631
|
})));
|
|
1171
|
-
}), filter((result) => fetchPolicy === "cache-only" || fetchPolicy === "cache-and-network" && result.data !== null || fetchPolicy === "cache-first" && result.data !== null)), pipe(merge(nonCache$, pipe(query$, filter((op) => {
|
|
632
|
+
}), require_stream.filter((result) => fetchPolicy === "cache-only" || fetchPolicy === "cache-and-network" && result.data !== null || fetchPolicy === "cache-first" && result.data !== null)), require_stream.pipe(require_stream.merge(nonCache$, require_stream.pipe(query$, require_stream.filter((op) => {
|
|
1172
633
|
const cached = cache.readQuery(op.artifact, op.variables);
|
|
1173
634
|
return fetchPolicy === "cache-and-network" || cached === null;
|
|
1174
|
-
})), pipe(ops$, filter((op) => op.variant === "teardown"))), forward, tap((result) => {
|
|
635
|
+
})), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown"))), forward, require_stream.tap((result) => {
|
|
1175
636
|
if (result.operation.variant === "request" && result.data) cache.writeQuery(result.operation.artifact, result.operation.variables, result.data);
|
|
1176
|
-
}), filter((result) => result.operation.variant !== "request" || result.operation.artifact.kind !== "query" || fetchPolicy === "network-only")));
|
|
637
|
+
}), require_stream.filter((result) => result.operation.variant !== "request" || result.operation.artifact.kind !== "query" || fetchPolicy === "network-only")));
|
|
1177
638
|
};
|
|
1178
639
|
};
|
|
1179
640
|
};
|
|
@@ -1185,15 +646,15 @@ const retryExchange = (options = {}) => {
|
|
|
1185
646
|
const { maxAttempts = 3, backoff = (attempt) => Math.min(1e3 * 2 ** attempt, 3e4), shouldRetry = defaultShouldRetry } = options;
|
|
1186
647
|
return ({ forward }) => {
|
|
1187
648
|
return (ops$) => {
|
|
1188
|
-
const { source: retries$, next } = makeSubject();
|
|
649
|
+
const { source: retries$, next } = require_stream.makeSubject();
|
|
1189
650
|
const tornDown = /* @__PURE__ */ new Set();
|
|
1190
|
-
const teardown$ = pipe(ops$, filter((op) => op.variant === "teardown"), tap((op) => {
|
|
651
|
+
const teardown$ = require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown"), require_stream.tap((op) => {
|
|
1191
652
|
tornDown.add(op.key);
|
|
1192
653
|
}));
|
|
1193
|
-
return pipe(merge(pipe(ops$, filter((op) => op.variant === "request")), pipe(retries$, filter((op) => !tornDown.has(op.key)), mergeMap((op) => {
|
|
1194
|
-
const teardown$$1 = pipe(ops$, filter((operation) => operation.variant === "teardown" && operation.key === op.key));
|
|
1195
|
-
return pipe(fromValue(op), delay(op.metadata.retry.delay), takeUntil(teardown$$1));
|
|
1196
|
-
})), teardown$), forward, filter((result) => {
|
|
654
|
+
return require_stream.pipe(require_stream.merge(require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request")), require_stream.pipe(retries$, require_stream.filter((op) => !tornDown.has(op.key)), require_stream.mergeMap((op) => {
|
|
655
|
+
const teardown$$1 = require_stream.pipe(ops$, require_stream.filter((operation) => operation.variant === "teardown" && operation.key === op.key));
|
|
656
|
+
return require_stream.pipe(require_stream.fromValue(op), delay(op.metadata.retry.delay), require_stream.takeUntil(teardown$$1));
|
|
657
|
+
})), teardown$), forward, require_stream.filter((result) => {
|
|
1197
658
|
if (!result.errors || result.errors.length === 0) return true;
|
|
1198
659
|
if (result.operation.variant === "request" && result.operation.artifact.kind === "mutation") return true;
|
|
1199
660
|
const attempt = result.operation.metadata.retry?.attempt ?? 0;
|
|
@@ -1221,7 +682,7 @@ const retryExchange = (options = {}) => {
|
|
|
1221
682
|
const fragmentExchange = () => {
|
|
1222
683
|
return ({ forward }) => {
|
|
1223
684
|
return (ops$) => {
|
|
1224
|
-
return merge(pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind === "fragment"), map((op) => {
|
|
685
|
+
return require_stream.merge(require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && op.artifact.kind === "fragment"), require_stream.map((op) => {
|
|
1225
686
|
const fragmentRef = op.metadata.fragmentRef;
|
|
1226
687
|
if (!fragmentRef) return {
|
|
1227
688
|
operation: op,
|
|
@@ -1231,7 +692,7 @@ const fragmentExchange = () => {
|
|
|
1231
692
|
operation: op,
|
|
1232
693
|
data: fragmentRef
|
|
1233
694
|
};
|
|
1234
|
-
})), pipe(ops$, filter((op) => op.variant === "teardown" || op.artifact.kind !== "fragment"), forward));
|
|
695
|
+
})), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown" || op.artifact.kind !== "fragment"), forward));
|
|
1235
696
|
};
|
|
1236
697
|
};
|
|
1237
698
|
};
|
|
@@ -1269,9 +730,9 @@ const subscriptionExchange = (options) => {
|
|
|
1269
730
|
const { client } = options;
|
|
1270
731
|
return ({ forward }) => {
|
|
1271
732
|
return (ops$) => {
|
|
1272
|
-
return merge(pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind === "subscription"), mergeMap((op) => {
|
|
1273
|
-
const teardown$ = pipe(ops$, filter((operation) => operation.variant === "teardown" && operation.key === op.key));
|
|
1274
|
-
return pipe(make((observer) => {
|
|
733
|
+
return require_stream.merge(require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "request" && op.artifact.kind === "subscription"), require_stream.mergeMap((op) => {
|
|
734
|
+
const teardown$ = require_stream.pipe(ops$, require_stream.filter((operation) => operation.variant === "teardown" && operation.key === op.key));
|
|
735
|
+
return require_stream.pipe(require_stream.make((observer) => {
|
|
1275
736
|
let unsubscribe;
|
|
1276
737
|
let completed = false;
|
|
1277
738
|
Promise.resolve().then(() => {
|
|
@@ -1310,8 +771,8 @@ const subscriptionExchange = (options) => {
|
|
|
1310
771
|
completed = true;
|
|
1311
772
|
unsubscribe?.();
|
|
1312
773
|
};
|
|
1313
|
-
}), takeUntil(teardown$));
|
|
1314
|
-
})), pipe(ops$, filter((op) => op.variant === "teardown" || op.artifact.kind !== "subscription"), forward));
|
|
774
|
+
}), require_stream.takeUntil(teardown$));
|
|
775
|
+
})), require_stream.pipe(ops$, require_stream.filter((op) => op.variant === "teardown" || op.artifact.kind !== "subscription"), forward));
|
|
1315
776
|
};
|
|
1316
777
|
};
|
|
1317
778
|
};
|
|
@@ -1374,13 +835,13 @@ const serialize = (schemaMeta, variableDefs, scalars, variables) => {
|
|
|
1374
835
|
const scalarExchange = () => {
|
|
1375
836
|
return ({ forward, client }) => {
|
|
1376
837
|
return (ops$) => {
|
|
1377
|
-
return pipe(ops$, map((op) => {
|
|
838
|
+
return require_stream.pipe(ops$, require_stream.map((op) => {
|
|
1378
839
|
if (op.variant !== "request" || !op.artifact.variableDefs || !client.scalars) return op;
|
|
1379
840
|
return {
|
|
1380
841
|
...op,
|
|
1381
842
|
variables: serialize(client.schema, op.artifact.variableDefs, client.scalars, op.variables)
|
|
1382
843
|
};
|
|
1383
|
-
}), forward, map((result) => {
|
|
844
|
+
}), forward, require_stream.map((result) => {
|
|
1384
845
|
if (result.operation.variant !== "request" || !result.data || !client.scalars) return result;
|
|
1385
846
|
return {
|
|
1386
847
|
...result,
|
|
@@ -1396,7 +857,7 @@ const scalarExchange = () => {
|
|
|
1396
857
|
const terminalExchange = () => {
|
|
1397
858
|
return () => {
|
|
1398
859
|
return (ops$) => {
|
|
1399
|
-
return pipe(ops$, filter((op) => op.variant !== "teardown"), mergeMap((op) => fromValue({
|
|
860
|
+
return require_stream.pipe(ops$, require_stream.filter((op) => op.variant !== "teardown"), require_stream.mergeMap((op) => require_stream.fromValue({
|
|
1400
861
|
operation: op,
|
|
1401
862
|
errors: [new ExchangeError("No terminal exchange found in exchange chain. Did you forget to add httpExchange to your exchanges array?", { exchangeName: "terminal" })]
|
|
1402
863
|
})));
|
|
@@ -1432,7 +893,7 @@ var Client = class {
|
|
|
1432
893
|
fragmentExchange(),
|
|
1433
894
|
terminalExchange()
|
|
1434
895
|
] });
|
|
1435
|
-
this.operations$ = makeSubject();
|
|
896
|
+
this.operations$ = require_stream.makeSubject();
|
|
1436
897
|
this.results$ = exchange({
|
|
1437
898
|
forward: never,
|
|
1438
899
|
client: this
|
|
@@ -1457,11 +918,11 @@ var Client = class {
|
|
|
1457
918
|
};
|
|
1458
919
|
}
|
|
1459
920
|
executeOperation(operation) {
|
|
1460
|
-
return pipe(this.results$, initialize(() => this.operations$.next(operation)), filter((result) => result.operation.key === operation.key), finalize(() => this.operations$.next({
|
|
921
|
+
return require_stream.pipe(this.results$, require_stream.initialize(() => this.operations$.next(operation)), require_stream.filter((result) => result.operation.key === operation.key), require_stream.finalize(() => this.operations$.next({
|
|
1461
922
|
variant: "teardown",
|
|
1462
923
|
key: operation.key,
|
|
1463
924
|
metadata: {}
|
|
1464
|
-
})), share());
|
|
925
|
+
})), require_stream.share());
|
|
1465
926
|
}
|
|
1466
927
|
executeQuery(artifact, ...[variables, options]) {
|
|
1467
928
|
const operation = this.createOperation(artifact, variables);
|