@vsaas/remoting 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.md +202 -0
- package/README.md +78 -0
- package/dist/_virtual/_rolldown/runtime.js +32 -0
- package/dist/ext/meta.d.ts +1 -0
- package/dist/ext/meta.js +39 -0
- package/dist/ext/meta.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/context-base.d.ts +1 -0
- package/dist/lib/context-base.js +30 -0
- package/dist/lib/context-base.js.map +1 -0
- package/dist/lib/deprecate.d.ts +1 -0
- package/dist/lib/deprecate.js +34 -0
- package/dist/lib/deprecate.js.map +1 -0
- package/dist/lib/escape-regexp.d.ts +1 -0
- package/dist/lib/escape-regexp.js +12 -0
- package/dist/lib/escape-regexp.js.map +1 -0
- package/dist/lib/exports-helper.d.ts +1 -0
- package/dist/lib/exports-helper.js +101 -0
- package/dist/lib/exports-helper.js.map +1 -0
- package/dist/lib/http-context.d.ts +1 -0
- package/dist/lib/http-context.js +484 -0
- package/dist/lib/http-context.js.map +1 -0
- package/dist/lib/http-invocation.d.ts +1 -0
- package/dist/lib/http-invocation.js +254 -0
- package/dist/lib/http-invocation.js.map +1 -0
- package/dist/lib/jsonrpc-adapter.d.ts +1 -0
- package/dist/lib/jsonrpc-adapter.js +187 -0
- package/dist/lib/jsonrpc-adapter.js.map +1 -0
- package/dist/lib/looks-like-json.d.ts +1 -0
- package/dist/lib/looks-like-json.js +22 -0
- package/dist/lib/looks-like-json.js.map +1 -0
- package/dist/lib/messages.d.ts +1 -0
- package/dist/lib/messages.js +24 -0
- package/dist/lib/messages.js.map +1 -0
- package/dist/lib/number-checks.d.ts +1 -0
- package/dist/lib/number-checks.js +18 -0
- package/dist/lib/number-checks.js.map +1 -0
- package/dist/lib/phases/merge-phase-name-lists.d.ts +5 -0
- package/dist/lib/phases/merge-phase-name-lists.d.ts.map +1 -0
- package/dist/lib/phases/merge-phase-name-lists.js +39 -0
- package/dist/lib/phases/merge-phase-name-lists.js.map +1 -0
- package/dist/lib/phases/phase-list.d.ts +27 -0
- package/dist/lib/phases/phase-list.d.ts.map +1 -0
- package/dist/lib/phases/phase-list.js +154 -0
- package/dist/lib/phases/phase-list.js.map +1 -0
- package/dist/lib/phases/phase.d.ts +24 -0
- package/dist/lib/phases/phase.d.ts.map +1 -0
- package/dist/lib/phases/phase.js +144 -0
- package/dist/lib/phases/phase.js.map +1 -0
- package/dist/lib/remote-objects.d.ts +1 -0
- package/dist/lib/remote-objects.js +642 -0
- package/dist/lib/remote-objects.js.map +1 -0
- package/dist/lib/rest-adapter-browser.d.ts +1 -0
- package/dist/lib/rest-adapter-browser.js +302 -0
- package/dist/lib/rest-adapter-browser.js.map +1 -0
- package/dist/lib/rest-adapter.d.ts +1 -0
- package/dist/lib/rest-adapter.js +519 -0
- package/dist/lib/rest-adapter.js.map +1 -0
- package/dist/lib/server-sent-events.d.ts +1 -0
- package/dist/lib/server-sent-events.js +61 -0
- package/dist/lib/server-sent-events.js.map +1 -0
- package/dist/lib/shared-class.d.ts +1 -0
- package/dist/lib/shared-class.js +207 -0
- package/dist/lib/shared-class.js.map +1 -0
- package/dist/lib/shared-method.d.ts +1 -0
- package/dist/lib/shared-method.js +469 -0
- package/dist/lib/shared-method.js.map +1 -0
- package/dist/lib/socket-io-adapter.d.ts +1 -0
- package/dist/lib/socket-io-adapter.js +93 -0
- package/dist/lib/socket-io-adapter.js.map +1 -0
- package/dist/lib/socket-io-context.d.ts +1 -0
- package/dist/lib/socket-io-context.js +94 -0
- package/dist/lib/socket-io-context.js.map +1 -0
- package/dist/lib/type-registry.d.ts +1 -0
- package/dist/lib/type-registry.js +99 -0
- package/dist/lib/type-registry.js.map +1 -0
- package/dist/lib/types/any.d.ts +1 -0
- package/dist/lib/types/any.js +44 -0
- package/dist/lib/types/any.js.map +1 -0
- package/dist/lib/types/array.d.ts +1 -0
- package/dist/lib/types/array.js +99 -0
- package/dist/lib/types/array.js.map +1 -0
- package/dist/lib/types/boolean.d.ts +1 -0
- package/dist/lib/types/boolean.js +37 -0
- package/dist/lib/types/boolean.js.map +1 -0
- package/dist/lib/types/date.d.ts +1 -0
- package/dist/lib/types/date.js +37 -0
- package/dist/lib/types/date.js.map +1 -0
- package/dist/lib/types/geopoint.d.ts +1 -0
- package/dist/lib/types/geopoint.js +68 -0
- package/dist/lib/types/geopoint.js.map +1 -0
- package/dist/lib/types/integer.d.ts +1 -0
- package/dist/lib/types/integer.js +36 -0
- package/dist/lib/types/integer.js.map +1 -0
- package/dist/lib/types/number.d.ts +1 -0
- package/dist/lib/types/number.js +30 -0
- package/dist/lib/types/number.js.map +1 -0
- package/dist/lib/types/object.d.ts +1 -0
- package/dist/lib/types/object.js +57 -0
- package/dist/lib/types/object.js.map +1 -0
- package/dist/lib/types/string.d.ts +1 -0
- package/dist/lib/types/string.js +29 -0
- package/dist/lib/types/string.js.map +1 -0
- package/dist/phases.d.ts +4 -0
- package/dist/phases.js +35 -0
- package/dist/phases.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_lib_messages = require("./messages.js");
|
|
4
|
+
const require_lib_context_base = require("./context-base.js");
|
|
5
|
+
//#region src/lib/http-invocation.ts
|
|
6
|
+
var require_http_invocation = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, module) => {
|
|
7
|
+
const g = require_lib_messages;
|
|
8
|
+
/*!
|
|
9
|
+
* Expose `HttpInvocation`.
|
|
10
|
+
*/
|
|
11
|
+
module.exports = HttpInvocation;
|
|
12
|
+
/*!
|
|
13
|
+
* Module dependencies.
|
|
14
|
+
*/
|
|
15
|
+
const EventEmitter = require("events").EventEmitter;
|
|
16
|
+
const debug = require("debug")("strong-remoting:http-invocation");
|
|
17
|
+
const inherits = require("util").inherits;
|
|
18
|
+
require("path");
|
|
19
|
+
require("assert");
|
|
20
|
+
const request = require("@sailshq/request");
|
|
21
|
+
const ContextBase = require_lib_context_base;
|
|
22
|
+
const qs = require("qs");
|
|
23
|
+
require("stream").Readable;
|
|
24
|
+
const MuxDemux = require("mux-demux");
|
|
25
|
+
/*!
|
|
26
|
+
* JSON Types
|
|
27
|
+
*/
|
|
28
|
+
const JSON_TYPES = [
|
|
29
|
+
"boolean",
|
|
30
|
+
"string",
|
|
31
|
+
"object",
|
|
32
|
+
"number"
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Create a new `HttpInvocation`.
|
|
36
|
+
* @class
|
|
37
|
+
* @param {SharedMethod} method
|
|
38
|
+
* @param {Array} [args]
|
|
39
|
+
* @param {String} base The base URL
|
|
40
|
+
* @property {String} base The base URL
|
|
41
|
+
* @property {SharedMethod} method The `SharedMethod` which will be invoked
|
|
42
|
+
* @property {Array} args The arguments to be used when invoking the `SharedMethod`
|
|
43
|
+
*/
|
|
44
|
+
function HttpInvocation(method, ctorArgs, args, baseUrl, auth, typeRegistry) {
|
|
45
|
+
this.base = baseUrl;
|
|
46
|
+
this.auth = auth;
|
|
47
|
+
this.method = method;
|
|
48
|
+
this.args = args || [];
|
|
49
|
+
this.ctorArgs = ctorArgs || [];
|
|
50
|
+
this.typeRegistry = typeRegistry;
|
|
51
|
+
this.isStatic = method.hasOwnProperty("isStatic") && method.isStatic || method.hasOwnProperty("sharedMethod") && method.sharedMethod.isStatic;
|
|
52
|
+
const namedArgs = this.namedArgs = {};
|
|
53
|
+
if (!this.isStatic) {
|
|
54
|
+
const ctorAccepts = method.restClass.ctor.accepts;
|
|
55
|
+
for (let i = 0; i < ctorAccepts.length; i++) {
|
|
56
|
+
const accept = ctorAccepts[i];
|
|
57
|
+
const val = ctorArgs[i];
|
|
58
|
+
if (HttpInvocation.isAcceptable(val, accept)) namedArgs[accept.arg || accept.name] = val;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < method.accepts.length; i++) {
|
|
62
|
+
const accept = method.accepts[i];
|
|
63
|
+
const val = args[i];
|
|
64
|
+
if (HttpInvocation.isAcceptable(val, accept)) namedArgs[accept.arg || accept.name] = val;
|
|
65
|
+
}
|
|
66
|
+
this.context = new ContextBase(method, typeRegistry);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Inherit from `EventEmitter`.
|
|
70
|
+
*/
|
|
71
|
+
inherits(HttpInvocation, EventEmitter);
|
|
72
|
+
/**
|
|
73
|
+
* Determine if the value matches the given accept definition.
|
|
74
|
+
*/
|
|
75
|
+
HttpInvocation.isAcceptable = function(val, accept) {
|
|
76
|
+
const acceptArray = Array.isArray(accept.type) || accept.type.toLowerCase() === "array";
|
|
77
|
+
const type = acceptArray ? "array" : accept.type && accept.type.toLowerCase();
|
|
78
|
+
const strict = type && type !== "any";
|
|
79
|
+
if (acceptArray) return Array.isArray(val);
|
|
80
|
+
if (strict) {
|
|
81
|
+
if (JSON_TYPES.indexOf(type) === -1) return typeof val === "object";
|
|
82
|
+
return (typeof val).toLowerCase() === type;
|
|
83
|
+
} else return true;
|
|
84
|
+
};
|
|
85
|
+
HttpInvocation.prototype._processArg = function(req, verb, query, accept) {
|
|
86
|
+
const httpFormat = accept.http;
|
|
87
|
+
const name = accept.name || accept.arg;
|
|
88
|
+
const val = this.getArgByName(name);
|
|
89
|
+
if (httpFormat) switch (typeof httpFormat) {
|
|
90
|
+
case "function": break;
|
|
91
|
+
case "object":
|
|
92
|
+
switch (httpFormat.source) {
|
|
93
|
+
case "body":
|
|
94
|
+
req.body = val;
|
|
95
|
+
break;
|
|
96
|
+
case "form":
|
|
97
|
+
case "formData":
|
|
98
|
+
req.body = req.body || {};
|
|
99
|
+
req.body[name] = val;
|
|
100
|
+
break;
|
|
101
|
+
case "query":
|
|
102
|
+
if (val !== void 0) {
|
|
103
|
+
query = query || {};
|
|
104
|
+
query[name] = serializeQueryStringValue(val, accept);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
case "header":
|
|
108
|
+
if (val !== void 0) {
|
|
109
|
+
req.headers = req.headers || {};
|
|
110
|
+
req.headers[name] = val;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case "path":
|
|
114
|
+
req.url = req.url.replace(":" + name, val);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
else if (verb.toLowerCase() === "get") {
|
|
120
|
+
if (val !== void 0) {
|
|
121
|
+
query = query || {};
|
|
122
|
+
query[name] = serializeQueryStringValue(val, accept);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
req.body = req.body || {};
|
|
126
|
+
req.body[name] = val;
|
|
127
|
+
}
|
|
128
|
+
return query;
|
|
129
|
+
};
|
|
130
|
+
function serializeQueryStringValue(val, accept) {
|
|
131
|
+
if ((accept.type === "object" || accept.type === "string") && typeof val === "object") return JSON.stringify(val);
|
|
132
|
+
else return val;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build args object from the http context's `req` and `res`.
|
|
136
|
+
*/
|
|
137
|
+
HttpInvocation.prototype.createRequest = function() {
|
|
138
|
+
const method = this.method;
|
|
139
|
+
const endpoint = method.getEndpoints()[0];
|
|
140
|
+
const verb = endpoint.verb;
|
|
141
|
+
const req = this.req = { method: verb || "GET" };
|
|
142
|
+
const accepts = method.accepts;
|
|
143
|
+
let ctorAccepts = null;
|
|
144
|
+
let query, i;
|
|
145
|
+
const auth = this.auth;
|
|
146
|
+
req.url = this.base + endpoint.fullPath;
|
|
147
|
+
if (URL.canParse(req.url)) req.protocol = new URL(req.url).protocol;
|
|
148
|
+
req.json = true;
|
|
149
|
+
if (auth && auth.accessToken) {
|
|
150
|
+
req.headers = req.headers || {};
|
|
151
|
+
req.headers.Authorization = auth.accessToken.id;
|
|
152
|
+
} else if (auth) {
|
|
153
|
+
req.auth = {};
|
|
154
|
+
if (auth.username && auth.password) {
|
|
155
|
+
req.auth.username = auth.username;
|
|
156
|
+
req.auth.password = auth.password;
|
|
157
|
+
}
|
|
158
|
+
if (auth.bearer) req.auth.bearer = auth.bearer;
|
|
159
|
+
if ("sendImmediately" in auth) req.auth.sendImmediately = auth.sendImmediately;
|
|
160
|
+
else req.auth.sendImmediately = false;
|
|
161
|
+
}
|
|
162
|
+
if (!this.isStatic) {
|
|
163
|
+
ctorAccepts = method.restClass.ctor.accepts;
|
|
164
|
+
for (i in ctorAccepts) query = this._processArg(req, verb, query, ctorAccepts[i]);
|
|
165
|
+
}
|
|
166
|
+
for (i in accepts) query = this._processArg(req, verb, query, accepts[i]);
|
|
167
|
+
if (query) req.url += "?" + qs.stringify(query);
|
|
168
|
+
return req;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Get an argument value by name.
|
|
172
|
+
*
|
|
173
|
+
* @param {String} name
|
|
174
|
+
* @returns {*} Value of specified argument.
|
|
175
|
+
*/
|
|
176
|
+
HttpInvocation.prototype.getArgByName = function(name) {
|
|
177
|
+
return this.namedArgs[name];
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Start the invocation.
|
|
181
|
+
*/
|
|
182
|
+
HttpInvocation.prototype.invoke = function(callback) {
|
|
183
|
+
const self = this;
|
|
184
|
+
if (!this.req) this.createRequest();
|
|
185
|
+
const method = this.method;
|
|
186
|
+
const returnStreamDesc = method.sharedMethod.streams && method.sharedMethod.streams.returns;
|
|
187
|
+
if (!!returnStreamDesc) {
|
|
188
|
+
if (returnStreamDesc.type === "ReadableStream" && returnStreamDesc.json) {
|
|
189
|
+
const mdm = new MuxDemux();
|
|
190
|
+
mdm.on("connection", function(stream) {
|
|
191
|
+
callback(null, stream);
|
|
192
|
+
});
|
|
193
|
+
request(this.req).pipe(mdm);
|
|
194
|
+
} else callback(new Error(g.f("unsupported stream type")));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
request(this.req, function(err, res, body) {
|
|
198
|
+
if (err instanceof SyntaxError) {
|
|
199
|
+
if (res.status === 204) err = null;
|
|
200
|
+
}
|
|
201
|
+
if (err) return callback(err);
|
|
202
|
+
self.res = self.context.res = res;
|
|
203
|
+
try {
|
|
204
|
+
self.transformResponse(res, body, callback);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
callback(err);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
HttpInvocation.prototype.getResponse = function() {
|
|
211
|
+
return this.res || null;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Transform the response into callback arguments
|
|
215
|
+
* @param {HttpResponse} res
|
|
216
|
+
* @param {Function} callback
|
|
217
|
+
*/
|
|
218
|
+
HttpInvocation.prototype.transformResponse = function(res, body, callback) {
|
|
219
|
+
const callbackArgs = [null];
|
|
220
|
+
const returns = this.method.returns;
|
|
221
|
+
const isObject = typeof body === "object";
|
|
222
|
+
let err;
|
|
223
|
+
if (res.statusCode >= 400) {
|
|
224
|
+
if (isObject && body.error) {
|
|
225
|
+
err = new Error(body.error.message);
|
|
226
|
+
for (const key in body.error) err[key] = body.error[key];
|
|
227
|
+
} else {
|
|
228
|
+
err = new Error(g.f("Error: %d", res.statusCode));
|
|
229
|
+
err.statusCode = res.statusCode;
|
|
230
|
+
err.details = body;
|
|
231
|
+
}
|
|
232
|
+
return callback(err);
|
|
233
|
+
}
|
|
234
|
+
for (let i = 0, n = returns.length; i < n; i++) {
|
|
235
|
+
const ret = returns[i];
|
|
236
|
+
const name = ret.name || ret.arg;
|
|
237
|
+
const type = ret.type;
|
|
238
|
+
const val = ret.root ? res.body : res.body[name];
|
|
239
|
+
const result = this.typeRegistry.getConverter(type).fromTypedValue(this.context, val);
|
|
240
|
+
debug("return arg %j: converted %j to %j", name, val, result);
|
|
241
|
+
if (result.error) {
|
|
242
|
+
err = result.error;
|
|
243
|
+
err.message = g.f("Invalid return argument %j. ", name) + err.message;
|
|
244
|
+
return callback(err);
|
|
245
|
+
}
|
|
246
|
+
callbackArgs.push(result.value);
|
|
247
|
+
}
|
|
248
|
+
callback.apply(this, callbackArgs);
|
|
249
|
+
};
|
|
250
|
+
}));
|
|
251
|
+
//#endregion
|
|
252
|
+
module.exports = require_http_invocation();
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=http-invocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-invocation.js","names":[],"sources":["../../src/lib/http-invocation.ts"],"sourcesContent":["// Copyright IBM Corp. 2014,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst g = require('./messages');\n/*!\n * Expose `HttpInvocation`.\n */\nmodule.exports = HttpInvocation;\n\n/*!\n * Module dependencies.\n */\nconst EventEmitter = require('events').EventEmitter;\nconst debug = require('debug')('strong-remoting:http-invocation');\nconst util = require('util');\nconst inherits = util.inherits;\nconst path = require('path');\nconst assert = require('assert');\nconst request = require('@sailshq/request');\nconst ContextBase = require('./context-base');\nconst SUPPORTED_TYPES = ['json', 'application/javascript', 'text/javascript'];\nconst qs = require('qs');\nconst ReadableStream = require('stream').Readable;\nconst MuxDemux = require('mux-demux');\n\n/*!\n * JSON Types\n */\nconst JSON_TYPES = ['boolean', 'string', 'object', 'number'];\n\n/**\n * Create a new `HttpInvocation`.\n * @class\n * @param {SharedMethod} method\n * @param {Array} [args]\n * @param {String} base The base URL\n * @property {String} base The base URL\n * @property {SharedMethod} method The `SharedMethod` which will be invoked\n * @property {Array} args The arguments to be used when invoking the `SharedMethod`\n */\n\nfunction HttpInvocation(method, ctorArgs, args, baseUrl, auth, typeRegistry) {\n this.base = baseUrl;\n this.auth = auth;\n this.method = method;\n this.args = args || [];\n this.ctorArgs = ctorArgs || [];\n this.typeRegistry = typeRegistry;\n this.isStatic =\n (method.hasOwnProperty('isStatic') && method.isStatic) ||\n (method.hasOwnProperty('sharedMethod') && method.sharedMethod.isStatic);\n const namedArgs = (this.namedArgs = {});\n\n if (!this.isStatic) {\n const ctorAccepts = method.restClass.ctor.accepts;\n for (let i = 0; i < ctorAccepts.length; i++) {\n const accept = ctorAccepts[i];\n const val = ctorArgs[i];\n if (HttpInvocation.isAcceptable(val, accept)) {\n namedArgs[accept.arg || accept.name] = val;\n }\n }\n }\n\n for (let i = 0; i < method.accepts.length; i++) {\n const accept = method.accepts[i];\n const val = args[i];\n if (HttpInvocation.isAcceptable(val, accept)) {\n namedArgs[accept.arg || accept.name] = val;\n }\n }\n\n this.context = new ContextBase(method, typeRegistry);\n}\n\n/**\n * Inherit from `EventEmitter`.\n */\n\ninherits(HttpInvocation, EventEmitter);\n\n/**\n * Determine if the value matches the given accept definition.\n */\n\nHttpInvocation.isAcceptable = function (val, accept) {\n const acceptArray = Array.isArray(accept.type) || accept.type.toLowerCase() === 'array';\n const type = acceptArray ? 'array' : accept.type && accept.type.toLowerCase();\n const strict = type && type !== 'any';\n\n if (acceptArray) {\n return Array.isArray(val);\n }\n\n if (strict) {\n if (JSON_TYPES.indexOf(type) === -1) {\n return typeof val === 'object';\n }\n return (typeof val).toLowerCase() === type;\n } else {\n return true;\n }\n};\n\nHttpInvocation.prototype._processArg = function (req, verb, query, accept) {\n const httpFormat = accept.http;\n const name = accept.name || accept.arg;\n const val = this.getArgByName(name);\n\n if (httpFormat) {\n switch (typeof httpFormat) {\n case 'function':\n // ignore defined formatter\n break;\n case 'object':\n switch (httpFormat.source) {\n case 'body':\n req.body = val;\n break;\n case 'form':\n case 'formData':\n // From the form (body)\n req.body = req.body || {};\n req.body[name] = val;\n break;\n case 'query':\n // From the query string\n if (val !== undefined) {\n query = query || {};\n query[name] = serializeQueryStringValue(val, accept);\n }\n break;\n case 'header':\n if (val !== undefined) {\n req.headers = req.headers || {};\n req.headers[name] = val;\n }\n break;\n case 'path':\n // From the url path\n req.url = req.url.replace(':' + name, val);\n break;\n }\n break;\n }\n } else if (verb.toLowerCase() === 'get') {\n // default to query string for GET\n if (val !== undefined) {\n query = query || {};\n query[name] = serializeQueryStringValue(val, accept);\n }\n } else {\n // default to storing args on the body for !GET\n req.body = req.body || {};\n req.body[name] = val;\n }\n\n return query;\n};\n\nfunction serializeQueryStringValue(val, accept) {\n if ((accept.type === 'object' || accept.type === 'string') && typeof val === 'object') {\n return JSON.stringify(val);\n } else {\n return val;\n }\n}\n\n/**\n * Build args object from the http context's `req` and `res`.\n */\n\nHttpInvocation.prototype.createRequest = function () {\n const method = this.method;\n const endpoint = method.getEndpoints()[0];\n const verb = endpoint.verb;\n const req = (this.req = { method: verb || 'GET' });\n const accepts = method.accepts;\n let ctorAccepts = null;\n let query, i;\n const auth = this.auth;\n\n // initial url is the format\n req.url = this.base + endpoint.fullPath;\n\n if (URL.canParse(req.url)) {\n req.protocol = new URL(req.url).protocol;\n }\n\n // the body is json\n req.json = true;\n\n if (auth && auth.accessToken) {\n // use regular headers to send LoopBack's access token\n req.headers = req.headers || {};\n req.headers.Authorization = auth.accessToken.id;\n } else if (auth) {\n req.auth = {};\n // add auth if it is set\n if (auth.username && auth.password) {\n req.auth.username = auth.username;\n req.auth.password = auth.password;\n }\n if (auth.bearer) {\n req.auth.bearer = auth.bearer;\n }\n if ('sendImmediately' in auth) {\n req.auth.sendImmediately = auth.sendImmediately;\n } else {\n req.auth.sendImmediately = false;\n }\n }\n\n // build request args and method options\n if (!this.isStatic) {\n ctorAccepts = method.restClass.ctor.accepts;\n for (i in ctorAccepts) {\n query = this._processArg(req, verb, query, ctorAccepts[i]);\n }\n }\n\n for (i in accepts) {\n query = this._processArg(req, verb, query, accepts[i]);\n }\n\n if (query) {\n req.url += '?' + qs.stringify(query);\n }\n\n return req;\n};\n\n/**\n * Get an argument value by name.\n *\n * @param {String} name\n * @returns {*} Value of specified argument.\n */\n\nHttpInvocation.prototype.getArgByName = function (name) {\n return this.namedArgs[name];\n};\n\n/**\n * Start the invocation.\n */\n\nHttpInvocation.prototype.invoke = function (callback) {\n const self = this;\n if (!this.req) {\n this.createRequest();\n }\n const method = this.method;\n const returnStreamDesc = method.sharedMethod.streams && method.sharedMethod.streams.returns;\n const methodReturnsStream = !!returnStreamDesc;\n\n if (methodReturnsStream) {\n if (returnStreamDesc.type === 'ReadableStream' && returnStreamDesc.json) {\n const mdm = new MuxDemux();\n mdm.on('connection', function (stream) {\n callback(null, stream);\n });\n\n request(this.req).pipe(mdm);\n } else {\n callback(new Error(g.f('unsupported stream type')));\n }\n\n return;\n }\n\n request(this.req, function (err, res, body) {\n if (err instanceof SyntaxError) {\n if (res.status === 204) err = null;\n }\n if (err) return callback(err);\n self.res = self.context.res = res;\n try {\n self.transformResponse(res, body, callback);\n } catch (err) {\n callback(err);\n }\n });\n};\n\n/*\n * Get Response object\n */\n\nHttpInvocation.prototype.getResponse = function () {\n return this.res || null;\n};\n\n/**\n * Transform the response into callback arguments\n * @param {HttpResponse} res\n * @param {Function} callback\n */\n\nHttpInvocation.prototype.transformResponse = function (res, body, callback) {\n const self = this;\n const callbackArgs = [null]; // null => placeholder for err\n const method = this.method;\n const returns = method.returns;\n const isObject = typeof body === 'object';\n let err;\n const hasError = res.statusCode >= 400;\n\n if (hasError) {\n if (isObject && body.error) {\n err = new Error(body.error.message);\n /* eslint-disable one-var */\n for (const key in body.error) {\n err[key] = body.error[key];\n }\n /* eslint-enable one-var */\n } else {\n err = new Error(g.f('Error: %d', res.statusCode));\n err.statusCode = res.statusCode;\n err.details = body;\n }\n\n return callback(err);\n }\n\n // build request args and method options\n for (let i = 0, n = returns.length; i < n; i++) {\n const ret = returns[i];\n const name = ret.name || ret.arg;\n const type = ret.type;\n\n const val = ret.root ? res.body : res.body[name];\n\n const converter = this.typeRegistry.getConverter(type);\n const result = converter.fromTypedValue(this.context, val);\n debug('return arg %j: converted %j to %j', name, val, result);\n\n if (result.error) {\n err = result.error;\n err.message = g.f('Invalid return argument %j. ', name) + err.message;\n return callback(err);\n }\n\n callbackArgs.push(result.value);\n /* eslint-enable one-var */\n }\n\n callback.apply(this, callbackArgs);\n};\n"],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nB;AACL,UAAM,IAAI,MAAM,EAAE,EAAE,aAAa,IAAI,WAAW,CAAC;AACjD,QAAI,aAAa,IAAI;AACrB,QAAI,UAAU;;AAGhB,UAAO,SAAS,IAAI;;AAItB,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAAI,GAAG,KAAK;GAC9C,MAAM,MAAM,QAAQ;GACpB,MAAM,OAAO,IAAI,QAAQ,IAAI;GAC7B,MAAM,OAAO,IAAI;GAEjB,MAAM,MAAM,IAAI,OAAO,IAAI,OAAO,IAAI,KAAK;GAG3C,MAAM,SADY,KAAK,aAAa,aAAa,KAAK,CAC7B,eAAe,KAAK,SAAS,IAAI;AAC1D,SAAM,qCAAqC,MAAM,KAAK,OAAO;AAE7D,OAAI,OAAO,OAAO;AAChB,UAAM,OAAO;AACb,QAAI,UAAU,EAAE,EAAE,gCAAgC,KAAK,GAAG,IAAI;AAC9D,WAAO,SAAS,IAAI;;AAGtB,gBAAa,KAAK,OAAO,MAAM;;AAIjC,WAAS,MAAM,MAAM,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_lib_messages = require("./messages.js");
|
|
3
|
+
const require_lib_http_context = require("./http-context.js");
|
|
4
|
+
//#region src/lib/jsonrpc-adapter.ts
|
|
5
|
+
const g = require_lib_messages;
|
|
6
|
+
/*!
|
|
7
|
+
* Expose `JsonRpcAdapter`.
|
|
8
|
+
*/
|
|
9
|
+
module.exports = JsonRpcAdapter;
|
|
10
|
+
/*!
|
|
11
|
+
* Module dependencies.
|
|
12
|
+
*/
|
|
13
|
+
const EventEmitter = require("events").EventEmitter;
|
|
14
|
+
const debug = require("debug")("strong-remoting:jsonrpc-adapter");
|
|
15
|
+
const inherits = require("util").inherits;
|
|
16
|
+
const jayson = require("jayson");
|
|
17
|
+
const express = require("express");
|
|
18
|
+
const HttpContext = require_lib_http_context;
|
|
19
|
+
const json = express.json;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new `JsonRpcAdapter` with the given `options`.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} options
|
|
24
|
+
* @return {JsonRpcAdapter}
|
|
25
|
+
*/
|
|
26
|
+
function JsonRpcAdapter(remotes) {
|
|
27
|
+
EventEmitter.call(this);
|
|
28
|
+
this.remotes = remotes;
|
|
29
|
+
this.Context = HttpContext;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Inherit from `EventEmitter`.
|
|
33
|
+
*/
|
|
34
|
+
inherits(JsonRpcAdapter, EventEmitter);
|
|
35
|
+
/*!
|
|
36
|
+
* Simplified APIs
|
|
37
|
+
*/
|
|
38
|
+
JsonRpcAdapter.create = JsonRpcAdapter.createJsonRpcAdapter = function(remotes) {
|
|
39
|
+
return new JsonRpcAdapter(remotes);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Get the path for the given method.
|
|
43
|
+
*/
|
|
44
|
+
JsonRpcAdapter.prototype.getRoutes = function(obj) {
|
|
45
|
+
return [{
|
|
46
|
+
verb: "POST",
|
|
47
|
+
path: obj.name ? "/" + obj.name : ""
|
|
48
|
+
}];
|
|
49
|
+
};
|
|
50
|
+
JsonRpcAdapter.errorHandler = function() {
|
|
51
|
+
return function restErrorHandler(err, req, res, next) {
|
|
52
|
+
if (typeof err === "string") {
|
|
53
|
+
err = new Error(err);
|
|
54
|
+
err.status = err.statusCode = 500;
|
|
55
|
+
}
|
|
56
|
+
res.statusCode = err.statusCode || err.status || 500;
|
|
57
|
+
debug("Error in %s %s: %s", req.method, req.url, err.stack);
|
|
58
|
+
const data = {
|
|
59
|
+
name: err.name,
|
|
60
|
+
status: res.statusCode,
|
|
61
|
+
message: err.message || g.f("An unknown error occurred")
|
|
62
|
+
};
|
|
63
|
+
for (const prop in err) data[prop] = err[prop];
|
|
64
|
+
data.stack = err.stack;
|
|
65
|
+
res.send({
|
|
66
|
+
jsonrpc: "2.0",
|
|
67
|
+
error: {
|
|
68
|
+
code: -32e3,
|
|
69
|
+
message: g.f("Server error"),
|
|
70
|
+
data
|
|
71
|
+
},
|
|
72
|
+
id: null
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const mockWrapper = [
|
|
77
|
+
"function mockWrapper(method) {",
|
|
78
|
+
" return function(__args__) {",
|
|
79
|
+
" var args = Array.prototype.slice.call(arguments);",
|
|
80
|
+
" if (method.isStatic) {",
|
|
81
|
+
" method.getFunction().apply(method.ctor, args);",
|
|
82
|
+
" } else {",
|
|
83
|
+
" method.sharedCtor.invoke(method, function(err, instance) {",
|
|
84
|
+
" method.getFunction().apply(instance, args);",
|
|
85
|
+
" });",
|
|
86
|
+
" }",
|
|
87
|
+
" };",
|
|
88
|
+
"}"
|
|
89
|
+
].join("\n");
|
|
90
|
+
/* istanbul ignore next */
|
|
91
|
+
JsonRpcAdapter.prototype.createHandler = function() {
|
|
92
|
+
const corsOptions = this.remotes.options.cors;
|
|
93
|
+
if (corsOptions !== void 0 && corsOptions !== false) throw new Error(g.f("The REST adapter no longer comes with a built-in CORS middleware, the config option %j is no longer available.See %s for more details.", "remoting.cors", "https://docs.strongloop.com/display/public/LB/Security+considerations"));
|
|
94
|
+
const root = express.Router();
|
|
95
|
+
const classes = this.remotes.classes();
|
|
96
|
+
root.use(function(req, res, next) {
|
|
97
|
+
if (requestIsJson(req)) {
|
|
98
|
+
if (getRequestHeader(req, "content-length") === "0") {
|
|
99
|
+
req._body = true;
|
|
100
|
+
req.body = {};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
next();
|
|
104
|
+
});
|
|
105
|
+
debug("remoting options: %j", this.remotes.options);
|
|
106
|
+
const jsonOptions = this.remotes.options.json || { strict: false };
|
|
107
|
+
root.use(json(jsonOptions));
|
|
108
|
+
root.use(JsonRpcAdapter.errorHandler());
|
|
109
|
+
classes.forEach(function(sc) {
|
|
110
|
+
const server = new jayson.server({}, { collect: false });
|
|
111
|
+
root.post("/" + sc.name + "/jsonrpc", new jayson.server.interfaces.middleware(server, {}));
|
|
112
|
+
sc.methods().forEach(function(method) {
|
|
113
|
+
let argsNames = "";
|
|
114
|
+
if (method.accepts) {
|
|
115
|
+
argsNames = method.accepts.map(function(item) {
|
|
116
|
+
return item.arg;
|
|
117
|
+
});
|
|
118
|
+
argsNames = argsNames.join(",");
|
|
119
|
+
} else {
|
|
120
|
+
const m = method.getFunction();
|
|
121
|
+
if (m.length > 1) {
|
|
122
|
+
const names = [];
|
|
123
|
+
for (let i = 0; i < m.length - 1; i++) names.push("param" + i);
|
|
124
|
+
argsNames = names.join(",");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
argsNames = argsNames ? argsNames + ",cb" : "cb";
|
|
128
|
+
const funcBody = mockWrapper.toString().replace("function mockWrapper(method) {", "").replace("__args__", argsNames).replace(/}$/, "");
|
|
129
|
+
const fn = new Function("method", funcBody)(method);
|
|
130
|
+
if (debug.enabled) debug("Generated function: %s", fn.toString());
|
|
131
|
+
server.method(method.name, fn);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
return root;
|
|
135
|
+
};
|
|
136
|
+
JsonRpcAdapter.prototype.allRoutes = function() {
|
|
137
|
+
const routes = [];
|
|
138
|
+
const adapter = this;
|
|
139
|
+
const classes = this.remotes.classes();
|
|
140
|
+
let currentRoot = "";
|
|
141
|
+
classes.forEach(function(sc) {
|
|
142
|
+
adapter.getRoutes(sc).forEach(function(classRoute) {
|
|
143
|
+
currentRoot = classRoute.path;
|
|
144
|
+
const methods = sc.methods();
|
|
145
|
+
const functions = [];
|
|
146
|
+
methods.forEach(function(method) {
|
|
147
|
+
if (functions.indexOf(method.fn) === -1) functions.push(method.fn);
|
|
148
|
+
else return;
|
|
149
|
+
adapter.getRoutes(method).forEach(function(route) {
|
|
150
|
+
if (method.isStatic) addRoute(route.verb, route.path, method);
|
|
151
|
+
else adapter.getRoutes(method.sharedCtor).forEach(function(sharedCtorRoute) {
|
|
152
|
+
addRoute(route.verb, sharedCtorRoute.path + route.path, method);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
return routes;
|
|
159
|
+
function addRoute(verb, path, method) {
|
|
160
|
+
if (path === "/" || path === "//") path = currentRoot;
|
|
161
|
+
else path = currentRoot + path;
|
|
162
|
+
if (path[path.length - 1] === "/") path = path.substr(0, path.length - 1);
|
|
163
|
+
path = path.replace(/\/\//g, "/");
|
|
164
|
+
routes.push({
|
|
165
|
+
verb,
|
|
166
|
+
path,
|
|
167
|
+
description: method.description,
|
|
168
|
+
notes: method.notes,
|
|
169
|
+
method: method.stringName,
|
|
170
|
+
accepts: method.accepts && method.accepts.length ? method.accepts : void 0,
|
|
171
|
+
returns: method.returns && method.returns.length ? method.returns : void 0,
|
|
172
|
+
errors: method.errors && method.errors.length ? method.errors : void 0
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
function requestIsJson(req) {
|
|
177
|
+
if (typeof req.is === "function") return req.is("application/json");
|
|
178
|
+
const contentType = getRequestHeader(req, "content-type");
|
|
179
|
+
return /^application\/json\b/i.test(contentType || "");
|
|
180
|
+
}
|
|
181
|
+
function getRequestHeader(req, name) {
|
|
182
|
+
if (typeof req.get === "function") return req.get(name);
|
|
183
|
+
return req.headers && req.headers[name.toLowerCase()];
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=jsonrpc-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc-adapter.js","names":[],"sources":["../../src/lib/jsonrpc-adapter.ts"],"sourcesContent":["// Copyright IBM Corp. 2013,2018. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst g = require('./messages');\n/*!\n * Expose `JsonRpcAdapter`.\n */\nmodule.exports = JsonRpcAdapter;\n\n/*!\n * Module dependencies.\n */\n\nconst EventEmitter = require('events').EventEmitter;\nconst debug = require('debug')('strong-remoting:jsonrpc-adapter');\nconst util = require('util');\nconst inherits = util.inherits;\nconst jayson = require('jayson');\nconst express = require('express');\nconst HttpContext = require('./http-context');\n\nconst json = express.json;\n\n/**\n * Create a new `JsonRpcAdapter` with the given `options`.\n *\n * @param {Object} options\n * @return {JsonRpcAdapter}\n */\n\nfunction JsonRpcAdapter(remotes) {\n EventEmitter.call(this);\n\n this.remotes = remotes;\n this.Context = HttpContext;\n}\n\n/**\n * Inherit from `EventEmitter`.\n */\n\ninherits(JsonRpcAdapter, EventEmitter);\n\n/*!\n * Simplified APIs\n */\n\nJsonRpcAdapter.create = JsonRpcAdapter.createJsonRpcAdapter = function (remotes) {\n // add simplified construction / sugar here\n return new JsonRpcAdapter(remotes);\n};\n\n/**\n * Get the path for the given method.\n */\n\nJsonRpcAdapter.prototype.getRoutes = function (obj) {\n // build default route\n const routes = [\n {\n verb: 'POST',\n path: obj.name ? '/' + obj.name : '',\n },\n ];\n return routes;\n};\n\nJsonRpcAdapter.errorHandler = function () {\n return function restErrorHandler(err, req, res, next) {\n if (typeof err === 'string') {\n err = new Error(err);\n err.status = err.statusCode = 500;\n }\n\n res.statusCode = err.statusCode || err.status || 500;\n\n debug('Error in %s %s: %s', req.method, req.url, err.stack);\n const data = {\n name: err.name,\n status: res.statusCode,\n message: err.message || g.f('An unknown error occurred'),\n };\n\n for (const prop in err) {\n data[prop] = err[prop];\n }\n\n // TODO(bajtos) Remove stack info when running in production\n data.stack = err.stack;\n\n res.send({\n jsonrpc: '2.0',\n error: { code: -32000, message: g.f('Server error'), data: data },\n id: null,\n });\n };\n};\n\n// A mock wrapper function to help code generation.\n// Note that we can't make it a real function and use .toString() on it because\n// that causes a whole world of trouble when we run strong-remoting's unit tests\n// with code coverage.\nconst mockWrapper = [\n 'function mockWrapper(method) {',\n ' return function(__args__) {',\n ' var args = Array.prototype.slice.call(arguments);',\n ' if (method.isStatic) {',\n ' method.getFunction().apply(method.ctor, args);',\n ' } else {',\n ' method.sharedCtor.invoke(method, function(err, instance) {',\n ' method.getFunction().apply(instance, args);',\n ' });',\n ' }',\n ' };',\n '}',\n].join('\\n');\n\n/* istanbul ignore next */\nJsonRpcAdapter.prototype.createHandler = function () {\n const corsOptions = this.remotes.options.cors;\n if (corsOptions !== undefined && corsOptions !== false) {\n throw new Error(\n g.f(\n 'The REST adapter no longer comes with a built-in CORS middleware, ' +\n 'the config option %j is no longer available.' +\n 'See %s for more details.',\n 'remoting.cors',\n 'https://docs.strongloop.com/display/public/LB/Security+considerations',\n ),\n );\n }\n\n const root = express.Router();\n const classes = this.remotes.classes();\n\n // Add a handler to tolerate empty json as connect's json middleware throws an error\n root.use(function (req, res, next) {\n if (requestIsJson(req)) {\n if (getRequestHeader(req, 'content-length') === '0') {\n // This doesn't cover the transfer-encoding: chunked\n req._body = true; // Mark it as parsed\n req.body = {};\n }\n }\n next();\n });\n\n // Set strict to be `false` so that anything `JSON.parse()` accepts will be parsed\n debug('remoting options: %j', this.remotes.options);\n const jsonOptions = this.remotes.options.json || { strict: false };\n\n root.use(json(jsonOptions));\n\n root.use(JsonRpcAdapter.errorHandler());\n\n classes.forEach(function (sc) {\n const server = new jayson.server({}, { collect: false });\n root.post('/' + sc.name + '/jsonrpc', new jayson.server.interfaces.middleware(server, {}));\n\n const methods = sc.methods();\n\n methods.forEach(function (method) {\n // Wrap the method so that it will keep its own receiver - the shared class\n let argsNames = '';\n if (method.accepts) {\n argsNames = method.accepts.map(function (item) {\n return item.arg;\n });\n argsNames = argsNames.join(',');\n } else {\n const m = method.getFunction();\n if (m.length > 1) {\n // The method has more args than cb\n // Build dummy param names\n const names = [];\n for (let i = 0; i < m.length - 1; i++) {\n names.push('param' + i);\n }\n argsNames = names.join(',');\n }\n }\n argsNames = argsNames ? argsNames + ',cb' : 'cb';\n\n // Generate the function based on the wrapper\n // We need to remove the header/footer to get the function body\n const funcBody = mockWrapper\n .toString()\n .replace('function mockWrapper(method) {', '')\n .replace('__args__', argsNames)\n .replace(/}$/, '');\n /* jslint evil: true */\n const fn = new Function('method', funcBody)(method);\n if (debug.enabled) {\n debug('Generated function: %s', fn.toString());\n }\n server.method(method.name, fn);\n });\n });\n\n return root;\n};\n\nJsonRpcAdapter.prototype.allRoutes = function () {\n const routes = [];\n const adapter = this;\n const classes = this.remotes.classes();\n let currentRoot = '';\n\n classes.forEach(function (sc) {\n adapter.getRoutes(sc).forEach(function (classRoute) {\n currentRoot = classRoute.path;\n const methods = sc.methods();\n\n const functions = [];\n methods.forEach(function (method) {\n // Use functions to keep track of JS functions to dedupe\n if (functions.indexOf(method.fn) === -1) {\n functions.push(method.fn);\n } else {\n return; // Skip duplicate methods such as X.m1 = X.m2 = function() {...}\n }\n adapter.getRoutes(method).forEach(function (route) {\n if (method.isStatic) {\n addRoute(route.verb, route.path, method);\n } else {\n adapter.getRoutes(method.sharedCtor).forEach(function (sharedCtorRoute) {\n addRoute(route.verb, sharedCtorRoute.path + route.path, method);\n });\n }\n });\n });\n });\n });\n\n return routes;\n\n function addRoute(verb, path, method) {\n if (path === '/' || path === '//') {\n path = currentRoot;\n } else {\n path = currentRoot + path;\n }\n\n if (path[path.length - 1] === '/') {\n path = path.substr(0, path.length - 1);\n }\n\n // TODO this could be cleaner\n path = path.replace(/\\/\\//g, '/');\n\n routes.push({\n verb: verb,\n path: path,\n description: method.description,\n notes: method.notes,\n method: method.stringName,\n accepts: method.accepts && method.accepts.length ? method.accepts : undefined,\n returns: method.returns && method.returns.length ? method.returns : undefined,\n errors: method.errors && method.errors.length ? method.errors : undefined,\n });\n }\n};\n\nfunction requestIsJson(req) {\n if (typeof req.is === 'function') {\n return req.is('application/json');\n }\n\n const contentType = getRequestHeader(req, 'content-type');\n return /^application\\/json\\b/i.test(contentType || '');\n}\n\nfunction getRequestHeader(req, name) {\n if (typeof req.get === 'function') {\n return req.get(name);\n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E;AAIxC,SAAO,KAAK,QAAQ,SAAS,IAAI;AAEjC,SAAO,KAAK;GACJ;GACA;GACN,aAAa,OAAO;GACpB,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,SAAS,OAAO,WAAW,OAAO,QAAQ,SAAS,OAAO,UAAU,KAAA;GACpE,SAAS,OAAO,WAAW,OAAO,QAAQ,SAAS,OAAO,UAAU,KAAA;GACpE,QAAQ,OAAO,UAAU,OAAO,OAAO,SAAS,OAAO,SAAS,KAAA;GACjE,CAAC;;;AAIN,SAAS,cAAc,KAAK;AAC1B,KAAI,OAAO,IAAI,OAAO,WACpB,QAAO,IAAI,GAAG,mBAAmB;CAGnC,MAAM,cAAc,iBAAiB,KAAK,eAAe;AACzD,QAAO,wBAAwB,KAAK,eAAe,GAAG;;AAGxD,SAAS,iBAAiB,KAAK,MAAM;AACnC,KAAI,OAAO,IAAI,QAAQ,WACrB,QAAO,IAAI,IAAI,KAAK;AAGtB,QAAO,IAAI,WAAW,IAAI,QAAQ,KAAK,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region src/lib/looks-like-json.ts
|
|
3
|
+
var require_looks_like_json = /* @__PURE__ */ require("../_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
|
|
4
|
+
module.exports = {
|
|
5
|
+
looksLikeJson,
|
|
6
|
+
looksLikeJsonArray,
|
|
7
|
+
looksLikeJsonObject
|
|
8
|
+
};
|
|
9
|
+
function looksLikeJson(value) {
|
|
10
|
+
return looksLikeJsonObject(value) || looksLikeJsonArray(value);
|
|
11
|
+
}
|
|
12
|
+
function looksLikeJsonArray(value) {
|
|
13
|
+
return typeof value === "string" && value[0] === "[" && value[value.length - 1] === "]";
|
|
14
|
+
}
|
|
15
|
+
function looksLikeJsonObject(value) {
|
|
16
|
+
return typeof value === "string" && value[0] === "{" && value[value.length - 1] === "}";
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
//#endregion
|
|
20
|
+
module.exports = require_looks_like_json();
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=looks-like-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"looks-like-json.js","names":[],"sources":["../../src/lib/looks-like-json.ts"],"sourcesContent":["// Copyright IBM Corp. 2016. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nmodule.exports = {\n looksLikeJson: looksLikeJson,\n looksLikeJsonArray: looksLikeJsonArray,\n looksLikeJsonObject: looksLikeJsonObject,\n};\n\nfunction looksLikeJson(value) {\n return looksLikeJsonObject(value) || looksLikeJsonArray(value);\n}\n\nfunction looksLikeJsonArray(value) {\n return typeof value === 'string' && value[0] === '[' && value[value.length - 1] === ']';\n}\n\nfunction looksLikeJsonObject(value) {\n return typeof value === 'string' && value[0] === '{' && value[value.length - 1] === '}';\n}\n"],"mappings":";;;AAQA,QAAO,UAAU;EACA;EACK;EACC;EACtB;CAED,SAAS,cAAc,OAAO;AAC5B,SAAO,oBAAoB,MAAM,IAAI,mBAAmB,MAAM;;CAGhE,SAAS,mBAAmB,OAAO;AACjC,SAAO,OAAO,UAAU,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM,SAAS,OAAO;;CAGtF,SAAS,oBAAoB,OAAO;AAClC,SAAO,OAAO,UAAU,YAAY,MAAM,OAAO,OAAO,MAAM,MAAM,SAAS,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region src/lib/messages.ts
|
|
3
|
+
var require_messages = /* @__PURE__ */ require("../_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
|
|
4
|
+
const util = require("util");
|
|
5
|
+
module.exports = {
|
|
6
|
+
f,
|
|
7
|
+
warn
|
|
8
|
+
};
|
|
9
|
+
function f(message) {
|
|
10
|
+
const args = Array.prototype.slice.call(arguments, 1);
|
|
11
|
+
return util.format(normalizeTemplate(message), ...args);
|
|
12
|
+
}
|
|
13
|
+
function warn(message) {
|
|
14
|
+
const args = Array.prototype.slice.call(arguments, 1);
|
|
15
|
+
console.warn(util.format(normalizeTemplate(message), ...args));
|
|
16
|
+
}
|
|
17
|
+
function normalizeTemplate(message) {
|
|
18
|
+
return String(message).replace(/\{\{([^}]+)\}\}/g, "$1");
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
//#endregion
|
|
22
|
+
module.exports = require_messages();
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../../src/lib/messages.ts"],"sourcesContent":["// Copyright IBM Corp. 2026. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\nconst util = require('util');\n\nmodule.exports = {\n f,\n warn,\n};\n\nfunction f(message) {\n const args = Array.prototype.slice.call(arguments, 1);\n return util.format(normalizeTemplate(message), ...args);\n}\n\nfunction warn(message) {\n const args = Array.prototype.slice.call(arguments, 1);\n console.warn(util.format(normalizeTemplate(message), ...args));\n}\n\nfunction normalizeTemplate(message) {\n return String(message).replace(/\\{\\{([^}]+)\\}\\}/g, '$1');\n}\n"],"mappings":";;;CAQA,MAAM,OAAO,QAAQ,OAAO;AAE5B,QAAO,UAAU;EACf;EACA;EACD;CAED,SAAS,EAAE,SAAS;EAClB,MAAM,OAAO,MAAM,UAAU,MAAM,KAAK,WAAW,EAAE;AACrD,SAAO,KAAK,OAAO,kBAAkB,QAAQ,EAAE,GAAG,KAAK;;CAGzD,SAAS,KAAK,SAAS;EACrB,MAAM,OAAO,MAAM,UAAU,MAAM,KAAK,WAAW,EAAE;AACrD,UAAQ,KAAK,KAAK,OAAO,kBAAkB,QAAQ,EAAE,GAAG,KAAK,CAAC;;CAGhE,SAAS,kBAAkB,SAAS;AAClC,SAAO,OAAO,QAAQ,CAAC,QAAQ,oBAAoB,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region src/lib/number-checks.ts
|
|
3
|
+
var require_number_checks = /* @__PURE__ */ require("../_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
|
|
4
|
+
const number = module.exports = {
|
|
5
|
+
MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER || 9007199254740991,
|
|
6
|
+
MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER || -9007199254740991,
|
|
7
|
+
isInteger: Number.isInteger || function(value) {
|
|
8
|
+
return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
|
|
9
|
+
},
|
|
10
|
+
isSafeInteger: Number.isSafeInteger || function(value) {
|
|
11
|
+
return number.isInteger(value) && value >= number.MIN_SAFE_INTEGER && value <= number.MAX_SAFE_INTEGER;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}));
|
|
15
|
+
//#endregion
|
|
16
|
+
module.exports = require_number_checks();
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=number-checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-checks.js","names":[],"sources":["../../src/lib/number-checks.ts"],"sourcesContent":["// Copyright IBM Corp. 2016,2017. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\n// @ts-nocheck\n'use strict';\n\n// To support Node v.0.10.x\nconst number = (module.exports = {\n MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER || 9007199254740991,\n MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER || -9007199254740991,\n isInteger:\n Number.isInteger ||\n function (value) {\n return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;\n },\n isSafeInteger:\n Number.isSafeInteger ||\n function (value) {\n return (\n number.isInteger(value) &&\n value >= number.MIN_SAFE_INTEGER &&\n value <= number.MAX_SAFE_INTEGER\n );\n },\n});\n"],"mappings":";;;CASA,MAAM,SAAU,OAAO,UAAU;EAC/B,kBAAkB,OAAO,oBAAoB;EAC7C,kBAAkB,OAAO,oBAAoB;EAC7C,WACE,OAAO,aACP,SAAU,OAAO;AACf,UAAO,OAAO,UAAU,YAAY,SAAS,MAAM,IAAI,KAAK,MAAM,MAAM,KAAK;;EAEjF,eACE,OAAO,iBACP,SAAU,OAAO;AACf,UACE,OAAO,UAAU,MAAM,IACvB,SAAS,OAAO,oBAChB,SAAS,OAAO;;EAGvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-phase-name-lists.d.ts","names":[],"sources":["../../../src/lib/phases/merge-phase-name-lists.ts"],"mappings":";iBAOgB,mBAAA,CAAoB,YAAA,YAAwB,YAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_lib_messages = require("../messages.js");
|
|
4
|
+
//#region src/lib/phases/merge-phase-name-lists.ts
|
|
5
|
+
function mergePhaseNameLists(currentNames, namesToMerge) {
|
|
6
|
+
if (!namesToMerge.length) return currentNames.slice();
|
|
7
|
+
const targetArray = currentNames.slice();
|
|
8
|
+
let targetIndex = targetArray.indexOf(namesToMerge[0]);
|
|
9
|
+
if (targetIndex === -1) {
|
|
10
|
+
targetArray.splice(0, 0, namesToMerge[0]);
|
|
11
|
+
targetIndex = 0;
|
|
12
|
+
}
|
|
13
|
+
for (let sourceIndex = 1; sourceIndex < namesToMerge.length; sourceIndex += 1) {
|
|
14
|
+
const valueToAdd = namesToMerge[sourceIndex];
|
|
15
|
+
const previousValue = namesToMerge[sourceIndex - 1];
|
|
16
|
+
const existingIndex = targetArray.indexOf(valueToAdd, targetIndex);
|
|
17
|
+
if (existingIndex === -1) {
|
|
18
|
+
if (targetArray.indexOf(valueToAdd) !== -1) throw new Error(f("Ordering conflict: cannot add \"%s\" after \"%s\", because the opposite order was already specified", valueToAdd, previousValue));
|
|
19
|
+
const previousIndex = targetArray.indexOf(previousValue);
|
|
20
|
+
targetArray.splice(previousIndex + 1, 0, valueToAdd);
|
|
21
|
+
} else targetIndex = existingIndex;
|
|
22
|
+
}
|
|
23
|
+
return targetArray;
|
|
24
|
+
}
|
|
25
|
+
var f;
|
|
26
|
+
var init_merge_phase_name_lists = require_runtime.__esmMin((() => {
|
|
27
|
+
({f} = require_lib_messages);
|
|
28
|
+
}));
|
|
29
|
+
//#endregion
|
|
30
|
+
init_merge_phase_name_lists();
|
|
31
|
+
Object.defineProperty(exports, "init_merge_phase_name_lists", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return init_merge_phase_name_lists;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.mergePhaseNameLists = mergePhaseNameLists;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=merge-phase-name-lists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-phase-name-lists.js","names":[],"sources":["../../../src/lib/phases/merge-phase-name-lists.ts"],"sourcesContent":["// Copyright IBM Corp. 2026. All Rights Reserved.\n// Node module: strong-remoting\n// This file is licensed under the Artistic License 2.0.\n// License text available at https://opensource.org/licenses/Artistic-2.0\n\nconst { f } = require('../messages');\n\nexport function mergePhaseNameLists(currentNames: string[], namesToMerge: string[]) {\n if (!namesToMerge.length) {\n return currentNames.slice();\n }\n\n const targetArray = currentNames.slice();\n let targetIndex = targetArray.indexOf(namesToMerge[0]);\n\n if (targetIndex === -1) {\n targetArray.splice(0, 0, namesToMerge[0]);\n targetIndex = 0;\n }\n\n for (let sourceIndex = 1; sourceIndex < namesToMerge.length; sourceIndex += 1) {\n const valueToAdd = namesToMerge[sourceIndex];\n const previousValue = namesToMerge[sourceIndex - 1];\n const existingIndex = targetArray.indexOf(valueToAdd, targetIndex);\n\n if (existingIndex === -1) {\n if (targetArray.indexOf(valueToAdd) !== -1) {\n throw new Error(\n f(\n 'Ordering conflict: cannot add \"%s\" after \"%s\", because the opposite order was already specified',\n valueToAdd,\n previousValue,\n ),\n );\n }\n\n const previousIndex = targetArray.indexOf(previousValue);\n targetArray.splice(previousIndex + 1, 0, valueToAdd);\n } else {\n targetIndex = existingIndex;\n }\n }\n\n return targetArray;\n}\n"],"mappings":";;;;AAOA,SAAgB,oBAAoB,cAAwB,cAAwB;AAClF,KAAI,CAAC,aAAa,OAChB,QAAO,aAAa,OAAO;CAG7B,MAAM,cAAc,aAAa,OAAO;CACxC,IAAI,cAAc,YAAY,QAAQ,aAAa,GAAG;AAEtD,KAAI,gBAAgB,IAAI;AACtB,cAAY,OAAO,GAAG,GAAG,aAAa,GAAG;AACzC,gBAAc;;AAGhB,MAAK,IAAI,cAAc,GAAG,cAAc,aAAa,QAAQ,eAAe,GAAG;EAC7E,MAAM,aAAa,aAAa;EAChC,MAAM,gBAAgB,aAAa,cAAc;EACjD,MAAM,gBAAgB,YAAY,QAAQ,YAAY,YAAY;AAElE,MAAI,kBAAkB,IAAI;AACxB,OAAI,YAAY,QAAQ,WAAW,KAAK,GACtC,OAAM,IAAI,MACR,EACE,uGACA,YACA,cACD,CACF;GAGH,MAAM,gBAAgB,YAAY,QAAQ,cAAc;AACxD,eAAY,OAAO,gBAAgB,GAAG,GAAG,WAAW;QAEpD,eAAc;;AAIlB,QAAO;;;;GAtCD,KAAA"}
|