@happyvertical/ smrt- 产品
产品目录参考模板,展示三重消费:npm包库,模块联合会,以及独立的REST API服务器.
安装
pnpm add @happyvertical/smrt-products
使用量
导入为 npm 库
import { Product, ProductCollection, Category } from '@happyvertical/smrt-products';
import { startServer } from '@happyvertical/smrt-products';
import { generateMCPServer } from '@happyvertical/smrt-products';
import { AssetCollection } from '@happyvertical/smrt-assets';
// Start standalone REST API server
const { shutdown } = await startServer();
const products = await ProductCollection.create();
const assets = await AssetCollection.create();
const product = await products.create({
name: 'Demo Product',
price: 29.99,
});
const hero = await assets.create({
name: 'demo-product-hero.jpg',
sourceUri: 'file:///tmp/demo-product-hero.jpg',
mimeType: 'image/jpeg',
});
await product.addAsset(hero, 'hero');
await products.addAsset(product.id!, hero, 'gallery', 1);
三种消费方式
- 国家预防机制图书馆 -- 直接导入类别、组件和存储
- 模块联合会 -- 运行时间组件共享(实验性)
- 独立 API - 说吧
startServer() 带有自动生成路线的快车
API 密码
顶级出口
| 导出 | 说明 |
startServer | 启动独立的 REST API 服务器 |
generateMCPServer | 生成用于 AI 工具集成的 MCP 服务器 |
demonstrateClient | 自动生成的 TypeScript 客户端的解析 |
startAll | 启动所有服务(REST + MCP) |
型号(从 lib/models(中文(简体) )
| 导出 | 说明 |
Product | 带有规格和标签的科技和创新产品 |
Category | 等级分类(父母身份、级别、产品) |
ProductAsset | 专用自有资产加入存储于 product_assets 与 relationship 财务报告和审定财务报表 sortOrder;由于 Product 没有租户范围 |
收款(从 lib/collections(中文(简体) )
| 导出 | 说明 |
ProductCollection | CROUD 外加号 findByManufacturer(), (中文(简体) ), findInStock()和自有资产包装 |
ProductAssetCollection | 直接进入 product_assets 行外加资产助手包装 |
构成部分(从 lib/components(中文(简体) )
| 导出 | 说明 |
ProductCard | Svelte 5 产品显示组件 |
ProductForm | Svelte 5 产品编辑表 |
库存(从 lib/stores(中文(简体) )
| 导出 | 说明 |
ProductStoreClass | Svelte 5 个基于 rune 的州级管理课程 |
productStore | Singleton 存储实例 |
水电费(从 lib/utils(中文(简体) )
| 导出 | 说明 |
formatPrice | 格式编号为USD 货币字符串 |
formatDate | 格式化日期为可读字符串 |
slugify | 将文本转换为方便 URL 的 sult |
generateId | 生成随机 ID 字符串 |
虚拟模块( Vite 插件)
| 导出 | 说明 |
createClient | 自动生成 TypeScript API 客户端 |
setupRoutes | 自动生成的快车路线 |
createMCPServer | 自动生成的 MCP 服务器 |
manifest | s-m-r-t 对象元数据 |
双方都有自有资产助手 Product 财务报告和审定财务报表 ProductCollection 通过
getAssets(), (中文(简体) ), addAsset(),以及 removeAsset()共同关系包括:
hero, (中文(简体) ), gallery, (中文(简体) ), attachment,以及 thumbnail。 。 。 .
依赖关系
| 软件包 | 目的 |
@happyvertical/smrt-core | Smrt Object/Smrt Collection base class, REST 服务器, MCP 生成器 |
@happyvertical/smrt-assets | 产品自有资产助手使用的共享资产/资产收集类型 |
@happyvertical/sql | 数据库操作 |
@happyvertical/ai | 大赦国际一体化 |