New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@polywrap/wrap-manifest-types-js

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polywrap/wrap-manifest-types-js - npm Package Compare versions

Comparing version

to
0.10.0-pre.0

8

package.json
{
"name": "@polywrap/wrap-manifest-types-js",
"description": "WRAP Manifest TypeScript Typings",
"version": "0.9.4",
"version": "0.10.0-pre.0",
"license": "MIT",

@@ -19,3 +19,2 @@ "repository": {

"dependencies": {
"@polywrap/msgpack-js": "0.9.4",
"json-schema-ref-parser": "9.0.9",

@@ -26,4 +25,5 @@ "jsonschema": "1.4.0",

"devDependencies": {
"@polywrap/os-js": "0.9.4",
"@polywrap/wrap-manifest-schemas": "0.9.4",
"@polywrap/msgpack-js": "0.10.0-pre.0",
"@polywrap/os-js": "0.10.0-pre.0",
"@polywrap/wrap-manifest-schemas": "0.9.3",
"@types/jest": "26.0.8",

@@ -30,0 +30,0 @@ "@types/mustache": "4.0.1",

import path from "path";
import fs from "fs";
import axios from "axios";
import * as os from "@polywrap/os-js";

@@ -8,12 +9,4 @@ import Mustache from "mustache";

async function generateFormatTypes() {
// Fetch all schemas within the @polywrap/wrap-manifest-schemas/schemas/formats directory
const schemasPackageDir = path.dirname(
require.resolve("@polywrap/wrap-manifest-schemas")
);
const formatsDir = path.join(schemasPackageDir, "formats");
// Resolve json-schema to typescript for wrap format type
async function wrapCodegen() {
const formatTypeName = "wrap.info";
const wrapDir = path.join(formatsDir, formatTypeName);
const wrapOutputDir = path.join(

@@ -23,2 +16,5 @@ __dirname,

);
const wrapSchemas: JSONSchema[] = [];
const wrapModules: {

@@ -30,72 +26,45 @@ interface: string;

// Get all JSON schemas for this format type (v1, v2, etc)
const wrapSchemaFiles = fs.readdirSync(wrapDir);
const wrapSchemas: JSONSchema[] = [];
const versions = (
await axios.get(
"https://raw.githubusercontent.com/polywrap/wrap/master/manifest/wrap.info/versions.json"
)
).data;
for (const version of versions) {
const wrapSchema = (await axios.get(
`https://raw.githubusercontent.com/polywrap/wrap/master/manifest/wrap.info/${version}.json`
)).data;
for (let k = 0; k < wrapSchemaFiles.length; ++k) {
const wrapSchemaName = wrapSchemaFiles[k];
const wrapVersion = wrapSchemaName.replace(".json", "");
const wrapSchemaPath = path.join(wrapDir, wrapSchemaName);
try {
// Parse the JSON schema
const wrapSchema = JSON.parse(
fs.readFileSync(wrapSchemaPath, { encoding: "utf-8" })
);
const abiJsonSchemaRelPath = wrapSchema.properties.abi.$ref;
const abiJsonSchemaPath = path.join(wrapDir, abiJsonSchemaRelPath);
const abiJsonSchema = JSON.parse(
fs.readFileSync(abiJsonSchemaPath, { encoding: "utf-8" })
);
const abiVersion = path
.parse(abiJsonSchemaPath)
.base.replace(".json", "");
const bundledSchema = await bundle(wrapSchema, {
resolve: {
file: {
read: (file: FileInfo) => {
// If both url is same
if (!path.relative(abiJsonSchemaRelPath, file.url)) {
return abiJsonSchema;
}
return file.data;
},
const bundledSchema = await bundle(wrapSchema, {
resolve: {
http: {
read: async (file: FileInfo) => {
const response = await axios.get(file.url);
return response.data;
},
},
});
},
});
wrapSchemas.push(bundledSchema);
wrapSchemas.push(bundledSchema);
// Convert it to a TypeScript interface
let tsFile = await compile(bundledSchema as any, wrapSchema.id, {additionalProperties: false});
// Convert it to a TypeScript interface
let tsFile = await compile(bundledSchema as any, wrapSchema.id, {additionalProperties: false});
// Hack: replace all instances of `abi: unknown;` with `abi: Abi;`
tsFile = tsFile.replace("abi: unknown;", "abi: Abi;");
// Emit the result
const tsOutputPath = path.join(wrapOutputDir, `${version}.ts`);
fs.mkdirSync(path.dirname(tsOutputPath), { recursive: true });
os.writeFileSync(
tsOutputPath,
`/* eslint-disable @typescript-eslint/naming-convention */\n${tsFile}`
);
// Emit the result
const tsOutputPath = path.join(wrapOutputDir, `${wrapVersion}.ts`);
fs.mkdirSync(path.dirname(tsOutputPath), { recursive: true });
os.writeFileSync(
tsOutputPath,
`/* eslint-disable @typescript-eslint/naming-convention */\n${tsFile}`
);
const schemaOutputPath = path.join(wrapOutputDir, `${version}.schema.json`);
os.writeFileSync(schemaOutputPath, JSON.stringify(bundledSchema, null ,2));
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,
version: wrapVersion,
abiVersion: abiVersion,
});
} catch (error) {
console.error(
`Error generating the Manifest file ${wrapSchemaPath}: `,
error
);
throw error;
}
// Add metadata for the root index.ts file to use
wrapModules.push({
interface: wrapSchema.id,
version: version,
abiVersion: version,
});
}

@@ -205,3 +174,3 @@

generateFormatTypes()
wrapCodegen()
.then(() => {

@@ -208,0 +177,0 @@ process.exit();