Add several serialization type specs

This commit is contained in:
Dan Schulte 2018-04-10 15:22:08 -07:00
Родитель 91be3847b4
Коммит 74f45c6c96
100 изменённых файлов: 1808 добавлений и 0 удалений

19
dist/lib/serialization/booleanSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a boolean.
*/
var booleanSpec = {
typeName: "boolean",
serialize: function (propertyPath, value) {
if (typeof value !== "boolean") {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "of type boolean"));
}
return value;
}
};
exports.default = booleanSpec;
//# sourceMappingURL=booleanSpec.js.map

1
dist/lib/serialization/booleanSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"booleanSpec.js","sourceRoot":"","sources":["../../../lib/serialization/booleanSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,WAAW,GAAsB;IACnC,QAAQ,EAAE,SAAS;IAEnB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC;SACzF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,WAAW,CAAC"}

19
dist/lib/serialization/dateSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a Date.
*/
var dateSpec = {
typeName: "Date",
serialize: function (propertyPath, value) {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an instanceof Date or a string in ISO8601 format"));
}
return (value instanceof Date ? value : new Date(value)).toISOString().substring(0, 10);
}
};
exports.default = dateSpec;
//# sourceMappingURL=dateSpec.js.map

1
dist/lib/serialization/dateSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateSpec.js","sourceRoot":"","sources":["../../../lib/serialization/dateSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,QAAQ,GAAqB;IAC/B,QAAQ,EAAE,MAAM;IAEhB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACjG,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,kDAAkD,CAAC,CAAC,CAAC;SAC1H;QACD,OAAO,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5F,CAAC;CACJ,CAAC;AAEF,kBAAe,QAAQ,CAAC"}

19
dist/lib/serialization/dateTimeRfc1123Spec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a Date.
*/
var dateTimeRfc1123Spec = {
typeName: "DateTimeRFC1123",
serialize: function (propertyPath, value) {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an instanceof Date or a string in ISO8601 format"));
}
return (value instanceof Date ? value : new Date(value)).toUTCString();
}
};
exports.default = dateTimeRfc1123Spec;
//# sourceMappingURL=dateTimeRfc1123Spec.js.map

1
dist/lib/serialization/dateTimeRfc1123Spec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateTimeRfc1123Spec.js","sourceRoot":"","sources":["../../../lib/serialization/dateTimeRfc1123Spec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,mBAAmB,GAAqB;IAC1C,QAAQ,EAAE,iBAAiB;IAE3B,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACjG,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,kDAAkD,CAAC,CAAC,CAAC;SAC1H;QACD,OAAO,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3E,CAAC;CACJ,CAAC;AAEF,kBAAe,mBAAmB,CAAC"}

19
dist/lib/serialization/dateTimeSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a Date.
*/
var dateTimeSpec = {
typeName: "DateTime",
serialize: function (propertyPath, value) {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an instanceof Date or a string in ISO8601 format"));
}
return (value instanceof Date ? value : new Date(value)).toISOString();
}
};
exports.default = dateTimeSpec;
//# sourceMappingURL=dateTimeSpec.js.map

1
dist/lib/serialization/dateTimeSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateTimeSpec.js","sourceRoot":"","sources":["../../../lib/serialization/dateTimeSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,YAAY,GAAqB;IACnC,QAAQ,EAAE,UAAU;IAEpB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACjG,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,kDAAkD,CAAC,CAAC,CAAC;SAC1H;QACD,OAAO,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3E,CAAC;CACJ,CAAC;AAEF,kBAAe,YAAY,CAAC"}

25
dist/lib/serialization/enumSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize an object.
*/
function enumSpec(enumName, allowedValues) {
return {
typeName: "Enum<" + enumName + ">",
allowedValues: allowedValues,
serialize: function (propertyPath, value) {
var foundMatch = allowedValues.some(function (item) {
return item === value || (typeof item === "string" && typeof value === "string" && item.toLowerCase() === value.toLowerCase());
});
if (!foundMatch) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "one of the enum allowed values: " + JSON.stringify(allowedValues)));
}
return value;
}
};
}
exports.enumSpec = enumSpec;
//# sourceMappingURL=enumSpec.js.map

1
dist/lib/serialization/enumSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"enumSpec.js","sourceRoot":"","sources":["../../../lib/serialization/enumSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,kBAA4B,QAAgB,EAAE,aAAkB;IAC5D,OAAO;QACH,QAAQ,EAAE,UAAQ,QAAQ,MAAG;QAE7B,aAAa,EAAE,aAAa;QAE5B,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;YACxC,IAAM,UAAU,GAAY,aAAa,CAAC,IAAI,CAAC,UAAC,IAAI;gBAChD,OAAO,IAAI,KAAK,KAAK,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;YACnI,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,EAAE;gBACb,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,qCAAmC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAG,CAAC,CAAC,CAAC;aAC1I;YACD,OAAO,KAAK,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC;AAhBD,4BAgBC"}

19
dist/lib/serialization/numberSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a number.
*/
var numberSpec = {
typeName: "number",
serialize: function (propertyPath, value) {
if (typeof value !== "number") {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "of type number"));
}
return value;
}
};
exports.default = numberSpec;
//# sourceMappingURL=numberSpec.js.map

1
dist/lib/serialization/numberSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"numberSpec.js","sourceRoot":"","sources":["../../../lib/serialization/numberSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,UAAU,GAAqB;IACjC,QAAQ,EAAE,QAAQ;IAElB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;SACxF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,UAAU,CAAC"}

19
dist/lib/serialization/objectSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize an object.
*/
var objectSpec = {
typeName: "object",
serialize: function (propertyPath, value) {
if (typeof value !== "object" || Array.isArray(value)) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an object"));
}
return value;
}
};
exports.default = objectSpec;
//# sourceMappingURL=objectSpec.js.map

1
dist/lib/serialization/objectSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"objectSpec.js","sourceRoot":"","sources":["../../../lib/serialization/objectSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,UAAU,GAAiB;IAC7B,QAAQ,EAAE,QAAQ;IAElB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACnD,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;SACnF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,UAAU,CAAC"}

20
dist/lib/serialization/streamSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var isStream = require("is-stream");
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a Stream.
*/
var streamSpec = {
typeName: "Stream",
serialize: function (propertyPath, value) {
if (!isStream(value)) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "a Stream"));
}
return value;
}
};
exports.default = streamSpec;
//# sourceMappingURL=streamSpec.js.map

1
dist/lib/serialization/streamSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"streamSpec.js","sourceRoot":"","sources":["../../../lib/serialization/streamSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,oCAAsC;AACtC,uCAAoE;AAEpE;;GAEG;AACH,IAAM,UAAU,GAAkB;IAC9B,QAAQ,EAAE,QAAQ;IAElB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;SAClF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,UAAU,CAAC"}

19
dist/lib/serialization/stringSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a string.
*/
var stringSpec = {
typeName: "string",
serialize: function (propertyPath, value) {
if (typeof value !== "string") {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "of type string"));
}
return value;
}
};
exports.default = stringSpec;
//# sourceMappingURL=stringSpec.js.map

1
dist/lib/serialization/stringSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"stringSpec.js","sourceRoot":"","sources":["../../../lib/serialization/stringSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,UAAU,GAAqB;IACjC,QAAQ,EAAE,QAAQ;IAElB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;SACxF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,UAAU,CAAC"}

20
dist/lib/serialization/timeSpanSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
var moment_1 = require("moment");
/**
* A type specification that describes how to validate and serialize a Date.
*/
var timeSpanSpec = {
typeName: "TimeSpan",
serialize: function (propertyPath, value) {
if (!value || (!moment_1.isDuration(value) && !(value.constructor && value.constructor.name === "Duration" && typeof value.isValid === "function" && value.isValid()))) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "a TimeSpan/Duration"));
}
return value.toISOString();
}
};
exports.default = timeSpanSpec;
//# sourceMappingURL=timeSpanSpec.js.map

1
dist/lib/serialization/timeSpanSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"timeSpanSpec.js","sourceRoot":"","sources":["../../../lib/serialization/timeSpanSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AACpE,iCAAoC;AAEpC;;GAEG;AACH,IAAM,YAAY,GAAqB;IACnC,QAAQ,EAAE,UAAU;IAEpB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,mBAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YAC3J,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC;SAC7F;QACD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC;CACJ,CAAC;AAEF,kBAAe,YAAY,CAAC"}

15
dist/lib/serialization/typeSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,15 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Create an error message for an invalid serialization.
* @param propertyPath The path to the property with the serialization error.
* @param value The value that failed the serialization.
* @param expectedConditionDescription A brief description of what type was expected.
*/
function createValidationErrorMessage(propertyPath, value, expectedConditionDescription) {
return "Property " + propertyPath.join(".") + " with value " + JSON.stringify(value) + " must be " + expectedConditionDescription + ".";
}
exports.createValidationErrorMessage = createValidationErrorMessage;
//# sourceMappingURL=typeSpec.js.map

1
dist/lib/serialization/typeSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"typeSpec.js","sourceRoot":"","sources":["../../../lib/serialization/typeSpec.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AA0B/F;;;;;GAKG;AACH,sCAA6C,YAAsB,EAAE,KAAU,EAAE,4BAAoC;IACjH,OAAO,cAAY,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAY,4BAA4B,MAAG,CAAC;AAC7H,CAAC;AAFD,oEAEC"}

20
dist/lib/serialization/unixTimeSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
/**
* A type specification that describes how to validate and serialize a Date.
*/
var unixTimeSpec = {
typeName: "UnixTime",
serialize: function (propertyPath, value) {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an instanceof Date or a string in ISO8601 format"));
}
var valueDate = (value instanceof Date ? value : new Date(value));
return Math.floor(valueDate.getTime() / 1000);
}
};
exports.default = unixTimeSpec;
//# sourceMappingURL=unixTimeSpec.js.map

1
dist/lib/serialization/unixTimeSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"unixTimeSpec.js","sourceRoot":"","sources":["../../../lib/serialization/unixTimeSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AAEpE;;GAEG;AACH,IAAM,YAAY,GAAqB;IACnC,QAAQ,EAAE,UAAU;IAEpB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACjG,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,kDAAkD,CAAC,CAAC,CAAC;SAC1H;QACD,IAAM,SAAS,GAAS,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,CAAC;CACJ,CAAC;AAEF,kBAAe,YAAY,CAAC"}

20
dist/lib/serialization/uuidSpec.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var typeSpec_1 = require("./typeSpec");
var utils = require("../util/utils");
/**
* A type specification that describes how to validate and serialize an UUID.
*/
var uuidSpec = {
typeName: "UUID",
serialize: function (propertyPath, value) {
if (typeof value !== "string" || !utils.isValidUuid(value)) {
throw new Error(typeSpec_1.createValidationErrorMessage(propertyPath, value, "an UUID"));
}
return value;
}
};
exports.default = uuidSpec;
//# sourceMappingURL=uuidSpec.js.map

1
dist/lib/serialization/uuidSpec.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"uuidSpec.js","sourceRoot":"","sources":["../../../lib/serialization/uuidSpec.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,uCAAoE;AACpE,qCAAuC;AAEvC;;GAEG;AACH,IAAM,QAAQ,GAAqB;IAC/B,QAAQ,EAAE,MAAM;IAEhB,SAAS,EAAT,UAAU,YAAsB,EAAE,KAAU;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;YACxD,MAAM,IAAI,KAAK,CAAC,uCAA4B,CAAC,YAAY,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;SACjF;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAC;AAEF,kBAAe,QAAQ,CAAC"}

35
dist/test/serialization/booleanSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var booleanSpec_1 = require("../../lib/serialization/booleanSpec");
describe("booleanSpec", function () {
it("should have \"boolean\" for its typeName property", function () {
assert.strictEqual("boolean", booleanSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
booleanSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type boolean.");
}
});
it("should throw an error when given 5", function () {
try {
booleanSpec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be of type boolean.");
}
});
it("should return the provided value with no error when given true", function () {
assert.strictEqual(booleanSpec_1.default.serialize(["this", "one", "works"], true), true);
});
});
});
//# sourceMappingURL=booleanSpecTests.js.map

1
dist/test/serialization/booleanSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"booleanSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/booleanSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,mEAA8D;AAE9D,QAAQ,CAAC,aAAa,EAAE;IACpB,EAAE,CAAC,mDAAmD,EAAE;QACpD,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,qBAAW,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,qBAAW,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC5D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,wEAAwE,CAAC,CAAC;aAC/G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,qBAAW,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,sEAAsE,CAAC,CAAC;aAC7G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gEAAgE,EAAE;YACjE,MAAM,CAAC,WAAW,CAAC,qBAAW,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

56
dist/test/serialization/dateSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var dateSpec_1 = require("../../lib/serialization/dateSpec");
describe("dateSpec", function () {
it("should have \"Date\" for its typeName property", function () {
assert.strictEqual("Date", dateSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
dateSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", function () {
try {
dateSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", function () {
try {
dateSpec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", function () {
try {
dateSpec_1.default.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", function () {
assert.strictEqual(dateSpec_1.default.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "2011-10-05");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", function () {
assert.strictEqual(dateSpec_1.default.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "2011-10-05");
});
});
});
//# sourceMappingURL=dateSpecTests.js.map

1
dist/test/serialization/dateSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/dateSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,6DAAwD;AAExD,QAAQ,CAAC,UAAU,EAAE;IACjB,EAAE,CAAC,gDAAgD,EAAE;QACjD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,kBAAQ,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBACzD,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yGAAyG,CAAC,CAAC;aAChJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,2GAA2G,CAAC,CAAC;aAClJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBACvD,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uGAAuG,CAAC,CAAC;aAC9I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE;YACpD,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;gBACpE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,sHAAsH,CAAC,CAAC;aAC7J;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mFAAmF,EAAE;YACpF,MAAM,CAAC,WAAW,CAAC,kBAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,0BAA0B,CAAC,EAAE,YAAY,CAAC,CAAC;QAC/G,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wGAAwG,EAAE;YACzG,MAAM,CAAC,WAAW,CAAC,kBAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;QACzH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

56
dist/test/serialization/dateTimeRfc1123SpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var dateTimeRfc1123Spec_1 = require("../../lib/serialization/dateTimeRfc1123Spec");
describe("dateTimeRfc1123Spec", function () {
it("should have \"DateTimeRFC1123\" for its typeName property", function () {
assert.strictEqual("DateTimeRFC1123", dateTimeRfc1123Spec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
dateTimeRfc1123Spec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", function () {
try {
dateTimeRfc1123Spec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", function () {
try {
dateTimeRfc1123Spec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", function () {
try {
dateTimeRfc1123Spec_1.default.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", function () {
assert.strictEqual(dateTimeRfc1123Spec_1.default.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "Wed, 05 Oct 2011 14:48:00 GMT");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", function () {
assert.strictEqual(dateTimeRfc1123Spec_1.default.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "Wed, 05 Oct 2011 14:48:00 GMT");
});
});
});
//# sourceMappingURL=dateTimeRfc1123SpecTests.js.map

1
dist/test/serialization/dateTimeRfc1123SpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateTimeRfc1123SpecTests.js","sourceRoot":"","sources":["../../../test/serialization/dateTimeRfc1123SpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,mFAA8E;AAE9E,QAAQ,CAAC,qBAAqB,EAAE;IAC5B,EAAE,CAAC,2DAA2D,EAAE;QAC5D,MAAM,CAAC,WAAW,CAAC,iBAAiB,EAAE,6BAAmB,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,6BAAmB,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBACpE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yGAAyG,CAAC,CAAC;aAChJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,6BAAmB,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBACtE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,2GAA2G,CAAC,CAAC;aAClJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,6BAAmB,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uGAAuG,CAAC,CAAC;aAC9I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE;YACpD,IAAI;gBACA,6BAAmB,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC/E,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,sHAAsH,CAAC,CAAC;aAC7J;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mFAAmF,EAAE;YACpF,MAAM,CAAC,WAAW,CAAC,6BAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,0BAA0B,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC7I,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wGAAwG,EAAE;YACzG,MAAM,CAAC,WAAW,CAAC,6BAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,EAAE,+BAA+B,CAAC,CAAC;QACvJ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

56
dist/test/serialization/dateTimeSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var dateTimeSpec_1 = require("../../lib/serialization/dateTimeSpec");
describe("dateTimeSpec", function () {
it("should have \"DateTime\" for its typeName property", function () {
assert.strictEqual("DateTime", dateTimeSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
dateTimeSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", function () {
try {
dateTimeSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", function () {
try {
dateTimeSpec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", function () {
try {
dateTimeSpec_1.default.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", function () {
assert.strictEqual(dateTimeSpec_1.default.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "2011-10-05T14:48:00.000Z");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", function () {
assert.strictEqual(dateTimeSpec_1.default.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "2011-10-05T14:48:00.000Z");
});
});
});
//# sourceMappingURL=dateTimeSpecTests.js.map

1
dist/test/serialization/dateTimeSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"dateTimeSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/dateTimeSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,qEAAgE;AAEhE,QAAQ,CAAC,cAAc,EAAE;IACrB,EAAE,CAAC,oDAAoD,EAAE;QACrD,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yGAAyG,CAAC,CAAC;aAChJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC/D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,2GAA2G,CAAC,CAAC;aAClJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uGAAuG,CAAC,CAAC;aAC9I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE;YACpD,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,sHAAsH,CAAC,CAAC;aAC7J;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mFAAmF,EAAE;YACpF,MAAM,CAAC,WAAW,CAAC,sBAAY,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,0BAA0B,CAAC,EAAE,0BAA0B,CAAC,CAAC;QACjI,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wGAAwG,EAAE;YACzG,MAAM,CAAC,WAAW,CAAC,sBAAY,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC;QAC3I,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

38
dist/test/serialization/enumSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var enumSpec_1 = require("../../lib/serialization/enumSpec");
describe("enumSpec", function () {
it("should have \"Enum<Letters>\" for its typeName property", function () {
assert.strictEqual("Enum<Letters>", enumSpec_1.enumSpec("Letters", []).typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
enumSpec_1.enumSpec("Letters", ["a", "b", "c"]).serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be one of the enum allowed values: [\"a\",\"b\",\"c\"].");
}
});
it("should throw an error when given \"\"", function () {
try {
enumSpec_1.enumSpec("Letters", ["a", "b", "c"]).serialize(["another", "property", "path"], "");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"\" must be one of the enum allowed values: [\"a\",\"b\",\"c\"].");
}
});
it("should return the provided value with no error when given \"a\"", function () {
assert.strictEqual(enumSpec_1.enumSpec("Letters", ["a", "b", "c"]).serialize(["this", "one", "works"], "a"), "a");
});
it("should return the provided value with no error when given \"A\"", function () {
assert.strictEqual(enumSpec_1.enumSpec("Letters", ["a", "b", "c"]).serialize(["this", "one", "works"], "A"), "A");
});
});
});
//# sourceMappingURL=enumSpecTests.js.map

1
dist/test/serialization/enumSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"enumSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/enumSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,6DAA4D;AAE5D,QAAQ,CAAC,UAAU,EAAE;IACjB,EAAE,CAAC,yDAAyD,EAAE;QAC1D,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,mBAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,mBAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBACrF,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,4GAAsG,CAAC,CAAC;aAC7I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE;YACxC,IAAI;gBACA,mBAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBACpF,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,6GAAuG,CAAC,CAAC;aAC9I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE;YAClE,MAAM,CAAC,WAAW,CAAC,mBAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3G,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE;YAClE,MAAM,CAAC,WAAW,CAAC,mBAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3G,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

35
dist/test/serialization/numberSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var numberSpec_1 = require("../../lib/serialization/numberSpec");
describe("numberSpec", function () {
it("should have \"number\" for its typeName property", function () {
assert.strictEqual("number", numberSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
numberSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type number.");
}
});
it("should throw an error when given \"\"", function () {
try {
numberSpec_1.default.serialize(["another", "property", "path"], "");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"\" must be of type number.");
}
});
it("should return the provided value with no error when given 12", function () {
assert.strictEqual(numberSpec_1.default.serialize(["this", "one", "works"], 12), 12);
});
});
});
//# sourceMappingURL=numberSpecTests.js.map

1
dist/test/serialization/numberSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"numberSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/numberSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,iEAA4D;AAE5D,QAAQ,CAAC,YAAY,EAAE;IACnB,EAAE,CAAC,kDAAkD,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,oBAAU,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uEAAuE,CAAC,CAAC;aAC9G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE;YACxC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,wEAAwE,CAAC,CAAC;aAC/G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA8D,EAAE;YAC/D,MAAM,CAAC,WAAW,CAAC,oBAAU,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

44
dist/test/serialization/objectSpecTest.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var objectSpec_1 = require("../../lib/serialization/objectSpec");
describe("objectSpec", function () {
it("should have \"object\" for its typeName property", function () {
assert.strictEqual("object", objectSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
objectSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an object.");
}
});
it("should throw an error when given false", function () {
try {
objectSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an object.");
}
});
it("should throw an error when given []", function () {
try {
objectSpec_1.default.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be an object.");
}
});
it("should return the provided value with no error when given {}", function () {
assert.deepEqual(objectSpec_1.default.serialize(["this", "one", "works"], {}), {});
});
});
});
//# sourceMappingURL=objectSpecTest.js.map

1
dist/test/serialization/objectSpecTest.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"objectSpecTest.js","sourceRoot":"","sources":["../../../test/serialization/objectSpecTest.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,iEAA4D;AAE5D,QAAQ,CAAC,YAAY,EAAE;IACnB,EAAE,CAAC,kDAAkD,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,oBAAU,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,kEAAkE,CAAC,CAAC;aACzG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,oEAAoE,CAAC,CAAC;aAC3G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE;YACtC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,iEAAiE,CAAC,CAAC;aACxG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA8D,EAAE;YAC/D,MAAM,CAAC,SAAS,CAAC,oBAAU,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

50
dist/test/serialization/streamSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var streamSpec_1 = require("../../lib/serialization/streamSpec");
describe("objectSpec", function () {
it("should have \"Stream\" for its typeName property", function () {
assert.strictEqual("Stream", streamSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
streamSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be a Stream.");
}
});
it("should throw an error when given false", function () {
try {
streamSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be a Stream.");
}
});
it("should throw an error when given {}", function () {
try {
streamSpec_1.default.serialize(["another", "property", "path"], {});
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value {} must be a Stream.");
}
});
it("should throw an error when given []", function () {
try {
streamSpec_1.default.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be a Stream.");
}
});
});
});
//# sourceMappingURL=streamSpecTests.js.map

1
dist/test/serialization/streamSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"streamSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/streamSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,iEAA4D;AAE5D,QAAQ,CAAC,YAAY,EAAE;IACnB,EAAE,CAAC,kDAAkD,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,oBAAU,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,iEAAiE,CAAC,CAAC;aACxG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,mEAAmE,CAAC,CAAC;aAC1G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE;YACtC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,gEAAgE,CAAC,CAAC;aACvG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE;YACtC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,gEAAgE,CAAC,CAAC;aACvG;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

35
dist/test/serialization/stringSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var stringSpec_1 = require("../../lib/serialization/stringSpec");
describe("stringSpec", function () {
it("should have \"string\" for its typeName property", function () {
assert.strictEqual("string", stringSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
stringSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type string.");
}
});
it("should throw an error when given false", function () {
try {
stringSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be of type string.");
}
});
it("should return the provided value with no error when given \"abc\"", function () {
assert.strictEqual(stringSpec_1.default.serialize(["this", "one", "works"], "abc"), "abc");
});
});
});
//# sourceMappingURL=stringSpecTests.js.map

1
dist/test/serialization/stringSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"stringSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/stringSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,iEAA4D;AAE5D,QAAQ,CAAC,YAAY,EAAE;IACnB,EAAE,CAAC,kDAAkD,EAAE;QACnD,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,oBAAU,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uEAAuE,CAAC,CAAC;aAC9G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,oBAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yEAAyE,CAAC,CAAC;aAChH;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mEAAmE,EAAE;YACpE,MAAM,CAAC,WAAW,CAAC,oBAAU,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACrF,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

63
dist/test/serialization/timeSpanSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var moment = require("moment");
var timeSpanSpec_1 = require("../../lib/serialization/timeSpanSpec");
describe("timeSpanSpec", function () {
it("should have \"TimeSpan\" for its typeName property", function () {
assert.strictEqual("TimeSpan", timeSpanSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
timeSpanSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be a TimeSpan/Duration.");
}
});
it("should throw an error when given false", function () {
try {
timeSpanSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be a TimeSpan/Duration.");
}
});
it("should throw an error when given 5", function () {
try {
timeSpanSpec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be a TimeSpan/Duration.");
}
});
it("should throw an error when given \"hello world!\"", function () {
try {
timeSpanSpec_1.default.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be a TimeSpan/Duration.");
}
});
it("should throw an error when given an ISO 8601 time span string", function () {
try {
timeSpanSpec_1.default.serialize(["another", "property", "path"], "P123DT22H14M12.011S");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"P123DT22H14M12.011S\" must be a TimeSpan/Duration.");
}
});
it("should return the ISO 8601 string representation of the provided value with no error when given a moment.Duration", function () {
assert.strictEqual(timeSpanSpec_1.default.serialize(["this", "one", "works"], moment.duration({ days: 123, hours: 22, minutes: 14, seconds: 12, milliseconds: 11 })), "P123DT22H14M12.011S");
});
});
});
//# sourceMappingURL=timeSpanSpecTests.js.map

1
dist/test/serialization/timeSpanSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"timeSpanSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/timeSpanSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,+BAAiC;AACjC,qEAAgE;AAEhE,QAAQ,CAAC,cAAc,EAAE;IACrB,EAAE,CAAC,oDAAoD,EAAE;QACrD,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,4EAA4E,CAAC,CAAC;aACnH;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC/D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,8EAA8E,CAAC,CAAC;aACrH;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,0EAA0E,CAAC,CAAC;aACjH;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE;YACpD,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yFAAyF,CAAC,CAAC;aAChI;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+DAA+D,EAAE;YAChE,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,qBAAqB,CAAC,CAAC;gBAC/E,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,gGAAgG,CAAC,CAAC;aACvI;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mHAAmH,EAAE;YACpH,MAAM,CAAC,WAAW,CAAC,sBAAY,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;QACvL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

56
dist/test/serialization/unixTimeSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var unixTimeSpec_1 = require("../../lib/serialization/unixTimeSpec");
describe("unixTimeSpec", function () {
it("should have \"UnixTime\" for its typeName property", function () {
assert.strictEqual("UnixTime", unixTimeSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
unixTimeSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", function () {
try {
unixTimeSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", function () {
try {
unixTimeSpec_1.default.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", function () {
try {
unixTimeSpec_1.default.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", function () {
assert.strictEqual(unixTimeSpec_1.default.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), 1317826080);
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", function () {
assert.strictEqual(unixTimeSpec_1.default.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), 1317826080);
});
});
});
//# sourceMappingURL=unixTimeSpecTests.js.map

1
dist/test/serialization/unixTimeSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"unixTimeSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/unixTimeSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,qEAAgE;AAEhE,QAAQ,CAAC,cAAc,EAAE;IACrB,EAAE,CAAC,oDAAoD,EAAE;QACrD,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,sBAAY,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBAC7D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,yGAAyG,CAAC,CAAC;aAChJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC/D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,2GAA2G,CAAC,CAAC;aAClJ;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE;YACrC,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,uGAAuG,CAAC,CAAC;aAC9I;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE;YACpD,IAAI;gBACA,sBAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;gBACxE,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,sHAAsH,CAAC,CAAC;aAC7J;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mFAAmF,EAAE;YACpF,MAAM,CAAC,WAAW,CAAC,sBAAY,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,0BAA0B,CAAC,EAAE,UAAU,CAAC,CAAC;QACjH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wGAAwG,EAAE;YACzG,MAAM,CAAC,WAAW,CAAC,sBAAY,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAC3H,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

53
dist/test/serialization/uuidSpecTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var uuidSpec_1 = require("../../lib/serialization/uuidSpec");
describe("uuidSpec", function () {
it("should have \"UUID\" for its typeName property", function () {
assert.strictEqual("UUID", uuidSpec_1.default.typeName);
});
describe("serialize()", function () {
it("should throw an error when given undefined", function () {
try {
uuidSpec_1.default.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an UUID.");
}
});
it("should throw an error when given false", function () {
try {
uuidSpec_1.default.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an UUID.");
}
});
it("should throw an error when given []", function () {
try {
uuidSpec_1.default.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be an UUID.");
}
});
it("should throw an error when given \"abc\"", function () {
try {
uuidSpec_1.default.serialize(["another", "property", "path"], "abc");
assert.fail("Expected an error to be thrown.");
}
catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"abc\" must be an UUID.");
}
});
it("should return the provided value with no error when given \"123e4567-e89b-12d3-a456-426655440000\"", function () {
assert.deepEqual(uuidSpec_1.default.serialize(["this", "one", "works"], "123e4567-e89b-12d3-a456-426655440000"), "123e4567-e89b-12d3-a456-426655440000");
});
});
});
//# sourceMappingURL=uuidSpecTests.js.map

1
dist/test/serialization/uuidSpecTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"uuidSpecTests.js","sourceRoot":"","sources":["../../../test/serialization/uuidSpecTests.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,6DAAwD;AAExD,QAAQ,CAAC,UAAU,EAAE;IACjB,EAAE,CAAC,gDAAgD,EAAE;QACjD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,kBAAQ,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA4C,EAAE;YAC7C,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;gBACzD,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,gEAAgE,CAAC,CAAC;aACvG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE;YACzC,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,kEAAkE,CAAC,CAAC;aACzG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qCAAqC,EAAE;YACtC,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxD,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,+DAA+D,CAAC,CAAC;aACtG;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE;YAC3C,IAAI;gBACA,kBAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,oEAAoE,CAAC,CAAC;aAC3G;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oGAAoG,EAAE;YACrG,MAAM,CAAC,SAAS,CAAC,kBAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,sCAAsC,CAAC,EAAE,sCAAsC,CAAC,CAAC;QACnJ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a boolean.
*/
const booleanSpec: TypeSpec<boolean> = {
typeName: "boolean",
serialize(propertyPath: string[], value: any): boolean {
if (typeof value !== "boolean") {
throw new Error(createValidationErrorMessage(propertyPath, value, "of type boolean"));
}
return value;
}
};
export default booleanSpec;

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
const dateSpec: TypeSpec<string> = {
typeName: "Date",
serialize(propertyPath: string[], value: any): string {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(createValidationErrorMessage(propertyPath, value, `an instanceof Date or a string in ISO8601 format`));
}
return (value instanceof Date ? value : new Date(value)).toISOString().substring(0, 10);
}
};
export default dateSpec;

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
const dateTimeRfc1123Spec: TypeSpec<string> = {
typeName: "DateTimeRFC1123",
serialize(propertyPath: string[], value: any): string {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(createValidationErrorMessage(propertyPath, value, `an instanceof Date or a string in ISO8601 format`));
}
return (value instanceof Date ? value : new Date(value)).toUTCString();
}
};
export default dateTimeRfc1123Spec;

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
const dateTimeSpec: TypeSpec<string> = {
typeName: "DateTime",
serialize(propertyPath: string[], value: any): string {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(createValidationErrorMessage(propertyPath, value, `an instanceof Date or a string in ISO8601 format`));
}
return (value instanceof Date ? value : new Date(value)).toISOString();
}
};
export default dateTimeSpec;

Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize an object.
*/
export function enumSpec<T>(enumName: string, allowedValues: T[]): TypeSpec<T> {
return {
typeName: `Enum<${enumName}>`,
allowedValues: allowedValues,
serialize(propertyPath: string[], value: any): T {
const foundMatch: boolean = allowedValues.some((item) => {
return item === value || (typeof item === "string" && typeof value === "string" && item.toLowerCase() === value.toLowerCase());
});
if (!foundMatch) {
throw new Error(createValidationErrorMessage(propertyPath, value, `one of the enum allowed values: ${JSON.stringify(allowedValues)}`));
}
return value;
}
};
}

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a number.
*/
const numberSpec: TypeSpec<number> = {
typeName: "number",
serialize(propertyPath: string[], value: any): number {
if (typeof value !== "number") {
throw new Error(createValidationErrorMessage(propertyPath, value, "of type number"));
}
return value;
}
};
export default numberSpec;

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize an object.
*/
const objectSpec: TypeSpec<{}> = {
typeName: "object",
serialize(propertyPath: string[], value: any): {} {
if (typeof value !== "object" || Array.isArray(value)) {
throw new Error(createValidationErrorMessage(propertyPath, value, "an object"));
}
return value;
}
};
export default objectSpec;

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as isStream from "is-stream";
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Stream.
*/
const streamSpec: TypeSpec<any> = {
typeName: "Stream",
serialize(propertyPath: string[], value: any): any {
if (!isStream(value)) {
throw new Error(createValidationErrorMessage(propertyPath, value, "a Stream"));
}
return value;
}
};
export default streamSpec;

Просмотреть файл

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a string.
*/
const stringSpec: TypeSpec<string> = {
typeName: "string",
serialize(propertyPath: string[], value: any): string {
if (typeof value !== "string") {
throw new Error(createValidationErrorMessage(propertyPath, value, "of type string"));
}
return value;
}
};
export default stringSpec;

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
import { isDuration } from "moment";
/**
* A type specification that describes how to validate and serialize a Date.
*/
const timeSpanSpec: TypeSpec<string> = {
typeName: "TimeSpan",
serialize(propertyPath: string[], value: any): string {
if (!value || (!isDuration(value) && !(value.constructor && value.constructor.name === "Duration" && typeof value.isValid === "function" && value.isValid()))) {
throw new Error(createValidationErrorMessage(propertyPath, value, `a TimeSpan/Duration`));
}
return value.toISOString();
}
};
export default timeSpanSpec;

Просмотреть файл

@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
/**
* A type specification that describes how to validate and serialize an object of a given type.
*/
export interface TypeSpec<TSerialized> {
/**
* The name of the type that this TypeSpec validates.
*/
typeName: string;
/**
* The values that are allowed for this TypeSpec. If this is undefined, then all values of the
* correct type are valid.
*/
allowedValues?: TSerialized[];
/**
* Validate and serialize the provided value into the return type T.
* @param propertyPath The path from the root of the type being serialized down to this
* property.
* @param value The value to validate and serialize.
*/
serialize(propertyPath: string[], value: any): TSerialized;
}
/**
* Create an error message for an invalid serialization.
* @param propertyPath The path to the property with the serialization error.
* @param value The value that failed the serialization.
* @param expectedConditionDescription A brief description of what type was expected.
*/
export function createValidationErrorMessage(propertyPath: string[], value: any, expectedConditionDescription: string): string {
return `Property ${propertyPath.join(".")} with value ${JSON.stringify(value)} must be ${expectedConditionDescription}.`;
}

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
const unixTimeSpec: TypeSpec<number> = {
typeName: "UnixTime",
serialize(propertyPath: string[], value: any): number {
if (!value || (!(value instanceof Date) && (typeof value !== "string" || isNaN(Date.parse(value))))) {
throw new Error(createValidationErrorMessage(propertyPath, value, `an instanceof Date or a string in ISO8601 format`));
}
const valueDate: Date = (value instanceof Date ? value : new Date(value));
return Math.floor(valueDate.getTime() / 1000);
}
};
export default unixTimeSpec;

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { TypeSpec, createValidationErrorMessage } from "./typeSpec";
import * as utils from "../util/utils";
/**
* A type specification that describes how to validate and serialize an UUID.
*/
const uuidSpec: TypeSpec<string> = {
typeName: "UUID",
serialize(propertyPath: string[], value: any): string {
if (typeof value !== "string" || !utils.isValidUuid(value)) {
throw new Error(createValidationErrorMessage(propertyPath, value, "an UUID"));
}
return value;
}
};
export default uuidSpec;

Просмотреть файл

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import booleanSpec from "../../lib/serialization/booleanSpec";
describe("booleanSpec", () => {
it("should have \"boolean\" for its typeName property", () => {
assert.strictEqual("boolean", booleanSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
booleanSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type boolean.");
}
});
it("should throw an error when given 5", () => {
try {
booleanSpec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be of type boolean.");
}
});
it("should return the provided value with no error when given true", () => {
assert.strictEqual(booleanSpec.serialize(["this", "one", "works"], true), true);
});
});
});

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import dateSpec from "../../lib/serialization/dateSpec";
describe("dateSpec", () => {
it("should have \"Date\" for its typeName property", () => {
assert.strictEqual("Date", dateSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
dateSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", () => {
try {
dateSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", () => {
try {
dateSpec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", () => {
try {
dateSpec.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", () => {
assert.strictEqual(dateSpec.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "2011-10-05");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", () => {
assert.strictEqual(dateSpec.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "2011-10-05");
});
});
});

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import dateTimeRfc1123Spec from "../../lib/serialization/dateTimeRfc1123Spec";
describe("dateTimeRfc1123Spec", () => {
it("should have \"DateTimeRFC1123\" for its typeName property", () => {
assert.strictEqual("DateTimeRFC1123", dateTimeRfc1123Spec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
dateTimeRfc1123Spec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", () => {
try {
dateTimeRfc1123Spec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", () => {
try {
dateTimeRfc1123Spec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", () => {
try {
dateTimeRfc1123Spec.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", () => {
assert.strictEqual(dateTimeRfc1123Spec.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "Wed, 05 Oct 2011 14:48:00 GMT");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", () => {
assert.strictEqual(dateTimeRfc1123Spec.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "Wed, 05 Oct 2011 14:48:00 GMT");
});
});
});

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import dateTimeSpec from "../../lib/serialization/dateTimeSpec";
describe("dateTimeSpec", () => {
it("should have \"DateTime\" for its typeName property", () => {
assert.strictEqual("DateTime", dateTimeSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
dateTimeSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", () => {
try {
dateTimeSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", () => {
try {
dateTimeSpec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", () => {
try {
dateTimeSpec.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", () => {
assert.strictEqual(dateTimeSpec.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), "2011-10-05T14:48:00.000Z");
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", () => {
assert.strictEqual(dateTimeSpec.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), "2011-10-05T14:48:00.000Z");
});
});
});

Просмотреть файл

@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import { enumSpec } from "../../lib/serialization/enumSpec";
describe("enumSpec", () => {
it("should have \"Enum<Letters>\" for its typeName property", () => {
assert.strictEqual("Enum<Letters>", enumSpec("Letters", []).typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
enumSpec("Letters", ["a", "b", "c"]).serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, `Property a.property.path with value undefined must be one of the enum allowed values: ["a","b","c"].`);
}
});
it("should throw an error when given \"\"", () => {
try {
enumSpec("Letters", ["a", "b", "c"]).serialize(["another", "property", "path"], "");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, `Property another.property.path with value \"\" must be one of the enum allowed values: ["a","b","c"].`);
}
});
it("should return the provided value with no error when given \"a\"", () => {
assert.strictEqual(enumSpec("Letters", ["a", "b", "c"]).serialize(["this", "one", "works"], "a"), "a");
});
it("should return the provided value with no error when given \"A\"", () => {
assert.strictEqual(enumSpec("Letters", ["a", "b", "c"]).serialize(["this", "one", "works"], "A"), "A");
});
});
});

Просмотреть файл

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import numberSpec from "../../lib/serialization/numberSpec";
describe("numberSpec", () => {
it("should have \"number\" for its typeName property", () => {
assert.strictEqual("number", numberSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
numberSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type number.");
}
});
it("should throw an error when given \"\"", () => {
try {
numberSpec.serialize(["another", "property", "path"], "");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"\" must be of type number.");
}
});
it("should return the provided value with no error when given 12", () => {
assert.strictEqual(numberSpec.serialize(["this", "one", "works"], 12), 12);
});
});
});

Просмотреть файл

@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import objectSpec from "../../lib/serialization/objectSpec";
describe("objectSpec", () => {
it("should have \"object\" for its typeName property", () => {
assert.strictEqual("object", objectSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
objectSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an object.");
}
});
it("should throw an error when given false", () => {
try {
objectSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an object.");
}
});
it("should throw an error when given []", () => {
try {
objectSpec.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be an object.");
}
});
it("should return the provided value with no error when given {}", () => {
assert.deepEqual(objectSpec.serialize(["this", "one", "works"], {}), {});
});
});
});

Просмотреть файл

@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import streamSpec from "../../lib/serialization/streamSpec";
describe("objectSpec", () => {
it("should have \"Stream\" for its typeName property", () => {
assert.strictEqual("Stream", streamSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
streamSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be a Stream.");
}
});
it("should throw an error when given false", () => {
try {
streamSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be a Stream.");
}
});
it("should throw an error when given {}", () => {
try {
streamSpec.serialize(["another", "property", "path"], {});
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value {} must be a Stream.");
}
});
it("should throw an error when given []", () => {
try {
streamSpec.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be a Stream.");
}
});
});
});

Просмотреть файл

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import stringSpec from "../../lib/serialization/stringSpec";
describe("stringSpec", () => {
it("should have \"string\" for its typeName property", () => {
assert.strictEqual("string", stringSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
stringSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be of type string.");
}
});
it("should throw an error when given false", () => {
try {
stringSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be of type string.");
}
});
it("should return the provided value with no error when given \"abc\"", () => {
assert.strictEqual(stringSpec.serialize(["this", "one", "works"], "abc"), "abc");
});
});
});

Просмотреть файл

@ -0,0 +1,62 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import * as moment from "moment";
import timeSpanSpec from "../../lib/serialization/timeSpanSpec";
describe("timeSpanSpec", () => {
it("should have \"TimeSpan\" for its typeName property", () => {
assert.strictEqual("TimeSpan", timeSpanSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
timeSpanSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be a TimeSpan/Duration.");
}
});
it("should throw an error when given false", () => {
try {
timeSpanSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be a TimeSpan/Duration.");
}
});
it("should throw an error when given 5", () => {
try {
timeSpanSpec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be a TimeSpan/Duration.");
}
});
it("should throw an error when given \"hello world!\"", () => {
try {
timeSpanSpec.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be a TimeSpan/Duration.");
}
});
it("should throw an error when given an ISO 8601 time span string", () => {
try {
timeSpanSpec.serialize(["another", "property", "path"], "P123DT22H14M12.011S");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"P123DT22H14M12.011S\" must be a TimeSpan/Duration.");
}
});
it("should return the ISO 8601 string representation of the provided value with no error when given a moment.Duration", () => {
assert.strictEqual(timeSpanSpec.serialize(["this", "one", "works"], moment.duration({ days: 123, hours: 22, minutes: 14, seconds: 12, milliseconds: 11 })), "P123DT22H14M12.011S");
});
});
});

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import unixTimeSpec from "../../lib/serialization/unixTimeSpec";
describe("unixTimeSpec", () => {
it("should have \"UnixTime\" for its typeName property", () => {
assert.strictEqual("UnixTime", unixTimeSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
unixTimeSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given false", () => {
try {
unixTimeSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given 5", () => {
try {
unixTimeSpec.serialize(["another", "property", "path"], 5);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value 5 must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should throw an error when given \"hello world!\"", () => {
try {
unixTimeSpec.serialize(["another", "property", "path"], "hello world!");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"hello world!\" must be an instanceof Date or a string in ISO8601 format.");
}
});
it("should return the provided value with no error when given an ISO 8601 date string", () => {
assert.strictEqual(unixTimeSpec.serialize(["this", "one", "works"], "2011-10-05T14:48:00.000Z"), 1317826080);
});
it("should return the ISO 8601 string representation of the provided value with no error when given a Date", () => {
assert.strictEqual(unixTimeSpec.serialize(["this", "one", "works"], new Date("2011-10-05T14:48:00.000Z")), 1317826080);
});
});
});

Просмотреть файл

@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import uuidSpec from "../../lib/serialization/uuidSpec";
describe("uuidSpec", () => {
it("should have \"UUID\" for its typeName property", () => {
assert.strictEqual("UUID", uuidSpec.typeName);
});
describe("serialize()", () => {
it("should throw an error when given undefined", () => {
try {
uuidSpec.serialize(["a", "property", "path"], undefined);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property a.property.path with value undefined must be an UUID.");
}
});
it("should throw an error when given false", () => {
try {
uuidSpec.serialize(["another", "property", "path"], false);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value false must be an UUID.");
}
});
it("should throw an error when given []", () => {
try {
uuidSpec.serialize(["another", "property", "path"], []);
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value [] must be an UUID.");
}
});
it("should throw an error when given \"abc\"", () => {
try {
uuidSpec.serialize(["another", "property", "path"], "abc");
assert.fail("Expected an error to be thrown.");
} catch (error) {
assert.strictEqual(error.message, "Property another.property.path with value \"abc\" must be an UUID.");
}
});
it("should return the provided value with no error when given \"123e4567-e89b-12d3-a456-426655440000\"", () => {
assert.deepEqual(uuidSpec.serialize(["this", "one", "works"], "123e4567-e89b-12d3-a456-426655440000"), "123e4567-e89b-12d3-a456-426655440000");
});
});
});

6
typings/lib/serialization/booleanSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a boolean.
*/
declare const booleanSpec: TypeSpec<boolean>;
export default booleanSpec;

6
typings/lib/serialization/dateSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
declare const dateSpec: TypeSpec<string>;
export default dateSpec;

6
typings/lib/serialization/dateTimeRfc1123Spec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
declare const dateTimeRfc1123Spec: TypeSpec<string>;
export default dateTimeRfc1123Spec;

6
typings/lib/serialization/dateTimeSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
declare const dateTimeSpec: TypeSpec<string>;
export default dateTimeSpec;

5
typings/lib/serialization/enumSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize an object.
*/
export declare function enumSpec<T>(enumName: string, allowedValues: T[]): TypeSpec<T>;

6
typings/lib/serialization/numberSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a number.
*/
declare const numberSpec: TypeSpec<number>;
export default numberSpec;

6
typings/lib/serialization/objectSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize an object.
*/
declare const objectSpec: TypeSpec<{}>;
export default objectSpec;

6
typings/lib/serialization/streamSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Stream.
*/
declare const streamSpec: TypeSpec<any>;
export default streamSpec;

6
typings/lib/serialization/stringSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a string.
*/
declare const stringSpec: TypeSpec<string>;
export default stringSpec;

6
typings/lib/serialization/timeSpanSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
declare const timeSpanSpec: TypeSpec<string>;
export default timeSpanSpec;

28
typings/lib/serialization/typeSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,28 @@
/**
* A type specification that describes how to validate and serialize an object of a given type.
*/
export interface TypeSpec<TSerialized> {
/**
* The name of the type that this TypeSpec validates.
*/
typeName: string;
/**
* The values that are allowed for this TypeSpec. If this is undefined, then all values of the
* correct type are valid.
*/
allowedValues?: TSerialized[];
/**
* Validate and serialize the provided value into the return type T.
* @param propertyPath The path from the root of the type being serialized down to this
* property.
* @param value The value to validate and serialize.
*/
serialize(propertyPath: string[], value: any): TSerialized;
}
/**
* Create an error message for an invalid serialization.
* @param propertyPath The path to the property with the serialization error.
* @param value The value that failed the serialization.
* @param expectedConditionDescription A brief description of what type was expected.
*/
export declare function createValidationErrorMessage(propertyPath: string[], value: any, expectedConditionDescription: string): string;

6
typings/lib/serialization/unixTimeSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize a Date.
*/
declare const unixTimeSpec: TypeSpec<number>;
export default unixTimeSpec;

6
typings/lib/serialization/uuidSpec.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { TypeSpec } from "./typeSpec";
/**
* A type specification that describes how to validate and serialize an UUID.
*/
declare const uuidSpec: TypeSpec<string>;
export default uuidSpec;

1
typings/test/serialization/booleanSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/dateSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/dateTimeRfc1123SpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/dateTimeSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/enumSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/numberSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/objectSpecTest.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/streamSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/stringSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/timeSpanSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/unixTimeSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};

1
typings/test/serialization/uuidSpecTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};