Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Javy.JSON builtins #16

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines -20 to -21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we drop the peer dependency? 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The javy npm dependency is what brings the fs namespace, which is no longer used (fs.{readSync, writeSync}).

}
}
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)
}
Loading