Skip to content

Commit e0d28c6

Browse files
committed
enable additional lint rules and fix
1 parent a4f1c12 commit e0d28c6

File tree

9 files changed

+48
-45
lines changed

9 files changed

+48
-45
lines changed

eslint.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ js.configs.recommended,
4646
"block-scoped-var": 2,
4747
"callback-return": 2,
4848
"default-case": 2,
49-
"semi": 2
49+
"semi": 2,
50+
"quotes": [2, "single", { "avoidEscape": true }]
51+
}
52+
},
53+
{
54+
files: ["lib/*"],
55+
rules: {
56+
"no-shadow":2,
5057
}
5158
},
52-
// {
53-
// files: ["lib/*"],
54-
// rules: {
55-
// "no-shadow":2,
56-
// "quotes": [2, "single", { "avoidEscape": true }]
57-
// }
58-
// },
5959
];
6060

lib/model.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const deepCloneObjectsAndArrays = (v) => {
6060
if (Array.isArray(v)) {
6161
return v.map(deepCloneObjectsAndArrays);
6262
} else if ((v?.constructor === Object) || (v instanceof BaseModel)) {
63-
return Object.fromEntries(Object.entries(v).map(([k,v]) => [k, deepCloneObjectsAndArrays(v)]));
63+
return Object.fromEntries(Object.entries(v).map(([k2,v2]) => [k2, deepCloneObjectsAndArrays(v2)]));
6464
} else {
6565
return v;
6666
}
@@ -774,7 +774,7 @@ class BaseModel {
774774
// { key1: {$between: [v1, v2]}} -> {key: key1, values: [v1, v2], condition: '$between'}
775775
return Object.entries(queryObject).map( ([k,v]) => {
776776
if (typeof v === 'object') {
777-
const conditions = Object.keys(v).filter(k => k.startsWith('$'));
777+
const conditions = Object.keys(v).filter(k2 => k2.startsWith('$'));
778778
if (conditions.length > 1) {
779779
throw new Error(`Only a single ${[...supportedQueryConditions.keys()].join('/')} condition is supported in the simple query api.`);
780780
} else if (conditions.length === 1) {

lib/schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const attributeTypeFromSchema = (indexName, schema, propertyName) => {
4747
throw new Error(`The schema type of property .${propertyName}, "${JSON.stringify(schema?.properties?.[propertyName])}" used by index "${indexName}" is not indexable.`);
4848
};
4949

50-
const parseIndexSpecification = (index, schemaSource) => {
51-
if (!index) return [];
50+
const parseIndexSpecification = (indexSpecs, schemaSource) => {
51+
if (!indexSpecs) return [];
5252
const indices = [];
53-
for (const [indexName, indexSpec] of Object.entries(index)) {
53+
for (const [indexName, indexSpec] of Object.entries(indexSpecs)) {
5454
if (!validIndexName.exec(indexName)) {
5555
throw new Error(`Invalid index name "${indexName}": Must be between 3 and 255 characters long, and may contain only the characters a-z, A-Z, 0-9, '_', '-', and '.'.`);
5656
}

test/crud.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22

33
const clientOptions = {
44
endpoint: 'http://localhost:8000'
@@ -7,7 +7,7 @@ const clientOptions = {
77
const DynamoDMConstructor = require('../');
88
const DynamoDM = DynamoDMConstructor({clientOptions, logger:{level:'error'}});
99

10-
t.test('crud:', async t => {
10+
tap.test('crud:', async t => {
1111
const table = DynamoDM.Table({ name: 'test-table-crud'});
1212
const ThingSchema = DynamoDM.Schema('namespace.thing', {
1313
properties: {
@@ -161,4 +161,4 @@ t.test('crud:', async t => {
161161
t.end();
162162
});
163163

164-
t.end();
164+
tap.end();

test/model.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22

33
const clientOptions = {
44
endpoint: 'http://localhost:8000'
@@ -7,7 +7,7 @@ const clientOptions = {
77
const DynamoDMConstructor = require('../');
88
const DynamoDM = DynamoDMConstructor({clientOptions, logger:{level:'error'}});
99

10-
t.test('model:', async t => {
10+
tap.test('model:', async t => {
1111
const table = DynamoDM.Table({ name: 'test-table-models'});
1212
const FooSchema = DynamoDM.Schema('namespace.foo', {
1313
properties: {
@@ -179,3 +179,5 @@ t.test('model:', async t => {
179179
t.end();
180180
});
181181
});
182+
183+
tap.end();

test/multi.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22

33
const clientOptions = {
44
endpoint: 'http://localhost:8000'
@@ -14,13 +14,13 @@ const DynamoDMConstructor2 = require('../');
1414
const DynamoDM1 = DynamoDMConstructor1({clientOptions, logger:{level:'error'}});
1515
const DynamoDM2 = DynamoDMConstructor2({clientOptions, logger:{level:'error'}});
1616

17-
t.test('unique identity', async t => {
17+
tap.test('unique identity', async t => {
1818
t.ok(DynamoDMConstructor1 !== DynamoDMConstructor2, "check that we've created separate module instances for testing");
1919
t.notOk(DynamoDM1.Schema('test') instanceof DynamoDM2.Schema('test').constructor, 'check that Schema types are unique');
2020
});
2121

2222

23-
t.test('crud with schema from separate module', async t => {
23+
tap.test('crud with schema from separate module', async t => {
2424
const table = DynamoDM1.Table({ name: 'test-table-multi-crud'});
2525
const ThingSchema = DynamoDM2.Schema('namespace.thing', {
2626
properties: {
@@ -76,4 +76,4 @@ t.test('crud with schema from separate module', async t => {
7676
t.end();
7777
});
7878

79-
t.end();
79+
tap.end();

test/queries.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22

33
const clientOptions = {
44
endpoint: 'http://localhost:8000'
@@ -15,7 +15,7 @@ async function arrayFromAsync(iter) {
1515
return r;
1616
}
1717

18-
t.test('queries:', async t => {
18+
tap.test('queries:', async t => {
1919
const table = DynamoDM.Table({ name: 'test-table-queries'});
2020
const FooSchema = DynamoDM.Schema('namespace.foo', {
2121
properties: {
@@ -709,7 +709,7 @@ t.test('queries:', async t => {
709709
t.end();
710710
});
711711

712-
t.test('largeQueries', async t => {
712+
tap.test('largeQueries', async t => {
713713
const table = DynamoDM.Table({ name: 'test-table-largequeries'});
714714
const XSchema = DynamoDM.Schema('x', {
715715
properties: {
@@ -763,3 +763,5 @@ t.test('largeQueries', async t => {
763763
});
764764

765765
});
766+
767+
tap.end();

test/schemas.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22

33
const clientOptions = {
44
endpoint: 'http://localhost:8000'
@@ -7,7 +7,7 @@ const clientOptions = {
77
const DynamoDMConstructor = require('../');
88
const DynamoDM = DynamoDMConstructor({clientOptions, logger:{level:'error'}});
99

10-
t.test('basic schemas:', async t => {
10+
tap.test('basic schemas:', async t => {
1111
const table = DynamoDM.Table({ name: 'test-table-schemas'});
1212

1313
await t.test('empty schema', async t => {
@@ -303,7 +303,7 @@ t.test('basic schemas:', async t => {
303303
});
304304
});
305305

306-
t.test('virtuals:', async t => {
306+
tap.test('virtuals:', async t => {
307307
t.test('string aliases', async t => {
308308
const table = DynamoDM.Table({ name: 'test-table-2'});
309309
const ASchema = DynamoDM.Schema('virtualsA', {
@@ -467,7 +467,7 @@ t.test('virtuals:', async t => {
467467
});
468468
});
469469

470-
t.test('converters:', async t => {
470+
tap.test('converters:', async t => {
471471
t.test('sync field creation and deletion', async t => {
472472
const table = DynamoDM.Table({ name: 'test-table-2'});
473473
const ASchema = DynamoDM.Schema('testConverters', {
@@ -553,7 +553,7 @@ t.test('converters:', async t => {
553553
});
554554
});
555555

556-
t.test('custom field names', async t => {
556+
tap.test('custom field names', async t => {
557557
const table = DynamoDM.Table({ name: 'test-table-custom-names'});
558558

559559
// models should have default .id, .type, .createdAt, .updatedAt properties
@@ -577,7 +577,7 @@ t.test('custom field names', async t => {
577577
t.equal(doc.myVersion, 1);
578578
});
579579

580-
t.test('versioning', async t => {
580+
tap.test('versioning', async t => {
581581
const logger = require('pino')({level:'warn'});
582582
// stop child logger creation so we can intercept messages
583583
logger.child = () => { return logger; };
@@ -784,7 +784,7 @@ t.test('versioning', async t => {
784784
});
785785
});
786786

787-
t.test('schema errors', async t => {
787+
tap.test('schema errors', async t => {
788788
const table = DynamoDM.Table({ name: 'test-table-schemas'});
789789

790790
const AStringSchema = DynamoDM.Schema('namespace.thing', { properties: { a: {type: 'string'}, } });
@@ -938,4 +938,4 @@ t.test('schema errors', async t => {
938938
});
939939
});
940940

941-
t.end();
941+
tap.end();

test/table.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const t = require('tap');
1+
const tap = require('tap');
22
const { DescribeTableCommand } = require('@aws-sdk/client-dynamodb');
33

44
const clientOptions = {
@@ -8,10 +8,9 @@ const clientOptions = {
88
const DynamoDMConstructor = require('../');
99
const DynamoDM = DynamoDMConstructor({clientOptions, logger:{level:'error'}});
1010

11-
t.pass('import ok');
11+
tap.pass('import ok');
1212

13-
t.test('incorrect usage throws', async t => {
14-
const DynamoDMConstructor = require('../');
13+
tap.test('incorrect usage throws', async t => {
1514
t.throws(() => {
1615
DynamoDMConstructor.Table({name: 'test-table-1'});
1716
}, {message: "DynamoDM must be called as a function to get an instance of the API, e.g. const DynamoDM = require('dynamodm')(options);"}, 'DynamoDM.Table() throws');
@@ -21,7 +20,7 @@ t.test('incorrect usage throws', async t => {
2120
}, {message: "DynamoDM must be called as a function to get an instance of the API, e.g. const DynamoDM = require('dynamodm')(options);"}, 'DynamoDM.Schema() throws');
2221
});
2322

24-
t.test('table initialisation', async t => {
23+
tap.test('table initialisation', async t => {
2524
await t.test('create without schemas', async t => {
2625
const table = DynamoDM.Table({ name: 'test-table-1', clientOptions});
2726
await t.rejects(table.ready());
@@ -73,7 +72,7 @@ t.test('table initialisation', async t => {
7372
});
7473
});
7574

76-
t.test('waiting for table creation', async t => {
75+
tap.test('waiting for table creation', async t => {
7776
const table = DynamoDM.Table({ name: 'test-table-slow-creation', clientOptions});
7877
table.model(DynamoDM.Schema('emptySchema'));
7978

@@ -101,7 +100,7 @@ t.test('waiting for table creation', async t => {
101100
t.equal(commandSendResults().length, 3, 'Should wait for success.');
102101
});
103102

104-
t.test('waiting for table UPDATING', async t => {
103+
tap.test('waiting for table UPDATING', async t => {
105104
const table = DynamoDM.Table({ name: 'test-table-slow-creation', clientOptions});
106105
table.model(DynamoDM.Schema('emptySchema'));
107106

@@ -142,7 +141,7 @@ t.test('waiting for table UPDATING', async t => {
142141
t.equal(commandSendResults().length, 2, 'UPDATING should be considered created, requiring only two responses.');
143142
});
144143

145-
t.test('table consistency:', async t => {
144+
tap.test('table consistency:', async t => {
146145
t.test('throws on inconsistent id field names', async t => {
147146
const table = DynamoDM.Table({ name: 'test-table-errors'});
148147
table.model(DynamoDM.Schema('schema1'));
@@ -282,7 +281,7 @@ t.test('table consistency:', async t => {
282281
t.end();
283282
});
284283

285-
t.test('index creation fails', async t => {
284+
tap.test('index creation fails', async t => {
286285
const Schema1_noIndexes = DynamoDM.Schema('1', {
287286
properties: {
288287
aString: {type:'string'},
@@ -342,7 +341,7 @@ t.test('index creation fails', async t => {
342341
t.end();
343342
});
344343

345-
t.test('wait for index creation', async t => {
344+
tap.test('wait for index creation', async t => {
346345
const Schema1_noIndexes = DynamoDM.Schema('1', {
347346
properties: {
348347
aString: {type:'string'},
@@ -394,7 +393,7 @@ t.test('wait for index creation', async t => {
394393
t.end();
395394
});
396395

397-
t.test("don't wait for index creation", async t => {
396+
tap.test("don't wait for index creation", async t => {
398397
const Schema1_noIndexes = DynamoDM.Schema('1', {
399398
properties: {
400399
aString: {type:'string'},
@@ -445,4 +444,4 @@ t.test("don't wait for index creation", async t => {
445444
t.end();
446445
});
447446

448-
t.end();
447+
tap.end();

0 commit comments

Comments
 (0)