@deepkit/api-console-gui
Version:
API Console GUI
359 lines • 18 kB
JavaScript
import { __decorate } from "tslib";
/*@ts-ignore*/
import { __ΩTypeParameter } from '@deepkit/type';
/*@ts-ignore*/
import { __ΩExcluded } from '@deepkit/type';
/*@ts-ignore*/
import { __ΩRemoteController } from '@deepkit/rpc';
/*@ts-ignore*/
import { __ΩRpcClientEventIncomingMessage } from '@deepkit/rpc';
/*@ts-ignore*/
import { __ΩRpcClientEventOutgoingMessage } from '@deepkit/rpc';
function __assignType(fn, args) {
fn.__type = args;
return fn;
}
import { ApiAction, ApiRoute } from '@deepkit/api-console-api';
import { RpcClient } from '@deepkit/rpc';
import { Observable, Subject, Subscription } from 'rxjs';
import { deserialize, isBackReferenceType, isMapType, isOptional, isReferenceType, isSetType, ReflectionClass, ReflectionKind, serialize } from '@deepkit/type';
import { Injectable, signal } from '@angular/core';
export class DataStructure {
constructor(value) {
this.active = signal(false);
this.asReference = signal(false);
this.typeIndex = -1; //for unions
this.children = (signal.Ω = [[() => DataStructure, 'P7!F']], signal([]));
this.properties = (signal.Ω = [[() => DataStructure, 'P&P7!LM']], signal({}));
this.value = signal(value);
}
getProperty(name) {
if (!this.properties()[name]) {
const ds = new DataStructure(undefined);
this.properties()[name] = ds;
queueMicrotask(() => {
this.properties.update(__assignType(v => ({ ...v, [name]: ds }), ['v', '', 'P"2!"/"']));
});
return ds;
}
return this.properties()[name];
}
}
DataStructure.__type = ['active', function () { return signal(false); }, 'asReference', function () { return signal(false); }, 'typeIndex', function () { return -1; }, 'WritableSignal', 'value', 'constructor', 'children', function () { return (signal.Ω = [[() => DataStructure, 'P7!F']], signal([])); }, 'properties', function () { return (signal.Ω = [[() => DataStructure, 'P&P7!LM']], signal({})); }, 'name', () => DataStructure, 'getProperty', 'DataStructure', '!3!>"!3#>$\'3%>&"w\'3(P"2("0)!3*>+!3,>-PP&\'J2.P7/005w1'];
export function extractDataStructure(ds, type) {
if (type.kind === ReflectionKind.class && type.classType === Date) {
return ds.value();
}
else if (isMapType(type)) {
const v = {};
if (!type.typeArguments)
return;
const keyProperty = type.typeArguments[0];
const valueProperty = type.typeArguments[1];
for (const childDs of ds.children()) {
const key = childDs.properties()['key'];
const value = childDs.properties()['value'];
if (!key || !value)
continue;
v[extractDataStructure(key, keyProperty)] = extractDataStructure(childDs.properties()['key'], valueProperty);
}
return v;
}
else if (type.kind === ReflectionKind.union) {
if (ds.typeIndex >= 0) {
if (!ds.properties()[ds.typeIndex])
return undefined;
if (!type.types[ds.typeIndex])
return undefined;
return extractDataStructure(ds.properties()[ds.typeIndex], type.types[ds.typeIndex]);
}
return ds.value();
}
else if (type.kind === ReflectionKind.array || isSetType(type)) {
const list = [];
const valueProperty = isSetType(type) ? type.typeArguments[0] : type.kind === ReflectionKind.array ? type.type : undefined;
if (!valueProperty)
return list;
for (const childDs of ds.children()) {
if (!childDs.properties()['value'])
continue;
const v = extractDataStructure(childDs.properties()['value'], valueProperty);
if (v === undefined && !isOptional(valueProperty))
continue;
list.push(v);
}
return list;
}
else if (type.kind === ReflectionKind.class || type.kind === ReflectionKind.objectLiteral) {
if ((isReferenceType(type) || isBackReferenceType(type)) && ds.asReference()) {
const primary = ReflectionClass.from(type).getPrimary();
return extractDataStructure(ds.properties()[primary.name], primary.type);
}
return extractDataStructureFromSchema(ds, ReflectionClass.from(type));
}
else {
return ds.value();
}
}
extractDataStructure.__type = [() => DataStructure, 'ds', 'Type', 'type', 'extractDataStructure', 'PP7!2""w#2$"/%'];
export function extractDataStructureFromSchema(ds, schema) {
const data = {};
for (const property of schema.getProperties()) {
const pds = ds.properties()[property.name];
if (!pds)
continue;
if (!property.isValueRequired() && !pds.active)
continue;
const v = extractDataStructure(pds, property.type);
if (v === undefined && property.isValueRequired())
continue;
data[property.name] = v;
}
return data;
}
extractDataStructureFromSchema.__type = [() => DataStructure, 'ds', () => ReflectionClass, 'schema', 'extractDataStructureFromSchema', 'PP7!2"P"7#2$"/%'];
export function extractDataStructureFromParameters(ds, parameters) {
const data = {};
for (const property of parameters) {
const pds = ds.properties()[property.name];
if (!pds)
continue;
if (property.optional && !pds.active)
continue;
const v = extractDataStructure(pds, property.type);
if (v === undefined && !property.optional)
continue;
data[property.name] = v;
}
return data;
}
extractDataStructureFromParameters.__type = [() => DataStructure, 'ds', () => __ΩTypeParameter, 'parameters', 'extractDataStructureFromParameters', 'PP7!2"n#F2$"/%'];
export class RouteState {
constructor(id, fullUrl, method = 'GET') {
this.id = id;
this.fullUrl = fullUrl;
this.method = method;
this.headers = [];
this.fullHeaders = [];
this.urls = new DataStructure(undefined);
this.params = new DataStructure(undefined);
this.body = new DataStructure(undefined);
}
}
RouteState.__type = ['id', 'fullUrl', 'method', () => "GET", 'constructor', 'name', 'value', 'headers', function () { return []; }, 'fullHeaders', function () { return []; }, () => DataStructure, 'urls', function () { return new DataStructure(undefined); }, () => DataStructure, 'params', function () { return new DataStructure(undefined); }, () => DataStructure, 'body', function () { return new DataStructure(undefined); }, () => __ΩExcluded, 'resolvedBody', 'RouteState', 'P&2!:&2":&2#:>$"0%P&4&&4\'MF3(>)P&4&&4\'MF3*>+P7,3->.P7/30>1P7233>4P"n5K3685w7'];
export class Request {
get result() {
if (this.loadedResult === undefined) {
this.loadedResult = localStorage.getItem('@deepkit/api-console/request/result/' + this.bodyStoreId) || undefined;
}
return this.loadedResult || undefined;
}
set result(v) {
this.loadedResult = v;
if (v)
localStorage.setItem('@deepkit/api-console/request/result/' + this.bodyStoreId, v);
}
get json() {
if (this.loadedJson === undefined) {
this.loadedJson = localStorage.getItem('@deepkit/api-console/request/json/' + this.bodyStoreId) || undefined;
}
return this.loadedJson || undefined;
}
set json(v) {
this.loadedJson = v;
if (v)
localStorage.setItem('@deepkit/api-console/request/json/' + this.bodyStoreId, v);
}
getHeader(name) {
for (const h of this.headers)
if (h.name === name)
return h.value;
return '';
}
get bodyStoreId() {
return this.id + '_' + this.created.getTime();
}
constructor(id, method, url) {
this.id = id;
this.method = method;
this.url = url;
this.headers = [];
this.took = 0;
this.error = '';
this.status = 0;
this.statusText = '';
this.tab = 'body';
this.created = new Date();
}
}
Request.__type = [() => __ΩExcluded, 'loadedJson', () => __ΩExcluded, 'loadedResult', 'name', 'value', 'headers', function () { return []; }, 'took', function () { return 0; }, 'error', function () { return ''; }, 'status', function () { return 0; }, 'statusText', function () { return ''; }, 'tab', function () { return 'body'; }, 'open', 'created', function () { return new Date(); }, 'getHeader', 'id', 'method', 'url', 'constructor', 'Request', 'P&n!K3"8;P&n#K3$8;!!P&4%&4&MF3\'>(\'3)>*&3+>,\'3->.&3/>0&31>2)338T34>5P&2%&06!P&27:&28:&29:"0:5w;'];
export class ViewHttp {
constructor() {
this.showDescription = false;
this.filterCategory = '';
this.filterGroup = '';
this.filterMethod = '';
this.filterPath = '';
this.codeGenerationType = 'curl';
this.codeGenerationVisible = true;
this.serverStatsVisible = false;
this.viewRequests = 'selected';
this.groupBy = 'controller';
this.closed = {};
}
}
ViewHttp.__type = ['showDescription', function () { return false; }, 'filterCategory', function () { return ''; }, 'filterGroup', function () { return ''; }, 'filterMethod', function () { return ''; }, 'filterPath', function () { return ''; }, 'codeGenerationType', function () { return 'curl'; }, 'codeGenerationVisible', function () { return true; }, 'serverStatsVisible', function () { return false; }, "all", "selected", 'viewRequests', function () { return 'selected'; }, "none", "controller", "method", 'groupBy', function () { return 'controller'; }, 'closed', function () { return {}; }, 'ViewHttp', ')3!>"&3#>$&3%>&&3\'>(&3)>*&3+>,)3->.)3/>0P.1.2J33>4P.5.6.7J38>9P&)LM3:>;5w<'];
export class ViewRpc {
constructor() {
this.showDescription = false;
this.filterCategory = '';
this.filterGroup = '';
this.filterPath = '';
this.viewRequests = 'selected';
this.displayClients = false;
this.displayClientsHeight = 170;
this.groupBy = 'controller';
this.closed = {};
}
}
ViewRpc.__type = ['showDescription', function () { return false; }, 'filterCategory', function () { return ''; }, 'filterGroup', function () { return ''; }, 'filterPath', function () { return ''; }, "all", "selected", 'viewRequests', function () { return 'selected'; }, 'displayClients', function () { return false; }, 'displayClientsHeight', function () { return 170; }, "none", "controller", 'groupBy', function () { return 'controller'; }, 'closed', function () { return {}; }, 'ViewRpc', ')3!>"&3#>$&3%>&&3\'>(P.).*J3+>,)3->.\'3/>0P.1.2J33>4P&)LM35>65w7'];
export class Environment {
constructor(name) {
this.name = name;
this.headers = [];
}
}
Environment.__type = ['name', 'value', 'headers', function () { return []; }, 'constructor', 'Environment', 'P&4!&4"MF3#>$P&2!:"0%5w&'];
const __ΩRpcExecutionSubscription = ['id', 'emitted', 'unsubscribed', '', 'unsubscribe', 'completed', 'error', () => Subscription, 'sub', 'RpcExecutionSubscription', 'P\'4!"F4")4#P$/$4%)4&"4\'8P7(4)Mw*y'];
export { __ΩRpcExecutionSubscription as __ΩRpcExecutionSubscription };
export class RpcExecution {
isObservable() {
return this.type === 'subject' || this.type === 'observable';
}
get result() {
if (this._result === undefined) {
const json = localStorage.getItem('@deepkit/api-console/rpcExecution/result/' + this.bodyStoreId);
if (json) {
this._result = JSON.parse(json);
}
}
return this._result || undefined;
}
set result(v) {
this._result = v;
if (v)
localStorage.setItem('@deepkit/api-console/rpcExecution/result/' + this.bodyStoreId, JSON.stringify(v));
}
get bodyStoreId() {
return this.controllerPath + '-' + this.method + '_' + this.created.getTime();
}
constructor(controllerClassName, controllerPath, method, args) {
this.controllerClassName = controllerClassName;
this.controllerPath = controllerPath;
this.method = method;
this.args = args;
this.created = new Date();
//we don't store a reference because the client could be deleted anytime.
this.clientName = '';
this.took = -1;
this.type = 'static';
this.subscriptionsId = 0;
this.subscriptions = [];
}
actionId() {
return this.controllerPath + '.' + this.method;
}
}
RpcExecution.__type = ['created', function () { return new Date(); }, 'clientName', function () { return ''; }, 'open', 'address', 'took', function () { return -1; }, 'error', () => __ΩExcluded, '_result', "subject", "observable", "static", 'type', function () { return 'static'; }, 'isObservable', () => Subject, () => __ΩExcluded, 'subject', () => Observable, 'observable', () => __ΩExcluded, 'subscriptionsId', function () { return 0; }, () => __ΩRpcExecutionSubscription, () => __ΩExcluded, 'subscriptions', function () { return []; }, 'controllerClassName', 'controllerPath', 'method', 'args', 'constructor', 'actionId', 'RpcExecution', 'T3!>"&3#>$)3%8&3&8\'3\'>("3)8P"n*K3+8<P.,.-..J3/>0P)01PP"72n3K348P#75368P\'n7K38>9Pn:Fn;K3<>=!!P&2>:&2?:&2@:"F2A:"0BP"0C5wD'];
export class RpcActionState {
constructor(id) {
this.id = id;
this.params = new DataStructure(undefined);
}
}
RpcActionState.__type = ['id', 'constructor', () => DataStructure, 'params', function () { return new DataStructure(undefined); }, 'RpcActionState', 'P&2!:"0"P7#3$>%5w&'];
export class RpcClientConfiguration {
constructor(name) {
this.name = name;
this.controller = {};
this.incomingMessages = [];
this.outgoingMessages = [];
}
}
RpcClientConfiguration.__type = [() => RpcClient, () => __ΩExcluded, 'client', () => __ΩRemoteController, () => __ΩExcluded, 'controller', function () { return {}; }, () => __ΩRpcClientEventIncomingMessage, () => __ΩExcluded, 'incomingMessages', function () { return []; }, () => __ΩRpcClientEventOutgoingMessage, () => __ΩExcluded, 'outgoingMessages', function () { return []; }, 'name', 'constructor', 'RpcClientConfiguration', 'PP7!n"K3#8PP&"o$"LMn%K3&>\'Pn(Fn)K3*>+Pn,Fn-K3.>/P&20:"015w2'];
export class StoreValue {
constructor() {
this.routeStates = {};
this.rpcActionStates = {};
this.requests = [];
this.rpcExecutions = [];
this.viewRpc = new ViewRpc;
this.viewHttp = new ViewHttp;
this.environments = [new Environment('default')];
this.activeEnvironmentIndex = 0;
this.rpcClients = [new RpcClientConfiguration('Client 1')];
this.activeRpcClientIndex = 0;
this.activeDebugRpcClientIndex = 0;
}
get rpcClient() {
return this.rpcClients[this.activeRpcClientIndex];
}
set rpcClient(v) {
console.log('rpcClient', v);
this.activeRpcClientIndex = v ? this.rpcClients.indexOf(v) : -1;
this.onChange();
}
get activeEnvironment() {
return this.environments[this.activeEnvironmentIndex];
}
set activeEnvironment(e) {
this.activeEnvironmentIndex = e ? this.environments.indexOf(e) : -1;
this.onChange();
}
getRpcActionState(action) {
let rpcState = this.rpcActionStates[action.id];
if (!rpcState) {
rpcState = new RpcActionState(action.id);
this.rpcActionStates[action.id] = rpcState;
this.onChange();
}
return rpcState;
}
onChange() {
}
}
StoreValue.__type = [() => RouteState, 'routeStates', function () { return {}; }, () => RpcActionState, 'rpcActionStates', function () { return {}; }, () => Request, 'requests', function () { return []; }, () => RpcExecution, 'rpcExecutions', function () { return []; }, () => ViewRpc, 'viewRpc', function () { return new ViewRpc; }, () => ViewHttp, 'viewHttp', function () { return new ViewHttp; }, () => Environment, 'environments', function () { return [new Environment('default')]; }, 'activeEnvironmentIndex', function () { return 0; }, () => RpcClientConfiguration, 'rpcClients', function () { return [new RpcClientConfiguration('Client 1')]; }, 'activeRpcClientIndex', function () { return 0; }, 'activeDebugRpcClientIndex', function () { return 0; }, () => ApiAction, 'action', () => RpcActionState, 'getRpcActionState', () => ApiRoute, () => __ΩExcluded, 'route', () => ApiAction, () => __ΩExcluded, 'onChange', 'StoreValue', 'P&P7!LM3">#P&P7$LM3%>&P7\'F3(>)P7*F3+>,P7-3.>/P7031>2P73F34>5\'36>7P78F39>:\'3;><\'3=>>!!PP7?2@P7A0BPP7CnDK3E8PP7FnGK3@8P"0H5wI'];
let Store = class Store {
constructor() {
this.state = new StoreValue;
this.restore();
this.state.onChange = () => this.store();
}
restore() {
const t = localStorage.getItem('@deepkit/api-console');
if (!t)
return;
try {
this.state = (deserialize.Ω = [[() => StoreValue, 'P7!']], deserialize(JSON.parse(t)));
console.log('this.state', this.state);
}
catch {
}
if (this.state.activeRpcClientIndex === -1 && this.state.rpcClients.length > 0) {
this.state.activeRpcClientIndex = 0;
}
}
store() {
localStorage.setItem('@deepkit/api-console', JSON.stringify((serialize.Ω = [[() => StoreValue, 'P7!']], serialize(this.state))));
}
set(cb) {
cb(this.state);
this.store();
}
};
Store.__type = ['state', function () { return new StoreValue; }, 'constructor', 'restore', 'store', () => StoreValue, '', 'cb', 'set', 'Store', '!3!>"P"0#P"0$P"0%PPP7&2%$/\'2("0)5w*'];
Store = __decorate([
Injectable({ providedIn: 'root' })
], Store);
export { Store };
//# sourceMappingURL=store.js.map