dryvPacks

@dryv/ts-api-clientv0.1.5

A framework-free TypeScript API client over fetch, with typed models and one call per operation.

TypeScript API ClientClientsUnitPublished 7 days ago2 downloads

dryv pack add @dryv/ts-api-client
2.9 KBRaw ↗
yaml
version: dryv.pack/v1alpha1
key: unit.clients.ts-api-client
layout: unit
package:
  name: { $ref: "#/inputs/package_name" }
  import_root: src
source: templates

info:
  title: TypeScript API Client
  version: 0.1.5
  description: Generates a framework-free TypeScript client package — models, enums and one typed fetch call per HTTP operation.
  purpose: clients
  summary: A framework-free TypeScript API client over fetch, with typed models and one call per operation.
  languages: [typescript]
  frameworks: [fetch]
  tags: [client, sdk, typescript, react-native, web]

plugins:
  - name: jinja
    extensions: [.j2]

inputs:
  package_name: { type: string, default: admin-console-api }
  package_private: { type: boolean, default: false }

selections:
  enums:
    subject: property.enum
    scope: each

  records:
    subject: property.record
    scope: each

  composites:
    subject: property.composite
    scope: each

  models:
    subject: schema
    scope: each

  operations:
    subject: operation
    filter:
      all: { facet: http }
    scope: each

templates:
  enum:
    $ref: "#/selections/enums"
    output:
      name: $(subject.name.kebab)
      symbol: $(subject.name.pascal)

  record:
    $ref: "#/selections/records"
    output: { name: $(subject.name.kebab), symbol: $(subject.name.pascal) }
    imports:
      - $ref: "#/templates/model"
      - $ref: "#/templates/enum"
      - $ref: "#/templates/record"
      - $ref: "#/templates/composite"

  composite:
    $ref: "#/selections/composites"
    output: { name: $(subject.name.kebab), symbol: $(subject.name.pascal) }
    imports:
      - $ref: "#/templates/model"
      - $ref: "#/templates/enum"
      - $ref: "#/templates/record"
      - $ref: "#/templates/composite"

  model:
    $ref: "#/selections/models"
    output:
      name: $(subject.name.kebab)
      symbol: $(subject.name.pascal)
    imports:
      - $ref: "#/templates/enum"
      - $ref: "#/templates/record"
      - $ref: "#/templates/composite"
      - $ref: "#/templates/model"

  operation:
    $ref: "#/selections/operations"
    output:
      name: $(subject.name.kebab)
      path:
        - $(group.name.kebab)
      symbol: $(subject.name.camel)
    imports:
      - $ref: "#/templates/model"
      - $ref: "#/templates/enum"
      - $ref: "#/templates/record"
      - $ref: "#/templates/composite"

  index:
    exports:
      - $ref: "#/templates/operation"
      - $ref: "#/templates/model"
      - $ref: "#/templates/enum"
      - $ref: "#/templates/record"
      - $ref: "#/templates/composite"

provides:
  operation.client:
    $ref: "#/templates/operation"
  schema.types:
    $ref: "#/templates/model"
  property.enum.types:
    $ref: "#/templates/enum"

# shared:js-package-manager:start
choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }
# shared:js-package-manager:end

actions:
  final:
    install:
      commands:
        - run: [(pnpm|npm|bun|yarn), install]