trackswap 0.0.27 → 0.2.1
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/course-plan.d.ts +3 -0
- package/dist/FIT/decoder.d.ts +0 -2
- package/dist/FIT/health.d.ts +121 -0
- package/dist/FIT/index.d.ts +2 -0
- package/dist/FIT/types.d.ts +6 -1
- package/dist/GPX/types.d.ts +1 -1
- package/dist/TCX/encoder.d.ts +5 -0
- package/dist/TCX/types.d.ts +2 -1
- package/dist/TrackSwap.d.ts +13 -50
- package/dist/activity/converters.d.ts +4 -0
- package/dist/activity/encoders.d.ts +5 -1
- 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/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 +8 -7
- package/dist/index.js +29 -26
- package/dist/types.d.ts +35 -1
- package/dist/util.d.ts +25 -0
- package/package.json +17 -9
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { BaseFITStructurePlugin } from "./base.js";
|
|
2
|
+
import type { FITContext } from "./types.js";
|
|
3
|
+
export type FITPrimaryKind = 'activity' | 'health' | 'workout' | 'course' | 'device' | 'unknown';
|
|
4
|
+
export type HealthMetricCode = 'heart_rate_bpm' | 'resting_heart_rate_bpm' | 'resting_heart_rate_7_day_bpm' | 'steps' | 'distance_m' | 'active_time_s' | 'active_energy_kcal' | 'total_energy_kcal' | 'stress_level' | 'respiration_rate_bpm' | 'spo2_percent' | 'body_battery_level' | 'body_battery_charged' | 'body_battery_drained' | 'hrv_rmssd_ms' | 'temperature_c' | 'skin_temperature_deviation_c' | 'skin_temperature_7_day_deviation_c' | 'skin_temperature_nightly_c' | 'ascent_m' | 'descent_m' | `vendor:${string}`;
|
|
5
|
+
export type HealthValueStatus = 'valid' | 'invalid' | 'off_wrist' | 'motion' | 'low_confidence' | 'gap' | 'unknown';
|
|
6
|
+
export type HealthMessagePointerV1 = {
|
|
7
|
+
messageName: string;
|
|
8
|
+
messageIndex: number;
|
|
9
|
+
fieldName?: string;
|
|
10
|
+
developerField?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type HealthPointV1 = {
|
|
13
|
+
metric: HealthMetricCode;
|
|
14
|
+
timestamp: Date;
|
|
15
|
+
localTimestamp?: string;
|
|
16
|
+
offsetSeconds?: number;
|
|
17
|
+
value?: number;
|
|
18
|
+
unit: string;
|
|
19
|
+
status: HealthValueStatus;
|
|
20
|
+
quality?: number;
|
|
21
|
+
aggregation?: 'instant' | 'mean' | 'min' | 'max' | 'sum' | 'latest';
|
|
22
|
+
source: HealthMessagePointerV1;
|
|
23
|
+
attributes?: Record<string, string | number | boolean | null>;
|
|
24
|
+
};
|
|
25
|
+
export type HealthIntervalV1 = {
|
|
26
|
+
metric: HealthMetricCode;
|
|
27
|
+
startTime: Date;
|
|
28
|
+
endTime: Date;
|
|
29
|
+
localStartTime?: string;
|
|
30
|
+
offsetSeconds?: number;
|
|
31
|
+
value?: number;
|
|
32
|
+
unit: string;
|
|
33
|
+
status: HealthValueStatus;
|
|
34
|
+
activityType?: string;
|
|
35
|
+
intensity?: string;
|
|
36
|
+
source: HealthMessagePointerV1;
|
|
37
|
+
attributes?: Record<string, string | number | boolean | null>;
|
|
38
|
+
};
|
|
39
|
+
export type HealthSummaryV1 = {
|
|
40
|
+
summaryType: 'daily' | 'sleep' | 'hrv_status' | 'monitoring_window' | 'device';
|
|
41
|
+
externalId: string;
|
|
42
|
+
calendarDate?: string;
|
|
43
|
+
startTime?: Date;
|
|
44
|
+
endTime?: Date;
|
|
45
|
+
offsetSeconds?: number;
|
|
46
|
+
metrics: Record<string, number | string | boolean | null>;
|
|
47
|
+
source: HealthMessagePointerV1;
|
|
48
|
+
};
|
|
49
|
+
export type HealthSessionSegmentV1 = {
|
|
50
|
+
segmentType: 'awake' | 'light' | 'deep' | 'rem' | 'unmeasurable' | 'sleeping' | `vendor:${string}`;
|
|
51
|
+
startTime: Date;
|
|
52
|
+
endTime: Date;
|
|
53
|
+
status: HealthValueStatus;
|
|
54
|
+
source: HealthMessagePointerV1;
|
|
55
|
+
};
|
|
56
|
+
export type HealthSessionV1 = {
|
|
57
|
+
sessionType: 'sleep' | 'nap' | 'health_snapshot' | `vendor:${string}`;
|
|
58
|
+
externalId: string;
|
|
59
|
+
startTime: Date;
|
|
60
|
+
endTime: Date;
|
|
61
|
+
startOffsetSeconds?: number;
|
|
62
|
+
endOffsetSeconds?: number;
|
|
63
|
+
calendarDate?: string;
|
|
64
|
+
deleted?: boolean;
|
|
65
|
+
segments: HealthSessionSegmentV1[];
|
|
66
|
+
metrics: Record<string, number | string | boolean | null>;
|
|
67
|
+
source: HealthMessagePointerV1;
|
|
68
|
+
attributes?: Record<string, string | number | boolean | null>;
|
|
69
|
+
};
|
|
70
|
+
export type FITDiagnosticWarningV1 = {
|
|
71
|
+
code: string;
|
|
72
|
+
message: string;
|
|
73
|
+
source?: HealthMessagePointerV1;
|
|
74
|
+
};
|
|
75
|
+
export type FITDiagnosticsV1 = {
|
|
76
|
+
sdkProfileVersion?: string;
|
|
77
|
+
parserVersion: string;
|
|
78
|
+
messageCounts: Record<string, number>;
|
|
79
|
+
recognizedMessageCounts: Record<string, number>;
|
|
80
|
+
unknownMessageCounts: Record<string, number>;
|
|
81
|
+
invalidValueCounts: Record<string, number>;
|
|
82
|
+
warnings: FITDiagnosticWarningV1[];
|
|
83
|
+
unknownMessages?: Record<string, unknown[]>;
|
|
84
|
+
};
|
|
85
|
+
export type HealthDocumentV1 = {
|
|
86
|
+
schemaVersion: '1';
|
|
87
|
+
observedStart?: Date;
|
|
88
|
+
observedEnd?: Date;
|
|
89
|
+
timezone: {
|
|
90
|
+
strategy: 'explicit_offset' | 'timestamp_correlation' | 'inferred' | 'unknown';
|
|
91
|
+
offsets: Array<{
|
|
92
|
+
at: Date;
|
|
93
|
+
offsetSeconds: number;
|
|
94
|
+
}>;
|
|
95
|
+
};
|
|
96
|
+
points: HealthPointV1[];
|
|
97
|
+
intervals: HealthIntervalV1[];
|
|
98
|
+
summaries: HealthSummaryV1[];
|
|
99
|
+
sessions: HealthSessionV1[];
|
|
100
|
+
diagnostics: FITDiagnosticsV1;
|
|
101
|
+
};
|
|
102
|
+
export type FITDocumentParseOptions = {
|
|
103
|
+
includeUnknownMessages?: boolean;
|
|
104
|
+
includeDeveloperFields?: boolean;
|
|
105
|
+
strict?: boolean;
|
|
106
|
+
health?: {
|
|
107
|
+
reconstructIntervals?: boolean;
|
|
108
|
+
retainCumulativeValues?: boolean;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export type FITMessages = Record<string, unknown[] | undefined>;
|
|
112
|
+
export declare const TRACKSWAP_HEALTH_PARSER_VERSION = "trackswap-0.2.0-health-ir-v1";
|
|
113
|
+
export declare function detectFITKinds(messages: FITMessages): FITPrimaryKind[];
|
|
114
|
+
export declare function buildHealthDocumentFromMessages(messages: FITMessages, options?: FITDocumentParseOptions, environment?: {
|
|
115
|
+
sdkProfileVersion?: string;
|
|
116
|
+
}): HealthDocumentV1;
|
|
117
|
+
export declare class HealthStructurePlugin extends BaseFITStructurePlugin {
|
|
118
|
+
name: string;
|
|
119
|
+
priority: number;
|
|
120
|
+
structureData(messages: FITMessages, context: FITContext): Partial<import("./types.js").FITFileType>;
|
|
121
|
+
}
|
package/dist/FIT/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { FITDecoder } from "./decoder.js";
|
|
|
2
2
|
export { FITEncoder } from "./encoder.js";
|
|
3
3
|
export { IFITMessageConverter, IFITStructurePlugin, IFITMiddlewarePlugin, BaseFITMessageConverter, BaseFITStructurePlugin, BaseFITMiddleware, } from "./base.js";
|
|
4
4
|
export { SessionStructurePlugin, CourseStructurePlugin, FileHeaderPlugin, } from "./plugins.js";
|
|
5
|
+
export { HealthStructurePlugin, buildHealthDocumentFromMessages, detectFITKinds, TRACKSWAP_HEALTH_PARSER_VERSION, } from "./health.js";
|
|
6
|
+
export type { FITDocumentParseOptions, FITPrimaryKind, FITDiagnosticsV1, HealthDocumentV1, HealthIntervalV1, HealthMetricCode, HealthPointV1, HealthSessionSegmentV1, HealthSessionV1, HealthSummaryV1, HealthValueStatus, } from "./health.js";
|
|
5
7
|
export * from "./types.js";
|
|
6
8
|
export { encodeCourse, buildCourseMesgs, type CoursePlan, type CourseRecordPoint, type CourseCuePoint, type FitMesg as CourseFitMesg, } from "./encoderCourse.js";
|
|
7
9
|
import { FITDecoder } from "./decoder.js";
|
package/dist/FIT/types.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface FITFileType {
|
|
|
8
8
|
userProfileMesgs?: UserProfileMesgType[];
|
|
9
9
|
sessionMesgs?: SessionMesgType[];
|
|
10
10
|
courseMesgs?: any[];
|
|
11
|
+
healthDocument?: import("./health.js").HealthDocumentV1;
|
|
12
|
+
fitDocumentMetadata?: {
|
|
13
|
+
detectedKinds: import("./health.js").FITPrimaryKind[];
|
|
14
|
+
messageCounts: Record<string, number>;
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
export type FITDecoderMesgs = {
|
|
13
18
|
fileIdMesgs?: FileIdMesgType[];
|
|
@@ -243,7 +248,7 @@ export interface SessionMesgType {
|
|
|
243
248
|
lapMesgs?: LapMesgType[];
|
|
244
249
|
}
|
|
245
250
|
export interface RecordMesgType {
|
|
246
|
-
timestamp
|
|
251
|
+
timestamp?: Date;
|
|
247
252
|
positionLat?: number;
|
|
248
253
|
positionLong?: number;
|
|
249
254
|
altitude?: number;
|
package/dist/GPX/types.d.ts
CHANGED
package/dist/TCX/encoder.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare class TCXEncoder {
|
|
|
18
18
|
private buildActivityLap;
|
|
19
19
|
private buildTrack;
|
|
20
20
|
private buildTrackpoint;
|
|
21
|
+
private buildGeoCoords;
|
|
22
|
+
private wrapGeoTag;
|
|
21
23
|
private buildPosition;
|
|
22
24
|
private buildCadence;
|
|
23
25
|
private buildMultiActivitySession;
|
|
@@ -25,6 +27,9 @@ export declare class TCXEncoder {
|
|
|
25
27
|
private buildNextActivity;
|
|
26
28
|
private buildWorkouts;
|
|
27
29
|
private buildCourses;
|
|
30
|
+
private buildCourseElement;
|
|
31
|
+
private buildCourseLap;
|
|
32
|
+
private buildCoursePoint;
|
|
28
33
|
private buildAuthor;
|
|
29
34
|
private buildExtensions;
|
|
30
35
|
private buildExtensionContent;
|
package/dist/TCX/types.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export interface ActivityListType {
|
|
|
97
97
|
MultiActivitySession?: MultiActivitySessionType[];
|
|
98
98
|
}
|
|
99
99
|
export interface ActivityType {
|
|
100
|
-
|
|
100
|
+
Sport?: "Other" | "Running" | "Biking";
|
|
101
101
|
Id: string;
|
|
102
102
|
Lap: ActivityLapType[];
|
|
103
103
|
Notes?: string;
|
|
@@ -121,6 +121,7 @@ export interface PlanType {
|
|
|
121
121
|
IntervalWorkout: boolean;
|
|
122
122
|
}
|
|
123
123
|
export interface ActivityLapType {
|
|
124
|
+
StartTime?: string;
|
|
124
125
|
TotalTimeSeconds?: number;
|
|
125
126
|
DistanceMeters?: number;
|
|
126
127
|
MaximumSpeed?: number;
|
package/dist/TrackSwap.d.ts
CHANGED
|
@@ -1,53 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
1
|
+
import type { CourseEncodeOptions, DecodeOptions, EncodeOptions, TrackDocument, TrackFormat, TrackInput, TrackSwapOptions, TranscodeOptions } from "./document.js";
|
|
2
|
+
import type { FileType } from "./types.js";
|
|
9
3
|
export declare class TrackSwap {
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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>;
|
|
4
|
+
private readonly registry;
|
|
5
|
+
private disposed;
|
|
6
|
+
constructor(options?: TrackSwapOptions);
|
|
7
|
+
detect(input: TrackInput): TrackFormat;
|
|
8
|
+
decode<TNative = unknown>(input: TrackInput, options?: DecodeOptions): Promise<TrackDocument<TNative>>;
|
|
9
|
+
decodeActivity(input: TrackInput, options?: DecodeOptions): Promise<FileType>;
|
|
10
|
+
encodeActivity(activity: FileType, options: EncodeOptions): Promise<Buffer>;
|
|
11
|
+
transcode(input: TrackInput, options: TranscodeOptions): Promise<Buffer>;
|
|
12
|
+
encodeCourse(source: TrackInput | FileType, options?: CourseEncodeOptions): Promise<Buffer>;
|
|
13
|
+
dispose(): Promise<void>;
|
|
14
|
+
private assertActive;
|
|
52
15
|
}
|
|
53
16
|
export default TrackSwap;
|
|
@@ -12,6 +12,8 @@ export declare class GPXToActivityConverter extends BaseActivityConverter {
|
|
|
12
12
|
protected convertPoint(point: WptType, idx?: number, lapIdx?: number): ActivityRecordType;
|
|
13
13
|
private convertTrk2Activity;
|
|
14
14
|
private convertTrackSeg2Lap;
|
|
15
|
+
private convertRoute2Lap;
|
|
16
|
+
private convertPoints2Lap;
|
|
15
17
|
private convertWpts2Points;
|
|
16
18
|
private convertGPXExtensions;
|
|
17
19
|
private autoNumber;
|
|
@@ -30,6 +32,8 @@ export declare class TCXToActivityConverter extends BaseActivityConverter {
|
|
|
30
32
|
supportedTags: string[];
|
|
31
33
|
convert(ast: TokenAST, context: ActivityContext): FileType | undefined;
|
|
32
34
|
private convertTCX;
|
|
35
|
+
private convertTCXCourseToRoute;
|
|
36
|
+
private convertTCXCoursePointToRecord;
|
|
33
37
|
private convertTCXActivityToActivity;
|
|
34
38
|
private convertTCXLap2Lap;
|
|
35
39
|
protected convertPoint(point: TrackpointType, idx?: number, lapIdx?: number): ActivityRecordType;
|
|
@@ -7,6 +7,8 @@ export declare class ActivityToGPXEncoder extends BaseActivityEncoder {
|
|
|
7
7
|
name: string;
|
|
8
8
|
supportedTags: string[];
|
|
9
9
|
encode(file: FileType, context: ActivityEncodingContext): GPX11Type | undefined;
|
|
10
|
+
private hasValidGpxCoordinates;
|
|
11
|
+
private countRecordsMissingGpxCoordinates;
|
|
10
12
|
private convertRecords2Wpts;
|
|
11
13
|
private convertRoute2GPXRoute;
|
|
12
14
|
private convertActivity2GPXTrack;
|
|
@@ -16,6 +18,7 @@ export declare class ActivityToFITEncoder extends BaseActivityEncoder {
|
|
|
16
18
|
name: string;
|
|
17
19
|
supportedTags: string[];
|
|
18
20
|
encode(file: FileType, context: ActivityEncodingContext): FITFileType | undefined;
|
|
21
|
+
private convertRoutesToSyntheticSession;
|
|
19
22
|
private convertActivity2FITSession;
|
|
20
23
|
private convertLap2FITLap;
|
|
21
24
|
private convertPoint2FITRecord;
|
|
@@ -28,5 +31,6 @@ export declare class ActivityToTCXEncoder extends BaseActivityEncoder {
|
|
|
28
31
|
private convertLap2TCXLap;
|
|
29
32
|
private convertRecords2TCXTrack;
|
|
30
33
|
private convertPoint2TCXTrackpoint;
|
|
31
|
-
private
|
|
34
|
+
private validTimestamp;
|
|
35
|
+
private convertRouteToTCXCourse;
|
|
32
36
|
}
|
|
@@ -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,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;
|