furystack-core
Version:
FuryStack framework, Core package
77 lines (54 loc) • 2.33 kB
Markdown
# furystack-core
[](https://greenkeeper.io/)
[](https://travis-ci.org/FuryTechs/furystack-core)
[](https://codecov.io/gh/FuryTechs/furystack-core)
[](https://www.codacy.com/app/gallayl/furystack-core?utm_source=github.com&utm_medium=referral&utm_content=FuryTechs/furystack-core&utm_campaign=Badge_Grade)
FuryStack framework, core package.
Model declaration with _@PrimaryKey_, _@Property_ and _@ForeignKey_ decorators:
``` ts
class RefExample {
@PrimaryKey
public Id;
@Property
public Value: string;
}
class MyModel {
@PrimaryKey
public Id: number;
@Property
public MyPropertyA: string;
@Property
public MyPropertyB: string;
@ForeignKey(RefExample, 'RefExample')
public RefExampleId: number;
public RefExample: RefExample;
}
```
Accessing model metadata via Global ModelDescriptorStore, usage:
``` ts
const descriptor = ModelDescriptorStore.GetDescriptor(MyModel);
/*
descriptor.Object = {constructor: class MyModel { … }}
descriptor.Entries = [
PrimaryKeyDescriptorEntry {PrimaryKey: "Id"}
ODataPropertyDesrciptorEntry {PropertyName: "MyPropertyA", EdmType: 0}
ODataPropertyDesrciptorEntry {PropertyName: "MyPropertyB", EdmType: 0}
ForeignKeyDescriptorEntry {ForeignKeyField: "RefExample", ReferenceName: "RefExample"}
]
descriptor..PrimaryKey = PrimaryKeyDescriptorEntry {PrimaryKey: "Id"}
descriptor.Properties = [
ODataPropertyDesrciptorEntry {PropertyName: "MyPropertyA", EdmType: 0}
ODataPropertyDesrciptorEntry {PropertyName: "MyPropertyB", EdmType: 0}
]
descriptor.ForeignKeys = [
ForeignKeyDescriptorEntry {ForeignKeyField: "RefExample", ReferenceName: "RefExample"}
]
*/
```
Setup and endpoint with the EndpointBuilder class:
``` ts
const builder = new EndpointBuilder('api');
builder.EntityType(MyModel);
builder.EntityType(RefExample);
builder.EntitySet(MyModel, 'mymodels');
```