catalog-model: unbreak EntityPolicy import cycle

This commit is contained in:
Fredrik Adelöw
2021-01-27 21:13:02 +01:00
parent 7881f21174
commit d822077dd6
10 changed files with 41 additions and 26 deletions
@@ -1,4 +1,3 @@
import { Entity } from './entity';
/*
* Copyright 2020 Spotify AB
*
@@ -15,8 +14,8 @@ import { Entity } from './entity';
* limitations under the License.
*/
import { Entity, EntityPolicy } from './entity';
import { EntityPolicies } from './EntityPolicies';
import { EntityPolicy } from './types';
describe('EntityPolicies', () => {
const p1: jest.Mocked<EntityPolicy> = { enforce: jest.fn() };
+1 -2
View File
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import { Entity } from './entity';
import { EntityPolicy } from './types';
import { Entity, EntityPolicy } from './entity';
// Helper that requires that all of a set of policies can be successfully
// applied
@@ -15,7 +15,7 @@
*/
import lodash from 'lodash';
import { EntityPolicy } from '../../types';
import { EntityPolicy } from './types';
import { ENTITY_DEFAULT_NAMESPACE } from '../constants';
import { Entity } from '../Entity';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityPolicy } from '../../types';
import { EntityPolicy } from './types';
import {
CommonValidatorFunctions,
KubernetesValidatorFunctions,
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { EntityPolicy } from '../../types';
import { EntityPolicy } from './types';
import { Entity } from '../Entity';
const defaultKnownFields = ['apiVersion', 'kind', 'metadata', 'spec'];
@@ -15,8 +15,8 @@
*/
import * as yup from 'yup';
import { EntityPolicy } from '../../types';
import { Entity, EntityLink } from '../Entity';
import { EntityPolicy } from './types';
const DEFAULT_ENTITY_SCHEMA = yup
.object({
@@ -18,3 +18,4 @@ export { DefaultNamespaceEntityPolicy } from './DefaultNamespaceEntityPolicy';
export { FieldFormatEntityPolicy } from './FieldFormatEntityPolicy';
export { NoForeignRootFieldsEntityPolicy } from './NoForeignRootFieldsEntityPolicy';
export { SchemaValidEntityPolicy } from './SchemaValidEntityPolicy';
export type { EntityPolicy } from './types';
@@ -0,0 +1,33 @@
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Entity } from '../Entity';
/**
* A policy for validation or mutation to be applied to entities as they are
* entering the system.
*/
export type EntityPolicy = {
/**
* Applies validation or mutation on an entity.
*
* @param entity The entity, as validated/mutated so far in the policy tree
* @returns The incoming entity, or a mutated version of the same, or
* undefined if this processor could not handle the entity
* @throws An error if the entity should be rejected
*/
enforce(entity: Entity): Promise<Entity | undefined>;
};
+1 -1
View File
@@ -18,5 +18,5 @@ export * from './entity';
export { EntityPolicies } from './EntityPolicies';
export * from './kinds';
export * from './location';
export type { EntityName, EntityPolicy, EntityRef, JSONSchema } from './types';
export type { EntityName, EntityRef, JSONSchema } from './types';
export * from './validation';
-17
View File
@@ -16,23 +16,6 @@
import { JsonValue } from '@backstage/config';
import { JSONSchema7 } from 'json-schema';
import type { Entity } from './entity/Entity';
/**
* A policy for validation or mutation to be applied to entities as they are
* entering the system.
*/
export type EntityPolicy = {
/**
* Applies validation or mutation on an entity.
*
* @param entity The entity, as validated/mutated so far in the policy tree
* @returns The incoming entity, or a mutated version of the same, or
* undefined if this processor could not handle the entity
* @throws An error if the entity should be rejected
*/
enforce(entity: Entity): Promise<Entity | undefined>;
};
export type JSONSchema = JSONSchema7 & { [key in string]?: JsonValue };