@ooneex/cli 1.38.1 → 1.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +305 -977
- package/dist/index.js.map +8 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6042,18 +6042,18 @@ var askName = async (config) => {
|
|
|
6042
6042
|
|
|
6043
6043
|
// src/templates/app/app-database.txt
|
|
6044
6044
|
var app_database_default = `import { SharedModule } from "@module/shared/SharedModule";
|
|
6045
|
-
import { AppEnv } from "@ooneex/app-env";
|
|
6046
|
-
import { inject } from "@ooneex/container";
|
|
6047
6045
|
import { DatabaseException, decorator, TypeormDatabase } from "@ooneex/database";
|
|
6046
|
+
import { inject } from "@ooneex/container";
|
|
6047
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
6048
6048
|
import { DataSource } from "typeorm";
|
|
6049
6049
|
|
|
6050
6050
|
@decorator.database()
|
|
6051
6051
|
export class SharedDatabase extends TypeormDatabase {
|
|
6052
|
-
constructor(@inject(AppEnv) private readonly env: AppEnv) {
|
|
6052
|
+
public constructor(@inject(AppEnv) private readonly env: AppEnv) {
|
|
6053
6053
|
super();
|
|
6054
6054
|
}
|
|
6055
6055
|
|
|
6056
|
-
public getSource(): DataSource {
|
|
6056
|
+
public getSource(_database?: string): DataSource {
|
|
6057
6057
|
if (this.source) {
|
|
6058
6058
|
return this.source;
|
|
6059
6059
|
}
|
|
@@ -6210,6 +6210,27 @@ const app = new App({
|
|
|
6210
6210
|
await app.run();
|
|
6211
6211
|
`;
|
|
6212
6212
|
|
|
6213
|
+
// src/templates/app/package.json.txt
|
|
6214
|
+
var package_json_default = `{
|
|
6215
|
+
"name": "{{NAME}}",
|
|
6216
|
+
"scripts": {
|
|
6217
|
+
"fmt": "bunx biome check --write",
|
|
6218
|
+
"lint": "bunx nx run-many -t lint --output-style=stream --verbose",
|
|
6219
|
+
"test": "bunx nx run-many -t test --output-style=stream --verbose",
|
|
6220
|
+
"check": "bun install && bun run build && bun run lint && bun run test",
|
|
6221
|
+
"commit": "bunx commit"
|
|
6222
|
+
},
|
|
6223
|
+
"workspaces": [
|
|
6224
|
+
"modules/*"
|
|
6225
|
+
],
|
|
6226
|
+
"lint-staged": {
|
|
6227
|
+
"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
|
|
6228
|
+
"biome check --files-ignore-unknown=true"
|
|
6229
|
+
]
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
`;
|
|
6233
|
+
|
|
6213
6234
|
// src/templates/bitbucket/pipelines.yml.txt
|
|
6214
6235
|
var pipelines_yml_default = `# Bitbucket Pipelines
|
|
6215
6236
|
# Place at bitbucket-pipelines.yml in the repository root.
|
|
@@ -10341,26 +10362,6 @@ var nx_json_default = `{
|
|
|
10341
10362
|
}
|
|
10342
10363
|
`;
|
|
10343
10364
|
|
|
10344
|
-
// src/templates/app/package.json.txt
|
|
10345
|
-
var package_json_default = `{
|
|
10346
|
-
"name": "{{NAME}}",
|
|
10347
|
-
"scripts": {
|
|
10348
|
-
"fmt": "bunx biome check --write",
|
|
10349
|
-
"lint": "bunx nx run-many -t lint --output-style=stream --verbose",
|
|
10350
|
-
"test": "bunx nx run-many -t test --output-style=stream --verbose",
|
|
10351
|
-
"commit": "bunx commit"
|
|
10352
|
-
},
|
|
10353
|
-
"workspaces": [
|
|
10354
|
-
"modules/*"
|
|
10355
|
-
],
|
|
10356
|
-
"lint-staged": {
|
|
10357
|
-
"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
|
|
10358
|
-
"biome check --files-ignore-unknown=true"
|
|
10359
|
-
]
|
|
10360
|
-
}
|
|
10361
|
-
}
|
|
10362
|
-
`;
|
|
10363
|
-
|
|
10364
10365
|
// src/templates/app/README.md.txt
|
|
10365
10366
|
var README_md_default = "# {{NAME}}\n\nA modular, enterprise-grade backend framework built with TypeScript and Bun, powered by the **@ooneex** ecosystem.\n\n## Prerequisites\n\n- [Bun](https://bun.sh) (latest)\n- [Docker](https://www.docker.com/) & Docker Compose\n\n## Getting Started\n\n### Install Dependencies\n\n```bash\nbun install\n```\n\n### Environment Configuration\n\nThe environment file is created automatically at `modules/app/.env.yml`. Edit it to fill in the required values:\n\n| Variable | Description | Required |\n|---|---|---|\n| `app.env` | Application environment (`local`, `development`, `staging`, `testing`, `production`, \u2026) | Yes |\n| `app.port` | Server port number (default: `3000`) | Yes |\n| `app.host` | Server hostname (default: `0.0.0.0`) | Yes |\n| `logs.database_url` | Database URL for storing application logs | No |\n| `logs.betterstack.source_token` | Logtail source token for Better Stack logging | No |\n| `logs.betterstack.ingesting_host` | Better Stack log ingestion host URL | No |\n| `exception.betterstack.application_token` | Better Stack token for exception tracking | No |\n| `exception.betterstack.ingesting_host` | Better Stack exception ingestion host URL | No |\n| `analytics.posthog.project_token` | PostHog project token for event tracking | No |\n| `analytics.posthog.host` | PostHog ingest host (default: `https://eu.i.posthog.com`) | No |\n| `cache.redis.url` | Redis connection URL for caching | No |\n| `cache.upstash.rest_url` | Upstash Redis REST URL for serverless caching | No |\n| `cache.upstash.rest_token` | Upstash Redis REST token for serverless caching | No |\n| `pubsub.redis.url` | Redis connection URL for pub/sub messaging | No |\n| `rate_limit.redis.url` | Redis connection URL for rate limiting | No |\n| `rate_limit.upstash.url` | Upstash Redis URL for serverless rate limiting | No |\n| `rate_limit.upstash.token` | Upstash Redis token for serverless rate limiting | No |\n| `cors.origins` | Comma-separated allowed origins or `*` (default: `*`) | No |\n| `cors.methods` | Comma-separated HTTP methods | No |\n| `cors.headers` | Comma-separated allowed request headers | No |\n| `cors.exposed_headers` | Comma-separated headers exposed to the browser | No |\n| `cors.credentials` | Allow credentials: `true` or `false` | No |\n| `cors.max_age` | Preflight response cache duration in seconds | No |\n| `database.url` | PostgreSQL connection URL | No |\n| `database.redis.url` | Redis connection URL for Redis-based database operations | No |\n| `database.sqlite.path` | SQLite database file path | No |\n| `storage.cloudflare.access_key` | Cloudflare R2 access key ID | No |\n| `storage.cloudflare.secret_key` | Cloudflare R2 secret access key | No |\n| `storage.cloudflare.endpoint` | Cloudflare R2 endpoint URL | No |\n| `storage.cloudflare.region` | Cloudflare R2 region (default: `EEUR`) | No |\n| `storage.bunny.access_key` | BunnyCDN access key | No |\n| `storage.bunny.storage_zone` | BunnyCDN storage zone name | No |\n| `storage.bunny.region` | BunnyCDN region (default: `de`) | No |\n| `storage.filesystem.path` | Base directory path for local file storage | No |\n| `mailer.sender.name` | Display name for email sender | No |\n| `mailer.sender.address` | Email address for sender | No |\n| `mailer.resend.api_key` | Resend email service API key | No |\n| `jwt.secret` | Secret key for HS256 JWT signing and verification | No |\n| `ai.openrouter.api_key` | OpenRouter API key for accessing 300+ AI models | No |\n| `ai.openai.api_key` | OpenAI API key | No |\n| `ai.anthropic.api_key` | Anthropic API key for Claude models | No |\n| `ai.gemini.api_key` | Google Gemini API key | No |\n| `ai.groq.api_key` | Groq API key for LLM inference | No |\n| `ai.ollama.host` | Ollama host URL for local LLM inference | No |\n| `payment.polar.access_token` | Polar payment platform access token | No |\n| `payment.polar.environment` | Polar environment (`sandbox` or `production`) | No |\n| `authentication.auth_token` | Shared secret token for service-to-service authentication | No |\n| `authentication.clerk.secret_key` | Clerk authentication secret key | No |\n| `linear.api_key` | Linear API key for issue sync (`issue:pull`, `issue:push`) | No |\n| `linear.team_id` | Linear team ID \u2014 skips team selection prompt in `issue:push` | No |\n| `allowed_users.development` | Comma-separated emails allowed in the `development` environment | No |\n| `allowed_users.staging` | Comma-separated emails allowed in the `staging` environment | No |\n| `allowed_users.testing` | Comma-separated emails allowed in the `testing` environment | No |\n| `allowed_users.test` | Comma-separated emails allowed in the `test` environment | No |\n| `allowed_users.qa` | Comma-separated emails allowed in the `qa` environment | No |\n| `allowed_users.uat` | Comma-separated emails allowed in the `uat` environment | No |\n| `allowed_users.integration` | Comma-separated emails allowed in the `integration` environment | No |\n| `allowed_users.preview` | Comma-separated emails allowed in the `preview` environment | No |\n| `allowed_users.demo` | Comma-separated emails allowed in the `demo` environment | No |\n| `allowed_users.sandbox` | Comma-separated emails allowed in the `sandbox` environment | No |\n| `allowed_users.beta` | Comma-separated emails allowed in the `beta` environment | No |\n| `allowed_users.canary` | Comma-separated emails allowed in the `canary` environment | No |\n| `allowed_users.hotfix` | Comma-separated emails allowed in the `hotfix` environment | No |\n| `allowed_users.system` | Comma-separated system user emails | No |\n| `allowed_users.super_admin` | Comma-separated super-admin user emails | No |\n| `allowed_users.admin` | Comma-separated admin user emails | No |\n\n### Start the App\n\nStarts Docker services (if a `docker-compose.yml` is present) and launches the application with hot reload:\n\n```bash\noo app:start\n```\n\n### Stop the App\n\nStops all Docker services:\n\n```bash\noo app:stop\n```\n\n### Build the App\n\nCompiles the application for production. Output is written to the `dist` directory:\n\n```bash\noo app:build\n```\n\n---\n\n## Modules\n\nModules are the core organizational unit. Each module lives under `modules/<name>/` and contains its own controllers, services, repositories, entities, migrations, and seeds.\n\n### Why Modules?\n\nA flat codebase quickly becomes hard to navigate and reason about as an application grows. Modules address this by enforcing **vertical slicing**: all code related to a single business domain (e.g. `user`, `order`, `billing`) lives together rather than being scattered across generic `controllers/`, `services/`, and `repositories/` folders.\n\n**Benefits:**\n\n- **Domain isolation** \u2014 changes to one feature cannot accidentally break another; each module is a self-contained unit with explicit boundaries.\n- **Parallel development** \u2014 teams can work on separate modules without stepping on each other's code or creating merge conflicts in shared directories.\n- **Independent deployment** \u2014 a module can be extracted into a standalone service later with minimal refactoring because its code is already co-located.\n- **Simpler onboarding** \u2014 a new developer understands the scope of a feature by exploring a single directory instead of tracing imports across the whole project.\n- **Scoped migrations & seeds** \u2014 database changes stay close to the entities they affect, making rollbacks and reviews straightforward.\n\n**Good practices:**\n\n- Name modules after business domains (`user`, `product`, `payment`), not technical layers (`controllers`, `helpers`).\n- Keep modules small and focused. If a module grows beyond ~10 controllers or services, consider splitting it by sub-domain.\n- Never import from another module's internal files directly \u2014 expose only what is needed through the module's public index.\n- Register all entities in `SharedModule` (done automatically by `oo make:entity`) so the ORM has a single source of truth.\n- Run `oo module:lock` after every migration or seed change to protect file integrity in CI.\n- Prefix route names with the module name (e.g. `api.user.create`) to avoid collisions across modules.\n\n### Create a Module\n\nScaffolds a new module with all required structure, registers it in `AppModule`, adds its entities to `SharedModule`, and updates `tsconfig.json` path aliases and commitlint config:\n\n```bash\noo module:create\noo module:create --name user\n```\n\n### Lock a Module\n\nHashes migration and seed files into a module manifest (`.yml`) for integrity verification. Run this after adding or modifying migrations/seeds:\n\n```bash\noo module:lock --module user\noo module:lock --module user --override # force update existing hashes\n```\n\n### Delete a Module\n\nRemoves a module and cleans up all references from `AppModule`, `SharedModule`, `tsconfig.json`, and commitlint config. The `app` and `shared` core modules cannot be removed:\n\n```bash\noo module:remove\noo module:remove --name user\noo module:remove --name user --silent # skip confirmation prompt\n```\n\n---\n\n## Migrations\n\nMigrations are versioned, incremental SQL scripts that evolve your database schema over time. Each migration lives in `modules/<name>/src/migrations/` and is executed in order, making every schema change reproducible, reviewable, and reversible.\n\n### Why Migrations?\n\nManually altering a database in production is error-prone and leaves no audit trail. Migrations solve this by treating schema changes as code: they are committed to git, reviewed in pull requests, and applied the same way in every environment \u2014 local, staging, and production.\n\n**Benefits:**\n\n- **Reproducibility** \u2014 any developer can recreate the exact database state by running `oo migration:up` from scratch.\n- **History & auditability** \u2014 every schema change is tied to a commit, a date, and an author, making it easy to understand when and why a column or table was added.\n- **Safe deployments** \u2014 CI runs migrations before the application boots, catching schema errors before they reach production.\n- **Rollback capability** \u2014 because changes are incremental and versioned, you can reason about what to undo if a deployment goes wrong.\n- **Team coordination** \u2014 concurrent feature branches each generate their own migration file; the timestamp ordering ensures they are applied in the correct sequence when merged.\n\n**Good practices:**\n\n- One migration per logical change (e.g. add a table, add a column, add an index). Avoid bundling unrelated schema changes in a single file.\n- Never edit a migration that has already been applied in any shared environment \u2014 create a new migration to amend it instead.\n- Always write both `up` and `down` logic so migrations can be rolled back cleanly.\n- Keep migrations idempotent where possible (e.g. `CREATE TABLE IF NOT EXISTS`) to prevent failures on re-runs.\n- Run `oo module:lock` after every new migration to hash the file into the module manifest and enable integrity checks in CI.\n- Test migrations against a real database in CI \u2014 schema errors are invisible to TypeScript's type checker.\n- Avoid putting business logic or data transformations in migrations; keep them strictly structural (DDL) or use a dedicated seed for data.\n\n### Create a Migration\n\nGenerates a timestamped migration file in `modules/<name>/src/migrations/` along with a test file and a `bin/migration/up.ts` runner (if not already present):\n\n```bash\noo migration:create --module user\n```\n\n### Run Migrations\n\nExecutes migrations across all modules sequentially:\n\n```bash\noo migration:up\noo migration:up --drop # drop database before migrating\n```\n\n---\n\n## Seeds\n\nSeeds populate your database with initial or reference data \u2014 default roles, configuration values, demo content, or test fixtures. Each seed lives in `modules/<name>/src/seeds/` as a YAML file and is executed in order via the seed runner.\n\n### Why Seeds?\n\nHardcoding initial data in migration files mixes structural changes with data concerns, making both harder to maintain. Seeds keep data separate from schema, so they can be re-run independently, updated without touching migrations, and disabled in environments where they are not needed.\n\n**Benefits:**\n\n- **Consistent starting state** \u2014 every developer and every environment boots with the same baseline data, eliminating \"works on my machine\" data discrepancies.\n- **Readable data definitions** \u2014 YAML files are easy to read, diff, and review in pull requests without understanding SQL or TypeScript.\n- **Repeatable setup** \u2014 onboarding a new developer or spinning up a fresh staging environment requires only `oo seed:run` instead of manual database operations.\n- **Separation of concerns** \u2014 schema structure (migrations) and data content (seeds) evolve independently, reducing noise in both histories.\n- **Safe resets** \u2014 `oo seed:run --drop` wipes and repopulates data without touching the schema, useful for resetting demo or test environments.\n\n**Good practices:**\n\n- Use seeds for **reference data** (roles, permissions, countries, currencies) and **development fixtures** (demo users, sample products). Avoid using them for production user data.\n- Keep each seed file focused on a single entity or dataset \u2014 one file per table is a reasonable default.\n- Write seeds so they are idempotent: inserting with `ON CONFLICT DO NOTHING` or checking for existence before inserting prevents errors on re-runs.\n- Never depend on data inserted by another module's seed unless you control the execution order explicitly.\n- Run `oo module:lock` after adding or modifying a seed to update the module manifest and protect file integrity in CI.\n- Mirror your migration order: seed data for a table only after the migration that creates it has been applied.\n- Avoid generating seeds with random or time-dependent values \u2014 deterministic data makes debugging and comparison across environments reliable.\n\n### Create a Seed\n\nGenerates a YAML seed file in `modules/<name>/src/seeds/` along with a test file and a `bin/seed/run.ts` runner (if not already present):\n\n```bash\noo seed:create --module user\noo seed:create --name initial-roles --module user\n```\n\n### Run Seeds\n\nExecutes seeds across all modules sequentially:\n\n```bash\noo seed:run\noo seed:run --drop # drop data before seeding\n```\n\n---\n\n## Issues\n\nIssues bridge your Linear project management board and your local codebase. Each issue is represented as a YAML file under `modules/<name>/issues/` and serves as the single source of truth for what is being built, why, and what \"done\" looks like.\n\n**Requirements:** `linear.api_key` must be set in the environment for commands that talk to Linear (`issue:pull`, `issue:push`). Add it to `modules/app/.env.yml`:\n\n```yaml\nlinear:\n api_key: lin_api_xxxxxxxxxx\n team_id: your_team_id # optional \u2014 skips the team selection prompt in issue:push\n```\n\n### Issue YAML format\n\nEvery issue file follows a consistent schema:\n\n```yaml\nid: \"OON-123\"\ntitle: \"Add password reset flow\"\nstate: \"In Progress\"\npriority: \"High\"\ndescription: |\n **Context**: Users currently have no way to recover a forgotten password.\n\n **Goal**: Implement a secure email-based password reset flow.\n\n **Acceptance Criteria**:\n - [ ] User can request a reset link via their email address\n - [ ] Link expires after 1 hour\n - [ ] Used links are invalidated immediately\n\n **Technical Notes**: Use JWT with short TTL; store a one-time token hash in the database.\nlabels:\n - \"authentication\"\n - \"security\"\ncomments:\n - author: \"Alice\"\n message: \"Make sure the token is hashed before storage, not stored in plain text.\"\n```\n\n---\n\n### Create an Issue\n\n`issue:create` scaffolds a new issue YAML locally with a generated `[A-F]{3}-[0-9]{6}` placeholder identifier. No Linear connection is required \u2014 use this when you want to define and refine an issue offline before pushing it to Linear.\n\nBy default all fields are empty; pass `--interactive` to be prompted for each one:\n\n```bash\noo issue:create # Empty skeleton in shared module\noo issue:create --title \"Add password reset\" --module user # Pre-fill title, save to user module\noo issue:create --interactive # Prompt for title, state, priority, labels, description\noo issue:create --interactive --module user # Interactive + save into modules/user/issues/\n```\n\nAfter writing the file the command optionally **improves the description with Claude** \u2014 rewrites a raw description into the structured *Context / Goal / Acceptance Criteria / Technical Notes* format and suggests labels derived from the description.\n\n---\n\n### Pull an Issue\n\n`issue:pull` fetches an existing Linear issue by its identifier and saves it as `modules/<name>/issues/<identifier>.yml`. Use this to sync a ticket into your local workspace before starting implementation.\n\n```bash\noo issue:pull # Prompt for issue ID\noo issue:pull --id OON-123 # Pull a specific issue\noo issue:pull --id OON-123 --module user # Save into modules/user/issues/\n```\n\nAfter saving the file the command optionally improves the description with Claude, the same as `issue:create`.\n\n---\n\n### Improve an Issue\n\n`/issue:improve` rewrites the description of an existing issue YAML into the structured *Context / Goal / Acceptance Criteria / Technical Notes* format, suggests labels, and optionally splits the issue into smaller focused sub-issues.\n\n```\n/issue:improve --id OON-123 --module user\n```\n\n---\n\n### Push an Issue\n\n`issue:push` reads a local YAML file and syncs it back to Linear. It detects whether the issue already exists and either **updates** it (title, description, state, priority, labels, new comments) or **creates** it from scratch in a team you select interactively.\n\n```bash\noo issue:push # Prompt for issue ID\noo issue:push --id OON-123 # Push modules/shared/issues/OON-123.yml\noo issue:push --id OON-123 --module user # Push modules/user/issues/OON-123.yml\n```\n\nWhen creating a new issue (no matching Linear issue found), the command:\n- Prompts you to select a target team\n- Resolves or creates states and labels as needed\n- Renames the local file to match the real Linear identifier once the issue is created\n\n---\n\n### Recommended Workflow\n\nThere are two natural entry points depending on whether the ticket originates in Linear or locally.\n\n#### Linear-first (existing ticket)\n\nUse this when a ticket is already created in Linear (e.g. by a product manager) and you are picking it up for implementation:\n\n```\n1. oo issue:pull --id OON-123 --module user\n \u2192 Downloads the issue YAML into modules/user/issues/OON-123.yml\n \u2192 Optionally improves the description with Claude\n\n2. oo issue:push --id OON-123 --module user\n \u2192 Pushes any local edits (description improvements, label changes, comments) back to Linear\n \u2192 Updates the state to reflect current progress (e.g. \"In Progress\" \u2192 \"In Review\")\n```\n\n#### Offline-first (new idea or local spike)\n\nUse this when you are defining a new feature locally before it exists in Linear:\n\n```\n1. oo issue:create --interactive --module user\n \u2192 Creates a YAML skeleton with a placeholder ID (e.g. ABD-042381)\n \u2192 Optionally improves the description with Claude and suggests labels\n\n2. Refine the YAML: adjust title, state, priority, description, labels.\n\n3. oo issue:push --id ABD-042381 --module user\n \u2192 Creates the issue in Linear under the team you select\n \u2192 Renames the local file to the real Linear identifier (e.g. OON-124.yml)\n```\n\n#### Day-to-day tips\n\n- **Commit issue YAMLs alongside implementation commits** \u2014 the file is the authoritative record of what was planned and why. Future reviewers and `git blame` will thank you.\n- **Use the description improvement step** \u2014 a well-structured description (Context / Goal / Acceptance Criteria) makes the issue easier to implement and review.\n- **Keep state in sync** \u2014 before marking a PR ready for review, run `issue:push` to move the Linear ticket to \"In Review\" so the board reflects reality.\n- **Never commit `linear.api_key`** \u2014 keep it in `modules/app/.env.yml` and ensure `.env.yml` is in `.gitignore`.\n\n---\n\n## Generators\n\n### AI\n\nGenerates an AI integration class in `modules/<name>/src/ai/<Name>Ai.ts`. Automatically installs `@ooneex/ai`:\n\n```bash\noo make:ai --name Chat --module user\n```\n\n**Why:** Calling LLM APIs directly from controllers or services mixes infrastructure concerns with business logic and makes it hard to swap providers. A dedicated AI class encapsulates the model, prompt strategy, and configuration in one place.\n\n**Benefits:** Provider-agnostic abstraction, centralised prompt management, easy to mock in tests, swap or upgrade models without touching business logic.\n\n**Good practices:**\n- One class per distinct AI capability (e.g. `ChatAi`, `SummarizeAi`, `ModerationAi`) \u2014 avoid a single god class.\n- Keep system prompts and model configuration inside the class, not scattered across callers.\n- Always handle rate-limit and timeout errors gracefully; never let an AI failure crash the request.\n- Log both the prompt and the response at `debug` level to simplify troubleshooting.\n\n---\n\n### Analytics\n\nGenerates an analytics handler class in `modules/<name>/src/analytics/<Name>Analytics.ts`. Automatically installs `@ooneex/analytics`:\n\n```bash\noo make:analytics --name User --module user\n```\n\n**Why:** Sprinkling raw analytics calls (PostHog, Segment, etc.) throughout controllers couples business logic to a third-party SDK. A dedicated analytics class centralises event definitions and makes it trivial to change or disable the provider.\n\n**Benefits:** Single source of truth for event names and properties, easy to stub in tests, provider can be swapped without touching controllers, events are discoverable by name.\n\n**Good practices:**\n- Name events after business actions, not UI interactions (e.g. `user.subscribed`, not `button.clicked`).\n- Define event property shapes as TypeScript types inside the class.\n- Always fire analytics asynchronously \u2014 never `await` a tracking call on the critical path.\n- Keep one analytics class per domain concept so event ownership is clear.\n\n---\n\n### Cache\n\nGenerates a cache handler class in `modules/<name>/src/cache/<Name>Cache.ts`. Automatically installs `@ooneex/cache`:\n\n```bash\noo make:cache --name User --module user\n```\n\n**Why:** Inline cache calls scattered through services create duplicated TTL values, inconsistent key formats, and make it hard to invalidate related entries. A dedicated cache class owns the key scheme and TTL policy for a given domain object.\n\n**Benefits:** Consistent key naming, single place to update TTLs, easy to add cache warming or invalidation logic, simple to disable caching during tests.\n\n**Good practices:**\n- Prefix keys with the module and entity name to avoid collisions (e.g. `user:profile:{id}`).\n- Define TTLs as named constants, not magic numbers.\n- Always invalidate or update the cache when the underlying data changes \u2014 stale reads are harder to debug than cache misses.\n- Use the cache for reads only; never store the primary copy of data in a cache.\n\n---\n\n### Controller\n\nGenerates an HTTP or WebSocket controller registered in the target module. Prompts for route name, path, and HTTP method if not provided. Automatically installs `@ooneex/controller`:\n\n```bash\noo make:controller --name UserCreate --module user\noo make:controller --name UserCreate --module user --route.name api.user.create --route.path /api/users --route.method POST\noo make:controller --name UserSocket --module user --isSocket\n```\n\n**Why:** Controllers are the entry point for all HTTP and WebSocket interactions. Generating them with a consistent structure ensures route registration, validation, and error handling are set up correctly from the start.\n\n**Benefits:** Automatic route registration in the module, consistent request/response patterns, clear separation between routing and business logic, WebSocket support out of the box.\n\n**Good practices:**\n- One controller per HTTP action (e.g. `UserCreateController`, `UserListController`) \u2014 avoid multi-action controllers.\n- Controllers should be thin: validate input, call a service, return a response. No business logic inside.\n- Prefix route names with the module (e.g. `api.user.create`) to avoid cross-module collisions.\n- Use the generated route name constant everywhere instead of hardcoding URL strings.\n\n---\n\n### Cron\n\nGenerates a cron job class in `modules/<name>/src/crons/<Name>Cron.ts` and registers it in the module. Automatically installs `@ooneex/cron`:\n\n```bash\noo make:cron --name Cleanup --module user\n```\n\n**Why:** Ad-hoc scheduled scripts outside the application are fragile, hard to monitor, and disconnected from the codebase. Cron classes live inside the module that owns the task, are registered with the DI container, and benefit from the same logging and error handling as the rest of the application.\n\n**Benefits:** Centralised schedule management, full access to injected services and repositories, observable via the application logger, easy to disable per environment.\n\n**Good practices:**\n- Name cron classes after the task, not the schedule (e.g. `ExpiredTokenCleanupCron`, not `DailyCron`).\n- Keep the cron class small \u2014 delegate actual work to a service method so the logic is testable independently.\n- Always log the start, end, and outcome of each run.\n- Make cron jobs idempotent: running the same job twice should not corrupt data.\n- Disable background jobs in the `testing` environment to keep tests fast and deterministic.\n\n---\n\n### Database\n\nGenerates a database adapter class in `modules/<name>/src/databases/<Name>Database.ts`. Automatically installs `@ooneex/database`:\n\n```bash\noo make:database --name User --module user\n```\n\n**Why:** Direct use of the ORM or raw query builder in services tightly couples business logic to the database layer. A database adapter wraps the connection and query interface, making it straightforward to configure per-module connections, switch drivers, or mock the database in tests.\n\n**Benefits:** Consistent connection configuration per module, single place to add query logging or instrumentation, easier to test services in isolation by injecting a mock adapter.\n\n**Good practices:**\n- Use the database adapter for raw queries or bulk operations that fall outside the repository pattern.\n- Never expose the raw ORM connection object outside the adapter class.\n- Configure connection pool sizes and timeouts in one place inside the adapter.\n- Prefer the repository pattern for standard CRUD; reach for the database adapter only when you need full query control.\n\n---\n\n### Docker\n\nAdds a Docker service to `modules/app/docker-compose.yml`. Creates the file if it does not exist. Available services: `postgres`, `mysql`, `mongodb`, `redis`, `rabbitmq`, `nats`, `elasticsearch`, `clickhouse`, `minio`, `memcached`, `prometheus`, `grafana`, `jaeger`, `keycloak`, `vault`, `temporal`, `libretranslate`, `maildev`:\n\n```bash\noo make:docker\noo make:docker --name postgres\noo make:docker --name redis\n```\n\n**Why:** Manually writing Docker Compose service definitions is repetitive, error-prone, and inconsistent across projects. The generator adds a pre-configured, production-ready service block so local infrastructure matches what the application expects.\n\n**Benefits:** Consistent port mappings and environment variables across the team, generated health-check and volume definitions, no need to memorise image names or versions.\n\n**Good practices:**\n- Commit `docker-compose.yml` to source control so every developer uses identical service versions.\n- Use named volumes for persistent data (databases) and anonymous volumes for ephemeral services (caches).\n- Never use Docker Compose in production \u2014 it is a local development tool only.\n- Pin image versions (e.g. `postgres:16`) rather than using `latest` to keep environments stable.\n- Add service dependencies (`depends_on`) so the application container only starts after its databases are healthy.\n\n---\n\n### Entity\n\nGenerates a TypeORM entity class in `modules/<name>/src/entities/<Name>Entity.ts` and registers it in `SharedModule`. Automatically installs `@ooneex/entity`:\n\n```bash\noo make:entity --name User --module user\noo make:entity --name User --module user --tableName users\n```\n\n**Why:** Entities are the single source of truth for your database schema. Generating them with consistent decorators and base class inheritance ensures that timestamps, soft deletes, and other cross-cutting concerns are applied uniformly across every table.\n\n**Benefits:** Automatic registration in `SharedModule`, consistent column conventions (snake_case table names, `created_at`/`updated_at` timestamps), TypeScript types aligned with the database schema.\n\n**Good practices:**\n- Always specify the table name explicitly to avoid surprises from TypeORM's pluralisation logic.\n- Keep entities as pure data structures \u2014 no business logic, no service calls inside entity methods.\n- Add database indexes to columns used in frequent `WHERE` or `ORDER BY` clauses.\n- Use enums for columns with a fixed set of values to enforce data integrity at the database level.\n- Create a migration immediately after adding or modifying an entity so schema and code stay in sync.\n\n---\n\n### Logger\n\nGenerates a logger class in `modules/<name>/src/loggers/<Name>Logger.ts`. Automatically installs `@ooneex/logger`:\n\n```bash\noo make:logger --name Audit --module user\n```\n\n**Why:** Using a global logger everywhere produces undifferentiated log output that is hard to filter by feature or severity. A dedicated logger class per domain adds a consistent context (module name, logger name) to every log entry, making logs actionable in production.\n\n**Benefits:** Structured log entries with automatic context tags, easy to route specific loggers to different backends (file, Better Stack, etc.), no need to repeat context strings across every log call.\n\n**Good practices:**\n- Use the `Audit` logger for security-sensitive actions (login, permission changes) and the default app logger for operational events.\n- Always log at the correct level: `debug` for internal state, `info` for significant business events, `warn` for recoverable problems, `error` for failures that need attention.\n- Include relevant IDs (user ID, request ID) in every log entry to enable correlation across services.\n- Never log sensitive data such as passwords, tokens, or payment details.\n\n---\n\n### Mailer\n\nGenerates a mailer class (`<Name>Mailer.ts`) and its JSX template (`<Name>MailerTemplate.tsx`) in `modules/<name>/src/mailers/`. Automatically installs `@ooneex/mailer`:\n\n```bash\noo make:mailer --name Welcome --module user\n```\n\n**Why:** Composing email HTML inline or with raw string templates is brittle and hard to preview. The generator creates a typed mailer class paired with a JSX template, keeping email logic and presentation cleanly separated and type-safe.\n\n**Benefits:** JSX template enables component reuse and design-system consistency across emails, typed mailer class prevents missing required variables, easy to test rendering without sending real emails.\n\n**Good practices:**\n- One mailer per transactional email type (e.g. `WelcomeMailer`, `PasswordResetMailer`).\n- Never send emails synchronously on the request path \u2014 enqueue them via a job or pub/sub event.\n- Always provide a plain-text fallback alongside the HTML template for clients that block images.\n- Test email rendering in multiple clients (Gmail, Outlook, Apple Mail) before deploying \u2014 CSS support varies widely.\n- Use the `testing` environment mailer backend to capture sent emails without delivering them.\n\n---\n\n### Middleware\n\nGenerates an HTTP or WebSocket middleware class registered in the target module. Automatically installs `@ooneex/middleware`:\n\n```bash\noo make:middleware --name Auth --module user\noo make:middleware --name Auth --module user --isSocket\n```\n\n**Why:** Cross-cutting concerns like authentication, CORS, request logging, and input sanitisation should not live inside controllers. Middleware classes intercept requests before they reach a controller, keeping that logic reusable and independently testable.\n\n**Benefits:** Reusable across multiple controllers within the module, auto-registered in the middleware pipeline, full access to injected services via DI, works identically for HTTP and WebSocket routes.\n\n**Good practices:**\n- Keep middleware single-purpose (e.g. `AuthMiddleware` only handles authentication, not rate limiting).\n- Always call `next()` explicitly or return a response \u2014 never leave the pipeline hanging.\n- Order matters: authentication middleware must run before authorisation middleware.\n- Avoid heavy computation in middleware; defer expensive work to the service layer.\n- Write unit tests that verify the middleware passes, blocks, and modifies requests as expected.\n\n---\n\n### Permission\n\nGenerates a permission class in `modules/<name>/src/permissions/<Name>Permission.ts`. Automatically installs `@ooneex/permission`:\n\n```bash\noo make:permission --name User --module user\n```\n\n**Why:** Scattering permission checks across controllers and services leads to inconsistency and makes auditing access control difficult. A dedicated permission class per domain centralises all access rules for that domain in one reviewable place.\n\n**Benefits:** All permissions for a domain are discoverable in a single file, easy to audit who can do what, permissions can be reused across multiple controllers without duplication, changes to access rules require touching only one class.\n\n**Good practices:**\n- Name permissions after the action and resource (e.g. `UserPermission` checks `canCreate`, `canUpdate`, `canDelete`).\n- Always check permissions in middleware or the service layer \u2014 never in the entity or repository.\n- Combine with roles (RBAC) for coarse-grained access and permissions for fine-grained control.\n- Write tests that assert both allowed and denied cases for every permission rule.\n- Never hardcode user IDs or emails inside permission logic; use roles and attributes instead.\n\n---\n\n### PubSub\n\nGenerates a pub/sub event class in `modules/<name>/src/events/<Name>Event.ts` and registers it in the module. Automatically installs `@ooneex/pub-sub`:\n\n```bash\noo make:pubsub --name UserCreated --module user\noo make:pubsub --name UserCreated --module user --channel user-created\n```\n\n**Why:** Direct calls between modules create tight coupling that makes the codebase fragile and hard to extend. Pub/sub events decouple the publisher from the subscriber: the `user` module emits `UserCreated` without knowing or caring which other modules react to it.\n\n**Benefits:** Loose coupling between modules, multiple subscribers can react to the same event independently, easy to add new reactions without modifying the publisher, events are named and typed so their contracts are explicit.\n\n**Good practices:**\n- Name events in the past tense (e.g. `UserCreated`, `OrderShipped`) to make clear they describe something that already happened.\n- Keep event payloads small and serialisable \u2014 include IDs rather than full entity objects where possible.\n- Subscribe in the module that owns the reaction, not in the module that owns the event.\n- Make event handlers idempotent: the same event may be delivered more than once in failure scenarios.\n- Log every event published and consumed to simplify debugging distributed flows.\n\n---\n\n### Repository\n\nGenerates a repository class for data access in `modules/<name>/src/repositories/<Name>Repository.ts`. Automatically installs `@ooneex/repository`:\n\n```bash\noo make:repository --name User --module user\n```\n\n**Why:** Putting database queries directly in services mixes business logic with persistence concerns and makes services impossible to test without a database. The repository pattern isolates all data-access code behind a typed interface that can be mocked in tests.\n\n**Benefits:** Services remain database-agnostic, all queries for an entity are discoverable in one class, easy to swap the underlying ORM or database without touching business logic, clean boundary for unit testing.\n\n**Good practices:**\n- One repository per entity (e.g. `UserRepository` owns all queries against the `users` table).\n- Repositories should only contain query logic \u2014 no business rules, no validation, no event publishing.\n- Use descriptive method names that reflect intent (e.g. `findActiveByEmail`, `findExpiredTokens`) rather than generic `find` with complex filter objects.\n- Return domain objects or plain data \u2014 never expose raw ORM query builders to callers.\n- Add pagination to any method that can return an unbounded number of rows.\n\n---\n\n### Service\n\nGenerates a service class in `modules/<name>/src/services/<Name>Service.ts`. Automatically installs `@ooneex/service`:\n\n```bash\noo make:service --name User --module user\n```\n\n**Why:** Business logic scattered across controllers is impossible to test, reuse, or reason about. Services are the home of all business rules, orchestrating repositories, events, and other services in a single, testable unit.\n\n**Benefits:** Business logic is testable without HTTP, reusable across multiple controllers or cron jobs, dependencies are explicit via constructor injection, easy to mock at the service boundary in integration tests.\n\n**Good practices:**\n- One service per aggregate or major business capability (e.g. `UserService` for user lifecycle, `BillingService` for payment flows).\n- Services should call repositories for data, never query the database directly.\n- Keep services stateless \u2014 all required data should come from method arguments or injected dependencies.\n- Raise typed exceptions (e.g. `UserNotFoundException`) rather than returning `null` or error codes.\n- A service method should do one thing; if a method grows beyond ~20 lines, consider extracting a helper or sub-service.\n\n---\n\n### Storage\n\nGenerates a file storage class in `modules/<name>/src/storage/<Name>Storage.ts`. Automatically installs `@ooneex/storage`:\n\n```bash\noo make:storage --name Avatar --module user\n```\n\n**Why:** Coupling file upload logic directly to a specific provider (S3, Cloudflare R2, local filesystem) makes it painful to change backends and duplicates configuration across the codebase. A storage class abstracts the provider behind a consistent interface scoped to a specific asset type.\n\n**Benefits:** Provider-agnostic uploads and reads, all storage configuration for an asset type in one class, easy to switch between local filesystem (development) and cloud storage (production) via environment variables, consistent file-naming and path conventions.\n\n**Good practices:**\n- Name storage classes after the asset they manage (e.g. `AvatarStorage`, `InvoiceStorage`).\n- Always validate file type and size before passing to the storage class \u2014 never trust client-supplied content types.\n- Generate deterministic, collision-resistant file names (e.g. `{userId}/{uuid}.{ext}`) rather than using the original filename.\n- Never store the full URL in the database \u2014 store only the path or key and derive the URL at read time so it works across environments.\n- Delete orphaned files when the associated entity is deleted to avoid unbounded storage growth.\n\n---\n\n### Vector Database\n\nGenerates a vector database class in `modules/<name>/src/databases/<Name>VectorDatabase.ts`. Automatically installs `@ooneex/rag`:\n\n```bash\noo make:vector-database --name Knowledge --module user\n```\n\n**Why:** Semantic search and Retrieval-Augmented Generation (RAG) require storing and querying high-dimensional embeddings, which relational databases are not designed for. A dedicated vector database class encapsulates the embedding model, index configuration, and similarity-search logic in one place.\n\n**Benefits:** Centralised embedding and retrieval strategy per knowledge domain, easy to swap vector backends (pgvector, Qdrant, etc.), consistent chunking and metadata conventions, decoupled from the LLM layer so both can evolve independently.\n\n**Good practices:**\n- One vector database class per knowledge domain (e.g. `KnowledgeVectorDatabase`, `ProductCatalogVectorDatabase`).\n- Always store the source document ID alongside each embedding so retrieved chunks can be traced back to their origin.\n- Use a consistent chunking strategy (fixed-size or sentence-boundary) within a class \u2014 mixing strategies pollutes the index.\n- Re-index when the embedding model changes; embeddings from different models are not comparable.\n- Cache frequently retrieved embeddings to avoid redundant model calls on hot queries.\n\n---\n\n## Claude\n\nThis project ships with a set of **Claude Code skills** \u2014 pre-built instruction sets that tell Claude exactly how to scaffold, implement, and test each type of artefact in this codebase. Skills eliminate the gap between \"generate the files\" and \"ship working code\": each skill runs the CLI generator, reads the output, completes the implementation, writes tests, and lints \u2014 all in one `/command`.\n\n### Why Skills?\n\nRunning `oo make:service` creates a skeleton. A Claude skill does that *and* completes the business logic, writes a meaningful test suite, applies coding conventions, and formats the result \u2014 turning a 10-step workflow into a single prompt.\n\n**Benefits:**\n- Consistent code quality across every artefact, regardless of who wrote it\n- Conventions (visibility modifiers, naming suffixes, DI patterns) are enforced automatically\n- Tests are generated alongside implementation, not as an afterthought\n- Skills chain together \u2014 `make:controller` automatically triggers `make:service` and `make:pubsub`\n\n### Setup\n\nBefore using skills, generate the `.claude/` directory with all skill files and the project `CLAUDE.md`:\n\n```bash\noo claude:skill:create\n```\n\nThis writes `.claude/CLAUDE.md` and one `SKILL.md` per skill under `.claude/skills/<skill-name>/`. Re-run any time you upgrade the CLI to pick up new or updated skills. Commit the generated files so every team member gets the same skill definitions without running the command themselves.\n\n### How to Use\n\nOpen Claude Code in the project root and type `/skill-name`. Claude will execute the full workflow described in the skill. You can pass arguments inline:\n\n```\n/make:service --name=UserCreate --module=user\n/make:controller --name=UserCreate --module=user --route.path=/users --route.method=POST\n/commit\n```\n\nIf you omit arguments, Claude will prompt you for the required values.\n\n> **Important:** Always run skills from the project root, not from inside a module directory.\n\n### Available Skills\n\n#### Code Quality\n\n| Skill | Description |\n|---|---|\n| `/optimize` | Enforce naming conventions, remove duplication, improve performance, and restructure tests across a module |\n| `/commit` | Analyze staged changes, group them by module, and create properly scoped conventional commits |\n\n#### Generators\n\n| Skill | Description |\n|---|---|\n| `/make:ai` | Generate an AI integration class with `run` and `runStream` methods, wired to `@ooneex/ai` |\n| `/make:analytics` | Generate an analytics handler class for tracking domain events via `@ooneex/analytics` |\n| `/make:cache` | Generate a cache handler class with key and TTL management via `@ooneex/cache` |\n| `/make:command` | Generate a CLI command class implementing `ICommand` via `@ooneex/cli` |\n| `/make:controller` | Generate an HTTP or WebSocket controller with route type, validation, roles, service, and pub/sub event |\n| `/make:cron` | Generate a cron job class registered in its module via `@ooneex/cron` |\n| `/make:database` | Generate a database adapter class for raw queries via `@ooneex/database` |\n| `/make:entity` | Generate a TypeORM entity class registered in `SharedModule` via `@ooneex/entity` |\n| `/make:logger` | Generate a structured logger class with domain context via `@ooneex/logger` |\n| `/make:mailer` | Generate a mailer class and its JSX email template via `@ooneex/mailer` |\n| `/make:middleware` | Generate an HTTP or WebSocket middleware class registered in the module via `@ooneex/middleware` |\n| `/make:permission` | Generate a permission class centralising access rules for a domain via `@ooneex/permission` |\n| `/make:pubsub` | Generate a pub/sub event class registered in the module via `@ooneex/pub-sub` |\n| `/make:repository` | Generate a repository class for typed data access via `@ooneex/repository` |\n| `/make:service` | Generate a service class implementing `IService` with business logic and tests |\n| `/make:storage` | Generate a file storage class for asset management via `@ooneex/storage` |\n| `/make:vector-database` | Generate a vector database class for semantic search and RAG via `@ooneex/rag` |\n\n#### Database\n\n| Skill | Description |\n|---|---|\n| `/migration:create` | Generate a migration file with `up`/`down` methods, index guidance, and structural tests |\n| `/seed:create` | Generate a seed class and its YAML data file with idempotent insertion logic |\n\n### Coding Conventions Enforced by Skills\n\nAll generator skills automatically apply the conventions defined in `/optimize`:\n\n- **Visibility modifiers** \u2014 every class method and property has explicit `public`, `private`, or `protected`\n- **Naming suffixes** \u2014 types end with `Type`, interfaces start with `I`\n- **Arrow functions** \u2014 used everywhere except class methods\n- **No non-null assertions** \u2014 use default values or optional types instead\n- **Dependency injection** \u2014 constructor injection via `@inject()` from `@ooneex/container`\n- **Code hygiene** \u2014 no unused imports, no dead code, no bare `TODO` comments\n\n---\n\n## Release\n\n```bash\noo make:release\n```\n\nScans every `packages/` and `modules/` directory for unreleased conventional commits and, for each one that has them, performs a full release cycle automatically:\n\n1. **Detects unreleased work** \u2014 finds the last git tag matching `<package-name>@*` and lists all conventional commits that have landed since then in that directory. Packages with no new commits are skipped.\n2. **Bumps the version** in `package.json`:\n - `minor` (e.g. `1.2.0 \u2192 1.3.0`) when any commit is of type `feat`\n - `patch` (e.g. `1.2.0 \u2192 1.2.1`) for all other types (`fix`, `refactor`, `perf`, `docs`, `chore`, \u2026)\n3. **Updates `CHANGELOG.md`** with a dated version section. Commits are grouped into standard Keep-a-Changelog categories and linked to their SHA on the remote:\n\n | Commit type | Changelog category |\n |---|---|\n | `feat` | Added |\n | `fix` | Fixed |\n | `refactor`, `perf`, `style`, `docs`, `build`, `ci`, `chore` | Changed |\n | `revert` | Removed |\n\n4. **Creates a release commit** \u2014 stages `package.json` and `CHANGELOG.md` then commits with the message `chore(release): <name>@<version>`.\n5. **Creates an annotated git tag** \u2014 `<name>@<version>` (e.g. `@acme/user@1.3.0`).\n6. **Prompts to push** \u2014 after all packages are processed, asks whether to push commits and tags to the remote. If confirmed, it also runs `bun install`, commits the updated `bun.lock`, and pushes everything.\n\n> **Note:** This command requires conventional commits (`type(scope): Subject`). Non-conventional commits are silently ignored when building the changelog.\n\n---\n\n## Scripts\n\n| Command | Description |\n|---|---|\n| `bun run fmt` | Format all source files with Biome |\n| `bun run lint` | Lint all modules with Biome and TypeScript |\n| `bun run test` | Run tests across all modules |\n| `bun run commit` | Interactive conventional commit prompt |\n";
|
|
10366
10367
|
|
|
@@ -13620,6 +13621,8 @@ Read \`modules/<module>/src/storage/<Name>Storage.ts\`, then implement:
|
|
|
13620
13621
|
|
|
13621
13622
|
\`\`\`typescript
|
|
13622
13623
|
import { Storage, decorator, StorageException } from "@ooneex/storage";
|
|
13624
|
+
import { inject } from "@ooneex/container";
|
|
13625
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
13623
13626
|
import type { S3Options } from "bun";
|
|
13624
13627
|
|
|
13625
13628
|
@decorator.storage()
|
|
@@ -13630,24 +13633,27 @@ export class <Name>Storage extends Storage {
|
|
|
13630
13633
|
private readonly endpoint: string;
|
|
13631
13634
|
private readonly region: string;
|
|
13632
13635
|
|
|
13633
|
-
constructor(
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
|
|
13638
|
-
|
|
13636
|
+
public constructor(
|
|
13637
|
+
@inject(AppEnv) private readonly env: AppEnv,
|
|
13638
|
+
options?: {
|
|
13639
|
+
accessKey?: string;
|
|
13640
|
+
secretKey?: string;
|
|
13641
|
+
endpoint?: string;
|
|
13642
|
+
region?: string;
|
|
13643
|
+
},
|
|
13644
|
+
) {
|
|
13639
13645
|
super();
|
|
13640
13646
|
|
|
13641
|
-
const accessKey = options?.accessKey ||
|
|
13642
|
-
const secretKey = options?.secretKey ||
|
|
13643
|
-
const endpoint = options?.endpoint ||
|
|
13647
|
+
const accessKey = options?.accessKey || this.env.STORAGE_<NAME_UPPER>_ACCESS_KEY;
|
|
13648
|
+
const secretKey = options?.secretKey || this.env.STORAGE_<NAME_UPPER>_SECRET_KEY;
|
|
13649
|
+
const endpoint = options?.endpoint || this.env.STORAGE_<NAME_UPPER>_ENDPOINT;
|
|
13644
13650
|
|
|
13645
13651
|
// ... validation throws StorageException if missing ...
|
|
13646
13652
|
|
|
13647
13653
|
this.accessKey = accessKey;
|
|
13648
13654
|
this.secretKey = secretKey;
|
|
13649
13655
|
this.endpoint = endpoint;
|
|
13650
|
-
this.region = options?.region ||
|
|
13656
|
+
this.region = options?.region || this.env.STORAGE_<NAME_UPPER>_REGION || "auto";
|
|
13651
13657
|
}
|
|
13652
13658
|
|
|
13653
13659
|
public getOptions(): S3Options {
|
|
@@ -14451,7 +14457,10 @@ class AppInitCommand {
|
|
|
14451
14457
|
await Bun.write(join5(destination, "biome.jsonc"), biome_jsonc_default);
|
|
14452
14458
|
await Bun.write(join5(destination, "bunfig.toml"), bunfig_toml_default);
|
|
14453
14459
|
await Bun.write(join5(destination, "nx.json"), nx_json_default);
|
|
14454
|
-
|
|
14460
|
+
const packageJsonPath = join5(destination, "package.json");
|
|
14461
|
+
if (!await Bun.file(packageJsonPath).exists()) {
|
|
14462
|
+
await Bun.write(packageJsonPath, packageContent);
|
|
14463
|
+
}
|
|
14455
14464
|
await Bun.write(join5(destination, "README.md"), README_md_default.replace(/{{NAME}}/g, kebabName));
|
|
14456
14465
|
await Bun.write(join5(destination, "tsconfig.json"), tsconfig_json_default);
|
|
14457
14466
|
await Bun.write(join5(destination, ".zed", "settings.json"), zed_settings_json_default);
|
|
@@ -14557,6 +14566,8 @@ class AppCreateCommand {
|
|
|
14557
14566
|
const dockerfileContent = Dockerfile_default.replace(/{{NAME}}/g, snakeName);
|
|
14558
14567
|
await Bun.write(join6(destination, "modules", "app", "Dockerfile"), dockerfileContent);
|
|
14559
14568
|
await Bun.write(join6(destination, "modules", "app", "var", ".gitkeep"), "");
|
|
14569
|
+
const appInitCommand = new AppInitCommand;
|
|
14570
|
+
await appInitCommand.run({ name, destination, silent: true, appType: "api" });
|
|
14560
14571
|
const addDeps = Bun.spawn([
|
|
14561
14572
|
"bun",
|
|
14562
14573
|
"add",
|
|
@@ -14587,7 +14598,7 @@ class AppCreateCommand {
|
|
|
14587
14598
|
"react-dom",
|
|
14588
14599
|
"apache-arrow",
|
|
14589
14600
|
"reflect-metadata",
|
|
14590
|
-
"typeorm"
|
|
14601
|
+
"typeorm@^1.0.0"
|
|
14591
14602
|
], { cwd: destination, stdout: "ignore", stderr: "inherit" });
|
|
14592
14603
|
await addDeps.exited;
|
|
14593
14604
|
const addDevDeps = Bun.spawn(["bun", "add", "-D", "@ooneex/command", "@ooneex/migrations", "@ooneex/seeds"], {
|
|
@@ -14596,8 +14607,14 @@ class AppCreateCommand {
|
|
|
14596
14607
|
stderr: "inherit"
|
|
14597
14608
|
});
|
|
14598
14609
|
await addDevDeps.exited;
|
|
14599
|
-
const
|
|
14600
|
-
await
|
|
14610
|
+
const rootPackagePath = join6(destination, "package.json");
|
|
14611
|
+
const rootPackage = await Bun.file(rootPackagePath).json();
|
|
14612
|
+
const templatePackage = JSON.parse(package_json_default.replace(/{{NAME}}/g, kebabName));
|
|
14613
|
+
rootPackage.scripts ??= templatePackage.scripts;
|
|
14614
|
+
rootPackage.workspaces ??= templatePackage.workspaces;
|
|
14615
|
+
rootPackage["lint-staged"] ??= templatePackage["lint-staged"];
|
|
14616
|
+
await Bun.write(rootPackagePath, `${JSON.stringify(rootPackage, null, 2)}
|
|
14617
|
+
`);
|
|
14601
14618
|
const logger = new TerminalLogger5;
|
|
14602
14619
|
logger.success(`${kebabName} created successfully at ${destination}`, undefined, {
|
|
14603
14620
|
showTimestamp: false,
|
|
@@ -96564,41 +96581,51 @@ import { decorator as decorator20 } from "@ooneex/command";
|
|
|
96564
96581
|
import { TerminalLogger as TerminalLogger19 } from "@ooneex/logger";
|
|
96565
96582
|
import { toPascalCase as toPascalCase7 } from "@ooneex/utils";
|
|
96566
96583
|
|
|
96567
|
-
// src/
|
|
96568
|
-
var
|
|
96569
|
-
|
|
96570
|
-
|
|
96571
|
-
|
|
96572
|
-
|
|
96573
|
-
|
|
96574
|
-
|
|
96575
|
-
|
|
96576
|
-
test("should have 'getSource' method", () => {
|
|
96577
|
-
expect({{NAME}}Database.prototype.getSource).toBeDefined();
|
|
96578
|
-
expect(typeof {{NAME}}Database.prototype.getSource).toBe("function");
|
|
96584
|
+
// src/prompts/askDatabaseType.ts
|
|
96585
|
+
var import_enquirer11 = __toESM(require_enquirer(), 1);
|
|
96586
|
+
var askDatabaseType = async (config) => {
|
|
96587
|
+
const response = await import_enquirer11.prompt({
|
|
96588
|
+
type: "select",
|
|
96589
|
+
name: "type",
|
|
96590
|
+
message: config.message,
|
|
96591
|
+
choices: ["postgres", "sqlite"]
|
|
96579
96592
|
});
|
|
96580
|
-
|
|
96581
|
-
|
|
96593
|
+
return response.type;
|
|
96594
|
+
};
|
|
96582
96595
|
|
|
96583
|
-
// src/templates/database.txt
|
|
96584
|
-
var
|
|
96596
|
+
// src/templates/database.pg.txt
|
|
96597
|
+
var database_pg_default = `import { DataSource } from "typeorm";
|
|
96585
96598
|
import { TypeormDatabase, DatabaseException, decorator } from "@ooneex/database";
|
|
96599
|
+
import { inject } from "@ooneex/container";
|
|
96600
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
96586
96601
|
|
|
96587
96602
|
@decorator.database()
|
|
96588
96603
|
export class {{NAME}}Database extends TypeormDatabase {
|
|
96589
|
-
public
|
|
96590
|
-
|
|
96604
|
+
public constructor(@inject(AppEnv) private readonly env: AppEnv) {
|
|
96605
|
+
super();
|
|
96606
|
+
}
|
|
96607
|
+
|
|
96608
|
+
public getSource(_database?: string): DataSource {
|
|
96609
|
+
const url = this.env.DATABASE_URL ?? "";
|
|
96610
|
+
|
|
96611
|
+
if (!url) {
|
|
96612
|
+
throw new DatabaseException(
|
|
96613
|
+
"Database URL is required. Please provide a URL either through the constructor options or set the DATABASE_URL environment variable.",
|
|
96614
|
+
"CONNECTION_FAILED",
|
|
96615
|
+
);
|
|
96616
|
+
}
|
|
96591
96617
|
|
|
96592
96618
|
this.source = new DataSource({
|
|
96593
96619
|
synchronize: false,
|
|
96594
96620
|
entities: [
|
|
96595
96621
|
// TODO: Load your entities here
|
|
96596
96622
|
],
|
|
96597
|
-
|
|
96598
|
-
|
|
96599
|
-
|
|
96600
|
-
|
|
96601
|
-
|
|
96623
|
+
extra: {
|
|
96624
|
+
max: 10,
|
|
96625
|
+
// idleTimeoutMillis: 30000,
|
|
96626
|
+
},
|
|
96627
|
+
url,
|
|
96628
|
+
type: "postgres",
|
|
96602
96629
|
});
|
|
96603
96630
|
|
|
96604
96631
|
return this.source;
|
|
@@ -96606,6 +96633,62 @@ export class {{NAME}}Database extends TypeormDatabase {
|
|
|
96606
96633
|
}
|
|
96607
96634
|
`;
|
|
96608
96635
|
|
|
96636
|
+
// src/templates/database.sqlite.txt
|
|
96637
|
+
var database_sqlite_default = `import { DataSource } from "typeorm";
|
|
96638
|
+
import { TypeormDatabase, DatabaseException, decorator } from "@ooneex/database";
|
|
96639
|
+
import { inject } from "@ooneex/container";
|
|
96640
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
96641
|
+
|
|
96642
|
+
@decorator.database()
|
|
96643
|
+
export class {{NAME}}Database extends TypeormDatabase {
|
|
96644
|
+
public constructor(@inject(AppEnv) private readonly env: AppEnv) {
|
|
96645
|
+
super();
|
|
96646
|
+
}
|
|
96647
|
+
|
|
96648
|
+
public getSource(database?: string): DataSource {
|
|
96649
|
+
database = database || this.env.SQLITE_DATABASE_PATH || "var/db";
|
|
96650
|
+
|
|
96651
|
+
if (!database) {
|
|
96652
|
+
throw new DatabaseException(
|
|
96653
|
+
"SQLite database path is required. Please provide a database path either through the constructor options or set the SQLITE_DATABASE_PATH environment variable.",
|
|
96654
|
+
"CONNECTION_FAILED",
|
|
96655
|
+
);
|
|
96656
|
+
}
|
|
96657
|
+
|
|
96658
|
+
if (!this.source) {
|
|
96659
|
+
this.source = new DataSource({
|
|
96660
|
+
synchronize: false,
|
|
96661
|
+
entities: [
|
|
96662
|
+
// TODO: Load your entities here
|
|
96663
|
+
],
|
|
96664
|
+
enableWAL: true,
|
|
96665
|
+
timeout: 30_000,
|
|
96666
|
+
database,
|
|
96667
|
+
type: "better-sqlite3",
|
|
96668
|
+
});
|
|
96669
|
+
}
|
|
96670
|
+
|
|
96671
|
+
return this.source;
|
|
96672
|
+
}
|
|
96673
|
+
}
|
|
96674
|
+
`;
|
|
96675
|
+
|
|
96676
|
+
// src/templates/database.test.txt
|
|
96677
|
+
var database_test_default = `import { describe, expect, test } from "bun:test";
|
|
96678
|
+
import { {{NAME}}Database } from "@module/{{MODULE}}/databases/{{NAME}}Database";
|
|
96679
|
+
|
|
96680
|
+
describe("{{NAME}}Database", () => {
|
|
96681
|
+
test("should have class name ending with 'Database'", () => {
|
|
96682
|
+
expect({{NAME}}Database.name.endsWith("Database")).toBe(true);
|
|
96683
|
+
});
|
|
96684
|
+
|
|
96685
|
+
test("should have 'getSource' method", () => {
|
|
96686
|
+
expect({{NAME}}Database.prototype.getSource).toBeDefined();
|
|
96687
|
+
expect(typeof {{NAME}}Database.prototype.getSource).toBe("function");
|
|
96688
|
+
});
|
|
96689
|
+
});
|
|
96690
|
+
`;
|
|
96691
|
+
|
|
96609
96692
|
// src/commands/MakeDatabaseCommand.ts
|
|
96610
96693
|
class MakeDatabaseCommand {
|
|
96611
96694
|
getName() {
|
|
@@ -96620,7 +96703,9 @@ class MakeDatabaseCommand {
|
|
|
96620
96703
|
name = await askName({ message: "Enter database name" });
|
|
96621
96704
|
}
|
|
96622
96705
|
name = toPascalCase7(name).replace(/DatabaseAdapter$/, "").replace(/Database$/, "");
|
|
96623
|
-
const
|
|
96706
|
+
const dbType = await askDatabaseType({ message: "Select database type" });
|
|
96707
|
+
const template = dbType === "postgres" ? database_pg_default : database_sqlite_default;
|
|
96708
|
+
const content = template.replace(/{{NAME}}/g, name);
|
|
96624
96709
|
await ensureModule(module);
|
|
96625
96710
|
const base = join20("modules", module);
|
|
96626
96711
|
const databaseLocalDir = join20(base, "src", "databases");
|
|
@@ -96667,7 +96752,7 @@ import { TerminalLogger as TerminalLogger20 } from "@ooneex/logger";
|
|
|
96667
96752
|
var {YAML } = globalThis.Bun;
|
|
96668
96753
|
|
|
96669
96754
|
// src/prompts/askDockerService.ts
|
|
96670
|
-
var
|
|
96755
|
+
var import_enquirer12 = __toESM(require_enquirer(), 1);
|
|
96671
96756
|
var DOCKER_SERVICES = [
|
|
96672
96757
|
"clickhouse",
|
|
96673
96758
|
"elasticsearch",
|
|
@@ -96689,7 +96774,7 @@ var DOCKER_SERVICES = [
|
|
|
96689
96774
|
"vault"
|
|
96690
96775
|
];
|
|
96691
96776
|
var askDockerService = async (config) => {
|
|
96692
|
-
const response = await
|
|
96777
|
+
const response = await import_enquirer12.prompt({
|
|
96693
96778
|
type: "autocomplete",
|
|
96694
96779
|
name: "service",
|
|
96695
96780
|
message: config.message,
|
|
@@ -98673,759 +98758,10 @@ class MakeRepositoryCommand {
|
|
|
98673
98758
|
MakeRepositoryCommand = __legacyDecorateClassTS([
|
|
98674
98759
|
decorator29.command()
|
|
98675
98760
|
], MakeRepositoryCommand);
|
|
98676
|
-
// src/commands/
|
|
98677
|
-
import { join as join32 } from "path";
|
|
98678
|
-
import { decorator as decorator32 } from "@ooneex/command";
|
|
98679
|
-
var {Glob } = globalThis.Bun;
|
|
98680
|
-
|
|
98681
|
-
// src/templates/resources/book/BookEntity.txt
|
|
98682
|
-
var BookEntity_default = `import type { LocaleType } from "@ooneex/translation";
|
|
98683
|
-
import { random } from "@ooneex/utils";
|
|
98684
|
-
import {
|
|
98685
|
-
Column,
|
|
98686
|
-
CreateDateColumn,
|
|
98687
|
-
Entity,
|
|
98688
|
-
PrimaryColumn,
|
|
98689
|
-
UpdateDateColumn,
|
|
98690
|
-
} from "typeorm";
|
|
98691
|
-
|
|
98692
|
-
@Entity({
|
|
98693
|
-
name: "books",
|
|
98694
|
-
})
|
|
98695
|
-
export class BookEntity {
|
|
98696
|
-
@PrimaryColumn({ name: "id", type: "varchar", length: 25, nullable: false })
|
|
98697
|
-
id: string = random.id();
|
|
98698
|
-
|
|
98699
|
-
@Column({ name: "title", type: "varchar", length: 255, nullable: false })
|
|
98700
|
-
title: string;
|
|
98701
|
-
|
|
98702
|
-
@Column({ name: "color", type: "varchar", length: 50, nullable: true })
|
|
98703
|
-
color?: string | null;
|
|
98704
|
-
|
|
98705
|
-
@Column({ name: "description", type: "text", nullable: true })
|
|
98706
|
-
description?: string | null;
|
|
98707
|
-
|
|
98708
|
-
@Column({ name: "summarize", type: "text", nullable: true })
|
|
98709
|
-
summarize?: string | null;
|
|
98710
|
-
|
|
98711
|
-
@Column({ name: "page_count", type: "int", nullable: true })
|
|
98712
|
-
pageCount?: number | null;
|
|
98713
|
-
|
|
98714
|
-
@Column({ name: "src", type: "varchar", length: 255, nullable: false })
|
|
98715
|
-
src: string;
|
|
98716
|
-
|
|
98717
|
-
@Column({ name: "cover_image", type: "varchar", length: 255, nullable: true })
|
|
98718
|
-
coverImage?: string | null;
|
|
98719
|
-
|
|
98720
|
-
@Column({ name: "tags", type: "text", array: true, nullable: true })
|
|
98721
|
-
tags?: string[] | null;
|
|
98722
|
-
|
|
98723
|
-
@Column({ name: "topics", type: "text", array: true, nullable: true })
|
|
98724
|
-
topics?: string[] | null;
|
|
98725
|
-
|
|
98726
|
-
@Column({ name: "categories", type: "text", array: true, nullable: true })
|
|
98727
|
-
categories?: string[] | null;
|
|
98728
|
-
|
|
98729
|
-
@Column({ name: "lang", type: "varchar", length: 10, nullable: true })
|
|
98730
|
-
lang?: LocaleType | null;
|
|
98731
|
-
|
|
98732
|
-
@Column({ name: "status", type: "varchar", length: 50, nullable: true })
|
|
98733
|
-
status?: string | null;
|
|
98734
|
-
|
|
98735
|
-
@CreateDateColumn({ name: "created_at", nullable: true })
|
|
98736
|
-
createdAt?: Date | null;
|
|
98737
|
-
|
|
98738
|
-
@UpdateDateColumn({ name: "updated_at", nullable: true })
|
|
98739
|
-
updatedAt?: Date | null;
|
|
98740
|
-
}
|
|
98741
|
-
`;
|
|
98742
|
-
|
|
98743
|
-
// src/templates/resources/book/BookMigration.txt
|
|
98744
|
-
var BookMigration_default = `import { decorator, type IMigration, type MigrationClassType } from '@ooneex/migrations';
|
|
98745
|
-
import type { TransactionSQL } from 'bun';
|
|
98746
|
-
|
|
98747
|
-
@decorator.migration()
|
|
98748
|
-
export class {{ name }} implements IMigration {
|
|
98749
|
-
public async up(tx: TransactionSQL): Promise<void> {
|
|
98750
|
-
await tx\`
|
|
98751
|
-
CREATE TABLE IF NOT EXISTS books (
|
|
98752
|
-
id VARCHAR(25) PRIMARY KEY,
|
|
98753
|
-
title VARCHAR(255) NOT NULL,
|
|
98754
|
-
color VARCHAR(50),
|
|
98755
|
-
description TEXT,
|
|
98756
|
-
summarize TEXT,
|
|
98757
|
-
page_count INT,
|
|
98758
|
-
src VARCHAR(255) NOT NULL,
|
|
98759
|
-
cover_image VARCHAR(255),
|
|
98760
|
-
tags TEXT[],
|
|
98761
|
-
topics TEXT[],
|
|
98762
|
-
categories TEXT[],
|
|
98763
|
-
lang VARCHAR(10),
|
|
98764
|
-
status VARCHAR(50),
|
|
98765
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
98766
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
98767
|
-
)
|
|
98768
|
-
\`;
|
|
98769
|
-
|
|
98770
|
-
await tx\`
|
|
98771
|
-
CREATE INDEX IF NOT EXISTS idx_books_title ON books (title)
|
|
98772
|
-
\`;
|
|
98773
|
-
}
|
|
98774
|
-
|
|
98775
|
-
public async down(tx: TransactionSQL): Promise<void> {
|
|
98776
|
-
await tx\`DROP TABLE IF EXISTS books\`;
|
|
98777
|
-
}
|
|
98778
|
-
|
|
98779
|
-
public getVersion(): string {
|
|
98780
|
-
return '{{ version }}';
|
|
98781
|
-
}
|
|
98782
|
-
|
|
98783
|
-
public getDependencies(): MigrationClassType[] {
|
|
98784
|
-
return [];
|
|
98785
|
-
}
|
|
98786
|
-
}
|
|
98787
|
-
`;
|
|
98788
|
-
|
|
98789
|
-
// src/templates/resources/book/BookRepository.txt
|
|
98790
|
-
var BookRepository_default = `import { inject } from "@ooneex/container";
|
|
98791
|
-
import type { ITypeormDatabase } from "@ooneex/database";
|
|
98792
|
-
import { decorator } from "@ooneex/repository";
|
|
98793
|
-
import type { FilterResultType } from "@ooneex/types";
|
|
98794
|
-
import type { FindManyOptions, FindOptionsWhere, Repository, SaveOptions, UpdateResult } from "typeorm";
|
|
98795
|
-
import { ILike } from "typeorm";
|
|
98796
|
-
import { BookEntity } from "../entities/BookEntity";
|
|
98797
|
-
|
|
98798
|
-
@decorator.repository()
|
|
98799
|
-
export class BookRepository {
|
|
98800
|
-
constructor(
|
|
98801
|
-
@inject("database")
|
|
98802
|
-
private readonly database: ITypeormDatabase,
|
|
98803
|
-
) {}
|
|
98804
|
-
|
|
98805
|
-
public async open(): Promise<Repository<BookEntity>> {
|
|
98806
|
-
return await this.database.open(BookEntity);
|
|
98807
|
-
}
|
|
98808
|
-
|
|
98809
|
-
public async close(): Promise<void> {
|
|
98810
|
-
await this.database.close();
|
|
98811
|
-
}
|
|
98812
|
-
|
|
98813
|
-
public async find(
|
|
98814
|
-
criteria: FindManyOptions<BookEntity> & { page?: number; limit?: number; order?: "ASC" | "DESC"; orderBy?: string; q?: string },
|
|
98815
|
-
): Promise<FilterResultType<BookEntity>> {
|
|
98816
|
-
const repository = await this.open();
|
|
98817
|
-
|
|
98818
|
-
const { page = 1, limit = 100, order, orderBy, q, ...rest } = criteria;
|
|
98819
|
-
|
|
98820
|
-
let skip: number | undefined;
|
|
98821
|
-
const take = limit === 0 ? 100 : limit;
|
|
98822
|
-
|
|
98823
|
-
if (page && page > 0 && limit && limit > 0) {
|
|
98824
|
-
skip = (page - 1) * take;
|
|
98825
|
-
}
|
|
98826
|
-
|
|
98827
|
-
let findOptions = {
|
|
98828
|
-
...rest,
|
|
98829
|
-
take,
|
|
98830
|
-
...(skip !== undefined && { skip }),
|
|
98831
|
-
...(orderBy && { order: { [orderBy]: order ?? "ASC" } }),
|
|
98832
|
-
};
|
|
98833
|
-
if (q) {
|
|
98834
|
-
findOptions = {
|
|
98835
|
-
...findOptions,
|
|
98836
|
-
where: {
|
|
98837
|
-
...rest.where,
|
|
98838
|
-
title: ILike(\`%\${q}%\`),
|
|
98839
|
-
},
|
|
98840
|
-
};
|
|
98841
|
-
}
|
|
98842
|
-
|
|
98843
|
-
const result = await repository.find(findOptions);
|
|
98844
|
-
|
|
98845
|
-
let countWhere = rest.where;
|
|
98846
|
-
if (q) {
|
|
98847
|
-
countWhere = {
|
|
98848
|
-
...rest.where,
|
|
98849
|
-
title: ILike(\`%\${q}%\`),
|
|
98850
|
-
};
|
|
98851
|
-
}
|
|
98852
|
-
|
|
98853
|
-
const total = await this.count(countWhere);
|
|
98854
|
-
const totalPages = Math.ceil(total / limit);
|
|
98855
|
-
|
|
98856
|
-
return {
|
|
98857
|
-
resources: result,
|
|
98858
|
-
total,
|
|
98859
|
-
totalPages,
|
|
98860
|
-
page,
|
|
98861
|
-
limit,
|
|
98862
|
-
};
|
|
98863
|
-
}
|
|
98864
|
-
|
|
98865
|
-
public async findOne(id: string): Promise<BookEntity | null> {
|
|
98866
|
-
const repository = await this.open();
|
|
98867
|
-
|
|
98868
|
-
return await repository.findOne({
|
|
98869
|
-
where: { id },
|
|
98870
|
-
});
|
|
98871
|
-
}
|
|
98872
|
-
|
|
98873
|
-
public async findOneBy(criteria: FindOptionsWhere<BookEntity>): Promise<BookEntity | null> {
|
|
98874
|
-
const repository = await this.open();
|
|
98875
|
-
|
|
98876
|
-
return await repository.findOne({
|
|
98877
|
-
where: criteria,
|
|
98878
|
-
});
|
|
98879
|
-
}
|
|
98880
|
-
|
|
98881
|
-
public async create(entity: BookEntity, options?: SaveOptions): Promise<BookEntity> {
|
|
98882
|
-
const repository = await this.open();
|
|
98883
|
-
|
|
98884
|
-
return await repository.save(entity, options);
|
|
98885
|
-
}
|
|
98886
|
-
|
|
98887
|
-
public async createMany(entities: BookEntity[], options?: SaveOptions): Promise<BookEntity[]> {
|
|
98888
|
-
const repository = await this.open();
|
|
98889
|
-
|
|
98890
|
-
return await repository.save(entities, options);
|
|
98891
|
-
}
|
|
98892
|
-
|
|
98893
|
-
public async update(entity: Partial<BookEntity> & { id: string }): Promise<UpdateResult> {
|
|
98894
|
-
const repository = await this.open();
|
|
98895
|
-
|
|
98896
|
-
return await repository.update(entity.id, entity);
|
|
98897
|
-
}
|
|
98898
|
-
|
|
98899
|
-
public async updateMany(entities: (Partial<BookEntity> & { id: string })[]): Promise<UpdateResult[]> {
|
|
98900
|
-
const repository = await this.open();
|
|
98901
|
-
|
|
98902
|
-
return await Promise.all(entities.map((entity) => repository.update(entity.id, entity)));
|
|
98903
|
-
}
|
|
98904
|
-
|
|
98905
|
-
public async delete(
|
|
98906
|
-
criteria: FindOptionsWhere<BookEntity> | FindOptionsWhere<BookEntity>[],
|
|
98907
|
-
): Promise<UpdateResult> {
|
|
98908
|
-
const repository = await this.open();
|
|
98909
|
-
|
|
98910
|
-
return await repository.softDelete(criteria);
|
|
98911
|
-
}
|
|
98912
|
-
|
|
98913
|
-
public async count(criteria?: FindOptionsWhere<BookEntity> | FindOptionsWhere<BookEntity>[]): Promise<number> {
|
|
98914
|
-
const repository = await this.open();
|
|
98915
|
-
|
|
98916
|
-
return await repository.count(criteria ? { where: criteria } : {});
|
|
98917
|
-
}
|
|
98918
|
-
}
|
|
98919
|
-
`;
|
|
98920
|
-
|
|
98921
|
-
// src/templates/resources/book/controllers/CreateBookController.txt
|
|
98922
|
-
var CreateBookController_default = `import type { ContextType } from "@ooneex/controller";
|
|
98923
|
-
import { inject } from "@ooneex/container";
|
|
98924
|
-
import { ERole } from "@ooneex/role";
|
|
98925
|
-
import { Route } from "@ooneex/routing";
|
|
98926
|
-
import type { LocaleType } from "@ooneex/translation";
|
|
98927
|
-
import { Assert } from "@ooneex/validation";
|
|
98928
|
-
import type { BookEntity } from "../entities/BookEntity";
|
|
98929
|
-
import { CreateBookService } from "../services/CreateBookService";
|
|
98930
|
-
|
|
98931
|
-
type CreateBookRouteType = {
|
|
98932
|
-
payload: {
|
|
98933
|
-
title: string;
|
|
98934
|
-
color?: string;
|
|
98935
|
-
description?: string;
|
|
98936
|
-
summarize?: string;
|
|
98937
|
-
pageCount?: number;
|
|
98938
|
-
src: string;
|
|
98939
|
-
coverImage?: string;
|
|
98940
|
-
tags?: string[];
|
|
98941
|
-
topics?: string[];
|
|
98942
|
-
categories?: string[];
|
|
98943
|
-
lang?: LocaleType;
|
|
98944
|
-
status?: string;
|
|
98945
|
-
};
|
|
98946
|
-
response: BookEntity | Record<string, never>;
|
|
98947
|
-
};
|
|
98948
|
-
|
|
98949
|
-
@Route.post("/books", {
|
|
98950
|
-
name: "book.create",
|
|
98951
|
-
version: 1,
|
|
98952
|
-
description: "Create a new book",
|
|
98953
|
-
payload: Assert({
|
|
98954
|
-
title: "string",
|
|
98955
|
-
color: "string?",
|
|
98956
|
-
description: "string?",
|
|
98957
|
-
summarize: "string?",
|
|
98958
|
-
pageCount: "number?",
|
|
98959
|
-
src: "string",
|
|
98960
|
-
coverImage: "string?",
|
|
98961
|
-
tags: "string[]?",
|
|
98962
|
-
topics: "string[]?",
|
|
98963
|
-
categories: "string[]?",
|
|
98964
|
-
lang: "string?",
|
|
98965
|
-
status: "string?",
|
|
98966
|
-
}),
|
|
98967
|
-
response: Assert({
|
|
98968
|
-
id: "string",
|
|
98969
|
-
title: "string",
|
|
98970
|
-
color: "string?",
|
|
98971
|
-
description: "string?",
|
|
98972
|
-
summarize: "string?",
|
|
98973
|
-
pageCount: "number?",
|
|
98974
|
-
src: "string",
|
|
98975
|
-
coverImage: "string?",
|
|
98976
|
-
tags: "string[]?",
|
|
98977
|
-
topics: "string[]?",
|
|
98978
|
-
categories: "string[]?",
|
|
98979
|
-
lang: "string?",
|
|
98980
|
-
status: "string?",
|
|
98981
|
-
}),
|
|
98982
|
-
roles: ["ROLE_USER"],
|
|
98983
|
-
})
|
|
98984
|
-
export class CreateBookController {
|
|
98985
|
-
constructor(
|
|
98986
|
-
@inject(CreateBookService) private readonly service: CreateBookService,
|
|
98987
|
-
) {}
|
|
98988
|
-
|
|
98989
|
-
public async index(context: ContextType<CreateBookRouteType>) {
|
|
98990
|
-
const { title, color, description, summarize, pageCount, src, coverImage, tags, topics, categories, lang, status } = context.payload;
|
|
98991
|
-
|
|
98992
|
-
const book = await this.service.execute({ title, color, description, summarize, pageCount, src, coverImage, tags, topics, categories, lang, status });
|
|
98993
|
-
|
|
98994
|
-
return context.response.json(book || {});
|
|
98995
|
-
}
|
|
98996
|
-
}
|
|
98997
|
-
`;
|
|
98998
|
-
|
|
98999
|
-
// src/templates/resources/book/controllers/DeleteBookController.txt
|
|
99000
|
-
var DeleteBookController_default = `import type { ContextType } from "@ooneex/controller";
|
|
99001
|
-
import { inject } from "@ooneex/container";
|
|
99002
|
-
import { ERole } from "@ooneex/role";
|
|
99003
|
-
import { Route } from "@ooneex/routing";
|
|
99004
|
-
import { Assert } from "@ooneex/validation";
|
|
99005
|
-
import { DeleteBookService } from "../services/DeleteBookService";
|
|
99006
|
-
|
|
99007
|
-
type DeleteBookRouteType = {
|
|
99008
|
-
params: { id: string };
|
|
99009
|
-
response: { id: string };
|
|
99010
|
-
};
|
|
99011
|
-
|
|
99012
|
-
@Route.delete("/books/:id", {
|
|
99013
|
-
name: "book.delete",
|
|
99014
|
-
version: 1,
|
|
99015
|
-
description: "Delete a book",
|
|
99016
|
-
params: {
|
|
99017
|
-
id: Assert("string"),
|
|
99018
|
-
},
|
|
99019
|
-
response: Assert({
|
|
99020
|
-
id: "string",
|
|
99021
|
-
}),
|
|
99022
|
-
roles: ["ROLE_USER"],
|
|
99023
|
-
})
|
|
99024
|
-
export class DeleteBookController {
|
|
99025
|
-
constructor(
|
|
99026
|
-
@inject(DeleteBookService) private readonly service: DeleteBookService,
|
|
99027
|
-
) {}
|
|
99028
|
-
|
|
99029
|
-
public async index(context: ContextType<DeleteBookRouteType>) {
|
|
99030
|
-
const { id } = context.params;
|
|
99031
|
-
|
|
99032
|
-
await this.service.execute({ id });
|
|
99033
|
-
|
|
99034
|
-
return context.response.json({ id });
|
|
99035
|
-
}
|
|
99036
|
-
}
|
|
99037
|
-
`;
|
|
99038
|
-
|
|
99039
|
-
// src/templates/resources/book/controllers/GetBookController.txt
|
|
99040
|
-
var GetBookController_default = `import type { ContextType } from "@ooneex/controller";
|
|
99041
|
-
import { inject } from "@ooneex/container";
|
|
99042
|
-
import { ERole } from "@ooneex/role";
|
|
99043
|
-
import { Route } from "@ooneex/routing";
|
|
99044
|
-
import { Assert } from "@ooneex/validation";
|
|
99045
|
-
import type { BookEntity } from "../entities/BookEntity";
|
|
99046
|
-
import { GetBookService } from "../services/GetBookService";
|
|
99047
|
-
|
|
99048
|
-
type GetBookRouteType = {
|
|
99049
|
-
params: { id: string };
|
|
99050
|
-
response: BookEntity | Record<string, never>;
|
|
99051
|
-
};
|
|
99052
|
-
|
|
99053
|
-
@Route.get("/books/:id", {
|
|
99054
|
-
name: "book.get",
|
|
99055
|
-
version: 1,
|
|
99056
|
-
description: "Get a book by id",
|
|
99057
|
-
params: {
|
|
99058
|
-
id: Assert("string"),
|
|
99059
|
-
},
|
|
99060
|
-
roles: ["ROLE_USER"],
|
|
99061
|
-
})
|
|
99062
|
-
export class GetBookController {
|
|
99063
|
-
constructor(
|
|
99064
|
-
@inject(GetBookService) private readonly service: GetBookService,
|
|
99065
|
-
) {}
|
|
99066
|
-
|
|
99067
|
-
public async index(context: ContextType<GetBookRouteType>) {
|
|
99068
|
-
const { id } = context.params;
|
|
99069
|
-
|
|
99070
|
-
const book = await this.service.execute({ id });
|
|
99071
|
-
|
|
99072
|
-
return context.response.json(book || {});
|
|
99073
|
-
}
|
|
99074
|
-
}
|
|
99075
|
-
`;
|
|
99076
|
-
|
|
99077
|
-
// src/templates/resources/book/controllers/ListBooksController.txt
|
|
99078
|
-
var ListBooksController_default = `import type { ContextType } from "@ooneex/controller";
|
|
99079
|
-
import { inject } from "@ooneex/container";
|
|
99080
|
-
import { ERole } from "@ooneex/role";
|
|
99081
|
-
import { Route } from "@ooneex/routing";
|
|
99082
|
-
import type { FilterResultType } from "@ooneex/types";
|
|
99083
|
-
import { Assert } from "@ooneex/validation";
|
|
99084
|
-
import type { BookEntity } from "../entities/BookEntity";
|
|
99085
|
-
import { ListBooksService } from "../services/ListBooksService";
|
|
99086
|
-
|
|
99087
|
-
type ListBooksRouteType = {
|
|
99088
|
-
queries: { page?: number; limit?: number; q?: string };
|
|
99089
|
-
response: FilterResultType<BookEntity>;
|
|
99090
|
-
};
|
|
99091
|
-
|
|
99092
|
-
@Route.get("/books", {
|
|
99093
|
-
name: "book.list",
|
|
99094
|
-
version: 1,
|
|
99095
|
-
description: "List all books",
|
|
99096
|
-
queries: Assert({
|
|
99097
|
-
page: "number?",
|
|
99098
|
-
limit: "number?",
|
|
99099
|
-
q: "string?",
|
|
99100
|
-
}),
|
|
99101
|
-
roles: ["ROLE_USER"],
|
|
99102
|
-
})
|
|
99103
|
-
export class ListBooksController {
|
|
99104
|
-
constructor(
|
|
99105
|
-
@inject(ListBooksService) private readonly service: ListBooksService,
|
|
99106
|
-
) {}
|
|
99107
|
-
|
|
99108
|
-
public async index(context: ContextType<ListBooksRouteType>) {
|
|
99109
|
-
const { page, limit, q } = context.queries;
|
|
99110
|
-
|
|
99111
|
-
const result = await this.service.execute({ page, limit, q });
|
|
99112
|
-
|
|
99113
|
-
return context.response.json(result);
|
|
99114
|
-
}
|
|
99115
|
-
}
|
|
99116
|
-
`;
|
|
99117
|
-
|
|
99118
|
-
// src/templates/resources/book/controllers/UpdateBookController.txt
|
|
99119
|
-
var UpdateBookController_default = `import type { ContextType } from "@ooneex/controller";
|
|
99120
|
-
import { inject } from "@ooneex/container";
|
|
99121
|
-
import { ERole } from "@ooneex/role";
|
|
99122
|
-
import { Route } from "@ooneex/routing";
|
|
99123
|
-
import type { LocaleType } from "@ooneex/translation";
|
|
99124
|
-
import { Assert } from "@ooneex/validation";
|
|
99125
|
-
import type { BookEntity } from "../entities/BookEntity";
|
|
99126
|
-
import { UpdateBookService } from "../services/UpdateBookService";
|
|
99127
|
-
|
|
99128
|
-
type UpdateBookRouteType = {
|
|
99129
|
-
params: { id: string };
|
|
99130
|
-
payload: {
|
|
99131
|
-
title?: string;
|
|
99132
|
-
color?: string;
|
|
99133
|
-
description?: string;
|
|
99134
|
-
summarize?: string;
|
|
99135
|
-
pageCount?: number;
|
|
99136
|
-
src?: string;
|
|
99137
|
-
coverImage?: string;
|
|
99138
|
-
tags?: string[];
|
|
99139
|
-
topics?: string[];
|
|
99140
|
-
categories?: string[];
|
|
99141
|
-
lang?: LocaleType;
|
|
99142
|
-
status?: string;
|
|
99143
|
-
};
|
|
99144
|
-
response: BookEntity | Record<string, never>;
|
|
99145
|
-
};
|
|
99146
|
-
|
|
99147
|
-
@Route.patch("/books/:id", {
|
|
99148
|
-
name: "book.update",
|
|
99149
|
-
version: 1,
|
|
99150
|
-
description: "Update a book",
|
|
99151
|
-
params: {
|
|
99152
|
-
id: Assert("string"),
|
|
99153
|
-
},
|
|
99154
|
-
payload: Assert({
|
|
99155
|
-
title: "string?",
|
|
99156
|
-
color: "string?",
|
|
99157
|
-
description: "string?",
|
|
99158
|
-
summarize: "string?",
|
|
99159
|
-
pageCount: "number?",
|
|
99160
|
-
src: "string?",
|
|
99161
|
-
coverImage: "string?",
|
|
99162
|
-
tags: "string[]?",
|
|
99163
|
-
topics: "string[]?",
|
|
99164
|
-
categories: "string[]?",
|
|
99165
|
-
lang: "string?",
|
|
99166
|
-
status: "string?",
|
|
99167
|
-
}),
|
|
99168
|
-
response: Assert({
|
|
99169
|
-
id: "string",
|
|
99170
|
-
title: "string",
|
|
99171
|
-
color: "string?",
|
|
99172
|
-
description: "string?",
|
|
99173
|
-
summarize: "string?",
|
|
99174
|
-
pageCount: "number?",
|
|
99175
|
-
src: "string",
|
|
99176
|
-
coverImage: "string?",
|
|
99177
|
-
tags: "string[]?",
|
|
99178
|
-
topics: "string[]?",
|
|
99179
|
-
categories: "string[]?",
|
|
99180
|
-
lang: "string?",
|
|
99181
|
-
status: "string?",
|
|
99182
|
-
}),
|
|
99183
|
-
roles: ["ROLE_USER"],
|
|
99184
|
-
})
|
|
99185
|
-
export class UpdateBookController {
|
|
99186
|
-
constructor(
|
|
99187
|
-
@inject(UpdateBookService) private readonly service: UpdateBookService,
|
|
99188
|
-
) {}
|
|
99189
|
-
|
|
99190
|
-
public async index(context: ContextType<UpdateBookRouteType>) {
|
|
99191
|
-
const { id } = context.params;
|
|
99192
|
-
const { title, color, description, summarize, pageCount, src, coverImage, tags, topics, categories, lang, status } = context.payload;
|
|
99193
|
-
|
|
99194
|
-
const book = await this.service.execute({ id, title, color, description, summarize, pageCount, src, coverImage, tags, topics, categories, lang, status });
|
|
99195
|
-
|
|
99196
|
-
return context.response.json(book || {});
|
|
99197
|
-
}
|
|
99198
|
-
}
|
|
99199
|
-
`;
|
|
99200
|
-
|
|
99201
|
-
// src/templates/resources/book/services/CreateBookService.txt
|
|
99202
|
-
var CreateBookService_default = `import { inject } from "@ooneex/container";
|
|
99203
|
-
import { decorator } from "@ooneex/service";
|
|
99204
|
-
import type { IService } from "@ooneex/service";
|
|
99205
|
-
import type { LocaleType } from "@ooneex/translation";
|
|
99206
|
-
import { BookEntity } from "../entities/BookEntity";
|
|
99207
|
-
import { BookRepository } from "../repositories/BookRepository";
|
|
99208
|
-
|
|
99209
|
-
type ServiceDataType = {
|
|
99210
|
-
title: string;
|
|
99211
|
-
color?: string;
|
|
99212
|
-
description?: string;
|
|
99213
|
-
summarize?: string;
|
|
99214
|
-
pageCount?: number;
|
|
99215
|
-
src: string;
|
|
99216
|
-
coverImage?: string;
|
|
99217
|
-
tags?: string[];
|
|
99218
|
-
topics?: string[];
|
|
99219
|
-
categories?: string[];
|
|
99220
|
-
lang?: LocaleType;
|
|
99221
|
-
status?: string;
|
|
99222
|
-
};
|
|
99223
|
-
|
|
99224
|
-
@decorator.service()
|
|
99225
|
-
export class CreateBookService implements IService {
|
|
99226
|
-
constructor(
|
|
99227
|
-
@inject(BookRepository) private readonly repository: BookRepository,
|
|
99228
|
-
) {}
|
|
99229
|
-
|
|
99230
|
-
public async execute(data?: ServiceDataType): Promise<BookEntity | null> {
|
|
99231
|
-
if (!data) return null;
|
|
99232
|
-
|
|
99233
|
-
const book = new BookEntity();
|
|
99234
|
-
book.title = data.title;
|
|
99235
|
-
book.color = data.color;
|
|
99236
|
-
book.description = data.description;
|
|
99237
|
-
book.summarize = data.summarize;
|
|
99238
|
-
book.pageCount = data.pageCount;
|
|
99239
|
-
book.src = data.src;
|
|
99240
|
-
book.coverImage = data.coverImage;
|
|
99241
|
-
book.tags = data.tags;
|
|
99242
|
-
book.topics = data.topics;
|
|
99243
|
-
book.categories = data.categories;
|
|
99244
|
-
book.lang = data.lang;
|
|
99245
|
-
book.status = data.status;
|
|
99246
|
-
|
|
99247
|
-
return await this.repository.create(book);
|
|
99248
|
-
}
|
|
99249
|
-
}
|
|
99250
|
-
`;
|
|
99251
|
-
|
|
99252
|
-
// src/templates/resources/book/services/DeleteBookService.txt
|
|
99253
|
-
var DeleteBookService_default = `import { inject } from "@ooneex/container";
|
|
99254
|
-
import { decorator } from "@ooneex/service";
|
|
99255
|
-
import type { IService } from "@ooneex/service";
|
|
99256
|
-
import { BookRepository } from "../repositories/BookRepository";
|
|
99257
|
-
|
|
99258
|
-
type ServiceDataType = {
|
|
99259
|
-
id: string;
|
|
99260
|
-
};
|
|
99261
|
-
|
|
99262
|
-
@decorator.service()
|
|
99263
|
-
export class DeleteBookService implements IService {
|
|
99264
|
-
constructor(
|
|
99265
|
-
@inject(BookRepository) private readonly repository: BookRepository,
|
|
99266
|
-
) {}
|
|
99267
|
-
|
|
99268
|
-
public async execute(data?: ServiceDataType): Promise<void> {
|
|
99269
|
-
if (!data) return;
|
|
99270
|
-
|
|
99271
|
-
await this.repository.delete({ id: data.id });
|
|
99272
|
-
}
|
|
99273
|
-
}
|
|
99274
|
-
`;
|
|
99275
|
-
|
|
99276
|
-
// src/templates/resources/book/services/GetBookService.txt
|
|
99277
|
-
var GetBookService_default = `import { inject } from "@ooneex/container";
|
|
99278
|
-
import { decorator } from "@ooneex/service";
|
|
99279
|
-
import type { IService } from "@ooneex/service";
|
|
99280
|
-
import { BookEntity } from "../entities/BookEntity";
|
|
99281
|
-
import { BookRepository } from "../repositories/BookRepository";
|
|
99282
|
-
|
|
99283
|
-
type ServiceDataType = {
|
|
99284
|
-
id: string;
|
|
99285
|
-
};
|
|
99286
|
-
|
|
99287
|
-
@decorator.service()
|
|
99288
|
-
export class GetBookService implements IService {
|
|
99289
|
-
constructor(
|
|
99290
|
-
@inject(BookRepository) private readonly repository: BookRepository,
|
|
99291
|
-
) {}
|
|
99292
|
-
|
|
99293
|
-
public async execute(data?: ServiceDataType): Promise<BookEntity | null> {
|
|
99294
|
-
if (!data) return null;
|
|
99295
|
-
|
|
99296
|
-
return await this.repository.findOne(data.id);
|
|
99297
|
-
}
|
|
99298
|
-
}
|
|
99299
|
-
`;
|
|
99300
|
-
|
|
99301
|
-
// src/templates/resources/book/services/ListBooksService.txt
|
|
99302
|
-
var ListBooksService_default = `import { inject } from "@ooneex/container";
|
|
99303
|
-
import { decorator } from "@ooneex/service";
|
|
99304
|
-
import type { IService } from "@ooneex/service";
|
|
99305
|
-
import type { FilterResultType } from "@ooneex/types";
|
|
99306
|
-
import { BookEntity } from "../entities/BookEntity";
|
|
99307
|
-
import { BookRepository } from "../repositories/BookRepository";
|
|
99308
|
-
|
|
99309
|
-
type ServiceDataType = {
|
|
99310
|
-
page?: number;
|
|
99311
|
-
limit?: number;
|
|
99312
|
-
q?: string;
|
|
99313
|
-
};
|
|
99314
|
-
|
|
99315
|
-
@decorator.service()
|
|
99316
|
-
export class ListBooksService implements IService {
|
|
99317
|
-
constructor(
|
|
99318
|
-
@inject(BookRepository) private readonly repository: BookRepository,
|
|
99319
|
-
) {}
|
|
99320
|
-
|
|
99321
|
-
public async execute(data?: ServiceDataType): Promise<FilterResultType<BookEntity>> {
|
|
99322
|
-
return await this.repository.find({
|
|
99323
|
-
page: data?.page,
|
|
99324
|
-
limit: data?.limit,
|
|
99325
|
-
q: data?.q,
|
|
99326
|
-
});
|
|
99327
|
-
}
|
|
99328
|
-
}
|
|
99329
|
-
`;
|
|
99330
|
-
|
|
99331
|
-
// src/templates/resources/book/services/UpdateBookService.txt
|
|
99332
|
-
var UpdateBookService_default = `import { inject } from "@ooneex/container";
|
|
99333
|
-
import { decorator } from "@ooneex/service";
|
|
99334
|
-
import type { IService } from "@ooneex/service";
|
|
99335
|
-
import type { LocaleType } from "@ooneex/translation";
|
|
99336
|
-
import { BookEntity } from "../entities/BookEntity";
|
|
99337
|
-
import { BookRepository } from "../repositories/BookRepository";
|
|
99338
|
-
|
|
99339
|
-
type ServiceDataType = {
|
|
99340
|
-
id: string;
|
|
99341
|
-
title?: string;
|
|
99342
|
-
color?: string;
|
|
99343
|
-
description?: string;
|
|
99344
|
-
summarize?: string;
|
|
99345
|
-
pageCount?: number;
|
|
99346
|
-
src?: string;
|
|
99347
|
-
coverImage?: string;
|
|
99348
|
-
tags?: string[];
|
|
99349
|
-
topics?: string[];
|
|
99350
|
-
categories?: string[];
|
|
99351
|
-
lang?: LocaleType;
|
|
99352
|
-
status?: string;
|
|
99353
|
-
};
|
|
99354
|
-
|
|
99355
|
-
@decorator.service()
|
|
99356
|
-
export class UpdateBookService implements IService {
|
|
99357
|
-
constructor(
|
|
99358
|
-
@inject(BookRepository) private readonly repository: BookRepository,
|
|
99359
|
-
) {}
|
|
99360
|
-
|
|
99361
|
-
public async execute(data?: ServiceDataType): Promise<BookEntity | null> {
|
|
99362
|
-
if (!data) return null;
|
|
99363
|
-
|
|
99364
|
-
const { id, ...fields } = data;
|
|
99365
|
-
|
|
99366
|
-
await this.repository.update({ id, ...fields });
|
|
99367
|
-
|
|
99368
|
-
return await this.repository.findOne(id);
|
|
99369
|
-
}
|
|
99370
|
-
}
|
|
99371
|
-
`;
|
|
99372
|
-
|
|
99373
|
-
// src/commands/MigrationCreateCommand.ts
|
|
98761
|
+
// src/commands/MakeServiceCommand.ts
|
|
99374
98762
|
import { join as join30 } from "path";
|
|
99375
98763
|
import { decorator as decorator30 } from "@ooneex/command";
|
|
99376
98764
|
import { TerminalLogger as TerminalLogger29 } from "@ooneex/logger";
|
|
99377
|
-
import { migrationCreate } from "@ooneex/migrations";
|
|
99378
|
-
|
|
99379
|
-
// src/templates/module/migration.up.txt
|
|
99380
|
-
var migration_up_default = `#!/usr/bin/env bun
|
|
99381
|
-
|
|
99382
|
-
import { up } from "@ooneex/migrations";
|
|
99383
|
-
import "@module/{{name}}/migrations/migrations";
|
|
99384
|
-
|
|
99385
|
-
await up({
|
|
99386
|
-
databaseUrl: Bun.env.DATABASE_URL,
|
|
99387
|
-
tableName: "migrations",
|
|
99388
|
-
});
|
|
99389
|
-
`;
|
|
99390
|
-
|
|
99391
|
-
// src/commands/MigrationCreateCommand.ts
|
|
99392
|
-
class MigrationCreateCommand {
|
|
99393
|
-
getName() {
|
|
99394
|
-
return "migration:create";
|
|
99395
|
-
}
|
|
99396
|
-
getDescription() {
|
|
99397
|
-
return "Generate a new migration file";
|
|
99398
|
-
}
|
|
99399
|
-
async run(options) {
|
|
99400
|
-
const { module = "shared" } = options;
|
|
99401
|
-
await ensureModule(module);
|
|
99402
|
-
const base = join30("modules", module);
|
|
99403
|
-
const { migrationPath: filePath } = await migrationCreate({
|
|
99404
|
-
migrationsDir: join30(base, "src", "migrations"),
|
|
99405
|
-
testsDir: join30(base, "tests", "migrations"),
|
|
99406
|
-
module
|
|
99407
|
-
});
|
|
99408
|
-
const binMigrationUpPath = join30(process.cwd(), base, "bin", "migration", "up.ts");
|
|
99409
|
-
const binMigrationUpFile = Bun.file(binMigrationUpPath);
|
|
99410
|
-
if (!await binMigrationUpFile.exists()) {
|
|
99411
|
-
await Bun.write(binMigrationUpPath, migration_up_default.replace(/{{name}}/g, module));
|
|
99412
|
-
}
|
|
99413
|
-
const logger = new TerminalLogger29;
|
|
99414
|
-
logger.success(`${filePath} created successfully`, undefined, {
|
|
99415
|
-
showTimestamp: false,
|
|
99416
|
-
showArrow: false,
|
|
99417
|
-
useSymbol: true
|
|
99418
|
-
});
|
|
99419
|
-
}
|
|
99420
|
-
}
|
|
99421
|
-
MigrationCreateCommand = __legacyDecorateClassTS([
|
|
99422
|
-
decorator30.command()
|
|
99423
|
-
], MigrationCreateCommand);
|
|
99424
|
-
|
|
99425
|
-
// src/commands/MakeServiceCommand.ts
|
|
99426
|
-
import { join as join31 } from "path";
|
|
99427
|
-
import { decorator as decorator31 } from "@ooneex/command";
|
|
99428
|
-
import { TerminalLogger as TerminalLogger30 } from "@ooneex/logger";
|
|
99429
98765
|
import { toPascalCase as toPascalCase15 } from "@ooneex/utils";
|
|
99430
98766
|
|
|
99431
98767
|
// src/templates/service.test.txt
|
|
@@ -99475,28 +98811,28 @@ class MakeServiceCommand {
|
|
|
99475
98811
|
name = toPascalCase15(name).replace(/Service$/, "");
|
|
99476
98812
|
const content = service_default.replace(/{{NAME}}/g, name);
|
|
99477
98813
|
await ensureModule(module);
|
|
99478
|
-
const base =
|
|
99479
|
-
const serviceLocalDir =
|
|
99480
|
-
const serviceDir =
|
|
99481
|
-
const filePath =
|
|
98814
|
+
const base = join30("modules", module);
|
|
98815
|
+
const serviceLocalDir = join30(base, "src", "services");
|
|
98816
|
+
const serviceDir = join30(process.cwd(), serviceLocalDir);
|
|
98817
|
+
const filePath = join30(serviceDir, `${name}Service.ts`);
|
|
99482
98818
|
await Bun.write(filePath, content);
|
|
99483
98819
|
const testContent = service_test_default.replace(/{{NAME}}/g, name).replace(/{{MODULE}}/g, module);
|
|
99484
|
-
const testsLocalDir =
|
|
99485
|
-
const testsDir =
|
|
99486
|
-
const testFilePath =
|
|
98820
|
+
const testsLocalDir = join30(base, "tests", "services");
|
|
98821
|
+
const testsDir = join30(process.cwd(), testsLocalDir);
|
|
98822
|
+
const testFilePath = join30(testsDir, `${name}Service.spec.ts`);
|
|
99487
98823
|
await Bun.write(testFilePath, testContent);
|
|
99488
|
-
const logger = new
|
|
99489
|
-
logger.success(`${
|
|
98824
|
+
const logger = new TerminalLogger29;
|
|
98825
|
+
logger.success(`${join30(serviceLocalDir, name)}Service.ts created successfully`, undefined, {
|
|
99490
98826
|
showTimestamp: false,
|
|
99491
98827
|
showArrow: false,
|
|
99492
98828
|
useSymbol: true
|
|
99493
98829
|
});
|
|
99494
|
-
logger.success(`${
|
|
98830
|
+
logger.success(`${join30(testsLocalDir, name)}Service.spec.ts created successfully`, undefined, {
|
|
99495
98831
|
showTimestamp: false,
|
|
99496
98832
|
showArrow: false,
|
|
99497
98833
|
useSymbol: true
|
|
99498
98834
|
});
|
|
99499
|
-
const packageJsonPath =
|
|
98835
|
+
const packageJsonPath = join30(process.cwd(), "package.json");
|
|
99500
98836
|
const packageJson = await Bun.file(packageJsonPath).json();
|
|
99501
98837
|
const deps = packageJson.dependencies ?? {};
|
|
99502
98838
|
const devDeps = packageJson.devDependencies ?? {};
|
|
@@ -99511,79 +98847,12 @@ class MakeServiceCommand {
|
|
|
99511
98847
|
}
|
|
99512
98848
|
}
|
|
99513
98849
|
MakeServiceCommand = __legacyDecorateClassTS([
|
|
99514
|
-
|
|
98850
|
+
decorator30.command()
|
|
99515
98851
|
], MakeServiceCommand);
|
|
99516
|
-
|
|
99517
|
-
// src/commands/MakeResourceBookCommand.ts
|
|
99518
|
-
class MakeResourceBookCommand {
|
|
99519
|
-
getName() {
|
|
99520
|
-
return "make:resource:book";
|
|
99521
|
-
}
|
|
99522
|
-
getDescription() {
|
|
99523
|
-
return "Generate book resource (entity, migration, repository)";
|
|
99524
|
-
}
|
|
99525
|
-
async run() {
|
|
99526
|
-
const module = "book";
|
|
99527
|
-
const base = join32("modules", module);
|
|
99528
|
-
const makeModuleCommand = new ModuleCreateCommand;
|
|
99529
|
-
await makeModuleCommand.run({ name: module, silent: true });
|
|
99530
|
-
const makeEntityCommand = new MakeEntityCommand;
|
|
99531
|
-
await makeEntityCommand.run({ name: "Book", module, tableName: "books" });
|
|
99532
|
-
const makeMigrationCommand = new MigrationCreateCommand;
|
|
99533
|
-
await makeMigrationCommand.run({ module });
|
|
99534
|
-
const makeRepositoryCommand = new MakeRepositoryCommand;
|
|
99535
|
-
await makeRepositoryCommand.run({ name: "Book", module });
|
|
99536
|
-
const makeControllerCommand = new MakeControllerCommand;
|
|
99537
|
-
const controllers = [
|
|
99538
|
-
{ name: "CreateBook", route: { name: "book.create", path: "/books", method: "POST" } },
|
|
99539
|
-
{ name: "GetBook", route: { name: "book.get", path: "/books/:id", method: "GET" } },
|
|
99540
|
-
{ name: "ListBooks", route: { name: "book.list", path: "/books", method: "GET" } },
|
|
99541
|
-
{ name: "UpdateBook", route: { name: "book.update", path: "/books/:id", method: "PATCH" } },
|
|
99542
|
-
{ name: "DeleteBook", route: { name: "book.delete", path: "/books/:id", method: "DELETE" } }
|
|
99543
|
-
];
|
|
99544
|
-
for (const controller of controllers) {
|
|
99545
|
-
await makeControllerCommand.run({ ...controller, module, isSocket: false });
|
|
99546
|
-
}
|
|
99547
|
-
const controllersDir = join32(process.cwd(), base, "src", "controllers");
|
|
99548
|
-
await Bun.write(join32(controllersDir, "CreateBookController.ts"), CreateBookController_default);
|
|
99549
|
-
await Bun.write(join32(controllersDir, "GetBookController.ts"), GetBookController_default);
|
|
99550
|
-
await Bun.write(join32(controllersDir, "ListBooksController.ts"), ListBooksController_default);
|
|
99551
|
-
await Bun.write(join32(controllersDir, "UpdateBookController.ts"), UpdateBookController_default);
|
|
99552
|
-
await Bun.write(join32(controllersDir, "DeleteBookController.ts"), DeleteBookController_default);
|
|
99553
|
-
const makeServiceCommand = new MakeServiceCommand;
|
|
99554
|
-
const services = ["CreateBook", "GetBook", "ListBooks", "UpdateBook", "DeleteBook"];
|
|
99555
|
-
for (const name of services) {
|
|
99556
|
-
await makeServiceCommand.run({ name, module });
|
|
99557
|
-
}
|
|
99558
|
-
const servicesDir = join32(process.cwd(), base, "src", "services");
|
|
99559
|
-
await Bun.write(join32(servicesDir, "CreateBookService.ts"), CreateBookService_default);
|
|
99560
|
-
await Bun.write(join32(servicesDir, "GetBookService.ts"), GetBookService_default);
|
|
99561
|
-
await Bun.write(join32(servicesDir, "ListBooksService.ts"), ListBooksService_default);
|
|
99562
|
-
await Bun.write(join32(servicesDir, "UpdateBookService.ts"), UpdateBookService_default);
|
|
99563
|
-
await Bun.write(join32(servicesDir, "DeleteBookService.ts"), DeleteBookService_default);
|
|
99564
|
-
const entityPath = join32(process.cwd(), base, "src", "entities", "BookEntity.ts");
|
|
99565
|
-
await Bun.write(entityPath, BookEntity_default);
|
|
99566
|
-
const migrationsDir = join32(process.cwd(), base, "src", "migrations");
|
|
99567
|
-
const glob = new Glob("Migration*.ts");
|
|
99568
|
-
for await (const file of glob.scan(migrationsDir)) {
|
|
99569
|
-
if (file === "migrations.ts")
|
|
99570
|
-
continue;
|
|
99571
|
-
const name = file.replace(/\.ts$/, "");
|
|
99572
|
-
const version = name.replace("Migration", "");
|
|
99573
|
-
const content = BookMigration_default.replaceAll("{{ name }}", name).replaceAll("{{ version }}", version);
|
|
99574
|
-
await Bun.write(join32(migrationsDir, file), content);
|
|
99575
|
-
}
|
|
99576
|
-
const repositoryPath = join32(process.cwd(), base, "src", "repositories", "BookRepository.ts");
|
|
99577
|
-
await Bun.write(repositoryPath, BookRepository_default);
|
|
99578
|
-
}
|
|
99579
|
-
}
|
|
99580
|
-
MakeResourceBookCommand = __legacyDecorateClassTS([
|
|
99581
|
-
decorator32.command()
|
|
99582
|
-
], MakeResourceBookCommand);
|
|
99583
98852
|
// src/commands/MakeStorageCommand.ts
|
|
99584
|
-
import { join as
|
|
99585
|
-
import { decorator as
|
|
99586
|
-
import { TerminalLogger as
|
|
98853
|
+
import { join as join31 } from "path";
|
|
98854
|
+
import { decorator as decorator31 } from "@ooneex/command";
|
|
98855
|
+
import { TerminalLogger as TerminalLogger30 } from "@ooneex/logger";
|
|
99587
98856
|
import { toPascalCase as toPascalCase16, toSnakeCase as toSnakeCase3 } from "@ooneex/utils";
|
|
99588
98857
|
|
|
99589
98858
|
// src/templates/storage.test.txt
|
|
@@ -99608,6 +98877,8 @@ describe("{{NAME}}StorageAdapter", () => {
|
|
|
99608
98877
|
|
|
99609
98878
|
// src/templates/storage.txt
|
|
99610
98879
|
var storage_default = `import { Storage, decorator, StorageException } from "@ooneex/storage";
|
|
98880
|
+
import { inject } from "@ooneex/container";
|
|
98881
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
99611
98882
|
import type { S3Options } from "bun";
|
|
99612
98883
|
|
|
99613
98884
|
@decorator.storage()
|
|
@@ -99618,17 +98889,20 @@ export class {{NAME}}Storage extends Storage {
|
|
|
99618
98889
|
private readonly endpoint: string;
|
|
99619
98890
|
private readonly region: string;
|
|
99620
98891
|
|
|
99621
|
-
constructor(
|
|
99622
|
-
|
|
99623
|
-
|
|
99624
|
-
|
|
99625
|
-
|
|
99626
|
-
|
|
98892
|
+
public constructor(
|
|
98893
|
+
@inject(AppEnv) private readonly env: AppEnv,
|
|
98894
|
+
options?: {
|
|
98895
|
+
accessKey?: string;
|
|
98896
|
+
secretKey?: string;
|
|
98897
|
+
endpoint?: string;
|
|
98898
|
+
region?: string;
|
|
98899
|
+
},
|
|
98900
|
+
) {
|
|
99627
98901
|
super();
|
|
99628
98902
|
|
|
99629
|
-
const accessKey = options?.accessKey ||
|
|
99630
|
-
const secretKey = options?.secretKey ||
|
|
99631
|
-
const endpoint = options?.endpoint ||
|
|
98903
|
+
const accessKey = options?.accessKey || this.env.STORAGE_{{NAME_UPPER}}_ACCESS_KEY;
|
|
98904
|
+
const secretKey = options?.secretKey || this.env.STORAGE_{{NAME_UPPER}}_SECRET_KEY;
|
|
98905
|
+
const endpoint = options?.endpoint || this.env.STORAGE_{{NAME_UPPER}}_ENDPOINT;
|
|
99632
98906
|
|
|
99633
98907
|
if (!accessKey) {
|
|
99634
98908
|
throw new StorageException(
|
|
@@ -99649,7 +98923,7 @@ export class {{NAME}}Storage extends Storage {
|
|
|
99649
98923
|
this.accessKey = accessKey;
|
|
99650
98924
|
this.secretKey = secretKey;
|
|
99651
98925
|
this.endpoint = endpoint;
|
|
99652
|
-
this.region = options?.region ||
|
|
98926
|
+
this.region = options?.region || this.env.STORAGE_{{NAME_UPPER}}_REGION || "auto";
|
|
99653
98927
|
}
|
|
99654
98928
|
|
|
99655
98929
|
public getOptions(): S3Options {
|
|
@@ -99681,28 +98955,28 @@ class MakeStorageCommand {
|
|
|
99681
98955
|
const nameUpper = toSnakeCase3(name).toUpperCase();
|
|
99682
98956
|
const content = storage_default.replace(/{{NAME}}/g, name).replace(/{{NAME_UPPER}}/g, nameUpper);
|
|
99683
98957
|
await ensureModule(module);
|
|
99684
|
-
const base =
|
|
99685
|
-
const storageLocalDir =
|
|
99686
|
-
const storageDir =
|
|
99687
|
-
const filePath =
|
|
98958
|
+
const base = join31("modules", module);
|
|
98959
|
+
const storageLocalDir = join31(base, "src", "storage");
|
|
98960
|
+
const storageDir = join31(process.cwd(), storageLocalDir);
|
|
98961
|
+
const filePath = join31(storageDir, `${name}Storage.ts`);
|
|
99688
98962
|
await Bun.write(filePath, content);
|
|
99689
98963
|
const testContent = storage_test_default.replace(/{{NAME}}/g, name).replace(/{{MODULE}}/g, module);
|
|
99690
|
-
const testsLocalDir =
|
|
99691
|
-
const testsDir =
|
|
99692
|
-
const testFilePath =
|
|
98964
|
+
const testsLocalDir = join31(base, "tests", "storage");
|
|
98965
|
+
const testsDir = join31(process.cwd(), testsLocalDir);
|
|
98966
|
+
const testFilePath = join31(testsDir, `${name}Storage.spec.ts`);
|
|
99693
98967
|
await Bun.write(testFilePath, testContent);
|
|
99694
|
-
const logger = new
|
|
99695
|
-
logger.success(`${
|
|
98968
|
+
const logger = new TerminalLogger30;
|
|
98969
|
+
logger.success(`${join31(storageLocalDir, name)}Storage.ts created successfully`, undefined, {
|
|
99696
98970
|
showTimestamp: false,
|
|
99697
98971
|
showArrow: false,
|
|
99698
98972
|
useSymbol: true
|
|
99699
98973
|
});
|
|
99700
|
-
logger.success(`${
|
|
98974
|
+
logger.success(`${join31(testsLocalDir, name)}Storage.spec.ts created successfully`, undefined, {
|
|
99701
98975
|
showTimestamp: false,
|
|
99702
98976
|
showArrow: false,
|
|
99703
98977
|
useSymbol: true
|
|
99704
98978
|
});
|
|
99705
|
-
const packageJsonPath =
|
|
98979
|
+
const packageJsonPath = join31(process.cwd(), "package.json");
|
|
99706
98980
|
const packageJson = await Bun.file(packageJsonPath).json();
|
|
99707
98981
|
const deps = packageJson.dependencies ?? {};
|
|
99708
98982
|
const devDeps = packageJson.devDependencies ?? {};
|
|
@@ -99717,12 +98991,12 @@ class MakeStorageCommand {
|
|
|
99717
98991
|
}
|
|
99718
98992
|
}
|
|
99719
98993
|
MakeStorageCommand = __legacyDecorateClassTS([
|
|
99720
|
-
|
|
98994
|
+
decorator31.command()
|
|
99721
98995
|
], MakeStorageCommand);
|
|
99722
98996
|
// src/commands/MakeVectorDatabaseCommand.ts
|
|
99723
|
-
import { join as
|
|
99724
|
-
import { decorator as
|
|
99725
|
-
import { TerminalLogger as
|
|
98997
|
+
import { join as join32 } from "path";
|
|
98998
|
+
import { decorator as decorator32 } from "@ooneex/command";
|
|
98999
|
+
import { TerminalLogger as TerminalLogger31 } from "@ooneex/logger";
|
|
99726
99000
|
import { toPascalCase as toPascalCase17 } from "@ooneex/utils";
|
|
99727
99001
|
|
|
99728
99002
|
// src/templates/vector-database.test.txt
|
|
@@ -99794,28 +99068,28 @@ class MakeVectorDatabaseCommand {
|
|
|
99794
99068
|
name = toPascalCase17(name).replace(/VectorDatabase$/, "").replace(/Database$/, "");
|
|
99795
99069
|
const content = vector_database_default.replace(/{{NAME}}/g, name);
|
|
99796
99070
|
await ensureModule(module);
|
|
99797
|
-
const base =
|
|
99798
|
-
const vectorDatabaseLocalDir =
|
|
99799
|
-
const vectorDatabaseDir =
|
|
99800
|
-
const filePath =
|
|
99071
|
+
const base = join32("modules", module);
|
|
99072
|
+
const vectorDatabaseLocalDir = join32(base, "src", "databases");
|
|
99073
|
+
const vectorDatabaseDir = join32(process.cwd(), vectorDatabaseLocalDir);
|
|
99074
|
+
const filePath = join32(vectorDatabaseDir, `${name}VectorDatabase.ts`);
|
|
99801
99075
|
await Bun.write(filePath, content);
|
|
99802
99076
|
const testContent = vector_database_test_default.replace(/{{NAME}}/g, name).replace(/{{MODULE}}/g, module);
|
|
99803
|
-
const testsLocalDir =
|
|
99804
|
-
const testsDir =
|
|
99805
|
-
const testFilePath =
|
|
99077
|
+
const testsLocalDir = join32(base, "tests", "databases");
|
|
99078
|
+
const testsDir = join32(process.cwd(), testsLocalDir);
|
|
99079
|
+
const testFilePath = join32(testsDir, `${name}VectorDatabase.spec.ts`);
|
|
99806
99080
|
await Bun.write(testFilePath, testContent);
|
|
99807
|
-
const logger = new
|
|
99808
|
-
logger.success(`${
|
|
99081
|
+
const logger = new TerminalLogger31;
|
|
99082
|
+
logger.success(`${join32(vectorDatabaseLocalDir, name)}VectorDatabase.ts created successfully`, undefined, {
|
|
99809
99083
|
showTimestamp: false,
|
|
99810
99084
|
showArrow: false,
|
|
99811
99085
|
useSymbol: true
|
|
99812
99086
|
});
|
|
99813
|
-
logger.success(`${
|
|
99087
|
+
logger.success(`${join32(testsLocalDir, name)}VectorDatabase.spec.ts created successfully`, undefined, {
|
|
99814
99088
|
showTimestamp: false,
|
|
99815
99089
|
showArrow: false,
|
|
99816
99090
|
useSymbol: true
|
|
99817
99091
|
});
|
|
99818
|
-
const packageJsonPath =
|
|
99092
|
+
const packageJsonPath = join32(process.cwd(), "package.json");
|
|
99819
99093
|
const packageJson = await Bun.file(packageJsonPath).json();
|
|
99820
99094
|
const deps = packageJson.dependencies ?? {};
|
|
99821
99095
|
const devDeps = packageJson.devDependencies ?? {};
|
|
@@ -99830,12 +99104,66 @@ class MakeVectorDatabaseCommand {
|
|
|
99830
99104
|
}
|
|
99831
99105
|
}
|
|
99832
99106
|
MakeVectorDatabaseCommand = __legacyDecorateClassTS([
|
|
99833
|
-
|
|
99107
|
+
decorator32.command()
|
|
99834
99108
|
], MakeVectorDatabaseCommand);
|
|
99109
|
+
// src/commands/MigrationCreateCommand.ts
|
|
99110
|
+
import { join as join33 } from "path";
|
|
99111
|
+
import { decorator as decorator33 } from "@ooneex/command";
|
|
99112
|
+
import { TerminalLogger as TerminalLogger32 } from "@ooneex/logger";
|
|
99113
|
+
import { migrationCreate } from "@ooneex/migrations";
|
|
99114
|
+
|
|
99115
|
+
// src/templates/module/migration.up.txt
|
|
99116
|
+
var migration_up_default = `#!/usr/bin/env bun
|
|
99117
|
+
|
|
99118
|
+
import { up } from "@ooneex/migrations";
|
|
99119
|
+
import { AppEnv } from "@ooneex/app-env";
|
|
99120
|
+
import "@module/{{name}}/migrations/migrations";
|
|
99121
|
+
|
|
99122
|
+
const env = new AppEnv();
|
|
99123
|
+
|
|
99124
|
+
await up({
|
|
99125
|
+
databaseUrl: env.DATABASE_URL,
|
|
99126
|
+
tableName: "migrations",
|
|
99127
|
+
});
|
|
99128
|
+
`;
|
|
99129
|
+
|
|
99130
|
+
// src/commands/MigrationCreateCommand.ts
|
|
99131
|
+
class MigrationCreateCommand {
|
|
99132
|
+
getName() {
|
|
99133
|
+
return "migration:create";
|
|
99134
|
+
}
|
|
99135
|
+
getDescription() {
|
|
99136
|
+
return "Generate a new migration file";
|
|
99137
|
+
}
|
|
99138
|
+
async run(options) {
|
|
99139
|
+
const { module = "shared" } = options;
|
|
99140
|
+
await ensureModule(module);
|
|
99141
|
+
const base = join33("modules", module);
|
|
99142
|
+
const { migrationPath: filePath } = await migrationCreate({
|
|
99143
|
+
migrationsDir: join33(base, "src", "migrations"),
|
|
99144
|
+
testsDir: join33(base, "tests", "migrations"),
|
|
99145
|
+
module
|
|
99146
|
+
});
|
|
99147
|
+
const binMigrationUpPath = join33(process.cwd(), base, "bin", "migration", "up.ts");
|
|
99148
|
+
const binMigrationUpFile = Bun.file(binMigrationUpPath);
|
|
99149
|
+
if (!await binMigrationUpFile.exists()) {
|
|
99150
|
+
await Bun.write(binMigrationUpPath, migration_up_default.replace(/{{name}}/g, module));
|
|
99151
|
+
}
|
|
99152
|
+
const logger = new TerminalLogger32;
|
|
99153
|
+
logger.success(`${filePath} created successfully`, undefined, {
|
|
99154
|
+
showTimestamp: false,
|
|
99155
|
+
showArrow: false,
|
|
99156
|
+
useSymbol: true
|
|
99157
|
+
});
|
|
99158
|
+
}
|
|
99159
|
+
}
|
|
99160
|
+
MigrationCreateCommand = __legacyDecorateClassTS([
|
|
99161
|
+
decorator33.command()
|
|
99162
|
+
], MigrationCreateCommand);
|
|
99835
99163
|
// src/commands/MigrationUpCommand.ts
|
|
99836
99164
|
import { existsSync as existsSync2 } from "fs";
|
|
99837
|
-
import { join as
|
|
99838
|
-
import { decorator as
|
|
99165
|
+
import { join as join34 } from "path";
|
|
99166
|
+
import { decorator as decorator34 } from "@ooneex/command";
|
|
99839
99167
|
import { TerminalLogger as TerminalLogger33 } from "@ooneex/logger";
|
|
99840
99168
|
class MigrationUpCommand {
|
|
99841
99169
|
getName() {
|
|
@@ -99846,7 +99174,7 @@ class MigrationUpCommand {
|
|
|
99846
99174
|
}
|
|
99847
99175
|
async run(options) {
|
|
99848
99176
|
const logger = new TerminalLogger33;
|
|
99849
|
-
const modulesDir =
|
|
99177
|
+
const modulesDir = join34(process.cwd(), "modules");
|
|
99850
99178
|
if (!existsSync2(modulesDir)) {
|
|
99851
99179
|
logger.warn("No modules with migrations found", undefined, {
|
|
99852
99180
|
showTimestamp: false,
|
|
@@ -99859,10 +99187,10 @@ class MigrationUpCommand {
|
|
|
99859
99187
|
const modules = [];
|
|
99860
99188
|
for await (const match of glob.scan({ cwd: modulesDir, onlyFiles: true })) {
|
|
99861
99189
|
const entry = match.replace("/package.json", "");
|
|
99862
|
-
const moduleDir =
|
|
99863
|
-
const migrationUpFile = Bun.file(
|
|
99190
|
+
const moduleDir = join34(modulesDir, entry);
|
|
99191
|
+
const migrationUpFile = Bun.file(join34(moduleDir, "bin", "migration", "up.ts"));
|
|
99864
99192
|
if (await migrationUpFile.exists()) {
|
|
99865
|
-
const packageJson = await Bun.file(
|
|
99193
|
+
const packageJson = await Bun.file(join34(modulesDir, match)).json();
|
|
99866
99194
|
modules.push({ name: packageJson.name ?? entry, dir: moduleDir });
|
|
99867
99195
|
}
|
|
99868
99196
|
}
|
|
@@ -99875,7 +99203,7 @@ class MigrationUpCommand {
|
|
|
99875
99203
|
return;
|
|
99876
99204
|
}
|
|
99877
99205
|
for (const { name, dir } of modules) {
|
|
99878
|
-
const migrationUpPath =
|
|
99206
|
+
const migrationUpPath = join34(dir, "bin", "migration", "up.ts");
|
|
99879
99207
|
logger.info(`Running migrations for ${name}...`, undefined, {
|
|
99880
99208
|
showTimestamp: false,
|
|
99881
99209
|
showArrow: false,
|
|
@@ -99908,11 +99236,11 @@ class MigrationUpCommand {
|
|
|
99908
99236
|
}
|
|
99909
99237
|
}
|
|
99910
99238
|
MigrationUpCommand = __legacyDecorateClassTS([
|
|
99911
|
-
|
|
99239
|
+
decorator34.command()
|
|
99912
99240
|
], MigrationUpCommand);
|
|
99913
99241
|
// src/commands/ModuleLockCommand.ts
|
|
99914
|
-
import { join as
|
|
99915
|
-
import { decorator as
|
|
99242
|
+
import { join as join35, relative } from "path";
|
|
99243
|
+
import { decorator as decorator35 } from "@ooneex/command";
|
|
99916
99244
|
import { TerminalLogger as TerminalLogger34 } from "@ooneex/logger";
|
|
99917
99245
|
import { migrationTestCreate } from "@ooneex/migrations";
|
|
99918
99246
|
import { seedTestCreate } from "@ooneex/seeds";
|
|
@@ -99928,16 +99256,16 @@ class ModuleLockCommand {
|
|
|
99928
99256
|
const { module = "shared", override } = options;
|
|
99929
99257
|
const logger = new TerminalLogger34;
|
|
99930
99258
|
await ensureModule(module);
|
|
99931
|
-
const base =
|
|
99259
|
+
const base = join35("modules", module);
|
|
99932
99260
|
const moduleName = module;
|
|
99933
|
-
const ymlPath =
|
|
99261
|
+
const ymlPath = join35(process.cwd(), base, `${moduleName}.yml`);
|
|
99934
99262
|
if (!await Bun.file(ymlPath).exists()) {
|
|
99935
99263
|
await Bun.write(ymlPath, yml_default.replace(/{{name}}/g, moduleName));
|
|
99936
99264
|
}
|
|
99937
99265
|
const { migrations: registeredMigrations, seeds: registeredSeeds } = await this.parseYml(ymlPath);
|
|
99938
99266
|
let added = 0;
|
|
99939
99267
|
let skipped = 0;
|
|
99940
|
-
const migrationsDir =
|
|
99268
|
+
const migrationsDir = join35(process.cwd(), base, "src", "migrations");
|
|
99941
99269
|
const migrationFiles = [];
|
|
99942
99270
|
try {
|
|
99943
99271
|
const glob = new Bun.Glob("Migration*.ts");
|
|
@@ -99947,17 +99275,17 @@ class ModuleLockCommand {
|
|
|
99947
99275
|
} catch {}
|
|
99948
99276
|
for (const file of migrationFiles.sort()) {
|
|
99949
99277
|
const name = file.replace(/\.ts$/, "");
|
|
99950
|
-
const testsDir =
|
|
99278
|
+
const testsDir = join35(base, "tests", "migrations");
|
|
99951
99279
|
await migrationTestCreate({ name, testsDir, ...module && { module } });
|
|
99952
99280
|
if (registeredMigrations[name] && !override) {
|
|
99953
99281
|
skipped++;
|
|
99954
99282
|
continue;
|
|
99955
99283
|
}
|
|
99956
|
-
const content = await Bun.file(
|
|
99284
|
+
const content = await Bun.file(join35(migrationsDir, file)).text();
|
|
99957
99285
|
registeredMigrations[name] = new Bun.CryptoHasher("sha256").update(content).digest("hex");
|
|
99958
99286
|
added++;
|
|
99959
99287
|
}
|
|
99960
|
-
const seedsDir =
|
|
99288
|
+
const seedsDir = join35(process.cwd(), base, "src", "seeds");
|
|
99961
99289
|
const seedFiles = [];
|
|
99962
99290
|
try {
|
|
99963
99291
|
const glob = new Bun.Glob("*-seed.yml");
|
|
@@ -99967,13 +99295,13 @@ class ModuleLockCommand {
|
|
|
99967
99295
|
} catch {}
|
|
99968
99296
|
for (const file of seedFiles.sort()) {
|
|
99969
99297
|
const name = file.replace(/\.yml$/, "");
|
|
99970
|
-
const testsDir =
|
|
99298
|
+
const testsDir = join35(base, "tests", "seeds");
|
|
99971
99299
|
await seedTestCreate({ name: toPascalCase18(name), testsDir, ...module && { module } });
|
|
99972
99300
|
if (registeredSeeds[name] && !override) {
|
|
99973
99301
|
skipped++;
|
|
99974
99302
|
continue;
|
|
99975
99303
|
}
|
|
99976
|
-
const content = await Bun.file(
|
|
99304
|
+
const content = await Bun.file(join35(seedsDir, file)).text();
|
|
99977
99305
|
registeredSeeds[name] = new Bun.CryptoHasher("sha256").update(content).digest("hex");
|
|
99978
99306
|
added++;
|
|
99979
99307
|
}
|
|
@@ -100040,12 +99368,12 @@ class ModuleLockCommand {
|
|
|
100040
99368
|
}
|
|
100041
99369
|
}
|
|
100042
99370
|
ModuleLockCommand = __legacyDecorateClassTS([
|
|
100043
|
-
|
|
99371
|
+
decorator35.command()
|
|
100044
99372
|
], ModuleLockCommand);
|
|
100045
99373
|
// src/commands/ModuleRemoveCommand.ts
|
|
100046
99374
|
import { rmdir } from "fs/promises";
|
|
100047
|
-
import { join as
|
|
100048
|
-
import { decorator as
|
|
99375
|
+
import { join as join36 } from "path";
|
|
99376
|
+
import { decorator as decorator36 } from "@ooneex/command";
|
|
100049
99377
|
import { TerminalLogger as TerminalLogger35 } from "@ooneex/logger";
|
|
100050
99378
|
import { toKebabCase as toKebabCase6, toPascalCase as toPascalCase19 } from "@ooneex/utils";
|
|
100051
99379
|
class ModuleRemoveCommand {
|
|
@@ -100126,8 +99454,8 @@ class ModuleRemoveCommand {
|
|
|
100126
99454
|
}
|
|
100127
99455
|
return;
|
|
100128
99456
|
}
|
|
100129
|
-
const moduleDir =
|
|
100130
|
-
const moduleDirExists = await Bun.file(
|
|
99457
|
+
const moduleDir = join36(cwd, "modules", kebabName);
|
|
99458
|
+
const moduleDirExists = await Bun.file(join36(moduleDir, "package.json")).exists();
|
|
100131
99459
|
if (!moduleDirExists) {
|
|
100132
99460
|
if (!silent) {
|
|
100133
99461
|
const logger = new TerminalLogger35;
|
|
@@ -100147,13 +99475,13 @@ class ModuleRemoveCommand {
|
|
|
100147
99475
|
if (!confirmed)
|
|
100148
99476
|
return;
|
|
100149
99477
|
}
|
|
100150
|
-
const appModulePath =
|
|
99478
|
+
const appModulePath = join36(cwd, "modules", "app", "src", "AppModule.ts");
|
|
100151
99479
|
await this.removeFromAppModule(appModulePath, pascalName, kebabName);
|
|
100152
|
-
const sharedModulePath =
|
|
99480
|
+
const sharedModulePath = join36(cwd, "modules", "shared", "src", "SharedModule.ts");
|
|
100153
99481
|
await this.removeFromSharedModule(sharedModulePath, pascalName, kebabName);
|
|
100154
|
-
const appTsconfigPath =
|
|
99482
|
+
const appTsconfigPath = join36(cwd, "tsconfig.json");
|
|
100155
99483
|
await this.removePathAlias(appTsconfigPath, kebabName);
|
|
100156
|
-
const commitlintPath =
|
|
99484
|
+
const commitlintPath = join36(cwd, ".commitlintrc.ts");
|
|
100157
99485
|
await this.removeModuleScope(commitlintPath, kebabName);
|
|
100158
99486
|
await rmdir(moduleDir, { recursive: true });
|
|
100159
99487
|
if (!silent) {
|
|
@@ -100167,11 +99495,11 @@ class ModuleRemoveCommand {
|
|
|
100167
99495
|
}
|
|
100168
99496
|
}
|
|
100169
99497
|
ModuleRemoveCommand = __legacyDecorateClassTS([
|
|
100170
|
-
|
|
99498
|
+
decorator36.command()
|
|
100171
99499
|
], ModuleRemoveCommand);
|
|
100172
99500
|
// src/commands/SeedCreateCommand.ts
|
|
100173
|
-
import { join as
|
|
100174
|
-
import { decorator as
|
|
99501
|
+
import { join as join37 } from "path";
|
|
99502
|
+
import { decorator as decorator37 } from "@ooneex/command";
|
|
100175
99503
|
import { TerminalLogger as TerminalLogger36 } from "@ooneex/logger";
|
|
100176
99504
|
import { seedCreate } from "@ooneex/seeds";
|
|
100177
99505
|
|
|
@@ -100209,18 +99537,18 @@ class SeedCreateCommand {
|
|
|
100209
99537
|
name = await askName({ message: "Enter seed name" });
|
|
100210
99538
|
}
|
|
100211
99539
|
await ensureModule(module);
|
|
100212
|
-
const base =
|
|
99540
|
+
const base = join37("modules", module);
|
|
100213
99541
|
const {
|
|
100214
99542
|
seedPath: filePath,
|
|
100215
99543
|
dataPath,
|
|
100216
99544
|
testPath
|
|
100217
99545
|
} = await seedCreate({
|
|
100218
99546
|
name,
|
|
100219
|
-
seedsDir:
|
|
100220
|
-
testsDir:
|
|
99547
|
+
seedsDir: join37(base, "src", "seeds"),
|
|
99548
|
+
testsDir: join37(base, "tests", "seeds"),
|
|
100221
99549
|
module
|
|
100222
99550
|
});
|
|
100223
|
-
const binSeedRunPath =
|
|
99551
|
+
const binSeedRunPath = join37(process.cwd(), base, "bin", "seed", "run.ts");
|
|
100224
99552
|
const binSeedRunFile = Bun.file(binSeedRunPath);
|
|
100225
99553
|
if (!await binSeedRunFile.exists()) {
|
|
100226
99554
|
await Bun.write(binSeedRunPath, seed_run_default.replace(/{{name}}/g, module));
|
|
@@ -100244,12 +99572,12 @@ class SeedCreateCommand {
|
|
|
100244
99572
|
}
|
|
100245
99573
|
}
|
|
100246
99574
|
SeedCreateCommand = __legacyDecorateClassTS([
|
|
100247
|
-
|
|
99575
|
+
decorator37.command()
|
|
100248
99576
|
], SeedCreateCommand);
|
|
100249
99577
|
// src/commands/SeedRunCommand.ts
|
|
100250
99578
|
import { existsSync as existsSync3 } from "fs";
|
|
100251
|
-
import { join as
|
|
100252
|
-
import { decorator as
|
|
99579
|
+
import { join as join38 } from "path";
|
|
99580
|
+
import { decorator as decorator38 } from "@ooneex/command";
|
|
100253
99581
|
import { TerminalLogger as TerminalLogger37 } from "@ooneex/logger";
|
|
100254
99582
|
class SeedRunCommand {
|
|
100255
99583
|
getName() {
|
|
@@ -100260,7 +99588,7 @@ class SeedRunCommand {
|
|
|
100260
99588
|
}
|
|
100261
99589
|
async run(options) {
|
|
100262
99590
|
const logger = new TerminalLogger37;
|
|
100263
|
-
const modulesDir =
|
|
99591
|
+
const modulesDir = join38(process.cwd(), "modules");
|
|
100264
99592
|
if (!existsSync3(modulesDir)) {
|
|
100265
99593
|
logger.warn("No modules with seeds found", undefined, {
|
|
100266
99594
|
showTimestamp: false,
|
|
@@ -100273,10 +99601,10 @@ class SeedRunCommand {
|
|
|
100273
99601
|
const modules = [];
|
|
100274
99602
|
for await (const match of glob.scan({ cwd: modulesDir, onlyFiles: true })) {
|
|
100275
99603
|
const entry = match.replace("/package.json", "");
|
|
100276
|
-
const moduleDir =
|
|
100277
|
-
const seedRunFile = Bun.file(
|
|
99604
|
+
const moduleDir = join38(modulesDir, entry);
|
|
99605
|
+
const seedRunFile = Bun.file(join38(moduleDir, "bin", "seed", "run.ts"));
|
|
100278
99606
|
if (await seedRunFile.exists()) {
|
|
100279
|
-
const packageJson = await Bun.file(
|
|
99607
|
+
const packageJson = await Bun.file(join38(modulesDir, match)).json();
|
|
100280
99608
|
modules.push({ name: packageJson.name ?? entry, dir: moduleDir });
|
|
100281
99609
|
}
|
|
100282
99610
|
}
|
|
@@ -100289,7 +99617,7 @@ class SeedRunCommand {
|
|
|
100289
99617
|
return;
|
|
100290
99618
|
}
|
|
100291
99619
|
for (const { name, dir } of modules) {
|
|
100292
|
-
const seedRunPath =
|
|
99620
|
+
const seedRunPath = join38(dir, "bin", "seed", "run.ts");
|
|
100293
99621
|
logger.info(`Running seeds for ${name}...`, undefined, {
|
|
100294
99622
|
showTimestamp: false,
|
|
100295
99623
|
showArrow: false,
|
|
@@ -100324,9 +99652,9 @@ class SeedRunCommand {
|
|
|
100324
99652
|
}
|
|
100325
99653
|
}
|
|
100326
99654
|
SeedRunCommand = __legacyDecorateClassTS([
|
|
100327
|
-
|
|
99655
|
+
decorator38.command()
|
|
100328
99656
|
], SeedRunCommand);
|
|
100329
99657
|
// src/index.ts
|
|
100330
99658
|
await run();
|
|
100331
99659
|
|
|
100332
|
-
//# debugId=
|
|
99660
|
+
//# debugId=3C100A421DA692FB64756E2164756E21
|