@webda/aws 2.0.0-beta.3 → 2.0.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/lib/deployers/cloudformation.d.ts +2 -2
- package/lib/deployers/cloudformation.js +672 -693
- package/lib/deployers/cloudformation.js.map +1 -1
- package/lib/deployers/cloudformation.spec.js +428 -477
- package/lib/deployers/cloudformation.spec.js.map +1 -1
- package/lib/deployers/index.js +282 -342
- package/lib/deployers/index.js.map +1 -1
- package/lib/deployers/index.spec.d.ts +1 -1
- package/lib/deployers/index.spec.js +445 -510
- package/lib/deployers/index.spec.js.map +1 -1
- package/lib/deployers/lambda-entrypoint.js +4 -16
- package/lib/deployers/lambda-entrypoint.js.map +1 -1
- package/lib/deployers/lambdapackager.js +13 -52
- package/lib/deployers/lambdapackager.js.map +1 -1
- package/lib/deployers/lambdapackager.spec.js +25 -61
- package/lib/deployers/lambdapackager.spec.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -17
- package/lib/index.js.map +1 -1
- package/lib/index.spec.d.ts +1 -1
- package/lib/index.spec.js +28 -75
- package/lib/index.spec.js.map +1 -1
- package/lib/services/aws-mixin.d.ts +2 -0
- package/lib/services/aws-mixin.js +2 -7
- package/lib/services/aws-mixin.js.map +1 -1
- package/lib/services/cloudwatchlogger.d.ts +3 -1
- package/lib/services/cloudwatchlogger.js +63 -104
- package/lib/services/cloudwatchlogger.js.map +1 -1
- package/lib/services/cloudwatchlogger.spec.js +57 -100
- package/lib/services/cloudwatchlogger.spec.js.map +1 -1
- package/lib/services/dynamodb.d.ts +4 -2
- package/lib/services/dynamodb.js +457 -498
- package/lib/services/dynamodb.js.map +1 -1
- package/lib/services/dynamodb.spec.d.ts +2 -2
- package/lib/services/dynamodb.spec.js +232 -302
- package/lib/services/dynamodb.spec.js.map +1 -1
- package/lib/services/index.d.ts +9 -9
- package/lib/services/index.js +8 -24
- package/lib/services/index.js.map +1 -1
- package/lib/services/lambdacaller.d.ts +2 -0
- package/lib/services/lambdacaller.js +15 -29
- package/lib/services/lambdacaller.js.map +1 -1
- package/lib/services/lambdacaller.spec.js +43 -81
- package/lib/services/lambdacaller.spec.js.map +1 -1
- package/lib/services/lambdaserver.js +168 -190
- package/lib/services/lambdaserver.js.map +1 -1
- package/lib/services/lambdaserver.spec.js +266 -354
- package/lib/services/lambdaserver.spec.js.map +1 -1
- package/lib/services/route53.js +112 -137
- package/lib/services/route53.js.map +1 -1
- package/lib/services/route53.spec.js +56 -92
- package/lib/services/route53.spec.js.map +1 -1
- package/lib/services/s3binary.d.ts +6 -2
- package/lib/services/s3binary.js +189 -251
- package/lib/services/s3binary.js.map +1 -1
- package/lib/services/s3binary.spec.js +185 -254
- package/lib/services/s3binary.spec.js.map +1 -1
- package/lib/services/secretsmanager.d.ts +2 -0
- package/lib/services/secretsmanager.js +32 -56
- package/lib/services/secretsmanager.js.map +1 -1
- package/lib/services/secretsmanager.spec.js +50 -93
- package/lib/services/secretsmanager.spec.js.map +1 -1
- package/lib/services/sqsqueue.d.ts +5 -7
- package/lib/services/sqsqueue.js +70 -99
- package/lib/services/sqsqueue.js.map +1 -1
- package/lib/services/sqsqueue.spec.js +95 -145
- package/lib/services/sqsqueue.spec.js.map +1 -1
- package/lib/shell.js +19 -38
- package/lib/shell.js.map +1 -1
- package/package.json +12 -9
- package/webda.module.json +48 -0
|
@@ -1,83 +1,36 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
6
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
32
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
7
|
var DynamoDBTest_1;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
yield (0, index_spec_1.checkLocalStack)();
|
|
67
|
-
this.buildWebda();
|
|
68
|
-
yield DynamoDBTest_1.install("webda-test-idents");
|
|
69
|
-
yield DynamoDBTest_1.install("webda-test-users");
|
|
70
|
-
yield _super.before.call(this);
|
|
71
|
-
});
|
|
8
|
+
import { BatchWriteItemCommand, DescribeTableCommand, DynamoDB, DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
|
|
9
|
+
import { suite, test } from "@testdeck/mocha";
|
|
10
|
+
import { getCommonJS, Ident, UpdateConditionFailError } from "@webda/core";
|
|
11
|
+
import { StoreTest } from "@webda/core/lib/stores/store.spec.js";
|
|
12
|
+
import { WorkerOutput } from "@webda/workout";
|
|
13
|
+
import * as assert from "assert";
|
|
14
|
+
import { mockClient } from "aws-sdk-client-mock";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import * as sinon from "sinon";
|
|
17
|
+
import { checkLocalStack, defaultCreds } from "../index.spec.js";
|
|
18
|
+
import { DynamoStore, DynamoStoreParameters } from "./dynamodb.js";
|
|
19
|
+
const { __dirname } = getCommonJS(import.meta.url);
|
|
20
|
+
let DynamoDBTest = DynamoDBTest_1 = class DynamoDBTest extends StoreTest {
|
|
21
|
+
async before() {
|
|
22
|
+
process.env.AWS_ACCESS_KEY_ID = defaultCreds.accessKeyId;
|
|
23
|
+
process.env.AWS_SECRET_ACCESS_KEY = defaultCreds.secretAccessKey;
|
|
24
|
+
process.env.AWS_DEFAULT_REGION = "us-east-1";
|
|
25
|
+
await checkLocalStack();
|
|
26
|
+
this.buildWebda();
|
|
27
|
+
await DynamoDBTest_1.install("webda-test-idents");
|
|
28
|
+
await DynamoDBTest_1.install("webda-test-users");
|
|
29
|
+
await super.before();
|
|
72
30
|
}
|
|
73
|
-
tweakApp(app) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
_super.tweakApp.call(this, app);
|
|
79
|
-
app.addService("test/awsevents", (yield Promise.resolve().then(() => __importStar(require(path_1.default.join(__dirname, ..."../../test/moddas/awsevents.js".split("/")))))).default);
|
|
80
|
-
});
|
|
31
|
+
async tweakApp(app) {
|
|
32
|
+
super.tweakApp(app);
|
|
33
|
+
app.addService("test/awsevents", (await import(path.join(__dirname, ..."../../test/moddas/awsevents.js".split("/")))).AWSEventsHandler);
|
|
81
34
|
}
|
|
82
35
|
getIdentStore() {
|
|
83
36
|
return this.getService("idents");
|
|
@@ -86,148 +39,135 @@ let DynamoDBTest = DynamoDBTest_1 = class DynamoDBTest extends store_spec_1.Stor
|
|
|
86
39
|
return this.getService("users");
|
|
87
40
|
}
|
|
88
41
|
getModelClass() {
|
|
89
|
-
return
|
|
42
|
+
return Ident;
|
|
90
43
|
}
|
|
91
|
-
queryOrder() {
|
|
92
|
-
|
|
93
|
-
// Disable default ordering query as it is not possible with Dynamo
|
|
94
|
-
});
|
|
44
|
+
async queryOrder() {
|
|
45
|
+
// Disable default ordering query as it is not possible with Dynamo
|
|
95
46
|
}
|
|
96
|
-
static install(TableName, GlobalSecondaryIndexes, attrs = []) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
region: "us-east-1"
|
|
102
|
-
});
|
|
103
|
-
try {
|
|
104
|
-
yield dynamodb.describeTable({
|
|
105
|
-
TableName
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
if (err.name === "ResourceNotFoundException") {
|
|
110
|
-
let createTable = {
|
|
111
|
-
TableName,
|
|
112
|
-
ProvisionedThroughput: {
|
|
113
|
-
ReadCapacityUnits: 5,
|
|
114
|
-
WriteCapacityUnits: 5
|
|
115
|
-
},
|
|
116
|
-
GlobalSecondaryIndexes,
|
|
117
|
-
KeySchema: [
|
|
118
|
-
{
|
|
119
|
-
AttributeName: "uuid",
|
|
120
|
-
KeyType: "HASH"
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
AttributeDefinitions: [
|
|
124
|
-
{
|
|
125
|
-
AttributeName: "uuid",
|
|
126
|
-
AttributeType: "S"
|
|
127
|
-
},
|
|
128
|
-
...attrs
|
|
129
|
-
]
|
|
130
|
-
};
|
|
131
|
-
let table = dynamodb.createTable(createTable);
|
|
132
|
-
return table;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
47
|
+
static async install(TableName, GlobalSecondaryIndexes, attrs = []) {
|
|
48
|
+
var dynamodb = new DynamoDB({
|
|
49
|
+
endpoint: "http://localhost:4566",
|
|
50
|
+
credentials: defaultCreds,
|
|
51
|
+
region: "us-east-1"
|
|
135
52
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
53
|
+
try {
|
|
54
|
+
await dynamodb.describeTable({
|
|
55
|
+
TableName
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err.name === "ResourceNotFoundException") {
|
|
60
|
+
let createTable = {
|
|
61
|
+
TableName,
|
|
62
|
+
ProvisionedThroughput: {
|
|
63
|
+
ReadCapacityUnits: 5,
|
|
64
|
+
WriteCapacityUnits: 5
|
|
65
|
+
},
|
|
66
|
+
GlobalSecondaryIndexes,
|
|
142
67
|
KeySchema: [
|
|
143
68
|
{
|
|
144
|
-
AttributeName: "
|
|
69
|
+
AttributeName: "uuid",
|
|
145
70
|
KeyType: "HASH"
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
AttributeName: "order",
|
|
149
|
-
KeyType: "RANGE"
|
|
150
71
|
}
|
|
151
72
|
],
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
73
|
+
AttributeDefinitions: [
|
|
74
|
+
{
|
|
75
|
+
AttributeName: "uuid",
|
|
76
|
+
AttributeType: "S"
|
|
77
|
+
},
|
|
78
|
+
...attrs
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
let table = dynamodb.createTable(createTable);
|
|
82
|
+
return table;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async fillForQuery() {
|
|
87
|
+
await DynamoDBTest_1.install("webda-test-query", [
|
|
88
|
+
{
|
|
89
|
+
IndexName: "States",
|
|
90
|
+
KeySchema: [
|
|
91
|
+
{
|
|
92
|
+
AttributeName: "state",
|
|
93
|
+
KeyType: "HASH"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
AttributeName: "order",
|
|
97
|
+
KeyType: "RANGE"
|
|
156
98
|
}
|
|
99
|
+
],
|
|
100
|
+
Projection: { ProjectionType: "ALL" },
|
|
101
|
+
ProvisionedThroughput: {
|
|
102
|
+
ReadCapacityUnits: 5,
|
|
103
|
+
WriteCapacityUnits: 5
|
|
157
104
|
}
|
|
158
|
-
], [
|
|
159
|
-
{
|
|
160
|
-
AttributeName: "state",
|
|
161
|
-
AttributeType: "S"
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
AttributeName: "order",
|
|
165
|
-
AttributeType: "N"
|
|
166
|
-
}
|
|
167
|
-
]);
|
|
168
|
-
let store = new dynamodb_1.DynamoStore(this.webda, "queryStore", {
|
|
169
|
-
table: "webda-test-query",
|
|
170
|
-
globalIndexes: {
|
|
171
|
-
States: {
|
|
172
|
-
key: "state",
|
|
173
|
-
sort: "order"
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
expose: {
|
|
177
|
-
url: "/none"
|
|
178
|
-
},
|
|
179
|
-
credentials: index_spec_1.defaultCreds,
|
|
180
|
-
endpoint: "http://localhost:4566",
|
|
181
|
-
region: "us-east-1"
|
|
182
|
-
});
|
|
183
|
-
store.resolve();
|
|
184
|
-
yield store.init();
|
|
185
|
-
if ((yield store.getAll()).length < 1000) {
|
|
186
|
-
yield Promise.all(this.getQueryDocuments().map(d => store.save(d)));
|
|
187
105
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// Run default query
|
|
197
|
-
let store = yield _super.query.call(this);
|
|
198
|
-
let res = yield store.query('state = "CA" AND order < 100 ORDER BY team.id ASC, order DESC');
|
|
199
|
-
console.log("RES", res.results.map(c => this.mapQueryModel(c)));
|
|
200
|
-
assert.strictEqual(res.results.shift().order, 96);
|
|
201
|
-
let set = ["CA"];
|
|
202
|
-
for (let i = 1; i < 150; i++) {
|
|
203
|
-
set.push(i.toString(16));
|
|
106
|
+
], [
|
|
107
|
+
{
|
|
108
|
+
AttributeName: "state",
|
|
109
|
+
AttributeType: "S"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
AttributeName: "order",
|
|
113
|
+
AttributeType: "N"
|
|
204
114
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
115
|
+
]);
|
|
116
|
+
let store = new DynamoStore(this.webda, "queryStore", {
|
|
117
|
+
table: "webda-test-query",
|
|
118
|
+
globalIndexes: {
|
|
119
|
+
States: {
|
|
120
|
+
key: "state",
|
|
121
|
+
sort: "order"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
expose: {
|
|
125
|
+
url: "/none"
|
|
126
|
+
},
|
|
127
|
+
credentials: defaultCreds,
|
|
128
|
+
endpoint: "http://localhost:4566",
|
|
129
|
+
region: "us-east-1"
|
|
208
130
|
});
|
|
131
|
+
store.resolve();
|
|
132
|
+
await store.init();
|
|
133
|
+
if ((await store.getAll()).length < 1000) {
|
|
134
|
+
await Promise.all(this.getQueryDocuments().map(d => store.save(d)));
|
|
135
|
+
}
|
|
136
|
+
return store;
|
|
209
137
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
138
|
+
async query() {
|
|
139
|
+
// Run default query
|
|
140
|
+
let store = await super.query();
|
|
141
|
+
let res = await store.query('state = "CA" AND order < 100 ORDER BY team.id ASC, order DESC');
|
|
142
|
+
console.log("RES", res.results.map(c => this.mapQueryModel(c)));
|
|
143
|
+
assert.strictEqual(res.results.shift().order, 96);
|
|
144
|
+
let set = ["CA"];
|
|
145
|
+
for (let i = 1; i < 150; i++) {
|
|
146
|
+
set.push(i.toString(16));
|
|
147
|
+
}
|
|
148
|
+
assert.strictEqual((await store.query(`state IN [${set.map(e => `"${e}"`).join(",")}]`)).results.length, 250);
|
|
149
|
+
// Add more test here
|
|
150
|
+
return store;
|
|
151
|
+
}
|
|
152
|
+
async dateHandling() {
|
|
153
|
+
let userStore = this.getUserStore();
|
|
154
|
+
await userStore.save({
|
|
155
|
+
uuid: "testUpdate",
|
|
156
|
+
subobject: {
|
|
157
|
+
empty: "",
|
|
158
|
+
t: {
|
|
159
|
+
plop: ""
|
|
160
|
+
},
|
|
161
|
+
date: new Date()
|
|
162
|
+
}
|
|
225
163
|
});
|
|
164
|
+
let user = await userStore.get("testUpdate");
|
|
165
|
+
assert.notStrictEqual(user.date, {});
|
|
226
166
|
}
|
|
227
167
|
bodyCleaning() {
|
|
228
168
|
//var parse = require("./data/to_clean.json");
|
|
229
169
|
let identStore = this.getIdentStore();
|
|
230
|
-
let ident = new
|
|
170
|
+
let ident = new Ident();
|
|
231
171
|
ident.load({
|
|
232
172
|
arr: [
|
|
233
173
|
{
|
|
@@ -263,148 +203,138 @@ let DynamoDBTest = DynamoDBTest_1 = class DynamoDBTest extends store_spec_1.Stor
|
|
|
263
203
|
userStore.getParameters().CloudFormationSkip = true;
|
|
264
204
|
assert.deepStrictEqual(userStore.getCloudFormation(undefined), {});
|
|
265
205
|
}
|
|
266
|
-
patchSkip() {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
});
|
|
206
|
+
async patchSkip() {
|
|
207
|
+
let userStore = this.getService("users");
|
|
208
|
+
let s = sinon.spy(userStore._client, "update");
|
|
209
|
+
try {
|
|
210
|
+
await userStore._patch({ uuid: "test" }, "test");
|
|
211
|
+
assert.strictEqual(s.callCount, 0);
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
s.restore();
|
|
215
|
+
}
|
|
278
216
|
}
|
|
279
|
-
deleteWithCondition() {
|
|
280
|
-
|
|
281
|
-
yield assert.rejects(() => this.getService("users")._delete("nop", new Date(), "p"), core_1.UpdateConditionFailError);
|
|
282
|
-
});
|
|
217
|
+
async deleteWithCondition() {
|
|
218
|
+
await assert.rejects(() => this.getService("users")._delete("nop", new Date(), "p"), UpdateConditionFailError);
|
|
283
219
|
}
|
|
284
220
|
params() {
|
|
285
|
-
assert.throws(() => new
|
|
286
|
-
}
|
|
287
|
-
errors() {
|
|
288
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
let stubs = [];
|
|
290
|
-
try {
|
|
291
|
-
const faultyMethod = () => {
|
|
292
|
-
throw new Error("Unknown");
|
|
293
|
-
};
|
|
294
|
-
let userStore = this.getService("users");
|
|
295
|
-
yield assert.rejects(() => userStore._upsertItemToCollection("plop2", "test", "plop", 1, 2, "", new Date()), /Item not found plop2 Store/);
|
|
296
|
-
stubs = ["update", "delete", "put"].map(method => {
|
|
297
|
-
// @ts-ignore
|
|
298
|
-
return sinon.stub(userStore._client, method).callsFake(faultyMethod);
|
|
299
|
-
});
|
|
300
|
-
stubs.push(sinon.stub(userStore._client, "scan").callsFake((p, c) => {
|
|
301
|
-
// @ts-ignore
|
|
302
|
-
throw new Error("Unknown");
|
|
303
|
-
}));
|
|
304
|
-
yield assert.rejects(() => userStore._removeAttribute("plop", "test"), /Unknown/);
|
|
305
|
-
yield assert.rejects(() => userStore._deleteItemFromCollection("plop", "test", 1, "plop", 2, new Date()), /Unknown/);
|
|
306
|
-
yield assert.rejects(() => userStore._upsertItemToCollection("plop", "test", "plop", 1, 2, "", new Date()), /Unknown/);
|
|
307
|
-
yield assert.rejects(() => userStore._delete("plop"), /Unknown/);
|
|
308
|
-
yield assert.rejects(() => userStore._patch({ t: "l" }, "plop"), /Unknown/);
|
|
309
|
-
yield assert.rejects(() => userStore._update({ t: "l" }, "plop"), /Unknown/);
|
|
310
|
-
yield assert.rejects(() => userStore._scan([]), /Unknown/);
|
|
311
|
-
yield assert.rejects(() => userStore._incrementAttribute("plop", "t", 1, new Date()), /Unknown/);
|
|
312
|
-
}
|
|
313
|
-
finally {
|
|
314
|
-
stubs.forEach(s => s.restore());
|
|
315
|
-
}
|
|
316
|
-
});
|
|
221
|
+
assert.throws(() => new DynamoStoreParameters({}, this.getService("users")), /Need to define a table at least/);
|
|
317
222
|
}
|
|
318
|
-
|
|
319
|
-
|
|
223
|
+
async errors() {
|
|
224
|
+
let stubs = [];
|
|
225
|
+
try {
|
|
226
|
+
const faultyMethod = () => {
|
|
227
|
+
throw new Error("Unknown");
|
|
228
|
+
};
|
|
320
229
|
let userStore = this.getService("users");
|
|
321
|
-
|
|
322
|
-
|
|
230
|
+
await assert.rejects(() => userStore._upsertItemToCollection("plop2", "test", "plop", 1, 2, "", new Date()), /Item not found plop2 Store/);
|
|
231
|
+
stubs = ["update", "delete", "put"].map(method => {
|
|
323
232
|
// @ts-ignore
|
|
324
|
-
|
|
325
|
-
throw err;
|
|
233
|
+
return sinon.stub(userStore._client, method).callsFake(faultyMethod);
|
|
326
234
|
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
235
|
+
stubs.push(sinon.stub(userStore._client, "scan").callsFake((p, c) => {
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
throw new Error("Unknown");
|
|
238
|
+
}));
|
|
239
|
+
await assert.rejects(() => userStore._removeAttribute("plop", "test"), /Unknown/);
|
|
240
|
+
await assert.rejects(() => userStore._deleteItemFromCollection("plop", "test", 1, "plop", 2, new Date()), /Unknown/);
|
|
241
|
+
await assert.rejects(() => userStore._upsertItemToCollection("plop", "test", "plop", 1, 2, "", new Date()), /Unknown/);
|
|
242
|
+
await assert.rejects(() => userStore._delete("plop"), /Unknown/);
|
|
243
|
+
await assert.rejects(() => userStore._patch({ t: "l" }, "plop"), /Unknown/);
|
|
244
|
+
await assert.rejects(() => userStore._update({ t: "l" }, "plop"), /Unknown/);
|
|
245
|
+
await assert.rejects(() => userStore._scan([]), /Unknown/);
|
|
246
|
+
await assert.rejects(() => userStore._incrementAttribute("plop", "t", 1, new Date()), /Unknown/);
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
stubs.forEach(s => s.restore());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async patch() {
|
|
253
|
+
let userStore = this.getService("users");
|
|
254
|
+
let stub = sinon.stub(userStore._client, "update").callsFake(() => {
|
|
255
|
+
let err = new Error();
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
err.code = "ConditionalCheckFailedException";
|
|
258
|
+
throw err;
|
|
333
259
|
});
|
|
260
|
+
try {
|
|
261
|
+
assert.rejects(() => userStore._patch({ t: "l" }, "plop"), UpdateConditionFailError);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
stub.restore();
|
|
265
|
+
}
|
|
334
266
|
}
|
|
335
|
-
copyTable() {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
ItemCount: 50
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
const results = [];
|
|
345
|
-
let output = new workout_1.WorkerOutput();
|
|
346
|
-
for (let i = 0; i < 50; i++) {
|
|
347
|
-
results.push({ Item: { S: `Title ${i}` } });
|
|
267
|
+
async copyTable() {
|
|
268
|
+
const mock = mockClient(DynamoDBClient);
|
|
269
|
+
try {
|
|
270
|
+
mock.on(DescribeTableCommand).resolves({
|
|
271
|
+
Table: {
|
|
272
|
+
ItemCount: 50
|
|
348
273
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
if (offset + 35 < results.length) {
|
|
356
|
-
LastEvaluatedKey = { year: { N: (offset + 35).toString() } };
|
|
357
|
-
}
|
|
358
|
-
return {
|
|
359
|
-
Items: results.slice(offset, 35),
|
|
360
|
-
LastEvaluatedKey
|
|
361
|
-
};
|
|
362
|
-
}));
|
|
363
|
-
mock.on(client_dynamodb_1.BatchWriteItemCommand).resolves({});
|
|
364
|
-
let userStore = this.getService("users");
|
|
365
|
-
yield dynamodb_1.DynamoStore.copyTable(output, "table1", "table2");
|
|
366
|
-
}
|
|
367
|
-
finally {
|
|
368
|
-
mock.restore();
|
|
274
|
+
});
|
|
275
|
+
const results = [];
|
|
276
|
+
let output = new WorkerOutput();
|
|
277
|
+
for (let i = 0; i < 50; i++) {
|
|
278
|
+
results.push({ Item: { S: `Title ${i}` } });
|
|
369
279
|
}
|
|
370
|
-
|
|
280
|
+
mock.on(ScanCommand).callsFake(async (p) => {
|
|
281
|
+
let offset = 0;
|
|
282
|
+
let LastEvaluatedKey;
|
|
283
|
+
if (p.ExclusiveStartKey) {
|
|
284
|
+
offset = parseInt(p.ExclusiveStartKey.year.N);
|
|
285
|
+
}
|
|
286
|
+
if (offset + 35 < results.length) {
|
|
287
|
+
LastEvaluatedKey = { year: { N: (offset + 35).toString() } };
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
Items: results.slice(offset, 35),
|
|
291
|
+
LastEvaluatedKey
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
mock.on(BatchWriteItemCommand).resolves({});
|
|
295
|
+
let userStore = this.getService("users");
|
|
296
|
+
await DynamoStore.copyTable(output, "table1", "table2");
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
mock.restore();
|
|
300
|
+
}
|
|
371
301
|
}
|
|
372
302
|
};
|
|
373
303
|
__decorate([
|
|
374
|
-
|
|
304
|
+
test
|
|
375
305
|
], DynamoDBTest.prototype, "queryOrder", null);
|
|
376
306
|
__decorate([
|
|
377
|
-
|
|
307
|
+
test
|
|
378
308
|
], DynamoDBTest.prototype, "query", null);
|
|
379
309
|
__decorate([
|
|
380
|
-
|
|
310
|
+
test
|
|
381
311
|
], DynamoDBTest.prototype, "dateHandling", null);
|
|
382
312
|
__decorate([
|
|
383
|
-
|
|
313
|
+
test
|
|
384
314
|
], DynamoDBTest.prototype, "bodyCleaning", null);
|
|
385
315
|
__decorate([
|
|
386
|
-
|
|
316
|
+
test
|
|
387
317
|
], DynamoDBTest.prototype, "ARNPolicy", null);
|
|
388
318
|
__decorate([
|
|
389
|
-
|
|
319
|
+
test
|
|
390
320
|
], DynamoDBTest.prototype, "patchSkip", null);
|
|
391
321
|
__decorate([
|
|
392
|
-
|
|
322
|
+
test
|
|
393
323
|
], DynamoDBTest.prototype, "deleteWithCondition", null);
|
|
394
324
|
__decorate([
|
|
395
|
-
|
|
325
|
+
test
|
|
396
326
|
], DynamoDBTest.prototype, "params", null);
|
|
397
327
|
__decorate([
|
|
398
|
-
|
|
328
|
+
test
|
|
399
329
|
], DynamoDBTest.prototype, "errors", null);
|
|
400
330
|
__decorate([
|
|
401
|
-
|
|
331
|
+
test
|
|
402
332
|
], DynamoDBTest.prototype, "patch", null);
|
|
403
333
|
__decorate([
|
|
404
|
-
|
|
334
|
+
test
|
|
405
335
|
], DynamoDBTest.prototype, "copyTable", null);
|
|
406
336
|
DynamoDBTest = DynamoDBTest_1 = __decorate([
|
|
407
|
-
|
|
337
|
+
suite
|
|
408
338
|
], DynamoDBTest);
|
|
409
|
-
|
|
339
|
+
export { DynamoDBTest };
|
|
410
340
|
//# sourceMappingURL=dynamodb.spec.js.map
|