api-core
Version:
Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels
93 lines • 3.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiRequest = exports.ApiRequestType = exports.ApiRequestPath = exports.RelatedFieldPathSegment = exports.EntryPathSegment = exports.EdgePathSegment = exports.MethodPathSegment = exports.PathSegment = void 0;
const ApiEdgeQueryContext_1 = require("../edge/ApiEdgeQueryContext");
class PathSegment {
constructor() {
this.inspect = () => {
return '';
};
}
}
exports.PathSegment = PathSegment;
class MethodPathSegment extends PathSegment {
constructor(edge, method) {
super();
this.inspect = () => {
return `call{${this.method.name}}`;
};
this.edge = edge;
this.method = method;
}
}
exports.MethodPathSegment = MethodPathSegment;
class EdgePathSegment extends PathSegment {
constructor(edge, relation) {
super();
this.inspect = () => {
return `[${this.edge.name}]`;
};
this.edge = edge;
this.relation = relation;
}
}
exports.EdgePathSegment = EdgePathSegment;
class EntryPathSegment extends PathSegment {
constructor(edge, id, relation) {
super();
this.inspect = () => {
return `${this.edge.name}(${this.id})`;
};
this.edge = edge;
this.relation = relation;
this.id = id;
}
}
exports.EntryPathSegment = EntryPathSegment;
class RelatedFieldPathSegment extends PathSegment {
constructor(edge, relation) {
super();
this.inspect = () => {
return `${this.edge.name}.${this.relation.name}`;
};
this.edge = edge;
this.relation = relation;
}
}
exports.RelatedFieldPathSegment = RelatedFieldPathSegment;
class ApiRequestPath {
constructor() {
this.segments = [];
this.add = (segment) => {
this.segments.push(segment);
};
this.inspect = () => {
return this.segments.map(segment => segment.inspect()).join(' -> ');
};
}
}
exports.ApiRequestPath = ApiRequestPath;
var ApiRequestType;
(function (ApiRequestType) {
ApiRequestType[ApiRequestType["Create"] = 1] = "Create";
ApiRequestType[ApiRequestType["Read"] = 2] = "Read";
ApiRequestType[ApiRequestType["Update"] = 4] = "Update";
ApiRequestType[ApiRequestType["Patch"] = 8] = "Patch";
ApiRequestType[ApiRequestType["Delete"] = 16] = "Delete";
ApiRequestType[ApiRequestType["Exists"] = 32] = "Exists";
ApiRequestType[ApiRequestType["Any"] = 63] = "Any";
ApiRequestType[ApiRequestType["Change"] = 13] = "Change";
})(ApiRequestType = exports.ApiRequestType || (exports.ApiRequestType = {}));
class ApiRequest {
constructor(api) {
this.body = null;
this.stream = null;
this.metadata = {};
this.api = api;
this.path = new ApiRequestPath();
this.type = ApiRequestType.Read;
this.context = new ApiEdgeQueryContext_1.ApiEdgeQueryContext();
}
}
exports.ApiRequest = ApiRequest;
//# sourceMappingURL=ApiRequest.js.map