Skip to content

Commit

Permalink
Merge branch 'main' into ssanjay/bulkActions
Browse files Browse the repository at this point in the history
  • Loading branch information
ssanjay1 committed Feb 8, 2024
2 parents c767eae + c8854e4 commit dcd0486
Show file tree
Hide file tree
Showing 148 changed files with 1,867 additions and 443 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

21 changes: 21 additions & 0 deletions examples/basic/cli/src/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ export async function typeChecks(client: Client<Ontology>) {
);
}

// just a demo of aggregations
{
const q = await client.objects.ObjectTypeWithAllPropertyTypes
.aggregateOrThrow({
select: {
integer: "sum",
float: "sum",
decimal: "sum",
short: ["max"],
string: "approximateDistinct",
},
groupBy: {
string: "exact",
stringArray: "exact",
},
orderBy: {
group: "string",
},
});
}

// object $link examples
{
const page = await client.objectSet("Employee").where({
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/changelog/@unreleased/pr-42.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Move argv override logging to middleware
links:
- https://github.com/palantir/osdk-ts/pull/42
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dev:transpile": "tsup --watch",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"test": "vitest run",
"test:watch": "vitest",
"transpile": "tsup",
"transpileWatch": "tsup --watch",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import auth from "./commands/auth/index.js";
import site from "./commands/site/index.js";
import typescript from "./commands/typescript/index.js";
import { ExitProcessError } from "./ExitProcessError.js";
import { logConfigFileMiddleware } from "./yargs/logConfigFileMiddleware.js";
import { logVersionMiddleware } from "./yargs/logVersionMiddleware.js";

export async function cli(args: string[] = process.argv) {
Expand All @@ -39,6 +40,7 @@ export async function cli(args: string[] = process.argv) {
)
.demandCommand()
.middleware(logVersionMiddleware, true)
.middleware(logConfigFileMiddleware)
.strict()
.command({
command: "unstable",
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/commands/site/CommonSiteArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type { CliCommonArgs } from "../../CliCommonArgs.js";
import type { ThirdPartyAppRid } from "../../net/ThirdPartyAppRid.js";

export interface CommonSiteArgs extends CliCommonArgs {
appRid: ThirdPartyAppRid;
baseUrl: string;
application: ThirdPartyAppRid;
foundryUrl: string;
token?: string;
tokenFile?: string;
}
7 changes: 5 additions & 2 deletions packages/cli/src/commands/site/deploy/SiteDeployArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import type { CommonSiteArgs } from "../CommonSiteArgs.js";

export interface SiteDeployArgs extends CommonSiteArgs {
siteVersion?: string;
clearVersion?: boolean;
version?: string;
directory: string;
uploadOnly: boolean;
autoVersion?: string;
gitTagPrefix?: string;
}
110 changes: 83 additions & 27 deletions packages/cli/src/commands/site/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,107 @@
*/

import type { CommandModule } from "yargs";
import type { LoadedFoundryConfig, SiteConfig } from "../../../util/config.js";
import configLoader from "../../../util/configLoader.js";
import type { CommonSiteArgs } from "../CommonSiteArgs.js";
import { logDeployCommandConfigFileOverride } from "./logDeployCommandConfigFileOverride.js";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

export const command: CommandModule<
const command: CommandModule<
CommonSiteArgs,
SiteDeployArgs
> = {
command: "deploy",
describe: "Deploy an uploaded version",
builder: (argv) => {
builder: async (argv) => {
const config: LoadedFoundryConfig | undefined = await configLoader();
const siteConfig: SiteConfig | undefined = config?.foundryConfig.site;
const directory = siteConfig?.directory;
const autoVersion = siteConfig?.autoVersion;
const gitTagPrefix = autoVersion?.tagPrefix;

return argv
.options({
"siteVersion": {
directory: {
type: "string",
conflicts: "clearVersion",
// group: "Deploy Version",
// implies: { "clearVersion": "false" },
description: "Directory to deploy",
...directory
? { default: directory }
: { demandOption: true },
},
undeploy: {
alias: "clearVersion",
description: "Causes the site to no longer be deployed",
uploadOnly: {
type: "boolean",
conflicts: "siteVersion",
// group: "Deploy Version",
// implies: { "siteVersion": "" },
description: "Upload the directory but do not deploy it",
default: false,
},
version: {
type: "string",
description: "Version to deploy",
...autoVersion == null
? { conflicts: "autoVersion" }
: {},
},
autoVersion: {
type: "string",
description:
"Enables autoversioning. Can be set to 'git-describe' to use git describe to determine the version.",
...(autoVersion != null)
? { default: autoVersion.type }
: { conflicts: "version" },
},
gitTagPrefix: {
type: "string",
description:
"Prefix to match git tags against when --autoVersion=git-describe is used. If not provided, a default prefix 'v' is used.",
...gitTagPrefix
? { default: gitTagPrefix }
: {},
},
}).group(
["siteVersion", "clearVersion"],
"Version To Deploy (requires one of)",
);
["autoVersion", "gitTagPrefix"],
"Autoversion Arguments",
)
.group(
["version", "directory", "uploadOnly"],
"Common Arguments",
)
.check((argv) => {
// This is required because we can't use demandOption with conflicts. conflicts protects us against the case where both are provided.
// So this case is for when nothing is provided.
if (
autoVersion == null && argv.autoVersion == null
&& argv.version == null
) {
throw new Error(
"One of --version or --autoVersion must be specified",
);
}

const autoVersionType = argv.autoVersion ?? autoVersion;
if (autoVersionType !== "git-describe") {
throw new Error(
`Only 'git-describe' is supported for autoVersion`,
);
}

// .check((args) => {
// if (
// (args.siteVersion && args.clearVersion)
// || (!args.siteVersion && args.clearVersion == undefined)
// ) {
// // consola.error("Only one of --siteVersion or --clearVersion may be provided");
// throw new Error(
// "Only one of --siteVersion or --clearVersion may be provided",
// );
// }
// });
const gitTagPrefixValue = argv.gitTagPrefix ?? gitTagPrefix;
// Future proofing for when we support other autoVersion types
if (gitTagPrefixValue != null && autoVersionType !== "git-describe") {
throw new Error(
`--gitTagPrefix is only supported when --autoVersion=git-describe`,
);
}

return true;
}).middleware((argv) =>
logDeployCommandConfigFileOverride(
argv,
siteConfig,
)
);
},
handler: async (args) => {
const command = await import("./handleSiteDeploy.mjs");
const command = await import("./siteDeployCommand.mjs");
await command.default(args);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.
*/

import type { Arguments } from "yargs";
import type { SiteConfig } from "../../../util/config.js";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

export async function logDeployCommandConfigFileOverride(
argv: Arguments<SiteDeployArgs>,
config: SiteConfig | undefined,
) {
const Consola = await import("consola");
const consola = Consola.consola;

if (
config?.autoVersion != null && argv.autoVersion !== config?.autoVersion.type
) {
consola.debug(
`Overriding "autoVersion" from config file with ${argv.autoVersion}`,
);
}

if (config?.directory != null && argv.directory !== config?.directory) {
consola.debug(
`Overriding "directory" from config file with ${argv.directory}`,
);
}

if (
config?.autoVersion?.tagPrefix != null
&& argv.gitTagPrefix != null
&& argv.gitTagPrefix !== config?.autoVersion.tagPrefix
) {
consola.debug(
`Overriding "gitTagPrefix" from config file with ${argv.gitTagPrefix}`,
);
}
}
94 changes: 94 additions & 0 deletions packages/cli/src/commands/site/deploy/siteDeployCommand.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.
*/

import { consola } from "consola";

import {
artifacts,
ArtifactsSitesAdminV2Service,
createConjureContext,
thirdPartyApplicationService,
} from "#net";
import archiver from "archiver";
import * as fs from "node:fs";
import { Readable } from "node:stream";
import { ExitProcessError } from "../../../ExitProcessError.js";
import { autoVersion as findAutoVersion } from "../../../util/autoVersion.js";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

export default async function siteDeployCommand(
{
version,
application,
foundryUrl,
autoVersion,
gitTagPrefix,
uploadOnly,
directory,
}: SiteDeployArgs,
) {
if (!version && !autoVersion) {
throw new ExitProcessError(
2,
"Either version or autoVersion must be specified",
);
}

const siteVersion = !version ? await findAutoVersion(gitTagPrefix) : version;
if (autoVersion) {
consola.info(
`Auto version inferred next version to be: ${siteVersion}`,
);
}

const stat = await fs.promises.stat(directory);
if (!stat.isDirectory()) {
consola.error("Specified path is not a directory");
throw new ExitProcessError(2);
}

consola.start("Zippping site files");

const archive = archiver("zip").directory(directory, false);

await Promise.all([
artifacts.SiteAssetArtifactsService.uploadZippedSiteAsset(
foundryUrl,
application,
siteVersion,
Readable.toWeb(archive) as ReadableStream<any>, // This cast is because the dom fetch doesnt align type wise with streams
),
archive.finalize(),
]);

consola.success("Upload complete");

if (!uploadOnly) {
const repositoryRid = await thirdPartyApplicationService
.fetchWebsiteRepositoryRid(foundryUrl, application);

const ctx = createConjureContext(foundryUrl, "/artifacts/api");
await ArtifactsSitesAdminV2Service.updateDeployedVersion(
ctx,
repositoryRid,
{ siteVersion: { version: siteVersion } },
);

consola.success(`Deployed ${siteVersion} successfully`);
} else {
consola.debug("Upload only mode enabled, skipping deployment");
}
}
Loading

0 comments on commit dcd0486

Please sign in to comment.