@itwin/core-backend 4.4.0-dev.2 → 4.4.0-dev.20
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/CHANGELOG.md +25 -1
- package/lib/cjs/ChangesetECAdaptor.d.ts +8 -1
- package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.js +77 -19
- package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +8 -0
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/Material.d.ts +4 -1
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +13 -0
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +13 -5
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +10 -5
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/package.json +20 -20
package/lib/cjs/Material.d.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* @module Elements
|
|
3
3
|
*/
|
|
4
4
|
import { Id64String } from "@itwin/core-bentley";
|
|
5
|
-
import { Code, CodeScopeProps, NormalMapProps, RenderMaterialProps, RgbFactorProps, TextureMapProps } from "@itwin/core-common";
|
|
5
|
+
import { Code, CodeScopeProps, ElementProps, NormalMapProps, RenderMaterialProps, RgbFactorProps, TextureMapProps } from "@itwin/core-common";
|
|
6
6
|
import { DefinitionElement } from "./Element";
|
|
7
7
|
import { IModelDb } from "./IModelDb";
|
|
8
|
+
import { IModelElementCloneContext } from "./IModelElementCloneContext";
|
|
8
9
|
/** A PhysicalMaterial defines the matter that makes up physical elements.
|
|
9
10
|
* @note See [[RenderMaterialElement]] for the DefinitionElement used to define rendering characteristics.
|
|
10
11
|
* @public
|
|
@@ -67,6 +68,8 @@ export declare class RenderMaterialElement extends DefinitionElement {
|
|
|
67
68
|
* @throws [[IModelError]] if unable to insert the element.
|
|
68
69
|
*/
|
|
69
70
|
static insert(iModelDb: IModelDb, definitionModelId: Id64String, materialName: string, params: RenderMaterialElementParams): Id64String;
|
|
71
|
+
/** @internal */
|
|
72
|
+
protected static onCloned(context: IModelElementCloneContext, sourceProps: ElementProps, targetProps: ElementProps): void;
|
|
70
73
|
}
|
|
71
74
|
/** @public */
|
|
72
75
|
export declare namespace RenderMaterialElement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Material.d.ts","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Material.d.ts","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAQ,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACQ,IAAI,EAAE,cAAc,EAAoC,YAAY,EAAE,cAAc,EAAgC,mBAAmB,EAAE,cAAc,EAAE,eAAe,EACtL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE;;;GAGG;AACH,8BAAsB,gBAAiB,SAAQ,iBAAiB;IAC9D,gBAAgB;IAChB,WAA2B,SAAS,IAAI,MAAM,CAA+B;IAC7E;;;;OAIG;WACW,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAIjG;;;;;;OAMG;WACW,MAAM,CAAC,CAAC,SAAS,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,I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QACzB,wEAAwE;QACjE,OAAO,CAAC,EAAE,MAAM,CAAC;QACxB,yEAAyE;QAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;QACzB,wBAAwB;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACxB,wBAAwB;QACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QAC/B;;;WAGG;QACI,UAAU,CAAC,EAAE,eAAe,CAAC;QACpC;;;;WAIG;QACI,SAAS,CAAC,EAAE,cAAc,GAAG;YAClC;;eAEG;YACH,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QAEF,gJAAgJ;oBAC7H,WAAW,EAAE,MAAM;KAGvC;CACF;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB,CAAC,MAAM;CAChF"}
|
package/lib/cjs/Material.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.RenderMaterialElement = exports.PhysicalMaterial = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
11
12
|
const core_common_1 = require("@itwin/core-common");
|
|
12
13
|
const Element_1 = require("./Element");
|
|
13
14
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -165,6 +166,18 @@ class RenderMaterialElement extends Element_1.DefinitionElement {
|
|
|
165
166
|
const renderMaterial = this.create(iModelDb, definitionModelId, materialName, params);
|
|
166
167
|
return iModelDb.elements.insertElement(renderMaterial.toJSON());
|
|
167
168
|
}
|
|
169
|
+
/** @internal */
|
|
170
|
+
static onCloned(context, sourceProps, targetProps) {
|
|
171
|
+
super.onCloned(context, sourceProps, targetProps);
|
|
172
|
+
for (const mapName in sourceProps.jsonProperties?.materialAssets?.renderMaterial?.Map ?? {}) {
|
|
173
|
+
if (typeof mapName !== "string")
|
|
174
|
+
continue;
|
|
175
|
+
const sourceMap = sourceProps.jsonProperties.materialAssets.renderMaterial.Map[mapName];
|
|
176
|
+
if (!core_bentley_1.Id64.isValid(sourceMap.TextureId) || sourceMap.TextureId === undefined)
|
|
177
|
+
continue;
|
|
178
|
+
targetProps.jsonProperties.materialAssets.renderMaterial.Map[mapName].TextureId = context.findTargetElementId(sourceMap.TextureId ?? core_bentley_1.Id64.invalid);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
168
181
|
}
|
|
169
182
|
exports.RenderMaterialElement = RenderMaterialElement;
|
|
170
183
|
/** @public */
|
package/lib/cjs/Material.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAE4B;AAC5B,uCAA8C;AAG9C,yDAAyD;AAEzD;;;GAGG;AACH,MAAsB,gBAAiB,SAAQ,2BAAiB;IAC9D,gBAAgB;IACT,MAAM,KAAc,SAAS,KAAa,OAAO,kBAAkB,CAAC,CAAC,CAAC;IAC7E;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,MAAgB,EAAE,iBAAiC,EAAE,IAAY;QACxF,MAAM,QAAQ,GAAa,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,yBAAW,CAAC,gBAAgB,CAAC,CAAC;QACpF,OAAO,IAAI,kBAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAA6B,QAAkB,EAAE,iBAAiC,EAAE,IAAY;QAClH,MAAM,YAAY,GAA2B;YAC3C,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,KAAK,EAAE,iBAAiB;YACxB,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,CAAC;SACzD,CAAC;QACF,OAAO,QA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AE,MAAM,CAAC,YAAY;wBAClC,GAAG,EAAE,IAAI;wBACT,UAAU;qBACX;iBACF;aACF;YACD,KAAK,EAAE,iBAAiB;YACxB,SAAS,EAAE,KAAK;SACjB,CAAC;QAEF,OAAO,IAAI,qBAAqB,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE,iBAA6B,EAAE,YAAoB,EAAE,MAAmC;QAC/H,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QACtF,OAAO,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AApID,sDAoIC;AAED,cAAc;AACd,WAAiB,qBAAqB;IACpC;;;;OAIG;IACH,MAAa,MAAM;QA2CjB,gJAAgJ;QAChJ,YAAmB,WAAmB;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;KACF;IA/CY,4BAAM,SA+ClB,CAAA;AACH,CAAC,EAtDgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAsDrC","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 Elements\r\n */\r\n\r\nimport { Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n BisCodeSpec, Code, CodeScopeProps, CodeSpec, DefinitionElementProps, NormalMapProps, RenderMaterialAssetMapsProps, RenderMaterialProps, RgbFactorProps, TextureMapProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\n/** A PhysicalMaterial defines the matter that makes up physical elements.\r\n * @note See [[RenderMaterialElement]] for the DefinitionElement used to define rendering characteristics.\r\n * @public\r\n */\r\nexport abstract class PhysicalMaterial extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"PhysicalMaterial\"; }\r\n /** Create a Code for a PhysicalMaterial given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param definitionModelId The Id of the DefinitionModel that will contain the PhysicalMaterial and provide the scope for its name.\r\n * @param name The name (codeValue) of the PhysicalMaterial\r\n */\r\n public static createCode(iModel: IModelDb, definitionModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.physicalMaterial);\r\n return new Code({ spec: codeSpec.id, scope: definitionModelId, value: name });\r\n }\r\n /** Create a PhysicalMaterial\r\n * @param iModelDb The IModelDb\r\n * @param definitionModelId The Id of the DefinitionModel that will contain the PhysicalMaterial and provide the scope for its name.\r\n * @param name The name (codeValue) of the PhysicalMaterial\r\n * @returns The newly constructed PhysicalMaterial\r\n * @throws [[IModelError]] if there is a problem creating the PhysicalMaterial\r\n */\r\n public static create<T extends PhysicalMaterial>(iModelDb: IModelDb, definitionModelId: CodeScopeProps, name: string): T {\r\n const elementProps: DefinitionElementProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n };\r\n return iModelDb.elements.createElement(elementProps);\r\n }\r\n}\r\n\r\n/** Defines a rendering material.\r\n * @note See [[PhysicalMaterial]] for the DefinitionElement used to define the matter that makes up physical elements.\r\n * @public\r\n */\r\nexport class RenderMaterialElement extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"RenderMaterial\"; }\r\n\r\n /** The name of a palette that can be used to categorize multiple materials. */\r\n public paletteName: string;\r\n /** An optional description of the material. */\r\n public description?: string;\r\n /** @internal */\r\n constructor(props: RenderMaterialProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.paletteName = props.paletteName;\r\n this.description = props.description;\r\n }\r\n\r\n public override toJSON(): RenderMaterialProps {\r\n const val = super.toJSON() as RenderMaterialProps;\r\n val.paletteName = this.paletteName;\r\n val.description = this.description;\r\n return val;\r\n }\r\n /** Create a Code for a RenderMaterial given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param scopeModelId The Id of the DefinitionModel that contains the RenderMaterial and provides the scope for its name.\r\n * @param name The RenderMaterial name\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.renderMaterial);\r\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\r\n }\r\n /**\r\n * Create a RenderMaterial with given parameters.\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param materialName The name/CodeValue of the RenderMaterial\r\n * @param params Parameters object which describes how to construct the RenderMaterial\r\n * @returns The newly constructed RenderMaterial element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, materialName: string, params: RenderMaterialElementParams): RenderMaterialElement {\r\n let maps: RenderMaterialAssetMapsProps | undefined;\r\n const pbr_normal = params.normalMap?.scale;\r\n if (params.patternMap || params.normalMap) {\r\n // If both normal and pattern map are present, their texture mapping modes, angles, scales, etc are expected to match.\r\n type TexMap = Omit<TextureMapProps, \"TextureId\">;\r\n function choose<K extends keyof TexMap>(obj: TexMap, key: K): void {\r\n const pat = params.patternMap;\r\n if (pat && undefined !== pat[key])\r\n obj[key] = pat[key];\r\n else if (params.normalMap && undefined !== params.normalMap[key])\r\n obj[key] = params.normalMap[key];\r\n }\r\n\r\n const baseProps: TexMap = {};\r\n choose(baseProps, \"pattern_angle\");\r\n choose(baseProps, \"pattern_u_flip\");\r\n choose(baseProps, \"pattern_flip\");\r\n choose(baseProps, \"pattern_scale\");\r\n choose(baseProps, \"pattern_offset\");\r\n choose(baseProps, \"pattern_scalemode\");\r\n choose(baseProps, \"pattern_mapping\");\r\n choose(baseProps, \"pattern_weight\");\r\n choose(baseProps, \"pattern_useConstantLod\");\r\n choose(baseProps, \"pattern_constantlod_repetitions\");\r\n choose(baseProps, \"pattern_constantlod_offset\");\r\n choose(baseProps, \"pattern_constantlod_mindistanceclamp\");\r\n choose(baseProps, \"pattern_constantlod_maxdistanceclamp\");\r\n\r\n maps = {};\r\n if (params.patternMap)\r\n maps.Pattern = { ...params.patternMap, ...baseProps };\r\n\r\n if (params.normalMap) {\r\n maps.Normal = {\r\n ...params.normalMap,\r\n ...baseProps,\r\n };\r\n\r\n delete (maps.Normal as any).scale;\r\n }\r\n }\r\n\r\n // const map = undefined !== params.patternMap ? { Pattern: params.patternMap } : undefined;\r\n const renderMaterialProps: RenderMaterialProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, materialName),\r\n paletteName: params.paletteName,\r\n description: params.description,\r\n jsonProperties: {\r\n materialAssets: {\r\n renderMaterial: {\r\n HasBaseColor: params.color !== undefined,\r\n color: params.color,\r\n HasSpecularColor: params.specularColor !== undefined,\r\n specular_color: params.specularColor,\r\n HasFinish: params.finish !== undefined,\r\n finish: params.finish,\r\n HasTransmit: params.transmit !== undefined,\r\n transmit: params.transmit,\r\n HasDiffuse: params.diffuse !== undefined,\r\n diffuse: params.diffuse,\r\n HasSpecular: params.specular !== undefined,\r\n specular: params.specular,\r\n HasReflect: params.reflect !== undefined,\r\n reflect: params.reflect,\r\n HasReflectColor: params.reflectColor !== undefined,\r\n reflect_color: params.reflectColor,\r\n Map: maps,\r\n pbr_normal,\r\n },\r\n },\r\n },\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n\r\n return new RenderMaterialElement(renderMaterialProps, iModelDb);\r\n }\r\n\r\n /**\r\n * Insert a new RenderMaterial into a model.\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new Texture into this DefinitionModel\r\n * @param materialName The name/CodeValue of the RenderMaterial\r\n * @param params Parameters object which describes how to construct the RenderMaterial\r\n * @returns The Id of the newly inserted RenderMaterial element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, materialName: string, params: RenderMaterialElementParams): Id64String {\r\n const renderMaterial = this.create(iModelDb, definitionModelId, materialName, params);\r\n return iModelDb.elements.insertElement(renderMaterial.toJSON());\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace RenderMaterialElement { // eslint-disable-line no-redeclare\r\n /** Parameters used to construct a [[RenderMaterial]].\r\n * The persistent JSON representation - [RenderMaterialAssetProps]($common) - is quite verbose and unwieldy. This representation simplifies it somewhat.\r\n * @see [[RenderMaterialElement.create]] and [[RenderMaterialElement.insert]] to create a [[RenderMaterial]] from parameters of this type.\r\n * @deprecated in 3.6 because it is not useful to use a `class` - just use [[RenderMaterialElementParams]] directly instead.\r\n */\r\n export class Params {\r\n /** A required palette name that categorizes this RenderMaterial */\r\n public paletteName: string;\r\n /** An optional description of this RenderMaterial */\r\n public description?: string;\r\n /** If defined, the color to use for surface fill or diffuse illumination, overriding the surface's own color. */\r\n public color?: RgbFactorProps;\r\n /** The color to use for specular illumination. Default: black. */\r\n public specularColor?: RgbFactorProps;\r\n /** The specular exponent describing the surface's shininess, in the range 0 through 128.\r\n * Default: 0.\r\n */\r\n public finish?: number;\r\n /** A transparency to be applied to the surface, ranging from 0 (fully opaque) to 1 (fully transparent).\r\n * The surface's own transparency will be multiplied by `(1 - transmit)`. permitting the material to increase but not decrease the surface transparency.\r\n * Default: 13.5.\r\n */\r\n public transmit?: number;\r\n /** The surface's diffuse reflectivity from 0.0 to 1.0. Default: 0.6. */\r\n public diffuse?: number;\r\n /** The surface's specular reflectivity from 0.0 to 1.0. Default: 0.0. */\r\n public specular?: number;\r\n /** Currently unused. */\r\n public reflect?: number;\r\n /** Currently unused. */\r\n public reflectColor?: number[];\r\n /** Specifies a texture image to map onto the surface, replacing or mixing with the surface's own color and transparency.\r\n * @note With the exception of `TextureId`, the [TextureMapProps]($common) of [[patternMap]] and [[normalMap]] are expected to be identical. If a property is defined in both\r\n * [[patternMap]]] and [[normalMap]], the value in [[patternMap]] takes precedence.\r\n */\r\n public patternMap?: TextureMapProps;\r\n /** Specifies a [normal map](https://en.wikipedia.org/wiki/Normal_mapping) to apply to the surface to simulate more surface detail than is present in the\r\n * surface's geometry.\r\n * @note With the exception of `TextureId`, the [TextureMapProps]($common) of [[patternMap]] and [[normalMap]] are expected to be identical. If a property is defined in both\r\n * [[patternMap]]] and [[normalMap]], the value in [[patternMap]] takes precedence.\r\n */\r\n public normalMap?: NormalMapProps & {\r\n /** A factor by which to multiply the components of the normal vectors read from the texture.\r\n * Default: 1.\r\n */\r\n scale?: number;\r\n };\r\n\r\n /** Construct a new RenderMaterial.Params object with the specified paletteName. Alter the public members on that object to specify settings. */\r\n public constructor(paletteName: string) {\r\n this.paletteName = paletteName;\r\n }\r\n }\r\n}\r\n\r\n/** Parameters used to create a [[RenderMaterial]] element.\r\n * The persistent JSON representation - [RenderMaterialAssetProps]($common) - is quite verbose and unwieldy. This representation simplifies it somewhat.\r\n * @see [[RenderMaterialElement.create]] and [[RenderMaterialElement.insert]] to create a [[RenderMaterial]] from parameters of this type.\r\n * @public\r\n */\r\nexport interface RenderMaterialElementParams extends RenderMaterialElement.Params { // eslint-disable-line deprecation/deprecation, @typescript-eslint/no-empty-interface\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAuD;AACvD,oDAE4B;AAC5B,uCAA8C;AAI9C,yDAAyD;AAEzD;;;GAGG;AACH,MAAsB,gBAAiB,SAAQ,2BAAiB;IAC9D,gBAAgB;IACT,MAAM,KAAc,SAAS,KAA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zH,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QAClD,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,EAAE;YAC3F,IAAI,OAAO,OAAO,KAAK,QAAQ;gBAC7B,SAAS;YACX,MAAM,SAAS,GAAG,WAAW,CAAC,cAAc,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACxF,IAAI,CAAC,mBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS;gBACzE,SAAS;YACX,WAAW,CAAC,cAAc,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,SAAS,IAAI,mBAAI,CAAC,OAAO,CAAC,CAAC;SACpJ;IACH,CAAC;CACF;AAjJD,sDAiJC;AAED,cAAc;AACd,WAAiB,qBAAqB;IACpC;;;;OAIG;IACH,MAAa,MAAM;QA2CjB,gJAAgJ;QAChJ,YAAmB,WAAmB;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;KACF;IA/CY,4BAAM,SA+ClB,CAAA;AACH,CAAC,EAtDgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAsDrC","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 Elements\r\n */\r\n\r\nimport { Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n BisCodeSpec, Code, CodeScopeProps, CodeSpec, DefinitionElementProps, ElementProps, NormalMapProps, RenderMaterialAssetMapsProps, RenderMaterialProps, RgbFactorProps, TextureMapProps,\r\n} from \"@itwin/core-common\";\r\nimport { DefinitionElement } from \"./Element\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { IModelElementCloneContext } from \"./IModelElementCloneContext\";\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\n\r\n/** A PhysicalMaterial defines the matter that makes up physical elements.\r\n * @note See [[RenderMaterialElement]] for the DefinitionElement used to define rendering characteristics.\r\n * @public\r\n */\r\nexport abstract class PhysicalMaterial extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"PhysicalMaterial\"; }\r\n /** Create a Code for a PhysicalMaterial given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param definitionModelId The Id of the DefinitionModel that will contain the PhysicalMaterial and provide the scope for its name.\r\n * @param name The name (codeValue) of the PhysicalMaterial\r\n */\r\n public static createCode(iModel: IModelDb, definitionModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.physicalMaterial);\r\n return new Code({ spec: codeSpec.id, scope: definitionModelId, value: name });\r\n }\r\n /** Create a PhysicalMaterial\r\n * @param iModelDb The IModelDb\r\n * @param definitionModelId The Id of the DefinitionModel that will contain the PhysicalMaterial and provide the scope for its name.\r\n * @param name The name (codeValue) of the PhysicalMaterial\r\n * @returns The newly constructed PhysicalMaterial\r\n * @throws [[IModelError]] if there is a problem creating the PhysicalMaterial\r\n */\r\n public static create<T extends PhysicalMaterial>(iModelDb: IModelDb, definitionModelId: CodeScopeProps, name: string): T {\r\n const elementProps: DefinitionElementProps = {\r\n classFullName: this.classFullName,\r\n model: definitionModelId,\r\n code: this.createCode(iModelDb, definitionModelId, name),\r\n };\r\n return iModelDb.elements.createElement(elementProps);\r\n }\r\n}\r\n\r\n/** Defines a rendering material.\r\n * @note See [[PhysicalMaterial]] for the DefinitionElement used to define the matter that makes up physical elements.\r\n * @public\r\n */\r\nexport class RenderMaterialElement extends DefinitionElement {\r\n /** @internal */\r\n public static override get className(): string { return \"RenderMaterial\"; }\r\n\r\n /** The name of a palette that can be used to categorize multiple materials. */\r\n public paletteName: string;\r\n /** An optional description of the material. */\r\n public description?: string;\r\n /** @internal */\r\n constructor(props: RenderMaterialProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.paletteName = props.paletteName;\r\n this.description = props.description;\r\n }\r\n\r\n public override toJSON(): RenderMaterialProps {\r\n const val = super.toJSON() as RenderMaterialProps;\r\n val.paletteName = this.paletteName;\r\n val.description = this.description;\r\n return val;\r\n }\r\n /** Create a Code for a RenderMaterial given a name that is meant to be unique within the scope of the specified DefinitionModel.\r\n * @param iModel The IModelDb\r\n * @param scopeModelId The Id of the DefinitionModel that contains the RenderMaterial and provides the scope for its name.\r\n * @param name The RenderMaterial name\r\n */\r\n public static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, name: string): Code {\r\n const codeSpec: CodeSpec = iModel.codeSpecs.getByName(BisCodeSpec.renderMaterial);\r\n return 0 === name.length ? Code.createEmpty() : new Code({ spec: codeSpec.id, scope: scopeModelId, value: name });\r\n }\r\n /**\r\n * Create a RenderMaterial with given parameters.\r\n * @param iModelDb The iModel\r\n * @param definitionModelId The [[DefinitionModel]]\r\n * @param materialName The name/CodeValue of the RenderMaterial\r\n * @param params Parameters object which describes how to construct the RenderMaterial\r\n * @returns The newly constructed RenderMaterial element.\r\n * @throws [[IModelError]] if unable to create the element.\r\n */\r\n public static create(iModelDb: IModelDb, definitionModelId: Id64String, materialName: string, params: RenderMaterialElementParams): RenderMaterialElement {\r\n let maps: RenderMaterialAssetMapsProps | undefined;\r\n const pbr_normal = params.normalMap?.scale;\r\n if (params.patternMap || params.normalMap) {\r\n // If both normal and pattern map are present, their texture mapping modes, angles, scales, etc are expected to match.\r\n type TexMap = Omit<TextureMapProps, \"TextureId\">;\r\n function choose<K extends keyof TexMap>(obj: TexMap, key: K): void {\r\n const pat = params.patternMap;\r\n if (pat && undefined !== pat[key])\r\n obj[key] = pat[key];\r\n else if (params.normalMap && undefined !== params.normalMap[key])\r\n obj[key] = params.normalMap[key];\r\n }\r\n\r\n const baseProps: TexMap = {};\r\n choose(baseProps, \"pattern_angle\");\r\n choose(baseProps, \"pattern_u_flip\");\r\n choose(baseProps, \"pattern_flip\");\r\n choose(baseProps, \"pattern_scale\");\r\n choose(baseProps, \"pattern_offset\");\r\n choose(baseProps, \"pattern_scalemode\");\r\n choose(baseProps, \"pattern_mapping\");\r\n choose(baseProps, \"pattern_weight\");\r\n choose(baseProps, \"pattern_useConstantLod\");\r\n choose(baseProps, \"pattern_constantlod_repetitions\");\r\n choose(baseProps, \"pattern_constantlod_offset\");\r\n choose(baseProps, \"pattern_constantlod_mindistanceclamp\");\r\n choose(baseProps, \"pattern_constantlod_maxdistanceclamp\");\r\n\r\n maps = {};\r\n if (params.patternMap)\r\n maps.Pattern = { ...params.patternMap, ...baseProps };\r\n\r\n if (params.normalMap) {\r\n maps.Normal = {\r\n ...params.normalMap,\r\n ...baseProps,\r\n };\r\n\r\n delete (maps.Normal as any).scale;\r\n }\r\n }\r\n\r\n // const map = undefined !== params.patternMap ? { Pattern: params.patternMap } : undefined;\r\n const renderMaterialProps: RenderMaterialProps = {\r\n classFullName: this.classFullName,\r\n code: this.createCode(iModelDb, definitionModelId, materialName),\r\n paletteName: params.paletteName,\r\n description: params.description,\r\n jsonProperties: {\r\n materialAssets: {\r\n renderMaterial: {\r\n HasBaseColor: params.color !== undefined,\r\n color: params.color,\r\n HasSpecularColor: params.specularColor !== undefined,\r\n specular_color: params.specularColor,\r\n HasFinish: params.finish !== undefined,\r\n finish: params.finish,\r\n HasTransmit: params.transmit !== undefined,\r\n transmit: params.transmit,\r\n HasDiffuse: params.diffuse !== undefined,\r\n diffuse: params.diffuse,\r\n HasSpecular: params.specular !== undefined,\r\n specular: params.specular,\r\n HasReflect: params.reflect !== undefined,\r\n reflect: params.reflect,\r\n HasReflectColor: params.reflectColor !== undefined,\r\n reflect_color: params.reflectColor,\r\n Map: maps,\r\n pbr_normal,\r\n },\r\n },\r\n },\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n\r\n return new RenderMaterialElement(renderMaterialProps, iModelDb);\r\n }\r\n\r\n /**\r\n * Insert a new RenderMaterial into a model.\r\n * @param iModelDb Insert into this iModel\r\n * @param definitionModelId Insert the new Texture into this DefinitionModel\r\n * @param materialName The name/CodeValue of the RenderMaterial\r\n * @param params Parameters object which describes how to construct the RenderMaterial\r\n * @returns The Id of the newly inserted RenderMaterial element.\r\n * @throws [[IModelError]] if unable to insert the element.\r\n */\r\n public static insert(iModelDb: IModelDb, definitionModelId: Id64String, materialName: string, params: RenderMaterialElementParams): Id64String {\r\n const renderMaterial = this.create(iModelDb, definitionModelId, materialName, params);\r\n return iModelDb.elements.insertElement(renderMaterial.toJSON());\r\n }\r\n\r\n /** @internal */\r\n protected static override onCloned(context: IModelElementCloneContext, sourceProps: ElementProps, targetProps: ElementProps) {\r\n super.onCloned(context, sourceProps, targetProps);\r\n for (const mapName in sourceProps.jsonProperties?.materialAssets?.renderMaterial?.Map ?? {}) {\r\n if (typeof mapName !== \"string\")\r\n continue;\r\n const sourceMap = sourceProps.jsonProperties.materialAssets.renderMaterial.Map[mapName];\r\n if (!Id64.isValid(sourceMap.TextureId) || sourceMap.TextureId === undefined)\r\n continue;\r\n targetProps.jsonProperties.materialAssets.renderMaterial.Map[mapName].TextureId = context.findTargetElementId(sourceMap.TextureId ?? Id64.invalid);\r\n }\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace RenderMaterialElement { // eslint-disable-line no-redeclare\r\n /** Parameters used to construct a [[RenderMaterial]].\r\n * The persistent JSON representation - [RenderMaterialAssetProps]($common) - is quite verbose and unwieldy. This representation simplifies it somewhat.\r\n * @see [[RenderMaterialElement.create]] and [[RenderMaterialElement.insert]] to create a [[RenderMaterial]] from parameters of this type.\r\n * @deprecated in 3.6 because it is not useful to use a `class` - just use [[RenderMaterialElementParams]] directly instead.\r\n */\r\n export class Params {\r\n /** A required palette name that categorizes this RenderMaterial */\r\n public paletteName: string;\r\n /** An optional description of this RenderMaterial */\r\n public description?: string;\r\n /** If defined, the color to use for surface fill or diffuse illumination, overriding the surface's own color. */\r\n public color?: RgbFactorProps;\r\n /** The color to use for specular illumination. Default: black. */\r\n public specularColor?: RgbFactorProps;\r\n /** The specular exponent describing the surface's shininess, in the range 0 through 128.\r\n * Default: 0.\r\n */\r\n public finish?: number;\r\n /** A transparency to be applied to the surface, ranging from 0 (fully opaque) to 1 (fully transparent).\r\n * The surface's own transparency will be multiplied by `(1 - transmit)`. permitting the material to increase but not decrease the surface transparency.\r\n * Default: 13.5.\r\n */\r\n public transmit?: number;\r\n /** The surface's diffuse reflectivity from 0.0 to 1.0. Default: 0.6. */\r\n public diffuse?: number;\r\n /** The surface's specular reflectivity from 0.0 to 1.0. Default: 0.0. */\r\n public specular?: number;\r\n /** Currently unused. */\r\n public reflect?: number;\r\n /** Currently unused. */\r\n public reflectColor?: number[];\r\n /** Specifies a texture image to map onto the surface, replacing or mixing with the surface's own color and transparency.\r\n * @note With the exception of `TextureId`, the [TextureMapProps]($common) of [[patternMap]] and [[normalMap]] are expected to be identical. If a property is defined in both\r\n * [[patternMap]]] and [[normalMap]], the value in [[patternMap]] takes precedence.\r\n */\r\n public patternMap?: TextureMapProps;\r\n /** Specifies a [normal map](https://en.wikipedia.org/wiki/Normal_mapping) to apply to the surface to simulate more surface detail than is present in the\r\n * surface's geometry.\r\n * @note With the exception of `TextureId`, the [TextureMapProps]($common) of [[patternMap]] and [[normalMap]] are expected to be identical. If a property is defined in both\r\n * [[patternMap]]] and [[normalMap]], the value in [[patternMap]] takes precedence.\r\n */\r\n public normalMap?: NormalMapProps & {\r\n /** A factor by which to multiply the components of the normal vectors read from the texture.\r\n * Default: 1.\r\n */\r\n scale?: number;\r\n };\r\n\r\n /** Construct a new RenderMaterial.Params object with the specified paletteName. Alter the public members on that object to specify settings. */\r\n public constructor(paletteName: string) {\r\n this.paletteName = paletteName;\r\n }\r\n }\r\n}\r\n\r\n/** Parameters used to create a [[RenderMaterial]] element.\r\n * The persistent JSON representation - [RenderMaterialAssetProps]($common) - is quite verbose and unwieldy. This representation simplifies it somewhat.\r\n * @see [[RenderMaterialElement.create]] and [[RenderMaterialElement.insert]] to create a [[RenderMaterial]] from parameters of this type.\r\n * @public\r\n */\r\nexport interface RenderMaterialElementParams extends RenderMaterialElement.Params { // eslint-disable-line deprecation/deprecation, @typescript-eslint/no-empty-interface\r\n}\r\n"]}
|
|
@@ -19,7 +19,7 @@ export interface DownloadAndOpenArgs {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class RpcBriefcaseUtility {
|
|
21
21
|
private static downloadAndOpen;
|
|
22
|
-
private static
|
|
22
|
+
private static _briefcasePromises;
|
|
23
23
|
private static openBriefcase;
|
|
24
24
|
/** find a previously opened iModel for RPC.
|
|
25
25
|
* @param accessToken necessary (only) for V2 checkpoints to refresh access token in daemon if it has expired. We use the accessToken of the current RPC request
|
|
@@ -27,11 +27,19 @@ export declare class RpcBriefcaseUtility {
|
|
|
27
27
|
* @param the IModelRpcProps to locate the opened iModel.
|
|
28
28
|
*/
|
|
29
29
|
static findOpenIModel(accessToken: AccessToken, iModel: IModelRpcProps): Promise<IModelDb>;
|
|
30
|
+
static open(args: DownloadAndOpenArgs & {
|
|
31
|
+
syncMode: SyncMode.FixedVersion;
|
|
32
|
+
}): Promise<IModelDb>;
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
* a RpcPendingResponse exception is thrown
|
|
34
|
+
* @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends
|
|
33
35
|
*/
|
|
34
|
-
static open(args: DownloadAndOpenArgs
|
|
35
|
-
|
|
36
|
+
static open(args: DownloadAndOpenArgs & {
|
|
37
|
+
syncMode: Exclude<SyncMode, "FixedVersion">;
|
|
38
|
+
}): Promise<IModelDb>;
|
|
39
|
+
static openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode.FixedVersion, timeout?: number): Promise<IModelConnectionProps>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends
|
|
42
|
+
*/
|
|
43
|
+
static openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: Exclude<SyncMode, "FixedVersion">, timeout?: number): Promise<IModelConnectionProps>;
|
|
36
44
|
}
|
|
37
45
|
//# sourceMappingURL=RpcBriefcaseUtility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcBriefcaseUtility.d.ts","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAA0D,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EACL,cAAc,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,cAAc,EAAiB,WAAW,EAAsB,QAAQ,EACpI,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAe,QAAQ,EAAc,MAAM,aAAa,CAAC;AAMhE,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC,EAAE,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AACD;;;GAGG;AACH,qBAAa,mBAAmB;mBAET,eAAe;IA2DpC,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"RpcBriefcaseUtility.d.ts","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAA0D,M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OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAQ1L"}
|
|
@@ -78,14 +78,17 @@ class RpcBriefcaseUtility {
|
|
|
78
78
|
return IModelDb_1.BriefcaseDb.open(props);
|
|
79
79
|
}
|
|
80
80
|
static async openBriefcase(args) {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const key = `${args.tokenProps.iModelId}:${args.tokenProps.changeset?.id}:${args.tokenProps.changeset?.index}:${args.syncMode}`;
|
|
82
|
+
const cachedPromise = this._briefcasePromises.get(key);
|
|
83
|
+
if (cachedPromise)
|
|
84
|
+
return cachedPromise;
|
|
83
85
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
const briefcasePromise = this.downloadAndOpen(args); // save the fact that we're working on downloading so if we timeout, we'll reuse this request.
|
|
87
|
+
this._briefcasePromises.set(key, briefcasePromise);
|
|
88
|
+
return await briefcasePromise;
|
|
86
89
|
}
|
|
87
90
|
finally {
|
|
88
|
-
this.
|
|
91
|
+
this._briefcasePromises.delete(key); // the download and open is now done
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
/** find a previously opened iModel for RPC.
|
|
@@ -158,8 +161,10 @@ class RpcBriefcaseUtility {
|
|
|
158
161
|
static async openWithTimeout(activity, tokenProps, syncMode, timeout = 1000) {
|
|
159
162
|
if (tokenProps.iModelId)
|
|
160
163
|
await IModelHost_1.IModelHost.tileStorage?.initialize(tokenProps.iModelId);
|
|
164
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
161
165
|
return (await this.open({ activity, tokenProps, syncMode, timeout })).toJSON();
|
|
162
166
|
}
|
|
163
167
|
}
|
|
168
|
+
RpcBriefcaseUtility._briefcasePromises = new Map();
|
|
164
169
|
exports.RpcBriefcaseUtility = RpcBriefcaseUtility;
|
|
165
170
|
//# sourceMappingURL=RpcBriefcaseUtility.js.map
|
|
@@ -1 +1 @@
|
|
|
1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AAI;QACnI,IAAI,UAAU,CAAC,QAAQ;YACrB,MAAM,uBAAU,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAChE,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjF,CAAC;CAEF;AA9JD,kDA8JC","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 RpcInterface\r\n */\r\n\r\nimport { AccessToken, assert, BeDuration, BentleyError, IModelStatus, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseProps, IModelConnectionProps, IModelRpcOpenProps, IModelRpcProps, IModelVersion, RpcActivity, RpcPendingResponse, SyncMode,\r\n} from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"../BackendLoggerCategory\";\r\nimport { BriefcaseManager, RequestNewBriefcaseArg } from \"../BriefcaseManager\";\r\nimport { CheckpointManager, CheckpointProps, V1CheckpointManager } from \"../CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, SnapshotDb } from \"../IModelDb\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.IModelDb;\r\n\r\n/** @internal */\r\nexport interface DownloadAndOpenArgs {\r\n activity: RpcActivity; // eslint-disable-line deprecation/deprecation\r\n tokenProps: IModelRpcOpenProps;\r\n syncMode: SyncMode;\r\n fileNameResolvers?: ((arg: BriefcaseProps) => string)[];\r\n timeout?: number;\r\n forceDownload?: boolean;\r\n}\r\n/**\r\n * Utility to open the iModel for RPC interfaces\r\n * @internal\r\n */\r\nexport class RpcBriefcaseUtility {\r\n\r\n private static async downloadAndOpen(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const { activity, tokenProps } = args;\r\n const accessToken = activity.accessToken;\r\n assert(undefined !== tokenProps.iModelId);\r\n\r\n const iModelId = tokenProps.iModelId;\r\n let myBriefcaseIds: number[];\r\n if (args.syncMode === SyncMode.PullOnly) {\r\n myBriefcaseIds = [0]; // PullOnly means briefcaseId 0\r\n } else {\r\n // check with iModelHub and see if we already have acquired any briefcaseIds\r\n myBriefcaseIds = await IModelHost.hubAccess.getMyBriefcaseIds({ accessToken, iModelId });\r\n }\r\n\r\n const resolvers = args.fileNameResolvers ?? [(arg) => BriefcaseManager.getFileName(arg)];\r\n\r\n // see if we can open any of the briefcaseIds we already acquired from iModelHub\r\n if (resolvers) {\r\n for (const resolver of resolvers) {\r\n for (const briefcaseId of myBriefcaseIds) {\r\n const fileName = resolver({ briefcaseId, iModelId });\r\n if (IModelJsFs.existsSync(fileName)) {\r\n const briefcaseDb = BriefcaseDb.findByFilename(fileName);\r\n if (briefcaseDb !== undefined)\r\n return briefcaseDb as BriefcaseDb;\r\n try {\r\n if (args.forceDownload)\r\n throw new Error(); // causes delete below\r\n const db = await BriefcaseDb.open({ fileName });\r\n if (db.changeset.id !== tokenProps.changeset?.id) {\r\n assert(undefined !== tokenProps.changeset);\r\n const toIndex = tokenProps.changeset?.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version: IModelVersion.asOfChangeSet(tokenProps.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n }\r\n return db;\r\n } catch (error: any) {\r\n if (!(error.errorNumber === IModelStatus.AlreadyOpen))\r\n // somehow we have this briefcaseId and the file exists, but we can't open it. Delete it.\r\n await BriefcaseManager.deleteBriefcaseFiles(fileName, accessToken);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // no local briefcase available. Download one and open it.\r\n assert(undefined !== tokenProps.iTwinId);\r\n const request: RequestNewBriefcaseArg = {\r\n accessToken,\r\n iTwinId: tokenProps.iTwinId,\r\n iModelId,\r\n briefcaseId: args.syncMode === SyncMode.PullOnly ? 0 : undefined, // if briefcaseId is undefined, we'll acquire a new one.\r\n };\r\n\r\n const props = await BriefcaseManager.downloadBriefcase(request);\r\n return BriefcaseDb.open(props);\r\n }\r\n\r\n private static _briefcasePromise: Promise<BriefcaseDb> | undefined;\r\n private static async openBriefcase(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n if (this._briefcasePromise)\r\n return this._briefcasePromise;\r\n\r\n try {\r\n this._briefcasePromise = this.downloadAndOpen(args); // save the fact that we're working on downloading so if we timeout, we'll reuse this request.\r\n return await this._briefcasePromise;\r\n } finally {\r\n this._briefcasePromise = undefined; // the download and open is now done\r\n }\r\n }\r\n\r\n /** find a previously opened iModel for RPC.\r\n * @param accessToken necessary (only) for V2 checkpoints to refresh access token in daemon if it has expired. We use the accessToken of the current RPC request\r\n * to refresh the daemon, even though it will be used for all authorized users.\r\n * @param the IModelRpcProps to locate the opened iModel.\r\n */\r\n public static async findOpenIModel(accessToken: AccessToken, iModel: IModelRpcProps) {\r\n const iModelDb = IModelDb.findByKey(iModel.key);\r\n\r\n // call refreshContainer, just in case this is a V2 checkpoint whose sasToken is about to expire, or its default transaction is about to be restarted.\r\n await iModelDb.refreshContainer(accessToken);\r\n return iModelDb;\r\n }\r\n\r\n /**\r\n * Download and open a checkpoint or briefcase, ensuring the operation completes within a default timeout. If the time to open exceeds the timeout period,\r\n * a RpcPendingResponse exception is thrown\r\n */\r\n public static async open(args: DownloadAndOpenArgs): Promise<IModelDb> {\r\n const { activity, tokenProps, syncMode } = args;\r\n Logger.logTrace(loggerCategory, \"RpcBriefcaseUtility.open\", () => ({ ...tokenProps }));\r\n\r\n const timeout = args.timeout ?? 1000;\r\n if (syncMode === SyncMode.PullOnly || syncMode === SyncMode.PullAndPush) {\r\n const briefcaseDb = await BeDuration.race(timeout, this.openBriefcase(args));\r\n\r\n if (briefcaseDb === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open briefcase - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n // note: usage is logged in the function BriefcaseManager.downloadNewBriefcaseAndOpen\r\n return briefcaseDb;\r\n }\r\n\r\n assert(undefined !== tokenProps.iModelId);\r\n assert(undefined !== tokenProps.iTwinId);\r\n assert(undefined !== tokenProps.changeset);\r\n\r\n const checkpoint: CheckpointProps = {\r\n iModelId: tokenProps.iModelId,\r\n iTwinId: tokenProps.iTwinId,\r\n changeset: tokenProps.changeset,\r\n accessToken: activity.accessToken,\r\n };\r\n\r\n // opening a checkpoint, readonly.\r\n let db: SnapshotDb | void;\r\n // first check if it's already open\r\n db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(checkpoint));\r\n if (db) {\r\n Logger.logTrace(loggerCategory, \"Checkpoint was already open\", () => ({ ...tokenProps }));\r\n return db;\r\n }\r\n\r\n try {\r\n // now try V2 checkpoint\r\n db = await SnapshotDb.openCheckpointV2(checkpoint);\r\n Logger.logTrace(loggerCategory, \"using V2 checkpoint briefcase\", () => ({ ...tokenProps }));\r\n } catch (e) {\r\n Logger.logTrace(loggerCategory, \"unable to open V2 checkpoint - falling back to V1 checkpoint\", () => ({ error: BentleyError.getErrorProps(e), ...tokenProps }));\r\n\r\n // this isn't a v2 checkpoint. Set up a race between the specified timeout period and the open. Throw an RpcPendingResponse exception if the timeout happens first.\r\n const request = {\r\n checkpoint,\r\n localFile: V1CheckpointManager.getFileName(checkpoint),\r\n aliasFiles: [],\r\n };\r\n db = await BeDuration.race(timeout, V1CheckpointManager.getCheckpointDb(request));\r\n\r\n if (db === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open V1 checkpoint - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n Logger.logTrace(loggerCategory, \"Opened V1 checkpoint\", () => ({ ...tokenProps }));\r\n }\r\n\r\n return db;\r\n }\r\n\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode, timeout: number = 1000): Promise<IModelConnectionProps> { // eslint-disable-line deprecation/deprecation\r\n if (tokenProps.iModelId)\r\n await IModelHost.tileStorage?.initialize(tokenProps.iModelId);\r\n return (await this.open({ activity, tokenProps, syncMode, timeout })).toJSON();\r\n }\r\n\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"RpcBriefcaseUtility.js","sourceRoot":"","sources":["../../../src/rpc-impl/RpcBriefcaseUtility.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0G;AAC1G,oDAE4B;AAC5B,oEAAiE;AACjE,0DAA+E;AAC/E,4DAA+F;AAC/F,0CAAgE;AAChE,8CAA2C;AAC3C,8CAA2C;AAE3C,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAW9D;;;GAGG;AACH,MAAa,mBAAmB;IAEtB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAyB;QAC5D,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QACtC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;QACzC,IAAA,qBAAM,EAAC,SAAS,KAAK,UAAU,CAAC,QAAQ,CAAC,CAAC;QAE1C,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC;QACrC,IAAI,cAAwB,CAAC;QAC7B,IAAI,IAAI,CAAC,QAAQ,KAAK,sBAAQ,CAAC,QAAQ,EAAE;YACvC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,+BAA+B;SACtD;aAAM;YACL,4EAA4E;YAC5E,cAAc,GAAG,MAAM,uBAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;SAC1F;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,i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AAE;aACf,CAAC;YACF,EAAE,GAAG,MAAM,yBAAU,CAAC,IAAI,CAAC,OAAO,EAAE,uCAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;YAElF,IAAI,EAAE,KAAK,SAAS,EAAE;gBACpB,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,8BAA8B,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;gBAC3F,MAAM,IAAI,gCAAkB,EAAE,CAAC,CAAC,8CAA8C;aAC/E;YACD,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;SACpF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAQM,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAqB,EAAE,UAA8B,EAAE,QAAkB,EAAE,UAAkB,IAAI;QACnI,IAAI,UAAU,CAAC,QAAQ;YACrB,MAAM,uBAAU,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAChE,mDAAmD;QACnD,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjF,CAAC;;AA/Gc,sCAAkB,GAAsC,IAAI,GAAG,EAAE,CAAC;AA7DtE,kDAAmB","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 RpcInterface\r\n */\r\n\r\nimport { AccessToken, assert, BeDuration, BentleyError, IModelStatus, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseProps, IModelConnectionProps, IModelRpcOpenProps, IModelRpcProps, IModelVersion, RpcActivity, RpcPendingResponse, SyncMode,\r\n} from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"../BackendLoggerCategory\";\r\nimport { BriefcaseManager, RequestNewBriefcaseArg } from \"../BriefcaseManager\";\r\nimport { CheckpointManager, CheckpointProps, V1CheckpointManager } from \"../CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, SnapshotDb } from \"../IModelDb\";\r\nimport { IModelHost } from \"../IModelHost\";\r\nimport { IModelJsFs } from \"../IModelJsFs\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.IModelDb;\r\n\r\n/** @internal */\r\nexport interface DownloadAndOpenArgs {\r\n activity: RpcActivity; // eslint-disable-line deprecation/deprecation\r\n tokenProps: IModelRpcOpenProps;\r\n syncMode: SyncMode;\r\n fileNameResolvers?: ((arg: BriefcaseProps) => string)[];\r\n timeout?: number;\r\n forceDownload?: boolean;\r\n}\r\n/**\r\n * Utility to open the iModel for RPC interfaces\r\n * @internal\r\n */\r\nexport class RpcBriefcaseUtility {\r\n\r\n private static async downloadAndOpen(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const { activity, tokenProps } = args;\r\n const accessToken = activity.accessToken;\r\n assert(undefined !== tokenProps.iModelId);\r\n\r\n const iModelId = tokenProps.iModelId;\r\n let myBriefcaseIds: number[];\r\n if (args.syncMode === SyncMode.PullOnly) {\r\n myBriefcaseIds = [0]; // PullOnly means briefcaseId 0\r\n } else {\r\n // check with iModelHub and see if we already have acquired any briefcaseIds\r\n myBriefcaseIds = await IModelHost.hubAccess.getMyBriefcaseIds({ accessToken, iModelId });\r\n }\r\n\r\n const resolvers = args.fileNameResolvers ?? [(arg) => BriefcaseManager.getFileName(arg)];\r\n\r\n // see if we can open any of the briefcaseIds we already acquired from iModelHub\r\n if (resolvers) {\r\n for (const resolver of resolvers) {\r\n for (const briefcaseId of myBriefcaseIds) {\r\n const fileName = resolver({ briefcaseId, iModelId });\r\n if (IModelJsFs.existsSync(fileName)) {\r\n const briefcaseDb = BriefcaseDb.findByFilename(fileName);\r\n if (briefcaseDb !== undefined)\r\n return briefcaseDb as BriefcaseDb;\r\n try {\r\n if (args.forceDownload)\r\n throw new Error(); // causes delete below\r\n const db = await BriefcaseDb.open({ fileName });\r\n if (db.changeset.id !== tokenProps.changeset?.id) {\r\n assert(undefined !== tokenProps.changeset);\r\n const toIndex = tokenProps.changeset?.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId, version: IModelVersion.asOfChangeSet(tokenProps.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n }\r\n return db;\r\n } catch (error: any) {\r\n if (!(error.errorNumber === IModelStatus.AlreadyOpen))\r\n // somehow we have this briefcaseId and the file exists, but we can't open it. Delete it.\r\n await BriefcaseManager.deleteBriefcaseFiles(fileName, accessToken);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // no local briefcase available. Download one and open it.\r\n assert(undefined !== tokenProps.iTwinId);\r\n const request: RequestNewBriefcaseArg = {\r\n accessToken,\r\n iTwinId: tokenProps.iTwinId,\r\n iModelId,\r\n briefcaseId: args.syncMode === SyncMode.PullOnly ? 0 : undefined, // if briefcaseId is undefined, we'll acquire a new one.\r\n };\r\n\r\n const props = await BriefcaseManager.downloadBriefcase(request);\r\n return BriefcaseDb.open(props);\r\n }\r\n\r\n private static _briefcasePromises: Map<string, Promise<BriefcaseDb>> = new Map();\r\n private static async openBriefcase(args: DownloadAndOpenArgs): Promise<BriefcaseDb> {\r\n const key = `${args.tokenProps.iModelId}:${args.tokenProps.changeset?.id}:${args.tokenProps.changeset?.index}:${args.syncMode}`;\r\n const cachedPromise = this._briefcasePromises.get(key);\r\n if (cachedPromise)\r\n return cachedPromise;\r\n\r\n try {\r\n const briefcasePromise = this.downloadAndOpen(args); // save the fact that we're working on downloading so if we timeout, we'll reuse this request.\r\n this._briefcasePromises.set(key, briefcasePromise);\r\n return await briefcasePromise;\r\n } finally {\r\n this._briefcasePromises.delete(key); // the download and open is now done\r\n }\r\n }\r\n\r\n /** find a previously opened iModel for RPC.\r\n * @param accessToken necessary (only) for V2 checkpoints to refresh access token in daemon if it has expired. We use the accessToken of the current RPC request\r\n * to refresh the daemon, even though it will be used for all authorized users.\r\n * @param the IModelRpcProps to locate the opened iModel.\r\n */\r\n public static async findOpenIModel(accessToken: AccessToken, iModel: IModelRpcProps) {\r\n const iModelDb = IModelDb.findByKey(iModel.key);\r\n\r\n // call refreshContainer, just in case this is a V2 checkpoint whose sasToken is about to expire, or its default transaction is about to be restarted.\r\n await iModelDb.refreshContainer(accessToken);\r\n return iModelDb;\r\n }\r\n\r\n public static async open(args: DownloadAndOpenArgs & {syncMode: SyncMode.FixedVersion }): Promise<IModelDb>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async open(args: DownloadAndOpenArgs & {syncMode: Exclude<SyncMode, \"FixedVersion\"> }): Promise<IModelDb>;\r\n /**\r\n * Download and open a checkpoint or briefcase, ensuring the operation completes within a default timeout. If the time to open exceeds the timeout period,\r\n * a RpcPendingResponse exception is thrown\r\n */\r\n public static async open(args: DownloadAndOpenArgs): Promise<IModelDb> {\r\n const { activity, tokenProps, syncMode } = args;\r\n Logger.logTrace(loggerCategory, \"RpcBriefcaseUtility.open\", () => ({ ...tokenProps }));\r\n\r\n const timeout = args.timeout ?? 1000;\r\n if (syncMode === SyncMode.PullOnly || syncMode === SyncMode.PullAndPush) {\r\n const briefcaseDb = await BeDuration.race(timeout, this.openBriefcase(args));\r\n\r\n if (briefcaseDb === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open briefcase - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n // note: usage is logged in the function BriefcaseManager.downloadNewBriefcaseAndOpen\r\n return briefcaseDb;\r\n }\r\n\r\n assert(undefined !== tokenProps.iModelId);\r\n assert(undefined !== tokenProps.iTwinId);\r\n assert(undefined !== tokenProps.changeset);\r\n\r\n const checkpoint: CheckpointProps = {\r\n iModelId: tokenProps.iModelId,\r\n iTwinId: tokenProps.iTwinId,\r\n changeset: tokenProps.changeset,\r\n accessToken: activity.accessToken,\r\n };\r\n\r\n // opening a checkpoint, readonly.\r\n let db: SnapshotDb | void;\r\n // first check if it's already open\r\n db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(checkpoint));\r\n if (db) {\r\n Logger.logTrace(loggerCategory, \"Checkpoint was already open\", () => ({ ...tokenProps }));\r\n return db;\r\n }\r\n\r\n try {\r\n // now try V2 checkpoint\r\n db = await SnapshotDb.openCheckpointV2(checkpoint);\r\n Logger.logTrace(loggerCategory, \"using V2 checkpoint briefcase\", () => ({ ...tokenProps }));\r\n } catch (e) {\r\n Logger.logTrace(loggerCategory, \"unable to open V2 checkpoint - falling back to V1 checkpoint\", () => ({ error: BentleyError.getErrorProps(e), ...tokenProps }));\r\n\r\n // this isn't a v2 checkpoint. Set up a race between the specified timeout period and the open. Throw an RpcPendingResponse exception if the timeout happens first.\r\n const request = {\r\n checkpoint,\r\n localFile: V1CheckpointManager.getFileName(checkpoint),\r\n aliasFiles: [],\r\n };\r\n db = await BeDuration.race(timeout, V1CheckpointManager.getCheckpointDb(request));\r\n\r\n if (db === undefined) {\r\n Logger.logTrace(loggerCategory, \"Open V1 checkpoint - pending\", () => ({ ...tokenProps }));\r\n throw new RpcPendingResponse(); // eslint-disable-line deprecation/deprecation\r\n }\r\n Logger.logTrace(loggerCategory, \"Opened V1 checkpoint\", () => ({ ...tokenProps }));\r\n }\r\n\r\n return db;\r\n }\r\n\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode.FixedVersion, timeout?: number): Promise<IModelConnectionProps>;\r\n /**\r\n * @deprecated in 4.4.0 - only `SyncMode.FixedVersion` should be used in RPC backends\r\n */\r\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- these are separate to explicitly deprecate some SyncMode members.\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: Exclude<SyncMode, \"FixedVersion\">, timeout?: number): Promise<IModelConnectionProps>;\r\n public static async openWithTimeout(activity: RpcActivity, tokenProps: IModelRpcOpenProps, syncMode: SyncMode, timeout: number = 1000): Promise<IModelConnectionProps> { // eslint-disable-line deprecation/deprecation\r\n if (tokenProps.iModelId)\r\n await IModelHost.tileStorage?.initialize(tokenProps.iModelId);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await this.open({ activity, tokenProps, syncMode, timeout })).toJSON();\r\n }\r\n\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-backend",
|
|
3
|
-
"version": "4.4.0-dev.
|
|
3
|
+
"version": "4.4.0-dev.20",
|
|
4
4
|
"description": "iTwin.js backend components",
|
|
5
5
|
"main": "lib/cjs/core-backend.js",
|
|
6
6
|
"typings": "lib/cjs/core-backend",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "http://www.bentley.com"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@itwin/core-bentley": "^4.4.0-dev.
|
|
29
|
-
"@itwin/core-common": "^4.4.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^4.4.0-dev.
|
|
28
|
+
"@itwin/core-bentley": "^4.4.0-dev.20",
|
|
29
|
+
"@itwin/core-common": "^4.4.0-dev.20",
|
|
30
|
+
"@itwin/core-geometry": "^4.4.0-dev.20",
|
|
31
31
|
"@opentelemetry/api": "^1.0.4"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
@@ -45,44 +45,44 @@
|
|
|
45
45
|
"@types/chai": "4.3.1",
|
|
46
46
|
"@types/chai-as-promised": "^7",
|
|
47
47
|
"@types/fs-extra": "^4.0.7",
|
|
48
|
-
"@types/mocha": "^
|
|
48
|
+
"@types/mocha": "^10.0.6",
|
|
49
49
|
"@types/multiparty": "^0.0.31",
|
|
50
50
|
"@types/node": "~18.16.20",
|
|
51
51
|
"@types/semver": "7.3.10",
|
|
52
|
-
"@types/sinon": "^
|
|
52
|
+
"@types/sinon": "^17.0.2",
|
|
53
53
|
"@types/touch": "^3.1.2",
|
|
54
54
|
"@types/ws": "^7.0.0",
|
|
55
55
|
"chai": "^4.3.10",
|
|
56
|
-
"chai-as-promised": "^7",
|
|
56
|
+
"chai-as-promised": "^7.1.1",
|
|
57
57
|
"cpx2": "^3.0.0",
|
|
58
58
|
"dotenv": "^10.0.0",
|
|
59
59
|
"dotenv-expand": "^5.1.0",
|
|
60
60
|
"eslint": "^8.44.0",
|
|
61
61
|
"fs-extra": "^8.1.0",
|
|
62
|
-
"mocha": "^10.
|
|
62
|
+
"mocha": "^10.2.0",
|
|
63
63
|
"node-simctl": "~7.2.1",
|
|
64
64
|
"null-loader": "^4.0.1",
|
|
65
65
|
"nyc": "^15.1.0",
|
|
66
66
|
"rimraf": "^3.0.2",
|
|
67
|
-
"sinon": "^
|
|
67
|
+
"sinon": "^17.0.1",
|
|
68
68
|
"source-map-loader": "^4.0.0",
|
|
69
69
|
"ts-node": "^10.8.2",
|
|
70
70
|
"typescript": "~5.0.2",
|
|
71
71
|
"webpack": "^5.76.0",
|
|
72
|
-
"@itwin/build-tools": "4.4.0-dev.
|
|
73
|
-
"@itwin/core-bentley": "4.4.0-dev.
|
|
74
|
-
"@itwin/core-
|
|
75
|
-
"@itwin/core-
|
|
76
|
-
"@itwin/
|
|
77
|
-
"@itwin/
|
|
72
|
+
"@itwin/build-tools": "4.4.0-dev.20",
|
|
73
|
+
"@itwin/core-bentley": "4.4.0-dev.20",
|
|
74
|
+
"@itwin/core-common": "4.4.0-dev.20",
|
|
75
|
+
"@itwin/core-geometry": "4.4.0-dev.20",
|
|
76
|
+
"@itwin/ecsql-common": "4.4.0-dev.20",
|
|
77
|
+
"@itwin/core-webpack-tools": "4.4.0-dev.20",
|
|
78
78
|
"internal-tools": "3.0.0-dev.69"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@bentley/imodeljs-native": "4.
|
|
81
|
+
"@bentley/imodeljs-native": "4.4.1",
|
|
82
82
|
"@itwin/cloud-agnostic-core": "^2.1.0",
|
|
83
|
-
"@itwin/object-storage-azure": "^2.
|
|
84
|
-
"@itwin/object-storage-core": "^2.
|
|
85
|
-
"form-data": "^2.
|
|
83
|
+
"@itwin/object-storage-azure": "^2.2.2",
|
|
84
|
+
"@itwin/object-storage-core": "^2.2.2",
|
|
85
|
+
"form-data": "^2.5.1",
|
|
86
86
|
"fs-extra": "^8.1.0",
|
|
87
87
|
"inversify": "~6.0.1",
|
|
88
88
|
"json5": "^2.2.3",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"semver": "^7.3.5",
|
|
92
92
|
"touch": "^3.1.0",
|
|
93
93
|
"ws": "^7.5.3",
|
|
94
|
-
"@itwin/core-telemetry": "4.4.0-dev.
|
|
94
|
+
"@itwin/core-telemetry": "4.4.0-dev.20"
|
|
95
95
|
},
|
|
96
96
|
"nyc": {
|
|
97
97
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|