Skip to content

Commit

Permalink
refactor: add missing returned type in getSchema function
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed May 2, 2024
1 parent 0175c4f commit 902b2be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName';
import { ERC725Config, ERC725Options } from './types/Config';
import { Permissions } from './types/Method';
import {
DynamicNameSchema,
ERC725JSONSchema,
ERC725JSONSchemaKeyType,
ERC725JSONSchemaValueContent,
Expand Down Expand Up @@ -359,15 +360,19 @@ export class ERC725 {
getSchema(
keyOrKeys: string[],
providedSchemas?: ERC725JSONSchema[],
): Record<string, ERC725JSONSchema | null>;
): Record<string, ERC725JSONSchema | DynamicNameSchema | null>;
getSchema(
keyOrKeys: string,
providedSchemas?: ERC725JSONSchema[],
): ERC725JSONSchema | null;
): ERC725JSONSchema | DynamicNameSchema | null;
getSchema(
keyOrKeys: string | string[],
providedSchemas?: ERC725JSONSchema[],
): ERC725JSONSchema | null | Record<string, ERC725JSONSchema | null> {
):
| ERC725JSONSchema
| DynamicNameSchema
| null
| Record<string, ERC725JSONSchema | DynamicNameSchema | null> {
return getSchema(
keyOrKeys,
this.options.schemas.concat(providedSchemas || []),
Expand Down
21 changes: 12 additions & 9 deletions src/lib/schemaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const findMappingWithGroupingSchemaForKey = (
function schemaParser(
key: string,
schemas: ERC725JSONSchema[],
): ERC725JSONSchema | null {
): ERC725JSONSchema | DynamicNameSchema | null {
const schemasByKeyType = getSchemasByKeyType(schemas);

let foundSchema: ERC725JSONSchema | null = null;
Expand Down Expand Up @@ -205,20 +205,23 @@ function schemaParser(
export function getSchema(
keyOrKeys: string | string[],
providedSchemas?: ERC725JSONSchema[],
): ERC725JSONSchema | null | Record<string, ERC725JSONSchema | null> {
):
| ERC725JSONSchema
| DynamicNameSchema
| null
| Record<string, ERC725JSONSchema | DynamicNameSchema | null> {
let fullSchema: ERC725JSONSchema[] = allSchemas;
if (providedSchemas) {
fullSchema = fullSchema.concat(providedSchemas);
}

if (Array.isArray(keyOrKeys)) {
return keyOrKeys.reduce<Record<string, ERC725JSONSchema | null>>(
(acc, key) => {
acc[key] = schemaParser(key, fullSchema);
return acc;
},
{},
);
return keyOrKeys.reduce<
Record<string, ERC725JSONSchema | DynamicNameSchema | null>
>((acc, key) => {
acc[key] = schemaParser(key, fullSchema);
return acc;
}, {});
}

return schemaParser(keyOrKeys, fullSchema);
Expand Down

0 comments on commit 902b2be

Please sign in to comment.