@contember/schema-definition
Advanced tools
Comparing version 1.1.0-alpha.5 to 1.1.0-alpha.6
@@ -36,4 +36,5 @@ "use strict"; | ||
} | ||
const entityOperations = permissions[entity.name].operations; | ||
for (const op of operations) { | ||
permissions[entity.name].operations[op] = { | ||
entityOperations[op] = { | ||
...(permissions[entity.name].operations[op] || {}), | ||
@@ -40,0 +41,0 @@ [field.name]: predicate, |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -30,2 +30,5 @@ "use strict"; | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: schema_1.Model.OnDelete.cascade }, | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
}; | ||
@@ -32,0 +35,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -38,2 +38,5 @@ "use strict"; | ||
tableName: options.tableName || this.conventions.getTableName(name), | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
}; | ||
@@ -40,0 +43,0 @@ } |
@@ -12,2 +12,3 @@ import { Model } from '@contember/schema'; | ||
notNull(): Interface<ColumnDefinition>; | ||
sequence(options?: Model.ColumnTypeDefinition['sequence']): Interface<ColumnDefinition>; | ||
unique(): Interface<ColumnDefinition>; | ||
@@ -39,3 +40,4 @@ default(value: ColumnDefinition['options']['default']): Interface<ColumnDefinition>; | ||
default?: Model.ColumnTypeDefinition['default']; | ||
sequence?: Model.ColumnTypeDefinition['sequence']; | ||
} & ColumnTypeOptions; | ||
//# sourceMappingURL=ColumnDefinition.d.ts.map |
@@ -30,2 +30,5 @@ "use strict"; | ||
} | ||
sequence(options) { | ||
return this.withOption('sequence', options !== null && options !== void 0 ? options : { precedence: 'BY DEFAULT' }); | ||
} | ||
unique() { | ||
@@ -41,3 +44,3 @@ return this.withOption('unique', true); | ||
createField({ name, conventions, enumRegistry, entityName }) { | ||
const { type, nullable, columnName, enumDefinition, default: defaultValue, columnType, typeAlias } = this.options; | ||
const { type, nullable, columnName, enumDefinition, default: defaultValue, columnType, typeAlias, sequence } = this.options; | ||
const common = { | ||
@@ -48,2 +51,3 @@ name: name, | ||
...(defaultValue !== undefined ? { default: defaultValue } : {}), | ||
...(sequence !== undefined ? { sequence } : {}), | ||
}; | ||
@@ -50,0 +54,0 @@ if (type === schema_1.Model.ColumnType.Enum) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -7,3 +7,3 @@ import { Model } from '@contember/schema'; | ||
inversedBy(inversedBy: string): Interface<ManyHasManyDefinition>; | ||
joiningTable(joiningTable: Model.JoiningTable): Interface<ManyHasManyDefinition>; | ||
joiningTable(joiningTable: Partial<Model.JoiningTable>): Interface<ManyHasManyDefinition>; | ||
orderBy(field: string | string[], direction?: Model.OrderDirection): Interface<ManyHasManyDefinition>; | ||
@@ -17,5 +17,5 @@ createField({ name, conventions, entityName, entityRegistry }: CreateFieldContext): Model.AnyField; | ||
inversedBy?: string; | ||
joiningTable?: Model.JoiningTable; | ||
joiningTable?: Partial<Model.JoiningTable>; | ||
orderBy?: Model.OrderBy[]; | ||
}; | ||
//# sourceMappingURL=ManyHasManyDefinition.d.ts.map |
@@ -23,11 +23,10 @@ "use strict"; | ||
const options = this.options; | ||
let joiningTable = options.joiningTable; | ||
if (!joiningTable) { | ||
const columnNames = conventions.getJoiningTableColumnNames(entityName, name, entityRegistry.getName(options.target), options.inversedBy); | ||
joiningTable = { | ||
tableName: conventions.getJoiningTableName(entityName, name), | ||
joiningColumn: { columnName: columnNames[0], onDelete: schema_1.Model.OnDelete.cascade }, | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: schema_1.Model.OnDelete.cascade }, | ||
}; | ||
} | ||
const columnNames = conventions.getJoiningTableColumnNames(entityName, name, entityRegistry.getName(options.target), options.inversedBy); | ||
const joiningTable = { | ||
tableName: conventions.getJoiningTableName(entityName, name), | ||
joiningColumn: { columnName: columnNames[0], onDelete: schema_1.Model.OnDelete.cascade }, | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: schema_1.Model.OnDelete.cascade }, | ||
eventLog: { enabled: true }, | ||
...options.joiningTable, | ||
}; | ||
return { | ||
@@ -34,0 +33,0 @@ type: schema_1.Model.RelationType.ManyHasMany, |
@@ -7,2 +7,3 @@ import { EntityConstructor, Interface } from './types'; | ||
export * from './fieldDefinitions'; | ||
export * from './EventLogDefinition'; | ||
export * from './EnumDefinition'; | ||
@@ -9,0 +10,0 @@ export * from './UniqueDefinition'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -21,2 +25,3 @@ if (k2 === undefined) k2 = k; | ||
__exportStar(require("./fieldDefinitions"), exports); | ||
__exportStar(require("./EventLogDefinition"), exports); | ||
__exportStar(require("./EnumDefinition"), exports); | ||
@@ -23,0 +28,0 @@ __exportStar(require("./UniqueDefinition"), exports); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -28,3 +28,2 @@ "use strict"; | ||
const primaryName = this.conventions.getPrimaryField(); | ||
const primaryField = this.createPrimaryColumn(); | ||
const entity = { | ||
@@ -35,3 +34,6 @@ name: entityName, | ||
unique: this.createUnique(entityName, definitionInstance), | ||
fields: [(0, utils_1.tuple)(primaryName, primaryField), ...Object.entries(definitionInstance)] | ||
fields: [ | ||
...definitionInstance[primaryName] ? [] : [(0, utils_1.tuple)(primaryName, this.createPrimaryColumn())], | ||
...Object.entries(definitionInstance), | ||
] | ||
.map(([name, definition]) => { | ||
@@ -53,2 +55,5 @@ return definition.createField({ | ||
tableName: this.conventions.getTableName(entityName), | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
}; | ||
@@ -55,0 +60,0 @@ return (0, extensions_1.applyEntityExtensions)(definition, { entity, definition: definitionInstance, registry: this.entityRegistry }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -6,3 +6,3 @@ import { SchemaDefinition } from '../model'; | ||
export declare type ContextPath = Validation.ContextPath | string | undefined; | ||
export declare const parsePath: (path: ContextPath) => string[]; | ||
export declare const parsePath: (path: ContextPath) => readonly string[]; | ||
export declare function fluent(): RuleBranch; | ||
@@ -9,0 +9,0 @@ declare class RuleBranch { |
{ | ||
"name": "@contember/schema-definition", | ||
"version": "1.1.0-alpha.5", | ||
"version": "1.1.0-alpha.6", | ||
"license": "Apache-2.0", | ||
@@ -11,4 +11,4 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/schema": "^1.1.0-alpha.5", | ||
"@contember/schema-utils": "^1.1.0-alpha.5", | ||
"@contember/schema": "^1.1.0-alpha.6", | ||
"@contember/schema-utils": "^1.1.0-alpha.6", | ||
"reflect-metadata": "^0.1.13" | ||
@@ -15,0 +15,0 @@ }, |
import { tuple } from '../utils' | ||
import EntitySelector from './EntitySelector' | ||
import { Acl, Model } from '@contember/schema' | ||
import { Acl, Model, Writable } from '@contember/schema' | ||
import FieldSelector from './FieldSelector' | ||
@@ -70,3 +70,3 @@ import FieldPermissionsBuilder from './FieldPermissionsBuilder' | ||
) | ||
const entityOperations: Acl.EntityOperations = {} | ||
const entityOperations: Writable<Acl.EntityOperations> = {} | ||
if (operations.includes(Acl.Operation.read)) { | ||
@@ -73,0 +73,0 @@ entityOperations.read = fieldPermissions |
import FieldSelector from './FieldSelector' | ||
import EntityPermissionsBuilder from './EntityPermissionsBuilder' | ||
import { Acl, Model } from '@contember/schema' | ||
import { Acl, Model, Writable } from '@contember/schema' | ||
import EntitySelector from './EntitySelector' | ||
@@ -45,3 +45,3 @@ import PermissionsBuilder from './PermissionsBuilder' | ||
): FieldPermissionsBuilder { | ||
const permissions: Acl.Permissions = {} | ||
const permissions: Writable<Acl.Permissions> = {} | ||
for (const [entity, field] of this.fields) { | ||
@@ -51,4 +51,5 @@ if (!permissions[entity.name]) { | ||
} | ||
const entityOperations: Writable<Acl.EntityOperations> = permissions[entity.name].operations | ||
for (const op of operations) { | ||
permissions[entity.name].operations[op] = { | ||
entityOperations[op] = { | ||
...(permissions[entity.name].operations[op] || {}), | ||
@@ -55,0 +56,0 @@ [field.name]: predicate, |
@@ -55,2 +55,5 @@ import FieldProcessor from './FieldProcessor' | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: Model.OnDelete.cascade }, | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
} | ||
@@ -57,0 +60,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Model } from '@contember/schema' | ||
import { Model, Writable } from '@contember/schema' | ||
import { NamingHelper } from '@contember/schema-utils' | ||
@@ -15,3 +15,3 @@ import EntityBuilder from './EntityBuilder' | ||
export default class SchemaBuilderInternal { | ||
private entities: { [name: string]: Model.Entity } = {} | ||
private entities: { [name: string]: Model.Entity & { fields: Record<string, Model.AnyField> } } = {} | ||
@@ -44,2 +44,5 @@ private fieldOptions: { [entity: string]: FieldBuilder.Map } = {} | ||
tableName: options.tableName || this.conventions.getTableName(name), | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
} | ||
@@ -160,3 +163,3 @@ } | ||
): Model.UniqueConstraints { | ||
const unique: Model.UniqueConstraints = {} | ||
const unique: Writable<Model.UniqueConstraints> = {} | ||
for (const singleUnique of options.unique || []) { | ||
@@ -163,0 +166,0 @@ const name = singleUnique.name || NamingHelper.createUniqueConstraintName(entityName, singleUnique.fields) |
@@ -20,2 +20,3 @@ import { Model } from '@contember/schema' | ||
public columnName(columnName: string): Interface<ColumnDefinition> { | ||
@@ -37,2 +38,6 @@ return this.withOption('columnName', columnName) | ||
public sequence(options?: Model.ColumnTypeDefinition['sequence']): Interface<ColumnDefinition> { | ||
return this.withOption('sequence', options ?? { precedence: 'BY DEFAULT' }) | ||
} | ||
public unique(): Interface<ColumnDefinition> { | ||
@@ -51,3 +56,3 @@ return this.withOption('unique', true) | ||
createField({ name, conventions, enumRegistry, entityName }: CreateFieldContext): Model.AnyField { | ||
const { type, nullable, columnName, enumDefinition, default: defaultValue, columnType, typeAlias } = this.options | ||
const { type, nullable, columnName, enumDefinition, default: defaultValue, columnType, typeAlias, sequence } = this.options | ||
const common = { | ||
@@ -58,2 +63,3 @@ name: name, | ||
...(defaultValue !== undefined ? { default: defaultValue } : {}), | ||
...(sequence !== undefined ? { sequence } : {}), | ||
} | ||
@@ -137,2 +143,3 @@ if (type === Model.ColumnType.Enum) { | ||
default?: Model.ColumnTypeDefinition['default'] | ||
sequence?: Model.ColumnTypeDefinition['sequence'] | ||
} & ColumnTypeOptions |
@@ -12,3 +12,3 @@ import { Model } from '@contember/schema' | ||
joiningTable(joiningTable: Model.JoiningTable): Interface<ManyHasManyDefinition> { | ||
joiningTable(joiningTable: Partial<Model.JoiningTable>): Interface<ManyHasManyDefinition> { | ||
return this.withOption('joiningTable', joiningTable) | ||
@@ -27,15 +27,14 @@ } | ||
const options = this.options | ||
let joiningTable: Model.JoiningTable | undefined = options.joiningTable | ||
if (!joiningTable) { | ||
const columnNames = conventions.getJoiningTableColumnNames( | ||
entityName, | ||
name, | ||
entityRegistry.getName(options.target), | ||
options.inversedBy, | ||
) | ||
joiningTable = { | ||
tableName: conventions.getJoiningTableName(entityName, name), | ||
joiningColumn: { columnName: columnNames[0], onDelete: Model.OnDelete.cascade }, | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: Model.OnDelete.cascade }, | ||
} | ||
const columnNames = conventions.getJoiningTableColumnNames( | ||
entityName, | ||
name, | ||
entityRegistry.getName(options.target), | ||
options.inversedBy, | ||
) | ||
const joiningTable = { | ||
tableName: conventions.getJoiningTableName(entityName, name), | ||
joiningColumn: { columnName: columnNames[0], onDelete: Model.OnDelete.cascade }, | ||
inverseJoiningColumn: { columnName: columnNames[1], onDelete: Model.OnDelete.cascade }, | ||
eventLog: { enabled: true }, | ||
...options.joiningTable, | ||
} | ||
@@ -63,4 +62,4 @@ | ||
inversedBy?: string | ||
joiningTable?: Model.JoiningTable | ||
joiningTable?: Partial<Model.JoiningTable> | ||
orderBy?: Model.OrderBy[] | ||
} |
@@ -10,2 +10,3 @@ import { EntityConstructor, Interface } from './types' | ||
export * from './fieldDefinitions' | ||
export * from './EventLogDefinition' | ||
export * from './EnumDefinition' | ||
@@ -12,0 +13,0 @@ export * from './UniqueDefinition' |
@@ -1,2 +0,2 @@ | ||
import { Model } from '@contember/schema' | ||
import { Model, Writable } from '@contember/schema' | ||
import { NamingHelper } from '@contember/schema-utils' | ||
@@ -33,3 +33,2 @@ import 'reflect-metadata' | ||
const primaryName = this.conventions.getPrimaryField() | ||
const primaryField = this.createPrimaryColumn() | ||
@@ -41,3 +40,6 @@ const entity: Model.Entity = { | ||
unique: this.createUnique(entityName, definitionInstance), | ||
fields: [tuple(primaryName, primaryField), ...Object.entries(definitionInstance)] | ||
fields: [ | ||
...definitionInstance[primaryName] ? [] : [tuple(primaryName, this.createPrimaryColumn())], | ||
...Object.entries(definitionInstance), | ||
] | ||
.map(([name, definition]) => { | ||
@@ -59,2 +61,5 @@ return definition.createField({ | ||
tableName: this.conventions.getTableName(entityName), | ||
eventLog: { | ||
enabled: true, | ||
}, | ||
} | ||
@@ -78,3 +83,3 @@ return applyEntityExtensions(definition, { entity, definition: definitionInstance, registry: this.entityRegistry }) | ||
private createUnique(entityName: string, fieldDefinitions: FieldsDefinition): Model.UniqueConstraints { | ||
const unique: Model.UniqueConstraints = {} | ||
const unique: Writable<Model.UniqueConstraints> = {} | ||
for (const [fieldName, definition] of Object.entries(fieldDefinitions)) { | ||
@@ -81,0 +86,0 @@ if (definition.options.unique) { |
@@ -9,3 +9,3 @@ import { tuple } from '../utils' | ||
export type ContextPath = Validation.ContextPath | string | undefined | ||
export const parsePath = (path: ContextPath): string[] => { | ||
export const parsePath = (path: ContextPath): readonly string[] => { | ||
if (!path) { | ||
@@ -12,0 +12,0 @@ return [] |
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
360640
271
4936