-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
3,321 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.tgz | ||
lib*/ | ||
package |
18 changes: 18 additions & 0 deletions
18
packages/juggler/examples/controllers/CustomerController1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {EntityCrudRepository} from '../../src/repository'; | ||
import {repository} from '../../src/decorator'; | ||
import {Customer} from '../models/customer'; | ||
|
||
/** | ||
* Controller for Customer | ||
*/ | ||
// @controller | ||
export class CustomerController1 { | ||
// Use property dependency injection | ||
@repository(Customer, 'mongodbDataSource') | ||
private repository: EntityCrudRepository<Customer, string>; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/juggler/examples/controllers/CustomerController2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {EntityCrudRepository} from '../../src/repository'; | ||
import {Customer} from '../models/customer'; | ||
import {repository} from '../../src/decorator'; | ||
/** | ||
* Controller for Customer | ||
*/ | ||
// @controller | ||
export class CustomerController2 { | ||
constructor( | ||
// Use constructor dependency injection | ||
@repository(Customer, 'mongodbDataSource') | ||
private repository: EntityCrudRepository<Customer, string>) { | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/juggler/examples/controllers/CustomerController3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {EntityCrudRepository} from '../../src/repository'; | ||
import {Customer} from '../models/customer'; | ||
import {repository} from '../../src/decorator'; | ||
|
||
/** | ||
* Controller for Customer | ||
*/ | ||
// @controller | ||
|
||
// Use class level @repository decorator to mixin repository methods into the | ||
// controller class | ||
|
||
// Style 1 | ||
// Create a repository that binds Customer to mongodbDataSource | ||
@repository(Customer, 'mongodbDataSource') | ||
// Style 2 | ||
// Reference a pre-configured repository by name. This is close to LoopBack | ||
// 3.x model-config.json | ||
// @repository('myCustomerRepository') | ||
export class CustomerController3 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {ValueObject} from '../../src/model'; | ||
|
||
export class Address extends ValueObject { | ||
street: string; | ||
city: string; | ||
zipCode: string; | ||
state: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
var Address = require('./address').Address; | ||
|
||
module.exports = { | ||
name: 'Customer', | ||
properties: { | ||
id: { | ||
type: 'string', | ||
id: true | ||
}, | ||
name: { | ||
type: string | ||
}, | ||
email: { | ||
type: string, | ||
regexp: '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$', | ||
required: true | ||
}, | ||
address: { | ||
type: Address | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {model} from '../../src/decorator'; | ||
import {Entity, ModelProperty} from '../../src/model'; | ||
|
||
@model(require('./customer.definition')) | ||
export class Customer extends Entity { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Entity} from '../../src/model'; | ||
import {property, model, belongsTo} from '../../src/decorator'; | ||
import {Customer} from './customer'; | ||
|
||
@model() | ||
class Order extends Entity { | ||
@property({name: 'qty', mysql: { | ||
column: 'QTY', | ||
}}) | ||
quantity: number; | ||
|
||
@property({name: 'id', id: true, generated: true}) | ||
id: string; | ||
customerId: string; | ||
|
||
@belongsTo() | ||
customer: Customer; | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/juggler/examples/repositories/CustomerRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Options} from '../../src/common'; | ||
import {Where} from '../../src/query'; | ||
import {DataSource} from '../../src/datasource'; | ||
|
||
import {EntityCrudRepository, CrudRepositoryImpl} from '../../src/repository'; | ||
import {Customer} from '../models/customer'; | ||
|
||
/** | ||
* A custom repository implementation | ||
*/ | ||
export class CustomerRepository extends CrudRepositoryImpl<Customer, string> { | ||
constructor(dataSource: DataSource, model: Customer) { | ||
super(dataSource, Customer); | ||
} | ||
|
||
/** | ||
* Override deleteAll to disable the operation | ||
*/ | ||
deleteAll(where?: Where, options?: Options) { | ||
return Promise.reject(new Error('deleteAll is disabled')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
const nodeMajorVersion = +process.versions.node.split('.')[0]; | ||
module.exports = nodeMajorVersion >= 7 ? | ||
require('./lib') : | ||
require('./lib6'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright IBM Corp. 2013,2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
// NOTE(bajtos) This file is used by VSCode/TypeScriptServer at dev time only | ||
export * from './src'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@loopback/juggler", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Juggler for LoopBack.next", | ||
"main": "index", | ||
"scripts": { | ||
"acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", | ||
"build": "npm run build:lib && npm run build:lib6", | ||
"build:lib": "node ../../bin/compile-package es2017", | ||
"build:lib6": "node ../../bin/compile-package es2015", | ||
"clean": "rm -rf loopback-context*.tgz lib* package", | ||
"prepublish": "npm run build", | ||
"pretest": "npm run build", | ||
"test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/acceptance/**/*.ts'", | ||
"unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'", | ||
"verify": "npm pack && tar xf loopback-juggler*.tgz && tree package && npm run clean" | ||
}, | ||
"author": "IBM", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@loopback/testlab": "^4.0.0-alpha.2", | ||
"mocha": "^3.2.0" | ||
}, | ||
"dependencies": { | ||
"@loopback/context": "^4.0.0-alpha.6", | ||
"loopback-datasource-juggler": "^3.9.0" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"index.js", | ||
"index.d.ts", | ||
"lib", | ||
"lib6" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/strongloop/loopback-next.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
/** | ||
* Common types/interfaces such as Class/Constructor/Options/Callback | ||
*/ | ||
// tslint:disable-next-line:no-any | ||
export type AnyType = any; | ||
|
||
/** | ||
* Interface for classes with `new` operator and static properties/methods | ||
*/ | ||
export interface Class<T> { | ||
// new MyClass(...args) ==> T | ||
new (...args: AnyType[]): T; | ||
// Other static properties/operations | ||
[property: string]: AnyType; | ||
} | ||
|
||
/** | ||
* Interface for constructor functions without `new` operator, for example, | ||
* ``` | ||
* function Foo(x) { | ||
* if (!(this instanceof Foo)) { return new Foo(x); } | ||
* this.x = x; | ||
* } | ||
* ``` | ||
*/ | ||
export interface ConstructorFunction<T> { | ||
(...args: AnyType[]): T; | ||
} | ||
|
||
/** | ||
* Constructor type - class or function | ||
*/ | ||
export type Constructor<T> = Class<T> | ConstructorFunction<T>; | ||
|
||
/** | ||
* Objects with open properties | ||
*/ | ||
export interface AnyObject { | ||
[property: string]: AnyType; | ||
} | ||
|
||
export type ObjectType<T> = T | AnyObject; | ||
|
||
/** | ||
* Type alias for Node.js options object | ||
*/ | ||
export type Options = AnyObject | null | undefined; | ||
|
||
/** | ||
* Type alias for Node.js callback functions | ||
*/ | ||
export type Callback<T> = | ||
(err: Error | string | null | undefined, result?: T) => void; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright IBM Corp. 2017. All Rights Reserved. | ||
// Node module: @loopback/juggler | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {AnyType} from './common'; | ||
import {Model} from './model'; | ||
|
||
/** | ||
* Common properties/operations for connectors | ||
*/ | ||
export interface Connector { | ||
name: string; // Name/type of the connector | ||
configModel?: Model; // The configuration model | ||
interfaces?: string[]; // A list of interfaces implemented by the connector | ||
connect(): Promise<AnyType>; // Connect to the underlying system | ||
disconnect(): Promise<AnyType>; // Disconnect from the underlying system | ||
ping(): Promise<AnyType>; // Ping the underlying system | ||
} |
Oops, something went wrong.