@aws-cdk/cloud-assembly-schema 40.0.7 → 40.2.0
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/.jsii +44 -43
- package/lib/cloud-assembly/context-queries.js +1 -1
- package/lib/manifest.js +4 -3
- package/package.json +35 -24
- package/node_modules/jsonschema/.editorconfig +0 -10
- package/node_modules/jsonschema/LICENSE +0 -21
- package/node_modules/jsonschema/README.md +0 -421
- package/node_modules/jsonschema/lib/attribute.js +0 -978
- package/node_modules/jsonschema/lib/helpers.js +0 -390
- package/node_modules/jsonschema/lib/index.d.ts +0 -142
- package/node_modules/jsonschema/lib/index.js +0 -15
- package/node_modules/jsonschema/lib/scan.js +0 -75
- package/node_modules/jsonschema/lib/validator.js +0 -336
- package/node_modules/jsonschema/package.json +0 -42
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var urilib = require('url');
|
|
4
|
-
|
|
5
|
-
var attribute = require('./attribute');
|
|
6
|
-
var helpers = require('./helpers');
|
|
7
|
-
var scanSchema = require('./scan').scan;
|
|
8
|
-
var ValidatorResult = helpers.ValidatorResult;
|
|
9
|
-
var ValidatorResultError = helpers.ValidatorResultError;
|
|
10
|
-
var SchemaError = helpers.SchemaError;
|
|
11
|
-
var SchemaContext = helpers.SchemaContext;
|
|
12
|
-
//var anonymousBase = 'vnd.jsonschema:///';
|
|
13
|
-
var anonymousBase = '/';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates a new Validator object
|
|
17
|
-
* @name Validator
|
|
18
|
-
* @constructor
|
|
19
|
-
*/
|
|
20
|
-
var Validator = function Validator () {
|
|
21
|
-
// Allow a validator instance to override global custom formats or to have their
|
|
22
|
-
// own custom formats.
|
|
23
|
-
this.customFormats = Object.create(Validator.prototype.customFormats);
|
|
24
|
-
this.schemas = {};
|
|
25
|
-
this.unresolvedRefs = [];
|
|
26
|
-
|
|
27
|
-
// Use Object.create to make this extensible without Validator instances stepping on each other's toes.
|
|
28
|
-
this.types = Object.create(types);
|
|
29
|
-
this.attributes = Object.create(attribute.validators);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// Allow formats to be registered globally.
|
|
33
|
-
Validator.prototype.customFormats = {};
|
|
34
|
-
|
|
35
|
-
// Hint at the presence of a property
|
|
36
|
-
Validator.prototype.schemas = null;
|
|
37
|
-
Validator.prototype.types = null;
|
|
38
|
-
Validator.prototype.attributes = null;
|
|
39
|
-
Validator.prototype.unresolvedRefs = null;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Adds a schema with a certain urn to the Validator instance.
|
|
43
|
-
* @param schema
|
|
44
|
-
* @param urn
|
|
45
|
-
* @return {Object}
|
|
46
|
-
*/
|
|
47
|
-
Validator.prototype.addSchema = function addSchema (schema, base) {
|
|
48
|
-
var self = this;
|
|
49
|
-
if (!schema) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
var scan = scanSchema(base||anonymousBase, schema);
|
|
53
|
-
var ourUri = base || schema.$id || schema.id;
|
|
54
|
-
for(var uri in scan.id){
|
|
55
|
-
this.schemas[uri] = scan.id[uri];
|
|
56
|
-
}
|
|
57
|
-
for(var uri in scan.ref){
|
|
58
|
-
// If this schema is already defined, it will be filtered out by the next step
|
|
59
|
-
this.unresolvedRefs.push(uri);
|
|
60
|
-
}
|
|
61
|
-
// Remove newly defined schemas from unresolvedRefs
|
|
62
|
-
this.unresolvedRefs = this.unresolvedRefs.filter(function(uri){
|
|
63
|
-
return typeof self.schemas[uri]==='undefined';
|
|
64
|
-
});
|
|
65
|
-
return this.schemas[ourUri];
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
Validator.prototype.addSubSchemaArray = function addSubSchemaArray(baseuri, schemas) {
|
|
69
|
-
if(!Array.isArray(schemas)) return;
|
|
70
|
-
for(var i=0; i<schemas.length; i++){
|
|
71
|
-
this.addSubSchema(baseuri, schemas[i]);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
Validator.prototype.addSubSchemaObject = function addSubSchemaArray(baseuri, schemas) {
|
|
76
|
-
if(!schemas || typeof schemas!='object') return;
|
|
77
|
-
for(var p in schemas){
|
|
78
|
-
this.addSubSchema(baseuri, schemas[p]);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Sets all the schemas of the Validator instance.
|
|
86
|
-
* @param schemas
|
|
87
|
-
*/
|
|
88
|
-
Validator.prototype.setSchemas = function setSchemas (schemas) {
|
|
89
|
-
this.schemas = schemas;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Returns the schema of a certain urn
|
|
94
|
-
* @param urn
|
|
95
|
-
*/
|
|
96
|
-
Validator.prototype.getSchema = function getSchema (urn) {
|
|
97
|
-
return this.schemas[urn];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Validates instance against the provided schema
|
|
102
|
-
* @param instance
|
|
103
|
-
* @param schema
|
|
104
|
-
* @param [options]
|
|
105
|
-
* @param [ctx]
|
|
106
|
-
* @return {Array}
|
|
107
|
-
*/
|
|
108
|
-
Validator.prototype.validate = function validate (instance, schema, options, ctx) {
|
|
109
|
-
if((typeof schema !== 'boolean' && typeof schema !== 'object') || schema === null){
|
|
110
|
-
throw new SchemaError('Expected `schema` to be an object or boolean');
|
|
111
|
-
}
|
|
112
|
-
if (!options) {
|
|
113
|
-
options = {};
|
|
114
|
-
}
|
|
115
|
-
// This section indexes subschemas in the provided schema, so they don't need to be added with Validator#addSchema
|
|
116
|
-
// This will work so long as the function at uri.resolve() will resolve a relative URI to a relative URI
|
|
117
|
-
var id = schema.$id || schema.id;
|
|
118
|
-
var base = urilib.resolve(options.base||anonymousBase, id||'');
|
|
119
|
-
if(!ctx){
|
|
120
|
-
ctx = new SchemaContext(schema, options, [], base, Object.create(this.schemas));
|
|
121
|
-
if (!ctx.schemas[base]) {
|
|
122
|
-
ctx.schemas[base] = schema;
|
|
123
|
-
}
|
|
124
|
-
var found = scanSchema(base, schema);
|
|
125
|
-
for(var n in found.id){
|
|
126
|
-
var sch = found.id[n];
|
|
127
|
-
ctx.schemas[n] = sch;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if(options.required && instance===undefined){
|
|
131
|
-
var result = new ValidatorResult(instance, schema, options, ctx);
|
|
132
|
-
result.addError('is required, but is undefined');
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
var result = this.validateSchema(instance, schema, options, ctx);
|
|
136
|
-
if (!result) {
|
|
137
|
-
throw new Error('Result undefined');
|
|
138
|
-
}else if(options.throwAll && result.errors.length){
|
|
139
|
-
throw new ValidatorResultError(result);
|
|
140
|
-
}
|
|
141
|
-
return result;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @param Object schema
|
|
146
|
-
* @return mixed schema uri or false
|
|
147
|
-
*/
|
|
148
|
-
function shouldResolve(schema) {
|
|
149
|
-
var ref = (typeof schema === 'string') ? schema : schema.$ref;
|
|
150
|
-
if (typeof ref=='string') return ref;
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Validates an instance against the schema (the actual work horse)
|
|
156
|
-
* @param instance
|
|
157
|
-
* @param schema
|
|
158
|
-
* @param options
|
|
159
|
-
* @param ctx
|
|
160
|
-
* @private
|
|
161
|
-
* @return {ValidatorResult}
|
|
162
|
-
*/
|
|
163
|
-
Validator.prototype.validateSchema = function validateSchema (instance, schema, options, ctx) {
|
|
164
|
-
var result = new ValidatorResult(instance, schema, options, ctx);
|
|
165
|
-
|
|
166
|
-
// Support for the true/false schemas
|
|
167
|
-
if(typeof schema==='boolean') {
|
|
168
|
-
if(schema===true){
|
|
169
|
-
// `true` is always valid
|
|
170
|
-
schema = {};
|
|
171
|
-
}else if(schema===false){
|
|
172
|
-
// `false` is always invalid
|
|
173
|
-
schema = {type: []};
|
|
174
|
-
}
|
|
175
|
-
}else if(!schema){
|
|
176
|
-
// This might be a string
|
|
177
|
-
throw new Error("schema is undefined");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (schema['extends']) {
|
|
181
|
-
if (Array.isArray(schema['extends'])) {
|
|
182
|
-
var schemaobj = {schema: schema, ctx: ctx};
|
|
183
|
-
schema['extends'].forEach(this.schemaTraverser.bind(this, schemaobj));
|
|
184
|
-
schema = schemaobj.schema;
|
|
185
|
-
schemaobj.schema = null;
|
|
186
|
-
schemaobj.ctx = null;
|
|
187
|
-
schemaobj = null;
|
|
188
|
-
} else {
|
|
189
|
-
schema = helpers.deepMerge(schema, this.superResolve(schema['extends'], ctx));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// If passed a string argument, load that schema URI
|
|
194
|
-
var switchSchema = shouldResolve(schema);
|
|
195
|
-
if (switchSchema) {
|
|
196
|
-
var resolved = this.resolve(schema, switchSchema, ctx);
|
|
197
|
-
var subctx = new SchemaContext(resolved.subschema, options, ctx.path, resolved.switchSchema, ctx.schemas);
|
|
198
|
-
return this.validateSchema(instance, resolved.subschema, options, subctx);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
var skipAttributes = options && options.skipAttributes || [];
|
|
202
|
-
// Validate each schema attribute against the instance
|
|
203
|
-
for (var key in schema) {
|
|
204
|
-
if (!attribute.ignoreProperties[key] && skipAttributes.indexOf(key) < 0) {
|
|
205
|
-
var validatorErr = null;
|
|
206
|
-
var validator = this.attributes[key];
|
|
207
|
-
if (validator) {
|
|
208
|
-
validatorErr = validator.call(this, instance, schema, options, ctx);
|
|
209
|
-
} else if (options.allowUnknownAttributes === false) {
|
|
210
|
-
// This represents an error with the schema itself, not an invalid instance
|
|
211
|
-
throw new SchemaError("Unsupported attribute: " + key, schema);
|
|
212
|
-
}
|
|
213
|
-
if (validatorErr) {
|
|
214
|
-
result.importErrors(validatorErr);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (typeof options.rewrite == 'function') {
|
|
220
|
-
var value = options.rewrite.call(this, instance, schema, options, ctx);
|
|
221
|
-
result.instance = value;
|
|
222
|
-
}
|
|
223
|
-
return result;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* @private
|
|
228
|
-
* @param Object schema
|
|
229
|
-
* @param SchemaContext ctx
|
|
230
|
-
* @returns Object schema or resolved schema
|
|
231
|
-
*/
|
|
232
|
-
Validator.prototype.schemaTraverser = function schemaTraverser (schemaobj, s) {
|
|
233
|
-
schemaobj.schema = helpers.deepMerge(schemaobj.schema, this.superResolve(s, schemaobj.ctx));
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* @private
|
|
238
|
-
* @param Object schema
|
|
239
|
-
* @param SchemaContext ctx
|
|
240
|
-
* @returns Object schema or resolved schema
|
|
241
|
-
*/
|
|
242
|
-
Validator.prototype.superResolve = function superResolve (schema, ctx) {
|
|
243
|
-
var ref = shouldResolve(schema);
|
|
244
|
-
if(ref) {
|
|
245
|
-
return this.resolve(schema, ref, ctx).subschema;
|
|
246
|
-
}
|
|
247
|
-
return schema;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* @private
|
|
252
|
-
* @param Object schema
|
|
253
|
-
* @param Object switchSchema
|
|
254
|
-
* @param SchemaContext ctx
|
|
255
|
-
* @return Object resolved schemas {subschema:String, switchSchema: String}
|
|
256
|
-
* @throws SchemaError
|
|
257
|
-
*/
|
|
258
|
-
Validator.prototype.resolve = function resolve (schema, switchSchema, ctx) {
|
|
259
|
-
switchSchema = ctx.resolve(switchSchema);
|
|
260
|
-
// First see if the schema exists under the provided URI
|
|
261
|
-
if (ctx.schemas[switchSchema]) {
|
|
262
|
-
return {subschema: ctx.schemas[switchSchema], switchSchema: switchSchema};
|
|
263
|
-
}
|
|
264
|
-
// Else try walking the property pointer
|
|
265
|
-
var parsed = urilib.parse(switchSchema);
|
|
266
|
-
var fragment = parsed && parsed.hash;
|
|
267
|
-
var document = fragment && fragment.length && switchSchema.substr(0, switchSchema.length - fragment.length);
|
|
268
|
-
if (!document || !ctx.schemas[document]) {
|
|
269
|
-
throw new SchemaError("no such schema <" + switchSchema + ">", schema);
|
|
270
|
-
}
|
|
271
|
-
var subschema = helpers.objectGetPath(ctx.schemas[document], fragment.substr(1));
|
|
272
|
-
if(subschema===undefined){
|
|
273
|
-
throw new SchemaError("no such schema " + fragment + " located in <" + document + ">", schema);
|
|
274
|
-
}
|
|
275
|
-
return {subschema: subschema, switchSchema: switchSchema};
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Tests whether the instance if of a certain type.
|
|
280
|
-
* @private
|
|
281
|
-
* @param instance
|
|
282
|
-
* @param schema
|
|
283
|
-
* @param options
|
|
284
|
-
* @param ctx
|
|
285
|
-
* @param type
|
|
286
|
-
* @return {boolean}
|
|
287
|
-
*/
|
|
288
|
-
Validator.prototype.testType = function validateType (instance, schema, options, ctx, type) {
|
|
289
|
-
if(type===undefined){
|
|
290
|
-
return;
|
|
291
|
-
}else if(type===null){
|
|
292
|
-
throw new SchemaError('Unexpected null in "type" keyword');
|
|
293
|
-
}
|
|
294
|
-
if (typeof this.types[type] == 'function') {
|
|
295
|
-
return this.types[type].call(this, instance);
|
|
296
|
-
}
|
|
297
|
-
if (type && typeof type == 'object') {
|
|
298
|
-
var res = this.validateSchema(instance, type, options, ctx);
|
|
299
|
-
return res === undefined || !(res && res.errors.length);
|
|
300
|
-
}
|
|
301
|
-
// Undefined or properties not on the list are acceptable, same as not being defined
|
|
302
|
-
return true;
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
var types = Validator.prototype.types = {};
|
|
306
|
-
types.string = function testString (instance) {
|
|
307
|
-
return typeof instance == 'string';
|
|
308
|
-
};
|
|
309
|
-
types.number = function testNumber (instance) {
|
|
310
|
-
// isFinite returns false for NaN, Infinity, and -Infinity
|
|
311
|
-
return typeof instance == 'number' && isFinite(instance);
|
|
312
|
-
};
|
|
313
|
-
types.integer = function testInteger (instance) {
|
|
314
|
-
return (typeof instance == 'number') && instance % 1 === 0;
|
|
315
|
-
};
|
|
316
|
-
types.boolean = function testBoolean (instance) {
|
|
317
|
-
return typeof instance == 'boolean';
|
|
318
|
-
};
|
|
319
|
-
types.array = function testArray (instance) {
|
|
320
|
-
return Array.isArray(instance);
|
|
321
|
-
};
|
|
322
|
-
types['null'] = function testNull (instance) {
|
|
323
|
-
return instance === null;
|
|
324
|
-
};
|
|
325
|
-
types.date = function testDate (instance) {
|
|
326
|
-
return instance instanceof Date;
|
|
327
|
-
};
|
|
328
|
-
types.any = function testAny (instance) {
|
|
329
|
-
return true;
|
|
330
|
-
};
|
|
331
|
-
types.object = function testObject (instance) {
|
|
332
|
-
// TODO: fix this - see #15
|
|
333
|
-
return instance && (typeof instance === 'object') && !(Array.isArray(instance)) && !(instance instanceof Date);
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
module.exports = Validator;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "Tom de Grunt <tom@degrunt.nl>",
|
|
3
|
-
"name": "jsonschema",
|
|
4
|
-
"version": "1.4.1",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"dependencies": {},
|
|
7
|
-
"contributors": [
|
|
8
|
-
{
|
|
9
|
-
"name": "Austin Wright"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
"main": "./lib/index.js",
|
|
13
|
-
"typings": "./lib/index.d.ts",
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@stryker-mutator/core": "^4.0.0",
|
|
16
|
-
"@stryker-mutator/mocha-runner": "^4.0.0",
|
|
17
|
-
"chai": "~4.2.0",
|
|
18
|
-
"eslint": "^7.7.0",
|
|
19
|
-
"json-metaschema": "^1.2.0",
|
|
20
|
-
"mocha": "~8.1.1"
|
|
21
|
-
},
|
|
22
|
-
"optionalDependencies": {},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": "*"
|
|
25
|
-
},
|
|
26
|
-
"keywords": [
|
|
27
|
-
"json",
|
|
28
|
-
"schema",
|
|
29
|
-
"jsonschema",
|
|
30
|
-
"validator",
|
|
31
|
-
"validation"
|
|
32
|
-
],
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "git://github.com/tdegrunt/jsonschema.git"
|
|
36
|
-
},
|
|
37
|
-
"description": "A fast and easy to use JSON Schema validator",
|
|
38
|
-
"scripts": {
|
|
39
|
-
"stryker": "stryker run",
|
|
40
|
-
"test": "./node_modules/.bin/mocha -R spec"
|
|
41
|
-
}
|
|
42
|
-
}
|