@smartlyio/oats-runtime 4.0.2 → 4.0.3
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/dist/client.d.ts +43 -0
- package/dist/client.js +131 -0
- package/dist/client.js.map +1 -0
- package/dist/make.d.ts +123 -0
- package/dist/make.js +645 -0
- package/dist/make.js.map +1 -0
- package/dist/reflection-type.d.ts +93 -0
- package/dist/reflection-type.js +198 -0
- package/dist/reflection-type.js.map +1 -0
- package/dist/runtime.d.ts +35 -0
- package/dist/runtime.js +172 -0
- package/dist/runtime.js.map +1 -0
- package/dist/server.d.ts +84 -0
- package/dist/server.js +123 -0
- package/dist/server.js.map +1 -0
- package/dist/union-discriminator.d.ts +26 -0
- package/dist/union-discriminator.js +116 -0
- package/dist/union-discriminator.js.map +1 -0
- package/dist/value-class.d.ts +14 -0
- package/dist/value-class.js +29 -0
- package/dist/value-class.js.map +1 -0
- package/package.json +2 -2
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAoB,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC;AAPD,kDAOC"}
|
package/dist/make.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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 {};
|