@pbvision/firestore-orm 0.0.14 → 0.0.15

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/context.js +30 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/firestore-orm",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Firestore ORM Library",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/context.js CHANGED
@@ -642,11 +642,18 @@ function parseFirestoreError (err) {
642
642
  }
643
643
 
644
644
  // error 6 is if you try to create a model that already exists
645
- const docInfo = parseFirestoreErrorPath(err)
646
- if (docInfo) {
647
- if (err.code === 6) {
648
- return new ModelAlreadyExistsError(docInfo.collection, docInfo.id)
645
+ if (err.code === 6) {
646
+ // if we can't parse out the doc id, then still throw this error but the
647
+ // error data will require some parsing to get the doc id later (noticed
648
+ // that from firebase-tools 1.18.2 to 1.19.1 the format of this error
649
+ // changed)
650
+ const docInfo = parseFirestoreErrorPath(err)
651
+ if (!docInfo) {
652
+ console.warn('could not parse model already exists error: ', err)
649
653
  }
654
+ return new ModelAlreadyExistsError(
655
+ docInfo?.collection ?? 'could not parse',
656
+ docInfo?.id ?? err.message)
650
657
  }
651
658
  }
652
659
  }
@@ -668,5 +675,24 @@ function parseFirestoreErrorPath (err) {
668
675
  return elt
669
676
  } catch { /* no-op */ }
670
677
  }
678
+ } else {
679
+ return parseFirestoreErrorPathAlternate(err)
680
+ }
681
+ }
682
+
683
+ // istanbul ignore next
684
+ function parseFirestoreErrorPathAlternate (err) {
685
+ const startIdx = err.message.indexOf('path=')
686
+ if (startIdx === -1) {
687
+ return
688
+ }
689
+ const endIdx = err.message.lastIndexOf('}')
690
+ if (endIdx < startIdx) {
691
+ return
692
+ }
693
+ const path = err.message.substring(startIdx + 5, endIdx)
694
+ const pieces = path.split('/', 2)
695
+ if (pieces.length === 2) {
696
+ return { collection: pieces[0], id: pieces[1] }
671
697
  }
672
698
  }