chore: format group HTTP mapping changes

This commit is contained in:
gfwangjie 2026-05-21 13:24:03 +08:00
parent ccbc284cff
commit 31b826c960
5 changed files with 22 additions and 24 deletions

View file

@ -29,9 +29,8 @@ export function registerGroupCommands(program: Command): void {
)
.action(async (groupName: string, groupPath: string, registryName: string) => {
const { getGroupDir, getDefaultGitnexusDir } = await import('../core/group/storage.js');
const { loadGroupConfig, serializeGroupConfig } = await import(
'../core/group/config-parser.js'
);
const { loadGroupConfig, serializeGroupConfig } =
await import('../core/group/config-parser.js');
const path = await import('node:path');
const fs = await import('node:fs/promises');
const groupDir = getGroupDir(getDefaultGitnexusDir(), groupName);
@ -52,9 +51,8 @@ export function registerGroupCommands(program: Command): void {
.description('Remove a repo from a group')
.action(async (groupName: string, repoPath: string) => {
const { getGroupDir, getDefaultGitnexusDir } = await import('../core/group/storage.js');
const { loadGroupConfig, serializeGroupConfig } = await import(
'../core/group/config-parser.js'
);
const { loadGroupConfig, serializeGroupConfig } =
await import('../core/group/config-parser.js');
const path = await import('node:path');
const fs = await import('node:fs/promises');
const groupDir = getGroupDir(getDefaultGitnexusDir(), groupName);

View file

@ -136,9 +136,7 @@ export function parseGroupConfig(yamlContent: string): GroupConfig {
}
const target = mapping.to as Record<string, unknown>;
if (!target.repo || !repoPaths.has(target.repo as string)) {
throw new Error(
`http_mappings[${i}].to.repo "${target.repo}" does not match any repo path`,
);
throw new Error(`http_mappings[${i}].to.repo "${target.repo}" does not match any repo path`);
}
if (mapping.match === undefined || String(mapping.match).trim() === '') {
throw new Error(`http_mappings[${i}].match is required`);
@ -152,7 +150,9 @@ export function parseGroupConfig(yamlContent: string): GroupConfig {
if (!Array.isArray(mapping.methods)) {
throw new Error(`http_mappings[${i}].methods must be an array when provided`);
}
methods = mapping.methods.map((method) => String(method).trim().toUpperCase()).filter(Boolean);
methods = mapping.methods
.map((method) => String(method).trim().toUpperCase())
.filter(Boolean);
if (methods.length === 0) {
throw new Error(`http_mappings[${i}].methods must not be empty`);
}
@ -160,7 +160,11 @@ export function parseGroupConfig(yamlContent: string): GroupConfig {
let when: Record<string, string> | undefined;
if (mapping.when !== undefined) {
if (typeof mapping.when !== 'object' || Array.isArray(mapping.when) || mapping.when === null) {
if (
typeof mapping.when !== 'object' ||
Array.isArray(mapping.when) ||
mapping.when === null
) {
throw new Error(`http_mappings[${i}].when must be an object when provided`);
}
when = Object.fromEntries(
@ -176,7 +180,9 @@ export function parseGroupConfig(yamlContent: string): GroupConfig {
to: {
repo: target.repo as string,
service:
target.service === undefined || target.service === null ? undefined : String(target.service),
target.service === undefined || target.service === null
? undefined
: String(target.service),
},
methods,
match: String(mapping.match),

View file

@ -74,7 +74,9 @@ export function applyHttpMappings(
}
const compiledRules = compileRules(rules);
const providers = contracts.filter((contract) => contract.role === 'provider' && contract.type === 'http');
const providers = contracts.filter(
(contract) => contract.role === 'provider' && contract.type === 'http',
);
const providerIndex = new Map<string, StoredContract[]>();
for (const provider of providers) {
const key = providerIndexKey(provider.contractId);

View file

@ -131,8 +131,6 @@ http_mappings:
expect(result.crossLinks).toHaveLength(1);
expect(result.crossLinks[0].matchType).toBe('manifest');
expect(result.crossLinks[0].contractId).toBe('http::POST::/orders/create');
expect(result.crossLinks[0].fromContractId).toBe(
'http::POST::/api/titans/order/1.0.0/create',
);
expect(result.crossLinks[0].fromContractId).toBe('http::POST::/api/titans/order/1.0.0/create');
});
});

View file

@ -138,11 +138,7 @@ describe('syncGroup', () => {
const mockContracts: StoredContract[] = [
{
...makeContract(
'http::POST::/api/titans/order/1.0.0/create',
'consumer',
'frontend',
),
...makeContract('http::POST::/api/titans/order/1.0.0/create', 'consumer', 'frontend'),
meta: { method: 'POST', path: '/api/titans/order/1.0.0/create' },
},
{
@ -160,9 +156,7 @@ describe('syncGroup', () => {
expect(result.crossLinks).toHaveLength(1);
expect(result.crossLinks[0].matchType).toBe('manifest');
expect(result.crossLinks[0].contractId).toBe('http::POST::/orders/create');
expect(result.crossLinks[0].fromContractId).toBe(
'http::POST::/api/titans/order/1.0.0/create',
);
expect(result.crossLinks[0].fromContractId).toBe('http::POST::/api/titans/order/1.0.0/create');
expect(result.crossLinks[0].toContractId).toBe('http::POST::/orders/create');
expect(result.crossLinks[0].to.service).toBe('services/order');
expect(result.unmatched).toHaveLength(0);