@itwin/ecschema-metadata
Version:
ECObjects core concepts in typescript
77 lines • 3.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IncrementalSchemaReader = void 0;
const Helper_1 = require("../Deserialization/Helper");
const JsonParser_1 = require("../Deserialization/JsonParser");
const ECObjects_1 = require("../ECObjects");
const Class_1 = require("../Metadata/Class");
const SchemaItem_1 = require("../Metadata/SchemaItem");
const SchemaLoadingController_1 = require("../utils/SchemaLoadingController");
/**
* Internal helper class to read schema information incrementally. It's based on the [[SchemaReadHelper]]
* but overrides a few methods to support the incremental schema loading case.
* @internal
*/
class IncrementalSchemaReader extends Helper_1.SchemaReadHelper {
_incremental;
/**
* Initializes a new [[IncrementalSchemaReader]] instance.
* @param schemaContext The [[SchemaContext]] used to load the schemas.
* @param incremental Indicates that the Schema should be read incrementally.
* Pass false to load the full schema without an incremental/partial load.
*/
constructor(schemaContext, incremental) {
super(JsonParser_1.JsonParser, schemaContext);
this._incremental = incremental;
}
/**
* Indicates that a given [[SchemaItem]] has been fully loaded.
* @param schemaItem The SchemaItem to check.
* @returns True if the item has been loaded, false if still in progress.
*/
isSchemaItemLoaded(schemaItem) {
return schemaItem !== undefined
&& schemaItem.loadingController !== undefined
&& schemaItem.loadingController.isComplete;
}
/**
* Starts loading the [[SchemaItem]] identified by the given name and itemType.
* @param schema The [[Schema]] that contains the SchemaItem.
* @param name The name of the SchemaItem to load.
* @param itemType The SchemaItem type name of the item to load.
* @param schemaItemObject The object accepting the SchemaItem data.
* @returns A promise that resolves to the loaded SchemaItem instance. Can be undefined.
*/
async loadSchemaItem(schema, name, itemType, schemaItemObject) {
const schemaItem = await super.loadSchemaItem(schema, name, itemType, this._incremental ? undefined : schemaItemObject);
// In incremental mode, we only load the stubs of the classes. These include the modifier and base classes.
// The fromJSON method of the actual class instances may complain about missing properties in the props, so
// calling the fromJSON on the ECClass ensures only the bare minimum is loaded.
if (this._incremental && schemaItemObject && schemaItem) {
if (schemaItem.schemaItemType === ECObjects_1.SchemaItemType.KindOfQuantity) {
SchemaItem_1.SchemaItem.prototype.fromJSONSync.call(schemaItem, schemaItemObject);
}
else {
schemaItem.fromJSONSync(schemaItemObject);
}
}
this.schemaItemLoading(schemaItem);
return schemaItem;
}
schemaItemLoading(schemaItem) {
if (schemaItem === undefined)
return;
if (schemaItem.loadingController === undefined) {
const controller = new SchemaLoadingController_1.SchemaLoadingController();
schemaItem.setLoadingController(controller);
}
if (Class_1.ECClass.isECClass(schemaItem)
|| schemaItem.schemaItemType === ECObjects_1.SchemaItemType.KindOfQuantity
|| schemaItem.schemaItemType === ECObjects_1.SchemaItemType.Format)
schemaItem.loadingController.isComplete = !this._incremental;
else
schemaItem.loadingController.isComplete = true;
}
}
exports.IncrementalSchemaReader = IncrementalSchemaReader;
//# sourceMappingURL=IncrementalSchemaReader.js.map