Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Natoandro committed Dec 27, 2024
1 parent 6b68642 commit 3188fe5
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 435 deletions.
168 changes: 84 additions & 84 deletions .ghjk/lock.json

Large diffs are not rendered by default.

292 changes: 18 additions & 274 deletions deno.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env("main")
.vars({
RUST_LOG:
"info,typegate=debug,deno=warn,swc_ecma_codegen=off,tracing::span=off,quaint=off",
TYPEGRAPH_VERSION: "0.0.3",
TYPEGRAPH_VERSION: "0.0.4",
CLICOLOR_FORCE: "1",
CROSS_CONFIG: "tools/Cross.toml",
GIT_CLIFF_CONFIG: "tools/cliff.toml",
Expand Down Expand Up @@ -164,6 +164,7 @@ task("version-bump", async ($) => {
lines: {
"./tools/consts.ts": lines,
},
ignores: [".metatype/**/*"],
});
await $`ghjk x lock-sed`;
});
Expand Down
3 changes: 2 additions & 1 deletion src/typegate/src/typegate/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class ReplicatedRegister extends Register {
);

// typegraph is updated while being pushed, this is only for initial load
const hasUpgrade = initialLoad && isTypegraphUpToDate(tg);
const hasUpgrade = (initialLoad && isTypegraphUpToDate(tg)) || true;
console.log({ hasUpgrade });

const engine = await typegate.initQueryEngine(
hasUpgrade ? upgradeTypegraph(tg) : tg,
Expand Down
38 changes: 37 additions & 1 deletion src/typegate/src/typegraph/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import { TypeGraph, type TypeGraphDS } from "../typegraph/mod.ts";
import { globalConfig } from "../config.ts";
import * as semver from "@std/semver";
import { ObjectNode, Type } from "./type_node.ts";

const typegraphVersion = "0.0.3";
const typegraphVersion = "0.0.4";

const typegraphChangelog: Record<
string,
Expand Down Expand Up @@ -38,10 +39,43 @@ const typegraphChangelog: Record<
return x;
},
},
"0.0.3": {
"next": "0.0.4",
"transform": (x) => {
console.log("types", x.types.length);
for (const typeNode of x.types) {
if (typeNode.type === Type.FUNCTION) {
// build injection tree from the input type
const path: string[] = [];
const input = x.types[typeNode.input];
const traverse = (objectNode: ObjectNode) => {
console.log({ path });
const properties = objectNode.properties;
for (const [name, typeIdx] of Object.entries(properties)) {
path.push(name);
const prop = x.types[typeIdx];
if ("injection" in prop) {
console.log({ injection: prop.injection, path });
throw new Error("injection");
}
if (prop.type === Type.OBJECT) {
traverse(prop);
}
path.pop();
}
};
traverse(input);
typeNode.injections = {};
}
}
return x;
},
},
};

export function isTypegraphUpToDate(typegraph: TypeGraphDS): boolean {
const { meta } = typegraph;
console.log({ typegraphVersion, metaVersion: meta.version });
return semver.equals(
semver.parse(typegraphVersion),
semver.parse(meta.version),
Expand All @@ -53,13 +87,15 @@ export function upgradeTypegraph(typegraph: TypeGraphDS): TypeGraphDS {
const { meta } = typegraph;

let currentVersion = meta.version;
console.log("upgrade", { currentVersion, typegraphVersion });
while (
semver.notEquals(
semver.parse(typegraphVersion),
semver.parse(currentVersion),
)
) {
const migration = typegraphChangelog[currentVersion];
console.log({ migration });
if (!migration) {
throw Error(
`typegate ${globalConfig.version} supports typegraph ${typegraphVersion} which is incompatible with ${typegraphName} ${meta.version} (max auto upgrade was ${currentVersion})`,
Expand Down
2 changes: 1 addition & 1 deletion src/typegraph/core/src/typegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ thread_local! {
static TG: RefCell<Option<TypegraphContext>> = const { RefCell::new(None) };
}

static TYPEGRAPH_VERSION: &str = "0.0.3";
static TYPEGRAPH_VERSION: &str = "0.0.4";

pub fn with_tg<T>(f: impl FnOnce(&TypegraphContext) -> T) -> Result<T> {
TG.with(|tg| {
Expand Down
104 changes: 33 additions & 71 deletions tests/e2e/published/published_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import { transformSyncConfig } from "@metatype/typegate/config.ts";
import { clearSyncData, setupSync } from "test-utils/hooks.ts";
import { assertEquals } from "@std/assert";

const previousVersion = PUBLISHED_VERSION;
// const previousVersion = PUBLISHED_VERSION;
const previousVersion = "0.4.10";

const tempDir = $.path(projectDir).join("tmp");

type Path = typeof tempDir;

function getAssetName(version: string) {
return `meta-cli-v${version}-${Deno.build.target}`;
}
Expand All @@ -45,10 +44,14 @@ const syncConfig = transformSyncConfig({
s3_bucket: syncEnvs.SYNC_S3_BUCKET,
s3_path_style: true,
});
console.log(syncConfig);

// put here typegraphs that are to be excluded
// from the test
const disabled = [] as string[];
// TODO remove after the next release
// The build.rs script now uses a META_CMD env var allowing us
// to use meta-old
const disabled = [
"metagen-rs.ts",
];

async function checkMetaBin(path: typeof tempDir, version: string) {
try {
Expand Down Expand Up @@ -112,40 +115,8 @@ export async function downloadAndExtractCli(version: string) {
return metaBin.toString();
}

type CopyCodeParams = {
branch: string;
destDir: Path;
files: (string | [string, string])[];
};

async function copyCode({ branch, files, destDir: dest }: CopyCodeParams) {
const destDir = $.path(dest);
console.log("copyCode", { branch, files, destDir });
const repoDir = $.path(`.metatype/old/${branch}`);
if (!(await repoDir.exists())) {
await $`git clone https://github.com/metatypedev/metatype.git ${repoDir} --depth 1 --branch ${branch}`
.stdout("inherit")
.stderr("inherit")
.printCommand();
}

await $.co(
files.map((file) => {
const [source, dest] = Array.isArray(file) ? file : [file, file];
// if (dest.endsWith("/")) {
// return $.path(repoDir).join(source).copyToDir(destDir.join(dest), {
// overwrite: true,
// });
// }
return $.path(repoDir).join(source).copy(destDir.join(dest), {
overwrite: true,
});
}),
);
}

// This also tests the published NPM version of the SDK
Meta.test(
Meta.test.only(
{
name: "typegate upgrade",
async setup() {
Expand All @@ -155,10 +126,6 @@ Meta.test(
async teardown() {
await clearSyncData(syncConfig);
},
// FIXME temporarily disabled, will be re-enabled the next related
// PR with a typegraph migration script
// - at `src/typegate/src/typegraph/version.ts`
ignore: true,
},
async (t) => {
let publishedBin = "";
Expand Down Expand Up @@ -192,12 +159,12 @@ Meta.test(
args: ["typegate"],
env: {
...Deno.env.toObject(),
LOG_LEVEL: "DEBUG",
PATH: `${metaBinDir}:${Deno.env.get("PATH")}`,
TG_SECRET: tgSecret,
TG_ADMIN_PASSWORD: "password",
TMP_DIR: typegateTempDir,
TG_PORT: port,
LOG_LEVEL: "DEBUG",
// TODO should not be necessary
VERSION: previousVersion,
...syncEnvs,
Expand All @@ -210,12 +177,16 @@ Meta.test(
async () => {
const tag = `v${previousVersion}`;

await copyCode({
branch: tag,
files: ["examples"],
destDir: examplesDir,
});
// FIXME: cache across test runs
await $`git clone https://github.com/metatypedev/metatype.git --depth 1 --branch ${tag}`
.cwd(repoDir)
.stdout("piped")
.stderr("piped")
.printCommand();

await $.path(repoDir).join("metatype/examples").copy(examplesDir, {
overwrite: true,
});
const typegraphsDir = examplesDir.join("typegraphs");
for await (const entry of typegraphsDir.readDir()) {
const path = typegraphsDir.relative(entry.path);
Expand All @@ -241,7 +212,7 @@ Meta.test(
const stdout = new Lines(proc.stdout);
await stdout.readWhile((line) => {
console.log(`typegate>`, line);
return !line.includes(`typegate ready on :${port}`);
return !line.includes(`typegate ready on ${port}`);
});
stdout.readWhile((line) => {
const match = line.match(/Initializing engine '(.+)'/);
Expand All @@ -254,7 +225,7 @@ Meta.test(

await t.should("successfully deploy on the published version", async () => {
const command =
`meta-old deploy --target dev --threads=4 --allow-dirty --gate http://localhost:${port} -vvv`;
`meta-old deploy --target dev --threads=4 --allow-dirty --gate http://localhost:${port} -vvv -f func.ts`;
const res = await $`bash -c ${command}`
.cwd(examplesDir.join("typegraphs"))
.env("PATH", `${metaBinDir}:${Deno.env.get("PATH")}`);
Expand Down Expand Up @@ -284,7 +255,6 @@ Meta.test(
TG_ADMIN_PASSWORD: "password",
TMP_DIR: typegateTempDir,
TG_PORT: `${port}`,
LOG_LEVEL: "DEBUG",
// TODO should not be necessary
VERSION: previousVersion,
...syncEnvs,
Expand All @@ -309,6 +279,8 @@ Meta.test(
console.log({ status });
});

console.log({ typegraphs: typegraphs.sort() });

await t.should("have the same typegraphs", () => {
assertEquals(typegraphs.sort(), typegraphs2.sort());
});
Expand Down Expand Up @@ -352,7 +324,6 @@ Meta.test(
TG_ADMIN_PASSWORD: "password",
TMP_DIR: typegateTempDir.toString(),
TG_PORT: `${port}`,
LOG_LEVEL: "DEBUG",
// TODO should not be necessary
VERSION: previousVersion,
DEBUG: "true",
Expand All @@ -367,7 +338,7 @@ Meta.test(

await stdout.readWhile((line) => {
console.error("typegate>", line);
return !line.includes(`typegate ready on :${port}`);
return !line.includes(`typegate ready on ${port}`);
});

const tgsDir = $.path(
Expand Down Expand Up @@ -401,16 +372,10 @@ typegraphs:
.cwd(
npmJsrDir,
);
await copyCode({
branch: `v${previousVersion}`,
destDir: npmJsrDir,
files: [
["examples/typegraphs/func.ts", "tg.ts"],
["examples/typegraphs/scripts", "scripts"],
["examples/templates/node/tsconfig.json", "tsconfig.json"],
],
});
await $.co([
$.path("examples/typegraphs/func.ts").copy(npmJsrDir.join("tg.ts")),
$.path("examples/typegraphs/scripts").copyToDir(npmJsrDir),
$.path("examples/templates/node/tsconfig.json").copyToDir(npmJsrDir),
npmJsrDir
.join("package.json")
.readJson()
Expand All @@ -436,20 +401,17 @@ typegraphs:
await $`bash -c 'deno add @typegraph/sdk@${PUBLISHED_VERSION}'`.cwd(
denoJsrDir,
);
await copyCode({
branch: `v${previousVersion}`,
files: [
["examples/typegraphs/func.ts", "tg.ts"],
["examples/typegraphs/scripts", "scripts"],
],
destDir: denoJsrDir,
});
await $.co([
$.path("examples/typegraphs/func.ts").copy(denoJsrDir.join("tg.ts")),
$.path("examples/typegraphs/scripts").copyToDir(denoJsrDir),
]);
const command =
`meta-old deploy --target dev --allow-dirty --gate http://localhost:${port} -vvv -f tg.ts`;
await $`bash -c ${command}`
.cwd(denoJsrDir)
.env("PATH", `${metaBinDir}:${Deno.env.get("PATH")}`)
// FIXME: rename to deno.jsonc on bump 0.4.9
.env("MCLI_LOADER_CMD", `deno run -A --config deno.json`)
.env("RUST_LOG", "trace");
}); */
Expand Down
5 changes: 4 additions & 1 deletion tools/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const RUST_VERSION = "1.80.1";
export const DENO_VERSION = "1.46.3";
export const WASMTIME_VERSION = "25.0.2";
export const WASMTIME_PY_VERSION = "25.0.0";
export const TYPEGRAPH_VERSION = "0.0.3";
export const TYPEGRAPH_VERSION = "0.0.4";
export const PRISMA_VERSION = "5.20.0";
export const SDK_PACKAGE_NAME_TS = "@typegraph/sdk";
export const PYTHON_VERSION = "3.9.19";
Expand Down Expand Up @@ -69,6 +69,9 @@ export const sedLockLines: Record<string, [string | RegExp, string][]> = {
['( TYPEGRAPH_VERSION: ").+(")', TYPEGRAPH_VERSION],
['( GHJK_VERSION: ").+(")', GHJK_VERSION],
],
"ghjk.ts": [
['( TYPEGRAPH_VERSION: ").+(",)', TYPEGRAPH_VERSION],
],
"docs/metatype.dev/docusaurus.config.js": [['( tagline: ").+(",)', TAGLINE]],
"**/pyproject.toml": [
['(version = ").+(")', METATYPE_VERSION],
Expand Down
2 changes: 1 addition & 1 deletion whiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# process will leak in the bg and hog the port

env:
TYPEGRAPH_VERSION: "0.0.3"
TYPEGRAPH_VERSION: "0.0.4"
CLICOLOR_FORCE: "1"
TIMER_MAX_TIMEOUT_MS: "30000"

Expand Down

0 comments on commit 3188fe5

Please sign in to comment.