@jsonjoy.com/json-type
Version:
High-performance JSON Pointer implementation
104 lines (103 loc) • 2.59 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 value_1 = require("../../value");
const fnNotImplemented = async () => {
throw new Error('NOT_IMPLEMENTED');
};
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();
this.req = req;
this.res = res;
this.fn = fnNotImplemented;
this.schema = {
...options,
...schema.s.Function(schema.s.any, schema.s.any),
};
}
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;
}
value(data) {
return new value_1.Value(this, data);
}
getSchema() {
return {
...this.schema,
req: this.req.getSchema(),
res: this.res.getSchema(),
};
}
toString(tab = '') {
return super.toString(tab) + toStringTree(tab, this);
}
}
exports.FnType = FnType;
class FnRxType extends AbsType_1.AbsType {
constructor(req, res, options) {
super();
this.req = req;
this.res = res;
this.isStreaming = true;
this.schema = {
...options,
...schema.s.Function$(schema.s.any, schema.s.any),
};
}
request(req) {
this.req = req;
return this;
}
inp(req) {
return this.request(req);
}
response(res) {
this.res = res;
return this;
}
out(res) {
return this.response(res);
}
getSchema() {
return {
...this.schema,
req: this.req.getSchema(),
res: this.res.getSchema(),
};
}
toString(tab = '') {
return super.toString(tab) + toStringTree(tab, this);
}
}
exports.FnRxType = FnRxType;