@saasicat/adapter-prisma 0.12.0 → 0.13.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/index.cjs CHANGED
@@ -855,14 +855,15 @@ var PrismaBundleRepository = class {
855
855
  });
856
856
  return rows.map((row) => toBundleVersionRow(row, bundle, this.validityWindows));
857
857
  }
858
- async findVersionById(versionId) {
859
- const row = await this.db().bundleVersion.findUnique({
858
+ async findVersionById(versionId, tx) {
859
+ const db = this.db(tx);
860
+ const row = await db.bundleVersion.findUnique({
860
861
  where: {
861
862
  id: versionId
862
863
  }
863
864
  });
864
865
  if (!row) return null;
865
- const bundle = await this.db().bundle.findUnique({
866
+ const bundle = await db.bundle.findUnique({
866
867
  where: {
867
868
  id: row.bundleId
868
869
  }
@@ -3724,8 +3725,8 @@ var PrismaSubscriptionBundleRepository = class {
3724
3725
  });
3725
3726
  return row ? toRecord3(row) : null;
3726
3727
  }
3727
- async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date()) {
3728
- const rows = await this.db().subscriptionBundle.findMany({
3728
+ async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date(), tx) {
3729
+ const rows = await this.db(tx).subscriptionBundle.findMany({
3729
3730
  where: {
3730
3731
  subscriptionId,
3731
3732
  OR: [
@@ -3852,11 +3853,11 @@ var PrismaSubscriptionContractRepository = class {
3852
3853
  constructor(prisma) {
3853
3854
  this.prisma = prisma;
3854
3855
  }
3855
- get db() {
3856
- return this.prisma;
3856
+ db(tx) {
3857
+ return tx ?? this.prisma;
3857
3858
  }
3858
3859
  async list(filter) {
3859
- const rows = await this.db.subscriptionContract.findMany({
3860
+ const rows = await this.db().subscriptionContract.findMany({
3860
3861
  where: {
3861
3862
  ...filter.projectKey ? {
3862
3863
  projectKey: filter.projectKey
@@ -3898,7 +3899,7 @@ var PrismaSubscriptionContractRepository = class {
3898
3899
  return rows.map(toRecord4);
3899
3900
  }
3900
3901
  async findById(contractId) {
3901
- const row = await this.db.subscriptionContract.findUnique({
3902
+ const row = await this.db().subscriptionContract.findUnique({
3902
3903
  where: {
3903
3904
  id: contractId
3904
3905
  },
@@ -3908,8 +3909,8 @@ var PrismaSubscriptionContractRepository = class {
3908
3909
  });
3909
3910
  return row ? toRecord4(row) : null;
3910
3911
  }
3911
- async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date()) {
3912
- const row = await this.db.subscriptionContract.findFirst({
3912
+ async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date(), tx) {
3913
+ const row = await this.db(tx).subscriptionContract.findFirst({
3913
3914
  where: {
3914
3915
  tenantId,
3915
3916
  status: {
@@ -3944,7 +3945,7 @@ var PrismaSubscriptionContractRepository = class {
3944
3945
  return row ? toRecord4(row) : null;
3945
3946
  }
3946
3947
  async create(data) {
3947
- const row = await this.db.subscriptionContract.create({
3948
+ const row = await this.db().subscriptionContract.create({
3948
3949
  data: {
3949
3950
  projectKey: data.projectKey,
3950
3951
  tenantId: data.tenantId,
@@ -3976,7 +3977,7 @@ var PrismaSubscriptionContractRepository = class {
3976
3977
  return toRecord4(row);
3977
3978
  }
3978
3979
  async terminate(contractId, data) {
3979
- const row = await this.db.subscriptionContract.update({
3980
+ const row = await this.db().subscriptionContract.update({
3980
3981
  where: {
3981
3982
  id: contractId
3982
3983
  },
package/dist/index.d.cts CHANGED
@@ -797,7 +797,7 @@ declare class PrismaBundleRepository implements BundleRepository {
797
797
  update(bundleId: string, data: UpdateBundleData): Promise<BundleRow>;
798
798
  softDelete(bundleId: string): Promise<void>;
799
799
  listVersions(bundleId: string): Promise<BundleVersionRow[]>;
800
- findVersionById(versionId: string): Promise<BundleVersionRow | null>;
800
+ findVersionById(versionId: string, tx?: TransactionContext): Promise<BundleVersionRow | null>;
801
801
  findCurrentDraft(bundleId: string): Promise<BundleVersionRow | null>;
802
802
  findLatestLive(bundleId: string, tx?: TransactionContext): Promise<BundleVersionRow | null>;
803
803
  private findActiveBundleVersionWithValidity;
@@ -1054,7 +1054,7 @@ declare class PrismaSubscriptionBundleRepository implements SubscriptionBundleRe
1054
1054
  private db;
1055
1055
  listBySubscription(subscriptionId: string): Promise<SubscriptionBundleRecord[]>;
1056
1056
  findById(subscriptionBundleId: string): Promise<SubscriptionBundleRecord | null>;
1057
- listActiveBySubscription(subscriptionId: string, asOf?: Date): Promise<SubscriptionBundleRecord[]>;
1057
+ listActiveBySubscription(subscriptionId: string, asOf?: Date, tx?: TransactionContext): Promise<SubscriptionBundleRecord[]>;
1058
1058
  add(data: CreateSubscriptionBundleData): Promise<SubscriptionBundleRecord>;
1059
1059
  cancel(subscriptionBundleId: string, data: CancelSubscriptionBundleData): Promise<SubscriptionBundleRecord>;
1060
1060
  reactivate(subscriptionBundleId: string): Promise<SubscriptionBundleRecord>;
@@ -1453,10 +1453,10 @@ declare class PrismaPromotionRepository implements PromotionRepository {
1453
1453
  declare class PrismaSubscriptionContractRepository implements SubscriptionContractRepository {
1454
1454
  private readonly prisma;
1455
1455
  constructor(prisma: PrismaLike);
1456
- private get db();
1456
+ private db;
1457
1457
  list(filter: SubscriptionContractFilter): Promise<SubscriptionContractRecord[]>;
1458
1458
  findById(contractId: string): Promise<SubscriptionContractRecord | null>;
1459
- findActiveByTenantId(tenantId: string, asOf?: Date): Promise<SubscriptionContractRecord | null>;
1459
+ findActiveByTenantId(tenantId: string, asOf?: Date, tx?: TransactionContext): Promise<SubscriptionContractRecord | null>;
1460
1460
  create(data: CreateSubscriptionContractData): Promise<SubscriptionContractRecord>;
1461
1461
  terminate(contractId: string, data: TerminateSubscriptionContractData): Promise<SubscriptionContractRecord>;
1462
1462
  }
package/dist/index.d.ts CHANGED
@@ -797,7 +797,7 @@ declare class PrismaBundleRepository implements BundleRepository {
797
797
  update(bundleId: string, data: UpdateBundleData): Promise<BundleRow>;
798
798
  softDelete(bundleId: string): Promise<void>;
799
799
  listVersions(bundleId: string): Promise<BundleVersionRow[]>;
800
- findVersionById(versionId: string): Promise<BundleVersionRow | null>;
800
+ findVersionById(versionId: string, tx?: TransactionContext): Promise<BundleVersionRow | null>;
801
801
  findCurrentDraft(bundleId: string): Promise<BundleVersionRow | null>;
802
802
  findLatestLive(bundleId: string, tx?: TransactionContext): Promise<BundleVersionRow | null>;
803
803
  private findActiveBundleVersionWithValidity;
@@ -1054,7 +1054,7 @@ declare class PrismaSubscriptionBundleRepository implements SubscriptionBundleRe
1054
1054
  private db;
1055
1055
  listBySubscription(subscriptionId: string): Promise<SubscriptionBundleRecord[]>;
1056
1056
  findById(subscriptionBundleId: string): Promise<SubscriptionBundleRecord | null>;
1057
- listActiveBySubscription(subscriptionId: string, asOf?: Date): Promise<SubscriptionBundleRecord[]>;
1057
+ listActiveBySubscription(subscriptionId: string, asOf?: Date, tx?: TransactionContext): Promise<SubscriptionBundleRecord[]>;
1058
1058
  add(data: CreateSubscriptionBundleData): Promise<SubscriptionBundleRecord>;
1059
1059
  cancel(subscriptionBundleId: string, data: CancelSubscriptionBundleData): Promise<SubscriptionBundleRecord>;
1060
1060
  reactivate(subscriptionBundleId: string): Promise<SubscriptionBundleRecord>;
@@ -1453,10 +1453,10 @@ declare class PrismaPromotionRepository implements PromotionRepository {
1453
1453
  declare class PrismaSubscriptionContractRepository implements SubscriptionContractRepository {
1454
1454
  private readonly prisma;
1455
1455
  constructor(prisma: PrismaLike);
1456
- private get db();
1456
+ private db;
1457
1457
  list(filter: SubscriptionContractFilter): Promise<SubscriptionContractRecord[]>;
1458
1458
  findById(contractId: string): Promise<SubscriptionContractRecord | null>;
1459
- findActiveByTenantId(tenantId: string, asOf?: Date): Promise<SubscriptionContractRecord | null>;
1459
+ findActiveByTenantId(tenantId: string, asOf?: Date, tx?: TransactionContext): Promise<SubscriptionContractRecord | null>;
1460
1460
  create(data: CreateSubscriptionContractData): Promise<SubscriptionContractRecord>;
1461
1461
  terminate(contractId: string, data: TerminateSubscriptionContractData): Promise<SubscriptionContractRecord>;
1462
1462
  }
package/dist/index.js CHANGED
@@ -796,14 +796,15 @@ var PrismaBundleRepository = class {
796
796
  });
797
797
  return rows.map((row) => toBundleVersionRow(row, bundle, this.validityWindows));
798
798
  }
799
- async findVersionById(versionId) {
800
- const row = await this.db().bundleVersion.findUnique({
799
+ async findVersionById(versionId, tx) {
800
+ const db = this.db(tx);
801
+ const row = await db.bundleVersion.findUnique({
801
802
  where: {
802
803
  id: versionId
803
804
  }
804
805
  });
805
806
  if (!row) return null;
806
- const bundle = await this.db().bundle.findUnique({
807
+ const bundle = await db.bundle.findUnique({
807
808
  where: {
808
809
  id: row.bundleId
809
810
  }
@@ -3665,8 +3666,8 @@ var PrismaSubscriptionBundleRepository = class {
3665
3666
  });
3666
3667
  return row ? toRecord3(row) : null;
3667
3668
  }
3668
- async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date()) {
3669
- const rows = await this.db().subscriptionBundle.findMany({
3669
+ async listActiveBySubscription(subscriptionId, asOf = /* @__PURE__ */ new Date(), tx) {
3670
+ const rows = await this.db(tx).subscriptionBundle.findMany({
3670
3671
  where: {
3671
3672
  subscriptionId,
3672
3673
  OR: [
@@ -3793,11 +3794,11 @@ var PrismaSubscriptionContractRepository = class {
3793
3794
  constructor(prisma) {
3794
3795
  this.prisma = prisma;
3795
3796
  }
3796
- get db() {
3797
- return this.prisma;
3797
+ db(tx) {
3798
+ return tx ?? this.prisma;
3798
3799
  }
3799
3800
  async list(filter) {
3800
- const rows = await this.db.subscriptionContract.findMany({
3801
+ const rows = await this.db().subscriptionContract.findMany({
3801
3802
  where: {
3802
3803
  ...filter.projectKey ? {
3803
3804
  projectKey: filter.projectKey
@@ -3839,7 +3840,7 @@ var PrismaSubscriptionContractRepository = class {
3839
3840
  return rows.map(toRecord4);
3840
3841
  }
3841
3842
  async findById(contractId) {
3842
- const row = await this.db.subscriptionContract.findUnique({
3843
+ const row = await this.db().subscriptionContract.findUnique({
3843
3844
  where: {
3844
3845
  id: contractId
3845
3846
  },
@@ -3849,8 +3850,8 @@ var PrismaSubscriptionContractRepository = class {
3849
3850
  });
3850
3851
  return row ? toRecord4(row) : null;
3851
3852
  }
3852
- async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date()) {
3853
- const row = await this.db.subscriptionContract.findFirst({
3853
+ async findActiveByTenantId(tenantId, asOf = /* @__PURE__ */ new Date(), tx) {
3854
+ const row = await this.db(tx).subscriptionContract.findFirst({
3854
3855
  where: {
3855
3856
  tenantId,
3856
3857
  status: {
@@ -3885,7 +3886,7 @@ var PrismaSubscriptionContractRepository = class {
3885
3886
  return row ? toRecord4(row) : null;
3886
3887
  }
3887
3888
  async create(data) {
3888
- const row = await this.db.subscriptionContract.create({
3889
+ const row = await this.db().subscriptionContract.create({
3889
3890
  data: {
3890
3891
  projectKey: data.projectKey,
3891
3892
  tenantId: data.tenantId,
@@ -3917,7 +3918,7 @@ var PrismaSubscriptionContractRepository = class {
3917
3918
  return toRecord4(row);
3918
3919
  }
3919
3920
  async terminate(contractId, data) {
3920
- const row = await this.db.subscriptionContract.update({
3921
+ const row = await this.db().subscriptionContract.update({
3921
3922
  where: {
3922
3923
  id: contractId
3923
3924
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasicat/adapter-prisma",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Prisma + PostgreSQL persistence for SaaSiCat: one standard bundle for core, catalog, entitlement, tenant billing, Admin resources and promo, plus individual adapters for custom compositions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@saasicat/types": "^0.12.0"
25
+ "@saasicat/types": "^0.13.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@nestjs/common": "^11.0.0"
@@ -34,8 +34,8 @@
34
34
  "@prisma/client": "^6.19.0",
35
35
  "tsup": "^8.0.0",
36
36
  "typescript": "^6.0.0",
37
- "@saasicat/persistence-testing": "^0.12.0",
38
- "@saasicat/spec": "^0.12.0"
37
+ "@saasicat/persistence-testing": "^0.13.0",
38
+ "@saasicat/spec": "^0.13.0"
39
39
  },
40
40
  "license": "Apache-2.0",
41
41
  "author": "Taci Uelker",