@goldstack/template-dynamodb 0.1.20 → 0.2.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/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 +11 -11
|
@@ -1,119 +1,119 @@
|
|
|
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.migrateDownTo = exports.deleteTable = exports.connect = exports.stopLocalDynamoDB = exports.getTableName = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
8
|
-
const dynamodb_1 = __importDefault(require("aws-sdk/clients/dynamodb"));
|
|
9
|
-
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
10
|
-
const utils_package_config_embedded_1 = require("@goldstack/utils-package-config-embedded");
|
|
11
|
-
const dynamoDBData_1 = require("./dynamoDBData");
|
|
12
|
-
const dynamoDBMigrations_1 = require("./dynamoDBMigrations");
|
|
13
|
-
const utils_esbuild_1 = require("@goldstack/utils-esbuild");
|
|
14
|
-
const core_1 = require("aws-sdk/lib/core");
|
|
15
|
-
/**
|
|
16
|
-
* Map to keep track for which deployment and tables initialisation and migrations have already been performed
|
|
17
|
-
*/
|
|
18
|
-
const coldStart = new Map();
|
|
19
|
-
const getTableName = async (goldstackConfig, packageSchema, deploymentName) => {
|
|
20
|
-
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
21
|
-
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
22
|
-
goldstackJson: goldstackConfig,
|
|
23
|
-
packageSchema,
|
|
24
|
-
});
|
|
25
|
-
return (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
26
|
-
};
|
|
27
|
-
exports.getTableName = getTableName;
|
|
28
|
-
const stopLocalDynamoDB = async (goldstackConfig, packageSchema, deploymentName) => {
|
|
29
|
-
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
30
|
-
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
31
|
-
goldstackJson: goldstackConfig,
|
|
32
|
-
packageSchema,
|
|
33
|
-
});
|
|
34
|
-
// only load this file when we absolutely need it, so we can avoid packaging it
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
36
|
-
const lib = require((0, utils_esbuild_1.excludeInBundle)('./localDynamoDB'));
|
|
37
|
-
await lib.stopLocalDynamoDB(packageConfig, deploymentName);
|
|
38
|
-
const coldStartKey = getColdStartKey(packageConfig, deploymentName);
|
|
39
|
-
coldStart.delete(coldStartKey);
|
|
40
|
-
};
|
|
41
|
-
exports.stopLocalDynamoDB = stopLocalDynamoDB;
|
|
42
|
-
const createClient = async (packageConfig, deploymentName) => {
|
|
43
|
-
if (deploymentName === 'local') {
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
45
|
-
const lib = require((0, utils_esbuild_1.excludeInBundle)('./localDynamoDB'));
|
|
46
|
-
return lib.localConnect(packageConfig, deploymentName);
|
|
47
|
-
}
|
|
48
|
-
const deployment = packageConfig.getDeployment(deploymentName);
|
|
49
|
-
let awsUser;
|
|
50
|
-
if (process.env.AWS_ACCESS_KEY_ID) {
|
|
51
|
-
awsUser = new core_1.EnvironmentCredentials('AWS');
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// load this in lazy to enable omitting the dependency when bundling lambdas
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
-
const infraAWSLib = require((0, utils_esbuild_1.excludeInBundle)('@goldstack/infra-aws'));
|
|
57
|
-
awsUser = await infraAWSLib.getAWSUser(deployment.awsUser);
|
|
58
|
-
}
|
|
59
|
-
const dynamoDB = new dynamodb_1.default({
|
|
60
|
-
apiVersion: '2012-08-10',
|
|
61
|
-
credentials: awsUser,
|
|
62
|
-
region: deployment.awsRegion,
|
|
63
|
-
});
|
|
64
|
-
return dynamoDB;
|
|
65
|
-
};
|
|
66
|
-
const connect = async ({ goldstackConfig, packageSchema, migrations, deploymentName, }) => {
|
|
67
|
-
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
68
|
-
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
69
|
-
goldstackJson: goldstackConfig,
|
|
70
|
-
packageSchema,
|
|
71
|
-
});
|
|
72
|
-
const client = await createClient(packageConfig, deploymentName);
|
|
73
|
-
// ensure table initialisation and migrations are only performed once per cold start
|
|
74
|
-
const coldStartKey = getColdStartKey(packageConfig, deploymentName);
|
|
75
|
-
if (!coldStart.has(coldStartKey)) {
|
|
76
|
-
await (0, dynamoDBData_1.assertTable)(packageConfig, deploymentName, client);
|
|
77
|
-
await (0, dynamoDBData_1.assertTableActive)(packageConfig, deploymentName, client);
|
|
78
|
-
await (0, dynamoDBMigrations_1.performMigrations)(packageConfig, deploymentName, migrations, client);
|
|
79
|
-
coldStart.set(coldStartKey, true);
|
|
80
|
-
}
|
|
81
|
-
return client;
|
|
82
|
-
};
|
|
83
|
-
exports.connect = connect;
|
|
84
|
-
/**
|
|
85
|
-
* Deletes the DynamoDB table with all its data.
|
|
86
|
-
*/
|
|
87
|
-
const deleteTable = async ({ goldstackConfig, packageSchema, deploymentName, }) => {
|
|
88
|
-
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
89
|
-
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
90
|
-
goldstackJson: goldstackConfig,
|
|
91
|
-
packageSchema,
|
|
92
|
-
});
|
|
93
|
-
const client = await createClient(packageConfig, deploymentName);
|
|
94
|
-
await (0, dynamoDBData_1.deleteTable)(packageConfig, deploymentName, client);
|
|
95
|
-
return client;
|
|
96
|
-
};
|
|
97
|
-
exports.deleteTable = deleteTable;
|
|
98
|
-
const migrateDownTo = async ({ migrationName, goldstackConfig, packageSchema, migrations, deploymentName, }) => {
|
|
99
|
-
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
100
|
-
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
101
|
-
goldstackJson: goldstackConfig,
|
|
102
|
-
packageSchema,
|
|
103
|
-
});
|
|
104
|
-
const client = await createClient(packageConfig, deploymentName);
|
|
105
|
-
await (0, dynamoDBData_1.assertTable)(packageConfig, deploymentName, client);
|
|
106
|
-
await (0, dynamoDBData_1.assertTableActive)(packageConfig, deploymentName, client);
|
|
107
|
-
await (0, dynamoDBMigrations_1.migrateDownTo)(migrationName, packageConfig, deploymentName, migrations, client);
|
|
108
|
-
return client;
|
|
109
|
-
};
|
|
110
|
-
exports.migrateDownTo = migrateDownTo;
|
|
111
|
-
function getColdStartKey(packageConfig, deploymentName) {
|
|
112
|
-
if (deploymentName === 'local') {
|
|
113
|
-
return `local-${(0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName)}`;
|
|
114
|
-
}
|
|
115
|
-
const deployment = packageConfig.getDeployment(deploymentName);
|
|
116
|
-
const coldStartKey = `${deployment.awsRegion}-${deploymentName}-${deployment.tableName}`;
|
|
117
|
-
return coldStartKey;
|
|
118
|
-
}
|
|
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.migrateDownTo = exports.deleteTable = exports.connect = exports.stopLocalDynamoDB = exports.getTableName = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
8
|
+
const dynamodb_1 = __importDefault(require("aws-sdk/clients/dynamodb"));
|
|
9
|
+
const dynamoDBPackageUtils_1 = require("./dynamoDBPackageUtils");
|
|
10
|
+
const utils_package_config_embedded_1 = require("@goldstack/utils-package-config-embedded");
|
|
11
|
+
const dynamoDBData_1 = require("./dynamoDBData");
|
|
12
|
+
const dynamoDBMigrations_1 = require("./dynamoDBMigrations");
|
|
13
|
+
const utils_esbuild_1 = require("@goldstack/utils-esbuild");
|
|
14
|
+
const core_1 = require("aws-sdk/lib/core");
|
|
15
|
+
/**
|
|
16
|
+
* Map to keep track for which deployment and tables initialisation and migrations have already been performed
|
|
17
|
+
*/
|
|
18
|
+
const coldStart = new Map();
|
|
19
|
+
const getTableName = async (goldstackConfig, packageSchema, deploymentName) => {
|
|
20
|
+
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
21
|
+
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
22
|
+
goldstackJson: goldstackConfig,
|
|
23
|
+
packageSchema,
|
|
24
|
+
});
|
|
25
|
+
return (0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName);
|
|
26
|
+
};
|
|
27
|
+
exports.getTableName = getTableName;
|
|
28
|
+
const stopLocalDynamoDB = async (goldstackConfig, packageSchema, deploymentName) => {
|
|
29
|
+
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
30
|
+
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
31
|
+
goldstackJson: goldstackConfig,
|
|
32
|
+
packageSchema,
|
|
33
|
+
});
|
|
34
|
+
// only load this file when we absolutely need it, so we can avoid packaging it
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
36
|
+
const lib = require((0, utils_esbuild_1.excludeInBundle)('./localDynamoDB'));
|
|
37
|
+
await lib.stopLocalDynamoDB(packageConfig, deploymentName);
|
|
38
|
+
const coldStartKey = getColdStartKey(packageConfig, deploymentName);
|
|
39
|
+
coldStart.delete(coldStartKey);
|
|
40
|
+
};
|
|
41
|
+
exports.stopLocalDynamoDB = stopLocalDynamoDB;
|
|
42
|
+
const createClient = async (packageConfig, deploymentName) => {
|
|
43
|
+
if (deploymentName === 'local') {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
45
|
+
const lib = require((0, utils_esbuild_1.excludeInBundle)('./localDynamoDB'));
|
|
46
|
+
return lib.localConnect(packageConfig, deploymentName);
|
|
47
|
+
}
|
|
48
|
+
const deployment = packageConfig.getDeployment(deploymentName);
|
|
49
|
+
let awsUser;
|
|
50
|
+
if (process.env.AWS_ACCESS_KEY_ID) {
|
|
51
|
+
awsUser = new core_1.EnvironmentCredentials('AWS');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// load this in lazy to enable omitting the dependency when bundling lambdas
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
+
const infraAWSLib = require((0, utils_esbuild_1.excludeInBundle)('@goldstack/infra-aws'));
|
|
57
|
+
awsUser = await infraAWSLib.getAWSUser(deployment.awsUser);
|
|
58
|
+
}
|
|
59
|
+
const dynamoDB = new dynamodb_1.default({
|
|
60
|
+
apiVersion: '2012-08-10',
|
|
61
|
+
credentials: awsUser,
|
|
62
|
+
region: deployment.awsRegion,
|
|
63
|
+
});
|
|
64
|
+
return dynamoDB;
|
|
65
|
+
};
|
|
66
|
+
const connect = async ({ goldstackConfig, packageSchema, migrations, deploymentName, }) => {
|
|
67
|
+
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
68
|
+
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
69
|
+
goldstackJson: goldstackConfig,
|
|
70
|
+
packageSchema,
|
|
71
|
+
});
|
|
72
|
+
const client = await createClient(packageConfig, deploymentName);
|
|
73
|
+
// ensure table initialisation and migrations are only performed once per cold start
|
|
74
|
+
const coldStartKey = getColdStartKey(packageConfig, deploymentName);
|
|
75
|
+
if (!coldStart.has(coldStartKey)) {
|
|
76
|
+
await (0, dynamoDBData_1.assertTable)(packageConfig, deploymentName, client);
|
|
77
|
+
await (0, dynamoDBData_1.assertTableActive)(packageConfig, deploymentName, client);
|
|
78
|
+
await (0, dynamoDBMigrations_1.performMigrations)(packageConfig, deploymentName, migrations, client);
|
|
79
|
+
coldStart.set(coldStartKey, true);
|
|
80
|
+
}
|
|
81
|
+
return client;
|
|
82
|
+
};
|
|
83
|
+
exports.connect = connect;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes the DynamoDB table with all its data.
|
|
86
|
+
*/
|
|
87
|
+
const deleteTable = async ({ goldstackConfig, packageSchema, deploymentName, }) => {
|
|
88
|
+
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
89
|
+
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
90
|
+
goldstackJson: goldstackConfig,
|
|
91
|
+
packageSchema,
|
|
92
|
+
});
|
|
93
|
+
const client = await createClient(packageConfig, deploymentName);
|
|
94
|
+
await (0, dynamoDBData_1.deleteTable)(packageConfig, deploymentName, client);
|
|
95
|
+
return client;
|
|
96
|
+
};
|
|
97
|
+
exports.deleteTable = deleteTable;
|
|
98
|
+
const migrateDownTo = async ({ migrationName, goldstackConfig, packageSchema, migrations, deploymentName, }) => {
|
|
99
|
+
deploymentName = (0, dynamoDBPackageUtils_1.getDeploymentName)(deploymentName);
|
|
100
|
+
const packageConfig = new utils_package_config_embedded_1.EmbeddedPackageConfig({
|
|
101
|
+
goldstackJson: goldstackConfig,
|
|
102
|
+
packageSchema,
|
|
103
|
+
});
|
|
104
|
+
const client = await createClient(packageConfig, deploymentName);
|
|
105
|
+
await (0, dynamoDBData_1.assertTable)(packageConfig, deploymentName, client);
|
|
106
|
+
await (0, dynamoDBData_1.assertTableActive)(packageConfig, deploymentName, client);
|
|
107
|
+
await (0, dynamoDBMigrations_1.migrateDownTo)(migrationName, packageConfig, deploymentName, migrations, client);
|
|
108
|
+
return client;
|
|
109
|
+
};
|
|
110
|
+
exports.migrateDownTo = migrateDownTo;
|
|
111
|
+
function getColdStartKey(packageConfig, deploymentName) {
|
|
112
|
+
if (deploymentName === 'local') {
|
|
113
|
+
return `local-${(0, dynamoDBPackageUtils_1.getTableName)(packageConfig, deploymentName)}`;
|
|
114
|
+
}
|
|
115
|
+
const deployment = packageConfig.getDeployment(deploymentName);
|
|
116
|
+
const coldStartKey = `${deployment.awsRegion}-${deploymentName}-${deployment.tableName}`;
|
|
117
|
+
return coldStartKey;
|
|
118
|
+
}
|
|
119
119
|
//# sourceMappingURL=templateDynamoDBTable.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AWSDeployment } from '@goldstack/infra-aws';
|
|
2
|
-
import { TerraformDeployment } from '@goldstack/utils-terraform';
|
|
3
|
-
import { Deployment } from '@goldstack/infra';
|
|
4
|
-
import { DynamoDBDeploymentConfiguration } from './DynamoDBDeploymentConfiguration';
|
|
5
|
-
export type { AWSDeployment, TerraformDeployment, Deployment, DynamoDBDeploymentConfiguration, };
|
|
6
|
-
export interface ThisDeployment extends Deployment, AWSDeployment, TerraformDeployment {
|
|
7
|
-
configuration: DynamoDBDeploymentConfiguration;
|
|
8
|
-
}
|
|
9
|
-
export type { ThisDeployment as DynamoDBDeployment };
|
|
10
|
-
export default ThisDeployment;
|
|
1
|
+
import { AWSDeployment } from '@goldstack/infra-aws';
|
|
2
|
+
import { TerraformDeployment } from '@goldstack/utils-terraform';
|
|
3
|
+
import { Deployment } from '@goldstack/infra';
|
|
4
|
+
import { DynamoDBDeploymentConfiguration } from './DynamoDBDeploymentConfiguration';
|
|
5
|
+
export type { AWSDeployment, TerraformDeployment, Deployment, DynamoDBDeploymentConfiguration, };
|
|
6
|
+
export interface ThisDeployment extends Deployment, AWSDeployment, TerraformDeployment {
|
|
7
|
+
configuration: DynamoDBDeploymentConfiguration;
|
|
8
|
+
}
|
|
9
|
+
export type { ThisDeployment as DynamoDBDeployment };
|
|
10
|
+
export default ThisDeployment;
|
|
11
11
|
//# sourceMappingURL=DynamoDBDeployment.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=DynamoDBDeployment.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { DeploymentConfiguration } from '@goldstack/infra';
|
|
2
|
-
export type { DeploymentConfiguration };
|
|
3
|
-
/**
|
|
4
|
-
* The name of the DynamoDB table. No spaces, numbers or special characters other than '-', '.' and '_' allowed.
|
|
5
|
-
*
|
|
6
|
-
* See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html
|
|
7
|
-
*
|
|
8
|
-
* @title DynamoDB table name
|
|
9
|
-
* @pattern ^[A-Za-z0-9-\._]*$
|
|
10
|
-
*/
|
|
11
|
-
declare type TableName = string;
|
|
12
|
-
export interface ThisDeploymentConfiguration extends DeploymentConfiguration {
|
|
13
|
-
tableName: TableName;
|
|
14
|
-
}
|
|
15
|
-
export type { ThisDeploymentConfiguration as DynamoDBDeploymentConfiguration };
|
|
1
|
+
import { DeploymentConfiguration } from '@goldstack/infra';
|
|
2
|
+
export type { DeploymentConfiguration };
|
|
3
|
+
/**
|
|
4
|
+
* The name of the DynamoDB table. No spaces, numbers or special characters other than '-', '.' and '_' allowed.
|
|
5
|
+
*
|
|
6
|
+
* See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html
|
|
7
|
+
*
|
|
8
|
+
* @title DynamoDB table name
|
|
9
|
+
* @pattern ^[A-Za-z0-9-\._]*$
|
|
10
|
+
*/
|
|
11
|
+
declare type TableName = string;
|
|
12
|
+
export interface ThisDeploymentConfiguration extends DeploymentConfiguration {
|
|
13
|
+
tableName: TableName;
|
|
14
|
+
}
|
|
15
|
+
export type { ThisDeploymentConfiguration as DynamoDBDeploymentConfiguration };
|
|
16
16
|
//# sourceMappingURL=DynamoDBDeploymentConfiguration.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=DynamoDBDeploymentConfiguration.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Package } from '@goldstack/utils-package';
|
|
2
|
-
import { DynamoDBConfiguration } from './DynamoDBPackageConfiguration';
|
|
3
|
-
import { DynamoDBDeployment } from './DynamoDBDeployment';
|
|
4
|
-
export type { DynamoDBConfiguration, DynamoDBDeployment };
|
|
5
|
-
/**
|
|
6
|
-
* Places where the DynamoDB table should be deployed to.
|
|
7
|
-
*
|
|
8
|
-
* @title Deployments
|
|
9
|
-
*/
|
|
10
|
-
export declare type DynamoDBDeployments = DynamoDBDeployment[];
|
|
11
|
-
/**
|
|
12
|
-
* A DynamoDB table.
|
|
13
|
-
*
|
|
14
|
-
* @title DynamoDB Package
|
|
15
|
-
*/
|
|
16
|
-
export interface ThisPackage extends Package {
|
|
17
|
-
configuration: DynamoDBConfiguration;
|
|
18
|
-
deployments: DynamoDBDeployments;
|
|
19
|
-
}
|
|
20
|
-
export type { ThisPackage as DynamoDBPackage };
|
|
21
|
-
export default ThisPackage;
|
|
1
|
+
import { Package } from '@goldstack/utils-package';
|
|
2
|
+
import { DynamoDBConfiguration } from './DynamoDBPackageConfiguration';
|
|
3
|
+
import { DynamoDBDeployment } from './DynamoDBDeployment';
|
|
4
|
+
export type { DynamoDBConfiguration, DynamoDBDeployment };
|
|
5
|
+
/**
|
|
6
|
+
* Places where the DynamoDB table should be deployed to.
|
|
7
|
+
*
|
|
8
|
+
* @title Deployments
|
|
9
|
+
*/
|
|
10
|
+
export declare type DynamoDBDeployments = DynamoDBDeployment[];
|
|
11
|
+
/**
|
|
12
|
+
* A DynamoDB table.
|
|
13
|
+
*
|
|
14
|
+
* @title DynamoDB Package
|
|
15
|
+
*/
|
|
16
|
+
export interface ThisPackage extends Package {
|
|
17
|
+
configuration: DynamoDBConfiguration;
|
|
18
|
+
deployments: DynamoDBDeployments;
|
|
19
|
+
}
|
|
20
|
+
export type { ThisPackage as DynamoDBPackage };
|
|
21
|
+
export default ThisPackage;
|
|
22
22
|
//# sourceMappingURL=DynamoDBPackage.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=DynamoDBPackage.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Configuration } from '@goldstack/utils-package';
|
|
2
|
-
export type { Configuration };
|
|
3
|
-
/**
|
|
4
|
-
* DynamoDB Configuration
|
|
5
|
-
*
|
|
6
|
-
* @title DynamoDB Configuration
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export interface ThisPackageConfiguration extends Configuration {
|
|
10
|
-
[propName: string]: any;
|
|
11
|
-
}
|
|
12
|
-
export type { ThisPackageConfiguration as DynamoDBConfiguration };
|
|
13
|
-
export default ThisPackageConfiguration;
|
|
1
|
+
import { Configuration } from '@goldstack/utils-package';
|
|
2
|
+
export type { Configuration };
|
|
3
|
+
/**
|
|
4
|
+
* DynamoDB Configuration
|
|
5
|
+
*
|
|
6
|
+
* @title DynamoDB Configuration
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export interface ThisPackageConfiguration extends Configuration {
|
|
10
|
+
[propName: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export type { ThisPackageConfiguration as DynamoDBConfiguration };
|
|
13
|
+
export default ThisPackageConfiguration;
|
|
14
14
|
//# sourceMappingURL=DynamoDBPackageConfiguration.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=DynamoDBPackageConfiguration.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
2
|
-
import { UmzugStorage } from 'umzug';
|
|
3
|
-
import { MigrationParams } from 'umzug/lib/types';
|
|
4
|
-
import { DynamoDBContext } from './dynamoDBMigrations';
|
|
5
|
-
export declare class DynamoDBStorage implements UmzugStorage<DynamoDBContext> {
|
|
6
|
-
dynamoClient: DynamoDB;
|
|
7
|
-
tableName: string;
|
|
8
|
-
migrationsKey: string;
|
|
9
|
-
partitionKey: string;
|
|
10
|
-
sortKey: string;
|
|
11
|
-
constructor({ dynamoDB, tableName, migrationsKey, partitionKey, sortKey, }: {
|
|
12
|
-
dynamoDB: DynamoDB;
|
|
13
|
-
tableName: string;
|
|
14
|
-
migrationsKey?: string;
|
|
15
|
-
partitionKey?: string;
|
|
16
|
-
sortKey?: string;
|
|
17
|
-
});
|
|
18
|
-
logMigration(params: MigrationParams<DynamoDBContext>): Promise<void>;
|
|
19
|
-
unlogMigration(params: MigrationParams<DynamoDBContext>): Promise<void>;
|
|
20
|
-
executed(): Promise<string[]>;
|
|
21
|
-
}
|
|
1
|
+
import DynamoDB from 'aws-sdk/clients/dynamodb';
|
|
2
|
+
import { UmzugStorage } from 'umzug';
|
|
3
|
+
import { MigrationParams } from 'umzug/lib/types';
|
|
4
|
+
import { DynamoDBContext } from './dynamoDBMigrations';
|
|
5
|
+
export declare class DynamoDBStorage implements UmzugStorage<DynamoDBContext> {
|
|
6
|
+
dynamoClient: DynamoDB;
|
|
7
|
+
tableName: string;
|
|
8
|
+
migrationsKey: string;
|
|
9
|
+
partitionKey: string;
|
|
10
|
+
sortKey: string;
|
|
11
|
+
constructor({ dynamoDB, tableName, migrationsKey, partitionKey, sortKey, }: {
|
|
12
|
+
dynamoDB: DynamoDB;
|
|
13
|
+
tableName: string;
|
|
14
|
+
migrationsKey?: string;
|
|
15
|
+
partitionKey?: string;
|
|
16
|
+
sortKey?: string;
|
|
17
|
+
});
|
|
18
|
+
logMigration(params: MigrationParams<DynamoDBContext>): Promise<void>;
|
|
19
|
+
unlogMigration(params: MigrationParams<DynamoDBContext>): Promise<void>;
|
|
20
|
+
executed(): Promise<string[]>;
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=umzugDynamoDBStorage.d.ts.map
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamoDBStorage = void 0;
|
|
4
|
-
const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
|
|
5
|
-
class DynamoDBStorage {
|
|
6
|
-
constructor({ dynamoDB, tableName, migrationsKey = '#MIGRATIONS', partitionKey = 'pk', sortKey = 'sk', }) {
|
|
7
|
-
this.dynamoClient = dynamoDB;
|
|
8
|
-
this.tableName = tableName;
|
|
9
|
-
this.migrationsKey = migrationsKey;
|
|
10
|
-
this.partitionKey = partitionKey;
|
|
11
|
-
this.sortKey = sortKey;
|
|
12
|
-
}
|
|
13
|
-
async logMigration(params) {
|
|
14
|
-
try {
|
|
15
|
-
await params.context.client
|
|
16
|
-
.putItem({
|
|
17
|
-
TableName: params.context.tableName,
|
|
18
|
-
Item: (0, util_dynamodb_1.marshall)({
|
|
19
|
-
[this.partitionKey]: this.migrationsKey,
|
|
20
|
-
[this.sortKey]: params.name,
|
|
21
|
-
}),
|
|
22
|
-
})
|
|
23
|
-
.promise();
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
throw new Error(`Failed to log migration ${params.name}. ` + e);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async unlogMigration(params) {
|
|
30
|
-
try {
|
|
31
|
-
await params.context.client
|
|
32
|
-
.deleteItem({
|
|
33
|
-
TableName: this.tableName,
|
|
34
|
-
Key: (0, util_dynamodb_1.marshall)({
|
|
35
|
-
[this.partitionKey]: this.migrationsKey,
|
|
36
|
-
[this.sortKey]: params.name,
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
39
|
-
.promise();
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
throw new Error(`Failed to unlog migration ${params.name}. ` + e);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async executed() {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
const migrations = [];
|
|
48
|
-
let res = undefined;
|
|
49
|
-
let lastEvaluatedKey = undefined;
|
|
50
|
-
do {
|
|
51
|
-
res = await this.dynamoClient
|
|
52
|
-
.query({
|
|
53
|
-
TableName: this.tableName,
|
|
54
|
-
KeyConditionExpression: '#pk = :pk',
|
|
55
|
-
ExpressionAttributeNames: {
|
|
56
|
-
'#pk': this.partitionKey,
|
|
57
|
-
},
|
|
58
|
-
ExpressionAttributeValues: (0, util_dynamodb_1.marshall)({
|
|
59
|
-
':pk': this.migrationsKey,
|
|
60
|
-
}),
|
|
61
|
-
ExclusiveStartKey: lastEvaluatedKey,
|
|
62
|
-
})
|
|
63
|
-
.promise();
|
|
64
|
-
lastEvaluatedKey = res.LastEvaluatedKey;
|
|
65
|
-
const items = (_a = res === null || res === void 0 ? void 0 : res.Items) === null || _a === void 0 ? void 0 : _a.map((entry) => {
|
|
66
|
-
return (0, util_dynamodb_1.unmarshall)(entry);
|
|
67
|
-
});
|
|
68
|
-
if (items) {
|
|
69
|
-
migrations.push(...items);
|
|
70
|
-
}
|
|
71
|
-
} while (((_b = res === null || res === void 0 ? void 0 : res.Items) === null || _b === void 0 ? void 0 : _b.length) && lastEvaluatedKey);
|
|
72
|
-
return migrations.map((m) => m[this.sortKey]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.DynamoDBStorage = DynamoDBStorage;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoDBStorage = void 0;
|
|
4
|
+
const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
|
|
5
|
+
class DynamoDBStorage {
|
|
6
|
+
constructor({ dynamoDB, tableName, migrationsKey = '#MIGRATIONS', partitionKey = 'pk', sortKey = 'sk', }) {
|
|
7
|
+
this.dynamoClient = dynamoDB;
|
|
8
|
+
this.tableName = tableName;
|
|
9
|
+
this.migrationsKey = migrationsKey;
|
|
10
|
+
this.partitionKey = partitionKey;
|
|
11
|
+
this.sortKey = sortKey;
|
|
12
|
+
}
|
|
13
|
+
async logMigration(params) {
|
|
14
|
+
try {
|
|
15
|
+
await params.context.client
|
|
16
|
+
.putItem({
|
|
17
|
+
TableName: params.context.tableName,
|
|
18
|
+
Item: (0, util_dynamodb_1.marshall)({
|
|
19
|
+
[this.partitionKey]: this.migrationsKey,
|
|
20
|
+
[this.sortKey]: params.name,
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
.promise();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw new Error(`Failed to log migration ${params.name}. ` + e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async unlogMigration(params) {
|
|
30
|
+
try {
|
|
31
|
+
await params.context.client
|
|
32
|
+
.deleteItem({
|
|
33
|
+
TableName: this.tableName,
|
|
34
|
+
Key: (0, util_dynamodb_1.marshall)({
|
|
35
|
+
[this.partitionKey]: this.migrationsKey,
|
|
36
|
+
[this.sortKey]: params.name,
|
|
37
|
+
}),
|
|
38
|
+
})
|
|
39
|
+
.promise();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw new Error(`Failed to unlog migration ${params.name}. ` + e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async executed() {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const migrations = [];
|
|
48
|
+
let res = undefined;
|
|
49
|
+
let lastEvaluatedKey = undefined;
|
|
50
|
+
do {
|
|
51
|
+
res = await this.dynamoClient
|
|
52
|
+
.query({
|
|
53
|
+
TableName: this.tableName,
|
|
54
|
+
KeyConditionExpression: '#pk = :pk',
|
|
55
|
+
ExpressionAttributeNames: {
|
|
56
|
+
'#pk': this.partitionKey,
|
|
57
|
+
},
|
|
58
|
+
ExpressionAttributeValues: (0, util_dynamodb_1.marshall)({
|
|
59
|
+
':pk': this.migrationsKey,
|
|
60
|
+
}),
|
|
61
|
+
ExclusiveStartKey: lastEvaluatedKey,
|
|
62
|
+
})
|
|
63
|
+
.promise();
|
|
64
|
+
lastEvaluatedKey = res.LastEvaluatedKey;
|
|
65
|
+
const items = (_a = res === null || res === void 0 ? void 0 : res.Items) === null || _a === void 0 ? void 0 : _a.map((entry) => {
|
|
66
|
+
return (0, util_dynamodb_1.unmarshall)(entry);
|
|
67
|
+
});
|
|
68
|
+
if (items) {
|
|
69
|
+
migrations.push(...items);
|
|
70
|
+
}
|
|
71
|
+
} while (((_b = res === null || res === void 0 ? void 0 : res.Items) === null || _b === void 0 ? void 0 : _b.length) && lastEvaluatedKey);
|
|
72
|
+
return migrations.map((m) => m[this.sortKey]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.DynamoDBStorage = DynamoDBStorage;
|
|
76
76
|
//# sourceMappingURL=umzugDynamoDBStorage.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/template-dynamodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Utilities for building modules for DynamoDB access.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@aws-sdk/util-dynamodb": "^3.87.0",
|
|
43
|
-
"@goldstack/infra": "0.
|
|
44
|
-
"@goldstack/infra-aws": "0.
|
|
45
|
-
"@goldstack/utils-esbuild": "0.
|
|
46
|
-
"@goldstack/utils-package": "0.
|
|
47
|
-
"@goldstack/utils-package-config-embedded": "0.
|
|
48
|
-
"@goldstack/utils-terraform": "0.
|
|
43
|
+
"@goldstack/infra": "0.4.0",
|
|
44
|
+
"@goldstack/infra-aws": "0.4.0",
|
|
45
|
+
"@goldstack/utils-esbuild": "0.5.0",
|
|
46
|
+
"@goldstack/utils-package": "0.4.0",
|
|
47
|
+
"@goldstack/utils-package-config-embedded": "0.5.0",
|
|
48
|
+
"@goldstack/utils-terraform": "0.4.0",
|
|
49
49
|
"aws-sdk": "2.1055.0",
|
|
50
50
|
"testcontainers": "^8.12.0",
|
|
51
51
|
"umzug": "^3.1.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@goldstack/utils-docs-cli": "0.3.11",
|
|
55
|
-
"@goldstack/utils-git": "0.
|
|
56
|
-
"@goldstack/utils-package-config-generate": "0.
|
|
57
|
-
"@types/jest": "^
|
|
58
|
-
"@types/node": "^
|
|
55
|
+
"@goldstack/utils-git": "0.2.0",
|
|
56
|
+
"@goldstack/utils-package-config-generate": "0.3.0",
|
|
57
|
+
"@types/jest": "^28.1.8",
|
|
58
|
+
"@types/node": "^18.7.13",
|
|
59
59
|
"@types/yargs": "^17.0.10",
|
|
60
60
|
"jest": "^28.1.0",
|
|
61
61
|
"rimraf": "^3.0.2",
|