@pbvision/firestore-orm 0.0.8 → 0.0.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/firestore-orm",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Firestore ORM Library",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/firestore.js CHANGED
@@ -111,7 +111,7 @@ export default function setup (firestoreDB) {
111
111
  TransactionFailedError,
112
112
  WriteAttemptedInReadOnlyTxError
113
113
  }
114
- if (Number(process.env.FIRESTORE_EMULATOR_HOST)) {
114
+ if (process.env.FIRESTORE_EMULATOR_HOST) {
115
115
  toExport.__private = {
116
116
  __Field,
117
117
  fields: [
package/src/models.js CHANGED
@@ -403,7 +403,12 @@ export class Model {
403
403
  pieces.push(stableStringify(givenValue))
404
404
  }
405
405
  }
406
- return pieces.join('\0')
406
+
407
+ // ` becomes `` (because we're going to use ` as an escape sequence)
408
+ // / becomes `F (because / is not allowed in Firestore doc keys)
409
+ const ret = pieces.join('\0')
410
+ const escaped = ret.replace(/`/g, '``').replace(/[/]/g, '`F')
411
+ return escaped
407
412
  }
408
413
 
409
414
  /**
@@ -418,7 +423,8 @@ export class Model {
418
423
  */
419
424
  static __decodeCompoundValue (keyOrder, val) {
420
425
  // Assume val is otherwise a string
421
- const pieces = val.split('\0')
426
+ const unescaped = val.replace(/`F/g, '/').replace(/``/g, '`')
427
+ const pieces = unescaped.split('\0')
422
428
  if (pieces.length !== keyOrder.length) {
423
429
  throw new InvalidFieldError(
424
430
  'KEY', 'failed to parse key: incorrect number of components')