@spoosh/plugin-invalidation 0.5.1 → 0.5.2

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.js CHANGED
@@ -25,39 +25,27 @@ __export(src_exports, {
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
27
  // src/plugin.ts
28
- var import_core = require("@spoosh/core");
29
28
  var INVALIDATION_DEFAULT_KEY = "invalidation:defaultMode";
30
- function resolveModeTags(context, mode, stripTagPrefix) {
29
+ function resolveModeTags(context, mode) {
31
30
  switch (mode) {
32
31
  case "all":
33
- if (stripTagPrefix) {
34
- return context.tags.map((tag) => {
35
- const segments = tag.split("/").filter(Boolean);
36
- return (0, import_core.stripPrefixFromPath)(segments, stripTagPrefix).join("/");
37
- });
38
- }
39
32
  return context.tags;
40
- case "self": {
41
- const selfPath = context.path.join("/");
42
- if (stripTagPrefix) {
43
- return [(0, import_core.stripPrefixFromPath)(context.path, stripTagPrefix).join("/")];
44
- }
45
- return [selfPath];
46
- }
33
+ case "self":
34
+ return [context.path.join("/")];
47
35
  case "none":
48
36
  return [];
49
37
  }
50
38
  }
51
- function resolveInvalidateTags(context, defaultMode, stripTagPrefix) {
39
+ function resolveInvalidateTags(context, defaultMode) {
52
40
  const pluginOptions = context.pluginOptions;
53
41
  const invalidateOption = pluginOptions?.invalidate;
54
42
  if (!invalidateOption) {
55
43
  const overrideDefault = context.metadata.get(INVALIDATION_DEFAULT_KEY);
56
44
  const effectiveDefault = overrideDefault ?? defaultMode;
57
- return resolveModeTags(context, effectiveDefault, stripTagPrefix);
45
+ return resolveModeTags(context, effectiveDefault);
58
46
  }
59
47
  if (typeof invalidateOption === "string") {
60
- return resolveModeTags(context, invalidateOption, stripTagPrefix);
48
+ return resolveModeTags(context, invalidateOption);
61
49
  }
62
50
  if (Array.isArray(invalidateOption)) {
63
51
  const tags = [];
@@ -66,15 +54,10 @@ function resolveInvalidateTags(context, defaultMode, stripTagPrefix) {
66
54
  if (item === "all" || item === "self") {
67
55
  mode = item;
68
56
  } else if (typeof item === "string") {
69
- if (stripTagPrefix) {
70
- const segments = item.split("/").filter(Boolean);
71
- tags.push((0, import_core.stripPrefixFromPath)(segments, stripTagPrefix).join("/"));
72
- } else {
73
- tags.push(item);
74
- }
57
+ tags.push(item);
75
58
  }
76
59
  }
77
- tags.push(...resolveModeTags(context, mode, stripTagPrefix));
60
+ tags.push(...resolveModeTags(context, mode));
78
61
  return [...new Set(tags)];
79
62
  }
80
63
  return [];
@@ -93,11 +76,7 @@ function invalidationPlugin(config = {}) {
93
76
  },
94
77
  afterResponse(context, response) {
95
78
  if (!response.error) {
96
- const tags = resolveInvalidateTags(
97
- context,
98
- defaultMode,
99
- context.stripTagPrefix
100
- );
79
+ const tags = resolveInvalidateTags(context, defaultMode);
101
80
  if (tags.length > 0) {
102
81
  context.stateManager.markStale(tags);
103
82
  context.eventEmitter.emit("invalidate", tags);
package/dist/index.mjs CHANGED
@@ -1,39 +1,25 @@
1
1
  // src/plugin.ts
2
- import {
3
- stripPrefixFromPath
4
- } from "@spoosh/core";
5
2
  var INVALIDATION_DEFAULT_KEY = "invalidation:defaultMode";
6
- function resolveModeTags(context, mode, stripTagPrefix) {
3
+ function resolveModeTags(context, mode) {
7
4
  switch (mode) {
8
5
  case "all":
9
- if (stripTagPrefix) {
10
- return context.tags.map((tag) => {
11
- const segments = tag.split("/").filter(Boolean);
12
- return stripPrefixFromPath(segments, stripTagPrefix).join("/");
13
- });
14
- }
15
6
  return context.tags;
16
- case "self": {
17
- const selfPath = context.path.join("/");
18
- if (stripTagPrefix) {
19
- return [stripPrefixFromPath(context.path, stripTagPrefix).join("/")];
20
- }
21
- return [selfPath];
22
- }
7
+ case "self":
8
+ return [context.path.join("/")];
23
9
  case "none":
24
10
  return [];
25
11
  }
26
12
  }
27
- function resolveInvalidateTags(context, defaultMode, stripTagPrefix) {
13
+ function resolveInvalidateTags(context, defaultMode) {
28
14
  const pluginOptions = context.pluginOptions;
29
15
  const invalidateOption = pluginOptions?.invalidate;
30
16
  if (!invalidateOption) {
31
17
  const overrideDefault = context.metadata.get(INVALIDATION_DEFAULT_KEY);
32
18
  const effectiveDefault = overrideDefault ?? defaultMode;
33
- return resolveModeTags(context, effectiveDefault, stripTagPrefix);
19
+ return resolveModeTags(context, effectiveDefault);
34
20
  }
35
21
  if (typeof invalidateOption === "string") {
36
- return resolveModeTags(context, invalidateOption, stripTagPrefix);
22
+ return resolveModeTags(context, invalidateOption);
37
23
  }
38
24
  if (Array.isArray(invalidateOption)) {
39
25
  const tags = [];
@@ -42,15 +28,10 @@ function resolveInvalidateTags(context, defaultMode, stripTagPrefix) {
42
28
  if (item === "all" || item === "self") {
43
29
  mode = item;
44
30
  } else if (typeof item === "string") {
45
- if (stripTagPrefix) {
46
- const segments = item.split("/").filter(Boolean);
47
- tags.push(stripPrefixFromPath(segments, stripTagPrefix).join("/"));
48
- } else {
49
- tags.push(item);
50
- }
31
+ tags.push(item);
51
32
  }
52
33
  }
53
- tags.push(...resolveModeTags(context, mode, stripTagPrefix));
34
+ tags.push(...resolveModeTags(context, mode));
54
35
  return [...new Set(tags)];
55
36
  }
56
37
  return [];
@@ -69,11 +50,7 @@ function invalidationPlugin(config = {}) {
69
50
  },
70
51
  afterResponse(context, response) {
71
52
  if (!response.error) {
72
- const tags = resolveInvalidateTags(
73
- context,
74
- defaultMode,
75
- context.stripTagPrefix
76
- );
53
+ const tags = resolveInvalidateTags(context, defaultMode);
77
54
  if (tags.length > 0) {
78
55
  context.stateManager.markStale(tags);
79
56
  context.eventEmitter.emit("invalidate", tags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/plugin-invalidation",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Cache invalidation plugin for Spoosh - auto-invalidates after mutations",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,10 +33,10 @@
33
33
  }
34
34
  },
35
35
  "peerDependencies": {
36
- "@spoosh/core": ">=0.9.1"
36
+ "@spoosh/core": ">=0.8.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@spoosh/core": "0.9.1",
39
+ "@spoosh/core": "0.9.2",
40
40
  "@spoosh/test-utils": "0.1.5"
41
41
  },
42
42
  "scripts": {