Skip to content

Commit

Permalink
use typesBundle for api options (#54)
Browse files Browse the repository at this point in the history
* works

* 6.0.8

* bump v6.1.0
  • Loading branch information
shunjizhan authored Jan 24, 2024
1 parent a9a4f45 commit 3166ff0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 107 deletions.
4 changes: 2 additions & 2 deletions packages/api-derive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/api-derive",
"version": "6.0.5",
"version": "6.1.0",
"description": "Additional polkadot.js derives for Acala Network",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
Expand All @@ -23,7 +23,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"@acala-network/types": "6.0.5"
"@acala-network/types": "6.1.0"
},
"peerDependencies": {
"@polkadot/api": "^10.9.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/api",
"version": "6.0.5",
"version": "6.1.0",
"description": "Acala JS API",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
Expand All @@ -23,8 +23,8 @@
"publish:manual": "npm publish --tolerate-republish --access public"
},
"dependencies": {
"@acala-network/api-derive": "6.0.5",
"@acala-network/types": "6.0.5"
"@acala-network/api-derive": "6.1.0",
"@acala-network/types": "6.1.0"
},
"peerDependencies": {
"@polkadot/api": "^10.9.1"
Expand Down
70 changes: 6 additions & 64 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,9 @@
import { acalaTypesBundle } from '@acala-network/types';
import type { ApiOptions } from '@polkadot/api/types';
import type { RegistryTypes } from '@polkadot/types/types';

import { acalaDerives } from '@acala-network/api-derive';
import {
acalaLookupTypes,
acalaRpc,
acalaRuntime,
acalaSignedExtensions,
acalaTypes,
acalaTypesAlias,
acalaTypesBundle,
} from '@acala-network/types';

export const options = ({ derives = {},
rpc = {},
runtime = {},
signedExtensions,
types = {},
typesAlias = {},
typesBundle = {},
...otherOptions }: ApiOptions = {}): ApiOptions => ({
types: {
...acalaTypes as unknown as RegistryTypes,
...acalaLookupTypes as unknown as RegistryTypes,
...types,
},
runtime: {
...acalaRuntime,
...runtime,
},
rpc: {
...acalaRpc,
...rpc,
},
typesAlias: {
...acalaTypesAlias,
...typesAlias,
},
derives: {
...acalaDerives,
...derives,
},
typesBundle: {
spec: {
...typesBundle.spec,
acala: {
...acalaTypesBundle.spec.acala,
...typesBundle?.spec?.acala,
},
mandala: {
...acalaTypesBundle.spec.mandala,
...typesBundle?.spec?.mandala,
},
karura: {
...acalaTypesBundle.spec.karura,
...typesBundle?.spec?.mandala,
},
},
...typesBundle,
},
signedExtensions: {
...acalaSignedExtensions,
...signedExtensions,
},
...otherOptions,
export const options = ({ provider }: ApiOptions = {}): ApiOptions => ({
typesBundle: acalaTypesBundle,
provider,
});

export const withAcalaTypes = options;
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/types",
"version": "6.0.5",
"version": "6.1.0",
"description": "Acala types for @polkadot/api",
"author": "Acala Developers <[email protected]>",
"license": "Apache-2.0",
Expand Down
57 changes: 25 additions & 32 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import './interfaces/augment-api';
import './interfaces/augment-types';
import './interfaces/types-lookup';

import type { OverrideBundleType, OverrideVersionedType } from '@polkadot/types/types';
import type { OverrideBundleDefinition, OverrideBundleType } from '@polkadot/types/types';

import * as acalaDefs from './interfaces/definitions';
import { acalaVersioned, karuraVersioned, mandalaVersioned } from './versioned';
import { jsonrpcFromDefs, typesAliasFromDefs, typesFromDefs } from './utils';
import { versioned } from './versioned';

export * as acalaLookupTypes from './interfaces/lookup';
export { acalaSignedExtensions } from './signedExtensions';
import { acalaSignedExtensions } from './signedExtensions';
export { acalaSignedExtensions };

// FIXME: currently we cannot override this in runtime definations because the code generation script cannot handle overrides
// This will make it behave correctly in runtime, but wrong types in TS defination.
Expand All @@ -24,36 +25,28 @@ export const acalaRpc = jsonrpcFromDefs(acalaDefs, {});
export const acalaTypesAlias = typesAliasFromDefs(acalaDefs, {});
export const acalaRuntime = acalaDefs.runtime.runtime;

function getBundle (versioned: OverrideVersionedType[]) {
return {
acalaRpc,
instances: { council: ['generalCouncil'] },
types: [...versioned].map((version) => {
return {
minmax: version.minmax,
types: {
...acalaTypes,
...version.types,
},
};
}),
alias: acalaTypesAlias,
};
}

export const acalaTypesBundle = {
spec: {
acala: getBundle(acalaVersioned),
mandala: getBundle(mandalaVersioned),
karura: getBundle(karuraVersioned),
},
} as unknown as OverrideBundleType;
const sharedBundle: OverrideBundleDefinition = {
rpc: acalaRpc,
instances: { council: ['generalCouncil'] },
types: versioned.map((version) => ({
minmax: version.minmax,
types: {
...acalaTypes,
...version.types,
},
})),
alias: acalaTypesAlias,
signedExtensions: acalaSignedExtensions,
runtime: acalaRuntime,
};

// Type overrides have priority issues
export const typesBundleForPolkadot = {
export const acalaTypesBundle: OverrideBundleType = {
spec: {
acala: getBundle(acalaVersioned),
mandala: getBundle(mandalaVersioned),
karura: getBundle(karuraVersioned),
acala: sharedBundle,
mandala: sharedBundle,
karura: sharedBundle,
},
};

// Type overrides have priority issues
export const typesBundleForPolkadot = acalaTypesBundle;
1 change: 1 addition & 0 deletions packages/types/src/versioned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ const versioned: OverrideVersionedType[] = [
},
];

export { versioned };
export const acalaVersioned = versioned;
export const karuraVersioned = versioned;
export const mandalaVersioned = versioned;
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ __metadata:
languageName: node
linkType: hard

"@acala-network/api-derive@6.0.5, @acala-network/api-derive@workspace:packages/api-derive":
"@acala-network/api-derive@6.1.0, @acala-network/api-derive@workspace:packages/api-derive":
version: 0.0.0-use.local
resolution: "@acala-network/api-derive@workspace:packages/api-derive"
dependencies:
"@acala-network/types": 6.0.5
"@acala-network/types": 6.1.0
typescript: ^5.0.4
peerDependencies:
"@polkadot/api": ^10.9.1
Expand All @@ -27,15 +27,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "@acala-network/api@workspace:packages/api"
dependencies:
"@acala-network/api-derive": 6.0.5
"@acala-network/types": 6.0.5
"@acala-network/api-derive": 6.1.0
"@acala-network/types": 6.1.0
typescript: ^5.0.4
peerDependencies:
"@polkadot/api": ^10.9.1
languageName: unknown
linkType: soft

"@acala-network/types@6.0.5, @acala-network/types@workspace:packages/types":
"@acala-network/types@6.1.0, @acala-network/types@workspace:packages/types":
version: 0.0.0-use.local
resolution: "@acala-network/types@workspace:packages/types"
dependencies:
Expand Down

0 comments on commit 3166ff0

Please sign in to comment.