Skip to content

Commit f484778

Browse files
susamongusacedemybidoubiwa
authored andcommitted
Add updatedAt and createdAt to Index
1 parent 3ea7201 commit f484778

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/indexes.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,29 @@ import { TaskClient } from './task'
4343
class Index<T = Record<string, any>> {
4444
uid: string
4545
primaryKey: string | undefined
46+
updatedAt: Date | undefined
47+
createdAt: Date | undefined
4648
httpRequest: HttpRequests
4749
tasks: TaskClient
4850

4951
/**
5052
* @param {Config} config Request configuration options
5153
* @param {string} uid UID of the index
52-
* @param {string} primaryKey? Primary Key of the index
54+
* @param {string} [primaryKey] Primary Key of the index
55+
* @param {Date} [createdAt] Creation date of the index
56+
* @param {Date} [updatedAt] Last update date of the index
5357
*/
54-
constructor(config: Config, uid: string, primaryKey?: string) {
58+
constructor(
59+
config: Config,
60+
uid: string,
61+
primaryKey?: string,
62+
updatedAt?: Date,
63+
createdAt?: Date
64+
) {
5565
this.uid = uid
5666
this.primaryKey = primaryKey
67+
this.updatedAt = updatedAt
68+
this.createdAt = createdAt
5769
this.httpRequest = new HttpRequests(config)
5870
this.tasks = new TaskClient(config)
5971
}
@@ -145,6 +157,8 @@ class Index<T = Record<string, any>> {
145157
const url = `indexes/${this.uid}`
146158
const res = await this.httpRequest.get<IndexResponse>(url)
147159
this.primaryKey = res.primaryKey
160+
this.updatedAt = res.updatedAt
161+
this.createdAt = res.createdAt
148162
return res
149163
}
150164

tests/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const indexNoPk = {
1313
const indexPk = {
1414
uid: 'movies_test2',
1515
primaryKey: 'id',
16+
createdAt: new Date(Date.now()).toISOString(),
17+
updatedAt: new Date(Date.now()).toISOString(),
1618
}
1719

1820
afterAll(async () => {
@@ -326,6 +328,28 @@ describe.each([{ permission: 'Master' }, { permission: 'Private' }])(
326328
expect(response).toHaveProperty('isIndexing', false)
327329
expect(response).toHaveProperty('fieldDistribution', {})
328330
})
331+
332+
test(`${permission} key: Get updatedAt and createdAt of created index`, async () => {
333+
const client = await getClient(permission)
334+
const { uid } = await client.createIndex(indexNoPk.uid)
335+
await client.waitForTask(uid)
336+
337+
const response = await client.index(indexPk.uid).getRawInfo()
338+
339+
expect(response).toBeInstanceOf(Date)
340+
expect(response).toBeInstanceOf(Date)
341+
})
342+
343+
test(`${permission} key: Get updatedAt and createdAt from initialized index`, async () => {
344+
const client = await getClient(permission)
345+
const { uid } = await client.createIndex(indexNoPk.uid)
346+
await client.waitForTask(uid)
347+
348+
const response = await client.index(indexPk.uid).getRawInfo()
349+
350+
expect(response).toBeUndefined()
351+
expect(response).toBeUndefined()
352+
})
329353
}
330354
)
331355

0 commit comments

Comments
 (0)