tson-schema
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,147 +0,7 @@ | ||
export interface TypedSchema<T> { | ||
type: T; | ||
getSchema(): JSONSchema; | ||
} | ||
export interface JSONSchema { | ||
type: string; | ||
} | ||
/******** | ||
* Null * | ||
********/ | ||
export interface NullSchema extends JSONSchema { | ||
type: 'null'; | ||
} | ||
export declare const Null: (schema?: undefined) => TypedSchema<null>; | ||
/*********** | ||
* Numbers * | ||
***********/ | ||
export interface NumberSchemaDefinition { | ||
minimum?: number; | ||
maximum?: number; | ||
exclusiveMinimum?: boolean; | ||
exclusingMaximum?: boolean; | ||
multipleOf?: number; | ||
} | ||
export interface NumberSchema extends JSONSchema, NumberSchemaDefinition { | ||
type: 'number'; | ||
} | ||
export declare const Number: (schema?: NumberSchemaDefinition | undefined) => TypedSchema<number>; | ||
export interface IntegerSchema extends JSONSchema, NumberSchemaDefinition { | ||
type: 'integer'; | ||
} | ||
export declare const Integer: (schema?: NumberSchemaDefinition | undefined) => TypedSchema<number>; | ||
/********** | ||
* String * | ||
**********/ | ||
export declare type JSONSchemaStringFormat = 'date-time' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'json-pointer' | 'uri-template'; | ||
export interface StringSchemaDefinition { | ||
minLength?: number; | ||
maxLength?: number; | ||
pattern?: string; | ||
format?: JSONSchemaStringFormat; | ||
} | ||
export interface StringSchema extends JSONSchema, StringSchemaDefinition { | ||
type: 'string'; | ||
} | ||
export declare const String: (schema?: StringSchemaDefinition | undefined) => TypedSchema<string>; | ||
/*********** | ||
* Boolean * | ||
***********/ | ||
export interface BooleanSchema extends JSONSchema { | ||
type: 'boolean'; | ||
} | ||
export declare const Boolean: (schema?: undefined) => TypedSchema<boolean>; | ||
/********** | ||
* Arrays * | ||
**********/ | ||
interface BaseArrayDefinition { | ||
minItems?: number; | ||
maxItems?: number; | ||
uniqueItems?: boolean; | ||
} | ||
export interface ListSchemaDefinition<T> extends BaseArrayDefinition { | ||
items?: TypedSchema<T>; | ||
contains?: TypedSchema<T>; | ||
} | ||
export declare function Array<T>(schema?: ListSchemaDefinition<T>): TypedSchema<T[]>; | ||
export interface Tuple1SchemaDefinition<T1> extends BaseArrayDefinition { | ||
items: [TypedSchema<T1>]; | ||
} | ||
export interface Tuple2SchemaDefinition<T1, T2> extends BaseArrayDefinition { | ||
items: [TypedSchema<T1>, TypedSchema<T2>]; | ||
} | ||
export interface Tuple3SchemaDefinition<T1, T2, T3> extends BaseArrayDefinition { | ||
items: [TypedSchema<T1>, TypedSchema<T2>, TypedSchema<T3>]; | ||
} | ||
export interface Tuple4SchemaDefinition<T1, T2, T3, T4> extends BaseArrayDefinition { | ||
items: [TypedSchema<T1>, TypedSchema<T2>, TypedSchema<T3>, TypedSchema<T4>]; | ||
} | ||
export interface TupleAnySchemaDefinition extends BaseArrayDefinition { | ||
items: TypedSchema<any>[]; | ||
} | ||
export declare function Tuple<T1>(schema: Tuple1SchemaDefinition<T1>): TypedSchema<[T1]>; | ||
export declare function Tuple<T1, T2>(schema: Tuple2SchemaDefinition<T1, T2>): TypedSchema<[T1, T2]>; | ||
export declare function Tuple<T1, T2, T3>(schema: Tuple3SchemaDefinition<T1, T2, T3>): TypedSchema<[T1, T2, T3]>; | ||
export declare function Tuple<T1, T2, T3, T4>(schema: Tuple4SchemaDefinition<T1, T2, T3, T4>): TypedSchema<[T1, T2, T3, T4]>; | ||
/*********** | ||
* Objects * | ||
***********/ | ||
export interface ObjectDefinition<T extends {}> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: (keyof T)[]; | ||
} | ||
export interface PartialObjectDefinition<T extends {}> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: []; | ||
} | ||
export interface ObjectDefinition1<T extends {}, R1 extends keyof T> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: [R1]; | ||
} | ||
export interface ObjectDefinition2<T extends {}, R1 extends keyof T, R2 extends keyof T> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: [R1, R2]; | ||
} | ||
export interface ObjectDefinition3<T extends {}, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: [R1, R2, R3]; | ||
} | ||
export interface ObjectDefinition4<T extends {}, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T, R4 extends keyof T> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: [R1, R2, R3, R4]; | ||
} | ||
export interface ObjectDefinition5<T extends {}, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T, R4 extends keyof T, R5 extends keyof T> { | ||
properties: { | ||
[Key in keyof T]: TypedSchema<T[Key]>; | ||
}; | ||
required: [R1, R2, R3, R4, R5]; | ||
} | ||
export declare function Obj<T>(schema: PartialObjectDefinition<T>): TypedSchema<Partial<T>>; | ||
export declare function Obj<T, R1 extends keyof T>(schema: ObjectDefinition1<T, R1>): TypedSchema<Partial<T> & { | ||
[key in R1]: T[key]; | ||
}>; | ||
export declare function Obj<T, R1 extends keyof T, R2 extends keyof T>(schema: ObjectDefinition2<T, R1, R2>): TypedSchema<Partial<T> & { | ||
[key in R1 | R2]: T[key]; | ||
}>; | ||
export declare function Obj<T, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T>(schema: ObjectDefinition3<T, R1, R2, R3>): TypedSchema<Partial<T> & { | ||
[key in R1 | R2 | R3]: T[key]; | ||
}>; | ||
export declare function Obj<T, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T, R4 extends keyof T>(schema: ObjectDefinition4<T, R1, R2, R3, R4>): TypedSchema<Partial<T> & { | ||
[key in R1 | R2 | R3 | R4]: T[key]; | ||
}>; | ||
export declare function Obj<T, R1 extends keyof T, R2 extends keyof T, R3 extends keyof T, R4 extends keyof T, R5 extends keyof T>(schema: ObjectDefinition5<T, R1, R2, R3, R4, R5>): TypedSchema<Partial<T> & { | ||
[key in R1 | R2 | R3 | R4 | R5]: T[key]; | ||
}>; | ||
export {}; | ||
export * from './null'; | ||
export * from './number'; | ||
export * from './string'; | ||
export * from './boolean'; | ||
export * from './array'; | ||
export * from './object'; | ||
export * from './enum'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function defineType(type, value) { | ||
return function (schema) { | ||
if (schema === void 0) { schema = {}; } | ||
return { | ||
getSchema: function () { return Object.assign({}, schema, { type: type }); }, | ||
type: value, | ||
}; | ||
}; | ||
} | ||
exports.Null = defineType('null', null); | ||
// tslint:disable-next-line:variable-name | ||
exports.Number = defineType('number', 0); | ||
exports.Integer = defineType('integer', 0); | ||
// tslint:disable-next-line:variable-name | ||
exports.String = defineType('string', ''); | ||
// tslint:disable-next-line:variable-name | ||
exports.Boolean = defineType('boolean', true); | ||
function Array(schema) { | ||
if (schema === void 0) { schema = {}; } | ||
return { | ||
getSchema: function () { | ||
return Object.assign({}, schema, schema.items | ||
? { | ||
items: schema.items.getSchema(), | ||
type: 'array', | ||
} | ||
: { type: 'array' }); | ||
}, | ||
type: [], | ||
}; | ||
} | ||
exports.Array = Array; | ||
function Tuple(schema) { | ||
return { | ||
getSchema: function () { | ||
return Object.assign({}, schema, { | ||
items: schema.items.map(function (i) { return i.getSchema(); }), | ||
type: 'array', | ||
}); | ||
}, | ||
type: [], | ||
}; | ||
} | ||
exports.Tuple = Tuple; | ||
function Obj(schema) { | ||
return { | ||
getSchema: function () { | ||
return schema.properties | ||
? Object.assign({}, schema, { | ||
properties: Object.keys(schema.properties).reduce(function (o, k) { | ||
var _a; | ||
return schema.properties | ||
? Object.assign(o, (_a = {}, _a[k] = schema.properties[k].getSchema(), _a)) | ||
: o; | ||
}, | ||
// tslint:disable-next-line:no-object-literal-type-assertion | ||
{}), | ||
type: 'object', | ||
}) | ||
: Object.assign({}, schema, { type: 'object' }); | ||
}, | ||
// tslint:disable-next-line:no-object-literal-type-assertion | ||
type: {}, | ||
}; | ||
} | ||
exports.Obj = Obj; | ||
__export(require("./null")); | ||
__export(require("./number")); | ||
__export(require("./string")); | ||
__export(require("./boolean")); | ||
__export(require("./array")); | ||
__export(require("./object")); | ||
__export(require("./enum")); | ||
//# sourceMappingURL=tson-schema.js.map |
{ | ||
"name": "tson-schema", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A TypeScript API to create JSON-Schemas and TypeScript types", | ||
@@ -16,3 +16,4 @@ "files": [ | ||
"pretest": "yarn lint && tslint -p test/tsconfig.json", | ||
"test": "ts-node -P test/tsconfig.json $(yarn bin)/tape test/**/*.spec.ts | tap-spec" | ||
"test": "ts-node -P test/tsconfig.json $(yarn bin)/tape test/**/*.spec.ts | tap-spec", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
@@ -19,0 +20,0 @@ "author": "Michael de Wit <mjwwit@gmail.com>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25310
32
454