Skip to content

Commit

Permalink
Change references to exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Feng committed Jun 7, 2017
1 parent 0185602 commit d67de2b
Show file tree
Hide file tree
Showing 27 changed files with 138 additions and 135 deletions.
10 changes: 5 additions & 5 deletions packages/repository/src/common-types.ts
Expand Up @@ -7,16 +7,16 @@
* Common types/interfaces such as Class/Constructor/Options/Callback
*/
// tslint:disable-next-line:no-any
export type AnyType = any;
export type Any = any;

/**
* Interface for classes with `new` operator and static properties/methods
*/
export interface Class<T> {
// new MyClass(...args) ==> T
new (...args: AnyType[]): T;
new (...args: Any[]): T;
// Other static properties/operations
[property: string]: AnyType;
[property: string]: Any;
}

/**
Expand All @@ -29,7 +29,7 @@ export interface Class<T> {
* ```
*/
export interface ConstructorFunction<T> {
(...args: AnyType[]): T;
(...args: Any[]): T;
}

/**
Expand All @@ -41,7 +41,7 @@ export type Constructor<T> = Class<T> | ConstructorFunction<T>;
* Objects with open properties
*/
export interface AnyObject {
[property: string]: AnyType;
[property: string]: Any;
}

export type ObjectType<T> = T | AnyObject;
Expand Down
12 changes: 6 additions & 6 deletions packages/repository/src/crud-connector.ts
Expand Up @@ -6,7 +6,7 @@
import { Connector } from './connector';
import { Entity } from './model';
import { Filter, Where } from './query';
import { Class, ObjectType, Options, AnyType } from './common-types';
import { Class, ObjectType, Options, Any } from './common-types';

export type EntityData = ObjectType<Entity>;

Expand All @@ -32,7 +32,7 @@ export interface CrudConnector extends Connector {
find(modelClass: Class<Entity>, filter?: Filter, options?: Options):
Promise<EntityData[]>;

findById?(modelClass: Class<Entity>, id: AnyType, options?: Options):
findById?(modelClass: Class<Entity>, id: Any, options?: Options):
Promise<EntityData>;

update?(modelClass: Class<Entity>, entity: EntityData, options?: Options):
Expand All @@ -48,10 +48,10 @@ export interface CrudConnector extends Connector {
where?: Where, options?: Options):
Promise<number>;

updateById?(modelClass: Class<Entity>, id: AnyType, data: EntityData,
updateById?(modelClass: Class<Entity>, id: Any, data: EntityData,
options?: Options): Promise<boolean>;

replaceById?(modelClass: Class<Entity>, id: AnyType, data: EntityData,
replaceById?(modelClass: Class<Entity>, id: Any, data: EntityData,
options?: Options): Promise<boolean>;

/**
Expand All @@ -60,7 +60,7 @@ export interface CrudConnector extends Connector {
deleteAll(modelClass: Class<Entity>, where?: Where, options?: Options):
Promise<number>;

deleteById?(modelClass: Class<Entity>, id: AnyType, options?: Options):
deleteById?(modelClass: Class<Entity>, id: Any, options?: Options):
Promise<boolean>;

/**
Expand All @@ -69,6 +69,6 @@ export interface CrudConnector extends Connector {
count(modelClass: Class<Entity>, where?: Where, options?: Options):
Promise<number>;

exists?(modelClass: Class<Entity>, id: AnyType, options?: Options):
exists?(modelClass: Class<Entity>, id: Any, options?: Options):
Promise<boolean>;
}
4 changes: 2 additions & 2 deletions packages/repository/src/datasource.ts
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {AnyType} from './common-types';
import {Any} from './common-types';
import {Connector} from './connector';

/**
Expand All @@ -12,5 +12,5 @@ import {Connector} from './connector';
export interface DataSource {
name: string; // Name of the data source
connector: Connector; // The underlying connector
[property: string]: AnyType; // Other properties that vary by connectors
[property: string]: Any; // Other properties that vary by connectors
}
6 changes: 3 additions & 3 deletions packages/repository/src/decorators/model.ts
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Class, AnyType } from '../common-types';
import { Class, Any } from '../common-types';
import { Reflector } from '@loopback/context';

export const MODEL_KEY = 'loopback:model';
Expand All @@ -15,7 +15,7 @@ export const PROPERTY_KEY = 'loopback:property';
* @returns {(target:AnyType)}
*/
export function model(definition?: Object) {
return function(target: AnyType) {
return function(target: Any) {
// Apply model definition to the model class
Reflector.defineMetadata(MODEL_KEY, definition, target);
};
Expand All @@ -27,7 +27,7 @@ export function model(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function property(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
Reflector.defineMetadata(PROPERTY_KEY, definition, target, key);
};
Expand Down
18 changes: 9 additions & 9 deletions packages/repository/src/decorators/relation.ts
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Class, AnyType } from '../common-types';
import { Class, Any } from '../common-types';
import { Entity } from '../model';

import { Reflector } from '@loopback/context';
Expand Down Expand Up @@ -32,7 +32,7 @@ export class RelationMetadata {
* @returns {(target:AnyType, key:string)}
*/
export function relation(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
Reflector.defineMetadata(RELATION_KEY, definition, target, key);
};
Expand All @@ -44,7 +44,7 @@ export function relation(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function belongsTo(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.belongsTo}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -57,7 +57,7 @@ export function belongsTo(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function hasOne(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.hasOne}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -70,7 +70,7 @@ export function hasOne(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function hasMany(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.hasMany}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -83,7 +83,7 @@ export function hasMany(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function embedsOne(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.embedsOne}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -97,7 +97,7 @@ export function embedsOne(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function embedsMany(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.embedsMany}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -110,7 +110,7 @@ export function embedsMany(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function referencesOne(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.referencesOne}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand All @@ -123,7 +123,7 @@ export function referencesOne(definition?: Object) {
* @returns {(target:AnyType, key:string)}
*/
export function referencesMany(definition?: Object) {
return function(target: AnyType, key: string) {
return function(target: Any, key: string) {
// Apply model definition to the model class
const rel = Object.assign({type: RelationType.referencesMany}, definition);
Reflector.defineMetadata(RELATION_KEY, rel, target, key);
Expand Down
4 changes: 2 additions & 2 deletions packages/repository/src/decorators/repository.ts
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Class, AnyType } from '../common-types';
import { Class, Any } from '../common-types';
import { Model } from '../model';
import { Repository } from '../repository';
import { DataSource } from '../datasource';
Expand Down Expand Up @@ -81,7 +81,7 @@ export function repository(model: string | Class<Model>,
dataSource?: string | DataSource) {
const meta = new RepositoryMetadata(model, dataSource);
return function(target: Object, key?: symbol | string,
descriptor?: TypedPropertyDescriptor<Repository<AnyType>> | number) {
descriptor?: TypedPropertyDescriptor<Repository<Any>> | number) {
if ((typeof descriptor === 'number') && meta.name) {
// Make it shortcut to `@inject('repositories:MyRepo')`
// Please note key is undefined for constructor. If strictNullChecks
Expand Down
3 changes: 3 additions & 0 deletions packages/repository/src/index.ts
Expand Up @@ -6,9 +6,12 @@
export * from './common-types';
export * from './decorators/model';
export * from './decorators/repository';
export * from './decorators/relation';
export * from './types';
export * from './model';
export * from './query';
export * from './connector';
export * from './datasource';
export * from './mixin';
export * from './repository';
export * from './legacy-juggler-bridge';
4 changes: 2 additions & 2 deletions packages/repository/src/legacy-juggler-bridge.ts
Expand Up @@ -6,7 +6,7 @@
export const jugglerModule = require('loopback-datasource-juggler');

import {MixinBuilder} from './mixin';
import {Class, ObjectType, Options, AnyType} from './common-types';
import {Class, ObjectType, Options, Any} from './common-types';

import {juggler} from './loopback-datasource-juggler';

Expand Down Expand Up @@ -35,7 +35,7 @@ import {Entity} from './model';
import {Filter, Where} from './query';
import {EntityCrudRepository} from './repository';

function isPromise<T>(p: AnyType): p is Promise<T> {
function isPromise<T>(p: Any): p is Promise<T> {
return p !== null && typeof p === 'object' && typeof p.then === 'function';
}

Expand Down
42 changes: 21 additions & 21 deletions packages/repository/src/loopback-datasource-juggler.ts
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Class, Options, Callback, AnyObject, AnyType } from './common-types';
import { Class, Options, Callback, AnyObject, Any } from './common-types';

export declare namespace juggler {
/**
Expand All @@ -18,8 +18,8 @@ export declare namespace juggler {
static modelName: string;
static definition: ModelDefinition;
static attachTo(ds: DataSource): void;
constructor(...args: AnyType[]);
[property: string]: AnyType;
constructor(...args: Any[]);
[property: string]: Any;
}

/**
Expand Down Expand Up @@ -69,14 +69,14 @@ export declare namespace juggler {
}

export interface Condition {
eq?: AnyType;
neq?: AnyType;
gt?: AnyType;
get?: AnyType;
lt?: AnyType;
lte?: AnyType;
inq?: AnyType[];
between?: AnyType[];
eq?: Any;
neq?: Any;
gt?: Any;
get?: Any;
lt?: Any;
lte?: Any;
inq?: Any[];
between?: Any[];
exists?: boolean;
and?: Where[];
or?: Where[];
Expand All @@ -88,7 +88,7 @@ export declare namespace juggler {
export interface Where {
and?: Where[]; // AND
or?: Where[]; // OR
[property: string]: Condition | AnyType; // Other criteria
[property: string]: Condition | Any; // Other criteria
}

/**
Expand Down Expand Up @@ -247,7 +247,7 @@ export declare namespace juggler {
* @param {Error} err Error object; see [Error object](http://loopback.io/doc/en/lb2/Error-object.html).
* @param {Boolean} exists True if the instance with the specified ID exists; false otherwise.
*/
static exists(id: AnyType, options?: Options,
static exists(id: Any, options?: Options,
callback?: Callback<boolean>): PromiseOrVoid<boolean>;

/**
Expand All @@ -263,7 +263,7 @@ export declare namespace juggler {
* @param {Error} err Error object; see [Error object](http://loopback.io/doc/en/lb2/Error-object.html).
* @param {Object} instance Model instance matching the specified ID or null if no instance matches.
*/
static findById(id: AnyType, filter?: Filter, options?: Options,
static findById(id: Any, filter?: Filter, options?: Options,
callback?: Callback<boolean>): PromiseOrVoid<PersistedData>;

/**
Expand Down Expand Up @@ -385,13 +385,13 @@ export declare namespace juggler {
* @callback {Function} callback Callback function called with `(err)` arguments. Required.
* @param {Error} err Error object; see [Error object](http://loopback.io/doc/en/lb2/Error-object.html).
*/
static destroyById(id: AnyType, options?: Options,
static destroyById(id: Any, options?: Options,
callback?: Callback<Count>): PromiseOrVoid<Count>;

static removeById(id: AnyType, options?: Options,
static removeById(id: Any, options?: Options,
callback?: Callback<Count>): PromiseOrVoid<Count>;

static deleteById(id: AnyType, options?: Options,
static deleteById(id: Any, options?: Options,
callback?: Callback<Count>): PromiseOrVoid<Count>;

/**
Expand All @@ -407,7 +407,7 @@ export declare namespace juggler {
* @param {Error} err Error object; see [Error object](http://loopback.io/doc/en/lb2/Error-object.html).
* @param {Object} instance Replaced instance.
*/
static replaceById(id: AnyType, data: PersistedData, options?: Options,
static replaceById(id: Any, data: PersistedData, options?: Options,
callback?: Callback<PersistedData>): PromiseOrVoid<PersistedData>;

/**
Expand Down Expand Up @@ -465,7 +465,7 @@ export declare namespace juggler {
* @param {Error} err Error object; see [Error object](http://loopback.io/doc/en/lb2/Error-object.html).
* @param {Object} instance Updated instance.
*/
updateAttribute(name: string, value: AnyType, options?: Options,
updateAttribute(name: string, value: Any, options?: Options,
callback?: Callback<boolean>): PromiseOrVoid<boolean>;

/**
Expand Down Expand Up @@ -509,15 +509,15 @@ export declare namespace juggler {
*
* @param {*} val The `id` value. Will be converted to the type that the `id` property specifies.
*/
setId(val: AnyType): void;
setId(val: Any): void;

/**
* Get the `id` value for the `PersistedModel`.
*
* @returns {*} The `id` value
*/

getId(): AnyType;
getId(): Any;

/**
* Get the `id` property name of the constructor.
Expand Down

0 comments on commit d67de2b

Please sign in to comment.