@probelabs/probe 0.6.0-rc274 → 0.6.0-rc275

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31292,13 +31292,44 @@ var init_TaskManager = __esm({
31292
31292
  this.tasks = newTasks;
31293
31293
  }
31294
31294
  /**
31295
- * Create multiple tasks in batch
31295
+ * Create multiple tasks in batch, resolving user-provided IDs to auto-generated IDs.
31296
+ * If any task fails validation, no tasks are created (atomic operation).
31296
31297
  * @param {Object[]} tasksData - Array of task data objects
31297
31298
  * @returns {Task[]} Created tasks
31298
31299
  */
31299
31300
  createTasks(tasksData) {
31300
- const createdTasks = [];
31301
+ const idMap = /* @__PURE__ */ new Map();
31302
+ const batchAutoIds = /* @__PURE__ */ new Set();
31303
+ let nextCounter = this.taskCounter;
31301
31304
  for (const taskData of tasksData) {
31305
+ nextCounter++;
31306
+ const autoId = `task-${nextCounter}`;
31307
+ batchAutoIds.add(autoId);
31308
+ if (taskData.id) {
31309
+ idMap.set(taskData.id, autoId);
31310
+ }
31311
+ }
31312
+ const resolvedTasksData = tasksData.map((taskData) => {
31313
+ const resolved = { ...taskData };
31314
+ delete resolved.id;
31315
+ if (resolved.dependencies) {
31316
+ resolved.dependencies = resolved.dependencies.map((depId) => {
31317
+ if (idMap.has(depId)) return idMap.get(depId);
31318
+ if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
31319
+ throw new Error(`Dependency "${depId}" does not exist. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
31320
+ });
31321
+ }
31322
+ if (resolved.after) {
31323
+ if (idMap.has(resolved.after)) {
31324
+ resolved.after = idMap.get(resolved.after);
31325
+ } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
31326
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
31327
+ }
31328
+ }
31329
+ return resolved;
31330
+ });
31331
+ const createdTasks = [];
31332
+ for (const taskData of resolvedTasksData) {
31302
31333
  const task = this.createTask(taskData);
31303
31334
  createdTasks.push(task);
31304
31335
  }
@@ -132,14 +132,53 @@ export class TaskManager {
132
132
  }
133
133
 
134
134
  /**
135
- * Create multiple tasks in batch
135
+ * Create multiple tasks in batch, resolving user-provided IDs to auto-generated IDs.
136
+ * If any task fails validation, no tasks are created (atomic operation).
136
137
  * @param {Object[]} tasksData - Array of task data objects
137
138
  * @returns {Task[]} Created tasks
138
139
  */
139
140
  createTasks(tasksData) {
140
- const createdTasks = [];
141
-
141
+ // Build a mapping of user-provided IDs to future auto-generated IDs
142
+ const idMap = new Map();
143
+ const batchAutoIds = new Set();
144
+ let nextCounter = this.taskCounter;
142
145
  for (const taskData of tasksData) {
146
+ nextCounter++;
147
+ const autoId = `task-${nextCounter}`;
148
+ batchAutoIds.add(autoId);
149
+ if (taskData.id) {
150
+ idMap.set(taskData.id, autoId);
151
+ }
152
+ }
153
+
154
+ // Resolve dependencies and "after" references, then validate before creating anything
155
+ const resolvedTasksData = tasksData.map(taskData => {
156
+ const resolved = { ...taskData };
157
+ delete resolved.id; // Don't pass user ID to createTask
158
+
159
+ if (resolved.dependencies) {
160
+ resolved.dependencies = resolved.dependencies.map(depId => {
161
+ if (idMap.has(depId)) return idMap.get(depId);
162
+ // Check if it's already an existing task ID or a batch auto-generated ID
163
+ if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
164
+ throw new Error(`Dependency "${depId}" does not exist. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
165
+ });
166
+ }
167
+
168
+ if (resolved.after) {
169
+ if (idMap.has(resolved.after)) {
170
+ resolved.after = idMap.get(resolved.after);
171
+ } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
172
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
173
+ }
174
+ }
175
+
176
+ return resolved;
177
+ });
178
+
179
+ // All validation passed — create tasks
180
+ const createdTasks = [];
181
+ for (const taskData of resolvedTasksData) {
143
182
  const task = this.createTask(taskData);
144
183
  createdTasks.push(task);
145
184
  }
@@ -58232,13 +58232,44 @@ var init_TaskManager = __esm({
58232
58232
  this.tasks = newTasks;
58233
58233
  }
58234
58234
  /**
58235
- * Create multiple tasks in batch
58235
+ * Create multiple tasks in batch, resolving user-provided IDs to auto-generated IDs.
58236
+ * If any task fails validation, no tasks are created (atomic operation).
58236
58237
  * @param {Object[]} tasksData - Array of task data objects
58237
58238
  * @returns {Task[]} Created tasks
58238
58239
  */
58239
58240
  createTasks(tasksData) {
58240
- const createdTasks = [];
58241
+ const idMap = /* @__PURE__ */ new Map();
58242
+ const batchAutoIds = /* @__PURE__ */ new Set();
58243
+ let nextCounter = this.taskCounter;
58241
58244
  for (const taskData of tasksData) {
58245
+ nextCounter++;
58246
+ const autoId = `task-${nextCounter}`;
58247
+ batchAutoIds.add(autoId);
58248
+ if (taskData.id) {
58249
+ idMap.set(taskData.id, autoId);
58250
+ }
58251
+ }
58252
+ const resolvedTasksData = tasksData.map((taskData) => {
58253
+ const resolved = { ...taskData };
58254
+ delete resolved.id;
58255
+ if (resolved.dependencies) {
58256
+ resolved.dependencies = resolved.dependencies.map((depId) => {
58257
+ if (idMap.has(depId)) return idMap.get(depId);
58258
+ if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
58259
+ throw new Error(`Dependency "${depId}" does not exist. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
58260
+ });
58261
+ }
58262
+ if (resolved.after) {
58263
+ if (idMap.has(resolved.after)) {
58264
+ resolved.after = idMap.get(resolved.after);
58265
+ } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
58266
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
58267
+ }
58268
+ }
58269
+ return resolved;
58270
+ });
58271
+ const createdTasks = [];
58272
+ for (const taskData of resolvedTasksData) {
58242
58273
  const task = this.createTask(taskData);
58243
58274
  createdTasks.push(task);
58244
58275
  }
package/cjs/index.cjs CHANGED
@@ -31368,13 +31368,44 @@ var init_TaskManager = __esm({
31368
31368
  this.tasks = newTasks;
31369
31369
  }
31370
31370
  /**
31371
- * Create multiple tasks in batch
31371
+ * Create multiple tasks in batch, resolving user-provided IDs to auto-generated IDs.
31372
+ * If any task fails validation, no tasks are created (atomic operation).
31372
31373
  * @param {Object[]} tasksData - Array of task data objects
31373
31374
  * @returns {Task[]} Created tasks
31374
31375
  */
31375
31376
  createTasks(tasksData) {
31376
- const createdTasks = [];
31377
+ const idMap = /* @__PURE__ */ new Map();
31378
+ const batchAutoIds = /* @__PURE__ */ new Set();
31379
+ let nextCounter = this.taskCounter;
31377
31380
  for (const taskData of tasksData) {
31381
+ nextCounter++;
31382
+ const autoId = `task-${nextCounter}`;
31383
+ batchAutoIds.add(autoId);
31384
+ if (taskData.id) {
31385
+ idMap.set(taskData.id, autoId);
31386
+ }
31387
+ }
31388
+ const resolvedTasksData = tasksData.map((taskData) => {
31389
+ const resolved = { ...taskData };
31390
+ delete resolved.id;
31391
+ if (resolved.dependencies) {
31392
+ resolved.dependencies = resolved.dependencies.map((depId) => {
31393
+ if (idMap.has(depId)) return idMap.get(depId);
31394
+ if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
31395
+ throw new Error(`Dependency "${depId}" does not exist. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
31396
+ });
31397
+ }
31398
+ if (resolved.after) {
31399
+ if (idMap.has(resolved.after)) {
31400
+ resolved.after = idMap.get(resolved.after);
31401
+ } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
31402
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
31403
+ }
31404
+ }
31405
+ return resolved;
31406
+ });
31407
+ const createdTasks = [];
31408
+ for (const taskData of resolvedTasksData) {
31378
31409
  const task = this.createTask(taskData);
31379
31410
  createdTasks.push(task);
31380
31411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc274",
3
+ "version": "0.6.0-rc275",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -132,14 +132,53 @@ export class TaskManager {
132
132
  }
133
133
 
134
134
  /**
135
- * Create multiple tasks in batch
135
+ * Create multiple tasks in batch, resolving user-provided IDs to auto-generated IDs.
136
+ * If any task fails validation, no tasks are created (atomic operation).
136
137
  * @param {Object[]} tasksData - Array of task data objects
137
138
  * @returns {Task[]} Created tasks
138
139
  */
139
140
  createTasks(tasksData) {
140
- const createdTasks = [];
141
-
141
+ // Build a mapping of user-provided IDs to future auto-generated IDs
142
+ const idMap = new Map();
143
+ const batchAutoIds = new Set();
144
+ let nextCounter = this.taskCounter;
142
145
  for (const taskData of tasksData) {
146
+ nextCounter++;
147
+ const autoId = `task-${nextCounter}`;
148
+ batchAutoIds.add(autoId);
149
+ if (taskData.id) {
150
+ idMap.set(taskData.id, autoId);
151
+ }
152
+ }
153
+
154
+ // Resolve dependencies and "after" references, then validate before creating anything
155
+ const resolvedTasksData = tasksData.map(taskData => {
156
+ const resolved = { ...taskData };
157
+ delete resolved.id; // Don't pass user ID to createTask
158
+
159
+ if (resolved.dependencies) {
160
+ resolved.dependencies = resolved.dependencies.map(depId => {
161
+ if (idMap.has(depId)) return idMap.get(depId);
162
+ // Check if it's already an existing task ID or a batch auto-generated ID
163
+ if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
164
+ throw new Error(`Dependency "${depId}" does not exist. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
165
+ });
166
+ }
167
+
168
+ if (resolved.after) {
169
+ if (idMap.has(resolved.after)) {
170
+ resolved.after = idMap.get(resolved.after);
171
+ } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
172
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
173
+ }
174
+ }
175
+
176
+ return resolved;
177
+ });
178
+
179
+ // All validation passed — create tasks
180
+ const createdTasks = [];
181
+ for (const taskData of resolvedTasksData) {
143
182
  const task = this.createTask(taskData);
144
183
  createdTasks.push(task);
145
184
  }