• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmcelhaney / counterfact / 6629231258

24 Oct 2023 03:40PM UTC coverage: 82.644% (-3.5%) from 86.129%
6629231258

Pull #599

github

pmcelhaney
changesets for two new features
Pull Request #599: don't expose moduleLoader

736 of 822 branches covered (0.0%)

Branch coverage included in aggregate %.

311 of 311 new or added lines in 7 files covered. (100.0%)

2383 of 2952 relevant lines covered (80.72%)

36.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/server/app.ts
1
import nodePath from "node:path";
×
2

×
3
import { createHttpTerminator, type HttpTerminator } from "http-terminator";
×
4
import yaml from "js-yaml";
×
5
import $RefParser from "json-schema-ref-parser";
×
6

×
7
import { readFile } from "../util/read-file.js";
×
8
import { CodeGenerator } from "./code-generator.js";
×
9
import type { Config } from "./config.js";
×
10
import { ContextRegistry } from "./context-registry.js";
×
11
import { createKoaApp } from "./create-koa-app.js";
×
12
import { Dispatcher, type OpenApiDocument } from "./dispatcher.js";
×
13
import { koaMiddleware } from "./koa-middleware.js";
×
14
import { ModuleLoader } from "./module-loader.js";
×
15
import { Registry } from "./registry.js";
×
16
import { startRepl } from "./repl.js";
×
17
import { Transpiler } from "./transpiler.js";
×
18

×
19
async function loadOpenApiDocument(source: string) {
×
20
  try {
×
21
    const text = await readFile(source);
×
22
    // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
×
23
    const openApiDocument = (await yaml.load(text)) as $RefParser.JSONSchema;
×
24

×
25
    // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
×
26
    return (await $RefParser.dereference(openApiDocument)) as OpenApiDocument;
×
27
  } catch {
×
28
    return undefined;
×
29
  }
×
30
}
×
31

×
32
// eslint-disable-next-line max-statements
×
33
export async function counterfact(config: Config) {
×
34
  const modulesPath = config.basePath;
×
35

×
36
  const compiledPathsDirectory = nodePath
×
37
    .join(modulesPath, ".cache")
×
38
    .replaceAll("\\", "/");
×
39

×
40
  const registry = new Registry();
×
41

×
42
  const contextRegistry = new ContextRegistry();
×
43

×
44
  const codeGenerator = new CodeGenerator(config.openApiPath, config.basePath);
×
45

×
46
  const dispatcher = new Dispatcher(
×
47
    registry,
×
48
    contextRegistry,
×
49
    await loadOpenApiDocument(config.openApiPath),
×
50
  );
×
51

×
52
  const transpiler = new Transpiler(
×
53
    nodePath.join(modulesPath, "paths").replaceAll("\\", "/"),
×
54
    compiledPathsDirectory,
×
55
  );
×
56

×
57
  const moduleLoader = new ModuleLoader(
×
58
    compiledPathsDirectory,
×
59
    registry,
×
60
    contextRegistry,
×
61
  );
×
62

×
63
  const middleware = koaMiddleware(dispatcher, config);
×
64

×
65
  const koaApp = createKoaApp(registry, middleware, config);
×
66

×
67
  // eslint-disable-next-line max-statements
×
68
  async function start(options: { http?: boolean } = {}) {
×
69
    const http = options.http ?? true;
×
70

×
71
    await codeGenerator.watch();
×
72
    await transpiler.watch();
×
73
    await moduleLoader.load();
×
74
    await moduleLoader.watch();
×
75

×
76
    // eslint-disable-next-line @typescript-eslint/init-declarations
×
77
    let httpTerminator: HttpTerminator | undefined;
×
78

×
79
    if (http) {
×
80
      const server = koaApp.listen({
×
81
        port: config.port,
×
82
      });
×
83

×
84
      httpTerminator = createHttpTerminator({
×
85
        server,
×
86
      });
×
87
    }
×
88

×
89
    const replServer = startRepl(contextRegistry, config);
×
90

×
91
    return {
×
92
      replServer,
×
93

×
94
      async stop() {
×
95
        await codeGenerator.stopWatching();
×
96
        await transpiler.stopWatching();
×
97
        await moduleLoader.stopWatching();
×
98
        await httpTerminator?.terminate();
×
99
      },
×
100
    };
×
101
  }
×
102

×
103
  return {
×
104
    contextRegistry,
×
105
    koaApp,
×
106
    koaMiddleware: middleware,
×
107
    registry,
×
108
    start,
×
109
  };
×
110
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc