@itwin/ecschema-rpcinterface-common
Version:
Schema RPC Interface common interface
65 lines • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ECSchemaRpcLocater = void 0;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
const ECSchemaRpcInterface_1 = require("./ECSchemaRpcInterface");
/**
* Defines a schema locater that retrieves schemas using an RPC interface.
* @public @preview
*/
class ECSchemaRpcLocater {
/** @internal */
token;
constructor(token) { this.token = token; }
/**
* Attempts to get a schema from the schema rpc locater. Yields undefined if no matching schema is found.
* @param schemaKey Key to look up
* @param matchType How to match key against candidate schemas
* @param context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
*/
async getSchema(schemaKey, matchType, context) {
await this.getSchemaInfo(schemaKey, matchType, context);
const schema = await context.getCachedSchema(schemaKey, matchType);
return schema;
}
/**
* Gets the schema info which matches the provided SchemaKey. The schema info may be returned before the schema is fully loaded.
* The fully loaded schema can be accessed via the schema context using the getCachedSchema method.
* @param schemaKey The SchemaKey describing the schema to get from the cache.
* @param matchType The match type to use when locating the schema
*/
async getSchemaInfo(schemaKey, matchType, context) {
let schemaJson;
try {
schemaJson = await ECSchemaRpcInterface_1.ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name);
}
catch (e) {
if (e.message && e.message === "schema not found")
return undefined;
throw (e);
}
const schemaInfo = await ecschema_metadata_1.Schema.startLoadingFromJson(schemaJson, context || new ecschema_metadata_1.SchemaContext());
if (schemaInfo !== undefined && schemaInfo.schemaKey.matches(schemaKey, matchType)) {
return schemaInfo;
}
return undefined;
}
/**
* This method is not supported for locating schemas over RPC/HTTP.
* Use the asynchronous `getSchema` method instead.
* @param _schemaKey Key to look up
* @param _matchType How to match key against candidate schemas
* @param _context The SchemaContext that will control the lifetime of the schema and holds the schema's references, if they exist.
* @throws Error Always throws an error indicating this method is not supported.
* @deprecated in 5.0 - will not be removed until after 2026-08-08. Use the asynchronous `getSchema` method for schema retrieval.
*/
getSchemaSync(_schemaKey, _matchType, _context) {
throw new Error("getSchemaSync is not supported. Use the asynchronous getSchema method instead.");
}
}
exports.ECSchemaRpcLocater = ECSchemaRpcLocater;
//# sourceMappingURL=ECSchemaRpcLocater.js.map