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

Commit

Permalink
Added entity types (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 27, 2019
1 parent 30d6069 commit b462031
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/entity-type.tests.ts
@@ -0,0 +1,68 @@
import "jasmine"
import * as entityType from "./entity-type"
import * as shared from "./shared.tests"

describe(`entity type`, () => {
shared.run(shared.nonObjects, value => shared.rejects(
entityType.schema, value, `instance`, `is not of a type(s) object`
))
describe(`unexpected properties`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
label: [],
columns: {},
unexpected: {}
}, `instance`, `additionalProperty "unexpected" exists in instance when not allowed`))
describe(`singular`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
plural: {},
label: [],
columns: {}
}, `instance`, `requires property "singular"`))
shared.testLocalizedString(entityType.schema, instance => ({
singular: instance,
plural: {},
label: [],
columns: {},
}), `instance.singular`)
})
describe(`plural`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
label: [],
columns: {}
}, `instance`, `requires property "plural"`))
shared.testLocalizedString(entityType.schema, instance => ({
singular: {},
plural: instance,
label: [],
columns: {},
}), `instance.plural`)
})
describe(`label`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
columns: {}
}, `instance`, `requires property "label"`))
shared.testLabel(entityType.schema, instance => ({
singular: {},
plural: {},
label: instance,
columns: {},
}), `instance.label`)
})
describe(`columns`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
label: []
}, `instance`, `requires property "columns"`))
shared.testColumnSet(entityType.schema, instance => ({
singular: {},
plural: {},
label: [],
columns: instance,
}), `instance.columns`)
})
})
50 changes: 50 additions & 0 deletions src/entity-type.ts
@@ -0,0 +1,50 @@
import * as jsonschema from "jsonschema"
import * as localizedString from "./localized-string"
import * as columnSet from "./column-set"
import * as label from "./label"

export const schema: jsonschema.Schema = {
description: `An entity type.`,
type: `object`,
additionalProperties: false,
required: [
`singular`,
`plural`,
`label`,
`columns`
],
properties: {
singular: localizedString.schema,
plural: localizedString.schema,
label: label.schema,
columns: columnSet.schema
}
}

/**
* An entity type.
*/
export type Type = {
/**
* Maps localization identifiers to the name of the entity type, in singular
* form, in those localizations.
*/
readonly singular: localizedString.Type

/**
* Maps localization identifiers to the name of the entity type, in plural
* form, in those localizations.
*/
readonly plural: localizedString.Type

/**
* A list of chains of column identifiers which can be followed to find
* values which are concatenated to build a label.
*/
readonly label: label.Type

/**
* Maps column identifiers to schemas.
*/
readonly columns: columnSet.Type
}
4 changes: 4 additions & 0 deletions src/index.tests.ts
Expand Up @@ -11,6 +11,7 @@ import * as column from "./column"
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 schema from "./schema"
import * as index from "./index"

Expand Down Expand Up @@ -52,6 +53,9 @@ describe(`index`, () => {
describe(`label`, () => {
it(`schema`, () => expect(index.label).toBe(label.schema))
})
describe(`entity type`, () => {
it(`schema`, () => expect(index.entityType).toBe(entityType.schema))
})
describe(`schema`, () => {
it(`schema`, () => expect(index.schema).toBe(schema.schema))
})
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -58,6 +58,11 @@ export {
Type as Label
} from "./label"

export {
schema as entityType,
Type as EntityType
} from "./entity-type"

export {
schema as schema,
Type as Schema
Expand Down

0 comments on commit b462031

Please sign in to comment.