@shisyamo4131/air-firebase-v2-client-adapter 2.1.1 → 2.1.3-dev.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/error.js +5 -0
- package/index.js +30 -28
- package/package.json +1 -1
package/error.js
CHANGED
|
@@ -70,6 +70,11 @@ export const ERRORS = {
|
|
|
70
70
|
message: "search string cannot be empty",
|
|
71
71
|
userMessage: "検索文字列を入力してください",
|
|
72
72
|
},
|
|
73
|
+
VALIDATION_FIELD_ERROR: {
|
|
74
|
+
code: "VALIDATION/FIELD_ERROR",
|
|
75
|
+
message: "validation failed",
|
|
76
|
+
userMessage: "入力内容に誤りがあります",
|
|
77
|
+
},
|
|
73
78
|
|
|
74
79
|
// データベース操作エラー (DATABASE)
|
|
75
80
|
DATABASE_DOCUMENT_NOT_FOUND: {
|
package/index.js
CHANGED
|
@@ -32,6 +32,7 @@ import { ClientAdapterError, ERRORS } from "./error.js";
|
|
|
32
32
|
class ClientAdapter {
|
|
33
33
|
static firestore = null;
|
|
34
34
|
static auth = null;
|
|
35
|
+
static functions = null; // 2025-12-29 added
|
|
35
36
|
static GeoPoint = null; // 2025-12-29 added
|
|
36
37
|
static httpsCallable = null; // 2025-12-29 added
|
|
37
38
|
|
|
@@ -61,7 +62,7 @@ class ClientAdapter {
|
|
|
61
62
|
get auth() {
|
|
62
63
|
if (!ClientAdapter.auth) {
|
|
63
64
|
throw new ClientAdapterError(
|
|
64
|
-
ERRORS.SYSTEM_AUTHENTICATION_NOT_INITIALIZED
|
|
65
|
+
ERRORS.SYSTEM_AUTHENTICATION_NOT_INITIALIZED,
|
|
65
66
|
);
|
|
66
67
|
}
|
|
67
68
|
return ClientAdapter.auth;
|
|
@@ -80,13 +81,10 @@ class ClientAdapter {
|
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
83
|
* Returns the Functions instance.
|
|
83
|
-
* - 2025-12-
|
|
84
|
+
* - 2025-12-30 modified to return null if not initialized (instead of throwing error)
|
|
84
85
|
*/
|
|
85
86
|
get functions() {
|
|
86
|
-
|
|
87
|
-
throw new ClientAdapterError(ERRORS.SYSTEM_FUNCTIONS_NOT_INITIALIZED);
|
|
88
|
-
}
|
|
89
|
-
return ClientAdapter.functions;
|
|
87
|
+
return ClientAdapter.functions; // ← null を返すように変更(エラーをスローしない)
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
/**
|
|
@@ -131,7 +129,7 @@ class ClientAdapter {
|
|
|
131
129
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
132
130
|
const colRef = collection(
|
|
133
131
|
ClientAdapter.firestore,
|
|
134
|
-
collectionPath
|
|
132
|
+
collectionPath,
|
|
135
133
|
).withConverter(this.constructor.converter());
|
|
136
134
|
|
|
137
135
|
return doc(colRef, docId);
|
|
@@ -173,7 +171,7 @@ class ClientAdapter {
|
|
|
173
171
|
const docSnap = await transaction.get(docRef);
|
|
174
172
|
if (!docSnap.exists()) {
|
|
175
173
|
throw new ClientAdapterError(
|
|
176
|
-
ERRORS.BUSINESS_AUTONUMBER_DOCUMENT_NOT_FOUND
|
|
174
|
+
ERRORS.BUSINESS_AUTONUMBER_DOCUMENT_NOT_FOUND,
|
|
177
175
|
);
|
|
178
176
|
}
|
|
179
177
|
|
|
@@ -300,7 +298,7 @@ class ClientAdapter {
|
|
|
300
298
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
301
299
|
const colRef = collection(
|
|
302
300
|
ClientAdapter.firestore,
|
|
303
|
-
collectionPath
|
|
301
|
+
collectionPath,
|
|
304
302
|
).withConverter(this.constructor.converter());
|
|
305
303
|
const docRef = docId ? doc(colRef, docId) : doc(colRef);
|
|
306
304
|
|
|
@@ -334,9 +332,11 @@ class ClientAdapter {
|
|
|
334
332
|
} catch (err) {
|
|
335
333
|
if (err instanceof ClientAdapterError) {
|
|
336
334
|
throw err;
|
|
335
|
+
} else if (err.name === "ValidationError") {
|
|
336
|
+
throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
|
|
337
337
|
} else {
|
|
338
338
|
this._outputErrorConsole("create", err);
|
|
339
|
-
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
|
|
339
|
+
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -363,7 +363,7 @@ class ClientAdapter {
|
|
|
363
363
|
// Prepare document reference.
|
|
364
364
|
const colRef = collection(
|
|
365
365
|
ClientAdapter.firestore,
|
|
366
|
-
collectionPath
|
|
366
|
+
collectionPath,
|
|
367
367
|
).withConverter(this.constructor.converter());
|
|
368
368
|
const docRef = doc(colRef, docId);
|
|
369
369
|
|
|
@@ -408,7 +408,7 @@ class ClientAdapter {
|
|
|
408
408
|
// Prepare document reference.
|
|
409
409
|
const colRef = collection(
|
|
410
410
|
ClientAdapter.firestore,
|
|
411
|
-
collectionPath
|
|
411
|
+
collectionPath,
|
|
412
412
|
).withConverter(this.constructor.converter());
|
|
413
413
|
const docRef = doc(colRef, docId);
|
|
414
414
|
|
|
@@ -450,7 +450,7 @@ class ClientAdapter {
|
|
|
450
450
|
case "orderBy":
|
|
451
451
|
if (!["asc", "desc"].includes(args[1] || "asc")) {
|
|
452
452
|
throw new ClientAdapterError(
|
|
453
|
-
ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION
|
|
453
|
+
ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION,
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
456
|
result.push(orderBy(args[0], args[1] || "asc"));
|
|
@@ -488,7 +488,7 @@ class ClientAdapter {
|
|
|
488
488
|
// サロゲートペア文字(絵文字など)を除外
|
|
489
489
|
const target = constraints.replace(
|
|
490
490
|
/[\uD800-\uDBFF]|[\uDC00-\uDFFF]|~|\*|\[|\]|\s+/g,
|
|
491
|
-
""
|
|
491
|
+
"",
|
|
492
492
|
);
|
|
493
493
|
|
|
494
494
|
// 1 文字・2 文字のトークンを生成
|
|
@@ -550,7 +550,7 @@ class ClientAdapter {
|
|
|
550
550
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
551
551
|
const colRef = collection(
|
|
552
552
|
ClientAdapter.firestore,
|
|
553
|
-
collectionPath
|
|
553
|
+
collectionPath,
|
|
554
554
|
).withConverter(this.constructor.converter());
|
|
555
555
|
|
|
556
556
|
const queryRef = query(colRef, ...queryConstraints);
|
|
@@ -604,7 +604,7 @@ class ClientAdapter {
|
|
|
604
604
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
605
605
|
const colRef = collection(
|
|
606
606
|
ClientAdapter.firestore,
|
|
607
|
-
collectionPath
|
|
607
|
+
collectionPath,
|
|
608
608
|
).withConverter(this.constructor.converter());
|
|
609
609
|
|
|
610
610
|
const querySnapshotArray = await Promise.all(
|
|
@@ -613,11 +613,11 @@ class ClientAdapter {
|
|
|
613
613
|
return getDocs(q);
|
|
614
614
|
/** transaction.get() が Query に対応した場合は以下を使用 */
|
|
615
615
|
// return transaction ? transaction.get(q) : getDocs(q);
|
|
616
|
-
})
|
|
616
|
+
}),
|
|
617
617
|
);
|
|
618
618
|
|
|
619
619
|
return querySnapshotArray.flatMap((snapshot) =>
|
|
620
|
-
snapshot.docs.map((doc) => doc.data())
|
|
620
|
+
snapshot.docs.map((doc) => doc.data()),
|
|
621
621
|
);
|
|
622
622
|
} catch (err) {
|
|
623
623
|
if (err instanceof ClientAdapterError) {
|
|
@@ -674,7 +674,7 @@ class ClientAdapter {
|
|
|
674
674
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
675
675
|
const colRef = collection(
|
|
676
676
|
ClientAdapter.firestore,
|
|
677
|
-
collectionPath
|
|
677
|
+
collectionPath,
|
|
678
678
|
).withConverter(this.constructor.converter());
|
|
679
679
|
const docRef = doc(colRef, this.docId);
|
|
680
680
|
|
|
@@ -694,9 +694,11 @@ class ClientAdapter {
|
|
|
694
694
|
} catch (err) {
|
|
695
695
|
if (err instanceof ClientAdapterError) {
|
|
696
696
|
throw err;
|
|
697
|
+
} else if (err.name === "ValidationError") {
|
|
698
|
+
throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
|
|
697
699
|
} else {
|
|
698
700
|
this._outputErrorConsole("update", err);
|
|
699
|
-
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
|
|
701
|
+
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
|
|
700
702
|
}
|
|
701
703
|
}
|
|
702
704
|
}
|
|
@@ -832,7 +834,7 @@ class ClientAdapter {
|
|
|
832
834
|
const sourceDocData = sourceDocSnap.data();
|
|
833
835
|
const archiveColRef = collection(
|
|
834
836
|
ClientAdapter.firestore,
|
|
835
|
-
`${collectionPath}_archive
|
|
837
|
+
`${collectionPath}_archive`,
|
|
836
838
|
);
|
|
837
839
|
const archiveDocRef = doc(archiveColRef, this.docId);
|
|
838
840
|
txn.set(archiveDocRef, sourceDocData);
|
|
@@ -911,7 +913,7 @@ class ClientAdapter {
|
|
|
911
913
|
} else {
|
|
912
914
|
return await runTransaction(
|
|
913
915
|
ClientAdapter.firestore,
|
|
914
|
-
performTransaction
|
|
916
|
+
performTransaction,
|
|
915
917
|
);
|
|
916
918
|
}
|
|
917
919
|
} catch (err) {
|
|
@@ -968,7 +970,7 @@ class ClientAdapter {
|
|
|
968
970
|
// const colRef = collection(ClientAdapter.firestore, collectionPath);
|
|
969
971
|
const colRef = collection(
|
|
970
972
|
ClientAdapter.firestore,
|
|
971
|
-
collectionPath
|
|
973
|
+
collectionPath,
|
|
972
974
|
).withConverter(this.constructor.converter());
|
|
973
975
|
const docRef = doc(colRef, docId);
|
|
974
976
|
this.listener = onSnapshot(docRef, (docSnapshot) => {
|
|
@@ -1006,7 +1008,7 @@ class ClientAdapter {
|
|
|
1006
1008
|
prefix = null,
|
|
1007
1009
|
callback: deprecatedCallback = null,
|
|
1008
1010
|
} = {},
|
|
1009
|
-
callback = null
|
|
1011
|
+
callback = null,
|
|
1010
1012
|
) {
|
|
1011
1013
|
/**
|
|
1012
1014
|
* [DEPRECATION NOTICE]
|
|
@@ -1015,13 +1017,13 @@ class ClientAdapter {
|
|
|
1015
1017
|
*/
|
|
1016
1018
|
if (deprecatedCallback) {
|
|
1017
1019
|
console.warn(
|
|
1018
|
-
"[FireModel-subscribeDocs] The 'callback' parameter has been moved from the options object to a separate parameter. Please update your code accordingly."
|
|
1020
|
+
"[FireModel-subscribeDocs] The 'callback' parameter has been moved from the options object to a separate parameter. Please update your code accordingly.",
|
|
1019
1021
|
);
|
|
1020
1022
|
if (!callback) {
|
|
1021
1023
|
callback = deprecatedCallback;
|
|
1022
1024
|
} else {
|
|
1023
1025
|
console.warn(
|
|
1024
|
-
"[FireModel-subscribeDocs] The 'callback' parameter was provided both in the options object and as a separate parameter. The separate parameter will take precedence."
|
|
1026
|
+
"[FireModel-subscribeDocs] The 'callback' parameter was provided both in the options object and as a separate parameter. The separate parameter will take precedence.",
|
|
1025
1027
|
);
|
|
1026
1028
|
}
|
|
1027
1029
|
}
|
|
@@ -1045,7 +1047,7 @@ class ClientAdapter {
|
|
|
1045
1047
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
1046
1048
|
const colRef = collection(
|
|
1047
1049
|
ClientAdapter.firestore,
|
|
1048
|
-
collectionPath
|
|
1050
|
+
collectionPath,
|
|
1049
1051
|
).withConverter(this.constructor.converter());
|
|
1050
1052
|
const queryRef = query(colRef, ...queryConstraints);
|
|
1051
1053
|
|
|
@@ -1053,7 +1055,7 @@ class ClientAdapter {
|
|
|
1053
1055
|
snapshot.docChanges().forEach((change) => {
|
|
1054
1056
|
const item = change.doc.data();
|
|
1055
1057
|
const index = this.docs.findIndex(
|
|
1056
|
-
({ docId }) => docId === item.docId
|
|
1058
|
+
({ docId }) => docId === item.docId,
|
|
1057
1059
|
);
|
|
1058
1060
|
if (change.type === "added") this.docs.push(item);
|
|
1059
1061
|
if (change.type === "modified") this.docs.splice(index, 1, item);
|