@shisyamo4131/air-firebase-v2-client-adapter 2.1.2 → 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 +27 -23
- 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
|
@@ -62,7 +62,7 @@ class ClientAdapter {
|
|
|
62
62
|
get auth() {
|
|
63
63
|
if (!ClientAdapter.auth) {
|
|
64
64
|
throw new ClientAdapterError(
|
|
65
|
-
ERRORS.SYSTEM_AUTHENTICATION_NOT_INITIALIZED
|
|
65
|
+
ERRORS.SYSTEM_AUTHENTICATION_NOT_INITIALIZED,
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
return ClientAdapter.auth;
|
|
@@ -129,7 +129,7 @@ class ClientAdapter {
|
|
|
129
129
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
130
130
|
const colRef = collection(
|
|
131
131
|
ClientAdapter.firestore,
|
|
132
|
-
collectionPath
|
|
132
|
+
collectionPath,
|
|
133
133
|
).withConverter(this.constructor.converter());
|
|
134
134
|
|
|
135
135
|
return doc(colRef, docId);
|
|
@@ -171,7 +171,7 @@ class ClientAdapter {
|
|
|
171
171
|
const docSnap = await transaction.get(docRef);
|
|
172
172
|
if (!docSnap.exists()) {
|
|
173
173
|
throw new ClientAdapterError(
|
|
174
|
-
ERRORS.BUSINESS_AUTONUMBER_DOCUMENT_NOT_FOUND
|
|
174
|
+
ERRORS.BUSINESS_AUTONUMBER_DOCUMENT_NOT_FOUND,
|
|
175
175
|
);
|
|
176
176
|
}
|
|
177
177
|
|
|
@@ -298,7 +298,7 @@ class ClientAdapter {
|
|
|
298
298
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
299
299
|
const colRef = collection(
|
|
300
300
|
ClientAdapter.firestore,
|
|
301
|
-
collectionPath
|
|
301
|
+
collectionPath,
|
|
302
302
|
).withConverter(this.constructor.converter());
|
|
303
303
|
const docRef = docId ? doc(colRef, docId) : doc(colRef);
|
|
304
304
|
|
|
@@ -332,9 +332,11 @@ class ClientAdapter {
|
|
|
332
332
|
} catch (err) {
|
|
333
333
|
if (err instanceof ClientAdapterError) {
|
|
334
334
|
throw err;
|
|
335
|
+
} else if (err.name === "ValidationError") {
|
|
336
|
+
throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
|
|
335
337
|
} else {
|
|
336
338
|
this._outputErrorConsole("create", err);
|
|
337
|
-
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
|
|
339
|
+
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
|
|
338
340
|
}
|
|
339
341
|
}
|
|
340
342
|
}
|
|
@@ -361,7 +363,7 @@ class ClientAdapter {
|
|
|
361
363
|
// Prepare document reference.
|
|
362
364
|
const colRef = collection(
|
|
363
365
|
ClientAdapter.firestore,
|
|
364
|
-
collectionPath
|
|
366
|
+
collectionPath,
|
|
365
367
|
).withConverter(this.constructor.converter());
|
|
366
368
|
const docRef = doc(colRef, docId);
|
|
367
369
|
|
|
@@ -406,7 +408,7 @@ class ClientAdapter {
|
|
|
406
408
|
// Prepare document reference.
|
|
407
409
|
const colRef = collection(
|
|
408
410
|
ClientAdapter.firestore,
|
|
409
|
-
collectionPath
|
|
411
|
+
collectionPath,
|
|
410
412
|
).withConverter(this.constructor.converter());
|
|
411
413
|
const docRef = doc(colRef, docId);
|
|
412
414
|
|
|
@@ -448,7 +450,7 @@ class ClientAdapter {
|
|
|
448
450
|
case "orderBy":
|
|
449
451
|
if (!["asc", "desc"].includes(args[1] || "asc")) {
|
|
450
452
|
throw new ClientAdapterError(
|
|
451
|
-
ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION
|
|
453
|
+
ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION,
|
|
452
454
|
);
|
|
453
455
|
}
|
|
454
456
|
result.push(orderBy(args[0], args[1] || "asc"));
|
|
@@ -486,7 +488,7 @@ class ClientAdapter {
|
|
|
486
488
|
// サロゲートペア文字(絵文字など)を除外
|
|
487
489
|
const target = constraints.replace(
|
|
488
490
|
/[\uD800-\uDBFF]|[\uDC00-\uDFFF]|~|\*|\[|\]|\s+/g,
|
|
489
|
-
""
|
|
491
|
+
"",
|
|
490
492
|
);
|
|
491
493
|
|
|
492
494
|
// 1 文字・2 文字のトークンを生成
|
|
@@ -548,7 +550,7 @@ class ClientAdapter {
|
|
|
548
550
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
549
551
|
const colRef = collection(
|
|
550
552
|
ClientAdapter.firestore,
|
|
551
|
-
collectionPath
|
|
553
|
+
collectionPath,
|
|
552
554
|
).withConverter(this.constructor.converter());
|
|
553
555
|
|
|
554
556
|
const queryRef = query(colRef, ...queryConstraints);
|
|
@@ -602,7 +604,7 @@ class ClientAdapter {
|
|
|
602
604
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
603
605
|
const colRef = collection(
|
|
604
606
|
ClientAdapter.firestore,
|
|
605
|
-
collectionPath
|
|
607
|
+
collectionPath,
|
|
606
608
|
).withConverter(this.constructor.converter());
|
|
607
609
|
|
|
608
610
|
const querySnapshotArray = await Promise.all(
|
|
@@ -611,11 +613,11 @@ class ClientAdapter {
|
|
|
611
613
|
return getDocs(q);
|
|
612
614
|
/** transaction.get() が Query に対応した場合は以下を使用 */
|
|
613
615
|
// return transaction ? transaction.get(q) : getDocs(q);
|
|
614
|
-
})
|
|
616
|
+
}),
|
|
615
617
|
);
|
|
616
618
|
|
|
617
619
|
return querySnapshotArray.flatMap((snapshot) =>
|
|
618
|
-
snapshot.docs.map((doc) => doc.data())
|
|
620
|
+
snapshot.docs.map((doc) => doc.data()),
|
|
619
621
|
);
|
|
620
622
|
} catch (err) {
|
|
621
623
|
if (err instanceof ClientAdapterError) {
|
|
@@ -672,7 +674,7 @@ class ClientAdapter {
|
|
|
672
674
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
673
675
|
const colRef = collection(
|
|
674
676
|
ClientAdapter.firestore,
|
|
675
|
-
collectionPath
|
|
677
|
+
collectionPath,
|
|
676
678
|
).withConverter(this.constructor.converter());
|
|
677
679
|
const docRef = doc(colRef, this.docId);
|
|
678
680
|
|
|
@@ -692,9 +694,11 @@ class ClientAdapter {
|
|
|
692
694
|
} catch (err) {
|
|
693
695
|
if (err instanceof ClientAdapterError) {
|
|
694
696
|
throw err;
|
|
697
|
+
} else if (err.name === "ValidationError") {
|
|
698
|
+
throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
|
|
695
699
|
} else {
|
|
696
700
|
this._outputErrorConsole("update", err);
|
|
697
|
-
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
|
|
701
|
+
throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
|
|
698
702
|
}
|
|
699
703
|
}
|
|
700
704
|
}
|
|
@@ -830,7 +834,7 @@ class ClientAdapter {
|
|
|
830
834
|
const sourceDocData = sourceDocSnap.data();
|
|
831
835
|
const archiveColRef = collection(
|
|
832
836
|
ClientAdapter.firestore,
|
|
833
|
-
`${collectionPath}_archive
|
|
837
|
+
`${collectionPath}_archive`,
|
|
834
838
|
);
|
|
835
839
|
const archiveDocRef = doc(archiveColRef, this.docId);
|
|
836
840
|
txn.set(archiveDocRef, sourceDocData);
|
|
@@ -909,7 +913,7 @@ class ClientAdapter {
|
|
|
909
913
|
} else {
|
|
910
914
|
return await runTransaction(
|
|
911
915
|
ClientAdapter.firestore,
|
|
912
|
-
performTransaction
|
|
916
|
+
performTransaction,
|
|
913
917
|
);
|
|
914
918
|
}
|
|
915
919
|
} catch (err) {
|
|
@@ -966,7 +970,7 @@ class ClientAdapter {
|
|
|
966
970
|
// const colRef = collection(ClientAdapter.firestore, collectionPath);
|
|
967
971
|
const colRef = collection(
|
|
968
972
|
ClientAdapter.firestore,
|
|
969
|
-
collectionPath
|
|
973
|
+
collectionPath,
|
|
970
974
|
).withConverter(this.constructor.converter());
|
|
971
975
|
const docRef = doc(colRef, docId);
|
|
972
976
|
this.listener = onSnapshot(docRef, (docSnapshot) => {
|
|
@@ -1004,7 +1008,7 @@ class ClientAdapter {
|
|
|
1004
1008
|
prefix = null,
|
|
1005
1009
|
callback: deprecatedCallback = null,
|
|
1006
1010
|
} = {},
|
|
1007
|
-
callback = null
|
|
1011
|
+
callback = null,
|
|
1008
1012
|
) {
|
|
1009
1013
|
/**
|
|
1010
1014
|
* [DEPRECATION NOTICE]
|
|
@@ -1013,13 +1017,13 @@ class ClientAdapter {
|
|
|
1013
1017
|
*/
|
|
1014
1018
|
if (deprecatedCallback) {
|
|
1015
1019
|
console.warn(
|
|
1016
|
-
"[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.",
|
|
1017
1021
|
);
|
|
1018
1022
|
if (!callback) {
|
|
1019
1023
|
callback = deprecatedCallback;
|
|
1020
1024
|
} else {
|
|
1021
1025
|
console.warn(
|
|
1022
|
-
"[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.",
|
|
1023
1027
|
);
|
|
1024
1028
|
}
|
|
1025
1029
|
}
|
|
@@ -1043,7 +1047,7 @@ class ClientAdapter {
|
|
|
1043
1047
|
const collectionPath = this.constructor.getCollectionPath(prefix);
|
|
1044
1048
|
const colRef = collection(
|
|
1045
1049
|
ClientAdapter.firestore,
|
|
1046
|
-
collectionPath
|
|
1050
|
+
collectionPath,
|
|
1047
1051
|
).withConverter(this.constructor.converter());
|
|
1048
1052
|
const queryRef = query(colRef, ...queryConstraints);
|
|
1049
1053
|
|
|
@@ -1051,7 +1055,7 @@ class ClientAdapter {
|
|
|
1051
1055
|
snapshot.docChanges().forEach((change) => {
|
|
1052
1056
|
const item = change.doc.data();
|
|
1053
1057
|
const index = this.docs.findIndex(
|
|
1054
|
-
({ docId }) => docId === item.docId
|
|
1058
|
+
({ docId }) => docId === item.docId,
|
|
1055
1059
|
);
|
|
1056
1060
|
if (change.type === "added") this.docs.push(item);
|
|
1057
1061
|
if (change.type === "modified") this.docs.splice(index, 1, item);
|