feat: docker compose maybe

This commit is contained in:
2023-11-13 16:10:04 -05:00
parent 180b261e40
commit b625ccd8d6
8031 changed files with 2182966 additions and 0 deletions

201
node_modules/ts-interface-checker/LICENSE generated vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

185
node_modules/ts-interface-checker/README.md generated vendored Normal file
View File

@ -0,0 +1,185 @@
# ts-interface-checker
[![Build Status](https://travis-ci.org/gristlabs/ts-interface-checker.svg?branch=master)](https://travis-ci.org/gristlabs/ts-interface-checker)
[![npm version](https://badge.fury.io/js/ts-interface-checker.svg)](https://badge.fury.io/js/ts-interface-checker)
> Runtime library to validate data against TypeScript interfaces.
This package is the runtime support for validators created by
[ts-interface-builder](https://github.com/gristlabs/ts-interface-builder).
It allows validating data, such as parsed JSON objects received
over the network, or parsed JSON or YAML files, to check if they satisfy a
TypeScript interface, and to produce informative error messages if they do not.
## Installation
```bash
npm install --save-dev ts-interface-builder
npm install --save ts-interface-checker
```
## Usage
Suppose you have a TypeScript file defining an interface:
```typescript
// foo.ts
interface Square {
size: number;
color?: string;
}
```
The first step is to generate some code for runtime checks:
```bash
`npm bin`/ts-interface-builder foo.ts
```
It produces a file like this:
```typescript
// foo-ti.js
import * as t from "ts-interface-checker";
export const Square = t.iface([], {
"size": "number",
"color": t.opt("string"),
});
...
```
Now at runtime, to check if a value satisfies the Square interface:
```typescript
import fooTI from "./foo-ti";
import {createCheckers} from "ts-interface-checker";
const {Square} = createCheckers(fooTI);
Square.check({size: 1}); // OK
Square.check({size: 1, color: "green"}); // OK
Square.check({color: "green"}); // Fails with "value.size is missing"
Square.check({size: 4, color: 5}); // Fails with "value.color is not a string"
```
Note that `ts-interface-builder` is only needed for the build-time step, and
`ts-interface-checker` is needed at runtime. That's why the recommendation is to npm-install the
former using `--save-dev` flag and the latter using `--save`.
## Checking method calls
If you have an interface with methods, you can validate method call arguments and return values:
```typescript
// greet.ts
interface Greeter {
greet(name: string): string;
}
```
After generating the runtime code, you can now check calls like:
```typescript
import greetTI from "./greet-ti";
import {createCheckers} from "ts-interface-checker";
const {Greeter} = createCheckers(greetTI);
Greeter.methodArgs("greet").check(["Bob"]); // OK
Greeter.methodArgs("greet").check([17]); // Fails with "value.name is not a string"
Greeter.methodArgs("greet").check([]); // Fails with "value.name is missing"
Greeter.methodResult("greet").check("hello"); // OK
Greeter.methodResult("greet").check(null); // Fails with "value is not a string"
```
## Type suites
If one type refers to a type defined in another file, you need to tell the interface checker about
all type names when you call `createCheckers()`. E.g. given
```typescript
// color.ts
export type Color = RGB | string;
export type RGB = [number, number, number];
```
```typescript
// shape.ts
import {Color} from "./color";
export interface Square {
size: number;
color?: Color;
}
```
the produced files `color-ti.ts` and `shape-ti.ts` do not automatically refer to each other, but
expect you to relate them in `createCheckers()` call:
```typescript
import color from "./color-ti";
import shape from "./shape-ti";
import {createCheckers} from "ts-interface-checker";
const {Square} = createCheckers(shape, color); // Pass in all required type suites.
Square.check({size: 1, color: [255,255,255]});
```
## Strict checking
You may check that data contains no extra properties. Note that it is not generally recommended as
it this prevents backward compatibility: if you add new properties to an interface, then older
code with strict checks will not accept them.
Following on the example above:
```typescript
Square.strictCheck({size: 1, color: [255,255,255], bg: "blue"}); // Fails with value.bg is extraneous
Square.strictCheck({size: 1, color: [255,255,255,0.5]}); // Fails with ...value.color[3] is extraneous
```
## Type guards
Standard `Checker` objects do the type checking logic, but are unable to make the TypeScript
compiler aware that an object of `unknown` type implements a certain interface.
Basic code:
```typescript
const unk: unknown = {size: 1, color: "green"};
// Type is unknown, so TypeScript will not let you access the members.
console.log(unk.size); // Error: "Object is of type 'unknown'"
```
With a `Checker` available:
```typescript
import fooTI from "./foo-ti";
import {createCheckers} from "ts-interface-checker";
const {Square} = createCheckers(fooTI);
const unk: unknown = {size: 1, color: "green"};
if (Square.test(unk)) {
// unk does implement Square, but TypeScript is not aware of it.
console.log(unk.size); // Error: "Object is of type 'unknown'"
}
```
To enable type guard functionality on the existing `test`, and `strictTest` functions, `Checker`
objects should be cast to `CheckerT<>` using the appropriate type.
Using `CheckerT<>`:
```typescript
import {Square} from "./foo";
import fooTI from "./foo-ti";
import {createCheckers, CheckerT} from "ts-interface-checker";
const {Square} = createCheckers(fooTI) as {Square: CheckerT<Square>};
const unk: unknown = {size: 1, color: "green"};
if (Square.test(unk)) {
// TypeScript is now aware that unk implements Square, and allows member access.
console.log(unk.size);
}
```
## Type assertions
`CheckerT<>` will eventually support type assertions using the `check` and `strictCheck` functions,
however, this feature is not yet fully working in TypeScript.

124
node_modules/ts-interface-checker/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,124 @@
import { ITypeSuite, TType } from "./types";
import { IErrorDetail } from "./util";
/**
* Export functions used to define interfaces.
*/
export { TArray, TEnumType, TEnumLiteral, TFunc, TIface, TLiteral, TName, TOptional, TParam, TParamList, TProp, TTuple, TType, TUnion, TIntersection, array, enumlit, enumtype, func, iface, lit, name, opt, param, tuple, union, intersection, BasicType, ITypeSuite, } from "./types";
export { VError, IErrorDetail } from './util';
export interface ICheckerSuite {
[name: string]: Checker;
}
/**
* Takes one of more type suites (e.g. a module generated by `ts-interface-builder`), and combines
* them into a suite of interface checkers. If a type is used by name, that name should be present
* among the passed-in type suites.
*
* The returned object maps type names to Checker objects.
*/
export declare function createCheckers(...typeSuite: ITypeSuite[]): ICheckerSuite;
/**
* Checker implements validation of objects, and also includes accessors to validate method calls.
* Checkers should be created using `createCheckers()`.
*/
export declare class Checker {
private suite;
private ttype;
private _path;
private props;
private checkerPlain;
private checkerStrict;
constructor(suite: ITypeSuite, ttype: TType, _path?: string);
/**
* Set the path to report in errors, instead of the default "value". (E.g. if the Checker is for
* a "person" interface, set path to "person" to report e.g. "person.name is not a string".)
*/
setReportedPath(path: string): void;
/**
* Check that the given value satisfies this checker's type, or throw Error.
*/
check(value: any): void;
/**
* A fast check for whether or not the given value satisfies this Checker's type. This returns
* true or false, does not produce an error message, and is fast both on success and on failure.
*/
test(value: any): boolean;
/**
* Returns an error object describing the errors if the given value does not satisfy this
* Checker's type, or null if it does.
*/
validate(value: any): IErrorDetail | null;
/**
* Check that the given value satisfies this checker's type strictly. This checks that objects
* and tuples have no extra members. Note that this prevents backward compatibility, so usually
* a plain check() is more appropriate.
*/
strictCheck(value: any): void;
/**
* A fast strict check for whether or not the given value satisfies this Checker's type. Returns
* true or false, does not produce an error message, and is fast both on success and on failure.
*/
strictTest(value: any): boolean;
/**
* Returns an error object describing the errors if the given value does not satisfy this
* Checker's type strictly, or null if it does.
*/
strictValidate(value: any): IErrorDetail | null;
/**
* If this checker is for an interface, returns a Checker for the type required for the given
* property of this interface.
*/
getProp(prop: string): Checker;
/**
* If this checker is for an interface, returns a Checker for the argument-list required to call
* the given method of this interface. E.g. if this Checker is for the interface:
* interface Foo {
* find(s: string, pos?: number): number;
* }
* Then methodArgs("find").check(...) will succeed for ["foo"] and ["foo", 3], but not for [17].
*/
methodArgs(methodName: string): Checker;
/**
* If this checker is for an interface, returns a Checker for the return value of the given
* method of this interface.
*/
methodResult(methodName: string): Checker;
/**
* If this checker is for a function, returns a Checker for its argument-list.
*/
getArgs(): Checker;
/**
* If this checker is for a function, returns a Checker for its result.
*/
getResult(): Checker;
/**
* Return the type for which this is a checker.
*/
getType(): TType;
/**
* Actual implementation of check() and strictCheck().
*/
private _doCheck;
private _doValidate;
private _getMethod;
}
/**
* Typed checker interface. Adds type guard functionality to a normal `Checker`.
*
* To use, cast a `Checker` to a `CheckerT<>` using the appropriate type.
*
* eg.
* import { MyInterface } from './my-interface';
* import MyInterfaceTi from './my-interface-ti';
*
* const checkers = createCheckers(MyInterfaceTi) as {
* MyInterface: CheckerT<MyInterface>
* };
*
* TODO:
* - Enable `check()` and `strictCheck()` type assertion definitions once the functionality
* is correctly working in TypeScript. (https://github.com/microsoft/TypeScript/issues/36931)
*/
export interface CheckerT<T> extends Checker {
test(value: any): value is T;
strictTest(value: any): value is T;
}

224
node_modules/ts-interface-checker/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,224 @@
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Checker = exports.createCheckers = void 0;
var types_1 = require("./types");
var util_1 = require("./util");
/**
* Export functions used to define interfaces.
*/
var types_2 = require("./types");
Object.defineProperty(exports, "TArray", { enumerable: true, get: function () { return types_2.TArray; } });
Object.defineProperty(exports, "TEnumType", { enumerable: true, get: function () { return types_2.TEnumType; } });
Object.defineProperty(exports, "TEnumLiteral", { enumerable: true, get: function () { return types_2.TEnumLiteral; } });
Object.defineProperty(exports, "TFunc", { enumerable: true, get: function () { return types_2.TFunc; } });
Object.defineProperty(exports, "TIface", { enumerable: true, get: function () { return types_2.TIface; } });
Object.defineProperty(exports, "TLiteral", { enumerable: true, get: function () { return types_2.TLiteral; } });
Object.defineProperty(exports, "TName", { enumerable: true, get: function () { return types_2.TName; } });
Object.defineProperty(exports, "TOptional", { enumerable: true, get: function () { return types_2.TOptional; } });
Object.defineProperty(exports, "TParam", { enumerable: true, get: function () { return types_2.TParam; } });
Object.defineProperty(exports, "TParamList", { enumerable: true, get: function () { return types_2.TParamList; } });
Object.defineProperty(exports, "TProp", { enumerable: true, get: function () { return types_2.TProp; } });
Object.defineProperty(exports, "TTuple", { enumerable: true, get: function () { return types_2.TTuple; } });
Object.defineProperty(exports, "TType", { enumerable: true, get: function () { return types_2.TType; } });
Object.defineProperty(exports, "TUnion", { enumerable: true, get: function () { return types_2.TUnion; } });
Object.defineProperty(exports, "TIntersection", { enumerable: true, get: function () { return types_2.TIntersection; } });
Object.defineProperty(exports, "array", { enumerable: true, get: function () { return types_2.array; } });
Object.defineProperty(exports, "enumlit", { enumerable: true, get: function () { return types_2.enumlit; } });
Object.defineProperty(exports, "enumtype", { enumerable: true, get: function () { return types_2.enumtype; } });
Object.defineProperty(exports, "func", { enumerable: true, get: function () { return types_2.func; } });
Object.defineProperty(exports, "iface", { enumerable: true, get: function () { return types_2.iface; } });
Object.defineProperty(exports, "lit", { enumerable: true, get: function () { return types_2.lit; } });
Object.defineProperty(exports, "name", { enumerable: true, get: function () { return types_2.name; } });
Object.defineProperty(exports, "opt", { enumerable: true, get: function () { return types_2.opt; } });
Object.defineProperty(exports, "param", { enumerable: true, get: function () { return types_2.param; } });
Object.defineProperty(exports, "tuple", { enumerable: true, get: function () { return types_2.tuple; } });
Object.defineProperty(exports, "union", { enumerable: true, get: function () { return types_2.union; } });
Object.defineProperty(exports, "intersection", { enumerable: true, get: function () { return types_2.intersection; } });
Object.defineProperty(exports, "BasicType", { enumerable: true, get: function () { return types_2.BasicType; } });
var util_2 = require("./util");
Object.defineProperty(exports, "VError", { enumerable: true, get: function () { return util_2.VError; } });
/**
* Takes one of more type suites (e.g. a module generated by `ts-interface-builder`), and combines
* them into a suite of interface checkers. If a type is used by name, that name should be present
* among the passed-in type suites.
*
* The returned object maps type names to Checker objects.
*/
function createCheckers() {
var typeSuite = [];
for (var _i = 0; _i < arguments.length; _i++) {
typeSuite[_i] = arguments[_i];
}
var fullSuite = Object.assign.apply(Object, __spreadArrays([{}, types_1.basicTypes], typeSuite));
var checkers = {};
for (var _a = 0, typeSuite_1 = typeSuite; _a < typeSuite_1.length; _a++) {
var suite_1 = typeSuite_1[_a];
for (var _b = 0, _c = Object.keys(suite_1); _b < _c.length; _b++) {
var name = _c[_b];
checkers[name] = new Checker(fullSuite, suite_1[name]);
}
}
return checkers;
}
exports.createCheckers = createCheckers;
/**
* Checker implements validation of objects, and also includes accessors to validate method calls.
* Checkers should be created using `createCheckers()`.
*/
var Checker = /** @class */ (function () {
// Create checkers by using `createCheckers()` function.
function Checker(suite, ttype, _path) {
if (_path === void 0) { _path = 'value'; }
this.suite = suite;
this.ttype = ttype;
this._path = _path;
this.props = new Map();
if (ttype instanceof types_1.TIface) {
for (var _i = 0, _a = ttype.props; _i < _a.length; _i++) {
var p = _a[_i];
this.props.set(p.name, p.ttype);
}
}
this.checkerPlain = this.ttype.getChecker(suite, false);
this.checkerStrict = this.ttype.getChecker(suite, true);
}
/**
* Set the path to report in errors, instead of the default "value". (E.g. if the Checker is for
* a "person" interface, set path to "person" to report e.g. "person.name is not a string".)
*/
Checker.prototype.setReportedPath = function (path) {
this._path = path;
};
/**
* Check that the given value satisfies this checker's type, or throw Error.
*/
Checker.prototype.check = function (value) { return this._doCheck(this.checkerPlain, value); };
/**
* A fast check for whether or not the given value satisfies this Checker's type. This returns
* true or false, does not produce an error message, and is fast both on success and on failure.
*/
Checker.prototype.test = function (value) {
return this.checkerPlain(value, new util_1.NoopContext());
};
/**
* Returns an error object describing the errors if the given value does not satisfy this
* Checker's type, or null if it does.
*/
Checker.prototype.validate = function (value) {
return this._doValidate(this.checkerPlain, value);
};
/**
* Check that the given value satisfies this checker's type strictly. This checks that objects
* and tuples have no extra members. Note that this prevents backward compatibility, so usually
* a plain check() is more appropriate.
*/
Checker.prototype.strictCheck = function (value) { return this._doCheck(this.checkerStrict, value); };
/**
* A fast strict check for whether or not the given value satisfies this Checker's type. Returns
* true or false, does not produce an error message, and is fast both on success and on failure.
*/
Checker.prototype.strictTest = function (value) {
return this.checkerStrict(value, new util_1.NoopContext());
};
/**
* Returns an error object describing the errors if the given value does not satisfy this
* Checker's type strictly, or null if it does.
*/
Checker.prototype.strictValidate = function (value) {
return this._doValidate(this.checkerStrict, value);
};
/**
* If this checker is for an interface, returns a Checker for the type required for the given
* property of this interface.
*/
Checker.prototype.getProp = function (prop) {
var ttype = this.props.get(prop);
if (!ttype) {
throw new Error("Type has no property " + prop);
}
return new Checker(this.suite, ttype, this._path + "." + prop);
};
/**
* If this checker is for an interface, returns a Checker for the argument-list required to call
* the given method of this interface. E.g. if this Checker is for the interface:
* interface Foo {
* find(s: string, pos?: number): number;
* }
* Then methodArgs("find").check(...) will succeed for ["foo"] and ["foo", 3], but not for [17].
*/
Checker.prototype.methodArgs = function (methodName) {
var tfunc = this._getMethod(methodName);
return new Checker(this.suite, tfunc.paramList);
};
/**
* If this checker is for an interface, returns a Checker for the return value of the given
* method of this interface.
*/
Checker.prototype.methodResult = function (methodName) {
var tfunc = this._getMethod(methodName);
return new Checker(this.suite, tfunc.result);
};
/**
* If this checker is for a function, returns a Checker for its argument-list.
*/
Checker.prototype.getArgs = function () {
if (!(this.ttype instanceof types_1.TFunc)) {
throw new Error("getArgs() applied to non-function");
}
return new Checker(this.suite, this.ttype.paramList);
};
/**
* If this checker is for a function, returns a Checker for its result.
*/
Checker.prototype.getResult = function () {
if (!(this.ttype instanceof types_1.TFunc)) {
throw new Error("getResult() applied to non-function");
}
return new Checker(this.suite, this.ttype.result);
};
/**
* Return the type for which this is a checker.
*/
Checker.prototype.getType = function () {
return this.ttype;
};
/**
* Actual implementation of check() and strictCheck().
*/
Checker.prototype._doCheck = function (checkerFunc, value) {
var noopCtx = new util_1.NoopContext();
if (!checkerFunc(value, noopCtx)) {
var detailCtx = new util_1.DetailContext();
checkerFunc(value, detailCtx);
throw detailCtx.getError(this._path);
}
};
Checker.prototype._doValidate = function (checkerFunc, value) {
var noopCtx = new util_1.NoopContext();
if (checkerFunc(value, noopCtx)) {
return null;
}
var detailCtx = new util_1.DetailContext();
checkerFunc(value, detailCtx);
return detailCtx.getErrorDetail(this._path);
};
Checker.prototype._getMethod = function (methodName) {
var ttype = this.props.get(methodName);
if (!ttype) {
throw new Error("Type has no property " + methodName);
}
if (!(ttype instanceof types_1.TFunc)) {
throw new Error("Property " + methodName + " is not a method");
}
return ttype;
};
return Checker;
}());
exports.Checker = Checker;

181
node_modules/ts-interface-checker/dist/types.d.ts generated vendored Normal file
View File

@ -0,0 +1,181 @@
/**
* This module defines nodes used to define types and validations for objects and interfaces.
*/
import { IContext } from "./util";
export declare type CheckerFunc = (value: any, ctx: IContext) => boolean;
/** Node that represents a type. */
export declare abstract class TType {
abstract getChecker(suite: ITypeSuite, strict: boolean, allowedProps?: Set<string>): CheckerFunc;
}
/**
* Descriptor from which TType may be build (by parseSpec()). A plain string is equivalent to
* name(string).
*/
export declare type TypeSpec = TType | string;
/**
* Represents a suite of named types. Suites are used to resolve type names.
*/
export interface ITypeSuite {
[name: string]: TType;
}
/**
* Defines a type name, either built-in, or defined in this suite. It can typically be included in
* the specs as just a plain string.
*/
export declare function name(value: string): TName;
export declare class TName extends TType {
name: string;
private _failMsg;
constructor(name: string);
getChecker(suite: ITypeSuite, strict: boolean, allowedProps?: Set<string>): CheckerFunc;
}
/**
* Defines a literal value, e.g. lit('hello') or lit(123).
*/
export declare function lit(value: any): TLiteral;
export declare class TLiteral extends TType {
value: any;
name: string;
private _failMsg;
constructor(value: any);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines an array type, e.g. array('number').
*/
export declare function array(typeSpec: TypeSpec): TArray;
export declare class TArray extends TType {
ttype: TType;
constructor(ttype: TType);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines a tuple type, e.g. tuple('string', 'number').
*/
export declare function tuple(...typeSpec: TypeSpec[]): TTuple;
export declare class TTuple extends TType {
ttypes: TType[];
constructor(ttypes: TType[]);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines a union type, e.g. union('number', 'null').
*/
export declare function union(...typeSpec: TypeSpec[]): TUnion;
export declare class TUnion extends TType {
ttypes: TType[];
private _failMsg;
constructor(ttypes: TType[]);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines an intersection type, e.g. intersection('number', 'null').
*/
export declare function intersection(...typeSpec: TypeSpec[]): TIntersection;
export declare class TIntersection extends TType {
ttypes: TType[];
constructor(ttypes: TType[]);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines an enum type, e.g. enum({'A': 1, 'B': 2}).
*/
export declare function enumtype(values: {
[name: string]: string | number;
}): TEnumType;
export declare class TEnumType extends TType {
members: {
[name: string]: string | number;
};
readonly validValues: Set<string | number>;
private _failMsg;
constructor(members: {
[name: string]: string | number;
});
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines a literal enum value, such as Direction.Up, specified as enumlit("Direction", "Up").
*/
export declare function enumlit(name: string, prop: string): TEnumLiteral;
export declare class TEnumLiteral extends TType {
enumName: string;
prop: string;
private _failMsg;
constructor(enumName: string, prop: string);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines an interface. The first argument is an array of interfaces that it extends, and the
* second is an array of properties.
*/
export declare function iface(bases: string[], props: {
[name: string]: TOptional | TypeSpec;
}): TIface;
export declare class TIface extends TType {
bases: string[];
props: TProp[];
private propSet;
constructor(bases: string[], props: TProp[]);
getChecker(suite: ITypeSuite, strict: boolean, allowedProps?: Set<string>): CheckerFunc;
}
/**
* Defines an optional property on an interface.
*/
export declare function opt(typeSpec: TypeSpec): TOptional;
export declare class TOptional extends TType {
ttype: TType;
constructor(ttype: TType);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines a property in an interface.
*/
export declare class TProp {
name: string;
ttype: TType;
isOpt: boolean;
constructor(name: string, ttype: TType, isOpt: boolean);
}
/**
* Defines a function. The first argument declares the function's return type, the rest declare
* its parameters.
*/
export declare function func(resultSpec: TypeSpec, ...params: TParam[]): TFunc;
export declare class TFunc extends TType {
paramList: TParamList;
result: TType;
constructor(paramList: TParamList, result: TType);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines a function parameter.
*/
export declare function param(name: string, typeSpec: TypeSpec, isOpt?: boolean): TParam;
export declare class TParam {
name: string;
ttype: TType;
isOpt: boolean;
constructor(name: string, ttype: TType, isOpt: boolean);
}
/**
* Defines a function parameter list.
*/
export declare class TParamList extends TType {
params: TParam[];
constructor(params: TParam[]);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Single TType implementation for all basic built-in types.
*/
export declare class BasicType extends TType {
validator: (value: any) => boolean;
private message;
constructor(validator: (value: any) => boolean, message: string);
getChecker(suite: ITypeSuite, strict: boolean): CheckerFunc;
}
/**
* Defines the suite of basic types.
*/
export declare const basicTypes: ITypeSuite;

566
node_modules/ts-interface-checker/dist/types.js generated vendored Normal file
View File

@ -0,0 +1,566 @@
"use strict";
/**
* This module defines nodes used to define types and validations for objects and interfaces.
*/
// tslint:disable:no-shadowed-variable prefer-for-of
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.basicTypes = exports.BasicType = exports.TParamList = exports.TParam = exports.param = exports.TFunc = exports.func = exports.TProp = exports.TOptional = exports.opt = exports.TIface = exports.iface = exports.TEnumLiteral = exports.enumlit = exports.TEnumType = exports.enumtype = exports.TIntersection = exports.intersection = exports.TUnion = exports.union = exports.TTuple = exports.tuple = exports.TArray = exports.array = exports.TLiteral = exports.lit = exports.TName = exports.name = exports.TType = void 0;
var util_1 = require("./util");
/** Node that represents a type. */
var TType = /** @class */ (function () {
function TType() {
}
return TType;
}());
exports.TType = TType;
/** Parses a type spec into a TType node. */
function parseSpec(typeSpec) {
return typeof typeSpec === "string" ? name(typeSpec) : typeSpec;
}
function getNamedType(suite, name) {
var ttype = suite[name];
if (!ttype) {
throw new Error("Unknown type " + name);
}
return ttype;
}
/**
* Defines a type name, either built-in, or defined in this suite. It can typically be included in
* the specs as just a plain string.
*/
function name(value) { return new TName(value); }
exports.name = name;
var TName = /** @class */ (function (_super) {
__extends(TName, _super);
function TName(name) {
var _this = _super.call(this) || this;
_this.name = name;
_this._failMsg = "is not a " + name;
return _this;
}
TName.prototype.getChecker = function (suite, strict, allowedProps) {
var _this = this;
var ttype = getNamedType(suite, this.name);
var checker = ttype.getChecker(suite, strict, allowedProps);
if (ttype instanceof BasicType || ttype instanceof TName) {
return checker;
}
// For complex types, add an additional "is not a <Type>" message on failure.
return function (value, ctx) { return checker(value, ctx) ? true : ctx.fail(null, _this._failMsg, 0); };
};
return TName;
}(TType));
exports.TName = TName;
/**
* Defines a literal value, e.g. lit('hello') or lit(123).
*/
function lit(value) { return new TLiteral(value); }
exports.lit = lit;
var TLiteral = /** @class */ (function (_super) {
__extends(TLiteral, _super);
function TLiteral(value) {
var _this = _super.call(this) || this;
_this.value = value;
_this.name = JSON.stringify(value);
_this._failMsg = "is not " + _this.name;
return _this;
}
TLiteral.prototype.getChecker = function (suite, strict) {
var _this = this;
return function (value, ctx) { return (value === _this.value) ? true : ctx.fail(null, _this._failMsg, -1); };
};
return TLiteral;
}(TType));
exports.TLiteral = TLiteral;
/**
* Defines an array type, e.g. array('number').
*/
function array(typeSpec) { return new TArray(parseSpec(typeSpec)); }
exports.array = array;
var TArray = /** @class */ (function (_super) {
__extends(TArray, _super);
function TArray(ttype) {
var _this = _super.call(this) || this;
_this.ttype = ttype;
return _this;
}
TArray.prototype.getChecker = function (suite, strict) {
var itemChecker = this.ttype.getChecker(suite, strict);
return function (value, ctx) {
if (!Array.isArray(value)) {
return ctx.fail(null, "is not an array", 0);
}
for (var i = 0; i < value.length; i++) {
var ok = itemChecker(value[i], ctx);
if (!ok) {
return ctx.fail(i, null, 1);
}
}
return true;
};
};
return TArray;
}(TType));
exports.TArray = TArray;
/**
* Defines a tuple type, e.g. tuple('string', 'number').
*/
function tuple() {
var typeSpec = [];
for (var _i = 0; _i < arguments.length; _i++) {
typeSpec[_i] = arguments[_i];
}
return new TTuple(typeSpec.map(function (t) { return parseSpec(t); }));
}
exports.tuple = tuple;
var TTuple = /** @class */ (function (_super) {
__extends(TTuple, _super);
function TTuple(ttypes) {
var _this = _super.call(this) || this;
_this.ttypes = ttypes;
return _this;
}
TTuple.prototype.getChecker = function (suite, strict) {
var itemCheckers = this.ttypes.map(function (t) { return t.getChecker(suite, strict); });
var checker = function (value, ctx) {
if (!Array.isArray(value)) {
return ctx.fail(null, "is not an array", 0);
}
for (var i = 0; i < itemCheckers.length; i++) {
var ok = itemCheckers[i](value[i], ctx);
if (!ok) {
return ctx.fail(i, null, 1);
}
}
return true;
};
if (!strict) {
return checker;
}
return function (value, ctx) {
if (!checker(value, ctx)) {
return false;
}
return value.length <= itemCheckers.length ? true :
ctx.fail(itemCheckers.length, "is extraneous", 2);
};
};
return TTuple;
}(TType));
exports.TTuple = TTuple;
/**
* Defines a union type, e.g. union('number', 'null').
*/
function union() {
var typeSpec = [];
for (var _i = 0; _i < arguments.length; _i++) {
typeSpec[_i] = arguments[_i];
}
return new TUnion(typeSpec.map(function (t) { return parseSpec(t); }));
}
exports.union = union;
var TUnion = /** @class */ (function (_super) {
__extends(TUnion, _super);
function TUnion(ttypes) {
var _this = _super.call(this) || this;
_this.ttypes = ttypes;
var names = ttypes.map(function (t) { return t instanceof TName || t instanceof TLiteral ? t.name : null; })
.filter(function (n) { return n; });
var otherTypes = ttypes.length - names.length;
if (names.length) {
if (otherTypes > 0) {
names.push(otherTypes + " more");
}
_this._failMsg = "is none of " + names.join(", ");
}
else {
_this._failMsg = "is none of " + otherTypes + " types";
}
return _this;
}
TUnion.prototype.getChecker = function (suite, strict) {
var _this = this;
var itemCheckers = this.ttypes.map(function (t) { return t.getChecker(suite, strict); });
return function (value, ctx) {
var ur = ctx.unionResolver();
for (var i = 0; i < itemCheckers.length; i++) {
var ok = itemCheckers[i](value, ur.createContext());
if (ok) {
return true;
}
}
ctx.resolveUnion(ur);
return ctx.fail(null, _this._failMsg, 0);
};
};
return TUnion;
}(TType));
exports.TUnion = TUnion;
/**
* Defines an intersection type, e.g. intersection('number', 'null').
*/
function intersection() {
var typeSpec = [];
for (var _i = 0; _i < arguments.length; _i++) {
typeSpec[_i] = arguments[_i];
}
return new TIntersection(typeSpec.map(function (t) { return parseSpec(t); }));
}
exports.intersection = intersection;
var TIntersection = /** @class */ (function (_super) {
__extends(TIntersection, _super);
function TIntersection(ttypes) {
var _this = _super.call(this) || this;
_this.ttypes = ttypes;
return _this;
}
TIntersection.prototype.getChecker = function (suite, strict) {
var allowedProps = new Set();
var itemCheckers = this.ttypes.map(function (t) { return t.getChecker(suite, strict, allowedProps); });
return function (value, ctx) {
var ok = itemCheckers.every(function (checker) { return checker(value, ctx); });
if (ok) {
return true;
}
return ctx.fail(null, null, 0);
};
};
return TIntersection;
}(TType));
exports.TIntersection = TIntersection;
/**
* Defines an enum type, e.g. enum({'A': 1, 'B': 2}).
*/
function enumtype(values) {
return new TEnumType(values);
}
exports.enumtype = enumtype;
var TEnumType = /** @class */ (function (_super) {
__extends(TEnumType, _super);
function TEnumType(members) {
var _this = _super.call(this) || this;
_this.members = members;
_this.validValues = new Set();
_this._failMsg = "is not a valid enum value";
_this.validValues = new Set(Object.keys(members).map(function (name) { return members[name]; }));
return _this;
}
TEnumType.prototype.getChecker = function (suite, strict) {
var _this = this;
return function (value, ctx) {
return (_this.validValues.has(value) ? true : ctx.fail(null, _this._failMsg, 0));
};
};
return TEnumType;
}(TType));
exports.TEnumType = TEnumType;
/**
* Defines a literal enum value, such as Direction.Up, specified as enumlit("Direction", "Up").
*/
function enumlit(name, prop) {
return new TEnumLiteral(name, prop);
}
exports.enumlit = enumlit;
var TEnumLiteral = /** @class */ (function (_super) {
__extends(TEnumLiteral, _super);
function TEnumLiteral(enumName, prop) {
var _this = _super.call(this) || this;
_this.enumName = enumName;
_this.prop = prop;
_this._failMsg = "is not " + enumName + "." + prop;
return _this;
}
TEnumLiteral.prototype.getChecker = function (suite, strict) {
var _this = this;
var ttype = getNamedType(suite, this.enumName);
if (!(ttype instanceof TEnumType)) {
throw new Error("Type " + this.enumName + " used in enumlit is not an enum type");
}
var val = ttype.members[this.prop];
if (!ttype.members.hasOwnProperty(this.prop)) {
throw new Error("Unknown value " + this.enumName + "." + this.prop + " used in enumlit");
}
return function (value, ctx) { return (value === val) ? true : ctx.fail(null, _this._failMsg, -1); };
};
return TEnumLiteral;
}(TType));
exports.TEnumLiteral = TEnumLiteral;
function makeIfaceProps(props) {
return Object.keys(props).map(function (name) { return makeIfaceProp(name, props[name]); });
}
function makeIfaceProp(name, prop) {
return prop instanceof TOptional ?
new TProp(name, prop.ttype, true) :
new TProp(name, parseSpec(prop), false);
}
/**
* Defines an interface. The first argument is an array of interfaces that it extends, and the
* second is an array of properties.
*/
function iface(bases, props) {
return new TIface(bases, makeIfaceProps(props));
}
exports.iface = iface;
var TIface = /** @class */ (function (_super) {
__extends(TIface, _super);
function TIface(bases, props) {
var _this = _super.call(this) || this;
_this.bases = bases;
_this.props = props;
_this.propSet = new Set(props.map(function (p) { return p.name; }));
return _this;
}
TIface.prototype.getChecker = function (suite, strict, allowedProps) {
var _this = this;
var baseCheckers = this.bases.map(function (b) { return getNamedType(suite, b).getChecker(suite, strict); });
var propCheckers = this.props.map(function (prop) { return prop.ttype.getChecker(suite, strict); });
var testCtx = new util_1.NoopContext();
// Consider a prop required if it's not optional AND does not allow for undefined as a value.
var isPropRequired = this.props.map(function (prop, i) {
return !prop.isOpt && !propCheckers[i](undefined, testCtx);
});
var checker = function (value, ctx) {
if (typeof value !== "object" || value === null) {
return ctx.fail(null, "is not an object", 0);
}
for (var i = 0; i < baseCheckers.length; i++) {
if (!baseCheckers[i](value, ctx)) {
return false;
}
}
for (var i = 0; i < propCheckers.length; i++) {
var name_1 = _this.props[i].name;
var v = value[name_1];
if (v === undefined) {
if (isPropRequired[i]) {
return ctx.fail(name_1, "is missing", 1);
}
}
else {
var ok = propCheckers[i](v, ctx);
if (!ok) {
return ctx.fail(name_1, null, 1);
}
}
}
return true;
};
if (!strict) {
return checker;
}
var propSet = this.propSet;
if (allowedProps) {
this.propSet.forEach(function (prop) { return allowedProps.add(prop); });
propSet = allowedProps;
}
// In strict mode, check also for unknown enumerable properties.
return function (value, ctx) {
if (!checker(value, ctx)) {
return false;
}
for (var prop in value) {
if (!propSet.has(prop)) {
return ctx.fail(prop, "is extraneous", 2);
}
}
return true;
};
};
return TIface;
}(TType));
exports.TIface = TIface;
/**
* Defines an optional property on an interface.
*/
function opt(typeSpec) { return new TOptional(parseSpec(typeSpec)); }
exports.opt = opt;
var TOptional = /** @class */ (function (_super) {
__extends(TOptional, _super);
function TOptional(ttype) {
var _this = _super.call(this) || this;
_this.ttype = ttype;
return _this;
}
TOptional.prototype.getChecker = function (suite, strict) {
var itemChecker = this.ttype.getChecker(suite, strict);
return function (value, ctx) {
return value === undefined || itemChecker(value, ctx);
};
};
return TOptional;
}(TType));
exports.TOptional = TOptional;
/**
* Defines a property in an interface.
*/
var TProp = /** @class */ (function () {
function TProp(name, ttype, isOpt) {
this.name = name;
this.ttype = ttype;
this.isOpt = isOpt;
}
return TProp;
}());
exports.TProp = TProp;
/**
* Defines a function. The first argument declares the function's return type, the rest declare
* its parameters.
*/
function func(resultSpec) {
var params = [];
for (var _i = 1; _i < arguments.length; _i++) {
params[_i - 1] = arguments[_i];
}
return new TFunc(new TParamList(params), parseSpec(resultSpec));
}
exports.func = func;
var TFunc = /** @class */ (function (_super) {
__extends(TFunc, _super);
function TFunc(paramList, result) {
var _this = _super.call(this) || this;
_this.paramList = paramList;
_this.result = result;
return _this;
}
TFunc.prototype.getChecker = function (suite, strict) {
return function (value, ctx) {
return typeof value === "function" ? true : ctx.fail(null, "is not a function", 0);
};
};
return TFunc;
}(TType));
exports.TFunc = TFunc;
/**
* Defines a function parameter.
*/
function param(name, typeSpec, isOpt) {
return new TParam(name, parseSpec(typeSpec), Boolean(isOpt));
}
exports.param = param;
var TParam = /** @class */ (function () {
function TParam(name, ttype, isOpt) {
this.name = name;
this.ttype = ttype;
this.isOpt = isOpt;
}
return TParam;
}());
exports.TParam = TParam;
/**
* Defines a function parameter list.
*/
var TParamList = /** @class */ (function (_super) {
__extends(TParamList, _super);
function TParamList(params) {
var _this = _super.call(this) || this;
_this.params = params;
return _this;
}
TParamList.prototype.getChecker = function (suite, strict) {
var _this = this;
var itemCheckers = this.params.map(function (t) { return t.ttype.getChecker(suite, strict); });
var testCtx = new util_1.NoopContext();
var isParamRequired = this.params.map(function (param, i) {
return !param.isOpt && !itemCheckers[i](undefined, testCtx);
});
var checker = function (value, ctx) {
if (!Array.isArray(value)) {
return ctx.fail(null, "is not an array", 0);
}
for (var i = 0; i < itemCheckers.length; i++) {
var p = _this.params[i];
if (value[i] === undefined) {
if (isParamRequired[i]) {
return ctx.fail(p.name, "is missing", 1);
}
}
else {
var ok = itemCheckers[i](value[i], ctx);
if (!ok) {
return ctx.fail(p.name, null, 1);
}
}
}
return true;
};
if (!strict) {
return checker;
}
return function (value, ctx) {
if (!checker(value, ctx)) {
return false;
}
return value.length <= itemCheckers.length ? true :
ctx.fail(itemCheckers.length, "is extraneous", 2);
};
};
return TParamList;
}(TType));
exports.TParamList = TParamList;
/**
* Single TType implementation for all basic built-in types.
*/
var BasicType = /** @class */ (function (_super) {
__extends(BasicType, _super);
function BasicType(validator, message) {
var _this = _super.call(this) || this;
_this.validator = validator;
_this.message = message;
return _this;
}
BasicType.prototype.getChecker = function (suite, strict) {
var _this = this;
return function (value, ctx) { return _this.validator(value) ? true : ctx.fail(null, _this.message, 0); };
};
return BasicType;
}(TType));
exports.BasicType = BasicType;
/**
* Defines the suite of basic types.
*/
exports.basicTypes = {
any: new BasicType(function (v) { return true; }, "is invalid"),
number: new BasicType(function (v) { return (typeof v === "number"); }, "is not a number"),
object: new BasicType(function (v) { return (typeof v === "object" && v); }, "is not an object"),
boolean: new BasicType(function (v) { return (typeof v === "boolean"); }, "is not a boolean"),
string: new BasicType(function (v) { return (typeof v === "string"); }, "is not a string"),
symbol: new BasicType(function (v) { return (typeof v === "symbol"); }, "is not a symbol"),
void: new BasicType(function (v) { return (v == null); }, "is not void"),
undefined: new BasicType(function (v) { return (v === undefined); }, "is not undefined"),
null: new BasicType(function (v) { return (v === null); }, "is not null"),
never: new BasicType(function (v) { return false; }, "is unexpected"),
Date: new BasicType(getIsNativeChecker("[object Date]"), "is not a Date"),
RegExp: new BasicType(getIsNativeChecker("[object RegExp]"), "is not a RegExp"),
};
// This approach for checking native object types mirrors that of lodash. Its advantage over
// `isinstance` is that it can still return true for native objects created in different JS
// execution environments.
var nativeToString = Object.prototype.toString;
function getIsNativeChecker(tag) {
return function (v) { return typeof v === "object" && v && nativeToString.call(v) === tag; };
}
if (typeof Buffer !== "undefined") {
exports.basicTypes.Buffer = new BasicType(function (v) { return Buffer.isBuffer(v); }, "is not a Buffer");
}
var _loop_1 = function (array_1) {
exports.basicTypes[array_1.name] = new BasicType(function (v) { return (v instanceof array_1); }, "is not a " + array_1.name);
};
// Support typed arrays of various flavors
for (var _i = 0, _a = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,
Int32Array, Uint32Array, Float32Array, Float64Array, ArrayBuffer]; _i < _a.length; _i++) {
var array_1 = _a[_i];
_loop_1(array_1);
}

55
node_modules/ts-interface-checker/dist/util.d.ts generated vendored Normal file
View File

@ -0,0 +1,55 @@
/**
* Error thrown by validation. Besides an informative message, it includes the path to the
* property which triggered the failure.
*/
export declare class VError extends Error {
path: string;
constructor(path: string, message: string);
}
/**
* IContext is used during validation to collect error messages. There is a "noop" fast
* implementation that does not pay attention to messages, and a full implementation that does.
*/
export interface IContext {
fail(relPath: string | number | null, message: string | null, score: number): false;
unionResolver(): IUnionResolver;
resolveUnion(ur: IUnionResolver): void;
}
/**
* This helper class is used to collect error messages reported while validating unions.
*/
export interface IUnionResolver {
createContext(): IContext;
}
/**
* IErrorDetail describes errors as returned by the validate() and validateStrict() methods.
*/
export interface IErrorDetail {
path: string;
message: string;
nested?: IErrorDetail[];
}
/**
* Fast implementation of IContext used for first-pass validation. If that fails, we can validate
* using DetailContext to collect error messages. That's faster for the common case when messages
* normally pass validation.
*/
export declare class NoopContext implements IContext, IUnionResolver {
fail(relPath: string | number | null, message: string | null, score: number): false;
unionResolver(): IUnionResolver;
createContext(): IContext;
resolveUnion(ur: IUnionResolver): void;
}
/**
* Complete implementation of IContext that collects meaningfull errors.
*/
export declare class DetailContext implements IContext {
private _propNames;
private _messages;
private _score;
fail(relPath: string | number | null, message: string | null, score: number): false;
unionResolver(): IUnionResolver;
resolveUnion(unionResolver: IUnionResolver): void;
getError(path: string): VError;
getErrorDetail(path: string): IErrorDetail | null;
}

130
node_modules/ts-interface-checker/dist/util.js generated vendored Normal file
View File

@ -0,0 +1,130 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DetailContext = exports.NoopContext = exports.VError = void 0;
/**
* Error thrown by validation. Besides an informative message, it includes the path to the
* property which triggered the failure.
*/
var VError = /** @class */ (function (_super) {
__extends(VError, _super);
function VError(path, message) {
var _this = _super.call(this, message) || this;
_this.path = path;
// See https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work for info about this workaround.
Object.setPrototypeOf(_this, VError.prototype);
return _this;
}
return VError;
}(Error));
exports.VError = VError;
/**
* Fast implementation of IContext used for first-pass validation. If that fails, we can validate
* using DetailContext to collect error messages. That's faster for the common case when messages
* normally pass validation.
*/
var NoopContext = /** @class */ (function () {
function NoopContext() {
}
NoopContext.prototype.fail = function (relPath, message, score) {
return false;
};
NoopContext.prototype.unionResolver = function () { return this; };
NoopContext.prototype.createContext = function () { return this; };
NoopContext.prototype.resolveUnion = function (ur) { };
return NoopContext;
}());
exports.NoopContext = NoopContext;
/**
* Complete implementation of IContext that collects meaningfull errors.
*/
var DetailContext = /** @class */ (function () {
function DetailContext() {
// Stack of property names and associated messages for reporting helpful error messages.
this._propNames = [""];
this._messages = [null];
// Score is used to choose the best union member whose DetailContext to use for reporting.
// Higher score means better match (or rather less severe mismatch).
this._score = 0;
}
DetailContext.prototype.fail = function (relPath, message, score) {
this._propNames.push(relPath);
this._messages.push(message);
this._score += score;
return false;
};
DetailContext.prototype.unionResolver = function () {
return new DetailUnionResolver();
};
DetailContext.prototype.resolveUnion = function (unionResolver) {
var _a, _b;
var u = unionResolver;
var best = null;
for (var _i = 0, _c = u.contexts; _i < _c.length; _i++) {
var ctx = _c[_i];
if (!best || ctx._score >= best._score) {
best = ctx;
}
}
if (best && best._score > 0) {
(_a = this._propNames).push.apply(_a, best._propNames);
(_b = this._messages).push.apply(_b, best._messages);
}
};
DetailContext.prototype.getError = function (path) {
var msgParts = [];
for (var i = this._propNames.length - 1; i >= 0; i--) {
var p = this._propNames[i];
path += (typeof p === "number") ? "[" + p + "]" : (p ? "." + p : "");
var m = this._messages[i];
if (m) {
msgParts.push(path + " " + m);
}
}
return new VError(path, msgParts.join("; "));
};
DetailContext.prototype.getErrorDetail = function (path) {
var details = [];
for (var i = this._propNames.length - 1; i >= 0; i--) {
var p = this._propNames[i];
path += (typeof p === "number") ? "[" + p + "]" : (p ? "." + p : "");
var message = this._messages[i];
if (message) {
details.push({ path: path, message: message });
}
}
var detail = null;
for (var i = details.length - 1; i >= 0; i--) {
if (detail) {
details[i].nested = [detail];
}
detail = details[i];
}
return detail;
};
return DetailContext;
}());
exports.DetailContext = DetailContext;
var DetailUnionResolver = /** @class */ (function () {
function DetailUnionResolver() {
this.contexts = [];
}
DetailUnionResolver.prototype.createContext = function () {
var ctx = new DetailContext();
this.contexts.push(ctx);
return ctx;
};
return DetailUnionResolver;
}());

60
node_modules/ts-interface-checker/package.json generated vendored Normal file
View File

@ -0,0 +1,60 @@
{
"name": "ts-interface-checker",
"version": "0.1.13",
"description": "Runtime library to validate data against TypeScript interfaces",
"main": "dist/index",
"typings": "dist/index",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "tsc && nyc mocha -R list test/",
"bench": "tsc && node test/bench/bench.js",
"preversion": "npm test",
"version": "npm run build"
},
"keywords": [
"typescript",
"ts",
"interface",
"type",
"validate",
"validator",
"check"
],
"files": [
"dist"
],
"author": "Dmitry S, Grist Labs",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/gristlabs/ts-interface-checker"
},
"bugs": {
"url": "https://github.com/gristlabs/ts-interface-checker/issues"
},
"nyc": {
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts"
]
},
"dependencies": {},
"devDependencies": {
"@types/benchmark": "^1.0.31",
"@types/chai": "~4.0.8",
"@types/mocha": "^8.0.1",
"@types/node": "^8.0.57",
"benchmark": "^2.1.4",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
"protobufjs": "^6.8.3",
"source-map-support": "^0.5.0",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
}
}