@o3r/rules-engine 10.2.0-prerelease.50 → 10.2.0-prerelease.51

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.
@@ -5,8 +5,8 @@ import { Action, MetadataFact, MetadataOperator } from './rules-engine.extractor
5
5
  * Extracts rules engine facts and operator from code
6
6
  */
7
7
  export declare class RulesEngineExtractor {
8
- private basePath;
9
- private logger;
8
+ private readonly basePath;
9
+ private readonly logger;
10
10
  /** Interface of a Fact definition */
11
11
  static readonly FACT_DEFINITIONS_INTERFACE = "FactDefinitions";
12
12
  /** Interface of an operator definition */
@@ -16,7 +16,7 @@ export declare class RulesEngineExtractor {
16
16
  /** Reserved fact names that will be filtered out of metadata */
17
17
  static readonly RESERVED_FACT_NAMES: Readonly<string[]>;
18
18
  /** TSConfig to parse the code */
19
- private tsconfig;
19
+ private readonly tsconfig;
20
20
  /** Instance of the comment parser */
21
21
  private readonly commentParser;
22
22
  constructor(tsconfigPath: string, basePath: string, logger: LoggerApi);
@@ -25,7 +25,6 @@ export declare class RulesEngineExtractor {
25
25
  *
26
26
  * @param type Name of the type to extract
27
27
  * @param sourceFile path to the code source file
28
- * @param outputPath path to the schema file to generate
29
28
  */
30
29
  private extractTypeRef;
31
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rules-engine.extractor.d.ts","sourceRoot":"","sources":["../../../../builders/rules-engine-extractor/helpers/rules-engine.extractor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAQjE,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAmE,YAAY,EAAE,gBAAgB,EAAkC,MAAM,qCAAqC,CAAC;AAE9L;;GAEG;AACH,qBAAa,oBAAoB;IAiBG,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,MAAM;IAf1E,qCAAqC;IACrC,gBAAuB,0BAA0B,qBAAqB;IACtE,0CAA0C;IAC1C,gBAAuB,+BAA+B,WAAiC;IACvF,wCAAwC;IACxC,gBAAuB,0BAA0B,uBAAuB;IACxE,gEAAgE;IAChE,gBAAuB,mBAAmB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAmB;IAEjF,kCAAkC;IAClC,OAAO,CAAC,QAAQ,CAAM;IAEtB,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;gBAE3C,YAAY,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,EAAU,MAAM,EAAE,SAAS;IAKrF;;;;;;OAMG;YACW,cAAc;IA2B5B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAiB9B;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;IA0B9B;;;;;;OAMG;IACU,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAkEtI;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ;IAMrC;;;;OAIG;IACI,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAqE/D;;;;OAIG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;CAkDpD"}
1
+ {"version":3,"file":"rules-engine.extractor.d.ts","sourceRoot":"","sources":["../../../../builders/rules-engine-extractor/helpers/rules-engine.extractor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AASjE,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EACL,MAAM,EAMN,YAAY,EACZ,gBAAgB,EAIjB,MAAM,qCAAqC,CAAC;AAE7C;;GAEG;AACH,qBAAa,oBAAoB;IAiBG,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;IAf5F,qCAAqC;IACrC,gBAAuB,0BAA0B,qBAAqB;IACtE,0CAA0C;IAC1C,gBAAuB,+BAA+B,WAAiC;IACvF,wCAAwC;IACxC,gBAAuB,0BAA0B,uBAAuB;IACxE,gEAAgE;IAChE,gBAAuB,mBAAmB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAmB;IAEjF,kCAAkC;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAE/B,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;gBAE3C,YAAY,EAAE,MAAM,EAAmB,QAAQ,EAAE,MAAM,EAAmB,MAAM,EAAE,SAAS;IAKvG;;;;;OAKG;YACW,cAAc;IA2B5B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAMvB;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAiB9B;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;IA0B9B;;;;;;OAMG;IACU,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAmGtI;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ;IAMrC;;;;OAIG;IACI,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAqE/D;;;;OAIG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;CAkDpD"}
@@ -1,16 +1,42 @@
1
1
  /** Supported types for a fact */
2
- export type FactSupportedTypes = 'string' | 'number' | 'date' | 'object' | 'boolean';
3
- /** Fact as description in the metadata file */
4
- export interface MetadataFact {
2
+ export type FactSupportedTypes = 'string' | 'number' | 'date' | 'object' | 'boolean' | 'array';
3
+ /** Base metadata fact */
4
+ interface BaseMetadataFact {
5
5
  /** Name of the Fact */
6
6
  name: string;
7
7
  /** Fact description */
8
8
  description?: string;
9
9
  /** Type of the fact */
10
10
  type: FactSupportedTypes;
11
+ }
12
+ /** Metadata fact of type enum */
13
+ export interface EnumMetadataFact extends BaseMetadataFact {
14
+ /** @inheritdoc */
15
+ type: 'string';
16
+ /** Set of values of enum of type string */
17
+ enum: string[];
18
+ }
19
+ /** Metadata fact of type object */
20
+ export interface ObjectMetadataFact extends BaseMetadataFact {
21
+ /** @inheritdoc */
22
+ type: 'object';
11
23
  /** Path to schema file describing the complex file */
12
24
  schemaFile?: string;
13
25
  }
26
+ /** Metadata fact of type array */
27
+ export interface ArrayMetadataFact extends BaseMetadataFact {
28
+ /** @inheritdoc */
29
+ type: 'array';
30
+ /** Items in array */
31
+ items: MetadataFact;
32
+ }
33
+ /** Metadata fact of type string, number, date, or boolean */
34
+ export interface OtherMetadataFact extends BaseMetadataFact {
35
+ /** @inheritdoc */
36
+ type: 'string' | 'number' | 'date' | 'boolean';
37
+ }
38
+ /** Fact as description in the metadata file */
39
+ export type MetadataFact = OtherMetadataFact | ObjectMetadataFact | EnumMetadataFact | ArrayMetadataFact;
14
40
  /** Supported types for a operand */
15
41
  export type MetadataOperatorSupportedTypes = 'string' | 'number' | 'date' | 'object' | 'boolean';
16
42
  /** All supported default type of an operator when not explicit by the operator (`unknown` as parameter) */
@@ -54,4 +80,5 @@ export interface Action {
54
80
  /** Map of parameter with types */
55
81
  parameters?: Record<string, string>;
56
82
  }
83
+ export {};
57
84
  //# sourceMappingURL=rules-engine.extractor.interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules-engine.extractor.interfaces.d.ts","sourceRoot":"","sources":["../../../../builders/rules-engine-extractor/helpers/rules-engine.extractor.interfaces.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,MAAM,kBAAkB,GAAG,QA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AAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC"}
1
+ {"version":3,"file":"rules-engine.extractor.interfaces.d.ts","sourceRoot":"","sources":["../../../../builders/rules-engine-extractor/helpers/rules-engine.extractor.interfaces.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/F,yBAAyB;AACzB,UAAU,gBAAgB;IACxB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,iCAAiC;AACjC,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,kBAAkB;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,2CAA2C;IAC3C,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,mCAAmC;AACnC,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,kBAAkB;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,kCAAkC;AAClC,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,kBAAkB;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,qBAAqB;IAErB,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,6DAA6D;AAC7D,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,kBAAkB;IAClB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;CAChD;AAED,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AACzG,oCAAoC;AACpC,MAAM,MAAM,8BAA8B,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,4GAA4G;AAC5G,eAAO,MAAM,wBAAwB,EAAE,8BAA8B,EAA4C,CAAC;AAElH,0CAA0C;AAC1C,eAAO,MAAM,iBAAiB,EAAE,8BAA8B,EAAsD,CAAC;AAErH,+CAA+C;AAC/C,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,KAAK,EAAE,CAAC,8BAA8B,GAAG,SAAS,CAAC,EAAE,CAAC;IACtD;;;;;;QAMI;IACJ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,WAAW,EAAE,eAAe,CAAC;IAC7B,sCAAsC;IACtC,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,6DAA6D;IAC7D,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC;AAED,sCAAsC;AACtC,MAAM,WAAW,MAAM;IACrB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC"}
@@ -38,9 +38,8 @@ class RulesEngineExtractor {
38
38
  *
39
39
  * @param type Name of the type to extract
40
40
  * @param sourceFile path to the code source file
41
- * @param outputPath path to the schema file to generate
42
41
  */
43
- async extractTypeRef(type, sourceFile, outputPath) {
42
+ async extractTypeRef(type, sourceFile) {
44
43
  const internalLibFiles = this.tsconfig.extraOptions?.otterSubModuleRefs?.length > 0 ?
45
44
  await (0, rxjs_1.lastValueFrom)((0, rxjs_1.zip)(...(this.tsconfig.extraOptions?.otterSubModuleRefs).map((value) => (0, globby_1.default)(value))).pipe((0, operators_1.map)((globFiles) => globFiles.reduce((acc, files) => [
46
45
  ...acc,
@@ -60,7 +59,7 @@ class RulesEngineExtractor {
60
59
  if (schema?.definitions?.['utils.DateTime']) {
61
60
  schema.definitions['utils.DateTime'] = { type: 'string', format: 'date-time' };
62
61
  }
63
- return node_fs_1.promises.writeFile(outputPath, JSON.stringify(schema, null, 2));
62
+ return schema;
64
63
  }
65
64
  /**
66
65
  * Extract the type node used to generate the type metadata.
@@ -191,21 +190,59 @@ class RulesEngineExtractor {
191
190
  }
192
191
  const typeName = mainType.getText(source);
193
192
  const type = ts.isTypeReferenceNode(mainType) && typeName !== 'Date' ? 'object' : typeName.replace('Date', 'date');
194
- const fact = {
195
- name,
196
- description,
197
- type
198
- };
193
+ let fact;
199
194
  if (type === 'object') {
200
- const schemaFile = `${core_1.strings.dasherize(typeName)}.schema.json`;
195
+ fact = {
196
+ type: 'object',
197
+ name,
198
+ description
199
+ };
201
200
  try {
202
- await this.extractTypeRef(typeName, sourceFile, path.resolve(schemaFolderFullPath, schemaFile));
203
- fact.schemaFile = path.join(schemaFolderRelativePath, schemaFile).replace(/[\\]/g, '/');
201
+ const schema = await this.extractTypeRef(typeName, sourceFile);
202
+ if (schema === null) {
203
+ this.logger.warn(`Schema of ${typeName} is null.`);
204
+ }
205
+ else if (schema.type === 'object') {
206
+ const schemaFile = `${core_1.strings.dasherize(typeName)}.schema.json`;
207
+ await node_fs_1.promises.writeFile(path.resolve(schemaFolderFullPath, schemaFile), JSON.stringify(schema, null, 2));
208
+ fact = {
209
+ ...fact,
210
+ schemaFile: path.join(schemaFolderRelativePath, schemaFile).replace(/[\\]/g, '/')
211
+ };
212
+ }
213
+ else if (schema.type === 'array') {
214
+ fact = {
215
+ ...fact,
216
+ type: 'array',
217
+ items: schema.items
218
+ };
219
+ }
220
+ else if (schema.enum) {
221
+ fact = {
222
+ ...fact,
223
+ type: 'string',
224
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
225
+ enum: schema.enum?.filter((value) => !!value).map((v) => v.toString())
226
+ };
227
+ }
228
+ else {
229
+ fact = {
230
+ ...fact,
231
+ type: schema.type
232
+ };
233
+ }
204
234
  }
205
235
  catch {
206
236
  this.logger.warn(`Error when parsing ${type} in ${sourceFile}`);
207
237
  }
208
238
  }
239
+ else {
240
+ fact = {
241
+ type: type,
242
+ name,
243
+ description
244
+ };
245
+ }
209
246
  return fact;
210
247
  }));
211
248
  }
@@ -60,7 +60,7 @@ exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderW
60
60
  await Promise.all(Object.entries(rulesEngineFactsMetadataFileWithContent)
61
61
  .reduce((acc, [metadataFilePath, factsFile]) => acc.concat([
62
62
  ...(factsFile.facts || [])
63
- .filter(({ schemaFile }) => !!schemaFile)
63
+ .filter((fact) => fact.type === 'object' && !!fact.schemaFile)
64
64
  .map(({ schemaFile }) => ({ fullPath: (0, node_path_1.resolve)((0, node_path_1.dirname)(metadataFilePath), schemaFile), relativePath: schemaFile }))
65
65
  ]), [])
66
66
  .map(({ fullPath, relativePath }) => node_fs_1.promises.copyFile(fullPath, (0, node_path_1.resolve)(basePath, relativePath))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/rules-engine",
3
- "version": "10.2.0-prerelease.50",
3
+ "version": "10.2.0-prerelease.51",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -49,10 +49,10 @@
49
49
  "@ngrx/entity": "~17.1.0",
50
50
  "@ngrx/store": "~17.1.0",
51
51
  "@ngx-translate/core": "~15.0.0",
52
- "@o3r/core": "^10.2.0-prerelease.50",
53
- "@o3r/extractors": "^10.2.0-prerelease.50",
54
- "@o3r/logger": "^10.2.0-prerelease.50",
55
- "@o3r/schematics": "^10.2.0-prerelease.50",
52
+ "@o3r/core": "^10.2.0-prerelease.51",
53
+ "@o3r/extractors": "^10.2.0-prerelease.51",
54
+ "@o3r/logger": "^10.2.0-prerelease.51",
55
+ "@o3r/schematics": "^10.2.0-prerelease.51",
56
56
  "@schematics/angular": "~17.3.0",
57
57
  "globby": "^11.1.0",
58
58
  "jasmine": "^5.0.0",