Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Added entity type sets (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 28, 2019
1 parent 705f322 commit d18d59d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/entity-type-set.tests.ts
@@ -0,0 +1,7 @@
import "jasmine"
import * as entityTypeSet from "./entity-type-set"
import * as shared from "./shared.tests"

describe(`entity type set`, () => {
shared.testEntityTypeSet(entityTypeSet.schema, value => value, `instance`)
})
21 changes: 21 additions & 0 deletions src/entity-type-set.ts
@@ -0,0 +1,21 @@
import * as jsonschema from "jsonschema"
import * as entityType from "./entity-type"

export const schema: jsonschema.Schema = {
description: `Maps entity type identifiers to schemas.`,
type: `object`,
additionalProperties: false,
patternProperties: {
"^[_a-z0-9]{6}$": entityType.schema
}
}

/**
* Maps entity type identifiers to schemas.
*/
export type Type = {
/**
* A mapping of an entity type identifier to its corresponding schema.
*/
readonly [column: string]: entityType.Type
}
4 changes: 4 additions & 0 deletions src/index.tests.ts
Expand Up @@ -12,6 +12,7 @@ import * as columnSet from "./column-set"
import * as labelPart from "./label-part"
import * as label from "./label"
import * as entityType from "./entity-type"
import * as entityTypeSet from "./entity-type-set"
import * as schema from "./schema"
import * as index from "./index"

Expand Down Expand Up @@ -56,6 +57,9 @@ describe(`index`, () => {
describe(`entity type`, () => {
it(`schema`, () => expect(index.entityType).toBe(entityType.schema))
})
describe(`entity type set`, () => {
it(`schema`, () => expect(index.entityTypeSet).toBe(entityTypeSet.schema))
})
describe(`schema`, () => {
it(`schema`, () => expect(index.schema).toBe(schema.schema))
})
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -63,6 +63,11 @@ export {
Type as EntityType
} from "./entity-type"

export {
schema as entityTypeSet,
Type as EntityTypeSet
} from "./entity-type-set"

export {
schema as schema,
Type as Schema
Expand Down
48 changes: 48 additions & 0 deletions src/shared.tests.ts
Expand Up @@ -892,3 +892,51 @@ export function testEntityType(
}), `${property}.columns`)
})
}

export function testEntityTypeSet(
schema: jsonschema.Schema,
instanceFactory: InstanceFactory,
property: string
): void {
run(nonObjects, value => rejects(schema, instanceFactory(value), property, `is not of a type(s) object`))
run(emptyObjects, value => accepts(schema, instanceFactory(value)))
run(identifierStrings, value => accepts(schema, instanceFactory(keyValue(value, {
singular: {},
plural: {},
label: [],
columns: {}
}))))
run(nonIdentifierStrings, value => rejects(schema, instanceFactory(keyValue(value, {
singular: {},
plural: {},
label: [],
columns: {}
})), property, `additionalProperty ${JSON.stringify(value)} exists in instance when not allowed`))
testEntityType(schema, value => instanceFactory(keyValue(`for_eg`, value)), `${property}.for_eg`)
describe(`multiple columns`, () => accepts(schema, instanceFactory({
for_eg: {
singular: {},
plural: {},
label: [],
columns: {}
},
oth_id: {
singular: {},
plural: {},
label: [],
columns: {}
},
anther: {
singular: {},
plural: {},
label: [],
columns: {}
},
lastid: {
singular: {},
plural: {},
label: [],
columns: {}
}
})))
}

0 comments on commit d18d59d

Please sign in to comment.