Skip to content

Commit b8d8796

Browse files
committed
refactor: simplify resource ID generation logic
- Updated the generateResourceId function to streamline ID creation by removing the uniqueness check and directly incorporating the resource's short ID. - Removed the existingIds parameter, enhancing the function's usability and reducing complexity in the pullResourceType function.
1 parent 50bfd3c commit b8d8796

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

src/pull.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,10 @@ function extractName(resource: VapiResource): string | undefined {
141141
return undefined;
142142
}
143143

144-
function generateResourceId(resource: VapiResource, existingIds: Set<string>): string {
144+
function generateResourceId(resource: VapiResource): string {
145145
const name = extractName(resource);
146-
const baseName = name
147-
? slugify(name)
148-
: `resource-${resource.id.slice(0, 8)}`;
149-
150-
let resourceId = baseName;
151-
let counter = 1;
152-
153-
// Ensure uniqueness
154-
while (existingIds.has(resourceId)) {
155-
resourceId = `${baseName}-${counter}`;
156-
counter++;
157-
}
158-
159-
return resourceId;
146+
const shortId = resource.id.slice(0, 8);
147+
return name ? `${slugify(name)}-${shortId}` : `resource-${shortId}`;
160148
}
161149

162150
// ─────────────────────────────────────────────────────────────────────────────
@@ -407,7 +395,6 @@ export async function pullResourceType(
407395
console.log(` Found ${resources.length} ${resourceType} in Vapi`);
408396

409397
const reverseMap = buildReverseMap(state, resourceType);
410-
const existingIds = new Set(Object.keys(state[resourceType]));
411398
const newStateSection: Record<string, string> = {};
412399

413400
let created = 0;
@@ -420,9 +407,7 @@ export async function pullResourceType(
420407
const isNew = !resourceId;
421408

422409
if (!resourceId) {
423-
// Generate new resource ID
424-
resourceId = generateResourceId(resource, existingIds);
425-
existingIds.add(resourceId);
410+
resourceId = generateResourceId(resource);
426411
}
427412

428413
// Skip files that have been locally modified or deleted (default mode)

0 commit comments

Comments
 (0)