Skip to content

Commit

Permalink
Merge branch 'feature/api-proxy' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelBinpar committed May 14, 2020
2 parents bbae5ae + 7f48f93 commit fa711f0
Show file tree
Hide file tree
Showing 74 changed files with 2,789 additions and 100 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chokidar from 'chokidar';
import { targetPath, proxyPath } from './settings';
import initWatchers from './utils/initWatchers';
import { ensureDir } from './tools/fs';
import isJest from './tools/isJest';
import { isJest } from './tools/isJest';

/**
* API Watcher process
Expand Down
181 changes: 181 additions & 0 deletions model/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import ts from 'typescript';

/**
* For typescript nodes casting as docs container purposes
*/
export interface JSDocContainer {
/**
* Optional JSDoc array
* @type {ts.JSDoc[]}
* @memberof JSDocContainer
*/
jsDoc?: ts.JSDoc[];
}

/**
* Information regarding the return type of a function extracted using AST
*/
export interface ReturnTypeInfo {
/**
* Return identifier
* @type {string}
* @memberof CompilerFileInfo
*/
identifier: string;
/**
* Return type
* @type {string}
* @memberof CompilerFileInfo
*/
type: string;
/**
* Return type
* @type {string}
* @memberof CompilerFileInfo
*/
typeNode: ts.TypeNode | null;
}

/**
* Model imports information
*/
export interface ModelImport {
/**
* Import clause
*/
clause: ts.ImportClause;
/**
* Path to import from
*/
path: string;
/**
* Related source file
*/
sourceFile?: ts.SourceFile;
}

/**
* Model imports information
*/
export interface GroupedModelImports {
/**
* Default import
*/
def?: string;
/**
* Named imports
*/
named?: string[];
/**
* Path to import from
*/
path: string;
}

/**
* API module info
*/
export interface ModuleInfo {
/**
* Main method node
* @memberof ModuleInfo
*/
mainMethodNode: ts.FunctionDeclaration | ts.ArrowFunction;
/**
* Main method name
* @memberof ModuleInfo
*/
mainMethodName: string;
/**
* Main method parameters nodes
* @type {ts.ParameterDeclaration[]}
* @memberof ModuleInfo
*/
mainMethodParamNodes: ts.ParameterDeclaration[];
/**
* Main method JSDoc node
* @type {JSDocContainer}
* @memberof ModuleInfo
*/
mainMethodDocs: JSDocContainer;
/**
* Main method return type info
* @type {ReturnTypeInfo}
* @memberof ModuleInfo
*/
mainMethodReturnTypeInfo: Required<ReturnTypeInfo>;
/**
* Module model imports
*/
modelImports: ModelImport[];
/**
* Keys based on file path (for proxy API object)
*/
keys: string[];
}

/**
* API Method in Client API structure
*/
export interface ApiMethod {
/**
* Property key
* @type {string}
* @memberof ApiMethod
*/
key: string;
/**
* Method name
* @type {string}
* @memberof ApiMethod
*/
methodName: string;
}

/**
* API Namespace in proxy API structure
*/
export interface ApiNamespace {
/**
* Property key
* @type {string}
* @memberof ApiNamespace
*/
key: string;
/**
* Namespaces for property (object sub-objects)
* @type {ApiNamespace[]}
* @memberof ApiNamespace
*/
namespaces: ApiNamespace[];
/**
* Methods for property (object methods)
* @type {ApiMethod[]}
* @memberof ApiNamespace
*/
methods: ApiMethod[];
}

/**
* API module
*/
export interface APIModule {
/**
* Module default export. Must be a `function` and return a `Promise`. Should contain a method to be called from client
* @memberof APIModule
*/
default: (...args: any[]) => Promise<any>;
/**
* Module dispose method. Optional. Will be called when a module is disposed or updated.
* @memberof APIModule
*/
dispose?: () => Promise<void>;
}

/**
* API levels structure
*/
export interface APIStructure {
[id: string]: APIModule;
}
76 changes: 76 additions & 0 deletions model/sockets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import io from 'socket.io';
import { ParsedUrlQuery } from 'querystring';

/**
* Socket basic call
*/
export interface SocketCall {
/**
* Unique ID for socket transmission
* @memberof SocketCall
*/
id: string;
}

/**
* Socket method call
*/
export interface MethodCall extends SocketCall {
/**
* API Method name corresponding to complete key (like 'users.login')
* @memberof MethodCall
*/
method: string;
/**
* Params for API Method
* @memberof MethodCall
*/
params: any[];
};

/**
* Socket data provider call
*/
export interface DataProviderCall extends SocketCall {
/**
* Page pathname (from Next.js router)
* @memberof DataProviderCall
*/
pathname: string;
/**
* Parsed url query
* @memberof DataProviderCall
*/
query: ParsedUrlQuery;
}

/**
* Socket standard response
*/
export interface SocketMessage {
/**
* Operation was ok (0) or not (1)
* @memberof SocketMessage
*/
o: number;
/**
* Operation error (if any)
* @memberof SocketMessage
*/
e?: string;
/**
* Operation stack (if error)
* @memberof SocketMessage
*/
s?: string;
/**
* Operation return data
* @memberof SocketMessage
*/
d: any;
};

export interface A2RSocket extends io.Socket {
sessionId: string;
};
5 changes: 5 additions & 0 deletions model/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export type OnReady = (
targetPath: string,
) => void | Promise<void>;

/**
* On Validation method
*/
export type OnValidation = (serverPath?: string, targetPath?: string) => Promise<void> | void;

/**
* Watcher options
*/
Expand Down
Loading

0 comments on commit fa711f0

Please sign in to comment.