From b1f0ed4df012114187d542f926aabd1a68568f28 Mon Sep 17 00:00:00 2001 From: Konstantin Tarkus Date: Fri, 11 Feb 2022 20:04:46 +0300 Subject: [PATCH] [`db`] Replace `faker` with `@faker-js/faker` --- .husky/pre-commit | 2 ++ README.md | 2 +- api/README.md | 2 +- db/package.json | 11 +++++------ db/seeds/01_users.ts | 5 +++-- scripts/api-deploy.js | 4 +++- yarn.lock | 26 ++++++++------------------ 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 9dcd433f..29eb3d56 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,3 +2,5 @@ . "$(dirname "$0")/_/husky.sh" yarn lint +yarn prettier --check . + diff --git a/README.md b/README.md index 59ad5bcd..1a93281a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ## Features -- Monorepo project structure powered by Yarn v2 with PnP +- Monorepo project structure powered by Yarn with PnP - GraphQL API using code-first development approach (TypeScript, GraphQL.js, Knex, PostgreSQL) - Stateless JWT cookie-based authentication (supporting SSR, OAuth 2.0 via Google, Facebook, etc.) - Database tooling — seed files, migrations, Knex.js REPL shell, etc. diff --git a/api/README.md b/api/README.md index 74d3eefc..afc4ced0 100644 --- a/api/README.md +++ b/api/README.md @@ -13,7 +13,7 @@ assistance. ## Tech Stack -- [Node.js](https://nodejs.org/) `v16`, [Yarn](https://yarnpkg.com/) `v2`, [TypeScript](https://www.typescriptlang.org/), [Babel](https://babeljs.io/), [Prettier](https://prettier.io/), [ESLint](https://eslint.org/) — core platform and dev tools +- [Node.js](https://nodejs.org/) `v16`, [Yarn](https://yarnpkg.com/), [TypeScript](https://www.typescriptlang.org/), [Babel](https://babeljs.io/), [Prettier](https://prettier.io/), [ESLint](https://eslint.org/) — core platform and dev tools - [GraphQL.js](https://github.com/graphql/graphql-js), [GraphQL.js Relay](https://github.com/graphql/graphql-relay-js), [DataLoader](https://github.com/graphql/dataloader), [Validator.js](https://github.com/validatorjs/validator.js) — [GraphQL](https://graphql.org/) schema and API endpoint(s) - [PostgreSQL](https://www.postgresql.org/), [Knex.js](https://knexjs.org/), [`pg`](https://node-postgres.com/), [`@google-cloud/storage`](https://googleapis.dev/nodejs/storage/latest) — data access - [`jswonwebtoken`](https://github.com/auth0/node-jsonwebtoken), [`google-auth-library`](https://github.com/googleapis/google-auth-library-nodejs) — stateless JWT-based sessions and authentication diff --git a/db/package.json b/db/package.json index a07b9e0f..913e967e 100644 --- a/db/package.json +++ b/db/package.json @@ -11,30 +11,29 @@ "db:migrate": "knex migrate:latest", "db:rollback": "knex migrate:rollback", "db:seed": "knex seed:run", - "db:reset": "babel-node --root-mode=upward -x .ts ./scripts/reset.ts", + "db:reset": "babel-node --root-mode=upward -o .,../api -x .ts ./scripts/reset.ts", "db:reset-test": "knex migrate:rollback --env=test 001_initial && knex migrate:latest --env=test && yarn db:restore --env=test", "db:reset-prod": "knex migrate:rollback --env=prod 001_initial && knex migrate:latest --env=prod && yarn db:restore --env=prod", "db:backup": "babel-node --root-mode=upward -x .ts ./scripts/backup.ts", "db:restore": "babel-node --root-mode=upward -x .ts ./scripts/restore.ts", - "db:import-seeds": "babel-node --root-mode=upward -x .ts ./scripts/import-seeds.ts", - "db:update-types": "babel-node --root-mode=upward -x .ts ./scripts/update-types.ts", + "db:import-seeds": "babel-node --root-mode=upward -o .,../api -x .ts ./scripts/import-seeds.ts", + "db:update-types": "babel-node --root-mode=upward -o .,../api -x .ts ./scripts/update-types.ts", "db:repl": "babel-node --root-mode=upward -o .,../api -x .ts --experimental-repl-await ./scripts/repl.ts", - "db:psql": "babel-node --root-mode=upward -x .ts ./scripts/psql.ts" + "db:psql": "babel-node --root-mode=upward -o .,../api -x .ts ./scripts/psql.ts" }, "devDependencies": { "@babel/core": "^7.17.2", "@babel/node": "^7.16.8", "@babel/register": "^7.17.0", + "@faker-js/faker": "^6.0.0-alpha.6", "@types/babel__core": "^7.1.18", "@types/cross-spawn": "^6.0.2", - "@types/faker": "^6.6.9", "@types/lodash": "^4.14.178", "@types/minimist": "^1.2.2", "@types/prettier": "^2.4.4", "chalk": "^4.1.2", "cross-spawn": "^7.0.3", "envars": "^0.4.0", - "faker": "^6.6.6", "knex": "^1.0.3", "knex-types": "^0.3.2", "lodash": "^4.17.21", diff --git a/db/seeds/01_users.ts b/db/seeds/01_users.ts index bcf25b7d..c8a9ac06 100644 --- a/db/seeds/01_users.ts +++ b/db/seeds/01_users.ts @@ -1,7 +1,7 @@ /* SPDX-FileCopyrightText: 2016-present Kriasoft */ /* SPDX-License-Identifier: MIT */ -import { date, image, internet, name, random } from "faker"; +import faker from "@faker-js/faker"; import { type Knex } from "knex"; import nanoid from "nanoid"; import fs from "node:fs/promises"; @@ -11,6 +11,7 @@ import prettier from "prettier"; // https://zelark.github.io/nano-id-cc/ const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; const newUserId = nanoid.customAlphabet(alphabet, 6); +const { date, image, internet, name, random } = faker; function stringify(obj: Record) { return prettier.format(JSON.stringify(obj), { parser: "json" }); @@ -62,5 +63,5 @@ export async function seed(db: Knex) { await fs.writeFile(jsonFile, stringify(users)); } - await db.table("user").insert(users); + await db.table("user").insert(users).onConflict(["id"]).ignore(); } diff --git a/scripts/api-deploy.js b/scripts/api-deploy.js index 36ca5507..6c0a8305 100644 --- a/scripts/api-deploy.js +++ b/scripts/api-deploy.js @@ -19,6 +19,7 @@ const args = minimist(process.argv.slice(2)); process.env.NODE_ENV = "production"; process.env.APP_ENV = args.env ?? process.env.APP_ENV ?? "test"; envars.config({ env: process.env.APP_ENV }); +delete process.env.PGSSLMODE; // Load the list of environment variables required by the app (api/env.ts) /** @type {import("../api/env").default} */ @@ -47,7 +48,8 @@ await $`gcloud functions deploy ${name} ${[ // `--signature-type=http`, `--source=./dist`, `--timeout=30`, - `--trigger-http`, `--set-env-vars=NODE_OPTIONS=--require=./.pnp.cjs --require=source-map-support/register --no-warnings`, ...Object.keys(env).map((key) => `--set-env-vars=${key}=${env[key]}`), + `--max-instances=4`, + `--trigger-http`, ]}`; diff --git a/yarn.lock b/yarn.lock index 86303bc6..c1fdf588 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1749,6 +1749,13 @@ __metadata: languageName: node linkType: hard +"@faker-js/faker@npm:^6.0.0-alpha.6": + version: 6.0.0-alpha.6 + resolution: "@faker-js/faker@npm:6.0.0-alpha.6" + checksum: 7da62a22a8e1bfbcd8b6517a6f3aa74cf468a681cea4b3cd306a285ec670dc591d48cb5191fc1131fba9fc669ba12f9c1b4849eb47f9be50c8476f72705bcc99 + languageName: node + linkType: hard + "@gar/promisify@npm:^1.0.1": version: 1.1.2 resolution: "@gar/promisify@npm:1.1.2" @@ -3020,15 +3027,6 @@ __metadata: languageName: node linkType: hard -"@types/faker@npm:^6.6.9": - version: 6.6.9 - resolution: "@types/faker@npm:6.6.9" - dependencies: - faker: "*" - checksum: 8fb069b6f2bf2cefec42a214395f49695b881d70e651a215a61c2fa7494bb173d1a598c895882ff89df3702ab51c49c23433b3d4bcfd8323cf4f608ed9fb6ce8 - languageName: node - linkType: hard - "@types/fs-extra@npm:^8.0.1": version: 8.1.2 resolution: "@types/fs-extra@npm:8.1.2" @@ -5612,16 +5610,15 @@ __metadata: "@babel/core": ^7.17.2 "@babel/node": ^7.16.8 "@babel/register": ^7.17.0 + "@faker-js/faker": ^6.0.0-alpha.6 "@types/babel__core": ^7.1.18 "@types/cross-spawn": ^6.0.2 - "@types/faker": ^6.6.9 "@types/lodash": ^4.14.178 "@types/minimist": ^1.2.2 "@types/prettier": ^2.4.4 chalk: ^4.1.2 cross-spawn: ^7.0.3 envars: ^0.4.0 - faker: ^6.6.6 knex: ^1.0.3 knex-types: ^0.3.2 lodash: ^4.17.21 @@ -6708,13 +6705,6 @@ __metadata: languageName: node linkType: hard -"faker@npm:*, faker@npm:^6.6.6": - version: 6.6.6 - resolution: "faker@npm:6.6.6" - checksum: bfb0d581ab4d76095f2c6bff213fe1735ce077f0f8df849c144ad26035e105bce1b7a704cc030366338c52e25b636ac097a712426a78c9b8804af78f6f2bffe7 - languageName: node - linkType: hard - "fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3": version: 3.1.3 resolution: "fast-deep-equal@npm:3.1.3"