@shisyamo4131/air-firebase-v2-client-adapter 1.0.1 → 2.0.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 (2) hide show
  1. package/index.js +43 -1
  2. package/package.json +7 -1
package/index.js CHANGED
@@ -15,7 +15,6 @@ import {
15
15
  collectionGroup,
16
16
  onSnapshot,
17
17
  getFirestore,
18
- increment as FieldValue_increment,
19
18
  } from "firebase/firestore";
20
19
  import { getAuth } from "firebase/auth";
21
20
  import { ClientAdapterError, ERRORS } from "./error.js";
@@ -69,6 +68,40 @@ class ClientAdapter {
69
68
  return ClientAdapter.firestore;
70
69
  }
71
70
 
71
+ /**
72
+ * 指定されたドキュメントIDからFirestoreのドキュメント参照を取得します。
73
+ * - コンバーターを適用したDocumentReferenceを返します。
74
+ * - このメソッドはFireModelクラスから静的に呼び出されることを想定しています。
75
+ *
76
+ * @param {Object} args - パラメータオブジェクト
77
+ * @param {string} args.docId - ドキュメントID(必須)
78
+ * @param {string|null} [args.prefix=null] - パスのプレフィックス(任意)
79
+ * @returns {DocumentReference} Firestoreのドキュメント参照
80
+ * @throws {Error} `docId` が指定されていない場合
81
+ */
82
+ getDocRef({ docId, prefix = null } = {}) {
83
+ if (!docId) {
84
+ throw new ClientAdapterError(ERRORS.VALIDATION_MISSING_DOC_ID);
85
+ }
86
+
87
+ try {
88
+ const collectionPath = this.constructor.getCollectionPath(prefix);
89
+ const colRef = collection(
90
+ ClientAdapter.firestore,
91
+ collectionPath
92
+ ).withConverter(this.constructor.converter());
93
+
94
+ return doc(colRef, docId);
95
+ } catch (err) {
96
+ if (err instanceof ClientAdapterError) {
97
+ throw err;
98
+ } else {
99
+ this._outputErrorConsole("getDocRef", err);
100
+ throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
101
+ }
102
+ }
103
+ }
104
+
72
105
  /**
73
106
  * Assigns an autonumber to the instance using a Firestore transaction.
74
107
  * - Retrieves the current autonumber doc from the `Autonumbers` collection.
@@ -991,6 +1024,15 @@ class ClientAdapter {
991
1024
  }
992
1025
  }
993
1026
  }
1027
+
1028
+ /**
1029
+ * Firestore トランザクションを実行します。
1030
+ * @param {Function} updateFunction - トランザクション内で実行する関数
1031
+ * @returns {Promise<any>} トランザクションの結果
1032
+ */
1033
+ async runTransaction(updateFunction) {
1034
+ return await runTransaction(this.firestore, updateFunction);
1035
+ }
994
1036
  }
995
1037
 
996
1038
  export default ClientAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-firebase-v2-client-adapter",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "client adapter for FireModel",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -23,6 +23,12 @@
23
23
  "type": "git",
24
24
  "url": "https://github.com/shisyamo4131/air-firebase-v2-client-adapter.git"
25
25
  },
26
+ "scripts": {
27
+ "dev:publish": "npm version prerelease --preid=dev && npm publish --tag dev",
28
+ "release:patch": "npm version patch && npm publish",
29
+ "release:minor": "npm version minor && npm publish",
30
+ "release:major": "npm version major && npm publish"
31
+ },
26
32
  "publishConfig": {
27
33
  "access": "public"
28
34
  },