@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.
- package/{dist/compile → compile}/index.js +41 -15
- package/compile/index.ts +553 -0
- package/compile/resources.js +116 -0
- package/compile/resources.ts +157 -0
- package/compile/schemas/resources.js +127 -0
- package/compile/schemas/resources.ts +144 -0
- package/{dist/compile → compile}/terminal-websocket.js +4 -1
- package/compile/terminal-websocket.ts +133 -0
- package/compile/time.js +30 -0
- package/compile/time.ts +32 -0
- package/{dist/compile → compile}/user/distributions.js +0 -1
- package/{dist/compile/user/distributions.d.ts → compile/user/distributions.ts} +0 -1
- package/{dist/compile → compile}/validation.js +23 -17
- package/compile/validation.ts +98 -0
- package/index.js +21 -0
- package/index.ts +5 -0
- package/package.json +38 -45
- package/runtime/ai.js +505 -0
- package/runtime/ai.ts +501 -0
- package/runtime/api.js +677 -0
- package/runtime/api.ts +857 -0
- package/runtime/database.js +94 -0
- package/runtime/database.ts +107 -0
- package/runtime/env.js +63 -0
- package/runtime/env.ts +68 -0
- package/{dist/runtime → runtime}/glm.js +7 -4
- package/runtime/glm.ts +36 -0
- package/runtime/index.js +28 -0
- package/{dist/runtime/index.js → runtime/index.ts} +1 -0
- package/runtime/ssh.js +47 -0
- package/runtime/ssh.ts +58 -0
- package/README.md +0 -65
- package/dist/compile/index.d.ts +0 -437
- package/dist/compile/index.d.ts.map +0 -1
- package/dist/compile/resources.d.ts +0 -69
- package/dist/compile/resources.d.ts.map +0 -1
- package/dist/compile/resources.js +0 -113
- package/dist/compile/schemas/resources.d.ts +0 -166
- package/dist/compile/schemas/resources.d.ts.map +0 -1
- package/dist/compile/schemas/resources.js +0 -123
- package/dist/compile/terminal-websocket.d.ts +0 -109
- package/dist/compile/terminal-websocket.d.ts.map +0 -1
- package/dist/compile/time.d.ts +0 -7
- package/dist/compile/time.d.ts.map +0 -1
- package/dist/compile/time.js +0 -27
- package/dist/compile/user/distributions.d.ts.map +0 -1
- package/dist/compile/validation.d.ts +0 -44
- package/dist/compile/validation.d.ts.map +0 -1
- package/dist/runtime/ai.d.ts +0 -1336
- package/dist/runtime/ai.d.ts.map +0 -1
- package/dist/runtime/ai.js +0 -416
- package/dist/runtime/api.d.ts +0 -1304
- package/dist/runtime/api.d.ts.map +0 -1
- package/dist/runtime/api.js +0 -673
- package/dist/runtime/database.d.ts +0 -376
- package/dist/runtime/database.d.ts.map +0 -1
- package/dist/runtime/database.js +0 -91
- package/dist/runtime/env.d.ts +0 -121
- package/dist/runtime/env.d.ts.map +0 -1
- package/dist/runtime/env.js +0 -54
- package/dist/runtime/glm.d.ts +0 -17
- package/dist/runtime/glm.d.ts.map +0 -1
- package/dist/runtime/index.d.ts +0 -13
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/ssh.d.ts +0 -111
- package/dist/runtime/ssh.d.ts.map +0 -1
- package/dist/runtime/ssh.js +0 -44
package/compile/time.js
ADDED
|
@@ -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
|
+
}
|
package/compile/time.ts
ADDED
|
@@ -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,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
|
-
|
|
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
|
-
|
|
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)
|
|
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)
|
|
27
|
+
.transform(function (val) { return val.trim(); });
|
|
22
28
|
/**
|
|
23
29
|
* Zod schema for SSH key name validation
|
|
24
30
|
*/
|
|
25
|
-
|
|
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)
|
|
35
|
+
.transform(function (val) { return val.trim(); });
|
|
30
36
|
/**
|
|
31
37
|
* Zod schema for Hetzner API token validation
|
|
32
38
|
*/
|
|
33
|
-
|
|
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)
|
|
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
|
-
|
|
44
|
-
|
|
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)
|
|
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
|
-
|
|
58
|
-
|
|
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)
|
|
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
|
-
|
|
72
|
-
|
|
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)
|
|
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
package/package.json
CHANGED
|
@@ -1,63 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebowwa/codespaces-types",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Shared types and runtime validation schemas for codespaces projects",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./runtime/index.ts",
|
|
8
7
|
"exports": {
|
|
9
8
|
".": {
|
|
10
|
-
"types": "./
|
|
11
|
-
"import": "./
|
|
9
|
+
"types": "./index.ts",
|
|
10
|
+
"import": "./index.js"
|
|
12
11
|
},
|
|
13
12
|
"./runtime": {
|
|
14
|
-
"types": "./
|
|
15
|
-
"import": "./
|
|
13
|
+
"types": "./runtime/index.ts",
|
|
14
|
+
"import": "./runtime/index.js"
|
|
16
15
|
},
|
|
17
|
-
"./runtime
|
|
18
|
-
"types": "./
|
|
19
|
-
"import": "./
|
|
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": "./
|
|
43
|
-
"import": "./
|
|
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
|
-
"
|
|
47
|
-
"
|
|
29
|
+
"keywords": [
|
|
30
|
+
"types",
|
|
31
|
+
"typescript",
|
|
32
|
+
"zod",
|
|
33
|
+
"validation",
|
|
34
|
+
"schemas",
|
|
35
|
+
"runtime",
|
|
36
|
+
"shared"
|
|
48
37
|
],
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
"
|
|
54
|
-
"
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/ebowwa/codespaces/issues"
|
|
55
48
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"zod": "^3.24.1"
|
|
59
54
|
},
|
|
60
|
-
"
|
|
61
|
-
"access": "public"
|
|
62
|
-
}
|
|
55
|
+
"devDependencies": {}
|
|
63
56
|
}
|