@itwin/ecschema-editing 3.0.0-dev.76 → 3.0.0-dev.77

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.
@@ -13,7 +13,7 @@ export interface IDiagnosticReporter {
13
13
  * of diagnostics codes identifying which rules violations to ignore during validation.
14
14
  */
15
15
  suppressions?: Map<string, string[]>;
16
- /** The I18N object to use for message translation. */
16
+ /** The localization object to use for message translation. */
17
17
  localization?: Localization;
18
18
  /**
19
19
  * Handles the given [[IDiagnostic]] based on the implementation requirements for a
@@ -55,7 +55,7 @@ export declare abstract class SuppressionDiagnosticReporter implements IDiagnost
55
55
  }
56
56
  /**
57
57
  * An abstract [[SuppressionDiagnosticReporter]] implementation that formats the
58
- * diagnostic message with the message args. If an I18N implementation is specified,
58
+ * diagnostic message with the message args. If a Localization implementation is specified,
59
59
  * the message will also be translated.
60
60
  * @beta
61
61
  */
@@ -63,10 +63,10 @@ export declare abstract class FormatDiagnosticReporter extends SuppressionDiagno
63
63
  /**
64
64
  * Initializes a new FormatDiagnosticReporter
65
65
  * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.
66
- * @param localization The I18N instance to use to translate validation messages.
66
+ * @param localization The Localization instance to use to translate validation messages.
67
67
  */
68
68
  constructor(suppressions?: Map<string, string[]>, localization?: Localization);
69
- /** The I18N object to use for message translation. If undefined, no translation will occur. */
69
+ /** The Localization object to use for message translation. If undefined, no translation will occur. */
70
70
  localization?: Localization;
71
71
  /**
72
72
  * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)
@@ -1 +1 @@
1
- {"version":3,"file":"DiagnosticReporter.d.ts","sourceRoot":"","sources":["../../src/Validation/DiagnosticReporter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAQ7C;;;GAGG;AACH,MAAM,WA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AC,gBAAgB,CAAC,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAEzF;;;;;;OAMG;IACH,SAAS,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,SAAI,GAAG,MAAM;IAI5F,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,aAAa;CAItB"}
@@ -50,7 +50,7 @@ class SuppressionDiagnosticReporter {
50
50
  exports.SuppressionDiagnosticReporter = SuppressionDiagnosticReporter;
51
51
  /**
52
52
  * An abstract [[SuppressionDiagnosticReporter]] implementation that formats the
53
- * diagnostic message with the message args. If an I18N implementation is specified,
53
+ * diagnostic message with the message args. If a Localization implementation is specified,
54
54
  * the message will also be translated.
55
55
  * @beta
56
56
  */
@@ -58,7 +58,7 @@ class FormatDiagnosticReporter extends SuppressionDiagnosticReporter {
58
58
  /**
59
59
  * Initializes a new FormatDiagnosticReporter
60
60
  * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.
61
- * @param localization The I18N instance to use to translate validation messages.
61
+ * @param localization The Localization instance to use to translate validation messages.
62
62
  */
63
63
  constructor(suppressions, localization) {
64
64
  super(suppressions);
@@ -1 +1 @@
1
- {"version":3,"file":"DiagnosticReporter.js","sourceRoot":"","sources":["../../src/Validation/DiagnosticReporter.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAKH,iCAAkC;AAElC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAC9C,MAAM,kBAAkB,GAAG,GAAG,oBAAoB,IAAI,uBAAuB,EAAE,CAAC;AAwBhF;;;;;GAKG;AACH,MAAsB,6BAA6B;IAGjD;;;OAGG;IACH,YAAY,YAAoC;QAC9C,IAAI,CAAC,aAAa,GAAG,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,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAE1D,IAAI,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;YAC7D,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3F,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEO,gBAAgB,CAAC,UAAyB;QAChD,IAAI,CAAC,IAAI,CAAC,YAAY;YACpB,OAAO,UAAU,CAAC,WAAW,CAAC;QAEhC,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;IAClF,CAAC;IAEO,iBAAiB,CAAC,UAAyB;QACjD,OAAO,GAAG,kBAAkB,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;IACpD,CAAC;IAEO,aAAa,CAAI,KAA2B,EAAE,OAAgB;QACpE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,CAAU,CAAC;QAClF,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlED,4DAkEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Diagnostic\n */\n\nimport { Localization } from \"@itwin/core-common\";\nimport { AnyDiagnostic } from \"./Diagnostic\";\n\nimport assert = require(\"assert\");\n\nconst translationNamespace = \"ECSchemaMetaData\";\nconst subTranslationNamespace = \"Diagnostics\";\nconst baseTranslationKey = `${translationNamespace}:${subTranslationNamespace}`;\n\n/**\n * Interface used to report [[IDiagnostic]] objects created during schema validation.\n * @beta\n */\nexport interface IDiagnosticReporter {\n /**\n * A map where the key is a schema full name and the value is a collection\n * of diagnostics codes identifying which rules violations to ignore during validation.\n */\n suppressions?: Map<string, string[]>;\n\n /** The I18N object to use for message translation. */\n localization?: Localization;\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n report(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract base class for [[IDiagnosticReporter]] implementation that used the\n * provided Map to suppress certain rule violations from being reported. The Map's key\n * a schema full name, and the Map's value is a collection of rule codes to suppress.\n * @beta\n */\nexport abstract class SuppressionDiagnosticReporter implements IDiagnosticReporter {\n private _suppressions?: Map<string, string[]>;\n\n /**\n * Initializes a new SuppressionDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n */\n constructor(suppressions?: Map<string, string[]>) {\n this._suppressions = suppressions;\n }\n\n /**\n * Gets the collection of ISchemaDiagnosticSuppression objects that identify\n * rules violations to ignore during validation.\n */\n public get suppressions(): Map<string, string[]> | undefined {\n return this._suppressions;\n }\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public report(diagnostic: AnyDiagnostic) {\n if (this._suppressions && this._suppressions.has(diagnostic.schema.fullName)) {\n const suppressedCodes = this._suppressions.get(diagnostic.schema.fullName);\n if (suppressedCodes!.includes(diagnostic.code))\n return;\n }\n\n this.reportInternal(diagnostic);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n protected abstract reportInternal(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract [[SuppressionDiagnosticReporter]] implementation that formats the\n * diagnostic message with the message args. If an I18N implementation is specified,\n * the message will also be translated.\n * @beta\n */\nexport abstract class FormatDiagnosticReporter extends SuppressionDiagnosticReporter {\n /**\n * Initializes a new FormatDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n * @param localization The I18N instance to use to translate validation messages.\n */\n constructor(suppressions?: Map<string, string[]>, localization?: Localization) {\n super(suppressions);\n this.localization = localization;\n }\n\n /** The I18N object to use for message translation. If undefined, no translation will occur. */\n public localization?: Localization;\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public reportInternal(diagnostic: AnyDiagnostic) {\n const message = this.formatMessage(diagnostic);\n this.reportDiagnostic(diagnostic, message);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n * @param messageText The formatted message.\n */\n protected abstract reportDiagnostic(diagnostic: AnyDiagnostic, messageText: string): void;\n\n /**\n * Helper method that formats string with provided arguments where the place holders\n * are in the the format '{0}', '{1}', etc.\n * @param text The text to format.\n * @param args The arguments to place in the text.\n * @param baseIndex The base index for the args, used for validation (typically 0, which is the default).\n */\n protected formatStringFromArgs(text: string, args: ArrayLike<string>, baseIndex = 0): string {\n return text.replace(/{(\\d+)}/g, (_match, index: string) => this.assertDefined(args[+index + baseIndex]));\n }\n\n private formatMessage(diagnostic: AnyDiagnostic): string {\n let translatedMessage = this.translateMessage(diagnostic);\n\n if (diagnostic.messageArgs && diagnostic.messageArgs.length > 0)\n translatedMessage = this.formatStringFromArgs(translatedMessage, diagnostic.messageArgs);\n return translatedMessage;\n }\n\n private translateMessage(diagnostic: AnyDiagnostic): string {\n if (!this.localization)\n return diagnostic.messageText;\n\n return this.localization.getLocalizedString(this.getTranslationKey(diagnostic));\n }\n\n private getTranslationKey(diagnostic: AnyDiagnostic): string {\n return `${baseTranslationKey}.${diagnostic.code}`;\n }\n\n private assertDefined<T>(value: T | null | undefined, message?: string): T {\n if (value === undefined || value === null) return assert(false, message) as never;\n return value;\n }\n}\n"]}
1
+ {"version":3,"file":"DiagnosticReporter.js","s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AC,CAAC;IAC7C,CAAC;IAUD;;;;;;OAMG;IACO,oBAAoB,CAAC,IAAY,EAAE,IAAuB,EAAE,SAAS,GAAG,CAAC;QACjF,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3G,CAAC;IAEO,aAAa,CAAC,UAAyB;QAC7C,IAAI,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAE1D,IAAI,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;YAC7D,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3F,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEO,gBAAgB,CAAC,UAAyB;QAChD,IAAI,CAAC,IAAI,CAAC,YAAY;YACpB,OAAO,UAAU,CAAC,WAAW,CAAC;QAEhC,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;IAClF,CAAC;IAEO,iBAAiB,CAAC,UAAyB;QACjD,OAAO,GAAG,kBAAkB,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;IACpD,CAAC;IAEO,aAAa,CAAI,KAA2B,EAAE,OAAgB;QACpE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,CAAU,CAAC;QAClF,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlED,4DAkEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Diagnostic\n */\n\nimport { Localization } from \"@itwin/core-common\";\nimport { AnyDiagnostic } from \"./Diagnostic\";\n\nimport assert = require(\"assert\");\n\nconst translationNamespace = \"ECSchemaMetaData\";\nconst subTranslationNamespace = \"Diagnostics\";\nconst baseTranslationKey = `${translationNamespace}:${subTranslationNamespace}`;\n\n/**\n * Interface used to report [[IDiagnostic]] objects created during schema validation.\n * @beta\n */\nexport interface IDiagnosticReporter {\n /**\n * A map where the key is a schema full name and the value is a collection\n * of diagnostics codes identifying which rules violations to ignore during validation.\n */\n suppressions?: Map<string, string[]>;\n\n /** The localization object to use for message translation. */\n localization?: Localization;\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n report(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract base class for [[IDiagnosticReporter]] implementation that used the\n * provided Map to suppress certain rule violations from being reported. The Map's key\n * a schema full name, and the Map's value is a collection of rule codes to suppress.\n * @beta\n */\nexport abstract class SuppressionDiagnosticReporter implements IDiagnosticReporter {\n private _suppressions?: Map<string, string[]>;\n\n /**\n * Initializes a new SuppressionDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n */\n constructor(suppressions?: Map<string, string[]>) {\n this._suppressions = suppressions;\n }\n\n /**\n * Gets the collection of ISchemaDiagnosticSuppression objects that identify\n * rules violations to ignore during validation.\n */\n public get suppressions(): Map<string, string[]> | undefined {\n return this._suppressions;\n }\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public report(diagnostic: AnyDiagnostic) {\n if (this._suppressions && this._suppressions.has(diagnostic.schema.fullName)) {\n const suppressedCodes = this._suppressions.get(diagnostic.schema.fullName);\n if (suppressedCodes!.includes(diagnostic.code))\n return;\n }\n\n this.reportInternal(diagnostic);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n */\n protected abstract reportInternal(diagnostic: AnyDiagnostic): void;\n}\n\n/**\n * An abstract [[SuppressionDiagnosticReporter]] implementation that formats the\n * diagnostic message with the message args. If a Localization implementation is specified,\n * the message will also be translated.\n * @beta\n */\nexport abstract class FormatDiagnosticReporter extends SuppressionDiagnosticReporter {\n /**\n * Initializes a new FormatDiagnosticReporter\n * @param suppressions A Map where the key is a schema full name and the value is collection of diagnostic codes to suppress.\n * @param localization The Localization instance to use to translate validation messages.\n */\n constructor(suppressions?: Map<string, string[]>, localization?: Localization) {\n super(suppressions);\n this.localization = localization;\n }\n\n /** The Localization object to use for message translation. If undefined, no translation will occur. */\n public localization?: Localization;\n\n /**\n * Prior to reporting the [[IDiagnostic]], the diagnostic message is formatted (with translations)\n * base on arguments contained in the diagnostic. Calls reportDiagnostic after the message is formatted.\n * @param diagnostic The diagnostic to report.\n */\n public reportInternal(diagnostic: AnyDiagnostic) {\n const message = this.formatMessage(diagnostic);\n this.reportDiagnostic(diagnostic, message);\n }\n\n /**\n * Handles the given [[IDiagnostic]] based on the implementation requirements for a\n * given reporter.\n * @param diagnostic The diagnostic to report.\n * @param messageText The formatted message.\n */\n protected abstract reportDiagnostic(diagnostic: AnyDiagnostic, messageText: string): void;\n\n /**\n * Helper method that formats string with provided arguments where the place holders\n * are in the the format '{0}', '{1}', etc.\n * @param text The text to format.\n * @param args The arguments to place in the text.\n * @param baseIndex The base index for the args, used for validation (typically 0, which is the default).\n */\n protected formatStringFromArgs(text: string, args: ArrayLike<string>, baseIndex = 0): string {\n return text.replace(/{(\\d+)}/g, (_match, index: string) => this.assertDefined(args[+index + baseIndex]));\n }\n\n private formatMessage(diagnostic: AnyDiagnostic): string {\n let translatedMessage = this.translateMessage(diagnostic);\n\n if (diagnostic.messageArgs && diagnostic.messageArgs.length > 0)\n translatedMessage = this.formatStringFromArgs(translatedMessage, diagnostic.messageArgs);\n return translatedMessage;\n }\n\n private translateMessage(diagnostic: AnyDiagnostic): string {\n if (!this.localization)\n return diagnostic.messageText;\n\n return this.localization.getLocalizedString(this.getTranslationKey(diagnostic));\n }\n\n private getTranslationKey(diagnostic: AnyDiagnostic): string {\n return `${baseTranslationKey}.${diagnostic.code}`;\n }\n\n private assertDefined<T>(value: T | null | undefined, message?: string): T {\n if (value === undefined || value === null) return assert(false, message) as never;\n return value;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/ecschema-editing",
3
- "version": "3.0.0-dev.76",
3
+ "version": "3.0.0-dev.77",
4
4
  "description": "ECSchema editing and validation API",
5
5
  "license": "MIT",
6
6
  "main": "lib/ecschema-editing.js",
@@ -20,12 +20,12 @@
20
20
  "url": "http://www.bentley.com"
21
21
  },
22
22
  "devDependencies": {
23
- "@itwin/core-bentley": "3.0.0-dev.76",
24
- "@itwin/core-common": "3.0.0-dev.76",
25
- "@itwin/build-tools": "3.0.0-dev.76",
26
- "@itwin/eslint-plugin": "3.0.0-dev.76",
27
- "@itwin/core-i18n": "3.0.0-dev.76",
28
- "@itwin/ecschema-metadata": "3.0.0-dev.76",
23
+ "@itwin/core-bentley": "3.0.0-dev.77",
24
+ "@itwin/core-common": "3.0.0-dev.77",
25
+ "@itwin/build-tools": "3.0.0-dev.77",
26
+ "@itwin/eslint-plugin": "3.0.0-dev.77",
27
+ "@itwin/core-i18n": "3.0.0-dev.77",
28
+ "@itwin/ecschema-metadata": "3.0.0-dev.77",
29
29
  "@bentley/units-schema": "^1.0.5",
30
30
  "@types/almost-equal": "1.1.0",
31
31
  "@types/benchmark": "^2.1.0",
@@ -49,8 +49,8 @@
49
49
  "xmlhttprequest": "^1.8.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@itwin/core-bentley": "^3.0.0-dev.76",
53
- "@itwin/ecschema-metadata": "^3.0.0-dev.76"
52
+ "@itwin/core-bentley": "^3.0.0-dev.77",
53
+ "@itwin/ecschema-metadata": "^3.0.0-dev.77"
54
54
  },
55
55
  "dependencies": {
56
56
  "almost-equal": "^1.1.0"