Skip to content

Commit 592a63f

Browse files
committed
Add new Javy JSON builtins
This commit introduces the usage of the the new `Javy.JSON` builtins. Also bumps the version and removes the dependency on the `javy` npm package as nothing from that package is consumed in this version anymore. Opted to introduce the TypeScript definition in this package instead of including a .d.ts file in the `javy` npm package given the reason stated in the previous paragraph.
1 parent 137a790 commit 592a63f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"access": "public",
55
"@shopify:registry": "https://registry.npmjs.org/"
66
},
7-
"version": "0.1.0",
7+
"version": "0.2.0",
88
"description": "",
99
"main": "index.ts",
1010
"keywords": [],
@@ -18,6 +18,5 @@
1818
"typescript": "^4.8.4"
1919
},
2020
"peerDependencies": {
21-
"javy": "^0.1.0"
2221
}
2322
}

run.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
import * as fs from "javy/fs";
2-
31
export type ShopifyFunction<Input extends {}, Output extends {}> = (
42
input: Input
53
) => Output;
64

5+
6+
interface Javy {
7+
JSON: {
8+
fromStdin(): any;
9+
toStdout(val: any);
10+
}
11+
}
12+
13+
declare global {
14+
const Javy: Javy;
15+
}
16+
17+
718
export default function <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
8-
const input_data = fs.readFileSync(fs.STDIO.Stdin);
9-
const input_str = new TextDecoder("utf-8").decode(input_data);
10-
const input_obj = JSON.parse(input_str);
19+
const input_obj = Javy.JSON.fromStdin();
1120
const output_obj = userfunction(input_obj);
12-
const output_str = JSON.stringify(output_obj);
13-
const output_data = new TextEncoder().encode(output_str);
14-
fs.writeFileSync(fs.STDIO.Stdout, output_data);
21+
Javy.JSON.toStdout(output_obj);
1522
}

0 commit comments

Comments
 (0)