{"_id":"@apielements/core","_rev":"6-e467c1a0e0a0e88f0b8a57246d78bd7d","name":"@apielements/core","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"@apielements/core","version":"0.1.0","description":"API Description SDK","author":{"name":"Apiary.io","email":"support@apiary.io"},"license":"MIT","main":"./lib/fury.js","homepage":"https://github.com/apiaryio/api-elements.js/tree/master/packages/core","repository":{"type":"git","url":"git+https://github.com/apiaryio/api-elements.js.git","directory":"packages/core"},"scripts":{"lint":"eslint .","lint:fix":"eslint . --fix","test":"mocha"},"dependencies":{"api-elements":"^0.2.4"},"devDependencies":{"chai":"^4.2.0","eslint":"^5.16.0","mocha":"^7.1.1"},"engines":{"node":">=8"},"gitHead":"ee3b21dd2d8911c32d0a571a529dd6b16b6e73be","bugs":{"url":"https://github.com/apiaryio/api-elements.js/issues"},"_id":"@apielements/core@0.1.0","_nodeVersion":"14.4.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-v/NMQrCkkxpVzEVONZ0ONQLqZfiTQSB8y2up5YqXkqFy078oDHDp7X8olbsGMQ5kXhLGyHNE4B7QfHOUaDGMGA==","shasum":"60426a84e991aef17b4f1177da6a78399cebb916","tarball":"https://registry.npmjs.org/@apielements/core/-/core-0.1.0.tgz","fileCount":5,"unpackedSize":21889,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe45U4CRA9TVsSAnZWagAA2PgP+wUugLelP+topgsGjsEM\nzEhcY0oeQk8Td88HAEKfDtehirmXt3UfM4p3u+VhEtxfkrt/JFD9rEWbVdZJ\nFclvKulFM7ATiCZ5dvN/EAkg7Z764CJh/bjV/cprWDLSyKp4CUTjoZqB9kB/\nPuciyw0pFAVmr4B3OyjlVZ/VANexdT3XrAzg+AOA8dbFon2D6B8PBT/Rekg+\ntSqyqRTXCZSstNllzVGwRb4c/eFm1Ri9gcLA5C7su0iCyA3wLPMEmlB9kCKE\nn0YPbqBRlITpLGv6ocfoM1sYSDXlD/xSmz1w5NKNc4OVzHJlNTREcn4Cfx6U\nPNTIcndhHWD9GrOssuL4dPtSpSp7jVy++FwEFtxeO/YL9bmtPKqxRnUsyuvw\n3hbZH/LCc9ETtVgXLBN6FMVffUr4gTYSR3fXdRtCl2VCHpo3FjNviLMt1d5U\nHro/wNyXCSEZaJQzAPQ4H/I1ZfA0j34ZocQgOqrFsrhabBEwak2X2VexU3gL\nzwZXoGZwtTVfOrnwRtvq2igI4M+GppqOz1hUF89X+xuEhdEytgWArz2Y1Dpl\nIZl5GSegwwyp3wDy8th222ZEzCD7z89MormVlt4PihTIU+5NPwRSn/rORJpf\nUh4Tc46TLbcIIKkmF8Vk9T7QfvkesRKmJjPRJnOxhP66HrAoERjLFvdtCbKq\ncjyD\r\n=ykel\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDeNrQz7cNNqL9BklNHKm2GNR5hKbDZzJFqq9tUPY3mRAiEAhENeXj4//0AHwif5k/h3Opqw6KBWeqwvjq1yooEGOnU="}]},"maintainers":[{"name":"kylef","email":"kyle@fuller.li"}],"_npmUser":{"name":"kylef","email":"kyle@fuller.li"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/core_0.1.0_1591973175979_0.22986778272513386"},"_hasShrinkwrap":false},"0.2.0":{"name":"@apielements/core","version":"0.2.0","description":"API Description SDK","author":{"name":"Apiary.io","email":"support@apiary.io"},"license":"MIT","main":"./lib/fury.js","homepage":"https://github.com/apiaryio/api-elements.js/tree/master/packages/core","repository":{"type":"git","url":"git+https://github.com/apiaryio/api-elements.js.git","directory":"packages/core"},"scripts":{"lint":"eslint .","lint:fix":"eslint . --fix","test":"mocha"},"dependencies":{"api-elements":"^0.3.0"},"devDependencies":{"chai":"^4.2.0","eslint":"^5.16.0","mocha":"^7.1.1"},"engines":{"node":">=8"},"gitHead":"8c8c429fb233f691b4dd64dabc4cc01d765f06ef","bugs":{"url":"https://github.com/apiaryio/api-elements.js/issues"},"_id":"@apielements/core@0.2.0","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.20.2/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-PU39/h32wEmZEwwHgV8Im46lj4xUKklpRkvnhjet6IeiQQ+8F3uWVLiHBVwnpeeytHSlcIe/XTa04Oqw/B6CZQ==","shasum":"44926554ad6e89ac37f56607533b48b7927f09cf","tarball":"https://registry.npmjs.org/@apielements/core/-/core-0.2.0.tgz","fileCount":5,"unpackedSize":22137,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfK/ySCRA9TVsSAnZWagAAW9wP/3pl4EyzxLnyJM6pkkQd\niiAj9vrU4WU5nvHqOfwnriSKWTYsnUEaGQunkW4ZkJYPX6qlCRQ6WrVmDmmG\nBvbWojEgzF+sQhjAE2x4mV8eREoo6XGYInMhqI09sidlEs7CuGAjG6P5U2ri\nriClk8n+xsdOz7owUxWktKGcmiMkdlXM7xHh8lI/fhP9gkaUOlE+7zxfI4cG\nhGdGLJPP/lizL26yowPLau4Xzvs7Bozsq7iPpNuYxTaCWLaeM8FZvDMbkwPE\ncXT9pMsqH0yHnxw4NQsQ1++tNeQxSyJuGpOQ5Wn5WKvrxp7GQy691tXdj0NF\nL89HXym7EtNnpVLvoWrtTLEJCn4s9VDi3PU4rJfF2+xJQ06Sbd12ahunDqej\nnD3Ks+f+y2ewvsoGeoBObaU4DMiRjYGROZifLjSdFM8REpzmtjgjhG5Xk4Kx\nC5ASn9bq5SXA/HyrWtWrtie8K2/bQWTcXcXWZU4QT5EnlrNSkMob8CA4ogx7\nPKXXoRlwKcqDP92Bzion+xIBjgk3nWKvoSH3io1L0TRaJHn+F8DZkYkChV0S\nAxWk3n02oK3C3blM0AwDM9DgNTKGO/8ROkD3SV4mE7sCEZdlftvw+Vp4kBVE\nsf3IZdAQYQT2bJPnMT8lKiYhrTZ33EQLLIDD2lFPITAqjGRsPrhUTZZtMpfO\ntly3\r\n=GQcD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZn4rOXdF4JVZpcjpmJpJOnRTtT7aBZHRGNYLxkIcn8QIgSK2L+NInw5KeiafHt6v3Q/825LOJnjwL80yLVoAN/cc="}]},"maintainers":[{"name":"kylef","email":"kyle@fuller.li"}],"_npmUser":{"name":"kylef","email":"kyle@fuller.li"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/core_0.2.0_1596718226483_0.3197293160718908"},"_hasShrinkwrap":false},"0.2.1":{"name":"@apielements/core","version":"0.2.1","description":"API Description SDK","author":{"name":"Apiary.io","email":"support@apiary.io"},"license":"MIT","main":"./lib/fury.js","homepage":"https://github.com/apiaryio/api-elements.js/tree/master/packages/core","repository":{"type":"git","url":"git+https://github.com/apiaryio/api-elements.js.git","directory":"packages/core"},"scripts":{"lint":"eslint .","lint:fix":"eslint . --fix","test":"mocha"},"dependencies":{"api-elements":"^0.3.0"},"devDependencies":{"chai":"^4.2.0","eslint":"^5.16.0","mocha":"^7.1.1"},"engines":{"node":">=8"},"gitHead":"e2a8c75ea92acfac44000a43782d032f06c16556","bugs":{"url":"https://github.com/apiaryio/api-elements.js/issues"},"_id":"@apielements/core@0.2.1","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-pI7hlAzXmceQjox10n+huOsYkSEunegHVMYl+7cq8WOO107CqGSuv1K8ERnKGQeAT4ZAacDnlo1Py/7WNtU+rQ==","shasum":"faca09f242702ef922fd7d897d6d7fe09deebd45","tarball":"https://registry.npmjs.org/@apielements/core/-/core-0.2.1.tgz","fileCount":5,"unpackedSize":23336,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfT4YMCRA9TVsSAnZWagAApNoP/RK/+dUG4QNrYf3SNC2V\nIjMHfAJYVORJz/ndVS9bBL55w0agZn4DGRBEDoqjiqTNmhYr+8JonjPyruTC\neIsniu+GvPeLAVzJiGEwoVkxLegH05DCh+2KVQWsCzXZdYQDdxLeGmShvF1t\nvPWH7F6SDcBoplN0WfxK4LWD7+EenZSP4PrzHap9Q2YnCEWXa6B4NP8BQPZR\nW5fQYiNIgAAyqel/sBxSTnu97VyxuvlCN3jlr5ZQNLiYN4c+EDF68OioNRja\nREFLy2n9ZPNoXqcdPjE2+eFAZdxQUk1QwosRahDJWNvEptKrkZJPDMThBPLG\nsPitMp2p+O62eBSWhriVsPhVTIGHt1vKndgsiIp/D6hsZBnRY52rLD2iZr3u\nCSYbWMTRTgWQvvvFEgbclEuPS/1TsuK7sIvQCxkMD/xpLRX2mzVpDTjVMXRf\nub0F1ZAddjNzgHn/qBCN+x/SIpY/z3c7fj3xJd1D+uHoNYuuSYBTxiocR21d\nAfcwlhC4EtRIMLBmMt8JNC4cukPwsqb0bxYfzUXf+AALDAyhuSHvCkniXM9B\ni+4qjKd9z+MZYLb0KAwSbxDBlXbW5BLfTg4RtsPiV6hnk/4PemLav7aj/vEV\nEL3npRIP33Pk0oUTyt/c+9D+hzWHFrPHWPNADXdDwMC7l3YMIMmoeeXaV8f9\nDdVe\r\n=Gvr3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDdsFntZmCgOgPs7QJB9aTsp3wvxqoHLHWwa1BI9KYGnQIgCc+O3/NZ0Ihtq8FxdbS2prulneOTkVgepSrelSylyo0="}]},"maintainers":[{"email":"kyle@fuller.li","name":"kylef"},{"email":"patrickx@gmail.com","name":"patrickmedina"}],"_npmUser":{"name":"patrickmedina","email":"patrickx@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/core_0.2.1_1599047180103_0.28151413251170343"},"_hasShrinkwrap":false}},"time":{"created":"2020-06-12T14:46:15.608Z","0.1.0":"2020-06-12T14:46:16.272Z","modified":"2022-06-28T21:36:06.655Z","0.2.0":"2020-08-06T12:50:26.736Z","0.2.1":"2020-09-02T11:46:20.263Z"},"maintainers":[{"email":"kyle@fuller.li","name":"kylef"},{"email":"sre@apiary.io","name":"apiary-sre"}],"description":"API Description SDK","homepage":"https://github.com/apiaryio/api-elements.js/tree/master/packages/core","repository":{"type":"git","url":"git+https://github.com/apiaryio/api-elements.js.git","directory":"packages/core"},"author":{"name":"Apiary.io","email":"support@apiary.io"},"bugs":{"url":"https://github.com/apiaryio/api-elements.js/issues"},"license":"MIT","readme":"# API Elements: Core\n\n[![NPM version](https://img.shields.io/npm/v/@apielements/core.svg)](https://www.npmjs.org/package/@apielements/core)\n[![License](https://img.shields.io/npm/l/@apielements/core.svg)](https://www.npmjs.org/package/@apielements/core)\n\nAPI Description SDK\n\n> _Wardaddy: [Best job I ever had](http://www.imdb.com/title/tt2713180/quotes?item=qt2267083)._\n\nFury provides uniform interface to API description formats such as\n[API Blueprint](https://apiblueprint.org) and [Swagger](http://swagger.io/).\n\nNote: Fury requires *adapters* to support parsing and serializing. You will need to install at least one adapter along with Fury. You can [find Fury adapters](https://www.npmjs.com/search?q=fury-adapter) via npm.\n\n## Usage\n\n### Install\n\nFury.js is available as an npm module.\n\n```sh\n$ npm install --save @apielements/core\n```\n\n### Refract Interface\n\nFury.js offers an interface based on the [Refract Project](https://github.com/refractproject/refract-spec) element specification and makes use of the API description and data structure namespaces. Adapters convert from formats such as API Blueprint into Refract elements and Fury.js exposes these with API-related convenience functionality. For example:\n\n```js\nimport fury from '@apielements/core';\nimport apibParser from '@apielements/apib-parser';\n\n// The input as a string\nconst source = 'FORMAT: 1A\\n# My API\\n...';\n\n// Use the API Blueprint parser adapter\nfury.use(apibParser);\n\n// Parse the input and print 'My API'\nconst parseResult = await fury.parse({ source });\nconsole.log(parseResult.api.title);\n```\n\nOnce you have a parsed API it is easy to traverse:\n\n```js\nparseResult.api.resourceGroups.forEach(function (resourceGroup) {\n  console.log(resourceGroup.title);\n\n  resourceGroup.resources.forEach(function (resource) {\n    console.log(resource.title);\n\n    resource.transitions.forEach(function (transition) {\n      console.log(transition.title);\n\n      transition.transactions.forEach(function (transaction) {\n        const request = transaction.request;\n        const response = transaction.response;\n\n        console.log(`${request.method} ${request.href}`);\n        console.log(`${response.statusCode} (${response.header('Content-Type')})`);\n        console.log(response.messageBody);\n      });\n    });\n  });\n});\n```\n\nIt is also possible to do complex document-wide searching and filtering. For example, to print out a listing of HTTP methods and paths for all defined example requests:\n\n```js\n/*\n * Prints out something like:\n *\n * POST /frobs\n * GET /frobs\n * GET /frobs/{id}\n * PUT /frobs/{id}\n * DELETE /frobs/{id}\n */\nfunction filterFunc(item) {\n  if (item.element === 'httpRequest' && item.statusCode === 200) {\n    return true;\n  }\n\n  return false;\n}\n\nconsole.log('All API request URIs:');\n\napi.find(filterFunc).forEach(function (request) {\n  console.log(`${request.method} ${request.href}`)\n});\n```\n\nReference:\n\n* [Minim](https://github.com/refractproject/minim)\n\n#### Multiple Fury Instances\n\nThere may come a day when you need to have multiple Fury instances with different adapters or other options set up in the same program. This is possible via the `Fury` class:\n\n```js\nimport {Fury} from '@apielements/core';\n\nconst fury1 = new Fury();\nconst fury2 = new Fury();\n\nawait fury1.parse(...);\n```\n\n#### Writing an Adapter\n\nAdapters convert from an input format such as API Blueprint into refract elements. This allows a single, consistent interface to be used to interact with multiple input API description formats. Writing your own adapter allows you to add support for new input formats.\n\nNote about `mediaTypes`: it allows two kinds of definitions. First one is **array** type. It is intended to \"catch all\" implementation.\nIt is useful if your adapter implements only one of fury methods, or if all methods accepts same types of Media Type.\n\nAnother possible option is to use object with mapping name of method to array of MediaTypes. It allows better granularity for detection.\n\nExamples:\n\nIf your adapter support just one method or all methods supports same kind of input Media Type:\n\n```js\nexport const mediaTypes = ['text/vnd.my-adapter'];\n```\n\nIf you need to distinguish among supported input Media Types for methods use:\n\n```js\nexport const mediaTypes = {\n  parse: ['text/vnd.my-parsing', 'text/vnd.another-supported-parsing'],\n  serialize: ['text/vnd.my-serialization'],\n};\n```\n\n\nAdapters are made up of a name, a list of media types, and up to four optional public functions: `detect`, `parse`, `serialize` and `serializeSync`. A simple example might look like this:\n\n```js\nexport const name = 'my-adapter';\nexport const mediaTypes = ['text/vnd.my-adapter'];\n\nexport function detect(source[, method]) {\n  // If no media type is know, then we fall back to auto-detection. Here you\n  // can check the source and see if you think you can parse it.\n  // \n  // optional parmeter `method` give you hint about caller is going to invoke\n  // note that value can be undefined\n  return source.match(/some-test/i) !== null;\n}\n\nexport async function parse({minim, generateSourceMap, mediaType, source}) {\n  // Here you convert the source into refract elements. Use the `minim`\n  // variable to access refract element classes.\n  const Resource = minim.getElementByClass('resource');\n  // ...\n  return elements;\n}\n\nexport async function validate({minim, mediaType, source}) {\n  // Here you validate the source and return a parse result for any warnings or\n  // errors.\n  //\n  // NOTE: Implementing `validate` is optional, Fury will fallback to using\n  // `parse` to find warnings or errors.\n  return null;\n}\n\nexport async function serialize({api, mediaType, minim}) {\n  // Here you convert `api` from javascript element objects to the serialized\n  // source format.\n  // ...\n  return outputString;\n}\n\nexport function serializeSync({api, mediaType, minim}) {\n  // Here you convert `api` from javascript element objects to the serialized\n  // source format.\n  // ...\n  return outputString;\n}\n\nexport default {name, mediaTypes, detect, parse, serialize, serializeSync};\n```\n\nNow you can register your adapter with Fury.js:\n\n```js\nimport fury from '@apielements/core';\nimport myAdapter from './my-adapter';\n\n// Register my custom adapter\nfury.use(myAdapter);\n\n// Now parse my custom input format!\nconst parseResult = await fury.parse({ source: 'some-test\\n...' });\nconsole.log(parseResult.api.title);\n```\n","readmeFilename":"README.md"}