trackswap 0.0.26 → 0.2.0
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/README.md +124 -431
- package/dist/FIT/base.d.ts +61 -0
- package/dist/FIT/course-plan.d.ts +3 -0
- package/dist/FIT/crc.d.ts +1 -0
- package/dist/FIT/decoder.d.ts +33 -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/health.d.ts +121 -0
- package/dist/FIT/index.d.ts +15 -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 +516 -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 +46 -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 +192 -0
- package/dist/TrackSwap.d.ts +16 -0
- package/dist/activity/base.d.ts +62 -0
- package/dist/activity/converters.d.ts +40 -0
- package/dist/activity/encoders.d.ts +36 -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/builtin-adapters.d.ts +52 -0
- package/dist/core/format-adapter.d.ts +23 -0
- package/dist/core/format-registry.d.ts +9 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/xml-utils.d.ts +17 -0
- package/dist/document.d.ts +57 -0
- package/dist/errors.d.ts +12 -0
- package/dist/fit-debug.d.ts +3 -0
- package/dist/index.cjs +29 -26
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -17
- package/dist/types.d.ts +76 -0
- package/dist/util.d.ts +25 -0
- package/package.json +15 -6
|
@@ -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,40 @@
|
|
|
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 convertRoute2Lap;
|
|
16
|
+
private convertPoints2Lap;
|
|
17
|
+
private convertWpts2Points;
|
|
18
|
+
private convertGPXExtensions;
|
|
19
|
+
private autoNumber;
|
|
20
|
+
}
|
|
21
|
+
export declare class FITToActivityConverter extends BaseActivityConverter {
|
|
22
|
+
name: string;
|
|
23
|
+
supportedTags: string[];
|
|
24
|
+
convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
|
|
25
|
+
private convertFIT;
|
|
26
|
+
protected convertPoint(point: RecordMesgType, idx?: number, lapIdx?: number): ActivityRecordType | undefined;
|
|
27
|
+
private convertFITLap2Trackseg;
|
|
28
|
+
private convertLap2Points;
|
|
29
|
+
}
|
|
30
|
+
export declare class TCXToActivityConverter extends BaseActivityConverter {
|
|
31
|
+
name: string;
|
|
32
|
+
supportedTags: string[];
|
|
33
|
+
convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
|
|
34
|
+
private convertTCX;
|
|
35
|
+
private convertTCXCourseToRoute;
|
|
36
|
+
private convertTCXCoursePointToRecord;
|
|
37
|
+
private convertTCXActivityToActivity;
|
|
38
|
+
private convertTCXLap2Lap;
|
|
39
|
+
protected convertPoint(point: TrackpointType, idx?: number, lapIdx?: number): ActivityRecordType;
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 hasValidGpxCoordinates;
|
|
11
|
+
private countRecordsMissingGpxCoordinates;
|
|
12
|
+
private convertRecords2Wpts;
|
|
13
|
+
private convertRoute2GPXRoute;
|
|
14
|
+
private convertActivity2GPXTrack;
|
|
15
|
+
private extractGPXExtensions;
|
|
16
|
+
}
|
|
17
|
+
export declare class ActivityToFITEncoder extends BaseActivityEncoder {
|
|
18
|
+
name: string;
|
|
19
|
+
supportedTags: string[];
|
|
20
|
+
encode(file: FileType, context: ActivityEncodingContext): FITFileType | undefined;
|
|
21
|
+
private convertRoutesToSyntheticSession;
|
|
22
|
+
private convertActivity2FITSession;
|
|
23
|
+
private convertLap2FITLap;
|
|
24
|
+
private convertPoint2FITRecord;
|
|
25
|
+
}
|
|
26
|
+
export declare class ActivityToTCXEncoder extends BaseActivityEncoder {
|
|
27
|
+
name: string;
|
|
28
|
+
supportedTags: string[];
|
|
29
|
+
encode(file: FileType, context: ActivityEncodingContext): TCXFileType | undefined;
|
|
30
|
+
private convertActivity2TCXActivity;
|
|
31
|
+
private convertLap2TCXLap;
|
|
32
|
+
private convertRecords2TCXTrack;
|
|
33
|
+
private convertPoint2TCXTrackpoint;
|
|
34
|
+
private validTimestamp;
|
|
35
|
+
private convertRouteToTCXCourse;
|
|
36
|
+
}
|
|
@@ -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,52 @@
|
|
|
1
|
+
import type { FITFileType } from "../FIT/types.js";
|
|
2
|
+
import type { GPX11Type } from "../GPX/types.js";
|
|
3
|
+
import type { TCXFileType } from "../TCX/types.js";
|
|
4
|
+
import { ActivityProcessor } from "../activity/processor.js";
|
|
5
|
+
import type { AdapterDecodeResult, FITCourseAdapter, TrackFormatAdapter } from "./format-adapter.js";
|
|
6
|
+
import type { DecodeOptions, TrackFormat } from "../document.js";
|
|
7
|
+
import type { FileType } from "../types.js";
|
|
8
|
+
export declare function detectBuiltInFormat(input: Buffer): TrackFormat | undefined;
|
|
9
|
+
declare abstract class BuiltInAdapter<TNative> implements TrackFormatAdapter<TNative> {
|
|
10
|
+
abstract readonly format: TrackFormat;
|
|
11
|
+
protected readonly activities: ActivityProcessor;
|
|
12
|
+
constructor(activities: ActivityProcessor);
|
|
13
|
+
matches(input: Buffer): boolean;
|
|
14
|
+
abstract decode(input: Buffer, options: DecodeOptions): Promise<AdapterDecodeResult<TNative>>;
|
|
15
|
+
abstract encodeActivity(activity: FileType): Promise<Buffer>;
|
|
16
|
+
}
|
|
17
|
+
export declare class FITAdapter extends BuiltInAdapter<FITFileType> implements FITCourseAdapter {
|
|
18
|
+
readonly format: "fit";
|
|
19
|
+
private decoder?;
|
|
20
|
+
private encoder?;
|
|
21
|
+
private getDecoder;
|
|
22
|
+
private getEncoder;
|
|
23
|
+
decode(input: Buffer, options: DecodeOptions): Promise<AdapterDecodeResult<FITFileType>>;
|
|
24
|
+
encodeActivity(activity: FileType): Promise<Buffer>;
|
|
25
|
+
encodeCourse(activity: FileType): Promise<Buffer>;
|
|
26
|
+
dispose(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare class GPXAdapter extends BuiltInAdapter<GPX11Type> {
|
|
29
|
+
readonly format: "gpx";
|
|
30
|
+
private decoder?;
|
|
31
|
+
private encoder?;
|
|
32
|
+
private getDecoder;
|
|
33
|
+
private getEncoder;
|
|
34
|
+
decode(input: Buffer): Promise<AdapterDecodeResult<GPX11Type>>;
|
|
35
|
+
encodeActivity(activity: FileType): Promise<Buffer>;
|
|
36
|
+
dispose(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare class TCXAdapter extends BuiltInAdapter<TCXFileType> {
|
|
39
|
+
readonly format: "tcx";
|
|
40
|
+
private decoder?;
|
|
41
|
+
private encoder?;
|
|
42
|
+
private getDecoder;
|
|
43
|
+
private getEncoder;
|
|
44
|
+
decode(input: Buffer): Promise<AdapterDecodeResult<TCXFileType>>;
|
|
45
|
+
encodeActivity(activity: FileType): Promise<Buffer>;
|
|
46
|
+
dispose(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createBuiltInAdapters(): {
|
|
49
|
+
adapters: TrackFormatAdapter[];
|
|
50
|
+
activities: ActivityProcessor;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DecodeOptions, TrackDocumentFacets, TrackDocumentKind, TrackDocumentMetadata, TrackFormat } from "../document.js";
|
|
2
|
+
import type { FITDiagnosticsV1 } from "../FIT/health.js";
|
|
3
|
+
import type { FileType } from "../types.js";
|
|
4
|
+
export interface AdapterDecodeResult<TNative = unknown> {
|
|
5
|
+
kinds: TrackDocumentKind[];
|
|
6
|
+
facets: TrackDocumentFacets;
|
|
7
|
+
metadata?: TrackDocumentMetadata;
|
|
8
|
+
native: TNative;
|
|
9
|
+
warnings?: string[];
|
|
10
|
+
fitDiagnostics?: FITDiagnosticsV1;
|
|
11
|
+
}
|
|
12
|
+
export interface TrackFormatAdapter<TNative = unknown> {
|
|
13
|
+
readonly format: TrackFormat;
|
|
14
|
+
matches(input: Buffer): boolean;
|
|
15
|
+
decode(input: Buffer, options: DecodeOptions): Promise<AdapterDecodeResult<TNative>>;
|
|
16
|
+
encodeActivity(activity: FileType): Promise<Buffer>;
|
|
17
|
+
dispose?(): Promise<void> | void;
|
|
18
|
+
}
|
|
19
|
+
export interface FITCourseAdapter extends TrackFormatAdapter {
|
|
20
|
+
readonly format: "fit";
|
|
21
|
+
encodeCourse(activity: FileType): Promise<Buffer>;
|
|
22
|
+
}
|
|
23
|
+
export declare function isFITCourseAdapter(adapter: TrackFormatAdapter): adapter is FITCourseAdapter;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TrackFormat } from "../document.js";
|
|
2
|
+
import type { TrackFormatAdapter } from "./format-adapter.js";
|
|
3
|
+
export declare class FormatRegistry {
|
|
4
|
+
private readonly adapters;
|
|
5
|
+
constructor(adapters: readonly TrackFormatAdapter[]);
|
|
6
|
+
get(format: TrackFormat): TrackFormatAdapter;
|
|
7
|
+
detect(input: Buffer): TrackFormat;
|
|
8
|
+
dispose(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { FITDiagnosticsV1, FITDocumentParseOptions, HealthDocumentV1 } from "./FIT/health.js";
|
|
2
|
+
import type { FileType } from "./types.js";
|
|
3
|
+
export type BuiltInTrackFormat = "fit" | "gpx" | "tcx";
|
|
4
|
+
export type TrackFormat = BuiltInTrackFormat | (string & {});
|
|
5
|
+
export type TrackDocumentKind = "activity" | "health" | "course" | "route" | "waypoint" | "workout" | "device" | "unknown" | (string & {});
|
|
6
|
+
export type TrackInput = Buffer | Uint8Array | string;
|
|
7
|
+
export interface DecodeOptions {
|
|
8
|
+
format?: TrackFormat;
|
|
9
|
+
includeNative?: boolean;
|
|
10
|
+
fit?: FITDocumentParseOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface EncodeOptions {
|
|
13
|
+
format: TrackFormat;
|
|
14
|
+
}
|
|
15
|
+
export interface TranscodeOptions extends EncodeOptions {
|
|
16
|
+
sourceFormat?: TrackFormat;
|
|
17
|
+
}
|
|
18
|
+
export interface CourseEncodeOptions {
|
|
19
|
+
sourceFormat?: TrackFormat;
|
|
20
|
+
}
|
|
21
|
+
export interface TrackSourceMetadata {
|
|
22
|
+
byteLength: number;
|
|
23
|
+
}
|
|
24
|
+
export interface TrackDocumentMetadata {
|
|
25
|
+
title?: string;
|
|
26
|
+
creator?: string;
|
|
27
|
+
createdAt?: Date;
|
|
28
|
+
fileType?: string | number;
|
|
29
|
+
manufacturer?: string | number;
|
|
30
|
+
product?: string | number;
|
|
31
|
+
productName?: string;
|
|
32
|
+
serialNumber?: string;
|
|
33
|
+
softwareVersion?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface TrackDocumentDiagnostics {
|
|
36
|
+
durationMs: number;
|
|
37
|
+
warnings: string[];
|
|
38
|
+
fit?: FITDiagnosticsV1;
|
|
39
|
+
}
|
|
40
|
+
export interface TrackDocumentFacets {
|
|
41
|
+
activity?: FileType;
|
|
42
|
+
health?: HealthDocumentV1;
|
|
43
|
+
}
|
|
44
|
+
export interface TrackDocument<TNative = unknown> {
|
|
45
|
+
schemaVersion: "2";
|
|
46
|
+
format: TrackFormat;
|
|
47
|
+
kinds: TrackDocumentKind[];
|
|
48
|
+
source: TrackSourceMetadata;
|
|
49
|
+
metadata: TrackDocumentMetadata;
|
|
50
|
+
facets: TrackDocumentFacets;
|
|
51
|
+
native?: TNative;
|
|
52
|
+
diagnostics: TrackDocumentDiagnostics;
|
|
53
|
+
}
|
|
54
|
+
export interface TrackSwapOptions {
|
|
55
|
+
adapters?: readonly import("./core/format-adapter.js").TrackFormatAdapter[];
|
|
56
|
+
includeBuiltInAdapters?: boolean;
|
|
57
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TrackFormat } from "./document.js";
|
|
2
|
+
export type TrackSwapErrorCode = "FORMAT_UNKNOWN" | "FORMAT_UNSUPPORTED" | "DECODE_FAILED" | "ACTIVITY_NOT_FOUND" | "ENCODE_FAILED" | "ADAPTER_CONFLICT" | "DISPOSED";
|
|
3
|
+
export declare class TrackSwapError extends Error {
|
|
4
|
+
readonly code: TrackSwapErrorCode;
|
|
5
|
+
readonly format?: TrackFormat;
|
|
6
|
+
readonly cause?: unknown;
|
|
7
|
+
constructor(code: TrackSwapErrorCode, message: string, options?: {
|
|
8
|
+
format?: TrackFormat;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export declare function asTrackSwapError(error: unknown, code: TrackSwapErrorCode, message: string, format?: TrackFormat): TrackSwapError;
|