-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
611 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { annotations } from '@axiomhq/js'; | ||
|
||
|
||
async function main() { | ||
const client = new annotations.Service({ token: 'token' }); | ||
await client.create({ | ||
type: 'deployment', | ||
datasets: ['dataset_name'], | ||
title: 'New deployment', | ||
description: 'Deployed version 1.0.0 with fixes for ...', | ||
}) | ||
} | ||
|
||
main(); |
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,23 @@ | ||
// This example shows querying a dataset with summarized results. | ||
import { Axiom } from '@axiomhq/js'; | ||
|
||
const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || '', orgId: process.env.AXIOM_ORG_ID || '' }); | ||
|
||
async function query() { | ||
const aplQuery = ` | ||
['my-dataset'] | ||
| where foo == "bar" | ||
and _time > datetime('2024-05-02') | ||
and _time < datetime('2024-05-27') | ||
| summarize cost = sum(value) by group_field | ||
`; | ||
|
||
try { | ||
const res = await axiom.query(aplQuery); | ||
console.log(JSON.stringify(res, null, 2)); | ||
} catch (error) { | ||
console.error('ERROR:', error); | ||
} | ||
} | ||
|
||
query(); |
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 |
---|---|---|
|
@@ -11,6 +11,6 @@ | |
}, | ||
"dependencies": { | ||
"@axiomhq/pino": "workspace:*", | ||
"pino": "^8.14.1" | ||
"pino": "^9.1.0" | ||
} | ||
} |
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,71 @@ | ||
import { describe, expect, it, beforeAll, afterAll } from 'vitest'; | ||
import { datasets, annotations } from '@axiomhq/js'; | ||
|
||
const datasetSuffix = process.env.AXIOM_DATASET_SUFFIX || 'local'; | ||
|
||
describe('AnnotationsService', () => { | ||
const datasetName = `test-axiom-js-datasets-${datasetSuffix}`; | ||
const datasetsClient = new datasets.Service({ token: process.env.AXIOM_TOKEN || '', url: process.env.AXIOM_URL, orgId: process.env.AXIOM_ORG_ID }); | ||
const client = new annotations.Service({ token: process.env.AXIOM_TOKEN || '', url: process.env.AXIOM_URL, orgId: process.env.AXIOM_ORG_ID }); | ||
let id: string = ''; | ||
|
||
beforeAll(async () => { | ||
await datasetsClient.create({ | ||
name: datasetName, | ||
description: 'This is a test dataset to be used for annotations testing', | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
const resp = await datasetsClient.delete(datasetName); | ||
expect(resp.status).toEqual(204); | ||
}); | ||
|
||
describe('create', () => { | ||
it('creates annotations successfully', async () => { | ||
const result = await client.create({ | ||
type: 'test-deployment', | ||
datasets: [datasetName], | ||
title: 'test1', | ||
description: 'This is a test description', | ||
url: 'some-url', | ||
}); | ||
|
||
expect(result).not.toEqual(null); | ||
expect(result.title).toEqual("test1"); | ||
|
||
// set id | ||
id = result.id; | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should update the annotation', async () => { | ||
const dataset = await client.update(id, { | ||
type: 'test-deployment', | ||
datasets: [datasetName], | ||
title: 'test1', | ||
url: 'some-url', | ||
description: 'This is a soon to be filled test dataset', | ||
}); | ||
|
||
expect(dataset.description).toEqual('This is a soon to be filled test dataset'); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should get the annotation', async () => { | ||
const annotation = await client.get(id); | ||
|
||
expect(annotation.title).toEqual("test1"); | ||
}); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should list the annotations', async () => { | ||
const annotations = await client.list(); | ||
|
||
expect(annotations.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
}); |
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,56 @@ | ||
import HTTPClient from './httpClient.js'; | ||
|
||
export namespace annotations { | ||
|
||
export interface Annotation { | ||
id: string; | ||
type: string; | ||
datasets: string[]; | ||
title?: string; | ||
description?: string; | ||
url?: string; | ||
time: string; | ||
endTime?: string; | ||
} | ||
|
||
export interface ListingQueryParams { | ||
datasets?: string[], | ||
start?: string, | ||
end?: string | ||
} | ||
|
||
export interface CreateRequest { | ||
type: string; | ||
datasets: string[]; | ||
title?: string; | ||
description?: string; | ||
url?: string; | ||
time?: string; | ||
endTime?: string; | ||
} | ||
|
||
export interface UpdateRequest { | ||
type?: string; | ||
datasets?: string[]; | ||
title?: string; | ||
description?: string; | ||
url?: string; | ||
time?: string; | ||
endTime?: string; | ||
} | ||
|
||
export class Service extends HTTPClient { | ||
private readonly localPath = '/v2/annotations'; | ||
|
||
list = (req?: ListingQueryParams): Promise<Annotation[]> => this.client.get(this.localPath, {}, req); | ||
|
||
get = (id: string): Promise<Annotation> => this.client.get(this.localPath + '/' + id); | ||
|
||
create = (req: CreateRequest): Promise<Annotation> => this.client.post(this.localPath, { body: JSON.stringify(req) }); | ||
|
||
update = (id: string, req: UpdateRequest): Promise<Annotation> => | ||
this.client.put(this.localPath + '/' + id, { body: JSON.stringify(req) }); | ||
|
||
delete = (id: string): Promise<Response> => this.client.delete(this.localPath + '/' + id); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { AxiomWithoutBatching, Axiom, ContentType, ContentEncoding, IngestOptions, IngestStatus, IngestFailure, QueryOptionsBase, QueryOptions, QueryLegacy, Aggregation, AggregationOp, Filter, FilterOp, Order, Projection, VirtualColumn, QueryLegacyResult, QueryResult, Timeseries, Interval, EntryGroup, EntryGroupAgg, Entry, Status, Message, Query } from './client.js'; | ||
export { ClientOptions } from './httpClient.js'; | ||
export { datasets } from './datasets.js'; | ||
export { annotations } from './annotations.js'; | ||
export { users } from './users.js'; |
Oops, something went wrong.