summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2019-01-20 20:15:10 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2019-01-20 20:15:10 -0800
commitf025520818b73f39b06c30838f29437b44963114 (patch)
treef6d57a385ed03796632eae1a6f200540bcf7e963
parentfc6b43224fe49be0cbb64785cd7e38d0f1a86eb5 (diff)
(WIP) Implement naive-client
-rw-r--r--client/src/config.model.ts5
-rw-r--r--client/src/database-connection.model.ts7
-rw-r--r--client/src/database-connection.ts31
-rw-r--r--client/src/index.ts3
-rw-r--r--client/tsconfig.json5
5 files changed, 49 insertions, 2 deletions
diff --git a/client/src/config.model.ts b/client/src/config.model.ts
new file mode 100644
index 0000000..9c3b70a
--- /dev/null
+++ b/client/src/config.model.ts
@@ -0,0 +1,5 @@
+export interface Config {
+ wsPort: number;
+ httpPort: number;
+ url: string;
+}
diff --git a/client/src/database-connection.model.ts b/client/src/database-connection.model.ts
new file mode 100644
index 0000000..b89014b
--- /dev/null
+++ b/client/src/database-connection.model.ts
@@ -0,0 +1,7 @@
+export interface DatabaseConnection {
+ init(): Promise<any>;
+ close(): Promise<any>;
+ subscribe(path: string, callback: (e: any) => any): Promise<() => any>;
+ write(path: string, toWrite: Object): Promise<any>;
+ remove(path: string): Promise<any>;
+}
diff --git a/client/src/database-connection.ts b/client/src/database-connection.ts
new file mode 100644
index 0000000..d870f71
--- /dev/null
+++ b/client/src/database-connection.ts
@@ -0,0 +1,31 @@
+import { Config } from "./config.model";
+import { DatabaseConnection } from "./database-connection.model";
+
+/**
+ * Client side implementation is implemented using
+ * a function/factory instead of a class to reduce bundle
+ * size
+ */
+export const dbFactory = (config: Config): DatabaseConnection => {
+ const write = (path: string, toWrite: Object | null) => {
+ const { url, httpPort } = config;
+ return fetch(`${url}:${httpPort}/write`, {
+ method: "POST",
+ body: JSON.stringify({
+ path,
+ toWrite
+ })
+ });
+ };
+ return {
+ async init() {},
+ async close() {},
+ async subscribe(path: string, callback: (e: any) => Promise<any>) {
+ return () => {};
+ },
+ write,
+ async remove(path: string) {
+ write(path, null);
+ }
+ };
+};
diff --git a/client/src/index.ts b/client/src/index.ts
new file mode 100644
index 0000000..c16688d
--- /dev/null
+++ b/client/src/index.ts
@@ -0,0 +1,3 @@
+export { dbFactory } from "./database-connection";
+export { DatabaseConnection } from "./database-connection.model";
+export { Config } from "./config.model";
diff --git a/client/tsconfig.json b/client/tsconfig.json
index 9e35360..1b31a6d 100644
--- a/client/tsconfig.json
+++ b/client/tsconfig.json
@@ -4,7 +4,8 @@
"target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
- "es2017"
+ "es2017",
+ "dom"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
@@ -14,7 +15,7 @@
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
+ "rootDir": "../" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */