@living-architecture/riviere-extract-config 0.3.3 → 0.3.4

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/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './types';
2
- export { isValidExtractionConfig, validateExtractionConfig, parseExtractionConfig, formatValidationErrors, mapAjvErrors, ExtractionConfigValidationError, type ValidationError, type ValidationResult, } from './validation';
2
+ export { isValidExtractionConfig, validateExtractionConfig, validateExtractionConfigSchema, parseExtractionConfig, formatValidationErrors, mapAjvErrors, ExtractionConfigValidationError, type ValidationError, type ValidationResult, } from './validation';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,+BAA+B,EAC/B,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,8BAA8B,EAC9B,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,+BAA+B,EAC/B,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './types';
2
- export { isValidExtractionConfig, validateExtractionConfig, parseExtractionConfig, formatValidationErrors, mapAjvErrors, ExtractionConfigValidationError, } from './validation';
2
+ export { isValidExtractionConfig, validateExtractionConfig, validateExtractionConfigSchema, parseExtractionConfig, formatValidationErrors, mapAjvErrors, ExtractionConfigValidationError, } from './validation';
package/dist/types.d.ts CHANGED
@@ -62,10 +62,100 @@ export type Predicate = HasDecoratorPredicate | HasJSDocPredicate | ExtendsClass
62
62
  export interface NotUsed {
63
63
  notUsed: true;
64
64
  }
65
+ /** Transform operations to apply to extracted values. */
66
+ export interface Transform {
67
+ stripSuffix?: string;
68
+ stripPrefix?: string;
69
+ toLowerCase?: true;
70
+ toUpperCase?: true;
71
+ kebabToPascal?: true;
72
+ pascalToKebab?: true;
73
+ }
74
+ /** Extracts a hardcoded literal value. */
75
+ export interface LiteralExtractionRule {
76
+ literal: string | boolean | number;
77
+ }
78
+ /** Extracts value from the class name. */
79
+ export interface FromClassNameExtractionRule {
80
+ fromClassName: true | {
81
+ transform?: Transform;
82
+ };
83
+ }
84
+ /** Extracts value from the method name. */
85
+ export interface FromMethodNameExtractionRule {
86
+ fromMethodName: true | {
87
+ transform?: Transform;
88
+ };
89
+ }
90
+ /** Extracts value from the file path using regex capture. */
91
+ export interface FromFilePathExtractionRule {
92
+ fromFilePath: {
93
+ pattern: string;
94
+ capture: number;
95
+ transform?: Transform;
96
+ };
97
+ }
98
+ /** Extracts value from a class property. */
99
+ export interface FromPropertyExtractionRule {
100
+ fromProperty: {
101
+ name: string;
102
+ kind: 'static' | 'instance';
103
+ transform?: Transform;
104
+ };
105
+ }
106
+ /** Extracts value from decorator argument. */
107
+ export interface FromDecoratorArgExtractionRule {
108
+ fromDecoratorArg: {
109
+ position?: number;
110
+ name?: string;
111
+ transform?: Transform;
112
+ };
113
+ }
114
+ /** Extracts value from the decorator name itself. */
115
+ export interface FromDecoratorNameExtractionRule {
116
+ fromDecoratorName: true | {
117
+ mapping?: Record<string, string>;
118
+ transform?: Transform;
119
+ };
120
+ }
121
+ /** Extracts value from generic type argument. */
122
+ export interface FromGenericArgExtractionRule {
123
+ fromGenericArg: {
124
+ interface: string;
125
+ position: number;
126
+ transform?: Transform;
127
+ };
128
+ }
129
+ /** Extracts method parameters and return type. */
130
+ export interface FromMethodSignatureExtractionRule {
131
+ fromMethodSignature: true;
132
+ }
133
+ /** Extracts constructor parameter names and types. */
134
+ export interface FromConstructorParamsExtractionRule {
135
+ fromConstructorParams: true;
136
+ }
137
+ /** Extracts type name of parameter at position. */
138
+ export interface FromParameterTypeExtractionRule {
139
+ fromParameterType: {
140
+ position: number;
141
+ transform?: Transform;
142
+ };
143
+ }
144
+ /**
145
+ * Union of all extraction rule types.
146
+ * Each rule type corresponds to a different source of metadata.
147
+ */
148
+ export type ExtractionRule = LiteralExtractionRule | FromClassNameExtractionRule | FromMethodNameExtractionRule | FromFilePathExtractionRule | FromPropertyExtractionRule | FromDecoratorArgExtractionRule | FromDecoratorNameExtractionRule | FromGenericArgExtractionRule | FromMethodSignatureExtractionRule | FromConstructorParamsExtractionRule | FromParameterTypeExtractionRule;
149
+ /**
150
+ * Extract block mapping field names to extraction rules.
151
+ * Each key is a Riviere schema field name (e.g., apiType, httpMethod, path).
152
+ */
153
+ export type ExtractBlock = Record<string, ExtractionRule>;
65
154
  /** Rule specifying what to find and how to filter matches. */
66
155
  export interface DetectionRule {
67
156
  find: FindTarget;
68
157
  where: Predicate;
158
+ extract?: ExtractBlock;
69
159
  }
70
160
  /** Either a detection rule or a marker that the component type is unused. */
71
161
  export type ComponentRule = NotUsed | DetectionRule;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAA;AAE5D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,GAAG,IAAI,CAAA;AAE5F,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QACvB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,kDAAkD;AAClD,MAAM,WAAW,iBAAi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,aAAa,CAAC,CAAA;AAEvD;;;GAGG;AACH,MAAM,WAAW,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,aAAa,CAAA;IACnB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,aAAa,CAAA;IAClB,OAAO,EAAE,aAAa,CAAA;IACtB,QAAQ,EAAE,aAAa,CAAA;IACvB,KAAK,EAAE,aAAa,CAAA;IACpB,YAAY,EAAE,aAAa,CAAA;IAC3B,EAAE,EAAE,aAAa,CAAA;IACjB,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,YAAY,EAAE,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB"}
@@ -31,8 +31,18 @@ interface AjvErrorLike {
31
31
  * @returns Array of ValidationError objects.
32
32
  */
33
33
  export declare function mapAjvErrors(errors: AjvErrorLike[] | null | undefined): ValidationError[];
34
+ /**
35
+ * Validates data against the ExtractionConfig JSON Schema only.
36
+ * Does NOT check semantic rules like required extraction fields.
37
+ * Use validateExtractionConfig() for full validation.
38
+ * @param data - Data to validate.
39
+ * @returns Validation result with errors if invalid.
40
+ */
41
+ export declare function validateExtractionConfigSchema(data: unknown): ValidationResult;
34
42
  /**
35
43
  * Validates data against the ExtractionConfig schema.
44
+ * Performs both JSON Schema validation and semantic validation
45
+ * for required extraction rules.
36
46
  * @param data - Data to validate.
37
47
  * @returns Validation result with errors if invalid.
38
48
  */
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAQ/C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,gBAAgB,CAE/E;AAED,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,mDAAmD;AACnD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,eAAe,EAAE,CAAA;CAC1B;AAED,4DAA4D;AAC5D,qBAAa,+BAAgC,SAAQ,KAAK;aAE5B,MAAM,EAAE,eAAe,EAAE;IADrD,mEAAmE;gBACvC,MAAM,EAAE,eAAe,EAAE;CAItD;AASD,UAAU,YAAY;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,EAAE,CAQzF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAaxE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAExE;A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 'ajv';
2
2
  import addFormats from 'ajv-formats';
3
3
  import rawSchema from '../extraction-config.schema.json' with { type: 'json' };
4
+ /**
5
+ * Required extraction fields by component type.
6
+ * These fields must have extraction rules defined (unless notUsed: true).
7
+ */
8
+ const REQUIRED_FIELDS = {
9
+ api: ['apiType'],
10
+ event: ['eventName'],
11
+ eventHandler: ['subscribedEvents'],
12
+ domainOp: ['operationName'],
13
+ ui: ['route'],
14
+ useCase: [],
15
+ };
16
+ const COMPONENT_TYPES = [
17
+ 'api',
18
+ 'useCase',
19
+ 'domainOp',
20
+ 'event',
21
+ 'eventHandler',
22
+ 'ui',
23
+ ];
4
24
  const ajv = new Ajv({ allErrors: true });
5
25
  addFormats(ajv);
6
26
  const validate = ajv.compile(rawSchema);
@@ -42,22 +62,96 @@ export function mapAjvErrors(errors) {
42
62
  message: e.message ?? 'unknown error',
43
63
  }));
44
64
  }
65
+ function isNotUsed(rule) {
66
+ return rule !== undefined && 'notUsed' in rule && rule.notUsed === true;
67
+ }
68
+ function hasDetectionRule(rule) {
69
+ return rule !== undefined && 'find' in rule && 'where' in rule;
70
+ }
71
+ function getExtractedFields(rule) {
72
+ if (!rule || !('extract' in rule) || !rule.extract) {
73
+ return [];
74
+ }
75
+ return Object.keys(rule.extract);
76
+ }
77
+ function validateModuleExtractionRules(module, moduleIndex) {
78
+ const errors = [];
79
+ for (const componentType of COMPONENT_TYPES) {
80
+ const rule = module[componentType];
81
+ if (isNotUsed(rule)) {
82
+ continue;
83
+ }
84
+ if (!hasDetectionRule(rule)) {
85
+ continue;
86
+ }
87
+ const requiredFields = REQUIRED_FIELDS[componentType];
88
+ if (requiredFields.length === 0) {
89
+ continue;
90
+ }
91
+ const extractedFields = getExtractedFields(rule);
92
+ const missingFields = requiredFields.filter((field) => !extractedFields.includes(field));
93
+ if (missingFields.length > 0) {
94
+ errors.push({
95
+ path: `/modules/${moduleIndex}/${componentType}`,
96
+ message: `Missing required extraction rules: ${missingFields.join(', ')}. ` +
97
+ `Add extraction rules to the 'extract' block or use 'notUsed: true' if not extracting ${componentType} components.`,
98
+ });
99
+ }
100
+ }
101
+ return errors;
102
+ }
103
+ function validateAllExtractionRules(config) {
104
+ return config.modules.flatMap((module, index) => {
105
+ if ('$ref' in module) {
106
+ return [];
107
+ }
108
+ return validateModuleExtractionRules(module, index);
109
+ });
110
+ }
111
+ /**
112
+ * Validates data against the ExtractionConfig JSON Schema only.
113
+ * Does NOT check semantic rules like required extraction fields.
114
+ * Use validateExtractionConfig() for full validation.
115
+ * @param data - Data to validate.
116
+ * @returns Validation result with errors if invalid.
117
+ */
118
+ export function validateExtractionConfigSchema(data) {
119
+ const schemaValid = validate(data) === true;
120
+ if (!schemaValid) {
121
+ return {
122
+ valid: false,
123
+ errors: mapAjvErrors(validate.errors),
124
+ };
125
+ }
126
+ return {
127
+ valid: true,
128
+ errors: [],
129
+ };
130
+ }
45
131
  /**
46
132
  * Validates data against the ExtractionConfig schema.
133
+ * Performs both JSON Schema validation and semantic validation
134
+ * for required extraction rules.
47
135
  * @param data - Data to validate.
48
136
  * @returns Validation result with errors if invalid.
49
137
  */
50
138
  export function validateExtractionConfig(data) {
51
- const valid = validate(data) === true;
52
- if (valid) {
139
+ // Type guard validates schema AND narrows type in one step
140
+ if (!isValidExtractionConfig(data)) {
141
+ // Get detailed error messages from schema validation
142
+ return validateExtractionConfigSchema(data);
143
+ }
144
+ // data is now narrowed to ExtractionConfig
145
+ const semanticErrors = validateAllExtractionRules(data);
146
+ if (semanticErrors.length > 0) {
53
147
  return {
54
- valid: true,
55
- errors: [],
148
+ valid: false,
149
+ errors: semanticErrors,
56
150
  };
57
151
  }
58
152
  return {
59
- valid: false,
60
- errors: mapAjvErrors(validate.errors),
153
+ valid: true,
154
+ errors: [],
61
155
  };
62
156
  }
63
157
  /**
@@ -132,6 +132,241 @@
132
132
  },
133
133
  "where": {
134
134
  "$ref": "#/$defs/predicate"
135
+ },
136
+ "extract": {
137
+ "$ref": "#/$defs/extractBlock",
138
+ "description": "Extraction rules for metadata fields"
139
+ }
140
+ }
141
+ },
142
+ "extractBlock": {
143
+ "type": "object",
144
+ "description": "Extraction rules mapping field names to extraction rules",
145
+ "additionalProperties": {
146
+ "$ref": "#/$defs/extractionRule"
147
+ }
148
+ },
149
+ "extractionRule": {
150
+ "oneOf": [
151
+ { "$ref": "#/$defs/literalExtractionRule" },
152
+ { "$ref": "#/$defs/fromClassNameExtractionRule" },
153
+ { "$ref": "#/$defs/fromMethodNameExtractionRule" },
154
+ { "$ref": "#/$defs/fromFilePathExtractionRule" },
155
+ { "$ref": "#/$defs/fromPropertyExtractionRule" },
156
+ { "$ref": "#/$defs/fromDecoratorArgExtractionRule" },
157
+ { "$ref": "#/$defs/fromDecoratorNameExtractionRule" },
158
+ { "$ref": "#/$defs/fromGenericArgExtractionRule" },
159
+ { "$ref": "#/$defs/fromMethodSignatureExtractionRule" },
160
+ { "$ref": "#/$defs/fromConstructorParamsExtractionRule" },
161
+ { "$ref": "#/$defs/fromParameterTypeExtractionRule" }
162
+ ]
163
+ },
164
+ "fromMethodNameExtractionRule": {
165
+ "type": "object",
166
+ "description": "Extracts value from the method name",
167
+ "required": ["fromMethodName"],
168
+ "additionalProperties": false,
169
+ "properties": {
170
+ "fromMethodName": {
171
+ "oneOf": [
172
+ { "type": "boolean", "const": true },
173
+ {
174
+ "type": "object",
175
+ "additionalProperties": false,
176
+ "properties": {
177
+ "transform": { "$ref": "#/$defs/transform" }
178
+ }
179
+ }
180
+ ]
181
+ }
182
+ }
183
+ },
184
+ "fromFilePathExtractionRule": {
185
+ "type": "object",
186
+ "description": "Extracts value from the file path using regex capture",
187
+ "required": ["fromFilePath"],
188
+ "additionalProperties": false,
189
+ "properties": {
190
+ "fromFilePath": {
191
+ "type": "object",
192
+ "required": ["pattern", "capture"],
193
+ "additionalProperties": false,
194
+ "properties": {
195
+ "pattern": { "type": "string", "minLength": 1 },
196
+ "capture": { "type": "integer", "minimum": 0 },
197
+ "transform": { "$ref": "#/$defs/transform" }
198
+ }
199
+ }
200
+ }
201
+ },
202
+ "fromPropertyExtractionRule": {
203
+ "type": "object",
204
+ "description": "Extracts value from a class property",
205
+ "required": ["fromProperty"],
206
+ "additionalProperties": false,
207
+ "properties": {
208
+ "fromProperty": {
209
+ "type": "object",
210
+ "required": ["name", "kind"],
211
+ "additionalProperties": false,
212
+ "properties": {
213
+ "name": { "type": "string", "minLength": 1 },
214
+ "kind": { "type": "string", "enum": ["static", "instance"] },
215
+ "transform": { "$ref": "#/$defs/transform" }
216
+ }
217
+ }
218
+ }
219
+ },
220
+ "fromDecoratorArgExtractionRule": {
221
+ "type": "object",
222
+ "description": "Extracts value from decorator argument",
223
+ "required": ["fromDecoratorArg"],
224
+ "additionalProperties": false,
225
+ "properties": {
226
+ "fromDecoratorArg": {
227
+ "type": "object",
228
+ "additionalProperties": false,
229
+ "minProperties": 1,
230
+ "properties": {
231
+ "position": { "type": "integer", "minimum": 0 },
232
+ "name": { "type": "string", "minLength": 1 },
233
+ "transform": { "$ref": "#/$defs/transform" }
234
+ }
235
+ }
236
+ }
237
+ },
238
+ "fromDecoratorNameExtractionRule": {
239
+ "type": "object",
240
+ "description": "Extracts value from the decorator name itself",
241
+ "required": ["fromDecoratorName"],
242
+ "additionalProperties": false,
243
+ "properties": {
244
+ "fromDecoratorName": {
245
+ "oneOf": [
246
+ { "type": "boolean", "const": true },
247
+ {
248
+ "type": "object",
249
+ "additionalProperties": false,
250
+ "properties": {
251
+ "mapping": {
252
+ "type": "object",
253
+ "additionalProperties": { "type": "string" },
254
+ "minProperties": 1
255
+ },
256
+ "transform": { "$ref": "#/$defs/transform" }
257
+ }
258
+ }
259
+ ]
260
+ }
261
+ }
262
+ },
263
+ "fromGenericArgExtractionRule": {
264
+ "type": "object",
265
+ "description": "Extracts value from generic type argument",
266
+ "required": ["fromGenericArg"],
267
+ "additionalProperties": false,
268
+ "properties": {
269
+ "fromGenericArg": {
270
+ "type": "object",
271
+ "required": ["interface", "position"],
272
+ "additionalProperties": false,
273
+ "properties": {
274
+ "interface": { "type": "string", "minLength": 1 },
275
+ "position": { "type": "integer", "minimum": 0 },
276
+ "transform": { "$ref": "#/$defs/transform" }
277
+ }
278
+ }
279
+ }
280
+ },
281
+ "fromMethodSignatureExtractionRule": {
282
+ "type": "object",
283
+ "description": "Extracts method parameters and return type",
284
+ "required": ["fromMethodSignature"],
285
+ "additionalProperties": false,
286
+ "properties": {
287
+ "fromMethodSignature": {
288
+ "type": "boolean",
289
+ "const": true
290
+ }
291
+ }
292
+ },
293
+ "fromConstructorParamsExtractionRule": {
294
+ "type": "object",
295
+ "description": "Extracts constructor parameter names and types",
296
+ "required": ["fromConstructorParams"],
297
+ "additionalProperties": false,
298
+ "properties": {
299
+ "fromConstructorParams": {
300
+ "type": "boolean",
301
+ "const": true
302
+ }
303
+ }
304
+ },
305
+ "fromParameterTypeExtractionRule": {
306
+ "type": "object",
307
+ "description": "Extracts type name of parameter at position",
308
+ "required": ["fromParameterType"],
309
+ "additionalProperties": false,
310
+ "properties": {
311
+ "fromParameterType": {
312
+ "type": "object",
313
+ "required": ["position"],
314
+ "additionalProperties": false,
315
+ "properties": {
316
+ "position": { "type": "integer", "minimum": 0 },
317
+ "transform": { "$ref": "#/$defs/transform" }
318
+ }
319
+ }
320
+ }
321
+ },
322
+ "fromClassNameExtractionRule": {
323
+ "type": "object",
324
+ "description": "Extracts value from the class name",
325
+ "required": ["fromClassName"],
326
+ "additionalProperties": false,
327
+ "properties": {
328
+ "fromClassName": {
329
+ "oneOf": [
330
+ { "type": "boolean", "const": true },
331
+ {
332
+ "type": "object",
333
+ "additionalProperties": false,
334
+ "properties": {
335
+ "transform": { "$ref": "#/$defs/transform" }
336
+ }
337
+ }
338
+ ],
339
+ "description": "Extract from class name, optionally with transform"
340
+ }
341
+ }
342
+ },
343
+ "transform": {
344
+ "type": "object",
345
+ "description": "Transform operations to apply to extracted value",
346
+ "additionalProperties": false,
347
+ "minProperties": 1,
348
+ "properties": {
349
+ "stripSuffix": { "type": "string", "minLength": 1 },
350
+ "stripPrefix": { "type": "string", "minLength": 1 },
351
+ "toLowerCase": { "type": "boolean", "const": true },
352
+ "toUpperCase": { "type": "boolean", "const": true },
353
+ "kebabToPascal": { "type": "boolean", "const": true },
354
+ "pascalToKebab": { "type": "boolean", "const": true }
355
+ }
356
+ },
357
+ "literalExtractionRule": {
358
+ "type": "object",
359
+ "description": "Extracts a hardcoded literal value",
360
+ "required": ["literal"],
361
+ "additionalProperties": false,
362
+ "properties": {
363
+ "literal": {
364
+ "oneOf": [
365
+ { "type": "string", "minLength": 1 },
366
+ { "type": "boolean" },
367
+ { "type": "number" }
368
+ ],
369
+ "description": "Literal value to use for this field"
135
370
  }
136
371
  }
137
372
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@living-architecture/riviere-extract-config",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"