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

chore: check that all interfaces are implemented in both sdk #435

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/templates/node/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/typegraph/runtimes/prisma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ pub struct PrismaRuntimeData {
pub struct PrismaOperationMatData {
pub table: String,
pub operation: String,
pub ordered_keys: Option<Vec<String>>,
}
2 changes: 1 addition & 1 deletion typegate/src/runtimes/prisma/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class PrismaRuntime {
stage.props.args?.(p) ?? {},
(v) => v != null,
);
const orderedKeys = (mat.data.ordered_keys ?? []) as Array<string>;
const orderedKeys = (matData.ordered_keys ?? []) as Array<string>;
const parameters = orderedKeys.map((
key,
) => args[key] ?? null);
Expand Down
1 change: 1 addition & 0 deletions typegate/src/types/typegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,5 @@ export interface ModuleMatData {
export interface PrismaOperationMatData {
table: string;
operation: string;
ordered_keys?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ snapshot[`typegraphs creation 6`] = `
"idempotent": true
},
"data": {
"code": "file:scrip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HrP/+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"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }),
Expand Down
14 changes: 10 additions & 4 deletions typegate/tests/runtimes/python_wasi/python_wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 }),
Expand Down
4 changes: 2 additions & 2 deletions typegraph/deno/src/runtimes/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type HttpRequestMat<M extends string> =
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,
Expand Down
21 changes: 14 additions & 7 deletions typegraph/deno/src/runtimes/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ export class PythonRuntime extends Runtime {
constructor() {
super(runtimes.registerPythonRuntime());
}

fromLambda(code: string) {
fromLambda<
P extends Record<string, t.Typedef> = Record<string, t.Typedef>,
I extends t.Struct<P> = t.Struct<P>,
O extends t.Typedef = t.Typedef,
>(inp: I, out: O, { code }: { code: string }) {
const matId = runtimes.fromPythonLambda(
{
runtime: this._id,
Expand All @@ -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<string, t.Typedef> = Record<string, t.Typedef>,
I extends t.Struct<P> = t.Struct<P>,
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}`);
Expand All @@ -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<
Expand Down
9 changes: 9 additions & 0 deletions website/static/specs/0.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,15 @@
},
"operation": {
"type": "string"
},
"ordered_keys": {
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
}
}
}
Expand Down