shelving 1.27.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/Database.d.ts +6 -6
- package/db/Database.js +7 -8
- package/db/Write.d.ts +1 -1
- package/db/Write.js +2 -2
- package/package.json +1 -1
- package/stream/DataState.d.ts +17 -2
- package/stream/DataState.js +35 -4
- package/stream/State.d.ts +0 -2
- package/stream/State.js +1 -9
- package/util/data.d.ts +0 -3
- package/util/data.js +0 -5
- package/util/null.d.ts +11 -0
- package/util/null.js +10 -0
- package/util/url.d.ts +8 -9
- package/util/url.js +16 -15
package/db/Database.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType, Dispatcher } from "../util/index.js";
|
|
1
|
+
import { Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType, Dispatcher, Nullish } from "../util/index.js";
|
|
2
2
|
import { PropUpdates, Update } from "../update/index.js";
|
|
3
3
|
import type { Provider } from "../provider/Provider.js";
|
|
4
4
|
import { Filters, Sorts, Query } from "../query/index.js";
|
|
5
|
-
import { DocumentDelete, DocumentSet, DocumentUpdate, Write
|
|
5
|
+
import { DocumentDelete, DocumentSet, DocumentUpdate, Write } from "./Write.js";
|
|
6
6
|
/**
|
|
7
7
|
* Combines a database model and a provider.
|
|
8
8
|
*
|
|
@@ -18,10 +18,10 @@ export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
|
|
|
18
18
|
query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DataQuery<ValidatorType<V[K]>>;
|
|
19
19
|
/** Reference a document in a collection in this model. */
|
|
20
20
|
doc<K extends Key<V>>(collection: K, id: string): DataDocument<ValidatorType<V[K]>>;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/** Perform
|
|
24
|
-
|
|
21
|
+
/** Create a writer for this database from a set of separate writes. */
|
|
22
|
+
writer(...writes: Nullish<Write>[]): Write;
|
|
23
|
+
/** Perform one or more writes on this database and return the `Writes` instance representing the combined changes. */
|
|
24
|
+
write(...writes: Nullish<Write>[]): Promise<Write>;
|
|
25
25
|
}
|
|
26
26
|
/** A documents reference within a specific database. */
|
|
27
27
|
export declare class DataQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Results<T>>, Iterable<Entry<T>> {
|
package/db/Database.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callAsync, getFirstItem, throwAsync, validate, toMap, countItems, TransformObserver, } from "../util/index.js";
|
|
1
|
+
import { callAsync, getFirstItem, throwAsync, validate, toMap, countItems, TransformObserver, NOT_NULLISH, } from "../util/index.js";
|
|
2
2
|
import { DataUpdate, Update } from "../update/index.js";
|
|
3
3
|
import { Feedback, InvalidFeedback } from "../feedback/index.js";
|
|
4
4
|
import { Filters, Query, EqualFilter } from "../query/index.js";
|
|
@@ -25,14 +25,13 @@ export class Database {
|
|
|
25
25
|
doc(collection, id) {
|
|
26
26
|
return new DataDocument(this.provider, this.validators[collection], collection, id);
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return write;
|
|
28
|
+
/** Create a writer for this database from a set of separate writes. */
|
|
29
|
+
writer(...writes) {
|
|
30
|
+
return new Writes(...writes.filter(NOT_NULLISH));
|
|
32
31
|
}
|
|
33
|
-
/** Perform
|
|
34
|
-
async
|
|
35
|
-
const write = new Writes(...writes);
|
|
32
|
+
/** Perform one or more writes on this database and return the `Writes` instance representing the combined changes. */
|
|
33
|
+
async write(...writes) {
|
|
34
|
+
const write = new Writes(...writes.filter(NOT_NULLISH));
|
|
36
35
|
await write.transform(this);
|
|
37
36
|
return write;
|
|
38
37
|
}
|
package/db/Write.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare abstract class Write implements Transformable<Database, void | Pr
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class Writes extends Write {
|
|
14
14
|
readonly writes: ImmutableArray<Write>;
|
|
15
|
-
constructor(...writes:
|
|
15
|
+
constructor(...writes: Write[]);
|
|
16
16
|
transform(db: Database): Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
/** Represent a write made to a single document in a database. */
|
package/db/Write.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataUpdate, Update } from "../update/index.js";
|
|
2
|
-
import { transform
|
|
2
|
+
import { transform } from "../util/index.js";
|
|
3
3
|
/** Represent a write made to a database. */
|
|
4
4
|
export class Write {
|
|
5
5
|
}
|
|
@@ -11,7 +11,7 @@ export class Write {
|
|
|
11
11
|
export class Writes extends Write {
|
|
12
12
|
constructor(...writes) {
|
|
13
13
|
super();
|
|
14
|
-
this.writes = writes
|
|
14
|
+
this.writes = writes;
|
|
15
15
|
}
|
|
16
16
|
async transform(db) {
|
|
17
17
|
for (const writes of this.writes)
|
package/package.json
CHANGED
package/stream/DataState.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import { Key, Data, PropTransformers } from "../util/index.js";
|
|
1
|
+
import { Key, Data, PropTransformers, Result } from "../util/index.js";
|
|
2
2
|
import { State } from "./State.js";
|
|
3
|
-
/** State that stores
|
|
3
|
+
/** State that stores a data object and has additional methods to help with that. */
|
|
4
4
|
export declare class DataState<T extends Data> extends State<T> {
|
|
5
|
+
/** Get the data value of this state. */
|
|
6
|
+
get data(): T;
|
|
5
7
|
/** Set a prop in this object to a new value. */
|
|
6
8
|
set<K extends Key<T>>(key: K, value: T[K]): void;
|
|
7
9
|
/** Update several props in this object. */
|
|
8
10
|
update(updates: PropTransformers<T>): void;
|
|
9
11
|
}
|
|
12
|
+
/** State that stores an optional data object and has additional methods to help with that. */
|
|
13
|
+
export declare class ResultState<T extends Data> extends State<Result<T>> {
|
|
14
|
+
/** Get the result value of this state. */
|
|
15
|
+
get result(): Result<T>;
|
|
16
|
+
/** Get current data value of this state (or throw `Promise` that resolves to the next required value). */
|
|
17
|
+
get data(): T;
|
|
18
|
+
/** Set a prop in this object to a new value. */
|
|
19
|
+
set<K extends Key<T>>(key: K, value: T[K]): void;
|
|
20
|
+
/** Update several props in this object. */
|
|
21
|
+
update(updates: PropTransformers<T>): void;
|
|
22
|
+
/** Delete this result. */
|
|
23
|
+
delete(): void;
|
|
24
|
+
}
|
package/stream/DataState.js
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
|
-
import { withProp, transformData } from "../util/index.js";
|
|
1
|
+
import { withProp, transformData, NOERROR, LOADING, awaitNext, getData } from "../util/index.js";
|
|
2
2
|
import { State } from "./State.js";
|
|
3
|
-
/** State that stores
|
|
3
|
+
/** State that stores a data object and has additional methods to help with that. */
|
|
4
4
|
export class DataState extends State {
|
|
5
|
+
/** Get the data value of this state. */
|
|
6
|
+
get data() {
|
|
7
|
+
return this.value;
|
|
8
|
+
}
|
|
5
9
|
/** Set a prop in this object to a new value. */
|
|
6
10
|
set(key, value) {
|
|
7
|
-
this.next(withProp(this.
|
|
11
|
+
this.next(withProp(this.data, key, value));
|
|
8
12
|
}
|
|
9
13
|
/** Update several props in this object. */
|
|
10
14
|
update(updates) {
|
|
11
|
-
this.next(transformData(this.
|
|
15
|
+
this.next(transformData(this.data, updates));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** State that stores an optional data object and has additional methods to help with that. */
|
|
19
|
+
export class ResultState extends State {
|
|
20
|
+
/** Get the result value of this state. */
|
|
21
|
+
get result() {
|
|
22
|
+
return this.value;
|
|
23
|
+
}
|
|
24
|
+
/** Get current data value of this state (or throw `Promise` that resolves to the next required value). */
|
|
25
|
+
get data() {
|
|
26
|
+
if (this.reason !== NOERROR)
|
|
27
|
+
throw this.reason;
|
|
28
|
+
if (this._value === LOADING)
|
|
29
|
+
throw awaitNext(this).then(getData);
|
|
30
|
+
return getData(this._value);
|
|
31
|
+
}
|
|
32
|
+
/** Set a prop in this object to a new value. */
|
|
33
|
+
set(key, value) {
|
|
34
|
+
this.next(withProp(this.data, key, value));
|
|
35
|
+
}
|
|
36
|
+
/** Update several props in this object. */
|
|
37
|
+
update(updates) {
|
|
38
|
+
this.next(transformData(this.data, updates));
|
|
39
|
+
}
|
|
40
|
+
/** Delete this result. */
|
|
41
|
+
delete() {
|
|
42
|
+
this.next(undefined);
|
|
12
43
|
}
|
|
13
44
|
}
|
package/stream/State.d.ts
CHANGED
|
@@ -28,8 +28,6 @@ export declare class State<T> extends Stream<T> {
|
|
|
28
28
|
/** Most recently dispatched value (or throw `Promise` that resolves to the next value). */
|
|
29
29
|
get value(): T;
|
|
30
30
|
protected _value: T | typeof LOADING;
|
|
31
|
-
/** Get current required value (or throw `Promise` that resolves to the next required value). */
|
|
32
|
-
get data(): Exclude<T, null | undefined>;
|
|
33
31
|
/** Is there a current value, or is it still loading. */
|
|
34
32
|
get loading(): boolean;
|
|
35
33
|
/** Apply a transformer to this state. */
|
package/stream/State.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { LOADING, NOERROR, dispatchNext, dispatchError, dispatchComplete, transform,
|
|
2
|
+
import { LOADING, NOERROR, dispatchNext, dispatchError, dispatchComplete, transform, awaitNext, } from "../util/index.js";
|
|
3
3
|
import { Stream } from "./Stream.js";
|
|
4
4
|
export class State extends Stream {
|
|
5
5
|
constructor() {
|
|
@@ -22,14 +22,6 @@ export class State extends Stream {
|
|
|
22
22
|
throw awaitNext(this);
|
|
23
23
|
return this._value;
|
|
24
24
|
}
|
|
25
|
-
/** Get current required value (or throw `Promise` that resolves to the next required value). */
|
|
26
|
-
get data() {
|
|
27
|
-
if (this.reason !== NOERROR)
|
|
28
|
-
throw this.reason;
|
|
29
|
-
if (this._value === LOADING)
|
|
30
|
-
throw awaitNext(this).then(getRequired);
|
|
31
|
-
return getRequired(this._value);
|
|
32
|
-
}
|
|
33
25
|
/** Is there a current value, or is it still loading. */
|
|
34
26
|
get loading() {
|
|
35
27
|
return this._value === LOADING;
|
package/util/data.d.ts
CHANGED
|
@@ -25,9 +25,6 @@ export declare const isData: <T extends Data>(value: unknown) => value is T;
|
|
|
25
25
|
/** Turn a data object into an array of entries (if it isn't one already). */
|
|
26
26
|
export declare function toProps<T extends Data>(input: T): ImmutableArray<Prop<T>>;
|
|
27
27
|
export declare function toProps<T extends Data>(input: Partial<T>): ImmutableArray<Prop<T>>;
|
|
28
|
-
/** Get a required value (returns value or throws `RequiredError` if value is `null` or `undefined`). */
|
|
29
|
-
export declare function getRequired<T>(v: T): Exclude<T, null | undefined>;
|
|
30
|
-
export declare function getRequired<T>(v: T | null | undefined): T;
|
|
31
28
|
/** Get the data of a result (returns data or throws `RequiredError` if value is `null` or `undefined`). */
|
|
32
29
|
export declare function getData<T extends Data>(result: Result<T>): T;
|
|
33
30
|
/**
|
package/util/data.js
CHANGED
|
@@ -4,11 +4,6 @@ export const isData = (value) => typeof value === "object" && value !== null;
|
|
|
4
4
|
export function toProps(input) {
|
|
5
5
|
return Object.entries(input);
|
|
6
6
|
}
|
|
7
|
-
export function getRequired(v) {
|
|
8
|
-
if (v === undefined || v === null)
|
|
9
|
-
throw new RequiredError(v === null ? "Required value is null" : "Required value is undefined");
|
|
10
|
-
return v;
|
|
11
|
-
}
|
|
12
7
|
/** Get the data of a result (returns data or throws `RequiredError` if value is `null` or `undefined`). */
|
|
13
8
|
export function getData(result) {
|
|
14
9
|
if (!result)
|
package/util/null.d.ts
CHANGED
|
@@ -4,3 +4,14 @@ export declare const IS_NULL: (v: unknown) => v is null;
|
|
|
4
4
|
export declare const NOT_NULL: <T>(v: T | null) => v is T;
|
|
5
5
|
/** Function that always returns null. */
|
|
6
6
|
export declare const NULL: () => null;
|
|
7
|
+
/** Nullish is `null` or `undefined` */
|
|
8
|
+
export declare type Nullish<T> = T | null | undefined;
|
|
9
|
+
/** Nullish is `null` or `undefined` */
|
|
10
|
+
export declare type NotNullish<T> = Exclude<T, null | undefined>;
|
|
11
|
+
/** Is a value nullish? */
|
|
12
|
+
export declare const IS_NULLISH: <T>(v: Nullish<T>) => v is null | undefined;
|
|
13
|
+
/** Is a value nullish? */
|
|
14
|
+
export declare const NOT_NULLISH: <T>(v: Nullish<T>) => v is T;
|
|
15
|
+
/** Get a required value (returns value or throws `RequiredError` if value is `null` or `undefined`). */
|
|
16
|
+
export declare function getRequired<T>(v: T): NotNullish<T>;
|
|
17
|
+
export declare function getRequired<T>(v: Nullish<T>): T;
|
package/util/null.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import { RequiredError } from "../error/index.js";
|
|
1
2
|
/** Is a value null? */
|
|
2
3
|
export const IS_NULL = (v) => v === null;
|
|
3
4
|
/** Is a value not null? */
|
|
4
5
|
export const NOT_NULL = (v) => v !== null;
|
|
5
6
|
/** Function that always returns null. */
|
|
6
7
|
export const NULL = () => null;
|
|
8
|
+
/** Is a value nullish? */
|
|
9
|
+
export const IS_NULLISH = (v) => v === null || v === undefined;
|
|
10
|
+
/** Is a value nullish? */
|
|
11
|
+
export const NOT_NULLISH = (v) => v !== null && v !== undefined;
|
|
12
|
+
export function getRequired(v) {
|
|
13
|
+
if (v === undefined || v === null)
|
|
14
|
+
throw new RequiredError("Required value is missing");
|
|
15
|
+
return v;
|
|
16
|
+
}
|
package/util/url.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
/** Things that can be converted to a URL instance. */
|
|
2
|
+
export declare type PossibleURL = string | URL;
|
|
3
|
+
export declare type PossibleOptionalURL = PossibleURL | null;
|
|
4
|
+
/** Convert a possible URL to a URL or return `null` if conversion fails. */
|
|
5
|
+
export declare function toURL(url: PossibleURL, base?: PossibleOptionalURL): URL | null;
|
|
6
|
+
/** Convert a possible URL to a URL but throw `AssertionError` if conversion fails. */
|
|
7
|
+
export declare function getURL(input: PossibleURL, base?: PossibleOptionalURL): URL;
|
|
1
8
|
/** Just get important part of a URL, e.g. `http://shax.com/test?uid=129483` → `shax.com/test` */
|
|
2
|
-
export declare const formatUrl: (url:
|
|
3
|
-
/**
|
|
4
|
-
* Convert a string to a URL instance or return `null` if we can't.
|
|
5
|
-
* - Automatically prepend `https://` if there's no `:` anywhere.
|
|
6
|
-
*
|
|
7
|
-
* @param url Base
|
|
8
|
-
* @param
|
|
9
|
-
*/
|
|
10
|
-
export declare function toURL(url: string | URL, base?: URL | string | undefined): URL | null;
|
|
9
|
+
export declare const formatUrl: (url: PossibleURL) => string;
|
package/util/url.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
4
|
-
const { host, pathname } = getRequired(toURL(url));
|
|
5
|
-
return `${host}${pathname.length > 1 ? pathname : ""}`;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Convert a string to a URL instance or return `null` if we can't.
|
|
9
|
-
* - Automatically prepend `https://` if there's no `:` anywhere.
|
|
10
|
-
*
|
|
11
|
-
* @param url Base
|
|
12
|
-
* @param
|
|
13
|
-
*/
|
|
14
|
-
export function toURL(url, base = typeof window === "object" ? window.location.href : undefined) {
|
|
1
|
+
import { AssertionError } from "../error/index.js";
|
|
2
|
+
/** Convert a possible URL to a URL or return `null` if conversion fails. */
|
|
3
|
+
export function toURL(url, base = typeof window === "object" ? window.location.href : null) {
|
|
15
4
|
if (url instanceof URL)
|
|
16
5
|
return url;
|
|
17
6
|
if (!url)
|
|
18
7
|
return null;
|
|
19
8
|
try {
|
|
20
|
-
return new URL(url, base);
|
|
9
|
+
return new URL(url, base || undefined);
|
|
21
10
|
}
|
|
22
11
|
catch (e) {
|
|
23
12
|
return null;
|
|
24
13
|
}
|
|
25
14
|
}
|
|
15
|
+
/** Convert a possible URL to a URL but throw `AssertionError` if conversion fails. */
|
|
16
|
+
export function getURL(input, base) {
|
|
17
|
+
const url = toURL(input, base);
|
|
18
|
+
if (!url)
|
|
19
|
+
throw new AssertionError("Invalid URL", input);
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
/** Just get important part of a URL, e.g. `http://shax.com/test?uid=129483` → `shax.com/test` */
|
|
23
|
+
export const formatUrl = (url) => {
|
|
24
|
+
const { host, pathname } = getURL(url);
|
|
25
|
+
return `${host}${pathname.length > 1 ? pathname : ""}`;
|
|
26
|
+
};
|