@microsoft/fast-html 1.0.0-alpha.4 → 1.0.0-alpha.40

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.
Files changed (68) hide show
  1. package/README.md +242 -18
  2. package/dist/dts/components/element.d.ts +10 -0
  3. package/dist/dts/components/index.d.ts +3 -1
  4. package/dist/dts/components/observer-map.d.ts +27 -0
  5. package/dist/dts/components/schema.d.ts +144 -0
  6. package/dist/dts/components/template.d.ts +83 -7
  7. package/dist/dts/components/utilities.d.ts +126 -37
  8. package/dist/dts/index.d.ts +1 -1
  9. package/dist/dts/tsdoc-metadata.json +1 -1
  10. package/dist/esm/components/element.js +73 -0
  11. package/dist/esm/components/index.js +3 -1
  12. package/dist/esm/components/observer-map.js +68 -0
  13. package/dist/esm/components/observer-map.spec.js +39 -0
  14. package/dist/esm/components/schema.js +250 -0
  15. package/dist/esm/components/schema.spec.js +484 -0
  16. package/dist/esm/components/template.js +235 -213
  17. package/dist/esm/components/utilities.js +990 -64
  18. package/dist/esm/components/utilities.spec.js +522 -93
  19. package/dist/esm/index.js +1 -1
  20. package/dist/fast-html.api.json +350 -1
  21. package/dist/fast-html.d.ts +283 -6
  22. package/dist/fast-html.untrimmed.d.ts +283 -6
  23. package/package.json +27 -38
  24. package/rules/attribute-directives.yml +38 -0
  25. package/rules/call-expression-with-event-argument.yml +41 -0
  26. package/rules/member-expression.yml +33 -0
  27. package/rules/tag-function-to-template-literal.yml +16 -0
  28. package/dist/dts/fixtures/binding/binding.spec.d.ts +0 -1
  29. package/dist/dts/fixtures/binding/main.d.ts +0 -1
  30. package/dist/dts/fixtures/children/children.spec.d.ts +0 -1
  31. package/dist/dts/fixtures/children/main.d.ts +0 -1
  32. package/dist/dts/fixtures/dot-syntax/dot-syntax.spec.d.ts +0 -1
  33. package/dist/dts/fixtures/dot-syntax/main.d.ts +0 -1
  34. package/dist/dts/fixtures/event/event.spec.d.ts +0 -1
  35. package/dist/dts/fixtures/event/main.d.ts +0 -1
  36. package/dist/dts/fixtures/partial/main.d.ts +0 -1
  37. package/dist/dts/fixtures/partial/partial.spec.d.ts +0 -1
  38. package/dist/dts/fixtures/ref/main.d.ts +0 -1
  39. package/dist/dts/fixtures/ref/ref.spec.d.ts +0 -1
  40. package/dist/dts/fixtures/repeat/main.d.ts +0 -1
  41. package/dist/dts/fixtures/repeat/repeat.spec.d.ts +0 -1
  42. package/dist/dts/fixtures/slotted/main.d.ts +0 -1
  43. package/dist/dts/fixtures/slotted/slotted.spec.d.ts +0 -1
  44. package/dist/dts/fixtures/when/main.d.ts +0 -1
  45. package/dist/dts/fixtures/when/when.spec.d.ts +0 -1
  46. package/dist/esm/fixtures/attribute/attribute.spec.js +0 -23
  47. package/dist/esm/fixtures/attribute/main.js +0 -19
  48. package/dist/esm/fixtures/binding/binding.spec.js +0 -17
  49. package/dist/esm/fixtures/binding/main.js +0 -19
  50. package/dist/esm/fixtures/children/children.spec.js +0 -33
  51. package/dist/esm/fixtures/children/main.js +0 -24
  52. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +0 -9
  53. package/dist/esm/fixtures/dot-syntax/main.js +0 -16
  54. package/dist/esm/fixtures/event/event.spec.js +0 -12
  55. package/dist/esm/fixtures/event/main.js +0 -16
  56. package/dist/esm/fixtures/partial/main.js +0 -31
  57. package/dist/esm/fixtures/partial/partial.spec.js +0 -14
  58. package/dist/esm/fixtures/ref/main.js +0 -14
  59. package/dist/esm/fixtures/ref/ref.spec.js +0 -13
  60. package/dist/esm/fixtures/repeat/main.js +0 -19
  61. package/dist/esm/fixtures/repeat/repeat.spec.js +0 -26
  62. package/dist/esm/fixtures/slotted/main.js +0 -22
  63. package/dist/esm/fixtures/slotted/slotted.spec.js +0 -25
  64. package/dist/esm/fixtures/when/main.js +0 -146
  65. package/dist/esm/fixtures/when/when.spec.js +0 -82
  66. package/dist/esm/tsconfig.tsbuildinfo +0 -1
  67. /package/dist/dts/{fixtures/attribute/attribute.spec.d.ts → components/observer-map.spec.d.ts} +0 -0
  68. /package/dist/dts/{fixtures/attribute/main.d.ts → components/schema.spec.d.ts} +0 -0
@@ -0,0 +1,484 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { refPropertyName, Schema } from "./schema.js";
3
+ test.describe("Schema", async () => {
4
+ test("should instantiate with a custom element name without throwing", async () => {
5
+ expect(() => new Schema("my-custom-element")).not.toThrow();
6
+ });
7
+ test("should return null when a JSON schema is requested but none exists for that property name", async () => {
8
+ const schema = new Schema("my-custom-element");
9
+ expect(schema.getSchema("foo")).toEqual(null);
10
+ });
11
+ test("should be able to return a JSON schema after adding a path", async () => {
12
+ const schema = new Schema("my-custom-element");
13
+ schema.addPath({
14
+ rootPropertyName: "a",
15
+ pathConfig: {
16
+ type: "default",
17
+ path: "a",
18
+ currentContext: null,
19
+ parentContext: null,
20
+ },
21
+ childrenMap: null,
22
+ });
23
+ const schemaA = schema.getSchema("a");
24
+ expect(schemaA).not.toBe(null);
25
+ expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
26
+ expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
27
+ });
28
+ test("should add a property and cast the schema as type object if a nested path is given", async () => {
29
+ const schema = new Schema("my-custom-element");
30
+ schema.addPath({
31
+ rootPropertyName: "a",
32
+ pathConfig: {
33
+ type: "default",
34
+ path: "a.b",
35
+ currentContext: null,
36
+ parentContext: null,
37
+ },
38
+ childrenMap: null,
39
+ });
40
+ let schemaA = schema.getSchema("a");
41
+ expect(schemaA.properties).toBeDefined();
42
+ expect(schemaA.properties).toHaveProperty("b");
43
+ schema.addPath({
44
+ rootPropertyName: "a",
45
+ pathConfig: {
46
+ type: "default",
47
+ path: "a.b.c",
48
+ currentContext: null,
49
+ parentContext: null,
50
+ },
51
+ childrenMap: null,
52
+ });
53
+ schemaA = schema.getSchema("a");
54
+ expect(schemaA.properties).toBeDefined();
55
+ expect(schemaA.properties).toHaveProperty("b");
56
+ expect(schemaA.properties.b.properties).toBeDefined();
57
+ expect(schemaA.properties.b.properties).toHaveProperty("c");
58
+ });
59
+ test("should add a new context in a schema", async () => {
60
+ var _a, _b, _c;
61
+ const schema = new Schema("my-custom-element");
62
+ schema.addPath({
63
+ rootPropertyName: "items",
64
+ pathConfig: {
65
+ type: "repeat",
66
+ path: "items",
67
+ currentContext: "item",
68
+ parentContext: null,
69
+ },
70
+ childrenMap: null,
71
+ });
72
+ const schemaA = schema.getSchema("items");
73
+ expect(schemaA).toBeDefined();
74
+ expect(schemaA.$ref).toBeDefined();
75
+ expect(schemaA.$ref).toEqual("#/$defs/item");
76
+ expect(schemaA.type).toEqual("array");
77
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["item"]).toBeDefined();
78
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["item"].$fast_context).toEqual("items");
79
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"].$fast_parent_contexts).toEqual([null]);
80
+ });
81
+ test("should add an object to a context in a schema", async () => {
82
+ var _a, _b, _c, _d, _e, _f;
83
+ const schema = new Schema("my-custom-element");
84
+ schema.addPath({
85
+ rootPropertyName: "items",
86
+ pathConfig: {
87
+ type: "repeat",
88
+ path: "items",
89
+ currentContext: "item",
90
+ parentContext: null,
91
+ },
92
+ childrenMap: null,
93
+ });
94
+ schema.addPath({
95
+ rootPropertyName: "items",
96
+ pathConfig: {
97
+ type: "default",
98
+ path: "item.a.b",
99
+ currentContext: "item",
100
+ parentContext: null,
101
+ },
102
+ childrenMap: null,
103
+ });
104
+ const schemaA = schema.getSchema("items");
105
+ expect(schemaA).toBeDefined();
106
+ expect(schemaA.$ref).toBeDefined();
107
+ expect(schemaA.$ref).toEqual("#/$defs/item");
108
+ expect(schemaA.type).toEqual("array");
109
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["item"]).toBeDefined();
110
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["item"].$fast_context).toEqual("items");
111
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"].$fast_parent_contexts).toEqual([null]);
112
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["item"].properties).toBeDefined();
113
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["item"].properties["a"]).toBeDefined();
114
+ expect((_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["item"].properties["a"].type).toEqual("object");
115
+ });
116
+ test("should add a nested context in a schema", async () => {
117
+ var _a, _b, _c, _d, _e;
118
+ const schema = new Schema("my-custom-element");
119
+ schema.addPath({
120
+ rootPropertyName: "a",
121
+ pathConfig: {
122
+ type: "default",
123
+ path: "a",
124
+ currentContext: null,
125
+ parentContext: null,
126
+ },
127
+ childrenMap: null,
128
+ });
129
+ schema.addPath({
130
+ rootPropertyName: "a",
131
+ pathConfig: {
132
+ type: "repeat",
133
+ path: "a.items",
134
+ currentContext: "item",
135
+ parentContext: null,
136
+ },
137
+ childrenMap: null,
138
+ });
139
+ const schemaA = schema.getSchema("a");
140
+ expect(schemaA).toBeDefined();
141
+ expect((_a = schemaA === null || schemaA === void 0 ? void 0 : schemaA.properties) === null || _a === void 0 ? void 0 : _a["items"]).toBeDefined();
142
+ expect((_b = schemaA === null || schemaA === void 0 ? void 0 : schemaA.properties) === null || _b === void 0 ? void 0 : _b["items"].items.$ref).toEqual("#/$defs/item");
143
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"]).toBeDefined();
144
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["item"].$fast_context).toEqual("items");
145
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["item"].$fast_parent_contexts).toEqual([null]);
146
+ });
147
+ test("should define an object as a nested context in a schema", async () => {
148
+ var _a, _b, _c, _d, _e, _f, _g;
149
+ const schema = new Schema("my-custom-element");
150
+ schema.addPath({
151
+ rootPropertyName: "a",
152
+ pathConfig: {
153
+ type: "default",
154
+ path: "a",
155
+ currentContext: null,
156
+ parentContext: null,
157
+ },
158
+ childrenMap: null,
159
+ });
160
+ schema.addPath({
161
+ rootPropertyName: "a",
162
+ pathConfig: {
163
+ type: "repeat",
164
+ path: "a.items",
165
+ currentContext: "item",
166
+ parentContext: null,
167
+ },
168
+ childrenMap: null,
169
+ });
170
+ schema.addPath({
171
+ rootPropertyName: "a",
172
+ pathConfig: {
173
+ type: "access",
174
+ path: "item.b",
175
+ currentContext: "item",
176
+ parentContext: null,
177
+ },
178
+ childrenMap: null,
179
+ });
180
+ const schemaA = schema.getSchema("a");
181
+ expect(schemaA).toBeDefined();
182
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["item"]).toBeDefined();
183
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["item"].$fast_context).toEqual("items");
184
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"].$fast_parent_contexts).toEqual([null]);
185
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["item"].type).toEqual("object");
186
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["item"].properties).toBeDefined();
187
+ expect((_g = (_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["item"].properties) === null || _g === void 0 ? void 0 : _g["b"]).toBeDefined();
188
+ });
189
+ test("should define nested contexts in a schema", async () => {
190
+ var _a, _b, _c, _d, _e, _f;
191
+ const schema = new Schema("my-custom-element");
192
+ schema.addPath({
193
+ rootPropertyName: "a",
194
+ pathConfig: {
195
+ type: "default",
196
+ path: "a",
197
+ currentContext: null,
198
+ parentContext: null,
199
+ },
200
+ childrenMap: null,
201
+ });
202
+ schema.addPath({
203
+ rootPropertyName: "a",
204
+ pathConfig: {
205
+ type: "repeat",
206
+ path: "a.users",
207
+ currentContext: "user",
208
+ parentContext: null,
209
+ },
210
+ childrenMap: null,
211
+ });
212
+ schema.addPath({
213
+ rootPropertyName: "a",
214
+ pathConfig: {
215
+ type: "repeat",
216
+ path: "user.posts",
217
+ currentContext: "post",
218
+ parentContext: "user"
219
+ },
220
+ childrenMap: null,
221
+ });
222
+ const schemaA = schema.getSchema("a");
223
+ expect(schemaA).toBeDefined();
224
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["user"]).toBeDefined();
225
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["user"].$fast_context).toEqual("users");
226
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["user"].$fast_parent_contexts).toEqual([null]);
227
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["post"]).toBeDefined();
228
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["post"].$fast_context).toEqual("posts");
229
+ expect((_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["post"].$fast_parent_contexts).toEqual([null, "user"]);
230
+ });
231
+ test("should define nested contexts with objects in a schema", async () => {
232
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
233
+ const schema = new Schema("my-custom-element");
234
+ schema.addPath({
235
+ rootPropertyName: "a",
236
+ pathConfig: {
237
+ type: "repeat",
238
+ path: "a.users",
239
+ currentContext: "user",
240
+ parentContext: null,
241
+ },
242
+ childrenMap: null,
243
+ });
244
+ schema.addPath({
245
+ rootPropertyName: "a",
246
+ pathConfig: {
247
+ type: "access",
248
+ path: "user.a.b",
249
+ currentContext: "user",
250
+ parentContext: null,
251
+ },
252
+ childrenMap: null,
253
+ });
254
+ schema.addPath({
255
+ rootPropertyName: "a",
256
+ pathConfig: {
257
+ type: "repeat",
258
+ path: "user.posts",
259
+ currentContext: "post",
260
+ parentContext: "user"
261
+ },
262
+ childrenMap: null,
263
+ });
264
+ schema.addPath({
265
+ rootPropertyName: "a",
266
+ pathConfig: {
267
+ type: "access",
268
+ path: "post.c.d",
269
+ currentContext: "post",
270
+ parentContext: null,
271
+ },
272
+ childrenMap: null,
273
+ });
274
+ schema.addPath({
275
+ rootPropertyName: "a",
276
+ pathConfig: {
277
+ type: "repeat",
278
+ path: "post.meta.tags",
279
+ currentContext: "tag",
280
+ parentContext: "post"
281
+ },
282
+ childrenMap: null,
283
+ });
284
+ const schemaA = schema.getSchema("a");
285
+ expect(schemaA).toBeDefined();
286
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["user"]).toBeDefined();
287
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["user"].$fast_context).toEqual("users");
288
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["user"].$fast_parent_contexts).toEqual([null]);
289
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["user"].type).toEqual("object");
290
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["user"].properties).toBeDefined();
291
+ expect((_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["user"].properties["a"]).toBeDefined();
292
+ expect((_g = schemaA.$defs) === null || _g === void 0 ? void 0 : _g["user"].properties["a"].properties["b"]).toBeDefined();
293
+ expect((_h = schemaA.$defs) === null || _h === void 0 ? void 0 : _h["post"]).toBeDefined();
294
+ expect((_j = schemaA.$defs) === null || _j === void 0 ? void 0 : _j["post"].$fast_context).toEqual("posts");
295
+ expect((_k = schemaA.$defs) === null || _k === void 0 ? void 0 : _k["post"].$fast_parent_contexts).toEqual([null, "user"]);
296
+ expect((_l = schemaA.$defs) === null || _l === void 0 ? void 0 : _l["post"].type).toEqual("object");
297
+ expect((_m = schemaA.$defs) === null || _m === void 0 ? void 0 : _m["post"].properties).toBeDefined();
298
+ expect((_o = schemaA.$defs) === null || _o === void 0 ? void 0 : _o["post"].properties["c"]).toBeDefined();
299
+ expect((_p = schemaA.$defs) === null || _p === void 0 ? void 0 : _p["post"].properties["c"].properties["d"]).toBeDefined();
300
+ expect((_q = schemaA.$defs) === null || _q === void 0 ? void 0 : _q["post"].properties["meta"]).toBeDefined();
301
+ expect((_r = schemaA.$defs) === null || _r === void 0 ? void 0 : _r["post"].properties["meta"].properties["tags"]).toBeDefined();
302
+ expect((_s = schemaA.$defs) === null || _s === void 0 ? void 0 : _s["post"].properties["meta"].properties["tags"].items).toBeDefined();
303
+ expect((_t = schemaA.$defs) === null || _t === void 0 ? void 0 : _t["post"].properties["meta"].properties["tags"].items.$ref).toEqual("#/$defs/tag");
304
+ expect((_u = schemaA.$defs) === null || _u === void 0 ? void 0 : _u["tag"]).toBeDefined();
305
+ expect((_v = schemaA.$defs) === null || _v === void 0 ? void 0 : _v["tag"].$fast_context).toEqual("tags");
306
+ expect((_w = schemaA.$defs) === null || _w === void 0 ? void 0 : _w["tag"].$fast_parent_contexts).toEqual([null, "user", "post"]);
307
+ });
308
+ test("should define an anyOf with a $ref to another schema", async () => {
309
+ var _a;
310
+ const schema = new Schema("my-custom-element");
311
+ schema.addPath({
312
+ rootPropertyName: "a",
313
+ pathConfig: {
314
+ type: "default",
315
+ path: "a",
316
+ currentContext: null,
317
+ parentContext: null,
318
+ },
319
+ childrenMap: {
320
+ customElementName: "my-custom-element-2",
321
+ attributeName: "b",
322
+ },
323
+ });
324
+ const schemaA = schema.getSchema("a");
325
+ expect(schemaA).not.toBe(null);
326
+ expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
327
+ expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
328
+ expect(schemaA.anyOf).not.toBeUndefined();
329
+ expect(schemaA.anyOf).toHaveLength(1);
330
+ expect((_a = schemaA.anyOf) === null || _a === void 0 ? void 0 : _a[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/b.json");
331
+ });
332
+ test("should define an anyOf with a $ref to multiple schemas", async () => {
333
+ var _a, _b;
334
+ const schema = new Schema("my-custom-element");
335
+ schema.addPath({
336
+ rootPropertyName: "a",
337
+ pathConfig: {
338
+ type: "default",
339
+ path: "a",
340
+ currentContext: null,
341
+ parentContext: null,
342
+ },
343
+ childrenMap: {
344
+ customElementName: "my-custom-element-2",
345
+ attributeName: "b",
346
+ },
347
+ });
348
+ schema.addPath({
349
+ rootPropertyName: "a",
350
+ pathConfig: {
351
+ type: "default",
352
+ path: "a",
353
+ currentContext: null,
354
+ parentContext: null,
355
+ },
356
+ childrenMap: {
357
+ customElementName: "my-custom-element-3",
358
+ attributeName: "c",
359
+ },
360
+ });
361
+ const schemaA = schema.getSchema("a");
362
+ expect(schemaA).not.toBe(null);
363
+ expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
364
+ expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
365
+ expect(schemaA.anyOf).not.toBeUndefined();
366
+ expect(schemaA.anyOf).toHaveLength(2);
367
+ expect((_a = schemaA.anyOf) === null || _a === void 0 ? void 0 : _a[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/b.json");
368
+ expect((_b = schemaA.anyOf) === null || _b === void 0 ? void 0 : _b[1].$ref).toEqual("https://fast.design/schemas/my-custom-element-3/c.json");
369
+ });
370
+ test("should define an anyOf with a $ref to another schema in a nested object", async () => {
371
+ const schema = new Schema("my-custom-element");
372
+ schema.addPath({
373
+ rootPropertyName: "a",
374
+ pathConfig: {
375
+ type: "default",
376
+ path: "a.b",
377
+ currentContext: null,
378
+ parentContext: null,
379
+ },
380
+ childrenMap: null,
381
+ });
382
+ let schemaA = schema.getSchema("a");
383
+ schema.addPath({
384
+ rootPropertyName: "a",
385
+ pathConfig: {
386
+ type: "default",
387
+ path: "a.b.c",
388
+ currentContext: null,
389
+ parentContext: null,
390
+ },
391
+ childrenMap: {
392
+ customElementName: "my-custom-element-2",
393
+ attributeName: "test"
394
+ },
395
+ });
396
+ schemaA = schema.getSchema("a");
397
+ expect(schemaA.properties.b.properties.c).toBeDefined();
398
+ expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
399
+ expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
400
+ });
401
+ test("should define an anyOf with a $ref to multiple schemas in a nested object", async () => {
402
+ const schema = new Schema("my-custom-element");
403
+ schema.addPath({
404
+ rootPropertyName: "a",
405
+ pathConfig: {
406
+ type: "default",
407
+ path: "a.b",
408
+ currentContext: null,
409
+ parentContext: null,
410
+ },
411
+ childrenMap: null,
412
+ });
413
+ let schemaA = schema.getSchema("a");
414
+ schema.addPath({
415
+ rootPropertyName: "a",
416
+ pathConfig: {
417
+ type: "default",
418
+ path: "a.b.c",
419
+ currentContext: null,
420
+ parentContext: null,
421
+ },
422
+ childrenMap: {
423
+ customElementName: "my-custom-element-2",
424
+ attributeName: "test"
425
+ },
426
+ });
427
+ schema.addPath({
428
+ rootPropertyName: "a",
429
+ pathConfig: {
430
+ type: "default",
431
+ path: "a.b.c",
432
+ currentContext: null,
433
+ parentContext: null,
434
+ },
435
+ childrenMap: {
436
+ customElementName: "my-custom-element-3",
437
+ attributeName: "test-2"
438
+ },
439
+ });
440
+ schemaA = schema.getSchema("a");
441
+ expect(schemaA.properties.b.properties.c).toBeDefined();
442
+ expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
443
+ expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
444
+ expect(schemaA.properties.b.properties.c.anyOf[1].$ref).toEqual("https://fast.design/schemas/my-custom-element-3/test-2.json");
445
+ });
446
+ test("should define an anyOf with a $ref in a nested object in a context", async () => {
447
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
448
+ const schema = new Schema("my-custom-element");
449
+ schema.addPath({
450
+ rootPropertyName: "a",
451
+ pathConfig: {
452
+ type: "repeat",
453
+ path: "a.users",
454
+ currentContext: "user",
455
+ parentContext: null,
456
+ },
457
+ childrenMap: null,
458
+ });
459
+ schema.addPath({
460
+ rootPropertyName: "a",
461
+ pathConfig: {
462
+ type: "access",
463
+ path: "user.a.b",
464
+ currentContext: "user",
465
+ parentContext: null,
466
+ },
467
+ childrenMap: {
468
+ customElementName: "my-custom-element-2",
469
+ attributeName: "c"
470
+ },
471
+ });
472
+ const schemaA = schema.getSchema("a");
473
+ expect(schemaA).toBeDefined();
474
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["user"]).toBeDefined();
475
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["user"].$fast_context).toEqual("users");
476
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["user"].$fast_parent_contexts).toEqual([null]);
477
+ expect((_d = schemaA.$defs) === null || _d === void 0 ? void 0 : _d["user"].type).toEqual("object");
478
+ expect((_e = schemaA.$defs) === null || _e === void 0 ? void 0 : _e["user"].properties).toBeDefined();
479
+ expect((_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["user"].properties["a"]).toBeDefined();
480
+ expect((_g = schemaA.$defs) === null || _g === void 0 ? void 0 : _g["user"].properties["a"].properties["b"]).toBeDefined();
481
+ expect((_h = schemaA.$defs) === null || _h === void 0 ? void 0 : _h["user"].properties["a"].properties["b"].anyOf).toHaveLength(1);
482
+ expect((_j = schemaA.$defs) === null || _j === void 0 ? void 0 : _j["user"].properties["a"].properties["b"].anyOf[0][refPropertyName]).toEqual("https://fast.design/schemas/my-custom-element-2/c.json");
483
+ });
484
+ });