khotan-data 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -6
- package/dist/cli.js +292 -8
- package/dist/factory.cjs +1083 -99
- package/dist/factory.cjs.map +1 -1
- package/dist/factory.d.cts +225 -38
- package/dist/factory.d.ts +225 -38
- package/dist/factory.js +1082 -101
- package/dist/factory.js.map +1 -1
- package/dist/templates/cache.example.ts +11 -0
- package/dist/templates/cache.ts +58 -0
- package/dist/templates/catch.ts +13 -1
- package/dist/templates/inflow.ts +5 -6
- package/dist/templates/khotan-config.ts +13 -4
- package/dist/templates/mapping-browser.tsx +761 -0
- package/dist/templates/mappings-page.tsx +9 -0
- package/dist/templates/outflow.ts +5 -5
- package/dist/templates/pass.ts +10 -0
- package/dist/templates/relay.example.ts +11 -1
- package/dist/templates/relay.ts +16 -7
- package/dist/templates/schema.ts +81 -0
- package/dist/templates/skill-plug.md +38 -15
- package/dist/templates/skill-setup.md +44 -2
- package/package.json +1 -1
package/dist/factory.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { PgDatabase } from 'drizzle-orm/pg-core';
|
|
2
2
|
|
|
3
|
+
type ResourceConnectField = string | [string, ...string[]];
|
|
4
|
+
interface ResourcePlugParticipation {
|
|
5
|
+
uniqueIdentifier: string;
|
|
6
|
+
}
|
|
7
|
+
interface ResourceMappingRegistration {
|
|
8
|
+
connectField: ResourceConnectField;
|
|
9
|
+
plugs?: Record<string, ResourcePlugParticipation>;
|
|
10
|
+
}
|
|
3
11
|
interface ResourceRegistration {
|
|
4
12
|
name: string;
|
|
5
|
-
connectField: string;
|
|
6
13
|
description?: string;
|
|
14
|
+
mapping: ResourceMappingRegistration;
|
|
7
15
|
}
|
|
8
16
|
type FlowType = "inflow" | "outflow" | "relay" | "webhook";
|
|
9
17
|
type KhotanRunStatus = "pending" | "running" | "completed" | "partial" | "failed" | "cancelled";
|
|
@@ -19,31 +27,64 @@ interface FlowRunResult {
|
|
|
19
27
|
error?: string | null;
|
|
20
28
|
metadata?: Record<string, unknown> | null;
|
|
21
29
|
}
|
|
30
|
+
interface BoundPlug {
|
|
31
|
+
get<T>(path: string, options?: {
|
|
32
|
+
params?: Record<string, unknown>;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
}): Promise<T>;
|
|
35
|
+
post<T>(path: string, options?: {
|
|
36
|
+
body?: unknown;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}): Promise<T>;
|
|
39
|
+
put<T>(path: string, options?: {
|
|
40
|
+
body?: unknown;
|
|
41
|
+
headers?: Record<string, string>;
|
|
42
|
+
}): Promise<T>;
|
|
43
|
+
patch<T>(path: string, options?: {
|
|
44
|
+
body?: unknown;
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
}): Promise<T>;
|
|
47
|
+
delete<T>(path: string, options?: {
|
|
48
|
+
headers?: Record<string, string>;
|
|
49
|
+
}): Promise<T>;
|
|
50
|
+
}
|
|
51
|
+
interface BindablePlug {
|
|
52
|
+
get<T>(path: string, options?: {
|
|
53
|
+
params?: Record<string, unknown>;
|
|
54
|
+
headers?: Record<string, string>;
|
|
55
|
+
vars?: Record<string, string>;
|
|
56
|
+
_setVars?: (updates: Record<string, string>) => Promise<void>;
|
|
57
|
+
}): Promise<T>;
|
|
58
|
+
post<T>(path: string, options?: {
|
|
59
|
+
body?: unknown;
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
vars?: Record<string, string>;
|
|
62
|
+
_setVars?: (updates: Record<string, string>) => Promise<void>;
|
|
63
|
+
}): Promise<T>;
|
|
64
|
+
put<T>(path: string, options?: {
|
|
65
|
+
body?: unknown;
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
vars?: Record<string, string>;
|
|
68
|
+
_setVars?: (updates: Record<string, string>) => Promise<void>;
|
|
69
|
+
}): Promise<T>;
|
|
70
|
+
patch<T>(path: string, options?: {
|
|
71
|
+
body?: unknown;
|
|
72
|
+
headers?: Record<string, string>;
|
|
73
|
+
vars?: Record<string, string>;
|
|
74
|
+
_setVars?: (updates: Record<string, string>) => Promise<void>;
|
|
75
|
+
}): Promise<T>;
|
|
76
|
+
delete<T>(path: string, options?: {
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
vars?: Record<string, string>;
|
|
79
|
+
_setVars?: (updates: Record<string, string>) => Promise<void>;
|
|
80
|
+
}): Promise<T>;
|
|
81
|
+
}
|
|
22
82
|
interface FlowRunContext {
|
|
23
|
-
plug:
|
|
24
|
-
get<T>(path: string, options?: {
|
|
25
|
-
params?: Record<string, unknown>;
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
}): Promise<T>;
|
|
28
|
-
post<T>(path: string, options?: {
|
|
29
|
-
body?: unknown;
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
}): Promise<T>;
|
|
32
|
-
put<T>(path: string, options?: {
|
|
33
|
-
body?: unknown;
|
|
34
|
-
headers?: Record<string, string>;
|
|
35
|
-
}): Promise<T>;
|
|
36
|
-
patch<T>(path: string, options?: {
|
|
37
|
-
body?: unknown;
|
|
38
|
-
headers?: Record<string, string>;
|
|
39
|
-
}): Promise<T>;
|
|
40
|
-
delete<T>(path: string, options?: {
|
|
41
|
-
headers?: Record<string, string>;
|
|
42
|
-
}): Promise<T>;
|
|
43
|
-
};
|
|
83
|
+
plug: BoundPlug;
|
|
44
84
|
flow: {
|
|
45
85
|
id: string;
|
|
46
86
|
name: string;
|
|
87
|
+
plugName: string;
|
|
47
88
|
type: FlowType;
|
|
48
89
|
resource?: string | null;
|
|
49
90
|
to?: string | null;
|
|
@@ -52,11 +93,13 @@ interface FlowRunContext {
|
|
|
52
93
|
body?: unknown;
|
|
53
94
|
vars: Record<string, string>;
|
|
54
95
|
setVars(updates: Record<string, string>): Promise<void>;
|
|
96
|
+
cache(cacheName: string): CacheInstance;
|
|
55
97
|
}
|
|
56
98
|
interface FlowWorkflowContext {
|
|
57
99
|
flow: {
|
|
58
100
|
id: string;
|
|
59
101
|
name: string;
|
|
102
|
+
plugName: string;
|
|
60
103
|
type: FlowType;
|
|
61
104
|
resource?: string | null;
|
|
62
105
|
to?: string | null;
|
|
@@ -64,8 +107,11 @@ interface FlowWorkflowContext {
|
|
|
64
107
|
runType: string;
|
|
65
108
|
body?: unknown;
|
|
66
109
|
vars: Record<string, string>;
|
|
110
|
+
plugVarsByName?: Record<string, Record<string, string>>;
|
|
67
111
|
khotanRunId: string;
|
|
112
|
+
khotanInstanceId: string;
|
|
68
113
|
}
|
|
114
|
+
declare function bindWorkflowPlug(plug: BindablePlug, ctx: FlowWorkflowContext, plugName?: string): BoundPlug;
|
|
69
115
|
interface KhotanRunUpdate {
|
|
70
116
|
type?: "progress" | "log" | "metric" | "error";
|
|
71
117
|
message: string;
|
|
@@ -157,27 +203,98 @@ interface CatchRegistration {
|
|
|
157
203
|
type: "catch";
|
|
158
204
|
name: string;
|
|
159
205
|
events?: string[];
|
|
160
|
-
workflow: (ctx:
|
|
161
|
-
event: Record<string, unknown>;
|
|
162
|
-
eventType: string;
|
|
163
|
-
headers: Record<string, string>;
|
|
164
|
-
khotanRunId: string;
|
|
165
|
-
}) => Promise<void>;
|
|
206
|
+
workflow: (ctx: CatchWorkflowContext) => Promise<void>;
|
|
166
207
|
}
|
|
167
208
|
interface PassRegistration {
|
|
168
209
|
type: "pass";
|
|
169
210
|
name: string;
|
|
170
211
|
to: string;
|
|
171
212
|
events?: string[];
|
|
172
|
-
workflow: (ctx:
|
|
173
|
-
event: Record<string, unknown>;
|
|
174
|
-
eventType: string;
|
|
175
|
-
headers: Record<string, string>;
|
|
176
|
-
destVars: Record<string, string>;
|
|
177
|
-
khotanRunId: string;
|
|
178
|
-
}) => Promise<void>;
|
|
213
|
+
workflow: (ctx: PassWorkflowContext) => Promise<void>;
|
|
179
214
|
}
|
|
180
215
|
type WebhookRegistration = CatchRegistration | PassRegistration;
|
|
216
|
+
interface CacheScope {
|
|
217
|
+
plug?: string;
|
|
218
|
+
resource?: string;
|
|
219
|
+
flow?: string;
|
|
220
|
+
}
|
|
221
|
+
interface CacheRegistration {
|
|
222
|
+
name: string;
|
|
223
|
+
scope?: CacheScope;
|
|
224
|
+
ttl?: string | number;
|
|
225
|
+
}
|
|
226
|
+
interface CacheEntryRecord {
|
|
227
|
+
id: string;
|
|
228
|
+
cacheId: string;
|
|
229
|
+
key: string;
|
|
230
|
+
value: unknown;
|
|
231
|
+
expiresAt: Date | null;
|
|
232
|
+
createdAt?: Date | undefined;
|
|
233
|
+
updatedAt?: Date | undefined;
|
|
234
|
+
}
|
|
235
|
+
interface CacheInstance {
|
|
236
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
237
|
+
set<T = unknown>(key: string, value: T): Promise<T>;
|
|
238
|
+
delete(key: string): Promise<void>;
|
|
239
|
+
}
|
|
240
|
+
interface CatchWorkflowContext {
|
|
241
|
+
event: Record<string, unknown>;
|
|
242
|
+
eventType: string;
|
|
243
|
+
headers: Record<string, string>;
|
|
244
|
+
khotanRunId: string;
|
|
245
|
+
khotanInstanceId: string;
|
|
246
|
+
}
|
|
247
|
+
interface PassWorkflowContext {
|
|
248
|
+
event: Record<string, unknown>;
|
|
249
|
+
eventType: string;
|
|
250
|
+
headers: Record<string, string>;
|
|
251
|
+
destVars: Record<string, string>;
|
|
252
|
+
khotanRunId: string;
|
|
253
|
+
khotanInstanceId: string;
|
|
254
|
+
}
|
|
255
|
+
interface KhotanWorkflowContextRef {
|
|
256
|
+
khotanInstanceId: string;
|
|
257
|
+
}
|
|
258
|
+
declare function khotanCache(ctx: KhotanWorkflowContextRef, cacheName: string): CacheInstance;
|
|
259
|
+
declare function khotanMappings(ctx: KhotanWorkflowContextRef): {
|
|
260
|
+
list: (params: {
|
|
261
|
+
resourceId: string;
|
|
262
|
+
limit?: number;
|
|
263
|
+
offset?: number;
|
|
264
|
+
search?: string;
|
|
265
|
+
}) => Promise<{
|
|
266
|
+
items: Record<string, unknown>[];
|
|
267
|
+
page: {
|
|
268
|
+
limit: number;
|
|
269
|
+
offset: number;
|
|
270
|
+
hasMore: boolean;
|
|
271
|
+
prevOffset: number;
|
|
272
|
+
nextOffset: number;
|
|
273
|
+
total: number;
|
|
274
|
+
};
|
|
275
|
+
}>;
|
|
276
|
+
lookup: (params: {
|
|
277
|
+
resourceId: string;
|
|
278
|
+
connectValue: string | string[];
|
|
279
|
+
} | {
|
|
280
|
+
resourceId: string;
|
|
281
|
+
plugName: string;
|
|
282
|
+
ref: string;
|
|
283
|
+
}) => Promise<Record<string, unknown> | null>;
|
|
284
|
+
upsert: (mapping: {
|
|
285
|
+
resourceId: string;
|
|
286
|
+
connectValue: string | string[];
|
|
287
|
+
refs: Record<string, string>;
|
|
288
|
+
metadata?: Record<string, unknown> | null;
|
|
289
|
+
}) => Promise<Record<string, unknown>>;
|
|
290
|
+
update: (id: string, mapping: {
|
|
291
|
+
resourceId: string;
|
|
292
|
+
connectValue: string | string[];
|
|
293
|
+
refs: Record<string, string>;
|
|
294
|
+
metadata?: Record<string, unknown> | null;
|
|
295
|
+
}) => Promise<Record<string, unknown>>;
|
|
296
|
+
delete: (id: string) => Promise<void>;
|
|
297
|
+
};
|
|
181
298
|
interface VarField {
|
|
182
299
|
readonly key: string;
|
|
183
300
|
label: string;
|
|
@@ -289,11 +406,30 @@ interface KhotanAdapter {
|
|
|
289
406
|
}>;
|
|
290
407
|
upsertResource(resource: {
|
|
291
408
|
name: string;
|
|
292
|
-
connectField:
|
|
409
|
+
connectField: ResourceConnectField;
|
|
293
410
|
description?: string | null;
|
|
294
411
|
}): Promise<{
|
|
295
412
|
id: string;
|
|
296
413
|
}>;
|
|
414
|
+
upsertCache(cache: {
|
|
415
|
+
name: string;
|
|
416
|
+
scope?: CacheScope | null;
|
|
417
|
+
ttlSeconds?: number | null;
|
|
418
|
+
}): Promise<{
|
|
419
|
+
id: string;
|
|
420
|
+
}>;
|
|
421
|
+
getCacheByName(name: string): Promise<Record<string, unknown> | null>;
|
|
422
|
+
getCacheEntry(cacheId: string, key: string): Promise<Record<string, unknown> | null>;
|
|
423
|
+
upsertCacheEntry(entry: {
|
|
424
|
+
cacheId: string;
|
|
425
|
+
key: string;
|
|
426
|
+
value: unknown;
|
|
427
|
+
expiresAt?: Date | null;
|
|
428
|
+
}): Promise<{
|
|
429
|
+
id: string;
|
|
430
|
+
created: boolean;
|
|
431
|
+
}>;
|
|
432
|
+
deleteCacheEntry(cacheId: string, key: string): Promise<void>;
|
|
297
433
|
listResources(): Promise<Record<string, unknown>[]>;
|
|
298
434
|
getResource(id: string): Promise<Record<string, unknown> | null>;
|
|
299
435
|
getResourceFlows(resourceId: string): Promise<Record<string, unknown>[]>;
|
|
@@ -308,9 +444,21 @@ interface KhotanAdapter {
|
|
|
308
444
|
created: boolean;
|
|
309
445
|
}>;
|
|
310
446
|
getMapping(id: string): Promise<Record<string, unknown> | null>;
|
|
311
|
-
listMappings(
|
|
447
|
+
listMappings(params: {
|
|
448
|
+
resourceId: string;
|
|
449
|
+
limit: number;
|
|
450
|
+
offset: number;
|
|
451
|
+
search?: string;
|
|
452
|
+
}): Promise<{
|
|
453
|
+
items: Record<string, unknown>[];
|
|
454
|
+
hasMore: boolean;
|
|
455
|
+
total: number;
|
|
456
|
+
}>;
|
|
312
457
|
deleteMapping(id: string): Promise<void>;
|
|
313
458
|
lookupMapping(params: {
|
|
459
|
+
resourceId: string;
|
|
460
|
+
connectValue: string;
|
|
461
|
+
} | {
|
|
314
462
|
resourceId: string;
|
|
315
463
|
plugName: string;
|
|
316
464
|
ref: string;
|
|
@@ -407,6 +555,7 @@ interface KhotanConfig {
|
|
|
407
555
|
adapter: KhotanAdapter;
|
|
408
556
|
plugs: PlugRegistration[];
|
|
409
557
|
resources?: ResourceRegistration[];
|
|
558
|
+
caches?: CacheRegistration[];
|
|
410
559
|
secret?: string;
|
|
411
560
|
}
|
|
412
561
|
type KhotanHandler = (request: Request) => Promise<Response>;
|
|
@@ -430,6 +579,44 @@ interface KhotanInstance {
|
|
|
430
579
|
init(): Promise<void>;
|
|
431
580
|
flow(flowNameOrId: string, options?: FlowSelectorOptions): FlowInstance;
|
|
432
581
|
wire(plugName: string): WireInstance;
|
|
582
|
+
cache(cacheName: string): CacheInstance;
|
|
583
|
+
listMappings(params: {
|
|
584
|
+
resourceId: string;
|
|
585
|
+
limit?: number;
|
|
586
|
+
offset?: number;
|
|
587
|
+
search?: string;
|
|
588
|
+
}): Promise<{
|
|
589
|
+
items: Record<string, unknown>[];
|
|
590
|
+
page: {
|
|
591
|
+
limit: number;
|
|
592
|
+
offset: number;
|
|
593
|
+
hasMore: boolean;
|
|
594
|
+
prevOffset: number;
|
|
595
|
+
nextOffset: number;
|
|
596
|
+
total: number;
|
|
597
|
+
};
|
|
598
|
+
}>;
|
|
599
|
+
lookupMapping(params: {
|
|
600
|
+
resourceId: string;
|
|
601
|
+
connectValue: string | string[];
|
|
602
|
+
} | {
|
|
603
|
+
resourceId: string;
|
|
604
|
+
plugName: string;
|
|
605
|
+
ref: string;
|
|
606
|
+
}): Promise<Record<string, unknown> | null>;
|
|
607
|
+
upsertMapping(mapping: {
|
|
608
|
+
resourceId: string;
|
|
609
|
+
connectValue: string | string[];
|
|
610
|
+
refs: Record<string, string>;
|
|
611
|
+
metadata?: Record<string, unknown> | null;
|
|
612
|
+
}): Promise<Record<string, unknown>>;
|
|
613
|
+
updateMapping(id: string, mapping: {
|
|
614
|
+
resourceId: string;
|
|
615
|
+
connectValue: string | string[];
|
|
616
|
+
refs: Record<string, string>;
|
|
617
|
+
metadata?: Record<string, unknown> | null;
|
|
618
|
+
}): Promise<Record<string, unknown>>;
|
|
619
|
+
deleteMapping(id: string): Promise<void>;
|
|
433
620
|
getVars(plugName: string): Promise<Record<string, string>>;
|
|
434
621
|
setVars(plugName: string, vars: Record<string, string>): Promise<void>;
|
|
435
622
|
clearVars(plugName: string): Promise<void>;
|
|
@@ -472,4 +659,4 @@ interface NextJsRouteHandlers {
|
|
|
472
659
|
}
|
|
473
660
|
declare function toNextJsHandler(factoryHandler: KhotanHandler): NextJsRouteHandlers;
|
|
474
661
|
|
|
475
|
-
export { type CatchRegistration, type FlowInstance, type FlowRegistration, type FlowRunContext, type FlowRunResult, type FlowSelectorOptions, type FlowStartOptions, type FlowType, type FlowWorkflowContext, type KhotanAdapter, type KhotanConfig, type KhotanHandler, type KhotanInstance, type KhotanRunStatus, type KhotanRunUpdate, type KhotanTerminalRunStatus, type PassRegistration, type PlugRegistration, type ResourceRegistration, type VarField, type WebhookRegistration, type WireInstance, type WireRegistration, type WireSubscribeContext, type WireUnsubscribeContext, type WireVerifyContext, __setWorkflowGetRunForTests, __setWorkflowGetWritableForTests, __setWorkflowStartForTests, drizzleAdapter, khotan, sendUpdate, toNextJsHandler };
|
|
662
|
+
export { type BindablePlug, type BoundPlug, type CacheEntryRecord, type CacheInstance, type CacheRegistration, type CacheScope, type CatchRegistration, type CatchWorkflowContext, type FlowInstance, type FlowRegistration, type FlowRunContext, type FlowRunResult, type FlowSelectorOptions, type FlowStartOptions, type FlowType, type FlowWorkflowContext, type KhotanAdapter, type KhotanConfig, type KhotanHandler, type KhotanInstance, type KhotanRunStatus, type KhotanRunUpdate, type KhotanTerminalRunStatus, type PassRegistration, type PassWorkflowContext, type PlugRegistration, type ResourceConnectField, type ResourceMappingRegistration, type ResourcePlugParticipation, type ResourceRegistration, type VarField, type WebhookRegistration, type WireInstance, type WireRegistration, type WireSubscribeContext, type WireUnsubscribeContext, type WireVerifyContext, __setWorkflowGetRunForTests, __setWorkflowGetWritableForTests, __setWorkflowStartForTests, bindWorkflowPlug, drizzleAdapter, khotan, khotanCache, khotanMappings, sendUpdate, toNextJsHandler };
|