@pgpmjs/slice 0.2.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/types.d.ts ADDED
@@ -0,0 +1,204 @@
1
+ import { Change, Tag, ExtendedPlanFile } from '@pgpmjs/ast/files/types';
2
+ /**
3
+ * Configuration for slicing a plan into multiple packages
4
+ */
5
+ export interface SliceConfig {
6
+ /** Source plan file path */
7
+ sourcePlan: string;
8
+ /** Output directory for packages */
9
+ outputDir: string;
10
+ /** Grouping strategy */
11
+ strategy: GroupingStrategy;
12
+ /** Package for changes that don't match any group */
13
+ defaultPackage?: string;
14
+ /** Whether to use tags for cross-package deps */
15
+ useTagsForCrossPackageDeps?: boolean;
16
+ /**
17
+ * How cross-package dependencies are recorded in sliced plans:
18
+ * - 'change' (default): per-change refs (`{package}:{change}`)
19
+ * - 'tag': per-change tag refs (`{package}:@tag`) when available
20
+ * (equivalent to `useTagsForCrossPackageDeps: true`)
21
+ * - 'control-only': drop per-change cross-package refs from plan lines
22
+ * entirely; the dependency is carried only by the control file's
23
+ * `requires` (extension install ordering deploys the whole dependency
24
+ * package first, which subsumes any per-change ordering constraint)
25
+ */
26
+ crossPackageDepMode?: CrossPackageDepMode;
27
+ /** Minimum changes per package (merge smaller groups) */
28
+ minChangesPerPackage?: number;
29
+ /** Author for generated plan files */
30
+ author?: string;
31
+ /**
32
+ * Opt-in dependency-closure expansion for pattern slices marked
33
+ * `closure: true`. Requires access to the module's deploy scripts to parse
34
+ * SQL and discover references that are not declared in `requires` headers.
35
+ */
36
+ closure?: ClosureOptions;
37
+ }
38
+ /**
39
+ * Options for AST-based dependency-closure expansion
40
+ */
41
+ export interface ClosureOptions {
42
+ /**
43
+ * Module root directory containing `deploy/<change>.sql` scripts, used to
44
+ * parse each change's SQL and extract referenced objects.
45
+ */
46
+ moduleDir: string;
47
+ }
48
+ /**
49
+ * How cross-package dependencies are represented in sliced plan files
50
+ */
51
+ export type CrossPackageDepMode = 'change' | 'tag' | 'control-only';
52
+ /**
53
+ * Grouping strategy for slicing
54
+ */
55
+ export type GroupingStrategy = FolderStrategy | PatternStrategy | ExplicitStrategy;
56
+ export interface FolderStrategy {
57
+ type: 'folder';
58
+ /** Depth in path to extract package name (default: 1) */
59
+ depth?: number;
60
+ /** Prefix to strip from paths (default: 'schemas') */
61
+ prefixToStrip?: string;
62
+ }
63
+ /**
64
+ * Pattern-based strategy using glob patterns to match changes to packages.
65
+ * Each slice defines a package name and an array of glob patterns.
66
+ * Changes matching any pattern in a slice are assigned to that package.
67
+ */
68
+ export interface PatternStrategy {
69
+ type: 'pattern';
70
+ /** Array of slice definitions with package names and patterns */
71
+ slices: PatternSlice[];
72
+ }
73
+ /**
74
+ * A single slice definition for pattern-based grouping
75
+ */
76
+ export interface PatternSlice {
77
+ /** Name of the output package */
78
+ packageName: string;
79
+ /** Glob patterns to match change paths (e.g., "schemas/auth/**") */
80
+ patterns: string[];
81
+ /**
82
+ * When true (and `SliceConfig.closure` is set), the package is expanded to
83
+ * cover the transitive dependency closure of the changes its patterns
84
+ * matched: declared plan `requires` plus AST-discovered references
85
+ * (function calls including PL/pgSQL bodies, table/view references, types,
86
+ * FK targets), intersected with plan-known changes. Auto-included changes
87
+ * are reported in `SliceResult.closureReport`.
88
+ */
89
+ closure?: boolean;
90
+ }
91
+ export interface ExplicitStrategy {
92
+ type: 'explicit';
93
+ /** Mapping of change name to package name */
94
+ mapping: Record<string, string>;
95
+ }
96
+ /**
97
+ * Dependency graph representation
98
+ */
99
+ export interface DependencyGraph {
100
+ /** Map of change name to Change object */
101
+ nodes: Map<string, Change>;
102
+ /** Map of change name to its dependencies */
103
+ edges: Map<string, Set<string>>;
104
+ /** Map of change name to changes that depend on it */
105
+ reverseEdges: Map<string, Set<string>>;
106
+ /** Map of change name to its tags */
107
+ tags: Map<string, Tag[]>;
108
+ /** Original plan metadata */
109
+ plan: ExtendedPlanFile;
110
+ }
111
+ /**
112
+ * Result of slicing operation
113
+ */
114
+ export interface SliceResult {
115
+ /** Generated packages */
116
+ packages: PackageOutput[];
117
+ /** Workspace manifest */
118
+ workspace: WorkspaceManifest;
119
+ /** Warnings/issues encountered */
120
+ warnings: SliceWarning[];
121
+ /** Statistics */
122
+ stats: SliceStats;
123
+ /** Report of dependency-closure expansion (when configured). */
124
+ closureReport?: ClosureReport;
125
+ }
126
+ /**
127
+ * A change automatically pulled into a package by closure expansion
128
+ */
129
+ export interface ClosureAutoInclude {
130
+ /** The auto-included change */
131
+ change: string;
132
+ /** Package it was pulled into */
133
+ package: string;
134
+ /** The change whose dependency pulled it in */
135
+ requiredBy: string;
136
+ /** Edge type: declared plan `requires` or AST-discovered reference */
137
+ reason: 'requires' | 'ast';
138
+ /** For AST edges: the referenced object that links the two changes */
139
+ ref?: string;
140
+ }
141
+ /**
142
+ * Report of dependency-closure expansion
143
+ */
144
+ export interface ClosureReport {
145
+ /** Changes pulled into packages beyond their pattern matches, and why */
146
+ autoIncluded: ClosureAutoInclude[];
147
+ /** Changes whose PL/pgSQL bodies execute dynamic SQL (edges incomplete) */
148
+ dynamicSqlChanges: string[];
149
+ /** Schema-qualified references no change in the plan produces */
150
+ unresolvedReferences: {
151
+ change: string;
152
+ ref: string;
153
+ }[];
154
+ }
155
+ /**
156
+ * Output for a single package
157
+ */
158
+ export interface PackageOutput {
159
+ /** Package name */
160
+ name: string;
161
+ /** Plan file content */
162
+ planContent: string;
163
+ /** Control file content */
164
+ controlContent: string;
165
+ /** Changes in this package */
166
+ changes: Change[];
167
+ /** Dependencies on other packages */
168
+ packageDependencies: string[];
169
+ }
170
+ /**
171
+ * Workspace manifest describing package relationships
172
+ */
173
+ export interface WorkspaceManifest {
174
+ /** List of package names */
175
+ packages: string[];
176
+ /** Order in which packages should be deployed */
177
+ deployOrder: string[];
178
+ /** Map of package name to its package dependencies */
179
+ dependencies: Record<string, string[]>;
180
+ }
181
+ /**
182
+ * Warning generated during slicing
183
+ */
184
+ export interface SliceWarning {
185
+ type: 'heavy_cross_deps' | 'cycle_detected' | 'orphan_change' | 'merge_required';
186
+ message: string;
187
+ affectedChanges?: string[];
188
+ suggestedAction?: string;
189
+ }
190
+ /**
191
+ * Statistics about the slicing operation
192
+ */
193
+ export interface SliceStats {
194
+ /** Total number of changes processed */
195
+ totalChanges: number;
196
+ /** Number of packages created */
197
+ packagesCreated: number;
198
+ /** Number of internal dependency edges */
199
+ internalEdges: number;
200
+ /** Number of cross-package dependency edges */
201
+ crossPackageEdges: number;
202
+ /** Ratio of cross-package to total edges */
203
+ crossPackageRatio: number;
204
+ }
package/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });