@shisyamo4131/air-firebase-v2-client-adapter 2.1.2 → 2.1.3-dev.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 (3) hide show
  1. package/error.js +5 -0
  2. package/index.js +31 -23
  3. package/package.json +43 -43
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,13 @@ class ClientAdapter {
332
332
  } catch (err) {
333
333
  if (err instanceof ClientAdapterError) {
334
334
  throw err;
335
+ } else if (err.name === "ValidationError") {
336
+ // BaseClass のエラーをそのままスローする
337
+ // throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
338
+ throw err;
335
339
  } else {
336
340
  this._outputErrorConsole("create", err);
337
- throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
341
+ throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
338
342
  }
339
343
  }
340
344
  }
@@ -361,7 +365,7 @@ class ClientAdapter {
361
365
  // Prepare document reference.
362
366
  const colRef = collection(
363
367
  ClientAdapter.firestore,
364
- collectionPath
368
+ collectionPath,
365
369
  ).withConverter(this.constructor.converter());
366
370
  const docRef = doc(colRef, docId);
367
371
 
@@ -406,7 +410,7 @@ class ClientAdapter {
406
410
  // Prepare document reference.
407
411
  const colRef = collection(
408
412
  ClientAdapter.firestore,
409
- collectionPath
413
+ collectionPath,
410
414
  ).withConverter(this.constructor.converter());
411
415
  const docRef = doc(colRef, docId);
412
416
 
@@ -448,7 +452,7 @@ class ClientAdapter {
448
452
  case "orderBy":
449
453
  if (!["asc", "desc"].includes(args[1] || "asc")) {
450
454
  throw new ClientAdapterError(
451
- ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION
455
+ ERRORS.VALIDATION_INVALID_ORDERBY_DIRECTION,
452
456
  );
453
457
  }
454
458
  result.push(orderBy(args[0], args[1] || "asc"));
@@ -486,7 +490,7 @@ class ClientAdapter {
486
490
  // サロゲートペア文字(絵文字など)を除外
487
491
  const target = constraints.replace(
488
492
  /[\uD800-\uDBFF]|[\uDC00-\uDFFF]|~|\*|\[|\]|\s+/g,
489
- ""
493
+ "",
490
494
  );
491
495
 
492
496
  // 1 文字・2 文字のトークンを生成
@@ -548,7 +552,7 @@ class ClientAdapter {
548
552
  const collectionPath = this.constructor.getCollectionPath(prefix);
549
553
  const colRef = collection(
550
554
  ClientAdapter.firestore,
551
- collectionPath
555
+ collectionPath,
552
556
  ).withConverter(this.constructor.converter());
553
557
 
554
558
  const queryRef = query(colRef, ...queryConstraints);
@@ -602,7 +606,7 @@ class ClientAdapter {
602
606
  const collectionPath = this.constructor.getCollectionPath(prefix);
603
607
  const colRef = collection(
604
608
  ClientAdapter.firestore,
605
- collectionPath
609
+ collectionPath,
606
610
  ).withConverter(this.constructor.converter());
607
611
 
608
612
  const querySnapshotArray = await Promise.all(
@@ -611,11 +615,11 @@ class ClientAdapter {
611
615
  return getDocs(q);
612
616
  /** transaction.get() が Query に対応した場合は以下を使用 */
613
617
  // return transaction ? transaction.get(q) : getDocs(q);
614
- })
618
+ }),
615
619
  );
616
620
 
617
621
  return querySnapshotArray.flatMap((snapshot) =>
618
- snapshot.docs.map((doc) => doc.data())
622
+ snapshot.docs.map((doc) => doc.data()),
619
623
  );
620
624
  } catch (err) {
621
625
  if (err instanceof ClientAdapterError) {
@@ -672,7 +676,7 @@ class ClientAdapter {
672
676
  const collectionPath = this.constructor.getCollectionPath(prefix);
673
677
  const colRef = collection(
674
678
  ClientAdapter.firestore,
675
- collectionPath
679
+ collectionPath,
676
680
  ).withConverter(this.constructor.converter());
677
681
  const docRef = doc(colRef, this.docId);
678
682
 
@@ -692,9 +696,13 @@ class ClientAdapter {
692
696
  } catch (err) {
693
697
  if (err instanceof ClientAdapterError) {
694
698
  throw err;
699
+ } else if (err.name === "ValidationError") {
700
+ // BaseClass のエラーをそのままスローする
701
+ // throw new ClientAdapterError(ERRORS.VALIDATION_FIELD_ERROR, err);
702
+ throw err;
695
703
  } else {
696
704
  this._outputErrorConsole("update", err);
697
- throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR);
705
+ throw new ClientAdapterError(ERRORS.SYSTEM_UNKNOWN_ERROR, err);
698
706
  }
699
707
  }
700
708
  }
@@ -830,7 +838,7 @@ class ClientAdapter {
830
838
  const sourceDocData = sourceDocSnap.data();
831
839
  const archiveColRef = collection(
832
840
  ClientAdapter.firestore,
833
- `${collectionPath}_archive`
841
+ `${collectionPath}_archive`,
834
842
  );
835
843
  const archiveDocRef = doc(archiveColRef, this.docId);
836
844
  txn.set(archiveDocRef, sourceDocData);
@@ -909,7 +917,7 @@ class ClientAdapter {
909
917
  } else {
910
918
  return await runTransaction(
911
919
  ClientAdapter.firestore,
912
- performTransaction
920
+ performTransaction,
913
921
  );
914
922
  }
915
923
  } catch (err) {
@@ -966,7 +974,7 @@ class ClientAdapter {
966
974
  // const colRef = collection(ClientAdapter.firestore, collectionPath);
967
975
  const colRef = collection(
968
976
  ClientAdapter.firestore,
969
- collectionPath
977
+ collectionPath,
970
978
  ).withConverter(this.constructor.converter());
971
979
  const docRef = doc(colRef, docId);
972
980
  this.listener = onSnapshot(docRef, (docSnapshot) => {
@@ -1004,7 +1012,7 @@ class ClientAdapter {
1004
1012
  prefix = null,
1005
1013
  callback: deprecatedCallback = null,
1006
1014
  } = {},
1007
- callback = null
1015
+ callback = null,
1008
1016
  ) {
1009
1017
  /**
1010
1018
  * [DEPRECATION NOTICE]
@@ -1013,13 +1021,13 @@ class ClientAdapter {
1013
1021
  */
1014
1022
  if (deprecatedCallback) {
1015
1023
  console.warn(
1016
- "[FireModel-subscribeDocs] The 'callback' parameter has been moved from the options object to a separate parameter. Please update your code accordingly."
1024
+ "[FireModel-subscribeDocs] The 'callback' parameter has been moved from the options object to a separate parameter. Please update your code accordingly.",
1017
1025
  );
1018
1026
  if (!callback) {
1019
1027
  callback = deprecatedCallback;
1020
1028
  } else {
1021
1029
  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."
1030
+ "[FireModel-subscribeDocs] The 'callback' parameter was provided both in the options object and as a separate parameter. The separate parameter will take precedence.",
1023
1031
  );
1024
1032
  }
1025
1033
  }
@@ -1043,7 +1051,7 @@ class ClientAdapter {
1043
1051
  const collectionPath = this.constructor.getCollectionPath(prefix);
1044
1052
  const colRef = collection(
1045
1053
  ClientAdapter.firestore,
1046
- collectionPath
1054
+ collectionPath,
1047
1055
  ).withConverter(this.constructor.converter());
1048
1056
  const queryRef = query(colRef, ...queryConstraints);
1049
1057
 
@@ -1051,7 +1059,7 @@ class ClientAdapter {
1051
1059
  snapshot.docChanges().forEach((change) => {
1052
1060
  const item = change.doc.data();
1053
1061
  const index = this.docs.findIndex(
1054
- ({ docId }) => docId === item.docId
1062
+ ({ docId }) => docId === item.docId,
1055
1063
  );
1056
1064
  if (change.type === "added") this.docs.push(item);
1057
1065
  if (change.type === "modified") this.docs.splice(index, 1, item);
package/package.json CHANGED
@@ -1,43 +1,43 @@
1
- {
2
- "name": "@shisyamo4131/air-firebase-v2-client-adapter",
3
- "version": "2.1.2",
4
- "description": "client adapter for FireModel",
5
- "type": "module",
6
- "main": "index.js",
7
- "exports": {
8
- ".": "./index.js"
9
- },
10
- "files": [
11
- "index.js",
12
- "error.js"
13
- ],
14
- "keywords": [
15
- "firebase",
16
- "firestore",
17
- "client",
18
- "adapter"
19
- ],
20
- "author": "shisyamo4131",
21
- "license": "ISC",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/shisyamo4131/air-firebase-v2-client-adapter.git"
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
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
32
- },
33
- "publishConfig": {
34
- "access": "public"
35
- },
36
- "peerDependencies": {
37
- "firebase": "^10.0.0 || ^11.0.0"
38
- },
39
- "devDependencies": {
40
- "@jest/globals": "^30.2.0",
41
- "jest": "^30.2.0"
42
- }
43
- }
1
+ {
2
+ "name": "@shisyamo4131/air-firebase-v2-client-adapter",
3
+ "version": "2.1.3-dev.1",
4
+ "description": "client adapter for FireModel",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "error.js"
13
+ ],
14
+ "keywords": [
15
+ "firebase",
16
+ "firestore",
17
+ "client",
18
+ "adapter"
19
+ ],
20
+ "author": "shisyamo4131",
21
+ "license": "ISC",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/shisyamo4131/air-firebase-v2-client-adapter.git"
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
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "peerDependencies": {
37
+ "firebase": "^10.0.0 || ^11.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@jest/globals": "^30.2.0",
41
+ "jest": "^30.2.0"
42
+ }
43
+ }