@fedify/vocab-tools 2.0.0-pr.458.1785
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/LICENSE +20 -0
- package/README.md +26 -0
- package/deno.json +28 -0
- package/dist/mod.cjs +1941 -0
- package/dist/mod.d.cts +190 -0
- package/dist/mod.d.ts +190 -0
- package/dist/mod.js +1916 -0
- package/package.json +49 -0
- package/src/__snapshots__/class.test.ts.deno.snap +81555 -0
- package/src/__snapshots__/class.test.ts.node.snap +81553 -0
- package/src/__snapshots__/class.test.ts.snap +81555 -0
- package/src/class.test.ts +122 -0
- package/src/class.ts +140 -0
- package/src/codec.ts +485 -0
- package/src/constructor.ts +337 -0
- package/src/field.ts +46 -0
- package/src/fs.test.ts +31 -0
- package/src/fs.ts +21 -0
- package/src/generate.ts +24 -0
- package/src/inspector.ts +96 -0
- package/src/mod.ts +7 -0
- package/src/property.ts +397 -0
- package/src/schema.test.ts +203 -0
- package/src/schema.ts +321 -0
- package/src/schema.yaml +247 -0
- package/src/type.ts +643 -0
- package/tsdown.config.ts +9 -0
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
//#region src/generate.d.ts
|
|
2
|
+
declare function generateVocab(schemaDir: string, generatedPath: string): Promise<void>;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The qualified URI of a type. It is used as the range of a property.
|
|
7
|
+
*/
|
|
8
|
+
type TypeUri = `https://${string}` | `http://${string}` | `fedify:${string}`;
|
|
9
|
+
/**
|
|
10
|
+
* The schema of a type. It is used to generate a class.
|
|
11
|
+
*/
|
|
12
|
+
interface TypeSchema {
|
|
13
|
+
/**
|
|
14
|
+
* The type name. It is used as the name of the generated class.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The qualified URI of the type.
|
|
19
|
+
*/
|
|
20
|
+
uri: TypeUri;
|
|
21
|
+
/**
|
|
22
|
+
* The qualified URIs of the base type of the type (if any).
|
|
23
|
+
*/
|
|
24
|
+
extends?: TypeUri;
|
|
25
|
+
/**
|
|
26
|
+
* The type name used in the compacted JSON-LD document. It is used as the
|
|
27
|
+
* value of the `type` field.
|
|
28
|
+
*/
|
|
29
|
+
compactName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Marks the type an entity type rather than a value type. Turning on this
|
|
32
|
+
* flag will make property accessors for the type asynchronous, so that they
|
|
33
|
+
* can load the values of the properties from the remote server.
|
|
34
|
+
*
|
|
35
|
+
* The extended subtypes must have the consistent value of this flag.
|
|
36
|
+
*/
|
|
37
|
+
entity: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The description of the type. It is used as the doc comment of
|
|
40
|
+
* the generated class.
|
|
41
|
+
*/
|
|
42
|
+
description: string;
|
|
43
|
+
/**
|
|
44
|
+
* The possible properties of the type.
|
|
45
|
+
*/
|
|
46
|
+
properties: PropertySchema[];
|
|
47
|
+
/**
|
|
48
|
+
* The default JSON-LD context of the type. It is used as the default
|
|
49
|
+
* context of the generated `toJsonLd()` method.
|
|
50
|
+
*/
|
|
51
|
+
defaultContext: Context;
|
|
52
|
+
}
|
|
53
|
+
interface PropertySchemaBase {
|
|
54
|
+
/**
|
|
55
|
+
* The singular form of the property name. It is used as the name of the
|
|
56
|
+
* generated property accessors.
|
|
57
|
+
*/
|
|
58
|
+
singularName: string;
|
|
59
|
+
/**
|
|
60
|
+
* The qualified URI of the property.
|
|
61
|
+
*/
|
|
62
|
+
uri: string;
|
|
63
|
+
/**
|
|
64
|
+
* The property name used in the compacted JSON-LD document. It is used as
|
|
65
|
+
* the key of the property.
|
|
66
|
+
*/
|
|
67
|
+
compactName?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The qualified URI of the superproperty of the property (if any).
|
|
70
|
+
* It means that the property is a specialization of the referenced property.
|
|
71
|
+
*/
|
|
72
|
+
subpropertyOf?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The description of the property. It is used as the doc comment of
|
|
75
|
+
* the generated property accessors.
|
|
76
|
+
*/
|
|
77
|
+
description: string;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the enclosed object should have its own context when the document
|
|
80
|
+
* is compacted.
|
|
81
|
+
*/
|
|
82
|
+
embedContext?: {
|
|
83
|
+
/**
|
|
84
|
+
* The compact name of the property that contains the context.
|
|
85
|
+
*/
|
|
86
|
+
compactName: string;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the embedded context should be the same as the context of
|
|
89
|
+
* the enclosing document.
|
|
90
|
+
*/
|
|
91
|
+
inherit: true;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
type PropertySchemaTyping = {
|
|
95
|
+
/**
|
|
96
|
+
* Whether the property value has `@type` field. If `true`, the `range` must
|
|
97
|
+
* have only one element.
|
|
98
|
+
*/
|
|
99
|
+
untyped?: false;
|
|
100
|
+
/**
|
|
101
|
+
* The qualified URIs of all possible types of the property values.
|
|
102
|
+
*/
|
|
103
|
+
range: [TypeUri] | [TypeUri, ...TypeUri[]];
|
|
104
|
+
} | {
|
|
105
|
+
/**
|
|
106
|
+
* Whether the property value has `@type` field. If `true`, the `range` must
|
|
107
|
+
* have only one element.
|
|
108
|
+
*/
|
|
109
|
+
untyped: true;
|
|
110
|
+
/**
|
|
111
|
+
* The qualified URIs of all possible types of the property values.
|
|
112
|
+
*/
|
|
113
|
+
range: [TypeUri];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The schema of a property. It is used to generate property accessors of
|
|
117
|
+
* a class.
|
|
118
|
+
*/
|
|
119
|
+
type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
120
|
+
/**
|
|
121
|
+
* Marks the property that it can have only one value. Turning on this
|
|
122
|
+
* flag will generate only singular property accessors, so `pluralName`
|
|
123
|
+
* and `singularAccessor` should not be specified.
|
|
124
|
+
*/
|
|
125
|
+
functional?: false;
|
|
126
|
+
/**
|
|
127
|
+
* The plural form of the property name. It is used as the name of the
|
|
128
|
+
* generated property accessors.
|
|
129
|
+
*/
|
|
130
|
+
pluralName: string;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to generate singular property accessors. Regardless of this
|
|
133
|
+
* flag, plural property accessors are generated (unless `functional` is
|
|
134
|
+
* turned on).
|
|
135
|
+
*/
|
|
136
|
+
singularAccessor?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* The container type of the property values. It can be unspecified.
|
|
139
|
+
*/
|
|
140
|
+
container?: "graph" | "list";
|
|
141
|
+
} | PropertySchemaBase & PropertySchemaTyping & {
|
|
142
|
+
/**
|
|
143
|
+
* Marks the property that it can have only one value. Turning on this
|
|
144
|
+
* flag will generate only singular property accessors, so `pluralName`
|
|
145
|
+
* and `singularAccessor` should not be specified.
|
|
146
|
+
*/
|
|
147
|
+
functional: true;
|
|
148
|
+
/**
|
|
149
|
+
* If it's present, those redundant properties are also filled with
|
|
150
|
+
* the same value altogether when the object is serialized into
|
|
151
|
+
* JSON-LD. When it's deserialized from JSON-LD, it tries to
|
|
152
|
+
* parse the values of the specified properties in order.
|
|
153
|
+
*/
|
|
154
|
+
redundantProperties?: {
|
|
155
|
+
/**
|
|
156
|
+
* The qualified URI of the property.
|
|
157
|
+
*/
|
|
158
|
+
uri: string;
|
|
159
|
+
/**
|
|
160
|
+
* The property name used in the compacted JSON-LD document. It is used
|
|
161
|
+
* as the key of the property.
|
|
162
|
+
*/
|
|
163
|
+
compactName?: string;
|
|
164
|
+
}[];
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* A JSON-LD context, which is placed in the `@context` property of a JSON-LD
|
|
168
|
+
* document.
|
|
169
|
+
*/
|
|
170
|
+
type Context = Uri | EmbeddedContext | (Uri | EmbeddedContext)[];
|
|
171
|
+
type Uri = "http://{string}" | "https://{string}";
|
|
172
|
+
type EmbeddedContext = Record<string, TermDefinition>;
|
|
173
|
+
type TermDefinition = Uri | Record<string, Uri | "@id">;
|
|
174
|
+
/**
|
|
175
|
+
* Type guard to check if a property is not functional (has pluralName).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Loads all schema files in the directory.
|
|
180
|
+
* @param dir The path of the directory to load schema files from.
|
|
181
|
+
* @returns A map from the qualified URI of a type to its {@link SchemaFile}.
|
|
182
|
+
* @throws {@link AggregateError} if any schema file is invalid. It contains
|
|
183
|
+
* all {@link SchemaError}s of the invalid schema files.
|
|
184
|
+
*/
|
|
185
|
+
declare function loadSchemaFiles(dir: string): Promise<Record<string, TypeSchema>>;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/type.d.ts
|
|
188
|
+
declare function areAllScalarTypes(typeUris: string[], types: Record<string, TypeSchema>): boolean;
|
|
189
|
+
//#endregion
|
|
190
|
+
export { PropertySchema, TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
//#region src/generate.d.ts
|
|
2
|
+
declare function generateVocab(schemaDir: string, generatedPath: string): Promise<void>;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The qualified URI of a type. It is used as the range of a property.
|
|
7
|
+
*/
|
|
8
|
+
type TypeUri = `https://${string}` | `http://${string}` | `fedify:${string}`;
|
|
9
|
+
/**
|
|
10
|
+
* The schema of a type. It is used to generate a class.
|
|
11
|
+
*/
|
|
12
|
+
interface TypeSchema {
|
|
13
|
+
/**
|
|
14
|
+
* The type name. It is used as the name of the generated class.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The qualified URI of the type.
|
|
19
|
+
*/
|
|
20
|
+
uri: TypeUri;
|
|
21
|
+
/**
|
|
22
|
+
* The qualified URIs of the base type of the type (if any).
|
|
23
|
+
*/
|
|
24
|
+
extends?: TypeUri;
|
|
25
|
+
/**
|
|
26
|
+
* The type name used in the compacted JSON-LD document. It is used as the
|
|
27
|
+
* value of the `type` field.
|
|
28
|
+
*/
|
|
29
|
+
compactName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Marks the type an entity type rather than a value type. Turning on this
|
|
32
|
+
* flag will make property accessors for the type asynchronous, so that they
|
|
33
|
+
* can load the values of the properties from the remote server.
|
|
34
|
+
*
|
|
35
|
+
* The extended subtypes must have the consistent value of this flag.
|
|
36
|
+
*/
|
|
37
|
+
entity: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The description of the type. It is used as the doc comment of
|
|
40
|
+
* the generated class.
|
|
41
|
+
*/
|
|
42
|
+
description: string;
|
|
43
|
+
/**
|
|
44
|
+
* The possible properties of the type.
|
|
45
|
+
*/
|
|
46
|
+
properties: PropertySchema[];
|
|
47
|
+
/**
|
|
48
|
+
* The default JSON-LD context of the type. It is used as the default
|
|
49
|
+
* context of the generated `toJsonLd()` method.
|
|
50
|
+
*/
|
|
51
|
+
defaultContext: Context;
|
|
52
|
+
}
|
|
53
|
+
interface PropertySchemaBase {
|
|
54
|
+
/**
|
|
55
|
+
* The singular form of the property name. It is used as the name of the
|
|
56
|
+
* generated property accessors.
|
|
57
|
+
*/
|
|
58
|
+
singularName: string;
|
|
59
|
+
/**
|
|
60
|
+
* The qualified URI of the property.
|
|
61
|
+
*/
|
|
62
|
+
uri: string;
|
|
63
|
+
/**
|
|
64
|
+
* The property name used in the compacted JSON-LD document. It is used as
|
|
65
|
+
* the key of the property.
|
|
66
|
+
*/
|
|
67
|
+
compactName?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The qualified URI of the superproperty of the property (if any).
|
|
70
|
+
* It means that the property is a specialization of the referenced property.
|
|
71
|
+
*/
|
|
72
|
+
subpropertyOf?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The description of the property. It is used as the doc comment of
|
|
75
|
+
* the generated property accessors.
|
|
76
|
+
*/
|
|
77
|
+
description: string;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the enclosed object should have its own context when the document
|
|
80
|
+
* is compacted.
|
|
81
|
+
*/
|
|
82
|
+
embedContext?: {
|
|
83
|
+
/**
|
|
84
|
+
* The compact name of the property that contains the context.
|
|
85
|
+
*/
|
|
86
|
+
compactName: string;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the embedded context should be the same as the context of
|
|
89
|
+
* the enclosing document.
|
|
90
|
+
*/
|
|
91
|
+
inherit: true;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
type PropertySchemaTyping = {
|
|
95
|
+
/**
|
|
96
|
+
* Whether the property value has `@type` field. If `true`, the `range` must
|
|
97
|
+
* have only one element.
|
|
98
|
+
*/
|
|
99
|
+
untyped?: false;
|
|
100
|
+
/**
|
|
101
|
+
* The qualified URIs of all possible types of the property values.
|
|
102
|
+
*/
|
|
103
|
+
range: [TypeUri] | [TypeUri, ...TypeUri[]];
|
|
104
|
+
} | {
|
|
105
|
+
/**
|
|
106
|
+
* Whether the property value has `@type` field. If `true`, the `range` must
|
|
107
|
+
* have only one element.
|
|
108
|
+
*/
|
|
109
|
+
untyped: true;
|
|
110
|
+
/**
|
|
111
|
+
* The qualified URIs of all possible types of the property values.
|
|
112
|
+
*/
|
|
113
|
+
range: [TypeUri];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The schema of a property. It is used to generate property accessors of
|
|
117
|
+
* a class.
|
|
118
|
+
*/
|
|
119
|
+
type PropertySchema = PropertySchemaBase & PropertySchemaTyping & {
|
|
120
|
+
/**
|
|
121
|
+
* Marks the property that it can have only one value. Turning on this
|
|
122
|
+
* flag will generate only singular property accessors, so `pluralName`
|
|
123
|
+
* and `singularAccessor` should not be specified.
|
|
124
|
+
*/
|
|
125
|
+
functional?: false;
|
|
126
|
+
/**
|
|
127
|
+
* The plural form of the property name. It is used as the name of the
|
|
128
|
+
* generated property accessors.
|
|
129
|
+
*/
|
|
130
|
+
pluralName: string;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to generate singular property accessors. Regardless of this
|
|
133
|
+
* flag, plural property accessors are generated (unless `functional` is
|
|
134
|
+
* turned on).
|
|
135
|
+
*/
|
|
136
|
+
singularAccessor?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* The container type of the property values. It can be unspecified.
|
|
139
|
+
*/
|
|
140
|
+
container?: "graph" | "list";
|
|
141
|
+
} | PropertySchemaBase & PropertySchemaTyping & {
|
|
142
|
+
/**
|
|
143
|
+
* Marks the property that it can have only one value. Turning on this
|
|
144
|
+
* flag will generate only singular property accessors, so `pluralName`
|
|
145
|
+
* and `singularAccessor` should not be specified.
|
|
146
|
+
*/
|
|
147
|
+
functional: true;
|
|
148
|
+
/**
|
|
149
|
+
* If it's present, those redundant properties are also filled with
|
|
150
|
+
* the same value altogether when the object is serialized into
|
|
151
|
+
* JSON-LD. When it's deserialized from JSON-LD, it tries to
|
|
152
|
+
* parse the values of the specified properties in order.
|
|
153
|
+
*/
|
|
154
|
+
redundantProperties?: {
|
|
155
|
+
/**
|
|
156
|
+
* The qualified URI of the property.
|
|
157
|
+
*/
|
|
158
|
+
uri: string;
|
|
159
|
+
/**
|
|
160
|
+
* The property name used in the compacted JSON-LD document. It is used
|
|
161
|
+
* as the key of the property.
|
|
162
|
+
*/
|
|
163
|
+
compactName?: string;
|
|
164
|
+
}[];
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* A JSON-LD context, which is placed in the `@context` property of a JSON-LD
|
|
168
|
+
* document.
|
|
169
|
+
*/
|
|
170
|
+
type Context = Uri | EmbeddedContext | (Uri | EmbeddedContext)[];
|
|
171
|
+
type Uri = "http://{string}" | "https://{string}";
|
|
172
|
+
type EmbeddedContext = Record<string, TermDefinition>;
|
|
173
|
+
type TermDefinition = Uri | Record<string, Uri | "@id">;
|
|
174
|
+
/**
|
|
175
|
+
* Type guard to check if a property is not functional (has pluralName).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Loads all schema files in the directory.
|
|
180
|
+
* @param dir The path of the directory to load schema files from.
|
|
181
|
+
* @returns A map from the qualified URI of a type to its {@link SchemaFile}.
|
|
182
|
+
* @throws {@link AggregateError} if any schema file is invalid. It contains
|
|
183
|
+
* all {@link SchemaError}s of the invalid schema files.
|
|
184
|
+
*/
|
|
185
|
+
declare function loadSchemaFiles(dir: string): Promise<Record<string, TypeSchema>>;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/type.d.ts
|
|
188
|
+
declare function areAllScalarTypes(typeUris: string[], types: Record<string, TypeSchema>): boolean;
|
|
189
|
+
//#endregion
|
|
190
|
+
export { PropertySchema, TypeSchema, areAllScalarTypes, generateVocab, loadSchemaFiles };
|