vuex-orm-decorators
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -6,10 +6,19 @@ import { ORMDatabase } from './database'; | ||
*/ | ||
export function OrmModel(entityName, parentEntity) { | ||
export function OrmModel(entityName, parentEntity, types, typeKey) { | ||
return function (constructor) { | ||
var model = constructor; | ||
// Set the entity name on the model constructor | ||
constructor.entity = entityName; | ||
// Set the parent entity name on the model constructo (if present) | ||
if (parentEntity) { | ||
constructor.baseEntity = parentEntity; | ||
} | ||
// Seup the types and descriminator (if set) | ||
constructor.types = types; | ||
if (types && typeKey) { | ||
constructor.typeKey = typeKey; | ||
} | ||
// Add the fields generated by tha attribute decorators | ||
constructor.fields = function () { return constructor._fields || {}; }; | ||
// Register the entity in the database | ||
ORMDatabase.registerEntity(constructor); | ||
@@ -16,0 +25,0 @@ return constructor; |
@@ -0,1 +1,2 @@ | ||
import { Model } from '@vuex-orm/core'; | ||
/** | ||
@@ -5,2 +6,4 @@ * Creates an vuex-orm Model | ||
*/ | ||
export declare function OrmModel(entityName: string, parentEntity?: string): <Model_1 extends Function>(constructor: Model_1) => void | Model_1; | ||
export declare function OrmModel(entityName: string, parentEntity?: string, types?: { | ||
[key: string]: Model; | ||
}, typeKey?: string): <Model_1 extends Function>(constructor: Model_1) => void | Model_1; |
{ | ||
"name": "vuex-orm-decorators", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Simple Typescript decorators to improve the vuex-orm experience in Typescript by introducing typed property access.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -134,2 +134,6 @@ # vuex-orm-decorators | ||
### Single Table Inheritance | ||
If your model extends a base model, then STI inheritance needs to be used. The base entity name needs to be provided as the second argument to the ORMModel decorator. To use a discriminator field the third and fourth arguments provide the type mapping and property name overrides. | ||
### Generic Types | ||
@@ -136,0 +140,0 @@ |
@@ -8,10 +8,20 @@ import { Model } from '@vuex-orm/core'; | ||
*/ | ||
export function OrmModel(entityName: string, parentEntity?: string) { | ||
export function OrmModel(entityName: string, parentEntity?: string, types?: { [key: string]: Model }, typeKey?: string) { | ||
return function <Model extends Function>(constructor: Model): Model | void { | ||
const model: Function = constructor; | ||
// Set the entity name on the model constructor | ||
(constructor as any).entity = entityName; | ||
// Set the parent entity name on the model constructo (if present) | ||
if (parentEntity) { (constructor as any).baseEntity = parentEntity; } | ||
// Seup the types and descriminator (if set) | ||
(constructor as any).types = types; | ||
if (types && typeKey) { (constructor as any).typeKey = typeKey; } | ||
// Add the fields generated by tha attribute decorators | ||
(constructor as any).fields = () => (constructor as any)._fields || {}; | ||
// Register the entity in the database | ||
ORMDatabase.registerEntity(constructor as unknown as typeof Model); | ||
@@ -18,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34923
426
169