From f2f7415040ede134387b3b3afad3a53731348789 Mon Sep 17 00:00:00 2001 From: piyook Date: Thu, 23 May 2024 10:03:29 +0100 Subject: [PATCH] chore(): remove unused files --- .env | 2 +- .vscode/launch.json | 54 +++++++++++++++++++---- templates/handlers/api.custom.template.ts | 46 ------------------- templates/handlers/api.rest.template.ts | 19 -------- templates/models/fake-data-model.ts | 15 ------- templates/models/json-data-model.ts | 12 ----- templates/seeders/fake-data-seeder.ts | 15 ------- templates/seeders/json-data-seeder.ts | 23 ---------- 8 files changed, 46 insertions(+), 140 deletions(-) delete mode 100644 templates/handlers/api.custom.template.ts delete mode 100644 templates/handlers/api.rest.template.ts delete mode 100644 templates/models/fake-data-model.ts delete mode 100644 templates/models/json-data-model.ts delete mode 100644 templates/seeders/fake-data-seeder.ts delete mode 100644 templates/seeders/json-data-seeder.ts diff --git a/.env b/.env index 5681c92..317157d 100644 --- a/.env +++ b/.env @@ -2,5 +2,5 @@ PROJECT_NAME= mock-api-framework SERVER_PORT=8000 USE_API_URL_PREFIX=chatgpt/chat ## MOCK_GPT_MODE can be 'lorem' or 'stored' -MOCK_GPT_MODE=stored +MOCK_GPT_MODE=lorem DEBUG=* \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 2e71105..066a3ee 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,11 +1,47 @@ +// { +// "configurations": [ +// { +// "name": "Docker Node.js Launch", +// "type": "docker", +// "request": "launch", +// "preLaunchTask": "docker-run: debug", +// "platform": "node" +// } +// ] +// } + { - "configurations": [ - { - "name": "Docker Node.js Launch", - "type": "docker", + "version": "0.2.0", + "configurations": [{ + "name": "tsx", + "type": "node", "request": "launch", - "preLaunchTask": "docker-run: debug", - "platform": "node" - } - ] -} + + // Debug current file in VSCode + "program": "${file}", + + /* + Path to tsx binary + Assuming locally installed + */ + "runtimeExecutable": "tsx", + + /* + Open terminal when debugging starts (Optional) + Useful to see console.logs + */ + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + + // Files to exclude from debugger (e.g. call stack) + "skipFiles": [ + // Node.js internal core modules + "/**", + + // Ignore all dependencies (optional) + "${workspaceFolder}/node_modules/**", + ], + }], + "compounds": [] + } + diff --git a/templates/handlers/api.custom.template.ts b/templates/handlers/api.custom.template.ts deleted file mode 100644 index 9f6374c..0000000 --- a/templates/handlers/api.custom.template.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Custom handler with middleware -// Copy and save as api.ts in the api path folder in your project - -import { http, HttpResponse } from 'msw'; -// import { db } from '../src/models/db.js'; -function handler(pathName: string) { - return [ - // Add any http handler here (get, push , delete etc., and middleware as needed) - http.get(`/${pathName}`, ({ request }) => { - // GET action code here - const url = new URL(request.url); - // get url parameters using url.searchParams.get('paramName') - const type = url.searchParams.get('type'); - - // Get data from db using db.[modelName].getAll() - // E.g const cats = db.cat.getAll(); - // E.g return HttpResponse.json(cats); - - // Middleware code here if needed and can return json, text or other responses - return HttpResponse.json({ - response: `this is a GET test response from ${pathName}`, - }); - }), - // Repeat process for POST, PUT and DELETE - http.post(`/${pathName}`, ({ request }) => { - // POST action code here using db.[modelName].create({data}) - return HttpResponse.json({ - response: `this is a POST test response from ${pathName}`, - }); - }), - http.put(`/${pathName}`, ({ request }) => { - // PUT action code here using db.[modelName].update({data}) - return HttpResponse.json({ - response: `this is a PUT test response from ${pathName}`, - }); - }), - http.delete(`/${pathName}`, ({ request }) => { - // DELETE action code here using db.[modelName].delete({data}) - return HttpResponse.json({ - response: `this is a DELETE test response from ${pathName}`, - }); - }), - ]; -} - -export default handler; diff --git a/templates/handlers/api.rest.template.ts b/templates/handlers/api.rest.template.ts deleted file mode 100644 index 2fe6473..0000000 --- a/templates/handlers/api.rest.template.ts +++ /dev/null @@ -1,19 +0,0 @@ -// // Copy and save as api.ts in the api path folder in your project using the correct path to models dir -import { db } from '../../src/models/db.js'; - -// Example of msw data auto REST handler generation -function handler(pathName: string) { - // Need to add a prefix here for automatic REST handler generation to a specific path - const prefix = process.env?.USE_API_URL_PREFIX - ? '/' + process.env.USE_API_URL_PREFIX - : ''; - - // This will generate all REST handlers for the /api/posts path - GET, POST, PUT and DELETE - return [...db.post.toHandlers('rest', prefix)]; -} - -export default handler; - -// To test localhost:9090/api/posts - to see all posts -// to add post send POST request to localhost:8000/api/posts with body {"userId": 101, "title": "new post title", "body": "new post body"} -// to check its been added visit localhost:8000/api/posts/101 diff --git a/templates/models/fake-data-model.ts b/templates/models/fake-data-model.ts deleted file mode 100644 index decda05..0000000 --- a/templates/models/fake-data-model.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { primaryKey } from '@mswjs/data'; - -// Set faker seed to keep same random values each start -faker.seed(); - -export const cat = { - cat: { - // ...with these properties and value getters. - id: primaryKey(() => faker.string.uuid()), - type: () => faker.animal.cat(), - description: () => faker.lorem.lines(5), - price: () => faker.commerce.price({ min: 50, max: 400 }), - }, -}; diff --git a/templates/models/json-data-model.ts b/templates/models/json-data-model.ts deleted file mode 100644 index caaad7c..0000000 --- a/templates/models/json-data-model.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { primaryKey } from '@mswjs/data'; - -// Use primaryKey(Number) to create a unique id for each post passed into the model during creation -// Remember to change the model name from post -export const post = { - post: { - id: primaryKey(Number), - userId: Number, - title: String, - body: String, - }, -}; diff --git a/templates/seeders/fake-data-seeder.ts b/templates/seeders/fake-data-seeder.ts deleted file mode 100644 index 746ff66..0000000 --- a/templates/seeders/fake-data-seeder.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable import/order */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -import { createRequire } from 'node:module'; -import { db } from '../../src/models/db.js'; -// Add own types for new model here - -// Never start at 0 - this will break the primary key -export const catSeeder = () => { - for (let i = 1; i < 100; i++) { - db.cat.create({ - id: i, - }); - } -}; diff --git a/templates/seeders/json-data-seeder.ts b/templates/seeders/json-data-seeder.ts deleted file mode 100644 index 2db9f2c..0000000 --- a/templates/seeders/json-data-seeder.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable import/order */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ - -// Model for using EXISTING data from json file data/data.json as seed data -import { createRequire } from 'node:module'; -import { db } from '../../src/models/db.js'; -import { type Post } from '../../src/types.js'; - -const require = createRequire(import.meta.url); -const postData: Post[] = require('../data/data.json'); - -// With this method we are seeding the database with persisted data from data/data.json rather than using faker data - see json-data-seeder -// Remember to change the model name db.modelName.create({data}) -export const postSeeder = () => { - for (const post of postData) { - db.post.create({ - id: post.id, - userId: post.userId, - title: post.title, - body: post.body, - }); - } -};