@jsonjoy.com/json-type
Version:
High-performance JSON Pointer implementation
115 lines • 2.81 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FnRxType = exports.FnType = void 0;
const tslib_1 = require("tslib");
const printTree_1 = require("tree-dump/lib/printTree");
const schema = tslib_1.__importStar(require("../../schema"));
const AbsType_1 = require("./AbsType");
const toStringTree = (tab = '', type) => {
return (0, printTree_1.printTree)(tab, [
(tab) => 'req: ' + type.req.toString(tab + ' '),
(tab) => 'res: ' + type.res.toString(tab + ' '),
]);
};
class FnType extends AbsType_1.AbsType {
constructor(req, res, options) {
super({
...options,
...schema.s.Function(schema.s.any, schema.s.any),
});
this.req = req;
this.res = res;
}
input(req) {
return this.inp(req);
}
inp(req) {
this.req = req;
return this;
}
output(res) {
return this.out(res);
}
out(res) {
this.res = res;
return this;
}
io(request, response) {
return this.inp(request).out(response);
}
signature(request, response) {
return this.io(request, response);
}
ctx() {
return this;
}
getSchema() {
return {
...this.schema,
req: this.req.getSchema(),
res: this.res.getSchema(),
};
}
default(value) {
this.schema.default = value;
return this;
}
exec(input) {
const func = this.schema.default;
return func(input);
}
toString(tab = '') {
return super.toString(tab) + toStringTree(tab, this);
}
}
exports.FnType = FnType;
class FnRxType extends AbsType_1.AbsType {
constructor(req, res, options) {
super({
...options,
...schema.s.Function$(schema.s.any, schema.s.any),
});
this.req = req;
this.res = res;
this.isStreaming = true;
}
input(req) {
return this.inp(req);
}
inp(req) {
this.req = req;
return this;
}
output(res) {
return this.out(res);
}
out(res) {
this.res = res;
return this;
}
io(request, response) {
return this.inp(request).out(response);
}
signature(request, response) {
return this.io(request, response);
}
ctx() {
return this;
}
getSchema() {
return {
...this.schema,
req: this.req.getSchema(),
res: this.res.getSchema(),
};
}
default(value) {
this.schema.default = value;
return this;
}
toString(tab = '') {
return super.toString(tab) + toStringTree(tab, this);
}
}
exports.FnRxType = FnRxType;
//# sourceMappingURL=FnType.js.map