firebase-rest-firestore 1.2.0 → 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.
Files changed (52) hide show
  1. package/README.md +37 -0
  2. package/dist/cjs/client.d.ts +454 -0
  3. package/dist/cjs/client.js +1192 -0
  4. package/dist/cjs/field-value.d.ts +22 -0
  5. package/dist/cjs/field-value.js +31 -0
  6. package/dist/{index.d.ts → cjs/index.d.ts} +2 -1
  7. package/dist/{index.js → cjs/index.js} +4 -2
  8. package/dist/cjs/types.d.ts +146 -0
  9. package/dist/cjs/types.js +75 -0
  10. package/dist/cjs/utils/auth.d.ts +13 -0
  11. package/dist/{utils → cjs/utils}/auth.js +14 -10
  12. package/dist/cjs/utils/config.d.ts +6 -0
  13. package/dist/{utils → cjs/utils}/config.js +0 -12
  14. package/dist/cjs/utils/converter.d.ts +57 -0
  15. package/dist/cjs/utils/converter.js +224 -0
  16. package/dist/cjs/utils/path.d.ts +73 -0
  17. package/dist/cjs/utils/path.js +176 -0
  18. package/dist/esm/client.d.ts +454 -0
  19. package/dist/esm/client.js +1180 -0
  20. package/dist/esm/field-value.d.ts +22 -0
  21. package/dist/esm/field-value.js +27 -0
  22. package/dist/esm/index.d.ts +8 -0
  23. package/dist/esm/index.js +13 -0
  24. package/dist/esm/types.d.ts +146 -0
  25. package/dist/esm/types.js +70 -0
  26. package/dist/esm/utils/auth.d.ts +13 -0
  27. package/dist/esm/utils/auth.js +57 -0
  28. package/dist/esm/utils/config.d.ts +6 -0
  29. package/dist/esm/utils/config.js +11 -0
  30. package/dist/esm/utils/converter.d.ts +57 -0
  31. package/dist/esm/utils/converter.js +216 -0
  32. package/dist/esm/utils/path.d.ts +73 -0
  33. package/dist/esm/utils/path.js +169 -0
  34. package/dist/types/client.d.ts +454 -0
  35. package/dist/types/field-value.d.ts +22 -0
  36. package/dist/types/index.d.ts +8 -0
  37. package/dist/types/types.d.ts +146 -0
  38. package/dist/types/utils/auth.d.ts +13 -0
  39. package/dist/types/utils/config.d.ts +6 -0
  40. package/dist/types/utils/converter.d.ts +57 -0
  41. package/dist/types/utils/path.d.ts +73 -0
  42. package/package.json +19 -5
  43. package/dist/client.d.ts +0 -381
  44. package/dist/client.js +0 -915
  45. package/dist/types.d.ts +0 -65
  46. package/dist/types.js +0 -2
  47. package/dist/utils/auth.d.ts +0 -13
  48. package/dist/utils/config.d.ts +0 -13
  49. package/dist/utils/converter.d.ts +0 -27
  50. package/dist/utils/converter.js +0 -113
  51. package/dist/utils/path.d.ts +0 -14
  52. package/dist/utils/path.js +0 -27
package/dist/types.d.ts DELETED
@@ -1,65 +0,0 @@
1
- /**
2
- * Firestoreクライアントの設定インターフェース
3
- */
4
- export interface FirestoreConfig {
5
- projectId: string;
6
- privateKey: string;
7
- clientEmail: string;
8
- databaseId?: string;
9
- }
10
- /**
11
- * Firestoreの値型定義
12
- */
13
- export type FirestoreFieldValue = {
14
- stringValue: string;
15
- } | {
16
- integerValue: number;
17
- } | {
18
- doubleValue: number;
19
- } | {
20
- booleanValue: boolean;
21
- } | {
22
- nullValue: null;
23
- } | {
24
- timestampValue: string;
25
- } | {
26
- mapValue: {
27
- fields: Record<string, FirestoreFieldValue>;
28
- };
29
- } | {
30
- arrayValue: {
31
- values: FirestoreFieldValue[];
32
- };
33
- };
34
- /**
35
- * Firestoreドキュメント型
36
- */
37
- export interface FirestoreDocument {
38
- name?: string;
39
- fields: Record<string, FirestoreFieldValue>;
40
- createTime?: string;
41
- updateTime?: string;
42
- }
43
- /**
44
- * Firestoreレスポンス型
45
- */
46
- export interface FirestoreResponse {
47
- name: string;
48
- fields?: Record<string, FirestoreFieldValue>;
49
- createTime?: string;
50
- updateTime?: string;
51
- }
52
- /**
53
- * クエリオプション型
54
- */
55
- export interface QueryOptions {
56
- where?: Array<{
57
- field: string;
58
- op: string;
59
- value: any;
60
- }>;
61
- orderBy?: string;
62
- orderDirection?: string;
63
- limit?: number;
64
- offset?: number;
65
- }
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +0,0 @@
1
- import { FirestoreConfig } from "../types";
2
- /**
3
- * JWT(JSON Web Token)を作成する関数
4
- * @param config Firestore設定
5
- * @returns JWT文字列
6
- */
7
- export declare function createJWT(config: FirestoreConfig): Promise<string>;
8
- /**
9
- * Firestoreの認証トークンを取得する関数
10
- * @param config Firestore設定
11
- * @returns アクセストークン
12
- */
13
- export declare function getFirestoreToken(config: FirestoreConfig): Promise<string>;
@@ -1,13 +0,0 @@
1
- import { FirestoreConfig } from "../types";
2
- /**
3
- * 秘密鍵の文字列内にある改行コードのエスケープシーケンスを実際の改行に変換する
4
- * @param privateKey 変換する秘密鍵文字列
5
- * @returns 変換後の秘密鍵文字列
6
- */
7
- export declare function formatPrivateKey(privateKey: string): string;
8
- /**
9
- * FirestoreConfigオブジェクトの秘密鍵をフォーマットする
10
- * @param config 元のconfigオブジェクト
11
- * @returns 秘密鍵をフォーマットしたconfigオブジェクト
12
- */
13
- export declare function formatConfig(config: FirestoreConfig): FirestoreConfig;
@@ -1,27 +0,0 @@
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
- };
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToFirestoreValue = convertToFirestoreValue;
4
- exports.convertFromFirestoreValue = convertFromFirestoreValue;
5
- exports.convertToFirestoreDocument = convertToFirestoreDocument;
6
- exports.convertFromFirestoreDocument = convertFromFirestoreDocument;
7
- const path_1 = require("./path");
8
- /**
9
- * JSの値をFirestore形式に変換する
10
- * @param value 変換する値
11
- * @returns Firestore形式の値
12
- */
13
- function convertToFirestoreValue(value) {
14
- if (value instanceof Date) {
15
- return { timestampValue: value.toISOString() };
16
- }
17
- else if (typeof value === "string") {
18
- return { stringValue: value };
19
- }
20
- else if (typeof value === "number") {
21
- return Number.isInteger(value)
22
- ? { integerValue: value }
23
- : { doubleValue: value };
24
- }
25
- else if (typeof value === "boolean") {
26
- return { booleanValue: value };
27
- }
28
- else if (value === null || value === undefined) {
29
- return { nullValue: null };
30
- }
31
- else if (Array.isArray(value)) {
32
- return {
33
- arrayValue: {
34
- values: value.map(item => convertToFirestoreValue(item)),
35
- },
36
- };
37
- }
38
- else if (typeof value === "object") {
39
- const fields = Object.entries(value).reduce((acc, [key, val]) => ({
40
- ...acc,
41
- [key]: convertToFirestoreValue(val),
42
- }), {});
43
- return { mapValue: { fields } };
44
- }
45
- // デフォルトは文字列化
46
- return { stringValue: String(value) };
47
- }
48
- /**
49
- * Firestore形式からJSの値に変換する
50
- * @param firestoreValue Firestore形式の値
51
- * @returns JS形式の値
52
- */
53
- function convertFromFirestoreValue(firestoreValue) {
54
- if ("stringValue" in firestoreValue) {
55
- return firestoreValue.stringValue;
56
- }
57
- else if ("integerValue" in firestoreValue) {
58
- return Number(firestoreValue.integerValue);
59
- }
60
- else if ("doubleValue" in firestoreValue) {
61
- return firestoreValue.doubleValue;
62
- }
63
- else if ("booleanValue" in firestoreValue) {
64
- return firestoreValue.booleanValue;
65
- }
66
- else if ("nullValue" in firestoreValue) {
67
- return null;
68
- }
69
- else if ("timestampValue" in firestoreValue) {
70
- return new Date(firestoreValue.timestampValue);
71
- }
72
- else if ("mapValue" in firestoreValue && firestoreValue.mapValue.fields) {
73
- return Object.entries(firestoreValue.mapValue.fields).reduce((acc, [key, val]) => ({
74
- ...acc,
75
- [key]: convertFromFirestoreValue(val),
76
- }), {});
77
- }
78
- else if ("arrayValue" in firestoreValue &&
79
- firestoreValue.arrayValue.values) {
80
- return firestoreValue.arrayValue.values.map(convertFromFirestoreValue);
81
- }
82
- return null;
83
- }
84
- /**
85
- * オブジェクトをFirestoreドキュメント形式に変換
86
- * @param data 変換するオブジェクト
87
- * @returns Firestoreドキュメント
88
- */
89
- function convertToFirestoreDocument(data) {
90
- return {
91
- fields: Object.entries(data).reduce((acc, [key, value]) => ({
92
- ...acc,
93
- [key]: convertToFirestoreValue(value),
94
- }), {}),
95
- };
96
- }
97
- /**
98
- * Firestoreドキュメントをオブジェクトに変換
99
- * @param doc Firestoreレスポンス
100
- * @returns 変換されたオブジェクト(idプロパティ付き)
101
- */
102
- function convertFromFirestoreDocument(doc) {
103
- if (!doc.fields)
104
- return { id: (0, path_1.getDocumentId)(doc.name) };
105
- const result = Object.entries(doc.fields).reduce((acc, [key, value]) => ({
106
- ...acc,
107
- [key]: convertFromFirestoreValue(value),
108
- }), {});
109
- return {
110
- ...result,
111
- id: (0, path_1.getDocumentId)(doc.name),
112
- };
113
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Firestoreのベースパスを取得
3
- * @param projectId プロジェクトID
4
- * @param collectionName コレクション名(省略可)
5
- * @param databaseId データベースID(省略時は'(default)')
6
- * @returns Firestoreのベースパス
7
- */
8
- export declare function getFirestoreBasePath(projectId: string, collectionName?: string, databaseId?: string): string;
9
- /**
10
- * ドキュメントパスからIDを抽出
11
- * @param path ドキュメントパス
12
- * @returns ドキュメントID
13
- */
14
- export declare function getDocumentId(path?: string): string;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFirestoreBasePath = getFirestoreBasePath;
4
- exports.getDocumentId = getDocumentId;
5
- /**
6
- * Firestoreのベースパスを取得
7
- * @param projectId プロジェクトID
8
- * @param collectionName コレクション名(省略可)
9
- * @param databaseId データベースID(省略時は'(default)')
10
- * @returns Firestoreのベースパス
11
- */
12
- function getFirestoreBasePath(projectId, collectionName, databaseId) {
13
- const dbId = databaseId || "(default)";
14
- const basePath = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/${dbId}/documents`;
15
- return collectionName ? `${basePath}/${collectionName}` : basePath;
16
- }
17
- /**
18
- * ドキュメントパスからIDを抽出
19
- * @param path ドキュメントパス
20
- * @returns ドキュメントID
21
- */
22
- function getDocumentId(path) {
23
- if (!path)
24
- return "";
25
- const pathParts = path.split("/");
26
- return pathParts[pathParts.length - 1];
27
- }