folder-schema
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -1,2 +0,2 @@ | ||
import { SchemaNode } from './SchemaNode'; | ||
import { SchemaNode, CompareOptions } from './SchemaNode'; | ||
export default class FolderSchema { | ||
@@ -12,4 +12,5 @@ static parse(folderpath: string): Promise<SchemaNode>; | ||
* @param schema the folder schema | ||
* @param options | ||
*/ | ||
static validate(folderpath: string, schema: SchemaNode): Promise<import("./SchemaNode").CompareResult>; | ||
static validate(folderpath: string, schema: SchemaNode, options: CompareOptions): Promise<import("./SchemaNode").CompareResult>; | ||
} |
@@ -116,4 +116,5 @@ "use strict"; | ||
* @param schema the folder schema | ||
* @param options | ||
*/ | ||
FolderSchema.validate = function (folderpath, schema) { | ||
FolderSchema.validate = function (folderpath, schema, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -131,3 +132,3 @@ var targetSchema; | ||
schema.updateRootDir(targetSchema.parentDir); | ||
return [2 /*return*/, targetSchema.equals(schema)]; | ||
return [2 /*return*/, targetSchema.equals(schema, options)]; | ||
} | ||
@@ -134,0 +135,0 @@ }); |
@@ -10,2 +10,5 @@ /// <reference types="node" /> | ||
} | ||
export interface CompareOptions { | ||
strict?: boolean; | ||
} | ||
export declare class SchemaNode { | ||
@@ -17,3 +20,4 @@ abspath: string; | ||
children: SchemaNode[]; | ||
ignoreChildren: boolean; | ||
private ignoreChildren; | ||
private _optional; | ||
constructor(abspath: string, handler: Stats | NodeType); | ||
@@ -27,2 +31,3 @@ toJSON(): any; | ||
withAnyChildren(): this; | ||
optional(): this; | ||
updateRootDir(rootDir: string): void; | ||
@@ -33,4 +38,5 @@ /** | ||
* @param expectedSchema | ||
* @param options | ||
*/ | ||
equals(expectedSchema: SchemaNode): CompareResult; | ||
equals(expectedSchema: SchemaNode, options?: CompareOptions): CompareResult; | ||
} |
@@ -50,2 +50,3 @@ "use strict"; | ||
this.ignoreChildren = false; | ||
this._optional = false; | ||
this.children = []; | ||
@@ -93,2 +94,6 @@ debug('%s of type %s', this.name, this.type); | ||
}; | ||
SchemaNode.prototype.optional = function () { | ||
this._optional = true; | ||
return this; | ||
}; | ||
SchemaNode.prototype.updateRootDir = function (rootDir) { | ||
@@ -112,4 +117,5 @@ if (this.parentDir.includes(exports.ROOT_DIR)) { | ||
* @param expectedSchema | ||
* @param options | ||
*/ | ||
SchemaNode.prototype.equals = function (expectedSchema) { | ||
SchemaNode.prototype.equals = function (expectedSchema, options) { | ||
debug('check if \n%j\nequals\n%j\n', this.toJSON(), expectedSchema.toJSON()); | ||
@@ -142,2 +148,5 @@ if (this.name !== expectedSchema.name) { | ||
if (!tChild) { | ||
if (options && options.strict === false) { | ||
return "continue"; | ||
} | ||
return { value: { | ||
@@ -162,2 +171,4 @@ success: false, | ||
} | ||
// remove optional items | ||
unvisited = unvisited.filter(function (r) { return !r._optional; }); | ||
if (unvisited.length === 0) { | ||
@@ -164,0 +175,0 @@ return { success: true }; |
{ | ||
"name": "folder-schema", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "generate and validate folder shema", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
46310
18
494