-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from polkadot-cloud/rb-init-scraper-tests
feat: Init scraper tests, metadata types to classes
- Loading branch information
Showing
42 changed files
with
60,854 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/mocharc.json", | ||
"require": "tsx", | ||
"spec": "test/**/*.spec.ts" | ||
"spec": "test/**/*.spec.ts", | ||
"recursive": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { MetadataLookup } from './types'; | ||
|
||
// Class to hold metadata lookup, with type accessors. | ||
export class Lookup { | ||
lookup: MetadataLookup; | ||
|
||
constructor(lookup: MetadataLookup) { | ||
this.lookup = lookup; | ||
} | ||
|
||
// Get types array from lookup. | ||
types() { | ||
return this.lookup.types; | ||
} | ||
|
||
// Get a type record from lookup types, or undefined otherwise. | ||
getType(typeId: number) { | ||
return this.types().find(({ id }: { id: number }) => id === typeId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { AnyJson } from '@w3ux/types'; | ||
|
||
export interface MetadataLookup { | ||
types: LookupTypes; | ||
} | ||
|
||
export type LookupTypes = LookupItem[]; | ||
|
||
export interface LookupItem { | ||
id: number; | ||
type: LookupType; | ||
} | ||
|
||
export interface LookupType { | ||
path: string[]; | ||
params: AnyJson[]; | ||
def: AnyJson; | ||
docs: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { IArrayType, MetadataType } from './types'; | ||
import type { TrailParam } from '../types'; | ||
|
||
// Class to hold an array type. | ||
export class ArrayType implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The array type and length. | ||
array: IArrayType; | ||
|
||
constructor(array: IArrayType, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.array = array; | ||
} | ||
|
||
// Scrape array type. Overwrites `type` with scraped type. | ||
scrape(scraper: MetadataScraper, trailParam: TrailParam) { | ||
return scraper.getType(this.array.type, trailParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { TrailParam } from '../types'; | ||
import type { BitSequenceType, MetadataType } from './types'; | ||
|
||
// Class to hold a bit sequence type. | ||
export class BitSequence implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The type of this bit sequence. | ||
bitSequence: BitSequenceType; | ||
|
||
constructor(bitSequence: BitSequenceType, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.bitSequence = bitSequence; | ||
} | ||
|
||
// Scrape bitSequence type. Overwrites `bitStoreType` and `bitOrderType` with scraped types. | ||
scrape(scraper: MetadataScraper, { trailId }: TrailParam) { | ||
return { | ||
bitOrderType: scraper.start(this.bitSequence.bitOrderType, trailId), | ||
bitStoreType: scraper.start(this.bitSequence.bitStoreType, trailId), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { TrailParam } from '../types'; | ||
import type { CompactType, MetadataType } from './types'; | ||
|
||
// Class to hold a compact type. | ||
export class Compact implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The inner type of this compact type. | ||
type: number; | ||
|
||
constructor(compact: CompactType, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.type = compact.type; | ||
} | ||
|
||
// Scrape compact type. Overwrites `type` with scraped type. | ||
scrape(scraper: MetadataScraper, trailParam: TrailParam) { | ||
return scraper.getType(this.type, trailParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { TrailParam } from '../types'; | ||
import type { CompositeField, CompositeType, MetadataType } from './types'; | ||
|
||
// Class to hold a composite type. | ||
export class Composite implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The fields of this composite. | ||
fields: CompositeField[]; | ||
|
||
constructor(composite: CompositeType, lookup: LookupItem) { | ||
this.fields = composite.fields; | ||
this.lookup = lookup; | ||
} | ||
|
||
// Scrape composite fields. Overwrites `fields` with scraped fields. | ||
scrape(scraper: MetadataScraper, { trailId }: TrailParam) { | ||
return [...this.fields].map((field) => ({ | ||
...field, | ||
type: scraper.start(field.type, trailId), | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataType } from './types'; | ||
|
||
// Class to hold a primitive type. | ||
export class Primitive implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The type of this primitive. | ||
primitive: string; | ||
|
||
constructor(primitive: string, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.primitive = primitive; | ||
} | ||
|
||
// Scrape primitive type. Simply returns the type. | ||
scrape() { | ||
return this.primitive; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { MetadataType, SequenceType } from './types'; | ||
import type { TrailParam } from '../types'; | ||
|
||
// Class to hold a sequence type. | ||
export class Sequence implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The type of this sequence. | ||
type: number; | ||
|
||
constructor(sequence: SequenceType, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.type = sequence.type; | ||
} | ||
|
||
// Scrape sequence type. Overwrites `type` with scraped type. | ||
scrape(scraper: MetadataScraper, trailParam: TrailParam) { | ||
return scraper.getType(this.type, trailParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { MetadataType, TupleType } from './types'; | ||
import type { TrailParam } from '../types'; | ||
|
||
// Class to hold a tuple type. | ||
export class Tuple implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The types of this tuple. | ||
tuple: TupleType; | ||
|
||
constructor(tuple: TupleType, lookup: LookupItem) { | ||
this.lookup = lookup; | ||
this.tuple = tuple; | ||
} | ||
|
||
// Scrape tuple types. Overwrites the type with scraped type at each index. | ||
scrape(scraper: MetadataScraper, { trailId }: TrailParam) { | ||
return this.tuple.map((id: number) => scraper.start(id, trailId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { LookupItem } from '../Lookup/types'; | ||
import type { MetadataScraper } from '..'; | ||
import type { MetadataType, VariantItem } from './types'; | ||
import type { TrailParam } from '../types'; | ||
|
||
// Class to hold a variant type. | ||
export class Variant implements MetadataType { | ||
// The raw lookup data of this type. | ||
lookup: LookupItem; | ||
|
||
// The variants of this variant type. | ||
items: VariantItem[]; | ||
|
||
constructor(variants: VariantItem[], lookup: LookupItem) { | ||
this.items = variants; | ||
this.lookup = lookup; | ||
} | ||
|
||
// Scrape variant fields. Overwrites `fields` with scraped fields. | ||
scrape(scraper: MetadataScraper, { trailId }: TrailParam) { | ||
return [...this.items].map((item) => ({ | ||
...item, | ||
fields: item.fields.map((field) => ({ | ||
...field, | ||
type: scraper.start(field.type, trailId), | ||
})), | ||
})); | ||
} | ||
} |
Oops, something went wrong.