Nonchalantly Perusing Magazines

    @api-client/amf-store
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.6 • Public • Published

    AMF service for web apps

    This is a work in progress.

    Published on NPM

    Tests and publishing

    The AMF service for web provides an access to the graph model generated from an API specification and parsed by the AMF parser. This service allows to read and manipulate API meta data. Can be used to render API documentation or to create / edit existing APIs.

    The entire work is performed in a web worker. This is essential especially when parsing APIs to eliminate a possibility of freezing the main thread.

    Status

    • [x] Importing an API from graph model (previously parsed by AMF parser)
    • [x] Creating a new web API
    • [ ] Creating a new Async API
    • [ ] Reading API model (about 70% done)
    • [ ] Manipulating API model (CUD) (about 5% done)
    • [ ] Generating API spec file
    • [ ] Importing API from source
    • [ ] Dom event based access to the meta store

    Usage

    Be aware: this is a work in progress. Everything at this point is a subject to change without prior notification or breaking changes announcements.

    Installation

    npm install --save @api-client/amf-store

    Using the store in a web browser

    To use the store directly in a web browser use the AmfStoreService class. The constructor accepts two argument: the events target (EventTarget instance) and optional configuration for the web worker creation and the AMF bundle location.

    By default the web worker location is expected to be in the workers/AmfWorker.js relative to the library location. You can set any the location by setting the workerLocation on the init object.

    import { AmfStoreService } from '@api-client/amf-store';
    
    const store = new AmfStoreService(window, {
      workerLocation: './node_modules/@api-client/amf-store/workers/AmfWorker.js',
    });

    Mind that the worker imports scripts from the main library so it also requires bundling when used.

    Alternatively, you can set the createWebWorker property on the init object to manually create the worker instance.

    import { AmfStoreService } from '@api-client/amf-store';
    
    const store = new AmfStoreService(window, {
      createWebWorker: () => {
        return new Worker('./node_modules/@api-client/amf-store/workers/AmfWorker.js', {
          type: 'module',
        });
      },
    });

    Finally, the worker imports the AMF bundle located in the root of this library. By default it expects the library to be located at /amf-bundle.js, which is the root of your web server. You can set a custom location by setting the amfLocation property on the init object.

    import { AmfStoreService } from '@api-client/amf-store';
    
    const store = new AmfStoreService(window, {
      amfLocation: '/static/amf-bundle.js',
    });

    Development

    git clone https://github.com/@api-client/amf-store
    cd amf-store
    npm install

    Running the demo locally

    npm start

    Running the tests

    npm test

    License

    API Components by Pawel Psztyc is licensed under CC BY 4.0

    Install

    npm i @api-client/amf-store

    DownloadsWeekly Downloads

    76

    Version

    0.3.6

    License

    cc-by-4.0

    Unpacked Size

    7.34 MB

    Total Files

    77

    Last publish

    Collaborators

    • jarrodek