@jaypie/fabric 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/README.md +677 -0
- package/dist/cjs/commander/FabricCommander.d.ts +94 -0
- package/dist/cjs/commander/createCommanderOptions.d.ts +25 -0
- package/dist/cjs/commander/fabricCommand.d.ts +43 -0
- package/dist/cjs/commander/index.cjs +1487 -0
- package/dist/cjs/commander/index.cjs.map +1 -0
- package/dist/cjs/commander/index.d.ts +6 -0
- package/dist/cjs/commander/parseCommanderOptions.d.ts +32 -0
- package/dist/cjs/commander/registerServiceCommand.d.ts +43 -0
- package/dist/cjs/commander/types.d.ts +107 -0
- package/dist/cjs/constants.d.ts +12 -0
- package/dist/cjs/convert-date.d.ts +47 -0
- package/dist/cjs/convert.d.ts +69 -0
- package/dist/cjs/data/FabricData.d.ts +42 -0
- package/dist/cjs/data/index.cjs +1575 -0
- package/dist/cjs/data/index.cjs.map +1 -0
- package/dist/cjs/data/index.d.ts +5 -0
- package/dist/cjs/data/services/archive.d.ts +8 -0
- package/dist/cjs/data/services/create.d.ts +8 -0
- package/dist/cjs/data/services/delete.d.ts +8 -0
- package/dist/cjs/data/services/execute.d.ts +8 -0
- package/dist/cjs/data/services/index.d.ts +7 -0
- package/dist/cjs/data/services/list.d.ts +8 -0
- package/dist/cjs/data/services/read.d.ts +8 -0
- package/dist/cjs/data/services/update.d.ts +8 -0
- package/dist/cjs/data/transforms.d.ts +80 -0
- package/dist/cjs/data/types.d.ts +190 -0
- package/dist/cjs/express/FabricRouter.d.ts +29 -0
- package/dist/cjs/express/fabricExpress.d.ts +16 -0
- package/dist/cjs/express/index.cjs +505 -0
- package/dist/cjs/express/index.cjs.map +1 -0
- package/dist/cjs/express/index.d.ts +3 -0
- package/dist/cjs/express/types.d.ts +51 -0
- package/dist/cjs/helpers/fallback.d.ts +21 -0
- package/dist/cjs/helpers/index.d.ts +3 -0
- package/dist/cjs/helpers/resolvedName.d.ts +24 -0
- package/dist/cjs/http/FabricHttpServer.d.ts +31 -0
- package/dist/cjs/http/authorization.d.ts +30 -0
- package/dist/cjs/http/cors.d.ts +40 -0
- package/dist/cjs/http/fabricHttp.d.ts +28 -0
- package/dist/cjs/http/httpTransform.d.ts +36 -0
- package/dist/cjs/http/index.cjs +1820 -0
- package/dist/cjs/http/index.cjs.map +1 -0
- package/dist/cjs/http/index.d.ts +10 -0
- package/dist/cjs/http/stream.d.ts +185 -0
- package/dist/cjs/http/types.d.ts +343 -0
- package/dist/cjs/index/index.d.ts +8 -0
- package/dist/cjs/index/keyBuilder.d.ts +81 -0
- package/dist/cjs/index/registry.d.ts +56 -0
- package/dist/cjs/index/types.d.ts +54 -0
- package/dist/cjs/index.cjs +1674 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +18 -0
- package/dist/cjs/lambda/createLambdaService.d.ts +33 -0
- package/dist/cjs/lambda/fabricLambda.d.ts +36 -0
- package/dist/cjs/lambda/index.cjs +967 -0
- package/dist/cjs/lambda/index.cjs.map +1 -0
- package/dist/cjs/lambda/index.d.ts +2 -0
- package/dist/cjs/lambda/types.d.ts +68 -0
- package/dist/cjs/llm/createLlmTool.d.ts +40 -0
- package/dist/cjs/llm/fabricTool.d.ts +40 -0
- package/dist/cjs/llm/index.cjs +1107 -0
- package/dist/cjs/llm/index.cjs.map +1 -0
- package/dist/cjs/llm/index.d.ts +3 -0
- package/dist/cjs/llm/inputToJsonSchema.d.ts +32 -0
- package/dist/cjs/llm/types.d.ts +61 -0
- package/dist/cjs/mcp/fabricMcp.d.ts +38 -0
- package/dist/cjs/mcp/index.cjs +938 -0
- package/dist/cjs/mcp/index.cjs.map +1 -0
- package/dist/cjs/mcp/index.d.ts +2 -0
- package/dist/cjs/mcp/registerMcpTool.d.ts +38 -0
- package/dist/cjs/mcp/types.d.ts +60 -0
- package/dist/cjs/models/base.d.ts +209 -0
- package/dist/cjs/resolve-date.d.ts +47 -0
- package/dist/cjs/resolve.d.ts +69 -0
- package/dist/cjs/resolveService.d.ts +49 -0
- package/dist/cjs/service.d.ts +13 -0
- package/dist/cjs/status.d.ts +30 -0
- package/dist/cjs/types/elementaryTypes.d.ts +84 -0
- package/dist/cjs/types/fieldCategory.d.ts +20 -0
- package/dist/cjs/types/fieldDefinition.d.ts +46 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types.d.ts +56 -0
- package/dist/esm/commander/FabricCommander.d.ts +94 -0
- package/dist/esm/commander/createCommanderOptions.d.ts +25 -0
- package/dist/esm/commander/fabricCommand.d.ts +43 -0
- package/dist/esm/commander/index.d.ts +6 -0
- package/dist/esm/commander/index.js +1482 -0
- package/dist/esm/commander/index.js.map +1 -0
- package/dist/esm/commander/parseCommanderOptions.d.ts +32 -0
- package/dist/esm/commander/registerServiceCommand.d.ts +43 -0
- package/dist/esm/commander/types.d.ts +107 -0
- package/dist/esm/constants.d.ts +12 -0
- package/dist/esm/convert-date.d.ts +47 -0
- package/dist/esm/convert.d.ts +69 -0
- package/dist/esm/data/FabricData.d.ts +42 -0
- package/dist/esm/data/index.d.ts +5 -0
- package/dist/esm/data/index.js +1548 -0
- package/dist/esm/data/index.js.map +1 -0
- package/dist/esm/data/services/archive.d.ts +8 -0
- package/dist/esm/data/services/create.d.ts +8 -0
- package/dist/esm/data/services/delete.d.ts +8 -0
- package/dist/esm/data/services/execute.d.ts +8 -0
- package/dist/esm/data/services/index.d.ts +7 -0
- package/dist/esm/data/services/list.d.ts +8 -0
- package/dist/esm/data/services/read.d.ts +8 -0
- package/dist/esm/data/services/update.d.ts +8 -0
- package/dist/esm/data/transforms.d.ts +80 -0
- package/dist/esm/data/types.d.ts +190 -0
- package/dist/esm/express/FabricRouter.d.ts +29 -0
- package/dist/esm/express/fabricExpress.d.ts +16 -0
- package/dist/esm/express/index.d.ts +3 -0
- package/dist/esm/express/index.js +500 -0
- package/dist/esm/express/index.js.map +1 -0
- package/dist/esm/express/types.d.ts +51 -0
- package/dist/esm/helpers/fallback.d.ts +21 -0
- package/dist/esm/helpers/index.d.ts +3 -0
- package/dist/esm/helpers/resolvedName.d.ts +24 -0
- package/dist/esm/http/FabricHttpServer.d.ts +31 -0
- package/dist/esm/http/authorization.d.ts +30 -0
- package/dist/esm/http/cors.d.ts +40 -0
- package/dist/esm/http/fabricHttp.d.ts +28 -0
- package/dist/esm/http/httpTransform.d.ts +36 -0
- package/dist/esm/http/index.d.ts +10 -0
- package/dist/esm/http/index.js +1775 -0
- package/dist/esm/http/index.js.map +1 -0
- package/dist/esm/http/stream.d.ts +185 -0
- package/dist/esm/http/types.d.ts +343 -0
- package/dist/esm/index/index.d.ts +8 -0
- package/dist/esm/index/keyBuilder.d.ts +81 -0
- package/dist/esm/index/registry.d.ts +56 -0
- package/dist/esm/index/types.d.ts +54 -0
- package/dist/esm/index.d.ts +18 -0
- package/dist/esm/index.js +1606 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lambda/createLambdaService.d.ts +33 -0
- package/dist/esm/lambda/fabricLambda.d.ts +36 -0
- package/dist/esm/lambda/index.d.ts +2 -0
- package/dist/esm/lambda/index.js +965 -0
- package/dist/esm/lambda/index.js.map +1 -0
- package/dist/esm/lambda/types.d.ts +68 -0
- package/dist/esm/llm/createLlmTool.d.ts +40 -0
- package/dist/esm/llm/fabricTool.d.ts +40 -0
- package/dist/esm/llm/index.d.ts +3 -0
- package/dist/esm/llm/index.js +1104 -0
- package/dist/esm/llm/index.js.map +1 -0
- package/dist/esm/llm/inputToJsonSchema.d.ts +32 -0
- package/dist/esm/llm/types.d.ts +61 -0
- package/dist/esm/mcp/fabricMcp.d.ts +38 -0
- package/dist/esm/mcp/index.d.ts +2 -0
- package/dist/esm/mcp/index.js +936 -0
- package/dist/esm/mcp/index.js.map +1 -0
- package/dist/esm/mcp/registerMcpTool.d.ts +38 -0
- package/dist/esm/mcp/types.d.ts +60 -0
- package/dist/esm/models/base.d.ts +209 -0
- package/dist/esm/resolve-date.d.ts +47 -0
- package/dist/esm/resolve.d.ts +69 -0
- package/dist/esm/resolveService.d.ts +49 -0
- package/dist/esm/service.d.ts +13 -0
- package/dist/esm/status.d.ts +30 -0
- package/dist/esm/types/elementaryTypes.d.ts +84 -0
- package/dist/esm/types/fieldCategory.d.ts +20 -0
- package/dist/esm/types/fieldDefinition.d.ts +46 -0
- package/dist/esm/types/index.d.ts +4 -0
- package/dist/esm/types.d.ts +56 -0
- package/package.json +122 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elementary Field Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the 10 elementary field types for the Fabric vocabulary.
|
|
5
|
+
* Each type has: alias, name, icon, and optional validation/format rules.
|
|
6
|
+
*/
|
|
7
|
+
import type { FieldDefinition } from "./fieldDefinition.js";
|
|
8
|
+
/** Elementary type aliases */
|
|
9
|
+
export declare const ELEMENTARY_TYPES: readonly ["boolean", "date", "datetime", "dollars", "multiselect", "number", "reference", "select", "text", "textarea"];
|
|
10
|
+
export type ElementaryType = (typeof ELEMENTARY_TYPES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Extended field definition for elementary types
|
|
13
|
+
*/
|
|
14
|
+
export interface ElementaryTypeDefinition extends FieldDefinition {
|
|
15
|
+
/** The elementary type alias */
|
|
16
|
+
alias: ElementaryType;
|
|
17
|
+
/** Display format pattern */
|
|
18
|
+
formatPattern?: string;
|
|
19
|
+
/** Input component type (for UI rendering) */
|
|
20
|
+
inputComponent?: string;
|
|
21
|
+
/** Options for select/multiselect types */
|
|
22
|
+
options?: Array<{
|
|
23
|
+
label: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}>;
|
|
26
|
+
/** Reference model for reference types */
|
|
27
|
+
referenceModel?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a string is an elementary type
|
|
31
|
+
*/
|
|
32
|
+
export declare function isElementaryType(value: unknown): value is ElementaryType;
|
|
33
|
+
/**
|
|
34
|
+
* Boolean - True/false toggle
|
|
35
|
+
*/
|
|
36
|
+
export declare const BOOLEAN_TYPE: ElementaryTypeDefinition;
|
|
37
|
+
/**
|
|
38
|
+
* Date - Date picker (ISO format)
|
|
39
|
+
*/
|
|
40
|
+
export declare const DATE_TYPE: ElementaryTypeDefinition;
|
|
41
|
+
/**
|
|
42
|
+
* Datetime - Date + time picker
|
|
43
|
+
*/
|
|
44
|
+
export declare const DATETIME_TYPE: ElementaryTypeDefinition;
|
|
45
|
+
/**
|
|
46
|
+
* Dollars - Currency with formatting
|
|
47
|
+
*/
|
|
48
|
+
export declare const DOLLARS_TYPE: ElementaryTypeDefinition;
|
|
49
|
+
/**
|
|
50
|
+
* Multiselect - Multiple selections from options
|
|
51
|
+
*/
|
|
52
|
+
export declare const MULTISELECT_TYPE: ElementaryTypeDefinition;
|
|
53
|
+
/**
|
|
54
|
+
* Number - Numeric input (integer or float)
|
|
55
|
+
*/
|
|
56
|
+
export declare const NUMBER_TYPE: ElementaryTypeDefinition;
|
|
57
|
+
/**
|
|
58
|
+
* Reference - Link to another model
|
|
59
|
+
*/
|
|
60
|
+
export declare const REFERENCE_TYPE: ElementaryTypeDefinition;
|
|
61
|
+
/**
|
|
62
|
+
* Select - Single selection from options
|
|
63
|
+
*/
|
|
64
|
+
export declare const SELECT_TYPE: ElementaryTypeDefinition;
|
|
65
|
+
/**
|
|
66
|
+
* Text - Single-line string input
|
|
67
|
+
*/
|
|
68
|
+
export declare const TEXT_TYPE: ElementaryTypeDefinition;
|
|
69
|
+
/**
|
|
70
|
+
* Textarea - Multi-line string input
|
|
71
|
+
*/
|
|
72
|
+
export declare const TEXTAREA_TYPE: ElementaryTypeDefinition;
|
|
73
|
+
/**
|
|
74
|
+
* Registry of all elementary types
|
|
75
|
+
*/
|
|
76
|
+
export declare const ELEMENTARY_TYPE_REGISTRY: Record<ElementaryType, ElementaryTypeDefinition>;
|
|
77
|
+
/**
|
|
78
|
+
* Get an elementary type definition by alias
|
|
79
|
+
*/
|
|
80
|
+
export declare function getElementaryType(alias: ElementaryType): ElementaryTypeDefinition;
|
|
81
|
+
/**
|
|
82
|
+
* Get all elementary type definitions
|
|
83
|
+
*/
|
|
84
|
+
export declare function getAllElementaryTypes(): ElementaryTypeDefinition[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Categories - Semantic classification of fields
|
|
3
|
+
*
|
|
4
|
+
* Categories define the semantic boundary of fields within models.
|
|
5
|
+
*/
|
|
6
|
+
/** Field categories defining semantic boundaries */
|
|
7
|
+
export declare const FIELD_CATEGORIES: readonly ["identity", "input", "metadata", "state"];
|
|
8
|
+
/**
|
|
9
|
+
* Field category - semantic classification of fields
|
|
10
|
+
*
|
|
11
|
+
* - identity: What the model IS (immutable) - id, model, ou
|
|
12
|
+
* - metadata: What the model is ABOUT (usually immutable) - alias, xid, class, type
|
|
13
|
+
* - state: What the model TRACKS (mutable) - content, status, progress
|
|
14
|
+
* - input: Request parameters (transient) - data, params, options
|
|
15
|
+
*/
|
|
16
|
+
export type FieldCategory = (typeof FIELD_CATEGORIES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Check if a string is a valid field category
|
|
19
|
+
*/
|
|
20
|
+
export declare function isFieldCategory(value: unknown): value is FieldCategory;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Definition - Describes a field's structure and behavior
|
|
3
|
+
*
|
|
4
|
+
* Field definitions are the building blocks of model definitions,
|
|
5
|
+
* specifying type, validation, and metadata for each field.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation rule for a field
|
|
9
|
+
*/
|
|
10
|
+
export interface ValidationRule {
|
|
11
|
+
/** Error message if validation fails */
|
|
12
|
+
message?: string;
|
|
13
|
+
/** Rule type (required, min, max, pattern, etc.) */
|
|
14
|
+
type: string;
|
|
15
|
+
/** Rule value (varies by type) */
|
|
16
|
+
value?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Field definition - describes a field's structure and behavior
|
|
20
|
+
*/
|
|
21
|
+
export interface FieldDefinition {
|
|
22
|
+
/** Field identifier (unique within model) */
|
|
23
|
+
alias: string;
|
|
24
|
+
/** Default value */
|
|
25
|
+
defaultValue?: unknown;
|
|
26
|
+
/** Description */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Fallback chain for value resolution */
|
|
29
|
+
fallback?: string[];
|
|
30
|
+
/** Icon (lucide name or custom) */
|
|
31
|
+
icon?: string;
|
|
32
|
+
/** Display name */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Field type (text, number, dollars, etc.) */
|
|
35
|
+
type: string;
|
|
36
|
+
/** Validation rules */
|
|
37
|
+
validation?: ValidationRule[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Field reference - either an alias string or inline definition
|
|
41
|
+
*/
|
|
42
|
+
export type FieldRef = FieldDefinition | string;
|
|
43
|
+
/**
|
|
44
|
+
* Check if a field ref is an inline definition
|
|
45
|
+
*/
|
|
46
|
+
export declare function isFieldDefinition(ref: FieldRef): ref is FieldDefinition;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BOOLEAN_TYPE, DATE_TYPE, DATETIME_TYPE, DOLLARS_TYPE, ELEMENTARY_TYPE_REGISTRY, ELEMENTARY_TYPES, getAllElementaryTypes, getElementaryType, isElementaryType, MULTISELECT_TYPE, NUMBER_TYPE, REFERENCE_TYPE, SELECT_TYPE, TEXT_TYPE, TEXTAREA_TYPE, } from "./elementaryTypes.js";
|
|
2
|
+
export type { ElementaryType, ElementaryTypeDefinition, } from "./elementaryTypes.js";
|
|
3
|
+
export { isFieldDefinition } from "./fieldDefinition.js";
|
|
4
|
+
export type { FieldDefinition, FieldRef, ValidationRule, } from "./fieldDefinition.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels for messages
|
|
3
|
+
* @default "info"
|
|
4
|
+
*/
|
|
5
|
+
export type MessageLevel = "debug" | "error" | "info" | "trace" | "warn";
|
|
6
|
+
/**
|
|
7
|
+
* Standard message structure for callbacks and notifications
|
|
8
|
+
*/
|
|
9
|
+
export interface Message {
|
|
10
|
+
content: string;
|
|
11
|
+
level?: MessageLevel;
|
|
12
|
+
}
|
|
13
|
+
export type ScalarType = typeof Boolean | typeof Number | typeof String | "boolean" | "number" | "string";
|
|
14
|
+
export type CompositeType = typeof Array | typeof Object | "array" | "object";
|
|
15
|
+
export type ArrayElementType = typeof Boolean | typeof Number | typeof Object | typeof String | "boolean" | "number" | "object" | "string" | "" | Record<string, never>;
|
|
16
|
+
export type TypedArrayType = [] | [typeof Boolean] | [typeof Number] | [typeof Object] | [typeof String] | ["boolean"] | ["number"] | ["object"] | ["string"] | [""] | [Record<string, never>];
|
|
17
|
+
export type ValidatedStringType = Array<string | RegExp>;
|
|
18
|
+
export type ValidatedNumberType = Array<number>;
|
|
19
|
+
export type RegExpType = RegExp;
|
|
20
|
+
export type DateConversionType = typeof Date;
|
|
21
|
+
export type ConversionType = CompositeType | DateConversionType | RegExpType | ScalarType | TypedArrayType | ValidatedNumberType | ValidatedStringType;
|
|
22
|
+
export interface InputFieldDefinition {
|
|
23
|
+
default?: unknown;
|
|
24
|
+
description?: string;
|
|
25
|
+
/** Override the long flag name for Commander.js (e.g., "user" for --user) */
|
|
26
|
+
flag?: string;
|
|
27
|
+
/** Short switch letter for Commander.js (e.g., "u" for -u) */
|
|
28
|
+
letter?: string;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
type: ConversionType;
|
|
31
|
+
validate?: ValidateFunction | RegExp | Array<unknown>;
|
|
32
|
+
}
|
|
33
|
+
export type ValidateFunction = (value: unknown) => boolean | void | Promise<boolean | void>;
|
|
34
|
+
/**
|
|
35
|
+
* Context passed to service functions for callbacks and utilities
|
|
36
|
+
*/
|
|
37
|
+
export interface ServiceContext {
|
|
38
|
+
/** Report a recoverable error during service execution (does not throw) */
|
|
39
|
+
onError?: (error: unknown) => void | Promise<void>;
|
|
40
|
+
/** Report a fatal error during service execution (does not throw) */
|
|
41
|
+
onFatal?: (error: unknown) => void | Promise<void>;
|
|
42
|
+
/** Send a message during service execution (connects to onMessage callback) */
|
|
43
|
+
sendMessage?: (message: Message) => void | Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export type ServiceFunction<TInput, TOutput> = (input: TInput, context?: ServiceContext) => TOutput | Promise<TOutput>;
|
|
46
|
+
export interface ServiceConfig<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> {
|
|
47
|
+
alias?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
input?: Record<string, InputFieldDefinition>;
|
|
50
|
+
service?: ServiceFunction<TInput, TOutput>;
|
|
51
|
+
}
|
|
52
|
+
export interface Service<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> extends ServiceConfig<TInput, TOutput> {
|
|
53
|
+
(input?: Partial<TInput> | string, context?: ServiceContext): Promise<TOutput>;
|
|
54
|
+
/** Fabric version identifier - used to detect pre-instantiated Services */
|
|
55
|
+
$fabric?: string;
|
|
56
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { InputFieldDefinition, Service, ServiceFunction } from "../types.js";
|
|
3
|
+
import type { OnCompleteCallback, OnErrorCallback, OnFatalCallback, OnMessageCallback } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Inline service definition for FabricCommander
|
|
6
|
+
* Allows defining services directly in the services array
|
|
7
|
+
*/
|
|
8
|
+
export interface InlineServiceDefinition {
|
|
9
|
+
/** Service alias (used as command name) */
|
|
10
|
+
alias: string;
|
|
11
|
+
/** Service description */
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Input field definitions */
|
|
14
|
+
input?: Record<string, InputFieldDefinition>;
|
|
15
|
+
/** The service function */
|
|
16
|
+
service: ServiceFunction<Record<string, unknown>, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Service entry - either a pre-instantiated Service or an inline definition
|
|
20
|
+
*/
|
|
21
|
+
export type ServiceEntry = Service | InlineServiceDefinition;
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for FabricCommander
|
|
24
|
+
*/
|
|
25
|
+
export interface FabricCommanderConfig {
|
|
26
|
+
/** CLI description */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** CLI name (defaults to process.argv script name) */
|
|
29
|
+
name?: string;
|
|
30
|
+
/** Default callback called when any command completes successfully */
|
|
31
|
+
onComplete?: OnCompleteCallback;
|
|
32
|
+
/** Default callback called when any command encounters an error */
|
|
33
|
+
onError?: OnErrorCallback;
|
|
34
|
+
/** Default callback called when any command encounters a fatal error */
|
|
35
|
+
onFatal?: OnFatalCallback;
|
|
36
|
+
/** Default callback called to report progress messages */
|
|
37
|
+
onMessage?: OnMessageCallback;
|
|
38
|
+
/** Services to register as commands */
|
|
39
|
+
services: ServiceEntry[];
|
|
40
|
+
/** CLI version */
|
|
41
|
+
version?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* FabricCommander - Convenient wrapper for creating multi-command CLIs
|
|
45
|
+
*
|
|
46
|
+
* Creates a Commander program with multiple service commands in a single call.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Array form - simple list of services
|
|
51
|
+
* const cli = new FabricCommander([greetService, farewellService]);
|
|
52
|
+
* cli.parse();
|
|
53
|
+
*
|
|
54
|
+
* // Config form - with description and version
|
|
55
|
+
* const cli = new FabricCommander({
|
|
56
|
+
* name: "my-cli",
|
|
57
|
+
* description: "My CLI application",
|
|
58
|
+
* version: "1.0.0",
|
|
59
|
+
* services: [greetService, farewellService],
|
|
60
|
+
* });
|
|
61
|
+
* cli.parse();
|
|
62
|
+
*
|
|
63
|
+
* // With inline service definitions
|
|
64
|
+
* const cli = new FabricCommander({
|
|
65
|
+
* description: "My CLI",
|
|
66
|
+
* version: "1.0.0",
|
|
67
|
+
* services: [
|
|
68
|
+
* existingService,
|
|
69
|
+
* {
|
|
70
|
+
* alias: "greet",
|
|
71
|
+
* description: "Greet a user",
|
|
72
|
+
* input: { name: { type: String } },
|
|
73
|
+
* service: ({ name }) => `Hello, ${name}!`,
|
|
74
|
+
* },
|
|
75
|
+
* ],
|
|
76
|
+
* });
|
|
77
|
+
* cli.parse();
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare class FabricCommander {
|
|
81
|
+
/** The underlying Commander Command instance */
|
|
82
|
+
readonly command: Command;
|
|
83
|
+
constructor(config: ServiceEntry[] | FabricCommanderConfig);
|
|
84
|
+
/**
|
|
85
|
+
* Parse command-line arguments
|
|
86
|
+
* Delegates to Commander's parse method
|
|
87
|
+
*/
|
|
88
|
+
parse(argv?: readonly string[]): this;
|
|
89
|
+
/**
|
|
90
|
+
* Parse command-line arguments asynchronously
|
|
91
|
+
* Delegates to Commander's parseAsync method
|
|
92
|
+
*/
|
|
93
|
+
parseAsync(argv?: readonly string[]): Promise<this>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InputFieldDefinition } from "../types.js";
|
|
2
|
+
import type { CreateCommanderOptionsConfig, CreateCommanderOptionsResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create Commander.js Option objects from a service config
|
|
5
|
+
*
|
|
6
|
+
* @param input - The input field definitions from a service config
|
|
7
|
+
* @param config - Optional configuration for excluding fields or overriding options
|
|
8
|
+
* @returns An object containing an array of Commander Option objects
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const handler = createService({
|
|
13
|
+
* input: {
|
|
14
|
+
* name: { type: String, description: "User name" },
|
|
15
|
+
* age: { type: Number, default: 25 },
|
|
16
|
+
* verbose: { type: Boolean },
|
|
17
|
+
* },
|
|
18
|
+
* service: (input) => input,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const { options } = createCommanderOptions(handler.input);
|
|
22
|
+
* options.forEach(opt => command.addOption(opt));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createCommanderOptions(input?: Record<string, InputFieldDefinition>, config?: CreateCommanderOptionsConfig): CreateCommanderOptionsResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FabricCommandConfig, FabricCommandResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fabric a service as a Commander.js command
|
|
4
|
+
*
|
|
5
|
+
* This function creates a command from a service, automatically:
|
|
6
|
+
* - Creating the command with the service's alias (or custom name)
|
|
7
|
+
* - Adding a description from the service's description (or custom)
|
|
8
|
+
* - Converting input definitions to Commander options
|
|
9
|
+
* - Wiring up the action to call the service with parsed input
|
|
10
|
+
*
|
|
11
|
+
* Error handling:
|
|
12
|
+
* - Services can call context.onError() for recoverable errors
|
|
13
|
+
* - Services can call context.onFatal() for fatal errors
|
|
14
|
+
* - Any error that throws out of the service is treated as fatal
|
|
15
|
+
*
|
|
16
|
+
* @param config - Configuration including service, program, and optional overrides
|
|
17
|
+
* @returns An object containing the created command
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { Command } from "commander";
|
|
22
|
+
* import { fabricService } from "@jaypie/fabric";
|
|
23
|
+
* import { fabricCommand } from "@jaypie/fabric/commander";
|
|
24
|
+
*
|
|
25
|
+
* const myService = fabricService({
|
|
26
|
+
* alias: "greet",
|
|
27
|
+
* description: "Greet a user",
|
|
28
|
+
* input: {
|
|
29
|
+
* userName: { type: String, description: "User name" },
|
|
30
|
+
* loud: { type: Boolean, description: "Shout greeting" },
|
|
31
|
+
* },
|
|
32
|
+
* service: ({ userName, loud }) => {
|
|
33
|
+
* const greeting = `Hello, ${userName}!`;
|
|
34
|
+
* return loud ? greeting.toUpperCase() : greeting;
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const program = new Command();
|
|
39
|
+
* fabricCommand({ program, service: myService });
|
|
40
|
+
* program.parse();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function fabricCommand({ alias, description, exclude, input, name, onComplete, onError, onFatal, onMessage, overrides, program, service: serviceOrFunction, }: FabricCommandConfig): FabricCommandResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createCommanderOptions } from "./createCommanderOptions.js";
|
|
2
|
+
export { fabricCommand } from "./fabricCommand.js";
|
|
3
|
+
export { FabricCommander } from "./FabricCommander.js";
|
|
4
|
+
export { parseCommanderOptions } from "./parseCommanderOptions.js";
|
|
5
|
+
export type { FabricCommanderConfig, InlineServiceDefinition, ServiceEntry, } from "./FabricCommander.js";
|
|
6
|
+
export type { CommanderOptionOverride, CreateCommanderOptionsConfig, CreateCommanderOptionsResult, FabricCommandConfig, FabricCommandResult, OnCompleteCallback, OnErrorCallback, OnFatalCallback, OnMessageCallback, ParseCommanderOptionsConfig, } from "./types.js";
|