Skip to content

Commit 73b3022

Browse files
committed
Demo dev-console-snippets
1 parent 76a85ef commit 73b3022

10 files changed

+263
-0
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/src/generatedNoCheck/
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import Handlebars from "handlebars";
19+
import * as fs from "node:fs";
20+
import * as templates from "./templates.mjs";
21+
22+
let indexContents = "";
23+
24+
for (const c of ["loadObjectPageGuide"]) {
25+
const h = Handlebars.compile(templates[c]);
26+
27+
fs.writeFileSync(
28+
`./src/generatedNoCheck/${c}.ts`,
29+
`import {client} from "../client.js";\n`
30+
+ h({
31+
objectType: "Employee",
32+
packageName: "@osdk/e2e.generated.catchall",
33+
titleProperty: "firstName",
34+
}),
35+
);
36+
37+
indexContents = `export const ${c} = ${JSON.stringify(templates[c])}\n\n`;
38+
}
39+
40+
fs.writeFileSync(`./src/generatedNoCheck/index.ts`, indexContents);
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@osdk/dev-console-snippets",
3+
"version": "0.0.0",
4+
"license": "Apache-2.0",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/palantir/osdk-ts.git"
8+
},
9+
"exports": {
10+
".": {
11+
"browser": "./build/browser/index.js",
12+
"import": "./build/esm/index.js"
13+
},
14+
"./*": {
15+
"browser": "./build/browser/public/*.js",
16+
"import": "./build/esm/public/*.js"
17+
}
18+
},
19+
"scripts": {
20+
"check-attw": "monorepo.tool.attw esm",
21+
"check-spelling": "cspell --quiet .",
22+
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
23+
"codegen": "node codegen.mjs",
24+
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
25+
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
26+
"transpile": "monorepo.tool.transpile"
27+
},
28+
"dependencies": {},
29+
"devDependencies": {
30+
"@osdk/client": "workspace:*",
31+
"@osdk/e2e.generated.catchall": "workspace:*",
32+
"@osdk/monorepo.api-extractor": "workspace:~",
33+
"@osdk/monorepo.tsconfig": "workspace:~",
34+
"@osdk/monorepo.tsup": "workspace:~",
35+
"handlebars": "^4.7.8",
36+
"outdent": "^0.8.0",
37+
"typescript": "~5.5.4"
38+
},
39+
"publishConfig": {
40+
"access": "public"
41+
},
42+
"files": [
43+
"build/cjs",
44+
"build/esm",
45+
"build/browser",
46+
"CHANGELOG.md",
47+
"package.json",
48+
"templates",
49+
"*.d.ts"
50+
],
51+
"module": "./build/esm/index.js",
52+
"types": "./build/esm/index.d.ts",
53+
"type": "module"
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { createClient } from "@osdk/client";
18+
export const client = createClient("", "", () => Promise.resolve(""));
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export { loadObjectPageGuide } from "./generatedNoCheck/index.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { outdent } from "outdent";
18+
19+
export const loadObjectPageGuide = outdent`
20+
import { {{objectType}} } from "{{{packageName}}}";
21+
import { isOk, Osdk, PageResult, Result } from "@osdk/client";
22+
const firstPage: Result<PageResult<Osdk.Instance<{{objectType}}>>>
23+
= await client({{objectType}}).fetchPageWithErrors({ $pageSize: 30 });
24+
if (isOk(firstPage)) {
25+
const secondPage: Result<PageResult<Osdk.Instance<{{objectType}}, never, "{{titleProperty}}">>>
26+
// You can also down select properties to only get the properties you need from the object
27+
= await client({{objectType}}).fetchPageWithErrors({ $select: ["{{titleProperty}}"], $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });
28+
const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;
29+
const object = objects[0];
30+
}
31+
// To fetch a page without a result wrapper, use fetchPage with a try/catch instead
32+
try {
33+
const firstPage: PageResult<Osdk.Instance<{{objectType}}>>
34+
= await client({{objectType}}).fetchPage({ $pageSize: 30 });
35+
const secondPage: PageResult<Osdk.Instance<{{objectType}}>>
36+
= await client({{objectType}}).fetchPage({ $pageSize: 30, $nextPageToken: firstPage.nextPageToken });
37+
const objects = [...firstPage.data, ...secondPage.data];
38+
const object = objects[0];
39+
}
40+
catch (e) {
41+
console.error(e);
42+
}
43+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "@osdk/monorepo.tsconfig/base.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build/esm"
6+
},
7+
"include": [
8+
"./src/**/*"
9+
],
10+
"references": []
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { defineConfig } from "tsup";
18+
19+
export default defineConfig(async (options) =>
20+
(await import("@osdk/monorepo.tsup")).default(options, {
21+
esmOnly: true,
22+
})
23+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { configDefaults, defineConfig } from "vitest/config";
18+
19+
export default defineConfig({
20+
test: {
21+
pool: "forks",
22+
exclude: [...configDefaults.exclude, "**/build/**/*"],
23+
},
24+
});

pnpm-lock.yaml

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)