Skip to content

Commit

Permalink
update pnpm-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi committed Jul 8, 2024
2 parents 0f3128a + 4746e68 commit 39c164c
Show file tree
Hide file tree
Showing 21 changed files with 611 additions and 71 deletions.
14 changes: 14 additions & 0 deletions examples/js/src/create-annotation.ts
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();
4 changes: 2 additions & 2 deletions examples/js/src/ingest-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import { Axiom, ContentType, ContentEncoding } from '@axiomhq/js';
import { ContentType, ContentEncoding, AxiomWithoutBatching } from '@axiomhq/js';

const axiom = new Axiom({ token: process.env.AXIOM_TOKEN || ''});
const axiom = new AxiomWithoutBatching({ token: process.env.AXIOM_TOKEN || ''});

async function ingestFile() {
const buff = fs.readFileSync('logs.json');
Expand Down
23 changes: 23 additions & 0 deletions examples/js/src/summarize-query.ts
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();
2 changes: 1 addition & 1 deletion examples/pino/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
},
"dependencies": {
"@axiomhq/pino": "workspace:*",
"pino": "^8.14.1"
"pino": "^9.1.0"
}
}
71 changes: 71 additions & 0 deletions integration/src/annotations.spec.ts
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);
});
});
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.32.4",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
"jsdom": "^24.0.0",
"prettier": "^2.8.8",
"rollup": "^4.17.2",
"prettier": "^3.3.1",
"rollup": "^4.18.0",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"turbo": "^1.12.5",
Expand Down
22 changes: 22 additions & 0 deletions packages/js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]



## [1.0.0] - 2024-06-12

## Added

- Added support for Annotations API

## [1.0.0-rc.4] - 2024-06-10

### Fixed

- fix: add BigInt support to JSON.stringify [#189] from lucassmuller/fix/json-stringify

## [1.0.0-rc.3] - 2024-03-20

### Fixed

- Fix fetch request init with retry

## [1.0.0-rc.2] - 2024-02-09

## [1.0.0-rc.1] - 2023-09-27

### Breaking Change
Expand Down
28 changes: 25 additions & 3 deletions packages/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install @axiomhq/js

If you use the [Axiom CLI](https://github.com/axiomhq/cli), run `eval $(axiom config export -f)` to configure your environment variables.

Otherwise create a personal token in [the Axiom settings](https://app.axiom.co/profile) and export it as `AXIOM_TOKEN`. Set `AXIOM_ORG_ID` to the organization ID from the settings page of the organization you want to access.
Otherwise create a new token in [the Axiom settings](https://app.axiom.co/api-tokens) and export it as `AXIOM_TOKEN`.

You can also configure the client using options passed to the constructor of the Client:

Expand All @@ -19,7 +19,6 @@ import { Axiom } from '@axiomhq/js';

const axiom = new Axiom({
token: process.env.AXIOM_TOKEN,
orgId: process.env.AXIOM_ORG_ID,
});
```

Expand Down Expand Up @@ -55,4 +54,27 @@ let client = new Axiom({
}
});
```
by default `onError` is set to `console.error`.
by default `onError` is set to `console.error`.


## Annotations

Starting from `v1.0.0` the SDK supports the [Annotations API](https://axiom.co/docs/restapi/endpoints/createAnnotation). You can create annotations like this:

```ts
// import the annotations module
import { annotations } from '@axiomhq/js';
// create a client
const client = new annotations.Service({ token: process.env.AXIOM_TOKEN });
```

Then create an annotation like this:

```ts
await annotations.create({
type: 'deployment',
datasets: ['dataset_name'],
title: 'New deployment',
description: 'Deployed version 1.0.0 with fixes for ...',
})
```
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@axiomhq/js",
"description": "The official javascript bindings for the Axiom API",
"version": "1.0.0-rc.3",
"version": "1.0.0",
"author": "Axiom, Inc.",
"license": "MIT",
"contributors": [
Expand Down
56 changes: 56 additions & 0 deletions packages/js/src/annotations.ts
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);
}
}
10 changes: 10 additions & 0 deletions packages/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ export class Axiom extends BaseClient {
};
}

declare global {
interface BigInt {
toJSON: () => string;
}
}

BigInt.prototype.toJSON = function () {
return this.toString();
};

export enum ContentType {
JSON = 'application/json',
NDJSON = 'application/x-ndjson',
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AxiomURL = 'https://api.axiom.co';
export interface ClientOptions {
/**
* an API or personal token to use for authentication, you can get one
* from @{link: Axiom settings | https://app.axiom.co/profile}.
* from @{link: Axiom settings | https://app.axiom.co/api-tokens}.
*/
token: string;
/**
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/index.ts
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';
Loading

0 comments on commit 39c164c

Please sign in to comment.