Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mf/callable-client
Browse files Browse the repository at this point in the history
* origin/main:
  Autorelease
  Increase CLI max width to 150 columns (#47)
  Debug log site zip stats (#49)
  Clean up yargs and consola imports (#51)
  Autorelease
  Add generated changelog entries
  Breaking: force dollar sign in osdk verbs for where
  Display errors more consistently in @osdk/cli (#41)
  Fix tagPrefix
  Add generated changelog entries
  Create foundry.config.json in create-app
  [3/] Improvement: Use loadedToken for fetching data (#17)
  Move argv override logging to middleware (#42)
  Make sure to run all tests (#39)
  Update create-app to use FOUNDRY_TOKEN in templates (#40)
  Add generated changelog entries
  Fix intellisense for aggregations and fill in more number types
  [2/] Improvement: Introduce new command structure  (#16)
  Autorelease
  Refactor create-app prompts with tests (#32)
  Refactor create-app dotfile generation (#31)
  add changelog
  Add generated changelog entries
  Add generated changelog entries
  put mkdir in right place
  remove generated files
  add ignore for legacy client
  remove deleted file
  added
  add back mkdir
  move mkdir
  fix
  fixes
  keep trying
  remove module
  shared testing infra for legacy
  • Loading branch information
ericanderson committed Feb 13, 2024
2 parents 28d5315 + ce7e49b commit e130e76
Show file tree
Hide file tree
Showing 183 changed files with 2,444 additions and 538 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

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function fetchEmployeePageByAdUsername(
adUsername: string,
) {
const result = await client.objects.Employee.where({
$and: [{ adUsername }, { employeeNumber: { ne: 5 } }],
$and: [{ adUsername }, { employeeNumber: { $ne: 5 } }],
}).fetchPageOrThrow();
// for await (const e of client.objects.Employee.asyncIter()) {
// e.__apiName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export async function fetchEmployeePageByAdUsernameAndLimit(
const result = await client.objects.Employee.where({
$and: [
{ adUsername },
{ employeeNumber: { ne: 5 } },
{ employeeNumber: { gte: 5 } },
{ employeeNumber: { $ne: 5 } },
{ employeeNumber: { $gte: 5 } },
],
}).fetchPageOrThrow({
select: ["adUsername", "employeeNumber", "jobProfile"],
Expand Down
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
2 changes: 1 addition & 1 deletion examples/basic/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"publishConfig": {
"access": "public"
},
"keywords": [],
"keywords": [ ],
"files": [
"build/types",
"build/js",
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/sdk/src/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function aggregateThingsWithGroupsAndHandleErrors() {
groupBy: {
text: "exact",
},
where: { id: { gt: 5 } },
where: { id: { $gt: 5 } },
});

if (isOk(result)) {
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.4.0/pr-17.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: '[3/] Improvement: Use loadedToken for fetching data'
links:
- https://github.com/palantir/osdk-ts/pull/17
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.4.0/pr-41.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Display errors more consistently in @osdk/cli
links:
- https://github.com/palantir/osdk-ts/pull/41
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.4.0/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
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.5.0/pr-47.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Increase CLI max width to 150 columns
links:
- https://github.com/palantir/osdk-ts/pull/47
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.5.0/pr-49.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Debug log site zip stats
links:
- https://github.com/palantir/osdk-ts/pull/49
5 changes: 5 additions & 0 deletions packages/cli/changelog/0.5.0/pr-51.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Clean up yargs handling and consola imports
links:
- https://github.com/palantir/osdk-ts/pull/51
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@osdk/cli",
"version": "0.3.0",
"version": "0.5.0",
"description": "",
"access": "public",
"license": "Apache-2.0",
Expand All @@ -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 Expand Up @@ -53,7 +54,7 @@
"imports": {
"#net": "./src/net/index.mts"
},
"keywords": [],
"keywords": [ ],
"bin": {
"osdk": "./bin/osdk.mjs"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import type { CommonSiteArgs } from "../CommonSiteArgs.js";

export interface UploadArgs extends CommonSiteArgs {
siteVersion: string;
dir?: string;
export class YargsCheckError extends Error {
constructor(msg?: string) {
super(msg);
}
}
31 changes: 26 additions & 5 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { consola } from "consola";
import type { Argv } from "yargs";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
Expand All @@ -22,10 +23,13 @@ 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";
import { YargsCheckError } from "./YargsCheckError.js";

export async function cli(args: string[] = process.argv) {
const base: Argv<CliCommonArgs> = yargs(hideBin(args))
.wrap(Math.min(150, yargs().terminalWidth()))
.env("OSDK")
.version(false)
.option(
Expand All @@ -39,10 +43,12 @@ export async function cli(args: string[] = process.argv) {
)
.demandCommand()
.middleware(logVersionMiddleware, true)
.middleware(logConfigFileMiddleware)
.strict()
.command({
command: "unstable",
aliases: ["experimental"],
describe: "Unstable commands",
builder: async (argv) => {
return argv
.command(site)
Expand All @@ -51,14 +57,29 @@ export async function cli(args: string[] = process.argv) {
.demandCommand();
},
handler: (_args) => {},
})
.fail(async (msg, err, argv) => {
if (err instanceof ExitProcessError) {
consola.error(err.message);
consola.debug(err.stack);
} else {
if (err && err instanceof YargsCheckError === false) {
throw err;
} else {
argv.showHelp();
consola.log(""); // intentional blank line
consola.error(msg);
}
}
process.exit(1);
});

// Special handling where failures happen before yargs does its error handling within .fail
try {
return base.parseAsync();
} catch (e) {
if (e instanceof ExitProcessError) {
const Consola = await import("consola");
Consola.consola.error(e.message);
return await base.parseAsync();
} catch (err) {
if (err instanceof ExitProcessError) {
consola.error(err);
}
}
}
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;
}
111 changes: 84 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,108 @@
*/

import type { CommandModule } from "yargs";
import type { LoadedFoundryConfig, SiteConfig } from "../../../util/config.js";
import configLoader from "../../../util/configLoader.js";
import { YargsCheckError } from "../../../YargsCheckError.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((args) => {
// 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 && args.autoVersion == null
&& args.version == null
) {
throw new YargsCheckError(
"One of --version or --autoVersion must be specified",
);
}

const autoVersionType = args.autoVersion ?? autoVersion;
if (autoVersionType !== "git-describe") {
throw new YargsCheckError(
`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 = args.gitTagPrefix ?? gitTagPrefix;
// Future proofing for when we support other autoVersion types
if (gitTagPrefixValue != null && autoVersionType !== "git-describe") {
throw new YargsCheckError(
`--gitTagPrefix is only supported when --autoVersion=git-describe`,
);
}

return true;
}).middleware((args) =>
logDeployCommandConfigFileOverride(
args,
siteConfig,
)
);
},
handler: async (args) => {
const command = await import("./handleSiteDeploy.mjs");
const command = await import("./siteDeployCommand.mjs");
await command.default(args);
},
};
Expand Down
Loading

0 comments on commit e130e76

Please sign in to comment.