Skip to content

Commit

Permalink
Merge pull request #13 from hyperse-io/feat/track
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun authored Oct 25, 2024
2 parents 0da5510 + c54d1c6 commit 2aee2f8
Show file tree
Hide file tree
Showing 41 changed files with 1,783 additions and 1,439 deletions.
7 changes: 7 additions & 0 deletions .changeset/twelve-goats-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@hyperse/track": patch
---


1、adjust ts rules
2、fix typing error
2 changes: 1 addition & 1 deletion examples/next-example/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useEffect, useState } from 'react';
import mockjs from 'mockjs';
import { reportTrack } from '@/track/track';
import { GoodsRecord } from '@/track/types';
import type { GoodsRecord } from '@/track/types';
import { fetchGoodsList } from './service';

export default function Home() {
Expand Down
2 changes: 1 addition & 1 deletion examples/next-example/app/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Mock from 'mockjs';
import { GoodsRecord } from '@/track/types';
import type { GoodsRecord } from '@/track/types';

export const fetchGoodsList = (): GoodsRecord[] => {
const data = Mock.mock({
Expand Down
2 changes: 1 addition & 1 deletion examples/next-example/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
28 changes: 14 additions & 14 deletions examples/next-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
}
},
"dependencies": {
"@hyperse/track": "^1.0.2",
"@types/node": "20.6.2",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"autoprefixer": "10.4.15",
"eslint": "^9.8.0",
"eslint-config-next": "14.2.5",
"next": "14.2.5",
"postcss": "8.4.30",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.3",
"typescript": "5.5.4"
"@hyperse/track": "^1.0.4",
"@types/node": "22.7.9",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"autoprefixer": "10.4.20",
"eslint": "^9.13.0",
"eslint-config-next": "15.0.1",
"next": "15.0.1",
"postcss": "8.4.47",
"react": "18.3.1",
"react-dom": "18.3.1",
"tailwindcss": "3.4.14",
"typescript": "5.6.3"
},
"devDependencies": {
"@hyperse/eslint-config-hyperse": "1.1.3",
"@hyperse/eslint-config-hyperse": "1.2.6",
"@types/mockjs": "^1",
"mockjs": "^1.1.0"
}
Expand Down
16 changes: 4 additions & 12 deletions examples/next-example/track/report-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AdapterReportData, BaseAdapter, TrackContext } from '@hyperse/track';
import {
import type { AdapterReportData, TrackContext } from '@hyperse/track';
import { BaseAdapter } from '@hyperse/track';
import type {
ReportAdapterOptions,
ReportEventData,
ReportRealEventData,
Expand All @@ -16,16 +17,7 @@ export class ReportAdapter extends BaseAdapter<
>,
ReportRealEventData
> {
isTrackable<EventType extends keyof ReportRealEventData>(
ctx: TrackContext<ReportTrackData>,
eventType: keyof ReportRealEventData,
reportData?:
| AdapterReportData<ReportRealEventData, ReportEventData, EventType>
| Awaited<
AdapterReportData<ReportRealEventData, ReportEventData, EventType>
>
| undefined
): boolean | Promise<boolean> {
isTrackable(): boolean | Promise<boolean> {
return true;
}

Expand Down
15 changes: 6 additions & 9 deletions examples/next-example/track/track.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
createAdapterBuilder,
createTrackBuilder,
TrackContext,
} from '@hyperse/track';
import type { TrackContext } from '@hyperse/track';
import { createAdapterBuilder, createTrackBuilder } from '@hyperse/track';
import { ReportAdapter } from './report-adapter';
import {
import type {
ReportAdapterOptions,
ReportEventData,
ReportRealEventData,
Expand Down Expand Up @@ -34,16 +31,16 @@ export const reportTrack = () => {
.before((ctx, eventType, eventData) => {
console.log('before', ctx, eventType, eventData);
})
.transform(['addCart', 'real_addCart'], (ctx, eventType, eventData) => {
.transform(['addCart', 'real_addCart'], (_, __, eventData) => {
if (eventData) {
return [eventData];
}
return [];
})
.transform(['addCartList', 'real_addCart'], (ctx, eventType, eventData) => {
.transform(['addCartList', 'real_addCart'], (_, __, eventData) => {
return eventData || [];
})
.transform('pv', (ctx, eventType, eventData) => {
.transform('pv', (_, __, eventData) => {
return eventData;
})
.after((ctx, eventType, reportData) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/next-example/track/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetSafeRealEventTypes } from '@hyperse/track';
import type { GetSafeRealEventTypes } from '@hyperse/track';

export type ReportAdapterOptions<Context, EventData, RealEventData> = {
setup?: <EventType extends keyof EventData>(
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@
},
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.7",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@hyperse/eslint-config-hyperse": "^1.0.12",
"@changesets/cli": "2.27.9",
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@hyperse/eslint-config-hyperse": "^1.2.6",
"@hyperse/exec-program": "^1.0.10",
"@hyperse/vitest-coverage-reporter": "^1.0.13",
"@hyperse/vitest-coverage-reporter": "^1.0.15",
"@types/lodash": "^4",
"@types/node": "^22.1.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitest/coverage-istanbul": "^2.0.5",
"@vitest/ui": "^2.0.5",
"commitizen": "4.3.0",
"@types/node": "^22.7.9",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitest/coverage-istanbul": "^2.1.3",
"@vitest/ui": "^2.1.3",
"commitizen": "4.3.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^9.8.0",
"husky": "9.1.4",
"lint-staged": "15.2.8",
"next": "14.2.5",
"eslint": "^9.13.0",
"husky": "9.1.6",
"lint-staged": "15.2.10",
"next": "15.0.1",
"npm-run-all": "^4.1.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"vite": "^5.3.5",
"vitest": "^2.0.5"
"tsup": "^8.3.0",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vitest": "^2.1.3"
},
"engines": {
"node": ">=18"
Expand Down
9 changes: 6 additions & 3 deletions src/adapter/adapter-base.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { pipe } from '@hyperse/pipeline';
import { executeFunction } from '../helpers/helper-execute.js';
import {
import type {
AdapterAfterFunction,
AdapterBeforeFunction,
AdapterReportData,
AdapterTransformFunction,
GetSafeRealEventTypes,
TrackAdapter,
} from '../types/types-adapter.js';
import { TrackAdapterOptions, TrackContext } from '../types/types-create.js';
import { TrackEventDataBase } from '../types/types-track.js';
import type {
TrackAdapterOptions,
TrackContext,
} from '../types/types-create.js';
import type { TrackEventDataBase } from '../types/types-track.js';

export abstract class BaseAdapter<
Context extends TrackContext<any>,
Expand Down
11 changes: 7 additions & 4 deletions src/adapter/adapter-builder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {
import type {
AdapterAfterFunction,
AdapterBeforeFunction,
TrackAdapter,
TransformEventData,
TransformEventType,
TransformReturns,
} from '../types/types-adapter.js';
import { TrackAdapterOptions, TrackContext } from '../types/types-create.js';
import { TrackEventDataBase } from '../types/types-track.js';
import { TransformHook } from '../types/types-transform-hook.js';
import type {
TrackAdapterOptions,
TrackContext,
} from '../types/types-create.js';
import type { TrackEventDataBase } from '../types/types-track.js';
import type { TransformHook } from '../types/types-transform-hook.js';

/**
* A builder for creating a track adapter.
Expand Down
9 changes: 6 additions & 3 deletions src/adapter/create-adapter-builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TrackAdapter } from '../types/types-adapter.js';
import { TrackAdapterOptions, TrackContext } from '../types/types-create.js';
import { TrackEventDataBase } from '../types/types-track.js';
import type { TrackAdapter } from '../types/types-adapter.js';
import type {
TrackAdapterOptions,
TrackContext,
} from '../types/types-create.js';
import type { TrackEventDataBase } from '../types/types-track.js';
import { AdapterBuilder } from './adapter-builder.js';

/**
Expand Down
7 changes: 5 additions & 2 deletions src/core/create-track-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { TrackContext, TrackCreateOptions } from '../types/types-create.js';
import { TrackEventDataBase } from '../types/types-track.js';
import type {
TrackContext,
TrackCreateOptions,
} from '../types/types-create.js';
import type { TrackEventDataBase } from '../types/types-track.js';
import { TrackBuilder } from './track-builder.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/track-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { deepMerge } from '../helpers/helper-deep-merge.js';
import { executeFunction } from '../helpers/helper-execute.js';
import { isFunction } from '../helpers/helper-is-function.js';
import { executeSelect } from '../helpers/helper-select-adapter.js';
import {
import type {
TrackContext,
TrackCreateDataFunction,
TrackCreateOptions,
} from '../types/types-create.js';
import {
import type {
TrackAdapterMap,
TrackAfterFunction,
TrackBeforeFunction,
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/helper-adapter-ctx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackEventDataBase } from '../types/index.js';
import {
import type { TrackEventDataBase } from '../types/index.js';
import type {
TrackContext,
TrackCreateDataFunction,
} from '../types/types-create.js';
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/helper-adapter-track.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { TrackContext } from '../types/types-create.js';
import { TrackAdapterMap, TrackEventDataBase } from '../types/types-track.js';
import type { TrackContext } from '../types/types-create.js';
import type {
TrackAdapterMap,
TrackEventDataBase,
} from '../types/types-track.js';

/**
* Executes the track function of each adapter in the adapterMap for the given eventType and result.
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/helper-select-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackContext } from '../types/types-create.js';
import {
import type { TrackContext } from '../types/types-create.js';
import type {
TrackAdapterMap,
TrackEventDataBase,
TrackSelectFunction,
Expand Down
4 changes: 2 additions & 2 deletions src/types/types-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackAdapterOptions, TrackContext } from './types-create.js';
import { TrackEventDataBase } from './types-track.js';
import type { TrackAdapterOptions, TrackContext } from './types-create.js';
import type { TrackEventDataBase } from './types-track.js';

export type TransformReturns<Key, RealEventData, EventData> =
Key extends keyof EventData
Expand Down
6 changes: 3 additions & 3 deletions src/types/types-create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetSafeRealEventTypes } from './types-adapter.js';
import { TrackLogger } from './types-logger.js';
import { TrackEventDataBase } from './types-track.js';
import type { GetSafeRealEventTypes } from './types-adapter.js';
import type { TrackLogger } from './types-logger.js';
import type { TrackEventDataBase } from './types-track.js';

/**
* A function that creates track data.
Expand Down
4 changes: 2 additions & 2 deletions src/types/types-track.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackAdapter } from './types-adapter.js';
import { TrackContext } from './types-create.js';
import type { TrackAdapter } from './types-adapter.js';
import type { TrackContext } from './types-create.js';

/**
* A function that is executed before tracking
Expand Down
8 changes: 4 additions & 4 deletions src/types/types-transform-hook.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UnionToTuple } from './type-union-tuple.js';
import {
import type { UnionToTuple } from './type-union-tuple.js';
import type {
TransformEventData,
TransformEventType,
TransformReturns,
} from './types-adapter.js';
import { TrackContext } from './types-create.js';
import { TrackEventDataBase } from './types-track.js';
import type { TrackContext } from './types-create.js';
import type { TrackEventDataBase } from './types-track.js';

/**
* Represents the return type of the TransformHookReturns function.
Expand Down
8 changes: 4 additions & 4 deletions tests/test-adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createAdapterBuilder } from '../src/adapter/create-adapter-builder.js';
import { TrackContext } from '../src/types/types-create.js';
import type { TrackContext } from '../src/types/types-create.js';
import { ReportAdapter } from './test-utils/adapter/report-adapter.js';
import { AdapterOptions } from './test-utils/types/type-adapter-options.js';
import { EventDataOption } from './test-utils/types/type-event.js';
import { TrackData } from './test-utils/types/type-track-data.js';
import type { AdapterOptions } from './test-utils/types/type-adapter-options.js';
import type { EventDataOption } from './test-utils/types/type-event.js';
import type { TrackData } from './test-utils/types/type-track-data.js';

describe('test-adapter.spec', () => {
const trackData: TrackData = {
Expand Down
8 changes: 4 additions & 4 deletions tests/test-real-transform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createAdapterBuilder } from '../src/adapter/create-adapter-builder.js';
import { createTrackBuilder } from '../src/index.js';
import { TrackContext } from '../src/types/types-create.js';
import type { TrackContext } from '../src/types/types-create.js';
import { AnalyzerAdapter } from './test-utils/adapter/analyzer-adapter.js';
import { ConsoleLogger } from './test-utils/console-logger.js';
import { AdapterRealOptions } from './test-utils/types/type-adapter-options.js';
import {
import type { AdapterRealOptions } from './test-utils/types/type-adapter-options.js';
import type {
EventDataOption,
RealEventDataOption,
} from './test-utils/types/type-event.js';
import { TrackData } from './test-utils/types/type-track-data.js';
import type { TrackData } from './test-utils/types/type-track-data.js';

describe('test-real-transform.spec', () => {
const trackData: TrackData = {
Expand Down
10 changes: 5 additions & 5 deletions tests/test-track-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createTrackBuilder } from '../src/core/create-track-builder.js';
import { TrackAdapter } from '../src/types/types-adapter.js';
import { TrackContext } from '../src/types/types-create.js';
import type { TrackAdapter } from '../src/types/types-adapter.js';
import type { TrackContext } from '../src/types/types-create.js';
import { defaultAdapterBuilder } from './test-utils/adapter/default-adapter-builder.js';
import { ConsoleLogger } from './test-utils/console-logger.js';
import { AdapterOptions } from './test-utils/types/type-adapter-options.js';
import { EventDataOption } from './test-utils/types/type-event.js';
import { TrackData } from './test-utils/types/type-track-data.js';
import type { AdapterOptions } from './test-utils/types/type-adapter-options.js';
import type { EventDataOption } from './test-utils/types/type-event.js';
import type { TrackData } from './test-utils/types/type-track-data.js';

describe('test-track-error.spec', () => {
const trackData: TrackData = {
Expand Down
Loading

0 comments on commit 2aee2f8

Please sign in to comment.