{"version":3,"file":"macro.mjs","sources":["../../src/odata/macro.ts"],"sourcesContent":["/**\n * Utility which provides a stable XML response for OData requests.\n * @module @nhtio/lucid-resourceful/odata/macro\n */\n\nimport { js2xml } from 'xml-js'\nimport { deepmerge } from 'deepmerge-ts'\nimport type { Response } from '@adonisjs/core/http'\nimport type { Element, ElementCompact, Options } from 'xml-js'\n\nexport function odataXmlResponseMacro(\n  this: Response,\n  status: number,\n  payload: Element | ElementCompact,\n  options: Options.JS2XML = {},\n  xmlContentType: string = 'xml'\n) {\n  const opts: Options.JS2XML = deepmerge(\n    {\n      compact: true,\n      spaces: 2,\n      ignoreComment: true,\n    },\n    options\n  )\n  const toStringify = opts.compact\n    ? deepmerge({ _declaration: { _attributes: { version: '1.0', encoding: 'utf-8' } } }, payload)\n    : deepmerge({ declaration: { attributes: { version: '1.0', encoding: 'utf-8' } } }, payload)\n  const stringified = js2xml(toStringify, opts)\n  const contentType = `application/${xmlContentType}; charset=utf-8`\n  this.header('Content-Type', contentType)\n  this.status(status).send(stringified)\n  return this\n}\n"],"names":["js2xml"],"mappings":";;AAUO,SAAS,sBAEd,QACA,SACA,UAA0B,CAAA,GAC1B,iBAAyB,OACzB;AACA,QAAM,OAAuB;AAAA,IAC3B;AAAA,MACE,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,eAAe;AAAA,IAAA;AAAA,IAEjB;AAAA,EAAA;AAEF,QAAM,cAAc,KAAK,UACrB,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,OAAO,UAAU,UAAQ,KAAO,OAAO,IAC3F,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,OAAO,UAAU,UAAQ,EAAE,GAAK,OAAO;AAC7F,QAAM,cAAcA,WAAAA,OAAO,aAAa,IAAI;AAC5C,QAAM,cAAc,eAAe,cAAc;AACjD,OAAK,OAAO,gBAAgB,WAAW;AACvC,OAAK,OAAO,MAAM,EAAE,KAAK,WAAW;AACpC,SAAO;AACT;"}