Skip to content

Commit 7146a12

Browse files
committed
Removed the need for a separate "rawsources" chunk in serverless.yml. Specifying a raw source is now merely by renaming your json source variable from "sources" to "rawsources".
1 parent f402aa5 commit 7146a12

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

index.js

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,16 @@ class ServerlessDynamodbLocal {
155155
const options = this.options;
156156
const dynamodb = this.dynamodbOptions(options);
157157

158-
const seedPromise = BbPromise.each(this.seedSources, (source) => {
158+
return BbPromise.each(this.seedSources, (source) => {
159159
if (!source.table) {
160160
throw new Error("seeding source \"table\" property not defined");
161161
}
162-
return seeder.locateSeeds(source.sources || [])
162+
const seedPromise = seeder.locateSeeds(source.sources || [])
163163
.then((seeds) => seeder.writeSeeds(dynamodb.doc.batchWrite.bind(dynamodb.doc), source.table, seeds));
164-
});
165-
166-
const rawSeedPromise = BbPromise.each(this.rawSeedSources, (source) => {
167-
if (!source.table) {
168-
throw new Error("Raw seeding source \"table\" property not defined");
169-
}
170-
return seeder.locateSeeds(source.rawsources || [])
164+
const rawSeedPromise = seeder.locateSeeds(source.rawsources || [])
171165
.then((seeds) => seeder.writeSeeds(dynamodb.raw.batchWriteItem.bind(dynamodb.raw), source.table, seeds));
166+
return BbPromise.all([seedPromise, rawSeedPromise]);
172167
});
173-
174-
return BbPromise.all([seedPromise, rawSeedPromise]);
175168
}
176169

177170
removeHandler() {
@@ -268,26 +261,6 @@ class ServerlessDynamodbLocal {
268261
return [].concat.apply([], sourcesByCategory);
269262
}
270263

271-
/**
272-
* Gets the raw seeding sources
273-
*/
274-
get rawSeedSources() {
275-
const config = this.service.custom.dynamodb;
276-
const seedConfig = _.get(config, "seed", {});
277-
const seed = this.options.seed || config.start.seed || seedConfig;
278-
let categories;
279-
if (typeof seed === "string") {
280-
categories = seed.split(",");
281-
} else if(seed) {
282-
categories = Object.keys(seedConfig);
283-
} else { // if (!seed)
284-
this.serverlessLog("DynamoDB - No seeding defined. Skipping data seeding.");
285-
return [];
286-
}
287-
const sourcesByCategory = categories.map((category) => seedConfig[category].rawsources);
288-
return [].concat.apply([], sourcesByCategory);
289-
}
290-
291264
createTable(dynamodb, migration) {
292265
return new BbPromise((resolve, reject) => {
293266
if (migration.StreamSpecification && migration.StreamSpecification.StreamViewType) {

0 commit comments

Comments
 (0)