Skip to content

Commit

Permalink
Merge pull request #34 from palantir/ssanjay/addSharedTestLegacy
Browse files Browse the repository at this point in the history
Trying to add shared testing infra for legacy client
  • Loading branch information
ssanjay1 authored Feb 6, 2024
2 parents 8374bed + 673344c commit e02924b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ tsconfig.tsbuildinfo
/tmp/

packages/client/src/generatedNoCheck
packages/legacy-client/src/generatedNoCheck

5 changes: 5 additions & 0 deletions packages/gateway/changelog/@unreleased/pr-34.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Trying to add shared testing infra for legacy client
links:
- https://github.com/palantir/osdk-ts/pull/34
5 changes: 5 additions & 0 deletions packages/generator/changelog/@unreleased/pr-34.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Trying to add shared testing infra for legacy client
links:
- https://github.com/palantir/osdk-ts/pull/34
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function generateClientSdkVersionOneDotOne(
const queriesDir = path.join(outDir, "ontology", "queries");

await verifyOutdir(outDir, fs);
await fs.mkdir(outDir, { recursive: true });

const sanitizedOntology = sanitizeMetadata(ontology);
await generateFoundryClientFile(fs, outDir, importExt);
Expand Down
5 changes: 5 additions & 0 deletions packages/legacy-client/changelog/@unreleased/pr-34.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Trying to add shared testing infra for legacy client
links:
- https://github.com/palantir/osdk-ts/pull/34
59 changes: 59 additions & 0 deletions packages/legacy-client/generateMockOntology.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// @ts-check

import { generateClientSdkVersionOneDotOne } from "@osdk/generator";
import { stubData } from "@osdk/shared.test";
import { rmSync } from "node:fs";
import { mkdir, readdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const outDir = join(__dirname, "src", "generatedNoCheck");

try {
rmSync(outDir, { recursive: true, force: true });
} catch (e) {
// ignored, only needed for regeneration
}

const ontologyWithoutUnsupportedAction = {
...stubData.fullOntology,
actionTypes: {
...stubData.fullOntology.actionTypes,
},
};

// the generator does not correctly handle actions that point to object types outside of the ontology
// this step is typically handled by code upstream of the actual generator
delete ontologyWithoutUnsupportedAction.actionTypes["unsupported-action"];

await generateClientSdkVersionOneDotOne(
ontologyWithoutUnsupportedAction,
"typescript-sdk/dev osdk-cli/dev",
{
writeFile: (path, contents) => {
return writeFile(path, contents, "utf-8");
},
mkdir: async (path, options) => {
await mkdir(path, options);
},
readdir: async (path) => readdir(path),
},
outDir,
);
2 changes: 2 additions & 0 deletions packages/legacy-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"scripts": {
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"codegen": "node ./generateMockOntology.mjs",
"dev:transpile": "tsup --watch",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
Expand All @@ -37,6 +38,7 @@
"tiny-invariant": "^1.3.1"
},
"devDependencies": {
"@osdk/generator": "workspace:*",
"@osdk/shared.test": "workspace:*",
"@types/luxon": "^3.3.3",
"@types/ngeohash": "^0.6.4",
Expand Down
3 changes: 3 additions & 0 deletions packages/legacy-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
{
"path": "../shared.net"
},
{
"path": "../generator"
},
{
"path": "../shared.test"
}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e02924b

Please sign in to comment.