1.0.7 • Published 3 years ago

@augejs/provider-scanner v1.0.7

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

npm version

https://augejs.github.io/provider-scanner/

provider-scanner is a Provider's metadata scan framework for nodeJs which is base on javascript Reflect.defineMetadata.

Installation

You can get the latest release and the type definitions using npm:

npm install @augejs/provider-scanner reflect-metadata --save

What is a Provider

To be honest, I don't know what a Provider exactly is. Maybe an Entity, a File, a structure, a component, a service, or a string. What ever, it can be defined with kinds of metadata.

The provider-scanner just focus on the scan process with kinds of metadata. Finally the result is what we want.

import { Metadata } from '@augejs/provider-scanner';

const employee = {
  fullName: 'xxxx',
  age: 12,
  headImageUrl: 'xxxx',
};
// here the employee structure consider as a provider

Metadata.defineMetadata(Metadata, 
{
  reporter: 'xxx',
  messageOwner: 'xxx'
}, employee);

// here we add a metadata to the employee structure.

A Provider can store kinds of metadata by using Reflect.defineMetadata. (Also this behavior can be used by Decorator).

provider model

Organize Provider

Let's take a look at below diagram, it a tree of Provider, I think the tree structure is a good idea to organize things, thinking about the user-interface elements, it's a tree structure. thinking about the computer file system, it's a tree structure.

provider tree

If the diagram means a school then the Provider means teachers and students.

If the diagram means a program then the Provider means logic unit.

ParentMetadata

Here is a Parent Metadata which can define the children metadata to Provider

import { ParentMetadata } from '@augejs/provider-scanner';

const employee = {
  fullName: 'xxxx',
  age: 12,
  headImageUrl: 'xxxx',
};
// here the employee structure consider as a provider

const manager = {
  fullName: 'xxxx',
  age: 54,
  headImageUrl: 'xxxx',
};
// here the manager structure consider as a provider

ParentMetadata.defineMetadata( 
[
  employee,
], manager);
// here we add the employee to the manager as this child node.

// we can easily use the `ParentMetadata` to build a tree structure which is composite of `providers` just the above diagram.

HookMetadata

Here is a HookMetadata which can define the metadata hooks to Provider. And the hook will execute in scan process.

hook-metadata

Single Provider Hooks Execute Model

Go back to Provider , Maybe we need do some logic process on Provider maybe process data, create new object, etc. The below diagram show the idea. Each logic process is call a hook, hook can be nested, and all hooks of Provider share the data structure ScanNode which can store some process results for current Provider

provider-hook

The hook execute order is A hook1-pre -> A hook2-pre -> A hook2-after->A hook1-after

The hook idea here is from KOA, it just a middleware in KOA.

async (context: any, next:Function) {
  // some logic before
  await next();
  // some logic after
}

The context here can get the current process ScanNode.

Onion

Maybe this diagram can explain how a middleware works.

Sibling Provider Hooks Execute Model

Provider C is sibling of provide B

sibling-provider-hook

The hook execute order is B hooks -> C hooks

Parent Provider Hooks Execute Model

Provider A is parent of Provider B

parent-provider-hook

The hook execute order is is A hook1-pre -> A hook2-pre -> B hooks -> A hook2-after->A hook1-after

the B hooks seem is inner A

So finally, the scanner go through the provider tree and execute all the hooks around the provide. You can do every thing you want base on provider metadata and hooks to build anything.

scan-execute-order

This is the Provide Tree(above diagram) scan execute order. It's like program function execute process right?

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5-rc.1

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.30

4 years ago

0.0.31

4 years ago

0.0.33

4 years ago

0.0.29

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.15

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.4

4 years ago

0.0.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago