Skip to content

Commit

Permalink
added imports to project manifest (not yet used in cli)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisbitney committed Oct 11, 2023
1 parent 7b52e35 commit 2e503ed
Show file tree
Hide file tree
Showing 25 changed files with 878 additions and 165 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/lib/SchemaComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class SchemaComposer {
private _abiResolver(
schemaFile: SchemaFile,
importFrom: string,
import_abis?: NonNullable<PolywrapManifest["source"]>["import_abis"]
import_abis?: PolywrapManifest["import_abis"]
): Promise<WrapAbi | SchemaFile> {
if (Uri.isValidUri(importFrom)) {
return this._resolveUri(importFrom, import_abis);
Expand All @@ -97,7 +97,7 @@ export class SchemaComposer {

private async _resolveUri(
uri: string,
import_abis?: NonNullable<PolywrapManifest["source"]>["import_abis"]
import_abis?: PolywrapManifest["import_abis"]
): Promise<WrapAbi> {
// Check to see if we have any import redirects that match
if (import_abis) {
Expand Down Expand Up @@ -155,7 +155,7 @@ export class SchemaComposer {

private async _loadGraphqlAbi(
path: string,
import_abis: NonNullable<PolywrapManifest["source"]>["import_abis"]
import_abis: PolywrapManifest["import_abis"]
): Promise<WrapAbi> {
const schema = fs.readFileSync(path, "utf-8");

Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/lib/project/AppProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ export class AppProject extends Project<AppManifest> {
: path.join(dir, manifest.source.schema);
}

public async getImportAbis(): Promise<
NonNullable<AppManifest["source"]>["import_abis"]
> {
public async getImportAbis(): Promise<AppManifest["import_abis"]> {
const manifest = await this.getManifest();
return manifest.source?.import_abis || [];
return manifest.import_abis || [];
}

public async getGenerationDirectory(
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/lib/project/PluginProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ export class PluginProject extends Project<PluginManifest> {
: path.join(dir, manifest.source.schema);
}

public async getImportAbis(): Promise<
NonNullable<PluginManifest["source"]>["import_abis"]
> {
public async getImportAbis(): Promise<PluginManifest["import_abis"]> {
const manifest = await this.getManifest();
return manifest.source?.import_abis || [];
return manifest.import_abis || [];
}

public async getGenerationDirectory(
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/lib/project/PolywrapProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,9 @@ export class PolywrapProject extends Project<PolywrapManifest> {
: path.join(dir, manifest.source.schema);
}

public async getImportAbis(): Promise<
NonNullable<PolywrapManifest["source"]>["import_abis"]
> {
public async getImportAbis(): Promise<PolywrapManifest["import_abis"]> {
const manifest = await this.getManifest();
return manifest.source?.import_abis || [];
return manifest.import_abis || [];
}

public async getGenerationDirectory(
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/lib/project/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export abstract class Project<TManifest extends AnyProjectManifest> {

public abstract getSchemaNamedPath(): Promise<string>;

public abstract getImportAbis(): Promise<
NonNullable<PolywrapManifest["source"]>["import_abis"]
>;
public abstract getImportAbis(): Promise<PolywrapManifest["import_abis"]>;

public abstract getGenerationDirectory(
generationSubPath?: string
Expand Down
75 changes: 75 additions & 0 deletions packages/js/manifests/polywrap/src/formats/polywrap.app/0.6.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export interface AppManifest {
/**
* Polywrap manifest format version.
*/
format: "0.6.0";
/**
* Basic project properties.
*/
project: {
/**
* Name of this project.
*/
name: string;
/**
* Type of this project.
*/
type: string;
};
/**
* Project source files.
*/
source?: {
/**
* Path to the project's graphql schema.
*/
schema?: string;
};
/**
* Specify URIs to be used to import ABIs in your schema.
*/
imports?: {
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` ".*".
*/
[k: string]: ImportUri | string;
};
/**
* Specify redirects from import URIs to ABIs on your filesystem.
*/
import_abis?: ImportAbi[];
__type: "AppManifest";
}
export interface ImportUri {
/**
* Wrap URI to import.
*/
uri: string;
/**
* List of types to import from Wrap (defaults to all).
*/
types?: string[];
/**
* List of functions to import from Wrap (defaults to all).
*/
functions?: string[];
}
export interface ImportAbi {
/**
* Import URI
*/
uri: string;
/**
* Path to a local ABI (or schema). Supported file formats: [*.graphql, *.info, *.json, *.yaml]
*/
abi: string;
}
11 changes: 9 additions & 2 deletions packages/js/manifests/polywrap/src/formats/polywrap.app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import {
import {
AppManifest as AppManifest_0_5_0,
} from "./0.5.0";
import {
AppManifest as AppManifest_0_6_0,
} from "./0.6.0";

export {
AppManifest_0_1_0,
AppManifest_0_2_0,
AppManifest_0_3_0,
AppManifest_0_4_0,
AppManifest_0_5_0,
AppManifest_0_6_0,
};

export enum AppManifestFormats {
Expand All @@ -37,6 +41,7 @@ export enum AppManifestFormats {
"v0.3.0" = "0.3.0",
"v0.4.0" = "0.4.0",
"v0.5.0" = "0.5.0",
"v0.6.0" = "0.6.0",
}

export const AppManifestSchemaFiles: Record<string, string> = {
Expand All @@ -47,6 +52,7 @@ export const AppManifestSchemaFiles: Record<string, string> = {
"0.3.0": "formats/polywrap.app/0.3.0.json",
"0.4.0": "formats/polywrap.app/0.4.0.json",
"0.5.0": "formats/polywrap.app/0.5.0.json",
"0.6.0": "formats/polywrap.app/0.6.0.json",
}

export type AnyAppManifest =
Expand All @@ -55,11 +61,12 @@ export type AnyAppManifest =
| AppManifest_0_3_0
| AppManifest_0_4_0
| AppManifest_0_5_0
| AppManifest_0_6_0


export type AppManifest = AppManifest_0_5_0;
export type AppManifest = AppManifest_0_6_0;

export const latestAppManifestFormat = AppManifestFormats["v0.5.0"]
export const latestAppManifestFormat = AppManifestFormats["v0.6.0"]

export { migrateAppManifest } from "./migrate";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AppManifest as OldManifest } from "../0.5.0";
import { AppManifest as NewManifest } from "../0.6.0";

export function migrate(migrate: OldManifest): NewManifest {
const newManifest: Partial<NewManifest> = {
...migrate,
format: "0.6.0",
};
if (migrate.source) {
newManifest["source"] = {};
if (migrate.source.schema) {
newManifest.source["schema"] = migrate.source.schema;
}
if (migrate.source.import_abis) {
newManifest["import_abis"] = migrate.source.import_abis;
}
}
return newManifest as NewManifest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { migrate as migrate_0_1_0_to_0_2_0 } from "./0.1.0_to_0.2.0";
import { migrate as migrate_0_2_0_to_0_3_0 } from "./0.2.0_to_0.3.0";
import { migrate as migrate_0_3_0_to_0_4_0 } from "./0.3.0_to_0.4.0";
import { migrate as migrate_0_4_0_to_0_5_0 } from "./0.4.0_to_0.5.0";
import { migrate as migrate_0_5_0_to_0_6_0 } from "./0.5.0_to_0.6.0";

export const migrators: Migrator[] = [
{
Expand Down Expand Up @@ -30,4 +31,9 @@ export const migrators: Migrator[] = [
to: "0.5.0",
migrate: migrate_0_4_0_to_0_5_0,
},
{
from: "0.5.0",
to: "0.6.0",
migrate: migrate_0_5_0_to_0_6_0,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import AppManifestSchema_0_2_0 from "@polywrap/polywrap-manifest-schemas/formats
import AppManifestSchema_0_3_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.3.0.json";
import AppManifestSchema_0_4_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.4.0.json";
import AppManifestSchema_0_5_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.5.0.json";
import AppManifestSchema_0_6_0 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.6.0.json";

import {
Schema,
Expand All @@ -34,6 +35,7 @@ const schemas: AppManifestSchemas = {
"0.3.0": AppManifestSchema_0_3_0,
"0.4.0": AppManifestSchema_0_4_0,
"0.5.0": AppManifestSchema_0_5_0,
"0.6.0": AppManifestSchema_0_6_0,
};

const validator = new Validator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export interface PluginManifest {
/**
* Polywrap manifest format version.
*/
format: "0.6.0";
/**
* Basic project properties.
*/
project: {
/**
* Name of this project.
*/
name: string;
/**
* Type of this project.
*/
type: string;
};
/**
* Project source files.
*/
source?: {
/**
* Path to the project's entry point.
*/
module?: string;
/**
* Path to the project's graphql schema.
*/
schema?: string;
};
/**
* Specify URIs to be used to import ABIs in your schema.
*/
imports?: {
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` ".*".
*/
[k: string]: ImportUri | string;
};
/**
* Specify redirects from import URIs to ABIs on your filesystem.
*/
import_abis?: ImportAbi[];
__type: "PluginManifest";
}
export interface ImportUri {
/**
* Wrap URI to import.
*/
uri: string;
/**
* List of types to import from Wrap (defaults to all).
*/
types?: string[];
/**
* List of functions to import from Wrap (defaults to all).
*/
functions?: string[];
}
export interface ImportAbi {
/**
* Import URI
*/
uri: string;
/**
* Path to a local ABI (or schema). Supported file formats: [*.graphql, *.info, *.json, *.yaml]
*/
abi: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import {
import {
PluginManifest as PluginManifest_0_5_0,
} from "./0.5.0";
import {
PluginManifest as PluginManifest_0_6_0,
} from "./0.6.0";

export {
PluginManifest_0_1_0,
PluginManifest_0_2_0,
PluginManifest_0_3_0,
PluginManifest_0_4_0,
PluginManifest_0_5_0,
PluginManifest_0_6_0,
};

export enum PluginManifestFormats {
Expand All @@ -37,6 +41,7 @@ export enum PluginManifestFormats {
"v0.3.0" = "0.3.0",
"v0.4.0" = "0.4.0",
"v0.5.0" = "0.5.0",
"v0.6.0" = "0.6.0",
}

export const PluginManifestSchemaFiles: Record<string, string> = {
Expand All @@ -47,6 +52,7 @@ export const PluginManifestSchemaFiles: Record<string, string> = {
"0.3.0": "formats/polywrap.plugin/0.3.0.json",
"0.4.0": "formats/polywrap.plugin/0.4.0.json",
"0.5.0": "formats/polywrap.plugin/0.5.0.json",
"0.6.0": "formats/polywrap.plugin/0.6.0.json",
}

export type AnyPluginManifest =
Expand All @@ -55,11 +61,12 @@ export type AnyPluginManifest =
| PluginManifest_0_3_0
| PluginManifest_0_4_0
| PluginManifest_0_5_0
| PluginManifest_0_6_0


export type PluginManifest = PluginManifest_0_5_0;
export type PluginManifest = PluginManifest_0_6_0;

export const latestPluginManifestFormat = PluginManifestFormats["v0.5.0"]
export const latestPluginManifestFormat = PluginManifestFormats["v0.6.0"]

export { migratePluginManifest } from "./migrate";

Expand Down
Loading

0 comments on commit 2e503ed

Please sign in to comment.