Build and Push Docker Container / build-and-push (push) Successful in 3m31s
- Serialize property set and remove commands per vault note to avoid lost frontmatter writes. - Wait briefly for successful property writes to hit disk before releasing the note lock. - Return property path, name, value, type, operation, and ok status in n8n outputs. - Include property details on continue-on-fail errors so failed items are visible in n8n. - Bump obsidian-api to 1.0.7 and n8n-nodes-obsidian-cli-api to 0.2.8. - Add regression coverage for concurrent property writes to the same note.
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import type {
|
|
IExecuteFunctions,
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
import { executeObsidianCommand } from '../../shared/ObsidianApiClient';
|
|
import { buildArgs } from './argBuilders';
|
|
import { nodeDescription } from './description';
|
|
import { outputForResult } from './output';
|
|
|
|
export class ObsidianApi implements INodeType {
|
|
description: INodeTypeDescription = nodeDescription;
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
const returnData: INodeExecutionData[] = [];
|
|
|
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
try {
|
|
const resource = this.getNodeParameter('resource', itemIndex) as string;
|
|
const operation = this.getNodeParameter('operation', itemIndex) as string;
|
|
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {}) as Record<string, unknown>;
|
|
const vault = String(additionalFields.vault || '');
|
|
const timeout = Number(additionalFields.timeout ?? 60);
|
|
const args = buildArgs(this, resource, operation, itemIndex, additionalFields);
|
|
const result = await executeObsidianCommand(this, itemIndex, args, { vault, timeout });
|
|
|
|
returnData.push(outputForResult(result, resource, operation, itemIndex));
|
|
} catch (error) {
|
|
if (this.continueOnFail()) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
const resource = this.getNodeParameter('resource', itemIndex, '') as string;
|
|
const operation = this.getNodeParameter('operation', itemIndex, '') as string;
|
|
const failure = resource === 'property'
|
|
? {
|
|
ok: false,
|
|
operation,
|
|
path: this.getNodeParameter('propertyPath', itemIndex, '') as string,
|
|
property: this.getNodeParameter('propertyName', itemIndex, '') as string,
|
|
value: this.getNodeParameter('propertyValue', itemIndex, '') as string,
|
|
type: this.getNodeParameter('propertyType', itemIndex, '') as string,
|
|
error: message,
|
|
}
|
|
: { ok: false, error: message };
|
|
returnData.push({ json: failure, pairedItem: { item: itemIndex } });
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
return [returnData];
|
|
}
|
|
}
|