@wentools/zli 0.2.0-beta.2dc33a43
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 +226 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/arg.d.ts +9 -0
- package/esm/arg.d.ts.map +1 -0
- package/esm/arg.js +4 -0
- package/esm/create_command.d.ts +28 -0
- package/esm/create_command.d.ts.map +1 -0
- package/esm/create_command.js +17 -0
- package/esm/create_command_directory.d.ts +35 -0
- package/esm/create_command_directory.d.ts.map +1 -0
- package/esm/create_command_directory.js +31 -0
- package/esm/create_flag_arg.d.ts +23 -0
- package/esm/create_flag_arg.d.ts.map +1 -0
- package/esm/create_flag_arg.js +14 -0
- package/esm/create_positional_arg.d.ts +24 -0
- package/esm/create_positional_arg.d.ts.map +1 -0
- package/esm/create_positional_arg.js +15 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/err.js +38 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/err/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts +156 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/index.js +65 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts +11 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.js +14 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts +2 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.js +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts +28 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/esm/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.js +30 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.d.ts +19 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.d.ts.map +1 -0
- package/esm/detect_arg_conflicts/detect_arg_conflicts.js +54 -0
- package/esm/detect_arg_conflicts/mod.d.ts +3 -0
- package/esm/detect_arg_conflicts/mod.d.ts.map +1 -0
- package/esm/detect_arg_conflicts/mod.js +1 -0
- package/esm/generate_help_text/generate_help_text.d.ts +13 -0
- package/esm/generate_help_text/generate_help_text.d.ts.map +1 -0
- package/esm/generate_help_text/generate_help_text.js +54 -0
- package/esm/generate_help_text/mod.d.ts +2 -0
- package/esm/generate_help_text/mod.d.ts.map +1 -0
- package/esm/generate_help_text/mod.js +1 -0
- package/esm/infer_args_type.d.ts +29 -0
- package/esm/infer_args_type.d.ts.map +1 -0
- package/esm/infer_args_type.js +6 -0
- package/esm/is_boolean_schema/is_boolean_schema.d.ts +12 -0
- package/esm/is_boolean_schema/is_boolean_schema.d.ts.map +1 -0
- package/esm/is_boolean_schema/is_boolean_schema.js +21 -0
- package/esm/is_boolean_schema/mod.d.ts +2 -0
- package/esm/is_boolean_schema/mod.d.ts.map +1 -0
- package/esm/is_boolean_schema/mod.js +1 -0
- package/esm/mod.d.ts +8 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +1 -0
- package/esm/package.json +3 -0
- package/esm/parse_args/mod.d.ts +3 -0
- package/esm/parse_args/mod.d.ts.map +1 -0
- package/esm/parse_args/mod.js +1 -0
- package/esm/parse_args/parse_args.d.ts +24 -0
- package/esm/parse_args/parse_args.d.ts.map +1 -0
- package/esm/parse_args/parse_args.js +89 -0
- package/esm/run.d.ts +19 -0
- package/esm/run.d.ts.map +1 -0
- package/esm/run.js +152 -0
- package/esm/validate_args/mod.d.ts +3 -0
- package/esm/validate_args/mod.d.ts.map +1 -0
- package/esm/validate_args/mod.js +1 -0
- package/esm/validate_args/validate_args.d.ts +20 -0
- package/esm/validate_args/validate_args.d.ts.map +1 -0
- package/esm/validate_args/validate_args.js +23 -0
- package/esm/zli.d.ts +118 -0
- package/esm/zli.d.ts.map +1 -0
- package/esm/zli.js +124 -0
- package/package.json +39 -0
- package/script/_dnt.shims.d.ts +6 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +65 -0
- package/script/arg.d.ts +9 -0
- package/script/arg.d.ts.map +1 -0
- package/script/arg.js +5 -0
- package/script/create_command.d.ts +28 -0
- package/script/create_command.d.ts.map +1 -0
- package/script/create_command.js +20 -0
- package/script/create_command_directory.d.ts +35 -0
- package/script/create_command_directory.d.ts.map +1 -0
- package/script/create_command_directory.js +34 -0
- package/script/create_flag_arg.d.ts +23 -0
- package/script/create_flag_arg.d.ts.map +1 -0
- package/script/create_flag_arg.js +17 -0
- package/script/create_positional_arg.d.ts +24 -0
- package/script/create_positional_arg.d.ts.map +1 -0
- package/script/create_positional_arg.js +18 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts +38 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/err.js +41 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/err/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts +156 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/index.js +77 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts +11 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/is_result/is_result.js +17 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts +2 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/index.js +5 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts +28 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.d.ts.map +1 -0
- package/script/deps/jsr.io/@wentools/result/0.1.0/src/propagate_err/propagate_err.js +33 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.d.ts +19 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.d.ts.map +1 -0
- package/script/detect_arg_conflicts/detect_arg_conflicts.js +57 -0
- package/script/detect_arg_conflicts/mod.d.ts +3 -0
- package/script/detect_arg_conflicts/mod.d.ts.map +1 -0
- package/script/detect_arg_conflicts/mod.js +5 -0
- package/script/generate_help_text/generate_help_text.d.ts +13 -0
- package/script/generate_help_text/generate_help_text.d.ts.map +1 -0
- package/script/generate_help_text/generate_help_text.js +57 -0
- package/script/generate_help_text/mod.d.ts +2 -0
- package/script/generate_help_text/mod.d.ts.map +1 -0
- package/script/generate_help_text/mod.js +5 -0
- package/script/infer_args_type.d.ts +29 -0
- package/script/infer_args_type.d.ts.map +1 -0
- package/script/infer_args_type.js +7 -0
- package/script/is_boolean_schema/is_boolean_schema.d.ts +12 -0
- package/script/is_boolean_schema/is_boolean_schema.d.ts.map +1 -0
- package/script/is_boolean_schema/is_boolean_schema.js +24 -0
- package/script/is_boolean_schema/mod.d.ts +2 -0
- package/script/is_boolean_schema/mod.d.ts.map +1 -0
- package/script/is_boolean_schema/mod.js +5 -0
- package/script/mod.d.ts +8 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +5 -0
- package/script/package.json +3 -0
- package/script/parse_args/mod.d.ts +3 -0
- package/script/parse_args/mod.d.ts.map +1 -0
- package/script/parse_args/mod.js +5 -0
- package/script/parse_args/parse_args.d.ts +24 -0
- package/script/parse_args/parse_args.d.ts.map +1 -0
- package/script/parse_args/parse_args.js +92 -0
- package/script/run.d.ts +19 -0
- package/script/run.d.ts.map +1 -0
- package/script/run.js +189 -0
- package/script/validate_args/mod.d.ts +3 -0
- package/script/validate_args/mod.d.ts.map +1 -0
- package/script/validate_args/mod.js +5 -0
- package/script/validate_args/validate_args.d.ts +20 -0
- package/script/validate_args/validate_args.d.ts.map +1 -0
- package/script/validate_args/validate_args.js +26 -0
- package/script/zli.d.ts +118 -0
- package/script/zli.d.ts.map +1 -0
- package/script/zli.js +127 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dntGlobalThis = exports.Deno = void 0;
|
|
4
|
+
const shim_deno_1 = require("@deno/shim-deno");
|
|
5
|
+
var shim_deno_2 = require("@deno/shim-deno");
|
|
6
|
+
Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
|
|
7
|
+
const dntGlobals = {
|
|
8
|
+
Deno: shim_deno_1.Deno,
|
|
9
|
+
};
|
|
10
|
+
exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
11
|
+
function createMergeProxy(baseObj, extObj) {
|
|
12
|
+
return new Proxy(baseObj, {
|
|
13
|
+
get(_target, prop, _receiver) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
return extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return baseObj[prop];
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
set(_target, prop, value) {
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
}
|
|
25
|
+
baseObj[prop] = value;
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
deleteProperty(_target, prop) {
|
|
29
|
+
let success = false;
|
|
30
|
+
if (prop in extObj) {
|
|
31
|
+
delete extObj[prop];
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
if (prop in baseObj) {
|
|
35
|
+
delete baseObj[prop];
|
|
36
|
+
success = true;
|
|
37
|
+
}
|
|
38
|
+
return success;
|
|
39
|
+
},
|
|
40
|
+
ownKeys(_target) {
|
|
41
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
42
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
43
|
+
const extKeysSet = new Set(extKeys);
|
|
44
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
45
|
+
},
|
|
46
|
+
defineProperty(_target, prop, desc) {
|
|
47
|
+
if (prop in extObj) {
|
|
48
|
+
delete extObj[prop];
|
|
49
|
+
}
|
|
50
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
54
|
+
if (prop in extObj) {
|
|
55
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
has(_target, prop) {
|
|
62
|
+
return prop in extObj || prop in baseObj;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
package/script/arg.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arg type - union of positional and flag args
|
|
3
|
+
*/
|
|
4
|
+
import type { PositionalArg } from './create_positional_arg.js';
|
|
5
|
+
import type { FlagArg } from './create_flag_arg.js';
|
|
6
|
+
import type { ZodSchema } from 'zod';
|
|
7
|
+
type Arg = PositionalArg<ZodSchema> | FlagArg<ZodSchema>;
|
|
8
|
+
export type { Arg };
|
|
9
|
+
//# sourceMappingURL=arg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arg.d.ts","sourceRoot":"","sources":["../src/arg.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAExD,YAAY,EAAE,GAAG,EAAE,CAAA"}
|
package/script/arg.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command configuration
|
|
3
|
+
*
|
|
4
|
+
* A command consists of:
|
|
5
|
+
* - Args (positional and flags)
|
|
6
|
+
* - Handler function (sync or async)
|
|
7
|
+
* - Optional description
|
|
8
|
+
*
|
|
9
|
+
* Type inference: The handler args are automatically typed based on the Zod schemas
|
|
10
|
+
* in the args array. This provides full autocomplete and type safety.
|
|
11
|
+
*/
|
|
12
|
+
import type { Arg } from './arg.js';
|
|
13
|
+
import type { InferArgsType } from './infer_args_type.js';
|
|
14
|
+
import type { Result } from './deps/jsr.io/@wentools/result/0.1.0/src/index.js';
|
|
15
|
+
type MaybeResult<TValue = void, TError = unknown> = TValue | Result<TValue, TError>;
|
|
16
|
+
type CommandHandler<TArgs> = (args: TArgs) => MaybeResult<void> | Promise<MaybeResult<void>>;
|
|
17
|
+
type Command<TArgs extends readonly Arg[] = readonly Arg[]> = {
|
|
18
|
+
args: TArgs;
|
|
19
|
+
handler: CommandHandler<InferArgsType<TArgs>>;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
type CommandOptions = {
|
|
23
|
+
description?: string;
|
|
24
|
+
};
|
|
25
|
+
declare const createCommand: <const TArgs extends readonly Arg[]>(args: TArgs, handler: CommandHandler<InferArgsType<TArgs>>, options?: CommandOptions) => Command<TArgs>;
|
|
26
|
+
export { createCommand };
|
|
27
|
+
export type { Command, CommandHandler, CommandOptions, MaybeResult };
|
|
28
|
+
//# sourceMappingURL=create_command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_command.d.ts","sourceRoot":"","sources":["../src/create_command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mDAAmD,CAAA;AAE/E,KAAK,WAAW,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,OAAO,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEnF,KAAK,cAAc,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;AAE5F,KAAK,OAAO,CAAC,KAAK,SAAS,SAAS,GAAG,EAAE,GAAG,SAAS,GAAG,EAAE,IAAI;IAC7D,IAAI,EAAE,KAAK,CAAA;IACX,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,cAAc,GAAG;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,aAAa,GAAI,KAAK,CAAC,KAAK,SAAS,SAAS,GAAG,EAAE,EACxD,MAAM,KAAK,EACX,SAAS,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAC7C,UAAU,cAAc,KACtB,OAAO,CAAC,KAAK,CAId,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a command configuration
|
|
4
|
+
*
|
|
5
|
+
* A command consists of:
|
|
6
|
+
* - Args (positional and flags)
|
|
7
|
+
* - Handler function (sync or async)
|
|
8
|
+
* - Optional description
|
|
9
|
+
*
|
|
10
|
+
* Type inference: The handler args are automatically typed based on the Zod schemas
|
|
11
|
+
* in the args array. This provides full autocomplete and type safety.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createCommand = void 0;
|
|
15
|
+
const createCommand = (args, handler, options) => ({
|
|
16
|
+
args,
|
|
17
|
+
handler,
|
|
18
|
+
description: options?.description,
|
|
19
|
+
});
|
|
20
|
+
exports.createCommand = createCommand;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a command directory configuration
|
|
3
|
+
*
|
|
4
|
+
* A command directory can contain both leaf commands and nested directories,
|
|
5
|
+
* allowing for hierarchical CLI organization.
|
|
6
|
+
*
|
|
7
|
+
* Think of it like a file system:
|
|
8
|
+
* - zli.c() = executable file (does work)
|
|
9
|
+
* - zli.d() = directory (organizes commands)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const collaborators = zli.d('collaborators', {
|
|
13
|
+
* description: 'Manage collaborators',
|
|
14
|
+
* commands: {
|
|
15
|
+
* add: addCommand,
|
|
16
|
+
* remove: removeCommand,
|
|
17
|
+
* }
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
import type { CommandEntry } from './run.js';
|
|
21
|
+
type CommandDirectory = {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
commands: Record<string, CommandEntry>;
|
|
25
|
+
};
|
|
26
|
+
type CommandDirectoryOptions = {
|
|
27
|
+
description?: string;
|
|
28
|
+
commands: Record<string, CommandEntry>;
|
|
29
|
+
};
|
|
30
|
+
declare const createCommandDirectory: <const TCommands extends Record<string, CommandEntry>>(name: string, options: CommandDirectoryOptions & {
|
|
31
|
+
commands: TCommands;
|
|
32
|
+
}) => CommandDirectory;
|
|
33
|
+
export { createCommandDirectory };
|
|
34
|
+
export type { CommandDirectory, CommandDirectoryOptions };
|
|
35
|
+
//# sourceMappingURL=create_command_directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_command_directory.d.ts","sourceRoot":"","sources":["../src/create_command_directory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,KAAK,gBAAgB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACtC,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACtC,CAAA;AAED,QAAA,MAAM,sBAAsB,GAAI,KAAK,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EACnF,MAAM,MAAM,EACZ,SAAS,uBAAuB,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,KACxD,gBAWF,CAAA;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAA;AACjC,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a command directory configuration
|
|
4
|
+
*
|
|
5
|
+
* A command directory can contain both leaf commands and nested directories,
|
|
6
|
+
* allowing for hierarchical CLI organization.
|
|
7
|
+
*
|
|
8
|
+
* Think of it like a file system:
|
|
9
|
+
* - zli.c() = executable file (does work)
|
|
10
|
+
* - zli.d() = directory (organizes commands)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const collaborators = zli.d('collaborators', {
|
|
14
|
+
* description: 'Manage collaborators',
|
|
15
|
+
* commands: {
|
|
16
|
+
* add: addCommand,
|
|
17
|
+
* remove: removeCommand,
|
|
18
|
+
* }
|
|
19
|
+
* })
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.createCommandDirectory = void 0;
|
|
23
|
+
const createCommandDirectory = (name, options) => {
|
|
24
|
+
// Validation
|
|
25
|
+
if (Object.keys(options.commands).length === 0) {
|
|
26
|
+
throw new Error(`Command directory '${name}' must have at least one command`);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name,
|
|
30
|
+
description: options.description,
|
|
31
|
+
commands: options.commands,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.createCommandDirectory = createCommandDirectory;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a flag argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Flags are specified with -- or - prefix:
|
|
5
|
+
* - Long name: script.ts --verbose
|
|
6
|
+
* - Short name: script.ts -v
|
|
7
|
+
*/
|
|
8
|
+
import type { ZodSchema } from 'zod';
|
|
9
|
+
type FlagArg<TSchema extends ZodSchema> = {
|
|
10
|
+
type: 'flag';
|
|
11
|
+
name: string;
|
|
12
|
+
schema: TSchema;
|
|
13
|
+
short?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
};
|
|
16
|
+
type FlagArgOptions = {
|
|
17
|
+
short?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
declare const createFlagArg: <TSchema extends ZodSchema>(name: string, schema: TSchema, options?: FlagArgOptions) => FlagArg<TSchema>;
|
|
21
|
+
export { createFlagArg };
|
|
22
|
+
export type { FlagArg, FlagArgOptions };
|
|
23
|
+
//# sourceMappingURL=create_flag_arg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_flag_arg.d.ts","sourceRoot":"","sources":["../src/create_flag_arg.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,OAAO,CAAC,OAAO,SAAS,SAAS,IAAI;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,cAAc,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,aAAa,GAAI,OAAO,SAAS,SAAS,EAC/C,MAAM,MAAM,EACZ,QAAQ,OAAO,EACf,UAAU,cAAc,KACtB,OAAO,CAAC,OAAO,CAKhB,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a flag argument configuration
|
|
4
|
+
*
|
|
5
|
+
* Flags are specified with -- or - prefix:
|
|
6
|
+
* - Long name: script.ts --verbose
|
|
7
|
+
* - Short name: script.ts -v
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createFlagArg = void 0;
|
|
11
|
+
const createFlagArg = (name, schema, options) => ({
|
|
12
|
+
type: 'flag',
|
|
13
|
+
name,
|
|
14
|
+
schema,
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
exports.createFlagArg = createFlagArg;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a positional argument configuration
|
|
3
|
+
*
|
|
4
|
+
* Positional args can be specified:
|
|
5
|
+
* - By position: script.ts value
|
|
6
|
+
* - By long name: script.ts --name value
|
|
7
|
+
* - By short name: script.ts -n value
|
|
8
|
+
*/
|
|
9
|
+
import type { ZodSchema } from 'zod';
|
|
10
|
+
type PositionalArg<TSchema extends ZodSchema> = {
|
|
11
|
+
type: 'positional';
|
|
12
|
+
name: string;
|
|
13
|
+
schema: TSchema;
|
|
14
|
+
short?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
};
|
|
17
|
+
type PositionalArgOptions = {
|
|
18
|
+
short?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
};
|
|
21
|
+
declare const createPositionalArg: <TSchema extends ZodSchema>(name: string, schema: TSchema, options?: PositionalArgOptions) => PositionalArg<TSchema>;
|
|
22
|
+
export { createPositionalArg };
|
|
23
|
+
export type { PositionalArg, PositionalArgOptions };
|
|
24
|
+
//# sourceMappingURL=create_positional_arg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_positional_arg.d.ts","sourceRoot":"","sources":["../src/create_positional_arg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;IAC/C,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,QAAA,MAAM,mBAAmB,GAAI,OAAO,SAAS,SAAS,EACrD,MAAM,MAAM,EACZ,QAAQ,OAAO,EACf,UAAU,oBAAoB,KAC5B,aAAa,CAAC,OAAO,CAKtB,CAAA;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAC9B,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a positional argument configuration
|
|
4
|
+
*
|
|
5
|
+
* Positional args can be specified:
|
|
6
|
+
* - By position: script.ts value
|
|
7
|
+
* - By long name: script.ts --name value
|
|
8
|
+
* - By short name: script.ts -n value
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createPositionalArg = void 0;
|
|
12
|
+
const createPositionalArg = (name, schema, options) => ({
|
|
13
|
+
type: 'positional',
|
|
14
|
+
name,
|
|
15
|
+
schema,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
exports.createPositionalArg = createPositionalArg;
|
|
@@ -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.0/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":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../src/deps/jsr.io/@wentools/result/0.1.0/src/err/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -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/index.js';
|
|
154
|
+
export { isResult } from './is_result/index.js';
|
|
155
|
+
export { propagateErr } from './propagate_err/index.js';
|
|
156
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@wentools/result/0.1.0/src/index.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,gBAAgB,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,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 index_js_1 = require("./err/index.js");
|
|
73
|
+
Object.defineProperty(exports, "err", { enumerable: true, get: function () { return index_js_1.err; } });
|
|
74
|
+
var index_js_2 = require("./is_result/index.js");
|
|
75
|
+
Object.defineProperty(exports, "isResult", { enumerable: true, get: function () { return index_js_2.isResult; } });
|
|
76
|
+
var index_js_3 = require("./propagate_err/index.js");
|
|
77
|
+
Object.defineProperty(exports, "propagateErr", { enumerable: true, get: function () { return index_js_3.propagateErr; } });
|