diff --git a/server/tool/src/initializer.ts b/server/tool/src/initializer.ts index 67d914865d..4da3975233 100644 --- a/server/tool/src/initializer.ts +++ b/server/tool/src/initializer.ts @@ -143,8 +143,8 @@ export class WorkspaceInitializer { const buffer = Buffer.from(await resp.arrayBuffer()) await this.storageAdapter.put(this.ctx, this.wsUrl, id, buffer, step.contentType, buffer.length) if (step.resultVariable !== undefined) { - vars[step.resultVariable] = id - vars[`${step.resultVariable}_size`] = buffer.length + vars[`\${${step.resultVariable}}`] = id + vars[`\${${step.resultVariable}_size}`] = buffer.length } } catch (error) { logger.error('Upload failed', error) @@ -159,7 +159,7 @@ export class WorkspaceInitializer { throw new Error(`Document not found: ${JSON.stringify(query)}`) } if (step.resultVariable !== undefined) { - vars[step.resultVariable] = res + vars[`\${${step.resultVariable}}`] = res } } @@ -188,7 +188,7 @@ export class WorkspaceInitializer { ): Promise { const _id = generateId() if (step.resultVariable !== undefined) { - vars[step.resultVariable] = _id + vars[`\${${step.resultVariable}}`] = _id } const data = await this.fillPropsWithMarkdown( { ...(defaults.get(step._class) ?? {}), ...step.data }, @@ -226,8 +226,15 @@ export class WorkspaceInitializer { ) { throw new Error('Add collection step must have attachedTo, attachedToClass, collection and space') } - return (await this.client.addCollection(_class, space, attachedTo, attachedToClass, collection, props), - _id) as unknown as Ref + return (await this.client.addCollection( + _class, + space, + attachedTo, + attachedToClass, + collection, + props, + _id as Ref | undefined + )) as unknown as Ref } else { const { space, ...props } = data if (space === undefined) { @@ -298,7 +305,7 @@ export class WorkspaceInitializer { const matched = fieldRegexp.exec(value) if (matched === null) break const result = vars[matched[0]] - if (result === undefined || typeof result !== 'string') { + if (result === undefined) { throw new Error(`Variable ${matched[0]} not found`) } else { value = value.replaceAll(matched[0], result)