@ebowwa/codespaces-types 1.4.0 → 1.4.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.
package/compile/time.js CHANGED
@@ -1,30 +1,26 @@
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
- */
1
+ // @bun
2
+ // compile/time.ts
9
3
  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(' ');
4
+ const now = Date.now();
5
+ const created = new Date(dateString).getTime();
6
+ const elapsed = now - created;
7
+ const seconds = Math.floor(elapsed / 1000);
8
+ const minutes = Math.floor(seconds / 60);
9
+ const hours = Math.floor(minutes / 60);
10
+ const days = Math.floor(hours / 24);
11
+ const parts = [];
12
+ if (days > 0) {
13
+ parts.push(`${days}d`);
14
+ }
15
+ if (hours % 24 > 0 || days > 0) {
16
+ parts.push(`${hours % 24}h`);
17
+ }
18
+ if (minutes % 60 > 0 || hours > 0) {
19
+ parts.push(`${minutes % 60}m`);
20
+ }
21
+ parts.push(`${seconds % 60}s`);
22
+ return parts.join(" ");
30
23
  }
24
+ export {
25
+ formatElapsedTime
26
+ };
@@ -1,86 +1,46 @@
1
- "use strict";
2
- /**
3
- * Validation utilities for environment names and other inputs
4
- * Migrated to use Zod for runtime type safety and better error messages
5
- */
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");
12
- /**
13
- * Zod schema for environment name validation
14
- * - Must start with a letter or number
15
- * - Can contain letters, numbers, hyphens, and underscores
16
- * - 1-64 characters long
17
- * - Cannot be a reserved word
18
- */
19
- exports.EnvironmentNameSchema = zod_1.z
20
- .string()
21
- .min(1, 'Environment name is required')
22
- .max(64, 'Environment name must be 64 characters or less')
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')
24
- .refine(function (name) { return !['ssh', 'ssh-keys', 'docker', 'registry', 'volume', 'network'].includes(name.toLowerCase()); }, {
25
- message: 'Name is a reserved word',
26
- })
27
- .transform(function (val) { return val.trim(); });
28
- /**
29
- * Zod schema for SSH key name validation
30
- */
31
- exports.SSHKeyNameSchema = zod_1.z
32
- .string()
33
- .min(1, 'SSH key name is required')
34
- .max(64, 'Name must be 64 characters or less')
35
- .transform(function (val) { return val.trim(); });
36
- /**
37
- * Zod schema for Hetzner API token validation
38
- */
39
- exports.APITokenSchema = zod_1.z
40
- .string()
41
- .min(1, 'API token is required')
42
- .min(32, 'API token appears too short')
43
- .startsWith('hetzner_', 'Hetzner API tokens typically start with "hetzner_"')
44
- .transform(function (val) { return val.trim(); });
45
- /**
46
- * Validates environment name according to Hetzner naming rules
47
- * @deprecated Use EnvironmentNameSchema.safeParse() instead
48
- */
1
+ // @bun
2
+ // compile/validation.ts
3
+ import { z } from "zod";
4
+ var EnvironmentNameSchema = z.string().min(1, "Environment name is required").max(64, "Environment name must be 64 characters or less").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").refine((name) => !["ssh", "ssh-keys", "docker", "registry", "volume", "network"].includes(name.toLowerCase()), {
5
+ message: "Name is a reserved word"
6
+ }).transform((val) => val.trim());
7
+ var SSHKeyNameSchema = z.string().min(1, "SSH key name is required").max(64, "Name must be 64 characters or less").transform((val) => val.trim());
8
+ var APITokenSchema = z.string().min(1, "API token is required").min(32, "API token appears too short").startsWith("hetzner_", 'Hetzner API tokens typically start with "hetzner_"').transform((val) => val.trim());
49
9
  function validateEnvironmentName(name) {
50
- var result = exports.EnvironmentNameSchema.safeParse(name);
51
- if (result.success) {
52
- return { isValid: true };
53
- }
54
- return {
55
- isValid: false,
56
- error: result.error.issues.map(function (e) { return e.message; }).join(', '),
57
- };
10
+ const result = EnvironmentNameSchema.safeParse(name);
11
+ if (result.success) {
12
+ return { isValid: true };
13
+ }
14
+ return {
15
+ isValid: false,
16
+ error: result.error.issues.map((e) => e.message).join(", ")
17
+ };
58
18
  }
59
- /**
60
- * Validates SSH key name
61
- * @deprecated Use SSHKeyNameSchema.safeParse() instead
62
- */
63
19
  function validateSSHKeyName(name) {
64
- var result = exports.SSHKeyNameSchema.safeParse(name);
65
- if (result.success) {
66
- return { isValid: true };
67
- }
68
- return {
69
- isValid: false,
70
- error: result.error.issues.map(function (e) { return e.message; }).join(', '),
71
- };
20
+ const result = SSHKeyNameSchema.safeParse(name);
21
+ if (result.success) {
22
+ return { isValid: true };
23
+ }
24
+ return {
25
+ isValid: false,
26
+ error: result.error.issues.map((e) => e.message).join(", ")
27
+ };
72
28
  }
73
- /**
74
- * Validates Hetzner API token format
75
- * @deprecated Use APITokenSchema.safeParse() instead
76
- */
77
29
  function validateAPIToken(token) {
78
- var result = exports.APITokenSchema.safeParse(token);
79
- if (result.success) {
80
- return { isValid: true };
81
- }
82
- return {
83
- isValid: false,
84
- error: result.error.issues.map(function (e) { return e.message; }).join(', '),
85
- };
30
+ const result = APITokenSchema.safeParse(token);
31
+ if (result.success) {
32
+ return { isValid: true };
33
+ }
34
+ return {
35
+ isValid: false,
36
+ error: result.error.issues.map((e) => e.message).join(", ")
37
+ };
86
38
  }
39
+ export {
40
+ validateSSHKeyName,
41
+ validateEnvironmentName,
42
+ validateAPIToken,
43
+ SSHKeyNameSchema,
44
+ EnvironmentNameSchema,
45
+ APITokenSchema
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebowwa/codespaces-types",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Shared types and runtime validation schemas for codespaces projects",
5
5
  "type": "module",
6
6
  "main": "./runtime/index.js",