Socket
Socket
Sign inDemoInstall

@compas/code-gen

Package Overview
Dependencies
28
Maintainers
1
Versions
177
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @compas/code-gen

Generate various boring parts of your server


Version published
Weekly downloads
1.4K
increased by86.69%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v0.11.0

Breaking changes
  • feat(eslint-plugin): stricter checks on missing eventStart calls 491561
    • Correctness checks; if event is passed into an async function, you most certainly want to call eventStart.
Features
  • feat(stdlib): make AppError compatible with Sentry 056d40
Bug fixes
  • fix(cli): make sure to load .cjs and .mjs test files ed546c

Readme

Source

@compas/code-gen

Install size CI status badge Codecov status


Code generators for routers, validators, SQL queries, API clients and more. Take a look at the documentation.

As a server

mainFn(import.meta, main);

async function main() {
  const app = new App();

  const T = new TypeCreator("post");
  const R = T.router("/post");

  app.add(
    new TypeCreator("database")
      .object("post")
      .keys({
        title: T.string().searchable(),
        body: T.string(),
      })
      .enableQueries({ withDates: true }),

    T.crud("/post").entity(T.reference("database", "post")).routes({
      listRoute: true,
      singleRoute: true,
      createRoute: true,
      updateRoute: true,
      deleteRoute: true,
    }),
  );

  await app.generate({
    outputDirectory: "./src/generated/application",
    dumpStructure: true,
    dumpApiStructure: true,
    dumpPostgres: true,
    enabledGenerators: ["validator", "router", "sql", "apiClient"],
  });
}

As a client

mainFn(import.meta, main);

async function main() {
  const app = new App({ verbose: true });

  let fromRemote = await loadApiStructureFromRemote(
    Axios,
    "https://some.compas.powered.backend",
  );

  app.extend(fromRemote);

  await app.generate({
    outputDirectory: "./src/generated",
    isBrowser: true,
    enabledGenerators: ["type", "apiClient", "reactQuery"],
  });

  await spawn("yarn", ["format"]);
}

Keywords

FAQs

Last updated on 26 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc