Skip to content

Commit

Permalink
chore: move ajv & tjs to individual deps.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 6, 2024
1 parent a24eb68 commit e7be9dc
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/artifacts/build_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//
// Generates schema JSON from the module & project config

import { join, tjs } from "../deps.ts";
import { join } from "../deps.ts";
import { tjs } from "./deps.ts";

const dirname = import.meta.dirname;
if (!dirname) throw new Error("Missing dirname");
Expand Down
1 change: 1 addition & 0 deletions src/artifacts/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as glob from "npm:glob@^10.3.10";
export * as tjs from "npm:typescript-json-schema@^0.62.0";
1 change: 1 addition & 0 deletions src/build/deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { crypto } from "https://deno.land/std@0.208.0/crypto/mod.ts";
export { encodeHex } from "https://deno.land/std@0.208.0/encoding/hex.ts";
export * as tjs from "npm:typescript-json-schema@^0.62.0";
30 changes: 19 additions & 11 deletions src/build/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { crypto, encodeHex } from "./deps.ts";
import { assertExists, exists, join } from "../deps.ts";
import { crypto, encodeHex, tjs } from "./deps.ts";
import { compileSchema } from "./schema.ts";
import { generateEntrypoint } from "./entrypoint.ts";
import { generateOpenApi } from "./openapi.ts";
Expand All @@ -12,7 +13,6 @@ import { Project } from "../project/project.ts";
import { generateDenoConfig } from "./deno_config.ts";
import { inflateRuntimeArchive } from "./inflate_runtime_archive.ts";
import { Module, Script } from "../project/mod.ts";
import { assertExists, exists, join, tjs } from "../deps.ts";
import { shutdownAllPools } from "../utils/worker_pool.ts";
import { migrateDev } from "../migrate/dev.ts";

Expand All @@ -31,7 +31,10 @@ export interface BuildCache {
interface BuildCachePersist {
version: number;
fileHashes: Record<string, string>;
scriptSchemas: Record<string, Record<string, { request: tjs.Definition, response: tjs.Definition }>>;
scriptSchemas: Record<
string,
Record<string, { request: tjs.Definition; response: tjs.Definition }>
>;
}

/**
Expand Down Expand Up @@ -160,8 +163,8 @@ export async function build(project: Project) {
newCache: {
version: 1,
fileHashes: {},
scriptSchemas: {}
} as BuildCachePersist
scriptSchemas: {},
} as BuildCachePersist,
} as BuildCache;

// Build state
Expand All @@ -178,7 +181,10 @@ export async function build(project: Project) {
// version: buildState.cache.newCache.version,
// hashCache: Object.assign({} as Record<string, string>, buildState.cache.oldCache, buildState.cache.newCache),
// } as BuildCachePersist;
await Deno.writeTextFile(buildCachePath, JSON.stringify(buildState.cache.newCache));
await Deno.writeTextFile(
buildCachePath,
JSON.stringify(buildState.cache.newCache),
);

console.log("✅ Finished");

Expand Down Expand Up @@ -313,7 +319,8 @@ async function buildScript(
},
async alreadyCached() {
// Read schemas from cache
const schemas = buildState.cache.oldCache.scriptSchemas[module.name][script.name];
const schemas =
buildState.cache.oldCache.scriptSchemas[module.name][script.name];
assertExists(schemas);
script.requestSchema = schemas.request;
script.responseSchema = schemas.response;
Expand All @@ -323,13 +330,14 @@ async function buildScript(
assertExists(script.responseSchema);

// Populate cache with response
if (!buildState.cache.newCache.scriptSchemas[module.name]) buildState.cache.newCache.scriptSchemas[module.name] = {};
if (!buildState.cache.newCache.scriptSchemas[module.name]) {
buildState.cache.newCache.scriptSchemas[module.name] = {};
}
buildState.cache.newCache.scriptSchemas[module.name][script.name] = {
request: script.requestSchema,
response: script.responseSchema,
}

}
};
},
});

buildStep(buildState, {
Expand Down
3 changes: 2 additions & 1 deletion src/build/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, tjs } from "../deps.ts";
import { join } from "../deps.ts";
import { tjs } from "./deps.ts";
import { Project } from "../project/mod.ts";

// deno-lint-ignore no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/build/schema.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// <reference no-default-lib="true" />
/// <reference lib="deno.worker" />

import { tjs } from "../deps.ts";
import { tjs } from "./deps.ts";
import { Script } from "../project/mod.ts";

export interface WorkerRequest {
Expand Down
2 changes: 2 additions & 0 deletions src/config/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Ajv from "npm:ajv@^8.12.0";
export { Ajv };
3 changes: 2 additions & 1 deletion src/config/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Ajv, join, parse } from "../deps.ts";
import { join, parse } from "../deps.ts";
import { Ajv } from "./deps.ts";
import schema from "../../artifacts/module_schema.json" with { type: "json" };

export interface ModuleConfig extends Record<string, unknown> {
Expand Down
3 changes: 2 additions & 1 deletion src/config/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parse, join, Ajv } from "../deps.ts";
import { parse, join } from "../deps.ts";
import { Ajv } from "./deps.ts";
import schema from "../../artifacts/project_schema.json" with { type: "json" };

export interface ProjectConfig extends Record<string, unknown> {
Expand Down
11 changes: 0 additions & 11 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,4 @@ export {
} from "https://deno.land/std@0.208.0/path/mod.ts";
export { copy, exists, emptyDir } from "https://deno.land/std@0.208.0/fs/mod.ts";
export { parse, stringify } from "https://deno.land/std@0.208.0/yaml/mod.ts";

export { assertEquals, assertExists } from "https://deno.land/std@0.208.0/assert/mod.ts";

export { fileURLToPath } from "node:url";

export * as tjs from "npm:typescript-json-schema@^0.62.0";

import Ajv from "npm:ajv@^8.12.0";
export { Ajv };

import addFormats from "npm:ajv-formats@^2.1.1";
export { addFormats };
3 changes: 2 additions & 1 deletion src/project/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as glob from "npm:glob@^10.3.10";
export * as glob from "npm:glob@^10.3.10";
export * as tjs from "npm:typescript-json-schema@^0.62.0";
3 changes: 2 additions & 1 deletion src/project/script.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, tjs } from "../deps.ts";
import { join } from "../deps.ts";
import { tjs } from "./deps.ts";
import { Module } from "./module.ts";
import { ScriptConfig } from "../config/module.ts";
import { Project } from "./project.ts";
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { QueryClient, Transaction } from "https://deno.land/x/postgres@v0.17.2/mod.ts";
export { QueryClient, Transaction } from "https://deno.land/x/postgres@v0.17.2/mod.ts";

import Ajv from "npm:ajv@^8.12.0";
export { Ajv };

import addFormats from "npm:ajv-formats@^2.1.1";
export { addFormats };
2 changes: 1 addition & 1 deletion src/runtime/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ajv, addFormats } from "../deps.ts";
import { Ajv, addFormats } from "./deps.ts";
import { ScriptContext } from "./context.ts";
import { Context, TestContext } from "./context.ts";
import { PrismaClientDummy, Postgres } from "./postgres.ts";
Expand Down

0 comments on commit e7be9dc

Please sign in to comment.