Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move schema ids to constants #550

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/domain/backbone/backbone.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { GenericValidator } from '../../validation/providers/generic.validator';
import { JsonSchemaService } from '../../validation/providers/json-schema.service';
import { IValidator } from '../interfaces/validator.interface';
import { Backbone } from './entities/backbone.entity';
import { backboneSchema } from './entities/schemas/backbone.schema';
import {
BACKBONE_SCHEMA_ID,
backboneSchema,
} from './entities/schemas/backbone.schema';

@Injectable()
export class BackboneValidator implements IValidator<Backbone> {
Expand All @@ -15,7 +18,7 @@ export class BackboneValidator implements IValidator<Backbone> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.isValidBackbone = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/backbone/backbone.json',
BACKBONE_SCHEMA_ID,
backboneSchema,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/domain/backbone/entities/schemas/backbone.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { JSONSchemaType } from 'ajv';
import { Backbone } from '../backbone.entity';

export const BACKBONE_SCHEMA_ID =
'https://safe-client.safe.global/schemas/backbone/backbone.json';

export const backboneSchema: JSONSchemaType<Backbone> = {
$id: 'https://safe-client.safe.global/schemas/backbone/backbone.json',
$id: BACKBONE_SCHEMA_ID,
type: 'object',
properties: {
name: { type: 'string' },
Expand Down
6 changes: 4 additions & 2 deletions src/domain/balances/balances.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { JsonSchemaService } from '../../validation/providers/json-schema.servic
import { IValidator } from '../interfaces/validator.interface';
import { Balance } from './entities/balance.entity';
import {
BALANCE_SCHEMA_ID,
BALANCE_TOKEN_SCHEMA_ID,
balanceSchema,
balanceTokenSchema,
} from './entities/schemas/balance.schema';
Expand All @@ -18,12 +20,12 @@ export class BalancesValidator implements IValidator<Balance> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/balances/balance-token.json',
BALANCE_TOKEN_SCHEMA_ID,
balanceTokenSchema,
);

this.isValidBalance = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/balances/balance.json',
BALANCE_SCHEMA_ID,
balanceSchema,
);
}
Expand Down
10 changes: 8 additions & 2 deletions src/domain/balances/entities/schemas/balance.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { JSONSchemaType, Schema } from 'ajv';
import { BalanceToken } from '../balance.token.entity';

export const BALANCE_TOKEN_SCHEMA_ID =
'https://safe-client.safe.global/schemas/balances/balance-token.json';

const balanceTokenSchema: JSONSchemaType<BalanceToken> = {
$id: 'https://safe-client.safe.global/schemas/balances/balance-token.json',
$id: BALANCE_TOKEN_SCHEMA_ID,
type: 'object',
properties: {
name: { type: 'string' },
Expand All @@ -13,8 +16,11 @@ const balanceTokenSchema: JSONSchemaType<BalanceToken> = {
required: ['name', 'symbol', 'decimals', 'logoUri'],
};

export const BALANCE_SCHEMA_ID =
'https://safe-client.safe.global/schemas/balances/balance.json';

const balanceSchema: Schema = {
$id: 'https://safe-client.safe.global/schemas/balances/balance.json',
$id: BALANCE_SCHEMA_ID,
type: 'object',
properties: {
tokenAddress: { type: 'string', nullable: true, default: null },
Expand Down
27 changes: 12 additions & 15 deletions src/domain/chains/chains.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { JsonSchemaService } from '../../validation/providers/json-schema.servic
import { IValidator } from '../interfaces/validator.interface';
import { Chain } from './entities/chain.entity';
import {
BLOCK_EXPLORER_URI_TEMPLATE_SCHEMA_ID,
CHAIN_SCHEMA_ID,
GAS_PRICE_SCHEMA_ID,
NATIVE_CURRENCY_SCHEMA_ID,
RPC_URI_SCHEMA_ID,
THEME_SCHEMA_ID,
blockExplorerUriTemplateSchema,
chainSchema,
gasPriceSchema,
Expand All @@ -22,32 +28,23 @@ export class ChainsValidator implements IValidator<Chain> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/native-currency.json',
NATIVE_CURRENCY_SCHEMA_ID,
nativeCurrencySchema,
);

this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/rpc-uri.json',
rpcUriSchema,
);
this.jsonSchemaService.getSchema(RPC_URI_SCHEMA_ID, rpcUriSchema);

this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/block-explorer-uri-template.json',
BLOCK_EXPLORER_URI_TEMPLATE_SCHEMA_ID,
blockExplorerUriTemplateSchema,
);

this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/theme.json',
themeSchema,
);
this.jsonSchemaService.getSchema(THEME_SCHEMA_ID, themeSchema);

this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/gas-price.json',
gasPriceSchema,
);
this.jsonSchemaService.getSchema(GAS_PRICE_SCHEMA_ID, gasPriceSchema);

this.isValidChain = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/chain.json',
CHAIN_SCHEMA_ID,
chainSchema,
);
}
Expand Down
30 changes: 24 additions & 6 deletions src/domain/chains/entities/schemas/chain.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { Theme } from '../theme.entity';
import { GasPriceOracle } from '../gas-price-oracle.entity';
import { GasPriceFixed } from '../gas-price-fixed.entity';

export const NATIVE_CURRENCY_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/native-currency.json';

export const nativeCurrencySchema: JSONSchemaType<NativeCurrency> = {
$id: 'https://safe-client.safe.global/schemas/chains/native-currency.json',
$id: NATIVE_CURRENCY_SCHEMA_ID,
type: 'object',
properties: {
name: { type: 'string' },
Expand All @@ -20,8 +23,11 @@ export const nativeCurrencySchema: JSONSchemaType<NativeCurrency> = {
required: ['name', 'symbol', 'decimals', 'logoUri'],
};

export const RPC_URI_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/rpc-uri.json';

export const rpcUriSchema: JSONSchemaType<RpcUri> = {
$id: 'https://safe-client.safe.global/schemas/chains/rpc-uri.json',
$id: RPC_URI_SCHEMA_ID,
type: 'object',
properties: {
authentication: {
Expand All @@ -34,9 +40,12 @@ export const rpcUriSchema: JSONSchemaType<RpcUri> = {
required: ['authentication', 'value'],
};

export const BLOCK_EXPLORER_URI_TEMPLATE_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/block-explorer-uri-template.json';

export const blockExplorerUriTemplateSchema: JSONSchemaType<BlockExplorerUriTemplate> =
{
$id: 'https://safe-client.safe.global/schemas/chains/block-explorer-uri-template.json',
$id: BLOCK_EXPLORER_URI_TEMPLATE_SCHEMA_ID,
type: 'object',
properties: {
address: { type: 'string' },
Expand All @@ -46,8 +55,11 @@ export const blockExplorerUriTemplateSchema: JSONSchemaType<BlockExplorerUriTemp
required: ['address', 'txHash', 'api'],
};

export const THEME_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/theme.json';

export const themeSchema: JSONSchemaType<Theme> = {
$id: 'https://safe-client.safe.global/schemas/chains/theme.json',
$id: THEME_SCHEMA_ID,
type: 'object',
properties: {
textColor: { type: 'string' },
Expand All @@ -56,10 +68,13 @@ export const themeSchema: JSONSchemaType<Theme> = {
required: ['textColor', 'backgroundColor'],
};

export const GAS_PRICE_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/gas-price.json';

export const gasPriceSchema: JSONSchemaType<
Array<GasPriceOracle | GasPriceFixed>
> = {
$id: 'https://safe-client.safe.global/schemas/chains/gas-price.json',
$id: GAS_PRICE_SCHEMA_ID,
type: 'array',
items: {
anyOf: [
Expand All @@ -85,9 +100,12 @@ export const gasPriceSchema: JSONSchemaType<
},
};

export const CHAIN_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/chain.json';

export const chainSchema: JSONSchemaType<Chain> = {
type: 'object',
$id: 'https://safe-client.safe.global/schemas/chains/chain.json',
$id: CHAIN_SCHEMA_ID,
properties: {
chainId: { type: 'string' },
chainName: { type: 'string' },
Expand Down
5 changes: 4 additions & 1 deletion src/domain/chains/entities/schemas/master-copy.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { JSONSchemaType } from 'ajv';
import { MasterCopy } from '../master-copies.entity';

export const MASTER_COPY_SCHEMA_ID =
'https://safe-client.safe.global/schemas/chains/master-copy.json';

export const masterCopySchema: JSONSchemaType<MasterCopy> = {
$id: 'https://safe-client.safe.global/schemas/chains/master-copy.json',
$id: MASTER_COPY_SCHEMA_ID,
type: 'object',
properties: {
address: { type: 'string' },
Expand Down
7 changes: 5 additions & 2 deletions src/domain/chains/master-copy.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { GenericValidator } from '../../validation/providers/generic.validator';
import { JsonSchemaService } from '../../validation/providers/json-schema.service';
import { IValidator } from '../interfaces/validator.interface';
import { MasterCopy } from './entities/master-copies.entity';
import { masterCopySchema } from './entities/schemas/master-copy.schema';
import {
MASTER_COPY_SCHEMA_ID,
masterCopySchema,
} from './entities/schemas/master-copy.schema';

@Injectable()
export class MasterCopyValidator implements IValidator<MasterCopy> {
Expand All @@ -15,7 +18,7 @@ export class MasterCopyValidator implements IValidator<MasterCopy> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.isValidMasterCopy = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/chains/master-copy.json',
MASTER_COPY_SCHEMA_ID,
masterCopySchema,
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/domain/collectibles/collectibles.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { GenericValidator } from '../../validation/providers/generic.validator';
import { JsonSchemaService } from '../../validation/providers/json-schema.service';
import { IValidator } from '../interfaces/validator.interface';
import { Collectible } from './entities/collectible.entity';
import { collectibleSchema } from './entities/schemas/collectible.schema';
import {
COLLECTIBLE_SCHEMA_ID,
collectibleSchema,
} from './entities/schemas/collectible.schema';

@Injectable()
export class CollectiblesValidator implements IValidator<Collectible> {
Expand All @@ -15,7 +18,7 @@ export class CollectiblesValidator implements IValidator<Collectible> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.isValidCollectible = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/collectibles/collectible.json',
COLLECTIBLE_SCHEMA_ID,
collectibleSchema,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { JSONSchemaType } from 'ajv';
import { Collectible } from '../collectible.entity';

export const COLLECTIBLE_SCHEMA_ID =
'https://safe-client.safe.global/schemas/collectibles/collectible.json';

export const collectibleSchema: JSONSchemaType<Collectible> = {
$id: 'https://safe-client.safe.global/schemas/collectibles/collectible.json',
$id: COLLECTIBLE_SCHEMA_ID,
type: 'object',
properties: {
address: { type: 'string' },
Expand Down
7 changes: 5 additions & 2 deletions src/domain/contracts/contracts.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { GenericValidator } from '../../validation/providers/generic.validator';
import { JsonSchemaService } from '../../validation/providers/json-schema.service';
import { IValidator } from '../interfaces/validator.interface';
import { Contract } from './entities/contract.entity';
import { contractSchema } from './entities/schemas/contract.schema';
import {
CONTRACT_SCHEMA_ID,
contractSchema,
} from './entities/schemas/contract.schema';

@Injectable()
export class ContractsValidator implements IValidator<Contract> {
Expand All @@ -15,7 +18,7 @@ export class ContractsValidator implements IValidator<Contract> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.isValidContract = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/contracts/contract.json',
CONTRACT_SCHEMA_ID,
contractSchema,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/domain/contracts/entities/schemas/contract.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Schema } from 'ajv';

export const CONTRACT_SCHEMA_ID =
'https://safe-client.safe.global/schemas/contracts/contract.json';

export const contractSchema: Schema = {
$id: 'https://safe-client.safe.global/schemas/contracts/contract.json',
$id: CONTRACT_SCHEMA_ID,
type: 'object',
properties: {
address: { type: 'string' },
Expand Down
6 changes: 4 additions & 2 deletions src/domain/data-decoder/data-decoded.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { JsonSchemaService } from '../../validation/providers/json-schema.servic
import { IValidator } from '../interfaces/validator.interface';
import { DataDecoded } from './entities/data-decoded.entity';
import {
DATA_DECODED_PARAMETER_SCHEMA_ID,
DATA_DECODED_SCHEMA_ID,
dataDecodedParameterSchema,
dataDecodedSchema,
} from './entities/schemas/data-decoded.schema';
Expand All @@ -18,11 +20,11 @@ export class DataDecodedValidator implements IValidator<DataDecoded> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/data-decoded/data-decoded-parameter.json',
DATA_DECODED_PARAMETER_SCHEMA_ID,
dataDecodedParameterSchema,
);
this.isValidDataDecoded = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/data-decoded/data-decoded.json',
DATA_DECODED_SCHEMA_ID,
dataDecodedSchema,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Schema } from 'ajv';

export const DATA_DECODED_PARAMETER_SCHEMA_ID =
'https://safe-client.safe.global/schemas/data-decoded/data-decoded-parameter.json';

export const dataDecodedParameterSchema: Schema = {
$id: 'https://safe-client.safe.global/schemas/data-decoded/data-decoded-parameter.json',
$id: DATA_DECODED_PARAMETER_SCHEMA_ID,
type: 'object',
properties: {
name: { type: 'string' },
Expand All @@ -13,8 +16,11 @@ export const dataDecodedParameterSchema: Schema = {
required: ['name', 'type', 'value'],
};

export const DATA_DECODED_SCHEMA_ID =
'https://safe-client.safe.global/schemas/data-decoded/data-decoded.json';

export const dataDecodedSchema: Schema = {
$id: 'https://safe-client.safe.global/schemas/data-decoded/data-decoded.json',
$id: DATA_DECODED_SCHEMA_ID,
type: 'object',
properties: {
method: { type: 'string' },
Expand Down
7 changes: 5 additions & 2 deletions src/domain/delegate/delegate.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { JsonSchemaService } from '../../validation/providers/json-schema.servic
import { ValidationErrorFactory } from '../../validation/providers/validation-error-factory';
import { IValidator } from '../interfaces/validator.interface';
import { Delegate } from './entities/delegate.entity';
import { delegateSchema } from './entities/schemas/delegate.schema';
import {
DELEGATE_SCHEMA_ID,
delegateSchema,
} from './entities/schemas/delegate.schema';

@Injectable()
export class DelegateValidator implements IValidator<Delegate> {
Expand All @@ -15,7 +18,7 @@ export class DelegateValidator implements IValidator<Delegate> {
private readonly jsonSchemaService: JsonSchemaService,
) {
this.isValidDelegate = this.jsonSchemaService.getSchema(
'https://safe-client.safe.global/schemas/delegates/delegate.json',
DELEGATE_SCHEMA_ID,
delegateSchema,
);
}
Expand Down
Loading