vrpc 3.9.1 → 3.10.1
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 +1 -1
- package/vrpc/VrpcAdapter.js +34 -17
- package/vrpc/VrpcAgent.js +5 -1
- package/vrpc/comment-parser/parser.js +5 -2
package/package.json
CHANGED
package/vrpc/VrpcAdapter.js
CHANGED
|
@@ -276,6 +276,15 @@ class VrpcAdapter {
|
|
|
276
276
|
* @param {String} description Parameter description
|
|
277
277
|
* @param {String} [type] Parameter type
|
|
278
278
|
* @param {Any} [default] The default to be injected when not provided
|
|
279
|
+
* @param {Callback} [callback] The signature of a function-typed
|
|
280
|
+
* parameter, when a `@callback` typedef of that name documents it
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @typedef {Object} Callback
|
|
285
|
+
* @param {String} name Typedef name (the parameter's type)
|
|
286
|
+
* @param {String} description Callback description
|
|
287
|
+
* @param {Array.<Param>} params The arguments the function is called with
|
|
279
288
|
*/
|
|
280
289
|
|
|
281
290
|
/**
|
|
@@ -341,27 +350,35 @@ class VrpcAdapter {
|
|
|
341
350
|
static _parseComments (content) {
|
|
342
351
|
const comments = commentParser(content, { assocFunctions: true })
|
|
343
352
|
const meta = {}
|
|
353
|
+
const paramsOf = tags =>
|
|
354
|
+
tags
|
|
355
|
+
.filter(
|
|
356
|
+
({ tag }) => tag === 'param' || tag === 'arg' || tag === 'argument'
|
|
357
|
+
)
|
|
358
|
+
.map(({ name, optional, description, type, default: defaultValue }) => {
|
|
359
|
+
return { name, optional, description, type, defaultValue }
|
|
360
|
+
})
|
|
361
|
+
// `@callback Name` blocks document the signature of a function-typed
|
|
362
|
+
// parameter; a parameter whose type names one carries it as `callback`
|
|
363
|
+
const callbacks = {}
|
|
364
|
+
comments.forEach(({ tags, description }) => {
|
|
365
|
+
const typedef = tags && tags.find(({ tag }) => tag === 'callback')
|
|
366
|
+
if (!typedef || !typedef.name) return
|
|
367
|
+
callbacks[typedef.name] = {
|
|
368
|
+
name: typedef.name,
|
|
369
|
+
description,
|
|
370
|
+
params: paramsOf(tags)
|
|
371
|
+
}
|
|
372
|
+
})
|
|
344
373
|
comments.forEach(({ tags, description, functionName }) => {
|
|
374
|
+
if (tags && tags.some(({ tag }) => tag === 'callback')) return
|
|
345
375
|
if (functionName) {
|
|
346
376
|
if (tags) {
|
|
347
|
-
|
|
348
|
-
|
|
377
|
+
const params = paramsOf(tags).map(param =>
|
|
378
|
+
callbacks[param.type]
|
|
379
|
+
? { ...param, callback: callbacks[param.type] }
|
|
380
|
+
: param
|
|
349
381
|
)
|
|
350
|
-
if (params.length > 0) {
|
|
351
|
-
params = params.map(
|
|
352
|
-
({
|
|
353
|
-
name,
|
|
354
|
-
optional,
|
|
355
|
-
description,
|
|
356
|
-
type,
|
|
357
|
-
default: defaultValue
|
|
358
|
-
}) => {
|
|
359
|
-
return { name, optional, description, type, defaultValue }
|
|
360
|
-
}
|
|
361
|
-
)
|
|
362
|
-
} else {
|
|
363
|
-
params = []
|
|
364
|
-
}
|
|
365
382
|
let ret = tags.filter(
|
|
366
383
|
({ tag }) => tag === 'returns' || tag === 'return'
|
|
367
384
|
)
|
package/vrpc/VrpcAgent.js
CHANGED
|
@@ -262,7 +262,11 @@ class VrpcAgent extends EventEmitter {
|
|
|
262
262
|
*/
|
|
263
263
|
create ({ className, instance = nanoid(8), args = [], isIsolated = false }) {
|
|
264
264
|
const obj = VrpcAdapter.create({ className, instance, args, isIsolated })
|
|
265
|
-
|
|
265
|
+
// An agent that is not served yet only collects: once the connection
|
|
266
|
+
// stands, the connect handler subscribes every adapter instance and
|
|
267
|
+
// publishes every class info, so a caller may build its full state
|
|
268
|
+
// before going online and "online" then means "complete"
|
|
269
|
+
if (this._client && !this._hasSharedInstance(instance)) {
|
|
266
270
|
this._subscribeToMethodsOfNewInstance(className, instance)
|
|
267
271
|
this._publishClassInfoMessage(className)
|
|
268
272
|
this._publishClassInfoConciseMessage(className)
|
|
@@ -219,12 +219,15 @@ function mkextract (opts) {
|
|
|
219
219
|
|
|
220
220
|
// if open marker detected and it's not, skip one
|
|
221
221
|
if (startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
// A block still waiting for its function is followed by another
|
|
223
|
+
// block: it documents no function (a typedef, a callback) and is
|
|
224
|
+
// returned as it is - parsed BEFORE the chunk makes way
|
|
224
225
|
if (findMethod) {
|
|
225
226
|
result = parse_block(chunk, opts)
|
|
226
227
|
findMethod = false
|
|
227
228
|
}
|
|
229
|
+
chunk = []
|
|
230
|
+
indent = startPos + MARKER_START.length
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
if (findMethod) {
|