maintain proper context in metadata.root and parent getters (#1917)
* fix(TRI-5140): maintain proper context in metadata.root and parent getters * Create two-tigers-dream.md --------- Co-authored-by: Eric Allam <eallam@icloud.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
maintain proper context in metadata.root and parent getters
|
||||
@@ -31,71 +31,83 @@ export class StandardMetadataManager implements RunMetadataManager {
|
||||
) {}
|
||||
|
||||
get parent(): RunMetadataUpdater {
|
||||
return {
|
||||
// Store a reference to 'this' to ensure proper context
|
||||
const self = this;
|
||||
|
||||
// Create the updater object and store it in a local variable
|
||||
const parentUpdater: RunMetadataUpdater = {
|
||||
set: (key, value) => {
|
||||
this.queuedParentOperations.add({ type: "set", key, value });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "set", key, value });
|
||||
return parentUpdater;
|
||||
},
|
||||
del: (key) => {
|
||||
this.queuedParentOperations.add({ type: "delete", key });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "delete", key });
|
||||
return parentUpdater;
|
||||
},
|
||||
append: (key, value) => {
|
||||
this.queuedParentOperations.add({ type: "append", key, value });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "append", key, value });
|
||||
return parentUpdater;
|
||||
},
|
||||
remove: (key, value) => {
|
||||
this.queuedParentOperations.add({ type: "remove", key, value });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "remove", key, value });
|
||||
return parentUpdater;
|
||||
},
|
||||
increment: (key, value) => {
|
||||
this.queuedParentOperations.add({ type: "increment", key, value });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "increment", key, value });
|
||||
return parentUpdater;
|
||||
},
|
||||
decrement: (key, value) => {
|
||||
this.queuedParentOperations.add({ type: "increment", key, value: -Math.abs(value) });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "increment", key, value: -Math.abs(value) });
|
||||
return parentUpdater;
|
||||
},
|
||||
update: (value) => {
|
||||
this.queuedParentOperations.add({ type: "update", value });
|
||||
return this.parent;
|
||||
self.queuedParentOperations.add({ type: "update", value });
|
||||
return parentUpdater;
|
||||
},
|
||||
stream: (key, value, signal) => this.doStream(key, value, "parent", this.parent, signal),
|
||||
stream: (key, value, signal) => self.doStream(key, value, "parent", parentUpdater, signal),
|
||||
};
|
||||
|
||||
return parentUpdater;
|
||||
}
|
||||
|
||||
get root(): RunMetadataUpdater {
|
||||
return {
|
||||
// Store a reference to 'this' to ensure proper context
|
||||
const self = this;
|
||||
|
||||
// Create the updater object and store it in a local variable
|
||||
const rootUpdater: RunMetadataUpdater = {
|
||||
set: (key, value) => {
|
||||
this.queuedRootOperations.add({ type: "set", key, value });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "set", key, value });
|
||||
return rootUpdater;
|
||||
},
|
||||
del: (key) => {
|
||||
this.queuedRootOperations.add({ type: "delete", key });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "delete", key });
|
||||
return rootUpdater;
|
||||
},
|
||||
append: (key, value) => {
|
||||
this.queuedRootOperations.add({ type: "append", key, value });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "append", key, value });
|
||||
return rootUpdater;
|
||||
},
|
||||
remove: (key, value) => {
|
||||
this.queuedRootOperations.add({ type: "remove", key, value });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "remove", key, value });
|
||||
return rootUpdater;
|
||||
},
|
||||
increment: (key, value) => {
|
||||
this.queuedRootOperations.add({ type: "increment", key, value });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "increment", key, value });
|
||||
return rootUpdater;
|
||||
},
|
||||
decrement: (key, value) => {
|
||||
this.queuedRootOperations.add({ type: "increment", key, value: -Math.abs(value) });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "increment", key, value: -Math.abs(value) });
|
||||
return rootUpdater;
|
||||
},
|
||||
update: (value) => {
|
||||
this.queuedRootOperations.add({ type: "update", value });
|
||||
return this.root;
|
||||
self.queuedRootOperations.add({ type: "update", value });
|
||||
return rootUpdater;
|
||||
},
|
||||
stream: (key, value, signal) => this.doStream(key, value, "root", this.root, signal),
|
||||
stream: (key, value, signal) => self.doStream(key, value, "root", rootUpdater, signal),
|
||||
};
|
||||
|
||||
return rootUpdater;
|
||||
}
|
||||
|
||||
public enterWithMetadata(metadata: Record<string, DeserializedJson>): void {
|
||||
|
||||
@@ -46,38 +46,50 @@ export class NoopRunMetadataManager implements RunMetadataManager {
|
||||
}
|
||||
|
||||
get parent(): RunMetadataUpdater {
|
||||
return {
|
||||
append: () => this.parent,
|
||||
set: () => this.parent,
|
||||
del: () => this.parent,
|
||||
increment: () => this.parent,
|
||||
decrement: () => this.parent,
|
||||
remove: () => this.parent,
|
||||
// Store a reference to this object
|
||||
const self = this;
|
||||
|
||||
// Create a local reference to ensure proper context
|
||||
const parentUpdater: RunMetadataUpdater = {
|
||||
append: () => parentUpdater,
|
||||
set: () => parentUpdater,
|
||||
del: () => parentUpdater,
|
||||
increment: () => parentUpdater,
|
||||
decrement: () => parentUpdater,
|
||||
remove: () => parentUpdater,
|
||||
stream: () =>
|
||||
Promise.resolve({
|
||||
[Symbol.asyncIterator]: () => ({
|
||||
next: () => Promise.resolve({ done: true, value: undefined }),
|
||||
}),
|
||||
}),
|
||||
update: () => this.parent,
|
||||
update: () => parentUpdater,
|
||||
};
|
||||
|
||||
return parentUpdater;
|
||||
}
|
||||
|
||||
get root(): RunMetadataUpdater {
|
||||
return {
|
||||
append: () => this.root,
|
||||
set: () => this.root,
|
||||
del: () => this.root,
|
||||
increment: () => this.root,
|
||||
decrement: () => this.root,
|
||||
remove: () => this.root,
|
||||
// Store a reference to this object
|
||||
const self = this;
|
||||
|
||||
// Create a local reference to ensure proper context
|
||||
const rootUpdater: RunMetadataUpdater = {
|
||||
append: () => rootUpdater,
|
||||
set: () => rootUpdater,
|
||||
del: () => rootUpdater,
|
||||
increment: () => rootUpdater,
|
||||
decrement: () => rootUpdater,
|
||||
remove: () => rootUpdater,
|
||||
stream: () =>
|
||||
Promise.resolve({
|
||||
[Symbol.asyncIterator]: () => ({
|
||||
next: () => Promise.resolve({ done: true, value: undefined }),
|
||||
}),
|
||||
}),
|
||||
update: () => this.root,
|
||||
update: () => rootUpdater,
|
||||
};
|
||||
|
||||
return rootUpdater;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user