@lcas58/esmi-api-types 1.0.11 → 1.0.13

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.
@@ -1,14 +1,22 @@
1
- import { and, eq } from "drizzle-orm";
1
+ import { and, eq, gte, inArray, lte } from "drizzle-orm";
2
2
  import * as HttpStatusCodes from "stoker/http-status-codes";
3
3
  import * as HttpStatusPhrases from "stoker/http-status-phrases";
4
4
  import { createDb } from "../../db/index.js";
5
- import { event } from "../../db/schema/index.js";
5
+ import { event, location } from "../../db/schema/index.js";
6
6
  export const list = async (c) => {
7
7
  const { db } = createDb(c.env);
8
8
  const query = c.req.valid("query");
9
9
  const { sportId, source } = query;
10
10
  const limit = query.limit ?? 20;
11
11
  const offset = query.offset ?? 0;
12
+ const city = query.city?.trim();
13
+ const state = query.state?.trim();
14
+ // Time window (default: now → +7 days)
15
+ const now = new Date();
16
+ const from = query.from ? new Date(query.from) : now;
17
+ const to = query.to
18
+ ? new Date(query.to)
19
+ : new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
12
20
  const whereConditions = [];
13
21
  if (sportId) {
14
22
  whereConditions.push(eq(event.sportId, sportId));
@@ -16,12 +24,37 @@ export const list = async (c) => {
16
24
  if (source) {
17
25
  whereConditions.push(eq(event.source, source));
18
26
  }
27
+ // Time filtering (recommended for feed relevance)
28
+ whereConditions.push(gte(event.startsAt, from));
29
+ whereConditions.push(lte(event.startsAt, to));
30
+ // City/state → locationIds → events
31
+ if (city && state) {
32
+ const locations = await db.query.location.findMany({
33
+ where: and(eq(location.city, city), eq(location.state, state)),
34
+ columns: { id: true },
35
+ limit: 1000,
36
+ });
37
+ if (locations.length === 0) {
38
+ return c.json([], HttpStatusCodes.OK);
39
+ }
40
+ const locationIds = locations.map((l) => l.id);
41
+ whereConditions.push(inArray(event.locationId, locationIds));
42
+ }
19
43
  const events = await db.query.event.findMany({
20
44
  where: whereConditions.length > 0 ? and(...whereConditions) : undefined,
21
45
  with: {
22
46
  sport: true,
23
47
  location: true,
24
48
  externalLink: true,
49
+ creator: {
50
+ columns: {
51
+ id: true,
52
+ name: true,
53
+ image: true,
54
+ homeCity: true,
55
+ homeState: true,
56
+ },
57
+ },
25
58
  },
26
59
  limit,
27
60
  offset,
@@ -38,6 +71,13 @@ export const getOne = async (c) => {
38
71
  sport: true,
39
72
  location: true,
40
73
  externalLink: true,
74
+ creator: {
75
+ columns: {
76
+ id: true,
77
+ name: true,
78
+ image: true,
79
+ },
80
+ },
41
81
  },
42
82
  });
43
83
  if (!foundEvent) {
@@ -4,7 +4,11 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
4
4
  input: {
5
5
  query: {
6
6
  sportId?: string | string[] | undefined;
7
+ city?: string | string[] | undefined;
8
+ state?: string | string[] | undefined;
7
9
  source?: string | string[] | undefined;
10
+ from?: string | string[] | undefined;
11
+ to?: string | string[] | undefined;
8
12
  limit?: string | string[] | undefined;
9
13
  offset?: string | string[] | undefined;
10
14
  };
@@ -37,6 +41,11 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
37
41
  source: "external" | "community";
38
42
  thumbnailUrl: string | null;
39
43
  createdByUserId: string | null;
44
+ creator: {
45
+ image: string | null;
46
+ id: string;
47
+ name: string;
48
+ } | null;
40
49
  externalLink: {
41
50
  url: string;
42
51
  id: string;
@@ -83,6 +92,11 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
83
92
  source: "external" | "community";
84
93
  thumbnailUrl: string | null;
85
94
  createdByUserId: string | null;
95
+ creator: {
96
+ image: string | null;
97
+ id: string;
98
+ name: string;
99
+ } | null;
86
100
  externalLink: {
87
101
  url: string;
88
102
  id: string;
@@ -7,16 +7,28 @@ export declare const list: {
7
7
  query: z.ZodObject<{
8
8
  sportId: z.ZodOptional<z.ZodString>;
9
9
  source: z.ZodOptional<z.ZodEnum<["external", "community"]>>;
10
+ city: z.ZodOptional<z.ZodString>;
11
+ state: z.ZodOptional<z.ZodString>;
12
+ from: z.ZodOptional<z.ZodDate>;
13
+ to: z.ZodOptional<z.ZodDate>;
10
14
  limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
11
15
  offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
12
16
  }, "strip", z.ZodTypeAny, {
13
17
  sportId?: string | undefined;
18
+ city?: string | undefined;
19
+ state?: string | undefined;
14
20
  source?: "external" | "community" | undefined;
21
+ from?: Date | undefined;
22
+ to?: Date | undefined;
15
23
  limit?: number | undefined;
16
24
  offset?: number | undefined;
17
25
  }, {
18
26
  sportId?: string | undefined;
27
+ city?: string | undefined;
28
+ state?: string | undefined;
19
29
  source?: "external" | "community" | undefined;
30
+ from?: Date | undefined;
31
+ to?: Date | undefined;
20
32
  limit?: number | undefined;
21
33
  offset?: number | undefined;
22
34
  }>;
@@ -139,6 +151,19 @@ export declare const list: {
139
151
  id: string;
140
152
  domain: string;
141
153
  }>>;
154
+ creator: z.ZodNullable<z.ZodObject<{
155
+ id: z.ZodString;
156
+ name: z.ZodString;
157
+ image: z.ZodNullable<z.ZodString>;
158
+ }, "strip", z.ZodTypeAny, {
159
+ image: string | null;
160
+ id: string;
161
+ name: string;
162
+ }, {
163
+ image: string | null;
164
+ id: string;
165
+ name: string;
166
+ }>>;
142
167
  }>, z.UnknownKeysParam, z.ZodTypeAny, {
143
168
  metadata: string | number | boolean | {
144
169
  [key: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -191,6 +216,11 @@ export declare const list: {
191
216
  source: "external" | "community";
192
217
  thumbnailUrl: string | null;
193
218
  createdByUserId: string | null;
219
+ creator: {
220
+ image: string | null;
221
+ id: string;
222
+ name: string;
223
+ } | null;
194
224
  externalLink: {
195
225
  url: string;
196
226
  id: string;
@@ -248,6 +278,11 @@ export declare const list: {
248
278
  source: "external" | "community";
249
279
  thumbnailUrl: string | null;
250
280
  createdByUserId: string | null;
281
+ creator: {
282
+ image: string | null;
283
+ id: string;
284
+ name: string;
285
+ } | null;
251
286
  externalLink: {
252
287
  url: string;
253
288
  id: string;
@@ -393,6 +428,19 @@ export declare const getOne: {
393
428
  id: string;
394
429
  domain: string;
395
430
  }>>;
431
+ creator: z.ZodNullable<z.ZodObject<{
432
+ id: z.ZodString;
433
+ name: z.ZodString;
434
+ image: z.ZodNullable<z.ZodString>;
435
+ }, "strip", z.ZodTypeAny, {
436
+ image: string | null;
437
+ id: string;
438
+ name: string;
439
+ }, {
440
+ image: string | null;
441
+ id: string;
442
+ name: string;
443
+ }>>;
396
444
  }>, z.UnknownKeysParam, z.ZodTypeAny, {
397
445
  metadata: string | number | boolean | {
398
446
  [key: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -445,6 +493,11 @@ export declare const getOne: {
445
493
  source: "external" | "community";
446
494
  thumbnailUrl: string | null;
447
495
  createdByUserId: string | null;
496
+ creator: {
497
+ image: string | null;
498
+ id: string;
499
+ name: string;
500
+ } | null;
448
501
  externalLink: {
449
502
  url: string;
450
503
  id: string;
@@ -502,6 +555,11 @@ export declare const getOne: {
502
555
  source: "external" | "community";
503
556
  thumbnailUrl: string | null;
504
557
  createdByUserId: string | null;
558
+ creator: {
559
+ image: string | null;
560
+ id: string;
561
+ name: string;
562
+ } | null;
505
563
  externalLink: {
506
564
  url: string;
507
565
  id: string;
@@ -113,6 +113,19 @@ export declare const eventWithRelationsSchema: z.ZodObject<z.objectUtil.extendSh
113
113
  id: string;
114
114
  domain: string;
115
115
  }>>;
116
+ creator: z.ZodNullable<z.ZodObject<{
117
+ id: z.ZodString;
118
+ name: z.ZodString;
119
+ image: z.ZodNullable<z.ZodString>;
120
+ }, "strip", z.ZodTypeAny, {
121
+ image: string | null;
122
+ id: string;
123
+ name: string;
124
+ }, {
125
+ image: string | null;
126
+ id: string;
127
+ name: string;
128
+ }>>;
116
129
  }>, z.UnknownKeysParam, z.ZodTypeAny, {
117
130
  metadata: string | number | boolean | {
118
131
  [key: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -165,6 +178,11 @@ export declare const eventWithRelationsSchema: z.ZodObject<z.objectUtil.extendSh
165
178
  source: "external" | "community";
166
179
  thumbnailUrl: string | null;
167
180
  createdByUserId: string | null;
181
+ creator: {
182
+ image: string | null;
183
+ id: string;
184
+ name: string;
185
+ } | null;
168
186
  externalLink: {
169
187
  url: string;
170
188
  id: string;
@@ -222,6 +240,11 @@ export declare const eventWithRelationsSchema: z.ZodObject<z.objectUtil.extendSh
222
240
  source: "external" | "community";
223
241
  thumbnailUrl: string | null;
224
242
  createdByUserId: string | null;
243
+ creator: {
244
+ image: string | null;
245
+ id: string;
246
+ name: string;
247
+ } | null;
225
248
  externalLink: {
226
249
  url: string;
227
250
  id: string;
@@ -231,16 +254,28 @@ export declare const eventWithRelationsSchema: z.ZodObject<z.objectUtil.extendSh
231
254
  export declare const listEventsQuerySchema: z.ZodObject<{
232
255
  sportId: z.ZodOptional<z.ZodString>;
233
256
  source: z.ZodOptional<z.ZodEnum<["external", "community"]>>;
257
+ city: z.ZodOptional<z.ZodString>;
258
+ state: z.ZodOptional<z.ZodString>;
259
+ from: z.ZodOptional<z.ZodDate>;
260
+ to: z.ZodOptional<z.ZodDate>;
234
261
  limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
235
262
  offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
236
263
  }, "strip", z.ZodTypeAny, {
237
264
  sportId?: string | undefined;
265
+ city?: string | undefined;
266
+ state?: string | undefined;
238
267
  source?: "external" | "community" | undefined;
268
+ from?: Date | undefined;
269
+ to?: Date | undefined;
239
270
  limit?: number | undefined;
240
271
  offset?: number | undefined;
241
272
  }, {
242
273
  sportId?: string | undefined;
274
+ city?: string | undefined;
275
+ state?: string | undefined;
243
276
  source?: "external" | "community" | undefined;
277
+ from?: Date | undefined;
278
+ to?: Date | undefined;
244
279
  limit?: number | undefined;
245
280
  offset?: number | undefined;
246
281
  }>;
@@ -20,10 +20,19 @@ export const eventWithRelationsSchema = selectEventSchema.extend({
20
20
  url: z.string(),
21
21
  domain: z.string(),
22
22
  }).nullable(),
23
+ creator: z.object({
24
+ id: z.string(),
25
+ name: z.string(),
26
+ image: z.string().nullable(),
27
+ }).nullable(),
23
28
  });
24
29
  export const listEventsQuerySchema = z.object({
25
30
  sportId: z.string().optional(),
26
31
  source: z.enum(["external", "community"]).optional(),
32
+ city: z.string().optional(),
33
+ state: z.string().optional(),
34
+ from: z.coerce.date().optional(),
35
+ to: z.coerce.date().optional(),
27
36
  limit: z.coerce.number().min(1).max(100).default(20).optional(),
28
37
  offset: z.coerce.number().min(0).default(0).optional(),
29
38
  });
@@ -1 +1 @@
1
- export { eventWithRelationsSchema, listEventsQuerySchema, type EventWithRelations, type ListEventsQuery, } from "./event.schemas.js";
1
+ export { type EventWithRelations, eventWithRelationsSchema, type ListEventsQuery, listEventsQuerySchema, } from "./event.schemas.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lcas58/esmi-api-types",
3
3
  "type": "module",
4
- "version": "1.0.11",
4
+ "version": "1.0.13",
5
5
  "license": "MIT",
6
6
  "exports": {
7
7
  ".": {