@contractspec/lib.contracts 1.45.2 → 1.45.3
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/app-config/contracts.d.ts +50 -50
- package/dist/app-config/events.d.ts +27 -27
- package/dist/app-config/lifecycle-contracts.d.ts +54 -54
- package/dist/client/react/form-render.js +2 -0
- package/dist/contract-registry/schemas.d.ts +6 -6
- package/dist/docs/presentations.js +1 -6
- package/dist/docs/types.d.ts +1 -1
- package/dist/examples/schema.d.ts +17 -17
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/knowledge/operations.d.ts +66 -66
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/versioning/index.d.ts +3 -0
- package/dist/versioning/index.js +4 -0
- package/dist/versioning/types.d.ts +127 -0
- package/dist/versioning/types.js +24 -0
- package/dist/versioning/utils.d.ts +95 -0
- package/dist/versioning/utils.js +180 -0
- package/dist/workspace-config/contractsrc-schema.d.ts +160 -84
- package/dist/workspace-config/contractsrc-schema.js +42 -2
- package/dist/workspace-config/index.d.ts +2 -2
- package/dist/workspace-config/index.js +2 -2
- package/package.json +8 -5
|
@@ -1,136 +1,136 @@
|
|
|
1
1
|
import { OperationSpec } from "./operations/operation.js";
|
|
2
2
|
import "./index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _contractspec_lib_schema118 from "@contractspec/lib.schema";
|
|
4
4
|
import { SchemaModel } from "@contractspec/lib.schema";
|
|
5
5
|
|
|
6
6
|
//#region src/onboarding-base.d.ts
|
|
7
7
|
/** Save/update onboarding draft (auto-save during flow) */
|
|
8
8
|
declare const SaveOnboardingDraftInput: SchemaModel<{
|
|
9
9
|
data: {
|
|
10
|
-
type:
|
|
10
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
11
11
|
isOptional: false;
|
|
12
12
|
};
|
|
13
13
|
}>;
|
|
14
14
|
declare const SaveOnboardingDraftOutput: SchemaModel<{
|
|
15
15
|
id: {
|
|
16
|
-
type:
|
|
16
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
17
17
|
isOptional: false;
|
|
18
18
|
};
|
|
19
19
|
organizationId: {
|
|
20
|
-
type:
|
|
20
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
21
21
|
isOptional: false;
|
|
22
22
|
};
|
|
23
23
|
}>;
|
|
24
24
|
declare const SaveOnboardingDraftBaseSpec: OperationSpec<SchemaModel<{
|
|
25
25
|
data: {
|
|
26
|
-
type:
|
|
26
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
27
27
|
isOptional: false;
|
|
28
28
|
};
|
|
29
29
|
}>, SchemaModel<{
|
|
30
30
|
id: {
|
|
31
|
-
type:
|
|
31
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
32
32
|
isOptional: false;
|
|
33
33
|
};
|
|
34
34
|
organizationId: {
|
|
35
|
-
type:
|
|
35
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
36
36
|
isOptional: false;
|
|
37
37
|
};
|
|
38
38
|
}>, undefined>;
|
|
39
39
|
/** Get current onboarding draft (on mount/restore) */
|
|
40
40
|
declare const GetOnboardingDraftOutput: SchemaModel<{
|
|
41
41
|
id: {
|
|
42
|
-
type:
|
|
42
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
43
43
|
isOptional: true;
|
|
44
44
|
};
|
|
45
45
|
organizationId: {
|
|
46
|
-
type:
|
|
46
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
47
47
|
isOptional: true;
|
|
48
48
|
};
|
|
49
49
|
data: {
|
|
50
|
-
type:
|
|
50
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
51
51
|
isOptional: true;
|
|
52
52
|
};
|
|
53
53
|
createdAt: {
|
|
54
|
-
type:
|
|
54
|
+
type: _contractspec_lib_schema118.FieldType<Date, string>;
|
|
55
55
|
isOptional: true;
|
|
56
56
|
};
|
|
57
57
|
updatedAt: {
|
|
58
|
-
type:
|
|
58
|
+
type: _contractspec_lib_schema118.FieldType<Date, string>;
|
|
59
59
|
isOptional: true;
|
|
60
60
|
};
|
|
61
61
|
}>;
|
|
62
|
-
declare const GetOnboardingDraftBaseSpec: OperationSpec<
|
|
62
|
+
declare const GetOnboardingDraftBaseSpec: OperationSpec<_contractspec_lib_schema118.AnySchemaModel, SchemaModel<{
|
|
63
63
|
id: {
|
|
64
|
-
type:
|
|
64
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
65
65
|
isOptional: true;
|
|
66
66
|
};
|
|
67
67
|
organizationId: {
|
|
68
|
-
type:
|
|
68
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
69
69
|
isOptional: true;
|
|
70
70
|
};
|
|
71
71
|
data: {
|
|
72
|
-
type:
|
|
72
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
73
73
|
isOptional: true;
|
|
74
74
|
};
|
|
75
75
|
createdAt: {
|
|
76
|
-
type:
|
|
76
|
+
type: _contractspec_lib_schema118.FieldType<Date, string>;
|
|
77
77
|
isOptional: true;
|
|
78
78
|
};
|
|
79
79
|
updatedAt: {
|
|
80
|
-
type:
|
|
80
|
+
type: _contractspec_lib_schema118.FieldType<Date, string>;
|
|
81
81
|
isOptional: true;
|
|
82
82
|
};
|
|
83
83
|
}>, undefined>;
|
|
84
84
|
/** Delete onboarding draft (cleanup after completion or cancel) */
|
|
85
85
|
declare const DeleteOnboardingDraftOutput: SchemaModel<{
|
|
86
86
|
ok: {
|
|
87
|
-
type:
|
|
87
|
+
type: _contractspec_lib_schema118.FieldType<boolean, boolean>;
|
|
88
88
|
isOptional: false;
|
|
89
89
|
};
|
|
90
90
|
}>;
|
|
91
|
-
declare const DeleteOnboardingDraftBaseSpec: OperationSpec<
|
|
91
|
+
declare const DeleteOnboardingDraftBaseSpec: OperationSpec<_contractspec_lib_schema118.AnySchemaModel, SchemaModel<{
|
|
92
92
|
ok: {
|
|
93
|
-
type:
|
|
93
|
+
type: _contractspec_lib_schema118.FieldType<boolean, boolean>;
|
|
94
94
|
isOptional: false;
|
|
95
95
|
};
|
|
96
96
|
}>, undefined>;
|
|
97
97
|
/** Complete onboarding (final submit, creates entities) */
|
|
98
98
|
declare const CompleteOnboardingBaseInput: SchemaModel<{
|
|
99
99
|
data: {
|
|
100
|
-
type:
|
|
100
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
101
101
|
isOptional: false;
|
|
102
102
|
};
|
|
103
103
|
}>;
|
|
104
104
|
declare const CompleteOnboardingBaseOutput: SchemaModel<{
|
|
105
105
|
success: {
|
|
106
|
-
type:
|
|
106
|
+
type: _contractspec_lib_schema118.FieldType<boolean, boolean>;
|
|
107
107
|
isOptional: false;
|
|
108
108
|
};
|
|
109
109
|
userId: {
|
|
110
|
-
type:
|
|
110
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
111
111
|
isOptional: true;
|
|
112
112
|
};
|
|
113
113
|
organizationId: {
|
|
114
|
-
type:
|
|
114
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
115
115
|
isOptional: true;
|
|
116
116
|
};
|
|
117
117
|
}>;
|
|
118
118
|
declare const CompleteOnboardingBaseSpec: OperationSpec<SchemaModel<{
|
|
119
119
|
data: {
|
|
120
|
-
type:
|
|
120
|
+
type: _contractspec_lib_schema118.FieldType<unknown, unknown>;
|
|
121
121
|
isOptional: false;
|
|
122
122
|
};
|
|
123
123
|
}>, SchemaModel<{
|
|
124
124
|
success: {
|
|
125
|
-
type:
|
|
125
|
+
type: _contractspec_lib_schema118.FieldType<boolean, boolean>;
|
|
126
126
|
isOptional: false;
|
|
127
127
|
};
|
|
128
128
|
userId: {
|
|
129
|
-
type:
|
|
129
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
130
130
|
isOptional: true;
|
|
131
131
|
};
|
|
132
132
|
organizationId: {
|
|
133
|
-
type:
|
|
133
|
+
type: _contractspec_lib_schema118.FieldType<string, string>;
|
|
134
134
|
isOptional: true;
|
|
135
135
|
};
|
|
136
136
|
}>, undefined>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ChangeEntry, ChangeType, ChangelogDocBlock, ChangelogEntry, ChangelogJsonExport, ChangelogResult, SemanticVersion, VersionAnalysis, VersionAnalysisResult, VersionBumpType, isChangeType, isChangelogDocBlock, isVersionBumpType } from "./types.js";
|
|
2
|
+
import { bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isValidVersion, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion } from "./utils.js";
|
|
3
|
+
export { ChangeEntry, ChangeType, ChangelogDocBlock, ChangelogEntry, ChangelogJsonExport, ChangelogResult, SemanticVersion, VersionAnalysis, VersionAnalysisResult, VersionBumpType, bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isChangeType, isChangelogDocBlock, isValidVersion, isVersionBumpType, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { isChangeType, isChangelogDocBlock, isVersionBumpType } from "./types.js";
|
|
2
|
+
import { bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isValidVersion, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion } from "./utils.js";
|
|
3
|
+
|
|
4
|
+
export { bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isChangeType, isChangelogDocBlock, isValidVersion, isVersionBumpType, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { DocBlock } from "../docs/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/versioning/types.d.ts
|
|
4
|
+
|
|
5
|
+
/** Version bump type based on semantic versioning */
|
|
6
|
+
type VersionBumpType = 'patch' | 'minor' | 'major';
|
|
7
|
+
/** Semantic version components */
|
|
8
|
+
interface SemanticVersion {
|
|
9
|
+
major: number;
|
|
10
|
+
minor: number;
|
|
11
|
+
patch: number;
|
|
12
|
+
prerelease?: string;
|
|
13
|
+
build?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Type of change for changelog entries */
|
|
16
|
+
type ChangeType = 'added' | 'changed' | 'fixed' | 'removed' | 'deprecated' | 'breaking' | 'security';
|
|
17
|
+
/** Individual change entry */
|
|
18
|
+
interface ChangeEntry {
|
|
19
|
+
/** Type of change */
|
|
20
|
+
type: ChangeType;
|
|
21
|
+
/** Human-readable description of the change */
|
|
22
|
+
description: string;
|
|
23
|
+
/** Schema/code path changed (e.g., "io.input.email", "meta.stability") */
|
|
24
|
+
path?: string;
|
|
25
|
+
/** Related issue/ticket reference (e.g., "GH-123", "JIRA-456") */
|
|
26
|
+
issueRef?: string;
|
|
27
|
+
/** Git commit SHA for traceability */
|
|
28
|
+
commitSha?: string;
|
|
29
|
+
/** Author of the change */
|
|
30
|
+
author?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Changelog entry for a specific version */
|
|
33
|
+
interface ChangelogEntry {
|
|
34
|
+
/** Version number (semver format) */
|
|
35
|
+
version: string;
|
|
36
|
+
/** Release date (ISO 8601 format) */
|
|
37
|
+
date: string;
|
|
38
|
+
/** Type of version bump that led to this version */
|
|
39
|
+
bumpType: VersionBumpType;
|
|
40
|
+
/** List of changes in this version */
|
|
41
|
+
changes: ChangeEntry[];
|
|
42
|
+
/** Breaking changes (subset for emphasis) */
|
|
43
|
+
breakingChanges?: ChangeEntry[];
|
|
44
|
+
/** Deprecation notices */
|
|
45
|
+
deprecations?: ChangeEntry[];
|
|
46
|
+
/** Contributors to this version */
|
|
47
|
+
contributors?: string[];
|
|
48
|
+
/** Release notes summary */
|
|
49
|
+
summary?: string;
|
|
50
|
+
}
|
|
51
|
+
/** DocBlock extension for per-spec changelogs */
|
|
52
|
+
interface ChangelogDocBlock extends DocBlock {
|
|
53
|
+
/** Changelog-specific kind */
|
|
54
|
+
kind: 'changelog';
|
|
55
|
+
/** Related spec key (e.g., "auth.beginSignup") */
|
|
56
|
+
specKey: string;
|
|
57
|
+
/** Current spec version */
|
|
58
|
+
specVersion: string;
|
|
59
|
+
/** Changelog entries for this spec */
|
|
60
|
+
entries: ChangelogEntry[];
|
|
61
|
+
}
|
|
62
|
+
/** Result of version analysis for a single spec */
|
|
63
|
+
interface VersionAnalysis {
|
|
64
|
+
/** Path to the spec file */
|
|
65
|
+
specPath: string;
|
|
66
|
+
/** Spec key (e.g., "auth.login") */
|
|
67
|
+
specKey: string;
|
|
68
|
+
/** Current version in the spec */
|
|
69
|
+
currentVersion: string;
|
|
70
|
+
/** Suggested new version based on changes */
|
|
71
|
+
suggestedVersion: string;
|
|
72
|
+
/** Suggested bump type */
|
|
73
|
+
bumpType: VersionBumpType;
|
|
74
|
+
/** Detected changes requiring version bump */
|
|
75
|
+
changes: ChangeEntry[];
|
|
76
|
+
/** Whether breaking changes were detected */
|
|
77
|
+
hasBreaking: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** Aggregated version analysis result */
|
|
80
|
+
interface VersionAnalysisResult {
|
|
81
|
+
/** Individual spec analyses */
|
|
82
|
+
analyses: VersionAnalysis[];
|
|
83
|
+
/** Total specs analyzed */
|
|
84
|
+
totalSpecs: number;
|
|
85
|
+
/** Specs needing version bump */
|
|
86
|
+
specsNeedingBump: number;
|
|
87
|
+
/** Total breaking changes across all specs */
|
|
88
|
+
totalBreaking: number;
|
|
89
|
+
/** Git baseline used for comparison */
|
|
90
|
+
baseline?: string;
|
|
91
|
+
}
|
|
92
|
+
/** Result of changelog generation */
|
|
93
|
+
interface ChangelogResult {
|
|
94
|
+
/** Per-spec DocBlock entries */
|
|
95
|
+
specChangelogs: ChangelogDocBlock[];
|
|
96
|
+
/** Library-level markdown by package path */
|
|
97
|
+
libraryMarkdown: Map<string, string>;
|
|
98
|
+
/** Monorepo-level markdown */
|
|
99
|
+
monorepoMarkdown: string;
|
|
100
|
+
/** JSON format for programmatic use */
|
|
101
|
+
json: ChangelogJsonExport;
|
|
102
|
+
}
|
|
103
|
+
/** JSON export format for changelogs */
|
|
104
|
+
interface ChangelogJsonExport {
|
|
105
|
+
generatedAt: string;
|
|
106
|
+
baseline?: string;
|
|
107
|
+
specs: {
|
|
108
|
+
key: string;
|
|
109
|
+
version: string;
|
|
110
|
+
path: string;
|
|
111
|
+
entries: ChangelogEntry[];
|
|
112
|
+
}[];
|
|
113
|
+
libraries: {
|
|
114
|
+
name: string;
|
|
115
|
+
path: string;
|
|
116
|
+
version: string;
|
|
117
|
+
entries: ChangelogEntry[];
|
|
118
|
+
}[];
|
|
119
|
+
}
|
|
120
|
+
/** Check if a DocBlock is a ChangelogDocBlock */
|
|
121
|
+
declare function isChangelogDocBlock(doc: DocBlock): doc is ChangelogDocBlock;
|
|
122
|
+
/** Check if a string is a valid VersionBumpType */
|
|
123
|
+
declare function isVersionBumpType(value: unknown): value is VersionBumpType;
|
|
124
|
+
/** Check if a string is a valid ChangeType */
|
|
125
|
+
declare function isChangeType(value: unknown): value is ChangeType;
|
|
126
|
+
//#endregion
|
|
127
|
+
export { ChangeEntry, ChangeType, ChangelogDocBlock, ChangelogEntry, ChangelogJsonExport, ChangelogResult, SemanticVersion, VersionAnalysis, VersionAnalysisResult, VersionBumpType, isChangeType, isChangelogDocBlock, isVersionBumpType };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/versioning/types.ts
|
|
2
|
+
/** Check if a DocBlock is a ChangelogDocBlock */
|
|
3
|
+
function isChangelogDocBlock(doc) {
|
|
4
|
+
return doc.kind === "changelog" && "specKey" in doc && "entries" in doc;
|
|
5
|
+
}
|
|
6
|
+
/** Check if a string is a valid VersionBumpType */
|
|
7
|
+
function isVersionBumpType(value) {
|
|
8
|
+
return value === "patch" || value === "minor" || value === "major";
|
|
9
|
+
}
|
|
10
|
+
/** Check if a string is a valid ChangeType */
|
|
11
|
+
function isChangeType(value) {
|
|
12
|
+
return typeof value === "string" && [
|
|
13
|
+
"added",
|
|
14
|
+
"changed",
|
|
15
|
+
"fixed",
|
|
16
|
+
"removed",
|
|
17
|
+
"deprecated",
|
|
18
|
+
"breaking",
|
|
19
|
+
"security"
|
|
20
|
+
].includes(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isChangeType, isChangelogDocBlock, isVersionBumpType };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { SemanticVersion, VersionBumpType } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/versioning/utils.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a semantic version string into components.
|
|
7
|
+
*
|
|
8
|
+
* @param version - Version string (e.g., "1.2.3", "1.0.0-alpha.1")
|
|
9
|
+
* @returns Parsed SemanticVersion or null if invalid
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* parseVersion("1.2.3") // { major: 1, minor: 2, patch: 3 }
|
|
13
|
+
* parseVersion("2.0.0-beta.1") // { major: 2, minor: 0, patch: 0, prerelease: "beta.1" }
|
|
14
|
+
*/
|
|
15
|
+
declare function parseVersion(version: string): SemanticVersion | null;
|
|
16
|
+
/**
|
|
17
|
+
* Strictly parse a version, throwing on invalid input.
|
|
18
|
+
*
|
|
19
|
+
* @throws Error if version is not valid semver
|
|
20
|
+
*/
|
|
21
|
+
declare function parseVersionStrict(version: string): SemanticVersion;
|
|
22
|
+
/**
|
|
23
|
+
* Format a SemanticVersion back to string.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* formatVersion({ major: 1, minor: 2, patch: 3 }) // "1.2.3"
|
|
27
|
+
* formatVersion({ major: 2, minor: 0, patch: 0, prerelease: "beta.1" }) // "2.0.0-beta.1"
|
|
28
|
+
*/
|
|
29
|
+
declare function formatVersion(version: SemanticVersion): string;
|
|
30
|
+
/**
|
|
31
|
+
* Compare two version strings.
|
|
32
|
+
*
|
|
33
|
+
* @returns -1 if a < b, 0 if a === b, 1 if a > b
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* compareVersions("1.0.0", "2.0.0") // -1
|
|
37
|
+
* compareVersions("1.2.3", "1.2.3") // 0
|
|
38
|
+
* compareVersions("2.0.0", "1.9.9") // 1
|
|
39
|
+
*/
|
|
40
|
+
declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
41
|
+
/**
|
|
42
|
+
* Check if version a is greater than version b.
|
|
43
|
+
*/
|
|
44
|
+
declare function isVersionGreater(a: string, b: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if version a is less than version b.
|
|
47
|
+
*/
|
|
48
|
+
declare function isVersionLess(a: string, b: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if two versions are equal.
|
|
51
|
+
*/
|
|
52
|
+
declare function isVersionEqual(a: string, b: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Bump a version by the specified type.
|
|
55
|
+
*
|
|
56
|
+
* @param current - Current version string
|
|
57
|
+
* @param bumpType - Type of bump: 'patch', 'minor', or 'major'
|
|
58
|
+
* @returns New version string
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* bumpVersion("1.2.3", "patch") // "1.2.4"
|
|
62
|
+
* bumpVersion("1.2.3", "minor") // "1.3.0"
|
|
63
|
+
* bumpVersion("1.2.3", "major") // "2.0.0"
|
|
64
|
+
*/
|
|
65
|
+
declare function bumpVersion(current: string, bumpType: VersionBumpType): string;
|
|
66
|
+
/**
|
|
67
|
+
* Determine the appropriate version bump type based on change impact.
|
|
68
|
+
*
|
|
69
|
+
* - Breaking changes → major
|
|
70
|
+
* - Non-breaking additions/changes → minor
|
|
71
|
+
* - Fixes only → patch
|
|
72
|
+
*
|
|
73
|
+
* @param hasBreaking - Whether breaking changes were detected
|
|
74
|
+
* @param hasNonBreaking - Whether non-breaking changes (additions, changes) were detected
|
|
75
|
+
* @returns Appropriate bump type
|
|
76
|
+
*/
|
|
77
|
+
declare function determineBumpType(hasBreaking: boolean, hasNonBreaking: boolean): VersionBumpType;
|
|
78
|
+
/**
|
|
79
|
+
* Get sort priority for bump types (higher = more significant).
|
|
80
|
+
*/
|
|
81
|
+
declare function getBumpTypePriority(bumpType: VersionBumpType): number;
|
|
82
|
+
/**
|
|
83
|
+
* Get the most significant bump type from a list.
|
|
84
|
+
*/
|
|
85
|
+
declare function getMaxBumpType(bumpTypes: VersionBumpType[]): VersionBumpType | null;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a string is a valid semantic version.
|
|
88
|
+
*/
|
|
89
|
+
declare function isValidVersion(version: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Validate a version string, returning validation errors.
|
|
92
|
+
*/
|
|
93
|
+
declare function validateVersion(version: string): string[];
|
|
94
|
+
//#endregion
|
|
95
|
+
export { bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isValidVersion, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
//#region src/versioning/utils.ts
|
|
2
|
+
/** Regex for parsing semantic versions */
|
|
3
|
+
const SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*))?(?:\+([a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*))?$/;
|
|
4
|
+
/**
|
|
5
|
+
* Parse a semantic version string into components.
|
|
6
|
+
*
|
|
7
|
+
* @param version - Version string (e.g., "1.2.3", "1.0.0-alpha.1")
|
|
8
|
+
* @returns Parsed SemanticVersion or null if invalid
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* parseVersion("1.2.3") // { major: 1, minor: 2, patch: 3 }
|
|
12
|
+
* parseVersion("2.0.0-beta.1") // { major: 2, minor: 0, patch: 0, prerelease: "beta.1" }
|
|
13
|
+
*/
|
|
14
|
+
function parseVersion(version) {
|
|
15
|
+
const match = version.trim().match(SEMVER_REGEX);
|
|
16
|
+
if (!match) return null;
|
|
17
|
+
const majorStr = match[1];
|
|
18
|
+
const minorStr = match[2];
|
|
19
|
+
const patchStr = match[3];
|
|
20
|
+
const prerelease = match[4];
|
|
21
|
+
const build = match[5];
|
|
22
|
+
if (!majorStr || !minorStr || !patchStr) return null;
|
|
23
|
+
return {
|
|
24
|
+
major: parseInt(majorStr, 10),
|
|
25
|
+
minor: parseInt(minorStr, 10),
|
|
26
|
+
patch: parseInt(patchStr, 10),
|
|
27
|
+
...prerelease && { prerelease },
|
|
28
|
+
...build && { build }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Strictly parse a version, throwing on invalid input.
|
|
33
|
+
*
|
|
34
|
+
* @throws Error if version is not valid semver
|
|
35
|
+
*/
|
|
36
|
+
function parseVersionStrict(version) {
|
|
37
|
+
const parsed = parseVersion(version);
|
|
38
|
+
if (!parsed) throw new Error(`Invalid semantic version: "${version}"`);
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format a SemanticVersion back to string.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* formatVersion({ major: 1, minor: 2, patch: 3 }) // "1.2.3"
|
|
46
|
+
* formatVersion({ major: 2, minor: 0, patch: 0, prerelease: "beta.1" }) // "2.0.0-beta.1"
|
|
47
|
+
*/
|
|
48
|
+
function formatVersion(version) {
|
|
49
|
+
let result = `${version.major}.${version.minor}.${version.patch}`;
|
|
50
|
+
if (version.prerelease) result += `-${version.prerelease}`;
|
|
51
|
+
if (version.build) result += `+${version.build}`;
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Compare two version strings.
|
|
56
|
+
*
|
|
57
|
+
* @returns -1 if a < b, 0 if a === b, 1 if a > b
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* compareVersions("1.0.0", "2.0.0") // -1
|
|
61
|
+
* compareVersions("1.2.3", "1.2.3") // 0
|
|
62
|
+
* compareVersions("2.0.0", "1.9.9") // 1
|
|
63
|
+
*/
|
|
64
|
+
function compareVersions(a, b) {
|
|
65
|
+
const versionA = parseVersionStrict(a);
|
|
66
|
+
const versionB = parseVersionStrict(b);
|
|
67
|
+
if (versionA.major !== versionB.major) return versionA.major > versionB.major ? 1 : -1;
|
|
68
|
+
if (versionA.minor !== versionB.minor) return versionA.minor > versionB.minor ? 1 : -1;
|
|
69
|
+
if (versionA.patch !== versionB.patch) return versionA.patch > versionB.patch ? 1 : -1;
|
|
70
|
+
if (versionA.prerelease && !versionB.prerelease) return -1;
|
|
71
|
+
if (!versionA.prerelease && versionB.prerelease) return 1;
|
|
72
|
+
if (versionA.prerelease && versionB.prerelease) return versionA.prerelease < versionB.prerelease ? -1 : versionA.prerelease > versionB.prerelease ? 1 : 0;
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if version a is greater than version b.
|
|
77
|
+
*/
|
|
78
|
+
function isVersionGreater(a, b) {
|
|
79
|
+
return compareVersions(a, b) === 1;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if version a is less than version b.
|
|
83
|
+
*/
|
|
84
|
+
function isVersionLess(a, b) {
|
|
85
|
+
return compareVersions(a, b) === -1;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if two versions are equal.
|
|
89
|
+
*/
|
|
90
|
+
function isVersionEqual(a, b) {
|
|
91
|
+
return compareVersions(a, b) === 0;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Bump a version by the specified type.
|
|
95
|
+
*
|
|
96
|
+
* @param current - Current version string
|
|
97
|
+
* @param bumpType - Type of bump: 'patch', 'minor', or 'major'
|
|
98
|
+
* @returns New version string
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* bumpVersion("1.2.3", "patch") // "1.2.4"
|
|
102
|
+
* bumpVersion("1.2.3", "minor") // "1.3.0"
|
|
103
|
+
* bumpVersion("1.2.3", "major") // "2.0.0"
|
|
104
|
+
*/
|
|
105
|
+
function bumpVersion(current, bumpType) {
|
|
106
|
+
const version = parseVersionStrict(current);
|
|
107
|
+
switch (bumpType) {
|
|
108
|
+
case "major": return formatVersion({
|
|
109
|
+
major: version.major + 1,
|
|
110
|
+
minor: 0,
|
|
111
|
+
patch: 0
|
|
112
|
+
});
|
|
113
|
+
case "minor": return formatVersion({
|
|
114
|
+
major: version.major,
|
|
115
|
+
minor: version.minor + 1,
|
|
116
|
+
patch: 0
|
|
117
|
+
});
|
|
118
|
+
case "patch": return formatVersion({
|
|
119
|
+
major: version.major,
|
|
120
|
+
minor: version.minor,
|
|
121
|
+
patch: version.patch + 1
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Determine the appropriate version bump type based on change impact.
|
|
127
|
+
*
|
|
128
|
+
* - Breaking changes → major
|
|
129
|
+
* - Non-breaking additions/changes → minor
|
|
130
|
+
* - Fixes only → patch
|
|
131
|
+
*
|
|
132
|
+
* @param hasBreaking - Whether breaking changes were detected
|
|
133
|
+
* @param hasNonBreaking - Whether non-breaking changes (additions, changes) were detected
|
|
134
|
+
* @returns Appropriate bump type
|
|
135
|
+
*/
|
|
136
|
+
function determineBumpType(hasBreaking, hasNonBreaking) {
|
|
137
|
+
if (hasBreaking) return "major";
|
|
138
|
+
if (hasNonBreaking) return "minor";
|
|
139
|
+
return "patch";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get sort priority for bump types (higher = more significant).
|
|
143
|
+
*/
|
|
144
|
+
function getBumpTypePriority(bumpType) {
|
|
145
|
+
switch (bumpType) {
|
|
146
|
+
case "major": return 3;
|
|
147
|
+
case "minor": return 2;
|
|
148
|
+
case "patch": return 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the most significant bump type from a list.
|
|
153
|
+
*/
|
|
154
|
+
function getMaxBumpType(bumpTypes) {
|
|
155
|
+
if (bumpTypes.length === 0) return null;
|
|
156
|
+
return bumpTypes.reduce((max, current) => getBumpTypePriority(current) > getBumpTypePriority(max) ? current : max);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if a string is a valid semantic version.
|
|
160
|
+
*/
|
|
161
|
+
function isValidVersion(version) {
|
|
162
|
+
return parseVersion(version) !== null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Validate a version string, returning validation errors.
|
|
166
|
+
*/
|
|
167
|
+
function validateVersion(version) {
|
|
168
|
+
const errors = [];
|
|
169
|
+
if (!version || typeof version !== "string") {
|
|
170
|
+
errors.push("Version must be a non-empty string");
|
|
171
|
+
return errors;
|
|
172
|
+
}
|
|
173
|
+
const trimmed = version.trim();
|
|
174
|
+
if (trimmed !== version) errors.push("Version should not have leading or trailing whitespace");
|
|
175
|
+
if (!parseVersion(trimmed)) errors.push(`Invalid semantic version format: "${version}". Expected format: MAJOR.MINOR.PATCH[-prerelease][+build]`);
|
|
176
|
+
return errors;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
export { bumpVersion, compareVersions, determineBumpType, formatVersion, getBumpTypePriority, getMaxBumpType, isValidVersion, isVersionEqual, isVersionGreater, isVersionLess, parseVersion, parseVersionStrict, validateVersion };
|