Skip to content

Commit 87a0ec9

Browse files
authored
Merge pull request #57 from getlang-dev/paint-inputs
paint inputs
2 parents 72f2de1 + 7b30853 commit 87a0ec9

4 files changed

Lines changed: 49 additions & 21 deletions

File tree

.changeset/proud-onions-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@getlang/get": patch
3+
---
4+
5+
paint inputs

packages/get/src/calls.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ export async function callModule(
6868
const [inputArgs, attrArgs] = partition(Object.entries(args.data), e =>
6969
entry.inputs.has(e[0]),
7070
)
71-
const inputs = Object.fromEntries(inputArgs)
71+
const inputs = materialize({
72+
data: Object.fromEntries(inputArgs),
73+
typeInfo: args.typeInfo,
74+
})
75+
7276
let extracted = await hooks.call(module, inputs)
7377
if (typeof extracted === 'undefined') {
7478
extracted = await execute(entry, inputs)
@@ -96,7 +100,10 @@ export async function callModule(
96100
return extracted
97101
}
98102

99-
const data = Object.fromEntries(attrArgs)
100-
const raster = materialize({ data, typeInfo: args.typeInfo })
103+
const raster = materialize({
104+
data: Object.fromEntries(attrArgs),
105+
typeInfo: args.typeInfo,
106+
})
107+
101108
return { ...raster, ...extracted }
102109
}

packages/get/src/execute.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,19 @@ export async function execute(
165165
},
166166

167167
ModuleExpr(node) {
168-
if (node.call) {
169-
return callModule(
170-
registry,
171-
executeModule,
172-
hooks,
173-
node.module.value,
174-
node.args,
175-
scope.context?.typeInfo,
176-
)
177-
}
178-
return {
179-
data: materialize(node.args),
180-
typeInfo: node.typeInfo,
181-
}
168+
return node.call
169+
? callModule(
170+
registry,
171+
executeModule,
172+
hooks,
173+
node.module.value,
174+
node.args,
175+
scope.context?.typeInfo,
176+
)
177+
: {
178+
data: materialize(node.args),
179+
typeInfo: node.typeInfo,
180+
}
182181
},
183182

184183
ObjectEntryExpr(node) {

test/modules.spec.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ describe('modules', () => {
219219
})
220220
})
221221

222+
test('paint inputs', async () => {
223+
const modules = {
224+
Reverse: `
225+
inputs { list }
226+
set result = | list.map(x => Number(x) * 10).reverse() |
227+
extract { $result }
228+
`,
229+
Home: `
230+
set list = "<ul><li>1</li><li>2</li><li>3</li></ul>" -> @html => li
231+
extract @Reverse({ $list }) -> result
232+
`,
233+
}
234+
235+
const result = await execute(modules)
236+
expect(result).toEqual([30, 20, 10])
237+
})
238+
222239
test('drill return value', async () => {
223240
const modules = {
224241
Req: `
@@ -396,10 +413,10 @@ describe('modules', () => {
396413
{
397414
fetch: () =>
398415
new Response(`
399-
<!doctype html>
400-
<div data-json='{"x": 1}'><p>first</p></li>
401-
<div data-json='{"y": 2}'><p>second</p></li>
402-
`),
416+
<!doctype html>
417+
<div data-json='{"x": 1}'><p>first</p></li>
418+
<div data-json='{"y": 2}'><p>second</p></li>
419+
`),
403420
},
404421
)
405422

0 commit comments

Comments
 (0)