@itwin/core-backend 3.4.0-dev.3 → 3.4.0-dev.33

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +46 -1
  2. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  3. package/lib/cjs/BackendHubAccess.js.map +1 -1
  4. package/lib/cjs/BackendLoggerCategory.d.ts +0 -5
  5. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  6. package/lib/cjs/BackendLoggerCategory.js +0 -5
  7. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  8. package/lib/cjs/ChangedElementsDb.d.ts +1 -0
  9. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  10. package/lib/cjs/ChangedElementsDb.js +2 -2
  11. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  12. package/lib/cjs/CodeService.d.ts +392 -0
  13. package/lib/cjs/CodeService.d.ts.map +1 -0
  14. package/lib/cjs/CodeService.js +62 -0
  15. package/lib/cjs/CodeService.js.map +1 -0
  16. package/lib/cjs/CodeSpecs.js.map +1 -1
  17. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  18. package/lib/cjs/CustomViewState3dCreator.js +1 -0
  19. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  20. package/lib/cjs/Element.d.ts.map +1 -1
  21. package/lib/cjs/Element.js +4 -0
  22. package/lib/cjs/Element.js.map +1 -1
  23. package/lib/cjs/ElementTreeWalker.d.ts +41 -18
  24. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  25. package/lib/cjs/ElementTreeWalker.js +91 -57
  26. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  27. package/lib/cjs/ExportGraphics.d.ts +9 -9
  28. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  29. package/lib/cjs/ExportGraphics.js.map +1 -1
  30. package/lib/cjs/GeoCoordConfig.d.ts +7 -1
  31. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  32. package/lib/cjs/GeoCoordConfig.js +15 -6
  33. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  34. package/lib/cjs/HubMock.d.ts.map +1 -1
  35. package/lib/cjs/HubMock.js +7 -7
  36. package/lib/cjs/HubMock.js.map +1 -1
  37. package/lib/cjs/IModelDb.d.ts +23 -4
  38. package/lib/cjs/IModelDb.d.ts.map +1 -1
  39. package/lib/cjs/IModelDb.js +61 -11
  40. package/lib/cjs/IModelDb.js.map +1 -1
  41. package/lib/cjs/IModelHost.d.ts.map +1 -1
  42. package/lib/cjs/IModelHost.js +3 -1
  43. package/lib/cjs/IModelHost.js.map +1 -1
  44. package/lib/cjs/LocalHub.js +1 -1
  45. package/lib/cjs/LocalHub.js.map +1 -1
  46. package/lib/cjs/Material.d.ts +3 -1
  47. package/lib/cjs/Material.d.ts.map +1 -1
  48. package/lib/cjs/Material.js +3 -1
  49. package/lib/cjs/Material.js.map +1 -1
  50. package/lib/cjs/PropertyStore.d.ts +134 -0
  51. package/lib/cjs/PropertyStore.d.ts.map +1 -0
  52. package/lib/cjs/PropertyStore.js +12 -0
  53. package/lib/cjs/PropertyStore.js.map +1 -0
  54. package/lib/cjs/SQLiteDb.d.ts +79 -40
  55. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  56. package/lib/cjs/SQLiteDb.js +57 -40
  57. package/lib/cjs/SQLiteDb.js.map +1 -1
  58. package/lib/cjs/SqliteStatement.d.ts +14 -2
  59. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  60. package/lib/cjs/SqliteStatement.js +50 -28
  61. package/lib/cjs/SqliteStatement.js.map +1 -1
  62. package/lib/cjs/TxnManager.js +1 -1
  63. package/lib/cjs/TxnManager.js.map +1 -1
  64. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +10 -0
  65. package/lib/cjs/assets/Settings/backend.setting.json5 +1 -1
  66. package/lib/cjs/core-backend.d.ts +3 -1
  67. package/lib/cjs/core-backend.d.ts.map +1 -1
  68. package/lib/cjs/core-backend.js +3 -1
  69. package/lib/cjs/core-backend.js.map +1 -1
  70. package/lib/cjs/workspace/Workspace.d.ts +7 -3
  71. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  72. package/lib/cjs/workspace/Workspace.js +25 -20
  73. package/lib/cjs/workspace/Workspace.js.map +1 -1
  74. package/package.json +13 -18
  75. package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
  76. package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
  77. package/lib/cjs/IModelSchemaLoader.js +0 -122
  78. package/lib/cjs/IModelSchemaLoader.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Material.js","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAA+I;AAC/I,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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AmB,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;IACD;;;;;;;;OAQG;IACI,MAAM,CAAC,MAAM,CAAC,QAAkB,EAAE,iBAA6B,EAAE,YAAoB,EAAE,MAAoC;QAChI,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;AAvFD,sDAuFC;AAED,cAAc;AACd,WAAiB,qBAAqB;IACpC,yDAAyD;IACzD,MAAa,MAAM;QAwBjB,iJAAiJ;QACjJ,YAAmB,WAAmB;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;KACF;IA5BY,4BAAM,SA4BlB,CAAA;AACH,CAAC,EA/BgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QA+BrC","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 { BisCodeSpec, Code, CodeScopeProps, CodeSpec, DefinitionElementProps, RenderMaterialProps, TextureMapProps } 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 /** @internal */\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.texture);\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: RenderMaterialElement.Params): RenderMaterialElement {\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: map,\r\n },\r\n },\r\n },\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n return new RenderMaterialElement(renderMaterialProps, iModelDb);\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: RenderMaterialElement.Params): 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 export class Params {\r\n /** The palette name which categorizes this RenderMaterial */\r\n public paletteName: string;\r\n /** The optional description for this RenderMaterial */\r\n public description?: string;\r\n /** If defined, use this color for surface fill or diffuse illumination; if undefined, defaults to black */\r\n public color?: number[];\r\n /** If defined, use this color for surface specular illumination; if undefined, defaults to black */\r\n public specularColor?: number[];\r\n /** If defined, apply this specular exponent(surface shininess); range is 0 to 128; if undefined, defaults to 15.0 * 0.9 */\r\n public finish?: number;\r\n /** If defined, apply this surface transparency; if undefined, defaults to 0.0 */\r\n public transmit?: number;\r\n /** If defined, apply this surface diffuse reflectivity; if undefined, defaults to 0.6 */\r\n public diffuse?: number;\r\n /** If defined, apply this surface specular reflectivity; if undefined, defaults to 0.0. NOTE: The actual JSON allows a HasSpecular property to be true and the specular value itself undefined, in which case the value 0.4 would be used. This API does not allow this case. */\r\n public specular?: number;\r\n /** If defined, apply this surface environmental reflectivity; stored as fraction of specular in V8 material settings; if undefined, defaults to 0.0 */\r\n public reflect?: number;\r\n /** If defined, apply this surface reflectance color; if undefined, defaults to whatever the specularColor is */\r\n public reflectColor?: number[];\r\n /** If defined, specifies the pattern mapping. */\r\n public patternMap?: TextureMapProps;\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"]}
1
+ {"version":3,"file":"Material.js","sourceRoot":"","sources":["../../src/Material.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,oDAA+I;AAC/I,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,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC;CACF;AA3BD,4CA2BC;AAED;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,2BAAiB;IAQ1D,gBAAgB;IAChB,YAAY,KAA0B,EAAE,MAAgB;QACtD,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI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,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AAvFD,sDAuFC;AAED;;EAEE;AACF,WAAiB,qBAAqB;IACpC,yDAAyD;IACzD,MAAa,MAAM;QAwBjB,iJAAiJ;QACjJ,YAAmB,WAAmB;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;KACF;IA5BY,4BAAM,SA4BlB,CAAA;AACH,CAAC,EA/BgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QA+BrC","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 { BisCodeSpec, Code, CodeScopeProps, CodeSpec, DefinitionElementProps, RenderMaterialProps, TextureMapProps } 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 /** @internal */\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.texture);\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: RenderMaterialElement.Params): RenderMaterialElement {\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: map,\r\n },\r\n },\r\n },\r\n model: definitionModelId,\r\n isPrivate: false,\r\n };\r\n return new RenderMaterialElement(renderMaterialProps, iModelDb);\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: RenderMaterialElement.Params): 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\n * @note color, specularColor and reflectColor are stored as [R,G,B] where each value is between 0 and 1\r\n*/\r\nexport namespace RenderMaterialElement { // eslint-disable-line no-redeclare\r\n /** Parameters used to construct a [[RenderMaterial]]. */\r\n export class Params {\r\n /** The palette name which categorizes this RenderMaterial */\r\n public paletteName: string;\r\n /** The optional description for this RenderMaterial */\r\n public description?: string;\r\n /** If defined, use this color for surface fill or diffuse illumination; if undefined, defaults to black */\r\n public color?: number[];\r\n /** If defined, use this color for surface specular illumination; if undefined, defaults to black */\r\n public specularColor?: number[];\r\n /** If defined, apply this specular exponent(surface shininess); range is 0 to 128; if undefined, defaults to 15.0 * 0.9 */\r\n public finish?: number;\r\n /** If defined, apply this surface transparency; if undefined, defaults to 0.0 */\r\n public transmit?: number;\r\n /** If defined, apply this surface diffuse reflectivity; if undefined, defaults to 0.6 */\r\n public diffuse?: number;\r\n /** If defined, apply this surface specular reflectivity; if undefined, defaults to 0.0. NOTE: The actual JSON allows a HasSpecular property to be true and the specular value itself undefined, in which case the value 0.4 would be used. This API does not allow this case. */\r\n public specular?: number;\r\n /** If defined, apply this surface environmental reflectivity; stored as fraction of specular in V8 material settings; if undefined, defaults to 0.0 */\r\n public reflect?: number;\r\n /** If defined, apply this surface reflectance color; if undefined, defaults to whatever the specularColor is */\r\n public reflectColor?: number[];\r\n /** If defined, specifies the pattern mapping. */\r\n public patternMap?: TextureMapProps;\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"]}
@@ -0,0 +1,134 @@
1
+ import { CloudSqlite } from "@bentley/imodeljs-native";
2
+ import { AccessToken } from "@itwin/core-bentley";
3
+ import { SQLiteDb } from "./SQLiteDb";
4
+ import { SettingObject } from "./workspace/Settings";
5
+ /**
6
+ * A persistent storage for a set of values of type `PropertyType`, each with a unique `PropertyName`.
7
+ * `PropertyStore`s are stored in cloud containers, and require an access token that grants permission to read and/or write them.
8
+ * All write operations will fail without an access token that grants write permission.
9
+ * A `PropertyStore` is cached on a local drive so reads are fast and inexpensive, and may even be done offline after a prefetch.
10
+ * However, that means that callers are responsible for synchronizing the local cache to ensure it includes changes
11
+ * made by others, as appropriate (see [[synchronizeWithCloud]]).
12
+ * @alpha */
13
+ export interface PropertyStore {
14
+ /** The collection of property values in the PropertyStore as of the last time it was synchronized. */
15
+ readonly values: PropertyStore.Values;
16
+ /** Application-supplied parameters for obtaining the write lock on the container for a PropertyStore.*/
17
+ readonly appParams: SQLiteDb.ObtainLockParams;
18
+ /**
19
+ * The token that grants access to the cloud container for this PropertyStore. If it does not grant write permissions, all
20
+ * write operations will fail. It should be refreshed (via a timer) before it expires.
21
+ */
22
+ sasToken: AccessToken;
23
+ /**
24
+ * Synchronize the local values in this PropertyStore with any changes by made by others.
25
+ * @note This is called automatically whenever any write operation is performed on the PropertyStore. It is only necessary to
26
+ * call this directly if you have not changed the PropertyStore recently, but wish to perform a readonly operation and want to
27
+ * ensure it is up-to-date as of now.
28
+ * @note There is no guarantee that the Values are up-to-date even immediately after calling this method, since others
29
+ * may be modifying them at any time.
30
+ */
31
+ synchronizeWithCloud(): void;
32
+ /** initiate a prefetch operation on this PropertyStore
33
+ * @internal
34
+ */
35
+ startPrefetch(): SQLiteDb.CloudPrefetch;
36
+ /** Save a single property in this PropertyStore. If the property already exists, its value is overwritten.
37
+ * @note This will obtain the write lock, save the value, and then release the write lock.
38
+ */
39
+ saveProperty(name: PropertyStore.PropertyName, value: PropertyStore.PropertyType): Promise<void>;
40
+ /** Save an array of properties in this PropertyStore. If a property already exists, its value is overwritten.
41
+ * @note This will obtain the write lock, save the values, and then release the write lock.
42
+ */
43
+ saveProperties(props: PropertyStore.PropertyArray): Promise<void>;
44
+ /** Delete a single property from this PropertyStore. If the value does not exist, this method does nothing.
45
+ * @note This will obtain the write lock, delete the value, and then release the write lock.
46
+ */
47
+ deleteProperty(propName: PropertyStore.PropertyName): Promise<void>;
48
+ /** Delete an array of properties from this PropertyStore. Any value that does not exist is ignored.
49
+ * @note This will obtain the write lock, delete the values, and then release the write lock.
50
+ */
51
+ deleteProperties(propNames: PropertyStore.PropertyName[]): Promise<void>;
52
+ }
53
+ /** @alpha */
54
+ export declare namespace PropertyStore {
55
+ /** @internal */
56
+ let openPropertyStore: ((props: CloudSqlite.ContainerAccessProps) => PropertyStore) | undefined;
57
+ /** The set of valid types for properties in a PropertyStore. */
58
+ type PropertyType = string | number | boolean | Uint8Array | SettingObject;
59
+ /** The name of a Property. May not have leading or trailing spaces, and must be between 3 and 2048 characters long. */
60
+ type PropertyName = string;
61
+ /** An array of PropertyName/PropertyType pairs to be stored in a PropertyStore. */
62
+ type PropertyArray = {
63
+ name: PropertyName;
64
+ value: PropertyType;
65
+ }[];
66
+ /** The return status of an iteration function. The value "stop" causes the iteration to terminate. */
67
+ type IterationReturn = void | "stop";
68
+ /** An iteration function over Properties in a PropertyStore. It is called with the name of a each Property. */
69
+ type PropertyIteration = (name: string) => IterationReturn;
70
+ /** A filter used to limit and/or sort the values returned by an iteration. */
71
+ interface PropertyFilter {
72
+ /** A value filter. May include wild cards when used with `GLOB` or `LIKE` */
73
+ readonly value?: string;
74
+ /** The comparison operator for `value`. Default is `=` */
75
+ readonly valueCompare?: "GLOB" | "LIKE" | "NOT GLOB" | "NOT LIKE" | "=" | "<" | ">";
76
+ /** Order results ascending or descending. If not supplied, the results are unordered (random). */
77
+ readonly orderBy?: "ASC" | "DESC";
78
+ /** An SQL expression to further filter results. This string is appended to the `WHERE` clause with an `AND` (that should not be part of the sqlExpression) */
79
+ readonly sqlExpression?: string;
80
+ }
81
+ /**
82
+ * A readonly set of Property values in a PropertyStore.
83
+ * @alpha
84
+ */
85
+ interface Values {
86
+ /** get the value of a Property by name.
87
+ * @returns the property's value if it exists, `undefined` otherwise.
88
+ */
89
+ getProperty(name: PropertyName): PropertyType | undefined;
90
+ /** Get the value of a string property by name.
91
+ * @returns the property's value if it exists and is a string, `undefined` otherwise.
92
+ */
93
+ getString(name: PropertyName): string | undefined;
94
+ /** Get the value of a string property by name.
95
+ * @returns the property's value if it exists and is a string, otherwise the supplied default value.
96
+ */
97
+ getString(name: PropertyName, defaultValue: string): string;
98
+ /** Get the value of a boolean property by name.
99
+ * @returns the property's value if it exists and is a boolean, `undefined` otherwise.
100
+ */
101
+ getBoolean(name: PropertyName): boolean | undefined;
102
+ /** Get the value of a boolean property by name.
103
+ * @returns the property's value if it exists and is a boolean, otherwise the supplied default value.
104
+ */
105
+ getBoolean(name: PropertyName, defaultValue: boolean): boolean;
106
+ /** Get the value of a number property by name.
107
+ * @returns the property's value if it exists and is a number, `undefined` otherwise.
108
+ */
109
+ getNumber(name: PropertyName): number | undefined;
110
+ /** Get the value of a number property by name.
111
+ * @returns the property's value if it exists and is a number, otherwise the supplied default value.
112
+ */
113
+ getNumber(name: PropertyName, defaultValue: number): number;
114
+ /** Get the value of a blob property by name.
115
+ * @returns the property's value if it exists and is a blob, `undefined` otherwise.
116
+ */
117
+ getBlob(name: PropertyName): Uint8Array | undefined;
118
+ /** Get the value of a blob property by name.
119
+ * @returns the property's value if it exists and is a blob, otherwise the supplied default value.
120
+ */
121
+ getBlob(name: PropertyName, defaultValue: Uint8Array): Uint8Array;
122
+ /** Get the value of an object property by name.
123
+ * @returns the property's value if it exists and is an object, `undefined` otherwise.
124
+ */
125
+ getObject<T extends SettingObject>(name: PropertyName): T | undefined;
126
+ /** Get the value of an object property by name.
127
+ * @returns the property's value if it exists and is an object, otherwise the supplied default value.
128
+ */
129
+ getObject<T extends SettingObject>(name: PropertyName, defaultValue: T): T;
130
+ /** call an iteration function for each property, optionally applying a filter */
131
+ forAllProperties(iter: PropertyIteration, filter?: PropertyFilter): void;
132
+ }
133
+ }
134
+ //# sourceMapping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AAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC;QAC/D;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;QAClD;;UAEE;QACF,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5D;;UAEE;QACF,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;QACpD;;UAEE;QACF,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC;QAClE;;UAEE;QACF,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,GAAG,SAAS,CAAC;QACtE;;UAEE;QACF,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC;QAC3E,iFAAiF;QACjF,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;KAC1E;CACF"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PropertyStore = void 0;
8
+ /** @alpha */
9
+ var PropertyStore;
10
+ (function (PropertyStore) {
11
+ })(PropertyStore = exports.PropertyStore || (exports.PropertyStore = {}));
12
+ //# sourceMappingURL=PropertyStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyStore.js","sourceRoot":"","sources":["../../src/PropertyStore.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AA8D/F,aAAa;AACb,IAAiB,aAAa,CA+E7B;AA/ED,WAAiB,aAAa;AA+E9B,CAAC,EA/EgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA+E7B","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 { CloudSqlite } from \"@bentley/imodeljs-native\";\r\nimport { AccessToken } from \"@itwin/core-bentley\";\r\nimport { SQLiteDb } from \"./SQLiteDb\";\r\nimport { SettingObject } from \"./workspace/Settings\";\r\n\r\n/**\r\n * A persistent storage for a set of values of type `PropertyType`, each with a unique `PropertyName`.\r\n * `PropertyStore`s are stored in cloud containers, and require an access token that grants permission to read and/or write them.\r\n * All write operations will fail without an access token that grants write permission.\r\n * A `PropertyStore` is cached on a local drive so reads are fast and inexpensive, and may even be done offline after a prefetch.\r\n * However, that means that callers are responsible for synchronizing the local cache to ensure it includes changes\r\n * made by others, as appropriate (see [[synchronizeWithCloud]]).\r\n * @alpha */\r\nexport interface PropertyStore {\r\n\r\n /** The collection of property values in the PropertyStore as of the last time it was synchronized. */\r\n readonly values: PropertyStore.Values;\r\n\r\n /** Application-supplied parameters for obtaining the write lock on the container for a PropertyStore.*/\r\n readonly appParams: SQLiteDb.ObtainLockParams;\r\n\r\n /**\r\n * The token that grants access to the cloud container for this PropertyStore. If it does not grant write permissions, all\r\n * write operations will fail. It should be refreshed (via a timer) before it expires.\r\n */\r\n sasToken: AccessToken;\r\n\r\n /**\r\n * Synchronize the local values in this PropertyStore with any changes by made by others.\r\n * @note This is called automatically whenever any write operation is performed on the PropertyStore. It is only necessary to\r\n * call this directly if you have not changed the PropertyStore recently, but wish to perform a readonly operation and want to\r\n * ensure it is up-to-date as of now.\r\n * @note There is no guarantee that the Values are up-to-date even immediately after calling this method, since others\r\n * may be modifying them at any time.\r\n */\r\n synchronizeWithCloud(): void;\r\n\r\n /** initiate a prefetch operation on this PropertyStore\r\n * @internal\r\n */\r\n startPrefetch(): SQLiteDb.CloudPrefetch;\r\n\r\n /** Save a single property in this PropertyStore. If the property already exists, its value is overwritten.\r\n * @note This will obtain the write lock, save the value, and then release the write lock.\r\n */\r\n saveProperty(name: PropertyStore.PropertyName, value: PropertyStore.PropertyType): Promise<void>;\r\n /** Save an array of properties in this PropertyStore. If a property already exists, its value is overwritten.\r\n * @note This will obtain the write lock, save the values, and then release the write lock.\r\n */\r\n saveProperties(props: PropertyStore.PropertyArray): Promise<void>;\r\n /** Delete a single property from this PropertyStore. If the value does not exist, this method does nothing.\r\n * @note This will obtain the write lock, delete the value, and then release the write lock.\r\n */\r\n deleteProperty(propName: PropertyStore.PropertyName): Promise<void>;\r\n /** Delete an array of properties from this PropertyStore. Any value that does not exist is ignored.\r\n * @note This will obtain the write lock, delete the values, and then release the write lock.\r\n */\r\n deleteProperties(propNames: PropertyStore.PropertyName[]): Promise<void>;\r\n}\r\n\r\n/** @alpha */\r\nexport namespace PropertyStore {\r\n /** @internal */\r\n export let openPropertyStore: ((props: CloudSqlite.ContainerAccessProps) => PropertyStore) | undefined;\r\n\r\n /** The set of valid types for properties in a PropertyStore. */\r\n export type PropertyType = string | number | boolean | Uint8Array | SettingObject;\r\n /** The name of a Property. May not have leading or trailing spaces, and must be between 3 and 2048 characters long. */\r\n export type PropertyName = string;\r\n /** An array of PropertyName/PropertyType pairs to be stored in a PropertyStore. */\r\n export type PropertyArray = { name: PropertyName, value: PropertyType }[];\r\n /** The return status of an iteration function. The value \"stop\" causes the iteration to terminate. */\r\n export type IterationReturn = void | \"stop\";\r\n /** An iteration function over Properties in a PropertyStore. It is called with the name of a each Property. */\r\n export type PropertyIteration = (name: string) => IterationReturn;\r\n\r\n /** A filter used to limit and/or sort the values returned by an iteration. */\r\n export interface PropertyFilter {\r\n /** A value filter. May include wild cards when used with `GLOB` or `LIKE` */\r\n readonly value?: string;\r\n /** The comparison operator for `value`. Default is `=` */\r\n readonly valueCompare?: \"GLOB\" | \"LIKE\" | \"NOT GLOB\" | \"NOT LIKE\" | \"=\" | \"<\" | \">\";\r\n /** Order results ascending or descending. If not supplied, the results are unordered (random). */\r\n readonly orderBy?: \"ASC\" | \"DESC\";\r\n /** An SQL expression to further filter results. This string is appended to the `WHERE` clause with an `AND` (that should not be part of the sqlExpression) */\r\n readonly sqlExpression?: string;\r\n }\r\n\r\n /**\r\n * A readonly set of Property values in a PropertyStore.\r\n * @alpha\r\n */\r\n export interface Values {\r\n /** get the value of a Property by name.\r\n * @returns the property's value if it exists, `undefined` otherwise.\r\n */\r\n getProperty(name: PropertyName): PropertyType | undefined;\r\n /** Get the value of a string property by name.\r\n * @returns the property's value if it exists and is a string, `undefined` otherwise.\r\n */\r\n getString(name: PropertyName): string | undefined;\r\n /** Get the value of a string property by name.\r\n * @returns the property's value if it exists and is a string, otherwise the supplied default value.\r\n */\r\n getString(name: PropertyName, defaultValue: string): string;\r\n /** Get the value of a boolean property by name.\r\n * @returns the property's value if it exists and is a boolean, `undefined` otherwise.\r\n */\r\n getBoolean(name: PropertyName): boolean | undefined;\r\n /** Get the value of a boolean property by name.\r\n * @returns the property's value if it exists and is a boolean, otherwise the supplied default value.\r\n */\r\n getBoolean(name: PropertyName, defaultValue: boolean): boolean;\r\n /** Get the value of a number property by name.\r\n * @returns the property's value if it exists and is a number, `undefined` otherwise.\r\n */\r\n getNumber(name: PropertyName): number | undefined;\r\n /** Get the value of a number property by name.\r\n * @returns the property's value if it exists and is a number, otherwise the supplied default value.\r\n */\r\n getNumber(name: PropertyName, defaultValue: number): number;\r\n /** Get the value of a blob property by name.\r\n * @returns the property's value if it exists and is a blob, `undefined` otherwise.\r\n */\r\n getBlob(name: PropertyName): Uint8Array | undefined;\r\n /** Get the value of a blob property by name.\r\n * @returns the property's value if it exists and is a blob, otherwise the supplied default value.\r\n */\r\n getBlob(name: PropertyName, defaultValue: Uint8Array): Uint8Array;\r\n /** Get the value of an object property by name.\r\n * @returns the property's value if it exists and is an object, `undefined` otherwise.\r\n */\r\n getObject<T extends SettingObject>(name: PropertyName): T | undefined;\r\n /** Get the value of an object property by name.\r\n * @returns the property's value if it exists and is an object, otherwise the supplied default value.\r\n */\r\n getObject<T extends SettingObject>(name: PropertyName, defaultValue: T): T;\r\n /** call an iteration function for each property, optionally applying a filter */\r\n forAllProperties(iter: PropertyIteration, filter?: PropertyFilter): void;\r\n }\r\n}\r\n"]}
@@ -36,55 +36,44 @@ export declare class SQLiteDb implements IDisposable {
36
36
  */
37
37
  openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: SQLiteDb.CloudContainer): void;
38
38
  /** Close SQLiteDb.
39
- * @param saveChanges if true, call `saveChanges` before closing db.
39
+ * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
40
40
  */
41
41
  closeDb(saveChanges?: boolean): void;
42
- /** Returns true if the SQLiteDb is open */
42
+ /** Returns true if this SQLiteDb is open */
43
43
  get isOpen(): boolean;
44
+ /** Returns true if this SQLiteDb is open readonly */
45
+ get isReadonly(): boolean;
44
46
  /**
45
- * 1. open a database
46
- * 2. call a function supplying the open SQliteDb as argument. If it is async, await its return.
47
- * 3. close the database (even if exceptions are thrown)
47
+ * Open a database, perform an operation, then close the database.
48
+ *
49
+ * Details:
50
+ * - if database is open, throw an error
51
+ * - open a database
52
+ * - call a function with the database opened. If it is async, await its return.
53
+ * - if function throws, abandon all changes, close database, and rethrow
54
+ * - save all changes
55
+ * - close the database
56
+ * @return value from operation
48
57
  */
49
- static withOpenDb<T>(args: {
50
- /** The name of the database to open */
51
- dbName: string;
52
- /** either an object with the open parameters or just OpenMode value. */
53
- openMode?: OpenMode | SQLiteDb.OpenParams;
54
- /** @internal */
55
- container?: SQLiteDb.CloudContainer;
56
- }, operation: (db: SQLiteDb) => T): T;
58
+ withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T;
57
59
  /**
58
- * 1. acquire the write lock on a CloudContainer
59
- * 2. open a ReadWrite database in the container
60
- * 3. call a function with the opened database as an argument
61
- * 4. close the database
62
- * 5. release the write lock and upload changes.
60
+ * Perform an operation on a database in a CloudContainer with the write lock held.
61
+ *
62
+ * Details:
63
+ * - acquire the write lock on a CloudContainer
64
+ * - call `withOpenDb` with openMode `ReadWrite`
65
+ * - upload changes
66
+ * - release the write lock
67
+ * @param args arguments to lock the container and open the database
68
+ * @param operation an operation performed on the database with the write lock held.
69
+ * @return value from operation
63
70
  * @internal
64
71
  */
65
- static withLockedContainer(args: {
66
- /** the name to be displayed in the event of lock collisions */
67
- user: string;
68
- /** the name of the database within the container */
69
- dbName: string;
70
- /** the CloudContainer on which the operation will be performed */
71
- container: SQLiteDb.CloudContainer;
72
- /** if present, function called when the write lock is currently held by another user. */
73
- busyHandler?: CloudSqlite.WriteLockBusyHandler;
74
- },
75
- /** an asynchronous operation performed on the database with the write lock held. */
76
- operation: (db: SQLiteDb) => Promise<void>): Promise<void>;
72
+ withLockedContainer<T>(args: SQLiteDb.LockAndOpenArgs, operation: () => T): Promise<T>;
77
73
  /** vacuum this database
78
74
  * @see https://www.sqlite.org/lang_vacuum.html
79
75
  */
80
- vacuum(args?: {
81
- /** new page size
82
- * @see https://www.sqlite.org/pragma.html#pragma_page_size
83
- */
84
- pageSize?: number;
85
- /** if present, name of new file to vacuum into */
86
- into?: LocalFileName;
87
- }): void;
76
+ vacuum(args?: SQLiteDb.VacuumDbArgs): void;
88
77
  /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
89
78
  saveChanges(): void;
90
79
  /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
@@ -109,6 +98,12 @@ export declare class SQLiteDb implements IDisposable {
109
98
  * @returns the value returned by `callback`.
110
99
  */
111
100
  withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T;
101
+ /**
102
+ * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
103
+ * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
104
+ * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
105
+ */
106
+ withSavePoint(savePointName: string, operation: () => void): void;
112
107
  /** Prepare an SQL statement.
113
108
  * @param sql The SQLite SQL statement to prepare
114
109
  * @param logErrors Determine if errors are logged or not
@@ -165,10 +160,54 @@ export declare namespace SQLiteDb {
165
160
  /** use OpenMode.ReadWrite to open the file with write access */
166
161
  openMode: OpenMode;
167
162
  }
168
- /** Parameters for creating a new SQLiteDb */
169
- interface CreateParams extends OpenOrCreateParams {
163
+ /** Size of a SQLiteDb page in bytes */
164
+ interface PageSize {
170
165
  /** see https://www.sqlite.org/pragma.html#pragma_page_size */
171
166
  pageSize?: number;
172
167
  }
168
+ /** Parameters for creating a new SQLiteDb */
169
+ type CreateParams = OpenOrCreateParams & PageSize;
170
+ /** Parameters used to obtain the write lock on a cloud container
171
+ * @internal
172
+ */
173
+ interface ObtainLockParams {
174
+ /** The name of the user attempting to acquire the write lock. This name will be shown to other users while the lock is held. */
175
+ user?: string;
176
+ /** number of times to retry in the event the lock currently held by someone else.
177
+ * After this number of attempts, `onFailure` is called. Default is 20.
178
+ */
179
+ nRetries: number;
180
+ /** Delay between retries, in milliseconds. Default is 100. */
181
+ retryDelayMs: number;
182
+ /** function called if lock cannot be obtained after all retries. It is called with the name of the user currently holding the lock and
183
+ * generally is expected that the user will be consulted whether to wait further.
184
+ * If this function returns "stop", an exception will be thrown. Otherwise the retry cycle is restarted. */
185
+ onFailure?: CloudSqlite.WriteLockBusyHandler;
186
+ }
187
+ /** @internal */
188
+ interface LockAndOpenArgs {
189
+ /** the name to be displayed in the event of lock collisions */
190
+ user: string;
191
+ /** the name of the database within the container */
192
+ dbName: string;
193
+ /** the CloudContainer on which the operation will be performed */
194
+ container: SQLiteDb.CloudContainer;
195
+ /** if present, function called when the write lock is currently held by another user. */
196
+ busyHandler?: CloudSqlite.WriteLockBusyHandler;
197
+ }
198
+ /** Arguments for `SqliteDb.withOpenDb` */
199
+ interface WithOpenDbArgs {
200
+ /** The name of the database to open */
201
+ dbName: string;
202
+ /** either an object with the open parameters or just OpenMode value. */
203
+ openMode?: OpenMode | SQLiteDb.OpenParams;
204
+ /** @internal */
205
+ container?: SQLiteDb.CloudContainer;
206
+ }
207
+ /** Arguments for `SQLiteDb.vacuum` */
208
+ interface VacuumDbArgs extends PageSize {
209
+ /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */
210
+ into?: LocalFileName;
211
+ }
173
212
  }
174
213
  //# sourceMappingURL=SQLiteDb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDb.d.ts","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAkB,MAAM,mBAAmB,CAAC;AAIpE;;GAEG;AACH,qBAAa,QAAS,YAAW,WAAW;IAC1C,gBAAgB;IAChB,SAAgB,QAAQ,0BAAsC;IAC9D,OAAO,CAAC,qBAAqB,CAAyC;IAEtE,gBAAgB;WACF,oBAAoB,CAAC,IAAI,EAAE,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,cAAc;IAGnG,gBAAgB;WACF,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU;IAGjF,gBAAgB;WACF,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa;IAG9I,gBAAgB;WACF,YAAY,IAAI,QAAQ,CAAC,MAAM;IAI7C,yBAAyB;IAClB,OAAO,IAAI,IAAI;IAItB;;OAEG;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AuC;IACvC,UAAiB,QAAQ;QACvB,8DAA8D;QAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAED,6CAA6C;IAC7C,KAAY,YAAY,GAAG,kBAAkB,GAAG,QAAQ,CAAC;IAEzD;;OAEG;IACH,UAAiB,gBAAgB;QAC/B,gIAAgI;QAChI,IAAI,CAAC,EAAE,MAAM,CAAC;QACd;;SAEC;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,8DAA8D;QAC9D,YAAY,EAAE,MAAM,CAAC;QACrB;;iHAEyG;QACzG,SAAS,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC;KAC9C;IAED,gBAAgB;IAChB,UAAiB,eAAe;QAC9B,+DAA+D;QAC/D,IAAI,EAAE,MAAM,CAAC;QACb,oDAAoD;QACpD,MAAM,EAAE,MAAM,CAAC;QACf,kEAAkE;QAClE,SAAS,EAAE,QAAQ,CAAC,cAAc,CAAC;QACnC,yFAAyF;QACzF,WAAW,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC;KAChD;IAED,0CAA0C;IAC1C,UAAiB,cAAc;QAC7B,uCAAuC;QACvC,MAAM,EAAE,MAAM,CAAC;QACf,wEAAwE;QACxE,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC;QAC1C,gBAAgB;QAChB,SAAS,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC;KACrC;IAED,sCAAsC;IACtC,UAAiB,YAAa,SAAQ,QAAQ;QAC5C,6FAA6F;QAC7F,IAAI,CAAC,EAAE,aAAa,CAAC;KACtB;CACF"}
@@ -12,6 +12,7 @@ const imodeljs_native_1 = require("@bentley/imodeljs-native");
12
12
  const core_bentley_1 = require("@itwin/core-bentley");
13
13
  const IModelHost_1 = require("./IModelHost");
14
14
  const SqliteStatement_1 = require("./SqliteStatement");
15
+ // cspell:ignore savepoint
15
16
  /* eslint-disable @typescript-eslint/unified-signatures */
16
17
  /** A SQLiteDb file
17
18
  * @public
@@ -53,7 +54,7 @@ class SQLiteDb {
53
54
  this.nativeDb.openDb(dbName, openMode, container);
54
55
  }
55
56
  /** Close SQLiteDb.
56
- * @param saveChanges if true, call `saveChanges` before closing db.
57
+ * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
57
58
  */
58
59
  closeDb(saveChanges) {
59
60
  if (saveChanges && this.isOpen)
@@ -61,45 +62,53 @@ class SQLiteDb {
61
62
  this._sqliteStatementCache.clear();
62
63
  this.nativeDb.closeDb();
63
64
  }
64
- /** Returns true if the SQLiteDb is open */
65
+ /** Returns true if this SQLiteDb is open */
65
66
  get isOpen() { return this.nativeDb.isOpen(); }
67
+ /** Returns true if this SQLiteDb is open readonly */
68
+ get isReadonly() { return this.nativeDb.isReadonly(); }
66
69
  /**
67
- * 1. open a database
68
- * 2. call a function supplying the open SQliteDb as argument. If it is async, await its return.
69
- * 3. close the database (even if exceptions are thrown)
70
+ * Open a database, perform an operation, then close the database.
71
+ *
72
+ * Details:
73
+ * - if database is open, throw an error
74
+ * - open a database
75
+ * - call a function with the database opened. If it is async, await its return.
76
+ * - if function throws, abandon all changes, close database, and rethrow
77
+ * - save all changes
78
+ * - close the database
79
+ * @return value from operation
70
80
  */
71
- static withOpenDb(args, operation) {
81
+ withOpenDb(args, operation) {
72
82
  var _a;
73
- const db = new SQLiteDb();
74
- db.openDb(args.dbName, (_a = args.openMode) !== null && _a !== void 0 ? _a : core_bentley_1.OpenMode.Readonly, args.container);
75
- let fromPromise = false;
83
+ if (this.isOpen)
84
+ throw new Error("database is already open");
85
+ const save = () => this.closeDb(true), abandon = () => this.closeDb(false);
86
+ this.openDb(args.dbName, (_a = args.openMode) !== null && _a !== void 0 ? _a : core_bentley_1.OpenMode.Readonly, args.container);
76
87
  try {
77
- const result = operation(db);
78
- if (result instanceof Promise) {
79
- fromPromise = true;
80
- const doClose = () => db.closeDb();
81
- result.then(doClose, doClose);
82
- }
88
+ const result = operation();
89
+ result instanceof Promise ? result.then(save, abandon) : save();
83
90
  return result;
84
91
  }
85
- finally {
86
- if (!fromPromise)
87
- db.closeDb();
92
+ catch (e) {
93
+ abandon();
94
+ throw e;
88
95
  }
89
96
  }
90
97
  /**
91
- * 1. acquire the write lock on a CloudContainer
92
- * 2. open a ReadWrite database in the container
93
- * 3. call a function with the opened database as an argument
94
- * 4. close the database
95
- * 5. release the write lock and upload changes.
98
+ * Perform an operation on a database in a CloudContainer with the write lock held.
99
+ *
100
+ * Details:
101
+ * - acquire the write lock on a CloudContainer
102
+ * - call `withOpenDb` with openMode `ReadWrite`
103
+ * - upload changes
104
+ * - release the write lock
105
+ * @param args arguments to lock the container and open the database
106
+ * @param operation an operation performed on the database with the write lock held.
107
+ * @return value from operation
96
108
  * @internal
97
109
  */
98
- static async withLockedContainer(args,
99
- /** an asynchronous operation performed on the database with the write lock held. */
100
- operation) {
101
- const fn = async () => SQLiteDb.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation);
102
- await imodeljs_native_1.CloudSqlite.withWriteLock(args.user, args.container, fn, args.busyHandler);
110
+ async withLockedContainer(args, operation) {
111
+ return imodeljs_native_1.CloudSqlite.withWriteLock(args.user, args.container, () => this.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation), args.busyHandler);
103
112
  }
104
113
  /** vacuum this database
105
114
  * @see https://www.sqlite.org/lang_vacuum.html
@@ -131,12 +140,7 @@ class SQLiteDb {
131
140
  const release = () => this._sqliteStatementCache.addOrDispose(stmt);
132
141
  try {
133
142
  const val = callback(stmt);
134
- if (val instanceof Promise) {
135
- val.then(release, release);
136
- }
137
- else {
138
- release();
139
- }
143
+ val instanceof Promise ? val.then(release, release) : release();
140
144
  return val;
141
145
  }
142
146
  catch (err) {
@@ -157,12 +161,7 @@ class SQLiteDb {
157
161
  const release = () => stmt.dispose();
158
162
  try {
159
163
  const val = callback(stmt);
160
- if (val instanceof Promise) {
161
- val.then(release, release);
162
- }
163
- else {
164
- release();
165
- }
164
+ val instanceof Promise ? val.then(release, release) : release();
166
165
  return val;
167
166
  }
168
167
  catch (err) {
@@ -170,6 +169,24 @@ class SQLiteDb {
170
169
  throw err;
171
170
  }
172
171
  }
172
+ /**
173
+ * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
174
+ * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
175
+ * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
176
+ */
177
+ withSavePoint(savePointName, operation) {
178
+ if (this.isReadonly)
179
+ throw new Error("database is readonly");
180
+ this.executeSQL(`SAVEPOINT ${savePointName}`);
181
+ try {
182
+ operation();
183
+ this.executeSQL(`RELEASE ${savePointName}`);
184
+ }
185
+ catch (e) {
186
+ this.executeSQL(`ROLLBACK TO ${savePointName}`);
187
+ throw e;
188
+ }
189
+ }
173
190
  /** Prepare an SQL statement.
174
191
  * @param sql The SQLite SQL statement to prepare
175
192
  * @param logErrors Determine if errors are logged or not