@webda/aws 2.0.0-beta.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +4 -2
- package/lib/services/cloudwatchlogger.js +63 -103
- 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 +5 -3
- package/lib/services/dynamodb.js +458 -498
- package/lib/services/dynamodb.js.map +1 -1
- package/lib/services/dynamodb.spec.d.ts +2 -2
- package/lib/services/dynamodb.spec.js +231 -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 +3 -1
- package/lib/services/lambdacaller.js +16 -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.d.ts +1 -8
- package/lib/services/lambdaserver.js +168 -206
- 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 +6 -8
- package/lib/services/sqsqueue.js +70 -98
- 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,134 @@ 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
|
+
assert.strictEqual(res.results.shift().order, 96);
|
|
143
|
+
let set = ["CA"];
|
|
144
|
+
for (let i = 1; i < 150; i++) {
|
|
145
|
+
set.push(i.toString(16));
|
|
146
|
+
}
|
|
147
|
+
assert.strictEqual((await store.query(`state IN [${set.map(e => `"${e}"`).join(",")}]`)).results.length, 250);
|
|
148
|
+
// Add more test here
|
|
149
|
+
return store;
|
|
150
|
+
}
|
|
151
|
+
async dateHandling() {
|
|
152
|
+
let userStore = this.getUserStore();
|
|
153
|
+
await userStore.save({
|
|
154
|
+
uuid: "testUpdate",
|
|
155
|
+
subobject: {
|
|
156
|
+
empty: "",
|
|
157
|
+
t: {
|
|
158
|
+
plop: ""
|
|
159
|
+
},
|
|
160
|
+
date: new Date()
|
|
161
|
+
}
|
|
225
162
|
});
|
|
163
|
+
let user = await userStore.get("testUpdate");
|
|
164
|
+
assert.notStrictEqual(user.date, {});
|
|
226
165
|
}
|
|
227
166
|
bodyCleaning() {
|
|
228
167
|
//var parse = require("./data/to_clean.json");
|
|
229
168
|
let identStore = this.getIdentStore();
|
|
230
|
-
let ident = new
|
|
169
|
+
let ident = new Ident();
|
|
231
170
|
ident.load({
|
|
232
171
|
arr: [
|
|
233
172
|
{
|
|
@@ -263,148 +202,138 @@ let DynamoDBTest = DynamoDBTest_1 = class DynamoDBTest extends store_spec_1.Stor
|
|
|
263
202
|
userStore.getParameters().CloudFormationSkip = true;
|
|
264
203
|
assert.deepStrictEqual(userStore.getCloudFormation(undefined), {});
|
|
265
204
|
}
|
|
266
|
-
patchSkip() {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
});
|
|
205
|
+
async patchSkip() {
|
|
206
|
+
let userStore = this.getService("users");
|
|
207
|
+
let s = sinon.spy(userStore._client, "update");
|
|
208
|
+
try {
|
|
209
|
+
await userStore._patch({ uuid: "test" }, "test");
|
|
210
|
+
assert.strictEqual(s.callCount, 0);
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
s.restore();
|
|
214
|
+
}
|
|
278
215
|
}
|
|
279
|
-
deleteWithCondition() {
|
|
280
|
-
|
|
281
|
-
yield assert.rejects(() => this.getService("users")._delete("nop", new Date(), "p"), core_1.UpdateConditionFailError);
|
|
282
|
-
});
|
|
216
|
+
async deleteWithCondition() {
|
|
217
|
+
await assert.rejects(() => this.getService("users")._delete("nop", new Date(), "p"), UpdateConditionFailError);
|
|
283
218
|
}
|
|
284
219
|
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
|
-
});
|
|
220
|
+
assert.throws(() => new DynamoStoreParameters({}, this.getService("users")), /Need to define a table at least/);
|
|
317
221
|
}
|
|
318
|
-
|
|
319
|
-
|
|
222
|
+
async errors() {
|
|
223
|
+
let stubs = [];
|
|
224
|
+
try {
|
|
225
|
+
const faultyMethod = () => {
|
|
226
|
+
throw new Error("Unknown");
|
|
227
|
+
};
|
|
320
228
|
let userStore = this.getService("users");
|
|
321
|
-
|
|
322
|
-
|
|
229
|
+
await assert.rejects(() => userStore._upsertItemToCollection("plop2", "test", "plop", 1, 2, "", new Date()), /Item not found plop2 Store/);
|
|
230
|
+
stubs = ["update", "delete", "put"].map(method => {
|
|
323
231
|
// @ts-ignore
|
|
324
|
-
|
|
325
|
-
throw err;
|
|
232
|
+
return sinon.stub(userStore._client, method).callsFake(faultyMethod);
|
|
326
233
|
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
234
|
+
stubs.push(sinon.stub(userStore._client, "scan").callsFake((p, c) => {
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
throw new Error("Unknown");
|
|
237
|
+
}));
|
|
238
|
+
await assert.rejects(() => userStore._removeAttribute("plop", "test"), /Unknown/);
|
|
239
|
+
await assert.rejects(() => userStore._deleteItemFromCollection("plop", "test", 1, "plop", 2, new Date()), /Unknown/);
|
|
240
|
+
await assert.rejects(() => userStore._upsertItemToCollection("plop", "test", "plop", 1, 2, "", new Date()), /Unknown/);
|
|
241
|
+
await assert.rejects(() => userStore._delete("plop"), /Unknown/);
|
|
242
|
+
await assert.rejects(() => userStore._patch({ t: "l" }, "plop"), /Unknown/);
|
|
243
|
+
await assert.rejects(() => userStore._update({ t: "l" }, "plop"), /Unknown/);
|
|
244
|
+
await assert.rejects(() => userStore._scan([]), /Unknown/);
|
|
245
|
+
await assert.rejects(() => userStore._incrementAttribute("plop", "t", 1, new Date()), /Unknown/);
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
stubs.forEach(s => s.restore());
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async patch() {
|
|
252
|
+
let userStore = this.getService("users");
|
|
253
|
+
let stub = sinon.stub(userStore._client, "update").callsFake(() => {
|
|
254
|
+
let err = new Error();
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
err.code = "ConditionalCheckFailedException";
|
|
257
|
+
throw err;
|
|
333
258
|
});
|
|
259
|
+
try {
|
|
260
|
+
assert.rejects(() => userStore._patch({ t: "l" }, "plop"), UpdateConditionFailError);
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
stub.restore();
|
|
264
|
+
}
|
|
334
265
|
}
|
|
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}` } });
|
|
266
|
+
async copyTable() {
|
|
267
|
+
const mock = mockClient(DynamoDBClient);
|
|
268
|
+
try {
|
|
269
|
+
mock.on(DescribeTableCommand).resolves({
|
|
270
|
+
Table: {
|
|
271
|
+
ItemCount: 50
|
|
348
272
|
}
|
|
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();
|
|
273
|
+
});
|
|
274
|
+
const results = [];
|
|
275
|
+
let output = new WorkerOutput();
|
|
276
|
+
for (let i = 0; i < 50; i++) {
|
|
277
|
+
results.push({ Item: { S: `Title ${i}` } });
|
|
369
278
|
}
|
|
370
|
-
|
|
279
|
+
mock.on(ScanCommand).callsFake(async (p) => {
|
|
280
|
+
let offset = 0;
|
|
281
|
+
let LastEvaluatedKey;
|
|
282
|
+
if (p.ExclusiveStartKey) {
|
|
283
|
+
offset = parseInt(p.ExclusiveStartKey.year.N);
|
|
284
|
+
}
|
|
285
|
+
if (offset + 35 < results.length) {
|
|
286
|
+
LastEvaluatedKey = { year: { N: (offset + 35).toString() } };
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
Items: results.slice(offset, 35),
|
|
290
|
+
LastEvaluatedKey
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
mock.on(BatchWriteItemCommand).resolves({});
|
|
294
|
+
let userStore = this.getService("users");
|
|
295
|
+
await DynamoStore.copyTable(output, "table1", "table2");
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
mock.restore();
|
|
299
|
+
}
|
|
371
300
|
}
|
|
372
301
|
};
|
|
373
302
|
__decorate([
|
|
374
|
-
|
|
303
|
+
test
|
|
375
304
|
], DynamoDBTest.prototype, "queryOrder", null);
|
|
376
305
|
__decorate([
|
|
377
|
-
|
|
306
|
+
test
|
|
378
307
|
], DynamoDBTest.prototype, "query", null);
|
|
379
308
|
__decorate([
|
|
380
|
-
|
|
309
|
+
test
|
|
381
310
|
], DynamoDBTest.prototype, "dateHandling", null);
|
|
382
311
|
__decorate([
|
|
383
|
-
|
|
312
|
+
test
|
|
384
313
|
], DynamoDBTest.prototype, "bodyCleaning", null);
|
|
385
314
|
__decorate([
|
|
386
|
-
|
|
315
|
+
test
|
|
387
316
|
], DynamoDBTest.prototype, "ARNPolicy", null);
|
|
388
317
|
__decorate([
|
|
389
|
-
|
|
318
|
+
test
|
|
390
319
|
], DynamoDBTest.prototype, "patchSkip", null);
|
|
391
320
|
__decorate([
|
|
392
|
-
|
|
321
|
+
test
|
|
393
322
|
], DynamoDBTest.prototype, "deleteWithCondition", null);
|
|
394
323
|
__decorate([
|
|
395
|
-
|
|
324
|
+
test
|
|
396
325
|
], DynamoDBTest.prototype, "params", null);
|
|
397
326
|
__decorate([
|
|
398
|
-
|
|
327
|
+
test
|
|
399
328
|
], DynamoDBTest.prototype, "errors", null);
|
|
400
329
|
__decorate([
|
|
401
|
-
|
|
330
|
+
test
|
|
402
331
|
], DynamoDBTest.prototype, "patch", null);
|
|
403
332
|
__decorate([
|
|
404
|
-
|
|
333
|
+
test
|
|
405
334
|
], DynamoDBTest.prototype, "copyTable", null);
|
|
406
335
|
DynamoDBTest = DynamoDBTest_1 = __decorate([
|
|
407
|
-
|
|
336
|
+
suite
|
|
408
337
|
], DynamoDBTest);
|
|
409
|
-
|
|
338
|
+
export { DynamoDBTest };
|
|
410
339
|
//# sourceMappingURL=dynamodb.spec.js.map
|