trackswap 0.2.3 → 0.2.4

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.
Files changed (53) hide show
  1. package/README.md +20 -0
  2. package/dist/FIT/base.d.ts +30 -0
  3. package/dist/FIT/decoder.d.ts +48 -0
  4. package/dist/FIT/encoder.d.ts +96 -0
  5. package/dist/FIT/encoderCourse.d.ts +45 -0
  6. package/dist/FIT/encoderWorkout.d.ts +45 -0
  7. package/dist/FIT/health.d.ts +195 -7
  8. package/dist/FIT/index.d.ts +1 -1
  9. package/dist/FIT/mesg.d.ts +3 -0
  10. package/dist/FIT/middleware.d.ts +15 -0
  11. package/dist/FIT/plugins.d.ts +9 -0
  12. package/dist/FIT/processor.d.ts +24 -0
  13. package/dist/FIT/types/checksum_type.d.ts +6 -0
  14. package/dist/FIT/types/date_time_type.d.ts +3 -0
  15. package/dist/FIT/types/file.d.ts +63 -0
  16. package/dist/FIT/types/file_flags_type.d.ts +9 -0
  17. package/dist/FIT/types/local_date_time_type.d.ts +3 -0
  18. package/dist/FIT/types/mesg_count_type.d.ts +6 -0
  19. package/dist/FIT/types/mesg_num.d.ts +369 -0
  20. package/dist/FIT/types/message_index_type.d.ts +6591 -0
  21. package/dist/FIT/types/sport.d.ts +44 -44
  22. package/dist/FIT/types.d.ts +509 -0
  23. package/dist/GPX/base.d.ts +24 -0
  24. package/dist/GPX/converters.d.ts +44 -0
  25. package/dist/GPX/decoder.d.ts +66 -0
  26. package/dist/GPX/encoder.d.ts +109 -0
  27. package/dist/GPX/middleware.d.ts +9 -0
  28. package/dist/GPX/processor.d.ts +18 -0
  29. package/dist/GPX/types.d.ts +138 -0
  30. package/dist/TCX/base.d.ts +33 -0
  31. package/dist/TCX/converters.d.ts +33 -0
  32. package/dist/TCX/decoder.d.ts +54 -0
  33. package/dist/TCX/encoder.d.ts +116 -0
  34. package/dist/TCX/middleware.d.ts +12 -0
  35. package/dist/TCX/processor.d.ts +30 -0
  36. package/dist/TCX/types.d.ts +13 -0
  37. package/dist/TrackSwap.d.ts +4 -0
  38. package/dist/activity/base.d.ts +54 -0
  39. package/dist/activity/converters.d.ts +57 -0
  40. package/dist/activity/encoders.d.ts +34 -0
  41. package/dist/activity/metrics/MetricsCalculator.d.ts +30 -0
  42. package/dist/activity/processor.d.ts +31 -0
  43. package/dist/core/base.d.ts +46 -0
  44. package/dist/core/builtin-adapters.d.ts +1 -0
  45. package/dist/core/xml-utils.d.ts +24 -0
  46. package/dist/errors.d.ts +1 -1
  47. package/dist/fit-debug.d.ts +3 -0
  48. package/dist/index.cjs +4 -4
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +29 -29
  51. package/dist/types.d.ts +102 -1
  52. package/dist/util.d.ts +9 -0
  53. package/package.json +4 -3
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LapMesgType, LengthMesgType, RecordMesgType, SessionMesgType } from "./FIT/types.js";
1
+ import { LapMesgType, LengthMesgType, RecordMesgType, SetMesgType, SessionMesgType } from "./FIT/types.js";
2
2
  export interface Token {
3
3
  type: "open" | "close" | "text";
4
4
  tag: string;
@@ -14,19 +14,41 @@ export interface TokenAST {
14
14
  export interface AttributeType {
15
15
  [key: string]: string;
16
16
  }
17
+ /**
18
+ * The latitude of the point. Decimal degrees, WGS84 datum.
19
+ * @type {number} -90.0 <= value <= 90.0
20
+ */
17
21
  export type LatitudeType = number;
22
+ /**
23
+ * The longitude of the point. Decimal degrees, WGS84 datum.
24
+ * @type {number} -180.0 <= value < 180.0
25
+ */
18
26
  export type LongitudeType = number;
27
+ /**
28
+ * Used for bearing, heading, course. Units are decimal degrees, true (not magnetic).
29
+ * @type {number} 0.0 <= value < 360.0
30
+
31
+ */
19
32
  export type DegreesType = number;
20
33
  export interface ExtensionsType {
21
34
  [key: string]: string | number | undefined | ExtensionsType;
22
35
  }
36
+ /**
37
+ * Parse File Type
38
+ */
23
39
  export interface FileType {
24
40
  metadata?: {
25
41
  originType: "GPX" | "FIT" | "TCX" | "HIJSON";
26
42
  fileName?: string;
27
43
  fileType?: string;
28
44
  };
45
+ /**
46
+ * 描述 gpx points
47
+ */
29
48
  points?: ActivityRecordType[];
49
+ /**
50
+ * 描述 gpx routes、 tcx course
51
+ */
30
52
  routes?: ActivityLapType[];
31
53
  activities?: ActivityType[];
32
54
  userProfile?: UserProfileType;
@@ -50,28 +72,84 @@ export interface UserProfileType {
50
72
  elevSetting?: string;
51
73
  weightSetting?: string;
52
74
  }
75
+ /**
76
+ * Activity Type 直接继承自 FIT 的 session message,
77
+ *
78
+ * gpx -> trk
79
+ * fit -> session
80
+ * tcx -> Activity
81
+ * 对应 gpx 的 trk , fit 的 sessions, tcx 的 Activity
82
+ */
53
83
  export interface ActivityType extends SessionMesgType {
84
+ /**
85
+ * 活动索引
86
+ */
54
87
  index: number;
88
+ /**
89
+ * 结束时间
90
+ */
55
91
  endTime?: Date;
56
92
  laps?: ActivityLapType[];
93
+ /** Ordered strength-training active/rest phases for this activity. */
94
+ strengthSets?: ActivityStrengthSetType[];
95
+ /** GPX trk/name or an equivalent source activity title. */
57
96
  activityName?: string;
97
+ /** GPX trk/cmt. */
58
98
  comment?: string;
99
+ /** GPX trk/desc. */
59
100
  description?: string;
101
+ /** GPX trk/src. */
60
102
  source?: string;
103
+ /** GPX trk/link values. */
61
104
  links?: ActivityLinkType[];
105
+ /** GPX trk/number. */
62
106
  activityNumber?: number;
107
+ /** Original GPX trk/extensions payload. */
63
108
  gpxExtensions?: ExtensionsType;
64
109
  }
110
+ export interface ActivityStrengthExerciseType {
111
+ /** FIT exercise category, for example `deadlift` or `cardio`. */
112
+ category: string | number;
113
+ /** Raw category-specific FIT exercise-name enum value. */
114
+ categorySubtype?: number;
115
+ /** Stable Garmin FIT profile name, for example `straightLegDeadlift`. */
116
+ name?: string;
117
+ }
118
+ export interface ActivityStrengthSetType extends SetMesgType {
119
+ /** Stable zero-based order inside the activity. */
120
+ index: number;
121
+ /** Category/subtype pairs projected into portable exercise labels. */
122
+ exercises: ActivityStrengthExerciseType[];
123
+ }
65
124
  export interface ActivityLinkType {
66
125
  href?: string;
67
126
  text?: string;
68
127
  type?: string;
69
128
  }
129
+ /**
130
+ * Activity Record Type 直接继承自 FIT 的 record message,
131
+ * 将 其他文件类型的数据向 FIT 结构对齐
132
+ */
70
133
  export interface ActivityRecordType extends RecordMesgType {
134
+ /**
135
+ * lap 索引
136
+ */
71
137
  lapIndex: number;
138
+ /**
139
+ * 记录索引
140
+ */
72
141
  index: number;
142
+ /**
143
+ * Horizontal dilution of precision.
144
+ */
73
145
  hdop?: number;
146
+ /**
147
+ * Vertical dilution of precision.
148
+ */
74
149
  vdop?: number;
150
+ /**
151
+ * Position dilution of precision.
152
+ */
75
153
  pdop?: number;
76
154
  course?: number;
77
155
  magvar?: number;
@@ -87,22 +165,45 @@ export interface ActivityRecordType extends RecordMesgType {
87
165
  ageofdgpsdata?: number;
88
166
  dgpsid?: number;
89
167
  gpxExtensions?: ExtensionsType;
168
+ /**
169
+ * 转弯角度
170
+ */
90
171
  turn?: number;
172
+ /**
173
+ * 记录描述
174
+ */
91
175
  description?: string;
92
176
  }
93
177
  export interface ActivityLengthType extends LengthMesgType {
94
178
  index: number;
95
179
  }
180
+ /**
181
+ * Segments & fit(lap) & tcx(lap)
182
+ */
96
183
  export interface ActivityLapType extends LapMesgType {
184
+ /**
185
+ * 活动索引
186
+ */
97
187
  index: number;
188
+ /**
189
+ * 结束时间
190
+ */
98
191
  endTime?: Date;
192
+ /** TCX Course / GPX rte 等路线的展示名称(可选) */
99
193
  routeName?: string;
194
+ /** GPX rte/cmt. */
100
195
  comment?: string;
196
+ /** GPX rte/desc. */
101
197
  description?: string;
198
+ /** GPX rte/src. */
102
199
  source?: string;
200
+ /** GPX rte/link values. */
103
201
  links?: ActivityLinkType[];
202
+ /** GPX rte/number. */
104
203
  routeNumber?: number;
204
+ /** GPX rte/type. */
105
205
  routeType?: string;
206
+ /** Original GPX rte or trkseg extensions payload. */
106
207
  gpxExtensions?: ExtensionsType;
107
208
  records: ActivityRecordType[];
108
209
  lengths: ActivityLengthType[];
package/dist/util.d.ts CHANGED
@@ -20,6 +20,15 @@ export declare const convertGPXExtensionsMapping: {
20
20
  "gpxx:Temperature": string;
21
21
  "gpxx:Depth": string;
22
22
  };
23
+ /**
24
+ * Convert semicircles (FIT wire/SDK units, scale 1 in Garmin JS profile) to decimal degrees.
25
+ * @garmin/fitsdk decoder applies scale/offset per field; record position fields remain semicircles (units string), not pre-converted degrees.
26
+ */
23
27
  export declare const semicirclesToDegrees: (semicircles: number) => number;
28
+ /** FIT sint32 semicircle field: invalid when all bits set (Garmin profile). */
24
29
  export declare const FIT_SEMICIRCLE_INVALID_SINT32 = 2147483647;
30
+ /**
31
+ * Raw FIT semicircle from SDK (scale 1 "semicircles" units) → decimal degrees.
32
+ * Treats FIT invalid sentinel as absent. Preserves 0° (equator / prime meridian).
33
+ */
25
34
  export declare function normalizeFitSemicircleToDegrees(raw: unknown, precision?: number): number | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trackswap",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "A typed, adapter-based toolkit for decoding, normalizing and transcoding FIT, GPX and TCX data.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -42,10 +42,11 @@
42
42
  "test:fit-coords": "npm run build:dev && node scripts/verify-fit-coordinates.mjs",
43
43
  "test:tcx-course": "npm run build:dev && node scripts/tcx-course-smoke.mjs",
44
44
  "test:routes-fit": "npm run build:dev && node scripts/routes-only-fit-smoke.mjs",
45
- "test": "npm run test:architecture && npm run test:health && npm run test:garmin-parity",
45
+ "test": "npm run test:architecture && npm run test:health && npm run test:garmin-parity && npm run test:fit-structure",
46
46
  "test:architecture": "esbuild test/architecture.test.ts --bundle --platform=node --target=node18 --format=esm --outfile=/tmp/trackswap-architecture.test.mjs && node /tmp/trackswap-architecture.test.mjs",
47
47
  "test:health": "esbuild test/health-fit.test.ts --bundle --platform=node --target=node18 --format=esm --outfile=/tmp/trackswap-health-fit.test.mjs && node /tmp/trackswap-health-fit.test.mjs",
48
48
  "test:garmin-parity": "esbuild test/garmin-sdk-parity.test.ts --bundle --platform=node --target=node18 --format=esm --outfile=/tmp/trackswap-garmin-sdk-parity.test.mjs && node /tmp/trackswap-garmin-sdk-parity.test.mjs",
49
+ "test:fit-structure": "esbuild test/fit-structure.test.ts --bundle --platform=node --target=node18 --format=esm --outfile=/tmp/trackswap-fit-structure.test.mjs && node /tmp/trackswap-fit-structure.test.mjs",
49
50
  "test:package": "node scripts/verify-package.mjs",
50
51
  "prepublishOnly": "npm run build"
51
52
  },
@@ -86,7 +87,7 @@
86
87
  "typescript": "^5.8.3"
87
88
  },
88
89
  "dependencies": {
89
- "@garmin/fitsdk": "^21.195.0",
90
+ "@garmin/fitsdk": "21.212.0",
90
91
  "dayjs": "^1.11.13",
91
92
  "geolib": "^3.3.4",
92
93
  "htmlparser2": "^10.0.0"