meadow 2.0.44 → 2.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow",
3
- "version": "2.0.44",
3
+ "version": "2.0.45",
4
4
  "description": "A data access library.",
5
5
  "main": "source/Meadow.js",
6
6
  "scripts": {
@@ -87,7 +87,7 @@
87
87
  "devDependencies": {
88
88
  "alasql": "^4.17.0",
89
89
  "dgraph-js-http": "^21.3.0",
90
- "fable": "^3.1.76",
90
+ "fable": "^3.1.77",
91
91
  "gulp-util": "^3.0.8",
92
92
  "meadow-connection-dgraph": "^1.0.3",
93
93
  "meadow-connection-mongodb": "^1.0.3",
@@ -56,7 +56,14 @@ var MeadowProvider = function()
56
56
  var buildURL = function(pAddress)
57
57
  {
58
58
  let tmpEndpointSettings = getEndpointSettings();
59
- return `${tmpEndpointSettings.ServerProtocol}://${tmpEndpointSettings.ServerAddress}:${tmpEndpointSettings.ServerPort}/${tmpEndpointSettings.ServerEndpointPrefix}${pAddress}`;
59
+ let tmpURL = `${tmpEndpointSettings.ServerProtocol}://${tmpEndpointSettings.ServerAddress}:${tmpEndpointSettings.ServerPort}/${tmpEndpointSettings.ServerEndpointPrefix}${pAddress}`;
60
+ // e.g. 'skipDecoration=true' — lets machine-to-machine connections
61
+ // opt out of per-row presentation decoration the remote applies.
62
+ if (typeof(tmpEndpointSettings.AdditionalQueryString) === 'string' && tmpEndpointSettings.AdditionalQueryString.length > 0)
63
+ {
64
+ tmpURL += (tmpURL.indexOf('?') >= 0) ? `&${tmpEndpointSettings.AdditionalQueryString}` : `?${tmpEndpointSettings.AdditionalQueryString}`;
65
+ }
66
+ return tmpURL;
60
67
  };
61
68
 
62
69
  var buildRequestOptions = function(pQuery)
@@ -75,10 +82,19 @@ var MeadowProvider = function()
75
82
  let tmpCookies = (tmpInstance && Array.isArray(tmpInstance.cookies))
76
83
  ? tmpInstance.cookies : [];
77
84
 
85
+ // Explicit timeout: Node 20+ installs a ~5s socket timeout on
86
+ // http.globalAgent; an explicit request timeout takes that default
87
+ // out of play (same workaround as fable's RestClient). Configurable
88
+ // per connection (settings.RequestTimeout) for slow decorated reads.
89
+ let tmpEndpointSettings = getEndpointSettings();
90
+ let tmpRequestTimeout = (typeof(tmpEndpointSettings.RequestTimeout) === 'number')
91
+ ? tmpEndpointSettings.RequestTimeout : 60000;
92
+
78
93
  let tmpRequestOptions = (
79
94
  {
80
95
  url: tmpURL,
81
- headers: _Fable.Utility.extend({cookie: ''}, tmpHeaders)
96
+ headers: _Fable.Utility.extend({cookie: ''}, tmpHeaders),
97
+ timeout: tmpRequestTimeout
82
98
  });
83
99
 
84
100
  tmpRequestOptions.headers.cookie = tmpCookies.join(';');
@@ -121,3 +121,78 @@ suite('MeadowEndpoints provider instance-driven configuration', function ()
121
121
  Expect(Array.isArray(tmpOutcome.Records)).to.equal(true);
122
122
  });
123
123
  });
124
+
125
+ suite('MeadowEndpoints provider request timeout', function ()
126
+ {
127
+ suiteSetup(async function () { await startStubAPI(); });
128
+ suiteTeardown(function () { if (_Server) { _Server.close(); } });
129
+
130
+ test('an explicit request timeout is always set (Node 20+ globalAgent ~5s default workaround)', function (fDone)
131
+ {
132
+ // Intercept the socket-level options by reading from a slow-but-fine
133
+ // stub: the request must carry a timeout >= the configured value, so
134
+ // the platform default never applies.
135
+ const libHTTP = require('http');
136
+ const tmpOriginalRequest = libHTTP.request;
137
+ let tmpCapturedOptions = null;
138
+ libHTTP.request = function (pOptions, fResponseHandler)
139
+ {
140
+ tmpCapturedOptions = pOptions;
141
+ return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
142
+ };
143
+ const tmpDAL = buildDAL(null, serverSettings());
144
+ readAnimals(tmpDAL).then((pOutcome) =>
145
+ {
146
+ libHTTP.request = tmpOriginalRequest;
147
+ Expect(tmpCapturedOptions).to.be.an('object');
148
+ Expect(tmpCapturedOptions.timeout).to.equal(60000, 'default 60s');
149
+ fDone();
150
+ }).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
151
+ });
152
+
153
+ test('the connection settings RequestTimeout overrides the default', function (fDone)
154
+ {
155
+ const libHTTP = require('http');
156
+ const tmpOriginalRequest = libHTTP.request;
157
+ let tmpCapturedOptions = null;
158
+ libHTTP.request = function (pOptions, fResponseHandler)
159
+ {
160
+ tmpCapturedOptions = pOptions;
161
+ return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
162
+ };
163
+ const tmpSettings = Object.assign(serverSettings(), { RequestTimeout: 120000 });
164
+ const tmpDAL = buildDAL(null, tmpSettings);
165
+ readAnimals(tmpDAL).then(() =>
166
+ {
167
+ libHTTP.request = tmpOriginalRequest;
168
+ Expect(tmpCapturedOptions.timeout).to.equal(120000);
169
+ fDone();
170
+ }).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
171
+ });
172
+ });
173
+
174
+ suite('MeadowEndpoints provider additional query string', function ()
175
+ {
176
+ suiteSetup(async function () { await startStubAPI(); });
177
+ suiteTeardown(function () { if (_Server) { _Server.close(); } });
178
+
179
+ test('AdditionalQueryString is appended to read URLs (e.g. skipDecoration=true)', function (fDone)
180
+ {
181
+ const libHTTP = require('http');
182
+ const tmpOriginalRequest = libHTTP.request;
183
+ let tmpCapturedPath = null;
184
+ libHTTP.request = function (pOptions, fResponseHandler)
185
+ {
186
+ tmpCapturedPath = pOptions.path;
187
+ return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
188
+ };
189
+ const tmpSettings = Object.assign(serverSettings(), { AdditionalQueryString: 'skipDecoration=true' });
190
+ const tmpDAL = buildDAL(null, tmpSettings);
191
+ readAnimals(tmpDAL).then(() =>
192
+ {
193
+ libHTTP.request = tmpOriginalRequest;
194
+ Expect(tmpCapturedPath).to.contain('?skipDecoration=true');
195
+ fDone();
196
+ }).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
197
+ });
198
+ });