@itwin/ecschema-metadata 5.1.0-dev.9 → 5.2.0-dev.2

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 (210) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/lib/cjs/Context.d.ts +1 -1
  3. package/lib/cjs/Context.js +1 -1
  4. package/lib/cjs/Context.js.map +1 -1
  5. package/lib/cjs/Deserialization/Helper.d.ts +30 -11
  6. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  7. package/lib/cjs/Deserialization/Helper.js +124 -96
  8. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  9. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +12 -3
  10. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts.map +1 -1
  11. package/lib/cjs/Deserialization/SchemaGraphUtil.js +36 -23
  12. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  13. package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
  14. package/lib/cjs/Deserialization/XmlParser.js +14 -5
  15. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  16. package/lib/cjs/Deserialization/XmlSerializationUtils.js +1 -1
  17. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  18. package/lib/cjs/ECName.js +1 -1
  19. package/lib/cjs/ECName.js.map +1 -1
  20. package/lib/cjs/ECObjects.d.ts +1 -1
  21. package/lib/cjs/ECObjects.js +2 -2
  22. package/lib/cjs/ECObjects.js.map +1 -1
  23. package/lib/cjs/IncrementalLoading/ClassParsers.d.ts +60 -0
  24. package/lib/cjs/IncrementalLoading/ClassParsers.d.ts.map +1 -0
  25. package/lib/cjs/IncrementalLoading/ClassParsers.js +111 -0
  26. package/lib/cjs/IncrementalLoading/ClassParsers.js.map +1 -0
  27. package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.d.ts +211 -0
  28. package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.d.ts.map +1 -0
  29. package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.js +387 -0
  30. package/lib/cjs/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -0
  31. package/lib/cjs/IncrementalLoading/FullSchemaQueries.d.ts +14 -0
  32. package/lib/cjs/IncrementalLoading/FullSchemaQueries.d.ts.map +1 -0
  33. package/lib/cjs/IncrementalLoading/FullSchemaQueries.js +609 -0
  34. package/lib/cjs/IncrementalLoading/FullSchemaQueries.js.map +1 -0
  35. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.d.ts +109 -0
  36. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.d.ts.map +1 -0
  37. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js +219 -0
  38. package/lib/cjs/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -0
  39. package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.d.ts +36 -0
  40. package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.d.ts.map +1 -0
  41. package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.js +77 -0
  42. package/lib/cjs/IncrementalLoading/IncrementalSchemaReader.js.map +1 -0
  43. package/lib/cjs/IncrementalLoading/PerformanceLogger.d.ts +60 -0
  44. package/lib/cjs/IncrementalLoading/PerformanceLogger.d.ts.map +1 -0
  45. package/lib/cjs/IncrementalLoading/PerformanceLogger.js +82 -0
  46. package/lib/cjs/IncrementalLoading/PerformanceLogger.js.map +1 -0
  47. package/lib/cjs/IncrementalLoading/SchemaItemParsers.d.ts +51 -0
  48. package/lib/cjs/IncrementalLoading/SchemaItemParsers.d.ts.map +1 -0
  49. package/lib/cjs/IncrementalLoading/SchemaItemParsers.js +122 -0
  50. package/lib/cjs/IncrementalLoading/SchemaItemParsers.js.map +1 -0
  51. package/lib/cjs/IncrementalLoading/SchemaItemQueries.d.ts +16 -0
  52. package/lib/cjs/IncrementalLoading/SchemaItemQueries.d.ts.map +1 -0
  53. package/lib/cjs/IncrementalLoading/SchemaItemQueries.js +308 -0
  54. package/lib/cjs/IncrementalLoading/SchemaItemQueries.js.map +1 -0
  55. package/lib/cjs/IncrementalLoading/SchemaParser.d.ts +42 -0
  56. package/lib/cjs/IncrementalLoading/SchemaParser.d.ts.map +1 -0
  57. package/lib/cjs/IncrementalLoading/SchemaParser.js +109 -0
  58. package/lib/cjs/IncrementalLoading/SchemaParser.js.map +1 -0
  59. package/lib/cjs/IncrementalLoading/SchemaStubQueries.d.ts +12 -0
  60. package/lib/cjs/IncrementalLoading/SchemaStubQueries.d.ts.map +1 -0
  61. package/lib/cjs/IncrementalLoading/SchemaStubQueries.js +365 -0
  62. package/lib/cjs/IncrementalLoading/SchemaStubQueries.js.map +1 -0
  63. package/lib/cjs/Metadata/Class.d.ts +5 -16
  64. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  65. package/lib/cjs/Metadata/Class.js +68 -68
  66. package/lib/cjs/Metadata/Class.js.map +1 -1
  67. package/lib/cjs/Metadata/CustomAttribute.d.ts +7 -1
  68. package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
  69. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  70. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +1 -1
  71. package/lib/cjs/Metadata/CustomAttributeClass.js +1 -1
  72. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  73. package/lib/cjs/Metadata/EntityClass.d.ts +6 -6
  74. package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
  75. package/lib/cjs/Metadata/EntityClass.js +48 -26
  76. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  77. package/lib/cjs/Metadata/Format.d.ts +5 -0
  78. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  79. package/lib/cjs/Metadata/Format.js +7 -0
  80. package/lib/cjs/Metadata/Format.js.map +1 -1
  81. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  82. package/lib/cjs/Metadata/Schema.d.ts +10 -0
  83. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  84. package/lib/cjs/Metadata/Schema.js +13 -0
  85. package/lib/cjs/Metadata/Schema.js.map +1 -1
  86. package/lib/cjs/Metadata/SchemaItem.d.ts +10 -0
  87. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  88. package/lib/cjs/Metadata/SchemaItem.js +13 -0
  89. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  90. package/lib/cjs/SchemaFormatsProvider.d.ts +4 -3
  91. package/lib/cjs/SchemaFormatsProvider.d.ts.map +1 -1
  92. package/lib/cjs/SchemaFormatsProvider.js +60 -17
  93. package/lib/cjs/SchemaFormatsProvider.js.map +1 -1
  94. package/lib/cjs/SchemaLoader.d.ts +4 -1
  95. package/lib/cjs/SchemaLoader.d.ts.map +1 -1
  96. package/lib/cjs/SchemaLoader.js +4 -1
  97. package/lib/cjs/SchemaLoader.js.map +1 -1
  98. package/lib/cjs/ecschema-metadata.d.ts +2 -0
  99. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  100. package/lib/cjs/ecschema-metadata.js +2 -0
  101. package/lib/cjs/ecschema-metadata.js.map +1 -1
  102. package/lib/cjs/utils/SchemaLoadingController.d.ts +37 -0
  103. package/lib/cjs/utils/SchemaLoadingController.d.ts.map +1 -0
  104. package/lib/cjs/utils/SchemaLoadingController.js +65 -0
  105. package/lib/cjs/utils/SchemaLoadingController.js.map +1 -0
  106. package/lib/esm/Context.d.ts +1 -1
  107. package/lib/esm/Context.js +1 -1
  108. package/lib/esm/Context.js.map +1 -1
  109. package/lib/esm/Deserialization/Helper.d.ts +30 -11
  110. package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
  111. package/lib/esm/Deserialization/Helper.js +124 -96
  112. package/lib/esm/Deserialization/Helper.js.map +1 -1
  113. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +12 -3
  114. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -1
  115. package/lib/esm/Deserialization/SchemaGraphUtil.js +36 -23
  116. package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -1
  117. package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -1
  118. package/lib/esm/Deserialization/XmlParser.js +14 -5
  119. package/lib/esm/Deserialization/XmlParser.js.map +1 -1
  120. package/lib/esm/Deserialization/XmlSerializationUtils.js +1 -1
  121. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
  122. package/lib/esm/ECName.js +1 -1
  123. package/lib/esm/ECName.js.map +1 -1
  124. package/lib/esm/ECObjects.d.ts +1 -1
  125. package/lib/esm/ECObjects.js +2 -2
  126. package/lib/esm/ECObjects.js.map +1 -1
  127. package/lib/esm/IncrementalLoading/ClassParsers.d.ts +60 -0
  128. package/lib/esm/IncrementalLoading/ClassParsers.d.ts.map +1 -0
  129. package/lib/esm/IncrementalLoading/ClassParsers.js +104 -0
  130. package/lib/esm/IncrementalLoading/ClassParsers.js.map +1 -0
  131. package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.d.ts +211 -0
  132. package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.d.ts.map +1 -0
  133. package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.js +383 -0
  134. package/lib/esm/IncrementalLoading/ECSqlSchemaLocater.js.map +1 -0
  135. package/lib/esm/IncrementalLoading/FullSchemaQueries.d.ts +14 -0
  136. package/lib/esm/IncrementalLoading/FullSchemaQueries.d.ts.map +1 -0
  137. package/lib/esm/IncrementalLoading/FullSchemaQueries.js +606 -0
  138. package/lib/esm/IncrementalLoading/FullSchemaQueries.js.map +1 -0
  139. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.d.ts +109 -0
  140. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.d.ts.map +1 -0
  141. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js +215 -0
  142. package/lib/esm/IncrementalLoading/IncrementalSchemaLocater.js.map +1 -0
  143. package/lib/esm/IncrementalLoading/IncrementalSchemaReader.d.ts +36 -0
  144. package/lib/esm/IncrementalLoading/IncrementalSchemaReader.d.ts.map +1 -0
  145. package/lib/esm/IncrementalLoading/IncrementalSchemaReader.js +73 -0
  146. package/lib/esm/IncrementalLoading/IncrementalSchemaReader.js.map +1 -0
  147. package/lib/esm/IncrementalLoading/PerformanceLogger.d.ts +60 -0
  148. package/lib/esm/IncrementalLoading/PerformanceLogger.d.ts.map +1 -0
  149. package/lib/esm/IncrementalLoading/PerformanceLogger.js +78 -0
  150. package/lib/esm/IncrementalLoading/PerformanceLogger.js.map +1 -0
  151. package/lib/esm/IncrementalLoading/SchemaItemParsers.d.ts +51 -0
  152. package/lib/esm/IncrementalLoading/SchemaItemParsers.d.ts.map +1 -0
  153. package/lib/esm/IncrementalLoading/SchemaItemParsers.js +117 -0
  154. package/lib/esm/IncrementalLoading/SchemaItemParsers.js.map +1 -0
  155. package/lib/esm/IncrementalLoading/SchemaItemQueries.d.ts +16 -0
  156. package/lib/esm/IncrementalLoading/SchemaItemQueries.d.ts.map +1 -0
  157. package/lib/esm/IncrementalLoading/SchemaItemQueries.js +305 -0
  158. package/lib/esm/IncrementalLoading/SchemaItemQueries.js.map +1 -0
  159. package/lib/esm/IncrementalLoading/SchemaParser.d.ts +42 -0
  160. package/lib/esm/IncrementalLoading/SchemaParser.d.ts.map +1 -0
  161. package/lib/esm/IncrementalLoading/SchemaParser.js +104 -0
  162. package/lib/esm/IncrementalLoading/SchemaParser.js.map +1 -0
  163. package/lib/esm/IncrementalLoading/SchemaStubQueries.d.ts +12 -0
  164. package/lib/esm/IncrementalLoading/SchemaStubQueries.d.ts.map +1 -0
  165. package/lib/esm/IncrementalLoading/SchemaStubQueries.js +359 -0
  166. package/lib/esm/IncrementalLoading/SchemaStubQueries.js.map +1 -0
  167. package/lib/esm/Metadata/Class.d.ts +5 -16
  168. package/lib/esm/Metadata/Class.d.ts.map +1 -1
  169. package/lib/esm/Metadata/Class.js +68 -68
  170. package/lib/esm/Metadata/Class.js.map +1 -1
  171. package/lib/esm/Metadata/CustomAttribute.d.ts +7 -1
  172. package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -1
  173. package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
  174. package/lib/esm/Metadata/CustomAttributeClass.d.ts +1 -1
  175. package/lib/esm/Metadata/CustomAttributeClass.js +1 -1
  176. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
  177. package/lib/esm/Metadata/EntityClass.d.ts +6 -6
  178. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
  179. package/lib/esm/Metadata/EntityClass.js +48 -26
  180. package/lib/esm/Metadata/EntityClass.js.map +1 -1
  181. package/lib/esm/Metadata/Format.d.ts +5 -0
  182. package/lib/esm/Metadata/Format.d.ts.map +1 -1
  183. package/lib/esm/Metadata/Format.js +7 -0
  184. package/lib/esm/Metadata/Format.js.map +1 -1
  185. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
  186. package/lib/esm/Metadata/Schema.d.ts +10 -0
  187. package/lib/esm/Metadata/Schema.d.ts.map +1 -1
  188. package/lib/esm/Metadata/Schema.js +13 -0
  189. package/lib/esm/Metadata/Schema.js.map +1 -1
  190. package/lib/esm/Metadata/SchemaItem.d.ts +10 -0
  191. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
  192. package/lib/esm/Metadata/SchemaItem.js +13 -0
  193. package/lib/esm/Metadata/SchemaItem.js.map +1 -1
  194. package/lib/esm/SchemaFormatsProvider.d.ts +4 -3
  195. package/lib/esm/SchemaFormatsProvider.d.ts.map +1 -1
  196. package/lib/esm/SchemaFormatsProvider.js +61 -18
  197. package/lib/esm/SchemaFormatsProvider.js.map +1 -1
  198. package/lib/esm/SchemaLoader.d.ts +4 -1
  199. package/lib/esm/SchemaLoader.d.ts.map +1 -1
  200. package/lib/esm/SchemaLoader.js +4 -1
  201. package/lib/esm/SchemaLoader.js.map +1 -1
  202. package/lib/esm/ecschema-metadata.d.ts +2 -0
  203. package/lib/esm/ecschema-metadata.d.ts.map +1 -1
  204. package/lib/esm/ecschema-metadata.js +2 -0
  205. package/lib/esm/ecschema-metadata.js.map +1 -1
  206. package/lib/esm/utils/SchemaLoadingController.d.ts +37 -0
  207. package/lib/esm/utils/SchemaLoadingController.d.ts.map +1 -0
  208. package/lib/esm/utils/SchemaLoadingController.js +61 -0
  209. package/lib/esm/utils/SchemaLoadingController.js.map +1 -0
  210. package/package.json +15 -10
@@ -39,8 +39,11 @@ class SchemaReadHelper {
39
39
  * calling getCachedSchema on the context.
40
40
  * @param schema The Schema to populate
41
41
  * @param rawSchema The serialized data to use to populate the Schema.
42
+ * @param addSchemaToCache Optional parameter that indicates if the schema should be added to the SchemaContext.
43
+ * The default is true. If false, the schema loading will not begin asynchronously in the background because the
44
+ * schema promise must be added to the context. In this case, only the SchemaInfo is returned.
42
45
  */
43
- async readSchemaInfo(schema, rawSchema) {
46
+ async readSchemaInfo(schema, rawSchema, addSchemaToCache = true) {
44
47
  // Ensure context matches schema context
45
48
  if (schema.context) {
46
49
  if (this._context !== schema.context)
@@ -53,15 +56,15 @@ class SchemaReadHelper {
53
56
  // Loads all of the properties on the Schema object
54
57
  await schema.fromJSON(this._parser.parseSchema());
55
58
  this._schema = schema;
56
- const schemaInfoReferences = [];
57
- const schemaInfo = { schemaKey: schema.schemaKey, alias: schema.alias, references: schemaInfoReferences };
59
+ const schemaReferences = [];
60
+ const schemaInfo = { schemaKey: schema.schemaKey, alias: schema.alias, references: schemaReferences };
58
61
  for (const reference of this._parser.getReferences()) {
59
62
  const refKey = new SchemaKey_1.SchemaKey(reference.name, SchemaKey_1.ECVersion.fromString(reference.version));
60
- schemaInfoReferences.push({ schemaKey: refKey });
63
+ schemaReferences.push({ schemaKey: refKey });
61
64
  }
62
65
  this._schemaInfo = schemaInfo;
63
66
  // Need to add this schema to the context to be able to locate schemaItems within the context.
64
- if (!this._context.schemaExists(schema.schemaKey)) {
67
+ if (addSchemaToCache && !this._context.schemaExists(schema.schemaKey)) {
65
68
  await this._context.addSchemaPromise(schemaInfo, schema, this.loadSchema(schemaInfo, schema));
66
69
  }
67
70
  return schemaInfo;
@@ -70,33 +73,53 @@ class SchemaReadHelper {
70
73
  * Populates the given Schema from a serialized representation.
71
74
  * @param schema The Schema to populate
72
75
  * @param rawSchema The serialized data to use to populate the Schema.
76
+ * @param addSchemaToCache Optional parameter that indicates if the schema should be added to the SchemaContext.
77
+ * The default is true. If false, the schema will be loaded directly by this method and not from the context's schema cache.
73
78
  */
74
- async readSchema(schema, rawSchema) {
79
+ async readSchema(schema, rawSchema, addSchemaToCache = true) {
75
80
  if (!this._schemaInfo) {
76
- await this.readSchemaInfo(schema, rawSchema);
81
+ await this.readSchemaInfo(schema, rawSchema, addSchemaToCache);
82
+ }
83
+ // If not adding schema to cache (occurs in readSchemaInfo), we must load the schema here
84
+ if (!addSchemaToCache) {
85
+ const loadedSchema = await this.loadSchema(this._schemaInfo, schema);
86
+ if (undefined === loadedSchema)
87
+ throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLoadSchema, `Could not load schema ${schema.schemaKey.toString()}`);
88
+ return loadedSchema;
77
89
  }
78
90
  const cachedSchema = await this._context.getCachedSchema(this._schemaInfo.schemaKey, ECObjects_1.SchemaMatchType.Latest);
79
91
  if (undefined === cachedSchema)
80
92
  throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLoadSchema, `Could not load schema ${schema.schemaKey.toString()}`);
81
93
  return cachedSchema;
82
94
  }
95
+ /**
96
+ * Called when a SchemaItem has been successfully loaded by the Helper. The default implementation simply
97
+ * checks if the schema item is undefined. An implementation of the helper may choose to partially load
98
+ * a schema item in which case this method would indicate if the item has been fully loaded.
99
+ * @param schemaItem The SchemaItem to check.
100
+ * @returns True if the SchemaItem has been fully loaded, false otherwise.
101
+ */
102
+ isSchemaItemLoaded(schemaItem) {
103
+ return schemaItem !== undefined;
104
+ }
83
105
  /* Finish loading the rest of the schema */
84
106
  async loadSchema(schemaInfo, schema) {
85
107
  // Verify that there are no schema reference cycles, this will start schema loading by loading their headers
86
108
  (await SchemaGraph_1.SchemaGraph.generateGraph(schemaInfo, this._context)).throwIfCycles();
87
109
  for (const reference of schemaInfo.references) {
88
- await this.loadSchemaReference(schemaInfo, reference.schemaKey);
110
+ await this.loadSchemaReference(schema, reference.schemaKey);
89
111
  }
90
112
  if (this._visitorHelper)
91
113
  await this._visitorHelper.visitSchema(schema, false);
92
114
  // Load all schema items
93
115
  for (const [itemName, itemType, rawItem] of this._parser.getItems()) {
94
- // Make sure the item has not already been read. No need to check the SchemaContext because all SchemaItems are added to a Schema,
116
+ // Make sure the item has not already been loaded. No need to check the SchemaContext because all SchemaItems are added to a Schema,
95
117
  // which would be found when adding to the context.
96
- if (await schema.getItem(itemName) !== undefined)
118
+ const schemaItem = await schema.getItem(itemName);
119
+ if (this.isSchemaItemLoaded(schemaItem))
97
120
  continue;
98
121
  const loadedItem = await this.loadSchemaItem(schema, itemName, itemType, rawItem);
99
- if (loadedItem && this._visitorHelper) {
122
+ if (this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
100
123
  await this._visitorHelper.visitSchemaPart(loadedItem);
101
124
  }
102
125
  }
@@ -127,12 +150,8 @@ class SchemaReadHelper {
127
150
  this._visitorHelper.visitSchemaSync(schema, false);
128
151
  // Load all schema items
129
152
  for (const [itemName, itemType, rawItem] of this._parser.getItems()) {
130
- // Make sure the item has not already been read. No need to check the SchemaContext because all SchemaItems are added to a Schema,
131
- // which would be found when adding to the context.
132
- if (schema.getItemSync(itemName) !== undefined)
133
- continue;
134
153
  const loadedItem = this.loadSchemaItemSync(schema, itemName, itemType, rawItem);
135
- if (loadedItem && this._visitorHelper) {
154
+ if (this.isSchemaItemLoaded(loadedItem) && this._visitorHelper) {
136
155
  this._visitorHelper.visitSchemaPartSync(loadedItem);
137
156
  }
138
157
  }
@@ -145,12 +164,14 @@ class SchemaReadHelper {
145
164
  * Ensures that the schema references can be located and adds them to the schema.
146
165
  * @param ref The object to read the SchemaReference's props from.
147
166
  */
148
- async loadSchemaReference(schemaInfo, refKey) {
167
+ async loadSchemaReference(schema, refKey) {
149
168
  const refSchema = await this._context.getSchema(refKey, ECObjects_1.SchemaMatchType.LatestWriteCompatible);
150
169
  if (undefined === refSchema)
151
- throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLocateSchema, `Could not locate the referenced schema, ${refKey.name}.${refKey.version.toString()}, of ${schemaInfo.schemaKey.name}`);
152
- await this._schema.addReference(refSchema);
153
- const results = this.validateSchemaReferences(this._schema);
170
+ throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.UnableToLocateSchema, `Could not locate the referenced schema, ${refKey.name}.${refKey.version.toString()}, of ${schema.schemaKey.name}`);
171
+ if (schema.references.find((ref) => ref.schemaKey.matches(refSchema.schemaKey)))
172
+ return refSchema;
173
+ await schema.addReference(refSchema);
174
+ const results = this.validateSchemaReferences(schema);
154
175
  let errorMessage = "";
155
176
  for (const result of results) {
156
177
  errorMessage += `${result}\r\n`;
@@ -158,6 +179,7 @@ class SchemaReadHelper {
158
179
  if (errorMessage) {
159
180
  throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECJson, `${errorMessage}`);
160
181
  }
182
+ return refSchema;
161
183
  }
162
184
  /**
163
185
  * Ensures that the schema references can be located and adds them to the schema.
@@ -207,73 +229,97 @@ class SchemaReadHelper {
207
229
  * @param schemaItemObject The Object to populate the SchemaItem with.
208
230
  */
209
231
  async loadSchemaItem(schema, name, itemType, schemaItemObject) {
210
- let schemaItem;
232
+ let schemaItem = await schema.getItem(name);
233
+ if (this.isSchemaItemLoaded(schemaItem)) {
234
+ return schemaItem;
235
+ }
211
236
  switch ((0, ECObjects_1.parseSchemaItemType)(itemType)) {
212
237
  case ECObjects_1.SchemaItemType.EntityClass:
213
- schemaItem = await schema.createEntityClass(name);
214
- await this.loadEntityClass(schemaItem, schemaItemObject);
238
+ schemaItem = schemaItem || await schema.createEntityClass(name);
239
+ schemaItemObject && await this.loadEntityClass(schemaItem, schemaItemObject);
215
240
  break;
216
241
  case ECObjects_1.SchemaItemType.StructClass:
217
- schemaItem = await schema.createStructClass(name);
218
- const structProps = this._parser.parseStructClass(schemaItemObject);
219
- await this.loadClass(schemaItem, structProps, schemaItemObject);
242
+ schemaItem = schemaItem || await schema.createStructClass(name);
243
+ const structProps = schemaItemObject && this._parser.parseStructClass(schemaItemObject);
244
+ structProps && await this.loadClass(schemaItem, structProps, schemaItemObject);
220
245
  break;
221
246
  case ECObjects_1.SchemaItemType.Mixin:
222
- schemaItem = await schema.createMixinClass(name);
223
- await this.loadMixin(schemaItem, schemaItemObject);
247
+ schemaItem = schemaItem || await schema.createMixinClass(name);
248
+ schemaItemObject && await this.loadMixin(schemaItem, schemaItemObject);
224
249
  break;
225
250
  case ECObjects_1.SchemaItemType.CustomAttributeClass:
226
- schemaItem = await schema.createCustomAttributeClass(name);
227
- const caClassProps = this._parser.parseCustomAttributeClass(schemaItemObject);
228
- await this.loadClass(schemaItem, caClassProps, schemaItemObject);
251
+ schemaItem = schemaItem || await schema.createCustomAttributeClass(name);
252
+ const caClassProps = schemaItemObject && this._parser.parseCustomAttributeClass(schemaItemObject);
253
+ caClassProps && await this.loadClass(schemaItem, caClassProps, schemaItemObject);
229
254
  break;
230
255
  case ECObjects_1.SchemaItemType.RelationshipClass:
231
- schemaItem = await schema.createRelationshipClass(name);
232
- await this.loadRelationshipClass(schemaItem, schemaItemObject);
256
+ schemaItem = schemaItem || await schema.createRelationshipClass(name);
257
+ schemaItemObject && await this.loadRelationshipClass(schemaItem, schemaItemObject);
233
258
  break;
234
259
  case ECObjects_1.SchemaItemType.KindOfQuantity:
235
- schemaItem = await schema.createKindOfQuantity(name);
236
- await this.loadKindOfQuantity(schemaItem, schemaItemObject);
260
+ schemaItem = schemaItem || await schema.createKindOfQuantity(name);
261
+ schemaItemObject && await this.loadKindOfQuantity(schemaItem, schemaItemObject);
237
262
  break;
238
263
  case ECObjects_1.SchemaItemType.Unit:
239
- schemaItem = await schema.createUnit(name);
240
- await this.loadUnit(schemaItem, schemaItemObject);
264
+ schemaItem = schemaItem || await schema.createUnit(name);
265
+ schemaItemObject && await this.loadUnit(schemaItem, schemaItemObject);
241
266
  break;
242
267
  case ECObjects_1.SchemaItemType.Constant:
243
- schemaItem = await schema.createConstant(name);
244
- await this.loadConstant(schemaItem, schemaItemObject);
268
+ schemaItem = schemaItem || await schema.createConstant(name);
269
+ schemaItemObject && await this.loadConstant(schemaItem, schemaItemObject);
245
270
  break;
246
271
  case ECObjects_1.SchemaItemType.InvertedUnit:
247
- schemaItem = await schema.createInvertedUnit(name);
248
- await this.loadInvertedUnit(schemaItem, schemaItemObject);
272
+ schemaItem = schemaItem || await schema.createInvertedUnit(name);
273
+ schemaItemObject && await this.loadInvertedUnit(schemaItem, schemaItemObject);
249
274
  break;
250
275
  case ECObjects_1.SchemaItemType.Format:
251
- schemaItem = await schema.createFormat(name);
252
- await this.loadFormat(schemaItem, schemaItemObject);
276
+ schemaItem = schemaItem || await schema.createFormat(name);
277
+ schemaItemObject && await this.loadFormat(schemaItem, schemaItemObject);
253
278
  break;
254
279
  case ECObjects_1.SchemaItemType.Phenomenon:
255
- schemaItem = await schema.createPhenomenon(name);
256
- const phenomenonProps = this._parser.parsePhenomenon(schemaItemObject);
257
- await schemaItem.fromJSON(phenomenonProps);
280
+ schemaItem = schemaItem || await schema.createPhenomenon(name);
281
+ const phenomenonProps = schemaItemObject && this._parser.parsePhenomenon(schemaItemObject);
282
+ phenomenonProps && await schemaItem.fromJSON(phenomenonProps);
258
283
  break;
259
284
  case ECObjects_1.SchemaItemType.UnitSystem:
260
- schemaItem = await schema.createUnitSystem(name);
261
- await schemaItem.fromJSON(this._parser.parseUnitSystem(schemaItemObject));
285
+ schemaItem = schemaItem || await schema.createUnitSystem(name);
286
+ schemaItemObject && await schemaItem.fromJSON(this._parser.parseUnitSystem(schemaItemObject));
262
287
  break;
263
288
  case ECObjects_1.SchemaItemType.PropertyCategory:
264
- schemaItem = await schema.createPropertyCategory(name);
265
- const propertyCategoryProps = this._parser.parsePropertyCategory(schemaItemObject);
266
- await schemaItem.fromJSON(propertyCategoryProps);
289
+ schemaItem = schemaItem || await schema.createPropertyCategory(name);
290
+ const propertyCategoryProps = schemaItemObject && this._parser.parsePropertyCategory(schemaItemObject);
291
+ propertyCategoryProps && schemaItemObject && await schemaItem.fromJSON(propertyCategoryProps);
267
292
  break;
268
293
  case ECObjects_1.SchemaItemType.Enumeration:
269
- schemaItem = await schema.createEnumeration(name);
270
- const enumerationProps = this._parser.parseEnumeration(schemaItemObject);
271
- await schemaItem.fromJSON(enumerationProps);
294
+ schemaItem = schemaItem || await schema.createEnumeration(name);
295
+ const enumerationProps = schemaItemObject && this._parser.parseEnumeration(schemaItemObject);
296
+ enumerationProps && await schemaItem.fromJSON(enumerationProps);
272
297
  break;
273
298
  // NOTE: we are being permissive here and allowing unknown types to silently fail. Not sure if we want to hard fail or just do a basic deserialization
274
299
  }
275
300
  return schemaItem;
276
301
  }
302
+ /**
303
+ * Load the customAttribute class dependencies for a set of CustomAttribute objects and add
304
+ * them to a given custom attribute container.
305
+ * @param container The CustomAttributeContainer that each CustomAttribute will be added to.
306
+ * @param customAttributes An iterable set of parsed CustomAttribute objects.
307
+ */
308
+ async loadCustomAttributes(container, caProviders) {
309
+ for (const providerTuple of caProviders) {
310
+ // First tuple entry is the CA class name.
311
+ const caClass = await this.findSchemaItem(providerTuple[0]);
312
+ // If custom attribute exist within the context and is referenced, validate the reference is defined in the container's schema
313
+ if (caClass && caClass.key.schemaName !== container.schema.name &&
314
+ !container.schema.getReferenceSync(caClass.key.schemaName)) {
315
+ throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECJson, `Unable to load custom attribute ${caClass.fullName} from container ${container.fullName}, ${caClass.key.schemaName} reference not defined`);
316
+ }
317
+ // Second tuple entry ia a function that provides the CA instance.
318
+ const provider = providerTuple[1];
319
+ const customAttribute = provider(caClass);
320
+ container.addCustomAttribute(customAttribute);
321
+ }
322
+ }
277
323
  /**
278
324
  * Given the schema item object, the anticipated type and the name a schema item is created and loaded into the schema provided.
279
325
  * @param schema The Schema the SchemaItem to.
@@ -282,66 +328,69 @@ class SchemaReadHelper {
282
328
  * @param schemaItemObject The Object to populate the SchemaItem with.
283
329
  */
284
330
  loadSchemaItemSync(schema, name, itemType, schemaItemObject) {
285
- let schemaItem;
331
+ let schemaItem = schema.getItemSync(name);
332
+ if (this.isSchemaItemLoaded(schemaItem)) {
333
+ return schemaItem;
334
+ }
286
335
  switch ((0, ECObjects_1.parseSchemaItemType)(itemType)) {
287
336
  case ECObjects_1.SchemaItemType.EntityClass:
288
- schemaItem = schema.createEntityClassSync(name);
337
+ schemaItem = schemaItem || schema.createEntityClassSync(name);
289
338
  this.loadEntityClassSync(schemaItem, schemaItemObject);
290
339
  break;
291
340
  case ECObjects_1.SchemaItemType.StructClass:
292
- schemaItem = schema.createStructClassSync(name);
341
+ schemaItem = schemaItem || schema.createStructClassSync(name);
293
342
  const structProps = this._parser.parseStructClass(schemaItemObject);
294
343
  this.loadClassSync(schemaItem, structProps, schemaItemObject);
295
344
  break;
296
345
  case ECObjects_1.SchemaItemType.Mixin:
297
- schemaItem = schema.createMixinClassSync(name);
346
+ schemaItem = schemaItem || schema.createMixinClassSync(name);
298
347
  this.loadMixinSync(schemaItem, schemaItemObject);
299
348
  break;
300
349
  case ECObjects_1.SchemaItemType.CustomAttributeClass:
301
- schemaItem = schema.createCustomAttributeClassSync(name);
350
+ schemaItem = schemaItem || schema.createCustomAttributeClassSync(name);
302
351
  const caClassProps = this._parser.parseCustomAttributeClass(schemaItemObject);
303
352
  this.loadClassSync(schemaItem, caClassProps, schemaItemObject);
304
353
  break;
305
354
  case ECObjects_1.SchemaItemType.RelationshipClass:
306
- schemaItem = schema.createRelationshipClassSync(name);
355
+ schemaItem = schemaItem || schema.createRelationshipClassSync(name);
307
356
  this.loadRelationshipClassSync(schemaItem, schemaItemObject);
308
357
  break;
309
358
  case ECObjects_1.SchemaItemType.KindOfQuantity:
310
- schemaItem = schema.createKindOfQuantitySync(name);
359
+ schemaItem = schemaItem || schema.createKindOfQuantitySync(name);
311
360
  this.loadKindOfQuantitySync(schemaItem, schemaItemObject);
312
361
  break;
313
362
  case ECObjects_1.SchemaItemType.Unit:
314
- schemaItem = schema.createUnitSync(name);
363
+ schemaItem = schemaItem || schema.createUnitSync(name);
315
364
  this.loadUnitSync(schemaItem, schemaItemObject);
316
365
  break;
317
366
  case ECObjects_1.SchemaItemType.Constant:
318
- schemaItem = schema.createConstantSync(name);
367
+ schemaItem = schemaItem || schema.createConstantSync(name);
319
368
  this.loadConstantSync(schemaItem, schemaItemObject);
320
369
  break;
321
370
  case ECObjects_1.SchemaItemType.InvertedUnit:
322
- schemaItem = schema.createInvertedUnitSync(name);
371
+ schemaItem = schemaItem || schema.createInvertedUnitSync(name);
323
372
  this.loadInvertedUnitSync(schemaItem, schemaItemObject);
324
373
  break;
325
374
  case ECObjects_1.SchemaItemType.Format:
326
- schemaItem = schema.createFormatSync(name);
375
+ schemaItem = schemaItem || schema.createFormatSync(name);
327
376
  this.loadFormatSync(schemaItem, schemaItemObject);
328
377
  break;
329
378
  case ECObjects_1.SchemaItemType.Phenomenon:
330
- schemaItem = schema.createPhenomenonSync(name);
379
+ schemaItem = schemaItem || schema.createPhenomenonSync(name);
331
380
  const phenomenonProps = this._parser.parsePhenomenon(schemaItemObject);
332
381
  schemaItem.fromJSONSync(phenomenonProps);
333
382
  break;
334
383
  case ECObjects_1.SchemaItemType.UnitSystem:
335
- schemaItem = schema.createUnitSystemSync(name);
384
+ schemaItem = schemaItem || schema.createUnitSystemSync(name);
336
385
  schemaItem.fromJSONSync(this._parser.parseUnitSystem(schemaItemObject));
337
386
  break;
338
387
  case ECObjects_1.SchemaItemType.PropertyCategory:
339
- schemaItem = schema.createPropertyCategorySync(name);
388
+ schemaItem = schemaItem || schema.createPropertyCategorySync(name);
340
389
  const propertyCategoryProps = this._parser.parsePropertyCategory(schemaItemObject);
341
390
  schemaItem.fromJSONSync(propertyCategoryProps);
342
391
  break;
343
392
  case ECObjects_1.SchemaItemType.Enumeration:
344
- schemaItem = schema.createEnumerationSync(name);
393
+ schemaItem = schemaItem || schema.createEnumerationSync(name);
345
394
  const enumerationProps = this._parser.parseEnumeration(schemaItemObject);
346
395
  schemaItem.fromJSONSync(enumerationProps);
347
396
  break;
@@ -389,7 +438,7 @@ class SchemaReadHelper {
389
438
  const foundItem = this._parser.findItem(itemName);
390
439
  if (foundItem) {
391
440
  schemaItem = await this.loadSchemaItem(this._schema, ...foundItem);
392
- if (!skipVisitor && schemaItem && this._visitorHelper) {
441
+ if (!skipVisitor && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
393
442
  await this._visitorHelper.visitSchemaPart(schemaItem);
394
443
  }
395
444
  if (loadCallBack && schemaItem)
@@ -422,7 +471,7 @@ class SchemaReadHelper {
422
471
  const foundItem = this._parser.findItem(itemName);
423
472
  if (foundItem) {
424
473
  schemaItem = this.loadSchemaItemSync(this._schema, ...foundItem);
425
- if (!skipVisitor && schemaItem && this._visitorHelper) {
474
+ if (!skipVisitor && this.isSchemaItemLoaded(schemaItem) && this._visitorHelper) {
426
475
  this._visitorHelper.visitSchemaPartSync(schemaItem);
427
476
  }
428
477
  if (loadCallBack && schemaItem)
@@ -572,7 +621,7 @@ class SchemaReadHelper {
572
621
  */
573
622
  async loadClass(classObj, classProps, rawClass) {
574
623
  const baseClassLoaded = async (baseClass) => {
575
- if (this._visitorHelper)
624
+ if (this._visitorHelper && this.isSchemaItemLoaded(baseClass))
576
625
  await this._visitorHelper.visitSchemaPart(baseClass);
577
626
  };
578
627
  // Load base class first
@@ -595,7 +644,7 @@ class SchemaReadHelper {
595
644
  */
596
645
  loadClassSync(classObj, classProps, rawClass) {
597
646
  const baseClassLoaded = async (baseClass) => {
598
- if (this._visitorHelper)
647
+ if (this._visitorHelper && this.isSchemaItemLoaded(baseClass))
599
648
  this._visitorHelper.visitSchemaPartSync(baseClass);
600
649
  };
601
650
  // Load base class first
@@ -646,7 +695,7 @@ class SchemaReadHelper {
646
695
  async loadMixin(mixin, rawMixin) {
647
696
  const mixinProps = this._parser.parseMixin(rawMixin);
648
697
  const appliesToLoaded = async (appliesToClass) => {
649
- if (this._visitorHelper)
698
+ if (this._visitorHelper && this.isSchemaItemLoaded(appliesToClass))
650
699
  await this._visitorHelper.visitSchemaPart(appliesToClass);
651
700
  };
652
701
  await this.findSchemaItem(mixinProps.appliesTo, true, appliesToLoaded);
@@ -660,7 +709,7 @@ class SchemaReadHelper {
660
709
  loadMixinSync(mixin, rawMixin) {
661
710
  const mixinProps = this._parser.parseMixin(rawMixin);
662
711
  const appliesToLoaded = async (appliesToClass) => {
663
- if (this._visitorHelper)
712
+ if (this._visitorHelper && this.isSchemaItemLoaded(appliesToClass))
664
713
  await this._visitorHelper.visitSchemaPart(appliesToClass);
665
714
  };
666
715
  this.findSchemaItemSync(mixinProps.appliesTo, true, appliesToLoaded);
@@ -856,27 +905,6 @@ class SchemaReadHelper {
856
905
  propertyObj.fromJSONSync(props);
857
906
  this.loadCustomAttributesSync(propertyObj, this._parser.getPropertyCustomAttributeProviders(rawProperty));
858
907
  }
859
- /**
860
- * Load the customAttribute class dependencies for a set of CustomAttribute objects and add
861
- * them to a given custom attribute container.
862
- * @param container The CustomAttributeContainer that each CustomAttribute will be added to.
863
- * @param customAttributes An iterable set of parsed CustomAttribute objects.
864
- */
865
- async loadCustomAttributes(container, caProviders) {
866
- for (const providerTuple of caProviders) {
867
- // First tuple entry is the CA class name.
868
- const caClass = await this.findSchemaItem(providerTuple[0]);
869
- // If custom attribute exist within the context and is referenced, validate the reference is defined in the container's schema
870
- if (caClass && caClass.key.schemaName !== container.schema.name &&
871
- !container.schema.getReferenceSync(caClass.key.schemaName)) {
872
- throw new Exception_1.ECSchemaError(Exception_1.ECSchemaStatus.InvalidECJson, `Unable to load custom attribute ${caClass.fullName} from container ${container.fullName}, ${caClass.key.schemaName} reference not defined`);
873
- }
874
- // Second tuple entry ia a function that provides the CA instance.
875
- const provider = providerTuple[1];
876
- const customAttribute = provider(caClass);
877
- container.addCustomAttribute(customAttribute);
878
- }
879
- }
880
908
  /**
881
909
  * Load the customAttribute class dependencies for a set of CustomAttribute objects and add them to a given custom attribute container.
882
910
  * @param container The CustomAttributeContainer that each CustomAttribute will be added to.