shelving 1.52.0 → 1.53.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/errors.d.ts +0 -24
- package/db/errors.js +0 -36
- package/package.json +1 -1
- package/provider/ErrorProvider.d.ts +32 -0
- package/provider/ErrorProvider.js +175 -0
- package/provider/Provider.d.ts +1 -1
- package/provider/index.d.ts +1 -0
- package/provider/index.js +1 -0
package/db/errors.d.ts
CHANGED
|
@@ -7,18 +7,6 @@ export declare class DocumentRequiredError<T extends Data> extends RequiredError
|
|
|
7
7
|
ref: DatabaseDocument<T>;
|
|
8
8
|
constructor(ref: DatabaseDocument<T>);
|
|
9
9
|
}
|
|
10
|
-
/** Thrown if an error occurs while reading a document. */
|
|
11
|
-
export declare class DocumentReadError<T extends Data> extends Error {
|
|
12
|
-
error: Error;
|
|
13
|
-
ref: DatabaseDocument<T>;
|
|
14
|
-
constructor(error: Error, ref: DatabaseDocument<T>);
|
|
15
|
-
}
|
|
16
|
-
/** Thrown if an error occurs while writing a document. */
|
|
17
|
-
export declare class DocumentWriteError<T extends Data> extends Error {
|
|
18
|
-
error: Error;
|
|
19
|
-
ref: DatabaseDocument<T>;
|
|
20
|
-
constructor(error: Error, ref: DatabaseDocument<T>);
|
|
21
|
-
}
|
|
22
10
|
/** Thrown if a document can't validate. */
|
|
23
11
|
export declare class DocumentValidationError<T extends Data> extends ValidationError {
|
|
24
12
|
ref: DatabaseDocument<T>;
|
|
@@ -29,18 +17,6 @@ export declare class QueryRequiredError<T extends Data> extends RequiredError {
|
|
|
29
17
|
ref: DatabaseQuery<T>;
|
|
30
18
|
constructor(ref: DatabaseQuery<T>);
|
|
31
19
|
}
|
|
32
|
-
/** Thrown if an error occurs while reading a query. */
|
|
33
|
-
export declare class QueryReadError<T extends Data> extends Error {
|
|
34
|
-
error: Error;
|
|
35
|
-
ref: DatabaseQuery<T>;
|
|
36
|
-
constructor(error: Error, ref: DatabaseQuery<T>);
|
|
37
|
-
}
|
|
38
|
-
/** Thrown if an error occurs while writing a query. */
|
|
39
|
-
export declare class QueryWriteError<T extends Data> extends Error {
|
|
40
|
-
error: Error;
|
|
41
|
-
ref: DatabaseQuery<T>;
|
|
42
|
-
constructor(error: Error, ref: DatabaseQuery<T>);
|
|
43
|
-
}
|
|
44
20
|
/** Thrown if a query can't validate a set of results. */
|
|
45
21
|
export declare class QueryValidationError<T extends Data> extends ValidationError {
|
|
46
22
|
ref: DatabaseQuery<T>;
|
package/db/errors.js
CHANGED
|
@@ -7,24 +7,6 @@ export class DocumentRequiredError extends RequiredError {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
DocumentRequiredError.prototype.name = "DocumentRequiredError";
|
|
10
|
-
/** Thrown if an error occurs while reading a document. */
|
|
11
|
-
export class DocumentReadError extends Error {
|
|
12
|
-
constructor(error, ref) {
|
|
13
|
-
super(`Error reading document ${ref.toString()}:\n${error.message}`);
|
|
14
|
-
this.error = error;
|
|
15
|
-
this.ref = ref;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
DocumentReadError.prototype.name = "DocumentReadError";
|
|
19
|
-
/** Thrown if an error occurs while writing a document. */
|
|
20
|
-
export class DocumentWriteError extends Error {
|
|
21
|
-
constructor(error, ref) {
|
|
22
|
-
super(`Error writing document ${ref.toString()}:\n${error.message}`);
|
|
23
|
-
this.error = error;
|
|
24
|
-
this.ref = ref;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
DocumentWriteError.prototype.name = "DocumentWriteError";
|
|
28
10
|
/** Thrown if a document can't validate. */
|
|
29
11
|
export class DocumentValidationError extends ValidationError {
|
|
30
12
|
constructor(ref, feedback) {
|
|
@@ -41,24 +23,6 @@ export class QueryRequiredError extends RequiredError {
|
|
|
41
23
|
}
|
|
42
24
|
}
|
|
43
25
|
QueryRequiredError.prototype.name = "QueryRequiredError";
|
|
44
|
-
/** Thrown if an error occurs while reading a query. */
|
|
45
|
-
export class QueryReadError extends Error {
|
|
46
|
-
constructor(error, ref) {
|
|
47
|
-
super(`Error reading query ${ref.toString()}:\n${error.message}`);
|
|
48
|
-
this.error = error;
|
|
49
|
-
this.ref = ref;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
QueryReadError.prototype.name = "QueryReadError";
|
|
53
|
-
/** Thrown if an error occurs while writing a query. */
|
|
54
|
-
export class QueryWriteError extends Error {
|
|
55
|
-
constructor(error, ref) {
|
|
56
|
-
super(`Error writing query ${ref.toString()}:\n${error.message}`);
|
|
57
|
-
this.error = error;
|
|
58
|
-
this.ref = ref;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
DocumentWriteError.prototype.name = "DocumentWriteError";
|
|
62
26
|
/** Thrown if a query can't validate a set of results. */
|
|
63
27
|
export class QueryValidationError extends ValidationError {
|
|
64
28
|
constructor(ref, feedback) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DatabaseDocument, DatabaseQuery } from "../db/Database.js";
|
|
2
|
+
import { Update } from "../update/Update.js";
|
|
3
|
+
import { Data, Result } from "../util/data.js";
|
|
4
|
+
import { Entries } from "../util/entry.js";
|
|
5
|
+
import { Observer, Unsubscriber } from "../util/observable.js";
|
|
6
|
+
import { ThroughProvider } from "./ThroughProvider.js";
|
|
7
|
+
/** Provider that wraps errors thrown from deeper providers in `DatabaseReadError` and `DatabaseWriteError` etc to make it easier to see what read/write caused the error. */
|
|
8
|
+
export declare class ErrorProvider extends ThroughProvider {
|
|
9
|
+
get<T extends Data>(ref: DatabaseDocument<T>): Result<T> | PromiseLike<Result<T>>;
|
|
10
|
+
subscribe<T extends Data>(ref: DatabaseDocument<T>, observer: Observer<Result<T>>): Unsubscriber;
|
|
11
|
+
add<T extends Data>(ref: DatabaseQuery<T>, data: T): string | PromiseLike<string>;
|
|
12
|
+
set<T extends Data>(ref: DatabaseDocument<T>, data: T): void | PromiseLike<void>;
|
|
13
|
+
update<T extends Data>(ref: DatabaseDocument<T>, updates: Update<T>): void | PromiseLike<void>;
|
|
14
|
+
delete<T extends Data>(ref: DatabaseDocument<T>): void | PromiseLike<void>;
|
|
15
|
+
getQuery<T extends Data>(ref: DatabaseQuery<T>): Entries<T> | PromiseLike<Entries<T>>;
|
|
16
|
+
subscribeQuery<T extends Data>(ref: DatabaseQuery<T>, observer: Observer<Entries<T>>): Unsubscriber;
|
|
17
|
+
setQuery<T extends Data>(ref: DatabaseQuery<T>, data: T): number | PromiseLike<number>;
|
|
18
|
+
updateQuery<T extends Data>(ref: DatabaseQuery<T>, updates: Update<T>): number | PromiseLike<number>;
|
|
19
|
+
deleteQuery<T extends Data>(ref: DatabaseQuery<T>): number | PromiseLike<number>;
|
|
20
|
+
}
|
|
21
|
+
/** Thrown if an error occurs while reading a query. */
|
|
22
|
+
export declare class DatabaseReadError<T extends Data> extends Error {
|
|
23
|
+
readonly error: Error;
|
|
24
|
+
readonly ref: DatabaseDocument<T> | DatabaseQuery<T>;
|
|
25
|
+
constructor(error: Error, ref: DatabaseDocument<T> | DatabaseQuery<T>);
|
|
26
|
+
}
|
|
27
|
+
/** Thrown if an error occurs while writing a document. */
|
|
28
|
+
export declare class DatabaseWriteError<T extends Data> extends Error {
|
|
29
|
+
readonly error: Error;
|
|
30
|
+
readonly ref: DatabaseDocument<T> | DatabaseQuery<T>;
|
|
31
|
+
constructor(error: Error, ref: DatabaseDocument<T> | DatabaseQuery<T>);
|
|
32
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isAsync } from "../index.js";
|
|
2
|
+
import { ThroughObserver } from "../util/observable.js";
|
|
3
|
+
import { ThroughProvider } from "./ThroughProvider.js";
|
|
4
|
+
/** Provider that wraps errors thrown from deeper providers in `DatabaseReadError` and `DatabaseWriteError` etc to make it easier to see what read/write caused the error. */
|
|
5
|
+
export class ErrorProvider extends ThroughProvider {
|
|
6
|
+
get(ref) {
|
|
7
|
+
try {
|
|
8
|
+
const result = super.get(ref);
|
|
9
|
+
return isAsync(result)
|
|
10
|
+
? result.then(undefined, err => {
|
|
11
|
+
throw err instanceof Error ? new DatabaseReadError(err, ref) : err;
|
|
12
|
+
})
|
|
13
|
+
: result;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
if (err instanceof Error)
|
|
17
|
+
throw new DatabaseReadError(err, ref);
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
subscribe(ref, observer) {
|
|
22
|
+
return super.subscribe(ref, new DatabaseErrorObserver(ref, observer));
|
|
23
|
+
}
|
|
24
|
+
add(ref, data) {
|
|
25
|
+
try {
|
|
26
|
+
const result = super.add(ref, data);
|
|
27
|
+
return isAsync(result)
|
|
28
|
+
? result.then(undefined, err => {
|
|
29
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
30
|
+
})
|
|
31
|
+
: result;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof Error)
|
|
35
|
+
throw new DatabaseWriteError(err, ref);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
set(ref, data) {
|
|
40
|
+
try {
|
|
41
|
+
const result = super.set(ref, data);
|
|
42
|
+
return isAsync(result)
|
|
43
|
+
? result.then(undefined, err => {
|
|
44
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
45
|
+
})
|
|
46
|
+
: result;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err instanceof Error)
|
|
50
|
+
throw new DatabaseWriteError(err, ref);
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
update(ref, updates) {
|
|
55
|
+
try {
|
|
56
|
+
const result = super.update(ref, updates);
|
|
57
|
+
return isAsync(result)
|
|
58
|
+
? result.then(undefined, err => {
|
|
59
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
60
|
+
})
|
|
61
|
+
: result;
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (err instanceof Error)
|
|
65
|
+
throw new DatabaseWriteError(err, ref);
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
delete(ref) {
|
|
70
|
+
try {
|
|
71
|
+
const result = super.delete(ref);
|
|
72
|
+
return isAsync(result)
|
|
73
|
+
? result.then(undefined, err => {
|
|
74
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
75
|
+
})
|
|
76
|
+
: result;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof Error)
|
|
80
|
+
throw new DatabaseWriteError(err, ref);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
getQuery(ref) {
|
|
85
|
+
try {
|
|
86
|
+
const results = super.getQuery(ref);
|
|
87
|
+
return isAsync(results)
|
|
88
|
+
? results.then(undefined, err => {
|
|
89
|
+
throw err instanceof Error ? new DatabaseReadError(err, ref) : err;
|
|
90
|
+
})
|
|
91
|
+
: results;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (err instanceof Error)
|
|
95
|
+
throw new DatabaseReadError(err, ref);
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
subscribeQuery(ref, observer) {
|
|
100
|
+
return super.subscribeQuery(ref, new DatabaseErrorObserver(ref, observer));
|
|
101
|
+
}
|
|
102
|
+
setQuery(ref, data) {
|
|
103
|
+
try {
|
|
104
|
+
const result = super.setQuery(ref, data);
|
|
105
|
+
return isAsync(result)
|
|
106
|
+
? result.then(undefined, err => {
|
|
107
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
108
|
+
})
|
|
109
|
+
: result;
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (err instanceof Error)
|
|
113
|
+
throw new DatabaseWriteError(err, ref);
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
updateQuery(ref, updates) {
|
|
118
|
+
try {
|
|
119
|
+
const result = super.updateQuery(ref, updates);
|
|
120
|
+
return isAsync(result)
|
|
121
|
+
? result.then(undefined, err => {
|
|
122
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
123
|
+
})
|
|
124
|
+
: result;
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
if (err instanceof Error)
|
|
128
|
+
throw new DatabaseWriteError(err, ref);
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
deleteQuery(ref) {
|
|
133
|
+
try {
|
|
134
|
+
const result = super.deleteQuery(ref);
|
|
135
|
+
return isAsync(result)
|
|
136
|
+
? result.then(undefined, err => {
|
|
137
|
+
throw err instanceof Error ? new DatabaseWriteError(err, ref) : err;
|
|
138
|
+
})
|
|
139
|
+
: result;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (err instanceof Error)
|
|
143
|
+
throw new DatabaseWriteError(err, ref);
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Thrown if an error occurs while reading a query. */
|
|
149
|
+
export class DatabaseReadError extends Error {
|
|
150
|
+
constructor(error, ref) {
|
|
151
|
+
super(`Error reading ${ref.toString()}:\n${error.message}`);
|
|
152
|
+
this.error = error;
|
|
153
|
+
this.ref = ref;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
DatabaseReadError.prototype.name = "DatabaseReadError";
|
|
157
|
+
/** Thrown if an error occurs while writing a document. */
|
|
158
|
+
export class DatabaseWriteError extends Error {
|
|
159
|
+
constructor(error, ref) {
|
|
160
|
+
super(`Error writing ${ref.toString()}:\n${error.message}`);
|
|
161
|
+
this.error = error;
|
|
162
|
+
this.ref = ref;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
DatabaseWriteError.prototype.name = "DocumentWriteError";
|
|
166
|
+
/** Observer that wraps errors in subscriptions in `DatabaseReadError` */
|
|
167
|
+
class DatabaseErrorObserver extends ThroughObserver {
|
|
168
|
+
constructor(ref, target) {
|
|
169
|
+
super(target);
|
|
170
|
+
this.ref = ref;
|
|
171
|
+
}
|
|
172
|
+
error(error) {
|
|
173
|
+
super.error(error instanceof Error ? new DatabaseReadError(error, this.ref) : error);
|
|
174
|
+
}
|
|
175
|
+
}
|
package/provider/Provider.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare abstract class Provider {
|
|
|
40
40
|
*
|
|
41
41
|
* @throws Error If a `Update` was provided but the document does not exist (ideally a `RequiredError` but may be provider-specific).
|
|
42
42
|
*/
|
|
43
|
-
abstract set<T extends Data>(ref: DatabaseDocument<T>,
|
|
43
|
+
abstract set<T extends Data>(ref: DatabaseDocument<T>, data: T): void | PromiseLike<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Update the data an existing document.
|
|
46
46
|
*
|
package/provider/index.d.ts
CHANGED
package/provider/index.js
CHANGED