Skip to content

Commit ef634b9

Browse files
committed
fix: merge conflict
2 parents 410d202 + 0461df1 commit ef634b9

File tree

15 files changed

+136
-57
lines changed

15 files changed

+136
-57
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ steps in advance to help us fix any potential bug as fast as possible.
7373
you might want to check [this section](#i-have-a-question)).
7474
- To see if other users have experienced (and potentially already solved) the
7575
same issue you are having, check if there is not already a bug report existing
76-
for your bug or error in the [bug tracker](https://github.com/metatypedev/metatype/issues?q=label%3Abug).
76+
for your bug or error in the
77+
[bug tracker](https://github.com/metatypedev/metatype/issues?q=label%3Abug).
7778
- Also make sure to search the internet (including Stack Overflow) to see if
7879
users outside the GitHub community have discussed the issue.
7980
- Collect information about the bug:
@@ -230,3 +231,16 @@ rustflags = [
230231
"-C", "link-arg=-fuse-ld=mold"
231232
]
232233
```
234+
235+
#### Local typegraph with Nodejs
236+
237+
Currently, the `typegraph/sdk/node/dist` project is generated dynamically.
238+
Depending on your package manager, the protocol used may differ.
239+
240+
```bash
241+
# uses the `file:..` protocol
242+
npm install path/to/typegraph/sdk/node/dist
243+
244+
# uses the `link:..` protocol (equivalent to `file:..` but for directories only)
245+
pnpm install path/to/typegraph/sdk/node/dist
246+
```

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typegate/engine/bindings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,7 @@ export function archive(a0: ArchiveInp): ArchiveResult {
570570
return { Err: { message: err.toString() } };
571571
}
572572
}
573+
574+
export function transformTypescript(a0: string): string {
575+
return Meta.deno.transformTypescript(a0);
576+
}

typegate/engine/runtime.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,8 @@ declare namespace Meta {
198198
function registerModule(inp: PythonRegisterInp): string;
199199
function unregisterModule(inp: PythonUnregisterInp): string;
200200
}
201+
202+
namespace deno {
203+
function transformTypescript(inp: string): string;
204+
}
201205
}

typegate/engine/runtime.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ globalThis.Meta = {
3838
registerModule: ops.op_register_module,
3939
unregisterModule: ops.op_unregister_module,
4040
},
41+
deno: {
42+
transformTypescript: ops.op_deno_transform_typescript,
43+
},
4144
version: ops.op_get_version,
4245
typescriptFormatCode: ops.op_typescript_format_code,
4346
typegraphValidate: ops.op_typegraph_validate,

typegate/engine/src/ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::interlude::*;
55
use crate::{
6-
runtimes::{prisma, python::python_bindings, temporal, wasmedge},
6+
runtimes::{deno_rt, prisma, python::python_bindings, temporal, wasmedge},
77
typegraph, typescript,
88
};
99

@@ -49,6 +49,7 @@ deno_core::extension!(
4949
prisma::op_prisma_reset,
5050
prisma::op_unpack,
5151
prisma::op_archive,
52+
deno_rt::op_deno_transform_typescript
5253
],
5354
esm_entry_point = "ext:tg_metatype_ext/runtime.js",
5455
esm = ["runtime.js"],

typegate/engine/src/runtimes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
22
// SPDX-License-Identifier: Elastic-2.0
33

4+
pub mod deno_rt;
45
pub mod prisma;
56
pub mod python;
67
pub mod temporal;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(clippy::not_unsafe_ptr_arg_deref)]
2+
3+
// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
4+
// SPDX-License-Identifier: Elastic-2.0
5+
6+
use crate::interlude::*;
7+
8+
#[rustfmt::skip]
9+
use deno_core as deno_core; // necessary for re-exported macros to work
10+
use typescript::parser::transform_script;
11+
12+
#[deno_core::op2]
13+
#[string]
14+
pub fn op_deno_transform_typescript(#[string] script: String) -> Result<String> {
15+
transform_script(script)
16+
}

typegate/src/postprocess.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
2+
// SPDX-License-Identifier: Elastic-2.0
3+
4+
import { transformTypescript, typescript_format_code } from "native";
5+
import { nativeResult } from "./utils.ts";
6+
import { TypeGraphDS } from "./typegraph/mod.ts";
7+
8+
abstract class PostProcessor {
9+
/** Postprocess the provided typegraph reference */
10+
abstract postprocess(tg: TypeGraphDS): void;
11+
}
12+
13+
class DenoPostProcess extends PostProcessor {
14+
postprocess(tg: TypeGraphDS): void {
15+
for (const mat of tg.materializers) {
16+
if (mat.name == "function") {
17+
const jsScript = transformTypescript(mat.data.script as string);
18+
mat.data.script = nativeResult(
19+
typescript_format_code({ source: jsScript }),
20+
)
21+
?.formatted_code!;
22+
}
23+
}
24+
}
25+
}
26+
27+
export function applyPostProcessors(typegraphRefs: TypeGraphDS[]): void {
28+
const postprocesses = [new DenoPostProcess()] as Array<PostProcessor>;
29+
for (const postprocess of postprocesses) {
30+
for (const tgJson of typegraphRefs) {
31+
postprocess.postprocess(tgJson);
32+
}
33+
}
34+
}

typegate/src/runtimes/deno/deno.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export class DenoRuntime extends Runtime {
8383
for (const mat of materializers) {
8484
if (mat.name === "function") {
8585
const code = mat.data.script as string;
86-
8786
ops.set(registryCount, {
8887
type: "register_func",
8988
fnCode: code,

typegate/src/runtimes/typegate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { closestWord } from "../utils.ts";
1414
import { Type, TypeNode } from "../typegraph/type_node.ts";
1515
import { StringFormat } from "../typegraph/types.ts";
1616
import { mapValues } from "std/collections/map_values.ts";
17+
import { applyPostProcessors } from "../postprocess.ts";
1718

1819
const logger = getLogger(import.meta);
1920

@@ -148,6 +149,8 @@ export class TypeGateRuntime extends Runtime {
148149
}
149150

150151
const tgJson = await TypeGraph.parseJson(fromString);
152+
applyPostProcessors([tgJson]);
153+
151154
const { engine, response, name } = await this.typegate.pushTypegraph(
152155
tgJson,
153156
JSON.parse(secrets),

typegate/tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ snapshot[`typegraphs creation 1`] = `
245245
"idempotent": true
246246
},
247247
"data": {
248-
"script": "var _my_lambda=()=>true;"
248+
"script": "var _my_lambda = () => true",
249+
"secrets": []
249250
}
250251
},
251252
{
@@ -489,7 +490,8 @@ snapshot[`typegraphs creation 2`] = `
489490
"idempotent": true
490491
},
491492
"data": {
492-
"script": "var _my_lambda=({first,second})=>first*second;"
493+
"script": "var _my_lambda = ({ first, second }) => first * second",
494+
"secrets": []
493495
}
494496
}
495497
],
@@ -538,7 +540,7 @@ snapshot[`typegraphs creation 2`] = `
538540
`;
539541

540542
snapshot[`typegraphs creation 3`] = `
541-
'[
543+
\`[
542544
{
543545
"\$id": "https://metatype.dev/specs/0.0.3.json",
544546
"types": [
@@ -697,7 +699,8 @@ snapshot[`typegraphs creation 3`] = `
697699
"idempotent": true
698700
},
699701
"data": {
700-
"script": "var _my_lambda=()=>12;"
702+
"script": "var _my_lambda = () => 12",
703+
"secrets": []
701704
}
702705
},
703706
{
@@ -708,7 +711,8 @@ snapshot[`typegraphs creation 3`] = `
708711
"idempotent": true
709712
},
710713
"data": {
711-
"script": "var _my_lambda=(_,{context})=>context.provider===\\\\"internal\\\\";"
714+
"script": "var _my_lambda = (_, { context }) => context.provider === 'internal'",
715+
"secrets": []
712716
}
713717
},
714718
{
@@ -719,7 +723,8 @@ snapshot[`typegraphs creation 3`] = `
719723
"idempotent": true
720724
},
721725
"data": {
722-
"script": "var _my_lambda=user=>({id:12,user});"
726+
"script": "var _my_lambda = (user) => ({ id: 12, user })",
727+
"secrets": []
723728
}
724729
},
725730
{
@@ -730,7 +735,8 @@ snapshot[`typegraphs creation 3`] = `
730735
"idempotent": true
731736
},
732737
"data": {
733-
"script": "var _my_lambda=()=>false;"
738+
"script": "var _my_lambda = () => false",
739+
"secrets": []
734740
}
735741
},
736742
{
@@ -812,7 +818,7 @@ snapshot[`typegraphs creation 3`] = `
812818
"version": "0.0.3"
813819
}
814820
}
815-
]'
821+
]\`
816822
`;
817823

818824
snapshot[`typegraphs creation 4`] = `
@@ -1060,7 +1066,8 @@ snapshot[`typegraphs creation 4`] = `
10601066
"idempotent": true
10611067
},
10621068
"data": {
1063-
"script": "var _my_lambda=()=>true;"
1069+
"script": "var _my_lambda = () => true",
1070+
"secrets": []
10641071
}
10651072
},
10661073
{
@@ -1304,7 +1311,8 @@ snapshot[`typegraphs creation 5`] = `
13041311
"idempotent": true
13051312
},
13061313
"data": {
1307-
"script": "var _my_lambda=({first,second})=>first*second;"
1314+
"script": "var _my_lambda = ({first, second}) => first * second",
1315+
"secrets": []
13081316
}
13091317
}
13101318
],
@@ -1353,7 +1361,7 @@ snapshot[`typegraphs creation 5`] = `
13531361
`;
13541362

13551363
snapshot[`typegraphs creation 6`] = `
1356-
'[
1364+
\`[
13571365
{
13581366
"\$id": "https://metatype.dev/specs/0.0.3.json",
13591367
"types": [
@@ -1512,7 +1520,8 @@ snapshot[`typegraphs creation 6`] = `
15121520
"idempotent": true
15131521
},
15141522
"data": {
1515-
"script": "var _my_lambda=()=>12;"
1523+
"script": "var _my_lambda = () => 12",
1524+
"secrets": []
15161525
}
15171526
},
15181527
{
@@ -1523,7 +1532,8 @@ snapshot[`typegraphs creation 6`] = `
15231532
"idempotent": true
15241533
},
15251534
"data": {
1526-
"script": "var _my_lambda=(_,{context})=>context.provider===\\\\"internal\\\\";"
1535+
"script": "var _my_lambda = (_, { context }) => context.provider === 'internal'",
1536+
"secrets": []
15271537
}
15281538
},
15291539
{
@@ -1534,7 +1544,8 @@ snapshot[`typegraphs creation 6`] = `
15341544
"idempotent": true
15351545
},
15361546
"data": {
1537-
"script": "var _my_lambda=user=>({id:12,user});"
1547+
"script": "var _my_lambda = (user) => ({ id: 12, user })",
1548+
"secrets": []
15381549
}
15391550
},
15401551
{
@@ -1545,7 +1556,8 @@ snapshot[`typegraphs creation 6`] = `
15451556
"idempotent": true
15461557
},
15471558
"data": {
1548-
"script": "var _my_lambda=()=>false;"
1559+
"script": "var _my_lambda = () => false",
1560+
"secrets": []
15491561
}
15501562
},
15511563
{
@@ -1627,5 +1639,5 @@ snapshot[`typegraphs creation 6`] = `
16271639
"version": "0.0.3"
16281640
}
16291641
}
1630-
]'
1642+
]\`
16311643
`;

typegate/tests/e2e/website/website_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ import { Meta } from "../../utils/mod.ts";
99
import { MetaTest } from "../../utils/test.ts";
1010
import { assertEquals } from "std/assert/assert_equals.ts";
1111
import config from "../../../src/config.ts";
12+
import { applyPostProcessors } from "../../../src/postprocess.ts";
13+
import { TypeGraphDS } from "../../../src/typegraph/mod.ts";
1214

1315
export const thisDir = dirname(fromFileUrl(import.meta.url));
1416

1517
function stripIncomparable(json: string) {
1618
return [
1719
// FIXME: python and deno does not produce the same tarball
1820
(source: string) => source.replace(/"file:scripts(.)+?"/g, '""'),
21+
(source: string) => {
22+
const tg: TypeGraphDS = JSON.parse(source)?.[0];
23+
// Required since the typescript format/js convesion Postprocessors are now removed from the cli and sdk
24+
applyPostProcessors([tg]);
25+
return JSON.stringify(tg, null, 2);
26+
},
1927
].reduce((prev, op) => op(prev), json);
2028
}
2129

typegraph/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ wit-bindgen = "0.12.0"
1515
regex = "1.10.2"
1616
indexmap = { version = "2.1.0", features = ["serde"] }
1717
common = { path = "../../libs/common" }
18-
typescript = { path = "../../libs/typescript" }
1918
indoc = "2.0.4"
2019
graphql-parser = "0.4.0"
2120
sha2 = "0.10.8"

0 commit comments

Comments
 (0)