From 81d2448a27b4fe8223fdd9b295d4ca48751c604e Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Sun, 26 Jan 2025 00:12:41 +0000 Subject: [PATCH] chore(typescript): update typescript-sdk seed --- .../pagination/.mock/definition/users.yml | 27 +++- seed/ts-sdk/pagination/reference.md | 67 ++++++++ .../pagination/resolved-snippet-templates.md | 16 ++ seed/ts-sdk/pagination/snippet-templates.json | 150 ++++++++++++++++++ seed/ts-sdk/pagination/snippet.json | 11 ++ .../src/api/resources/users/client/Client.ts | 97 +++++++++++ .../ListUsersDoubleOffsetPaginationRequest.ts | 31 ++++ .../resources/users/client/requests/index.ts | 1 + 8 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 seed/ts-sdk/pagination/src/api/resources/users/client/requests/ListUsersDoubleOffsetPaginationRequest.ts diff --git a/seed/ts-sdk/pagination/.mock/definition/users.yml b/seed/ts-sdk/pagination/.mock/definition/users.yml index b8a1df01ccc..a135137954d 100644 --- a/seed/ts-sdk/pagination/.mock/definition/users.yml +++ b/seed/ts-sdk/pagination/.mock/definition/users.yml @@ -152,6 +152,31 @@ service: the next page of results. response: ListUsersPaginationResponse + listWithDoubleOffsetPagination: + pagination: + offset: $request.page + results: $response.data + method: GET + path: "" + request: + name: ListUsersDoubleOffsetPaginationRequest + query-parameters: + page: + type: optional + docs: Defaults to first page + default: 0 + per_page: + type: optional + docs: Defaults to per page + order: + type: optional + starting_after: + type: optional + docs: | + The cursor used for pagination in order to fetch + the next page of results. + response: ListUsersPaginationResponse + listWithBodyOffsetPagination: pagination: offset: $request.pagination.page @@ -267,4 +292,4 @@ service: query-parameters: offset: type: optional - response: UsernameContainer \ No newline at end of file + response: UsernameContainer diff --git a/seed/ts-sdk/pagination/reference.md b/seed/ts-sdk/pagination/reference.md index b66a7edfc27..f5736495310 100644 --- a/seed/ts-sdk/pagination/reference.md +++ b/seed/ts-sdk/pagination/reference.md @@ -201,6 +201,73 @@ while (page.hasNextPage()) { +
client.users.listWithDoubleOffsetPagination({ ...params }) -> core.Page +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```typescript +const response = await client.users.listWithDoubleOffsetPagination({ + page: 1.1, + perPage: 1.1, + order: "asc", + startingAfter: "starting_after", +}); +for await (const item of response) { + console.log(item); +} + +// Or you can manually iterate page-by-page +const page = await client.users.listWithDoubleOffsetPagination({ + page: 1.1, + perPage: 1.1, + order: "asc", + startingAfter: "starting_after", +}); +while (page.hasNextPage()) { + page = page.getNextPage(); +} +``` + +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `SeedPagination.ListUsersDoubleOffsetPaginationRequest` + +
+
+ +
+
+ +**requestOptions:** `Users.RequestOptions` + +
+
+
+
+ +
+
+
+
client.users.listWithBodyOffsetPagination({ ...params }) -> core.Page
diff --git a/seed/ts-sdk/pagination/resolved-snippet-templates.md b/seed/ts-sdk/pagination/resolved-snippet-templates.md index bfbcb26276f..f3b09807498 100644 --- a/seed/ts-sdk/pagination/resolved-snippet-templates.md +++ b/seed/ts-sdk/pagination/resolved-snippet-templates.md @@ -46,6 +46,22 @@ await client.users.listWithOffsetPagination({ ``` +```typescript +import { SeedPaginationClient } from "@fern/pagination"; + +const client = new SeedPaginationClient({ + environment: "YOUR_BASE_URL", + token: "YOUR_TOKEN", +}); +await client.users.listWithDoubleOffsetPagination({ + page: 1.1, + perPage: 1.1, + startingAfter: "starting_after", +}); + +``` + + ```typescript import { SeedPaginationClient } from "@fern/pagination"; diff --git a/seed/ts-sdk/pagination/snippet-templates.json b/seed/ts-sdk/pagination/snippet-templates.json index 0be8d0d9684..87d1bb287dd 100644 --- a/seed/ts-sdk/pagination/snippet-templates.json +++ b/seed/ts-sdk/pagination/snippet-templates.json @@ -411,6 +411,156 @@ "type": "v1" } }, + { + "sdk": { + "package": "@fern/pagination", + "version": "0.0.1", + "type": "typescript" + }, + "endpointId": { + "path": "/users", + "method": "GET", + "identifierOverride": "endpoint_users.listWithDoubleOffsetPagination" + }, + "snippetTemplate": { + "clientInstantiation": { + "imports": [ + "import { SeedPaginationClient } from \"@fern/pagination\";" + ], + "templateString": "const client = new SeedPaginationClient($FERN_INPUT);", + "isOptional": false, + "inputDelimiter": ",", + "templateInputs": [ + { + "value": { + "imports": [], + "templateString": "{ $FERN_INPUT }", + "isOptional": true, + "templateInputs": [ + { + "value": { + "imports": [], + "templateString": "environment: \"YOUR_BASE_URL\"", + "isOptional": false, + "templateInputs": [], + "type": "generic" + }, + "type": "template" + }, + { + "value": { + "imports": [], + "templateString": "token: $FERN_INPUT", + "isOptional": false, + "templateInputs": [ + { + "location": "AUTH", + "path": "token", + "type": "payload" + } + ], + "type": "generic" + }, + "type": "template" + } + ], + "type": "generic" + }, + "type": "template" + } + ], + "type": "generic" + }, + "functionInvocation": { + "imports": [], + "templateString": "await client.users.listWithDoubleOffsetPagination(\n\t$FERN_INPUT\n)", + "isOptional": false, + "inputDelimiter": ",\n\t", + "templateInputs": [ + { + "value": { + "imports": [], + "templateString": "{\n\t\t$FERN_INPUT\n\t}", + "isOptional": true, + "inputDelimiter": ",\n\t\t", + "templateInputs": [ + { + "value": { + "imports": [], + "templateString": "page: $FERN_INPUT", + "isOptional": true, + "templateInputs": [ + { + "location": "QUERY", + "path": "page", + "type": "payload" + } + ], + "type": "generic" + }, + "type": "template" + }, + { + "value": { + "imports": [], + "templateString": "perPage: $FERN_INPUT", + "isOptional": true, + "templateInputs": [ + { + "location": "QUERY", + "path": "per_page", + "type": "payload" + } + ], + "type": "generic" + }, + "type": "template" + }, + { + "value": { + "imports": [], + "isOptional": true, + "values": { + "asc": "\"asc\"", + "desc": "\"desc\"" + }, + "templateString": "order: $FERN_INPUT", + "templateInput": { + "location": "QUERY", + "path": "order", + "type": "payload" + }, + "type": "enum" + }, + "type": "template" + }, + { + "value": { + "imports": [], + "templateString": "startingAfter: $FERN_INPUT", + "isOptional": true, + "templateInputs": [ + { + "location": "QUERY", + "path": "starting_after", + "type": "payload" + } + ], + "type": "generic" + }, + "type": "template" + } + ], + "type": "generic" + }, + "type": "template" + } + ], + "type": "generic" + }, + "type": "v1" + } + }, { "sdk": { "package": "@fern/pagination", diff --git a/seed/ts-sdk/pagination/snippet.json b/seed/ts-sdk/pagination/snippet.json index 39afa9218d7..4081eb2919a 100644 --- a/seed/ts-sdk/pagination/snippet.json +++ b/seed/ts-sdk/pagination/snippet.json @@ -33,6 +33,17 @@ "client": "import { SeedPaginationClient } from \"@fern/pagination\";\n\nconst client = new SeedPaginationClient({ environment: \"YOUR_BASE_URL\", token: \"YOUR_TOKEN\" });\nconst response = await client.users.listWithOffsetPagination({\n page: 1,\n perPage: 1,\n order: \"asc\",\n startingAfter: \"starting_after\"\n});\nfor await (const item of response) {\n console.log(item);\n}\n\n// Or you can manually iterate page-by-page\nconst page = await client.users.listWithOffsetPagination({\n page: 1,\n perPage: 1,\n order: \"asc\",\n startingAfter: \"starting_after\"\n});\nwhile (page.hasNextPage()) {\n page = page.getNextPage();\n}\n" } }, + { + "id": { + "path": "/users", + "method": "GET", + "identifier_override": "endpoint_users.listWithDoubleOffsetPagination" + }, + "snippet": { + "type": "typescript", + "client": "import { SeedPaginationClient } from \"@fern/pagination\";\n\nconst client = new SeedPaginationClient({ environment: \"YOUR_BASE_URL\", token: \"YOUR_TOKEN\" });\nconst response = await client.users.listWithDoubleOffsetPagination({\n page: 1.1,\n perPage: 1.1,\n order: \"asc\",\n startingAfter: \"starting_after\"\n});\nfor await (const item of response) {\n console.log(item);\n}\n\n// Or you can manually iterate page-by-page\nconst page = await client.users.listWithDoubleOffsetPagination({\n page: 1.1,\n perPage: 1.1,\n order: \"asc\",\n startingAfter: \"starting_after\"\n});\nwhile (page.hasNextPage()) {\n page = page.getNextPage();\n}\n" + } + }, { "id": { "path": "/users", diff --git a/seed/ts-sdk/pagination/src/api/resources/users/client/Client.ts b/seed/ts-sdk/pagination/src/api/resources/users/client/Client.ts index d6cb6766de4..cf45cb6980b 100644 --- a/seed/ts-sdk/pagination/src/api/resources/users/client/Client.ts +++ b/seed/ts-sdk/pagination/src/api/resources/users/client/Client.ts @@ -305,6 +305,103 @@ export class Users { }); } + /** + * @param {SeedPagination.ListUsersDoubleOffsetPaginationRequest} request + * @param {Users.RequestOptions} requestOptions - Request-specific configuration. + * + * @example + * await client.users.listWithDoubleOffsetPagination({ + * page: 1.1, + * perPage: 1.1, + * order: "asc", + * startingAfter: "starting_after" + * }) + */ + public async listWithDoubleOffsetPagination( + request: SeedPagination.ListUsersDoubleOffsetPaginationRequest = {}, + requestOptions?: Users.RequestOptions, + ): Promise> { + const list = async ( + request: SeedPagination.ListUsersDoubleOffsetPaginationRequest, + ): Promise => { + const { page, perPage, order, startingAfter } = request; + const _queryParams: Record = {}; + if (page != null) { + _queryParams["page"] = page.toString(); + } + if (perPage != null) { + _queryParams["per_page"] = perPage.toString(); + } + if (order != null) { + _queryParams["order"] = serializers.Order.jsonOrThrow(order, { unrecognizedObjectKeys: "strip" }); + } + if (startingAfter != null) { + _queryParams["starting_after"] = startingAfter; + } + const _response = await core.fetcher({ + url: urlJoin( + (await core.Supplier.get(this._options.baseUrl)) ?? + (await core.Supplier.get(this._options.environment)), + "/users", + ), + method: "GET", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@fern/pagination", + "X-Fern-SDK-Version": "0.0.1", + "User-Agent": "@fern/pagination/0.0.1", + "X-Fern-Runtime": core.RUNTIME.type, + "X-Fern-Runtime-Version": core.RUNTIME.version, + ...requestOptions?.headers, + }, + contentType: "application/json", + queryParameters: _queryParams, + requestType: "json", + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions?.maxRetries, + abortSignal: requestOptions?.abortSignal, + }); + if (_response.ok) { + return serializers.ListUsersPaginationResponse.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + if (_response.error.reason === "status-code") { + throw new errors.SeedPaginationError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + switch (_response.error.reason) { + case "non-json": + throw new errors.SeedPaginationError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.SeedPaginationTimeoutError("Timeout exceeded when calling GET /users."); + case "unknown": + throw new errors.SeedPaginationError({ + message: _response.error.errorMessage, + }); + } + }; + let _offset = request?.page != null ? request?.page : 1; + return new core.Pageable({ + response: await list(request), + hasNextPage: (response) => (response?.data ?? []).length > 0, + getItems: (response) => response?.data ?? [], + loadPage: (_response) => { + _offset += 1; + return list(core.setObjectProperty(request, "page", _offset)); + }, + }); + } + /** * @param {SeedPagination.ListUsersBodyOffsetPaginationRequest} request * @param {Users.RequestOptions} requestOptions - Request-specific configuration. diff --git a/seed/ts-sdk/pagination/src/api/resources/users/client/requests/ListUsersDoubleOffsetPaginationRequest.ts b/seed/ts-sdk/pagination/src/api/resources/users/client/requests/ListUsersDoubleOffsetPaginationRequest.ts new file mode 100644 index 00000000000..bfba76691a4 --- /dev/null +++ b/seed/ts-sdk/pagination/src/api/resources/users/client/requests/ListUsersDoubleOffsetPaginationRequest.ts @@ -0,0 +1,31 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +import * as SeedPagination from "../../../../index"; + +/** + * @example + * { + * page: 1.1, + * perPage: 1.1, + * order: "asc", + * startingAfter: "starting_after" + * } + */ +export interface ListUsersDoubleOffsetPaginationRequest { + /** + * Defaults to first page + */ + page?: number; + /** + * Defaults to per page + */ + perPage?: number; + order?: SeedPagination.Order; + /** + * The cursor used for pagination in order to fetch + * the next page of results. + */ + startingAfter?: string; +} diff --git a/seed/ts-sdk/pagination/src/api/resources/users/client/requests/index.ts b/seed/ts-sdk/pagination/src/api/resources/users/client/requests/index.ts index 9831fff2ace..ac6df298a48 100644 --- a/seed/ts-sdk/pagination/src/api/resources/users/client/requests/index.ts +++ b/seed/ts-sdk/pagination/src/api/resources/users/client/requests/index.ts @@ -1,6 +1,7 @@ export { type ListUsersCursorPaginationRequest } from "./ListUsersCursorPaginationRequest"; export { type ListUsersBodyCursorPaginationRequest } from "./ListUsersBodyCursorPaginationRequest"; export { type ListUsersOffsetPaginationRequest } from "./ListUsersOffsetPaginationRequest"; +export { type ListUsersDoubleOffsetPaginationRequest } from "./ListUsersDoubleOffsetPaginationRequest"; export { type ListUsersBodyOffsetPaginationRequest } from "./ListUsersBodyOffsetPaginationRequest"; export { type ListUsersOffsetStepPaginationRequest } from "./ListUsersOffsetStepPaginationRequest"; export { type ListWithOffsetPaginationHasNextPageRequest } from "./ListWithOffsetPaginationHasNextPageRequest";