Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo dev-console-snippets #925

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ericanderson
Copy link
Member

@ericanderson ericanderson commented Oct 24, 2024

Generated ./src/generatedNoCheck/loadObjectPageGuide.ts

import {client} from "../client.js";
import { Employee } from "@osdk/e2e.generated.catchall";
import { isOk, Osdk, PageResult, Result } from "@osdk/client";
const firstPage: Result<PageResult<Osdk.Instance<Employee>>>
    = await client(Employee).fetchPageWithErrors({ $pageSize: 30 });
if (isOk(firstPage)) {
    const secondPage: Result<PageResult<Osdk.Instance<Employee, never, "firstName">>>
    // You can also down select properties to only get the properties you need from the object
    = await client(Employee).fetchPageWithErrors({ $select: ["firstName"], $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });
    const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;
    const object = objects[0];
}
// To fetch a page without a result wrapper, use fetchPage with a try/catch instead
try {
    const firstPage: PageResult<Osdk.Instance<Employee>>
        = await client(Employee).fetchPage({ $pageSize: 30 });
    const secondPage: PageResult<Osdk.Instance<Employee>>
    = await client(Employee).fetchPage({ $pageSize: 30, $nextPageToken: firstPage.nextPageToken });
    const objects = [...firstPage.data, ...secondPage.data];
    const object = objects[0];
}
catch (e) {
    console.error(e);
}

Generated ./src/generatedNoCheck/index.ts:

export const loadObjectPageGuide = "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { isOk, Osdk, PageResult, Result } from \"@osdk/client\";\nconst firstPage: Result<PageResult<Osdk.Instance<{{objectType}}>>>\n    = await client({{objectType}}).fetchPageWithErrors({ $pageSize: 30 });\nif (isOk(firstPage)) {\n    const secondPage: Result<PageResult<Osdk.Instance<{{objectType}}, never, \"{{titleProperty}}\">>>\n    // You can also down select properties to only get the properties you need from the object\n    = await client({{objectType}}).fetchPageWithErrors({ $select: [\"{{titleProperty}}\"], $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });\n    const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;\n    const object = objects[0];\n}\n// To fetch a page without a result wrapper, use fetchPage with a try/catch instead\ntry {\n    const firstPage: PageResult<Osdk.Instance<{{objectType}}>>\n        = await client({{objectType}}).fetchPage({ $pageSize: 30 });\n    const secondPage: PageResult<Osdk.Instance<{{objectType}}>>\n    = await client({{objectType}}).fetchPage({ $pageSize: 30, $nextPageToken: firstPage.nextPageToken });\n    const objects = [...firstPage.data, ...secondPage.data];\n    const object = objects[0];\n}\ncatch (e) {\n    console.error(e);\n}"

@ericanderson ericanderson force-pushed the ea.demo-dev-console-snipets branch from 73b3022 to 9ef7201 Compare October 24, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant