@happyvertical/smrt-cli 0.55.6 → 0.55.8

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 (25) hide show
  1. package/README.md +13 -0
  2. package/dist/{AuditLogCollection-WDHL-_AF-DOee2NBy.js → AuditLogCollection-WDHL-_AF-itCZzK5F.js} +1 -1
  3. package/dist/{OidcIdentity-BUblgQLs-Cp6EohoH.js → OidcIdentity-BUblgQLs-xNOS3SLe.js} +2 -2
  4. package/dist/{OidcIdentityCollection-ClOyaHeF-h8pqeEc_.js → OidcIdentityCollection-ClOyaHeF-DmSa-Jj5.js} +1 -1
  5. package/dist/{ProfileAssetCollection-CRMcjLJ--oaqYhSv8.js → ProfileAssetCollection-CRMcjLJ--DTgGpP0y.js} +3 -3
  6. package/dist/{ProfileCollection-C4INKh7Y-kmilpari.js → ProfileCollection-C4INKh7Y-5u2MkyxW.js} +17 -17
  7. package/dist/{ProfileLinkCollection-DFfZRsgv-CKXvOpLD.js → ProfileLinkCollection-DFfZRsgv-tnjoutpX.js} +2 -2
  8. package/dist/{ProfileMetadataCollection-BIYKy4Y3-VkWyyz0S.js → ProfileMetadataCollection-BIYKy4Y3-BqrGy3XJ.js} +1 -1
  9. package/dist/{ProfileMetafieldCollection-Buz7gzag-C2PNWrSB.js → ProfileMetafieldCollection-Buz7gzag-CqdYjtLA.js} +1 -1
  10. package/dist/{ProfileRelationshipCollection-C4g_QLI4-BjEj-f3r.js → ProfileRelationshipCollection-C4g_QLI4-CQ3lrObu.js} +1 -1
  11. package/dist/{ProfileTypeCollection-B7kwi1mU-DykwBiUN.js → ProfileTypeCollection-B7kwi1mU-BokukciD.js} +2 -2
  12. package/dist/commands/export.d.ts +55 -0
  13. package/dist/commands/export.d.ts.map +1 -1
  14. package/dist/{commands-DtHto12X.js → commands-C9auioVL.js} +95 -9
  15. package/dist/dist-AUzJ0Xmj.js +4113 -0
  16. package/dist/dist-B3JYpeec.js +21 -0
  17. package/dist/{dist-D23BpLWY.js → dist-CAEt-5TC.js} +22 -50
  18. package/dist/{dist-DdAui9xB.js → dist-EqBk8t9l.js} +2 -2
  19. package/dist/{dist-DZLiubwM.js → dist-IwSYOsmg.js} +15 -5
  20. package/dist/index.js +9 -9
  21. package/dist/{oidcProvisioningPrimitives-DNP9EZlU-DbRoD1Xf.js → oidcProvisioningPrimitives-DNP9EZlU-jiB_hMzf.js} +3 -3
  22. package/dist/{resolveIdentity-CkyqvctR-Be_aG4SC.js → resolveIdentity-CkyqvctR-BZy7A4kX.js} +14 -14
  23. package/package.json +15 -15
  24. package/dist/dist-BS8Pl9RN.js +0 -4113
  25. package/dist/dist-CxAolFbD.js +0 -21
package/README.md CHANGED
@@ -199,6 +199,19 @@ knowledge index; documentation snapshots use lightweight package discovery.
199
199
  | `smrt export` | Export data in various formats |
200
200
  | `smrt init` | Initialize s-m-r-t in an existing SvelteKit project |
201
201
 
202
+ `smrt export` reads the `export` section of `smrt.config.js`. A listed type that
203
+ is not registered fails the command (non-zero exit, naming the type) instead of
204
+ skipping the file. A file listing several types that share one table (STI)
205
+ exports the union of their columns (absent columns are NULL; `_meta_type`
206
+ distinguishes rows); set `fields: 'common'` on the file to keep only the
207
+ columns every type has. A column marked `exported: false` for any listed type is
208
+ never emitted for that type's rows, even when another listed type exports it:
209
+ the value is NULLed per row from the `_meta_type` discriminator (the export
210
+ selects it even when `_meta_type` is not an output column). If a row's type
211
+ cannot be matched to a listed type, or an excluding type has no discriminator,
212
+ the export fails naming the field and types rather than publishing the column.
213
+ `include` whitelists cannot re-enable an `exported: false` field.
214
+
202
215
  `smrt init` updates an existing SvelteKit application's `package.json` with the
203
216
  direct dependencies its generated source and default MCP server require:
204
217
  `@happyvertical/smrt-core`, `@happyvertical/smrt-config`, and
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
4
  import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/AuditLogCollection-WDHL-_AF.js
@@ -42,7 +42,7 @@ var OidcIdentity = class extends SmrtObject {
42
42
  * Find identity by issuer and subject
43
43
  */
44
44
  static async findBySubject(issuer, subject, options = {}) {
45
- const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-h8pqeEc_.js").then((n) => n.r).then((n) => n.r);
45
+ const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-DmSa-Jj5.js").then((n) => n.r).then((n) => n.r);
46
46
  return await (await OidcIdentityCollection.create(options)).findBySubject(issuer, subject);
47
47
  }
48
48
  /** Build the collision-free natural key for one OIDC issuer subject. */
@@ -65,7 +65,7 @@ var OidcIdentity = class extends SmrtObject {
65
65
  static async findOrCreate(profile, oidcData, options = {}) {
66
66
  const profileId = profile.id;
67
67
  if (typeof profileId !== "string" || !profileId) throw new Error("OidcIdentity.findOrCreate() requires a saved Profile.");
68
- const { reuseExistingOidcIdentityForProfile } = await import("./resolveIdentity-CkyqvctR-Be_aG4SC.js").then((n) => n.i).then((n) => n.i);
68
+ const { reuseExistingOidcIdentityForProfile } = await import("./resolveIdentity-CkyqvctR-BZy7A4kX.js").then((n) => n.i).then((n) => n.i);
69
69
  const profileOptions = profile.options ?? {};
70
70
  return (await reuseExistingOidcIdentityForProfile(profileId, {
71
71
  email: oidcData.email,
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
2
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
3
- import { t as OidcIdentity } from "./OidcIdentity-BUblgQLs-Cp6EohoH.js";
3
+ import { t as OidcIdentity } from "./OidcIdentity-BUblgQLs-xNOS3SLe.js";
4
4
  import { SmrtCollection } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/OidcIdentityCollection-ClOyaHeF.js
6
6
  var OidcIdentityCollection_ClOyaHeF_exports = /* @__PURE__ */ __exportAll({
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
- import { a as getOwnedAssetsFromCollection, o as removeOwnedAssetFromCollection, t as addOwnedAssetFromCollection } from "./dist-DZLiubwM.js";
4
+ import { a as getOwnedAssetsFromCollection, o as removeOwnedAssetFromCollection, t as addOwnedAssetFromCollection } from "./dist-IwSYOsmg.js";
5
5
  import { SmrtJunction, SmrtObject, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
6
6
  //#region ../profiles/dist/chunks/ProfileAssetCollection-CRMcjLJ-.js
7
7
  var ProfileAssetCollection_CRMcjLJ__exports = /* @__PURE__ */ __exportAll({
@@ -84,7 +84,7 @@ var ProfileAssetCollection = class extends SmrtJunction {
84
84
  profileCollectionPromise = null;
85
85
  async getProfileCollection() {
86
86
  if (!this.profileCollectionPromise) {
87
- const { ProfileCollection } = await import("./ProfileCollection-C4INKh7Y-kmilpari.js").then((n) => n.o).then((n) => n.r);
87
+ const { ProfileCollection } = await import("./ProfileCollection-C4INKh7Y-5u2MkyxW.js").then((n) => n.o).then((n) => n.r);
88
88
  this.profileCollectionPromise = ProfileCollection.create({ db: this.db });
89
89
  }
90
90
  return this.profileCollectionPromise;
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { a as queryGlobal, c as getTenantId, i as tenantId, n as resolvePrompt, o as queryWithGlobals, r as TenantScoped, t as definePrompt, u as withSystemContext } from "./dist-DdAui9xB.js";
2
+ import { a as queryGlobal, c as getTenantId, i as tenantId, n as resolvePrompt, o as queryWithGlobals, r as TenantScoped, t as definePrompt, u as withSystemContext } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
- import { a as getOwnedAssetsFromCollection, i as assertValidOwnedAssetSortOrder, n as assertAssetLinkable, o as removeOwnedAssetFromCollection, r as assertValidOwnedAssetRelationship, s as resolveOwnedAssetsById, t as addOwnedAssetFromCollection } from "./dist-DZLiubwM.js";
4
+ import { a as getOwnedAssetsFromCollection, i as assertValidOwnedAssetSortOrder, n as assertAssetLinkable, o as removeOwnedAssetFromCollection, r as assertValidOwnedAssetRelationship, s as resolveOwnedAssetsById, t as addOwnedAssetFromCollection } from "./dist-IwSYOsmg.js";
5
5
  import { RuntimeError, SmrtCollection, SmrtObject, ValidationError, field, foreignKey, isAbortedTransactionError, oneToMany, smrt } from "@happyvertical/smrt-core";
6
6
  import { BackfillTableUnavailableError, BackfillTracker } from "@happyvertical/smrt-core/migrations";
7
7
  //#region ../profiles/dist/chunks/ProfileCollection-C4INKh7Y.js
@@ -435,7 +435,7 @@ var Profile = class extends SmrtObject {
435
435
  async getTypeSlug() {
436
436
  const tenantId2 = this.tenantId || getTenantId();
437
437
  if (this.typeId && tenantId2) {
438
- const { ProfileTypeCollection } = await import("./ProfileTypeCollection-B7kwi1mU-DykwBiUN.js").then((n) => n.n).then((n) => n.n);
438
+ const { ProfileTypeCollection } = await import("./ProfileTypeCollection-B7kwi1mU-BokukciD.js").then((n) => n.n).then((n) => n.n);
439
439
  return (await (await ProfileTypeCollection.create(this.options)).getAvailableById(this.typeId, tenantId2))?.slug ?? "";
440
440
  }
441
441
  return (await this.loadRelated("typeId"))?.slug || "";
@@ -458,8 +458,8 @@ var Profile = class extends SmrtObject {
458
458
  * @param value - The value to set
459
459
  */
460
460
  async addMetadata(metafieldSlug, value) {
461
- const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-Buz7gzag-C2PNWrSB.js").then((n) => n.r).then((n) => n.n);
462
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-VkWyyz0S.js").then((n) => n.r).then((n) => n.n);
461
+ const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-Buz7gzag-CqdYjtLA.js").then((n) => n.r).then((n) => n.n);
462
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-BqrGy3XJ.js").then((n) => n.r).then((n) => n.n);
463
463
  const metafield = await this.resolveMetafield(await ProfileMetafieldCollection.create(this.options), metafieldSlug);
464
464
  if (!metafield) throw new Error(`Metafield '${metafieldSlug}' not found`);
465
465
  await metafield.validateValue(value);
@@ -492,7 +492,7 @@ var Profile = class extends SmrtObject {
492
492
  * @returns Object with metafield slugs as keys
493
493
  */
494
494
  async getMetadata() {
495
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-VkWyyz0S.js").then((n) => n.r).then((n) => n.n);
495
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-BqrGy3XJ.js").then((n) => n.r).then((n) => n.n);
496
496
  return await (await ProfileMetadataCollection.create(this.options)).getMetadataObject(this.id);
497
497
  }
498
498
  /**
@@ -509,8 +509,8 @@ var Profile = class extends SmrtObject {
509
509
  * @param metafieldSlug - The slug of the metafield to remove
510
510
  */
511
511
  async removeMetadata(metafieldSlug) {
512
- const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-Buz7gzag-C2PNWrSB.js").then((n) => n.r).then((n) => n.n);
513
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-VkWyyz0S.js").then((n) => n.r).then((n) => n.n);
512
+ const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-Buz7gzag-CqdYjtLA.js").then((n) => n.r).then((n) => n.n);
513
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-BIYKy4Y3-BqrGy3XJ.js").then((n) => n.r).then((n) => n.n);
514
514
  const metafield = await this.resolveMetafield(await ProfileMetafieldCollection.create(this.options), metafieldSlug);
515
515
  if (!metafield) throw new Error(`Metafield '${metafieldSlug}' not found`);
516
516
  const existing = await (await ProfileMetadataCollection.create(this.options)).list({
@@ -535,7 +535,7 @@ var Profile = class extends SmrtObject {
535
535
  return candidates.find((candidate) => ownerTenantId && candidate.tenantId === ownerTenantId) ?? candidates.find((candidate) => !candidate.tenantId) ?? null;
536
536
  }
537
537
  async getProfileLinkCollection() {
538
- const { ProfileLinkCollection } = await import("./ProfileLinkCollection-DFfZRsgv-CKXvOpLD.js").then((n) => n.i).then((n) => n.r);
538
+ const { ProfileLinkCollection } = await import("./ProfileLinkCollection-DFfZRsgv-tnjoutpX.js").then((n) => n.i).then((n) => n.r);
539
539
  return ProfileLinkCollection.create({ db: this.db });
540
540
  }
541
541
  /** This profile's web links in display order. */
@@ -552,7 +552,7 @@ var Profile = class extends SmrtObject {
552
552
  return (await this.getProfileLinkCollection()).replaceForProfile(this.id, links);
553
553
  }
554
554
  async getProfileAssetCollection() {
555
- const { ProfileAssetCollection } = await import("./ProfileAssetCollection-CRMcjLJ--oaqYhSv8.js").then((n) => n.r).then((n) => n.n);
555
+ const { ProfileAssetCollection } = await import("./ProfileAssetCollection-CRMcjLJ--DTgGpP0y.js").then((n) => n.r).then((n) => n.n);
556
556
  return ProfileAssetCollection.create({ db: this.db });
557
557
  }
558
558
  async getAssets(relationship) {
@@ -584,7 +584,7 @@ var Profile = class extends SmrtObject {
584
584
  */
585
585
  async addRelationship(toProfile, relationshipSlug, contextProfile) {
586
586
  const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-_n22WqTb-DiZUWvev.js").then((n) => n.n).then((n) => n.n);
587
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-BjEj-f3r.js").then((n) => n.r).then((n) => n.n);
587
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-CQ3lrObu.js").then((n) => n.r).then((n) => n.n);
588
588
  const { ProfileRelationshipType } = await import("./ProfileRelationshipType-U7IwF6Wf-DNavf24e.js").then((n) => n.n).then((n) => n.n);
589
589
  const relationshipType = await (await ProfileRelationshipTypeCollection.create(this.options)).getBySlug(relationshipSlug);
590
590
  if (!relationshipType) throw new Error(`Relationship type '${relationshipSlug}' not found`);
@@ -609,7 +609,7 @@ var Profile = class extends SmrtObject {
609
609
  * @returns Array of ProfileRelationship instances
610
610
  */
611
611
  async getRelationships(options) {
612
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-BjEj-f3r.js").then((n) => n.r).then((n) => n.n);
612
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-CQ3lrObu.js").then((n) => n.r).then((n) => n.n);
613
613
  const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-_n22WqTb-DiZUWvev.js").then((n) => n.n).then((n) => n.n);
614
614
  const relationshipCollection = await ProfileRelationshipCollection.create(this.options);
615
615
  const direction = options?.direction || "all";
@@ -654,7 +654,7 @@ var Profile = class extends SmrtObject {
654
654
  */
655
655
  async removeRelationship(toProfile, relationshipSlug) {
656
656
  const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-_n22WqTb-DiZUWvev.js").then((n) => n.n).then((n) => n.n);
657
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-BjEj-f3r.js").then((n) => n.r).then((n) => n.n);
657
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-C4g_QLI4-CQ3lrObu.js").then((n) => n.r).then((n) => n.n);
658
658
  const relationshipType = await (await ProfileRelationshipTypeCollection.create(this.options)).getBySlug(relationshipSlug);
659
659
  if (!relationshipType) throw new Error(`Relationship type '${relationshipSlug}' not found`);
660
660
  const relationshipCollection = await ProfileRelationshipCollection.create(this.options);
@@ -778,7 +778,7 @@ var Profile = class extends SmrtObject {
778
778
  * @returns Array of OIDC identity records
779
779
  */
780
780
  async getOidcIdentities() {
781
- const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-h8pqeEc_.js").then((n) => n.r).then((n) => n.r);
781
+ const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-DmSa-Jj5.js").then((n) => n.r).then((n) => n.r);
782
782
  return await (await OidcIdentityCollection.create(this.options)).findByProfile(this.id);
783
783
  }
784
784
  /**
@@ -791,7 +791,7 @@ var Profile = class extends SmrtObject {
791
791
  * type, but refuses to create or rebind authority.
792
792
  */
793
793
  async linkOidcIdentity(oidcData) {
794
- const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-h8pqeEc_.js").then((n) => n.r).then((n) => n.r);
794
+ const { OidcIdentityCollection } = await import("./OidcIdentityCollection-ClOyaHeF-DmSa-Jj5.js").then((n) => n.r).then((n) => n.r);
795
795
  return await (await OidcIdentityCollection.create(this.options)).linkToProfile(this, oidcData);
796
796
  }
797
797
  /**
@@ -820,7 +820,7 @@ var Profile = class extends SmrtObject {
820
820
  * @returns Array of audit log entries
821
821
  */
822
822
  async getAuditLogs(limit = 50) {
823
- const { AuditLogCollection } = await import("./AuditLogCollection-WDHL-_AF-DOee2NBy.js").then((n) => n.r).then((n) => n.n);
823
+ const { AuditLogCollection } = await import("./AuditLogCollection-WDHL-_AF-itCZzK5F.js").then((n) => n.r).then((n) => n.n);
824
824
  return await (await AuditLogCollection.create(this.options)).getRecentActivity(this.id, limit);
825
825
  }
826
826
  /**
@@ -830,7 +830,7 @@ var Profile = class extends SmrtObject {
830
830
  * @returns The created audit log entry
831
831
  */
832
832
  async recordAction(options) {
833
- const { AuditLogCollection } = await import("./AuditLogCollection-WDHL-_AF-DOee2NBy.js").then((n) => n.r).then((n) => n.n);
833
+ const { AuditLogCollection } = await import("./AuditLogCollection-WDHL-_AF-itCZzK5F.js").then((n) => n.r).then((n) => n.n);
834
834
  return await (await AuditLogCollection.create(this.options)).record({
835
835
  profile: this,
836
836
  ...options
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
4
  import { SmrtCollection, SmrtObject, field, foreignKey, isEmbeddedDatabase, smrt, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/ProfileLinkCollection-DFfZRsgv.js
@@ -203,7 +203,7 @@ var ProfileLinkCollection = class ProfileLinkCollection extends SmrtCollection {
203
203
  /** The profile's tenant; throws when the profile is not visible here. */
204
204
  async requireProfileTenant(profileId) {
205
205
  if (!profileId) throw new Error("A profile link needs a profile");
206
- const { ProfileCollection } = await import("./ProfileCollection-C4INKh7Y-kmilpari.js").then((n) => n.o).then((n) => n.r);
206
+ const { ProfileCollection } = await import("./ProfileCollection-C4INKh7Y-5u2MkyxW.js").then((n) => n.o).then((n) => n.r);
207
207
  const profile = await (await ProfileCollection.create({ db: this.db })).get({ id: profileId });
208
208
  if (!profile) throw new Error(`Profile '${profileId}' not found`);
209
209
  return profile.tenantId ?? null;
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
4
  import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/ProfileMetadataCollection-BIYKy4Y3.js
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
4
  import { SmrtCollection, SmrtObject, field, smrt } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/ProfileMetafieldCollection-Buz7gzag.js
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { i as tenantId, r as TenantScoped } from "./dist-DdAui9xB.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
4
  import { SmrtCollection, SmrtObject, foreignKey, oneToMany, smrt } from "@happyvertical/smrt-core";
5
5
  //#region ../profiles/dist/chunks/ProfileRelationshipCollection-C4g_QLI4.js
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { l as isSystemContext, s as withTenantGlobalRead } from "./dist-DdAui9xB.js";
2
+ import { l as isSystemContext, s as withTenantGlobalRead } from "./dist-EqBk8t9l.js";
3
3
  import { n as __exportAll$1 } from "./NostrIdentity-AC8fAdxe-DKxKyu_a.js";
4
- import { s as ProfileType } from "./ProfileCollection-C4INKh7Y-kmilpari.js";
4
+ import { s as ProfileType } from "./ProfileCollection-C4INKh7Y-5u2MkyxW.js";
5
5
  import { SmrtCollection } from "@happyvertical/smrt-core";
6
6
  //#region ../profiles/dist/chunks/ProfileTypeCollection-B7kwi1mU.js
7
7
  var ProfileTypeCollection_B7kwi1mU_exports = /* @__PURE__ */ __exportAll({
@@ -26,6 +26,61 @@ export declare function formatProjectedRecords(records: ExportRow[], fieldColumn
26
26
  * Get common fields across all types for an export file
27
27
  */
28
28
  export declare function getCommonFields(types: string[], fileConfig: ExportFileConfig, fieldExportDefault: boolean): Promise<string[]>;
29
+ /**
30
+ * Columns to select for an export file, plus the per-type exclusions that must
31
+ * still be enforced row by row.
32
+ */
33
+ export interface ExportColumnPlan {
34
+ /** Output fields, in first-appearance order. */
35
+ fields: string[];
36
+ /**
37
+ * Union exports only: for each listed type, the fields that type has but does
38
+ * not export (`exported: false`, `exclude`, or `fieldExportDefault: false`)
39
+ * while another listed type does. The union column set contains these, so
40
+ * rows of the excluding type must have them blanked after the query.
41
+ * Types with nothing to blank are omitted.
42
+ */
43
+ excludedByType: Map<string, Set<string>>;
44
+ }
45
+ /**
46
+ * Get the union of exportable fields across all types for an export file, and
47
+ * the per-type exclusions the union would otherwise leak.
48
+ *
49
+ * Fields are ordered by first appearance. Rows of a type that lacks a column
50
+ * come back NULL, so this is only appropriate for types that share one table.
51
+ * A column exportable for one type but excluded for another (`exported: false`)
52
+ * is in the union, so `excludedByType` names it for the excluding type and the
53
+ * caller blanks it per row via {@link applyTypeExclusions}.
54
+ */
55
+ export declare function getUnionPlan(types: string[], fileConfig: ExportFileConfig, fieldExportDefault: boolean): Promise<ExportColumnPlan>;
56
+ /**
57
+ * Get the union of exportable fields across all types for an export file.
58
+ * See {@link getUnionPlan} for the per-type exclusions this set implies.
59
+ */
60
+ export declare function getUnionFields(types: string[], fileConfig: ExportFileConfig, fieldExportDefault: boolean): Promise<string[]>;
61
+ /**
62
+ * Resolve the columns (and per-type exclusions) for an export file.
63
+ *
64
+ * Types that share one table (single-table inheritance) export the union of
65
+ * their columns, so subtype columns reach the file; `fields: 'common'` opts
66
+ * back into the intersection. Types spread over different tables always use
67
+ * the intersection, because only one table is queried. The intersection never
68
+ * contains a column excluded for any type, so only the union path needs
69
+ * per-row exclusions.
70
+ */
71
+ export declare function resolveExportPlan(types: string[], fileConfig: ExportFileConfig, fieldExportDefault: boolean): Promise<ExportColumnPlan>;
72
+ /** Resolve just the columns for an export file. See {@link resolveExportPlan}. */
73
+ export declare function resolveExportFields(types: string[], fileConfig: ExportFileConfig, fieldExportDefault: boolean): Promise<string[]>;
74
+ /**
75
+ * Blank, in place of the stored value, every field a row's own type excludes.
76
+ *
77
+ * The row's type comes from its `_meta_type` discriminator (`scope:Class`).
78
+ * Excluded fields are set to `null` under both the field and column keys so
79
+ * output shape stays identical across rows. A row whose type cannot be matched
80
+ * to a listed type fails the export, naming the fields and types involved,
81
+ * instead of risking an excluded value reaching the file.
82
+ */
83
+ export declare function applyTypeExclusions(rows: ExportRow[], excludedByType: Map<string, Set<string>>, typeNames: string[]): ExportRow[];
29
84
  export declare const exportCommand: CLICommand;
30
85
  export {};
31
86
  //# sourceMappingURL=export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAmBtD,mEAAmE;AACnE,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC,8DAA8D;AAC9D,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA8M7C;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,iBAAiB,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,EAAE,CAAC,CA2GtB;AAiBD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,SAAS,EAAE,EACpB,YAAY,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,6BAavD;AAoCD;;GAEG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC,CAoBnB;AAED,eAAO,MAAM,aAAa,EAAE,UA8R3B,CAAC"}
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/commands/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAmBtD,mEAAmE;AACnE,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzC,8DAA8D;AAC9D,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAqN7C;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,iBAAiB,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,EAAE,CAAC,CA2GtB;AAiBD,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,SAAS,EAAE,EACpB,YAAY,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,6BAavD;AAoCD;;GAEG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC,CAoBnB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;;OAMG;IACH,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAgD3B;AAgBD;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAmB3B;AAED,kFAAkF;AAClF,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,gBAAgB,EAC5B,kBAAkB,EAAE,OAAO,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC,CAGnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,EAAE,EACjB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EACxC,SAAS,EAAE,MAAM,EAAE,GAClB,SAAS,EAAE,CA8Bb;AAED,eAAO,MAAM,aAAa,EAAE,UA0S3B,CAAC"}
@@ -4246,11 +4246,8 @@ async function getExportableFields(typeName, fileConfig, fieldExportDefault) {
4246
4246
  const { ObjectRegistry } = await import("@happyvertical/smrt-core");
4247
4247
  const projection = await getProjectionCapabilities(typeName);
4248
4248
  const fields = await ObjectRegistry.getAllFields(typeName);
4249
- if (fields.size === 0) {
4250
- console.warn(`⚠️ No fields found for type: ${typeName}`);
4251
- return [];
4252
- }
4253
- if (fileConfig.include && fileConfig.include.length > 0) return fileConfig.include.filter((f) => fields.has(f) || f === "_meta_type" && projection.includeMetaType || f === "_meta_data" && projection.includeMetaData || f === "id" && projection.schemaColumns.has("id") || f === "slug" && projection.schemaColumns.has("slug"));
4249
+ if (fields.size === 0) throw new Error(`Export type "${typeName}" is not registered (no fields found). Check the spelling in smrt.config.js export types and that the class is registered (decorated and imported by the project).`);
4250
+ if (fileConfig.include && fileConfig.include.length > 0) return fileConfig.include.filter((f) => fields.has(f) && fields.get(f).exported !== false || f === "_meta_type" && projection.includeMetaType || f === "_meta_data" && projection.includeMetaData || f === "id" && projection.schemaColumns.has("id") || f === "slug" && projection.schemaColumns.has("slug"));
4254
4251
  const exportableFields = [];
4255
4252
  for (const [fieldName, rawFieldDef] of fields) {
4256
4253
  const fieldDef = rawFieldDef;
@@ -4415,6 +4412,94 @@ async function getCommonFields(types, fileConfig, fieldExportDefault) {
4415
4412
  if (fieldSets.length === 0) return [];
4416
4413
  return [...fieldSets[0]].filter((field) => fieldSets.every((set) => set.has(field)));
4417
4414
  }
4415
+ /**
4416
+ * Get the union of exportable fields across all types for an export file, and
4417
+ * the per-type exclusions the union would otherwise leak.
4418
+ *
4419
+ * Fields are ordered by first appearance. Rows of a type that lacks a column
4420
+ * come back NULL, so this is only appropriate for types that share one table.
4421
+ * A column exportable for one type but excluded for another (`exported: false`)
4422
+ * is in the union, so `excludedByType` names it for the excluding type and the
4423
+ * caller blanks it per row via {@link applyTypeExclusions}.
4424
+ */
4425
+ async function getUnionPlan(types, fileConfig, fieldExportDefault) {
4426
+ const { ObjectRegistry } = await import("@happyvertical/smrt-core");
4427
+ const union = /* @__PURE__ */ new Set();
4428
+ const perType = /* @__PURE__ */ new Map();
4429
+ for (const typeName of types) {
4430
+ const fields = await getExportableFields(typeName, fileConfig, fieldExportDefault);
4431
+ for (const field of fields) union.add(field);
4432
+ const all = await ObjectRegistry.getAllFields(typeName);
4433
+ perType.set(typeName, {
4434
+ exportable: new Set(fields),
4435
+ has: new Set(all.keys())
4436
+ });
4437
+ }
4438
+ const excludedByType = /* @__PURE__ */ new Map();
4439
+ for (const [typeName, { exportable, has }] of perType) {
4440
+ const excluded = /* @__PURE__ */ new Set();
4441
+ for (const field of union) if (!exportable.has(field) && has.has(field)) excluded.add(field);
4442
+ if (excluded.size > 0) excludedByType.set(typeName, excluded);
4443
+ }
4444
+ if (excludedByType.size > 0) {
4445
+ for (const typeName of excludedByType.keys()) if (!(await getProjectionCapabilities(typeName)).includeMetaType) throw new Error(`Export cannot enforce per-type field exclusions for "${typeName}": its table has no _meta_type discriminator. ${describeExclusions(excludedByType)}`);
4446
+ }
4447
+ return {
4448
+ fields: [...union],
4449
+ excludedByType
4450
+ };
4451
+ }
4452
+ /** Human-readable `field (Type, Type)` list for error messages. */
4453
+ function describeExclusions(excludedByType) {
4454
+ const byField = /* @__PURE__ */ new Map();
4455
+ for (const [typeName, fields] of excludedByType) for (const field of fields) byField.set(field, [...byField.get(field) ?? [], typeName]);
4456
+ return `Fields: ${[...byField].map(([field, typeNames]) => `"${field}" (excluded for ${typeNames.join(", ")})`).join("; ")}.`;
4457
+ }
4458
+ /**
4459
+ * Resolve the columns (and per-type exclusions) for an export file.
4460
+ *
4461
+ * Types that share one table (single-table inheritance) export the union of
4462
+ * their columns, so subtype columns reach the file; `fields: 'common'` opts
4463
+ * back into the intersection. Types spread over different tables always use
4464
+ * the intersection, because only one table is queried. The intersection never
4465
+ * contains a column excluded for any type, so only the union path needs
4466
+ * per-row exclusions.
4467
+ */
4468
+ async function resolveExportPlan(types, fileConfig, fieldExportDefault) {
4469
+ if (types.length > 1 && fileConfig.fields !== "common") {
4470
+ const { ObjectRegistry } = await import("@happyvertical/smrt-core");
4471
+ const tables = new Set(types.map((t) => ObjectRegistry.getTableName(t)));
4472
+ if (tables.size === 1 && !tables.has(void 0)) return getUnionPlan(types, fileConfig, fieldExportDefault);
4473
+ if (fileConfig.fields === "union") throw new Error(`Export "fields: 'union'" requires all types to share one table; got ${types.join(", ")}.`);
4474
+ }
4475
+ return {
4476
+ fields: await getCommonFields(types, fileConfig, fieldExportDefault),
4477
+ excludedByType: /* @__PURE__ */ new Map()
4478
+ };
4479
+ }
4480
+ /**
4481
+ * Blank, in place of the stored value, every field a row's own type excludes.
4482
+ *
4483
+ * The row's type comes from its `_meta_type` discriminator (`scope:Class`).
4484
+ * Excluded fields are set to `null` under both the field and column keys so
4485
+ * output shape stays identical across rows. A row whose type cannot be matched
4486
+ * to a listed type fails the export, naming the fields and types involved,
4487
+ * instead of risking an excluded value reaching the file.
4488
+ */
4489
+ function applyTypeExclusions(rows, excludedByType, typeNames) {
4490
+ if (excludedByType.size === 0) return rows;
4491
+ return rows.map((row) => {
4492
+ const discriminator = row._meta_type;
4493
+ const matched = typeof discriminator === "string" ? typeNames.filter((t) => discriminator === t || discriminator.endsWith(`:${t}`)) : [];
4494
+ if (matched.length === 0) throw new Error(`Export cannot determine the type of a row (_meta_type=${JSON.stringify(discriminator ?? null)}; expected one of ${typeNames.join(", ")}), so per-type field exclusions cannot be enforced. ${describeExclusions(excludedByType)}`);
4495
+ const redacted = { ...row };
4496
+ for (const typeName of matched) for (const field of excludedByType.get(typeName) ?? []) {
4497
+ redacted[field] = null;
4498
+ redacted[toColumnName(field)] = null;
4499
+ }
4500
+ return redacted;
4501
+ });
4502
+ }
4418
4503
  var exportCommand = {
4419
4504
  name: "export",
4420
4505
  description: "Export data from database to JSON files for static site generation",
@@ -4519,7 +4604,7 @@ var exportCommand = {
4519
4604
  console.warn(`⚠️ No types specified for ${filename}, skipping`);
4520
4605
  continue;
4521
4606
  }
4522
- const fields = await getCommonFields(types, fileConfig, fieldExportDefault);
4607
+ const { fields, excludedByType } = await resolveExportPlan(types, fileConfig, fieldExportDefault);
4523
4608
  if (fields.length === 0) {
4524
4609
  console.warn(`⚠️ No exportable fields for ${filename}, skipping`);
4525
4610
  continue;
@@ -4529,7 +4614,8 @@ var exportCommand = {
4529
4614
  if (tableName === "contents" && !showDrafts && fields.includes("status")) {
4530
4615
  if (!filters.status) filters.status = ["published"];
4531
4616
  }
4532
- const formattedRecords = formatProjectedRecords(await queryWithProjection(db, tableName, types, fields, filters, fileConfig.orderBy, fileConfig.limit), fields.map((field) => ({
4617
+ const queryFields = excludedByType.size > 0 && !fields.includes("_meta_type") ? [...fields, "_meta_type"] : fields;
4618
+ const formattedRecords = formatProjectedRecords(applyTypeExclusions(await queryWithProjection(db, tableName, types, queryFields, filters, fileConfig.orderBy, fileConfig.limit), excludedByType, types), fields.map((field) => ({
4533
4619
  field,
4534
4620
  column: toColumnName(field)
4535
4621
  })));
@@ -7051,7 +7137,7 @@ var dbMaterializeTenantHierarchyCommand = {
7051
7137
  if (!config.database?.url || config.database.url === ":memory:") throw new Error("Database configuration required for db:materialize-tenant-hierarchy. Configure database.url in smrt.config.ts (or DATABASE_URL).");
7052
7138
  const dbType = config.database.type || "sqlite";
7053
7139
  const { getDatabase } = await import("@happyvertical/sql");
7054
- const { materializeTenantHierarchy, TenantHierarchyMaterializationError } = await import("./dist-BS8Pl9RN.js");
7140
+ const { materializeTenantHierarchy, TenantHierarchyMaterializationError } = await import("./dist-AUzJ0Xmj.js");
7055
7141
  db = await getDatabase({
7056
7142
  type: dbType,
7057
7143
  url: config.database.url
@@ -7260,7 +7346,7 @@ var dbMigrateLedgerAccountsCommand = {
7260
7346
  if (dbType !== "postgres") throw new Error("db:migrate-ledger-accounts currently supports PostgreSQL only; no changes were made. See the smrt-ledgers README for SQLite.");
7261
7347
  await autoDiscoverAndLoad();
7262
7348
  const { getDatabase } = await import("@happyvertical/sql");
7263
- const { migrateLedgerAccountsTable, planLedgerAccountsTableMove } = await import("./dist-D23BpLWY.js");
7349
+ const { migrateLedgerAccountsTable, planLedgerAccountsTableMove } = await import("./dist-CAEt-5TC.js");
7264
7350
  db = await getDatabase({
7265
7351
  type: dbType,
7266
7352
  url: config.database.url