@happyvertical/smrt-财产
S-m-r-t框架的数字属性和分级区管理. 属性代表网站,应用程序,或出版物. 区块在每个地产内任意地形成一棵筑巢树,用于内容和广告放置.
安装
pnpm add @happyvertical/smrt-properties
使用量
import {
Property, PropertyCollection,
Zone, ZoneCollection
} from '@happyvertical/smrt-properties';
// Create a property
const properties = await PropertyCollection.create({ db });
const site = await properties.create({
name: 'Oak Creek News',
domain: 'oakcreeknews.com',
url: 'https://oakcreeknews.com',
status: 'active',
});
await site.save();
// Build a zone hierarchy: page -> section -> ad slot
const zones = await ZoneCollection.create({ db });
const homePage = await zones.create({
propertyId: site.id,
name: 'Home Page',
type: 'page',
path: '/',
});
await homePage.save();
const sidebar = await zones.create({
propertyId: site.id,
parentId: homePage.id,
name: 'Sidebar',
type: 'section',
selector: '.sidebar',
});
await sidebar.save();
const adSlot = await zones.create({
propertyId: site.id,
parentId: sidebar.id,
name: 'Sidebar Ad',
type: 'slot',
width: 300,
height: 250,
allowedFormats: ['image', 'html'],
});
await adSlot.save();
// Retrieve the full zone tree for a property
const tree = await zones.getTree(site.id);
// Move a zone (validates against descendant cycles)
await zones.moveZone(adSlot.id, homePage.id);
// Delete a zone — cascade=false moves children to parent
await zones.deleteZone(sidebar.id, false);
区级
区数 parentId 自我引用来形成一棵树。 共同区类型包括: page, (中文(简体) ), section, (中文(简体) ), slot, (中文(简体) ), container,以及 widget。每个区域可以指定一个 URL path 图案, CSS selector, (中文(简体) ), position 提示, 像素 width编号 :height,则 allowedFormats 用于过滤内容或广告类型的数组。 一个空的 allowedFormats 数组表示允许所有格式(没有限制).
这个 ZoneCollection 提供树运算 : getTree() 在记忆中构建一个嵌入式结构, getAncestors()编号 :getDescendants() 步入等级 moveZone() 防止循环,在再生育前检查后代. deleteZone(cascade) 或将后代或孤儿转移到被删除区域的父母身边.
API 密码
模型
| 导出 | 说明 |
|---|---|
Property | 有域名、 URL、 状态和所有者/ 存储器链接的数字属性( STI) |
Zone | 财产内的等级区,用于内容/ad放置 |
收款
| 导出 | 说明 |
|---|---|
PropertyCollection | CRUD 和查询财产记录 |
ZoneCollection | 区域 CRUD+树行动 : getTree(), (中文(简体) ), moveZone(), (中文(简体) ), deleteZone(), (中文(简体) ), getAncestors(), (中文(简体) ), getDescendants() |
密钥类型
PropertyOptions, (中文(简体) ), PropertyStatus, (中文(简体) ), ZoneOptions, (中文(简体) ), ZoneTree, (中文(简体) ), ZoneTreeNode
依赖关系
@happyvertical/smrt-core-- ORM 和代码生成@happyvertical/smrt-tenancy-- 可选多租户范围界定- 端点 :
@happyvertical/smrt-profiles, (中文(简体) ),@happyvertical/smrt-projects(可选)