@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,343 @@
|
|
|
1
|
+
import type { Service, ServiceConfig } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* HTTP request context passed to the `http` transformation function
|
|
4
|
+
*/
|
|
5
|
+
export interface HttpContext {
|
|
6
|
+
/** Parsed request body */
|
|
7
|
+
body: unknown;
|
|
8
|
+
/** Request headers */
|
|
9
|
+
headers: Headers;
|
|
10
|
+
/** HTTP method (GET, POST, PUT, DELETE, PATCH) */
|
|
11
|
+
method: string;
|
|
12
|
+
/** URL path */
|
|
13
|
+
path: string;
|
|
14
|
+
/** Query string parameters */
|
|
15
|
+
query: URLSearchParams;
|
|
16
|
+
/** Path parameters extracted from route pattern (e.g., :id) */
|
|
17
|
+
params: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Function that transforms HTTP context to fabric service input
|
|
21
|
+
*/
|
|
22
|
+
export type HttpTransformFunction<TInput = Record<string, unknown>> = (context: HttpContext) => TInput | Promise<TInput>;
|
|
23
|
+
/**
|
|
24
|
+
* Authorization function that validates a token and returns auth context
|
|
25
|
+
* Token is extracted from Authorization header with Bearer prefix removed
|
|
26
|
+
*/
|
|
27
|
+
export type AuthorizationFunction<TAuth = unknown> = (token: string) => TAuth | Promise<TAuth>;
|
|
28
|
+
/**
|
|
29
|
+
* Authorization configuration - either a function or false for public endpoints
|
|
30
|
+
*/
|
|
31
|
+
export type AuthorizationConfig<TAuth = unknown> = AuthorizationFunction<TAuth> | false;
|
|
32
|
+
/**
|
|
33
|
+
* CORS configuration options
|
|
34
|
+
*/
|
|
35
|
+
export interface CorsConfig {
|
|
36
|
+
/** Allowed origins - "*" for all, or array of specific origins */
|
|
37
|
+
origin?: string | string[];
|
|
38
|
+
/** Allow credentials (Access-Control-Allow-Credentials) */
|
|
39
|
+
credentials?: boolean;
|
|
40
|
+
/** Additional allowed headers (Access-Control-Allow-Headers) */
|
|
41
|
+
headers?: string[];
|
|
42
|
+
/** Headers to expose to the client (Access-Control-Expose-Headers) */
|
|
43
|
+
exposeHeaders?: string[];
|
|
44
|
+
/** Preflight cache duration in seconds (Access-Control-Max-Age) */
|
|
45
|
+
maxAge?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* CORS configuration - object config, true for defaults, or false to disable
|
|
49
|
+
*/
|
|
50
|
+
export type CorsOption = CorsConfig | boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Resolved CORS headers to send in response
|
|
53
|
+
*/
|
|
54
|
+
export interface CorsHeaders {
|
|
55
|
+
"Access-Control-Allow-Origin"?: string;
|
|
56
|
+
"Access-Control-Allow-Methods"?: string;
|
|
57
|
+
"Access-Control-Allow-Headers"?: string;
|
|
58
|
+
"Access-Control-Allow-Credentials"?: string;
|
|
59
|
+
"Access-Control-Expose-Headers"?: string;
|
|
60
|
+
"Access-Control-Max-Age"?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* JSON:API-style success response envelope
|
|
64
|
+
*/
|
|
65
|
+
export interface DataResponse<T = unknown> {
|
|
66
|
+
data: T;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* JSON:API-style error object
|
|
70
|
+
*/
|
|
71
|
+
export interface ErrorObject {
|
|
72
|
+
status: number;
|
|
73
|
+
title: string;
|
|
74
|
+
detail?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* JSON:API-style error response envelope
|
|
78
|
+
*/
|
|
79
|
+
export interface ErrorResponse {
|
|
80
|
+
errors: ErrorObject[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* HTTP service configuration - extends base ServiceConfig with HTTP-specific options
|
|
84
|
+
*/
|
|
85
|
+
export interface FabricHttpConfig<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown, TAuth = unknown> extends Omit<ServiceConfig<TInput, TOutput>, "service"> {
|
|
86
|
+
/** Pre-built fabricService or inline service function */
|
|
87
|
+
service?: Service<TInput, TOutput> | ServiceConfig<TInput, TOutput>["service"];
|
|
88
|
+
/** Transform HTTP context to service input (defaults to body + query merge) */
|
|
89
|
+
http?: HttpTransformFunction<TInput>;
|
|
90
|
+
/** Authorization function or false for public endpoints */
|
|
91
|
+
authorization?: AuthorizationConfig<TAuth>;
|
|
92
|
+
/** CORS configuration (enabled by default) */
|
|
93
|
+
cors?: CorsOption;
|
|
94
|
+
/** Streaming configuration (disabled by default) */
|
|
95
|
+
stream?: StreamOption;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* HTTP service - fabricService with HTTP-specific metadata
|
|
99
|
+
*/
|
|
100
|
+
export interface FabricHttpService<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown, TAuth = unknown> extends Service<TInput, TOutput> {
|
|
101
|
+
/** HTTP transformation function */
|
|
102
|
+
http: HttpTransformFunction<TInput>;
|
|
103
|
+
/** Authorization configuration */
|
|
104
|
+
authorization: AuthorizationConfig<TAuth>;
|
|
105
|
+
/** CORS configuration */
|
|
106
|
+
cors: CorsOption;
|
|
107
|
+
/** Streaming configuration */
|
|
108
|
+
stream: StreamOption;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Supported HTTP methods
|
|
112
|
+
*/
|
|
113
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
|
|
114
|
+
/**
|
|
115
|
+
* Default HTTP methods for fabric services
|
|
116
|
+
*/
|
|
117
|
+
export declare const DEFAULT_HTTP_METHODS: HttpMethod[];
|
|
118
|
+
/**
|
|
119
|
+
* HTTP stream event types for SSE/NDJSON streaming
|
|
120
|
+
*/
|
|
121
|
+
export declare enum HttpStreamEventType {
|
|
122
|
+
/** Stream complete */
|
|
123
|
+
Complete = "complete",
|
|
124
|
+
/** Final response data */
|
|
125
|
+
Data = "data",
|
|
126
|
+
/** Error event */
|
|
127
|
+
Error = "error",
|
|
128
|
+
/** Fabric progress message (from sendMessage) */
|
|
129
|
+
Message = "message",
|
|
130
|
+
/** Keep-alive signal (no content) */
|
|
131
|
+
Noop = "noop",
|
|
132
|
+
/** LLM text chunk */
|
|
133
|
+
Text = "text",
|
|
134
|
+
/** LLM tool call event */
|
|
135
|
+
ToolCall = "tool_call",
|
|
136
|
+
/** LLM tool result event */
|
|
137
|
+
ToolResult = "tool_result"
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Base stream event structure
|
|
141
|
+
*/
|
|
142
|
+
export interface HttpStreamEventBase {
|
|
143
|
+
stream: HttpStreamEventType;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Message event - progress updates from sendMessage
|
|
147
|
+
*/
|
|
148
|
+
export interface HttpStreamEventMessage extends HttpStreamEventBase {
|
|
149
|
+
stream: HttpStreamEventType.Message;
|
|
150
|
+
content: string;
|
|
151
|
+
level?: "trace" | "debug" | "info" | "warn" | "error";
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Text event - LLM text chunk
|
|
155
|
+
*/
|
|
156
|
+
export interface HttpStreamEventText extends HttpStreamEventBase {
|
|
157
|
+
stream: HttpStreamEventType.Text;
|
|
158
|
+
content: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Tool call event - LLM requesting tool execution
|
|
162
|
+
*/
|
|
163
|
+
export interface HttpStreamEventToolCall extends HttpStreamEventBase {
|
|
164
|
+
stream: HttpStreamEventType.ToolCall;
|
|
165
|
+
toolCall: {
|
|
166
|
+
id: string;
|
|
167
|
+
name: string;
|
|
168
|
+
arguments: string;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Tool result event - result from tool execution
|
|
173
|
+
*/
|
|
174
|
+
export interface HttpStreamEventToolResult extends HttpStreamEventBase {
|
|
175
|
+
stream: HttpStreamEventType.ToolResult;
|
|
176
|
+
toolResult: {
|
|
177
|
+
id: string;
|
|
178
|
+
name: string;
|
|
179
|
+
result: unknown;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Data event - final response data
|
|
184
|
+
*/
|
|
185
|
+
export interface HttpStreamEventData<T = unknown> extends HttpStreamEventBase {
|
|
186
|
+
stream: HttpStreamEventType.Data;
|
|
187
|
+
data: T;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Error event
|
|
191
|
+
*/
|
|
192
|
+
export interface HttpStreamEventError extends HttpStreamEventBase {
|
|
193
|
+
stream: HttpStreamEventType.Error;
|
|
194
|
+
error: {
|
|
195
|
+
status: number | string;
|
|
196
|
+
title: string;
|
|
197
|
+
detail?: string;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Complete event - stream complete
|
|
202
|
+
*/
|
|
203
|
+
export interface HttpStreamEventComplete extends HttpStreamEventBase {
|
|
204
|
+
stream: HttpStreamEventType.Complete;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Noop event - keep-alive signal
|
|
208
|
+
*/
|
|
209
|
+
export interface HttpStreamEventNoop extends HttpStreamEventBase {
|
|
210
|
+
stream: HttpStreamEventType.Noop;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Union of all stream event types
|
|
214
|
+
*/
|
|
215
|
+
export type HttpStreamEvent = HttpStreamEventComplete | HttpStreamEventData | HttpStreamEventError | HttpStreamEventMessage | HttpStreamEventNoop | HttpStreamEventText | HttpStreamEventToolCall | HttpStreamEventToolResult;
|
|
216
|
+
/**
|
|
217
|
+
* Stream configuration options (internal)
|
|
218
|
+
*/
|
|
219
|
+
export interface StreamConfig {
|
|
220
|
+
/** Output format - NDJSON (default) or SSE */
|
|
221
|
+
format?: "ndjson" | "sse";
|
|
222
|
+
/** Keep-alive heartbeat interval in ms (default: 15000) */
|
|
223
|
+
heartbeat?: number;
|
|
224
|
+
/** Include tool calls/results in stream (default: true) */
|
|
225
|
+
includeTools?: boolean;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Stream option - true to enable streaming, false to disable
|
|
229
|
+
*/
|
|
230
|
+
export type StreamOption = boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Streaming service function that yields events
|
|
233
|
+
*/
|
|
234
|
+
export type StreamingServiceFunction<TInput extends Record<string, unknown> = Record<string, unknown>> = (input: TInput, context: unknown) => AsyncIterable<HttpStreamEvent> | Promise<AsyncIterable<HttpStreamEvent>>;
|
|
235
|
+
/**
|
|
236
|
+
* Route entry for FabricHttpServer - service with path and method configuration
|
|
237
|
+
*/
|
|
238
|
+
export interface FabricHttpServerRoute<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown, TAuth = unknown> {
|
|
239
|
+
/** The FabricHttpService to handle requests */
|
|
240
|
+
service: FabricHttpService<TInput, TOutput, TAuth>;
|
|
241
|
+
/** Route path pattern (defaults to /${alias}) */
|
|
242
|
+
path?: string;
|
|
243
|
+
/** Allowed HTTP methods (defaults to DEFAULT_HTTP_METHODS) */
|
|
244
|
+
methods?: HttpMethod[];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Service entry - either a FabricHttpService or a route config
|
|
248
|
+
*/
|
|
249
|
+
export type FabricHttpServerServiceEntry = FabricHttpService | FabricHttpServerRoute;
|
|
250
|
+
/**
|
|
251
|
+
* Configuration for FabricHttpServer
|
|
252
|
+
*/
|
|
253
|
+
export interface FabricHttpServerConfig {
|
|
254
|
+
/** Array of services or route configs to register */
|
|
255
|
+
services: FabricHttpServerServiceEntry[];
|
|
256
|
+
/** Server-level authorization (applied to all services unless overridden) */
|
|
257
|
+
authorization?: AuthorizationConfig;
|
|
258
|
+
/** Server-level CORS config (applied to all services unless overridden) */
|
|
259
|
+
cors?: CorsOption;
|
|
260
|
+
/** Path prefix for all routes (e.g., "/api") */
|
|
261
|
+
prefix?: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* API Gateway v1 (REST API) event format
|
|
265
|
+
*/
|
|
266
|
+
export interface ApiGatewayV1Event {
|
|
267
|
+
body: string | null;
|
|
268
|
+
headers: Record<string, string>;
|
|
269
|
+
httpMethod: string;
|
|
270
|
+
path: string;
|
|
271
|
+
pathParameters?: Record<string, string> | null;
|
|
272
|
+
queryStringParameters?: Record<string, string> | null;
|
|
273
|
+
requestContext?: {
|
|
274
|
+
requestId?: string;
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* API Gateway v2 (HTTP API) event format
|
|
279
|
+
*/
|
|
280
|
+
export interface ApiGatewayV2Event {
|
|
281
|
+
body?: string;
|
|
282
|
+
headers: Record<string, string>;
|
|
283
|
+
rawPath: string;
|
|
284
|
+
rawQueryString?: string;
|
|
285
|
+
requestContext: {
|
|
286
|
+
http: {
|
|
287
|
+
method: string;
|
|
288
|
+
path: string;
|
|
289
|
+
};
|
|
290
|
+
requestId?: string;
|
|
291
|
+
};
|
|
292
|
+
pathParameters?: Record<string, string>;
|
|
293
|
+
queryStringParameters?: Record<string, string>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Union of API Gateway event types
|
|
297
|
+
*/
|
|
298
|
+
export type ApiGatewayEvent = ApiGatewayV1Event | ApiGatewayV2Event;
|
|
299
|
+
/**
|
|
300
|
+
* API Gateway response format (compatible with v1 and v2)
|
|
301
|
+
*/
|
|
302
|
+
export interface ApiGatewayResponse {
|
|
303
|
+
statusCode: number;
|
|
304
|
+
headers: Record<string, string>;
|
|
305
|
+
body: string;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Registered route with resolved path and methods
|
|
309
|
+
*/
|
|
310
|
+
export interface RegisteredRoute {
|
|
311
|
+
/** Compiled path pattern */
|
|
312
|
+
path: string;
|
|
313
|
+
/** Path segments for matching */
|
|
314
|
+
segments: string[];
|
|
315
|
+
/** Allowed methods */
|
|
316
|
+
methods: HttpMethod[];
|
|
317
|
+
/** The service to handle requests */
|
|
318
|
+
service: FabricHttpService;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Match result from route matching
|
|
322
|
+
*/
|
|
323
|
+
export interface RouteMatch {
|
|
324
|
+
/** The matched route */
|
|
325
|
+
route: RegisteredRoute;
|
|
326
|
+
/** Extracted path parameters */
|
|
327
|
+
params: Record<string, string>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* FabricHttpServer handler function
|
|
331
|
+
*/
|
|
332
|
+
export type FabricHttpServerHandler = (event: ApiGatewayEvent) => Promise<ApiGatewayResponse>;
|
|
333
|
+
/**
|
|
334
|
+
* FabricHttpServer with metadata
|
|
335
|
+
*/
|
|
336
|
+
export interface FabricHttpServer extends FabricHttpServerHandler {
|
|
337
|
+
/** Registered services */
|
|
338
|
+
services: FabricHttpService[];
|
|
339
|
+
/** Route prefix */
|
|
340
|
+
prefix?: string;
|
|
341
|
+
/** Registered routes */
|
|
342
|
+
routes: RegisteredRoute[];
|
|
343
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Module for @jaypie/fabric
|
|
3
|
+
*
|
|
4
|
+
* Exports all index-related types, functions, and constants.
|
|
5
|
+
*/
|
|
6
|
+
export { ARCHIVED_SUFFIX, DEFAULT_INDEXES, DEFAULT_SORT_KEY, DELETED_SUFFIX, type IndexDefinition, type IndexField, type ModelSchema, } from "./types.js";
|
|
7
|
+
export { buildCompositeKey, calculateIndexSuffix, calculateScope, generateIndexName, type IndexableModel, populateIndexKeys, tryBuildCompositeKey, } from "./keyBuilder.js";
|
|
8
|
+
export { clearRegistry, getAllRegisteredIndexes, getModelIndexes, getModelSchema, getRegisteredModels, isModelRegistered, registerModel, } from "./registry.js";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key Builder for @jaypie/fabric
|
|
3
|
+
*
|
|
4
|
+
* Builds composite keys from model fields and index definitions.
|
|
5
|
+
*/
|
|
6
|
+
import { type IndexDefinition, type IndexField } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Model with fields for indexing.
|
|
9
|
+
*
|
|
10
|
+
* Does not extend FabricModel to allow flexibility with timestamp types
|
|
11
|
+
* (DynamoDB uses string timestamps, FabricModel uses Date objects).
|
|
12
|
+
*/
|
|
13
|
+
export interface IndexableModel {
|
|
14
|
+
/** Schema reference (required for indexing) */
|
|
15
|
+
model: string;
|
|
16
|
+
/** Scope (optional) */
|
|
17
|
+
scope?: string;
|
|
18
|
+
/** Chronological ordering timestamp (optional) */
|
|
19
|
+
sequence?: number;
|
|
20
|
+
/** Archived timestamp - presence triggers #archived suffix */
|
|
21
|
+
archivedAt?: Date | string | null;
|
|
22
|
+
/** Deleted timestamp - presence triggers #deleted suffix */
|
|
23
|
+
deletedAt?: Date | string | null;
|
|
24
|
+
/** Allow any additional fields */
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build a composite key from model fields
|
|
29
|
+
*
|
|
30
|
+
* @param model - Model with fields to extract
|
|
31
|
+
* @param fields - Field names to combine
|
|
32
|
+
* @param suffix - Optional suffix to append (e.g., "#deleted")
|
|
33
|
+
* @returns Composite key string (e.g., "@#record#my-alias")
|
|
34
|
+
* @throws ConfigurationError if a required field is missing
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildCompositeKey(model: IndexableModel, fields: IndexField[], suffix?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Try to build a composite key, returning undefined if fields are missing
|
|
39
|
+
*
|
|
40
|
+
* @param model - Model with fields to extract
|
|
41
|
+
* @param fields - Field names to combine
|
|
42
|
+
* @param suffix - Optional suffix to append
|
|
43
|
+
* @returns Composite key string or undefined if fields missing
|
|
44
|
+
*/
|
|
45
|
+
export declare function tryBuildCompositeKey(model: IndexableModel, fields: IndexField[], suffix?: string): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Generate an index name from partition key fields
|
|
48
|
+
*
|
|
49
|
+
* @param pk - Partition key field names
|
|
50
|
+
* @returns Generated index name (e.g., "indexOuModelAlias")
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateIndexName(pk: IndexField[]): string;
|
|
53
|
+
/**
|
|
54
|
+
* Calculate the suffix for index keys based on model state
|
|
55
|
+
*
|
|
56
|
+
* @param model - Model to check for archived/deleted state
|
|
57
|
+
* @returns Suffix string (e.g., "", "#archived", "#deleted", "#archived#deleted")
|
|
58
|
+
*/
|
|
59
|
+
export declare function calculateIndexSuffix(model: IndexableModel): string;
|
|
60
|
+
/**
|
|
61
|
+
* Populate index keys on a model based on index definitions
|
|
62
|
+
*
|
|
63
|
+
* Only the partition key composite is stored on the model (e.g., indexOu).
|
|
64
|
+
* The sort key (e.g., sequence) is a regular field that the GSI references directly.
|
|
65
|
+
*
|
|
66
|
+
* @param model - Model to populate index keys on
|
|
67
|
+
* @param indexes - Index definitions to use
|
|
68
|
+
* @param suffix - Optional suffix to append to all index keys
|
|
69
|
+
* @returns Model with index keys populated
|
|
70
|
+
*/
|
|
71
|
+
export declare function populateIndexKeys<T extends IndexableModel>(model: T, indexes: IndexDefinition[], suffix?: string): T;
|
|
72
|
+
/**
|
|
73
|
+
* Calculate scope from parent reference
|
|
74
|
+
*
|
|
75
|
+
* @param parent - Parent model with model and id
|
|
76
|
+
* @returns Scope string ("{parent.model}#{parent.id}") or APEX ("@") if no parent
|
|
77
|
+
*/
|
|
78
|
+
export declare function calculateScope(parent?: {
|
|
79
|
+
id: string;
|
|
80
|
+
model: string;
|
|
81
|
+
}): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Registry for @jaypie/fabric
|
|
3
|
+
*
|
|
4
|
+
* Stores model schemas with their index definitions.
|
|
5
|
+
* DynamoDB reads from this registry to create GSIs and select indexes for queries.
|
|
6
|
+
*/
|
|
7
|
+
import { type IndexDefinition, type ModelSchema } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Register a model schema with its index definitions
|
|
10
|
+
*
|
|
11
|
+
* @param schema - Model schema with model name and optional indexes
|
|
12
|
+
*/
|
|
13
|
+
export declare function registerModel(schema: ModelSchema): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get a model schema by name
|
|
16
|
+
*
|
|
17
|
+
* @param model - Model name to look up
|
|
18
|
+
* @returns Model schema or undefined if not registered
|
|
19
|
+
*/
|
|
20
|
+
export declare function getModelSchema(model: string): ModelSchema | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Get index definitions for a model
|
|
23
|
+
*
|
|
24
|
+
* Returns the model's custom indexes if registered,
|
|
25
|
+
* otherwise returns DEFAULT_INDEXES.
|
|
26
|
+
*
|
|
27
|
+
* @param model - Model name to get indexes for
|
|
28
|
+
* @returns Array of index definitions
|
|
29
|
+
*/
|
|
30
|
+
export declare function getModelIndexes(model: string): IndexDefinition[];
|
|
31
|
+
/**
|
|
32
|
+
* Get all registered models
|
|
33
|
+
*
|
|
34
|
+
* @returns Array of model names
|
|
35
|
+
*/
|
|
36
|
+
export declare function getRegisteredModels(): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Get all unique indexes across all registered models
|
|
39
|
+
*
|
|
40
|
+
* Used by createTable to collect all GSIs that need to be created.
|
|
41
|
+
* Deduplicates by index name.
|
|
42
|
+
*
|
|
43
|
+
* @returns Array of unique index definitions
|
|
44
|
+
*/
|
|
45
|
+
export declare function getAllRegisteredIndexes(): IndexDefinition[];
|
|
46
|
+
/**
|
|
47
|
+
* Check if a model is registered
|
|
48
|
+
*
|
|
49
|
+
* @param model - Model name to check
|
|
50
|
+
* @returns true if model is registered
|
|
51
|
+
*/
|
|
52
|
+
export declare function isModelRegistered(model: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Clear the model registry (for testing)
|
|
55
|
+
*/
|
|
56
|
+
export declare function clearRegistry(): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Types for @jaypie/fabric
|
|
3
|
+
*
|
|
4
|
+
* Declarative index definitions for DynamoDB single-table design.
|
|
5
|
+
* Models can specify their own indexes, and dynamodb will create
|
|
6
|
+
* GSIs and auto-detect which index to use for queries.
|
|
7
|
+
*/
|
|
8
|
+
import type { FabricModel } from "../models/base.js";
|
|
9
|
+
/**
|
|
10
|
+
* Index field - can be a FabricModel field name or custom field
|
|
11
|
+
*/
|
|
12
|
+
export type IndexField = keyof FabricModel | string;
|
|
13
|
+
/**
|
|
14
|
+
* Single index definition
|
|
15
|
+
*
|
|
16
|
+
* pk fields are combined with SEPARATOR to form the partition key.
|
|
17
|
+
* sk fields are combined with SEPARATOR to form the sort key.
|
|
18
|
+
*/
|
|
19
|
+
export interface IndexDefinition {
|
|
20
|
+
/** Name of the index (auto-generated from pk fields if not provided) */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** Partition key fields - combined with SEPARATOR */
|
|
23
|
+
pk: IndexField[];
|
|
24
|
+
/** Sort key fields - combined with SEPARATOR (default: ["sequence"]) */
|
|
25
|
+
sk?: IndexField[];
|
|
26
|
+
/** Only create index key when ALL pk fields are present on model */
|
|
27
|
+
sparse?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Model schema with index definitions
|
|
31
|
+
*/
|
|
32
|
+
export interface ModelSchema {
|
|
33
|
+
/** The model name (e.g., "record", "message", "chat") */
|
|
34
|
+
model: string;
|
|
35
|
+
/** Custom indexes for this model (uses DEFAULT_INDEXES if not specified) */
|
|
36
|
+
indexes?: IndexDefinition[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Default indexes for the DynamoDB GSI pattern.
|
|
40
|
+
* These are used when a model does not specify custom indexes.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_INDEXES: IndexDefinition[];
|
|
43
|
+
/**
|
|
44
|
+
* Default sort key fields when sk is not specified
|
|
45
|
+
*/
|
|
46
|
+
export declare const DEFAULT_SORT_KEY: IndexField[];
|
|
47
|
+
/**
|
|
48
|
+
* Suffix appended to index keys when model is archived
|
|
49
|
+
*/
|
|
50
|
+
export declare const ARCHIVED_SUFFIX = "#archived";
|
|
51
|
+
/**
|
|
52
|
+
* Suffix appended to index keys when model is deleted
|
|
53
|
+
*/
|
|
54
|
+
export declare const DELETED_SUFFIX = "#deleted";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { createFabricModelInput, FABRIC_MODEL_AUTO_FIELDS, FABRIC_MODEL_FIELDS, FABRIC_MODEL_REQUIRED_FIELDS, FABRIC_MODEL_TIMESTAMP_FIELDS, hasFabricModelShape, isAutoField, isFabricModel, isTimestampField, pickFabricModelFields, } from "./models/base.js";
|
|
2
|
+
export type { FabricHistoryEntry, FabricJob, FabricMessage, FabricModel, FabricModelFilter, FabricModelInput, FabricModelUpdate, FabricProgress, } from "./models/base.js";
|
|
3
|
+
export { APEX, FABRIC_VERSION, SEPARATOR, SYSTEM_MODELS } from "./constants.js";
|
|
4
|
+
export type { SystemModel } from "./constants.js";
|
|
5
|
+
export { fabric, fabricArray, fabricBoolean, fabricNumber, fabricObject, fabricString, resolveFromArray, resolveFromObject, } from "./resolve.js";
|
|
6
|
+
export { DateType, fabricDate, isDateType, isValidDate, resolveFromDate, } from "./resolve-date.js";
|
|
7
|
+
export { computeResolvedName, resolveWithFallback } from "./helpers/index.js";
|
|
8
|
+
export type { ResolvedNameModel } from "./helpers/index.js";
|
|
9
|
+
export { ARCHIVED_SUFFIX, buildCompositeKey, calculateIndexSuffix, calculateScope, clearRegistry, DEFAULT_INDEXES, DEFAULT_SORT_KEY, DELETED_SUFFIX, generateIndexName, getAllRegisteredIndexes, getModelIndexes, getModelSchema, getRegisteredModels, isModelRegistered, populateIndexKeys, registerModel, tryBuildCompositeKey, } from "./index/index.js";
|
|
10
|
+
export type { IndexableModel, IndexDefinition, IndexField, ModelSchema, } from "./index/index.js";
|
|
11
|
+
export { BOOLEAN_TYPE, DATE_TYPE, DATETIME_TYPE, DOLLARS_TYPE, ELEMENTARY_TYPE_REGISTRY, ELEMENTARY_TYPES, getAllElementaryTypes, getElementaryType, isElementaryType, isFieldDefinition, MULTISELECT_TYPE, NUMBER_TYPE, REFERENCE_TYPE, SELECT_TYPE, TEXT_TYPE, TEXTAREA_TYPE, } from "./types/index.js";
|
|
12
|
+
export type { ElementaryType, ElementaryTypeDefinition, FieldDefinition, FieldRef, ValidationRule, } from "./types/index.js";
|
|
13
|
+
export { fabricService } from "./service.js";
|
|
14
|
+
export { resolveService } from "./resolveService.js";
|
|
15
|
+
export type { ResolveServiceConfig } from "./resolveService.js";
|
|
16
|
+
export { isStatus, STATUS_VALUES, StatusType } from "./status.js";
|
|
17
|
+
export type { Status } from "./status.js";
|
|
18
|
+
export type { ArrayElementType, CompositeType, ConversionType, DateConversionType, InputFieldDefinition, Message, MessageLevel, RegExpType, ScalarType, Service, ServiceConfig, ServiceContext, ServiceFunction, TypedArrayType, ValidatedNumberType, ValidatedStringType, ValidateFunction, } from "./types.js";
|