@awsless/dynamodb-server 0.0.12 → 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/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@awsless/dynamodb-server",
3
- "version": "0.0.12",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
+ "type": "module",
5
6
  "main": "./dist/index.js",
6
- "module": "./dist/index.mjs",
7
+ "module": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",
8
9
  "files": [
9
10
  "dist"
@@ -15,16 +16,27 @@
15
16
  "bugs": {
16
17
  "url": "https://github.com/awsless/awsless/issues"
17
18
  },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
18
25
  "dependencies": {
19
26
  "@aws-sdk/client-dynamodb": "3.363.0",
20
- "@aws-sdk/lib-dynamodb": "3.363.0",
21
- "@aws-sdk/url-parser": "^3.272.0",
22
- "dynamo-db-local": "^4.0.0",
23
- "sleep-await": "^1.0.2"
27
+ "@aws-sdk/lib-dynamodb": "3.363.0"
28
+ },
29
+ "optionalDependencies": {
30
+ "dynamo-db-local": "^10.3.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bun": "^1.1.6",
34
+ "bun-types": "^1.1.6",
35
+ "typescript": "^5.5.4"
24
36
  },
25
37
  "scripts": {
26
- "test": "pnpm code test",
27
- "build": "pnpm tsup src/index.ts --format cjs,esm --dts --clean --external vitest",
28
- "prepublish": "if pnpm test; then pnpm build; else exit; fi"
38
+ "test": "bun test",
39
+ "build": "pnpm tsup src/index.ts --format esm --dts --clean --external dynamo-db-local",
40
+ "prepublish": "if bun test; then pnpm build; else exit; fi"
29
41
  }
30
42
  }
package/dist/index.d.mts DELETED
@@ -1,24 +0,0 @@
1
- import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
- import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
-
4
- declare class DynamoDBServer {
5
- private region;
6
- private client?;
7
- private documentClient?;
8
- private endpoint;
9
- private process;
10
- constructor(region?: string);
11
- listen(port: number): Promise<void>;
12
- /** Kill the DynamoDB server. */
13
- kill(): Promise<void>;
14
- /** Ping the DynamoDB server if its ready. */
15
- ping(): Promise<boolean>;
16
- /** Ping the DynamoDB server untill its ready. */
17
- wait(times?: number): Promise<void>;
18
- /** Get DynamoDBClient connected to dynamodb local. */
19
- getClient(): DynamoDBClient;
20
- /** Get DynamoDBDocumentClient connected to dynamodb local. */
21
- getDocumentClient(): DynamoDBDocumentClient;
22
- }
23
-
24
- export { DynamoDBServer };
package/dist/index.mjs DELETED
@@ -1,84 +0,0 @@
1
- // src/index.ts
2
- import { DynamoDBClient, ListTablesCommand } from "@aws-sdk/client-dynamodb";
3
- import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
4
- import { parseUrl } from "@aws-sdk/url-parser";
5
- import { sleepAwait } from "sleep-await";
6
- import { spawn } from "dynamo-db-local";
7
- var DynamoDBServer = class {
8
- constructor(region = "us-east-1") {
9
- this.region = region;
10
- this.endpoint = parseUrl(`http://localhost`);
11
- }
12
- client;
13
- documentClient;
14
- endpoint;
15
- process;
16
- async listen(port) {
17
- if (this.process) {
18
- throw new Error(`DynamoDB server is already listening on port: ${this.endpoint.port}`);
19
- }
20
- if (port < 0 || port >= 65536) {
21
- throw new RangeError(`Port should be >= 0 and < 65536. Received ${port}.`);
22
- }
23
- this.endpoint.port = port;
24
- this.process = await spawn({ port });
25
- }
26
- /** Kill the DynamoDB server. */
27
- async kill() {
28
- if (this.process) {
29
- await this.process.kill();
30
- this.process = void 0;
31
- }
32
- }
33
- /** Ping the DynamoDB server if its ready. */
34
- async ping() {
35
- const client = this.getClient();
36
- const command = new ListTablesCommand({});
37
- try {
38
- const response = await client.send(command);
39
- return Array.isArray(response.TableNames);
40
- } catch (error) {
41
- return false;
42
- }
43
- }
44
- /** Ping the DynamoDB server untill its ready. */
45
- async wait(times = 10) {
46
- while (times--) {
47
- if (await this.ping()) {
48
- return;
49
- }
50
- await sleepAwait(100 * times);
51
- }
52
- throw new Error("DynamoDB server is unavailable");
53
- }
54
- /** Get DynamoDBClient connected to dynamodb local. */
55
- getClient() {
56
- if (!this.client) {
57
- this.client = new DynamoDBClient({
58
- maxAttempts: 3,
59
- endpoint: this.endpoint,
60
- region: this.region,
61
- tls: false,
62
- credentials: {
63
- accessKeyId: "fake",
64
- secretAccessKey: "fake"
65
- }
66
- });
67
- }
68
- return this.client;
69
- }
70
- /** Get DynamoDBDocumentClient connected to dynamodb local. */
71
- getDocumentClient() {
72
- if (!this.documentClient) {
73
- this.documentClient = DynamoDBDocumentClient.from(this.getClient(), {
74
- marshallOptions: {
75
- removeUndefinedValues: true
76
- }
77
- });
78
- }
79
- return this.documentClient;
80
- }
81
- };
82
- export {
83
- DynamoDBServer
84
- };