@atproto-labs/simple-store-memory 0.2.2 → 0.2.3
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/CHANGELOG.md +13 -0
- package/dist/util.js.map +1 -1
- package/package.json +9 -6
- package/src/index.ts +0 -98
- package/src/util.ts +0 -77
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atproto-labs/simple-store-memory
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
|
|
8
|
+
|
|
9
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
|
|
10
|
+
|
|
11
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build with `noImplicitAny` enabled
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
|
|
14
|
+
- @atproto-labs/simple-store@0.4.3
|
|
15
|
+
|
|
3
16
|
## 0.2.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,IAAI,OAAO,EAAkB,CAAA;AAEhD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;IAC5B,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,CAAA,CAAC,uDAAuD;IAC7E,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;QAEzB,2EAA2E;QAC3E,iEAAiE;QACjE,uCAAuC;QAEvC,QAAQ,OAAO,KAAK,EAAE,CAAC;YACrB,iCAAiC;YACjC,KAAK,QAAQ;gBACX,8CAA8C;gBAC9C,KAAK,IAAI,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;gBAC7C,MAAK;YACP,KAAK,QAAQ;gBACX,KAAK,IAAI,EAAE,CAAA,CAAC,4BAA4B;gBACxC,MAAK;YACP,KAAK,SAAS;gBACZ,KAAK,IAAI,CAAC,CAAA,CAAC,mBAAmB;gBAC9B,MAAK;YACP,KAAK,QAAQ;gBACX,KAAK,IAAI,CAAC,CAAA,CAAC,mBAAmB;gBAE9B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,MAAK;gBACP,CAAC;gBAED,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC1B,KAAK,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAE,CAAA;oBAC/B,MAAK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CAAC,CAAA;oBACjB,CAAC;gBACH,CAAC;gBACD,MAAK;YACP,KAAK,UAAU;gBACb,KAAK,IAAI,CAAC,CAAA,CAAC,6DAA6D;gBACxE,MAAK;YACP,KAAK,QAAQ;gBACX,KAAK,IAAI,CAAC,CAAA,CAAC,6BAA6B;gBACxC,MAAK;YACP,KAAK,QAAQ;gBACX,KAAK,IAAI,EAAE,CAAA,CAAC,4BAA4B;gBACxC,MAAK;QACT,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["const knownSizes = new WeakMap<object, number>()\n\n/**\n * @see {@link https://stackoverflow.com/a/11900218/356537}\n */\nexport function roughSizeOfObject(value: unknown): number {\n const objectList = new Set()\n const stack = [value] // This would be more efficient using a circular buffer\n let bytes = 0\n\n while (stack.length) {\n const value = stack.pop()\n\n // > All objects on the heap start with a shape descriptor, which takes one\n // > pointer size (usually 4 bytes these days, thanks to \"pointer\n // > compression\" on 64-bit platforms).\n\n switch (typeof value) {\n // Types are ordered by frequency\n case 'string':\n // https://stackoverflow.com/a/68791382/356537\n bytes += 12 + 4 * Math.ceil(value.length / 4)\n break\n case 'number':\n bytes += 12 // Shape descriptor + double\n break\n case 'boolean':\n bytes += 4 // Shape descriptor\n break\n case 'object':\n bytes += 4 // Shape descriptor\n\n if (value === null) {\n break\n }\n\n if (knownSizes.has(value)) {\n bytes += knownSizes.get(value)!\n break\n }\n\n if (objectList.has(value)) continue\n objectList.add(value)\n\n if (Array.isArray(value)) {\n bytes += 4\n stack.push(...value)\n } else {\n bytes += 8\n const keys = Object.getOwnPropertyNames(value)\n for (let i = 0; i < keys.length; i++) {\n bytes += 4\n const key = keys[i]\n const val = (value as Record<string, unknown>)[key]\n if (val !== undefined) stack.push(val)\n stack.push(key)\n }\n }\n break\n case 'function':\n bytes += 8 // Shape descriptor + pointer (assuming functions are shared)\n break\n case 'symbol':\n bytes += 8 // Shape descriptor + pointer\n break\n case 'bigint':\n bytes += 16 // Shape descriptor + BigInt\n break\n }\n }\n\n if (typeof value === 'object' && value !== null) {\n knownSizes.set(value, bytes)\n }\n\n return bytes\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto-labs/simple-store-memory",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=22"
|
|
6
|
-
},
|
|
3
|
+
"version": "0.2.3",
|
|
7
4
|
"license": "MIT",
|
|
8
5
|
"description": "Memory based simple-store implementation",
|
|
9
6
|
"keywords": [
|
|
@@ -17,6 +14,10 @@
|
|
|
17
14
|
"url": "https://github.com/bluesky-social/atproto",
|
|
18
15
|
"directory": "packages/internal/simple-store-memory"
|
|
19
16
|
},
|
|
17
|
+
"files": [
|
|
18
|
+
"./dist",
|
|
19
|
+
"./CHANGELOG.md"
|
|
20
|
+
],
|
|
20
21
|
"type": "module",
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
@@ -24,11 +25,13 @@
|
|
|
24
25
|
"default": "./dist/index.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"lru-cache": "^10.2.0",
|
|
29
|
-
"@atproto-labs/simple-store": "^0.4.
|
|
33
|
+
"@atproto-labs/simple-store": "^0.4.3"
|
|
30
34
|
},
|
|
31
|
-
"devDependencies": {},
|
|
32
35
|
"scripts": {
|
|
33
36
|
"build": "tsgo --build tsconfig.build.json"
|
|
34
37
|
}
|
package/src/index.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { LRUCache } from 'lru-cache'
|
|
2
|
-
import { Key, SimpleStore, Value } from '@atproto-labs/simple-store'
|
|
3
|
-
import { roughSizeOfObject } from './util.js'
|
|
4
|
-
|
|
5
|
-
export type SimpleStoreMemoryOptions<K extends Key, V extends Value> = {
|
|
6
|
-
/**
|
|
7
|
-
* The maximum number of entries in the cache.
|
|
8
|
-
*/
|
|
9
|
-
max?: number
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The time-to-live of a cache entry, in milliseconds.
|
|
13
|
-
*/
|
|
14
|
-
ttl?: number
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Whether to automatically prune expired entries.
|
|
18
|
-
*/
|
|
19
|
-
ttlAutopurge?: boolean
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The maximum total size of the cache, in units defined by the sizeCalculation
|
|
23
|
-
* function.
|
|
24
|
-
*
|
|
25
|
-
* @default No limit
|
|
26
|
-
*/
|
|
27
|
-
maxSize?: number
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The maximum size of a single cache entry, in units defined by the
|
|
31
|
-
* sizeCalculation function.
|
|
32
|
-
*
|
|
33
|
-
* @default No limit
|
|
34
|
-
*/
|
|
35
|
-
maxEntrySize?: number
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A function that returns the size of a value. The size is used to determine
|
|
39
|
-
* when the cache should be pruned, based on `maxSize`.
|
|
40
|
-
*
|
|
41
|
-
* @default The (rough) size in bytes used in memory.
|
|
42
|
-
*/
|
|
43
|
-
sizeCalculation?: (value: V, key: K) => number
|
|
44
|
-
} & ( // Memory is not infinite, so at least one pruning option is required.
|
|
45
|
-
| { max: number }
|
|
46
|
-
| { maxSize: number }
|
|
47
|
-
| { ttl: number; ttlAutopurge: boolean }
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
// LRUCache does not allow storing "null", so we use a symbol to represent it.
|
|
51
|
-
const nullSymbol = Symbol('nullItem')
|
|
52
|
-
type AsLruValue<V extends Value> = V extends null
|
|
53
|
-
? typeof nullSymbol
|
|
54
|
-
: Exclude<V, null>
|
|
55
|
-
const toLruValue = <V extends Value>(value: V) =>
|
|
56
|
-
(value === null ? nullSymbol : value) as AsLruValue<V>
|
|
57
|
-
const fromLruValue = <V extends Value>(value: AsLruValue<V>) =>
|
|
58
|
-
(value === nullSymbol ? null : value) as V
|
|
59
|
-
|
|
60
|
-
export class SimpleStoreMemory<K extends Key, V extends Value>
|
|
61
|
-
implements SimpleStore<K, V>
|
|
62
|
-
{
|
|
63
|
-
#cache: LRUCache<K, AsLruValue<V>>
|
|
64
|
-
|
|
65
|
-
constructor({ sizeCalculation, ...options }: SimpleStoreMemoryOptions<K, V>) {
|
|
66
|
-
this.#cache = new LRUCache<K, AsLruValue<V>>({
|
|
67
|
-
...options,
|
|
68
|
-
allowStale: false,
|
|
69
|
-
updateAgeOnGet: false,
|
|
70
|
-
updateAgeOnHas: false,
|
|
71
|
-
sizeCalculation: sizeCalculation
|
|
72
|
-
? (value, key) => sizeCalculation(fromLruValue(value), key)
|
|
73
|
-
: options.maxEntrySize != null || options.maxSize != null
|
|
74
|
-
? // maxEntrySize and maxSize require a size calculation function.
|
|
75
|
-
roughSizeOfObject
|
|
76
|
-
: undefined,
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get(key: K): V | undefined {
|
|
81
|
-
const value = this.#cache.get(key)
|
|
82
|
-
if (value === undefined) return undefined
|
|
83
|
-
|
|
84
|
-
return fromLruValue(value)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
set(key: K, value: V): void {
|
|
88
|
-
this.#cache.set(key, toLruValue(value))
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
del(key: K): void {
|
|
92
|
-
this.#cache.delete(key)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
clear(): void {
|
|
96
|
-
this.#cache.clear()
|
|
97
|
-
}
|
|
98
|
-
}
|
package/src/util.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const knownSizes = new WeakMap<object, number>()
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @see {@link https://stackoverflow.com/a/11900218/356537}
|
|
5
|
-
*/
|
|
6
|
-
export function roughSizeOfObject(value: unknown): number {
|
|
7
|
-
const objectList = new Set()
|
|
8
|
-
const stack = [value] // This would be more efficient using a circular buffer
|
|
9
|
-
let bytes = 0
|
|
10
|
-
|
|
11
|
-
while (stack.length) {
|
|
12
|
-
const value = stack.pop()
|
|
13
|
-
|
|
14
|
-
// > All objects on the heap start with a shape descriptor, which takes one
|
|
15
|
-
// > pointer size (usually 4 bytes these days, thanks to "pointer
|
|
16
|
-
// > compression" on 64-bit platforms).
|
|
17
|
-
|
|
18
|
-
switch (typeof value) {
|
|
19
|
-
// Types are ordered by frequency
|
|
20
|
-
case 'string':
|
|
21
|
-
// https://stackoverflow.com/a/68791382/356537
|
|
22
|
-
bytes += 12 + 4 * Math.ceil(value.length / 4)
|
|
23
|
-
break
|
|
24
|
-
case 'number':
|
|
25
|
-
bytes += 12 // Shape descriptor + double
|
|
26
|
-
break
|
|
27
|
-
case 'boolean':
|
|
28
|
-
bytes += 4 // Shape descriptor
|
|
29
|
-
break
|
|
30
|
-
case 'object':
|
|
31
|
-
bytes += 4 // Shape descriptor
|
|
32
|
-
|
|
33
|
-
if (value === null) {
|
|
34
|
-
break
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (knownSizes.has(value)) {
|
|
38
|
-
bytes += knownSizes.get(value)!
|
|
39
|
-
break
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (objectList.has(value)) continue
|
|
43
|
-
objectList.add(value)
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
bytes += 4
|
|
47
|
-
stack.push(...value)
|
|
48
|
-
} else {
|
|
49
|
-
bytes += 8
|
|
50
|
-
const keys = Object.getOwnPropertyNames(value)
|
|
51
|
-
for (let i = 0; i < keys.length; i++) {
|
|
52
|
-
bytes += 4
|
|
53
|
-
const key = keys[i]
|
|
54
|
-
const val = value[key]
|
|
55
|
-
if (val !== undefined) stack.push(val)
|
|
56
|
-
stack.push(key)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
break
|
|
60
|
-
case 'function':
|
|
61
|
-
bytes += 8 // Shape descriptor + pointer (assuming functions are shared)
|
|
62
|
-
break
|
|
63
|
-
case 'symbol':
|
|
64
|
-
bytes += 8 // Shape descriptor + pointer
|
|
65
|
-
break
|
|
66
|
-
case 'bigint':
|
|
67
|
-
bytes += 16 // Shape descriptor + BigInt
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (typeof value === 'object' && value !== null) {
|
|
73
|
-
knownSizes.set(value, bytes)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return bytes
|
|
77
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"7.0.0-dev.20260614.1","root":["./src/index.ts","./src/util.ts"]}
|
package/tsconfig.json
DELETED