diff --git a/docs/advance/cache.md b/docs/advance/cache.md index e09b213..1ca416b 100644 --- a/docs/advance/cache.md +++ b/docs/advance/cache.md @@ -45,7 +45,7 @@ Deploy your application again and you may now use ElastiCache. ## Cache Usage -Import the `cache` module from `Utils/cache`. +Import the `cache` module from `lesgo/utils/cache`. To test the sample usage, uncomment `samples.yml` function in `serverless.yml` and deploy the application to a development environment. @@ -60,7 +60,7 @@ cache.get( ``` ```js -import cache from "Utils/cache"; +import cache from "lesgo/utils/cache"; const data = await cache.get("foo"); ``` @@ -78,7 +78,7 @@ cache.getMulti( **Example Usage** ```js -import cache from "Utils/cache"; +import cache from "lesgo/Utils/cache"; const cacheKeys = ["foo", "foo2", "foo3"]; @@ -90,7 +90,7 @@ const data = await cache.getMulti(["foo", "foo2", "foo3"]); You may use the `set` method on the `cache` util to store items to the cache. ```js -import cache from "Utils/cache"; +import cache from "lesgo/utils/cache"; const cacheKey = "foo"; const cacheValue = "bar"; @@ -114,7 +114,7 @@ cache.del( **Example Usage** ```js -import cache from "Utils/cache"; +import cache from "lesgo/utils/cache"; await cache.del("foo"); ``` @@ -132,7 +132,7 @@ cache.delMulti( **Example Usage** ```js -import cache from "Utils/cache"; +import cache from "lesgo/utils/cache"; await cache.delMulti(["foo", "foo2", "foo3"]); ``` diff --git a/docs/advance/helpers.md b/docs/advance/helpers.md index 650de82..e2607a2 100644 --- a/docs/advance/helpers.md +++ b/docs/advance/helpers.md @@ -1,10 +1,10 @@ # Helpers -Lesgo! comes in-built with various helper functions available within the `Utils/` namespace. +Lesgo! comes in-built with various helper functions available within the `lesgo/utils/` namespace. ## Crypto -> `Utils/crypto` +> `lesgo/utils/crypto` Cryptographic functions using the Crypto npm library. @@ -13,7 +13,7 @@ Cryptographic functions using the Crypto npm library. One way hashing of data using SHA-256. ```js -import { hash } from "Utils/crypto"; +import { hash } from "lesgo/utils/crypto"; const hashedString = hash("some data to hash"); @@ -25,7 +25,7 @@ const hashedString = hash("some data to hash"); One way hashing of data using the faster MD5. ```js -import { hashMD5 } from "Utils/crypto"; +import { hashMD5 } from "lesgo/utils/crypto"; const hashedMD5String = hashMD5("some data to hash"); @@ -41,7 +41,7 @@ const hashedMD5String = hashMD5("some data to hash"); 2-way encryption with auto-generated iv and cipher. ```js -import { encrypt } from "Utils/crypto"; +import { encrypt } from "lesgo/utils/crypto"; const encryptedStr = encrypt( "some string to be encrypted that can be decrypted" @@ -55,7 +55,7 @@ const encryptedStr = encrypt( Decrypting a previously encrypted data. ```js -import { decrypt } from "Utils/crypto"; +import { decrypt } from "lesgo/utils/crypto"; const decryptedStr = decrypt("some-encrypted-string"); @@ -64,12 +64,12 @@ const decryptedStr = decrypt("some-encrypted-string"); ## Generate Uid -> `Utils/generateUid` +> `lesgo/utils/generateUid` Generates random string with an optional prefix and suffix using the Nanoid npm library. Useful for generating unique id. ```js -import generateUid from "Utils/generateUid"; +import generateUid from "lesgo/utils/generateUid"; const uid = generateUid()); @@ -90,12 +90,12 @@ const uidLimited = generateUid({ length: 36 })); ## Email Format Validator -> `Utils/isEmail` +> `lesgo/utils/isEmail` Validates for a valid email format. ```js -import isEmail from "Utils/isEmail"; +import isEmail from "lesgo/utils/isEmail"; isEmail("john@doe.com")); @@ -108,12 +108,12 @@ isEmail("some string")); ## Decimal Number Validator -> `Utils/isDecimal` +> `lesgo/utils/isDecimal` Validates for a valid decimal number in any format such as `##.##`. ```js -import isDecimal from "Utils/isDecimal"; +import isDecimal from "lesgo/utils/isDecimal"; isDecimal(5.4); @@ -126,12 +126,12 @@ isDecimal(5); ## Empty Value Validator -> `Utils/isEmpty` +> `lesgo/utils/isEmpty` Validates if a value is either an `undefined`, or `null`, or empty string, or an empty array, or an object without keys. ```js -import isEmpty from "Utils/isEmpty"; +import isEmpty from "lesgo/utils/isEmpty"; isEmpty(undefined); isEmpty(null); @@ -149,12 +149,12 @@ isEmpty(0); ## Field Validator -> `Utils/validateFields` +> `lesgo/utils/validateFields` Validates parameters received to ensure the data is of the right type and exists. ```js -import validateFields from "Utils/validateFields"; +import validateFields from "lesgo/utils/validateFields"; const validFields = [ { key: "someString", type: "string", required: true }, @@ -242,7 +242,7 @@ prepSQLInsertParams( **Usage** ```js -import prepSQLInsertParams from "Utils/prepSQLInsertParams"; +import prepSQLInsertParams from "lesgo/utils/prepSQLInsertParams"; const params = { username: "John", diff --git a/docs/advance/object-store.md b/docs/advance/object-store.md index 8b11dcd..57fa787 100644 --- a/docs/advance/object-store.md +++ b/docs/advance/object-store.md @@ -24,7 +24,7 @@ AWS_S3_OPTIONS_REGION="" The `getObject()` function will fetch the object from the Bucket. ```js -import { getObject } from 'Utils/objectStore'; +import { getObject } from "lesgo/utils/objectStore"; // Returns a buffered object response. See AWS for more information const objectFile = await getObject('Key', 'Bucket'); diff --git a/docs/advance/queues.md b/docs/advance/queues.md index a5072c6..2edd037 100644 --- a/docs/advance/queues.md +++ b/docs/advance/queues.md @@ -28,7 +28,7 @@ The `Utils/dispatch` function will dispatch a message payload to the queue. This example usage will send a message to the pre-defined PingQueue. ```js -import { dispatch } from "Utils/queue"; +import { dispatch } from "lesgo/utils/queue"; const payload = { someData: "someValue", diff --git a/docs/basics/error-handling.md b/docs/basics/error-handling.md index 79b80b1..c0b7b5d 100644 --- a/docs/basics/error-handling.md +++ b/docs/basics/error-handling.md @@ -51,7 +51,7 @@ SENTRY_RELEASE="sls-my-project-maste" Call this as early as possible on any of your lambdas. A suggestion would be to put this inside of a middleware ```js -import connectSentry from "Utils/sentry"; +import connectSentry from "lesgo/utils/sentry"; connectSentry(); ``` diff --git a/docs/basics/logging.md b/docs/basics/logging.md index 7730e9a..3a65d64 100644 --- a/docs/basics/logging.md +++ b/docs/basics/logging.md @@ -5,7 +5,7 @@ Lesgo! is configured with structured logging. Structured logs will appear on the console by default. ```js -import logger from "Utils/logger"; +import logger from "lesgo/utils/logger"; logger.log("info", "this is an info log"); logger.info("This is an info log"); diff --git a/docs/basics/middleware.md b/docs/basics/middleware.md index 0450265..6158139 100644 --- a/docs/basics/middleware.md +++ b/docs/basics/middleware.md @@ -20,7 +20,7 @@ This middleware normalizes all HTTP requests, handles, and formats success and e ```js import middy from '@middy/core'; -import httpMiddleware from "Middlewares/httpMiddleware"; +import httpMiddleware from "lesgo/middlewares/httpMiddleware"; const originalHandler = event => { return event.input; @@ -74,7 +74,7 @@ This middleware will normalize records coming from sqs message event. The `Recor ```js import middy from '@middy/core'; -import normalizeSQSMessage from "Middlewares/normalizeSQSMessage"; +import normalizeSQSMessage from "lesgo/middlewares/normalizeSQSMessage"; const originalHandler = event => { return event.collection; @@ -117,7 +117,7 @@ JWT_CUSTOM_CLAIMS_DATA="" ```js import middy from '@middy/core'; -import verifyJwtTokenMiddleware from "Middlewares/verifyJwtTokenMiddleware"; +import verifyJwtTokenMiddleware from "lesgo/middlewares/verifyJwtTokenMiddleware"; const originalHandler = event => { return event.collection; diff --git a/docs/database/dynamodb.md b/docs/database/dynamodb.md index fd1b87b..c7857e3 100644 --- a/docs/database/dynamodb.md +++ b/docs/database/dynamodb.md @@ -55,7 +55,7 @@ dynamodb.query( **Usage** ```js -import dynamodb from "Utils/dynamodb"; +import dynamodb from "lesgo/utils/dynamodb"; const user = await dynamodb.query( "ActorsTable", @@ -91,7 +91,7 @@ dynamodb.queryCount( **Usage** ```js -import dynamodb from "Utils/dynamodb"; +import dynamodb from "lesgo/utils/dynamodb"; const count = await dynamodb.queryCount( "ActorsTable", @@ -118,7 +118,7 @@ dynamodb.put( **Usage** ```js -import dynamodb from "Utils/dynamodb"; +import dynamodb from "lesgo/utils/dynamodb"; const data = await dynamodb.put("ActorTable", { actorName: "Keanue Reaves", @@ -142,7 +142,7 @@ dynamodb.update( **Usage** ```js -import dynamodb from "Utils/dynamodb"; +import dynamodb from "lesgo/utils/dynamodb"; const data = await dynamodb.update( "ActorsTable", diff --git a/docs/database/rds-aurora.md b/docs/database/rds-aurora.md index f1eb787..45c9ab0 100644 --- a/docs/database/rds-aurora.md +++ b/docs/database/rds-aurora.md @@ -123,9 +123,9 @@ As such, specifically for RDS Proxy, you should make use of Lesgo's persistent c // src/handlers/utils/ping.js import middy from "@middy/core"; -import httpMiddleware from "Middlewares/httpMiddleware"; -import ping from "Core/utils/ping"; -import db from "Utils/db"; +import httpMiddleware from "lesgo/middlewares/httpMiddleware"; +import db from "lesgo/utils/db"; +import ping from "core/utils/ping"; const originalHandler = async (event) => { await db.pConnect(); @@ -146,8 +146,8 @@ Should you want to handle the closing of the db connection yourself and without // src/handlers/utils/ping.js import middy from "@middy/core"; -import ping from "Core/utils/ping"; -import db from "Utils/db"; +import db from "lesgo/utils/db"; +import ping from "core/utils/ping"; const originalHandler = async (event) => { await db.pConnect(); @@ -186,7 +186,7 @@ db.select( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const data = await db.select( "SELECT * FROM users WHERE is_deleted = :isDeleted", @@ -211,7 +211,7 @@ db.selectFirst( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const data = await db.selectFirst("SELECT * FROM users WHERE id = :id", { id: 1, @@ -240,7 +240,7 @@ db.selectPaginate( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const data = await db.selectPaginate( "SELECT * FROM users WHERE is_deleted = :isDeleted", @@ -270,7 +270,7 @@ db.insert( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const insertId = await db.insert( "INSERT INTO users(username,email) VALUES (:username, :email)", @@ -284,9 +284,9 @@ const insertId = await db.insert( A much better approach to inserting records is to first validate the fields and then inserting it with `Utils/prepSQLInsertParams`. ```js -import prepSQLInsertParams from "Utils/prepSQLInsertParams"; -import validateFields from "Utils/validateFields"; -import db from "Utils/db"; +import prepSQLInsertParams from "lesgo/utils/prepSQLInsertParams"; +import validateFields from "lesgo/utils/validateFields"; +import db from "lesgo/utils/db"; const validFields = [ { key: "username", type: "string", required: true }, @@ -323,7 +323,7 @@ db.update( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const insertId = await db.update( "UPDATE users SET username=:username, email=:email, updated_at=now()) WHERE id=:id", @@ -338,9 +338,9 @@ const insertId = await db.update( As with insert, updatating an existing record is best done with `Utils/prepSQLUpdateParams`. ```js -import prepSQLUpdateParams from "Utils/prepSQLUpdateParams"; -import validateFields from "Utils/validateFields"; -import db from "Utils/db"; +import prepSQLUpdateParams from "lesgo/utils/prepSQLUpdateParams"; +import validateFields from "lesgo/utils/validateFields"; +import db from "lesgo/utils/db"; const validFields = [ { key: "username", type: "string", required: true }, @@ -380,7 +380,7 @@ db.query( **Usage** ```js -import db from "Utils/db"; +import db from "lesgo/utils/db"; const data = await db.query("SELECT * FROM users WHERE id = :id", { id: 1, diff --git a/docs/packages/elasticsearch.md b/docs/packages/elasticsearch.md index 5ede0fb..f9c10c4 100644 --- a/docs/packages/elasticsearch.md +++ b/docs/packages/elasticsearch.md @@ -28,7 +28,7 @@ ES_REGION="" To run a basic query, you may use the search method on the `Utils/es`: ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; const response = await es().search({ query: { @@ -79,7 +79,7 @@ const response = await es().search({ ## Advanced Query ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; const response = await es().search({ from: 0, @@ -164,7 +164,7 @@ const response = await es().search({ If ever needed you can also access the client directly ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; const client = es().getClient(); @@ -184,7 +184,7 @@ await client.index({ This will set the current connection to either `aws` or `default`. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; es().setConnection("aws"); ``` @@ -194,7 +194,7 @@ es().setConnection("aws"); This will create a new index. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es().createIndices( { @@ -210,7 +210,7 @@ await es().createIndices( This will delete one or more indices. For more options, refer [here](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_delete) ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es().deleteIndices(["game-of-thrones", "twitter", "store"]); @@ -226,7 +226,7 @@ await es().deleteIndices("game-of-thrones", { This will check if an index or indices exists. For more options, refer [here](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_exists) ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es().existIndices("game-of-thrones"); @@ -245,7 +245,7 @@ This will add new fields to an existing data stream or index. Due to deprecation of `type` from Elasticsearch 7.0.0, use `es.getClient()` directly. For more info, refer [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/removal-of-types.html) ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es().putMapping("twitter", "user", { name: { type: "text" }, @@ -259,7 +259,7 @@ await es().putMapping("twitter", "user", { This will retrieve the specified JSON document from an index using the document ID. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es({ index: "game-of-thrones" }).get("0"); @@ -309,7 +309,7 @@ es.search( **Example Usage** ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; const search = es({ index: "game-of-thrones" }); @@ -335,7 +335,7 @@ es.msearch( **Example Usage** ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; const search = es({ index: "game-of-thrones" }); @@ -392,7 +392,7 @@ Learn more with [Multi Search API](https://www.elastic.co/guide/en/elasticsearch This will add a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version, else it is created. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es({ index: "game-of-thrones" }).create("1", { character: "Tyrion Lannister", @@ -432,7 +432,7 @@ await es({ index: "game-of-thrones" }).indexOrCreateById( This will perform multiple indexing or delete operations in a single API call. This reduces overhead and can greatly increase indexing speed. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es({ index: "game-of-thrones" }).bulkIndex([ { @@ -481,7 +481,7 @@ await es({ index: "game-of-thrones" }).bulkIndex([ This adds a JSON document to the specified data stream or index and makes it searchable. ```js -import es from "Utils/elasticsearch"; +import es from "lesgo/utils/elasticsearch"; await es({ index: "game-of-thrones" }).create("1", { text: "If I fall, don't bring me back.", diff --git a/docs/packages/firebase.md b/docs/packages/firebase.md index 4f29838..0f340e9 100644 --- a/docs/packages/firebase.md +++ b/docs/packages/firebase.md @@ -5,7 +5,7 @@ Lesgo! comes with a service wrapper of `firebase-admin` plugin ## Initialization ```js -import FirebaseAdmin from "Services/FirebaseAdminService"; +import FirebaseAdmin from "lesgo/services/FirebaseAdminService"; const serviceAccount = require("path/to/serviceAccountKey.json"); diff --git a/docs/prologue/release-notes.md b/docs/prologue/release-notes.md index c107bb9..24ea069 100644 --- a/docs/prologue/release-notes.md +++ b/docs/prologue/release-notes.md @@ -37,9 +37,9 @@ Previously, persistent connections have to be manually disconnected for both db // src/handlers/utils/ping.js import middy from "@middy/core"; -import httpMiddleware from "Middlewares/httpMiddleware"; -import ping from "Core/utils/ping"; -import db from "Utils/db"; +import httpMiddleware from "lesgo/middlewares/httpMiddleware"; +import db from "lesgo/utils/db"; +import ping from "core/utils/ping"; const originalHandler = async (event) => { await Promise.all([dbRead.pConnect(), cache.pConnect()]); // connect to the db and cache before anything else @@ -58,8 +58,8 @@ handler.use(httpMiddleware({ db, cache })); // pass along the instance to the mi // src/handlers/utils/ping.js import middy from "@middy/core"; -import ping from "Core/utils/ping"; -import db from "Utils/db"; +import db from "lesgo/utils/db"; +import ping from "core/utils/ping"; const originalHandler = async (event) => { await db.pConnect(); // connect to the db before anything else