@microsoft/fast-html 1.0.0-alpha.34 → 1.0.0-alpha.36
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/dts/components/utilities.d.ts +9 -2
- package/dist/esm/components/element.js +51 -5
- package/dist/esm/components/observer-map.js +15 -9
- package/dist/esm/components/observer-map.spec.js +29 -9
- package/dist/esm/components/schema.spec.js +96 -97
- package/dist/esm/components/template.js +120 -130
- package/dist/esm/components/utilities.js +113 -30
- package/dist/esm/components/utilities.spec.js +249 -135
- package/package.json +5 -5
|
@@ -173,12 +173,19 @@ export declare function getChildrenMap(previousString: string | null): ChildrenM
|
|
|
173
173
|
* @returns True if the objects are deeply equal, false otherwise
|
|
174
174
|
*/
|
|
175
175
|
export declare function deepEqual(obj1: any, obj2: any): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Checks if a value is a plain object (not an array, null, or other type).
|
|
178
|
+
*
|
|
179
|
+
* @param value - The value to check
|
|
180
|
+
* @returns True if the value is a plain object, false otherwise
|
|
181
|
+
*/
|
|
182
|
+
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
176
183
|
/**
|
|
177
184
|
* Deeply merges the source object into the target object.
|
|
178
185
|
*
|
|
179
186
|
* @param target - The target object to merge into
|
|
180
187
|
* @param source - The source object to merge from
|
|
181
|
-
* @returns
|
|
188
|
+
* @returns boolean indicating whether changes were made
|
|
182
189
|
*/
|
|
183
|
-
export declare function deepMerge(target: any, source: any):
|
|
190
|
+
export declare function deepMerge(target: any, source: any): boolean;
|
|
184
191
|
export {};
|
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
import { attr } from "@microsoft/fast-element";
|
|
2
|
+
import { deferHydrationAttribute } from "@microsoft/fast-element/element-hydration.js";
|
|
3
|
+
import { composedParent } from "@microsoft/fast-element/utilities.js";
|
|
4
|
+
/**
|
|
5
|
+
* Waits for the `defer-hydration` attribute to be removed from the target element.
|
|
6
|
+
*
|
|
7
|
+
* @param target - The target element to wait for attribute removal
|
|
8
|
+
*/
|
|
9
|
+
function waitForAttributeRemoval(target) {
|
|
10
|
+
if (!target.hasAttribute(deferHydrationAttribute)) {
|
|
11
|
+
return Promise.resolve();
|
|
12
|
+
}
|
|
13
|
+
return new Promise(resolve => {
|
|
14
|
+
const observer = new MutationObserver(() => {
|
|
15
|
+
if (!target.hasAttribute(deferHydrationAttribute)) {
|
|
16
|
+
observer.disconnect();
|
|
17
|
+
resolve();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
observer.observe(target, { attributeFilter: [deferHydrationAttribute] });
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Waits until all ancestor elements no longer have the `defer-hydration` attribute.
|
|
25
|
+
*
|
|
26
|
+
* @param element - The element to wait for ancestor hydration
|
|
27
|
+
*/
|
|
28
|
+
async function waitForAncestorHydration(element) {
|
|
29
|
+
let ancestor = composedParent(element);
|
|
30
|
+
while (ancestor) {
|
|
31
|
+
if (ancestor instanceof HTMLElement &&
|
|
32
|
+
ancestor.hasAttribute(deferHydrationAttribute)) {
|
|
33
|
+
await waitForAttributeRemoval(ancestor);
|
|
34
|
+
}
|
|
35
|
+
ancestor = composedParent(ancestor);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
2
38
|
/**
|
|
3
39
|
* A mixin function that extends a base class with additional functionality for
|
|
4
40
|
* rendering and hydration.
|
|
@@ -9,15 +45,25 @@ import { attr } from "@microsoft/fast-element";
|
|
|
9
45
|
*/
|
|
10
46
|
export function RenderableFASTElement(BaseCtor) {
|
|
11
47
|
const C = class extends BaseCtor {
|
|
48
|
+
/**
|
|
49
|
+
* Prepares the element for hydration by calling the user-defined prepare method
|
|
50
|
+
* and waiting for all ancestor elements to be hydrated.
|
|
51
|
+
*
|
|
52
|
+
* @returns A promise that resolves when the element is ready for hydration.
|
|
53
|
+
*/
|
|
54
|
+
async _prepare() {
|
|
55
|
+
if (this.prepare) {
|
|
56
|
+
await this.prepare();
|
|
57
|
+
}
|
|
58
|
+
await waitForAncestorHydration(this);
|
|
59
|
+
this.deferHydration = false;
|
|
60
|
+
}
|
|
12
61
|
constructor(...args) {
|
|
13
|
-
var _a, _b;
|
|
14
62
|
super(...args);
|
|
15
63
|
this.deferHydration = true;
|
|
16
|
-
|
|
17
|
-
this.deferHydration = false;
|
|
18
|
-
});
|
|
64
|
+
void this._prepare();
|
|
19
65
|
}
|
|
20
66
|
};
|
|
21
|
-
attr({ mode: "boolean", attribute:
|
|
67
|
+
attr({ mode: "boolean", attribute: deferHydrationAttribute })(C.prototype, "deferHydration");
|
|
22
68
|
return C;
|
|
23
69
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from "@microsoft/fast-element/observable.js";
|
|
2
|
-
import { assignObservables } from "./utilities.js";
|
|
2
|
+
import { assignObservables, deepMerge } from "./utilities.js";
|
|
3
3
|
/**
|
|
4
4
|
* ObserverMap provides functionality for caching binding paths, extracting root properties,
|
|
5
5
|
* and defining observable properties on class prototypes
|
|
@@ -17,15 +17,21 @@ export class ObserverMap {
|
|
|
17
17
|
const getAndAssignObservablesAlias = this.getAndAssignObservables;
|
|
18
18
|
const schema = this.schema;
|
|
19
19
|
function instanceResolverChanged(prev, next) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const isObjectAssignment = next !== null && typeof next === "object";
|
|
21
|
+
const isManagedArray = Array.isArray(next) && (next === null || next === void 0 ? void 0 : next.$fastController);
|
|
22
|
+
const shouldAssignProxy = isObjectAssignment && !(next === null || next === void 0 ? void 0 : next.$isProxy) && !isManagedArray;
|
|
23
|
+
const hasExistingProxy = prev !== null && typeof prev === "object" && prev.$isProxy;
|
|
24
|
+
if (shouldAssignProxy) {
|
|
25
|
+
if (hasExistingProxy) {
|
|
26
|
+
deepMerge(prev, next);
|
|
27
|
+
this[`_${propertyName}`] = prev;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this[propertyName] = getAndAssignObservablesAlias(this, propertyName, next, schema);
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
else if (
|
|
24
|
-
|
|
25
|
-
(Array.isArray(prev) &&
|
|
26
|
-
Array.isArray(next) &&
|
|
27
|
-
!(next === null || next === void 0 ? void 0 : next.$fastController))) {
|
|
28
|
-
this[propertyName] = getAndAssignObservablesAlias(this, propertyName, next, schema);
|
|
33
|
+
else if (!isObjectAssignment) {
|
|
34
|
+
this[propertyName] = next;
|
|
29
35
|
}
|
|
30
36
|
existingChangedMethod === null || existingChangedMethod === void 0 ? void 0 : existingChangedMethod.call(this, prev, next);
|
|
31
37
|
}
|
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { expect, test } from "@playwright/test";
|
|
3
2
|
import { ObserverMap } from "./observer-map.js";
|
|
4
|
-
import { Schema } from "./schema.js";
|
|
5
|
-
|
|
3
|
+
import { Schema, defsPropertyName } from "./schema.js";
|
|
4
|
+
const testElementName = "test-class";
|
|
5
|
+
test.describe("ObserverMap", async () => {
|
|
6
6
|
let observerMap;
|
|
7
|
-
let schema
|
|
7
|
+
let schema;
|
|
8
8
|
class TestClass {
|
|
9
9
|
}
|
|
10
|
-
test.beforeEach(() =>
|
|
10
|
+
test.beforeEach(async () => {
|
|
11
|
+
schema = new Schema(testElementName);
|
|
11
12
|
// Use TestClass.prototype so instances will have the observable properties
|
|
12
13
|
observerMap = new ObserverMap(TestClass.prototype, schema);
|
|
13
|
-
})
|
|
14
|
-
test("should create new instances", () =>
|
|
14
|
+
});
|
|
15
|
+
test("should create new instances", async () => {
|
|
15
16
|
const instance1 = new ObserverMap(TestClass.prototype, schema);
|
|
16
17
|
const instance2 = new ObserverMap(TestClass.prototype, schema);
|
|
17
18
|
expect(instance1).not.toBe(instance2);
|
|
18
|
-
})
|
|
19
|
-
|
|
19
|
+
});
|
|
20
|
+
test("proxies direct object assignments", async () => {
|
|
21
|
+
const schemaMap = Schema.jsonSchemaMap.get(testElementName);
|
|
22
|
+
schemaMap.set("someData", {
|
|
23
|
+
$schema: "https://json-schema.org/draft/2019-09/schema",
|
|
24
|
+
$id: `https://fast.design/schemas/${testElementName}/someData.json`,
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
foo: { type: "string" },
|
|
28
|
+
},
|
|
29
|
+
[defsPropertyName]: {},
|
|
30
|
+
});
|
|
31
|
+
observerMap.defineProperties();
|
|
32
|
+
const instance = new TestClass();
|
|
33
|
+
instance.someData = null;
|
|
34
|
+
const nextValue = { foo: "bar" };
|
|
35
|
+
instance.someData = nextValue;
|
|
36
|
+
expect(instance.someData).not.toBe(nextValue);
|
|
37
|
+
expect(instance.someData.$isProxy).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { expect, test } from "@playwright/test";
|
|
3
2
|
import { refPropertyName, Schema } from "./schema.js";
|
|
4
|
-
test.describe("Schema", () =>
|
|
5
|
-
test("should instantiate with a custom element name without throwing", () =>
|
|
3
|
+
test.describe("Schema", async () => {
|
|
4
|
+
test("should instantiate with a custom element name without throwing", async () => {
|
|
6
5
|
expect(() => new Schema("my-custom-element")).not.toThrow();
|
|
7
|
-
})
|
|
8
|
-
test("should return null when a JSON schema is requested but none exists for that property name", () =>
|
|
6
|
+
});
|
|
7
|
+
test("should return null when a JSON schema is requested but none exists for that property name", async () => {
|
|
9
8
|
const schema = new Schema("my-custom-element");
|
|
10
9
|
expect(schema.getSchema("foo")).toEqual(null);
|
|
11
|
-
})
|
|
12
|
-
test("should be able to return a JSON schema after adding a path", () =>
|
|
10
|
+
});
|
|
11
|
+
test("should be able to return a JSON schema after adding a path", async () => {
|
|
13
12
|
const schema = new Schema("my-custom-element");
|
|
14
13
|
schema.addPath({
|
|
15
14
|
rootPropertyName: "a",
|
|
@@ -25,8 +24,8 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
25
24
|
expect(schemaA).not.toBe(null);
|
|
26
25
|
expect(schemaA.$id).toEqual("https://fast.design/schemas/my-custom-element/a.json");
|
|
27
26
|
expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
|
|
28
|
-
})
|
|
29
|
-
test("should add a property and cast the schema as type object if a nested path is given", () =>
|
|
27
|
+
});
|
|
28
|
+
test("should add a property and cast the schema as type object if a nested path is given", async () => {
|
|
30
29
|
const schema = new Schema("my-custom-element");
|
|
31
30
|
schema.addPath({
|
|
32
31
|
rootPropertyName: "a",
|
|
@@ -56,8 +55,8 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
56
55
|
expect(schemaA.properties).toHaveProperty("b");
|
|
57
56
|
expect(schemaA.properties.b.properties).toBeDefined();
|
|
58
57
|
expect(schemaA.properties.b.properties).toHaveProperty("c");
|
|
59
|
-
})
|
|
60
|
-
test("should add a new context in a schema", () =>
|
|
58
|
+
});
|
|
59
|
+
test("should add a new context in a schema", async () => {
|
|
61
60
|
var _a, _b, _c;
|
|
62
61
|
const schema = new Schema("my-custom-element");
|
|
63
62
|
schema.addPath({
|
|
@@ -78,9 +77,9 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
78
77
|
expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["item"]).toBeDefined();
|
|
79
78
|
expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["item"].$fast_context).toEqual("items");
|
|
80
79
|
expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"].$fast_parent_contexts).toEqual([null]);
|
|
81
|
-
})
|
|
82
|
-
test("should add an object to a context in a schema", () =>
|
|
83
|
-
var
|
|
80
|
+
});
|
|
81
|
+
test("should add an object to a context in a schema", async () => {
|
|
82
|
+
var _a, _b, _c, _d, _e, _f;
|
|
84
83
|
const schema = new Schema("my-custom-element");
|
|
85
84
|
schema.addPath({
|
|
86
85
|
rootPropertyName: "items",
|
|
@@ -107,15 +106,15 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
107
106
|
expect(schemaA.$ref).toBeDefined();
|
|
108
107
|
expect(schemaA.$ref).toEqual("#/$defs/item");
|
|
109
108
|
expect(schemaA.type).toEqual("array");
|
|
110
|
-
expect((
|
|
111
|
-
expect((
|
|
112
|
-
expect((
|
|
113
|
-
expect((
|
|
114
|
-
expect((
|
|
115
|
-
expect((
|
|
116
|
-
})
|
|
117
|
-
test("should add a nested context in a schema", () =>
|
|
118
|
-
var
|
|
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;
|
|
119
118
|
const schema = new Schema("my-custom-element");
|
|
120
119
|
schema.addPath({
|
|
121
120
|
rootPropertyName: "a",
|
|
@@ -139,14 +138,14 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
139
138
|
});
|
|
140
139
|
const schemaA = schema.getSchema("a");
|
|
141
140
|
expect(schemaA).toBeDefined();
|
|
142
|
-
expect((
|
|
143
|
-
expect((
|
|
144
|
-
expect((
|
|
145
|
-
expect((
|
|
146
|
-
expect((
|
|
147
|
-
})
|
|
148
|
-
test("should define an object as a nested context in a schema", () =>
|
|
149
|
-
var
|
|
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;
|
|
150
149
|
const schema = new Schema("my-custom-element");
|
|
151
150
|
schema.addPath({
|
|
152
151
|
rootPropertyName: "a",
|
|
@@ -180,15 +179,15 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
180
179
|
});
|
|
181
180
|
const schemaA = schema.getSchema("a");
|
|
182
181
|
expect(schemaA).toBeDefined();
|
|
183
|
-
expect((
|
|
184
|
-
expect((
|
|
185
|
-
expect((
|
|
186
|
-
expect((
|
|
187
|
-
expect((
|
|
188
|
-
expect((
|
|
189
|
-
})
|
|
190
|
-
test("should define nested contexts in a schema", () =>
|
|
191
|
-
var
|
|
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;
|
|
192
191
|
const schema = new Schema("my-custom-element");
|
|
193
192
|
schema.addPath({
|
|
194
193
|
rootPropertyName: "a",
|
|
@@ -222,15 +221,15 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
222
221
|
});
|
|
223
222
|
const schemaA = schema.getSchema("a");
|
|
224
223
|
expect(schemaA).toBeDefined();
|
|
225
|
-
expect((
|
|
226
|
-
expect((
|
|
227
|
-
expect((
|
|
228
|
-
expect((
|
|
229
|
-
expect((
|
|
230
|
-
expect((
|
|
231
|
-
})
|
|
232
|
-
test("should define nested contexts with objects in a schema", () =>
|
|
233
|
-
var
|
|
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;
|
|
234
233
|
const schema = new Schema("my-custom-element");
|
|
235
234
|
schema.addPath({
|
|
236
235
|
rootPropertyName: "a",
|
|
@@ -284,30 +283,30 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
284
283
|
});
|
|
285
284
|
const schemaA = schema.getSchema("a");
|
|
286
285
|
expect(schemaA).toBeDefined();
|
|
287
|
-
expect((
|
|
288
|
-
expect((
|
|
289
|
-
expect((
|
|
290
|
-
expect((
|
|
291
|
-
expect((
|
|
292
|
-
expect((
|
|
293
|
-
expect((
|
|
294
|
-
expect((
|
|
295
|
-
expect((
|
|
296
|
-
expect((
|
|
297
|
-
expect((
|
|
298
|
-
expect((
|
|
299
|
-
expect((
|
|
300
|
-
expect((
|
|
301
|
-
expect((
|
|
302
|
-
expect((
|
|
303
|
-
expect((
|
|
304
|
-
expect((
|
|
305
|
-
expect((
|
|
306
|
-
expect((
|
|
307
|
-
expect((
|
|
308
|
-
})
|
|
309
|
-
test("should define an anyOf with a $ref to another schema", () =>
|
|
310
|
-
var
|
|
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;
|
|
311
310
|
const schema = new Schema("my-custom-element");
|
|
312
311
|
schema.addPath({
|
|
313
312
|
rootPropertyName: "a",
|
|
@@ -328,10 +327,10 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
328
327
|
expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
|
|
329
328
|
expect(schemaA.anyOf).not.toBeUndefined();
|
|
330
329
|
expect(schemaA.anyOf).toHaveLength(1);
|
|
331
|
-
expect((
|
|
332
|
-
})
|
|
333
|
-
test("should define an anyOf with a $ref to multiple schemas", () =>
|
|
334
|
-
var
|
|
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;
|
|
335
334
|
const schema = new Schema("my-custom-element");
|
|
336
335
|
schema.addPath({
|
|
337
336
|
rootPropertyName: "a",
|
|
@@ -365,10 +364,10 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
365
364
|
expect(schemaA.$schema).toEqual("https://json-schema.org/draft/2019-09/schema");
|
|
366
365
|
expect(schemaA.anyOf).not.toBeUndefined();
|
|
367
366
|
expect(schemaA.anyOf).toHaveLength(2);
|
|
368
|
-
expect((
|
|
369
|
-
expect((
|
|
370
|
-
})
|
|
371
|
-
test("should define an anyOf with a $ref to another schema in a nested object", () =>
|
|
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 () => {
|
|
372
371
|
const schema = new Schema("my-custom-element");
|
|
373
372
|
schema.addPath({
|
|
374
373
|
rootPropertyName: "a",
|
|
@@ -398,8 +397,8 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
398
397
|
expect(schemaA.properties.b.properties.c).toBeDefined();
|
|
399
398
|
expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
|
|
400
399
|
expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
|
|
401
|
-
})
|
|
402
|
-
test("should define an anyOf with a $ref to multiple schemas in a nested object", () =>
|
|
400
|
+
});
|
|
401
|
+
test("should define an anyOf with a $ref to multiple schemas in a nested object", async () => {
|
|
403
402
|
const schema = new Schema("my-custom-element");
|
|
404
403
|
schema.addPath({
|
|
405
404
|
rootPropertyName: "a",
|
|
@@ -443,9 +442,9 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
443
442
|
expect(schemaA.properties.b.properties.c.anyOf).not.toBeUndefined();
|
|
444
443
|
expect(schemaA.properties.b.properties.c.anyOf[0].$ref).toEqual("https://fast.design/schemas/my-custom-element-2/test.json");
|
|
445
444
|
expect(schemaA.properties.b.properties.c.anyOf[1].$ref).toEqual("https://fast.design/schemas/my-custom-element-3/test-2.json");
|
|
446
|
-
})
|
|
447
|
-
test("should define an anyOf with a $ref in a nested object in a context", () =>
|
|
448
|
-
var
|
|
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;
|
|
449
448
|
const schema = new Schema("my-custom-element");
|
|
450
449
|
schema.addPath({
|
|
451
450
|
rootPropertyName: "a",
|
|
@@ -472,14 +471,14 @@ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
472
471
|
});
|
|
473
472
|
const schemaA = schema.getSchema("a");
|
|
474
473
|
expect(schemaA).toBeDefined();
|
|
475
|
-
expect((
|
|
476
|
-
expect((
|
|
477
|
-
expect((
|
|
478
|
-
expect((
|
|
479
|
-
expect((
|
|
480
|
-
expect((
|
|
481
|
-
expect((
|
|
482
|
-
expect((
|
|
483
|
-
expect((
|
|
484
|
-
})
|
|
485
|
-
})
|
|
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
|
+
});
|