@ebowwa/codespaces-types 1.1.0 → 1.2.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 (67) hide show
  1. package/{dist/compile → compile}/index.js +41 -15
  2. package/compile/index.ts +553 -0
  3. package/compile/resources.js +116 -0
  4. package/compile/resources.ts +157 -0
  5. package/compile/schemas/resources.js +127 -0
  6. package/compile/schemas/resources.ts +144 -0
  7. package/{dist/compile → compile}/terminal-websocket.js +4 -1
  8. package/compile/terminal-websocket.ts +133 -0
  9. package/compile/time.js +30 -0
  10. package/compile/time.ts +32 -0
  11. package/{dist/compile → compile}/user/distributions.js +0 -1
  12. package/{dist/compile/user/distributions.d.ts → compile/user/distributions.ts} +0 -1
  13. package/{dist/compile → compile}/validation.js +23 -17
  14. package/compile/validation.ts +98 -0
  15. package/index.js +21 -0
  16. package/index.ts +5 -0
  17. package/package.json +38 -45
  18. package/runtime/ai.js +505 -0
  19. package/runtime/ai.ts +501 -0
  20. package/runtime/api.js +677 -0
  21. package/runtime/api.ts +857 -0
  22. package/runtime/database.js +94 -0
  23. package/runtime/database.ts +107 -0
  24. package/runtime/env.js +63 -0
  25. package/runtime/env.ts +68 -0
  26. package/{dist/runtime → runtime}/glm.js +7 -4
  27. package/runtime/glm.ts +36 -0
  28. package/runtime/index.js +28 -0
  29. package/{dist/runtime/index.js → runtime/index.ts} +1 -0
  30. package/runtime/ssh.js +47 -0
  31. package/runtime/ssh.ts +58 -0
  32. package/README.md +0 -65
  33. package/dist/compile/index.d.ts +0 -437
  34. package/dist/compile/index.d.ts.map +0 -1
  35. package/dist/compile/resources.d.ts +0 -69
  36. package/dist/compile/resources.d.ts.map +0 -1
  37. package/dist/compile/resources.js +0 -113
  38. package/dist/compile/schemas/resources.d.ts +0 -166
  39. package/dist/compile/schemas/resources.d.ts.map +0 -1
  40. package/dist/compile/schemas/resources.js +0 -123
  41. package/dist/compile/terminal-websocket.d.ts +0 -109
  42. package/dist/compile/terminal-websocket.d.ts.map +0 -1
  43. package/dist/compile/time.d.ts +0 -7
  44. package/dist/compile/time.d.ts.map +0 -1
  45. package/dist/compile/time.js +0 -27
  46. package/dist/compile/user/distributions.d.ts.map +0 -1
  47. package/dist/compile/validation.d.ts +0 -44
  48. package/dist/compile/validation.d.ts.map +0 -1
  49. package/dist/runtime/ai.d.ts +0 -1336
  50. package/dist/runtime/ai.d.ts.map +0 -1
  51. package/dist/runtime/ai.js +0 -416
  52. package/dist/runtime/api.d.ts +0 -1304
  53. package/dist/runtime/api.d.ts.map +0 -1
  54. package/dist/runtime/api.js +0 -673
  55. package/dist/runtime/database.d.ts +0 -376
  56. package/dist/runtime/database.d.ts.map +0 -1
  57. package/dist/runtime/database.js +0 -91
  58. package/dist/runtime/env.d.ts +0 -121
  59. package/dist/runtime/env.d.ts.map +0 -1
  60. package/dist/runtime/env.js +0 -54
  61. package/dist/runtime/glm.d.ts +0 -17
  62. package/dist/runtime/glm.d.ts.map +0 -1
  63. package/dist/runtime/index.d.ts +0 -13
  64. package/dist/runtime/index.d.ts.map +0 -1
  65. package/dist/runtime/ssh.d.ts +0 -111
  66. package/dist/runtime/ssh.d.ts.map +0 -1
  67. package/dist/runtime/ssh.js +0 -44
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatElapsedTime = formatElapsedTime;
4
+ /**
5
+ * Format elapsed time since a given date in full precision (e.g., "2d 14h 32m 15s")
6
+ * @param dateString - ISO date string to calculate elapsed time from
7
+ * @returns Formatted elapsed time string
8
+ */
9
+ function formatElapsedTime(dateString) {
10
+ var now = Date.now();
11
+ var created = new Date(dateString).getTime();
12
+ var elapsed = now - created;
13
+ var seconds = Math.floor(elapsed / 1000);
14
+ var minutes = Math.floor(seconds / 60);
15
+ var hours = Math.floor(minutes / 60);
16
+ var days = Math.floor(hours / 24);
17
+ var parts = [];
18
+ if (days > 0) {
19
+ parts.push("".concat(days, "d"));
20
+ }
21
+ if (hours % 24 > 0 || days > 0) {
22
+ parts.push("".concat(hours % 24, "h"));
23
+ }
24
+ if (minutes % 60 > 0 || hours > 0) {
25
+ parts.push("".concat(minutes % 60, "m"));
26
+ }
27
+ // Always show seconds if less than a minute, or for completeness
28
+ parts.push("".concat(seconds % 60, "s"));
29
+ return parts.join(' ');
30
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Format elapsed time since a given date in full precision (e.g., "2d 14h 32m 15s")
3
+ * @param dateString - ISO date string to calculate elapsed time from
4
+ * @returns Formatted elapsed time string
5
+ */
6
+ export function formatElapsedTime(dateString: string): string {
7
+ const now = Date.now();
8
+ const created = new Date(dateString).getTime();
9
+ const elapsed = now - created;
10
+
11
+ const seconds = Math.floor(elapsed / 1000);
12
+ const minutes = Math.floor(seconds / 60);
13
+ const hours = Math.floor(minutes / 60);
14
+ const days = Math.floor(hours / 24);
15
+
16
+ const parts: string[] = [];
17
+
18
+ if (days > 0) {
19
+ parts.push(`${days}d`);
20
+ }
21
+ if (hours % 24 > 0 || days > 0) {
22
+ parts.push(`${hours % 24}h`);
23
+ }
24
+ if (minutes % 60 > 0 || hours > 0) {
25
+ parts.push(`${minutes % 60}m`);
26
+ }
27
+
28
+ // Always show seconds if less than a minute, or for completeness
29
+ parts.push(`${seconds % 60}s`);
30
+
31
+ return parts.join(' ');
32
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * - firstJoined: datetime
4
3
  * - last active: datetime
@@ -11,4 +11,3 @@
11
11
  * - isGithubEnabled: Y/N
12
12
  * - AdminNodeProfile: MacOs, IOS, Android, Windows, etc.
13
13
  */
14
- //# sourceMappingURL=distributions.d.ts.map
@@ -1,8 +1,14 @@
1
+ "use strict";
1
2
  /**
2
3
  * Validation utilities for environment names and other inputs
3
4
  * Migrated to use Zod for runtime type safety and better error messages
4
5
  */
5
- import { z } from 'zod';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.APITokenSchema = exports.SSHKeyNameSchema = exports.EnvironmentNameSchema = void 0;
8
+ exports.validateEnvironmentName = validateEnvironmentName;
9
+ exports.validateSSHKeyName = validateSSHKeyName;
10
+ exports.validateAPIToken = validateAPIToken;
11
+ var zod_1 = require("zod");
6
12
  /**
7
13
  * Zod schema for environment name validation
8
14
  * - Must start with a letter or number
@@ -10,71 +16,71 @@ import { z } from 'zod';
10
16
  * - 1-64 characters long
11
17
  * - Cannot be a reserved word
12
18
  */
13
- export const EnvironmentNameSchema = z
19
+ exports.EnvironmentNameSchema = zod_1.z
14
20
  .string()
15
21
  .min(1, 'Environment name is required')
16
22
  .max(64, 'Environment name must be 64 characters or less')
17
23
  .regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/, 'Name must start with a letter or number and contain only letters, numbers, hyphens, and underscores')
18
- .refine((name) => !['ssh', 'ssh-keys', 'docker', 'registry', 'volume', 'network'].includes(name.toLowerCase()), {
24
+ .refine(function (name) { return !['ssh', 'ssh-keys', 'docker', 'registry', 'volume', 'network'].includes(name.toLowerCase()); }, {
19
25
  message: 'Name is a reserved word',
20
26
  })
21
- .transform((val) => val.trim());
27
+ .transform(function (val) { return val.trim(); });
22
28
  /**
23
29
  * Zod schema for SSH key name validation
24
30
  */
25
- export const SSHKeyNameSchema = z
31
+ exports.SSHKeyNameSchema = zod_1.z
26
32
  .string()
27
33
  .min(1, 'SSH key name is required')
28
34
  .max(64, 'Name must be 64 characters or less')
29
- .transform((val) => val.trim());
35
+ .transform(function (val) { return val.trim(); });
30
36
  /**
31
37
  * Zod schema for Hetzner API token validation
32
38
  */
33
- export const APITokenSchema = z
39
+ exports.APITokenSchema = zod_1.z
34
40
  .string()
35
41
  .min(1, 'API token is required')
36
42
  .min(32, 'API token appears too short')
37
43
  .startsWith('hetzner_', 'Hetzner API tokens typically start with "hetzner_"')
38
- .transform((val) => val.trim());
44
+ .transform(function (val) { return val.trim(); });
39
45
  /**
40
46
  * Validates environment name according to Hetzner naming rules
41
47
  * @deprecated Use EnvironmentNameSchema.safeParse() instead
42
48
  */
43
- export function validateEnvironmentName(name) {
44
- const result = EnvironmentNameSchema.safeParse(name);
49
+ function validateEnvironmentName(name) {
50
+ var result = exports.EnvironmentNameSchema.safeParse(name);
45
51
  if (result.success) {
46
52
  return { isValid: true };
47
53
  }
48
54
  return {
49
55
  isValid: false,
50
- error: result.error.issues.map((e) => e.message).join(', '),
56
+ error: result.error.issues.map(function (e) { return e.message; }).join(', '),
51
57
  };
52
58
  }
53
59
  /**
54
60
  * Validates SSH key name
55
61
  * @deprecated Use SSHKeyNameSchema.safeParse() instead
56
62
  */
57
- export function validateSSHKeyName(name) {
58
- const result = SSHKeyNameSchema.safeParse(name);
63
+ function validateSSHKeyName(name) {
64
+ var result = exports.SSHKeyNameSchema.safeParse(name);
59
65
  if (result.success) {
60
66
  return { isValid: true };
61
67
  }
62
68
  return {
63
69
  isValid: false,
64
- error: result.error.issues.map((e) => e.message).join(', '),
70
+ error: result.error.issues.map(function (e) { return e.message; }).join(', '),
65
71
  };
66
72
  }
67
73
  /**
68
74
  * Validates Hetzner API token format
69
75
  * @deprecated Use APITokenSchema.safeParse() instead
70
76
  */
71
- export function validateAPIToken(token) {
72
- const result = APITokenSchema.safeParse(token);
77
+ function validateAPIToken(token) {
78
+ var result = exports.APITokenSchema.safeParse(token);
73
79
  if (result.success) {
74
80
  return { isValid: true };
75
81
  }
76
82
  return {
77
83
  isValid: false,
78
- error: result.error.issues.map((e) => e.message).join(', '),
84
+ error: result.error.issues.map(function (e) { return e.message; }).join(', '),
79
85
  };
80
86
  }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Validation utilities for environment names and other inputs
3
+ * Migrated to use Zod for runtime type safety and better error messages
4
+ */
5
+
6
+ import { z } from 'zod'
7
+
8
+ export interface ValidationResult {
9
+ isValid: boolean
10
+ error?: string
11
+ }
12
+
13
+ /**
14
+ * Zod schema for environment name validation
15
+ * - Must start with a letter or number
16
+ * - Can contain letters, numbers, hyphens, and underscores
17
+ * - 1-64 characters long
18
+ * - Cannot be a reserved word
19
+ */
20
+ export const EnvironmentNameSchema = z
21
+ .string()
22
+ .min(1, 'Environment name is required')
23
+ .max(64, 'Environment name must be 64 characters or less')
24
+ .regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/, 'Name must start with a letter or number and contain only letters, numbers, hyphens, and underscores')
25
+ .refine((name) => !['ssh', 'ssh-keys', 'docker', 'registry', 'volume', 'network'].includes(name.toLowerCase()), {
26
+ message: 'Name is a reserved word',
27
+ })
28
+ .transform((val) => val.trim())
29
+
30
+ export type EnvironmentName = z.infer<typeof EnvironmentNameSchema>
31
+
32
+ /**
33
+ * Zod schema for SSH key name validation
34
+ */
35
+ export const SSHKeyNameSchema = z
36
+ .string()
37
+ .min(1, 'SSH key name is required')
38
+ .max(64, 'Name must be 64 characters or less')
39
+ .transform((val) => val.trim())
40
+
41
+ export type SSHKeyName = z.infer<typeof SSHKeyNameSchema>
42
+
43
+ /**
44
+ * Zod schema for Hetzner API token validation
45
+ */
46
+ export const APITokenSchema = z
47
+ .string()
48
+ .min(1, 'API token is required')
49
+ .min(32, 'API token appears too short')
50
+ .startsWith('hetzner_', 'Hetzner API tokens typically start with "hetzner_"')
51
+ .transform((val) => val.trim())
52
+
53
+ export type APIToken = z.infer<typeof APITokenSchema>
54
+
55
+ /**
56
+ * Validates environment name according to Hetzner naming rules
57
+ * @deprecated Use EnvironmentNameSchema.safeParse() instead
58
+ */
59
+ export function validateEnvironmentName(name: string): ValidationResult {
60
+ const result = EnvironmentNameSchema.safeParse(name)
61
+ if (result.success) {
62
+ return { isValid: true }
63
+ }
64
+ return {
65
+ isValid: false,
66
+ error: result.error.issues.map((e) => e.message).join(', '),
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Validates SSH key name
72
+ * @deprecated Use SSHKeyNameSchema.safeParse() instead
73
+ */
74
+ export function validateSSHKeyName(name: string): ValidationResult {
75
+ const result = SSHKeyNameSchema.safeParse(name)
76
+ if (result.success) {
77
+ return { isValid: true }
78
+ }
79
+ return {
80
+ isValid: false,
81
+ error: result.error.issues.map((e) => e.message).join(', '),
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Validates Hetzner API token format
87
+ * @deprecated Use APITokenSchema.safeParse() instead
88
+ */
89
+ export function validateAPIToken(token: string): ValidationResult {
90
+ const result = APITokenSchema.safeParse(token)
91
+ if (result.success) {
92
+ return { isValid: true }
93
+ }
94
+ return {
95
+ isValid: false,
96
+ error: result.error.issues.map((e) => e.message).join(', '),
97
+ }
98
+ }
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Re-export runtime schemas and compile-time types
19
+ */
20
+ __exportStar(require("./runtime/index.js"), exports);
21
+ __exportStar(require("./compile/index.js"), exports);
package/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Re-export runtime schemas and compile-time types
3
+ */
4
+ export * from './runtime/index.js';
5
+ export * from './compile/index.js';
package/package.json CHANGED
@@ -1,63 +1,56 @@
1
1
  {
2
2
  "name": "@ebowwa/codespaces-types",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Shared types and runtime validation schemas for codespaces projects",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
6
+ "main": "./runtime/index.ts",
8
7
  "exports": {
9
8
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
9
+ "types": "./index.ts",
10
+ "import": "./index.js"
12
11
  },
13
12
  "./runtime": {
14
- "types": "./dist/runtime/index.d.ts",
15
- "import": "./dist/runtime/index.js"
13
+ "types": "./runtime/index.ts",
14
+ "import": "./runtime/index.js"
16
15
  },
17
- "./runtime/api": {
18
- "types": "./dist/runtime/api.d.ts",
19
- "import": "./dist/runtime/api.js"
20
- },
21
- "./runtime/ai": {
22
- "types": "./dist/runtime/ai.d.ts",
23
- "import": "./dist/runtime/ai.js"
24
- },
25
- "./runtime/database": {
26
- "types": "./dist/runtime/database.d.ts",
27
- "import": "./dist/runtime/database.js"
28
- },
29
- "./runtime/env": {
30
- "types": "./dist/runtime/env.d.ts",
31
- "import": "./dist/runtime/env.js"
32
- },
33
- "./runtime/glm": {
34
- "types": "./dist/runtime/glm.d.ts",
35
- "import": "./dist/runtime/glm.js"
36
- },
37
- "./runtime/ssh": {
38
- "types": "./dist/runtime/ssh.d.ts",
39
- "import": "./dist/runtime/ssh.js"
16
+ "./runtime/*": {
17
+ "types": "./runtime/*.ts",
18
+ "import": "./runtime/*.js"
40
19
  },
41
20
  "./compile": {
42
- "types": "./dist/compile/index.d.ts",
43
- "import": "./dist/compile/index.js"
21
+ "types": "./compile/index.ts",
22
+ "import": "./compile/index.ts"
23
+ },
24
+ "./compile/*": {
25
+ "types": "./compile/*.ts",
26
+ "import": "./compile/*.ts"
44
27
  }
45
28
  },
46
- "files": [
47
- "dist"
29
+ "keywords": [
30
+ "types",
31
+ "typescript",
32
+ "zod",
33
+ "validation",
34
+ "schemas",
35
+ "runtime",
36
+ "shared"
48
37
  ],
49
- "scripts": {
50
- "build": "tsc",
51
- "prepublishOnly": "npm run build"
38
+ "author": "Ebowwa Labs <labs@ebowwa.com>",
39
+ "license": "MIT",
40
+ "homepage": "https://github.com/ebowwa/codespaces/tree/main/packages/src/codespaces-types#readme",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/ebowwa/codespaces.git",
44
+ "directory": "packages/src/codespaces-types"
52
45
  },
53
- "dependencies": {
54
- "zod": "^3.22.4"
46
+ "bugs": {
47
+ "url": "https://github.com/ebowwa/codespaces/issues"
55
48
  },
56
- "devDependencies": {
57
- "@types/node": "^20.11.0",
58
- "typescript": "^5.3.3"
49
+ "engines": {
50
+ "node": ">=18.0.0"
51
+ },
52
+ "dependencies": {
53
+ "zod": "^3.24.1"
59
54
  },
60
- "publishConfig": {
61
- "access": "public"
62
- }
55
+ "devDependencies": {}
63
56
  }