@itwin/core-backend 4.9.0-dev.2 → 4.9.0-dev.4

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 (123) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/lib/cjs/BackendHubAccess.js.map +1 -1
  3. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  4. package/lib/cjs/BisCoreSchema.js.map +1 -1
  5. package/lib/cjs/BlobContainerService.js.map +1 -1
  6. package/lib/cjs/BriefcaseManager.js.map +1 -1
  7. package/lib/cjs/Category.js.map +1 -1
  8. package/lib/cjs/ChangeSummaryManager.js +2 -2
  9. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  10. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  11. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  12. package/lib/cjs/ChangesetECAdaptor.js +242 -242
  13. package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
  14. package/lib/cjs/ChannelControl.js.map +1 -1
  15. package/lib/cjs/CheckpointManager.js.map +1 -1
  16. package/lib/cjs/ClassRegistry.js +5 -5
  17. package/lib/cjs/ClassRegistry.js.map +1 -1
  18. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  19. package/lib/cjs/CloudSqlite.js +3 -0
  20. package/lib/cjs/CloudSqlite.js.map +1 -1
  21. package/lib/cjs/CodeService.js.map +1 -1
  22. package/lib/cjs/CodeSpecs.js.map +1 -1
  23. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  24. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  25. package/lib/cjs/DevTools.js.map +1 -1
  26. package/lib/cjs/DisplayStyle.js.map +1 -1
  27. package/lib/cjs/ECDb.js.map +1 -1
  28. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  29. package/lib/cjs/ECSqlStatement.js.map +1 -1
  30. package/lib/cjs/Element.js.map +1 -1
  31. package/lib/cjs/ElementAspect.js.map +1 -1
  32. package/lib/cjs/ElementGraphics.js.map +1 -1
  33. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  34. package/lib/cjs/Entity.js.map +1 -1
  35. package/lib/cjs/EntityReferences.js.map +1 -1
  36. package/lib/cjs/ExportGraphics.js.map +1 -1
  37. package/lib/cjs/ExternalSource.js.map +1 -1
  38. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  39. package/lib/cjs/GeographicCRSServices.js.map +1 -1
  40. package/lib/cjs/GeometrySummary.js +47 -47
  41. package/lib/cjs/GeometrySummary.js.map +1 -1
  42. package/lib/cjs/HubMock.js.map +1 -1
  43. package/lib/cjs/IModelCloneContext.js.map +1 -1
  44. package/lib/cjs/IModelDb.d.ts +1 -0
  45. package/lib/cjs/IModelDb.d.ts.map +1 -1
  46. package/lib/cjs/IModelDb.js +9 -8
  47. package/lib/cjs/IModelDb.js.map +1 -1
  48. package/lib/cjs/IModelElementCloneContext.js.map +1 -1
  49. package/lib/cjs/IModelHost.js.map +1 -1
  50. package/lib/cjs/IModelJsFs.js.map +1 -1
  51. package/lib/cjs/IpcHost.js.map +1 -1
  52. package/lib/cjs/LineStyle.js.map +1 -1
  53. package/lib/cjs/LocalHub.js +1 -1
  54. package/lib/cjs/LocalHub.js.map +1 -1
  55. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  56. package/lib/cjs/LockControl.js.map +1 -1
  57. package/lib/cjs/Material.js.map +1 -1
  58. package/lib/cjs/Model.js.map +1 -1
  59. package/lib/cjs/NativeAppStorage.js.map +1 -1
  60. package/lib/cjs/NativeHost.js.map +1 -1
  61. package/lib/cjs/NavigationRelationship.js.map +1 -1
  62. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  63. package/lib/cjs/PropertyStore.js.map +1 -1
  64. package/lib/cjs/Relationship.js.map +1 -1
  65. package/lib/cjs/RpcBackend.js.map +1 -1
  66. package/lib/cjs/SQLiteDb.js.map +1 -1
  67. package/lib/cjs/Schema.js.map +1 -1
  68. package/lib/cjs/SchemaSync.js.map +1 -1
  69. package/lib/cjs/SchemaUtils.js.map +1 -1
  70. package/lib/cjs/SqliteChangesetReader.js.map +1 -1
  71. package/lib/cjs/SqliteStatement.js.map +1 -1
  72. package/lib/cjs/TextAnnotationElement.js.map +1 -1
  73. package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
  74. package/lib/cjs/TextAnnotationLayout.d.ts +21 -0
  75. package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
  76. package/lib/cjs/TextAnnotationLayout.js +29 -1
  77. package/lib/cjs/TextAnnotationLayout.js.map +1 -1
  78. package/lib/cjs/Texture.js.map +1 -1
  79. package/lib/cjs/TileStorage.js.map +1 -1
  80. package/lib/cjs/TxnManager.js.map +1 -1
  81. package/lib/cjs/ViewDefinition.js.map +1 -1
  82. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  83. package/lib/cjs/ViewStore.js.map +1 -1
  84. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  85. package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +32 -32
  86. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +27 -27
  87. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +94 -94
  88. package/lib/cjs/assets/Settings/backend.setting.json5 +21 -21
  89. package/lib/cjs/core-backend.d.ts +1 -1
  90. package/lib/cjs/core-backend.d.ts.map +1 -1
  91. package/lib/cjs/core-backend.js +2 -1
  92. package/lib/cjs/core-backend.js.map +1 -1
  93. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  94. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  95. package/lib/cjs/domains/GenericElements.js.map +1 -1
  96. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  97. package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -1
  98. package/lib/cjs/internal/ChannelAdmin.js.map +1 -1
  99. package/lib/cjs/internal/NativePlatform.js.map +1 -1
  100. package/lib/cjs/internal/NoLocks.js.map +1 -1
  101. package/lib/cjs/internal/ServerBasedLocks.js.map +1 -1
  102. package/lib/cjs/internal/Symbols.js.map +1 -1
  103. package/lib/cjs/internal/cross-package.js.map +1 -1
  104. package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -1
  105. package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -1
  106. package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -1
  107. package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -1
  108. package/lib/cjs/rpc/multipart.js.map +1 -1
  109. package/lib/cjs/rpc/tracing.js.map +1 -1
  110. package/lib/cjs/rpc/web/logging.js.map +1 -1
  111. package/lib/cjs/rpc/web/request.js.map +1 -1
  112. package/lib/cjs/rpc/web/response.js.map +1 -1
  113. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  114. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  115. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  116. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  117. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  118. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  119. package/lib/cjs/workspace/Settings.js.map +1 -1
  120. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  121. package/lib/cjs/workspace/Workspace.js.map +1 -1
  122. package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -1
  123. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"Relationship.js","sourceRoot":"","sources":["../../src/Relationship.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAiE;AACjE,oDAAuH;AAEvH,qCAAkC;AAElC,gDAA+C;AAI/C;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IAC/B,MAAM,KAAc,SAAS,KAAa,OAAO,cAAc,CAAC,CAAC,CAAC;IAIzE,YAAsB,KAAwB,EAAE,MAAgB;QAC9D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AAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,KAAK,CAAC,aAAa,GAAI,KAAa,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAyB,eAAuB,EAAE,QAAsC;QACxG,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAyB,gBAAwB,EAAE,QAAsC;QAC5G,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAoB,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAClG,OAAO,SAAS,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1G,CAAC;CACF;AAvGD,sCAuGC","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 Relationships\r\n */\r\n\r\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { EntityReferenceSet, IModelError, IModelStatus, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\r\nimport { ECSqlStatement } from \"./ECSqlStatement\";\r\nimport { Entity } from \"./Entity\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\r\n\r\n/** Base class for all link table ECRelationships\r\n * @public\r\n */\r\nexport class Relationship extends Entity {\r\n public static override get className(): string { return \"Relationship\"; }\r\n public readonly sourceId: Id64String;\r\n public readonly targetId: Id64String;\r\n\r\n protected constructor(props: RelationshipProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.sourceId = Id64.fromJSON(props.sourceId);\r\n this.targetId = Id64.fromJSON(props.targetId);\r\n }\r\n\r\n public override toJSON(): RelationshipProps {\r\n const val = super.toJSON() as RelationshipProps;\r\n val.sourceId = this.sourceId;\r\n val.targetId = this.targetId;\r\n return val;\r\n }\r\n\r\n /**\r\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\r\n * This callback is invoked after the input element has been processed by upstream relationships.\r\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\r\n * @param _props The ElementDrivesElement relationship instance.\r\n * @param _iModel The iModel\r\n */\r\n public static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void { }\r\n\r\n /**\r\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\r\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\r\n * @param _props The deleted ElementDrivesElement relationship instance.\r\n * @param _iModel The iModel\r\n */\r\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\r\n\r\n /** Insert this Relationship into the iModel. */\r\n public insert(): Id64String { return this.id = this.iModel.relationships.insertInstance(this.toJSON()); }\r\n /** Update this Relationship in the iModel. */\r\n public update() { this.iModel.relationships.updateInstance(this.toJSON()); }\r\n /** Delete this Relationship from the iModel. */\r\n public delete() { this.iModel.relationships.deleteInstance(this.toJSON()); }\r\n\r\n public static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T { return iModel.relationships.getInstance(this.classFullName, criteria); }\r\n}\r\n\r\n/** A Relationship where one Element refers to another Element\r\n * @public\r\n */\r\nexport class ElementRefersToElements extends Relationship {\r\n public static override get className(): string { return \"ElementRefersToElements\"; }\r\n /** Create an instance of the Relationship.\r\n * @param iModel The iModel that will contain the relationship\r\n * @param sourceId The sourceId of the relationship, that is, the driver element\r\n * @param targetId The targetId of the relationship, that is, the driven element\r\n * @return an instance of the specified class.\r\n */\r\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): T {\r\n return iModel.relationships.createInstance({ sourceId, targetId, classFullName: this.classFullName }) as T;\r\n }\r\n /** Insert a new instance of the Relationship.\r\n * @param iModel The iModel that will contain the relationship\r\n * @param sourceId The sourceId of the relationship, that is, the driver element\r\n * @param targetId The targetId of the relationship, that is, the driven element\r\n * @return The Id of the inserted Relationship.\r\n */\r\n public static insert<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\r\n const relationship: T = this.create(iModel, sourceId, targetId);\r\n return iModel.relationships.insertInstance(relationship.toJSON());\r\n }\r\n\r\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\r\n super.collectReferenceIds(referenceIds);\r\n referenceIds.addElement(this.sourceId);\r\n referenceIds.addElement(this.targetId);\r\n }\r\n}\r\n\r\n/** Relates a [[DrawingGraphic]] to the [[Element]] that it represents\r\n * @public\r\n */\r\nexport class DrawingGraphicRepresentsElement extends ElementRefersToElements {\r\n public static override get className(): string { return \"DrawingGraphicRepresentsElement\"; }\r\n}\r\n\r\n/** Relates a [[GraphicalElement3d]] to the [[Element]] that it represents\r\n * @public\r\n */\r\nexport class GraphicalElement3dRepresentsElement extends ElementRefersToElements {\r\n public static override get className(): string { return \"GraphicalElement3dRepresentsElement\"; }\r\n}\r\n\r\n/** Relates a [[SynchronizationConfigLink]] to N [[ExternalSource]] instances.\r\n * Each relationship instance represents an external source processed by the synchronization configuration.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class SynchronizationConfigProcessesSources extends ElementRefersToElements {\r\n public static override get className(): string { return \"SynchronizationConfigProcessesSources\"; }\r\n}\r\n\r\n/** Relates a [[SynchronizationConfigLink]] to *root* [[ExternalSource]] instances.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class SynchronizationConfigSpecifiesRootSources extends SynchronizationConfigProcessesSources {\r\n public static override get className(): string { return \"SynchronizationConfigSpecifiesRootSources\"; }\r\n}\r\n\r\n/** Properties that are common to all types of link table ECRelationships\r\n * @public\r\n */\r\nexport interface ElementGroupsMembersProps extends RelationshipProps {\r\n memberPriority: number;\r\n}\r\n\r\n/** An ElementRefersToElements relationship where one Element *groups* a set of other Elements.\r\n * @public\r\n */\r\nexport class ElementGroupsMembers extends ElementRefersToElements {\r\n public static override get className(): string { return \"ElementGroupsMembers\"; }\r\n public memberPriority: number;\r\n\r\n constructor(props: ElementGroupsMembersProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.memberPriority = props.memberPriority;\r\n }\r\n\r\n public static override create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, memberPriority: number = 0): T {\r\n const props: ElementGroupsMembersProps = { sourceId, targetId, memberPriority, classFullName: this.classFullName };\r\n return iModel.relationships.createInstance(props) as T;\r\n }\r\n}\r\n\r\n/** Relates a [[DefinitionGroup]] to its [[DefinitionElement]] members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.10\r\n * @public\r\n */\r\nexport class DefinitionGroupGroupsDefinitions extends ElementGroupsMembers {\r\n public static override get className(): string { return \"DefinitionGroupGroupsDefinitions\"; }\r\n}\r\n\r\n/** Represents group membership where the group Element (and its properties) impart information about the member Elements above mere membership.\r\n * Implies that properties of the group should be considered as properties of its members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.11\r\n * @public\r\n */\r\nexport class GroupImpartsToMembers extends ElementGroupsMembers {\r\n public static override get className(): string { return \"GroupImpartsToMembers\"; }\r\n}\r\n\r\n/** Relates an [[ExternalSourceGroup]] to its [[ExternalSource]] members.\r\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\r\n * @beta\r\n */\r\nexport class ExternalSourceGroupGroupsSources extends ElementGroupsMembers {\r\n public static override get className(): string { return \"ExternalSourceGroupGroupsSources\"; }\r\n}\r\n\r\n/** Properties that are common to all types of ElementDrivesElements\r\n * @beta\r\n */\r\nexport interface ElementDrivesElementProps extends RelationshipProps {\r\n status: number;\r\n priority: number;\r\n}\r\n\r\n/** A Relationship indicating that one Element *drives* another Element.\r\n * An ElementDrivesElement relationship defines a one-way \"driving\" relationship from the source to the target.\r\n * When the source of an ElementDrivesElement relationship changes, the ElementDrivesElement itself can get a callback, and both the source and target elements can get callbacks.\r\n * By inserting ElementDrivesElement relationships, an app can create and store an acyclic directed graph of dependencies between elements.\r\n *\r\n * # Defining dependencies\r\n * Create an ElementDrivesElement relationship to specify that the source element drives the target element.\r\n * For example, to specify that element e1 drives element e2, create a relationship between them like this:\r\n * ```ts\r\n * const ede = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * ede.insert();\r\n * ```\r\n * This creates a persistent relationship. The fact that e1 drives e2 is persisted in the iModel.\r\n *\r\n * # Defining dependency graphs\r\n * When you create multiple ElementDrivesElement relationships, you create a network of dependencies. The target of one may be the source of another.\r\n * A change in the content of an DgnElement can therefore trigger changes to many downstream elements.\r\n *\r\n * For example, to make element e1 drive element e2 and e2 drive another element, e3, create two relationships like this:\r\n * ```ts\r\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\r\n * ede12.insert();\r\n * ede23.insert();\r\n * ```\r\n * Those two relationships create this graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n * Where the \"-->\" is meant to represent a driving relationship.\r\n *\r\n * The order in which you create the relationships does not matter.\r\n * The graph indicates that e3 depends on e2 and e2 depends on e1.\r\n *\r\n * An ElementDrivesElement relationship is between one source element and one target element.\r\n * Many ElementDrivesElement relationships can point to a given element, and many can point out of it.\r\n * Thus, you can define many:many relationships.\r\n * For example:\r\n * ```ts\r\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\r\n * const ede112 = ElementDrivesElement.create(iModel, e11id, e2id);\r\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\r\n * const ede231 = ElementDrivesElement.create(iModel, e2id, e31id);\r\n * ede12.insert();\r\n * ede112.insert();\r\n * ede23.insert();\r\n * ede231.insert();\r\n * ```\r\n * Creates this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * e2 depends on both e1 and e11. e2 then drives e3 and e31.\r\n *\r\n * In an ElementDrivesElement dependency graph, the relationships are the \"edges\" and the Elements are the \"nodes\".\r\n * The following terms are used when referring to the elements (nodes) in a dependency graph:\r\n * * Inputs - The sources of all edges that point to the element. This includes all upstream elements that flow into the element.\r\n * * Outputs - The targets of all edges that point out of the element. This includes all downstream elements.\r\n *\r\n * # Subgraph Processing\r\n * When changes are made, only the part of the overall graph that is affected will be processed. So, for example,\r\n * suppose we have this graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n * If e1 changes, then the subgraph to be processed is equal to the full graph, as shown.\r\n *\r\n * If only e2 changes, then the subgraph to be processed is just:\r\n * ```\r\n * e2 --> e3\r\n * ```\r\n * If only e3 changes, then the subgraph consists of e3 by itself.\r\n *\r\n * Returning to the second example above, suppose we have this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * If e1 is changed, the affected subgraph is:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * If e2 is changed, the affected subgraph is:\r\n * ```\r\n * e3\r\n * /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * # Callbacks\r\n * Once the affected subgraph to process is found, it propagates changes through it by making callbacks.\r\n * Classes for both elements (nodes) and ElementDrivesElements relationships (edges) can receive callbacks.\r\n *\r\n * ## ElementDrivesElement Callbacks\r\n * The following callbacks are invoked on ElementDrivesElement relationship classes (edges):\r\n * * onRootChanged\r\n * * onDeletedDependency\r\n *\r\n * Note that these are static methods. Their default implementations do nothing.\r\n * To receive and act on these callbacks, a domain should define a subclass of ElementDrivesElement and use that to create relationships.\r\n * The subclass should then implement the callbacks that it would like to act on.\r\n *\r\n * A ElementDrivesElement subclass callback is expected to make changes to the output element only!\r\n *\r\n * ## Element Callbacks\r\n * The following callbacks are invoked on Element classes (nodes):\r\n * * Element.onBeforeOutputsHandled\r\n * * Element.onAllInputsHandled\r\n *\r\n * ## Order\r\n * Callbacks are invoked by BriefcaseDb.saveChanges.\r\n * They are invoked in dependency (topological) order: driving elements first, then driven elements.\r\n *\r\n * Each callback is invoked only once. No matter how many times a given element was changed during the transaction,\r\n * a callback such as ElementDrivesElement.onRootChanged will be invoked only once.\r\n * In the same way, no matter how many of its inputs were changed, a callback such as Element.onAllInputsHandled will be\r\n * invoked only once.\r\n *\r\n * For example, suppose we have a graph:\r\n * ```\r\n * e1 --> e2 --> e3\r\n * ```\r\n *\r\n * Suppose that e1 is directly modified. No callbacks are made at that time.\r\n * Later, when BriefcaseDb.saveChanges is called, the following callbacks are made, in order:\r\n * 1. Element.onBeforeOutputsHandled e1\r\n * 1. ElementDrivesElement.onRootChanged e1->e2\r\n * 1. Element.onAllInputsHandled e2\r\n * 1. ElementDrivesElement.onRootChanged e2->e3\r\n * 1. Element.onAllInputsHandled e3\r\n *\r\n * Suppose that e3 is modified directly and BriefcaseDb.saveChanges is called.\r\n * Since no input to a relationship was changed, the sub-graph will be empty, and no callbacks will be made.\r\n *\r\n * Returning to the second example above, suppose we have this graph:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * / \\\r\n * e11 e31\r\n * ```\r\n * If e1 is changed and BriefcaseDb.saveChanges is called, the subgraph is:\r\n * ```\r\n * e1 e3\r\n * \\ /\r\n * e2\r\n * \\\r\n * e31\r\n * ```\r\n * The callbacks are:\r\n * 1. Element.onBeforeOutputsHandled e1\r\n * 1. ElementDrivesElement.onRootChanged e1->e2\r\n * 1. Element.onAllInputsHandled e2\r\n * 1. ElementDrivesElement.onRootChanged e2->e3\r\n * 1. Element.onAllInputsHandled e3\r\n * 1. ElementDrivesElement.onRootChanged e2->e31\r\n * 1. Element.onAllInputsHandled e31\r\n *\r\n * (The ElementDrivesElement.)\r\n *\r\n * #Errors\r\n * Circular dependencies are not permitted. If a cycle is detected, that is treated as a fatal error. All ElementDrivesElement relationships\r\n * involved in a cycle will have their status set to 1, indicating a failure.\r\n *\r\n * A callback may call txnManager.reportError to reject an invalid change. It can classify the error as fatal or just a warning.\r\n * A callback make set the status value of an ElementDrivesElement instance to 1 to indicate a processing failure in that edge.\r\n *\r\n * After BriefcaseDb.saveChanges is called, an app should check db.txns.validationErrors and db.txns.hasFatalError to find out if graph-evaluation failed.\r\n *\r\n * @beta\r\n */\r\nexport class ElementDrivesElement extends Relationship {\r\n public static override get className(): string { return \"ElementDrivesElement\"; }\r\n /** Relationship status\r\n * * 0 indicates no errors. Set after a successful evaluation.\r\n * * 1 indicates that this driving relationship could not be evaluated. The callback itself can set this to indicate that it failed to process the input changes. Also, it is set if the relationship is part of a circular dependency.\r\n * * 0x80 The app or callback can set this to indicate to not propagate changes through this relationship.\r\n */\r\n public status: number;\r\n /** Affects the order in which relationships are processed in the case where two relationships have the same output. */\r\n public priority: number;\r\n\r\n protected constructor(props: ElementDrivesElementProps, iModel: IModelDb) {\r\n super(props, iModel);\r\n this.status = props.status;\r\n this.priority = props.priority;\r\n }\r\n\r\n public static create<T extends ElementDrivesElement>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, priority: number = 0): T {\r\n const props: ElementDrivesElementProps = { sourceId, targetId, priority, status: 0, classFullName: this.classFullName };\r\n return iModel.relationships.createInstance(props) as T;\r\n }\r\n\r\n public override toJSON(): ElementDrivesElementProps {\r\n const props = super.toJSON() as ElementDrivesElementProps;\r\n props.status = this.status;\r\n props.priority = this.priority;\r\n return props;\r\n }\r\n\r\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\r\n super.collectReferenceIds(referenceIds);\r\n referenceIds.addElement(this.sourceId);\r\n referenceIds.addElement(this.targetId);\r\n }\r\n}\r\n\r\n/** The third (and last) possible link-table relationship base class in an iModel.\r\n * Has no external use, but is included for completeness of the [Entity.collectReferenceIds]($backend)\r\n * implementations for link-table relationships. Generating the types of the source and target automatically would require\r\n * coupling this package with ecschema-metadata which we do not want to do.\r\n * @internal\r\n */\r\nexport class ModelSelectorRefersToModels extends Relationship {\r\n public static override get className(): string { return \"ModelSelectorRefersToModels\"; }\r\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\r\n super.collectReferenceIds(referenceIds);\r\n referenceIds.addElement(this.sourceId);\r\n referenceIds.addModel(this.targetId);\r\n }\r\n}\r\n\r\n/** Manages [[Relationship]]s.\r\n * @public\r\n */\r\nexport class Relationships {\r\n private _iModel: IModelDb;\r\n\r\n /** @internal */\r\n public constructor(iModel: IModelDb) { this._iModel = iModel; }\r\n\r\n /** Create a new instance of a Relationship.\r\n * @param props The properties of the new Relationship.\r\n * @throws [[IModelError]] if there is a problem creating the Relationship.\r\n */\r\n public createInstance(props: RelationshipProps): Relationship { return this._iModel.constructEntity<Relationship>(props); }\r\n\r\n /** Check classFullName to ensure it is a link table relationship class. */\r\n private checkRelationshipClass(classFullName: string) {\r\n if (!this._iModel[_nativeDb].isLinkTableRelationship(classFullName.replace(\".\", \":\"))) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\r\n }\r\n }\r\n\r\n /** Insert a new relationship instance into the iModel. The relationship provided must be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.\r\n * @param props The properties of the new relationship.\r\n * @returns The Id of the newly inserted relationship.\r\n * @note The id property of the props object is set as a side effect of this function.\r\n */\r\n public insertInstance(props: RelationshipProps): Id64String {\r\n this.checkRelationshipClass(props.classFullName);\r\n return props.id = this._iModel[_nativeDb].insertLinkTableRelationship(props);\r\n }\r\n\r\n /** Update the properties of an existing relationship instance in the iModel.\r\n * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.\r\n */\r\n public updateInstance(props: RelationshipProps): void {\r\n this._iModel[_nativeDb].updateLinkTableRelationship(props);\r\n }\r\n\r\n /** Delete an Relationship instance from this iModel. */\r\n public deleteInstance(props: RelationshipProps): void {\r\n this._iModel[_nativeDb].deleteLinkTableRelationship(props);\r\n }\r\n\r\n /** Get the props of a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\r\n * @see tryGetInstanceProps\r\n */\r\n public getInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T {\r\n const relationshipProps = this.tryGetInstanceProps<T>(relClassFullName, criteria);\r\n if (undefined === relationshipProps) {\r\n throw new IModelError(IModelStatus.NotFound, \"Relationship not found\");\r\n }\r\n return relationshipProps;\r\n }\r\n\r\n /** Get the props of a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @returns The RelationshipProps or `undefined` if the relationship is not found.\r\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\r\n * @see getInstanceProps\r\n */\r\n public tryGetInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\r\n let props: T | undefined;\r\n if (typeof criteria === \"string\") {\r\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE ecinstanceid=?`, (stmt: ECSqlStatement) => {\r\n stmt.bindId(1, criteria);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\r\n });\r\n } else {\r\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE SourceECInstanceId=? AND TargetECInstanceId=?`, (stmt: ECSqlStatement) => {\r\n stmt.bindId(1, criteria.sourceId);\r\n stmt.bindId(2, criteria.targetId);\r\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\r\n });\r\n }\r\n if (undefined !== props) {\r\n props.classFullName = (props as any).className.replace(\".\", \":\");\r\n }\r\n return props;\r\n }\r\n\r\n /** Get a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\r\n * @see tryGetInstance\r\n */\r\n public getInstance<T extends Relationship>(relClassSqlName: string, criteria: Id64String | SourceAndTarget): T {\r\n return this._iModel.constructEntity<T>(this.getInstanceProps(relClassSqlName, criteria));\r\n }\r\n\r\n /** Get a Relationship instance\r\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\r\n * @param criteria Either the relationship instanceId or the source and target Ids\r\n * @returns The relationship or `undefined` if the relationship is not found.\r\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\r\n * @see getInstance\r\n */\r\n public tryGetInstance<T extends Relationship>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\r\n const relationshipProps = this.tryGetInstanceProps<RelationshipProps>(relClassFullName, criteria);\r\n return undefined !== relationshipProps ? this._iModel.constructEntity<T>(relationshipProps) : undefined;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Relationship.js","sourceRoot":"","sources":["../../src/Relationship.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAiE;AACjE,oDAAuH;AAEvH,qCAAkC;AAElC,gDAA+C;AAI/C;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IAC/B,MAAM,KAAc,SAAS,KAAa,OAAO,cAAc,CAAC,CAAC,CAAC;IAIzE,YAAsB,KAAwB,EAAE,MAAgB;QAC9D,KAAK,CAAC,KAAK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ACL,CAAC;QACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACxB,KAAK,CAAC,aAAa,GAAI,KAAa,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,WAAW,CAAyB,eAAuB,EAAE,QAAsC;QACxG,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAyB,gBAAwB,EAAE,QAAsC;QAC5G,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,CAAoB,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAClG,OAAO,SAAS,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1G,CAAC;CACF;AAvGD,sCAuGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Relationships\n */\n\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { EntityReferenceSet, IModelError, IModelStatus, RelationshipProps, SourceAndTarget } from \"@itwin/core-common\";\nimport { ECSqlStatement } from \"./ECSqlStatement\";\nimport { Entity } from \"./Entity\";\nimport { IModelDb } from \"./IModelDb\";\nimport { _nativeDb } from \"./internal/Symbols\";\n\nexport type { SourceAndTarget, RelationshipProps } from \"@itwin/core-common\"; // for backwards compatibility\n\n/** Base class for all link table ECRelationships\n * @public\n */\nexport class Relationship extends Entity {\n public static override get className(): string { return \"Relationship\"; }\n public readonly sourceId: Id64String;\n public readonly targetId: Id64String;\n\n protected constructor(props: RelationshipProps, iModel: IModelDb) {\n super(props, iModel);\n this.sourceId = Id64.fromJSON(props.sourceId);\n this.targetId = Id64.fromJSON(props.targetId);\n }\n\n public override toJSON(): RelationshipProps {\n const val = super.toJSON() as RelationshipProps;\n val.sourceId = this.sourceId;\n val.targetId = this.targetId;\n return val;\n }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when its input has changed or is the output of some upstream relationship whose input has changed.\n * This callback is invoked after the input element has been processed by upstream relationships.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action. onRootChanged may modify the output element only.\n * @param _props The ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n */\n public static onRootChanged(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /**\n * Callback invoked by saveChanges on an ElementDrivesElement relationship when the relationship instance has been deleted.\n * A subclass of ElementDrivesElement can re-implement this static method to take some action.\n * @param _props The deleted ElementDrivesElement relationship instance.\n * @param _iModel The iModel\n */\n public static onDeletedDependency(_props: RelationshipProps, _iModel: IModelDb): void { }\n\n /** Insert this Relationship into the iModel. */\n public insert(): Id64String { return this.id = this.iModel.relationships.insertInstance(this.toJSON()); }\n /** Update this Relationship in the iModel. */\n public update() { this.iModel.relationships.updateInstance(this.toJSON()); }\n /** Delete this Relationship from the iModel. */\n public delete() { this.iModel.relationships.deleteInstance(this.toJSON()); }\n\n public static getInstance<T extends Relationship>(iModel: IModelDb, criteria: Id64String | SourceAndTarget): T { return iModel.relationships.getInstance(this.classFullName, criteria); }\n}\n\n/** A Relationship where one Element refers to another Element\n * @public\n */\nexport class ElementRefersToElements extends Relationship {\n public static override get className(): string { return \"ElementRefersToElements\"; }\n /** Create an instance of the Relationship.\n * @param iModel The iModel that will contain the relationship\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return an instance of the specified class.\n */\n public static create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): T {\n return iModel.relationships.createInstance({ sourceId, targetId, classFullName: this.classFullName }) as T;\n }\n /** Insert a new instance of the Relationship.\n * @param iModel The iModel that will contain the relationship\n * @param sourceId The sourceId of the relationship, that is, the driver element\n * @param targetId The targetId of the relationship, that is, the driven element\n * @return The Id of the inserted Relationship.\n */\n public static insert<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String): Id64String {\n const relationship: T = this.create(iModel, sourceId, targetId);\n return iModel.relationships.insertInstance(relationship.toJSON());\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** Relates a [[DrawingGraphic]] to the [[Element]] that it represents\n * @public\n */\nexport class DrawingGraphicRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"DrawingGraphicRepresentsElement\"; }\n}\n\n/** Relates a [[GraphicalElement3d]] to the [[Element]] that it represents\n * @public\n */\nexport class GraphicalElement3dRepresentsElement extends ElementRefersToElements {\n public static override get className(): string { return \"GraphicalElement3dRepresentsElement\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to N [[ExternalSource]] instances.\n * Each relationship instance represents an external source processed by the synchronization configuration.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigProcessesSources extends ElementRefersToElements {\n public static override get className(): string { return \"SynchronizationConfigProcessesSources\"; }\n}\n\n/** Relates a [[SynchronizationConfigLink]] to *root* [[ExternalSource]] instances.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class SynchronizationConfigSpecifiesRootSources extends SynchronizationConfigProcessesSources {\n public static override get className(): string { return \"SynchronizationConfigSpecifiesRootSources\"; }\n}\n\n/** Properties that are common to all types of link table ECRelationships\n * @public\n */\nexport interface ElementGroupsMembersProps extends RelationshipProps {\n memberPriority: number;\n}\n\n/** An ElementRefersToElements relationship where one Element *groups* a set of other Elements.\n * @public\n */\nexport class ElementGroupsMembers extends ElementRefersToElements {\n public static override get className(): string { return \"ElementGroupsMembers\"; }\n public memberPriority: number;\n\n constructor(props: ElementGroupsMembersProps, iModel: IModelDb) {\n super(props, iModel);\n this.memberPriority = props.memberPriority;\n }\n\n public static override create<T extends ElementRefersToElements>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, memberPriority: number = 0): T {\n const props: ElementGroupsMembersProps = { sourceId, targetId, memberPriority, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n}\n\n/** Relates a [[DefinitionGroup]] to its [[DefinitionElement]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.10\n * @public\n */\nexport class DefinitionGroupGroupsDefinitions extends ElementGroupsMembers {\n public static override get className(): string { return \"DefinitionGroupGroupsDefinitions\"; }\n}\n\n/** Represents group membership where the group Element (and its properties) impart information about the member Elements above mere membership.\n * Implies that properties of the group should be considered as properties of its members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.11\n * @public\n */\nexport class GroupImpartsToMembers extends ElementGroupsMembers {\n public static override get className(): string { return \"GroupImpartsToMembers\"; }\n}\n\n/** Relates an [[ExternalSourceGroup]] to its [[ExternalSource]] members.\n * @note The associated ECClass was added to the BisCore schema in version 1.0.13\n * @beta\n */\nexport class ExternalSourceGroupGroupsSources extends ElementGroupsMembers {\n public static override get className(): string { return \"ExternalSourceGroupGroupsSources\"; }\n}\n\n/** Properties that are common to all types of ElementDrivesElements\n * @beta\n */\nexport interface ElementDrivesElementProps extends RelationshipProps {\n status: number;\n priority: number;\n}\n\n/** A Relationship indicating that one Element *drives* another Element.\n * An ElementDrivesElement relationship defines a one-way \"driving\" relationship from the source to the target.\n * When the source of an ElementDrivesElement relationship changes, the ElementDrivesElement itself can get a callback, and both the source and target elements can get callbacks.\n * By inserting ElementDrivesElement relationships, an app can create and store an acyclic directed graph of dependencies between elements.\n *\n * # Defining dependencies\n * Create an ElementDrivesElement relationship to specify that the source element drives the target element.\n * For example, to specify that element e1 drives element e2, create a relationship between them like this:\n * ```ts\n * const ede = ElementDrivesElement.create(iModel, e1id, e2id);\n * ede.insert();\n * ```\n * This creates a persistent relationship. The fact that e1 drives e2 is persisted in the iModel.\n *\n * # Defining dependency graphs\n * When you create multiple ElementDrivesElement relationships, you create a network of dependencies. The target of one may be the source of another.\n * A change in the content of an DgnElement can therefore trigger changes to many downstream elements.\n *\n * For example, to make element e1 drive element e2 and e2 drive another element, e3, create two relationships like this:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * ede12.insert();\n * ede23.insert();\n * ```\n * Those two relationships create this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * Where the \"-->\" is meant to represent a driving relationship.\n *\n * The order in which you create the relationships does not matter.\n * The graph indicates that e3 depends on e2 and e2 depends on e1.\n *\n * An ElementDrivesElement relationship is between one source element and one target element.\n * Many ElementDrivesElement relationships can point to a given element, and many can point out of it.\n * Thus, you can define many:many relationships.\n * For example:\n * ```ts\n * const ede12 = ElementDrivesElement.create(iModel, e1id, e2id);\n * const ede112 = ElementDrivesElement.create(iModel, e11id, e2id);\n * const ede23 = ElementDrivesElement.create(iModel, e2id, e3id);\n * const ede231 = ElementDrivesElement.create(iModel, e2id, e31id);\n * ede12.insert();\n * ede112.insert();\n * ede23.insert();\n * ede231.insert();\n * ```\n * Creates this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * e2 depends on both e1 and e11. e2 then drives e3 and e31.\n *\n * In an ElementDrivesElement dependency graph, the relationships are the \"edges\" and the Elements are the \"nodes\".\n * The following terms are used when referring to the elements (nodes) in a dependency graph:\n * * Inputs - The sources of all edges that point to the element. This includes all upstream elements that flow into the element.\n * * Outputs - The targets of all edges that point out of the element. This includes all downstream elements.\n *\n * # Subgraph Processing\n * When changes are made, only the part of the overall graph that is affected will be processed. So, for example,\n * suppose we have this graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n * If e1 changes, then the subgraph to be processed is equal to the full graph, as shown.\n *\n * If only e2 changes, then the subgraph to be processed is just:\n * ```\n * e2 --> e3\n * ```\n * If only e3 changes, then the subgraph consists of e3 by itself.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed, the affected subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * If e2 is changed, the affected subgraph is:\n * ```\n * e3\n * /\n * e2\n * \\\n * e31\n * ```\n * # Callbacks\n * Once the affected subgraph to process is found, it propagates changes through it by making callbacks.\n * Classes for both elements (nodes) and ElementDrivesElements relationships (edges) can receive callbacks.\n *\n * ## ElementDrivesElement Callbacks\n * The following callbacks are invoked on ElementDrivesElement relationship classes (edges):\n * * onRootChanged\n * * onDeletedDependency\n *\n * Note that these are static methods. Their default implementations do nothing.\n * To receive and act on these callbacks, a domain should define a subclass of ElementDrivesElement and use that to create relationships.\n * The subclass should then implement the callbacks that it would like to act on.\n *\n * A ElementDrivesElement subclass callback is expected to make changes to the output element only!\n *\n * ## Element Callbacks\n * The following callbacks are invoked on Element classes (nodes):\n * * Element.onBeforeOutputsHandled\n * * Element.onAllInputsHandled\n *\n * ## Order\n * Callbacks are invoked by BriefcaseDb.saveChanges.\n * They are invoked in dependency (topological) order: driving elements first, then driven elements.\n *\n * Each callback is invoked only once. No matter how many times a given element was changed during the transaction,\n * a callback such as ElementDrivesElement.onRootChanged will be invoked only once.\n * In the same way, no matter how many of its inputs were changed, a callback such as Element.onAllInputsHandled will be\n * invoked only once.\n *\n * For example, suppose we have a graph:\n * ```\n * e1 --> e2 --> e3\n * ```\n *\n * Suppose that e1 is directly modified. No callbacks are made at that time.\n * Later, when BriefcaseDb.saveChanges is called, the following callbacks are made, in order:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n *\n * Suppose that e3 is modified directly and BriefcaseDb.saveChanges is called.\n * Since no input to a relationship was changed, the sub-graph will be empty, and no callbacks will be made.\n *\n * Returning to the second example above, suppose we have this graph:\n * ```\n * e1 e3\n * \\ /\n * e2\n * / \\\n * e11 e31\n * ```\n * If e1 is changed and BriefcaseDb.saveChanges is called, the subgraph is:\n * ```\n * e1 e3\n * \\ /\n * e2\n * \\\n * e31\n * ```\n * The callbacks are:\n * 1. Element.onBeforeOutputsHandled e1\n * 1. ElementDrivesElement.onRootChanged e1->e2\n * 1. Element.onAllInputsHandled e2\n * 1. ElementDrivesElement.onRootChanged e2->e3\n * 1. Element.onAllInputsHandled e3\n * 1. ElementDrivesElement.onRootChanged e2->e31\n * 1. Element.onAllInputsHandled e31\n *\n * (The ElementDrivesElement.)\n *\n * #Errors\n * Circular dependencies are not permitted. If a cycle is detected, that is treated as a fatal error. All ElementDrivesElement relationships\n * involved in a cycle will have their status set to 1, indicating a failure.\n *\n * A callback may call txnManager.reportError to reject an invalid change. It can classify the error as fatal or just a warning.\n * A callback make set the status value of an ElementDrivesElement instance to 1 to indicate a processing failure in that edge.\n *\n * After BriefcaseDb.saveChanges is called, an app should check db.txns.validationErrors and db.txns.hasFatalError to find out if graph-evaluation failed.\n *\n * @beta\n */\nexport class ElementDrivesElement extends Relationship {\n public static override get className(): string { return \"ElementDrivesElement\"; }\n /** Relationship status\n * * 0 indicates no errors. Set after a successful evaluation.\n * * 1 indicates that this driving relationship could not be evaluated. The callback itself can set this to indicate that it failed to process the input changes. Also, it is set if the relationship is part of a circular dependency.\n * * 0x80 The app or callback can set this to indicate to not propagate changes through this relationship.\n */\n public status: number;\n /** Affects the order in which relationships are processed in the case where two relationships have the same output. */\n public priority: number;\n\n protected constructor(props: ElementDrivesElementProps, iModel: IModelDb) {\n super(props, iModel);\n this.status = props.status;\n this.priority = props.priority;\n }\n\n public static create<T extends ElementDrivesElement>(iModel: IModelDb, sourceId: Id64String, targetId: Id64String, priority: number = 0): T {\n const props: ElementDrivesElementProps = { sourceId, targetId, priority, status: 0, classFullName: this.classFullName };\n return iModel.relationships.createInstance(props) as T;\n }\n\n public override toJSON(): ElementDrivesElementProps {\n const props = super.toJSON() as ElementDrivesElementProps;\n props.status = this.status;\n props.priority = this.priority;\n return props;\n }\n\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addElement(this.targetId);\n }\n}\n\n/** The third (and last) possible link-table relationship base class in an iModel.\n * Has no external use, but is included for completeness of the [Entity.collectReferenceIds]($backend)\n * implementations for link-table relationships. Generating the types of the source and target automatically would require\n * coupling this package with ecschema-metadata which we do not want to do.\n * @internal\n */\nexport class ModelSelectorRefersToModels extends Relationship {\n public static override get className(): string { return \"ModelSelectorRefersToModels\"; }\n protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {\n super.collectReferenceIds(referenceIds);\n referenceIds.addElement(this.sourceId);\n referenceIds.addModel(this.targetId);\n }\n}\n\n/** Manages [[Relationship]]s.\n * @public\n */\nexport class Relationships {\n private _iModel: IModelDb;\n\n /** @internal */\n public constructor(iModel: IModelDb) { this._iModel = iModel; }\n\n /** Create a new instance of a Relationship.\n * @param props The properties of the new Relationship.\n * @throws [[IModelError]] if there is a problem creating the Relationship.\n */\n public createInstance(props: RelationshipProps): Relationship { return this._iModel.constructEntity<Relationship>(props); }\n\n /** Check classFullName to ensure it is a link table relationship class. */\n private checkRelationshipClass(classFullName: string) {\n if (!this._iModel[_nativeDb].isLinkTableRelationship(classFullName.replace(\".\", \":\"))) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Class '${classFullName}' must be a relationship class and it should be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.`);\n }\n }\n\n /** Insert a new relationship instance into the iModel. The relationship provided must be subclass of BisCore:ElementRefersToElements or BisCore:ElementDrivesElement.\n * @param props The properties of the new relationship.\n * @returns The Id of the newly inserted relationship.\n * @note The id property of the props object is set as a side effect of this function.\n */\n public insertInstance(props: RelationshipProps): Id64String {\n this.checkRelationshipClass(props.classFullName);\n return props.id = this._iModel[_nativeDb].insertLinkTableRelationship(props);\n }\n\n /** Update the properties of an existing relationship instance in the iModel.\n * @param props the properties of the relationship instance to update. Any properties that are not present will be left unchanged.\n */\n public updateInstance(props: RelationshipProps): void {\n this._iModel[_nativeDb].updateLinkTableRelationship(props);\n }\n\n /** Delete an Relationship instance from this iModel. */\n public deleteInstance(props: RelationshipProps): void {\n this._iModel[_nativeDb].deleteLinkTableRelationship(props);\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstanceProps\n */\n public getInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T {\n const relationshipProps = this.tryGetInstanceProps<T>(relClassFullName, criteria);\n if (undefined === relationshipProps) {\n throw new IModelError(IModelStatus.NotFound, \"Relationship not found\");\n }\n return relationshipProps;\n }\n\n /** Get the props of a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The RelationshipProps or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstanceProps\n */\n public tryGetInstanceProps<T extends RelationshipProps>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n let props: T | undefined;\n if (typeof criteria === \"string\") {\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE ecinstanceid=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n } else {\n props = this._iModel.withPreparedStatement(`SELECT * FROM ${relClassFullName} WHERE SourceECInstanceId=? AND TargetECInstanceId=?`, (stmt: ECSqlStatement) => {\n stmt.bindId(1, criteria.sourceId);\n stmt.bindId(2, criteria.targetId);\n return DbResult.BE_SQLITE_ROW === stmt.step() ? stmt.getRow() as T : undefined;\n });\n }\n if (undefined !== props) {\n props.classFullName = (props as any).className.replace(\".\", \":\");\n }\n return props;\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @throws [IModelError]($common) if the relationship is not found or cannot be loaded.\n * @see tryGetInstance\n */\n public getInstance<T extends Relationship>(relClassSqlName: string, criteria: Id64String | SourceAndTarget): T {\n return this._iModel.constructEntity<T>(this.getInstanceProps(relClassSqlName, criteria));\n }\n\n /** Get a Relationship instance\n * @param relClassFullName The full class name of the relationship in the form of \"schema:class\"\n * @param criteria Either the relationship instanceId or the source and target Ids\n * @returns The relationship or `undefined` if the relationship is not found.\n * @note Useful for cases when a relationship may or may not exist and throwing an `Error` would be overkill.\n * @see getInstance\n */\n public tryGetInstance<T extends Relationship>(relClassFullName: string, criteria: Id64String | SourceAndTarget): T | undefined {\n const relationshipProps = this.tryGetInstanceProps<RelationshipProps>(relClassFullName, criteria);\n return undefined !== relationshipProps ? this._iModel.constructEntity<T>(relationshipProps) : undefined;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RpcBackend.js","sourceRoot":"","sources":["../../src/RpcBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAAsF;AACtF,+CAAsG;AACtG,2CAAkD;AAClD,+CAA4D;AAC5D,+CAAiD;AACjD,iDAAkD;AAElD,4CAA4C;AAE5C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,gBAAgB;AAChB,SAAgB,oBAAoB,CAAC,sBAA+B,KAAK;IACvE,IAAI,WAAW;QACb,OAAO;IAET,IAAA,2BAAiB,EAAC,mBAAmB,CAAC,CAAC;IAEvC,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAC3D,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAC3D,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAE3D,8BAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,uBAAY,CAAC;IACrD,8BAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,sBAAY,CAAC;IAErD,8BAAgB,CAAC,iBAAiB,CAAC,IAAI,iCAAuB,EAAE,CAAC,CAAC;IAElE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAhBD,oDAgBC","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 { RpcMultipart, WebAppRpcLogging, WebAppRpcRequest } from \"@itwin/core-common\";\r\nimport { appendToMultipartForm, createMultipartStream, parseMultipartRequest } from \"./rpc/multipart\";\r\nimport { initializeTracing } from \"./rpc/tracing\";\r\nimport { WebAppRpcLoggingBackend } from \"./rpc/web/logging\";\r\nimport { parseRequest } from \"./rpc/web/request\";\r\nimport { sendResponse } from \"./rpc/web/response\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nlet initialized = false;\r\n/** @internal */\r\nexport function initializeRpcBackend(enableOpenTelemetry: boolean = false) {\r\n if (initialized)\r\n return;\r\n\r\n initializeTracing(enableOpenTelemetry);\r\n\r\n RpcMultipart.platform.createStream = createMultipartStream;\r\n RpcMultipart.platform.parseRequest = parseMultipartRequest;\r\n RpcMultipart.platform.appendToForm = appendToMultipartForm;\r\n\r\n WebAppRpcRequest.backend.sendResponse = sendResponse;\r\n WebAppRpcRequest.backend.parseRequest = parseRequest;\r\n\r\n WebAppRpcLogging.initializeBackend(new WebAppRpcLoggingBackend());\r\n\r\n initialized = true;\r\n}\r\n"]}
1
+ {"version":3,"file":"RpcBackend.js","sourceRoot":"","sources":["../../src/RpcBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAAsF;AACtF,+CAAsG;AACtG,2CAAkD;AAClD,+CAA4D;AAC5D,+CAAiD;AACjD,iDAAkD;AAElD,4CAA4C;AAE5C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,gBAAgB;AAChB,SAAgB,oBAAoB,CAAC,sBAA+B,KAAK;IACvE,IAAI,WAAW;QACb,OAAO;IAET,IAAA,2BAAiB,EAAC,mBAAmB,CAAC,CAAC;IAEvC,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAC3D,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAC3D,0BAAY,CAAC,QAAQ,CAAC,YAAY,GAAG,iCAAqB,CAAC;IAE3D,8BAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,uBAAY,CAAC;IACrD,8BAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,sBAAY,CAAC;IAErD,8BAAgB,CAAC,iBAAiB,CAAC,IAAI,iCAAuB,EAAE,CAAC,CAAC;IAElE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAhBD,oDAgBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module RpcInterface\n */\n\nimport { RpcMultipart, WebAppRpcLogging, WebAppRpcRequest } from \"@itwin/core-common\";\nimport { appendToMultipartForm, createMultipartStream, parseMultipartRequest } from \"./rpc/multipart\";\nimport { initializeTracing } from \"./rpc/tracing\";\nimport { WebAppRpcLoggingBackend } from \"./rpc/web/logging\";\nimport { parseRequest } from \"./rpc/web/request\";\nimport { sendResponse } from \"./rpc/web/response\";\n\n/* eslint-disable deprecation/deprecation */\n\nlet initialized = false;\n/** @internal */\nexport function initializeRpcBackend(enableOpenTelemetry: boolean = false) {\n if (initialized)\n return;\n\n initializeTracing(enableOpenTelemetry);\n\n RpcMultipart.platform.createStream = createMultipartStream;\n RpcMultipart.platform.parseRequest = parseMultipartRequest;\n RpcMultipart.platform.appendToForm = appendToMultipartForm;\n\n WebAppRpcRequest.backend.sendResponse = sendResponse;\n WebAppRpcRequest.backend.parseRequest = parseRequest;\n\n WebAppRpcLogging.initializeBackend(new WebAppRpcLoggingBackend());\n\n initialized = true;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,iCAAiC;AAEjC,sDAAyD;AAEzD,+CAA4C;AAC5C,8DAAyD;AACzD,6CAA0C;AAC1C,uDAAoE;AACpE,gDAA+C;AAE/C,0CAA0C;AAE1C,0DAA0D;AAE1D;;;GAGG;AACH,MAAa,QAAQ;IAArB;QAME,gBAAgB;QACA,QAAW,GAAG,IAAI,6BAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC3D,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;IAmOxE,CAAC;IA1OC;;OAEG;IACH,IAAW,QAAQ,KAA8B,OAAO,IAAI,CAAC,mBAAS,CAAC,CAAC,CAAC,CAAC;IAM1E,gBAAgB;IACT,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,6BAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAQM,QAAQ,CAAC,MAAc,EAAE,SAAsC,EAAE,MAA8B;QACpG,IAAI,CAAC,mBAAS,CA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,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,GAAuH;QAChJ,2EAA2E;QAC3E,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;YAC1B,KAAK,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,aAAa,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;YACpG,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,uBAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC;;AA7FH,8CA8FC;AA7FkB,+BAAa,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AA+FxF,cAAc;AACd,WAAiB,QAAQ;IAqEvB;;OAEG;IACH,IAAY,cASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjIgB,QAAQ,wBAAR,QAAQ,QAiIxB","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 SQLiteDb\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport { dirname } from \"path\";\r\nimport * as semver from \"semver\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n// cspell:ignore savepoint julianday rowid\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/**\r\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\r\n * @public\r\n */\r\nexport class SQLiteDb {\r\n /** @internal\r\n * @deprecated in 4.8. This internal API will be removed in 5.0. Use SQLiteDb's public API instead.\r\n */\r\n public get nativeDb(): IModelJsNative.SQLiteDb { return this[_nativeDb]; }\r\n\r\n /** @internal */\r\n public readonly [_nativeDb] = new IModelNative.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelNative.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb.\r\n * @deprecated in 4.0, use [[closeDb]]\r\n */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this[_nativeDb].createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\r\n this[_nativeDb].openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this[_nativeDb].closeDb();\r\n }\r\n\r\n /** Returns true if this SQLiteDb is open */\r\n public get isOpen(): boolean { return this[_nativeDb].isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this[_nativeDb].isReadonly(); }\r\n\r\n /** Create a new table in this database. */\r\n protected createTable(args: {\r\n /** The name of the table to create. */\r\n tableName: string;\r\n /** all of the columns in the table. */\r\n columns: string;\r\n /** any unique or foreign key constraints */\r\n constraints?: string;\r\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\r\n addTimestamp?: boolean;\r\n }) {\r\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\r\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\r\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\r\n if (args.addTimestamp)\r\n this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);\r\n }\r\n\r\n /**\r\n * Get the last modified date for a row in a table of this database.\r\n * @note the table must have been created with `addTimestamp: true`\r\n */\r\n public readLastModTime(tableName: string, rowId: number): Date {\r\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\r\n stmt.bindInteger(1, rowId);\r\n return stmt.getValueDate(0);\r\n });\r\n }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\r\n return CloudSqlite.withWriteLock(args, async () => this.withOpenDb({ ...args, openMode: args.openMode ?? OpenMode.ReadWrite }, operation));\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\r\n this[_nativeDb].vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\r\n public saveChanges(): void {\r\n this[_nativeDb].saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\r\n public abandonChanges(): void {\r\n this[_nativeDb].abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this[_nativeDb], logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\r\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\r\n * always used for access.\r\n *\r\n * Notes:\r\n * - This class may be used either to access a local file, or one stored in a cloud container.\r\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\r\n * tables.\r\n * @beta\r\n */\r\nexport abstract class VersionedSqliteDb extends SQLiteDb {\r\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\r\n\r\n /** The current semver \"persistence version\" of this class.\r\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\r\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\r\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\r\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\r\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\r\n * supported by it, the user will be informed that they need to upgrade their software.\r\n * @note this identifier is independent of versions in `package.json` files.\r\n */\r\n public abstract myVersion: string;\r\n\r\n /**\r\n * Change the \"versions required to open this database\" property stored in this database. After this call,\r\n * versions of software that don't meet the supplied ranges will fail.\r\n * @param versions the new versions required for reading and writing this database.\r\n * @note the database must be opened for write access.\r\n */\r\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\r\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\r\n this[_nativeDb].saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\r\n }\r\n\r\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\r\n public getRequiredVersions() {\r\n const checkIsString = (value: any) => {\r\n if (typeof value !== \"string\")\r\n throw new Error(`CloudDb ${this[_nativeDb].getFilePath()} has invalid \"versions\" property`);\r\n return value;\r\n };\r\n const versionJson = checkIsString(this[_nativeDb].queryFileProperty(VersionedSqliteDb._versionProps, true));\r\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\r\n checkIsString(versionRanges.readVersion);\r\n checkIsString(versionRanges.writeVersion);\r\n return versionRanges;\r\n }\r\n\r\n /**\r\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\r\n */\r\n protected abstract createDDL(args: any): void;\r\n\r\n /**\r\n * Create a new database file for the subclass of VersionedSqliteDb.\r\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\r\n */\r\n public static createNewDb(fileName: LocalFileName, setupArgs?: any) {\r\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\r\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\r\n if (fs.existsSync(fileName))\r\n fs.unlinkSync(fileName);\r\n\r\n db.createDb(fileName);\r\n db.createDDL(setupArgs);\r\n const minVer = `^${db.myVersion}`;\r\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\r\n db.closeDb(true);\r\n }\r\n\r\n /**\r\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n */\r\n protected verifyVersions() {\r\n const versions = this.getRequiredVersions();\r\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\r\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\r\n if (semver.satisfies(this.myVersion, range))\r\n return;\r\n\r\n this.closeDb();\r\n const tooNew = semver.gtr(this.myVersion, range);\r\n throw new Error(`${this[_nativeDb].getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\r\n\r\n }\r\n\r\n /**\r\n * Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\r\n * Throws otherwise.\r\n * @see [[SqliteDb.openDb]] for argument types\r\n */\r\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\r\n super.openDb(dbName, openMode, container);\r\n this.verifyVersions();\r\n }\r\n\r\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }) {\r\n // can't use \"this\" because it checks for version, which we don't want here\r\n return (arg.lockContainer) ?\r\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\r\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A semver version range.\r\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\r\n */\r\n export type VersionRange = string;\r\n\r\n /**\r\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\r\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\r\n */\r\n export interface RequiredVersionRanges {\r\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\r\n readonly readVersion: VersionRange;\r\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\r\n readonly writeVersion: VersionRange;\r\n }\r\n\r\n /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,iCAAiC;AAEjC,sDAAyD;AAEzD,+CAA4C;AAC5C,8DAAyD;AACzD,6CAA0C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AAQ;IAqEvB;;OAEG;IACH,IAAY,cASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjIgB,QAAQ,wBAAR,QAAQ,QAiIxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLiteDb\n */\n\nimport * as fs from \"fs\";\nimport { dirname } from \"path\";\nimport * as semver from \"semver\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\nimport { LocalFileName } from \"@itwin/core-common\";\nimport { CloudSqlite } from \"./CloudSqlite\";\nimport { IModelNative } from \"./internal/NativePlatform\";\nimport { IModelJsFs } from \"./IModelJsFs\";\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\nimport { _nativeDb } from \"./internal/Symbols\";\n\n// cspell:ignore savepoint julianday rowid\n\n/* eslint-disable @typescript-eslint/unified-signatures */\n\n/**\n * A \"generic\" SQLiteDb. This class may be used to access local files or databases in a cloud container.\n * @public\n */\nexport class SQLiteDb {\n /** @internal\n * @deprecated in 4.8. This internal API will be removed in 5.0. Use SQLiteDb's public API instead.\n */\n public get nativeDb(): IModelJsNative.SQLiteDb { return this[_nativeDb]; }\n\n /** @internal */\n public readonly [_nativeDb] = new IModelNative.platform.SQLiteDb();\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\n\n /** @internal */\n public static createBlobIO(): SQLiteDb.BlobIO {\n return new IModelNative.platform.BlobIO();\n }\n\n /** alias for closeDb.\n * @deprecated in 4.0, use [[closeDb]]\n */\n public dispose(): void {\n this.closeDb();\n }\n\n /** Create a SQLiteDb\n * @param dbName The path to the SQLiteDb file to create.\n */\n public createDb(dbName: string): void;\n /** @beta */\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\n this[_nativeDb].createDb(dbName, container, params);\n }\n\n /** Open a SQLiteDb.\n * @param dbName The path to the SQLiteDb file to open\n */\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\n /**\n * @param container optional CloudContainer holding database\n * @beta\n */\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\n this[_nativeDb].openDb(dbName, openMode, container);\n }\n\n /** Close SQLiteDb.\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\n */\n public closeDb(saveChanges?: boolean): void {\n if (saveChanges && this.isOpen)\n this.saveChanges();\n this._sqliteStatementCache.clear();\n this[_nativeDb].closeDb();\n }\n\n /** Returns true if this SQLiteDb is open */\n public get isOpen(): boolean { return this[_nativeDb].isOpen(); }\n\n /** Returns true if this SQLiteDb is open readonly */\n public get isReadonly(): boolean { return this[_nativeDb].isReadonly(); }\n\n /** Create a new table in this database. */\n protected createTable(args: {\n /** The name of the table to create. */\n tableName: string;\n /** all of the columns in the table. */\n columns: string;\n /** any unique or foreign key constraints */\n constraints?: string;\n /** if true, add a \"lastMod\" timestamp column and triggers to automatically update it. */\n addTimestamp?: boolean;\n }) {\n const timestampCol = args.addTimestamp ? \",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))\" : \"\";\n const constraints = args.constraints ? `,${args.constraints}` : \"\";\n this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);\n if (args.addTimestamp)\n this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);\n }\n\n /**\n * Get the last modified date for a row in a table of this database.\n * @note the table must have been created with `addTimestamp: true`\n */\n public readLastModTime(tableName: string, rowId: number): Date {\n return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {\n stmt.bindInteger(1, rowId);\n return stmt.getValueDate(0);\n });\n }\n\n /**\n * Open a database, perform an operation, then close the database.\n *\n * Details:\n * - if database is open, throw an error\n * - open a database\n * - call a function with the database opened. If it is async, await its return.\n * - if function throws, abandon all changes, close database, and rethrow\n * - save all changes\n * - close the database\n * @return value from operation\n */\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\n if (this.isOpen)\n throw new Error(\"database is already open\");\n\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\n try {\n const result = operation();\n result instanceof Promise ? result.then(save, abandon) : save();\n return result;\n } catch (e) {\n abandon();\n throw e;\n }\n }\n\n /**\n * Perform an operation on a database in a CloudContainer with the write lock held.\n *\n * Details:\n * - acquire the write lock on a CloudContainer\n * - call `withOpenDb` with openMode `ReadWrite`\n * - upload changes\n * - release the write lock\n * @param args arguments to lock the container and open the database\n * @param operation an operation performed on the database with the write lock held.\n * @return value from operation\n * @internal\n */\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => Promise<T>) {\n return CloudSqlite.withWriteLock(args, async () => this.withOpenDb({ ...args, openMode: args.openMode ?? OpenMode.ReadWrite }, operation));\n }\n\n /** vacuum this database\n * @see https://www.sqlite.org/lang_vacuum.html\n */\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\n this[_nativeDb].vacuum(args);\n }\n\n /** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */\n public saveChanges(): void {\n this[_nativeDb].saveChanges();\n }\n\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */\n public abandonChanges(): void {\n this[_nativeDb].abandonChanges();\n }\n\n /**\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\n * @param sql The SQLite SQL statement to execute\n * @param callback the callback to invoke on the prepared statement\n * @returns the value returned by `callback`.\n */\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\n try {\n const val = callback(stmt);\n val instanceof Promise ? val.then(release, release) : release();\n return val;\n } catch (err) {\n release();\n throw err;\n }\n }\n\n /**\n * Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\n * @param sql The SQLite SQL statement to execute\n * @param callback the callback to invoke on the prepared statement\n * @returns the value returned by `callback`.\n */\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\n const stmt = this.prepareSqliteStatement(sql);\n const release = () => stmt.dispose();\n try {\n const val = callback(stmt);\n val instanceof Promise ? val.then(release, release) : release();\n return val;\n } catch (err) {\n release();\n throw err;\n }\n }\n\n /**\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\n */\n public withSavePoint(savePointName: string, operation: () => void) {\n if (this.isReadonly)\n throw new Error(\"database is readonly\");\n\n this.executeSQL(`SAVEPOINT ${savePointName}`);\n try {\n operation();\n this.executeSQL(`RELEASE ${savePointName}`);\n } catch (e) {\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\n throw e;\n }\n }\n\n /** Prepare an SQL statement.\n * @param sql The SQLite SQL statement to prepare\n * @param logErrors Determine if errors are logged or not\n * @internal\n */\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\n const stmt = new SqliteStatement(sql);\n stmt.prepare(this[_nativeDb], logErrors);\n return stmt;\n }\n\n /** execute an SQL statement */\n public executeSQL(sql: string): DbResult {\n const stmt = this.prepareSqliteStatement(sql);\n try {\n return stmt.step();\n } finally {\n stmt.dispose();\n }\n }\n}\n\n/**\n * Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.\n * This class provides version checking when the database is opened, to guarantee that a valid version of software is\n * always used for access.\n *\n * Notes:\n * - This class may be used either to access a local file, or one stored in a cloud container.\n * - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its\n * tables.\n * @beta\n */\nexport abstract class VersionedSqliteDb extends SQLiteDb {\n protected static _versionProps = { namespace: \"SQLiteDb\", name: \"versions\" } as const;\n\n /** The current semver \"persistence version\" of this class.\n * @note This value should only be changed when logic in its code is modified in a way that affects the operation of extant copies.\n * If this value is outside of the range of accepted versions of a to-be-opened VersionedSqliteDb, the operation will fail. In this manner, if\n * changes are made to the format of a VersionedSqliteDb, or if bug fixes are necessary, the `requiredVersions` property in a VersionedSqliteDb may be updated\n * and immediately old versions of the package will refuse to open the VersionedSqliteDb, with a message to the user that they need to upgrade their\n * software. Likewise, if a new version of the package is asked to open an older VersionedSqliteDb that has not been upgraded to the lowest version\n * supported by it, the user will be informed that they need to upgrade their software.\n * @note this identifier is independent of versions in `package.json` files.\n */\n public abstract myVersion: string;\n\n /**\n * Change the \"versions required to open this database\" property stored in this database. After this call,\n * versions of software that don't meet the supplied ranges will fail.\n * @param versions the new versions required for reading and writing this database.\n * @note the database must be opened for write access.\n */\n public setRequiredVersions(versions: SQLiteDb.RequiredVersionRanges) {\n // NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.\n this[_nativeDb].saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));\n }\n\n /** Get the required version ranges necessary to open this VersionedSqliteDb. */\n public getRequiredVersions() {\n const checkIsString = (value: any) => {\n if (typeof value !== \"string\")\n throw new Error(`CloudDb ${this[_nativeDb].getFilePath()} has invalid \"versions\" property`);\n return value;\n };\n const versionJson = checkIsString(this[_nativeDb].queryFileProperty(VersionedSqliteDb._versionProps, true));\n const versionRanges = JSON.parse(versionJson) as SQLiteDb.RequiredVersionRanges;\n checkIsString(versionRanges.readVersion);\n checkIsString(versionRanges.writeVersion);\n return versionRanges;\n }\n\n /**\n * Implement this method to create all tables for this subclass of `VersionedSqliteDb` when a new database file is created. Called from [[createNewDb]].\n */\n protected abstract createDDL(args: any): void;\n\n /**\n * Create a new database file for the subclass of VersionedSqliteDb.\n * @note The required versions are saved as [[myVersion]] or newer for both read and write.\n */\n public static createNewDb(fileName: LocalFileName, setupArgs?: any) {\n const db = new (this as any)() as VersionedSqliteDb; // \"as any\" necessary because VersionedSqliteDb is abstract\n IModelJsFs.recursiveMkDirSync(dirname(fileName));\n if (fs.existsSync(fileName))\n fs.unlinkSync(fileName);\n\n db.createDb(fileName);\n db.createDDL(setupArgs);\n const minVer = `^${db.myVersion}`;\n db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });\n db.closeDb(true);\n }\n\n /**\n * Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\n * Throws otherwise.\n */\n protected verifyVersions() {\n const versions = this.getRequiredVersions();\n const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.\n const range = isReadonly ? versions.readVersion : versions.writeVersion;\n if (semver.satisfies(this.myVersion, range))\n return;\n\n this.closeDb();\n const tooNew = semver.gtr(this.myVersion, range);\n throw new Error(`${this[_nativeDb].getFilePath()} requires ${tooNew ? \"older\" : \"newer\"} version of ${this.constructor.name} for ${isReadonly ? \"read\" : \"write\"}`);\n\n }\n\n /**\n * Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.\n * Throws otherwise.\n * @see [[SqliteDb.openDb]] for argument types\n */\n public override openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer) {\n super.openDb(dbName, openMode, container);\n this.verifyVersions();\n }\n\n public async upgradeSchema(arg: { dbName: string, lockContainer?: { container: CloudSqlite.CloudContainer, user: string }, upgradeFn: () => void }) {\n // can't use \"this\" because it checks for version, which we don't want here\n return (arg.lockContainer) ?\n super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :\n super.withOpenDb({ ...arg, openMode: OpenMode.ReadWrite }, arg.upgradeFn);\n }\n}\n\n/** @public */\nexport namespace SQLiteDb {\n /** A semver version range.\n * @see https://docs.npmjs.com/cli/v6/using-npm/semver\n */\n export type VersionRange = string;\n\n /**\n * A pair of semver [[SQLiteDb.VersionRange]]s, one for read and one for write, required to access a [[VersionedSqliteDb]].\n * If the version of the software attempting to read or write the database does not satisfy the range, access is denied.\n */\n export interface RequiredVersionRanges {\n /** a range of acceptable persistence versions for reading from a VersionedSqliteDb. */\n readonly readVersion: VersionRange;\n /** a range of acceptable persistence versions for writing to a VersionedSqliteDb. */\n readonly writeVersion: VersionRange;\n }\n\n /** interface for reading and writing to a blob in a SQLiteDb\n * @internal\n */\n export interface BlobIO {\n /** Close this BlobIO if it is opened.\n * @note this BlobIO *may* be reused after this call by calling `open` again.\n */\n close(): void;\n /** get the total number of bytes in the blob */\n getNumBytes(): number;\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\n isValid(): boolean;\n /** Open this BlobIO against a table/row/column in a Db */\n open(\n /** The database for the blob */\n db: IModelJsNative.AnyDb,\n args: {\n /** the name of the table for the blob*/\n tableName: string;\n /** the name of the column for the blob */\n columnName: string;\n /** The rowId of the blob */\n row: number;\n /** If true, open this BlobIO for write access */\n writeable?: boolean;\n }): void;\n /** Read from a blob\n * @returns the contents of the requested byte range\n */\n read(args: {\n /** The number of bytes to read */\n numBytes: number;\n /** starting offset within the blob to read */\n offset: number;\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\n blob?: ArrayBuffer;\n }): Uint8Array;\n /** Reposition this BlobIO to a new rowId\n * @note this BlobIO must be valid when this methods is called.\n */\n changeRow(row: number): void;\n /** Write to a blob */\n write(args: {\n /** The number of bytes to write */\n numBytes: number;\n /** starting offset within the blob to write */\n offset: number;\n /** the value to write */\n blob: ArrayBuffer;\n }): void;\n }\n\n /** Default transaction mode for SQLiteDbs.\n * @see https://www.sqlite.org/lang_transaction.html\n */\n export enum DefaultTxnMode {\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\n None = 0,\n /** A deferred transaction is started when the file is first opened. This is the default. */\n Deferred = 1,\n /** An immediate transaction is started when the file is first opened. */\n Immediate = 2,\n /** An exclusive transaction is started when the file is first opened. */\n Exclusive = 3\n }\n\n /** parameters common to opening or creating a new SQLiteDb */\n export interface OpenOrCreateParams {\n /** If true, do not require that the `be_Prop` table exist */\n rawSQLite?: boolean;\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\n immutable?: boolean;\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\n skipFileCheck?: boolean;\n /** the default transaction mode\n * @see [[SQLiteDb.DefaultTxnMode]]\n */\n defaultTxn?: 0 | 1 | 2 | 3;\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\n queryParam?: string;\n }\n\n /** Parameters for opening an existing SQLiteDb */\n export interface OpenParams extends OpenOrCreateParams {\n /** use OpenMode.ReadWrite to open the file with write access */\n openMode: OpenMode;\n }\n\n /** Size of a SQLiteDb page in bytes */\n export interface PageSize {\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\n pageSize?: number;\n }\n\n /** Parameters for creating a new SQLiteDb */\n export type CreateParams = OpenOrCreateParams & PageSize;\n\n /** Arguments for `SqliteDb.withOpenDb` */\n export interface WithOpenDbArgs {\n /** The name of the database to open */\n dbName: string;\n /** either an object with the open parameters or just OpenMode value. */\n openMode?: OpenMode | SQLiteDb.OpenParams;\n /** @internal */\n container?: CloudSqlite.CloudContainer;\n }\n\n /** Arguments for `SQLiteDb.vacuum` */\n export interface VacuumDbArgs extends PageSize {\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\n into?: LocalFileName;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,oDAAiD;AACjD,mDAAgD;AAEhD;;GAEG;AACH,MAAa,MAAM;IACjB;;;;OAIG;IACI,MAAM,KAAK,UAAU,KAAa,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAElH;;;OAGG;IACI,MAAM,KAAK,uBAAuB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtE;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,aAAqB;QAChD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QAC1C,IAAI,cAAc;YAChB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,qCAAqC;QAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,gBAA0B,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;CAC/G;AAlCD,wBAkCC;AAED;;GAEG;AACH,MAAa,OAAO;IAElB,gBAAwB,CAAC,CAAC,sBAAsB;IAEhD;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,MAAqB;QAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC;YAC/B,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,aAAa,EAAE,WAAW,MAAM,CAAC,UAAU,yBAAyB,CAAC,CAAC;QAC3G,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,gBAAgB,CAAC,UAAkB;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACpD,IAAI,SAAS,KAAK,MAAM;YACtB,6BAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,mBAAmB,CAAC,UAAkB,IAA+B,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;;AA/BpJ,0BAgCC;AA/ByB,0BAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC","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 Schema\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ClassRegistry } from \"./ClassRegistry\";\r\n\r\n/** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).\r\n * @public\r\n */\r\nexport class Schema {\r\n /** The name of the BIS schema handled by this Schema.\r\n * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.\r\n * Failure to do so will ordinarily result in an error when the schema is registered, since there may only\r\n * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)\r\n */\r\n public static get schemaName(): string { throw new Error(`you must override static schemaName in ${this.name}`); }\r\n\r\n /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.\r\n * Classes generated for this Schema will disallow protected operations.\r\n * @internal\r\n */\r\n public static get missingRequiredBehavior(): boolean { return false; }\r\n\r\n /** Get a semver-compatible string from a padded version string.\r\n * works on unpadded version strings as well\r\n * if there is no write version, it will be added\r\n * @example Schema.toSemverString(\"1.02.03\") === \"1.2.3\"\r\n * @example Schema.toSemverString(\"1.01\") === \"1.0.1\" // write version was added\r\n * @beta\r\n */\r\n public static toSemverString(paddedVersion: string): string {\r\n const tuple = paddedVersion.split(\".\").map(Number);\r\n const noWriteVersion = tuple.length === 2;\r\n if (noWriteVersion)\r\n tuple.splice(1, 0, 0); // insert 0 before the second element\r\n return tuple.join(\".\");\r\n }\r\n\r\n /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an\r\n * error if it is ever called.\r\n * @internal\r\n */\r\n protected constructor() { throw new Error(`cannot create an instance of a Schema ${this.constructor.name}`); }\r\n}\r\n\r\n/** Manages registered schemas\r\n * @public\r\n */\r\nexport class Schemas {\r\n private static readonly _registeredSchemas = new Map<string, typeof Schema>();\r\n private constructor() { } // this is a singleton\r\n\r\n /** Register a schema prior to using it.\r\n * @throws [[IModelError]] if a schema of the same name is already registered.\r\n */\r\n public static registerSchema(schema: typeof Schema) {\r\n const key = schema.schemaName.toLowerCase();\r\n if (this.getRegisteredSchema(key))\r\n throw new IModelError(IModelStatus.DuplicateName, `Schema \"${schema.schemaName}\" is already registered`);\r\n this._registeredSchemas.set(key, schema);\r\n }\r\n\r\n /** Unregister a schema, by name, if one is already registered.\r\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\r\n * @param schemaName Name of the schema to unregister\r\n * @return true if the schema was unregistered\r\n */\r\n public static unregisterSchema(schemaName: string): boolean {\r\n const schema = this.getRegisteredSchema(schemaName);\r\n if (undefined !== schema)\r\n ClassRegistry.unregisterClassesFrom(schema);\r\n\r\n return this._registeredSchemas.delete(schemaName.toLowerCase());\r\n }\r\n\r\n /** Look up a previously registered schema\r\n * @param schemaName The name of the schema\r\n * @returns the previously registered schema or undefined if not registered.\r\n */\r\n public static getRegisteredSchema(schemaName: string): typeof Schema | undefined { return this._registeredSchemas.get(schemaName.toLowerCase()); }\r\n}\r\n"]}
1
+ {"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,oDAAiD;AACjD,mDAAgD;AAEhD;;GAEG;AACH,MAAa,MAAM;IACjB;;;;OAIG;IACI,MAAM,KAAK,UAAU,KAAa,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAElH;;;OAGG;IACI,MAAM,KAAK,uBAAuB,KAAc,OAAO,KAAK,CAAC,CAAC,CAAC;IAEtE;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,aAAqB;QAChD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QAC1C,IAAI,cAAc;YAChB,KAAK,CAAC,MAAM,CAA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------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Schema\n */\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { ClassRegistry } from \"./ClassRegistry\";\n\n/** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).\n * @public\n */\nexport class Schema {\n /** The name of the BIS schema handled by this Schema.\n * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.\n * Failure to do so will ordinarily result in an error when the schema is registered, since there may only\n * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)\n */\n public static get schemaName(): string { throw new Error(`you must override static schemaName in ${this.name}`); }\n\n /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.\n * Classes generated for this Schema will disallow protected operations.\n * @internal\n */\n public static get missingRequiredBehavior(): boolean { return false; }\n\n /** Get a semver-compatible string from a padded version string.\n * works on unpadded version strings as well\n * if there is no write version, it will be added\n * @example Schema.toSemverString(\"1.02.03\") === \"1.2.3\"\n * @example Schema.toSemverString(\"1.01\") === \"1.0.1\" // write version was added\n * @beta\n */\n public static toSemverString(paddedVersion: string): string {\n const tuple = paddedVersion.split(\".\").map(Number);\n const noWriteVersion = tuple.length === 2;\n if (noWriteVersion)\n tuple.splice(1, 0, 0); // insert 0 before the second element\n return tuple.join(\".\");\n }\n\n /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an\n * error if it is ever called.\n * @internal\n */\n protected constructor() { throw new Error(`cannot create an instance of a Schema ${this.constructor.name}`); }\n}\n\n/** Manages registered schemas\n * @public\n */\nexport class Schemas {\n private static readonly _registeredSchemas = new Map<string, typeof Schema>();\n private constructor() { } // this is a singleton\n\n /** Register a schema prior to using it.\n * @throws [[IModelError]] if a schema of the same name is already registered.\n */\n public static registerSchema(schema: typeof Schema) {\n const key = schema.schemaName.toLowerCase();\n if (this.getRegisteredSchema(key))\n throw new IModelError(IModelStatus.DuplicateName, `Schema \"${schema.schemaName}\" is already registered`);\n this._registeredSchemas.set(key, schema);\n }\n\n /** Unregister a schema, by name, if one is already registered.\n * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.\n * @param schemaName Name of the schema to unregister\n * @return true if the schema was unregistered\n */\n public static unregisterSchema(schemaName: string): boolean {\n const schema = this.getRegisteredSchema(schemaName);\n if (undefined !== schema)\n ClassRegistry.unregisterClassesFrom(schema);\n\n return this._registeredSchemas.delete(schemaName.toLowerCase());\n }\n\n /** Look up a previously registered schema\n * @param schemaName The name of the schema\n * @returns the previously registered schema or undefined if not registered.\n */\n public static getRegisteredSchema(schemaName: string): typeof Schema | undefined { return this._registeredSchemas.get(schemaName.toLowerCase()); }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,+CAA4C;AAC5C,yCAA+C;AAC/C,yCAAmD;AACnD,sDAAyD;AACzD,oDAAgE;AAEhE,8DAAyD;AACzD,gDAA+C;AAE/C,gBAAgB;AAChB,IAAiB,UAAU,CAkI1B;AAlID,WAAiB,UAAU;IACzB,MAAM,UAAU,GAAiC,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAEtF,kFAAkF;IAClF,MAAa,YAAa,SAAQ,4BAAiB;QAAnD;;YAC2B,cAAS,GAAG,OAAO,CAAC;QAE/C,CAAC;QADoB,SAAS,KAAK,CAAC;KACnC;IAHY,uBAAY,eAGxB,CAAA;IAED,MAAM,YAAY,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAClE,MAAM,aAAa,GAAG,cAAuB,CAAC;IAC9C,MAAM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AC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;KACF;IAhBY,sBAAW,cAgBvB,CAAA;AACH,CAAC,EAlIgB,UAAU,0BAAV,UAAU,QAkI1B","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\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { VersionedSqliteDb } from \"./SQLiteDb\";\r\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\r\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\n\r\n/** @internal */\r\nexport namespace SchemaSync {\r\n const lockParams: CloudSqlite.ObtainLockParams = { retryDelayMs: 1000, nRetries: 30 };\r\n\r\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\r\n export class SchemaSyncDb extends VersionedSqliteDb {\r\n public override readonly myVersion = \"4.0.0\";\r\n protected override createDDL() { }\r\n }\r\n\r\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\r\n const defaultDbName = \"SchemaSyncDb\" as const;\r\n const testSyncCachePropKey = \"test.schema_sync.cache_name\" as const;\r\n // for tests only\r\n export const setTestCache = (iModel: IModelDb, cacheName?: string) => {\r\n if (cacheName)\r\n iModel[_nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);\r\n else\r\n iModel[_nativeDb].deleteLocalValue(testSyncCachePropKey);\r\n };\r\n\r\n const getCloudAccess = async (arg: IModelDb | { readonly fileName: LocalFileName }) => {\r\n let nativeDb: IModelJsNative.DgnDb | undefined;\r\n const argIsIModelDb = arg instanceof IModelDb;\r\n if (argIsIModelDb) {\r\n nativeDb = arg[_nativeDb];\r\n } else {\r\n nativeDb = new IModelNative.platform.DgnDb();\r\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\r\n }\r\n\r\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\r\n if (!propsString)\r\n throw new Error(\"iModel does not have a SchemaSyncDb\");\r\n try {\r\n const props = JSON.parse(propsString) as CloudSqlite.ContainerProps;\r\n const accessToken = await CloudSqlite.requestToken(props);\r\n const access = new CloudAccess({ ...props, accessToken });\r\n Object.assign(access.lockParams, lockParams);\r\n const testSyncCache = nativeDb.queryLocalValue(testSyncCachePropKey);\r\n if (testSyncCache)\r\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testSyncCache }));\r\n return access;\r\n } finally {\r\n if (!argIsIModelDb) {\r\n nativeDb.closeFile();\r\n }\r\n }\r\n };\r\n\r\n export const withLockedAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, args: { operationName: string, openMode?: OpenMode, user?: string }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\r\n const access = await getCloudAccess(iModel);\r\n try {\r\n await access.withLockedDb(args, async () => operation(access));\r\n } finally {\r\n access.close();\r\n }\r\n };\r\n\r\n export const withReadonlyAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\r\n const access = await getCloudAccess(iModel);\r\n access.synchronizeWithCloud();\r\n access.openForRead();\r\n try {\r\n await operation(access);\r\n } finally {\r\n access.close();\r\n }\r\n };\r\n\r\n /** Synchronize local briefcase schemas with cloud container */\r\n export const pull = async (iModel: IModelDb) => {\r\n if (iModel[_nativeDb].schemaSyncEnabled() && !iModel.isReadonly) {\r\n await SchemaSync.withReadonlyAccess(iModel, async (syncAccess) => {\r\n const schemaSyncDbUri = syncAccess.getUri();\r\n iModel.clearCaches();\r\n iModel[_nativeDb].schemaSyncPull(schemaSyncDbUri);\r\n iModel.saveChanges(\"schema synchronized with cloud container\");\r\n });\r\n }\r\n };\r\n\r\n export const initializeForIModel = async (arg: { iModel: IModelDb, containerProps: CloudSqlite.ContainerProps, overrideContainer?: boolean }) => {\r\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\r\n const iModel = arg.iModel;\r\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\r\n await iModel.acquireSchemaLock();\r\n if (briefcase) {\r\n if (briefcase.txns.hasLocalChanges) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Enabling SchemaSync for iModel failed. There are unsaved or un-pushed local changes.\");\r\n }\r\n await briefcase.pullChanges();\r\n }\r\n try {\r\n iModel.saveFileProperty(syncProperty, JSON.stringify(props));\r\n await withLockedAccess(arg.iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\r\n iModel[_nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\r\n iModel.saveChanges(`Enable SchemaSync (container id: ${props.containerId})`);\r\n });\r\n } catch (err) {\r\n throw err;\r\n } finally {\r\n iModel.abandonChanges();\r\n }\r\n\r\n if (briefcase) {\r\n if (arg.overrideContainer)\r\n await briefcase.pushChanges({ description: `Overriding SchemaSync for iModel with container-id: ${props.containerId}` });\r\n else\r\n await briefcase.pushChanges({ description: `Enable SchemaSync for iModel with container-id: ${props.containerId}` });\r\n }\r\n };\r\n\r\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\r\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb> {\r\n public constructor(props: CloudSqlite.ContainerAccessProps) {\r\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\r\n }\r\n\r\n public getUri() {\r\n return `${this.getCloudDb()[_nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\r\n }\r\n /**\r\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\r\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\r\n * @note this deletes any existing content in the container.\r\n */\r\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\r\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\r\n }\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"SchemaSync.js","sourceRoot":"","sources":["../../src/SchemaSync.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,+CAA4C;AAC5C,yCAA+C;AAC/C,yCAAmD;AACnD,sDAAyD;AACzD,oDAAgE;AAEhE,8DAAyD;AACzD,gDAA+C;AAE/C,gBAAgB;AAChB,IAAiB,UAAU,CAkI1B;AAlID,WAAiB,UAAU;IACzB,MAAM,UAAU,GAAiC,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAEtF,kFAAkF;IAClF,MAAa,YAAa,SAAQ,4BAAiB;QAAnD;;YAC2B,cAAS,GAAG,OAAO,CAAC;QAE/C,CAAC;QADoB,SAAS,KAAK,CAAC;KACnC;IAHY,uBAAY,eAGxB,CAAA;IAED,MAAM,YAAY,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAClE,MAAM,aAAa,GAAG,cAAuB,CAAC;IAC9C,MAAM,oBAAoB,GAAG,6BAAsC,CAAC;IACpE,iBAAiB;IACJ,uBAAY,GAAG,CAAC,MAAgB,EAAE,SAAkB,EAAE,EAAE;QACnE,IAAI,SAAS;YACX,MAAM,CAAC,mBAAS,CAAC,CAAC,cAAc,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;;YAElE,MAAM,CAAC,mBAAS,CAAC,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;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CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,GAAG,CAAC,iBAAiB;gBACvB,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,uDAAuD,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;;gBAEzH,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,mDAAmD,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACzH,CAAC;IACH,CAAC,CAAC;IAEF,0EAA0E;IAC1E,MAAa,WAAY,SAAQ,yBAAW,CAAC,QAAsB;QACjE,YAAmB,KAAuC;YACxD,KAAK,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAChE,CAAC;QAEM,MAAM;YACX,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,mBAAS,CAAC,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,aAAa,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1I,CAAC;QACD;;;;SAIC;QACM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,KAAiC;YAChE,OAAO,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QACrF,CAAC;KACF;IAhBY,sBAAW,cAgBvB,CAAA;AACH,CAAC,EAlIgB,UAAU,0BAAV,UAAU,QAkI1B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module SQLiteDb\n */\n\nimport { CloudSqlite } from \"./CloudSqlite\";\nimport { VersionedSqliteDb } from \"./SQLiteDb\";\nimport { BriefcaseDb, IModelDb } from \"./IModelDb\";\nimport { DbResult, OpenMode } from \"@itwin/core-bentley\";\nimport { IModelError, LocalFileName } from \"@itwin/core-common\";\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { IModelNative } from \"./internal/NativePlatform\";\nimport { _nativeDb } from \"./internal/Symbols\";\n\n/** @internal */\nexport namespace SchemaSync {\n const lockParams: CloudSqlite.ObtainLockParams = { retryDelayMs: 1000, nRetries: 30 };\n\n /** A CloudSqlite database for synchronizing schema changes across briefcases. */\n export class SchemaSyncDb extends VersionedSqliteDb {\n public override readonly myVersion = \"4.0.0\";\n protected override createDDL() { }\n }\n\n const syncProperty = { namespace: \"itwinjs\", name: \"SchemaSync\" };\n const defaultDbName = \"SchemaSyncDb\" as const;\n const testSyncCachePropKey = \"test.schema_sync.cache_name\" as const;\n // for tests only\n export const setTestCache = (iModel: IModelDb, cacheName?: string) => {\n if (cacheName)\n iModel[_nativeDb].saveLocalValue(testSyncCachePropKey, cacheName);\n else\n iModel[_nativeDb].deleteLocalValue(testSyncCachePropKey);\n };\n\n const getCloudAccess = async (arg: IModelDb | { readonly fileName: LocalFileName }) => {\n let nativeDb: IModelJsNative.DgnDb | undefined;\n const argIsIModelDb = arg instanceof IModelDb;\n if (argIsIModelDb) {\n nativeDb = arg[_nativeDb];\n } else {\n nativeDb = new IModelNative.platform.DgnDb();\n nativeDb.openIModel(arg.fileName, OpenMode.Readonly);\n }\n\n const propsString = nativeDb.queryFileProperty(syncProperty, true) as string | undefined;\n if (!propsString)\n throw new Error(\"iModel does not have a SchemaSyncDb\");\n try {\n const props = JSON.parse(propsString) as CloudSqlite.ContainerProps;\n const accessToken = await CloudSqlite.requestToken(props);\n const access = new CloudAccess({ ...props, accessToken });\n Object.assign(access.lockParams, lockParams);\n const testSyncCache = nativeDb.queryLocalValue(testSyncCachePropKey);\n if (testSyncCache)\n access.setCache(CloudSqlite.CloudCaches.getCache({ cacheName: testSyncCache }));\n return access;\n } finally {\n if (!argIsIModelDb) {\n nativeDb.closeFile();\n }\n }\n };\n\n export const withLockedAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, args: { operationName: string, openMode?: OpenMode, user?: string }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\n const access = await getCloudAccess(iModel);\n try {\n await access.withLockedDb(args, async () => operation(access));\n } finally {\n access.close();\n }\n };\n\n export const withReadonlyAccess = async (iModel: IModelDb | { readonly fileName: LocalFileName }, operation: (access: CloudAccess) => Promise<void>): Promise<void> => {\n const access = await getCloudAccess(iModel);\n access.synchronizeWithCloud();\n access.openForRead();\n try {\n await operation(access);\n } finally {\n access.close();\n }\n };\n\n /** Synchronize local briefcase schemas with cloud container */\n export const pull = async (iModel: IModelDb) => {\n if (iModel[_nativeDb].schemaSyncEnabled() && !iModel.isReadonly) {\n await SchemaSync.withReadonlyAccess(iModel, async (syncAccess) => {\n const schemaSyncDbUri = syncAccess.getUri();\n iModel.clearCaches();\n iModel[_nativeDb].schemaSyncPull(schemaSyncDbUri);\n iModel.saveChanges(\"schema synchronized with cloud container\");\n });\n }\n };\n\n export const initializeForIModel = async (arg: { iModel: IModelDb, containerProps: CloudSqlite.ContainerProps, overrideContainer?: boolean }) => {\n const props = { baseUri: arg.containerProps.baseUri, containerId: arg.containerProps.containerId, storageType: arg.containerProps.storageType }; // sanitize to only known properties\n const iModel = arg.iModel;\n const briefcase = iModel instanceof BriefcaseDb ? iModel : undefined;\n await iModel.acquireSchemaLock();\n if (briefcase) {\n if (briefcase.txns.hasLocalChanges) {\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Enabling SchemaSync for iModel failed. There are unsaved or un-pushed local changes.\");\n }\n await briefcase.pullChanges();\n }\n try {\n iModel.saveFileProperty(syncProperty, JSON.stringify(props));\n await withLockedAccess(arg.iModel, { operationName: \"initialize schemaSync\", openMode: OpenMode.Readonly }, async (syncAccess) => {\n iModel[_nativeDb].schemaSyncInit(syncAccess.getUri(), props.containerId, arg.overrideContainer ?? false);\n iModel.saveChanges(`Enable SchemaSync (container id: ${props.containerId})`);\n });\n } catch (err) {\n throw err;\n } finally {\n iModel.abandonChanges();\n }\n\n if (briefcase) {\n if (arg.overrideContainer)\n await briefcase.pushChanges({ description: `Overriding SchemaSync for iModel with container-id: ${props.containerId}` });\n else\n await briefcase.pushChanges({ description: `Enable SchemaSync for iModel with container-id: ${props.containerId}` });\n }\n };\n\n /** Provides access to a cloud-based `SchemaSyncDb` to hold ECSchemas. */\n export class CloudAccess extends CloudSqlite.DbAccess<SchemaSyncDb> {\n public constructor(props: CloudSqlite.ContainerAccessProps) {\n super({ dbType: SchemaSyncDb, props, dbName: defaultDbName });\n }\n\n public getUri() {\n return `${this.getCloudDb()[_nativeDb].getFilePath()}?vfs=${this.container.cache?.name}&writable=${this.container.isWriteable ? 1 : 0}`;\n }\n /**\n * Initialize a cloud container for use as a SchemaSync. The container must first be created via its storage supplier api (e.g. Azure, or AWS).\n * A valid sasToken that grants write access must be supplied. This function creates and uploads an empty ChannelDb into the container.\n * @note this deletes any existing content in the container.\n */\n public static async initializeDb(props: CloudSqlite.ContainerProps) {\n return super._initializeDb({ props, dbType: SchemaSyncDb, dbName: defaultDbName });\n }\n }\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAAiD;AAEjD,8DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,aAAuB,EAAE,aAAkC;IACvG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,aAAa,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IAC5H,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kCAAkC,CAAC,CAAC;IAEjF,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,sEAOC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,UAAoB,EAAE,aAAkC;IACnG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,sBAAsB,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IACrI,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,mDAAmD,CAAC,CAAC;IAElG,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAPD,oEAOC","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 Schema\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { ECSchemaXmlContext } from \"./ECSchemaXmlContext\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\n\r\n/** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.\r\n * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.\r\n * @returns EC3.2 Xml ECSchema(s).\r\n * @throws [[IModelError]] if there is a problem converting the EC2 schemas.\r\n * @beta\r\n */\r\nexport function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const ec3XmlSchemas: string[] = IModelNative.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);\r\n if (ec2XmlSchemas.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting EC2 Xml schemas\");\r\n\r\n return ec3XmlSchemas;\r\n}\r\n\r\n/** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName\r\n * @param xmlSchemas The ECSchema Xml string(s).\r\n * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.\r\n * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.\r\n * @beta\r\n */\r\nexport function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\r\n const maybeNativeContext = schemaContext?.nativeContext;\r\n const schemasWithConvertedCA: string[] = IModelNative.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);\r\n if (schemasWithConvertedCA.length === 0)\r\n throw new IModelError(BentleyStatus.ERROR, \"Error converting custom attributes of Xml schemas\");\r\n\r\n return schemasWithConvertedCA;\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaUtils.js","sourceRoot":"","sources":["../../src/SchemaUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAAiD;AAEjD,8DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,aAAuB,EAAE,aAAkC;IACvG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,aAAa,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IAC5H,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kCAAkC,CAAC,CAAC;IAEjF,OAAO,aAAa,CAAC;AACvB,CAAC;AAPD,sEAOC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAAC,UAAoB,EAAE,aAAkC;IACnG,MAAM,kBAAkB,GAAG,aAAa,EAAE,aAAa,CAAC;IACxD,MAAM,sBAAsB,GAAa,6BAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,uBAAuB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IACrI,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,mDAAmD,CAAC,CAAC;IAElG,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAPD,oEAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Schema\n */\n\nimport { BentleyStatus } from \"@itwin/core-bentley\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { ECSchemaXmlContext } from \"./ECSchemaXmlContext\";\nimport { IModelNative } from \"./internal/NativePlatform\";\n\n/** Converts EC2 Xml ECSchema(s). On success, the `EC2 Xml schemas` are converted into `EC3.2 Xml schemas`.\n * @param ec2XmlSchemas The EC2 Xml string(s) created from a serialized ECSchema.\n * @returns EC3.2 Xml ECSchema(s).\n * @throws [[IModelError]] if there is a problem converting the EC2 schemas.\n * @beta\n */\nexport function convertEC2SchemasToEC3Schemas(ec2XmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\n const maybeNativeContext = schemaContext?.nativeContext;\n const ec3XmlSchemas: string[] = IModelNative.platform.SchemaUtility.convertEC2XmlSchemas(ec2XmlSchemas, maybeNativeContext);\n if (ec2XmlSchemas.length === 0)\n throw new IModelError(BentleyStatus.ERROR, \"Error converting EC2 Xml schemas\");\n\n return ec3XmlSchemas;\n}\n\n/** Converts schema metadata to EC3 concepts by traversing custom attributes of the supplied schema and calling converters based on schemaName:customAttributeName\n * @param xmlSchemas The ECSchema Xml string(s).\n * @returns EC3.2 Xml ECSchema(s) with converted custom attributes.\n * @throws [[IModelError]] if there is a problem converting the custom attributes of a schema.\n * @beta\n */\nexport function upgradeCustomAttributesToEC3(xmlSchemas: string[], schemaContext?: ECSchemaXmlContext): string[] {\n const maybeNativeContext = schemaContext?.nativeContext;\n const schemasWithConvertedCA: string[] = IModelNative.platform.SchemaUtility.convertCustomAttributes(xmlSchemas, maybeNativeContext);\n if (schemasWithConvertedCA.length === 0)\n throw new IModelError(BentleyStatus.ERROR, \"Error converting custom attributes of Xml schemas\");\n\n return schemasWithConvertedCA;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteChangesetReader.js","sourceRoot":"","sources":["../../src/SqliteChangesetReader.ts"],"names":[],"mappings":";;;AAQA,sDAA8G;AAG9G,8DAAyD;AAsEzD;;;;;GAKG;AACH,MAAa,qBAAqB;IAKhC;IACE,4CAA4C;IAC5B,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;QANX,kBAAa,GAAG,IAAI,6BAAY,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;QACrE,iBAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC3C,wBAAmB,GAAG,KAAK,CAAC;QAC5B,iBAAY,GAAG,CAAC,CAAC;IAIrB,CAAC;IAEL;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,IAA+D;QACpF,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClD,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,IAAI,KAAK,CAAC;QAC9D,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;OAI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CAAC;QAEjB,IAAI,CAAC,IAAI,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC,EAAE,CAAC,2BAA2B,CAAC,wDAAwD,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5G,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YAC9B,MAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,aAAa,EAAE,CAAC;gBAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC1C,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IACD;;OAEG;IACH,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACI,KAAK;QACV,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACD;;;OAGG;IACI,OAAO;QACZ,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF;AA1SD,sDA0SC","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 SQLiteDb\r\n */\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbChangeStage, DbOpcode, DbResult, DbValueType, Id64String, IDisposable } from \"@itwin/core-bentley\";\r\nimport { ECDb } from \"./ECDb\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\n\r\n/** Changed value type\r\n * @beta\r\n*/\r\ntype SqliteValue = Uint8Array | number | string | null | undefined;\r\n\r\n/** Array of changed values\r\n * @beta\r\n*/\r\ntype SqliteValueArray = SqliteValue[];\r\n/**\r\n * Format option when converting change from array to column/value object.\r\n * @beta\r\n */\r\nexport interface ChangeFormatArgs {\r\n /** include table name */\r\n includeTableName?: true;\r\n /** include op code */\r\n includeOpCode?: true;\r\n /** include null columns */\r\n includeNullColumns?: true;\r\n /** include value version */\r\n includeStage?: true;\r\n /** include primary key in update change */\r\n includePrimaryKeyInUpdateNew?: true;\r\n}\r\n\r\n/** Operation that cause the change\r\n * @beta\r\n*/\r\nexport type SqliteChangeOp = \"Inserted\" | \"Updated\" | \"Deleted\";\r\n\r\n/** Stage is version of value that needed to be read\r\n * @beta\r\n*/\r\nexport type SqliteValueStage = \"Old\" | \"New\";\r\n\r\n/** Db from which schema will be read. It should be from timeline to which changeset belong.\r\n * @beta\r\n*/\r\nexport type AnyDb = IModelDb | ECDb;\r\n\r\n/** Arg to open a changeset file from disk\r\n * @beta\r\n*/\r\nexport interface SqliteChangesetReaderArgs {\r\n /** db from which schema will be read. It should be close to changeset.*/\r\n readonly db?: AnyDb;\r\n /** invert the changeset operations */\r\n readonly invert?: true;\r\n /** do not check if column of change match db schema instead ignore addition columns */\r\n readonly disableSchemaCheck?: true;\r\n}\r\n\r\n/**\r\n * Represent sqlite change.\r\n * @beta\r\n */\r\nexport interface SqliteChange {\r\n /** name of table */\r\n $table?: string;\r\n /** SQLite operation that created this change */\r\n $op?: SqliteChangeOp;\r\n /** version of data in change. */\r\n $stage?: SqliteValueStage;\r\n /** columns in change */\r\n [key: string]: any;\r\n}\r\n\r\n/**\r\n * Read raw sqlite changeset from disk and enumerate changes.\r\n * It also optionally let you format change with schema from\r\n * a db provided.\r\n * @beta\r\n */\r\nexport class SqliteChangesetReader implements IDisposable {\r\n private readonly _nativeReader = new IModelNative.platform.ChangesetReader();\r\n private _schemaCache = new Map<string, string[]>();\r\n private _disableSchemaCheck = false;\r\n private _changeIndex = 0;\r\n protected constructor(\r\n /** db from where sql schema will be read */\r\n public readonly db?: AnyDb,\r\n ) { }\r\n\r\n /**\r\n * Open changeset file from disk\r\n * @param args fileName of changeset reader and other options.\r\n * @returns SqliteChangesetReader instance\r\n */\r\n public static openFile(args: { readonly fileName: string } & SqliteChangesetReaderArgs): SqliteChangesetReader {\r\n const reader = new SqliteChangesetReader(args.db);\r\n reader._disableSchemaCheck = args.disableSchemaCheck ?? false;\r\n reader._nativeReader.openFile(args.fileName, args.invert ?? false);\r\n return reader;\r\n }\r\n\r\n /**\r\n * Open local changes in iModel.\r\n * @param args iModel and other options.\r\n * @returns SqliteChangesetReader instance\r\n */\r\n public static openLocalChanges(args: { iModel: IModelJsNative.DgnDb, includeInMemoryChanges?: true } & SqliteChangesetReaderArgs): SqliteChangesetReader {\r\n const reader = new SqliteChangesetReader(args.db);\r\n reader._disableSchemaCheck = args.disableSchemaCheck ?? false;\r\n reader._nativeReader.openLocalChanges(args.iModel, args.includeInMemoryChanges ?? false, args.invert ?? false);\r\n return reader;\r\n }\r\n /** check if schema check is disabled or not */\r\n public get disableSchemaCheck(): boolean { return this._disableSchemaCheck; }\r\n /** Move to next change in changeset\r\n * @returns true if there is current change false if reader is end of changeset.\r\n * @beta\r\n */\r\n public step(): boolean {\r\n if (this._nativeReader.step()) {\r\n this._changeIndex++;\r\n return true;\r\n }\r\n return false;\r\n }\r\n /** Check if reader current on a row\r\n * @beta\r\n */\r\n public get hasRow(): boolean {\r\n return this._nativeReader.hasRow();\r\n }\r\n /** Check if its current change is indirect\r\n * @beta\r\n */\r\n public get isIndirect(): boolean {\r\n return this._nativeReader.isIndirectChange();\r\n }\r\n /** Get count of columns in current change\r\n * @beta\r\n */\r\n public get columnCount(): number {\r\n return this._nativeReader.getColumnCount();\r\n }\r\n /** Get operation that caused the change\r\n * @beta\r\n */\r\n public get op(): SqliteChangeOp {\r\n if (this._nativeReader.getOpCode() === DbOpcode.Insert)\r\n return \"Inserted\";\r\n\r\n if (this._nativeReader.getOpCode() === DbOpcode.Delete)\r\n return \"Deleted\";\r\n\r\n return \"Updated\";\r\n }\r\n /** Get primary key value array\r\n * @beta\r\n */\r\n public get primaryKeyValues(): SqliteValueArray {\r\n return this._nativeReader.getPrimaryKeys();\r\n }\r\n /** Get primary key columns.\r\n * @note To this to work db arg must be set when opening changeset file.\r\n * @beta\r\n */\r\n public getPrimaryKeyColumnNames(): string[] {\r\n const cols = this.getColumnNames(this.tableName);\r\n if (!this._disableSchemaCheck && cols.length !== this.columnCount)\r\n throw new Error(`changeset table ${this.tableName} columns count does not match db declared table. ${this.columnCount} <> ${cols.length}`);\r\n\r\n return this._nativeReader.getPrimaryKeyColumnIndexes().map((i) => cols[i]);\r\n }\r\n /** Get current change table.\r\n * @beta\r\n */\r\n public get tableName(): string {\r\n return this._nativeReader.getTableName();\r\n }\r\n /**\r\n * Get changed binary value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined {\r\n return this._nativeReader.getColumnValueType(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old) as DbValueType;\r\n }\r\n\r\n /**\r\n * Get changed binary value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueBinary(columnIndex: number, stage: SqliteValueStage): Uint8Array | null | undefined {\r\n return this._nativeReader.getColumnValueBinary(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Get changed double value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueDouble(columnIndex: number, stage: SqliteValueStage): number | null | undefined {\r\n return this._nativeReader.getColumnValueDouble(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Get changed Id value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueId(columnIndex: number, stage: SqliteValueStage): Id64String | null | undefined {\r\n return this._nativeReader.getColumnValueId(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Get changed integer value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueInteger(columnIndex: number, stage: SqliteValueStage): number | null | undefined {\r\n return this._nativeReader.getColumnValueInteger(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Get changed text value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValueText(columnIndex: number, stage: SqliteValueStage): string | null | undefined {\r\n return this._nativeReader.getColumnValueText(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Check if change value is null\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns true if value is null\r\n * @beta\r\n */\r\n public isColumnValueNull(columnIndex: number, stage: SqliteValueStage): boolean | undefined {\r\n return this._nativeReader.isColumnValueNull(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n\r\n /**\r\n * Get change value type\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns change value type\r\n * @beta\r\n */\r\n public getColumnValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined {\r\n return this._nativeReader.getColumnValueType(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old) as DbValueType | undefined;\r\n }\r\n\r\n /**\r\n * Get changed value for a column\r\n * @param columnIndex index of column in current change\r\n * @param stage old or new value for change.\r\n * @returns value for changed column\r\n * @beta\r\n */\r\n public getChangeValue(columnIndex: number, stage: SqliteValueStage): SqliteValue {\r\n return this._nativeReader.getColumnValue(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n /**\r\n * Get all changed value in current change as array\r\n * @param stage old or new values for current change.\r\n * @returns array of values.\r\n * @beta\r\n */\r\n public getChangeValuesArray(stage: SqliteValueStage): SqliteValueArray | undefined {\r\n return this._nativeReader.getRow(stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\r\n }\r\n /**\r\n * Get change as object and format its content.\r\n * @param stage old or new value for current change.\r\n * @param args change format options\r\n * @returns return object or undefined\r\n * @beta\r\n */\r\n public getChangeValuesObject(stage: SqliteValueStage, args: ChangeFormatArgs = {}): SqliteChange | undefined {\r\n const cols = this.getColumnNames(this.tableName);\r\n const row = this.getChangeValuesArray(stage);\r\n if (!row)\r\n return undefined;\r\n process.env;\r\n const minLen = Math.min(cols.length, row.length);\r\n\r\n if (!this._disableSchemaCheck && cols.length !== this.columnCount)\r\n throw new Error(`changeset table ${this.tableName} columns count does not match db declared table. ${this.columnCount} <> ${cols.length}`);\r\n\r\n const out: SqliteChange = {};\r\n if (args.includeTableName) {\r\n out.$table = this.tableName;\r\n }\r\n if (args.includeOpCode) {\r\n out.$op = this.op;\r\n }\r\n if (args.includeStage) {\r\n out.$stage = stage;\r\n }\r\n\r\n if (args.includePrimaryKeyInUpdateNew && this.op === \"Updated\" && stage === \"New\") {\r\n const pkNames = this.getPrimaryKeyColumnNames();\r\n const pkValues = this.primaryKeyValues;\r\n pkNames.forEach((v, i) => {\r\n out[v] = pkValues[i];\r\n });\r\n }\r\n const isNullOrUndefined = (val: SqliteValue) => typeof val === \"undefined\";\r\n\r\n for (let i = 0; i < minLen; ++i) {\r\n const columnValue = row[i];\r\n const columnName = cols[i];\r\n if (!args.includeNullColumns && isNullOrUndefined(columnValue))\r\n continue;\r\n\r\n out[columnName] = columnValue;\r\n }\r\n return out;\r\n }\r\n /**\r\n * Get list of column for a table. This function also caches the result.\r\n * @note To this to work db arg must be set when opening changeset file.\r\n * @param tableName name of the table for which columns are requested.\r\n * @returns columns of table.\r\n * @beta\r\n */\r\n public getColumnNames(tableName: string): string[] {\r\n const columns = this._schemaCache.get(tableName);\r\n if (columns)\r\n return columns;\r\n\r\n if (!this.db)\r\n throw new Error(\"getColumns() require db context to be provided.\");\r\n\r\n return this.db.withPreparedSqliteStatement(\"SELECT [name] FROM PRAGMA_TABLE_INFO(?) ORDER BY [cid]\", (stmt) => {\r\n stmt.bindString(1, tableName);\r\n const tblCols: string[] = [];\r\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\r\n tblCols.push(stmt.getValueString(0));\r\n }\r\n this._schemaCache.set(tableName, tblCols);\r\n return tblCols;\r\n });\r\n }\r\n /** index of current change\r\n * @beta\r\n */\r\n public get changeIndex() { return this._changeIndex; }\r\n /**\r\n * Close changeset\r\n * @beta\r\n */\r\n public close() {\r\n this._changeIndex = 0;\r\n this._nativeReader.close();\r\n }\r\n /**\r\n * Dispose this object\r\n * @beta\r\n */\r\n public dispose(): void {\r\n this.close();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SqliteChangesetReader.js","sourceRoot":"","sources":["../../src/SqliteChangesetReader.ts"],"names":[],"mappings":";;;AAQA,sDAA8G;AAG9G,8DAAyD;AAsEzD;;;;;GAKG;AACH,MAAa,qBAAqB;IAKhC;IACE,4CAA4C;IAC5B,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;QANX,kBAAa,GAAG,IAAI,6BAAY,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;QACrE,iBAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC3C,wBAAmB,GAAG,KAAK,CAAC;QAC5B,iBAAY,GAAG,CAAC,CAAC;IAIrB,CAAC;IAEL;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,IAA+D;QAC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kBAAkB,IAAI,iBAAiB,CAAC,WAAW,CAAC;gBAC5D,SAAS;YAEX,GAAG,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC;QAChC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD;;;;;;OAMG;IACI,cAAc,CAAC,SAAiB;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,OAAO;YACT,OAAO,OAAO,CAAC;QAEjB,IAAI,CAAC,IAAI,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC,EAAE,CAAC,2BAA2B,CAAC,wDAAwD,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5G,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YAC9B,MAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,aAAa,EAAE,CAAC;gBAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,CAAC;YACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC1C,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IACD;;OAEG;IACH,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACI,KAAK;QACV,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACD;;;OAGG;IACI,OAAO;QACZ,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF;AA1SD,sDA0SC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLiteDb\n */\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { DbChangeStage, DbOpcode, DbResult, DbValueType, Id64String, IDisposable } from \"@itwin/core-bentley\";\nimport { ECDb } from \"./ECDb\";\nimport { IModelDb } from \"./IModelDb\";\nimport { IModelNative } from \"./internal/NativePlatform\";\n\n/** Changed value type\n * @beta\n*/\ntype SqliteValue = Uint8Array | number | string | null | undefined;\n\n/** Array of changed values\n * @beta\n*/\ntype SqliteValueArray = SqliteValue[];\n/**\n * Format option when converting change from array to column/value object.\n * @beta\n */\nexport interface ChangeFormatArgs {\n /** include table name */\n includeTableName?: true;\n /** include op code */\n includeOpCode?: true;\n /** include null columns */\n includeNullColumns?: true;\n /** include value version */\n includeStage?: true;\n /** include primary key in update change */\n includePrimaryKeyInUpdateNew?: true;\n}\n\n/** Operation that cause the change\n * @beta\n*/\nexport type SqliteChangeOp = \"Inserted\" | \"Updated\" | \"Deleted\";\n\n/** Stage is version of value that needed to be read\n * @beta\n*/\nexport type SqliteValueStage = \"Old\" | \"New\";\n\n/** Db from which schema will be read. It should be from timeline to which changeset belong.\n * @beta\n*/\nexport type AnyDb = IModelDb | ECDb;\n\n/** Arg to open a changeset file from disk\n * @beta\n*/\nexport interface SqliteChangesetReaderArgs {\n /** db from which schema will be read. It should be close to changeset.*/\n readonly db?: AnyDb;\n /** invert the changeset operations */\n readonly invert?: true;\n /** do not check if column of change match db schema instead ignore addition columns */\n readonly disableSchemaCheck?: true;\n}\n\n/**\n * Represent sqlite change.\n * @beta\n */\nexport interface SqliteChange {\n /** name of table */\n $table?: string;\n /** SQLite operation that created this change */\n $op?: SqliteChangeOp;\n /** version of data in change. */\n $stage?: SqliteValueStage;\n /** columns in change */\n [key: string]: any;\n}\n\n/**\n * Read raw sqlite changeset from disk and enumerate changes.\n * It also optionally let you format change with schema from\n * a db provided.\n * @beta\n */\nexport class SqliteChangesetReader implements IDisposable {\n private readonly _nativeReader = new IModelNative.platform.ChangesetReader();\n private _schemaCache = new Map<string, string[]>();\n private _disableSchemaCheck = false;\n private _changeIndex = 0;\n protected constructor(\n /** db from where sql schema will be read */\n public readonly db?: AnyDb,\n ) { }\n\n /**\n * Open changeset file from disk\n * @param args fileName of changeset reader and other options.\n * @returns SqliteChangesetReader instance\n */\n public static openFile(args: { readonly fileName: string } & SqliteChangesetReaderArgs): SqliteChangesetReader {\n const reader = new SqliteChangesetReader(args.db);\n reader._disableSchemaCheck = args.disableSchemaCheck ?? false;\n reader._nativeReader.openFile(args.fileName, args.invert ?? false);\n return reader;\n }\n\n /**\n * Open local changes in iModel.\n * @param args iModel and other options.\n * @returns SqliteChangesetReader instance\n */\n public static openLocalChanges(args: { iModel: IModelJsNative.DgnDb, includeInMemoryChanges?: true } & SqliteChangesetReaderArgs): SqliteChangesetReader {\n const reader = new SqliteChangesetReader(args.db);\n reader._disableSchemaCheck = args.disableSchemaCheck ?? false;\n reader._nativeReader.openLocalChanges(args.iModel, args.includeInMemoryChanges ?? false, args.invert ?? false);\n return reader;\n }\n /** check if schema check is disabled or not */\n public get disableSchemaCheck(): boolean { return this._disableSchemaCheck; }\n /** Move to next change in changeset\n * @returns true if there is current change false if reader is end of changeset.\n * @beta\n */\n public step(): boolean {\n if (this._nativeReader.step()) {\n this._changeIndex++;\n return true;\n }\n return false;\n }\n /** Check if reader current on a row\n * @beta\n */\n public get hasRow(): boolean {\n return this._nativeReader.hasRow();\n }\n /** Check if its current change is indirect\n * @beta\n */\n public get isIndirect(): boolean {\n return this._nativeReader.isIndirectChange();\n }\n /** Get count of columns in current change\n * @beta\n */\n public get columnCount(): number {\n return this._nativeReader.getColumnCount();\n }\n /** Get operation that caused the change\n * @beta\n */\n public get op(): SqliteChangeOp {\n if (this._nativeReader.getOpCode() === DbOpcode.Insert)\n return \"Inserted\";\n\n if (this._nativeReader.getOpCode() === DbOpcode.Delete)\n return \"Deleted\";\n\n return \"Updated\";\n }\n /** Get primary key value array\n * @beta\n */\n public get primaryKeyValues(): SqliteValueArray {\n return this._nativeReader.getPrimaryKeys();\n }\n /** Get primary key columns.\n * @note To this to work db arg must be set when opening changeset file.\n * @beta\n */\n public getPrimaryKeyColumnNames(): string[] {\n const cols = this.getColumnNames(this.tableName);\n if (!this._disableSchemaCheck && cols.length !== this.columnCount)\n throw new Error(`changeset table ${this.tableName} columns count does not match db declared table. ${this.columnCount} <> ${cols.length}`);\n\n return this._nativeReader.getPrimaryKeyColumnIndexes().map((i) => cols[i]);\n }\n /** Get current change table.\n * @beta\n */\n public get tableName(): string {\n return this._nativeReader.getTableName();\n }\n /**\n * Get changed binary value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined {\n return this._nativeReader.getColumnValueType(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old) as DbValueType;\n }\n\n /**\n * Get changed binary value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueBinary(columnIndex: number, stage: SqliteValueStage): Uint8Array | null | undefined {\n return this._nativeReader.getColumnValueBinary(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Get changed double value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueDouble(columnIndex: number, stage: SqliteValueStage): number | null | undefined {\n return this._nativeReader.getColumnValueDouble(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Get changed Id value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueId(columnIndex: number, stage: SqliteValueStage): Id64String | null | undefined {\n return this._nativeReader.getColumnValueId(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Get changed integer value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueInteger(columnIndex: number, stage: SqliteValueStage): number | null | undefined {\n return this._nativeReader.getColumnValueInteger(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Get changed text value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValueText(columnIndex: number, stage: SqliteValueStage): string | null | undefined {\n return this._nativeReader.getColumnValueText(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Check if change value is null\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns true if value is null\n * @beta\n */\n public isColumnValueNull(columnIndex: number, stage: SqliteValueStage): boolean | undefined {\n return this._nativeReader.isColumnValueNull(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n\n /**\n * Get change value type\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns change value type\n * @beta\n */\n public getColumnValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined {\n return this._nativeReader.getColumnValueType(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old) as DbValueType | undefined;\n }\n\n /**\n * Get changed value for a column\n * @param columnIndex index of column in current change\n * @param stage old or new value for change.\n * @returns value for changed column\n * @beta\n */\n public getChangeValue(columnIndex: number, stage: SqliteValueStage): SqliteValue {\n return this._nativeReader.getColumnValue(columnIndex, stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n /**\n * Get all changed value in current change as array\n * @param stage old or new values for current change.\n * @returns array of values.\n * @beta\n */\n public getChangeValuesArray(stage: SqliteValueStage): SqliteValueArray | undefined {\n return this._nativeReader.getRow(stage === \"New\" ? DbChangeStage.New : DbChangeStage.Old);\n }\n /**\n * Get change as object and format its content.\n * @param stage old or new value for current change.\n * @param args change format options\n * @returns return object or undefined\n * @beta\n */\n public getChangeValuesObject(stage: SqliteValueStage, args: ChangeFormatArgs = {}): SqliteChange | undefined {\n const cols = this.getColumnNames(this.tableName);\n const row = this.getChangeValuesArray(stage);\n if (!row)\n return undefined;\n process.env;\n const minLen = Math.min(cols.length, row.length);\n\n if (!this._disableSchemaCheck && cols.length !== this.columnCount)\n throw new Error(`changeset table ${this.tableName} columns count does not match db declared table. ${this.columnCount} <> ${cols.length}`);\n\n const out: SqliteChange = {};\n if (args.includeTableName) {\n out.$table = this.tableName;\n }\n if (args.includeOpCode) {\n out.$op = this.op;\n }\n if (args.includeStage) {\n out.$stage = stage;\n }\n\n if (args.includePrimaryKeyInUpdateNew && this.op === \"Updated\" && stage === \"New\") {\n const pkNames = this.getPrimaryKeyColumnNames();\n const pkValues = this.primaryKeyValues;\n pkNames.forEach((v, i) => {\n out[v] = pkValues[i];\n });\n }\n const isNullOrUndefined = (val: SqliteValue) => typeof val === \"undefined\";\n\n for (let i = 0; i < minLen; ++i) {\n const columnValue = row[i];\n const columnName = cols[i];\n if (!args.includeNullColumns && isNullOrUndefined(columnValue))\n continue;\n\n out[columnName] = columnValue;\n }\n return out;\n }\n /**\n * Get list of column for a table. This function also caches the result.\n * @note To this to work db arg must be set when opening changeset file.\n * @param tableName name of the table for which columns are requested.\n * @returns columns of table.\n * @beta\n */\n public getColumnNames(tableName: string): string[] {\n const columns = this._schemaCache.get(tableName);\n if (columns)\n return columns;\n\n if (!this.db)\n throw new Error(\"getColumns() require db context to be provided.\");\n\n return this.db.withPreparedSqliteStatement(\"SELECT [name] FROM PRAGMA_TABLE_INFO(?) ORDER BY [cid]\", (stmt) => {\n stmt.bindString(1, tableName);\n const tblCols: string[] = [];\n while (stmt.step() === DbResult.BE_SQLITE_ROW) {\n tblCols.push(stmt.getValueString(0));\n }\n this._schemaCache.set(tableName, tblCols);\n return tblCols;\n });\n }\n /** index of current change\n * @beta\n */\n public get changeIndex() { return this._changeIndex; }\n /**\n * Close changeset\n * @beta\n */\n public close() {\n this._changeIndex = 0;\n this._nativeReader.close();\n }\n /**\n * Dispose this object\n * @beta\n */\n public dispose(): void {\n this.close();\n }\n}\n"]}