@happyvertical/smrt-cli 0.54.2 → 0.54.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/{ApiKey-BZmbOTnL-BbZupUZ3.js → ApiKey-CVmlf3V6-BAeHuH48.js} +13 -5
  2. package/dist/{ApiKeyCollection-Bfb_nw81-DYAZwx0O.js → ApiKeyCollection-CiiDNFdD-CMGF3_ul.js} +5 -5
  3. package/dist/{AuditLogCollection-B1YonCAP-BPTsPePh.js → AuditLogCollection-WDHL-_AF-Cm6c206j.js} +33 -15
  4. package/dist/{NostrIdentity-n70E0vck-Di3_eNCq.js → NostrIdentity-AC8fAdxe-DKxKyu_a.js} +12 -4
  5. package/dist/{NostrIdentityCollection-Ca74dkaL-DvjOg9Xy.js → NostrIdentityCollection-CctlECpX-fkAPnK02.js} +4 -4
  6. package/dist/{OidcIdentity-Cb1bxreM-DO8v8PPX.js → OidcIdentity-BjRu3n1g-DPfoJOJq.js} +11 -3
  7. package/dist/{OidcIdentityCollection-TV8VdK69-CKJPi8VX.js → OidcIdentityCollection-B4jYh36_-CDCS-lBk.js} +5 -5
  8. package/dist/{ProfileAssetCollection-B9hacUJa-60k6WDBo.js → ProfileAssetCollection-HeMtjBc0-BnvWWbZ6.js} +16 -7
  9. package/dist/{ProfileCollection-DuJT7Mum-DuFdSzQj.js → ProfileCollection-Bt6IJK49-ir8YINdu.js} +53 -29
  10. package/dist/{ProfileLinkCollection-4uNURz32-DMtNzJcf.js → ProfileLinkCollection-u1hhzKTm-DN7eng_7.js} +14 -6
  11. package/dist/{ProfileMetadataCollection-DQhbfEfa-BKwTBhrv.js → ProfileMetadataCollection-BIYKy4Y3-BUDJszIc.js} +13 -5
  12. package/dist/{ProfileMetafieldCollection-CoBuM_5G-BMLo_Rie.js → ProfileMetafieldCollection-Buz7gzag-DDlih_5j.js} +13 -5
  13. package/dist/{ProfileRelationshipCollection-DUVgaIqf-c_BIh5H0.js → ProfileRelationshipCollection-C4g_QLI4-QJJ__ROk.js} +16 -8
  14. package/dist/{ProfileRelationshipTermCollection-DtA9OM23-BoGhQBSQ.js → ProfileRelationshipTermCollection-C9J7mC7P-ChIFqjCg.js} +12 -4
  15. package/dist/{ProfileRelationshipType-BRiRka6t-Dezjv5jP.js → ProfileRelationshipType-U7IwF6Wf-DNavf24e.js} +12 -4
  16. package/dist/{ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js → ProfileRelationshipTypeCollection-_n22WqTb-DiZUWvev.js} +5 -5
  17. package/dist/cli-generator.d.ts.map +1 -1
  18. package/dist/{commands-D-XOOzpO.js → commands-iFti-f80.js} +2 -2
  19. package/dist/{dist-DxolxjaP.js → dist-Bqg09MUx.js} +18 -2
  20. package/dist/dist-CrzK6GwA.js +20 -0
  21. package/dist/dist-D5GdZ8W6.js +4112 -0
  22. package/dist/{dist-DWOviNjs.js → dist-DIGbZpp6.js} +29 -5
  23. package/dist/dist-DJOzoOZn.js +1778 -0
  24. package/dist/index.js +26 -16
  25. package/dist/{oidcProvisioningPrimitives-D9OYu5-F-jUSih8OU.js → oidcProvisioningPrimitives-CYood-2M-D8npRnlS.js} +17 -7
  26. package/dist/{resolveIdentity-B-PK6RwU-Dp7_W7kZ.js → resolveIdentity-CvGDegU6-DkEz2oV8.js} +19 -19
  27. package/package.json +15 -15
  28. package/dist/dist-DqXOUqT-.js +0 -20
  29. package/dist/dist-NvkfhAbI.js +0 -3928
  30. package/dist/dist-RDQR2enZ.js +0 -1705
@@ -1,1705 +0,0 @@
1
- import { a as queryGlobal, i as tenantId, l as withSystemContext, o as queryWithGlobals, r as TenantScoped } from "./dist-DxolxjaP.js";
2
- import { ObjectRegistry, SmrtCollection, SmrtHierarchical, SmrtJunction, SmrtObject, SmrtPolymorphicAssociation, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
3
- //#region ../tags/dist/index.js
4
- var __defProp$2$1 = Object.defineProperty;
5
- var __exportAll$1 = (all, no_symbols) => {
6
- let target = {};
7
- for (var name in all) __defProp$2$1(target, name, {
8
- get: all[name],
9
- enumerable: true
10
- });
11
- if (!no_symbols) __defProp$2$1(target, Symbol.toStringTag, { value: "Module" });
12
- return target;
13
- };
14
- ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-tags\",\"packageVersion\":\"0.54.2\",\"objects\":{\"@happyvertical/smrt-tags:TagAlias\":{\"name\":\"tagalias\",\"className\":\"TagAlias\",\"qualifiedName\":\"@happyvertical/smrt-tags:TagAlias\",\"collection\":\"tagaliases\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/tags/src/tag-alias.ts\",\"packageName\":\"@happyvertical/smrt-tags\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"tagSlug\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"alias\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"language\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"createdAt\":{\"type\":\"datetime\",\"required\":false}},\"methods\":{\"getTag\":{\"name\":\"getTag\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Tag | null>\",\"isStatic\":false,\"isPublic\":true},\"searchByAlias\":{\"name\":\"searchByAlias\",\"async\":true,\"parameters\":[{\"name\":\"_alias\",\"type\":\"string\",\"optional\":false},{\"name\":\"_language\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":true,\"isPublic\":true},\"getAliasesForTag\":{\"name\":\"getAliasesForTag\",\"async\":true,\"parameters\":[{\"name\":\"_tagSlug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"]},\"extends\":\"SmrtObject\",\"exportName\":\"TagAlias\",\"collectionExportName\":\"TagAliasCollection\",\"validationRules\":[{\"field\":\"alias\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"tag_aliases\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tag_aliases\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tag_slug\\\" TEXT DEFAULT '',\\n \\\"alias\\\" TEXT DEFAULT '',\\n \\\"language\\\" TEXT DEFAULT '',\\n \\\"tenant_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tag_slug\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"alias\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"language\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false}},\"indexes\":[{\"name\":\"tag_aliases_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"tag_aliases_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"tag_aliases_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"95a4bc18\"},\"importPath\":\"@happyvertical/smrt-tags\"},\"@happyvertical/smrt-tags:TagAliasCollection\":{\"name\":\"tagaliascollection\",\"className\":\"TagAliasCollection\",\"qualifiedName\":\"@happyvertical/smrt-tags:TagAliasCollection\",\"collection\":\"tagaliases\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/tags/src/tag-aliases.ts\",\"packageName\":\"@happyvertical/smrt-tags\",\"fields\":{},\"methods\":{\"addAlias\":{\"name\":\"addAlias\",\"async\":true,\"parameters\":[{\"name\":\"tagSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"alias\",\"type\":\"string\",\"optional\":false},{\"name\":\"language\",\"type\":\"string\",\"optional\":true},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<TagAlias>\",\"isStatic\":false,\"isPublic\":true},\"searchByAlias\":{\"name\":\"searchByAlias\",\"async\":true,\"parameters\":[{\"name\":\"alias\",\"type\":\"string\",\"optional\":false},{\"name\":\"language\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"getAliasesForTag\":{\"name\":\"getAliasesForTag\",\"async\":true,\"parameters\":[{\"name\":\"tagSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"language\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true},\"removeAlias\":{\"name\":\"removeAlias\",\"async\":true,\"parameters\":[{\"name\":\"aliasId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"bulkAddAliases\":{\"name\":\"bulkAddAliases\",\"async\":true,\"parameters\":[{\"name\":\"tagSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"aliases\",\"type\":\"Array<object>\",\"optional\":false,\"memberTypes\":[\"string\"]}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true},\"getAliasesByLanguage\":{\"name\":\"getAliasesByLanguage\",\"async\":true,\"parameters\":[{\"name\":\"tagSlug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Map<string, string[]>>\",\"isStatic\":false,\"isPublic\":true},\"findMatchingAliases\":{\"name\":\"findMatchingAliases\",\"async\":true,\"parameters\":[{\"name\":\"query\",\"type\":\"string\",\"optional\":false},{\"name\":\"language\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true},\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<TagAlias[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"TagAlias\",\"exportName\":\"TagAliasCollection\",\"collectionExportName\":\"TagAliasCollectionCollection\",\"schema\":{\"tableName\":\"tag_aliases\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tag_aliases\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tag_slug\\\" TEXT DEFAULT '',\\n \\\"alias\\\" TEXT DEFAULT '',\\n \\\"language\\\" TEXT DEFAULT '',\\n \\\"tenant_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tag_slug\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"alias\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"language\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false}},\"indexes\":[{\"name\":\"tag_aliases_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"tag_aliases_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"tag_aliases_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]}],\"version\":\"95a4bc18\"},\"importPath\":\"@happyvertical/smrt-tags\"},\"@happyvertical/smrt-tags:Tag\":{\"name\":\"tag\",\"className\":\"Tag\",\"qualifiedName\":\"@happyvertical/smrt-tags:Tag\",\"collection\":\"tags\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/tags/src/tag.ts\",\"packageName\":\"@happyvertical/smrt-tags\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"parentId\":{\"type\":\"foreignKey\",\"required\":false,\"related\":\"Tag\",\"_meta\":{\"nullable\":true}},\"name\":{\"type\":\"text\",\"required\":true,\"default\":\"\",\"_meta\":{\"required\":true}},\"level\":{\"type\":\"integer\",\"required\":false,\"default\":0},\"description\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"metadata\":{\"type\":\"text\",\"required\":false,\"default\":\"\"},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"createdAt\":{\"type\":\"datetime\",\"required\":false},\"updatedAt\":{\"type\":\"datetime\",\"required\":false}},\"methods\":{\"getParent\":{\"name\":\"getParent\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this | null>\",\"isStatic\":false,\"isPublic\":true},\"getChildren\":{\"name\":\"getChildren\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getAncestors\":{\"name\":\"getAncestors\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getDescendants\":{\"name\":\"getDescendants\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getHierarchy\":{\"name\":\"getHierarchy\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<HierarchyView<this>>\",\"isStatic\":false,\"isPublic\":true},\"moveTo\":{\"name\":\"moveTo\",\"async\":true,\"parameters\":[{\"name\":\"newParent\",\"type\":\"this | string | null\",\"optional\":false,\"unionBranches\":[{\"type\":\"this\"},{\"type\":\"string\"},{\"type\":\"null\"}]}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getMetadata\":{\"name\":\"getMetadata\",\"async\":false,\"parameters\":[],\"returnType\":\"TagMetadata\",\"isStatic\":false,\"isPublic\":true},\"setMetadata\":{\"name\":\"setMetadata\",\"async\":false,\"parameters\":[{\"name\":\"data\",\"type\":\"TagMetadata\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"updateMetadata\":{\"name\":\"updateMetadata\",\"async\":false,\"parameters\":[{\"name\":\"updates\",\"type\":\"Partial<TagMetadata>\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"_context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<Tag | null>\",\"isStatic\":true,\"isPublic\":true},\"getRootTags\":{\"name\":\"getRootTags\",\"async\":true,\"parameters\":[{\"name\":\"_context\",\"type\":\"string\",\"optional\":true,\"default\":\"global\"}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\",\"update\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"]},\"extends\":\"SmrtHierarchical\",\"exportName\":\"Tag\",\"collectionExportName\":\"TagCollection\",\"validationRules\":[{\"field\":\"name\",\"rule\":\"required\",\"fieldType\":\"text\"}],\"schema\":{\"tableName\":\"tags\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tags\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"parent_id\\\" UUID,\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"level\\\" INTEGER DEFAULT 0,\\n \\\"description\\\" TEXT DEFAULT '',\\n \\\"metadata\\\" TEXT DEFAULT '',\\n \\\"tenant_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"parent_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"tags\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"level\":{\"type\":\"INTEGER\",\"notNull\":false,\"default\":0},\"description\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"metadata\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false}},\"indexes\":[{\"name\":\"tags_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"tags_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"tags_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"tags_parent_id_idx\",\"columns\":[\"parent_id\"]}],\"version\":\"4da9de3e\"},\"importPath\":\"@happyvertical/smrt-tags\"},\"@happyvertical/smrt-tags:TagCollection\":{\"name\":\"tagcollection\",\"className\":\"TagCollection\",\"qualifiedName\":\"@happyvertical/smrt-tags:TagCollection\",\"collection\":\"tags\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/tags/src/tags.ts\",\"packageName\":\"@happyvertical/smrt-tags\",\"fields\":{},\"methods\":{\"getOrCreate\":{\"name\":\"getOrCreate\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"context\",\"type\":\"string\",\"optional\":true,\"default\":\"global\"}],\"returnType\":\"Promise<Tag>\",\"isStatic\":false,\"isPublic\":true},\"listByContext\":{\"name\":\"listByContext\",\"async\":true,\"parameters\":[{\"name\":\"context\",\"type\":\"string\",\"optional\":false},{\"name\":\"parentSlug\",\"type\":\"string | null\",\"optional\":true,\"unionBranches\":[{\"type\":\"string\"},{\"type\":\"null\"}]}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"getRootTags\":{\"name\":\"getRootTags\",\"async\":true,\"parameters\":[{\"name\":\"context\",\"type\":\"string\",\"optional\":true,\"default\":\"global\"}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"getChildren\":{\"name\":\"getChildren\",\"async\":true,\"parameters\":[{\"name\":\"parentSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"getHierarchy\":{\"name\":\"getHierarchy\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<TagHierarchy>\",\"isStatic\":false,\"isPublic\":true},\"moveTag\":{\"name\":\"moveTag\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"newParentSlug\",\"type\":\"string | null\",\"optional\":false,\"unionBranches\":[{\"type\":\"string\"},{\"type\":\"null\"}]},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"mergeTag\":{\"name\":\"mergeTag\",\"async\":true,\"parameters\":[{\"name\":\"fromSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"toSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"cleanupUnused\":{\"name\":\"cleanupUnused\",\"async\":true,\"parameters\":[{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"calculateLevel\":{\"name\":\"calculateLevel\",\"async\":true,\"parameters\":[{\"name\":\"parentSlug\",\"type\":\"string | null\",\"optional\":false,\"unionBranches\":[{\"type\":\"string\"},{\"type\":\"null\"}]},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<number>\",\"isStatic\":false,\"isPublic\":true},\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"Tag\",\"exportName\":\"TagCollection\",\"collectionExportName\":\"TagCollectionCollection\",\"schema\":{\"tableName\":\"tags\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"tags\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"parent_id\\\" UUID,\\n \\\"name\\\" TEXT DEFAULT '',\\n \\\"level\\\" INTEGER DEFAULT 0,\\n \\\"description\\\" TEXT DEFAULT '',\\n \\\"metadata\\\" TEXT DEFAULT '',\\n \\\"tenant_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"parent_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"tags\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"level\":{\"type\":\"INTEGER\",\"notNull\":false,\"default\":0},\"description\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"metadata\":{\"type\":\"TEXT\",\"notNull\":false,\"default\":\"\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false}},\"indexes\":[{\"name\":\"tags_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"tags_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"tags_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"tags_parent_id_idx\",\"columns\":[\"parent_id\"]}],\"version\":\"4da9de3e\"},\"importPath\":\"@happyvertical/smrt-tags\"}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-tenancy\"]}"));
15
- var __defProp$1$1 = Object.defineProperty;
16
- var __getOwnPropDesc$1$1 = Object.getOwnPropertyDescriptor;
17
- var __decorateClass$1$1 = (decorators, target, key, kind) => {
18
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1$1(target, key) : target;
19
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
20
- if (kind && result) __defProp$1$1(target, key, result);
21
- return result;
22
- };
23
- var Tag = class extends SmrtHierarchical {
24
- _slug = "";
25
- _context = "global";
26
- get slug() {
27
- return this._slug;
28
- }
29
- set slug(value) {
30
- this._slug = value;
31
- }
32
- get context() {
33
- return this._context;
34
- }
35
- set context(value) {
36
- this._context = value;
37
- }
38
- name = "";
39
- level = 0;
40
- description = "";
41
- metadata = "";
42
- tenantId = null;
43
- createdAt = /* @__PURE__ */ new Date();
44
- updatedAt = /* @__PURE__ */ new Date();
45
- constructor(options = {}) {
46
- super(options);
47
- if (options.name) this.name = options.name;
48
- if (options.parentId !== void 0) this.parentId = options.parentId ?? null;
49
- if (options.slug) this._slug = options.slug;
50
- if (options.context !== void 0) this._context = options.context;
51
- if (options.level !== void 0) this.level = options.level;
52
- if (options.description !== void 0) this.description = options.description;
53
- if (options.metadata !== void 0) if (typeof options.metadata === "string") this.metadata = options.metadata;
54
- else this.metadata = JSON.stringify(options.metadata);
55
- }
56
- /**
57
- * Get metadata as parsed object
58
- *
59
- * @returns Parsed metadata object or empty object if no metadata
60
- */
61
- getMetadata() {
62
- const metadataValue = String(this.metadata || "");
63
- if (!metadataValue) return {};
64
- try {
65
- return JSON.parse(metadataValue);
66
- } catch {
67
- return {};
68
- }
69
- }
70
- /**
71
- * Set metadata from object
72
- *
73
- * @param data - Metadata object to store
74
- */
75
- setMetadata(data) {
76
- this.metadata = JSON.stringify(data);
77
- }
78
- /**
79
- * Update metadata by merging with existing values
80
- *
81
- * @param updates - Partial metadata to merge
82
- */
83
- updateMetadata(updates) {
84
- const current = this.getMetadata();
85
- this.setMetadata({
86
- ...current,
87
- ...updates
88
- });
89
- }
90
- /**
91
- * Convenience method for slug-based lookup
92
- *
93
- * @param slug - The slug to search for
94
- * @param context - Optional context filter
95
- * @returns Tag instance or null if not found
96
- */
97
- static async getBySlug(_slug, _context) {
98
- return null;
99
- }
100
- /**
101
- * Get root tags (no parent) for a context
102
- *
103
- * @param context - The context to filter by
104
- * @returns Array of root tags
105
- */
106
- static async getRootTags(_context = "global") {
107
- return [];
108
- }
109
- };
110
- __decorateClass$1$1([field({ required: true })], Tag.prototype, "name", 2);
111
- __decorateClass$1$1([tenantId({ nullable: true })], Tag.prototype, "tenantId", 2);
112
- Tag = __decorateClass$1$1([TenantScoped({ mode: "optional" }), smrt({
113
- tableStrategy: "sti",
114
- api: { include: [
115
- "list",
116
- "get",
117
- "create",
118
- "update",
119
- "delete"
120
- ] },
121
- mcp: { include: [
122
- "list",
123
- "get",
124
- "create",
125
- "update"
126
- ] },
127
- cli: { skipApiCheck: true }
128
- })], Tag);
129
- var __defProp$10 = Object.defineProperty;
130
- var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
131
- var __decorateClass$9 = (decorators, target, key, kind) => {
132
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
133
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
134
- if (kind && result) __defProp$10(target, key, result);
135
- return result;
136
- };
137
- var TagAlias = class extends SmrtObject {
138
- tagSlug = "";
139
- alias = "";
140
- language = "";
141
- _context = "";
142
- get context() {
143
- return this._context;
144
- }
145
- set context(value) {
146
- this._context = value;
147
- }
148
- tenantId = null;
149
- createdAt = /* @__PURE__ */ new Date();
150
- constructor(options = {}) {
151
- super(options);
152
- if (options.tagSlug !== void 0) this.tagSlug = options.tagSlug;
153
- if (options.alias) this.alias = options.alias;
154
- if (options.language !== void 0) this.language = options.language;
155
- if (options.context !== void 0) this._context = options.context;
156
- }
157
- /**
158
- * Get the tag this alias belongs to
159
- *
160
- * @returns Tag instance or null if not found
161
- */
162
- async getTag() {
163
- const { TagCollection } = await Promise.resolve().then(() => tags_exports);
164
- return await (await TagCollection.create(this.options)).get({ slug: this.tagSlug });
165
- }
166
- /**
167
- * Search tags by alias
168
- *
169
- * @param alias - The alias to search for
170
- * @param language - Optional language filter
171
- * @returns Array of matching tags
172
- */
173
- static async searchByAlias(_alias, _language) {
174
- return [];
175
- }
176
- /**
177
- * Get all aliases for a tag
178
- *
179
- * @param tagSlug - The tag slug to get aliases for
180
- * @returns Array of TagAlias instances
181
- */
182
- static async getAliasesForTag(_tagSlug) {
183
- return [];
184
- }
185
- };
186
- __decorateClass$9([field({ required: true })], TagAlias.prototype, "alias", 2);
187
- __decorateClass$9([tenantId({ nullable: true })], TagAlias.prototype, "tenantId", 2);
188
- TagAlias = __decorateClass$9([TenantScoped({ mode: "optional" }), smrt({
189
- tableStrategy: "sti",
190
- api: { include: [
191
- "list",
192
- "get",
193
- "create",
194
- "update",
195
- "delete"
196
- ] },
197
- mcp: { include: [
198
- "list",
199
- "get",
200
- "create"
201
- ] },
202
- cli: { skipApiCheck: true }
203
- })], TagAlias);
204
- var tag_aliases_exports = /* @__PURE__ */ __exportAll$1({ TagAliasCollection: () => TagAliasCollection });
205
- var TagAliasCollection = class extends SmrtCollection {
206
- static _itemClass = TagAlias;
207
- /**
208
- * Add an alias to a tag (get or create)
209
- *
210
- * @param tagSlug - The tag slug
211
- * @param alias - The alias text
212
- * @param language - Optional language code
213
- * @param context - Optional context
214
- * @returns TagAlias instance
215
- */
216
- async addAlias(tagSlug, alias, language, context) {
217
- const where = {
218
- tagSlug,
219
- alias
220
- };
221
- if (language) where.language = language;
222
- if (context) where.context = context;
223
- const existing = await this.list({
224
- where,
225
- limit: 1
226
- });
227
- if (existing.length > 0) return existing[0];
228
- return await this.create({
229
- tagSlug,
230
- alias,
231
- language,
232
- context
233
- });
234
- }
235
- /**
236
- * Search tags by alias
237
- *
238
- * @param alias - The alias to search for
239
- * @param language - Optional language filter
240
- * @returns Array of matching tags
241
- */
242
- async searchByAlias(alias, language) {
243
- const where = { alias };
244
- if (language) where.language = language;
245
- const aliases = await this.list({ where });
246
- const tagSlugs = [...new Set(aliases.map((a) => a.tagSlug))];
247
- const { TagCollection } = await Promise.resolve().then(() => tags_exports);
248
- const tagCollection = await TagCollection.create(this.options);
249
- const tags = [];
250
- for (const slug of tagSlugs) {
251
- const tag = await tagCollection.get({ slug });
252
- if (tag) tags.push(tag);
253
- }
254
- return tags;
255
- }
256
- /**
257
- * Get all aliases for a tag
258
- *
259
- * @param tagSlug - The tag slug
260
- * @param language - Optional language filter
261
- * @returns Array of TagAlias instances
262
- */
263
- async getAliasesForTag(tagSlug, language) {
264
- const where = { tagSlug };
265
- if (language) where.language = language;
266
- return await this.list({ where });
267
- }
268
- /**
269
- * Remove an alias by ID
270
- *
271
- * @param aliasId - The alias UUID
272
- */
273
- async removeAlias(aliasId) {
274
- const alias = await this.get({ id: aliasId });
275
- if (alias) await alias.delete();
276
- }
277
- /**
278
- * Bulk add aliases to a tag
279
- *
280
- * @param tagSlug - The tag slug
281
- * @param aliases - Array of alias configurations
282
- * @returns Array of created TagAlias instances
283
- */
284
- async bulkAddAliases(tagSlug, aliases) {
285
- const created = [];
286
- for (const aliasData of aliases) {
287
- const tagAlias = await this.addAlias(tagSlug, aliasData.alias, aliasData.language, aliasData.context);
288
- created.push(tagAlias);
289
- }
290
- return created;
291
- }
292
- /**
293
- * Get aliases grouped by language
294
- *
295
- * @param tagSlug - The tag slug
296
- * @returns Map of language code to array of aliases
297
- */
298
- async getAliasesByLanguage(tagSlug) {
299
- const aliases = await this.getAliasesForTag(tagSlug);
300
- const grouped = /* @__PURE__ */ new Map();
301
- for (const alias of aliases) {
302
- const lang = String(alias.language || "default");
303
- if (!grouped.has(lang)) grouped.set(lang, []);
304
- grouped.get(lang)?.push(String(alias.alias));
305
- }
306
- return grouped;
307
- }
308
- /**
309
- * Find matching aliases (case-insensitive partial match)
310
- *
311
- * Note: This is a simple implementation. For production use,
312
- * consider using full-text search or fuzzy matching.
313
- *
314
- * @param query - The search query
315
- * @param language - Optional language filter
316
- * @returns Array of matching TagAlias instances
317
- */
318
- async findMatchingAliases(query, language) {
319
- const where = {};
320
- if (language) where.language = language;
321
- const all = await this.list({ where });
322
- const queryLower = query.toLowerCase();
323
- return all.filter((alias) => String(alias.alias).toLowerCase().includes(queryLower));
324
- }
325
- /**
326
- * Find all tag aliases belonging to a specific tenant
327
- *
328
- * @param tenantId - The tenant ID to filter by
329
- * @returns Array of tag aliases for the specified tenant
330
- */
331
- async findByTenant(tenantId) {
332
- return this.list({ where: { tenantId } });
333
- }
334
- /**
335
- * Find all global (tenant-less) tag aliases.
336
- *
337
- * Routes through the shared tenant-global helper so it does not throw under
338
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
339
- * flagged as an isolation violation). (#1600)
340
- *
341
- * @returns Array of global tag aliases with null tenantId
342
- */
343
- async findGlobal() {
344
- return queryGlobal(this);
345
- }
346
- /**
347
- * Find tag aliases for a tenant including global aliases.
348
- *
349
- * Fails closed if an active tenant context requests a different tenant's
350
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
351
- *
352
- * @param tenantId - The tenant ID to filter by
353
- * @returns Array of tag aliases for the tenant plus all global aliases
354
- */
355
- async findWithGlobals(tenantId) {
356
- return queryWithGlobals(this, tenantId, "TagAlias.findWithGlobals");
357
- }
358
- };
359
- var tags_exports = /* @__PURE__ */ __exportAll$1({ TagCollection: () => TagCollection });
360
- var TagCollection = class extends SmrtCollection {
361
- static _itemClass = Tag;
362
- /**
363
- * Get or create a tag with context
364
- *
365
- * @param slug - Tag slug
366
- * @param context - Tag context (default: 'global')
367
- * @returns Tag instance
368
- */
369
- async getOrCreate(slug, context = "global") {
370
- const existing = await this.list({
371
- where: {
372
- slug,
373
- context
374
- },
375
- limit: 1
376
- });
377
- if (existing.length > 0) return existing[0];
378
- return await this.create({
379
- slug,
380
- name: slug.replace(/-/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
381
- context,
382
- level: 0
383
- });
384
- }
385
- /**
386
- * Resolve a tag by slug, optionally scoped to a context.
387
- *
388
- * Tags are identified by `(slug, context)`. When `context` is omitted
389
- * and the slug exists in more than one context, this throws a clear
390
- * ambiguity error rather than silently picking the first matching row.
391
- * Callers that know their context should pass it; callers that work in
392
- * a single-context world can leave it off.
393
- *
394
- * @returns The matching Tag, or `null` if nothing matches.
395
- * @throws Error if `context` is omitted and the slug is ambiguous.
396
- */
397
- async resolveBySlug(slug, context) {
398
- const where = { slug };
399
- if (context !== void 0) where.context = context;
400
- const matches = await this.list({
401
- where,
402
- limit: 2
403
- });
404
- if (matches.length === 0) return null;
405
- if (matches.length > 1) throw new Error(`Tag slug '${slug}' is ambiguous: resolves to ${matches.length}+ rows across contexts. Pass an explicit \`context\` argument.`);
406
- return matches[0];
407
- }
408
- /**
409
- * List tags by context with optional parent filtering by slug.
410
- *
411
- * @param context - The context to filter by
412
- * @param parentSlug - Optional parent slug to filter children. Pass an
413
- * empty string or `null` to find root tags; pass a slug to find that
414
- * tag's immediate children. Typed as `string | null` so TypeScript
415
- * callers can pass `null` without a cast — the `null` and `''` paths
416
- * are both treated as "roots only".
417
- * @returns Array of matching tags
418
- */
419
- async listByContext(context, parentSlug) {
420
- const where = { context };
421
- if (parentSlug === "" || parentSlug === null) where.parentId = null;
422
- else if (parentSlug !== void 0) {
423
- const parent = await this.get({
424
- slug: parentSlug,
425
- context
426
- });
427
- if (!parent?.id) return [];
428
- where.parentId = parent.id;
429
- }
430
- return await this.list({ where });
431
- }
432
- /**
433
- * Get root tags (no parent) for a context
434
- *
435
- * @param context - The context to filter by (default: 'global')
436
- * @returns Array of root tags
437
- */
438
- async getRootTags(context = "global") {
439
- return await this.list({ where: {
440
- context,
441
- parentId: null
442
- } });
443
- }
444
- /**
445
- * Get immediate children of a parent tag, looked up by slug.
446
- *
447
- * @param parentSlug - The parent tag slug
448
- * @param context - Optional context for the parent lookup. When omitted,
449
- * the parent slug must be unambiguous across contexts (throws if not).
450
- * @returns Array of child tags, or `[]` if the parent slug doesn't
451
- * resolve. Children are filtered to the resolved parent's context so
452
- * cross-context children don't leak in.
453
- */
454
- async getChildren(parentSlug, context) {
455
- const parent = await this.resolveBySlug(parentSlug, context);
456
- if (!parent?.id) return [];
457
- return await this.list({ where: {
458
- parentId: parent.id,
459
- context: parent.context
460
- } });
461
- }
462
- /**
463
- * Get tag hierarchy (all ancestors and descendants)
464
- *
465
- * @param slug - The tag slug
466
- * @param context - Optional context for the slug lookup. When omitted,
467
- * the slug must be unambiguous across contexts.
468
- * @returns Object with ancestors, current tag, and descendants
469
- */
470
- async getHierarchy(slug, context) {
471
- const tag = await this.resolveBySlug(slug, context);
472
- if (!tag) throw new Error(`Tag '${slug}' not found`);
473
- const [ancestors, descendants] = await Promise.all([tag.getAncestors(), tag.getDescendants()]);
474
- return {
475
- ancestors,
476
- current: tag,
477
- descendants
478
- };
479
- }
480
- /**
481
- * Move a tag to a new parent. Slug-based API; UUIDs resolved internally.
482
- *
483
- * Cycle detection is inlined here (mirroring `SmrtHierarchical.moveTo`'s
484
- * self-loop + descendant checks) so that both `parentId` and the
485
- * denormalised `level` field can be persisted in a single `save()`.
486
- * Delegating to `moveTo` would write `parentId` first and `level` in a
487
- * second save — if the second save failed, the tag would be left with
488
- * the new parent but a stale level, breaking the depth cache.
489
- *
490
- * After the moved tag persists, descendant levels are recalculated
491
- * recursively via `updateDescendantLevels`.
492
- *
493
- * @param slug - The tag to move
494
- * @param newParentSlug - The new parent slug (null for root)
495
- * @param context - Optional context. When provided, both source and new
496
- * parent are resolved within it. When omitted, both slugs must be
497
- * unambiguous across contexts; the resolver throws otherwise.
498
- * @throws Error if either slug fails to resolve, if either slug is
499
- * ambiguous across contexts (no context provided), if source and new
500
- * parent live in different contexts, or if the move would create a
501
- * cycle.
502
- */
503
- async moveTag(slug, newParentSlug, context) {
504
- const tag = await this.resolveBySlug(slug, context);
505
- if (!tag) throw new Error(`Tag '${slug}' not found`);
506
- let newParent = null;
507
- if (newParentSlug) {
508
- newParent = await this.resolveBySlug(newParentSlug, context ?? tag.context);
509
- if (!newParent) throw new Error(`Tag '${newParentSlug}' not found`);
510
- if (newParent.context !== tag.context) throw new Error(`Cannot move Tag '${slug}' (context '${tag.context}') under '${newParentSlug}' (context '${newParent.context}') \u2014 contexts must match.`);
511
- }
512
- const newParentId = newParent?.id ?? null;
513
- if (newParentId !== null && newParentId === tag.id) throw new Error(`Cannot move Tag ${tag.id} to itself.`);
514
- if (newParentId !== null) {
515
- if ((await tag.getDescendants()).some((d) => d.id === newParentId)) throw new Error(`Cannot move Tag ${tag.id} under one of its own descendants (${newParentId}) \u2014 would create a cycle.`);
516
- }
517
- tag.parentId = newParentId;
518
- tag.level = newParent ? newParent.level + 1 : 0;
519
- await tag.save();
520
- await this.updateDescendantLevels(tag);
521
- }
522
- /**
523
- * Merge one tag into another (updates all references)
524
- *
525
- * Reparents `fromTag`'s direct children onto `toTag` and recalculates
526
- * their `level` field plus the level of every descendant — without
527
- * this, children moved from a different depth would carry stale
528
- * levels relative to their new parent. `TagAlias.tagSlug` references
529
- * are also rewritten, then `fromTag` is deleted.
530
- *
531
- * Note: Consuming packages are responsible for updating their own
532
- * join tables (e.g. `asset_tags`).
533
- *
534
- * @param fromSlug - The tag to merge from
535
- * @param toSlug - The tag to merge into
536
- * @param context - Optional context. When provided, both tags are
537
- * resolved within it. When omitted, both slugs must be unambiguous
538
- * across contexts.
539
- * @throws Error if either slug fails to resolve, if either slug is
540
- * ambiguous, or if the two tags live in different contexts.
541
- */
542
- async mergeTag(fromSlug, toSlug, context) {
543
- const fromTag = await this.resolveBySlug(fromSlug, context);
544
- const toTag = await this.resolveBySlug(toSlug, context ?? fromTag?.context);
545
- if (!fromTag) throw new Error(`Source tag '${fromSlug}' not found`);
546
- if (!toTag) throw new Error(`Target tag '${toSlug}' not found`);
547
- if (!fromTag.id) throw new Error(`Source tag '${fromSlug}' has no id`);
548
- if (!toTag.id) throw new Error(`Target tag '${toSlug}' has no id`);
549
- if (fromTag.context !== toTag.context) throw new Error(`Cannot merge '${fromSlug}' (context '${fromTag.context}') into '${toSlug}' (context '${toTag.context}') \u2014 contexts must match.`);
550
- if (fromTag.id === toTag.id) throw new Error(`Cannot merge tag '${fromSlug}' into itself.`);
551
- if ((await fromTag.getDescendants()).some((d) => d.id === toTag.id)) throw new Error(`Cannot merge '${fromSlug}' into '${toSlug}' \u2014 target is a descendant of source (would create a cycle).`);
552
- const children = await this.list({ where: { parentId: fromTag.id } });
553
- const newChildLevel = toTag.level + 1;
554
- for (const child of children) {
555
- child.parentId = toTag.id;
556
- child.level = newChildLevel;
557
- await child.save();
558
- await this.updateDescendantLevels(child);
559
- }
560
- const { TagAliasCollection } = await Promise.resolve().then(() => tag_aliases_exports);
561
- const aliasCollection = await TagAliasCollection.create(this.options);
562
- const aliasContexts = [fromTag.context];
563
- if (fromTag.context === "global") aliasContexts.push("");
564
- const aliases = await aliasCollection.list({ where: {
565
- tagSlug: fromSlug,
566
- context: aliasContexts
567
- } });
568
- for (const alias of aliases) {
569
- alias.tagSlug = toSlug;
570
- await alias.save();
571
- }
572
- await this.repointTagReferences(fromTag.id, toTag.id);
573
- await fromTag.delete();
574
- }
575
- /**
576
- * Move every reference to tag `fromId` onto `toId`. A row whose natural key
577
- * includes the tag column and that already exists for `toId` (an asset
578
- * tagged with both) is a duplicate after the merge and is removed instead.
579
- * Rows are matched by tag id, which is specific to one tenant's tag, so
580
- * this reads and writes through the adapter directly.
581
- */
582
- async repointTagReferences(fromId, toId) {
583
- const tagClass = ObjectRegistry.getClassByConstructor(Tag)?.qualifiedName ?? "Tag";
584
- const tagTable = ObjectRegistry.getTableName(tagClass);
585
- for (const reference of ObjectRegistry.getIncomingReferences(tagClass)) {
586
- if (reference.tableName === tagTable) continue;
587
- if (!await this.db.tableExists(reference.tableName)) continue;
588
- const conflictColumns = ObjectRegistry.getConflictColumns(reference.className);
589
- const keyed = conflictColumns.includes(reference.column) && !(conflictColumns.length === 1 && conflictColumns[0] === "id");
590
- const rows = await this.db.list(reference.tableName, { [reference.column]: fromId });
591
- for (const row of rows) {
592
- if (keyed) {
593
- const probe = {};
594
- for (const column of conflictColumns) probe[column] = column === reference.column ? toId : row[column];
595
- if (await this.db.get(reference.tableName, probe)) {
596
- await this.db.delete(reference.tableName, { id: row.id });
597
- continue;
598
- }
599
- }
600
- await this.db.update(reference.tableName, { id: row.id }, { [reference.column]: toId });
601
- }
602
- }
603
- }
604
- /**
605
- * Remove tags with no references (cleanup unused tags)
606
- *
607
- * Note: This requires consuming packages to provide usage information.
608
- * By default, only removes tags with no children and no aliases.
609
- *
610
- * @param context - Optional context to filter cleanup
611
- */
612
- async cleanupUnused(context) {
613
- const where = {};
614
- if (context) where.context = context;
615
- const tags = await this.list({ where });
616
- const { TagAliasCollection } = await Promise.resolve().then(() => tag_aliases_exports);
617
- const aliasCollection = await TagAliasCollection.create(this.options);
618
- let deletedCount = 0;
619
- for (const tag of tags) {
620
- if (!tag.id) continue;
621
- if ((await this.list({
622
- where: { parentId: tag.id },
623
- limit: 1
624
- })).length > 0) continue;
625
- if ((await aliasCollection.list({
626
- where: { tagSlug: tag.slug },
627
- limit: 1
628
- })).length > 0) continue;
629
- await tag.delete();
630
- deletedCount++;
631
- }
632
- return deletedCount;
633
- }
634
- /**
635
- * Calculate hierarchy level for a tag, looking the parent up by slug.
636
- *
637
- * @param parentSlug - The parent tag slug (null/empty for root)
638
- * @param context - Optional context for the parent lookup. When
639
- * omitted, the parent slug must be unambiguous across contexts.
640
- * @returns The calculated level (root parent → 1, missing parent → 0)
641
- */
642
- async calculateLevel(parentSlug, context) {
643
- if (!parentSlug) return 0;
644
- const parent = await this.resolveBySlug(parentSlug, context);
645
- if (!parent) return 0;
646
- return parent.level + 1;
647
- }
648
- /**
649
- * Update levels for all descendants after moving a tag
650
- *
651
- * @param tag - The tag that was moved
652
- */
653
- async updateDescendantLevels(tag) {
654
- if (!tag.id) return;
655
- const children = await this.list({ where: { parentId: tag.id } });
656
- for (const child of children) {
657
- child.level = tag.level + 1;
658
- await child.save();
659
- await this.updateDescendantLevels(child);
660
- }
661
- }
662
- /**
663
- * Find all tags belonging to a specific tenant
664
- *
665
- * @param tenantId - The tenant ID to filter by
666
- * @returns Array of tags for the specified tenant
667
- */
668
- async findByTenant(tenantId) {
669
- return this.list({ where: { tenantId } });
670
- }
671
- /**
672
- * Find all global (tenant-less) tags.
673
- *
674
- * Routes through the shared tenant-global helper so it does not throw under
675
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
676
- * flagged as an isolation violation). (#1600)
677
- *
678
- * @returns Array of global tags with null tenantId
679
- */
680
- async findGlobal() {
681
- return queryGlobal(this);
682
- }
683
- /**
684
- * Find tags for a tenant including global tags.
685
- *
686
- * Fails closed if an active tenant context requests a different tenant's
687
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
688
- *
689
- * @param tenantId - The tenant ID to filter by
690
- * @returns Array of tags for the tenant plus all global tags
691
- */
692
- async findWithGlobals(tenantId) {
693
- return queryWithGlobals(this, tenantId, "Tag.findWithGlobals");
694
- }
695
- };
696
- //#endregion
697
- //#region ../assets/dist/index.js
698
- var __defProp$9 = Object.defineProperty;
699
- var __exportAll = (all, no_symbols) => {
700
- let target = {};
701
- for (var name in all) __defProp$9(target, name, {
702
- get: all[name],
703
- enumerable: true
704
- });
705
- if (!no_symbols) __defProp$9(target, Symbol.toStringTag, { value: "Module" });
706
- return target;
707
- };
708
- ObjectRegistry.registerPackageManifest(JSON.parse("{\"version\":\"1.0.0\",\"timestamp\":0,\"packageName\":\"@happyvertical/smrt-assets\",\"packageVersion\":\"0.54.2\",\"objects\":{\"@happyvertical/smrt-assets:AssetAssociation\":{\"name\":\"assetassociation\",\"className\":\"AssetAssociation\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetAssociation\",\"collection\":\"assetassociations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-association.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"metaType\":{\"type\":\"text\",\"required\":true,\"_meta\":{\"required\":true}},\"metaId\":{\"type\":\"text\",\"required\":true,\"_meta\":{\"required\":true}},\"role\":{\"type\":\"text\",\"required\":true,\"_meta\":{\"required\":true}},\"sortOrder\":{\"type\":\"integer\",\"required\":false,\"default\":0},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"assetId\":{\"type\":\"foreignKey\",\"required\":true,\"related\":\"Asset\",\"_meta\":{\"required\":true}}},\"methods\":{\"hydrate\":{\"name\":\"hydrate\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<T | null>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"conflictColumns\":[\"asset_id\",\"meta_type\",\"meta_id\",\"role\"],\"api\":{\"include\":[\"list\",\"get\",\"create\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtPolymorphicAssociation\",\"exportName\":\"AssetAssociation\",\"collectionExportName\":\"AssetAssociationCollection\",\"validationRules\":[{\"field\":\"metaType\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"metaId\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"role\",\"rule\":\"required\",\"fieldType\":\"text\"},{\"field\":\"assetId\",\"rule\":\"required\",\"fieldType\":\"foreignKey\"}],\"schema\":{\"tableName\":\"asset_associations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_associations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"meta_type\\\" TEXT NOT NULL,\\n \\\"meta_id\\\" TEXT NOT NULL,\\n \\\"role\\\" TEXT NOT NULL,\\n \\\"sort_order\\\" INTEGER DEFAULT 0,\\n \\\"tenant_id\\\" UUID,\\n \\\"asset_id\\\" UUID NOT NULL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"meta_type\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"meta_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"role\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"sort_order\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false,\"default\":0},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":true,\"unique\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"CASCADE\",\"onUpdate\":\"CASCADE\"}}},\"indexes\":[{\"name\":\"asset_associations_asset_id_meta_type_idx\",\"columns\":[\"asset_id\",\"meta_type\",\"meta_id\",\"role\"],\"unique\":true},{\"name\":\"asset_associations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"asset_associations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"asset_associations_meta_type_meta_id_idx\",\"columns\":[\"meta_type\",\"meta_id\"]}],\"version\":\"faa13cea\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetAssociationCollection\":{\"name\":\"assetassociationcollection\",\"className\":\"AssetAssociationCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetAssociationCollection\",\"collection\":\"assetassociations\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-associations.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"byLeft\":{\"name\":\"byLeft\",\"async\":true,\"parameters\":[{\"name\":\"metaType\",\"type\":\"string\",\"optional\":false},{\"name\":\"metaId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<AssetAssociation[]>\",\"isStatic\":false,\"isPublic\":true},\"byRight\":{\"name\":\"byRight\",\"async\":true,\"parameters\":[{\"name\":\"rightId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<TItem[]>\",\"isStatic\":false,\"isPublic\":true},\"attach\":{\"name\":\"attach\",\"async\":true,\"parameters\":[{\"name\":\"metaType\",\"type\":\"string\",\"optional\":false},{\"name\":\"metaId\",\"type\":\"string\",\"optional\":false},{\"name\":\"assetId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionAttachOptions\",\"optional\":true}],\"returnType\":\"Promise<AssetAssociation>\",\"isStatic\":false,\"isPublic\":true},\"detach\":{\"name\":\"detach\",\"async\":true,\"parameters\":[{\"name\":\"metaType\",\"type\":\"string\",\"optional\":false},{\"name\":\"metaId\",\"type\":\"string\",\"optional\":false},{\"name\":\"assetId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"setLinks\":{\"name\":\"setLinks\",\"async\":true,\"parameters\":[{\"name\":\"metaType\",\"type\":\"string\",\"optional\":false},{\"name\":\"metaId\",\"type\":\"string\",\"optional\":false},{\"name\":\"assetIds\",\"type\":\"string[]\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionAttachOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtJunction\",\"extendsTypeArg\":\"AssetAssociation\",\"exportName\":\"AssetAssociationCollection\",\"collectionExportName\":\"AssetAssociationCollectionCollection\",\"schema\":{\"tableName\":\"asset_associations\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_associations\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"meta_type\\\" TEXT NOT NULL,\\n \\\"meta_id\\\" TEXT NOT NULL,\\n \\\"role\\\" TEXT NOT NULL,\\n \\\"sort_order\\\" INTEGER DEFAULT 0,\\n \\\"tenant_id\\\" UUID,\\n \\\"asset_id\\\" UUID NOT NULL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"meta_type\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"meta_id\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"role\":{\"type\":\"TEXT\",\"notNull\":true,\"unique\":false},\"sort_order\":{\"type\":\"INTEGER\",\"notNull\":false,\"unique\":false,\"default\":0},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":true,\"unique\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"CASCADE\",\"onUpdate\":\"CASCADE\"}}},\"indexes\":[{\"name\":\"asset_associations_asset_id_meta_type_idx\",\"columns\":[\"asset_id\",\"meta_type\",\"meta_id\",\"role\"],\"unique\":true},{\"name\":\"asset_associations_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"asset_associations_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"asset_associations_meta_type_meta_id_idx\",\"columns\":[\"meta_type\",\"meta_id\"]}],\"version\":\"faa13cea\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetMetafield\":{\"name\":\"assetmetafield\",\"className\":\"AssetMetafield\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetMetafield\",\"collection\":\"assetmetafields\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-metafield.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"name\":{\"type\":\"text\",\"required\":false},\"validation\":{\"type\":\"text\",\"required\":false}},\"methods\":{\"getValidation\":{\"name\":\"getValidation\",\"async\":false,\"parameters\":[],\"returnType\":\"Record<string, unknown>\",\"isStatic\":false,\"isPublic\":true},\"setValidation\":{\"name\":\"setValidation\",\"async\":false,\"parameters\":[{\"name\":\"rules\",\"type\":\"Record<string, unknown>\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AssetMetafield | null>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\"]},\"cli\":{\"skipApiCheck\":true}},\"extends\":\"SmrtObject\",\"exportName\":\"AssetMetafield\",\"collectionExportName\":\"AssetMetafieldCollection\",\"schema\":{\"tableName\":\"asset_metafields\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_metafields\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"validation\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"validation\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_metafields_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_metafields_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_metafields_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"7393718c\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetMetafieldCollection\":{\"name\":\"assetmetafieldcollection\",\"className\":\"AssetMetafieldCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetMetafieldCollection\",\"collection\":\"assetmetafields\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-metafields.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"getOrCreate\":{\"name\":\"getOrCreate\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"name\",\"type\":\"string\",\"optional\":true},{\"name\":\"validation\",\"type\":\"string | Record<string, unknown>\",\"optional\":true,\"unionBranches\":[{\"type\":\"string\"},{\"type\":\"Record<string, unknown>\"}]}],\"returnType\":\"Promise<AssetMetafield>\",\"isStatic\":false,\"isPublic\":true},\"initializeCommonMetafields\":{\"name\":\"initializeCommonMetafields\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AssetMetafield\",\"exportName\":\"AssetMetafieldCollection\",\"collectionExportName\":\"AssetMetafieldCollectionCollection\",\"schema\":{\"tableName\":\"asset_metafields\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_metafields\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"validation\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"validation\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_metafields_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_metafields_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_metafields_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"7393718c\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetStatus\":{\"name\":\"assetstatus\",\"className\":\"AssetStatus\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetStatus\",\"collection\":\"assetstatuses\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-status.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"name\":{\"type\":\"text\",\"required\":false},\"description\":{\"type\":\"text\",\"required\":false}},\"methods\":{\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AssetStatus | null>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\"]},\"cli\":{\"skipApiCheck\":true}},\"extends\":\"SmrtObject\",\"exportName\":\"AssetStatus\",\"collectionExportName\":\"AssetStatusCollection\",\"schema\":{\"tableName\":\"asset_statuses\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_statuses\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_statuses_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_statuses_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_statuses_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"8251a52f\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetStatusCollection\":{\"name\":\"assetstatuscollection\",\"className\":\"AssetStatusCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetStatusCollection\",\"collection\":\"assetstatuses\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-statuses.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"getOrCreate\":{\"name\":\"getOrCreate\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"name\",\"type\":\"string\",\"optional\":true},{\"name\":\"description\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<AssetStatus>\",\"isStatic\":false,\"isPublic\":true},\"initializeCommonStatuses\":{\"name\":\"initializeCommonStatuses\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AssetStatus\",\"exportName\":\"AssetStatusCollection\",\"collectionExportName\":\"AssetStatusCollectionCollection\",\"schema\":{\"tableName\":\"asset_statuses\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_statuses\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_statuses_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_statuses_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_statuses_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"8251a52f\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetTag\":{\"name\":\"assettag\",\"className\":\"AssetTag\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetTag\",\"collection\":\"assettags\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-tag.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"assetId\":{\"type\":\"foreignKey\",\"required\":true,\"related\":\"Asset\",\"_meta\":{\"required\":true,\"onDelete\":\"CASCADE\"}},\"tagId\":{\"type\":\"crossPackageRef\",\"required\":true,\"related\":\"@happyvertical/smrt-tags:Tag\",\"_meta\":{\"onDelete\":\"CASCADE\"}}},\"methods\":{},\"decoratorConfig\":{\"tableName\":\"asset_tags\",\"conflictColumns\":[\"asset_id\",\"tag_id\"],\"api\":false,\"mcp\":false,\"cli\":false,\"tenantScoped\":{\"mode\":\"optional\"}},\"extends\":\"SmrtObject\",\"exportName\":\"AssetTag\",\"collectionExportName\":\"AssetTagCollection\",\"validationRules\":[{\"field\":\"assetId\",\"rule\":\"required\",\"fieldType\":\"foreignKey\"},{\"field\":\"tagId\",\"rule\":\"required\",\"fieldType\":\"crossPackageRef\"}],\"schema\":{\"tableName\":\"asset_tags\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_tags\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"asset_id\\\" UUID NOT NULL,\\n \\\"tag_id\\\" UUID NOT NULL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":true,\"unique\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"CASCADE\",\"onUpdate\":\"CASCADE\"}},\"tag_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":true,\"unique\":false}},\"indexes\":[{\"name\":\"asset_tags_asset_id_tag_id_idx\",\"columns\":[\"asset_id\",\"tag_id\"],\"unique\":true},{\"name\":\"asset_tags_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"asset_tags_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"asset_tags_tag_id_idx\",\"columns\":[\"tag_id\"]}],\"version\":\"e60d24f5\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetTagCollection\":{\"name\":\"assettagcollection\",\"className\":\"AssetTagCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetTagCollection\",\"collection\":\"assettags\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-tags.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"byLeft\":{\"name\":\"byLeft\",\"async\":true,\"parameters\":[{\"name\":\"leftId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<TItem[]>\",\"isStatic\":false,\"isPublic\":true},\"byRight\":{\"name\":\"byRight\",\"async\":true,\"parameters\":[{\"name\":\"rightId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<TItem[]>\",\"isStatic\":false,\"isPublic\":true},\"attach\":{\"name\":\"attach\",\"async\":true,\"parameters\":[{\"name\":\"leftId\",\"type\":\"string\",\"optional\":false},{\"name\":\"rightId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionAttachOptions\",\"optional\":true}],\"returnType\":\"Promise<TItem>\",\"isStatic\":false,\"isPublic\":true},\"detach\":{\"name\":\"detach\",\"async\":true,\"parameters\":[{\"name\":\"leftId\",\"type\":\"string\",\"optional\":false},{\"name\":\"rightId\",\"type\":\"string\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionFilterOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"setLinks\":{\"name\":\"setLinks\",\"async\":true,\"parameters\":[{\"name\":\"leftId\",\"type\":\"string\",\"optional\":false},{\"name\":\"rightIds\",\"type\":\"string[]\",\"optional\":false},{\"name\":\"opts\",\"type\":\"JunctionAttachOptions\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{\"tableName\":\"asset_tags\",\"api\":false,\"mcp\":false,\"cli\":false},\"extends\":\"SmrtJunction\",\"extendsTypeArg\":\"AssetTag\",\"exportName\":\"AssetTagCollection\",\"collectionExportName\":\"AssetTagCollectionCollection\",\"schema\":{\"tableName\":\"asset_tags\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_tags\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"asset_id\\\" UUID NOT NULL,\\n \\\"tag_id\\\" UUID NOT NULL\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":true,\"unique\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"CASCADE\",\"onUpdate\":\"CASCADE\"}},\"tag_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":true,\"unique\":false}},\"indexes\":[{\"name\":\"asset_tags_asset_id_tag_id_idx\",\"columns\":[\"asset_id\",\"tag_id\"],\"unique\":true},{\"name\":\"asset_tags_slug_context_idx\",\"columns\":[\"slug\",\"context\"]},{\"name\":\"asset_tags_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"asset_tags_tag_id_idx\",\"columns\":[\"tag_id\"]}],\"version\":\"e60d24f5\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetType\":{\"name\":\"assettype\",\"className\":\"AssetType\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetType\",\"collection\":\"assettypes\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-type.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"name\":{\"type\":\"text\",\"required\":false},\"description\":{\"type\":\"text\",\"required\":false}},\"methods\":{\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<AssetType | null>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\"]},\"cli\":{\"skipApiCheck\":true}},\"extends\":\"SmrtObject\",\"exportName\":\"AssetType\",\"collectionExportName\":\"AssetTypeCollection\",\"schema\":{\"tableName\":\"asset_types\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_types\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_types_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_types_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_types_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"a9c93be2\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetTypeCollection\":{\"name\":\"assettypecollection\",\"className\":\"AssetTypeCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetTypeCollection\",\"collection\":\"assettypes\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset-types.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"getOrCreate\":{\"name\":\"getOrCreate\",\"async\":true,\"parameters\":[{\"name\":\"slug\",\"type\":\"string\",\"optional\":false},{\"name\":\"name\",\"type\":\"string\",\"optional\":true},{\"name\":\"description\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<AssetType>\",\"isStatic\":false,\"isPublic\":true},\"initializeCommonTypes\":{\"name\":\"initializeCommonTypes\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"AssetType\",\"exportName\":\"AssetTypeCollection\",\"collectionExportName\":\"AssetTypeCollectionCollection\",\"schema\":{\"tableName\":\"asset_types\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"asset_types\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"asset_types_slug_context_meta_type_idx\",\"columns\":[\"slug\",\"context\",\"_meta_type\"],\"unique\":true},{\"name\":\"asset_types_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"asset_types_created_at_idx\",\"columns\":[\"created_at\"]}],\"version\":\"a9c93be2\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:Asset\":{\"name\":\"asset\",\"className\":\"Asset\",\"qualifiedName\":\"@happyvertical/smrt-assets:Asset\",\"collection\":\"assets\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/asset.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"created_at\":{\"type\":\"datetime\",\"required\":false},\"updated_at\":{\"type\":\"datetime\",\"required\":false},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"name\":{\"type\":\"text\",\"required\":false},\"sourceUri\":{\"type\":\"text\",\"required\":false},\"mimeType\":{\"type\":\"text\",\"required\":false},\"description\":{\"type\":\"text\",\"required\":false},\"metadata\":{\"type\":\"text\",\"required\":false},\"version\":{\"type\":\"integer\",\"required\":true,\"default\":1},\"primaryVersionId\":{\"type\":\"foreignKey\",\"required\":false,\"related\":\"Asset\"},\"typeSlug\":{\"type\":\"text\",\"required\":false},\"statusSlug\":{\"type\":\"text\",\"required\":false},\"ownerProfileId\":{\"type\":\"crossPackageRef\",\"required\":false,\"related\":\"@happyvertical/smrt-profiles:Profile\"},\"sourceAssetId\":{\"type\":\"foreignKey\",\"required\":false,\"related\":\"Asset\"},\"folderId\":{\"type\":\"foreignKey\",\"required\":false,\"related\":\"Folder\"},\"sourceType\":{\"type\":\"text\",\"required\":false},\"externalId\":{\"type\":\"text\",\"required\":false},\"externalRefs\":{\"type\":\"text\",\"required\":false},\"createdAt\":{\"type\":\"text\",\"required\":false},\"updatedAt\":{\"type\":\"text\",\"required\":false}},\"methods\":{\"getSlug\":{\"name\":\"getSlug\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<string | null | undefined>\",\"isStatic\":false,\"isPublic\":true},\"getMetadata\":{\"name\":\"getMetadata\",\"async\":false,\"parameters\":[],\"returnType\":\"Record<string, unknown>\",\"isStatic\":false,\"isPublic\":true},\"setMetadata\":{\"name\":\"setMetadata\",\"async\":false,\"parameters\":[{\"name\":\"metadata\",\"type\":\"Record<string, unknown>\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"mergeMetadata\":{\"name\":\"mergeMetadata\",\"async\":false,\"parameters\":[{\"name\":\"metadata\",\"type\":\"Record<string, unknown>\",\"optional\":false}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getExternalRefs\":{\"name\":\"getExternalRefs\",\"async\":false,\"parameters\":[],\"returnType\":\"Record<string, AssetExternalReference>\",\"isStatic\":false,\"isPublic\":true},\"getExternalRef\":{\"name\":\"getExternalRef\",\"async\":false,\"parameters\":[{\"name\":\"provider\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"AssetExternalReference | null\",\"isStatic\":false,\"isPublic\":true},\"setExternalRef\":{\"name\":\"setExternalRef\",\"async\":false,\"parameters\":[{\"name\":\"provider\",\"type\":\"string\",\"optional\":false},{\"name\":\"reference\",\"type\":\"any\",\"optional\":false,\"typeUnresolved\":true}],\"returnType\":\"void\",\"isStatic\":false,\"isPublic\":true},\"getTags\":{\"name\":\"getTags\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"hasTag\":{\"name\":\"hasTag\",\"async\":true,\"parameters\":[{\"name\":\"tagSlug\",\"type\":\"string\",\"optional\":false},{\"name\":\"context\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<boolean>\",\"isStatic\":false,\"isPublic\":true},\"getSource\":{\"name\":\"getSource\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Asset | null>\",\"isStatic\":false,\"isPublic\":true},\"getDerivatives\":{\"name\":\"getDerivatives\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getType\":{\"name\":\"getType\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AssetType | null>\",\"isStatic\":false,\"isPublic\":true},\"getStatus\":{\"name\":\"getStatus\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AssetStatus | null>\",\"isStatic\":false,\"isPublic\":true},\"getAssociations\":{\"name\":\"getAssociations\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<AssetAssociation[]>\",\"isStatic\":false,\"isPublic\":true},\"associateWith\":{\"name\":\"associateWith\",\"async\":true,\"parameters\":[{\"name\":\"metaType\",\"type\":\"string\",\"optional\":false},{\"name\":\"metaId\",\"type\":\"string\",\"optional\":false},{\"name\":\"role\",\"type\":\"any\",\"optional\":true,\"default\":\"default\"}],\"returnType\":\"Promise<AssetAssociation>\",\"isStatic\":false,\"isPublic\":true},\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset | null>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"tableStrategy\":\"sti\",\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\",\"update\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"]},\"extends\":\"SmrtObject\",\"exportName\":\"Asset\",\"collectionExportName\":\"AssetCollection\",\"validationRules\":[{\"field\":\"version\",\"rule\":\"required\",\"fieldType\":\"integer\"}],\"schema\":{\"tableName\":\"assets\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"assets\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"name\\\" TEXT,\\n \\\"source_uri\\\" TEXT,\\n \\\"mime_type\\\" TEXT,\\n \\\"description\\\" TEXT,\\n \\\"metadata\\\" TEXT,\\n \\\"version\\\" INTEGER DEFAULT 1,\\n \\\"primary_version_id\\\" UUID,\\n \\\"type_slug\\\" TEXT,\\n \\\"status_slug\\\" TEXT,\\n \\\"owner_profile_id\\\" UUID,\\n \\\"source_asset_id\\\" UUID,\\n \\\"folder_id\\\" UUID,\\n \\\"source_type\\\" TEXT,\\n \\\"external_id\\\" TEXT,\\n \\\"external_refs\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"source_uri\":{\"type\":\"TEXT\",\"notNull\":false},\"mime_type\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false},\"metadata\":{\"type\":\"TEXT\",\"notNull\":false},\"version\":{\"type\":\"INTEGER\",\"notNull\":false,\"default\":1},\"primary_version_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"type_slug\":{\"type\":\"TEXT\",\"notNull\":false},\"status_slug\":{\"type\":\"TEXT\",\"notNull\":false},\"owner_profile_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":false},\"source_asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"folder_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"folders\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false},\"external_id\":{\"type\":\"TEXT\",\"notNull\":false},\"external_refs\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"assets_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"assets_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"assets_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"assets_primary_version_id_idx\",\"columns\":[\"primary_version_id\"]},{\"name\":\"assets_owner_profile_id_idx\",\"columns\":[\"owner_profile_id\"]},{\"name\":\"assets_source_asset_id_idx\",\"columns\":[\"source_asset_id\"]},{\"name\":\"assets_folder_id_idx\",\"columns\":[\"folder_id\"]}],\"version\":\"16d6c152\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:AssetCollection\":{\"name\":\"assetcollection\",\"className\":\"AssetCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:AssetCollection\",\"collection\":\"assets\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/assets.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"findByTenant\":{\"name\":\"findByTenant\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"findGlobal\":{\"name\":\"findGlobal\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"findWithGlobals\":{\"name\":\"findWithGlobals\",\"async\":true,\"parameters\":[{\"name\":\"tenantId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"addTag\":{\"name\":\"addTag\",\"async\":true,\"parameters\":[{\"name\":\"assetId\",\"type\":\"string\",\"optional\":false},{\"name\":\"tag\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"AssetTagInput\",\"optional\":true}],\"returnType\":\"Promise<Tag>\",\"isStatic\":false,\"isPublic\":true},\"removeTag\":{\"name\":\"removeTag\",\"async\":true,\"parameters\":[{\"name\":\"assetId\",\"type\":\"string\",\"optional\":false},{\"name\":\"tag\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"Pick<AssetTagInput, 'context'>\",\"optional\":true}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"setTags\":{\"name\":\"setTags\",\"async\":true,\"parameters\":[{\"name\":\"assetId\",\"type\":\"string\",\"optional\":false},{\"name\":\"tags\",\"type\":\"string[]\",\"optional\":false},{\"name\":\"options\",\"type\":\"Pick<AssetTagInput, 'context'>\",\"optional\":true}],\"returnType\":\"Promise<Tag[]>\",\"isStatic\":false,\"isPublic\":true},\"getTagsForAssets\":{\"name\":\"getTagsForAssets\",\"async\":true,\"parameters\":[{\"name\":\"assetIds\",\"type\":\"string[]\",\"optional\":false}],\"returnType\":\"Promise<Map<string, Tag[]>>\",\"isStatic\":false,\"isPublic\":true},\"getByTag\":{\"name\":\"getByTag\",\"async\":true,\"parameters\":[{\"name\":\"tag\",\"type\":\"string\",\"optional\":false},{\"name\":\"options\",\"type\":\"Pick<AssetTagInput, 'context'>\",\"optional\":true}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getByType\":{\"name\":\"getByType\",\"async\":true,\"parameters\":[{\"name\":\"typeSlug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getByStatus\":{\"name\":\"getByStatus\",\"async\":true,\"parameters\":[{\"name\":\"statusSlug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getByOwner\":{\"name\":\"getByOwner\",\"async\":true,\"parameters\":[{\"name\":\"ownerProfileId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"createNewVersion\":{\"name\":\"createNewVersion\",\"async\":true,\"parameters\":[{\"name\":\"primaryVersionId\",\"type\":\"string\",\"optional\":false},{\"name\":\"newSourceUri\",\"type\":\"string\",\"optional\":false},{\"name\":\"updates\",\"type\":\"Partial<Asset>\",\"optional\":true}],\"returnType\":\"Promise<Asset>\",\"isStatic\":false,\"isPublic\":true},\"getLatestVersion\":{\"name\":\"getLatestVersion\",\"async\":true,\"parameters\":[{\"name\":\"primaryVersionId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset | null>\",\"isStatic\":false,\"isPublic\":true},\"listVersions\":{\"name\":\"listVersions\",\"async\":true,\"parameters\":[{\"name\":\"primaryVersionId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getDerivatives\":{\"name\":\"getDerivatives\",\"async\":true,\"parameters\":[{\"name\":\"sourceAssetId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"getByMimeType\":{\"name\":\"getByMimeType\",\"async\":true,\"parameters\":[{\"name\":\"mimePattern\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"rollbackToVersion\":{\"name\":\"rollbackToVersion\",\"async\":true,\"parameters\":[{\"name\":\"primaryVersionId\",\"type\":\"string\",\"optional\":false},{\"name\":\"targetVersion\",\"type\":\"number\",\"optional\":false}],\"returnType\":\"Promise<Asset>\",\"isStatic\":false,\"isPublic\":true},\"getByFolder\":{\"name\":\"getByFolder\",\"async\":true,\"parameters\":[{\"name\":\"folderId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"Asset\",\"exportName\":\"AssetCollection\",\"collectionExportName\":\"AssetCollectionCollection\",\"schema\":{\"tableName\":\"assets\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"assets\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"_meta_type\\\" TEXT NOT NULL,\\n \\\"_meta_data\\\" JSON,\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"tenant_id\\\" UUID,\\n \\\"name\\\" TEXT,\\n \\\"source_uri\\\" TEXT,\\n \\\"mime_type\\\" TEXT,\\n \\\"description\\\" TEXT,\\n \\\"metadata\\\" TEXT,\\n \\\"version\\\" INTEGER DEFAULT 1,\\n \\\"primary_version_id\\\" UUID,\\n \\\"type_slug\\\" TEXT,\\n \\\"status_slug\\\" TEXT,\\n \\\"owner_profile_id\\\" UUID,\\n \\\"source_asset_id\\\" UUID,\\n \\\"folder_id\\\" UUID,\\n \\\"source_type\\\" TEXT,\\n \\\"external_id\\\" TEXT,\\n \\\"external_refs\\\" TEXT\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"_meta_type\":{\"type\":\"TEXT\",\"notNull\":true},\"_meta_data\":{\"type\":\"JSON\",\"notNull\":false},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false},\"name\":{\"type\":\"TEXT\",\"notNull\":false},\"source_uri\":{\"type\":\"TEXT\",\"notNull\":false},\"mime_type\":{\"type\":\"TEXT\",\"notNull\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false},\"metadata\":{\"type\":\"TEXT\",\"notNull\":false},\"version\":{\"type\":\"INTEGER\",\"notNull\":false,\"default\":1},\"primary_version_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"type_slug\":{\"type\":\"TEXT\",\"notNull\":false},\"status_slug\":{\"type\":\"TEXT\",\"notNull\":false},\"owner_profile_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":false},\"source_asset_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"assets\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"folder_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"foreignKey\":{\"table\":\"folders\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"source_type\":{\"type\":\"TEXT\",\"notNull\":false},\"external_id\":{\"type\":\"TEXT\",\"notNull\":false},\"external_refs\":{\"type\":\"TEXT\",\"notNull\":false}},\"indexes\":[{\"name\":\"assets_slug_context_meta_type_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\",\"_meta_type\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"assets_meta_type_idx\",\"columns\":[\"_meta_type\"]},{\"name\":\"assets_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"assets_primary_version_id_idx\",\"columns\":[\"primary_version_id\"]},{\"name\":\"assets_owner_profile_id_idx\",\"columns\":[\"owner_profile_id\"]},{\"name\":\"assets_source_asset_id_idx\",\"columns\":[\"source_asset_id\"]},{\"name\":\"assets_folder_id_idx\",\"columns\":[\"folder_id\"]}],\"version\":\"16d6c152\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:Folder\":{\"name\":\"folder\",\"className\":\"Folder\",\"qualifiedName\":\"@happyvertical/smrt-assets:Folder\",\"collection\":\"folders\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/folder.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{\"parentId\":{\"type\":\"foreignKey\",\"required\":false,\"related\":\"Folder\",\"_meta\":{\"nullable\":true}},\"tenantId\":{\"type\":\"text\",\"required\":false,\"_meta\":{\"sqlType\":\"UUID\",\"nullable\":true,\"__tenancy\":{\"isTenantIdField\":true,\"autoFilter\":true,\"required\":false,\"autoPopulate\":true,\"nullable\":true,\"mode\":\"optional\",\"field\":\"tenantId\",\"allowSuperAdminBypass\":false}}},\"name\":{\"type\":\"text\",\"required\":false},\"description\":{\"type\":\"text\",\"required\":false},\"ownerProfileId\":{\"type\":\"crossPackageRef\",\"required\":false,\"related\":\"@happyvertical/smrt-profiles:Profile\"},\"createdAt\":{\"type\":\"text\",\"required\":false},\"updatedAt\":{\"type\":\"text\",\"required\":false}},\"methods\":{\"getParent\":{\"name\":\"getParent\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this | null>\",\"isStatic\":false,\"isPublic\":true},\"getChildren\":{\"name\":\"getChildren\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getAncestors\":{\"name\":\"getAncestors\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getDescendants\":{\"name\":\"getDescendants\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<this[]>\",\"isStatic\":false,\"isPublic\":true},\"getHierarchy\":{\"name\":\"getHierarchy\",\"async\":true,\"parameters\":[],\"returnType\":\"Promise<HierarchyView<this>>\",\"isStatic\":false,\"isPublic\":true},\"moveTo\":{\"name\":\"moveTo\",\"async\":true,\"parameters\":[{\"name\":\"newParent\",\"type\":\"this | string | null\",\"optional\":false,\"unionBranches\":[{\"type\":\"this\"},{\"type\":\"string\"},{\"type\":\"null\"}]}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true},\"getBySlug\":{\"name\":\"getBySlug\",\"async\":true,\"parameters\":[{\"name\":\"_slug\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Folder | null>\",\"isStatic\":true,\"isPublic\":true}},\"decoratorConfig\":{\"api\":{\"include\":[\"list\",\"get\",\"create\",\"update\",\"delete\"]},\"mcp\":{\"include\":[\"list\",\"get\",\"create\",\"update\"]},\"cli\":{\"skipApiCheck\":true},\"tenantScoped\":{\"mode\":\"optional\"},\"conflictColumns\":[\"tenant_id\",\"slug\",\"context\"]},\"extends\":\"SmrtHierarchical\",\"exportName\":\"Folder\",\"collectionExportName\":\"FolderCollection\",\"schema\":{\"tableName\":\"folders\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"folders\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"parent_id\\\" UUID,\\n \\\"tenant_id\\\" UUID,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT,\\n \\\"owner_profile_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"parent_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"unique\":false,\"foreignKey\":{\"table\":\"folders\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"owner_profile_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"folders_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"folders_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"folders_parent_id_idx\",\"columns\":[\"parent_id\"]},{\"name\":\"folders_owner_profile_id_idx\",\"columns\":[\"owner_profile_id\"]}],\"version\":\"1d0b1fcb\"},\"importPath\":\"@happyvertical/smrt-assets\"},\"@happyvertical/smrt-assets:FolderCollection\":{\"name\":\"foldercollection\",\"className\":\"FolderCollection\",\"qualifiedName\":\"@happyvertical/smrt-assets:FolderCollection\",\"collection\":\"folders\",\"filePath\":\"/home/runner/work/smrt/smrt/packages/assets/src/folders.ts\",\"packageName\":\"@happyvertical/smrt-assets\",\"fields\":{},\"methods\":{\"getTree\":{\"name\":\"getTree\",\"async\":true,\"parameters\":[{\"name\":\"rootId\",\"type\":\"string\",\"optional\":true}],\"returnType\":\"Promise<Folder[]>\",\"isStatic\":false,\"isPublic\":true},\"getPath\":{\"name\":\"getPath\",\"async\":true,\"parameters\":[{\"name\":\"folderId\",\"type\":\"string\",\"optional\":false}],\"returnType\":\"Promise<Folder[]>\",\"isStatic\":false,\"isPublic\":true},\"getContents\":{\"name\":\"getContents\",\"async\":true,\"parameters\":[{\"name\":\"folderId\",\"type\":\"string\",\"optional\":false},{\"name\":\"assetCollection\",\"type\":\"AssetCollection\",\"optional\":false}],\"returnType\":\"Promise<Asset[]>\",\"isStatic\":false,\"isPublic\":true},\"moveAsset\":{\"name\":\"moveAsset\",\"async\":true,\"parameters\":[{\"name\":\"asset\",\"type\":\"Asset\",\"optional\":false},{\"name\":\"folderId\",\"type\":\"string | null\",\"optional\":false,\"unionBranches\":[{\"type\":\"string\"},{\"type\":\"null\"}]}],\"returnType\":\"Promise<void>\",\"isStatic\":false,\"isPublic\":true}},\"decoratorConfig\":{},\"extends\":\"SmrtCollection\",\"extendsTypeArg\":\"Folder\",\"exportName\":\"FolderCollection\",\"collectionExportName\":\"FolderCollectionCollection\",\"schema\":{\"tableName\":\"folders\",\"ddl\":\"CREATE TABLE IF NOT EXISTS \\\"folders\\\" (\\n \\\"id\\\" UUID PRIMARY KEY NOT NULL,\\n \\\"slug\\\" TEXT NOT NULL,\\n \\\"context\\\" TEXT NOT NULL DEFAULT '',\\n \\\"created_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"updated_at\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\\"parent_id\\\" UUID,\\n \\\"tenant_id\\\" UUID,\\n \\\"name\\\" TEXT,\\n \\\"description\\\" TEXT,\\n \\\"owner_profile_id\\\" UUID\\n);\",\"columns\":{\"id\":{\"type\":\"UUID\",\"primaryKey\":true,\"referenceKind\":\"id\",\"notNull\":true},\"slug\":{\"type\":\"TEXT\",\"notNull\":true},\"context\":{\"type\":\"TEXT\",\"notNull\":true,\"default\":\"\"},\"created_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"updated_at\":{\"type\":\"TIMESTAMP\",\"notNull\":true,\"default\":\"current_timestamp\"},\"parent_id\":{\"type\":\"UUID\",\"referenceKind\":\"foreignKey\",\"notNull\":false,\"unique\":false,\"foreignKey\":{\"table\":\"folders\",\"column\":\"id\",\"onDelete\":\"NO ACTION\",\"onUpdate\":\"CASCADE\"}},\"tenant_id\":{\"type\":\"UUID\",\"referenceKind\":\"tenantId\",\"notNull\":false,\"unique\":false},\"name\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"description\":{\"type\":\"TEXT\",\"notNull\":false,\"unique\":false},\"owner_profile_id\":{\"type\":\"UUID\",\"referenceKind\":\"crossPackageRef\",\"notNull\":false,\"unique\":false}},\"indexes\":[{\"name\":\"folders_slug_context_idx\",\"columns\":[\"tenant_id\",\"slug\",\"context\"],\"unique\":true,\"nullsNotDistinct\":true},{\"name\":\"folders_tenant_id_created_at_idx\",\"columns\":[\"tenant_id\",\"created_at\"]},{\"name\":\"folders_parent_id_idx\",\"columns\":[\"parent_id\"]},{\"name\":\"folders_owner_profile_id_idx\",\"columns\":[\"owner_profile_id\"]}],\"version\":\"1d0b1fcb\"},\"importPath\":\"@happyvertical/smrt-assets\"}},\"moduleType\":\"smrt\",\"smrtDependencies\":[\"@happyvertical/smrt-core\",\"@happyvertical/smrt-tags\",\"@happyvertical/smrt-tenancy\"]}"));
709
- var __defProp$8 = Object.defineProperty;
710
- var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
711
- var __decorateClass$8 = (decorators, target, key, kind) => {
712
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
713
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
714
- if (kind && result) __defProp$8(target, key, result);
715
- return result;
716
- };
717
- var AssetAssociation = class extends SmrtPolymorphicAssociation {
718
- tenantId = null;
719
- assetId = "";
720
- constructor(options = {}) {
721
- super(options);
722
- if (options.assetId) this.assetId = options.assetId;
723
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
724
- }
725
- };
726
- __decorateClass$8([tenantId({ nullable: true })], AssetAssociation.prototype, "tenantId", 2);
727
- __decorateClass$8([foreignKey("Asset", { required: true })], AssetAssociation.prototype, "assetId", 2);
728
- AssetAssociation = __decorateClass$8([TenantScoped({ mode: "optional" }), smrt({
729
- conflictColumns: [
730
- "asset_id",
731
- "meta_type",
732
- "meta_id",
733
- "role"
734
- ],
735
- api: { include: [
736
- "list",
737
- "get",
738
- "create",
739
- "delete"
740
- ] },
741
- mcp: { include: [
742
- "list",
743
- "get",
744
- "create"
745
- ] },
746
- cli: { skipApiCheck: true }
747
- })], AssetAssociation);
748
- var __defProp$7 = Object.defineProperty;
749
- var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
750
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$7(obj, key, {
751
- enumerable: true,
752
- configurable: true,
753
- writable: true,
754
- value
755
- }) : obj[key] = value;
756
- var __decorateClass$7 = (decorators, target, key, kind) => {
757
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
758
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
759
- if (kind && result) __defProp$7(target, key, result);
760
- return result;
761
- };
762
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
763
- async function metaTypeFilter(metaType) {
764
- const names = await ObjectRegistry.getEquivalentQualifiedNamesAsync(metaType, { source: "AssetAssociationCollection" });
765
- return names.length === 1 ? names[0] : names;
766
- }
767
- var AssetAssociationCollection = class extends SmrtJunction {
768
- leftField = "metaId";
769
- rightField = "assetId";
770
- /**
771
- * List associations for a polymorphic owner.
772
- *
773
- * Composite left key — pass both halves.
774
- */
775
- async byLeft(metaType, metaId, opts = {}) {
776
- return await this.list({
777
- where: {
778
- ...opts,
779
- metaType: await metaTypeFilter(metaType),
780
- metaId
781
- },
782
- orderBy: "sort_order ASC"
783
- });
784
- }
785
- /**
786
- * Create an association. Composite left (metaType, metaId) precedes right (assetId).
787
- */
788
- async attach(metaType, metaId, assetId, opts = {}) {
789
- return await this.create({
790
- ...opts,
791
- assetId,
792
- metaType,
793
- metaId
794
- });
795
- }
796
- /**
797
- * Delete matching associations. Composite left (metaType, metaId) precedes right (assetId).
798
- */
799
- async detach(metaType, metaId, assetId, opts = {}) {
800
- const links = await this.list({ where: {
801
- ...opts,
802
- metaType: await metaTypeFilter(metaType),
803
- metaId,
804
- assetId
805
- } });
806
- for (const link of links) await link.delete();
807
- }
808
- /**
809
- * Replace all associations for a polymorphic owner with the given asset IDs.
810
- * Not transactional — see `SmrtJunction.setLinks` for caveats.
811
- */
812
- async setLinks(metaType, metaId, assetIds, opts = {}) {
813
- const snapshotOpts = { ...opts };
814
- delete snapshotOpts.assetId;
815
- const existing = await this.list({ where: {
816
- ...snapshotOpts,
817
- metaType: await metaTypeFilter(metaType),
818
- metaId
819
- } });
820
- for (const link of existing) await link.delete();
821
- const positionKey = this.positionField;
822
- for (let i = 0; i < assetIds.length; i++) {
823
- const rowOpts = { ...opts };
824
- if (positionKey && rowOpts[positionKey] === void 0) rowOpts[positionKey] = i;
825
- await this.attach(metaType, metaId, assetIds[i], rowOpts);
826
- }
827
- }
828
- };
829
- __publicField$1(AssetAssociationCollection, "_itemClass", AssetAssociation);
830
- AssetAssociationCollection = __decorateClass$7([smrt()], AssetAssociationCollection);
831
- var __defProp$6 = Object.defineProperty;
832
- var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
833
- var __decorateClass$6 = (decorators, target, key, kind) => {
834
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
835
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
836
- if (kind && result) __defProp$6(target, key, result);
837
- return result;
838
- };
839
- var AssetStatus = class extends SmrtObject {
840
- name = "";
841
- description = "";
842
- constructor(options = {}) {
843
- super(options);
844
- if (options.slug) this.slug = options.slug;
845
- if (options.name) this.name = options.name;
846
- if (options.description) this.description = options.description;
847
- }
848
- /**
849
- * Get asset status by slug
850
- *
851
- * @param slug - The slug to search for
852
- * @returns AssetStatus instance or null
853
- */
854
- static async getBySlug(_slug) {
855
- return null;
856
- }
857
- };
858
- AssetStatus = __decorateClass$6([smrt({
859
- tableStrategy: "sti",
860
- api: { include: [
861
- "list",
862
- "get",
863
- "create",
864
- "update",
865
- "delete"
866
- ] },
867
- mcp: { include: [
868
- "list",
869
- "get",
870
- "create"
871
- ] },
872
- cli: { skipApiCheck: true }
873
- })], AssetStatus);
874
- var __defProp$5 = Object.defineProperty;
875
- var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
876
- var __decorateClass$5 = (decorators, target, key, kind) => {
877
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
878
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
879
- if (kind && result) __defProp$5(target, key, result);
880
- return result;
881
- };
882
- var AssetType = class extends SmrtObject {
883
- name = "";
884
- description = "";
885
- constructor(options = {}) {
886
- super(options);
887
- if (options.slug) this.slug = options.slug;
888
- if (options.name) this.name = options.name;
889
- if (options.description) this.description = options.description;
890
- }
891
- /**
892
- * Get asset type by slug
893
- *
894
- * @param slug - The slug to search for
895
- * @returns AssetType instance or null
896
- */
897
- static async getBySlug(_slug) {
898
- return null;
899
- }
900
- };
901
- AssetType = __decorateClass$5([smrt({
902
- tableStrategy: "sti",
903
- api: { include: [
904
- "list",
905
- "get",
906
- "create",
907
- "update",
908
- "delete"
909
- ] },
910
- mcp: { include: [
911
- "list",
912
- "get",
913
- "create"
914
- ] },
915
- cli: { skipApiCheck: true }
916
- })], AssetType);
917
- var __defProp$4 = Object.defineProperty;
918
- var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
919
- var __decorateClass$4 = (decorators, target, key, kind) => {
920
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
921
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
922
- if (kind && result) __defProp$4(target, key, result);
923
- return result;
924
- };
925
- function parseAssetRecord(value) {
926
- if (!value) return {};
927
- if (typeof value !== "string") return value;
928
- if (!value.trim()) return {};
929
- try {
930
- const parsed = JSON.parse(value);
931
- return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
932
- } catch {
933
- return {};
934
- }
935
- }
936
- function stringifyAssetRecord(value) {
937
- if (!value || Object.keys(value).length === 0) return "";
938
- return JSON.stringify(value);
939
- }
940
- var Asset = class extends SmrtObject {
941
- tenantId = null;
942
- name = "";
943
- sourceUri = "";
944
- mimeType = "";
945
- description = "";
946
- metadata = "";
947
- version = 1;
948
- primaryVersionId = null;
949
- typeSlug = "";
950
- statusSlug = "";
951
- ownerProfileId = null;
952
- sourceAssetId = null;
953
- folderId = null;
954
- sourceType = "";
955
- externalId = "";
956
- externalRefs = "";
957
- createdAt = /* @__PURE__ */ new Date();
958
- updatedAt = /* @__PURE__ */ new Date();
959
- /**
960
- * A file's name is not its identity: two pictures named "photo.jpg" are two
961
- * assets. Without an explicit slug the default (name-derived) slug would
962
- * make the second save adopt the first row through the (tenant, slug,
963
- * context) natural key and overwrite it, so an asset's default slug is its
964
- * id. An explicit slug is kept.
965
- */
966
- async getSlug() {
967
- if (!this.slug && this.id) this.slug = String(this.id);
968
- return super.getSlug();
969
- }
970
- constructor(options = {}) {
971
- super(options);
972
- if (options.name) this.name = options.name;
973
- if (options.slug) this.slug = options.slug;
974
- if (options.sourceUri) this.sourceUri = options.sourceUri;
975
- if (options.mimeType) this.mimeType = options.mimeType;
976
- if (options.description) this.description = options.description;
977
- if (options.metadata !== void 0) this.metadata = typeof options.metadata === "string" ? options.metadata : stringifyAssetRecord(options.metadata);
978
- if (options.version !== void 0) this.version = options.version;
979
- if (options.primaryVersionId !== void 0) this.primaryVersionId = options.primaryVersionId;
980
- if (options.typeSlug) this.typeSlug = options.typeSlug;
981
- if (options.statusSlug) this.statusSlug = options.statusSlug;
982
- if (options.ownerProfileId !== void 0) this.ownerProfileId = options.ownerProfileId;
983
- if (options.sourceAssetId !== void 0) this.sourceAssetId = options.sourceAssetId;
984
- if (options.folderId !== void 0) this.folderId = options.folderId;
985
- if (options.sourceType) this.sourceType = options.sourceType;
986
- if (options.externalId) this.externalId = options.externalId;
987
- if (options.externalRefs !== void 0) this.externalRefs = typeof options.externalRefs === "string" ? options.externalRefs : stringifyAssetRecord(options.externalRefs);
988
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
989
- if (options.createdAt) this.createdAt = options.createdAt;
990
- if (options.updatedAt) this.updatedAt = options.updatedAt;
991
- }
992
- getMetadata() {
993
- return parseAssetRecord(this.metadata);
994
- }
995
- setMetadata(metadata) {
996
- this.metadata = stringifyAssetRecord(metadata);
997
- }
998
- mergeMetadata(metadata) {
999
- this.setMetadata({
1000
- ...this.getMetadata(),
1001
- ...metadata
1002
- });
1003
- }
1004
- getExternalRefs() {
1005
- const refs = parseAssetRecord(this.externalRefs);
1006
- const normalized = {};
1007
- for (const [provider, value] of Object.entries(refs)) if (value && typeof value === "object" && !Array.isArray(value)) normalized[provider] = {
1008
- ...value,
1009
- provider
1010
- };
1011
- return normalized;
1012
- }
1013
- getExternalRef(provider) {
1014
- return this.getExternalRefs()[provider] ?? null;
1015
- }
1016
- setExternalRef(provider, reference) {
1017
- this.externalRefs = stringifyAssetRecord({
1018
- ...this.getExternalRefs(),
1019
- [provider]: {
1020
- ...this.getExternalRef(provider) ?? {},
1021
- ...reference,
1022
- provider: reference.provider ?? provider
1023
- }
1024
- });
1025
- }
1026
- /**
1027
- * Get all tags for this asset from @happyvertical/smrt-tags, through the
1028
- * `asset_tags` join (`AssetTag`), sorted by name.
1029
- *
1030
- * @returns Array of Tag instances from @happyvertical/smrt-tags package
1031
- */
1032
- async getTags() {
1033
- if (!this.id) return [];
1034
- const { AssetTagCollection } = await Promise.resolve().then(() => asset_tags_exports);
1035
- const rows = await (await AssetTagCollection.create({ db: this.db })).byLeft(this.id);
1036
- if (rows.length === 0) return [];
1037
- return (await (await TagCollection.create({ db: this.db })).listByIds([...new Set(rows.map((row) => row.tagId))])).sort((a, b) => a.name.localeCompare(b.name));
1038
- }
1039
- /**
1040
- * Check if this asset has a specific tag
1041
- *
1042
- * @param tagSlug - The slug of the tag to check
1043
- * @param context - Tag context; any context when omitted
1044
- * @returns True if the asset has this tag
1045
- */
1046
- async hasTag(tagSlug, context) {
1047
- return (await this.getTags()).some((tag) => tag.slug === tagSlug && (context === void 0 || tag.context === context));
1048
- }
1049
- /**
1050
- * Resolve the AssetCollection lazily. Going through `ObjectRegistry`
1051
- * mirrors the pattern used by `SmrtHierarchical._hierarchyCollection`
1052
- * so source/derivative lookups inherit tenant scoping and ORM
1053
- * hydration without hard-coding an import of `./assets` (which would
1054
- * create a module-import cycle).
1055
- *
1056
- * The return type is `SmrtCollection<Asset>` (the framework base, type-
1057
- * only import from core) rather than the concrete `AssetCollection` —
1058
- * importing the concrete class is what would create the cycle, but the
1059
- * base-class shape gives callers full `.get()` / `.list()` type
1060
- * safety here.
1061
- *
1062
- * R5-canon: hardcode the base Asset's qualified key so a different
1063
- * package also registering a class called `Asset` can't be picked
1064
- * by `findClass`'s multi-strategy fallback. Crucially we DON'T
1065
- * resolve via `this.constructor._smrtQualifiedName` — for an STI
1066
- * subclass like `Image`, that would yield the Image collection
1067
- * (which auto-filters `_meta_type = '...:Image'` on `get`/`list`),
1068
- * and `getSource()` / `getDerivatives()` would miss cross-type
1069
- * derivation links (Image derived from a plain Asset, etc.).
1070
- * `sourceAssetId` is a base-table derivation link, so it always
1071
- * resolves through the base Asset collection.
1072
- */
1073
- async _assetCollection() {
1074
- return await ObjectRegistry.getCollection("@happyvertical/smrt-assets:Asset", this.options);
1075
- }
1076
- /**
1077
- * Get the source asset this one was derived from, if any.
1078
- *
1079
- * Renamed from `getParent` in R3-D. The relationship is "I was produced
1080
- * from that asset" (e.g. a thumbnail's source is its original image),
1081
- * not a structural-hierarchy parent.
1082
- *
1083
- * Goes through the AssetCollection so tenant interceptors and ORM
1084
- * hydration apply — important because a tenant-scoped consumer with
1085
- * cross-tenant derivative chains would otherwise return assets from
1086
- * tenants the caller cannot see, and a raw `db.get` returns
1087
- * snake_case rows that leave camelCase props (e.g. `sourceUri`) at
1088
- * their constructor defaults.
1089
- *
1090
- * @returns Source Asset instance, or null if this asset has no source
1091
- */
1092
- async getSource() {
1093
- if (!this.sourceAssetId) return null;
1094
- return await (await this._assetCollection()).get({ id: this.sourceAssetId });
1095
- }
1096
- /**
1097
- * Get all assets derived from this one (e.g. thumbnails, variants,
1098
- * transcodes, AI edits).
1099
- *
1100
- * Renamed from `getChildren` in R3-D to match the derivation
1101
- * semantics. Goes through the AssetCollection so tenant interceptors
1102
- * and ORM hydration apply (see `getSource` for why this matters —
1103
- * the pre-R3-D `getChildren` used raw `db.list`, which both bypassed
1104
- * tenant scoping and dropped camelCase property hydration; that
1105
- * latent breakage is fixed here).
1106
- *
1107
- * @returns Array of derivative Asset instances
1108
- */
1109
- async getDerivatives() {
1110
- if (!this.id) return [];
1111
- return await (await this._assetCollection()).list({ where: { sourceAssetId: this.id } });
1112
- }
1113
- /**
1114
- * Get the type of this asset
1115
- *
1116
- * @returns AssetType instance or null
1117
- */
1118
- async getType() {
1119
- if (!this.typeSlug) return null;
1120
- return await AssetType.getBySlug(this.typeSlug);
1121
- }
1122
- /**
1123
- * Get the status of this asset
1124
- *
1125
- * @returns AssetStatus instance or null
1126
- */
1127
- async getStatus() {
1128
- if (!this.statusSlug) return null;
1129
- return await AssetStatus.getBySlug(this.statusSlug);
1130
- }
1131
- /**
1132
- * Get all associations for this asset
1133
- *
1134
- * @returns Array of AssetAssociation instances
1135
- */
1136
- async getAssociations() {
1137
- return await (await AssetAssociationCollection.create({ db: this.db })).byRight(this.id);
1138
- }
1139
- /**
1140
- * Associate this asset with a target object
1141
- *
1142
- * @param metaType - Target class name or qualified name (e.g., 'Article' or '@pkg:Article')
1143
- * @param metaId - Target object ID
1144
- * @param role - Association role (default: 'default')
1145
- * @returns The created AssetAssociation
1146
- */
1147
- async associateWith(metaType, metaId, role = "default") {
1148
- return await (await AssetAssociationCollection.create({ db: this.db })).attach(metaType, metaId, this.id, { role });
1149
- }
1150
- /**
1151
- * Get asset by slug
1152
- *
1153
- * @param slug - The slug to search for
1154
- * @returns Asset instance or null
1155
- */
1156
- static async getBySlug(_slug) {
1157
- return null;
1158
- }
1159
- };
1160
- __decorateClass$4([tenantId({ nullable: true })], Asset.prototype, "tenantId", 2);
1161
- __decorateClass$4([foreignKey("Asset")], Asset.prototype, "primaryVersionId", 2);
1162
- __decorateClass$4([crossPackageRef("@happyvertical/smrt-profiles:Profile")], Asset.prototype, "ownerProfileId", 2);
1163
- __decorateClass$4([foreignKey("Asset")], Asset.prototype, "sourceAssetId", 2);
1164
- __decorateClass$4([foreignKey("Folder")], Asset.prototype, "folderId", 2);
1165
- Asset = __decorateClass$4([TenantScoped({ mode: "optional" }), smrt({
1166
- tableStrategy: "sti",
1167
- api: { include: [
1168
- "list",
1169
- "get",
1170
- "create",
1171
- "update",
1172
- "delete"
1173
- ] },
1174
- mcp: { include: [
1175
- "list",
1176
- "get",
1177
- "create",
1178
- "update"
1179
- ] },
1180
- cli: { skipApiCheck: true }
1181
- })], Asset);
1182
- var __defProp$3 = Object.defineProperty;
1183
- var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1184
- var __decorateClass$3 = (decorators, target, key, kind) => {
1185
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1186
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1187
- if (kind && result) __defProp$3(target, key, result);
1188
- return result;
1189
- };
1190
- var AssetMetafield = class extends SmrtObject {
1191
- name = "";
1192
- validation = "";
1193
- constructor(options = {}) {
1194
- super(options);
1195
- if (options.slug) this.slug = options.slug;
1196
- if (options.name) this.name = options.name;
1197
- if (options.validation) this.validation = options.validation;
1198
- }
1199
- /**
1200
- * Get validation rules as parsed object
1201
- *
1202
- * @returns Parsed validation object or empty object if no validation
1203
- */
1204
- getValidation() {
1205
- if (!this.validation) return {};
1206
- try {
1207
- return JSON.parse(this.validation);
1208
- } catch {
1209
- return {};
1210
- }
1211
- }
1212
- /**
1213
- * Set validation rules from object
1214
- *
1215
- * @param rules - Validation rules object
1216
- */
1217
- setValidation(rules) {
1218
- this.validation = JSON.stringify(rules);
1219
- }
1220
- /**
1221
- * Get asset metafield by slug
1222
- *
1223
- * @param slug - The slug to search for
1224
- * @returns AssetMetafield instance or null
1225
- */
1226
- static async getBySlug(_slug) {
1227
- return null;
1228
- }
1229
- };
1230
- AssetMetafield = __decorateClass$3([smrt({
1231
- tableStrategy: "sti",
1232
- api: { include: [
1233
- "list",
1234
- "get",
1235
- "create",
1236
- "update",
1237
- "delete"
1238
- ] },
1239
- mcp: { include: [
1240
- "list",
1241
- "get",
1242
- "create"
1243
- ] },
1244
- cli: { skipApiCheck: true }
1245
- })], AssetMetafield);
1246
- function assetTagSlug(label) {
1247
- return String(label ?? "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
1248
- }
1249
- function titleFromSlug(slug) {
1250
- const words = slug.replace(/-/g, " ");
1251
- return words.charAt(0).toUpperCase() + words.slice(1);
1252
- }
1253
- var AssetCollection = class extends SmrtCollection {
1254
- static _itemClass = Asset;
1255
- /**
1256
- * Find all assets belonging to a specific tenant
1257
- *
1258
- * @param tenantId - The tenant ID to filter by
1259
- * @returns Array of assets belonging to this tenant
1260
- */
1261
- async findByTenant(tenantId) {
1262
- return await this.list({ where: { tenantId } });
1263
- }
1264
- /**
1265
- * Find all global assets (assets without a tenant).
1266
- *
1267
- * Routes through the shared tenant-global helper so it does not throw under
1268
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
1269
- * flagged as an isolation violation). (#1600)
1270
- *
1271
- * @returns Array of global assets
1272
- */
1273
- async findGlobal() {
1274
- return queryGlobal(this);
1275
- }
1276
- /**
1277
- * Find assets belonging to a tenant plus all global assets.
1278
- *
1279
- * Fails closed if an active tenant context requests a different tenant's
1280
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
1281
- *
1282
- * @param tenantId - The tenant ID to include
1283
- * @returns Array of tenant-specific and global assets
1284
- */
1285
- async findWithGlobals(tenantId) {
1286
- return queryWithGlobals(this, tenantId, "Asset.findWithGlobals");
1287
- }
1288
- async assetTagCollection() {
1289
- const { AssetTagCollection } = await Promise.resolve().then(() => asset_tags_exports);
1290
- return AssetTagCollection.create({ db: this.db });
1291
- }
1292
- async tagCollection() {
1293
- return TagCollection.create({ db: this.db });
1294
- }
1295
- async requireAsset(assetId) {
1296
- const asset = await this.get({ id: assetId });
1297
- if (!asset?.id) throw new Error(`Asset '${assetId}' not found`);
1298
- return asset;
1299
- }
1300
- /**
1301
- * Find the asset's tag for `tag` (a slug or a label) in the asset's own
1302
- * tenant, optionally creating it. A tag of another tenant is never used.
1303
- */
1304
- async resolveAssetTag(asset, tag, options) {
1305
- const slug = assetTagSlug(tag);
1306
- if (!slug) throw new Error("A tag needs at least one letter or digit");
1307
- const context = options.context ?? "asset";
1308
- const tags = await this.tagCollection();
1309
- const existing = (await tags.list({
1310
- where: asset.tenantId ? {
1311
- slug,
1312
- context,
1313
- tenantId: asset.tenantId
1314
- } : {
1315
- slug,
1316
- context
1317
- },
1318
- limit: 10
1319
- })).find((candidate) => (candidate.tenantId ?? null) === (asset.tenantId ?? null));
1320
- if (existing || !options.create) return existing ?? null;
1321
- const trimmed = tag.trim();
1322
- return await tags.create({
1323
- slug,
1324
- name: options.name?.trim() || (trimmed !== slug ? trimmed : titleFromSlug(slug)),
1325
- context,
1326
- level: 0,
1327
- tenantId: asset.tenantId ?? null
1328
- });
1329
- }
1330
- /**
1331
- * Add a tag to an asset. `tag` is a slug (`town-hall`) or a label
1332
- * (`Town hall`); the tag is found or created in the asset's tenant under
1333
- * `context` (default {@link ASSET_TAG_CONTEXT}). Adding a tag twice is a
1334
- * no-op. Returns the Tag.
1335
- *
1336
- * @throws when the asset does not exist (or is not visible in the active
1337
- * tenant context)
1338
- */
1339
- async addTag(assetId, tag, options = {}) {
1340
- const asset = await this.requireAsset(assetId);
1341
- const resolved = await this.resolveAssetTag(asset, tag, {
1342
- ...options,
1343
- create: true
1344
- });
1345
- const links = await this.assetTagCollection();
1346
- if ((await links.byLeft(asset.id, { tagId: resolved.id })).length === 0) await links.attach(asset.id, resolved.id, { tenantId: asset.tenantId ?? null });
1347
- return resolved;
1348
- }
1349
- /**
1350
- * Remove a tag (slug or label) from an asset. Unknown tags are ignored.
1351
- * The Tag itself is kept; only the link goes.
1352
- */
1353
- async removeTag(assetId, tag, options = {}) {
1354
- const asset = await this.requireAsset(assetId);
1355
- const resolved = await this.resolveAssetTag(asset, tag, {
1356
- ...options,
1357
- create: false
1358
- });
1359
- if (!resolved?.id) return;
1360
- await (await this.assetTagCollection()).detach(asset.id, resolved.id);
1361
- }
1362
- /**
1363
- * Make the asset's tags (in `context`) exactly `tags`: missing ones are
1364
- * added, others in the same context removed. Returns the resulting Tags.
1365
- */
1366
- async setTags(assetId, tags, options = {}) {
1367
- const asset = await this.requireAsset(assetId);
1368
- const context = options.context ?? "asset";
1369
- const wanted = [];
1370
- const seen = /* @__PURE__ */ new Set();
1371
- for (const tag of tags) {
1372
- const slug = assetTagSlug(tag);
1373
- if (!slug || seen.has(slug)) continue;
1374
- seen.add(slug);
1375
- wanted.push(await this.addTag(asset.id, tag, { context }));
1376
- }
1377
- const wantedIds = new Set(wanted.map((tag) => tag.id));
1378
- const current = await asset.getTags();
1379
- for (const tag of current) if (tag.context === context && !wantedIds.has(tag.id)) await this.removeTag(asset.id, tag.slug, { context });
1380
- return wanted;
1381
- }
1382
- /**
1383
- * Tags for many assets in two queries, keyed by asset id (assets without
1384
- * tags map to an empty list). Useful for list views.
1385
- */
1386
- async getTagsForAssets(assetIds) {
1387
- const result = /* @__PURE__ */ new Map();
1388
- const ids = [...new Set(assetIds.filter(Boolean))];
1389
- for (const id of ids) result.set(id, []);
1390
- if (ids.length === 0) return result;
1391
- const rows = await (await this.assetTagCollection()).list({ where: { "assetId in": ids } });
1392
- if (rows.length === 0) return result;
1393
- const tags = await this.tagCollection();
1394
- const tagById = new Map((await tags.listByIds([...new Set(rows.map((row) => row.tagId))])).filter((tag) => tag.id).map((tag) => [tag.id, tag]));
1395
- for (const row of rows) {
1396
- const tag = tagById.get(row.tagId);
1397
- if (tag) result.get(row.assetId)?.push(tag);
1398
- }
1399
- for (const list of result.values()) list.sort((a, b) => a.name.localeCompare(b.name));
1400
- return result;
1401
- }
1402
- /**
1403
- * Get all assets with a specific tag (slug or label), within the active
1404
- * tenant context.
1405
- */
1406
- async getByTag(tag, options = {}) {
1407
- const slug = assetTagSlug(tag);
1408
- if (!slug) return [];
1409
- const tagIds = (await (await this.tagCollection()).list({ where: {
1410
- slug,
1411
- context: options.context ?? "asset"
1412
- } })).map((match) => match.id).filter(Boolean);
1413
- if (tagIds.length === 0) return [];
1414
- const rows = await (await this.assetTagCollection()).list({ where: { "tagId in": tagIds } });
1415
- const assetIds = [...new Set(rows.map((row) => row.assetId))];
1416
- if (assetIds.length === 0) return [];
1417
- return await this.listByIds(assetIds);
1418
- }
1419
- /**
1420
- * Get assets by type
1421
- *
1422
- * @param typeSlug - The asset type slug (e.g., 'image', 'video')
1423
- * @returns Array of assets matching the type
1424
- */
1425
- async getByType(typeSlug) {
1426
- return await this.list({ where: { typeSlug } });
1427
- }
1428
- /**
1429
- * Get assets by status
1430
- *
1431
- * @param statusSlug - The asset status slug (e.g., 'published', 'draft')
1432
- * @returns Array of assets matching the status
1433
- */
1434
- async getByStatus(statusSlug) {
1435
- return await this.list({ where: { statusSlug } });
1436
- }
1437
- /**
1438
- * Get assets by owner
1439
- *
1440
- * @param ownerProfileId - The profile ID of the owner
1441
- * @returns Array of assets owned by this profile
1442
- */
1443
- async getByOwner(ownerProfileId) {
1444
- return await this.list({ where: { ownerProfileId } });
1445
- }
1446
- /**
1447
- * Create a new version of an existing asset
1448
- *
1449
- * @param primaryVersionId - The primary version ID (first version's ID)
1450
- * @param newSourceUri - The new source URI for this version
1451
- * @param updates - Optional additional updates
1452
- * @returns The newly created asset version
1453
- */
1454
- async createNewVersion(primaryVersionId, newSourceUri, updates = {}) {
1455
- const versions = await this.listVersions(primaryVersionId);
1456
- if (versions.length === 0) throw new Error(`No asset found with primary version ID: ${primaryVersionId}`);
1457
- versions.sort((a, b) => b.version - a.version);
1458
- const latestVersion = versions[0];
1459
- const newVersionNumber = latestVersion.version + 1;
1460
- const primary = versions.find((v) => v.id === primaryVersionId) ?? versions[versions.length - 1];
1461
- const baseSlug = String(primary?.slug ?? "") || "asset";
1462
- const takenInChain = new Set(versions.map((v) => v.slug).filter(Boolean));
1463
- let candidate = `${baseSlug}-v${newVersionNumber}`;
1464
- for (let attempt = 1;; attempt += 1) {
1465
- if (!(takenInChain.has(candidate) || await this.get({ slug: candidate }) !== null)) break;
1466
- candidate = `${baseSlug}-v${newVersionNumber}-${attempt}`;
1467
- }
1468
- return await this.create({
1469
- ...latestVersion,
1470
- id: void 0,
1471
- slug: candidate,
1472
- sourceUri: newSourceUri,
1473
- version: newVersionNumber,
1474
- primaryVersionId,
1475
- createdAt: /* @__PURE__ */ new Date(),
1476
- updatedAt: /* @__PURE__ */ new Date(),
1477
- ...updates
1478
- });
1479
- }
1480
- /**
1481
- * Get the latest version of an asset
1482
- *
1483
- * @param primaryVersionId - The primary version ID
1484
- * @returns The latest version or null
1485
- */
1486
- async getLatestVersion(primaryVersionId) {
1487
- const versions = await this.listVersions(primaryVersionId);
1488
- if (versions.length === 0) return null;
1489
- versions.sort((a, b) => b.version - a.version);
1490
- return versions[0];
1491
- }
1492
- /**
1493
- * List all versions of an asset
1494
- *
1495
- * @param primaryVersionId - The primary version ID
1496
- * @returns Array of all asset versions, ordered by version number
1497
- */
1498
- async listVersions(primaryVersionId) {
1499
- const [chained, primary] = await Promise.all([this.list({ where: { primaryVersionId } }), this.get({ id: primaryVersionId })]);
1500
- const byId = /* @__PURE__ */ new Map();
1501
- for (const asset of [...primary ? [primary] : [], ...chained]) if (asset?.id) byId.set(asset.id, asset);
1502
- const assets = Array.from(byId.values());
1503
- assets.sort((a, b) => a.version - b.version);
1504
- return assets;
1505
- }
1506
- /**
1507
- * Get derivative assets of a source asset.
1508
- *
1509
- * Renamed from `getChildren(parentId)` in R3-D to match the rename of
1510
- * the underlying column (`parent_id` → `source_asset_id`) and method
1511
- * (`Asset.getChildren` → `Asset.getDerivatives`).
1512
- *
1513
- * @param sourceAssetId - The source asset ID
1514
- * @returns Array of derivative assets
1515
- */
1516
- async getDerivatives(sourceAssetId) {
1517
- return await this.list({ where: { sourceAssetId } });
1518
- }
1519
- /**
1520
- * Get assets by MIME type pattern
1521
- *
1522
- * @param mimePattern - MIME type pattern (e.g., 'image/*', 'video/mp4')
1523
- * @returns Array of matching assets
1524
- */
1525
- async getByMimeType(mimePattern) {
1526
- const pattern = mimePattern.replace("*", "%");
1527
- return await this.list({ where: { "mimeType like": pattern } });
1528
- }
1529
- /**
1530
- * Rollback to a previous version by creating a new version with the target's content.
1531
- * Does NOT delete intermediate versions (safe rollback).
1532
- *
1533
- * @param primaryVersionId - The primary version ID of the version chain
1534
- * @param targetVersion - The version number to rollback to
1535
- * @returns The newly created asset version with content copied from target
1536
- */
1537
- async rollbackToVersion(primaryVersionId, targetVersion) {
1538
- const target = (await this.listVersions(primaryVersionId)).find((v) => v.version === targetVersion);
1539
- if (!target) throw new Error(`Version ${targetVersion} not found for asset ${primaryVersionId}`);
1540
- return await this.createNewVersion(primaryVersionId, target.sourceUri, { description: `Rollback to version ${targetVersion}` });
1541
- }
1542
- /**
1543
- * Get assets in a specific folder
1544
- *
1545
- * @param folderId - The folder ID to list contents for
1546
- * @returns Array of assets in this folder
1547
- */
1548
- async getByFolder(folderId) {
1549
- return await this.list({ where: { folderId } });
1550
- }
1551
- };
1552
- var __defProp$2 = Object.defineProperty;
1553
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1554
- var __decorateClass$2 = (decorators, target, key, kind) => {
1555
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1556
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1557
- if (kind && result) __defProp$2(target, key, result);
1558
- return result;
1559
- };
1560
- var AssetTag = class extends SmrtObject {
1561
- tenantId = null;
1562
- assetId = "";
1563
- tagId = "";
1564
- constructor(options = {}) {
1565
- super(options);
1566
- if (options.assetId) this.assetId = options.assetId;
1567
- if (options.tagId) this.tagId = options.tagId;
1568
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
1569
- }
1570
- };
1571
- __decorateClass$2([tenantId({ nullable: true })], AssetTag.prototype, "tenantId", 2);
1572
- __decorateClass$2([foreignKey("Asset", {
1573
- required: true,
1574
- onDelete: "CASCADE"
1575
- })], AssetTag.prototype, "assetId", 2);
1576
- __decorateClass$2([crossPackageRef("@happyvertical/smrt-tags:Tag", {
1577
- required: true,
1578
- onDelete: "CASCADE"
1579
- })], AssetTag.prototype, "tagId", 2);
1580
- AssetTag = __decorateClass$2([TenantScoped({ mode: "optional" }), smrt({
1581
- tableName: "asset_tags",
1582
- conflictColumns: ["asset_id", "tag_id"],
1583
- api: false,
1584
- mcp: false,
1585
- cli: false
1586
- })], AssetTag);
1587
- var asset_tags_exports = /* @__PURE__ */ __exportAll({ AssetTagCollection: () => AssetTagCollection });
1588
- var __defProp$1 = Object.defineProperty;
1589
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
1590
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
1591
- enumerable: true,
1592
- configurable: true,
1593
- writable: true,
1594
- value
1595
- }) : obj[key] = value;
1596
- var __decorateClass$1 = (decorators, target, key, kind) => {
1597
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
1598
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1599
- if (kind && result) __defProp$1(target, key, result);
1600
- return result;
1601
- };
1602
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1603
- var AssetTagCollection = class extends SmrtJunction {
1604
- leftField = "assetId";
1605
- rightField = "tagId";
1606
- sortField = null;
1607
- positionField = null;
1608
- };
1609
- __publicField(AssetTagCollection, "_itemClass", AssetTag);
1610
- AssetTagCollection = __decorateClass$1([smrt()], AssetTagCollection);
1611
- var __defProp = Object.defineProperty;
1612
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1613
- var __decorateClass = (decorators, target, key, kind) => {
1614
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
1615
- for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1616
- if (kind && result) __defProp(target, key, result);
1617
- return result;
1618
- };
1619
- var Folder = class extends SmrtHierarchical {
1620
- tenantId = null;
1621
- name = "";
1622
- description = "";
1623
- ownerProfileId = null;
1624
- createdAt = /* @__PURE__ */ new Date();
1625
- updatedAt = /* @__PURE__ */ new Date();
1626
- constructor(options = {}) {
1627
- super(options);
1628
- if (options.name !== void 0) this.name = options.name;
1629
- if (options.slug !== void 0) this.slug = options.slug;
1630
- if (options.description !== void 0) this.description = options.description;
1631
- if (options.parentId !== void 0) this.parentId = options.parentId ?? null;
1632
- if (options.ownerProfileId !== void 0) this.ownerProfileId = options.ownerProfileId;
1633
- if (options.tenantId !== void 0) this.tenantId = options.tenantId;
1634
- if (options.createdAt) this.createdAt = options.createdAt;
1635
- if (options.updatedAt) this.updatedAt = options.updatedAt;
1636
- }
1637
- /**
1638
- * Look up a folder by slug.
1639
- */
1640
- static async getBySlug(_slug) {
1641
- return null;
1642
- }
1643
- };
1644
- __decorateClass([tenantId({ nullable: true })], Folder.prototype, "tenantId", 2);
1645
- __decorateClass([crossPackageRef("@happyvertical/smrt-profiles:Profile")], Folder.prototype, "ownerProfileId", 2);
1646
- Folder = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
1647
- api: { include: [
1648
- "list",
1649
- "get",
1650
- "create",
1651
- "update",
1652
- "delete"
1653
- ] },
1654
- mcp: { include: [
1655
- "list",
1656
- "get",
1657
- "create",
1658
- "update"
1659
- ] },
1660
- cli: { skipApiCheck: true }
1661
- })], Folder);
1662
- var OWNED_ASSET_RELATIONSHIP_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
1663
- function assertValidOwnedAssetRelationship(relationship) {
1664
- if (!OWNED_ASSET_RELATIONSHIP_PATTERN.test(relationship)) throw new Error(`Invalid relationship type "${relationship}"; must start with a letter or underscore and contain only letters, digits, and underscores`);
1665
- }
1666
- function assertValidOwnedAssetSortOrder(sortOrder) {
1667
- if (!Number.isInteger(sortOrder) || sortOrder < 0 || sortOrder > 2147483647) throw new Error(`Invalid sortOrder "${sortOrder}"; must be a non-negative integer`);
1668
- }
1669
- async function assertAssetLinkable(db, assetId, ownerTenantId, ownerLabel) {
1670
- const assets = await AssetCollection.create({ db });
1671
- const [stored] = await withSystemContext(async () => assets.listByIds([assetId]));
1672
- if (!stored) throw new Error(`Cannot associate asset ${assetId}: it does not exist`);
1673
- const assetTenant = stored.tenantId ? String(stored.tenantId) : null;
1674
- const ownerTenant = ownerTenantId ? String(ownerTenantId) : null;
1675
- if (assetTenant === null || assetTenant === ownerTenant) return;
1676
- throw new Error(ownerTenant === null ? `Cannot associate a tenant's asset with a shared ${ownerLabel}` : `Cannot associate an asset from another tenant with this ${ownerLabel}`);
1677
- }
1678
- async function resolveOwnedAssetsById(db, assetIds, tenantId) {
1679
- if (assetIds.length === 0) return [];
1680
- const assets = await AssetCollection.create({ db });
1681
- const resolved = tenantId ? await withSystemContext(async () => assets.listByIds(assetIds)) : await assets.listByIds(assetIds);
1682
- const visibleAssets = tenantId ? resolved.filter((asset) => asset.tenantId === tenantId || asset.tenantId === null) : resolved;
1683
- const assetsById = new Map(visibleAssets.filter((asset) => asset.id).map((asset) => [asset.id, asset]));
1684
- return assetIds.map((assetId) => assetsById.get(assetId)).filter(Boolean);
1685
- }
1686
- async function getOwnerRecord(collection, ownerId) {
1687
- return collection.get({ id: ownerId });
1688
- }
1689
- async function getOwnedAssetsFromCollection(collection, ownerId, relationship) {
1690
- const owner = await getOwnerRecord(collection, ownerId);
1691
- if (!owner) return [];
1692
- return owner.getAssets(relationship);
1693
- }
1694
- async function addOwnedAssetFromCollection(collection, ownerType, ownerId, asset, relationship = "attachment", sortOrder = 0) {
1695
- const owner = await getOwnerRecord(collection, ownerId);
1696
- if (!owner) throw new Error(`${ownerType} '${ownerId}' not found`);
1697
- await owner.addAsset(asset, relationship, sortOrder);
1698
- }
1699
- async function removeOwnedAssetFromCollection(collection, ownerType, ownerId, assetId, relationship) {
1700
- const owner = await getOwnerRecord(collection, ownerId);
1701
- if (!owner) throw new Error(`${ownerType} '${ownerId}' not found`);
1702
- await owner.removeAsset(assetId, relationship);
1703
- }
1704
- //#endregion
1705
- export { getOwnedAssetsFromCollection as a, assertValidOwnedAssetSortOrder as i, assertAssetLinkable as n, removeOwnedAssetFromCollection as o, assertValidOwnedAssetRelationship as r, resolveOwnedAssetsById as s, addOwnedAssetFromCollection as t };