Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: context should be read-only #208

Merged
merged 2 commits into from
Mar 19, 2024
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/eight-ants-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"barnard59-core": major
---

Freeze pipeline context object to prevent accidental modifications
2 changes: 1 addition & 1 deletion packages/core/lib/factory/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function createPipeline(maybePtr: { term?: Term; dataset?: DatasetCore }, init:
context.createPipeline = (ptr, { context, ...args } = {}) => createPipeline(ptr, { ...defaults, ...args })

pipeline.variables = variables
pipeline.context = context
pipeline.context = Object.freeze(context)

for (const stepPtr of ptr.out(context.env.ns.p.steps).out(context.env.ns.p.stepList).list()!) {
if (stepPtr.has(context.env.ns.rdf.type, context.env.ns.p.Pipeline).terms.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/Pipeline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Pipeline', () => {

await finished(pipeline.stream)

strictEqual(pipeline.context.content.toString(), 'test')
strictEqual(pipeline.context.variables.get('input').toString(), 'test')
})

it('should support nested pipelines', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/support/definitions/write.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
code:implementedBy [ a code:EcmaScriptModule;
code:link <node:barnard59-base#map>
];
code:arguments ("""input => {
this.content = input
code:arguments ("""function (input) {
this.variables.set('input', input)

return input
}"""^^code:EcmaScript).
Expand Down
Loading