stacks 0.1.0 → 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 -413
  219. package/test/test.stacks.js +0 -148
package/lib/stacks.js DELETED
@@ -1,413 +0,0 @@
1
- var debug = require('debug')('stacks'),
2
- net = require('net'),
3
- actorify = require('actorify'),
4
- async = require('async');
5
-
6
- var stacks = new (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
- console.warn('WARNING: listen() has already been called on this instance of stacks... overwriting');
27
- }
28
-
29
- this._server = new StacksServer();
30
- this._server.listen(port, callback);
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
- console.warn('WARNING: connect() has already been called on this instance of stacks... overwriting');
64
- }
65
-
66
- this._client = new StacksClient();
67
- this._client.connect(server, callback);
68
- this.disconnect = this._client.disconnect;
69
- };
70
-
71
- return this;
72
- });
73
-
74
- /**
75
- * stacks client object prototype
76
- *
77
- * @api private
78
- */
79
- function StacksClient() {
80
- var client = {};
81
- client._actor = null;
82
- client._connection = null;
83
- client._queues = {};
84
-
85
- debug('new instance of StacksClient');
86
-
87
- /**
88
- * connect to server
89
- *
90
- * @api public
91
- * @param <Mixed> server
92
- * @param <Function> callback
93
- */
94
- client.connect = function connect(server, callback) {
95
- debug('stacks client connect...');
96
-
97
- client._connection = net.connect(server, function() {
98
- debug('stacks client connected to stacks server');
99
-
100
- client._actor = actorify(client._connection);
101
-
102
- /**
103
- * handle stacks request of type |type| with worker |worker|
104
- * allow |concurrency| concurrent workers
105
- *
106
- * @api public
107
- * @param <String> type
108
- * @param <Function> worker
109
- * @param <Number> concurrency
110
- */
111
- client.on = function on(type, worker, concurrency) {
112
- debug('create queue for requests of type: ', type);
113
-
114
- client._queues[type] = async.queue(worker, concurrency);
115
-
116
- client._actor.on(type, function(body, reply) {
117
- debug('received stacks request of type %s; with body: ', type, body);
118
-
119
- client._queues[type].push(body, reply);
120
- });
121
- };
122
-
123
- /**
124
- * debug messages for socket events
125
- */
126
- client._connection.on('error', function(error) {
127
- debug('socket error: ', error);
128
- });
129
- client._connection.on('end', function() {
130
- debug('socket end');
131
- });
132
- client._connection.on('close', function() {
133
- debug('socket close');
134
- });
135
- client._connection.on('timeout', function() {
136
- debug('socket timeout');
137
- });
138
-
139
- callback(client);
140
- });
141
- };
142
-
143
- /**
144
- * disconnect stacks client
145
- *
146
- * @api public
147
- */
148
- client.disconnect = function disconnect() {
149
- client._connection.end();
150
- delete stacks._client;
151
- };
152
-
153
- /**
154
- * expose public api
155
- */
156
- this.connect = client.connect;
157
- this.disconnect = client.disconnect;
158
- };
159
-
160
- /**
161
- * stacks server object prototype
162
- *
163
- * @api private
164
- */
165
- function StacksServer() {
166
- var server = {};
167
- server.backupStacks = [];
168
- server.clients = {};
169
- server.requestNumber = 0;
170
-
171
- debug('new instance of StacksServer');
172
-
173
- /**
174
- * server connection handler
175
- *
176
- * @api private
177
- * @param <Socket> sock
178
- */
179
- server.connectionHandler = function serverConnectionHandler(sock) {
180
- var actor = actorify(sock),
181
- clientKey = actor.id,
182
- handleSocketClose;
183
-
184
- debug('client with key %s has connected', clientKey);
185
- debug('actor', actor);
186
-
187
- /**
188
- * handle socket close
189
- */
190
- handleSocketClose = function handleSocketClose() {
191
- var removedClient = server.clients[clientKey];
192
- debug('client with key %s has disconnected', clientKey);
193
-
194
- delete server.clients[clientKey];
195
- debug('deleted client with key %s', clientKey);
196
-
197
- /**
198
- * request (again) any pending requests on disconnected client
199
- */
200
- for (requestNumber in removedClient.pendingRequests) {
201
- debug('request request number %s again', requestNumber);
202
-
203
- var thisRequest = removedClient.pendingRequests[requestNumber];
204
- server.request(thisRequest.type, thisRequest.body, thisRequest.callback);
205
- }
206
-
207
- };
208
-
209
- /**
210
- * on sock 'error' or 'close', handle socket close
211
- */
212
- sock.on('error', function(error) {
213
- console.error('error: ', error);
214
- return handleSocketClose;
215
- });
216
- sock.on('close', handleSocketClose);
217
-
218
- /**
219
- * add new client
220
- */
221
- server.clients[clientKey] = {
222
- actor: actor,
223
- pendingRequests: {}
224
- };
225
-
226
- /**
227
- * request any requests from backup stacks
228
- */
229
- for (i in server.backupStacks) {
230
- var thisRequest = server.backupStacks[i];
231
-
232
- debug('request %s request from backup stacks', thisRequest.type);
233
-
234
- server.request(thisRequest.type, thisRequest.body, thisRequest.callback);
235
-
236
- delete server.backupStacks[i];
237
- }
238
- };
239
-
240
- /**
241
- * listen for client connections
242
- *
243
- * @api private
244
- * @param <Number> port
245
- * @param <Function> callback
246
- */
247
- server.listen = function listen(port, callback) {
248
- var connectionListener;
249
-
250
- debug('stacks server listen...');
251
-
252
- if (typeof callback != 'function') {
253
- callback = function() {};
254
- }
255
-
256
- connectionListener = net.createServer(server.connectionHandler);
257
-
258
- connectionListener.listen(port, function() {
259
- debug('stacks server listening on port ', port);
260
-
261
- callback();
262
- });
263
-
264
- };
265
-
266
- /**
267
- * get the key (actor.id) of the next client to request
268
- * uses round-robin distribution
269
- *
270
- * @api private
271
- */
272
- server.getNextClientKey = function getNextClientKey() {
273
- var clientKeys = Object.keys(server.clients);
274
- clientCount = clientKeys.length,
275
- nextClientKey = clientKeys[server.requestNumber % clientCount];
276
-
277
- debug('get next client key. nextClientKey: ', nextClientKey);
278
-
279
- return nextClientKey;
280
- };
281
-
282
- /**
283
- * get a client by key (actor.id)
284
- *
285
- * @api private
286
- * @param key
287
- */
288
- server.getClient = function getClient(key) {
289
-
290
- /**
291
- * send a request to this client,
292
- * add it to this client's pending requests,
293
- * when it calls back, remove it from this client's pending requests
294
- * call back with error & response body
295
- */
296
- this.clientRequest = function clientRequest(type, body, options, callback) {
297
- debug('client request. _requestNumber: ', options._requestNumber);
298
-
299
- server.clients[key].pendingRequests[options._requestNumber] = {
300
- type: type,
301
- body: body,
302
- callback: callback
303
- };
304
-
305
- server.clients[key].actor.send(type, body, function(error, response) {
306
- debug('client request finished. _requestNumber: ', options._requestNumber);
307
-
308
- delete server.clients[key].pendingRequests[options._requestNumber];
309
-
310
- debug('client with key %s\'s pendingRequests: ', key, server.clients[key].pendingRequests);
311
-
312
- callback(error, response);
313
- });
314
- };
315
-
316
- return this;
317
- };
318
-
319
- /**
320
- * make a request to stacks
321
- *
322
- * @api private
323
- * @param <String> type
324
- * @param <Mixed> body
325
- * @param <Object> options
326
- * @param <Function> callback
327
- */
328
- server.request = function serverRequest(type, body, options, callback) {
329
- debug('stacks.server.request');
330
-
331
- /**
332
- * handle options
333
- * if typeof options is function, no options were passed
334
- */
335
- if (typeof options === 'function') {
336
- callback = options;
337
- options = {};
338
- }
339
-
340
- /**
341
- * handle options.maxRetries
342
- * if undefined, default to 3
343
- */
344
- if (typeof options.maxRetries === 'undefined') {
345
- options.maxRetries = 3;
346
- }
347
-
348
- /**
349
- * handle options._retrySequence
350
- * if undefined, default to 0
351
- */
352
- if (typeof options._retrySequence === 'undefined') {
353
- options._retrySequence = 0;
354
- }
355
-
356
- /**
357
- * set this request's options._requestNumber; increment _requestNumber
358
- */
359
- options._requestNumber = server.requestNumber++;
360
-
361
- /**
362
- * if no clients are connected, add request to backup stacks and return
363
- */
364
- if (Object.keys(server.clients).length < 1) {
365
- debug('no clients connected, backing up request');
366
-
367
- server.backupStacks.push({
368
- type: type,
369
- body: body,
370
- callback: callback
371
- });
372
- return;
373
- }
374
-
375
- /**
376
- * if options._retrySequence++ >= options.maxRetries,
377
- * request
378
- * else
379
- * callback with new error
380
- */
381
- if (options._retrySequence++ <= options.maxRetries) {
382
- server.getClient(server.getNextClientKey()).clientRequest(type, body, options, function(error, response) {
383
- debug('request finished. _requestNumber: ', options._requestNumber);
384
-
385
- if (error) {
386
- debug('request with _requestNumber %s resulted in error: ', options._requestNumber, error);
387
-
388
- server.request(type, body, options, callback);
389
- } else {
390
- debug('request with _requestNumber %s had response: ', options._requestNumber, response);
391
-
392
- callback(error, response);
393
- }
394
- });
395
- } else {
396
- callback(new Error(type +' request failed after max retry attempts'), null);
397
- }
398
-
399
- };
400
-
401
- /**
402
- * expose public api
403
- */
404
- this.listen = server.listen;
405
- this.request = server.request;
406
-
407
- return this;
408
- };
409
-
410
- /**
411
- * export api
412
- */
413
- module.exports = stacks;
@@ -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
- });