From aad0f7e8b0f0112521c40418bacacafecacea07c Mon Sep 17 00:00:00 2001 From: vipul-sourcrefuse Date: Thu, 23 Jan 2025 17:11:55 +0530 Subject: [PATCH 1/3] refactor(core): change to run the cache-example change to run the cache-example 0 change to run the cache-example --- sandbox/cache-example/package.json | 6 +- sandbox/cache-example/src/application.ts | 10 ++- .../cache-example/src/repositories/README.md | 87 ++++++++++++++++++- 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/sandbox/cache-example/package.json b/sandbox/cache-example/package.json index 5aed7361df..7012a18ba0 100644 --- a/sandbox/cache-example/package.json +++ b/sandbox/cache-example/package.json @@ -34,9 +34,9 @@ "start": "node -r source-map-support/register .", "clean": "lb-clean dist *.tsbuildinfo .eslintcache", "rebuild": "npm run clean && npm run build", - "db:migrate": "./node_modules/db-migrate/bin/db-migrate up --config './migrations/database.json'", - "db:migrate:down": "./node_modules/db-migrate/bin/db-migrate down --config './migrations/database.json'", - "db:migrate:reset": "./node_modules/db-migrate/bin/db-migrate reset --config './migrations/database.json'" + "db:migrate": "../../node_modules/db-migrate/bin/db-migrate up --config './migrations/database.json'", + "db:migrate:down": "../../node_modules/db-migrate/bin/db-migrate down --config './migrations/database.json'", + "db:migrate:reset": "../../node_modules/db-migrate/bin/db-migrate reset --config './migrations/database.json'" }, "repository": { "type": "git", diff --git a/sandbox/cache-example/src/application.ts b/sandbox/cache-example/src/application.ts index 05563e284f..d0974bf634 100644 --- a/sandbox/cache-example/src/application.ts +++ b/sandbox/cache-example/src/application.ts @@ -11,11 +11,11 @@ import { RestExplorerComponent, } from '@loopback/rest-explorer'; import {ServiceMixin} from '@loopback/service-proxy'; -import {CachingComponent} from '@sourceloop/cache'; +import { CacheComponentBindings, CachingComponent, RedisStoreStrategy } from '@sourceloop/cache'; import path from 'path'; import {MySequence} from './sequence'; -export {ApplicationConfig}; +export { ApplicationConfig }; export class CacheExampleApplication extends BootMixin( ServiceMixin(RepositoryMixin(RestApplication)), @@ -29,6 +29,12 @@ export class CacheExampleApplication extends BootMixin( // Set up default home page this.static('/', path.join(__dirname, '../public')); + this.bind(CacheComponentBindings.CacheConfig).to({ + ttl: 1000, + strategy: RedisStoreStrategy, + datasourceName: 'cacheDb', + }); + // Customize @loopback/rest-explorer configuration here this.configure(RestExplorerBindings.COMPONENT).to({ path: '/explorer', diff --git a/sandbox/cache-example/src/repositories/README.md b/sandbox/cache-example/src/repositories/README.md index 08638a7878..cccd283857 100644 --- a/sandbox/cache-example/src/repositories/README.md +++ b/sandbox/cache-example/src/repositories/README.md @@ -1,3 +1,86 @@ -# Repositories +# CacheExample -This directory contains code for repositories provided by this app. +This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the +[initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html). + +## STEP 1: Install dependencies + +To install the project dependencies, run the following command: + +```sh +npm install +``` +## STEP 2: Set up Environment Variables +1. Copy the .env.example file to .env: + +```sh +cp .env.example .env +``` +2. Open the .env file and configure the necessary environment variables (e.g., database connection settings, redis connection settings). + +## STEP 3: Database Migration +Run the following command to migrate the database: +```sh +npm run db:migrate +``` + +## STEP 4: Start the application +Once everything is set up, you can start the Node.js application with the following command: +```sh +npm start +``` +This will start the server, and you can begin testing the API. + +## STEP 5: Testing the API +After starting the application, you can test the API using Swagger UI. Open your browser and visit: + +http://127.0.0.1:3000 Replace the URL according to your configuration + +## Rebuild the project + +To incrementally build the project: + +```sh +npm run build +``` + +To force a full build by cleaning up cached artifacts: + +```sh +npm run rebuild +``` + +## Fix code style and formatting issues + +```sh +npm run lint +``` + +To automatically fix such issues: + +```sh +npm run lint:fix +``` + +## Other useful commands +- `npm run openapi-spec`: Generate OpenAPI spec into a file +- `npm run docker:build`: Build a Docker image for this application +- `npm run docker:run`: Run this application inside a Docker container + +## Tests + +```sh +npm test +``` + +## Troubleshooting +* Ensure that your database is correctly configured and running. +* Make sure that the JWT private and public keys are properly set up in the .env file. +* If you encounter issues with Swagger UI not loading, verify that the server has successfully started and that the correct port is specified. + +## What's next + +Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to +understand how you can continue to add features to this application. + +[![LoopBack]()](http://loopback.io/) From 34a921f6f925e4e5924986ccb31f55ab0b545d5c Mon Sep 17 00:00:00 2001 From: vipul-sourcrefuse Date: Thu, 23 Jan 2025 17:25:22 +0530 Subject: [PATCH 2/3] refactor(sandbox): changes changes 0 changes --- sandbox/cache-example/README.md | 37 +++++--- .../cache-example/src/repositories/README.md | 87 +------------------ 2 files changed, 25 insertions(+), 99 deletions(-) diff --git a/sandbox/cache-example/README.md b/sandbox/cache-example/README.md index f7bd846e5c..cccd283857 100644 --- a/sandbox/cache-example/README.md +++ b/sandbox/cache-example/README.md @@ -1,32 +1,40 @@ -# cache-example +# CacheExample This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the [initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html). -## Install dependencies +## STEP 1: Install dependencies -By default, dependencies were installed when this application was generated. -Whenever dependencies in `package.json` are changed, run the following command: +To install the project dependencies, run the following command: ```sh npm install ``` - -To only install resolved dependencies in `package-lock.json`: +## STEP 2: Set up Environment Variables +1. Copy the .env.example file to .env: ```sh -npm ci +cp .env.example .env ``` +2. Open the .env file and configure the necessary environment variables (e.g., database connection settings, redis connection settings). -## Run the application +## STEP 3: Database Migration +Run the following command to migrate the database: +```sh +npm run db:migrate +``` +## STEP 4: Start the application +Once everything is set up, you can start the Node.js application with the following command: ```sh npm start ``` +This will start the server, and you can begin testing the API. -You can also run `node .` to skip the build step. +## STEP 5: Testing the API +After starting the application, you can test the API using Swagger UI. Open your browser and visit: -Open http://127.0.0.1:3000 in your browser. +http://127.0.0.1:3000 Replace the URL according to your configuration ## Rebuild the project @@ -55,8 +63,6 @@ npm run lint:fix ``` ## Other useful commands - -- `npm run migrate`: Migrate database schemas for models - `npm run openapi-spec`: Generate OpenAPI spec into a file - `npm run docker:build`: Build a Docker image for this application - `npm run docker:run`: Run this application inside a Docker container @@ -67,9 +73,14 @@ npm run lint:fix npm test ``` +## Troubleshooting +* Ensure that your database is correctly configured and running. +* Make sure that the JWT private and public keys are properly set up in the .env file. +* If you encounter issues with Swagger UI not loading, verify that the server has successfully started and that the correct port is specified. + ## What's next Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to understand how you can continue to add features to this application. -[![LoopBack](https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/) +[![LoopBack]()](http://loopback.io/) diff --git a/sandbox/cache-example/src/repositories/README.md b/sandbox/cache-example/src/repositories/README.md index cccd283857..00a3b0e904 100644 --- a/sandbox/cache-example/src/repositories/README.md +++ b/sandbox/cache-example/src/repositories/README.md @@ -1,86 +1 @@ -# CacheExample - -This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the -[initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html). - -## STEP 1: Install dependencies - -To install the project dependencies, run the following command: - -```sh -npm install -``` -## STEP 2: Set up Environment Variables -1. Copy the .env.example file to .env: - -```sh -cp .env.example .env -``` -2. Open the .env file and configure the necessary environment variables (e.g., database connection settings, redis connection settings). - -## STEP 3: Database Migration -Run the following command to migrate the database: -```sh -npm run db:migrate -``` - -## STEP 4: Start the application -Once everything is set up, you can start the Node.js application with the following command: -```sh -npm start -``` -This will start the server, and you can begin testing the API. - -## STEP 5: Testing the API -After starting the application, you can test the API using Swagger UI. Open your browser and visit: - -http://127.0.0.1:3000 Replace the URL according to your configuration - -## Rebuild the project - -To incrementally build the project: - -```sh -npm run build -``` - -To force a full build by cleaning up cached artifacts: - -```sh -npm run rebuild -``` - -## Fix code style and formatting issues - -```sh -npm run lint -``` - -To automatically fix such issues: - -```sh -npm run lint:fix -``` - -## Other useful commands -- `npm run openapi-spec`: Generate OpenAPI spec into a file -- `npm run docker:build`: Build a Docker image for this application -- `npm run docker:run`: Run this application inside a Docker container - -## Tests - -```sh -npm test -``` - -## Troubleshooting -* Ensure that your database is correctly configured and running. -* Make sure that the JWT private and public keys are properly set up in the .env file. -* If you encounter issues with Swagger UI not loading, verify that the server has successfully started and that the correct port is specified. - -## What's next - -Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to -understand how you can continue to add features to this application. - -[![LoopBack]()](http://loopback.io/) +# Repositories From bd11e760b5fbe9d8669bdd201f084760fbfed96e Mon Sep 17 00:00:00 2001 From: vipul-sourcrefuse Date: Mon, 27 Jan 2025 09:58:00 +0530 Subject: [PATCH 3/3] refactor(cache): lint issues fixes lint issues fix 0 --- sandbox/cache-example/src/application.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sandbox/cache-example/src/application.ts b/sandbox/cache-example/src/application.ts index d0974bf634..b326578f98 100644 --- a/sandbox/cache-example/src/application.ts +++ b/sandbox/cache-example/src/application.ts @@ -11,11 +11,15 @@ import { RestExplorerComponent, } from '@loopback/rest-explorer'; import {ServiceMixin} from '@loopback/service-proxy'; -import { CacheComponentBindings, CachingComponent, RedisStoreStrategy } from '@sourceloop/cache'; +import { + CacheComponentBindings, + CachingComponent, + RedisStoreStrategy, +} from '@sourceloop/cache'; import path from 'path'; import {MySequence} from './sequence'; -export { ApplicationConfig }; +export {ApplicationConfig}; export class CacheExampleApplication extends BootMixin( ServiceMixin(RepositoryMixin(RestApplication)),