@modern-js/types 2.42.2 → 2.43.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/server/utils.d.ts +58 -0
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.42.2",
18
+ "version": "2.43.0",
19
19
  "types": "./index.d.ts",
20
20
  "exports": {
21
21
  ".": {
@@ -45,8 +45,8 @@
45
45
  "http-proxy-middleware": "^2.0.4",
46
46
  "jest": "^29",
47
47
  "type-fest": "2.15.0",
48
- "@scripts/build": "2.42.2",
49
- "@scripts/jest-config": "2.42.2"
48
+ "@scripts/build": "2.43.0",
49
+ "@scripts/jest-config": "2.43.0"
50
50
  },
51
51
  "sideEffects": false,
52
52
  "publishConfig": {
package/server/utils.d.ts CHANGED
@@ -72,3 +72,61 @@ export type BffProxyOptions =
72
72
  | Record<string, ProxyDetail>
73
73
  | ProxyDetail[]
74
74
  | ProxyDetail;
75
+
76
+ export type CacheControl = {
77
+ /**
78
+ * The maxAge like http cache-control: max-age.
79
+ *
80
+ * It refers to the cache validation time, measured in (ms).
81
+ */
82
+ maxAge: number;
83
+
84
+ /**
85
+ * The staleWhileRevalidate reference to http header cache-control: stale-while-revalidate.
86
+ *
87
+ * It means that the cache is stale but can still be used directly while asynchronously revalidating it, measured in (ms).
88
+ */
89
+ staleWhileRevalidate: number;
90
+
91
+ /**
92
+ * Specify a custom cache key yourself.
93
+ *
94
+ * The custom key will override the key used by default.
95
+ */
96
+ customKey?: string | ((pathname: string) => string);
97
+ };
98
+
99
+ export type CacheOptionProvider = (
100
+ req: IncomingMessage,
101
+ ) => Promise<CacheControl> | CacheControl;
102
+
103
+ export type CacheOption =
104
+ | false
105
+ | CacheOptionProvider
106
+ | CacheControl
107
+ | Record<string, CacheControl | CacheOptionProvider>;
108
+
109
+ export interface Container<K = string, V = string> {
110
+ /**
111
+ * Returns a specified element from the containter. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Containter.
112
+ * @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
113
+ */
114
+ get: (key: K) => Promise<V | undefined>;
115
+
116
+ /**
117
+ * Adds a new element with a specified key and value to the containter. If an element with the same key already exists, the element will be updated.
118
+ */
119
+ set: (key: K, value: V, options?: { ttl?: number }) => Promise<this>;
120
+
121
+ /**
122
+ * @returns boolean indicating whether an element with the specified key exists or not.
123
+ */
124
+ has: (key: K) => Promise<boolean>;
125
+
126
+ /**
127
+ * @returns true if an element in the containter existed and has been removed, or false if the element does not exist.
128
+ */
129
+ delete: (key: K) => Promise<boolean>;
130
+
131
+ forEach?: (callbackFn: (v: V, k: K, containter: this) => void) => void;
132
+ }