Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/repository/src/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ export type Callback<T> = (
err: Error | string | null | undefined,
result?: T,
) => void;

/**
* Type for a command
*/
export type Command = string | AnyObject;

/**
* Named parameters, such as `{x: 1, y: 'a'}`
*/
export type NamedParameters = AnyObject;

/**
* Positional parameters, such as [1, 'a']
*/
// tslint:disable-next-line:no-any
export type PositionalParameters = any[];
13 changes: 13 additions & 0 deletions packages/repository/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// License text available at https://opensource.org/licenses/MIT

import {Model} from './model';
import {
AnyObject,
Options,
Command,
NamedParameters,
PositionalParameters,
} from '..';

/**
* Common properties/operations for connectors
Expand All @@ -15,4 +22,10 @@ export interface Connector {
connect(): Promise<void>; // Connect to the underlying system
disconnect(): Promise<void>; // Disconnect from the underlying system
ping(): Promise<void>; // Ping the underlying system
execute?(
command: Command,
// tslint:disable:no-any
parameters: NamedParameters | PositionalParameters,
options?: Options,
): Promise<AnyObject>;
}
16 changes: 16 additions & 0 deletions packages/repository/src/legacy-juggler-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {EntityCrudRepository} from './repository';

export * from './loopback-datasource-juggler';
import {juggler} from './loopback-datasource-juggler';
import {
AnyObject,
Command,
NamedParameters,
PositionalParameters,
} from '../index';

type DataSourceType = juggler.DataSource;
export {DataSourceType};
Expand Down Expand Up @@ -195,6 +201,16 @@ export class DefaultCrudRepository<T extends Entity, ID>
return ensurePromise(this.modelClass.exists(id, options));
}

async execute(
command: Command,
// tslint:disable:no-any
parameters: NamedParameters | PositionalParameters,
options?: Options,
): Promise<AnyObject> {
/* istanbul ignore next */
throw new Error('Not implemented');
}

protected toEntity(model: DataObject<T>): T {
return new this.entityClass(model.toObject()) as T;
}
Expand Down
19 changes: 4 additions & 15 deletions packages/repository/src/loopback-datasource-juggler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export declare namespace juggler {
* Base model class
*/
export class ModelBase {
static dataSource?: DataSource;
static modelName: string;
static definition: ModelDefinition;
static attachTo(ds: DataSource): void;
Expand Down Expand Up @@ -202,7 +203,7 @@ export declare namespace juggler {
eq?: any;
neq?: any;
gt?: any;
get?: any;
gte?: any;
lt?: any;
lte?: any;
inq?: any[];
Expand All @@ -221,18 +222,6 @@ export declare namespace juggler {
[property: string]: Condition | any; // Other criteria
}

/**
* Order by direction
*/
export type Direction = 'ASC' | 'DESC';

/**
* Order by
*/
export interface Order {
[property: string]: Direction;
}

/**
* Selection of fields
*/
Expand All @@ -245,7 +234,7 @@ export declare namespace juggler {
*/
export interface Inclusion {
relation: string;
scope: Filter;
scope?: Filter;
}

/**
Expand All @@ -254,7 +243,7 @@ export declare namespace juggler {
export interface Filter {
where?: Where;
fields?: Fields;
order?: Order[];
order?: string[];
limit?: number;
skip?: number;
offset?: number;
Expand Down
Loading