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

Function buildNestedObject

packages/core/scripts/generate-wrapper.mjs:31–55  ·  view source on GitHub ↗
(obj, segments, operationId)

Source from the content-addressed store, hash-verified

29// Build nested object structure from path segments.
30// When a leaf (operationId string) would get children, promote to nested object. When multiple ops share a path, use action keys.
31function buildNestedObject(obj, segments, operationId) {
32 if (segments.length === 0) return operationId
33
34 const [first, ...rest] = segments
35 const key = toCamelCase(first)
36
37 if (rest.length === 0) {
38 const existing = obj[key]
39 if (typeof existing === 'string')
40 obj[key] = { [toActionKey(existing)]: existing, [toActionKey(operationId)]: operationId }
41 else if (existing && typeof existing === 'object' && !Array.isArray(existing))
42 obj[key][toActionKey(operationId)] = operationId
43 else obj[key] = operationId
44
45 return obj
46 }
47
48 const existing = obj[key]
49 if (typeof existing === 'string') obj[key] = { [toActionKey(existing)]: existing }
50
51 if (!obj[key] || typeof obj[key] === 'string') obj[key] = {}
52
53 buildNestedObject(obj[key], rest, operationId)
54 return obj
55}
56
57// Generate TypeScript code for nested object
58function generateNestedObject(obj, indent = 0) {

Callers 1

Calls 2

toCamelCaseFunction · 0.70
toActionKeyFunction · 0.70

Tested by

no test coverage detected