@prmichaelsen/firebase-admin-sdk-v8 2.0.8 → 2.0.12

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/dist/index.js CHANGED
@@ -591,8 +591,14 @@ function convertFromFirestoreFormat(fields) {
591
591
  return result;
592
592
  }
593
593
  function buildStructuredQuery(collectionPath, options) {
594
+ const pathSegments = collectionPath.split("/");
595
+ const collectionId = pathSegments[pathSegments.length - 1];
596
+ const fromClause = { collectionId };
597
+ if (pathSegments.length > 1) {
598
+ fromClause.allDescendants = false;
599
+ }
594
600
  const query = {
595
- from: [{ collectionId: collectionPath.split("/").pop() }]
601
+ from: [fromClause]
596
602
  };
597
603
  if (options?.where && options.where.length > 0) {
598
604
  const filters = options.where.map((filter) => ({
@@ -791,8 +797,8 @@ async function queryDocuments(collectionPath, options) {
791
797
  const accessToken = await getAdminAccessToken();
792
798
  const projectId = getProjectId();
793
799
  if (!options || Object.keys(options).length === 0) {
794
- const url2 = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${collectionPath}`;
795
- const response2 = await fetch(url2, {
800
+ const url = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${collectionPath}`;
801
+ const response2 = await fetch(url, {
796
802
  headers: {
797
803
  "Authorization": `Bearer ${accessToken}`
798
804
  }
@@ -808,9 +814,16 @@ async function queryDocuments(collectionPath, options) {
808
814
  data: convertFromFirestoreFormat(doc.fields)
809
815
  }));
810
816
  }
811
- const url = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents:runQuery`;
817
+ const pathSegments = collectionPath.split("/");
818
+ let queryUrl;
819
+ if (pathSegments.length > 1) {
820
+ const parentPath = pathSegments.slice(0, -1).join("/");
821
+ queryUrl = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${parentPath}:runQuery`;
822
+ } else {
823
+ queryUrl = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents:runQuery`;
824
+ }
812
825
  const structuredQuery = buildStructuredQuery(collectionPath, options);
813
- const response = await fetch(url, {
826
+ const response = await fetch(queryUrl, {
814
827
  method: "POST",
815
828
  headers: {
816
829
  "Authorization": `Bearer ${accessToken}`,
package/dist/index.mjs CHANGED
@@ -548,8 +548,14 @@ function convertFromFirestoreFormat(fields) {
548
548
  return result;
549
549
  }
550
550
  function buildStructuredQuery(collectionPath, options) {
551
+ const pathSegments = collectionPath.split("/");
552
+ const collectionId = pathSegments[pathSegments.length - 1];
553
+ const fromClause = { collectionId };
554
+ if (pathSegments.length > 1) {
555
+ fromClause.allDescendants = false;
556
+ }
551
557
  const query = {
552
- from: [{ collectionId: collectionPath.split("/").pop() }]
558
+ from: [fromClause]
553
559
  };
554
560
  if (options?.where && options.where.length > 0) {
555
561
  const filters = options.where.map((filter) => ({
@@ -748,8 +754,8 @@ async function queryDocuments(collectionPath, options) {
748
754
  const accessToken = await getAdminAccessToken();
749
755
  const projectId = getProjectId();
750
756
  if (!options || Object.keys(options).length === 0) {
751
- const url2 = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${collectionPath}`;
752
- const response2 = await fetch(url2, {
757
+ const url = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${collectionPath}`;
758
+ const response2 = await fetch(url, {
753
759
  headers: {
754
760
  "Authorization": `Bearer ${accessToken}`
755
761
  }
@@ -765,9 +771,16 @@ async function queryDocuments(collectionPath, options) {
765
771
  data: convertFromFirestoreFormat(doc.fields)
766
772
  }));
767
773
  }
768
- const url = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents:runQuery`;
774
+ const pathSegments = collectionPath.split("/");
775
+ let queryUrl;
776
+ if (pathSegments.length > 1) {
777
+ const parentPath = pathSegments.slice(0, -1).join("/");
778
+ queryUrl = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents/${parentPath}:runQuery`;
779
+ } else {
780
+ queryUrl = `${FIRESTORE_API}/projects/${projectId}/databases/(default)/documents:runQuery`;
781
+ }
769
782
  const structuredQuery = buildStructuredQuery(collectionPath, options);
770
- const response = await fetch(url, {
783
+ const response = await fetch(queryUrl, {
771
784
  method: "POST",
772
785
  headers: {
773
786
  "Authorization": `Bearer ${accessToken}`,
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>/src'],
5
+ testMatch: ['**/*.spec.ts'],
6
+ moduleFileExtensions: ['ts', 'js'],
7
+ collectCoverageFrom: [
8
+ 'src/**/*.ts',
9
+ '!src/**/*.d.ts',
10
+ '!src/**/*.spec.ts',
11
+ ],
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prmichaelsen/firebase-admin-sdk-v8",
3
- "version": "2.0.8",
3
+ "version": "2.0.12",
4
4
  "description": "Firebase Admin SDK for Cloudflare Workers and edge runtimes using REST APIs",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,7 +23,9 @@
23
23
  "scripts": {
24
24
  "build": "tsup src/index.ts --format cjs,esm --dts",
25
25
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
26
- "typecheck": "tsc --noEmit"
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "jest",
28
+ "test:watch": "jest --watch"
27
29
  },
28
30
  "keywords": [
29
31
  "firebase",
@@ -37,9 +39,11 @@
37
39
  ],
38
40
  "author": "",
39
41
  "license": "MIT",
40
- "dependencies": {},
41
42
  "devDependencies": {
43
+ "@types/jest": "^30.0.0",
42
44
  "@types/node": "^20.11.0",
45
+ "jest": "^30.2.0",
46
+ "ts-jest": "^29.4.6",
43
47
  "tsup": "^8.0.1",
44
48
  "typescript": "^5.3.3"
45
49
  }