@smartlyio/oats-runtime 3.5.0 → 4.0.2
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/package.json +11 -11
- package/src/make.ts +6 -6
- package/src/reflection-type.ts +5 -3
- package/src/runtime.ts +2 -0
- package/src/union-discriminator.ts +2 -2
- package/src/value-class.ts +2 -2
- package/dist/client.d.ts +0 -43
- package/dist/client.js +0 -131
- package/dist/client.js.map +0 -1
- package/dist/make.d.ts +0 -123
- package/dist/make.js +0 -645
- package/dist/make.js.map +0 -1
- package/dist/reflection-type.d.ts +0 -92
- package/dist/reflection-type.js +0 -198
- package/dist/reflection-type.js.map +0 -1
- package/dist/runtime.d.ts +0 -35
- package/dist/runtime.js +0 -172
- package/dist/runtime.js.map +0 -1
- package/dist/server.d.ts +0 -84
- package/dist/server.js +0 -123
- package/dist/server.js.map +0 -1
- package/dist/union-discriminator.d.ts +0 -26
- package/dist/union-discriminator.js +0 -116
- package/dist/union-discriminator.js.map +0 -1
- package/dist/value-class.d.ts +0 -14
- package/dist/value-class.js +0 -29
- package/dist/value-class.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartlyio/oats-runtime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Runtime for Oats a Openapi3 based generator for typescript aware servers and clients",
|
|
6
6
|
"private": false,
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"client"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/jest": "27.0.
|
|
39
|
-
"@types/lodash": "4.14.
|
|
40
|
-
"@types/node": "16.11.
|
|
41
|
-
"fast-check": "2.
|
|
42
|
-
"jest": "27.
|
|
38
|
+
"@types/jest": "27.0.3",
|
|
39
|
+
"@types/lodash": "4.14.178",
|
|
40
|
+
"@types/node": "16.11.14",
|
|
41
|
+
"fast-check": "2.20.0",
|
|
42
|
+
"jest": "27.4.5",
|
|
43
43
|
"jsverify": "0.8.4",
|
|
44
|
-
"prettier": "2.
|
|
45
|
-
"ts-jest": "27.
|
|
44
|
+
"prettier": "2.5.1",
|
|
45
|
+
"ts-jest": "27.1.2",
|
|
46
46
|
"ts-node": "10.4.0",
|
|
47
|
-
"tsconfig-paths": "3.
|
|
48
|
-
"typescript": "4.
|
|
47
|
+
"tsconfig-paths": "3.12.0",
|
|
48
|
+
"typescript": "4.5.4"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "140ea78c4bb8bd34c7959941d4f9d771c289c30c"
|
|
51
51
|
}
|
package/src/make.ts
CHANGED
|
@@ -484,7 +484,7 @@ export function makeNullable(maker: any) {
|
|
|
484
484
|
|
|
485
485
|
function isScalar(type: Type): boolean {
|
|
486
486
|
if (type.type === 'named') {
|
|
487
|
-
return isScalar(type.reference.definition);
|
|
487
|
+
return isScalar(type.reference().definition);
|
|
488
488
|
}
|
|
489
489
|
return ['array', 'object', 'union', 'intersection', 'unknown'].indexOf(type.type) < 0;
|
|
490
490
|
}
|
|
@@ -494,7 +494,7 @@ function enumOptions(type: Type): number | null {
|
|
|
494
494
|
return 1;
|
|
495
495
|
}
|
|
496
496
|
if (type.type === 'named') {
|
|
497
|
-
return enumOptions(type.reference.definition);
|
|
497
|
+
return enumOptions(type.reference().definition);
|
|
498
498
|
}
|
|
499
499
|
if (
|
|
500
500
|
type.type === 'string' ||
|
|
@@ -581,7 +581,7 @@ function fromUnionReflection(types: Type[]): Maker<any, any> {
|
|
|
581
581
|
discriminatedMakers.set(key, makeOneOf(...[...untaggedMaker, fromReflection(t)]));
|
|
582
582
|
}
|
|
583
583
|
return (value: any, opts?: MakeOptions) => {
|
|
584
|
-
if (value && typeof value === 'object' && !Array.isArray(value) &&
|
|
584
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && discriminator.key in value) {
|
|
585
585
|
const discriminatedType = discriminatedMakers.get(value[discriminator.key]);
|
|
586
586
|
if (discriminatedType) {
|
|
587
587
|
return discriminatedType(value, opts);
|
|
@@ -622,7 +622,7 @@ export function fromReflection(type: Type): Maker<any, any> {
|
|
|
622
622
|
case 'intersection':
|
|
623
623
|
return makeAllOf(...type.options.map(req => fromReflection(req)));
|
|
624
624
|
case 'named':
|
|
625
|
-
return type.reference.maker;
|
|
625
|
+
return type.reference().maker;
|
|
626
626
|
case 'unknown':
|
|
627
627
|
return makeAny();
|
|
628
628
|
case 'binary':
|
|
@@ -683,7 +683,7 @@ export function extractDiscriminatorKeys(
|
|
|
683
683
|
typeObjectRef: Type
|
|
684
684
|
): string[] {
|
|
685
685
|
const typeObject =
|
|
686
|
-
typeObjectRef.type === 'named' ? typeObjectRef.reference.definition : typeObjectRef;
|
|
686
|
+
typeObjectRef.type === 'named' ? typeObjectRef.reference().definition : typeObjectRef;
|
|
687
687
|
|
|
688
688
|
if (typeObject.type === 'union') {
|
|
689
689
|
const keys = typeObject.options.map(type => extractDiscriminatorKeys(discriminatorField, type));
|
|
@@ -700,7 +700,7 @@ export function extractDiscriminatorKeys(
|
|
|
700
700
|
}
|
|
701
701
|
const fieldSchemaRef = typeObject.properties[discriminatorField].value;
|
|
702
702
|
const fieldSchema =
|
|
703
|
-
fieldSchemaRef.type === 'named' ? fieldSchemaRef.reference.definition : fieldSchemaRef;
|
|
703
|
+
fieldSchemaRef.type === 'named' ? fieldSchemaRef.reference().definition : fieldSchemaRef;
|
|
704
704
|
|
|
705
705
|
if (fieldSchema.type === 'union') {
|
|
706
706
|
return extractDiscriminatorKeys(discriminatorField, fieldSchemaRef);
|
package/src/reflection-type.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type Type =
|
|
|
18
18
|
| ObjectType
|
|
19
19
|
| NamedType;
|
|
20
20
|
|
|
21
|
+
export type NamedTypeDefinitionDeferred<A, Shape = any> = () => NamedTypeDefinition<A, Shape>;
|
|
22
|
+
|
|
21
23
|
export interface NamedTypeDefinition<A, Shape = any> {
|
|
22
24
|
readonly name: string;
|
|
23
25
|
readonly definition: Type;
|
|
@@ -88,7 +90,7 @@ export interface ArrayType {
|
|
|
88
90
|
|
|
89
91
|
export interface NamedType {
|
|
90
92
|
readonly type: 'named';
|
|
91
|
-
readonly reference:
|
|
93
|
+
readonly reference: NamedTypeDefinitionDeferred<unknown>;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export interface PropType {
|
|
@@ -348,8 +350,8 @@ function calculateReachInType(
|
|
|
348
350
|
ambiguousPath: boolean
|
|
349
351
|
) {
|
|
350
352
|
if (type.type === 'named') {
|
|
351
|
-
canReach(reaches, from, type.reference, path);
|
|
352
|
-
calculateReverseReach(processed, reaches, type.reference, to, ambiguousPath);
|
|
353
|
+
canReach(reaches, from, type.reference(), path);
|
|
354
|
+
calculateReverseReach(processed, reaches, type.reference(), to, ambiguousPath);
|
|
353
355
|
} else if (type.type === 'array') {
|
|
354
356
|
calculateReachInType(
|
|
355
357
|
processed,
|
package/src/runtime.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type ShapeOf<A> = A extends Scalar
|
|
|
24
24
|
? unknown
|
|
25
25
|
: A extends Array<infer Item>
|
|
26
26
|
? Array<ShapeOf<Item>>
|
|
27
|
+
: A extends ReadonlyArray<infer Item>
|
|
28
|
+
? ReadonlyArray<ShapeOf<Item>>
|
|
27
29
|
: { [K in keyof A]: ShapeOf<A[K]> };
|
|
28
30
|
|
|
29
31
|
class ShapedClass<Shape> {
|
|
@@ -49,14 +49,14 @@ export function getTags(type: Type): Map<string, unknown[]> {
|
|
|
49
49
|
|
|
50
50
|
function rootType(type: Type): Type {
|
|
51
51
|
if (type.type === 'named') {
|
|
52
|
-
return rootType(type.reference.definition);
|
|
52
|
+
return rootType(type.reference().definition);
|
|
53
53
|
}
|
|
54
54
|
return type;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function typeTag(v: Type): unknown[] {
|
|
58
58
|
if (v.type === 'named') {
|
|
59
|
-
return typeTag(v.reference.definition);
|
|
59
|
+
return typeTag(v.reference().definition);
|
|
60
60
|
}
|
|
61
61
|
if (v.type === 'string' || v.type === 'boolean' || v.type === 'number' || v.type === 'integer') {
|
|
62
62
|
if (v.enum) {
|
package/src/value-class.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NamedTypeDefinitionDeferred } from './reflection-type';
|
|
2
2
|
import { ShapeOf } from './runtime';
|
|
3
3
|
|
|
4
4
|
function asPlainObject(value: any): any {
|
|
@@ -15,7 +15,7 @@ function asPlainObject(value: any): any {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export class ValueClass {
|
|
18
|
-
public static reflection:
|
|
18
|
+
public static reflection: NamedTypeDefinitionDeferred<ValueClass>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
type WritableArray<T> = Array<Writable<T>>;
|
package/dist/client.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as server from './server';
|
|
2
|
-
declare type HasOnlyOptionalTypes<O> = Partial<O> extends O ? true : O extends void ? true : false;
|
|
3
|
-
declare type MakeOptional<O, K extends string> = true extends HasOnlyOptionalTypes<O> ? {
|
|
4
|
-
[P in K]?: O;
|
|
5
|
-
} : {
|
|
6
|
-
[P in K]: O;
|
|
7
|
-
};
|
|
8
|
-
export declare type ClientArg<H extends server.Headers | void, Q extends server.Query | void, B extends server.RequestBody<any> | void> = MakeOptional<H, 'headers'> & MakeOptional<Q, 'query'> & MakeOptional<B, 'body'>;
|
|
9
|
-
export declare type ClientEndpoint<H extends server.Headers | void, Q extends server.Query | void, B extends server.RequestBody<any> | void, R extends server.Response<number, any, any, Record<string, any>>> = object extends ClientArg<H, Q, B> ? (ctx?: ClientArg<H, Q, B>) => Promise<R> : (ctx: ClientArg<H, Q, B>) => Promise<R>;
|
|
10
|
-
declare type PathParam = (param: string | number) => ClientSpec | ClientEndpoint<any, any, any, any>;
|
|
11
|
-
export interface ClientSpec {
|
|
12
|
-
readonly [part: string]: ClientSpec | PathParam | ClientEndpoint<any, any, any, any>;
|
|
13
|
-
}
|
|
14
|
-
export declare type ClientAdapter = server.SafeEndpoint;
|
|
15
|
-
export declare type ClientFactory<Spec> = (adapter: ClientAdapter) => Spec;
|
|
16
|
-
interface RequestBody<T, ContentType> {
|
|
17
|
-
contentType: ContentType;
|
|
18
|
-
value: T;
|
|
19
|
-
}
|
|
20
|
-
export declare function body<T, ContentType extends string>(contentType: ContentType, value: T): RequestBody<T, ContentType>;
|
|
21
|
-
export declare const noContentContentType: "oatsNoContent";
|
|
22
|
-
export declare function noContent(): RequestBody<null, typeof noContentContentType>;
|
|
23
|
-
export declare function json<T>(data: T): RequestBody<T, 'application/json'>;
|
|
24
|
-
export declare function formData<T>(data: T): RequestBody<T, 'multipart/form-data'>;
|
|
25
|
-
export declare function formUrlEncoded<T>(data: T): RequestBody<T, 'application/x-www-form-urlencoded'>;
|
|
26
|
-
export default function literal<T extends string>(literal: T): T;
|
|
27
|
-
export declare function emptyTree<T>(): OpTree<T>;
|
|
28
|
-
export declare function identifier(part: string): string;
|
|
29
|
-
export declare function addPath<T>(opTree: OpTree<T>, path: string, method: server.Methods, value: T): OpTree<T>;
|
|
30
|
-
export interface OpTree<T> {
|
|
31
|
-
methods: {
|
|
32
|
-
[method: string]: T;
|
|
33
|
-
};
|
|
34
|
-
parts: {
|
|
35
|
-
[part: string]: OpTree<T>;
|
|
36
|
-
};
|
|
37
|
-
param?: {
|
|
38
|
-
name: string;
|
|
39
|
-
tree: OpTree<T>;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export declare function createClientFactory<Spec>(handlers: server.Handler[]): ClientFactory<Spec>;
|
|
43
|
-
export {};
|
package/dist/client.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createClientFactory = exports.addPath = exports.identifier = exports.emptyTree = exports.formUrlEncoded = exports.formData = exports.json = exports.noContent = exports.noContentContentType = exports.body = void 0;
|
|
4
|
-
const server = require("./server");
|
|
5
|
-
const assert = require("assert");
|
|
6
|
-
const safe_navigation_1 = require("@smartlyio/safe-navigation");
|
|
7
|
-
function body(contentType, value) {
|
|
8
|
-
return {
|
|
9
|
-
contentType,
|
|
10
|
-
value
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.body = body;
|
|
14
|
-
exports.noContentContentType = 'oatsNoContent';
|
|
15
|
-
function noContent() {
|
|
16
|
-
return body(exports.noContentContentType, null);
|
|
17
|
-
}
|
|
18
|
-
exports.noContent = noContent;
|
|
19
|
-
function json(data) {
|
|
20
|
-
return body('application/json', data);
|
|
21
|
-
}
|
|
22
|
-
exports.json = json;
|
|
23
|
-
function formData(data) {
|
|
24
|
-
return body('multipart/form-data', data);
|
|
25
|
-
}
|
|
26
|
-
exports.formData = formData;
|
|
27
|
-
function formUrlEncoded(data) {
|
|
28
|
-
return body('application/x-www-form-urlencoded', data);
|
|
29
|
-
}
|
|
30
|
-
exports.formUrlEncoded = formUrlEncoded;
|
|
31
|
-
function literal(literal) {
|
|
32
|
-
return literal;
|
|
33
|
-
}
|
|
34
|
-
exports.default = literal;
|
|
35
|
-
function emptyTree() {
|
|
36
|
-
return {
|
|
37
|
-
methods: {},
|
|
38
|
-
parts: {}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
exports.emptyTree = emptyTree;
|
|
42
|
-
function identifier(part) {
|
|
43
|
-
return part;
|
|
44
|
-
}
|
|
45
|
-
exports.identifier = identifier;
|
|
46
|
-
function addPath(opTree, path, method, value) {
|
|
47
|
-
const parts = path.split('/').filter(n => n);
|
|
48
|
-
function addPath_(parts, opTree) {
|
|
49
|
-
opTree = opTree || emptyTree();
|
|
50
|
-
const part = parts[0];
|
|
51
|
-
if (part === undefined) {
|
|
52
|
-
assert((0, safe_navigation_1.default)(opTree).methods[method].$ === undefined, 'duplicate method definition for ' + path);
|
|
53
|
-
return Object.assign(Object.assign({}, opTree), { methods: Object.assign(Object.assign({}, opTree.methods), { [method]: value }) });
|
|
54
|
-
}
|
|
55
|
-
const param = part.match('(.*){([^}]+)}');
|
|
56
|
-
if (param) {
|
|
57
|
-
assert(!/{.*}/.test(param[1]), 'only single path parameter is supported per url segment. Got multiple in ' + path);
|
|
58
|
-
if (param[1] === '') {
|
|
59
|
-
return Object.assign(Object.assign({}, opTree), { param: {
|
|
60
|
-
name: identifier(param[2]),
|
|
61
|
-
tree: addPath_(parts.slice(1), (0, safe_navigation_1.default)(opTree).param.tree.$)
|
|
62
|
-
} });
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const id = identifier(param[1]);
|
|
66
|
-
return Object.assign(Object.assign({}, opTree), { parts: Object.assign(Object.assign({}, opTree.parts), { [id]: addPath_(['{' + param[2] + '}', ...parts.slice(1)], opTree.parts[id]) }) });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const id = identifier(part);
|
|
70
|
-
return Object.assign(Object.assign({}, opTree), { parts: Object.assign(Object.assign({}, opTree.parts), { [id]: addPath_(parts.slice(1), opTree.parts[id]) }) });
|
|
71
|
-
}
|
|
72
|
-
return addPath_(parts, opTree);
|
|
73
|
-
}
|
|
74
|
-
exports.addPath = addPath;
|
|
75
|
-
function makeParam(adapter, param, pathParams) {
|
|
76
|
-
return (value) => fromTree(adapter, param.tree, [...pathParams, value]);
|
|
77
|
-
}
|
|
78
|
-
function paramObject(pathParams, path) {
|
|
79
|
-
const matches = path.match(/{([^}]+)}/g) || [];
|
|
80
|
-
assert(matches.length === pathParams.length, 'mismatch in path param sizes for ' + path);
|
|
81
|
-
if (matches.length === 0) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
const params = {};
|
|
85
|
-
for (let i = 0; i < matches.length; i++) {
|
|
86
|
-
params[matches[i].replace(/{|}/g, '')] = pathParams[i];
|
|
87
|
-
}
|
|
88
|
-
return params;
|
|
89
|
-
}
|
|
90
|
-
function fillInPathParams(params, path) {
|
|
91
|
-
return path.replace(/{([^}]+)}/g, (m, param) => {
|
|
92
|
-
assert(params[param] != null, 'missing path param ' + param);
|
|
93
|
-
return params[param];
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function makeMethod(adapter, handler, pathParams) {
|
|
97
|
-
const params = paramObject(pathParams, handler.path);
|
|
98
|
-
const call = server.safe(handler.headers, handler.params, handler.query, handler.body, handler.response, ctx => adapter(Object.assign(Object.assign({}, ctx), { path: fillInPathParams(params, handler.path), servers: handler.servers })));
|
|
99
|
-
return (ctx) => call({
|
|
100
|
-
path: handler.path,
|
|
101
|
-
servers: handler.servers,
|
|
102
|
-
method: handler.method,
|
|
103
|
-
params,
|
|
104
|
-
headers: (0, safe_navigation_1.default)(ctx).headers.$,
|
|
105
|
-
query: (0, safe_navigation_1.default)(ctx).query.$,
|
|
106
|
-
body: (0, safe_navigation_1.default)(ctx).body.$,
|
|
107
|
-
requestContext: {}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function fromTree(adapter, tree, pathParams) {
|
|
111
|
-
const node = tree.param ? makeParam(adapter, tree.param, pathParams) : {};
|
|
112
|
-
Object.keys(tree.methods).forEach(key => {
|
|
113
|
-
assert(!node[key], 'duplicate path part ' + key);
|
|
114
|
-
node[key] = makeMethod(adapter, tree.methods[key], pathParams);
|
|
115
|
-
});
|
|
116
|
-
Object.keys(tree.parts).forEach(key => {
|
|
117
|
-
assert(!node[key], 'duplicate path part ' + key);
|
|
118
|
-
node[key] = fromTree(adapter, tree.parts[key], pathParams);
|
|
119
|
-
});
|
|
120
|
-
return node;
|
|
121
|
-
}
|
|
122
|
-
function createClientFactory(handlers) {
|
|
123
|
-
return (adapter) => {
|
|
124
|
-
const tree = handlers.reduce((memo, handler) => {
|
|
125
|
-
return addPath(memo, handler.path, handler.method, handler);
|
|
126
|
-
}, emptyTree());
|
|
127
|
-
return fromTree(adapter, tree, []);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
exports.createClientFactory = createClientFactory;
|
|
131
|
-
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,iCAAiC;AACjC,gEAA8C;AAmC9C,SAAgB,IAAI,CAClB,WAAwB,EACxB,KAAQ;IAER,OAAO;QACL,WAAW;QACX,KAAK;KACN,CAAC;AACJ,CAAC;AARD,oBAQC;AAEY,QAAA,oBAAoB,GAAG,eAAwB,CAAC;AAC7D,SAAgB,SAAS;IACvB,OAAO,IAAI,CAAC,4BAAoB,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAFD,8BAEC;AAED,SAAgB,IAAI,CAAI,IAAO;IAC7B,OAAO,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,oBAEC;AAED,SAAgB,QAAQ,CAAI,IAAO;IACjC,OAAO,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAFD,4BAEC;AAED,SAAgB,cAAc,CAAI,IAAO;IACvC,OAAO,IAAI,CAAC,mCAAmC,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC;AAFD,wCAEC;AAED,SAAwB,OAAO,CAAmB,OAAU;IAC1D,OAAO,OAAO,CAAC;AACjB,CAAC;AAFD,0BAEC;AAED,SAAgB,SAAS;IACvB,OAAO;QACL,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC;AALD,8BAKC;AAED,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,gCAEC;AAED,SAAgB,OAAO,CACrB,MAAiB,EACjB,IAAY,EACZ,MAAsB,EACtB,KAAQ;IAER,MAAM,KAAK,GAAa,IAAI,CAAC,KAAK,CAAC,G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AChC,OAAO,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAoB,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC;AAPD,kDAOC"}
|
package/dist/make.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { NamedTypeDefinition, Type } from './reflection-type';
|
|
3
|
-
export declare class MakeError extends Error {
|
|
4
|
-
readonly errors: ValidationError[];
|
|
5
|
-
constructor(errors: ValidationError[]);
|
|
6
|
-
}
|
|
7
|
-
export interface ErrorGroup {
|
|
8
|
-
groupMessage: string;
|
|
9
|
-
errors: ValidationError[];
|
|
10
|
-
}
|
|
11
|
-
export interface ValidationError {
|
|
12
|
-
path: Path;
|
|
13
|
-
error: string | ErrorGroup;
|
|
14
|
-
}
|
|
15
|
-
declare type Path = ReadonlyArray<string>;
|
|
16
|
-
export declare function validationErrorPrinter(error: ValidationError, indentation?: number): string;
|
|
17
|
-
export declare class Make<V> {
|
|
18
|
-
static ok<V>(value: V): Make<V>;
|
|
19
|
-
static error<V>(errors: ValidationError[]): Make<V>;
|
|
20
|
-
readonly errors: ValidationError[];
|
|
21
|
-
private readonly value;
|
|
22
|
-
private constructor();
|
|
23
|
-
isError(): boolean;
|
|
24
|
-
isSuccess(): boolean;
|
|
25
|
-
success(handler?: (e: this) => V): V;
|
|
26
|
-
group(groupMessage: string): Make<null>;
|
|
27
|
-
errorPath(path: string): Make<null>;
|
|
28
|
-
map<R>(fn: (value: V) => R): Make<R>;
|
|
29
|
-
}
|
|
30
|
-
export interface MakeOptions {
|
|
31
|
-
unknownField?: 'drop' | 'fail';
|
|
32
|
-
/**
|
|
33
|
-
* If enabled, "number" ans "integer" schemas will accept strings and try to parse them.
|
|
34
|
-
*/
|
|
35
|
-
parseNumericStrings?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* If enabled, "boolean" schemas will accept strings and try to parse them.
|
|
38
|
-
*/
|
|
39
|
-
parseBooleanStrings?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* If enabled, "array" schema will convert any non-array value to an array with a single element.
|
|
42
|
-
* Useful for supporting arrays in query parameters
|
|
43
|
-
* (if query parameter is not repeated, it will not be an array on server side).
|
|
44
|
-
*/
|
|
45
|
-
allowConvertForArrayType?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export declare type Maker<Shape, V> = (value: Shape, opts?: MakeOptions) => Make<V>;
|
|
48
|
-
export declare function registerFormat(format: string, maker: Maker<any, undefined>): void;
|
|
49
|
-
export declare function makeString(format?: string, pattern?: string, minLength?: number, maxLength?: number): Maker<any, string>;
|
|
50
|
-
export declare function makeNumber(min?: number, max?: number): Maker<unknown, number>;
|
|
51
|
-
export declare function makeInteger(min?: number, max?: number): Maker<unknown, number>;
|
|
52
|
-
declare function checkAny(value: any): Make<any>;
|
|
53
|
-
export declare function makeAny(): typeof checkAny;
|
|
54
|
-
declare function checkVoid(value: any): Make<any>;
|
|
55
|
-
export declare function makeVoid(): typeof checkVoid;
|
|
56
|
-
export declare function makeEnum<T>(...args: T[]): (value: T) => Make<T>;
|
|
57
|
-
export declare function makeOptional(maker: any): {
|
|
58
|
-
optional: any;
|
|
59
|
-
};
|
|
60
|
-
export declare function makeBoolean(): Maker<unknown, boolean>;
|
|
61
|
-
export declare function makeArray(maker: any, minSize?: number, maxSize?: number): Maker<unknown, unknown[]>;
|
|
62
|
-
export declare function makeOneOf(...options: any[]): (value: any, opts?: MakeOptions | undefined) => any;
|
|
63
|
-
export declare function makeAllOf(...all: any[]): (value: any, opts?: MakeOptions | undefined) => Make<any>;
|
|
64
|
-
export declare function makeObject<P extends {
|
|
65
|
-
[key: string]: Maker<any, any> | {
|
|
66
|
-
optional: Maker<any, any>;
|
|
67
|
-
};
|
|
68
|
-
}>(props: P, additionalProp?: any, comparisorOrder?: string[]): (value: any, opts?: MakeOptions | undefined) => Make<any>;
|
|
69
|
-
export declare type Binary = File | Buffer | FormBinary;
|
|
70
|
-
export declare class FormBinary {
|
|
71
|
-
readonly binary: Binary;
|
|
72
|
-
readonly options?: string | {
|
|
73
|
-
[key: string]: string;
|
|
74
|
-
} | undefined;
|
|
75
|
-
constructor(binary: Binary, options?: string | {
|
|
76
|
-
[key: string]: string;
|
|
77
|
-
} | undefined);
|
|
78
|
-
}
|
|
79
|
-
export declare class File {
|
|
80
|
-
readonly path: string;
|
|
81
|
-
readonly size: number;
|
|
82
|
-
readonly name?: string | undefined;
|
|
83
|
-
private brand;
|
|
84
|
-
constructor(path: string, size: number, name?: string | undefined);
|
|
85
|
-
}
|
|
86
|
-
declare function checkBinary(value: any): Make<any>;
|
|
87
|
-
export declare function makeBinary(): typeof checkBinary;
|
|
88
|
-
export declare function makeNullable(maker: any): (value: any, opts?: MakeOptions | undefined) => any;
|
|
89
|
-
export declare function fromReflection(type: Type): Maker<any, any>;
|
|
90
|
-
export declare function createMaker<Shape, Type>(fun: () => any): (value: Shape, opts?: MakeOptions | undefined) => Make<Type>;
|
|
91
|
-
export declare function createMakerWith<Shape, Type>(constructor: new (v: Shape, opts?: MakeOptions) => Type): Maker<Shape, Type>;
|
|
92
|
-
/**
|
|
93
|
-
* Merge multiple mappings into one set of mappings
|
|
94
|
-
*
|
|
95
|
-
* Throw error if there are duplicate koys
|
|
96
|
-
* @deprecated
|
|
97
|
-
*/
|
|
98
|
-
export declare function mergeMappings(...mappings: readonly {
|
|
99
|
-
[key: string]: Maker<any, any>;
|
|
100
|
-
}[]): {
|
|
101
|
-
[key: string]: Maker<any, any>;
|
|
102
|
-
};
|
|
103
|
-
export declare function extractDiscriminatorKeys(discriminatorField: string, typeObjectRef: Type): string[];
|
|
104
|
-
/** @deprecated */
|
|
105
|
-
export declare function extractDiscriminatorValueMap(discriminatorField: string, typeObject: NamedTypeDefinition<any>): {
|
|
106
|
-
[key: string]: Maker<any, any>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Make oneOf with the discriminator support
|
|
110
|
-
*
|
|
111
|
-
* Will use given mapping to find correct maker. If optional importedTypes are provided, will extract
|
|
112
|
-
* extra mapping keys from them.
|
|
113
|
-
*
|
|
114
|
-
* @deprecated
|
|
115
|
-
*
|
|
116
|
-
* @param discriminatorField Field to use as discriminator
|
|
117
|
-
* @param mapping Mappings that we should use to determine target makers
|
|
118
|
-
* @param importedTypes Optional types where we should extract enum values for makers
|
|
119
|
-
*/
|
|
120
|
-
export declare function makeOneOfWithDiscriminator(discriminatorField: string, mapping: {
|
|
121
|
-
[key: string]: Maker<any, any>;
|
|
122
|
-
}, importedTypes?: readonly any[]): (value: any, opts?: MakeOptions | undefined) => Make<any>;
|
|
123
|
-
export {};
|