Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-onions-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@getlang/get": patch
---

paint inputs
13 changes: 10 additions & 3 deletions packages/get/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export async function callModule(
const [inputArgs, attrArgs] = partition(Object.entries(args.data), e =>
entry.inputs.has(e[0]),
)
const inputs = Object.fromEntries(inputArgs)
const inputs = materialize({
data: Object.fromEntries(inputArgs),
typeInfo: args.typeInfo,
})

let extracted = await hooks.call(module, inputs)
if (typeof extracted === 'undefined') {
extracted = await execute(entry, inputs)
Expand Down Expand Up @@ -96,7 +100,10 @@ export async function callModule(
return extracted
}

const data = Object.fromEntries(attrArgs)
const raster = materialize({ data, typeInfo: args.typeInfo })
const raster = materialize({
data: Object.fromEntries(attrArgs),
typeInfo: args.typeInfo,
})

return { ...raster, ...extracted }
}
27 changes: 13 additions & 14 deletions packages/get/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,19 @@ export async function execute(
},

ModuleExpr(node) {
if (node.call) {
return callModule(
registry,
executeModule,
hooks,
node.module.value,
node.args,
scope.context?.typeInfo,
)
}
return {
data: materialize(node.args),
typeInfo: node.typeInfo,
}
return node.call
? callModule(
registry,
executeModule,
hooks,
node.module.value,
node.args,
scope.context?.typeInfo,
)
: {
data: materialize(node.args),
typeInfo: node.typeInfo,
}
},

ObjectEntryExpr(node) {
Expand Down
25 changes: 21 additions & 4 deletions test/modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ describe('modules', () => {
})
})

test('paint inputs', async () => {
const modules = {
Reverse: `
inputs { list }
set result = | list.map(x => Number(x) * 10).reverse() |
extract { $result }
`,
Home: `
set list = "<ul><li>1</li><li>2</li><li>3</li></ul>" -> @html => li
extract @Reverse({ $list }) -> result
`,
}

const result = await execute(modules)
expect(result).toEqual([30, 20, 10])
})

test('drill return value', async () => {
const modules = {
Req: `
Expand Down Expand Up @@ -396,10 +413,10 @@ describe('modules', () => {
{
fetch: () =>
new Response(`
<!doctype html>
<div data-json='{"x": 1}'><p>first</p></li>
<div data-json='{"y": 2}'><p>second</p></li>
`),
<!doctype html>
<div data-json='{"x": 1}'><p>first</p></li>
<div data-json='{"y": 2}'><p>second</p></li>
`),
},
)

Expand Down