-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkeyv.node.txt
70 lines (59 loc) · 3.3 KB
/
keyv.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
┏━━━━━━━━━━┓
┃ KEYV ┃
┗━━━━━━━━━━┛
VERSION ==> #5.1.2 (2024-11-02)
new Keyv([STORE, [OPTS]]) #Key-value database abstraction layer
OPTS|KEYV.namespace #'NAMESPACE' (def: 'keyv')
#Prefixed to every 'KEY' as 'NAMESPACE:KEY'
OPTS.serialize #FUNC(VAL)->STR (def: JSON.stringify() which also handles BUFFER)
OPTS.deserialize #FUNC(STR)->VAL (def: JSON.parse() which also handles BUFFER)
OPTS.compression #COMPRESSION. [de]compress on [de]serialize()
#Available ones:
# - @keyv/compress-brotli
# - @keyv/compress-gzip
KEYV.get('KEY'[_ARR][, OPTS]) #OPTS:
->>VAL[_ARR] # - raw BOOL: if true (def), get OBJ instead of OBJ.value
KEYV.set('KEY', VAL[, NUM])->> #NUM is TTL, in ms (def: OPTS.ttl)
KEYV.has('KEY')->>BOOL #
KEYV.delete('KEY'[_ARR])->> #
KEYV.clear()->> #
KEYV.iterator(['NAMESPACE'])
->ASYNC_ITERATOR #
KEYV.disconnect()->> #
OPTS.store #STORE. Store adapter
#Is a MAP
#Def: use OPTS.adapter 'MODULE' -> new (require('MODULE'))(OPTS)
# - only for supported stores '@keyv/*'
STORE.namespace #Set to OPTS.namespace
KEYV|STORE.on('error',FUNC(ERROR))#ERROR on STORE are propagated to KEYV
#Not if OPTS.emitErrors false (def: true)
KEYV|STORE.on
('clear|disconnect', FUNC()) #On KEYV.clear|disconnect()
KEYV.hooks.addListener #HOOK_NAME is PRE|POST_GET|GET_MANY|SET|DELETE
(KeyvHooks.HOOK_NAME, #Arguments can be mutated
FUNC('KEY'[_ARR], VAL[, NUM])) #'KEY' is ARR with *_DELETE
OPTS.stats #BOOL (def: false). Sets KEYV.stats
KEYV.stats.enabled #BOOL
KEYV.stats
.hits|misses|deletes|sets #NUM
STORE.get('KEY')->[>]'OBJ'|OBJ #OBJ:
# - expires TIMESTAMP_NUM (in ms): call STORE.delete('KEY') if past it
# - value VAL: value passed to user
# - anything else custom
STORE.getMany('KEY'_ARR)
->[>]'OBJ'|OBJ_ARR #
STORE.set('KEY', 'OBJ',
TIMESTAMP_NUM|null)[->>] #OBJ has properties: expires, value
STORE.has('KEY')->[>]BOOL #
STORE.delete('KEY')[->>] #
STORE.deleteMany('KEY'_ARR)[->>] #
STORE.clear()[->>] #
OTHER AVAILABLE STORES ==> # - new Map(): in-memory, no limit
# - quick-lru (see its doc): in-memory, LRU limit
# - keyv-file: in filesystem
# - @keyv/redis
# - @keyv/mongo
# - @keyv/sqlite
# - @keyv/postgres
# - @keyv/mysql
#Not documented yet (do it when I use them)