@wentools/schema-migrations 0.1.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/LICENSE +21 -0
- package/README.md +141 -0
- package/esm/create_migration.d.ts +31 -0
- package/esm/create_migration.d.ts.map +1 -0
- package/esm/create_migration.js +31 -0
- package/esm/create_migrations.d.ts +71 -0
- package/esm/create_migrations.d.ts.map +1 -0
- package/esm/create_migrations.js +58 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/err.js +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts +11 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.js +14 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts +156 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/mod.js +65 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts +28 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.js +30 -0
- package/esm/migrate.d.ts +51 -0
- package/esm/migrate.d.ts.map +1 -0
- package/esm/migrate.js +65 -0
- package/esm/migrate_one_step.d.ts +35 -0
- package/esm/migrate_one_step.d.ts.map +1 -0
- package/esm/migrate_one_step.js +37 -0
- package/esm/migrate_range.d.ts +65 -0
- package/esm/migrate_range.d.ts.map +1 -0
- package/esm/migrate_range.js +51 -0
- package/esm/mod.d.ts +23 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +23 -0
- package/esm/package.json +3 -0
- package/esm/with_version.d.ts +22 -0
- package/esm/with_version.d.ts.map +1 -0
- package/esm/with_version.js +23 -0
- package/package.json +34 -0
- package/script/create_migration.d.ts +31 -0
- package/script/create_migration.d.ts.map +1 -0
- package/script/create_migration.js +34 -0
- package/script/create_migrations.d.ts +71 -0
- package/script/create_migrations.d.ts.map +1 -0
- package/script/create_migrations.js +61 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts +38 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/err.js +41 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts +11 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.js +17 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts +156 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/mod.js +77 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts +28 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.js +33 -0
- package/script/migrate.d.ts +51 -0
- package/script/migrate.d.ts.map +1 -0
- package/script/migrate.js +68 -0
- package/script/migrate_one_step.d.ts +35 -0
- package/script/migrate_one_step.d.ts.map +1 -0
- package/script/migrate_one_step.js +40 -0
- package/script/migrate_range.d.ts +65 -0
- package/script/migrate_range.d.ts.map +1 -0
- package/script/migrate_range.js +54 -0
- package/script/mod.d.ts +23 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +32 -0
- package/script/package.json +3 -0
- package/script/with_version.d.ts +22 -0
- package/script/with_version.d.ts.map +1 -0
- package/script/with_version.js +26 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMigration = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a typed migration step with schema inference
|
|
6
|
+
*
|
|
7
|
+
* Helper function that pairs a schema with its migration function,
|
|
8
|
+
* providing type inference for the migration function input.
|
|
9
|
+
*
|
|
10
|
+
* **Type Safety:** The returned tuple is typed as readonly to ensure
|
|
11
|
+
* compile-time validation of migration chain ordering in createMigrations.
|
|
12
|
+
*
|
|
13
|
+
* @param fromSchema - Schema for input version (used for type inference)
|
|
14
|
+
* @param toSchema - Schema for output version
|
|
15
|
+
* @param migrate - Migration function from TFrom to TTo
|
|
16
|
+
* @returns Readonly tuple of [schema, migrateFn] ready for createMigrations
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const v0Schema = z.object({ name: z.string() })
|
|
21
|
+
* const v1Schema = z.object({ name: z.string(), description: z.string() })
|
|
22
|
+
*
|
|
23
|
+
* const addDescription = createMigration(v0Schema, v1Schema, (v0) => ({
|
|
24
|
+
* ...v0,
|
|
25
|
+
* description: '', // v0 is typed as { name: string }
|
|
26
|
+
* }))
|
|
27
|
+
*
|
|
28
|
+
* const migrations = createMigrations(v0Schema, [addDescription])
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const createMigration = (fromSchema, toSchema, migrate) => {
|
|
32
|
+
return [toSchema, migrate];
|
|
33
|
+
};
|
|
34
|
+
exports.createMigration = createMigration;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ZodTypeAny } from 'zod';
|
|
2
|
+
import type { MigrationConfig } from './migrate_range.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extract output type from a ZodType using the _output property
|
|
5
|
+
*/
|
|
6
|
+
type ExtractOutput<T> = T extends {
|
|
7
|
+
_output: infer TOutput;
|
|
8
|
+
} ? TOutput : never;
|
|
9
|
+
/**
|
|
10
|
+
* Validates migration chain type safety at compile time
|
|
11
|
+
*
|
|
12
|
+
* Recursively checks that each migration's input type matches the previous migration's output.
|
|
13
|
+
* Returns the same tuple type if valid, or `never` if the chain is invalid.
|
|
14
|
+
*
|
|
15
|
+
* Uses structural typing to match against function signatures rather than exact types,
|
|
16
|
+
* making it compatible with TypeScript's type inference for complex Zod schemas.
|
|
17
|
+
*
|
|
18
|
+
* @template TInitial - Expected input type for first migration
|
|
19
|
+
* @template TSteps - Tuple of migration steps to validate
|
|
20
|
+
* @returns The same tuple type if valid, `never` if invalid (causing a compile error)
|
|
21
|
+
*/
|
|
22
|
+
type ValidChain<TInitial, TSteps extends readonly unknown[]> = TSteps extends readonly [] ? readonly [] : TSteps extends readonly [infer TFirst, ...infer TRest] ? TFirst extends readonly [infer _TSchema, infer TFn] ? TFn extends (from: TInitial) => infer TNext ? readonly [TFirst, ...ValidChain<TNext, TRest>] : never : never : never;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the final output type from a migration chain
|
|
25
|
+
*
|
|
26
|
+
* @template TInitial - Type of the initial schema (v0)
|
|
27
|
+
* @template TSteps - Tuple of migration steps
|
|
28
|
+
* @returns The output type of the last migration, or TInitial if no migrations
|
|
29
|
+
*/
|
|
30
|
+
type FinalType<TInitial, TSteps extends readonly unknown[]> = TSteps extends readonly [] ? TInitial : TSteps extends readonly [...unknown[], readonly [unknown, (from: any) => infer TFinal]] ? TFinal : never;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a type-safe migration configuration from initial schema and migration steps
|
|
33
|
+
*
|
|
34
|
+
* **Type Safety:** The migration chain is validated at compile time. Each migration
|
|
35
|
+
* must accept the output type of the previous migration. Reordering or mismatched
|
|
36
|
+
* migrations will cause TypeScript errors.
|
|
37
|
+
*
|
|
38
|
+
* @param initialSchema - Schema for version 0
|
|
39
|
+
* @param steps - Array of [schema, migrateFn] tuples, each typed to accept previous output
|
|
40
|
+
* @returns Complete migration configuration ready for use with migrate()
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const v0Schema = z.object({ name: z.string() })
|
|
45
|
+
* const v1Schema = z.object({ name: z.string(), description: z.string() })
|
|
46
|
+
* const v2Schema = z.object({ name: z.string(), description: z.string(), capacity: z.number() })
|
|
47
|
+
*
|
|
48
|
+
* // ✅ Valid - each migration accepts previous output
|
|
49
|
+
* const eventMigrations = createMigrations(v0Schema, [
|
|
50
|
+
* createMigration(v0Schema, v1Schema, (v0) => ({ ...v0, description: '' })), // v0 → v1
|
|
51
|
+
* createMigration(v1Schema, v2Schema, (v1) => ({ ...v1, capacity: 100 })), // v1 → v2
|
|
52
|
+
* ])
|
|
53
|
+
*
|
|
54
|
+
* // ❌ Type Error - wrong order! Second migration expects v1 but gets v0
|
|
55
|
+
* const badMigrations = createMigrations(v0Schema, [
|
|
56
|
+
* createMigration(v1Schema, v2Schema, (v1) => ({ ...v1, capacity: 100 })), // Expects v1, gets v0
|
|
57
|
+
* createMigration(v0Schema, v1Schema, (v0) => ({ ...v0, description: '' })),
|
|
58
|
+
* ])
|
|
59
|
+
*
|
|
60
|
+
* // Result:
|
|
61
|
+
* // {
|
|
62
|
+
* // schemas: [v0Schema, v1Schema, v2Schema],
|
|
63
|
+
* // migrations: [migrate0→1, migrate1→2],
|
|
64
|
+
* // currentVersion: 2,
|
|
65
|
+
* // currentSchema: v2Schema
|
|
66
|
+
* // }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare const createMigrations: <TInitialSchema extends ZodTypeAny, const TSteps extends readonly unknown[]>(initialSchema: TInitialSchema, steps: TSteps & ValidChain<ExtractOutput<TInitialSchema>, TSteps>) => MigrationConfig<FinalType<ExtractOutput<TInitialSchema>, TSteps>>;
|
|
70
|
+
export { createMigrations, type ValidChain, type FinalType };
|
|
71
|
+
//# sourceMappingURL=create_migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_migrations.d.ts","sourceRoot":"","sources":["../src/create_migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,KAAK,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEzD;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAA;AAE9E;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,CAAC,QAAQ,EAAE,MAAM,SAAS,SAAS,OAAO,EAAE,IAAI,MAAM,SAAS,SAAS,EAAE,GACtF,SAAS,EAAE,GACX,MAAM,SAAS,SAAS,CAAC,MAAM,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,GACrD,MAAM,SAAS,SAAS,CAAC,MAAM,QAAQ,EAAE,MAAM,GAAG,CAAC,GAClD,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,KAAK,GAC1C,SAAS,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAC9C,KAAK,GACN,KAAK,GACN,KAAK,CAAA;AAET;;;;;;GAMG;AACH,KAAK,SAAS,CAAC,QAAQ,EAAE,MAAM,SAAS,SAAS,OAAO,EAAE,IAAI,MAAM,SAAS,SAAS,EAAE,GACrF,QAAQ,GACR,MAAM,SAAS,SAAS,CAAC,GAAG,OAAO,EAAE,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,MAAM,CAAC,CAAC,GACtF,MAAM,GACN,KAAK,CAAA;AAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,QAAA,MAAM,gBAAgB,GACrB,cAAc,SAAS,UAAU,EACjC,KAAK,CAAC,MAAM,SAAS,SAAS,OAAO,EAAE,EAEvC,eAAe,cAAc,EAC7B,OAAO,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,KAC/D,eAAe,CAAC,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,CA0BlE,CAAA;AAED,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMigrations = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a type-safe migration configuration from initial schema and migration steps
|
|
6
|
+
*
|
|
7
|
+
* **Type Safety:** The migration chain is validated at compile time. Each migration
|
|
8
|
+
* must accept the output type of the previous migration. Reordering or mismatched
|
|
9
|
+
* migrations will cause TypeScript errors.
|
|
10
|
+
*
|
|
11
|
+
* @param initialSchema - Schema for version 0
|
|
12
|
+
* @param steps - Array of [schema, migrateFn] tuples, each typed to accept previous output
|
|
13
|
+
* @returns Complete migration configuration ready for use with migrate()
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const v0Schema = z.object({ name: z.string() })
|
|
18
|
+
* const v1Schema = z.object({ name: z.string(), description: z.string() })
|
|
19
|
+
* const v2Schema = z.object({ name: z.string(), description: z.string(), capacity: z.number() })
|
|
20
|
+
*
|
|
21
|
+
* // ✅ Valid - each migration accepts previous output
|
|
22
|
+
* const eventMigrations = createMigrations(v0Schema, [
|
|
23
|
+
* createMigration(v0Schema, v1Schema, (v0) => ({ ...v0, description: '' })), // v0 → v1
|
|
24
|
+
* createMigration(v1Schema, v2Schema, (v1) => ({ ...v1, capacity: 100 })), // v1 → v2
|
|
25
|
+
* ])
|
|
26
|
+
*
|
|
27
|
+
* // ❌ Type Error - wrong order! Second migration expects v1 but gets v0
|
|
28
|
+
* const badMigrations = createMigrations(v0Schema, [
|
|
29
|
+
* createMigration(v1Schema, v2Schema, (v1) => ({ ...v1, capacity: 100 })), // Expects v1, gets v0
|
|
30
|
+
* createMigration(v0Schema, v1Schema, (v0) => ({ ...v0, description: '' })),
|
|
31
|
+
* ])
|
|
32
|
+
*
|
|
33
|
+
* // Result:
|
|
34
|
+
* // {
|
|
35
|
+
* // schemas: [v0Schema, v1Schema, v2Schema],
|
|
36
|
+
* // migrations: [migrate0→1, migrate1→2],
|
|
37
|
+
* // currentVersion: 2,
|
|
38
|
+
* // currentSchema: v2Schema
|
|
39
|
+
* // }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const createMigrations = (initialSchema, steps) => {
|
|
43
|
+
// Build schemas array: [initial, ...step schemas]
|
|
44
|
+
const schemas = [
|
|
45
|
+
initialSchema,
|
|
46
|
+
...steps.map(([schema]) => schema),
|
|
47
|
+
];
|
|
48
|
+
// Extract migration functions from steps
|
|
49
|
+
const migrations = steps.map(([, migrate]) => migrate);
|
|
50
|
+
// Current version is the index of the last schema
|
|
51
|
+
const currentVersion = schemas.length - 1;
|
|
52
|
+
// Current schema is the last schema in the array
|
|
53
|
+
const currentSchema = schemas[currentVersion];
|
|
54
|
+
return {
|
|
55
|
+
schemas,
|
|
56
|
+
migrations,
|
|
57
|
+
currentVersion,
|
|
58
|
+
currentSchema,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.createMigrations = createMigrations;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Err } from 'neverthrow';
|
|
2
|
+
/**
|
|
3
|
+
* Create an Err Result with automatic literal type preservation
|
|
4
|
+
*
|
|
5
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
6
|
+
* No need for 'as const' - the type parameter is inferred as a literal!
|
|
7
|
+
*
|
|
8
|
+
* Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // ✅ Simple error
|
|
12
|
+
* return err('not_found', 'User not found')
|
|
13
|
+
* // Type: Err<never, { type: 'not_found', message: string }>
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // ✅ Error with additional properties
|
|
17
|
+
* return err('not_found', 'User not found', { userId: '123' })
|
|
18
|
+
* // Type: Err<never, { type: 'not_found', message: string, userId: string }>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // ✅ Direct .error access (no narrowing needed)
|
|
22
|
+
* const error = err('not_found', 'User not found').error
|
|
23
|
+
* // error.type is 'not_found'
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // ✅ Error with complex additional data
|
|
27
|
+
* return err('validation_failed', 'Invalid input', {
|
|
28
|
+
* field: 'email',
|
|
29
|
+
* errors: ['Invalid format']
|
|
30
|
+
* })
|
|
31
|
+
* // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
32
|
+
*/
|
|
33
|
+
declare const err: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => Err<never, {
|
|
34
|
+
type: TType;
|
|
35
|
+
message: string;
|
|
36
|
+
} & TAdditional>;
|
|
37
|
+
export { err };
|
|
38
|
+
//# sourceMappingURL=err.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/err/err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,GAAG,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,QAAA,MAAM,GAAG,GACR,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnE,MAAM,KAAK,EACX,SAAS,MAAM,EACf,aAAa,WAAW,KACtB,GAAG,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAKP,CAAA;AAErD,OAAO,EAAE,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.err = void 0;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
/**
|
|
6
|
+
* Create an Err Result with automatic literal type preservation
|
|
7
|
+
*
|
|
8
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
9
|
+
* No need for 'as const' - the type parameter is inferred as a literal!
|
|
10
|
+
*
|
|
11
|
+
* Returns Err<never, E> (not Result<never, E>) so .error is directly accessible.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // ✅ Simple error
|
|
15
|
+
* return err('not_found', 'User not found')
|
|
16
|
+
* // Type: Err<never, { type: 'not_found', message: string }>
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // ✅ Error with additional properties
|
|
20
|
+
* return err('not_found', 'User not found', { userId: '123' })
|
|
21
|
+
* // Type: Err<never, { type: 'not_found', message: string, userId: string }>
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // ✅ Direct .error access (no narrowing needed)
|
|
25
|
+
* const error = err('not_found', 'User not found').error
|
|
26
|
+
* // error.type is 'not_found'
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // ✅ Error with complex additional data
|
|
30
|
+
* return err('validation_failed', 'Invalid input', {
|
|
31
|
+
* field: 'email',
|
|
32
|
+
* errors: ['Invalid format']
|
|
33
|
+
* })
|
|
34
|
+
* // Type: Err<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
35
|
+
*/
|
|
36
|
+
const err = (type, message, additional) => (0, neverthrow_1.err)({
|
|
37
|
+
...additional,
|
|
38
|
+
type,
|
|
39
|
+
message,
|
|
40
|
+
});
|
|
41
|
+
exports.err = err;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/err/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is a neverthrow Result type
|
|
3
|
+
*
|
|
4
|
+
* Uses duck typing to detect Result objects without importing neverthrow types.
|
|
5
|
+
*/
|
|
6
|
+
declare const isResult: (value: unknown) => value is {
|
|
7
|
+
isOk: () => boolean;
|
|
8
|
+
isErr: () => boolean;
|
|
9
|
+
};
|
|
10
|
+
export { isResult };
|
|
11
|
+
//# sourceMappingURL=is_result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is_result.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/is_result/is_result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAA,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAA;CAStF,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Check if a value is a neverthrow Result type
|
|
4
|
+
*
|
|
5
|
+
* Uses duck typing to detect Result objects without importing neverthrow types.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isResult = void 0;
|
|
9
|
+
const isResult = (value) => {
|
|
10
|
+
return (value !== null &&
|
|
11
|
+
typeof value === 'object' &&
|
|
12
|
+
'isOk' in value &&
|
|
13
|
+
'isErr' in value &&
|
|
14
|
+
typeof value.isOk === 'function' &&
|
|
15
|
+
typeof value.isErr === 'function');
|
|
16
|
+
};
|
|
17
|
+
exports.isResult = isResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/is_result/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isResult = void 0;
|
|
4
|
+
var is_result_js_1 = require("./is_result.js");
|
|
5
|
+
Object.defineProperty(exports, "isResult", { enumerable: true, get: function () { return is_result_js_1.isResult; } });
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { err as _Err, ok, type Result, type Err, ResultAsync, okAsync as neverthrowOkAsync } from 'neverthrow';
|
|
2
|
+
/**
|
|
3
|
+
* Create an error object with literal type preservation
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const error = makeErr('not_found', 'User not found')
|
|
7
|
+
* // ✅ Type: { type: 'not_found', message: string }
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const error = makeErr('not_found', 'User not found', { userId: '123' })
|
|
11
|
+
* // ✅ Type: { type: 'not_found', message: string, userId: string }
|
|
12
|
+
*/
|
|
13
|
+
declare const makeErr: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => {
|
|
14
|
+
type: TType;
|
|
15
|
+
message: string;
|
|
16
|
+
} & TAdditional;
|
|
17
|
+
/**
|
|
18
|
+
* Create an async Err ResultAsync with automatic literal type preservation
|
|
19
|
+
*
|
|
20
|
+
* Async version of err() - same signature, returns ResultAsync instead of Result.
|
|
21
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // ✅ Simple error
|
|
25
|
+
* return errAsync('not_found', 'User not found')
|
|
26
|
+
* // Type: ResultAsync<never, { type: 'not_found', message: string }>
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // ✅ Error with additional properties
|
|
30
|
+
* return errAsync('not_found', 'User not found', { userId: '123' })
|
|
31
|
+
* // Type: ResultAsync<never, { type: 'not_found', message: string, userId: string }>
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // ✅ Error with complex additional data
|
|
35
|
+
* return errAsync('validation_failed', 'Invalid input', {
|
|
36
|
+
* field: 'email',
|
|
37
|
+
* errors: ['Invalid format']
|
|
38
|
+
* })
|
|
39
|
+
* // Type: ResultAsync<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
40
|
+
*/
|
|
41
|
+
declare const errAsync: <const TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>>(type: TType, message: string, additional?: TAdditional) => ResultAsync<never, {
|
|
42
|
+
type: TType;
|
|
43
|
+
message: string;
|
|
44
|
+
} & TAdditional>;
|
|
45
|
+
/**
|
|
46
|
+
* Re-export okAsync from neverthrow for consistency
|
|
47
|
+
* Creates a successful ResultAsync
|
|
48
|
+
*/
|
|
49
|
+
declare const okAsync: typeof neverthrowOkAsync;
|
|
50
|
+
/**
|
|
51
|
+
* Utility type for defining error types concisely
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Instead of:
|
|
55
|
+
* type UserNotFoundError = {
|
|
56
|
+
* type: 'user_not_found'
|
|
57
|
+
* message: string
|
|
58
|
+
* userId: UserId
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* // Write:
|
|
62
|
+
* type UserNotFoundError = ErrorType<'user_not_found', { userId: UserId }>
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Error without additional properties:
|
|
66
|
+
* type InvalidOperationError = ErrorType<'invalid_operation'>
|
|
67
|
+
*/
|
|
68
|
+
type ErrorType<TType extends string, TAdditional extends Record<string, unknown> = Record<string, never>> = {
|
|
69
|
+
type: TType;
|
|
70
|
+
message: string;
|
|
71
|
+
} & TAdditional;
|
|
72
|
+
/**
|
|
73
|
+
* Extract the error type from a Result or Promise<Result>
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // From async function
|
|
77
|
+
* const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
|
|
78
|
+
* type GetUserError = ExtractError<ReturnType<typeof getUser>>
|
|
79
|
+
* // Type: UserNotFoundError
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // From Result type directly
|
|
83
|
+
* type MyResult = Result<User, InvalidError>
|
|
84
|
+
* type MyError = ExtractError<MyResult>
|
|
85
|
+
* // Type: InvalidError
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // Works with composed errors
|
|
89
|
+
* const replaceVersion = async (): Promise<Result<Version, VersionNotFoundError | VersionExistsError>> => { ... }
|
|
90
|
+
* type ReplaceError = ExtractError<ReturnType<typeof replaceVersion>>
|
|
91
|
+
* // Type: VersionNotFoundError | VersionExistsError
|
|
92
|
+
*/
|
|
93
|
+
type ExtractError<TResultOrPromise> = TResultOrPromise extends Promise<Result<unknown, infer TError>> ? TError : TResultOrPromise extends Result<unknown, infer TError> ? TError : never;
|
|
94
|
+
/**
|
|
95
|
+
* Extract the error type from a function that returns Result or Promise<Result>
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Simple extraction
|
|
99
|
+
* const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
|
|
100
|
+
* type GetUserError = ExtractFnError<typeof getUser>
|
|
101
|
+
* // Type: UserNotFoundError
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // Compose errors from multiple functions
|
|
105
|
+
* const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
|
|
106
|
+
* const getImage = async (id: string): Promise<Result<Image, ImageNotFoundError>> => { ... }
|
|
107
|
+
* type CombinedError = ExtractFnError<typeof getUser> | ExtractFnError<typeof getImage>
|
|
108
|
+
* // Type: UserNotFoundError | ImageNotFoundError
|
|
109
|
+
*/
|
|
110
|
+
type ExtractFnError<TFunction extends (...args: unknown[]) => unknown> = ExtractError<ReturnType<TFunction>>;
|
|
111
|
+
/**
|
|
112
|
+
* Extract and combine error types from multiple Result or Promise<Result> types
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* type UserResult = Result<User, UserNotFoundError>
|
|
116
|
+
* type ImageResult = Promise<Result<Image, ImageNotFoundError>>
|
|
117
|
+
* type ProductResult = Result<Product, ProductNotFoundError>
|
|
118
|
+
*
|
|
119
|
+
* type CombinedError = ExtractErrors<[UserResult, ImageResult, ProductResult]>
|
|
120
|
+
* // Type: UserNotFoundError | ImageNotFoundError | ProductNotFoundError
|
|
121
|
+
*/
|
|
122
|
+
type ExtractErrors<TResults extends readonly unknown[]> = TResults extends readonly [
|
|
123
|
+
infer TFirst,
|
|
124
|
+
...infer TRest
|
|
125
|
+
] ? ExtractError<TFirst> | ExtractErrors<TRest> : never;
|
|
126
|
+
/**
|
|
127
|
+
* Extract and combine error types from multiple functions that return Result or Promise<Result>
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const getUser = async (id: string): Promise<Result<User, UserNotFoundError>> => { ... }
|
|
131
|
+
* const getImage = async (id: string): Promise<Result<Image, ImageNotFoundError>> => { ... }
|
|
132
|
+
* const deleteProduct = async (id: string): Promise<Result<void, ProductNotFoundError>> => { ... }
|
|
133
|
+
*
|
|
134
|
+
* type CombinedError = ExtractFnsError<[typeof getUser, typeof getImage, typeof deleteProduct]>
|
|
135
|
+
* // Type: UserNotFoundError | ImageNotFoundError | ProductNotFoundError
|
|
136
|
+
*/
|
|
137
|
+
type ExtractFnsError<TFunctions extends readonly ((...args: unknown[]) => unknown)[]> = TFunctions extends readonly [
|
|
138
|
+
infer TFirst,
|
|
139
|
+
...infer TRest extends readonly ((...args: unknown[]) => unknown)[]
|
|
140
|
+
] ? ExtractFnError<TFirst & ((...args: unknown[]) => unknown)> | ExtractFnsError<TRest> : never;
|
|
141
|
+
/**
|
|
142
|
+
* Raw error function from neverthrow - use for lifting database errors directly
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* const seedResult = await songSeeds.get.one.byId(songSeedId)
|
|
146
|
+
* if (seedResult.isErr()) {
|
|
147
|
+
* return rawErr(seedResult.error)
|
|
148
|
+
* }
|
|
149
|
+
*/
|
|
150
|
+
declare const rawErr: typeof _Err;
|
|
151
|
+
export { makeErr, errAsync, ok, okAsync, rawErr, _Err, ResultAsync };
|
|
152
|
+
export type { Result, Err, ErrorType, ExtractError, ExtractFnError, ExtractErrors, ExtractFnsError };
|
|
153
|
+
export { err } from './err/mod.js';
|
|
154
|
+
export { isResult } from './is_result/mod.js';
|
|
155
|
+
export { propagateErr } from './propagate_err/mod.js';
|
|
156
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,IAAI,IAAI,EACX,EAAE,EACF,KAAK,MAAM,EACX,KAAK,GAAG,EACR,WAAW,EAEX,OAAO,IAAI,iBAAiB,EAC5B,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;GAUG;AACH,QAAA,MAAM,OAAO,GACZ,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnE,MAAM,KAAK,EACX,SAAS,MAAM,EACf,aAAa,WAAW,KACtB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAKe,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,QAAQ,GACb,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnE,MAAM,KAAK,EACX,SAAS,MAAM,EACf,aAAa,WAAW,KACtB,WAAW,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAKf,CAAA;AAErD;;;GAGG;AACH,QAAA,MAAM,OAAO,EAAE,OAAO,iBAAqC,CAAA;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,SAAS,CACb,KAAK,SAAS,MAAM,EACpB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAChE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,KAAK,YAAY,CAAC,gBAAgB,IACjC,gBAAgB,SAAS,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC,CAAC,GAC5D,MAAM,GACN,gBAAgB,SAAS,MAAM,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC,GACrD,MAAM,GACN,KAAK,CAAA;AAEV;;;;;;;;;;;;;;;GAeG;AACH,KAAK,cAAc,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,IAAI,YAAY,CACpF,UAAU,CAAC,SAAS,CAAC,CACrB,CAAA;AAED;;;;;;;;;;GAUG;AACH,KAAK,aAAa,CAAC,QAAQ,SAAS,SAAS,OAAO,EAAE,IAAI,QAAQ,SAAS,SAAS;IACnF,MAAM,MAAM;IACZ,GAAG,MAAM,KAAK;CACd,GACE,YAAY,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAC3C,KAAK,CAAA;AAER;;;;;;;;;;GAUG;AACH,KAAK,eAAe,CAAC,UAAU,SAAS,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,EAAE,IACnF,UAAU,SAAS,SAAS;IAC3B,MAAM,MAAM;IACZ,GAAG,MAAM,KAAK,SAAS,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,EAAE;CACnE,GACE,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,GACnF,KAAK,CAAA;AAET;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,OAAO,IAAW,CAAA;AAEhC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;AACpE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAA;AACpG,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.propagateErr = exports.isResult = exports.err = exports.ResultAsync = exports._Err = exports.rawErr = exports.okAsync = exports.ok = exports.errAsync = exports.makeErr = void 0;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
Object.defineProperty(exports, "_Err", { enumerable: true, get: function () { return neverthrow_1.err; } });
|
|
6
|
+
Object.defineProperty(exports, "ok", { enumerable: true, get: function () { return neverthrow_1.ok; } });
|
|
7
|
+
Object.defineProperty(exports, "ResultAsync", { enumerable: true, get: function () { return neverthrow_1.ResultAsync; } });
|
|
8
|
+
/**
|
|
9
|
+
* Create an error object with literal type preservation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const error = makeErr('not_found', 'User not found')
|
|
13
|
+
* // ✅ Type: { type: 'not_found', message: string }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const error = makeErr('not_found', 'User not found', { userId: '123' })
|
|
17
|
+
* // ✅ Type: { type: 'not_found', message: string, userId: string }
|
|
18
|
+
*/
|
|
19
|
+
const makeErr = (type, message, additional) => ({
|
|
20
|
+
...additional,
|
|
21
|
+
type,
|
|
22
|
+
message,
|
|
23
|
+
});
|
|
24
|
+
exports.makeErr = makeErr;
|
|
25
|
+
/**
|
|
26
|
+
* Create an async Err ResultAsync with automatic literal type preservation
|
|
27
|
+
*
|
|
28
|
+
* Async version of err() - same signature, returns ResultAsync instead of Result.
|
|
29
|
+
* Uses TypeScript 5.0+ const type parameters to preserve literal types automatically.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // ✅ Simple error
|
|
33
|
+
* return errAsync('not_found', 'User not found')
|
|
34
|
+
* // Type: ResultAsync<never, { type: 'not_found', message: string }>
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // ✅ Error with additional properties
|
|
38
|
+
* return errAsync('not_found', 'User not found', { userId: '123' })
|
|
39
|
+
* // Type: ResultAsync<never, { type: 'not_found', message: string, userId: string }>
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // ✅ Error with complex additional data
|
|
43
|
+
* return errAsync('validation_failed', 'Invalid input', {
|
|
44
|
+
* field: 'email',
|
|
45
|
+
* errors: ['Invalid format']
|
|
46
|
+
* })
|
|
47
|
+
* // Type: ResultAsync<never, { type: 'validation_failed', message: string, field: string, errors: string[] }>
|
|
48
|
+
*/
|
|
49
|
+
const errAsync = (type, message, additional) => (0, neverthrow_1.errAsync)({
|
|
50
|
+
...additional,
|
|
51
|
+
type,
|
|
52
|
+
message,
|
|
53
|
+
});
|
|
54
|
+
exports.errAsync = errAsync;
|
|
55
|
+
/**
|
|
56
|
+
* Re-export okAsync from neverthrow for consistency
|
|
57
|
+
* Creates a successful ResultAsync
|
|
58
|
+
*/
|
|
59
|
+
const okAsync = neverthrow_1.okAsync;
|
|
60
|
+
exports.okAsync = okAsync;
|
|
61
|
+
/**
|
|
62
|
+
* Raw error function from neverthrow - use for lifting database errors directly
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const seedResult = await songSeeds.get.one.byId(songSeedId)
|
|
66
|
+
* if (seedResult.isErr()) {
|
|
67
|
+
* return rawErr(seedResult.error)
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
const rawErr = neverthrow_1.err;
|
|
71
|
+
exports.rawErr = rawErr;
|
|
72
|
+
var mod_js_1 = require("./err/mod.js");
|
|
73
|
+
Object.defineProperty(exports, "err", { enumerable: true, get: function () { return mod_js_1.err; } });
|
|
74
|
+
var mod_js_2 = require("./is_result/mod.js");
|
|
75
|
+
Object.defineProperty(exports, "isResult", { enumerable: true, get: function () { return mod_js_2.isResult; } });
|
|
76
|
+
var mod_js_3 = require("./propagate_err/mod.js");
|
|
77
|
+
Object.defineProperty(exports, "propagateErr", { enumerable: true, get: function () { return mod_js_3.propagateErr; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.propagateErr = void 0;
|
|
4
|
+
var propagate_err_js_1 = require("./propagate_err.js");
|
|
5
|
+
Object.defineProperty(exports, "propagateErr", { enumerable: true, get: function () { return propagate_err_js_1.propagateErr; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
2
|
+
/**
|
|
3
|
+
* Propagates an error Result to a different success type context.
|
|
4
|
+
*
|
|
5
|
+
* This is safe because error Results never contain the success value - only the error.
|
|
6
|
+
* TypeScript's structural typing prevents direct assignment of Result<T, E> to Result<U, E>
|
|
7
|
+
* even though the error type is identical and we're in the error branch.
|
|
8
|
+
*
|
|
9
|
+
* Common use case: Early return from a function that creates multiple items. If creating
|
|
10
|
+
* item 2 fails with Result<Item, DatabaseError>, we need to return Result<Item[], DatabaseError>.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result = await createUser(db, data) // Result<User, DatabaseError>
|
|
14
|
+
* if (result.isErr()) {
|
|
15
|
+
* // Need to return Result<Profile, DatabaseError> but have Result<User, DatabaseError>
|
|
16
|
+
* return propagateErr(result)
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // In bulk creation, propagate single-item error to array context
|
|
21
|
+
* const itemResult = await createItem(data) // Result<Item, Error>
|
|
22
|
+
* if (itemResult.isErr()) {
|
|
23
|
+
* return propagateErr<Item[], Error>(itemResult) // Result<Item[], Error>
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
declare const propagateErr: <TNew, E>(errorResult: Result<unknown, E>) => Result<TNew, E>;
|
|
27
|
+
export { propagateErr };
|
|
28
|
+
//# sourceMappingURL=propagate_err.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propagate_err.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.3/src/propagate_err/propagate_err.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,YAAY,GAAI,IAAI,EAAE,CAAC,EAAE,aAAa,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAI9E,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.propagateErr = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Propagates an error Result to a different success type context.
|
|
6
|
+
*
|
|
7
|
+
* This is safe because error Results never contain the success value - only the error.
|
|
8
|
+
* TypeScript's structural typing prevents direct assignment of Result<T, E> to Result<U, E>
|
|
9
|
+
* even though the error type is identical and we're in the error branch.
|
|
10
|
+
*
|
|
11
|
+
* Common use case: Early return from a function that creates multiple items. If creating
|
|
12
|
+
* item 2 fails with Result<Item, DatabaseError>, we need to return Result<Item[], DatabaseError>.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const result = await createUser(db, data) // Result<User, DatabaseError>
|
|
16
|
+
* if (result.isErr()) {
|
|
17
|
+
* // Need to return Result<Profile, DatabaseError> but have Result<User, DatabaseError>
|
|
18
|
+
* return propagateErr(result)
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // In bulk creation, propagate single-item error to array context
|
|
23
|
+
* const itemResult = await createItem(data) // Result<Item, Error>
|
|
24
|
+
* if (itemResult.isErr()) {
|
|
25
|
+
* return propagateErr<Item[], Error>(itemResult) // Result<Item[], Error>
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
const propagateErr = (errorResult) => {
|
|
29
|
+
// Type assertion is safe: we're only propagating errors, and error Results
|
|
30
|
+
// don't contain the success value. The error type E is preserved exactly.
|
|
31
|
+
return errorResult;
|
|
32
|
+
};
|
|
33
|
+
exports.propagateErr = propagateErr;
|