Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@r35007/mock-server

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@r35007/mock-server - npm Package Versions

1
11

9.1.0

Diff

Changelog

Source

v9.1.0

  • revoked - mockServer.rewriterwont't setrewriters`. - Now It will set to the global rewriters
  • update - config.host - Set to empty string to set the host as your Local Ip Address.
r35007
published 9.0.1 •

Changelog

Source

v9.0.1

  • If methods passed as a param not working - Fixed.
  • Update - mockServer.default wont't set config.
  • Update - mockServer.rewriter wont't set rewriters.
  • Always use only Setter methods to set any data.
r35007
published 9.0.0 •

Changelog

Source

v9.0.0

  • Renamed - _getDb(), _getStore to getDb(), getStore().
  • Added- Now it automatically picks the index.js file from the given folder path instead of getting all the files from the folder.
  • Added- Now we can give a method as a param to set any config, rewriter, injectors, store, sb etc... For example: db.js
const { MockServer } = require('@r35007/mock-server');
module.exports = (mockServer) => {
  if (mockServer) {
    // This can be undefined If you don't pass the mockServer instance.
  }
  return {
    // Your Db here
    '/post': { id: 1, name: 'foo' },
  };
};

const mockServer = MockServer.Create();
const resources = mockServer.resource(db, { mockServer });
mockServer.app.use(resources);

Note: For now it cant handle async methods.

  • Updated following method params.
// launchServer sets all the resource data. It sets db, injectors, middlewares, store, rewriters, middlewares.
launchServer(db?: ParamTypes.Db, { injectors, middlewares, store, rewriters, router }?: LaunchServerOptions): Promise<Server | undefined>;
// Resources sets only db and it will not set injectors, middlewares or any other options provided. This db will be added to the existing db.
resources(db?: ParamTypes.Db, { injectors, middlewares, mockServer, reverse, rootPath, dbMode, router }?: ResourceOptions): express.Router;

// Setters
setData(data?: SetData, options?: SetterOptions): void;
setConfig(config?: Params.Config, { rootPath, merge, mockServer }?: SetterOptions): void;
setRewriters(rewriters?: Params.Rewriters, { rootPath, merge, mockServer }?: SetterOptions): void;
setMiddlewares(middleware?: Params.Middlewares, { rootPath, merge, mockServer }?: SetterOptions): void;
setInjectors(injectors?: Params.Injectors, { rootPath, merge, mockServer }?: SetterOptions): void;
setStore(store?: Params.Store, { rootPath, merge, mockServer }?: SetterOptions): void;
setDb(db?: Params.Db, { injectors, rootPath, reverse, dbMode, merge, mockServer }?: SetterOptions): void;

// Validators
getValidConfig(config?: ParamTypes.Config | undefined, { rootPath, mockServer }?: SetterOptions): ValidTypes.Config;
getValidMiddlewares(middlewares?: ParamTypes.Middlewares | undefined, { rootPath, mockServer }?: SetterOptions): ValidTypes.Middlewares;
getValidInjectors(injectors?: ParamTypes.Injectors | undefined, { rootPath, mockServer }?: SetterOptions): ValidTypes.Injectors;
getValidStore(store?: ParamTypes.Store | undefined, { rootPath, mockServer }?: SetterOptions): ValidTypes.Store;
getValidRewriters(rewriters?: ParamTypes.Rewriters | undefined, { rootPath, mockServer }?: SetterOptions): ValidTypes.Rewriters;
getValidDb(data?: ParamTypes.Db | undefined, { mockServer, injectors, rootPath, reverse, dbMode }?: SetterOptions): ValidTypes.Db;
r35007
published 8.0.1 •

Changelog

Source

v8.0.1

  • removed unwanted console logs.
r35007
published 8.0.0 •

Changelog

Source

v8.0.0

  • added merge param in all setters. If true it merges the data with the existing. For Example:

    mockServer.setDb({ user:{ id: 1, name: "foo" } });
    mockServer.setDb({ post:{ id: 1, name: "bar" } }); // replaces the previous one
    mockServer.setDb({ comment:{ id: 1, comment: "I am Happy !" } }, true); // adds to the previous one
    
    mockServer.db
    {
      "/post":{_config: true, mock: { id: 1, name:"bar" } }
      "/comment":{_config: true, mock: { id: 1, comment: "I am Happy !" } }
    }
    
  • renamed defaultRoutes to homePage. Now we can use mockServer.homePage which returns the hoePage router.

  • removed - mockServer.router

  • removed - mockServer.addDb instead use mockServer.resource

  • update - mockServer.resources will always return the new router and if repeated it will add the resource to the existing resources. For Example:

    const user = mockServer.resources({ user:{ id: 1, name: "foo" } }); // creates user resource
    mockServer.app.use(user);
    const post = mockServer.resources({ post:{ id: 1, name: "bar" } }); // creates post resource. this resource will be added in db with the existing resources.
    mockServer.app.use(post);
    
    mockServer.db
    {
      "/user":{_config: true, mock: { id: 1, name:"foo" } }
      "/post":{_config: true, mock: { id: 1, name:"bar" } }
    }
    
  • updated config.staticDir - It uses ./public directory as the default static host directory. Set it to empty string to avoid hosting static dir.

r35007
published 7.3.0 •

Changelog

Source

v7.3.0

  • renamed mode to dbMode in config.

  • added multi dbMode in config.

    dbMode :

    • multi - Only direct sting value sets to fetch attribute. All other direct values will be set to - mock attribute.
    • fetch - All other direct values will be set to fetch attribute.
    • mock - All other direct values will be set to mock attribute.
  • Fetch not showing any error on a invalid file path - Fixed

r35007
published 7.2.1 •

Changelog

Source

v7.2.1

  • rewriters not working - Fixed
r35007
published 7.2.0 •

Changelog

Source

v7.2.0

  • added mockServer.port - Gives the current running port. This will be undefined if server is stopped.

  • added mockServer.address - Gives the current running server ip address. This will be undefined if server is stopped.

  • Set Port to 0(zero) to pick a dynamic available port

  • Now we can do default import Example of imports :

    const { MockServer } = require('@r35007/mock-server');
    const MockServer = require('@r35007/mock-server').default;
    
    import MockServer from '@r35007/mock-server';
    import { MockServer } from '@r35007/mock-server';
    
r35007
published 7.1.0 •

Changelog

Source

v7.1.0

  • added cookieParser in config and defaults. Enables the cookie parser. Click here for more details
r35007
published 7.0.1 •

Changelog

Source

v7.0.1

  • toBase64 - method throws error on invalid route - Fixed
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc