Skip to content
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
15 changes: 2 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import * as fs from "javy/fs";

// This package name will be aliased to the file provided by the user.
import * as userFunction from "user-function";
import run from "./run";

export type ShopifyFunction<Input extends {}, Output extends {}> = (
input: Input
) => Output;
Comment on lines -6 to -8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we expect anyone to be using this exported type? If so, I can re-export it.


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 output_obj = userFunction?.default(input_obj);
const output_str = JSON.stringify(output_obj);
const output_data = new TextEncoder().encode(output_str);
fs.writeFileSync(fs.STDIO.Stdout, output_data);
run(userFunction?.default)
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"@graphql-codegen/typescript-operations": "^2.5.5",
"graphql": "^16.6.0",
"typescript": "^4.8.4"
},
"peerDependencies": {
"javy": "^0.1.0"
}
}
15 changes: 15 additions & 0 deletions run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as fs from "javy/fs";

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

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