@ dynamatix/ cat- 共享
Catura 服务综合共享库,提供数据模型、中间软件以及文件管理、审计记录和工作流程自动化服务.
* 安装
npm install @dynamatix/cat-shared
QQ 快速启动
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' });
* 特性
🔍 数据模型
- 文件管理数字 :
DocumentModel, (中文(简体) ),DocumentTypeModel, (中文(简体) ),DocumentHistoryModel - 审计和遵守情况数字 :
AuditModel, (中文(简体) ),AuditConfigModel - 工作流程管理数字 :
WorkflowConfigModel, (中文(简体) ),WorkflowAlertModel - 窗体配置数字 :
FormConfigurationModel - 数值参考映射数字 :
ValueReferenceMapModel
🛡️ 中间软件
- MongoDB 文档的自动更改跟踪
- 与自定义解析器配置审计记录
- 支持复杂的外地描述和查询
- 与用户归属请求的关联
🔧 服务
- 请求上下文: 基于Async本地Storage的上下文管理
- 审计钩:用于自动审计记录的Mongoose钩
API 参考
模型
文档模式
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'
});
审计模式
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'
});
中间软件
应用 AuditMiddle 软件
import { applyAuditMiddleware } from '@dynamatix/cat-shared';
// Apply audit middleware to a model
applyAuditMiddleware(DocumentModel);
// The model will now automatically log all changes
注册
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)
});
服务
请求上下文
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);
QQ 配置
审计配置
审计系统使用 AuditConfigModel 配置要跟踪的字段以及如何描述变化:
const auditConfig = new AuditConfigModel({
modelName: 'Document',
fields: ['status', 'filename'],
descriptionField: 'filename',
descriptionResolverType: 'direct'
});
数值参考映射
使用 ValueReferenceMapModel 以配置如何解析和显示引用字段:
const valueMap = new ValueReferenceMapModel({
field: 'createdBy',
model: 'User',
displayField: 'fullName',
descriptionResolverType: 'lookup'
});
种子
该项目包括初步数据集的种子:
# Run the value reference map seeder
node seeders/value-reference-map.seeder.js
项目结构
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
出口
库提供以下导出路径:
// 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';
发展
先决条件
- 节点.js 18+
- 蒙戈DB
- 8.13.1 + 蒙古语
地方发展
# Clone the repository
git clone <repository-url>
cd cat-shared
# Install dependencies
npm install
# Run tests (when implemented)
npm test
许可证
ISC 许可证
捐款
这是Catura Services的共享库. 请与开发团队联系,了解捐款准则.
++ 辅助
如需支援及提问,请与Catura Services开发团队联系.