@contractspec/lib.contracts 1.49.0 → 1.50.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.
@@ -0,0 +1,179 @@
1
+ //#region src/versioning/refs.d.ts
2
+ /**
3
+ * Base reference types for ContractSpec versioning.
4
+ *
5
+ * Provides canonical reference types for linking between specs.
6
+ * Domain-specific refs (OpRef, EventRef, etc.) should alias these
7
+ * base types for consistency and maintainability.
8
+ *
9
+ * @module versioning/refs
10
+ */
11
+ /**
12
+ * Base reference type for versioned specs.
13
+ * Used to reference any spec by its key and version.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const opRef: VersionedSpecRef = { key: 'auth.login', version: '1.0.0' };
18
+ * ```
19
+ */
20
+ interface VersionedSpecRef {
21
+ /** Unique key identifying the spec (e.g., "auth.login", "user.created"). */
22
+ key: string;
23
+ /** Semantic version of the spec (e.g., "1.0.0", "2.1.0"). */
24
+ version: string;
25
+ }
26
+ /**
27
+ * Base reference type for specs with optional version.
28
+ * When version is omitted, typically refers to the latest version.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Reference to latest version
33
+ * const latestRef: OptionalVersionedSpecRef = { key: 'auth.login' };
34
+ *
35
+ * // Reference to specific version
36
+ * const specificRef: OptionalVersionedSpecRef = { key: 'auth.login', version: '1.0.0' };
37
+ * ```
38
+ */
39
+ interface OptionalVersionedSpecRef {
40
+ /** Unique key identifying the spec. */
41
+ key: string;
42
+ /** Optional semantic version. When omitted, refers to the latest version. */
43
+ version?: string;
44
+ }
45
+ /**
46
+ * Base reference type for unversioned spec keys.
47
+ * Used when only the key is needed without version information.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const featureRef: SpecKeyRef = { key: 'premium-features' };
52
+ * ```
53
+ */
54
+ interface SpecKeyRef {
55
+ /** Unique key identifying the spec. */
56
+ key: string;
57
+ }
58
+ /**
59
+ * Checks if a value is a valid VersionedSpecRef.
60
+ *
61
+ * @param ref - The value to check
62
+ * @returns True if the value has both key and version as strings
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const ref = { key: 'auth.login', version: '1.0.0' };
67
+ * if (isVersionedSpecRef(ref)) {
68
+ * console.log(`Spec: ${ref.key}@${ref.version}`);
69
+ * }
70
+ * ```
71
+ */
72
+ declare function isVersionedSpecRef(ref: unknown): ref is VersionedSpecRef;
73
+ /**
74
+ * Checks if a value is a valid OptionalVersionedSpecRef.
75
+ *
76
+ * @param ref - The value to check
77
+ * @returns True if the value has a key string and optional version string
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const ref = { key: 'auth.login' };
82
+ * if (isOptionalVersionedSpecRef(ref)) {
83
+ * console.log(`Spec: ${ref.key}${ref.version ? `@${ref.version}` : ''}`);
84
+ * }
85
+ * ```
86
+ */
87
+ declare function isOptionalVersionedSpecRef(ref: unknown): ref is OptionalVersionedSpecRef;
88
+ /**
89
+ * Checks if a value is a valid SpecKeyRef.
90
+ *
91
+ * @param ref - The value to check
92
+ * @returns True if the value has a key string
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const ref = { key: 'premium-features' };
97
+ * if (isSpecKeyRef(ref)) {
98
+ * console.log(`Feature: ${ref.key}`);
99
+ * }
100
+ * ```
101
+ */
102
+ declare function isSpecKeyRef(ref: unknown): ref is SpecKeyRef;
103
+ /**
104
+ * Creates a versioned spec reference.
105
+ *
106
+ * @param key - The spec key (e.g., "auth.login")
107
+ * @param version - The semantic version (e.g., "1.0.0")
108
+ * @returns A VersionedSpecRef object
109
+ * @throws {Error} If key or version is empty
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const ref = createVersionedRef('auth.login', '1.0.0');
114
+ * // { key: 'auth.login', version: '1.0.0' }
115
+ * ```
116
+ */
117
+ declare function createVersionedRef(key: string, version: string): VersionedSpecRef;
118
+ /**
119
+ * Creates an optional versioned spec reference.
120
+ *
121
+ * @param key - The spec key (e.g., "auth.login")
122
+ * @param version - Optional semantic version
123
+ * @returns An OptionalVersionedSpecRef object
124
+ * @throws {Error} If key is empty
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Reference to latest version
129
+ * const latestRef = createOptionalRef('auth.login');
130
+ * // { key: 'auth.login' }
131
+ *
132
+ * // Reference to specific version
133
+ * const specificRef = createOptionalRef('auth.login', '1.0.0');
134
+ * // { key: 'auth.login', version: '1.0.0' }
135
+ * ```
136
+ */
137
+ declare function createOptionalRef(key: string, version?: string): OptionalVersionedSpecRef;
138
+ /**
139
+ * Creates a spec key reference.
140
+ *
141
+ * @param key - The spec key (e.g., "premium-features")
142
+ * @returns A SpecKeyRef object
143
+ * @throws {Error} If key is empty
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const ref = createKeyRef('premium-features');
148
+ * // { key: 'premium-features' }
149
+ * ```
150
+ */
151
+ declare function createKeyRef(key: string): SpecKeyRef;
152
+ /**
153
+ * Formats a versioned ref as a string key.
154
+ *
155
+ * @param ref - The versioned spec reference
156
+ * @returns A string in the format "key.vversion"
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const str = formatVersionedRefKey({ key: 'auth.login', version: '1.0.0' });
161
+ * // "auth.login.v1.0.0"
162
+ * ```
163
+ */
164
+ declare function formatVersionedRefKey(ref: VersionedSpecRef): string;
165
+ /**
166
+ * Parses a versioned ref string back into a ref object.
167
+ *
168
+ * @param refKey - A string in the format "key.vversion"
169
+ * @returns A VersionedSpecRef or undefined if parsing fails
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const ref = parseVersionedRefKey('auth.login.v1.0.0');
174
+ * // { key: 'auth.login', version: '1.0.0' }
175
+ * ```
176
+ */
177
+ declare function parseVersionedRefKey(refKey: string): VersionedSpecRef | undefined;
178
+ //#endregion
179
+ export { OptionalVersionedSpecRef, SpecKeyRef, VersionedSpecRef, createKeyRef, createOptionalRef, createVersionedRef, formatVersionedRefKey, isOptionalVersionedSpecRef, isSpecKeyRef, isVersionedSpecRef, parseVersionedRefKey };
@@ -0,0 +1,161 @@
1
+ //#region src/versioning/refs.ts
2
+ /**
3
+ * Checks if a value is a valid VersionedSpecRef.
4
+ *
5
+ * @param ref - The value to check
6
+ * @returns True if the value has both key and version as strings
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const ref = { key: 'auth.login', version: '1.0.0' };
11
+ * if (isVersionedSpecRef(ref)) {
12
+ * console.log(`Spec: ${ref.key}@${ref.version}`);
13
+ * }
14
+ * ```
15
+ */
16
+ function isVersionedSpecRef(ref) {
17
+ return typeof ref === "object" && ref !== null && "key" in ref && typeof ref.key === "string" && ref.key.length > 0 && "version" in ref && typeof ref.version === "string" && ref.version.length > 0;
18
+ }
19
+ /**
20
+ * Checks if a value is a valid OptionalVersionedSpecRef.
21
+ *
22
+ * @param ref - The value to check
23
+ * @returns True if the value has a key string and optional version string
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const ref = { key: 'auth.login' };
28
+ * if (isOptionalVersionedSpecRef(ref)) {
29
+ * console.log(`Spec: ${ref.key}${ref.version ? `@${ref.version}` : ''}`);
30
+ * }
31
+ * ```
32
+ */
33
+ function isOptionalVersionedSpecRef(ref) {
34
+ if (typeof ref !== "object" || ref === null) return false;
35
+ if (!("key" in ref)) return false;
36
+ if (typeof ref.key !== "string" || ref.key.length === 0) return false;
37
+ if ("version" in ref && ref.version != null) return typeof ref.version === "string";
38
+ return true;
39
+ }
40
+ /**
41
+ * Checks if a value is a valid SpecKeyRef.
42
+ *
43
+ * @param ref - The value to check
44
+ * @returns True if the value has a key string
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const ref = { key: 'premium-features' };
49
+ * if (isSpecKeyRef(ref)) {
50
+ * console.log(`Feature: ${ref.key}`);
51
+ * }
52
+ * ```
53
+ */
54
+ function isSpecKeyRef(ref) {
55
+ return typeof ref === "object" && ref !== null && "key" in ref && typeof ref.key === "string" && ref.key.length > 0;
56
+ }
57
+ /**
58
+ * Creates a versioned spec reference.
59
+ *
60
+ * @param key - The spec key (e.g., "auth.login")
61
+ * @param version - The semantic version (e.g., "1.0.0")
62
+ * @returns A VersionedSpecRef object
63
+ * @throws {Error} If key or version is empty
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const ref = createVersionedRef('auth.login', '1.0.0');
68
+ * // { key: 'auth.login', version: '1.0.0' }
69
+ * ```
70
+ */
71
+ function createVersionedRef(key, version) {
72
+ if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
73
+ if (!version || version.trim().length === 0) throw new Error("Spec version cannot be empty");
74
+ return {
75
+ key: key.trim(),
76
+ version: version.trim()
77
+ };
78
+ }
79
+ /**
80
+ * Creates an optional versioned spec reference.
81
+ *
82
+ * @param key - The spec key (e.g., "auth.login")
83
+ * @param version - Optional semantic version
84
+ * @returns An OptionalVersionedSpecRef object
85
+ * @throws {Error} If key is empty
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Reference to latest version
90
+ * const latestRef = createOptionalRef('auth.login');
91
+ * // { key: 'auth.login' }
92
+ *
93
+ * // Reference to specific version
94
+ * const specificRef = createOptionalRef('auth.login', '1.0.0');
95
+ * // { key: 'auth.login', version: '1.0.0' }
96
+ * ```
97
+ */
98
+ function createOptionalRef(key, version) {
99
+ if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
100
+ const ref = { key: key.trim() };
101
+ if (version != null && version.trim().length > 0) ref.version = version.trim();
102
+ return ref;
103
+ }
104
+ /**
105
+ * Creates a spec key reference.
106
+ *
107
+ * @param key - The spec key (e.g., "premium-features")
108
+ * @returns A SpecKeyRef object
109
+ * @throws {Error} If key is empty
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const ref = createKeyRef('premium-features');
114
+ * // { key: 'premium-features' }
115
+ * ```
116
+ */
117
+ function createKeyRef(key) {
118
+ if (!key || key.trim().length === 0) throw new Error("Spec key cannot be empty");
119
+ return { key: key.trim() };
120
+ }
121
+ /**
122
+ * Formats a versioned ref as a string key.
123
+ *
124
+ * @param ref - The versioned spec reference
125
+ * @returns A string in the format "key.vversion"
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const str = formatVersionedRefKey({ key: 'auth.login', version: '1.0.0' });
130
+ * // "auth.login.v1.0.0"
131
+ * ```
132
+ */
133
+ function formatVersionedRefKey(ref) {
134
+ return `${ref.key}.v${ref.version}`;
135
+ }
136
+ /**
137
+ * Parses a versioned ref string back into a ref object.
138
+ *
139
+ * @param refKey - A string in the format "key.vversion"
140
+ * @returns A VersionedSpecRef or undefined if parsing fails
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const ref = parseVersionedRefKey('auth.login.v1.0.0');
145
+ * // { key: 'auth.login', version: '1.0.0' }
146
+ * ```
147
+ */
148
+ function parseVersionedRefKey(refKey) {
149
+ const match = refKey.match(/^(.+)\.v(\d+\.\d+\.\d+(?:-.+)?)$/);
150
+ if (!match) return void 0;
151
+ const key = match[1];
152
+ const version = match[2];
153
+ if (!key || !version) return void 0;
154
+ return {
155
+ key,
156
+ version
157
+ };
158
+ }
159
+
160
+ //#endregion
161
+ export { createKeyRef, createOptionalRef, createVersionedRef, formatVersionedRefKey, isOptionalVersionedSpecRef, isSpecKeyRef, isVersionedSpecRef, parseVersionedRefKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/lib.contracts",
3
- "version": "1.49.0",
3
+ "version": "1.50.0",
4
4
  "description": "Core contract specification definitions and runtime",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -25,8 +25,8 @@
25
25
  "test": "bun test"
26
26
  },
27
27
  "devDependencies": {
28
- "@contractspec/tool.tsdown": "1.49.0",
29
- "@contractspec/tool.typescript": "1.49.0",
28
+ "@contractspec/tool.tsdown": "1.50.0",
29
+ "@contractspec/tool.typescript": "1.50.0",
30
30
  "@types/express": "^5.0.3",
31
31
  "@types/turndown": "^5.0.6",
32
32
  "tsdown": "^0.19.0",
@@ -35,8 +35,8 @@
35
35
  "dependencies": {
36
36
  "@aws-sdk/client-secrets-manager": "^3.966.0",
37
37
  "@aws-sdk/client-sqs": "^3.966.0",
38
- "@contractspec/lib.logger": "1.49.0",
39
- "@contractspec/lib.schema": "1.49.0",
38
+ "@contractspec/lib.logger": "1.50.0",
39
+ "@contractspec/lib.schema": "1.50.0",
40
40
  "@elevenlabs/elevenlabs-js": "^2.30.0",
41
41
  "@google-cloud/secret-manager": "^6.1.1",
42
42
  "@google-cloud/storage": "^7.18.0",
@@ -339,6 +339,7 @@
339
339
  "./translations/tenant": "./dist/translations/tenant.js",
340
340
  "./types": "./dist/types.js",
341
341
  "./versioning": "./dist/versioning/index.js",
342
+ "./versioning/refs": "./dist/versioning/refs.js",
342
343
  "./versioning/types": "./dist/versioning/types.js",
343
344
  "./versioning/utils": "./dist/versioning/utils.js",
344
345
  "./workflow": "./dist/workflow/index.js",