@happyvertical/smrt-profiles 0.37.2 → 0.37.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/chunks/ApiKey-3DlNEc91.js +145 -0
  2. package/dist/chunks/ApiKey-3DlNEc91.js.map +1 -0
  3. package/dist/chunks/ApiKeyCollection-PwVs0qDb.js +83 -0
  4. package/dist/chunks/ApiKeyCollection-PwVs0qDb.js.map +1 -0
  5. package/dist/chunks/AuditLogCollection-CnIYU0aK.js +191 -0
  6. package/dist/chunks/AuditLogCollection-CnIYU0aK.js.map +1 -0
  7. package/dist/chunks/NostrIdentityCollection-CG6HGf6c.js +3267 -0
  8. package/dist/chunks/NostrIdentityCollection-CG6HGf6c.js.map +1 -0
  9. package/dist/chunks/OidcIdentityCollection-DiLneB7J.js +158 -0
  10. package/dist/chunks/OidcIdentityCollection-DiLneB7J.js.map +1 -0
  11. package/dist/chunks/ProfileAssetCollection-BY2Wbem3.js +93 -0
  12. package/dist/chunks/ProfileAssetCollection-BY2Wbem3.js.map +1 -0
  13. package/dist/chunks/ProfileCollection-DlhdOnDr.js +641 -0
  14. package/dist/chunks/ProfileCollection-DlhdOnDr.js.map +1 -0
  15. package/dist/chunks/ProfileMetadataCollection-CGcO4Iw_.js +105 -0
  16. package/dist/chunks/ProfileMetadataCollection-CGcO4Iw_.js.map +1 -0
  17. package/dist/chunks/ProfileMetafieldCollection-C8TX9HvN.js +142 -0
  18. package/dist/chunks/ProfileMetafieldCollection-C8TX9HvN.js.map +1 -0
  19. package/dist/chunks/ProfileRelationshipCollection-JnskbZTd.js +159 -0
  20. package/dist/chunks/ProfileRelationshipCollection-JnskbZTd.js.map +1 -0
  21. package/dist/chunks/ProfileRelationshipTermCollection-UopP7sja.js +105 -0
  22. package/dist/chunks/ProfileRelationshipTermCollection-UopP7sja.js.map +1 -0
  23. package/dist/chunks/ProfileRelationshipType-OMBn5cWR.js +98 -0
  24. package/dist/chunks/ProfileRelationshipType-OMBn5cWR.js.map +1 -0
  25. package/dist/chunks/ProfileRelationshipTypeCollection-CQu08kxF.js +54 -0
  26. package/dist/chunks/ProfileRelationshipTypeCollection-CQu08kxF.js.map +1 -0
  27. package/dist/index.js +690 -69
  28. package/dist/index.js.map +1 -1
  29. package/dist/manifest.json +2 -2
  30. package/dist/smrt-knowledge.json +9 -9
  31. package/dist/types.js +0 -2
  32. package/dist/utils.js +18 -36
  33. package/dist/utils.js.map +1 -1
  34. package/package.json +16 -16
  35. package/dist/chunks/ApiKey-B2LKEaP8.js +0 -143
  36. package/dist/chunks/ApiKey-B2LKEaP8.js.map +0 -1
  37. package/dist/chunks/ApiKeyCollection-B6Op817e.js +0 -91
  38. package/dist/chunks/ApiKeyCollection-B6Op817e.js.map +0 -1
  39. package/dist/chunks/AuditLogCollection-BYqCj0uE.js +0 -195
  40. package/dist/chunks/AuditLogCollection-BYqCj0uE.js.map +0 -1
  41. package/dist/chunks/NostrIdentityCollection-DadQBHWy.js +0 -3065
  42. package/dist/chunks/NostrIdentityCollection-DadQBHWy.js.map +0 -1
  43. package/dist/chunks/ProfileAssetCollection-CUM5QfuJ.js +0 -122
  44. package/dist/chunks/ProfileAssetCollection-CUM5QfuJ.js.map +0 -1
  45. package/dist/chunks/ProfileCollection-M2PK8bp-.js +0 -800
  46. package/dist/chunks/ProfileCollection-M2PK8bp-.js.map +0 -1
  47. package/dist/chunks/ProfileMetadataCollection-DEhmljMY.js +0 -120
  48. package/dist/chunks/ProfileMetadataCollection-DEhmljMY.js.map +0 -1
  49. package/dist/chunks/ProfileMetafieldCollection-DMKhSHXX.js +0 -184
  50. package/dist/chunks/ProfileMetafieldCollection-DMKhSHXX.js.map +0 -1
  51. package/dist/chunks/ProfileRelationshipCollection-_TsY7MHL.js +0 -189
  52. package/dist/chunks/ProfileRelationshipCollection-_TsY7MHL.js.map +0 -1
  53. package/dist/chunks/ProfileRelationshipTermCollection-CXem_qT-.js +0 -117
  54. package/dist/chunks/ProfileRelationshipTermCollection-CXem_qT-.js.map +0 -1
  55. package/dist/chunks/ProfileRelationshipType-BXBLldea.js +0 -103
  56. package/dist/chunks/ProfileRelationshipType-BXBLldea.js.map +0 -1
  57. package/dist/chunks/ProfileRelationshipTypeCollection-CF8YvLTV.js +0 -48
  58. package/dist/chunks/ProfileRelationshipTypeCollection-CF8YvLTV.js.map +0 -1
  59. package/dist/chunks/index-B9lXQy7N.js +0 -1029
  60. package/dist/chunks/index-B9lXQy7N.js.map +0 -1
  61. package/dist/types.js.map +0 -1
@@ -0,0 +1,158 @@
1
+ import { x as __exportAll } from "./NostrIdentityCollection-CG6HGf6c.js";
2
+ import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
3
+ //#region src/models/OidcIdentity.ts
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ var OidcIdentity = class extends SmrtObject {
13
+ profileId;
14
+ provider = "";
15
+ issuer = "";
16
+ subject = "";
17
+ email = "";
18
+ lastUsedAt = null;
19
+ constructor(options = {}) {
20
+ super(options);
21
+ if (options.profileId) this.profileId = options.profileId;
22
+ if (options.provider) this.provider = options.provider;
23
+ if (options.issuer) this.issuer = options.issuer;
24
+ if (options.subject) this.subject = options.subject;
25
+ if (options.email) this.email = options.email;
26
+ if (options.lastUsedAt !== void 0) this.lastUsedAt = options.lastUsedAt;
27
+ }
28
+ /**
29
+ * Get the linked Profile
30
+ */
31
+ async getProfile() {
32
+ return await this.getRelated("profileId");
33
+ }
34
+ /**
35
+ * Find identity by issuer and subject
36
+ */
37
+ static async findBySubject(issuer, subject, options = {}) {
38
+ const { OidcIdentityCollection } = await Promise.resolve().then(() => OidcIdentityCollection_exports);
39
+ return await (await OidcIdentityCollection.create(options)).findOne({ where: {
40
+ issuer,
41
+ subject
42
+ } });
43
+ }
44
+ /**
45
+ * Find or create identity for a profile
46
+ */
47
+ static async findOrCreate(profile, oidcData, options = {}) {
48
+ const existing = await OidcIdentity.findBySubject(oidcData.issuer, oidcData.subject, options);
49
+ if (existing) {
50
+ existing.lastUsedAt = /* @__PURE__ */ new Date();
51
+ if (oidcData.email) existing.email = oidcData.email;
52
+ await existing.save();
53
+ return existing;
54
+ }
55
+ const identity = new OidcIdentity({
56
+ ...options,
57
+ profileId: profile.id,
58
+ provider: oidcData.provider,
59
+ issuer: oidcData.issuer,
60
+ subject: oidcData.subject,
61
+ email: oidcData.email || ""
62
+ });
63
+ await identity.initialize();
64
+ await identity.save();
65
+ return identity;
66
+ }
67
+ /**
68
+ * Record usage of this identity
69
+ */
70
+ async recordUsage() {
71
+ this.lastUsedAt = /* @__PURE__ */ new Date();
72
+ await this.save();
73
+ }
74
+ };
75
+ __decorateClass([foreignKey("Profile", { required: true })], OidcIdentity.prototype, "profileId", 2);
76
+ __decorateClass([field({ type: "text" })], OidcIdentity.prototype, "provider", 2);
77
+ __decorateClass([field({ type: "text" })], OidcIdentity.prototype, "issuer", 2);
78
+ __decorateClass([field({ type: "text" })], OidcIdentity.prototype, "subject", 2);
79
+ __decorateClass([field({ type: "text" })], OidcIdentity.prototype, "email", 2);
80
+ __decorateClass([field({
81
+ type: "datetime",
82
+ nullable: true
83
+ })], OidcIdentity.prototype, "lastUsedAt", 2);
84
+ OidcIdentity = __decorateClass([smrt({
85
+ tableName: "oidc_identities",
86
+ api: { exclude: ["delete"] },
87
+ mcp: { include: ["list", "get"] },
88
+ cli: { include: ["list", "get"] }
89
+ })], OidcIdentity);
90
+ //#endregion
91
+ //#region src/collections/OidcIdentityCollection.ts
92
+ var OidcIdentityCollection_exports = /* @__PURE__ */ __exportAll({ OidcIdentityCollection: () => OidcIdentityCollection });
93
+ var OidcIdentityCollection = class extends SmrtCollection {
94
+ static _itemClass = OidcIdentity;
95
+ /**
96
+ * Find identities for a profile
97
+ */
98
+ async findByProfile(profileId) {
99
+ return await this.list({ where: { profileId } });
100
+ }
101
+ /**
102
+ * Find identity by issuer and subject
103
+ */
104
+ async findBySubject(issuer, subject) {
105
+ return await this.findOne({ where: {
106
+ issuer,
107
+ subject
108
+ } });
109
+ }
110
+ /**
111
+ * Find identities by provider
112
+ */
113
+ async findByProvider(provider) {
114
+ return await this.list({ where: { provider } });
115
+ }
116
+ /**
117
+ * Link a new OIDC identity to a profile
118
+ */
119
+ async linkToProfile(profile, oidcData) {
120
+ const existing = await this.findBySubject(oidcData.issuer, oidcData.subject);
121
+ if (existing) {
122
+ existing.lastUsedAt = /* @__PURE__ */ new Date();
123
+ if (oidcData.email) existing.email = oidcData.email;
124
+ await existing.save();
125
+ return existing;
126
+ }
127
+ const identity = new OidcIdentity({
128
+ ...this.options,
129
+ profileId: profile.id,
130
+ provider: oidcData.provider,
131
+ issuer: oidcData.issuer,
132
+ subject: oidcData.subject,
133
+ email: oidcData.email || ""
134
+ });
135
+ await identity.initialize();
136
+ await identity.save();
137
+ return identity;
138
+ }
139
+ /**
140
+ * Unlink an OIDC identity from a profile
141
+ */
142
+ async unlinkFromProfile(profileId, issuer, subject) {
143
+ const identity = await this.findOne({ where: {
144
+ profileId,
145
+ issuer,
146
+ subject
147
+ } });
148
+ if (identity) {
149
+ await identity.delete();
150
+ return true;
151
+ }
152
+ return false;
153
+ }
154
+ };
155
+ //#endregion
156
+ export { OidcIdentityCollection_exports as n, OidcIdentity as r, OidcIdentityCollection as t };
157
+
158
+ //# sourceMappingURL=OidcIdentityCollection-DiLneB7J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OidcIdentityCollection-DiLneB7J.js","names":[],"sources":["../../src/models/OidcIdentity.ts","../../src/collections/OidcIdentityCollection.ts"],"sourcesContent":["/**\n * OidcIdentity - Links OIDC provider identities to Profile\n *\n * Stores the mapping between external OIDC providers (Keycloak, Google, GitHub)\n * and internal Profile records. Multiple identities can link to a single profile.\n */\n\nimport {\n field,\n foreignKey,\n SmrtObject,\n type SmrtObjectOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport type { Profile } from './Profile';\n\nexport interface OidcIdentityOptions extends SmrtObjectOptions {\n profileId?: string;\n provider?: string;\n issuer?: string;\n subject?: string;\n email?: string;\n lastUsedAt?: Date | null;\n}\n\n@smrt({\n tableName: 'oidc_identities',\n api: { exclude: ['delete'] },\n mcp: { include: ['list', 'get'] },\n cli: { include: ['list', 'get'] },\n})\nexport class OidcIdentity extends SmrtObject {\n /**\n * Link to the Profile (Person, Organization, Bot)\n */\n @foreignKey('Profile', { required: true })\n profileId?: string;\n\n /**\n * Provider name (e.g., 'keycloak', 'google', 'github')\n */\n @field({ type: 'text' })\n provider: string = '';\n\n /**\n * OIDC issuer URL (e.g., https://keycloak.example.com/realms/bmp)\n */\n @field({ type: 'text' })\n issuer: string = '';\n\n /**\n * OIDC subject claim - unique identifier from the provider\n */\n @field({ type: 'text' })\n subject: string = '';\n\n /**\n * Cached email from the IdP (for display/lookup)\n */\n @field({ type: 'text' })\n email: string = '';\n\n /**\n * Last time this identity was used for authentication\n */\n @field({ type: 'datetime', nullable: true })\n lastUsedAt: Date | null = null;\n\n constructor(options: OidcIdentityOptions = {}) {\n super(options);\n if (options.profileId) this.profileId = options.profileId;\n if (options.provider) this.provider = options.provider;\n if (options.issuer) this.issuer = options.issuer;\n if (options.subject) this.subject = options.subject;\n if (options.email) this.email = options.email;\n if (options.lastUsedAt !== undefined) this.lastUsedAt = options.lastUsedAt;\n }\n\n /**\n * Get the linked Profile\n */\n async getProfile(): Promise<Profile | null> {\n return (await this.getRelated('profileId')) as Profile | null;\n }\n\n /**\n * Find identity by issuer and subject\n */\n static async findBySubject(\n issuer: string,\n subject: string,\n options: SmrtObjectOptions = {},\n ): Promise<OidcIdentity | null> {\n const { OidcIdentityCollection } = await import(\n '../collections/OidcIdentityCollection'\n );\n const collection = await OidcIdentityCollection.create(options);\n return await collection.findOne({\n where: { issuer, subject },\n });\n }\n\n /**\n * Find or create identity for a profile\n */\n static async findOrCreate(\n profile: Profile,\n oidcData: {\n provider: string;\n issuer: string;\n subject: string;\n email?: string;\n },\n options: SmrtObjectOptions = {},\n ): Promise<OidcIdentity> {\n const existing = await OidcIdentity.findBySubject(\n oidcData.issuer,\n oidcData.subject,\n options,\n );\n\n if (existing) {\n // Update last used\n existing.lastUsedAt = new Date();\n if (oidcData.email) existing.email = oidcData.email;\n await existing.save();\n return existing;\n }\n\n // Create new\n const identity = new OidcIdentity({\n ...options,\n profileId: profile.id as string,\n provider: oidcData.provider,\n issuer: oidcData.issuer,\n subject: oidcData.subject,\n email: oidcData.email || '',\n });\n await identity.initialize();\n await identity.save();\n return identity;\n }\n\n /**\n * Record usage of this identity\n */\n async recordUsage(): Promise<void> {\n this.lastUsedAt = new Date();\n await this.save();\n }\n}\n","/**\n * OidcIdentityCollection - Collection for managing OIDC identity records\n */\n\nimport { SmrtCollection } from '@happyvertical/smrt-core';\nimport { OidcIdentity } from '../models/OidcIdentity';\nimport type { Profile } from '../models/Profile';\n\nexport class OidcIdentityCollection extends SmrtCollection<OidcIdentity> {\n static readonly _itemClass = OidcIdentity;\n\n /**\n * Find identities for a profile\n */\n async findByProfile(profileId: string): Promise<OidcIdentity[]> {\n return await this.list({\n where: { profileId },\n });\n }\n\n /**\n * Find identity by issuer and subject\n */\n async findBySubject(\n issuer: string,\n subject: string,\n ): Promise<OidcIdentity | null> {\n return await this.findOne({\n where: { issuer, subject },\n });\n }\n\n /**\n * Find identities by provider\n */\n async findByProvider(provider: string): Promise<OidcIdentity[]> {\n return await this.list({\n where: { provider },\n });\n }\n\n /**\n * Link a new OIDC identity to a profile\n */\n async linkToProfile(\n profile: Profile,\n oidcData: {\n provider: string;\n issuer: string;\n subject: string;\n email?: string;\n },\n ): Promise<OidcIdentity> {\n // Check if already exists\n const existing = await this.findBySubject(\n oidcData.issuer,\n oidcData.subject,\n );\n if (existing) {\n // Update and return existing\n existing.lastUsedAt = new Date();\n if (oidcData.email) existing.email = oidcData.email;\n await existing.save();\n return existing;\n }\n\n // Create new\n const identity = new OidcIdentity({\n ...this.options,\n profileId: profile.id as string,\n provider: oidcData.provider,\n issuer: oidcData.issuer,\n subject: oidcData.subject,\n email: oidcData.email || '',\n });\n await identity.initialize();\n await identity.save();\n return identity;\n }\n\n /**\n * Unlink an OIDC identity from a profile\n */\n async unlinkFromProfile(\n profileId: string,\n issuer: string,\n subject: string,\n ): Promise<boolean> {\n const identity = await this.findOne({\n where: { profileId, issuer, subject },\n });\n\n if (identity) {\n await identity.delete();\n return true;\n }\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BO,IAAM,eAAN,cAA2B,WAAW;CAK3C;CAMA,WAAmB;CAMnB,SAAiB;CAMjB,UAAkB;CAMlB,QAAgB;CAMhB,aAA0B;CAE1B,YAAY,UAA+B,CAAC,GAAG;EAC7C,MAAM,OAAO;EACb,IAAI,QAAQ,WAAW,KAAK,YAAY,QAAQ;EAChD,IAAI,QAAQ,UAAU,KAAK,WAAW,QAAQ;EAC9C,IAAI,QAAQ,QAAQ,KAAK,SAAS,QAAQ;EAC1C,IAAI,QAAQ,SAAS,KAAK,UAAU,QAAQ;EAC5C,IAAI,QAAQ,OAAO,KAAK,QAAQ,QAAQ;EACxC,IAAI,QAAQ,eAAe,KAAA,GAAW,KAAK,aAAa,QAAQ;CAClE;;;;CAKA,MAAM,aAAsC;EAC1C,OAAQ,MAAM,KAAK,WAAW,WAAW;CAC3C;;;;CAKA,aAAa,cACX,QACA,SACA,UAA6B,CAAC,GACA;EAC9B,MAAM,EAAE,2BAA2B,MAAA,QAAA,QAAA,CAAA,CAAA,WAAA,8BAAA;EAInC,OAAO,OAAM,MADY,uBAAuB,OAAO,OAAO,EAAA,CACtC,QAAQ,EAC9B,OAAO;GAAE;G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ction, SmrtObject, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
3
+ import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
4
+ import { addOwnedAssetFromCollection, getOwnedAssetsFromCollection, removeOwnedAssetFromCollection } from "@happyvertical/smrt-assets";
5
+ //#region src/models/ProfileAsset.ts
6
+ var __defProp$1 = Object.defineProperty;
7
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
8
+ var __decorateClass$1 = (decorators, target, key, kind) => {
9
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
10
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result) __defProp$1(target, key, result);
12
+ return result;
13
+ };
14
+ var ProfileAsset = class extends SmrtObject {
15
+ tenantId = null;
16
+ profileId = "";
17
+ assetId = "";
18
+ relationship = "attachment";
19
+ sortOrder = 0;
20
+ constructor(options = {}) {
21
+ super(options);
22
+ if (options.profileId) this.profileId = options.profileId;
23
+ if (options.assetId) this.assetId = options.assetId;
24
+ if (options.relationship) this.relationship = options.relationship;
25
+ if (options.sortOrder !== void 0) this.sortOrder = options.sortOrder;
26
+ if (options.tenantId !== void 0) this.tenantId = options.tenantId;
27
+ }
28
+ };
29
+ __decorateClass$1([tenantId({ nullable: true })], ProfileAsset.prototype, "tenantId", 2);
30
+ __decorateClass$1([foreignKey("Profile", { required: true })], ProfileAsset.prototype, "profileId", 2);
31
+ __decorateClass$1([crossPackageRef("@happyvertical/smrt-assets:Asset", { required: true })], ProfileAsset.prototype, "assetId", 2);
32
+ __decorateClass$1([field({ required: true })], ProfileAsset.prototype, "relationship", 2);
33
+ __decorateClass$1([field()], ProfileAsset.prototype, "sortOrder", 2);
34
+ ProfileAsset = __decorateClass$1([TenantScoped({ mode: "optional" }), smrt({
35
+ tableName: "profile_assets",
36
+ conflictColumns: [
37
+ "profile_id",
38
+ "asset_id",
39
+ "relationship"
40
+ ],
41
+ api: false,
42
+ mcp: false,
43
+ cli: false
44
+ })], ProfileAsset);
45
+ //#endregion
46
+ //#region src/collections/ProfileAssetCollection.ts
47
+ var ProfileAssetCollection_exports = /* @__PURE__ */ __exportAll({ ProfileAssetCollection: () => ProfileAssetCollection });
48
+ var __defProp = Object.defineProperty;
49
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
50
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value
55
+ }) : obj[key] = value;
56
+ var __decorateClass = (decorators, target, key, kind) => {
57
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
58
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
59
+ if (kind && result) __defProp(target, key, result);
60
+ return result;
61
+ };
62
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
63
+ var ProfileAssetCollection = class extends SmrtJunction {
64
+ leftField = "profileId";
65
+ rightField = "assetId";
66
+ profileCollectionPromise = null;
67
+ async getProfileCollection() {
68
+ if (!this.profileCollectionPromise) {
69
+ const { ProfileCollection } = await import("./ProfileCollection-DlhdOnDr.js").then((n) => n.n);
70
+ this.profileCollectionPromise = ProfileCollection.create({ db: this.db });
71
+ }
72
+ return this.profileCollectionPromise;
73
+ }
74
+ async getAssets(profileId, relationship) {
75
+ return getOwnedAssetsFromCollection(await this.getProfileCollection(), profileId, relationship);
76
+ }
77
+ async addAsset(profileId, asset, relationship = "attachment", sortOrder = 0) {
78
+ await addOwnedAssetFromCollection(await this.getProfileCollection(), "Profile", profileId, asset, relationship, sortOrder);
79
+ }
80
+ async removeAsset(profileId, assetId, relationship) {
81
+ await removeOwnedAssetFromCollection(await this.getProfileCollection(), "Profile", profileId, assetId, relationship);
82
+ }
83
+ };
84
+ __publicField(ProfileAssetCollection, "_itemClass", ProfileAsset);
85
+ ProfileAssetCollection = __decorateClass([smrt({
86
+ api: false,
87
+ mcp: false,
88
+ cli: false
89
+ })], ProfileAssetCollection);
90
+ //#endregion
91
+ export { ProfileAssetCollection_exports as n, ProfileAsset as r, ProfileAssetCollection as t };
92
+
93
+ //# sourceMappingURL=ProfileAssetCollection-BY2Wbem3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProfileAssetCollection-BY2Wbem3.js","names":[],"sources":["../../src/models/ProfileAsset.ts","../../src/collections/ProfileAssetCollection.ts"],"sourcesContent":["import type { SmrtObjectOptions } from '@happyvertical/smrt-core';\nimport {\n crossPackageRef,\n field,\n foreignKey,\n SmrtObject,\n smrt,\n} from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\n\nexport interface ProfileAssetOptions extends SmrtObjectOptions {\n profileId?: string;\n assetId?: string;\n relationship?: string;\n sortOrder?: number;\n tenantId?: string | null;\n}\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n tableName: 'profile_assets',\n conflictColumns: ['profile_id', 'asset_id', 'relationship'],\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ProfileAsset extends SmrtObject {\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n @foreignKey('Profile', { required: true })\n profileId = '';\n\n @crossPackageRef('@happyvertical/smrt-assets:Asset', { required: true })\n assetId = '';\n\n @field({ required: true })\n relationship = 'attachment';\n\n @field()\n sortOrder = 0;\n\n constructor(options: ProfileAssetOptions = {}) {\n super(options);\n if (options.profileId) this.profileId = options.profileId;\n if (options.assetId) this.assetId = options.assetId;\n if (options.relationship) this.relationship = options.relationship;\n if (options.sortOrder !== undefined) this.sortOrder = options.sortOrder;\n if (options.tenantId !== undefined) this.tenantId = options.tenantId;\n }\n}\n","import type { Asset } from '@happyvertical/smrt-assets';\nimport {\n addOwnedAssetFromCollection,\n getOwnedAssetsFromCollection,\n removeOwnedAssetFromCollection,\n} from '@happyvertical/smrt-assets';\nimport type { SmrtCollectionOptions } from '@happyvertical/smrt-core';\nimport { SmrtJunction, smrt } from '@happyvertical/smrt-core';\nimport { ProfileAsset } from '../models/ProfileAsset';\nimport type { ProfileCollection } from './ProfileCollection';\n\nexport interface ProfileAssetCollectionOptions extends SmrtCollectionOptions {}\n\n@smrt({\n api: false,\n mcp: false,\n cli: false,\n})\nexport class ProfileAssetCollection extends SmrtJunction<ProfileAsset> {\n static readonly _itemClass = ProfileAsset;\n protected leftField = 'profileId';\n protected rightField = 'assetId';\n\n private profileCollectionPromise: Promise<ProfileCollection> | null = null;\n\n private async getProfileCollection(): Promise<ProfileCollection> {\n if (!this.profileCollectionPromise) {\n const { ProfileCollection } = await import('./ProfileCollection');\n this.profileCollectionPromise = ProfileCollection.create({ db: this.db });\n }\n\n return this.profileCollectionPromise;\n }\n\n async getAssets(profileId: string, relationship?: string): Promise<Asset[]> {\n return getOwnedAssetsFromCollection(\n await this.getProfileCollection(),\n profileId,\n relationship,\n );\n }\n\n async addAsset(\n profileId: string,\n asset: Asset,\n relationship = 'attachment',\n sortOrder = 0,\n ): Promise<void> {\n await addOwnedAssetFromCollection(\n await this.getProfileCollection(),\n 'Profile',\n profileId,\n asset,\n relationship,\n sortOrder,\n );\n }\n\n async removeAsset(\n profileId: string,\n assetId: string,\n relationship?: string,\n ): Promise<void> {\n await removeOwnedAssetFromCollection(\n await this.getProfileCollection(),\n 'Profile',\n profileId,\n assetId,\n relationship,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0BO,IAAM,eAAN,cAA2B,WAAW;CAE3C,WAA0B;CAG1B,YAAY;CAGZ,UAAU;CAGV,eAAe;CAGf,YAAY;CAEZ,YAAY,UAA+B,CAAC,GAAG;EAC7C,MAAM,OAAO;EACb,IAAI,QAAQ,WAAW,KAAK,YAAY,QAAQ;EAChD,IAAI,QAAQ,SAAS,KAAK,UAAU,QAAQ;EAC5C,IAAI,QAAQ,cAAc,KAAK,eAAe,QAAQ;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