shelving 1.41.0 → 1.42.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/Operation.d.ts +73 -0
- package/db/Operation.js +116 -0
- package/db/index.d.ts +1 -0
- package/db/index.js +1 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +1 -1
- package/operation/AddOperation.d.ts +0 -15
- package/operation/AddOperation.js +0 -23
- package/operation/DeleteOperation.d.ts +0 -9
- package/operation/DeleteOperation.js +0 -13
- package/operation/Operation.d.ts +0 -6
- package/operation/Operation.js +0 -3
- package/operation/Operations.d.ts +0 -21
- package/operation/Operations.js +0 -33
- package/operation/SetOperation.d.ts +0 -15
- package/operation/SetOperation.js +0 -23
- package/operation/UpdateOperation.d.ts +0 -16
- package/operation/UpdateOperation.js +0 -23
- package/operation/WriteOperation.d.ts +0 -16
- package/operation/WriteOperation.js +0 -25
- package/operation/hydrations.d.ts +0 -13
- package/operation/hydrations.js +0 -14
- package/operation/index.d.ts +0 -8
- package/operation/index.js +0 -8
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PropUpdates, Update } from "../update/index.js";
|
|
2
|
+
import { ImmutableArray, Nullish, Data, Key } from "../util/index.js";
|
|
3
|
+
import type { Database, DatabaseDocument, DatabaseQuery } from "./Database.js";
|
|
4
|
+
/** Represent a write operation on a database. */
|
|
5
|
+
export declare abstract class Operation {
|
|
6
|
+
abstract run(db: Database): Promise<Operation>;
|
|
7
|
+
}
|
|
8
|
+
/** Represent a list of write operations on a database run in series. */
|
|
9
|
+
export declare class Operations extends Operation {
|
|
10
|
+
/** Return a new write operations list with a set of write operations. */
|
|
11
|
+
static with(...operations: Nullish<Operation>[]): Operations;
|
|
12
|
+
readonly operations: ImmutableArray<Operation>;
|
|
13
|
+
constructor(operations: ImmutableArray<Nullish<Operation>>);
|
|
14
|
+
run(db: Database): Promise<Operations>;
|
|
15
|
+
/** Return a new write operations list with an additional write operation added. */
|
|
16
|
+
with(...operations: Nullish<Operation>[]): {
|
|
17
|
+
__proto__: any;
|
|
18
|
+
} & this & {
|
|
19
|
+
operations: (Operation | Nullish<Operation>[])[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Represent a add operation made to a collection in a database. */
|
|
23
|
+
export declare class AddOperation<T extends Data> extends Operation {
|
|
24
|
+
/** Create a new add operation on a collection. */
|
|
25
|
+
static on<X extends Data>({ collection }: DatabaseDocument | DatabaseQuery, data: X): AddOperation<X>;
|
|
26
|
+
readonly collection: string;
|
|
27
|
+
readonly data: T;
|
|
28
|
+
constructor(collection: string, data: T);
|
|
29
|
+
run(db: Database): Promise<SetOperation<T>>;
|
|
30
|
+
/** Set one of the props on this set operation to a different value. */
|
|
31
|
+
with<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
|
|
32
|
+
}
|
|
33
|
+
/** Represent a set operation made to a single document in a database. */
|
|
34
|
+
export declare class SetOperation<T extends Data> extends Operation {
|
|
35
|
+
/** Create a new add operation on a collection. */
|
|
36
|
+
static on<X extends Data>({ collection, id }: DatabaseDocument, data: X): SetOperation<X>;
|
|
37
|
+
readonly collection: string;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly data: T;
|
|
40
|
+
constructor(collection: string, id: string, data: T);
|
|
41
|
+
run(db: Database): Promise<this>;
|
|
42
|
+
/** Set one of the props on this set operation to a different value. */
|
|
43
|
+
with<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
|
|
44
|
+
}
|
|
45
|
+
/** Represent an update operation made to a single document in a database. */
|
|
46
|
+
export declare class UpdateOperation<T extends Data> extends Operation {
|
|
47
|
+
/** Create a new update operation on a document. */
|
|
48
|
+
static on<X extends Data>({ collection, id }: DatabaseDocument<X>, updates?: PropUpdates<X>): UpdateOperation<X>;
|
|
49
|
+
readonly collection: string;
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly updates: PropUpdates<T>;
|
|
52
|
+
constructor(collection: string, id: string, updates: PropUpdates<T>);
|
|
53
|
+
run(db: Database): Promise<this>;
|
|
54
|
+
/** update one of the props on this set operation to a different value. */
|
|
55
|
+
with<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
56
|
+
}
|
|
57
|
+
/** Represent a delete operation made to a single document in a database. */
|
|
58
|
+
export declare class DeleteOperation extends Operation {
|
|
59
|
+
/** Create a new update operation on a document. */
|
|
60
|
+
static on({ collection, id }: DatabaseDocument): DeleteOperation;
|
|
61
|
+
readonly collection: string;
|
|
62
|
+
readonly id: string;
|
|
63
|
+
constructor(collection: string, id: string);
|
|
64
|
+
run(db: Database): Promise<this>;
|
|
65
|
+
}
|
|
66
|
+
/** Set of hydrations for all change classes. */
|
|
67
|
+
export declare const OPERATION_HYDRATIONS: {
|
|
68
|
+
Operations: typeof Operations;
|
|
69
|
+
AddOperation: typeof AddOperation;
|
|
70
|
+
SetOperation: typeof SetOperation;
|
|
71
|
+
UpdateOperation: typeof UpdateOperation;
|
|
72
|
+
DeleteOperation: typeof DeleteOperation;
|
|
73
|
+
};
|
package/db/Operation.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { callAsyncSeries, isNotNullish, isNullish } from "../util/index.js";
|
|
2
|
+
/** Represent a write operation on a database. */
|
|
3
|
+
export class Operation {
|
|
4
|
+
}
|
|
5
|
+
/** Represent a list of write operations on a database run in series. */
|
|
6
|
+
export class Operations extends Operation {
|
|
7
|
+
constructor(operations) {
|
|
8
|
+
super();
|
|
9
|
+
this.operations = operations.filter(isNotNullish);
|
|
10
|
+
}
|
|
11
|
+
/** Return a new write operations list with a set of write operations. */
|
|
12
|
+
static with(...operations) {
|
|
13
|
+
return new Operations(operations);
|
|
14
|
+
}
|
|
15
|
+
async run(db) {
|
|
16
|
+
return new Operations(await callAsyncSeries(_write, this.operations, db));
|
|
17
|
+
}
|
|
18
|
+
/** Return a new write operations list with an additional write operation added. */
|
|
19
|
+
with(...operations) {
|
|
20
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, operations: [...this.operations, operations] };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const _write = (operation, db) => operation.run(db);
|
|
24
|
+
/** Represent a add operation made to a collection in a database. */
|
|
25
|
+
export class AddOperation extends Operation {
|
|
26
|
+
constructor(collection, data) {
|
|
27
|
+
super();
|
|
28
|
+
this.collection = collection;
|
|
29
|
+
this.data = data;
|
|
30
|
+
}
|
|
31
|
+
/** Create a new add operation on a collection. */
|
|
32
|
+
static on({ collection }, data) {
|
|
33
|
+
return new AddOperation(collection, data);
|
|
34
|
+
}
|
|
35
|
+
async run(db) {
|
|
36
|
+
const id = await db.query(this.collection).add(this.data);
|
|
37
|
+
return new SetOperation(this.collection, id, this.data); // When an add operation is run it returns a set operation so the operation is repeatable.
|
|
38
|
+
}
|
|
39
|
+
/** Set one of the props on this set operation to a different value. */
|
|
40
|
+
with(key, value) {
|
|
41
|
+
if (isNullish(key))
|
|
42
|
+
return this;
|
|
43
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Represent a set operation made to a single document in a database. */
|
|
47
|
+
export class SetOperation extends Operation {
|
|
48
|
+
constructor(collection, id, data) {
|
|
49
|
+
super();
|
|
50
|
+
this.collection = collection;
|
|
51
|
+
this.id = id;
|
|
52
|
+
this.data = data;
|
|
53
|
+
}
|
|
54
|
+
/** Create a new add operation on a collection. */
|
|
55
|
+
static on({ collection, id }, data) {
|
|
56
|
+
return new SetOperation(collection, id, data);
|
|
57
|
+
}
|
|
58
|
+
async run(db) {
|
|
59
|
+
await db.doc(this.collection, this.id).set(this.data);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/** Set one of the props on this set operation to a different value. */
|
|
63
|
+
with(key, value) {
|
|
64
|
+
if (isNullish(key))
|
|
65
|
+
return this;
|
|
66
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Represent an update operation made to a single document in a database. */
|
|
70
|
+
export class UpdateOperation extends Operation {
|
|
71
|
+
constructor(collection, id, updates) {
|
|
72
|
+
super();
|
|
73
|
+
this.collection = collection;
|
|
74
|
+
this.id = id;
|
|
75
|
+
this.updates = updates;
|
|
76
|
+
}
|
|
77
|
+
/** Create a new update operation on a document. */
|
|
78
|
+
static on({ collection, id }, updates = {}) {
|
|
79
|
+
return new UpdateOperation(collection, id, updates);
|
|
80
|
+
}
|
|
81
|
+
async run(db) {
|
|
82
|
+
await db.doc(this.collection, this.id).update(this.updates);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/** update one of the props on this set operation to a different value. */
|
|
86
|
+
with(key, value) {
|
|
87
|
+
if (isNullish(key))
|
|
88
|
+
return this;
|
|
89
|
+
return { __proto__: Object.getPrototypeOf(this), ...this, updates: { ...this.updates, [key]: value } };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Represent a delete operation made to a single document in a database. */
|
|
93
|
+
export class DeleteOperation extends Operation {
|
|
94
|
+
constructor(collection, id) {
|
|
95
|
+
super();
|
|
96
|
+
this.collection = collection;
|
|
97
|
+
this.id = id;
|
|
98
|
+
}
|
|
99
|
+
/** Create a new update operation on a document. */
|
|
100
|
+
static on({ collection, id }) {
|
|
101
|
+
return new DeleteOperation(collection, id);
|
|
102
|
+
}
|
|
103
|
+
async run(db) {
|
|
104
|
+
await db.doc(this.collection, this.id).delete();
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Set of hydrations for all change classes. */
|
|
109
|
+
export const OPERATION_HYDRATIONS = {
|
|
110
|
+
Operations: Operations,
|
|
111
|
+
AddOperation,
|
|
112
|
+
SetOperation,
|
|
113
|
+
UpdateOperation,
|
|
114
|
+
DeleteOperation,
|
|
115
|
+
};
|
|
116
|
+
OPERATION_HYDRATIONS;
|
package/db/index.d.ts
CHANGED
package/db/index.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -15,7 +15,6 @@ export * from "./feedback/index.js";
|
|
|
15
15
|
export * from "./markup/index.js";
|
|
16
16
|
export * from "./stream/index.js";
|
|
17
17
|
export * from "./update/index.js";
|
|
18
|
-
export * from "./operation/index.js";
|
|
19
18
|
export * from "./util/index.js";
|
|
20
19
|
// Integrations.
|
|
21
20
|
// export * from "./react/index.js"; // Not exported.
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Database, DatabaseQuery } from "../db/index.js";
|
|
2
|
-
import { Data, Nullish, Key } from "../util/index.js";
|
|
3
|
-
import { SetOperation } from "./SetOperation.js";
|
|
4
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
5
|
-
/** Represent a add operation made to a collection in a database. */
|
|
6
|
-
export declare class AddOperation<T extends Data> extends WriteOperation {
|
|
7
|
-
readonly collection: string;
|
|
8
|
-
readonly data: T;
|
|
9
|
-
constructor(collection: string, data: T);
|
|
10
|
-
run(db: Database): Promise<SetOperation<T>>;
|
|
11
|
-
/** Set one of the props on this set operation to a different value. */
|
|
12
|
-
with<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
|
|
13
|
-
}
|
|
14
|
-
/** Create an add operation for a document. */
|
|
15
|
-
export declare const ADD: <T extends Data>({ collection }: DatabaseQuery<T>, data: T) => AddOperation<T>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isNullish } from "../util/index.js";
|
|
2
|
-
import { SetOperation } from "./SetOperation.js";
|
|
3
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
4
|
-
/** Represent a add operation made to a collection in a database. */
|
|
5
|
-
export class AddOperation extends WriteOperation {
|
|
6
|
-
constructor(collection, data) {
|
|
7
|
-
super();
|
|
8
|
-
this.collection = collection;
|
|
9
|
-
this.data = data;
|
|
10
|
-
}
|
|
11
|
-
async run(db) {
|
|
12
|
-
const id = await db.query(this.collection).add(this.data);
|
|
13
|
-
return new SetOperation(this.collection, id, this.data); // When an add operation is run it returns a set operation so the operation is repeatable.
|
|
14
|
-
}
|
|
15
|
-
/** Set one of the props on this set operation to a different value. */
|
|
16
|
-
with(key, value) {
|
|
17
|
-
if (isNullish(key))
|
|
18
|
-
return this;
|
|
19
|
-
return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Create an add operation for a document. */
|
|
23
|
-
export const ADD = ({ collection }, data) => new AddOperation(collection, data);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Database } from "../db/Database.js";
|
|
2
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
3
|
-
/** Represent a delete operation made to a single document in a database. */
|
|
4
|
-
export declare class DeleteOperation extends WriteOperation {
|
|
5
|
-
readonly collection: string;
|
|
6
|
-
readonly id: string;
|
|
7
|
-
constructor(collection: string, id: string);
|
|
8
|
-
run(db: Database): Promise<this>;
|
|
9
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
2
|
-
/** Represent a delete operation made to a single document in a database. */
|
|
3
|
-
export class DeleteOperation extends WriteOperation {
|
|
4
|
-
constructor(collection, id) {
|
|
5
|
-
super();
|
|
6
|
-
this.collection = collection;
|
|
7
|
-
this.id = id;
|
|
8
|
-
}
|
|
9
|
-
async run(db) {
|
|
10
|
-
await db.doc(this.collection, this.id).delete();
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
}
|
package/operation/Operation.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Arguments } from "../index.js";
|
|
2
|
-
/** Represent an async operation. */
|
|
3
|
-
export declare abstract class Operation<A extends Arguments = []> {
|
|
4
|
-
/** Run this operation against a database and return the operation that was completed (which may be this same `Operation` instance). */
|
|
5
|
-
abstract run(...args: A): Promise<Operation<A>>;
|
|
6
|
-
}
|
package/operation/Operation.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ImmutableArray, Nullish, Arguments } from "../util/index.js";
|
|
2
|
-
import { Operation } from "./Operation.js";
|
|
3
|
-
/** Represent a list of operations that take the same arguments. */
|
|
4
|
-
export declare abstract class Operations<A extends Arguments> extends Operation<A> {
|
|
5
|
-
readonly operations: ImmutableArray<Operation<A>>;
|
|
6
|
-
constructor(...operations: Nullish<Operation<A>>[]);
|
|
7
|
-
/** Return a new instance of this object with an additional operation added. */
|
|
8
|
-
with(operation: Nullish<Operation<A>>): this;
|
|
9
|
-
}
|
|
10
|
-
/** Represent a list of operations run in series. */
|
|
11
|
-
export declare class SeriesOperations<A extends Arguments> extends Operations<A> {
|
|
12
|
-
run(...args: A): Promise<SeriesOperations<A>>;
|
|
13
|
-
}
|
|
14
|
-
/** Create a list of operations to be run. */
|
|
15
|
-
export declare const SERIES: <A extends Arguments>(...operations: Operation<A>[]) => SeriesOperations<A>;
|
|
16
|
-
/** Represent a list of operations run in series. */
|
|
17
|
-
export declare class ParallelOperations<A extends Arguments> extends Operations<A> {
|
|
18
|
-
run(...args: A): Promise<ParallelOperations<A>>;
|
|
19
|
-
}
|
|
20
|
-
/** Create a list of operations to be run. */
|
|
21
|
-
export declare const PARALLEL: <A extends Arguments>(...operations: Operation<A>[]) => ParallelOperations<A>;
|
package/operation/Operations.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { callAsyncSeries, callAsyncParallel, isNullish, isNotNullish } from "../util/index.js";
|
|
2
|
-
import { Operation } from "./Operation.js";
|
|
3
|
-
// Run an operation on to a database.
|
|
4
|
-
const _runOperation = (operation, ...args) => operation.run(...args);
|
|
5
|
-
/** Represent a list of operations that take the same arguments. */
|
|
6
|
-
export class Operations extends Operation {
|
|
7
|
-
constructor(...operations) {
|
|
8
|
-
super();
|
|
9
|
-
this.operations = operations.filter(isNotNullish);
|
|
10
|
-
}
|
|
11
|
-
/** Return a new instance of this object with an additional operation added. */
|
|
12
|
-
with(operation) {
|
|
13
|
-
if (isNullish(operation))
|
|
14
|
-
return this;
|
|
15
|
-
return { __proto__: Object.getPrototypeOf(this), ...this, operations: [...this.operations, operation] };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/** Represent a list of operations run in series. */
|
|
19
|
-
export class SeriesOperations extends Operations {
|
|
20
|
-
async run(...args) {
|
|
21
|
-
return new SeriesOperations(...(await callAsyncSeries(_runOperation, this.operations, ...args)));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** Create a list of operations to be run. */
|
|
25
|
-
export const SERIES = (...operations) => new SeriesOperations(...operations);
|
|
26
|
-
/** Represent a list of operations run in series. */
|
|
27
|
-
export class ParallelOperations extends Operations {
|
|
28
|
-
async run(...args) {
|
|
29
|
-
return new ParallelOperations(...(await callAsyncParallel(_runOperation, this.operations, ...args)));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Create a list of operations to be run. */
|
|
33
|
-
export const PARALLEL = (...operations) => new ParallelOperations(...operations);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Database, DatabaseDocument } from "../db/index.js";
|
|
2
|
-
import { Data, Key, Nullish } from "../util/index.js";
|
|
3
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
4
|
-
/** Represent a set operation made to a single document in a database. */
|
|
5
|
-
export declare class SetOperation<T extends Data> extends WriteOperation {
|
|
6
|
-
readonly collection: string;
|
|
7
|
-
readonly id: string;
|
|
8
|
-
readonly data: T;
|
|
9
|
-
constructor(collection: string, id: string, data: T);
|
|
10
|
-
run(db: Database): Promise<this>;
|
|
11
|
-
/** Set one of the props on this set operation to a different value. */
|
|
12
|
-
with<K extends Key<T>>(key: Nullish<K>, value: T[K]): this;
|
|
13
|
-
}
|
|
14
|
-
/** Create a set operation for a document. */
|
|
15
|
-
export declare const SET: <T extends Data>({ collection, id }: DatabaseDocument<T>, data: T) => SetOperation<T>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isNullish } from "../util/index.js";
|
|
2
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
3
|
-
/** Represent a set operation made to a single document in a database. */
|
|
4
|
-
export class SetOperation extends WriteOperation {
|
|
5
|
-
constructor(collection, id, data) {
|
|
6
|
-
super();
|
|
7
|
-
this.collection = collection;
|
|
8
|
-
this.id = id;
|
|
9
|
-
this.data = data;
|
|
10
|
-
}
|
|
11
|
-
async run(db) {
|
|
12
|
-
await db.doc(this.collection, this.id).set(this.data);
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
/** Set one of the props on this set operation to a different value. */
|
|
16
|
-
with(key, value) {
|
|
17
|
-
if (isNullish(key))
|
|
18
|
-
return this;
|
|
19
|
-
return { __proto__: Object.getPrototypeOf(this), ...this, data: { ...this.data, [key]: value } };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Create a set operation for a document. */
|
|
23
|
-
export const SET = ({ collection, id }, data) => new SetOperation(collection, id, data);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Database, DatabaseDocument } from "../db/index.js";
|
|
2
|
-
import type { PropUpdates, Update } from "../update/index.js";
|
|
3
|
-
import { Data, Key, Nullish } from "../util/index.js";
|
|
4
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
5
|
-
/** Represent an update operation made to a single document in a database. */
|
|
6
|
-
export declare class UpdateOperation<T extends Data> extends WriteOperation {
|
|
7
|
-
readonly collection: string;
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly updates: PropUpdates<T>;
|
|
10
|
-
constructor(collection: string, id: string, updates: PropUpdates<T>);
|
|
11
|
-
run(db: Database): Promise<this>;
|
|
12
|
-
/** update one of the props on this set operation to a different value. */
|
|
13
|
-
with<K extends Key<T>>(key: Nullish<K>, value: T[K] | Update<T[K]>): this;
|
|
14
|
-
}
|
|
15
|
-
/** Create an update operation for a document. */
|
|
16
|
-
export declare const UPDATE: <T extends Data>({ collection, id }: DatabaseDocument<T>, updates: PropUpdates<T>) => UpdateOperation<T>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isNullish } from "../util/index.js";
|
|
2
|
-
import { WriteOperation } from "./WriteOperation.js";
|
|
3
|
-
/** Represent an update operation made to a single document in a database. */
|
|
4
|
-
export class UpdateOperation extends WriteOperation {
|
|
5
|
-
constructor(collection, id, updates) {
|
|
6
|
-
super();
|
|
7
|
-
this.collection = collection;
|
|
8
|
-
this.id = id;
|
|
9
|
-
this.updates = updates;
|
|
10
|
-
}
|
|
11
|
-
async run(db) {
|
|
12
|
-
await db.doc(this.collection, this.id).update(this.updates);
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
/** update one of the props on this set operation to a different value. */
|
|
16
|
-
with(key, value) {
|
|
17
|
-
if (isNullish(key))
|
|
18
|
-
return this;
|
|
19
|
-
return { __proto__: Object.getPrototypeOf(this), ...this, updates: { ...this.updates, [key]: value } };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Create an update operation for a document. */
|
|
23
|
-
export const UPDATE = ({ collection, id }, updates) => new UpdateOperation(collection, id, updates);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Database } from "../db/Database.js";
|
|
2
|
-
import { ImmutableArray, Nullish } from "../util/index.js";
|
|
3
|
-
import { Operation } from "./Operation.js";
|
|
4
|
-
/** Represent a write operation on a database. */
|
|
5
|
-
export declare abstract class WriteOperation extends Operation<[Database]> {
|
|
6
|
-
}
|
|
7
|
-
/** Represent a list of write operations on a database run in series. */
|
|
8
|
-
export declare class WriteOperations extends WriteOperation {
|
|
9
|
-
readonly operations: ImmutableArray<WriteOperation>;
|
|
10
|
-
constructor(...operations: Nullish<WriteOperation>[]);
|
|
11
|
-
run(db: Database): Promise<WriteOperations>;
|
|
12
|
-
/** Return a new instance of this object with an additional operation added. */
|
|
13
|
-
with(operation: Nullish<WriteOperation>): this;
|
|
14
|
-
}
|
|
15
|
-
/** Create a list of operations to be run. */
|
|
16
|
-
export declare const WRITES: (...operations: WriteOperation[]) => WriteOperations;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { callAsyncSeries, isNullish, isNotNullish } from "../util/index.js";
|
|
2
|
-
import { Operation } from "./Operation.js";
|
|
3
|
-
/** Represent a write operation on a database. */
|
|
4
|
-
export class WriteOperation extends Operation {
|
|
5
|
-
}
|
|
6
|
-
/** Represent a list of write operations on a database run in series. */
|
|
7
|
-
export class WriteOperations extends WriteOperation {
|
|
8
|
-
constructor(...operations) {
|
|
9
|
-
super();
|
|
10
|
-
this.operations = operations.filter(isNotNullish);
|
|
11
|
-
}
|
|
12
|
-
async run(db) {
|
|
13
|
-
return new WriteOperations(...(await callAsyncSeries(_write, this.operations, db)));
|
|
14
|
-
}
|
|
15
|
-
/** Return a new instance of this object with an additional operation added. */
|
|
16
|
-
with(operation) {
|
|
17
|
-
if (isNullish(operation))
|
|
18
|
-
return this;
|
|
19
|
-
return { __proto__: Object.getPrototypeOf(this), ...this, operations: [...this.operations, operation] };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// Run an operation on to a database.
|
|
23
|
-
const _write = (operation, db) => operation.run(db);
|
|
24
|
-
/** Create a list of operations to be run. */
|
|
25
|
-
export const WRITES = (...operations) => new WriteOperations(...operations);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AddOperation } from "./AddOperation.js";
|
|
2
|
-
import { DeleteOperation } from "./DeleteOperation.js";
|
|
3
|
-
import { SetOperation } from "./SetOperation.js";
|
|
4
|
-
import { UpdateOperation } from "./UpdateOperation.js";
|
|
5
|
-
import { WriteOperations } from "./WriteOperation.js";
|
|
6
|
-
/** Set of hydrations for all change classes. */
|
|
7
|
-
export declare const OPERATION_HYDRATIONS: {
|
|
8
|
-
WriteOperations: typeof WriteOperations;
|
|
9
|
-
AddOperation: typeof AddOperation;
|
|
10
|
-
SetOperation: typeof SetOperation;
|
|
11
|
-
UpdateOperation: typeof UpdateOperation;
|
|
12
|
-
DeleteOperation: typeof DeleteOperation;
|
|
13
|
-
};
|
package/operation/hydrations.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AddOperation } from "./AddOperation.js";
|
|
2
|
-
import { DeleteOperation } from "./DeleteOperation.js";
|
|
3
|
-
import { SetOperation } from "./SetOperation.js";
|
|
4
|
-
import { UpdateOperation } from "./UpdateOperation.js";
|
|
5
|
-
import { WriteOperations } from "./WriteOperation.js";
|
|
6
|
-
/** Set of hydrations for all change classes. */
|
|
7
|
-
export const OPERATION_HYDRATIONS = {
|
|
8
|
-
WriteOperations,
|
|
9
|
-
AddOperation,
|
|
10
|
-
SetOperation,
|
|
11
|
-
UpdateOperation,
|
|
12
|
-
DeleteOperation,
|
|
13
|
-
};
|
|
14
|
-
OPERATION_HYDRATIONS;
|
package/operation/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./Operation.js";
|
|
2
|
-
export * from "./Operations.js";
|
|
3
|
-
export * from "./WriteOperation.js";
|
|
4
|
-
export * from "./AddOperation.js";
|
|
5
|
-
export * from "./DeleteOperation.js";
|
|
6
|
-
export * from "./SetOperation.js";
|
|
7
|
-
export * from "./UpdateOperation.js";
|
|
8
|
-
export * from "./hydrations.js";
|
package/operation/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./Operation.js";
|
|
2
|
-
export * from "./Operations.js";
|
|
3
|
-
export * from "./WriteOperation.js";
|
|
4
|
-
export * from "./AddOperation.js";
|
|
5
|
-
export * from "./DeleteOperation.js";
|
|
6
|
-
export * from "./SetOperation.js";
|
|
7
|
-
export * from "./UpdateOperation.js";
|
|
8
|
-
export * from "./hydrations.js";
|