diff --git a/.github/workflows/js-npm-publish.yml b/.github/workflows/js-npm-publish.yml index 5ba3758..2150724 100644 --- a/.github/workflows/js-npm-publish.yml +++ b/.github/workflows/js-npm-publish.yml @@ -50,6 +50,6 @@ jobs: registry-url: https://registry.npmjs.org/ - run: | yarn - yarn publish --access public + yarn publish --access public --tag beta env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN }} diff --git a/apitable.java/.version b/apitable.java/.version index 589268e..20c4e26 100644 --- a/apitable.java/.version +++ b/apitable.java/.version @@ -1 +1 @@ -1.3.0 \ No newline at end of file +2.0.0-beta.4 diff --git a/apitable.java/client/src/main/java/com/apitable/client/api/ApitableApiClient.java b/apitable.java/client/src/main/java/com/apitable/client/api/ApitableApiClient.java index 300eb95..045a1de 100644 --- a/apitable.java/client/src/main/java/com/apitable/client/api/ApitableApiClient.java +++ b/apitable.java/client/src/main/java/com/apitable/client/api/ApitableApiClient.java @@ -182,4 +182,9 @@ public DatasheetApi getDatasheetApi() { } return datasheetApi; } + + + public boolean isV3(){ + return this.apiVersion == ApiVersion.V3; + } } diff --git a/apitable.java/client/src/main/java/com/apitable/client/api/RecordApi.java b/apitable.java/client/src/main/java/com/apitable/client/api/RecordApi.java index 533dddd..631d887 100644 --- a/apitable.java/client/src/main/java/com/apitable/client/api/RecordApi.java +++ b/apitable.java/client/src/main/java/com/apitable/client/api/RecordApi.java @@ -39,6 +39,7 @@ import com.apitable.client.api.model.Record; import com.apitable.client.api.model.Records; import com.apitable.client.api.model.UpdateRecordRequest; +import com.apitable.core.http.DefaultHttpClient; import com.apitable.core.http.GenericTypeReference; import com.apitable.core.http.HttpHeader; import com.apitable.core.utils.CollectionUtil; @@ -62,6 +63,10 @@ public Stream getRecordsAsStream(String datasheetId) throws ApiException } public List getRecords(String datasheetId, int page, int itemsPerPage) throws ApiException { + return getRecords(datasheetId, page, itemsPerPage, false); + } + + public List getRecords(String datasheetId, int page, int itemsPerPage, boolean isV3) throws ApiException { if (page < 0 || itemsPerPage < 0) { throw new ApiException("page or itemsPerPage don't set right"); } @@ -69,7 +74,11 @@ public List getRecords(String datasheetId, int page, int itemsPerPage) t Map uriVariables = queryParam.toMap(); GenericTypeReference>> reference = new GenericTypeReference>>() {}; String uri = String.format(PATH, datasheetId) + MapUtil.extractKeyToVariables(uriVariables); - HttpResult> result = getDefaultHttpClient().get(uri, new HttpHeader(), reference, uriVariables); + DefaultHttpClient client = getDefaultHttpClient(); + if (isV3) { + client = getHttpClientWithVersion(ApiHttpClient.ApiVersion.V3); + } + HttpResult> result = client.get(uri, new HttpHeader(), reference, uriVariables); return result.getData().getRecords(); } @@ -77,6 +86,14 @@ public Pager getRecords(String datasheetId) throws ApiException { return new Pager<>(this, String.format(PATH, datasheetId), getDefaultPerPage(), Record.class); } + + public Pager getRecords(String datasheetId, boolean isV3) throws ApiException { + if (isV3) { + return new Pager<>(this, String.format(PATH, datasheetId), getDefaultPerPage(), Record.class, true); + } + return getRecords(datasheetId); + } + public Pager getRecords(String datasheetId, int itemsPerPage) throws ApiException { return new Pager<>(this, String.format(PATH, datasheetId), itemsPerPage, Record.class); } @@ -85,6 +102,13 @@ public Pager getRecords(String datasheetId, ApiQueryParam queryParam) th return new Pager<>(this, String.format(PATH, datasheetId), queryParam, Record.class); } + public Pager getRecords(String datasheetId, ApiQueryParam queryParam, boolean isV3) throws ApiException { + if (isV3) { + return new Pager<>(this, String.format(PATH, datasheetId), queryParam, Record.class, true); + } + return new Pager<>(this, String.format(PATH, datasheetId), queryParam, Record.class); + } + public List addRecords(String datasheetId, CreateRecordRequest record) throws ApiException { if (!StringUtil.hasText(datasheetId)) { throw new ApiException("datasheet id must be not null"); diff --git a/apitable.java/client/src/main/java/com/apitable/client/api/http/ApiHttpClient.java b/apitable.java/client/src/main/java/com/apitable/client/api/http/ApiHttpClient.java index a879eb4..7022d71 100644 --- a/apitable.java/client/src/main/java/com/apitable/client/api/http/ApiHttpClient.java +++ b/apitable.java/client/src/main/java/com/apitable/client/api/http/ApiHttpClient.java @@ -36,6 +36,8 @@ public class ApiHttpClient { public enum ApiVersion { V1, V2, + + V3 ; public String getApiNamespace() { diff --git a/apitable.java/client/src/main/java/com/apitable/client/api/model/Pager.java b/apitable.java/client/src/main/java/com/apitable/client/api/model/Pager.java index f093aa4..63ed4aa 100644 --- a/apitable.java/client/src/main/java/com/apitable/client/api/model/Pager.java +++ b/apitable.java/client/src/main/java/com/apitable/client/api/model/Pager.java @@ -32,6 +32,8 @@ import com.apitable.client.api.Constants; import com.apitable.client.api.exception.ApiException; import com.apitable.client.api.http.AbstractApi; +import com.apitable.client.api.http.ApiHttpClient; +import com.apitable.core.http.DefaultHttpClient; import com.apitable.core.http.GenericTypeReference; import com.apitable.core.http.HttpHeader; import com.apitable.core.utils.JacksonConverter; @@ -64,8 +66,7 @@ public class Pager implements Iterator> { private JavaType javaType; - public Pager(AbstractApi api, String url, int itemsPerPage, Class type) throws ApiException { - javaType = JacksonConverter.getCollectionJavaType(type); + public Pager(AbstractApi api, String url, int itemsPerPage, Class type, boolean isV3) throws ApiException {javaType = JacksonConverter.getCollectionJavaType(type); this.api = api; this.url = url; @@ -78,7 +79,11 @@ public Pager(AbstractApi api, String url, int itemsPerPage, Class type) throw Map uriVariables = this.queryParam.toMap(); GenericTypeReference>> reference = new GenericTypeReference>>() {}; String uri = url + MapUtil.extractKeyToVariables(uriVariables); - HttpResult> result = api.getDefaultHttpClient().get(uri, new HttpHeader(), reference, uriVariables); + DefaultHttpClient client = api.getDefaultHttpClient(); + if (isV3) { + client = api.getHttpClientWithVersion(ApiHttpClient.ApiVersion.V3); + } + HttpResult> result = client.get(uri, new HttpHeader(), reference, uriVariables); if (result.getData().getRecords() != null) { this.currentItems = JacksonConverter.toGenericBean(result.getData().getRecords(), javaType); if (this.currentItems == null) { @@ -93,7 +98,11 @@ public Pager(AbstractApi api, String url, int itemsPerPage, Class type) throw this.totalPages = this.totalItems == 0 ? 1 : ((this.totalItems - 1) / this.itemsPerPage + 1); } - public Pager(AbstractApi api, String url, ApiQueryParam queryParam, Class type) throws ApiException { + public Pager(AbstractApi api, String url, int itemsPerPage, Class type) throws ApiException { + this(api, url, itemsPerPage, type, false); + } + + public Pager(AbstractApi api, String url, ApiQueryParam queryParam, Class type, boolean isV3) throws ApiException { this.api = api; this.url = url; this.queryParam = queryParam; @@ -101,7 +110,11 @@ public Pager(AbstractApi api, String url, ApiQueryParam queryParam, Class typ GenericTypeReference>> reference = new GenericTypeReference>>() {}; Map uriVariables = this.queryParam.toMap(); String uri = url + MapUtil.extractKeyToVariables(uriVariables); - HttpResult> result = api.getDefaultHttpClient().get(uri, new HttpHeader(), reference, uriVariables); + DefaultHttpClient client = api.getDefaultHttpClient(); + if (isV3) { + client = api.getHttpClientWithVersion(ApiHttpClient.ApiVersion.V3); + } + HttpResult> result = client.get(uri, new HttpHeader(), reference, uriVariables); if (result.getData().getRecords() != null) { this.currentItems = JacksonConverter.toGenericBean(result.getData().getRecords(), javaType); if (this.currentItems == null) { @@ -116,6 +129,10 @@ public Pager(AbstractApi api, String url, ApiQueryParam queryParam, Class typ this.totalPages = this.totalItems == 0 ? 1 : ((this.totalItems - 1) / this.itemsPerPage + 1); } + public Pager(AbstractApi api, String url, ApiQueryParam queryParam, Class type) throws ApiException { + this(api, url, queryParam, type, false); + } + public int getCurrentPage() { return currentPage; } diff --git a/apitable.java/pom.xml b/apitable.java/pom.xml index f24f956..48a7dd8 100644 --- a/apitable.java/pom.xml +++ b/apitable.java/pom.xml @@ -12,7 +12,7 @@ https://github.com/apitable/apitable-sdks/tree/develop/apitable.java - 1.3.0 + 2.0.0-beta.4 1.8 ${java.version} ${java.version} diff --git a/apitable.js/.version b/apitable.js/.version index 589268e..c9be7a5 100644 --- a/apitable.js/.version +++ b/apitable.js/.version @@ -1 +1 @@ -1.3.0 \ No newline at end of file +2.0.0-beta.4 \ No newline at end of file diff --git a/apitable.js/lib/apitable.ts b/apitable.js/lib/apitable.ts index 1277722..8d358ed 100644 --- a/apitable.js/lib/apitable.ts +++ b/apitable.js/lib/apitable.ts @@ -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 { DEFAULT_HOST, DEFAULT_REQUEST_TIMEOUT, DATA_BUS_VERSION_PREFIX, DEFAULT_VERSION_PREFIX, FUSION_PATH_PREFIX } from "./const"; import { Datasheet } from "./datasheet"; import { IHttpResponse, IAPITableClientConfig } from "./interface"; import { NodeManager } from "./node"; @@ -75,12 +75,18 @@ export class APITable { timeout?: number; }): Promise> { const { path, params, method, data, headers, timeout } = config; + 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); + } let result: IHttpResponse; try { result = ( await this.axios.request>({ timeout, - url: path.includes(FUSION_PATH_PREFIX) ? path : DEFAULT_VERSION_PREFIX.concat(path), + url: urlPath, method, params: { fieldKey: this.config.fieldKey, @@ -145,4 +151,8 @@ export class APITable { space(spaceId: string) { return new SpaceManager(this, spaceId); } + + public isV3() { + return true; + } } diff --git a/apitable.js/lib/const.ts b/apitable.js/lib/const.ts index 8a1cdb6..efbbd93 100644 --- a/apitable.js/lib/const.ts +++ b/apitable.js/lib/const.ts @@ -7,6 +7,7 @@ export const DST_MAX_RECORDS = 50000; // Maximum number of records in a single d export const DEFAULT_HOST = 'https://api.apitable.com'; 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; diff --git a/apitable.js/lib/interface/record.ts b/apitable.js/lib/interface/record.ts index 3dfc55b..2cf7b71 100644 --- a/apitable.js/lib/interface/record.ts +++ b/apitable.js/lib/interface/record.ts @@ -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; } diff --git a/apitable.js/package.json b/apitable.js/package.json index 109874d..719d468 100644 --- a/apitable.js/package.json +++ b/apitable.js/package.json @@ -1,6 +1,6 @@ { "name": "apitable", - "version": "1.3.0", + "version": "2.0.0-beta.4", "description": "APITable JavaScript SDK", "main": "./es/index.js", "scripts": { diff --git a/apitable.py/.version b/apitable.py/.version new file mode 100644 index 0000000..c9be7a5 --- /dev/null +++ b/apitable.py/.version @@ -0,0 +1 @@ +2.0.0-beta.4 \ No newline at end of file diff --git a/apitable.py/apitable/datasheet/datasheet.py b/apitable.py/apitable/datasheet/datasheet.py index 3a6d438..682724b 100644 --- a/apitable.py/apitable/datasheet/datasheet.py +++ b/apitable.py/apitable/datasheet/datasheet.py @@ -57,6 +57,11 @@ def _record_api_endpoint(self): return urljoin(self.apitable.api_base, f"/fusion/v1/datasheets/{self.id}/records") + @property + def _record_api_endpoint_v3(self): + return urljoin(self.apitable.api_base, + f"/fusion/v3/datasheets/{self.id}/records") + @property @timed_lru_cache(seconds=300) def fields(self): @@ -137,6 +142,12 @@ def get_records(self, **kwargs): """ Paginate to get data """ + + is_v3 = bool(kwargs.get("isV3", False)) + endpoint = self._record_api_endpoint + if is_v3: + endpoint = self._record_api_endpoint_v3 + params = {} for key in kwargs: if key in API_GET_DATASHEET_QS_SET: @@ -147,7 +158,7 @@ def get_records(self, **kwargs): else: raise ErrorSortParams('The format of the sort parameter is incorrect') params.update({key: params_value}) - resp = self.apitable.request.get(self._record_api_endpoint, params=params) + resp = self.apitable.request.get(endpoint, params=params) return handle_response(resp, GETRecordResponse) def get_records_all(self, **kwargs) -> List[RawRecord]: diff --git a/apitable.py/pyproject.toml b/apitable.py/pyproject.toml index 434853c..b47ac98 100644 --- a/apitable.py/pyproject.toml +++ b/apitable.py/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "apitable" -version = "1.4.1" +version = "2.0.0-beta.4" description = "APITable OpenAPI Python SDK" authors = ["APITable Ltd. "] readme = "README.md" diff --git a/apitable.py/setup.py b/apitable.py/setup.py new file mode 100644 index 0000000..0aeb053 --- /dev/null +++ b/apitable.py/setup.py @@ -0,0 +1,28 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +with open(".version", "r") as fh: + version_number = fh.read() + +setuptools.setup( + name="apitable", + version=version_number, + author="apitable", + author_email="dev@apitable.com", + description="Apitable Python SDK", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/apitable/apitable-sdks", + packages=[ + "apitable", "apitable.datasheet", "apitable.types", "apitable.node", "apitable.space", "apitable.unit" + ], + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires=">=3.6", + install_requires=["requests<=2.31.0", "pydantic==1.7", "environs<=9.5.0"], +) \ No newline at end of file