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

feat: injection on output types (outjection) #935

Merged
merged 13 commits into from
Dec 9, 2024
24 changes: 15 additions & 9 deletions .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@
"crateName": "cargo-udeps",
"locked": true,
"specifiedVersion": true
},
"bciqb53vnbgb6fcovjas7p4vhxkqbqicchrmz4g6cz2c2ffj2lqaog3i": {
"version": "v9.15.0",
"buildDepConfigs": {},
"portRef": "pnpm_ghrel@0.1.0",
"specifiedVersion": true
}
}
},
Expand Down Expand Up @@ -772,7 +778,7 @@
"bciqkgncxbauys2qfguplxcz2auxrcyamj4b6htqk2fqvohfm3afd7sa",
"bciqihcmo6l5uwzih3e3ujc55curep4arfomo6rzkdsfim74unxexiqy",
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqojan3zglnfctnmqyxvnxaha46yrnlhj77j3kw4mxadvauqepqdba",
"bciqcnbruy2q6trpvia52n2yis4t27taoz4mxkeguqz5aif7ex6rp26y",
Expand Down Expand Up @@ -808,7 +814,7 @@
"bciqkgncxbauys2qfguplxcz2auxrcyamj4b6htqk2fqvohfm3afd7sa",
"bciqihcmo6l5uwzih3e3ujc55curep4arfomo6rzkdsfim74unxexiqy",
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqojan3zglnfctnmqyxvnxaha46yrnlhj77j3kw4mxadvauqepqdba",
"bciqcnbruy2q6trpvia52n2yis4t27taoz4mxkeguqz5aif7ex6rp26y",
Expand All @@ -820,7 +826,7 @@
"ghjkEnvProvInstSet____ecma": {
"installs": [
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqminqcmgw3fbbhibwc7tf6mrupttheic7kpiykadbowqmnzhmzo5a"
],
Expand Down Expand Up @@ -865,7 +871,7 @@
"ghjkEnvProvInstSet_______task_env_dev-website": {
"installs": [
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqminqcmgw3fbbhibwc7tf6mrupttheic7kpiykadbowqmnzhmzo5a",
"bciqfpjzi6gguk7dafyicfjpzpwtybgyc2dsnxg2zxkcmyinzy7abpla",
Expand All @@ -880,7 +886,7 @@
"bciqlubbahrp4pxohyffmn5yj52atjgmn5nxepmkdev6wtmvpbx7kr7y",
"bciqminqcmgw3fbbhibwc7tf6mrupttheic7kpiykadbowqmnzhmzo5a",
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqfpjzi6gguk7dafyicfjpzpwtybgyc2dsnxg2zxkcmyinzy7abpla",
"bciqkgncxbauys2qfguplxcz2auxrcyamj4b6htqk2fqvohfm3afd7sa",
Expand All @@ -894,7 +900,7 @@
"bciqlubbahrp4pxohyffmn5yj52atjgmn5nxepmkdev6wtmvpbx7kr7y",
"bciqminqcmgw3fbbhibwc7tf6mrupttheic7kpiykadbowqmnzhmzo5a",
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa",
"bciqfpjzi6gguk7dafyicfjpzpwtybgyc2dsnxg2zxkcmyinzy7abpla",
"bciqkgncxbauys2qfguplxcz2auxrcyamj4b6htqk2fqvohfm3afd7sa",
Expand Down Expand Up @@ -939,7 +945,7 @@
"bciqpu7gxs3zm7i4gwp3m3cfdxwz27ixvsykdnbxrl5m5mt3xbb3b4la",
"bciqjme7csfq43oenkrsakdhaha34hgy6vdwkfffki2ank3kf6mjcguq",
"bciqezep4ufkgwesldlm5etyfkgdsiickfudx7cosydcz6xtgeorn2hy",
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y",
"bciqlt27ioikxnpkqq37hma7ibn5e5wpzfarbvoh77zwdkarwghtvzxa"
],
"allowedBuildDeps": "bciqek3tmrhm4iohl6tvdzlhxwhv7b52makvvgehltxv52d3l7rbki3y"
Expand Down Expand Up @@ -2843,8 +2849,8 @@
"moduleSpecifier": "https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/ports/node.ts"
}
},
"bciqaixkkacuuligsvtjcfdfgjgl65owtyspiiljb3vmutlgymecsiwq": {
"version": "v9.4.0",
"bciqlt3rqqcn2tgexcgf7ndjceavwycoddgtn63fkh6z6i6pgmz7jr6y": {
"version": "v9.15.0",
"port": {
"ty": "denoWorker@v1",
"name": "pnpm_ghrel",
Expand Down
25 changes: 25 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (Deno.build.os == "linux" && !Deno.env.has("NO_MOLD")) {

env("_ecma").install(
installs.node,
ports.pnpm({ version: "v9.4.0" }),
ports.pnpm({ version: "v9.15.0" }),
ports.npmi({ packageName: "node-gyp", version: "10.0.1" })[0],
);

Expand Down
3 changes: 2 additions & 1 deletion import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"sentry": "npm:@sentry/node@7.70.0",
"swc": "https://deno.land/x/swc@0.2.1/mod.ts",
"swc/types": "https://esm.sh/@swc/core@1.3.87/types.d.ts?pin=v135",
"validator": "npm:validator@13.12.0"
"validator": "npm:validator@13.12.0",
"@sinonjs/fake-timers": "npm:@sinonjs/fake-timers@13.0.5"
}
}
3 changes: 3 additions & 0 deletions src/common/src/typegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct Queries {
pub struct TypeMeta {
pub prefix: Option<String>,
pub secrets: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub outjection_secrets: Vec<String>,
pub queries: Queries,
pub cors: Cors,
pub auths: Vec<Auth>,
Expand Down
23 changes: 23 additions & 0 deletions src/common/src/typegraph/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,37 @@ pub enum InjectionNode {
},
}

impl InjectionNode {
pub fn collect_secrets_into(&self, collector: &mut Vec<String>) -> Result<()> {
match self {
InjectionNode::Leaf { injection } => {
if let Injection::Secret(d) = injection {
collector.extend(d.values::<String>()?);
}
}
InjectionNode::Parent { children } => {
for child in children.values() {
child.collect_secrets_into(collector)?;
}
}
}
Ok(())
}
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct FunctionTypeData<Id = TypeId> {
pub input: Id,
#[serde(rename = "parameterTransform")]
pub parameter_transform: Option<FunctionParameterTransform>,
pub output: Id,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
#[serde(default)]
pub injections: IndexMap<String, InjectionNode>,
#[serde(skip_serializing_if = "IndexMap::is_empty")]
#[serde(default)]
pub outjections: IndexMap<String, InjectionNode>,
#[serde(rename = "runtimeConfig")]
pub runtime_config: serde_json::Value,
pub materializer: u32,
Expand Down
20 changes: 20 additions & 0 deletions src/common/src/typegraph/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ impl<'a> TypeVisitor<'a> for Validator {
);
path.pop();
}
// TODO validate outjection
// if !data.outjections.is_empty() {
// let outj_cx = InjectionValidationContext {
// fn_path: current_node.path.to_vec(),
// fn_idx: current_node.type_idx,
// input_idx: data.output,
// parent_object,
// validator: context,
// };
// for (k, outj) in data.outjections.iter() {
// path.push(k.clone());
// self.validate_injection(
// &mut path,
// *parent_object.properties.get(k).unwrap(),
// outj,
// &outj_cx,
// );
// path.pop();
// }
// }
} else if let TypeNode::Either { data, .. } = type_node {
let variants = data.one_of.clone();
for i in 0..variants.len() {
Expand Down
2 changes: 1 addition & 1 deletion src/metagen/src/client_rs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::shared::client::*;
use crate::shared::types::NameMemo;
use crate::shared::types::TypeRenderer;
use crate::utils::GenDestBuf;
use normpath::PathExt;
use utils::normalize_type_title;

#[derive(Serialize, Deserialize, Debug, garde::Validate)]
Expand Down Expand Up @@ -436,6 +435,7 @@ pub fn gen_cargo_toml(crate_name: Option<&str>) -> String {

#[cfg(debug_assertions)]
let dependency = if is_test {
use normpath::PathExt;
let client_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../metagen-client-rs")
.normalize()
Expand Down
1 change: 1 addition & 0 deletions src/metagen/src/fdk_rust/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ mod test {
input: 1,
output: 1,
injections: Default::default(),
outjections: Default::default(),
runtime_config: Default::default(),
rate_calls: false,
rate_weight: None,
Expand Down
1 change: 1 addition & 0 deletions src/metagen/src/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn test_typegraph_2() -> Typegraph {
input: 1,
output: 1,
injections: Default::default(),
outjections: Default::default(),
runtime_config: Default::default(),
rate_calls: false,
rate_weight: None,
Expand Down
7 changes: 7 additions & 0 deletions src/typegate/src/engine/injection/dynamic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

export default {
"now": () => new Date().toISOString(),
// "uuid": () =>
} as const;
11 changes: 4 additions & 7 deletions src/typegate/src/engine/planner/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { QueryFunction as JsonPathQuery } from "../../libs/jsonpath.ts";
import { getInjection } from "../../typegraph/utils.ts";
import { GeneratorNode } from "../../runtimes/random.ts";
import DynamicInjection from "../injection/dynamic.ts";

class MandatoryArgumentError extends Error {
constructor(argDetails: string) {
Expand Down Expand Up @@ -104,7 +105,7 @@ export function collectArgs(
stageId,
effect,
parentProps,
injectionTree,
injectionTree ?? {},
);
const argTypeNode = typegraph.type(typeIdx, Type.OBJECT);
for (const argName of Object.keys(astNodes)) {
Expand Down Expand Up @@ -169,11 +170,6 @@ export function collectArgs(
};
}

const GENERATORS = {
"now": () => new Date().toISOString(),
// "uuid": () =>
} as const;

interface Dependencies {
context: Set<string>;
parent: Set<string>;
Expand Down Expand Up @@ -814,7 +810,8 @@ class ArgumentCollector {
if (generatorName == null) {
return null;
}
const generator = GENERATORS[generatorName as keyof typeof GENERATORS];
const generator =
DynamicInjection[generatorName as keyof typeof DynamicInjection];
if (generator == null) {
throw new Error(
`Unknown generator '${generatorName}' for dynamic injection`,
Expand Down
10 changes: 10 additions & 0 deletions src/typegate/src/engine/planner/injection_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@
}
return null;
}

export function getInjectionValues<T = string>(
data: InjectionData,

Check warning on line 21 in src/typegate/src/engine/planner/injection_utils.ts

View check run for this annotation

Codecov / codecov/patch

src/typegate/src/engine/planner/injection_utils.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
): T[] {
if ("value" in data) {
return [data.value as T];
}

Check warning on line 25 in src/typegate/src/engine/planner/injection_utils.ts

View check run for this annotation

Codecov / codecov/patch

src/typegate/src/engine/planner/injection_utils.ts#L23-L25

Added lines #L23 - L25 were not covered by tests

return Object.values(data).filter((v) => typeof v === "string") as T[];
}

Check warning on line 28 in src/typegate/src/engine/planner/injection_utils.ts

View check run for this annotation

Codecov / codecov/patch

src/typegate/src/engine/planner/injection_utils.ts#L27-L28

Added lines #L27 - L28 were not covered by tests
Loading
Loading