@supernova-studio/client 1.17.2 → 1.18.0
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.
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +115 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17229,18 +17229,24 @@ var LocalProjectActionExecutor = class {
|
|
|
17229
17229
|
return this.artifactUpdate(trx);
|
|
17230
17230
|
case "ArtifactDelete":
|
|
17231
17231
|
return this.artifactDelete(trx);
|
|
17232
|
+
case "ArtifactMove":
|
|
17233
|
+
return this.artifactMove(trx);
|
|
17232
17234
|
case "FeatureCreate":
|
|
17233
17235
|
return this.featureCreate(trx);
|
|
17234
17236
|
case "FeatureDelete":
|
|
17235
17237
|
return this.featureDelete(trx);
|
|
17236
17238
|
case "FeatureUpdate":
|
|
17237
17239
|
return this.featureUpdate(trx);
|
|
17240
|
+
case "FeatureMove":
|
|
17241
|
+
return this.featureMove(trx);
|
|
17238
17242
|
case "SectionCreate":
|
|
17239
17243
|
return this.sectionCreate(trx);
|
|
17240
17244
|
case "SectionUpdate":
|
|
17241
17245
|
return this.sectionUpdate(trx);
|
|
17242
17246
|
case "SectionDelete":
|
|
17243
17247
|
return this.sectionDelete(trx);
|
|
17248
|
+
case "SectionMove":
|
|
17249
|
+
return this.sectionMove(trx);
|
|
17244
17250
|
}
|
|
17245
17251
|
}
|
|
17246
17252
|
//
|
|
@@ -17248,11 +17254,13 @@ var LocalProjectActionExecutor = class {
|
|
|
17248
17254
|
//
|
|
17249
17255
|
artifactCreate(trx) {
|
|
17250
17256
|
const { input } = trx;
|
|
17251
|
-
const { id } = input;
|
|
17257
|
+
const { id, afterArtifactId, sectionId } = input;
|
|
17258
|
+
const sortOrder = this.calculateItemSortOrder(this.artifacts, afterArtifactId, sectionId);
|
|
17252
17259
|
this.artifacts.set(id, {
|
|
17253
17260
|
id,
|
|
17254
17261
|
projectId: this.projectId,
|
|
17255
|
-
|
|
17262
|
+
sectionId,
|
|
17263
|
+
sortOrder,
|
|
17256
17264
|
title: input.title,
|
|
17257
17265
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
17258
17266
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -17273,6 +17281,21 @@ var LocalProjectActionExecutor = class {
|
|
|
17273
17281
|
};
|
|
17274
17282
|
this.artifacts.set(id, mergedArtifact);
|
|
17275
17283
|
}
|
|
17284
|
+
artifactMove(trx) {
|
|
17285
|
+
const { input } = trx;
|
|
17286
|
+
const { id, afterId, sectionId } = input;
|
|
17287
|
+
const existingArtifact = this.artifacts.get(id);
|
|
17288
|
+
if (!existingArtifact) {
|
|
17289
|
+
throw new Error(`Cannot move artifact: artifact ${id} was not found in local storage`);
|
|
17290
|
+
}
|
|
17291
|
+
const sortOrder = this.calculateItemSortOrder(this.artifacts, afterId, sectionId);
|
|
17292
|
+
const mergedArtifact = {
|
|
17293
|
+
...existingArtifact,
|
|
17294
|
+
sortOrder,
|
|
17295
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17296
|
+
};
|
|
17297
|
+
this.artifacts.set(id, mergedArtifact);
|
|
17298
|
+
}
|
|
17276
17299
|
artifactDelete(trx) {
|
|
17277
17300
|
const { input } = trx;
|
|
17278
17301
|
const { id } = input;
|
|
@@ -17285,14 +17308,15 @@ var LocalProjectActionExecutor = class {
|
|
|
17285
17308
|
//
|
|
17286
17309
|
featureCreate(trx) {
|
|
17287
17310
|
const { input } = trx;
|
|
17288
|
-
const { id } = input;
|
|
17311
|
+
const { id, afterFeatureId, sectionId } = input;
|
|
17312
|
+
const sortOrder = this.calculateItemSortOrder(this.features, afterFeatureId, sectionId);
|
|
17289
17313
|
this.features.set(id, {
|
|
17290
17314
|
id,
|
|
17291
17315
|
projectId: this.projectId,
|
|
17292
17316
|
description: input.description,
|
|
17293
17317
|
isArchived: false,
|
|
17294
17318
|
sectionId: input.sectionId,
|
|
17295
|
-
sortOrder
|
|
17319
|
+
sortOrder,
|
|
17296
17320
|
name: input.name,
|
|
17297
17321
|
status: "Draft",
|
|
17298
17322
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
@@ -17317,6 +17341,21 @@ var LocalProjectActionExecutor = class {
|
|
|
17317
17341
|
};
|
|
17318
17342
|
this.features.set(id, mergedFeature);
|
|
17319
17343
|
}
|
|
17344
|
+
featureMove(trx) {
|
|
17345
|
+
const { input } = trx;
|
|
17346
|
+
const { id, afterId, sectionId } = input;
|
|
17347
|
+
const existingFeature = this.features.get(id);
|
|
17348
|
+
if (!existingFeature) {
|
|
17349
|
+
throw new Error(`Cannot move feature: feature ${id} was not found in local storage`);
|
|
17350
|
+
}
|
|
17351
|
+
const sortOrder = this.calculateItemSortOrder(this.features, afterId, sectionId);
|
|
17352
|
+
const mergedFeature = {
|
|
17353
|
+
...existingFeature,
|
|
17354
|
+
sortOrder,
|
|
17355
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17356
|
+
};
|
|
17357
|
+
this.features.set(id, mergedFeature);
|
|
17358
|
+
}
|
|
17320
17359
|
featureDelete(trx) {
|
|
17321
17360
|
const { input } = trx;
|
|
17322
17361
|
const { id } = input;
|
|
@@ -17329,15 +17368,15 @@ var LocalProjectActionExecutor = class {
|
|
|
17329
17368
|
//
|
|
17330
17369
|
sectionCreate(trx) {
|
|
17331
17370
|
const { input } = trx;
|
|
17332
|
-
const { id } = input;
|
|
17371
|
+
const { id, afterSectionId } = input;
|
|
17333
17372
|
const sections = input.childType === "Artifact" ? this.artifactSections : this.featureSections;
|
|
17373
|
+
const sortOrder = this.calculateSectionSortOrder(sections, afterSectionId);
|
|
17334
17374
|
sections.set(id, {
|
|
17335
17375
|
id,
|
|
17336
17376
|
projectId: this.projectId,
|
|
17337
17377
|
name: input.name,
|
|
17338
17378
|
childType: input.childType,
|
|
17339
|
-
sortOrder
|
|
17340
|
-
// TODO: Use Roman's calculate functions
|
|
17379
|
+
sortOrder,
|
|
17341
17380
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
17342
17381
|
createdAt: /* @__PURE__ */ new Date()
|
|
17343
17382
|
});
|
|
@@ -17357,6 +17396,22 @@ var LocalProjectActionExecutor = class {
|
|
|
17357
17396
|
const sections = existingSection.childType === "Artifact" ? this.artifactSections : this.featureSections;
|
|
17358
17397
|
sections.set(id, mergedSection);
|
|
17359
17398
|
}
|
|
17399
|
+
sectionMove(trx) {
|
|
17400
|
+
const { input } = trx;
|
|
17401
|
+
const { id, afterSectionId } = input;
|
|
17402
|
+
const existingSection = this.artifactSections.get(id) ?? this.featureSections.get(id);
|
|
17403
|
+
if (!existingSection) {
|
|
17404
|
+
throw new Error(`Cannot move section: section ${id} was not found in local storage`);
|
|
17405
|
+
}
|
|
17406
|
+
const sections = existingSection.childType === "Artifact" ? this.artifactSections : this.featureSections;
|
|
17407
|
+
const sortOrder = this.calculateSectionSortOrder(sections, afterSectionId);
|
|
17408
|
+
const mergedSection = {
|
|
17409
|
+
...existingSection,
|
|
17410
|
+
sortOrder,
|
|
17411
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17412
|
+
};
|
|
17413
|
+
sections.set(id, mergedSection);
|
|
17414
|
+
}
|
|
17360
17415
|
sectionDelete(trx) {
|
|
17361
17416
|
const { input } = trx;
|
|
17362
17417
|
const { id } = input;
|
|
@@ -17366,6 +17421,59 @@ var LocalProjectActionExecutor = class {
|
|
|
17366
17421
|
throw new Error(`Cannot delete section: section ${id} was not found in local storage`);
|
|
17367
17422
|
}
|
|
17368
17423
|
}
|
|
17424
|
+
calculateSectionSortOrder(items, afterItemId) {
|
|
17425
|
+
const sortedItems = Array.from(items.values()).sort((a, b) => a.sortOrder - b.sortOrder);
|
|
17426
|
+
const sortOrder = this.calculateSortOrderNoDb(
|
|
17427
|
+
(pId) => sortedItems.find((s) => s.projectId === pId),
|
|
17428
|
+
(pId) => sortedItems.findLast((s) => s.projectId === pId),
|
|
17429
|
+
(pId, id) => sortedItems.find((s) => s.projectId === pId && s.id === id),
|
|
17430
|
+
(pId, sortOrder2) => sortedItems.find((s) => s.projectId === pId && s.sortOrder > sortOrder2),
|
|
17431
|
+
(pId, sortOrder2, step) => items.forEach((s) => s.sortOrder > sortOrder2 && s.projectId === pId ? s.sortOrder += step : {}),
|
|
17432
|
+
this.projectId,
|
|
17433
|
+
afterItemId
|
|
17434
|
+
);
|
|
17435
|
+
return sortOrder ?? 0;
|
|
17436
|
+
}
|
|
17437
|
+
calculateItemSortOrder(items, afterItemId, sectionId) {
|
|
17438
|
+
const sortedItems = Array.from(items.values()).sort((a, b) => a.sortOrder - b.sortOrder);
|
|
17439
|
+
const matchIds = (i, pId, sId) => i.sectionId === sId && i.projectId === pId;
|
|
17440
|
+
const sortOrder = this.calculateSortOrderNoDb(
|
|
17441
|
+
(pId, sId) => sortedItems.find((i) => matchIds(i, pId, sId)),
|
|
17442
|
+
(pId, sId) => sortedItems.findLast((i) => matchIds(i, pId, sId)),
|
|
17443
|
+
(pId, id, sId) => sortedItems.find((i) => i.id === id && matchIds(i, pId, sId)),
|
|
17444
|
+
(pId, sortOrder2, sId) => sortedItems.find((i) => i.sortOrder > sortOrder2 && matchIds(i, pId, sId)),
|
|
17445
|
+
(pId, sortOrder2, step, sId) => items.forEach((i) => i.sortOrder > sortOrder2 && matchIds(i, pId, sId) ? i.sortOrder += step : {}),
|
|
17446
|
+
this.projectId,
|
|
17447
|
+
afterItemId,
|
|
17448
|
+
sectionId ?? void 0
|
|
17449
|
+
);
|
|
17450
|
+
return sortOrder ?? 0;
|
|
17451
|
+
}
|
|
17452
|
+
// See also calculateSectionSortOrder and calculateSectionedItemSortOrder
|
|
17453
|
+
calculateSortOrderNoDb(findFirst, findLast, findUnique, findNext, shiftAfter, projectId, afterItemId, sectionId) {
|
|
17454
|
+
const SORT_ORDER_STEP = 1e3;
|
|
17455
|
+
if (afterItemId === void 0) {
|
|
17456
|
+
const lastSection = findLast(projectId, sectionId);
|
|
17457
|
+
return (lastSection?.sortOrder ?? 0) + SORT_ORDER_STEP;
|
|
17458
|
+
} else if (afterItemId === null) {
|
|
17459
|
+
const firstSection = findFirst(projectId, sectionId);
|
|
17460
|
+
return (firstSection?.sortOrder ?? SORT_ORDER_STEP) - SORT_ORDER_STEP;
|
|
17461
|
+
} else {
|
|
17462
|
+
const targetSection = findUnique(projectId, afterItemId, sectionId);
|
|
17463
|
+
if (!targetSection) return null;
|
|
17464
|
+
const nextSection = findNext(projectId, targetSection.sortOrder, sectionId);
|
|
17465
|
+
if (nextSection) {
|
|
17466
|
+
let newSortOrder = Math.floor((targetSection.sortOrder + nextSection.sortOrder) / 2);
|
|
17467
|
+
if (newSortOrder <= targetSection.sortOrder) {
|
|
17468
|
+
newSortOrder = targetSection.sortOrder + SORT_ORDER_STEP / 2;
|
|
17469
|
+
shiftAfter(projectId, targetSection.sortOrder, SORT_ORDER_STEP, sectionId);
|
|
17470
|
+
}
|
|
17471
|
+
return newSortOrder;
|
|
17472
|
+
} else {
|
|
17473
|
+
return targetSection.sortOrder + SORT_ORDER_STEP;
|
|
17474
|
+
}
|
|
17475
|
+
}
|
|
17476
|
+
}
|
|
17369
17477
|
};
|
|
17370
17478
|
|
|
17371
17479
|
// src/sync/project-content-repo.ts
|