memx 0.0.7 → 0.1.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 (78) hide show
  1. package/dist/buffers.cjs +50 -0
  2. package/dist/buffers.cjs.map +6 -0
  3. package/dist/buffers.d.ts +14 -0
  4. package/dist/buffers.mjs +25 -0
  5. package/dist/buffers.mjs.map +6 -0
  6. package/dist/client.cjs +251 -0
  7. package/dist/client.cjs.map +6 -0
  8. package/dist/client.d.ts +76 -0
  9. package/dist/client.mjs +216 -0
  10. package/dist/client.mjs.map +6 -0
  11. package/dist/cluster.cjs +147 -0
  12. package/dist/cluster.cjs.map +6 -0
  13. package/dist/cluster.d.ts +60 -0
  14. package/dist/cluster.mjs +112 -0
  15. package/dist/cluster.mjs.map +6 -0
  16. package/dist/connection.cjs +186 -0
  17. package/dist/connection.cjs.map +6 -0
  18. package/dist/connection.d.ts +18 -0
  19. package/dist/connection.mjs +151 -0
  20. package/dist/connection.mjs.map +6 -0
  21. package/dist/constants.cjs +140 -0
  22. package/dist/constants.cjs.map +6 -0
  23. package/dist/constants.d.ts +87 -0
  24. package/dist/constants.mjs +107 -0
  25. package/dist/constants.mjs.map +6 -0
  26. package/dist/decode.cjs +101 -0
  27. package/dist/decode.cjs.map +6 -0
  28. package/dist/decode.d.ts +16 -0
  29. package/dist/decode.mjs +66 -0
  30. package/dist/decode.mjs.map +6 -0
  31. package/dist/encode.cjs +70 -0
  32. package/dist/encode.cjs.map +6 -0
  33. package/dist/encode.d.ts +20 -0
  34. package/dist/encode.mjs +45 -0
  35. package/dist/encode.mjs.map +6 -0
  36. package/dist/fake.cjs +183 -0
  37. package/dist/fake.cjs.map +6 -0
  38. package/dist/fake.d.ts +53 -0
  39. package/dist/fake.mjs +157 -0
  40. package/dist/fake.mjs.map +6 -0
  41. package/dist/index.cjs +57 -0
  42. package/dist/index.cjs.map +6 -0
  43. package/dist/index.d.ts +12 -0
  44. package/dist/index.mjs +15 -1460
  45. package/dist/index.mjs.map +2 -2
  46. package/dist/internals.cjs +58 -0
  47. package/dist/internals.cjs.map +6 -0
  48. package/dist/internals.d.ts +7 -0
  49. package/dist/internals.mjs +21 -0
  50. package/dist/internals.mjs.map +6 -0
  51. package/dist/server.cjs +468 -0
  52. package/dist/server.cjs.map +6 -0
  53. package/dist/server.d.ts +59 -0
  54. package/dist/server.mjs +443 -0
  55. package/dist/server.mjs.map +6 -0
  56. package/dist/types.cjs +19 -0
  57. package/dist/types.cjs.map +6 -0
  58. package/dist/types.d.ts +239 -0
  59. package/dist/types.mjs +1 -0
  60. package/dist/types.mjs.map +6 -0
  61. package/dist/utils.cjs +182 -0
  62. package/dist/utils.cjs.map +6 -0
  63. package/dist/utils.d.ts +22 -0
  64. package/dist/utils.mjs +145 -0
  65. package/dist/utils.mjs.map +6 -0
  66. package/package.json +29 -27
  67. package/src/client.ts +25 -23
  68. package/src/cluster.ts +6 -3
  69. package/src/connection.ts +8 -4
  70. package/src/decode.ts +5 -2
  71. package/src/encode.ts +5 -2
  72. package/src/fake.ts +34 -33
  73. package/src/internals.ts +7 -7
  74. package/src/server.ts +47 -45
  75. package/src/utils.ts +7 -4
  76. package/dist/index.js +0 -1496
  77. package/dist/index.js.map +0 -6
  78. package/index.d.ts +0 -710
package/package.json CHANGED
@@ -1,48 +1,50 @@
1
1
  {
2
2
  "name": "memx",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "description": "Simple and fast memcached client",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "commonjs",
7
9
  "exports": {
8
10
  ".": {
9
- "import": "./dist/index.mjs",
10
- "require": "./dist/index.js"
11
+ "require": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.mjs"
18
+ }
11
19
  }
12
20
  },
13
- "types": "./index.d.ts",
14
21
  "scripts": {
15
- "build": "./build.sh",
16
- "dev": "nodemon -e ts -x ./build.sh -w src -w test",
17
- "lint": "eslint src test",
18
- "prepare": "patch -N -p0 -i .nyc.patch || true"
22
+ "build": "plug",
23
+ "coverage": "plug coverage",
24
+ "dev": "plug coverage -w src -w test",
25
+ "lint": "plug lint",
26
+ "test": "plug test",
27
+ "transpile": "plug transpile"
19
28
  },
20
29
  "author": "Juit Developers <developers@juit.com>",
21
30
  "license": "Apache-2.0",
22
31
  "devDependencies": {
23
- "@microsoft/api-extractor": "^7.19.5",
24
- "@types/chai": "^4.3.0",
32
+ "@plugjs/build": "^0.2.2",
33
+ "@types/chai": "^4.3.4",
25
34
  "@types/chai-as-promised": "^7.1.5",
26
- "@types/memjs": "^1.2.4",
27
- "@types/mocha": "^9.1.0",
28
- "@types/node": "~16.11.26",
29
- "@types/source-map-support": "^0.5.4",
30
- "@typescript-eslint/eslint-plugin": "^5.17.0",
31
- "@typescript-eslint/parser": "^5.17.0",
32
- "chai": "^4.3.6",
35
+ "@types/memjs": "^1.3.0",
36
+ "chai": "^4.3.7",
33
37
  "chai-as-promised": "^7.1.1",
34
38
  "chai-exclude": "^2.1.0",
35
- "esbuild": "^0.14.28",
36
- "eslint": "^8.12.0",
37
- "eslint-config-google": "^0.14.0",
38
39
  "memjs": "^1.3.0",
39
- "mocha": "^9.2.2",
40
- "nodemon": "^2.0.15",
41
- "nyc": "^15.1.0",
42
- "source-map-support": "^0.5.21",
43
- "typescript": "^4.6.3"
40
+ "typescript": "^4.9.5"
44
41
  },
45
42
  "directories": {
46
43
  "test": "test"
47
- }
44
+ },
45
+ "files": [
46
+ "*.md",
47
+ "dist/",
48
+ "src/"
49
+ ]
48
50
  }
package/src/client.ts CHANGED
@@ -1,10 +1,12 @@
1
- import assert from 'assert'
2
- import { types } from 'util'
1
+ import assert from 'node:assert'
2
+ import { types } from 'node:util'
3
3
 
4
- import { ClusterAdapter, ClusterOptions } from './cluster'
4
+ import { ClusterAdapter } from './cluster'
5
5
  import { EMPTY_BUFFER, FLAGS } from './constants'
6
6
  import { typedArrayFlags } from './internals'
7
- import { Adapter, AdapterResult, Counter, Stats } from './types'
7
+
8
+ import type { ClusterOptions } from './cluster'
9
+ import type { Adapter, AdapterResult, Counter, Stats } from './types'
8
10
 
9
11
  /** JSON replacere function serializing `bigint`, {@link Date}, {@link Set} and {@link Map}. */
10
12
  function replacer(this: any, key: string, value: any): any {
@@ -16,7 +18,7 @@ function replacer(this: any, key: string, value: any): any {
16
18
  }
17
19
 
18
20
  /** JSON reviver function deserializing `bigint`, {@link Date}, {@link Set} and {@link Map}. */
19
- function reviver(this: any, key: string, value: any): any {
21
+ function reviver(this: any, _key: string, value: any): any {
20
22
  if (Array.isArray(value)) {
21
23
  switch (value[0]) {
22
24
  case '\0__$BIGINT$__\0': return BigInt(value[1])
@@ -120,8 +122,8 @@ function fromBuffer<T extends Serializable>(result: AdapterResult): ClientResult
120
122
 
121
123
  /** Create a {@link NodeJS.TypedArray} copying the contents of its source {@link Buffer} */
122
124
  function makeTypedArray<T extends NodeJS.TypedArray>(
123
- constructor: TypedArrayConstructor<T>,
124
- source: Buffer,
125
+ constructor: TypedArrayConstructor<T>,
126
+ source: Buffer,
125
127
  ): T {
126
128
  const clone = Buffer.from(source)
127
129
  const { buffer, byteOffset, byteLength } = clone
@@ -227,25 +229,25 @@ export class MemxClient {
227
229
  }
228
230
 
229
231
  append(
230
- key: string,
231
- value: Appendable,
232
- options?: { cas?: bigint },
232
+ key: string,
233
+ value: Appendable,
234
+ options?: { cas?: bigint },
233
235
  ): Promise<boolean> {
234
236
  return this.#adapter.append(this.#prefix + key, ...toBuffer(value, options))
235
237
  }
236
238
 
237
239
  prepend(
238
- key: string,
239
- value: Appendable,
240
- options?: { cas?: bigint },
240
+ key: string,
241
+ value: Appendable,
242
+ options?: { cas?: bigint },
241
243
  ): Promise<boolean> {
242
244
  return this.#adapter.prepend(this.#prefix + key, ...toBuffer(value, options))
243
245
  }
244
246
 
245
247
  async increment(
246
- key: string,
247
- delta?: bigint | number,
248
- options?: { initial?: bigint | number, cas?: bigint, ttl?: number },
248
+ key: string,
249
+ delta?: bigint | number,
250
+ options?: { initial?: bigint | number, cas?: bigint, ttl?: number },
249
251
  ): Promise<Counter | undefined> {
250
252
  const counter = await this.#adapter.increment(this.#prefix + key, delta, options)
251
253
 
@@ -257,9 +259,9 @@ export class MemxClient {
257
259
  }
258
260
 
259
261
  async decrement(
260
- key: string,
261
- delta?: bigint | number,
262
- options?: { initial?: bigint | number, cas?: bigint, ttl?: number },
262
+ key: string,
263
+ delta?: bigint | number,
264
+ options?: { initial?: bigint | number, cas?: bigint, ttl?: number },
263
265
  ): Promise<Counter | undefined> {
264
266
  const counter = await this.#adapter.decrement(this.#prefix + key, delta, options)
265
267
 
@@ -271,15 +273,15 @@ export class MemxClient {
271
273
  }
272
274
 
273
275
  touch(
274
- key: string,
275
- ttl?: number,
276
+ key: string,
277
+ ttl?: number,
276
278
  ): Promise<boolean> {
277
279
  return this.#adapter.touch(this.#prefix + key, ttl)
278
280
  }
279
281
 
280
282
  delete(
281
- key: string,
282
- options?: { cas?: bigint },
283
+ key: string,
284
+ options?: { cas?: bigint },
283
285
  ): Promise<boolean> {
284
286
  return this.#adapter.delete(this.#prefix + key, options)
285
287
  }
package/src/cluster.ts CHANGED
@@ -1,6 +1,9 @@
1
- import { Adapter, Counter, AdapterResult, Stats } from './types'
2
- import { ServerAdapter, ServerOptions } from './server'
3
- import assert from 'assert'
1
+ import assert from 'node:assert'
2
+
3
+ import { ServerAdapter } from './server'
4
+
5
+ import type { Adapter, Counter, AdapterResult, Stats } from './types'
6
+ import type { ServerOptions } from './server'
4
7
 
5
8
  function parseHosts(hosts?: string): ServerOptions[] {
6
9
  const result: { host: string, port?: number }[] = []
package/src/connection.ts CHANGED
@@ -1,11 +1,15 @@
1
- import assert from 'assert'
2
- import net, { Socket } from 'net'
1
+ import assert from 'node:assert'
2
+ import net from 'node:net'
3
3
 
4
- import { Encoder, RawOutgoingPacket } from './encode'
5
- import { Decoder, RawIncomingPacket } from './decode'
4
+ import { Encoder } from './encode'
5
+ import { Decoder } from './decode'
6
6
  import { BUFFERS, OPCODE } from './constants'
7
7
  import { socketFinalizationRegistry } from './internals'
8
8
 
9
+ import type { RawIncomingPacket } from './decode'
10
+ import type { RawOutgoingPacket } from './encode'
11
+ import type { Socket } from 'node:net'
12
+
9
13
  export type RawIncomingPackets = [ RawIncomingPacket, ...RawIncomingPacket[] ]
10
14
 
11
15
  class Deferred {
package/src/decode.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import assert from 'node:assert'
2
+
1
3
  import { DATA_TYPE, EMPTY_BUFFER, MAGIC, OFFSETS } from './constants'
2
- import assert from 'assert'
3
- import { allocateBuffer, RecyclableBuffer } from './buffers'
4
+ import { allocateBuffer } from './buffers'
5
+
6
+ import type { RecyclableBuffer } from './buffers'
4
7
 
5
8
  // Reading the full header would be like
6
9
  // const magic = header.readUInt8 (0)
package/src/encode.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { allocateBuffer, RecyclableBuffer } from './buffers'
2
- import { DATA_TYPE, EMPTY_BUFFER, MAGIC, VBUCKET, OPCODE, OFFSETS } from './constants'
1
+ import { allocateBuffer } from './buffers'
2
+ import { DATA_TYPE, EMPTY_BUFFER, MAGIC, VBUCKET, OFFSETS } from './constants'
3
+
4
+ import type { RecyclableBuffer } from './buffers'
5
+ import type { OPCODE } from './constants'
3
6
 
4
7
  // Writing the full header would be like
5
8
  // header.writeUInt8 (magic, 0)
package/src/fake.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Adapter, AdapterResult, Counter, Stats } from './types'
2
1
  import { MemxClient } from './client'
3
2
 
3
+ import type { Adapter, AdapterResult, Counter, Stats } from './types'
4
+
4
5
  interface Entry {
5
6
  value: Buffer,
6
7
  flags: number,
@@ -43,7 +44,7 @@ export class FakeAdapter implements Adapter {
43
44
  }
44
45
 
45
46
  async get(
46
- key: string,
47
+ key: string,
47
48
  ): Promise<AdapterResult | undefined> {
48
49
  const entry = this.#get(key)
49
50
  if (! entry) return
@@ -57,8 +58,8 @@ export class FakeAdapter implements Adapter {
57
58
  }
58
59
 
59
60
  async gat(
60
- key: string,
61
- ttl: number,
61
+ key: string,
62
+ ttl: number,
62
63
  ): Promise<AdapterResult | undefined> {
63
64
  const entry = this.#get(key)
64
65
  if (! entry) return
@@ -74,8 +75,8 @@ export class FakeAdapter implements Adapter {
74
75
  }
75
76
 
76
77
  async touch(
77
- key: string,
78
- ttl: number,
78
+ key: string,
79
+ ttl: number,
79
80
  ): Promise<boolean> {
80
81
  const entry = this.#get(key)
81
82
  if (entry) entry.exp = toExp(ttl)
@@ -83,9 +84,9 @@ export class FakeAdapter implements Adapter {
83
84
  }
84
85
 
85
86
  async set(
86
- key: string,
87
- value: Buffer,
88
- options: { flags?: number; cas?: bigint; ttl?: number } = {},
87
+ key: string,
88
+ value: Buffer,
89
+ options: { flags?: number; cas?: bigint; ttl?: number } = {},
89
90
  ): Promise<bigint | undefined> {
90
91
  const entry = this.#get(key)
91
92
  if (entry && (options.cas !== undefined) && (entry.cas !== options.cas)) {
@@ -96,27 +97,27 @@ export class FakeAdapter implements Adapter {
96
97
  }
97
98
 
98
99
  async add(
99
- key: string,
100
- value: Buffer,
101
- options: { flags?: number; ttl?: number } = {},
100
+ key: string,
101
+ value: Buffer,
102
+ options: { flags?: number; ttl?: number } = {},
102
103
  ): Promise<bigint | undefined> {
103
104
  if (this.#get(key)) return
104
105
  return this.#set(key, value, options.flags, options.ttl)
105
106
  }
106
107
 
107
108
  async replace(
108
- key: string,
109
- value: Buffer,
110
- options: { flags?: number; cas?: bigint; ttl?: number } = {},
109
+ key: string,
110
+ value: Buffer,
111
+ options: { flags?: number; cas?: bigint; ttl?: number } = {},
111
112
  ): Promise<bigint | undefined> {
112
113
  if (! this.#get(key)) return
113
114
  return this.#set(key, value, options.flags, options.ttl)
114
115
  }
115
116
 
116
117
  async append(
117
- key: string,
118
- value: Buffer,
119
- options: { cas?: bigint } = {},
118
+ key: string,
119
+ value: Buffer,
120
+ options: { cas?: bigint } = {},
120
121
  ): Promise<boolean> {
121
122
  const entry = this.#get(key)
122
123
  if (! entry) return false
@@ -128,9 +129,9 @@ export class FakeAdapter implements Adapter {
128
129
  }
129
130
 
130
131
  async prepend(
131
- key: string,
132
- value: Buffer,
133
- options: { cas?: bigint } = {},
132
+ key: string,
133
+ value: Buffer,
134
+ options: { cas?: bigint } = {},
134
135
  ): Promise<boolean> {
135
136
  const entry = this.#get(key)
136
137
  if (! entry) return false
@@ -142,9 +143,9 @@ export class FakeAdapter implements Adapter {
142
143
  }
143
144
 
144
145
  async #counter(
145
- key: string,
146
- delta: number | bigint,
147
- options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean },
146
+ key: string,
147
+ delta: number | bigint,
148
+ options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean },
148
149
  ): Promise<Counter | undefined> {
149
150
  const entry = this.#get(key)
150
151
 
@@ -170,24 +171,24 @@ export class FakeAdapter implements Adapter {
170
171
  }
171
172
 
172
173
  increment(
173
- key: string,
174
- delta: number | bigint = 1n,
175
- options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
174
+ key: string,
175
+ delta: number | bigint = 1n,
176
+ options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
176
177
  ): Promise<Counter | undefined> {
177
178
  return this.#counter(key, delta, options)
178
179
  }
179
180
 
180
181
  decrement(
181
- key: string,
182
- delta: number | bigint = 1n,
183
- options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
182
+ key: string,
183
+ delta: number | bigint = 1n,
184
+ options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
184
185
  ): Promise<Counter | undefined> {
185
186
  return this.#counter(key, -delta, options)
186
187
  }
187
188
 
188
189
  async delete(
189
- key: string,
190
- options: { cas?: bigint } = {},
190
+ key: string,
191
+ options: { cas?: bigint } = {},
191
192
  ): Promise<boolean> {
192
193
  const entry = this.#get(key)
193
194
  if (entry && (options.cas !== undefined) && (entry.cas !== options.cas)) {
@@ -198,7 +199,7 @@ export class FakeAdapter implements Adapter {
198
199
  }
199
200
 
200
201
  async flush(
201
- ttl?: number,
202
+ ttl?: number,
202
203
  ): Promise<void> {
203
204
  if (! ttl) return this.#cache.clear()
204
205
 
package/src/internals.ts CHANGED
@@ -1,12 +1,11 @@
1
- // Keep these here: they must be ignored by Istanbul, but ESBUILD swallows
2
- // commments (for a reason: https://github.com/evanw/esbuild/issues/578)
3
-
4
- import assert from 'assert'
5
- import type { Socket } from 'net'
6
- import { types } from 'util'
1
+ import assert from 'node:assert'
2
+ import { types } from 'node:util'
7
3
 
8
4
  import { FLAGS } from './constants'
9
5
 
6
+ import type { Socket } from 'node:net'
7
+
8
+ /* coverage ignore next */
10
9
  export const socketFinalizationRegistry = new FinalizationRegistry((socket: Socket): void => {
11
10
  if (! socket.destroyed) socket.destroy()
12
11
  })
@@ -28,7 +27,8 @@ export function typedArrayFlags(value: NodeJS.TypedArray): FLAGS {
28
27
  return flags
29
28
  }
30
29
 
30
+ /* coverage ignore next */
31
31
  export function logPromiseError(promise: Promise<any>, message: string): Promise<void> {
32
- // eslint-disable-next-line no-console
32
+ /* eslint-disable-next-line no-console */
33
33
  return promise.catch((error) => console.log(message, error)).then(() => void 0)
34
34
  }
package/src/server.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { Adapter, Counter, AdapterResult, Stats } from './types'
2
- import { Connection, ConnectionOptions } from './connection'
1
+ import { Connection } from './connection'
3
2
  import { BUFFERS, OPCODE, STATUS } from './constants'
4
- import { RawIncomingPacket } from './decode'
3
+
4
+ import type { Adapter, Counter, AdapterResult, Stats } from './types'
5
+ import type { ConnectionOptions } from './connection'
6
+ import type { RawIncomingPacket } from './decode'
5
7
 
6
8
  const statsBigInt: readonly string[] = [
7
9
  'auth_cmds', 'auth_errors', 'bytes', 'bytes_read', 'bytes_written', 'cas_badval', 'cas_hits', 'cas_misses',
@@ -108,8 +110,8 @@ export class ServerAdapter implements Adapter {
108
110
  /* ======================================================================== */
109
111
 
110
112
  async #get(
111
- key: string,
112
- ttl?: number,
113
+ key: string,
114
+ ttl?: number,
113
115
  ): Promise<AdapterResult | undefined> {
114
116
  let keyOffset = 0
115
117
  if (ttl !== undefined) keyOffset = this.#buffer.writeUInt32BE(ttl)
@@ -141,21 +143,21 @@ export class ServerAdapter implements Adapter {
141
143
  }
142
144
 
143
145
  async get(
144
- key: string,
146
+ key: string,
145
147
  ): Promise<AdapterResult | undefined> {
146
148
  return this.#get(key)
147
149
  }
148
150
 
149
151
  async gat(
150
- key: string,
151
- ttl: number,
152
+ key: string,
153
+ ttl: number,
152
154
  ): Promise<AdapterResult | undefined> {
153
155
  return this.#get(key, ttl || 2592000) // TTL 0 is "invalid arg"
154
156
  }
155
157
 
156
158
  async touch(
157
- key: string,
158
- ttl?: number,
159
+ key: string,
160
+ ttl?: number,
159
161
  ): Promise<boolean> {
160
162
  const timeToLive = ttl ?? this.#ttl
161
163
 
@@ -189,10 +191,10 @@ export class ServerAdapter implements Adapter {
189
191
  /* ======================================================================== */
190
192
 
191
193
  async #sar(
192
- opcode: OPCODE.SET | OPCODE.ADD | OPCODE.REPLACE,
193
- key: string,
194
- value: Buffer,
195
- options: { flags?: number, cas?: bigint, ttl?: number },
194
+ opcode: OPCODE.SET | OPCODE.ADD | OPCODE.REPLACE,
195
+ key: string,
196
+ value: Buffer,
197
+ options: { flags?: number, cas?: bigint, ttl?: number },
196
198
  ): Promise<bigint | undefined> {
197
199
  const { flags = 0, cas = 0n, ttl = this.#ttl } = options
198
200
 
@@ -229,25 +231,25 @@ export class ServerAdapter implements Adapter {
229
231
  }
230
232
 
231
233
  set(
232
- key: string,
233
- value: Buffer,
234
- options: { flags?: number, cas?: bigint, ttl?: number } = {},
234
+ key: string,
235
+ value: Buffer,
236
+ options: { flags?: number, cas?: bigint, ttl?: number } = {},
235
237
  ): Promise<bigint | undefined> {
236
238
  return this.#sar(OPCODE.SET, key, value, options)
237
239
  }
238
240
 
239
241
  add(
240
- key: string,
241
- value: Buffer,
242
- options: { flags?: number, ttl?: number } = {},
242
+ key: string,
243
+ value: Buffer,
244
+ options: { flags?: number, ttl?: number } = {},
243
245
  ): Promise<bigint | undefined> {
244
246
  return this.#sar(OPCODE.ADD, key, value, options)
245
247
  }
246
248
 
247
249
  replace(
248
- key: string,
249
- value: Buffer,
250
- options: { flags?: number, cas?: bigint, ttl?: number } = {},
250
+ key: string,
251
+ value: Buffer,
252
+ options: { flags?: number, cas?: bigint, ttl?: number } = {},
251
253
  ): Promise<bigint | undefined> {
252
254
  return this.#sar(OPCODE.REPLACE, key, value, options)
253
255
  }
@@ -255,10 +257,10 @@ export class ServerAdapter implements Adapter {
255
257
  /* ======================================================================== */
256
258
 
257
259
  async #pend(
258
- opcode: OPCODE.APPEND | OPCODE.PREPEND,
259
- key: string,
260
- value: Buffer,
261
- options: { cas?: bigint },
260
+ opcode: OPCODE.APPEND | OPCODE.PREPEND,
261
+ key: string,
262
+ value: Buffer,
263
+ options: { cas?: bigint },
262
264
  ): Promise<boolean> {
263
265
  const { cas = 0n } = options
264
266
 
@@ -289,17 +291,17 @@ export class ServerAdapter implements Adapter {
289
291
  }
290
292
 
291
293
  append(
292
- key: string,
293
- value: Buffer,
294
- options: { cas?: bigint } = {},
294
+ key: string,
295
+ value: Buffer,
296
+ options: { cas?: bigint } = {},
295
297
  ): Promise<boolean> {
296
298
  return this.#pend(OPCODE.APPEND, key, value, options)
297
299
  }
298
300
 
299
301
  prepend(
300
- key: string,
301
- value: Buffer,
302
- options: { cas?: bigint } = {},
302
+ key: string,
303
+ value: Buffer,
304
+ options: { cas?: bigint } = {},
303
305
  ): Promise<boolean> {
304
306
  return this.#pend(OPCODE.PREPEND, key, value, options)
305
307
  }
@@ -307,10 +309,10 @@ export class ServerAdapter implements Adapter {
307
309
  /* ======================================================================== */
308
310
 
309
311
  async #counter(
310
- opcode: OPCODE.INCREMENT | OPCODE.DECREMENT,
311
- key: string,
312
- delta: bigint | number,
313
- options: { initial?: bigint | number, cas?: bigint, ttl?: number },
312
+ opcode: OPCODE.INCREMENT | OPCODE.DECREMENT,
313
+ key: string,
314
+ delta: bigint | number,
315
+ options: { initial?: bigint | number, cas?: bigint, ttl?: number },
314
316
  ): Promise<Counter | undefined> {
315
317
  const {
316
318
  initial,
@@ -354,17 +356,17 @@ export class ServerAdapter implements Adapter {
354
356
  }
355
357
 
356
358
  increment(
357
- key: string,
358
- delta: bigint | number = 1,
359
- options: { initial?: bigint | number, cas?: bigint, ttl?: number, create?: boolean } = {},
359
+ key: string,
360
+ delta: bigint | number = 1,
361
+ options: { initial?: bigint | number, cas?: bigint, ttl?: number, create?: boolean } = {},
360
362
  ): Promise<Counter | undefined> {
361
363
  return this.#counter(OPCODE.INCREMENT, key, delta, options)
362
364
  }
363
365
 
364
366
  decrement(
365
- key: string,
366
- delta: bigint | number = 1,
367
- options: { initial?: bigint | number, cas?: bigint, ttl?: number, create?: boolean } = {},
367
+ key: string,
368
+ delta: bigint | number = 1,
369
+ options: { initial?: bigint | number, cas?: bigint, ttl?: number, create?: boolean } = {},
368
370
  ): Promise<Counter | undefined> {
369
371
  return this.#counter(OPCODE.DECREMENT, key, delta, options)
370
372
  }
@@ -372,8 +374,8 @@ export class ServerAdapter implements Adapter {
372
374
  /* ======================================================================== */
373
375
 
374
376
  async delete(
375
- key: string,
376
- options: { cas?: bigint } = {},
377
+ key: string,
378
+ options: { cas?: bigint } = {},
377
379
  ): Promise<boolean> {
378
380
  const { cas = 0n } = options
379
381
 
package/src/utils.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable no-console */
2
2
 
3
- import assert from 'assert'
4
- import { MemxClient, Serializable } from './client'
3
+ import assert from 'node:assert'
4
+
5
5
  import { logPromiseError } from './internals'
6
6
 
7
+ import type { MemxClient, Serializable } from './client'
8
+
7
9
  export class Factory<T extends Serializable> {
8
10
  #factory: (key: string) => T | Promise<T>
9
11
  #client: MemxClient
@@ -79,6 +81,7 @@ export class Bundle<T extends Serializable = Serializable> {
79
81
  const result = await this.#client.getc<T>(`${this.#name}:${key}`)
80
82
  if (result) return result.value
81
83
  await this.#removeKey(key)
84
+ return undefined
82
85
  }
83
86
 
84
87
  async delete(key: string): Promise<void> {
@@ -122,8 +125,8 @@ export class PoorManLock {
122
125
  }
123
126
 
124
127
  async execute<T>(
125
- executor: () => T | Promise<T>,
126
- options?: { timeout?: number, owner?: string },
128
+ executor: () => T | Promise<T>,
129
+ options?: { timeout?: number, owner?: string },
127
130
  ): Promise<T> {
128
131
  const { timeout = 5000, owner = false } = options || {}
129
132
  const end = Date.now() + timeout