@builder.io/ai-utils 0.12.20 → 0.12.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.12.20",
3
+ "version": "0.12.21",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/projects.d.ts CHANGED
@@ -276,7 +276,8 @@ export interface PartialBranchData {
276
276
  branchName: string;
277
277
  };
278
278
  }
279
- export interface Branch {
279
+ export type EntityState = "active" | "deleted";
280
+ interface BranchSharedData {
280
281
  lockedFusionEnvironment?: FusionExecutionEnvironment;
281
282
  id?: string;
282
283
  appName?: string | null;
@@ -310,13 +311,15 @@ export interface Branch {
310
311
  address: string | null;
311
312
  allocated: boolean | null;
312
313
  } | null;
313
- preRecoveryData?: Partial<Branch> & {
314
- recoveryDate: Date;
315
- };
316
314
  backup?: BranchBackup;
317
315
  metadata?: Record<string, unknown>;
318
316
  needsCleanup?: boolean;
317
+ /** The state of the branch. Use `isBranchDeleted()` helper for backwards-compatible checks. */
318
+ state?: EntityState;
319
+ /** @deprecated Use `state` field instead. Kept for backwards compatibility. */
319
320
  deleted?: boolean;
321
+ deletedAt?: string;
322
+ deletedBy?: string;
320
323
  updatedAt?: string;
321
324
  commitMode?: CommitMode;
322
325
  kubePodName?: string | null;
@@ -325,6 +328,33 @@ export interface Branch {
325
328
  kubeHostname?: string | null;
326
329
  checkoutBranch?: string | null;
327
330
  }
331
+ /**
332
+ * LegacyBranch represents branch data as stored in the nested project.branches field.
333
+ * This type does NOT include projectId or legacyId as those don't exist in the legacy format.
334
+ */
335
+ export interface LegacyBranch extends BranchSharedData {
336
+ preRecoveryData?: Partial<LegacyBranch> & {
337
+ recoveryDate: Date;
338
+ };
339
+ }
340
+ /**
341
+ * NewBranch represents branch data as stored in the standalone branches collection.
342
+ * Extends LegacyBranch with required projectId, name, and optional legacyId fields.
343
+ */
344
+ export interface NewBranch extends BranchSharedData {
345
+ /** The project this branch belongs to */
346
+ projectId: string;
347
+ /** The branch name (required in new collection) */
348
+ name: string;
349
+ /** Legacy ID for mapping to project.branches[branchName] format: ${projectId}-${branchName} */
350
+ legacyId: string;
351
+ }
352
+ /**
353
+ * Branch is a union type that can represent either a legacy branch or a new branch.
354
+ * Use this type when you need to handle branches from either source.
355
+ */
356
+ export type Branch = NewBranch | LegacyBranch;
357
+ export declare const checkIsNewBranch: (branch: Branch) => branch is NewBranch;
328
358
  export type CpuKind = "performance" | "standard" | "shared";
329
359
  export type MachineAutoStop = "stop" | "off" | "suspend";
330
360
  export interface ProjectRolePermissions {
@@ -445,7 +475,27 @@ export interface Project {
445
475
  isFromUserTemplate?: boolean;
446
476
  templateId?: string | null;
447
477
  localPath?: string | null;
478
+ /** The state of the project. Use `isProjectDeleted()` helper for backwards-compatible checks. */
479
+ state?: EntityState;
480
+ deletedAt?: string;
481
+ deletedBy?: string;
448
482
  }
483
+ /**
484
+ * Get the state of a branch, checking `state` first and falling back to `deleted` for backwards compatibility.
485
+ */
486
+ export declare const getBranchState: (branch: Branch) => EntityState;
487
+ /**
488
+ * Get the state of a project, checking `state` first and falling back to `deleted` for backwards compatibility.
489
+ */
490
+ export declare const getProjectState: (project: Project) => EntityState;
491
+ /**
492
+ * Check if a branch is deleted, supporting both `state` and legacy `deleted` fields.
493
+ */
494
+ export declare const isBranchDeleted: (branch: Branch) => boolean;
495
+ /**
496
+ * Check if a project is deleted, supporting both `state` and legacy `deleted` fields.
497
+ */
498
+ export declare const isProjectDeleted: (project: Project) => boolean;
449
499
  export interface ProjectWithBranches extends Project {
450
500
  branches: Record<string, Branch>;
451
501
  }
package/src/projects.js CHANGED
@@ -10,3 +10,33 @@ export const EXAMPLE_REPOS = [
10
10
  export const STARTER_REPO = "BuilderIO/fusion-starter";
11
11
  export const EXAMPLE_OR_STARTER_REPOS = [...EXAMPLE_REPOS, STARTER_REPO];
12
12
  export const EXAMPLE_OR_STARTER_REPOS_URLS = EXAMPLE_OR_STARTER_REPOS.map((repo) => `https://github.com/${repo}`);
13
+ export const checkIsNewBranch = (branch) => {
14
+ return "projectId" in branch;
15
+ };
16
+ /**
17
+ * Get the state of a branch, checking `state` first and falling back to `deleted` for backwards compatibility.
18
+ */
19
+ export const getBranchState = (branch) => {
20
+ if (branch.state)
21
+ return branch.state;
22
+ return branch.deleted ? "deleted" : "active";
23
+ };
24
+ /**
25
+ * Get the state of a project, checking `state` first and falling back to `deleted` for backwards compatibility.
26
+ */
27
+ export const getProjectState = (project) => {
28
+ var _a;
29
+ return (_a = project.state) !== null && _a !== void 0 ? _a : "active";
30
+ };
31
+ /**
32
+ * Check if a branch is deleted, supporting both `state` and legacy `deleted` fields.
33
+ */
34
+ export const isBranchDeleted = (branch) => {
35
+ return getBranchState(branch) === "deleted";
36
+ };
37
+ /**
38
+ * Check if a project is deleted, supporting both `state` and legacy `deleted` fields.
39
+ */
40
+ export const isProjectDeleted = (project) => {
41
+ return getProjectState(project) === "deleted";
42
+ };