@happyvertical/smrt-profiles 0.62.14 → 0.64.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/dist/chunks/{ApiKey-BhseCX_J.js → ApiKey-DILxIM21.js} +3 -3
- package/dist/chunks/{ApiKey-BhseCX_J.js.map → ApiKey-DILxIM21.js.map} +1 -1
- package/dist/chunks/{ApiKeyCollection-BK2Wn-wa.js → ApiKeyCollection-BAoIu1NT.js} +3 -3
- package/dist/chunks/{ApiKeyCollection-BK2Wn-wa.js.map → ApiKeyCollection-BAoIu1NT.js.map} +1 -1
- package/dist/chunks/{AuditLogCollection-NYUFFPni.js → AuditLogCollection-BvJ39Qa7.js} +2 -3
- package/dist/chunks/{AuditLogCollection-NYUFFPni.js.map → AuditLogCollection-BvJ39Qa7.js.map} +1 -1
- package/dist/chunks/{NostrIdentity-joAS5ZlD.js → NostrIdentity-CRClZAF0.js} +4 -4
- package/dist/chunks/{NostrIdentity-joAS5ZlD.js.map → NostrIdentity-CRClZAF0.js.map} +1 -1
- package/dist/chunks/{NostrIdentityCollection-B9G_vrWL.js → NostrIdentityCollection-6eKkDSnZ.js} +2 -4
- package/dist/chunks/NostrIdentityCollection-6eKkDSnZ.js.map +1 -0
- package/dist/chunks/{OidcIdentity-B06GwRj2.js → OidcIdentity-CzZbq7Lv.js} +3 -3
- package/dist/chunks/{OidcIdentity-B06GwRj2.js.map → OidcIdentity-CzZbq7Lv.js.map} +1 -1
- package/dist/chunks/{OidcIdentityCollection-lHtQmTFB.js → OidcIdentityCollection-C5r_toph.js} +3 -3
- package/dist/chunks/{OidcIdentityCollection-lHtQmTFB.js.map → OidcIdentityCollection-C5r_toph.js.map} +1 -1
- package/dist/chunks/{ProfileAssetCollection-CijIwtKj.js → ProfileAssetCollection-DwLqpZe0.js} +3 -3
- package/dist/chunks/{ProfileAssetCollection-CijIwtKj.js.map → ProfileAssetCollection-DwLqpZe0.js.map} +1 -1
- package/dist/chunks/{ProfileCollection-CSFLzcXp.js → ProfileCollection-CO74zsSf.js} +28 -28
- package/dist/chunks/{ProfileCollection-CSFLzcXp.js.map → ProfileCollection-CO74zsSf.js.map} +1 -1
- package/dist/chunks/{ProfileLinkCollection-BHgVmkly.js → ProfileLinkCollection-CzmFe8_n.js} +3 -3
- package/dist/chunks/{ProfileLinkCollection-BHgVmkly.js.map → ProfileLinkCollection-CzmFe8_n.js.map} +1 -1
- package/dist/chunks/{ProfileMetadataCollection-BStSVlUX.js → ProfileMetadataCollection-LAWIrnCP.js} +2 -2
- package/dist/chunks/{ProfileMetadataCollection-BStSVlUX.js.map → ProfileMetadataCollection-LAWIrnCP.js.map} +1 -1
- package/dist/chunks/{ProfileMetafieldCollection-DCZi2Ba1.js → ProfileMetafieldCollection-DsumXtKX.js} +2 -2
- package/dist/chunks/{ProfileMetafieldCollection-DCZi2Ba1.js.map → ProfileMetafieldCollection-DsumXtKX.js.map} +1 -1
- package/dist/chunks/{ProfileRelationshipCollection-Cat8A3R3.js → ProfileRelationshipCollection-BsRbLqaH.js} +5 -5
- package/dist/chunks/{ProfileRelationshipCollection-Cat8A3R3.js.map → ProfileRelationshipCollection-BsRbLqaH.js.map} +1 -1
- package/dist/chunks/{ProfileRelationshipTermCollection-CInZSL7B.js → ProfileRelationshipTermCollection-MN3A0ZPp.js} +2 -2
- package/dist/chunks/{ProfileRelationshipTermCollection-CInZSL7B.js.map → ProfileRelationshipTermCollection-MN3A0ZPp.js.map} +1 -1
- package/dist/chunks/{ProfileRelationshipType-tp6iZQVQ.js → ProfileRelationshipType-BqFwMM-w.js} +2 -2
- package/dist/chunks/{ProfileRelationshipType-tp6iZQVQ.js.map → ProfileRelationshipType-BqFwMM-w.js.map} +1 -1
- package/dist/chunks/{ProfileRelationshipTypeCollection-Dkb0nsnt.js → ProfileRelationshipTypeCollection-BmKtnlaP.js} +3 -3
- package/dist/chunks/{ProfileRelationshipTypeCollection-Dkb0nsnt.js.map → ProfileRelationshipTypeCollection-BmKtnlaP.js.map} +1 -1
- package/dist/chunks/{ProfileTypeCollection-BYSvknkE.js → ProfileTypeCollection-BRxbs9mz.js} +3 -3
- package/dist/chunks/{ProfileTypeCollection-BYSvknkE.js.map → ProfileTypeCollection-BRxbs9mz.js.map} +1 -1
- package/dist/chunks/{oidcProvisioningPrimitives-ClLJDotp.js → oidcProvisioningPrimitives-HMb3NIi3.js} +5 -5
- package/dist/chunks/{oidcProvisioningPrimitives-ClLJDotp.js.map → oidcProvisioningPrimitives-HMb3NIi3.js.map} +1 -1
- package/dist/chunks/{resolveIdentity-CBP8wpBI.js → resolveIdentity-CQfLpOeY.js} +16 -16
- package/dist/chunks/{resolveIdentity-CBP8wpBI.js.map → resolveIdentity-CQfLpOeY.js.map} +1 -1
- package/dist/collections/AuditLogCollection.d.ts.map +1 -1
- package/dist/collections/NostrIdentityCollection.d.ts.map +1 -1
- package/dist/index.js +24 -24
- package/dist/index.js.map +1 -1
- package/dist/internal/oidc-provisioning.js +2 -2
- package/dist/manifest.json +1 -1
- package/dist/smrt-knowledge.json +3 -3
- package/dist/utils.js +4 -4
- package/package.json +6 -6
- package/dist/chunks/NostrIdentityCollection-B9G_vrWL.js.map +0 -1
package/dist/chunks/{ProfileLinkCollection-BHgVmkly.js.map → ProfileLinkCollection-CzmFe8_n.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileLinkCollection-BHgVmkly.js","names":[],"sources":["../../src/models/ProfileLink.ts","../../src/collections/ProfileLinkCollection.ts"],"sourcesContent":["/**\n * ProfileLink model - An ordered web link on a profile\n *\n * A profile's social accounts and websites: one row per link, ordered by\n * `sortOrder`, several links per platform allowed (\"Website\", \"Other\").\n * Links belong to their profile's tenant and are removed with the profile.\n */\n\nimport {\n field,\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\n/** Where a profile link points. `website` and `other` accept any web address. */\nexport const PROFILE_LINK_PLATFORMS = [\n 'facebook',\n 'instagram',\n 'x',\n 'linkedin',\n 'youtube',\n 'tiktok',\n 'website',\n 'other',\n] as const;\n\nexport type ProfileLinkPlatform = (typeof PROFILE_LINK_PLATFORMS)[number];\n\n/** Longest address a link may hold. */\nexport const PROFILE_LINK_MAX_URL_LENGTH = 2048;\n\n/** Longest label a link may hold. */\nexport const PROFILE_LINK_MAX_LABEL_LENGTH = 200;\n\nexport function isProfileLinkPlatform(\n value: unknown,\n): value is ProfileLinkPlatform {\n return (\n typeof value === 'string' &&\n (PROFILE_LINK_PLATFORMS as readonly string[]).includes(value)\n );\n}\n\n/**\n * The address as a normalized http(s) URL. Throws for anything else: other\n * schemes (`javascript:`, `data:`, `mailto:`), embedded credentials, blanks,\n * whitespace, or over-long values.\n */\nexport function normalizeProfileLinkUrl(raw: string): string {\n const text = String(raw ?? '').trim();\n if (!text) throw new Error('A profile link needs a web address');\n if (text.length > PROFILE_LINK_MAX_URL_LENGTH || /\\s/.test(text)) {\n throw new Error('A profile link must be a single web address');\n }\n let url: URL;\n try {\n url = new URL(text);\n } catch {\n throw new Error(`Not a web address: ${text}`);\n }\n if (url.protocol !== 'https:' && url.protocol !== 'http:') {\n throw new Error('A profile link must start with http:// or https://');\n }\n if (url.username || url.password) {\n throw new Error('A profile link cannot carry a user name or password');\n }\n if (!url.hostname) throw new Error(`Not a web address: ${text}`);\n return url.toString();\n}\n\nexport interface ProfileLinkOptions extends SmrtObjectOptions {\n profileId?: string;\n platform?: ProfileLinkPlatform;\n url?: string;\n label?: string | null;\n sortOrder?: number;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'profile_links',\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ProfileLink extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Profile', {\n required: true,\n requiredFor: 'identity',\n onDelete: 'CASCADE',\n })\n profileId = '';\n\n /** One of {@link PROFILE_LINK_PLATFORMS}. */\n @field({ required: true, maxLength: 32 })\n platform: ProfileLinkPlatform = 'website';\n\n /** A normalized http(s) address. */\n @field({ required: true, requiredFor: 'identity', maxLength: 2048 })\n url = '';\n\n /** Optional words shown instead of the address (\"Campaign site\"). */\n @field({ nullable: true, maxLength: 200 })\n label: string | null = null;\n\n /** Position in the profile's list, from 0. */\n @field()\n sortOrder = 0;\n\n constructor(options: ProfileLinkOptions = {}) {\n super(options);\n if (options.profileId) this.profileId = options.profileId;\n if (options.platform) this.platform = options.platform;\n if (options.url) this.url = options.url;\n if (options.label !== undefined) this.label = options.label;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n\n /**\n * A link's address and label are not its identity: two people can link the\n * same page, and one person can relabel a link. Without an explicit slug\n * the default (label-derived) slug would make a new link adopt another row\n * through the (tenant, slug, context) natural key, so a link's default slug\n * is its id.\n */\n override async getSlug(): Promise<string | null | undefined> {\n if (!this.slug && this.id) this.slug = String(this.id);\n return super.getSlug();\n }\n\n /** Validates and normalizes the link before it is written. */\n override async save(...args: Parameters<SmrtObject['save']>): Promise<this> {\n if (!this.profileId) throw new Error('A profile link needs a profile');\n if (!isProfileLinkPlatform(this.platform)) {\n throw new Error(`Unknown profile link platform: ${this.platform}`);\n }\n this.url = normalizeProfileLinkUrl(this.url);\n const label = this.label?.trim() ?? '';\n if (label.length > PROFILE_LINK_MAX_LABEL_LENGTH) {\n throw new Error('A profile link label is too long');\n }\n this.label = label || null;\n if (!Number.isInteger(this.sortOrder) || this.sortOrder < 0) {\n throw new Error('A profile link sortOrder must be a whole number ≥ 0');\n }\n return super.save(...args);\n }\n}\n","/**\n * ProfileLinkCollection - A profile's ordered web links\n *\n * Reads return a profile's links in display order; writes replace or reorder\n * the whole list in one transaction so a reader never sees half a list.\n */\n\nimport {\n isEmbeddedDatabase,\n SmrtCollection,\n withEmbeddedWriteTransaction,\n} from '@happyvertical/smrt-core';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n isProfileLinkPlatform,\n normalizeProfileLinkUrl,\n ProfileLink,\n type ProfileLinkPlatform,\n} from '../models/ProfileLink';\n\n/** One link as a caller supplies it, in display order. */\nexport interface ProfileLinkInput {\n platform: ProfileLinkPlatform;\n url: string;\n label?: string | null;\n}\n\n/** Most links one profile may hold. */\nexport const PROFILE_LINK_LIMIT = 50;\n\nexport class ProfileLinkCollection extends SmrtCollection<ProfileLink> {\n static readonly _itemClass = ProfileLink;\n\n /** The profile's links in display order (sortOrder, then age). */\n async listForProfile(profileId: string): Promise<ProfileLink[]> {\n if (!profileId) return [];\n const links = await this.list({ where: { profileId } });\n return links.sort(compareLinks);\n }\n\n /**\n * Makes the profile's links exactly `links`, in that order, in one\n * transaction: a link whose address is already on the profile keeps its row\n * (and id), new addresses are added, and links left out are removed. The\n * same address given twice is kept once, at its first position. New links\n * take the profile's tenant. Throws, changing nothing, when the profile is\n * not visible in the current tenant context or a link is invalid.\n */\n async replaceForProfile(\n profileId: string,\n links: readonly ProfileLinkInput[],\n ): Promise<ProfileLink[]> {\n const wanted = normalizeInputs(links);\n return this.inTransaction(async (bound) => {\n const tenantId = await bound.requireProfileTenant(profileId);\n const existing = await bound.listForProfile(profileId);\n const byUrl = new Map<string, ProfileLink>();\n for (const link of existing) {\n if (!byUrl.has(link.url)) byUrl.set(link.url, link);\n }\n\n const kept = new Set<ProfileLink>();\n const result: ProfileLink[] = [];\n for (const [index, input] of wanted.entries()) {\n const current = byUrl.get(input.url);\n if (current) {\n kept.add(current);\n const changed =\n current.platform !== input.platform ||\n (current.label ?? null) !== input.label ||\n current.sortOrder !== index ||\n (!current.tenantId && tenantId !== null);\n current.platform = input.platform;\n current.label = input.label;\n current.sortOrder = index;\n if (!current.tenantId && tenantId) current.tenantId = tenantId;\n if (changed) await current.save();\n result.push(current);\n continue;\n }\n const created = await bound.create({\n profileId,\n platform: input.platform,\n url: input.url,\n label: input.label,\n sortOrder: index,\n ...(tenantId ? { tenantId } : {}),\n });\n // create() already persisted it.\n result.push(created);\n }\n\n for (const link of existing) {\n if (!kept.has(link)) await link.delete();\n }\n return result;\n });\n }\n\n /**\n * Puts the profile's links in the order of `linkIds`, which must name every\n * link on the profile exactly once. One transaction; throws, changing\n * nothing, on a missing, extra or repeated id.\n */\n async reorder(\n profileId: string,\n linkIds: readonly string[],\n ): Promise<ProfileLink[]> {\n return this.inTransaction(async (bound) => {\n await bound.requireProfileTenant(profileId);\n const existing = await bound.listForProfile(profileId);\n const byId = new Map(existing.map((link) => [String(link.id), link]));\n const ids = linkIds.map(String);\n if (\n ids.length !== existing.length ||\n new Set(ids).size !== ids.length ||\n ids.some((id) => !byId.has(id))\n ) {\n throw new Error(\n 'Reorder must list every link on the profile exactly once',\n );\n }\n const ordered: ProfileLink[] = [];\n for (const [index, id] of ids.entries()) {\n const link = byId.get(id) as ProfileLink;\n if (link.sortOrder !== index) {\n link.sortOrder = index;\n await link.save();\n }\n ordered.push(link);\n }\n return ordered;\n });\n }\n\n /** The profile's tenant; throws when the profile is not visible here. */\n private async requireProfileTenant(\n profileId: string,\n ): Promise<string | null> {\n if (!profileId) throw new Error('A profile link needs a profile');\n const { ProfileCollection } = await import('./ProfileCollection');\n const profiles = await ProfileCollection.create({ db: this.db });\n const profile = await profiles.get({ id: profileId });\n if (!profile) throw new Error(`Profile '${profileId}' not found`);\n return profile.tenantId ?? null;\n }\n\n private async inTransaction<T>(\n work: (bound: ProfileLinkCollection) => Promise<T>,\n ): Promise<T> {\n const db = this.db as DatabaseInterface;\n return withEmbeddedWriteTransaction(\n db,\n isEmbeddedDatabase(db),\n async (transaction) =>\n work(await ProfileLinkCollection.create({ db: transaction })),\n );\n }\n}\n\nfunction compareLinks(a: ProfileLink, b: ProfileLink): number {\n if (a.sortOrder !== b.sortOrder) return a.sortOrder - b.sortOrder;\n const aTime = new Date(a.created_at ?? 0).getTime();\n const bTime = new Date(b.created_at ?? 0).getTime();\n if (aTime !== bTime) return aTime - bTime;\n return String(a.id).localeCompare(String(b.id));\n}\n\nfunction normalizeInputs(\n links: readonly ProfileLinkInput[],\n): Array<{ platform: ProfileLinkPlatform; url: string; label: string | null }> {\n if (links.length > PROFILE_LINK_LIMIT) {\n throw new Error(\n `A profile can hold at most ${PROFILE_LINK_LIMIT} links (got ${links.length})`,\n );\n }\n const seen = new Set<string>();\n const out: Array<{\n platform: ProfileLinkPlatform;\n url: string;\n label: string | null;\n }> = [];\n for (const link of links) {\n if (!isProfileLinkPlatform(link.platform)) {\n throw new Error(`Unknown profile link platform: ${link.platform}`);\n }\n const url = normalizeProfileLinkUrl(link.url);\n if (seen.has(url)) continue;\n seen.add(url);\n out.push({\n platform: link.platform,\n url,\n label: link.label?.trim() ? link.label.trim() : null,\n });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBO,IAAM,yBAAyB;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAKO,IAAM,8BAA8B;AAGpC,IAAM,gCAAgC;AAEtC,SAAS,sBACd,OAC8B;CAC9B,OACE,OAAO,UAAU,YAChB,uBAA6C,SAAS,KAAK;AAEhE;AAOO,SAAS,wBAAwB,KAAqB;CAC3D,MAAM,OAAO,OAAO,OAAO,EAAE,CAAA,CAAE,KAAK;CACpC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,oCAAoC;CAC/D,IAAI,KAAK,SAAA,QAAwC,KAAK,KAAK,IAAI,GAC7D,MAAM,IAAI,MAAM,6CAA6C;CAE/D,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,IAAI;CACpB,QAAQ;EACN,MAAM,IAAI,MAAM,sBAAsB,MAAM;CAC9C;CACA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,IAAI,MAAM,oDAAoD;CAEtE,IAAI,IAAI,YAAY,IAAI,UACtB,MAAM,IAAI,MAAM,qDAAqD;CAE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AC6E;CAC7E,IAAI,MAAM,SAAA,IACR,MAAM,IAAI,MACR,4CAA+D,MAAM,OAAM,EAC7E;CAEF,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,MAID,CAAC;CACN,KAAA,MAAW,QAAQ,OAAO;EACxB,IAAI,CAAC,sBAAsB,KAAK,QAAQ,GACtC,MAAM,IAAI,MAAM,kCAAkC,KAAK,UAAU;EAEnE,MAAM,MAAM,wBAAwB,KAAK,GAAG;EAC5C,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,KAAK,IAAI,GAAG;EACZ,IAAI,KAAK;GACP,UAAU,KAAK;GACf;GACA,OAAO,KAAK,OAAO,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI;EAClD,CAAC;CACH;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"ProfileLinkCollection-CzmFe8_n.js","names":[],"sources":["../../src/models/ProfileLink.ts","../../src/collections/ProfileLinkCollection.ts"],"sourcesContent":["/**\n * ProfileLink model - An ordered web link on a profile\n *\n * A profile's social accounts and websites: one row per link, ordered by\n * `sortOrder`, several links per platform allowed (\"Website\", \"Other\").\n * Links belong to their profile's tenant and are removed with the profile.\n */\n\nimport {\n field,\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\n/** Where a profile link points. `website` and `other` accept any web address. */\nexport const PROFILE_LINK_PLATFORMS = [\n 'facebook',\n 'instagram',\n 'x',\n 'linkedin',\n 'youtube',\n 'tiktok',\n 'website',\n 'other',\n] as const;\n\nexport type ProfileLinkPlatform = (typeof PROFILE_LINK_PLATFORMS)[number];\n\n/** Longest address a link may hold. */\nexport const PROFILE_LINK_MAX_URL_LENGTH = 2048;\n\n/** Longest label a link may hold. */\nexport const PROFILE_LINK_MAX_LABEL_LENGTH = 200;\n\nexport function isProfileLinkPlatform(\n value: unknown,\n): value is ProfileLinkPlatform {\n return (\n typeof value === 'string' &&\n (PROFILE_LINK_PLATFORMS as readonly string[]).includes(value)\n );\n}\n\n/**\n * The address as a normalized http(s) URL. Throws for anything else: other\n * schemes (`javascript:`, `data:`, `mailto:`), embedded credentials, blanks,\n * whitespace, or over-long values.\n */\nexport function normalizeProfileLinkUrl(raw: string): string {\n const text = String(raw ?? '').trim();\n if (!text) throw new Error('A profile link needs a web address');\n if (text.length > PROFILE_LINK_MAX_URL_LENGTH || /\\s/.test(text)) {\n throw new Error('A profile link must be a single web address');\n }\n let url: URL;\n try {\n url = new URL(text);\n } catch {\n throw new Error(`Not a web address: ${text}`);\n }\n if (url.protocol !== 'https:' && url.protocol !== 'http:') {\n throw new Error('A profile link must start with http:// or https://');\n }\n if (url.username || url.password) {\n throw new Error('A profile link cannot carry a user name or password');\n }\n if (!url.hostname) throw new Error(`Not a web address: ${text}`);\n return url.toString();\n}\n\nexport interface ProfileLinkOptions extends SmrtObjectOptions {\n profileId?: string;\n platform?: ProfileLinkPlatform;\n url?: string;\n label?: string | null;\n sortOrder?: number;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'profile_links',\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ProfileLink extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Profile', {\n required: true,\n requiredFor: 'identity',\n onDelete: 'CASCADE',\n })\n profileId = '';\n\n /** One of {@link PROFILE_LINK_PLATFORMS}. */\n @field({ required: true, maxLength: 32 })\n platform: ProfileLinkPlatform = 'website';\n\n /** A normalized http(s) address. */\n @field({ required: true, requiredFor: 'identity', maxLength: 2048 })\n url = '';\n\n /** Optional words shown instead of the address (\"Campaign site\"). */\n @field({ nullable: true, maxLength: 200 })\n label: string | null = null;\n\n /** Position in the profile's list, from 0. */\n @field()\n sortOrder = 0;\n\n constructor(options: ProfileLinkOptions = {}) {\n super(options);\n if (options.profileId) this.profileId = options.profileId;\n if (options.platform) this.platform = options.platform;\n if (options.url) this.url = options.url;\n if (options.label !== undefined) this.label = options.label;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n\n /**\n * A link's address and label are not its identity: two people can link the\n * same page, and one person can relabel a link. Without an explicit slug\n * the default (label-derived) slug would make a new link adopt another row\n * through the (tenant, slug, context) natural key, so a link's default slug\n * is its id.\n */\n override async getSlug(): Promise<string | null | undefined> {\n if (!this.slug && this.id) this.slug = String(this.id);\n return super.getSlug();\n }\n\n /** Validates and normalizes the link before it is written. */\n override async save(...args: Parameters<SmrtObject['save']>): Promise<this> {\n if (!this.profileId) throw new Error('A profile link needs a profile');\n if (!isProfileLinkPlatform(this.platform)) {\n throw new Error(`Unknown profile link platform: ${this.platform}`);\n }\n this.url = normalizeProfileLinkUrl(this.url);\n const label = this.label?.trim() ?? '';\n if (label.length > PROFILE_LINK_MAX_LABEL_LENGTH) {\n throw new Error('A profile link label is too long');\n }\n this.label = label || null;\n if (!Number.isInteger(this.sortOrder) || this.sortOrder < 0) {\n throw new Error('A profile link sortOrder must be a whole number ≥ 0');\n }\n return super.save(...args);\n }\n}\n","/**\n * ProfileLinkCollection - A profile's ordered web links\n *\n * Reads return a profile's links in display order; writes replace or reorder\n * the whole list in one transaction so a reader never sees half a list.\n */\n\nimport {\n isEmbeddedDatabase,\n SmrtCollection,\n withEmbeddedWriteTransaction,\n} from '@happyvertical/smrt-core';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n isProfileLinkPlatform,\n normalizeProfileLinkUrl,\n ProfileLink,\n type ProfileLinkPlatform,\n} from '../models/ProfileLink';\n\n/** One link as a caller supplies it, in display order. */\nexport interface ProfileLinkInput {\n platform: ProfileLinkPlatform;\n url: string;\n label?: string | null;\n}\n\n/** Most links one profile may hold. */\nexport const PROFILE_LINK_LIMIT = 50;\n\nexport class ProfileLinkCollection extends SmrtCollection<ProfileLink> {\n static readonly _itemClass = ProfileLink;\n\n /** The profile's links in display order (sortOrder, then age). */\n async listForProfile(profileId: string): Promise<ProfileLink[]> {\n if (!profileId) return [];\n const links = await this.list({ where: { profileId } });\n return links.sort(compareLinks);\n }\n\n /**\n * Makes the profile's links exactly `links`, in that order, in one\n * transaction: a link whose address is already on the profile keeps its row\n * (and id), new addresses are added, and links left out are removed. The\n * same address given twice is kept once, at its first position. New links\n * take the profile's tenant. Throws, changing nothing, when the profile is\n * not visible in the current tenant context or a link is invalid.\n */\n async replaceForProfile(\n profileId: string,\n links: readonly ProfileLinkInput[],\n ): Promise<ProfileLink[]> {\n const wanted = normalizeInputs(links);\n return this.inTransaction(async (bound) => {\n const tenantId = await bound.requireProfileTenant(profileId);\n const existing = await bound.listForProfile(profileId);\n const byUrl = new Map<string, ProfileLink>();\n for (const link of existing) {\n if (!byUrl.has(link.url)) byUrl.set(link.url, link);\n }\n\n const kept = new Set<ProfileLink>();\n const result: ProfileLink[] = [];\n for (const [index, input] of wanted.entries()) {\n const current = byUrl.get(input.url);\n if (current) {\n kept.add(current);\n const changed =\n current.platform !== input.platform ||\n (current.label ?? null) !== input.label ||\n current.sortOrder !== index ||\n (!current.tenantId && tenantId !== null);\n current.platform = input.platform;\n current.label = input.label;\n current.sortOrder = index;\n if (!current.tenantId && tenantId) current.tenantId = tenantId;\n if (changed) await current.save();\n result.push(current);\n continue;\n }\n const created = await bound.create({\n profileId,\n platform: input.platform,\n url: input.url,\n label: input.label,\n sortOrder: index,\n ...(tenantId ? { tenantId } : {}),\n });\n // create() already persisted it.\n result.push(created);\n }\n\n for (const link of existing) {\n if (!kept.has(link)) await link.delete();\n }\n return result;\n });\n }\n\n /**\n * Puts the profile's links in the order of `linkIds`, which must name every\n * link on the profile exactly once. One transaction; throws, changing\n * nothing, on a missing, extra or repeated id.\n */\n async reorder(\n profileId: string,\n linkIds: readonly string[],\n ): Promise<ProfileLink[]> {\n return this.inTransaction(async (bound) => {\n await bound.requireProfileTenant(profileId);\n const existing = await bound.listForProfile(profileId);\n const byId = new Map(existing.map((link) => [String(link.id), link]));\n const ids = linkIds.map(String);\n if (\n ids.length !== existing.length ||\n new Set(ids).size !== ids.length ||\n ids.some((id) => !byId.has(id))\n ) {\n throw new Error(\n 'Reorder must list every link on the profile exactly once',\n );\n }\n const ordered: ProfileLink[] = [];\n for (const [index, id] of ids.entries()) {\n const link = byId.get(id) as ProfileLink;\n if (link.sortOrder !== index) {\n link.sortOrder = index;\n await link.save();\n }\n ordered.push(link);\n }\n return ordered;\n });\n }\n\n /** The profile's tenant; throws when the profile is not visible here. */\n private async requireProfileTenant(\n profileId: string,\n ): Promise<string | null> {\n if (!profileId) throw new Error('A profile link needs a profile');\n const { ProfileCollection } = await import('./ProfileCollection');\n const profiles = await ProfileCollection.create({ db: this.db });\n const profile = await profiles.get({ id: profileId });\n if (!profile) throw new Error(`Profile '${profileId}' not found`);\n return profile.tenantId ?? null;\n }\n\n private async inTransaction<T>(\n work: (bound: ProfileLinkCollection) => Promise<T>,\n ): Promise<T> {\n const db = this.db as DatabaseInterface;\n return withEmbeddedWriteTransaction(\n db,\n isEmbeddedDatabase(db),\n async (transaction) =>\n work(await ProfileLinkCollection.create({ db: transaction })),\n );\n }\n}\n\nfunction compareLinks(a: ProfileLink, b: ProfileLink): number {\n if (a.sortOrder !== b.sortOrder) return a.sortOrder - b.sortOrder;\n const aTime = new Date(a.created_at ?? 0).getTime();\n const bTime = new Date(b.created_at ?? 0).getTime();\n if (aTime !== bTime) return aTime - bTime;\n return String(a.id).localeCompare(String(b.id));\n}\n\nfunction normalizeInputs(\n links: readonly ProfileLinkInput[],\n): Array<{ platform: ProfileLinkPlatform; url: string; label: string | null }> {\n if (links.length > PROFILE_LINK_LIMIT) {\n throw new Error(\n `A profile can hold at most ${PROFILE_LINK_LIMIT} links (got ${links.length})`,\n );\n }\n const seen = new Set<string>();\n const out: Array<{\n platform: ProfileLinkPlatform;\n url: string;\n label: string | null;\n }> = [];\n for (const link of links) {\n if (!isProfileLinkPlatform(link.platform)) {\n throw new Error(`Unknown profile link platform: ${link.platform}`);\n }\n const url = normalizeProfileLinkUrl(link.url);\n if (seen.has(url)) continue;\n seen.add(url);\n out.push({\n platform: link.platform,\n url,\n label: link.label?.trim() ? link.label.trim() : null,\n });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBO,IAAM,yBAAyB;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAKO,IAAM,8BAA8B;AAGpC,IAAM,gCAAgC;AAEtC,SAAS,sBACd,OAC8B;CAC9B,OACE,OAAO,UAAU,YAChB,uBAA6C,SAAS,KAAK;AAEhE;AAOO,SAAS,wBAAwB,KAAqB;CAC3D,MAAM,OAAO,OAAO,OAAO,EAAE,CAAA,CAAE,KAAK;CACpC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,oCAAoC;CAC/D,IAAI,KAAK,SAAA,QAAwC,KAAK,KAAK,IAAI,GAC7D,MAAM,IAAI,MAAM,6CAA6C;CAE/D,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,IAAI;CACpB,QAAQ;EACN,MAAM,IAAI,MAAM,sBAAsB,MAAM;CAC9C;CACA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,IAAI,MAAM,oDAAoD;CAEtE,IAAI,IAAI,YAAY,IAAI,UACtB,MAAM,IAAI,MAAM,qDAAqD;CAEvE,IAAI,CAAC,IAAI,UAAU,MAAM,IAAI,MAAM,sBAAsB,MAAM;CAC/D,OAAO,IAAI,SAAS;AACtB;AAkBO,IAAM,cAAN,cAA0B,WAAW;CAE1C,WAA0B;CAO1B,YAAY;CAIZ,WAAgC;CAIhC,MAAM;CAIN,QAAuB;CAIvB,YAAY;CAEZ,YAAY,UAA8B,CAAC,GAAG;EAC5C,MAAM,OAAO;EACb,IAAI,QAAQ,WAAW,KAAK,YAAY,QAAQ;EAChD,IAAI,QAAQ,UAAU,KAAK,WAAW,QAAQ;EAC9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;EACZ,IAAI,KAAK;GACP,UAAU,KAAK;GACf;GACA,OAAO,KAAK,OAAO,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI;EAClD,CAAC;CACH;CACA,OAAO;AACT"}
|
package/dist/chunks/{ProfileMetadataCollection-BStSVlUX.js → ProfileMetadataCollection-LAWIrnCP.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
2
|
import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
|
|
3
3
|
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
|
|
4
4
|
//#region src/models/ProfileMetadata.ts
|
|
@@ -117,4 +117,4 @@ var ProfileMetadataCollection = class extends SmrtCollection {
|
|
|
117
117
|
//#endregion
|
|
118
118
|
export { ProfileMetadataCollection_exports as n, ProfileMetadata as r, ProfileMetadataCollection as t };
|
|
119
119
|
|
|
120
|
-
//# sourceMappingURL=ProfileMetadataCollection-
|
|
120
|
+
//# sourceMappingURL=ProfileMetadataCollection-LAWIrnCP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetadataCollection-
|
|
1
|
+
{"version":3,"file":"ProfileMetadataCollection-LAWIrnCP.js","names":[],"sources":["../../src/models/ProfileMetadata.ts","../../src/collections/ProfileMetadataCollection.ts"],"sourcesContent":["/**\n * ProfileMetadata model - Stores metadata values for profiles\n *\n * Links profiles to metafield definitions with actual values.\n * Uses UUID primary key with foreign keys to Profile and ProfileMetafield.\n */\n\nimport {\n field,\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\nexport interface ProfileMetadataOptions extends SmrtObjectOptions {\n profileId?: string;\n metafieldId?: string;\n value?: string;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileMetadata extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // id: UUID (auto-generated by SmrtObject)\n @foreignKey('Profile', { required: true, requiredFor: 'identity' })\n profileId?: string; // References Profile.id\n\n @foreignKey('ProfileMetafield', { required: true, requiredFor: 'identity' })\n metafieldId?: string; // References ProfileMetafield.id\n\n @field()\n value: string = ''; // The metadata value (stored as text)\n\n constructor(options: ProfileMetadataOptions = {}) {\n super(options);\n if (options.profileId !== undefined) this.profileId = options.profileId;\n if (options.metafieldId !== undefined)\n this.metafieldId = options.metafieldId;\n if (options.value) this.value = options.value;\n // The class-field initializer above runs after super(), so an explicit\n // tenant must be re-applied here or it is silently dropped.\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n\n /**\n * Validate this metadata value against the metafield's validation schema\n *\n * @returns True if valid, throws error if invalid\n */\n async validate(): Promise<boolean> {\n const metafield = await this.loadRelated('metafieldId');\n if (!metafield) {\n throw new Error('Metafield not found');\n }\n\n return await metafield.validateValue(this.value);\n }\n\n /**\n * Get the metafield slug for this metadata\n *\n * @returns The slug of the metafield\n */\n async getMetafieldSlug(): Promise<string> {\n const metafield = await this.loadRelated('metafieldId');\n return metafield?.slug || '';\n }\n}\n","/**\n * ProfileMetadataCollection - Collection manager for ProfileMetadata objects\n *\n * Provides querying and batch operations for profile metadata.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileMetadata } from '../models/ProfileMetadata';\n\nexport class ProfileMetadataCollection extends SmrtCollection<ProfileMetadata> {\n static readonly _itemClass = ProfileMetadata;\n\n /**\n * Get all metadata for a profile\n *\n * @param profileId - The profile UUID\n * @returns Array of ProfileMetadata instances\n */\n async getByProfile(profileId: string): Promise<ProfileMetadata[]> {\n return await this.list({ where: { profileId } });\n }\n\n /**\n * Get metadata as key-value object for a profile\n *\n * @param profileId - The profile UUID\n * @returns Object with metafield slugs as keys\n */\n async getMetadataObject(profileId: string): Promise<Record<string, string>> {\n const metadata = await this.getByProfile(profileId);\n const result: Record<string, string> = {};\n\n for (const item of metadata) {\n const slug = await item.getMetafieldSlug();\n if (slug) {\n result[slug] = item.value;\n }\n }\n\n return result;\n }\n\n /**\n * Find all profiles with a specific metadata key-value pair\n *\n * @param metafieldId - The metafield UUID\n * @param value - The value to match\n * @returns Array of profile UUIDs\n */\n async findProfilesByMetadata(\n metafieldId: string,\n value: unknown,\n ): Promise<string[]> {\n const matches = await this.list({\n where: { metafieldId, value: String(value) },\n });\n\n return matches\n .map((m) => m.profileId)\n .filter((id) => typeof id === 'string') as string[];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BO,IAAM,kBAAN,cAA8B,WAAW;CAE9C,WAA0B;CAI1B;CAGA;CAGA,QAAgB;CAEhB,YAAY,UAAkC,CAAC,GAAG;EAChD,MAAM,OAAO;EACb,IAAI,QAAQ,cAAc,KAAA,GAAW,KAAK,YAAY,QAAQ;EAC9D,IAAI,QAAQ,gBAAgB,KAAA,GAC1B,KAAK,cAAc,QAAQ;EAC7B,IAAI,QAAQ,OAAO,KAAK,QAAQ,QAAQ;EAGxC,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;CAC9D;;;;;;CAOA,MAAM,WAA6B;EACjC,MAAM,YAAY,MAAM,KAAK,YAAY,aAAa;EACtD,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,qBAAqB;EAGvC,OAAO,MAAM,UAAU,cAAc,KAAK,KAAK;CACjD;;;;;;CAOA,MAAM,mBAAoC;EAExC,QAAO,MADiB,KAAK,YAAY,aAAa,EAAA,EACpC,QAAQ;CAC5B;AACF;AAhDkD,cAArC,iBAA4C,mBAAkB,8BAAA;AAEzE,gBAAA,CADC,SA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 +1,4 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
2
|
import { SmrtCollection, SmrtObject, field, smrt } from "@happyvertical/smrt-core";
|
|
3
3
|
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
|
|
4
4
|
//#region src/models/ProfileMetafield.ts
|
|
@@ -148,4 +148,4 @@ var ProfileMetafieldCollection = class extends SmrtCollection {
|
|
|
148
148
|
//#endregion
|
|
149
149
|
export { ProfileMetafieldCollection_exports as n, ProfileMetafield as r, ProfileMetafieldCollection as t };
|
|
150
150
|
|
|
151
|
-
//# sourceMappingURL=ProfileMetafieldCollection-
|
|
151
|
+
//# sourceMappingURL=ProfileMetafieldCollection-DsumXtKX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetafieldCollection-DCZi2Ba1.js","names":[],"sources":["../../src/models/ProfileMetafield.ts","../../src/collections/ProfileMetafieldCollection.ts"],"sourcesContent":["/**\n * ProfileMetafield model - Controlled vocabulary for metadata fields\n *\n * Defines allowed metadata keys with validation rules.\n * Uses UUID primary key with unique slug for human-readable lookups.\n */\n\nimport {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { ValidationSchema, ValidatorFunction } from '../types';\n\nexport interface ProfileMetafieldOptions extends SmrtObjectOptions {\n slug?: string;\n name?: string;\n description?: string;\n validation?: ValidationSchema;\n tenantId?: string | null;\n}\n\n/**\n * Extend globalThis to include custom validators registry.\n * Using globalThis ensures all module instances share the same validators,\n * which is critical in monorepos where the same package can be loaded\n * from different paths (e.g., pnpm store vs workspace symlink).\n *\n * @see https://github.com/happyvertical/smrt/issues/543\n */\ndeclare global {\n // eslint-disable-next-line no-var\n var __smrtProfileMetafieldValidators:\n | Map<string, ValidatorFunction>\n | undefined;\n}\n\n/**\n * Get the custom validators Map from globalThis\n */\nfunction getCustomValidators(): Map<string, ValidatorFunction> {\n if (!globalThis.__smrtProfileMetafieldValidators) {\n globalThis.__smrtProfileMetafieldValidators = new Map<\n string,\n ValidatorFunction\n >();\n }\n return globalThis.__smrtProfileMetafieldValidators;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileMetafield extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // id: UUID (auto-generated by SmrtObject)\n // slug is inherited from SmrtObject (auto-generated from name)\n @field()\n name: string = '';\n\n description?: string;\n\n validation?: ValidationSchema; // Validation schema as JSON\n\n constructor(options: ProfileMetafieldOptions = {}) {\n super(options);\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.validation !== undefined) this.validation = options.validation;\n // The class-field initializer above runs after super(), so an explicit\n // tenant must be re-applied here or it is silently dropped.\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n\n /**\n * Convenience method for slug-based lookup\n *\n * @param slug - The slug to search for\n * @returns ProfileMetafield instance or null if not found\n */\n static async getBySlug(_slug: string): Promise<ProfileMetafield | null> {\n // Will be auto-implemented by SMRT\n return null;\n }\n\n /**\n * Register a custom validator function\n *\n * @param name - Name of the validator (used in validation.custom field)\n * @param validator - The validator function\n */\n static registerValidator(name: string, validator: ValidatorFunction): void {\n getCustomValidators().set(name, validator);\n }\n\n /**\n * Get a registered custom validator\n *\n * @param name - Name of the validator\n * @returns The validator function or undefined\n */\n static getValidator(name: string): ValidatorFunction | undefined {\n return getCustomValidators().get(name);\n }\n\n /**\n * Validate a value against this metafield's validation schema\n *\n * @param value - The value to validate\n * @returns True if valid, throws ValidationError if invalid\n */\n async validateValue(value: unknown): Promise<boolean> {\n if (!this.validation) return true;\n\n const schema = this.validation;\n\n // Type validation\n if (schema.type) {\n const actualType = typeof value;\n const expectedType = schema.type;\n\n if (expectedType === 'number' && actualType !== 'number') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n if (expectedType === 'string' && actualType !== 'string') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n if (expectedType === 'boolean' && actualType !== 'boolean') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n }\n\n // String validations\n if (schema.pattern && typeof value === 'string') {\n const regex = new RegExp(schema.pattern);\n if (!regex.test(value)) {\n throw new Error(schema.message || 'Pattern validation failed');\n }\n }\n\n if (schema.minLength && typeof value === 'string') {\n if (value.length < schema.minLength) {\n throw new Error(\n schema.message ||\n `Minimum length is ${schema.minLength}, got ${value.length}`,\n );\n }\n }\n\n if (schema.maxLength && typeof value === 'string') {\n if (value.length > schema.maxLength) {\n throw new Error(\n schema.message ||\n `Maximum length is ${schema.maxLength}, got ${value.length}`,\n );\n }\n }\n\n // Numeric validations\n if (schema.min !== undefined && typeof value === 'number') {\n if (value < schema.min) {\n throw new Error(\n schema.message || `Value must be at least ${schema.min}`,\n );\n }\n }\n\n if (schema.max !== undefined && typeof value === 'number') {\n if (value > schema.max) {\n throw new Error(\n schema.message || `Value must be at most ${schema.max}`,\n );\n }\n }\n\n // Custom validator\n if (schema.custom) {\n const validator = ProfileMetafield.getValidator(schema.custom);\n if (!validator) {\n throw new Error(`Custom validator '${schema.custom}' not registered`);\n }\n\n const result = await validator(value);\n if (!result) {\n throw new Error(schema.message || 'Custom validation failed');\n }\n }\n\n return true;\n }\n}\n","/**\n * ProfileMetafieldCollection - Collection manager for ProfileMetafield objects\n *\n * Provides querying for profile metafield lookup table.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileMetafield } from '../models/ProfileMetafield';\nimport type { ValidationSchema } from '../types';\n\nexport class ProfileMetafieldCollection extends SmrtCollection<ProfileMetafield> {\n static readonly _itemClass = ProfileMetafield;\n\n /**\n * Get metafield by slug\n *\n * @param slug - The slug to search for\n * @returns ProfileMetafield instance or null\n */\n async getBySlug(slug: string): Promise<ProfileMetafield | null> {\n return await this.get({ slug });\n }\n\n /**\n * Get or create a metafield by slug\n *\n * @param slug - The slug to search for\n * @param defaults - Default values if creating\n * @returns ProfileMetafield instance\n */\n async getOrCreateBySlug(\n slug: string,\n defaults: {\n name: string;\n description?: string;\n validation?: ValidationSchema;\n },\n ): Promise<ProfileMetafield> {\n const existing = await this.getBySlug(slug);\n if (existing) return existing;\n\n const metafield = await this.create({ slug, ...defaults });\n await metafield.save();\n return metafield;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,SAAS,sBAAsD;CAC7D,IAAI,CAAC,WAAW,kCACd,WAAW,mDAAmC,IAAI,IAGhD;CAEJ,OAAO,WAAW;AACpB;AASO,IAAM,mBAAN,cAA+B,WAAW;CAE/C,WAA0B;CAK1B,OAAe;CAEf;CAEA;CAEA,YAAY,UAAmC,CAAC,GAAG;EACjD,MAAM,OAAO;EACb,IAAI,QAAQ,MAAM,KAAK,OAAO,QAAQ;EACtC,IAAI,QAAQ,gBAAgB,KAAA,GAC1B,KAAK,cAAc,QAAQ;EAC7B,IAAI,QAAQ,eAAe,KAAA,GAAW,KAAK,aAAa,QAAQ;EAGhE,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;CAC9D;;;;;;;CAQA,aAAa,UAAU,OAAiD;EAEtE,OAAO;CACT;;;;;;;CAQA,OAAO,kBAAkB,MAAc,WAAoC;EACzE,oBAAoB,CAAA,CAAE,IAAI,MAAM,SAAS;CAC3C;;;;;;;CAQA,OAAO,aAAa,MAA6C;EAC/D,OAAO,oBAAoB,CAAA,CAAE,IAAI,IAAI;CACvC;;;;;;;CAQA,MAAM,cAAc,OAAkC;EACpD,IAAI,CAAC,KAAK,YAAY,OAAO;EAE7B,MAAM,SA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,KAAK,GAElC,MAAM,IAAI,MAAM,OAAO,WAAW,0BAA0B;EAEhE;EAEA,OAAO;CACT;AACF;AAlJmD,cAAtC,kBAA6C,mBAAkB,8BAAA;AAE1E,gBAAA,CADC,SAAS,EAAE,UAAU,KAAK,CAAC,CAAA,GADjB,iBAEX,WAAA,YAAA,CAAA;AAKA,gBAAA,CADC,MAAM,CAAA,GANI,iBAOX,WAAA,QAAA,CAAA;AAPW,mBAAN,gBAAA,CAPN,aAAa,EAAE,MAAM,WAAW,CAAC,GACjC,KAAK;CACJ,eAAe;CACf,KAAK,EAAE,SAAS;EAAC;EAAQ;EAAO;EAAU;CAAQ,EAAE;CACpD,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,cAAc,KAAK;AAC5B,CAAC,CAAA,GACY,gBAAA;;;;ACjDN,IAAM,6BAAN,cAAyC,eAAiC;CAC/E,OAAgB,aAAa;;;;;;;CAQ7B,MAAM,UAAU,MAAgD;EAC9D,OAAO,MAAM,KAAK,IAAI,EAAE,KAAK,CAAC;CAChC;;;;;;;;CASA,MAAM,kBACJ,MACA,UAK2B;EAC3B,MAAM,WAAW,MAAM,KAAK,UAAU,IAAI;EAC1C,IAAI,UAAU,OAAO;EAErB,MAAM,YAAY,MAAM,KAAK,OAAO;GAAE;GAAM,GAAG;EAAS,CAAC;EACzD,MAAM,UAAU,KAAK;EACrB,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"ProfileMetafieldCollection-DsumXtKX.js","names":[],"sources":["../../src/models/ProfileMetafield.ts","../../src/collections/ProfileMetafieldCollection.ts"],"sourcesContent":["/**\n * ProfileMetafield model - Controlled vocabulary for metadata fields\n *\n * Defines allowed metadata keys with validation rules.\n * Uses UUID primary key with unique slug for human-readable lookups.\n */\n\nimport {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { ValidationSchema, ValidatorFunction } from '../types';\n\nexport interface ProfileMetafieldOptions extends SmrtObjectOptions {\n slug?: string;\n name?: string;\n description?: string;\n validation?: ValidationSchema;\n tenantId?: string | null;\n}\n\n/**\n * Extend globalThis to include custom validators registry.\n * Using globalThis ensures all module instances share the same validators,\n * which is critical in monorepos where the same package can be loaded\n * from different paths (e.g., pnpm store vs workspace symlink).\n *\n * @see https://github.com/happyvertical/smrt/issues/543\n */\ndeclare global {\n // eslint-disable-next-line no-var\n var __smrtProfileMetafieldValidators:\n | Map<string, ValidatorFunction>\n | undefined;\n}\n\n/**\n * Get the custom validators Map from globalThis\n */\nfunction getCustomValidators(): Map<string, ValidatorFunction> {\n if (!globalThis.__smrtProfileMetafieldValidators) {\n globalThis.__smrtProfileMetafieldValidators = new Map<\n string,\n ValidatorFunction\n >();\n }\n return globalThis.__smrtProfileMetafieldValidators;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileMetafield extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // id: UUID (auto-generated by SmrtObject)\n // slug is inherited from SmrtObject (auto-generated from name)\n @field()\n name: string = '';\n\n description?: string;\n\n validation?: ValidationSchema; // Validation schema as JSON\n\n constructor(options: ProfileMetafieldOptions = {}) {\n super(options);\n if (options.name) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.validation !== undefined) this.validation = options.validation;\n // The class-field initializer above runs after super(), so an explicit\n // tenant must be re-applied here or it is silently dropped.\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n\n /**\n * Convenience method for slug-based lookup\n *\n * @param slug - The slug to search for\n * @returns ProfileMetafield instance or null if not found\n */\n static async getBySlug(_slug: string): Promise<ProfileMetafield | null> {\n // Will be auto-implemented by SMRT\n return null;\n }\n\n /**\n * Register a custom validator function\n *\n * @param name - Name of the validator (used in validation.custom field)\n * @param validator - The validator function\n */\n static registerValidator(name: string, validator: ValidatorFunction): void {\n getCustomValidators().set(name, validator);\n }\n\n /**\n * Get a registered custom validator\n *\n * @param name - Name of the validator\n * @returns The validator function or undefined\n */\n static getValidator(name: string): ValidatorFunction | undefined {\n return getCustomValidators().get(name);\n }\n\n /**\n * Validate a value against this metafield's validation schema\n *\n * @param value - The value to validate\n * @returns True if valid, throws ValidationError if invalid\n */\n async validateValue(value: unknown): Promise<boolean> {\n if (!this.validation) return true;\n\n const schema = this.validation;\n\n // Type validation\n if (schema.type) {\n const actualType = typeof value;\n const expectedType = schema.type;\n\n if (expectedType === 'number' && actualType !== 'number') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n if (expectedType === 'string' && actualType !== 'string') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n if (expectedType === 'boolean' && actualType !== 'boolean') {\n throw new Error(\n schema.message || `Expected ${expectedType}, got ${actualType}`,\n );\n }\n }\n\n // String validations\n if (schema.pattern && typeof value === 'string') {\n const regex = new RegExp(schema.pattern);\n if (!regex.test(value)) {\n throw new Error(schema.message || 'Pattern validation failed');\n }\n }\n\n if (schema.minLength && typeof value === 'string') {\n if (value.length < schema.minLength) {\n throw new Error(\n schema.message ||\n `Minimum length is ${schema.minLength}, got ${value.length}`,\n );\n }\n }\n\n if (schema.maxLength && typeof value === 'string') {\n if (value.length > schema.maxLength) {\n throw new Error(\n schema.message ||\n `Maximum length is ${schema.maxLength}, got ${value.length}`,\n );\n }\n }\n\n // Numeric validations\n if (schema.min !== undefined && typeof value === 'number') {\n if (value < schema.min) {\n throw new Error(\n schema.message || `Value must be at least ${schema.min}`,\n );\n }\n }\n\n if (schema.max !== undefined && typeof value === 'number') {\n if (value > schema.max) {\n throw new Error(\n schema.message || `Value must be at most ${schema.max}`,\n );\n }\n }\n\n // Custom validator\n if (schema.custom) {\n const validator = ProfileMetafield.getValidator(schema.custom);\n if (!validator) {\n throw new Error(`Custom validator '${schema.custom}' not registered`);\n }\n\n const result = await validator(value);\n if (!result) {\n throw new Error(schema.message || 'Custom validation failed');\n }\n }\n\n return true;\n }\n}\n","/**\n * ProfileMetafieldCollection - Collection manager for ProfileMetafield objects\n *\n * Provides querying for profile metafield lookup table.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileMetafield } from '../models/ProfileMetafield';\nimport type { ValidationSchema } from '../types';\n\nexport class ProfileMetafieldCollection extends SmrtCollection<ProfileMetafield> {\n static readonly _itemClass = ProfileMetafield;\n\n /**\n * Get metafield by slug\n *\n * @param slug - The slug to search for\n * @returns ProfileMetafield instance or null\n */\n async getBySlug(slug: string): Promise<ProfileMetafield | null> {\n return await this.get({ slug });\n }\n\n /**\n * Get or create a metafield by slug\n *\n * @param slug - The slug to search for\n * @param defaults - Default values if creating\n * @returns ProfileMetafield instance\n */\n async getOrCreateBySlug(\n slug: string,\n defaults: {\n name: string;\n description?: string;\n validation?: ValidationSchema;\n },\n ): Promise<ProfileMetafield> {\n const existing = await this.getBySlug(slug);\n if (existing) return existing;\n\n const metafield = await this.create({ slug, ...defaults });\n await metafield.save();\n return metafield;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,SAAS,sBAAsD;CAC7D,IAAI,CAAC,WAAW,kCACd,WAAW,mDAAmC,IAAI,IAGhD;CAEJ,OAAO,WAAW;AACpB;AASO,IAAM,mBAAN,cAA+B,WAAW;CAE/C,WAA0B;CAK1B,OAAe;CAEf;CAEA;CAEA,YAAY,UAAmC,CAAC,GAAG;EACjD,MAAM,OAAO;EACb,IAAI,QAAQ,MAAM,KAAK,OAAO,QAAQ;EACtC,IAAI,QAAQ,gBAAgB,KAAA,GAC1B,KAAK,cAAc,QAAQ;EAC7B,IAAI,QAAQ,eAAe,KAAA,GAAW,KAAK,aAAa,QAAQ;EAGhE,IAAI,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rB,OAAO;CACT;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
2
|
import { SmrtCollection, SmrtObject, foreignKey, oneToMany, smrt } from "@happyvertical/smrt-core";
|
|
3
3
|
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
|
|
4
4
|
//#region src/models/ProfileRelationship.ts
|
|
@@ -48,7 +48,7 @@ var ProfileRelationship = class extends SmrtObject {
|
|
|
48
48
|
async addTerm(startedAt, endedAt) {
|
|
49
49
|
if (!this.id) throw new Error("ProfileRelationship.addTerm requires a persisted relationship (missing id)");
|
|
50
50
|
const relationshipId = this.id;
|
|
51
|
-
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-
|
|
51
|
+
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-MN3A0ZPp.js").then((n) => n.n);
|
|
52
52
|
await (await (await ProfileRelationshipTermCollection.create(this.options)).create({
|
|
53
53
|
relationshipId,
|
|
54
54
|
startedAt,
|
|
@@ -70,7 +70,7 @@ var ProfileRelationship = class extends SmrtObject {
|
|
|
70
70
|
* @returns Array of ProfileRelationshipTerm instances
|
|
71
71
|
*/
|
|
72
72
|
async getTerms() {
|
|
73
|
-
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-
|
|
73
|
+
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-MN3A0ZPp.js").then((n) => n.n);
|
|
74
74
|
return await (await ProfileRelationshipTermCollection.create(this.options)).getByRelationship(this.id);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
@@ -79,7 +79,7 @@ var ProfileRelationship = class extends SmrtObject {
|
|
|
79
79
|
* @returns Current term or null if none active
|
|
80
80
|
*/
|
|
81
81
|
async getActiveTerm() {
|
|
82
|
-
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-
|
|
82
|
+
const { ProfileRelationshipTermCollection } = await import("./ProfileRelationshipTermCollection-MN3A0ZPp.js").then((n) => n.n);
|
|
83
83
|
return await (await ProfileRelationshipTermCollection.create(this.options)).getActiveTerm(this.id);
|
|
84
84
|
}
|
|
85
85
|
};
|
|
@@ -173,4 +173,4 @@ var ProfileRelationshipCollection = class extends SmrtCollection {
|
|
|
173
173
|
//#endregion
|
|
174
174
|
export { ProfileRelationshipCollection_exports as n, ProfileRelationship as r, ProfileRelationshipCollection as t };
|
|
175
175
|
|
|
176
|
-
//# sourceMappingURL=ProfileRelationshipCollection-
|
|
176
|
+
//# sourceMappingURL=ProfileRelationshipCollection-BsRbLqaH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileRelationshipCollection-
|
|
1
|
+
{"version":3,"file":"ProfileRelationshipCollection-BsRbLqaH.js","names":[],"sources":["../../src/models/ProfileRelationship.ts","../../src/collections/ProfileRelationshipCollection.ts"],"sourcesContent":["/**\n * ProfileRelationship model - Connects two profiles with a relationship type\n *\n * Represents directional or reciprocal relationships between profiles.\n * Uses UUID primary key with foreign keys to profiles and relationship type.\n */\n\nimport {\n foreignKey,\n oneToMany,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { ProfileRelationshipTerm } from './ProfileRelationshipTerm';\n\nexport interface ProfileRelationshipOptions extends SmrtObjectOptions {\n fromProfileId?: string;\n toProfileId?: string;\n typeId?: string;\n contextProfileId?: string;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileRelationship extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n // id: UUID (auto-generated by SmrtObject)\n @foreignKey('Profile', { required: true, requiredFor: 'identity' })\n fromProfileId?: string; // Origin profile\n\n @foreignKey('Profile', { required: true, requiredFor: 'identity' })\n toProfileId?: string; // Target profile\n\n @foreignKey('ProfileRelationshipType', {\n required: true,\n requiredFor: 'identity',\n })\n typeId?: string; // Relationship type\n\n @foreignKey('Profile')\n contextProfileId?: string; // Optional tertiary context\n\n // Relationships\n @oneToMany('ProfileRelationshipTerm')\n terms: ProfileRelationshipTerm[] = [];\n\n constructor(options: ProfileRelationshipOptions = {}) {\n super(options);\n if (options.fromProfileId !== undefined)\n this.fromProfileId = options.fromProfileId;\n if (options.toProfileId !== undefined)\n this.toProfileId = options.toProfileId;\n if (options.typeId !== undefined) this.typeId = options.typeId;\n if (options.contextProfileId !== undefined)\n this.contextProfileId = options.contextProfileId;\n }\n\n /**\n * Get the relationship type slug\n *\n * @returns The slug of the relationship type\n */\n async getTypeSlug(): Promise<string> {\n const type = await this.loadRelated('typeId');\n return type?.slug || '';\n }\n\n /**\n * Add a term (time period) to this relationship\n *\n * @param startedAt - Start date of the term\n * @param endedAt - Optional end date of the term\n */\n async addTerm(startedAt: Date, endedAt?: Date): Promise<void> {\n if (!this.id) {\n throw new Error(\n 'ProfileRelationship.addTerm requires a persisted relationship (missing id)',\n );\n }\n const relationshipId = this.id;\n\n const { ProfileRelationshipTermCollection } = await import(\n '../collections/ProfileRelationshipTermCollection'\n );\n\n const termCollection = await ProfileRelationshipTermCollection.create(\n this.options,\n );\n\n const term = await termCollection.create({\n relationshipId,\n startedAt,\n endedAt,\n });\n\n await term.save();\n }\n\n /**\n * End the current active term\n *\n * @param endedAt - End date for the term\n */\n async endCurrentTerm(endedAt: Date): Promise<void> {\n const activeTerm = await this.getActiveTerm();\n if (activeTerm) {\n await activeTerm.end(endedAt);\n }\n }\n\n /**\n * Get all terms for this relationship\n *\n * @returns Array of ProfileRelationshipTerm instances\n */\n async getTerms(): Promise<ProfileRelationshipTerm[]> {\n const { ProfileRelationshipTermCollection } = await import(\n '../collections/ProfileRelationshipTermCollection'\n );\n\n const termCollection = await ProfileRelationshipTermCollection.create(\n this.options,\n );\n\n return await termCollection.getByRelationship(this.id as string);\n }\n\n /**\n * Get the active term (no end date)\n *\n * @returns Current term or null if none active\n */\n async getActiveTerm(): Promise<ProfileRelationshipTerm | null> {\n const { ProfileRelationshipTermCollection } = await import(\n '../collections/ProfileRelationshipTermCollection'\n );\n\n const termCollection = await ProfileRelationshipTermCollection.create(\n this.options,\n );\n\n return await termCollection.getActiveTerm(this.id as string);\n }\n}\n","/**\n * ProfileRelationshipCollection - Collection manager for ProfileRelationship objects\n *\n * Provides querying for relationships between profiles.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileRelationship } from '../models/ProfileRelationship';\n\nexport class ProfileRelationshipCollection extends SmrtCollection<ProfileRelationship> {\n static readonly _itemClass = ProfileRelationship;\n\n /**\n * Get all relationships from a profile\n *\n * @param fromProfileId - The origin profile UUID\n * @param typeId - Optional filter by relationship type UUID\n * @returns Array of ProfileRelationship instances\n */\n async getFromProfile(\n fromProfileId: string,\n typeId?: string,\n ): Promise<ProfileRelationship[]> {\n const where: Record<string, unknown> = { fromProfileId };\n if (typeId) where.typeId = typeId;\n\n return await this.list({ where });\n }\n\n /**\n * Get all relationships to a profile\n *\n * @param toProfileId - The target profile UUID\n * @param typeId - Optional filter by relationship type UUID\n * @returns Array of ProfileRelationship instances\n */\n async getToProfile(\n toProfileId: string,\n typeId?: string,\n ): Promise<ProfileRelationship[]> {\n const where: Record<string, unknown> = { toProfileId };\n if (typeId) where.typeId = typeId;\n\n return await this.list({ where });\n }\n\n /**\n * Get all relationships for a profile (both directions)\n *\n * @param profileId - The profile UUID\n * @param typeId - Optional filter by relationship type UUID\n * @returns Array of ProfileRelationship instances\n */\n async getForProfile(\n profileId: string,\n typeId?: string,\n ): Promise<ProfileRelationship[]> {\n const fromRelationships = await this.getFromProfile(profileId, typeId);\n const toRelationships = await this.getToProfile(profileId, typeId);\n\n return [...fromRelationships, ...toRelationships];\n }\n\n /**\n * Check if a relationship exists between two profiles\n *\n * @param fromProfileId - The origin profile UUID\n * @param toProfileId - The target profile UUID\n * @param typeId - The relationship type UUID\n * @returns True if relationship exists\n */\n async exists(\n fromProfileId: string,\n toProfileId: string,\n typeId: string,\n ): Promise<boolean> {\n const matches = await this.list({\n where: { fromProfileId, toProfileId, typeId },\n limit: 1,\n });\n\n return matches.length > 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCO,IAAM,sBAAN,cAAkC,WAAW;CAElD,WAA0B;CAI1B;CAGA;CAMA;CAGA;CAIA,QAAmC,CAAC;CAEpC,YAAY,UAAsC,CAAC,GAAG;EACpD,MAAM,OAAO;EACb,IAAI,QAAQ,kBAAkB,KAAA,GAC5B,KAAK,gBAAgB,QAAQ;EAC/B,IAAI,QAAQ,gBAAgB,KAAA,GAC1B,KAAK,cAAc,QAAQ;EAC7B,IAAI,QAAQ,WAAW,KAAA,GAAW,KAAK,SAAS,QAAQ;EACxD,IAAI,QAAQ,qBAAqB,KAAA,GAC/B,KAAK,mBAAmB,QAAQ;CACpC;;;;;;CAOA,MAAM,cAA+B;EAEnC,QAAO,MADY,KAAK,YAAY,QAAQ,EAAA,EAC/B,QAAQ;CACvB;;;;;;;CAQA,MAAM,QAAQ,WAAiB,SAA+B;EAC5D,IAAI,CAAC,KAAK,IACR,MAAM,IAAI,MACR,4EACF;EAEF,MAAM,iBAAiB,KAAK;EAE5B,MAAM,EAAE,sCAAsC,MAAM,OAClD,kDAAA,CAAA,MAAA,MAAA,EAAA,CAAA;EAaF,OAAM,OANa,MAJU,kCAAkC,OAC7D,KAAK,OACP,EAAA,CAEkC,OAAO;GACvC;GACA;GACA;EACF,CAAC,EAAA,CAEU,KAAK;CAClB;;;;;;CAOA,MAAM,eAAe,SAA8B;EACjD,MAAM,aAAa,MAAM,KAAK,cAAc;EAC5C,IAAI,YACF,MAAM,WAAW,IAAI,OAAO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A;;;;ACvBN,IAAM,gCAAN,cAA4C,eAAoC;CACrF,OAAgB,aAAa;;;;;;;;CAS7B,MAAM,eACJ,eACA,QACgC;EAChC,MAAM,QAAiC,EAAE,cAAc;EACvD,IAAI,QAAQ,MAAM,SAAS;EAE3B,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;;;;;CASA,MAAM,aACJ,aACA,QACgC;EAChC,MAAM,QAAiC,EAAE,YAAY;EACrD,IAAI,QAAQ,MAAM,SAAS;EAE3B,OAAO,MAAM,KAAK,KAAK,EAAE,MAAM,CAAC;CAClC;;;;;;;;CASA,MAAM,cACJ,WACA,QACgC;EAChC,MAAM,oBAAoB,MAAM,KAAK,eAAe,WAAW,MAAM;EACrE,MAAM,kBAAkB,MAAM,KAAK,aAAa,WAAW,MAAM;EAEjE,OAAO,CAAC,GAAG,mBAAmB,GAAG,eAAe;CAClD;;;;;;;;;CAUA,MAAM,OACJ,eACA,aACA,QACkB;EAMlB,QAAO,MALe,KAAK,KAAK;GAC9B,OAAO;IAAE;IAAe;IAAa;GAAO;GAC5C,OAAO;EACT,CAAC,EAAA,CAEc,SAAS;CAC1B;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
2
|
import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
|
|
3
3
|
//#region src/models/ProfileRelationshipTerm.ts
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -113,4 +113,4 @@ var ProfileRelationshipTermCollection = class extends SmrtCollection {
|
|
|
113
113
|
//#endregion
|
|
114
114
|
export { ProfileRelationshipTermCollection_exports as n, ProfileRelationshipTerm as r, ProfileRelationshipTermCollection as t };
|
|
115
115
|
|
|
116
|
-
//# sourceMappingURL=ProfileRelationshipTermCollection-
|
|
116
|
+
//# sourceMappingURL=ProfileRelationshipTermCollection-MN3A0ZPp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileRelationshipTermCollection-
|
|
1
|
+
{"version":3,"file":"ProfileRelationshipTermCollection-MN3A0ZPp.js","names":[],"sources":["../../src/models/ProfileRelationshipTerm.ts","../../src/collections/ProfileRelationshipTermCollection.ts"],"sourcesContent":["/**\n * ProfileRelationshipTerm model - Temporal data for relationships\n *\n * Defines the duration or terms of a specific relationship.\n * Uses UUID primary key with foreign key to ProfileRelationship.\n */\n\nimport {\n field,\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\n\nexport interface ProfileRelationshipTermOptions extends SmrtObjectOptions {\n relationshipId?: string;\n startedAt?: Date;\n endedAt?: Date;\n}\n\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileRelationshipTerm extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n // id: UUID (auto-generated by SmrtObject)\n @foreignKey('ProfileRelationship', {\n required: true,\n requiredFor: 'identity',\n })\n relationshipId?: string; // References ProfileRelationship.id\n\n @field({ required: true })\n startedAt: Date = new Date(); // Start date of the term\n\n endedAt?: Date; // Optional end date\n\n constructor(options: ProfileRelationshipTermOptions = {}) {\n super(options);\n if (options.relationshipId !== undefined)\n this.relationshipId = options.relationshipId;\n if (options.startedAt) this.startedAt = options.startedAt;\n if (options.endedAt !== undefined) this.endedAt = options.endedAt;\n }\n\n /**\n * Check if this term is currently active\n *\n * @returns True if active (no end date or end date in future)\n */\n isActive(): boolean {\n if (!this.endedAt) return true;\n return this.endedAt > new Date();\n }\n\n /**\n * End this term\n *\n * @param endedAt - End date for the term (defaults to now)\n */\n async end(endedAt: Date = new Date()): Promise<void> {\n this.endedAt = endedAt;\n await this.save();\n }\n\n /**\n * Get the duration of this term in days\n *\n * @returns Duration in days\n */\n getDurationDays(): number {\n const endValue = this.endedAt || new Date();\n const diffMs = endValue.getTime() - this.startedAt.getTime();\n return Math.floor(diffMs / (1000 * 60 * 60 * 24));\n }\n}\n","/**\n * ProfileRelationshipTermCollection - Collection manager for ProfileRelationshipTerm objects\n *\n * Provides querying for relationship terms (temporal data).\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileRelationshipTerm } from '../models/ProfileRelationshipTerm';\n\nexport class ProfileRelationshipTermCollection extends SmrtCollection<ProfileRelationshipTerm> {\n static readonly _itemClass = ProfileRelationshipTerm;\n\n /**\n * Get all terms for a relationship\n *\n * @param relationshipId - The relationship UUID\n * @returns Array of ProfileRelationshipTerm instances\n */\n async getByRelationship(\n relationshipId: string,\n ): Promise<ProfileRelationshipTerm[]> {\n return await this.list({\n where: { relationshipId },\n orderBy: ['startedAt DESC'],\n });\n }\n\n /**\n * Get the active term for a relationship (no end date or future end date)\n *\n * @param relationshipId - The relationship UUID\n * @returns Active term or null\n */\n async getActiveTerm(\n relationshipId: string,\n ): Promise<ProfileRelationshipTerm | null> {\n const terms = await this.getByRelationship(relationshipId);\n\n for (const term of terms) {\n if (term.isActive()) {\n return term;\n }\n }\n\n return null;\n }\n\n /**\n * Get all historical (ended) terms for a relationship\n *\n * @param relationshipId - The relationship UUID\n * @returns Array of ended ProfileRelationshipTerm instances\n */\n async getHistoricalTerms(\n relationshipId: string,\n ): Promise<ProfileRelationshipTerm[]> {\n const terms = await this.getByRelationship(relationshipId);\n return terms.filter((term) => !term.isActive());\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BO,IAAM,0BAAN,cAAsC,WAAW;CAMtD;CAGA,4BAAkB,IAAI,KAAK;CAE3B;CAEA,YAAY,UAA0C,CAAC,GAAG;EACxD,MAAM,OAAO;EACb,IAAI,QAAQ,mBAAmB,KAAA,GAC7B,KAAK,iBAAiB,QAAQ;EAChC,IAAI,QAAQ,WAAW,KAAK,YAAY,QAAQ;EAChD,IA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;;CAQA,MAAM,mBACJ,gBACoC;EAEpC,QAAO,MADa,KAAK,kBAAkB,cAAc,EAAA,CAC5C,QAAQ,SAAS,CAAC,KAAK,SAAS,CAAC;CAChD;AACF"}
|
package/dist/chunks/{ProfileRelationshipType-tp6iZQVQ.js → ProfileRelationshipType-BqFwMM-w.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
2
|
import { SmrtObject, field, smrt } from "@happyvertical/smrt-core";
|
|
3
3
|
//#region src/models/ProfileRelationshipType.ts
|
|
4
4
|
var ProfileRelationshipType_exports = /* @__PURE__ */ __exportAll({ ProfileRelationshipType: () => ProfileRelationshipType });
|
|
@@ -103,4 +103,4 @@ ProfileRelationshipType = __decorateClass([smrt({
|
|
|
103
103
|
//#endregion
|
|
104
104
|
export { ProfileRelationshipType_exports as n, ProfileRelationshipType as t };
|
|
105
105
|
|
|
106
|
-
//# sourceMappingURL=ProfileRelationshipType-
|
|
106
|
+
//# sourceMappingURL=ProfileRelationshipType-BqFwMM-w.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileRelationshipType-
|
|
1
|
+
{"version":3,"file":"ProfileRelationshipType-BqFwMM-w.js","names":[],"sources":["../../src/models/ProfileRelationshipType.ts"],"sourcesContent":["/**\n * ProfileRelationshipType model - Lookup table for relationship types\n *\n * Defines the kinds of relationships that can exist between profiles.\n * Uses UUID primary key with unique slug for human-readable lookups.\n */\n\nimport {\n field,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport type { ReciprocalHandler } from '../types';\n\nexport interface ProfileRelationshipTypeOptions extends SmrtObjectOptions {\n slug?: string;\n name?: string;\n reciprocal?: boolean;\n}\n\n/**\n * Extend globalThis to include reciprocal handlers registry.\n * Using globalThis ensures all module instances share the same handlers,\n * which is critical in monorepos where the same package can be loaded\n * from different paths (e.g., pnpm store vs workspace symlink).\n *\n * @see https://github.com/happyvertical/smrt/issues/543\n */\ndeclare global {\n // eslint-disable-next-line no-var\n var __smrtProfileRelationshipHandlers:\n | Map<string, ReciprocalHandler>\n | undefined;\n // eslint-disable-next-line no-var\n var __smrtProfileRelationshipHandlersInitialized: boolean | undefined;\n}\n\n/**\n * Get the reciprocal handlers Map from globalThis\n */\nfunction getReciprocalHandlers(): Map<string, ReciprocalHandler> {\n if (!globalThis.__smrtProfileRelationshipHandlers) {\n globalThis.__smrtProfileRelationshipHandlers = new Map<\n string,\n ReciprocalHandler\n >();\n }\n return globalThis.__smrtProfileRelationshipHandlers;\n}\n\n/**\n * Default handlers for common reciprocal relationship patterns\n */\nconst DEFAULT_HANDLERS: Record<string, ReciprocalHandler> = {\n // Symmetric relationships (same type in both directions)\n friend: async (from, to, context) => {\n await to.addRelationship(from, 'friend', context);\n },\n\n spouse: async (from, to) => {\n await to.addRelationship(from, 'spouse');\n },\n\n partner: async (from, to, context) => {\n await to.addRelationship(from, 'partner', context);\n },\n\n colleague: async (from, to, context) => {\n await to.addRelationship(from, 'colleague', context);\n },\n\n sibling: async (from, to) => {\n await to.addRelationship(from, 'sibling');\n },\n};\n\n// Register default handlers (only once across all module instances)\nif (!globalThis.__smrtProfileRelationshipHandlersInitialized) {\n globalThis.__smrtProfileRelationshipHandlersInitialized = true;\n for (const [slug, handler] of Object.entries(DEFAULT_HANDLERS)) {\n getReciprocalHandlers().set(slug, handler);\n }\n}\n\n@smrt({\n tableStrategy: 'sti',\n api: { include: ['list', 'get', 'create', 'update'] },\n mcp: { include: ['list', 'get'] },\n cli: { skipApiCheck: true },\n})\nexport class ProfileRelationshipType extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n // id: UUID (auto-generated by SmrtObject)\n // slug is inherited from SmrtObject (auto-generated from name)\n @field()\n name: string = '';\n\n reciprocal: boolean = true; // True for two-way relationships\n\n constructor(options: ProfileRelationshipTypeOptions = {}) {\n super(options);\n if (options.name) this.name = options.name;\n if (options.reciprocal !== undefined) this.reciprocal = options.reciprocal;\n }\n\n /**\n * Convenience method for slug-based lookup\n *\n * @param slug - The slug to search for\n * @returns ProfileRelationshipType instance or null if not found\n */\n static async getBySlug(\n _slug: string,\n ): Promise<ProfileRelationshipType | null> {\n // Will be auto-implemented by SMRT\n return null;\n }\n\n /**\n * Register a custom reciprocal handler for a relationship type\n *\n * @param slug - The relationship type slug\n * @param handler - The handler function to execute when creating reciprocal relationship\n */\n static registerReciprocalHandler(\n slug: string,\n handler: ReciprocalHandler,\n ): void {\n getReciprocalHandlers().set(slug, handler);\n }\n\n /**\n * Get the reciprocal handler for a relationship type\n *\n * @param slug - The relationship type slug\n * @returns The handler function or undefined\n */\n static getReciprocalHandler(slug: string): ReciprocalHandler | undefined {\n return getReciprocalHandlers().get(slug);\n }\n\n /**\n * Check if a relationship type is reciprocal\n *\n * @param slug - The relationship type slug\n * @returns True if reciprocal, false otherwise\n */\n static async isReciprocal(slug: string): Promise<boolean> {\n const type = await ProfileRelationshipType.getBySlug(slug);\n return type?.reciprocal || false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,SAAS,wBAAwD;CAC/D,IAAI,CAAC,WAAW,mCACd,WAAW,oDAAoC,IAAI,IAGjD;CAEJ,OAAO,WAAW;AACpB;AAKA,IAAM,mBAAsD;CAE1D,QAAQ,OAAO,MAAM,IAAI,YAAY;EACnC,MAAM,GAAG,gBAAgB,MAAM,UAAU,OAAO;CAClD;CAEA,QAAQ,OAAO,MAAM,OAAO;EAC1B,MAAM,GAAG,gBAAgB,MAAM,QAAQ;CACzC;CAEA,SAAS,OAAO,MAAM,IAAI,YAAY;EACpC,MAAM,GAAG,gBAAgB,MAAM,WAAW,OAAO;CACnD;CAEA,WAAW,OAAO,MAAM,IAAI,YAAY;EACtC,MAAM,GAAG,gBAAgB,MAAM,aAAa,OAAO;CACrD;CAEA,SAAS,OAAO,MAAM,OAAO;EAC3B,MAAM,GAAG,gBAAgB,MAAM,SAAS;CAC1C;AACF;AAGA,IAAI,CAAC,WAAW,8CAA8C;CAC5D,WAAW,+CAA+C;CAC1D,KAAA,MAAW,CAAC,MAAM,YAAY,OAAO,QAAQ,gBAAgB,GAC3D,sBAAsB,CAAA,CAAE,IAAI,MAAM,OAAO;AAE7C;AAQO,IAAM,0BAAN,cAAsC,WAAW;CAItD,OAAe;CAEf,aAAsB;CAEtB,YAAY,UAA0C,CAAC,GAAG;EACxD,MAAM,OAAO;EACb,IAAI,QAAQ,MAAM,KAAK,OAAO,QAAQ;EACtC,IAAI,QAAQ,eAAe,KAAA,GAAW,KAAK,aAAa,QAAQ;CAClE;;;;;;;CAQA,aAAa,UACX,OACyC;EAEzC,OAAO;CACT;;;;;;;CAQA,OAAO,0BACL,MACA,SACM;EACN,sBAAsB,CAAA,CAAE,IAAI,MAAM,OAAO;CAC3C;;;;;;;CAQA,OAAO,qBAAqB,MAA6C;EACvE,OAAO,sBAAsB,CAAA,CAAE,IAAI,IAAI;CACzC;;;;;;;CAQA,aAAa,aAAa,MAAgC;EAExD,QAAO,MADY,wBAAwB,UAAU,IAAI,EAAA,EAC5C,cAAc;CAC7B;AACF;AA5D0D,cAA7C,yBAAoD,mBAAkB,8BAAA;AAIjF,gBAAA,CADC,MAAM,CAAA,GAHI,wBAIX,WAAA,QAAA,CAAA;AAJW,0BAAN,gBAAA,CANN,KAAK;CACJ,eAAe;CACf,KAAK,EAAE,SAAS;EAAC;EAAQ;EAAO;EAAU;CAAQ,EAAE;CACpD,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,EAAE;CAChC,KAAK,EAAE,cAAc,KAAK;AAC5B,CAAC,CAAA,GACY,uBAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
2
|
-
import { t as ProfileRelationshipType } from "./ProfileRelationshipType-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
|
+
import { t as ProfileRelationshipType } from "./ProfileRelationshipType-BqFwMM-w.js";
|
|
3
3
|
import { SmrtCollection } from "@happyvertical/smrt-core";
|
|
4
4
|
//#region src/collections/ProfileRelationshipTypeCollection.ts
|
|
5
5
|
var ProfileRelationshipTypeCollection_exports = /* @__PURE__ */ __exportAll({ ProfileRelationshipTypeCollection: () => ProfileRelationshipTypeCollection });
|
|
@@ -51,4 +51,4 @@ var ProfileRelationshipTypeCollection = class extends SmrtCollection {
|
|
|
51
51
|
//#endregion
|
|
52
52
|
export { ProfileRelationshipTypeCollection_exports as n, ProfileRelationshipTypeCollection as t };
|
|
53
53
|
|
|
54
|
-
//# sourceMappingURL=ProfileRelationshipTypeCollection-
|
|
54
|
+
//# sourceMappingURL=ProfileRelationshipTypeCollection-BmKtnlaP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileRelationshipTypeCollection-
|
|
1
|
+
{"version":3,"file":"ProfileRelationshipTypeCollection-BmKtnlaP.js","names":[],"sources":["../../src/collections/ProfileRelationshipTypeCollection.ts"],"sourcesContent":["/**\n * ProfileRelationshipTypeCollection - Collection manager for ProfileRelationshipType objects\n *\n * Provides querying for relationship type lookup table.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { ProfileRelationshipType } from '../models/ProfileRelationshipType';\n\nexport class ProfileRelationshipTypeCollection extends SmrtCollection<ProfileRelationshipType> {\n static readonly _itemClass = ProfileRelationshipType;\n\n /**\n * Get relationship type by slug\n *\n * @param slug - The slug to search for\n * @returns ProfileRelationshipType instance or null\n */\n async getBySlug(slug: string): Promise<ProfileRelationshipType | null> {\n return await this.get({ slug });\n }\n\n /**\n * Get or create a relationship type by slug\n *\n * @param slug - The slug to search for\n * @param defaults - Default values if creating\n * @returns ProfileRelationshipType instance\n */\n async getOrCreateBySlug(\n slug: string,\n defaults: { name: string; reciprocal?: boolean },\n ): Promise<ProfileRelationshipType> {\n const existing = await this.getBySlug(slug);\n if (existing) return existing;\n\n const relationshipType = await this.create({ slug, ...defaults });\n await relationshipType.save();\n return relationshipType;\n }\n\n /**\n * Get all reciprocal relationship types\n *\n * @returns Array of reciprocal ProfileRelationshipType instances\n */\n async getReciprocal(): Promise<ProfileRelationshipType[]> {\n return await this.list({ where: { reciprocal: true } });\n }\n\n /**\n * Get all directional (non-reciprocal) relationship types\n *\n * @returns Array of directional ProfileRelationshipType instances\n */\n async getDirectional(): Promise<ProfileRelationshipType[]> {\n return await this.list({ where: { reciprocal: false } });\n }\n}\n"],"mappings":";;;;;AASO,IAAM,oCAAN,cAAgD,eAAwC;CAC7F,OAAgB,aAAa;;;;;;;CAQ7B,MAAM,UAAU,MAAuD;EACrE,OAAO,MAAM,KAAK,IAAI,EAAE,KAAK,CAAC;CAChC;;;;;;;;CASA,MAAM,kBACJ,MACA,UACkC;EAClC,MAAM,WAAW,MAAM,KAAK,UAAU,IAAI;EAC1C,IAAI,UAAU,OAAO;EAErB,MAAM,mBAAmB,MAAM,KAAK,OAAO;GAAE;GAAM,GAAG;EAAS,CAAC;EAChE,MAAM,iBAAiB,KAAK;EAC5B,OAAO;CACT;;;;;;CAOA,MAAM,gBAAoD;EACxD,OAAO,MAAM,KAAK,KAAK,EAAE,OAAO,EAAE,YAAY,KAAK,EAAE,CAAC;CACxD;;;;;;CAOA,MAAM,iBAAqD;EACzD,OAAO,MAAM,KAAK,KAAK,EAAE,OAAO,EAAE,YAAY,MAAM,EAAE,CAAC;CACzD;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
2
|
-
import { m as ProfileType } from "./ProfileCollection-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
|
+
import { m as ProfileType } from "./ProfileCollection-CO74zsSf.js";
|
|
3
3
|
import { SmrtCollection } from "@happyvertical/smrt-core";
|
|
4
4
|
import { isSystemContext, withTenantGlobalRead } from "@happyvertical/smrt-tenancy";
|
|
5
5
|
//#region src/collections/ProfileTypeCollection.ts
|
|
@@ -97,4 +97,4 @@ var ProfileTypeCollection = class extends SmrtCollection {
|
|
|
97
97
|
//#endregion
|
|
98
98
|
export { ProfileTypeCollection_exports as n, ProfileTypeCollection as t };
|
|
99
99
|
|
|
100
|
-
//# sourceMappingURL=ProfileTypeCollection-
|
|
100
|
+
//# sourceMappingURL=ProfileTypeCollection-BRxbs9mz.js.map
|
package/dist/chunks/{ProfileTypeCollection-BYSvknkE.js.map → ProfileTypeCollection-BRxbs9mz.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileTypeCollection-
|
|
1
|
+
{"version":3,"file":"ProfileTypeCollection-BRxbs9mz.js","names":[],"sources":["../../src/collections/ProfileTypeCollection.ts"],"sourcesContent":["/**\n * ProfileTypeCollection - Collection manager for ProfileType objects\n *\n * Provides querying for profile type lookup table.\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport {\n isSystemContext,\n withTenantGlobalRead,\n} from '@happyvertical/smrt-tenancy';\nimport { ProfileType } from '../models/ProfileType';\n\nfunction isPostgresUrl(url: string | undefined): boolean {\n return /^postgres(?:ql)?:/iu.test(url ?? '');\n}\n\nexport class ProfileTypeCollection extends SmrtCollection<ProfileType> {\n static readonly _itemClass = ProfileType;\n\n /**\n * Get profile type by slug\n *\n * @param slug - The slug to search for\n * @returns ProfileType instance or null\n */\n async getBySlug(slug: string): Promise<ProfileType | null> {\n return await this.get({ slug });\n }\n\n /**\n * Resolve one profile type available to a tenant.\n *\n * Profile types may be tenant-owned or global lookup rows. A normal point\n * read under an active tenant context intentionally cannot see a global\n * row, so this uses the bounded tenant-plus-globals list capability. The\n * capability preserves the active actor and fails closed when the requested\n * tenant differs from the active tenant context.\n */\n async getAvailableById(\n id: string,\n tenantId: string,\n ): Promise<ProfileType | null> {\n const rows = await withTenantGlobalRead(tenantId, () =>\n this.list({ where: { id }, limit: 1 }),\n );\n return rows[0] ?? null;\n }\n\n /**\n * Get or create a profile type by slug\n *\n * @param slug - The slug to search for\n * @param defaults - Default values if creating\n * @returns ProfileType instance\n */\n async getOrCreateBySlug(\n slug: string,\n defaults: { name: string; description?: string },\n ): Promise<ProfileType> {\n const existing = await this.getBySlug(slug);\n if (existing) return existing;\n\n const profileType = await this.create({ slug, ...defaults });\n await profileType.save();\n return profileType;\n }\n\n /**\n * Atomically create or load a global ProfileType from trusted system code.\n *\n * This intentionally bypasses tenant auto-population and therefore refuses\n * to run outside an explicit `withSystemContext()` boundary.\n */\n async getOrCreateGlobalBySlug(\n slug: string,\n defaults: { name: string; description?: string },\n ): Promise<ProfileType> {\n if (!isSystemContext()) {\n throw new Error(\n 'Global ProfileType creation requires an explicit system context.',\n );\n }\n\n const existing = await this.loadGlobalBySlug(slug);\n if (existing) return existing;\n\n // A plain SMRT create is an upsert and may replace the winning row's id\n // when two first-login transactions race. Keep the canonical id stable by\n // using a cross-adapter insert-if-absent and then hydrating the winner.\n //\n // The table's unique key is `(tenant_id, slug, context, _meta_type)` since\n // smrt#2360, and a global row's NULL tenant never conflicts at the\n // database level (NULLs are distinct in a unique index), so a raw\n // `ON CONFLICT (…) DO NOTHING` can no longer arbitrate this race. Serialize\n // the global create per slug instead: PostgreSQL through a\n // transaction-scoped advisory lock (the arbiter the SDK's null-aware\n // upsert uses too); the embedded engines through the provisioning\n // coordinator's in-process lock plus their single-writer transactions.\n const insertIfAbsent = async (db: typeof this.db): Promise<void> => {\n if (isPostgresUrl(db.url)) {\n await db.query(\n 'SELECT pg_advisory_xact_lock(hashtext(?), hashtext(?))',\n '@happyvertical/smrt-profiles:profile_types:global',\n slug,\n );\n }\n await db.query(\n `INSERT INTO profile_types\n (id, slug, context, _meta_type, tenant_id, name, description)\n SELECT ?, ?, '', '@happyvertical/smrt-profiles:ProfileType', NULL, ?, ?\n WHERE NOT EXISTS (\n SELECT 1 FROM profile_types\n WHERE slug = ?\n AND context = ''\n AND _meta_type = '@happyvertical/smrt-profiles:ProfileType'\n AND tenant_id IS NULL\n )`,\n crypto.randomUUID(),\n slug,\n defaults.name,\n defaults.description ?? null,\n slug,\n );\n };\n\n // A transaction-scoped advisory lock only spans both statements when they\n // run on one transaction. On PostgreSQL, any handle that is NOT already\n // transaction-bound may route each query to a different pooled connection\n // — a root adapter (`beginTransaction` present) and equally a view\n // wrapper (only `transaction()` present) — so open a transaction for the\n // pair on every such handle. A transaction-bound handle (fingerprint: it\n // carries `commit`) already keeps both statements on one client and must\n // not nest. Embedded engines run directly: a nested root transaction\n // would deadlock their single-writer adapters, and the provisioning\n // coordinator's in-process lock already serializes them.\n const isTransactionBound =\n typeof (this.db as { commit?: unknown }).commit === 'function';\n if (\n isPostgresUrl(this.db.url) &&\n !isTransactionBound &&\n typeof this.db.transaction === 'function'\n ) {\n await this.db.transaction((tx) => insertIfAbsent(tx));\n } else {\n await insertIfAbsent(this.db);\n }\n const profileType = await this.loadGlobalBySlug(slug);\n if (!profileType) {\n throw new Error(\n `Global ProfileType '${slug}' could not be created or loaded.`,\n );\n }\n return profileType;\n }\n\n private async loadGlobalBySlug(slug: string): Promise<ProfileType | null> {\n const result = await this.db.query(\n `SELECT CAST(id AS VARCHAR) AS id\n FROM profile_types\n WHERE slug = ?\n AND context = ''\n AND _meta_type = '@happyvertical/smrt-profiles:ProfileType'\n AND tenant_id IS NULL\n LIMIT 1`,\n slug,\n );\n const id = result.rows[0]?.id;\n if (typeof id !== 'string') return null;\n const profileType = await this.get({ id });\n // @happyvertical/sql 0.88 exposes native DuckDB UUID result values as an\n // internal object. The cast above is the portable identity boundary for\n // this lookup; retain it on the hydrated object used by provisioning.\n if (profileType) profileType.id = id;\n return profileType;\n }\n}\n"],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAkC;CACvD,OAAO,sBAAsB,KAAK,OAAO,EAAE;AAC7C;AAEO,IAAM,wBAAN,cAAoC,eAA4B;CACrE,OAAgB,aAAa;;;;;;;CAQ7B,MAAM,UAAU,MAA2C;EACzD,O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AAK,EAAC,EAAG;EAC3B,IAAI,OAAO,OAAO,UAAU,OAAO;EACnC,MAAM,cAAc,MAAM,KAAK,IAAI,EAAE,GAAG,CAAC;EAIzC,IAAI,aAAa,YAAY,KAAK;EAClC,OAAO;CACT;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { y as __exportAll } from "./NostrIdentity-
|
|
2
|
-
import { a as Profile, f as saveOidcRaceArbiter, n as ProfileCollection } from "./ProfileCollection-
|
|
3
|
-
import { t as ProfileTypeCollection } from "./ProfileTypeCollection-
|
|
4
|
-
import { t as OidcIdentity } from "./OidcIdentity-
|
|
1
|
+
import { y as __exportAll } from "./NostrIdentity-CRClZAF0.js";
|
|
2
|
+
import { a as Profile, f as saveOidcRaceArbiter, n as ProfileCollection } from "./ProfileCollection-CO74zsSf.js";
|
|
3
|
+
import { t as ProfileTypeCollection } from "./ProfileTypeCollection-BRxbs9mz.js";
|
|
4
|
+
import { t as OidcIdentity } from "./OidcIdentity-CzZbq7Lv.js";
|
|
5
5
|
import { ObjectRegistry, smrt } from "@happyvertical/smrt-core";
|
|
6
6
|
//#region src/models/ProfileTypes.ts
|
|
7
7
|
var ProfileTypes_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -85,4 +85,4 @@ function requireProvisioningId(value, label) {
|
|
|
85
85
|
//#endregion
|
|
86
86
|
export { Person as a, Organization as i, insertOidcProvisioningIdentity as n, ProfileTypes_exports as o, Bot as r, createOidcProvisioningPerson as t };
|
|
87
87
|
|
|
88
|
-
//# sourceMappingURL=oidcProvisioningPrimitives-
|
|
88
|
+
//# sourceMappingURL=oidcProvisioningPrimitives-HMb3NIi3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidcProvisioningPrimitives-
|
|
1
|
+
{"version":3,"file":"oidcProvisioningPrimitives-HMb3NIi3.js","names":[],"sources":["../../src/models/ProfileTypes.ts","../../src/auth/oidcProvisioningPrimitives.ts"],"sourcesContent":["/**\n * Profile subclasses for STI (Single Table Inheritance)\n *\n * These classes inherit from Profile and automatically use the shared\n * profiles table with _meta_type discriminator.\n */\n\nimport { smrt } from '@happyvertical/smrt-core';\nimport { Profile, type ProfileOptions } from './Profile';\n\n/**\n * Person profile type\n *\n * Represents individual people/users.\n */\n@smrt({\n tableStrategy: 'sti',\n})\nexport class Person extends Profile { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n constructor(options: ProfileOptions = {}) {\n super(options);\n // Person-specific initialization can go here\n }\n}\n\n/**\n * Organization profile type\n *\n * Represents companies, groups, institutions, and other organizational entities.\n */\n@smrt({\n tableStrategy: 'sti',\n})\nexport class Organization extends Profile { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n constructor(options: ProfileOptions = {}) {\n super(options);\n // Organization-specific initialization can go here\n }\n}\n\n/**\n * Bot profile type\n *\n * Represents automated agents, bots, and AI entities.\n */\n@smrt({\n tableStrategy: 'sti',\n})\nexport class Bot extends Profile { static __smrtPackage__ = \"@happyvertical/smrt-profiles\";\n constructor(options: ProfileOptions = {}) {\n super(options);\n // Bot-specific initialization can go here\n }\n}\n","import { ObjectRegistry } from '@happyvertical/smrt-core';\nimport type { getDatabase } from '@happyvertical/sql';\nimport { ProfileCollection } from '../collections/ProfileCollection';\nimport { ProfileTypeCollection } from '../collections/ProfileTypeCollection';\nimport { OidcIdentity } from '../models/OidcIdentity';\nimport type { Profile } from '../models/Profile';\nimport { Person } from '../models/ProfileTypes';\nimport { saveOidcRaceArbiter } from './oidcProvisioningCoordinator';\n\ntype DatabaseInterface = Awaited<ReturnType<typeof getDatabase>>;\n\nexport interface OidcProvisioningPersonInput {\n email?: string;\n name?: string;\n preferredUsername?: string;\n subject: string;\n}\n\nexport interface OidcProvisioningIdentityInput {\n email?: string;\n issuer: string;\n profileId: string;\n provider: string;\n subject: string;\n}\n\n/** Create and reserve a fresh global Person inside the caller's transaction. */\nexport async function createOidcProvisioningPerson(\n db: DatabaseInterface,\n input: OidcProvisioningPersonInput,\n): Promise<Profile> {\n const typeCollection = await ProfileTypeCollection.create({ db });\n const personType = await typeCollection.getOrCreateGlobalBySlug('person', {\n name: 'Person',\n description: 'Individual person profile',\n });\n const typeId = requireProvisioningId(personType.id, 'Person ProfileType');\n let profile: Profile = new (ObjectRegistry.resolveEffectiveConstructor(\n Person,\n ))({\n db,\n // OIDC display names are not identity keys. A per-profile slug keeps\n // SMRT's natural-key upsert from replacing an unrelated Person.\n slug: `oidc-${crypto.randomUUID()}`,\n tenantId: null,\n typeId,\n email: input.email ?? '',\n name: input.name || input.preferredUsername || input.subject,\n });\n await profile.initialize();\n await saveOidcRaceArbiter(() => profile.save());\n\n if (input.email) {\n const profiles = await ProfileCollection.create({ db });\n profile = await profiles.reserveCanonicalIdentityEmail(\n requireProvisioningId(profile.id, 'Created Profile'),\n input.email,\n );\n }\n return profile;\n}\n\n/** Insert the identity after the caller proves Profile ownership. */\nexport async function insertOidcProvisioningIdentity(\n db: DatabaseInterface,\n input: OidcProvisioningIdentityInput,\n): Promise<OidcIdentity> {\n const identity = new (ObjectRegistry.resolveEffectiveConstructor(\n OidcIdentity,\n ))({\n db,\n email: input.email ?? '',\n issuer: input.issuer,\n profileId: input.profileId,\n provider: input.provider,\n subject: input.subject,\n });\n await identity.initialize();\n await saveOidcRaceArbiter(() => identity.save());\n return identity;\n}\n\nfunction requireProvisioningId(value: unknown, label: string): string {\n if (typeof value !== 'string' || !value) {\n throw new Error(`${label} did not produce an id.`);\n }\n return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,SAAN,cAAqB,QAAQ;CAClC,YAAY,UAA0B,CAAC,GAAG;EACxC,MAAM,OAAO;CAEf;AACF;AALsC,cAAzB,QAAgC,mBAAkB,8BAAA;AAAlD,SAAN,gBAAA,CAHN,KAAK,EACJ,eAAe,MACjB,CAAC,CAAA,GACY,MAAA;AAeN,IAAM,eAAN,cAA2B,QAAQ;CACxC,YAAY,UAA0B,CAAC,GAAG;EACxC,MAAM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