diff --git a/src/entity-type.tests.ts b/src/entity-type.tests.ts new file mode 100644 index 0000000..792481c --- /dev/null +++ b/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`) + }) +}) diff --git a/src/entity-type.ts b/src/entity-type.ts new file mode 100644 index 0000000..7f00d0f --- /dev/null +++ b/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 +} diff --git a/src/index.tests.ts b/src/index.tests.ts index 334abad..988897f 100644 --- a/src/index.tests.ts +++ b/src/index.tests.ts @@ -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" @@ -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)) }) diff --git a/src/index.ts b/src/index.ts index e2236e0..8a32583 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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