Skip to content

Commit

Permalink
Merge pull request #1032 from polywrap/origin-dev
Browse files Browse the repository at this point in the history
Prep Origin 0.1.1
  • Loading branch information
dOrgJelli authored Jul 7, 2022
2 parents 55110e0 + 7637c51 commit 729693a
Show file tree
Hide file tree
Showing 85 changed files with 1,053 additions and 614 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Polywrap Origin (0.1.1)
## Features
* [PR-1017](https://github.com/polywrap/monorepo/pull/1017) `@polywrap/templates`, `polywrap` CLI: Rust wasm wrapper project template has been added, and made available via the `polywrap create ...` CLI command.

## Bugs
* [PR-1016](https://github.com/polywrap/monorepo/pull/1016) `polywrap` CLI: Improved logging when running workflows using the `polywrap run ...` command.
* [PR-924](https://github.com/polywrap/monorepo/pull/924) `@polywrap/schema-parse`, `@polywrap/schema-bind`: Complex `Map<Key, Value>` type usages within wrapper schemas lead to incorrect bindings being generated. Additional tests + fixes have been added.

# Polywrap Origin (0.1.0)
![Public Release Announcement (2)](https://user-images.githubusercontent.com/5522128/177474776-76886b67-6554-41a9-841b-939728e273ca.png)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
2 changes: 1 addition & 1 deletion packages/cli/bin/polywrap
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if (['v', 'version', '-v', '--v', '-version', '--version'].includes(process.argv
}

var sourceDir = __dirname + '/../build'
require(sourceDir + '/cli').run(process.argv)
require(sourceDir + '/cli').run(process.argv)
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Options:
Commands:
wasm [options] <language> <name> Create a Polywrap wasm wrapper langs:
assemblyscript, interface
assemblyscript, rust, interface
app [options] <language> <name> Create a Polywrap application langs:
typescript-node, typescript-react
plugin [options] <language> <name> Create a Polywrap plugin langs:
Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/__tests__/e2e/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,32 +230,38 @@ describe("e2e tests for run command", () => {
"./workflows/config.ts",
"-v",
"./workflows/validator.cue",
"-q",
],
cwd: testCaseRoot,
cli: polywrapCli,
});

expect(stdout).toBe("");
const output = parseOutput(stdout);

expect(stdout).toBeTruthy();
expect(output.filter((o => o.status === "SUCCEED"))).toHaveLength(output.length);
expect(stderr).toBe("");
expect(code).toEqual(0);

}, 48000);

it("Should print error on stderr if validation fails", async () => {
const { exitCode: code, stderr } = await runCLI({
const { exitCode: code, stdout } = await runCLI({
args: [
"run",
"./workflows/e2e.json",
"-v",
"./workflows/validator.cue",
"-q",
],
cwd: testCaseRoot,
cli: polywrapCli,
});

const output = parseOutput(stdout);

expect(code).toEqual(1);
expect(stderr).toBeDefined();
expect(output[0].status).toBe("FAILED");
expect(output[0].error).toBeTruthy();
expect(output[1].status).toBe("SKIPPED");
expect(output[2].status).toBe("SKIPPED");
}, 48000);
});
50 changes: 44 additions & 6 deletions packages/cli/src/__tests__/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,58 @@ export const clearStyle = (styled: string) => {

export const parseOutput = (
outputs: string
): Array<{ id: string; data?: unknown, error?: unknown }> => {
): Array<{
id: string;
data?: unknown;
error?: unknown;
validation?: string;
status: string;
}> => {
const outputsArr = outputs.split(/-{35}[\t \n]+-{35}/);
return outputsArr.map((output) => {
output = output.replace(/-{35}/, "");
const idIdx = output.indexOf("ID: ");
const statusIdx = output.indexOf("Status: ");
const dataIdx = output.indexOf("Data: ");
const validationIdx = output.indexOf("Validation: ");
if (dataIdx !== -1) {
const id = output.substring(idIdx + 3, dataIdx - 1);
const data = output.substring(dataIdx + 6);
return { id: id.replace(/\s/g, ""), data: JSON.parse(data) };
const id = output.substring(idIdx + 3, statusIdx - 1);
const status = output.substring(statusIdx + 8, dataIdx - 1);
const data =
validationIdx !== -1
? output.substring(dataIdx + 6, validationIdx - 1)
: output.substring(dataIdx + 6);
const validation =
validationIdx !== -1
? output.substring(validationIdx + 12).replace(/\s/g, "")
: undefined;

return {
id: id.replace(/\s/g, ""),
status: status,
data: JSON.parse(data),
validation: validation,
};
} else {
const errIdx = output.indexOf("Error: ");
const id = output.substring(idIdx + 3);
return { id: id.replace(/\s/g, ""), error: output.substring(errIdx + 7) };

const id = output.substring(idIdx + 3, statusIdx - 1);
const status = output.substring(statusIdx + 8, errIdx - 1);
const error =
validationIdx !== -1
? output.substring(errIdx + 6, validationIdx - 1)
: output.substring(errIdx + 6);
const validation =
validationIdx !== -1
? output.substring(validationIdx + 12).replace(/\s/g, "")
: undefined;

return {
id: id.replace(/\s/g, ""),
status: status,
error: error,
validation: validation,
};
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createPluginStr = intlMsg.commands_create_options_createPlugin();
const pathStr = intlMsg.commands_create_options_o_path();

export const supportedLangs = {
wasm: ["assemblyscript", "interface"] as const,
wasm: ["assemblyscript", "rust", "interface"] as const,
app: ["typescript-node", "typescript-react"] as const,
plugin: ["typescript"] as const,
};
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
validateOutput,
} from "../lib";

import { InvokeResult, Workflow, JobResult } from "@polywrap/core-js";
import { Workflow, JobResult, JobStatus } from "@polywrap/core-js";
import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js";
import path from "path";
import yaml from "js-yaml";
Expand Down Expand Up @@ -79,37 +79,39 @@ const _run = async (workflowPath: string, options: WorkflowCommandOptions) => {
const workflow: Workflow = getParser(workflowPath)(
fs.readFileSync(workflowPath).toString()
);
const workflowOutput: (InvokeResult & { id: string })[] = [];
const workflowOutput: (JobResult & { id: string })[] = [];

await client.run({
workflow,
config: clientConfig,
ids: jobs,
onExecution: async (id: string, jobResult: JobResult) => {
const { data, error } = jobResult;
const { data, error, status } = jobResult;

if (!quiet) {
console.log("-----------------------------------");
console.log(`ID: ${id}`);
console.log(`Status: ${status}`);
}

if (!quiet && data) {
if (!quiet && data !== undefined) {
console.log(`Data: ${JSON.stringify(data, null, 2)}`);
console.log("-----------------------------------");
}

if (!quiet && error) {
if (!quiet && error !== undefined) {
console.log(`Error: ${error.message}`);
console.log(error.stack || "");
console.log("-----------------------------------");
process.exitCode = 1;
}

if (validateScript) {
await validateOutput(id, { data, error }, validateScript);
if (status !== JobStatus.SKIPPED && validateScript) {
await validateOutput(id, { data, error }, validateScript, quiet);
}

if (!quiet) {
console.log("-----------------------------------");
}

workflowOutput.push({ id, data, error });
workflowOutput.push({ id, status, data, error });
},
});

Expand Down
24 changes: 16 additions & 8 deletions packages/cli/src/lib/helpers/workflow-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export async function cueExists(): Promise<boolean> {
export async function validateOutput(
id: string,
result: InvokeResult,
validateScriptPath: string
validateScriptPath: string,
quiet?: boolean
): Promise<void> {
if (!(await cueExists())) {
console.warn(intlMsg.commands_run_error_cueDoesNotExist());
Expand All @@ -34,18 +35,25 @@ export async function validateOutput(
await fs.promises.writeFile(jsonOutput, JSON.stringify(result, null, 2));

try {
const { stderr } = await runCommand(
await runCommand(
`cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}`,
true
);

if (stderr) {
console.error(stderr);
console.log("-----------------------------------");
if (!quiet) {
console.log("Validation: SUCCEED");
}
} catch (e) {
console.error(e);
console.log("-----------------------------------");
const msgLines = e.split(/\r?\n/);
msgLines[1] = `${validateScriptPath}:${msgLines[1]
.split(":")
.slice(1)
.join(":")}`;
const errMsg = msgLines.slice(0, 2).join("\n");

if (!quiet) {
console.log("Validation: FAILED");
console.log(`Error: ${errMsg}`);
}
process.exitCode = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/js/core/src/types/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export type Workflow<TUri extends Uri | string = string> = {
};

export enum JobStatus {
SUCCEED,
FAILED,
SKIPPED,
SUCCEED = "SUCCEED",
FAILED = "FAILED",
SKIPPED = "SKIPPED",
}

export interface JobResult<TData extends unknown = unknown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ return reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read):
return reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read): {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}} => {
return reader.read{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}();
}, (reader: Read): {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}} => {
{{#value}}
{{> deserialize_map_value}}
{{/value}}
});
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export function deserialize{{name}}Args(argsBuf: ArrayBuffer): Args_{{name}} {
_{{name}} = reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read): {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}} => {
return reader.read{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}();
}, (reader: Read): {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}} => {
{{#value}}
{{> deserialize_map_value}}
{{/value}}
});
{{/map}}
{{#enum}}
Expand Down Expand Up @@ -120,9 +118,7 @@ export function write{{name}}Result(writer: Write, result: {{#return}}{{#toWasm}
writer.write{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}(result, (writer: Write, key: {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}}) => {
writer.write{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}(key);
}, (writer: Write, value: {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}}): void => {
{{#value}}
{{> serialize_map_value}}
{{/value}}
});
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export function write{{type}}(writer: Write, type: {{type}}): void {
writer.write{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}(type.{{#handleKeywords}}{{name}}{{/handleKeywords}}, (writer: Write, key: {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}}) => {
writer.write{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}(key);
}, (writer: Write, value: {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}}): void => {
{{#value}}
{{> serialize_map_value}}
{{/value}}
});
{{/map}}
{{#object}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}
reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
}, |reader| {
{{#value}}
{{> deserialize_map_value}}
{{/value}}
})
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}
reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
}, |reader| {
{{#value}}
{{> deserialize_map_value_nobox}}
{{/value}}
})
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ pub fn deserialize_{{#toLower}}{{name}}{{/toLower}}_args(args: &[u8]) -> Result<
_{{#toLower}}{{name}}{{/toLower}} = reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
}, |reader| {
{{#value}}
{{> deserialize_map_value_nobox}}
{{/value}}
})?;
{{/map}}
{{#enum}}
Expand Down Expand Up @@ -144,9 +142,7 @@ pub fn write_{{#toLower}}{{name}}{{/toLower}}_result<W: Write>(result: {{#return
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(&result, |writer, key| {
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
}, |writer, value| {
{{#value}}
{{> serialize_map_value}}
{{/value}}
})?;
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ pub fn write_{{#toLower}}{{type}}{{/toLower}}<W: Write>(args: &{{#toUpper}}{{typ
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(&args.{{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}, |writer, key| {
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
}, |writer, value| {
{{#value}}
{{> serialize_map_value}}
{{/value}}
})?;
{{/map}}
{{#object}}
Expand Down Expand Up @@ -130,9 +128,7 @@ pub fn read_{{#toLower}}{{type}}{{/toLower}}<R: Read>(reader: &mut R) -> Result<
_{{#toLower}}{{name}}{{/toLower}} = reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()?
}, |reader| {
{{#value}}
{{> deserialize_map_value_nobox}}
{{/value}}
})?;
{{/map}}
{{#enum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(value, |writer, key| {
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
}, |writer, value| {
{{#value}}
{{> serialize_map_value}}
{{/value}}
})
{{/map}}
{{#enum}}
Expand Down
Loading

0 comments on commit 729693a

Please sign in to comment.