Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import type { Project } from '@n8n/db';
|
|
import { generateNanoId, VariablesRepository } from '@n8n/db';
|
|
import { Container } from '@n8n/di';
|
|
import { randomString } from 'n8n-workflow';
|
|
|
|
import { VariablesService } from '@/environments.ee/variables/variables.service.ee';
|
|
|
|
export async function createVariable(key = randomString(5), value = randomString(5)) {
|
|
const result = await Container.get(VariablesRepository).save({
|
|
id: generateNanoId(),
|
|
key,
|
|
value,
|
|
});
|
|
await Container.get(VariablesService).updateCache();
|
|
return result;
|
|
}
|
|
|
|
export async function createProjectVariable(
|
|
key = randomString(5),
|
|
value = randomString(5),
|
|
project: Project,
|
|
) {
|
|
const result = await Container.get(VariablesRepository).save({
|
|
id: generateNanoId(),
|
|
key,
|
|
value,
|
|
project,
|
|
});
|
|
|
|
await Container.get(VariablesService).updateCache();
|
|
return result;
|
|
}
|
|
|
|
export async function getVariableByIdOrFail(id: string) {
|
|
return await Container.get(VariablesRepository).findOneOrFail({
|
|
where: { id },
|
|
relations: ['project'],
|
|
});
|
|
}
|
|
|
|
export async function getVariableByKey(key: string) {
|
|
return await Container.get(VariablesRepository).findOne({
|
|
where: {
|
|
key,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getVariableById(id: string) {
|
|
return await Container.get(VariablesRepository).findOne({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
}
|