Skip to content

Commit

Permalink
chore: reformat code using [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Apr 6, 2020
1 parent 2b99e63 commit f195865
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ describe('TodoController', () => {

aTodo = givenTodo();
aTodoWithId = givenTodo({id: 1});
aListOfTodos =
[
aTodoWithId,
givenTodo({
id: 2,
title: 'do another thing',
}),
] as Todo[];
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'do another thing',
}),
] as Todo[];
aTodoToPatchTo = givenTodo({
title: 'revised thing to do',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ describe('TodoController', () => {
aTodoListWithId = givenTodoList({
id: 1,
});
aListOfTodoLists =
[
aTodoListWithId,
givenTodoList({
id: 2,
title: 'a lot of todos',
}),
] as TodoList[];
aListOfTodoLists = [
aTodoListWithId,
givenTodoList({
id: 2,
title: 'a lot of todos',
}),
] as TodoList[];
aTodoListToPatchTo = givenTodoList({
title: 'changed list of todos',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ describe('TodoController', () => {
aTodoWithId = givenTodo({
id: 1,
});
aListOfTodos =
[
aTodoWithId,
givenTodo({
id: 2,
title: 'so many things to do',
}),
] as Todo[];
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'so many things to do',
}),
] as Todo[];
aChangedTodo = givenTodo({
id: aTodoWithId.id,
title: 'Do some important things',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,13 @@ describe('TodoController', () => {
aTodoWithId = givenTodo({
id: 1,
});
aListOfTodos =
[
aTodoWithId,
givenTodo({
id: 2,
title: 'so many things to do',
}),
] as Todo[];
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'so many things to do',
}),
] as Todo[];
aChangedTodo = givenTodo({
id: aTodoWithId.id,
title: 'Do some important things',
Expand Down
6 changes: 3 additions & 3 deletions packages/context/src/__tests__/unit/resolver.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ describe('constructor injection', () => {

const theNonInjectedArg = 'BAZ';

const test =
instantiateClass(TestClass, ctx, undefined, [theNonInjectedArg]) as
TestClass;
const test = instantiateClass(TestClass, ctx, undefined, [
theNonInjectedArg,
]) as TestClass;
expect(test.foo).to.eql('FOO');
expect(test.nonInjectedArg).to.eql('BAZ');
});
Expand Down
16 changes: 6 additions & 10 deletions packages/context/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,11 @@ function createInterceptionProxyFromInstance<T>(
) {
return transformValueOrPromise(instOrPromise, inst => {
if (typeof inst !== 'object') return inst;
return (
(createProxyWithInterceptors(
// Cast inst from `T` to `object`
(inst as unknown) as object,
context,
session,
) as
unknown) as
T
);
return (createProxyWithInterceptors(
// Cast inst from `T` to `object`
(inst as unknown) as object,
context,
session,
) as unknown) as T;
});
}
6 changes: 3 additions & 3 deletions packages/context/src/context-tag-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export class ContextTagIndexer {
const bindingsByTag = this.bindingsIndexedByTag.get(t);
if (bindingsByTag == null) break; // One of the tags is not found
filter = filter ?? filterByTag(tag);
const matched =
new Set(Array.from(bindingsByTag).filter(filter)) as
Set<Readonly<Binding<ValueType>>>;
const matched = new Set(Array.from(bindingsByTag).filter(filter)) as Set<
Readonly<Binding<ValueType>>
>;
if (!union && matched.size === 0) break; // One of the tag name/value is not found
if (bindings == null) {
// First set of bindings matching the tag
Expand Down
10 changes: 4 additions & 6 deletions packages/context/src/interception-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ export function createProxyWithInterceptors<T extends object>(
context?: Context,
session?: ResolutionSession,
): AsyncProxy<T> {
return (
new Proxy(
target,
new InterceptionHandler(context, ResolutionSession.fork(session)),
) as AsyncProxy<T>
);
return new Proxy(
target,
new InterceptionHandler(context, ResolutionSession.fork(session)),
) as AsyncProxy<T>;
}
7 changes: 3 additions & 4 deletions packages/context/src/interceptor-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,9 @@ export class GenericInterceptorChain<C extends Context = Context> {
private loadInterceptor(interceptor: GenericInterceptorOrKey<C>) {
if (typeof interceptor === 'function') return interceptor;
debug('Resolving interceptor binding %s', interceptor);
return (
this.context.getValueOrPromise(interceptor) as
ValueOrPromise<GenericInterceptor<C>>
);
return this.context.getValueOrPromise(interceptor) as ValueOrPromise<
GenericInterceptor<C>
>;
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/__tests__/unit/lifecycle-registry.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ describe('LifeCycleRegistry', () => {
.bind(CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY)
.toClass(TestObserverRegistry)
.inScope(BindingScope.SINGLETON);
registry =
(await context.get(CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY)) as
TestObserverRegistry;
registry = (await context.get(
CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY,
)) as TestObserverRegistry;
}

function givenObserver(name: string, group = '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,11 @@ describe('HttpCachingProxy', () => {
(err as any).status = res.status;
throw err;
}
const patchedRes =
Object.create(res) as
AxiosResponse & {
statusCode: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: any;
};
const patchedRes = Object.create(res) as AxiosResponse & {
statusCode: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body: any;
};
patchedRes.statusCode = res.status;
patchedRes.body = res.data;
return patchedRes;
Expand Down
5 changes: 3 additions & 2 deletions packages/openapi-v3/src/decorators/response.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ function buildDecoratorReducer(
Object.keys(m.content ?? {}).forEach(ct => {
r.push({
responseCode,
responseModelOrSpec:
m.content[ct].schema as SchemaObject | ReferenceObject,
responseModelOrSpec: m.content[ct].schema as
| SchemaObject
| ReferenceObject,
contentType: ct,
description: m.description ?? description,
});
Expand Down
13 changes: 6 additions & 7 deletions packages/repository-tests/src/crud/replace-by-id.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ export function createSuiteForReplaceById(
// the database is converted to JSON and client sends plain data object
// encoded as JSON.
it('replaces all model properties (using plain data object)', async () => {
const created =
toJSON(
await repo.create({
name: 'Pencil',
description: 'some description',
}),
) as AnyObject;
const created = toJSON(
await repo.create({
name: 'Pencil',
description: 'some description',
}),
) as AnyObject;
expect(created.id).to.be.ok();

created.name = 'new name';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ describe('Repository', () => {
});

it('returns cached metadata instead of recreating it', () => {
const classMeta =
MetadataInspector.getClassMetadata(MODEL_KEY, Phlange) as
ModelDefinition;
const classMeta = MetadataInspector.getClassMetadata(
MODEL_KEY,
Phlange,
) as ModelDefinition;
classMeta.properties = {
foo: {
type: String,
Expand All @@ -103,8 +104,9 @@ describe('Repository', () => {
Phlange,
);

const meta =
ModelMetadataHelper.getModelMetadata(Phlange) as ModelDefinition;
const meta = ModelMetadataHelper.getModelMetadata(
Phlange,
) as ModelDefinition;
expect(meta.properties).to.eql(classMeta.properties);
});
});
Expand Down
6 changes: 4 additions & 2 deletions packages/repository/src/define-model-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ export function defineModelClass<
base.name,
`return class ${modelName} extends ${base.name} {}`,
);
const modelClass =
defineNamedModelClass(base) as DynamicModelCtor<BaseCtor, Props>;
const modelClass = defineNamedModelClass(base) as DynamicModelCtor<
BaseCtor,
Props
>;
assert.equal(modelClass.name, modelName);
modelClass.definition = definition;
return modelClass;
Expand Down
6 changes: 3 additions & 3 deletions packages/repository/src/repositories/kv.repository.bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export class DefaultKeyValueRepository<T extends Model>
}

async get(key: string, options?: Options): Promise<T> {
const val =
this.kvModelClass.get(key, options) as
legacy.PromiseOrVoid<legacy.ModelData>;
const val = this.kvModelClass.get(key, options) as legacy.PromiseOrVoid<
legacy.ModelData
>;
const result = await ensurePromise(val);
return this.toEntity(result);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/rest-crud/src/crud-rest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ function getIdSchema<T extends Entity>(
modelCtor: typeof Entity & {prototype: T},
): SchemaObject {
const idProp = modelCtor.getIdProperties()[0];
const modelSchema =
jsonToSchemaObject(getJsonSchema(modelCtor)) as SchemaObject;
const modelSchema = jsonToSchemaObject(
getJsonSchema(modelCtor),
) as SchemaObject;
return (modelSchema.properties ?? {})[idProp] as SchemaObject;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/rest/src/validation/request-body.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ const DEFAULT_COMPILED_SCHEMA_CACHE: SchemaValidatorCache = new WeakMap();
function getKeyForOptions(options: RequestBodyValidationOptions) {
const ajvOptions: Record<string, unknown> = {};
// Sort keys for options
const keys =
Object.keys(options).sort() as (keyof RequestBodyValidationOptions)[];
const keys = Object.keys(
options,
).sort() as (keyof RequestBodyValidationOptions)[];
for (const k of keys) {
if (k === 'compiledSchemaCache') continue;
ajvOptions[k] = options[k];
Expand Down

0 comments on commit f195865

Please sign in to comment.