@medusajs/caching 2.10.4-snapshot-20250927182917

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 (42) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +14 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/loaders/hash.d.ts +5 -0
  6. package/dist/loaders/hash.d.ts.map +1 -0
  7. package/dist/loaders/hash.js +9 -0
  8. package/dist/loaders/hash.js.map +1 -0
  9. package/dist/loaders/providers.d.ts +5 -0
  10. package/dist/loaders/providers.d.ts.map +1 -0
  11. package/dist/loaders/providers.js +57 -0
  12. package/dist/loaders/providers.js.map +1 -0
  13. package/dist/providers/memory-cache.d.ts +53 -0
  14. package/dist/providers/memory-cache.d.ts.map +1 -0
  15. package/dist/providers/memory-cache.js +158 -0
  16. package/dist/providers/memory-cache.js.map +1 -0
  17. package/dist/services/cache-module.d.ts +83 -0
  18. package/dist/services/cache-module.d.ts.map +1 -0
  19. package/dist/services/cache-module.js +166 -0
  20. package/dist/services/cache-module.js.map +1 -0
  21. package/dist/services/cache-provider.d.ts +13 -0
  22. package/dist/services/cache-provider.d.ts.map +1 -0
  23. package/dist/services/cache-provider.js +53 -0
  24. package/dist/services/cache-provider.js.map +1 -0
  25. package/dist/services/index.d.ts +3 -0
  26. package/dist/services/index.d.ts.map +1 -0
  27. package/dist/services/index.js +11 -0
  28. package/dist/services/index.js.map +1 -0
  29. package/dist/tsconfig.tsbuildinfo +1 -0
  30. package/dist/types/index.d.ts +49 -0
  31. package/dist/types/index.d.ts.map +1 -0
  32. package/dist/types/index.js +8 -0
  33. package/dist/types/index.js.map +1 -0
  34. package/dist/utils/parser.d.ts +47 -0
  35. package/dist/utils/parser.d.ts.map +1 -0
  36. package/dist/utils/parser.js +189 -0
  37. package/dist/utils/parser.js.map +1 -0
  38. package/dist/utils/strategy.d.ts +17 -0
  39. package/dist/utils/strategy.d.ts.map +1 -0
  40. package/dist/utils/strategy.js +122 -0
  41. package/dist/utils/strategy.js.map +1 -0
  42. package/package.json +49 -0
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CacheProviderService_container, _CacheProviderService_logger;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("@medusajs/framework/utils");
16
+ const types_1 = require("../types");
17
+ class CacheProviderService {
18
+ constructor(container) {
19
+ _CacheProviderService_container.set(this, void 0);
20
+ _CacheProviderService_logger.set(this, void 0);
21
+ __classPrivateFieldSet(this, _CacheProviderService_container, container, "f");
22
+ __classPrivateFieldSet(this, _CacheProviderService_logger, container["logger"]
23
+ ? container.logger
24
+ : console, "f");
25
+ }
26
+ static getRegistrationIdentifier(providerClass) {
27
+ if (!providerClass.identifier) {
28
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_ARGUMENT, `Trying to register a caching provider without an identifier.`);
29
+ }
30
+ return `${providerClass.identifier}`;
31
+ }
32
+ retrieveProvider(providerId) {
33
+ try {
34
+ return __classPrivateFieldGet(this, _CacheProviderService_container, "f")[`${types_1.CachingProviderRegistrationPrefix}${providerId}`];
35
+ }
36
+ catch (err) {
37
+ if (err.name === "AwilixResolutionError") {
38
+ const errMessage = `
39
+ Unable to retrieve the caching provider with id: ${providerId}
40
+ Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`;
41
+ // Log full error for debugging
42
+ __classPrivateFieldGet(this, _CacheProviderService_logger, "f").error(`AwilixResolutionError: ${err.message}`, err);
43
+ throw new Error(errMessage);
44
+ }
45
+ const errMessage = `Unable to retrieve the caching provider with id: ${providerId}, the following error occurred: ${err.message}`;
46
+ __classPrivateFieldGet(this, _CacheProviderService_logger, "f").error(errMessage);
47
+ throw new Error(errMessage);
48
+ }
49
+ }
50
+ }
51
+ _CacheProviderService_container = new WeakMap(), _CacheProviderService_logger = new WeakMap();
52
+ exports.default = CacheProviderService;
53
+ //# sourceMappingURL=cache-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-provider.js","sourceRoot":"","sources":["../../src/services/cache-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,qDAAuD;AACvD,oCAA4D;AAO5D,MAAqB,oBAAoB;IAIvC,YAAY,SAA+B;QAH3C,kDAAgC;QAChC,+CAAe;QAGb,uBAAA,IAAI,mCAAc,SAAS,MAAA,CAAA;QAC3B,uBAAA,IAAI,gCAAW,SAAS,CAAC,QAAQ,CAAC;YAChC,CAAC,CAAC,SAAS,CAAC,MAAM;YAClB,CAAC,CAAE,OAA6B,MAAA,CAAA;IACpC,CAAC;IAED,MAAM,CAAC,yBAAyB,CAC9B,aAAmD;QAEnD,IAAI,CAAE,aAAqB,CAAC,UAAU,EAAE,CAAC;YACvC,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,gBAAgB,EAClC,8DAA8D,CAC/D,CAAA;QACH,CAAC;QACD,OAAO,GAAI,aAAqB,CAAC,UAAU,EAAE,CAAA;IAC/C,CAAC;IAEM,gBAAgB,CAAC,UAAkB;QACxC,IAAI,CAAC;YACH,OAAO,uBAAA,IAAI,uCAAW,CACpB,GAAG,yCAAiC,GAAG,UAAU,EAAE,CACpD,CAAA;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,CAAC,IAAI,KAAK,uBAAuB,EAAE,CAAC;gBACzC,MAAM,UAAU,GAAG;oDACyB,UAAU;qIACuE,CAAA;gBAE7H,+BAA+B;gBAC/B,uBAAA,IAAI,oCAAQ,CAAC,KAAK,CAAC,0BAA0B,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAA;gBAEhE,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;YAC7B,CAAC;YAED,MAAM,UAAU,GAAG,oDAAoD,UAAU,mCAAmC,GAAG,CAAC,OAAO,EAAE,CAAA;YACjI,uBAAA,IAAI,oCAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YAE9B,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;CACF;;kBA9CoB,oBAAoB"}
@@ -0,0 +1,3 @@
1
+ export { default as CachingModuleService } from "./cache-module";
2
+ export { default as CachingProviderService } from "./cache-provider";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CachingProviderService = exports.CachingModuleService = void 0;
7
+ var cache_module_1 = require("./cache-module");
8
+ Object.defineProperty(exports, "CachingModuleService", { enumerable: true, get: function () { return __importDefault(cache_module_1).default; } });
9
+ var cache_provider_1 = require("./cache-provider");
10
+ Object.defineProperty(exports, "CachingProviderService", { enumerable: true, get: function () { return __importDefault(cache_provider_1).default; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAgE;AAAvD,qIAAA,OAAO,OAAwB;AACxC,mDAAoE;AAA3D,yIAAA,OAAO,OAA0B"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/loaders/hash.ts","../src/loaders/providers.ts","../src/providers/memory-cache.ts","../src/services/cache-module.ts","../src/services/cache-provider.ts","../src/services/index.ts","../src/types/index.ts","../src/utils/parser.ts","../src/utils/strategy.ts","../src/utils/__tests__/parser.test.ts"],"version":"5.6.2"}
@@ -0,0 +1,49 @@
1
+ import type { Constructor, ICachingStrategy, IEventBusModuleService, Logger, ModuleProviderExports, ModuleServiceInitializeOptions } from "@medusajs/framework/types";
2
+ import { Modules } from "@medusajs/framework/utils";
3
+ import { default as CacheProviderService, default as CachingProviderService } from "../services/cache-provider";
4
+ export declare const CachingDefaultProvider = "default_provider";
5
+ export declare const CachingIdentifiersRegistrationName = "caching_providers_identifier";
6
+ export declare const CachingProviderRegistrationPrefix = "lp_";
7
+ export type InjectedDependencies = {
8
+ cachingProviderService: CachingProviderService;
9
+ logger?: Logger;
10
+ [CachingDefaultProvider]: string;
11
+ [Modules.EVENT_BUS]: IEventBusModuleService;
12
+ };
13
+ export type ModuleInjectedDependencies = InjectedDependencies & {
14
+ cacheProviderService: CacheProviderService;
15
+ strategy: Constructor<ICachingStrategy>;
16
+ hasher: (data: string) => string;
17
+ };
18
+ export type CachingModuleOptions = Partial<ModuleServiceInitializeOptions> & {
19
+ /**
20
+ * The strategy to be used. Default to the inbuilt default strategy.
21
+ */
22
+ strategy?: ICachingStrategy;
23
+ /**
24
+ * Time to keep data in cache (in seconds)
25
+ */
26
+ ttl?: number;
27
+ /**
28
+ * Providers to be registered
29
+ */
30
+ providers?: {
31
+ /**
32
+ * The module provider to be registered
33
+ */
34
+ resolve: string | ModuleProviderExports;
35
+ /**
36
+ * If the provider is the default
37
+ */
38
+ is_default?: boolean;
39
+ /**
40
+ * The id of the provider
41
+ */
42
+ id: string;
43
+ /**
44
+ * key value pair of the configuration to be passed to the provider constructor
45
+ */
46
+ options?: Record<string, unknown>;
47
+ }[];
48
+ };
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,EACN,qBAAqB,EACrB,8BAA8B,EAC/B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACnD,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,OAAO,IAAI,sBAAsB,EAClC,MAAM,4BAA4B,CAAA;AAEnC,eAAO,MAAM,sBAAsB,qBAAqB,CAAA;AACxD,eAAO,MAAM,kCAAkC,iCAAiC,CAAA;AAEhF,eAAO,MAAM,iCAAiC,QAAQ,CAAA;AAEtD,MAAM,MAAM,oBAAoB,GAAG;IACjC,sBAAsB,EAAE,sBAAsB,CAAA;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAChC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAA;CAC5C,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG,oBAAoB,GAAG;IAC9D,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,QAAQ,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IACvC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,8BAA8B,CAAC,GAAG;IAC3E;;OAEG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE;QACV;;WAEG;QACH,OAAO,EAAE,MAAM,GAAG,qBAAqB,CAAA;QACvC;;WAEG;QACH,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB;;WAEG;QACH,EAAE,EAAE,MAAM,CAAA;QACV;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAClC,EAAE,CAAA;CACJ,CAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CachingProviderRegistrationPrefix = exports.CachingIdentifiersRegistrationName = exports.CachingDefaultProvider = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ exports.CachingDefaultProvider = "default_provider";
6
+ exports.CachingIdentifiersRegistrationName = "caching_providers_identifier";
7
+ exports.CachingProviderRegistrationPrefix = "lp_";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAQA,qDAAmD;AAMtC,QAAA,sBAAsB,GAAG,kBAAkB,CAAA;AAC3C,QAAA,kCAAkC,GAAG,8BAA8B,CAAA;AAEnE,QAAA,iCAAiC,GAAG,KAAK,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { ModuleJoinerConfig } from "@medusajs/framework/types";
2
+ import { GraphQLSchema } from "graphql";
3
+ export interface EntityReference {
4
+ type: string;
5
+ id: string | number;
6
+ field?: string;
7
+ }
8
+ export interface InvalidationEvent {
9
+ entityType: string;
10
+ entityId: string | number;
11
+ relatedEntities: EntityReference[];
12
+ cacheKeys: string[];
13
+ }
14
+ export declare class CacheInvalidationParser {
15
+ private typeMap;
16
+ private idPrefixToEntityName;
17
+ constructor(schema: GraphQLSchema, joinerConfigs: ModuleJoinerConfig[]);
18
+ /**
19
+ * Parse an object to identify entities and their relationships
20
+ */
21
+ parseObjectForEntities(obj: any, parentType?: string): EntityReference[];
22
+ /**
23
+ * Detect entity type based on object structure and GraphQL type map
24
+ */
25
+ private detectEntityType;
26
+ /**
27
+ * Check if object structure matches GraphQL type fields
28
+ */
29
+ private objectMatchesType;
30
+ /**
31
+ * Get the expected type for a relationship field
32
+ */
33
+ private getRelationshipType;
34
+ /**
35
+ * Build invalidation events based on parsed entities
36
+ */
37
+ buildInvalidationEvents(entities: EntityReference[], cacheKey: string, operation?: "created" | "updated" | "deleted"): InvalidationEvent[];
38
+ /**
39
+ * Build list of cache keys that should be invalidated
40
+ */
41
+ private buildAffectedCacheKeys;
42
+ /**
43
+ * Generate event name for cache invalidation
44
+ */
45
+ generateInvalidationEventName(entityType: string, operation?: "created" | "updated" | "deleted"): string;
46
+ }
47
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/utils/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAEL,aAAa,EAId,MAAM,SAAS,CAAA;AAEhB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,eAAe,EAAE,eAAe,EAAE,CAAA;IAClC,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,oBAAoB,CAAwB;gBAExC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE;IAwBtE;;OAEG;IACH,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE;IA0CxE;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA4BxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAczB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAmC3B;;OAEG;IACH,uBAAuB,CACrB,QAAQ,EAAE,eAAe,EAAE,EAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,SAAS,GAAG,SAAS,GAAG,SAAqB,GACvD,iBAAiB,EAAE;IAoCtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA0C9B;;OAEG;IACH,6BAA6B,CAC3B,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,SAAS,GAAG,SAAS,GAAG,SAAqB,GACvD,MAAM;CAGV"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CacheInvalidationParser = void 0;
4
+ const graphql_1 = require("graphql");
5
+ class CacheInvalidationParser {
6
+ constructor(schema, joinerConfigs) {
7
+ this.typeMap = new Map();
8
+ // Build type map for quick lookups
9
+ const schemaTypeMap = schema.getTypeMap();
10
+ Object.keys(schemaTypeMap).forEach((typeName) => {
11
+ const type = schemaTypeMap[typeName];
12
+ if ((0, graphql_1.isObjectType)(type) && !typeName.startsWith("__")) {
13
+ this.typeMap.set(typeName, type);
14
+ }
15
+ });
16
+ this.idPrefixToEntityName = joinerConfigs.reduce((acc, joinerConfig) => {
17
+ if (joinerConfig.idPrefixToEntityName) {
18
+ Object.entries(joinerConfig.idPrefixToEntityName).forEach(([idPrefix, entityName]) => {
19
+ acc[idPrefix] = entityName;
20
+ });
21
+ }
22
+ return acc;
23
+ }, {});
24
+ }
25
+ /**
26
+ * Parse an object to identify entities and their relationships
27
+ */
28
+ parseObjectForEntities(obj, parentType) {
29
+ const entities = [];
30
+ if (!obj || typeof obj !== "object") {
31
+ return entities;
32
+ }
33
+ // Check if this object matches any known GraphQL types
34
+ const detectedType = this.detectEntityType(obj, parentType);
35
+ if (detectedType && obj.id) {
36
+ entities.push({
37
+ type: detectedType,
38
+ id: obj.id,
39
+ });
40
+ }
41
+ // Recursively parse nested objects and arrays
42
+ Object.keys(obj).forEach((key) => {
43
+ const value = obj[key];
44
+ if (Array.isArray(value)) {
45
+ value.forEach((item) => {
46
+ entities.push(...this.parseObjectForEntities(item, this.getRelationshipType(detectedType, key)));
47
+ });
48
+ }
49
+ else if (value && typeof value === "object") {
50
+ entities.push(...this.parseObjectForEntities(value, this.getRelationshipType(detectedType, key)));
51
+ }
52
+ });
53
+ return entities;
54
+ }
55
+ /**
56
+ * Detect entity type based on object structure and GraphQL type map
57
+ */
58
+ detectEntityType(obj, suggestedType) {
59
+ if (obj.id) {
60
+ const idParts = obj.id.split("_");
61
+ if (idParts.length > 1) {
62
+ const idPrefix = idParts[0];
63
+ if (idPrefix && this.idPrefixToEntityName[idPrefix]) {
64
+ return this.idPrefixToEntityName[idPrefix];
65
+ }
66
+ }
67
+ }
68
+ if (suggestedType && this.typeMap.has(suggestedType)) {
69
+ const type = this.typeMap.get(suggestedType);
70
+ if (this.objectMatchesType(obj, type)) {
71
+ return suggestedType;
72
+ }
73
+ }
74
+ // Try to match against all known types
75
+ for (const [typeName, type] of this.typeMap) {
76
+ if (this.objectMatchesType(obj, type)) {
77
+ return typeName;
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+ /**
83
+ * Check if object structure matches GraphQL type fields
84
+ */
85
+ objectMatchesType(obj, type) {
86
+ const fields = type.getFields();
87
+ const objKeys = Object.keys(obj);
88
+ // Must have id field for entities
89
+ if (!obj.id || !fields.id) {
90
+ return false;
91
+ }
92
+ // Check if at least 50% of non-null object fields match type fields
93
+ const matchingFields = objKeys.filter((key) => fields[key]).length;
94
+ return matchingFields >= Math.max(1, objKeys.length * 0.5);
95
+ }
96
+ /**
97
+ * Get the expected type for a relationship field
98
+ */
99
+ getRelationshipType(parentType, fieldName) {
100
+ if (!parentType || !this.typeMap.has(parentType)) {
101
+ return undefined;
102
+ }
103
+ const type = this.typeMap.get(parentType);
104
+ const field = type.getFields()[fieldName];
105
+ if (!field) {
106
+ return undefined;
107
+ }
108
+ let fieldType = field.type;
109
+ // Unwrap NonNull and List wrappers
110
+ if ((0, graphql_1.isNonNullType)(fieldType)) {
111
+ fieldType = fieldType.ofType;
112
+ }
113
+ if ((0, graphql_1.isListType)(fieldType)) {
114
+ fieldType = fieldType.ofType;
115
+ }
116
+ if ((0, graphql_1.isNonNullType)(fieldType)) {
117
+ fieldType = fieldType.ofType;
118
+ }
119
+ if ((0, graphql_1.isObjectType)(fieldType)) {
120
+ return fieldType.name;
121
+ }
122
+ return undefined;
123
+ }
124
+ /**
125
+ * Build invalidation events based on parsed entities
126
+ */
127
+ buildInvalidationEvents(entities, cacheKey, operation = "updated") {
128
+ const events = [];
129
+ const processedEntities = new Set();
130
+ entities.forEach((entity) => {
131
+ const entityKey = `${entity.type}:${entity.id}`;
132
+ if (processedEntities.has(entityKey)) {
133
+ return;
134
+ }
135
+ processedEntities.add(entityKey);
136
+ // Get related entities for this entity type
137
+ const relatedEntities = entities.filter((e) => e.type !== entity.type || e.id !== entity.id);
138
+ // Build cache keys that might be affected
139
+ const affectedKeys = this.buildAffectedCacheKeys(entity, relatedEntities, cacheKey, operation);
140
+ events.push({
141
+ entityType: entity.type,
142
+ entityId: entity.id,
143
+ relatedEntities,
144
+ cacheKeys: affectedKeys,
145
+ });
146
+ });
147
+ return events;
148
+ }
149
+ /**
150
+ * Build list of cache keys that should be invalidated
151
+ */
152
+ buildAffectedCacheKeys(entity, relatedEntities, originalKey, operation = "updated") {
153
+ const keys = new Set([originalKey]);
154
+ // Add keys based on entity type and ID
155
+ keys.add(`${entity.type}:${entity.id}`);
156
+ keys.add(`${entity.type}:*`);
157
+ keys.add(`*:${entity.id}`);
158
+ // Add keys for related entities
159
+ relatedEntities.forEach((related) => {
160
+ keys.add(`${entity.type}:${entity.id}:${related.type}:${related.id}`);
161
+ keys.add(`${related.type}:${related.id}:${entity.type}:${entity.id}`);
162
+ });
163
+ // Always add collection keys since entity changes can impact collections
164
+ keys.add(`${entity.type}:collection`);
165
+ keys.add(`${entity.type}:list:*`);
166
+ // Add operation-specific keys
167
+ keys.add(`${entity.type}:${operation}`);
168
+ keys.add(`${entity.type}:${entity.id}:${operation}`);
169
+ // For delete operations, also invalidate existence checks
170
+ if (operation === "deleted") {
171
+ keys.add(`${entity.type}:exists:${entity.id}`);
172
+ keys.add(`${entity.type}:active:*`);
173
+ }
174
+ // For create operations, invalidate count caches
175
+ if (operation === "created") {
176
+ keys.add(`${entity.type}:count`);
177
+ keys.add(`${entity.type}:total:*`);
178
+ }
179
+ return Array.from(keys);
180
+ }
181
+ /**
182
+ * Generate event name for cache invalidation
183
+ */
184
+ generateInvalidationEventName(entityType, operation = "updated") {
185
+ return `cache.invalidate.${entityType}.${operation}`;
186
+ }
187
+ }
188
+ exports.CacheInvalidationParser = CacheInvalidationParser;
189
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/utils/parser.ts"],"names":[],"mappings":";;;AACA,qCAMgB;AAehB,MAAa,uBAAuB;IAIlC,YAAY,MAAqB,EAAE,aAAmC;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAA;QAExB,mCAAmC;QACnC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;QACzC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;YACpC,IAAI,IAAA,sBAAY,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU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CAAC,IAAI,SAAS,CAAC,CAAA;QAEjC,8BAA8B;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAA;QACvC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,SAAS,EAAE,CAAC,CAAA;QAEpD,0DAA0D;QAC1D,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,WAAW,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;YAC9C,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,WAAW,CAAC,CAAA;QACrC,CAAC;QAED,iDAAiD;QACjD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,CAAA;YAChC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,UAAU,CAAC,CAAA;QACpC,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED;;OAEG;IACH,6BAA6B,CAC3B,UAAkB,EAClB,YAA+C,SAAS;QAExD,OAAO,oBAAoB,UAAU,IAAI,SAAS,EAAE,CAAA;IACtD,CAAC;CACF;AAhQD,0DAgQC"}
@@ -0,0 +1,17 @@
1
+ import type { ICachingStrategy, ModuleJoinerConfig } from "@medusajs/framework/types";
2
+ import { type GraphQLSchema } from "@medusajs/framework/utils";
3
+ import { type CachingModuleService } from "../services";
4
+ import type { ModuleInjectedDependencies } from "../types";
5
+ import { EntityReference } from "./parser";
6
+ export declare class DefaultCacheStrategy implements ICachingStrategy {
7
+ #private;
8
+ constructor(container: ModuleInjectedDependencies, cacheModule: CachingModuleService);
9
+ objectHash(input: any): string;
10
+ onApplicationStart(schema: GraphQLSchema, joinerConfigs: ModuleJoinerConfig[]): Promise<void>;
11
+ computeKey(input: object): Promise<string>;
12
+ computeTags(input: object, options?: {
13
+ entities?: EntityReference[];
14
+ operation?: "created" | "updated" | "deleted";
15
+ }): Promise<string[]>;
16
+ }
17
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/utils/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AAExD,OAAO,EAA2B,eAAe,EAAE,MAAM,UAAU,CAAA;AAEnE,qBAAa,oBAAqB,YAAW,gBAAgB;;gBAOzD,SAAS,EAAE,0BAA0B,EACrC,WAAW,EAAE,oBAAoB;IAOnC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM;IAKxB,kBAAkB,CACtB,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,kBAAkB,EAAE;IA4E/B,UAAU,CAAC,KAAK,EAAE,MAAM;IAIxB,WAAW,CACf,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;QAC5B,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;KAC9C,GACA,OAAO,CAAC,MAAM,EAAE,CAAC;CAiCrB"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _DefaultCacheStrategy_cacheInvalidationParser, _DefaultCacheStrategy_cacheModule, _DefaultCacheStrategy_container, _DefaultCacheStrategy_hasher;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DefaultCacheStrategy = void 0;
19
+ const utils_1 = require("@medusajs/framework/utils");
20
+ const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
21
+ const parser_1 = require("./parser");
22
+ class DefaultCacheStrategy {
23
+ constructor(container, cacheModule) {
24
+ _DefaultCacheStrategy_cacheInvalidationParser.set(this, void 0);
25
+ _DefaultCacheStrategy_cacheModule.set(this, void 0);
26
+ _DefaultCacheStrategy_container.set(this, void 0);
27
+ _DefaultCacheStrategy_hasher.set(this, void 0);
28
+ __classPrivateFieldSet(this, _DefaultCacheStrategy_cacheModule, cacheModule, "f");
29
+ __classPrivateFieldSet(this, _DefaultCacheStrategy_container, container, "f");
30
+ __classPrivateFieldSet(this, _DefaultCacheStrategy_hasher, container.hasher, "f");
31
+ }
32
+ objectHash(input) {
33
+ const str = (0, fast_json_stable_stringify_1.default)(input);
34
+ return __classPrivateFieldGet(this, _DefaultCacheStrategy_hasher, "f").call(this, str);
35
+ }
36
+ async onApplicationStart(schema, joinerConfigs) {
37
+ __classPrivateFieldSet(this, _DefaultCacheStrategy_cacheInvalidationParser, new parser_1.CacheInvalidationParser(schema, joinerConfigs), "f");
38
+ const eventBus = __classPrivateFieldGet(this, _DefaultCacheStrategy_container, "f")[utils_1.Modules.EVENT_BUS];
39
+ eventBus.subscribe("*", async (data) => {
40
+ try {
41
+ // We dont have to await anything here and the rest can be done in the background
42
+ return;
43
+ }
44
+ finally {
45
+ const eventName = data.name;
46
+ const operation = eventName.split(".").pop();
47
+ const entityType = eventName.split(".").slice(-2).shift();
48
+ const eventData = data.data;
49
+ // We expect event data to be either { id: string | string[] } or { id: string | string[] }[]
50
+ if (Array.isArray(eventData)) {
51
+ for (const item of eventData) {
52
+ const ids = Array.isArray(item.id) ? item.id : [item.id];
53
+ const tags = [];
54
+ for (const id of ids) {
55
+ const entityReference = {
56
+ type: (0, utils_1.upperCaseFirst)((0, utils_1.toCamelCase)(entityType)),
57
+ id,
58
+ };
59
+ const tags_ = await this.computeTags(item, {
60
+ entities: [entityReference],
61
+ operation,
62
+ });
63
+ tags.push(...tags_);
64
+ }
65
+ await __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheModule, "f").clear({
66
+ tags,
67
+ options: { autoInvalidate: true },
68
+ });
69
+ }
70
+ }
71
+ else {
72
+ const ids = Array.isArray(eventData.id)
73
+ ? eventData.id
74
+ : [eventData.id];
75
+ const tags = [];
76
+ for (const id of ids) {
77
+ const entityReference = {
78
+ type: (0, utils_1.upperCaseFirst)((0, utils_1.toCamelCase)(entityType)),
79
+ id,
80
+ };
81
+ const tags_ = await this.computeTags(eventData, {
82
+ entities: [entityReference],
83
+ operation,
84
+ });
85
+ tags.push(...tags_);
86
+ }
87
+ await __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheModule, "f").clear({
88
+ tags,
89
+ options: { autoInvalidate: true },
90
+ });
91
+ }
92
+ }
93
+ });
94
+ }
95
+ async computeKey(input) {
96
+ return this.objectHash(input);
97
+ }
98
+ async computeTags(input, options) {
99
+ // Parse the input object to identify entities
100
+ const entities_ = options?.entities ||
101
+ __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheInvalidationParser, "f").parseObjectForEntities(input);
102
+ if (entities_.length === 0) {
103
+ return [];
104
+ }
105
+ // Generate cache key for this input
106
+ const cacheKey = await this.computeKey(input);
107
+ // Build invalidation events to get comprehensive cache keys
108
+ const events = __classPrivateFieldGet(this, _DefaultCacheStrategy_cacheInvalidationParser, "f").buildInvalidationEvents(entities_, cacheKey, options?.operation);
109
+ // Collect all unique cache keys from all events as tags
110
+ const tags = new Set();
111
+ events.forEach((event) => {
112
+ event.cacheKeys.forEach((key) => tags.add(key));
113
+ // Also add entity-specific tags
114
+ tags.add(`${event.entityType}:${event.entityId}`);
115
+ tags.add(`${event.entityType}:list:*`);
116
+ });
117
+ return Array.from(tags);
118
+ }
119
+ }
120
+ exports.DefaultCacheStrategy = DefaultCacheStrategy;
121
+ _DefaultCacheStrategy_cacheInvalidationParser = new WeakMap(), _DefaultCacheStrategy_cacheModule = new WeakMap(), _DefaultCacheStrategy_container = new WeakMap(), _DefaultCacheStrategy_hasher = new WeakMap();
122
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/utils/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,qDAKkC;AAGlC,4FAAkD;AAClD,qCAAmE;AAEnE,MAAa,oBAAoB;IAM/B,YACE,SAAqC,EACrC,WAAiC;QAPnC,gEAAiD;QACjD,oDAAmC;QACnC,kDAAsC;QACtC,+CAAiC;QAM/B,uBAAA,IAAI,qCAAgB,WAAW,MAAA,CAAA;QAC/B,uBAAA,IAAI,mCAAc,SAAS,MAAA,CAAA;QAC3B,uBAAA,IAAI,gCAAW,SAAS,CAAC,MAAM,MAAA,CAAA;IACjC,CAAC;IAED,UAAU,CAAC,KAAU;QACnB,MAAM,GAAG,GAAG,IAAA,oCAAS,EAAC,KAAK,CAAC,CAAA;QAC5B,OA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CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,KAAK,CAAC,WAAW,CACf,KAAa,EACb,OAGC;QAED,8CAA8C;QAC9C,MAAM,SAAS,GACb,OAAO,EAAE,QAAQ;YACjB,uBAAA,IAAI,qDAAyB,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;QAE7D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,oCAAoC;QACpC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAE7C,4DAA4D;QAC5D,MAAM,MAAM,GAAG,uBAAA,IAAI,qDAAyB,CAAC,uBAAuB,CAClE,SAAS,EACT,QAAQ,EACR,OAAO,EAAE,SAAS,CACnB,CAAA;QAED,wDAAwD;QACxD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;QAE9B,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;YAE/C,gCAAgC;YAChC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;YACjD,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,UAAU,SAAS,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF;AA7ID,oDA6IC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@medusajs/caching",
3
+ "version": "2.10.4-snapshot-20250927182917",
4
+ "description": "Caching Module for Medusa",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/medusajs/medusa",
9
+ "directory": "packages/modules/caching"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "!dist/**/__tests__",
14
+ "!dist/**/__mocks__",
15
+ "!dist/**/__fixtures__"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "author": "Medusa",
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "watch": "tsc --build --watch",
24
+ "watch:test": "tsc --build tsconfig.spec.json --watch",
25
+ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",
26
+ "build": "rimraf dist && tsc --build && npm run resolve:aliases",
27
+ "test": "jest --passWithNoTests --runInBand --bail --forceExit -- src/",
28
+ "test:integration": "jest --runInBand --forceExit -- integration-tests/__tests__/**/*.ts"
29
+ },
30
+ "devDependencies": {
31
+ "@medusajs/framework": "2.10.4-snapshot-20250927182917",
32
+ "@medusajs/test-utils": "2.10.4-snapshot-20250927182917",
33
+ "@swc/core": "^1.7.28",
34
+ "@swc/jest": "^0.2.36",
35
+ "jest": "^29.7.0",
36
+ "rimraf": "^3.0.2",
37
+ "tsc-alias": "^1.8.6",
38
+ "typescript": "^5.6.2"
39
+ },
40
+ "peerDependencies": {
41
+ "@medusajs/framework": "2.10.4-snapshot-20250927182917",
42
+ "awilix": "^8.0.1"
43
+ },
44
+ "dependencies": {
45
+ "fast-json-stable-stringify": "^2.1.0",
46
+ "node-cache": "^5.1.2",
47
+ "xxhash-wasm": "^1.1.0"
48
+ }
49
+ }