@player-lang/json-language-service 0.0.2-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 +2314 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +2249 -0
- package/dist/index.mjs +2249 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +40 -0
- package/src/__tests__/__snapshots__/service.test.ts.snap +213 -0
- package/src/__tests__/service.test.ts +298 -0
- package/src/constants.ts +38 -0
- package/src/index.ts +490 -0
- package/src/parser/__tests__/parse.test.ts +18 -0
- package/src/parser/document.ts +456 -0
- package/src/parser/edits.ts +31 -0
- package/src/parser/index.ts +38 -0
- package/src/parser/jsonParseErrors.ts +69 -0
- package/src/parser/types.ts +314 -0
- package/src/parser/utils.ts +94 -0
- package/src/plugins/__tests__/asset-wrapper-array-plugin.test.ts +112 -0
- package/src/plugins/__tests__/binding-schema-plugin.test.ts +62 -0
- package/src/plugins/__tests__/duplicate-id-plugin.test.ts +195 -0
- package/src/plugins/__tests__/missing-asset-wrapper-plugin.test.ts +190 -0
- package/src/plugins/__tests__/nav-state-plugin.test.ts +136 -0
- package/src/plugins/__tests__/view-node-plugin.test.ts +154 -0
- package/src/plugins/asset-wrapper-array-plugin.ts +123 -0
- package/src/plugins/binding-schema-plugin.ts +289 -0
- package/src/plugins/duplicate-id-plugin.ts +158 -0
- package/src/plugins/missing-asset-wrapper-plugin.ts +96 -0
- package/src/plugins/nav-state-plugin.ts +139 -0
- package/src/plugins/view-node-plugin.ts +225 -0
- package/src/plugins/xlr-plugin.ts +371 -0
- package/src/types.ts +119 -0
- package/src/utils.ts +143 -0
- package/src/xlr/__tests__/__snapshots__/transform.test.ts.snap +390 -0
- package/src/xlr/__tests__/transform.test.ts +108 -0
- package/src/xlr/index.ts +3 -0
- package/src/xlr/registry.ts +99 -0
- package/src/xlr/service.ts +190 -0
- package/src/xlr/transforms.ts +169 -0
- package/types/constants.d.ts +7 -0
- package/types/index.d.ts +69 -0
- package/types/parser/document.d.ts +25 -0
- package/types/parser/edits.d.ts +10 -0
- package/types/parser/index.d.ts +16 -0
- package/types/parser/jsonParseErrors.d.ts +27 -0
- package/types/parser/types.d.ts +188 -0
- package/types/parser/utils.d.ts +26 -0
- package/types/plugins/asset-wrapper-array-plugin.d.ts +9 -0
- package/types/plugins/binding-schema-plugin.d.ts +15 -0
- package/types/plugins/duplicate-id-plugin.d.ts +7 -0
- package/types/plugins/missing-asset-wrapper-plugin.d.ts +9 -0
- package/types/plugins/nav-state-plugin.d.ts +9 -0
- package/types/plugins/view-node-plugin.d.ts +9 -0
- package/types/plugins/xlr-plugin.d.ts +7 -0
- package/types/types.d.ts +81 -0
- package/types/utils.d.ts +24 -0
- package/types/xlr/index.d.ts +4 -0
- package/types/xlr/registry.d.ts +17 -0
- package/types/xlr/service.d.ts +22 -0
- package/types/xlr/transforms.d.ts +18 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Transform Tests > AssetWrapperOrSwitch Transform 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"additionalProperties": {
|
|
6
|
+
"type": "unknown",
|
|
7
|
+
},
|
|
8
|
+
"description": "Mock Asset for test",
|
|
9
|
+
"extends": undefined,
|
|
10
|
+
"genericTokens": [
|
|
11
|
+
{
|
|
12
|
+
"constraints": {
|
|
13
|
+
"ref": "Asset",
|
|
14
|
+
"type": "ref",
|
|
15
|
+
},
|
|
16
|
+
"default": {
|
|
17
|
+
"ref": "Asset",
|
|
18
|
+
"type": "ref",
|
|
19
|
+
},
|
|
20
|
+
"symbol": "AnyAsset",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
"name": "MockAsset",
|
|
24
|
+
"properties": {
|
|
25
|
+
"id": {
|
|
26
|
+
"node": {
|
|
27
|
+
"description": "Each asset requires a unique id per view",
|
|
28
|
+
"title": "Asset.id",
|
|
29
|
+
"type": "string",
|
|
30
|
+
},
|
|
31
|
+
"required": true,
|
|
32
|
+
},
|
|
33
|
+
"primaryChild": {
|
|
34
|
+
"node": {
|
|
35
|
+
"description": "A text-like asset for the action's label",
|
|
36
|
+
"genericArguments": [
|
|
37
|
+
{
|
|
38
|
+
"ref": "AnyAsset",
|
|
39
|
+
"type": "ref",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
"ref": "AssetWrapperOrSwitch<AnyAsset>",
|
|
43
|
+
"title": "ActionAsset.label",
|
|
44
|
+
"type": "ref",
|
|
45
|
+
},
|
|
46
|
+
"required": true,
|
|
47
|
+
},
|
|
48
|
+
"secondaryChildren": {
|
|
49
|
+
"node": {
|
|
50
|
+
"elementType": {
|
|
51
|
+
"ref": "Asset",
|
|
52
|
+
"type": "ref",
|
|
53
|
+
},
|
|
54
|
+
"type": "array",
|
|
55
|
+
},
|
|
56
|
+
"required": false,
|
|
57
|
+
},
|
|
58
|
+
"type": {
|
|
59
|
+
"node": {
|
|
60
|
+
"const": "mock",
|
|
61
|
+
"description": "The asset type determines the semantics of how a user interacts with a page",
|
|
62
|
+
"title": "Asset.type",
|
|
63
|
+
"type": "string",
|
|
64
|
+
},
|
|
65
|
+
"required": true,
|
|
66
|
+
},
|
|
67
|
+
"value": {
|
|
68
|
+
"node": {
|
|
69
|
+
"description": "The transition value of the action in the state machine",
|
|
70
|
+
"title": "MockAsset.value",
|
|
71
|
+
"type": "string",
|
|
72
|
+
},
|
|
73
|
+
"required": false,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
"source": "transform.test.ts",
|
|
77
|
+
"title": "MockAsset",
|
|
78
|
+
"type": "object",
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
exports[`Transform Tests > CommonProps Transform 1`] = `
|
|
83
|
+
{
|
|
84
|
+
"additionalProperties": {
|
|
85
|
+
"type": "unknown",
|
|
86
|
+
},
|
|
87
|
+
"description": "Mock Asset for test",
|
|
88
|
+
"extends": undefined,
|
|
89
|
+
"genericTokens": [
|
|
90
|
+
{
|
|
91
|
+
"constraints": {
|
|
92
|
+
"ref": "Asset",
|
|
93
|
+
"type": "ref",
|
|
94
|
+
},
|
|
95
|
+
"default": {
|
|
96
|
+
"ref": "Asset",
|
|
97
|
+
"type": "ref",
|
|
98
|
+
},
|
|
99
|
+
"symbol": "AnyAsset",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
"name": "MockAsset",
|
|
103
|
+
"properties": {
|
|
104
|
+
"_comment": {
|
|
105
|
+
"node": {
|
|
106
|
+
"description": "Adds a comment for the given node",
|
|
107
|
+
"type": "string",
|
|
108
|
+
},
|
|
109
|
+
"required": false,
|
|
110
|
+
},
|
|
111
|
+
"applicability": {
|
|
112
|
+
"node": {
|
|
113
|
+
"description": "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
|
|
114
|
+
"name": "Applicability",
|
|
115
|
+
"or": [
|
|
116
|
+
{
|
|
117
|
+
"type": "boolean",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"ref": "Expression",
|
|
121
|
+
"type": "ref",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
"type": "or",
|
|
125
|
+
},
|
|
126
|
+
"required": false,
|
|
127
|
+
},
|
|
128
|
+
"id": {
|
|
129
|
+
"node": {
|
|
130
|
+
"description": "Each asset requires a unique id per view",
|
|
131
|
+
"title": "Asset.id",
|
|
132
|
+
"type": "string",
|
|
133
|
+
},
|
|
134
|
+
"required": true,
|
|
135
|
+
},
|
|
136
|
+
"primaryChild": {
|
|
137
|
+
"node": {
|
|
138
|
+
"description": "A text-like asset for the action's label",
|
|
139
|
+
"genericArguments": [
|
|
140
|
+
{
|
|
141
|
+
"ref": "AnyAsset",
|
|
142
|
+
"type": "ref",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
"ref": "AssetWrapper<AnyAsset>",
|
|
146
|
+
"title": "ActionAsset.label",
|
|
147
|
+
"type": "ref",
|
|
148
|
+
},
|
|
149
|
+
"required": true,
|
|
150
|
+
},
|
|
151
|
+
"secondaryChildren": {
|
|
152
|
+
"node": {
|
|
153
|
+
"elementType": {
|
|
154
|
+
"ref": "Asset",
|
|
155
|
+
"type": "ref",
|
|
156
|
+
},
|
|
157
|
+
"type": "array",
|
|
158
|
+
},
|
|
159
|
+
"required": false,
|
|
160
|
+
},
|
|
161
|
+
"type": {
|
|
162
|
+
"node": {
|
|
163
|
+
"const": "mock",
|
|
164
|
+
"description": "The asset type determines the semantics of how a user interacts with a page",
|
|
165
|
+
"title": "Asset.type",
|
|
166
|
+
"type": "string",
|
|
167
|
+
},
|
|
168
|
+
"required": true,
|
|
169
|
+
},
|
|
170
|
+
"value": {
|
|
171
|
+
"node": {
|
|
172
|
+
"description": "The transition value of the action in the state machine",
|
|
173
|
+
"title": "MockAsset.value",
|
|
174
|
+
"type": "string",
|
|
175
|
+
},
|
|
176
|
+
"required": false,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
"source": "transform.test.ts",
|
|
180
|
+
"title": "MockAsset",
|
|
181
|
+
"type": "object",
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
exports[`Transform Tests > applyTemplateProperty Transform 1`] = `
|
|
186
|
+
{
|
|
187
|
+
"additionalProperties": {
|
|
188
|
+
"type": "unknown",
|
|
189
|
+
},
|
|
190
|
+
"description": "Mock Asset for test",
|
|
191
|
+
"extends": undefined,
|
|
192
|
+
"genericTokens": [
|
|
193
|
+
{
|
|
194
|
+
"constraints": {
|
|
195
|
+
"ref": "Asset",
|
|
196
|
+
"type": "ref",
|
|
197
|
+
},
|
|
198
|
+
"default": {
|
|
199
|
+
"ref": "Asset",
|
|
200
|
+
"type": "ref",
|
|
201
|
+
},
|
|
202
|
+
"symbol": "AnyAsset",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
"name": "MockAsset",
|
|
206
|
+
"properties": {
|
|
207
|
+
"id": {
|
|
208
|
+
"node": {
|
|
209
|
+
"description": "Each asset requires a unique id per view",
|
|
210
|
+
"title": "Asset.id",
|
|
211
|
+
"type": "string",
|
|
212
|
+
},
|
|
213
|
+
"required": true,
|
|
214
|
+
},
|
|
215
|
+
"primaryChild": {
|
|
216
|
+
"node": {
|
|
217
|
+
"description": "A text-like asset for the action's label",
|
|
218
|
+
"genericArguments": [
|
|
219
|
+
{
|
|
220
|
+
"ref": "AnyAsset",
|
|
221
|
+
"type": "ref",
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
"ref": "AssetWrapper<AnyAsset>",
|
|
225
|
+
"title": "ActionAsset.label",
|
|
226
|
+
"type": "ref",
|
|
227
|
+
},
|
|
228
|
+
"required": true,
|
|
229
|
+
},
|
|
230
|
+
"secondaryChildren": {
|
|
231
|
+
"node": {
|
|
232
|
+
"elementType": {
|
|
233
|
+
"ref": "Asset",
|
|
234
|
+
"type": "ref",
|
|
235
|
+
},
|
|
236
|
+
"type": "array",
|
|
237
|
+
},
|
|
238
|
+
"required": false,
|
|
239
|
+
},
|
|
240
|
+
"template": {
|
|
241
|
+
"node": {
|
|
242
|
+
"description": "A list of templates to process for this node",
|
|
243
|
+
"elementType": {
|
|
244
|
+
"genericArguments": [
|
|
245
|
+
{
|
|
246
|
+
"ref": "Asset",
|
|
247
|
+
"type": "ref",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"const": "secondaryChildren",
|
|
251
|
+
"type": "string",
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
"ref": "Template<Asset, "secondaryChildren">",
|
|
255
|
+
"type": "ref",
|
|
256
|
+
},
|
|
257
|
+
"type": "array",
|
|
258
|
+
},
|
|
259
|
+
"required": false,
|
|
260
|
+
},
|
|
261
|
+
"type": {
|
|
262
|
+
"node": {
|
|
263
|
+
"const": "mock",
|
|
264
|
+
"description": "The asset type determines the semantics of how a user interacts with a page",
|
|
265
|
+
"title": "Asset.type",
|
|
266
|
+
"type": "string",
|
|
267
|
+
},
|
|
268
|
+
"required": true,
|
|
269
|
+
},
|
|
270
|
+
"value": {
|
|
271
|
+
"node": {
|
|
272
|
+
"description": "The transition value of the action in the state machine",
|
|
273
|
+
"title": "MockAsset.value",
|
|
274
|
+
"type": "string",
|
|
275
|
+
},
|
|
276
|
+
"required": false,
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
"source": "transform.test.ts",
|
|
280
|
+
"title": "MockAsset",
|
|
281
|
+
"type": "object",
|
|
282
|
+
}
|
|
283
|
+
`;
|
|
284
|
+
|
|
285
|
+
exports[`Transform Tests > applyValueRefs Transform 1`] = `
|
|
286
|
+
{
|
|
287
|
+
"additionalProperties": {
|
|
288
|
+
"type": "unknown",
|
|
289
|
+
},
|
|
290
|
+
"description": "Mock Asset for test",
|
|
291
|
+
"extends": undefined,
|
|
292
|
+
"genericTokens": [
|
|
293
|
+
{
|
|
294
|
+
"constraints": {
|
|
295
|
+
"ref": "Asset",
|
|
296
|
+
"type": "ref",
|
|
297
|
+
},
|
|
298
|
+
"default": {
|
|
299
|
+
"ref": "Asset",
|
|
300
|
+
"type": "ref",
|
|
301
|
+
},
|
|
302
|
+
"symbol": "AnyAsset",
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
"name": "MockAsset",
|
|
306
|
+
"properties": {
|
|
307
|
+
"id": {
|
|
308
|
+
"node": {
|
|
309
|
+
"description": "Each asset requires a unique id per view",
|
|
310
|
+
"title": "Asset.id",
|
|
311
|
+
"type": "string",
|
|
312
|
+
},
|
|
313
|
+
"required": true,
|
|
314
|
+
},
|
|
315
|
+
"primaryChild": {
|
|
316
|
+
"node": {
|
|
317
|
+
"description": "A text-like asset for the action's label",
|
|
318
|
+
"genericArguments": [
|
|
319
|
+
{
|
|
320
|
+
"ref": "AnyAsset",
|
|
321
|
+
"type": "ref",
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
"ref": "AssetWrapper<AnyAsset>",
|
|
325
|
+
"title": "ActionAsset.label",
|
|
326
|
+
"type": "ref",
|
|
327
|
+
},
|
|
328
|
+
"required": true,
|
|
329
|
+
},
|
|
330
|
+
"secondaryChildren": {
|
|
331
|
+
"node": {
|
|
332
|
+
"elementType": {
|
|
333
|
+
"ref": "Asset",
|
|
334
|
+
"type": "ref",
|
|
335
|
+
},
|
|
336
|
+
"type": "array",
|
|
337
|
+
},
|
|
338
|
+
"required": false,
|
|
339
|
+
},
|
|
340
|
+
"type": {
|
|
341
|
+
"node": {
|
|
342
|
+
"description": "The asset type determines the semantics of how a user interacts with a page",
|
|
343
|
+
"or": [
|
|
344
|
+
{
|
|
345
|
+
"const": "mock",
|
|
346
|
+
"description": "The asset type determines the semantics of how a user interacts with a page",
|
|
347
|
+
"title": "Asset.type",
|
|
348
|
+
"type": "string",
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"ref": "ExpressionRef",
|
|
352
|
+
"type": "ref",
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
"ref": "BindingRef",
|
|
356
|
+
"type": "ref",
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
"type": "or",
|
|
360
|
+
},
|
|
361
|
+
"required": true,
|
|
362
|
+
},
|
|
363
|
+
"value": {
|
|
364
|
+
"node": {
|
|
365
|
+
"description": "The transition value of the action in the state machine",
|
|
366
|
+
"or": [
|
|
367
|
+
{
|
|
368
|
+
"description": "The transition value of the action in the state machine",
|
|
369
|
+
"title": "MockAsset.value",
|
|
370
|
+
"type": "string",
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
"ref": "ExpressionRef",
|
|
374
|
+
"type": "ref",
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"ref": "BindingRef",
|
|
378
|
+
"type": "ref",
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
"type": "or",
|
|
382
|
+
},
|
|
383
|
+
"required": false,
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
"source": "transform.test.ts",
|
|
387
|
+
"title": "MockAsset",
|
|
388
|
+
"type": "object",
|
|
389
|
+
}
|
|
390
|
+
`;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { test, expect, describe, beforeEach } from "vitest";
|
|
2
|
+
import type { NamedTypeWithGenerics, ObjectType } from "@xlr-lib/xlr";
|
|
3
|
+
import {
|
|
4
|
+
applyCommonProps,
|
|
5
|
+
applyAssetWrapperOrSwitch,
|
|
6
|
+
applyValueRefs,
|
|
7
|
+
applyTemplateProperty,
|
|
8
|
+
} from "../index";
|
|
9
|
+
|
|
10
|
+
describe("Transform Tests", () => {
|
|
11
|
+
let MockAsset: NamedTypeWithGenerics<ObjectType>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
MockAsset = {
|
|
15
|
+
name: "MockAsset",
|
|
16
|
+
type: "object",
|
|
17
|
+
source: "transform.test.ts",
|
|
18
|
+
properties: {
|
|
19
|
+
id: {
|
|
20
|
+
required: true,
|
|
21
|
+
node: {
|
|
22
|
+
type: "string",
|
|
23
|
+
title: "Asset.id",
|
|
24
|
+
description: "Each asset requires a unique id per view",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
type: {
|
|
28
|
+
required: true,
|
|
29
|
+
node: {
|
|
30
|
+
type: "string",
|
|
31
|
+
const: "mock",
|
|
32
|
+
title: "Asset.type",
|
|
33
|
+
description:
|
|
34
|
+
"The asset type determines the semantics of how a user interacts with a page",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
value: {
|
|
38
|
+
required: false,
|
|
39
|
+
node: {
|
|
40
|
+
type: "string",
|
|
41
|
+
title: "MockAsset.value",
|
|
42
|
+
description:
|
|
43
|
+
"The transition value of the action in the state machine",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
primaryChild: {
|
|
47
|
+
required: true,
|
|
48
|
+
node: {
|
|
49
|
+
type: "ref",
|
|
50
|
+
ref: "AssetWrapper<AnyAsset>",
|
|
51
|
+
genericArguments: [
|
|
52
|
+
{
|
|
53
|
+
type: "ref",
|
|
54
|
+
ref: "AnyAsset",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
title: "ActionAsset.label",
|
|
58
|
+
description: "A text-like asset for the action's label",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
secondaryChildren: {
|
|
62
|
+
required: false,
|
|
63
|
+
node: {
|
|
64
|
+
type: "array",
|
|
65
|
+
elementType: {
|
|
66
|
+
type: "ref",
|
|
67
|
+
ref: "Asset",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
additionalProperties: {
|
|
73
|
+
type: "unknown",
|
|
74
|
+
},
|
|
75
|
+
title: "MockAsset",
|
|
76
|
+
description: "Mock Asset for test",
|
|
77
|
+
genericTokens: [
|
|
78
|
+
{
|
|
79
|
+
symbol: "AnyAsset",
|
|
80
|
+
constraints: {
|
|
81
|
+
type: "ref",
|
|
82
|
+
ref: "Asset",
|
|
83
|
+
},
|
|
84
|
+
default: {
|
|
85
|
+
type: "ref",
|
|
86
|
+
ref: "Asset",
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("CommonProps Transform", () => {
|
|
94
|
+
expect(applyCommonProps(MockAsset, "Assets")).toMatchSnapshot();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("AssetWrapperOrSwitch Transform", () => {
|
|
98
|
+
expect(applyAssetWrapperOrSwitch(MockAsset, "Assets")).toMatchSnapshot();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("applyValueRefs Transform", () => {
|
|
102
|
+
expect(applyValueRefs(MockAsset, "Assets")).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("applyTemplateProperty Transform", () => {
|
|
106
|
+
expect(applyTemplateProperty(MockAsset, "Assets")).toMatchSnapshot();
|
|
107
|
+
});
|
|
108
|
+
});
|
package/src/xlr/index.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Filters, TypeMetadata } from "@xlr-lib/xlr-sdk";
|
|
2
|
+
import { BasicXLRRegistry } from "@xlr-lib/xlr-sdk";
|
|
3
|
+
import type { NamedType, NodeType } from "@xlr-lib/xlr";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Player specific implementation of a XLRs Registry
|
|
7
|
+
*/
|
|
8
|
+
export class PlayerXLRRegistry extends BasicXLRRegistry {
|
|
9
|
+
/** Keeps the mapping of how a type is referenced by Player to the underlying XLR */
|
|
10
|
+
private registrationMap: Map<string, string | Array<string>>;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.registrationMap = new Map();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get(id: string): NamedType<NodeType> | undefined {
|
|
18
|
+
const realNames = this.registrationMap.get(id);
|
|
19
|
+
if (realNames === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(realNames)) {
|
|
24
|
+
return {
|
|
25
|
+
name: `${id}PartialMatchType`,
|
|
26
|
+
source: "registry.ts",
|
|
27
|
+
type: "or",
|
|
28
|
+
or: realNames.map(
|
|
29
|
+
(partialMatchID) => super.get(partialMatchID) as NamedType,
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return super.get(realNames);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
add(type: NamedType<NodeType>, plugin: string, capability: string): void {
|
|
38
|
+
let registeredName = type.name;
|
|
39
|
+
// Figure out how the Asset/View will be referenced from the type argument that will fill in Asset
|
|
40
|
+
if (
|
|
41
|
+
(capability === "Assets" || capability === "Views") &&
|
|
42
|
+
type.type === "object" &&
|
|
43
|
+
type.extends?.genericArguments?.[0]?.type === "string" &&
|
|
44
|
+
type.extends?.genericArguments?.[0]?.const
|
|
45
|
+
) {
|
|
46
|
+
this.registrationMap.set(registeredName, type.name);
|
|
47
|
+
registeredName = type.extends.genericArguments[0].const;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.registrationMap.has(registeredName)) {
|
|
51
|
+
const current = this.registrationMap.get(registeredName) as
|
|
52
|
+
| string
|
|
53
|
+
| string[];
|
|
54
|
+
if (Array.isArray(current)) {
|
|
55
|
+
current.push(registeredName);
|
|
56
|
+
} else {
|
|
57
|
+
this.registrationMap.set(registeredName, [current, type.name]);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
this.registrationMap.set(registeredName, type.name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
super.add(type, plugin, capability);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
has(id: string): boolean {
|
|
67
|
+
return this.registrationMap.has(id);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
list(filterArgs?: Filters): NamedType<NodeType>[] {
|
|
71
|
+
return super.list(filterArgs);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
info(id: string): TypeMetadata | undefined {
|
|
75
|
+
const realNames = this.registrationMap.get(id);
|
|
76
|
+
if (realNames === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (Array.isArray(realNames)) {
|
|
81
|
+
const metaDataArrays = realNames.map((name) => super.info(name));
|
|
82
|
+
const firstElement = metaDataArrays[0];
|
|
83
|
+
const equal = metaDataArrays.every(
|
|
84
|
+
(metaData) =>
|
|
85
|
+
metaData?.plugin === firstElement?.plugin &&
|
|
86
|
+
metaData?.capability === firstElement?.capability,
|
|
87
|
+
);
|
|
88
|
+
if (equal) {
|
|
89
|
+
return firstElement;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
throw Error(
|
|
93
|
+
`Error: can't determine accurate info for type ${id} as it is provided by multiple plugins/capabilities`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return super.info(realNames);
|
|
98
|
+
}
|
|
99
|
+
}
|