1.0.2 • Published 3 years ago

@drischdaan/registry v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Examples

In these example we are using this basic setup:

class Product {
    constructor(
        public displayName: string,
        public price: number,
        public isAvailable: boolean,
    ) {}
}

const registry: Registry<Product> = new Registry<Product>();

Adding an entry

const uuidTestProduct: string = registry.insert(new Product('TestProduct', 9.99, true));
const uuidTestProduct2: string = registry.insert(new Product('TestProduct2', 9.99, false));

Finding an entry by uuid

const testProduct: Product = registry.findOne({ uuid: uuid });
console.log(testProduct.displayName); // <-- Should return "TestProduct"

Finding an entry by using the "where" find options

const testProduct: Product = registry.findOne({ where: { displayName: 'TestProduct' } });
console.log(testProduct.displayName); // <-- Should return "TestProduct"

Finding multiple entries by using the "where" find options

const products: Product[] = registry.find({ where: { price: 9.99 } });
console.log(products); // <-- Should return an array with all 2 products
console.log(products[1].displayName); // <-- Should return "TestProduct2"

Getting all entries

const products: Product[] = registry.find();
console.log(products); // <-- Should return an array with all 2 products

Getting the uuid of an entry

const uuid: string = registry.findUuid({ where: { displayName: 'TestProduct2' } });
console.log(uuidTestProduct2 === uuid); // <-- Should return true

Deleting an entry

You can either use the "where" option or the "uuid" option to specify which entry should be deleted

const response: boolean = registry.delete({ where: { displayName: 'TestProduct2' } });
console.log(response); // <-- Should return true

Support

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago