Socket
Socket
Sign inDemoInstall

@pentops/jsonapi-jdef-ts-generator

Package Overview
Dependencies
26
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pentops/jsonapi-jdef-ts-generator

Generate types from a jdef.json file served by your pentops registry.


Version published
Weekly downloads
37
decreased by-13.95%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

jsonapi-jdef-ts-generator

Generate types and API client functionality from a jdef.json file served by your registry.

Getting Started

Install @pentops/jsonapi-jdef-ts-generator as a dev dependency and @pentops/jsonapi-request as a dependency (if you are going to use the generated API client).

Configuration

Create a .jdef_config.js file in your project root. This file should default export a configuration object:

const EXCLUDED_NAMESPACES = ['service', 'topic'];

export default {
  typeOutput: {
    fileName: 'index.ts',
    directory: './packages/types/generated',
    importPath: '@yourcompany/types',
  },
  clientOutput: {
    fileName: 'index.ts',
    directory: './packages/api-client/generated',
  },
  client: {
    // Remove the excluded namespaces from the method name and camelCase the result
    methodNameWriter: (method) =>
      method.fullGrpcName
        .split(/[./]/)
        .filter((s) => s && !EXCLUDED_NAMESPACES.includes(s.toLowerCase()))
        .map((s, i) => (i === 0 ? s : s[0].toUpperCase() + s.slice(1)))
        .join(''),
  },
  types: {
    enumType: 'enum',
    // Remove the excluded namespaces from the interface/enum name and camelCase the result
    nameWriter: (x) =>
      x
        .split('.')
        .filter((s) => s && !EXCLUDED_NAMESPACES.includes(s.toLowerCase()))
        .map((s) => s?.[0]?.toUpperCase() + s?.slice(1))
        .join(''),
    requestType: 'merged',
  },
  jdefJsonSource: {
    path: 'jdef.json',
  },
};
Source Configuration

You can specify the source of the jdef.json file using the jdefJsonSource property.

  • The path property should be the path to a local jdef.json file.
  • The service property should be set for a remote jdef.json file. It should be an object with the following properties:
    • url: The URL of the remote jdef.json file.
    • auth: An optional object containing a token if required.

See the configuration definitions for more information.

Generating Types

Add a script to your package.json to run the generator.

{
  "scripts": {
    "generate-types": "jdef-ts-generator"
  }
}

Peer Dependencies

You will need to have @pentops/jsonapi-request installed as a dependency if you're going to use the generated API client.

FAQs

Last updated on 09 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