shelving 1.22.1 → 1.23.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/db/Database.d.ts +22 -46
- package/db/Database.js +35 -49
- package/db/Pagination.js +1 -1
- package/db/Write.d.ts +30 -0
- package/db/Write.js +37 -0
- package/db/index.d.ts +1 -1
- package/db/index.js +1 -1
- package/firestore/client/FirestoreClientProvider.d.ts +3 -3
- package/firestore/client/FirestoreClientProvider.js +2 -2
- package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
- package/firestore/server/FirestoreServerProvider.d.ts +3 -3
- package/firestore/server/FirestoreServerProvider.js +2 -2
- package/package.json +1 -1
- package/provider/BatchProvider.js +2 -2
- package/provider/CacheProvider.js +3 -3
- package/provider/MemoryProvider.js +20 -20
- package/query/Filter.d.ts +1 -1
- package/query/Filter.js +1 -1
- package/query/Filters.d.ts +1 -1
- package/query/Filters.js +1 -1
- package/query/Query.d.ts +1 -1
- package/query/Query.js +2 -2
- package/query/Rule.d.ts +3 -3
- package/query/Sort.d.ts +1 -1
- package/query/Sort.js +1 -1
- package/query/Sorts.d.ts +1 -1
- package/query/Sorts.js +1 -1
- package/react/useDocument.js +3 -3
- package/react/useFetch.js +2 -2
- package/react/usePureState.d.ts +4 -4
- package/react/useQuery.js +4 -4
- package/react/useSubscribe.js +1 -1
- package/stream/DataState.d.ts +2 -2
- package/stream/DataState.js +2 -2
- package/stream/LastStream.js +1 -1
- package/stream/LazyState.d.ts +1 -1
- package/stream/LazyState.js +4 -4
- package/stream/LazyStream.d.ts +1 -1
- package/stream/LazyStream.js +5 -5
- package/stream/State.d.ts +5 -5
- package/stream/State.js +6 -6
- package/stream/Stream.d.ts +13 -13
- package/stream/Stream.js +25 -25
- package/transform/AddEntriesTransform.d.ts +1 -1
- package/transform/AddEntriesTransform.js +1 -1
- package/transform/AddItemsTransform.d.ts +1 -1
- package/transform/AddItemsTransform.js +1 -1
- package/transform/DataTransform.d.ts +1 -1
- package/transform/DataTransform.js +3 -3
- package/transform/IncrementTransform.d.ts +1 -1
- package/transform/IncrementTransform.js +1 -1
- package/transform/RemoveEntriesTransform.d.ts +1 -1
- package/transform/RemoveEntriesTransform.js +1 -1
- package/transform/RemoveItemsTransform.d.ts +1 -1
- package/transform/RemoveItemsTransform.js +1 -1
- package/transform/Transform.d.ts +3 -3
- package/transform/hydrations.d.ts +1 -1
- package/transform/hydrations.js +1 -1
- package/transform/util.js +2 -2
- package/util/async.d.ts +6 -6
- package/util/clone.js +3 -3
- package/util/error.js +1 -1
- package/util/filter.d.ts +4 -4
- package/util/filter.js +5 -5
- package/util/function.d.ts +8 -0
- package/util/function.js +19 -0
- package/util/hydrate.d.ts +7 -7
- package/util/hydrate.js +13 -13
- package/util/index.d.ts +2 -3
- package/util/index.js +2 -3
- package/util/observable.d.ts +15 -19
- package/util/observable.js +22 -28
- package/util/sort.d.ts +4 -4
- package/util/sort.js +5 -6
- package/util/transform.d.ts +88 -0
- package/util/transform.js +48 -0
- package/db/Change.d.ts +0 -37
- package/db/Change.js +0 -60
- package/util/derive.d.ts +0 -88
- package/util/derive.js +0 -48
- package/util/dispatch.d.ts +0 -29
- package/util/dispatch.js +0 -43
package/query/Query.js
CHANGED
|
@@ -79,8 +79,8 @@ export class Query extends Rule {
|
|
|
79
79
|
return { __proto__: Object.getPrototypeOf(this), ...this, filters: new Filters(...filters) };
|
|
80
80
|
}
|
|
81
81
|
// Implement `Rule`
|
|
82
|
-
|
|
83
|
-
const sorted = this.sorts.
|
|
82
|
+
transform(results) {
|
|
83
|
+
const sorted = this.sorts.transform(this.filters.transform(results));
|
|
84
84
|
return typeof this.limit === "number" ? limitItems(sorted, this.limit) : sorted;
|
|
85
85
|
}
|
|
86
86
|
// Implement toString()
|
package/query/Rule.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Data,
|
|
1
|
+
import { Data, Transformable, Results } from "../util/index.js";
|
|
2
2
|
/** Something that can be used to query against a result set or an array of entries. */
|
|
3
|
-
export declare abstract class Rule<T extends Data> implements
|
|
4
|
-
abstract
|
|
3
|
+
export declare abstract class Rule<T extends Data> implements Transformable<Results<T>, Results<T>> {
|
|
4
|
+
abstract transform(results: Results<T>): Results<T>;
|
|
5
5
|
abstract toString(): string;
|
|
6
6
|
}
|
package/query/Sort.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare abstract class Sort<T extends Data> extends Rule<T> implements Ra
|
|
|
10
10
|
readonly key: QueryKey<T>;
|
|
11
11
|
constructor(key: QueryKey<T>);
|
|
12
12
|
rank([leftId, leftData]: Entry<T>, [rightId, rightData]: Entry<T>): number;
|
|
13
|
-
|
|
13
|
+
transform(iterable: Results<T>): Results<T>;
|
|
14
14
|
toString(): string;
|
|
15
15
|
}
|
|
16
16
|
/** Sort a list of values in ascending order. */
|
package/query/Sort.js
CHANGED
|
@@ -9,7 +9,7 @@ export class Sort extends Rule {
|
|
|
9
9
|
rank([leftId, leftData], [rightId, rightData]) {
|
|
10
10
|
return rank(getQueryProp(leftId, leftData, this.key), this.ranker, getQueryProp(rightId, rightData, this.key));
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
transform(iterable) {
|
|
13
13
|
return sortItems(iterable, this);
|
|
14
14
|
}
|
|
15
15
|
toString() {
|
package/query/Sorts.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export declare class Sorts<T extends Data> extends Rules<T, Sort<T>> implements
|
|
|
7
7
|
asc(key: QueryKey<T>): this;
|
|
8
8
|
desc(key: QueryKey<T>): this;
|
|
9
9
|
rank(left: Entry<T>, right: Entry<T>): number;
|
|
10
|
-
|
|
10
|
+
transform(iterable: Results<T>): Results<T>;
|
|
11
11
|
}
|
package/query/Sorts.js
CHANGED
package/react/useDocument.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { CacheProvider, throwAsync, NOERROR, findSourceProvider, NOVALUE
|
|
2
|
+
import { CacheProvider, throwAsync, NOERROR, findSourceProvider, NOVALUE } from "../index.js";
|
|
3
3
|
import { usePureEffect } from "./usePureEffect.js";
|
|
4
4
|
import { usePureMemo } from "./usePureMemo.js";
|
|
5
5
|
import { usePureState } from "./usePureState.js";
|
|
@@ -22,7 +22,7 @@ export function useAsyncDocument(ref, maxAge = 1000) {
|
|
|
22
22
|
// If `maxAge` is `true` open a subscription for 10 seconds.
|
|
23
23
|
// Done before `ref.get()` because efficient providers (i.e. `BatchProvider`) will reuse the subscription's first result as its first get request.
|
|
24
24
|
if (maxAge === true)
|
|
25
|
-
setTimeout(ref.subscribe(setNext, setError), 10000);
|
|
25
|
+
setTimeout(ref.subscribe({ next: setNext, error: setError }), 10000);
|
|
26
26
|
// Return a promise for the result.
|
|
27
27
|
return ref.result;
|
|
28
28
|
}
|
|
@@ -49,7 +49,7 @@ function subscribeEffect(ref, maxAge, next, error) {
|
|
|
49
49
|
else {
|
|
50
50
|
// If cache provider's cached document is older than maxAge then force refresh the data.
|
|
51
51
|
if (provider.getCachedAge(ref) > maxAge)
|
|
52
|
-
|
|
52
|
+
Promise.resolve(ref.result).then(next, error);
|
|
53
53
|
}
|
|
54
54
|
return stopCache;
|
|
55
55
|
}
|
package/react/useFetch.js
CHANGED
|
@@ -23,7 +23,7 @@ export function useFetch(fetcher, deps, maxAge = 86400000) {
|
|
|
23
23
|
// Create a new state and start a fetch.
|
|
24
24
|
state = new State();
|
|
25
25
|
sources.set(key, state);
|
|
26
|
-
dispatchAsyncNext(fetcher(...deps)
|
|
26
|
+
dispatchAsyncNext(state, fetcher(...deps));
|
|
27
27
|
}
|
|
28
28
|
else if (state.closed) {
|
|
29
29
|
// Clean up source in a few seconds if it's closed.
|
|
@@ -32,7 +32,7 @@ export function useFetch(fetcher, deps, maxAge = 86400000) {
|
|
|
32
32
|
}
|
|
33
33
|
else if (state.age > maxAge) {
|
|
34
34
|
// Refetch if state has value and it's older than `maxAge`
|
|
35
|
-
dispatchAsyncNext(fetcher(...deps)
|
|
35
|
+
dispatchAsyncNext(state, fetcher(...deps));
|
|
36
36
|
}
|
|
37
37
|
useSubscribe(state);
|
|
38
38
|
return state;
|
package/react/usePureState.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Arguments
|
|
1
|
+
import { Arguments } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Version of React's `useState()` that allows the use of a pure (side-effect free) function.
|
|
4
4
|
* - Unlike `useState()` the initialiser will be re-run and the state will be regenerated if `args` changes.
|
|
@@ -13,6 +13,6 @@ import { Arguments, Dispatcher } from "../index.js";
|
|
|
13
13
|
* - This means you can create the function once (outside the component) rather than creating it on every render.
|
|
14
14
|
* - This improves performance (though probably only noticeable on functions that render 1,000s of times).
|
|
15
15
|
*/
|
|
16
|
-
export declare function usePureState<T, A extends Arguments>(initial: (...args: A) => T, ...args: A): readonly [T,
|
|
17
|
-
export declare function usePureState<T, A extends Arguments>(initial: new (...args: A) => T, ...args: A): readonly [T,
|
|
18
|
-
export declare function usePureState<T>(initial: T, ...args: Arguments): readonly [T,
|
|
16
|
+
export declare function usePureState<T, A extends Arguments>(initial: (...args: A) => T, ...args: A): readonly [T, (next: T) => void];
|
|
17
|
+
export declare function usePureState<T, A extends Arguments>(initial: new (...args: A) => T, ...args: A): readonly [T, (next: T) => void];
|
|
18
|
+
export declare function usePureState<T>(initial: T, ...args: Arguments): readonly [T, (next: T) => void];
|
package/react/useQuery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { CacheProvider, throwAsync, NOERROR, findSourceProvider, NOVALUE,
|
|
2
|
+
import { CacheProvider, throwAsync, NOERROR, findSourceProvider, NOVALUE, TransformObserver, toMap, } from "../index.js";
|
|
3
3
|
import { usePureEffect } from "./usePureEffect.js";
|
|
4
4
|
import { usePureMemo } from "./usePureMemo.js";
|
|
5
5
|
import { usePureState } from "./usePureState.js";
|
|
@@ -22,7 +22,7 @@ export function useAsyncQuery(ref, maxAge = 1000) {
|
|
|
22
22
|
// If `maxAge` is `true` open a subscription for 10 seconds.
|
|
23
23
|
// Done before `ref.get()` because efficient providers (i.e. `BatchProvider`) will reuse the subscription's first result as its first get request.
|
|
24
24
|
if (maxAge === true)
|
|
25
|
-
setTimeout(ref.subscribeMap(setNext, setError), 10000);
|
|
25
|
+
setTimeout(ref.subscribeMap({ next: setNext, error: setError }), 10000);
|
|
26
26
|
// Return a promise for the result.
|
|
27
27
|
return ref.resultsMap;
|
|
28
28
|
}
|
|
@@ -37,7 +37,7 @@ function getCachedResults(ref) {
|
|
|
37
37
|
function subscribeEffect(ref, maxAge, next, error) {
|
|
38
38
|
if (ref) {
|
|
39
39
|
const provider = findSourceProvider(ref.provider, CacheProvider);
|
|
40
|
-
const observer = new
|
|
40
|
+
const observer = new TransformObserver(toMap, { next, error });
|
|
41
41
|
const stopCache = provider.cache.subscribeQuery(ref, observer);
|
|
42
42
|
if (maxAge === true) {
|
|
43
43
|
// If `maxAge` is true subscribe to the source for as long as this component is attached.
|
|
@@ -50,7 +50,7 @@ function subscribeEffect(ref, maxAge, next, error) {
|
|
|
50
50
|
else {
|
|
51
51
|
// If cache provider's cached document is older than maxAge then force refresh the data.
|
|
52
52
|
if (provider.getCachedAge(ref) > maxAge)
|
|
53
|
-
|
|
53
|
+
Promise.resolve(ref.resultsMap).then(next, error);
|
|
54
54
|
}
|
|
55
55
|
return stopCache;
|
|
56
56
|
}
|
package/react/useSubscribe.js
CHANGED
|
@@ -14,4 +14,4 @@ export function useSubscribe(subscribable) {
|
|
|
14
14
|
usePureEffect(subscribeEffect, useState(LOADING)[1], subscribable);
|
|
15
15
|
}
|
|
16
16
|
/** Effect that subscribes the component to changes in the `State` instance for the lifetime of the component. */
|
|
17
|
-
const subscribeEffect = (
|
|
17
|
+
const subscribeEffect = (change, subscribable) => subscribable ? subscribe(subscribable, { next: change, error: change }) : undefined;
|
package/stream/DataState.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Key, Data,
|
|
1
|
+
import { Key, Data, Transformers } from "../util/index.js";
|
|
2
2
|
import { State } from "./State.js";
|
|
3
3
|
/** State that stores an array and has additional methods to help with that. */
|
|
4
4
|
export declare class DataState<T extends Data> extends State<T> {
|
|
5
5
|
/** Set a prop in this object to a new value. */
|
|
6
6
|
set<K extends Key<T>>(key: K, value: T[K]): void;
|
|
7
7
|
/** Update several props in this object. */
|
|
8
|
-
update(updates:
|
|
8
|
+
update(updates: Transformers<T>): void;
|
|
9
9
|
}
|
package/stream/DataState.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withProp,
|
|
1
|
+
import { withProp, transformData } from "../util/index.js";
|
|
2
2
|
import { State } from "./State.js";
|
|
3
3
|
/** State that stores an array and has additional methods to help with that. */
|
|
4
4
|
export class DataState extends State {
|
|
@@ -8,6 +8,6 @@ export class DataState extends State {
|
|
|
8
8
|
}
|
|
9
9
|
/** Update several props in this object. */
|
|
10
10
|
update(updates) {
|
|
11
|
-
this.next(
|
|
11
|
+
this.next(transformData(this.value, updates));
|
|
12
12
|
}
|
|
13
13
|
}
|
package/stream/LastStream.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Stream } from "./Stream.js";
|
|
|
4
4
|
export class LastStream extends Stream {
|
|
5
5
|
// Override to dispatch only to a slice of the subscribers.
|
|
6
6
|
_dispatch(value) {
|
|
7
|
-
const subscriber = getLastItem(this.
|
|
7
|
+
const subscriber = getLastItem(this._observers);
|
|
8
8
|
if (subscriber)
|
|
9
9
|
dispatchNext(subscriber, value);
|
|
10
10
|
}
|
package/stream/LazyState.d.ts
CHANGED
package/stream/LazyState.js
CHANGED
|
@@ -9,20 +9,20 @@ export class LazyState extends State {
|
|
|
9
9
|
this._delay = delay;
|
|
10
10
|
}
|
|
11
11
|
// Override to stop the source subscription when the last subscriber unsubscribes.
|
|
12
|
-
|
|
13
|
-
super.
|
|
12
|
+
_off(observer) {
|
|
13
|
+
super._off(observer);
|
|
14
14
|
if (this._delay) {
|
|
15
15
|
// Maybe stop in a bit (if there are still no subscribers).
|
|
16
16
|
if (this._timeout)
|
|
17
17
|
clearTimeout(this._timeout);
|
|
18
18
|
this._timeout = setTimeout(() => {
|
|
19
|
-
if (!this.
|
|
19
|
+
if (!this._observers.size && !this.closed)
|
|
20
20
|
this.complete();
|
|
21
21
|
}, this._delay);
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
// Stop now.
|
|
25
|
-
if (!this.
|
|
25
|
+
if (!this._observers.size && !this.closed)
|
|
26
26
|
this.complete();
|
|
27
27
|
}
|
|
28
28
|
}
|
package/stream/LazyStream.d.ts
CHANGED
package/stream/LazyStream.js
CHANGED
|
@@ -9,19 +9,19 @@ export class LazyStream extends Stream {
|
|
|
9
9
|
this._delay = delay;
|
|
10
10
|
}
|
|
11
11
|
// Override to stop the source subscription when the last subscriber unsubscribes.
|
|
12
|
-
|
|
13
|
-
super.
|
|
12
|
+
_off(observer) {
|
|
13
|
+
super._off(observer);
|
|
14
14
|
if (this._delay) {
|
|
15
15
|
// Maybe stop in a bit (if there are still no subscribers).
|
|
16
|
-
if (!this.
|
|
16
|
+
if (!this._observers.size && !this.closed) {
|
|
17
17
|
if (this._timeout)
|
|
18
18
|
clearTimeout(this._timeout);
|
|
19
|
-
this._timeout = setTimeout(() => !this.
|
|
19
|
+
this._timeout = setTimeout(() => !this._observers.size && !this.closed && this.complete(), this._delay);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
// Stop now.
|
|
24
|
-
if (!this.
|
|
24
|
+
if (!this._observers.size && !this.closed)
|
|
25
25
|
this.complete();
|
|
26
26
|
}
|
|
27
27
|
}
|
package/stream/State.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transformer, LOADING, ObserverType, NOERROR, Observer } from "../util/index.js";
|
|
2
2
|
import { Stream } from "./Stream.js";
|
|
3
3
|
/** Any state (useful for `extends AnySubscribable` clauses). */
|
|
4
4
|
export declare type AnyState = State<any>;
|
|
@@ -14,8 +14,8 @@ export declare type AnyState = State<any>;
|
|
|
14
14
|
* */
|
|
15
15
|
export interface State<T> {
|
|
16
16
|
to(): State<T>;
|
|
17
|
-
derive<TT>(
|
|
18
|
-
deriveAsync<TT>(
|
|
17
|
+
derive<TT>(transformer: Transformer<T, TT>): State<TT>;
|
|
18
|
+
deriveAsync<TT>(transformer: Transformer<T, PromiseLike<TT>>): State<TT>;
|
|
19
19
|
}
|
|
20
20
|
export declare class State<T> extends Stream<T> {
|
|
21
21
|
static [Symbol.species]: typeof State;
|
|
@@ -33,9 +33,9 @@ export declare class State<T> extends Stream<T> {
|
|
|
33
33
|
/** Is there a current value, or is it still loading. */
|
|
34
34
|
get loading(): boolean;
|
|
35
35
|
/** Apply a deriver to this state. */
|
|
36
|
-
apply(deriver:
|
|
36
|
+
apply(deriver: Transformer<T, T>): void;
|
|
37
37
|
error(reason: Error | unknown): void;
|
|
38
|
-
|
|
38
|
+
_on(observer: Observer<T>): void;
|
|
39
39
|
protected _dispatch(value: T): void;
|
|
40
40
|
}
|
|
41
41
|
/** Create a state with an initial value. */
|
package/stream/State.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { LOADING, NOERROR, dispatchNext, dispatchError, dispatchComplete,
|
|
2
|
+
import { LOADING, NOERROR, dispatchNext, dispatchError, dispatchComplete, transform, getRequired, awaitNext, } from "../util/index.js";
|
|
3
3
|
import { Stream } from "./Stream.js";
|
|
4
4
|
export class State extends Stream {
|
|
5
5
|
constructor() {
|
|
@@ -36,7 +36,7 @@ export class State extends Stream {
|
|
|
36
36
|
}
|
|
37
37
|
/** Apply a deriver to this state. */
|
|
38
38
|
apply(deriver) {
|
|
39
|
-
this.next(
|
|
39
|
+
this.next(transform(this.value, deriver));
|
|
40
40
|
}
|
|
41
41
|
// Override to save the reason at `this.reason` and clean up.
|
|
42
42
|
error(reason) {
|
|
@@ -45,14 +45,14 @@ export class State extends Stream {
|
|
|
45
45
|
super.error(reason);
|
|
46
46
|
}
|
|
47
47
|
// Override to send the current error or value to any new subscribers.
|
|
48
|
-
|
|
49
|
-
super.
|
|
48
|
+
_on(observer) {
|
|
49
|
+
super._on(observer);
|
|
50
50
|
if (this.reason !== NOERROR)
|
|
51
|
-
dispatchError(this.reason
|
|
51
|
+
dispatchError(observer, this.reason);
|
|
52
52
|
else if (this.closed)
|
|
53
53
|
dispatchComplete(observer);
|
|
54
54
|
else if (this._value !== LOADING)
|
|
55
|
-
dispatchNext(this.
|
|
55
|
+
dispatchNext(observer, this._value);
|
|
56
56
|
}
|
|
57
57
|
// Dispatcher saves any values that are dispatched.
|
|
58
58
|
_dispatch(value) {
|
package/stream/Stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transformer, ObserverType, Subscribable, Unsubscriber, Observer, Observable, Constructor, Dispatcher } from "../util/index.js";
|
|
2
2
|
/** Any stream (useful for `extends AnyStream` clauses). */
|
|
3
3
|
export declare type AnyStream = Stream<any>;
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ export declare class Stream<T> implements Observer<T>, Observable<T> {
|
|
|
11
11
|
/** List of sources this stream is subscribed to. */
|
|
12
12
|
protected readonly _cleanups: Set<Unsubscriber>;
|
|
13
13
|
/** List of subscribed observers that values are forwarded to. */
|
|
14
|
-
protected readonly
|
|
14
|
+
protected readonly _observers: Set<Observer<T>>;
|
|
15
15
|
/** Get the number of current subscribers. */
|
|
16
16
|
get subscribers(): number;
|
|
17
17
|
/** Is this stream open or closed (i.e. `error()` or `complete()` have been called. */
|
|
@@ -44,20 +44,20 @@ export declare class Stream<T> implements Observer<T>, Observable<T> {
|
|
|
44
44
|
/** Create a new stream from this stream. */
|
|
45
45
|
to<O extends AnyStream>(target: O): O;
|
|
46
46
|
to(): Stream<T>;
|
|
47
|
-
/** Derive a new stream from this stream using a
|
|
48
|
-
derive<O extends AnyStream>(
|
|
49
|
-
derive<TT>(
|
|
50
|
-
/** Derive a new stream from this stream using an async
|
|
51
|
-
deriveAsync<O extends AnyStream>(
|
|
52
|
-
deriveAsync<TT>(
|
|
47
|
+
/** Derive a new stream from this stream using a transformer. */
|
|
48
|
+
derive<O extends AnyStream>(transformer: Transformer<T, ObserverType<O>>, target: O): O;
|
|
49
|
+
derive<TT>(transformer: Transformer<T, TT>): Stream<T>;
|
|
50
|
+
/** Derive a new stream from this stream using an async transformer. */
|
|
51
|
+
deriveAsync<O extends AnyStream>(transformer: Transformer<T, Promise<ObserverType<O>>>, target: O): O;
|
|
52
|
+
deriveAsync<TT>(transformer: Transformer<T, PromiseLike<TT>>): Stream<T>;
|
|
53
53
|
/**
|
|
54
54
|
* Subscribe to this stream and return an unsubscriber function.
|
|
55
55
|
* - Allows either an `Observer` object or separate `next()`, `error()` and `complete()` functions.
|
|
56
56
|
* - Implements `Observable`
|
|
57
57
|
*/
|
|
58
|
-
subscribe(next: Observer<T> | Dispatcher<T
|
|
59
|
-
/** Add an observer
|
|
60
|
-
|
|
61
|
-
/** Remove an observer
|
|
62
|
-
|
|
58
|
+
subscribe(next: Observer<T> | Dispatcher<[T]>): Unsubscriber;
|
|
59
|
+
/** Add an observer. */
|
|
60
|
+
_on(observer: Observer<T>): void;
|
|
61
|
+
/** Remove an observer. */
|
|
62
|
+
_off(observer: Observer<T>): void;
|
|
63
63
|
}
|
package/stream/Stream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { AsyncObserver,
|
|
2
|
+
import { AsyncObserver, TransformObserver, dispatchNext, dispatchError, dispatchComplete, subscribe, dispatch, } from "../util/index.js";
|
|
3
3
|
import { ConditionError } from "../error/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Simple stream.
|
|
@@ -10,13 +10,13 @@ export class Stream {
|
|
|
10
10
|
/** List of sources this stream is subscribed to. */
|
|
11
11
|
this._cleanups = new Set();
|
|
12
12
|
/** List of subscribed observers that values are forwarded to. */
|
|
13
|
-
this.
|
|
13
|
+
this._observers = new Set();
|
|
14
14
|
/** Is this stream open or closed (i.e. `error()` or `complete()` have been called. */
|
|
15
15
|
this.closed = false;
|
|
16
16
|
}
|
|
17
17
|
/** Get the number of current subscribers. */
|
|
18
18
|
get subscribers() {
|
|
19
|
-
return this.
|
|
19
|
+
return this._observers.size;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Send a next value.
|
|
@@ -29,8 +29,8 @@ export class Stream {
|
|
|
29
29
|
}
|
|
30
30
|
/** Call `next()` on the subscribers. */
|
|
31
31
|
_dispatch(value) {
|
|
32
|
-
for (const
|
|
33
|
-
dispatchNext(
|
|
32
|
+
for (const observer of this._observers)
|
|
33
|
+
dispatchNext(observer, value);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Complete this stream with an error.
|
|
@@ -41,9 +41,9 @@ export class Stream {
|
|
|
41
41
|
if (this.closed)
|
|
42
42
|
throw new ConditionError("Stream is closed");
|
|
43
43
|
this._close();
|
|
44
|
-
for (const subscriber of this.
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
for (const subscriber of this._observers) {
|
|
45
|
+
this._observers.delete(subscriber);
|
|
46
|
+
dispatchError(subscriber, reason);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -55,17 +55,17 @@ export class Stream {
|
|
|
55
55
|
if (this.closed)
|
|
56
56
|
throw new ConditionError("Stream is closed");
|
|
57
57
|
this._close();
|
|
58
|
-
for (const subscriber of this.
|
|
58
|
+
for (const subscriber of this._observers) {
|
|
59
|
+
this._observers.delete(subscriber);
|
|
59
60
|
dispatchComplete(subscriber);
|
|
60
|
-
this.off(subscriber);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
/** Close this stream. */
|
|
64
64
|
_close() {
|
|
65
65
|
this.closed = true;
|
|
66
66
|
for (const cleanup of this._cleanups) {
|
|
67
|
-
dispatch(undefined, cleanup);
|
|
68
67
|
this._cleanups.delete(cleanup);
|
|
68
|
+
dispatch(cleanup);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
/** Start a subscription that gets cleaned up when this subscriber ends. */
|
|
@@ -89,12 +89,12 @@ export class Stream {
|
|
|
89
89
|
target.during(this, target);
|
|
90
90
|
return target;
|
|
91
91
|
}
|
|
92
|
-
derive(
|
|
93
|
-
target.during(this, new
|
|
92
|
+
derive(transformer, target = new this.constructor[Symbol.species]()) {
|
|
93
|
+
target.during(this, new TransformObserver(transformer, target));
|
|
94
94
|
return target;
|
|
95
95
|
}
|
|
96
|
-
deriveAsync(
|
|
97
|
-
target.during(this, new
|
|
96
|
+
deriveAsync(transformer, target = new this.constructor[Symbol.species]()) {
|
|
97
|
+
target.during(this, new TransformObserver(transformer, new AsyncObserver(target)));
|
|
98
98
|
return target;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -102,18 +102,18 @@ export class Stream {
|
|
|
102
102
|
* - Allows either an `Observer` object or separate `next()`, `error()` and `complete()` functions.
|
|
103
103
|
* - Implements `Observable`
|
|
104
104
|
*/
|
|
105
|
-
subscribe(next
|
|
106
|
-
const observer =
|
|
107
|
-
this.
|
|
108
|
-
return this.
|
|
105
|
+
subscribe(next) {
|
|
106
|
+
const observer = typeof next === "function" ? { next } : next;
|
|
107
|
+
this._on(observer);
|
|
108
|
+
return this._off.bind(this, observer);
|
|
109
109
|
}
|
|
110
|
-
/** Add an observer
|
|
111
|
-
|
|
112
|
-
this.
|
|
110
|
+
/** Add an observer. */
|
|
111
|
+
_on(observer) {
|
|
112
|
+
this._observers.add(observer);
|
|
113
113
|
}
|
|
114
|
-
/** Remove an observer
|
|
115
|
-
|
|
116
|
-
this.
|
|
114
|
+
/** Remove an observer. */
|
|
115
|
+
_off(observer) {
|
|
116
|
+
this._observers.delete(observer);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
_a = Symbol.species;
|
|
@@ -4,7 +4,7 @@ import { Transform } from "./Transform.js";
|
|
|
4
4
|
export declare class AddEntriesTransform<T> extends Transform<ImmutableObject<T>> implements Iterable<Entry<T>> {
|
|
5
5
|
readonly props: ImmutableObject<T>;
|
|
6
6
|
constructor(props: ImmutableObject<T>);
|
|
7
|
-
|
|
7
|
+
transform(existing?: unknown): ImmutableObject<T>;
|
|
8
8
|
/** Iterate over the entries. */
|
|
9
9
|
[Symbol.iterator](): Iterator<Entry<T>, void>;
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import { Transform } from "./Transform.js";
|
|
|
4
4
|
export declare class AddItemsTransform<T> extends Transform<ImmutableArray<T>> implements Iterable<T> {
|
|
5
5
|
readonly items: ImmutableArray<T>;
|
|
6
6
|
constructor(...items: ImmutableArray<T>);
|
|
7
|
-
|
|
7
|
+
transform(existing?: unknown): ImmutableArray<T>;
|
|
8
8
|
/** Iterate over the items. */
|
|
9
9
|
[Symbol.iterator](): Iterator<T, void>;
|
|
10
10
|
}
|
|
@@ -14,7 +14,7 @@ export declare type Transforms<T extends Data> = {
|
|
|
14
14
|
export declare class DataTransform<T extends Data> extends Transform<T> implements Iterable<Prop<Transforms<T>>> {
|
|
15
15
|
readonly transforms: Transforms<T>;
|
|
16
16
|
constructor(transforms: Transforms<T>);
|
|
17
|
-
|
|
17
|
+
transform(existing: T): T;
|
|
18
18
|
/** Return a new object with the specified additional transform. */
|
|
19
19
|
prop<K extends Key<T>>(key: K, transform: T[K] | Transform<T[K]>): this;
|
|
20
20
|
/** Return a new object with the specified additional transforms. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformData } from "../util/index.js";
|
|
2
2
|
import { Transform } from "./Transform.js";
|
|
3
3
|
/** Set of transforms that can be appled to an object's properties. */
|
|
4
4
|
export class DataTransform extends Transform {
|
|
@@ -6,8 +6,8 @@ export class DataTransform extends Transform {
|
|
|
6
6
|
super();
|
|
7
7
|
this.transforms = transforms;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
return
|
|
9
|
+
transform(existing) {
|
|
10
|
+
return transformData(existing, this.transforms);
|
|
11
11
|
}
|
|
12
12
|
/** Return a new object with the specified additional transform. */
|
|
13
13
|
prop(key, transform) {
|
|
@@ -4,7 +4,7 @@ import { Transform } from "./Transform.js";
|
|
|
4
4
|
export declare class RemoveEntriesTransform<T> extends Transform<ImmutableObject<T>> implements Iterable<string> {
|
|
5
5
|
readonly props: ImmutableArray<string>;
|
|
6
6
|
constructor(...props: ImmutableArray<string>);
|
|
7
|
-
|
|
7
|
+
transform(existing?: unknown): ImmutableObject<T>;
|
|
8
8
|
/** Iterate over the entry keys. */
|
|
9
9
|
[Symbol.iterator](): Iterator<string, void>;
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import { Transform } from "./Transform.js";
|
|
|
4
4
|
export declare class RemoveItemsTransform<T> extends Transform<ImmutableArray<T>> implements Iterable<T> {
|
|
5
5
|
readonly items: ImmutableArray<T>;
|
|
6
6
|
constructor(...items: ImmutableArray<T>);
|
|
7
|
-
|
|
7
|
+
transform(existing?: ImmutableArray<T> | unknown): ImmutableArray<T>;
|
|
8
8
|
/** Iterate over the items. */
|
|
9
9
|
[Symbol.iterator](): Iterator<T, void>;
|
|
10
10
|
}
|
package/transform/Transform.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transformable } from "../util/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* An object that transforms an existing value value into a new value with its `transform()` method.
|
|
4
4
|
* - Probably has a configuration that accompanies it.
|
|
5
5
|
*/
|
|
6
|
-
export declare abstract class Transform<T> implements
|
|
6
|
+
export declare abstract class Transform<T> implements Transformable<T, T> {
|
|
7
7
|
/** Apply this transform to a value. */
|
|
8
|
-
abstract
|
|
8
|
+
abstract transform(existing?: unknown): T;
|
|
9
9
|
}
|