-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change how the data is sent from the CLI to the console
- Loading branch information
Showing
9 changed files
with
144 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { putCliData } from "../../db"; | ||
|
||
export async function POST(request: Request) { | ||
const json = await request.json(); | ||
await putCliData(json); | ||
return new Response("OK"); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { JSONFilePreset } from "lowdb/node"; | ||
|
||
// We added a DB here because we don't know how next will handle | ||
// the request. We have found a hack where we could use modules to | ||
// have a singleton and handle shared state but we are not guaranteed | ||
// that it would work: https://stackoverflow.com/questions/13179109/singleton-pattern-in-nodejs-is-it-needed | ||
// In terms of Local db implementation, we looked at: Level, PouchDB, sqlite3, lowdb | ||
|
||
const DB_FILE = "./console.db"; | ||
const CLI_DATA_ID = "cliData"; | ||
|
||
const defaultData: { | ||
[CLI_DATA_ID]: CliData; | ||
} = { | ||
[CLI_DATA_ID]: { | ||
routes: [], | ||
tables: [], | ||
topics: [], | ||
}, | ||
}; | ||
|
||
const dbPromise = JSONFilePreset(DB_FILE, defaultData); | ||
|
||
export interface Route { | ||
file_path: string; | ||
route_path: string; | ||
table_name: string; | ||
view_name: string; | ||
} | ||
|
||
export interface Table { | ||
database: string; | ||
dependencies_table: string[]; | ||
engine: string; | ||
name: string; | ||
uuid: string; | ||
} | ||
|
||
export interface CliData { | ||
routes: Route[]; | ||
tables: Table[]; | ||
topics: string[]; | ||
} | ||
|
||
export async function putCliData(data: CliData): Promise<void> { | ||
const db = await dbPromise; | ||
return await db.update((dbData) => { | ||
dbData[CLI_DATA_ID] = data; | ||
}); | ||
} | ||
|
||
export async function getCliData(): Promise<CliData> { | ||
const db = await dbPromise; | ||
await db.read(); | ||
return db.data[CLI_DATA_ID]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.