@vtecx/vtecxnext 2.3.0 → 2.3.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/dist/vtecxnext.js +81 -5
  2. package/package.json +3 -3
package/dist/vtecxnext.js CHANGED
@@ -59,6 +59,8 @@ const HEADER_NEXTPAGE = 'x-vtecx-nextpage';
59
59
  const PAGINATION_NUM = 7;
60
60
  /** pagination memorysort */
61
61
  const MEMORYSORT = 'memorysort';
62
+ /** parameter : nextpage */
63
+ const PARAM_NEXTPAGE = 'p';
62
64
  class VtecxNext {
63
65
  /** Request */
64
66
  req;
@@ -625,11 +627,36 @@ class VtecxNext {
625
627
  * @return count
626
628
  */
627
629
  count = async (uri, targetService) => {
628
- //console.log('[vtecxnext count] start.')
629
- const vtecxRes = await this.countResponse(uri, targetService);
630
- // 戻り値
631
- const data = vtecxRes.data;
632
- return vtecxRes.data.feed.title ? Number(data.feed.title) : null;
630
+ //console.log(`[vtecxnext count] start. uri=${uri}`)
631
+ let cnt = 0;
632
+ let noRepeat = false;
633
+ let nextpage = '';
634
+ const params = getParamMap(uri);
635
+ if (params[PARAM_NEXTPAGE]) {
636
+ noRepeat = true;
637
+ }
638
+ do {
639
+ const editedUri = noRepeat ? uri : addNextpage(uri, nextpage);
640
+ //console.log(`[vtecxnext count] editedUri=${editedUri}`)
641
+ nextpage = '';
642
+ const vtecxRes = await this.countResponse(editedUri, targetService);
643
+ if (vtecxRes.status === 200) {
644
+ const data = vtecxRes.data;
645
+ if (!data?.feed?.title) {
646
+ if (!cnt) {
647
+ return null;
648
+ }
649
+ }
650
+ else {
651
+ cnt += Number(data.feed.title);
652
+ }
653
+ if (vtecxRes.header.hasOwnProperty(HEADER_NEXTPAGE)) {
654
+ nextpage = vtecxRes.header[HEADER_NEXTPAGE];
655
+ //console.log(`[vtecxnext count] ${HEADER_NEXTPAGE}=${nextpage}`)
656
+ }
657
+ }
658
+ } while (!noRepeat && nextpage);
659
+ return cnt;
633
660
  };
634
661
  /**
635
662
  * get count
@@ -4590,3 +4617,52 @@ const createURLSearchParams = (data) => {
4590
4617
  Object.keys(data).forEach((key) => params.append(key, data[key]));
4591
4618
  return params;
4592
4619
  };
4620
+ /**
4621
+ * URIのパラメータ部分を連想配列にして返却
4622
+ * @param uri URI
4623
+ * @returns パラメータを連想配列にしたオブジェクト
4624
+ */
4625
+ const getParamMap = (uri) => {
4626
+ if (!uri) {
4627
+ return {};
4628
+ }
4629
+ const idxQ = uri.indexOf('?');
4630
+ if (idxQ < 0) {
4631
+ return {};
4632
+ }
4633
+ const paramStr = uri.substring(idxQ + 1);
4634
+ if (!paramStr) {
4635
+ return {};
4636
+ }
4637
+ const params = {};
4638
+ const paramStrParts = paramStr.split('&');
4639
+ for (const paramStrPart of paramStrParts) {
4640
+ let name = '';
4641
+ let value = '';
4642
+ const idxE = paramStrPart.indexOf('=');
4643
+ if (idxE < 0) {
4644
+ name = paramStrPart;
4645
+ }
4646
+ else {
4647
+ name = paramStrPart.substring(0, idxE);
4648
+ value = paramStrPart.substring(idxE + 1);
4649
+ }
4650
+ params[name] = value;
4651
+ }
4652
+ return params;
4653
+ };
4654
+ /**
4655
+ * URIにカーソルを付加
4656
+ * @param uri URI
4657
+ * @param nextpage カーソル
4658
+ * @returns URIにカーソルを付加した文字列
4659
+ */
4660
+ const addNextpage = (uri, nextpage) => {
4661
+ if (nextpage) {
4662
+ const rchar = uri.indexOf('?') < 0 ? '?' : '&';
4663
+ return `${uri}${rchar}${PARAM_NEXTPAGE}=${nextpage}`;
4664
+ }
4665
+ else {
4666
+ return uri;
4667
+ }
4668
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtecx/vtecxnext",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "vte.cx Next.js api",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -18,13 +18,13 @@
18
18
  },
19
19
  "homepage": "https://github.com/reflexworks/vtecxnext#readme",
20
20
  "devDependencies": {
21
- "@types/node": "^24.9.1",
21
+ "@types/node": "^24.10.1",
22
22
  "@types/sqlstring": "^2.3.2",
23
23
  "ts-node": "^10.9.2",
24
24
  "typescript": "^5.9.3"
25
25
  },
26
26
  "dependencies": {
27
- "next": "^16.0.0",
27
+ "next": "^16.0.7",
28
28
  "sqlstring": "^2.3.3"
29
29
  },
30
30
  "scripts": {