@contember/schema-utils
Advanced tools
Comparing version 0.9.0-alpha.0 to 0.9.0-alpha.1
@@ -6,3 +6,2 @@ import { Model } from '@contember/schema'; | ||
export declare const getTargetEntity: (schema: Model.Schema, entity: Model.Entity, relationName: string) => Model.Entity | null; | ||
export declare const getUniqueConstraints: (schema: Model.Schema, entity: Model.Entity) => Model.UniqueConstraint[]; | ||
export declare const acceptEveryFieldVisitor: <T>(schema: Model.Schema, entity: string | Model.Entity, visitor: Model.FieldVisitor<T>) => { | ||
@@ -9,0 +8,0 @@ [fieldName: string]: T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.emptyModelSchema = exports.isOwnerRelation = exports.isInversedRelation = exports.acceptRelationTypeVisitor = exports.acceptFieldVisitor = exports.acceptEveryFieldVisitor = exports.getUniqueConstraints = exports.getTargetEntity = exports.getColumnType = exports.getColumnName = exports.getEntity = void 0; | ||
exports.emptyModelSchema = exports.isOwnerRelation = exports.isInversedRelation = exports.acceptRelationTypeVisitor = exports.acceptFieldVisitor = exports.acceptEveryFieldVisitor = exports.getTargetEntity = exports.getColumnType = exports.getColumnName = exports.getEntity = void 0; | ||
const utils_1 = require("../utils"); | ||
const schema_1 = require("@contember/schema"); | ||
const NamingHelper_1 = require("./NamingHelper"); | ||
exports.getEntity = (schema, entityName) => { | ||
@@ -43,20 +42,2 @@ const entity = schema.entities[entityName]; | ||
}; | ||
exports.getUniqueConstraints = (schema, entity) => { | ||
const additionalConstraints = Object.values(exports.acceptEveryFieldVisitor(schema, entity, { | ||
visitColumn: () => undefined, | ||
visitManyHasManyInversed: () => undefined, | ||
visitManyHasManyOwner: () => undefined, | ||
visitOneHasMany: () => undefined, | ||
visitManyHasOne: () => undefined, | ||
visitOneHasOneInversed: (entity, relation) => ({ | ||
fields: [relation.name], | ||
name: NamingHelper_1.NamingHelper.createUniqueConstraintName(entity.name, [relation.name]), | ||
}), | ||
visitOneHasOneOwner: (entity, relation) => ({ | ||
fields: [relation.name], | ||
name: NamingHelper_1.NamingHelper.createUniqueConstraintName(entity.name, [relation.name]), | ||
}), | ||
})).filter((it) => !!it); | ||
return [...Object.values(entity.unique), ...additionalConstraints]; | ||
}; | ||
exports.acceptEveryFieldVisitor = (schema, entity, visitor) => { | ||
@@ -63,0 +44,0 @@ const entityObj = typeof entity === 'string' ? exports.getEntity(schema, entity) : entity; |
{ | ||
"name": "@contember/schema-utils", | ||
"version": "0.9.0-alpha.0", | ||
"version": "0.9.0-alpha.1", | ||
"license": "Apache-2.0", | ||
@@ -9,3 +9,3 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/schema": "^0.9.0-alpha.0" | ||
"@contember/schema": "^0.9.0-alpha.1" | ||
}, | ||
@@ -16,3 +16,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "d930763080dbf9868cd4ed2e39f0bb6ffe5220af" | ||
"gitHead": "ef9d3567bc86885591341cca901b7a12e0e46f74" | ||
} |
@@ -49,24 +49,2 @@ import { isIt } from '../utils' | ||
export const getUniqueConstraints = (schema: Model.Schema, entity: Model.Entity): Model.UniqueConstraint[] => { | ||
const additionalConstraints = Object.values( | ||
acceptEveryFieldVisitor<Model.UniqueConstraint | undefined>(schema, entity, { | ||
visitColumn: () => undefined, | ||
visitManyHasManyInversed: () => undefined, | ||
visitManyHasManyOwner: () => undefined, | ||
visitOneHasMany: () => undefined, | ||
visitManyHasOne: () => undefined, | ||
visitOneHasOneInversed: (entity, relation) => ({ | ||
fields: [relation.name], | ||
name: NamingHelper.createUniqueConstraintName(entity.name, [relation.name]), | ||
}), | ||
visitOneHasOneOwner: (entity, relation) => ({ | ||
fields: [relation.name], | ||
name: NamingHelper.createUniqueConstraintName(entity.name, [relation.name]), | ||
}), | ||
}), | ||
).filter((it): it is Model.UniqueConstraint => !!it) | ||
return [...Object.values(entity.unique), ...additionalConstraints] | ||
} | ||
export const acceptEveryFieldVisitor = <T>( | ||
@@ -73,0 +51,0 @@ schema: Model.Schema, |
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
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
320699
3386