@porulle/plugin-channel-connector 0.50.3 → 0.51.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/plugin-channel-connector",
3
- "version": "0.50.3",
3
+ "version": "0.51.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,15 +19,15 @@
19
19
  "dependencies": {
20
20
  "@hono/zod-openapi": "^1.2.2",
21
21
  "hono": "^4.12.5",
22
- "@porulle/core": "0.50.3"
22
+ "@porulle/core": "0.51.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^24.5.2",
26
26
  "eslint": "^9.39.1",
27
27
  "typescript": "5.9.2",
28
28
  "vitest": "^3.2.4",
29
- "@porulle/typescript-config": "0.1.0",
30
- "@porulle/eslint-config": "0.1.0"
29
+ "@porulle/eslint-config": "0.1.0",
30
+ "@porulle/typescript-config": "0.1.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
package/src/service.ts CHANGED
@@ -1743,11 +1743,18 @@ export class ChannelConnectorService {
1743
1743
  const currentIds = [...(existingOptionValues.get(variantId) ?? [])].sort();
1744
1744
  const desiredIds = [...new Set(desiredOptionValueIds)].sort();
1745
1745
  if (currentIds.length !== desiredIds.length || currentIds.some((id, index) => id !== desiredIds[index])) {
1746
- await this.db.delete(variantOptionValues).where(eq(variantOptionValues.variantId, variantId));
1747
- if (desiredIds.length > 0) {
1748
- await this.db.insert(variantOptionValues).values(desiredIds.map((optionValueId) => ({ variantId, optionValueId }))).onConflictDoNothing();
1749
- repaired += 1;
1750
- }
1746
+ // Rewrite and bump in ONE transaction: an option-value change is a variant-only change
1747
+ // (the entity row is not touched), and `variants.updated_at` is the only trace a consumer
1748
+ // can version it from. Neither may commit without the other.
1749
+ const optionVariantId = variantId;
1750
+ await this.transact(async (tx) => {
1751
+ await tx.delete(variantOptionValues).where(eq(variantOptionValues.variantId, optionVariantId));
1752
+ if (desiredIds.length > 0) {
1753
+ await tx.insert(variantOptionValues).values(desiredIds.map((optionValueId) => ({ variantId: optionVariantId, optionValueId }))).onConflictDoNothing();
1754
+ }
1755
+ await tx.update(variants).set({ updatedAt: sql`now()` }).where(eq(variants.id, optionVariantId));
1756
+ });
1757
+ if (desiredIds.length > 0) repaired += 1;
1751
1758
  // The map is the read model for this pass; a payload repeating an externalId must not see
1752
1759
  // the pre-fetched state after this write.
1753
1760
  existingOptionValues.set(variantId, [...desiredIds]);