@vsaas/loopback-connector-remote 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +94 -0
- package/dist/_virtual/_rolldown/runtime.cjs +4 -0
- package/dist/index.cjs +7 -0
- package/dist/lib/relations.cjs +70 -0
- package/dist/lib/remote-connector.cjs +94 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) IBM Corp. 2014,2018. All Rights Reserved.
|
|
2
|
+
Node module: loopback-connector-remote
|
|
3
|
+
This project is licensed under the MIT License, full text below.
|
|
4
|
+
|
|
5
|
+
--------
|
|
6
|
+
|
|
7
|
+
MIT license
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @vsaas/loopback-connector-remote
|
|
2
|
+
|
|
3
|
+
`@vsaas/loopback-connector-remote` is a maintained fork of
|
|
4
|
+
`loopback-connector-remote` for the Xompass LoopBack 3 stack.
|
|
5
|
+
|
|
6
|
+
The goal of this fork is practical compatibility with existing LoopBack 3
|
|
7
|
+
applications while simplifying the package and aligning it with the rest of the
|
|
8
|
+
modernized `@vsaas/*` ecosystem.
|
|
9
|
+
|
|
10
|
+
## What Changed In This Fork
|
|
11
|
+
|
|
12
|
+
- Runtime migrated to TypeScript-backed sources and built to `dist/`
|
|
13
|
+
- Tooling aligned with the other forks:
|
|
14
|
+
- `tsdown`
|
|
15
|
+
- `vitest`
|
|
16
|
+
- `oxlint`
|
|
17
|
+
- `oxfmt`
|
|
18
|
+
- Legacy test/build infrastructure removed:
|
|
19
|
+
- `grunt`
|
|
20
|
+
- `mocha`
|
|
21
|
+
- old ESLint/JSHint config
|
|
22
|
+
- Avoidable development dependencies removed
|
|
23
|
+
- Package metadata and exports aligned with the scoped `@vsaas/*` packages
|
|
24
|
+
|
|
25
|
+
This package is intended for the Xompass-maintained LoopBack 3 forks. It is not
|
|
26
|
+
targeted at LoopBack 4.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @vsaas/loopback-connector-remote
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In practice this connector is usually installed alongside:
|
|
35
|
+
|
|
36
|
+
- `@vsaas/loopback`
|
|
37
|
+
- `@vsaas/loopback-datasource-juggler`
|
|
38
|
+
- `@vsaas/remoting`
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Configure a datasource with the `remote` connector:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"myRemoteDataSource": {
|
|
47
|
+
"name": "myRemoteDataSource",
|
|
48
|
+
"connector": "remote",
|
|
49
|
+
"url": "http://localhost:3000/api"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or in code:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const loopback = require('@vsaas/loopback');
|
|
58
|
+
|
|
59
|
+
const app = loopback();
|
|
60
|
+
|
|
61
|
+
const ds = app.dataSource('remote', {
|
|
62
|
+
connector: require('@vsaas/loopback-connector-remote'),
|
|
63
|
+
url: 'http://localhost:3000/api',
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
After attaching a compatible remote model, the connector proxies the remote
|
|
68
|
+
methods through LoopBack models and preserves promise-based usage:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const result = await app.dataSources.remote.models.MyModel.findById(1);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Public Exports
|
|
75
|
+
|
|
76
|
+
- `@vsaas/loopback-connector-remote`
|
|
77
|
+
- `@vsaas/loopback-connector-remote/relations`
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm run typecheck
|
|
83
|
+
npm run lint
|
|
84
|
+
npm test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Notes
|
|
88
|
+
|
|
89
|
+
- This fork keeps compatibility with common LoopBack 3 remote-model behavior.
|
|
90
|
+
- Error messages and maintenance decisions in the Xompass forks are kept in
|
|
91
|
+
English only.
|
|
92
|
+
- If you are using this package outside the Xompass forked stack, verify the
|
|
93
|
+
exact versions of `@vsaas/loopback`, `@vsaas/loopback-datasource-juggler`
|
|
94
|
+
and `@vsaas/remoting` you want to pair with it.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_lib_relations = require("./lib/relations.cjs");
|
|
3
|
+
const require_lib_remote_connector = require("./lib/remote-connector.cjs");
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
module.exports = require_lib_remote_connector;
|
|
6
|
+
module.exports.RelationMixin = require_lib_relations;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region src/lib/relations.ts
|
|
3
|
+
var require_relations = /* @__PURE__ */ require("../_virtual/_rolldown/runtime.cjs").__commonJSMin(((exports, module) => {
|
|
4
|
+
const RelationDefinition = require("@vsaas/loopback-datasource-juggler/relation-definition").RelationDefinition;
|
|
5
|
+
module.exports = RelationMixin;
|
|
6
|
+
function RelationMixin() {}
|
|
7
|
+
RelationMixin.hasMany = function hasMany(modelTo, params) {
|
|
8
|
+
const def = RelationDefinition.hasMany(this, modelTo, params);
|
|
9
|
+
this.dataSource.adapter.resolve(this);
|
|
10
|
+
defineRelationProperty(this, def);
|
|
11
|
+
};
|
|
12
|
+
RelationMixin.belongsTo = function belongsTo(modelTo, params) {
|
|
13
|
+
const def = RelationDefinition.belongsTo(this, modelTo, params);
|
|
14
|
+
this.dataSource.adapter.resolve(this);
|
|
15
|
+
defineRelationProperty(this, def);
|
|
16
|
+
};
|
|
17
|
+
RelationMixin.hasAndBelongsToMany = function hasAndBelongsToMany(modelTo, params) {
|
|
18
|
+
const def = RelationDefinition.hasAndBelongsToMany(this, modelTo, params);
|
|
19
|
+
this.dataSource.adapter.resolve(this);
|
|
20
|
+
defineRelationProperty(this, def);
|
|
21
|
+
};
|
|
22
|
+
RelationMixin.hasOne = function hasOne(modelTo, params) {
|
|
23
|
+
const def = RelationDefinition.hasOne(this, modelTo, params);
|
|
24
|
+
this.dataSource.adapter.resolve(this);
|
|
25
|
+
defineRelationProperty(this, def);
|
|
26
|
+
};
|
|
27
|
+
RelationMixin.referencesMany = function referencesMany(modelTo, params) {
|
|
28
|
+
const def = RelationDefinition.referencesMany(this, modelTo, params);
|
|
29
|
+
this.dataSource.adapter.resolve(this);
|
|
30
|
+
defineRelationProperty(this, def);
|
|
31
|
+
};
|
|
32
|
+
RelationMixin.embedsOne = function embedsOne(modelTo, params) {
|
|
33
|
+
const def = RelationDefinition.embedsOne(this, modelTo, params);
|
|
34
|
+
this.dataSource.adapter.resolve(this);
|
|
35
|
+
defineRelationProperty(this, def);
|
|
36
|
+
};
|
|
37
|
+
RelationMixin.embedsMany = function embedsMany(modelTo, params) {
|
|
38
|
+
const def = RelationDefinition.embedsMany(this, modelTo, params);
|
|
39
|
+
this.dataSource.adapter.resolve(this);
|
|
40
|
+
defineRelationProperty(this, def);
|
|
41
|
+
};
|
|
42
|
+
function defineRelationProperty(modelClass, def) {
|
|
43
|
+
Object.defineProperty(modelClass.prototype, def.name, { get() {
|
|
44
|
+
const scope = (...args) => {
|
|
45
|
+
const cachedEntities = this.__cachedRelations && this.__cachedRelations[def.name];
|
|
46
|
+
if (args.length || !cachedEntities) return this["__get__" + def.name].apply(this, args);
|
|
47
|
+
if (Array.isArray(cachedEntities)) return cachedEntities.map((data) => new def.modelTo(data));
|
|
48
|
+
return new def.modelTo(cachedEntities);
|
|
49
|
+
};
|
|
50
|
+
scope.count = (...args) => {
|
|
51
|
+
return this["__count__" + def.name].apply(this, args);
|
|
52
|
+
};
|
|
53
|
+
scope.create = (...args) => {
|
|
54
|
+
return this["__create__" + def.name].apply(this, args);
|
|
55
|
+
};
|
|
56
|
+
scope.deleteById = scope.destroyById = (...args) => {
|
|
57
|
+
return this["__destroyById__" + def.name].apply(this, args);
|
|
58
|
+
};
|
|
59
|
+
scope.exists = (...args) => {
|
|
60
|
+
return this["__exists__" + def.name].apply(this, args);
|
|
61
|
+
};
|
|
62
|
+
scope.findById = (...args) => {
|
|
63
|
+
return this["__findById__" + def.name].apply(this, args);
|
|
64
|
+
};
|
|
65
|
+
return scope;
|
|
66
|
+
} });
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
//#endregion
|
|
70
|
+
module.exports = require_relations();
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_lib_relations = require("./relations.cjs");
|
|
4
|
+
//#region src/lib/remote-connector.ts
|
|
5
|
+
var require_remote_connector = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
6
|
+
const assert = require("assert");
|
|
7
|
+
const remoting = require("@vsaas/remoting");
|
|
8
|
+
const utils = require("@vsaas/loopback-datasource-juggler/utils");
|
|
9
|
+
const jutil = require("@vsaas/loopback-datasource-juggler/jutil");
|
|
10
|
+
const RelationMixin = require_lib_relations;
|
|
11
|
+
const InclusionMixin = require("@vsaas/loopback-datasource-juggler/include");
|
|
12
|
+
const findMethodNames = new Set(["findById", "findOne"]);
|
|
13
|
+
module.exports = RemoteConnector;
|
|
14
|
+
function RemoteConnector(settings) {
|
|
15
|
+
assert(typeof settings === "object", "cannot initialize RemoteConnector without a settings object");
|
|
16
|
+
this.client = settings.client;
|
|
17
|
+
this.adapter = settings.adapter || "rest";
|
|
18
|
+
this.protocol = settings.protocol || "http";
|
|
19
|
+
this.root = settings.root || "";
|
|
20
|
+
this.host = settings.host || "localhost";
|
|
21
|
+
this.port = settings.port || 3e3;
|
|
22
|
+
this.remotes = remoting.create(settings.options);
|
|
23
|
+
this.name = "remote-connector";
|
|
24
|
+
if (settings.url) this.url = settings.url;
|
|
25
|
+
else this.url = this.protocol + "://" + this.host + ":" + this.port + this.root;
|
|
26
|
+
this.DataAccessObject = function() {};
|
|
27
|
+
}
|
|
28
|
+
RemoteConnector.prototype.connect = function() {
|
|
29
|
+
this.remotes.connect(this.url, this.adapter);
|
|
30
|
+
};
|
|
31
|
+
RemoteConnector.initialize = function(dataSource, callback) {
|
|
32
|
+
(dataSource.connector = new RemoteConnector(dataSource.settings)).connect();
|
|
33
|
+
process.nextTick(callback);
|
|
34
|
+
};
|
|
35
|
+
RemoteConnector.prototype.define = function(definition) {
|
|
36
|
+
const Model = definition.model;
|
|
37
|
+
const remotes = this.remotes;
|
|
38
|
+
assert(Model.sharedClass, "cannot attach " + Model.modelName + " to a remote connector without a Model.sharedClass");
|
|
39
|
+
jutil.mixin(Model, RelationMixin);
|
|
40
|
+
jutil.mixin(Model, InclusionMixin);
|
|
41
|
+
remotes.addClass(Model.sharedClass);
|
|
42
|
+
this.resolve(Model);
|
|
43
|
+
this.setupRemotingTypeFor(Model);
|
|
44
|
+
};
|
|
45
|
+
RemoteConnector.prototype.resolve = function(Model) {
|
|
46
|
+
const remotes = this.remotes;
|
|
47
|
+
Model.sharedClass.methods().forEach(function(remoteMethod) {
|
|
48
|
+
if (remoteMethod.name !== "Change" && remoteMethod.name !== "Checkpoint") createProxyMethod(Model, remotes, remoteMethod);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
RemoteConnector.prototype.setupRemotingTypeFor = function(Model) {
|
|
52
|
+
this.remotes.defineObjectType(Model.modelName, function(data) {
|
|
53
|
+
const model = new Model(data);
|
|
54
|
+
if (model.__cachedRelations) for (const relation in model.__cachedRelations) {
|
|
55
|
+
const relatedModel = model.__cachedRelations[relation];
|
|
56
|
+
model.__data[relation] = relatedModel;
|
|
57
|
+
}
|
|
58
|
+
return model;
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
function createProxyMethod(Model, remotes, remoteMethod) {
|
|
62
|
+
const scope = remoteMethod.isStatic ? Model : Model.prototype;
|
|
63
|
+
function remoteMethodProxy() {
|
|
64
|
+
const args = Array.prototype.slice.call(arguments);
|
|
65
|
+
const lastArgIsFunc = typeof args[args.length - 1] === "function";
|
|
66
|
+
let callback;
|
|
67
|
+
if (lastArgIsFunc) callback = args.pop();
|
|
68
|
+
else callback = utils.createPromiseCallback();
|
|
69
|
+
const callbackPromise = callback.promise;
|
|
70
|
+
const finalCallback = findMethodNames.has(remoteMethod.name) ? proxy404toNull(callback) : callback;
|
|
71
|
+
if (remoteMethod.isStatic) remotes.invoke(remoteMethod.stringName, args, finalCallback);
|
|
72
|
+
else {
|
|
73
|
+
const ctorArgs = [this.id];
|
|
74
|
+
remotes.invoke(remoteMethod.stringName, ctorArgs, args, finalCallback);
|
|
75
|
+
}
|
|
76
|
+
return callbackPromise;
|
|
77
|
+
}
|
|
78
|
+
scope[remoteMethod.name] = remoteMethodProxy;
|
|
79
|
+
remoteMethod.aliases.forEach(function(alias) {
|
|
80
|
+
scope[alias] = remoteMethodProxy;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function proxy404toNull(cb) {
|
|
84
|
+
return function(err, data) {
|
|
85
|
+
if (err && err.code === "MODEL_NOT_FOUND") {
|
|
86
|
+
cb(null, null);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
cb(err, data);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
//#endregion
|
|
94
|
+
module.exports = require_remote_connector();
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vsaas/loopback-connector-remote",
|
|
3
|
+
"version": "10.0.0",
|
|
4
|
+
"description": "Remote REST API connector for Loopback",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"StrongLoop",
|
|
7
|
+
"rest",
|
|
8
|
+
"restful",
|
|
9
|
+
"web"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/xompass/loopback-connector-remote",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/xompass/loopback-connector-remote/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Xompass",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/xompass/loopback-connector-remote"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./dist/index.cjs",
|
|
29
|
+
"./relations": "./dist/lib/relations.cjs",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@vsaas/remoting": "^10.0.0",
|
|
38
|
+
"@vsaas/loopback-datasource-juggler": "^10.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "25.5.0",
|
|
42
|
+
"oxfmt": "0.42.0",
|
|
43
|
+
"oxlint": "1.57.0",
|
|
44
|
+
"tsdown": "0.21.5",
|
|
45
|
+
"typescript": "6.0.2",
|
|
46
|
+
"vitest": "4.1.1",
|
|
47
|
+
"@vsaas/error-handler": "^10.0.0",
|
|
48
|
+
"@vsaas/loopback": "^10.0.0"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown",
|
|
55
|
+
"fmt": "oxfmt -c ../.oxfmtrc.json .",
|
|
56
|
+
"lint": "oxlint -c ../.oxlintrc.json .",
|
|
57
|
+
"lint:fix": "oxlint -c ../.oxlintrc.json . --fix",
|
|
58
|
+
"test:run": "vitest run",
|
|
59
|
+
"test:deps": "pnpm --filter @vsaas/error-handler --filter @vsaas/remoting --filter @vsaas/loopback-datasource-juggler --filter @vsaas/loopback-connector-remote --filter @vsaas/loopback build",
|
|
60
|
+
"test": "pnpm run test:deps && pnpm run build && vitest run",
|
|
61
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
62
|
+
}
|
|
63
|
+
}
|