diff --git a/jest.config.cjs b/jest.config.cjs index 4198974617..2468408595 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -11,7 +11,7 @@ module.exports = { '@polkadot/api(.*)$': '/packages/api/src/$1', '@polkadot/rpc-(core|provider)(.*)$': '/packages/rpc-$1/src/$2', '@polkadot/typegen(.*)$': '/packages/typegen/src/$1', - '@polkadot/types-(codec|known|support)(.*)$': '/packages/types-$1/src/$2', + '@polkadot/types-(codec|create|known|support)(.*)$': '/packages/types-$1/src/$2', // eslint-disable-next-line sort-keys '@polkadot/types(.*)$': '/packages/types/src/$1' }, diff --git a/packages/api-contract/src/Abi/index.ts b/packages/api-contract/src/Abi/index.ts index 50b03f2768..89b2376690 100644 --- a/packages/api-contract/src/Abi/index.ts +++ b/packages/api-contract/src/Abi/index.ts @@ -6,7 +6,8 @@ import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecL import type { Codec, Registry } from '@polkadot/types/types'; import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types'; -import { TypeDefInfo, TypeRegistry } from '@polkadot/types'; +import { TypeRegistry } from '@polkadot/types'; +import { TypeDefInfo } from '@polkadot/types-create'; import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util'; import { v0ToLatest, v1ToLatest } from './toLatest'; diff --git a/packages/api/package.json b/packages/api/package.json index db14503826..2f1196ac32 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -29,6 +29,9 @@ "@polkadot/rpc-core": "6.12.2-2", "@polkadot/rpc-provider": "6.12.2-2", "@polkadot/types": "6.12.2-2", + "@polkadot/types-codec": "6.12.2-2", + "@polkadot/types-create": "6.12.2-2", + "@polkadot/types-known": "6.12.2-2", "@polkadot/util": "^8.1.2", "@polkadot/util-crypto": "^8.1.2", "eventemitter3": "^4.0.7", diff --git a/packages/api/src/detectPackage.ts b/packages/api/src/detectPackage.ts index 216c395822..36719df4e3 100644 --- a/packages/api/src/detectPackage.ts +++ b/packages/api/src/detectPackage.ts @@ -4,8 +4,11 @@ import { packageInfo as coreInfo } from '@polkadot/rpc-core/packageInfo'; import { packageInfo as providerInfo } from '@polkadot/rpc-provider/packageInfo'; import { packageInfo as typesInfo } from '@polkadot/types/packageInfo'; +import { packageInfo as codecInfo } from '@polkadot/types-codec/packageInfo'; +import { packageInfo as createInfo } from '@polkadot/types-create/packageInfo'; +import { packageInfo as knownInfo } from '@polkadot/types-known/packageInfo'; import { detectPackage } from '@polkadot/util'; import { packageInfo } from './packageInfo'; -detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [coreInfo, providerInfo, typesInfo]); +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [coreInfo, providerInfo, typesInfo, codecInfo, createInfo, knownInfo]); diff --git a/packages/typegen/package.json b/packages/typegen/package.json index 8dfda269b2..3154de67d9 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -37,6 +37,7 @@ "@polkadot/rpc-provider": "6.12.2-2", "@polkadot/types": "6.12.2-2", "@polkadot/types-codec": "6.12.2-2", + "@polkadot/types-create": "6.12.2-2", "@polkadot/types-support": "6.12.2-2", "@polkadot/util": "^8.1.2", "handlebars": "^4.7.7", diff --git a/packages/typegen/scripts/polkadot-types-chain-info.cjs b/packages/typegen/scripts/polkadot-types-chain-info.cjs index cc6b67522b..82131ee931 100755 --- a/packages/typegen/scripts/polkadot-types-chain-info.cjs +++ b/packages/typegen/scripts/polkadot-types-chain-info.cjs @@ -21,6 +21,7 @@ try { '^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1', '^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1', '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', + '^@polkadot/types-create(.*)': './packages/types-create/src\\1', '^@polkadot/types-known(.*)': './packages/types-known/src\\1', '^@polkadot/types-support(.*)': './packages/types-support/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/scripts/polkadot-types-from-chain.cjs b/packages/typegen/scripts/polkadot-types-from-chain.cjs index 993be0d74c..708da87fd1 100755 --- a/packages/typegen/scripts/polkadot-types-from-chain.cjs +++ b/packages/typegen/scripts/polkadot-types-from-chain.cjs @@ -17,6 +17,7 @@ try { ['module-resolver', { alias: { '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', + '^@polkadot/types-create(.*)': './packages/types-create/src\\1', '^@polkadot/types-known(.*)': './packages/types-known/src\\1', '^@polkadot/types-support(.*)': './packages/types-support/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/scripts/polkadot-types-from-defs.cjs b/packages/typegen/scripts/polkadot-types-from-defs.cjs index 938423c801..5c4ed34dd3 100755 --- a/packages/typegen/scripts/polkadot-types-from-defs.cjs +++ b/packages/typegen/scripts/polkadot-types-from-defs.cjs @@ -18,6 +18,7 @@ try { alias: { '^@polkadot/typegen(.*)': './packages/typegen/src\\1', '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', + '^@polkadot/types-create(.*)': './packages/types-create/src\\1', '^@polkadot/types-known(.*)': './packages/types-known/src\\1', '^@polkadot/types-support(.*)': './packages/types-support/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/scripts/polkadot-types-internal-interfaces.cjs b/packages/typegen/scripts/polkadot-types-internal-interfaces.cjs index 52830ab71d..2531f4e9e8 100755 --- a/packages/typegen/scripts/polkadot-types-internal-interfaces.cjs +++ b/packages/typegen/scripts/polkadot-types-internal-interfaces.cjs @@ -17,6 +17,7 @@ try { ['module-resolver', { alias: { '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', + '^@polkadot/types-create(.*)': './packages/types-create/src\\1', '^@polkadot/types-known(.*)': './packages/types-known/src\\1', '^@polkadot/types-support(.*)': './packages/types-support/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/scripts/polkadot-types-internal-metadata.cjs b/packages/typegen/scripts/polkadot-types-internal-metadata.cjs index f9e269d8f6..f869a617de 100755 --- a/packages/typegen/scripts/polkadot-types-internal-metadata.cjs +++ b/packages/typegen/scripts/polkadot-types-internal-metadata.cjs @@ -17,6 +17,7 @@ try { ['module-resolver', { alias: { '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', + '^@polkadot/types-create(.*)': './packages/types-create/src\\1', '^@polkadot/types-known(.*)': './packages/types-known/src\\1', '^@polkadot/types-support(.*)': './packages/types-support/src\\1', '^@polkadot/types(.*)': './packages/types/src\\1' diff --git a/packages/typegen/src/generate/lookup.ts b/packages/typegen/src/generate/lookup.ts index ad2f58f4ca..f5d8bc987b 100644 --- a/packages/typegen/src/generate/lookup.ts +++ b/packages/typegen/src/generate/lookup.ts @@ -3,7 +3,7 @@ import type { PortableType, SiLookupTypeId, SiPath, SiTypeParameter } from '@polkadot/types/interfaces'; import type { PortableRegistry } from '@polkadot/types/metadata'; -import type { TypeDef } from '@polkadot/types/types'; +import type { TypeDef } from '@polkadot/types-create/types'; import type { HexString } from '@polkadot/util/types'; import Handlebars from 'handlebars'; diff --git a/packages/typegen/src/generate/tsDef.ts b/packages/typegen/src/generate/tsDef.ts index f0d8cda1de..cc808042c2 100644 --- a/packages/typegen/src/generate/tsDef.ts +++ b/packages/typegen/src/generate/tsDef.ts @@ -1,16 +1,16 @@ // Copyright 2017-2021 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { TypeDef } from '@polkadot/types/create/types'; import type { Registry } from '@polkadot/types/types'; +import type { TypeDef } from '@polkadot/types-create/types'; import type { ModuleTypes } from '../util/imports'; import Handlebars from 'handlebars'; import path from 'path'; -import { getTypeDef, TypeRegistry } from '@polkadot/types/create'; -import { TypeDefInfo } from '@polkadot/types/create/types'; +import { TypeRegistry } from '@polkadot/types/create'; import * as defaultDefinitions from '@polkadot/types/interfaces/definitions'; +import { getTypeDef, TypeDefInfo } from '@polkadot/types-create'; import { assert, isString, stringify, stringPascalCase } from '@polkadot/util'; import { createImports, exportInterface, exportType, formatType, readTemplate, setImports, TypeImports, writeFile } from '../util'; diff --git a/packages/typegen/src/util/derived.ts b/packages/typegen/src/util/derived.ts index d57098b02f..9f27098592 100644 --- a/packages/typegen/src/util/derived.ts +++ b/packages/typegen/src/util/derived.ts @@ -1,14 +1,13 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { TypeDef } from '@polkadot/types/create/types'; import type { Constructor, Registry } from '@polkadot/types/types'; +import type { TypeDef } from '@polkadot/types-create/types'; -import { getTypeDef } from '@polkadot/types/create'; -import { TypeDefInfo } from '@polkadot/types/create/types'; import { GenericAccountId, GenericLookupSource, GenericVote } from '@polkadot/types/generic'; import { AllConvictions } from '@polkadot/types/interfaces/democracy/definitions'; import { AbstractInt, bool, Compact, Enum, Null, Option, Struct, Tuple, UInt, Vec } from '@polkadot/types-codec'; +import { getTypeDef, TypeDefInfo } from '@polkadot/types-create'; import { isChildClass, stringify } from '@polkadot/util'; import { formatType } from './formatting'; diff --git a/packages/typegen/src/util/formatting.ts b/packages/typegen/src/util/formatting.ts index 1d511de8d3..debd36d547 100644 --- a/packages/typegen/src/util/formatting.ts +++ b/packages/typegen/src/util/formatting.ts @@ -3,14 +3,13 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import type { TypeDef } from '@polkadot/types/create/types'; import type { Registry } from '@polkadot/types/types'; import type { CodecRegistry } from '@polkadot/types-codec/types'; +import type { TypeDef } from '@polkadot/types-create/types'; import Handlebars from 'handlebars'; -import { getTypeDef, paramsNotation } from '@polkadot/types/create'; -import { TypeDefInfo } from '@polkadot/types/create/types'; +import { getTypeDef, paramsNotation, TypeDefInfo } from '@polkadot/types-create'; import { isString, stringify } from '@polkadot/util'; import { readTemplate } from './file'; diff --git a/packages/typegen/src/util/imports.ts b/packages/typegen/src/util/imports.ts index d7b306e742..bcaadd267c 100644 --- a/packages/typegen/src/util/imports.ts +++ b/packages/typegen/src/util/imports.ts @@ -2,11 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import * as codecClasses from '@polkadot/types/codec'; -import { getTypeDef } from '@polkadot/types/create'; -import { TypeDefInfo } from '@polkadot/types/create/types'; import * as extrinsicClasses from '@polkadot/types/extrinsic'; import * as genericClasses from '@polkadot/types/generic'; import * as primitiveClasses from '@polkadot/types/primitive'; +import { getTypeDef, TypeDefInfo } from '@polkadot/types-create'; export interface ModuleTypes { types: Record; diff --git a/packages/types-create/package.json b/packages/types-create/package.json new file mode 100644 index 0000000000..f5e5e3def4 --- /dev/null +++ b/packages/types-create/package.json @@ -0,0 +1,29 @@ +{ + "author": "Jaco Greeff ", + "bugs": "https://github.com/polkadot-js/api/issues", + "contributors": [], + "description": "Type creator helpers", + "engines": { + "node": ">=14.0.0" + }, + "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-create#readme", + "license": "Apache-2.0", + "maintainers": [], + "name": "@polkadot/types-create", + "repository": { + "directory": "packages/types-create", + "type": "git", + "url": "https://github.com/polkadot-js/api.git" + }, + "sideEffects": [ + "./detectPackage.js", + "./detectPackage.cjs" + ], + "type": "module", + "version": "6.12.2-2", + "main": "index.js", + "dependencies": { + "@babel/runtime": "^7.16.3", + "@polkadot/util": "^8.1.2" + } +} diff --git a/packages/types-create/src/bundle.ts b/packages/types-create/src/bundle.ts new file mode 100644 index 0000000000..e815c98d59 --- /dev/null +++ b/packages/types-create/src/bundle.ts @@ -0,0 +1,8 @@ +// Copyright 2017-2021 @polkadot/types-codec authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export { packageInfo } from './packageInfo'; +export { TypeDefInfo } from './types'; + +export * from './create'; +export * from './util'; diff --git a/packages/types/src/create/createClass.ts b/packages/types-create/src/create/class.ts similarity index 92% rename from packages/types/src/create/createClass.ts rename to packages/types-create/src/create/class.ts index aaaf5d8a2e..b7a2c7e934 100644 --- a/packages/types/src/create/createClass.ts +++ b/packages/types-create/src/create/class.ts @@ -1,15 +1,14 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-create authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Codec, CodecClass, CodecRegistry, U8aBitLength, UIntBitLength } from '@polkadot/types-codec/types'; -import type { DetectCodec, LookupRegistry } from '../types'; -import type { TypeDef } from './types'; +import type { CreateRegistry, TypeDef } from '../types'; import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperOpaque } from '@polkadot/types-codec'; import { assert, isNumber, stringify } from '@polkadot/util'; -import { getTypeDef } from './getTypeDef'; -import { TypeDefInfo } from './types'; +import { TypeDefInfo } from '../types'; +import { getTypeDef } from '../util/getTypeDef'; function getTypeDefType ({ lookupName, type }: TypeDef): string { return lookupName || type; @@ -143,7 +142,7 @@ const infoMapping: Record => - getTypeClass(registry, (registry as LookupRegistry).lookup.getTypeDef(value.type)), + getTypeClass(registry, (registry as CreateRegistry).lookup.getTypeDef(value.type)), [TypeDefInfo.Struct]: (registry: CodecRegistry, value: TypeDef): CodecClass => Struct.with(getTypeClassMap(value), value.alias), @@ -199,18 +198,14 @@ export function constructTypeClass (registry: CodecRegi // Returns the type Class for construction export function getTypeClass (registry: CodecRegistry, typeDef: TypeDef): CodecClass { - return (registry as LookupRegistry).getUnsafe(typeDef.type, false, typeDef) as CodecClass; -} - -export function createClass (registry: CodecRegistry, type: K): CodecClass> { - return createClassUnsafe(registry, type); + return (registry as CreateRegistry).getUnsafe(typeDef.type, false, typeDef) as CodecClass; } export function createClassUnsafe (registry: CodecRegistry, type: K): CodecClass { return getTypeClass( registry, registry.isLookupType(type) - ? (registry as LookupRegistry).lookup.getTypeDef(type) + ? (registry as CreateRegistry).lookup.getTypeDef(type) : getTypeDef(type) ); } diff --git a/packages/types-create/src/create/index.ts b/packages/types-create/src/create/index.ts new file mode 100644 index 0000000000..19bce18940 --- /dev/null +++ b/packages/types-create/src/create/index.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export * from './class'; +export * from './type'; diff --git a/packages/types/src/create/createType.ts b/packages/types-create/src/create/type.ts similarity index 73% rename from packages/types/src/create/createType.ts rename to packages/types-create/src/create/type.ts index d60ef95892..0b0e5afd54 100644 --- a/packages/types/src/create/createType.ts +++ b/packages/types-create/src/create/type.ts @@ -1,14 +1,13 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-create authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Codec, CodecClass, CodecRegistry } from '@polkadot/types-codec/types'; -import type { DetectCodec } from '../types'; -import type { CreateOptions } from './types'; +import type { Codec, CodecClass, CodecRegistry, IU8a } from '@polkadot/types-codec/types'; +import type { CreateOptions } from '../types'; import { Bytes, Option } from '@polkadot/types-codec'; import { assert, isHex, isU8a, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { createClass } from './createClass'; +import { createClassUnsafe } from './class'; // With isPedantic, actually check that the encoding matches that supplied. This // is much slower, but verifies that we have the correct types defined @@ -51,7 +50,7 @@ function initType (registry: CodecRegistry, Type: CodecClass, p checkPedantic(created, params, isPedantic); if (blockHash) { - created.createdAtHash = createType(registry, 'Hash', blockHash); + created.createdAtHash = createTypeUnsafe(registry, 'Hash', [blockHash]); } return created as T; @@ -60,12 +59,12 @@ function initType (registry: CodecRegistry, Type: CodecClass, p // An unsafe version of the `createType` below. It's unsafe because the `type` // argument here can be any string, which, when it cannot parse, will yield a // runtime error. -export function createTypeUnsafe (registry: CodecRegistry, type: K, params: unknown[] = [], options: CreateOptions = {}): DetectCodec { +export function createTypeUnsafe (registry: CodecRegistry, type: K, params: unknown[] = [], options: CreateOptions = {}): T { let Clazz: CodecClass | null = null; let firstError: Error | null = null; try { - Clazz = createClass(registry, type); + Clazz = createClassUnsafe(registry, type); return initType(registry, Clazz, params, options); } catch (error) { @@ -74,7 +73,7 @@ export function createTypeUnsafe (registry: CodecRegistry, type: K, ...params: unknown[]): DetectCodec { - return createTypeUnsafe(registry, type, params); -} diff --git a/packages/types-create/src/detectPackage.ts b/packages/types-create/src/detectPackage.ts new file mode 100644 index 0000000000..5856562a74 --- /dev/null +++ b/packages/types-create/src/detectPackage.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { packageInfo as codecInfo } from '@polkadot/types-codec'; +import { detectPackage } from '@polkadot/util'; + +import { packageInfo } from './packageInfo'; + +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [codecInfo]); diff --git a/packages/types-create/src/index.ts b/packages/types-create/src/index.ts new file mode 100644 index 0000000000..87c973efb6 --- /dev/null +++ b/packages/types-create/src/index.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import './detectPackage'; + +export * from './bundle'; diff --git a/packages/types-create/src/packageInfo.ts b/packages/types-create/src/packageInfo.ts new file mode 100644 index 0000000000..28178af2ba --- /dev/null +++ b/packages/types-create/src/packageInfo.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// Auto-generated by @polkadot/dev, do not edit + +export const packageInfo = { name: '@polkadot/types-create', version: '6.12.2-2' }; diff --git a/packages/types-create/src/types.ts b/packages/types-create/src/types.ts new file mode 100644 index 0000000000..92f821aabf --- /dev/null +++ b/packages/types-create/src/types.ts @@ -0,0 +1,67 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { Codec, CodecClass, CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types'; + +export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types'; + +export enum TypeDefInfo { + BTreeMap, + BTreeSet, + Compact, + DoNotConstruct, + Enum, + HashMap, + Int, + Linkage, + Null, + Option, + Plain, + Range, + Result, + Set, + Si, + Struct, + Tuple, + UInt, + Vec, + VecFixed, + WrapperOpaque +} + +export interface TypeDef { + alias?: Map; + displayName?: string; + docs?: string[]; + fallbackType?: string; + info: TypeDefInfo; + index?: number; + isFromSi?: boolean; + length?: number; + lookupIndex?: number; + lookupName?: string; + lookupNameRoot?: string; + name?: string; + namespace?: string; + sub?: TypeDef | TypeDef[]; + type: string; + typeName?: string; +} + +export interface ILookup { + getSiType (lookupId: ICompact | string | number): { + def: { + asTuple: ICompact[] + } + }, + getTypeDef (lookupId: ICompact | string | number): TypeDef; +} + +export interface CreateRegistry extends CodecRegistry { + lookup: ILookup; + + createLookupType (lookupId: ICompact | number): string; + setLookup (lookup: ILookup): void; + + getUnsafe (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass | undefined; +} diff --git a/packages/types/src/create/encodeTypes.ts b/packages/types-create/src/util/encodeTypes.ts similarity index 97% rename from packages/types/src/create/encodeTypes.ts rename to packages/types-create/src/util/encodeTypes.ts index 7f0c2ff0d4..5eb4c7cd60 100644 --- a/packages/types/src/create/encodeTypes.ts +++ b/packages/types-create/src/util/encodeTypes.ts @@ -1,12 +1,12 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-create authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { CodecRegistry } from '@polkadot/types-codec/types'; -import type { TypeDef } from './types'; +import type { TypeDef } from '@polkadot/types-create/types'; import { assert, isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util'; -import { TypeDefInfo } from './types'; +import { TypeDefInfo } from '../types'; const stringIdentity = string }> (value: T): string => value.toString(); diff --git a/packages/types/src/create/getTypeDef.ts b/packages/types-create/src/util/getTypeDef.ts similarity index 98% rename from packages/types/src/create/getTypeDef.ts rename to packages/types-create/src/util/getTypeDef.ts index 1bae1d38a9..ad3744c696 100644 --- a/packages/types/src/create/getTypeDef.ts +++ b/packages/types-create/src/util/getTypeDef.ts @@ -1,12 +1,12 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-create authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { TypeDef } from './types'; +import type { TypeDef } from '@polkadot/types-create/types'; import { sanitize } from '@polkadot/types-codec'; import { assert, isNumber, isString, objectSpread } from '@polkadot/util'; -import { TypeDefInfo } from './types'; +import { TypeDefInfo } from '../types'; import { typeSplit } from './typeSplit'; interface TypeDefOptions { diff --git a/packages/types-create/src/util/index.ts b/packages/types-create/src/util/index.ts new file mode 100644 index 0000000000..6e484377ec --- /dev/null +++ b/packages/types-create/src/util/index.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2021 @polkadot/types-create authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export * from './encodeTypes'; +export * from './getTypeDef'; +export * from './typeSplit'; diff --git a/packages/types/src/create/typeSplit.ts b/packages/types-create/src/util/typeSplit.ts similarity index 95% rename from packages/types/src/create/typeSplit.ts rename to packages/types-create/src/util/typeSplit.ts index fdf39161be..200ece3ca8 100644 --- a/packages/types/src/create/typeSplit.ts +++ b/packages/types-create/src/util/typeSplit.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-create authors & contributors // SPDX-License-Identifier: Apache-2.0 import { assert } from '@polkadot/util'; diff --git a/packages/types-create/tsconfig.json b/packages/types-create/tsconfig.json new file mode 100644 index 0000000000..c477fce8b3 --- /dev/null +++ b/packages/types-create/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "outDir": "./build", + "rootDir": "./src", + "resolveJsonModule": true + }, + "references": [ + { "path": "../types-codec" } + ] +} diff --git a/packages/types-known/src/bundle.ts b/packages/types-known/src/bundle.ts index b06ef0f4b6..95bfc92a4c 100644 --- a/packages/types-known/src/bundle.ts +++ b/packages/types-known/src/bundle.ts @@ -1,6 +1,6 @@ // Copyright 2017-2021 @polkadot/types-known authors & contributors // SPDX-License-Identifier: Apache-2.0 -export * from '@polkadot/types/known'; +export { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types'; export { packageInfo } from './packageInfo'; diff --git a/packages/types/package.json b/packages/types/package.json index af5907b27d..29941a11a6 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -25,6 +25,7 @@ "dependencies": { "@babel/runtime": "^7.16.5", "@polkadot/types-codec": "6.12.2-2", + "@polkadot/types-create": "6.12.2-2", "@polkadot/util": "^8.1.2", "@polkadot/util-crypto": "^8.1.2", "rxjs": "^7.4.0" diff --git a/packages/types/src/bundle.ts b/packages/types/src/bundle.ts index e723a75a0b..a297c66742 100644 --- a/packages/types/src/bundle.ts +++ b/packages/types/src/bundle.ts @@ -7,9 +7,11 @@ import rpcDefinitions from './interfaces/jsonrpc'; export * from './codec'; export * from './create'; export * from './index.types'; +export * from './known'; export * from './metadata'; -export { TypeDefInfo } from './create/types'; +export { TypeDefInfo } from '@polkadot/types-create'; + export { convertSiV0toV1 } from './metadata/PortableRegistry'; export { packageInfo } from './packageInfo'; export { unwrapStorageType } from './primitive/StorageKey'; diff --git a/packages/types/src/create/createClass.spec.ts b/packages/types/src/create/createClass.spec.ts index bdf5ed2627..35e9ae85cb 100644 --- a/packages/types/src/create/createClass.spec.ts +++ b/packages/types/src/create/createClass.spec.ts @@ -1,7 +1,8 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDefInfo } from '../types'; +import { TypeDefInfo } from '@polkadot/types-create'; + import { createClass, getTypeClass, TypeRegistry } from '.'; describe('createClass', (): void => { diff --git a/packages/types/src/create/encodeTypes.spec.ts b/packages/types/src/create/encodeTypes.spec.ts index 3c0e65b95d..f283edc23a 100644 --- a/packages/types/src/create/encodeTypes.spec.ts +++ b/packages/types/src/create/encodeTypes.spec.ts @@ -1,9 +1,10 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { encodeTypeDef } from './encodeTypes'; +import { TypeDefInfo } from '@polkadot/types-create'; + import { TypeRegistry } from './registry'; -import { TypeDefInfo } from './types'; +import { encodeTypeDef } from '.'; describe('encodeTypeDef', (): void => { const registry = new TypeRegistry(); diff --git a/packages/types/src/create/getTypeDef.spec.ts b/packages/types/src/create/getTypeDef.spec.ts index 47357fca57..96c2378700 100644 --- a/packages/types/src/create/getTypeDef.spec.ts +++ b/packages/types/src/create/getTypeDef.spec.ts @@ -1,7 +1,8 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { TypeDefInfo } from './types'; +import { TypeDefInfo } from '@polkadot/types-create'; + import { getTypeDef, TypeRegistry } from '.'; describe('getTypeDef', (): void => { diff --git a/packages/types/src/create/index.ts b/packages/types/src/create/index.ts index a1bde39723..7e2836ab74 100644 --- a/packages/types/src/create/index.ts +++ b/packages/types/src/create/index.ts @@ -1,10 +1,26 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -export * from './createClass'; -export * from './createType'; -export * from './encodeTypes'; -export * from './getTypeDef'; +import type { Codec, CodecClass, CodecRegistry } from '@polkadot/types-codec/types'; +import type { DetectCodec } from '../types'; + +import { createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create'; + +export * from '@polkadot/types-create'; + export * from './lazy'; export * from './registry'; -export * from './typeSplit'; + +export function createClass (registry: CodecRegistry, type: K): CodecClass> { + return createClassUnsafe(registry, type); +} + +/** + * Create an instance of a `type` with a given `params`. + * @param type - A recognizable string representing the type to create an + * instance from + * @param params - The value to instantiate the type with + */ +export function createType (registry: CodecRegistry, type: K, ...params: unknown[]): DetectCodec { + return createTypeUnsafe(registry, type, params); +} diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 29bfbc64d7..e180271363 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import type { Codec, CodecClass, CodecRegistry, IU8a } from '@polkadot/types-codec/types'; +import type { CreateOptions, TypeDef } from '@polkadot/types-create/types'; import type { ExtDef } from '../extrinsic/signedExtensions/types'; import type { ChainProperties, DispatchErrorModule, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types'; import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types'; -import type { CreateOptions, TypeDef } from './types'; import { DoNotConstruct, Json, Raw } from '@polkadot/types-codec'; +import { constructTypeClass, createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create'; import { assert, assertReturn, BN_ZERO, formatBalance, isFunction, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util'; import { blake2AsU8a } from '@polkadot/util-crypto'; @@ -19,8 +20,6 @@ import { decorateConstants, filterCallsSome, filterEventsSome } from '../metadat import { createCallFunction } from '../metadata/decorate/extrinsics'; import { Metadata } from '../metadata/Metadata'; import { PortableRegistry } from '../metadata/PortableRegistry'; -import { constructTypeClass, createClassUnsafe } from './createClass'; -import { createTypeUnsafe } from './createType'; import { lazyVariants } from './lazy'; const l = logger('registry'); @@ -266,8 +265,8 @@ export class TypeRegistry implements Registry { /** * @describe Creates an instance of the class */ - public createClass > (type: K): CodecClass { - return this.createClassUnsafe(type) as unknown as CodecClass; + public createClass (type: K): CodecClass> { + return this.createClassUnsafe(type) as unknown as CodecClass>; } /** @@ -280,7 +279,7 @@ export class TypeRegistry implements Registry { /** * @description Creates an instance of a type as registered */ - public createType > (type: K, ...params: unknown[]): R { + public createType (type: K, ...params: unknown[]): DetectCodec { return this.createTypeUnsafe(type, params); } diff --git a/packages/types/src/create/types.ts b/packages/types/src/create/types.ts index a3544fc216..34c4c4849f 100644 --- a/packages/types/src/create/types.ts +++ b/packages/types/src/create/types.ts @@ -2,46 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types'; +export type { TypeDef } from '@polkadot/types-create/types'; -export enum TypeDefInfo { - BTreeMap, - BTreeSet, - Compact, - DoNotConstruct, - Enum, - HashMap, - Int, - Linkage, - Null, - Option, - Plain, - Range, - Result, - Set, - Si, - Struct, - Tuple, - UInt, - Vec, - VecFixed, - WrapperOpaque -} - -export interface TypeDef { - alias?: Map; - displayName?: string; - docs?: string[]; - fallbackType?: string; - info: TypeDefInfo; - index?: number; - isFromSi?: boolean; - length?: number; - lookupIndex?: number; - lookupName?: string; - lookupNameRoot?: string; - name?: string; - namespace?: string; - sub?: TypeDef | TypeDef[]; - type: string; - typeName?: string; -} +export { TypeDefInfo } from '@polkadot/types-create'; diff --git a/packages/types/src/detectPackage.ts b/packages/types/src/detectPackage.ts index 8e767bef4a..a4c89c8202 100644 --- a/packages/types/src/detectPackage.ts +++ b/packages/types/src/detectPackage.ts @@ -2,8 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import { packageInfo as codecInfo } from '@polkadot/types-codec'; +import { packageInfo as createInfo } from '@polkadot/types-create'; import { detectPackage } from '@polkadot/util'; import { packageInfo } from './packageInfo'; -detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [codecInfo]); +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [codecInfo, createInfo]); diff --git a/packages/types/src/generic/Event.ts b/packages/types/src/generic/Event.ts index d36386bca5..cbc2809200 100644 --- a/packages/types/src/generic/Event.ts +++ b/packages/types/src/generic/Event.ts @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import type { AnyJson, Codec, CodecClass, CodecRegistry } from '@polkadot/types-codec/types'; -import type { TypeDef } from '../create/types'; +import type { CreateRegistry, TypeDef } from '@polkadot/types-create/types'; import type { EventMetadataLatest } from '../interfaces/metadata'; import type { EventId } from '../interfaces/system'; -import type { IEvent, IEventData, InterfaceTypes, LookupRegistry } from '../types'; +import type { IEvent, IEventData, InterfaceTypes } from '../types'; import { Null, Struct, Tuple } from '@polkadot/types-codec'; import { objectSpread } from '@polkadot/util'; @@ -57,7 +57,7 @@ export class GenericEventData extends Tuple implements IEventData { this.#meta = meta; this.#method = method; this.#section = section; - this.#typeDef = fields.map(({ type }) => (registry as LookupRegistry).lookup.getTypeDef(type)); + this.#typeDef = fields.map(({ type }) => (registry as CreateRegistry).lookup.getTypeDef(type)); } /** diff --git a/packages/types/src/known/index.ts b/packages/types/src/known/index.ts index f143ab9592..82ff60a120 100644 --- a/packages/types/src/known/index.ts +++ b/packages/types/src/known/index.ts @@ -1,10 +1,10 @@ // Copyright 2017-2021 @polkadot/types-known authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { Text } from '@polkadot/types-codec'; import type { BN } from '@polkadot/util'; import type { ExtDef } from '../extrinsic/signedExtensions/types'; import type { Hash } from '../interfaces'; -import type { Text } from '../primitive'; import type { ChainUpgradeVersion, CodecHasher, DefinitionRpc, DefinitionRpcSub, OverrideModuleType, OverrideVersionedType, Registry, RegistryTypes } from '../types'; import { bnToBn, isNull, isUndefined, objectSpread } from '@polkadot/util'; diff --git a/packages/types/src/known/knownOrigins.ts b/packages/types/src/known/knownOrigins.ts index 077a4de0a8..062fcad1ff 100644 --- a/packages/types/src/known/knownOrigins.ts +++ b/packages/types/src/known/knownOrigins.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors +// Copyright 2017-2021 @polkadot/types-known authors & contributors // SPDX-License-Identifier: Apache-2.0 // We want predictive ordering (manually managed) diff --git a/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts b/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts index db35e862d6..8855c321bf 100644 --- a/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts +++ b/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts @@ -3,18 +3,15 @@ import type { Vec } from '@polkadot/types-codec'; import type { CodecRegistry } from '@polkadot/types-codec/types'; +import type { ILookup, TypeDef } from '@polkadot/types-create/types'; import type { PortableType } from '../../interfaces/metadata'; import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../../interfaces/scaleInfo'; import type { Text, Type } from '../../primitive'; -import type { ILookup, TypeDef } from '../../types'; -import { sanitize, Struct } from '@polkadot/types-codec'; +import { sanitize, Struct, u32 } from '@polkadot/types-codec'; +import { getTypeDef, TypeDefInfo, withTypeString } from '@polkadot/types-create'; import { assert, isNumber, isString, objectSpread, stringCamelCase, stringify, stringPascalCase } from '@polkadot/util'; -import { withTypeString } from '../../create/encodeTypes'; -import { getTypeDef } from '../../create/getTypeDef'; -import { u32 } from '../../primitive'; -import { TypeDefInfo } from '../../types'; import { assertUnreachable } from './util'; // Just a placeholder for a type.unrwapOr() diff --git a/packages/types/src/metadata/decorate/storage/createFunction.ts b/packages/types/src/metadata/decorate/storage/createFunction.ts index 2e2c7e2eb6..923417d3d5 100644 --- a/packages/types/src/metadata/decorate/storage/createFunction.ts +++ b/packages/types/src/metadata/decorate/storage/createFunction.ts @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import type { CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types'; +import type { CreateRegistry } from '@polkadot/types-create/types'; import type { StorageEntryMetadataLatest, StorageHasher } from '../../../interfaces/metadata'; import type { StorageEntry } from '../../../primitive/types'; -import type { LookupRegistry } from '../../../types'; import { Raw } from '@polkadot/types-codec'; import { assert, compactAddLength, compactStripLength, isUndefined, objectSpread, stringCamelCase, stringLowerFirst, u8aConcat, u8aToU8a } from '@polkadot/util'; @@ -104,7 +104,7 @@ function createWStorageFn (registry: CodecRegistry, itemFn: CreateItemFn, option return hashers.length === 1 ? createKey(registry, itemFn, { args, hashers, keys: [key] }) - : createKey(registry, itemFn, { args, hashers, keys: (registry as LookupRegistry).lookup.getSiType(key).def.asTuple }); + : createKey(registry, itemFn, { args, hashers, keys: (registry as CreateRegistry).lookup.getSiType(key).def.asTuple }); }; } @@ -162,7 +162,7 @@ function extendPrefixedMap (registry: CodecRegistry, itemFn: CreateItemFn, stora const { hashers, key } = type.asMap; const keysVec = hashers.length === 1 ? [key] - : (registry as LookupRegistry).lookup.getSiType(key).def.asTuple; + : (registry as CreateRegistry).lookup.getSiType(key).def.asTuple; return new Raw(registry, createKeyRaw(registry, itemFn, { args, hashers: hashers.slice(0, args.length), keys: keysVec.slice(0, args.length) })); } diff --git a/packages/types/src/metadata/util/extractTypes.ts b/packages/types/src/metadata/util/extractTypes.ts index 925f9300fb..6359dd57ca 100644 --- a/packages/types/src/metadata/util/extractTypes.ts +++ b/packages/types/src/metadata/util/extractTypes.ts @@ -1,11 +1,9 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { TypeDef } from '../../types'; +import type { TypeDef } from '@polkadot/types-create/types'; -// we are attempting to avoid circular refs, hence the path import -import { getTypeDef } from '../../create/getTypeDef'; -import { TypeDefInfo } from '../../create/types'; +import { getTypeDef, TypeDefInfo } from '@polkadot/types-create'; type Extracted = string | Extracted[]; diff --git a/packages/types/src/metadata/util/getSiName.ts b/packages/types/src/metadata/util/getSiName.ts index a22031ae87..b54001c703 100644 --- a/packages/types/src/metadata/util/getSiName.ts +++ b/packages/types/src/metadata/util/getSiName.ts @@ -1,8 +1,8 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { ILookup } from '@polkadot/types-create/types'; import type { SiLookupTypeId } from '../../interfaces'; -import type { ILookup } from '../../types'; export function getSiName (lookup: ILookup, type: SiLookupTypeId): string { const typeDef = lookup.getTypeDef(type); diff --git a/packages/types/src/metadata/v13/toV14.ts b/packages/types/src/metadata/v13/toV14.ts index 8e8fa89c46..e0afe9a1a7 100644 --- a/packages/types/src/metadata/v13/toV14.ts +++ b/packages/types/src/metadata/v13/toV14.ts @@ -1,11 +1,10 @@ // Copyright 2017-2021 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Text } from '@polkadot/types-codec'; +import type { Text, Type } from '@polkadot/types-codec'; import type { CodecRegistry } from '@polkadot/types-codec/types'; import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageHasherV13, StorageMetadataV13 } from '../../interfaces/metadata'; import type { SiVariant } from '../../interfaces/scaleInfo'; -import type { Type } from '../../primitive/Type'; import type { OverrideModuleType, Registry } from '../../types'; import { stringCamelCase } from '@polkadot/util'; diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index e15137ebeb..4e6ae93d7b 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -2,10 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 import type { AnyJson, AnyTuple, Codec, CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types'; +import type { CreateRegistry } from '@polkadot/types-create/types'; import type { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata'; import type { AllHashers } from '../interfaces/metadata/definitions'; import type { SiLookupTypeId } from '../interfaces/scaleInfo'; -import type { InterfaceTypes, IStorageKey, LookupRegistry } from '../types'; +import type { InterfaceTypes, IStorageKey } from '../types'; import type { StorageEntry } from './types'; import { Bytes } from '@polkadot/types-codec'; @@ -44,7 +45,7 @@ export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId { /** @internal */ export function unwrapStorageType (registry: CodecRegistry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes { - const outputType = getSiName((registry as LookupRegistry).lookup, unwrapStorageSi(type)); + const outputType = getSiName((registry as CreateRegistry).lookup, unwrapStorageSi(type)); return isOptional ? `Option<${outputType}>` as unknown as keyof InterfaceTypes @@ -118,7 +119,7 @@ function decodeArgsFromMeta (registry: CodecRegistry, value const { hashers, key } = meta.type.asMap; const keys = hashers.length === 1 ? [key] - : (registry as LookupRegistry).lookup.getSiType(key).def.asTuple; + : (registry as CreateRegistry).lookup.getSiType(key).def.asTuple; return decodeHashers(registry, value, hashers.map((h, i) => [h, keys[i]])); } diff --git a/packages/types/src/primitive/Type.ts b/packages/types/src/primitive/Type.ts deleted file mode 100644 index 803aa109a0..0000000000 --- a/packages/types/src/primitive/Type.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017-2021 @polkadot/types authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { CodecRegistry } from '@polkadot/types-codec/types'; - -import { sanitize, Text } from '@polkadot/types-codec'; - -/** - * @name Type - * @description - * This is a extended version of Text, specifically to handle types. Here we rely fully - * on what Text provides us, however we also adjust the types received from the runtime, - * i.e. we remove the `T::` prefixes found in some types for consistency across implementation. - */ -export class Type extends Text { - constructor (registry: CodecRegistry, value: Text | Uint8Array | string = '') { - super(registry, value); - - this.setOverride(sanitize(this.toString())); - } - - /** - * @description Returns the base runtime type name for this instance - */ - public override toRawType (): string { - return 'Type'; - } -} diff --git a/packages/types/src/primitive/index.ts b/packages/types/src/primitive/index.ts index d8e9b06c1c..e0debe397c 100644 --- a/packages/types/src/primitive/index.ts +++ b/packages/types/src/primitive/index.ts @@ -4,7 +4,7 @@ /** * @summary Type definitions that are used in the system */ -export { BitVec, bool, Bool, Bytes, Type, i8, I8, i16, I16, i32, I32, i64, I64, i128, I128, i256, I256, Null, Text, u8, U8, u16, U16, u32, U32, u64, U64, u128, U128, u256, U256, usize, USize } from '@polkadot/types-codec'; +export { BitVec, bool, Bool, Bytes, i8, I8, i16, I16, i32, I32, i64, I64, i128, I128, i256, I256, Null, Text, Type, u8, U8, u16, U16, u32, U32, u64, U64, u128, U128, u256, U256, usize, USize } from '@polkadot/types-codec'; export { Data } from './Data'; export { StorageKey } from './StorageKey'; diff --git a/packages/types/src/types/registry.ts b/packages/types/src/types/registry.ts index 5d5baa40ff..481171fec9 100644 --- a/packages/types/src/types/registry.ts +++ b/packages/types/src/types/registry.ts @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; -import type { CodecRegistry, ICompact, INumber, RegistryTypes } from '@polkadot/types-codec/types'; +import type { RegistryTypes } from '@polkadot/types-codec/types'; +import type { CreateRegistry, TypeDef } from '@polkadot/types-create/types'; import type { BN } from '@polkadot/util'; -import type { TypeDef } from '../create/types'; import type { ExtDef } from '../extrinsic/signedExtensions/types'; import type { MetadataLatest } from '../interfaces/metadata'; import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo'; @@ -96,26 +96,8 @@ export interface RegisteredTypes { typesSpec?: Record; } -export interface ILookup { - getSiType (lookupId: ICompact | string | number): { - def: { - asTuple: ICompact[] - } - }, - getTypeDef (lookupId: ICompact | string | number): TypeDef; -} - -export interface LookupRegistry extends CodecRegistry { - lookup: ILookup; - - createLookupType (lookupId: ICompact | number): string; - setLookup (lookup: ILookup): void; - - getUnsafe (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass | undefined; -} - // Note the commented interfaces here are directly from CodecRegistry -export interface Registry extends LookupRegistry { +export interface Registry extends CreateRegistry { // readonly chainDecimals: number[]; // readonly chainSS58: number | undefined; // readonly chainTokens: string[]; diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json index 9dd06fd436..6a24449ba0 100644 --- a/packages/types/tsconfig.json +++ b/packages/types/tsconfig.json @@ -8,6 +8,7 @@ }, "references": [ { "path": "../types-codec" }, + { "path": "../types-create" }, { "path": "../types-support" } ] } diff --git a/rollup.config.mjs b/rollup.config.mjs index 3496110922..0e8476eaf0 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -18,7 +18,15 @@ const external = [ '@polkadot/util-crypto' ]; -const entries = ['api-derive', 'rpc-core', 'rpc-provider', 'types-codec', 'types-known'].reduce((all, p) => ({ +function expand (prefix, all) { + return all.map((p) => `${prefix}-${p}`); +} + +const entries = [ + 'api-derive', + ...expand('rpc', ['core', 'provider']), + ...expand('types', ['codec', 'create', 'known']) +].reduce((all, p) => ({ ...all, [`@polkadot/${p}`]: path.resolve(process.cwd(), `packages/${p}/build/bundle.js`) }), { diff --git a/tsconfig.base.json b/tsconfig.base.json index fc526cd83c..4172610024 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -18,6 +18,8 @@ "@polkadot/types/*": ["types/src/*"], "@polkadot/types-codec": ["types-codec/src"], "@polkadot/types-codec/*": ["types-codec/src/*"], + "@polkadot/types-create": ["types-create/src"], + "@polkadot/types-create/*": ["types-create/src/*"], "@polkadot/types-known": ["types-known/src"], "@polkadot/types-known/*": ["types-known/src/*"], "@polkadot/types-support": ["types-support/src"], diff --git a/tsconfig.json b/tsconfig.json index 083bf93b8f..7488bdceb9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ { "path": "./packages/typegen" }, { "path": "./packages/types" }, { "path": "./packages/types-codec" }, + { "path": "./packages/types-create" }, { "path": "./packages/types-known" }, { "path": "./packages/types-support" } ] diff --git a/yarn.lock b/yarn.lock index 81808efc3a..b3489972aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1907,6 +1907,9 @@ __metadata: "@polkadot/rpc-core": 6.12.2-2 "@polkadot/rpc-provider": 6.12.2-2 "@polkadot/types": 6.12.2-2 + "@polkadot/types-codec": 6.12.2-2 + "@polkadot/types-create": 6.12.2-2 + "@polkadot/types-known": 6.12.2-2 "@polkadot/util": ^8.1.2 "@polkadot/util-crypto": ^8.1.2 eventemitter3: ^4.0.7 @@ -2079,6 +2082,7 @@ __metadata: "@polkadot/rpc-provider": 6.12.2-2 "@polkadot/types": 6.12.2-2 "@polkadot/types-codec": 6.12.2-2 + "@polkadot/types-create": 6.12.2-2 "@polkadot/types-support": 6.12.2-2 "@polkadot/util": ^8.1.2 "@types/websocket": ^1.0.4 @@ -2104,7 +2108,16 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/types-known@workspace:packages/types-known": +"@polkadot/types-create@6.12.2-2, @polkadot/types-create@workspace:packages/types-create": + version: 0.0.0-use.local + resolution: "@polkadot/types-create@workspace:packages/types-create" + dependencies: + "@babel/runtime": ^7.16.3 + "@polkadot/util": ^8.1.2 + languageName: unknown + linkType: soft + +"@polkadot/types-known@6.12.2-2, @polkadot/types-known@workspace:packages/types-known": version: 0.0.0-use.local resolution: "@polkadot/types-known@workspace:packages/types-known" dependencies: @@ -2131,6 +2144,7 @@ __metadata: "@babel/runtime": ^7.16.5 "@polkadot/keyring": ^8.1.2 "@polkadot/types-codec": 6.12.2-2 + "@polkadot/types-create": 6.12.2-2 "@polkadot/types-support": 6.12.2-2 "@polkadot/util": ^8.1.2 "@polkadot/util-crypto": ^8.1.2