Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contember/schema-definition

Package Overview
Dependencies
Maintainers
5
Versions
258
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/schema-definition - npm Package Compare versions

Comparing version 0.10.0-alpha.5 to 0.10.0-alpha.6

10

dist/src/model/definition/EntityRegistry.d.ts

@@ -1,8 +0,8 @@

import { EntityConstructor, EntityType } from './types';
import { EntityConstructor } from './types';
export declare class EntityRegistry {
readonly entities: Record<string, EntityConstructor<EntityType<any>>>;
register(name: string, definition: EntityConstructor<EntityType<any>>): void;
has(definition: EntityConstructor<EntityType<any>>): boolean;
getName(definition: EntityConstructor<EntityType<any>>): string;
readonly entities: Record<string, EntityConstructor>;
register(name: string, definition: EntityConstructor): void;
has(definition: EntityConstructor): boolean;
getName(definition: EntityConstructor): string;
}
//# sourceMappingURL=EntityRegistry.d.ts.map

@@ -11,3 +11,3 @@ import { Interface } from './types';

import OneHasOneInverseDefinition from './OneHasOneInverseDefinition';
import { EntityConstructor, EntityType } from './types';
import { EntityConstructor } from './types';
import FieldDefinition from './FieldDefinition';

@@ -24,15 +24,12 @@ import 'reflect-metadata';

export declare function enumColumn(enumDefinition: EnumDefinition): ColumnDefinition<Model.ColumnType>;
declare type KeysOfType<T, TProp> = {
[P in keyof T]: T[P] extends TProp ? P : never;
}[keyof T];
export declare function manyHasOne<T extends EntityType<T>>(target: EntityConstructor<T>, inversedBy?: KeysOfType<T, Interface<OneHasManyDefinition>> & string): ManyHasOneDefinition;
export declare function oneHasMany<T extends EntityType<T>>(target: EntityConstructor<T>, ownedBy: KeysOfType<T, Interface<ManyHasOneDefinition>> & string): OneHasManyDefinition;
export declare function manyHasMany<T extends EntityType<T>>(target: EntityConstructor<T>, inversedBy?: KeysOfType<T, Interface<ManyHasManyInverseDefinition>> & string): ManyHasManyDefinition;
export declare function manyHasManyInverse<T extends EntityType<T>>(target: EntityConstructor<T>, ownedBy: KeysOfType<T, Interface<ManyHasManyDefinition>> & string): ManyHasManyInverseDefinition;
export declare function manyHasOne(target: EntityConstructor, inversedBy?: string): ManyHasOneDefinition;
export declare function oneHasMany(target: EntityConstructor, ownedBy: string): OneHasManyDefinition;
export declare function manyHasMany(target: EntityConstructor, inversedBy?: string): ManyHasManyDefinition;
export declare function manyHasManyInverse(target: EntityConstructor, ownedBy: string): ManyHasManyInverseDefinition;
/** @deprecated use manyHasManyInverse */
export declare function manyHasManyInversed<T extends EntityType<T>>(target: EntityConstructor<T>, ownedBy: KeysOfType<T, Interface<ManyHasManyDefinition>> & string): ManyHasManyInverseDefinition;
export declare function oneHasOne<T extends EntityType<T>>(target: EntityConstructor<T>, inversedBy?: KeysOfType<T, Interface<OneHasOneInverseDefinition>> & string): OneHasOneDefinition;
export declare function oneHasOneInverse<T extends EntityType<T>>(target: EntityConstructor<T>, ownedBy: KeysOfType<T, Interface<OneHasOneDefinition>> & string): OneHasOneInverseDefinition;
export declare function manyHasManyInversed(target: EntityConstructor, ownedBy: string): ManyHasManyInverseDefinition;
export declare function oneHasOne(target: EntityConstructor, inversedBy?: string): OneHasOneDefinition;
export declare function oneHasOneInverse(target: EntityConstructor, ownedBy: string): OneHasOneInverseDefinition;
/** @deprecated use oneHasOneInverse */
export declare function oneHasOneInversed<T extends EntityType<T>>(target: EntityConstructor<T>, ownedBy: KeysOfType<T, Interface<OneHasOneDefinition>> & string): OneHasOneInverseDefinition;
export declare function oneHasOneInversed(target: EntityConstructor, ownedBy: string): OneHasOneInverseDefinition;
export declare function createEnum(...values: string[]): EnumDefinition;

@@ -43,5 +40,5 @@ declare type UniqueOptions<T> = {

};
declare type DecoratorFunction<T extends EntityType<T>> = (cls: EntityConstructor<T>) => void;
export declare function Unique<T extends EntityType<T>>(options: UniqueOptions<T>): DecoratorFunction<T>;
export declare function Unique<T extends EntityType<T>>(...fields: (keyof T)[]): DecoratorFunction<T>;
declare type DecoratorFunction<T> = (cls: EntityConstructor<T>) => void;
export declare function Unique<T>(options: UniqueOptions<T>): DecoratorFunction<T>;
export declare function Unique<T>(...fields: (keyof T)[]): DecoratorFunction<T>;
export declare abstract class Entity {

@@ -51,5 +48,3 @@ [key: string]: Interface<FieldDefinition<any>> | undefined;

export declare type ModelDefinition<M> = {
[K in keyof M]: EnumDefinition | EntityConstructor<EntityType<M[K] extends {
new (): any;
} ? InstanceType<M[K]> : never>>;
[K in keyof M]: EnumDefinition | EntityConstructor;
};

@@ -56,0 +51,0 @@ export declare function createModel<M extends ModelDefinition<M>>(definitions: M): Model.Schema;

import { Model } from '@contember/schema';
import { EntityConstructor } from './types';
import NamingConventions from './NamingConventions';
import { EntityConstructor } from './types';
import EnumDefinition from './EnumDefinition';

@@ -11,3 +11,3 @@ import 'reflect-metadata';

constructor(conventions: NamingConventions);
addEntity(name: string, entity: EntityConstructor<any>): void;
addEntity(name: string, entity: EntityConstructor): void;
addEnum(name: string, definition: EnumDefinition): void;

@@ -14,0 +14,0 @@ createSchema(): Model.Schema;

@@ -1,12 +0,8 @@

import FieldDefinition from './FieldDefinition';
export declare type Interface<T> = {
[P in keyof T]: T[P];
};
export declare type RelationTarget = EntityConstructor<EntityType<any>>;
export declare type EntityType<T> = {
[K in keyof T]: Interface<FieldDefinition<any>>;
};
export declare type EntityConstructor<T> = {
export declare type RelationTarget = EntityConstructor;
export declare type EntityConstructor<T = any> = {
new (): T;
};
//# sourceMappingURL=types.d.ts.map
{
"name": "@contember/schema-definition",
"version": "0.10.0-alpha.5",
"version": "0.10.0-alpha.6",
"license": "Apache-2.0",

@@ -11,4 +11,4 @@ "main": "dist/src/index.js",

"dependencies": {
"@contember/schema": "^0.10.0-alpha.5",
"@contember/schema-utils": "^0.10.0-alpha.5",
"@contember/schema": "^0.10.0-alpha.6",
"@contember/schema-utils": "^0.10.0-alpha.6",
"reflect-metadata": "^0.1.13"

@@ -15,0 +15,0 @@ },

@@ -1,7 +0,7 @@

import { EntityConstructor, EntityType } from './types'
import { EntityConstructor } from './types'
export class EntityRegistry {
public readonly entities: Record<string, EntityConstructor<EntityType<any>>> = {}
public readonly entities: Record<string, EntityConstructor> = {}
register(name: string, definition: EntityConstructor<EntityType<any>>) {
register(name: string, definition: EntityConstructor) {
if (this.entities[name]) {

@@ -13,7 +13,7 @@ throw new Error(`Entity with name ${name} is already registered`)

has(definition: EntityConstructor<EntityType<any>>): boolean {
has(definition: EntityConstructor): boolean {
return Object.values(this.entities).includes(definition)
}
getName(definition: EntityConstructor<EntityType<any>>): string {
getName(definition: EntityConstructor): string {
for (const [name, def] of Object.entries(this.entities)) {

@@ -20,0 +20,0 @@ if (def === definition) {

@@ -11,3 +11,3 @@ import { Interface } from './types'

import OneHasOneInverseDefinition from './OneHasOneInverseDefinition'
import { EntityConstructor, EntityType } from './types'
import { EntityConstructor } from './types'
import SchemaBuilder from './SchemaBuilder'

@@ -51,29 +51,15 @@ import NamingConventions from './NamingConventions'

type KeysOfType<T, TProp> = { [P in keyof T]: T[P] extends TProp ? P : never }[keyof T]
export function manyHasOne<T extends EntityType<T>>(
target: EntityConstructor<T>,
inversedBy?: KeysOfType<T, Interface<OneHasManyDefinition>> & string,
): ManyHasOneDefinition {
export function manyHasOne(target: EntityConstructor, inversedBy?: string): ManyHasOneDefinition {
return new ManyHasOneDefinition({ target, inversedBy })
}
export function oneHasMany<T extends EntityType<T>>(
target: EntityConstructor<T>,
ownedBy: KeysOfType<T, Interface<ManyHasOneDefinition>> & string,
): OneHasManyDefinition {
export function oneHasMany(target: EntityConstructor, ownedBy: string): OneHasManyDefinition {
return new OneHasManyDefinition({ target, ownedBy })
}
export function manyHasMany<T extends EntityType<T>>(
target: EntityConstructor<T>,
inversedBy?: KeysOfType<T, Interface<ManyHasManyInverseDefinition>> & string,
): ManyHasManyDefinition {
export function manyHasMany(target: EntityConstructor, inversedBy?: string): ManyHasManyDefinition {
return new ManyHasManyDefinition({ target, inversedBy })
}
export function manyHasManyInverse<T extends EntityType<T>>(
target: EntityConstructor<T>,
ownedBy: KeysOfType<T, Interface<ManyHasManyDefinition>> & string,
): ManyHasManyInverseDefinition {
export function manyHasManyInverse(target: EntityConstructor, ownedBy: string): ManyHasManyInverseDefinition {
return new ManyHasManyInverseDefinition({ target, ownedBy })

@@ -83,20 +69,11 @@ }

/** @deprecated use manyHasManyInverse */
export function manyHasManyInversed<T extends EntityType<T>>(
target: EntityConstructor<T>,
ownedBy: KeysOfType<T, Interface<ManyHasManyDefinition>> & string,
): ManyHasManyInverseDefinition {
export function manyHasManyInversed(target: EntityConstructor, ownedBy: string): ManyHasManyInverseDefinition {
return new ManyHasManyInverseDefinition({ target, ownedBy })
}
export function oneHasOne<T extends EntityType<T>>(
target: EntityConstructor<T>,
inversedBy?: KeysOfType<T, Interface<OneHasOneInverseDefinition>> & string,
): OneHasOneDefinition {
export function oneHasOne(target: EntityConstructor, inversedBy?: string): OneHasOneDefinition {
return new OneHasOneDefinition({ target, inversedBy })
}
export function oneHasOneInverse<T extends EntityType<T>>(
target: EntityConstructor<T>,
ownedBy: KeysOfType<T, Interface<OneHasOneDefinition>> & string,
): OneHasOneInverseDefinition {
export function oneHasOneInverse(target: EntityConstructor, ownedBy: string): OneHasOneInverseDefinition {
return new OneHasOneInverseDefinition({ target, ownedBy })

@@ -106,6 +83,3 @@ }

/** @deprecated use oneHasOneInverse */
export function oneHasOneInversed<T extends EntityType<T>>(
target: EntityConstructor<T>,
ownedBy: KeysOfType<T, Interface<OneHasOneDefinition>> & string,
): OneHasOneInverseDefinition {
export function oneHasOneInversed(target: EntityConstructor, ownedBy: string): OneHasOneInverseDefinition {
return new OneHasOneInverseDefinition({ target, ownedBy })

@@ -119,10 +93,7 @@ }

type UniqueOptions<T> = { name?: string; fields: (keyof T)[] }
type DecoratorFunction<T extends EntityType<T>> = (cls: EntityConstructor<T>) => void
type DecoratorFunction<T> = (cls: EntityConstructor<T>) => void
export function Unique<T extends EntityType<T>>(options: UniqueOptions<T>): DecoratorFunction<T>
export function Unique<T extends EntityType<T>>(...fields: (keyof T)[]): DecoratorFunction<T>
export function Unique<T extends EntityType<T>>(
options: UniqueOptions<T> | keyof T,
...fields: (keyof T)[]
): DecoratorFunction<T> {
export function Unique<T>(options: UniqueOptions<T>): DecoratorFunction<T>
export function Unique<T>(...fields: (keyof T)[]): DecoratorFunction<T>
export function Unique<T>(options: UniqueOptions<T> | keyof T, ...fields: (keyof T)[]): DecoratorFunction<T> {
if (typeof options !== 'object') {

@@ -134,3 +105,3 @@ options = {

return function (cls: { new (): T }) {
return function (cls: EntityConstructor<T>) {
const keys = Reflect.getMetadata('uniqueKeys', cls) || []

@@ -146,5 +117,3 @@ Reflect.defineMetadata('uniqueKeys', [...keys, options], cls)

export type ModelDefinition<M> = {
[K in keyof M]:
| EnumDefinition
| EntityConstructor<EntityType<M[K] extends { new (): any } ? InstanceType<M[K]> : never>>
[K in keyof M]: EnumDefinition | EntityConstructor
}

@@ -151,0 +120,0 @@

import { Model } from '@contember/schema'
import { NamingHelper } from '@contember/schema-utils'
import { tuple } from '../../utils'
import { Interface } from './types'
import { EntityConstructor, Interface } from './types'
import NamingConventions from './NamingConventions'
import FieldDefinition from './FieldDefinition'
import UniqueDefinition from './UniqueDefinition'
import { EntityConstructor } from './types'
import ColumnDefinition from './ColumnDefinition'

@@ -22,3 +21,3 @@ import EnumDefinition from './EnumDefinition'

public addEntity(name: string, entity: EntityConstructor<any>): void {
public addEntity(name: string, entity: EntityConstructor): void {
this.entityRegistry.register(name, entity)

@@ -34,3 +33,3 @@ }

([entityName, definition]): Model.Entity => {
const definitionInstance = new definition()
const definitionInstance: Record<string, Interface<FieldDefinition<any>>> = new definition()

@@ -37,0 +36,0 @@ const unique = Reflect.getMetadata('uniqueKeys', definition) || []

import FieldDefinition from './FieldDefinition'
export type Interface<T> = { [P in keyof T]: T[P] }
export type RelationTarget = EntityConstructor<EntityType<any>>
export type EntityType<T> = { [K in keyof T]: Interface<FieldDefinition<any>> }
export type EntityConstructor<T> = { new (): T }
export type RelationTarget = EntityConstructor
export type EntityConstructor<T = any> = { new (): T }

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc