@goldstack/template-dynamodb 0.2.0 → 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/dist/src/dynamoDBData.d.ts +6 -6
- package/dist/src/dynamoDBData.js +102 -102
- package/dist/src/dynamoDBMigrations.d.ts +10 -10
- package/dist/src/dynamoDBMigrations.js +33 -33
- package/dist/src/dynamoDBPackageUtils.d.ts +4 -4
- package/dist/src/dynamoDBPackageUtils.js +24 -24
- package/dist/src/localDynamoDB.d.ts +9 -9
- package/dist/src/localDynamoDB.js +64 -64
- package/dist/src/templateDynamoDB.d.ts +3 -3
- package/dist/src/templateDynamoDB.js +18 -18
- package/dist/src/templateDynamoDBTable.d.ts +27 -27
- package/dist/src/templateDynamoDBTable.js +118 -118
- package/dist/src/types/DynamoDBDeployment.d.ts +10 -10
- package/dist/src/types/DynamoDBDeployment.js +2 -2
- package/dist/src/types/DynamoDBDeploymentConfiguration.d.ts +15 -15
- package/dist/src/types/DynamoDBDeploymentConfiguration.js +2 -2
- package/dist/src/types/DynamoDBPackage.d.ts +21 -21
- package/dist/src/types/DynamoDBPackage.js +2 -2
- package/dist/src/types/DynamoDBPackageConfiguration.d.ts +13 -13
- package/dist/src/types/DynamoDBPackageConfiguration.js +2 -2
- package/dist/src/umzugDynamoDBStorage.d.ts +21 -21
- package/dist/src/umzugDynamoDBStorage.js +75 -75
- package/package.json +10 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
-
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
3
|
-
import { DynamoDBDeployment, DynamoDBPackage } from './templateDynamoDB';
|
|
4
|
-
export declare function assertTableActive(packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB): Promise<void>;
|
|
5
|
-
export declare const assertTable: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB) => Promise<void>;
|
|
6
|
-
export declare const deleteTable: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB) => Promise<void>;
|
|
1
|
+
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
+
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
3
|
+
import { DynamoDBDeployment, DynamoDBPackage } from './templateDynamoDB';
|
|
4
|
+
export declare function assertTableActive(packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB): Promise<void>;
|
|
5
|
+
export declare const assertTable: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB) => Promise<void>;
|
|
6
|
+
export declare const deleteTable: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, client: DynamoDB) => Promise<void>;
|
|
7
7
|
//# sourceMappingURL=dynamoDBData.d.ts.map
|
package/dist/src/dynamoDBData.js
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteTable = exports.assertTable = exports.assertTableActive = void 0;
|
|
4
|
-
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
5
|
-
function sleep(ms) {
|
|
6
|
-
return new Promise((resolve) => {
|
|
7
|
-
setTimeout(resolve, ms);
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
async function assertTableActive(packageConfig, deploymentName, client) {
|
|
11
|
-
var _a;
|
|
12
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
13
|
-
let retries = 0;
|
|
14
|
-
let tableStatus = undefined;
|
|
15
|
-
// ensure that able is ACTIVE before proceeding
|
|
16
|
-
while (tableStatus !== 'ACTIVE' && retries < 120) {
|
|
17
|
-
try {
|
|
18
|
-
const tableInfo = await client
|
|
19
|
-
.describeTable({ TableName: tableName })
|
|
20
|
-
.promise();
|
|
21
|
-
tableStatus = (_a = tableInfo.Table) === null || _a === void 0 ? void 0 : _a.TableStatus;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
console.warn(`Error retrieving table information: ${e.code}.\n${e}`);
|
|
25
|
-
}
|
|
26
|
-
console.debug(`DynamoDB table '${tableName}' created. Current table status: ${tableStatus}. Retries: ${retries}`);
|
|
27
|
-
await sleep(1000);
|
|
28
|
-
retries++;
|
|
29
|
-
}
|
|
30
|
-
if (retries === 120) {
|
|
31
|
-
throw new Error(`DynamoDB table '${tableName}' creation timed out. Status: ${tableStatus}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.assertTableActive = assertTableActive;
|
|
35
|
-
const assertTable = async (packageConfig, deploymentName, client) => {
|
|
36
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
37
|
-
const res = client
|
|
38
|
-
.createTable({
|
|
39
|
-
TableName: tableName,
|
|
40
|
-
AttributeDefinitions: [
|
|
41
|
-
{
|
|
42
|
-
AttributeName: 'pk',
|
|
43
|
-
AttributeType: 'S',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
AttributeName: 'sk',
|
|
47
|
-
AttributeType: 'S',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
KeySchema: [
|
|
51
|
-
{
|
|
52
|
-
AttributeName: 'pk',
|
|
53
|
-
KeyType: 'HASH',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
AttributeName: 'sk',
|
|
57
|
-
KeyType: 'RANGE',
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
BillingMode: 'PAY_PER_REQUEST',
|
|
61
|
-
})
|
|
62
|
-
.promise();
|
|
63
|
-
await new Promise((resolve, reject) => {
|
|
64
|
-
res
|
|
65
|
-
.then(async () => {
|
|
66
|
-
console.debug(`DynamoDB table '${tableName}' created.`);
|
|
67
|
-
resolve();
|
|
68
|
-
})
|
|
69
|
-
.catch((e) => {
|
|
70
|
-
if (e.code === 'ResourceInUseException') {
|
|
71
|
-
// all good if table exists already
|
|
72
|
-
resolve();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
reject(e);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
exports.assertTable = assertTable;
|
|
80
|
-
const deleteTable = async (packageConfig, deploymentName, client) => {
|
|
81
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
82
|
-
const res = client
|
|
83
|
-
.deleteTable({
|
|
84
|
-
TableName: tableName,
|
|
85
|
-
})
|
|
86
|
-
.promise();
|
|
87
|
-
await new Promise((resolve, reject) => {
|
|
88
|
-
res
|
|
89
|
-
.then(async () => {
|
|
90
|
-
resolve();
|
|
91
|
-
})
|
|
92
|
-
.catch((e) => {
|
|
93
|
-
if (e.code === 'ResourceNotFoundException') {
|
|
94
|
-
// all good if table already deleted
|
|
95
|
-
resolve();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
reject(e);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
exports.deleteTable = deleteTable;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteTable = exports.assertTable = exports.assertTableActive = void 0;
|
|
4
|
+
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
setTimeout(resolve, ms);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async function assertTableActive(packageConfig, deploymentName, client) {
|
|
11
|
+
var _a;
|
|
12
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
13
|
+
let retries = 0;
|
|
14
|
+
let tableStatus = undefined;
|
|
15
|
+
// ensure that able is ACTIVE before proceeding
|
|
16
|
+
while (tableStatus !== 'ACTIVE' && retries < 120) {
|
|
17
|
+
try {
|
|
18
|
+
const tableInfo = await client
|
|
19
|
+
.describeTable({ TableName: tableName })
|
|
20
|
+
.promise();
|
|
21
|
+
tableStatus = (_a = tableInfo.Table) === null || _a === void 0 ? void 0 : _a.TableStatus;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.warn(`Error retrieving table information: ${e.code}.\n${e}`);
|
|
25
|
+
}
|
|
26
|
+
console.debug(`DynamoDB table '${tableName}' created. Current table status: ${tableStatus}. Retries: ${retries}`);
|
|
27
|
+
await sleep(1000);
|
|
28
|
+
retries++;
|
|
29
|
+
}
|
|
30
|
+
if (retries === 120) {
|
|
31
|
+
throw new Error(`DynamoDB table '${tableName}' creation timed out. Status: ${tableStatus}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.assertTableActive = assertTableActive;
|
|
35
|
+
const assertTable = async (packageConfig, deploymentName, client) => {
|
|
36
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
37
|
+
const res = client
|
|
38
|
+
.createTable({
|
|
39
|
+
TableName: tableName,
|
|
40
|
+
AttributeDefinitions: [
|
|
41
|
+
{
|
|
42
|
+
AttributeName: 'pk',
|
|
43
|
+
AttributeType: 'S',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
AttributeName: 'sk',
|
|
47
|
+
AttributeType: 'S',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
KeySchema: [
|
|
51
|
+
{
|
|
52
|
+
AttributeName: 'pk',
|
|
53
|
+
KeyType: 'HASH',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
AttributeName: 'sk',
|
|
57
|
+
KeyType: 'RANGE',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
BillingMode: 'PAY_PER_REQUEST',
|
|
61
|
+
})
|
|
62
|
+
.promise();
|
|
63
|
+
await new Promise((resolve, reject) => {
|
|
64
|
+
res
|
|
65
|
+
.then(async () => {
|
|
66
|
+
console.debug(`DynamoDB table '${tableName}' created.`);
|
|
67
|
+
resolve();
|
|
68
|
+
})
|
|
69
|
+
.catch((e) => {
|
|
70
|
+
if (e.code === 'ResourceInUseException') {
|
|
71
|
+
// all good if table exists already
|
|
72
|
+
resolve();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
reject(e);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
exports.assertTable = assertTable;
|
|
80
|
+
const deleteTable = async (packageConfig, deploymentName, client) => {
|
|
81
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
82
|
+
const res = client
|
|
83
|
+
.deleteTable({
|
|
84
|
+
TableName: tableName,
|
|
85
|
+
})
|
|
86
|
+
.promise();
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
res
|
|
89
|
+
.then(async () => {
|
|
90
|
+
resolve();
|
|
91
|
+
})
|
|
92
|
+
.catch((e) => {
|
|
93
|
+
if (e.code === 'ResourceNotFoundException') {
|
|
94
|
+
// all good if table already deleted
|
|
95
|
+
resolve();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
reject(e);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.deleteTable = deleteTable;
|
|
103
103
|
//# sourceMappingURL=dynamoDBData.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
-
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
3
|
-
import DynamoDBPackage, { DynamoDBDeployment } from './types/DynamoDBPackage';
|
|
4
|
-
import { InputMigrations } from 'umzug/lib/types';
|
|
5
|
-
export interface DynamoDBContext {
|
|
6
|
-
client: DynamoDB;
|
|
7
|
-
tableName: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const performMigrations: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, migrations: InputMigrations<DynamoDBContext>, client: DynamoDB) => Promise<void>;
|
|
10
|
-
export declare const migrateDownTo: (migrationName: string, packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, migrations: InputMigrations<DynamoDBContext>, client: DynamoDB) => Promise<void>;
|
|
1
|
+
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
+
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
3
|
+
import DynamoDBPackage, { DynamoDBDeployment } from './types/DynamoDBPackage';
|
|
4
|
+
import { InputMigrations } from 'umzug/lib/types';
|
|
5
|
+
export interface DynamoDBContext {
|
|
6
|
+
client: DynamoDB;
|
|
7
|
+
tableName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const performMigrations: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, migrations: InputMigrations<DynamoDBContext>, client: DynamoDB) => Promise<void>;
|
|
10
|
+
export declare const migrateDownTo: (migrationName: string, packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName: string, migrations: InputMigrations<DynamoDBContext>, client: DynamoDB) => Promise<void>;
|
|
11
11
|
//# sourceMappingURL=dynamoDBMigrations.d.ts.map
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateDownTo = exports.performMigrations = void 0;
|
|
4
|
-
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
5
|
-
const umzugDynamoDBStorage_1 = require("./umzugDynamoDBStorage");
|
|
6
|
-
const umzug_1 = require("umzug");
|
|
7
|
-
const performMigrations = async (packageConfig, deploymentName, migrations, client) => {
|
|
8
|
-
const umzug = await initUmzug(packageConfig, deploymentName, client, migrations);
|
|
9
|
-
await umzug.up();
|
|
10
|
-
};
|
|
11
|
-
exports.performMigrations = performMigrations;
|
|
12
|
-
const migrateDownTo = async (migrationName, packageConfig, deploymentName, migrations, client) => {
|
|
13
|
-
const umzug = await initUmzug(packageConfig, deploymentName, client, migrations);
|
|
14
|
-
await umzug.down({ to: migrationName });
|
|
15
|
-
};
|
|
16
|
-
exports.migrateDownTo = migrateDownTo;
|
|
17
|
-
async function initUmzug(packageConfig, deploymentName, client, migrations) {
|
|
18
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
19
|
-
const storage = new umzugDynamoDBStorage_1.DynamoDBStorage({
|
|
20
|
-
dynamoDB: client,
|
|
21
|
-
tableName,
|
|
22
|
-
});
|
|
23
|
-
const umzug = new umzug_1.Umzug({
|
|
24
|
-
migrations: migrations,
|
|
25
|
-
context: {
|
|
26
|
-
client,
|
|
27
|
-
tableName,
|
|
28
|
-
},
|
|
29
|
-
logger: console,
|
|
30
|
-
storage: storage,
|
|
31
|
-
});
|
|
32
|
-
return umzug;
|
|
33
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateDownTo = exports.performMigrations = void 0;
|
|
4
|
+
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
5
|
+
const umzugDynamoDBStorage_1 = require("./umzugDynamoDBStorage");
|
|
6
|
+
const umzug_1 = require("umzug");
|
|
7
|
+
const performMigrations = async (packageConfig, deploymentName, migrations, client) => {
|
|
8
|
+
const umzug = await initUmzug(packageConfig, deploymentName, client, migrations);
|
|
9
|
+
await umzug.up();
|
|
10
|
+
};
|
|
11
|
+
exports.performMigrations = performMigrations;
|
|
12
|
+
const migrateDownTo = async (migrationName, packageConfig, deploymentName, migrations, client) => {
|
|
13
|
+
const umzug = await initUmzug(packageConfig, deploymentName, client, migrations);
|
|
14
|
+
await umzug.down({ to: migrationName });
|
|
15
|
+
};
|
|
16
|
+
exports.migrateDownTo = migrateDownTo;
|
|
17
|
+
async function initUmzug(packageConfig, deploymentName, client, migrations) {
|
|
18
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
19
|
+
const storage = new umzugDynamoDBStorage_1.DynamoDBStorage({
|
|
20
|
+
dynamoDB: client,
|
|
21
|
+
tableName,
|
|
22
|
+
});
|
|
23
|
+
const umzug = new umzug_1.Umzug({
|
|
24
|
+
migrations: migrations,
|
|
25
|
+
context: {
|
|
26
|
+
client,
|
|
27
|
+
tableName,
|
|
28
|
+
},
|
|
29
|
+
logger: console,
|
|
30
|
+
storage: storage,
|
|
31
|
+
});
|
|
32
|
+
return umzug;
|
|
33
|
+
}
|
|
34
34
|
//# sourceMappingURL=dynamoDBMigrations.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
-
import DynamoDBPackage, { DynamoDBDeployment } from './types/DynamoDBPackage';
|
|
3
|
-
export declare const getTableName: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<string>;
|
|
4
|
-
export declare const getDeploymentName: (deploymentName?: string) => string;
|
|
1
|
+
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
+
import DynamoDBPackage, { DynamoDBDeployment } from './types/DynamoDBPackage';
|
|
3
|
+
export declare const getTableName: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<string>;
|
|
4
|
+
export declare const getDeploymentName: (deploymentName?: string) => string;
|
|
5
5
|
//# sourceMappingURL=dynamoDBPackageUtils.d.ts.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDeploymentName = exports.getTableName = void 0;
|
|
7
|
-
const assert_1 = __importDefault(require("assert"));
|
|
8
|
-
const getTableName = async (packageConfig, deploymentName) => {
|
|
9
|
-
deploymentName = (0, exports.getDeploymentName)(deploymentName);
|
|
10
|
-
if (deploymentName === 'local') {
|
|
11
|
-
return `local-${packageConfig.getConfig().name}`;
|
|
12
|
-
}
|
|
13
|
-
const deployment = packageConfig.getDeployment(deploymentName);
|
|
14
|
-
return deployment.configuration.tableName;
|
|
15
|
-
};
|
|
16
|
-
exports.getTableName = getTableName;
|
|
17
|
-
const getDeploymentName = (deploymentName) => {
|
|
18
|
-
if (!deploymentName) {
|
|
19
|
-
(0, assert_1.default)(process.env.GOLDSTACK_DEPLOYMENT, 'Cannot connect to DynamoDB table. Either specify a deploymentName or ensure environment variable GOLDSTACK_DEPLOYMENT is defined.');
|
|
20
|
-
return process.env.GOLDSTACK_DEPLOYMENT;
|
|
21
|
-
}
|
|
22
|
-
return deploymentName;
|
|
23
|
-
};
|
|
24
|
-
exports.getDeploymentName = getDeploymentName;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDeploymentName = exports.getTableName = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const getTableName = async (packageConfig, deploymentName) => {
|
|
9
|
+
deploymentName = (0, exports.getDeploymentName)(deploymentName);
|
|
10
|
+
if (deploymentName === 'local') {
|
|
11
|
+
return `local-${packageConfig.getConfig().name}`;
|
|
12
|
+
}
|
|
13
|
+
const deployment = packageConfig.getDeployment(deploymentName);
|
|
14
|
+
return deployment.configuration.tableName;
|
|
15
|
+
};
|
|
16
|
+
exports.getTableName = getTableName;
|
|
17
|
+
const getDeploymentName = (deploymentName) => {
|
|
18
|
+
if (!deploymentName) {
|
|
19
|
+
(0, assert_1.default)(process.env.GOLDSTACK_DEPLOYMENT, 'Cannot connect to DynamoDB table. Either specify a deploymentName or ensure environment variable GOLDSTACK_DEPLOYMENT is defined.');
|
|
20
|
+
return process.env.GOLDSTACK_DEPLOYMENT;
|
|
21
|
+
}
|
|
22
|
+
return deploymentName;
|
|
23
|
+
};
|
|
24
|
+
exports.getDeploymentName = getDeploymentName;
|
|
25
25
|
//# sourceMappingURL=dynamoDBPackageUtils.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
-
import { DynamoDB } from 'aws-sdk';
|
|
3
|
-
import { StartedTestContainer } from 'testcontainers';
|
|
4
|
-
import { DynamoDBDeployment, DynamoDBPackage } from './templateDynamoDB';
|
|
5
|
-
export declare const localConnect: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<DynamoDB>;
|
|
6
|
-
export declare const endpointUrl: (startedContainer: StartedTestContainer) => string;
|
|
7
|
-
export declare const createClient: (startedContainer: StartedTestContainer) => DynamoDB;
|
|
8
|
-
export declare const startContainer: () => Promise<StartedTestContainer>;
|
|
9
|
-
export declare const stopLocalDynamoDB: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<void>;
|
|
1
|
+
import { EmbeddedPackageConfig } from '@goldstack/utils-package-config-embedded';
|
|
2
|
+
import { DynamoDB } from 'aws-sdk';
|
|
3
|
+
import { StartedTestContainer } from 'testcontainers';
|
|
4
|
+
import { DynamoDBDeployment, DynamoDBPackage } from './templateDynamoDB';
|
|
5
|
+
export declare const localConnect: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<DynamoDB>;
|
|
6
|
+
export declare const endpointUrl: (startedContainer: StartedTestContainer) => string;
|
|
7
|
+
export declare const createClient: (startedContainer: StartedTestContainer) => DynamoDB;
|
|
8
|
+
export declare const startContainer: () => Promise<StartedTestContainer>;
|
|
9
|
+
export declare const stopLocalDynamoDB: (packageConfig: EmbeddedPackageConfig<DynamoDBPackage, DynamoDBDeployment>, deploymentName?: string) => Promise<void>;
|
|
10
10
|
//# sourceMappingURL=localDynamoDB.d.ts.map
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stopLocalDynamoDB = exports.startContainer = exports.createClient = exports.endpointUrl = exports.localConnect = void 0;
|
|
4
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
5
|
-
const testcontainers_1 = require("testcontainers");
|
|
6
|
-
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
7
|
-
const MAPPED_PORT = 8000;
|
|
8
|
-
const IMAGE_NAME = 'amazon/dynamodb-local:1.18.0';
|
|
9
|
-
const startedContainers = new Map();
|
|
10
|
-
const localConnect = async (packageConfig, deploymentName) => {
|
|
11
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
12
|
-
// TODO the key in this map may need to be extended to include the region as well, since dynamodb table names are unique per region.
|
|
13
|
-
let startedContainer = startedContainers.get(tableName);
|
|
14
|
-
if (startedContainer && startedContainer !== 'stopped') {
|
|
15
|
-
return (0, exports.createClient)(startedContainer);
|
|
16
|
-
}
|
|
17
|
-
startedContainer = await (0, exports.startContainer)();
|
|
18
|
-
// Check if another container for this table has already been started in the meanwhile
|
|
19
|
-
const startedContainerTest = startedContainers.get(tableName);
|
|
20
|
-
if (startedContainerTest && startedContainerTest !== 'stopped') {
|
|
21
|
-
await startedContainer.stop();
|
|
22
|
-
return (0, exports.createClient)(startedContainerTest);
|
|
23
|
-
}
|
|
24
|
-
startedContainers.set(tableName, startedContainer);
|
|
25
|
-
return (0, exports.createClient)(startedContainer);
|
|
26
|
-
};
|
|
27
|
-
exports.localConnect = localConnect;
|
|
28
|
-
const endpointUrl = (startedContainer) => {
|
|
29
|
-
return `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(MAPPED_PORT)}`;
|
|
30
|
-
};
|
|
31
|
-
exports.endpointUrl = endpointUrl;
|
|
32
|
-
const createClient = (startedContainer) => {
|
|
33
|
-
const endpoint = (0, exports.endpointUrl)(startedContainer);
|
|
34
|
-
return new aws_sdk_1.DynamoDB({
|
|
35
|
-
endpoint,
|
|
36
|
-
region: 'eu-central-1',
|
|
37
|
-
credentials: {
|
|
38
|
-
accessKeyId: 'dummy',
|
|
39
|
-
secretAccessKey: 'dummy',
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
exports.createClient = createClient;
|
|
44
|
-
const startContainer = () => {
|
|
45
|
-
const startedContainer = new testcontainers_1.GenericContainer(IMAGE_NAME)
|
|
46
|
-
.withExposedPorts(MAPPED_PORT)
|
|
47
|
-
.withReuse()
|
|
48
|
-
.start();
|
|
49
|
-
return startedContainer;
|
|
50
|
-
};
|
|
51
|
-
exports.startContainer = startContainer;
|
|
52
|
-
const stopLocalDynamoDB = async (packageConfig, deploymentName) => {
|
|
53
|
-
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
54
|
-
const startedContainer = startedContainers.get(tableName);
|
|
55
|
-
if (!startedContainer) {
|
|
56
|
-
throw new Error(`Attempting to stop container that has not been started for DynamoDB table ${tableName}`);
|
|
57
|
-
}
|
|
58
|
-
if (startedContainer === 'stopped') {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
startedContainers.set(tableName, 'stopped');
|
|
62
|
-
await startedContainer.stop();
|
|
63
|
-
};
|
|
64
|
-
exports.stopLocalDynamoDB = stopLocalDynamoDB;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stopLocalDynamoDB = exports.startContainer = exports.createClient = exports.endpointUrl = exports.localConnect = void 0;
|
|
4
|
+
const aws_sdk_1 = require("aws-sdk");
|
|
5
|
+
const testcontainers_1 = require("testcontainers");
|
|
6
|
+
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
7
|
+
const MAPPED_PORT = 8000;
|
|
8
|
+
const IMAGE_NAME = 'amazon/dynamodb-local:1.18.0';
|
|
9
|
+
const startedContainers = new Map();
|
|
10
|
+
const localConnect = async (packageConfig, deploymentName) => {
|
|
11
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
12
|
+
// TODO the key in this map may need to be extended to include the region as well, since dynamodb table names are unique per region.
|
|
13
|
+
let startedContainer = startedContainers.get(tableName);
|
|
14
|
+
if (startedContainer && startedContainer !== 'stopped') {
|
|
15
|
+
return (0, exports.createClient)(startedContainer);
|
|
16
|
+
}
|
|
17
|
+
startedContainer = await (0, exports.startContainer)();
|
|
18
|
+
// Check if another container for this table has already been started in the meanwhile
|
|
19
|
+
const startedContainerTest = startedContainers.get(tableName);
|
|
20
|
+
if (startedContainerTest && startedContainerTest !== 'stopped') {
|
|
21
|
+
await startedContainer.stop();
|
|
22
|
+
return (0, exports.createClient)(startedContainerTest);
|
|
23
|
+
}
|
|
24
|
+
startedContainers.set(tableName, startedContainer);
|
|
25
|
+
return (0, exports.createClient)(startedContainer);
|
|
26
|
+
};
|
|
27
|
+
exports.localConnect = localConnect;
|
|
28
|
+
const endpointUrl = (startedContainer) => {
|
|
29
|
+
return `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(MAPPED_PORT)}`;
|
|
30
|
+
};
|
|
31
|
+
exports.endpointUrl = endpointUrl;
|
|
32
|
+
const createClient = (startedContainer) => {
|
|
33
|
+
const endpoint = (0, exports.endpointUrl)(startedContainer);
|
|
34
|
+
return new aws_sdk_1.DynamoDB({
|
|
35
|
+
endpoint,
|
|
36
|
+
region: 'eu-central-1',
|
|
37
|
+
credentials: {
|
|
38
|
+
accessKeyId: 'dummy',
|
|
39
|
+
secretAccessKey: 'dummy',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.createClient = createClient;
|
|
44
|
+
const startContainer = () => {
|
|
45
|
+
const startedContainer = new testcontainers_1.GenericContainer(IMAGE_NAME)
|
|
46
|
+
.withExposedPorts(MAPPED_PORT)
|
|
47
|
+
.withReuse()
|
|
48
|
+
.start();
|
|
49
|
+
return startedContainer;
|
|
50
|
+
};
|
|
51
|
+
exports.startContainer = startContainer;
|
|
52
|
+
const stopLocalDynamoDB = async (packageConfig, deploymentName) => {
|
|
53
|
+
const tableName = await (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
54
|
+
const startedContainer = startedContainers.get(tableName);
|
|
55
|
+
if (!startedContainer) {
|
|
56
|
+
throw new Error(`Attempting to stop container that has not been started for DynamoDB table ${tableName}`);
|
|
57
|
+
}
|
|
58
|
+
if (startedContainer === 'stopped') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
startedContainers.set(tableName, 'stopped');
|
|
62
|
+
await startedContainer.stop();
|
|
63
|
+
};
|
|
64
|
+
exports.stopLocalDynamoDB = stopLocalDynamoDB;
|
|
65
65
|
//# sourceMappingURL=localDynamoDB.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './types/DynamoDBPackage';
|
|
2
|
-
export * from './templateDynamoDBTable';
|
|
3
|
-
export type { DynamoDBContext } from './dynamoDBMigrations';
|
|
1
|
+
export * from './types/DynamoDBPackage';
|
|
2
|
+
export * from './templateDynamoDBTable';
|
|
3
|
+
export type { DynamoDBContext } from './dynamoDBMigrations';
|
|
4
4
|
//# sourceMappingURL=templateDynamoDB.d.ts.map
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types/DynamoDBPackage"), exports);
|
|
18
|
-
__exportStar(require("./templateDynamoDBTable"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types/DynamoDBPackage"), exports);
|
|
18
|
+
__exportStar(require("./templateDynamoDBTable"), exports);
|
|
19
19
|
//# sourceMappingURL=templateDynamoDB.js.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
2
|
-
import { DynamoDBPackage } from './types/DynamoDBPackage';
|
|
3
|
-
import { InputMigrations } from 'umzug/lib/types';
|
|
4
|
-
import { DynamoDBContext } from './dynamoDBMigrations';
|
|
5
|
-
export declare const getTableName: (goldstackConfig: DynamoDBPackage | any, packageSchema: any, deploymentName?: string) => Promise<string>;
|
|
6
|
-
export declare const stopLocalDynamoDB: (goldstackConfig: DynamoDBPackage | any, packageSchema: any, deploymentName?: string) => Promise<void>;
|
|
7
|
-
export declare const connect: ({ goldstackConfig, packageSchema, migrations, deploymentName, }: {
|
|
8
|
-
goldstackConfig: DynamoDBPackage | any;
|
|
9
|
-
packageSchema: any;
|
|
10
|
-
migrations: InputMigrations<DynamoDBContext>;
|
|
11
|
-
deploymentName?: string | undefined;
|
|
12
|
-
}) => Promise<DynamoDB>;
|
|
13
|
-
/**
|
|
14
|
-
* Deletes the DynamoDB table with all its data.
|
|
15
|
-
*/
|
|
16
|
-
export declare const deleteTable: ({ goldstackConfig, packageSchema, deploymentName, }: {
|
|
17
|
-
goldstackConfig: DynamoDBPackage | any;
|
|
18
|
-
packageSchema: any;
|
|
19
|
-
deploymentName?: string | undefined;
|
|
20
|
-
}) => Promise<DynamoDB>;
|
|
21
|
-
export declare const migrateDownTo: ({ migrationName, goldstackConfig, packageSchema, migrations, deploymentName, }: {
|
|
22
|
-
migrationName: string;
|
|
23
|
-
goldstackConfig: DynamoDBPackage | any;
|
|
24
|
-
packageSchema: any;
|
|
25
|
-
migrations: InputMigrations<DynamoDBContext>;
|
|
26
|
-
deploymentName?: string | undefined;
|
|
27
|
-
}) => Promise<DynamoDB>;
|
|
1
|
+
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
2
|
+
import { DynamoDBPackage } from './types/DynamoDBPackage';
|
|
3
|
+
import { InputMigrations } from 'umzug/lib/types';
|
|
4
|
+
import { DynamoDBContext } from './dynamoDBMigrations';
|
|
5
|
+
export declare const getTableName: (goldstackConfig: DynamoDBPackage | any, packageSchema: any, deploymentName?: string) => Promise<string>;
|
|
6
|
+
export declare const stopLocalDynamoDB: (goldstackConfig: DynamoDBPackage | any, packageSchema: any, deploymentName?: string) => Promise<void>;
|
|
7
|
+
export declare const connect: ({ goldstackConfig, packageSchema, migrations, deploymentName, }: {
|
|
8
|
+
goldstackConfig: DynamoDBPackage | any;
|
|
9
|
+
packageSchema: any;
|
|
10
|
+
migrations: InputMigrations<DynamoDBContext>;
|
|
11
|
+
deploymentName?: string | undefined;
|
|
12
|
+
}) => Promise<DynamoDB>;
|
|
13
|
+
/**
|
|
14
|
+
* Deletes the DynamoDB table with all its data.
|
|
15
|
+
*/
|
|
16
|
+
export declare const deleteTable: ({ goldstackConfig, packageSchema, deploymentName, }: {
|
|
17
|
+
goldstackConfig: DynamoDBPackage | any;
|
|
18
|
+
packageSchema: any;
|
|
19
|
+
deploymentName?: string | undefined;
|
|
20
|
+
}) => Promise<DynamoDB>;
|
|
21
|
+
export declare const migrateDownTo: ({ migrationName, goldstackConfig, packageSchema, migrations, deploymentName, }: {
|
|
22
|
+
migrationName: string;
|
|
23
|
+
goldstackConfig: DynamoDBPackage | any;
|
|
24
|
+
packageSchema: any;
|
|
25
|
+
migrations: InputMigrations<DynamoDBContext>;
|
|
26
|
+
deploymentName?: string | undefined;
|
|
27
|
+
}) => Promise<DynamoDB>;
|
|
28
28
|
//# sourceMappingURL=templateDynamoDBTable.d.ts.map
|