Comparing version 0.5.0 to 0.6.0
@@ -21,3 +21,3 @@ "use strict"; | ||
this.schema = schema; | ||
this.store = store !== null && store !== void 0 ? store : new store_1.SchemaStore().add(schema); | ||
this.store = new store_1.SchemaStore(store).add(schema); | ||
} | ||
@@ -24,0 +24,0 @@ decode(value, options = {}) { |
@@ -0,1 +1,2 @@ | ||
import { SchemaWithId } from '.'; | ||
import { SchemaDecoder } from './decoder'; | ||
@@ -7,7 +8,5 @@ import { Schema } from './schema'; | ||
constructor(parent?: SchemaStore | null); | ||
register<T>(id: string, schema: Schema<T>): this; | ||
register<T>(schema: SchemaWithId<T>): SchemaDecoder<T>; | ||
add(...schemas: Schema<unknown>[]): this; | ||
get<T>(schemaId: string): Schema<T> | null; | ||
createDecoder<T>(schema: Schema<T>): SchemaDecoder<T>; | ||
protected buildRefMap(schema: Schema<unknown>): void; | ||
} |
@@ -10,10 +10,12 @@ "use strict"; | ||
} | ||
register(id, schema) { | ||
this.refMap.set(id, schema); | ||
this.add(schema); | ||
return this; | ||
register(schema) { | ||
this.refMap.set(schema.id, schema); | ||
return new decoder_1.SchemaDecoder(schema, this); | ||
} | ||
add(...schemas) { | ||
for (const schema of schemas) { | ||
this.buildRefMap(schema); | ||
const id = schema.id; | ||
if (id) { | ||
this.refMap.set(id, schema); | ||
} | ||
} | ||
@@ -30,31 +32,3 @@ return this; | ||
} | ||
createDecoder(schema) { | ||
this.add(schema); | ||
return new decoder_1.SchemaDecoder(schema, this); | ||
} | ||
buildRefMap(schema) { | ||
var _a; | ||
if (schema.type === 'ref') { | ||
return; | ||
} | ||
if (schema.id) { | ||
this.refMap.set(schema.id, schema); | ||
} | ||
if (schema.type === 'object') { | ||
const objSchema = schema; | ||
for (const s of Object.values((_a = objSchema.properties) !== null && _a !== void 0 ? _a : {})) { | ||
this.buildRefMap(s); | ||
} | ||
if (objSchema.additionalProperties) { | ||
this.buildRefMap(objSchema.additionalProperties); | ||
} | ||
} | ||
if (schema.type === 'array') { | ||
const arrSchema = schema; | ||
if (arrSchema.items) { | ||
this.buildRefMap(arrSchema.items); | ||
} | ||
} | ||
} | ||
} | ||
exports.SchemaStore = SchemaStore; |
{ | ||
"name": "airtight", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Tight subset of JSON schema", | ||
@@ -5,0 +5,0 @@ "main": "out/main/index.js", |
16409
442