@x12i/kinedrop 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps-operations.mjs +1867 -0
- package/index.d.ts +352 -0
- package/index.mjs +428 -0
- package/keyrox.mjs +106 -0
- package/object-storage.mjs +37 -0
- package/package.json +12 -4
- package/placement-operations.mjs +1772 -0
- package/service-operations.mjs +2610 -0
- package/validate.mjs +46 -0
- package/README.md +0 -3
package/validate.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The bounded JSON Schema subset used by the portable service descriptors.
|
|
2
|
+
// Validation messages name fields, never values (which could be credentials).
|
|
3
|
+
export function validateInput(value,schema,path='input',depth=0){
|
|
4
|
+
const fail=message=>{throw Object.assign(new Error(path+' '+message),{code:'INVALID_ARGUMENTS',status:422});};
|
|
5
|
+
if(depth>40)fail('is nested too deeply.');
|
|
6
|
+
if(schema.$ref)fail('uses an unresolved contract reference.');
|
|
7
|
+
const matches=branch=>{try{validateInput(value,branch,path,depth+1);return true;}catch{return false;}};
|
|
8
|
+
if(schema.anyOf&&!schema.anyOf.some(matches))fail('does not match an allowed shape.');
|
|
9
|
+
if(schema.oneOf&&schema.oneOf.filter(matches).length!==1)fail('does not match exactly one allowed shape.');
|
|
10
|
+
if(schema.allOf)for(const branch of schema.allOf)validateInput(value,branch,path,depth+1);
|
|
11
|
+
if(Object.hasOwn(schema,'const')&&value!==schema.const)fail('must match its declared constant.');
|
|
12
|
+
if(schema.enum&&!schema.enum.includes(value))fail('is not an allowed choice.');
|
|
13
|
+
if(Array.isArray(schema.type)){if(!schema.type.some(type=>matches({...schema,type,anyOf:undefined,oneOf:undefined,allOf:undefined})))fail('has the wrong type.');return;}
|
|
14
|
+
switch(schema.type){
|
|
15
|
+
case 'object':{
|
|
16
|
+
if(!value||typeof value!=='object'||Array.isArray(value))fail('must be an object.');
|
|
17
|
+
for(const name of schema.required??[])if(!Object.hasOwn(value,name)||value[name]===undefined)fail('requires '+name+'.');
|
|
18
|
+
for(const [name,item]of Object.entries(value)){
|
|
19
|
+
if(['__proto__','constructor','prototype'].includes(name))fail('contains an unsafe property.');
|
|
20
|
+
if(Object.hasOwn(schema.properties??{},name))validateInput(item,schema.properties[name],path+'.'+name,depth+1);
|
|
21
|
+
else if(schema.additionalProperties===false)fail('contains an unsupported field.');
|
|
22
|
+
else if(schema.additionalProperties&&typeof schema.additionalProperties==='object')validateInput(item,schema.additionalProperties,path+'.'+name,depth+1);
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'array':
|
|
27
|
+
if(!Array.isArray(value))fail('must be an array.');
|
|
28
|
+
if(schema.minItems!==undefined&&value.length<schema.minItems||schema.maxItems!==undefined&&value.length>schema.maxItems)fail('has an unsupported number of items.');
|
|
29
|
+
if(schema.uniqueItems&&new Set(value.map(x=>JSON.stringify(x))).size!==value.length)fail('must contain unique items.');
|
|
30
|
+
if(schema.items)value.forEach((item,index)=>validateInput(item,schema.items,path+'['+index+']',depth+1));
|
|
31
|
+
break;
|
|
32
|
+
case 'string':
|
|
33
|
+
if(typeof value!=='string')fail('must be a string.');
|
|
34
|
+
if(schema.minLength!==undefined&&value.length<schema.minLength||schema.maxLength!==undefined&&value.length>schema.maxLength)fail('has an unsupported length.');
|
|
35
|
+
if(schema.pattern&&!new RegExp(schema.pattern).test(value))fail('has an unsupported format.');
|
|
36
|
+
if(schema.format==='date-time'&&(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(value)||!Number.isFinite(Date.parse(value))))fail('must be a date-time.');
|
|
37
|
+
break;
|
|
38
|
+
case 'integer':case 'number':
|
|
39
|
+
if(typeof value!=='number'||!Number.isFinite(value)||schema.type==='integer'&&!Number.isInteger(value))fail('must be a '+schema.type+'.');
|
|
40
|
+
if(schema.minimum!==undefined&&value<schema.minimum||schema.maximum!==undefined&&value>schema.maximum)fail('is outside the allowed range.');
|
|
41
|
+
if(schema.exclusiveMinimum!==undefined&&value<=schema.exclusiveMinimum||schema.exclusiveMaximum!==undefined&&value>=schema.exclusiveMaximum)fail('is outside the allowed range.');
|
|
42
|
+
break;
|
|
43
|
+
case 'boolean':if(typeof value!=='boolean')fail('must be a boolean.');break;
|
|
44
|
+
case 'null':if(value!==null)fail('must be null.');break;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/README.md
DELETED