Skip to content

Commit 729693a

Browse files
authored
Merge pull request #1032 from polywrap/origin-dev
Prep Origin 0.1.1
2 parents 55110e0 + 7637c51 commit 729693a

File tree

85 files changed

+1053
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1053
-614
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Polywrap Origin (0.1.1)
2+
## Features
3+
* [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.
4+
5+
## Bugs
6+
* [PR-1016](https://github.com/polywrap/monorepo/pull/1016) `polywrap` CLI: Improved logging when running workflows using the `polywrap run ...` command.
7+
* [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.
8+
19
# Polywrap Origin (0.1.0)
210
![Public Release Announcement (2)](https://user-images.githubusercontent.com/5522128/177474776-76886b67-6554-41a9-841b-939728e273ca.png)
311

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

packages/cli/bin/polywrap

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ if (['v', 'version', '-v', '--v', '-version', '--version'].includes(process.argv
1010
}
1111

1212
var sourceDir = __dirname + '/../build'
13-
require(sourceDir + '/cli').run(process.argv)
13+
require(sourceDir + '/cli').run(process.argv)

packages/cli/src/__tests__/e2e/create.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Options:
1313
1414
Commands:
1515
wasm [options] <language> <name> Create a Polywrap wasm wrapper langs:
16-
assemblyscript, interface
16+
assemblyscript, rust, interface
1717
app [options] <language> <name> Create a Polywrap application langs:
1818
typescript-node, typescript-react
1919
plugin [options] <language> <name> Create a Polywrap plugin langs:

packages/cli/src/__tests__/e2e/run.spec.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -230,32 +230,38 @@ describe("e2e tests for run command", () => {
230230
"./workflows/config.ts",
231231
"-v",
232232
"./workflows/validator.cue",
233-
"-q",
234233
],
235234
cwd: testCaseRoot,
236235
cli: polywrapCli,
237236
});
238237

239-
expect(stdout).toBe("");
238+
const output = parseOutput(stdout);
239+
240+
expect(stdout).toBeTruthy();
241+
expect(output.filter((o => o.status === "SUCCEED"))).toHaveLength(output.length);
240242
expect(stderr).toBe("");
241243
expect(code).toEqual(0);
242244

243245
}, 48000);
244246

245247
it("Should print error on stderr if validation fails", async () => {
246-
const { exitCode: code, stderr } = await runCLI({
248+
const { exitCode: code, stdout } = await runCLI({
247249
args: [
248250
"run",
249251
"./workflows/e2e.json",
250252
"-v",
251253
"./workflows/validator.cue",
252-
"-q",
253254
],
254255
cwd: testCaseRoot,
255256
cli: polywrapCli,
256257
});
257258

259+
const output = parseOutput(stdout);
260+
258261
expect(code).toEqual(1);
259-
expect(stderr).toBeDefined();
262+
expect(output[0].status).toBe("FAILED");
263+
expect(output[0].error).toBeTruthy();
264+
expect(output[1].status).toBe("SKIPPED");
265+
expect(output[2].status).toBe("SKIPPED");
260266
}, 48000);
261267
});

packages/cli/src/__tests__/e2e/utils.ts

+44-6
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,58 @@ export const clearStyle = (styled: string) => {
77

88
export const parseOutput = (
99
outputs: string
10-
): Array<{ id: string; data?: unknown, error?: unknown }> => {
10+
): Array<{
11+
id: string;
12+
data?: unknown;
13+
error?: unknown;
14+
validation?: string;
15+
status: string;
16+
}> => {
1117
const outputsArr = outputs.split(/-{35}[\t \n]+-{35}/);
1218
return outputsArr.map((output) => {
1319
output = output.replace(/-{35}/, "");
1420
const idIdx = output.indexOf("ID: ");
21+
const statusIdx = output.indexOf("Status: ");
1522
const dataIdx = output.indexOf("Data: ");
23+
const validationIdx = output.indexOf("Validation: ");
1624
if (dataIdx !== -1) {
17-
const id = output.substring(idIdx + 3, dataIdx - 1);
18-
const data = output.substring(dataIdx + 6);
19-
return { id: id.replace(/\s/g, ""), data: JSON.parse(data) };
25+
const id = output.substring(idIdx + 3, statusIdx - 1);
26+
const status = output.substring(statusIdx + 8, dataIdx - 1);
27+
const data =
28+
validationIdx !== -1
29+
? output.substring(dataIdx + 6, validationIdx - 1)
30+
: output.substring(dataIdx + 6);
31+
const validation =
32+
validationIdx !== -1
33+
? output.substring(validationIdx + 12).replace(/\s/g, "")
34+
: undefined;
35+
36+
return {
37+
id: id.replace(/\s/g, ""),
38+
status: status,
39+
data: JSON.parse(data),
40+
validation: validation,
41+
};
2042
} else {
2143
const errIdx = output.indexOf("Error: ");
22-
const id = output.substring(idIdx + 3);
23-
return { id: id.replace(/\s/g, ""), error: output.substring(errIdx + 7) };
44+
45+
const id = output.substring(idIdx + 3, statusIdx - 1);
46+
const status = output.substring(statusIdx + 8, errIdx - 1);
47+
const error =
48+
validationIdx !== -1
49+
? output.substring(errIdx + 6, validationIdx - 1)
50+
: output.substring(errIdx + 6);
51+
const validation =
52+
validationIdx !== -1
53+
? output.substring(validationIdx + 12).replace(/\s/g, "")
54+
: undefined;
55+
56+
return {
57+
id: id.replace(/\s/g, ""),
58+
status: status,
59+
error: error,
60+
validation: validation,
61+
};
2462
}
2563
});
2664
};

packages/cli/src/commands/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const createPluginStr = intlMsg.commands_create_options_createPlugin();
1313
const pathStr = intlMsg.commands_create_options_o_path();
1414

1515
export const supportedLangs = {
16-
wasm: ["assemblyscript", "interface"] as const,
16+
wasm: ["assemblyscript", "rust", "interface"] as const,
1717
app: ["typescript-node", "typescript-react"] as const,
1818
plugin: ["typescript"] as const,
1919
};

packages/cli/src/commands/run.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
validateOutput,
88
} from "../lib";
99

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

8484
await client.run({
8585
workflow,
8686
config: clientConfig,
8787
ids: jobs,
8888
onExecution: async (id: string, jobResult: JobResult) => {
89-
const { data, error } = jobResult;
89+
const { data, error, status } = jobResult;
9090

9191
if (!quiet) {
9292
console.log("-----------------------------------");
9393
console.log(`ID: ${id}`);
94+
console.log(`Status: ${status}`);
9495
}
9596

96-
if (!quiet && data) {
97+
if (!quiet && data !== undefined) {
9798
console.log(`Data: ${JSON.stringify(data, null, 2)}`);
98-
console.log("-----------------------------------");
9999
}
100100

101-
if (!quiet && error) {
101+
if (!quiet && error !== undefined) {
102102
console.log(`Error: ${error.message}`);
103-
console.log(error.stack || "");
104-
console.log("-----------------------------------");
105103
process.exitCode = 1;
106104
}
107105

108-
if (validateScript) {
109-
await validateOutput(id, { data, error }, validateScript);
106+
if (status !== JobStatus.SKIPPED && validateScript) {
107+
await validateOutput(id, { data, error }, validateScript, quiet);
108+
}
109+
110+
if (!quiet) {
111+
console.log("-----------------------------------");
110112
}
111113

112-
workflowOutput.push({ id, data, error });
114+
workflowOutput.push({ id, status, data, error });
113115
},
114116
});
115117

packages/cli/src/lib/helpers/workflow-validator.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export async function cueExists(): Promise<boolean> {
1818
export async function validateOutput(
1919
id: string,
2020
result: InvokeResult,
21-
validateScriptPath: string
21+
validateScriptPath: string,
22+
quiet?: boolean
2223
): Promise<void> {
2324
if (!(await cueExists())) {
2425
console.warn(intlMsg.commands_run_error_cueDoesNotExist());
@@ -34,18 +35,25 @@ export async function validateOutput(
3435
await fs.promises.writeFile(jsonOutput, JSON.stringify(result, null, 2));
3536

3637
try {
37-
const { stderr } = await runCommand(
38+
await runCommand(
3839
`cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}`,
3940
true
4041
);
41-
42-
if (stderr) {
43-
console.error(stderr);
44-
console.log("-----------------------------------");
42+
if (!quiet) {
43+
console.log("Validation: SUCCEED");
4544
}
4645
} catch (e) {
47-
console.error(e);
48-
console.log("-----------------------------------");
46+
const msgLines = e.split(/\r?\n/);
47+
msgLines[1] = `${validateScriptPath}:${msgLines[1]
48+
.split(":")
49+
.slice(1)
50+
.join(":")}`;
51+
const errMsg = msgLines.slice(0, 2).join("\n");
52+
53+
if (!quiet) {
54+
console.log("Validation: FAILED");
55+
console.log(`Error: ${errMsg}`);
56+
}
4957
process.exitCode = 1;
5058
}
5159

packages/js/core/src/types/Workflow.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export type Workflow<TUri extends Uri | string = string> = {
2424
};
2525

2626
export enum JobStatus {
27-
SUCCEED,
28-
FAILED,
29-
SKIPPED,
27+
SUCCEED = "SUCCEED",
28+
FAILED = "FAILED",
29+
SKIPPED = "SKIPPED",
3030
}
3131

3232
export interface JobResult<TData extends unknown = unknown>

packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/deserialize_map_value.mustache

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ return reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read):
1010
return reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read): {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}} => {
1111
return reader.read{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}();
1212
}, (reader: Read): {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}} => {
13-
{{#value}}
1413
{{> deserialize_map_value}}
15-
{{/value}}
1614
});
1715
{{/map}}
1816
{{#enum}}

packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/module-type/serialization-ts.mustache

-4
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ export function deserialize{{name}}Args(argsBuf: ArrayBuffer): Args_{{name}} {
5151
_{{name}} = reader.read{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}((reader: Read): {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}} => {
5252
return reader.read{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}();
5353
}, (reader: Read): {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}} => {
54-
{{#value}}
5554
{{> deserialize_map_value}}
56-
{{/value}}
5755
});
5856
{{/map}}
5957
{{#enum}}
@@ -120,9 +118,7 @@ export function write{{name}}Result(writer: Write, result: {{#return}}{{#toWasm}
120118
writer.write{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}(result, (writer: Write, key: {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}}) => {
121119
writer.write{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}(key);
122120
}, (writer: Write, value: {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}}): void => {
123-
{{#value}}
124121
{{> serialize_map_value}}
125-
{{/value}}
126122
});
127123
{{/map}}
128124
{{#enum}}

packages/schema/bind/src/bindings/assemblyscript/wasm-as/templates/object-type/serialization-ts.mustache

-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export function write{{type}}(writer: Write, type: {{type}}): void {
3030
writer.write{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}(type.{{#handleKeywords}}{{name}}{{/handleKeywords}}, (writer: Write, key: {{#key}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/key}}) => {
3131
writer.write{{#key}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/key}}(key);
3232
}, (writer: Write, value: {{#value}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/value}}): void => {
33-
{{#value}}
3433
{{> serialize_map_value}}
35-
{{/value}}
3634
});
3735
{{/map}}
3836
{{#object}}

packages/schema/bind/src/bindings/rust/wasm-rs/templates/deserialize_map_value.mustache

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}
1010
reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
1111
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
1212
}, |reader| {
13-
{{#value}}
1413
{{> deserialize_map_value}}
15-
{{/value}}
1614
})
1715
{{/map}}
1816
{{#enum}}

packages/schema/bind/src/bindings/rust/wasm-rs/templates/deserialize_map_value_nobox.mustache

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}
1010
reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
1111
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
1212
}, |reader| {
13-
{{#value}}
1413
{{> deserialize_map_value_nobox}}
15-
{{/value}}
1614
})
1715
{{/map}}
1816
{{#enum}}

packages/schema/bind/src/bindings/rust/wasm-rs/templates/module-type/serialization-rs.mustache

-4
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ pub fn deserialize_{{#toLower}}{{name}}{{/toLower}}_args(args: &[u8]) -> Result<
8383
_{{#toLower}}{{name}}{{/toLower}} = reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
8484
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()
8585
}, |reader| {
86-
{{#value}}
8786
{{> deserialize_map_value_nobox}}
88-
{{/value}}
8987
})?;
9088
{{/map}}
9189
{{#enum}}
@@ -144,9 +142,7 @@ pub fn write_{{#toLower}}{{name}}{{/toLower}}_result<W: Write>(result: {{#return
144142
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(&result, |writer, key| {
145143
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
146144
}, |writer, value| {
147-
{{#value}}
148145
{{> serialize_map_value}}
149-
{{/value}}
150146
})?;
151147
{{/map}}
152148
{{#enum}}

packages/schema/bind/src/bindings/rust/wasm-rs/templates/object-type/serialization-rs.mustache

-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ pub fn write_{{#toLower}}{{type}}{{/toLower}}<W: Write>(args: &{{#toUpper}}{{typ
5353
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(&args.{{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}, |writer, key| {
5454
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
5555
}, |writer, value| {
56-
{{#value}}
5756
{{> serialize_map_value}}
58-
{{/value}}
5957
})?;
6058
{{/map}}
6159
{{#object}}
@@ -130,9 +128,7 @@ pub fn read_{{#toLower}}{{type}}{{/toLower}}<R: Read>(reader: &mut R) -> Result<
130128
_{{#toLower}}{{name}}{{/toLower}} = reader.read_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(|reader| {
131129
reader.read_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}()?
132130
}, |reader| {
133-
{{#value}}
134131
{{> deserialize_map_value_nobox}}
135-
{{/value}}
136132
})?;
137133
{{/map}}
138134
{{#enum}}

packages/schema/bind/src/bindings/rust/wasm-rs/templates/serialize_map_value.mustache

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower
1010
writer.write_{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}(value, |writer, key| {
1111
writer.write_{{#key}}{{#toLower}}{{#toMsgPack}}{{toGraphQLType}}{{/toMsgPack}}{{/toLower}}{{/key}}(key)
1212
}, |writer, value| {
13-
{{#value}}
1413
{{> serialize_map_value}}
15-
{{/value}}
1614
})
1715
{{/map}}
1816
{{#enum}}

0 commit comments

Comments
 (0)