Skip to content

Commit 11d0049

Browse files
committed
lint
1 parent 102c7c0 commit 11d0049

File tree

13 files changed

+68
-68
lines changed

13 files changed

+68
-68
lines changed

apps/velo-external-db/test/drivers/index_api_rest_matchers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { IndexFieldOrder, IndexStatus, Index } from "libs/velo-external-db-core/src/spi-model/indexing";
1+
import { indexSpi } from '@wix-velo/velo-external-db-core'
2+
const { IndexFieldOrder, IndexStatus } = indexSpi
23

34
const responseWith = (matcher: any) => expect.objectContaining({ data: matcher })
45

56

6-
const indexWith = (index: Index, extraProps: Partial<Index>) => ({
7+
const indexWith = (index: indexSpi.Index, extraProps: Partial<indexSpi.Index>) => ({
78
...index,
89
fields: index.fields.map(field => ({
910
...field,
@@ -17,9 +18,9 @@ const indexWith = (index: Index, extraProps: Partial<Index>) => ({
1718
export const listIndexResponseWithDefaultIndex = () =>
1819
expect.arrayContaining([toHaveDefaultIndex()])
1920

20-
export const listIndexResponseWith = (indexes: Index[]) =>
21+
export const listIndexResponseWith = (indexes: indexSpi.Index[]) =>
2122
expect.arrayContaining(
22-
[...indexes.map((index: Index) => indexWith(index, { status: IndexStatus.ACTIVE }))]
23+
[...indexes.map((index: indexSpi.Index) => indexWith(index, { status: IndexStatus.ACTIVE }))]
2324
)
2425

2526
export const toHaveDefaultIndex = () => ({
@@ -36,10 +37,10 @@ export const toHaveDefaultIndex = () => ({
3637
})
3738

3839

39-
export const createIndexResponseWith = (index: Index) => responseWith(({ index: indexWith(index, { status: IndexStatus.BUILDING }) }))
40+
export const createIndexResponseWith = (index: indexSpi.Index) => responseWith(({ index: indexWith(index, { status: IndexStatus.BUILDING }) }))
4041

4142
export const removeIndexResponse = () => responseWith(({}))
4243

43-
export const listIndexResponseWithFailedIndex = (index: Index) => {
44+
export const listIndexResponseWithFailedIndex = (index: indexSpi.Index) => {
4445
return expect.arrayContaining([indexWith(index, { status: IndexStatus.FAILED })])
4546
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
import { authOwner } from "@wix-velo/external-db-testkit"
2-
import { streamToArray } from "@wix-velo/test-commons"
3-
import waitUntil from "async-wait-until"
4-
import { CreateIndexRequest, Index, ListIndexesRequest } from "libs/velo-external-db-core/src/spi-model/indexing"
1+
import { streamToArray } from '@wix-velo/test-commons'
2+
import waitUntil from 'async-wait-until'
3+
import { indexSpi } from '@wix-velo/velo-external-db-core'
54

65
const axios = require('axios').create({
76
baseURL: 'http://localhost:8080'
87
})
98

10-
export const givenIndexes = async (collectionName: string, indexes: Index[], auth: any) => {
9+
export const givenIndexes = async(collectionName: string, indexes: indexSpi.Index[], auth: any) => {
1110
for (const index of indexes) {
12-
await axios.post('/indexes/create', { dataCollectionId: collectionName, index } as CreateIndexRequest, auth)
11+
await axios.post('/indexes/create', { dataCollectionId: collectionName, index } as indexSpi.CreateIndexRequest, auth)
1312
}
1413
await Promise.all(indexes.map(index => indexCreated(collectionName, index.name, auth)))
1514
}
1615

17-
const indexCreated = async (collectionName: string, indexName: string, auth: any) => {
18-
await waitUntil(async () => {
19-
const indexes = await retrieveIndexesFor(collectionName) as Index[]
16+
const indexCreated = async(collectionName: string, indexName: string, auth: any) => {
17+
await waitUntil(async() => {
18+
const indexes = await retrieveIndexesFor(collectionName, auth) as indexSpi.Index[]
2019
return indexes.some(index => index.name === indexName)
2120
})
2221
}
2322

24-
export const retrieveIndexesFor = async (collectionName: string) => axios.post('/indexes/list', { dataCollectionId: collectionName }, {responseType: 'stream', ...authOwner})
25-
.then(response => streamToArray(response.data))
23+
export const retrieveIndexesFor = async(collectionName: string, auth: any) => axios.post('/indexes/list', { dataCollectionId: collectionName }, { responseType: 'stream', ...auth })
24+
.then(response => streamToArray(response.data))

apps/velo-external-db/test/e2e/app_index.e2e.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Chance = require('chance')
2-
import { Uninitialized } from '@wix-velo/test-commons';
2+
import { Uninitialized } from '@wix-velo/test-commons'
33
import { authOwner } from '@wix-velo/external-db-testkit'
44
import { initApp, teardownApp, dbTeardown, setupDb, currentDbImplementationName } from '../resources/e2e_resources'
55
import * as schema from '../drivers/schema_api_rest_test_support'
@@ -16,29 +16,29 @@ const axiosServer = axios.create({
1616

1717

1818
describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
19-
beforeAll(async () => {
19+
beforeAll(async() => {
2020
await setupDb()
2121
await initApp()
2222
})
2323

24-
afterAll(async () => {
24+
afterAll(async() => {
2525
await dbTeardown()
2626
}, 20000)
2727

28-
test('list', async () => {
28+
test('list', async() => {
2929
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
3030

31-
expect(index.retrieveIndexesFor(ctx.collectionName)).resolves.toEqual(matchers.listIndexResponseWithDefaultIndex())
31+
await expect(index.retrieveIndexesFor(ctx.collectionName, authOwner)).resolves.toEqual(matchers.listIndexResponseWithDefaultIndex())
3232
})
3333

34-
test('list with multiple indexes', async () => {
34+
test('list with multiple indexes', async() => {
3535
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
3636
await index.givenIndexes(ctx.collectionName, [ctx.index], authOwner)
3737

38-
await expect(index.retrieveIndexesFor(ctx.collectionName)).resolves.toEqual(matchers.listIndexResponseWith([ctx.index]))
38+
await expect(index.retrieveIndexesFor(ctx.collectionName, authOwner)).resolves.toEqual(matchers.listIndexResponseWith([ctx.index]))
3939
})
4040

41-
test('create', async () => {
41+
test('create', async() => {
4242
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
4343

4444
// in-progress
@@ -48,12 +48,12 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
4848
}, authOwner)).resolves.toEqual(matchers.createIndexResponseWith(ctx.index))
4949

5050
// active
51-
await eventually(async () =>
52-
await expect(index.retrieveIndexesFor(ctx.collectionName)).resolves.toEqual(matchers.listIndexResponseWith([ctx.index]))
51+
await eventually(async() =>
52+
await expect(index.retrieveIndexesFor(ctx.collectionName, authOwner)).resolves.toEqual(matchers.listIndexResponseWith([ctx.index]))
5353
)
5454
})
5555

56-
test('create with existing index', async () => {
56+
test('create with existing index', async() => {
5757
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
5858
await index.givenIndexes(ctx.collectionName, [ctx.index], authOwner)
5959

@@ -63,7 +63,7 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
6363
}, authOwner)).rejects.toThrow()
6464
})
6565

66-
test('remove', async () => {
66+
test('remove', async() => {
6767
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
6868
await index.givenIndexes(ctx.collectionName, [ctx.index], authOwner)
6969

@@ -72,25 +72,25 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
7272
indexName: ctx.index.name
7373
}, authOwner)).resolves.toEqual(matchers.removeIndexResponse()).catch()
7474

75-
await expect(index.retrieveIndexesFor(ctx.collectionName)).resolves.not.toEqual(matchers.listIndexResponseWith([ctx.index]))
75+
await expect(index.retrieveIndexesFor(ctx.collectionName, authOwner)).resolves.not.toEqual(matchers.listIndexResponseWith([ctx.index]))
7676
})
7777

7878

79-
test('get failed indexes', async () => {
79+
test('get failed indexes', async() => {
8080
await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner)
8181

8282
await axiosServer.post('/indexes/create', {
8383
dataCollectionId: ctx.collectionName,
8484
index: ctx.invalidIndex
85-
}, authOwner).catch(e=>{})
85+
}, authOwner).catch(_e => {})
8686

8787

88-
await eventually(async () =>
89-
await expect(index.retrieveIndexesFor(ctx.collectionName)).resolves.toEqual(matchers.listIndexResponseWithFailedIndex(ctx.invalidIndex))
88+
await eventually(async() =>
89+
await expect(index.retrieveIndexesFor(ctx.collectionName, authOwner)).resolves.toEqual(matchers.listIndexResponseWithFailedIndex(ctx.invalidIndex))
9090
)
9191
})
9292

93-
afterAll(async () => {
93+
afterAll(async() => {
9494
await teardownApp()
9595
})
9696

@@ -107,4 +107,4 @@ describe(`Velo External DB Index API: ${currentDbImplementationName()}`, () => {
107107
ctx.index = gen.spiIndexFor(ctx.collectionName, [ctx.column.name])
108108
ctx.invalidIndex = gen.spiIndexFor(ctx.collectionName, ['wrongColumn'])
109109
})
110-
});
110+
})

apps/velo-external-db/test/gen.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SystemFields } from '@wix-velo/velo-external-db-commons'
22
import { InputField } from '@wix-velo/velo-external-db-types'
33
import * as Chance from 'chance'
4-
import { Index as spiIndex, IndexFieldOrder } from 'libs/velo-external-db-core/src/spi-model/indexing'
4+
import { indexSpi } from '@wix-velo/velo-external-db-core'
5+
const { IndexFieldOrder } = indexSpi
56

67
const chance = Chance()
78

@@ -106,11 +107,11 @@ export const randomMatchesValueWithDashes = () => {
106107
return arr.join('-')
107108
}
108109

109-
export const spiIndexFor = (collectionName: string, columns: string[]): spiIndex => {
110+
export const spiIndexFor = (_collectionName: string, columns: string[]): indexSpi.Index => {
110111
return {
111112
name: chance.word(),
112-
fields: columns.map((column: string) => ({ path: column, order: chance.pickone([IndexFieldOrder.ASC, IndexFieldOrder.DESC])})),
113+
fields: columns.map((column: string) => ({ path: column, order: chance.pickone([IndexFieldOrder.ASC, IndexFieldOrder.DESC]) })),
113114
unique: chance.bool(),
114115
caseInsensitive: chance.bool(),
115116
}
116-
}
117+
}

apps/velo-external-db/test/utils/eventually.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const defaults = {
55
interval: 200
66
}
77

8-
export const eventually = async (fn: any, opts?: { timeout?: number; interval?: number }) => {
8+
export const eventually = async(fn: any, opts?: { timeout?: number; interval?: number }) => {
99
return Promise.resolve().then(() => {
1010
let error = null
1111
const action = () => Promise.resolve().then(fn).catch(err => {

libs/external-db-mysql/src/mysql_index_provider.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,39 @@ export default class IndexProvider implements IIndexProvider {
5959
}
6060

6161
private async getInProgressIndexesFor(collectionName: string): Promise<{ [x: string]: DomainIndex }> {
62-
const databaseName = this.pool.config.connectionConfig.database;
63-
const inProgressIndexes = await this.query(`SELECT * FROM information_schema.processlist WHERE db = ? AND info LIKE 'CREATE%INDEX%'`, [databaseName])
64-
const domainIndexesForCollection = inProgressIndexes.map((r: any) => this.extractIndexFromQueryForCollection(collectionName, r.INFO)).filter(Boolean) as DomainIndex[];
62+
const databaseName = this.pool.config.connectionConfig.database
63+
const inProgressIndexes = await this.query('SELECT * FROM information_schema.processlist WHERE db = ? AND info LIKE \'CREATE%INDEX%\'', [databaseName])
64+
const domainIndexesForCollection = inProgressIndexes.map((r: any) => this.extractIndexFromQueryForCollection(collectionName, r.INFO)).filter(Boolean) as DomainIndex[]
6565
return domainIndexesForCollection.reduce((acc, index) => {
66-
acc[index.name] = index;
67-
return acc;
68-
}, {} as { [x: string]: DomainIndex });
66+
acc[index.name] = index
67+
return acc
68+
}, {} as { [x: string]: DomainIndex })
6969
}
7070

7171
private extractIndexFromQueryForCollection(collectionName: string, createIndexQuery: string): DomainIndex | undefined {
72-
const regex = /CREATE\s+(UNIQUE)?\s?INDEX\s+`(\w+)`\s+ON\s+`(\w+)`\s+\(([\w\s`,]+)\)/;
73-
const match = createIndexQuery.match(regex);
72+
const regex = /CREATE\s+(UNIQUE)?\s?INDEX\s+`(\w+)`\s+ON\s+`(\w+)`\s+\(([\w\s`,]+)\)/
73+
const match = createIndexQuery.match(regex)
7474
if (match) {
75-
const [, isUnique, name, collection, columnsString] = match;
75+
const [, isUnique, name, collection, columnsString] = match
7676
if (collection === collectionName) {
77-
const columns = columnsString.replace(/`/g, '').split(',').map((column) => column.trim());
77+
const columns = columnsString.replace(/`/g, '').split(',').map((column) => column.trim())
7878
return {
7979
name,
8080
columns,
8181
isUnique: !!isUnique,
8282
caseInsensitive: true,
8383
order: 'ASC',
8484
status: DomainIndexStatus.BUILDING
85-
};
85+
}
8686
}
8787
}
88-
return;
88+
return
8989
}
9090

9191
private async returnStatusAfterXSeconds(x: number, promise: Promise<any>, index: DomainIndex): Promise<DomainIndexStatus> {
9292
return new Promise((resolve, reject) => {
9393
promise.catch((e: any) => {
94-
console.log('failed to create index', e);
94+
console.log('failed to create index', e)
9595
this.failedIndexes[index.name] = ({ ...index, status: DomainIndexStatus.FAILED, error: this.translateErrorCodes(e) })
9696
reject(this.translateErrorCodes(e))
9797
})
@@ -115,4 +115,4 @@ export default class IndexProvider implements IIndexProvider {
115115
return new errors.UnrecognizedError(`Error while creating index: ${e.sqlMessage}`)
116116
}
117117
}
118-
}
118+
}

libs/velo-external-db-commons/src/libs/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ export class IndexDoesNotExist extends BaseHttpError {
9999
constructor(message: string) {
100100
super(message, 404)
101101
}
102-
}
102+
}

libs/velo-external-db-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ export class ExternalDbRouter {
7171
}
7272
}
7373

74-
export * as dataSpi from './spi-model/data_source'
74+
export * as dataSpi from './spi-model/data_source'
75+
export * as indexSpi from './spi-model/indexing'
7576
export { DataService, SchemaService, OperationService, CacheableSchemaInformation, FilterTransformer, AggregationTransformer, QueryValidator, SchemaAwareDataService, ItemTransformer, Hooks, ServiceContext, CollectionCapability, decodeBase64 }

libs/velo-external-db-core/src/router.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ import { JwtAuthenticator } from './web/jwt-auth-middleware'
2626
import * as dataSource from './spi-model/data_source'
2727
import * as capabilities from './spi-model/capabilities'
2828
import { WixDataFacade } from './web/wix_data_facade'
29-
import { json } from 'stream/consumers';
30-
import DataService from './service/data';
31-
import IndexService from './service/indexing';
32-
import { CreateIndexRequest, ListIndexesRequest, RemoveIndexRequest } from './spi-model/indexing';
29+
import IndexService from './service/indexing'
30+
import { CreateIndexRequest, ListIndexesRequest, RemoveIndexRequest } from './spi-model/indexing'
3331

3432

3533
const { InvalidRequest } = errors
@@ -365,7 +363,7 @@ export const createRouter = () => {
365363

366364
// *************** Indexes API **********************
367365

368-
router.post('/indexes/list', async (req, res, next) => {
366+
router.post('/indexes/list', async(req, res, next) => {
369367
try {
370368
const { dataCollectionId: collectionId } = req.body as ListIndexesRequest
371369
const indexes = await indexService.list(collectionId)
@@ -375,7 +373,7 @@ export const createRouter = () => {
375373
}
376374
})
377375

378-
router.post('/indexes/create', async (req, res, next) => {
376+
router.post('/indexes/create', async(req, res, next) => {
379377
try {
380378
const { dataCollectionId: collectionId, index } = req.body as CreateIndexRequest
381379
const createdIndex = await indexService.create(collectionId, index)
@@ -387,7 +385,7 @@ export const createRouter = () => {
387385
}
388386
})
389387

390-
router.post('/indexes/remove', async (req, res, next) => {
388+
router.post('/indexes/remove', async(req, res, next) => {
391389
try {
392390
const { dataCollectionId: collectionId, indexName } = req.body as RemoveIndexRequest
393391
await indexService.remove(collectionId, indexName)

libs/velo-external-db-core/src/service/indexing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ export default class IndexService {
4242
order: spiIndex.fields[0].order,
4343
}
4444
}
45-
}
45+
}

0 commit comments

Comments
 (0)