Moonglade

Modern Markdown blogging with AI-powered localization and search.


NestJS pg template

This article introduces a backend project template based on NestJS, PostgreSQL, and TypeORM, aimed at providing a standardized development foundation. The article first outlines the configuration management approach, which involves reading YAML files and combining them with class-validator for strict data validation and transformation, ensuring the security and standardization of configurations. Next, it demonstrates how to use Docker Compose to quickly deploy Redis and PostgreSQL, optimizing the local development environment. The core functional modules include implementing database operations and migration management using TypeORM, as well as building a user authentication and permission control system based on JWT, Passport, and RBAC mechanisms, supporting dynamic retrieval of interface permission information via metadata. Additionally, the template integrates OpenAPI documentation generation and SDK automation tools to facilitate frontend integration. The logging system utilizes Winston and Dayjs to achieve Nest-style logging in development environments and file-based logging in production environments. Finally, the article covers specific data migration commands and a code submission process that follows the Conventional Commits specification, providing a complete technology stack reference for building robust, scalable enterprise-level backend applications.

Views 142
2024 daily nest node pgsql typeorm

Mongoose Type Issue

This article discusses the TypeScript type definition deficiencies encountered when performing database refactoring with Mongoose in a NestJS environment. The author points out that whether using `typegoose` or `nestjs/mongoose`, the type system fails to provide effective field constraints and error messages when constructing query filters (`FilterQuery`). Specifically, even if a filter object is assigned properties that do not exist in the Schema, TypeScript does not report an error. This prevents the detection of spelling mistakes or logical errors during the compilation phase, which contradicts the original intent of TypeScript to reduce coding mistakes through strong typing. Given that this issue stems from Mongoose's own type definition mechanism and that TypeORM has poor support for MongoDB, the author ultimately decided to abandon the existing solution and chose to rewrite the Schema and related code to migrate to Prima. This prioritizes type safety and clarity for the development experience, reflecting a focus on the quality of type support when selecting an ORM.

Views 110
2024 mongoose orm study typescript work

Yinming Ruzhenglun: A Structured Overview of the Argumentation Theory

This passage is excerpted from the section on Hetuvidyā (Buddhist Logic) in Maitreya Bodhisattva's *Mahāyānasaṃgraha* (Treatise on the Ground of the Master). It systematically elaborates on the seven core elements of Buddhist logical debate. First, it defines the nature of debate (*vāda*), categorizing discourse into six types: ordinary speech (*vākya*), deliberation (*parīkṣā*), quarrel (*vāda*), defamation (*vāda*), right discourse (*sādhak*), and instruction (*upadeśa*). It emphasizes that the latter two are genuine and lead to benefit and profit, and thus should be cultivated, while the others require careful distinction or avoidance. Second, it details the place of debate and its basis. The basis of debate includes two types of established meanings—essential nature (*svabhāva*) and difference (*viśeṣa*)—as well as eight methods of establishment: thesis (*pratijñā*), reason (*hetu*), example (*udāharaṇa*), similarity (*sādṛśya*), dissimilarity (*asādṛśya*), direct perception (*pratyakṣa*), inference (*anumāna*), and authoritative testimony (*āgama*). It provides an in-depth analysis of the three criteria for direct perception: not non-apparent, not already considered but needing consideration, and not a deluded state. It also examines the five classifications of inference: characteristic, entity, function, dharma, and cause-and-effect. Furthermore, it outlines the three verifications of authoritative testimony: not contradicting the words of the sages, capable of eliminating defilements, and not violating the characteristics of dharmas. Third, the article proposes the five virtues of adornment in debate: mastery of one's own and others' positions, completeness of speech, fearlessness, propriety, and reverence. It lists twenty-seven types of praiseworthy merit obtained through these virtues. Simultaneously, it warns of the three states of defeat in debate: abandonment of speech, being refuted by speech, and excessive speech. It points out that if a debater commits any of these nine faults or thirteen types of regression, they fall into the state of defeat. Finally, it clarifies the three observations for exiting debate, requiring the debater to examine gain and loss, the timing and audience, and their own skillfulness before establishing a thesis. It summarizes the extensive functions of debate as mastery of one's own and others' positions, courageous fearlessness, and inexhaustible eloquence, aiming to achieve the manifestation of truth and the liberation of wisdom through rigorous logic and pure motivation.

Views 153
2024 debate logic study weishi zhongzhe

OpenAPI client generation

This article documents the selection process and practical experience of automatically generating SDKs based on OpenAPI metadata. The author compared three libraries: `autorest`, `swagger-codegen-cli`, and `@hey-api/openapi-ts`, ultimately choosing the latter due to its superior performance in frontend environment compatibility, code conciseness, and type reuse. This choice effectively reduces the workload of manually writing request code and improves development efficiency. Using a NestJS backend and Vue frontend as examples, the article details the complete technical pipeline: configuring `nest-cli.json` to extract DTO and Entity types, utilizing a GitHub Actions pipeline to start the service in a CI environment to retrieve metadata, invoking `@hey-api/openapi-ts` to generate the SDK, and pushing it to a separate sub-repository. The frontend wraps the `@hey-api/client-fetch` client to implement unified authentication interception and error handling, directly importing the generated types and functions within Pinia Stores to achieve type safety and code reuse. This workflow not only reduces the collaboration cost between frontend and backend teams but also minimizes format errors through standardized interface definitions. Although the currently auto-generated parameter validation feature has limitations, the overall solution offers significant advantages in terms of type safety and development efficiency.

Views 385
2024 ci-cd github openapi study swagger vue work

Debug Vue3 source code (deprecated)

This article primarily shares an awkward experience of accidentally using Vue 2 source code while debugging Vue 3 source code, and elaborates in detail on the correct debugging approach and configuration methods. The core strategy is to have the Vue 3 source code generate sourcemaps and link them to the project template via a local build, replacing remote package references. Specifically, in Vue's Rollup build configuration file, you need to add `sourcemap: true` in the `output` section to enable source mapping. Regarding the debugging environment configuration, the article provides a VS Code `launch.json` example covering three debugging scenarios: first, debugging the `npm run build` build script itself; second, debugging a remote project based on the official Vue template, where you need to configure `outFiles` to correctly map the source code; and third, debugging raw HTML files, which also requires specifying the `outFiles` path to point to the local Vue source code directory. By combining local builds with source mapping, developers can more effectively track and debug Vue 3 internal logic, avoiding the difficulties of directly debugging minified code, and providing a practical technical solution for deeply understanding the framework's source code.

Views 83
2024 source-code study vue vue3 web

Related Content to Note

This article comprehensively outlines the core technology stack required for full-stack development and operations. The frontend section covers React, Vue, ES, TS, CSS, and UI frameworks, aiming to build modern user interfaces. The backend employs Node.js with the NestJS framework for data type ORM management, integrates mainstream databases and caching technologies such as MySQL, PostgreSQL, MongoDB, and Redis, and incorporates Nginx reverse proxy, Kafka message queue, and V8 engine optimization to ensure high-concurrency processing capabilities. On the operations side, containerized deployment is implemented based on Docker and Containerd, orchestration management is handled via Kubernetes, and a robust observability system is established using Elastic Stack, APM, monitoring, and distributed tracing systems, thereby ensuring high availability and stability of services.

Views 52
2024 Backend Technologies Frontend Development docker study todo

Detailed records of pre-installed Ubuntu applications are documented here.

This document records the checklist of essential software to be installed on the Ubuntu 24.04 system and the operational details. The author lists commonly used software including v2raya proxy tool, Edge browser, VSCode-Insider, QQ, Git, curl, nvm, Docker, CopyQ, DBeaver, MongoDB Compass, VLC, OBS Studio, Four-Leaf Clover Pinyin Input Method, Calibre, Bing Wall, and uLauncher. The text specifically notes potential startup delays after installing the Edge browser, as well as possible permission insufficiency issues when installing curl via snap that may lead to Node.js download failures, and provides corresponding resolution ideas. Additionally, the article includes specific installation commands covering various methods such as snap, apt, flatpak, and script-based installation. Examples include using snap to install v2raya and VLC, using apt to install Git and flatpak, using scripts to install nvm, and using flatpak to install OBS and Calibre, providing a reference for subsequent supplementary software installations.

Views 227
2024 Development Tools Software Installation Ubuntu 24.04 daily ubuntu

Upgrading umijs 3 to 4

This article documents the complete process and insights gained from upgrading the frontend framework of a legacy project from UmiJS 3 to UmiJS 4. The upgrade aims to address low development efficiency, clean up redundant code and libraries, and strengthen engineering standards such as TypeScript and ESLint. The author adopted a strategy of creating a new UmiJS 4 project and gradually migrating code, ensuring functionality stability before merging back into the original project. Specific changes include: replacing configurations with @umijs/max, removing dependencies on webpack-chain, proxy, and mock; rewriting the permission system to support dynamic routing and menus; refactoring class components into function components and introducing Hooks; updating Ant Design to the latest version and removing Less dependencies; deprecating umi-request in favor of axios; and adjusting tsconfig and internationalization configurations. Although specific errors were not detailed in this record, compatibility issues were successfully resolved through official documentation and community assistance, providing a practical reference for similar project upgrades.

Views 126
2024 configuration migration react ts umijs upgrade work

Frontend Excel Import Related Optimizations

This article introduces an implementation approach for an Excel import component based on Ant Design Pro Components. The component uses the Steps component to implement step-by-step operations and integrates ProTable to support online data editing, deletion, and paginated display. Core features include using class-validator for data validation, intuitively displaying validation error messages within the table, and supporting custom validation rules. The component utilizes the ActionProvider pattern to pass data sources, column configurations, and properties between steps, thereby achieving state transitions and data linkage across steps. However, the current implementation has several areas for optimization: the stepChange function should be exposed as a public API; the validation logic is currently hard-coded to depend on class-validator and needs to support pluggable validation libraries; the rawColumns and nextColumns parameter design is redundant and difficult to adapt to single-step or multi-step scenarios; the implicit length-matching convention between the stepActions array and the step list is not flexible enough, so it is recommended to refactor it into a clearer state machine pattern combined with stepProp. The overall architecture aims to provide a flexible data import experience, but further improvements are needed in API design, extensibility, and state management to enhance generality and maintainability.

Views 135
2024 Data Processing Form Validation improve react ts