trackswap 0.0.25 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,12 @@ export declare class TrackSwap {
21
21
  encodeGPXString(gpxData: GPX11Type): string;
22
22
  parseFIT(buffer: Buffer): Promise<FITFileType | undefined>;
23
23
  encodeFIT(fitData: FITFileType): Promise<Buffer>;
24
- encodeFITCourse(fitData: FITFileType): Promise<Buffer>;
24
+ encodeFITCourse(buffer: Buffer): Promise<Buffer>;
25
+ convertFITToCourse(buffer: Buffer): Promise<Buffer>;
26
+ convertToFITCourse(buffer: Buffer, sourceType?: "gpx" | "fit" | "tcx"): Promise<Buffer>;
27
+ private buildCoursePlanFromActivityFile;
28
+ private resolveCourseName;
29
+ private toEnumValue;
25
30
  parseTCXString(xmlString: string): Promise<TCXFileType>;
26
31
  parseTCX(buffer: Buffer): Promise<TCXFileType>;
27
32
  encodeTCX(tcxData: TCXFileType): Promise<Buffer>;
@@ -0,0 +1,62 @@
1
+ import { IPlugin, IConverterPlugin, IMiddlewarePlugin, BaseConverter, BaseMiddleware, IProcessingContext } from "../core/base.js";
2
+ import { ActivityType, ActivityRecordType, ActivityLapType, TokenAST, FileType } from "../types.js";
3
+ export interface ActivityContext extends IProcessingContext {
4
+ sourceFormat: string;
5
+ sourceData: any;
6
+ result?: FileType;
7
+ performance: {
8
+ startTime: number;
9
+ convertTime?: number;
10
+ endTime?: number;
11
+ };
12
+ }
13
+ export interface ActivityEncodingContext extends IProcessingContext {
14
+ targetFormat: string;
15
+ result?: any;
16
+ performance: {
17
+ startTime: number;
18
+ encodeTime?: number;
19
+ endTime?: number;
20
+ };
21
+ }
22
+ export interface IActivityPlugin extends IPlugin {
23
+ }
24
+ export interface IActivityConverterPlugin extends IConverterPlugin {
25
+ convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
26
+ }
27
+ export interface IActivityMiddlewarePlugin extends IMiddlewarePlugin {
28
+ process(context: ActivityContext): Promise<void>;
29
+ }
30
+ export interface IActivityEncoderPlugin extends IPlugin<ActivityEncodingContext> {
31
+ encode(file: FileType, context: ActivityEncodingContext): any | undefined;
32
+ supports(format: string): boolean;
33
+ priority?: number;
34
+ }
35
+ export declare abstract class BaseActivityConverter extends BaseConverter<ActivityContext> implements IActivityConverterPlugin {
36
+ protected convertPoints(points: any[]): ActivityRecordType[];
37
+ protected abstract convertPoint(point: any): ActivityRecordType | undefined;
38
+ protected convertTime(time: Date | string | number | undefined): number | undefined;
39
+ }
40
+ export declare abstract class BaseActivityEncoder implements IActivityEncoderPlugin {
41
+ abstract name: string;
42
+ abstract supportedTags: string[];
43
+ version: string;
44
+ priority: number;
45
+ abstract encode(file: FileType, context: ActivityEncodingContext): any | undefined;
46
+ supports(format: string): boolean;
47
+ initialize(context: ActivityEncodingContext): Promise<void>;
48
+ destroy(context: ActivityEncodingContext): Promise<void>;
49
+ validate(context: ActivityEncodingContext): Promise<boolean>;
50
+ protected convertTimeToDate(time: number | undefined): Date;
51
+ protected convertTimeToString(time: number | undefined): string;
52
+ protected ensureValidCoordinates(lat: number, lon: number): boolean;
53
+ protected round(value: number, precision?: number): number;
54
+ }
55
+ export declare abstract class BaseActivityMiddleware extends BaseMiddleware<ActivityContext, ActivityType> implements IActivityMiddlewarePlugin {
56
+ abstract process(context: ActivityContext): Promise<void>;
57
+ onError(error: Error, context: ActivityContext): Promise<void>;
58
+ protected validateActivityFile(file: FileType): boolean;
59
+ protected validateActivity(activity: ActivityType): boolean;
60
+ protected validateRoute(route: ActivityLapType): boolean;
61
+ protected validatePoint(point: ActivityRecordType): boolean;
62
+ }
@@ -0,0 +1,36 @@
1
+ import { BaseActivityConverter, ActivityContext } from "./base.js";
2
+ import { FileType, TokenAST } from "../types.js";
3
+ import { ActivityRecordType } from "../types.js";
4
+ import { WptType } from "../GPX/types.js";
5
+ import { RecordMesgType } from "../FIT/types.js";
6
+ import { TrackpointType } from "../TCX/types.js";
7
+ export declare class GPXToActivityConverter extends BaseActivityConverter {
8
+ name: string;
9
+ supportedTags: string[];
10
+ convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
11
+ private convertGPX;
12
+ protected convertPoint(point: WptType, idx?: number, lapIdx?: number): ActivityRecordType;
13
+ private convertTrk2Activity;
14
+ private convertTrackSeg2Lap;
15
+ private convertWpts2Points;
16
+ private convertGPXExtensions;
17
+ private autoNumber;
18
+ }
19
+ export declare class FITToActivityConverter extends BaseActivityConverter {
20
+ name: string;
21
+ supportedTags: string[];
22
+ convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
23
+ private convertFIT;
24
+ protected convertPoint(point: RecordMesgType, idx?: number, lapIdx?: number): ActivityRecordType | undefined;
25
+ private convertFITLap2Trackseg;
26
+ private convertLap2Points;
27
+ }
28
+ export declare class TCXToActivityConverter extends BaseActivityConverter {
29
+ name: string;
30
+ supportedTags: string[];
31
+ convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
32
+ private convertTCX;
33
+ private convertTCXActivityToActivity;
34
+ private convertTCXLap2Lap;
35
+ protected convertPoint(point: TrackpointType, idx?: number, lapIdx?: number): ActivityRecordType;
36
+ }
@@ -0,0 +1,32 @@
1
+ import { BaseActivityEncoder, ActivityEncodingContext } from "./base.js";
2
+ import { FileType } from "../types.js";
3
+ import { GPX11Type } from "../GPX/types.js";
4
+ import { FITFileType } from "../FIT/types.js";
5
+ import { TCXFileType } from "../TCX/types.js";
6
+ export declare class ActivityToGPXEncoder extends BaseActivityEncoder {
7
+ name: string;
8
+ supportedTags: string[];
9
+ encode(file: FileType, context: ActivityEncodingContext): GPX11Type | undefined;
10
+ private convertRecords2Wpts;
11
+ private convertRoute2GPXRoute;
12
+ private convertActivity2GPXTrack;
13
+ private extractGPXExtensions;
14
+ }
15
+ export declare class ActivityToFITEncoder extends BaseActivityEncoder {
16
+ name: string;
17
+ supportedTags: string[];
18
+ encode(file: FileType, context: ActivityEncodingContext): FITFileType | undefined;
19
+ private convertActivity2FITSession;
20
+ private convertLap2FITLap;
21
+ private convertPoint2FITRecord;
22
+ }
23
+ export declare class ActivityToTCXEncoder extends BaseActivityEncoder {
24
+ name: string;
25
+ supportedTags: string[];
26
+ encode(file: FileType, context: ActivityEncodingContext): TCXFileType | undefined;
27
+ private convertActivity2TCXActivity;
28
+ private convertLap2TCXLap;
29
+ private convertRecords2TCXTrack;
30
+ private convertPoint2TCXTrackpoint;
31
+ private convertRoute2TCXCourse;
32
+ }
@@ -0,0 +1,17 @@
1
+ export * from "./base.js";
2
+ export * from "./converters.js";
3
+ export * from "./encoders.js";
4
+ export * from "./processor.js";
5
+ import { GPXToActivityConverter, FITToActivityConverter, TCXToActivityConverter } from "./converters.js";
6
+ import { ActivityToGPXEncoder, ActivityToFITEncoder, ActivityToTCXEncoder } from "./encoders.js";
7
+ import { ActivityProcessor } from "./processor.js";
8
+ declare const _default: {
9
+ GPXToActivityConverter: typeof GPXToActivityConverter;
10
+ FITToActivityConverter: typeof FITToActivityConverter;
11
+ TCXToActivityConverter: typeof TCXToActivityConverter;
12
+ ActivityToGPXEncoder: typeof ActivityToGPXEncoder;
13
+ ActivityToFITEncoder: typeof ActivityToFITEncoder;
14
+ ActivityToTCXEncoder: typeof ActivityToTCXEncoder;
15
+ ActivityProcessor: typeof ActivityProcessor;
16
+ };
17
+ export default _default;
@@ -0,0 +1,18 @@
1
+ import { ActivityType, ActivityLapType, ActivityRecordType } from "../../types.js";
2
+ interface MetricsRecordsResult extends Partial<ActivityLapType> {
3
+ records: ActivityRecordType[];
4
+ }
5
+ interface MetricsLapsResult extends Partial<ActivityType> {
6
+ timestamp: Date;
7
+ laps: ActivityLapType[];
8
+ }
9
+ export declare class MetricsAggregator {
10
+ calculateRecordsAggMetrics(records: ActivityRecordType[]): MetricsRecordsResult | undefined;
11
+ calculateLapAggMetrics(laps: ActivityLapType[]): MetricsLapsResult | undefined;
12
+ private preprocessRecords;
13
+ private calculatePointDistanceByPosition;
14
+ private calculateInstantSpeed;
15
+ private calculateAccumulatedPower;
16
+ private calculateElevationChanges;
17
+ }
18
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./MetricsCalculator.js";
@@ -0,0 +1,19 @@
1
+ import { IActivityConverterPlugin, IActivityEncoderPlugin } from "./base.js";
2
+ import { FileType } from "../types.js";
3
+ import { GPX11Type } from "../GPX/types.js";
4
+ import { FITFileType } from "../FIT/types.js";
5
+ import { TCXFileType } from "../TCX/types.js";
6
+ export declare class ActivityProcessor {
7
+ private converters;
8
+ private encoders;
9
+ constructor();
10
+ private registerDefaultConverters;
11
+ private registerDefaultEncoders;
12
+ registerConverter(converter: IActivityConverterPlugin): void;
13
+ registerEncoder(encoder: IActivityEncoderPlugin): void;
14
+ convertToActivity(sourceData: GPX11Type | FITFileType | TCXFileType, sourceFormat: "gpx" | "fit" | "tcx"): Promise<FileType>;
15
+ encodeActivity(file: FileType, targetFormat: "gpx" | "fit" | "tcx"): Promise<GPX11Type | FITFileType | TCXFileType>;
16
+ private findConverter;
17
+ private findEncoder;
18
+ destroy(): Promise<void>;
19
+ }