diff --git a/packages/js/manifests/polywrap/scripts/generate.ts b/packages/js/manifests/polywrap/scripts/generate.ts index 499279efae..aa9d228891 100644 --- a/packages/js/manifests/polywrap/scripts/generate.ts +++ b/packages/js/manifests/polywrap/scripts/generate.ts @@ -88,6 +88,7 @@ async function generateFormatTypes() { os.writeFileSync(tsOutputPath, tsSrc); }; + const firstItem = (arr: Array) => arr[0]; const lastItem = (arr: Array) => arr[arr.length - 1]; const versionToTs = (version: string) => version.replace(/\./g, "_").replace(/\-/g, "_"); @@ -137,6 +138,7 @@ async function generateFormatTypes() { const validateContext = { formats: validateFormats, + first: firstItem(validateFormats), latest: lastItem(validateFormats), validators: [] as string[], }; diff --git a/packages/js/manifests/polywrap/scripts/templates/validate-ts.mustache b/packages/js/manifests/polywrap/scripts/templates/validate-ts.mustache index fe5ad36417..8b7a054d01 100644 --- a/packages/js/manifests/polywrap/scripts/templates/validate-ts.mustache +++ b/packages/js/manifests/polywrap/scripts/templates/validate-ts.mustache @@ -10,7 +10,7 @@ import { } from "."; {{#validators.length}}import * as Validators from "../../validators";{{/validators.length}} {{#formats}} -import schema_{{tsVersion}} from "@polywrap/polywrap-manifest-schemas/formats/{{dir}}/{{version}}.json"; +import {{type}}Schema_{{tsVersion}} from "@polywrap/polywrap-manifest-schemas/formats/{{dir}}/{{version}}.json"; {{/formats}} import { @@ -26,9 +26,9 @@ type {{#latest}}{{type}}{{/latest}}Schemas = { const schemas: {{#latest}}{{type}}{{/latest}}Schemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, + "0.1.0": {{#first}}{{type}}{{/first}}Schema_0_1, {{#formats}} - "{{version}}": schema_{{tsVersion}}, + "{{version}}": {{type}}Schema_{{tsVersion}}, {{/formats}} }; diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.app/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.app/validate.ts index d5bb77f948..5fe7ee082e 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.app/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.app/validate.ts @@ -9,7 +9,7 @@ import { AppManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.1.json"; +import AppManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.app/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type AppManifestSchemas = { const schemas: AppManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": AppManifestSchema_0_1, + "0.1": AppManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.build/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.build/validate.ts index 3ac17e6e98..591172ec7e 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.build/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.build/validate.ts @@ -9,7 +9,7 @@ import { BuildManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.build/0.1.json"; +import BuildManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.build/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type BuildManifestSchemas = { const schemas: BuildManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": BuildManifestSchema_0_1, + "0.1": BuildManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.deploy/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.deploy/validate.ts index 14f21d80d7..6d0befe523 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.deploy/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.deploy/validate.ts @@ -9,7 +9,7 @@ import { DeployManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.deploy/0.1.json"; +import DeployManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.deploy/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type DeployManifestSchemas = { const schemas: DeployManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": DeployManifestSchema_0_1, + "0.1": DeployManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.infra/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.infra/validate.ts index 78471acd72..61593028f1 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.infra/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.infra/validate.ts @@ -9,7 +9,7 @@ import { InfraManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.infra/0.1.json"; +import InfraManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.infra/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type InfraManifestSchemas = { const schemas: InfraManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": InfraManifestSchema_0_1, + "0.1": InfraManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.meta/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.meta/validate.ts index b2747fc71a..09872692d6 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.meta/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.meta/validate.ts @@ -9,7 +9,7 @@ import { MetaManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.meta/0.1.json"; +import MetaManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.meta/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type MetaManifestSchemas = { const schemas: MetaManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": MetaManifestSchema_0_1, + "0.1": MetaManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap.plugin/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap.plugin/validate.ts index 01aa2845ef..de976b7646 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap.plugin/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap.plugin/validate.ts @@ -9,7 +9,7 @@ import { PluginManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.plugin/0.1.json"; +import PluginManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap.plugin/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type PluginManifestSchemas = { const schemas: PluginManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": PluginManifestSchema_0_1, + "0.1": PluginManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/polywrap/src/formats/polywrap/validate.ts b/packages/js/manifests/polywrap/src/formats/polywrap/validate.ts index d3dcc56b9c..e6357a2f66 100644 --- a/packages/js/manifests/polywrap/src/formats/polywrap/validate.ts +++ b/packages/js/manifests/polywrap/src/formats/polywrap/validate.ts @@ -9,7 +9,7 @@ import { PolywrapManifestFormats } from "."; -import schema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap/0.1.json"; +import PolywrapManifestSchema_0_1 from "@polywrap/polywrap-manifest-schemas/formats/polywrap/0.1.json"; import { Schema, @@ -24,8 +24,8 @@ type PolywrapManifestSchemas = { const schemas: PolywrapManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": PolywrapManifestSchema_0_1, + "0.1": PolywrapManifestSchema_0_1, }; const validator = new Validator(); diff --git a/packages/js/manifests/wrap/package.json b/packages/js/manifests/wrap/package.json index debe9c6513..900fbcc3a5 100644 --- a/packages/js/manifests/wrap/package.json +++ b/packages/js/manifests/wrap/package.json @@ -17,13 +17,13 @@ }, "dependencies": { "@polywrap/msgpack-js": "0.3.0", - "@polywrap/wrap-manifest-schemas": "0.3.0", "json-schema-ref-parser": "9.0.9", "jsonschema": "1.4.0", "semver": "7.3.5" }, "devDependencies": { "@polywrap/os-js": "0.3.0", + "@polywrap/wrap-manifest-schemas": "0.3.0", "@types/jest": "26.0.8", "@types/mustache": "4.0.1", "@types/prettier": "2.6.0", diff --git a/packages/js/manifests/wrap/scripts/generate.ts b/packages/js/manifests/wrap/scripts/generate.ts index 85f7f27216..4f7d326a65 100644 --- a/packages/js/manifests/wrap/scripts/generate.ts +++ b/packages/js/manifests/wrap/scripts/generate.ts @@ -82,6 +82,9 @@ async function generateFormatTypes() { `/* eslint-disable @typescript-eslint/naming-convention */\n${tsFile}` ); + const schemaOutputPath = path.join(wrapOutputDir, `${wrapVersion}.schema.json`); + os.writeFileSync(schemaOutputPath, JSON.stringify(bundledSchema, null ,2)); + // Add metadata for the root index.ts file to use wrapModules.push({ interface: wrapSchema.id, diff --git a/packages/js/manifests/wrap/scripts/templates/index-ts.mustache b/packages/js/manifests/wrap/scripts/templates/index-ts.mustache index 842e497817..8e4235dd72 100644 --- a/packages/js/manifests/wrap/scripts/templates/index-ts.mustache +++ b/packages/js/manifests/wrap/scripts/templates/index-ts.mustache @@ -12,10 +12,15 @@ import { } from "./{{version}}"; {{/formats}} +{{#formats}} +import WrapManifestSchema_{{tsVersion}} from "./{{version}}.schema.json"; +{{/formats}} + export { {{#formats}} WrapManifest_{{tsVersion}}, - WrapAbi_{{tsVersion}}_{{abiTsVersion}} + WrapAbi_{{tsVersion}}_{{abiTsVersion}}, + WrapManifestSchema_{{tsVersion}} {{/formats}} }; diff --git a/packages/js/manifests/wrap/scripts/templates/validate-ts.mustache b/packages/js/manifests/wrap/scripts/templates/validate-ts.mustache index 8892ea2a76..3886f66841 100644 --- a/packages/js/manifests/wrap/scripts/templates/validate-ts.mustache +++ b/packages/js/manifests/wrap/scripts/templates/validate-ts.mustache @@ -6,13 +6,12 @@ */ import { AnyWrapManifest, - WrapManifestVersions + WrapManifestVersions, + {{#formats}} + WrapManifestSchema_{{tsVersion}} + {{/formats}} } from "."; {{#validators.length}}import * as Validators from "../validators";{{/validators.length}} -{{#formats}} -import schema_{{tsVersion}} from "@polywrap/wrap-manifest-schemas/formats/wrap.info/{{version}}.json"; -import abi_schema_{{abiTsVersion}} from "@polywrap/wrap-manifest-schemas/formats/abi/{{abiVersion}}.json"; -{{/formats}} import { Schema, @@ -20,33 +19,20 @@ import { ValidationError, ValidatorResult } from "jsonschema"; -import { resolve, bundle, FileInfo, $Refs } from "json-schema-ref-parser"; -import path from "path"; +import { resolve, $Refs } from "json-schema-ref-parser"; type WrapManifestSchemas = { [key in WrapManifestVersions]: Schema | undefined }; -type WrapAbiSchemas = { - [key in WrapManifestVersions]: Schema | undefined -} - const schemas: WrapManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, + "0.1.0": WrapManifestSchema_0_1, {{#formats}} - "{{version}}": schema_{{tsVersion}}, + "{{version}}": WrapManifestSchema_{{tsVersion}}, {{/formats}} }; -const abiSchemas: WrapAbiSchemas = { - // NOTE: Patch fix for backwards compatability - "0.1.0": abi_schema_0_1, - {{#formats}} - "{{version}}": abi_schema_{{abiTsVersion}}, - {{/formats}} -} - {{#validators}} Validator.prototype.{{.}} = Validators.{{.}}; {{/validators}} @@ -65,37 +51,15 @@ export async function validateWrapManifest( extSchema: Schema | undefined = undefined ): Promise { const schema = schemas[manifest.version as WrapManifestVersions]; - const abiSchema = abiSchemas[manifest.version as WrapManifestVersions]; - if (!schema || !abiSchema) { + if (!schema) { throw new Error(`Unrecognized WrapManifest schema version "${manifest.version}"\nmanifest: ${JSON.stringify(manifest, null, 2)}`); } - if (!schema.properties) { - // This should never happen - throw new Error(`WrapManifest schema doesn't contain any properties`) - } - - const abiJsonSchemaRelPath = schema.properties.abi.$ref as string; - - const finalSchema = await bundle(schema as any, { - resolve: { - file: { - read: (file: FileInfo) => { - // If both url is same - if (!path.relative(abiJsonSchemaRelPath, file.url)) { - return abiSchema as any; - } - return file.data; - }, - }, - }, - }); - - const refs: $Refs = await resolve(finalSchema); + const refs: $Refs = await resolve(schema as any); const validator = new Validator(); - validator.addSchema(finalSchema as Schema); + validator.addSchema(schema); const resolveRefs = () => { const unresolvedRef = validator.unresolvedRefs.shift(); @@ -113,7 +77,7 @@ export async function validateWrapManifest( resolveRefs(); - throwIfErrors(validator.validate(manifest, finalSchema as Schema), manifest.version); + throwIfErrors(validator.validate(manifest, schema), manifest.version); if (extSchema) { throwIfErrors(validator.validate(manifest, extSchema), manifest.version); diff --git a/packages/js/manifests/wrap/src/formats/wrap.info/0.1.schema.json b/packages/js/manifests/wrap/src/formats/wrap.info/0.1.schema.json new file mode 100644 index 0000000000..a14436328f --- /dev/null +++ b/packages/js/manifests/wrap/src/formats/wrap.info/0.1.schema.json @@ -0,0 +1,679 @@ +{ + "id": "WrapManifest", + "type": "object", + "additionalProperties": false, + "required": [ + "version", + "name", + "type", + "abi" + ], + "properties": { + "version": { + "description": "WRAP Standard Version", + "type": "string", + "enum": [ + "0.1.0", + "0.1" + ] + }, + "type": { + "description": "Wrapper Package Type", + "type": "string", + "enum": [ + "wasm", + "interface" + ] + }, + "name": { + "description": "Wrapper Name", + "type": "string", + "pattern": "^[a-zA-Z0-9\\-\\_]+$" + }, + "abi": { + "id": "Abi", + "type": "object", + "unevaluatedProperties": false, + "required": [ + "objectTypes", + "enumTypes", + "interfaceTypes", + "importedObjectTypes", + "importedModuleTypes", + "importedEnumTypes", + "importedEnvTypes" + ], + "properties": { + "version": { + "description": "ABI Version", + "type": "string", + "const": "0.1" + }, + "objectTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/objectDefinition" + } + }, + "moduleType": { + "$ref": "#/properties/abi/definitions/moduleDefinition" + }, + "enumTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/enumDefinition" + } + }, + "interfaceTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/interfaceDefinition" + } + }, + "importedObjectTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/importedObjectDefinition" + } + }, + "importedModuleTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/importedModuleDefinition" + } + }, + "importedEnumTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/importedEnumDefinition" + } + }, + "importedEnvTypes": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/importedEnvDefinition" + } + }, + "envType": { + "$ref": "#/properties/abi/definitions/envDefinition" + } + }, + "definitions": { + "objectDefinition": { + "type": "object", + "required": [ + "properties", + "interfaces" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "properties": { + "properties": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/propertyDefinition" + } + }, + "interfaces": { + "type": "array", + "items": { + "$ref": "#/properties/abi/definitions/interfaceImplementedDefinition" + } + } + }, + "unevaluatedProperties": false + }, + "moduleDefinition": { + "type": "object", + "required": [ + "methods", + "imports", + "interfaces" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "properties": { + "methods": { + "type": "array", + "items": [ + { + "$ref": "#/properties/abi/definitions/methodDefinition" + } + ] + }, + "imports": { + "type": "array", + "items": [ + { + "$ref": "#/properties/abi/definitions/importedModuleRef" + } + ] + }, + "interfaces": { + "type": "array", + "items": [ + { + "$ref": "#/properties/abi/definitions/interfaceImplementedDefinition" + } + ] + } + }, + "unevaluatedProperties": false + }, + "interfaceImplementedDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + ], + "unevaluatedProperties": false + }, + "methodDefinition": { + "type": "object", + "required": [ + "arguments", + "return" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "properties": { + "arguments": { + "type": "array", + "items": [ + { + "$ref": "#/properties/abi/definitions/propertyDefinition" + } + ] + }, + "env": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + } + }, + "unevaluatedProperties": false + }, + "return": { + "$ref": "#/properties/abi/definitions/propertyDefinition" + } + }, + "unevaluatedProperties": false + }, + "envDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/objectDefinition" + } + ] + }, + "enumDefinition": { + "type": "object", + "required": [ + "constants" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "properties": { + "constants": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "interfaceDefinition": { + "type": "object", + "required": [ + "capabilities" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/importedDefinition" + } + ], + "properties": { + "capabilities": { + "$ref": "#/properties/abi/definitions/capabilityDefinition" + } + }, + "unevaluatedProperties": false + }, + "capabilityDefinition": { + "type": "object", + "properties": { + "getImplementations": { + "type": "object", + "required": [ + "enabled" + ], + "properties": { + "enabled": { + "type": "boolean" + } + }, + "unevaluatedProperties": false + } + }, + "unevaluatedProperties": false + }, + "importedDefinition": { + "type": "object", + "required": [ + "uri", + "namespace", + "nativeType" + ], + "properties": { + "uri": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "nativeType": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "importedObjectDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/objectDefinition" + }, + { + "$ref": "#/properties/abi/definitions/importedDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "unevaluatedProperties": false + }, + "importedModuleDefinition": { + "type": "object", + "required": [ + "methods" + ], + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "$ref": "#/properties/abi/definitions/importedDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "properties": { + "methods": { + "type": "array", + "items": [ + { + "$ref": "#/properties/abi/definitions/methodDefinition" + } + ] + }, + "isInterface": { + "type": [ + "boolean", + "null" + ] + } + }, + "unevaluatedProperties": false + }, + "importedEnumDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/enumDefinition" + }, + { + "$ref": "#/properties/abi/definitions/importedDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + } + ], + "unevaluatedProperties": false + }, + "importedEnvDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/importedObjectDefinition" + } + ], + "unevaluatedProperties": false + }, + "withKind": { + "type": "object", + "properties": { + "kind": { + "type": "number" + } + }, + "unevaluatedProperties": false, + "required": [ + "kind" + ] + }, + "withComment": { + "type": "object", + "properties": { + "comment": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "propertyDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/withComment" + }, + { + "$ref": "#/properties/abi/definitions/anyDefinition" + } + ], + "unevaluatedProperties": false + }, + "genericDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/withKind" + }, + { + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string" + }, + "name": { + "type": [ + "string", + "null" + ] + }, + "required": { + "type": [ + "boolean", + "null" + ] + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": false + }, + "anyDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + }, + { + "properties": { + "array": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/arrayDefinition" + }, + { + "type": "null" + } + ] + }, + "scalar": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/scalarDefinition" + }, + { + "type": "null" + } + ] + }, + "map": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/mapDefinition" + }, + { + "type": "null" + } + ] + }, + "object": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/objectRef" + }, + { + "type": "null" + } + ] + }, + "enum": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/enumRef" + }, + { + "type": "null" + } + ] + }, + "unresolvedObjectOrEnum": { + "anyOf": [ + { + "$ref": "#/properties/abi/definitions/unresolvedObjectOrEnumRef" + }, + { + "type": "null" + } + ] + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": false + }, + "arrayDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/anyDefinition" + }, + { + "properties": { + "item": { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": false, + "required": [ + "item" + ] + }, + "scalarType": { + "type": "string", + "enum": [ + "UInt", + "UInt8", + "UInt16", + "UInt32", + "Int", + "Int8", + "Int16", + "Int32", + "String", + "Boolean", + "Bytes", + "BigInt", + "BigNumber", + "JSON" + ] + }, + "scalarDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + ], + "properties": { + "type": { + "$ref": "#/properties/abi/definitions/scalarType" + } + }, + "unevaluatedProperties": false, + "required": [ + "type" + ] + }, + "mapKeyType": { + "type": "string", + "enum": [ + "UInt", + "UInt8", + "UInt16", + "UInt32", + "Int", + "Int8", + "Int16", + "Int32", + "String" + ] + }, + "mapKeyDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/anyDefinition" + }, + { + "properties": { + "type": { + "$ref": "#/properties/abi/definitions/mapKeyType" + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": false, + "required": [ + "type" + ] + }, + "mapDefinition": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/anyDefinition" + }, + { + "$ref": "#/properties/abi/definitions/withComment" + }, + { + "properties": { + "key": { + "$ref": "#/properties/abi/definitions/mapKeyDefinition" + }, + "value": { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": false, + "required": [ + "key", + "value" + ] + }, + "objectRef": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + ], + "unevaluatedProperties": false + }, + "enumRef": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + ], + "unevaluatedProperties": false + }, + "unresolvedObjectOrEnumRef": { + "type": "object", + "allOf": [ + { + "$ref": "#/properties/abi/definitions/genericDefinition" + } + ], + "unevaluatedProperties": false + }, + "importedModuleRef": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + } + } + } +} \ No newline at end of file diff --git a/packages/js/manifests/wrap/src/formats/wrap.info/index.ts b/packages/js/manifests/wrap/src/formats/wrap.info/index.ts index 2e4abf0c52..5bbcae4a72 100644 --- a/packages/js/manifests/wrap/src/formats/wrap.info/index.ts +++ b/packages/js/manifests/wrap/src/formats/wrap.info/index.ts @@ -10,9 +10,12 @@ import { Abi as WrapAbi_0_1_0_1 } from "./0.1"; +import WrapManifestSchema_0_1 from "./0.1.schema.json"; + export { WrapManifest_0_1, - WrapAbi_0_1_0_1 + WrapAbi_0_1_0_1, + WrapManifestSchema_0_1 }; export enum WrapManifestVersions { diff --git a/packages/js/manifests/wrap/src/formats/wrap.info/validate.ts b/packages/js/manifests/wrap/src/formats/wrap.info/validate.ts index bdecc6c4d5..fd90559a99 100644 --- a/packages/js/manifests/wrap/src/formats/wrap.info/validate.ts +++ b/packages/js/manifests/wrap/src/formats/wrap.info/validate.ts @@ -6,11 +6,10 @@ */ import { AnyWrapManifest, - WrapManifestVersions + WrapManifestVersions, + WrapManifestSchema_0_1 } from "."; -import schema_0_1 from "@polywrap/wrap-manifest-schemas/formats/wrap.info/0.1.json"; -import abi_schema_0_1 from "@polywrap/wrap-manifest-schemas/formats/abi/0.1.json"; import { Schema, @@ -18,29 +17,18 @@ import { ValidationError, ValidatorResult } from "jsonschema"; -import { resolve, bundle, FileInfo, $Refs } from "json-schema-ref-parser"; -import path from "path"; +import { resolve, $Refs } from "json-schema-ref-parser"; type WrapManifestSchemas = { [key in WrapManifestVersions]: Schema | undefined }; -type WrapAbiSchemas = { - [key in WrapManifestVersions]: Schema | undefined -} - const schemas: WrapManifestSchemas = { // NOTE: Patch fix for backwards compatability - "0.1.0": schema_0_1, - "0.1": schema_0_1, + "0.1.0": WrapManifestSchema_0_1, + "0.1": WrapManifestSchema_0_1, }; -const abiSchemas: WrapAbiSchemas = { - // NOTE: Patch fix for backwards compatability - "0.1.0": abi_schema_0_1, - "0.1": abi_schema_0_1, -} - function throwIfErrors(result: ValidatorResult, version: string) { if (result.errors.length) { @@ -56,37 +44,15 @@ export async function validateWrapManifest( extSchema: Schema | undefined = undefined ): Promise { const schema = schemas[manifest.version as WrapManifestVersions]; - const abiSchema = abiSchemas[manifest.version as WrapManifestVersions]; - if (!schema || !abiSchema) { + if (!schema) { throw new Error(`Unrecognized WrapManifest schema version "${manifest.version}"\nmanifest: ${JSON.stringify(manifest, null, 2)}`); } - if (!schema.properties) { - // This should never happen - throw new Error(`WrapManifest schema doesn't contain any properties`) - } - - const abiJsonSchemaRelPath = schema.properties.abi.$ref as string; - - const finalSchema = await bundle(schema as any, { - resolve: { - file: { - read: (file: FileInfo) => { - // If both url is same - if (!path.relative(abiJsonSchemaRelPath, file.url)) { - return abiSchema as any; - } - return file.data; - }, - }, - }, - }); - - const refs: $Refs = await resolve(finalSchema); + const refs: $Refs = await resolve(schema as any); const validator = new Validator(); - validator.addSchema(finalSchema as Schema); + validator.addSchema(schema); const resolveRefs = () => { const unresolvedRef = validator.unresolvedRefs.shift(); @@ -104,7 +70,7 @@ export async function validateWrapManifest( resolveRefs(); - throwIfErrors(validator.validate(manifest, finalSchema as Schema), manifest.version); + throwIfErrors(validator.validate(manifest, schema), manifest.version); if (extSchema) { throwIfErrors(validator.validate(manifest, extSchema), manifest.version); diff --git a/packages/templates/plugin/typescript/tsconfig.json b/packages/templates/plugin/typescript/tsconfig.json index a015a98879..561f3475e3 100644 --- a/packages/templates/plugin/typescript/tsconfig.json +++ b/packages/templates/plugin/typescript/tsconfig.json @@ -9,6 +9,7 @@ "dom" ], "moduleResolution": "node", + "resolveJsonModule": true, "declaration": true, "preserveSymlinks": true, "preserveWatchOutput": true,