chrono-forge
Advanced tools
Comparing version 0.7.20 to 0.7.21
@@ -121,2 +121,3 @@ import EventEmitter from 'eventemitter3'; | ||
query(entityName: string, id: string, denormalizeData?: boolean): any; | ||
updateStateAtPath(entityName: string, id: string, entity: any, path: string, value: any): void; | ||
/** | ||
@@ -145,3 +146,2 @@ * Creates schemas dynamically based on the configuration provided. | ||
setState(newState: EntitiesState): void; | ||
updateStateAtPath(entityName: string, id: string, entity: any, path: string, value: any): void; | ||
} | ||
@@ -148,0 +148,0 @@ declare const _default: SchemaManager; |
@@ -288,5 +288,12 @@ "use strict"; | ||
set: (target, prop, value) => { | ||
this.updateStateAtPath(entityName, id, result, prop, value); | ||
this.updateStateAtPath(entityName, id, result, prop.toString(), value); | ||
target[prop] = value; | ||
return true; | ||
}, | ||
get: (target, prop) => { | ||
const val = target[prop]; | ||
if (Array.isArray(val) || (typeof val === 'object' && val !== null)) { | ||
return new Proxy(val, handler); // Recursively apply proxy | ||
} | ||
return val; | ||
} | ||
@@ -299,2 +306,23 @@ }; | ||
} | ||
updateStateAtPath(entityName, id, entity, path, value) { | ||
workflow.log.debug(`[SchemaManager]: updateStateAtPath(${entityName}.${id}.${path}) = ${value}...`); | ||
if (!entity) { | ||
throw new Error(`Entity ${entityName} with ID ${id} not found.`); | ||
} | ||
const existingValue = dottie_1.default.get(entity, path); | ||
if (Array.isArray(existingValue) && Array.isArray(value)) { | ||
dottie_1.default.set(entity, path, [...existingValue, ...value]); // Handle array concatenation | ||
} | ||
else if (Array.isArray(existingValue)) { | ||
dottie_1.default.set(entity, path, [...existingValue, value]); // Add single value to an array | ||
} | ||
else if (typeof existingValue === 'object' && typeof value === 'object') { | ||
dottie_1.default.set(entity, path, { ...existingValue, ...value }); // Merge objects | ||
} | ||
else { | ||
dottie_1.default.set(entity, path, value); // Set value directly | ||
} | ||
this.dispatch((0, entities_1.updateEntity)(entity, entityName), true, workflow.workflowInfo().workflowId); | ||
workflow.log.debug(`Updated state at path ${path} for ${entityName}:${id}`); | ||
} | ||
/** | ||
@@ -354,22 +382,2 @@ * Creates schemas dynamically based on the configuration provided. | ||
} | ||
updateStateAtPath(entityName, id, entity, path, value) { | ||
workflow.log.debug(`[SchemaManager]:updateStateAtPath(${entityName}.${id}.${path}) = ${value}...`); | ||
if (!entity) { | ||
throw new Error(`Entity ${entityName} with ID ${id} not found.`); | ||
} | ||
const existingValue = dottie_1.default.get(entity, path); | ||
if (Array.isArray(existingValue) && Array.isArray(value)) { | ||
// Handle array concatenation (like pushing to the array) | ||
dottie_1.default.set(entity, path, [...existingValue, ...value]); | ||
} | ||
else if (Array.isArray(existingValue)) { | ||
// Handle adding a single value to an array | ||
dottie_1.default.set(entity, path, [...existingValue, value]); | ||
} | ||
else { | ||
// Handle regular object or primitive value update | ||
dottie_1.default.set(entity, path, value); | ||
} | ||
this.dispatch((0, entities_1.updateEntity)(entity, entityName), true, workflow.workflowInfo().workflowId); | ||
} | ||
} | ||
@@ -376,0 +384,0 @@ exports.SchemaManager = SchemaManager; |
{ | ||
"name": "chrono-forge", | ||
"version": "0.7.20", | ||
"version": "0.7.21", | ||
"description": "A comprehensive framework for building resilient Temporal workflows, advanced state management, and real-time streaming activities in TypeScript. Designed for a seamless developer experience with powerful abstractions, dynamic orchestration, and full control over distributed systems.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
285850
3373