@tmlmobilidade/interfaces 20260420.1828.16 → 20260423.1140.30

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.
@@ -68,7 +68,7 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
68
68
  * @param key The key to find distinct values for.
69
69
  * @returns A promise that resolves to an array of distinct values for the given key.
70
70
  */
71
- distinct<Key extends keyof WithId<T>>(key: Key, filter: Filter<T>): Promise<Array<Flatten<WithId<T>[Key]>>>;
71
+ distinct<Key extends keyof WithId<T>>(key: Key, filter?: Filter<T>): Promise<Array<Flatten<WithId<T>[Key]>>>;
72
72
  /**
73
73
  * Checks if a document with the given key and value exists in the collection.
74
74
  * @param key The key to check for existence.
@@ -107,8 +107,13 @@ export class MongoCollectionClass {
107
107
  async disconnect() {
108
108
  await this.mongoConnector.disconnect();
109
109
  }
110
- async distinct(key) {
111
- return this.mongoCollection.distinct(key);
110
+ /**
111
+ * Finds all distinct values for a key in the collection.
112
+ * @param key The key to find distinct values for.
113
+ * @returns A promise that resolves to an array of distinct values for the given key.
114
+ */
115
+ async distinct(key, filter) {
116
+ return this.mongoCollection.distinct(key, filter);
112
117
  }
113
118
  /**
114
119
  * Checks if a document with the given key and value exists in the collection.
@@ -62,6 +62,13 @@ declare class EventsClass extends MongoCollectionClass<Event, CreateEventDto, Up
62
62
  lines_to_include?: string[] | undefined;
63
63
  same_weekday?: boolean | undefined;
64
64
  })[];
65
+ associated_patterns: {
66
+ _id: string;
67
+ code: string;
68
+ line_id: string;
69
+ headsign: string;
70
+ route_id: string;
71
+ }[];
65
72
  updated_by?: string | undefined;
66
73
  }>[]>;
67
74
  protected getCollectionIndexes(): IndexDescription[];
@@ -69,6 +69,8 @@ declare class PatternsClass extends MongoCollectionClass<Pattern, CreatePatternD
69
69
  lines_to_include?: string[] | undefined;
70
70
  same_weekday?: boolean | undefined;
71
71
  })[];
72
+ headsign: string;
73
+ route_id: string;
72
74
  comments: ({
73
75
  created_at: number & {
74
76
  __brand: "UnixTimestamp";
@@ -115,8 +117,6 @@ declare class PatternsClass extends MongoCollectionClass<Pattern, CreatePatternD
115
117
  _id?: string | undefined;
116
118
  updated_by?: string | undefined;
117
119
  })[];
118
- headsign: string;
119
- route_id: string;
120
120
  destination: string;
121
121
  direction: "outbound" | "inbound";
122
122
  origin: string;
@@ -271,9 +271,13 @@ function routeTermToField(term) {
271
271
  if (/^\d+_\d+_\d+$/.test(term)) {
272
272
  return { pattern_id: term };
273
273
  }
274
- // Exact trip_id match: "1001_0_2_0800_0829_0_26"
275
- if (/^\d+_\d+_\d+_\d+_\d+_\d+_\d+$/.test(term)) {
276
- return { trip_id: term };
274
+ // Wildcard trip_id: any string containing %%; %% → regex .*
275
+ // NOTE: case-sensitive (no $options: 'i') so anchored prefix regex can use
276
+ // the { trip_id: 1 } / { trip_id: 1, start_time_scheduled: 1 } index.
277
+ if (term.includes('%%')) {
278
+ let escaped = term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
279
+ escaped = escaped.replace(/%%/g, '.*');
280
+ return { trip_id: { $regex: `^${escaped}$` } };
277
281
  }
278
282
  // route_id: "1001_0"
279
283
  if (/^\d+_\d+$/.test(term)) {
@@ -289,12 +293,6 @@ function routeTermToField(term) {
289
293
  const n = Number(term);
290
294
  if (term.length >= 3)
291
295
  return { line_id: n };
292
- if (term.length <= 2)
293
- return { agency_id: term };
294
- }
295
- // plan_id: uppercase alpha-numeric prefix like "KACZ2"
296
- if (/^[A-Z]+\d*$/.test(term)) {
297
- return { plan_id: term };
298
296
  }
299
297
  return null;
300
298
  }
@@ -331,10 +329,17 @@ function buildSearchPipeline(filter) {
331
329
  }
332
330
  }
333
331
  if (unroutableTerms.length > 0) {
334
- const pattern = unroutableTerms
335
- .map(k => `(?=.*${k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`)
336
- .join('') + '.*';
337
- conditions.push({ _id: { $options: 'i', $regex: pattern } });
332
+ // Anchor first term as prefix on trip_id so the query can use the
333
+ // { trip_id: 1, start_time_scheduled: 1 } compound index.
334
+ // Remaining terms become plain contains-regex (no index, but bounded
335
+ // by the prefix scan of the first term).
336
+ // NOTE: case-sensitive; adding $options: 'i' disables index usage.
337
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
338
+ const [firstTerm, ...restTerms] = unroutableTerms;
339
+ conditions.push({ trip_id: { $regex: `^${escape(firstTerm)}` } });
340
+ for (const rest of restTerms) {
341
+ conditions.push({ trip_id: { $regex: escape(rest) } });
342
+ }
338
343
  }
339
344
  if (conditions.length === 1) {
340
345
  pipeline.push({ $match: conditions[0] });
@@ -28,10 +28,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
28
28
  pattern_id: string;
29
29
  trip_id: string;
30
30
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
31
- driver_ids: string[];
32
31
  headsign: string;
33
- plan_id: string;
34
32
  route_id: string;
33
+ driver_ids: string[];
34
+ plan_id: string;
35
35
  vehicle_ids: number[];
36
36
  operational_date: string & {
37
37
  __brand: "OperationalDate";
@@ -177,10 +177,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
177
177
  pattern_id: string;
178
178
  trip_id: string;
179
179
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
180
- driver_ids: string[];
181
180
  headsign: string;
182
- plan_id: string;
183
181
  route_id: string;
182
+ driver_ids: string[];
183
+ plan_id: string;
184
184
  vehicle_ids: number[];
185
185
  operational_date: string & {
186
186
  __brand: "OperationalDate";
@@ -326,10 +326,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
326
326
  pattern_id: string;
327
327
  trip_id: string;
328
328
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
329
- driver_ids: string[];
330
329
  headsign: string;
331
- plan_id: string;
332
330
  route_id: string;
331
+ driver_ids: string[];
332
+ plan_id: string;
333
333
  vehicle_ids: number[];
334
334
  operational_date: string & {
335
335
  __brand: "OperationalDate";
@@ -475,10 +475,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
475
475
  pattern_id: string;
476
476
  trip_id: string;
477
477
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
478
- driver_ids: string[];
479
478
  headsign: string;
480
- plan_id: string;
481
479
  route_id: string;
480
+ driver_ids: string[];
481
+ plan_id: string;
482
482
  vehicle_ids: number[];
483
483
  operational_date: string & {
484
484
  __brand: "OperationalDate";
@@ -624,10 +624,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
624
624
  pattern_id: string;
625
625
  trip_id: string;
626
626
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
627
- driver_ids: string[];
628
627
  headsign: string;
629
- plan_id: string;
630
628
  route_id: string;
629
+ driver_ids: string[];
630
+ plan_id: string;
631
631
  vehicle_ids: number[];
632
632
  operational_date: string & {
633
633
  __brand: "OperationalDate";
@@ -773,10 +773,10 @@ declare class RidesClass extends MongoCollectionClass<Ride, CreateRideDto, Updat
773
773
  pattern_id: string;
774
774
  trip_id: string;
775
775
  seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
776
- driver_ids: string[];
777
776
  headsign: string;
778
- plan_id: string;
779
777
  route_id: string;
778
+ driver_ids: string[];
779
+ plan_id: string;
780
780
  vehicle_ids: number[];
781
781
  operational_date: string & {
782
782
  __brand: "OperationalDate";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20260420.1828.16",
3
+ "version": "20260423.1140.30",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"