{"version":3,"sources":["../../src/sections/api-reference.ts"],"sourcesContent":["import { DocumentSection } from './section.js';\nimport { heading } from '../elements/heading.js';\n\ninterface Parameter {\n  name: string;\n  type: string;\n  description: string;\n}\n\nexport interface ApiEndpoint {\n  title: string;\n  httpMethod: string;\n  path: string;\n  parameter: Parameter;\n}\n\nexport interface ApiFunction {\n  name: string;\n  parameters: Array<string>;\n  description: string;\n}\n\nconst isObject = (maybeObject: unknown): maybeObject is Object => {\n  return (\n    typeof maybeObject === 'object' &&\n    !Array.isArray(maybeObject) &&\n    maybeObject !== null\n  );\n};\n\nconst isApiEndpoint = (reference: unknown): reference is ApiEndpoint => {\n  return (\n    isObject(reference) &&\n    ['title', 'httpMethod', 'path', 'parameter'].every(\n      (property) => property in reference,\n    )\n  );\n};\n\nconst isApiFunction = (reference: unknown): reference is ApiFunction => {\n  return (\n    isObject(reference) &&\n    ['name', 'parameters', 'description'].every(\n      (property) => property in reference,\n    )\n  );\n};\n\nexport interface ApiReferenceOptions {\n  title?: string;\n  items?: Array<ApiEndpoint | ApiFunction>;\n}\n\nexport class ApiReference extends DocumentSection {\n  private _apiEndpoints: Array<ApiEndpoint>;\n  private _apiFunctions: Array<ApiFunction>;\n\n  constructor({ title, items }: ApiReferenceOptions = {}) {\n    super({ title: title ?? 'API Reference' });\n    this._apiEndpoints = items?.filter(isApiEndpoint) ?? [];\n    this._apiFunctions = items?.filter(isApiFunction) ?? [];\n  }\n\n  public add(reference: ApiEndpoint | ApiFunction) {\n    if (isApiEndpoint(reference)) {\n      this._apiEndpoints.push(reference);\n    } else if (isApiFunction(reference)) {\n      this._apiFunctions.push(reference);\n    } else {\n      throw new Error('Unknown Reference Type');\n    }\n    return this;\n  }\n\n  private mapEndpoint(apiEndpoint: ApiEndpoint): string {\n    return [\n      heading(4, apiEndpoint.title),\n      '',\n      '```http',\n      'GET /api/items',\n      '```',\n      '',\n      '| Parameter | Type     | Description                |',\n      '| :-------- | :------- | :------------------------- |',\n      `|${apiEndpoint.parameter.name} | ${apiEndpoint.parameter.type} | ${apiEndpoint.parameter.description}|`,\n    ].join('\\n');\n  }\n\n  private mapFunction(apiFunction: ApiFunction): string {\n    return [\n      heading(4, `${apiFunction.name}(${apiFunction.parameters.join(', ')})`),\n      '',\n      apiFunction.description,\n    ].join('\\n');\n  }\n\n  protected synthesizeContent(): string[] {\n    const content = [heading(2, this.title)];\n\n    if (this._apiEndpoints.length) {\n      content.push('', this._apiEndpoints.map(this.mapEndpoint).join('\\n\\n'));\n    }\n\n    if (this._apiFunctions.length) {\n      content.push('', this._apiFunctions.map(this.mapFunction).join('\\n\\n'));\n    }\n\n    return content;\n  }\n}\n\nexport function apiReferenceSection(options?: ApiReferenceOptions) {\n  return new ApiReference(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAChC,qBAAwB;AAqBxB,MAAM,WAAW,CAAC,gBAAgD;AAChE,SACE,OAAO,gBAAgB,YACvB,CAAC,MAAM,QAAQ,WAAW,KAC1B,gBAAgB;AAEpB;AAEA,MAAM,gBAAgB,CAAC,cAAiD;AACtE,SACE,SAAS,SAAS,KAClB,CAAC,SAAS,cAAc,QAAQ,WAAW,EAAE;AAAA,IAC3C,CAAC,aAAa,YAAY;AAAA,EAC5B;AAEJ;AAEA,MAAM,gBAAgB,CAAC,cAAiD;AACtE,SACE,SAAS,SAAS,KAClB,CAAC,QAAQ,cAAc,aAAa,EAAE;AAAA,IACpC,CAAC,aAAa,YAAY;AAAA,EAC5B;AAEJ;AAOO,MAAM,qBAAqB,+BAAgB;AAAA,EACxC;AAAA,EACA;AAAA,EAER,YAAY,EAAE,OAAO,MAAM,IAAyB,CAAC,GAAG;AACtD,UAAM,EAAE,OAAO,SAAS,gBAAgB,CAAC;AACzC,SAAK,gBAAgB,OAAO,OAAO,aAAa,KAAK,CAAC;AACtD,SAAK,gBAAgB,OAAO,OAAO,aAAa,KAAK,CAAC;AAAA,EACxD;AA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