@ontrails/trails 1.0.0-beta.13 → 1.0.0-beta.15

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.
Files changed (165) hide show
  1. package/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +29 -0
  3. package/__tests__/examples.test.ts +39 -0
  4. package/dist/src/app.d.ts.map +1 -1
  5. package/dist/src/app.js +12 -1
  6. package/dist/src/app.js.map +1 -1
  7. package/dist/src/cli.js +4 -3
  8. package/dist/src/cli.js.map +1 -1
  9. package/dist/src/trails/add-surface.d.ts +3 -3
  10. package/dist/src/trails/add-surface.d.ts.map +1 -1
  11. package/dist/src/trails/add-surface.js +46 -24
  12. package/dist/src/trails/add-surface.js.map +1 -1
  13. package/dist/src/trails/add-trail.d.ts +3 -1
  14. package/dist/src/trails/add-trail.d.ts.map +1 -1
  15. package/dist/src/trails/add-trail.js +49 -22
  16. package/dist/src/trails/add-trail.js.map +1 -1
  17. package/dist/src/trails/add-trailhead.d.ts +13 -0
  18. package/dist/src/trails/add-trailhead.d.ts.map +1 -0
  19. package/dist/src/trails/add-trailhead.js +88 -0
  20. package/dist/src/trails/add-trailhead.js.map +1 -0
  21. package/dist/src/trails/add-verify.d.ts +1 -1
  22. package/dist/src/trails/add-verify.d.ts.map +1 -1
  23. package/dist/src/trails/add-verify.js +17 -16
  24. package/dist/src/trails/add-verify.js.map +1 -1
  25. package/dist/src/trails/create-scaffold.d.ts +1 -1
  26. package/dist/src/trails/create-scaffold.d.ts.map +1 -1
  27. package/dist/src/trails/create-scaffold.js +34 -27
  28. package/dist/src/trails/create-scaffold.js.map +1 -1
  29. package/dist/src/trails/create.d.ts +9 -13
  30. package/dist/src/trails/create.d.ts.map +1 -1
  31. package/dist/src/trails/create.js +40 -35
  32. package/dist/src/trails/create.js.map +1 -1
  33. package/dist/src/trails/dev-clean.d.ts +9 -0
  34. package/dist/src/trails/dev-clean.d.ts.map +1 -0
  35. package/dist/src/trails/dev-clean.js +66 -0
  36. package/dist/src/trails/dev-clean.js.map +1 -0
  37. package/dist/src/trails/dev-reset.d.ts +6 -0
  38. package/dist/src/trails/dev-reset.d.ts.map +1 -0
  39. package/dist/src/trails/dev-reset.js +39 -0
  40. package/dist/src/trails/dev-reset.js.map +1 -0
  41. package/dist/src/trails/dev-stats.d.ts +7 -0
  42. package/dist/src/trails/dev-stats.d.ts.map +1 -0
  43. package/dist/src/trails/dev-stats.js +61 -0
  44. package/dist/src/trails/dev-stats.js.map +1 -0
  45. package/dist/src/trails/dev-support.d.ts +64 -0
  46. package/dist/src/trails/dev-support.d.ts.map +1 -0
  47. package/dist/src/trails/dev-support.js +181 -0
  48. package/dist/src/trails/dev-support.js.map +1 -0
  49. package/dist/src/trails/draft-promote.d.ts +18 -0
  50. package/dist/src/trails/draft-promote.d.ts.map +1 -0
  51. package/dist/src/trails/draft-promote.js +400 -0
  52. package/dist/src/trails/draft-promote.js.map +1 -0
  53. package/dist/src/trails/guide.d.ts +14 -4
  54. package/dist/src/trails/guide.d.ts.map +1 -1
  55. package/dist/src/trails/guide.js +22 -41
  56. package/dist/src/trails/guide.js.map +1 -1
  57. package/dist/src/trails/load-app.d.ts +9 -1
  58. package/dist/src/trails/load-app.d.ts.map +1 -1
  59. package/dist/src/trails/load-app.js +404 -13
  60. package/dist/src/trails/load-app.js.map +1 -1
  61. package/dist/src/trails/project.d.ts.map +1 -1
  62. package/dist/src/trails/project.js +14 -3
  63. package/dist/src/trails/project.js.map +1 -1
  64. package/dist/src/trails/survey.d.ts +6 -60
  65. package/dist/src/trails/survey.d.ts.map +1 -1
  66. package/dist/src/trails/survey.js +83 -182
  67. package/dist/src/trails/survey.js.map +1 -1
  68. package/dist/src/trails/topo-constants.d.ts +3 -0
  69. package/dist/src/trails/topo-constants.d.ts.map +1 -0
  70. package/dist/src/trails/topo-constants.js +3 -0
  71. package/dist/src/trails/topo-constants.js.map +1 -0
  72. package/dist/src/trails/topo-export.d.ts +19 -0
  73. package/dist/src/trails/topo-export.d.ts.map +1 -0
  74. package/dist/src/trails/topo-export.js +31 -0
  75. package/dist/src/trails/topo-export.js.map +1 -0
  76. package/dist/src/trails/topo-history.d.ts +20 -0
  77. package/dist/src/trails/topo-history.d.ts.map +1 -0
  78. package/dist/src/trails/topo-history.js +32 -0
  79. package/dist/src/trails/topo-history.js.map +1 -0
  80. package/dist/src/trails/topo-pin.d.ts +17 -0
  81. package/dist/src/trails/topo-pin.d.ts.map +1 -0
  82. package/dist/src/trails/topo-pin.js +31 -0
  83. package/dist/src/trails/topo-pin.js.map +1 -0
  84. package/dist/src/trails/topo-read-support.d.ts +58 -0
  85. package/dist/src/trails/topo-read-support.d.ts.map +1 -0
  86. package/dist/src/trails/topo-read-support.js +167 -0
  87. package/dist/src/trails/topo-read-support.js.map +1 -0
  88. package/dist/src/trails/topo-reports.d.ts +54 -0
  89. package/dist/src/trails/topo-reports.d.ts.map +1 -0
  90. package/dist/src/trails/topo-reports.js +128 -0
  91. package/dist/src/trails/topo-reports.js.map +1 -0
  92. package/dist/src/trails/topo-show.d.ts +23 -0
  93. package/dist/src/trails/topo-show.d.ts.map +1 -0
  94. package/dist/src/trails/topo-show.js +49 -0
  95. package/dist/src/trails/topo-show.js.map +1 -0
  96. package/dist/src/trails/topo-store-support.d.ts +13 -0
  97. package/dist/src/trails/topo-store-support.d.ts.map +1 -0
  98. package/dist/src/trails/topo-store-support.js +55 -0
  99. package/dist/src/trails/topo-store-support.js.map +1 -0
  100. package/dist/src/trails/topo-support.d.ts +76 -0
  101. package/dist/src/trails/topo-support.d.ts.map +1 -0
  102. package/dist/src/trails/topo-support.js +132 -0
  103. package/dist/src/trails/topo-support.js.map +1 -0
  104. package/dist/src/trails/topo-unpin.d.ts +20 -0
  105. package/dist/src/trails/topo-unpin.d.ts.map +1 -0
  106. package/dist/src/trails/topo-unpin.js +44 -0
  107. package/dist/src/trails/topo-unpin.js.map +1 -0
  108. package/dist/src/trails/topo-verify.d.ts +5 -0
  109. package/dist/src/trails/topo-verify.d.ts.map +1 -0
  110. package/dist/src/trails/topo-verify.js +24 -0
  111. package/dist/src/trails/topo-verify.js.map +1 -0
  112. package/dist/src/trails/topo.d.ts +5 -0
  113. package/dist/src/trails/topo.d.ts.map +1 -0
  114. package/dist/src/trails/topo.js +63 -0
  115. package/dist/src/trails/topo.js.map +1 -0
  116. package/dist/src/trails/warden.d.ts +3 -2
  117. package/dist/src/trails/warden.d.ts.map +1 -1
  118. package/dist/src/trails/warden.js +37 -27
  119. package/dist/src/trails/warden.js.map +1 -1
  120. package/dist/src/versions.d.ts +12 -0
  121. package/dist/src/versions.d.ts.map +1 -0
  122. package/dist/src/versions.js +23 -0
  123. package/dist/src/versions.js.map +1 -0
  124. package/dist/tsconfig.tsbuildinfo +1 -1
  125. package/package.json +8 -7
  126. package/src/__tests__/add-trail.test.ts +97 -0
  127. package/src/__tests__/create.test.ts +91 -27
  128. package/src/__tests__/draft-promote.test.ts +144 -0
  129. package/src/__tests__/guide.test.ts +10 -5
  130. package/src/__tests__/load-app.test.ts +406 -2
  131. package/src/__tests__/survey.test.ts +221 -60
  132. package/src/__tests__/topo-dev.test.ts +426 -0
  133. package/src/app.ts +24 -2
  134. package/src/clack.ts +1 -1
  135. package/src/cli.ts +4 -3
  136. package/src/trails/add-surface.ts +150 -0
  137. package/src/trails/add-trail.ts +46 -10
  138. package/src/trails/add-verify.ts +11 -6
  139. package/src/trails/create-scaffold.ts +16 -3
  140. package/src/trails/create.ts +76 -71
  141. package/src/trails/dev-clean.ts +77 -0
  142. package/src/trails/dev-reset.ts +45 -0
  143. package/src/trails/dev-stats.ts +67 -0
  144. package/src/trails/dev-support.ts +328 -0
  145. package/src/trails/draft-promote.ts +739 -0
  146. package/src/trails/guide.ts +23 -41
  147. package/src/trails/load-app.ts +556 -14
  148. package/src/trails/project.ts +17 -3
  149. package/src/trails/survey.ts +110 -285
  150. package/src/trails/topo-constants.ts +2 -0
  151. package/src/trails/topo-export.ts +35 -0
  152. package/src/trails/topo-history.ts +38 -0
  153. package/src/trails/topo-pin.ts +38 -0
  154. package/src/trails/topo-read-support.ts +329 -0
  155. package/src/trails/topo-reports.ts +228 -0
  156. package/src/trails/topo-show.ts +54 -0
  157. package/src/trails/topo-store-support.ts +104 -0
  158. package/src/trails/topo-support.ts +230 -0
  159. package/src/trails/topo-unpin.ts +56 -0
  160. package/src/trails/topo-verify.ts +25 -0
  161. package/src/trails/topo.ts +69 -0
  162. package/src/trails/warden.ts +13 -3
  163. package/src/versions.ts +43 -0
  164. package/tsconfig.tests.json +10 -0
  165. package/src/trails/add-trailhead.ts +0 -121
@@ -0,0 +1,61 @@
1
+ import { Result, trail } from '@ontrails/core';
2
+ import { z } from 'zod';
3
+ import { buildDevStats, DEFAULT_TOPO_SNAPSHOT_RETENTION, } from './dev-support.js';
4
+ import { createIsolatedExampleInput } from './topo-support.js';
5
+ export const devStatsTrail = trail('dev.stats', {
6
+ blaze: (input, ctx) => {
7
+ const rootDir = input.rootDir ?? ctx.cwd ?? process.cwd();
8
+ return Result.ok(buildDevStats({
9
+ maxAge: input.traceAgeMs,
10
+ maxRecords: input.traces,
11
+ rootDir,
12
+ snapshotRetention: input.snapshots,
13
+ }));
14
+ },
15
+ description: 'Show local Trails workspace state and retention',
16
+ examples: [
17
+ {
18
+ input: { rootDir: createIsolatedExampleInput('dev-stats').rootDir },
19
+ name: 'Show local dev state',
20
+ },
21
+ ],
22
+ input: z.object({
23
+ rootDir: z.string().optional().describe('Workspace root directory'),
24
+ snapshots: z
25
+ .number()
26
+ .default(DEFAULT_TOPO_SNAPSHOT_RETENTION)
27
+ .describe('Unpinned topo snapshots to retain'),
28
+ traceAgeMs: z
29
+ .number()
30
+ .default(7 * 24 * 60 * 60 * 1000)
31
+ .describe('Maximum retained trace age in milliseconds'),
32
+ traces: z.number().default(10_000).describe('Maximum retained trace count'),
33
+ }),
34
+ intent: 'read',
35
+ output: z.object({
36
+ db: z.object({
37
+ exists: z.boolean(),
38
+ fileSizeBytes: z.number(),
39
+ path: z.string(),
40
+ }),
41
+ lock: z.object({
42
+ exists: z.boolean(),
43
+ fileSizeBytes: z.number(),
44
+ path: z.string(),
45
+ }),
46
+ retention: z.object({
47
+ snapshots: z.number(),
48
+ traceAgeMs: z.number(),
49
+ traces: z.number(),
50
+ }),
51
+ topo: z.object({
52
+ pinnedCount: z.number(),
53
+ prunableSnapshotCount: z.number(),
54
+ snapshotCount: z.number(),
55
+ }),
56
+ tracing: z.object({
57
+ recordCount: z.number(),
58
+ }),
59
+ }),
60
+ });
61
+ //# sourceMappingURL=dev-stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-stats.js","sourceRoot":"","sources":["../../../src/trails/dev-stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,aAAa,EACb,+BAA+B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/D,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,EAAE;IAC9C,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACpB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAC1D,OAAO,MAAM,CAAC,EAAE,CACd,aAAa,CAAC;YACZ,MAAM,EAAE,KAAK,CAAC,UAAU;YACxB,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,OAAO;YACP,iBAAiB,EAAE,KAAK,CAAC,SAAS;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IACD,WAAW,EAAE,iDAAiD;IAC9D,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,EAAE,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE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YACvB,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE;YACjC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;SAC1B,CAAC;QACF,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;YAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;SACxB,CAAC;KACH,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ export declare const DEFAULT_TOPO_SNAPSHOT_RETENTION = 50;
2
+ export interface DevStatsReport {
3
+ readonly db: {
4
+ readonly exists: boolean;
5
+ readonly fileSizeBytes: number;
6
+ readonly path: string;
7
+ };
8
+ readonly lock: {
9
+ readonly exists: boolean;
10
+ readonly fileSizeBytes: number;
11
+ readonly path: string;
12
+ };
13
+ readonly retention: {
14
+ readonly snapshots: number;
15
+ readonly traceAgeMs: number;
16
+ readonly traces: number;
17
+ };
18
+ readonly topo: {
19
+ readonly pinnedCount: number;
20
+ readonly prunableSnapshotCount: number;
21
+ readonly snapshotCount: number;
22
+ };
23
+ readonly tracing: {
24
+ readonly recordCount: number;
25
+ };
26
+ }
27
+ export interface DevCleanReport {
28
+ readonly dryRun: boolean;
29
+ readonly remaining: {
30
+ readonly pinnedCount: number;
31
+ readonly snapshotCount: number;
32
+ readonly traceCount: number;
33
+ };
34
+ readonly removed: {
35
+ readonly topoSnapshots: number;
36
+ readonly traceRecords: number;
37
+ };
38
+ readonly retention: {
39
+ readonly snapshots: number;
40
+ readonly traceAgeMs: number;
41
+ readonly traces: number;
42
+ };
43
+ }
44
+ export interface DevResetReport {
45
+ readonly dryRun: boolean;
46
+ readonly removedCount: number;
47
+ readonly removedFiles: readonly string[];
48
+ }
49
+ interface DevRetentionOptions {
50
+ readonly maxAge?: number;
51
+ readonly maxRecords?: number;
52
+ readonly rootDir?: string;
53
+ readonly snapshotRetention?: number;
54
+ }
55
+ export declare const buildDevStats: (options?: DevRetentionOptions) => DevStatsReport;
56
+ export declare const cleanDevState: (options?: DevRetentionOptions & {
57
+ readonly dryRun?: boolean;
58
+ }) => DevCleanReport;
59
+ export declare const resetDevState: (options?: {
60
+ readonly dryRun?: boolean;
61
+ readonly rootDir?: string;
62
+ }) => DevResetReport;
63
+ export {};
64
+ //# sourceMappingURL=dev-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-support.d.ts","sourceRoot":"","sources":["../../../src/trails/dev-support.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAYlD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE;QACX,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;QACvC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,WAAW,E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 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { countPinnedSnapshots, countPrunableSnapshots, countTopoSnapshots, pruneUnpinnedSnapshots, } from '@ontrails/core/internal/topo-snapshots';
4
+ import { openReadTrailsDb, openWriteTrailsDb, deriveTrailsDbPath, deriveTrailsDir, } from '@ontrails/core/internal/trails-db';
5
+ import { DEFAULT_MAX_AGE, DEFAULT_MAX_RECORDS, applyTraceCleanup, countTraceRecords, previewTraceCleanup, } from '@ontrails/tracing/internal/dev-state';
6
+ export const DEFAULT_TOPO_SNAPSHOT_RETENTION = 50;
7
+ const deriveRootDir = (cwd) => cwd ?? process.cwd();
8
+ const removeIfPresent = (filePath) => {
9
+ if (!existsSync(filePath)) {
10
+ return false;
11
+ }
12
+ rmSync(filePath, { force: true });
13
+ return true;
14
+ };
15
+ const buildRetention = (options) => ({
16
+ snapshots: options?.snapshotRetention ?? DEFAULT_TOPO_SNAPSHOT_RETENTION,
17
+ traceAgeMs: options?.maxAge ?? DEFAULT_MAX_AGE,
18
+ traces: options?.maxRecords ?? DEFAULT_MAX_RECORDS,
19
+ });
20
+ const emptyDevClean = (retention, dryRun) => ({
21
+ dryRun,
22
+ remaining: {
23
+ pinnedCount: 0,
24
+ snapshotCount: 0,
25
+ traceCount: 0,
26
+ },
27
+ removed: {
28
+ topoSnapshots: 0,
29
+ traceRecords: 0,
30
+ },
31
+ retention,
32
+ });
33
+ const buildLockStats = (lockPath) => ({
34
+ exists: existsSync(lockPath),
35
+ fileSizeBytes: existsSync(lockPath) ? statSync(lockPath).size : 0,
36
+ path: lockPath,
37
+ });
38
+ const buildDbStats = (dbPath, exists) => ({
39
+ exists,
40
+ fileSizeBytes: exists ? statSync(dbPath).size : 0,
41
+ path: '.trails/trails.db',
42
+ });
43
+ const emptyDevStats = (dbPath, lockPath, retention) => ({
44
+ db: buildDbStats(dbPath, false),
45
+ lock: buildLockStats(lockPath),
46
+ retention,
47
+ topo: {
48
+ pinnedCount: 0,
49
+ prunableSnapshotCount: 0,
50
+ snapshotCount: 0,
51
+ },
52
+ tracing: {
53
+ recordCount: 0,
54
+ },
55
+ });
56
+ const liveDevStats = (db, dbPath, lockPath, retention) => ({
57
+ db: buildDbStats(dbPath, true),
58
+ lock: buildLockStats(lockPath),
59
+ retention,
60
+ topo: {
61
+ pinnedCount: countPinnedSnapshots(db),
62
+ prunableSnapshotCount: countPrunableSnapshots(db, {
63
+ keep: retention.snapshots,
64
+ }),
65
+ snapshotCount: countTopoSnapshots(db),
66
+ },
67
+ tracing: {
68
+ recordCount: countTraceRecords(db),
69
+ },
70
+ });
71
+ const deriveDevStatsContext = (options) => {
72
+ const rootDir = deriveRootDir(options?.rootDir);
73
+ const dbPath = deriveTrailsDbPath({ rootDir });
74
+ const trailsDir = deriveTrailsDir({ rootDir });
75
+ const lockPath = join(trailsDir, 'trails.lock');
76
+ return {
77
+ dbExists: existsSync(dbPath),
78
+ dbPath,
79
+ lockPath,
80
+ retention: buildRetention(options),
81
+ rootDir,
82
+ };
83
+ };
84
+ const deriveDevCleanupContext = (options) => {
85
+ const rootDir = deriveRootDir(options?.rootDir);
86
+ return {
87
+ dbPath: deriveTrailsDbPath({ rootDir }),
88
+ dryRun: options?.dryRun ?? false,
89
+ retention: buildRetention(options),
90
+ rootDir,
91
+ };
92
+ };
93
+ const cleanupTraces = (db, context) => context.dryRun
94
+ ? previewTraceCleanup(db, {
95
+ maxAge: context.retention.traceAgeMs,
96
+ maxRecords: context.retention.traces,
97
+ })
98
+ : applyTraceCleanup(db, {
99
+ maxAge: context.retention.traceAgeMs,
100
+ maxRecords: context.retention.traces,
101
+ });
102
+ const cleanupTopoSnapshots = (db, context) => context.dryRun
103
+ ? countPrunableSnapshots(db, { keep: context.retention.snapshots })
104
+ : pruneUnpinnedSnapshots(db, { keep: context.retention.snapshots });
105
+ const buildCleanReport = (db, context) => {
106
+ const traceReport = cleanupTraces(db, context);
107
+ const topoRemoved = cleanupTopoSnapshots(db, context);
108
+ const snapshotCount = countTopoSnapshots(db);
109
+ return {
110
+ dryRun: context.dryRun,
111
+ remaining: {
112
+ pinnedCount: countPinnedSnapshots(db),
113
+ snapshotCount: context.dryRun
114
+ ? snapshotCount - topoRemoved
115
+ : snapshotCount,
116
+ traceCount: context.dryRun
117
+ ? traceReport.remaining - traceReport.removedTotal
118
+ : traceReport.remaining,
119
+ },
120
+ removed: {
121
+ topoSnapshots: topoRemoved,
122
+ traceRecords: traceReport.removedTotal,
123
+ },
124
+ retention: context.retention,
125
+ };
126
+ };
127
+ const RESET_FILES = [
128
+ '.trails/trails.db',
129
+ '.trails/trails.db-shm',
130
+ '.trails/trails.db-wal',
131
+ '.trails/dev/tracing.db',
132
+ '.trails/dev/tracing.db-shm',
133
+ '.trails/dev/tracing.db-wal',
134
+ ];
135
+ const presentResetFiles = (rootDir) => RESET_FILES.filter((relativePath) => existsSync(join(rootDir, relativePath)));
136
+ export const buildDevStats = (options) => {
137
+ const { dbExists, dbPath, lockPath, retention, rootDir } = deriveDevStatsContext(options);
138
+ if (!dbExists) {
139
+ return emptyDevStats(dbPath, lockPath, retention);
140
+ }
141
+ const db = openReadTrailsDb({ rootDir });
142
+ try {
143
+ return liveDevStats(db, dbPath, lockPath, retention);
144
+ }
145
+ finally {
146
+ db.close();
147
+ }
148
+ };
149
+ export const cleanDevState = (options) => {
150
+ const context = deriveDevCleanupContext(options);
151
+ if (!existsSync(context.dbPath)) {
152
+ return emptyDevClean(context.retention, context.dryRun);
153
+ }
154
+ const db = context.dryRun
155
+ ? openReadTrailsDb({ rootDir: context.rootDir })
156
+ : openWriteTrailsDb({ rootDir: context.rootDir });
157
+ try {
158
+ return buildCleanReport(db, context);
159
+ }
160
+ finally {
161
+ db.close();
162
+ }
163
+ };
164
+ export const resetDevState = (options) => {
165
+ const rootDir = deriveRootDir(options?.rootDir);
166
+ const files = presentResetFiles(rootDir);
167
+ if (options?.dryRun === true) {
168
+ return {
169
+ dryRun: true,
170
+ removedCount: files.length,
171
+ removedFiles: files,
172
+ };
173
+ }
174
+ const removedFiles = files.filter((relativePath) => removeIfPresent(join(rootDir, relativePath)));
175
+ return {
176
+ dryRun: false,
177
+ removedCount: removedFiles.length,
178
+ removedFiles,
179
+ };
180
+ };
181
+ //# sourceMappingURL=dev-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-support.js","sourceRoot":"","sources":["../../../src/trails/dev-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,sCAAsC,CAAC;AAE9C,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAElD,MAAM,aAAa,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAErE,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAW,EAAE;IACpD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAkEF,MAAM,cAAc,GAAG,CAAC,OAA6B,EAAE,EAAE,CAAC,CAAC;IACzD,SAAS,EAAE,OAAO,EAAE,iBAAiB,IAAI,+BAA+B;IACxE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,eAAe;IAC9C,M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renameFiles: boolean;
4
+ toId: string;
5
+ appModule?: string | undefined;
6
+ rootDir?: string | undefined;
7
+ }, {
8
+ appModule: string | null;
9
+ message: string;
10
+ promotedEstablished: boolean;
11
+ remainingDraftIds: string[];
12
+ renamedFiles: {
13
+ from: string;
14
+ to: string;
15
+ }[];
16
+ updatedFiles: string[];
17
+ }, never>;
18
+ //# sourceMappingURL=draft-promote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-promote.d.ts","sourceRoot":"","sources":["../../../src/trails/draft-promote.ts"],"names":[],"mappings":"AAorBA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;SA8C5B,CAAC"}