firebase-rest-firestore 1.2.0 → 1.5.0

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 (41) hide show
  1. package/dist/cjs/client.d.ts +417 -0
  2. package/dist/{client.js → cjs/client.js} +442 -279
  3. package/dist/{index.d.ts → cjs/index.d.ts} +1 -1
  4. package/dist/{index.js → cjs/index.js} +1 -2
  5. package/dist/{types.d.ts → cjs/types.d.ts} +4 -0
  6. package/dist/cjs/utils/auth.d.ts +13 -0
  7. package/dist/{utils → cjs/utils}/auth.js +14 -10
  8. package/dist/cjs/utils/config.d.ts +6 -0
  9. package/dist/{utils → cjs/utils}/config.js +0 -12
  10. package/dist/cjs/utils/path.d.ts +73 -0
  11. package/dist/cjs/utils/path.js +176 -0
  12. package/dist/esm/client.d.ts +417 -0
  13. package/dist/esm/client.js +1066 -0
  14. package/dist/esm/index.d.ts +7 -0
  15. package/dist/esm/index.js +11 -0
  16. package/dist/esm/types.d.ts +69 -0
  17. package/dist/esm/types.js +1 -0
  18. package/dist/esm/utils/auth.d.ts +13 -0
  19. package/dist/esm/utils/auth.js +57 -0
  20. package/dist/esm/utils/config.d.ts +6 -0
  21. package/dist/esm/utils/config.js +11 -0
  22. package/dist/esm/utils/converter.d.ts +27 -0
  23. package/dist/esm/utils/converter.js +107 -0
  24. package/dist/esm/utils/path.d.ts +73 -0
  25. package/dist/esm/utils/path.js +169 -0
  26. package/dist/types/client.d.ts +417 -0
  27. package/dist/types/index.d.ts +7 -0
  28. package/dist/types/types.d.ts +69 -0
  29. package/dist/types/utils/auth.d.ts +13 -0
  30. package/dist/types/utils/config.d.ts +6 -0
  31. package/dist/types/utils/converter.d.ts +27 -0
  32. package/dist/types/utils/path.d.ts +73 -0
  33. package/package.json +18 -5
  34. package/dist/client.d.ts +0 -381
  35. package/dist/utils/auth.d.ts +0 -13
  36. package/dist/utils/config.d.ts +0 -13
  37. package/dist/utils/path.d.ts +0 -14
  38. package/dist/utils/path.js +0 -27
  39. /package/dist/{types.js → cjs/types.js} +0 -0
  40. /package/dist/{utils → cjs/utils}/converter.d.ts +0 -0
  41. /package/dist/{utils → cjs/utils}/converter.js +0 -0
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ import { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult } from "./client";
3
+ export { getFirestoreToken } from "./utils/auth";
4
+ export { convertToFirestoreValue, convertFromFirestoreValue, convertToFirestoreDocument, convertFromFirestoreDocument, } from "./utils/converter";
5
+ export { getFirestoreBasePath, getDocumentId } from "./utils/path";
6
+ export { formatPrivateKey } from "./utils/config";
7
+ export { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult, };
@@ -0,0 +1,11 @@
1
+ // 型定義のエクスポート
2
+ export * from "./types";
3
+ // クライアントのエクスポート
4
+ import { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult, } from "./client";
5
+ // ユーティリティ関数のエクスポート
6
+ export { getFirestoreToken } from "./utils/auth";
7
+ export { convertToFirestoreValue, convertFromFirestoreValue, convertToFirestoreDocument, convertFromFirestoreDocument, } from "./utils/converter";
8
+ export { getFirestoreBasePath, getDocumentId } from "./utils/path";
9
+ export { formatPrivateKey } from "./utils/config";
10
+ // クライアント関連のエクスポート
11
+ export { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult, };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Firestoreクライアントの設定インターフェース
3
+ */
4
+ export interface FirestoreConfig {
5
+ projectId: string;
6
+ privateKey: string;
7
+ clientEmail: string;
8
+ databaseId?: string;
9
+ debug?: boolean;
10
+ useEmulator?: boolean;
11
+ emulatorHost?: string;
12
+ emulatorPort?: number;
13
+ }
14
+ /**
15
+ * Firestoreの値型定義
16
+ */
17
+ export type FirestoreFieldValue = {
18
+ stringValue: string;
19
+ } | {
20
+ integerValue: number;
21
+ } | {
22
+ doubleValue: number;
23
+ } | {
24
+ booleanValue: boolean;
25
+ } | {
26
+ nullValue: null;
27
+ } | {
28
+ timestampValue: string;
29
+ } | {
30
+ mapValue: {
31
+ fields: Record<string, FirestoreFieldValue>;
32
+ };
33
+ } | {
34
+ arrayValue: {
35
+ values: FirestoreFieldValue[];
36
+ };
37
+ };
38
+ /**
39
+ * Firestoreドキュメント型
40
+ */
41
+ export interface FirestoreDocument {
42
+ name?: string;
43
+ fields: Record<string, FirestoreFieldValue>;
44
+ createTime?: string;
45
+ updateTime?: string;
46
+ }
47
+ /**
48
+ * Firestoreレスポンス型
49
+ */
50
+ export interface FirestoreResponse {
51
+ name: string;
52
+ fields?: Record<string, FirestoreFieldValue>;
53
+ createTime?: string;
54
+ updateTime?: string;
55
+ }
56
+ /**
57
+ * クエリオプション型
58
+ */
59
+ export interface QueryOptions {
60
+ where?: Array<{
61
+ field: string;
62
+ op: string;
63
+ value: any;
64
+ }>;
65
+ orderBy?: string;
66
+ orderDirection?: string;
67
+ limit?: number;
68
+ offset?: number;
69
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { FirestoreConfig } from "../types";
2
+ /**
3
+ * Function to create a JWT (JSON Web Token)
4
+ * @param config Firestore configuration
5
+ * @returns JWT string
6
+ */
7
+ export declare function createJWT(config: FirestoreConfig): Promise<string>;
8
+ /**
9
+ * Function to get Firestore authentication token
10
+ * @param config Firestore configuration
11
+ * @returns Access token
12
+ */
13
+ export declare function getFirestoreToken(config: FirestoreConfig): Promise<string>;
@@ -0,0 +1,57 @@
1
+ import * as jose from "jose";
2
+ /**
3
+ * Function to create a JWT (JSON Web Token)
4
+ * @param config Firestore configuration
5
+ * @returns JWT string
6
+ */
7
+ export async function createJWT(config) {
8
+ const now = Math.floor(Date.now() / 1000);
9
+ const payload = {
10
+ iss: config.clientEmail,
11
+ sub: config.clientEmail,
12
+ aud: "https://oauth2.googleapis.com/token",
13
+ iat: now,
14
+ exp: now + 3600, // Expires in 1 hour
15
+ scope: "https://www.googleapis.com/auth/datastore",
16
+ };
17
+ try {
18
+ // Import the private key
19
+ const privateKey = await jose.importPKCS8(config.privateKey, "RS256");
20
+ // Create JWT
21
+ const token = await new jose.SignJWT(payload)
22
+ .setProtectedHeader({
23
+ alg: "RS256",
24
+ typ: "JWT",
25
+ })
26
+ .sign(privateKey);
27
+ return token;
28
+ }
29
+ catch (error) {
30
+ console.error("Error creating JWT:", error);
31
+ throw error;
32
+ }
33
+ }
34
+ /**
35
+ * Function to get Firestore authentication token
36
+ * @param config Firestore configuration
37
+ * @returns Access token
38
+ */
39
+ export async function getFirestoreToken(config) {
40
+ // No authentication in emulator mode (returns a dummy token)
41
+ if (config.useEmulator) {
42
+ return "firebase-emulator-auth-token";
43
+ }
44
+ // Normal authentication process
45
+ const response = await fetch("https://oauth2.googleapis.com/token", {
46
+ method: "POST",
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ },
50
+ body: JSON.stringify({
51
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
52
+ assertion: await createJWT(config),
53
+ }),
54
+ });
55
+ const data = (await response.json());
56
+ return data.access_token;
57
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 秘密鍵の文字列内にある改行コードのエスケープシーケンスを実際の改行に変換する
3
+ * @param privateKey 変換する秘密鍵文字列
4
+ * @returns 変換後の秘密鍵文字列
5
+ */
6
+ export declare function formatPrivateKey(privateKey: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 秘密鍵の文字列内にある改行コードのエスケープシーケンスを実際の改行に変換する
3
+ * @param privateKey 変換する秘密鍵文字列
4
+ * @returns 変換後の秘密鍵文字列
5
+ */
6
+ export function formatPrivateKey(privateKey) {
7
+ if (privateKey.includes("\\n")) {
8
+ return privateKey.replace(/\\n/g, "\n");
9
+ }
10
+ return privateKey;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { FirestoreDocument, FirestoreFieldValue, FirestoreResponse } from "../types";
2
+ /**
3
+ * JSの値をFirestore形式に変換する
4
+ * @param value 変換する値
5
+ * @returns Firestore形式の値
6
+ */
7
+ export declare function convertToFirestoreValue(value: any): FirestoreFieldValue;
8
+ /**
9
+ * Firestore形式からJSの値に変換する
10
+ * @param firestoreValue Firestore形式の値
11
+ * @returns JS形式の値
12
+ */
13
+ export declare function convertFromFirestoreValue(firestoreValue: FirestoreFieldValue): any;
14
+ /**
15
+ * オブジェクトをFirestoreドキュメント形式に変換
16
+ * @param data 変換するオブジェクト
17
+ * @returns Firestoreドキュメント
18
+ */
19
+ export declare function convertToFirestoreDocument(data: Record<string, any>): FirestoreDocument;
20
+ /**
21
+ * Firestoreドキュメントをオブジェクトに変換
22
+ * @param doc Firestoreレスポンス
23
+ * @returns 変換されたオブジェクト(idプロパティ付き)
24
+ */
25
+ export declare function convertFromFirestoreDocument(doc: FirestoreResponse): Record<string, any> & {
26
+ id: string;
27
+ };
@@ -0,0 +1,107 @@
1
+ import { getDocumentId } from "./path";
2
+ /**
3
+ * JSの値をFirestore形式に変換する
4
+ * @param value 変換する値
5
+ * @returns Firestore形式の値
6
+ */
7
+ export function convertToFirestoreValue(value) {
8
+ if (value instanceof Date) {
9
+ return { timestampValue: value.toISOString() };
10
+ }
11
+ else if (typeof value === "string") {
12
+ return { stringValue: value };
13
+ }
14
+ else if (typeof value === "number") {
15
+ return Number.isInteger(value)
16
+ ? { integerValue: value }
17
+ : { doubleValue: value };
18
+ }
19
+ else if (typeof value === "boolean") {
20
+ return { booleanValue: value };
21
+ }
22
+ else if (value === null || value === undefined) {
23
+ return { nullValue: null };
24
+ }
25
+ else if (Array.isArray(value)) {
26
+ return {
27
+ arrayValue: {
28
+ values: value.map(item => convertToFirestoreValue(item)),
29
+ },
30
+ };
31
+ }
32
+ else if (typeof value === "object") {
33
+ const fields = Object.entries(value).reduce((acc, [key, val]) => ({
34
+ ...acc,
35
+ [key]: convertToFirestoreValue(val),
36
+ }), {});
37
+ return { mapValue: { fields } };
38
+ }
39
+ // デフォルトは文字列化
40
+ return { stringValue: String(value) };
41
+ }
42
+ /**
43
+ * Firestore形式からJSの値に変換する
44
+ * @param firestoreValue Firestore形式の値
45
+ * @returns JS形式の値
46
+ */
47
+ export function convertFromFirestoreValue(firestoreValue) {
48
+ if ("stringValue" in firestoreValue) {
49
+ return firestoreValue.stringValue;
50
+ }
51
+ else if ("integerValue" in firestoreValue) {
52
+ return Number(firestoreValue.integerValue);
53
+ }
54
+ else if ("doubleValue" in firestoreValue) {
55
+ return firestoreValue.doubleValue;
56
+ }
57
+ else if ("booleanValue" in firestoreValue) {
58
+ return firestoreValue.booleanValue;
59
+ }
60
+ else if ("nullValue" in firestoreValue) {
61
+ return null;
62
+ }
63
+ else if ("timestampValue" in firestoreValue) {
64
+ return new Date(firestoreValue.timestampValue);
65
+ }
66
+ else if ("mapValue" in firestoreValue && firestoreValue.mapValue.fields) {
67
+ return Object.entries(firestoreValue.mapValue.fields).reduce((acc, [key, val]) => ({
68
+ ...acc,
69
+ [key]: convertFromFirestoreValue(val),
70
+ }), {});
71
+ }
72
+ else if ("arrayValue" in firestoreValue &&
73
+ firestoreValue.arrayValue.values) {
74
+ return firestoreValue.arrayValue.values.map(convertFromFirestoreValue);
75
+ }
76
+ return null;
77
+ }
78
+ /**
79
+ * オブジェクトをFirestoreドキュメント形式に変換
80
+ * @param data 変換するオブジェクト
81
+ * @returns Firestoreドキュメント
82
+ */
83
+ export function convertToFirestoreDocument(data) {
84
+ return {
85
+ fields: Object.entries(data).reduce((acc, [key, value]) => ({
86
+ ...acc,
87
+ [key]: convertToFirestoreValue(value),
88
+ }), {}),
89
+ };
90
+ }
91
+ /**
92
+ * Firestoreドキュメントをオブジェクトに変換
93
+ * @param doc Firestoreレスポンス
94
+ * @returns 変換されたオブジェクト(idプロパティ付き)
95
+ */
96
+ export function convertFromFirestoreDocument(doc) {
97
+ if (!doc.fields)
98
+ return { id: getDocumentId(doc.name) };
99
+ const result = Object.entries(doc.fields).reduce((acc, [key, value]) => ({
100
+ ...acc,
101
+ [key]: convertFromFirestoreValue(value),
102
+ }), {});
103
+ return {
104
+ ...result,
105
+ id: getDocumentId(doc.name),
106
+ };
107
+ }
@@ -0,0 +1,73 @@
1
+ import { FirestoreConfig } from "../types";
2
+ /**
3
+ * Utility class for constructing Firestore URIs
4
+ * Consistently handles different types of paths and operations
5
+ */
6
+ export declare class FirestorePath {
7
+ private projectId;
8
+ private databaseId;
9
+ private useEmulator;
10
+ private emulatorHost;
11
+ private emulatorPort;
12
+ private debug;
13
+ /**
14
+ * Constructor
15
+ */
16
+ constructor(config: FirestoreConfig, debug?: boolean);
17
+ /**
18
+ * Get Firestore base URL (without document path)
19
+ */
20
+ getBasePath(): string;
21
+ /**
22
+ * Get base URL + collection path for a collection root
23
+ * @param path Collection path (ex: "users" or "users/uid/posts")
24
+ */
25
+ getCollectionPath(path: string): string;
26
+ /**
27
+ * Get the complete URL for a document
28
+ * @param collectionPath Collection path
29
+ * @param documentId Document ID
30
+ */
31
+ getDocumentPath(collectionPath: string, documentId: string): string;
32
+ /**
33
+ * Get URL for query execution
34
+ * @param path Collection path (ex: "users" or "users/uid/posts")
35
+ * @returns URL for query execution, collection ID, and parent path (if needed)
36
+ */
37
+ getQueryPath(path: string): {
38
+ url: string;
39
+ collectionId: string;
40
+ parentPath?: string;
41
+ };
42
+ /**
43
+ * Get reference path for parent document (for query construction)
44
+ * @param parentPath Parent document path
45
+ */
46
+ getParentReference(parentPath: string): string;
47
+ /**
48
+ * Get URL for runQuery
49
+ * @param collectionPath Collection path
50
+ * @returns URL for executing runQuery
51
+ */
52
+ getRunQueryPath(collectionPath: string): string;
53
+ }
54
+ /**
55
+ * Create an instance of FirestorePath class
56
+ * @param config Firestore configuration
57
+ * @param debug Debug mode
58
+ */
59
+ export declare function createFirestorePath(config: FirestoreConfig, debug?: boolean): FirestorePath;
60
+ /**
61
+ * Get Firestore base path URL (without path)
62
+ * @param projectId Project ID
63
+ * @param databaseId Database ID (defaults to default)
64
+ * @param config Firestore configuration (for emulator settings)
65
+ * @returns Firestore base path URL (without path)
66
+ */
67
+ export declare function getFirestoreBasePath(projectId: string, databaseId?: string, config?: FirestoreConfig): string;
68
+ /**
69
+ * Extract document ID from document path
70
+ * @param path Document path
71
+ * @returns Document ID
72
+ */
73
+ export declare function getDocumentId(path: string): string;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Utility class for constructing Firestore URIs
3
+ * Consistently handles different types of paths and operations
4
+ */
5
+ export class FirestorePath {
6
+ /**
7
+ * Constructor
8
+ */
9
+ constructor(config, debug = false) {
10
+ this.useEmulator = false;
11
+ this.emulatorHost = "localhost";
12
+ this.emulatorPort = 8080;
13
+ this.debug = false;
14
+ this.projectId = config.projectId;
15
+ this.databaseId = config.databaseId || "(default)";
16
+ this.debug = debug;
17
+ if (config.useEmulator) {
18
+ this.useEmulator = true;
19
+ this.emulatorHost = config.emulatorHost || "localhost";
20
+ this.emulatorPort = config.emulatorPort || 8080;
21
+ }
22
+ }
23
+ /**
24
+ * Get Firestore base URL (without document path)
25
+ */
26
+ getBasePath() {
27
+ const baseUrl = this.useEmulator
28
+ ? `http://${this.emulatorHost}:${this.emulatorPort}/v1`
29
+ : "https://firestore.googleapis.com/v1";
30
+ const path = `${baseUrl}/projects/${this.projectId}/databases/${this.databaseId}/documents`;
31
+ if (this.debug) {
32
+ console.log(`Generated base path: ${path}`);
33
+ }
34
+ return path;
35
+ }
36
+ /**
37
+ * Get base URL + collection path for a collection root
38
+ * @param path Collection path (ex: "users" or "users/uid/posts")
39
+ */
40
+ getCollectionPath(path) {
41
+ // Remove leading and trailing slashes
42
+ const cleanPath = path.replace(/^\/+|\/+$/g, '');
43
+ const fullPath = `${this.getBasePath()}/${cleanPath}`;
44
+ if (this.debug) {
45
+ console.log(`Generated collection path: ${fullPath}`);
46
+ }
47
+ return fullPath;
48
+ }
49
+ /**
50
+ * Get the complete URL for a document
51
+ * @param collectionPath Collection path
52
+ * @param documentId Document ID
53
+ */
54
+ getDocumentPath(collectionPath, documentId) {
55
+ const cleanCollectionPath = collectionPath.replace(/^\/+|\/+$/g, '');
56
+ const path = `${this.getBasePath()}/${cleanCollectionPath}/${documentId}`;
57
+ if (this.debug) {
58
+ console.log(`Generated document path: ${path}`);
59
+ }
60
+ return path;
61
+ }
62
+ /**
63
+ * Get URL for query execution
64
+ * @param path Collection path (ex: "users" or "users/uid/posts")
65
+ * @returns URL for query execution, collection ID, and parent path (if needed)
66
+ */
67
+ getQueryPath(path) {
68
+ // パスをセグメントに分割
69
+ const segments = path.replace(/^\/+|\/+$/g, '').split('/');
70
+ // 単一コレクションの場合
71
+ if (segments.length === 1) {
72
+ const url = `${this.getBasePath()}:runQuery`;
73
+ if (this.debug) {
74
+ console.log(`Generated query URL (single collection): ${url}`);
75
+ console.log(`Collection ID: ${segments[0]}`);
76
+ }
77
+ return {
78
+ url,
79
+ collectionId: segments[0]
80
+ };
81
+ }
82
+ // ネストしたコレクションパスの場合 (例: "users/uid/posts")
83
+ const collectionId = segments[segments.length - 1];
84
+ const parentSegments = segments.slice(0, -1);
85
+ const parentPath = parentSegments.join('/');
86
+ // ベースURLでネストしたドキュメントまでのパスを取得
87
+ const url = `${this.getBasePath()}:runQuery`;
88
+ if (this.debug) {
89
+ console.log(`Generated query URL (nested collection): ${url}`);
90
+ console.log(`Collection ID: ${collectionId}`);
91
+ console.log(`Parent path: ${parentPath}`);
92
+ }
93
+ return {
94
+ url,
95
+ collectionId,
96
+ parentPath
97
+ };
98
+ }
99
+ /**
100
+ * Get reference path for parent document (for query construction)
101
+ * @param parentPath Parent document path
102
+ */
103
+ getParentReference(parentPath) {
104
+ return `projects/${this.projectId}/databases/${this.databaseId}/documents/${parentPath}`;
105
+ }
106
+ /**
107
+ * Get URL for runQuery
108
+ * @param collectionPath Collection path
109
+ * @returns URL for executing runQuery
110
+ */
111
+ getRunQueryPath(collectionPath) {
112
+ // コレクションパス情報を取得
113
+ const { collectionId, parentPath } = this.getQueryPath(collectionPath);
114
+ // parentPathがある場合は、親ドキュメントパスを使用してURLを作成
115
+ if (parentPath) {
116
+ // getBasePathからベースURLを取得
117
+ const baseUrl = this.getBasePath().replace(/\/documents$/, '');
118
+ // 親ドキュメントパスを含むrunQueryのURL
119
+ const runQueryUrl = `${baseUrl}/documents/${parentPath}:runQuery`;
120
+ if (this.debug) {
121
+ console.log(`Generated runQuery URL for nested collection: ${runQueryUrl}`);
122
+ console.log(`Collection ID: ${collectionId}`);
123
+ }
124
+ return runQueryUrl;
125
+ }
126
+ // トップレベルコレクションの場合は、ベースパスを使用
127
+ const baseUrl = this.getBasePath();
128
+ const runQueryUrl = `${baseUrl}:runQuery`;
129
+ if (this.debug) {
130
+ console.log(`Generated runQuery URL for top-level collection: ${runQueryUrl}`);
131
+ console.log(`Collection ID: ${collectionId}`);
132
+ }
133
+ return runQueryUrl;
134
+ }
135
+ }
136
+ /**
137
+ * Create an instance of FirestorePath class
138
+ * @param config Firestore configuration
139
+ * @param debug Debug mode
140
+ */
141
+ export function createFirestorePath(config, debug = false) {
142
+ return new FirestorePath(config, debug);
143
+ }
144
+ /**
145
+ * Get Firestore base path URL (without path)
146
+ * @param projectId Project ID
147
+ * @param databaseId Database ID (defaults to default)
148
+ * @param config Firestore configuration (for emulator settings)
149
+ * @returns Firestore base path URL (without path)
150
+ */
151
+ export function getFirestoreBasePath(projectId, databaseId, config) {
152
+ // Use emulator URL for emulator mode
153
+ if (config?.useEmulator) {
154
+ const host = config.emulatorHost || "127.0.0.1";
155
+ const port = config.emulatorPort || 8080;
156
+ return `http://${host}:${port}/v1/projects/${projectId}/databases/${databaseId || "(default)"}/documents`;
157
+ }
158
+ // Use normal production environment URL
159
+ return `https://firestore.googleapis.com/v1/projects/${projectId}/databases/${databaseId || "(default)"}/documents`;
160
+ }
161
+ /**
162
+ * Extract document ID from document path
163
+ * @param path Document path
164
+ * @returns Document ID
165
+ */
166
+ export function getDocumentId(path) {
167
+ const parts = path.split("/");
168
+ return parts[parts.length - 1];
169
+ }