diff --git a/packages/content/src/attributes/RelationshipAttribute.ts b/packages/content/src/attributes/RelationshipAttribute.ts index dabe29751..f03e8228f 100644 --- a/packages/content/src/attributes/RelationshipAttribute.ts +++ b/packages/content/src/attributes/RelationshipAttribute.ts @@ -2,6 +2,7 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; import { AbstractAttribute, AbstractAttributeJSON, IAbstractAttribute } from "./AbstractAttribute"; import { AttributeValues } from "./AttributeValueTypes"; import { RelationshipAttributeConfidentiality } from "./RelationshipAttributeConfidentiality"; +import { characterSets } from "./constants/CharacterSets"; export interface RelationshipAttributeJSON extends AbstractAttributeJSON { "@type": "RelationshipAttribute"; @@ -28,7 +29,7 @@ export class RelationshipAttribute = { + // DIN91379 character sets from https://xoev.de/schemata/din/91379/2022-08/din-norm-91379-datatypes.xsd + // See the sources in the browser's dev mode, they're not equal to what's initially displayed + // data type A for names of natural persons + din91379DatatypeA: + /^( |'|[,-.]|[A-Z]|[`-z]|~|¨|´|·|[À-Ö]|[Ø-ö]|[ø-ž]|[Ƈ-ƈ]|Ə|Ɨ|[Ơ-ơ]|[Ư-ư]|Ʒ|[Ǎ-ǜ]|[Ǟ-ǟ]|[Ǣ-ǰ]|[Ǵ-ǵ]|[Ǹ-ǿ]|[Ȓ-ȓ]|[Ș-ț]|[Ȟ-ȟ]|[ȧ-ȳ]|ə|ɨ|ʒ|[ʹ-ʺ]|[ʾ-ʿ]|ˈ|ˌ|[Ḃ-ḃ]|[Ḇ-ḇ]|[Ḋ-ḑ]|ḗ|[Ḝ-ḫ]|[ḯ-ḷ]|[Ḻ-ḻ]|[Ṁ-ṉ]|[Ṓ-ṛ]|[Ṟ-ṣ]|[Ṫ-ṯ]|[Ẁ-ẇ]|[Ẍ-ẗ]|ẞ|[Ạ-ỹ]|’|‡|A̋|C(̀|̄|̆|̈|̕|̣|̦|̨̆)|D̂|F(̀|̄)|G̀|H(̄|̦|̱)|J(́|̌)|K(̀|̂|̄|̇|̕|̛|̦|͟H|͟h)|L(̂|̥|̥̄|̦)|M(̀|̂|̆|̐)|N(̂|̄|̆|̦)|P(̀|̄|̕|̣)|R(̆|̥|̥̄)|S(̀|̄|̛̄|̱)|T(̀|̄|̈|̕|̛)|U̇|Z(̀|̄|̆|̈|̧)|a̋|c(̀|̄|̆|̈|̕|̣|̦|̨̆)|d̂|f(̀|̄)|g̀|h(̄|̦)|j́|k(̀|̂|̄|̇|̕|̛|̦|͟h)|l(̂|̥|̥̄|̦)|m(̀|̂|̆|̐)|n(̂|̄|̆|̦)|p(̀|̄|̕|̣)|r(̆|̥|̥̄)|s(̀|̄|̛̄|̱)|t(̀|̄|̕|̛)|u̇|z(̀|̄|̆|̈|̧)|Ç̆|Û̄|ç̆|û̄|ÿ́|Č(̕|̣)|č(̕|̣)|ē̍|Ī́|ī́|ō̍|Ž(̦|̧)|ž(̦|̧)|Ḳ̄|ḳ̄|Ṣ̄|ṣ̄|Ṭ̄|ṭ̄|Ạ̈|ạ̈|Ọ̈|ọ̈|Ụ(̄|̈)|ụ(̄|̈))*$/, + // data type B for all names + din91379DatatypeB: + /^([ -~]|[¡-£]|¥|[§-¬]|[®-·]|[¹-»]|[¿-ž]|[Ƈ-ƈ]|Ə|Ɨ|[Ơ-ơ]|[Ư-ư]|Ʒ|[Ǎ-ǜ]|[Ǟ-ǟ]|[Ǣ-ǰ]|[Ǵ-ǵ]|[Ǹ-ǿ]|[Ȓ-ȓ]|[Ș-ț]|[Ȟ-ȟ]|[ȧ-ȳ]|ə|ɨ|ʒ|[ʹ-ʺ]|[ʾ-ʿ]|ˈ|ˌ|[Ḃ-ḃ]|[Ḇ-ḇ]|[Ḋ-ḑ]|ḗ|[Ḝ-ḫ]|[ḯ-ḷ]|[Ḻ-ḻ]|[Ṁ-ṉ]|[Ṓ-ṛ]|[Ṟ-ṣ]|[Ṫ-ṯ]|[Ẁ-ẇ]|[Ẍ-ẗ]|ẞ|[Ạ-ỹ]|’|‡|€|A̋|C(̀|̄|̆|̈|̕|̣|̦|̨̆)|D̂|F(̀|̄)|G̀|H(̄|̦|̱)|J(́|̌)|K(̀|̂|̄|̇|̕|̛|̦|͟H|͟h)|L(̂|̥|̥̄|̦)|M(̀|̂|̆|̐)|N(̂|̄|̆|̦)|P(̀|̄|̕|̣)|R(̆|̥|̥̄)|S(̀|̄|̛̄|̱)|T(̀|̄|̈|̕|̛)|U̇|Z(̀|̄|̆|̈|̧)|a̋|c(̀|̄|̆|̈|̕|̣|̦|̨̆)|d̂|f(̀|̄)|g̀|h(̄|̦)|j́|k(̀|̂|̄|̇|̕|̛|̦|͟h)|l(̂|̥|̥̄|̦)|m(̀|̂|̆|̐)|n(̂|̄|̆|̦)|p(̀|̄|̕|̣)|r(̆|̥|̥̄)|s(̀|̄|̛̄|̱)|t(̀|̄|̕|̛)|u̇|z(̀|̄|̆|̈|̧)|Ç̆|Û̄|ç̆|û̄|ÿ́|Č(̕|̣)|č(̕|̣)|ē̍|Ī́|ī́|ō̍|Ž(̦|̧)|ž(̦|̧)|Ḳ̄|ḳ̄|Ṣ̄|ṣ̄|Ṭ̄|ṭ̄|Ạ̈|ạ̈|Ọ̈|ọ̈|Ụ(̄|̈)|ụ(̄|̈))*$/, + // data type C for every mandatory character in the norm + din91379DatatypeC: + /^([\u0009-\u000A]|\u000D|[ -~]|[ -¬]|[®-ž]|[Ƈ-ƈ]|Ə|Ɨ|[Ơ-ơ]|[Ư-ư]|Ʒ|[Ǎ-ǜ]|[Ǟ-ǟ]|[Ǣ-ǰ]|[Ǵ-ǵ]|[Ǹ-ǿ]|[Ȓ-ȓ]|[Ș-ț]|[Ȟ-ȟ]|[ȧ-ȳ]|ə|ɨ|ʒ|[ʹ-ʺ]|[ʾ-ʿ]|ˈ|ˌ|[Ḃ-ḃ]|[Ḇ-ḇ]|[Ḋ-ḑ]|ḗ|[Ḝ-ḫ]|[ḯ-ḷ]|[Ḻ-ḻ]|[Ṁ-ṉ]|[Ṓ-ṛ]|[Ṟ-ṣ]|[Ṫ-ṯ]|[Ẁ-ẇ]|[Ẍ-ẗ]|ẞ|[Ạ-ỹ]|’|‡|€|A̋|C(̀|̄|̆|̈|̕|̣|̦|̨̆)|D̂|F(̀|̄)|G̀|H(̄|̦|̱)|J(́|̌)|K(̀|̂|̄|̇|̕|̛|̦|͟H|͟h)|L(̂|̥|̥̄|̦)|M(̀|̂|̆|̐)|N(̂|̄|̆|̦)|P(̀|̄|̕|̣)|R(̆|̥|̥̄)|S(̀|̄|̛̄|̱)|T(̀|̄|̈|̕|̛)|U̇|Z(̀|̄|̆|̈|̧)|a̋|c(̀|̄|̆|̈|̕|̣|̦|̨̆)|d̂|f(̀|̄)|g̀|h(̄|̦)|j́|k(̀|̂|̄|̇|̕|̛|̦|͟h)|l(̂|̥|̥̄|̦)|m(̀|̂|̆|̐)|n(̂|̄|̆|̦)|p(̀|̄|̕|̣)|r(̆|̥|̥̄)|s(̀|̄|̛̄|̱)|t(̀|̄|̕|̛)|u̇|z(̀|̄|̆|̈|̧)|Ç̆|Û̄|ç̆|û̄|ÿ́|Č(̕|̣)|č(̕|̣)|ē̍|Ī́|ī́|ō̍|Ž(̦|̧)|ž(̦|̧)|Ḳ̄|ḳ̄|Ṣ̄|ṣ̄|Ṭ̄|ṭ̄|Ạ̈|ạ̈|Ọ̈|ọ̈|Ụ(̄|̈)|ụ(̄|̈))*$/ +}; diff --git a/packages/content/src/attributes/hints/ValueHints.ts b/packages/content/src/attributes/hints/ValueHints.ts index 95b280950..b81f26777 100644 --- a/packages/content/src/attributes/hints/ValueHints.ts +++ b/packages/content/src/attributes/hints/ValueHints.ts @@ -1,5 +1,6 @@ import { ISerializable, PrimitiveType, Serializable, serialize, type, validate } from "@js-soft/ts-serval"; import { ContentJSON } from "../../ContentJSON"; +import { characterSets } from "../constants/CharacterSets"; import { IValueHintsValue, ValueHintsValue, ValueHintsValueJSON } from "./ValueHintsValue"; export interface ValueHintsJSON extends ContentJSON { @@ -48,7 +49,7 @@ function serializePropertyHints(hints: ValueHints | ValueHintsOverride, json: Va @type("ValueHints") export class ValueHints extends Serializable implements IValueHints { @serialize() - @validate({ nullable: true, max: 500 }) + @validate({ nullable: true, max: 500, regExp: characterSets.din91379DatatypeC }) public editHelp?: string; @serialize() @@ -67,7 +68,7 @@ export class ValueHints extends Serializable implements IValueHints { @validate({ nullable: true }) public values?: ValueHintsValue[]; - @validate({ nullable: true, allowedTypes: [PrimitiveType.Number, PrimitiveType.String, PrimitiveType.Boolean] }) + @validate({ nullable: true, allowedTypes: [PrimitiveType.Number, PrimitiveType.String, PrimitiveType.Boolean], customValidator: validateDefaultValue }) @serialize() public defaultValue?: number | string | boolean; @@ -104,7 +105,7 @@ export class ValueHints extends Serializable implements IValueHints { @type("ValueHintsOverride") export class ValueHintsOverride extends Serializable implements IValueHintsOverride { @serialize() - @validate({ nullable: true, max: 500 }) + @validate({ nullable: true, max: 500, regExp: characterSets.din91379DatatypeC }) public editHelp?: string; @serialize() @@ -124,7 +125,7 @@ export class ValueHintsOverride extends Serializable implements IValueHintsOverr public values?: ValueHintsValue[]; @serialize() - @validate({ nullable: true, allowedTypes: [PrimitiveType.Number, PrimitiveType.String, PrimitiveType.Boolean] }) + @validate({ nullable: true, allowedTypes: [PrimitiveType.Number, PrimitiveType.String, PrimitiveType.Boolean], customValidator: validateDefaultValue }) public defaultValue?: boolean | number | string; @serialize() @@ -147,3 +148,11 @@ export class ValueHintsOverride extends Serializable implements IValueHintsOverr return json; } } + +function validateDefaultValue(defaultValue: string | number | boolean) { + if (typeof defaultValue === "string" && !characterSets.din91379DatatypeC.test(defaultValue)) { + return "Value does not match regular expression /^([\\u0009-\\u000A]|\\u000D|[ -~]|[ -¬]|[®-ž]|[Ƈ-ƈ]|Ə|Ɨ|[Ơ-ơ]|[Ư-ư]|Ʒ|[Ǎ-ǜ]|[Ǟ-ǟ]|[Ǣ-ǰ]|[Ǵ-ǵ]|[Ǹ-ǿ]|[Ȓ-ȓ]|[Ș-ț]|[Ȟ-ȟ]|[ȧ-ȳ]|ə|ɨ|ʒ|[ʹ-ʺ]|[ʾ-ʿ]|ˈ|ˌ|[Ḃ-ḃ]|[Ḇ-ḇ]|[Ḋ-ḑ]|ḗ|[Ḝ-ḫ]|[ḯ-ḷ]|[Ḻ-ḻ]|[Ṁ-ṉ]|[Ṓ-ṛ]|[Ṟ-ṣ]|[Ṫ-ṯ]|[Ẁ-ẇ]|[Ẍ-ẗ]|ẞ|[Ạ-ỹ]|’|‡|€|A̋|C(̀|̄|̆|̈|̕|̣|̦|̨̆)|D̂|F(̀|̄)|G̀|H(̄|̦|̱)|J(́|̌)|K(̀|̂|̄|̇|̕|̛|̦|͟H|͟h)|L(̂|̥|̥̄|̦)|M(̀|̂|̆|̐)|N(̂|̄|̆|̦)|P(̀|̄|̕|̣)|R(̆|̥|̥̄)|S(̀|̄|̛̄|̱)|T(̀|̄|̈|̕|̛)|U̇|Z(̀|̄|̆|̈|̧)|a̋|c(̀|̄|̆|̈|̕|̣|̦|̨̆)|d̂|f(̀|̄)|g̀|h(̄|̦)|j́|k(̀|̂|̄|̇|̕|̛|̦|͟h)|l(̂|̥|̥̄|̦)|m(̀|̂|̆|̐)|n(̂|̄|̆|̦)|p(̀|̄|̕|̣)|r(̆|̥|̥̄)|s(̀|̄|̛̄|̱)|t(̀|̄|̕|̛)|u̇|z(̀|̄|̆|̈|̧)|Ç̆|Û̄|ç̆|û̄|ÿ́|Č(̕|̣)|č(̕|̣)|ē̍|Ī́|ī́|ō̍|Ž(̦|̧)|ž(̦|̧)|Ḳ̄|ḳ̄|Ṣ̄|ṣ̄|Ṭ̄|ṭ̄|Ạ̈|ạ̈|Ọ̈|ọ̈|Ụ(̄|̈)|ụ(̄|̈))*$/"; + } + + return undefined; +} diff --git a/packages/content/src/attributes/hints/ValueHintsValue.ts b/packages/content/src/attributes/hints/ValueHintsValue.ts index 83522ad19..8e9d5e36e 100644 --- a/packages/content/src/attributes/hints/ValueHintsValue.ts +++ b/packages/content/src/attributes/hints/ValueHintsValue.ts @@ -1,4 +1,5 @@ import { ISerializable, PrimitiveType, Serializable, serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../constants/CharacterSets"; export interface ValueHintsValueJSON { key: string | number | boolean; @@ -13,7 +14,7 @@ export interface IValueHintsValue extends ISerializable { @type("ValueHintsValue") export class ValueHintsValue extends Serializable implements IValueHintsValue { @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeC }) public displayName: string; @validate({ @@ -28,8 +29,11 @@ export class ValueHintsValue extends Serializable implements IValueHintsValue { } private static validateKey(key: string | number | boolean) { - if (typeof key === "string" && key.length > 100) { - return "The maximum length of a key is 200 characters."; + if (typeof key === "string") { + if (key.length > 100) return "The maximum length of a key is 100 characters."; + if (!characterSets.din91379DatatypeC.test(key)) { + return "Value does not match regular expression /^([\\u0009-\\u000A]|\\u000D|[ -~]|[ -¬]|[®-ž]|[Ƈ-ƈ]|Ə|Ɨ|[Ơ-ơ]|[Ư-ư]|Ʒ|[Ǎ-ǜ]|[Ǟ-ǟ]|[Ǣ-ǰ]|[Ǵ-ǵ]|[Ǹ-ǿ]|[Ȓ-ȓ]|[Ș-ț]|[Ȟ-ȟ]|[ȧ-ȳ]|ə|ɨ|ʒ|[ʹ-ʺ]|[ʾ-ʿ]|ˈ|ˌ|[Ḃ-ḃ]|[Ḇ-ḇ]|[Ḋ-ḑ]|ḗ|[Ḝ-ḫ]|[ḯ-ḷ]|[Ḻ-ḻ]|[Ṁ-ṉ]|[Ṓ-ṛ]|[Ṟ-ṣ]|[Ṫ-ṯ]|[Ẁ-ẇ]|[Ẍ-ẗ]|ẞ|[Ạ-ỹ]|’|‡|€|A̋|C(̀|̄|̆|̈|̕|̣|̦|̨̆)|D̂|F(̀|̄)|G̀|H(̄|̦|̱)|J(́|̌)|K(̀|̂|̄|̇|̕|̛|̦|͟H|͟h)|L(̂|̥|̥̄|̦)|M(̀|̂|̆|̐)|N(̂|̄|̆|̦)|P(̀|̄|̕|̣)|R(̆|̥|̥̄)|S(̀|̄|̛̄|̱)|T(̀|̄|̈|̕|̛)|U̇|Z(̀|̄|̆|̈|̧)|a̋|c(̀|̄|̆|̈|̕|̣|̦|̨̆)|d̂|f(̀|̄)|g̀|h(̄|̦)|j́|k(̀|̂|̄|̇|̕|̛|̦|͟h)|l(̂|̥|̥̄|̦)|m(̀|̂|̆|̐)|n(̂|̄|̆|̦)|p(̀|̄|̕|̣)|r(̆|̥|̥̄)|s(̀|̄|̛̄|̱)|t(̀|̄|̕|̛)|u̇|z(̀|̄|̆|̈|̧)|Ç̆|Û̄|ç̆|û̄|ÿ́|Č(̕|̣)|č(̕|̣)|ē̍|Ī́|ī́|ō̍|Ž(̦|̧)|ž(̦|̧)|Ḳ̄|ḳ̄|Ṣ̄|ṣ̄|Ṭ̄|ṭ̄|Ạ̈|ạ̈|Ọ̈|ọ̈|Ụ(̄|̈)|ụ(̄|̈))*$/"; + } } return undefined; diff --git a/packages/content/src/attributes/types/AbstractString.ts b/packages/content/src/attributes/types/AbstractString.ts index 0eed500e9..de9687750 100644 --- a/packages/content/src/attributes/types/AbstractString.ts +++ b/packages/content/src/attributes/types/AbstractString.ts @@ -1,5 +1,6 @@ import { serialize, validate } from "@js-soft/ts-serval"; import { AbstractAttributeValue, AbstractAttributeValueJSON, IAbstractAttributeValue } from "../AbstractAttributeValue"; +import { characterSets } from "../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../hints"; export interface AbstractStringJSON extends AbstractAttributeValueJSON { @@ -12,7 +13,7 @@ export interface IAbstractString extends IAbstractAttributeValue { export class AbstractString extends AbstractAttributeValue implements IAbstractString { @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeC }) public value: string; public static override preFrom(value: any): any { @@ -26,7 +27,8 @@ export class AbstractString extends AbstractAttributeValue implements IAbstractS public static get valueHints(): ValueHints { return ValueHints.from({ - max: 100 + max: 100, + pattern: characterSets.din91379DatatypeC.toString().slice(1, -1).replaceAll("/", "\\/") }); } diff --git a/packages/content/src/attributes/types/address/AbstractAddress.ts b/packages/content/src/attributes/types/address/AbstractAddress.ts index 1fd7509e2..57672f8d4 100644 --- a/packages/content/src/attributes/types/address/AbstractAddress.ts +++ b/packages/content/src/attributes/types/address/AbstractAddress.ts @@ -1,6 +1,7 @@ import { serialize, validate } from "@js-soft/ts-serval"; import { nameof } from "ts-simple-nameof"; import { AbstractComplexValue, AbstractComplexValueJSON, IAbstractComplexValue } from "../../AbstractComplexValue"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../../hints"; export interface AbstractAddressJSON extends AbstractComplexValueJSON { @@ -13,13 +14,15 @@ export interface IAbstractAddress extends IAbstractComplexValue { export abstract class AbstractAddress extends AbstractComplexValue implements IAbstractAddress { @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeB }) public recipient: string; public static get valueHints(): ValueHints { return ValueHints.from({ propertyHints: { - [nameof((a) => a.recipient)]: ValueHints.from({}) + [nameof((a) => a.recipient)]: ValueHints.from({ + pattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") + }) } }); } diff --git a/packages/content/src/attributes/types/address/City.ts b/packages/content/src/attributes/types/address/City.ts index 524c85144..5f3ab5b84 100644 --- a/packages/content/src/attributes/types/address/City.ts +++ b/packages/content/src/attributes/types/address/City.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface CityJSON extends AbstractStringJSON { "@type": "City"; @@ -8,7 +9,7 @@ export interface CityJSON extends AbstractStringJSON { export interface ICity extends IAbstractString {} @type("City") -export class City extends AbstractString implements ICity { +export class City extends AbstractName implements ICity { public static from(value: ICity | Omit | string): City { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/address/DeliveryBoxAddress.ts b/packages/content/src/attributes/types/address/DeliveryBoxAddress.ts index 8571d0368..02d097b58 100644 --- a/packages/content/src/attributes/types/address/DeliveryBoxAddress.ts +++ b/packages/content/src/attributes/types/address/DeliveryBoxAddress.ts @@ -2,6 +2,7 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; import { nameof } from "ts-simple-nameof"; import { AbstractAttributeValue } from "../../AbstractAttributeValue"; import { COUNTRIES_ALPHA2_TO_ENGLISH_NAME } from "../../constants"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../../hints"; import { IPhoneNumber, PhoneNumber } from "../communication"; import { AbstractAddress, AbstractAddressJSON, IAbstractAddress } from "./AbstractAddress"; @@ -34,11 +35,11 @@ export interface IDeliveryBoxAddress extends IAbstractAddress { @type("DeliveryBoxAddress") export class DeliveryBoxAddress extends AbstractAddress implements IDeliveryBoxAddress { @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeB }) public userId: string; @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeB }) public deliveryBoxId: string; @serialize({ customGenerator: AbstractAttributeValue.valueGenerator }) @@ -64,8 +65,8 @@ export class DeliveryBoxAddress extends AbstractAddress implements IDeliveryBoxA public static override get valueHints(): ValueHints { return super.valueHints.copyWith({ propertyHints: { - [nameof((d) => d.userId)]: ValueHints.from({}), - [nameof((d) => d.deliveryBoxId)]: ValueHints.from({}), + [nameof((d) => d.userId)]: ValueHints.from({ pattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") }), + [nameof((d) => d.deliveryBoxId)]: ValueHints.from({ pattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") }), [nameof((d) => d.zipCode)]: ZipCode.valueHints, [nameof((d) => d.city)]: City.valueHints, [nameof((d) => d.country)]: Country.valueHints, diff --git a/packages/content/src/attributes/types/address/HouseNumber.ts b/packages/content/src/attributes/types/address/HouseNumber.ts index fd8d7e02c..5d600ef59 100644 --- a/packages/content/src/attributes/types/address/HouseNumber.ts +++ b/packages/content/src/attributes/types/address/HouseNumber.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface HouseNumberJSON extends AbstractStringJSON { "@type": "HouseNumber"; @@ -8,7 +9,7 @@ export interface HouseNumberJSON extends AbstractStringJSON { export interface IHouseNumber extends IAbstractString {} @type("HouseNumber") -export class HouseNumber extends AbstractString implements IHouseNumber { +export class HouseNumber extends AbstractName implements IHouseNumber { public static from(value: IHouseNumber | Omit | string): HouseNumber { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/address/PostOfficeBoxAddress.ts b/packages/content/src/attributes/types/address/PostOfficeBoxAddress.ts index 465987fed..bd5227ae8 100644 --- a/packages/content/src/attributes/types/address/PostOfficeBoxAddress.ts +++ b/packages/content/src/attributes/types/address/PostOfficeBoxAddress.ts @@ -2,6 +2,7 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; import { nameof } from "ts-simple-nameof"; import { AbstractAttributeValue } from "../../AbstractAttributeValue"; import { COUNTRIES_ALPHA2_TO_ENGLISH_NAME } from "../../constants"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../../hints"; import { AbstractAddress, AbstractAddressJSON, IAbstractAddress } from "./AbstractAddress"; import { City, ICity } from "./City"; @@ -29,7 +30,7 @@ export interface IPostOfficeBoxAddress extends IAbstractAddress { @type("PostOfficeBoxAddress") export class PostOfficeBoxAddress extends AbstractAddress implements IPostOfficeBoxAddress { @serialize() - @validate({ max: 100 }) + @validate({ max: 100, regExp: characterSets.din91379DatatypeB }) public boxId: string; @serialize({ customGenerator: AbstractAttributeValue.valueGenerator }) @@ -51,7 +52,7 @@ export class PostOfficeBoxAddress extends AbstractAddress implements IPostOffice public static override get valueHints(): ValueHints { return super.valueHints.copyWith({ propertyHints: { - [nameof((p) => p.boxId)]: ValueHints.from({}), + [nameof((p) => p.boxId)]: ValueHints.from({ pattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") }), [nameof((p) => p.zipCode)]: ZipCode.valueHints, [nameof((p) => p.city)]: City.valueHints, [nameof((p) => p.country)]: Country.valueHints, diff --git a/packages/content/src/attributes/types/address/State.ts b/packages/content/src/attributes/types/address/State.ts index ed79d8590..c24da977e 100644 --- a/packages/content/src/attributes/types/address/State.ts +++ b/packages/content/src/attributes/types/address/State.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface StateJSON extends AbstractStringJSON { "@type": "State"; @@ -8,7 +9,7 @@ export interface StateJSON extends AbstractStringJSON { export interface IState extends IAbstractString {} @type("State") -export class State extends AbstractString implements IState { +export class State extends AbstractName implements IState { public static from(value: IState | Omit | string): State { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/address/Street.ts b/packages/content/src/attributes/types/address/Street.ts index 2e093c8a6..117784540 100644 --- a/packages/content/src/attributes/types/address/Street.ts +++ b/packages/content/src/attributes/types/address/Street.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface StreetJSON extends AbstractStringJSON { "@type": "Street"; @@ -8,7 +9,7 @@ export interface StreetJSON extends AbstractStringJSON { export interface IStreet extends IAbstractString {} @type("Street") -export class Street extends AbstractString implements IStreet { +export class Street extends AbstractName implements IStreet { public static from(value: IStreet | Omit | string): Street { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/address/ZipCode.ts b/packages/content/src/attributes/types/address/ZipCode.ts index 1a4f1e1a7..6cd79c638 100644 --- a/packages/content/src/attributes/types/address/ZipCode.ts +++ b/packages/content/src/attributes/types/address/ZipCode.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface ZipCodeJSON extends AbstractStringJSON { "@type": "ZipCode"; @@ -8,7 +9,7 @@ export interface ZipCodeJSON extends AbstractStringJSON { export interface IZipCode extends IAbstractString {} @type("ZipCode") -export class ZipCode extends AbstractString implements IZipCode { +export class ZipCode extends AbstractName implements IZipCode { public static from(value: IZipCode | Omit | string): ZipCode { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/affiliation/AffiliationOrganization.ts b/packages/content/src/attributes/types/affiliation/AffiliationOrganization.ts index bff5ed0fe..8838b6da1 100644 --- a/packages/content/src/attributes/types/affiliation/AffiliationOrganization.ts +++ b/packages/content/src/attributes/types/affiliation/AffiliationOrganization.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface AffiliationOrganizationJSON extends AbstractStringJSON { "@type": "AffiliationOrganization"; @@ -8,7 +9,7 @@ export interface AffiliationOrganizationJSON extends AbstractStringJSON { export interface IAffiliationOrganization extends IAbstractString {} @type("AffiliationOrganization") -export class AffiliationOrganization extends AbstractString implements IAffiliationOrganization { +export class AffiliationOrganization extends AbstractName implements IAffiliationOrganization { public static from(value: IAffiliationOrganization | Omit | string): AffiliationOrganization { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/identity/DisplayName.ts b/packages/content/src/attributes/types/identity/DisplayName.ts index 9cd43e84d..5505a1ddc 100644 --- a/packages/content/src/attributes/types/identity/DisplayName.ts +++ b/packages/content/src/attributes/types/identity/DisplayName.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface DisplayNameJSON extends AbstractStringJSON { "@type": "DisplayName"; @@ -8,7 +9,7 @@ export interface DisplayNameJSON extends AbstractStringJSON { export interface IDisplayName extends IAbstractString {} @type("DisplayName") -export class DisplayName extends AbstractString implements IDisplayName { +export class DisplayName extends AbstractName implements IDisplayName { public static from(value: IDisplayName | Omit | string): DisplayName { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/BirthName.ts b/packages/content/src/attributes/types/name/BirthName.ts index a5deec4d0..657e20ba1 100644 --- a/packages/content/src/attributes/types/name/BirthName.ts +++ b/packages/content/src/attributes/types/name/BirthName.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface BirthNameJSON extends AbstractStringJSON { "@type": "BirthName"; @@ -8,7 +9,7 @@ export interface BirthNameJSON extends AbstractStringJSON { export interface IBirthName extends IAbstractString {} @type("BirthName") -export class BirthName extends AbstractString implements IBirthName { +export class BirthName extends AbstractNaturalPersonName implements IBirthName { public static from(value: IBirthName | Omit | string): BirthName { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/GivenName.ts b/packages/content/src/attributes/types/name/GivenName.ts index 1615ee185..1e6e324c7 100644 --- a/packages/content/src/attributes/types/name/GivenName.ts +++ b/packages/content/src/attributes/types/name/GivenName.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface GivenNameJSON extends AbstractStringJSON { "@type": "GivenName"; @@ -8,7 +9,7 @@ export interface GivenNameJSON extends AbstractStringJSON { export interface IGivenName extends IAbstractString {} @type("GivenName") -export class GivenName extends AbstractString implements IGivenName { +export class GivenName extends AbstractNaturalPersonName implements IGivenName { public static from(value: IGivenName | Omit | string): GivenName { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/HonorificPrefix.ts b/packages/content/src/attributes/types/name/HonorificPrefix.ts index a962c80ef..a76cc2008 100644 --- a/packages/content/src/attributes/types/name/HonorificPrefix.ts +++ b/packages/content/src/attributes/types/name/HonorificPrefix.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface HonorificPrefixJSON extends AbstractStringJSON { "@type": "HonorificPrefix"; @@ -8,7 +9,7 @@ export interface HonorificPrefixJSON extends AbstractStringJSON { export interface IHonorificPrefix extends IAbstractString {} @type("HonorificPrefix") -export class HonorificPrefix extends AbstractString implements HonorificPrefix { +export class HonorificPrefix extends AbstractNaturalPersonName implements HonorificPrefix { public static from(value: HonorificPrefix | Omit | string): HonorificPrefix { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/HonorificSuffix.ts b/packages/content/src/attributes/types/name/HonorificSuffix.ts index 765f3070c..2681a6f38 100644 --- a/packages/content/src/attributes/types/name/HonorificSuffix.ts +++ b/packages/content/src/attributes/types/name/HonorificSuffix.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface HonorificSuffixJSON extends AbstractStringJSON { "@type": "HonorificSuffix"; @@ -8,7 +9,7 @@ export interface HonorificSuffixJSON extends AbstractStringJSON { export interface IHonorificSuffix extends IAbstractString {} @type("HonorificSuffix") -export class HonorificSuffix extends AbstractString implements IHonorificSuffix { +export class HonorificSuffix extends AbstractNaturalPersonName implements IHonorificSuffix { public static from(value: IHonorificSuffix | Omit | string): HonorificSuffix { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/MiddleName.ts b/packages/content/src/attributes/types/name/MiddleName.ts index 1359834f2..97df32da3 100644 --- a/packages/content/src/attributes/types/name/MiddleName.ts +++ b/packages/content/src/attributes/types/name/MiddleName.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface MiddleNameJSON extends AbstractStringJSON { "@type": "MiddleName"; @@ -8,7 +9,7 @@ export interface MiddleNameJSON extends AbstractStringJSON { export interface IMiddleName extends IAbstractString {} @type("MiddleName") -export class MiddleName extends AbstractString implements IMiddleName { +export class MiddleName extends AbstractNaturalPersonName implements IMiddleName { public static from(value: IMiddleName | Omit | string): MiddleName { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/Pseudonym.ts b/packages/content/src/attributes/types/name/Pseudonym.ts index c0ea1a1b9..4cba661f2 100644 --- a/packages/content/src/attributes/types/name/Pseudonym.ts +++ b/packages/content/src/attributes/types/name/Pseudonym.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface PseudonymJSON extends AbstractStringJSON { "@type": "Pseudonym"; @@ -8,7 +9,7 @@ export interface PseudonymJSON extends AbstractStringJSON { export interface IPseudonym extends IAbstractString {} @type("Pseudonym") -export class Pseudonym extends AbstractString implements IPseudonym { +export class Pseudonym extends AbstractNaturalPersonName implements IPseudonym { public static from(value: IPseudonym | Omit | string): Pseudonym { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/name/Surname.ts b/packages/content/src/attributes/types/name/Surname.ts index 27e850aeb..2b27a664c 100644 --- a/packages/content/src/attributes/types/name/Surname.ts +++ b/packages/content/src/attributes/types/name/Surname.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractNaturalPersonName } from "../strings/AbstractNaturalPersonName"; export interface SurnameJSON extends AbstractStringJSON { "@type": "Surname"; @@ -8,7 +9,7 @@ export interface SurnameJSON extends AbstractStringJSON { export interface ISurname extends IAbstractString {} @type("Surname") -export class Surname extends AbstractString implements ISurname { +export class Surname extends AbstractNaturalPersonName implements ISurname { public static from(value: ISurname | Omit | string): Surname { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/person/JobTitle.ts b/packages/content/src/attributes/types/person/JobTitle.ts index f9c8067ea..a4cad9b81 100644 --- a/packages/content/src/attributes/types/person/JobTitle.ts +++ b/packages/content/src/attributes/types/person/JobTitle.ts @@ -1,5 +1,6 @@ import { type } from "@js-soft/ts-serval"; -import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractStringJSON, IAbstractString } from "../AbstractString"; +import { AbstractName } from "../strings/AbstractName"; export interface JobTitleJSON extends AbstractStringJSON { "@type": "JobTitle"; @@ -8,7 +9,7 @@ export interface JobTitleJSON extends AbstractStringJSON { export interface IJobTitle extends IAbstractString {} @type("JobTitle") -export class JobTitle extends AbstractString implements IJobTitle { +export class JobTitle extends AbstractName implements IJobTitle { public static from(value: IJobTitle | Omit | string): JobTitle { return this.fromAny(value); } diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryBoolean.ts b/packages/content/src/attributes/types/proprietary/ProprietaryBoolean.ts index bbc1d00f9..ac5c36448 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryBoolean.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryBoolean.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractBoolean, AbstractBooleanJSON, IAbstractBoolean } from "../AbstractBoolean"; import { @@ -17,11 +18,11 @@ export interface IProprietaryBoolean extends IProprietaryAttributeValue, IAbstra @type("ProprietaryBoolean") export class ProprietaryBoolean extends AbstractBoolean { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryCountry.ts b/packages/content/src/attributes/types/proprietary/ProprietaryCountry.ts index bcda1cb67..b0cce814c 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryCountry.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryCountry.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractCountry } from "../strings/AbstractCountry"; @@ -18,11 +19,11 @@ export interface IProprietaryCountry extends IProprietaryAttributeValue, IAbstra @type("ProprietaryCountry") export class ProprietaryCountry extends AbstractCountry { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryEMailAddress.ts b/packages/content/src/attributes/types/proprietary/ProprietaryEMailAddress.ts index f4fafde6d..18963a1d1 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryEMailAddress.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryEMailAddress.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractEMailAddress } from "../strings/AbstractEMailAddress"; @@ -18,11 +19,11 @@ export interface IProprietaryEMailAddress extends IProprietaryAttributeValue, IA @type("ProprietaryEMailAddress") export class ProprietaryEMailAddress extends AbstractEMailAddress { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryFileReference.ts b/packages/content/src/attributes/types/proprietary/ProprietaryFileReference.ts index f36f3bbba..e60eac452 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryFileReference.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryFileReference.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractFileReference } from "../strings"; @@ -18,11 +19,11 @@ export interface IProprietaryFileReference extends IProprietaryAttributeValue, I @type("ProprietaryFileReference") export class ProprietaryFileReference extends AbstractFileReference { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryFloat.ts b/packages/content/src/attributes/types/proprietary/ProprietaryFloat.ts index d4dde88d5..2ae549383 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryFloat.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryFloat.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractFloat, AbstractFloatJSON, IAbstractFloat } from "../AbstractFloat"; import { @@ -17,11 +18,11 @@ export interface IProprietaryFloat extends IProprietaryAttributeValue, IAbstract @type("ProprietaryFloat") export class ProprietaryFloat extends AbstractFloat { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryHEXColor.ts b/packages/content/src/attributes/types/proprietary/ProprietaryHEXColor.ts index 6b4be289d..675b8950a 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryHEXColor.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryHEXColor.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractHEXColor } from "../strings/AbstractHEXColor"; @@ -18,11 +19,11 @@ export interface IProprietaryHEXColor extends IProprietaryAttributeValue, IAbstr @type("ProprietaryHEXColor") export class ProprietaryHEXColor extends AbstractHEXColor { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryInteger.ts b/packages/content/src/attributes/types/proprietary/ProprietaryInteger.ts index 8f238f330..4ec3696d6 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryInteger.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryInteger.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractInteger, AbstractIntegerJSON, IAbstractInteger } from "../AbstractInteger"; import { @@ -17,11 +18,11 @@ export interface IProprietaryInteger extends IProprietaryAttributeValue, IAbstra @type("ProprietaryInteger") export class ProprietaryInteger extends AbstractInteger implements IProprietaryInteger { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryJSON.ts b/packages/content/src/attributes/types/proprietary/ProprietaryJSON.ts index db2bdaaea..58bf2c97a 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryJSON.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryJSON.ts @@ -1,5 +1,6 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; import { AbstractAttributeValue, AbstractAttributeValueJSON, IAbstractAttributeValue } from "../../AbstractAttributeValue"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../../hints"; import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH } from "./ProprietaryAttributeValue"; @@ -19,11 +20,11 @@ export interface IProprietaryJSON extends IAbstractAttributeValue { @type("ProprietaryJSON") export class ProprietaryJSON extends AbstractAttributeValue { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize({ any: true }) diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryLanguage.ts b/packages/content/src/attributes/types/proprietary/ProprietaryLanguage.ts index c8878d662..5b0f5af87 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryLanguage.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryLanguage.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractLanguage } from "../strings/AbstractLanguage"; @@ -18,11 +19,11 @@ export interface IProprietaryLanguage extends IProprietaryAttributeValue, IAbstr @type("ProprietaryLanguage") export class ProprietaryLanguage extends AbstractLanguage { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryPhoneNumber.ts b/packages/content/src/attributes/types/proprietary/ProprietaryPhoneNumber.ts index a4a9d02d0..ae9f843b1 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryPhoneNumber.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryPhoneNumber.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractPhoneNumber } from "../strings/AbstractPhoneNumber"; @@ -18,11 +19,11 @@ export interface IProprietaryPhoneNumber extends IProprietaryAttributeValue, IAb @type("ProprietaryPhoneNumber") export class ProprietaryPhoneNumber extends AbstractPhoneNumber { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryString.ts b/packages/content/src/attributes/types/proprietary/ProprietaryString.ts index 69c1d358a..e7e20372b 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryString.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryString.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; import { @@ -17,11 +18,11 @@ export interface IProprietaryString extends IProprietaryAttributeValue, IAbstrac @type("ProprietaryString") export class ProprietaryString extends AbstractString { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryURL.ts b/packages/content/src/attributes/types/proprietary/ProprietaryURL.ts index 58e6f8d69..52dd5bccb 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryURL.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryURL.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractURL } from "../strings/AbstractURL"; @@ -18,11 +19,11 @@ export interface IProprietaryURL extends IProprietaryAttributeValue, IAbstractSt @type("ProprietaryURL") export class ProprietaryURL extends AbstractURL { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/proprietary/ProprietaryXML.ts b/packages/content/src/attributes/types/proprietary/ProprietaryXML.ts index 9eb59d4e9..a4dcb516c 100644 --- a/packages/content/src/attributes/types/proprietary/ProprietaryXML.ts +++ b/packages/content/src/attributes/types/proprietary/ProprietaryXML.ts @@ -1,4 +1,5 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { ValueHints, ValueHintsOverride } from "../../hints"; import { AbstractStringJSON, IAbstractString } from "../AbstractString"; import { AbstractXML } from "../strings/AbstractXML"; @@ -21,11 +22,11 @@ export interface IProprietaryXML extends IProprietaryAttributeValue, IAbstractSt @type("ProprietaryXML") export class ProprietaryXML extends AbstractXML { @serialize() - @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH }) + @validate({ max: PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH, regExp: characterSets.din91379DatatypeC }) public title: string; @serialize() - @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH }) + @validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, regExp: characterSets.din91379DatatypeC }) public description?: string; @serialize() diff --git a/packages/content/src/attributes/types/relationship/Consent.ts b/packages/content/src/attributes/types/relationship/Consent.ts index 6f9a6b2b6..fee1de11b 100644 --- a/packages/content/src/attributes/types/relationship/Consent.ts +++ b/packages/content/src/attributes/types/relationship/Consent.ts @@ -1,5 +1,6 @@ import { serialize, type, validate } from "@js-soft/ts-serval"; import { AbstractAttributeValue, AbstractAttributeValueJSON, IAbstractAttributeValue } from "../../AbstractAttributeValue"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsDataType, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../../hints"; export interface ConsentJSON extends AbstractAttributeValueJSON { @@ -15,7 +16,7 @@ export interface IConsent extends IAbstractAttributeValue { @type("Consent") export class Consent extends AbstractAttributeValue implements IConsent { @serialize() - @validate({ max: 2000 }) + @validate({ max: 2000, regExp: characterSets.din91379DatatypeC }) public consent: string; @serialize() @@ -41,7 +42,10 @@ export class Consent extends AbstractAttributeValue implements IConsent { public static get valueHints(): ValueHints { return ValueHints.from({ propertyHints: { - consent: { max: 2000 }, + consent: { + max: 2000, + pattern: characterSets.din91379DatatypeC.toString().slice(1, -1).replaceAll("/", "\\/") + }, link: { min: 3, max: 1024 diff --git a/packages/content/src/attributes/types/statement/StatementPredicate.ts b/packages/content/src/attributes/types/statement/StatementPredicate.ts index 64aba47d8..d4e9b031b 100644 --- a/packages/content/src/attributes/types/statement/StatementPredicate.ts +++ b/packages/content/src/attributes/types/statement/StatementPredicate.ts @@ -1,4 +1,5 @@ import { PrimitiveType, serialize, type, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; import { RenderHints, RenderHintsEditType, ValueHints, ValueHintsValue } from "../../hints"; import { AbstractString, AbstractStringJSON, IAbstractString } from "../AbstractString"; @@ -25,7 +26,8 @@ export class StatementPredicate extends AbstractString { @serialize() @validate({ customValidator: StatementPredicate.validatePredicate, - allowedTypes: [PrimitiveType.String] + allowedTypes: [PrimitiveType.String], + regExp: characterSets.din91379DatatypeC }) public override value: Predicates | `z-${string}`; diff --git a/packages/content/src/attributes/types/strings/AbstractName.ts b/packages/content/src/attributes/types/strings/AbstractName.ts new file mode 100644 index 000000000..f147c6f90 --- /dev/null +++ b/packages/content/src/attributes/types/strings/AbstractName.ts @@ -0,0 +1,20 @@ +import { serialize, validate } from "@js-soft/ts-serval"; +import { characterSets } from "../../constants/CharacterSets"; +import { ValueHints } from "../../hints"; +import { AbstractString } from "../AbstractString"; + +export abstract class AbstractName extends AbstractString { + @serialize() + @validate({ + max: 100, + regExp: characterSets.din91379DatatypeB + }) + public override value: string; + + public static override get valueHints(): ValueHints { + return super.valueHints.copyWith({ + max: 100, + pattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") + }); + } +} diff --git a/packages/content/src/attributes/types/strings/AbstractNaturalPersonName.ts b/packages/content/src/attributes/types/strings/AbstractNaturalPersonName.ts new file mode 100644 index 000000000..a20e38da0 --- /dev/null +++ b/packages/content/src/attributes/types/strings/AbstractNaturalPersonName.ts @@ -0,0 +1,20 @@ +import { serialize, validate } from "@js-soft/ts-serval"; +import { ValueHints } from "../../../attributes/hints"; +import { characterSets } from "../../constants/CharacterSets"; +import { AbstractString } from "../AbstractString"; + +export abstract class AbstractNaturalPersonName extends AbstractString { + @serialize() + @validate({ + max: 100, + regExp: characterSets.din91379DatatypeA + }) + public override value: string; + + public static override get valueHints(): ValueHints { + return super.valueHints.copyWith({ + max: 100, + pattern: characterSets.din91379DatatypeA.toString().slice(1, -1).replaceAll("/", "\\/") + }); + } +} diff --git a/packages/content/src/attributes/types/strings/AbstractXML.ts b/packages/content/src/attributes/types/strings/AbstractXML.ts index 4793d21c7..ebfd728f8 100644 --- a/packages/content/src/attributes/types/strings/AbstractXML.ts +++ b/packages/content/src/attributes/types/strings/AbstractXML.ts @@ -8,7 +8,7 @@ export abstract class AbstractXML extends AbstractString { public override value: string; public static override get valueHints(): ValueHints { - return ValueHints.from({ + return super.valueHints.copyWith({ max: 50000 }); } diff --git a/packages/content/test/attributeValues/NameValueTests.test.ts b/packages/content/test/attributeValues/NameValueTests.test.ts index 99e2c54bf..d016dc4e2 100644 --- a/packages/content/test/attributeValues/NameValueTests.test.ts +++ b/packages/content/test/attributeValues/NameValueTests.test.ts @@ -36,7 +36,7 @@ new GenericValueTest().runParametrized({ typeClass: PersonName, expectedJSON: { "@type": "PersonName", - givenName: "TestGivenName1 TestGivenName2", + givenName: "aTestGivenName anotherTestGivenName", middleName: "Middler", surname: "TestSurname", honorificPrefix: "Dr. Dr. rer. nat.", @@ -44,7 +44,7 @@ new GenericValueTest().runParametrized({ }, valueJSON: { "@type": "PersonName", - givenName: "TestGivenName1 TestGivenName2", + givenName: "aTestGivenName anotherTestGivenName", middleName: "Middler", surname: "TestSurname", honorificPrefix: "Dr. Dr. rer. nat.", @@ -54,7 +54,7 @@ new GenericValueTest().runParametrized({ "@type": "PersonName", givenName: { "@type": "GivenName", - value: "TestGivenName1 TestGivenName2" + value: "aTestGivenName anotherTestGivenName" }, middleName: { "@type": "MiddleName", @@ -74,11 +74,11 @@ new GenericValueTest().runParametrized({ } }, valueInterface: { - givenName: GivenName.fromAny("TestGivenName1 TestGivenName2"), + givenName: GivenName.fromAny("aTestGivenName anotherTestGivenName"), middleName: MiddleName.fromAny("Middler"), surname: Surname.fromAny("TestSurname"), honorificPrefix: HonorificPrefix.fromAny("Dr. Dr. rer. nat."), honorificSuffix: HonorificSuffix.fromAny("M.Sc.") }, - valueString: "Dr. Dr. rer. nat. TestGivenName1 TestGivenName2 Middler TestSurname M.Sc." + valueString: "Dr. Dr. rer. nat. aTestGivenName anotherTestGivenName Middler TestSurname M.Sc." }); diff --git a/packages/content/test/attributes/CharacterSets.test.ts b/packages/content/test/attributes/CharacterSets.test.ts new file mode 100644 index 000000000..64e3983e4 --- /dev/null +++ b/packages/content/test/attributes/CharacterSets.test.ts @@ -0,0 +1,299 @@ +import { ParsingError, Serializable } from "@js-soft/ts-serval"; +import { + Consent, + DeliveryBoxAddress, + IDeliveryBoxAddress, + IPostOfficeBoxAddress, + PostOfficeBoxAddress, + ProprietaryString, + RelationshipAttribute, + RelationshipAttributeConfidentiality, + RelationshipAttributeQuery, + ThirdPartyRelationshipAttributeQuery, + ValueHintsValue +} from "../../src"; +import { characterSets } from "../../src/attributes/constants/CharacterSets"; + +const errorMessageDatatypeA = `Value does not match regular expression ${characterSets.din91379DatatypeA.toString()}`; +const errorMessageDatatypeB = `Value does not match regular expression ${characterSets.din91379DatatypeB.toString()}`; +const errorMessageDatatypeC = `Value does not match regular expression ${characterSets.din91379DatatypeC.toString()}`; + +test("Consent is considered as valid", () => { + const consent = Consent.from({ consent: "z-validValue\u000D¾£()," }); + expect(consent.consent.toString()).toBe("z-validValue\u000D¾£(),"); +}); + +test("Consent is considered as invalid", () => { + const invalidCall = () => { + Consent.from({ + consent: "invalidValue\u0012" + }); + }; + expect(invalidCall).toThrow(new ParsingError("Consent", "consent", errorMessageDatatypeC)); +}); + +const correctDeliveryBoxAddress: IDeliveryBoxAddress = { + city: "aCity", + country: "DE", + deliveryBoxId: "aBoxId~0", + recipient: "aRecipient@7", + userId: "aUserId<6", + zipCode: "aZipCode" +}; + +test("DeliveryBoxAddress is considered as valid", () => { + const deliveryBoxAddress = DeliveryBoxAddress.from(correctDeliveryBoxAddress); + expect(deliveryBoxAddress.valueHints.propertyHints.deliveryBoxId.pattern).toBe(characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/")); + expect(deliveryBoxAddress.valueHints.propertyHints.recipient.pattern).toBe(characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/")); + expect(deliveryBoxAddress.valueHints.propertyHints.userId.pattern).toBe(characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/")); +}); + +test.each(["recipient", "userId", "deliveryBoxId"])("%s of DeliveryBoxAddress is considered as invalid", (propertyName) => { + const invalidCall = () => { + DeliveryBoxAddress.from({ + ...correctDeliveryBoxAddress, + [propertyName]: "invalidValue≥" + }); + }; + + expect(invalidCall).toThrow(new ParsingError("DeliveryBoxAddress", propertyName, errorMessageDatatypeB)); +}); + +const correctPostOfficeBoxAddress: IPostOfficeBoxAddress = { + city: "aCity", + country: "DE", + boxId: "aBoxId#", + recipient: "aRecipient_", + zipCode: "aZipCode" +}; + +test("PostOfficeBoxAddress is considered as valid", () => { + const postOfficeBoxAddress = PostOfficeBoxAddress.from(correctPostOfficeBoxAddress); + expect(postOfficeBoxAddress.valueHints.propertyHints.boxId.pattern).toBe(characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/")); + expect(postOfficeBoxAddress.valueHints.propertyHints.recipient.pattern).toBe(characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/")); +}); + +test.each(["boxId", "recipient"])("%s of PostOfficeBoxAddress is considered as invalid", (propertyName) => { + const invalidCall = () => { + PostOfficeBoxAddress.from({ + ...correctPostOfficeBoxAddress, + [propertyName]: "invalidValue≤" + }); + }; + expect(invalidCall).toThrow(new ParsingError("PostOfficeBoxAddress", propertyName, errorMessageDatatypeB)); +}); + +const restrictedIdentityAttributeTypesA = ["BirthName", "GivenName", "HonorificPrefix", "HonorificSuffix", "MiddleName", "Pseudonym", "Surname"]; +const restrictedIdentityAttributeTypesB = ["City", "HouseNumber", "State", "Street", "ZipCode", "AffiliationOrganization", "DisplayName", "JobTitle"]; +const restrictedIdentityAttributeTypesC = ["AffiliationRole", "AffiliationUnit", "StatementPredicate"]; + +const identityAttributeTestParameters = restrictedIdentityAttributeTypesA + .map((type) => ({ + type, + positiveTestValue: "validValueÄĞǼẌ ", + negativeTestValue: "invalidValue€", + errorMessage: errorMessageDatatypeA, + valueHintsPattern: characterSets.din91379DatatypeA.toString().slice(1, -1).replaceAll("/", "\\/") + })) + .concat( + restrictedIdentityAttributeTypesB.map((type) => ({ + type, + positiveTestValue: "validValueµẄ€k͟hŽ̧", + negativeTestValue: "z-invalidValue\u000D", + errorMessage: errorMessageDatatypeB, + valueHintsPattern: characterSets.din91379DatatypeB.toString().slice(1, -1).replaceAll("/", "\\/") + })) + ) + .concat( + restrictedIdentityAttributeTypesC.map((type) => ({ + type, + positiveTestValue: "z-validValue\u000D¾£(),", + negativeTestValue: "invalidValue\u0012", + errorMessage: errorMessageDatatypeC, + valueHintsPattern: characterSets.din91379DatatypeC.toString().slice(1, -1).replaceAll("/", "\\/") + })) + ); + +test.each(identityAttributeTestParameters)("$type is considered as valid", ({ type, positiveTestValue, valueHintsPattern }) => { + const attribute = Serializable.fromUnknown({ "@type": type, value: positiveTestValue }) as any; + expect(attribute.value).toBe(positiveTestValue); + expect(attribute.valueHints.pattern).toBe(valueHintsPattern); +}); + +test.each(identityAttributeTestParameters)("$type is considered as invalid", ({ type, negativeTestValue, errorMessage }) => { + const invalidCall = () => Serializable.fromUnknown({ "@type": type, value: negativeTestValue }); + expect(invalidCall).toThrow(new ParsingError(type, "value", errorMessage)); +}); + +test("value of ProprietaryString is considered as valid", () => { + const attribute = ProprietaryString.from({ value: "z-validValue\u000D¾£(),", title: "aTitle" }) as any; + expect(attribute.value).toBe("z-validValue\u000D¾£(),"); + expect(attribute.valueHints.pattern).toBe(characterSets.din91379DatatypeC.toString().slice(1, -1).replaceAll("/", "\\/")); +}); + +test("value of ProprietaryString is considered as invalid", () => { + const invalidCall = () => { + ProprietaryString.from({ value: "z-invalidValue\u0012", title: "aTitle" }); + }; + expect(invalidCall).toThrow(new ParsingError("ProprietaryString", "value", errorMessageDatatypeC)); +}); + +const proprietaryAttributeTestParameters = [ + { type: "ProprietaryBoolean", value: true }, + { type: "ProprietaryCountry", value: "DE" }, + { type: "ProprietaryEMailAddress", value: "email@email.de" }, + { type: "ProprietaryFileReference", value: "FIL123456789012345678901234567" }, + { type: "ProprietaryFloat", value: 1 }, + { type: "ProprietaryHEXColor", value: "#000000" }, + { type: "ProprietaryInteger", value: 1 }, + { type: "ProprietaryJSON", value: "aString" }, + { type: "ProprietaryLanguage", value: "de" }, + { type: "ProprietaryPhoneNumber", value: "1234567890" }, + { type: "ProprietaryString", value: "aString" }, + { type: "ProprietaryURL", value: "mail.de" }, + { type: "ProprietaryXML", value: "aString" }, + { type: "RelationshipAttributeCreationHints", valueType: "ProprietaryBoolean", confidentiality: RelationshipAttributeConfidentiality.Private } +]; + +test.each(proprietaryAttributeTestParameters)("title of $type is considered as valid", ({ type, value, valueType, confidentiality }) => { + const attribute = Serializable.fromUnknown({ "@type": type, value, valueType, confidentiality, title: "validValue\u000D¾£()," }); + expect((attribute as any).title).toBe("validValue\u000D¾£(),"); +}); + +test.each(proprietaryAttributeTestParameters)("title of $type is considered as invalid", ({ type, value, valueType, confidentiality }) => { + const invalidCall = () => { + Serializable.fromUnknown({ "@type": type, value, valueType, confidentiality, title: "invalidValueΩ" }); + }; + expect(invalidCall).toThrow(new ParsingError(type, "title", errorMessageDatatypeC)); +}); + +test.each(proprietaryAttributeTestParameters)("description of $type is considered as valid", ({ type, value, valueType, confidentiality }) => { + const attribute = Serializable.fromUnknown({ "@type": type, value, valueType, confidentiality, title: "aTitle", description: "validValue\u000D¾£()," }); + expect((attribute as any).description).toBe("validValue\u000D¾£(),"); +}); + +test.each(proprietaryAttributeTestParameters)("description of $type is considered as invalid", ({ type, value, valueType, confidentiality }) => { + const invalidCall = () => { + Serializable.fromUnknown({ "@type": type, value, valueType, confidentiality, title: "aTitle", description: "invalidValueΩ" }); + }; + expect(invalidCall).toThrow(new ParsingError(type, "description", errorMessageDatatypeC)); +}); + +test("key of RelationshipAttribute is considered as valid", () => { + const attribute = RelationshipAttribute.from({ + key: "validValue\u000D¾£(),", + confidentiality: RelationshipAttributeConfidentiality.Private, + value: { + "@type": "ProprietaryBoolean", + value: true, + title: "aTitle" + }, + "@type": "RelationshipAttribute", + owner: "theOwner" + }); + expect(attribute.key).toBe("validValue\u000D¾£(),"); +}); + +test("key of RelationshipAttribute is considered as invalid", () => { + const invalidCall = () => { + RelationshipAttribute.from({ + key: "invalidValueБ", + confidentiality: RelationshipAttributeConfidentiality.Private, + value: { + "@type": "ProprietaryBoolean", + value: true, + title: "aTitle" + }, + "@type": "RelationshipAttribute", + owner: "theOwner" + }); + }; + expect(invalidCall).toThrow(new ParsingError("RelationshipAttribute", "key", errorMessageDatatypeC)); +}); + +test("key of RelationshipAttributeQuery is considered as valid", () => { + const attribute = RelationshipAttributeQuery.from({ + owner: "theOwner", + attributeCreationHints: { confidentiality: RelationshipAttributeConfidentiality.Private, title: "aTitle", valueType: "ProprietaryBoolean" }, + key: "validValue\u000D¾£()," + }); + expect(attribute.key).toBe("validValue\u000D¾£(),"); +}); + +test("key of RelationshipAttributeQuery is considered as invalid", () => { + const invalidCall = () => { + RelationshipAttributeQuery.from({ + owner: "theOwner", + attributeCreationHints: { confidentiality: RelationshipAttributeConfidentiality.Private, title: "aTitle", valueType: "ProprietaryBoolean" }, + key: "invalidValueБ" + }); + }; + expect(invalidCall).toThrow(new ParsingError("RelationshipAttributeQuery", "key", errorMessageDatatypeC)); +}); + +test("key of ThirdPartyRelationshipAttributeQuery is considered as valid", () => { + const attribute = ThirdPartyRelationshipAttributeQuery.from({ + owner: "", + thirdParty: ["aThirdParty"], + key: "validValue\u000D¾£()," + }); + expect(attribute.key).toBe("validValue\u000D¾£(),"); +}); + +test("key of ThirdPartyRelationshipAttributeQuery is considered as invalid", () => { + const invalidCall = () => { + ThirdPartyRelationshipAttributeQuery.from({ + owner: "", + thirdParty: ["aThirdParty"], + key: "invalidValueБ" + }); + }; + expect(invalidCall).toThrow(new ParsingError("ThirdPartyRelationshipAttributeQuery", "key", errorMessageDatatypeC)); +}); + +describe.each(["ValueHints", "ValueHintsOverride"])("%s tests", (type) => { + test("is considered as valid", () => { + const validCall = () => { + Serializable.fromUnknown({ + "@type": type, + defaultValue: "validValue\u000D¾£(),", + editHelp: "validValue\u000D¾£(),", + values: [ + { + key: "validValue\u000D¾£(),", + displayName: "validValue\u000D¾£()," + } + ] + }); + }; + expect(validCall).not.toThrow(); + }); + + test("defaultValue is considered as invalid", () => { + const invalidCall = () => { + Serializable.fromUnknown({ "@type": type, defaultValue: "invalidValue™" }); + }; + expect(invalidCall).toThrow(new ParsingError(type, "defaultValue:Object", errorMessageDatatypeC)); + }); + + test("editHelp is considered as invalid", () => { + const invalidCall = () => { + Serializable.fromUnknown({ "@type": type, editHelp: "invalidValue™" }); + }; + expect(invalidCall).toThrow(new ParsingError(type, "editHelp", errorMessageDatatypeC)); + }); +}); + +test("key of ValueHintsValue is considered as invalid", () => { + const invalidCall = () => { + ValueHintsValue.from({ key: "invalidValue™", displayName: "aDisplayName" }); + }; + expect(invalidCall).toThrow(new ParsingError("ValueHintsValue", "key:Object", errorMessageDatatypeC)); +}); + +test("displayName of ValueHintsValue is considered as invalid", () => { + const invalidCall = () => { + ValueHintsValue.from({ key: "aKey", displayName: "invalidValue💩" }); + }; + expect(invalidCall).toThrow(new ParsingError("ValueHintsValue", "displayName", errorMessageDatatypeC)); +}); diff --git a/packages/runtime/test/consumption/attributes.test.ts b/packages/runtime/test/consumption/attributes.test.ts index 0c412a6c1..fd0a33498 100644 --- a/packages/runtime/test/consumption/attributes.test.ts +++ b/packages/runtime/test/consumption/attributes.test.ts @@ -1373,7 +1373,7 @@ describe(CreateRepositoryAttributeUseCase.name, () => { content: { value: { "@type": "GivenName", - value: "aGivenName2" + value: "anotherGivenName" }, tags: ["x+%+tag1", "x+%+tag2"] } @@ -1534,7 +1534,7 @@ describe(ShareRepositoryAttributeUseCase.name, () => { content: { value: { "@type": "Surname", - value: "Name 1" + value: "aSurname" } } }); @@ -1545,7 +1545,7 @@ describe(ShareRepositoryAttributeUseCase.name, () => { successorContent: { value: { "@type": "Surname", - value: "Name 2" + value: "anotherSurname" } } }) diff --git a/packages/runtime/test/consumption/iqlQuery.test.ts b/packages/runtime/test/consumption/iqlQuery.test.ts index 494cdea1b..daa8736f7 100644 --- a/packages/runtime/test/consumption/iqlQuery.test.ts +++ b/packages/runtime/test/consumption/iqlQuery.test.ts @@ -48,7 +48,7 @@ describe("IQL Query", () => { content: { value: { "@type": "GivenName", - value: "aGivenName1" + value: "aGivenName" }, tags: ["x+%+language:de"] } @@ -60,7 +60,7 @@ describe("IQL Query", () => { content: { value: { "@type": "GivenName", - value: "aGivenName2" + value: "aSecondGivenName" }, tags: ["x+%+language:en"] } @@ -71,7 +71,7 @@ describe("IQL Query", () => { content: { value: { "@type": "GivenName", - value: "aGivenName3" + value: "aThirdGivenName" }, tags: ["x+%+content:someContent"] } diff --git a/packages/runtime/test/transport/relationships.test.ts b/packages/runtime/test/transport/relationships.test.ts index 79614b88d..8c988b665 100644 --- a/packages/runtime/test/transport/relationships.test.ts +++ b/packages/runtime/test/transport/relationships.test.ts @@ -15,7 +15,7 @@ import { ResponseResult } from "@nmshd/content"; import { CoreAddress, CoreId } from "@nmshd/core-types"; -import { IdentityDeletionProcessStatus, Random } from "@nmshd/transport"; +import { IdentityDeletionProcessStatus, Random, RandomCharacterRange } from "@nmshd/transport"; import assert from "assert"; import { DateTime } from "luxon"; import { @@ -1267,7 +1267,7 @@ describe("RelationshipDecomposition", () => { await sendAndReceiveNotification(services1.transport, services2.transport, services2.consumption); - const randomName1 = await Random.string(7); + const randomName1 = await Random.string(7, RandomCharacterRange.Alphabet); await executeFullCreateAndShareRepositoryAttributeFlow(services1, services2, { content: { value: { @@ -1277,7 +1277,7 @@ describe("RelationshipDecomposition", () => { } }); - const randomName2 = await Random.string(7); + const randomName2 = await Random.string(7, RandomCharacterRange.Alphabet); await executeFullCreateAndShareRepositoryAttributeFlow(services2, services1, { content: { value: {