Skip to content

Instantly share code, notes, and snippets.

@minenwerfer
Last active February 23, 2024 00:59
Show Gist options
  • Save minenwerfer/bdb640811e6cbc647328364a45f2cbf4 to your computer and use it in GitHub Desktop.
Save minenwerfer/bdb640811e6cbc647328364a45f2cbf4 to your computer and use it in GitHub Desktop.

node_modules/.aeria/package.json

{
  "exports": {
    "collections": {
      "import": "dist/collections/index.mjs",
      "require": "dist/collections/index.js",
      "types": "dist/collections/index.d.ts",
    }
    "collections/pizza": {
      "import": "dist/collections/pizza.mjs",
      "require": "dist/collections/pizza.js",
      "types": "dist/collections/pizza.d.ts",
    }
  }
}

node_modules/.aeria/dist/collections/index.mjs

// precisa incluir a extensão .mjs
export { pizza } from './pizza.mjs'

node_modules/.aeria/dist/collections/pizza.mjs

export const description = {
  $id: 'pizza',
  // ...
}

export const pizza = {
  description,
  functions: {
    get,
    getAll,
    // ...
  }
}

import { defineCollection as originalDefineCollection } from '@sonata-api/api'
export const defineCollection = (collection) => originalDefineCollection(deepMerge(pizza, collection))

node_modules/.aeria/dist/collections/pizza.d.ts

import type { Collection } from '@sonata-api/types'

export type description = {
  $id: 'pizza',
  // ...
}

export type pizza = {
  description: typeof description,
  functions: {
    get: typeof import('@sonata-api/api').get,
    getAll: typeof import('@sonata-api/api').getAll,
    // ...
  }
}

export type defineCollection = <const TCollection extends Collection>(collection: TCollection) =>
  typeof description & TCollection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment