Browse Source

types: additional potential circular dep fixes

Mokhtar Naamani 4 years ago
parent
commit
27081e80a6

+ 5 - 0
types/src/common.ts

@@ -7,6 +7,9 @@ export { JoyStruct } from './JoyStruct';
 // Treat a BTreeSet as a Vec since it is encoded in the same way
 export class BTreeSet<T extends Codec> extends Vec<T> {}
 
+export class Credential extends u64 {}
+export class CredentialSet extends Vec.with(Credential) {} // BtreeSet ?
+
 // common types between Forum and Proposal Discussions modules
 export class ThreadId extends u64 {}
 export class PostId extends u64 {}
@@ -89,6 +92,8 @@ export function registerCommonTypes() {
     const typeRegistry = getTypeRegistry();
 
     typeRegistry.register({
+      Credential,
+      CredentialSet,
       BlockAndTime,
       ThreadId,
       PostId,

+ 3 - 0
types/src/content-working-group/ChannelId.ts

@@ -0,0 +1,3 @@
+import { ActorId } from '../members';
+
+export default class ChannelId extends ActorId {};

+ 4 - 4
types/src/content-working-group/index.ts

@@ -1,20 +1,20 @@
 import { getTypeRegistry, BTreeMap, Enum, bool, u8, u32, u128, Text, GenericAccountId, Null , Option, Vec, u16 } from '@polkadot/types';
 import { BlockNumber, AccountId, Balance } from '@polkadot/types/interfaces';
-import { BTreeSet, JoyStruct } from '../common';
+import { BTreeSet, JoyStruct, OptionText, Credential } from '../common';
 import { ActorId, MemberId } from '../members';
 import { StakeId } from '../stake';
 import { OpeningId, ApplicationId, ApplicationRationingPolicy, StakingPolicy } from '../hiring/index';
-import { Credential } from '../versioned-store/permissions/credentials';
 import { RewardRelationshipId } from '../recurring-rewards';
 
-export class ChannelId extends ActorId {};
+import ChannelId from './ChannelId';
+export { ChannelId };
 export class CuratorId extends ActorId {};
 export class CuratorOpeningId extends OpeningId {};
 export class CuratorApplicationId extends ApplicationId {};
 export class LeadId extends ActorId {};
 export class PrincipalId extends Credential {};
 
-export class OptionalText extends Option.with(Text) {};
+export class OptionalText extends OptionText {};
 
 export type ChannelContentTypeValue =
   'Video' |

+ 4 - 4
types/src/index.ts

@@ -10,12 +10,12 @@ import { registerStakeTypes } from "./stake";
 import { registerMintTypes } from "./mint";
 import { registerRecurringRewardsTypes } from "./recurring-rewards";
 import { registerHiringTypes } from "./hiring";
-import { registerVersionedStoreTypes } from "./versioned-store"; //Circular dep FIX needed - depends on ChannelId from content working group!
-import { registerVersionedStorePermissionsTypes } from "./versioned-store/permissions"; // depends on versioned store!
-import { registerContentWorkingGroupTypes } from "./content-working-group"; // depends on Credential from versioned permissions store!
+import { registerVersionedStoreTypes } from "./versioned-store";
+import { registerVersionedStorePermissionsTypes } from "./versioned-store/permissions";
+import { registerContentWorkingGroupTypes } from "./content-working-group";
 import { registerBureaucracyTypes } from "./bureaucracy";
 import { registerDiscoveryTypes } from "./discovery";
-import { registerMediaTypes } from "./media"; // depends on StorageProviderId from buraucracy.. not ideal
+import { registerMediaTypes } from "./media";
 import { registerProposalTypes } from "./proposals";
 
 export function registerJoystreamTypes() {

+ 2 - 2
types/src/versioned-store/EntityCodec.ts

@@ -1,11 +1,11 @@
 import BN from 'bn.js';
 import { Text, bool, Vec, u16 } from '@polkadot/types';
 import { Codec } from '@polkadot/types/types';
+import { Class, Entity, VecClassPropertyValue, ClassPropertyValue, EntityId, ClassId, unifyPropName } from '.';
 import * as PV from './PropertyValue';
 import { PropertyValue } from './PropertyValue';
-import { Class, Entity, VecClassPropertyValue, ClassPropertyValue, EntityId, ClassId, unifyPropName } from '.';
 import PropertyTypeName from './PropertyTypeName';
-import { ChannelId } from '../content-working-group';
+import ChannelId from '../content-working-group/ChannelId';
 
 /**
  * Convert a Substrate value to a plain JavaScript value of a corresponding type

+ 3 - 30
types/src/versioned-store/index.ts

@@ -1,10 +1,10 @@
 import { getTypeRegistry, u16, Text, bool as Bool } from '@polkadot/types';
 import { Vec as Vector } from '@polkadot/types/codec';
-import { JoyStruct } from '../JoyStruct';
+import { JoyStruct } from '../common';
+import EntityId from './EntityId';
+import ClassId from './ClassId';
 import PropertyType from './PropertyType';
 import PropertyValue from './PropertyValue';
-import ClassId from './ClassId';
-import EntityId from './EntityId';
 import { camelCase, upperFirst } from 'lodash'
 
 export {
@@ -14,32 +14,6 @@ export {
   PropertyValue
 }
 
-export type InputValidationLengthConstraintType = {
-  min: u16,
-  max_min_diff: u16
-};
-
-export class InputValidationLengthConstraint extends JoyStruct<InputValidationLengthConstraintType> {
-  constructor (value: InputValidationLengthConstraintType) {
-    super({
-      min: u16,
-      max_min_diff: u16
-    }, value);
-  }
-
-  get min (): u16 {
-    return this.getField('min');
-  }
-
-  get max_min_diff (): u16 {
-    return this.getField('max_min_diff');
-  }
-
-  get max (): u16 {
-    return new u16(this.min.add(this.max_min_diff));
-  }
-}
-
 export type PropertyTsType = {
   prop_type: PropertyType,
   required: Bool,
@@ -224,7 +198,6 @@ export function unifyPropName(propName: string): string {
 export function registerVersionedStoreTypes () {
   try {
     getTypeRegistry().register({
-      InputValidationLengthConstraint,
       ClassId: 'u64',
       EntityId: 'u64',
       Class,

+ 2 - 3
types/src/versioned-store/permissions/ClassPermissions.ts

@@ -1,9 +1,8 @@
-import { JoyStruct } from '../../JoyStruct';
 import { u32, bool } from '@polkadot/types';
+import { BlockNumber } from '@polkadot/types/interfaces';
+import { JoyStruct, CredentialSet } from '../../common';
 import EntityPermissions from './EntityPermissions';
-import { CredentialSet } from './credentials';
 import { ReferenceConstraint } from './reference-constraint';
-import { BlockNumber } from '@polkadot/types/interfaces';
 
 type IClassPermissions = {
     entity_permissions: EntityPermissions,

+ 1 - 1
types/src/versioned-store/permissions/EntityPermissions.ts

@@ -1,6 +1,6 @@
 import { JoyStruct } from '../../JoyStruct';
 import { bool } from '@polkadot/types';
-import { CredentialSet } from './credentials';
+import { CredentialSet } from '../../common';
 
 type IEntityPermissions = {
     update: CredentialSet,

+ 2 - 3
types/src/versioned-store/permissions/PropertyOfClass.ts

@@ -1,7 +1,6 @@
-import { JoyStruct } from '../../JoyStruct';
-import ClassId from '../ClassId';
 import { u16 } from '@polkadot/types';
-
+import { JoyStruct } from '../../common';
+import ClassId from '../ClassId';
 
 type IPropertyOfClass = {
     class_id: ClassId,

+ 1 - 1
types/src/versioned-store/permissions/batching/ParametrizedClassPropertyValue.ts

@@ -1,6 +1,6 @@
 
 import { ParametrizedPropertyValue } from './parametrized-property-value';
-import { JoyStruct } from '../../../JoyStruct';
+import { JoyStruct } from '../../../common';
 import { u16 } from '@polkadot/types';
 
 type IParametrizedClassPropertyValue = {

+ 1 - 2
types/src/versioned-store/permissions/batching/index.ts

@@ -1,7 +1,6 @@
-import { JoyStruct } from '../../../JoyStruct';
+import { JoyStruct, Credential } from '../../../common';
 import { OperationType } from './operation-types';
 import { bool, Option } from '@polkadot/types';
-import { Credential } from '../credentials';
 
 type IOperation = {
     with_credential: Option<Credential>,

+ 1 - 1
types/src/versioned-store/permissions/batching/operations.ts

@@ -1,5 +1,5 @@
 import ClassId from "../../ClassId";
-import { JoyStruct } from '../../../JoyStruct';
+import { JoyStruct } from '../../../common';
 import { ParametrizedEntity } from "./parametrized-entity";
 import { Vec, u16 } from "@polkadot/types";
 import ParametrizedClassPropertyValue from "./ParametrizedClassPropertyValue";

+ 0 - 4
types/src/versioned-store/permissions/credentials.ts

@@ -1,4 +0,0 @@
-import { u64, Vec } from '@polkadot/types';
-
-export class Credential extends u64 {}
-export class CredentialSet extends Vec.with(Credential) {} // BtreeSet ?

+ 0 - 3
types/src/versioned-store/permissions/index.ts

@@ -1,6 +1,5 @@
 import { getTypeRegistry } from '@polkadot/types';
 
-import { Credential, CredentialSet } from './credentials';
 import EntityPermissions from './EntityPermissions';
 import { ReferenceConstraint} from './reference-constraint';
 import ClassPermissionsType from './ClassPermissions';
@@ -9,8 +8,6 @@ import { Operation } from './batching/';
 export function registerVersionedStorePermissionsTypes () {
     try {
       getTypeRegistry().register({
-        Credential,
-        CredentialSet,
         EntityPermissions,
         ReferenceConstraint,
         ClassPermissionsType,