@contember/schema-definition
Advanced tools
Comparing version 1.2.1 to 1.3.0-alpha.2
import { Role } from './roles'; | ||
import { DecoratorFunction } from '../../model/definition/types'; | ||
import { DecoratorFunction } from '../../utils'; | ||
export declare const allowCustomPrimary: (role?: Role | Role[]) => DecoratorFunction<any>; | ||
//# sourceMappingURL=customPrimary.d.ts.map |
import { Role } from '../roles'; | ||
import { AllowDefinition } from '../permissions'; | ||
export declare const allowCustomPrimaryStore: import("./MetadataStore").MetadataStore<Role<string>[]>; | ||
export declare const allowCustomPrimaryAllRolesStore: import("./MetadataStore").MetadataStore<boolean>; | ||
export declare const allowCustomPrimaryStore: import("../../../utils/MetadataStore").MetadataStore<Role<string>[]>; | ||
export declare const allowCustomPrimaryAllRolesStore: import("../../../utils/MetadataStore").MetadataStore<boolean>; | ||
export declare type EntityPermissionsDefinition = AllowDefinition<any> & { | ||
role: Role<string>; | ||
}; | ||
export declare const allowDefinitionsStore: import("./MetadataStore").MetadataStore<EntityPermissionsDefinition[]>; | ||
export declare const allowDefinitionsStore: import("../../../utils/MetadataStore").MetadataStore<EntityPermissionsDefinition[]>; | ||
//# sourceMappingURL=stores.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.allowDefinitionsStore = exports.allowCustomPrimaryAllRolesStore = exports.allowCustomPrimaryStore = void 0; | ||
const MetadataStore_1 = require("./MetadataStore"); | ||
const MetadataStore_1 = require("../../../utils/MetadataStore"); | ||
exports.allowCustomPrimaryStore = (0, MetadataStore_1.createMetadataStore)([]); | ||
@@ -6,0 +6,0 @@ exports.allowCustomPrimaryAllRolesStore = (0, MetadataStore_1.createMetadataStore)(false); |
@@ -5,3 +5,3 @@ import { Acl } from '@contember/schema'; | ||
import { PredicateEvaluationReference } from './references'; | ||
import { DecoratorFunction } from '../../model/definition/types'; | ||
import { DecoratorFunction } from '../../utils'; | ||
export declare type PredicateExtra = PredicateEvaluationReference | VariableDefinition; | ||
@@ -8,0 +8,0 @@ export declare type WhenDefinition = Acl.PredicateDefinition<PredicateExtra>; |
@@ -7,2 +7,3 @@ import FieldBuilder from './FieldBuilder'; | ||
import ManyHasOneBuilder from './ManyHasOneBuilder'; | ||
import { Model } from '@contember/schema'; | ||
import { AddEntityCallback } from './types'; | ||
@@ -23,2 +24,3 @@ declare class EntityBuilder { | ||
getFields(): FieldBuilder.Map; | ||
orderBy(field: string | string[], direction?: Model.OrderDirection): EntityBuilder; | ||
} | ||
@@ -34,2 +36,3 @@ declare namespace EntityBuilder { | ||
tableName?: string; | ||
orderBy?: Model.OrderBy[]; | ||
unique?: UniqueOptions[]; | ||
@@ -36,0 +39,0 @@ }; |
@@ -54,4 +54,9 @@ "use strict"; | ||
} | ||
orderBy(field, direction = schema_1.Model.OrderDirection.asc) { | ||
var _a; | ||
const path = typeof field === 'string' ? [field] : field; | ||
return new EntityBuilder({ ...this.options, orderBy: [...((_a = this.options.orderBy) !== null && _a !== void 0 ? _a : []), { path, direction }] }, this.fields, this.addEntity); | ||
} | ||
} | ||
exports.default = EntityBuilder; | ||
//# sourceMappingURL=EntityBuilder.js.map |
@@ -42,2 +42,3 @@ "use strict"; | ||
}, | ||
...(options.orderBy !== undefined ? { orderBy: options.orderBy } : {}), | ||
}; | ||
@@ -44,0 +45,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export declare const DisableEventLog: () => import("./types").DecoratorFunction<unknown>; | ||
export declare const DisableEventLog: () => import("../../utils").DecoratorFunction<unknown>; | ||
//# sourceMappingURL=EventLogDefinition.d.ts.map |
import { Model } from '@contember/schema'; | ||
import { DecoratorFunction, EntityConstructor, FieldsDefinition } from './types'; | ||
import { EntityConstructor, FieldsDefinition } from './types'; | ||
import { EntityRegistry, EnumRegistry } from './internal'; | ||
import { NamingConventions } from '@contember/schema-utils'; | ||
import { DecoratorFunction } from '../../utils'; | ||
interface EntityExtensionArgs { | ||
@@ -6,0 +7,0 @@ entity: Model.Entity; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyEntityExtensions = exports.extendEntity = void 0; | ||
const utils_1 = require("../../utils"); | ||
const entityExtensionsStore = (0, utils_1.createMetadataStore)([]); | ||
const extendEntity = (extension) => { | ||
return function (cls) { | ||
const extensions = Reflect.getMetadata('extensions', cls) || []; | ||
Reflect.defineMetadata('extensions', [...extensions, extension], cls); | ||
entityExtensionsStore.update(cls, current => [...current, extension]); | ||
}; | ||
}; | ||
exports.extendEntity = extendEntity; | ||
const applyEntityExtensions = (cls, args) => (Reflect.getMetadata('extensions', cls) || []).reduce((entity, ext) => ext({ ...args, entity }), args.entity); | ||
const applyEntityExtensions = (cls, args) => entityExtensionsStore.get(cls).reduce((entity, ext) => ext({ ...args, entity }), args.entity); | ||
exports.applyEntityExtensions = applyEntityExtensions; | ||
//# sourceMappingURL=extensions.js.map |
@@ -9,2 +9,3 @@ import { Interface } from './types'; | ||
export * from './IndexDefinition'; | ||
export * from './OrderByDefinition'; | ||
export * from './EnumDefinition'; | ||
@@ -11,0 +12,0 @@ export * from './UniqueDefinition'; |
@@ -28,2 +28,3 @@ "use strict"; | ||
__exportStar(require("./IndexDefinition"), exports); | ||
__exportStar(require("./OrderByDefinition"), exports); | ||
__exportStar(require("./EnumDefinition"), exports); | ||
@@ -30,0 +31,0 @@ __exportStar(require("./UniqueDefinition"), exports); |
@@ -1,2 +0,2 @@ | ||
import { DecoratorFunction } from './types'; | ||
import { DecoratorFunction } from '../../utils'; | ||
export declare type IndexOptions<T> = { | ||
@@ -3,0 +3,0 @@ name?: string; |
@@ -1,2 +0,2 @@ | ||
import { EntityConstructor } from '../types'; | ||
import { EntityConstructor } from '../../../utils'; | ||
export declare class EntityRegistry { | ||
@@ -3,0 +3,0 @@ readonly entities: Record<string, EntityConstructor>; |
import { FieldDefinition } from './fieldDefinitions'; | ||
import { EntityConstructor } from '../../utils'; | ||
export declare type Interface<T> = { | ||
@@ -6,7 +7,4 @@ [P in keyof T]: T[P]; | ||
export declare type RelationTarget = EntityConstructor; | ||
export declare type EntityConstructor<T = any> = { | ||
new (): T; | ||
}; | ||
export declare type DecoratorFunction<T> = (cls: EntityConstructor<T>) => void; | ||
export declare type FieldsDefinition = Record<string, Interface<FieldDefinition<any>>>; | ||
export { EntityConstructor }; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { DecoratorFunction } from './types'; | ||
import { DecoratorFunction } from '../../utils'; | ||
export declare type UniqueOptions<T> = { | ||
@@ -3,0 +3,0 @@ name?: string; |
import { EntityConstructor } from './types'; | ||
export declare const View: (sql: string, { dependencies }?: { | ||
dependencies?: EntityConstructor<any>[] | (() => EntityConstructor[]) | undefined; | ||
}) => import("./types").DecoratorFunction<unknown>; | ||
}) => import("../../utils").DecoratorFunction<unknown>; | ||
//# sourceMappingURL=ViewDefinition.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import { EntityConstructor } from '../model/definition/types'; | ||
import { EntityConstructor } from './decorators'; | ||
export declare const filterEntityDefinition: (definitions: Record<string, unknown>) => [string, EntityConstructor][]; | ||
export declare const isEntityConstructor: (it: unknown) => it is EntityConstructor<any>; | ||
//# sourceMappingURL=filterEntityDefinition.d.ts.map |
export * from './assertNever'; | ||
export * from './filterEntityDefinition'; | ||
export * from './tuple'; | ||
export * from './decorators'; | ||
export * from './MetadataStore'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -20,2 +20,4 @@ "use strict"; | ||
__exportStar(require("./tuple"), exports); | ||
__exportStar(require("./decorators"), exports); | ||
__exportStar(require("./MetadataStore"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@contember/schema-definition", | ||
"version": "1.2.1", | ||
"version": "1.3.0-alpha.2", | ||
"license": "Apache-2.0", | ||
@@ -11,4 +11,4 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/schema": "^1.2.1", | ||
"@contember/schema-utils": "^1.2.1", | ||
"@contember/schema": "^1.3.0-alpha.2", | ||
"@contember/schema-utils": "^1.3.0-alpha.2", | ||
"reflect-metadata": "^0.1.13" | ||
@@ -15,0 +15,0 @@ }, |
import { Role } from './roles' | ||
import { allowCustomPrimaryAllRolesStore, allowCustomPrimaryStore } from './internal/stores' | ||
import { DecoratorFunction, EntityConstructor } from '../../model/definition/types' | ||
import { DecoratorFunction, EntityConstructor } from '../../utils' | ||
@@ -5,0 +5,0 @@ export const allowCustomPrimary = (role?: Role | Role[]): DecoratorFunction<any> => { |
@@ -1,2 +0,2 @@ | ||
import { createMetadataStore } from './MetadataStore' | ||
import { createMetadataStore } from '../../../utils/MetadataStore' | ||
import { Role } from '../roles' | ||
@@ -3,0 +3,0 @@ import { AllowDefinition } from '../permissions' |
@@ -6,3 +6,3 @@ import { Acl } from '@contember/schema' | ||
import { allowDefinitionsStore } from './internal/stores' | ||
import { DecoratorFunction, EntityConstructor } from '../../model/definition/types' | ||
import { DecoratorFunction, EntityConstructor } from '../../utils' | ||
@@ -9,0 +9,0 @@ export type PredicateExtra = PredicateEvaluationReference | VariableDefinition |
@@ -92,2 +92,12 @@ import FieldBuilder from './FieldBuilder' | ||
} | ||
orderBy(field: string | string[], direction: Model.OrderDirection = Model.OrderDirection.asc): EntityBuilder { | ||
const path = typeof field === 'string' ? [field] : field | ||
return new EntityBuilder( | ||
{ ...this.options, orderBy: [...(this.options.orderBy ?? []), { path, direction }] }, | ||
this.fields, | ||
this.addEntity, | ||
) | ||
} | ||
} | ||
@@ -106,2 +116,3 @@ | ||
tableName?: string | ||
orderBy?: Model.OrderBy[] | ||
unique?: UniqueOptions[] | ||
@@ -108,0 +119,0 @@ } |
@@ -47,2 +47,3 @@ import { Model, Writable } from '@contember/schema' | ||
}, | ||
...(options.orderBy !== undefined ? { orderBy: options.orderBy } : {}), | ||
} | ||
@@ -49,0 +50,0 @@ } |
import { Model } from '@contember/schema' | ||
import { DecoratorFunction, EntityConstructor, FieldsDefinition } from './types' | ||
import { EntityConstructor, FieldsDefinition } from './types' | ||
import { EntityRegistry, EnumRegistry } from './internal' | ||
import { NamingConventions } from '@contember/schema-utils' | ||
import { createMetadataStore, DecoratorFunction } from '../../utils' | ||
@@ -17,7 +18,8 @@ interface EntityExtensionArgs { | ||
const entityExtensionsStore = createMetadataStore<EntityExtension[]>([]) | ||
export type EntityExtension = (args: EntityExtensionArgs) => Model.Entity | ||
export const extendEntity = <T>(extension: EntityExtension): DecoratorFunction<T> => { | ||
return function (cls: EntityConstructor) { | ||
const extensions = Reflect.getMetadata('extensions', cls) || [] | ||
Reflect.defineMetadata('extensions', [...extensions, extension], cls) | ||
entityExtensionsStore.update(cls, current => [...current, extension]) | ||
} | ||
@@ -30,5 +32,5 @@ } | ||
): Model.Entity => | ||
((Reflect.getMetadata('extensions', cls) || []) as EntityExtension[]).reduce( | ||
entityExtensionsStore.get(cls).reduce( | ||
(entity, ext) => ext({ ...args, entity }), | ||
args.entity, | ||
) |
@@ -1,2 +0,2 @@ | ||
import { EntityConstructor, Interface } from './types' | ||
import { Interface } from './types' | ||
import { Model } from '@contember/schema' | ||
@@ -13,2 +13,3 @@ import { EnumDefinition } from './EnumDefinition' | ||
export * from './IndexDefinition' | ||
export * from './OrderByDefinition' | ||
export * from './EnumDefinition' | ||
@@ -15,0 +16,0 @@ export * from './UniqueDefinition' |
@@ -1,4 +0,4 @@ | ||
import { DecoratorFunction } from './types' | ||
import { extendEntity } from './extensions' | ||
import { NamingHelper } from '@contember/schema-utils' | ||
import { DecoratorFunction } from '../../utils' | ||
@@ -5,0 +5,0 @@ export type IndexOptions<T> = { name?: string; fields: (keyof T)[] } |
@@ -1,2 +0,2 @@ | ||
import { EntityConstructor } from '../types' | ||
import { EntityConstructor } from '../../../utils' | ||
@@ -3,0 +3,0 @@ export class EntityRegistry { |
import { FieldDefinition } from './fieldDefinitions' | ||
import { EntityConstructor } from '../../utils' | ||
export type Interface<T> = { [P in keyof T]: T[P] } | ||
export type RelationTarget = EntityConstructor | ||
export type EntityConstructor<T = any> = { new (): T } | ||
export type DecoratorFunction<T> = (cls: EntityConstructor<T>) => void | ||
export type FieldsDefinition = Record<string, Interface<FieldDefinition<any>>> | ||
export { EntityConstructor } |
@@ -1,4 +0,4 @@ | ||
import { DecoratorFunction } from './types' | ||
import { extendEntity } from './extensions' | ||
import { NamingHelper } from '@contember/schema-utils' | ||
import { DecoratorFunction } from '../../utils' | ||
@@ -5,0 +5,0 @@ export type UniqueOptions<T> = { name?: string; fields: (keyof T)[] } |
@@ -7,9 +7,5 @@ { | ||
"references": [ | ||
{ | ||
"path": "../../schema/src" | ||
}, | ||
{ | ||
"path": "../../schema-utils/src" | ||
} | ||
{ "path": "../../schema/src" }, | ||
{ "path": "../../schema-utils/src" } | ||
] | ||
} |
@@ -1,2 +0,2 @@ | ||
import { EntityConstructor } from '../model/definition/types' | ||
import { EntityConstructor } from './decorators' | ||
@@ -3,0 +3,0 @@ export const filterEntityDefinition = (definitions: Record<string, unknown>): [string, EntityConstructor][] => Object.entries(definitions) |
export * from './assertNever' | ||
export * from './filterEntityDefinition' | ||
export * from './tuple' | ||
export * from './decorators' | ||
export * from './MetadataStore' |
@@ -9,6 +9,4 @@ { | ||
"references": [ | ||
{ | ||
"path": "../src" | ||
} | ||
{ "path": "../src" } | ||
] | ||
} |
@@ -5,3 +5,3 @@ import { Model } from '@contember/schema' | ||
import { extendEntity, FieldDefinition } from '../../src/model/definition' | ||
import { DecoratorFunction } from '../../src/model/definition/types' | ||
import { DecoratorFunction } from '../../src/utils' | ||
@@ -8,0 +8,0 @@ namespace ExtendedModel { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
537730
348
7160
2