@carddb/node 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/README.md +74 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +67 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @carddb/node
|
|
2
|
+
|
|
3
|
+
CardDB client for Node.js, Bun, and Deno.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @carddb/node
|
|
9
|
+
# or
|
|
10
|
+
bun add @carddb/node
|
|
11
|
+
# or
|
|
12
|
+
deno add npm:@carddb/node
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { CardDBClient, MemoryCache, gte, ilike } from '@carddb/node'
|
|
19
|
+
|
|
20
|
+
const client = new CardDBClient({
|
|
21
|
+
apiKey: 'carddb_xxx...', // Optional, increases rate limits
|
|
22
|
+
cache: new MemoryCache(), // Optional in-memory caching
|
|
23
|
+
defaultPublisher: 'pokemon',
|
|
24
|
+
defaultGame: 'tcg',
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Search for cards with filtering
|
|
28
|
+
const cards = await client.records.search({
|
|
29
|
+
datasetKey: 'cards',
|
|
30
|
+
filter: (f) =>
|
|
31
|
+
f
|
|
32
|
+
.where('hp', gte(100))
|
|
33
|
+
.where('name', ilike('%pikachu%')),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Iterate through all results (auto-paginates)
|
|
37
|
+
for await (const card of cards) {
|
|
38
|
+
console.log(card.data.name)
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## MemoryCache
|
|
43
|
+
|
|
44
|
+
Simple in-memory cache with TTL support:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { MemoryCache } from '@carddb/node'
|
|
48
|
+
|
|
49
|
+
const cache = new MemoryCache()
|
|
50
|
+
|
|
51
|
+
// Use with client
|
|
52
|
+
const client = new CardDBClient({
|
|
53
|
+
cache,
|
|
54
|
+
cacheTtl: 300, // 5 minutes default
|
|
55
|
+
cacheTtls: {
|
|
56
|
+
publishers: 3600, // 1 hour for publishers
|
|
57
|
+
records: 60, // 1 minute for records
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Manual cache management
|
|
62
|
+
cache.cleanup() // Remove expired entries
|
|
63
|
+
cache.clear() // Clear all entries
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For production multi-instance deployments, consider implementing a Redis-based cache using the `Cache` interface.
|
|
67
|
+
|
|
68
|
+
## Full Documentation
|
|
69
|
+
|
|
70
|
+
See the [main README](../../README.md) for complete documentation.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@carddb/client');
|
|
4
|
+
|
|
5
|
+
// src/cache.ts
|
|
6
|
+
var MemoryCache = class {
|
|
7
|
+
store = /* @__PURE__ */ new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Get a value from the cache
|
|
10
|
+
*/
|
|
11
|
+
get(key) {
|
|
12
|
+
const entry = this.store.get(key);
|
|
13
|
+
if (!entry) return null;
|
|
14
|
+
if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {
|
|
15
|
+
this.store.delete(key);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return entry.value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set a value in the cache
|
|
22
|
+
*
|
|
23
|
+
* @param key - The cache key
|
|
24
|
+
* @param value - The value to cache
|
|
25
|
+
* @param ttl - Time to live in seconds (optional, undefined = no expiry)
|
|
26
|
+
*/
|
|
27
|
+
set(key, value, ttl) {
|
|
28
|
+
const expiresAt = ttl !== void 0 ? Date.now() + ttl * 1e3 : null;
|
|
29
|
+
this.store.set(key, { value, expiresAt });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete a value from the cache
|
|
33
|
+
*/
|
|
34
|
+
delete(key) {
|
|
35
|
+
this.store.delete(key);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clear all cached values
|
|
39
|
+
*/
|
|
40
|
+
clear() {
|
|
41
|
+
this.store.clear();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a key exists and is not expired
|
|
45
|
+
*/
|
|
46
|
+
has(key) {
|
|
47
|
+
return this.get(key) !== null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the number of entries (including expired ones that haven't been cleaned up)
|
|
51
|
+
*/
|
|
52
|
+
get size() {
|
|
53
|
+
return this.store.size;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Clean up expired entries
|
|
57
|
+
* Call this periodically if you want to reclaim memory from expired entries
|
|
58
|
+
*/
|
|
59
|
+
cleanup() {
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
for (const [key, entry] of this.store.entries()) {
|
|
62
|
+
if (entry.expiresAt !== null && now > entry.expiresAt) {
|
|
63
|
+
this.store.delete(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.MemoryCache = MemoryCache;
|
|
70
|
+
Object.keys(client).forEach(function (k) {
|
|
71
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return client[k]; }
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.cjs.map
|
|
77
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache.ts"],"names":[],"mappings":";;;;;AAiCO,IAAM,cAAN,MAAmC;AAAA,EAChC,KAAA,uBAAY,GAAA,EAAiC;AAAA;AAAA;AAAA;AAAA,EAKrD,IAAO,GAAA,EAAuB;AAC5B,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,GAAG,CAAA;AAChC,IAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AAGnB,IAAA,IAAI,MAAM,SAAA,KAAc,IAAA,IAAQ,KAAK,GAAA,EAAI,GAAI,MAAM,SAAA,EAAW;AAC5D,MAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AACrB,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,OAAO,KAAA,CAAM,KAAA;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA,CAAO,GAAA,EAAa,KAAA,EAAU,GAAA,EAAoB;AAChD,IAAA,MAAM,YAAY,GAAA,KAAQ,MAAA,GAAY,KAAK,GAAA,EAAI,GAAI,MAAM,GAAA,GAAO,IAAA;AAChE,IAAA,IAAA,CAAK,MAAM,GAAA,CAAI,GAAA,EAAK,EAAE,KAAA,EAAO,WAAW,CAAA;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,GAAA,EAAmB;AACxB,IAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,MAAM,KAAA,EAAM;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,GAAA,EAAsB;AACxB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA,KAAM,IAAA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,KAAA,CAAM,IAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAA,GAAgB;AACd,IAAA,MAAM,GAAA,GAAM,KAAK,GAAA,EAAI;AACrB,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,IAAA,CAAK,KAAA,CAAM,SAAQ,EAAG;AAC/C,MAAA,IAAI,KAAA,CAAM,SAAA,KAAc,IAAA,IAAQ,GAAA,GAAM,MAAM,SAAA,EAAW;AACrD,QAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["/**\n * In-memory cache implementation with TTL support for Node.js\n */\n\nimport type { Cache } from '@carddb/core'\n\ninterface CacheEntry<T> {\n value: T\n expiresAt: number | null\n}\n\n/**\n * Simple in-memory cache with TTL support.\n * Suitable for server-side applications where memory caching is appropriate.\n *\n * For production use with multiple instances, consider using Redis or another\n * distributed cache that implements the Cache interface.\n *\n * @example\n * import { CardDBClient, MemoryCache } from '@carddb/node'\n *\n * const client = new CardDBClient({\n * cache: new MemoryCache(),\n * cacheTtl: 300 // 5 minutes\n * })\n *\n * @example Manual usage\n * const cache = new MemoryCache()\n * cache.set('key', 'value', 60) // expires in 60 seconds\n * cache.get('key') // => 'value'\n * // After 60 seconds...\n * cache.get('key') // => null\n */\nexport class MemoryCache implements Cache {\n private store = new Map<string, CacheEntry<unknown>>()\n\n /**\n * Get a value from the cache\n */\n get<T>(key: string): T | null {\n const entry = this.store.get(key) as CacheEntry<T> | undefined\n if (!entry) return null\n\n // Check if expired\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key)\n return null\n }\n\n return entry.value\n }\n\n /**\n * Set a value in the cache\n *\n * @param key - The cache key\n * @param value - The value to cache\n * @param ttl - Time to live in seconds (optional, undefined = no expiry)\n */\n set<T>(key: string, value: T, ttl?: number): void {\n const expiresAt = ttl !== undefined ? Date.now() + ttl * 1000 : null\n this.store.set(key, { value, expiresAt })\n }\n\n /**\n * Delete a value from the cache\n */\n delete(key: string): void {\n this.store.delete(key)\n }\n\n /**\n * Clear all cached values\n */\n clear(): void {\n this.store.clear()\n }\n\n /**\n * Check if a key exists and is not expired\n */\n has(key: string): boolean {\n return this.get(key) !== null\n }\n\n /**\n * Get the number of entries (including expired ones that haven't been cleaned up)\n */\n get size(): number {\n return this.store.size\n }\n\n /**\n * Clean up expired entries\n * Call this periodically if you want to reclaim memory from expired entries\n */\n cleanup(): void {\n const now = Date.now()\n for (const [key, entry] of this.store.entries()) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key)\n }\n }\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Cache } from '@carddb/core';
|
|
2
|
+
export * from '@carddb/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory cache implementation with TTL support for Node.js
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Simple in-memory cache with TTL support.
|
|
10
|
+
* Suitable for server-side applications where memory caching is appropriate.
|
|
11
|
+
*
|
|
12
|
+
* For production use with multiple instances, consider using Redis or another
|
|
13
|
+
* distributed cache that implements the Cache interface.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { CardDBClient, MemoryCache } from '@carddb/node'
|
|
17
|
+
*
|
|
18
|
+
* const client = new CardDBClient({
|
|
19
|
+
* cache: new MemoryCache(),
|
|
20
|
+
* cacheTtl: 300 // 5 minutes
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @example Manual usage
|
|
24
|
+
* const cache = new MemoryCache()
|
|
25
|
+
* cache.set('key', 'value', 60) // expires in 60 seconds
|
|
26
|
+
* cache.get('key') // => 'value'
|
|
27
|
+
* // After 60 seconds...
|
|
28
|
+
* cache.get('key') // => null
|
|
29
|
+
*/
|
|
30
|
+
declare class MemoryCache implements Cache {
|
|
31
|
+
private store;
|
|
32
|
+
/**
|
|
33
|
+
* Get a value from the cache
|
|
34
|
+
*/
|
|
35
|
+
get<T>(key: string): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* Set a value in the cache
|
|
38
|
+
*
|
|
39
|
+
* @param key - The cache key
|
|
40
|
+
* @param value - The value to cache
|
|
41
|
+
* @param ttl - Time to live in seconds (optional, undefined = no expiry)
|
|
42
|
+
*/
|
|
43
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a value from the cache
|
|
46
|
+
*/
|
|
47
|
+
delete(key: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clear all cached values
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a key exists and is not expired
|
|
54
|
+
*/
|
|
55
|
+
has(key: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get the number of entries (including expired ones that haven't been cleaned up)
|
|
58
|
+
*/
|
|
59
|
+
get size(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Clean up expired entries
|
|
62
|
+
* Call this periodically if you want to reclaim memory from expired entries
|
|
63
|
+
*/
|
|
64
|
+
cleanup(): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { MemoryCache };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Cache } from '@carddb/core';
|
|
2
|
+
export * from '@carddb/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory cache implementation with TTL support for Node.js
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Simple in-memory cache with TTL support.
|
|
10
|
+
* Suitable for server-side applications where memory caching is appropriate.
|
|
11
|
+
*
|
|
12
|
+
* For production use with multiple instances, consider using Redis or another
|
|
13
|
+
* distributed cache that implements the Cache interface.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { CardDBClient, MemoryCache } from '@carddb/node'
|
|
17
|
+
*
|
|
18
|
+
* const client = new CardDBClient({
|
|
19
|
+
* cache: new MemoryCache(),
|
|
20
|
+
* cacheTtl: 300 // 5 minutes
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @example Manual usage
|
|
24
|
+
* const cache = new MemoryCache()
|
|
25
|
+
* cache.set('key', 'value', 60) // expires in 60 seconds
|
|
26
|
+
* cache.get('key') // => 'value'
|
|
27
|
+
* // After 60 seconds...
|
|
28
|
+
* cache.get('key') // => null
|
|
29
|
+
*/
|
|
30
|
+
declare class MemoryCache implements Cache {
|
|
31
|
+
private store;
|
|
32
|
+
/**
|
|
33
|
+
* Get a value from the cache
|
|
34
|
+
*/
|
|
35
|
+
get<T>(key: string): T | null;
|
|
36
|
+
/**
|
|
37
|
+
* Set a value in the cache
|
|
38
|
+
*
|
|
39
|
+
* @param key - The cache key
|
|
40
|
+
* @param value - The value to cache
|
|
41
|
+
* @param ttl - Time to live in seconds (optional, undefined = no expiry)
|
|
42
|
+
*/
|
|
43
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a value from the cache
|
|
46
|
+
*/
|
|
47
|
+
delete(key: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clear all cached values
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a key exists and is not expired
|
|
54
|
+
*/
|
|
55
|
+
has(key: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Get the number of entries (including expired ones that haven't been cleaned up)
|
|
58
|
+
*/
|
|
59
|
+
get size(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Clean up expired entries
|
|
62
|
+
* Call this periodically if you want to reclaim memory from expired entries
|
|
63
|
+
*/
|
|
64
|
+
cleanup(): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { MemoryCache };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export * from '@carddb/client';
|
|
2
|
+
|
|
3
|
+
// src/cache.ts
|
|
4
|
+
var MemoryCache = class {
|
|
5
|
+
store = /* @__PURE__ */ new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Get a value from the cache
|
|
8
|
+
*/
|
|
9
|
+
get(key) {
|
|
10
|
+
const entry = this.store.get(key);
|
|
11
|
+
if (!entry) return null;
|
|
12
|
+
if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {
|
|
13
|
+
this.store.delete(key);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return entry.value;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Set a value in the cache
|
|
20
|
+
*
|
|
21
|
+
* @param key - The cache key
|
|
22
|
+
* @param value - The value to cache
|
|
23
|
+
* @param ttl - Time to live in seconds (optional, undefined = no expiry)
|
|
24
|
+
*/
|
|
25
|
+
set(key, value, ttl) {
|
|
26
|
+
const expiresAt = ttl !== void 0 ? Date.now() + ttl * 1e3 : null;
|
|
27
|
+
this.store.set(key, { value, expiresAt });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Delete a value from the cache
|
|
31
|
+
*/
|
|
32
|
+
delete(key) {
|
|
33
|
+
this.store.delete(key);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Clear all cached values
|
|
37
|
+
*/
|
|
38
|
+
clear() {
|
|
39
|
+
this.store.clear();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a key exists and is not expired
|
|
43
|
+
*/
|
|
44
|
+
has(key) {
|
|
45
|
+
return this.get(key) !== null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the number of entries (including expired ones that haven't been cleaned up)
|
|
49
|
+
*/
|
|
50
|
+
get size() {
|
|
51
|
+
return this.store.size;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Clean up expired entries
|
|
55
|
+
* Call this periodically if you want to reclaim memory from expired entries
|
|
56
|
+
*/
|
|
57
|
+
cleanup() {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
for (const [key, entry] of this.store.entries()) {
|
|
60
|
+
if (entry.expiresAt !== null && now > entry.expiresAt) {
|
|
61
|
+
this.store.delete(key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { MemoryCache };
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache.ts"],"names":[],"mappings":";;;AAiCO,IAAM,cAAN,MAAmC;AAAA,EAChC,KAAA,uBAAY,GAAA,EAAiC;AAAA;AAAA;AAAA;AAAA,EAKrD,IAAO,GAAA,EAAuB;AAC5B,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,GAAG,CAAA;AAChC,IAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AAGnB,IAAA,IAAI,MAAM,SAAA,KAAc,IAAA,IAAQ,KAAK,GAAA,EAAI,GAAI,MAAM,SAAA,EAAW;AAC5D,MAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AACrB,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,OAAO,KAAA,CAAM,KAAA;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,GAAA,CAAO,GAAA,EAAa,KAAA,EAAU,GAAA,EAAoB;AAChD,IAAA,MAAM,YAAY,GAAA,KAAQ,MAAA,GAAY,KAAK,GAAA,EAAI,GAAI,MAAM,GAAA,GAAO,IAAA;AAChE,IAAA,IAAA,CAAK,MAAM,GAAA,CAAI,GAAA,EAAK,EAAE,KAAA,EAAO,WAAW,CAAA;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,GAAA,EAAmB;AACxB,IAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,MAAM,KAAA,EAAM;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,GAAA,EAAsB;AACxB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,GAAG,CAAA,KAAM,IAAA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,KAAA,CAAM,IAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAA,GAAgB;AACd,IAAA,MAAM,GAAA,GAAM,KAAK,GAAA,EAAI;AACrB,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,IAAA,CAAK,KAAA,CAAM,SAAQ,EAAG;AAC/C,MAAA,IAAI,KAAA,CAAM,SAAA,KAAc,IAAA,IAAQ,GAAA,GAAM,MAAM,SAAA,EAAW;AACrD,QAAA,IAAA,CAAK,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF","file":"index.js","sourcesContent":["/**\n * In-memory cache implementation with TTL support for Node.js\n */\n\nimport type { Cache } from '@carddb/core'\n\ninterface CacheEntry<T> {\n value: T\n expiresAt: number | null\n}\n\n/**\n * Simple in-memory cache with TTL support.\n * Suitable for server-side applications where memory caching is appropriate.\n *\n * For production use with multiple instances, consider using Redis or another\n * distributed cache that implements the Cache interface.\n *\n * @example\n * import { CardDBClient, MemoryCache } from '@carddb/node'\n *\n * const client = new CardDBClient({\n * cache: new MemoryCache(),\n * cacheTtl: 300 // 5 minutes\n * })\n *\n * @example Manual usage\n * const cache = new MemoryCache()\n * cache.set('key', 'value', 60) // expires in 60 seconds\n * cache.get('key') // => 'value'\n * // After 60 seconds...\n * cache.get('key') // => null\n */\nexport class MemoryCache implements Cache {\n private store = new Map<string, CacheEntry<unknown>>()\n\n /**\n * Get a value from the cache\n */\n get<T>(key: string): T | null {\n const entry = this.store.get(key) as CacheEntry<T> | undefined\n if (!entry) return null\n\n // Check if expired\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key)\n return null\n }\n\n return entry.value\n }\n\n /**\n * Set a value in the cache\n *\n * @param key - The cache key\n * @param value - The value to cache\n * @param ttl - Time to live in seconds (optional, undefined = no expiry)\n */\n set<T>(key: string, value: T, ttl?: number): void {\n const expiresAt = ttl !== undefined ? Date.now() + ttl * 1000 : null\n this.store.set(key, { value, expiresAt })\n }\n\n /**\n * Delete a value from the cache\n */\n delete(key: string): void {\n this.store.delete(key)\n }\n\n /**\n * Clear all cached values\n */\n clear(): void {\n this.store.clear()\n }\n\n /**\n * Check if a key exists and is not expired\n */\n has(key: string): boolean {\n return this.get(key) !== null\n }\n\n /**\n * Get the number of entries (including expired ones that haven't been cleaned up)\n */\n get size(): number {\n return this.store.size\n }\n\n /**\n * Clean up expired entries\n * Call this periodically if you want to reclaim memory from expired entries\n */\n cleanup(): void {\n const now = Date.now()\n for (const [key, entry] of this.store.entries()) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key)\n }\n }\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@carddb/node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CardDB client for Node.js, Bun, and Deno",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": ["dist"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"test": "bun test",
|
|
27
|
+
"lint": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"keywords": ["carddb", "api", "client", "graphql", "card-games", "node", "bun", "deno"],
|
|
30
|
+
"author": "CardDB Team",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/xtda/carddb-js.git",
|
|
35
|
+
"directory": "packages/node"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/xtda/carddb-js#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/xtda/carddb-js/issues"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@carddb/client": "0.1.0",
|
|
43
|
+
"@carddb/core": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"sideEffects": false
|
|
49
|
+
}
|