@happyvertical/smrt-cli 0.51.39 → 0.52.0
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.
- package/AGENTS.md +6 -2
- package/README.md +21 -0
- package/agents/type-drift.md +16 -0
- package/dist/{ApiKey-BZmbOTnL-DEwZtcGA.js → ApiKey-BZmbOTnL-CMUo3WLf.js} +2 -2
- package/dist/ApiKeyCollection-Bfb_nw81-C3Xz7MUq.js +2 -0
- package/dist/AuditLogCollection-B1YonCAP-DmmboC_X.js +2 -0
- package/dist/{NostrIdentity-n70E0vck-DiBJPv76.js → NostrIdentity-n70E0vck-BD7uutxz.js} +3 -3
- package/dist/NostrIdentityCollection-Ca74dkaL--KYlM_ou.js +2 -0
- package/dist/{OidcIdentity-K8V4u0CR-B_ek3cPN.js → OidcIdentity-Cb1bxreM-DY0aRLu-.js} +3 -3
- package/dist/OidcIdentityCollection-TV8VdK69-DPeFJt3R.js +2 -0
- package/dist/ProfileAssetCollection-B9hacUJa-6R8lwjti.js +2 -0
- package/dist/{ProfileCollection-DTT4KNpQ-D1RNYfjm.js → ProfileCollection-DuJT7Mum-D_ScbSMu.js} +69 -31
- package/dist/ProfileLinkCollection-4uNURz32-lMKBjaik.js +2 -0
- package/dist/ProfileMetadataCollection-DQhbfEfa-B1QlmBkX.js +2 -0
- package/dist/{ProfileMetafieldCollection-CMKhVi2I-mh3UgeZA.js → ProfileMetafieldCollection-CoBuM_5G-BDwo4x3z.js} +1 -1
- package/dist/{ProfileRelationshipCollection-DUVgaIqf-CXHrAni4.js → ProfileRelationshipCollection-DUVgaIqf-BRrBeg1Q.js} +1 -1
- package/dist/{ProfileRelationshipTermCollection-DtA9OM23-Cj4bLTpU.js → ProfileRelationshipTermCollection-DtA9OM23-D4WMfN9a.js} +1 -1
- package/dist/{ProfileRelationshipType-BRiRka6t-ICv2cawn.js → ProfileRelationshipType-BRiRka6t-B32A4UFT.js} +1 -1
- package/dist/{ProfileRelationshipTypeCollection-BdXwd7Kf-CaYLxJmh.js → ProfileRelationshipTypeCollection-BdXwd7Kf-BqQa8Awc.js} +1 -1
- package/dist/commands/db-diff.d.ts.map +1 -1
- package/dist/commands/db-history.d.ts.map +1 -1
- package/dist/commands/db-migrate-actions.d.ts +7 -0
- package/dist/commands/db-migrate-actions.d.ts.map +1 -1
- package/dist/commands/db-parity.d.ts +7 -0
- package/dist/commands/db-parity.d.ts.map +1 -1
- package/dist/commands/db-status.d.ts.map +1 -1
- package/dist/commands/tenant-natural-keys.d.ts +58 -0
- package/dist/commands/tenant-natural-keys.d.ts.map +1 -0
- package/dist/commands/utilities.d.ts.map +1 -1
- package/dist/{commands-C2PjCUio.js → commands-BvcMfEoO.js} +165 -18
- package/dist/{dist-B3npUhW6.js → dist-BTxdRxKP.js} +151 -6
- package/dist/{dist-C8sNOzr2.js → dist-Dm4q4uB4.js} +4 -4
- package/dist/dist-qJw7ALwV.js +1701 -0
- package/dist/dist-vJJL0WMc.js +3937 -0
- package/dist/index.js +9 -9
- package/dist/{json-validator-oEN7eUI3.js → json-validator-BiAdsE1O.js} +4 -4
- package/dist/{oidcProvisioningPrimitives-0-3n3D6f-yUBRl2DC.js → oidcProvisioningPrimitives-D9OYu5-F-D9DQdiwS.js} +7 -7
- package/dist/resolveIdentity-B-PK6RwU-Dvqeq9-I.js +2 -0
- package/package.json +14 -14
- package/dist/ApiKeyCollection-Bfb_nw81-D4pLjDGS.js +0 -2
- package/dist/AuditLogCollection-B1YonCAP-w1iOHW4A.js +0 -2
- package/dist/NostrIdentityCollection-Ca74dkaL-Ce-O_zQz.js +0 -2
- package/dist/OidcIdentityCollection-gnrLoF08-DJI-69Ow.js +0 -2
- package/dist/ProfileAssetCollection-CmbeSgDi-BpJ7XXsP.js +0 -2
- package/dist/ProfileMetadataCollection-DxX_BJKV-orYFlYii.js +0 -2
- package/dist/dist-DsMohSo_.js +0 -1487
- package/dist/dist-iMaSv6C_.js +0 -3712
- package/dist/resolveIdentity-BrJDCjYi-kdAssLr0.js +0 -2
|
@@ -0,0 +1,1701 @@
|
|
|
1
|
+
import { a as queryGlobal, i as tenantId, l as withSystemContext, o as queryWithGlobals, r as TenantScoped } from "./dist-BTxdRxKP.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.52.0\",\"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.52.0\",\"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
|
+
var AssetAssociationCollection = class extends SmrtJunction {
|
|
764
|
+
leftField = "metaId";
|
|
765
|
+
rightField = "assetId";
|
|
766
|
+
/**
|
|
767
|
+
* List associations for a polymorphic owner.
|
|
768
|
+
*
|
|
769
|
+
* Composite left key — pass both halves.
|
|
770
|
+
*/
|
|
771
|
+
async byLeft(metaType, metaId, opts = {}) {
|
|
772
|
+
return await this.list({
|
|
773
|
+
where: {
|
|
774
|
+
...opts,
|
|
775
|
+
metaType,
|
|
776
|
+
metaId
|
|
777
|
+
},
|
|
778
|
+
orderBy: "sort_order ASC"
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Create an association. Composite left (metaType, metaId) precedes right (assetId).
|
|
783
|
+
*/
|
|
784
|
+
async attach(metaType, metaId, assetId, opts = {}) {
|
|
785
|
+
return await this.create({
|
|
786
|
+
...opts,
|
|
787
|
+
assetId,
|
|
788
|
+
metaType,
|
|
789
|
+
metaId
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Delete matching associations. Composite left (metaType, metaId) precedes right (assetId).
|
|
794
|
+
*/
|
|
795
|
+
async detach(metaType, metaId, assetId, opts = {}) {
|
|
796
|
+
const links = await this.list({ where: {
|
|
797
|
+
...opts,
|
|
798
|
+
metaType,
|
|
799
|
+
metaId,
|
|
800
|
+
assetId
|
|
801
|
+
} });
|
|
802
|
+
for (const link of links) await link.delete();
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Replace all associations for a polymorphic owner with the given asset IDs.
|
|
806
|
+
* Not transactional — see `SmrtJunction.setLinks` for caveats.
|
|
807
|
+
*/
|
|
808
|
+
async setLinks(metaType, metaId, assetIds, opts = {}) {
|
|
809
|
+
const snapshotOpts = { ...opts };
|
|
810
|
+
delete snapshotOpts.assetId;
|
|
811
|
+
const existing = await this.list({ where: {
|
|
812
|
+
...snapshotOpts,
|
|
813
|
+
metaType,
|
|
814
|
+
metaId
|
|
815
|
+
} });
|
|
816
|
+
for (const link of existing) await link.delete();
|
|
817
|
+
const positionKey = this.positionField;
|
|
818
|
+
for (let i = 0; i < assetIds.length; i++) {
|
|
819
|
+
const rowOpts = { ...opts };
|
|
820
|
+
if (positionKey && rowOpts[positionKey] === void 0) rowOpts[positionKey] = i;
|
|
821
|
+
await this.attach(metaType, metaId, assetIds[i], rowOpts);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
__publicField$1(AssetAssociationCollection, "_itemClass", AssetAssociation);
|
|
826
|
+
AssetAssociationCollection = __decorateClass$7([smrt()], AssetAssociationCollection);
|
|
827
|
+
var __defProp$6 = Object.defineProperty;
|
|
828
|
+
var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
|
|
829
|
+
var __decorateClass$6 = (decorators, target, key, kind) => {
|
|
830
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
|
|
831
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
832
|
+
if (kind && result) __defProp$6(target, key, result);
|
|
833
|
+
return result;
|
|
834
|
+
};
|
|
835
|
+
var AssetStatus = class extends SmrtObject {
|
|
836
|
+
name = "";
|
|
837
|
+
description = "";
|
|
838
|
+
constructor(options = {}) {
|
|
839
|
+
super(options);
|
|
840
|
+
if (options.slug) this.slug = options.slug;
|
|
841
|
+
if (options.name) this.name = options.name;
|
|
842
|
+
if (options.description) this.description = options.description;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Get asset status by slug
|
|
846
|
+
*
|
|
847
|
+
* @param slug - The slug to search for
|
|
848
|
+
* @returns AssetStatus instance or null
|
|
849
|
+
*/
|
|
850
|
+
static async getBySlug(_slug) {
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
AssetStatus = __decorateClass$6([smrt({
|
|
855
|
+
tableStrategy: "sti",
|
|
856
|
+
api: { include: [
|
|
857
|
+
"list",
|
|
858
|
+
"get",
|
|
859
|
+
"create",
|
|
860
|
+
"update",
|
|
861
|
+
"delete"
|
|
862
|
+
] },
|
|
863
|
+
mcp: { include: [
|
|
864
|
+
"list",
|
|
865
|
+
"get",
|
|
866
|
+
"create"
|
|
867
|
+
] },
|
|
868
|
+
cli: { skipApiCheck: true }
|
|
869
|
+
})], AssetStatus);
|
|
870
|
+
var __defProp$5 = Object.defineProperty;
|
|
871
|
+
var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
|
|
872
|
+
var __decorateClass$5 = (decorators, target, key, kind) => {
|
|
873
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
|
|
874
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
875
|
+
if (kind && result) __defProp$5(target, key, result);
|
|
876
|
+
return result;
|
|
877
|
+
};
|
|
878
|
+
var AssetType = class extends SmrtObject {
|
|
879
|
+
name = "";
|
|
880
|
+
description = "";
|
|
881
|
+
constructor(options = {}) {
|
|
882
|
+
super(options);
|
|
883
|
+
if (options.slug) this.slug = options.slug;
|
|
884
|
+
if (options.name) this.name = options.name;
|
|
885
|
+
if (options.description) this.description = options.description;
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Get asset type by slug
|
|
889
|
+
*
|
|
890
|
+
* @param slug - The slug to search for
|
|
891
|
+
* @returns AssetType instance or null
|
|
892
|
+
*/
|
|
893
|
+
static async getBySlug(_slug) {
|
|
894
|
+
return null;
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
AssetType = __decorateClass$5([smrt({
|
|
898
|
+
tableStrategy: "sti",
|
|
899
|
+
api: { include: [
|
|
900
|
+
"list",
|
|
901
|
+
"get",
|
|
902
|
+
"create",
|
|
903
|
+
"update",
|
|
904
|
+
"delete"
|
|
905
|
+
] },
|
|
906
|
+
mcp: { include: [
|
|
907
|
+
"list",
|
|
908
|
+
"get",
|
|
909
|
+
"create"
|
|
910
|
+
] },
|
|
911
|
+
cli: { skipApiCheck: true }
|
|
912
|
+
})], AssetType);
|
|
913
|
+
var __defProp$4 = Object.defineProperty;
|
|
914
|
+
var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
|
|
915
|
+
var __decorateClass$4 = (decorators, target, key, kind) => {
|
|
916
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
|
|
917
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
918
|
+
if (kind && result) __defProp$4(target, key, result);
|
|
919
|
+
return result;
|
|
920
|
+
};
|
|
921
|
+
function parseAssetRecord(value) {
|
|
922
|
+
if (!value) return {};
|
|
923
|
+
if (typeof value !== "string") return value;
|
|
924
|
+
if (!value.trim()) return {};
|
|
925
|
+
try {
|
|
926
|
+
const parsed = JSON.parse(value);
|
|
927
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
928
|
+
} catch {
|
|
929
|
+
return {};
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function stringifyAssetRecord(value) {
|
|
933
|
+
if (!value || Object.keys(value).length === 0) return "";
|
|
934
|
+
return JSON.stringify(value);
|
|
935
|
+
}
|
|
936
|
+
var Asset = class extends SmrtObject {
|
|
937
|
+
tenantId = null;
|
|
938
|
+
name = "";
|
|
939
|
+
sourceUri = "";
|
|
940
|
+
mimeType = "";
|
|
941
|
+
description = "";
|
|
942
|
+
metadata = "";
|
|
943
|
+
version = 1;
|
|
944
|
+
primaryVersionId = null;
|
|
945
|
+
typeSlug = "";
|
|
946
|
+
statusSlug = "";
|
|
947
|
+
ownerProfileId = null;
|
|
948
|
+
sourceAssetId = null;
|
|
949
|
+
folderId = null;
|
|
950
|
+
sourceType = "";
|
|
951
|
+
externalId = "";
|
|
952
|
+
externalRefs = "";
|
|
953
|
+
createdAt = /* @__PURE__ */ new Date();
|
|
954
|
+
updatedAt = /* @__PURE__ */ new Date();
|
|
955
|
+
/**
|
|
956
|
+
* A file's name is not its identity: two pictures named "photo.jpg" are two
|
|
957
|
+
* assets. Without an explicit slug the default (name-derived) slug would
|
|
958
|
+
* make the second save adopt the first row through the (tenant, slug,
|
|
959
|
+
* context) natural key and overwrite it, so an asset's default slug is its
|
|
960
|
+
* id. An explicit slug is kept.
|
|
961
|
+
*/
|
|
962
|
+
async getSlug() {
|
|
963
|
+
if (!this.slug && this.id) this.slug = String(this.id);
|
|
964
|
+
return super.getSlug();
|
|
965
|
+
}
|
|
966
|
+
constructor(options = {}) {
|
|
967
|
+
super(options);
|
|
968
|
+
if (options.name) this.name = options.name;
|
|
969
|
+
if (options.slug) this.slug = options.slug;
|
|
970
|
+
if (options.sourceUri) this.sourceUri = options.sourceUri;
|
|
971
|
+
if (options.mimeType) this.mimeType = options.mimeType;
|
|
972
|
+
if (options.description) this.description = options.description;
|
|
973
|
+
if (options.metadata !== void 0) this.metadata = typeof options.metadata === "string" ? options.metadata : stringifyAssetRecord(options.metadata);
|
|
974
|
+
if (options.version !== void 0) this.version = options.version;
|
|
975
|
+
if (options.primaryVersionId !== void 0) this.primaryVersionId = options.primaryVersionId;
|
|
976
|
+
if (options.typeSlug) this.typeSlug = options.typeSlug;
|
|
977
|
+
if (options.statusSlug) this.statusSlug = options.statusSlug;
|
|
978
|
+
if (options.ownerProfileId !== void 0) this.ownerProfileId = options.ownerProfileId;
|
|
979
|
+
if (options.sourceAssetId !== void 0) this.sourceAssetId = options.sourceAssetId;
|
|
980
|
+
if (options.folderId !== void 0) this.folderId = options.folderId;
|
|
981
|
+
if (options.sourceType) this.sourceType = options.sourceType;
|
|
982
|
+
if (options.externalId) this.externalId = options.externalId;
|
|
983
|
+
if (options.externalRefs !== void 0) this.externalRefs = typeof options.externalRefs === "string" ? options.externalRefs : stringifyAssetRecord(options.externalRefs);
|
|
984
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
985
|
+
if (options.createdAt) this.createdAt = options.createdAt;
|
|
986
|
+
if (options.updatedAt) this.updatedAt = options.updatedAt;
|
|
987
|
+
}
|
|
988
|
+
getMetadata() {
|
|
989
|
+
return parseAssetRecord(this.metadata);
|
|
990
|
+
}
|
|
991
|
+
setMetadata(metadata) {
|
|
992
|
+
this.metadata = stringifyAssetRecord(metadata);
|
|
993
|
+
}
|
|
994
|
+
mergeMetadata(metadata) {
|
|
995
|
+
this.setMetadata({
|
|
996
|
+
...this.getMetadata(),
|
|
997
|
+
...metadata
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
getExternalRefs() {
|
|
1001
|
+
const refs = parseAssetRecord(this.externalRefs);
|
|
1002
|
+
const normalized = {};
|
|
1003
|
+
for (const [provider, value] of Object.entries(refs)) if (value && typeof value === "object" && !Array.isArray(value)) normalized[provider] = {
|
|
1004
|
+
...value,
|
|
1005
|
+
provider
|
|
1006
|
+
};
|
|
1007
|
+
return normalized;
|
|
1008
|
+
}
|
|
1009
|
+
getExternalRef(provider) {
|
|
1010
|
+
return this.getExternalRefs()[provider] ?? null;
|
|
1011
|
+
}
|
|
1012
|
+
setExternalRef(provider, reference) {
|
|
1013
|
+
this.externalRefs = stringifyAssetRecord({
|
|
1014
|
+
...this.getExternalRefs(),
|
|
1015
|
+
[provider]: {
|
|
1016
|
+
...this.getExternalRef(provider) ?? {},
|
|
1017
|
+
...reference,
|
|
1018
|
+
provider: reference.provider ?? provider
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Get all tags for this asset from @happyvertical/smrt-tags, through the
|
|
1024
|
+
* `asset_tags` join (`AssetTag`), sorted by name.
|
|
1025
|
+
*
|
|
1026
|
+
* @returns Array of Tag instances from @happyvertical/smrt-tags package
|
|
1027
|
+
*/
|
|
1028
|
+
async getTags() {
|
|
1029
|
+
if (!this.id) return [];
|
|
1030
|
+
const { AssetTagCollection } = await Promise.resolve().then(() => asset_tags_exports);
|
|
1031
|
+
const rows = await (await AssetTagCollection.create({ db: this.db })).byLeft(this.id);
|
|
1032
|
+
if (rows.length === 0) return [];
|
|
1033
|
+
return (await (await TagCollection.create({ db: this.db })).listByIds([...new Set(rows.map((row) => row.tagId))])).sort((a, b) => a.name.localeCompare(b.name));
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Check if this asset has a specific tag
|
|
1037
|
+
*
|
|
1038
|
+
* @param tagSlug - The slug of the tag to check
|
|
1039
|
+
* @param context - Tag context; any context when omitted
|
|
1040
|
+
* @returns True if the asset has this tag
|
|
1041
|
+
*/
|
|
1042
|
+
async hasTag(tagSlug, context) {
|
|
1043
|
+
return (await this.getTags()).some((tag) => tag.slug === tagSlug && (context === void 0 || tag.context === context));
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Resolve the AssetCollection lazily. Going through `ObjectRegistry`
|
|
1047
|
+
* mirrors the pattern used by `SmrtHierarchical._hierarchyCollection`
|
|
1048
|
+
* so source/derivative lookups inherit tenant scoping and ORM
|
|
1049
|
+
* hydration without hard-coding an import of `./assets` (which would
|
|
1050
|
+
* create a module-import cycle).
|
|
1051
|
+
*
|
|
1052
|
+
* The return type is `SmrtCollection<Asset>` (the framework base, type-
|
|
1053
|
+
* only import from core) rather than the concrete `AssetCollection` —
|
|
1054
|
+
* importing the concrete class is what would create the cycle, but the
|
|
1055
|
+
* base-class shape gives callers full `.get()` / `.list()` type
|
|
1056
|
+
* safety here.
|
|
1057
|
+
*
|
|
1058
|
+
* R5-canon: hardcode the base Asset's qualified key so a different
|
|
1059
|
+
* package also registering a class called `Asset` can't be picked
|
|
1060
|
+
* by `findClass`'s multi-strategy fallback. Crucially we DON'T
|
|
1061
|
+
* resolve via `this.constructor._smrtQualifiedName` — for an STI
|
|
1062
|
+
* subclass like `Image`, that would yield the Image collection
|
|
1063
|
+
* (which auto-filters `_meta_type = '...:Image'` on `get`/`list`),
|
|
1064
|
+
* and `getSource()` / `getDerivatives()` would miss cross-type
|
|
1065
|
+
* derivation links (Image derived from a plain Asset, etc.).
|
|
1066
|
+
* `sourceAssetId` is a base-table derivation link, so it always
|
|
1067
|
+
* resolves through the base Asset collection.
|
|
1068
|
+
*/
|
|
1069
|
+
async _assetCollection() {
|
|
1070
|
+
return await ObjectRegistry.getCollection("@happyvertical/smrt-assets:Asset", this.options);
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Get the source asset this one was derived from, if any.
|
|
1074
|
+
*
|
|
1075
|
+
* Renamed from `getParent` in R3-D. The relationship is "I was produced
|
|
1076
|
+
* from that asset" (e.g. a thumbnail's source is its original image),
|
|
1077
|
+
* not a structural-hierarchy parent.
|
|
1078
|
+
*
|
|
1079
|
+
* Goes through the AssetCollection so tenant interceptors and ORM
|
|
1080
|
+
* hydration apply — important because a tenant-scoped consumer with
|
|
1081
|
+
* cross-tenant derivative chains would otherwise return assets from
|
|
1082
|
+
* tenants the caller cannot see, and a raw `db.get` returns
|
|
1083
|
+
* snake_case rows that leave camelCase props (e.g. `sourceUri`) at
|
|
1084
|
+
* their constructor defaults.
|
|
1085
|
+
*
|
|
1086
|
+
* @returns Source Asset instance, or null if this asset has no source
|
|
1087
|
+
*/
|
|
1088
|
+
async getSource() {
|
|
1089
|
+
if (!this.sourceAssetId) return null;
|
|
1090
|
+
return await (await this._assetCollection()).get({ id: this.sourceAssetId });
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Get all assets derived from this one (e.g. thumbnails, variants,
|
|
1094
|
+
* transcodes, AI edits).
|
|
1095
|
+
*
|
|
1096
|
+
* Renamed from `getChildren` in R3-D to match the derivation
|
|
1097
|
+
* semantics. Goes through the AssetCollection so tenant interceptors
|
|
1098
|
+
* and ORM hydration apply (see `getSource` for why this matters —
|
|
1099
|
+
* the pre-R3-D `getChildren` used raw `db.list`, which both bypassed
|
|
1100
|
+
* tenant scoping and dropped camelCase property hydration; that
|
|
1101
|
+
* latent breakage is fixed here).
|
|
1102
|
+
*
|
|
1103
|
+
* @returns Array of derivative Asset instances
|
|
1104
|
+
*/
|
|
1105
|
+
async getDerivatives() {
|
|
1106
|
+
if (!this.id) return [];
|
|
1107
|
+
return await (await this._assetCollection()).list({ where: { sourceAssetId: this.id } });
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Get the type of this asset
|
|
1111
|
+
*
|
|
1112
|
+
* @returns AssetType instance or null
|
|
1113
|
+
*/
|
|
1114
|
+
async getType() {
|
|
1115
|
+
if (!this.typeSlug) return null;
|
|
1116
|
+
return await AssetType.getBySlug(this.typeSlug);
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Get the status of this asset
|
|
1120
|
+
*
|
|
1121
|
+
* @returns AssetStatus instance or null
|
|
1122
|
+
*/
|
|
1123
|
+
async getStatus() {
|
|
1124
|
+
if (!this.statusSlug) return null;
|
|
1125
|
+
return await AssetStatus.getBySlug(this.statusSlug);
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Get all associations for this asset
|
|
1129
|
+
*
|
|
1130
|
+
* @returns Array of AssetAssociation instances
|
|
1131
|
+
*/
|
|
1132
|
+
async getAssociations() {
|
|
1133
|
+
return await (await AssetAssociationCollection.create({ db: this.db })).byRight(this.id);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Associate this asset with a target object
|
|
1137
|
+
*
|
|
1138
|
+
* @param metaType - Target class name or qualified name (e.g., 'Article' or '@pkg:Article')
|
|
1139
|
+
* @param metaId - Target object ID
|
|
1140
|
+
* @param role - Association role (default: 'default')
|
|
1141
|
+
* @returns The created AssetAssociation
|
|
1142
|
+
*/
|
|
1143
|
+
async associateWith(metaType, metaId, role = "default") {
|
|
1144
|
+
return await (await AssetAssociationCollection.create({ db: this.db })).attach(metaType, metaId, this.id, { role });
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Get asset by slug
|
|
1148
|
+
*
|
|
1149
|
+
* @param slug - The slug to search for
|
|
1150
|
+
* @returns Asset instance or null
|
|
1151
|
+
*/
|
|
1152
|
+
static async getBySlug(_slug) {
|
|
1153
|
+
return null;
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
__decorateClass$4([tenantId({ nullable: true })], Asset.prototype, "tenantId", 2);
|
|
1157
|
+
__decorateClass$4([foreignKey("Asset")], Asset.prototype, "primaryVersionId", 2);
|
|
1158
|
+
__decorateClass$4([crossPackageRef("@happyvertical/smrt-profiles:Profile")], Asset.prototype, "ownerProfileId", 2);
|
|
1159
|
+
__decorateClass$4([foreignKey("Asset")], Asset.prototype, "sourceAssetId", 2);
|
|
1160
|
+
__decorateClass$4([foreignKey("Folder")], Asset.prototype, "folderId", 2);
|
|
1161
|
+
Asset = __decorateClass$4([TenantScoped({ mode: "optional" }), smrt({
|
|
1162
|
+
tableStrategy: "sti",
|
|
1163
|
+
api: { include: [
|
|
1164
|
+
"list",
|
|
1165
|
+
"get",
|
|
1166
|
+
"create",
|
|
1167
|
+
"update",
|
|
1168
|
+
"delete"
|
|
1169
|
+
] },
|
|
1170
|
+
mcp: { include: [
|
|
1171
|
+
"list",
|
|
1172
|
+
"get",
|
|
1173
|
+
"create",
|
|
1174
|
+
"update"
|
|
1175
|
+
] },
|
|
1176
|
+
cli: { skipApiCheck: true }
|
|
1177
|
+
})], Asset);
|
|
1178
|
+
var __defProp$3 = Object.defineProperty;
|
|
1179
|
+
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
|
1180
|
+
var __decorateClass$3 = (decorators, target, key, kind) => {
|
|
1181
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
|
|
1182
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1183
|
+
if (kind && result) __defProp$3(target, key, result);
|
|
1184
|
+
return result;
|
|
1185
|
+
};
|
|
1186
|
+
var AssetMetafield = class extends SmrtObject {
|
|
1187
|
+
name = "";
|
|
1188
|
+
validation = "";
|
|
1189
|
+
constructor(options = {}) {
|
|
1190
|
+
super(options);
|
|
1191
|
+
if (options.slug) this.slug = options.slug;
|
|
1192
|
+
if (options.name) this.name = options.name;
|
|
1193
|
+
if (options.validation) this.validation = options.validation;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Get validation rules as parsed object
|
|
1197
|
+
*
|
|
1198
|
+
* @returns Parsed validation object or empty object if no validation
|
|
1199
|
+
*/
|
|
1200
|
+
getValidation() {
|
|
1201
|
+
if (!this.validation) return {};
|
|
1202
|
+
try {
|
|
1203
|
+
return JSON.parse(this.validation);
|
|
1204
|
+
} catch {
|
|
1205
|
+
return {};
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Set validation rules from object
|
|
1210
|
+
*
|
|
1211
|
+
* @param rules - Validation rules object
|
|
1212
|
+
*/
|
|
1213
|
+
setValidation(rules) {
|
|
1214
|
+
this.validation = JSON.stringify(rules);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Get asset metafield by slug
|
|
1218
|
+
*
|
|
1219
|
+
* @param slug - The slug to search for
|
|
1220
|
+
* @returns AssetMetafield instance or null
|
|
1221
|
+
*/
|
|
1222
|
+
static async getBySlug(_slug) {
|
|
1223
|
+
return null;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
AssetMetafield = __decorateClass$3([smrt({
|
|
1227
|
+
tableStrategy: "sti",
|
|
1228
|
+
api: { include: [
|
|
1229
|
+
"list",
|
|
1230
|
+
"get",
|
|
1231
|
+
"create",
|
|
1232
|
+
"update",
|
|
1233
|
+
"delete"
|
|
1234
|
+
] },
|
|
1235
|
+
mcp: { include: [
|
|
1236
|
+
"list",
|
|
1237
|
+
"get",
|
|
1238
|
+
"create"
|
|
1239
|
+
] },
|
|
1240
|
+
cli: { skipApiCheck: true }
|
|
1241
|
+
})], AssetMetafield);
|
|
1242
|
+
function assetTagSlug(label) {
|
|
1243
|
+
return String(label ?? "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
1244
|
+
}
|
|
1245
|
+
function titleFromSlug(slug) {
|
|
1246
|
+
const words = slug.replace(/-/g, " ");
|
|
1247
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
1248
|
+
}
|
|
1249
|
+
var AssetCollection = class extends SmrtCollection {
|
|
1250
|
+
static _itemClass = Asset;
|
|
1251
|
+
/**
|
|
1252
|
+
* Find all assets belonging to a specific tenant
|
|
1253
|
+
*
|
|
1254
|
+
* @param tenantId - The tenant ID to filter by
|
|
1255
|
+
* @returns Array of assets belonging to this tenant
|
|
1256
|
+
*/
|
|
1257
|
+
async findByTenant(tenantId) {
|
|
1258
|
+
return await this.list({ where: { tenantId } });
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Find all global assets (assets without a tenant).
|
|
1262
|
+
*
|
|
1263
|
+
* Routes through the shared tenant-global helper so it does not throw under
|
|
1264
|
+
* an active tenant context (an explicit `tenant_id IS NULL` filter would be
|
|
1265
|
+
* flagged as an isolation violation). (#1600)
|
|
1266
|
+
*
|
|
1267
|
+
* @returns Array of global assets
|
|
1268
|
+
*/
|
|
1269
|
+
async findGlobal() {
|
|
1270
|
+
return queryGlobal(this);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Find assets belonging to a tenant plus all global assets.
|
|
1274
|
+
*
|
|
1275
|
+
* Fails closed if an active tenant context requests a different tenant's
|
|
1276
|
+
* rows; the admin/system path keeps the cross-tenant capability. (#1600)
|
|
1277
|
+
*
|
|
1278
|
+
* @param tenantId - The tenant ID to include
|
|
1279
|
+
* @returns Array of tenant-specific and global assets
|
|
1280
|
+
*/
|
|
1281
|
+
async findWithGlobals(tenantId) {
|
|
1282
|
+
return queryWithGlobals(this, tenantId, "Asset.findWithGlobals");
|
|
1283
|
+
}
|
|
1284
|
+
async assetTagCollection() {
|
|
1285
|
+
const { AssetTagCollection } = await Promise.resolve().then(() => asset_tags_exports);
|
|
1286
|
+
return AssetTagCollection.create({ db: this.db });
|
|
1287
|
+
}
|
|
1288
|
+
async tagCollection() {
|
|
1289
|
+
return TagCollection.create({ db: this.db });
|
|
1290
|
+
}
|
|
1291
|
+
async requireAsset(assetId) {
|
|
1292
|
+
const asset = await this.get({ id: assetId });
|
|
1293
|
+
if (!asset?.id) throw new Error(`Asset '${assetId}' not found`);
|
|
1294
|
+
return asset;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Find the asset's tag for `tag` (a slug or a label) in the asset's own
|
|
1298
|
+
* tenant, optionally creating it. A tag of another tenant is never used.
|
|
1299
|
+
*/
|
|
1300
|
+
async resolveAssetTag(asset, tag, options) {
|
|
1301
|
+
const slug = assetTagSlug(tag);
|
|
1302
|
+
if (!slug) throw new Error("A tag needs at least one letter or digit");
|
|
1303
|
+
const context = options.context ?? "asset";
|
|
1304
|
+
const tags = await this.tagCollection();
|
|
1305
|
+
const existing = (await tags.list({
|
|
1306
|
+
where: asset.tenantId ? {
|
|
1307
|
+
slug,
|
|
1308
|
+
context,
|
|
1309
|
+
tenantId: asset.tenantId
|
|
1310
|
+
} : {
|
|
1311
|
+
slug,
|
|
1312
|
+
context
|
|
1313
|
+
},
|
|
1314
|
+
limit: 10
|
|
1315
|
+
})).find((candidate) => (candidate.tenantId ?? null) === (asset.tenantId ?? null));
|
|
1316
|
+
if (existing || !options.create) return existing ?? null;
|
|
1317
|
+
const trimmed = tag.trim();
|
|
1318
|
+
return await tags.create({
|
|
1319
|
+
slug,
|
|
1320
|
+
name: options.name?.trim() || (trimmed !== slug ? trimmed : titleFromSlug(slug)),
|
|
1321
|
+
context,
|
|
1322
|
+
level: 0,
|
|
1323
|
+
tenantId: asset.tenantId ?? null
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Add a tag to an asset. `tag` is a slug (`town-hall`) or a label
|
|
1328
|
+
* (`Town hall`); the tag is found or created in the asset's tenant under
|
|
1329
|
+
* `context` (default {@link ASSET_TAG_CONTEXT}). Adding a tag twice is a
|
|
1330
|
+
* no-op. Returns the Tag.
|
|
1331
|
+
*
|
|
1332
|
+
* @throws when the asset does not exist (or is not visible in the active
|
|
1333
|
+
* tenant context)
|
|
1334
|
+
*/
|
|
1335
|
+
async addTag(assetId, tag, options = {}) {
|
|
1336
|
+
const asset = await this.requireAsset(assetId);
|
|
1337
|
+
const resolved = await this.resolveAssetTag(asset, tag, {
|
|
1338
|
+
...options,
|
|
1339
|
+
create: true
|
|
1340
|
+
});
|
|
1341
|
+
const links = await this.assetTagCollection();
|
|
1342
|
+
if ((await links.byLeft(asset.id, { tagId: resolved.id })).length === 0) await links.attach(asset.id, resolved.id, { tenantId: asset.tenantId ?? null });
|
|
1343
|
+
return resolved;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Remove a tag (slug or label) from an asset. Unknown tags are ignored.
|
|
1347
|
+
* The Tag itself is kept; only the link goes.
|
|
1348
|
+
*/
|
|
1349
|
+
async removeTag(assetId, tag, options = {}) {
|
|
1350
|
+
const asset = await this.requireAsset(assetId);
|
|
1351
|
+
const resolved = await this.resolveAssetTag(asset, tag, {
|
|
1352
|
+
...options,
|
|
1353
|
+
create: false
|
|
1354
|
+
});
|
|
1355
|
+
if (!resolved?.id) return;
|
|
1356
|
+
await (await this.assetTagCollection()).detach(asset.id, resolved.id);
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Make the asset's tags (in `context`) exactly `tags`: missing ones are
|
|
1360
|
+
* added, others in the same context removed. Returns the resulting Tags.
|
|
1361
|
+
*/
|
|
1362
|
+
async setTags(assetId, tags, options = {}) {
|
|
1363
|
+
const asset = await this.requireAsset(assetId);
|
|
1364
|
+
const context = options.context ?? "asset";
|
|
1365
|
+
const wanted = [];
|
|
1366
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1367
|
+
for (const tag of tags) {
|
|
1368
|
+
const slug = assetTagSlug(tag);
|
|
1369
|
+
if (!slug || seen.has(slug)) continue;
|
|
1370
|
+
seen.add(slug);
|
|
1371
|
+
wanted.push(await this.addTag(asset.id, tag, { context }));
|
|
1372
|
+
}
|
|
1373
|
+
const wantedIds = new Set(wanted.map((tag) => tag.id));
|
|
1374
|
+
const current = await asset.getTags();
|
|
1375
|
+
for (const tag of current) if (tag.context === context && !wantedIds.has(tag.id)) await this.removeTag(asset.id, tag.slug, { context });
|
|
1376
|
+
return wanted;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Tags for many assets in two queries, keyed by asset id (assets without
|
|
1380
|
+
* tags map to an empty list). Useful for list views.
|
|
1381
|
+
*/
|
|
1382
|
+
async getTagsForAssets(assetIds) {
|
|
1383
|
+
const result = /* @__PURE__ */ new Map();
|
|
1384
|
+
const ids = [...new Set(assetIds.filter(Boolean))];
|
|
1385
|
+
for (const id of ids) result.set(id, []);
|
|
1386
|
+
if (ids.length === 0) return result;
|
|
1387
|
+
const rows = await (await this.assetTagCollection()).list({ where: { "assetId in": ids } });
|
|
1388
|
+
if (rows.length === 0) return result;
|
|
1389
|
+
const tags = await this.tagCollection();
|
|
1390
|
+
const tagById = new Map((await tags.listByIds([...new Set(rows.map((row) => row.tagId))])).filter((tag) => tag.id).map((tag) => [tag.id, tag]));
|
|
1391
|
+
for (const row of rows) {
|
|
1392
|
+
const tag = tagById.get(row.tagId);
|
|
1393
|
+
if (tag) result.get(row.assetId)?.push(tag);
|
|
1394
|
+
}
|
|
1395
|
+
for (const list of result.values()) list.sort((a, b) => a.name.localeCompare(b.name));
|
|
1396
|
+
return result;
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Get all assets with a specific tag (slug or label), within the active
|
|
1400
|
+
* tenant context.
|
|
1401
|
+
*/
|
|
1402
|
+
async getByTag(tag, options = {}) {
|
|
1403
|
+
const slug = assetTagSlug(tag);
|
|
1404
|
+
if (!slug) return [];
|
|
1405
|
+
const tagIds = (await (await this.tagCollection()).list({ where: {
|
|
1406
|
+
slug,
|
|
1407
|
+
context: options.context ?? "asset"
|
|
1408
|
+
} })).map((match) => match.id).filter(Boolean);
|
|
1409
|
+
if (tagIds.length === 0) return [];
|
|
1410
|
+
const rows = await (await this.assetTagCollection()).list({ where: { "tagId in": tagIds } });
|
|
1411
|
+
const assetIds = [...new Set(rows.map((row) => row.assetId))];
|
|
1412
|
+
if (assetIds.length === 0) return [];
|
|
1413
|
+
return await this.listByIds(assetIds);
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Get assets by type
|
|
1417
|
+
*
|
|
1418
|
+
* @param typeSlug - The asset type slug (e.g., 'image', 'video')
|
|
1419
|
+
* @returns Array of assets matching the type
|
|
1420
|
+
*/
|
|
1421
|
+
async getByType(typeSlug) {
|
|
1422
|
+
return await this.list({ where: { typeSlug } });
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Get assets by status
|
|
1426
|
+
*
|
|
1427
|
+
* @param statusSlug - The asset status slug (e.g., 'published', 'draft')
|
|
1428
|
+
* @returns Array of assets matching the status
|
|
1429
|
+
*/
|
|
1430
|
+
async getByStatus(statusSlug) {
|
|
1431
|
+
return await this.list({ where: { statusSlug } });
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Get assets by owner
|
|
1435
|
+
*
|
|
1436
|
+
* @param ownerProfileId - The profile ID of the owner
|
|
1437
|
+
* @returns Array of assets owned by this profile
|
|
1438
|
+
*/
|
|
1439
|
+
async getByOwner(ownerProfileId) {
|
|
1440
|
+
return await this.list({ where: { ownerProfileId } });
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Create a new version of an existing asset
|
|
1444
|
+
*
|
|
1445
|
+
* @param primaryVersionId - The primary version ID (first version's ID)
|
|
1446
|
+
* @param newSourceUri - The new source URI for this version
|
|
1447
|
+
* @param updates - Optional additional updates
|
|
1448
|
+
* @returns The newly created asset version
|
|
1449
|
+
*/
|
|
1450
|
+
async createNewVersion(primaryVersionId, newSourceUri, updates = {}) {
|
|
1451
|
+
const versions = await this.listVersions(primaryVersionId);
|
|
1452
|
+
if (versions.length === 0) throw new Error(`No asset found with primary version ID: ${primaryVersionId}`);
|
|
1453
|
+
versions.sort((a, b) => b.version - a.version);
|
|
1454
|
+
const latestVersion = versions[0];
|
|
1455
|
+
const newVersionNumber = latestVersion.version + 1;
|
|
1456
|
+
const primary = versions.find((v) => v.id === primaryVersionId) ?? versions[versions.length - 1];
|
|
1457
|
+
const baseSlug = String(primary?.slug ?? "") || "asset";
|
|
1458
|
+
const takenInChain = new Set(versions.map((v) => v.slug).filter(Boolean));
|
|
1459
|
+
let candidate = `${baseSlug}-v${newVersionNumber}`;
|
|
1460
|
+
for (let attempt = 1;; attempt += 1) {
|
|
1461
|
+
if (!(takenInChain.has(candidate) || await this.get({ slug: candidate }) !== null)) break;
|
|
1462
|
+
candidate = `${baseSlug}-v${newVersionNumber}-${attempt}`;
|
|
1463
|
+
}
|
|
1464
|
+
return await this.create({
|
|
1465
|
+
...latestVersion,
|
|
1466
|
+
id: void 0,
|
|
1467
|
+
slug: candidate,
|
|
1468
|
+
sourceUri: newSourceUri,
|
|
1469
|
+
version: newVersionNumber,
|
|
1470
|
+
primaryVersionId,
|
|
1471
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1472
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1473
|
+
...updates
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Get the latest version of an asset
|
|
1478
|
+
*
|
|
1479
|
+
* @param primaryVersionId - The primary version ID
|
|
1480
|
+
* @returns The latest version or null
|
|
1481
|
+
*/
|
|
1482
|
+
async getLatestVersion(primaryVersionId) {
|
|
1483
|
+
const versions = await this.listVersions(primaryVersionId);
|
|
1484
|
+
if (versions.length === 0) return null;
|
|
1485
|
+
versions.sort((a, b) => b.version - a.version);
|
|
1486
|
+
return versions[0];
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* List all versions of an asset
|
|
1490
|
+
*
|
|
1491
|
+
* @param primaryVersionId - The primary version ID
|
|
1492
|
+
* @returns Array of all asset versions, ordered by version number
|
|
1493
|
+
*/
|
|
1494
|
+
async listVersions(primaryVersionId) {
|
|
1495
|
+
const [chained, primary] = await Promise.all([this.list({ where: { primaryVersionId } }), this.get({ id: primaryVersionId })]);
|
|
1496
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1497
|
+
for (const asset of [...primary ? [primary] : [], ...chained]) if (asset?.id) byId.set(asset.id, asset);
|
|
1498
|
+
const assets = Array.from(byId.values());
|
|
1499
|
+
assets.sort((a, b) => a.version - b.version);
|
|
1500
|
+
return assets;
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Get derivative assets of a source asset.
|
|
1504
|
+
*
|
|
1505
|
+
* Renamed from `getChildren(parentId)` in R3-D to match the rename of
|
|
1506
|
+
* the underlying column (`parent_id` → `source_asset_id`) and method
|
|
1507
|
+
* (`Asset.getChildren` → `Asset.getDerivatives`).
|
|
1508
|
+
*
|
|
1509
|
+
* @param sourceAssetId - The source asset ID
|
|
1510
|
+
* @returns Array of derivative assets
|
|
1511
|
+
*/
|
|
1512
|
+
async getDerivatives(sourceAssetId) {
|
|
1513
|
+
return await this.list({ where: { sourceAssetId } });
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Get assets by MIME type pattern
|
|
1517
|
+
*
|
|
1518
|
+
* @param mimePattern - MIME type pattern (e.g., 'image/*', 'video/mp4')
|
|
1519
|
+
* @returns Array of matching assets
|
|
1520
|
+
*/
|
|
1521
|
+
async getByMimeType(mimePattern) {
|
|
1522
|
+
const pattern = mimePattern.replace("*", "%");
|
|
1523
|
+
return await this.list({ where: { "mimeType like": pattern } });
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Rollback to a previous version by creating a new version with the target's content.
|
|
1527
|
+
* Does NOT delete intermediate versions (safe rollback).
|
|
1528
|
+
*
|
|
1529
|
+
* @param primaryVersionId - The primary version ID of the version chain
|
|
1530
|
+
* @param targetVersion - The version number to rollback to
|
|
1531
|
+
* @returns The newly created asset version with content copied from target
|
|
1532
|
+
*/
|
|
1533
|
+
async rollbackToVersion(primaryVersionId, targetVersion) {
|
|
1534
|
+
const target = (await this.listVersions(primaryVersionId)).find((v) => v.version === targetVersion);
|
|
1535
|
+
if (!target) throw new Error(`Version ${targetVersion} not found for asset ${primaryVersionId}`);
|
|
1536
|
+
return await this.createNewVersion(primaryVersionId, target.sourceUri, { description: `Rollback to version ${targetVersion}` });
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Get assets in a specific folder
|
|
1540
|
+
*
|
|
1541
|
+
* @param folderId - The folder ID to list contents for
|
|
1542
|
+
* @returns Array of assets in this folder
|
|
1543
|
+
*/
|
|
1544
|
+
async getByFolder(folderId) {
|
|
1545
|
+
return await this.list({ where: { folderId } });
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
var __defProp$2 = Object.defineProperty;
|
|
1549
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
1550
|
+
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
1551
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
1552
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1553
|
+
if (kind && result) __defProp$2(target, key, result);
|
|
1554
|
+
return result;
|
|
1555
|
+
};
|
|
1556
|
+
var AssetTag = class extends SmrtObject {
|
|
1557
|
+
tenantId = null;
|
|
1558
|
+
assetId = "";
|
|
1559
|
+
tagId = "";
|
|
1560
|
+
constructor(options = {}) {
|
|
1561
|
+
super(options);
|
|
1562
|
+
if (options.assetId) this.assetId = options.assetId;
|
|
1563
|
+
if (options.tagId) this.tagId = options.tagId;
|
|
1564
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
__decorateClass$2([tenantId({ nullable: true })], AssetTag.prototype, "tenantId", 2);
|
|
1568
|
+
__decorateClass$2([foreignKey("Asset", {
|
|
1569
|
+
required: true,
|
|
1570
|
+
onDelete: "CASCADE"
|
|
1571
|
+
})], AssetTag.prototype, "assetId", 2);
|
|
1572
|
+
__decorateClass$2([crossPackageRef("@happyvertical/smrt-tags:Tag", {
|
|
1573
|
+
required: true,
|
|
1574
|
+
onDelete: "CASCADE"
|
|
1575
|
+
})], AssetTag.prototype, "tagId", 2);
|
|
1576
|
+
AssetTag = __decorateClass$2([TenantScoped({ mode: "optional" }), smrt({
|
|
1577
|
+
tableName: "asset_tags",
|
|
1578
|
+
conflictColumns: ["asset_id", "tag_id"],
|
|
1579
|
+
api: false,
|
|
1580
|
+
mcp: false,
|
|
1581
|
+
cli: false
|
|
1582
|
+
})], AssetTag);
|
|
1583
|
+
var asset_tags_exports = /* @__PURE__ */ __exportAll({ AssetTagCollection: () => AssetTagCollection });
|
|
1584
|
+
var __defProp$1 = Object.defineProperty;
|
|
1585
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
1586
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
1587
|
+
enumerable: true,
|
|
1588
|
+
configurable: true,
|
|
1589
|
+
writable: true,
|
|
1590
|
+
value
|
|
1591
|
+
}) : obj[key] = value;
|
|
1592
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
|
1593
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
|
1594
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1595
|
+
if (kind && result) __defProp$1(target, key, result);
|
|
1596
|
+
return result;
|
|
1597
|
+
};
|
|
1598
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1599
|
+
var AssetTagCollection = class extends SmrtJunction {
|
|
1600
|
+
leftField = "assetId";
|
|
1601
|
+
rightField = "tagId";
|
|
1602
|
+
sortField = null;
|
|
1603
|
+
positionField = null;
|
|
1604
|
+
};
|
|
1605
|
+
__publicField(AssetTagCollection, "_itemClass", AssetTag);
|
|
1606
|
+
AssetTagCollection = __decorateClass$1([smrt()], AssetTagCollection);
|
|
1607
|
+
var __defProp = Object.defineProperty;
|
|
1608
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1609
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1610
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
1611
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1612
|
+
if (kind && result) __defProp(target, key, result);
|
|
1613
|
+
return result;
|
|
1614
|
+
};
|
|
1615
|
+
var Folder = class extends SmrtHierarchical {
|
|
1616
|
+
tenantId = null;
|
|
1617
|
+
name = "";
|
|
1618
|
+
description = "";
|
|
1619
|
+
ownerProfileId = null;
|
|
1620
|
+
createdAt = /* @__PURE__ */ new Date();
|
|
1621
|
+
updatedAt = /* @__PURE__ */ new Date();
|
|
1622
|
+
constructor(options = {}) {
|
|
1623
|
+
super(options);
|
|
1624
|
+
if (options.name !== void 0) this.name = options.name;
|
|
1625
|
+
if (options.slug !== void 0) this.slug = options.slug;
|
|
1626
|
+
if (options.description !== void 0) this.description = options.description;
|
|
1627
|
+
if (options.parentId !== void 0) this.parentId = options.parentId ?? null;
|
|
1628
|
+
if (options.ownerProfileId !== void 0) this.ownerProfileId = options.ownerProfileId;
|
|
1629
|
+
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
1630
|
+
if (options.createdAt) this.createdAt = options.createdAt;
|
|
1631
|
+
if (options.updatedAt) this.updatedAt = options.updatedAt;
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Look up a folder by slug.
|
|
1635
|
+
*/
|
|
1636
|
+
static async getBySlug(_slug) {
|
|
1637
|
+
return null;
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
__decorateClass([tenantId({ nullable: true })], Folder.prototype, "tenantId", 2);
|
|
1641
|
+
__decorateClass([crossPackageRef("@happyvertical/smrt-profiles:Profile")], Folder.prototype, "ownerProfileId", 2);
|
|
1642
|
+
Folder = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
|
|
1643
|
+
api: { include: [
|
|
1644
|
+
"list",
|
|
1645
|
+
"get",
|
|
1646
|
+
"create",
|
|
1647
|
+
"update",
|
|
1648
|
+
"delete"
|
|
1649
|
+
] },
|
|
1650
|
+
mcp: { include: [
|
|
1651
|
+
"list",
|
|
1652
|
+
"get",
|
|
1653
|
+
"create",
|
|
1654
|
+
"update"
|
|
1655
|
+
] },
|
|
1656
|
+
cli: { skipApiCheck: true }
|
|
1657
|
+
})], Folder);
|
|
1658
|
+
var OWNED_ASSET_RELATIONSHIP_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
1659
|
+
function assertValidOwnedAssetRelationship(relationship) {
|
|
1660
|
+
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`);
|
|
1661
|
+
}
|
|
1662
|
+
function assertValidOwnedAssetSortOrder(sortOrder) {
|
|
1663
|
+
if (!Number.isInteger(sortOrder) || sortOrder < 0 || sortOrder > 2147483647) throw new Error(`Invalid sortOrder "${sortOrder}"; must be a non-negative integer`);
|
|
1664
|
+
}
|
|
1665
|
+
async function assertAssetLinkable(db, assetId, ownerTenantId, ownerLabel) {
|
|
1666
|
+
const assets = await AssetCollection.create({ db });
|
|
1667
|
+
const [stored] = await withSystemContext(async () => assets.listByIds([assetId]));
|
|
1668
|
+
if (!stored) throw new Error(`Cannot associate asset ${assetId}: it does not exist`);
|
|
1669
|
+
const assetTenant = stored.tenantId ? String(stored.tenantId) : null;
|
|
1670
|
+
const ownerTenant = ownerTenantId ? String(ownerTenantId) : null;
|
|
1671
|
+
if (assetTenant === null || assetTenant === ownerTenant) return;
|
|
1672
|
+
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}`);
|
|
1673
|
+
}
|
|
1674
|
+
async function resolveOwnedAssetsById(db, assetIds, tenantId) {
|
|
1675
|
+
if (assetIds.length === 0) return [];
|
|
1676
|
+
const assets = await AssetCollection.create({ db });
|
|
1677
|
+
const resolved = tenantId ? await withSystemContext(async () => assets.listByIds(assetIds)) : await assets.listByIds(assetIds);
|
|
1678
|
+
const visibleAssets = tenantId ? resolved.filter((asset) => asset.tenantId === tenantId || asset.tenantId === null) : resolved;
|
|
1679
|
+
const assetsById = new Map(visibleAssets.filter((asset) => asset.id).map((asset) => [asset.id, asset]));
|
|
1680
|
+
return assetIds.map((assetId) => assetsById.get(assetId)).filter(Boolean);
|
|
1681
|
+
}
|
|
1682
|
+
async function getOwnerRecord(collection, ownerId) {
|
|
1683
|
+
return collection.get({ id: ownerId });
|
|
1684
|
+
}
|
|
1685
|
+
async function getOwnedAssetsFromCollection(collection, ownerId, relationship) {
|
|
1686
|
+
const owner = await getOwnerRecord(collection, ownerId);
|
|
1687
|
+
if (!owner) return [];
|
|
1688
|
+
return owner.getAssets(relationship);
|
|
1689
|
+
}
|
|
1690
|
+
async function addOwnedAssetFromCollection(collection, ownerType, ownerId, asset, relationship = "attachment", sortOrder = 0) {
|
|
1691
|
+
const owner = await getOwnerRecord(collection, ownerId);
|
|
1692
|
+
if (!owner) throw new Error(`${ownerType} '${ownerId}' not found`);
|
|
1693
|
+
await owner.addAsset(asset, relationship, sortOrder);
|
|
1694
|
+
}
|
|
1695
|
+
async function removeOwnedAssetFromCollection(collection, ownerType, ownerId, assetId, relationship) {
|
|
1696
|
+
const owner = await getOwnerRecord(collection, ownerId);
|
|
1697
|
+
if (!owner) throw new Error(`${ownerType} '${ownerId}' not found`);
|
|
1698
|
+
await owner.removeAsset(assetId, relationship);
|
|
1699
|
+
}
|
|
1700
|
+
//#endregion
|
|
1701
|
+
export { getOwnedAssetsFromCollection as a, assertValidOwnedAssetSortOrder as i, assertAssetLinkable as n, removeOwnedAssetFromCollection as o, assertValidOwnedAssetRelationship as r, resolveOwnedAssetsById as s, addOwnedAssetFromCollection as t };
|