@pbvision/firestore-orm 0.0.14 → 0.0.16

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/environment.js CHANGED
@@ -1 +1 @@
1
- process.env.FIRESTORE_EMULATOR_HOST = '[::1]:8404'
1
+ process.env.FIRESTORE_EMULATOR_HOST = '127.0.0.1:9091'
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.16",
4
4
  "description": "Firestore ORM Library",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -59,6 +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": "^13.5.2",
62
63
  "jest": "^29",
63
64
  "jsdoc": "3.6.4",
64
65
  "nodemon": "^2.0.20",
@@ -0,0 +1,5 @@
1
+ {
2
+ "projects": {
3
+ "default": "localhost-emulator"
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "firestore": {},
3
+ "emulators": {
4
+ "singleProjectMode": true,
5
+ "auth": {
6
+ "port": "9090"
7
+ },
8
+ "firestore": {
9
+ "port": "9091"
10
+ }
11
+ }
12
+ }
@@ -1,12 +1,13 @@
1
1
  #!/bin/bash
2
2
  set -o errexit
3
3
  set -o nounset
4
+ cd "`dirname \"$0\"`"
4
5
 
5
- firestorePort=8404
6
- pid=`lsof -tPi :$firestorePort -sTCP:LISTEN || echo 'port_not_in_use'`
7
- if [ "$pid" != "port_not_in_use" ]; then
8
- echo "local db emulator port $firestorePort already in use; replacing PID $pid"
6
+ firestorePort=9091
7
+ pid=`ps ax | grep 'firebase emulators:start' | grep -v grep | cut -d' ' -f1`
8
+ if [ "$pid" != "" ]; then
9
+ echo "local emulator already running; replacing PID $pid"
9
10
  kill $pid
10
11
  fi
11
- gcloud emulators firestore start --host-port [::1]:$firestorePort > /dev/null 2> /dev/null &
12
- echo "firestore db emulator is now running in the background as PID $!"
12
+ firebase emulators:start --only firestore > /dev/null 2> /dev/null &
13
+ echo "firebase emulators are now running in the background as PID $!"
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
  }