Skip to content

Commit d044006

Browse files
dominiciampogo
authored andcommitted
all: add method parameter to Index creation
Indexes are now created with a `type` and `method` parameter. However, each only has one option today: `token` for type, and `sum` for method. The method signatures for creating an index with the SDKs now look like: ``` # Ruby/Node chain.indexes.create( type: 'token', method: 'sum', filter: 'account_id = $1' ) # Java Index.TokenSum.Builder() .setFilter("tags.type=$1") .create(client); ``` In the interest of being very explicit about just what is being indexed `type` and `method` are essentially non-options right now, but give users an innate understanding of what's being created while being a flexible design that can (likely) be extended in the future. Closes #4390 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Fri Jul 27 14:20:02 2018 -0700 upstream:c4c4ca5af5db14ddbff2e1823955dc46136453e8
1 parent c8f8178 commit d044006

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

src/api/indexes.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import { Query } from '../query'
1313
* Unique identifier of the index.
1414
*
1515
* @property {String} type
16-
* Type of index, "action" or "token".
16+
* Type of index, currently must be "token".
17+
*
18+
* @property {String} method
19+
* Method for index, currently must be "sum".
1720
*
1821
* @property {String[]} groupBy
19-
* Token/Action object fields to group by.
22+
* Token object fields to group by.
2023
*
2124
* @property {String} filter
2225
* The query filter used to select matching items.
@@ -35,7 +38,8 @@ export const indexesAPI = (client: Client) => {
3538
* Create a new index.
3639
*
3740
* @param {Object} params - Parameters for index creation.
38-
* @param {String} params.type - Type of index, "action" or "token".
41+
* @param {String} params.type - Type of index, currently only "token".
42+
* @param {String} params.method - Method for index, currently only "sum".
3943
* @param {String} params.filter - filter string, see {@link https://dashboard.seq.com/docs/filters}.
4044
* @param {Array<String>} params.groupBy - object fields to group by.
4145
* @param {String} params.id - Unique identifier. Will be auto-generated if
@@ -44,6 +48,7 @@ export const indexesAPI = (client: Client) => {
4448
*/
4549
create: (params: {
4650
type: string
51+
method: string
4752
id?: string
4853
filter: string
4954
groupBy?: string[]

src/validate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ajv.addSchema(
2828
properties: {
2929
id: { type: 'string' },
3030
type: { type: 'string' },
31+
method: { type: 'string' },
3132
filter: { type: 'string' },
3233
groupBy: { type: 'array', items: { type: 'string' } },
3334
},

test/indexes.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,46 @@ import { testHelpers } from './testHelpers'
1414
const { client, createAccount, createFlavor } = testHelpers
1515

1616
describe('Index', () => {
17-
it('creates an action index', async () => {
17+
it('rejects bad types', () => {
18+
return expect(client.indexes.create({
19+
type: 'not-a-type',
20+
method: 'sum',
21+
filter: `tags.type=$1`,
22+
}) as any).to.be.rejectedWith(
23+
'SEQ611'
24+
)
25+
})
26+
27+
it('rejects bad methods', () => {
28+
return expect(client.indexes.create({
29+
type: 'token',
30+
method: 'not-a-method',
31+
filter: `tags.type=$1`,
32+
}) as any).to.be.rejectedWith(
33+
'SEQ611'
34+
)
35+
})
36+
37+
it('creates an index', async () => {
1838
const uuidCreated = uuid.v4()
1939

2040
const index = await client.indexes.create({
21-
type: 'action',
22-
id: `actionIndex-${uuidCreated}`,
41+
type: 'token',
42+
method: 'sum',
43+
id: `tokenIndex-${uuidCreated}`,
2344
filter: `tags.type-${uuidCreated}=$1`,
45+
groupBy: ["flavorId"],
2446
})
25-
expect(index.type).to.equal('action')
47+
expect(index.type).to.equal('token')
2648
})
2749

28-
it('creates a token index', async () => {
50+
it('creates an index without id', async () => {
2951
const uuidCreated = uuid.v4()
3052

3153
const index = await client.indexes.create({
3254
type: 'token',
33-
id: `tokenIndex-${uuidCreated}`,
55+
method: 'sum',
3456
filter: `tags.type-${uuidCreated}=$1`,
35-
groupBy: ["flavorId"],
3657
})
3758
expect(index.type).to.equal('token')
3859
})
@@ -41,7 +62,8 @@ describe('Index', () => {
4162
const uuidDeleted = uuid.v4()
4263

4364
const index = await client.indexes.create({
44-
type: 'action',
65+
type: 'token',
66+
method: 'sum',
4567
id: `index-${uuidDeleted}`,
4668
filter: `tags.type-${uuidDeleted}=$1`,
4769
})
@@ -55,21 +77,23 @@ describe('Index', () => {
5577
it('lists indexes', async () => {
5678
const uuidListed = uuid.v4()
5779

58-
const actionIndex = await client.indexes.create({
59-
type: 'action',
60-
id: `actionIndex-${uuidListed}`,
80+
const tokenIndex1 = await client.indexes.create({
81+
type: 'token',
82+
method: 'sum',
6183
filter: `tags.type-${uuidListed}=$1`,
84+
groupBy: ["flavorId"],
6285
})
6386

64-
const tokenIndex = await client.indexes.create({
87+
const tokenIndex2 = await client.indexes.create({
6588
type: 'token',
66-
id: `tokenIndex-${uuidListed}`,
89+
method: 'sum',
6790
filter: `tags.type-${uuidListed}=$1`,
68-
groupBy: ["flavorId"],
91+
groupBy: ["flavorId", "accountId"],
6992
})
7093

94+
7195
const items = await testHelpers.asyncAll(client.indexes.list().all())
7296
const ids = items.map(item => item.id)
73-
expect(ids).to.include(actionIndex.id, tokenIndex.id)
97+
expect(ids).to.include(tokenIndex1.id, tokenIndex2.id)
7498
})
7599
})

0 commit comments

Comments
 (0)