-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deno/sdk): native function embedding in typescript (#598)
Add support for function or lambda definition typescript sdk for `deno.func` similarly to how `python.from_def` in python sdk works. #### Motivation and context Providing a string is a bit impractical and counter-intuitive espcially when the sdk language matches with runtime's language. #### Migration notes No changes needed. ### Checklist - [x] The change come with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change --------- Signed-off-by: Michaël <[email protected]>
- Loading branch information
1 parent
a13ab9b
commit fffe530
Showing
5 changed files
with
102 additions
and
30 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
import { Policy, t, typegraph } from "@typegraph/sdk/index.js"; | ||
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js"; | ||
|
||
const hello = ({ name }: any) => `Hello ${name}`; | ||
function helloFn({ name }: any) { | ||
return `Hello ${(name as string).toLowerCase()}`; | ||
} | ||
|
||
typegraph("test-deno-tyepscript", (g: any) => { | ||
const deno = new DenoRuntime(); | ||
const pub = Policy.public(); | ||
|
||
g.expose({ | ||
static: deno.static(t.struct({ a: t.string() }), { | ||
a: "Hello World", | ||
}).withPolicy(pub), | ||
hello: deno.func( | ||
t.struct({ name: t.string() }), | ||
t.string(), | ||
{ code: hello }, | ||
).withPolicy(pub), | ||
helloFn: deno.func( | ||
t.struct({ name: t.string() }), | ||
t.string(), | ||
{ code: helloFn }, | ||
).withPolicy(pub), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters