@pbvision/firestore-orm 0.0.24 → 0.0.26

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 +16 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/firestore-orm",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "Firestore ORM Library",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/context.js CHANGED
@@ -678,7 +678,16 @@ function parseFirestoreError (err) {
678
678
  }
679
679
  }
680
680
 
681
+ // production Firestore names the document's full resource path, e.g.
682
+ // "Document already exists: projects/p/databases/(default)/documents/Type/id"
683
+ const PRODUCTION_ALREADY_EXISTS_PATH =
684
+ /Document already exists: projects\/[^/]+\/databases\/[^/]+\/documents\/(.+)$/s
685
+
681
686
  function parseFirestoreErrorPath (err) {
687
+ const docPath = PRODUCTION_ALREADY_EXISTS_PATH.exec(err.message)?.[1]
688
+ if (docPath) {
689
+ return splitDocPath(docPath)
690
+ }
682
691
  const startIdx = err.message.indexOf('Element {')
683
692
  if (startIdx >= 0) {
684
693
  const endIdx = err.message.indexOf('}', startIdx)
@@ -714,9 +723,13 @@ function parseFirestoreErrorPathAlternate (err) {
714
723
  if (endIdx < startIdx) {
715
724
  return
716
725
  }
717
- const path = err.message.substring(startIdx + 5, endIdx)
718
- const pieces = path.split('/', 2)
719
- if (pieces.length === 2) {
726
+ return splitDocPath(err.message.substring(startIdx + 5, endIdx))
727
+ }
728
+
729
+ // "Type/id", with or without a leading slash
730
+ function splitDocPath (path) {
731
+ const pieces = path.replace(/^\//, '').split('/')
732
+ if (pieces.length === 2 && pieces[0] && pieces[1]) {
720
733
  return { collection: pieces[0], id: pieces[1] }
721
734
  }
722
735
  }