@teardown/schemas 0.1.0 → 0.1.2

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,12 +1,12 @@
1
+ import { Type } from "@sinclair/typebox";
1
2
  import { DevicePlatformEnum } from "@teardown/types";
2
- import { t } from "elysia";
3
3
  /**
4
4
  * Device platform enum matching database
5
5
  */
6
6
  /**
7
7
  * Device platform
8
8
  */
9
- export const DevicePlatformSchema = t.Enum(DevicePlatformEnum, { error: "platform is required" });
9
+ export const DevicePlatformSchema = Type.Enum(DevicePlatformEnum, { error: "platform is required" });
10
10
  /**
11
11
  * Parse and validate a DevicePlatformEnum value
12
12
  * Uses a switch statement to ensure type safety and runtime validation
@@ -59,107 +59,107 @@ export function parseDevicePlatformEnum(value) {
59
59
  * Base device schema
60
60
  * Represents devices table structure
61
61
  */
62
- export const DeviceSchema = t.Object({
63
- id: t.String({ format: "uuid" }),
64
- persona_id: t.String({ format: "uuid" }),
65
- environment_id: t.Union([t.String({ format: "uuid" }), t.Null()]),
66
- device_id: t.String(),
67
- platform: t.Union([DevicePlatformSchema, t.Null()]),
68
- os_type: t.Union([t.String(), t.Null()]),
69
- os_name: t.Union([t.String(), t.Null()]),
70
- device_name: t.Union([t.String(), t.Null()]),
71
- device_brand: t.Union([t.String(), t.Null()]),
72
- metadata: t.Union([t.Record(t.String(), t.Unknown()), t.Null()]),
73
- created_at: t.String(),
74
- updated_at: t.String(),
62
+ export const DeviceSchema = Type.Object({
63
+ id: Type.String({ format: "uuid" }),
64
+ persona_id: Type.String({ format: "uuid" }),
65
+ environment_id: Type.Union([Type.String({ format: "uuid" }), Type.Null()]),
66
+ device_id: Type.String(),
67
+ platform: Type.Union([DevicePlatformSchema, Type.Null()]),
68
+ os_type: Type.Union([Type.String(), Type.Null()]),
69
+ os_name: Type.Union([Type.String(), Type.Null()]),
70
+ device_name: Type.Union([Type.String(), Type.Null()]),
71
+ device_brand: Type.Union([Type.String(), Type.Null()]),
72
+ metadata: Type.Union([Type.Record(Type.String(), Type.Unknown()), Type.Null()]),
73
+ created_at: Type.String(),
74
+ updated_at: Type.String(),
75
75
  });
76
76
  /**
77
77
  * Device params schema
78
78
  */
79
- export const DeviceParamsSchema = t.Object({
80
- device_id: t.String({ format: "uuid" }),
79
+ export const DeviceParamsSchema = Type.Object({
80
+ device_id: Type.String({ format: "uuid" }),
81
81
  });
82
82
  /**
83
83
  * Search devices query schema
84
84
  * Supports pagination, search, and sorting
85
85
  */
86
- export const SearchDevicesQuerySchema = t.Object({
87
- project_id: t.String({ format: "uuid" }),
88
- page: t.Numeric({ minimum: 1, default: 1 }),
89
- limit: t.Numeric({ minimum: 1, maximum: 100, default: 20 }),
90
- search: t.Optional(t.String()),
91
- sort_by: t.Union([
92
- t.Literal("created_at"),
93
- t.Literal("updated_at"),
94
- t.Literal("device_name"),
95
- t.Literal("platform"),
96
- t.Literal("os_name"),
86
+ export const SearchDevicesQuerySchema = Type.Object({
87
+ project_id: Type.String({ format: "uuid" }),
88
+ page: Type.Number({ minimum: 1, default: 1 }),
89
+ limit: Type.Number({ minimum: 1, maximum: 100, default: 20 }),
90
+ search: Type.Optional(Type.String()),
91
+ sort_by: Type.Union([
92
+ Type.Literal("created_at"),
93
+ Type.Literal("updated_at"),
94
+ Type.Literal("device_name"),
95
+ Type.Literal("platform"),
96
+ Type.Literal("os_name"),
97
97
  ], { default: "created_at" }),
98
- sort_order: t.Union([t.Literal("asc"), t.Literal("desc")], { default: "desc" }),
98
+ sort_order: Type.Union([Type.Literal("asc"), Type.Literal("desc")], { default: "desc" }),
99
99
  });
100
100
  /**
101
101
  * Search devices query schema without project_id (injected from headers)
102
102
  */
103
- export const SearchDevicesQueryParamsSchema = t.Omit(SearchDevicesQuerySchema, ["project_id"]);
103
+ export const SearchDevicesQueryParamsSchema = Type.Omit(SearchDevicesQuerySchema, ["project_id"]);
104
104
  /**
105
105
  * Devices by IDs request schema
106
106
  */
107
- export const DevicesByIdsSchema = t.Object({
108
- device_ids: t.Array(t.String({ format: "uuid" }), { minItems: 1, maxItems: 100 }),
107
+ export const DevicesByIdsSchema = Type.Object({
108
+ device_ids: Type.Array(Type.String({ format: "uuid" }), { minItems: 1, maxItems: 100 }),
109
109
  });
110
110
  /**
111
111
  * Paginated devices response schema
112
112
  */
113
- export const DevicesResponseSchema = t.Object({
114
- devices: t.Array(DeviceSchema),
115
- pagination: t.Object({
116
- page: t.Integer({ minimum: 1 }),
117
- limit: t.Integer({ minimum: 1 }),
118
- total: t.Integer({ minimum: 0 }),
119
- total_pages: t.Integer({ minimum: 0 }),
113
+ export const DevicesResponseSchema = Type.Object({
114
+ devices: Type.Array(DeviceSchema),
115
+ pagination: Type.Object({
116
+ page: Type.Integer({ minimum: 1 }),
117
+ limit: Type.Integer({ minimum: 1 }),
118
+ total: Type.Integer({ minimum: 0 }),
119
+ total_pages: Type.Integer({ minimum: 0 }),
120
120
  }),
121
121
  });
122
122
  /**
123
123
  * Single device response schema
124
124
  */
125
- export const DeviceResponseSchema = t.Object({
126
- success: t.Literal(true),
125
+ export const DeviceResponseSchema = Type.Object({
126
+ success: Type.Literal(true),
127
127
  data: DeviceSchema,
128
128
  });
129
129
  /**
130
130
  * Device error response schema
131
131
  * Discriminated union by error code
132
132
  */
133
- export const DeviceErrorSchema = t.Union([
134
- t.Object({
135
- code: t.Literal("DEVICE_NOT_FOUND"),
136
- message: t.String(),
133
+ export const DeviceErrorSchema = Type.Union([
134
+ Type.Object({
135
+ code: Type.Literal("DEVICE_NOT_FOUND"),
136
+ message: Type.String(),
137
137
  }),
138
- t.Object({
139
- code: t.Literal("PROJECT_NOT_FOUND"),
140
- message: t.String(),
138
+ Type.Object({
139
+ code: Type.Literal("PROJECT_NOT_FOUND"),
140
+ message: Type.String(),
141
141
  }),
142
- t.Object({
143
- code: t.Literal("FORBIDDEN"),
144
- message: t.String(),
142
+ Type.Object({
143
+ code: Type.Literal("FORBIDDEN"),
144
+ message: Type.String(),
145
145
  }),
146
- t.Object({
147
- code: t.Literal("FETCH_FAILED"),
148
- message: t.String(),
146
+ Type.Object({
147
+ code: Type.Literal("FETCH_FAILED"),
148
+ message: Type.String(),
149
149
  }),
150
- t.Object({
151
- code: t.Literal("INVALID_PARAMS"),
152
- message: t.String(),
150
+ Type.Object({
151
+ code: Type.Literal("INVALID_PARAMS"),
152
+ message: Type.String(),
153
153
  }),
154
154
  ]);
155
155
  /**
156
156
  * Device error response wrapper
157
157
  */
158
- export const DeviceErrorResponseSchema = t.Object({
159
- success: t.Literal(false),
158
+ export const DeviceErrorResponseSchema = Type.Object({
159
+ success: Type.Literal(false),
160
160
  error: DeviceErrorSchema,
161
161
  });
162
162
  /**
163
163
  * Device request response schema
164
164
  */
165
- export const DeviceRequestResponseSchema = t.Union([DeviceResponseSchema, DeviceErrorResponseSchema]);
165
+ export const DeviceRequestResponseSchema = Type.Union([DeviceResponseSchema, DeviceErrorResponseSchema]);
@@ -1,5 +1,5 @@
1
+ import { type Static } from "@sinclair/typebox";
1
2
  import { EnvironmentTypeEnum } from "@teardown/types";
2
- import { type Static } from "elysia";
3
3
  import type { AssertSchemaCompatibleWithInsert, AssertSchemaCompatibleWithRow, AssertSchemaCompatibleWithUpdate, AssertTrue } from "../../common";
4
4
  /**
5
5
  * Environment type enum (re-exported for backward compatibility)
@@ -1,5 +1,5 @@
1
+ import { Type } from "@sinclair/typebox";
1
2
  import { EnvironmentTypeEnum } from "@teardown/types";
2
- import { t } from "elysia";
3
3
  /**
4
4
  * Environment type enum (re-exported for backward compatibility)
5
5
  * @deprecated Use EnvironmentTypeEnum from @teardown/types instead
@@ -9,14 +9,14 @@ export { EnvironmentTypeEnum as EnvironmentType };
9
9
  * Environment schema
10
10
  * Represents an environment within a project
11
11
  */
12
- export const EnvironmentSchema = t.Object({
13
- id: t.String({ format: "uuid" }),
14
- project_id: t.String({ format: "uuid" }),
15
- name: t.String({ minLength: 1 }),
16
- slug: t.String({ minLength: 1 }),
17
- type: t.Enum(EnvironmentTypeEnum),
18
- created_at: t.String(),
19
- updated_at: t.String(),
12
+ export const EnvironmentSchema = Type.Object({
13
+ id: Type.String({ format: "uuid" }),
14
+ project_id: Type.String({ format: "uuid" }),
15
+ name: Type.String({ minLength: 1 }),
16
+ slug: Type.String({ minLength: 1 }),
17
+ type: Type.Enum(EnvironmentTypeEnum),
18
+ created_at: Type.String(),
19
+ updated_at: Type.String(),
20
20
  });
21
21
  /**
22
22
  * Parse and validate an EnvironmentTypeEnum value
@@ -41,17 +41,17 @@ export function parseEnvironmentTypeEnum(value) {
41
41
  * Create environment schema
42
42
  * Used for creating new environments
43
43
  */
44
- export const CreateEnvironmentSchema = t.Object({
45
- project_id: t.String({ format: "uuid" }),
46
- name: t.String({ minLength: 1 }),
47
- slug: t.String({ minLength: 1 }),
48
- type: t.Enum(EnvironmentTypeEnum),
44
+ export const CreateEnvironmentSchema = Type.Object({
45
+ project_id: Type.String({ format: "uuid" }),
46
+ name: Type.String({ minLength: 1 }),
47
+ slug: Type.String({ minLength: 1 }),
48
+ type: Type.Enum(EnvironmentTypeEnum),
49
49
  });
50
50
  /**
51
51
  * Update environment schema
52
52
  * Used for updating existing environments
53
53
  */
54
- export const UpdateEnvironmentSchema = t.Object({
55
- name: t.String({ minLength: 1 }),
56
- type: t.Enum(EnvironmentTypeEnum),
54
+ export const UpdateEnvironmentSchema = Type.Object({
55
+ name: Type.String({ minLength: 1 }),
56
+ type: Type.Enum(EnvironmentTypeEnum),
57
57
  });
@@ -1,4 +1,4 @@
1
- import { type Static } from "elysia";
1
+ import { type Static } from "@sinclair/typebox";
2
2
  import type { AssertSchemaCompatibleWithRow, AssertTrue } from "../../common";
3
3
  /**
4
4
  * Event type enum
@@ -1,4 +1,4 @@
1
- import { t } from "elysia";
1
+ import { Type } from "@sinclair/typebox";
2
2
  /**
3
3
  * Event type enum
4
4
  */
@@ -6,111 +6,111 @@ export const EventTypeEnum = ["action", "screen_view", "custom"];
6
6
  /**
7
7
  * Single event schema
8
8
  */
9
- export const EventSchema = t.Object({
9
+ export const EventSchema = Type.Object({
10
10
  /**
11
11
  * Name of the event (required)
12
12
  */
13
- event_name: t.String({ minLength: 1, error: "event_name is required" }),
13
+ event_name: Type.String({ minLength: 1, error: "event_name is required" }),
14
14
  /**
15
15
  * Type of event
16
16
  */
17
- event_type: t.Union([t.Literal("action"), t.Literal("screen_view"), t.Literal("custom")], { default: "custom" }),
17
+ event_type: Type.Union([Type.Literal("action"), Type.Literal("screen_view"), Type.Literal("custom")], { default: "custom" }),
18
18
  /**
19
19
  * Custom properties for the event (optional)
20
20
  */
21
- properties: t.Optional(t.Record(t.String(), t.Unknown())),
21
+ properties: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
22
22
  /**
23
23
  * Client-side timestamp (optional, defaults to server time)
24
24
  */
25
- timestamp: t.Optional(t.String()),
25
+ timestamp: Type.Optional(Type.String()),
26
26
  /**
27
27
  * Session ID (optional, can come from header)
28
28
  */
29
- session_id: t.Optional(t.String({ format: "uuid" })),
29
+ session_id: Type.Optional(Type.String({ format: "uuid" })),
30
30
  /**
31
31
  * Device ID (optional, can come from header)
32
32
  */
33
- device_id: t.Optional(t.String()),
33
+ device_id: Type.Optional(Type.String()),
34
34
  });
35
35
  /**
36
36
  * Batch events request schema
37
37
  * Accepts 1-100 events per request
38
38
  */
39
- export const EventsRequestSchema = t.Object({
39
+ export const EventsRequestSchema = Type.Object({
40
40
  /**
41
41
  * Array of events to ingest (1-100)
42
42
  */
43
- events: t.Array(EventSchema, { minItems: 1, maxItems: 100, error: "At least one event is required, maximum 100" }),
43
+ events: Type.Array(EventSchema, { minItems: 1, maxItems: 100, error: "At least one event is required, maximum 100" }),
44
44
  /**
45
45
  * Session ID (optional, applies to all events if not specified per-event)
46
46
  */
47
- session_id: t.Optional(t.String({ format: "uuid" })),
47
+ session_id: Type.Optional(Type.String({ format: "uuid" })),
48
48
  /**
49
49
  * Device ID (optional, applies to all events if not specified per-event)
50
50
  */
51
- device_id: t.Optional(t.String()),
51
+ device_id: Type.Optional(Type.String()),
52
52
  });
53
53
  /**
54
54
  * Events response schema
55
55
  */
56
- export const EventsResponseSchema = t.Object({
57
- success: t.Literal(true),
58
- data: t.Object({
56
+ export const EventsResponseSchema = Type.Object({
57
+ success: Type.Literal(true),
58
+ data: Type.Object({
59
59
  /**
60
60
  * IDs of created events
61
61
  */
62
- event_ids: t.Array(t.String()),
62
+ event_ids: Type.Array(Type.String()),
63
63
  /**
64
64
  * Number of successfully processed events
65
65
  */
66
- processed_count: t.Number(),
66
+ processed_count: Type.Number(),
67
67
  /**
68
68
  * Number of failed events
69
69
  */
70
- failed_count: t.Number(),
70
+ failed_count: Type.Number(),
71
71
  }),
72
72
  });
73
73
  /**
74
74
  * Events error response schema
75
75
  */
76
- export const EventsErrorResponseSchema = t.Object({
77
- success: t.Literal(false),
78
- error: t.Union([
79
- t.Object({
80
- code: t.Literal("MISSING_ORG_ID"),
81
- message: t.String(),
76
+ export const EventsErrorResponseSchema = Type.Object({
77
+ success: Type.Literal(false),
78
+ error: Type.Union([
79
+ Type.Object({
80
+ code: Type.Literal("MISSING_ORG_ID"),
81
+ message: Type.String(),
82
82
  }),
83
- t.Object({
84
- code: t.Literal("MISSING_PROJECT_ID"),
85
- message: t.String(),
83
+ Type.Object({
84
+ code: Type.Literal("MISSING_PROJECT_ID"),
85
+ message: Type.String(),
86
86
  }),
87
- t.Object({
88
- code: t.Literal("MISSING_ENVIRONMENT_SLUG"),
89
- message: t.String(),
87
+ Type.Object({
88
+ code: Type.Literal("MISSING_ENVIRONMENT_SLUG"),
89
+ message: Type.String(),
90
90
  }),
91
- t.Object({
92
- code: t.Literal("MISSING_DEVICE_ID"),
93
- message: t.String(),
91
+ Type.Object({
92
+ code: Type.Literal("MISSING_DEVICE_ID"),
93
+ message: Type.String(),
94
94
  }),
95
- t.Object({
96
- code: t.Literal("EVENTS_PROCESSING_FAILED"),
97
- message: t.String(),
95
+ Type.Object({
96
+ code: Type.Literal("EVENTS_PROCESSING_FAILED"),
97
+ message: Type.String(),
98
98
  }),
99
- t.Object({
100
- code: t.Literal("INVALID_SESSION"),
101
- message: t.String(),
99
+ Type.Object({
100
+ code: Type.Literal("INVALID_SESSION"),
101
+ message: Type.String(),
102
102
  }),
103
- t.Object({
104
- code: t.Literal("INVALID_DEVICE"),
105
- message: t.String(),
103
+ Type.Object({
104
+ code: Type.Literal("INVALID_DEVICE"),
105
+ message: Type.String(),
106
106
  }),
107
- t.Object({
108
- code: t.Literal("BATCH_SIZE_EXCEEDED"),
109
- message: t.String(),
107
+ Type.Object({
108
+ code: Type.Literal("BATCH_SIZE_EXCEEDED"),
109
+ message: Type.String(),
110
110
  }),
111
- t.Object({
112
- code: t.Literal("VALIDATION_ERROR"),
113
- message: t.String(),
111
+ Type.Object({
112
+ code: Type.Literal("VALIDATION_ERROR"),
113
+ message: Type.String(),
114
114
  }),
115
115
  ]),
116
116
  });
@@ -1,5 +1,5 @@
1
+ import { type Static } from "@sinclair/typebox";
1
2
  import { DevicePlatformEnum } from "@teardown/types";
2
- import { type Static } from "elysia";
3
3
  export { DevicePlatformEnum };
4
4
  /**
5
5
  * Application info schema
@@ -63,7 +63,7 @@ export declare const DeviceUpdateInfoSchema: import("@sinclair/typebox").TObject
63
63
  created_at: import("@sinclair/typebox").TString;
64
64
  }>;
65
65
  export type DeviceUpdateInfo = Static<typeof DeviceUpdateInfoSchema>;
66
- export declare enum NotificationPlatform {
66
+ export declare enum NotificationPlatformEnum {
67
67
  APNS = "APNS",// Apple Push Notification Service
68
68
  FCM = "FCM",// Firebase Cloud Messaging
69
69
  EXPO = "EXPO"
@@ -75,7 +75,7 @@ export declare const PushNotificationInfoSchema: import("@sinclair/typebox").TOb
75
75
  enabled: import("@sinclair/typebox").TBoolean;
76
76
  granted: import("@sinclair/typebox").TBoolean;
77
77
  token: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
78
- platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatform>;
78
+ platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatformEnum>;
79
79
  }>;
80
80
  export type PushNotificationInfo = Static<typeof PushNotificationInfoSchema>;
81
81
  export declare const NotificationsInfoSchema: import("@sinclair/typebox").TObject<{
@@ -83,7 +83,7 @@ export declare const NotificationsInfoSchema: import("@sinclair/typebox").TObjec
83
83
  enabled: import("@sinclair/typebox").TBoolean;
84
84
  granted: import("@sinclair/typebox").TBoolean;
85
85
  token: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
86
- platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatform>;
86
+ platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatformEnum>;
87
87
  }>;
88
88
  }>;
89
89
  export type NotificationsInfo = Static<typeof NotificationsInfoSchema>;
@@ -153,7 +153,7 @@ export declare const DeviceInfoSchema: import("@sinclair/typebox").TObject<{
153
153
  enabled: import("@sinclair/typebox").TBoolean;
154
154
  granted: import("@sinclair/typebox").TBoolean;
155
155
  token: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
156
- platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatform>;
156
+ platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatformEnum>;
157
157
  }>;
158
158
  }>;
159
159
  }>;
@@ -236,7 +236,7 @@ export declare const IdentifyRequestSchema: import("@sinclair/typebox").TObject<
236
236
  enabled: import("@sinclair/typebox").TBoolean;
237
237
  granted: import("@sinclair/typebox").TBoolean;
238
238
  token: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
239
- platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatform>;
239
+ platform: import("@sinclair/typebox").TEnum<typeof NotificationPlatformEnum>;
240
240
  }>;
241
241
  }>;
242
242
  }>;