@itwin/ecschema-metadata 5.12.0-dev.8 → 5.13.0-dev.1
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.
- package/CHANGELOG.md +11 -1
- package/lib/cjs/Localization/SchemaLocalization.d.ts +1 -1
- package/lib/cjs/Localization/SchemaLocalization.d.ts.map +1 -1
- package/lib/cjs/Localization/SchemaLocalization.js.map +1 -1
- package/lib/cjs/SchemaView/SchemaManifest.d.ts +81 -0
- package/lib/cjs/SchemaView/SchemaManifest.d.ts.map +1 -0
- package/lib/cjs/SchemaView/SchemaManifest.js +131 -0
- package/lib/cjs/SchemaView/SchemaManifest.js.map +1 -0
- package/lib/cjs/{SchemaView.d.ts → SchemaView/SchemaView.d.ts} +23 -90
- package/lib/cjs/SchemaView/SchemaView.d.ts.map +1 -0
- package/lib/cjs/{SchemaView.js → SchemaView/SchemaView.js} +32 -198
- package/lib/cjs/SchemaView/SchemaView.js.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewBinaryReader.d.ts +37 -0
- package/lib/cjs/SchemaView/SchemaViewBinaryReader.d.ts.map +1 -0
- package/lib/cjs/{SchemaViewBinaryReader.js → SchemaView/SchemaViewBinaryReader.js} +84 -43
- package/lib/cjs/SchemaView/SchemaViewBinaryReader.js.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewBuilder.d.ts +116 -0
- package/lib/cjs/SchemaView/SchemaViewBuilder.d.ts.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewBuilder.js +230 -0
- package/lib/cjs/SchemaView/SchemaViewBuilder.js.map +1 -0
- package/lib/cjs/{SchemaViewInterfaces.d.ts → SchemaView/SchemaViewInterfaces.d.ts} +1 -1
- package/lib/cjs/SchemaView/SchemaViewInterfaces.d.ts.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewInterfaces.js.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewManager.d.ts +114 -0
- package/lib/cjs/SchemaView/SchemaViewManager.d.ts.map +1 -0
- package/lib/cjs/SchemaView/SchemaViewManager.js +184 -0
- package/lib/cjs/SchemaView/SchemaViewManager.js.map +1 -0
- package/lib/cjs/ecschema-metadata.d.ts +6 -3
- package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
- package/lib/cjs/ecschema-metadata.js +6 -3
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/lib/esm/Localization/SchemaLocalization.d.ts +1 -1
- package/lib/esm/Localization/SchemaLocalization.d.ts.map +1 -1
- package/lib/esm/Localization/SchemaLocalization.js.map +1 -1
- package/lib/esm/SchemaView/SchemaManifest.d.ts +81 -0
- package/lib/esm/SchemaView/SchemaManifest.d.ts.map +1 -0
- package/lib/esm/SchemaView/SchemaManifest.js +127 -0
- package/lib/esm/SchemaView/SchemaManifest.js.map +1 -0
- package/lib/esm/{SchemaView.d.ts → SchemaView/SchemaView.d.ts} +23 -90
- package/lib/esm/SchemaView/SchemaView.d.ts.map +1 -0
- package/lib/esm/{SchemaView.js → SchemaView/SchemaView.js} +32 -197
- package/lib/esm/SchemaView/SchemaView.js.map +1 -0
- package/lib/esm/SchemaView/SchemaViewBinaryReader.d.ts +37 -0
- package/lib/esm/SchemaView/SchemaViewBinaryReader.d.ts.map +1 -0
- package/lib/esm/{SchemaViewBinaryReader.js → SchemaView/SchemaViewBinaryReader.js} +82 -43
- package/lib/esm/SchemaView/SchemaViewBinaryReader.js.map +1 -0
- package/lib/esm/SchemaView/SchemaViewBuilder.d.ts +116 -0
- package/lib/esm/SchemaView/SchemaViewBuilder.d.ts.map +1 -0
- package/lib/esm/SchemaView/SchemaViewBuilder.js +226 -0
- package/lib/esm/SchemaView/SchemaViewBuilder.js.map +1 -0
- package/lib/esm/{SchemaViewInterfaces.d.ts → SchemaView/SchemaViewInterfaces.d.ts} +1 -1
- package/lib/esm/SchemaView/SchemaViewInterfaces.d.ts.map +1 -0
- package/lib/esm/SchemaView/SchemaViewInterfaces.js.map +1 -0
- package/lib/esm/SchemaView/SchemaViewManager.d.ts +114 -0
- package/lib/esm/SchemaView/SchemaViewManager.d.ts.map +1 -0
- package/lib/esm/SchemaView/SchemaViewManager.js +180 -0
- package/lib/esm/SchemaView/SchemaViewManager.js.map +1 -0
- package/lib/esm/ecschema-metadata.d.ts +6 -3
- package/lib/esm/ecschema-metadata.d.ts.map +1 -1
- package/lib/esm/ecschema-metadata.js +6 -3
- package/lib/esm/ecschema-metadata.js.map +1 -1
- package/package.json +8 -8
- package/lib/cjs/SchemaView.d.ts.map +0 -1
- package/lib/cjs/SchemaView.js.map +0 -1
- package/lib/cjs/SchemaViewBinaryReader.d.ts +0 -16
- package/lib/cjs/SchemaViewBinaryReader.d.ts.map +0 -1
- package/lib/cjs/SchemaViewBinaryReader.js.map +0 -1
- package/lib/cjs/SchemaViewInterfaces.d.ts.map +0 -1
- package/lib/cjs/SchemaViewInterfaces.js.map +0 -1
- package/lib/esm/SchemaView.d.ts.map +0 -1
- package/lib/esm/SchemaView.js.map +0 -1
- package/lib/esm/SchemaViewBinaryReader.d.ts +0 -16
- package/lib/esm/SchemaViewBinaryReader.d.ts.map +0 -1
- package/lib/esm/SchemaViewBinaryReader.js.map +0 -1
- package/lib/esm/SchemaViewInterfaces.d.ts.map +0 -1
- package/lib/esm/SchemaViewInterfaces.js.map +0 -1
- /package/lib/cjs/{SchemaViewInterfaces.js → SchemaView/SchemaViewInterfaces.js} +0 -0
- /package/lib/esm/{SchemaViewInterfaces.js → SchemaView/SchemaViewInterfaces.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaViewManager.js","sourceRoot":"","sources":["../../../src/SchemaView/SchemaViewManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,6CAA0C;AA8D1C;;;;;GAKG;AACH,MAAa,iBAAiB;IACX,aAAa,CAAyB;IAEvD;wEACoE;IAC5D,YAAY,CAAmC;IAEvD,qGAAqG;IAC7F,SAAS,CAAkB;IAEnC,iGAAiG;IACzF,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AQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;YAC7K,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArLD,8CAqLC","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 { SchemaManifest } from \"./SchemaManifest\";\nimport { SchemaView } from \"./SchemaView\";\n\n/** One schema-view blob with its cache-invalidation token, as fetched by a\n * {@link SchemaViewDataProvider}. Full and fragment blobs share this shape.\n * @internal\n */\nexport interface SchemaViewBlob {\n /** The binary schema metadata (the `data` column of `PRAGMA schema_view` / `schema_view_fragment`). */\n readonly data: Uint8Array;\n /** Schema-identity hash of the iModel's whole schema set (the `schemaToken` column). Empty string when unavailable. */\n readonly schemaToken: string;\n}\n\n/** The data source a {@link SchemaViewManager} loads schema-view data from, implemented by the hosts\n * that own the query APIs: `IModelDb` on the backend and `IModelConnection` on the frontend. The\n * manager deals only in schema names, blobs and the manifest; everything transport-specific - pragma\n * strings, format-version pinning - belongs to the provider.\n * @internal\n */\nexport interface SchemaViewDataProvider {\n /** Fetch the blob containing every schema in the iModel (`PRAGMA schema_view`). */\n fetchFullBlob(): Promise<SchemaViewBlob>;\n\n /** Fetch one blob containing exactly the given schemas (`PRAGMA schema_view_fragment`). The\n * requested set is always dependency-closed - the manager computes the reference closure from the\n * manifest before calling. */\n fetchFragmentBlob(schemaNames: readonly string[]): Promise<SchemaViewBlob>;\n\n /** Fetch the reference graph of every schema in the iModel, built from ECDbMeta\n * (`meta.ECSchemaDef` + `meta.SchemaHasSchemaReferences`; see {@link SchemaManifest.fromRows}). */\n fetchManifest(): Promise<SchemaManifest>;\n\n /** Fetch the current schema-identity token (`PRAGMA checksum(schema_token)`). */\n fetchSchemaToken(): Promise<string>;\n}\n\n/** Options for `getSchemaView` (see `IModelDb.getSchemaView` / `IModelConnection.getSchemaView`,\n * which delegate to {@link SchemaViewManager.getSchemaView}).\n * @beta\n */\nexport interface GetSchemaViewArgs {\n /** When provided, return a view loaded with at least these schemas plus their references, instead\n * of every schema in the iModel.\n *\n * The view accumulates: one instance is reused across calls, so a later request - with different\n * schemas or with no filter at all - merges the still-missing schemas into the same view and\n * everything requested earlier stays available. It resets when the iModel's schemas change.\n *\n * Names the iModel does not contain are ignored. Omitting this option loads all schemas, identical\n * to calling `getSchemaView()` with no arguments.\n */\n readonly schemas?: readonly string[];\n\n /** When `true`, discard whatever is currently loaded and rebuild the view from scratch before\n * returning it. The previously returned view instance (if any) is marked outdated. Like every other\n * request this is serialized behind any in-flight load, so it never leaves the view in an invalid\n * intermediate state.\n * @internal\n */\n readonly forceReload?: boolean;\n}\n\n/** Owns the lifetime of one iModel's {@link (SchemaView:class)}: lazy loading, incremental (filtered)\n * hydration, serialization of concurrent requests, and invalidation. Hosts (`IModelDb`,\n * `IModelConnection`) hold one instance and delegate to it; all data access goes through the\n * host-implemented {@link SchemaViewDataProvider}.\n * @internal\n */\nexport class SchemaViewManager {\n private readonly _dataProvider: SchemaViewDataProvider;\n\n /** The single accumulating view, held as a promise so all requests chain onto it and never overlap.\n * Undefined (or resolving to undefined) means nothing is loaded. */\n private _viewPromise?: Promise<SchemaView | undefined>;\n\n /** Reference graph for incremental loading; undefined when the view is (or will be) fully loaded. */\n private _manifest?: SchemaManifest;\n\n /** Schema-identity token the manifest - and thus every fragment merged under it - belongs to. */\n private _manifestToken?: string;\n\n /** Lower-cased names already merged into the view (incremental mode only). */\n private readonly _loadedSchemaNames = new Set<string>();\n\n public constructor(dataProvider: SchemaViewDataProvider) {\n this._dataProvider = dataProvider;\n }\n\n /** Get the schema view, loading whatever the request needs that is not present yet. See\n * {@link GetSchemaViewArgs} for filtering and reload semantics; hosts document the full\n * user-facing contract on their `getSchemaView` methods.\n */\n public async getSchemaView(args?: GetSchemaViewArgs): Promise<SchemaView> {\n const previous = this._viewPromise;\n const next = this._loadSchemaView(previous, args?.schemas, args?.forceReload === true);\n this._viewPromise = next;\n return next;\n }\n\n /** Throw away the current schema view. Called by the host when schemas may have changed (e.g.\n * `IModelDb.clearCaches` after a schema import). Chains behind any in-flight load and marks the\n * discarded view outdated; the next getSchemaView starts over.\n */\n public reset(): void {\n if (this._viewPromise) {\n this._viewPromise = this._viewPromise.then(\n (view) => { view?.markOutdated(); this._resetIncrementalState(); return undefined; },\n () => { this._resetIncrementalState(); return undefined; },\n );\n }\n }\n\n /** Check whether the iModel's schemas have changed since the current view was built, and discard\n * the view only if they have. For hosts that *cannot* determine whether an operation actually\n * modified schemas - e.g. `BriefcaseConnection.pullChanges` on the frontend, whose IPC response\n * carries only the new changeset id, not the applied changesets' types. Discarding after every\n * such operation would reload unnecessarily in the common case where schemas are unchanged, so\n * this compares the cheap schema-identity token instead.\n * @note If the token cannot be fetched, the view is discarded rather than risking stale metadata.\n */\n public async invalidateIfChanged(): Promise<void> {\n const previous = this._viewPromise;\n if (previous === undefined)\n return;\n // Queue the check on the same chain as loading, so a getSchemaView arriving while the token is\n // in flight cannot swap in a new promise for the same stale view and hide the schema change.\n const next = this._invalidateIfChanged(previous);\n this._viewPromise = next;\n await next;\n }\n\n /** Serialized body of {@link SchemaViewManager.invalidateIfChanged}. Resolves to the view to keep,\n * or to `undefined` when it was discarded and the next getSchemaView has to start over.\n */\n private async _invalidateIfChanged(previous: Promise<SchemaView | undefined>): Promise<SchemaView | undefined> {\n let existing: SchemaView | undefined;\n try {\n existing = await previous;\n } catch {\n return undefined;\n }\n if (existing === undefined)\n return undefined;\n // A view without a token (e.g. built directly from a SchemaViewBuilder) cannot be verified by\n // token; views loaded through this manager always carry one.\n if (existing.schemaToken === \"\")\n return existing;\n\n try {\n if (await this._dataProvider.fetchSchemaToken() === existing.schemaToken)\n return existing;\n } catch {\n // Cannot verify the cached view: drop it rather than risk stale metadata.\n }\n existing.markOutdated();\n this._resetIncrementalState();\n return undefined;\n }\n\n /** Serialized body of {@link SchemaViewManager.getSchemaView}. On failure it resets and rejects,\n * so the next call starts over.\n */\n private async _loadSchemaView(previous: Promise<SchemaView | undefined> | undefined, schemas: readonly string[] | undefined, forceReload: boolean): Promise<SchemaView> {\n let currentView: SchemaView | undefined;\n if (previous !== undefined) {\n try {\n currentView = await previous;\n } catch {\n currentView = undefined; // the failed load already reset; start over\n }\n }\n\n if (forceReload) {\n currentView?.markOutdated();\n currentView = undefined;\n this._resetIncrementalState();\n }\n\n try {\n return await this._ensureSchemasLoaded(currentView, schemas);\n } catch (err) {\n // A failed merge may have left the view partially extended - discard everything.\n currentView?.markOutdated();\n this._resetIncrementalState();\n throw err;\n }\n }\n\n /** Clear the incremental schema-view bookkeeping. */\n private _resetIncrementalState(): void {\n this._manifest = undefined;\n this._manifestToken = undefined;\n this._loadedSchemaNames.clear();\n }\n\n /** Ensures the requested schemas (or all schemas, when no filter is given) are present in\n * `currentView` (or a freshly created view) and returns it. The first load fixes the strategy:\n * no filter fetches everything as one full blob; a filter fetches fragments and keeps the\n * manifest and loaded-name set so later calls extend the same view. Once every schema is loaded\n * the incremental state is dropped, collapsing back to full mode.\n */\n private async _ensureSchemasLoaded(currentView: SchemaView | undefined, schemas: readonly string[] | undefined, isRetry = false): Promise<SchemaView> {\n const isFirstLoad = currentView === undefined;\n // No manifest means everything is loaded; in incremental mode a filtered request is satisfied as\n // soon as every requested name is present.\n if (!isFirstLoad &&\n (this._manifest === undefined ||\n (schemas !== undefined && schemas.every((name) => this._loadedSchemaNames.has(name.toLowerCase())))))\n return currentView;\n\n if (isFirstLoad && schemas === undefined) {\n const blob = await this._dataProvider.fetchFullBlob();\n const schemaView = SchemaView.fromBinary(blob.data, blob.schemaToken);\n this._resetIncrementalState();\n return schemaView;\n }\n\n if (this._manifest === undefined) {\n // Token first: any schema change after this point shows up as a token mismatch below.\n this._manifestToken = await this._dataProvider.fetchSchemaToken();\n this._manifest = await this._dataProvider.fetchManifest();\n }\n const manifest = this._manifest;\n\n const requested = schemas ?? manifest.getAvailableSchemaNames();\n const namesToLoad = manifest.getSchemaClosure(requested).filter((name) => !this._loadedSchemaNames.has(name.toLowerCase()));\n const husk = currentView ?? SchemaView.createMergeable(this._manifestToken);\n if (namesToLoad.length > 0) {\n const blob = await this._dataProvider.fetchFragmentBlob(namesToLoad);\n if (blob.schemaToken !== this._manifestToken) {\n // Schemas changed between the manifest and fragment fetches. Everything loaded so far\n // belongs to the old revision - discard it and start over, once.\n currentView?.markOutdated();\n this._resetIncrementalState();\n if (isRetry)\n throw new Error(\"The iModel's schemas changed while the schema view was loading.\");\n return this._ensureSchemasLoaded(undefined, schemas, true);\n }\n husk.mergeFragment(blob.data);\n // Record the whole closure as loaded, including *excluded* schemas (e.g. CoreCustomAttributes)\n // the writer emits no rows for, so later requests prune them instead of re-fetching.\n for (const name of namesToLoad)\n this._loadedSchemaNames.add(name.toLowerCase());\n }\n // Once every schema is loaded, collapse back to full mode (the size check is just a fast path).\n if (schemas === undefined || (this._loadedSchemaNames.size >= manifest.schemaCount && manifest.entries.every((entry) => this._loadedSchemaNames.has(entry.name.toLowerCase()))))\n this._resetIncrementalState();\n return husk;\n }\n}\n"]}
|
|
@@ -41,9 +41,12 @@ export * from "./IncrementalLoading/ECSqlSchemaLocater";
|
|
|
41
41
|
export * from "./IncrementalLoading/IncrementalSchemaLocater";
|
|
42
42
|
export { CustomAttribute, CustomAttributeContainerProps } from "./Metadata/CustomAttribute";
|
|
43
43
|
export { SchemaGraph } from "./utils/SchemaGraph";
|
|
44
|
-
export * from "./SchemaViewBinaryReader";
|
|
45
|
-
export * from "./SchemaView";
|
|
46
|
-
export * from "./
|
|
44
|
+
export * from "./SchemaView/SchemaViewBinaryReader";
|
|
45
|
+
export * from "./SchemaView/SchemaView";
|
|
46
|
+
export * from "./SchemaView/SchemaViewBuilder";
|
|
47
|
+
export * from "./SchemaView/SchemaViewInterfaces";
|
|
48
|
+
export * from "./SchemaView/SchemaManifest";
|
|
49
|
+
export * from "./SchemaView/SchemaViewManager";
|
|
47
50
|
export * from "./Localization/LocalizationTypes";
|
|
48
51
|
export * from "./Localization/LocalizationProvider";
|
|
49
52
|
export * from "./Localization/SchemaLocalization";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-metadata.d.ts","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":"AAKA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC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BAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,+CAA+C,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAElD;;GAEG;AACH;;;GAGG;AACH;;;GAGG"}
|
|
@@ -90,9 +90,12 @@ __exportStar(require("./IncrementalLoading/ECSqlSchemaLocater"), exports);
|
|
|
90
90
|
__exportStar(require("./IncrementalLoading/IncrementalSchemaLocater"), exports);
|
|
91
91
|
var SchemaGraph_1 = require("./utils/SchemaGraph");
|
|
92
92
|
Object.defineProperty(exports, "SchemaGraph", { enumerable: true, get: function () { return SchemaGraph_1.SchemaGraph; } });
|
|
93
|
-
__exportStar(require("./SchemaViewBinaryReader"), exports);
|
|
94
|
-
__exportStar(require("./SchemaView"), exports);
|
|
95
|
-
__exportStar(require("./
|
|
93
|
+
__exportStar(require("./SchemaView/SchemaViewBinaryReader"), exports);
|
|
94
|
+
__exportStar(require("./SchemaView/SchemaView"), exports);
|
|
95
|
+
__exportStar(require("./SchemaView/SchemaViewBuilder"), exports);
|
|
96
|
+
__exportStar(require("./SchemaView/SchemaViewInterfaces"), exports);
|
|
97
|
+
__exportStar(require("./SchemaView/SchemaManifest"), exports);
|
|
98
|
+
__exportStar(require("./SchemaView/SchemaViewManager"), exports);
|
|
96
99
|
__exportStar(require("./Localization/LocalizationTypes"), exports);
|
|
97
100
|
__exportStar(require("./Localization/LocalizationProvider"), exports);
|
|
98
101
|
__exportStar(require("./Localization/SchemaLocalization"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecschema-metadata.js","sourceRoot":"","sources":["../../src/ecschema-metadata.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;AAE/F,8CAA4B;AAC5B,4CAA0B;AAC1B,mDAAiC;AACjC,oEAAkD;AAClD,8DAA4C;AAC5C,2DAAyC;AACzC,8DAA4C;AAC5C,2CAAyB;AACzB,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,0CAAwD;AAA/C,gGAAA,OAAO,OAAA;AAAE,oGAAA,WAAW,OAAA;AAC7B,gDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AACjB,wEAAuE;AAA9D,4HAAA,oBAAoB,OAAA;AAC7B,sDAAqD;AAA5C,0GAAA,WAAW,OAAA;AACpB,sDAAgF;AAAxD,0GAAA,WAAW,OAAA;AACnC,4CAA2C;AAAlC,gGAAA,MAAM,OAAA;AACf,wDAAuD;AAA9C,4GAAA,YAAY,OAAA;AACrB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,0CAAyC;AAAhC,8FAAA,KAAK,OAAA;AACd,4DAA0C;AAC1C,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,gDAI6B;AAH3B,oGAAA,QAAQ,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAAE,0GAA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AuD;AAA9C,4GAAA,YAAY,OAAA;AACrB,4DAA2D;AAAlD,gHAAA,cAAc,OAAA;AACvB,0CAAyC;AAAhC,8FAAA,KAAK,OAAA;AACd,4DAA0C;AAC1C,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,gDAI6B;AAH3B,oGAAA,QAAQ,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxF,+GAAA,mBAAmB,OAAA;AAAE,oHAAA,wBAAwB,OAAA;AAAE,8GAAA,kBAAkB,OAAA;AACX,yGAAA,aAAa,OAAA;AAAE,uHAAA,2BAA2B,OAAA;AAElG,gEAA+D;AAAtD,oHAAA,gBAAgB,OAAA;AACzB,kEAAmH;AAA1G,sHAAA,iBAAiB,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAAE,6HAAA,wBAAwB,OAAA;AAC5E,4CAA2C;AAAlC,gGAAA,MAAM,OAAA;AACf,wDAAsC;AACtC,wCAAuC;AAA9B,4FAAA,IAAI,OAAA;AACb,oDAAmD;AAA1C,wGAAA,UAAU,OAAA;AACnB,kDAAgC;AAChC,sDAAoC;AACpC,8CAA4B;AAC5B,iDAA+B;AAC/B,iEAA+C;AAC/C,oEAAkD;AAClD,4DAA0C;AAC1C,8DAA4C;AAC5C,qEAAmD;AACnD,wEAAsD;AACtD,0EAAwD;AACxD,gFAA8D;AAE9D,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AACpB,sEAAoD;AACpD,0DAAwC;AACxC,iEAA+C;AAC/C,oEAAkD;AAClD,8DAA4C;AAC5C,iEAA+C;AAC/C,mEAAiD;AACjD,sEAAoD;AACpD,oEAAkD;AAElD;;GAEG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Constants\";\nexport * from \"./Context\";\nexport * from \"./DelayedPromise\";\nexport * from \"./Deserialization/SchemaGraphUtil\";\nexport * from \"./Deserialization/JsonProps\";\nexport * from \"./Deserialization/Helper\";\nexport * from \"./Deserialization/XmlParser\";\nexport * from \"./ECName\";\nexport * from \"./ECObjects\";\nexport * from \"./Exception\";\nexport * from \"./Interfaces\";\nexport { ECClass, StructClass } from \"./Metadata/Class\";\nexport { Constant } from \"./Metadata/Constant\";\nexport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\nexport { EntityClass } from \"./Metadata/EntityClass\";\nexport { AnyEnumerator, Enumeration, Enumerator } from \"./Metadata/Enumeration\";\nexport { Format } from \"./Metadata/Format\";\nexport { InvertedUnit } from \"./Metadata/InvertedUnit\";\nexport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\nexport { Mixin } from \"./Metadata/Mixin\";\nexport * from \"./Metadata/OverrideFormat\";\nexport { Phenomenon } from \"./Metadata/Phenomenon\";\nexport {\n Property, PrimitiveProperty, PrimitiveArrayProperty, EnumerationProperty, StructProperty,\n StructArrayProperty, EnumerationArrayProperty, NavigationProperty, AnyArrayProperty, AnyEnumerationProperty,\n AnyPrimitiveProperty, AnyProperty, AnyStructProperty, ArrayProperty, PrimitiveOrEnumPropertyBase,\n} from \"./Metadata/Property\";\nexport { PropertyCategory } from \"./Metadata/PropertyCategory\";\nexport { RelationshipClass, RelationshipConstraint, RelationshipMultiplicity } from \"./Metadata/RelationshipClass\";\nexport { Schema } from \"./Metadata/Schema\";\nexport * from \"./Metadata/SchemaItem\";\nexport { Unit } from \"./Metadata/Unit\";\nexport { UnitSystem } from \"./Metadata/UnitSystem\";\nexport * from \"./PropertyTypes\";\nexport * from \"./SchemaJsonLocater\";\nexport * from \"./SchemaKey\";\nexport * from \"./SchemaLoader\";\nexport * from \"./UnitConversion/UnitConverter\";\nexport * from \"./UnitProvider/SchemaUnitProvider\";\nexport * from \"./Validation/SchemaWalker\";\nexport * from \"./SchemaPartVisitorDelegate\";\nexport * from \"./Formatting/SchemaFormatsProvider\";\nexport * from \"./Formatting/FormatSetFormatsProvider\";\nexport * from \"./IncrementalLoading/ECSqlSchemaLocater\";\nexport * from \"./IncrementalLoading/IncrementalSchemaLocater\";\nexport { CustomAttribute, CustomAttributeContainerProps } from \"./Metadata/CustomAttribute\";\nexport { SchemaGraph } from \"./utils/SchemaGraph\";\nexport * from \"./SchemaView/SchemaViewBinaryReader\";\nexport * from \"./SchemaView/SchemaView\";\nexport * from \"./SchemaView/SchemaViewBuilder\";\nexport * from \"./SchemaView/SchemaViewInterfaces\";\nexport * from \"./SchemaView/SchemaManifest\";\nexport * from \"./SchemaView/SchemaViewManager\";\nexport * from \"./Localization/LocalizationTypes\";\nexport * from \"./Localization/LocalizationProvider\";\nexport * from \"./Localization/SchemaLocalization\";\n\n/** @docs-package-description\n * The ecschema-metadata package contains classes for working with ECSchemas that can be used in both [frontend]($docs/learning/frontend/index.md) and [backend]($docs/learning/backend/index.md).\n */\n/**\n * @docs-group-description Metadata\n * Definitions of classes and interfaces that represent all [EC elements]($docs/bis/ec/index.md).\n */\n/**\n * @docs-group-description Utils\n * A set of utility classes used throughout the package.\n */\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaKey } from "../SchemaKey";
|
|
2
|
-
import { SchemaView } from "../SchemaView";
|
|
2
|
+
import { SchemaView } from "../SchemaView/SchemaView";
|
|
3
3
|
import { Schema } from "../Metadata/Schema";
|
|
4
4
|
import { ECClass } from "../Metadata/Class";
|
|
5
5
|
import { Property } from "../Metadata/Property";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaLocalization.d.ts","sourceRoot":"","sources":["../../../src/Localization/SchemaLocalization.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":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AAO,IAAI,EAAE,KAAK,CAAC;QACrB,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC5C,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,YAAgD,EAAE,QAAiB,EAAE,UAAmB;QACjH,IAAI,CAAC,YAAY;YACf,OAAO,SAAS,CAAC;QACnB,IAAI,CAAC,QAAQ;YACX,OAAO,YAAY,CAAC,WAAW,CAAC;QAClC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU;YACb,OAAO,IAAI,EAAE,WAAW,CAAC;QAC3B,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC;IAClD,CAAC;CACF","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\nimport { SchemaKey } from \"../SchemaKey\";\nimport { SchemaView } from \"../SchemaView\";\nimport { Schema } from \"../Metadata/Schema\";\nimport { ECClass } from \"../Metadata/Class\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { Property } from \"../Metadata/Property\";\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\nimport { ILocalizationProvider } from \"./LocalizationProvider\";\nimport { AnyEnumerator, Enumeration } from \"../Metadata/Enumeration\";\nimport { LocalizedText, SchemaLocalizationJson } from \"./LocalizationTypes\";\n\nconst loggerCategory = \"SchemaLocalization\";\n\ntype SchemaViewItem = SchemaView.Class | SchemaView.Enumeration | SchemaView.KindOfQuantity | SchemaView.PropertyCategory;\n\n/**\n * Manages schema localization to provide localized labels and descriptions.\n * @beta\n */\nexport class SchemaLocalization {\n private _provider: ILocalizationProvider;\n private _locale: string;\n private _cache: Map<string, SchemaLocalizationJson | undefined> = new Map();\n\n private constructor(provider: ILocalizationProvider, locale: string) {\n this._provider = provider;\n this._locale = locale;\n }\n\n private get _baseLocale(): string | undefined {\n return this._locale.includes(\"-\") ? this._locale.split(\"-\")[0] : undefined;\n }\n\n private cacheKey(schemaName: string, locale: string): string {\n return `${schemaName}:${locale}`;\n }\n\n /**\n * Create a SchemaLocalization instance and pre-load localization files for the given schemas.\n * @param provider The localization provider to use for loading localization files\n * @param locale The target locale (e.g., \"de\", \"fr\", \"es-CO\")\n * @param schemas The schemas whose localization should be pre-loaded\n */\n public static async create(provider: ILocalizationProvider, locale: string, schemaKeys: Iterable<SchemaKey>): Promise<SchemaLocalization> {\n const localization = new SchemaLocalization(provider, locale);\n await localization.loadLocalizations(schemaKeys);\n return localization;\n }\n\n public get locale(): string {\n return this._locale;\n }\n\n public setLocale(locale: string): void {\n this._locale = locale;\n this._cache.clear();\n }\n\n /**\n * Get localization provider.\n */\n public get provider(): ILocalizationProvider {\n return this._provider;\n }\n\n /**\n * Load localizations for the given schema keys.\n * @param schemaKeys The schema keys to load localization for\n */\n public async loadLocalizations(schemaKeys: Iterable<SchemaKey>): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const key of schemaKeys) {\n promises.push(this.loadLocalizationInfo(key.name, key.readVersion, this._locale));\n if (this._baseLocale !== undefined)\n promises.push(this.loadLocalizationInfo(key.name, key.readVersion, this._baseLocale));\n }\n await Promise.all(promises);\n }\n\n /**\n * Get a localized label for a schema, schema item, or member.\n */\n public getLabel(schemaName: string, itemName?: string, memberName?: string): string | undefined {\n const localization = this.getCachedLocalization(schemaName, this._locale);\n const label = this.resolveLabel(localization, itemName, memberName);\n if (label)\n return label;\n\n if (this._baseLocale) {\n const baseLocalization = this.getCachedLocalization(schemaName, this._baseLocale);\n return this.resolveLabel(baseLocalization, itemName, memberName);\n }\n\n return undefined;\n }\n\n /**\n * Get a localized description for a schema, schema item, or member.\n */\n public getDescription(schemaName: string, itemName?: string, memberName?: string): string | undefined {\n const localization = this.getCachedLocalization(schemaName, this._locale);\n const description = this.resolveDescription(localization, itemName, memberName);\n if (description)\n return description;\n\n if (this._baseLocale) {\n const baseLocalization = this.getCachedLocalization(schemaName, this._baseLocale);\n return this.resolveDescription(baseLocalization, itemName, memberName);\n }\n\n return undefined;\n }\n\n /**\n * Get localized label and description of a schema.\n * Label fallback: localized label → base locale label → original label → schema name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedSchema(schema: Schema | SchemaView.Schema): LocalizedText {\n const label = this.getLabel(schema.name) ?? (schema.label || schema.name);\n const description = this.getDescription(schema.name) ?? schema.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of a schema item (class, enumeration, unit, etc.).\n * Label fallback: localized label → base locale label → original label → item name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedSchemaItem(item: SchemaItem | SchemaViewItem): LocalizedText {\n const label = this.getLabel(item.schema.name, item.name) ?? (item.label || item.name);\n const description = this.getDescription(item.schema.name, item.name) ?? item.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of a property.\n * Label fallback: localized label → base locale label → original label → property name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedProperty(ecClass: ECClass | SchemaView.Class, property: Property | SchemaView.Property): LocalizedText {\n const label = this.getLabel(ecClass.schema.name, ecClass.name, property.name) ?? (property.label || property.name);\n const description = this.getDescription(ecClass.schema.name, ecClass.name, property.name) ?? property.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of an enumerator.\n * Label fallback: localized label → base locale label → original label → enumerator name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedEnumerator(enumeration: Enumeration | SchemaView.Enumeration, enumerator: AnyEnumerator | SchemaView.Enumerator): LocalizedText {\n const label = this.getLabel(enumeration.schema.name, enumeration.name, enumerator.name) ?? (enumerator.label || enumerator.name);\n const description = this.getDescription(enumeration.schema.name, enumeration.name, enumerator.name) ?? enumerator.description;\n return { label, description };\n }\n\n /**\n * Load localization information for a specific schema and locale.\n */\n private async loadLocalizationInfo(schemaName: string, readVersion: number, locale: string): Promise<void> {\n const cacheKey = this.cacheKey(schemaName, locale);\n if (this._cache.has(cacheKey))\n return;\n\n const localization = await this._provider.getLocalization(schemaName, locale);\n if (localization?.version) {\n const localizationMajor = this.getMajorVersion(localization.version);\n if (localizationMajor === undefined || readVersion !== localizationMajor) {\n Logger.logWarning(loggerCategory, `Localization version mismatch for schema \"${schemaName}\". Schema major version is ${readVersion.toString()}, but localization is for major version ${localizationMajor?.toString() ?? \"undefined\"}.`);\n this._cache.set(cacheKey, undefined);\n return;\n }\n }\n\n this._cache.set(cacheKey, localization);\n }\n\n /**\n * Get major version from version string\n */\n private getMajorVersion(version: string): number | undefined {\n const rawVersion = version.split(\".\");\n if (rawVersion.length > 0) {\n const majorVersion = parseInt(rawVersion[0], 10);\n return isNaN(majorVersion) ? undefined : majorVersion;\n }\n return undefined;\n }\n\n /**\n * Retrieve the cached localization for a locale\n */\n private getCachedLocalization(schemaName: string, locale: string): SchemaLocalizationJson | undefined {\n const cacheKey = this.cacheKey(schemaName, locale);\n return this._cache.get(cacheKey);\n }\n\n /**\n * Resolve a label from a localization object by item and optional member path.\n */\n private resolveLabel(localization: SchemaLocalizationJson | undefined, itemName?: string, memberName?: string): string | undefined {\n if (!localization)\n return undefined;\n if (!itemName)\n return localization.label;\n const item = localization.items?.[itemName];\n if (!memberName)\n return item?.label;\n return item?.members?.[memberName]?.label;\n }\n\n /**\n * Resolve a description from a localization object by item and optional member path.\n */\n private resolveDescription(localization: SchemaLocalizationJson | undefined, itemName?: string, memberName?: string): string | undefined {\n if (!localization)\n return undefined;\n if (!itemName)\n return localization.description;\n const item = localization.items?.[itemName];\n if (!memberName)\n return item?.description;\n return item?.members?.[memberName]?.description;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SchemaLocalization.js","sourceRoot":"","sources":["../../../src/Localization/SchemaLocalization.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAM/F,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO7C,MAAM,cAAc,GAA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AAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU;YACb,OAAO,IAAI,EAAE,KAAK,CAAC;QACrB,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAC5C,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,YAAgD,EAAE,QAAiB,EAAE,UAAmB;QACjH,IAAI,CAAC,YAAY;YACf,OAAO,SAAS,CAAC;QACnB,IAAI,CAAC,QAAQ;YACX,OAAO,YAAY,CAAC,WAAW,CAAC;QAClC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,UAAU;YACb,OAAO,IAAI,EAAE,WAAW,CAAC;QAC3B,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC;IAClD,CAAC;CACF","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\nimport { SchemaKey } from \"../SchemaKey\";\nimport { SchemaView } from \"../SchemaView/SchemaView\";\nimport { Schema } from \"../Metadata/Schema\";\nimport { ECClass } from \"../Metadata/Class\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport { Property } from \"../Metadata/Property\";\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\nimport { ILocalizationProvider } from \"./LocalizationProvider\";\nimport { AnyEnumerator, Enumeration } from \"../Metadata/Enumeration\";\nimport { LocalizedText, SchemaLocalizationJson } from \"./LocalizationTypes\";\n\nconst loggerCategory = \"SchemaLocalization\";\n\ntype SchemaViewItem = SchemaView.Class | SchemaView.Enumeration | SchemaView.KindOfQuantity | SchemaView.PropertyCategory;\n\n/**\n * Manages schema localization to provide localized labels and descriptions.\n * @beta\n */\nexport class SchemaLocalization {\n private _provider: ILocalizationProvider;\n private _locale: string;\n private _cache: Map<string, SchemaLocalizationJson | undefined> = new Map();\n\n private constructor(provider: ILocalizationProvider, locale: string) {\n this._provider = provider;\n this._locale = locale;\n }\n\n private get _baseLocale(): string | undefined {\n return this._locale.includes(\"-\") ? this._locale.split(\"-\")[0] : undefined;\n }\n\n private cacheKey(schemaName: string, locale: string): string {\n return `${schemaName}:${locale}`;\n }\n\n /**\n * Create a SchemaLocalization instance and pre-load localization files for the given schemas.\n * @param provider The localization provider to use for loading localization files\n * @param locale The target locale (e.g., \"de\", \"fr\", \"es-CO\")\n * @param schemas The schemas whose localization should be pre-loaded\n */\n public static async create(provider: ILocalizationProvider, locale: string, schemaKeys: Iterable<SchemaKey>): Promise<SchemaLocalization> {\n const localization = new SchemaLocalization(provider, locale);\n await localization.loadLocalizations(schemaKeys);\n return localization;\n }\n\n public get locale(): string {\n return this._locale;\n }\n\n public setLocale(locale: string): void {\n this._locale = locale;\n this._cache.clear();\n }\n\n /**\n * Get localization provider.\n */\n public get provider(): ILocalizationProvider {\n return this._provider;\n }\n\n /**\n * Load localizations for the given schema keys.\n * @param schemaKeys The schema keys to load localization for\n */\n public async loadLocalizations(schemaKeys: Iterable<SchemaKey>): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const key of schemaKeys) {\n promises.push(this.loadLocalizationInfo(key.name, key.readVersion, this._locale));\n if (this._baseLocale !== undefined)\n promises.push(this.loadLocalizationInfo(key.name, key.readVersion, this._baseLocale));\n }\n await Promise.all(promises);\n }\n\n /**\n * Get a localized label for a schema, schema item, or member.\n */\n public getLabel(schemaName: string, itemName?: string, memberName?: string): string | undefined {\n const localization = this.getCachedLocalization(schemaName, this._locale);\n const label = this.resolveLabel(localization, itemName, memberName);\n if (label)\n return label;\n\n if (this._baseLocale) {\n const baseLocalization = this.getCachedLocalization(schemaName, this._baseLocale);\n return this.resolveLabel(baseLocalization, itemName, memberName);\n }\n\n return undefined;\n }\n\n /**\n * Get a localized description for a schema, schema item, or member.\n */\n public getDescription(schemaName: string, itemName?: string, memberName?: string): string | undefined {\n const localization = this.getCachedLocalization(schemaName, this._locale);\n const description = this.resolveDescription(localization, itemName, memberName);\n if (description)\n return description;\n\n if (this._baseLocale) {\n const baseLocalization = this.getCachedLocalization(schemaName, this._baseLocale);\n return this.resolveDescription(baseLocalization, itemName, memberName);\n }\n\n return undefined;\n }\n\n /**\n * Get localized label and description of a schema.\n * Label fallback: localized label → base locale label → original label → schema name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedSchema(schema: Schema | SchemaView.Schema): LocalizedText {\n const label = this.getLabel(schema.name) ?? (schema.label || schema.name);\n const description = this.getDescription(schema.name) ?? schema.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of a schema item (class, enumeration, unit, etc.).\n * Label fallback: localized label → base locale label → original label → item name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedSchemaItem(item: SchemaItem | SchemaViewItem): LocalizedText {\n const label = this.getLabel(item.schema.name, item.name) ?? (item.label || item.name);\n const description = this.getDescription(item.schema.name, item.name) ?? item.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of a property.\n * Label fallback: localized label → base locale label → original label → property name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedProperty(ecClass: ECClass | SchemaView.Class, property: Property | SchemaView.Property): LocalizedText {\n const label = this.getLabel(ecClass.schema.name, ecClass.name, property.name) ?? (property.label || property.name);\n const description = this.getDescription(ecClass.schema.name, ecClass.name, property.name) ?? property.description;\n return { label, description };\n }\n\n /**\n * Get localized label and description of an enumerator.\n * Label fallback: localized label → base locale label → original label → enumerator name\n * Description fallback: localized description → base locale description → original description\n */\n public getLocalizedEnumerator(enumeration: Enumeration | SchemaView.Enumeration, enumerator: AnyEnumerator | SchemaView.Enumerator): LocalizedText {\n const label = this.getLabel(enumeration.schema.name, enumeration.name, enumerator.name) ?? (enumerator.label || enumerator.name);\n const description = this.getDescription(enumeration.schema.name, enumeration.name, enumerator.name) ?? enumerator.description;\n return { label, description };\n }\n\n /**\n * Load localization information for a specific schema and locale.\n */\n private async loadLocalizationInfo(schemaName: string, readVersion: number, locale: string): Promise<void> {\n const cacheKey = this.cacheKey(schemaName, locale);\n if (this._cache.has(cacheKey))\n return;\n\n const localization = await this._provider.getLocalization(schemaName, locale);\n if (localization?.version) {\n const localizationMajor = this.getMajorVersion(localization.version);\n if (localizationMajor === undefined || readVersion !== localizationMajor) {\n Logger.logWarning(loggerCategory, `Localization version mismatch for schema \"${schemaName}\". Schema major version is ${readVersion.toString()}, but localization is for major version ${localizationMajor?.toString() ?? \"undefined\"}.`);\n this._cache.set(cacheKey, undefined);\n return;\n }\n }\n\n this._cache.set(cacheKey, localization);\n }\n\n /**\n * Get major version from version string\n */\n private getMajorVersion(version: string): number | undefined {\n const rawVersion = version.split(\".\");\n if (rawVersion.length > 0) {\n const majorVersion = parseInt(rawVersion[0], 10);\n return isNaN(majorVersion) ? undefined : majorVersion;\n }\n return undefined;\n }\n\n /**\n * Retrieve the cached localization for a locale\n */\n private getCachedLocalization(schemaName: string, locale: string): SchemaLocalizationJson | undefined {\n const cacheKey = this.cacheKey(schemaName, locale);\n return this._cache.get(cacheKey);\n }\n\n /**\n * Resolve a label from a localization object by item and optional member path.\n */\n private resolveLabel(localization: SchemaLocalizationJson | undefined, itemName?: string, memberName?: string): string | undefined {\n if (!localization)\n return undefined;\n if (!itemName)\n return localization.label;\n const item = localization.items?.[itemName];\n if (!memberName)\n return item?.label;\n return item?.members?.[memberName]?.label;\n }\n\n /**\n * Resolve a description from a localization object by item and optional member path.\n */\n private resolveDescription(localization: SchemaLocalizationJson | undefined, itemName?: string, memberName?: string): string | undefined {\n if (!localization)\n return undefined;\n if (!itemName)\n return localization.description;\n const item = localization.items?.[itemName];\n if (!memberName)\n return item?.description;\n return item?.members?.[memberName]?.description;\n }\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Schema
|
|
3
|
+
*/
|
|
4
|
+
/** One schema in a {@link SchemaManifest}: its name, version, and the entries it directly references.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface SchemaManifestEntry {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly readVersion: number;
|
|
10
|
+
readonly writeVersion: number;
|
|
11
|
+
readonly minorVersion: number;
|
|
12
|
+
/** The schemas this schema directly references. */
|
|
13
|
+
readonly references: readonly SchemaManifestEntry[];
|
|
14
|
+
}
|
|
15
|
+
/** One row of `SELECT ECInstanceId, Name, VersionMajor, VersionWrite, VersionMinor FROM
|
|
16
|
+
* meta.ECSchemaDef`, as passed to {@link SchemaManifest.fromRows}.
|
|
17
|
+
* @note `ecInstanceId` is a plain number, matching SchemaView's convention for schema-related rows:
|
|
18
|
+
* `ec_` metadata rowids carry no briefcase prefix, so they are exactly representable. It is used
|
|
19
|
+
* only to wire reference edges and is not retained in the manifest.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export interface SchemaManifestSchemaRow {
|
|
23
|
+
readonly ecInstanceId: number;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly versionMajor: number;
|
|
26
|
+
readonly versionWrite: number;
|
|
27
|
+
readonly versionMinor: number;
|
|
28
|
+
}
|
|
29
|
+
/** One row of `SELECT SourceECInstanceId, TargetECInstanceId FROM meta.SchemaHasSchemaReferences`,
|
|
30
|
+
* as passed to {@link SchemaManifest.fromRows}.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export interface SchemaManifestReferenceRow {
|
|
34
|
+
readonly sourceECInstanceId: number;
|
|
35
|
+
readonly targetECInstanceId: number;
|
|
36
|
+
}
|
|
37
|
+
/** The reference graph of every schema in one iModel - names, versions and reference edges, without
|
|
38
|
+
* any schema data. A {@link (SchemaView:class)} husk loads it up front to answer which schemas exist
|
|
39
|
+
* and which dependency-ordered set it must load to satisfy a request.
|
|
40
|
+
*
|
|
41
|
+
* A `SchemaViewDataProvider` builds the manifest from ECDbMeta rows via {@link SchemaManifest.fromRows}.
|
|
42
|
+
* The entries are a flat array with no iModel or platform dependency; even the largest iModels hold
|
|
43
|
+
* on the order of a hundred schemas, so the closure and topological walks are plain recursion.
|
|
44
|
+
* @note The manifest does not track which schemas are already loaded. `SchemaViewManager` does that
|
|
45
|
+
* and filters the result of {@link SchemaManifest.getSchemaClosure} itself.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare class SchemaManifest {
|
|
49
|
+
private readonly _entries;
|
|
50
|
+
private readonly _byLowerName;
|
|
51
|
+
/** Wraps a set of entries whose references are already wired to one another. */
|
|
52
|
+
constructor(entries: readonly SchemaManifestEntry[]);
|
|
53
|
+
/** Build a manifest from raw ECDbMeta query rows, so a `SchemaViewDataProvider` only has to run
|
|
54
|
+
* the two queries and hand the rows over. Reference rows whose endpoints are unknown or
|
|
55
|
+
* self-referential are skipped; that cannot happen for a well-formed iModel.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
static fromRows(schemaRows: readonly SchemaManifestSchemaRow[], referenceRows: readonly SchemaManifestReferenceRow[]): SchemaManifest;
|
|
59
|
+
/** The number of schemas in the iModel. */
|
|
60
|
+
get schemaCount(): number;
|
|
61
|
+
/** The names of every schema in the iModel, in manifest order. */
|
|
62
|
+
getAvailableSchemaNames(): string[];
|
|
63
|
+
get entries(): readonly SchemaManifestEntry[];
|
|
64
|
+
/** The entry for a schema by name (case-insensitive), or `undefined` if the iModel has no such schema. */
|
|
65
|
+
findByName(name: string): SchemaManifestEntry | undefined;
|
|
66
|
+
/** The transitive reference closure of the requested schemas, as a flat, duplicate-free list of
|
|
67
|
+
* names: the full set that must be present to use them. The order is unspecified - run
|
|
68
|
+
* {@link SchemaManifest.sortInDependencyOrder} on the result when a load order is needed.
|
|
69
|
+
* @note Requested names the iModel does not contain are ignored; check
|
|
70
|
+
* {@link SchemaManifest.findByName} first to detect them.
|
|
71
|
+
*/
|
|
72
|
+
getSchemaClosure(requestedNames: Iterable<string>): string[];
|
|
73
|
+
/** Orders the given schema names so each appears after every schema it references, directly or
|
|
74
|
+
* transitively. References through schemas not in `schemaNames` are still honored, so the order is
|
|
75
|
+
* correct even when an intermediate schema is left out. Names the iModel does not contain are
|
|
76
|
+
* ignored, and reference cycles - which EC forbids - are broken arbitrarily rather than looping.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
sortInDependencyOrder(schemaNames: Iterable<string>): string[];
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=SchemaManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaManifest.d.ts","sourceRoot":"","sources":["../../../src/SchemaView/SchemaManifest.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACrD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAC1D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA2C;IAExE,gFAAgF;gBAC7D,OAAO,EAAE,SAAS,mBAAmB,EAAE;IAQ1D;;;;OAIG;WACW,QAAQ,CAAC,UAAU,EAAE,SAAS,uBAAuB,EAAE,EAAE,aAAa,EAAE,SAAS,0BAA0B,EAAE,GAAG,cAAc;IA6B5I,2CAA2C;IAC3C,IAAW,WAAW,IAAI,MAAM,CAAiC;IAEjE,kEAAkE;IAC3D,uBAAuB,IAAI,MAAM,EAAE;IAI1C,IAAW,OAAO,IAAI,SAAS,mBAAmB,EAAE,CAEnD;IAED,0GAA0G;IACnG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAIhE;;;;;OAKG;IACI,gBAAgB,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE;IAqBnE;;;;;OAKG;IACI,qBAAqB,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE;CA4BtE"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Schema
|
|
7
|
+
*/
|
|
8
|
+
/** The reference graph of every schema in one iModel - names, versions and reference edges, without
|
|
9
|
+
* any schema data. A {@link (SchemaView:class)} husk loads it up front to answer which schemas exist
|
|
10
|
+
* and which dependency-ordered set it must load to satisfy a request.
|
|
11
|
+
*
|
|
12
|
+
* A `SchemaViewDataProvider` builds the manifest from ECDbMeta rows via {@link SchemaManifest.fromRows}.
|
|
13
|
+
* The entries are a flat array with no iModel or platform dependency; even the largest iModels hold
|
|
14
|
+
* on the order of a hundred schemas, so the closure and topological walks are plain recursion.
|
|
15
|
+
* @note The manifest does not track which schemas are already loaded. `SchemaViewManager` does that
|
|
16
|
+
* and filters the result of {@link SchemaManifest.getSchemaClosure} itself.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export class SchemaManifest {
|
|
20
|
+
_entries;
|
|
21
|
+
_byLowerName;
|
|
22
|
+
/** Wraps a set of entries whose references are already wired to one another. */
|
|
23
|
+
constructor(entries) {
|
|
24
|
+
this._entries = entries;
|
|
25
|
+
const byLowerName = new Map();
|
|
26
|
+
for (const entry of entries)
|
|
27
|
+
byLowerName.set(entry.name.toLowerCase(), entry);
|
|
28
|
+
this._byLowerName = byLowerName;
|
|
29
|
+
}
|
|
30
|
+
/** Build a manifest from raw ECDbMeta query rows, so a `SchemaViewDataProvider` only has to run
|
|
31
|
+
* the two queries and hand the rows over. Reference rows whose endpoints are unknown or
|
|
32
|
+
* self-referential are skipped; that cannot happen for a well-formed iModel.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
static fromRows(schemaRows, referenceRows) {
|
|
36
|
+
const entries = [];
|
|
37
|
+
const entryByECInstanceId = new Map();
|
|
38
|
+
for (const row of schemaRows) {
|
|
39
|
+
const entry = {
|
|
40
|
+
name: row.name,
|
|
41
|
+
readVersion: row.versionMajor,
|
|
42
|
+
writeVersion: row.versionWrite,
|
|
43
|
+
minorVersion: row.versionMinor,
|
|
44
|
+
references: [],
|
|
45
|
+
};
|
|
46
|
+
entries.push(entry);
|
|
47
|
+
entryByECInstanceId.set(row.ecInstanceId, entry);
|
|
48
|
+
}
|
|
49
|
+
for (const row of referenceRows) {
|
|
50
|
+
const source = entryByECInstanceId.get(row.sourceECInstanceId);
|
|
51
|
+
const target = entryByECInstanceId.get(row.targetECInstanceId);
|
|
52
|
+
if (source === undefined || target === undefined || source === target || source.references.includes(target))
|
|
53
|
+
continue;
|
|
54
|
+
source.references.push(target);
|
|
55
|
+
}
|
|
56
|
+
return new SchemaManifest(entries);
|
|
57
|
+
}
|
|
58
|
+
/** The number of schemas in the iModel. */
|
|
59
|
+
get schemaCount() { return this._entries.length; }
|
|
60
|
+
/** The names of every schema in the iModel, in manifest order. */
|
|
61
|
+
getAvailableSchemaNames() {
|
|
62
|
+
return this._entries.map((entry) => entry.name);
|
|
63
|
+
}
|
|
64
|
+
get entries() {
|
|
65
|
+
return this._entries;
|
|
66
|
+
}
|
|
67
|
+
/** The entry for a schema by name (case-insensitive), or `undefined` if the iModel has no such schema. */
|
|
68
|
+
findByName(name) {
|
|
69
|
+
return this._byLowerName.get(name.toLowerCase());
|
|
70
|
+
}
|
|
71
|
+
/** The transitive reference closure of the requested schemas, as a flat, duplicate-free list of
|
|
72
|
+
* names: the full set that must be present to use them. The order is unspecified - run
|
|
73
|
+
* {@link SchemaManifest.sortInDependencyOrder} on the result when a load order is needed.
|
|
74
|
+
* @note Requested names the iModel does not contain are ignored; check
|
|
75
|
+
* {@link SchemaManifest.findByName} first to detect them.
|
|
76
|
+
*/
|
|
77
|
+
getSchemaClosure(requestedNames) {
|
|
78
|
+
const result = [];
|
|
79
|
+
const visited = new Set();
|
|
80
|
+
const visit = (entry) => {
|
|
81
|
+
if (visited.has(entry))
|
|
82
|
+
return;
|
|
83
|
+
visited.add(entry);
|
|
84
|
+
result.push(entry.name);
|
|
85
|
+
for (const reference of entry.references)
|
|
86
|
+
visit(reference);
|
|
87
|
+
};
|
|
88
|
+
for (const name of requestedNames) {
|
|
89
|
+
const entry = this._byLowerName.get(name.toLowerCase());
|
|
90
|
+
if (entry !== undefined)
|
|
91
|
+
visit(entry);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/** Orders the given schema names so each appears after every schema it references, directly or
|
|
96
|
+
* transitively. References through schemas not in `schemaNames` are still honored, so the order is
|
|
97
|
+
* correct even when an intermediate schema is left out. Names the iModel does not contain are
|
|
98
|
+
* ignored, and reference cycles - which EC forbids - are broken arbitrarily rather than looping.
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
sortInDependencyOrder(schemaNames) {
|
|
102
|
+
const requested = new Set();
|
|
103
|
+
for (const name of schemaNames) {
|
|
104
|
+
const entry = this._byLowerName.get(name.toLowerCase());
|
|
105
|
+
if (entry !== undefined)
|
|
106
|
+
requested.add(entry);
|
|
107
|
+
}
|
|
108
|
+
const result = [];
|
|
109
|
+
const visited = new Set();
|
|
110
|
+
const visiting = new Set();
|
|
111
|
+
const visit = (entry) => {
|
|
112
|
+
if (visited.has(entry) || visiting.has(entry))
|
|
113
|
+
return;
|
|
114
|
+
visiting.add(entry);
|
|
115
|
+
for (const reference of entry.references)
|
|
116
|
+
visit(reference);
|
|
117
|
+
visiting.delete(entry);
|
|
118
|
+
visited.add(entry);
|
|
119
|
+
if (requested.has(entry))
|
|
120
|
+
result.push(entry.name);
|
|
121
|
+
};
|
|
122
|
+
for (const entry of requested)
|
|
123
|
+
visit(entry);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=SchemaManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaManifest.js","sourceRoot":"","sources":["../../../src/SchemaView/SchemaManifest.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAsCH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,cAAc;IACR,QAAQ,CAAiC;IACzC,YAAY,CAA2C;IAExE,gFAAgF;IAChF,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,MAAM,WAAW,GAAG,IAAI,GAAG,EAA+B,CAAC;QAC3D,KAAK,MAAM,KAAK,IAAI,OAAO;YACzB,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,MAAM,C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,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;QAC/C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAEhD,MAAM,KAAK,GAAG,CAAC,KAA0B,EAAQ,EAAE;YACjD,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;gBAC3C,OAAO;YACT,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,UAAU;gBACtC,KAAK,CAAC,SAAS,CAAC,CAAC;YACnB,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;gBACtB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;QAEF,KAAK,MAAM,KAAK,IAAI,SAAS;YAC3B,KAAK,CAAC,KAAK,CAAC,CAAC;QACf,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","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\n/** One schema in a {@link SchemaManifest}: its name, version, and the entries it directly references.\n * @internal\n */\nexport interface SchemaManifestEntry {\n readonly name: string;\n readonly readVersion: number;\n readonly writeVersion: number;\n readonly minorVersion: number;\n /** The schemas this schema directly references. */\n readonly references: readonly SchemaManifestEntry[];\n}\n\n/** One row of `SELECT ECInstanceId, Name, VersionMajor, VersionWrite, VersionMinor FROM\n * meta.ECSchemaDef`, as passed to {@link SchemaManifest.fromRows}.\n * @note `ecInstanceId` is a plain number, matching SchemaView's convention for schema-related rows:\n * `ec_` metadata rowids carry no briefcase prefix, so they are exactly representable. It is used\n * only to wire reference edges and is not retained in the manifest.\n * @internal\n */\nexport interface SchemaManifestSchemaRow {\n readonly ecInstanceId: number;\n readonly name: string;\n readonly versionMajor: number;\n readonly versionWrite: number;\n readonly versionMinor: number;\n}\n\n/** One row of `SELECT SourceECInstanceId, TargetECInstanceId FROM meta.SchemaHasSchemaReferences`,\n * as passed to {@link SchemaManifest.fromRows}.\n * @internal\n */\nexport interface SchemaManifestReferenceRow {\n readonly sourceECInstanceId: number;\n readonly targetECInstanceId: number;\n}\n\n/** The reference graph of every schema in one iModel - names, versions and reference edges, without\n * any schema data. A {@link (SchemaView:class)} husk loads it up front to answer which schemas exist\n * and which dependency-ordered set it must load to satisfy a request.\n *\n * A `SchemaViewDataProvider` builds the manifest from ECDbMeta rows via {@link SchemaManifest.fromRows}.\n * The entries are a flat array with no iModel or platform dependency; even the largest iModels hold\n * on the order of a hundred schemas, so the closure and topological walks are plain recursion.\n * @note The manifest does not track which schemas are already loaded. `SchemaViewManager` does that\n * and filters the result of {@link SchemaManifest.getSchemaClosure} itself.\n * @internal\n */\nexport class SchemaManifest {\n private readonly _entries: readonly SchemaManifestEntry[];\n private readonly _byLowerName: ReadonlyMap<string, SchemaManifestEntry>;\n\n /** Wraps a set of entries whose references are already wired to one another. */\n public constructor(entries: readonly SchemaManifestEntry[]) {\n this._entries = entries;\n const byLowerName = new Map<string, SchemaManifestEntry>();\n for (const entry of entries)\n byLowerName.set(entry.name.toLowerCase(), entry);\n this._byLowerName = byLowerName;\n }\n\n /** Build a manifest from raw ECDbMeta query rows, so a `SchemaViewDataProvider` only has to run\n * the two queries and hand the rows over. Reference rows whose endpoints are unknown or\n * self-referential are skipped; that cannot happen for a well-formed iModel.\n * @internal\n */\n public static fromRows(schemaRows: readonly SchemaManifestSchemaRow[], referenceRows: readonly SchemaManifestReferenceRow[]): SchemaManifest {\n // Mutable during the wiring walk below; entries are read-only once handed to the manifest.\n type MutableEntry = Omit<SchemaManifestEntry, \"references\"> & { references: SchemaManifestEntry[] };\n\n const entries: MutableEntry[] = [];\n const entryByECInstanceId = new Map<number, MutableEntry>();\n for (const row of schemaRows) {\n const entry: MutableEntry = {\n name: row.name,\n readVersion: row.versionMajor,\n writeVersion: row.versionWrite,\n minorVersion: row.versionMinor,\n references: [],\n };\n entries.push(entry);\n entryByECInstanceId.set(row.ecInstanceId, entry);\n }\n\n for (const row of referenceRows) {\n const source = entryByECInstanceId.get(row.sourceECInstanceId);\n const target = entryByECInstanceId.get(row.targetECInstanceId);\n if (source === undefined || target === undefined || source === target || source.references.includes(target))\n continue;\n source.references.push(target);\n }\n\n return new SchemaManifest(entries);\n }\n\n /** The number of schemas in the iModel. */\n public get schemaCount(): number { return this._entries.length; }\n\n /** The names of every schema in the iModel, in manifest order. */\n public getAvailableSchemaNames(): string[] {\n return this._entries.map((entry) => entry.name);\n }\n\n public get entries(): readonly SchemaManifestEntry[] {\n return this._entries;\n }\n\n /** The entry for a schema by name (case-insensitive), or `undefined` if the iModel has no such schema. */\n public findByName(name: string): SchemaManifestEntry | undefined {\n return this._byLowerName.get(name.toLowerCase());\n }\n\n /** The transitive reference closure of the requested schemas, as a flat, duplicate-free list of\n * names: the full set that must be present to use them. The order is unspecified - run\n * {@link SchemaManifest.sortInDependencyOrder} on the result when a load order is needed.\n * @note Requested names the iModel does not contain are ignored; check\n * {@link SchemaManifest.findByName} first to detect them.\n */\n public getSchemaClosure(requestedNames: Iterable<string>): string[] {\n const result: string[] = [];\n const visited = new Set<SchemaManifestEntry>();\n\n const visit = (entry: SchemaManifestEntry): void => {\n if (visited.has(entry))\n return;\n visited.add(entry);\n result.push(entry.name);\n for (const reference of entry.references)\n visit(reference);\n };\n\n for (const name of requestedNames) {\n const entry = this._byLowerName.get(name.toLowerCase());\n if (entry !== undefined)\n visit(entry);\n }\n return result;\n }\n\n /** Orders the given schema names so each appears after every schema it references, directly or\n * transitively. References through schemas not in `schemaNames` are still honored, so the order is\n * correct even when an intermediate schema is left out. Names the iModel does not contain are\n * ignored, and reference cycles - which EC forbids - are broken arbitrarily rather than looping.\n * @internal\n */\n public sortInDependencyOrder(schemaNames: Iterable<string>): string[] {\n const requested = new Set<SchemaManifestEntry>();\n for (const name of schemaNames) {\n const entry = this._byLowerName.get(name.toLowerCase());\n if (entry !== undefined)\n requested.add(entry);\n }\n\n const result: string[] = [];\n const visited = new Set<SchemaManifestEntry>();\n const visiting = new Set<SchemaManifestEntry>();\n\n const visit = (entry: SchemaManifestEntry): void => {\n if (visited.has(entry) || visiting.has(entry))\n return;\n visiting.add(entry);\n for (const reference of entry.references)\n visit(reference);\n visiting.delete(entry);\n visited.add(entry);\n if (requested.has(entry))\n result.push(entry.name);\n };\n\n for (const entry of requested)\n visit(entry);\n return result;\n }\n}\n"]}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* @module Schema
|
|
3
3
|
*/
|
|
4
4
|
import { type ClassData, ClassModifier, ClassType, type EnumerationData, type EnumeratorData, type KoqData, type PropCategoryData, type PropertyDef, PropertyKind, type PropertyRef, type RelConstraintData, type SchemaData, SchemaViewPrimitiveType } from "./SchemaViewInterfaces";
|
|
5
|
-
import {
|
|
5
|
+
import { SchemaViewMergeContext } from "./SchemaViewBinaryReader";
|
|
6
|
+
import { StrengthDirection, StrengthType } from "../ECObjects";
|
|
6
7
|
declare const _storage: unique symbol;
|
|
7
8
|
/** Internal runtime storage attached to a SchemaView instance. Carries the immutable data
|
|
8
9
|
* tables built by SchemaViewBuilder plus two mutable caches populated lazily at runtime.
|
|
@@ -58,11 +59,15 @@ export interface SchemaViewData {
|
|
|
58
59
|
export declare class SchemaView {
|
|
59
60
|
/** @internal */
|
|
60
61
|
readonly [_storage]: SchemaViewStorage;
|
|
61
|
-
private _schemaToken;
|
|
62
|
+
private readonly _schemaToken;
|
|
62
63
|
private _outdated;
|
|
64
|
+
/** When present, this view is a *husk*: it retains the live builder and cross-reference maps, so
|
|
65
|
+
* `mergeFragment` can append further fragment blobs. Undefined for one-shot views from `fromBinary`. */
|
|
66
|
+
private readonly _mergeContext?;
|
|
63
67
|
/** @internal */
|
|
64
|
-
constructor(data: SchemaViewData, schemaToken?: string);
|
|
65
|
-
/**
|
|
68
|
+
constructor(data: SchemaViewData, schemaToken?: string, mergeContext?: SchemaViewMergeContext);
|
|
69
|
+
/** Cache-invalidation token identifying the schemas this view was built from: a hash of every
|
|
70
|
+
* schema's name and version (see `PRAGMA checksum(schema_token)`), not of their full contents.
|
|
66
71
|
* Empty string if not set (e.g., when built from a builder without a token).
|
|
67
72
|
* @beta
|
|
68
73
|
*/
|
|
@@ -105,14 +110,25 @@ export declare class SchemaView {
|
|
|
105
110
|
findPropertyCategory(qualifiedName: string): SchemaView.PropertyCategory | undefined;
|
|
106
111
|
/** Parse a binary blob into a SchemaView. Synchronous.
|
|
107
112
|
* @param blob - The binary blob from `PRAGMA schema_view`.
|
|
108
|
-
* @param schemaToken - Optional
|
|
113
|
+
* @param schemaToken - Optional cache-invalidation token (schema name+version hash; see `PRAGMA checksum(schema_token)`).
|
|
109
114
|
* @beta
|
|
110
115
|
*/
|
|
111
116
|
static fromBinary(blob: Uint8Array, schemaToken?: string): SchemaView;
|
|
112
|
-
/**
|
|
117
|
+
/** Create an empty, *mergeable* view (a "husk"). It contains no schemas until `mergeFragment` is
|
|
118
|
+
* called. Each merged fragment is appended into the same instance, so flyweights and cached
|
|
119
|
+
* cross-references obtained earlier stay valid - indices are append-only and never reordered.
|
|
120
|
+
* @note Fragments must be merged in dependency order: a fragment may only reference schemas from
|
|
121
|
+
* fragments already merged.
|
|
113
122
|
* @internal
|
|
114
123
|
*/
|
|
115
|
-
static
|
|
124
|
+
static createMergeable(schemaToken?: string): SchemaView;
|
|
125
|
+
/** Merge one fragment blob into this view. Only valid on a view created via `createMergeable`.
|
|
126
|
+
* Synchronous. Any flyweight or cached index obtained before the call remains valid.
|
|
127
|
+
* @note If the merge throws (e.g. on a malformed blob), the view may be left partially extended
|
|
128
|
+
* and must be discarded by the host.
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
mergeFragment(blob: Uint8Array): void;
|
|
116
132
|
/** Resolve a qualified "SchemaName:ItemName" (or dot-separated) to an index using the given
|
|
117
133
|
* per-schema name map. Returns undefined if not found. @internal */
|
|
118
134
|
private _resolveSchemaItemIdx;
|
|
@@ -566,88 +582,5 @@ export declare namespace SchemaView {
|
|
|
566
582
|
get constraintClasses(): readonly Class[];
|
|
567
583
|
}
|
|
568
584
|
}
|
|
569
|
-
/** Builder for constructing an immutable `SchemaView`.
|
|
570
|
-
*
|
|
571
|
-
* Collects data during binary blob parsing, then freezes it into a view.
|
|
572
|
-
* Handles string interning and property definition deduplication.
|
|
573
|
-
*
|
|
574
|
-
* Consumers should not use this directly - read views via `IModelDb.getSchemaView`
|
|
575
|
-
* / `IModelConnection.getSchemaView` (or `SchemaView.fromBinary` if you have a raw blob).
|
|
576
|
-
* @internal
|
|
577
|
-
*/
|
|
578
|
-
export declare class SchemaViewBuilder {
|
|
579
|
-
private readonly _strings;
|
|
580
|
-
private readonly _lowerStrings;
|
|
581
|
-
private readonly _stringMap;
|
|
582
|
-
private readonly _schemas;
|
|
583
|
-
private readonly _classes;
|
|
584
|
-
private readonly _classMixins;
|
|
585
|
-
private readonly _propDefs;
|
|
586
|
-
private readonly _propertyRefs;
|
|
587
|
-
private readonly _relConstraints;
|
|
588
|
-
private readonly _constraintClassRefs;
|
|
589
|
-
private readonly _enumerations;
|
|
590
|
-
private readonly _enumerators;
|
|
591
|
-
private readonly _koqs;
|
|
592
|
-
private readonly _propCategories;
|
|
593
|
-
private readonly _propDefMap;
|
|
594
|
-
/** Intern a string, returning its SID. Empty/undefined strings return 0.
|
|
595
|
-
* Interning is case-sensitive - "MyLabel" and "MYLABEL" get distinct SIDs.
|
|
596
|
-
* The `lowerStrings` array provides case-insensitive lookup without mutating display values.
|
|
597
|
-
*/
|
|
598
|
-
internString(value: string | undefined): number;
|
|
599
|
-
/** Add a schema. Returns its index. */
|
|
600
|
-
addSchema(data: SchemaData): number;
|
|
601
|
-
/** Add a class. Returns its index. Must be called after the owning schema. */
|
|
602
|
-
addClass(data: ClassData): number;
|
|
603
|
-
/** Add a property definition with deduplication. Returns the def index (possibly existing). */
|
|
604
|
-
addPropertyDef(data: PropertyDef): number;
|
|
605
|
-
/** Append a property reference to the flat refs array. */
|
|
606
|
-
addPropertyRef(ref: PropertyRef): void;
|
|
607
|
-
/** Add an enumeration. Returns its index. */
|
|
608
|
-
addEnumeration(data: EnumerationData): number;
|
|
609
|
-
/** Append an enumerator to the flat enumerators array. */
|
|
610
|
-
addEnumerator(data: EnumeratorData): void;
|
|
611
|
-
/** Add a KindOfQuantity. Returns its index. */
|
|
612
|
-
addKoq(data: KoqData): number;
|
|
613
|
-
/** Add a PropertyCategory. Returns its index. */
|
|
614
|
-
addPropertyCategory(data: PropCategoryData): number;
|
|
615
|
-
/** Add a relationship constraint. Returns its index. */
|
|
616
|
-
addRelConstraint(data: RelConstraintData): number;
|
|
617
|
-
/** Append a constraint class reference to the flat array. */
|
|
618
|
-
addConstraintClassRef(classIdx: number): void;
|
|
619
|
-
/** Append a mixin class reference to the flat array. */
|
|
620
|
-
addClassMixin(classIdx: number): void;
|
|
621
|
-
/** The current count of property refs (used to set ownPropStart on ClassData). */
|
|
622
|
-
get propertyRefCount(): number;
|
|
623
|
-
/** The current count of enumerators (used to set enumeratorStart on EnumerationData). */
|
|
624
|
-
get enumeratorCount(): number;
|
|
625
|
-
/** The current count of constraint class refs (used to set classRefStart). */
|
|
626
|
-
get constraintClassRefCount(): number;
|
|
627
|
-
/** The current count of class mixins (used to set mixinStartIdx). */
|
|
628
|
-
get classMixinCount(): number;
|
|
629
|
-
/** Get a string by SID. @internal */
|
|
630
|
-
getString(sid: number): string;
|
|
631
|
-
/** Replace class data at the given index (used during deferred cross-ref resolution). @internal */
|
|
632
|
-
updateClass(classIdx: number, data: ClassData): void;
|
|
633
|
-
/** Update range fields on a schema (used after all items for a schema are collected). @internal */
|
|
634
|
-
updateSchemaRanges(schemaIdx: number, ranges: {
|
|
635
|
-
classRangeStart: number;
|
|
636
|
-
classCount: number;
|
|
637
|
-
enumRangeStart: number;
|
|
638
|
-
enumCount: number;
|
|
639
|
-
koqRangeStart: number;
|
|
640
|
-
koqCount: number;
|
|
641
|
-
catRangeStart: number;
|
|
642
|
-
catCount: number;
|
|
643
|
-
}): void;
|
|
644
|
-
/** Freeze all data and produce an immutable SchemaView. */
|
|
645
|
-
build(schemaToken?: string): SchemaView;
|
|
646
|
-
/** Produce a dedup signature for a PropertyDef. Label and priority are excluded because
|
|
647
|
-
* they are per-PropertyRef overrides, not part of the structural definition.
|
|
648
|
-
* Uses SIDs (not lowercase strings) for name/description so that case-preserving names
|
|
649
|
-
* stay distinct - matching the C++ writer's dedup behavior. */
|
|
650
|
-
private _propDefSignature;
|
|
651
|
-
}
|
|
652
585
|
export {};
|
|
653
586
|
//# sourceMappingURL=SchemaView.d.ts.map
|