velocious 1.0.467 → 1.0.468
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/build/environment-handlers/node/cli/commands/generate/frontend-models.js +155 -35
- package/build/frontend-model-controller.js +47 -1
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts +82 -9
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +137 -35
- package/build/src/frontend-model-controller.d.ts +16 -0
- package/build/src/frontend-model-controller.d.ts.map +1 -1
- package/build/src/frontend-model-controller.js +36 -2
- package/package.json +1 -1
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +155 -35
- package/src/frontend-model-controller.js +47 -1
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
29
29
|
/** @type {Map<string, string> | null} */
|
|
30
30
|
_resourceMethodReturnTypes = null
|
|
31
31
|
|
|
32
|
-
/** @type {Map<string, string
|
|
32
|
+
/** @type {Map<string, Array<{name: string | null, type: string}>> | null} */
|
|
33
33
|
_resourceMethodParameterTypes = null
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -288,7 +288,12 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
288
288
|
}
|
|
289
289
|
const collectionCommands = modelConfig.collectionCommands
|
|
290
290
|
const memberCommands = modelConfig.memberCommands
|
|
291
|
-
const
|
|
291
|
+
const declaredCommandMetadata = modelConfig.commandMetadata || {}
|
|
292
|
+
const commandMetadata = await this.commandMetadataWithResourceJsDoc({
|
|
293
|
+
commandMetadata: declaredCommandMetadata,
|
|
294
|
+
commandNames: [...Object.keys(collectionCommands), ...Object.keys(memberCommands)],
|
|
295
|
+
resourceClass
|
|
296
|
+
})
|
|
292
297
|
const builtInCollectionCommandsAreDefault = builtInCollectionCommands.create === "create" && builtInCollectionCommands.index === "index"
|
|
293
298
|
const builtInMemberCommandsAreDefault = builtInMemberCommands.attach === "attach"
|
|
294
299
|
&& builtInMemberCommands.destroy === "destroy"
|
|
@@ -472,12 +477,12 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
472
477
|
fileContent += ` * @returns {Promise<${signature.returnType}>} - Command response.\n`
|
|
473
478
|
fileContent += " */\n"
|
|
474
479
|
fileContent += ` static async ${methodName}(${signature.parameters}) {\n`
|
|
475
|
-
fileContent +=
|
|
480
|
+
fileContent += ` return /** @type {${signature.returnType}} */ (await this.executeCustomCommand({\n`
|
|
476
481
|
fileContent += ` commandName: ${JSON.stringify(collectionCommands[methodName])},\n`
|
|
477
482
|
fileContent += ` commandType: ${JSON.stringify(collectionCommands[methodName])},\n`
|
|
478
483
|
fileContent += ` payload: ${className}.normalizeCustomCommandPayloadArguments(${signature.payloadArguments}),\n`
|
|
479
484
|
fileContent += " resourcePath: this.resourcePath()\n"
|
|
480
|
-
fileContent += " })\n"
|
|
485
|
+
fileContent += " }))\n"
|
|
481
486
|
fileContent += " }\n"
|
|
482
487
|
}
|
|
483
488
|
|
|
@@ -491,13 +496,13 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
491
496
|
fileContent += ` * @returns {Promise<${signature.returnType}>} - Command response.\n`
|
|
492
497
|
fileContent += " */\n"
|
|
493
498
|
fileContent += ` async ${methodName}(${signature.parameters}) {\n`
|
|
494
|
-
fileContent += ` return await ${className}.executeCustomCommand({\n`
|
|
499
|
+
fileContent += ` return /** @type {${signature.returnType}} */ (await ${className}.executeCustomCommand({\n`
|
|
495
500
|
fileContent += ` commandName: ${JSON.stringify(memberCommands[methodName])},\n`
|
|
496
501
|
fileContent += ` commandType: ${JSON.stringify(memberCommands[methodName])},\n`
|
|
497
502
|
fileContent += " memberId: this.primaryKeyValue(),\n"
|
|
498
503
|
fileContent += ` payload: ${className}.normalizeCustomCommandPayloadArguments(${signature.payloadArguments}),\n`
|
|
499
504
|
fileContent += ` resourcePath: ${className}.resourcePath()\n`
|
|
500
|
-
fileContent += " })\n"
|
|
505
|
+
fileContent += " }))\n"
|
|
501
506
|
fileContent += " }\n"
|
|
502
507
|
}
|
|
503
508
|
|
|
@@ -1406,11 +1411,7 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1406
1411
|
* @returns {string} - A frontend-resolvable attribute type.
|
|
1407
1412
|
*/
|
|
1408
1413
|
frontendResolvableAttributeJsDocType(jsDocType) {
|
|
1409
|
-
const safeTypeIdentifiers =
|
|
1410
|
-
"Array", "Date", "Exclude", "Extract", "FrontendModelAttributeValue", "FrontendModelTransportValue",
|
|
1411
|
-
"Map", "NonNullable", "Omit", "Partial", "Pick", "Promise", "Readonly", "ReadonlyArray", "Record",
|
|
1412
|
-
"Required", "ReturnType", "Set"
|
|
1413
|
-
])
|
|
1414
|
+
const safeTypeIdentifiers = this.frontendResolvableTypeIdentifiers()
|
|
1414
1415
|
const referencedIdentifiers = jsDocType.match(/[A-Z][A-Za-z0-9_$]*/g) || []
|
|
1415
1416
|
|
|
1416
1417
|
if (referencedIdentifiers.some((identifier) => !safeTypeIdentifiers.has(identifier))) {
|
|
@@ -1420,6 +1421,43 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1420
1421
|
return jsDocType
|
|
1421
1422
|
}
|
|
1422
1423
|
|
|
1424
|
+
/**
|
|
1425
|
+
* Capitalized identifiers a generated frontend model can resolve on its own
|
|
1426
|
+
* (primitives are lower-case and matched separately), so only framework-owned
|
|
1427
|
+
* and builtin generic types are listed.
|
|
1428
|
+
* @returns {Set<string>} - Frontend-resolvable type identifiers.
|
|
1429
|
+
*/
|
|
1430
|
+
frontendResolvableTypeIdentifiers() {
|
|
1431
|
+
return new Set([
|
|
1432
|
+
"Array", "Date", "Exclude", "Extract", "FrontendModelAttributeValue", "FrontendModelTransportValue",
|
|
1433
|
+
"Map", "NonNullable", "Omit", "Partial", "Pick", "Promise", "Readonly", "ReadonlyArray", "Record",
|
|
1434
|
+
"Required", "ReturnType", "Set"
|
|
1435
|
+
])
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* Rewrites a custom-command param/return JSDoc type so it resolves in the generated
|
|
1440
|
+
* frontend model: each model-class (or otherwise non-frontend-resolvable) identifier
|
|
1441
|
+
* becomes `any` in place, keeping the surrounding object fields typed. A command-result
|
|
1442
|
+
* field holding a model arrives as a serialized transport value, so the consumer hydrates
|
|
1443
|
+
* it with `Model.instantiateFromResponse(...)`. The word boundary avoids matching the
|
|
1444
|
+
* capitalized middle of a camelCase property name (e.g. `adjustedTotalCents`).
|
|
1445
|
+
* @param {string} jsDocType - Resolved (Promise-unwrapped) JSDoc type.
|
|
1446
|
+
* @returns {string} - A frontend-resolvable JSDoc type.
|
|
1447
|
+
*/
|
|
1448
|
+
frontendResolvableCommandJsDocType(jsDocType) {
|
|
1449
|
+
const safeTypeIdentifiers = this.frontendResolvableTypeIdentifiers()
|
|
1450
|
+
|
|
1451
|
+
return jsDocType
|
|
1452
|
+
// A type that reaches into a backend source file via `import("...")` (optionally
|
|
1453
|
+
// `.Member` and `[]`) can't resolve from the generated frontend model and would type
|
|
1454
|
+
// a serialized result as a backend model instance, so collapse it to `any`.
|
|
1455
|
+
.replace(/import\(\s*["'][^"']*["']\s*\)(\s*\.\s*[A-Za-z_$][\w$]*)*(\s*\[\s*\])*/g, "any")
|
|
1456
|
+
// Remaining capitalized identifiers are model classes or otherwise non-resolvable
|
|
1457
|
+
// types; downgrade each in place so sibling scalar fields keep their real types.
|
|
1458
|
+
.replace(/\b[A-Z][A-Za-z0-9_$]*/g, (identifier) => safeTypeIdentifiers.has(identifier) ? identifier : "any")
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1423
1461
|
/**
|
|
1424
1462
|
* Builds the JSDoc param block, parameter list, payload-argument expression, and
|
|
1425
1463
|
* return type for a custom command method. With declared `args` each becomes a
|
|
@@ -1453,6 +1491,69 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1453
1491
|
}
|
|
1454
1492
|
}
|
|
1455
1493
|
|
|
1494
|
+
/**
|
|
1495
|
+
* Enriches custom-command metadata by deriving a command's typed args and return
|
|
1496
|
+
* type from the backend resource method's `@param`/`@returns` JSDoc when they are
|
|
1497
|
+
* not already declared in `resourceConfig`. Precedence: explicit `resourceConfig`
|
|
1498
|
+
* `{args, returnType}` wins, then the derived backend-method JSDoc, then the generic
|
|
1499
|
+
* default. Model-class identifiers in the derived types are downgraded to `any`
|
|
1500
|
+
* because the frontend receives a serialized record, not a model instance, which the
|
|
1501
|
+
* consumer hydrates with `Model.instantiateFromResponse(...)`.
|
|
1502
|
+
* @param {object} args - Arguments.
|
|
1503
|
+
* @param {Record<string, {args: Array<{name: string, type: string}>, returnType: string | null}>} args.commandMetadata - Declared per-command metadata.
|
|
1504
|
+
* @param {string[]} args.commandNames - Command method names to resolve.
|
|
1505
|
+
* @param {import("../../../../../configuration-types.js").FrontendModelResourceClassType | null | undefined} args.resourceClass - Resource class.
|
|
1506
|
+
* @returns {Promise<Record<string, {args: Array<{name: string, type: string}>, returnType: string | null}>>} - Enriched metadata.
|
|
1507
|
+
*/
|
|
1508
|
+
async commandMetadataWithResourceJsDoc({commandMetadata, commandNames, resourceClass}) {
|
|
1509
|
+
if (!resourceClass) return commandMetadata
|
|
1510
|
+
|
|
1511
|
+
/** @type {Record<string, {args: Array<{name: string, type: string}>, returnType: string | null}>} */
|
|
1512
|
+
const enriched = {...commandMetadata}
|
|
1513
|
+
|
|
1514
|
+
for (const commandName of commandNames) {
|
|
1515
|
+
const declared = commandMetadata[commandName] || {args: [], returnType: null}
|
|
1516
|
+
const sourceClassName = this.methodOwnerClassName({methodName: commandName, targetClass: resourceClass})
|
|
1517
|
+
|
|
1518
|
+
if (!sourceClassName) {
|
|
1519
|
+
enriched[commandName] = declared
|
|
1520
|
+
|
|
1521
|
+
continue
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
let returnType = declared.returnType
|
|
1525
|
+
|
|
1526
|
+
if (!returnType) {
|
|
1527
|
+
const jsDocReturnType = await this.resourceMethodReturnType({methodName: commandName, sourceClassName})
|
|
1528
|
+
|
|
1529
|
+
if (jsDocReturnType) {
|
|
1530
|
+
returnType = this.frontendResolvableCommandJsDocType(this.unwrappedPromiseJsDocType({jsDocType: jsDocReturnType}))
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
let args = declared.args
|
|
1535
|
+
|
|
1536
|
+
if (!args || args.length === 0) {
|
|
1537
|
+
const jsDocParameters = await this.resourceMethodParameters({methodName: commandName, sourceClassName})
|
|
1538
|
+
// Skip object-property tags (`@param {string} args.message`); only the
|
|
1539
|
+
// top-level parameters map to method arguments, otherwise the shared
|
|
1540
|
+
// `@param {object} args` + property style would emit `name(args, args)`.
|
|
1541
|
+
const topLevelParameters = (jsDocParameters || []).filter((parameter) => typeof parameter.name === "string" && !parameter.name.includes("."))
|
|
1542
|
+
|
|
1543
|
+
if (topLevelParameters.length > 0) {
|
|
1544
|
+
args = topLevelParameters.map((parameter) => ({
|
|
1545
|
+
name: /** @type {string} */ (parameter.name),
|
|
1546
|
+
type: this.frontendResolvableCommandJsDocType(parameter.type)
|
|
1547
|
+
}))
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
enriched[commandName] = {args: args || [], returnType: returnType || null}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
return enriched
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1456
1557
|
/**
|
|
1457
1558
|
* Runs unwrapped promise js doc type.
|
|
1458
1559
|
* @param {object} args - Arguments.
|
|
@@ -1534,26 +1635,39 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1534
1635
|
* @returns {Promise<string | null>} - JSDoc parameter type when documented.
|
|
1535
1636
|
*/
|
|
1536
1637
|
async resourceMethodParameterType({methodName, parameterIndex, sourceClassName}) {
|
|
1537
|
-
const
|
|
1538
|
-
const parameterTypesKey = `${sourceClassName}.${methodName}`
|
|
1638
|
+
const parameters = await this.resourceMethodParameters({methodName, sourceClassName})
|
|
1539
1639
|
|
|
1540
|
-
if (!
|
|
1640
|
+
if (!parameters) return null
|
|
1541
1641
|
|
|
1542
|
-
const
|
|
1642
|
+
const parameter = parameters[parameterIndex]
|
|
1543
1643
|
|
|
1544
|
-
if (
|
|
1545
|
-
|
|
1644
|
+
if (parameter === undefined) return null
|
|
1645
|
+
|
|
1646
|
+
if (parameter.type.length < 1) {
|
|
1647
|
+
throw new Error(`Expected non-empty JSDoc parameter type for ${sourceClassName}.${methodName} parameter ${parameterIndex}`)
|
|
1546
1648
|
}
|
|
1547
1649
|
|
|
1548
|
-
|
|
1650
|
+
return parameter.type
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Runs resource method parameters.
|
|
1655
|
+
* @param {{methodName: string, sourceClassName: string}} args - Arguments.
|
|
1656
|
+
* @returns {Promise<Array<{name: string | null, type: string}> | null>} - JSDoc parameters (name + type) when documented.
|
|
1657
|
+
*/
|
|
1658
|
+
async resourceMethodParameters({methodName, sourceClassName}) {
|
|
1659
|
+
const resourceMethodParameterTypes = await this.resourceMethodParameterTypes()
|
|
1660
|
+
const parameterTypesKey = `${sourceClassName}.${methodName}`
|
|
1661
|
+
|
|
1662
|
+
if (!resourceMethodParameterTypes.has(parameterTypesKey)) return null
|
|
1549
1663
|
|
|
1550
|
-
|
|
1664
|
+
const parameters = resourceMethodParameterTypes.get(parameterTypesKey)
|
|
1551
1665
|
|
|
1552
|
-
if (
|
|
1553
|
-
throw new Error(`Expected
|
|
1666
|
+
if (!parameters) {
|
|
1667
|
+
throw new Error(`Expected JSDoc parameters for ${parameterTypesKey}`)
|
|
1554
1668
|
}
|
|
1555
1669
|
|
|
1556
|
-
return
|
|
1670
|
+
return parameters
|
|
1557
1671
|
}
|
|
1558
1672
|
|
|
1559
1673
|
/**
|
|
@@ -1579,7 +1693,7 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1579
1693
|
|
|
1580
1694
|
/**
|
|
1581
1695
|
* Runs resource method parameter types.
|
|
1582
|
-
* @returns {Promise<Map<string, string
|
|
1696
|
+
* @returns {Promise<Map<string, Array<{name: string | null, type: string}>>>} - Resource method parameters keyed by ClassName.methodName.
|
|
1583
1697
|
*/
|
|
1584
1698
|
async resourceMethodParameterTypes() {
|
|
1585
1699
|
if (this._resourceMethodParameterTypes) return this._resourceMethodParameterTypes
|
|
@@ -1678,7 +1792,7 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1678
1792
|
|
|
1679
1793
|
/**
|
|
1680
1794
|
* Adds resource method parameter types from source.
|
|
1681
|
-
* @param {{parameterTypes: Map<string, string
|
|
1795
|
+
* @param {{parameterTypes: Map<string, Array<{name: string | null, type: string}>>, sourceText: string}} args - Arguments.
|
|
1682
1796
|
* @returns {void}
|
|
1683
1797
|
*/
|
|
1684
1798
|
addResourceMethodParameterTypesFromSource({parameterTypes, sourceText}) {
|
|
@@ -1710,10 +1824,10 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1710
1824
|
if (!methodMatch) continue
|
|
1711
1825
|
|
|
1712
1826
|
const methodName = methodMatch[1]
|
|
1713
|
-
const
|
|
1827
|
+
const jsDocParameters = this.jsDocParameters(jsDocMatch[1])
|
|
1714
1828
|
|
|
1715
|
-
if (
|
|
1716
|
-
parameterTypes.set(`${className}.${methodName}`,
|
|
1829
|
+
if (jsDocParameters.length > 0) {
|
|
1830
|
+
parameterTypes.set(`${className}.${methodName}`, jsDocParameters)
|
|
1717
1831
|
}
|
|
1718
1832
|
}
|
|
1719
1833
|
|
|
@@ -1748,12 +1862,12 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1748
1862
|
}
|
|
1749
1863
|
|
|
1750
1864
|
/**
|
|
1751
|
-
* Runs js doc
|
|
1865
|
+
* Runs js doc parameters.
|
|
1752
1866
|
* @param {string} jsDocText - JSDoc text inside comment markers.
|
|
1753
|
-
* @returns {string
|
|
1867
|
+
* @returns {Array<{name: string | null, type: string}>} - JSDoc parameters (name + type) in declaration order.
|
|
1754
1868
|
*/
|
|
1755
|
-
|
|
1756
|
-
const
|
|
1869
|
+
jsDocParameters(jsDocText) {
|
|
1870
|
+
const parameters = []
|
|
1757
1871
|
const paramRegex = /@param\s*\{/g
|
|
1758
1872
|
let _paramMatch
|
|
1759
1873
|
|
|
@@ -1765,17 +1879,23 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
1765
1879
|
throw new Error(`Could not parse JSDoc parameter type from: ${jsDocText}`)
|
|
1766
1880
|
}
|
|
1767
1881
|
|
|
1768
|
-
const
|
|
1882
|
+
const type = jsDocText.slice(typeOpenIndex + 1, typeCloseIndex).trim()
|
|
1769
1883
|
|
|
1770
|
-
if (
|
|
1884
|
+
if (type.length < 1) {
|
|
1771
1885
|
throw new Error(`Expected non-empty JSDoc parameter type in: ${jsDocText}`)
|
|
1772
1886
|
}
|
|
1773
1887
|
|
|
1774
|
-
|
|
1888
|
+
// After the closing brace the parameter name follows (optionally bracketed
|
|
1889
|
+
// for `@param {type} [name]`). Capture the leading name token — including any
|
|
1890
|
+
// dotted path so object-property tags like `@param {string} args.message` stay
|
|
1891
|
+
// distinguishable from the top-level `@param {object} args` parameter.
|
|
1892
|
+
const nameMatch = jsDocText.slice(typeCloseIndex + 1).match(/^\s*\[?\s*([A-Za-z_$][\w$.]*)/)
|
|
1893
|
+
|
|
1894
|
+
parameters.push({name: nameMatch ? nameMatch[1] : null, type})
|
|
1775
1895
|
paramRegex.lastIndex = typeCloseIndex + 1
|
|
1776
1896
|
}
|
|
1777
1897
|
|
|
1778
|
-
return
|
|
1898
|
+
return parameters
|
|
1779
1899
|
}
|
|
1780
1900
|
|
|
1781
1901
|
/**
|
|
@@ -584,6 +584,12 @@ export default class FrontendModelController extends Controller {
|
|
|
584
584
|
* Frontend model ability override.
|
|
585
585
|
* @type {import("./authorization/ability.js").default | undefined} */
|
|
586
586
|
_frontendModelAbilityOverride = undefined
|
|
587
|
+
/**
|
|
588
|
+
* Original deserialized custom-command client payload, captured before route
|
|
589
|
+
* framework params are merged in, so a typed command method receives the client's
|
|
590
|
+
* own arguments rather than the route metadata. Only set on the shared-endpoint path.
|
|
591
|
+
* @type {Record<string, ?> | undefined} */
|
|
592
|
+
_frontendModelCustomCommandClientArguments = undefined
|
|
587
593
|
|
|
588
594
|
/**
|
|
589
595
|
* Runs frontend model params.
|
|
@@ -3578,6 +3584,14 @@ export default class FrontendModelController extends Controller {
|
|
|
3578
3584
|
viewPath
|
|
3579
3585
|
})
|
|
3580
3586
|
|
|
3587
|
+
// Preserve the client's own command arguments before route framework params won
|
|
3588
|
+
// the `controllerParams` merge above, so a typed command method (`async name(args)`)
|
|
3589
|
+
// receives the client payload — not the route's member id / model / controller keys.
|
|
3590
|
+
const customCommandController = /** @type {FrontendModelController} */ (/** @type {unknown} */ (controllerInstance))
|
|
3591
|
+
|
|
3592
|
+
customCommandController._frontendModelCustomCommandClientArguments =
|
|
3593
|
+
(payload && typeof payload === "object" && !Array.isArray(payload)) ? /** @type {Record<string, ?>} */ (payload) : {}
|
|
3594
|
+
|
|
3581
3595
|
await this.withFrontendModelRequestContext(controllerParams, response, async () => {
|
|
3582
3596
|
await controllerInstance._runBeforeCallbacks()
|
|
3583
3597
|
const controllerMethods = /** @type {Record<string, () => Promise<void> | void>} */ (/** @type {?} */ (controllerInstance))
|
|
@@ -3757,7 +3771,13 @@ export default class FrontendModelController extends Controller {
|
|
|
3757
3771
|
return this.frontendModelErrorPayload(`Missing frontend-model custom command '${methodName}'.`)
|
|
3758
3772
|
}
|
|
3759
3773
|
|
|
3760
|
-
|
|
3774
|
+
// Pass the client command arguments as the method's first argument so a command
|
|
3775
|
+
// method can take a typed args object (`async name(args)`) and the generated
|
|
3776
|
+
// frontend method can forward the backend method's `@param`. `this.params()` is
|
|
3777
|
+
// unchanged, so existing parameterless methods keep working. The args are untrusted
|
|
3778
|
+
// client input typed only by the declared contract, so methods must still validate.
|
|
3779
|
+
const commandArguments = this.frontendModelCustomCommandArguments(params)
|
|
3780
|
+
const responsePayload = await commandMethod.call(resource, commandArguments)
|
|
3761
3781
|
|
|
3762
3782
|
if (!responsePayload || typeof responsePayload !== "object") {
|
|
3763
3783
|
return {status: "success"}
|
|
@@ -3772,6 +3792,32 @@ export default class FrontendModelController extends Controller {
|
|
|
3772
3792
|
)
|
|
3773
3793
|
}
|
|
3774
3794
|
|
|
3795
|
+
/**
|
|
3796
|
+
* Resolves the typed argument object passed to a custom command method. On the
|
|
3797
|
+
* shared-endpoint path the original client payload was captured before route
|
|
3798
|
+
* framework params were merged, so it is returned verbatim (a client `id` survives
|
|
3799
|
+
* a member route). On the direct path it falls back to the request params with the
|
|
3800
|
+
* framework keys the command route hook injected stripped out.
|
|
3801
|
+
* @param {Record<string, ?>} params - Deserialized frontend-model params.
|
|
3802
|
+
* @returns {Record<string, ?>} - Client command arguments.
|
|
3803
|
+
*/
|
|
3804
|
+
frontendModelCustomCommandArguments(params) {
|
|
3805
|
+
if (this._frontendModelCustomCommandClientArguments) {
|
|
3806
|
+
return this._frontendModelCustomCommandClientArguments
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
const {
|
|
3810
|
+
action: _action,
|
|
3811
|
+
controller: _controller,
|
|
3812
|
+
frontendModelCustomCommandMethodName: _methodName,
|
|
3813
|
+
frontendModelCustomCommandScope: _scope,
|
|
3814
|
+
model: _model,
|
|
3815
|
+
...commandArguments
|
|
3816
|
+
} = params
|
|
3817
|
+
|
|
3818
|
+
return commandArguments
|
|
3819
|
+
}
|
|
3820
|
+
|
|
3775
3821
|
/**
|
|
3776
3822
|
* Walks a custom-command response payload and replaces any backend `Record`
|
|
3777
3823
|
* instance with the resource's per-action serialized form so handlers can
|