@pbvision/firestore-orm 0.0.26 → 0.0.27
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 +1 -1
- package/src/context.js +16 -3
- package/src/errors.js +11 -3
package/package.json
CHANGED
package/src/context.js
CHANGED
|
@@ -405,10 +405,23 @@ export class Context {
|
|
|
405
405
|
await model.__write(this)
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
__throwIfWritesNotAllowed (
|
|
409
|
-
if (this.options.readOnly) {
|
|
410
|
-
|
|
408
|
+
__throwIfWritesNotAllowed (modelOrKey) {
|
|
409
|
+
if (!this.options.readOnly) {
|
|
410
|
+
return
|
|
411
|
+
}
|
|
412
|
+
let key = modelOrKey
|
|
413
|
+
let fieldNames = []
|
|
414
|
+
if (modelOrKey instanceof Model) {
|
|
415
|
+
key = modelOrKey.__key
|
|
416
|
+
fieldNames = Object.values(modelOrKey.__cached_attrs)
|
|
417
|
+
.filter(field => field.hasChangesToCommit(false))
|
|
418
|
+
.map(field => field.name)
|
|
411
419
|
}
|
|
420
|
+
// delete() checks for read-only before it checks its args
|
|
421
|
+
const doc = key instanceof Key
|
|
422
|
+
? `${key.Cls.collectionName} _id=${key.encodedKey}`
|
|
423
|
+
: 'an unknown doc'
|
|
424
|
+
throw new WriteAttemptedInReadOnlyTxError(doc, fieldNames)
|
|
412
425
|
}
|
|
413
426
|
|
|
414
427
|
/**
|
package/src/errors.js
CHANGED
|
@@ -135,12 +135,20 @@ export class DeletedTwiceError extends GenericModelError {
|
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Thrown when a tx tries to write when it was marked read-only.
|
|
138
|
+
*
|
|
139
|
+
* Names the doc and the fields it would have changed, never their values: a
|
|
140
|
+
* model can hold secrets, and this message ends up in logs and error reports
|
|
141
|
+
* (and, through an error handler that returns crash messages, in API
|
|
142
|
+
* responses).
|
|
138
143
|
* @memberof Errors
|
|
139
144
|
*/
|
|
140
145
|
export class WriteAttemptedInReadOnlyTxError extends Error {
|
|
141
|
-
constructor (
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
constructor (doc, fieldNames) {
|
|
147
|
+
const fields = fieldNames.length
|
|
148
|
+
? ` (changed fields: ${fieldNames.join(', ')})`
|
|
149
|
+
: ''
|
|
150
|
+
super(`Tried to write ${doc} in a read-only transaction${fields}`)
|
|
151
|
+
this.name = this.constructor.name
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
|