@keyv/dynamo 1.1.0 → 1.2.1

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 CHANGED
@@ -35,6 +35,20 @@ e.g:
35
35
  const keyv = new KeyvDynamo({ tableName: 'cacheTable' });
36
36
  ```
37
37
 
38
+ ### Using the `createKeyv` helper function
39
+
40
+ The `createKeyv` function is a convenience method that creates a new Keyv instance with the DynamoDB adapter. It automatically sets `useKeyPrefix` to `false` to allow the adapter to handle key prefixing:
41
+
42
+ ```js
43
+ import { createKeyv } from '@keyv/dynamo';
44
+
45
+ const keyv = createKeyv({
46
+ endpoint: 'http://localhost:8000',
47
+ tableName: 'cacheTable',
48
+ namespace: 'my-app'
49
+ });
50
+ ```
51
+
38
52
  ### Accessing the DynamoDB Client
39
53
 
40
54
  The DynamoDB client is exposed as a property for advanced use cases:
package/dist/index.cjs CHANGED
@@ -30,13 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ Keyv: () => import_keyv2.Keyv,
33
34
  KeyvDynamo: () => KeyvDynamo,
35
+ createKeyv: () => createKeyv,
34
36
  default: () => index_default
35
37
  });
36
38
  module.exports = __toCommonJS(index_exports);
37
39
  var import_node_events = __toESM(require("events"), 1);
38
40
  var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
39
41
  var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
42
+ var import_keyv = require("keyv");
43
+ var import_keyv2 = require("keyv");
40
44
  var KeyvDynamo = class extends import_node_events.default {
41
45
  ttlSupport = true;
42
46
  sixHoursInMilliseconds = 6 * 60 * 60 * 1e3;
@@ -201,7 +205,24 @@ var KeyvDynamo = class extends import_node_events.default {
201
205
  }
202
206
  };
203
207
  var index_default = KeyvDynamo;
208
+ function createKeyv(options) {
209
+ const adapter = new KeyvDynamo(options ?? {});
210
+ if (typeof options === "object" && options?.namespace) {
211
+ adapter.namespace = options.namespace;
212
+ const keyv2 = new import_keyv.Keyv(adapter, {
213
+ namespace: options.namespace,
214
+ useKeyPrefix: false
215
+ });
216
+ return keyv2;
217
+ }
218
+ const keyv = new import_keyv.Keyv(adapter, { useKeyPrefix: false });
219
+ keyv.namespace = void 0;
220
+ return keyv;
221
+ }
204
222
  // Annotate the CommonJS export names for ESM import in node:
205
223
  0 && (module.exports = {
206
- KeyvDynamo
224
+ Keyv,
225
+ KeyvDynamo,
226
+ createKeyv
207
227
  });
228
+ /* c8 ignore next -- @preserve */
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
3
3
  import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
4
- import { KeyvStoreAdapter, StoredData } from 'keyv';
4
+ import { KeyvStoreAdapter, StoredData, Keyv } from 'keyv';
5
+ export { Keyv } from 'keyv';
5
6
 
6
7
  declare class KeyvDynamo extends EventEmitter implements KeyvStoreAdapter {
7
8
  ttlSupport: boolean;
@@ -29,5 +30,11 @@ type KeyvDynamoOptions = {
29
30
  dialect?: string;
30
31
  tableName?: string;
31
32
  } & DynamoDBClientConfig;
33
+ /**
34
+ * Will create a Keyv instance with the DynamoDB adapter. This will also set the namespace and useKeyPrefix to false.
35
+ * @param options - Options for the adapter including DynamoDB client configuration and table settings.
36
+ * @returns {Keyv} - Keyv instance with the DynamoDB adapter
37
+ */
38
+ declare function createKeyv(options?: KeyvDynamoOptions | string): Keyv;
32
39
 
33
- export { KeyvDynamo, type KeyvDynamoOptions, KeyvDynamo as default };
40
+ export { KeyvDynamo, type KeyvDynamoOptions, createKeyv, KeyvDynamo as default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
3
3
  import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
4
- import { KeyvStoreAdapter, StoredData } from 'keyv';
4
+ import { KeyvStoreAdapter, StoredData, Keyv } from 'keyv';
5
+ export { Keyv } from 'keyv';
5
6
 
6
7
  declare class KeyvDynamo extends EventEmitter implements KeyvStoreAdapter {
7
8
  ttlSupport: boolean;
@@ -29,5 +30,11 @@ type KeyvDynamoOptions = {
29
30
  dialect?: string;
30
31
  tableName?: string;
31
32
  } & DynamoDBClientConfig;
33
+ /**
34
+ * Will create a Keyv instance with the DynamoDB adapter. This will also set the namespace and useKeyPrefix to false.
35
+ * @param options - Options for the adapter including DynamoDB client configuration and table settings.
36
+ * @returns {Keyv} - Keyv instance with the DynamoDB adapter
37
+ */
38
+ declare function createKeyv(options?: KeyvDynamoOptions | string): Keyv;
32
39
 
33
- export { KeyvDynamo, type KeyvDynamoOptions, KeyvDynamo as default };
40
+ export { KeyvDynamo, type KeyvDynamoOptions, createKeyv, KeyvDynamo as default };
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ import {
12
12
  import {
13
13
  DynamoDBDocument
14
14
  } from "@aws-sdk/lib-dynamodb";
15
+ import { Keyv } from "keyv";
16
+ import { Keyv as Keyv2 } from "keyv";
15
17
  var KeyvDynamo = class extends EventEmitter {
16
18
  ttlSupport = true;
17
19
  sixHoursInMilliseconds = 6 * 60 * 60 * 1e3;
@@ -176,7 +178,24 @@ var KeyvDynamo = class extends EventEmitter {
176
178
  }
177
179
  };
178
180
  var index_default = KeyvDynamo;
181
+ function createKeyv(options) {
182
+ const adapter = new KeyvDynamo(options ?? {});
183
+ if (typeof options === "object" && options?.namespace) {
184
+ adapter.namespace = options.namespace;
185
+ const keyv2 = new Keyv(adapter, {
186
+ namespace: options.namespace,
187
+ useKeyPrefix: false
188
+ });
189
+ return keyv2;
190
+ }
191
+ const keyv = new Keyv(adapter, { useKeyPrefix: false });
192
+ keyv.namespace = void 0;
193
+ return keyv;
194
+ }
179
195
  export {
196
+ Keyv2 as Keyv,
180
197
  KeyvDynamo,
198
+ createKeyv,
181
199
  index_default as default
182
200
  };
201
+ /* c8 ignore next -- @preserve */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/dynamo",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "DynamoDB storage adapter for Keyv",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -35,14 +35,17 @@
35
35
  },
36
36
  "homepage": "https://github.com/jaredwray/keyv",
37
37
  "dependencies": {
38
- "@aws-sdk/client-dynamodb": "^3.883.0",
39
- "@aws-sdk/lib-dynamodb": "^3.883.0"
38
+ "@aws-sdk/client-dynamodb": "^3.917.0",
39
+ "@aws-sdk/lib-dynamodb": "^3.917.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@biomejs/biome": "^2.2.3",
43
- "vitest": "^3.2.4",
44
- "@keyv/test-suite": "^2.1.1",
45
- "keyv": "^5.5.1"
42
+ "@biomejs/biome": "^2.3.0",
43
+ "@vitest/coverage-v8": "^4.0.3",
44
+ "vitest": "^4.0.3",
45
+ "@keyv/test-suite": "^2.1.1"
46
+ },
47
+ "peerDependencies": {
48
+ "keyv": "^5.5.3"
46
49
  },
47
50
  "tsd": {
48
51
  "directory": "test"
@@ -53,8 +56,10 @@
53
56
  ],
54
57
  "scripts": {
55
58
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
56
- "test": "biome check --write && vitest run --coverage",
57
- "test:ci": "biome check && vitest --run --sequence.setupFiles=list --coverage",
59
+ "lint": "biome check --write --error-on-warnings",
60
+ "lint:ci": "biome check --error-on-warnings",
61
+ "test": "pnpm lint && vitest run --coverage",
62
+ "test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
58
63
  "clean": "rimraf ./node_modules ./coverage ./dist"
59
64
  }
60
65
  }