@vtecx/vtecxnext 2.2.3 → 2.2.5
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/dist/vtecxnext.d.ts +32 -3
- package/dist/vtecxnext.js +93 -5
- package/package.json +1 -1
package/dist/vtecxnext.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ export type CreateGroupadminInfo = {
|
|
|
24
24
|
group: string;
|
|
25
25
|
uids: string[];
|
|
26
26
|
};
|
|
27
|
+
export type PaginationInfo = {
|
|
28
|
+
lastPageNumber: number;
|
|
29
|
+
countWithinRange: number;
|
|
30
|
+
hasNext: boolean;
|
|
31
|
+
};
|
|
27
32
|
export declare class VtecxNext {
|
|
28
33
|
/** Request */
|
|
29
34
|
readonly req: NextRequest | undefined;
|
|
@@ -383,17 +388,34 @@ export declare class VtecxNext {
|
|
|
383
388
|
* @param uri key and conditions
|
|
384
389
|
* @param pagerange page range
|
|
385
390
|
* @param targetService target service name (for service linkage)
|
|
386
|
-
* @return
|
|
391
|
+
* @return Maximum number of pages in the specified page range, and total count.
|
|
387
392
|
*/
|
|
388
|
-
pagination: (uri: string, pagerange: string, targetService?: string) => Promise<
|
|
393
|
+
pagination: (uri: string, pagerange: string, targetService?: string) => Promise<PaginationInfo>;
|
|
389
394
|
/**
|
|
390
395
|
* get page
|
|
391
396
|
* @param uri key and conditions
|
|
392
397
|
* @param num page number
|
|
393
398
|
* @param targetService target service name (for service linkage)
|
|
394
|
-
* @return feed
|
|
399
|
+
* @return feed (entry array)
|
|
395
400
|
*/
|
|
396
401
|
getPage: (uri: string, num: number, targetService?: string) => Promise<any>;
|
|
402
|
+
/**
|
|
403
|
+
* practical paging
|
|
404
|
+
* If you specify page 1, a new cursor list will be created.
|
|
405
|
+
* @param uri key and conditions
|
|
406
|
+
* @param num page number
|
|
407
|
+
* @param targetService target service name (for service linkage)
|
|
408
|
+
* @return feed (entry array)
|
|
409
|
+
*/
|
|
410
|
+
practicalPaging: (uri: string, num: number, targetService?: string) => Promise<any>;
|
|
411
|
+
/**
|
|
412
|
+
* ページングのカーソルリスト作成処理
|
|
413
|
+
* 続きがある場合、次のカーソルリスト作成処理を実行する
|
|
414
|
+
* @param vtecxnext
|
|
415
|
+
* @param uri キーとパラメータ
|
|
416
|
+
* @param prevLastPage 前回の最終ページ
|
|
417
|
+
*/
|
|
418
|
+
private nextPagination;
|
|
397
419
|
/**
|
|
398
420
|
* post data to bigquery
|
|
399
421
|
* @param feed entries (JSON)
|
|
@@ -980,3 +1002,10 @@ export declare class VtecxNextError extends Error {
|
|
|
980
1002
|
export declare class FetchError extends VtecxNextError {
|
|
981
1003
|
constructor(message: string);
|
|
982
1004
|
}
|
|
1005
|
+
/**
|
|
1006
|
+
* VtecxNextError型かどうかチェック
|
|
1007
|
+
* インターフェースの判定には型ガード関数を使う
|
|
1008
|
+
* @param value チェックオブジェクト
|
|
1009
|
+
* @returns VtecxNextError型の場合true
|
|
1010
|
+
*/
|
|
1011
|
+
export declare const isVtecxNextError: (value: unknown) => value is VtecxNextError;
|
package/dist/vtecxnext.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.FetchError = exports.VtecxNextError = exports.VtecxResponse = exports.VtecxNext = exports.hello = void 0;
|
|
29
|
+
exports.isVtecxNextError = exports.FetchError = exports.VtecxNextError = exports.VtecxResponse = exports.VtecxNext = exports.hello = void 0;
|
|
30
30
|
const sqlstring_1 = __importDefault(require("sqlstring"));
|
|
31
31
|
const url_1 = __importStar(require("url"));
|
|
32
32
|
/**
|
|
@@ -45,6 +45,8 @@ const SERVLETPATH_PROVIDER = '/p';
|
|
|
45
45
|
const SERVLETPATH_OAUTH = '/o';
|
|
46
46
|
/** header : nextpage */
|
|
47
47
|
const HEADER_NEXTPAGE = 'x-vtecx-nextpage';
|
|
48
|
+
/** The number of cursors to create (for practical paging) */
|
|
49
|
+
const PAGINATION_NUM = 7;
|
|
48
50
|
class VtecxNext {
|
|
49
51
|
/** Request */
|
|
50
52
|
req;
|
|
@@ -1356,7 +1358,7 @@ class VtecxNext {
|
|
|
1356
1358
|
* @param uri key and conditions
|
|
1357
1359
|
* @param pagerange page range
|
|
1358
1360
|
* @param targetService target service name (for service linkage)
|
|
1359
|
-
* @return
|
|
1361
|
+
* @return Maximum number of pages in the specified page range, and total count.
|
|
1360
1362
|
*/
|
|
1361
1363
|
pagination = async (uri, pagerange, targetService) => {
|
|
1362
1364
|
//console.log('[vtecxnext pagination] start.')
|
|
@@ -1377,15 +1379,25 @@ class VtecxNext {
|
|
|
1377
1379
|
this.setCookie(response);
|
|
1378
1380
|
// レスポンスのエラーチェック
|
|
1379
1381
|
await checkVtecxResponse(response);
|
|
1380
|
-
//
|
|
1381
|
-
|
|
1382
|
+
// 戻り値編集
|
|
1383
|
+
const respJson = await getJson(response);
|
|
1384
|
+
let hasNext = false;
|
|
1385
|
+
if (respJson.feed.link && respJson.feed.link[0]?.___rel === 'next') {
|
|
1386
|
+
hasNext = true;
|
|
1387
|
+
}
|
|
1388
|
+
const pagenationInfo = {
|
|
1389
|
+
'lastPageNumber': Number(respJson.feed.title),
|
|
1390
|
+
'countWithinRange': Number(respJson.feed.subtitle),
|
|
1391
|
+
'hasNext': hasNext
|
|
1392
|
+
};
|
|
1393
|
+
return pagenationInfo;
|
|
1382
1394
|
};
|
|
1383
1395
|
/**
|
|
1384
1396
|
* get page
|
|
1385
1397
|
* @param uri key and conditions
|
|
1386
1398
|
* @param num page number
|
|
1387
1399
|
* @param targetService target service name (for service linkage)
|
|
1388
|
-
* @return feed
|
|
1400
|
+
* @return feed (entry array)
|
|
1389
1401
|
*/
|
|
1390
1402
|
getPage = async (uri, num, targetService) => {
|
|
1391
1403
|
//console.log(`[vtecxnext getPage] start. uri=${uri} num=${num}`)
|
|
@@ -1410,6 +1422,59 @@ class VtecxNext {
|
|
|
1410
1422
|
// 戻り値
|
|
1411
1423
|
return await getJson(response);
|
|
1412
1424
|
};
|
|
1425
|
+
/**
|
|
1426
|
+
* practical paging
|
|
1427
|
+
* If you specify page 1, a new cursor list will be created.
|
|
1428
|
+
* @param uri key and conditions
|
|
1429
|
+
* @param num page number
|
|
1430
|
+
* @param targetService target service name (for service linkage)
|
|
1431
|
+
* @return feed (entry array)
|
|
1432
|
+
*/
|
|
1433
|
+
practicalPaging = async (uri, num, targetService) => {
|
|
1434
|
+
//console.log(`[practicalPaging] start. uri=${uri} num=${num} ${targetService ? 'targetService=' + targetService : ''}`)
|
|
1435
|
+
// ページ数が1の場合、カーソルリスト作成処理を行う
|
|
1436
|
+
if (num === 1) {
|
|
1437
|
+
//console.log(`[practicalPaging] pagination start. uri=${uri}`)
|
|
1438
|
+
const paginationInfo = await this.pagination(uri, `1,${String(PAGINATION_NUM)}`);
|
|
1439
|
+
if (paginationInfo.hasNext) {
|
|
1440
|
+
// 次のカーソルリスト作成 (非同期のまま)
|
|
1441
|
+
this.nextPagination(uri, PAGINATION_NUM);
|
|
1442
|
+
}
|
|
1443
|
+
if (paginationInfo.lastPageNumber === 0) {
|
|
1444
|
+
// データが存在しない場合終了
|
|
1445
|
+
return undefined;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
// ページ取得
|
|
1449
|
+
//console.log(`[practicalPaging] getPage start. uri=${uri} num=${num}`)
|
|
1450
|
+
try {
|
|
1451
|
+
return await this.getPage(uri, num);
|
|
1452
|
+
}
|
|
1453
|
+
catch (error) {
|
|
1454
|
+
if ((0, exports.isVtecxNextError)(error)) {
|
|
1455
|
+
// ステータス400で「There is no designated page. The last page: ページ数」の場合、空データを返す。
|
|
1456
|
+
if (error.status === 400 && error.message.startsWith('There is no designated page.')) {
|
|
1457
|
+
return undefined;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
throw error;
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
/**
|
|
1464
|
+
* ページングのカーソルリスト作成処理
|
|
1465
|
+
* 続きがある場合、次のカーソルリスト作成処理を実行する
|
|
1466
|
+
* @param vtecxnext
|
|
1467
|
+
* @param uri キーとパラメータ
|
|
1468
|
+
* @param prevLastPage 前回の最終ページ
|
|
1469
|
+
*/
|
|
1470
|
+
nextPagination = async (uri, prevLastPage) => {
|
|
1471
|
+
const firstPage = prevLastPage + 1;
|
|
1472
|
+
const lastPage = prevLastPage + prevLastPage;
|
|
1473
|
+
const paginationInfo = await this.pagination(uri, `${String(firstPage)},${String(lastPage)}`);
|
|
1474
|
+
if (paginationInfo.hasNext) {
|
|
1475
|
+
await this.nextPagination(uri, lastPage);
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1413
1478
|
/**
|
|
1414
1479
|
* post data to bigquery
|
|
1415
1480
|
* @param feed entries (JSON)
|
|
@@ -4001,6 +4066,29 @@ class FetchError extends VtecxNextError {
|
|
|
4001
4066
|
}
|
|
4002
4067
|
}
|
|
4003
4068
|
exports.FetchError = FetchError;
|
|
4069
|
+
/**
|
|
4070
|
+
* VtecxNextError型かどうかチェック
|
|
4071
|
+
* インターフェースの判定には型ガード関数を使う
|
|
4072
|
+
* @param value チェックオブジェクト
|
|
4073
|
+
* @returns VtecxNextError型の場合true
|
|
4074
|
+
*/
|
|
4075
|
+
const isVtecxNextError = (value) => {
|
|
4076
|
+
// 値がオブジェクトであるかの判定
|
|
4077
|
+
if (typeof value !== "object" || value === null) {
|
|
4078
|
+
return false;
|
|
4079
|
+
}
|
|
4080
|
+
const { status, message } = value;
|
|
4081
|
+
// statusプロパティーが数値型かを判定
|
|
4082
|
+
if (typeof status !== "number") {
|
|
4083
|
+
return false;
|
|
4084
|
+
}
|
|
4085
|
+
// messageプロパティーが文字列型かを判定
|
|
4086
|
+
if (typeof message !== "string") {
|
|
4087
|
+
return false;
|
|
4088
|
+
}
|
|
4089
|
+
return true;
|
|
4090
|
+
};
|
|
4091
|
+
exports.isVtecxNextError = isVtecxNextError;
|
|
4004
4092
|
//---------------------------------------------
|
|
4005
4093
|
/**
|
|
4006
4094
|
* vte.cxへリクエスト
|