forked from chaiNNer-org/chaiNNer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon-types.ts
More file actions
520 lines (477 loc) · 15.3 KB
/
common-types.ts
File metadata and controls
520 lines (477 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
import { ExpressionJson } from './types/json';
export interface JsonObject {
[key: string]: JsonValue;
}
export type JsonValue = null | string | number | boolean | JsonObject | JsonValue[];
export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export interface Size {
width: number;
height: number;
}
export type SchemaId = string & { readonly __schemaId: never };
export type InputId = number & { readonly __inputId: never };
export type OutputId = number & { readonly __outputId: never };
export type GroupId = number & { readonly __groupId: never };
export type PackageId = string & { readonly __packageId: never };
export type FeatureId = string & { readonly __featureId: never };
export type PyPiName = string & { readonly __pyPiName: never };
export type InputValue = InputSchemaValue | undefined;
export type InputSchemaValue = string | number;
export interface InputConversionSchema {
readonly type: ExpressionJson;
readonly convert: ExpressionJson;
}
export interface IOFusion {
readonly outputId: OutputId;
}
interface InputBase {
readonly id: InputId;
readonly type: ExpressionJson;
/**
* A list of input conversions. Before checking for compatibility, the type
* system will attempt to convert any assigned type using input conversions.
*
* This can be used to implement e.g. number rounding or type wrapping for
* edges.
*/
readonly conversions: InputConversionSchema[];
/**
* Optional type conversion for adapting input data.
*
* The frontend stores input data as numbers and strings, but inputs may
* use different types. This optional conversion allows inputs to convert
* input data to compatible types. E.g. the directory input wraps its path.
*/
readonly adapt?: ExpressionJson | null;
readonly typeDefinitions?: string | null;
readonly kind: InputKind;
readonly label: string;
readonly optional: boolean;
readonly hasHandle: boolean;
readonly description?: string;
readonly hint: boolean;
readonly fused?: IOFusion | null;
readonly suggest: boolean;
}
export interface InputOption {
readonly option: string;
readonly value: InputSchemaValue;
readonly icon?: string | null;
readonly type?: ExpressionJson;
readonly condition?: Condition | null;
}
export type FileInputKind = 'image' | 'pth' | 'pt' | 'video' | 'bin' | 'param' | 'onnx';
export type DropDownStyle = 'dropdown' | 'checkbox' | 'tabs' | 'icons';
export interface DropdownGroup {
readonly label?: string | null;
readonly startAt: InputSchemaValue;
}
export type LabelStyle = 'default' | 'inline' | 'hidden';
export interface GenericInput extends InputBase {
readonly kind: 'generic';
}
export interface DropDownInput extends InputBase {
readonly kind: 'dropdown';
readonly def: string | number;
readonly options: readonly InputOption[];
readonly preferredStyle: DropDownStyle;
readonly labelStyle: LabelStyle;
readonly groups: readonly DropdownGroup[];
}
export interface FileInput extends InputBase {
readonly kind: 'file';
readonly fileKind: FileInputKind;
readonly filetypes: readonly string[];
readonly primaryInput: boolean;
}
export interface DirectoryInput extends InputBase {
readonly kind: 'directory';
readonly labelStyle: LabelStyle;
}
export interface TextInput extends InputBase {
readonly kind: 'text';
readonly multiline?: boolean;
readonly minLength?: number | null;
readonly maxLength?: number | null;
readonly placeholder?: string | null;
readonly def?: string | null;
readonly allowEmptyString?: boolean;
readonly invalidPattern?: string | null;
readonly labelStyle: LabelStyle | undefined;
}
export interface NumberInput extends InputBase {
readonly kind: 'number';
readonly def: number;
readonly min?: number | null;
readonly max?: number | null;
readonly precision: number;
readonly controlsStep: number;
readonly unit?: string | null;
readonly noteExpression?: string | null;
readonly hideTrailingZeros: boolean;
readonly labelStyle: LabelStyle;
}
export interface SliderInput extends InputBase {
readonly kind: 'slider';
readonly def: number;
readonly min: number;
readonly max: number;
readonly precision: number;
readonly controlsStep: number;
readonly unit?: string | null;
readonly noteExpression?: string | null;
readonly hideTrailingZeros: boolean;
readonly ends: readonly [string | null, string | null];
readonly sliderStep: number;
readonly gradient?: readonly string[] | null;
readonly scale: 'linear' | 'log' | 'log-offset' | 'sqrt';
}
export interface ColorInput extends InputBase {
readonly kind: 'color';
readonly def: string;
readonly channels?: readonly number[] | null;
}
export interface StaticValueInput extends InputBase {
readonly kind: 'static';
readonly value: 'execution_number';
}
export type InputKind = Input['kind'];
export type Input =
| GenericInput
| FileInput
| DirectoryInput
| TextInput
| DropDownInput
| SliderInput
| NumberInput
| ColorInput
| StaticValueInput;
export type OutputKind = 'image' | 'large-image' | 'tagged' | 'generic';
export interface Output {
readonly id: OutputId;
readonly type: ExpressionJson;
/**
* A likely reason as to why the (generic) type expression might evaluate to `never`.
*/
readonly neverReason?: string | null;
readonly label: string;
readonly kind: OutputKind;
readonly hasHandle: boolean;
readonly passthroughOf?: InputId | null;
readonly description?: string | null;
readonly suggest: boolean;
}
export type Condition = AndCondition | OrCondition | NotCondition | EnumCondition | TypeCondition;
export interface AndCondition {
readonly kind: 'and';
readonly items: readonly Condition[];
}
export interface OrCondition {
readonly kind: 'or';
readonly items: readonly Condition[];
}
export interface NotCondition {
readonly kind: 'not';
readonly condition: Condition;
}
export interface EnumCondition {
readonly kind: 'enum';
readonly enum: InputId;
readonly values: readonly InputSchemaValue[];
}
export interface TypeCondition {
readonly kind: 'type';
readonly input: InputId;
readonly condition: ExpressionJson;
readonly ifNotConnected: boolean;
}
interface GroupBase {
readonly id: GroupId;
readonly kind: GroupKind;
readonly options: Readonly<Record<string, unknown>>;
readonly items: readonly (InputId | Group)[];
}
interface NcnnFileInputGroup extends GroupBase {
readonly kind: 'ncnn-file-inputs';
readonly options: Readonly<Record<string, never>>;
}
interface FromToDropdownsGroup extends GroupBase {
readonly kind: 'from-to-dropdowns';
readonly options: Readonly<Record<string, never>>;
}
interface OptionalListGroup extends GroupBase {
readonly kind: 'optional-list';
readonly options: Readonly<Record<string, never>>;
}
interface OptionalListGroup extends GroupBase {
readonly kind: 'optional-list';
readonly options: Readonly<Record<string, never>>;
}
interface ConditionalGroup extends GroupBase {
readonly kind: 'conditional';
readonly options: {
readonly condition: Condition;
};
}
interface RequiredGroup extends GroupBase {
readonly kind: 'required';
readonly options: {
readonly condition: Condition;
};
}
interface SeedGroup extends GroupBase {
readonly kind: 'seed';
readonly options: Readonly<Record<string, never>>;
}
interface LinkedInputsGroup extends GroupBase {
readonly kind: 'linked-inputs';
readonly options: Readonly<Record<string, never>>;
}
interface IconSetGroup extends GroupBase {
readonly kind: 'icon-set';
readonly options: {
readonly label: string;
};
}
interface MenuIconRowGroup extends GroupBase {
readonly kind: 'menu-icon-row';
readonly options: Readonly<Record<string, never>>;
}
export type GroupKind = Group['kind'];
export type Group =
| NcnnFileInputGroup
| FromToDropdownsGroup
| OptionalListGroup
| ConditionalGroup
| RequiredGroup
| SeedGroup
| LinkedInputsGroup
| IconSetGroup
| MenuIconRowGroup;
export type OfKind<T extends { readonly kind: string }, Kind extends T['kind']> = T extends {
readonly kind: Kind;
}
? T
: never;
export type NodeKind = 'regularNode' | 'newIterator' | 'collector';
export type InputData = Readonly<Record<InputId, InputValue>>;
export type InputHeight = Readonly<Record<InputId, number>>;
export type OutputData = Readonly<Record<OutputId, unknown>>;
export type OutputHeight = Readonly<Record<OutputId, number>>;
export type OutputTypes = Readonly<Partial<Record<OutputId, ExpressionJson | null>>>;
export interface IteratorInputInfo {
readonly inputs: readonly InputId[];
readonly lengthType: ExpressionJson;
}
export interface IteratorOutputInfo {
readonly outputs: readonly OutputId[];
readonly lengthType: ExpressionJson;
}
export type KeyInfo = EnumKeyInfo | NumberKeyInfo | TypeKeyInfo;
export interface EnumKeyInfo {
readonly kind: 'enum';
readonly inputId: InputId;
}
export interface NumberKeyInfo {
readonly kind: 'number';
readonly inputId: InputId;
}
export interface TypeKeyInfo {
readonly kind: 'type';
readonly expression: ExpressionJson;
}
export interface SpecialSuggestion {
readonly query: string;
readonly name?: string | null;
readonly parseInput?: InputId | null;
readonly inputs: Partial<InputData>;
}
export interface NodeSchema {
readonly name: string;
readonly category: CategoryId;
readonly nodeGroup: NodeGroupId;
readonly description: string;
readonly seeAlso: readonly SchemaId[];
readonly icon: string;
readonly kind: NodeKind;
readonly inputs: readonly Input[];
readonly outputs: readonly Output[];
readonly groupLayout: readonly (InputId | Group)[];
readonly iteratorInputs: readonly IteratorInputInfo[];
readonly iteratorOutputs: readonly IteratorOutputInfo[];
readonly keyInfo?: KeyInfo | null;
readonly suggestions: readonly SpecialSuggestion[];
readonly schemaId: SchemaId;
readonly hasSideEffects: boolean;
readonly deprecated: boolean;
readonly features: readonly FeatureId[];
}
export interface DefaultNode {
// Default nodes aren't currently used
__SPECIAL: never;
schemaId: SchemaId;
}
export interface NodeData {
readonly id: string;
readonly schemaId: SchemaId;
readonly isDisabled?: boolean;
readonly isLocked?: boolean;
readonly inputData: InputData;
readonly inputHeight?: InputHeight;
readonly outputHeight?: OutputHeight;
readonly nodeWidth?: number;
readonly isCollapsed?: boolean;
readonly isPassthrough?: boolean;
readonly nodeName?: string;
}
export interface EdgeData {
sourceX?: number;
sourceY?: number;
targetX?: number;
targetY?: number;
}
export interface PyPiPackage {
readonly displayName: string;
readonly pypiName: PyPiName;
readonly version: Version;
readonly findLink?: string | null;
/**
* A size estimate (in bytes) for the whl file to download.
*/
readonly sizeEstimate: number;
readonly autoUpdate: boolean;
}
export interface Feature {
readonly id: FeatureId;
readonly name: string;
readonly description: string;
}
export type SettingKey = string & { readonly __settingKey: never };
export type SettingValue = string | number | boolean;
interface SettingBase {
readonly type: Setting['type'];
readonly key: SettingKey;
readonly label: string;
readonly description: string;
readonly default: SettingValue;
readonly disabled?: boolean;
}
export interface ToggleSetting extends SettingBase {
readonly type: 'toggle';
readonly default: boolean;
}
export interface NumberSetting extends SettingBase {
readonly type: 'number';
readonly min: number;
readonly max: number;
readonly default: number;
}
export interface DropdownSetting extends SettingBase {
readonly type: 'dropdown';
readonly options: readonly { readonly label: string; readonly value: string }[];
readonly default: string;
readonly small?: boolean;
}
export interface CacheSetting extends SettingBase {
readonly type: 'cache';
readonly default: string;
readonly directory: string;
}
export type Setting = ToggleSetting | NumberSetting | DropdownSetting | CacheSetting;
export interface Package {
readonly id: PackageId;
readonly name: string;
readonly icon: string;
readonly color: string;
readonly description: string;
readonly dependencies: readonly PyPiPackage[];
readonly features: readonly Feature[];
readonly settings: readonly Setting[];
}
export interface FeatureState {
readonly packageId: PackageId;
readonly featureId: FeatureId;
readonly enabled: boolean;
readonly details?: string | null;
}
/**
* A valid semantic version or a string that can be coerced into one.
*/
export type Version =
| `${number}.${number}.${number}`
| `${number}.${number}.${number}${'+' | '-'}${string}`
| (string & { readonly __coerceableVersionString: undefined });
export interface PythonInfo {
readonly python: string;
readonly version: Version;
}
export type FileSaveResult = FileSaveSuccess | FileSaveCanceled;
export type FileSaveCanceled = { kind: 'Canceled' };
export type FileSaveSuccess = { kind: 'Success'; path: string };
export type FileOpenResult<T> = FileOpenSuccess<T> | FileOpenError;
export interface FileOpenSuccess<T> {
kind: 'Success';
path: string;
saveData: T;
}
export interface FileOpenError {
kind: 'Error';
path: string;
error: string;
}
export interface BackendJsonEdgeInput {
type: 'edge';
id: string;
index: number;
}
export interface BackendJsonValueInput {
type: 'value';
value: InputValue | null;
}
export type BackendJsonInput = BackendJsonEdgeInput | BackendJsonValueInput;
export interface BackendJsonNode {
id: string;
schemaId: SchemaId;
inputs: BackendJsonInput[];
nodeType: string;
}
export interface WindowSize {
readonly maximized: boolean;
readonly width: number;
readonly height: number;
}
export type CategoryId = string & { readonly __categoryId: never };
export interface Category {
readonly id: CategoryId;
readonly name: string;
readonly description: string;
readonly icon: string;
readonly color: string;
readonly installHint?: string;
readonly groups: readonly NodeGroup[];
}
export type NodeGroupId = string & { readonly __nodeGroupId: never };
export interface NodeGroup {
readonly id: NodeGroupId;
readonly category: CategoryId;
readonly name: string;
readonly order: readonly SchemaId[];
}
export type ColorJson = GrayscaleColorJson | RgbColorJson | RgbaColorJson;
export type ColorKind = ColorJson['kind'];
export interface GrayscaleColorJson {
readonly kind: 'grayscale';
readonly values: readonly [luma: number];
}
export interface RgbColorJson {
readonly kind: 'rgb';
readonly values: readonly [r: number, g: number, b: number];
}
export interface RgbaColorJson {
readonly kind: 'rgba';
readonly values: readonly [r: number, g: number, b: number, a: number];
}
export interface PackageSettings {
[packageName: string]: Partial<Record<string, SettingValue>> | undefined;
}