@dynamatix/cat-shared

中文文档
0.0.171发布于 2026/11/05ISCES Module近 30 天下载 2297

A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.

原始使用文档
文档目录22 节
  1. 📦 Installation
  2. 🚀 Quick Start
  3. 📚 Features
  4. 🔍 Data Models
  5. 🛡️ Audit Middleware
  6. 🔧 Services
  7. 📖 API Reference
  8. Models
  9. Middleware
  10. Services
  11. 🔧 Configuration
  12. Audit Configuration
  13. Value Reference Mapping
  14. 🌱 Seeding
  15. 📁 Project Structure
  16. 🔌 Exports
  17. 🧪 Development
  18. Prerequisites
  19. Local Development
  20. 📝 License
  21. 🤝 Contributing
  22. 📞 Support

@dynamatix/cat-shared

A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.

📦 Installation

npm install @dynamatix/cat-shared

🚀 Quick Start

import { 
  DocumentModel, 
  AuditModel, 
  applyAuditMiddleware,
  getContext 
} from '@dynamatix/cat-shared';

// Use models directly
const document = new DocumentModel({
  filename: 'example.pdf',
  documentTypeId: '...',
  // ... other fields
});

// Apply audit middleware to track changes
applyAuditMiddleware(DocumentModel);

// Set request context
setContext({ userId: 'user123', requestId: 'req456' });

📚 Features

🔍 Data Models

  • Document Management: DocumentModel, DocumentTypeModel, DocumentHistoryModel
  • Audit & Compliance: AuditModel, AuditConfigModel
  • Workflow Management: WorkflowConfigModel, WorkflowAlertModel
  • Form Configuration: FormConfigurationModel
  • Value Reference Mapping: ValueReferenceMapModel

🛡️ Audit Middleware

  • Automatic change tracking for MongoDB documents
  • Configurable audit logging with custom resolvers
  • Support for complex field descriptions and lookups
  • Integration with request context for user attribution

🔧 Services

  • Request Context: AsyncLocalStorage-based context management
  • Audit Hooks: Mongoose hooks for automatic audit logging

📖 API Reference

Models

DocumentModel

import { DocumentModel } from '@dynamatix/cat-shared';

const document = new DocumentModel({
  contextId: 'application123',
  filename: 'document.pdf',
  documentTypeId: 'type456',
  documentUrl: 'https://storage.example.com/doc.pdf',
  statusLid: 'status789',
  uploadedBy: 'user123'
});

AuditModel

import { AuditModel } from '@dynamatix/cat-shared';

const auditLog = new AuditModel({
  name: 'Document Updated',
  recordId: 'document123',
  contextId: 'application456',
  oldValue: { status: 'pending' },
  newValue: { status: 'approved' },
  createdBy: 'user789'
});

Middleware

applyAuditMiddleware

import { applyAuditMiddleware } from '@dynamatix/cat-shared';

// Apply audit middleware to a model
applyAuditMiddleware(DocumentModel);

// The model will now automatically log all changes

registerAuditHook

import { registerAuditHook } from '@dynamatix/cat-shared';

// Register custom audit hooks
registerAuditHook(DocumentModel, {
  pre: (doc) => console.log('Before save:', doc),
  post: (doc) => console.log('After save:', doc)
});

Services

Request Context

import { getContext, setContext } from '@dynamatix/cat-shared';

// Set context for the current request
setContext({
  userId: 'user123',
  requestId: 'req456',
  timestamp: new Date()
});

// Get context anywhere in the request lifecycle
const context = getContext();
console.log('Current user:', context.userId);

🔧 Configuration

Audit Configuration

The audit system uses AuditConfigModel to configure what fields to track and how to describe changes:

const auditConfig = new AuditConfigModel({
  modelName: 'Document',
  fields: ['status', 'filename'],
  descriptionField: 'filename',
  descriptionResolverType: 'direct'
});

Value Reference Mapping

Use ValueReferenceMapModel to configure how to resolve and display referenced fields:

const valueMap = new ValueReferenceMapModel({
  field: 'createdBy',
  model: 'User',
  displayField: 'fullName',
  descriptionResolverType: 'lookup'
});

🌱 Seeding

The project includes seeders for initial data setup:

# Run the value reference map seeder
node seeders/value-reference-map.seeder.js

📁 Project Structure

cat-shared/
├── models/                 # MongoDB/Mongoose data models
│   ├── document.model.js
│   ├── audit.model.js
│   ├── workflow-*.model.js
│   └── index.js
├── middlewares/           # Express/Node.js middleware
│   ├── audit.middleware.js
│   └── index.js
├── services/              # Business logic services
│   ├── request-context.service.js
│   ├── audit-log.hook.js
│   └── index.js
├── seeders/               # Database seeding scripts
├── utils/                 # Utility functions
└── index.js               # Main export file

🔌 Exports

The library provides the following export paths:

// Main exports
import { DocumentModel, AuditModel } from '@dynamatix/cat-shared';

// Specific module exports
import { DocumentModel } from '@dynamatix/cat-shared/models';
import { applyAuditMiddleware } from '@dynamatix/cat-shared/middlewares';
import { getContext } from '@dynamatix/cat-shared/services';

🧪 Development

Prerequisites

  • Node.js 18+
  • MongoDB
  • Mongoose 8.13.1+

Local Development

# Clone the repository
git clone <repository-url>
cd cat-shared

# Install dependencies
npm install

# Run tests (when implemented)
npm test

📝 License

ISC License

🤝 Contributing

This is a shared library for Catura Services. Please contact the development team for contribution guidelines.

📞 Support

For support and questions, please contact the Catura Services development team.

版本与发布记录

@dynamatix/cat-shared 共发布 159 个版本,首次发布于 2025/03/29;过去 12 个月发布了 24 个版本。

版本发布日期距今
0.0.171latest2026/11/058 天前
0.0.1702026/11/049 天前
0.0.1692026/05/026 个月前
0.0.1682026/05/026 个月前
0.0.1652026/03/247 个月前
0.0.1642026/03/237 个月前

关于 @dynamatix/cat-shared 的常见问题

@dynamatix/cat-shared 是什么?

A comprehensive shared library for Catura Services providing data models, middleware, and services for document management, audit logging, and workflow automation.

如何安装 @dynamatix/cat-shared?

在项目目录运行 npm install @dynamatix/cat-shared,或使用 pnpm add / yarn add / bun add。

@dynamatix/cat-shared 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dynamatix__cat-shared 是否存在。

@dynamatix/cat-shared 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dynamatix/cat-shared 可以商用吗?

@dynamatix/cat-shared 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dynamatix/cat-shared 的下载量有多少?

根据 npm 官方下载统计,@dynamatix/cat-shared 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,297 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dynamatix/cat-shared 还在维护吗?

最新版本 0.0.171 发布于 2026/11/05(8 天前);至今共发布 159 个版本,其中过去 12 个月发布了 24 个;首次发布于 2025/03/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。