@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/dist/service.js +12 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/service.ts +12 -5
package/dist/service.js
CHANGED
|
@@ -1073,11 +1073,19 @@ export class ChannelConnectorService {
|
|
|
1073
1073
|
const currentIds = [...(existingOptionValues.get(variantId) ?? [])].sort();
|
|
1074
1074
|
const desiredIds = [...new Set(desiredOptionValueIds)].sort();
|
|
1075
1075
|
if (currentIds.length !== desiredIds.length || currentIds.some((id, index) => id !== desiredIds[index])) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1076
|
+
// Rewrite and bump in ONE transaction: an option-value change is a variant-only change
|
|
1077
|
+
// (the entity row is not touched), and `variants.updated_at` is the only trace a consumer
|
|
1078
|
+
// can version it from. Neither may commit without the other.
|
|
1079
|
+
const optionVariantId = variantId;
|
|
1080
|
+
await this.transact(async (tx) => {
|
|
1081
|
+
await tx.delete(variantOptionValues).where(eq(variantOptionValues.variantId, optionVariantId));
|
|
1082
|
+
if (desiredIds.length > 0) {
|
|
1083
|
+
await tx.insert(variantOptionValues).values(desiredIds.map((optionValueId) => ({ variantId: optionVariantId, optionValueId }))).onConflictDoNothing();
|
|
1084
|
+
}
|
|
1085
|
+
await tx.update(variants).set({ updatedAt: sql `now()` }).where(eq(variants.id, optionVariantId));
|
|
1086
|
+
});
|
|
1087
|
+
if (desiredIds.length > 0)
|
|
1079
1088
|
repaired += 1;
|
|
1080
|
-
}
|
|
1081
1089
|
// The map is the read model for this pass; a payload repeating an externalId must not see
|
|
1082
1090
|
// the pre-fetched state after this write.
|
|
1083
1091
|
existingOptionValues.set(variantId, [...desiredIds]);
|