@alienplatform/testing 1.4.1 → 1.5.1
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/errors.js +8 -8
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +178 -30
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/errors.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AlienError, defineError } from "@alienplatform/core";
|
|
2
|
-
import * as z from "zod/v4";
|
|
2
|
+
import * as z$1 from "zod/v4";
|
|
3
3
|
//#region src/errors.ts
|
|
4
4
|
const TestingOperationFailedError = defineError({
|
|
5
5
|
code: "TESTING_OPERATION_FAILED",
|
|
6
|
-
context: z.object({
|
|
7
|
-
operation: z.string(),
|
|
8
|
-
message: z.string(),
|
|
9
|
-
details: z.record(z.string(), z.unknown()).optional()
|
|
6
|
+
context: z$1.object({
|
|
7
|
+
operation: z$1.string(),
|
|
8
|
+
message: z$1.string(),
|
|
9
|
+
details: z$1.record(z$1.string(), z$1.unknown()).optional()
|
|
10
10
|
}),
|
|
11
11
|
message: ({ operation, message }) => `Testing operation '${operation}' failed: ${message}`,
|
|
12
12
|
retryable: false,
|
|
@@ -15,9 +15,9 @@ const TestingOperationFailedError = defineError({
|
|
|
15
15
|
});
|
|
16
16
|
const TestingUnsupportedPlatformError = defineError({
|
|
17
17
|
code: "TESTING_UNSUPPORTED_PLATFORM",
|
|
18
|
-
context: z.object({
|
|
19
|
-
platform: z.string(),
|
|
20
|
-
operation: z.string()
|
|
18
|
+
context: z$1.object({
|
|
19
|
+
platform: z$1.string(),
|
|
20
|
+
operation: z$1.string()
|
|
21
21
|
}),
|
|
22
22
|
message: ({ platform, operation }) => `Unsupported platform '${platform}' for testing operation '${operation}'`,
|
|
23
23
|
retryable: false,
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { AlienError, defineError } from \"@alienplatform/core\"\nimport * as z from \"zod/v4\"\n\nexport const TestingOperationFailedError = defineError({\n code: \"TESTING_OPERATION_FAILED\",\n context: z.object({\n operation: z.string(),\n message: z.string(),\n details: z.record(z.string(), z.unknown()).optional(),\n }),\n message: ({ operation, message }) => `Testing operation '${operation}' failed: ${message}`,\n retryable: false,\n internal: false,\n httpStatusCode: 500,\n})\n\nexport const TestingUnsupportedPlatformError = defineError({\n code: \"TESTING_UNSUPPORTED_PLATFORM\",\n context: z.object({\n platform: z.string(),\n operation: z.string(),\n }),\n message: ({ platform, operation }) =>\n `Unsupported platform '${platform}' for testing operation '${operation}'`,\n retryable: false,\n internal: false,\n httpStatusCode: 400,\n})\n\nexport async function withTestingContext(\n error: unknown,\n operation: string,\n message: string,\n details?: Record<string, unknown>,\n): Promise<AlienError<any>> {\n return (await AlienError.from(error)).withContext(\n TestingOperationFailedError.create({\n operation,\n message,\n details,\n }),\n )\n}\n"],"mappings":";;;AAGA,MAAa,8BAA8B,YAAY;CACrD,MAAM;CACN,
|
|
1
|
+
{"version":3,"file":"errors.js","names":["z"],"sources":["../src/errors.ts"],"sourcesContent":["import { AlienError, defineError } from \"@alienplatform/core\"\nimport * as z from \"zod/v4\"\n\nexport const TestingOperationFailedError = defineError({\n code: \"TESTING_OPERATION_FAILED\",\n context: z.object({\n operation: z.string(),\n message: z.string(),\n details: z.record(z.string(), z.unknown()).optional(),\n }),\n message: ({ operation, message }) => `Testing operation '${operation}' failed: ${message}`,\n retryable: false,\n internal: false,\n httpStatusCode: 500,\n})\n\nexport const TestingUnsupportedPlatformError = defineError({\n code: \"TESTING_UNSUPPORTED_PLATFORM\",\n context: z.object({\n platform: z.string(),\n operation: z.string(),\n }),\n message: ({ platform, operation }) =>\n `Unsupported platform '${platform}' for testing operation '${operation}'`,\n retryable: false,\n internal: false,\n httpStatusCode: 400,\n})\n\nexport async function withTestingContext(\n error: unknown,\n operation: string,\n message: string,\n details?: Record<string, unknown>,\n): Promise<AlienError<any>> {\n return (await AlienError.from(error)).withContext(\n TestingOperationFailedError.create({\n operation,\n message,\n details,\n }),\n )\n}\n"],"mappings":";;;AAGA,MAAa,8BAA8B,YAAY;CACrD,MAAM;CACN,SAASA,IAAE,OAAO;EAChB,WAAWA,IAAE,OAAO;EACpB,SAASA,IAAE,OAAO;EAClB,SAASA,IAAE,OAAOA,IAAE,OAAO,GAAGA,IAAE,QAAQ,CAAC,EAAE,SAAS;CACtD,CAAC;CACD,UAAU,EAAE,WAAW,cAAc,sBAAsB,UAAU,YAAY;CACjF,WAAW;CACX,UAAU;CACV,gBAAgB;AAClB,CAAC;AAED,MAAa,kCAAkC,YAAY;CACzD,MAAM;CACN,SAASA,IAAE,OAAO;EAChB,UAAUA,IAAE,OAAO;EACnB,WAAWA,IAAE,OAAO;CACtB,CAAC;CACD,UAAU,EAAE,UAAU,gBACpB,yBAAyB,SAAS,2BAA2B,UAAU;CACzE,WAAW;CACX,UAAU;CACV,gBAAgB;AAClB,CAAC;AAED,eAAsB,mBACpB,OACA,WACA,SACA,SAC0B;CAC1B,QAAQ,MAAM,WAAW,KAAK,KAAK,GAAG,YACpC,4BAA4B,OAAO;EACjC;EACA;EACA;CACF,CAAC,CACH;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as node_child_process0 from "node:child_process";
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
4
|
-
import * as z from "zod
|
|
2
|
+
import * as z$1 from "zod/v4";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
import * as z$2 from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/types.d.ts
|
|
7
7
|
|
|
@@ -121,44 +121,192 @@ declare class Deployment {
|
|
|
121
121
|
*/
|
|
122
122
|
declare function deploy(options: DeployOptions): Promise<Deployment>;
|
|
123
123
|
//#endregion
|
|
124
|
+
//#region ../core/dist/index.d.ts
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/generated/zod/alien-error-schema.d.ts
|
|
127
|
+
/**
|
|
128
|
+
* @description Canonical error container that provides a structured way to represent errors\nwith rich metadata including error codes, human-readable messages, context,\nand chaining capabilities for error propagation.\n\nThis struct is designed to be both machine-readable and user-friendly,\nsupporting serialization for API responses and detailed error reporting\nin distributed systems.
|
|
129
|
+
*/
|
|
130
|
+
declare const AlienErrorSchema: z$2.ZodObject<{
|
|
131
|
+
code: z$2.ZodString;
|
|
132
|
+
context: z$2.ZodOptional<z$2.ZodAny>;
|
|
133
|
+
hint: z$2.ZodOptional<z$2.ZodNullable<z$2.ZodString>>;
|
|
134
|
+
httpStatusCode: z$2.ZodOptional<z$2.ZodNullable<z$2.ZodInt>>;
|
|
135
|
+
internal: z$2.ZodBoolean;
|
|
136
|
+
message: z$2.ZodString;
|
|
137
|
+
retryable: z$2.ZodDefault<z$2.ZodBoolean>;
|
|
138
|
+
source: z$2.ZodOptional<z$2.ZodAny>;
|
|
139
|
+
}, z$2.core.$strip>;
|
|
140
|
+
type AlienError$1 = z$2.infer<typeof AlienErrorSchema>;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/generated/zod/alien-event-schema.d.ts
|
|
143
|
+
/**
|
|
144
|
+
* @description Represents all possible events in the Alien system
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/error.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* Base interface that all error type definitions must implement.
|
|
151
|
+
*
|
|
152
|
+
* This provides the structure for creating type-safe error definitions
|
|
153
|
+
* with Zod validation and contextual information.
|
|
154
|
+
*
|
|
155
|
+
* @template TContext - Zod schema type for the error context
|
|
156
|
+
*/
|
|
157
|
+
interface AlienErrorMetadata<TContext extends z.ZodTypeAny> {
|
|
158
|
+
/** Unique error code (e.g., "DATABASE_CONNECTION_FAILED") */
|
|
159
|
+
code: string;
|
|
160
|
+
/** Zod schema for type-safe context validation */
|
|
161
|
+
context: TContext;
|
|
162
|
+
/** Whether this error can be retried */
|
|
163
|
+
retryable: boolean;
|
|
164
|
+
/** Whether this error contains sensitive information */
|
|
165
|
+
internal: boolean;
|
|
166
|
+
/** HTTP status code for API responses */
|
|
167
|
+
httpStatusCode?: number;
|
|
168
|
+
/** Worker to generate human-readable error message from context */
|
|
169
|
+
message: (context: z.infer<TContext>) => string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Helper function to create type-safe error definitions.
|
|
173
|
+
*
|
|
174
|
+
* This function provides a clean API for defining reusable error types
|
|
175
|
+
* with full TypeScript type safety and Zod validation.
|
|
176
|
+
*
|
|
177
|
+
* @template TContext - Zod schema type for the error context
|
|
178
|
+
* @param metadata - Error metadata including code, schema, and message generator
|
|
179
|
+
* @returns Object with metadata and a create function for error instances
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const UserNotFound = defineError({
|
|
184
|
+
* code: "USER_NOT_FOUND",
|
|
185
|
+
* context: z.object({
|
|
186
|
+
* userId: z.string(),
|
|
187
|
+
* searchMethod: z.string(),
|
|
188
|
+
* }),
|
|
189
|
+
* message: ({ userId, searchMethod }) =>
|
|
190
|
+
* `User '${userId}' not found using method '${searchMethod}'`,
|
|
191
|
+
* retryable: false,
|
|
192
|
+
* internal: false,
|
|
193
|
+
* httpStatusCode: 404,
|
|
194
|
+
* })
|
|
195
|
+
*
|
|
196
|
+
* // Usage
|
|
197
|
+
* const error = UserNotFound.create({
|
|
198
|
+
* userId: "123",
|
|
199
|
+
* searchMethod: "database_lookup"
|
|
200
|
+
* })
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Represents a specific error instance with its context.
|
|
206
|
+
*
|
|
207
|
+
* This is created by calling `.create()` on an error definition
|
|
208
|
+
* and contains the actual context data for a specific error occurrence.
|
|
209
|
+
*
|
|
210
|
+
* @template TContext - Zod schema type for the error context
|
|
211
|
+
*/
|
|
212
|
+
interface AlienErrorDefinition<TContext extends z.ZodTypeAny> {
|
|
213
|
+
metadata: AlienErrorMetadata<TContext>;
|
|
214
|
+
contextSchema: TContext;
|
|
215
|
+
context: z.infer<TContext>;
|
|
216
|
+
/**
|
|
217
|
+
* Convert this error definition directly to AlienErrorOptions.
|
|
218
|
+
*
|
|
219
|
+
* This allows you to get the wire format representation
|
|
220
|
+
* without creating an AlienError instance first.
|
|
221
|
+
*
|
|
222
|
+
* @returns AlienErrorOptions object representing this error
|
|
223
|
+
*/
|
|
224
|
+
toOptions(): AlienError$1;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Main AlienError class that provides structured error handling.
|
|
228
|
+
*
|
|
229
|
+
* This class extends the standard JavaScript Error with additional features:
|
|
230
|
+
* - Type-safe context data
|
|
231
|
+
* - Error chaining and source tracking
|
|
232
|
+
* - Retryability and internal/external visibility flags
|
|
233
|
+
* - HTTP status code mapping
|
|
234
|
+
* - Sanitization for external APIs
|
|
235
|
+
*
|
|
236
|
+
* @template TContext - Zod schema type for the error context
|
|
237
|
+
*
|
|
238
|
+
* @example Basic Construction
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const error = new AlienError(DatabaseError.create({
|
|
241
|
+
* host: "localhost",
|
|
242
|
+
* port: 5432,
|
|
243
|
+
* reason: "Timeout"
|
|
244
|
+
* }))
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @example Converting JavaScript Errors
|
|
248
|
+
* ```typescript
|
|
249
|
+
* try {
|
|
250
|
+
* JSON.parse("invalid json")
|
|
251
|
+
* } catch (jsError) {
|
|
252
|
+
* const alienError = AlienError.from(jsError)
|
|
253
|
+
* console.log(alienError.code) // "GENERIC_ERROR"
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @example Error Chaining
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const contextualError = AlienError.from(new Error("Network timeout"))
|
|
260
|
+
* .withContext(DatabaseError.create({
|
|
261
|
+
* host: "localhost",
|
|
262
|
+
* port: 5432,
|
|
263
|
+
* reason: "Connection timeout"
|
|
264
|
+
* }))
|
|
265
|
+
*
|
|
266
|
+
* // Check error chain
|
|
267
|
+
* console.log(contextualError.hasErrorCode("DATABASE_CONNECTION_FAILED")) // true
|
|
268
|
+
* console.log(contextualError.toString()) // Shows full error chain
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
//#endregion
|
|
124
272
|
//#region src/errors.d.ts
|
|
125
273
|
declare const TestingOperationFailedError: {
|
|
126
|
-
metadata:
|
|
127
|
-
operation: z.ZodString;
|
|
128
|
-
message: z.ZodString;
|
|
129
|
-
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
130
|
-
}, z.core.$strip>>;
|
|
131
|
-
contextSchema: z.ZodObject<{
|
|
132
|
-
operation: z.ZodString;
|
|
133
|
-
message: z.ZodString;
|
|
134
|
-
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
135
|
-
}, z.core.$strip>;
|
|
274
|
+
metadata: AlienErrorMetadata<z$1.ZodObject<{
|
|
275
|
+
operation: z$1.ZodString;
|
|
276
|
+
message: z$1.ZodString;
|
|
277
|
+
details: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
278
|
+
}, z$1.core.$strip>>;
|
|
279
|
+
contextSchema: z$1.ZodObject<{
|
|
280
|
+
operation: z$1.ZodString;
|
|
281
|
+
message: z$1.ZodString;
|
|
282
|
+
details: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
283
|
+
}, z$1.core.$strip>;
|
|
136
284
|
create: (context: {
|
|
137
285
|
operation: string;
|
|
138
286
|
message: string;
|
|
139
287
|
details?: Record<string, unknown> | undefined;
|
|
140
|
-
}) =>
|
|
141
|
-
operation: z.ZodString;
|
|
142
|
-
message: z.ZodString;
|
|
143
|
-
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
144
|
-
}, z.core.$strip>>;
|
|
288
|
+
}) => AlienErrorDefinition<z$1.ZodObject<{
|
|
289
|
+
operation: z$1.ZodString;
|
|
290
|
+
message: z$1.ZodString;
|
|
291
|
+
details: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
292
|
+
}, z$1.core.$strip>>;
|
|
145
293
|
};
|
|
146
294
|
declare const TestingUnsupportedPlatformError: {
|
|
147
|
-
metadata:
|
|
148
|
-
platform: z.ZodString;
|
|
149
|
-
operation: z.ZodString;
|
|
150
|
-
}, z.core.$strip>>;
|
|
151
|
-
contextSchema: z.ZodObject<{
|
|
152
|
-
platform: z.ZodString;
|
|
153
|
-
operation: z.ZodString;
|
|
154
|
-
}, z.core.$strip>;
|
|
295
|
+
metadata: AlienErrorMetadata<z$1.ZodObject<{
|
|
296
|
+
platform: z$1.ZodString;
|
|
297
|
+
operation: z$1.ZodString;
|
|
298
|
+
}, z$1.core.$strip>>;
|
|
299
|
+
contextSchema: z$1.ZodObject<{
|
|
300
|
+
platform: z$1.ZodString;
|
|
301
|
+
operation: z$1.ZodString;
|
|
302
|
+
}, z$1.core.$strip>;
|
|
155
303
|
create: (context: {
|
|
156
304
|
platform: string;
|
|
157
305
|
operation: string;
|
|
158
|
-
}) =>
|
|
159
|
-
platform: z.ZodString;
|
|
160
|
-
operation: z.ZodString;
|
|
161
|
-
}, z.core.$strip>>;
|
|
306
|
+
}) => AlienErrorDefinition<z$1.ZodObject<{
|
|
307
|
+
platform: z$1.ZodString;
|
|
308
|
+
operation: z$1.ZodString;
|
|
309
|
+
}, z$1.core.$strip>>;
|
|
162
310
|
};
|
|
163
311
|
//#endregion
|
|
164
312
|
export { type DeployOptions, Deployment, type DeploymentInfo, type EnvironmentVariable, type Platform, TestingOperationFailedError, TestingUnsupportedPlatformError, type UpgradeOptions, deploy };
|