MCPcopy
hub / github.com/composerize/composerize / getComposeEntry

Function getComposeEntry

packages/composerize/src/logic.js:40–207  ·  view source on GitHub ↗
(mapping: Mapping, value: RawValue)

Source from the content-addressed store, hash-verified

38 * Turn a mapping and the value of the mapping into a formatted json object
39 */
40export const getComposeEntry = (mapping: Mapping, value: RawValue): ComposeEntry | Array<ComposeEntry> => {
41 if (mapping.type === 'Array') {
42 return ({
43 path: mapping.path,
44 // $FlowFixMe: TODO: Map to array of strings
45 value: Array.isArray(value) ? value : [String(value)],
46 }: ArrayComposeEntry);
47 }
48
49 if (mapping.type === 'Networks') {
50 const stringValue = String(value);
51 if (!stringValue.match(/^(host|bridge|none)$|^container:.+/)) {
52 return ({
53 path: 'networks',
54 value: { [stringValue]: {} },
55 }: ValueComposeEntry);
56 }
57
58 return ({
59 path: 'network_mode',
60 value: stringValue,
61 }: ValueComposeEntry);
62 }
63
64 if (mapping.type === 'Switch') {
65 return ({
66 path: mapping.path,
67 value: value === 'true' || value === true,
68 }: SwitchComposeEntry);
69 }
70
71 if (mapping.type === 'Gpus') {
72 return ({
73 path: 'deploy',
74 value: {
75 resources: {
76 reservations: {
77 devices: [
78 {
79 driver: 'nvidia',
80 count: value === 'all' ? 'all' : parseInt(value, 10),
81 capabilities: ['gpu'],
82 },
83 ],
84 },
85 },
86 },
87 }: KVComposeEntry);
88 }
89
90 if (mapping.type === 'Envs') {
91 const values = Array.isArray(value) ? value : [value];
92
93 return values.map((_value) => {
94 const [k, ...v] = String(_value).split('=');
95 return ({
96 path: mapping.path,
97 value: [v.length ? `${k}=${stripQuotes(v.join('='))}` : k],

Callers 1

maybeGetComposeEntryFunction · 0.85

Calls 2

stripQuotesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…