@pbvision/firestore-orm 0.0.22 → 0.0.24
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/package.json +4 -4
- package/src/context.js +23 -2
- package/src/errors.js +17 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pbvision/firestore-orm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Firestore ORM Library",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=24"
|
|
9
9
|
},
|
|
10
10
|
"exports": "./src/default-db.js",
|
|
11
11
|
"scripts": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@google-cloud/firestore": "^7.1.0",
|
|
43
|
-
"@pbvision/schema": "^0.2.
|
|
43
|
+
"@pbvision/schema": "^0.2.31",
|
|
44
44
|
"deep-object-diff": "^1.1.7",
|
|
45
45
|
"fast-deep-equal": "^3.1.3",
|
|
46
46
|
"fast-json-stable-stringify": "^2.1.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"eslint-plugin-node": "^11.1.0",
|
|
60
60
|
"eslint-plugin-promise": "^6.0.0",
|
|
61
61
|
"eslint-plugin-standard": "^4.0.1",
|
|
62
|
-
"firebase-tools": "^
|
|
62
|
+
"firebase-tools": "^14.26.0",
|
|
63
63
|
"jest": "^29",
|
|
64
64
|
"jsdoc": "3.6.4",
|
|
65
65
|
"nodemon": "^2.0.20",
|
package/src/context.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
WriteAttemptedInReadOnlyTxError,
|
|
15
15
|
ModelTrackedTwiceError,
|
|
16
16
|
ModelAlreadyExistsError,
|
|
17
|
+
TransactionExpiredError,
|
|
17
18
|
TransactionLockTimeoutError
|
|
18
19
|
} from './errors.js'
|
|
19
20
|
import { Key } from './key.js'
|
|
@@ -644,6 +645,22 @@ function parseFirestoreError (err) {
|
|
|
644
645
|
return new TransactionLockTimeoutError(err.message, err)
|
|
645
646
|
}
|
|
646
647
|
|
|
648
|
+
// error 3 is INVALID_ARGUMENT, which mostly means the caller got something
|
|
649
|
+
// wrong and must NOT be retried (bad field value, malformed query). The one
|
|
650
|
+
// exception is "The referenced transaction has expired or is no longer
|
|
651
|
+
// valid": the transaction outlived Firestore's limit before this call
|
|
652
|
+
// reached the server, which happens when the client library's own retries
|
|
653
|
+
// push a slow call past the window. That says nothing about the work being
|
|
654
|
+
// wrong, only that this attempt ran out of time, so a fresh transaction is
|
|
655
|
+
// expected to succeed. Left unclassified it was non-retryable, so a
|
|
656
|
+
// transient slowdown surfaced to callers as a hard failure. Match on the
|
|
657
|
+
// message, never on the code alone, so genuine INVALID_ARGUMENT bugs still
|
|
658
|
+
// fail fast.
|
|
659
|
+
if (err.code === 3 &&
|
|
660
|
+
/transaction has expired or is no longer valid/i.test(err.message)) {
|
|
661
|
+
return new TransactionExpiredError(err.message, err)
|
|
662
|
+
}
|
|
663
|
+
|
|
647
664
|
// error 6 is if you try to create a model that already exists
|
|
648
665
|
if (err.code === 6) {
|
|
649
666
|
// if we can't parse out the doc id, then still throw this error but the
|
|
@@ -683,13 +700,17 @@ function parseFirestoreErrorPath (err) {
|
|
|
683
700
|
}
|
|
684
701
|
}
|
|
685
702
|
|
|
686
|
-
// istanbul ignore next
|
|
687
703
|
function parseFirestoreErrorPathAlternate (err) {
|
|
688
704
|
const startIdx = err.message.indexOf('path=')
|
|
689
705
|
if (startIdx === -1) {
|
|
690
706
|
return
|
|
691
707
|
}
|
|
692
|
-
|
|
708
|
+
// the path value is terminated by the EntityRef bracket. firebase-tools<=14
|
|
709
|
+
// (firestore emulator v1.19.x) wraps it in curly braces
|
|
710
|
+
// (EntityRef{...path=/Type/id}), while v1.21.0 switched to square brackets
|
|
711
|
+
// (EntityRef[...path=/Type/id]); accept whichever closes last.
|
|
712
|
+
const endIdx = Math.max(
|
|
713
|
+
err.message.lastIndexOf('}'), err.message.lastIndexOf(']'))
|
|
693
714
|
if (endIdx < startIdx) {
|
|
694
715
|
return
|
|
695
716
|
}
|
package/src/errors.js
CHANGED
|
@@ -70,6 +70,23 @@ export class TransactionLockTimeoutError extends TransactionFailedError {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Thrown when Firestore rejects an operation because the transaction it names
|
|
75
|
+
* is no longer valid, i.e. the transaction outlived Firestore's limit before
|
|
76
|
+
* this call reached the server. Like a lock timeout this says nothing about the
|
|
77
|
+
* work being wrong, only that this attempt ran out of time, so a fresh attempt
|
|
78
|
+
* is expected to succeed and it is retryable.
|
|
79
|
+
*
|
|
80
|
+
* @memberof Errors
|
|
81
|
+
*/
|
|
82
|
+
export class TransactionExpiredError extends TransactionFailedError {
|
|
83
|
+
constructor (reason, original) {
|
|
84
|
+
super(reason, original)
|
|
85
|
+
this.name = this.constructor.name
|
|
86
|
+
this.retryable = true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
73
90
|
/**
|
|
74
91
|
* Thrown when there's some error with a particular model.
|
|
75
92
|
* @memberof Errors
|