UNPKG

@itwin/ecschema-rpcinterface-common

Version:

Schema RPC Interface common interface

59 lines 3.23 kB
"use strict"; 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. * @beta */ class ECSchemaRpcLocater { 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) { const schemaJson = await ECSchemaRpcInterface_1.ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name); 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; } /** * 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. */ getSchemaSync(schemaKey, matchType, context) { const schemaJson = ECSchemaRpcInterface_1.ECSchemaRpcInterface.getClient().getSchemaJSON(this.token, schemaKey.name).then((props) => { return props; }); const schema = ecschema_metadata_1.Schema.fromJsonSync(schemaJson, context || new ecschema_metadata_1.SchemaContext()); if (schema !== undefined && schema.schemaKey.matches(schemaKey, matchType)) { return schema; } return undefined; } } exports.ECSchemaRpcLocater = ECSchemaRpcLocater; //# sourceMappingURL=ECSchemaRpcLocater.js.map