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

Update api-gateway definitions #38

Merged
merged 9 commits into from
Feb 14, 2024
1 change: 1 addition & 0 deletions packages/api/src/ontology/ActionDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface ValidBaseActionParameterTypes {
datetime: Date;
timestamp: Date;
attachment: any;
marking: string;
}

export interface ObjectActionDataType<K extends string> {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/ontology/WirePropertyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface WirePropertyTypes {
float: number;
decimal: number;
byte: number;
marking: string;

numericTimeseries: any;
stringTimeseries: any;
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/changelog/@unreleased/pr-38.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Update api-gateway definitions
links:
- https://github.com/palantir/osdk-ts/pull/38
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"archiver": "^6.0.1",
"conjure-lite": "^0.3.3",
"consola": "^3.2.3",
"find-up": "^6.3.0",
"find-up": "^7.0.0",
"open": "^9.1.0",
"semver": "^7.6.0",
"yargs": "^17.7.2"
Expand Down
5 changes: 5 additions & 0 deletions packages/create-app/changelog/@unreleased/pr-38.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Update api-gateway definitions
links:
- https://github.com/palantir/osdk-ts/pull/38
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"consola": "^3.2.3",
"find-up": "^6.3.0",
"find-up": "^7.0.0",
"handlebars": "^4.7.8",
"yargs": "^17.7.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exports[`Load Ontologies Metadata > Loads object and action types using only spe
"interfaceTypes": {},
"objectTypes": {
"Employee": {
"implementsInterfaces": [],
"linkTypes": [
{
"apiName": "peeps",
Expand Down Expand Up @@ -98,8 +99,10 @@ exports[`Load Ontologies Metadata > Loads object and action types using only spe
"rid": "ri.ontology.main.object-type.401ac022-89eb-4591-8b7e-0a912b9efb44",
"status": "ACTIVE",
},
"sharedPropertyTypeMapping": {},
},
"Office": {
"implementsInterfaces": [],
"linkTypes": [],
"objectType": {
"apiName": "Office",
Expand Down Expand Up @@ -132,6 +135,7 @@ exports[`Load Ontologies Metadata > Loads object and action types using only spe
"rid": "ri.ontology.main.object-type.404ac022-89eb-4591-8b7e-1a912b9efb45",
"status": "ACTIVE",
},
"sharedPropertyTypeMapping": {},
},
},
"ontology": {
Expand Down Expand Up @@ -184,6 +188,7 @@ exports[`Load Ontologies Metadata > Loads object and action types without link t
"interfaceTypes": {},
"objectTypes": {
"Employee": {
"implementsInterfaces": [],
"linkTypes": [],
"objectType": {
"apiName": "Employee",
Expand Down Expand Up @@ -228,6 +233,7 @@ exports[`Load Ontologies Metadata > Loads object and action types without link t
"rid": "ri.ontology.main.object-type.401ac022-89eb-4591-8b7e-0a912b9efb44",
"status": "ACTIVE",
},
"sharedPropertyTypeMapping": {},
},
},
"ontology": {
Expand Down
5 changes: 5 additions & 0 deletions packages/gateway-generator/changelog/@unreleased/pr-38.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Update api-gateway definitions
links:
- https://github.com/palantir/osdk-ts/pull/38
2 changes: 2 additions & 0 deletions packages/gateway-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"typecheck": "tsc-absolute --build"
},
"dependencies": {
"find-up": "^7.0.0",
"ts-morph": "^19.0.0",
"yaml": "^2.3.4",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions packages/gateway-generator/src/cli/generateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
*/

import { readFile } from "fs/promises";
import { parse } from "yaml";
import type { Arguments, Argv, CommandModule } from "yargs";
import { generate } from "../generate/generate";
import type { ApiSpec } from "../spec";
import { updateSls } from "./updateSls";

export interface GenerateOpenApiArgs {
/*
* Positional arguments
*/
inputFile: string;
manifestFile: string;
outputDir: string;
generateVisitors: boolean;
}
Expand All @@ -42,6 +45,11 @@ export class GenerateCommand implements CommandModule<{}, GenerateOpenApiArgs> {
type: "string",
demandOption: true,
})
.positional("manifestFile", {
describe: "The location of the API manifest.yml",
type: "string",
demandOption: true,
})
.positional("outputDir", {
describe: "The output directory for the generated code",
type: "string",
Expand All @@ -68,8 +76,15 @@ export class GenerateCommand implements CommandModule<{}, GenerateOpenApiArgs> {
const irSpecRead = await readFile(`${input}`, { encoding: "utf8" });
const irSpec: ApiSpec = JSON.parse(irSpecRead);

const manifestRead = await readFile(`${args.manifestFile}`, {
encoding: "utf8",
});
const manifest = parse(manifestRead);

await generate(irSpec, output, {
generateVisitors,
});

await updateSls(manifest, output);
};
}
71 changes: 71 additions & 0 deletions packages/gateway-generator/src/cli/updateSls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericanderson do we have eslint set up for the copyright header?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its in monorepo/eslint-config-sane/library.cjs. We should probably split that into its own PR through.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yupyup no worries

*
* 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 { readFile, writeFile } from "fs/promises";

export interface Manifest {
"manifest-version": string;
"extensions": {
"product-dependencies": ReadonlyArray<{
"product-group": string;
"product-name": string;
"minimum-version": string;
"maximum-version": string;
"optional": boolean;
}>;
};
}

export async function updateSls(manifest: Manifest, output: string) {
// the whole manifest shape is hand-jammed so lets have a quick sanity check to make sure we're ok
if (manifest["manifest-version"] !== "1.0") {
throw new Error(
`Unsupported manifest version ${manifest["manifest-version"]}`,
);
}

const { findUp } = await import("find-up");

const packageJsonFile = await findUp("package.json", { cwd: output });
if (!packageJsonFile) {
throw new Error("Could not find target package.json");
}
const packageJsonRead = await readFile(packageJsonFile, { encoding: "utf8" });
const packageJson = JSON.parse(packageJsonRead);

const dependencies:
| Record<string, { minVersion: string; maxVersion: string }>
| undefined = packageJson?.["sls"]?.["dependencies"];
if (!dependencies) {
throw new Error("package.json does not have an sls block yet?");
}

const deps = manifest?.extensions?.["product-dependencies"];

for (const dep of deps) {
if (dep.optional) {
throw new Error("No support for optional dependencies");
}
const key = `${dep["product-group"]}:${dep["product-name"]}`;
const value = {
minVersion: dep["minimum-version"],
maxVersion: dep["maximum-version"],
};
dependencies[key] = value;
}

await writeFile(packageJsonFile, JSON.stringify(packageJson, null, 2));
}
5 changes: 5 additions & 0 deletions packages/gateway/changelog/@unreleased/pr-38.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Update api-gateway definitions
links:
- https://github.com/palantir/osdk-ts/pull/38
10 changes: 9 additions & 1 deletion packages/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,13 @@
],
"main": "./build/js/index.js",
"module": "./build/js/index.mjs",
"types": "./build/types/index.d.ts"
"types": "./build/types/index.d.ts",
"sls": {
"dependencies": {
"com.palantir.foundry.api:api-gateway": {
"minVersion": "1.763.0",
"maxVersion": "1.x.x"
}
Comment on lines +58 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so i understand, is this so this will propagate to the asset that the generator is included in? apologies i hadn't been following ultra closely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is halfway to that. Right now we're just adding it to @osdk/gateway so that anyone that depends on that will get it in their package tree so our internal code should pick this up. It doesn't wind up on the package built by foundry-sdk-generator OR the create-osdk-app assets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok great, thanks for explaining! that's what I was hoping for

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { DateType } from "./DateType";
import type { DoubleType } from "./DoubleType";
import type { IntegerType } from "./IntegerType";
import type { LongType } from "./LongType";
import type { MarkingType } from "./MarkingType";
import type { OntologyObjectSetType } from "./OntologyObjectSetType";
import type { OntologyObjectType } from "./OntologyObjectType";
import type { StringType } from "./StringType";
Expand Down Expand Up @@ -54,6 +55,10 @@ export interface ActionParameterType_Long extends LongType {
type: "long";
}

export interface ActionParameterType_Marking extends MarkingType {
type: "marking";
}

export interface ActionParameterType_ObjectSet extends OntologyObjectSetType {
type: "objectSet";
}
Expand All @@ -78,6 +83,7 @@ export type ActionParameterType =
| ActionParameterType_Double
| ActionParameterType_Integer
| ActionParameterType_Long
| ActionParameterType_Marking
| ActionParameterType_ObjectSet
| ActionParameterType_Object
| ActionParameterType_String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
* | Double | number | `3.14159265` |
* | Integer | number | `238940` |
* | Long | string | `"58319870951433"` |
* | Marking | string | `"MU"` |
* | Null | null | `null` |
* | Object Set | string | `ri.object-set.main.versioned-object-set.h13274m8-23f5-431c-8aee-a4554157c57z`|
* | Object Set | string OR the object set definition | `ri.object-set.main.versioned-object-set.h13274m8-23f5-431c-8aee-a4554157c57z`|
* | Ontology Object Reference | JSON encoding of the object's primary key | `10033123` or `"EMP1234"` |
* | Set | array | `["alpha", "bravo", "charlie"]` |
* | Short | number | `8739` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@
* limitations under the License.
*/

import type { LinkTypeSideV2 } from "./LinkTypeSideV2";
import type { ObjectTypeV2 } from "./ObjectTypeV2";

export interface ObjectTypeWithLink {
objectType: ObjectTypeV2;
linkTypes: Array<LinkTypeSideV2>;
export interface MarkingType {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { GeoPointType } from "./GeoPointType";
import type { GeoShapeType } from "./GeoShapeType";
import type { IntegerType } from "./IntegerType";
import type { LongType } from "./LongType";
import type { MarkingType } from "./MarkingType";
import type { OntologyObjectArrayType } from "./OntologyObjectArrayType";
import type { ShortType } from "./ShortType";
import type { StringType } from "./StringType";
Expand Down Expand Up @@ -79,6 +80,10 @@ export interface ObjectPropertyType_Long extends LongType {
type: "long";
}

export interface ObjectPropertyType_Marking extends MarkingType {
type: "marking";
}

export interface ObjectPropertyType_Short extends ShortType {
type: "short";
}
Expand Down Expand Up @@ -108,6 +113,7 @@ export type ObjectPropertyType =
| ObjectPropertyType_Geoshape
| ObjectPropertyType_Integer
| ObjectPropertyType_Long
| ObjectPropertyType_Marking
| ObjectPropertyType_Short
| ObjectPropertyType_String
| ObjectPropertyType_Timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { InterfaceTypeApiName } from "./InterfaceTypeApiName";
import type { LinkTypeSideV2 } from "./LinkTypeSideV2";
import type { ObjectTypeV2 } from "./ObjectTypeV2";
import type { PropertyApiName } from "./PropertyApiName";
import type { SharedPropertyTypeApiName } from "./SharedPropertyTypeApiName";

export interface ObjectTypeFullMetadata {
objectType: ObjectTypeV2;
linkTypes: Array<LinkTypeSideV2>;
/** A list of interfaces that this object type implements. */
implementsInterfaces: Array<InterfaceTypeApiName>;
/**
* A map from shared property type API name to backing local property API name for the shared property types
* present on this object type.
*/
sharedPropertyTypeMapping: Record<SharedPropertyTypeApiName, PropertyApiName>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { DoubleType } from "./DoubleType";
import type { FloatType } from "./FloatType";
import type { IntegerType } from "./IntegerType";
import type { LongType } from "./LongType";
import type { MarkingType } from "./MarkingType";
import type { OntologyArrayType } from "./OntologyArrayType";
import type { OntologyMapType } from "./OntologyMapType";
import type { OntologyObjectSetType } from "./OntologyObjectSetType";
Expand Down Expand Up @@ -75,6 +76,10 @@ export interface OntologyDataType_Long extends LongType {
type: "long";
}

export interface OntologyDataType_Marking extends MarkingType {
type: "marking";
}

export interface OntologyDataType_Short extends ShortType {
type: "short";
}
Expand Down Expand Up @@ -126,6 +131,7 @@ export type OntologyDataType =
| OntologyDataType_Float
| OntologyDataType_Integer
| OntologyDataType_Long
| OntologyDataType_Marking
| OntologyDataType_Short
| OntologyDataType_String
| OntologyDataType_Timestamp
Expand Down
Loading
Loading