-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from poap-xyz/field-expand
Field expand
- Loading branch information
Showing
16 changed files
with
133 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; | ||
export const DEAD_ADDRESS = '0x000000000000000000000000000000000000dead'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './address'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Deep recursive field with `V` final value. | ||
*/ | ||
type Field<V> = { [key: string]: Field<V> | V }; | ||
|
||
/** | ||
* Creates a deep recursive object with dot separated keys and a final value. | ||
* For example, `createField<number>('a.b.c', 42)` will return `{ a: { b: { c: 42 } } }`. | ||
*/ | ||
export function createField<V>(keys: string, value: V): Field<V> { | ||
return keys.split('.').reduceRight( | ||
(prev: Field<V> | V, key: string): Field<V> => ({ | ||
[key]: prev, | ||
}), | ||
value, | ||
) as Field<V>; // casted becuse keys is assumed to not be empty | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { createField } from './field'; | ||
import { Order, FieldOrderBy } from '../types/order'; | ||
|
||
export function createOrderBy<E extends string = string>( | ||
key: E | undefined, | ||
value?: Order | undefined, | ||
value?: Order, | ||
): FieldOrderBy { | ||
return key && value ? { [key]: value } : {}; | ||
return key && value ? createField<Order>(key, value) : {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createField } from '../../src/queries/field'; | ||
|
||
describe('field', () => { | ||
describe('createField', () => { | ||
it('returns a field with given value', () => { | ||
expect(createField('field_name', 42)).toEqual({ field_name: 42 }); | ||
}); | ||
|
||
it('returns a field with another field inside when keys are given separated by dots', () => { | ||
expect(createField('field_name.sub_field', 42)).toEqual({ | ||
field_name: { sub_field: 42 }, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.