Skip to content

Commit 14b4166

Browse files
authored
Merge pull request #16 from saulecabrera/javy-json-v1
Introduce Javy.JSON builtins
2 parents e8b56e8 + 7a3b36a commit 14b4166

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

package.json

Lines changed: 1 addition & 4 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.3.0",
7+
"version": "1.0.0",
88
"description": "",
99
"main": "index.ts",
1010
"keywords": [],
@@ -16,8 +16,5 @@
1616
"@graphql-codegen/typescript-operations": "^2.5.5",
1717
"graphql": "^16.6.0",
1818
"typescript": "^4.8.4"
19-
},
20-
"peerDependencies": {
21-
"javy": "^0.1.0"
2219
}
2320
}

run.ts

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

5+
interface Javy {
6+
JSON: {
7+
fromStdin(): any;
8+
toStdout(val: any);
9+
}
10+
}
11+
12+
declare global {
13+
const Javy: Javy;
14+
}
15+
716
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);
17+
const input_obj = Javy.JSON.fromStdin();
1118
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);
19+
Javy.JSON.toStdout(output_obj)
1520
}

0 commit comments

Comments
 (0)