-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathField.ts
More file actions
69 lines (64 loc) · 1.51 KB
/
Field.ts
File metadata and controls
69 lines (64 loc) · 1.51 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
import type { Resource } from "./Resource.js";
import type { Nullable } from "./types.js";
export type FieldType =
| "string"
| "integer"
| "negativeInteger"
| "nonNegativeInteger"
| "positiveInteger"
| "nonPositiveInteger"
| "number"
| "decimal"
| "double"
| "float"
| "boolean"
| "date"
| "dateTime"
| "duration"
| "time"
| "byte"
| "binary"
| "hexBinary"
| "base64Binary"
| "array"
| "object"
| "email"
| "url"
| "uuid"
| "password"
// oxlint-disable-next-line ban-types
| ({} & string); // Allow any other string type
export interface FieldOptions
extends Nullable<{
id?: string;
range?: string;
type?: FieldType;
arrayType?: FieldType;
enum?: { [key: string | number]: string | number };
reference?: string | Resource;
embedded?: Resource;
nullable?: boolean;
required?: boolean;
description?: string;
maxCardinality?: number;
deprecated?: boolean;
}> {}
export class Field implements FieldOptions {
name: string;
id?: string | null;
range?: string | null;
type?: FieldType | null;
arrayType?: FieldType | null;
enum?: { [key: string | number]: string | number } | null;
reference?: string | Resource | null;
embedded?: Resource | null;
nullable?: boolean | null;
required?: boolean | null;
description?: string | null;
maxCardinality?: number | null;
deprecated?: boolean | null;
constructor(name: string, options: FieldOptions = {}) {
this.name = name;
Object.assign(this, options);
}
}