@microsoft/fast-html 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (52) hide show
  1. package/README.md +111 -18
  2. package/dist/dts/components/element.d.ts +10 -0
  3. package/dist/dts/components/index.d.ts +2 -0
  4. package/dist/dts/components/observer-map.d.ts +26 -0
  5. package/dist/dts/components/schema.d.ts +134 -0
  6. package/dist/dts/components/template.d.ts +39 -5
  7. package/dist/dts/components/utilities.d.ts +92 -19
  8. package/dist/dts/fixtures/observer-map/main.d.ts +1 -0
  9. package/dist/dts/fixtures/observer-map/observer-map.spec.d.ts +1 -0
  10. package/dist/dts/index.d.ts +1 -1
  11. package/dist/esm/components/element.js +27 -0
  12. package/dist/esm/components/index.js +2 -0
  13. package/dist/esm/components/observer-map.js +49 -0
  14. package/dist/esm/components/observer-map.spec.js +19 -0
  15. package/dist/esm/components/schema.js +215 -0
  16. package/dist/esm/components/schema.spec.js +257 -0
  17. package/dist/esm/components/template.js +154 -99
  18. package/dist/esm/components/utilities.js +553 -43
  19. package/dist/esm/components/utilities.spec.js +246 -44
  20. package/dist/esm/fixtures/attribute/main.js +3 -2
  21. package/dist/esm/fixtures/binding/binding.spec.js +6 -0
  22. package/dist/esm/fixtures/binding/main.js +13 -2
  23. package/dist/esm/fixtures/children/children.spec.js +4 -0
  24. package/dist/esm/fixtures/children/main.js +3 -2
  25. package/dist/esm/fixtures/dot-syntax/dot-syntax.spec.js +109 -2
  26. package/dist/esm/fixtures/dot-syntax/main.js +30 -4
  27. package/dist/esm/fixtures/event/event.spec.js +28 -5
  28. package/dist/esm/fixtures/event/main.js +21 -5
  29. package/dist/esm/fixtures/observer-map/main.js +304 -0
  30. package/dist/esm/fixtures/observer-map/observer-map.spec.js +174 -0
  31. package/dist/esm/fixtures/ref/main.js +3 -2
  32. package/dist/esm/fixtures/ref/ref.spec.js +2 -6
  33. package/dist/esm/fixtures/repeat/main.js +27 -2
  34. package/dist/esm/fixtures/repeat/repeat.spec.js +16 -6
  35. package/dist/esm/fixtures/slotted/main.js +15 -4
  36. package/dist/esm/fixtures/slotted/slotted.spec.js +18 -19
  37. package/dist/esm/fixtures/when/main.js +139 -2
  38. package/dist/esm/fixtures/when/when.spec.js +64 -1
  39. package/dist/esm/index.js +1 -1
  40. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  41. package/dist/fast-html.api.json +279 -0
  42. package/dist/fast-html.d.ts +219 -5
  43. package/dist/fast-html.untrimmed.d.ts +219 -5
  44. package/package.json +12 -9
  45. package/rules/attribute-directives.yml +38 -0
  46. package/rules/call-expression-with-event-argument.yml +41 -0
  47. package/rules/member-expression.yml +33 -0
  48. package/rules/tag-function-to-template-literal.yml +16 -0
  49. package/dist/esm/fixtures/partial/main.js +0 -31
  50. package/dist/esm/fixtures/partial/partial.spec.js +0 -14
  51. /package/dist/dts/{fixtures/partial/main.d.ts → components/observer-map.spec.d.ts} +0 -0
  52. /package/dist/dts/{fixtures/partial/partial.spec.d.ts → components/schema.spec.d.ts} +0 -0
@@ -0,0 +1,49 @@
1
+ import { Observable } from "@microsoft/fast-element/observable.js";
2
+ import { assignObservables } from "./utilities.js";
3
+ /**
4
+ * ObserverMap provides functionality for caching binding paths, extracting root properties,
5
+ * and defining observable properties on class prototypes
6
+ */
7
+ export class ObserverMap {
8
+ constructor(classPrototype, schema) {
9
+ /**
10
+ * Creates a property change handler function for observable properties
11
+ * This handler is called when an observable property transitions from undefined to a defined value
12
+ * @param propertyName - The name of the property for which to create the change handler
13
+ * @returns A function that handles property changes and sets up proxies for object values
14
+ */
15
+ this.defineChanged = (propertyName) => {
16
+ const getAndAssignObservablesAlias = this.getAndAssignObservables;
17
+ const schema = this.schema;
18
+ function instanceResolverChanged(prev, next) {
19
+ if (prev === undefined && next !== undefined) {
20
+ const proxy = getAndAssignObservablesAlias(this, propertyName, next, schema);
21
+ this[propertyName] = proxy;
22
+ }
23
+ }
24
+ return instanceResolverChanged;
25
+ };
26
+ this.classPrototype = classPrototype;
27
+ this.schema = schema;
28
+ }
29
+ defineProperties() {
30
+ const propertyNames = this.schema.getRootProperties();
31
+ for (const propertyName of propertyNames) {
32
+ Observable.defineProperty(this.classPrototype, propertyName);
33
+ this.classPrototype[`${propertyName}Changed`] =
34
+ this.defineChanged(propertyName);
35
+ }
36
+ }
37
+ /**
38
+ * Creates a proxy for an object that intercepts property mutations and triggers Observable notifications
39
+ * @param target - The target instance that owns the root property
40
+ * @param rootProperty - The name of the root property for notification purposes
41
+ * @param object - The object to wrap with a proxy
42
+ * @returns A proxy that triggers notifications on property mutations
43
+ */
44
+ getAndAssignObservables(target, rootProperty, object, schema) {
45
+ let proxiedObject = object;
46
+ proxiedObject = assignObservables(schema.getSchema(rootProperty), schema.getSchema(rootProperty), proxiedObject, target, rootProperty);
47
+ return proxiedObject;
48
+ }
49
+ }
@@ -0,0 +1,19 @@
1
+ import { __awaiter } from "tslib";
2
+ import { expect, test } from "@playwright/test";
3
+ import { ObserverMap } from "./observer-map.js";
4
+ import { Schema } from "./schema.js";
5
+ test.describe("ObserverMap", () => __awaiter(void 0, void 0, void 0, function* () {
6
+ let observerMap;
7
+ let schema = new Schema("test-class");
8
+ class TestClass {
9
+ }
10
+ test.beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
11
+ // Use TestClass.prototype so instances will have the observable properties
12
+ observerMap = new ObserverMap(TestClass.prototype, schema);
13
+ }));
14
+ test("should create new instances", () => __awaiter(void 0, void 0, void 0, function* () {
15
+ const instance1 = new ObserverMap(TestClass.prototype, schema);
16
+ const instance2 = new ObserverMap(TestClass.prototype, schema);
17
+ expect(instance1).not.toBe(instance2);
18
+ }));
19
+ }));
@@ -0,0 +1,215 @@
1
+ // The context, in most cases the array property e.g. users
2
+ export const fastContextMetaData = "$fast_context";
3
+ // The list of contexts preceeding this context, the first of which should be the root property
4
+ export const fastContextsMetaData = "$fast_parent_contexts";
5
+ export const defsPropertyName = "$defs";
6
+ export const refPropertyName = "$ref";
7
+ /**
8
+ * A constructed JSON schema from a template
9
+ */
10
+ export class Schema {
11
+ constructor(name) {
12
+ /**
13
+ * A JSON schema describing each root schema
14
+ */
15
+ this.jsonSchemaMap = new Map();
16
+ this.customElementName = name;
17
+ }
18
+ /**
19
+ * Add a path to a schema
20
+ * @param config RegisterPathConfig
21
+ */
22
+ addPath(config) {
23
+ var _a, _b, _c;
24
+ const splitPath = this.getSplitPath(config.pathConfig.path);
25
+ let schema = this.jsonSchemaMap.get(config.rootPropertyName);
26
+ // Create a root level property JSON
27
+ if (!schema) {
28
+ this.addNewSchema(config.rootPropertyName);
29
+ schema = this.jsonSchemaMap.get(config.rootPropertyName);
30
+ }
31
+ switch (config.pathConfig.type) {
32
+ case "default":
33
+ case "access": {
34
+ if (splitPath.length > 1) {
35
+ if (config.pathConfig.currentContext === null) {
36
+ this.addPropertiesToAnObject(schema, splitPath.slice(1), config.pathConfig.currentContext);
37
+ }
38
+ else {
39
+ if (!((_a = schema[defsPropertyName]) === null || _a === void 0 ? void 0 : _a[splitPath[0]])) {
40
+ schema[defsPropertyName] = {
41
+ [splitPath[0]]: {},
42
+ };
43
+ }
44
+ this.addPropertiesToAContext(schema[defsPropertyName][splitPath[0]], splitPath.slice(1), config.pathConfig.currentContext);
45
+ }
46
+ }
47
+ break;
48
+ }
49
+ case "repeat": {
50
+ this.addContext(schema, splitPath.at(-1), // example items
51
+ config.pathConfig.currentContext, // example item
52
+ config.pathConfig.parentContext);
53
+ if (splitPath.length > 2) {
54
+ let updatedSchema = schema;
55
+ const hasParentContext = !!config.pathConfig.parentContext;
56
+ if (hasParentContext) {
57
+ updatedSchema = this.addPropertiesToAnObject((_b = schema[defsPropertyName]) === null || _b === void 0 ? void 0 : _b[config.pathConfig.parentContext], splitPath.slice(1, -1), config.pathConfig.parentContext);
58
+ }
59
+ this.addPropertiesToAnObject(updatedSchema, hasParentContext ? splitPath.slice(2) : splitPath.slice(1), config.pathConfig.currentContext, "array");
60
+ }
61
+ else if (splitPath.length > 1) {
62
+ let schemaDefinition;
63
+ if (config.pathConfig.parentContext) {
64
+ schemaDefinition = (_c = schema === null || schema === void 0 ? void 0 : schema[defsPropertyName]) === null || _c === void 0 ? void 0 : _c[config.pathConfig.parentContext];
65
+ }
66
+ this.addPropertiesToAnObject(schemaDefinition !== null && schemaDefinition !== void 0 ? schemaDefinition : schema, splitPath.slice(1), config.pathConfig.currentContext, "array");
67
+ }
68
+ else {
69
+ schema.type = "array";
70
+ schema[refPropertyName] = this.getDefsPath(config.pathConfig.currentContext);
71
+ }
72
+ break;
73
+ }
74
+ }
75
+ }
76
+ /**
77
+ * Gets the JSON schema for a property name
78
+ * @param rootPropertyName - the root property the JSON schema is mapped to
79
+ * @returns The JSON schema for the root property
80
+ */
81
+ getSchema(rootPropertyName) {
82
+ var _a;
83
+ return (_a = this.jsonSchemaMap.get(rootPropertyName)) !== null && _a !== void 0 ? _a : null;
84
+ }
85
+ /**
86
+ * Gets root properties
87
+ * @returns IterableIterator<string>
88
+ */
89
+ getRootProperties() {
90
+ return this.jsonSchemaMap.keys();
91
+ }
92
+ /**
93
+ * Get a path split into property names
94
+ * @param path The dot syntax path e.g. a.b.c
95
+ * @returns An array of items in the path
96
+ */
97
+ getSplitPath(path) {
98
+ return path.split(".");
99
+ }
100
+ /**
101
+ * Gets the path to the $def
102
+ * @param context The context name e.g. {{item in items}} in a repeat creates the "item" context
103
+ * @returns A string to use as a $ref
104
+ */
105
+ getDefsPath(context) {
106
+ return `#/${defsPropertyName}/${context}`;
107
+ }
108
+ /**
109
+ * Add a new JSON schema to the JSON schema map
110
+ * @param propertyName The name of the property to assign this JSON schema to
111
+ */
112
+ addNewSchema(propertyName) {
113
+ this.jsonSchemaMap.set(propertyName, {
114
+ $schema: "https://json-schema.org/draft/2019-09/schema",
115
+ $id: `https://fast.design/schemas/${this.customElementName}/${propertyName}.json`,
116
+ [defsPropertyName]: {},
117
+ });
118
+ }
119
+ /**
120
+ * Add properties to a context
121
+ * @param schema The schema to add the properties to
122
+ * @param splitPath The path split into property/context names
123
+ * @param context The paths context
124
+ */
125
+ addPropertiesToAContext(schema, splitPath, context) {
126
+ schema.type = "object";
127
+ if (schema.properties && !schema.properties[splitPath[0]]) {
128
+ schema.properties[splitPath[0]] = {};
129
+ }
130
+ else if (!schema.properties) {
131
+ schema.properties = {
132
+ [splitPath[0]]: {},
133
+ };
134
+ }
135
+ if (splitPath.length > 1) {
136
+ this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context);
137
+ }
138
+ }
139
+ /**
140
+ * Add properties to an object
141
+ * @param schema The schema to add the properties to
142
+ * @param splitPath The path split into property/context names
143
+ * @param context The paths context
144
+ * @param type The data type (see JSON schema for details)
145
+ */
146
+ addPropertiesToAnObject(schema, splitPath, context, type = "object") {
147
+ schema.type = "object";
148
+ if (schema.properties && !schema.properties[splitPath[0]]) {
149
+ schema.properties[splitPath[0]] = {};
150
+ }
151
+ else if (!schema.properties) {
152
+ schema.properties = {
153
+ [splitPath[0]]: {},
154
+ };
155
+ }
156
+ if (type === "object" && splitPath.length > 1) {
157
+ return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, type);
158
+ }
159
+ else if (type === "array") {
160
+ if (splitPath.length > 1) {
161
+ return this.addPropertiesToAnObject(schema.properties[splitPath[0]], splitPath.slice(1), context, type);
162
+ }
163
+ else {
164
+ return this.addArrayToAnObject(schema.properties[splitPath[0]], context);
165
+ }
166
+ }
167
+ return schema.properties[splitPath[0]];
168
+ }
169
+ /**
170
+ * Add an array to an object property
171
+ * @param schema The schema to add the properties to
172
+ * @param context The name of the context
173
+ */
174
+ addArrayToAnObject(schema, context) {
175
+ schema.type = "array";
176
+ schema.items = {
177
+ [refPropertyName]: this.getDefsPath(context),
178
+ };
179
+ return schema.items;
180
+ }
181
+ /**
182
+ * Add a context to the $defs property
183
+ * @param schema The schema to use
184
+ * @param propertyName The name of the property the context belongs to
185
+ * @param currentContext The current context
186
+ * @param parentContext The parent context
187
+ * @returns
188
+ */
189
+ addContext(schema, propertyName, // e.g items
190
+ currentContext, // e.g. item
191
+ parentContext) {
192
+ if (schema[defsPropertyName][currentContext]) {
193
+ return;
194
+ }
195
+ schema[defsPropertyName][currentContext] = {
196
+ [fastContextMetaData]: propertyName,
197
+ [fastContextsMetaData]: this.getParentContexts(schema, parentContext),
198
+ };
199
+ }
200
+ /**
201
+ * Get parent contexts
202
+ * @param schema The schema to use
203
+ * @param parentContext The parent context
204
+ * @param contexts A list of parent contexts
205
+ * @returns
206
+ */
207
+ getParentContexts(schema, parentContext, contexts = []) {
208
+ var _a;
209
+ if (parentContext === null) {
210
+ return [null, ...contexts];
211
+ }
212
+ const parentParentContext = (_a = schema === null || schema === void 0 ? void 0 : schema[defsPropertyName]) === null || _a === void 0 ? void 0 : _a[parentContext][fastContextsMetaData];
213
+ return this.getParentContexts(schema, parentParentContext.at(-1), [parentContext, ...contexts]);
214
+ }
215
+ }
@@ -0,0 +1,257 @@
1
+ import { __awaiter } from "tslib";
2
+ import { expect, test } from "@playwright/test";
3
+ import { Schema } from "./schema.js";
4
+ test.describe("Schema", () => __awaiter(void 0, void 0, void 0, function* () {
5
+ test("should instantiate with a custom element name without throwing", () => __awaiter(void 0, void 0, void 0, function* () {
6
+ 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", () => __awaiter(void 0, void 0, void 0, function* () {
9
+ const schema = new Schema("my-custom-element");
10
+ expect(schema.getSchema("foo")).toEqual(null);
11
+ }));
12
+ test("should be able to return a JSON schema after adding a path", () => __awaiter(void 0, void 0, void 0, function* () {
13
+ const schema = new Schema("my-custom-element");
14
+ schema.addPath({
15
+ rootPropertyName: "a",
16
+ pathConfig: {
17
+ type: "default",
18
+ path: "a",
19
+ currentContext: null,
20
+ parentContext: null,
21
+ }
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", () => __awaiter(void 0, void 0, void 0, function* () {
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
+ });
39
+ let schemaA = schema.getSchema("a");
40
+ expect(schemaA.properties).toBeDefined();
41
+ expect(schemaA.properties).toHaveProperty("b");
42
+ schema.addPath({
43
+ rootPropertyName: "a",
44
+ pathConfig: {
45
+ type: "default",
46
+ path: "a.b.c",
47
+ currentContext: null,
48
+ parentContext: null,
49
+ },
50
+ });
51
+ schemaA = schema.getSchema("a");
52
+ expect(schemaA.properties).toBeDefined();
53
+ expect(schemaA.properties).toHaveProperty("b");
54
+ expect(schemaA.properties.b.properties).toBeDefined();
55
+ expect(schemaA.properties.b.properties).toHaveProperty("c");
56
+ }));
57
+ test("should add a new context in a schema", () => __awaiter(void 0, void 0, void 0, function* () {
58
+ var _a, _b, _c;
59
+ const schema = new Schema("my-custom-element");
60
+ schema.addPath({
61
+ rootPropertyName: "items",
62
+ pathConfig: {
63
+ type: "repeat",
64
+ path: "items",
65
+ currentContext: "item",
66
+ parentContext: null,
67
+ },
68
+ });
69
+ const schemaA = schema.getSchema("items");
70
+ expect(schemaA).toBeDefined();
71
+ expect(schemaA.$ref).toBeDefined();
72
+ expect(schemaA.$ref).toEqual("#/$defs/item");
73
+ expect(schemaA.type).toEqual("array");
74
+ expect((_a = schemaA.$defs) === null || _a === void 0 ? void 0 : _a["item"]).toBeDefined();
75
+ expect((_b = schemaA.$defs) === null || _b === void 0 ? void 0 : _b["item"].$fast_context).toEqual("items");
76
+ expect((_c = schemaA.$defs) === null || _c === void 0 ? void 0 : _c["item"].$fast_parent_contexts).toEqual([null]);
77
+ }));
78
+ test("should add a nested context in a schema", () => __awaiter(void 0, void 0, void 0, function* () {
79
+ var _d, _e, _f, _g, _h;
80
+ const schema = new Schema("my-custom-element");
81
+ schema.addPath({
82
+ rootPropertyName: "a",
83
+ pathConfig: {
84
+ type: "default",
85
+ path: "a",
86
+ currentContext: null,
87
+ parentContext: null,
88
+ },
89
+ });
90
+ schema.addPath({
91
+ rootPropertyName: "a",
92
+ pathConfig: {
93
+ type: "repeat",
94
+ path: "a.items",
95
+ currentContext: "item",
96
+ parentContext: null,
97
+ },
98
+ });
99
+ const schemaA = schema.getSchema("a");
100
+ expect(schemaA).toBeDefined();
101
+ expect((_d = schemaA === null || schemaA === void 0 ? void 0 : schemaA.properties) === null || _d === void 0 ? void 0 : _d["items"]).toBeDefined();
102
+ expect((_e = schemaA === null || schemaA === void 0 ? void 0 : schemaA.properties) === null || _e === void 0 ? void 0 : _e["items"].items.$ref).toEqual("#/$defs/item");
103
+ expect((_f = schemaA.$defs) === null || _f === void 0 ? void 0 : _f["item"]).toBeDefined();
104
+ expect((_g = schemaA.$defs) === null || _g === void 0 ? void 0 : _g["item"].$fast_context).toEqual("items");
105
+ expect((_h = schemaA.$defs) === null || _h === void 0 ? void 0 : _h["item"].$fast_parent_contexts).toEqual([null]);
106
+ }));
107
+ test("should define an object as a nested context in a schema", () => __awaiter(void 0, void 0, void 0, function* () {
108
+ var _j, _k, _l, _m, _o, _p, _q;
109
+ const schema = new Schema("my-custom-element");
110
+ schema.addPath({
111
+ rootPropertyName: "a",
112
+ pathConfig: {
113
+ type: "default",
114
+ path: "a",
115
+ currentContext: null,
116
+ parentContext: null,
117
+ },
118
+ });
119
+ schema.addPath({
120
+ rootPropertyName: "a",
121
+ pathConfig: {
122
+ type: "repeat",
123
+ path: "a.items",
124
+ currentContext: "item",
125
+ parentContext: null,
126
+ },
127
+ });
128
+ schema.addPath({
129
+ rootPropertyName: "a",
130
+ pathConfig: {
131
+ type: "access",
132
+ path: "item.b",
133
+ currentContext: "item",
134
+ parentContext: null,
135
+ },
136
+ });
137
+ const schemaA = schema.getSchema("a");
138
+ expect(schemaA).toBeDefined();
139
+ expect((_j = schemaA.$defs) === null || _j === void 0 ? void 0 : _j["item"]).toBeDefined();
140
+ expect((_k = schemaA.$defs) === null || _k === void 0 ? void 0 : _k["item"].$fast_context).toEqual("items");
141
+ expect((_l = schemaA.$defs) === null || _l === void 0 ? void 0 : _l["item"].$fast_parent_contexts).toEqual([null]);
142
+ expect((_m = schemaA.$defs) === null || _m === void 0 ? void 0 : _m["item"].type).toEqual("object");
143
+ expect((_o = schemaA.$defs) === null || _o === void 0 ? void 0 : _o["item"].properties).toBeDefined();
144
+ expect((_q = (_p = schemaA.$defs) === null || _p === void 0 ? void 0 : _p["item"].properties) === null || _q === void 0 ? void 0 : _q["b"]).toBeDefined();
145
+ }));
146
+ test("should define nested contexts in a schema", () => __awaiter(void 0, void 0, void 0, function* () {
147
+ var _r, _s, _t, _u, _v, _w;
148
+ const schema = new Schema("my-custom-element");
149
+ schema.addPath({
150
+ rootPropertyName: "a",
151
+ pathConfig: {
152
+ type: "default",
153
+ path: "a",
154
+ currentContext: null,
155
+ parentContext: null,
156
+ },
157
+ });
158
+ schema.addPath({
159
+ rootPropertyName: "a",
160
+ pathConfig: {
161
+ type: "repeat",
162
+ path: "a.users",
163
+ currentContext: "user",
164
+ parentContext: null,
165
+ },
166
+ });
167
+ schema.addPath({
168
+ rootPropertyName: "a",
169
+ pathConfig: {
170
+ type: "repeat",
171
+ path: "user.posts",
172
+ currentContext: "post",
173
+ parentContext: "user"
174
+ },
175
+ });
176
+ const schemaA = schema.getSchema("a");
177
+ expect(schemaA).toBeDefined();
178
+ expect((_r = schemaA.$defs) === null || _r === void 0 ? void 0 : _r["user"]).toBeDefined();
179
+ expect((_s = schemaA.$defs) === null || _s === void 0 ? void 0 : _s["user"].$fast_context).toEqual("users");
180
+ expect((_t = schemaA.$defs) === null || _t === void 0 ? void 0 : _t["user"].$fast_parent_contexts).toEqual([null]);
181
+ expect((_u = schemaA.$defs) === null || _u === void 0 ? void 0 : _u["post"]).toBeDefined();
182
+ expect((_v = schemaA.$defs) === null || _v === void 0 ? void 0 : _v["post"].$fast_context).toEqual("posts");
183
+ expect((_w = schemaA.$defs) === null || _w === void 0 ? void 0 : _w["post"].$fast_parent_contexts).toEqual([null, "user"]);
184
+ }));
185
+ test("should define nested contexts with objects in a schema", () => __awaiter(void 0, void 0, void 0, function* () {
186
+ var _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17;
187
+ const schema = new Schema("my-custom-element");
188
+ schema.addPath({
189
+ rootPropertyName: "a",
190
+ pathConfig: {
191
+ type: "repeat",
192
+ path: "a.users",
193
+ currentContext: "user",
194
+ parentContext: null,
195
+ },
196
+ });
197
+ schema.addPath({
198
+ rootPropertyName: "a",
199
+ pathConfig: {
200
+ type: "access",
201
+ path: "user.a.b",
202
+ currentContext: "user",
203
+ parentContext: null,
204
+ },
205
+ });
206
+ schema.addPath({
207
+ rootPropertyName: "a",
208
+ pathConfig: {
209
+ type: "repeat",
210
+ path: "user.posts",
211
+ currentContext: "post",
212
+ parentContext: "user"
213
+ },
214
+ });
215
+ schema.addPath({
216
+ rootPropertyName: "a",
217
+ pathConfig: {
218
+ type: "access",
219
+ path: "post.c.d",
220
+ currentContext: "post",
221
+ parentContext: null,
222
+ },
223
+ });
224
+ schema.addPath({
225
+ rootPropertyName: "a",
226
+ pathConfig: {
227
+ type: "repeat",
228
+ path: "post.meta.tags",
229
+ currentContext: "tag",
230
+ parentContext: "post"
231
+ },
232
+ });
233
+ const schemaA = schema.getSchema("a");
234
+ expect(schemaA).toBeDefined();
235
+ expect((_x = schemaA.$defs) === null || _x === void 0 ? void 0 : _x["user"]).toBeDefined();
236
+ expect((_y = schemaA.$defs) === null || _y === void 0 ? void 0 : _y["user"].$fast_context).toEqual("users");
237
+ expect((_z = schemaA.$defs) === null || _z === void 0 ? void 0 : _z["user"].$fast_parent_contexts).toEqual([null]);
238
+ expect((_0 = schemaA.$defs) === null || _0 === void 0 ? void 0 : _0["user"].type).toEqual("object");
239
+ expect((_1 = schemaA.$defs) === null || _1 === void 0 ? void 0 : _1["user"].properties).toBeDefined();
240
+ expect((_2 = schemaA.$defs) === null || _2 === void 0 ? void 0 : _2["user"].properties["a"]).toBeDefined();
241
+ expect((_3 = schemaA.$defs) === null || _3 === void 0 ? void 0 : _3["user"].properties["a"].properties["b"]).toBeDefined();
242
+ expect((_4 = schemaA.$defs) === null || _4 === void 0 ? void 0 : _4["post"]).toBeDefined();
243
+ expect((_5 = schemaA.$defs) === null || _5 === void 0 ? void 0 : _5["post"].$fast_context).toEqual("posts");
244
+ expect((_6 = schemaA.$defs) === null || _6 === void 0 ? void 0 : _6["post"].$fast_parent_contexts).toEqual([null, "user"]);
245
+ expect((_7 = schemaA.$defs) === null || _7 === void 0 ? void 0 : _7["post"].type).toEqual("object");
246
+ expect((_8 = schemaA.$defs) === null || _8 === void 0 ? void 0 : _8["post"].properties).toBeDefined();
247
+ expect((_9 = schemaA.$defs) === null || _9 === void 0 ? void 0 : _9["post"].properties["c"]).toBeDefined();
248
+ expect((_10 = schemaA.$defs) === null || _10 === void 0 ? void 0 : _10["post"].properties["c"].properties["d"]).toBeDefined();
249
+ expect((_11 = schemaA.$defs) === null || _11 === void 0 ? void 0 : _11["post"].properties["meta"]).toBeDefined();
250
+ expect((_12 = schemaA.$defs) === null || _12 === void 0 ? void 0 : _12["post"].properties["meta"].properties["tags"]).toBeDefined();
251
+ expect((_13 = schemaA.$defs) === null || _13 === void 0 ? void 0 : _13["post"].properties["meta"].properties["tags"].items).toBeDefined();
252
+ expect((_14 = schemaA.$defs) === null || _14 === void 0 ? void 0 : _14["post"].properties["meta"].properties["tags"].items.$ref).toEqual("#/$defs/tag");
253
+ expect((_15 = schemaA.$defs) === null || _15 === void 0 ? void 0 : _15["tag"]).toBeDefined();
254
+ expect((_16 = schemaA.$defs) === null || _16 === void 0 ? void 0 : _16["tag"].$fast_context).toEqual("tags");
255
+ expect((_17 = schemaA.$defs) === null || _17 === void 0 ? void 0 : _17["tag"].$fast_parent_contexts).toEqual([null, "user", "post"]);
256
+ }));
257
+ }));