Skip to content

Commit

Permalink
Add types for counter analytics rule, and also add Analytics Events
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed Apr 17, 2024
1 parent 21f04c8 commit e8cee13
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 7 deletions.
71 changes: 71 additions & 0 deletions dist/typesense.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/typesense.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/Typesense/Analytics.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import ApiCall from "./ApiCall";
import AnalyticsRules from "./AnalyticsRules";
import AnalyticsRule from "./AnalyticsRule";
import AnalyticsEvents from "./AnalyticsEvents";
export default class Analytics {
private readonly apiCall;
private readonly _analyticsRules;
private readonly individualAnalyticsRules;
private readonly _analyticsEvents;
constructor(apiCall: ApiCall);
rules(id?: string): AnalyticsRules | AnalyticsRule;
events(): AnalyticsEvents;
static get RESOURCEPATH(): string;
}
5 changes: 5 additions & 0 deletions lib/Typesense/Analytics.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Typesense/Analytics.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/Typesense/AnalyticsEvent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AnalyticsEventCreateSchema {
type: string;
name: string;
data?: object;
}
3 changes: 3 additions & 0 deletions lib/Typesense/AnalyticsEvent.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/Typesense/AnalyticsEvent.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/Typesense/AnalyticsEvents.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ApiCall from "./ApiCall";
import { AnalyticsEventCreateSchema } from "./AnalyticsEvent";
export default class AnalyticsEvents {
private readonly apiCall;
constructor(apiCall: ApiCall);
create(params: AnalyticsEventCreateSchema): Promise<AnalyticsEventCreateSchema>;
private endpointPath;
static get RESOURCEPATH(): string;
}
65 changes: 65 additions & 0 deletions lib/Typesense/AnalyticsEvents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/Typesense/AnalyticsEvents.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion lib/Typesense/AnalyticsRule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ export interface AnalyticsRuleCreateSchema {
params: {
source: {
collections: string[];
events?: Array<{
type: string;
weight: number;
name: string;
}>;
};
expand_query?: boolean;
destination: {
collection: string;
counter_field?: string;
};
limit: number;
limit?: number;
};
}
export interface AnalyticsRuleDeleteSchema {
Expand Down
2 changes: 1 addition & 1 deletion lib/Typesense/AnalyticsRule.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Typesense/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import ApiCall from "./ApiCall";
import AnalyticsRules from "./AnalyticsRules";
import AnalyticsRule from "./AnalyticsRule";
import AnalyticsEvents from "./AnalyticsEvents";

const RESOURCEPATH = "/analytics";

export default class Analytics {
private readonly _analyticsRules: AnalyticsRules;
private readonly individualAnalyticsRules: Record<string, AnalyticsRule> = {};
private readonly _analyticsEvents: AnalyticsEvents;

constructor(private readonly apiCall: ApiCall) {
this.apiCall = apiCall;
this._analyticsRules = new AnalyticsRules(this.apiCall);
this._analyticsEvents = new AnalyticsEvents(this.apiCall);
}

rules(id?: string): AnalyticsRules | AnalyticsRule {
Expand All @@ -24,6 +27,10 @@ export default class Analytics {
}
}

events(): AnalyticsEvents {
return this._analyticsEvents;
}

static get RESOURCEPATH() {
return RESOURCEPATH;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Typesense/AnalyticsEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AnalyticsEventCreateSchema {
type: string;
name: string;
data?: object;
}
29 changes: 29 additions & 0 deletions src/Typesense/AnalyticsEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ApiCall from "./ApiCall";
import { AnalyticsEventCreateSchema } from "./AnalyticsEvent";

const RESOURCEPATH = "/analytics/events";

export default class AnalyticsEvents {
constructor(private readonly apiCall: ApiCall) {
this.apiCall = apiCall;
}

async create(
params: AnalyticsEventCreateSchema,
): Promise<AnalyticsEventCreateSchema> {
return this.apiCall.post<AnalyticsEventCreateSchema>(
this.endpointPath(),
params,
);
}

private endpointPath(operation?: string): string {
return `${AnalyticsEvents.RESOURCEPATH}${
operation === undefined ? "" : "/" + operation
}`;
}

static get RESOURCEPATH() {
return RESOURCEPATH;
}
}
8 changes: 7 additions & 1 deletion src/Typesense/AnalyticsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ export interface AnalyticsRuleCreateSchema {
params: {
source: {
collections: string[];
events?: Array<{
type: string;
weight: number;
name: string;
}>;
};
expand_query?: boolean;
destination: {
collection: string;
counter_field?: string;
};
limit: number;
limit?: number;
};
}

Expand Down
Loading

0 comments on commit e8cee13

Please sign in to comment.