@itwin/core-backend 3.1.0-dev.27 → 3.1.0-dev.32

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.
@@ -1,5 +1,5 @@
1
- import { Schema } from "@itwin/ecschema-metadata";
2
1
  import { IModelDb } from "./IModelDb";
2
+ import type { Schema as SchemaType } from "@itwin/ecschema-metadata";
3
3
  /**
4
4
  * A utility class for retrieving EC Schema objects from an iModel. Loaded schemas are held in memory within
5
5
  * a schema context managed by IModelSchemaLoader. The IModelSchemaLoader object should be held in memory if
@@ -16,11 +16,11 @@ export declare class IModelSchemaLoader {
16
16
  * @param schemaName a string with the name of the schema to load.
17
17
  * @throws [IModelError]($common) if the schema is not found or cannot be loaded.
18
18
  */
19
- getSchema<T extends Schema>(schemaName: string): T;
19
+ getSchema<T extends SchemaType>(schemaName: string): T;
20
20
  /** Attempts to get a schema by name
21
21
  * @param schemaName a string with the name of the schema to load.
22
22
  * @throws [IModelError]($common) if the schema exists, but cannot be loaded.
23
23
  */
24
- tryGetSchema<T extends Schema>(schemaName: string): T | undefined;
24
+ tryGetSchema<T extends SchemaType>(schemaName: string): T | undefined;
25
25
  }
26
26
  //# sourceMappingURL=IModelSchemaLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IModelSchemaLoader.d.ts","sourceRoot":"","sources":["../../src/IModelSchemaLoader.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6B,MAAM,EAA6C,MAAM,0BAA0B,CAAC;AAGxH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAIV,OAAO,CAAC,OAAO;IAHlC,OAAO,CAAC,QAAQ,CAAgB;IAEhC,gBAAgB;gBACW,OAAO,EAAE,QAAQ;IAM5C;;;OAGG;IACI,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;IAQzD;;;OAGG;IACI,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;CAMzE"}
1
+ {"version":3,"file":"IModelSchemaLoader.d.ts","sourceRoot":"","sources":["../../src/IModelSchemaLoader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAwC,MAAM,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AA6B3G;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAIV,OAAO,CAAC,OAAO;IAHlC,OAAO,CAAC,QAAQ,CAAuB;IAEvC,gBAAgB;gBACW,OAAO,EAAE,QAAQ;IAU5C;;;OAGG;IACI,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;IAQ7D;;;OAGG;IACI,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;CAM7E"}
@@ -6,8 +6,32 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.IModelSchemaLoader = void 0;
8
8
  const core_bentley_1 = require("@itwin/core-bentley");
9
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
10
9
  const core_common_1 = require("@itwin/core-common");
10
+ /* eslint-disable @typescript-eslint/naming-convention */
11
+ /* eslint-disable @typescript-eslint/no-var-requires */
12
+ let Schema;
13
+ let SchemaContext;
14
+ let SchemaKey;
15
+ let SchemaMatchType;
16
+ let ECVersion;
17
+ /** The ecschema-metadata package is now an optional dependency. If the package
18
+ * has not been installed, the exception is caught below. All the types will be
19
+ * undefined, and an exception is throw in the IModelSchemaLoader constructor.
20
+ */
21
+ function loadMetadata() {
22
+ try {
23
+ const metadata = require("@itwin/ecschema-metadata");
24
+ Schema = metadata.Schema;
25
+ SchemaContext = metadata.SchemaContext;
26
+ SchemaKey = metadata.SchemaKey;
27
+ SchemaMatchType = metadata.SchemaMatchType;
28
+ ECVersion = metadata.ECVersion;
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
11
35
  /**
12
36
  * A utility class for retrieving EC Schema objects from an iModel. Loaded schemas are held in memory within
13
37
  * a schema context managed by IModelSchemaLoader. The IModelSchemaLoader object should be held in memory if
@@ -19,7 +43,10 @@ class IModelSchemaLoader {
19
43
  /** @internal */
20
44
  constructor(_iModel) {
21
45
  this._iModel = _iModel;
22
- this._context = new ecschema_metadata_1.SchemaContext();
46
+ // If the ecschema-metadata package was not installed inform the caller.
47
+ if (!loadMetadata())
48
+ throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotFound, "IModelSchemaLoader requires that @bentley/ecschema-metadata be installed.");
49
+ this._context = new SchemaContext();
23
50
  const locater = new IModelSchemaLocater(this._iModel);
24
51
  this._context.addLocater(locater);
25
52
  }
@@ -39,8 +66,8 @@ class IModelSchemaLoader {
39
66
  */
40
67
  tryGetSchema(schemaName) {
41
68
  // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.
42
- const key = new ecschema_metadata_1.SchemaKey(schemaName, new ecschema_metadata_1.ECVersion(1, 0, 0));
43
- const schema = this._context.getSchemaSync(key, ecschema_metadata_1.SchemaMatchType.Latest);
69
+ const key = new SchemaKey(schemaName, new ECVersion(1, 0, 0));
70
+ const schema = this._context.getSchemaSync(key, SchemaMatchType.Latest);
44
71
  return schema;
45
72
  }
46
73
  }
@@ -73,8 +100,8 @@ class IModelSchemaLocater {
73
100
  const schemaProps = this.getSchemaString(schemaKey.name);
74
101
  if (!schemaProps)
75
102
  return undefined;
76
- context = context ? context : new ecschema_metadata_1.SchemaContext();
77
- return ecschema_metadata_1.Schema.fromJsonSync(schemaProps, context);
103
+ context = context ? context : new SchemaContext();
104
+ return Schema.fromJsonSync(schemaProps, context);
78
105
  }
79
106
  /** Read schema data from the iModel as JSON string
80
107
  * @param schemaName A string with the name of the schema to load.
@@ -1 +1 @@
1
- {"version":3,"file":"IModelSchemaLoader.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AI,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAM,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,aAAa,CAAmB,SAAoB,EAAE,UAA2B,EAAE,OAAmC;QAC3H,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW;YACd,OAAO,SAAS,CAAC;QAEnB,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,iCAAa,EAAE,CAAC;QAClD,OAAO,0BAAM,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAM,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,UAAkB;QACxC,MAAM,GAAG,GAAiD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACtG,IAAI,SAAS,KAAK,GAAG,CAAC,KAAK,EAAE;YAC3B,IAAI,2BAAY,CAAC,QAAQ,KAAK,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE;gBAC9C,OAAO,SAAS,CAAC;aAClB;YACD,MAAM,IAAI,yBAAW,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC;SACzE;QACD,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { ECVersion, ISchemaLocater, Schema, SchemaContext, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/**\r\n * A utility class for retrieving EC Schema objects from an iModel. Loaded schemas are held in memory within\r\n * a schema context managed by IModelSchemaLoader. The IModelSchemaLoader object should be held in memory if\r\n * multiple calls to [[getSchema]] or [[tryGetSchema]] is a possibility, thereby avoiding unnecessary schema\r\n * retrievals from an iModel.\r\n * @alpha\r\n */\r\nexport class IModelSchemaLoader {\r\n private _context: SchemaContext;\r\n\r\n /** @internal */\r\n public constructor(private _iModel: IModelDb) {\r\n this._context = new SchemaContext();\r\n const locater = new IModelSchemaLocater(this._iModel);\r\n this._context.addLocater(locater);\r\n }\r\n\r\n /** Get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [IModelError]($common) if the schema is not found or cannot be loaded.\r\n */\r\n public getSchema<T extends Schema>(schemaName: string): T {\r\n const schema = this.tryGetSchema(schemaName);\r\n if (!schema)\r\n throw new IModelError(IModelStatus.NotFound, `reading schema=${schemaName}`);\r\n\r\n return schema as T;\r\n }\r\n\r\n /** Attempts to get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public tryGetSchema<T extends Schema>(schemaName: string): T | undefined {\r\n // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.\r\n const key = new SchemaKey(schemaName, new ECVersion(1, 0, 0));\r\n const schema = this._context.getSchemaSync(key, SchemaMatchType.Latest);\r\n return schema as T;\r\n }\r\n}\r\n\r\n/**\r\n * A private ISchemaLocater implementation for locating and retrieving EC Schema objects from an iModel\r\n * @alpha\r\n */\r\nclass IModelSchemaLocater implements ISchemaLocater {\r\n /** @internal */\r\n public constructor(private _iModel: IModelDb) { }\r\n\r\n /** Get a schema by [SchemaKey]\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public async getSchema<T extends Schema>(schemaKey: SchemaKey, matchType: SchemaMatchType, context?: SchemaContext | undefined): Promise<T | undefined> {\r\n return this.getSchemaSync(schemaKey, matchType, context) as T;\r\n }\r\n\r\n /** Get a schema by [SchemaKey] synchronously.\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public getSchemaSync<T extends Schema>(schemaKey: SchemaKey, _matchType: SchemaMatchType, context?: SchemaContext | undefined): T | undefined {\r\n const schemaProps = this.getSchemaString(schemaKey.name);\r\n if (!schemaProps)\r\n return undefined;\r\n\r\n context = context ? context : new SchemaContext();\r\n return Schema.fromJsonSync(schemaProps, context) as T;\r\n }\r\n\r\n /** Read schema data from the iModel as JSON string\r\n * @param schemaName A string with the name of the schema to load.\r\n * @returns A string with the JSON for the schema or `undefined` if the schema is not found.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n private getSchemaString(schemaName: string): string | undefined {\r\n const val: IModelJsNative.ErrorStatusOrResult<any, any> = this._iModel.nativeDb.getSchema(schemaName);\r\n if (undefined !== val.error) {\r\n if (IModelStatus.NotFound === val.error.status) {\r\n return undefined;\r\n }\r\n throw new IModelError(val.error.status, `reading schema=${schemaName}`);\r\n }\r\n return val.result;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"IModelSchemaLoader.js","sourceRoot":"","sources":["../../src/IModelSchemaLoader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAmD;AACnD,oDAAiD;AAKjD,yDAAyD;AACzD,wDAAwD;AAExD,IAAI,MAAW,CAAC;AAChB,IAAI,aAAkB,CAAC;AACvB,IAAI,SAAc,CAAC;AACnB,IAAI,eAAoB,CAAC;AACzB,IAAI,SAAc,CAAC;AAEnB;;;GAGG;AACH,SAAS,YAAY;IACnB,IAAI;QACF,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","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport type { ISchemaLocater as ISchemaLocaterType, Schema as SchemaType } from \"@itwin/ecschema-metadata\";\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\n/* eslint-disable @typescript-eslint/no-var-requires */\r\n\r\nlet Schema: any;\r\nlet SchemaContext: any;\r\nlet SchemaKey: any;\r\nlet SchemaMatchType: any;\r\nlet ECVersion: any;\r\n\r\n/** The ecschema-metadata package is now an optional dependency. If the package\r\n * has not been installed, the exception is caught below. All the types will be\r\n * undefined, and an exception is throw in the IModelSchemaLoader constructor.\r\n */\r\nfunction loadMetadata(): boolean {\r\n try {\r\n const metadata = require(\"@itwin/ecschema-metadata\");\r\n Schema = metadata.Schema;\r\n SchemaContext = metadata.SchemaContext;\r\n SchemaKey = metadata.SchemaKey;\r\n SchemaMatchType = metadata.SchemaMatchType;\r\n ECVersion = metadata.ECVersion;\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * A utility class for retrieving EC Schema objects from an iModel. Loaded schemas are held in memory within\r\n * a schema context managed by IModelSchemaLoader. The IModelSchemaLoader object should be held in memory if\r\n * multiple calls to [[getSchema]] or [[tryGetSchema]] is a possibility, thereby avoiding unnecessary schema\r\n * retrievals from an iModel.\r\n * @alpha\r\n */\r\nexport class IModelSchemaLoader {\r\n private _context: typeof SchemaContext;\r\n\r\n /** @internal */\r\n public constructor(private _iModel: IModelDb) {\r\n // If the ecschema-metadata package was not installed inform the caller.\r\n if (!loadMetadata())\r\n throw new IModelError(IModelStatus.NotFound, \"IModelSchemaLoader requires that @bentley/ecschema-metadata be installed.\");\r\n\r\n this._context = new SchemaContext();\r\n const locater = new IModelSchemaLocater(this._iModel);\r\n this._context.addLocater(locater);\r\n }\r\n\r\n /** Get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [IModelError]($common) if the schema is not found or cannot be loaded.\r\n */\r\n public getSchema<T extends SchemaType>(schemaName: string): T {\r\n const schema = this.tryGetSchema(schemaName);\r\n if (!schema)\r\n throw new IModelError(IModelStatus.NotFound, `reading schema=${schemaName}`);\r\n\r\n return schema as T;\r\n }\r\n\r\n /** Attempts to get a schema by name\r\n * @param schemaName a string with the name of the schema to load.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public tryGetSchema<T extends SchemaType>(schemaName: string): T | undefined {\r\n // SchemaKey version is not used when locating schema in an iModel, so the version is arbitrary.\r\n const key = new SchemaKey(schemaName, new ECVersion(1, 0, 0));\r\n const schema = this._context.getSchemaSync(key, SchemaMatchType.Latest);\r\n return schema as T;\r\n }\r\n}\r\n\r\n/**\r\n * A private ISchemaLocater implementation for locating and retrieving EC Schema objects from an iModel\r\n * @alpha\r\n */\r\nclass IModelSchemaLocater implements ISchemaLocaterType {\r\n /** @internal */\r\n public constructor(private _iModel: IModelDb) { }\r\n\r\n /** Get a schema by [SchemaKey]\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public async getSchema<T extends SchemaType>(schemaKey: typeof SchemaKey, matchType: typeof SchemaMatchType, context?: typeof SchemaContext | undefined): Promise<T | undefined> {\r\n return this.getSchemaSync(schemaKey, matchType, context) as T;\r\n }\r\n\r\n /** Get a schema by [SchemaKey] synchronously.\r\n * @param schemaKey The [SchemaKey] that identifies the schema.\r\n * * @param matchType The [SchemaMatchType] to used for comparing schema versions.\r\n * @param context The [SchemaContext] used to facilitate schema location.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n public getSchemaSync<T extends SchemaType>(schemaKey: typeof SchemaKey, _matchType: typeof SchemaMatchType, context?: typeof SchemaContext | undefined): T | undefined {\r\n const schemaProps = this.getSchemaString(schemaKey.name);\r\n if (!schemaProps)\r\n return undefined;\r\n\r\n context = context ? context : new SchemaContext();\r\n return Schema.fromJsonSync(schemaProps, context) as T;\r\n }\r\n\r\n /** Read schema data from the iModel as JSON string\r\n * @param schemaName A string with the name of the schema to load.\r\n * @returns A string with the JSON for the schema or `undefined` if the schema is not found.\r\n * @throws [IModelError]($common) if the schema exists, but cannot be loaded.\r\n */\r\n private getSchemaString(schemaName: string): string | undefined {\r\n const val: IModelJsNative.ErrorStatusOrResult<any, any> = this._iModel.nativeDb.getSchema(schemaName);\r\n if (undefined !== val.error) {\r\n if (IModelStatus.NotFound === val.error.status) {\r\n return undefined;\r\n }\r\n throw new IModelError(val.error.status, `reading schema=${schemaName}`);\r\n }\r\n return val.result;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PromiseMemoizer.d.ts","sourceRoot":"","sources":["../../src/PromiseMemoizer.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAG1D;;GAEG;AACH,qBAAa,gBAAgB,CAAC,CAAC;aAUM,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAT/C,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IAEnB,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,SAAS,CAAkB;IAEnC,IAAW,SAAS,IAAI,OAAO,CAAkD;IACjF,IAAW,WAAW,IAAI,OAAO,CAA4B;IAC7D,IAAW,UAAU,IAAI,OAAO,CAA2B;gBACxB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CAKvD;AAED,gBAAgB;AA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AS,CAAkB;IAEnC,IAAW,SAAS,IAAI,OAAO,CAAkD;IACjF,IAAW,WAAW,IAAI,OAAO,CAA4B;IAC7D,IAAW,UAAU,IAAI,OAAO,CAA2B;gBACxB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CAKvD;AAED,gBAAgB;AAChB,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9D,gBAAgB;AAChB,oBAAY,iBAAiB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAE3D;;;GAGG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,WAAW;IACpD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4E;IAC5G,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8D;IACtF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC;;;;;;;;OAQG;gBACgB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,GAAE,MAAY,EAAE,YAAY,GAAE,MAAc;IAO1I,iCAAiC;IAC1B,OAAO,YAAa,GAAG,EAAE,KAAG,iBAAiB,CAAC,CAAC,CAyBpD;IAEF,mCAAmC;IAC5B,cAAc,YAAa,GAAG,EAAE,UAMrC;IAEF,8CAA8C;IACvC,UAAU,aAEf;IAEK,OAAO,aAKZ;CACH"}
@@ -72,6 +72,9 @@ class PromiseMemoizer {
72
72
  this.deleteMemoized = (...args) => {
73
73
  const key = this._generateKeyFn(...args);
74
74
  this._cachedPromises.delete(key);
75
+ const timer = this._timers.get(key);
76
+ if (timer)
77
+ clearTimeout(timer);
75
78
  };
76
79
  /** Clear all entries in the memoizer cache */
77
80
  this.clearCache = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"PromiseMemoizer.js","sourceRoot":"","sources":["../../src/PromiseMemoizer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,gBAAgB;IAU3B,YAAmC,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAN9C,eAAU,GAAY,KAAK,CAAC;QAC5B,cAAS,GAAY,KAAK,CAAC;QAMjC,IAAI,CAAC,OAAO;aACT,IAAI,CAAC,CAAC,GAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;aAChE,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IAPD,IAAW,SAAS,KAAc,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IACjF,IAAW,WAAW,KAAc,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7D,IAAW,UAAU,KAAc,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;CAM5D;AAfD,4CAeC;AAOD;;;GAGG;AACH,MAAa,eAAe;IAQ1B;;;;;;;;OAQG;IACH,YAAmB,SAA2B,EAAE,aAAgC,EAAE,eAAuB,GAAG,EAAE,eAAuB,KAAK;QAhBzH,oBAAe,GAAqC,IAAI,GAAG,EAA+B,CAAC;QAC3F,YAAO,GAA8B,IAAI,GAAG,EAAwB,CAAC;QAsBtF,iCAAiC;QAC1B,YAAO,GAAG,CAAC,GAAG,IAAW,EAAuB,EAAE;YACv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W,EAAE,EAAE;YACzC,MAAM,GAAG,GAAW,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC,CAAC;QAEF,8CAA8C;QACvC,eAAU,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEK,YAAO,GAAG,GAAG,EAAE;YACpB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACvC,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;QAlDA,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;CA+CF;AArED,0CAqEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { IDisposable, Logger } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\n\r\n/** Wrapper around a promise that allows synchronous queries of it's state\r\n * @internal\r\n */\r\nexport class QueryablePromise<T> {\r\n public result?: T;\r\n public error?: any;\r\n\r\n private _fulfilled: boolean = false;\r\n private _rejected: boolean = false;\r\n\r\n public get isPending(): boolean { return !this.isFulfilled && !this.isRejected; }\r\n public get isFulfilled(): boolean { return this._fulfilled; }\r\n public get isRejected(): boolean { return this._rejected; }\r\n public constructor(public readonly promise: Promise<T>) {\r\n this.promise\r\n .then((res: T) => { this.result = res; this._fulfilled = true; })\r\n .catch((err: any) => { this.error = err; this._rejected = true; });\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport type MemoizeFnType<T> = (...args: any[]) => Promise<T>;\r\n/** @internal */\r\nexport type GenerateKeyFnType = (...args: any[]) => string;\r\n\r\n/** Utility to cache and retrieve results of long running asynchronous functions.\r\n * The cache is keyed on the input arguments passed to these functions\r\n * @internal\r\n */\r\nexport class PromiseMemoizer<T> implements IDisposable {\r\n private readonly _cachedPromises: Map<string, QueryablePromise<T>> = new Map<string, QueryablePromise<T>>();\r\n private readonly _timers: Map<string, NodeJS.Timer> = new Map<string, NodeJS.Timer>();\r\n private readonly _memoizeFn: MemoizeFnType<T>;\r\n private readonly _generateKeyFn: GenerateKeyFnType;\r\n private readonly _maxCacheSize: number;\r\n private readonly _cacheTimeout: number;\r\n\r\n /**\r\n * Constructor\r\n * @param memoizeFn Function to memoize\r\n * @param generateKeyFn Function to generate the key for the memoized function\r\n * @param maxCacheSize Maximum size of the memoizer cache.\r\n * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these\r\n * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize\r\n * threshold, the entire cache is then cleared.\r\n */\r\n public constructor(memoizeFn: MemoizeFnType<T>, generateKeyFn: GenerateKeyFnType, maxCacheSize: number = 500, cacheTimeout: number = 30000) {\r\n this._memoizeFn = memoizeFn;\r\n this._generateKeyFn = generateKeyFn;\r\n this._maxCacheSize = maxCacheSize;\r\n this._cacheTimeout = cacheTimeout;\r\n }\r\n\r\n /** Call the memoized function */\r\n public memoize = (...args: any[]): QueryablePromise<T> => {\r\n const key: string = this._generateKeyFn(...args);\r\n let qp: QueryablePromise<T> | undefined = this._cachedPromises.get(key);\r\n if (qp)\r\n return qp;\r\n\r\n if (this._cachedPromises.size >= this._maxCacheSize) {\r\n if (this._maxCacheSize > 1)\r\n Logger.logError(BackendLoggerCategory.PromiseMemoizer, \"Cleared too many unresolved entries in memoizer cache\");\r\n this.clearCache();\r\n }\r\n\r\n const removeCachedPromise = (v: T) => {\r\n const cleanUp = () => {\r\n this._cachedPromises.delete(key);\r\n this._timers.delete(key);\r\n };\r\n this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));\r\n return v;\r\n };\r\n\r\n const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => { throw removeCachedPromise(e); });\r\n qp = new QueryablePromise<T>(p);\r\n this._cachedPromises.set(key, qp);\r\n return qp;\r\n };\r\n\r\n /** Delete the memoized function */\r\n public deleteMemoized = (...args: any[]) => {\r\n const key: string = this._generateKeyFn(...args);\r\n this._cachedPromises.delete(key);\r\n };\r\n\r\n /** Clear all entries in the memoizer cache */\r\n public clearCache = () => {\r\n this._cachedPromises.clear();\r\n };\r\n\r\n public dispose = () => {\r\n for (const timer of this._timers.values())\r\n clearTimeout(timer);\r\n this._timers.clear();\r\n this.clearCache();\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"PromiseMemoizer.js","sourceRoot":"","sources":["../../src/PromiseMemoizer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0D;AAC1D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,gBAAgB;IAU3B,YAAmC,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAN9C,eAAU,GAAY,KAAK,CAAC;QAC5B,cAAS,GAAY,KAAK,CAAC;QAMjC,IAAI,CAAC,OAAO;aACT,IAAI,CAAC,CAAC,GAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;aAChE,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;I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SAAS,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;CAkDF;AAxED,0CAwEC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\nimport { IDisposable, Logger } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\n\r\n/** Wrapper around a promise that allows synchronous queries of it's state\r\n * @internal\r\n */\r\nexport class QueryablePromise<T> {\r\n public result?: T;\r\n public error?: any;\r\n\r\n private _fulfilled: boolean = false;\r\n private _rejected: boolean = false;\r\n\r\n public get isPending(): boolean { return !this.isFulfilled && !this.isRejected; }\r\n public get isFulfilled(): boolean { return this._fulfilled; }\r\n public get isRejected(): boolean { return this._rejected; }\r\n public constructor(public readonly promise: Promise<T>) {\r\n this.promise\r\n .then((res: T) => { this.result = res; this._fulfilled = true; })\r\n .catch((err: any) => { this.error = err; this._rejected = true; });\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport type MemoizeFnType<T> = (...args: any[]) => Promise<T>;\r\n/** @internal */\r\nexport type GenerateKeyFnType = (...args: any[]) => string;\r\n\r\n/** Utility to cache and retrieve results of long running asynchronous functions.\r\n * The cache is keyed on the input arguments passed to these functions\r\n * @internal\r\n */\r\nexport class PromiseMemoizer<T> implements IDisposable {\r\n private readonly _cachedPromises: Map<string, QueryablePromise<T>> = new Map<string, QueryablePromise<T>>();\r\n private readonly _timers: Map<string, NodeJS.Timer> = new Map<string, NodeJS.Timer>();\r\n private readonly _memoizeFn: MemoizeFnType<T>;\r\n private readonly _generateKeyFn: GenerateKeyFnType;\r\n private readonly _maxCacheSize: number;\r\n private readonly _cacheTimeout: number;\r\n\r\n /**\r\n * Constructor\r\n * @param memoizeFn Function to memoize\r\n * @param generateKeyFn Function to generate the key for the memoized function\r\n * @param maxCacheSize Maximum size of the memoizer cache.\r\n * If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these\r\n * may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize\r\n * threshold, the entire cache is then cleared.\r\n */\r\n public constructor(memoizeFn: MemoizeFnType<T>, generateKeyFn: GenerateKeyFnType, maxCacheSize: number = 500, cacheTimeout: number = 30000) {\r\n this._memoizeFn = memoizeFn;\r\n this._generateKeyFn = generateKeyFn;\r\n this._maxCacheSize = maxCacheSize;\r\n this._cacheTimeout = cacheTimeout;\r\n }\r\n\r\n /** Call the memoized function */\r\n public memoize = (...args: any[]): QueryablePromise<T> => {\r\n const key: string = this._generateKeyFn(...args);\r\n let qp: QueryablePromise<T> | undefined = this._cachedPromises.get(key);\r\n if (qp)\r\n return qp;\r\n\r\n if (this._cachedPromises.size >= this._maxCacheSize) {\r\n if (this._maxCacheSize > 1)\r\n Logger.logError(BackendLoggerCategory.PromiseMemoizer, \"Cleared too many unresolved entries in memoizer cache\");\r\n this.clearCache();\r\n }\r\n\r\n const removeCachedPromise = (v: T) => {\r\n const cleanUp = () => {\r\n this._cachedPromises.delete(key);\r\n this._timers.delete(key);\r\n };\r\n this._timers.set(key, setTimeout(cleanUp, this._cacheTimeout));\r\n return v;\r\n };\r\n\r\n const p = this._memoizeFn(...args).then(removeCachedPromise, (e) => { throw removeCachedPromise(e); });\r\n qp = new QueryablePromise<T>(p);\r\n this._cachedPromises.set(key, qp);\r\n return qp;\r\n };\r\n\r\n /** Delete the memoized function */\r\n public deleteMemoized = (...args: any[]) => {\r\n const key: string = this._generateKeyFn(...args);\r\n this._cachedPromises.delete(key);\r\n const timer = this._timers.get(key);\r\n if (timer)\r\n clearTimeout(timer);\r\n };\r\n\r\n /** Clear all entries in the memoizer cache */\r\n public clearCache = () => {\r\n this._cachedPromises.clear();\r\n };\r\n\r\n public dispose = () => {\r\n for (const timer of this._timers.values())\r\n clearTimeout(timer);\r\n this._timers.clear();\r\n this.clearCache();\r\n };\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-backend",
3
- "version": "3.1.0-dev.27",
3
+ "version": "3.1.0-dev.32",
4
4
  "description": "iTwin.js backend components",
5
5
  "main": "lib/cjs/core-backend.js",
6
6
  "typings": "lib/cjs/core-backend",
@@ -24,22 +24,27 @@
24
24
  "url": "http://www.bentley.com"
25
25
  },
26
26
  "peerDependencies": {
27
- "@itwin/core-bentley": "^3.1.0-dev.27",
28
- "@itwin/core-common": "^3.1.0-dev.27",
29
- "@itwin/core-geometry": "^3.1.0-dev.27",
30
- "@itwin/ecschema-metadata": "^3.1.0-dev.27"
27
+ "@itwin/core-bentley": "^3.1.0-dev.32",
28
+ "@itwin/core-common": "^3.1.0-dev.32",
29
+ "@itwin/core-geometry": "^3.1.0-dev.32",
30
+ "@itwin/ecschema-metadata": "^3.1.0-dev.32"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "@itwin/ecschema-metadata": {
34
+ "optional": true
35
+ }
31
36
  },
32
37
  "//devDependencies": [
33
38
  "NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
34
39
  "NOTE: All tools used by scripts in this package must be listed as devDependencies"
35
40
  ],
36
41
  "devDependencies": {
37
- "@itwin/build-tools": "3.1.0-dev.27",
38
- "@itwin/core-bentley": "3.1.0-dev.27",
39
- "@itwin/core-common": "3.1.0-dev.27",
40
- "@itwin/core-geometry": "3.1.0-dev.27",
41
- "@itwin/ecschema-metadata": "3.1.0-dev.27",
42
- "@itwin/eslint-plugin": "3.1.0-dev.27",
42
+ "@itwin/build-tools": "3.1.0-dev.32",
43
+ "@itwin/core-bentley": "3.1.0-dev.32",
44
+ "@itwin/core-common": "3.1.0-dev.32",
45
+ "@itwin/core-geometry": "3.1.0-dev.32",
46
+ "@itwin/ecschema-metadata": "3.1.0-dev.32",
47
+ "@itwin/eslint-plugin": "3.1.0-dev.32",
43
48
  "@types/chai": "^4.1.4",
44
49
  "@types/chai-as-promised": "^7",
45
50
  "@types/fs-extra": "^4.0.7",
@@ -64,8 +69,8 @@
64
69
  },
65
70
  "dependencies": {
66
71
  "@azure/storage-blob": "^12.7.0",
67
- "@bentley/imodeljs-native": "3.1.1",
68
- "@itwin/core-telemetry": "3.1.0-dev.27",
72
+ "@bentley/imodeljs-native": "3.1.5",
73
+ "@itwin/core-telemetry": "3.1.0-dev.32",
69
74
  "form-data": "^2.3.2",
70
75
  "fs-extra": "^8.1.0",
71
76
  "json5": "^2.2.0",