trackswap 0.0.26 → 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.
- package/dist/FIT/base.d.ts +61 -0
- package/dist/FIT/crc.d.ts +1 -0
- package/dist/FIT/decoder.d.ts +35 -0
- package/dist/FIT/encoder.d.ts +45 -0
- package/dist/FIT/encoderCourse.d.ts +37 -0
- package/dist/FIT/encoderWorkout.d.ts +41 -0
- package/dist/FIT/index.d.ts +13 -0
- package/dist/FIT/mesg.d.ts +37 -0
- package/dist/FIT/middleware.d.ts +33 -0
- package/dist/FIT/plugins.d.ts +17 -0
- package/dist/FIT/processor.d.ts +34 -0
- package/dist/FIT/types/checksum_type.d.ts +4 -0
- package/dist/FIT/types/course_point.d.ts +56 -0
- package/dist/FIT/types/date_time_type.d.ts +3 -0
- package/dist/FIT/types/event.d.ts +49 -0
- package/dist/FIT/types/event_type.d.ts +18 -0
- package/dist/FIT/types/file.d.ts +23 -0
- package/dist/FIT/types/file_flags_type.d.ts +5 -0
- package/dist/FIT/types/index.d.ts +119 -0
- package/dist/FIT/types/local_date_time_type.d.ts +3 -0
- package/dist/FIT/types/mesg_count_type.d.ts +5 -0
- package/dist/FIT/types/mesg_num.d.ts +125 -0
- package/dist/FIT/types/message_index_type.d.ts +4558 -0
- package/dist/FIT/types/sport.d.ts +47 -0
- package/dist/FIT/types.d.ts +511 -0
- package/dist/FIT/util.d.ts +1 -0
- package/dist/GPX/base.d.ts +16 -0
- package/dist/GPX/converters.d.ts +62 -0
- package/dist/GPX/decoder.d.ts +43 -0
- package/dist/GPX/encoder.d.ts +45 -0
- package/dist/GPX/extensions/index.d.ts +14 -0
- package/dist/GPX/index.d.ts +13 -0
- package/dist/GPX/middleware.d.ts +18 -0
- package/dist/GPX/processor.d.ts +30 -0
- package/dist/GPX/types.d.ts +124 -0
- package/dist/GPX/util.d.ts +1 -0
- package/dist/TCX/base.d.ts +19 -0
- package/dist/TCX/converters.d.ts +52 -0
- package/dist/TCX/decoder.d.ts +33 -0
- package/dist/TCX/encoder.d.ts +41 -0
- package/dist/TCX/index.d.ts +7 -0
- package/dist/TCX/middleware.d.ts +25 -0
- package/dist/TCX/processor.d.ts +39 -0
- package/dist/TCX/types.d.ts +191 -0
- package/dist/TrackSwap.d.ts +53 -0
- package/dist/activity/base.d.ts +62 -0
- package/dist/activity/converters.d.ts +36 -0
- package/dist/activity/encoders.d.ts +32 -0
- package/dist/activity/index.d.ts +17 -0
- package/dist/activity/metrics/MetricsCalculator.d.ts +18 -0
- package/dist/activity/metrics/index.d.ts +1 -0
- package/dist/activity/processor.d.ts +19 -0
- package/dist/core/base.d.ts +73 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/xml-utils.d.ts +17 -0
- package/dist/index.d.ts +8 -0
- package/dist/types.d.ts +75 -0
- package/package.json +6 -5
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GPXDecoder, GPXEncoder } from "./GPX/index.js";
|
|
2
|
+
import { GPX11Type } from "./GPX/types.js";
|
|
3
|
+
import { FITDecoder, FITEncoder } from "./FIT/index.js";
|
|
4
|
+
import { FITFileType } from "./FIT/types.js";
|
|
5
|
+
import { TCXDecoder, TCXEncoder } from "./TCX/index.js";
|
|
6
|
+
import { TCXFileType } from "./TCX/types.js";
|
|
7
|
+
import { ActivityProcessor } from "./activity/processor.js";
|
|
8
|
+
import { FileType } from "./types.js";
|
|
9
|
+
export declare class TrackSwap {
|
|
10
|
+
private gpxDecoder;
|
|
11
|
+
private gpxEncoder;
|
|
12
|
+
private fitDecoder;
|
|
13
|
+
private fitEncoder;
|
|
14
|
+
private tcxDecoder;
|
|
15
|
+
private tcxEncoder;
|
|
16
|
+
private activityProcessor;
|
|
17
|
+
constructor();
|
|
18
|
+
parseGPX(buffer: Buffer): Promise<GPX11Type | undefined>;
|
|
19
|
+
parseGPXString(xmlString: string): Promise<GPX11Type | undefined>;
|
|
20
|
+
encodeGPX(gpxData: GPX11Type): Promise<Buffer>;
|
|
21
|
+
encodeGPXString(gpxData: GPX11Type): string;
|
|
22
|
+
parseFIT(buffer: Buffer): Promise<FITFileType | undefined>;
|
|
23
|
+
encodeFIT(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;
|
|
30
|
+
parseTCXString(xmlString: string): Promise<TCXFileType>;
|
|
31
|
+
parseTCX(buffer: Buffer): Promise<TCXFileType>;
|
|
32
|
+
encodeTCX(tcxData: TCXFileType): Promise<Buffer>;
|
|
33
|
+
encodeTCXString(tcxData: TCXFileType): Promise<string>;
|
|
34
|
+
convertGPXToActivity(gpxData: GPX11Type): Promise<FileType>;
|
|
35
|
+
convertFITToActivity(fitData: FITFileType): Promise<FileType>;
|
|
36
|
+
convertTCXToActivity(tcxData: TCXFileType): Promise<FileType>;
|
|
37
|
+
convertActivityToGPX(file: FileType): Promise<GPX11Type>;
|
|
38
|
+
convertActivityToFIT(file: FileType): Promise<FITFileType>;
|
|
39
|
+
convertActivityToTCX(file: FileType): Promise<TCXFileType>;
|
|
40
|
+
convertFile(sourceFile: Buffer, targetType: "gpx" | "fit" | "tcx", sourceType?: "gpx" | "fit" | "tcx"): Promise<Buffer>;
|
|
41
|
+
detectFormat(buffer: Buffer): "gpx" | "fit" | "tcx" | "unknown";
|
|
42
|
+
parseFile(buffer: Buffer, sourceType?: "gpx" | "fit" | "tcx"): Promise<GPX11Type | FITFileType | TCXFileType | undefined>;
|
|
43
|
+
parseToActivity(buffer: Buffer, sourceType?: "gpx" | "fit" | "tcx"): Promise<FileType | undefined>;
|
|
44
|
+
getActivityProcessor(): ActivityProcessor;
|
|
45
|
+
getGPXDecoder(): GPXDecoder;
|
|
46
|
+
getGPXEncoder(): GPXEncoder;
|
|
47
|
+
getFITDecoder(): FITDecoder;
|
|
48
|
+
getFITEncoder(): FITEncoder;
|
|
49
|
+
getTCXDecoder(): TCXDecoder;
|
|
50
|
+
getTCXEncoder(): TCXEncoder;
|
|
51
|
+
destroy(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export default TrackSwap;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ExtensionsType, Token, TokenAST } from "../types.js";
|
|
2
|
+
export interface IPlugin<TContext = any> {
|
|
3
|
+
name: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
dependencies?: string[];
|
|
7
|
+
supportedTags?: string[];
|
|
8
|
+
initialize?(context: TContext): Promise<void> | void;
|
|
9
|
+
destroy?(context: TContext): Promise<void> | void;
|
|
10
|
+
validate?(context: TContext): Promise<boolean> | boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface IConverterPlugin<TContext = any> extends IPlugin<TContext> {
|
|
13
|
+
convert(ast: TokenAST, context: TContext): any | undefined;
|
|
14
|
+
supports(tag: string): boolean;
|
|
15
|
+
priority?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface IMiddlewarePlugin<TContext = any, TResult = any> extends IPlugin<TContext> {
|
|
18
|
+
priority?: number;
|
|
19
|
+
onTokenize?(tokens: Token[], context: TContext): Promise<Token[]> | Token[];
|
|
20
|
+
onAstGenerate?(ast: TokenAST, context: TContext): Promise<TokenAST> | TokenAST;
|
|
21
|
+
onConvert?(result: any, context: TContext): Promise<any> | any;
|
|
22
|
+
onComplete?(result: TResult, context: TContext): Promise<TResult> | TResult;
|
|
23
|
+
onError?(error: Error, context: TContext): Promise<void> | void;
|
|
24
|
+
}
|
|
25
|
+
export interface IProcessingContext {
|
|
26
|
+
metadata: Map<string, any>;
|
|
27
|
+
errors: Error[];
|
|
28
|
+
warnings: string[];
|
|
29
|
+
stats: {
|
|
30
|
+
startTime: number;
|
|
31
|
+
endTime?: number;
|
|
32
|
+
processedTokens: number;
|
|
33
|
+
convertedElements: number;
|
|
34
|
+
};
|
|
35
|
+
userData?: Record<string, any>;
|
|
36
|
+
}
|
|
37
|
+
export declare abstract class BaseConverter<TContext extends IProcessingContext = IProcessingContext> implements IConverterPlugin<TContext> {
|
|
38
|
+
abstract name: string;
|
|
39
|
+
abstract supportedTags: string[];
|
|
40
|
+
version: string;
|
|
41
|
+
priority: number;
|
|
42
|
+
abstract convert(ast: TokenAST, context: TContext): any | undefined;
|
|
43
|
+
supports(tag: string): boolean;
|
|
44
|
+
initialize(context: TContext): Promise<void>;
|
|
45
|
+
destroy(context: TContext): Promise<void>;
|
|
46
|
+
validate(context: TContext): Promise<boolean>;
|
|
47
|
+
protected parseFloat(value: string | number | undefined): number | undefined;
|
|
48
|
+
protected parseInt(value: string | number | undefined): number;
|
|
49
|
+
protected parseString(value: string | number | undefined): string;
|
|
50
|
+
protected parseBoolean(value: string | boolean | undefined): boolean;
|
|
51
|
+
protected parseDate(value: string | undefined): Date | undefined;
|
|
52
|
+
protected hasRequiredAttributes(ast: TokenAST, required: string[]): boolean;
|
|
53
|
+
protected extractAttributes<U extends Record<string, any>>(ast: TokenAST, target: U, mapping: Record<string, keyof U>): void;
|
|
54
|
+
protected processChildren<U extends Record<string, any>>(ast: TokenAST, target: U, processors: Record<string, (child: TokenAST, target: U) => void>): void;
|
|
55
|
+
protected getChildValue(ast: TokenAST, tag: string): string | undefined;
|
|
56
|
+
protected getChildByTag(ast: TokenAST, tag: string): TokenAST | undefined;
|
|
57
|
+
protected getChildrenByTag(ast: TokenAST, tag: string): TokenAST[];
|
|
58
|
+
protected convertExtensions(extensionsAST: TokenAST): ExtensionsType;
|
|
59
|
+
protected convertExtensionContent(extension: TokenAST): any;
|
|
60
|
+
}
|
|
61
|
+
export declare abstract class BaseMiddleware<TContext extends IProcessingContext = IProcessingContext, TResult = any> implements IMiddlewarePlugin<TContext, TResult> {
|
|
62
|
+
abstract name: string;
|
|
63
|
+
version: string;
|
|
64
|
+
description: string;
|
|
65
|
+
initialize(context: TContext): Promise<void>;
|
|
66
|
+
destroy(context: TContext): Promise<void>;
|
|
67
|
+
validate(context: TContext): Promise<boolean>;
|
|
68
|
+
onTokenize(tokens: Token[], context: TContext): Promise<Token[]>;
|
|
69
|
+
onAstGenerate(ast: TokenAST, context: TContext): Promise<TokenAST>;
|
|
70
|
+
onConvert(result: any, context: TContext): Promise<any>;
|
|
71
|
+
onComplete(result: TResult, context: TContext): Promise<TResult>;
|
|
72
|
+
onError(error: Error, context: TContext): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Token } from "../types.js";
|
|
2
|
+
export declare class XMLUtils {
|
|
3
|
+
static tokenizeXML(xmlContent: string): Token[];
|
|
4
|
+
static compressXML(xmlContent: string): string;
|
|
5
|
+
static formatXML(xmlContent: string, indentSize?: number): string;
|
|
6
|
+
static validateXML(xmlContent: string): {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
error?: string;
|
|
9
|
+
};
|
|
10
|
+
static extractXMLDeclaration(xmlContent: string): {
|
|
11
|
+
version?: string;
|
|
12
|
+
encoding?: string;
|
|
13
|
+
standalone?: string;
|
|
14
|
+
};
|
|
15
|
+
static escapeXML(text: string): string;
|
|
16
|
+
static unescapeXML(text: string): string;
|
|
17
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export { FITDecoder, FITEncoder, encodeCourse, buildCourseMesgs, type CoursePlan, type CourseRecordPoint, type CourseCuePoint, type CourseFitMesg, } from "./FIT/index.js";
|
|
3
|
+
export { GPXDecoder, GPXEncoder, registerDefaultMiddlewares, PipelineStage, } from "./GPX/index.js";
|
|
4
|
+
export { TCXDecoder, TCXEncoder } from "./TCX/index.js";
|
|
5
|
+
export * from "./activity/index.js";
|
|
6
|
+
import { TrackSwap } from "./TrackSwap.js";
|
|
7
|
+
export { TrackSwap } from "./TrackSwap.js";
|
|
8
|
+
export default TrackSwap;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LapMesgType, LengthMesgType, RecordMesgType, SessionMesgType } from "./FIT/types.js";
|
|
2
|
+
export interface Token {
|
|
3
|
+
type: "open" | "close" | "text";
|
|
4
|
+
tag: string;
|
|
5
|
+
attributes?: AttributeType;
|
|
6
|
+
value?: string | number;
|
|
7
|
+
}
|
|
8
|
+
export interface TokenAST {
|
|
9
|
+
tag: string;
|
|
10
|
+
attributes?: AttributeType;
|
|
11
|
+
children?: TokenAST[];
|
|
12
|
+
value?: string | number;
|
|
13
|
+
}
|
|
14
|
+
export interface AttributeType {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
}
|
|
17
|
+
export type LatitudeType = number;
|
|
18
|
+
export type LongitudeType = number;
|
|
19
|
+
export type DegreesType = number;
|
|
20
|
+
export interface ExtensionsType {
|
|
21
|
+
[key: string]: string | number | undefined | ExtensionsType;
|
|
22
|
+
}
|
|
23
|
+
export interface FileType {
|
|
24
|
+
metadata?: {
|
|
25
|
+
originType: "GPX" | "FIT" | "TCX" | "HIJSON";
|
|
26
|
+
fileName?: string;
|
|
27
|
+
fileType?: string;
|
|
28
|
+
};
|
|
29
|
+
points?: ActivityRecordType[];
|
|
30
|
+
routes?: ActivityLapType[];
|
|
31
|
+
activities?: ActivityType[];
|
|
32
|
+
userProfile?: UserProfileType;
|
|
33
|
+
}
|
|
34
|
+
export interface UserProfileType {
|
|
35
|
+
name?: string;
|
|
36
|
+
weight?: number;
|
|
37
|
+
gender?: string;
|
|
38
|
+
age?: number;
|
|
39
|
+
height?: number;
|
|
40
|
+
language?: string;
|
|
41
|
+
defaultMaxBikingHeartRate?: number;
|
|
42
|
+
defaultMaxHeartRate?: number;
|
|
43
|
+
hrSetting?: string;
|
|
44
|
+
speedSetting?: string;
|
|
45
|
+
distSetting?: string;
|
|
46
|
+
powerSetting?: string;
|
|
47
|
+
activityClass?: number;
|
|
48
|
+
positionSetting?: string;
|
|
49
|
+
temperatureSetting?: string;
|
|
50
|
+
elevSetting?: string;
|
|
51
|
+
weightSetting?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ActivityType extends SessionMesgType {
|
|
54
|
+
index: number;
|
|
55
|
+
endTime?: Date;
|
|
56
|
+
laps?: ActivityLapType[];
|
|
57
|
+
}
|
|
58
|
+
export interface ActivityRecordType extends RecordMesgType {
|
|
59
|
+
lapIndex: number;
|
|
60
|
+
index: number;
|
|
61
|
+
hdop?: number;
|
|
62
|
+
vdop?: number;
|
|
63
|
+
pdop?: number;
|
|
64
|
+
turn?: number;
|
|
65
|
+
description?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ActivityLengthType extends LengthMesgType {
|
|
68
|
+
index: number;
|
|
69
|
+
}
|
|
70
|
+
export interface ActivityLapType extends LapMesgType {
|
|
71
|
+
index: number;
|
|
72
|
+
endTime?: Date;
|
|
73
|
+
records: ActivityRecordType[];
|
|
74
|
+
lengths: ActivityLengthType[];
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trackswap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "A powerful and flexible GPX parser and encoder library for Node.js and TypeScript. TrackSwap provides comprehensive support for GPX 1.1 format with advanced features like plugin system, middleware support, and optimized performance.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
10
11
|
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.cjs"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
"dev": "ts-node src/index.ts",
|
|
27
27
|
"clean": "rm -rf dist",
|
|
28
28
|
"build": "npm run clean && npm run build:types && npm run build:esm && npm run build:cjs && npm run build:optimize",
|
|
29
|
-
"build:types": "tsc
|
|
29
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
30
30
|
"build:esm": "NODE_ENV=production node build.config.js",
|
|
31
31
|
"build:cjs": "NODE_ENV=production FORMAT=cjs node build.config.js",
|
|
32
32
|
"build:dev": "npm run clean && npm run build:types && NODE_ENV=development node build.config.js",
|
|
33
33
|
"build:optimize": "node scripts/optimize-dist.js",
|
|
34
|
+
"verify:types": "node -e \"const fs=require('fs'); const files=['dist/index.d.ts','dist/TrackSwap.d.ts','dist/types.d.ts']; const missing=files.filter((f)=>!fs.existsSync(f)); if(missing.length){console.error('Missing type artifacts:', missing.join(', ')); process.exit(1);} console.log('Type artifacts verified');\"",
|
|
34
35
|
"build:js": "esbuild src/index.ts --bundle --platform=node --target=node14 --format=esm --outfile=dist/index.js --minify --sourcemap",
|
|
35
36
|
"build:tsc": "tsc && npm run minify",
|
|
36
37
|
"minify": "terser dist/**/*.js --compress --mangle --output dist/index.min.js --source-map",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"start": "node dist/index.js",
|
|
39
40
|
"test:gpx": "cd example/gpx && rm -f output* *.json *_encoded.xml && node test.js",
|
|
40
41
|
"test:fit": "cd example/FIT && rm -rf output && node test.js",
|
|
41
|
-
"prepublishOnly": "npm run build"
|
|
42
|
+
"prepublishOnly": "npm run build && npm run verify:types"
|
|
42
43
|
},
|
|
43
44
|
"keywords": [
|
|
44
45
|
"gpx",
|