Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelBinpar committed May 14, 2020
2 parents b0ac341 + 00271b6 commit 789953e
Show file tree
Hide file tree
Showing 93 changed files with 3,378 additions and 1,019 deletions.
2 changes: 2 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ patch:
SNYK-JS-LODASH-567746:
- winston > async > lodash:
patched: '2020-04-30T17:10:55.970Z'
- '@a2r/telemetry > winston > async > lodash':
patched: '2020-05-04T17:21:45.941Z'
8 changes: 4 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';
import chokidar from 'chokidar';

import { targetPath, runtimePath } from './settings';
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 All @@ -16,7 +16,7 @@ interface Process {

const pendingProcesses: Process[] = [];
const serverPath = path.resolve(__dirname, targetPath);
const runtimeDestPath = path.resolve(__dirname, runtimePath);
const proxyDestPath = path.resolve(__dirname, proxyPath);

let runningProcess: 'start' | 'stop' = null;

Expand Down Expand Up @@ -93,7 +93,7 @@ export const restart = start;
* Inits API Watcher by ensuring destination path and running start process
*/
const init = async (): Promise<void> => {
await ensureDir(runtimeDestPath);
await ensureDir(proxyDestPath);
await start();
};

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 789953e

Please sign in to comment.