stacks 0.0.9 → 0.37.3

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.
Files changed (219) hide show
  1. package/.gitignore +10 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +65 -104
  4. package/auto-imports.d.ts +826 -0
  5. package/bin/stacks.mjs +4 -0
  6. package/components.d.ts +22 -0
  7. package/core/actions/README.md +59 -0
  8. package/core/actions/node_modules/.bin/markdown-it +17 -0
  9. package/core/actions/node_modules/.bin/mkdist +17 -0
  10. package/core/actions/node_modules/.bin/tsc +17 -0
  11. package/core/actions/node_modules/.bin/tsserver +17 -0
  12. package/core/actions/package.json +64 -0
  13. package/core/actions/src/copy-types.ts +22 -0
  14. package/core/actions/src/generate/component-meta.ts +94 -0
  15. package/core/actions/src/generate/index.ts +4 -0
  16. package/core/actions/src/generate/lib-entries.ts +106 -0
  17. package/core/actions/src/generate/package-json.ts +87 -0
  18. package/core/actions/src/generate/vscode-custom-data.ts +28 -0
  19. package/core/actions/src/generate/vue-compat.ts +17 -0
  20. package/core/actions/src/generate-component-meta.ts +19 -0
  21. package/core/actions/src/generate-ide-helpers.ts +23 -0
  22. package/core/actions/src/generate-lib-entries.ts +22 -0
  23. package/core/actions/src/generate-package-json.ts +15 -0
  24. package/core/actions/src/generate-vscode-custom-data.ts +20 -0
  25. package/core/actions/src/generate-vue-compat.ts +10 -0
  26. package/core/arrays/README.md +59 -0
  27. package/core/arrays/node_modules/.bin/mkdist +17 -0
  28. package/core/arrays/node_modules/.bin/tsc +17 -0
  29. package/core/arrays/node_modules/.bin/tsserver +17 -0
  30. package/core/arrays/package.json +50 -0
  31. package/core/arrays/src/index.ts +3 -0
  32. package/core/build/README.md +59 -0
  33. package/core/build/entries/README.md +7 -0
  34. package/core/build/node_modules/.bin/acorn +17 -0
  35. package/core/build/node_modules/.bin/browserslist +17 -0
  36. package/core/build/node_modules/.bin/jiti +17 -0
  37. package/core/build/node_modules/.bin/mkdist +17 -0
  38. package/core/build/node_modules/.bin/rollup +17 -0
  39. package/core/build/node_modules/.bin/vite +17 -0
  40. package/core/build/node_modules/.bin/vite-ssg +17 -0
  41. package/core/build/node_modules/.bin/vue-docgen-web-types +17 -0
  42. package/core/build/package.json +71 -0
  43. package/core/build/src/example-vue.ts +26 -0
  44. package/core/build/src/example-wc.ts +26 -0
  45. package/core/build/src/functions.ts +56 -0
  46. package/core/build/src/index.ts +7 -0
  47. package/core/build/src/pages.ts +50 -0
  48. package/core/build/src/stacks.ts +204 -0
  49. package/core/build/src/vue-components.ts +76 -0
  50. package/core/build/src/web-components.ts +63 -0
  51. package/core/build/web-types.config.cjs +4 -0
  52. package/core/build/web-types.ts +14 -0
  53. package/core/collections/README.md +59 -0
  54. package/core/collections/node_modules/.bin/mkdist +17 -0
  55. package/core/collections/node_modules/.bin/tsc +17 -0
  56. package/core/collections/node_modules/.bin/tsserver +17 -0
  57. package/core/collections/package.json +54 -0
  58. package/core/collections/src/index.ts +1 -0
  59. package/core/fs/README.md +59 -0
  60. package/core/fs/node_modules/.bin/mkdist +17 -0
  61. package/core/fs/package.json +56 -0
  62. package/core/fs/src/index.ts +170 -0
  63. package/core/helpers/node_modules/.bin/mkdist +17 -0
  64. package/core/helpers/package.json +58 -0
  65. package/core/helpers/src/index.ts +129 -0
  66. package/core/modules/README.md +61 -0
  67. package/core/modules/node_modules/.bin/acorn +17 -0
  68. package/core/modules/node_modules/.bin/mkdist +17 -0
  69. package/core/modules/package.json +51 -0
  70. package/core/modules/src/i18n.ts +23 -0
  71. package/core/modules/src/nprogress.ts +12 -0
  72. package/core/modules/src/pwa.ts +12 -0
  73. package/core/objects/README.md +59 -0
  74. package/core/objects/node_modules/.bin/mkdist +17 -0
  75. package/core/objects/node_modules/.bin/tsc +17 -0
  76. package/core/objects/node_modules/.bin/tsserver +17 -0
  77. package/core/objects/package.json +51 -0
  78. package/core/objects/src/index.ts +1 -0
  79. package/core/paths/node_modules/.bin/mkdist +17 -0
  80. package/core/paths/node_modules/.bin/tsc +17 -0
  81. package/core/paths/node_modules/.bin/tsserver +17 -0
  82. package/core/paths/package.json +51 -0
  83. package/core/paths/src/index.ts +178 -0
  84. package/core/router/README.md +59 -0
  85. package/core/router/node_modules/.bin/mkdist +17 -0
  86. package/core/router/package.json +51 -0
  87. package/core/router/src/index.ts +14 -0
  88. package/core/security/README.md +59 -0
  89. package/core/security/node_modules/.bin/mkdist +17 -0
  90. package/core/security/package.json +56 -0
  91. package/core/security/src/crypt.ts +14 -0
  92. package/core/security/src/hash.ts +52 -0
  93. package/core/security/src/index.ts +3 -0
  94. package/core/security/src/key.ts +11 -0
  95. package/core/strings/README.md +59 -0
  96. package/core/strings/node_modules/.bin/mkdist +17 -0
  97. package/core/strings/node_modules/.bin/tsc +17 -0
  98. package/core/strings/node_modules/.bin/tsserver +17 -0
  99. package/core/strings/package.json +63 -0
  100. package/core/strings/src/index.ts +14 -0
  101. package/core/types/README.md +59 -0
  102. package/core/types/node_modules/.bin/markdown-it +17 -0
  103. package/core/types/node_modules/.bin/mkdist +17 -0
  104. package/core/types/node_modules/.bin/vite +17 -0
  105. package/core/types/node_modules/.bin/vitepress +17 -0
  106. package/core/types/package.json +60 -0
  107. package/core/types/src/app.ts +131 -0
  108. package/core/types/src/auto-imports.ts +3 -0
  109. package/core/types/src/build.ts +3 -0
  110. package/core/types/src/cli.ts +49 -0
  111. package/core/types/src/components.ts +66 -0
  112. package/core/types/src/deploy.ts +11 -0
  113. package/core/types/src/docs.ts +3 -0
  114. package/core/types/src/exit-code.ts +10 -0
  115. package/core/types/src/fs.ts +17 -0
  116. package/core/types/src/git.ts +131 -0
  117. package/core/types/src/hashing.ts +107 -0
  118. package/core/types/src/i18n.ts +19 -0
  119. package/core/types/src/index.ts +21 -0
  120. package/core/types/src/inspect.ts +10 -0
  121. package/core/types/src/layout.ts +8 -0
  122. package/core/types/src/library.ts +148 -0
  123. package/core/types/src/manifest.ts +9 -0
  124. package/core/types/src/markdown.ts +198 -0
  125. package/core/types/src/pages.ts +8 -0
  126. package/core/types/src/pwa.ts +8 -0
  127. package/core/types/src/ssg.ts +3 -0
  128. package/core/types/src/ui.ts +141 -0
  129. package/core/ui/README.md +60 -0
  130. package/core/ui/node_modules/.bin/mkdist +17 -0
  131. package/core/ui/node_modules/.bin/tsc +17 -0
  132. package/core/ui/node_modules/.bin/tsserver +17 -0
  133. package/core/ui/node_modules/.bin/vite +17 -0
  134. package/core/ui/node_modules/.bin/vue-tsc +17 -0
  135. package/core/ui/package.json +62 -0
  136. package/core/ui/src/index.ts +60 -0
  137. package/custom-elements.json +14 -0
  138. package/examples/vue-components/App.vue +12 -0
  139. package/examples/vue-components/favicon.png +0 -0
  140. package/examples/vue-components/index.html +20 -0
  141. package/examples/web-components/favicon.png +0 -0
  142. package/examples/web-components/index.html +13 -0
  143. package/functions/node_modules/.bin/artisan +17 -0
  144. package/functions/node_modules/.bin/stacks +17 -0
  145. package/functions/node_modules/.bin/stx +17 -0
  146. package/functions/package.json +40 -0
  147. package/netlify.toml +18 -0
  148. package/nitro.config.ts +6 -0
  149. package/package.json +224 -27
  150. package/pages/App.vue +26 -0
  151. package/pages/index.html +23 -0
  152. package/pages/main.ts +26 -0
  153. package/pages/public/_headers +3 -0
  154. package/pages/public/favicon-dark.svg +3 -0
  155. package/pages/public/favicon.svg +3 -0
  156. package/pages/public/pwa-192x192.png +0 -0
  157. package/pages/public/pwa-512x512.png +0 -0
  158. package/pages/public/safari-pinned-tab.svg +41 -0
  159. package/pages/styles/main.css +29 -0
  160. package/pages/styles/markdown.css +28 -0
  161. package/scripts/ensure-env.sh +248 -0
  162. package/shims.d.ts +29 -0
  163. package/simple-git-hooks.cjs +4 -0
  164. package/src/cli/actions/build.ts +160 -0
  165. package/src/cli/actions/commit.ts +9 -0
  166. package/src/cli/actions/dev.ts +47 -0
  167. package/src/cli/actions/examples.ts +74 -0
  168. package/src/cli/actions/fresh.ts +9 -0
  169. package/src/cli/actions/generate.ts +159 -0
  170. package/src/cli/actions/index.ts +12 -0
  171. package/src/cli/actions/key.ts +31 -0
  172. package/src/cli/actions/lint.ts +19 -0
  173. package/src/cli/actions/make.ts +116 -0
  174. package/src/cli/actions/release.ts +9 -0
  175. package/src/cli/actions/test.ts +39 -0
  176. package/src/cli/actions/types.ts +180 -0
  177. package/src/cli/actions/update.ts +90 -0
  178. package/src/cli/build.ts +49 -0
  179. package/src/cli/create.ts +71 -0
  180. package/src/cli/dev.ts +28 -0
  181. package/src/cli/example.ts +28 -0
  182. package/src/cli/generate.ts +64 -0
  183. package/src/cli/index.ts +13 -0
  184. package/src/cli/key.ts +12 -0
  185. package/src/cli/make.ts +47 -0
  186. package/src/cli/test.ts +24 -0
  187. package/src/cli/types.ts +18 -0
  188. package/src/cli/update.ts +17 -0
  189. package/src/cli/utility.ts +39 -0
  190. package/src/cli.ts +48 -0
  191. package/src/docs.ts +4 -0
  192. package/src/index.ts +22 -0
  193. package/tsconfig.json +96 -0
  194. package/vitest.config.ts +22 -0
  195. package/vue-components/dist/.gitkeep +0 -0
  196. package/vue-components/index.html +13 -0
  197. package/vue-components/main.ts +18 -0
  198. package/vue-components/node_modules/.bin/artisan +17 -0
  199. package/vue-components/node_modules/.bin/stacks +17 -0
  200. package/vue-components/node_modules/.bin/stx +17 -0
  201. package/vue-components/node_modules/.vite/deps/@vueuse_core.js +7847 -0
  202. package/vue-components/node_modules/.vite/deps/@vueuse_core.js.map +7 -0
  203. package/vue-components/node_modules/.vite/deps/_metadata.json +13 -0
  204. package/vue-components/node_modules/.vite/deps/package.json +1 -0
  205. package/vue-components/package.json +40 -0
  206. package/web-components/dist/.gitkeep +0 -0
  207. package/web-components/node_modules/.bin/artisan +17 -0
  208. package/web-components/node_modules/.bin/stacks +17 -0
  209. package/web-components/node_modules/.bin/stx +17 -0
  210. package/web-components/package.json +40 -0
  211. package/web-types.json +67 -0
  212. package/.npmignore +0 -1
  213. package/.travis.yml +0 -4
  214. package/examples/stringReverse.js +0 -41
  215. package/examples/sumServer.js +0 -21
  216. package/examples/sumWorker.js +0 -23
  217. package/index.js +0 -1
  218. package/lib/stacks.js +0 -398
  219. package/test/test.stacks.js +0 -148
package/lib/stacks.js DELETED
@@ -1,398 +0,0 @@
1
- var debug = require('debug')('stacks'),
2
- net = require('net'),
3
- actorify = require('actorify'),
4
- async = require('async');
5
-
6
- module.exports = (function stacks() {
7
- /**
8
- * stacks can either be a server or a client
9
- */
10
- this.server = null,
11
- this.client = null;
12
-
13
- debug('stacks init');
14
-
15
- /**
16
- * create a stacks server to listen for client connections
17
- *
18
- * @api public
19
- * @param <Number> port
20
- * @param <Function> callback
21
- */
22
- this.listen = function listen(port, callback) {
23
- debug('stacks.listen');
24
-
25
- if (! this.server) {
26
- this.server = new StacksServer();
27
- this.server.listen(port, callback);
28
- } else {
29
- console.error(new Error('listen() has already been called on this stacks.'));
30
- }
31
- };
32
-
33
- /**
34
- * make a request to stacks
35
- *
36
- * @api public
37
- * @param <String> type
38
- * @param <Mixed> body
39
- * @param <Object> options
40
- * @param <Function> callback
41
- */
42
- this.request = function request(type, body, options, callback) {
43
- debug('stacks.request');
44
-
45
- if (this.server) {
46
- this.server.request(type, body, options, callback);
47
- } else {
48
- console.error(new Error('This stacks instance is not a server, and cannot make requests'));
49
- }
50
- };
51
-
52
- /**
53
- * create a stacks client to connect to a stacks server
54
- *
55
- * @api public
56
- * @param <Mixed> server
57
- * @param <Function> callback
58
- */
59
- this.connect = function connect(server, callback) {
60
- debug('stacks.connect');
61
-
62
- if (! this.client) {
63
- this.client = new StacksClient();
64
- this.client.connect(server, callback);
65
- } else {
66
- console.error(new Error('connect() has already been called on this stacks'));
67
- }
68
-
69
- this.disconnect = this.client.disconnect;
70
- };
71
-
72
- return this;
73
- })();
74
-
75
- /**
76
- * stacks client object prototype
77
- *
78
- * @api private
79
- */
80
- function StacksClient() {
81
- var _actor = null,
82
- _connection = null,
83
- _queues = {},
84
- client = {};
85
-
86
- debug('new instance of StacksClient');
87
-
88
- /**
89
- * connect to server
90
- *
91
- * @api public
92
- * @param <Mixed> server
93
- * @param <Function> callback
94
- */
95
- this.connect = function connect(server, callback) {
96
- debug('stacks client connect...');
97
-
98
- _connection = net.connect(server, function() {
99
- debug('stacks client connected to stacks server');
100
-
101
- _actor = actorify(_connection);
102
-
103
- /**
104
- * handle stacks request of type |type| with worker |worker|
105
- * allow |concurrency| concurrent workers
106
- *
107
- * @api public
108
- * @param <String> type
109
- * @param <Function> worker
110
- * @param <Number> concurrency
111
- */
112
- client.on = function on(type, worker, concurrency) {
113
- debug('create queue for requests of type: ', type);
114
-
115
- _queues[type] = async.queue(worker, concurrency);
116
-
117
- _actor.on(type, function(body, reply) {
118
- debug('received stacks request of type %s; with body: ', type, body);
119
-
120
- _queues[type].push(body, reply);
121
- });
122
- };
123
-
124
- /**
125
- * debug messages for socket events
126
- */
127
- _connection.on('error', function(error) {
128
- debug('socket error: ', error);
129
- });
130
- _connection.on('end', function() {
131
- debug('socket end');
132
- });
133
- _connection.on('close', function() {
134
- debug('socket close');
135
- });
136
- _connection.on('timeout', function() {
137
- debug('socket timeout');
138
- });
139
-
140
- callback(client);
141
- });
142
- };
143
-
144
- /**
145
- * disconnect stacks client
146
- *
147
- * @api public
148
- */
149
- this.disconnect = function disconnect() {
150
- _connection.end();
151
- delete this.client;
152
- };
153
- };
154
-
155
- /**
156
- * stacks server object prototype
157
- *
158
- * @api private
159
- */
160
- function StacksServer() {
161
- var _backupStacks = [],
162
- _clients = {},
163
- _requestNumber = 0;
164
-
165
- debug('new instance of StacksServer');
166
-
167
- /**
168
- * server connection listener
169
- * Note: bind to this in order for this.request to function
170
- *
171
- * @api private
172
- * @param <Socket> sock
173
- */
174
- this._connectionListener = function _connectionListener(sock) {
175
- var actor = actorify(sock),
176
- clientKey = actor.id,
177
- _handleSocketClose;
178
-
179
- debug('client with key %s has connected', clientKey);
180
- debug('actor', actor);
181
-
182
- /**
183
- * handle socket close
184
- * Note: bind to this in order for this.request to function
185
- */
186
- _handleSocketClose = function _handleSocketClose() {
187
- var removedClient = _clients[clientKey];
188
- debug('client with key %s has disconnected', clientKey);
189
-
190
- delete _clients[clientKey];
191
- debug('deleted client with key %s', clientKey);
192
-
193
- /**
194
- * request (again) any pending requests on disconnected client
195
- */
196
- for (requestNumber in removedClient.pendingRequests) {
197
- debug('request request number %s again', requestNumber);
198
-
199
- var thisRequest = removedClient.pendingRequests[requestNumber];
200
- this.request(thisRequest.type, thisRequest.body, thisRequest.callback);
201
- }
202
-
203
- }.bind(this);
204
-
205
- /**
206
- * on sock 'error' or 'close', handle socket close
207
- */
208
- sock.on('error', function(error) {
209
- console.error('error: ', error);
210
- return _handleSocketClose;
211
- });
212
- sock.on('close', _handleSocketClose);
213
-
214
- /**
215
- * add new client
216
- */
217
- _clients[clientKey] = {
218
- actor: actor,
219
- pendingRequests: {}
220
- };
221
-
222
- /**
223
- * request any requests from backup stacks
224
- */
225
- for (i in _backupStacks) {
226
- var thisRequest = _backupStacks[i];
227
-
228
- debug('request %s request from backup stacks', thisRequest.type);
229
-
230
- this.request(thisRequest.type, thisRequest.body, thisRequest.callback);
231
-
232
- delete _backupStacks[i];
233
- }
234
- }.bind(this);
235
-
236
- /**
237
- * listen for client connections
238
- *
239
- * @api private
240
- * @param <Number> port
241
- * @param <Function> callback
242
- */
243
- this.listen = function listen(port, callback) {
244
- var server;
245
-
246
- debug('stacks server listen...');
247
-
248
- if (typeof callback != 'function') {
249
- callback = function() {};
250
- }
251
-
252
- server = net.createServer(this._connectionListener);
253
-
254
- server.listen(port, function() {
255
- debug('stacks server listening on port ', port);
256
-
257
- callback();
258
- });
259
-
260
- };
261
-
262
- /**
263
- * get the key (actor.id) of the next client to request
264
- * uses round-robin distribution
265
- *
266
- * @api private
267
- */
268
- _getNextClientKey = function _getNextClientKey() {
269
- var clientKeys = Object.keys(_clients);
270
- clientCount = clientKeys.length,
271
- nextClientKey = clientKeys[_requestNumber % clientCount];
272
-
273
- debug('get next client key. nextClientKey: ', nextClientKey);
274
-
275
- return nextClientKey;
276
- };
277
-
278
- /**
279
- * get a client by key (actor.id)
280
- *
281
- * @api private
282
- * @param key
283
- */
284
- _client = function _client(key) {
285
-
286
- /**
287
- * send a request to this client,
288
- * add it to this client's pending requests,
289
- * when it calls back, remove it from this client's pending requests
290
- * call back with error & response body
291
- */
292
- this.clientRequest = function clientRequest(type, body, options, callback) {
293
- debug('client request. _requestNumber: ', options._requestNumber);
294
-
295
- _clients[key].pendingRequests[options._requestNumber] = {
296
- type: type,
297
- body: body,
298
- callback: callback
299
- };
300
-
301
- _clients[key].actor.send(type, body, function(error, response) {
302
- debug('client request finished. _requestNumber: ', options._requestNumber);
303
-
304
- delete _clients[key].pendingRequests[options._requestNumber];
305
-
306
- debug('client with key %s\'s pendingRequests: ', key, _clients[key].pendingRequests);
307
-
308
- callback(error, response);
309
- });
310
- };
311
-
312
- return this;
313
- };
314
-
315
- /**
316
- * make a request to stacks
317
- *
318
- * @api public
319
- * @param <String> type
320
- * @param <Mixed> body
321
- * @param <Object> options
322
- * @param <Function> callback
323
- */
324
- this.request = function request(type, body, options, callback) {
325
- debug('stacks.server.request');
326
-
327
- /**
328
- * handle options
329
- * if typeof options is function, no options were passed
330
- */
331
- if (typeof options === 'function') {
332
- callback = options;
333
- options = {};
334
- }
335
-
336
- /**
337
- * handle options.maxRetries
338
- * if undefined, default to 3
339
- */
340
- if (typeof options.maxRetries === 'undefined') {
341
- options.maxRetries = 3;
342
- }
343
-
344
- /**
345
- * handle options._retrySequence
346
- * if undefined, default to 0
347
- */
348
- if (typeof options._retrySequence === 'undefined') {
349
- options._retrySequence = 0;
350
- }
351
-
352
- /**
353
- * set this request's options._requestNumber; increment _requestNumber
354
- */
355
- options._requestNumber = _requestNumber++;
356
-
357
- /**
358
- * if no clients are connected, add request to backup stacks and return
359
- */
360
- if (Object.keys(_clients).length < 1) {
361
- debug('no clients connected, backing up request');
362
-
363
- _backupStacks.push({
364
- type: type,
365
- body: body,
366
- callback: callback
367
- });
368
- return;
369
- }
370
-
371
- /**
372
- * if options._retrySequence++ >= options.maxRetries,
373
- * request
374
- * else
375
- * callback with new error
376
- */
377
- if (options._retrySequence++ <= options.maxRetries) {
378
- _client(_getNextClientKey()).clientRequest(type, body, options, function(error, response) {
379
- debug('request finished. _requestNumber: ', options._requestNumber);
380
-
381
- if (error) {
382
- debug('request with _requestNumber %s resulted in error: ', options._requestNumber, error);
383
-
384
- this.request(type, body, options, callback);
385
- } else {
386
- debug('request with _requestNumber %s had response: ', options._requestNumber, response);
387
-
388
- callback(error, response);
389
- }
390
- });
391
- } else {
392
- callback(new Error(type +' request failed after max retry attempts'), null);
393
- }
394
-
395
- };
396
-
397
-
398
- };
@@ -1,148 +0,0 @@
1
- var stacks = require('..'),
2
- assert = require('assert');
3
-
4
- describe('Stacks', function() {
5
- describe('#listen()', function() {
6
- it('should listen', function(done) {
7
- stacks.listen(3000, done);
8
- });
9
- it('should enable stacks.request', function() {
10
- stacks.request('echo', 'echo this', function(error, string) {});
11
- });
12
- it('should accept stacks clients', function(done) {
13
- stacks.connect(3000, function(client) {
14
- stacks.disconnect();
15
- done();
16
- });
17
- });
18
- });
19
- describe('#connect()', function() {
20
- it('should connect to stacks server', function(done) {
21
- stacks.connect(3000, function(client) {
22
- stacks.disconnect();
23
- done();
24
- });
25
- });
26
- it('should set stacks.client', function() {
27
- stacks.connect(3000, function(client) {
28
- assert(typeof stacks.client != 'undefined');
29
- stacks.disconnect();
30
- });
31
- });
32
- it('should call back with client (an actor)', function(done) {
33
- stacks.connect(3000, function(client) {
34
- assert(typeof client != undefined, 'client is undefined');
35
- assert(typeof client.on === 'function', 'client has no method `on`')
36
- stacks.disconnect();
37
-
38
- done();
39
- });
40
- });
41
- });
42
- describe('Client', function() {
43
- describe('#disconnect()', function() {
44
- it('should disconnect the from stacks server without error', function() {
45
- stacks.connect(3000, function(client) {
46
- stacks.disconnect();
47
- });
48
- });
49
- it('should delete stacks.client', function() {
50
- stacks.connect(3000, function() {
51
- stacks.disconnect();
52
- assert(typeof stacks.client === 'undefined');
53
- });
54
- });
55
- });
56
- describe('#on()', function() {
57
- it('should process requests of the specified type', function(done) {
58
- stacks.connect(3000, function(client) {
59
- var echoString = 'echo this';
60
- stacks.request('echo', echoString, function(error, string) {
61
- assert(string === echoString, 'echo failed to reply with identical string');
62
-
63
- stacks.disconnect();
64
-
65
- done(error);
66
- });
67
- client.on('echo', function(string, reply) {
68
- var error = null,
69
- string = string;
70
-
71
- reply(error, string);
72
- });
73
- });
74
- });
75
- });
76
- });
77
- describe('server', function() {
78
- describe('with no connected clients', function() {
79
- it('should keep requests on backup stacks until first client connects', function(done) {
80
- assert(! stacks.client, 'stacks already had a client – test invalid');
81
-
82
- stacks.request('echo', 'hey, how are you?', function(error, string) {});
83
- stacks.connect(3000, function(client) {
84
- client.on('echo', function(string, reply) {
85
- var error = null;
86
- reply(error, string);
87
-
88
- stacks.disconnect();
89
-
90
- done();
91
- });
92
- });
93
- });
94
- });
95
- it('should re-request requests that were pending on a client that disconnected', function(done) {
96
- var waited = false,
97
- error = null;
98
-
99
- stacks.request('wait ms', 1000, function(error, waited) {
100
- if (! error & waited) {
101
- done();
102
- stacks.disconnect();
103
- }
104
- });
105
- stacks.connect(3000, function(client) {
106
- client.on('wait ms', function(ms, reply) {
107
- setTimeout(function() {
108
- reply(error, waited);
109
- }, ms);
110
-
111
- stacks.disconnect();
112
-
113
- stacks.connect(3000, function(client) {
114
- client.on('wait ms', function(ms, reply) {
115
- waited = true;
116
-
117
- reply(error, waited);
118
- });
119
- });
120
-
121
- });
122
- });
123
- });
124
- it('should retry failed requests (up to request options.maxRetries times)', function(done) {
125
- var attempts = 0;
126
-
127
- stacks.request('echo', 'hey, how are you?', function(error, string) {
128
- if (! error) {
129
- stacks.disconnect();
130
-
131
- done();
132
- }
133
- });
134
- stacks.connect(3000, function(client) {
135
- client.on('echo', function(string, reply) {
136
- var error = null;
137
-
138
- if (++attempts <= 2) {
139
- error = new Error('echo error');
140
- }
141
-
142
- reply(error, string);
143
-
144
- });
145
- });
146
- });
147
- });
148
- });