@cougargrades/firebase-rest-firestore 1.6.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.
- package/README.ja.md +294 -0
- package/README.md +393 -0
- package/dist/cjs/client.d.ts +417 -0
- package/dist/cjs/client.js +1078 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +43 -0
- package/dist/cjs/types.d.ts +127 -0
- package/dist/cjs/types.js +86 -0
- package/dist/cjs/utils/auth.d.ts +13 -0
- package/dist/cjs/utils/auth.js +94 -0
- package/dist/cjs/utils/config.d.ts +6 -0
- package/dist/cjs/utils/config.js +14 -0
- package/dist/cjs/utils/converter.d.ts +27 -0
- package/dist/cjs/utils/converter.js +132 -0
- package/dist/cjs/utils/path.d.ts +73 -0
- package/dist/cjs/utils/path.js +176 -0
- package/dist/esm/client.d.ts +417 -0
- package/dist/esm/client.js +1066 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/types.d.ts +127 -0
- package/dist/esm/types.js +81 -0
- package/dist/esm/utils/auth.d.ts +13 -0
- package/dist/esm/utils/auth.js +57 -0
- package/dist/esm/utils/config.d.ts +6 -0
- package/dist/esm/utils/config.js +11 -0
- package/dist/esm/utils/converter.d.ts +27 -0
- package/dist/esm/utils/converter.js +126 -0
- package/dist/esm/utils/path.d.ts +73 -0
- package/dist/esm/utils/path.js +169 -0
- package/dist/types/client.d.ts +417 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/types.d.ts +127 -0
- package/dist/types/utils/auth.d.ts +13 -0
- package/dist/types/utils/config.d.ts +6 -0
- package/dist/types/utils/converter.d.ts +27 -0
- package/dist/types/utils/path.d.ts +73 -0
- package/package.json +65 -0
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
* A reference to a document. For example: `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
|
|
16
|
+
* Used to represent document references globally and not connected to any particular client.
|
|
17
|
+
*/
|
|
18
|
+
export declare class LiteralDocumentReference {
|
|
19
|
+
referenceValue: string;
|
|
20
|
+
constructor(options: Pick<LiteralDocumentReference, "referenceValue">);
|
|
21
|
+
/**
|
|
22
|
+
* The pattern for globally unique Firestore Document Reference paths
|
|
23
|
+
*/
|
|
24
|
+
private static pattern;
|
|
25
|
+
/**
|
|
26
|
+
* Parse using URLPattern, which is a relatively new addition to the standard.
|
|
27
|
+
* See: https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol
|
|
28
|
+
* Added in Node.js v23: https://nodejs.org/api/url.html#class-urlpattern
|
|
29
|
+
* Baseline 2025 in browsers: https://developer.mozilla.org/en-US/docs/Web/API/URLPattern/protocol
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
private parse;
|
|
33
|
+
/**
|
|
34
|
+
* Get Project ID
|
|
35
|
+
*/
|
|
36
|
+
get project_id(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get Database ID
|
|
39
|
+
* Ex: `(default)`
|
|
40
|
+
*/
|
|
41
|
+
get database_id(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get document ID
|
|
44
|
+
*/
|
|
45
|
+
get id(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get the collection ID
|
|
48
|
+
*/
|
|
49
|
+
get collectionPath(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Get document path
|
|
52
|
+
*/
|
|
53
|
+
get path(): string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A geo point value representing a point on the surface of Earth.
|
|
57
|
+
*/
|
|
58
|
+
export declare class LiteralGeoPointValue {
|
|
59
|
+
geoPointValue: {
|
|
60
|
+
/**
|
|
61
|
+
* The latitude in degrees. It must be in the range [-90.0, +90.0].
|
|
62
|
+
*/
|
|
63
|
+
latitude: number;
|
|
64
|
+
/**
|
|
65
|
+
* The longitude in degrees. It must be in the range [-180.0, +180.0].
|
|
66
|
+
*/
|
|
67
|
+
longitude: number;
|
|
68
|
+
};
|
|
69
|
+
constructor(options: Pick<LiteralGeoPointValue, "geoPointValue">);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Firestoreの値型定義
|
|
73
|
+
* See: https://github.com/googleapis/google-api-nodejs-client/blob/5870dfe31f4885eebc82c19f7471c50403308f26/src/apis/firestore/v1.ts#L2246
|
|
74
|
+
*/
|
|
75
|
+
export type FirestoreFieldValue = {
|
|
76
|
+
stringValue: string;
|
|
77
|
+
} | {
|
|
78
|
+
integerValue: number;
|
|
79
|
+
} | {
|
|
80
|
+
doubleValue: number;
|
|
81
|
+
} | {
|
|
82
|
+
booleanValue: boolean;
|
|
83
|
+
} | {
|
|
84
|
+
nullValue: null;
|
|
85
|
+
} | {
|
|
86
|
+
timestampValue: string;
|
|
87
|
+
} | Pick<LiteralGeoPointValue, 'geoPointValue'> | Pick<LiteralDocumentReference, 'referenceValue'> | {
|
|
88
|
+
mapValue: {
|
|
89
|
+
fields: Record<string, FirestoreFieldValue>;
|
|
90
|
+
};
|
|
91
|
+
} | {
|
|
92
|
+
arrayValue: {
|
|
93
|
+
values: FirestoreFieldValue[];
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Firestoreドキュメント型
|
|
98
|
+
*/
|
|
99
|
+
export interface FirestoreDocument {
|
|
100
|
+
name?: string;
|
|
101
|
+
fields: Record<string, FirestoreFieldValue>;
|
|
102
|
+
createTime?: string;
|
|
103
|
+
updateTime?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Firestoreレスポンス型
|
|
107
|
+
*/
|
|
108
|
+
export interface FirestoreResponse {
|
|
109
|
+
name: string;
|
|
110
|
+
fields?: Record<string, FirestoreFieldValue>;
|
|
111
|
+
createTime?: string;
|
|
112
|
+
updateTime?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* クエリオプション型
|
|
116
|
+
*/
|
|
117
|
+
export interface QueryOptions {
|
|
118
|
+
where?: Array<{
|
|
119
|
+
field: string;
|
|
120
|
+
op: string;
|
|
121
|
+
value: any;
|
|
122
|
+
}>;
|
|
123
|
+
orderBy?: string;
|
|
124
|
+
orderDirection?: string;
|
|
125
|
+
limit?: number;
|
|
126
|
+
offset?: number;
|
|
127
|
+
}
|
|
@@ -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,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,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;
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cougargrades/firebase-rest-firestore",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Firebase Firestore REST API client for Edge runtime environments",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
14
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
15
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
16
|
+
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly --declarationDir dist/types",
|
|
17
|
+
"watch": "concurrently \"npm run watch:esm\" \"npm run watch:cjs\" \"npm run watch:types\"",
|
|
18
|
+
"watch:esm": "tsc -p tsconfig.esm.json --watch",
|
|
19
|
+
"watch:cjs": "tsc -p tsconfig.cjs.json --watch",
|
|
20
|
+
"watch:types": "tsc -p tsconfig.json --emitDeclarationOnly --declarationDir dist/types --watch",
|
|
21
|
+
|
|
22
|
+
"setup:local:env": "cp .env.local.example .env && echo 'Created .env file from local example.'",
|
|
23
|
+
"emulator:start": "cd test/emulator && firebase emulators:start -P demo-test-project",
|
|
24
|
+
"emulator:stop": "npx kill-port -y 4089 8089 9089",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"test:emulator": "bash test/scripts/test-with-emulator.sh"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"firebase",
|
|
30
|
+
"firestore",
|
|
31
|
+
"rest",
|
|
32
|
+
"api",
|
|
33
|
+
"edge",
|
|
34
|
+
"cloudflare",
|
|
35
|
+
"workers",
|
|
36
|
+
"vercel"
|
|
37
|
+
],
|
|
38
|
+
"author": "",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"jose": "^4.14.4",
|
|
42
|
+
"urlpattern-polyfill": "^10.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
46
|
+
"@semantic-release/git": "^10.0.1",
|
|
47
|
+
"@types/node": "^18.16.0",
|
|
48
|
+
"concurrently": "^8.2.2",
|
|
49
|
+
"dotenv": "^16.4.7",
|
|
50
|
+
"semantic-release": "^24.2.3",
|
|
51
|
+
"typescript": "^5.0.4",
|
|
52
|
+
"vitest": "^3.0.9"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.8.1"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/cougargrades/firebase-rest-firestore.git"
|
|
60
|
+
},
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/cougargrades/firebase-rest-firestore/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/cougargrades/firebase-rest-firestore#readme"
|
|
65
|
+
}
|