MCPcopy Create free account
hub / github.com/blockmatic/basilic / buildNestedObject

Function buildNestedObject

packages/cli/scripts/generate-cli.mjs:29–53  ·  view source on GitHub ↗
(obj, segments, operationId)

Source from the content-addressed store, hash-verified

27
28// Build nested object structure from path segments (same as core generate-wrapper)
29function buildNestedObject(obj, segments, operationId) {
30 if (segments.length === 0) return operationId
31
32 const [first, ...rest] = segments
33 const key = toCamelCase(first)
34
35 if (rest.length === 0) {
36 const existing = obj[key]
37 if (typeof existing === 'string')
38 obj[key] = { [toActionKey(existing)]: existing, [toActionKey(operationId)]: operationId }
39 else if (existing && typeof existing === 'object' && !Array.isArray(existing))
40 obj[key][toActionKey(operationId)] = operationId
41 else obj[key] = operationId
42
43 return obj
44 }
45
46 const existing = obj[key]
47 if (typeof existing === 'string') obj[key] = { [toActionKey(existing)]: existing }
48
49 if (!obj[key] || typeof obj[key] === 'string') obj[key] = {}
50
51 buildNestedObject(obj[key], rest, operationId)
52 return obj
53}
54
55// Traverse nested structure and collect { path, operationId } for each leaf
56function collectCommandSpecs(obj, pathPrefix = [], acc = []) {

Callers 1

generate-cli.mjsFile · 0.70

Calls 2

toCamelCaseFunction · 0.70
toActionKeyFunction · 0.70

Tested by

no test coverage detected