New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@boundstate/pluggable-ds

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boundstate/pluggable-ds

Classes, interfaces and utilities for pluggable datasources

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by142.86%
Maintainers
2
Weekly downloads
 
Created
Source

Pluggable Datasource

TypeScript interfaces for an abstract datasource that can be "plugged" with different implementations. Includes classes for a mock datasource that can be used during development and demos.

$ npm install @boundstate/pluggable-ds

Datasource interfaces

Define the interfaces for records, repos, and the datasource that you will be implementing.

person.ts
import { Record, Relation, RepoFindById, RepoPersist, RepoRemoveById } from '@boundstate/pluggable-ds';
import { Address } from './address';

export interface PersonAttributes {
  id: string | null;
  firstName: string;
  lastName: string;
  address: Relation<Address>;
}

export class Person implements Record, PersonAttributes {
  id: string | null;
  firstName: string;
  lastName: string;
  address: Relation<Address>;
}

export interface PersonRepo extends
  RepoFindById<Person>,
  RepoPersist<PersonAttributes, Person>,
  RepoRemoveById<Person> {}
datasource.ts
import { Address } from './address';
import { Person } from './person';

export interface Datasource {
  addresses: AddressRepo;
  people: PersonRepo;
}

Mock implementation

Extend the MockRepo and MockDatasource classes to create a mock implementation of your datasource:

mock-person-repo.ts
import { MockRepo } from '@boundstate/pluggable-ds';
import { PersonAttributes, PersonRepo, Person } from './person';

export class MockPersonRepo extends MockRepo<PersonAttributes, Person, {}, {}> implements PersonRepo {
  constructor() {
    super({ RecordClass: Person });
  }
}
mock-datasource.ts
import { MockDatasource } from '@boundstate/pluggable-ds';
import { Datasource } from './datasource';
import { MockAddressRepo } from './mock-address-repo';
import { MockPersonRepo } from './mock-person-repo';

export class MyMockDatasource extends MockDatasource implements Datasource {
  addresses = this.register('addresses', MockAddressRepo);
  people = this.register('people', MockPersonRepo);
}

FAQs

Package last updated on 22 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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