Skip to content

Commit

Permalink
Merge pull request #16 from saulecabrera/javy-json-v1
Browse files Browse the repository at this point in the history
Introduce Javy.JSON builtins
  • Loading branch information
saulecabrera authored Sep 13, 2024
2 parents e8b56e8 + 7a3b36a commit 14b4166
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"access": "public",
"@shopify:registry": "https://registry.npmjs.org/"
},
"version": "0.3.0",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"keywords": [],
Expand All @@ -16,8 +16,5 @@
"@graphql-codegen/typescript-operations": "^2.5.5",
"graphql": "^16.6.0",
"typescript": "^4.8.4"
},
"peerDependencies": {
"javy": "^0.1.0"
}
}
21 changes: 13 additions & 8 deletions run.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import * as fs from "javy/fs";

export type ShopifyFunction<Input extends {}, Output extends {}> = (
input: Input
) => Output;

interface Javy {
JSON: {
fromStdin(): any;
toStdout(val: any);
}
}

declare global {
const Javy: Javy;
}

export default function <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
const input_data = fs.readFileSync(fs.STDIO.Stdin);
const input_str = new TextDecoder("utf-8").decode(input_data);
const input_obj = JSON.parse(input_str);
const input_obj = Javy.JSON.fromStdin();
const output_obj = userfunction(input_obj);
const output_str = JSON.stringify(output_obj);
const output_data = new TextEncoder().encode(output_str);
fs.writeFileSync(fs.STDIO.Stdout, output_data);
Javy.JSON.toStdout(output_obj)
}

0 comments on commit 14b4166

Please sign in to comment.