@xlr-lib/xlr-sdk 0.1.1-next.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/dist/cjs/index.cjs +992 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +961 -0
- package/dist/index.mjs +961 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -0
- package/src/__tests__/__snapshots__/sdk.test.ts.snap +3167 -0
- package/src/__tests__/sdk.test.ts +392 -0
- package/src/__tests__/utils.test.ts +0 -0
- package/src/index.ts +4 -0
- package/src/registry/basic-registry.ts +82 -0
- package/src/registry/index.ts +2 -0
- package/src/registry/types.ts +28 -0
- package/src/sdk.ts +458 -0
- package/src/types.ts +48 -0
- package/src/utils.ts +191 -0
- package/src/validator.ts +542 -0
- package/types/index.d.ts +5 -0
- package/types/registry/basic-registry.d.ts +18 -0
- package/types/registry/index.d.ts +3 -0
- package/types/registry/types.d.ts +23 -0
- package/types/sdk.d.ts +111 -0
- package/types/types.d.ts +32 -0
- package/types/utils.d.ts +13 -0
- package/types/validator.d.ts +27 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { test, expect, describe } from "vitest";
|
|
2
|
+
import type { NamedType, TransformFunction, OrType } from "@xlr-lib/xlr";
|
|
3
|
+
import { parseTree } from "jsonc-parser";
|
|
4
|
+
import { Types, ReferenceAssetsWebPluginManifest } from "@xlr-lib/static-xlrs";
|
|
5
|
+
import type { Filters } from "../registry";
|
|
6
|
+
import { XLRSDK } from "../sdk";
|
|
7
|
+
import { XLRValidator } from "../validator";
|
|
8
|
+
import { ValidationMessage } from "../types";
|
|
9
|
+
|
|
10
|
+
const EXCLUDE: Filters = { typeFilter: "Transformed" };
|
|
11
|
+
|
|
12
|
+
describe("Loading XLRs", () => {
|
|
13
|
+
test("Loading from Disk", () => {
|
|
14
|
+
const sdk = new XLRSDK();
|
|
15
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
16
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
17
|
+
|
|
18
|
+
expect(sdk.hasType("Asset")).toStrictEqual(true);
|
|
19
|
+
expect(sdk.hasType("AssetWrapper")).toStrictEqual(true);
|
|
20
|
+
expect(sdk.hasType("Binding")).toStrictEqual(true);
|
|
21
|
+
expect(sdk.hasType("BindingRef")).toStrictEqual(true);
|
|
22
|
+
expect(sdk.hasType("ExpressionRef")).toStrictEqual(true);
|
|
23
|
+
expect(sdk.hasType("ActionAsset")).toStrictEqual(true);
|
|
24
|
+
expect(sdk.hasType("InputAsset")).toStrictEqual(true);
|
|
25
|
+
expect(sdk.hasType("TransformedAction")).toStrictEqual(false);
|
|
26
|
+
expect(sdk.hasType("TransformedInput")).toStrictEqual(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("Loading from Module", async () => {
|
|
30
|
+
const sdk = new XLRSDK();
|
|
31
|
+
await sdk.loadDefinitionsFromModule(
|
|
32
|
+
ReferenceAssetsWebPluginManifest,
|
|
33
|
+
EXCLUDE,
|
|
34
|
+
);
|
|
35
|
+
await sdk.loadDefinitionsFromModule(Types);
|
|
36
|
+
|
|
37
|
+
expect(sdk.hasType("Asset")).toStrictEqual(true);
|
|
38
|
+
expect(sdk.hasType("AssetWrapper")).toStrictEqual(true);
|
|
39
|
+
expect(sdk.hasType("Binding")).toStrictEqual(true);
|
|
40
|
+
expect(sdk.hasType("BindingRef")).toStrictEqual(true);
|
|
41
|
+
expect(sdk.hasType("ExpressionRef")).toStrictEqual(true);
|
|
42
|
+
expect(sdk.hasType("ActionAsset")).toStrictEqual(true);
|
|
43
|
+
expect(sdk.hasType("InputAsset")).toStrictEqual(true);
|
|
44
|
+
expect(sdk.hasType("TransformedAction")).toStrictEqual(false);
|
|
45
|
+
expect(sdk.hasType("TransformedInput")).toStrictEqual(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("Object Recall", () => {
|
|
50
|
+
test("Raw", () => {
|
|
51
|
+
const sdk = new XLRSDK();
|
|
52
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
53
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
54
|
+
|
|
55
|
+
expect(sdk.getType("InputAsset", { getRawType: true })).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("Processed", () => {
|
|
59
|
+
const sdk = new XLRSDK();
|
|
60
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
61
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
62
|
+
|
|
63
|
+
expect(sdk.getType("InputAsset", { optimize: false })).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("Optimized", () => {
|
|
67
|
+
const sdk = new XLRSDK();
|
|
68
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
69
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
70
|
+
|
|
71
|
+
expect(sdk.getType("InputAsset")).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("Validation", () => {
|
|
76
|
+
test("Basic Validation By Name", () => {
|
|
77
|
+
const mockAsset = parseTree(`
|
|
78
|
+
{
|
|
79
|
+
"id": 1,
|
|
80
|
+
"type": "input",
|
|
81
|
+
"binding": "some.data",
|
|
82
|
+
"label": {
|
|
83
|
+
"asset": {
|
|
84
|
+
"value": "{{input.label}}"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
88
|
+
|
|
89
|
+
const sdk = new XLRSDK();
|
|
90
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
91
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
92
|
+
|
|
93
|
+
expect(sdk.validateByName("InputAsset", mockAsset)).toMatchSnapshot();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("Basic Validation By Type (unoptimized)", () => {
|
|
97
|
+
const mockAsset = parseTree(`
|
|
98
|
+
{
|
|
99
|
+
"id": 1,
|
|
100
|
+
"type": "input",
|
|
101
|
+
"binding": "some.data",
|
|
102
|
+
"label": {
|
|
103
|
+
"asset": {
|
|
104
|
+
"value": "{{input.label}}"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`);
|
|
108
|
+
|
|
109
|
+
const sdk = new XLRSDK();
|
|
110
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
111
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
112
|
+
|
|
113
|
+
const inputAsset = sdk.getType("InputAsset", { optimize: false });
|
|
114
|
+
expect(inputAsset).toBeDefined();
|
|
115
|
+
expect(
|
|
116
|
+
sdk.validateByType(inputAsset as NamedType, mockAsset),
|
|
117
|
+
).toMatchSnapshot();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("Basic Validation By Type (optimized)", () => {
|
|
121
|
+
const mockAsset = parseTree(`
|
|
122
|
+
{
|
|
123
|
+
"id": 1,
|
|
124
|
+
"type": "input",
|
|
125
|
+
"binding": "some.data",
|
|
126
|
+
"label": {
|
|
127
|
+
"asset": {
|
|
128
|
+
"value": "{{input.label}}"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`);
|
|
132
|
+
|
|
133
|
+
const sdk = new XLRSDK();
|
|
134
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
135
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
136
|
+
|
|
137
|
+
const inputAsset = sdk.getType("InputAsset");
|
|
138
|
+
expect(inputAsset).toBeDefined();
|
|
139
|
+
expect(
|
|
140
|
+
sdk.validateByType(inputAsset as NamedType, mockAsset),
|
|
141
|
+
).toMatchSnapshot();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("Export Test", () => {
|
|
146
|
+
test("Exports Typescript types", () => {
|
|
147
|
+
const importMap = new Map([
|
|
148
|
+
[
|
|
149
|
+
"@player-ui/types",
|
|
150
|
+
["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
|
|
151
|
+
],
|
|
152
|
+
]);
|
|
153
|
+
|
|
154
|
+
const sdk = new XLRSDK();
|
|
155
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
156
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
157
|
+
const results = sdk.exportRegistry("TypeScript", importMap);
|
|
158
|
+
expect(results[0][0]).toBe("out.d.ts");
|
|
159
|
+
expect(results[0][1]).toMatchSnapshot();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("Exports Typescript Types With Filters", () => {
|
|
163
|
+
const importMap = new Map([
|
|
164
|
+
[
|
|
165
|
+
"@player-ui/types",
|
|
166
|
+
["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
|
|
167
|
+
],
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
const sdk = new XLRSDK();
|
|
171
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
172
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
173
|
+
const results = sdk.exportRegistry("TypeScript", importMap, {
|
|
174
|
+
typeFilter: "Transformed",
|
|
175
|
+
pluginFilter: "Types",
|
|
176
|
+
});
|
|
177
|
+
expect(results[0][0]).toBe("out.d.ts");
|
|
178
|
+
expect(results[0][1]).toMatchSnapshot();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("Exports Typescript Types With Transforms", () => {
|
|
182
|
+
const importMap = new Map([
|
|
183
|
+
[
|
|
184
|
+
"@player-ui/types",
|
|
185
|
+
["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
|
|
186
|
+
],
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
*/
|
|
192
|
+
const transformFunction: TransformFunction = (input, capability) => {
|
|
193
|
+
if (capability === "Assets") {
|
|
194
|
+
const ret = { ...input };
|
|
195
|
+
if (ret.type === "object") {
|
|
196
|
+
ret.properties.transformed = {
|
|
197
|
+
required: false,
|
|
198
|
+
node: { type: "boolean", const: true },
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return ret;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return input;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const sdk = new XLRSDK();
|
|
209
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
210
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
211
|
+
const results = sdk.exportRegistry(
|
|
212
|
+
"TypeScript",
|
|
213
|
+
importMap,
|
|
214
|
+
{
|
|
215
|
+
pluginFilter: "Types",
|
|
216
|
+
},
|
|
217
|
+
[transformFunction],
|
|
218
|
+
);
|
|
219
|
+
expect(results[0][0]).toBe("out.d.ts");
|
|
220
|
+
expect(results[0][1]).toMatchSnapshot();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("Or Type Validation", () => {
|
|
225
|
+
test("Outputs helpful type error messages", () => {
|
|
226
|
+
const mockAsset = parseTree(`
|
|
227
|
+
{
|
|
228
|
+
"type": "string",
|
|
229
|
+
"value": "orange"
|
|
230
|
+
}`);
|
|
231
|
+
|
|
232
|
+
const orType: OrType = {
|
|
233
|
+
type: "or",
|
|
234
|
+
or: [
|
|
235
|
+
{ type: "string", const: "apple" },
|
|
236
|
+
{ type: "string", const: "banana" },
|
|
237
|
+
{ type: "string", const: "carrot" },
|
|
238
|
+
{ type: "string", const: "deli-meat" },
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const sdk = new XLRSDK();
|
|
243
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
244
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
245
|
+
|
|
246
|
+
const validator = new XLRValidator(sdk.getType);
|
|
247
|
+
let validationResult: ValidationMessage[];
|
|
248
|
+
|
|
249
|
+
if (mockAsset.children && mockAsset.children.length > 0) {
|
|
250
|
+
validationResult = validator.validateType(mockAsset.children[0], orType);
|
|
251
|
+
} else {
|
|
252
|
+
validationResult = [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Expected error and info messages
|
|
256
|
+
expect(validationResult).toHaveLength(2);
|
|
257
|
+
expect(validationResult[0].message).toBe(
|
|
258
|
+
"Does not match any of the types: string | string | string | string",
|
|
259
|
+
);
|
|
260
|
+
expect(validationResult[1].message).toBe(
|
|
261
|
+
"Expected: apple | banana | carrot | deli-meat",
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("Uses primitive type names over titles", () => {
|
|
266
|
+
const sdk = new XLRSDK();
|
|
267
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
268
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
269
|
+
const validator = new XLRValidator(sdk.getType.bind(sdk));
|
|
270
|
+
|
|
271
|
+
const orType: OrType = {
|
|
272
|
+
type: "or",
|
|
273
|
+
or: [{ type: "string", title: "TextAsset.value" }, { type: "boolean" }],
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const rootNode = parseTree(`1`);
|
|
277
|
+
if (!rootNode) {
|
|
278
|
+
throw new Error("Expected root node to be parsed");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const validationResult = validator.validateType(rootNode, orType);
|
|
282
|
+
|
|
283
|
+
expect(validationResult[0].message).toBe(
|
|
284
|
+
"Does not match any of the types: string | boolean",
|
|
285
|
+
);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe("generateNestedTypesInfo Test", () => {
|
|
290
|
+
test("Test with potentialTypeErrors", () => {
|
|
291
|
+
const sdk = new XLRSDK();
|
|
292
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
293
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
294
|
+
const validator = new XLRValidator(sdk.getType);
|
|
295
|
+
|
|
296
|
+
const potentialTypeErrors = [
|
|
297
|
+
{
|
|
298
|
+
type: { type: "string" },
|
|
299
|
+
errors: [
|
|
300
|
+
{
|
|
301
|
+
type: "type",
|
|
302
|
+
node: {} as any,
|
|
303
|
+
message: "Expected string",
|
|
304
|
+
severity: 1,
|
|
305
|
+
expected: "string",
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
const xlrNode = {
|
|
312
|
+
type: "or",
|
|
313
|
+
or: [{ type: "string" }, { type: "number" }],
|
|
314
|
+
} as OrType;
|
|
315
|
+
|
|
316
|
+
const rootNode = {
|
|
317
|
+
type: "boolean",
|
|
318
|
+
value: true,
|
|
319
|
+
} as any;
|
|
320
|
+
|
|
321
|
+
const result = (validator as any).generateNestedTypesInfo(
|
|
322
|
+
potentialTypeErrors,
|
|
323
|
+
xlrNode,
|
|
324
|
+
rootNode,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
expect(result.nestedTypesList).toBe("string");
|
|
328
|
+
expect(result.infoMessage).toBe("Got: true and expected: string");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("Works with urlMapping", () => {
|
|
332
|
+
const sdk = new XLRSDK();
|
|
333
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
334
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
335
|
+
const validator = new XLRValidator(sdk.getType, {
|
|
336
|
+
urlMapping: {
|
|
337
|
+
MyType: "https://example.com/mytype",
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const potentialTypeErrors: any[] = [];
|
|
342
|
+
|
|
343
|
+
const xlrNode = {
|
|
344
|
+
type: "or",
|
|
345
|
+
name: "MyType",
|
|
346
|
+
or: [{ type: "string" }, { type: "number" }],
|
|
347
|
+
} as OrType;
|
|
348
|
+
|
|
349
|
+
const rootNode = {
|
|
350
|
+
type: "boolean",
|
|
351
|
+
value: true,
|
|
352
|
+
} as any;
|
|
353
|
+
|
|
354
|
+
const result = (validator as any).generateNestedTypesInfo(
|
|
355
|
+
potentialTypeErrors,
|
|
356
|
+
xlrNode,
|
|
357
|
+
rootNode,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
expect(result.nestedTypesList).toBe("https://example.com/mytype");
|
|
361
|
+
expect(result.infoMessage).toBe(
|
|
362
|
+
"Got: true and expected: https://example.com/mytype",
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test("Without rootNode value", () => {
|
|
367
|
+
const sdk = new XLRSDK();
|
|
368
|
+
sdk.loadDefinitionsFromModule(Types);
|
|
369
|
+
sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
|
|
370
|
+
const validator = new XLRValidator(sdk.getType);
|
|
371
|
+
|
|
372
|
+
const potentialTypeErrors: any[] = [];
|
|
373
|
+
|
|
374
|
+
const xlrNode = {
|
|
375
|
+
type: "or",
|
|
376
|
+
or: [{ type: "string" }, { type: "number" }],
|
|
377
|
+
} as OrType;
|
|
378
|
+
|
|
379
|
+
const rootNode = {
|
|
380
|
+
type: "boolean",
|
|
381
|
+
} as any;
|
|
382
|
+
|
|
383
|
+
const result = (validator as any).generateNestedTypesInfo(
|
|
384
|
+
potentialTypeErrors,
|
|
385
|
+
xlrNode,
|
|
386
|
+
rootNode,
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
expect(result.nestedTypesList).toBe("string | number");
|
|
390
|
+
expect(result.infoMessage).toBe("Expected: string | number");
|
|
391
|
+
});
|
|
392
|
+
});
|
|
File without changes
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { NamedType, NodeType } from "@xlr-lib/xlr";
|
|
2
|
+
import type { XLRRegistry, Filters, TypeMetadata } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Basic example of a XLRs Registry
|
|
6
|
+
*/
|
|
7
|
+
export class BasicXLRRegistry implements XLRRegistry {
|
|
8
|
+
private typeMap: Map<string, NamedType<NodeType>>;
|
|
9
|
+
private pluginMap: Map<string, Map<string, Array<string>>>;
|
|
10
|
+
private infoMap: Map<string, TypeMetadata>;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.typeMap = new Map();
|
|
14
|
+
this.pluginMap = new Map();
|
|
15
|
+
this.infoMap = new Map();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Returns a copy of the XLR to guard against unexpected type modification */
|
|
19
|
+
get(id: string): NamedType<NodeType> | undefined {
|
|
20
|
+
const value = this.typeMap.get(id);
|
|
21
|
+
return value ? JSON.parse(JSON.stringify(value)) : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
add(type: NamedType<NodeType>, plugin: string, capability: string): void {
|
|
25
|
+
this.typeMap.set(type.name, type);
|
|
26
|
+
this.infoMap.set(type.name, { plugin, capability });
|
|
27
|
+
|
|
28
|
+
if (!this.pluginMap.has(plugin)) {
|
|
29
|
+
this.pluginMap.set(plugin, new Map());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const pluginsCapabilities = this.pluginMap.get(plugin) as Map<
|
|
33
|
+
string,
|
|
34
|
+
Array<string>
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
if (!pluginsCapabilities.has(capability)) {
|
|
38
|
+
pluginsCapabilities.set(capability, []);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const providedCapabilities = pluginsCapabilities.get(
|
|
42
|
+
capability,
|
|
43
|
+
) as string[];
|
|
44
|
+
providedCapabilities.push(type.name);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
has(id: string): boolean {
|
|
48
|
+
return this.typeMap.has(id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
list(filterArgs?: Filters): NamedType<NodeType>[] {
|
|
52
|
+
const validTypes: Array<string> = [];
|
|
53
|
+
|
|
54
|
+
this.pluginMap.forEach((manifest, pluginName) => {
|
|
55
|
+
if (
|
|
56
|
+
!filterArgs?.pluginFilter ||
|
|
57
|
+
!pluginName.match(filterArgs.pluginFilter)
|
|
58
|
+
) {
|
|
59
|
+
manifest.forEach((types, capabilityName) => {
|
|
60
|
+
if (
|
|
61
|
+
!filterArgs?.capabilityFilter ||
|
|
62
|
+
!capabilityName.match(filterArgs.capabilityFilter)
|
|
63
|
+
) {
|
|
64
|
+
types.forEach((type) => {
|
|
65
|
+
if (
|
|
66
|
+
!filterArgs?.typeFilter ||
|
|
67
|
+
!type.match(filterArgs.typeFilter)
|
|
68
|
+
) {
|
|
69
|
+
validTypes.push(type);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return validTypes.map((type) => this.get(type) as NamedType);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
info(id: string): TypeMetadata | undefined {
|
|
80
|
+
return this.infoMap.get(id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { NamedType } from "@xlr-lib/xlr";
|
|
2
|
+
|
|
3
|
+
export interface Filters {
|
|
4
|
+
/** filter based on plugin name */
|
|
5
|
+
pluginFilter?: string | RegExp;
|
|
6
|
+
|
|
7
|
+
/** filter based on capability name */
|
|
8
|
+
capabilityFilter?: string | RegExp;
|
|
9
|
+
|
|
10
|
+
/** filter based on type name */
|
|
11
|
+
typeFilter?: string | RegExp;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TypeMetadata {
|
|
15
|
+
/** The Plugin the Type comes from */
|
|
16
|
+
plugin: string;
|
|
17
|
+
|
|
18
|
+
/** The Capability of the Type */
|
|
19
|
+
capability: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface XLRRegistry {
|
|
23
|
+
get(id: string): NamedType | undefined;
|
|
24
|
+
add(type: NamedType, from: string, capability: string): void;
|
|
25
|
+
has(id: string): boolean;
|
|
26
|
+
list(filterArgs?: Filters): Array<NamedType>;
|
|
27
|
+
info(id: string): TypeMetadata | undefined;
|
|
28
|
+
}
|