Ensure metadata private fields are not accessed (#3341)
This commit is contained in:
@@ -33,18 +33,18 @@ export class MetadataVersioned extends Struct {
|
|||||||
}, value as Map<unknown, unknown>);
|
}, value as Map<unknown, unknown>);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _assertVersion (version: number): boolean {
|
#assertVersion = (version: number): boolean => {
|
||||||
assert(this.version <= version, `Cannot convert metadata from v${this.version} to v${version}`);
|
assert(this.version <= version, `Cannot convert metadata from v${this.version} to v${version}`);
|
||||||
|
|
||||||
return this.version === version;
|
return this.version === version;
|
||||||
}
|
};
|
||||||
|
|
||||||
private _getVersion<T extends MetaMapped, F extends MetaMapped> (version: MetaVersions, fromPrev: (registry: Registry, input: F, metaVersion: number) => T): T {
|
#getVersion = <T extends MetaMapped, F extends MetaMapped>(version: MetaVersions, fromPrev: (registry: Registry, input: F, metaVersion: number) => T): T => {
|
||||||
const asCurr = `asV${version}` as MetaAsX;
|
const asCurr = `asV${version}` as MetaAsX;
|
||||||
const asPrev = `asV${version - 1}` as MetaAsX;
|
const asPrev = `asV${version - 1}` as MetaAsX;
|
||||||
|
|
||||||
if (this._assertVersion(version)) {
|
if (this.#assertVersion(version)) {
|
||||||
return this._metadata[asCurr] as T;
|
return this.#metadata()[asCurr] as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.#converted.has(version)) {
|
if (!this.#converted.has(version)) {
|
||||||
@@ -52,6 +52,13 @@ export class MetadataVersioned extends Struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.#converted.get(version) as T;
|
return this.#converted.get(version) as T;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description the metadata wrapped
|
||||||
|
*/
|
||||||
|
#metadata = (): MetadataAll => {
|
||||||
|
return this.get('metadata') as MetadataAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,30 +75,30 @@ export class MetadataVersioned extends Struct {
|
|||||||
* @description Returns the wrapped metadata as a V9 object
|
* @description Returns the wrapped metadata as a V9 object
|
||||||
*/
|
*/
|
||||||
public get asV9 (): MetadataV9 {
|
public get asV9 (): MetadataV9 {
|
||||||
this._assertVersion(9);
|
this.#assertVersion(9);
|
||||||
|
|
||||||
return this._metadata.asV9;
|
return this.#metadata().asV9;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns the wrapped values as a V10 object
|
* @description Returns the wrapped values as a V10 object
|
||||||
*/
|
*/
|
||||||
public get asV10 (): MetadataV10 {
|
public get asV10 (): MetadataV10 {
|
||||||
return this._getVersion(10, toV10);
|
return this.#getVersion(10, toV10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns the wrapped values as a V11 object
|
* @description Returns the wrapped values as a V11 object
|
||||||
*/
|
*/
|
||||||
public get asV11 (): MetadataV11 {
|
public get asV11 (): MetadataV11 {
|
||||||
return this._getVersion(11, toV11);
|
return this.#getVersion(11, toV11);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns the wrapped values as a V12 object
|
* @description Returns the wrapped values as a V12 object
|
||||||
*/
|
*/
|
||||||
public get asV12 (): MetadataV12 {
|
public get asV12 (): MetadataV12 {
|
||||||
return this._getVersion(12, toV12);
|
return this.#getVersion(12, toV12);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +106,7 @@ export class MetadataVersioned extends Struct {
|
|||||||
*/
|
*/
|
||||||
public get asLatest (): MetadataLatest {
|
public get asLatest (): MetadataLatest {
|
||||||
// This is non-existent & latest - applied here to do the module-specific type conversions
|
// This is non-existent & latest - applied here to do the module-specific type conversions
|
||||||
return this._getVersion(13, toLatest);
|
return this.#getVersion(13, toLatest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,18 +116,11 @@ export class MetadataVersioned extends Struct {
|
|||||||
return this.get('magicNumber') as MagicNumber;
|
return this.get('magicNumber') as MagicNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description the metadata wrapped
|
|
||||||
*/
|
|
||||||
private get _metadata (): MetadataAll {
|
|
||||||
return this.get('metadata') as MetadataAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description the metadata version this structure represents
|
* @description the metadata version this structure represents
|
||||||
*/
|
*/
|
||||||
public get version (): number {
|
public get version (): number {
|
||||||
return this._metadata.index;
|
return this.#metadata().index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUniqTypes (throwError: boolean): string[] {
|
public getUniqTypes (throwError: boolean): string[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user