@teardown/schemas 0.1.0

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 (61) hide show
  1. package/dist/common/index.d.ts +3 -0
  2. package/dist/common/index.js +3 -0
  3. package/dist/common/primitives.d.ts +11 -0
  4. package/dist/common/primitives.js +9 -0
  5. package/dist/common/responses.d.ts +27 -0
  6. package/dist/common/responses.js +13 -0
  7. package/dist/common/type-checks.d.ts +58 -0
  8. package/dist/common/type-checks.js +1 -0
  9. package/dist/index.d.ts +13 -0
  10. package/dist/index.js +14 -0
  11. package/dist/modules/analytics/index.d.ts +1 -0
  12. package/dist/modules/analytics/index.js +1 -0
  13. package/dist/modules/analytics/schemas.d.ts +239 -0
  14. package/dist/modules/analytics/schemas.js +136 -0
  15. package/dist/modules/builds/index.d.ts +1 -0
  16. package/dist/modules/builds/index.js +1 -0
  17. package/dist/modules/builds/schemas.d.ts +248 -0
  18. package/dist/modules/builds/schemas.js +137 -0
  19. package/dist/modules/devices/index.d.ts +1 -0
  20. package/dist/modules/devices/index.js +1 -0
  21. package/dist/modules/devices/schemas.d.ts +207 -0
  22. package/dist/modules/devices/schemas.js +165 -0
  23. package/dist/modules/environment/index.d.ts +1 -0
  24. package/dist/modules/environment/index.js +1 -0
  25. package/dist/modules/environment/schemas.d.ts +56 -0
  26. package/dist/modules/environment/schemas.js +57 -0
  27. package/dist/modules/events/index.d.ts +1 -0
  28. package/dist/modules/events/index.js +1 -0
  29. package/dist/modules/events/schemas.d.ts +138 -0
  30. package/dist/modules/events/schemas.js +116 -0
  31. package/dist/modules/identify/index.d.ts +1 -0
  32. package/dist/modules/identify/index.js +1 -0
  33. package/dist/modules/identify/schemas.d.ts +377 -0
  34. package/dist/modules/identify/schemas.js +221 -0
  35. package/dist/modules/index.d.ts +12 -0
  36. package/dist/modules/index.js +12 -0
  37. package/dist/modules/me/index.d.ts +1 -0
  38. package/dist/modules/me/index.js +1 -0
  39. package/dist/modules/me/schemas.d.ts +75 -0
  40. package/dist/modules/me/schemas.js +76 -0
  41. package/dist/modules/orgs/index.d.ts +1 -0
  42. package/dist/modules/orgs/index.js +1 -0
  43. package/dist/modules/orgs/schemas.d.ts +308 -0
  44. package/dist/modules/orgs/schemas.js +214 -0
  45. package/dist/modules/personas/index.d.ts +1 -0
  46. package/dist/modules/personas/index.js +1 -0
  47. package/dist/modules/personas/schemas.d.ts +170 -0
  48. package/dist/modules/personas/schemas.js +100 -0
  49. package/dist/modules/projects/index.d.ts +1 -0
  50. package/dist/modules/projects/index.js +1 -0
  51. package/dist/modules/projects/schemas.d.ts +222 -0
  52. package/dist/modules/projects/schemas.js +145 -0
  53. package/dist/modules/sessions/index.d.ts +1 -0
  54. package/dist/modules/sessions/index.js +1 -0
  55. package/dist/modules/sessions/schemas.d.ts +258 -0
  56. package/dist/modules/sessions/schemas.js +128 -0
  57. package/dist/modules/versions/index.d.ts +1 -0
  58. package/dist/modules/versions/index.js +1 -0
  59. package/dist/modules/versions/schemas.d.ts +248 -0
  60. package/dist/modules/versions/schemas.js +155 -0
  61. package/package.json +106 -0
@@ -0,0 +1,155 @@
1
+ import { VersionBuildStatusEnum } from "@teardown/types";
2
+ import { t } from "elysia";
3
+ /**
4
+ * Version status enum matching database
5
+ */
6
+ export const VersionBuildStatusSchema = t.Enum(VersionBuildStatusEnum);
7
+ /**
8
+ * Parse and validate a VersionBuildStatusEnum value
9
+ * Uses a switch statement to ensure type safety and runtime validation
10
+ * @param value - The value to parse
11
+ * @returns The validated VersionBuildStatusEnum value
12
+ * @throws Error if the value is not a valid VersionBuildStatusEnum
13
+ */
14
+ export function parseVersionStatusEnum(value) {
15
+ switch (value) {
16
+ case VersionBuildStatusEnum.SUPPORTED:
17
+ return VersionBuildStatusEnum.SUPPORTED;
18
+ case VersionBuildStatusEnum.UPDATE_AVAILABLE:
19
+ return VersionBuildStatusEnum.UPDATE_AVAILABLE;
20
+ case VersionBuildStatusEnum.UPDATE_RECOMMENDED:
21
+ case VersionBuildStatusEnum.UPDATE_REQUIRED:
22
+ return VersionBuildStatusEnum.UPDATE_REQUIRED;
23
+ default:
24
+ throw new Error(`Invalid VersionBuildStatusEnum value: ${value}. Expected one of: ${Object.values(VersionBuildStatusEnum).join(", ")}`);
25
+ }
26
+ }
27
+ /**
28
+ * Base version schema
29
+ * Represents project_versions table structure
30
+ */
31
+ export const VersionSchema = t.Object({
32
+ id: t.String({ format: "uuid" }),
33
+ project_id: t.String({ format: "uuid" }),
34
+ name: t.String(),
35
+ major: t.Number(), // Matches type number, not integer constraint (db type numeric)
36
+ minor: t.Number(),
37
+ patch: t.Number(),
38
+ status: VersionBuildStatusSchema, // SUPPORTED, UPDATE_AVAILABLE, UPDATE_RECOMMENDED, UPDATE_REQUIRED - controls if version is active
39
+ created_at: t.String(),
40
+ updated_at: t.String(),
41
+ });
42
+ /**
43
+ * Version params schema
44
+ */
45
+ export const VersionParamsSchema = t.Object({
46
+ version_id: t.String({ format: "uuid" }),
47
+ });
48
+ /**
49
+ * Search versions query schema
50
+ * Supports pagination, search, and sorting
51
+ */
52
+ export const SearchVersionsQuerySchema = t.Object({
53
+ project_id: t.String({ format: "uuid" }),
54
+ page: t.Numeric({ minimum: 1, default: 1 }),
55
+ limit: t.Numeric({ minimum: 1, maximum: 100, default: 20 }),
56
+ search: t.Optional(t.String()),
57
+ sort_by: t.Union([
58
+ t.Literal("created_at"),
59
+ t.Literal("updated_at"),
60
+ t.Literal("name"),
61
+ t.Literal("major"),
62
+ t.Literal("minor"),
63
+ t.Literal("patch"),
64
+ ], { default: "created_at" }),
65
+ sort_order: t.Union([t.Literal("asc"), t.Literal("desc")], { default: "desc" }),
66
+ });
67
+ /**
68
+ * Search versions query schema without project_id (injected from headers)
69
+ */
70
+ export const SearchVersionsQueryParamsSchema = t.Omit(SearchVersionsQuerySchema, ["project_id"]);
71
+ /**
72
+ * Versions by IDs request schema
73
+ */
74
+ export const VersionsByIdsSchema = t.Object({
75
+ version_ids: t.Array(t.String({ format: "uuid" }), { minItems: 1, maxItems: 100 }),
76
+ });
77
+ /**
78
+ * Paginated versions response schema
79
+ */
80
+ export const VersionsResponseSchema = t.Object({
81
+ versions: t.Array(VersionSchema),
82
+ pagination: t.Object({
83
+ page: t.Integer({ minimum: 1 }),
84
+ limit: t.Integer({ minimum: 1 }),
85
+ total: t.Integer({ minimum: 0 }),
86
+ total_pages: t.Integer({ minimum: 0 }),
87
+ }),
88
+ });
89
+ /**
90
+ * Single version response schema
91
+ */
92
+ export const VersionResponseSchema = t.Object({
93
+ success: t.Literal(true),
94
+ data: VersionSchema,
95
+ });
96
+ /**
97
+ * Version error response schema
98
+ * Discriminated union by error code
99
+ */
100
+ export const VersionErrorSchema = t.Union([
101
+ t.Object({
102
+ code: t.Literal("VERSION_NOT_FOUND"),
103
+ message: t.String(),
104
+ }),
105
+ t.Object({
106
+ code: t.Literal("PROJECT_NOT_FOUND"),
107
+ message: t.String(),
108
+ }),
109
+ t.Object({
110
+ code: t.Literal("FORBIDDEN"),
111
+ message: t.String(),
112
+ }),
113
+ t.Object({
114
+ code: t.Literal("FETCH_FAILED"),
115
+ message: t.String(),
116
+ }),
117
+ t.Object({
118
+ code: t.Literal("INVALID_PARAMS"),
119
+ message: t.String(),
120
+ }),
121
+ ]);
122
+ /**
123
+ * Version error response wrapper
124
+ */
125
+ export const VersionErrorResponseSchema = t.Object({
126
+ success: t.Literal(false),
127
+ error: VersionErrorSchema,
128
+ });
129
+ /**
130
+ * Version request response schema
131
+ */
132
+ export const VersionRequestResponseSchema = t.Union([VersionResponseSchema, VersionErrorResponseSchema]);
133
+ /**
134
+ * Update version status request body schema
135
+ */
136
+ export const UpdateVersionStatusBodySchema = t.Object({
137
+ status: VersionBuildStatusSchema,
138
+ });
139
+ /**
140
+ * Add UPDATE_FAILED error code for update operations
141
+ */
142
+ export const VersionErrorSchemaWithUpdate = t.Union([
143
+ VersionErrorSchema,
144
+ t.Object({
145
+ code: t.Literal("UPDATE_FAILED"),
146
+ message: t.String(),
147
+ }),
148
+ ]);
149
+ /**
150
+ * Version error response wrapper with update error
151
+ */
152
+ export const VersionErrorResponseWithUpdateSchema = t.Object({
153
+ success: t.Literal(false),
154
+ error: VersionErrorSchemaWithUpdate,
155
+ });
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@teardown/schemas",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "files": ["dist/**/*"],
10
+ "main": "./dist/index.js",
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./common": {
20
+ "types": "./dist/common/index.d.ts",
21
+ "import": "./dist/common/index.js",
22
+ "default": "./dist/common/index.js"
23
+ },
24
+ "./devices": {
25
+ "types": "./dist/modules/devices/index.d.ts",
26
+ "import": "./dist/modules/devices/index.js",
27
+ "default": "./dist/modules/devices/index.js"
28
+ },
29
+ "./environment": {
30
+ "types": "./dist/modules/environment/index.d.ts",
31
+ "import": "./dist/modules/environment/index.js",
32
+ "default": "./dist/modules/environment/index.js"
33
+ },
34
+ "./identify": {
35
+ "types": "./dist/modules/identify/index.d.ts",
36
+ "import": "./dist/modules/identify/index.js",
37
+ "default": "./dist/modules/identify/index.js"
38
+ },
39
+ "./me": {
40
+ "types": "./dist/modules/me/index.d.ts",
41
+ "import": "./dist/modules/me/index.js",
42
+ "default": "./dist/modules/me/index.js"
43
+ },
44
+ "./orgs": {
45
+ "types": "./dist/modules/orgs/index.d.ts",
46
+ "import": "./dist/modules/orgs/index.js",
47
+ "default": "./dist/modules/orgs/index.js"
48
+ },
49
+ "./personas": {
50
+ "types": "./dist/modules/personas/index.d.ts",
51
+ "import": "./dist/modules/personas/index.js",
52
+ "default": "./dist/modules/personas/index.js"
53
+ },
54
+ "./projects": {
55
+ "types": "./dist/modules/projects/index.d.ts",
56
+ "import": "./dist/modules/projects/index.js",
57
+ "default": "./dist/modules/projects/index.js"
58
+ },
59
+ "./sessions": {
60
+ "types": "./dist/modules/sessions/index.d.ts",
61
+ "import": "./dist/modules/sessions/index.js",
62
+ "default": "./dist/modules/sessions/index.js"
63
+ },
64
+ "./versions": {
65
+ "types": "./dist/modules/versions/index.d.ts",
66
+ "import": "./dist/modules/versions/index.js",
67
+ "default": "./dist/modules/versions/index.js"
68
+ },
69
+ "./builds": {
70
+ "types": "./dist/modules/builds/index.d.ts",
71
+ "import": "./dist/modules/builds/index.js",
72
+ "default": "./dist/modules/builds/index.js"
73
+ },
74
+ "./analytics": {
75
+ "types": "./dist/modules/analytics/index.d.ts",
76
+ "import": "./dist/modules/analytics/index.js",
77
+ "default": "./dist/modules/analytics/index.js"
78
+ },
79
+ "./events": {
80
+ "types": "./dist/modules/events/index.d.ts",
81
+ "import": "./dist/modules/events/index.js",
82
+ "default": "./dist/modules/events/index.js"
83
+ }
84
+ },
85
+ "scripts": {
86
+ "dev": "bun x tsc --project ./tsconfig.json --watch",
87
+ "build": "bun x tsc --project ./tsconfig.json",
88
+ "typecheck": "bun x tsc --noEmit --project ./tsconfig.json",
89
+ "lint": "bun x biome lint .",
90
+ "fmt": "bun x biome format --write .",
91
+ "check": "bun x biome check .",
92
+ "prepublishOnly": "bun x turbo run build"
93
+ },
94
+ "dependencies": {
95
+ "@teardown/types": "0.0.2",
96
+ "elysia": "1.4.16"
97
+ },
98
+ "devDependencies": {
99
+ "@biomejs/biome": "2.3.7",
100
+ "@teardown/tsconfig": "1.0.0",
101
+ "typescript": "^5.9.3"
102
+ },
103
+ "peerDependencies": {
104
+ "typescript": "^5.9.3"
105
+ }
106
+ }