fogui-common 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/dist/examples/extension/index.d.ts +1 -0
- package/dist/examples/extension/index.js +40 -0
- package/dist/examples/extension/index.js.map +1 -0
- package/dist/examples/parse-json-config/index.d.ts +1 -0
- package/dist/examples/parse-json-config/index.js +75 -0
- package/dist/examples/parse-json-config/index.js.map +1 -0
- package/dist/examples/parse-json-config/model/Config.d.ts +15 -0
- package/dist/examples/parse-json-config/model/Config.js +10 -0
- package/dist/examples/parse-json-config/model/Config.js.map +1 -0
- package/dist/examples/parse-json-config/model/DatabaseConnection.d.ts +26 -0
- package/dist/examples/parse-json-config/model/DatabaseConnection.js +12 -0
- package/dist/examples/parse-json-config/model/DatabaseConnection.js.map +1 -0
- package/dist/examples/parse-json-config/model/Socket.d.ts +15 -0
- package/dist/examples/parse-json-config/model/Socket.js +10 -0
- package/dist/examples/parse-json-config/model/Socket.js.map +1 -0
- package/dist/examples/parse-json-config/model/types/HostType.d.ts +4 -0
- package/dist/examples/parse-json-config/model/types/HostType.js +12 -0
- package/dist/examples/parse-json-config/model/types/HostType.js.map +1 -0
- package/dist/examples/parse-json-config/model/types/PortType.d.ts +5 -0
- package/dist/examples/parse-json-config/model/types/PortType.js +6 -0
- package/dist/examples/parse-json-config/model/types/PortType.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/model/base/Model.d.ts +15 -0
- package/dist/model/base/Model.js +46 -0
- package/dist/model/base/Model.js.map +1 -0
- package/dist/model/base/Model.spec.d.ts +1 -0
- package/dist/model/base/Model.spec.js +82 -0
- package/dist/model/base/Model.spec.js.map +1 -0
- package/dist/types/UuidType.d.ts +8 -0
- package/dist/types/UuidType.js +15 -0
- package/dist/types/UuidType.js.map +1 -0
- package/dist/types/UuidType.spec.d.ts +1 -0
- package/dist/types/UuidType.spec.js +27 -0
- package/dist/types/UuidType.spec.js.map +1 -0
- package/dist/types/base/ArrayType.d.ts +11 -0
- package/dist/types/base/ArrayType.js +40 -0
- package/dist/types/base/ArrayType.js.map +1 -0
- package/dist/types/base/ArrayType.spec.d.ts +1 -0
- package/dist/types/base/ArrayType.spec.js +51 -0
- package/dist/types/base/ArrayType.spec.js.map +1 -0
- package/dist/types/base/AttributeType.d.ts +44 -0
- package/dist/types/base/AttributeType.js +61 -0
- package/dist/types/base/AttributeType.js.map +1 -0
- package/dist/types/base/BooleanType.d.ts +10 -0
- package/dist/types/base/BooleanType.js +24 -0
- package/dist/types/base/BooleanType.js.map +1 -0
- package/dist/types/base/BooleanType.spec.d.ts +1 -0
- package/dist/types/base/BooleanType.spec.js +41 -0
- package/dist/types/base/BooleanType.spec.js.map +1 -0
- package/dist/types/base/NumberType.d.ts +13 -0
- package/dist/types/base/NumberType.js +38 -0
- package/dist/types/base/NumberType.js.map +1 -0
- package/dist/types/base/NumberType.spec.d.ts +1 -0
- package/dist/types/base/NumberType.spec.js +72 -0
- package/dist/types/base/NumberType.spec.js.map +1 -0
- package/dist/types/base/StringArrayType.d.ts +5 -0
- package/dist/types/base/StringArrayType.js +6 -0
- package/dist/types/base/StringArrayType.js.map +1 -0
- package/dist/types/base/StringType.d.ts +27 -0
- package/dist/types/base/StringType.js +59 -0
- package/dist/types/base/StringType.js.map +1 -0
- package/dist/types/base/StringType.spec.d.ts +1 -0
- package/dist/types/base/StringType.spec.js +28 -0
- package/dist/types/base/StringType.spec.js.map +1 -0
- package/dist/util/InferType.d.ts +15 -0
- package/dist/util/InferType.js +2 -0
- package/dist/util/InferType.js.map +1 -0
- package/package.json +33 -0
- package/src/examples/extension/index.ts +65 -0
- package/src/examples/parse-json-config/index.ts +81 -0
- package/src/examples/parse-json-config/model/Config.ts +10 -0
- package/src/examples/parse-json-config/model/DatabaseConnection.ts +12 -0
- package/src/examples/parse-json-config/model/Socket.ts +10 -0
- package/src/examples/parse-json-config/model/types/HostType.ts +12 -0
- package/src/examples/parse-json-config/model/types/PortType.ts +6 -0
- package/src/index.ts +8 -0
- package/src/model/base/Model.spec.ts +84 -0
- package/src/model/base/Model.ts +55 -0
- package/src/types/UuidType.spec.ts +31 -0
- package/src/types/UuidType.ts +20 -0
- package/src/types/base/ArrayType.spec.ts +62 -0
- package/src/types/base/ArrayType.ts +44 -0
- package/src/types/base/AttributeType.ts +83 -0
- package/src/types/base/BooleanType.spec.ts +48 -0
- package/src/types/base/BooleanType.ts +28 -0
- package/src/types/base/NumberType.spec.ts +86 -0
- package/src/types/base/NumberType.ts +43 -0
- package/src/types/base/StringArrayType.ts +6 -0
- package/src/types/base/StringType.spec.ts +34 -0
- package/src/types/base/StringType.ts +69 -0
- package/src/util/InferType.ts +27 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { registerGlobalExtensionConfiguration } from "../../types/base/AttributeType.js";
|
|
2
|
+
import { NumberType } from "../../types/base/NumberType.js";
|
|
3
|
+
import { StringType } from "../../types/base/StringType.js";
|
|
4
|
+
Object.defineProperty(StringType.prototype, 'extensionsConfigurations', {
|
|
5
|
+
value: { "HelpAndInformation": {
|
|
6
|
+
extensionName: "HelpAndInformation",
|
|
7
|
+
helpText: "This is a string attribute",
|
|
8
|
+
infoText: "String attributes can contain any text value"
|
|
9
|
+
} },
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
registerGlobalExtensionConfiguration(StringType.name, {
|
|
13
|
+
extensionName: "HelpAndInformation",
|
|
14
|
+
helpText: "This is a string attribute",
|
|
15
|
+
infoText: "String attributes can contain any text value"
|
|
16
|
+
});
|
|
17
|
+
registerGlobalExtensionConfiguration(NumberType.name, {
|
|
18
|
+
extensionName: "HelpAndInformation",
|
|
19
|
+
helpText: "This is a number attribute",
|
|
20
|
+
infoText: "Number attributes can contain any numeric value"
|
|
21
|
+
});
|
|
22
|
+
let myString = new StringType({ defaultValue: "Hello, World!", allowNull: false });
|
|
23
|
+
class MySpecialString extends StringType {
|
|
24
|
+
}
|
|
25
|
+
class MyOtherSpecialString extends MySpecialString {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this.extensionsConfigurations["HelpAndInformation"] = {
|
|
29
|
+
extensionName: "HelpAndInformation",
|
|
30
|
+
helpText: "This is a special string attribute",
|
|
31
|
+
infoText: "Special string attributes can contain any text value but are special"
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
console.log("Help text for myString: ", myString.getExtensionConfiguration("HelpAndInformation")?.helpText);
|
|
36
|
+
let mySpecialString = new MySpecialString();
|
|
37
|
+
console.log("Help text for mySpecialString: ", mySpecialString.getExtensionConfiguration("HelpAndInformation")?.helpText);
|
|
38
|
+
let myOtherSpecialString = new MyOtherSpecialString();
|
|
39
|
+
console.log("Help text for myOtherSpecialString: ", myOtherSpecialString.getExtensionConfiguration("HelpAndInformation")?.helpText);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/examples/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,oCAAoC,EAAE,MAAM,mCAAmC,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAQ5D,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,EAAE,0BAA0B,EAAE;IACpE,KAAK,EAAE,EAAC,oBAAoB,EAAE;YACtB,aAAa,EAAE,oBAAoB;YACnC,QAAQ,EAAE,4BAA4B;YACtC,QAAQ,EAAE,8CAA8C;SAC3D,EAAC;IACN,QAAQ,EAAE,IAAI;CACjB,CAAC,CAAA;AAEF,oCAAoC,CAAC,UAAU,CAAC,IAAI,EAAE;IAClD,aAAa,EAAE,oBAAoB;IACnC,QAAQ,EAAE,4BAA4B;IACtC,QAAQ,EAAE,8CAA8C;CACf,CAAC,CAAA;AAC9C,oCAAoC,CAAC,UAAU,CAAC,IAAI,EAAE;IAClD,aAAa,EAAE,oBAAoB;IACnC,QAAQ,EAAE,4BAA4B;IACtC,QAAQ,EAAE,iDAAiD;CAClB,CAAC,CAAA;AAI9C,IAAI,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAC,CAAC,CAAA;AAEhF,MAAM,eAAgB,SAAQ,UAAU;CAAG;AAE3C,MAAM,oBAAqB,SAAQ,eAAe;IAC9C;QACI,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,wBAAwB,CAAC,oBAAoB,CAAC,GAAG;YAClD,aAAa,EAAE,oBAAoB;YACnC,QAAQ,EAAE,oCAAoC;YAC9C,QAAQ,EAAE,sEAAsE;SACvC,CAAA;IACjD,CAAC;CACJ;AAED,OAAO,CAAC,GAAG,CACP,0BAA0B,EACzB,QAAQ,CAAC,yBAAyB,CAAC,oBAAoB,CAA8C,EAAE,QAAQ,CACnH,CAAA;AAED,IAAI,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;AAE3C,OAAO,CAAC,GAAG,CACP,iCAAiC,EAChC,eAAe,CAAC,yBAAyB,CAAC,oBAAoB,CAA8C,EAAE,QAAQ,CAC1H,CAAA;AAED,IAAI,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAA;AAErD,OAAO,CAAC,GAAG,CACP,sCAAsC,EACrC,oBAAoB,CAAC,yBAAyB,CAAC,oBAAoB,CAA8C,EAAE,QAAQ,CAC/H,CAAA","sourcesContent":["import { AttributeType, registerGlobalExtensionConfiguration } from \"../../types/base/AttributeType.js\";\nimport { NumberType } from \"../../types/base/NumberType.js\";\nimport { StringType } from \"../../types/base/StringType.js\";\n\ntype HelpAndInformationExtensionConfiguration = {\n extensionName: \"HelpAndInformation\"\n helpText?: string\n infoText?: string\n} \n\nObject.defineProperty(StringType.prototype, 'extensionsConfigurations', {\n value: {\"HelpAndInformation\": {\n extensionName: \"HelpAndInformation\",\n helpText: \"This is a string attribute\",\n infoText: \"String attributes can contain any text value\"\n }},\n writable: true\n})\n\nregisterGlobalExtensionConfiguration(StringType.name, {\n extensionName: \"HelpAndInformation\",\n helpText: \"This is a string attribute\",\n infoText: \"String attributes can contain any text value\"\n} as HelpAndInformationExtensionConfiguration)\nregisterGlobalExtensionConfiguration(NumberType.name, {\n extensionName: \"HelpAndInformation\",\n helpText: \"This is a number attribute\",\n infoText: \"Number attributes can contain any numeric value\"\n} as HelpAndInformationExtensionConfiguration)\n\n\n\nlet myString = new StringType({defaultValue: \"Hello, World!\", allowNull: false})\n\nclass MySpecialString extends StringType {}\n\nclass MyOtherSpecialString extends MySpecialString {\n constructor(){\n super()\n this.extensionsConfigurations[\"HelpAndInformation\"] = {\n extensionName: \"HelpAndInformation\",\n helpText: \"This is a special string attribute\",\n infoText: \"Special string attributes can contain any text value but are special\"\n } as HelpAndInformationExtensionConfiguration\n }\n}\n\nconsole.log(\n \"Help text for myString: \",\n (myString.getExtensionConfiguration(\"HelpAndInformation\") as HelpAndInformationExtensionConfiguration)?.helpText\n)\n\nlet mySpecialString = new MySpecialString()\n\nconsole.log(\n \"Help text for mySpecialString: \",\n (mySpecialString.getExtensionConfiguration(\"HelpAndInformation\") as HelpAndInformationExtensionConfiguration)?.helpText\n)\n\nlet myOtherSpecialString = new MyOtherSpecialString()\n\nconsole.log(\n \"Help text for myOtherSpecialString: \",\n (myOtherSpecialString.getExtensionConfiguration(\"HelpAndInformation\") as HelpAndInformationExtensionConfiguration)?.helpText\n)"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ParseAndValidationCriticality } from '../../types/base/AttributeType.js';
|
|
2
|
+
import { Config } from './model/Config.js';
|
|
3
|
+
const rawDataValide = `{
|
|
4
|
+
"server": {
|
|
5
|
+
"host": "localhost",
|
|
6
|
+
"port": 8080
|
|
7
|
+
},
|
|
8
|
+
"database": {
|
|
9
|
+
"host": "127.0.0.1",
|
|
10
|
+
"port": 5432,
|
|
11
|
+
"database": "SAMPLE_DB",
|
|
12
|
+
"username": "admin",
|
|
13
|
+
"password": "password123"
|
|
14
|
+
}
|
|
15
|
+
}`;
|
|
16
|
+
const rawDataInvalide = `{
|
|
17
|
+
"server": {
|
|
18
|
+
"host": "Sörver",
|
|
19
|
+
"port": 65536
|
|
20
|
+
},
|
|
21
|
+
"database": {
|
|
22
|
+
"host": "999.0.0.1",
|
|
23
|
+
"port": 0,
|
|
24
|
+
"name": "SAMPLE_DB",
|
|
25
|
+
"user": "admin",
|
|
26
|
+
"password": "password123"
|
|
27
|
+
}
|
|
28
|
+
}`;
|
|
29
|
+
async function parseAndValidateConfig(rawData) {
|
|
30
|
+
let configData = JSON.parse(rawData);
|
|
31
|
+
let configModel = new Config();
|
|
32
|
+
let parseResult = configModel.parse(configData);
|
|
33
|
+
let config = parseResult.value;
|
|
34
|
+
//console.log("Parsed config:", JSON.stringify(config, null, 2))
|
|
35
|
+
if (parseResult.deepResult.criticality !== ParseAndValidationCriticality.Ok) {
|
|
36
|
+
console.log("There were some issues during parsing:");
|
|
37
|
+
printErrors(parseResult.deepResult);
|
|
38
|
+
}
|
|
39
|
+
if (config === undefined) {
|
|
40
|
+
console.log("Parsed config is undefined, cannot validate.");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let result = await configModel.validate(config, ParseAndValidationCriticality.Info); //NO Debug and Silly messages
|
|
44
|
+
//console.log("Validation result:", JSON.stringify(result, null, 2))
|
|
45
|
+
if (result.criticality === ParseAndValidationCriticality.Ok) {
|
|
46
|
+
console.log("Configuration is valid.");
|
|
47
|
+
}
|
|
48
|
+
else if (result.criticality <= ParseAndValidationCriticality.Info) {
|
|
49
|
+
console.log("There are some info messages:");
|
|
50
|
+
printErrors(result);
|
|
51
|
+
}
|
|
52
|
+
else if (result.criticality <= ParseAndValidationCriticality.Warn) {
|
|
53
|
+
console.log("There are some warnings:");
|
|
54
|
+
printErrors(result);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log("Configuration is invalid. Errors:");
|
|
58
|
+
printErrors(result);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function printErrors(validationObject, path = "/") {
|
|
62
|
+
for (let message of validationObject.messages) {
|
|
63
|
+
if (message.criticality >= ParseAndValidationCriticality.Error) {
|
|
64
|
+
console.log(`- ${path}: ${message.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (validationObject.subValidationResults) {
|
|
68
|
+
for (let key in validationObject.subValidationResults) {
|
|
69
|
+
printErrors(validationObject.subValidationResults[key], `${path}${key}/`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
await parseAndValidateConfig(rawDataValide);
|
|
74
|
+
await parseAndValidateConfig(rawDataInvalide);
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/examples/parse-json-config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAA4B,MAAM,mCAAmC,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,aAAa,GAAG;;;;;;;;;;;;EAYpB,CAAA;AAGF,MAAM,eAAe,GAAG;;;;;;;;;;;;EAYtB,CAAA;AAEF,KAAK,UAAU,sBAAsB,CAAC,OAAe;IAEjD,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAEpC,IAAI,WAAW,GAAG,IAAI,MAAM,EAAE,CAAA;IAC9B,IAAI,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAC/C,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,CAAA;IAC9B,gEAAgE;IAChE,IAAI,WAAW,CAAC,U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AO,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IACD,IAAI,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;QACxC,KAAK,IAAI,GAAG,IAAI,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;YACpD,WAAW,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;AACL,CAAC;AAED,MAAM,sBAAsB,CAAC,aAAa,CAAC,CAAA;AAC3C,MAAM,sBAAsB,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import { ParseAndValidationCriticality, ParseAndValidationResult } from '../../types/base/AttributeType.js';\nimport { Config } from './model/Config.js';\n\nconst rawDataValide = `{\n \"server\": {\n \"host\": \"localhost\",\n \"port\": 8080\n },\n \"database\": {\n \"host\": \"127.0.0.1\",\n \"port\": 5432,\n \"database\": \"SAMPLE_DB\",\n \"username\": \"admin\",\n \"password\": \"password123\"\n }\n}`\n\n\nconst rawDataInvalide = `{\n \"server\": {\n \"host\": \"Sörver\",\n \"port\": 65536\n },\n \"database\": {\n \"host\": \"999.0.0.1\",\n \"port\": 0,\n \"name\": \"SAMPLE_DB\",\n \"user\": \"admin\",\n \"password\": \"password123\"\n }\n}`\n\nasync function parseAndValidateConfig(rawData: string) {\n\n let configData = JSON.parse(rawData)\n\n let configModel = new Config()\n let parseResult = configModel.parse(configData)\n let config = parseResult.value\n //console.log(\"Parsed config:\", JSON.stringify(config, null, 2))\n if (parseResult.deepResult.criticality !== ParseAndValidationCriticality.Ok) {\n console.log(\"There were some issues during parsing:\")\n printErrors(parseResult.deepResult)\n }\n if(config === undefined) {\n console.log(\"Parsed config is undefined, cannot validate.\")\n return\n }\n let result = await configModel.validate(config, ParseAndValidationCriticality.Info) //NO Debug and Silly messages\n //console.log(\"Validation result:\", JSON.stringify(result, null, 2))\n if (result.criticality === ParseAndValidationCriticality.Ok) {\n console.log(\"Configuration is valid.\")\n }\n else if( result.criticality <= ParseAndValidationCriticality.Info ){\n console.log(\"There are some info messages:\")\n printErrors(result)\n }\n else if( result.criticality <= ParseAndValidationCriticality.Warn ){\n console.log(\"There are some warnings:\")\n printErrors(result)\n }\n else{\n console.log(\"Configuration is invalid. Errors:\")\n printErrors(result)\n }\n}\nfunction printErrors(validationObject: ParseAndValidationResult, path:string = \"/\") {\n for (let message of validationObject.messages) {\n if (message.criticality >= ParseAndValidationCriticality.Error) {\n console.log(`- ${path}: ${message.message}`);\n }\n }\n if (validationObject.subValidationResults) {\n for (let key in validationObject.subValidationResults) {\n printErrors(validationObject.subValidationResults[key], `${path}${key}/`);\n }\n }\n}\n\nawait parseAndValidateConfig(rawDataValide)\nawait parseAndValidateConfig(rawDataInvalide)\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model } from "../../../model/base/Model.js";
|
|
2
|
+
import { DatabaseConnection } from "./DatabaseConnection.js";
|
|
3
|
+
import { Socket } from "./Socket.js";
|
|
4
|
+
export declare class Config extends Model {
|
|
5
|
+
properties: {
|
|
6
|
+
server: {
|
|
7
|
+
required: true;
|
|
8
|
+
type: Socket;
|
|
9
|
+
};
|
|
10
|
+
database: {
|
|
11
|
+
required: true;
|
|
12
|
+
type: DatabaseConnection;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Model, required } from "../../../model/base/Model.js";
|
|
2
|
+
import { DatabaseConnection } from "./DatabaseConnection.js";
|
|
3
|
+
import { Socket } from "./Socket.js";
|
|
4
|
+
export class Config extends Model {
|
|
5
|
+
properties = {
|
|
6
|
+
server: { required, type: new Socket() },
|
|
7
|
+
database: { required, type: new DatabaseConnection() },
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../../../../src/examples/parse-json-config/model/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,OAAO,MAAO,SAAQ,KAAK;IAC7B,UAAU,GAAG;QACT,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,EAAE;QACxC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,kBAAkB,EAAE,EAAE;KACzD,CAAC;CACL","sourcesContent":["import { Model, required } from \"../../../model/base/Model.js\";\nimport { DatabaseConnection } from \"./DatabaseConnection.js\";\nimport { Socket } from \"./Socket.js\";\n\nexport class Config extends Model {\n properties = {\n server: { required, type: new Socket() },\n database: { required, type: new DatabaseConnection() },\n };\n}"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StringType } from "../../../types/base/StringType.js";
|
|
2
|
+
import { Socket } from "./Socket.js";
|
|
3
|
+
export declare class DatabaseConnection extends Socket {
|
|
4
|
+
properties: {
|
|
5
|
+
username: {
|
|
6
|
+
required: true;
|
|
7
|
+
type: StringType<string>;
|
|
8
|
+
};
|
|
9
|
+
password: {
|
|
10
|
+
required: true;
|
|
11
|
+
type: StringType<string>;
|
|
12
|
+
};
|
|
13
|
+
database: {
|
|
14
|
+
required: true;
|
|
15
|
+
type: StringType<string>;
|
|
16
|
+
};
|
|
17
|
+
host: {
|
|
18
|
+
required: true;
|
|
19
|
+
type: import("./types/HostType.js").HostType;
|
|
20
|
+
};
|
|
21
|
+
port: {
|
|
22
|
+
required: true;
|
|
23
|
+
type: import("./types/PortType.js").PortType;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { required } from "../../../model/base/Model.js";
|
|
2
|
+
import { StringType } from "../../../types/base/StringType.js";
|
|
3
|
+
import { Socket } from "./Socket.js";
|
|
4
|
+
export class DatabaseConnection extends Socket {
|
|
5
|
+
properties = {
|
|
6
|
+
...Socket.prototype.properties,
|
|
7
|
+
username: { required, type: new StringType() },
|
|
8
|
+
password: { required, type: new StringType() },
|
|
9
|
+
database: { required, type: new StringType() },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=DatabaseConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseConnection.js","sourceRoot":"","sources":["../../../../src/examples/parse-json-config/model/DatabaseConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,OAAO,kBAAmB,SAAQ,MAAM;IAC1C,UAAU,GAAG;QACT,GAAI,MAAM,CAAC,SAAS,CAAC,UAAU;QAC/B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,UAAU,EAAE,EAAE;QAC9C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,UAAU,EAAE,EAAE;QAC9C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,UAAU,EAAE,EAAE;KACjD,CAAC;CACL","sourcesContent":["import { required } from \"../../../model/base/Model.js\";\nimport { StringType } from \"../../../types/base/StringType.js\"\nimport { Socket } from \"./Socket.js\";\n\nexport class DatabaseConnection extends Socket {\n properties = {\n ... Socket.prototype.properties,\n username: { required, type: new StringType() },\n password: { required, type: new StringType() },\n database: { required, type: new StringType() },\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model } from "../../../model/base/Model.js";
|
|
2
|
+
import { HostType } from "./types/HostType.js";
|
|
3
|
+
import { PortType } from "./types/PortType.js";
|
|
4
|
+
export declare class Socket extends Model {
|
|
5
|
+
properties: {
|
|
6
|
+
host: {
|
|
7
|
+
required: true;
|
|
8
|
+
type: HostType;
|
|
9
|
+
};
|
|
10
|
+
port: {
|
|
11
|
+
required: true;
|
|
12
|
+
type: PortType;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Model, required } from "../../../model/base/Model.js";
|
|
2
|
+
import { HostType } from "./types/HostType.js";
|
|
3
|
+
import { PortType } from "./types/PortType.js";
|
|
4
|
+
export class Socket extends Model {
|
|
5
|
+
properties = {
|
|
6
|
+
host: { required, type: new HostType() },
|
|
7
|
+
port: { required, type: new PortType() },
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Socket.js","sourceRoot":"","sources":["../../../../src/examples/parse-json-config/model/Socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,OAAO,MAAO,SAAQ,KAAK;IAC7B,UAAU,GAAG;QACT,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,QAAQ,EAAE,EAAC;QACvC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,QAAQ,EAAE,EAAC;KAC1C,CAAA;CACJ","sourcesContent":["import { Model, required } from \"../../../model/base/Model.js\";\nimport { HostType } from \"./types/HostType.js\";\nimport { PortType } from \"./types/PortType.js\";\n\nexport class Socket extends Model {\n properties = {\n host: { required, type: new HostType()},\n port: { required, type: new PortType()}, \n }\n}"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StringType } from "../../../../types/base/StringType.js";
|
|
2
|
+
export class HostType extends StringType {
|
|
3
|
+
constructor() {
|
|
4
|
+
super({
|
|
5
|
+
minLength: 1,
|
|
6
|
+
// Regex pattern to match valid IPv4 addresses and domain names https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
7
|
+
matchPattern: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/,
|
|
8
|
+
matchPatternMessage: "Host must be a valid IPv4 address or domain name"
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=HostType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostType.js","sourceRoot":"","sources":["../../../../../src/examples/parse-json-config/model/types/HostType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,MAAM,OAAO,QAAS,SAAQ,UAAU;IACpC;QACI,KAAK,CAAC;YACF,SAAS,EAAG,CAAC;YACb,iKAAiK;YACjK,YAAY,EAAG,6GAA6G;YAC5H,mBAAmB,EAAE,kDAAkD;SAC1E,CAAC,CAAA;IACN,CAAC;CACA","sourcesContent":["import { StringType } from \"../../../../types/base/StringType.js\";\n\nexport class HostType extends StringType {\n constructor() {\n super({\n minLength : 1,\n // Regex pattern to match valid IPv4 addresses and domain names https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address\n matchPattern: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$/,\n matchPatternMessage: \"Host must be a valid IPv4 address or domain name\"\n })\n }\n }"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortType.js","sourceRoot":"","sources":["../../../../../src/examples/parse-json-config/model/types/PortType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEjE,MAAM,OAAO,QAAS,SAAQ,UAAU;IACpC,GAAG,GAAG,CAAC,CAAA;IACP,GAAG,GAAG,KAAK,CAAA;CACd","sourcesContent":["import { NumberType } from \"../../../../types/base/NumberType.js\"\n\nexport class PortType extends NumberType {\n min = 1\n max = 65535\n}"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./model/base/Model.js";
|
|
2
|
+
export * from "./types/base/AttributeType.js";
|
|
3
|
+
export * from "./types/base/StringType.js";
|
|
4
|
+
export * from "./types/base/NumberType.js";
|
|
5
|
+
export * from "./types/base/BooleanType.js";
|
|
6
|
+
export * from "./util/InferType.js";
|
|
7
|
+
export * from "./types/UuidType.js";
|
|
8
|
+
export * from "./types/base/ArrayType.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./model/base/Model.js";
|
|
2
|
+
export * from "./types/base/AttributeType.js";
|
|
3
|
+
export * from "./types/base/StringType.js";
|
|
4
|
+
export * from "./types/base/NumberType.js";
|
|
5
|
+
export * from "./types/base/BooleanType.js";
|
|
6
|
+
export * from "./util/InferType.js";
|
|
7
|
+
export * from "./types/UuidType.js";
|
|
8
|
+
export * from "./types/base/ArrayType.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA","sourcesContent":["export * from \"./model/base/Model.js\"\nexport * from \"./types/base/AttributeType.js\"\nexport * from \"./types/base/StringType.js\"\nexport * from \"./types/base/NumberType.js\"\nexport * from \"./types/base/BooleanType.js\"\nexport * from \"./util/InferType.js\"\nexport * from \"./types/UuidType.js\"\nexport * from \"./types/base/ArrayType.js\""]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AttributeType, ParseAndValidationCriticality, ParseAndValidationResult, parseResult } from "../../types/base/AttributeType.js";
|
|
2
|
+
import { InferType } from "../../util/InferType.js";
|
|
3
|
+
export declare const required: true;
|
|
4
|
+
interface PropertyOptions {
|
|
5
|
+
required?: boolean;
|
|
6
|
+
type: AttributeType<any, any>;
|
|
7
|
+
}
|
|
8
|
+
export declare class Model extends AttributeType<object, Record<string, any>> {
|
|
9
|
+
properties: Record<string, PropertyOptions>;
|
|
10
|
+
parse(value: Record<string, any>): parseResult<InferType<this>>;
|
|
11
|
+
validate(value: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}, level?: ParseAndValidationCriticality): Promise<ParseAndValidationResult>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AttributeType, ParseAndValidationCriticality } from "../../types/base/AttributeType.js";
|
|
2
|
+
export const required = true;
|
|
3
|
+
export class Model extends AttributeType {
|
|
4
|
+
properties = {};
|
|
5
|
+
parse(value) {
|
|
6
|
+
const obj = {};
|
|
7
|
+
let validationObject = { criticality: ParseAndValidationCriticality.Ok, messages: [] };
|
|
8
|
+
validationObject.subValidationResults = {};
|
|
9
|
+
for (const key in this.properties) {
|
|
10
|
+
if (this.properties[key].required || value[key] !== undefined) {
|
|
11
|
+
let result = this.properties[key].type.parse(value[key]);
|
|
12
|
+
obj[key] = result.value;
|
|
13
|
+
validationObject.subValidationResults[key] = result.deepResult;
|
|
14
|
+
validationObject.criticality = Math.max(validationObject.criticality, result.deepResult.criticality);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for (let objectProperty in value) {
|
|
18
|
+
if (this.properties[objectProperty] === undefined)
|
|
19
|
+
validationObject.messages.push({ criticality: ParseAndValidationCriticality.Error, message: `Property "${objectProperty}" nicht erlaubt.` });
|
|
20
|
+
}
|
|
21
|
+
return { value: obj, deepResult: validationObject };
|
|
22
|
+
}
|
|
23
|
+
async validate(value, level) {
|
|
24
|
+
let validationObject = { criticality: ParseAndValidationCriticality.Ok, messages: [] };
|
|
25
|
+
validationObject.subValidationResults = {};
|
|
26
|
+
for (let propertyName in this.properties) {
|
|
27
|
+
let property = this.properties[propertyName];
|
|
28
|
+
if (value[propertyName] === undefined) {
|
|
29
|
+
if (property.required) {
|
|
30
|
+
validationObject.messages.push({ criticality: ParseAndValidationCriticality.Error, message: `Property "${propertyName}" is required.` });
|
|
31
|
+
validationObject.criticality = Math.max(validationObject.criticality, ParseAndValidationCriticality.Error);
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
let validationResult = await property.type.validate(value[propertyName]);
|
|
36
|
+
validationObject.subValidationResults[propertyName] = validationResult;
|
|
37
|
+
validationObject.criticality = Math.max(validationObject.criticality, validationResult.criticality);
|
|
38
|
+
}
|
|
39
|
+
for (let objectProperty in value) {
|
|
40
|
+
if (this.properties[objectProperty] === undefined)
|
|
41
|
+
validationObject.messages.push({ criticality: ParseAndValidationCriticality.Error, message: `Property "${objectProperty}" nicht erlaubt.` });
|
|
42
|
+
}
|
|
43
|
+
return validationObject;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=Model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.js","sourceRoot":"","sources":["../../../src/model/base/Model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAyC,MAAM,mCAAmC,CAAC;AAGxI,MAAM,C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,WAAW,EAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,EAAC,aAAa,cAAc,kBAAkB,EAAE,CAAC,CAAA;QACjJ,CAAC;QACD,OAAO,gBAAgB,CAAA;IAC3B,CAAC;CACJ","sourcesContent":["import { AttributeType, ParseAndValidationCriticality, ParseAndValidationResult, parseResult } from \"../../types/base/AttributeType.js\";\nimport { InferType } from \"../../util/InferType.js\";\n\nexport const required = true as const\n\n\ninterface PropertyOptions {\n required?: boolean;\n type: AttributeType<any, any>;\n}\n\n\nexport class Model extends AttributeType<object,Record<string, any>> {\n properties: Record<string, PropertyOptions> = {};\n parse(value: Record<string, any>): parseResult<InferType<this>> {\n const obj: any = {};\n let validationObject:ParseAndValidationResult = {criticality:ParseAndValidationCriticality.Ok,messages:[]}\n validationObject.subValidationResults={}\n for (const key in this.properties) {\n if (this.properties[key].required || value[key] !== undefined) {\n let result = this.properties[key].type.parse(value[key]);\n obj[key] = result.value;\n validationObject.subValidationResults[key]=result.deepResult\n validationObject.criticality=Math.max(validationObject.criticality,result.deepResult.criticality)\n }\n }\n for(let objectProperty in value){\n if(this.properties[objectProperty]===undefined)\n validationObject.messages.push({criticality:ParseAndValidationCriticality.Error, message:`Property \"${objectProperty}\" nicht erlaubt.` })\n }\n return {value: obj, deepResult: validationObject};\n }\n async validate(value: { [key: string]: any}, level?: ParseAndValidationCriticality): Promise<ParseAndValidationResult> {\n let validationObject:ParseAndValidationResult = {criticality:ParseAndValidationCriticality.Ok,messages:[]}\n validationObject.subValidationResults={}\n for(let propertyName in this.properties){\n let property = this.properties[propertyName]\n if(value[propertyName]===undefined ){\n if(property.required){\n validationObject.messages.push({criticality:ParseAndValidationCriticality.Error, message:`Property \"${propertyName}\" is required.`})\n validationObject.criticality=Math.max(validationObject.criticality,ParseAndValidationCriticality.Error)\n }\n continue\n }\n let validationResult = await property.type.validate(value[propertyName])\n validationObject.subValidationResults[propertyName]=validationResult\n validationObject.criticality=Math.max(validationObject.criticality,validationResult.criticality)\n }\n for(let objectProperty in value){\n if(this.properties[objectProperty]===undefined)\n validationObject.messages.push({criticality:ParseAndValidationCriticality.Error, message:`Property \"${objectProperty}\" nicht erlaubt.` })\n }\n return validationObject\n }\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { BooleanType, Model, NumberType, required, StringType } from "../../index.js";
|
|
3
|
+
import { StringArrayType } from "../../types/base/StringArrayType.js";
|
|
4
|
+
describe("Model", () => {
|
|
5
|
+
it("should parse a model with required and optional properties", () => {
|
|
6
|
+
class AddressType extends Model {
|
|
7
|
+
properties = {
|
|
8
|
+
street: { required, type: new StringType() },
|
|
9
|
+
city: { required, type: new StringType() },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
class Person extends Model {
|
|
13
|
+
properties = {
|
|
14
|
+
name: { required, type: new StringType() },
|
|
15
|
+
age: { type: new NumberType() },
|
|
16
|
+
isActive: { required, type: new BooleanType() },
|
|
17
|
+
address: { type: new AddressType() },
|
|
18
|
+
hobbies: { required, type: new StringArrayType() }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const personModel = new Person();
|
|
22
|
+
const person = personModel.parse({
|
|
23
|
+
name: "John Doe",
|
|
24
|
+
age: "30",
|
|
25
|
+
isActive: "true",
|
|
26
|
+
address: {
|
|
27
|
+
street: "123 Main St",
|
|
28
|
+
city: "Anytown"
|
|
29
|
+
},
|
|
30
|
+
hobbies: ["reading", "traveling"]
|
|
31
|
+
});
|
|
32
|
+
assert.deepEqual(person.value, {
|
|
33
|
+
name: "John Doe",
|
|
34
|
+
age: 30,
|
|
35
|
+
isActive: true,
|
|
36
|
+
address: {
|
|
37
|
+
street: "123 Main St",
|
|
38
|
+
city: "Anytown"
|
|
39
|
+
},
|
|
40
|
+
hobbies: ["reading", "traveling"]
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it("should parse a model with missing optional properties", () => {
|
|
44
|
+
class Person extends Model {
|
|
45
|
+
properties = {
|
|
46
|
+
name: { required, type: new StringType() },
|
|
47
|
+
age: { type: new NumberType() },
|
|
48
|
+
isActive: { required, type: new BooleanType() },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const personModel = new Person();
|
|
52
|
+
const person = personModel.parse({
|
|
53
|
+
name: "John Doe",
|
|
54
|
+
isActive: "false",
|
|
55
|
+
});
|
|
56
|
+
assert.deepEqual(person.value, {
|
|
57
|
+
name: "John Doe",
|
|
58
|
+
isActive: false,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it("should parse a model with missing required properties", () => {
|
|
62
|
+
// Missing required properties should be set to undefined or default values
|
|
63
|
+
// Is this a good idea?
|
|
64
|
+
class Person extends Model {
|
|
65
|
+
properties = {
|
|
66
|
+
name: { required, type: new StringType() },
|
|
67
|
+
age: { required, type: new NumberType({ defaultValue: 10 }) },
|
|
68
|
+
isActive: { required, type: new BooleanType({ defaultValue: false }) },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const personModel = new Person();
|
|
72
|
+
const person = personModel.parse({
|
|
73
|
+
name: "John Doe"
|
|
74
|
+
});
|
|
75
|
+
assert.deepEqual(person.value, {
|
|
76
|
+
age: 10,
|
|
77
|
+
isActive: false,
|
|
78
|
+
name: "John Doe"
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=Model.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.spec.js","sourceRoot":"","sources":["../../../src/model/base/Model.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAA4B,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC/G,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAG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C,KAAK,CAAC;YAC7B,IAAI,EAAE,UAAU;SACnB,CAAC,CAAA;QACF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE;YAC3B,GAAG,EAAE,EAAE;YACP,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,UAAU;SACnB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import { assert } from \"chai\"\nimport { ArrayType, AttributeType, BooleanType, Model, NumberType, required, StringType } from \"../../index.js\"\nimport { StringArrayType } from \"../../types/base/StringArrayType.js\";\n\n\ndescribe(\"Model\", () => {\n it(\"should parse a model with required and optional properties\", () => {\n class AddressType extends Model {\n properties = {\n street: { required, type: new StringType() },\n city: { required, type: new StringType() },\n };\n }\n\n class Person extends Model {\n properties = {\n name: { required, type: new StringType() },\n age: { type: new NumberType() },\n isActive: { required, type: new BooleanType() },\n address: { type: new AddressType() },\n hobbies: { required, type: new StringArrayType()}\n }\n }\n const personModel = new Person()\n const person = personModel.parse({\n name: \"John Doe\",\n age: \"30\",\n isActive: \"true\",\n address: {\n street: \"123 Main St\",\n city: \"Anytown\"\n },\n hobbies: [\"reading\", \"traveling\"]\n })\n assert.deepEqual(person.value, {\n name: \"John Doe\",\n age: 30,\n isActive: true,\n address: {\n street: \"123 Main St\",\n city: \"Anytown\"\n },\n hobbies: [\"reading\", \"traveling\"]\n })\n })\n it(\"should parse a model with missing optional properties\", () => {\n class Person extends Model {\n properties = {\n name: { required, type: new StringType() },\n age: { type: new NumberType() },\n isActive: { required, type: new BooleanType() },\n }\n }\n const personModel = new Person()\n const person = personModel.parse({\n name: \"John Doe\",\n isActive: \"false\",\n })\n assert.deepEqual(person.value, {\n name: \"John Doe\",\n isActive: false,\n })\n })\n it(\"should parse a model with missing required properties\", () => {\n // Missing required properties should be set to undefined or default values\n // Is this a good idea?\n class Person extends Model {\n properties = {\n name: { required, type: new StringType() },\n age: { required, type: new NumberType({defaultValue: 10}) },\n isActive: { required, type: new BooleanType({defaultValue: false}) },\n }\n }\n const personModel = new Person()\n const person = personModel.parse({\n name: \"John Doe\"\n })\n assert.deepEqual(person.value, {\n age: 10,\n isActive: false,\n name: \"John Doe\"\n })\n })\n})"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StringType, StringTypeOptions } from "./base/StringType.js";
|
|
2
|
+
type UUIDTsType = `${string}-${string}-${string}-${string}-${string}`;
|
|
3
|
+
export type UUIDTsTypeOptions = StringTypeOptions;
|
|
4
|
+
export declare class UUIDType extends StringType<UUIDTsType> {
|
|
5
|
+
constructor(options?: UUIDTsTypeOptions);
|
|
6
|
+
get defaultValue(): string;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StringType } from "./base/StringType.js";
|
|
2
|
+
export class UUIDType extends StringType {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
options = options || {};
|
|
5
|
+
options.parsePattern = /^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i;
|
|
6
|
+
options.parseReplacement = '$1$2$3$4$5';
|
|
7
|
+
options.formatPattern = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/g;
|
|
8
|
+
options.formatReplacement = '$1-$2-$3-$4-$5';
|
|
9
|
+
super(options);
|
|
10
|
+
}
|
|
11
|
+
get defaultValue() {
|
|
12
|
+
return this._defaultValue ?? this.parse(crypto.randomUUID()).value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=UuidType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UuidType.js","sourceRoot":"","sources":["../../src/types/UuidType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,sBAAsB,CAAC;AAMrE,MAAM,OAAO,QAAS,SAAQ,UAAsB;IAChD,YAAY,UAA6B,EAAE;QACvC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAA;QAEvB,OAAO,CAAC,YAAY,GAAG,+EAA+E,CAAA;QACtG,OAAO,CAAC,gBAAgB,GAAG,YAAY,CAAA;QACvC,OAAO,CAAC,aAAa,GAAG,oCAAoC,CAAA;QAC5D,OAAO,CAAC,iBAAiB,GAAG,gBAAgB,CAAA;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;IACD,IAAI,YAAY;QACZ,OAAQ,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,KAAe,CAAA;IACjF,CAAC;CACJ","sourcesContent":["import { StringType, StringTypeOptions } from \"./base/StringType.js\";\n\ntype UUIDTsType = `${string}-${string}-${string}-${string}-${string}`;\n\nexport type UUIDTsTypeOptions = StringTypeOptions\n\nexport class UUIDType extends StringType<UUIDTsType> {\n constructor(options: UUIDTsTypeOptions = {}) {\n options = options || {}\n \n options.parsePattern = /^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i\n options.parseReplacement = '$1$2$3$4$5'\n options.formatPattern = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/g\n options.formatReplacement = '$1-$2-$3-$4-$5'\n super(options)\n }\n get defaultValue(): string {\n return this._defaultValue ?? this.parse(crypto.randomUUID()).value as string\n }\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { UUIDType } from "./UuidType.js";
|
|
3
|
+
describe("UUIDType", () => {
|
|
4
|
+
const uuidType = new UUIDType();
|
|
5
|
+
const undformatedUuid = "123e4567e89b12d3a456426614174000";
|
|
6
|
+
const formatedUuid = "123e4567-e89b-12d3-a456-426614174000";
|
|
7
|
+
it("should return the value as is in format()", () => {
|
|
8
|
+
expect(uuidType.format(undformatedUuid)).to.equal(formatedUuid);
|
|
9
|
+
});
|
|
10
|
+
it("should return the value as is in parse()", () => {
|
|
11
|
+
expect(uuidType.parse(formatedUuid).value).to.equal(undformatedUuid);
|
|
12
|
+
});
|
|
13
|
+
it("should return defaultValue if value is undefined in parse()", () => {
|
|
14
|
+
uuidType._defaultValue = "00000000-0000-0000-0000-000000000000";
|
|
15
|
+
// @ts-expect-error: Testing undefined input
|
|
16
|
+
expect(uuidType.parse(undefined).value).to.equal(uuidType.defaultValue);
|
|
17
|
+
});
|
|
18
|
+
it("should handle empty string in parse()", () => {
|
|
19
|
+
uuidType._defaultValue = "00000000000000000000000000000000";
|
|
20
|
+
// @ts-expect-error: is not assignable to parameter of type '`${string}-${string}-${string}-${string}-${string}`'.
|
|
21
|
+
expect(uuidType.parse("").value).to.equal(uuidType._defaultValue);
|
|
22
|
+
});
|
|
23
|
+
it("should throw error for invalid UUID in parse()", () => {
|
|
24
|
+
expect(() => uuidType.parse("INVALID0-UUID-0000-0000-000000000000").value).to.throw();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=UuidType.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UuidType.spec.js","sourceRoot":"","sources":["../../src/types/UuidType.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACtB,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,MAAM,eAAe,GAAG,kCAAkC,CAAC;IAC3D,MAAM,YAAY,GAAG,sCAAsC,CAAC;IAE5D,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACnE,QAAQ,CAAC,aAAa,GAAG,sCAAsC,CAAC;QAChE,4CAA4C;QAC5C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,QAAQ,CAAC,aAAa,GAAG,kCAAkC,CAAC;QAC5D,mHAAmH;QACnH,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAC1F,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from \"chai\";\nimport { UUIDType } from \"./UuidType.js\";\n\ndescribe(\"UUIDType\", () => {\n const uuidType = new UUIDType();\n const undformatedUuid = \"123e4567e89b12d3a456426614174000\";\n const formatedUuid = \"123e4567-e89b-12d3-a456-426614174000\";\n\n it(\"should return the value as is in format()\", () => {\n expect(uuidType.format(undformatedUuid)).to.equal(formatedUuid);\n });\n\n it(\"should return the value as is in parse()\", () => {\n expect(uuidType.parse(formatedUuid).value).to.equal(undformatedUuid);\n });\n\n it(\"should return defaultValue if value is undefined in parse()\", () => {\n uuidType._defaultValue = \"00000000-0000-0000-0000-000000000000\";\n // @ts-expect-error: Testing undefined input\n expect(uuidType.parse(undefined).value).to.equal(uuidType.defaultValue);\n });\n\n it(\"should handle empty string in parse()\", () => {\n uuidType._defaultValue = \"00000000000000000000000000000000\";\n // @ts-expect-error: is not assignable to parameter of type '`${string}-${string}-${string}-${string}-${string}`'.\n expect(uuidType.parse(\"\").value).to.equal(uuidType._defaultValue);\n });\n it(\"should throw error for invalid UUID in parse()\", () => {\n expect(() => uuidType.parse(\"INVALID0-UUID-0000-0000-000000000000\").value).to.throw();\n });\n});"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AttributeType, AttributeTypeOptions, ParseAndValidationCriticality, ParseAndValidationResult, parseResult } from "./AttributeType.js";
|
|
2
|
+
export type ArrayTypeOptions = AttributeTypeOptions<any[]> & {
|
|
3
|
+
type: AttributeType<any, any>;
|
|
4
|
+
};
|
|
5
|
+
export declare abstract class ArrayType<InternalType, ExternalType> extends AttributeType<InternalType[], ExternalType[]> {
|
|
6
|
+
abstract type: AttributeType<InternalType, ExternalType>;
|
|
7
|
+
constructor(options?: ArrayTypeOptions);
|
|
8
|
+
parse(value: ExternalType[]): parseResult<InternalType[]>;
|
|
9
|
+
validate(value: InternalType[], level?: ParseAndValidationCriticality): Promise<ParseAndValidationResult>;
|
|
10
|
+
format(value: InternalType[]): ExternalType[];
|
|
11
|
+
}
|