WIP: minimal data structure implemented
This commit is contained in:
1 parent
a940243aea
commit
6d63d932e0
9 files changed
+102
-7
No files matched your search
+2
-1
@@ -9,7 +9,8 @@
|
||||
"dev:node": "node --watch-preserve-output --watch-path=./dist dist/app.js",
|
||||
"dev": "pnpm run dev:tsc:silent & pnpm run dev:node",
|
||||
"build": "tsc",
|
||||
"start": "node dist/app.js"
|
||||
"start": "node dist/app.js",
|
||||
"run": "pnpm run build && pnpm run start"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { doSomething } from "./modules/something";
|
||||
import { readJSON } from "./modules/parser/json.parser";
|
||||
|
||||
console.log("TS is working!!!");
|
||||
doSomething();
|
||||
readJSON("./src/modules/parser/fixtures/mock.fixture.json").then(d => console.log(JSON.stringify(d)));
|
||||
@@ -0,0 +1,19 @@
|
||||
export type HTTPHeaders = Record<string, string>;
|
||||
|
||||
export interface RawJuke {
|
||||
path: string;
|
||||
responses: Object[];
|
||||
}
|
||||
|
||||
export interface Juke<T = unknown> {
|
||||
path: string;
|
||||
status: {
|
||||
condition: (body: T, headers: HTTPHeaders) => boolean;
|
||||
response: HTTPMinimalResponse<T>;
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface HTTPMinimalResponse<T> {
|
||||
code: number;
|
||||
body?: T;
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"routes": [
|
||||
{
|
||||
"path": "/test",
|
||||
"responses": [
|
||||
{
|
||||
"code": "401",
|
||||
"when": "body.name !== 'test' || headers['Content-Type'] !== 'application/json'"
|
||||
},
|
||||
{
|
||||
"code": "200",
|
||||
"when": "",
|
||||
"body": {
|
||||
"name": "$request.body.name",
|
||||
"param": "$query.id",
|
||||
"data": [{
|
||||
"title": "$word",
|
||||
"subtitle": "$word",
|
||||
"description": "$text"
|
||||
}],
|
||||
"limitedData": {
|
||||
"$array": {
|
||||
"$array.count": 15,
|
||||
"$array.content": {
|
||||
"title": "$word",
|
||||
"subtitle": "$word",
|
||||
"description": "$text"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pagination": {
|
||||
"page": "$number",
|
||||
"total": "$number"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { RawJuke } from "../core/juker.types";
|
||||
|
||||
export async function readJSON(path: string): Promise<RawJuke[]> {
|
||||
try {
|
||||
const jukes: RawJuke[] = [];
|
||||
const f = await readFile(path);
|
||||
const j = JSON.parse(f.toString());
|
||||
|
||||
if ("routes" in j && Array.isArray(j.routes)) {
|
||||
j.routes.forEach((route: RawJuke) => {
|
||||
if ("path" in route && "responses" in route && Array.isArray(route.responses)) {
|
||||
jukes.push({ path: route.path, responses: route.responses })
|
||||
} else {
|
||||
console.error("[!!] Route entry wrong format");
|
||||
}
|
||||
})
|
||||
} else {
|
||||
throw Error("incorrect format, 'routes' not present at the root of the file.")
|
||||
}
|
||||
|
||||
return jukes;
|
||||
} catch (e) {
|
||||
console.error("[!!] Reading JSON error", e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Juke, RawJuke } from "../core/juker.types";
|
||||
|
||||
export function parseJuke(raw: RawJuke): Juke {
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function doSomething() {
|
||||
console.log("Does something...");
|
||||
}
|
||||
+7
-1
@@ -10,7 +10,13 @@
|
||||
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
Reference in new issue
Block a user