Skip to content

Commit

Permalink
feat: beta add test (#29)
Browse files Browse the repository at this point in the history
* feat: add v3 version name

* feat: add new version

* feat: add new test

* feat: revert test code

* feat: remove test

* feat: rename file

* feat: revert test

* feat: remove console
  • Loading branch information
ziqiang authored Nov 30, 2023
1 parent 32a7c8e commit db2a4f4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/apitable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { AxiosInstance } from "axios";
// import mpAdapter from 'axios-miniprogram-adapter';
import qs from "qs";
import { DEFAULT_HOST, DEFAULT_REQUEST_TIMEOUT, DEFAULT_VERSION_PREFIX, FUSION_PATH_PREFIX } from "./const";
import {DATA_BUS_VERSION_PREFIX, DEFAULT_HOST, DEFAULT_REQUEST_TIMEOUT, DEFAULT_VERSION_PREFIX, FUSION_PATH_PREFIX} from "./const";
import { Datasheet } from "./datasheet";
import { IHttpResponse, IVikaClientConfig } from "./interface";
import { NodeManager } from "./node";
Expand Down Expand Up @@ -76,11 +76,17 @@ export class Vika {
}): Promise<IHttpResponse<T>> {
const { path, params, method, data, headers, timeout } = config;
let result: IHttpResponse<T>;
let urlPath = '';
if (params?.isV3){
urlPath = path.includes(FUSION_PATH_PREFIX) ? path : DATA_BUS_VERSION_PREFIX.concat(path);
}else {
urlPath = path.includes(FUSION_PATH_PREFIX) ? path : DEFAULT_VERSION_PREFIX.concat(path);
}
try {
result = (
await this.axios.request<IHttpResponse<T>>({
timeout,
url: path.includes(FUSION_PATH_PREFIX) ? path : DEFAULT_VERSION_PREFIX.concat(path),
url: urlPath,
method,
params: {
fieldKey: this.config.fieldKey,
Expand Down
1 change: 1 addition & 0 deletions lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const DST_MAX_RECORDS = 50000; // Maximum number of records in a single d
export const DEFAULT_HOST = 'https://api.vika.cn';
export const FUSION_PATH_PREFIX = '/fusion';
export const DEFAULT_VERSION_PREFIX = '/fusion/v1';
export const DATA_BUS_VERSION_PREFIX = '/fusion/v3';
export const DEFAULT_REQUEST_TIMEOUT = 60000;
export const MAX_WRITE_SIZE_PER_REQ = 10;

Expand Down
5 changes: 5 additions & 0 deletions lib/interface/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export interface IGetRecordsReqParams {
* return method (using id will avoid code failure due to column name changes).
*/
fieldKey?: 'name' | 'id';

/**
* use databus fusion api
* */
isV3?: boolean;
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vikadata/vika",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "维格表官方 JavaScript SDK",
"main": "./es/index.js",
"scripts": {
Expand Down
40 changes: 40 additions & 0 deletions test/fusion.v3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {IDatasheetCreateRo, INodeItem, IRecord, Vika} from "../lib";
import {Buffer} from "buffer";
import fs from "fs";
import path from "path";
import {IAddOpenSingleTextFieldProperty} from "../lib/interface/field.create.property";
import {IDatasheetFieldCreateRo} from "../lib/interface/datasheet.field.create.ro";
import {EmbedLinkTheme, PermissionType} from "../lib/interface/embed.link";

jest.setTimeout(300000);
describe('full pipeline', () => {
const host = `https://integration.vika.ltd/fusion/v1`;
const token = 'uskM9c6MzfkHMeCJVipM1zv';
const datasheetId = 'dstVrj2y9AMx1YJ5Jy';
const folderId = process.env.FOLDER_ID as string;
const spaceId = process.env.SPACE_ID as string;
const viewId = process.env.VIEW_ID as string;

const apitable = new Vika({
token,
host,
});

const datasheet = apitable.datasheet(datasheetId);

let records: IRecord[];
let spaceIds: string[];
let nodes: INodeItem[];
let createdDatasheetId: string;
let createdFieldId: string;

it('get records', async () => {
const allRecords = await datasheet.records.query({
isV3: true
});
const allRecords2 = await datasheet.records.query();
// console.log(' see result', allRecords);
// console.log(' see result2', allRecords2);
});

});

0 comments on commit db2a4f4

Please sign in to comment.