@elaraai/e3-api-server 0.0.2-beta.12 → 0.0.2-beta.13

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 (111) hide show
  1. package/README.md +144 -29
  2. package/dist/src/async-operation-state.d.ts +63 -0
  3. package/dist/src/async-operation-state.d.ts.map +1 -0
  4. package/dist/src/async-operation-state.js +193 -0
  5. package/dist/src/async-operation-state.js.map +1 -0
  6. package/dist/src/auth/device.d.ts +26 -0
  7. package/dist/src/auth/device.d.ts.map +1 -0
  8. package/dist/src/auth/device.js +227 -0
  9. package/dist/src/auth/device.js.map +1 -0
  10. package/dist/src/auth/discovery.d.ts +23 -0
  11. package/dist/src/auth/discovery.d.ts.map +1 -0
  12. package/dist/src/auth/discovery.js +40 -0
  13. package/dist/src/auth/discovery.js.map +1 -0
  14. package/dist/src/auth/index.d.ts +56 -0
  15. package/dist/src/auth/index.d.ts.map +1 -0
  16. package/dist/src/auth/index.js +69 -0
  17. package/dist/src/auth/index.js.map +1 -0
  18. package/dist/src/auth/keys.d.ts +55 -0
  19. package/dist/src/auth/keys.d.ts.map +1 -0
  20. package/dist/src/auth/keys.js +78 -0
  21. package/dist/src/auth/keys.js.map +1 -0
  22. package/dist/src/beast2.d.ts +15 -3
  23. package/dist/src/beast2.d.ts.map +1 -1
  24. package/dist/src/beast2.js +30 -4
  25. package/dist/src/beast2.js.map +1 -1
  26. package/dist/src/cli.js +58 -6
  27. package/dist/src/cli.js.map +1 -1
  28. package/dist/src/errors.d.ts.map +1 -1
  29. package/dist/src/errors.js +5 -2
  30. package/dist/src/errors.js.map +1 -1
  31. package/dist/src/execution-state.d.ts +54 -0
  32. package/dist/src/execution-state.d.ts.map +1 -0
  33. package/dist/src/execution-state.js +150 -0
  34. package/dist/src/execution-state.js.map +1 -0
  35. package/dist/src/handlers/dataflow.d.ts +49 -0
  36. package/dist/src/handlers/dataflow.d.ts.map +1 -0
  37. package/dist/src/handlers/dataflow.js +371 -0
  38. package/dist/src/handlers/dataflow.js.map +1 -0
  39. package/dist/src/handlers/datasets.d.ts +23 -0
  40. package/dist/src/handlers/datasets.d.ts.map +1 -0
  41. package/dist/src/handlers/datasets.js +113 -0
  42. package/dist/src/handlers/datasets.js.map +1 -0
  43. package/dist/src/handlers/index.d.ts +12 -0
  44. package/dist/src/handlers/index.d.ts.map +1 -0
  45. package/dist/src/handlers/index.js +12 -0
  46. package/dist/src/handlers/index.js.map +1 -0
  47. package/dist/src/handlers/packages.d.ts +26 -0
  48. package/dist/src/handlers/packages.d.ts.map +1 -0
  49. package/dist/src/handlers/packages.js +101 -0
  50. package/dist/src/handlers/packages.js.map +1 -0
  51. package/dist/src/handlers/repos.d.ts +11 -0
  52. package/dist/src/handlers/repos.d.ts.map +1 -0
  53. package/dist/src/handlers/repos.js +52 -0
  54. package/dist/src/handlers/repos.js.map +1 -0
  55. package/dist/src/handlers/repository.d.ts +35 -0
  56. package/dist/src/handlers/repository.d.ts.map +1 -0
  57. package/dist/src/handlers/repository.js +142 -0
  58. package/dist/src/handlers/repository.js.map +1 -0
  59. package/dist/src/handlers/tasks.d.ts +18 -0
  60. package/dist/src/handlers/tasks.d.ts.map +1 -0
  61. package/dist/src/handlers/tasks.js +134 -0
  62. package/dist/src/handlers/tasks.js.map +1 -0
  63. package/dist/src/handlers/workspaces.d.ts +34 -0
  64. package/dist/src/handlers/workspaces.d.ts.map +1 -0
  65. package/dist/src/handlers/workspaces.js +225 -0
  66. package/dist/src/handlers/workspaces.js.map +1 -0
  67. package/dist/src/index.d.ts +3 -0
  68. package/dist/src/index.d.ts.map +1 -1
  69. package/dist/src/index.js +6 -0
  70. package/dist/src/index.js.map +1 -1
  71. package/dist/src/middleware/auth.d.ts +51 -0
  72. package/dist/src/middleware/auth.d.ts.map +1 -0
  73. package/dist/src/middleware/auth.js +158 -0
  74. package/dist/src/middleware/auth.js.map +1 -0
  75. package/dist/src/routes/datasets.d.ts +2 -1
  76. package/dist/src/routes/datasets.d.ts.map +1 -1
  77. package/dist/src/routes/datasets.js +50 -85
  78. package/dist/src/routes/datasets.js.map +1 -1
  79. package/dist/src/routes/executions.d.ts +2 -1
  80. package/dist/src/routes/executions.d.ts.map +1 -1
  81. package/dist/src/routes/executions.js +60 -286
  82. package/dist/src/routes/executions.js.map +1 -1
  83. package/dist/src/routes/index.d.ts +11 -0
  84. package/dist/src/routes/index.d.ts.map +1 -0
  85. package/dist/src/routes/index.js +11 -0
  86. package/dist/src/routes/index.js.map +1 -0
  87. package/dist/src/routes/packages.d.ts +2 -1
  88. package/dist/src/routes/packages.d.ts.map +1 -1
  89. package/dist/src/routes/packages.js +42 -105
  90. package/dist/src/routes/packages.js.map +1 -1
  91. package/dist/src/routes/repository.d.ts +2 -1
  92. package/dist/src/routes/repository.d.ts.map +1 -1
  93. package/dist/src/routes/repository.js +19 -54
  94. package/dist/src/routes/repository.js.map +1 -1
  95. package/dist/src/routes/tasks.d.ts +2 -1
  96. package/dist/src/routes/tasks.d.ts.map +1 -1
  97. package/dist/src/routes/tasks.js +22 -46
  98. package/dist/src/routes/tasks.js.map +1 -1
  99. package/dist/src/routes/workspaces.d.ts +2 -1
  100. package/dist/src/routes/workspaces.d.ts.map +1 -1
  101. package/dist/src/routes/workspaces.js +45 -116
  102. package/dist/src/routes/workspaces.js.map +1 -1
  103. package/dist/src/server.d.ts +24 -3
  104. package/dist/src/server.d.ts.map +1 -1
  105. package/dist/src/server.js +178 -19
  106. package/dist/src/server.js.map +1 -1
  107. package/dist/src/types.d.ts +486 -1
  108. package/dist/src/types.d.ts.map +1 -1
  109. package/dist/src/types.js +209 -2
  110. package/dist/src/types.js.map +1 -1
  111. package/package.json +15 -3
package/README.md CHANGED
@@ -12,88 +12,183 @@ npm install @elaraai/e3-api-server
12
12
 
13
13
  REST API server exposing e3-core operations over HTTP. Uses BEAST2 binary serialization for efficient request/response encoding.
14
14
 
15
+ Supports two modes:
16
+ - **Single-repo mode**: Serve one repository, accessed via `/repos/default`
17
+ - **Multi-repo mode**: Serve multiple repositories from a directory, accessed via `/repos/:name`
18
+
15
19
  ## CLI Usage
16
20
 
17
21
  ```bash
18
- # Start server on default port 3000
19
- e3-api-server /path/to/.e3
22
+ # Single repository mode
23
+ e3-api-server --repo /path/to/repo
24
+ e3-api-server --repo /path/to/repo --port 8080 --cors
25
+
26
+ # Multi-repository mode (serves repos from subdirectories)
27
+ e3-api-server --repos /path/to/repos-dir
28
+
29
+ # With OIDC authentication
30
+ e3-api-server --repo /path/to/repo --oidc
20
31
 
21
32
  # Custom port and host
22
- e3-api-server /path/to/.e3 --port 8080 --host 0.0.0.0
33
+ e3-api-server --repo /path/to/repo --port 8080 --host 0.0.0.0
23
34
  ```
24
35
 
36
+ ### CLI Options
37
+
38
+ | Option | Description |
39
+ |--------|-------------|
40
+ | `--repo <path>` | Single repository mode - serve one repo at `/repos/default` |
41
+ | `--repos <dir>` | Multi-repo mode - serve repos from subdirectories |
42
+ | `-p, --port <port>` | HTTP port (default: 3000) |
43
+ | `-H, --host <host>` | Bind address (default: localhost) |
44
+ | `--cors` | Enable CORS for cross-origin requests |
45
+ | `--oidc` | Enable built-in OIDC authentication provider |
46
+ | `--token-expiry <duration>` | Access token expiry, e.g., "5s", "15m", "1h" (default: 1h) |
47
+ | `--refresh-token-expiry <duration>` | Refresh token expiry, e.g., "7d", "90d" (default: 90d) |
48
+
25
49
  ## Programmatic Usage
26
50
 
51
+ ### Single Repository (Embedded Server)
52
+
53
+ For embedding in applications like VS Code extensions:
54
+
27
55
  ```typescript
28
56
  import { createServer } from '@elaraai/e3-api-server';
29
57
 
30
- const server = createServer({
31
- repo: '/path/to/.e3',
58
+ // createServer is async
59
+ const server = await createServer({
60
+ singleRepoPath: '/path/to/repo',
32
61
  port: 3000,
33
62
  host: 'localhost',
63
+ cors: true, // Enable for webview/cross-origin access
34
64
  });
35
65
 
36
66
  await server.start();
37
- console.log(`Server listening on port ${server.port}`);
67
+ console.log(`Server listening on http://localhost:${server.port}`);
68
+ console.log('Access repository via: /repos/default');
38
69
 
39
70
  // Graceful shutdown
40
71
  await server.stop();
41
72
  ```
42
73
 
74
+ ### Multi-Repository Mode
75
+
76
+ For serving multiple repositories:
77
+
78
+ ```typescript
79
+ import { createServer } from '@elaraai/e3-api-server';
80
+
81
+ const server = await createServer({
82
+ reposDir: '/path/to/repos', // Each subdirectory is a repo
83
+ port: 3000,
84
+ host: 'localhost',
85
+ });
86
+
87
+ await server.start();
88
+ // Repos accessible at /repos/repo1, /repos/repo2, etc.
89
+ ```
90
+
91
+ ### With Authentication
92
+
93
+ ```typescript
94
+ import { createServer } from '@elaraai/e3-api-server';
95
+
96
+ const server = await createServer({
97
+ singleRepoPath: '/path/to/repo',
98
+ port: 3000,
99
+ oidc: {
100
+ baseUrl: 'http://localhost:3000',
101
+ tokenExpiry: '1h',
102
+ refreshTokenExpiry: '90d',
103
+ },
104
+ });
105
+
106
+ await server.start();
107
+ // OIDC endpoints available at /.well-known/*, /oauth2/*, /device
108
+ ```
109
+
110
+ ### ServerConfig Options
111
+
112
+ ```typescript
113
+ interface ServerConfig {
114
+ // Repository mode (specify exactly one)
115
+ singleRepoPath?: string; // Single repo at /repos/default
116
+ reposDir?: string; // Multi-repo from subdirectories
117
+
118
+ // Server options
119
+ port?: number; // Default: 3000
120
+ host?: string; // Default: 'localhost'
121
+ cors?: boolean; // Enable CORS (default: false)
122
+
123
+ // Authentication (optional)
124
+ auth?: AuthConfig; // External JWT validation
125
+ oidc?: OidcConfig; // Built-in OIDC provider
126
+ }
127
+ ```
128
+
43
129
  ## API Endpoints
44
130
 
131
+ All endpoints are prefixed with `/api/repos/:repo` where `:repo` is:
132
+ - `default` in single-repo mode
133
+ - The repository name in multi-repo mode
134
+
45
135
  ### Repository
46
136
 
47
137
  | Method | Endpoint | Description |
48
138
  |--------|----------|-------------|
49
- | GET | `/api/status` | Repository status (path, object/package/workspace counts) |
50
- | POST | `/api/gc` | Garbage collection |
139
+ | GET | `/api/repos` | List available repositories (multi-repo mode) |
140
+ | PUT | `/api/repos/:repo` | Create repository (multi-repo mode) |
141
+ | DELETE | `/api/repos/:repo` | Delete repository (multi-repo mode, async) |
142
+ | GET | `/api/repos/:repo/status` | Repository status (counts) |
143
+ | POST | `/api/repos/:repo/gc` | Start garbage collection (async) |
144
+ | GET | `/api/repos/:repo/gc/:id` | Get GC status |
51
145
 
52
146
  ### Packages
53
147
 
54
148
  | Method | Endpoint | Description |
55
149
  |--------|----------|-------------|
56
- | GET | `/api/packages` | List all packages |
57
- | GET | `/api/packages/:name/:version` | Get package details |
58
- | POST | `/api/packages` | Import package (zip body) |
59
- | GET | `/api/packages/:name/:version/export` | Export package as zip |
60
- | DELETE | `/api/packages/:name/:version` | Remove package |
150
+ | GET | `/api/repos/:repo/packages` | List all packages |
151
+ | GET | `/api/repos/:repo/packages/:name/:version` | Get package details |
152
+ | POST | `/api/repos/:repo/packages` | Import package (zip body) |
153
+ | GET | `/api/repos/:repo/packages/:name/:version/export` | Export package as zip |
154
+ | DELETE | `/api/repos/:repo/packages/:name/:version` | Remove package |
61
155
 
62
156
  ### Workspaces
63
157
 
64
158
  | Method | Endpoint | Description |
65
159
  |--------|----------|-------------|
66
- | GET | `/api/workspaces` | List all workspaces |
67
- | POST | `/api/workspaces` | Create workspace |
68
- | GET | `/api/workspaces/:ws` | Get workspace info |
69
- | GET | `/api/workspaces/:ws/status` | Get workspace status (datasets, tasks, summary) |
70
- | POST | `/api/workspaces/:ws/deploy` | Deploy package to workspace |
71
- | DELETE | `/api/workspaces/:ws` | Remove workspace |
160
+ | GET | `/api/repos/:repo/workspaces` | List all workspaces |
161
+ | POST | `/api/repos/:repo/workspaces` | Create workspace |
162
+ | GET | `/api/repos/:repo/workspaces/:ws` | Get workspace info |
163
+ | GET | `/api/repos/:repo/workspaces/:ws/status` | Get workspace status (datasets, tasks, summary) |
164
+ | POST | `/api/repos/:repo/workspaces/:ws/deploy` | Deploy package to workspace |
165
+ | DELETE | `/api/repos/:repo/workspaces/:ws` | Remove workspace |
166
+ | GET | `/api/repos/:repo/workspaces/:ws/export` | Export workspace as package zip |
72
167
 
73
168
  ### Datasets
74
169
 
75
170
  | Method | Endpoint | Description |
76
171
  |--------|----------|-------------|
77
- | GET | `/api/workspaces/:ws/list` | List root dataset fields |
78
- | GET | `/api/workspaces/:ws/list/*path` | List nested dataset fields |
79
- | GET | `/api/workspaces/:ws/get/*path` | Get dataset value (BEAST2) |
80
- | PUT | `/api/workspaces/:ws/set/*path` | Set dataset value (BEAST2) |
172
+ | GET | `/api/repos/:repo/workspaces/:ws/datasets` | List root datasets |
173
+ | GET | `/api/repos/:repo/workspaces/:ws/datasets/*path` | Get dataset value (BEAST2) |
174
+ | PUT | `/api/repos/:repo/workspaces/:ws/datasets/*path` | Set dataset value (BEAST2) |
81
175
 
82
176
  ### Tasks
83
177
 
84
178
  | Method | Endpoint | Description |
85
179
  |--------|----------|-------------|
86
- | GET | `/api/workspaces/:ws/tasks` | List tasks |
87
- | GET | `/api/workspaces/:ws/tasks/:task` | Get task details |
180
+ | GET | `/api/repos/:repo/workspaces/:ws/tasks` | List tasks |
181
+ | GET | `/api/repos/:repo/workspaces/:ws/tasks/:task` | Get task details |
88
182
 
89
183
  ### Execution
90
184
 
91
185
  | Method | Endpoint | Description |
92
186
  |--------|----------|-------------|
93
- | POST | `/api/workspaces/:ws/start` | Start dataflow (non-blocking) |
94
- | POST | `/api/workspaces/:ws/execute` | Execute dataflow (blocking, returns result) |
95
- | GET | `/api/workspaces/:ws/graph` | Get dependency graph |
96
- | GET | `/api/workspaces/:ws/logs/:task` | Read task logs |
187
+ | POST | `/api/repos/:repo/workspaces/:ws/dataflow/start` | Start dataflow (async, returns immediately) |
188
+ | POST | `/api/repos/:repo/workspaces/:ws/dataflow/execute` | Execute dataflow (blocking, returns result) |
189
+ | GET | `/api/repos/:repo/workspaces/:ws/dataflow/graph` | Get dependency graph |
190
+ | GET | `/api/repos/:repo/workspaces/:ws/dataflow/logs/:task` | Read task logs |
191
+ | GET | `/api/repos/:repo/workspaces/:ws/dataflow/state` | Get current execution state |
97
192
 
98
193
  ## Request/Response Format
99
194
 
@@ -113,6 +208,26 @@ Error variants include:
113
208
  - `task_not_found` - Task doesn't exist
114
209
  - `internal` - Internal server error
115
210
 
211
+ ## Using with e3-api-client
212
+
213
+ ```typescript
214
+ import { workspaceList, workspaceStatus, datasetGet } from '@elaraai/e3-api-client';
215
+
216
+ const baseUrl = 'http://localhost:3000';
217
+ const repo = 'default'; // In single-repo mode
218
+ const options = { token: '' }; // Empty token if no auth configured
219
+
220
+ // List workspaces
221
+ const workspaces = await workspaceList(baseUrl, repo, options);
222
+
223
+ // Get workspace status
224
+ const status = await workspaceStatus(baseUrl, repo, 'my-workspace', options);
225
+
226
+ // Get dataset value
227
+ const path = [{ value: 'inputs' }, { value: 'data' }];
228
+ const data = await datasetGet(baseUrl, repo, 'my-workspace', path, options);
229
+ ```
230
+
116
231
  ## License
117
232
 
118
233
  BSL 1.1. See [LICENSE.md](./LICENSE.md).
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ import type { GcResult, GcStatusResult, RepoDeleteStatusResult } from './types.js';
6
+ /**
7
+ * Create a new GC operation and return its execution ID.
8
+ */
9
+ export declare function createGcOperation(): string;
10
+ /**
11
+ * Mark a GC operation as succeeded with stats.
12
+ */
13
+ export declare function completeGcOperation(executionId: string, stats: GcResult): void;
14
+ /**
15
+ * Mark a GC operation as failed with error message.
16
+ */
17
+ export declare function failGcOperation(executionId: string, error: string): void;
18
+ /**
19
+ * Get the status of a GC operation.
20
+ * Returns null if operation doesn't exist.
21
+ */
22
+ export declare function getGcOperationStatus(executionId: string): GcStatusResult | null;
23
+ /**
24
+ * Check if a GC operation exists.
25
+ */
26
+ export declare function hasGcOperation(executionId: string): boolean;
27
+ /**
28
+ * Clear a GC operation.
29
+ * Useful for cleanup in tests.
30
+ */
31
+ export declare function clearGcOperation(executionId: string): void;
32
+ /**
33
+ * Create a new repo delete operation and return its execution ID.
34
+ */
35
+ export declare function createRepoDeleteOperation(): string;
36
+ /**
37
+ * Mark a repo delete operation as succeeded.
38
+ */
39
+ export declare function completeRepoDeleteOperation(executionId: string): void;
40
+ /**
41
+ * Mark a repo delete operation as failed with error message.
42
+ */
43
+ export declare function failRepoDeleteOperation(executionId: string, error: string): void;
44
+ /**
45
+ * Get the status of a repo delete operation.
46
+ * Returns null if operation doesn't exist.
47
+ */
48
+ export declare function getRepoDeleteOperationStatus(executionId: string): RepoDeleteStatusResult | null;
49
+ /**
50
+ * Check if a repo delete operation exists.
51
+ */
52
+ export declare function hasRepoDeleteOperation(executionId: string): boolean;
53
+ /**
54
+ * Clear a repo delete operation.
55
+ * Useful for cleanup in tests.
56
+ */
57
+ export declare function clearRepoDeleteOperation(executionId: string): void;
58
+ /**
59
+ * Clear all async operation states.
60
+ * Useful for cleanup in tests.
61
+ */
62
+ export declare function clearAllAsyncOperations(): void;
63
+ //# sourceMappingURL=async-operation-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-operation-state.d.ts","sourceRoot":"","sources":["../../src/async-operation-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAuBnF;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAa9E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOxE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAoC/E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAE1D;AAgBD;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAOlD;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAMrE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOhF;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAwB/F;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAElE;AAMD;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * In-memory state storage for async operations (GC, repo deletion).
7
+ *
8
+ * Tracks operation status for each execution, allowing clients to poll
9
+ * for progress updates during long-running operations.
10
+ *
11
+ * This serves as a development/test mock for the Step Function-based
12
+ * execution tracking in e3-aws.
13
+ */
14
+ import { randomUUID } from 'crypto';
15
+ import { variant, some, none } from '@elaraai/east';
16
+ // Key: executionId (UUID)
17
+ const gcOperations = new Map();
18
+ /**
19
+ * Create a new GC operation and return its execution ID.
20
+ */
21
+ export function createGcOperation() {
22
+ const executionId = randomUUID();
23
+ gcOperations.set(executionId, {
24
+ status: 'running',
25
+ startedAt: new Date(),
26
+ });
27
+ return executionId;
28
+ }
29
+ /**
30
+ * Mark a GC operation as succeeded with stats.
31
+ */
32
+ export function completeGcOperation(executionId, stats) {
33
+ const op = gcOperations.get(executionId);
34
+ if (op) {
35
+ op.status = 'succeeded';
36
+ op.completedAt = new Date();
37
+ op.stats = {
38
+ deletedObjects: stats.deletedObjects,
39
+ deletedPartials: stats.deletedPartials,
40
+ retainedObjects: stats.retainedObjects,
41
+ skippedYoung: stats.skippedYoung,
42
+ bytesFreed: stats.bytesFreed,
43
+ };
44
+ }
45
+ }
46
+ /**
47
+ * Mark a GC operation as failed with error message.
48
+ */
49
+ export function failGcOperation(executionId, error) {
50
+ const op = gcOperations.get(executionId);
51
+ if (op) {
52
+ op.status = 'failed';
53
+ op.completedAt = new Date();
54
+ op.error = error;
55
+ }
56
+ }
57
+ /**
58
+ * Get the status of a GC operation.
59
+ * Returns null if operation doesn't exist.
60
+ */
61
+ export function getGcOperationStatus(executionId) {
62
+ const op = gcOperations.get(executionId);
63
+ if (!op) {
64
+ return null;
65
+ }
66
+ // Convert status to East variant
67
+ let status;
68
+ switch (op.status) {
69
+ case 'running':
70
+ status = variant('running', null);
71
+ break;
72
+ case 'succeeded':
73
+ status = variant('succeeded', null);
74
+ break;
75
+ case 'failed':
76
+ status = variant('failed', null);
77
+ break;
78
+ }
79
+ // Convert stats to East option
80
+ const stats = op.stats
81
+ ? some({
82
+ deletedObjects: op.stats.deletedObjects,
83
+ deletedPartials: op.stats.deletedPartials,
84
+ retainedObjects: op.stats.retainedObjects,
85
+ skippedYoung: op.stats.skippedYoung,
86
+ bytesFreed: op.stats.bytesFreed,
87
+ })
88
+ : none;
89
+ return {
90
+ status,
91
+ stats,
92
+ error: op.error ? some(op.error) : none,
93
+ };
94
+ }
95
+ /**
96
+ * Check if a GC operation exists.
97
+ */
98
+ export function hasGcOperation(executionId) {
99
+ return gcOperations.has(executionId);
100
+ }
101
+ /**
102
+ * Clear a GC operation.
103
+ * Useful for cleanup in tests.
104
+ */
105
+ export function clearGcOperation(executionId) {
106
+ gcOperations.delete(executionId);
107
+ }
108
+ // Key: executionId (UUID)
109
+ const repoDeleteOperations = new Map();
110
+ /**
111
+ * Create a new repo delete operation and return its execution ID.
112
+ */
113
+ export function createRepoDeleteOperation() {
114
+ const executionId = randomUUID();
115
+ repoDeleteOperations.set(executionId, {
116
+ status: 'running',
117
+ startedAt: new Date(),
118
+ });
119
+ return executionId;
120
+ }
121
+ /**
122
+ * Mark a repo delete operation as succeeded.
123
+ */
124
+ export function completeRepoDeleteOperation(executionId) {
125
+ const op = repoDeleteOperations.get(executionId);
126
+ if (op) {
127
+ op.status = 'succeeded';
128
+ op.completedAt = new Date();
129
+ }
130
+ }
131
+ /**
132
+ * Mark a repo delete operation as failed with error message.
133
+ */
134
+ export function failRepoDeleteOperation(executionId, error) {
135
+ const op = repoDeleteOperations.get(executionId);
136
+ if (op) {
137
+ op.status = 'failed';
138
+ op.completedAt = new Date();
139
+ op.error = error;
140
+ }
141
+ }
142
+ /**
143
+ * Get the status of a repo delete operation.
144
+ * Returns null if operation doesn't exist.
145
+ */
146
+ export function getRepoDeleteOperationStatus(executionId) {
147
+ const op = repoDeleteOperations.get(executionId);
148
+ if (!op) {
149
+ return null;
150
+ }
151
+ // Convert status to East variant
152
+ let status;
153
+ switch (op.status) {
154
+ case 'running':
155
+ status = variant('running', null);
156
+ break;
157
+ case 'succeeded':
158
+ status = variant('succeeded', null);
159
+ break;
160
+ case 'failed':
161
+ status = variant('failed', null);
162
+ break;
163
+ }
164
+ return {
165
+ status,
166
+ error: op.error ? some(op.error) : none,
167
+ };
168
+ }
169
+ /**
170
+ * Check if a repo delete operation exists.
171
+ */
172
+ export function hasRepoDeleteOperation(executionId) {
173
+ return repoDeleteOperations.has(executionId);
174
+ }
175
+ /**
176
+ * Clear a repo delete operation.
177
+ * Useful for cleanup in tests.
178
+ */
179
+ export function clearRepoDeleteOperation(executionId) {
180
+ repoDeleteOperations.delete(executionId);
181
+ }
182
+ // =============================================================================
183
+ // Test Utilities
184
+ // =============================================================================
185
+ /**
186
+ * Clear all async operation states.
187
+ * Useful for cleanup in tests.
188
+ */
189
+ export function clearAllAsyncOperations() {
190
+ gcOperations.clear();
191
+ repoDeleteOperations.clear();
192
+ }
193
+ //# sourceMappingURL=async-operation-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-operation-state.js","sourceRoot":"","sources":["../../src/async-operation-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAqBpD,0BAA0B;AAC1B,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+B,CAAC;AAE5D;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC;IACjC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE;QAC5B,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,IAAI,IAAI,EAAE;KACtB,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,KAAe;IACtE,MAAM,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,EAAE,EAAE,CAAC;QACP,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC;QACxB,EAAE,CAAC,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,EAAE,CAAC,KAAK,GAAG;YACT,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB,EAAE,KAAa;IAChE,MAAM,EA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} from 'hono';
6
+ import type { KeyPair } from './keys.js';
7
+ /**
8
+ * Device flow configuration.
9
+ */
10
+ export interface DeviceFlowConfig {
11
+ /** Server base URL (e.g., http://localhost:3000) */
12
+ baseUrl: string;
13
+ /** RSA keypair for signing tokens */
14
+ keys: KeyPair;
15
+ /** Access token expiry in seconds (default: 3600 = 1 hour) */
16
+ accessTokenExpiry: number;
17
+ /** Refresh token expiry in seconds (default: 7776000 = 90 days) */
18
+ refreshTokenExpiry: number;
19
+ /** Auto-approve device codes (for CI testing) */
20
+ autoApprove: boolean;
21
+ }
22
+ /**
23
+ * Create device flow routes.
24
+ */
25
+ export declare function createDeviceRoutes(config: DeviceFlowConfig): Hono;
26
+ //# sourceMappingURL=device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../src/auth/device.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,WAAW,CAAC;AAYrD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iDAAiD;IACjD,WAAW,EAAE,OAAO,CAAC;CACtB;AAqCD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CA0MjE"}