以上下文镜所标注的鼻涕、多语种别名和鼻涕装置进行分级标记.
安装
pnpm add @happyvertical/smrt-tags
使用量
import { Tag, TagCollection, TagAlias, TagAliasCollection } from '@happyvertical/smrt-tags';
import { sanitizeSlug, validateSlug, generateUniqueSlug } from '@happyvertical/smrt-tags';
// Create a tag hierarchy
const collection = await TagCollection.create();
// `collection.create(...)` returns the saved row, so use it directly
// instead of `new Tag()` + a separate `.create(...)` step. The returned
// instance has its persisted `id` set for use as a parent reference.
const tech = await collection.create({
slug: 'technology',
name: 'Technology',
context: 'blog', // defaults to 'global' if omitted
});
// Children reference their parent by UUID (`parentId`). With `tech`
// already saved, pass `tech.id` directly. `level` is recalculated by
// `TagCollection.moveTag` / `mergeTag` for later moves; you can pass it
// explicitly on create or let it stay at 0 and call moveTag later.
const ai = await collection.create({
slug: 'artificial-intelligence',
name: 'Artificial Intelligence',
context: 'blog',
parentId: tech.id,
level: 1,
});
// Traverse hierarchy
const children = await tech.getChildren();
const ancestors = await ai.getAncestors();
// Context scoping -- same slug, different contexts
const blogNews = new Tag({ slug: 'news', name: 'News', context: 'blog' });
const forumNews = new Tag({ slug: 'news', name: 'Forum News', context: 'forum' });
// Multi-language aliases
const aliasCollection = await TagAliasCollection.create();
const alias = new TagAlias({
tagSlug: 'technology',
alias: 'Tecnologia',
language: 'es',
context: 'blog',
});
await aliasCollection.create(alias);
// Collection operations. Slug args resolve through (slug, context) —
// pass an explicit context when the same slug exists in multiple
// contexts, otherwise the resolver throws on ambiguity.
await collection.moveTag('artificial-intelligence', 'technology', 'blog'); // cycle-checked
await collection.mergeTag('source', 'target', 'blog'); // moves children + aliases, deletes source
await collection.cleanupUnused(); // deletes tags with no children and no aliases
// Slug utilities
sanitizeSlug('My Cool Tag!'); // 'my-cool-tag'
validateSlug('my-tag-123'); // true
API 密码
模型( smrt 对象)
| 导出 | 说明 |
Tag | 已确认 slug + 键 context。通过 parentId (UUID,从 SmrtHierarchical) (中文(简体) ). 非正常状态 level 重新计算 TagCollection.moveTag 编号 : mergeTag贾森 metadata继承的等级方法: getParent(), (中文(简体) ), getChildren(), (中文(简体) ), getAncestors(), (中文(简体) ), getDescendants(), (中文(简体) ), getHierarchy(), (中文(简体) ), moveTo()。拥有帮助者: getMetadata(), (中文(简体) ), setMetadata(), (中文(简体) ), updateMetadata() |
TagAlias | 特定语文翻译: tagSlug, (中文(简体) ), alias, (中文(简体) ), language (ISO 639-1),可选 context |
收藏( 收藏)
| 导出 | 说明 |
TagCollection | CRUD + 软件 getOrCreate(), (中文(简体) ), moveTag(), (中文(简体) ), mergeTag(), (中文(简体) ), cleanupUnused(), (中文(简体) ), findWithGlobals() |
TagAliasCollection | 标记别名的 CRUD |
公用事业
| 导出 | 说明 |
sanitizeSlug(input) | 干净并格式化 switch 字符串 |
validateSlug(slug) | 验证 sattle 格式( 小写, 字母数 + 连字符) |
generateUniqueSlug(name, context, collection) | 自动编号独有的弹片生成 |
calculateLevel(parentSlug, collection) | 从父定义等级深度 |
hasCircularReference(slug, parentSlug, collection) | 检测循环父引用 |
类型
| 导出 | 说明 |
TagOptions | 备选方案 Tag 构造器 |
TagAliasOptions | 备选方案 TagAlias 构造器 |
TagMetadata | 灵活的元数据结构(颜色、图标、统计) |
TagHierarchy | 完整的等级结果(祖先、现世、后代) |
依赖关系
| 软件包 | 目的 |
@happyvertical/smrt-core | ORM 基础( Smrt Object, Smrt Collection) |
@happyvertical/smrt-tenancy | 备选租户范围界定 |