Skip to content

Commit da1d8cf

Browse files
committed
feat(loopback4-dynamic-datasource): initial implementation
0 parents  commit da1d8cf

27 files changed

+5997
-0
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
.eslintrc.js

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: '@loopback/eslint-config',
3+
};

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# Transpiled JavaScript files from Typescript
61+
/dist
62+
63+
# Cache used by TypeScript's incremental build
64+
*.tsbuildinfo
65+
66+
# Webstorm files
67+
.idea/
68+
69+
# Mac file issue
70+
.DS_Store
71+

.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"exit": true,
3+
"recursive": true,
4+
"require": "source-map-support/register"
5+
}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
*.json

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"bracketSpacing": false,
3+
"singleQuote": true,
4+
"printWidth": 80,
5+
"trailingComma": "all",
6+
"arrowParens": "avoid"
7+
}

.vscode/launch.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "node",
5+
"request": "launch",
6+
"name": "Launch Program",
7+
"skipFiles": [
8+
"<node_internals>/**"
9+
],
10+
"program": "${workspaceFolder}/dist/index.js",
11+
},
12+
{
13+
"type": "node",
14+
"request": "launch",
15+
"name": "Run Mocha tests",
16+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
17+
"runtimeArgs": [
18+
"-r",
19+
"${workspaceRoot}/node_modules/source-map-support/register"
20+
],
21+
"cwd": "${workspaceRoot}",
22+
"autoAttachChildProcesses": true,
23+
"args": [
24+
"--config",
25+
"${workspaceRoot}/.mocharc.json",
26+
"${workspaceRoot}/dist/__tests__/**/*.js",
27+
"-t",
28+
"0"
29+
]
30+
},
31+
{
32+
"type": "node",
33+
"request": "attach",
34+
"name": "Attach to Process",
35+
"port": 5858
36+
}
37+
]
38+
}

.vscode/settings.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"editor.rulers": [80],
3+
"editor.tabCompletion": "on",
4+
"editor.tabSize": 2,
5+
"editor.trimAutoWhitespace": true,
6+
"editor.formatOnSave": true,
7+
"editor.codeActionsOnSave": {
8+
"source.organizeImports": true,
9+
"source.fixAll.eslint": true
10+
},
11+
12+
"files.exclude": {
13+
"**/.DS_Store": true,
14+
"**/.git": true,
15+
"**/.hg": true,
16+
"**/.svn": true,
17+
"**/CVS": true,
18+
"dist": true,
19+
},
20+
"files.insertFinalNewline": true,
21+
"files.trimTrailingWhitespace": true,
22+
23+
"typescript.tsdk": "./node_modules/typescript/lib",
24+
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
25+
"typescript.preferences.quoteStyle": "single",
26+
"eslint.run": "onSave",
27+
"eslint.nodePath": "./node_modules",
28+
"eslint.validate": [
29+
"javascript",
30+
"typescript"
31+
]
32+
}

.vscode/tasks.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Watch and Compile Project",
8+
"type": "shell",
9+
"command": "npm",
10+
"args": ["--silent", "run", "build:watch"],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
},
15+
"problemMatcher": "$tsc-watch"
16+
},
17+
{
18+
"label": "Build, Test and Lint",
19+
"type": "shell",
20+
"command": "npm",
21+
"args": ["--silent", "run", "test:dev"],
22+
"group": {
23+
"kind": "test",
24+
"isDefault": true
25+
},
26+
"problemMatcher": ["$tsc", "$eslint-compact", "$eslint-stylish"]
27+
}
28+
]
29+
}

.yo-rc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@loopback/cli": {
3+
"packageManager": "npm",
4+
"version": "2.21.0"
5+
}
6+
}

DEVELOPING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Developer's Guide
2+
3+
We use Visual Studio Code for developing LoopBack and recommend the same to our
4+
users.
5+
6+
## VSCode setup
7+
8+
Install the following extensions:
9+
10+
- [eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
11+
- [prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
12+
13+
## Development workflow
14+
15+
### Visual Studio Code
16+
17+
1. Start the build task (Cmd+Shift+B) to run TypeScript compiler in the
18+
background, watching and recompiling files as you change them. Compilation
19+
errors will be shown in the VSCode's "PROBLEMS" window.
20+
21+
2. Execute "Run Rest Task" from the Command Palette (Cmd+Shift+P) to re-run the
22+
test suite and lint the code for both programming and style errors. Linting
23+
errors will be shown in VSCode's "PROBLEMS" window. Failed tests are printed
24+
to terminal output only.
25+
26+
### Other editors/IDEs
27+
28+
1. Open a new terminal window/tab and start the continuous build process via
29+
`npm run build:watch`. It will run TypeScript compiler in watch mode,
30+
recompiling files as you change them. Any compilation errors will be printed
31+
to the terminal.
32+
33+
2. In your main terminal window/tab, run `npm run test:dev` to re-run the test
34+
suite and lint the code for both programming and style errors. You should run
35+
this command manually whenever you have new changes to test. Test failures
36+
and linter errors will be printed to the terminal.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# loopback4-dynamic-datasource
2+
3+
[![LoopBack](https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/)
4+
5+
## Installation
6+
7+
Install Loopback4DynamicDatasourceComponent using `npm`;
8+
9+
```sh
10+
$ [npm install | yarn add] loopback4-dynamic-datasource
11+
```
12+
13+
## Basic Use
14+
15+
Configure and load Loopback4DynamicDatasourceComponent in the application constructor
16+
as shown below.
17+
18+
```ts
19+
import {Loopback4DynamicDatasourceComponent, Loopback4DynamicDatasourceComponentOptions, DEFAULT_LOOPBACK4_DYNAMIC_DATASOURCE_OPTIONS} from 'loopback4-dynamic-datasource';
20+
// ...
21+
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
22+
constructor(options: ApplicationConfig = {}) {
23+
const opts: Loopback4DynamicDatasourceComponentOptions = DEFAULT_LOOPBACK4_DYNAMIC_DATASOURCE_OPTIONS;
24+
this.configure(Loopback4DynamicDatasourceComponentBindings.COMPONENT).to(opts);
25+
// Put the configuration options here
26+
});
27+
this.component(Loopback4DynamicDatasourceComponent);
28+
// ...
29+
}
30+
// ...
31+
}
32+
```

0 commit comments

Comments
 (0)