@fluid-experimental/property-changeset 1.2.7 → 2.0.0-dev.1.3.0.96595
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/changeset.d.ts +39 -45
- package/dist/changeset.d.ts.map +1 -1
- package/dist/changeset.js +42 -51
- package/dist/changeset.js.map +1 -1
- package/dist/changeset_operations/array.d.ts +34 -3
- package/dist/changeset_operations/array.d.ts.map +1 -1
- package/dist/changeset_operations/array.js +97 -94
- package/dist/changeset_operations/array.js.map +1 -1
- package/dist/changeset_operations/indexedCollection.d.ts +13 -15
- package/dist/changeset_operations/indexedCollection.d.ts.map +1 -1
- package/dist/changeset_operations/indexedCollection.js +14 -15
- package/dist/changeset_operations/indexedCollection.js.map +1 -1
- package/dist/helpers/typeidHelper.d.ts +14 -14
- package/dist/helpers/typeidHelper.d.ts.map +1 -1
- package/dist/helpers/typeidHelper.js +24 -34
- package/dist/helpers/typeidHelper.js.map +1 -1
- package/dist/pathHelper.d.ts +5 -5
- package/dist/pathHelper.d.ts.map +1 -1
- package/dist/pathHelper.js +54 -56
- package/dist/pathHelper.js.map +1 -1
- package/dist/templateValidator.d.ts +62 -30
- package/dist/templateValidator.d.ts.map +1 -1
- package/dist/templateValidator.js +128 -94
- package/dist/templateValidator.js.map +1 -1
- package/dist/test/array.spec.js +3 -6
- package/dist/test/array.spec.js.map +1 -1
- package/dist/test/pathHelper.spec.js +2 -4
- package/dist/test/pathHelper.spec.js.map +1 -1
- package/dist/test/reversibleCs.spec.js +2 -4
- package/dist/test/reversibleCs.spec.js.map +1 -1
- package/dist/test/tsconfig.tsbuildinfo +1 -1
- package/dist/test/validator/templateValidator.spec.js +5 -10
- package/dist/test/validator/templateValidator.spec.js.map +1 -1
- package/dist/utils.d.ts +137 -109
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +167 -174
- package/dist/utils.js.map +1 -1
- package/dist/validationResultBuilder.d.ts +6 -8
- package/dist/validationResultBuilder.d.ts.map +1 -1
- package/dist/validationResultBuilder.js +5 -11
- package/dist/validationResultBuilder.js.map +1 -1
- package/lib/changeset.js +42 -51
- package/lib/changeset.js.map +1 -1
- package/lib/changeset_operations/array.js +97 -94
- package/lib/changeset_operations/array.js.map +1 -1
- package/lib/changeset_operations/indexedCollection.js +14 -15
- package/lib/changeset_operations/indexedCollection.js.map +1 -1
- package/lib/helpers/typeidHelper.js +24 -34
- package/lib/helpers/typeidHelper.js.map +1 -1
- package/lib/pathHelper.js +54 -56
- package/lib/pathHelper.js.map +1 -1
- package/lib/templateValidator.js +128 -94
- package/lib/templateValidator.js.map +1 -1
- package/lib/utils.js +167 -174
- package/lib/utils.js.map +1 -1
- package/lib/validationResultBuilder.js +5 -11
- package/lib/validationResultBuilder.js.map +1 -1
- package/package.json +5 -5
|
@@ -57,7 +57,7 @@ export interface TemplateValidatorOptions {
|
|
|
57
57
|
hasSchemaAsync?: (schema: PropertySchema, typeid: string) => Promise<boolean>;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Instantiates a new TemplateValidator. Must be provided with a set of inheritsFrom and hasSchema
|
|
61
61
|
* function or inheritsFromAsync and hasSchemaAsync, but not both.
|
|
62
62
|
*/
|
|
63
63
|
export declare class TemplateValidator {
|
|
@@ -73,56 +73,88 @@ export declare class TemplateValidator {
|
|
|
73
73
|
private readonly _skipSemver;
|
|
74
74
|
constructor(in_params?: TemplateValidatorOptions);
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
76
|
+
* Validates that all templates conform to the following mandatory rules:
|
|
77
|
+
*
|
|
78
|
+
* 1. Must have a typeid attribute.
|
|
79
|
+
*
|
|
80
|
+
* 2. typeid must end in a valid semver string.
|
|
81
|
+
*
|
|
82
|
+
* 3. When both in_template (B) and in_templatePrevious (A) are supplied:
|
|
83
|
+
*
|
|
84
|
+
* - 3a. Semver is identical only if content is identical.
|
|
85
|
+
*
|
|
86
|
+
* - 3b. B's semver >= A's semver
|
|
87
|
+
*
|
|
88
|
+
* Additionally, the following soft rules will produce warnings when violated:
|
|
89
|
+
*
|
|
90
|
+
* 3.5. Elements of sets must eventually inherit from 'NamedProperty'
|
|
91
|
+
*
|
|
92
|
+
* 4. PATCH revision should be increased when _only_ the template description changes.
|
|
93
|
+
*
|
|
94
|
+
* 5. Adding one or more template attributes is a MINOR change.
|
|
95
|
+
*
|
|
96
|
+
* 6. Removing one or more template attributes is a MAJOR change.
|
|
97
|
+
*
|
|
98
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
99
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
100
|
+
* @returns The validation results. Example:
|
|
101
|
+
*
|
|
102
|
+
* ```json
|
|
103
|
+
* {
|
|
104
|
+
* isValid: false,
|
|
105
|
+
* errors: ['Something went wrong. Validation failed.'],
|
|
106
|
+
* warnings: ['A non-fatal warning'],
|
|
107
|
+
* typeid: 'SomeNamespace:PointID-1.0.0'
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* It's possible for 'isValid' to be true while 'warnings' contains one or more messages.
|
|
112
|
+
*/
|
|
97
113
|
validate(in_template: PropertySchema, in_templatePrevious?: PropertySchema): SchemaValidationResult;
|
|
98
114
|
/**
|
|
99
115
|
* Validates that all templates conform to the following mandatory rules:
|
|
116
|
+
*
|
|
100
117
|
* 1. Must have a typeid attribute.
|
|
118
|
+
*
|
|
101
119
|
* 2. typeid must end in a valid semver string.
|
|
120
|
+
*
|
|
102
121
|
* 3. When both in_template (B) and in_templatePrevious (A) are supplied:
|
|
103
|
-
*
|
|
104
|
-
*
|
|
122
|
+
*
|
|
123
|
+
* - 3a. Semver is identical only if content is identical.
|
|
124
|
+
*
|
|
125
|
+
* - 3b. B's semver >= A's semver
|
|
126
|
+
*
|
|
105
127
|
* Additionally, the following soft rules will produce warnings when violated:
|
|
106
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* 3.5. Elements of sets must eventually inherit from 'NamedProperty'
|
|
130
|
+
*
|
|
107
131
|
* 4. PATCH revision should be increased when _only_ the template description changes.
|
|
132
|
+
*
|
|
108
133
|
* 5. Adding one or more template attributes is a MINOR change.
|
|
134
|
+
*
|
|
109
135
|
* 6. Removing one or more template attributes is a MAJOR change.
|
|
110
|
-
*
|
|
111
|
-
* @param
|
|
112
|
-
* @
|
|
136
|
+
*
|
|
137
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
138
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
139
|
+
* @returns A promise that resolves to the validation results as an object. Example:
|
|
140
|
+
*
|
|
141
|
+
* ```json
|
|
142
|
+
* {
|
|
113
143
|
* isValid: false,
|
|
114
144
|
* errors: ['Something went wrong. Validation failed.'],
|
|
115
145
|
* warnings: ['A non-fatal warning'],
|
|
116
146
|
* typeid: 'SomeNamespace:PointID-1.0.0'
|
|
117
147
|
* }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
118
150
|
* It's possible for 'isValid' to be true while 'warnings' contains one or more messages.
|
|
119
151
|
*/
|
|
120
152
|
validateAsync(in_template: PropertySchema, in_templatePrevious?: PropertySchema): Promise<SchemaValidationResult>;
|
|
121
153
|
/**
|
|
122
154
|
* Called by validateAsync if a previous schema is passed in argument
|
|
123
155
|
*
|
|
124
|
-
* @param in_template The latest template version, as a JSON object.
|
|
125
|
-
* @param in_templatePrevious The previous template version, as a JSON object. Optional.
|
|
156
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
157
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
126
158
|
*
|
|
127
159
|
* @returns promise that resolves to the validation results as an objet. See validateAsync
|
|
128
160
|
* @ignore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateValidator.d.ts","sourceRoot":"","sources":["../src/templateValidator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH;;;;GAIG;AA4BH,OAAO,EAAE,sBAAsB,EAA2B,MAAM,2BAA2B,CAAC;AAc5F,aAAK,UAAU,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAAE,CAAC;AAEjD,aAAK,YAAY,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,aAAK,cAAc,GAAG,YAAY,EAAE,CAAC;AAErC,MAAM,WAAW,cAAc;IAC3B,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KAAE,CAAC;IACxC,UAAU,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"templateValidator.d.ts","sourceRoot":"","sources":["../src/templateValidator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH;;;;GAIG;AA4BH,OAAO,EAAE,sBAAsB,EAA2B,MAAM,2BAA2B,CAAC;AAc5F,aAAK,UAAU,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAAE,CAAC;AAEjD,aAAK,YAAY,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,aAAK,cAAc,GAAG,YAAY,EAAE,CAAC;AAErC,MAAM,WAAW,cAAc;IAC3B,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KAAE,CAAC;IACxC,UAAU,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;CACtB;AAm1BD,MAAM,WAAW,wBAAwB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC;IAC3E;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAChE;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzF;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAEjF;AAQD;;;GAGG;AACH,qBAAa,iBAAiB;IAC1B,MAAM,CAAC,KAAK;;MAAS;IACrB,OAAO,CAAC,cAAc,CAA0B;IACzC,aAAa,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC;IAC3E,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAChE,kBAAkB,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzF,eAAe,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;gBAC1B,SAAS,GAAE,wBAAmE;IAe9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACC,QAAQ,CAAC,WAAW,EAAE,cAAc,EAAE,mBAAmB,CAAC,EAAE,cAAc,GAAG,sBAAsB;IAiFnG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,aAAa,CAAC,WAAW,EAAE,cAAc,EAAE,mBAAmB,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAcvH;;;;;;;;OAQG;YACW,gCAAgC;CAwCjD"}
|
|
@@ -77,9 +77,8 @@ const _extractTypeid = function (typeidOrReference) {
|
|
|
77
77
|
};
|
|
78
78
|
/**
|
|
79
79
|
* Given a typeid string, fetches the semver 'x.y.z' version string.
|
|
80
|
-
* @param in_typeid A PropertySet typeid. For example: 'TeamLeoValidation2:ColorID-1.0.0'.
|
|
81
|
-
* @returns The semver 'x.y.z' version string, or null if in_typeid is not a valid
|
|
82
|
-
* PropertySet typeid.
|
|
80
|
+
* @param in_typeid - A PropertySet typeid. For example: 'TeamLeoValidation2:ColorID-1.0.0'.
|
|
81
|
+
* @returns The semver 'x.y.z' version string, or null if in_typeid is not a valid PropertySet typeid.
|
|
83
82
|
*/
|
|
84
83
|
const _getSemverFromTypeId = function (in_typeid) {
|
|
85
84
|
const semverRegex = /.*-(.*)$/g;
|
|
@@ -88,7 +87,7 @@ const _getSemverFromTypeId = function (in_typeid) {
|
|
|
88
87
|
};
|
|
89
88
|
/**
|
|
90
89
|
* Fetches the type name of a javascript entity.
|
|
91
|
-
* @param in_obj A javascript entity.
|
|
90
|
+
* @param in_obj - A javascript entity.
|
|
92
91
|
* @returns The type name for in_obj.
|
|
93
92
|
*/
|
|
94
93
|
const _getType = (in_obj) => Object.prototype.toString.call(in_obj).slice(8, -1);
|
|
@@ -102,12 +101,14 @@ function isPropertyArray(source) {
|
|
|
102
101
|
* An object deep compare with special handling for pset property arrays.
|
|
103
102
|
* pset property arrays are allowed to be out of order as long as elements can be matched with
|
|
104
103
|
* their id.
|
|
105
|
-
* @param in_source The source entity to test for deep equality.
|
|
106
|
-
* @param in_target The target entity to test for deep equality.
|
|
104
|
+
* @param in_source - The source entity to test for deep equality.
|
|
105
|
+
* @param in_target - The target entity to test for deep equality.
|
|
107
106
|
* @returns {isEqual: false, path: 'foo.properties[1].x'}
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
107
|
+
*
|
|
108
|
+
* - isEqual: true if in_source and in_target property sets are equal, even if the individual property arrays
|
|
109
|
+
* differ but contain the same out of order elements.
|
|
110
|
+
*
|
|
111
|
+
* - path: path to the property that is not equal.
|
|
111
112
|
*/
|
|
112
113
|
const _psetDeepEquals = function (in_source, in_target) {
|
|
113
114
|
const idPath = [];
|
|
@@ -116,11 +117,11 @@ const _psetDeepEquals = function (in_source, in_target) {
|
|
|
116
117
|
}
|
|
117
118
|
/**
|
|
118
119
|
* Create the _psetDeepEquals result.
|
|
119
|
-
* @param isEqual Whether or not a PropertySet result is being constructed for
|
|
120
|
-
*
|
|
120
|
+
* @param isEqual - Whether or not a PropertySet result is being constructed for
|
|
121
|
+
* PropertySets that are deeply equal.
|
|
121
122
|
* @returns {{isEqual: boolean, path: string}} An object that indicates whether or not the source
|
|
122
|
-
*
|
|
123
|
-
*
|
|
123
|
+
* and target PropertySets are deeply equal. If they're not, it also contains a path to the
|
|
124
|
+
* property that is not equal.
|
|
124
125
|
*/
|
|
125
126
|
const _getPSetDeepEqualsResult = (isEqual) => ({
|
|
126
127
|
isEqual,
|
|
@@ -128,9 +129,9 @@ const _psetDeepEquals = function (in_source, in_target) {
|
|
|
128
129
|
});
|
|
129
130
|
/**
|
|
130
131
|
* Performs a recursive, depth first deep equal test against two PropertySets.
|
|
131
|
-
* @param source The source entity to test for deep equality.
|
|
132
|
-
* @param target The target entity to test for deep equality.
|
|
133
|
-
* @param id The current path element being compared.
|
|
132
|
+
* @param source - The source entity to test for deep equality.
|
|
133
|
+
* @param target - The target entity to test for deep equality.
|
|
134
|
+
* @param id - The current path element being compared.
|
|
134
135
|
* @return The result of _getPSetDeepEqualsResult
|
|
135
136
|
*/
|
|
136
137
|
let _depthFirstDeepEquals = function (source, target, id) {
|
|
@@ -208,7 +209,7 @@ const _psetDeepEquals = function (in_source, in_target) {
|
|
|
208
209
|
};
|
|
209
210
|
/**
|
|
210
211
|
* Fetches the non semver part of a typeid string.
|
|
211
|
-
* @param in_typeid A PropertySet typeid. For example: 'TeamLeoValidation2:ColorID-1.0.0'.
|
|
212
|
+
* @param in_typeid - A PropertySet typeid. For example: 'TeamLeoValidation2:ColorID-1.0.0'.
|
|
212
213
|
* @returns The typeid, without a semver.
|
|
213
214
|
*/
|
|
214
215
|
const _stripSemverFromTypeId = function (in_typeid) {
|
|
@@ -236,7 +237,7 @@ const _unresolvedTypes = function (in_template) {
|
|
|
236
237
|
};
|
|
237
238
|
/**
|
|
238
239
|
* Performs basic template validation.
|
|
239
|
-
* @param in_template The template object to validate.
|
|
240
|
+
* @param in_template - The template object to validate.
|
|
240
241
|
*/
|
|
241
242
|
const _validateBasic = function (in_template) {
|
|
242
243
|
if (!in_template) {
|
|
@@ -248,14 +249,17 @@ const _validateBasic = function (in_template) {
|
|
|
248
249
|
};
|
|
249
250
|
/**
|
|
250
251
|
* Validations performed when the version increases between consecutive templates.
|
|
252
|
+
*
|
|
253
|
+
* @remarks
|
|
251
254
|
* For example: 1.1.3 -> 2.0.0
|
|
252
255
|
* This function checks the change level (PATCH, MINOR, MAJOR) and analyses the template content
|
|
253
256
|
* to emit warnings if the change level should be higher, given the content that changed.
|
|
254
|
-
* This function assumes that: in_versionPrevious < in_version
|
|
255
|
-
*
|
|
256
|
-
* @param
|
|
257
|
-
* @param
|
|
258
|
-
* @param
|
|
257
|
+
* This function assumes that: in_versionPrevious < in_version.
|
|
258
|
+
*
|
|
259
|
+
* @param in_template - The latest template object.
|
|
260
|
+
* @param in_templatePrevious - The previous template object.
|
|
261
|
+
* @param in_version - The latest template version. Ex.: '2.0.0'.
|
|
262
|
+
* @param in_versionPrevious - The previous template version. Ex.: '1.1.3'.
|
|
259
263
|
*/
|
|
260
264
|
const _validatePositiveIncrement = function (in_template, in_templatePrevious, in_version, in_versionPrevious) {
|
|
261
265
|
property_common_1.ConsoleUtils.assert((0, semver_1.gt)(in_version, in_versionPrevious), "property-changeset.TemplateValidator._validatePositiveIncrement called on non incremental " +
|
|
@@ -437,8 +441,8 @@ const _validatePositiveIncrement = function (in_template, in_templatePrevious, i
|
|
|
437
441
|
* Validations performed when the version between consecutive templates doesn't change.
|
|
438
442
|
* For example: 1.1.3 -> 1.1.3.
|
|
439
443
|
* Templates whose version didn't change should have identical content.
|
|
440
|
-
* @param in_template The latest template object.
|
|
441
|
-
* @param in_templatePrevious The previous template object.
|
|
444
|
+
* @param in_template - The latest template object.
|
|
445
|
+
* @param in_templatePrevious - The previous template object.
|
|
442
446
|
*/
|
|
443
447
|
const _validateSameVersion = function (in_template, in_templatePrevious) {
|
|
444
448
|
const result = _psetDeepEquals.call(this, in_templatePrevious, in_template);
|
|
@@ -450,21 +454,25 @@ const _validateSameVersion = function (in_template, in_templatePrevious) {
|
|
|
450
454
|
/**
|
|
451
455
|
* Validate a template
|
|
452
456
|
* Check that the template is syntactically correct as well as semantically correct.
|
|
453
|
-
* @param in_template The template to check against
|
|
454
|
-
* Produces an {object|undefined} map of key-value pairs
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
457
|
+
* @param in_template - The template to check against.
|
|
458
|
+
* Produces an {object|undefined} map of key-value pairs where the path of the invalid property is the key and the
|
|
459
|
+
* value is the error message.
|
|
460
|
+
*
|
|
461
|
+
* i.e.
|
|
462
|
+
*
|
|
463
|
+
* ```
|
|
464
|
+
* <pre>
|
|
465
|
+
* {
|
|
466
|
+
* 'isValid': true or false,
|
|
467
|
+
* 'typeid': 'The typeid of the object being parsed',
|
|
468
|
+
* 'unresolvedTypes': [ 'An array', 'of strong typeids', 'that were found',
|
|
469
|
+
* 'in the document', 'but not resolved from the local cache' ],
|
|
470
|
+
* 'resolvedTypes': [ 'Array of', 'strong types resolved', 'during template parsing'],
|
|
471
|
+
* 'errors': [ 'Array of', 'objects describing', 'syntax errors in the template' ]
|
|
472
|
+
* ...
|
|
473
|
+
* }
|
|
474
|
+
* </pre>
|
|
475
|
+
* ```
|
|
468
476
|
* @throws if context validation fails
|
|
469
477
|
*/
|
|
470
478
|
const _validateSemanticAndSyntax = function (in_template) {
|
|
@@ -475,7 +483,7 @@ const _validateSemanticAndSyntax = function (in_template) {
|
|
|
475
483
|
/**
|
|
476
484
|
* Validate a template
|
|
477
485
|
* Check that the template is syntactically correct as well as semantically correct.
|
|
478
|
-
* @param in_template The template to check against
|
|
486
|
+
* @param in_template - The template to check against
|
|
479
487
|
* @return {Promise} a promise that resolved to nothing
|
|
480
488
|
* @ignore
|
|
481
489
|
*/
|
|
@@ -484,7 +492,7 @@ const _validateSemanticAndSyntaxAsync = async function (in_template) {
|
|
|
484
492
|
};
|
|
485
493
|
/**
|
|
486
494
|
* Validates that the semver part of a template's typeid is valid.
|
|
487
|
-
* @param {Object} in_template The template object to validate.
|
|
495
|
+
* @param {Object} in_template - The template object to validate.
|
|
488
496
|
* @return {string} The semver string. For example: '1.0.0'.
|
|
489
497
|
* @private
|
|
490
498
|
* @this TemplateValidator
|
|
@@ -503,8 +511,8 @@ const _validateSemverFormat = function (in_template) {
|
|
|
503
511
|
/**
|
|
504
512
|
* Skip semver validation. Verify that the content is the same for both templates, while ignoring
|
|
505
513
|
* the root 'typeid' property.
|
|
506
|
-
* @param {Object} in_template The latest template object.
|
|
507
|
-
* @param {Object} in_templatePrevious The previous template object.
|
|
514
|
+
* @param {Object} in_template - The latest template object.
|
|
515
|
+
* @param {Object} in_templatePrevious - The previous template object.
|
|
508
516
|
* @private
|
|
509
517
|
* @this TemplateValidator
|
|
510
518
|
*/
|
|
@@ -518,8 +526,8 @@ const _validateSkipSemver = function (in_template, in_templatePrevious) {
|
|
|
518
526
|
};
|
|
519
527
|
/**
|
|
520
528
|
* Checks if an invalid context error should be signified
|
|
521
|
-
|
|
522
|
-
* @param {String} in_context The latest template object.
|
|
529
|
+
*
|
|
530
|
+
* @param {String} in_context - The latest template object.
|
|
523
531
|
* @return {Error|undefined} If exists returns the InvalidContext error
|
|
524
532
|
* @private
|
|
525
533
|
* @this TemplateValidator
|
|
@@ -533,7 +541,7 @@ const getInvalidContextError = function (in_context) {
|
|
|
533
541
|
/**
|
|
534
542
|
* Validate that the context is valid
|
|
535
543
|
* Validate that only Named Properties are in sets
|
|
536
|
-
* @param {object} in_template The template to check against
|
|
544
|
+
* @param {object} in_template - The template to check against
|
|
537
545
|
* @ignore
|
|
538
546
|
* @throws if the context is invalid.
|
|
539
547
|
*/
|
|
@@ -550,7 +558,7 @@ const _validateContext = function (in_template) {
|
|
|
550
558
|
/**
|
|
551
559
|
* Validate just the syntax of a template
|
|
552
560
|
* Check that the template is well-formed, according to the schema.
|
|
553
|
-
* @param {object} in_template The template to check against
|
|
561
|
+
* @param {object} in_template - The template to check against
|
|
554
562
|
*
|
|
555
563
|
* Context validation makes sure that elements of sets eventually inherit from NamedProperty.
|
|
556
564
|
* If this is not the case, a promise rejection will occur with the appropriate error.
|
|
@@ -614,7 +622,7 @@ const _validateContextAsync = async function (in_template) {
|
|
|
614
622
|
/**
|
|
615
623
|
* Validate that the context is valid
|
|
616
624
|
* Validate that only Named Properties are in sets
|
|
617
|
-
* @param {object} in_template The template to check against
|
|
625
|
+
* @param {object} in_template - The template to check against
|
|
618
626
|
* @ignore
|
|
619
627
|
* @throws if the context is invalid.
|
|
620
628
|
*/
|
|
@@ -637,7 +645,7 @@ let _validateConstants = function (in_template) {
|
|
|
637
645
|
/**
|
|
638
646
|
* Analyze output of the syntax validation and build error messages
|
|
639
647
|
*
|
|
640
|
-
* @param in_template The template that was analyzed
|
|
648
|
+
* @param in_template - The template that was analyzed
|
|
641
649
|
*/
|
|
642
650
|
const _processValidationResults = function (in_template) {
|
|
643
651
|
let that = this;
|
|
@@ -655,25 +663,19 @@ const _processValidationResults = function (in_template) {
|
|
|
655
663
|
error.message = `typeid should have a pattern like: my.example:point-1.0.0 ${error.data} does not match that pattern`;
|
|
656
664
|
}
|
|
657
665
|
else if ("pattern" && regexTypeId.test(error.dataPath)) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
else {
|
|
662
|
-
error.message = `${error.dataPath} should follow this pattern: <namespace>:<typeid>-<version> ` +
|
|
666
|
+
error.message = error.schemaPath === "#/definitions/typed-reference-typeid/pattern"
|
|
667
|
+
? ""
|
|
668
|
+
: `${error.dataPath} should follow this pattern: <namespace>:<typeid>-<version> ` +
|
|
663
669
|
`(for example: Sample:Rectangle-1.0.0) or match one of the Primitive Types (Float32, Float64, ` +
|
|
664
670
|
`Int8, Uint8, Int16, Uint16, Int32, Uint32, Bool, String, Reference, Enum, Int64, Uint64) or ` +
|
|
665
671
|
`Reserved Types (BaseProperty, NamedProperty, NodeProperty, NamedNodeProperty, ` +
|
|
666
672
|
`RelationshipProperty). '${error.data}' is not valid`;
|
|
667
|
-
}
|
|
668
673
|
}
|
|
669
674
|
break;
|
|
670
675
|
case "enum":
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
else {
|
|
675
|
-
error.message = `${error.dataPath} should match one of the following: ${error.schema}`;
|
|
676
|
-
}
|
|
676
|
+
error.message = regexTypeId.test(error.dataPath)
|
|
677
|
+
? ""
|
|
678
|
+
: `${error.dataPath} should match one of the following: ${error.schema}`;
|
|
677
679
|
break;
|
|
678
680
|
case "type":
|
|
679
681
|
error.message = `${error.dataPath} should be a ${error.schema}`;
|
|
@@ -709,7 +711,7 @@ const _processValidationResults = function (in_template) {
|
|
|
709
711
|
/**
|
|
710
712
|
* Validate just the syntax of a template
|
|
711
713
|
* Check that the template is well-formed, according to the schema.
|
|
712
|
-
* @param in_template The template to check against
|
|
714
|
+
* @param in_template - The template to check against
|
|
713
715
|
* @throws if a property with context set is not an instance of NamedProperties
|
|
714
716
|
* @ignore
|
|
715
717
|
*/
|
|
@@ -746,7 +748,7 @@ const createContextCheckAsyncQueue = function () {
|
|
|
746
748
|
* Validate just the syntax of a template
|
|
747
749
|
* Check that the template is well-formed, according to the schema.
|
|
748
750
|
*
|
|
749
|
-
* @param in_template The template to check against
|
|
751
|
+
* @param in_template - The template to check against
|
|
750
752
|
* Mainly checks context. See _validateContextAsync
|
|
751
753
|
* @returns Promise that resolves without any result
|
|
752
754
|
* @ignore
|
|
@@ -791,7 +793,7 @@ const Utils = {
|
|
|
791
793
|
},
|
|
792
794
|
};
|
|
793
795
|
/**
|
|
794
|
-
*
|
|
796
|
+
* Instantiates a new TemplateValidator. Must be provided with a set of inheritsFrom and hasSchema
|
|
795
797
|
* function or inheritsFromAsync and hasSchemaAsync, but not both.
|
|
796
798
|
*/
|
|
797
799
|
class TemplateValidator {
|
|
@@ -812,27 +814,43 @@ class TemplateValidator {
|
|
|
812
814
|
}
|
|
813
815
|
}
|
|
814
816
|
/**
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
817
|
+
* Validates that all templates conform to the following mandatory rules:
|
|
818
|
+
*
|
|
819
|
+
* 1. Must have a typeid attribute.
|
|
820
|
+
*
|
|
821
|
+
* 2. typeid must end in a valid semver string.
|
|
822
|
+
*
|
|
823
|
+
* 3. When both in_template (B) and in_templatePrevious (A) are supplied:
|
|
824
|
+
*
|
|
825
|
+
* - 3a. Semver is identical only if content is identical.
|
|
826
|
+
*
|
|
827
|
+
* - 3b. B's semver >= A's semver
|
|
828
|
+
*
|
|
829
|
+
* Additionally, the following soft rules will produce warnings when violated:
|
|
830
|
+
*
|
|
831
|
+
* 3.5. Elements of sets must eventually inherit from 'NamedProperty'
|
|
832
|
+
*
|
|
833
|
+
* 4. PATCH revision should be increased when _only_ the template description changes.
|
|
834
|
+
*
|
|
835
|
+
* 5. Adding one or more template attributes is a MINOR change.
|
|
836
|
+
*
|
|
837
|
+
* 6. Removing one or more template attributes is a MAJOR change.
|
|
838
|
+
*
|
|
839
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
840
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
841
|
+
* @returns The validation results. Example:
|
|
842
|
+
*
|
|
843
|
+
* ```json
|
|
844
|
+
* {
|
|
845
|
+
* isValid: false,
|
|
846
|
+
* errors: ['Something went wrong. Validation failed.'],
|
|
847
|
+
* warnings: ['A non-fatal warning'],
|
|
848
|
+
* typeid: 'SomeNamespace:PointID-1.0.0'
|
|
849
|
+
* }
|
|
850
|
+
* ```
|
|
851
|
+
*
|
|
852
|
+
* It's possible for 'isValid' to be true while 'warnings' contains one or more messages.
|
|
853
|
+
*/
|
|
836
854
|
validate(in_template, in_templatePrevious) {
|
|
837
855
|
this._resultBuilder = new validationResultBuilder_1.ValidationResultBuilder(in_template ? in_template.typeid : "");
|
|
838
856
|
let isDraft = false;
|
|
@@ -901,24 +919,40 @@ class TemplateValidator {
|
|
|
901
919
|
}
|
|
902
920
|
/**
|
|
903
921
|
* Validates that all templates conform to the following mandatory rules:
|
|
922
|
+
*
|
|
904
923
|
* 1. Must have a typeid attribute.
|
|
924
|
+
*
|
|
905
925
|
* 2. typeid must end in a valid semver string.
|
|
926
|
+
*
|
|
906
927
|
* 3. When both in_template (B) and in_templatePrevious (A) are supplied:
|
|
907
|
-
*
|
|
908
|
-
*
|
|
928
|
+
*
|
|
929
|
+
* - 3a. Semver is identical only if content is identical.
|
|
930
|
+
*
|
|
931
|
+
* - 3b. B's semver >= A's semver
|
|
932
|
+
*
|
|
909
933
|
* Additionally, the following soft rules will produce warnings when violated:
|
|
910
|
-
*
|
|
934
|
+
*
|
|
935
|
+
* 3.5. Elements of sets must eventually inherit from 'NamedProperty'
|
|
936
|
+
*
|
|
911
937
|
* 4. PATCH revision should be increased when _only_ the template description changes.
|
|
938
|
+
*
|
|
912
939
|
* 5. Adding one or more template attributes is a MINOR change.
|
|
940
|
+
*
|
|
913
941
|
* 6. Removing one or more template attributes is a MAJOR change.
|
|
914
|
-
*
|
|
915
|
-
* @param
|
|
916
|
-
* @
|
|
942
|
+
*
|
|
943
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
944
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
945
|
+
* @returns A promise that resolves to the validation results as an object. Example:
|
|
946
|
+
*
|
|
947
|
+
* ```json
|
|
948
|
+
* {
|
|
917
949
|
* isValid: false,
|
|
918
950
|
* errors: ['Something went wrong. Validation failed.'],
|
|
919
951
|
* warnings: ['A non-fatal warning'],
|
|
920
952
|
* typeid: 'SomeNamespace:PointID-1.0.0'
|
|
921
953
|
* }
|
|
954
|
+
* ```
|
|
955
|
+
*
|
|
922
956
|
* It's possible for 'isValid' to be true while 'warnings' contains one or more messages.
|
|
923
957
|
*/
|
|
924
958
|
async validateAsync(in_template, in_templatePrevious) {
|
|
@@ -937,8 +971,8 @@ class TemplateValidator {
|
|
|
937
971
|
/**
|
|
938
972
|
* Called by validateAsync if a previous schema is passed in argument
|
|
939
973
|
*
|
|
940
|
-
* @param in_template The latest template version, as a JSON object.
|
|
941
|
-
* @param in_templatePrevious The previous template version, as a JSON object. Optional.
|
|
974
|
+
* @param in_template - The latest template version, as a JSON object.
|
|
975
|
+
* @param in_templatePrevious - The previous template version, as a JSON object. Optional.
|
|
942
976
|
*
|
|
943
977
|
* @returns promise that resolves to the validation results as an objet. See validateAsync
|
|
944
978
|
* @ignore
|