@shisyamo4131/air-firebase-v2-client-adapter 1.0.0 → 1.0.1

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/error.js +139 -0
  2. package/package.json +3 -2
package/error.js ADDED
@@ -0,0 +1,139 @@
1
+ export class ClientAdapterError extends Error {
2
+ constructor(errorInfo, originalError = null) {
3
+ super(errorInfo.message);
4
+ this.name = "ClientAdapterError";
5
+ this.code = errorInfo.code;
6
+ this.userMessage = errorInfo.userMessage;
7
+ this.originalError = originalError;
8
+ }
9
+
10
+ /**
11
+ * Checks if the error belongs to a specific category.
12
+ * @param {string} category
13
+ * @returns {boolean} - True if the error code starts with the category, otherwise false.
14
+ */
15
+ isCategory(category) {
16
+ return this.code.startsWith(category);
17
+ }
18
+
19
+ /**
20
+ * Returns a user-friendly message.
21
+ * @returns {string} - The user-friendly error message.
22
+ */
23
+ getUserMessage() {
24
+ return this.userMessage || this.message;
25
+ }
26
+ }
27
+
28
+ /*****************************************************************************
29
+ * DEFINED ERROR CODES
30
+ *****************************************************************************/
31
+ export const ERRORS = {
32
+ // 入力検証エラー (VALIDATION)
33
+ VALIDATION_MISSING_DOC_ID: {
34
+ code: "VALIDATION/MISSING_DOC_ID",
35
+ message: "docId is required",
36
+ userMessage: "ドキュメントIDが指定されていません",
37
+ },
38
+ VALIDATION_MISSING_TRANSACTION: {
39
+ code: "VALIDATION/MISSING_TRANSACTION",
40
+ message: "transaction is required",
41
+ userMessage: "トランザクションが必要です",
42
+ },
43
+ VALIDATION_INVALID_CALLBACK: {
44
+ code: "VALIDATION/INVALID_CALLBACK",
45
+ message: "callback must be a function",
46
+ userMessage: "コールバック関数が不正です",
47
+ },
48
+ VALIDATION_INVALID_ORDERBY_DIRECTION: {
49
+ code: "VALIDATION/INVALID_ORDERBY_DIRECTION",
50
+ message: "orderBy direction must be 'asc' or 'desc'",
51
+ userMessage: "orderBy の方向は 'asc' または 'desc' でなければなりません",
52
+ },
53
+ VALIDATION_INVALID_QUERY_TYPE: {
54
+ code: "VALIDATION/INVALID_QUERY_TYPE",
55
+ message: "invalid query type",
56
+ userMessage: "クエリタイプが不正です",
57
+ },
58
+ VALIDATION_INVALID_LIMIT: {
59
+ code: "VALIDATION/INVALID_LIMIT",
60
+ message: "limit must be a positive number",
61
+ userMessage: "limit は正の数でなければなりません",
62
+ },
63
+ VALIDATION_INVALID_CONSTRAINTS: {
64
+ code: "VALIDATION/INVALID_CONSTRAINTS",
65
+ message: "invalid query constraints",
66
+ userMessage: "クエリ条件が不正です",
67
+ },
68
+ VALIDATION_EMPTY_SEARCH_STRING: {
69
+ code: "VALIDATION/EMPTY_SEARCH_STRING",
70
+ message: "search string cannot be empty",
71
+ userMessage: "検索文字列を入力してください",
72
+ },
73
+
74
+ // データベース操作エラー (DATABASE)
75
+ DATABASE_DOCUMENT_NOT_FOUND: {
76
+ code: "DATABASE/DOCUMENT_NOT_FOUND",
77
+ message: "document not found",
78
+ userMessage: "指定されたドキュメントが見つかりません",
79
+ },
80
+ DATABASE_TRANSACTION_FAILED: {
81
+ code: "DATABASE/TRANSACTION_FAILED",
82
+ message: "transaction failed",
83
+ userMessage: "データの更新に失敗しました",
84
+ },
85
+ DATABASE_QUERY_FAILED: {
86
+ code: "DATABASE/QUERY_FAILED",
87
+ message: "query execution failed",
88
+ userMessage: "データの取得に失敗しました",
89
+ },
90
+ DATABASE_CONNECTION_ERROR: {
91
+ code: "DATABASE/CONNECTION_ERROR",
92
+ message: "database connection error",
93
+ userMessage: "データベースに接続できません",
94
+ },
95
+
96
+ // ビジネスロジックエラー (BUSINESS)
97
+ BUSINESS_CHILD_DOCUMENTS_EXIST: {
98
+ code: "BUSINESS/CHILD_DOCUMENTS_EXIST",
99
+ message: "child documents exist",
100
+ userMessage: "関連するドキュメントが存在するため削除できません",
101
+ },
102
+ BUSINESS_AUTONUMBER_DOCUMENT_NOT_FOUND: {
103
+ code: "BUSINESS/AUTONUMBER_DOCUMENT_NOT_FOUND",
104
+ message: "autonumber document not found",
105
+ userMessage: "自動採番ドキュメントが見つかりません",
106
+ },
107
+ BUSINESS_AUTONUMBER_DISABLED: {
108
+ code: "BUSINESS/AUTONUMBER_DISABLED",
109
+ message: "autonumber is disabled",
110
+ userMessage: "自動採番が無効になっています",
111
+ },
112
+ BUSINESS_AUTONUMBER_MAX_REACHED: {
113
+ code: "BUSINESS/AUTONUMBER_MAX_REACHED",
114
+ message: "autonumber maximum reached",
115
+ userMessage: "採番の上限に達しています",
116
+ },
117
+ BUSINESS_DOCUMENT_UNDELETABLE: {
118
+ code: "BUSINESS/DOCUMENT_UNDELETABLE",
119
+ message: "document cannot be deleted",
120
+ userMessage: "このドキュメントは削除できません",
121
+ },
122
+
123
+ // システムエラー (SYSTEM)
124
+ SYSTEM_AUTHENTICATION_NOT_INITIALIZED: {
125
+ code: "SYSTEM/AUTHENTICATION_NOT_INITIALIZED",
126
+ message: "Authentication not initialized",
127
+ userMessage: "認証が初期化されていません",
128
+ },
129
+ SYSTEM_FIRESTORE_NOT_INITIALIZED: {
130
+ code: "SYSTEM/FIRESTORE_NOT_INITIALIZED",
131
+ message: "Firestore not initialized",
132
+ userMessage: "データベースが初期化されていません",
133
+ },
134
+ SYSTEM_UNKNOWN_ERROR: {
135
+ code: "SYSTEM/UNKNOWN_ERROR",
136
+ message: "unknown error occurred",
137
+ userMessage: "予期しないエラーが発生しました",
138
+ },
139
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-firebase-v2-client-adapter",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "client adapter for FireModel",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -8,7 +8,8 @@
8
8
  ".": "./index.js"
9
9
  },
10
10
  "files": [
11
- "index.js"
11
+ "index.js",
12
+ "error.js"
12
13
  ],
13
14
  "keywords": [
14
15
  "firebase",