diff --git a/examples/templates/node/api.ts b/examples/templates/node/api.ts index 37c4c9594..c45a85291 100644 --- a/examples/templates/node/api.ts +++ b/examples/templates/node/api.ts @@ -8,11 +8,11 @@ typegraph("test-multiple-runtimes", (g) => { const python = new PythonRuntime(); g.expose({ - add: t - .func( + add: python + .fromLambda( t.struct({ first: t.float(), second: t.float() }), t.float(), - python.fromLambda("lambda x: x['first'] + x['second']") + { code: "lambda x: x['first'] + x['second']" }, ) .withPolicy(pub), multiply: deno diff --git a/libs/common/src/typegraph/runtimes/prisma.rs b/libs/common/src/typegraph/runtimes/prisma.rs index 2788ace92..c1344317e 100644 --- a/libs/common/src/typegraph/runtimes/prisma.rs +++ b/libs/common/src/typegraph/runtimes/prisma.rs @@ -63,4 +63,5 @@ pub struct PrismaRuntimeData { pub struct PrismaOperationMatData { pub table: String, pub operation: String, + pub ordered_keys: Option>, } diff --git a/typegate/src/runtimes/prisma/prisma.ts b/typegate/src/runtimes/prisma/prisma.ts index 008e318db..275b52a34 100644 --- a/typegate/src/runtimes/prisma/prisma.ts +++ b/typegate/src/runtimes/prisma/prisma.ts @@ -191,7 +191,7 @@ export class PrismaRuntime { stage.props.args?.(p) ?? {}, (v) => v != null, ); - const orderedKeys = (mat.data.ordered_keys ?? []) as Array; + const orderedKeys = (matData.ordered_keys ?? []) as Array; const parameters = orderedKeys.map(( key, ) => args[key] ?? null); diff --git a/typegate/src/types/typegraph.ts b/typegate/src/types/typegraph.ts index 6b0349388..7e03d1d65 100644 --- a/typegate/src/types/typegraph.ts +++ b/typegate/src/types/typegraph.ts @@ -458,4 +458,5 @@ export interface ModuleMatData { export interface PrismaOperationMatData { table: string; operation: string; + ordered_keys?: string[]; } diff --git a/typegate/tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap b/typegate/tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap index f2876afbc..1fbf7be0f 100644 --- a/typegate/tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap +++ b/typegate/tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap @@ -1569,7 +1569,7 @@ snapshot[`typegraphs creation 6`] = ` "idempotent": true }, "data": { - "code": "file:scripts/three.ts;base64:H4sIAAAAAAAA/+0Y7W7bNtC//RSE/lTuFMeSnWDQ1mJdW6wFOiRoMmBAYBi0RDtC9TWKmm0YepO9zV5sd0fqw06WZOgSrJ0PhkUd74tH3vF0QZbksVgPVdF7NBgBnE4m9ATYf47H40nPHU1O3ZE38saId13P9Xqj3hNAWSguGet9Luwv7guB42P2Oss3MlpeK/azUFxtcsHO/vzDYXEUiLQQISvTUEimrgV7G/NCRQH7oKeYNxwN+yDi4vzNr0cGefQ+FKmKFpGQfs1wBIR9JLw8e3PmsxJYoyTPpGIJz/tmuGXnGejcOEzBD8xYSp5fs4otZJYw64cGdQwKsuNCBsdJFsLJtb5rRbyBqY8l6E/EnZxS0xSE2ZPxqlR3q8255EmhufpBlhaKFVkiLtF1L5gaFkqWgbK3fcayVPiA4VLyja2GUarEUkh74ICeJEp9NmYVjlOeAKF1ucosVg0c4FSrDDmzXEVZymNgzmW23tjWhVFlDYCuy9xMgITGsEAH+G228Rm8ROnS12gY2aSZzxZxxhWiaWAbU12HJWWsIpB3tvCZZwzl6UykZYLk+JzZVxas2nKYBUuwpjWNWXpDW7tiyxAjJMd1+uwKtHhTcgrwMbA/XURg4pZ9EhtY5O88LnGFKLXqmtsIrm3eEzs8AcHDk2nDpT3hd3zCSHgrY2BoU1EoEXb3UUQQDtK+6jius6TBdDBoN64jYrYCvpkU4L36wNQeTHgUkwtxYO/t7Ot2E83mNqfSBn7tKUOrQNOR2fUjJCssh+YLEUihCvCFpYcu7pEeeu1wbE01PbgO5GnZjK2iNMxWFyLw2enI2UF+iJII/Oh639b430ohNwbdIOMs4PHbdSAKsOGkxsL+KrFW3aRhQX6QxujKMadAFq0tPI6z1WspiIfHMLOAf+F0p98JDlkLVzvdwUOOu85C8sJPby+t3ckzyIN40q+s5+2MWOdZIW6Rl/D1q6Ugl7jea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GLcgGUa7lVEKwSTMSoyOTUdZN8ORS7Gkl2LjUozWWq0XqfA5OMC90CT0WXMhPkAleE/95536N+q/ycSfHOq/R4DHrP/+b3XexQavguw/SSkUi6n8ujtYX7pNLB015Hip9hL1nSn4U7K4EaBMMDQ7SzCpfC+RswgrF2M3rfAdS+cRa7J5r/ixFrEopdUrf3RNkGeRdbMm0swNoUFsmyyfKCWwDmB99UTJfTKF7+hFC3wytZpU/i+J3Dhzc8sN9EA221slzAHNX6uNUyh4anB3G013T/2F3TtlKOJClsfyWnD+QF2Ae/I/Zv7Jfv73JyfeIf8/Ajxq/sdKXyxYyOGSTtvbrKikyozzAPBbbc4FZTnWvdTDIaUyTNYU/vQ5Beqcqm8eYA7MoQ56wigIt3WgQlp9VQTwHuNWRD/qrzQHl/Ixy1fZc1Uh6g8K1lfes6RWs/hBVIms1UY2Db4mKGOq5R+0/Xdf/PsY7jf6f2OsCQ/x//DwDdZ/pjHGVDusbdl0nTxvp0+mAn+3X6WbYdT+6jfa5jvyWiqH2gQBnEz6tNTg2O/GxVFfiyoosIpT/SnT+LvAV2uvM/QbtUr6oonnE0RTgyIXqhUrdiUqLftNJl3gmm7SzaL2E6rWu8tedTVgs6yjaTC3F7WqrdoVhiU2DedO227YaTV4ftNK2inaGvmmDlTd1k6gcovy5U2pNKck4yaTZ2mP1YbWo1s1KamFHlv4sqFem7ZNta1UH1fZQBeZsUIf9KbixfXdGLUbpthQJgZJlRBiv6b7+qrWAxzgAAc4wOfCP7hZHUUAIAAA" } }, { diff --git a/typegate/tests/e2e/typegraph/typegraphs/deno/multiple_runtimes.ts b/typegate/tests/e2e/typegraph/typegraphs/deno/multiple_runtimes.ts index fc5728a07..78e5a7d9a 100644 --- a/typegate/tests/e2e/typegraph/typegraphs/deno/multiple_runtimes.ts +++ b/typegate/tests/e2e/typegraph/typegraphs/deno/multiple_runtimes.ts @@ -11,10 +11,10 @@ typegraph("test-multiple-runtimes", (g) => { const python = new PythonRuntime(); g.expose({ - add: t.func( + add: python.fromLambda( t.struct({ "first": t.float(), "second": t.float() }), t.float(), - python.fromLambda("lambda x: x['first'] + x['second']"), + { code: "lambda x: x['first'] + x['second']" }, ).withPolicy(pub), multiply: deno.func( t.struct({ "first": t.float(), "second": t.float() }), diff --git a/typegate/tests/runtimes/python_wasi/python_wasi.ts b/typegate/tests/runtimes/python_wasi/python_wasi.ts index 0885099dd..c7da84b3e 100644 --- a/typegate/tests/runtimes/python_wasi/python_wasi.ts +++ b/typegate/tests/runtimes/python_wasi/python_wasi.ts @@ -3,6 +3,7 @@ import { Policy, t, typegraph } from "@typegraph/deno/src/mod.ts"; import { PythonRuntime } from "@typegraph/deno/src/runtimes/python.ts"; +import outdent from "outdent"; const tpe = t.struct({ "a": t.string(), @@ -14,15 +15,20 @@ typegraph("python_wasi", (g) => { const pub = Policy.public(); g.expose({ - identityLambda: t.func( + identityLambda: python.fromLambda( t.struct({ input: tpe }), tpe, - python.fromLambda("lambda x: x['input']"), + { code: "lambda x: x['input']" }, ).withPolicy(pub), - identityDef: t.func( + identityDef: python.fromDef( t.struct({ input: tpe }), tpe, - python.fromDef("def identity(x):\n\treturn x['input']"), + { + code: outdent` + def identity(x): + return x['input'] + `, + }, ).withPolicy(pub), identityMod: python.import( t.struct({ input: tpe }), diff --git a/typegraph/deno/src/runtimes/http.ts b/typegraph/deno/src/runtimes/http.ts index 724eb3b6c..a8537ef2f 100644 --- a/typegraph/deno/src/runtimes/http.ts +++ b/typegraph/deno/src/runtimes/http.ts @@ -21,8 +21,8 @@ type HttpRequestMat = export class HttpRuntime extends Runtime { constructor( public endpoint: string, - public certSecret: string | undefined, - public basicAuthSecret: string | undefined, + public certSecret?: string, + public basicAuthSecret?: string, ) { super(runtimes.registerHttpRuntime({ endpoint, diff --git a/typegraph/deno/src/runtimes/python.ts b/typegraph/deno/src/runtimes/python.ts index f8b08a608..a6ff5de0f 100644 --- a/typegraph/deno/src/runtimes/python.ts +++ b/typegraph/deno/src/runtimes/python.ts @@ -33,8 +33,11 @@ export class PythonRuntime extends Runtime { constructor() { super(runtimes.registerPythonRuntime()); } - - fromLambda(code: string) { + fromLambda< + P extends Record = Record, + I extends t.Struct

= t.Struct

, + O extends t.Typedef = t.Typedef, + >(inp: I, out: O, { code }: { code: string }) { const matId = runtimes.fromPythonLambda( { runtime: this._id, @@ -46,13 +49,17 @@ export class PythonRuntime extends Runtime { }, ); - return { + return t.func(inp, out, { _id: matId, fn: code, - } as LambdaMat; + } as LambdaMat); } - fromDef(code: string) { + fromDef< + P extends Record = Record, + I extends t.Struct

= t.Struct

, + O extends t.Typedef = t.Typedef, + >(inp: I, out: O, { code }: { code: string }) { const name = code.trim().match(/def\s+([A-Za-z0-9_]+)/)?.[1]; if (name == undefined) { throw new Error(`unable to extract def name from source code ${code}`); @@ -69,11 +76,11 @@ export class PythonRuntime extends Runtime { }, ); - return { + return t.func(inp, out, { _id: matId, name, fn: code, - } as DefMat; + } as DefMat); } import< diff --git a/website/static/specs/0.0.2.json b/website/static/specs/0.0.2.json index 1b24dace9..ad3676629 100644 --- a/website/static/specs/0.0.2.json +++ b/website/static/specs/0.0.2.json @@ -2246,6 +2246,15 @@ }, "operation": { "type": "string" + }, + "ordered_keys": { + "type": [ + "array", + "null" + ], + "items": { + "type": "string" + } } } }