Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This is a definition of domain model for `comments` context.
import * as ts from 'io-ts'
// Runtime type, that can be used for schema validation:
export const RawComment = ts.type({
'id': ts.number,
'body': ts.string,
'email': ts.string,
})
// Static TypeScript type, that can be used as a regular `type`:
export type RawCommentType = ts.TypeOf
// We add rating only on the client (for demo purposes)
export type CommentType = RawCommentType & {
rating: number
}
export interface CommentPayloadType {
commentId: number
delta: number
return new t.Type(
name,
(u: unknown): u is TypeT | undefined => u === undefined || codec.is(u),
(u, c) => (u === undefined ? t.success(u) : codec.validate(u, c)),
a => (a === undefined ? undefined : codec.encode(a))
);
}
// IMPORTANT: This t.types MUST be kept in sync with the actual types.
const BuidlerNetworkAccount = t.type({
privateKey: t.string,
balance: t.string
});
const BuidlerNetworkConfig = t.type({
hardfork: optional(t.string),
chainId: optional(t.number),
from: optional(t.string),
gas: optional(t.union([t.literal("auto"), t.number])),
gasPrice: optional(t.union([t.literal("auto"), t.number])),
gasMultiplier: optional(t.number),
accounts: optional(t.array(BuidlerNetworkAccount)),
blockGasLimit: optional(t.number),
throwOnTransactionFailures: optional(t.boolean),
throwOnCallFailures: optional(t.boolean)
});
const HDAccountsConfig = t.type({
mnemonic: t.string,
initialIndex: optional(t.number),
count: optional(t.number),
...BaseQueryParameterObjectProps,
type: t.literal('number'),
});
export type TIntegerQueryParameterObject = TBaseQueryParameterObjectProps & {
type: 'integer';
};
const IntegerQueryParameterObject: t.Tagged<'type', TIntegerQueryParameterObject, mixed> = t.type({
...BaseQueryParameterObjectProps,
type: t.literal('integer'),
});
export type TBooleanQueryParameterObject = TBaseQueryParameterObjectProps & {
type: 'boolean';
};
const BooleanQueryParameterObject: t.Tagged<'type', TBooleanQueryParameterObject, mixed> = t.type({
...BaseQueryParameterObjectProps,
type: t.literal('boolean'),
});
export type TArrayQueryParameterObject = TBaseQueryParameterObjectProps & {
type: 'array';
items: TNonArrayItemsObject;
};
const ArrayQueryParameterObject: t.Tagged<'type', TArrayQueryParameterObject, mixed> = t.type({
...BaseQueryParameterObjectProps,
type: t.literal('array'),
items: NonArrayItemsObject,
});
export type TQueryParameterObject =
| TStringQueryParameterObject
export const SnapshotModelCumulativeSumRT = rt.type({
cumulative_sum: rt.type({
buckets_path: rt.string,
}),
});
export const SnapshotModelDerivativeRT = rt.type({
derivative: rt.type({
buckets_path: rt.string,
gap_policy: rt.keyof({ skip: null, insert_zeros: null }),
unit: rt.string,
}),
});
export const SnapshotModelSumBucketRT = rt.type({
sum_bucket: rt.type({
buckets_path: rt.string,
}),
});
interface SnapshotTermsWithAggregation {
terms: { field: string };
aggregations: SnapshotModel;
}
export const SnapshotTermsWithAggregationRT: rt.Type = rt.recursion(
'SnapshotModelRT',
() =>
rt.type({
terms: rt.type({ field: rt.string }),
aggregations: SnapshotModelRT,
})
import * as t from "io-ts";
import Knex from "knex";
import { Address, Bytes32, SortLimitParams } from "../../types";
import { queryModifier } from "./database";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
export const AccountTransferHistoryParamsSpecific = t.type({
account: t.string,
token: t.union([t.string, t.null, t.undefined]),
isInternalTransfer: t.union([t.boolean, t.null, t.undefined]),
earliestCreationTime: t.union([t.number, t.null, t.undefined]),
latestCreationTime: t.union([t.number, t.null, t.undefined]),
});
export const AccountTransferHistoryParams = t.intersection([
AccountTransferHistoryParamsSpecific,
SortLimitParams,
]);
export interface TransferRow {
transactionHash: Bytes32;
logIndex: number;
blockNumber: number;
export const ItemsObject: t.Type = t.recursion('ItemsObject', ItemsObject => {
const ArrayItemsObject = t.type({
...BaseItemsObjectProps,
type: t.literal('array'),
items: createOptionFromNullable(t.array(ItemsObject)),
});
return t.taggedUnion('type', [
ArrayItemsObject,
StringItemsObject,
NumberItemsObject,
IntegerItemsObject,
BooleanItemsObject,
]) as any;
});
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as rt from 'io-ts';
export const timeRangeRT = rt.type({
startTime: rt.number,
endTime: rt.number,
});
export type TimeRange = rt.TypeOf;
start: bucket.from || 0,
end: bucket.to || 0,
topEntryKeys: bucket.top_hits_by_key.hits.hits.map(hit => ({
tiebreaker: hit.sort[1],
time: hit.sort[0],
})),
});
const createQueryFilterClauses = (filterQuery: LogEntryQuery | undefined) =>
filterQuery ? [filterQuery] : [];
const LogSummaryDateRangeBucketRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
doc_count: runtimeTypes.number,
key: runtimeTypes.string,
top_hits_by_key: runtimeTypes.type({
hits: runtimeTypes.type({
hits: runtimeTypes.array(
runtimeTypes.type({
sort: runtimeTypes.tuple([runtimeTypes.number, runtimeTypes.number]),
})
),
}),
}),
}),
runtimeTypes.partial({
from: runtimeTypes.number,
to: runtimeTypes.number,
}),
]);
export interface LogSummaryDateRangeBucket
match_usernames: t.boolean,
match_nicknames: t.boolean,
match_custom_status: t.boolean,
});
type TMatchLinksTrigger = t.TypeOf;
const defaultMatchLinksTrigger: Partial = {
include_subdomains: true,
match_messages: true,
match_embeds: true,
match_visible_names: false,
match_usernames: false,
match_nicknames: false,
match_custom_status: false,
};
const BaseSpamTrigger = t.type({
amount: t.number,
within: t.string,
});
const BaseTextSpamTrigger = t.intersection([
BaseSpamTrigger,
t.type({
per_channel: t.boolean,
}),
]);
type TBaseTextSpamTrigger = t.TypeOf;
const defaultTextSpamTrigger: Partial> = {
per_channel: true,
};
const MessageSpamTrigger = BaseTextSpamTrigger;
type TMessageSpamTrigger = t.TypeOf;
export const ImportSeedErrors = t.union(Object.values(importSeedErrors))
export type ImportSeedErrors = t.TypeOf
export const ImportSeedError = t.type({
kind: t.literal("ERROR"),
error: ImportSeedErrors,
})
export type ImportSeedError = t.TypeOf
export const ImportSeedResponse = t.taggedUnion("kind", [
ImportSeedSuccess,
ImportSeedError,
], "ImportSeedResponse")
export type ImportSeedResponse = t.TypeOf
export const GetWalletParams = t.type({
id: t.string,
password: t.string,
})
export type GetWalletParams = t.TypeOf
export const GetWalletSuccess = t.type({
kind: t.literal("SUCCESS"),
wallet: Wallet,
})
export type GetWalletSuccess = t.TypeOf
export const getWalletErrors = {
INVALID_PARAMS_TYPE: t.literal("INVALID_PARAMS_TYPE"),
INVALID_WALLET_TYPE: t.literal("INVALID_WALLET_TYPE"),
CANNOT_ENCODE_WALLET: t.literal("CANNOT_ENCODE_WALLET"),
WRONG_PASSWORD: t.literal("WRONG_PASSWORD"),