memx 0.0.6 → 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.
- package/dist/buffers.cjs +50 -0
- package/dist/buffers.cjs.map +6 -0
- package/dist/buffers.d.ts +14 -0
- package/dist/buffers.mjs +25 -0
- package/dist/buffers.mjs.map +6 -0
- package/dist/client.cjs +251 -0
- package/dist/client.cjs.map +6 -0
- package/dist/client.d.ts +76 -0
- package/dist/client.mjs +216 -0
- package/dist/client.mjs.map +6 -0
- package/dist/cluster.cjs +147 -0
- package/dist/cluster.cjs.map +6 -0
- package/dist/cluster.d.ts +60 -0
- package/dist/cluster.mjs +112 -0
- package/dist/cluster.mjs.map +6 -0
- package/dist/connection.cjs +186 -0
- package/dist/connection.cjs.map +6 -0
- package/dist/connection.d.ts +18 -0
- package/dist/connection.mjs +151 -0
- package/dist/connection.mjs.map +6 -0
- package/dist/constants.cjs +140 -0
- package/dist/constants.cjs.map +6 -0
- package/dist/constants.d.ts +87 -0
- package/dist/constants.mjs +107 -0
- package/dist/constants.mjs.map +6 -0
- package/dist/decode.cjs +101 -0
- package/dist/decode.cjs.map +6 -0
- package/dist/decode.d.ts +16 -0
- package/dist/decode.mjs +66 -0
- package/dist/decode.mjs.map +6 -0
- package/dist/encode.cjs +70 -0
- package/dist/encode.cjs.map +6 -0
- package/dist/encode.d.ts +20 -0
- package/dist/encode.mjs +45 -0
- package/dist/encode.mjs.map +6 -0
- package/dist/fake.cjs +183 -0
- package/dist/fake.cjs.map +6 -0
- package/dist/fake.d.ts +53 -0
- package/dist/fake.mjs +157 -0
- package/dist/fake.mjs.map +6 -0
- package/dist/index.cjs +57 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.mjs +15 -1454
- package/dist/index.mjs.map +2 -2
- package/dist/internals.cjs +58 -0
- package/dist/internals.cjs.map +6 -0
- package/dist/internals.d.ts +7 -0
- package/dist/internals.mjs +21 -0
- package/dist/internals.mjs.map +6 -0
- package/dist/server.cjs +468 -0
- package/dist/server.cjs.map +6 -0
- package/dist/server.d.ts +59 -0
- package/dist/server.mjs +443 -0
- package/dist/server.mjs.map +6 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +6 -0
- package/dist/types.d.ts +239 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +6 -0
- package/dist/utils.cjs +182 -0
- package/dist/utils.cjs.map +6 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.mjs +145 -0
- package/dist/utils.mjs.map +6 -0
- package/package.json +29 -27
- package/src/client.ts +37 -35
- package/src/cluster.ts +6 -3
- package/src/connection.ts +8 -4
- package/src/decode.ts +5 -2
- package/src/encode.ts +5 -2
- package/src/fake.ts +41 -33
- package/src/internals.ts +7 -7
- package/src/server.ts +47 -45
- package/src/utils.ts +13 -10
- package/dist/index.js +0 -1489
- package/dist/index.js.map +0 -6
- package/index.d.ts +0 -706
package/package.json
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memx",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Simple and fast memcached client",
|
|
5
|
-
"main": "./dist/index.
|
|
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
|
-
"
|
|
10
|
-
|
|
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": "
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
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
|
-
"@
|
|
24
|
-
"@types/chai": "^4.3.
|
|
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.
|
|
27
|
-
"
|
|
28
|
-
"@types/node": "~16.11.26",
|
|
29
|
-
"@types/source-map-support": "^0.5.4",
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
31
|
-
"@typescript-eslint/parser": "^5.15.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.27",
|
|
36
|
-
"eslint": "^8.11.0",
|
|
37
|
-
"eslint-config-google": "^0.14.0",
|
|
38
39
|
"memjs": "^1.3.0",
|
|
39
|
-
"
|
|
40
|
-
"nodemon": "^2.0.15",
|
|
41
|
-
"nyc": "^15.1.0",
|
|
42
|
-
"source-map-support": "^0.5.21",
|
|
43
|
-
"typescript": "^4.6.2"
|
|
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
|
|
4
|
+
import { ClusterAdapter } from './cluster'
|
|
5
5
|
import { EMPTY_BUFFER, FLAGS } from './constants'
|
|
6
6
|
import { typedArrayFlags } from './internals'
|
|
7
|
-
|
|
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,
|
|
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
|
-
|
|
124
|
-
|
|
125
|
+
constructor: TypedArrayConstructor<T>,
|
|
126
|
+
source: Buffer,
|
|
125
127
|
): T {
|
|
126
128
|
const clone = Buffer.from(source)
|
|
127
129
|
const { buffer, byteOffset, byteLength } = clone
|
|
@@ -130,15 +132,15 @@ function makeTypedArray<T extends NodeJS.TypedArray>(
|
|
|
130
132
|
|
|
131
133
|
/* ========================================================================== */
|
|
132
134
|
|
|
133
|
-
/** Types that can be serialized by our {@link
|
|
135
|
+
/** Types that can be serialized by our {@link MemxClient}. */
|
|
134
136
|
export type Serializable = bigint | string | number | boolean | null | object
|
|
135
137
|
|
|
136
|
-
/** Types that can be appended/prepended by our {@link
|
|
138
|
+
/** Types that can be appended/prepended by our {@link MemxClient}. */
|
|
137
139
|
export type Appendable = string | NodeJS.TypedArray
|
|
138
140
|
|
|
139
141
|
/** The `ClientResult` interface associate a value with its _CAS_. */
|
|
140
142
|
export interface ClientResult<T extends Serializable> {
|
|
141
|
-
/** The value returned by the {@link
|
|
143
|
+
/** The value returned by the {@link MemxClient} */
|
|
142
144
|
value: T
|
|
143
145
|
/** The _CAS_ of the value being returned */
|
|
144
146
|
cas: bigint
|
|
@@ -147,15 +149,15 @@ export interface ClientResult<T extends Serializable> {
|
|
|
147
149
|
/**
|
|
148
150
|
* A `Client` represents a high-level client for a _Memcached_ server.
|
|
149
151
|
*/
|
|
150
|
-
export class
|
|
152
|
+
export class MemxClient {
|
|
151
153
|
#adapter!: Adapter
|
|
152
154
|
#prefix: string
|
|
153
155
|
|
|
154
|
-
/** Construct a new {@link
|
|
156
|
+
/** Construct a new {@link MemxClient} from environment variables */
|
|
155
157
|
constructor()
|
|
156
|
-
/** Construct a new {@link
|
|
158
|
+
/** Construct a new {@link MemxClient} wrapping an existing {@link Adapter} */
|
|
157
159
|
constructor(adapter: Adapter)
|
|
158
|
-
/** Construct a new {@link
|
|
160
|
+
/** Construct a new {@link MemxClient} given the specified {@link ClusterOptions} */
|
|
159
161
|
constructor(options: ClusterOptions)
|
|
160
162
|
|
|
161
163
|
constructor(adapterOrOptions?: Adapter | ClusterOptions) {
|
|
@@ -172,20 +174,20 @@ export class Client {
|
|
|
172
174
|
assert(this.#adapter, 'Invalid client constructor arguments')
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
/** Return the {@link Adapter} backing this {@link
|
|
177
|
+
/** Return the {@link Adapter} backing this {@link MemxClient} instance */
|
|
176
178
|
get adapter(): Adapter {
|
|
177
179
|
return this.#adapter
|
|
178
180
|
}
|
|
179
181
|
|
|
180
|
-
/** Return the prefix prepended to all keys managed by this {@link
|
|
182
|
+
/** Return the prefix prepended to all keys managed by this {@link MemxClient} */
|
|
181
183
|
get prefix(): string {
|
|
182
184
|
return this.#prefix
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
/** Return a new {@link
|
|
186
|
-
withPrefix(prefix: string):
|
|
187
|
+
/** Return a new {@link MemxClient} prefixing keys with the specified `string` */
|
|
188
|
+
withPrefix(prefix: string): MemxClient {
|
|
187
189
|
assert(prefix, 'Invalid prefix')
|
|
188
|
-
const client = new
|
|
190
|
+
const client = new MemxClient(this.#adapter)
|
|
189
191
|
client.#prefix = prefix
|
|
190
192
|
return client
|
|
191
193
|
}
|
|
@@ -227,25 +229,25 @@ export class Client {
|
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
append(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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 Client {
|
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
async decrement(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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 Client {
|
|
|
271
273
|
}
|
|
272
274
|
|
|
273
275
|
touch(
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
282
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
import
|
|
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
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import net from 'node:net'
|
|
3
3
|
|
|
4
|
-
import { Encoder
|
|
5
|
-
import { Decoder
|
|
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
|
|
3
|
-
|
|
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
|
|
2
|
-
import { DATA_TYPE, EMPTY_BUFFER, MAGIC, VBUCKET,
|
|
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,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MemxClient } from './client'
|
|
2
|
+
|
|
3
|
+
import type { Adapter, AdapterResult, Counter, Stats } from './types'
|
|
2
4
|
|
|
3
5
|
interface Entry {
|
|
4
6
|
value: Buffer,
|
|
@@ -42,7 +44,7 @@ export class FakeAdapter implements Adapter {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async get(
|
|
45
|
-
|
|
47
|
+
key: string,
|
|
46
48
|
): Promise<AdapterResult | undefined> {
|
|
47
49
|
const entry = this.#get(key)
|
|
48
50
|
if (! entry) return
|
|
@@ -56,8 +58,8 @@ export class FakeAdapter implements Adapter {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
async gat(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
key: string,
|
|
62
|
+
ttl: number,
|
|
61
63
|
): Promise<AdapterResult | undefined> {
|
|
62
64
|
const entry = this.#get(key)
|
|
63
65
|
if (! entry) return
|
|
@@ -73,8 +75,8 @@ export class FakeAdapter implements Adapter {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
async touch(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
key: string,
|
|
79
|
+
ttl: number,
|
|
78
80
|
): Promise<boolean> {
|
|
79
81
|
const entry = this.#get(key)
|
|
80
82
|
if (entry) entry.exp = toExp(ttl)
|
|
@@ -82,9 +84,9 @@ export class FakeAdapter implements Adapter {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
async set(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
key: string,
|
|
88
|
+
value: Buffer,
|
|
89
|
+
options: { flags?: number; cas?: bigint; ttl?: number } = {},
|
|
88
90
|
): Promise<bigint | undefined> {
|
|
89
91
|
const entry = this.#get(key)
|
|
90
92
|
if (entry && (options.cas !== undefined) && (entry.cas !== options.cas)) {
|
|
@@ -95,27 +97,27 @@ export class FakeAdapter implements Adapter {
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
async add(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
key: string,
|
|
101
|
+
value: Buffer,
|
|
102
|
+
options: { flags?: number; ttl?: number } = {},
|
|
101
103
|
): Promise<bigint | undefined> {
|
|
102
104
|
if (this.#get(key)) return
|
|
103
105
|
return this.#set(key, value, options.flags, options.ttl)
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
async replace(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
key: string,
|
|
110
|
+
value: Buffer,
|
|
111
|
+
options: { flags?: number; cas?: bigint; ttl?: number } = {},
|
|
110
112
|
): Promise<bigint | undefined> {
|
|
111
113
|
if (! this.#get(key)) return
|
|
112
114
|
return this.#set(key, value, options.flags, options.ttl)
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
async append(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
key: string,
|
|
119
|
+
value: Buffer,
|
|
120
|
+
options: { cas?: bigint } = {},
|
|
119
121
|
): Promise<boolean> {
|
|
120
122
|
const entry = this.#get(key)
|
|
121
123
|
if (! entry) return false
|
|
@@ -127,9 +129,9 @@ export class FakeAdapter implements Adapter {
|
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
async prepend(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
key: string,
|
|
133
|
+
value: Buffer,
|
|
134
|
+
options: { cas?: bigint } = {},
|
|
133
135
|
): Promise<boolean> {
|
|
134
136
|
const entry = this.#get(key)
|
|
135
137
|
if (! entry) return false
|
|
@@ -141,9 +143,9 @@ export class FakeAdapter implements Adapter {
|
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
async #counter(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
key: string,
|
|
147
|
+
delta: number | bigint,
|
|
148
|
+
options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean },
|
|
147
149
|
): Promise<Counter | undefined> {
|
|
148
150
|
const entry = this.#get(key)
|
|
149
151
|
|
|
@@ -169,24 +171,24 @@ export class FakeAdapter implements Adapter {
|
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
increment(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
key: string,
|
|
175
|
+
delta: number | bigint = 1n,
|
|
176
|
+
options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
|
|
175
177
|
): Promise<Counter | undefined> {
|
|
176
178
|
return this.#counter(key, delta, options)
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
decrement(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
key: string,
|
|
183
|
+
delta: number | bigint = 1n,
|
|
184
|
+
options: { initial?: number | bigint; cas?: bigint; ttl?: number; create?: boolean } = {},
|
|
183
185
|
): Promise<Counter | undefined> {
|
|
184
186
|
return this.#counter(key, -delta, options)
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
async delete(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
key: string,
|
|
191
|
+
options: { cas?: bigint } = {},
|
|
190
192
|
): Promise<boolean> {
|
|
191
193
|
const entry = this.#get(key)
|
|
192
194
|
if (entry && (options.cas !== undefined) && (entry.cas !== options.cas)) {
|
|
@@ -197,7 +199,7 @@ export class FakeAdapter implements Adapter {
|
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
async flush(
|
|
200
|
-
|
|
202
|
+
ttl?: number,
|
|
201
203
|
): Promise<void> {
|
|
202
204
|
if (! ttl) return this.#cache.clear()
|
|
203
205
|
|
|
@@ -220,3 +222,9 @@ export class FakeAdapter implements Adapter {
|
|
|
220
222
|
return { fake: { version: '0.0.0-fake' } as Stats }
|
|
221
223
|
}
|
|
222
224
|
}
|
|
225
|
+
|
|
226
|
+
export class MemxFakeClient extends MemxClient {
|
|
227
|
+
constructor() {
|
|
228
|
+
super(new FakeAdapter())
|
|
229
|
+
}
|
|
230
|
+
}
|
package/src/internals.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
32
|
+
/* eslint-disable-next-line no-console */
|
|
33
33
|
return promise.catch((error) => console.log(message, error)).then(() => void 0)
|
|
34
34
|
}
|