@medusajs/link-modules 0.2.7 → 0.2.8-next-20240208080225
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/definitions/cart-sales-channel.js +5 -8
- package/dist/definitions/product-sales-channel.js +2 -2
- package/dist/definitions/product-shipping-profile.js +3 -0
- package/dist/definitions/product-variant-inventory-item.js +7 -4
- package/dist/definitions/product-variant-price-set.js +5 -5
- package/dist/initialize/index.js +12 -1
- package/dist/links.js +4 -4
- package/dist/loaders/container.js +11 -0
- package/dist/repositories/link.d.ts +10 -9
- package/dist/services/link-module-service.d.ts +10 -4
- package/dist/services/link-module-service.js +67 -3
- package/dist/services/link.d.ts +2 -2
- package/package.json +4 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CartSalesChannel = void 0;
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
4
5
|
const links_1 = require("../links");
|
|
5
6
|
exports.CartSalesChannel = {
|
|
6
7
|
serviceName: links_1.LINKS.CartSalesChannel,
|
|
@@ -20,15 +21,13 @@ exports.CartSalesChannel = {
|
|
|
20
21
|
primaryKeys: ["id", "cart_id", "sales_channel_id"],
|
|
21
22
|
relationships: [
|
|
22
23
|
{
|
|
23
|
-
serviceName:
|
|
24
|
-
isInternalService: true,
|
|
24
|
+
serviceName: modules_sdk_1.Modules.CART,
|
|
25
25
|
primaryKey: "id",
|
|
26
26
|
foreignKey: "cart_id",
|
|
27
27
|
alias: "cart",
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
serviceName:
|
|
31
|
-
isInternalService: true,
|
|
30
|
+
serviceName: modules_sdk_1.Modules.SALES_CHANNEL,
|
|
32
31
|
primaryKey: "id",
|
|
33
32
|
foreignKey: "sales_channel_id",
|
|
34
33
|
alias: "sales_channel",
|
|
@@ -36,26 +35,24 @@ exports.CartSalesChannel = {
|
|
|
36
35
|
],
|
|
37
36
|
extends: [
|
|
38
37
|
{
|
|
39
|
-
serviceName:
|
|
38
|
+
serviceName: modules_sdk_1.Modules.CART,
|
|
40
39
|
fieldAlias: {
|
|
41
40
|
sales_channel: "sales_channel_link.sales_channel",
|
|
42
41
|
},
|
|
43
42
|
relationship: {
|
|
44
43
|
serviceName: links_1.LINKS.CartSalesChannel,
|
|
45
|
-
isInternalService: true,
|
|
46
44
|
primaryKey: "cart_id",
|
|
47
45
|
foreignKey: "id",
|
|
48
46
|
alias: "sales_channel_link",
|
|
49
47
|
},
|
|
50
48
|
},
|
|
51
49
|
{
|
|
52
|
-
serviceName:
|
|
50
|
+
serviceName: modules_sdk_1.Modules.SALES_CHANNEL,
|
|
53
51
|
fieldAlias: {
|
|
54
52
|
carts: "cart_link.cart",
|
|
55
53
|
},
|
|
56
54
|
relationship: {
|
|
57
55
|
serviceName: links_1.LINKS.CartSalesChannel,
|
|
58
|
-
isInternalService: true,
|
|
59
56
|
primaryKey: "sales_channel_id",
|
|
60
57
|
foreignKey: "id",
|
|
61
58
|
alias: "cart_link",
|
|
@@ -27,7 +27,7 @@ exports.ProductSalesChannel = {
|
|
|
27
27
|
alias: "product",
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
serviceName:
|
|
30
|
+
serviceName: modules_sdk_1.Modules.SALES_CHANNEL,
|
|
31
31
|
isInternalService: true,
|
|
32
32
|
primaryKey: "id",
|
|
33
33
|
foreignKey: "sales_channel_id",
|
|
@@ -49,7 +49,7 @@ exports.ProductSalesChannel = {
|
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
serviceName:
|
|
52
|
+
serviceName: modules_sdk_1.Modules.SALES_CHANNEL,
|
|
53
53
|
relationship: {
|
|
54
54
|
serviceName: links_1.LINKS.ProductSalesChannel,
|
|
55
55
|
isInternalService: true,
|
|
@@ -18,10 +18,13 @@ exports.ProductVariantInventoryItem = {
|
|
|
18
18
|
},
|
|
19
19
|
alias: [
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
name: [
|
|
22
|
+
"product_variant_inventory_item",
|
|
23
|
+
"product_variant_inventory_items",
|
|
24
|
+
],
|
|
25
|
+
args: {
|
|
26
|
+
entity: "LinkProductVariantInventoryItem",
|
|
27
|
+
},
|
|
25
28
|
},
|
|
26
29
|
],
|
|
27
30
|
primaryKeys: ["id", "variant_id", "inventory_item_id"],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProductVariantPriceSet = void 0;
|
|
4
|
-
const links_1 = require("../links");
|
|
5
4
|
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
+
const links_1 = require("../links");
|
|
6
6
|
exports.ProductVariantPriceSet = {
|
|
7
7
|
serviceName: links_1.LINKS.ProductVariantPriceSet,
|
|
8
8
|
isLink: true,
|
|
@@ -12,10 +12,10 @@ exports.ProductVariantPriceSet = {
|
|
|
12
12
|
},
|
|
13
13
|
alias: [
|
|
14
14
|
{
|
|
15
|
-
name: "product_variant_price_set",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
name: ["product_variant_price_set", "product_variant_price_sets"],
|
|
16
|
+
args: {
|
|
17
|
+
entity: "LinkProductVariantPriceSet",
|
|
18
|
+
},
|
|
19
19
|
},
|
|
20
20
|
],
|
|
21
21
|
primaryKeys: ["id", "variant_id", "price_set_id"],
|
package/dist/initialize/index.js
CHANGED
|
@@ -74,12 +74,23 @@ const initialize = async (options, modulesDefinition, injectedDependencies) => {
|
|
|
74
74
|
!modulesLoadedKeys.includes(foreign.serviceName))) {
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const logger = injectedDependencies?.[utils_1.ContainerRegistrationKeys.LOGGER] ?? console.log;
|
|
78
|
+
definition.schema = (0, utils_2.generateGraphQLSchema)(definition, primary, foreign, {
|
|
79
|
+
logger,
|
|
80
|
+
});
|
|
81
|
+
definition.alias ?? (definition.alias = []);
|
|
82
|
+
for (const alias of definition.alias) {
|
|
83
|
+
alias.args ?? (alias.args = {});
|
|
84
|
+
alias.args.entity = (0, utils_1.toPascalCase)("Link_" +
|
|
85
|
+
(definition.databaseConfig?.tableName ??
|
|
86
|
+
(0, utils_2.composeTableName)(primary.serviceName, primary.foreignKey, foreign.serviceName, foreign.foreignKey)));
|
|
87
|
+
}
|
|
78
88
|
const moduleDefinition = (0, module_definition_1.getLinkModuleDefinition)(definition, primary, foreign);
|
|
79
89
|
const linkModuleDefinition = {
|
|
80
90
|
key: serviceKey,
|
|
81
91
|
registrationName: serviceKey,
|
|
82
92
|
label: serviceKey,
|
|
93
|
+
dependencies: [modules_sdk_1.ModuleRegistrationName.EVENT_BUS],
|
|
83
94
|
defaultModuleDeclaration: {
|
|
84
95
|
scope: types_1.MODULE_SCOPE.INTERNAL,
|
|
85
96
|
resources: injectedDependencies?.[utils_1.ContainerRegistrationKeys.PG_CONNECTION]
|
package/dist/links.js
CHANGED
|
@@ -8,8 +8,8 @@ exports.LINKS = {
|
|
|
8
8
|
ProductVariantPriceSet: (0, utils_1.composeLinkName)(modules_sdk_1.Modules.PRODUCT, "variant_id", modules_sdk_1.Modules.PRICING, "price_set_id"),
|
|
9
9
|
// Internal services
|
|
10
10
|
ProductShippingProfile: (0, utils_1.composeLinkName)(modules_sdk_1.Modules.PRODUCT, "variant_id", "shippingProfileService", "profile_id"),
|
|
11
|
-
ProductSalesChannel: (0, utils_1.composeLinkName)(modules_sdk_1.Modules.PRODUCT, "product_id",
|
|
12
|
-
CartSalesChannel: (0, utils_1.composeLinkName)(
|
|
13
|
-
OrderSalesChannel: (0, utils_1.composeLinkName)("orderService", "order_id",
|
|
14
|
-
PublishableApiKeySalesChannel: (0, utils_1.composeLinkName)("publishableApiKeyService", "publishable_key_id",
|
|
11
|
+
ProductSalesChannel: (0, utils_1.composeLinkName)(modules_sdk_1.Modules.PRODUCT, "product_id", modules_sdk_1.Modules.SALES_CHANNEL, "sales_channel_id"),
|
|
12
|
+
CartSalesChannel: (0, utils_1.composeLinkName)(modules_sdk_1.Modules.CART, "cart_id", modules_sdk_1.Modules.SALES_CHANNEL, "sales_channel_id"),
|
|
13
|
+
OrderSalesChannel: (0, utils_1.composeLinkName)("orderService", "order_id", modules_sdk_1.Modules.SALES_CHANNEL, "sales_channel_id"),
|
|
14
|
+
PublishableApiKeySalesChannel: (0, utils_1.composeLinkName)("publishableApiKeyService", "publishable_key_id", modules_sdk_1.Modules.SALES_CHANNEL, "sales_channel_id"),
|
|
15
15
|
};
|
|
@@ -3,10 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.containerLoader = void 0;
|
|
4
4
|
const _repositories_1 = require("../repositories");
|
|
5
5
|
const _services_1 = require("../services");
|
|
6
|
+
const utils_1 = require("@medusajs/utils");
|
|
6
7
|
const awilix_1 = require("awilix");
|
|
8
|
+
const utils_2 = require("../utils");
|
|
7
9
|
function containerLoader(entity, joinerConfig) {
|
|
8
10
|
return async ({ options, container, }, moduleDeclaration) => {
|
|
9
11
|
const [primary, foreign] = joinerConfig.relationships;
|
|
12
|
+
const serviceName = !joinerConfig.isReadOnlyLink
|
|
13
|
+
? (0, utils_1.lowerCaseFirst)(joinerConfig.serviceName ??
|
|
14
|
+
(0, utils_2.composeLinkName)(primary.serviceName, primary.foreignKey, foreign.serviceName, foreign.foreignKey))
|
|
15
|
+
: (0, utils_1.simpleHash)(JSON.stringify(joinerConfig.extends));
|
|
16
|
+
const entityName = (0, utils_1.toPascalCase)("Link_" +
|
|
17
|
+
(joinerConfig.databaseConfig?.tableName ??
|
|
18
|
+
(0, utils_2.composeTableName)(primary.serviceName, primary.foreignKey, foreign.serviceName, foreign.foreignKey)));
|
|
10
19
|
container.register({
|
|
11
20
|
joinerConfig: (0, awilix_1.asValue)(joinerConfig),
|
|
12
21
|
primaryKey: (0, awilix_1.asValue)(primary.foreignKey.split(",")),
|
|
@@ -16,6 +25,8 @@ function containerLoader(entity, joinerConfig) {
|
|
|
16
25
|
linkService: (0, awilix_1.asClass)(_services_1.LinkService).singleton(),
|
|
17
26
|
baseRepository: (0, awilix_1.asClass)(_repositories_1.BaseRepository).singleton(),
|
|
18
27
|
linkRepository: (0, awilix_1.asClass)((0, _repositories_1.getLinkRepository)(entity)).singleton(),
|
|
28
|
+
entityName: (0, awilix_1.asValue)(entityName),
|
|
29
|
+
serviceName: (0, awilix_1.asValue)(serviceName),
|
|
19
30
|
});
|
|
20
31
|
};
|
|
21
32
|
}
|
|
@@ -7,22 +7,25 @@ export declare function getLinkRepository(model: EntitySchema): {
|
|
|
7
7
|
readonly joinerConfig_: ModuleJoinerConfig;
|
|
8
8
|
delete(data: any, context?: Context): Promise<void>;
|
|
9
9
|
create(data: object[], context?: Context): Promise<object[]>;
|
|
10
|
-
update(data:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
update(data: {
|
|
11
|
+
entity: any;
|
|
12
|
+
update: any;
|
|
13
|
+
}[], context?: Context | undefined): Promise<object[]>;
|
|
14
|
+
find(options?: import("@medusajs/types").FindOptions<object> | undefined, context?: Context | undefined): Promise<object[]>;
|
|
15
|
+
findAndCount(options?: import("@medusajs/types").FindOptions<object> | undefined, context?: Context | undefined): Promise<[object[], number]>;
|
|
16
|
+
upsert(data: unknown[], context?: Context | undefined): Promise<object[]>;
|
|
14
17
|
softDelete(idsOrFilter: string[] | {
|
|
15
18
|
[x: string]: any;
|
|
16
|
-
},
|
|
19
|
+
}, sharedContext?: Context | undefined): Promise<[object[], Record<string, unknown[]>]>;
|
|
17
20
|
restore(idsOrFilter: string[] | {
|
|
18
21
|
[x: string]: any;
|
|
19
|
-
},
|
|
22
|
+
}, sharedContext?: Context | undefined): Promise<[object[], Record<string, unknown[]>]>;
|
|
20
23
|
applyFreeTextSearchFilters<T>(findOptions: import("@medusajs/types").FindOptions<T & {
|
|
21
24
|
q?: string | undefined;
|
|
22
25
|
}>, retrieveConstraintsToApply: (q: string) => any[]): void;
|
|
23
26
|
readonly manager_: any;
|
|
24
27
|
getFreshManager<TManager = unknown>(): TManager;
|
|
25
|
-
getActiveManager<TManager_1 = unknown>({ transactionManager, manager }?: Context | undefined): TManager_1;
|
|
28
|
+
getActiveManager<TManager_1 = unknown>({ transactionManager, manager, }?: Context | undefined): TManager_1;
|
|
26
29
|
transaction<TManager_2 = unknown>(task: (transactionManager: TManager_2) => Promise<any>, options?: {
|
|
27
30
|
isolationLevel?: string | undefined;
|
|
28
31
|
enableNestedTransactions?: boolean | undefined;
|
|
@@ -30,6 +33,4 @@ export declare function getLinkRepository(model: EntitySchema): {
|
|
|
30
33
|
} | undefined): Promise<any>;
|
|
31
34
|
serialize<TOutput extends object | object[]>(data: any, options?: any): Promise<TOutput>;
|
|
32
35
|
};
|
|
33
|
-
buildUniqueCompositeKeyValue(keys: string[], data: object): string;
|
|
34
|
-
retrievePrimaryKeys(entity: EntitySchema<any, never> | import("@mikro-orm/core").EntityClass<any>): string[];
|
|
35
36
|
};
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import { Context, DAL, FindConfig, ILinkModule, InternalModuleDeclaration, ModuleJoinerConfig, RestoreReturn, SoftDeleteReturn } from "@medusajs/types";
|
|
1
|
+
import { Context, DAL, FindConfig, IEventBusModuleService, ILinkModule, InternalModuleDeclaration, ModuleJoinerConfig, RestoreReturn, SoftDeleteReturn } from "@medusajs/types";
|
|
2
2
|
import { LinkService } from ".";
|
|
3
3
|
type InjectedDependencies = {
|
|
4
4
|
baseRepository: DAL.RepositoryService;
|
|
5
5
|
linkService: LinkService<any>;
|
|
6
|
+
eventBusModuleService?: IEventBusModuleService;
|
|
6
7
|
primaryKey: string | string[];
|
|
7
8
|
foreignKey: string;
|
|
8
9
|
extraFields: string[];
|
|
10
|
+
entityName: string;
|
|
11
|
+
serviceName: string;
|
|
9
12
|
};
|
|
10
13
|
export default class LinkModuleService<TLink> implements ILinkModule {
|
|
11
14
|
readonly moduleDeclaration: InternalModuleDeclaration;
|
|
12
15
|
protected baseRepository_: DAL.RepositoryService;
|
|
13
16
|
protected readonly linkService_: LinkService<TLink>;
|
|
17
|
+
protected readonly eventBusModuleService_?: IEventBusModuleService;
|
|
18
|
+
protected readonly entityName_: string;
|
|
19
|
+
protected readonly serviceName_: string;
|
|
14
20
|
protected primaryKey_: string[];
|
|
15
21
|
protected foreignKey_: string;
|
|
16
22
|
protected extraFields_: string[];
|
|
17
|
-
constructor({ baseRepository, linkService, primaryKey, foreignKey, extraFields, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
23
|
+
constructor({ baseRepository, linkService, eventBusModuleService, primaryKey, foreignKey, extraFields, entityName, serviceName, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
18
24
|
__joinerConfig(): ModuleJoinerConfig;
|
|
19
25
|
private buildData;
|
|
20
26
|
private isValidKeyName;
|
|
@@ -26,8 +32,8 @@ export default class LinkModuleService<TLink> implements ILinkModule {
|
|
|
26
32
|
dismiss(primaryKeyOrBulkData: string | string[] | [string | string[], string][], foreignKeyData?: string, sharedContext?: Context): Promise<object[]>;
|
|
27
33
|
delete(data: any, sharedContext?: Context): Promise<void>;
|
|
28
34
|
softDelete(data: any, { returnLinkableKeys }?: SoftDeleteReturn, sharedContext?: Context): Promise<Record<string, unknown[]> | void>;
|
|
29
|
-
protected softDelete_(data: any, sharedContext?: Context): Promise<[
|
|
35
|
+
protected softDelete_(data: any, sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
|
|
30
36
|
restore(data: any, { returnLinkableKeys }?: RestoreReturn, sharedContext?: Context): Promise<Record<string, unknown[]> | void>;
|
|
31
|
-
restore_(data: any, sharedContext?: Context): Promise<[
|
|
37
|
+
restore_(data: any, sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
|
|
32
38
|
}
|
|
33
39
|
export {};
|
|
@@ -15,13 +15,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const utils_1 = require("@medusajs/utils");
|
|
16
16
|
const utils_2 = require("../utils");
|
|
17
17
|
class LinkModuleService {
|
|
18
|
-
constructor({ baseRepository, linkService, primaryKey, foreignKey, extraFields, }, moduleDeclaration) {
|
|
18
|
+
constructor({ baseRepository, linkService, eventBusModuleService, primaryKey, foreignKey, extraFields, entityName, serviceName, }, moduleDeclaration) {
|
|
19
19
|
this.moduleDeclaration = moduleDeclaration;
|
|
20
20
|
this.baseRepository_ = baseRepository;
|
|
21
21
|
this.linkService_ = linkService;
|
|
22
|
+
this.eventBusModuleService_ = eventBusModuleService;
|
|
22
23
|
this.primaryKey_ = !Array.isArray(primaryKey) ? [primaryKey] : primaryKey;
|
|
23
24
|
this.foreignKey_ = foreignKey;
|
|
24
25
|
this.extraFields_ = extraFields;
|
|
26
|
+
this.entityName_ = entityName;
|
|
27
|
+
this.serviceName_ = serviceName;
|
|
25
28
|
}
|
|
26
29
|
__joinerConfig() {
|
|
27
30
|
return {};
|
|
@@ -85,6 +88,18 @@ class LinkModuleService {
|
|
|
85
88
|
data.push(this.buildData(primaryKeyOrBulkData, foreignKeyData, extraFields));
|
|
86
89
|
}
|
|
87
90
|
const links = await this.linkService_.create(data, sharedContext);
|
|
91
|
+
await this.eventBusModuleService_?.emit(data.map(({ id }) => ({
|
|
92
|
+
eventName: this.entityName_ + "." + utils_1.CommonEvents.ATTACHED,
|
|
93
|
+
body: {
|
|
94
|
+
metadata: {
|
|
95
|
+
service: this.serviceName_,
|
|
96
|
+
action: utils_1.CommonEvents.ATTACHED,
|
|
97
|
+
object: this.entityName_,
|
|
98
|
+
eventGroupId: sharedContext.eventGroupId,
|
|
99
|
+
},
|
|
100
|
+
data: { id },
|
|
101
|
+
},
|
|
102
|
+
})));
|
|
88
103
|
return await this.baseRepository_.serialize(links);
|
|
89
104
|
}
|
|
90
105
|
async dismiss(primaryKeyOrBulkData, foreignKeyData, sharedContext = {}) {
|
|
@@ -103,10 +118,23 @@ class LinkModuleService {
|
|
|
103
118
|
async delete(data, sharedContext = {}) {
|
|
104
119
|
this.validateFields(data);
|
|
105
120
|
await this.linkService_.delete(data, sharedContext);
|
|
121
|
+
const allData = Array.isArray(data) ? data : [data];
|
|
122
|
+
await this.eventBusModuleService_?.emit(allData.map(({ id }) => ({
|
|
123
|
+
eventName: this.entityName_ + "." + utils_1.CommonEvents.DETACHED,
|
|
124
|
+
body: {
|
|
125
|
+
metadata: {
|
|
126
|
+
service: this.serviceName_,
|
|
127
|
+
action: utils_1.CommonEvents.DETACHED,
|
|
128
|
+
object: this.entityName_,
|
|
129
|
+
eventGroupId: sharedContext.eventGroupId,
|
|
130
|
+
},
|
|
131
|
+
data: { id },
|
|
132
|
+
},
|
|
133
|
+
})));
|
|
106
134
|
}
|
|
107
135
|
async softDelete(data, { returnLinkableKeys } = {}, sharedContext = {}) {
|
|
108
136
|
this.validateFields(data);
|
|
109
|
-
let [, cascadedEntitiesMap] = await this.softDelete_(data, sharedContext);
|
|
137
|
+
let [deletedEntities, cascadedEntitiesMap] = await this.softDelete_(data, sharedContext);
|
|
110
138
|
const pk = this.primaryKey_.join(",");
|
|
111
139
|
const entityNameToLinkableKeysMap = {
|
|
112
140
|
LinkModel: [
|
|
@@ -122,6 +150,18 @@ class LinkModuleService {
|
|
|
122
150
|
pick: returnLinkableKeys,
|
|
123
151
|
});
|
|
124
152
|
}
|
|
153
|
+
await this.eventBusModuleService_?.emit(deletedEntities.map(({ id }) => ({
|
|
154
|
+
eventName: this.entityName_ + "." + utils_1.CommonEvents.DETACHED,
|
|
155
|
+
body: {
|
|
156
|
+
metadata: {
|
|
157
|
+
service: this.serviceName_,
|
|
158
|
+
action: utils_1.CommonEvents.DETACHED,
|
|
159
|
+
object: this.entityName_,
|
|
160
|
+
eventGroupId: sharedContext.eventGroupId,
|
|
161
|
+
},
|
|
162
|
+
data: { id },
|
|
163
|
+
},
|
|
164
|
+
})));
|
|
125
165
|
return mappedCascadedEntitiesMap ? mappedCascadedEntitiesMap : void 0;
|
|
126
166
|
}
|
|
127
167
|
async softDelete_(data, sharedContext = {}) {
|
|
@@ -129,7 +169,7 @@ class LinkModuleService {
|
|
|
129
169
|
}
|
|
130
170
|
async restore(data, { returnLinkableKeys } = {}, sharedContext = {}) {
|
|
131
171
|
this.validateFields(data);
|
|
132
|
-
let [, cascadedEntitiesMap] = await this.restore_(data, sharedContext);
|
|
172
|
+
let [restoredEntities, cascadedEntitiesMap] = await this.restore_(data, sharedContext);
|
|
133
173
|
const pk = this.primaryKey_.join(",");
|
|
134
174
|
const entityNameToLinkableKeysMap = {
|
|
135
175
|
LinkModel: [
|
|
@@ -145,6 +185,18 @@ class LinkModuleService {
|
|
|
145
185
|
pick: returnLinkableKeys,
|
|
146
186
|
});
|
|
147
187
|
}
|
|
188
|
+
await this.eventBusModuleService_?.emit(restoredEntities.map(({ id }) => ({
|
|
189
|
+
eventName: this.entityName_ + "." + utils_1.CommonEvents.ATTACHED,
|
|
190
|
+
body: {
|
|
191
|
+
metadata: {
|
|
192
|
+
service: this.serviceName_,
|
|
193
|
+
action: utils_1.CommonEvents.ATTACHED,
|
|
194
|
+
object: this.entityName_,
|
|
195
|
+
eventGroupId: sharedContext.eventGroupId,
|
|
196
|
+
},
|
|
197
|
+
data: { id },
|
|
198
|
+
},
|
|
199
|
+
})));
|
|
148
200
|
return mappedCascadedEntitiesMap ? mappedCascadedEntitiesMap : void 0;
|
|
149
201
|
}
|
|
150
202
|
async restore_(data, sharedContext = {}) {
|
|
@@ -194,6 +246,12 @@ __decorate([
|
|
|
194
246
|
__metadata("design:paramtypes", [Object, Object]),
|
|
195
247
|
__metadata("design:returntype", Promise)
|
|
196
248
|
], LinkModuleService.prototype, "delete", null);
|
|
249
|
+
__decorate([
|
|
250
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
251
|
+
__metadata("design:type", Function),
|
|
252
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
253
|
+
__metadata("design:returntype", Promise)
|
|
254
|
+
], LinkModuleService.prototype, "softDelete", null);
|
|
197
255
|
__decorate([
|
|
198
256
|
(0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
|
|
199
257
|
__param(1, (0, utils_1.MedusaContext)()),
|
|
@@ -201,6 +259,12 @@ __decorate([
|
|
|
201
259
|
__metadata("design:paramtypes", [Object, Object]),
|
|
202
260
|
__metadata("design:returntype", Promise)
|
|
203
261
|
], LinkModuleService.prototype, "softDelete_", null);
|
|
262
|
+
__decorate([
|
|
263
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
264
|
+
__metadata("design:type", Function),
|
|
265
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
266
|
+
__metadata("design:returntype", Promise)
|
|
267
|
+
], LinkModuleService.prototype, "restore", null);
|
|
204
268
|
__decorate([
|
|
205
269
|
(0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
|
|
206
270
|
__param(1, (0, utils_1.MedusaContext)()),
|
package/dist/services/link.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default class LinkService<TEntity> {
|
|
|
10
10
|
create(data: unknown[], sharedContext?: Context): Promise<TEntity[]>;
|
|
11
11
|
dismiss(data: unknown[], sharedContext?: Context): Promise<TEntity[]>;
|
|
12
12
|
delete(data: unknown, sharedContext?: Context): Promise<void>;
|
|
13
|
-
softDelete(data: any, sharedContext?: Context): Promise<[
|
|
14
|
-
restore(data: any, sharedContext?: Context): Promise<[
|
|
13
|
+
softDelete(data: any, sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
|
|
14
|
+
restore(data: any, sharedContext?: Context): Promise<[object[], Record<string, string[]>]>;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/link-modules",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8-next-20240208080225",
|
|
4
4
|
"description": "Medusa Default Link Modules Package and Definitions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"typescript": "^5.1.6"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@medusajs/modules-sdk": "
|
|
43
|
-
"@medusajs/types": "
|
|
44
|
-
"@medusajs/utils": "
|
|
42
|
+
"@medusajs/modules-sdk": "1.12.8-next-20240208080225",
|
|
43
|
+
"@medusajs/types": "1.11.12-next-20240208080225",
|
|
44
|
+
"@medusajs/utils": "1.11.5-next-20240208080225",
|
|
45
45
|
"@mikro-orm/core": "5.9.7",
|
|
46
46
|
"@mikro-orm/postgresql": "5.9.7",
|
|
47
47
|
"awilix": "^8.0.0"
|