Commit e5d20640 authored by François Ferry's avatar François Ferry
Browse files

style(prettier): update prettier and run it.

parent 3f0ca54b6fb8
Pipeline #85367 failed with stages
in 3 minutes and 1 second
......@@ -7148,9 +7148,9 @@
"dev": true
},
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
"integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==",
"dev": true
},
"pretty-format": {
......
......@@ -13,12 +13,12 @@ import {waitUntilStarted} from './waitUntilStarted';
const CW_BASE_URL = process.env.CW_BASE_URL ?? 'http://localhost:8080';
beforeAll(async function() {
beforeAll(async function () {
return await waitUntilStarted(CW_BASE_URL);
}, 15 * 1000);
describe('CwSimpleHtttpClient Tests', function() {
it('should be instantiable', function() {
describe('CwSimpleHtttpClient Tests', function () {
it('should be instantiable', function () {
const client = new CwSimpleHttpClient(CW_BASE_URL);
expect(CW_BASE_URL + '/').toBe(client.baseUrl);
});
......@@ -42,7 +42,7 @@ describe('CwSimpleHtttpClient Tests', function() {
});
});
describe('CwSigningHttpClient Tests', function() {
describe('CwSigningHttpClient Tests', function () {
async function getAuthToken() {
const response = await fetch(`${CW_BASE_URL}/admin-token`);
const token = await response.json();
......@@ -50,7 +50,7 @@ describe('CwSigningHttpClient Tests', function() {
return token;
}
it('should be instantiable', async function() {
it('should be instantiable', async function () {
const token = await getAuthToken();
const client = new CwSigningHttpClient(
CW_BASE_URL,
......@@ -67,15 +67,15 @@ describe('CwSigningHttpClient Tests', function() {
);
await client
.transactionV1([['Any U WHERE U login %(l)s', {l: 'admin'}]])
.then(result => {
.then((result) => {
expect(result[0]).not.toBeNull();
expect(result[0].length).toBeGreaterThan(0);
});
});
});
describe('CwRqlClient Tests', function() {
it('should correctly build_url with params', function() {
describe('CwRqlClient Tests', function () {
it('should correctly build_url with params', function () {
const client = new CwRqlClient(new CwSimpleHttpClient(CW_BASE_URL));
const str = client.buildUrl('Any L WHERE U login %(l)s', {l: 'anon'});
expect(str).toBe('view?rql=Any L WHERE U login "anon"&vid=jsonexport');
......@@ -83,7 +83,7 @@ describe('CwRqlClient Tests', function() {
it('should have an query method', async () => {
const client = new CwRqlClient(new CwSimpleHttpClient(CW_BASE_URL));
await client.queryRows('Any L WHERE U login L', {}).then(result => {
await client.queryRows('Any L WHERE U login L', {}).then((result) => {
expect(result).not.toBeNull();
expect(result.length).toBeGreaterThan(0);
});
......@@ -93,7 +93,7 @@ describe('CwRqlClient Tests', function() {
const client = new CwRqlClient(new CwSimpleHttpClient(CW_BASE_URL));
await client
.queryRows('Any U WHERE U login %(l)s', {l: 'anon'})
.then(result => {
.then((result) => {
expect(result).not.toBeNull();
expect(result.length).toBeGreaterThan(0);
});
......@@ -107,7 +107,7 @@ describe('CwRqlClient Tests', function() {
);
await client
.transactionV1([['Any U WHERE U login %(l)s', {l: 'admin'}]])
.then(result => {
.then((result) => {
expect(result).not.toBeNull();
expect(result.length).toBeGreaterThan(0);
});
......@@ -121,7 +121,7 @@ describe('CwRqlClient Tests', function() {
);
await client
.transactionV2([['Any U WHERE U login %(l)s', {l: 'admin'}]])
.then(result => {
.then((result) => {
expect(result).not.toBeNull();
expect(result.length).toBeGreaterThan(0);
expect(result[0].variables.length).toBeGreaterThanOrEqual(1);
......@@ -145,7 +145,7 @@ describe('CwRqlClient Tests', function() {
],
0
)
.then(result => {
.then((result) => {
expect(result).not.toBeNull();
expect(result.length).toBeGreaterThan(0);
expect(result[0].creation_date).not.toBeNull();
......
......@@ -25,7 +25,7 @@ function getCookieValueFromArray(cookies: string[], name: string) {
}
function getCookieValueFromString(cookiesString: string, name: string) {
const cookies = cookiesString.split(';').map(cookie => cookie.trim());
const cookies = cookiesString.split(';').map((cookie) => cookie.trim());
return getCookieValueFromArray(cookies, name);
}
......@@ -119,7 +119,7 @@ function doRequestFetch(
headers: headers,
redirect: 'manual',
credentials: allowsCrossOrigin ? 'include' : 'same-origin',
}).then(response => {
}).then((response) => {
onResponseHeaders(response.headers);
let contentType = response.headers.get('Content-Type');
let toHttpResponse = (content: any): HttpResponse => {
......@@ -200,7 +200,7 @@ function requestFetchWithCookies(
method,
finalContent,
requestHeaders,
responseHeaders => {
(responseHeaders) => {
const cookiesString = responseHeaders.get('Set-Cookie');
if (cookiesString !== null) {
const cookies = cookiesString.split(',');
......@@ -322,7 +322,7 @@ function requestSignAndFetch(
method,
finalContent,
requestHeaders,
_ => {},
(_) => {},
false
);
}
......@@ -407,7 +407,7 @@ export class CwSimpleHttpClient implements HttpClient {
accept,
this.cookieJar,
this.allowsCrossOrigin
).then(response => {
).then((response) => {
if (
response.content !== null &&
typeof response.content === 'object' &&
......@@ -441,7 +441,7 @@ export class CwSimpleHttpClient implements HttpClient {
null,
'application/x-www-form-urlencoded',
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
).then(_ => {
).then((_) => {
// try to authenticate
return this.request(
'login',
......@@ -449,7 +449,7 @@ export class CwSimpleHttpClient implements HttpClient {
content,
'application/x-www-form-urlencoded',
'application/json'
).then(response => {
).then((response) => {
this.login = login;
return response;
});
......@@ -538,7 +538,7 @@ export class CwSigningHttpClient implements HttpClient {
this.hashMethod,
this.tokenName,
this.tokenValue
).then(response => {
).then((response) => {
if (
response.content !== null &&
typeof response.content === 'object' &&
......@@ -563,7 +563,7 @@ export function interpolateRql(
str: string,
dict: {[key: string]: any}
): string {
return str.replace(/%\(([a-zA-Z0-9]+?)\)s/g, function(base, pattern) {
return str.replace(/%\(([a-zA-Z0-9]+?)\)s/g, function (base, pattern) {
return pattern in dict ? JSON.stringify(dict[pattern]) : base;
});
}
......@@ -650,7 +650,7 @@ export function rowsAsSolutions(
rows: RqlRows,
variables: string[]
): RqlSolutions {
return rows.map(row => rowAsSolution(row, variables));
return rows.map((row) => rowAsSolution(row, variables));
}
/**
......@@ -757,7 +757,7 @@ export class CwRqlClient implements RqlClient {
params?: {[key: string]: any}
): Promise<RqlRows> {
const finalParams = typeof params === 'undefined' ? {} : params;
return this.transactionV1([[query, finalParams]]).then(results => {
return this.transactionV1([[query, finalParams]]).then((results) => {
return results[0];
});
}
......@@ -767,7 +767,7 @@ export class CwRqlClient implements RqlClient {
params?: {[key: string]: any}
): Promise<RqlSolutions> {
const finalParams = typeof params === 'undefined' ? {} : params;
return this.transactionV2([[query, finalParams]]).then(results => {
return this.transactionV2([[query, finalParams]]).then((results) => {
return rqlIoV2asSolutions(results[0]);
});
}
......@@ -778,13 +778,13 @@ export class CwRqlClient implements RqlClient {
params?: {[key: string]: any}
): Promise<RqlSolutions> {
const finalParams = params ?? {};
return this.transactionGetEntities([[query, finalParams]], col)
return this.transactionGetEntities([[query, finalParams]], col);
}
public getSchema(): Promise<Schema> {
return this.httpClient
.request('rqlio/schema/', 'GET', null, null, 'application/json')
.then(response => {
.then((response) => {
return {
metadata: {
timestamp: new Date(),
......@@ -797,7 +797,7 @@ export class CwRqlClient implements RqlClient {
public getSchemaHash(): Promise<string | null> {
return fetch(`${this.httpClient.baseUrl}rqlio/schema/`, {
method: 'HEAD',
}).then(response => {
}).then((response) => {
const hash = response.headers.get('Etag');
return hash ? hash : null;
});
......@@ -816,7 +816,7 @@ export class CwRqlClient implements RqlClient {
'application/json',
'application/json'
)
.then(response => response.content);
.then((response) => response.content);
}
public transactionV1(
......@@ -830,10 +830,10 @@ export class CwRqlClient implements RqlClient {
'application/json',
'application/json'
)
.then(response => {
.then((response) => {
return response.content;
})
.catch(error => {
.catch((error) => {
if (error instanceof Error) {
throw error;
} else {
......@@ -861,7 +861,7 @@ export class CwRqlClient implements RqlClient {
'application/json',
'application/json'
)
.then(response => {
.then((response) => {
return response.content;
});
}
......@@ -878,7 +878,7 @@ export class CwRqlClient implements RqlClient {
'application/json',
'application/json'
)
.then(response => {
.then((response) => {
return response.content;
});
}
......
......@@ -9,11 +9,11 @@ import {waitUntilStarted} from './waitUntilStarted';
const CW_BASE_URL = process.env.CW_BASE_URL ?? 'http://localhost:8080';
beforeAll(async function() {
beforeAll(async function () {
return await waitUntilStarted(CW_BASE_URL);
}, 15 * 1000);
describe('RqlEntitySchemaProvider Tests', function() {
describe('RqlEntitySchemaProvider Tests', function () {
it('should be able to pre-load all schemas', async () => {
const client = new CwRqlClient(new CwSimpleHttpClient(CW_BASE_URL));
const provider = new RqlEntitySchemaProvider(client);
......@@ -25,7 +25,7 @@ describe('RqlEntitySchemaProvider Tests', function() {
}, 15000);
});
describe('RqlEntityProvider Tests', function() {
describe('RqlEntityProvider Tests', function () {
it('should be able get an entity', async () => {
const client = new CwRqlClient(new CwSimpleHttpClient(CW_BASE_URL));
const provider = new RqlEntityProvider(client);
......
......@@ -211,9 +211,7 @@ export interface EntitySchemaProvider {
* Gets all relations (included inherited ones) for an entity type
* @param typeEid The EID of the entity type
*/
getAllRelationsFor(
typeEid: number
): {
getAllRelationsFor(typeEid: number): {
relationsTo: EntityRelationSchema[];
relationsFrom: EntityRelationSchema[];
};
......@@ -294,7 +292,7 @@ export class LocalStorageEntitySchemasLoader implements EntitySchemasLoader {
inner: EntitySchemasLoader,
storageKey: string,
hashStorageKey: string | null = null,
isCacheUsable: (schema: Schema) => Promise<boolean> = _ => {
isCacheUsable: (schema: Schema) => Promise<boolean> = (_) => {
return inner.getSchemaHash().then((hashStr: string) => {
const oldHash = window.localStorage.getItem(
this.hashStorageKey
......@@ -302,7 +300,7 @@ export class LocalStorageEntitySchemasLoader implements EntitySchemasLoader {
return oldHash === hashStr;
});
},
onRetrieved: (schema: Schema) => Promise<Schema> = schema =>
onRetrieved: (schema: Schema) => Promise<Schema> = (schema) =>
new Promise((resolve, _) => resolve(schema))
) {
this.inner = inner;
......@@ -325,7 +323,7 @@ export class LocalStorageEntitySchemasLoader implements EntitySchemasLoader {
return this.loadFromInner();
}
const schema: Schema = JSON.parse(content);
return this.isCacheUsable(schema).then(usable => {
return this.isCacheUsable(schema).then((usable) => {
if (usable) {
return new Promise((resolve, _) => resolve(schema));
} else {
......@@ -425,11 +423,11 @@ export class LoadableEntitySchemaProvider implements EntitySchemaProvider {
);
}
if (this.isLoadingWith !== null) {
let newPromise = this.isLoadingWith.then(data => data);
let newPromise = this.isLoadingWith.then((data) => data);
this.isLoadingWith = newPromise;
return newPromise;
}
this.isLoadingWith = this.loader.load().then(schema => {
this.isLoadingWith = this.loader.load().then((schema) => {
for (const entitySchema of schema.entities) {
this.schemaById[entitySchema.eid] = entitySchema;
this.schemaByName[entitySchema.name] = entitySchema;
......@@ -461,9 +459,7 @@ export class LoadableEntitySchemaProvider implements EntitySchemaProvider {
}
}
public getAllRelationsFor(
typeEid: number
): {
public getAllRelationsFor(typeEid: number): {
relationsTo: EntityRelationSchema[];
relationsFrom: EntityRelationSchema[];
} {
......@@ -479,13 +475,15 @@ export class LoadableEntitySchemaProvider implements EntitySchemaProvider {
public getEntitySchemaByName(
typeName: string
): Promise<EntitySchema | null> {
return this.load().then(_ =>
return this.load().then((_) =>
undefinedToNull(this.schemaByName[typeName])
);
}
public getEntitySchemaById(typeEid: number): Promise<EntitySchema | null> {
return this.load().then(_ => undefinedToNull(this.schemaById[typeEid]));
return this.load().then((_) =>
undefinedToNull(this.schemaById[typeEid])
);
}
public getEntitySchemaFor(eid: number): Promise<EntitySchema | null> {
......@@ -513,9 +511,9 @@ export class RqlEntitySchemaProvider extends LoadableEntitySchemaProvider {
rqlClient: RqlClient,
storageKey?: string,
hashStorageKey: string | null = null,
isCacheUsable: (schema: Schema) => Promise<boolean> = _ =>
isCacheUsable: (schema: Schema) => Promise<boolean> = (_) =>
new Promise((resolve, _) => resolve(true)),
onRetrieved: (schema: Schema) => Promise<Schema> = schema =>
onRetrieved: (schema: Schema) => Promise<Schema> = (schema) =>
new Promise((resolve, _) => resolve(schema))
) {
super(
......@@ -531,12 +529,12 @@ export class RqlEntitySchemaProvider extends LoadableEntitySchemaProvider {
}
public getEntitySchemaFor(eid: number): Promise<EntitySchema | null> {
return this.load().then(_ => {
return this.load().then((_) => {
return this.rqlClient
.queryRows('Any TYPE WHERE X eid %(eid)s, X is TYPE', {
eid: eid,
})
.then(rows => {
.then((rows) => {
if (rows.length === 0) {
return null;
}
......@@ -609,7 +607,7 @@ export class RqlEntityProvider implements EntityProvider {
}
public getEntity(eid: number): Promise<Entity | null> {
return this.schemaProvider.getEntitySchemaFor(eid).then(schema => {
return this.schemaProvider.getEntitySchemaFor(eid).then((schema) => {
if (schema === null) {
return null;
}
......@@ -632,10 +630,8 @@ export class RqlEntityProvider implements EntityProvider {
.join(','),
{eid: eid},
]);
let {
relationsTo,
relationsFrom,
} = this.schemaProvider.getAllRelationsFor(schema.eid);
let {relationsTo, relationsFrom} =
this.schemaProvider.getAllRelationsFor(schema.eid);
// queries for relations (as a subject)
relationsTo.forEach((relation: EntityRelationSchema) => {
const statement = `Any Y WHERE X eid %(eidSubject)s, X ${relation.name} Y, Y is T, T eid %(eidObject)s`;
......@@ -653,7 +649,7 @@ export class RqlEntityProvider implements EntityProvider {
]);
});
// run the queries in a transactionV1
return this.rqlClient.transactionV1(queries).then(results => {
return this.rqlClient.transactionV1(queries).then((results) => {
if (results[0].length === 0) {
// no data for the first query
return null;
......@@ -706,7 +702,7 @@ export class RqlEntityProvider implements EntityProvider {
eid: eid,
}
)
.then(rows => {
.then((rows) => {
if (rows.length === 0) {
return null;
}
......@@ -736,7 +732,7 @@ export class EJsonExportEntityProvider implements EntityProvider {
{eid: eid},
'ejsonexport'
)
.then(entities => {
.then((entities) => {
entities[0]['@type'] = entities[0]['cw_etype'];
entities[0]['@eid'] = eid;
return entities[0];
......@@ -754,7 +750,7 @@ export class EJsonExportEntityProvider implements EntityProvider {
eid: number,
schema: EntitySchema
): Promise<string | null> {
return this.getEntity(eid).then(entity => {
return this.getEntity(eid).then((entity) => {
if (entity === null) {
return null;
}
......@@ -801,7 +797,7 @@ export class CachedEntityProvider implements EntityProvider {
if (entity !== undefined) {
return new Promise((resolve, _) => resolve(entity));
}
return this.inner.getEntity(eid).then(entity => {
return this.inner.getEntity(eid).then((entity) => {
if (entity === null) {
return null;
}
......@@ -818,7 +814,7 @@ export class CachedEntityProvider implements EntityProvider {
if (entity !== undefined) {
return new Promise((resolve, _) => resolve(entity));
}
return this.inner.getEntityGivenSchema(eid, schema).then(entity => {
return this.inner.getEntityGivenSchema(eid, schema).then((entity) => {
if (entity === null) {
return null;
}
......
const PAUSE_BETWEEN_REQUESTS_MILLIS = 500;
function sleep(timeMilliseconds: number) {
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(() => resolve(), timeMilliseconds);
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment