@warp-drive-mirror/schema-record 5.4.0-alpha.150 → 5.4.0-alpha.151

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive-mirror/schema-record",
3
- "version": "5.4.0-alpha.150",
3
+ "version": "5.4.0-alpha.151",
4
4
  "description": "Schema Driven Resource Presentation for WarpDrive and EmberData",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -38,11 +38,11 @@
38
38
  },
39
39
  "peerDependencies": {
40
40
  "ember-source": "3.28.12 || ^4.0.4 || ^5.0.0 || ^6.0.0",
41
- "@ember-data-mirror/request": "5.4.0-alpha.150",
42
- "@ember-data-mirror/model": "5.4.0-alpha.150",
43
- "@ember-data-mirror/store": "5.4.0-alpha.150",
44
- "@ember-data-mirror/tracking": "5.4.0-alpha.150",
45
- "@warp-drive-mirror/core-types": "5.4.0-alpha.150"
41
+ "@ember-data-mirror/request": "5.4.0-alpha.151",
42
+ "@ember-data-mirror/model": "5.4.0-alpha.151",
43
+ "@ember-data-mirror/store": "5.4.0-alpha.151",
44
+ "@ember-data-mirror/tracking": "5.4.0-alpha.151",
45
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.151"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@ember-data-mirror/model": {
@@ -51,23 +51,23 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@embroider/macros": "^1.16.11",
54
- "@warp-drive-mirror/build-config": "5.4.0-alpha.150"
54
+ "@warp-drive-mirror/build-config": "5.4.0-alpha.151"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@babel/core": "^7.26.9",
58
58
  "@babel/plugin-transform-typescript": "^7.26.8",
59
59
  "@babel/preset-env": "^7.26.9",
60
60
  "@babel/preset-typescript": "^7.26.0",
61
- "@ember-data-mirror/request": "5.4.0-alpha.150",
62
- "@ember-data-mirror/model": "5.4.0-alpha.150",
63
- "@ember-data-mirror/store": "5.4.0-alpha.150",
64
- "@ember-data-mirror/legacy-compat": "5.4.0-alpha.150",
65
- "@ember-data-mirror/tracking": "5.4.0-alpha.150",
66
- "@ember-data-mirror/request-utils": "5.4.0-alpha.150",
61
+ "@ember-data-mirror/request": "5.4.0-alpha.151",
62
+ "@ember-data-mirror/model": "5.4.0-alpha.151",
63
+ "@ember-data-mirror/store": "5.4.0-alpha.151",
64
+ "@ember-data-mirror/legacy-compat": "5.4.0-alpha.151",
65
+ "@ember-data-mirror/tracking": "5.4.0-alpha.151",
66
+ "@ember-data-mirror/request-utils": "5.4.0-alpha.151",
67
67
  "@ember/test-waiters": "^3.1.0",
68
68
  "@glimmer/component": "^1.1.2",
69
- "@warp-drive-mirror/core-types": "5.4.0-alpha.150",
70
- "@warp-drive/internal-config": "5.4.0-alpha.150",
69
+ "@warp-drive-mirror/core-types": "5.4.0-alpha.151",
70
+ "@warp-drive/internal-config": "5.4.0-alpha.151",
71
71
  "ember-source": "~5.12.0",
72
72
  "vite": "^5.4.14"
73
73
  },
@@ -10,8 +10,39 @@ declare module '@warp-drive-mirror/schema-record/-private/schema' {
10
10
  /**
11
11
  * Utility for constructing a ResourceSchema with the recommended fields
12
12
  * for the Polaris experience.
13
+ *
14
+ * @method withDefaults
15
+ * @for @warp-drive-mirror/schema-record
16
+ * @static
17
+ * @public
18
+ * @param schema
19
+ * @return {ResourceSchema}
13
20
  */
14
21
  export function withDefaults(schema: WithPartial<ResourceSchema, 'identity'>): ResourceSchema;
22
+ /**
23
+ * A derivation that computes its value from the
24
+ * record's identity.
25
+ *
26
+ * It can be used via a derived field definition like:
27
+ *
28
+ * ```ts
29
+ * {
30
+ * kind: 'derived',
31
+ * name: 'id',
32
+ * type: '@identity',
33
+ * options: { key: 'id' }
34
+ * }
35
+ * ```
36
+ *
37
+ * Valid keys are `'id'`, `'lid'`, `'type'`, and `'^'`.
38
+ *
39
+ * `^` returns the entire identifier object.
40
+ *
41
+ * @method fromIdentity
42
+ * @for @warp-drive-mirror/schema-record
43
+ * @static
44
+ * @public
45
+ */
15
46
  export function fromIdentity(record: SchemaRecord, options: {
16
47
  key: 'lid';
17
48
  } | {
@@ -25,6 +56,15 @@ declare module '@warp-drive-mirror/schema-record/-private/schema' {
25
56
  }, key: string): StableRecordIdentifier;
26
57
  export function fromIdentity(record: SchemaRecord, options: null, key: string): asserts options;
27
58
  export namespace fromIdentity { }
59
+ /**
60
+ * Registers the default derivations for the SchemaRecord
61
+ *
62
+ * @method registerDerivations
63
+ * @for @warp-drive-mirror/schema-record
64
+ * @static
65
+ * @public
66
+ * @param {SchemaService} schema
67
+ */
28
68
  export function registerDerivations(schema: SchemaServiceInterface): void;
29
69
  interface InternalSchema {
30
70
  original: ResourceSchema | ObjectSchema;
@@ -48,6 +88,12 @@ declare module '@warp-drive-mirror/schema-record/-private/schema' {
48
88
  type: string;
49
89
  }): InternalSchema['relationships'];
50
90
  }
91
+ /**
92
+ * A SchemaService designed to work with dynamically registered schemas.
93
+ *
94
+ * @class SchemaService
95
+ * @public
96
+ */
51
97
  export class SchemaService implements SchemaServiceInterface {
52
98
  _schemas: Map<string, InternalSchema>;
53
99
  _transforms: Map<string, Transformation>;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/-private/schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,IAAI,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAMvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EAGd,KAAK,oBAAoB,EACzB,KA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AA;KAAE,GAAG,UAAU;IAiB9D,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAiBnD,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,GAAG,YAAY;IAI5F,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,cAAc,GAAG,YAAY,CAAC,GAAG,IAAI;IAKtE,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,GAAG,IAAI;IA4B7D,sBAAsB,CAAC,CAAC,SAAS,KAAK,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI;IAI3G,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,WAAW,GAAG,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI;IAI/F,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;IAIzD,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,CAAC,QAAQ,CAAC;IAU5D,WAAW,CAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;CAGjD"}
@@ -8,6 +8,343 @@
8
8
  /// <reference path="./-private/fields/many-array-manager.d.ts" />
9
9
  /// <reference path="./-private/fields/compute.d.ts" />
10
10
  declare module '@warp-drive-mirror/schema-record' {
11
+ /**
12
+ * <h3 align="center">Your Data, Managed.</h3>
13
+ * <p align="center">🌲 Get back to Nature 🐿️ Or shipping 💚</p>
14
+ *
15
+ * SchemaRecord is a reactive object that transforms raw data from an [associated cache](../classes/<Interface>%20Cache)
16
+ * into reactive data backed by Signals. The shape of the object and the transformation of raw cache data into its
17
+ * reactive form is controlled by a resource schema. Resource schemas are simple JSON, allowing them to be defined
18
+ * and delivered from anywhere.
19
+ *
20
+ * The capabilities that SchemaRecord brings to [*Warp***Drive**](https://github.com/emberjs/data/)
21
+ * will simplify even the most complex parts of your app's state management.
22
+ *
23
+ * ## Installation
24
+ *
25
+ * Install using your javascript package manager of choice. For instance
26
+ * with [pnpm](https://pnpm.io/)
27
+ *
28
+ * ```cli
29
+ * pnpm add @warp-drive-mirror/schema-record
30
+ * ```
31
+ *
32
+ *
33
+ * ---
34
+ *
35
+ *
36
+ * ## Getting Started
37
+ *
38
+ * If this package is how you are first learning about WarpDrive/EmberData, we
39
+ * recommend starting with learning about [Requests](../modules/@ember-data%2Frequest)
40
+ * and the [Store](../modules/@ember-data%2Fstore).
41
+ *
42
+ *
43
+ * ---
44
+ *
45
+ *
46
+ * ## 🚀 Setup
47
+ *
48
+ * SchemaRecord integrates with WarpDrive via the Store's resource lifecycle hooks.
49
+ * When WarpDrive needs to create a new record instance to give reactive access to
50
+ * a resource in the cache, it calls `instantiateRecord`. When it no longer needs
51
+ * that instance, it will call `teardownRecord`.
52
+ *
53
+ * ```diff
54
+ * import Store from '@ember-data-mirror/store';
55
+ * +import { instantiateRecord, teardownRecord, registerDerivations, SchemaService } from '@warp-drive-mirror/schema-record';
56
+ *
57
+ * class AppStore extends Store {
58
+ *
59
+ * + createSchemaService() {
60
+ * + const schema = new SchemaService();
61
+ * + registerDerivations(schema);
62
+ * + return schema;
63
+ * + }
64
+ *
65
+ * + instantiateRecord(identifier, createArgs) {
66
+ * + return instantiateRecord(this, identifier, createArgs);
67
+ * + }
68
+ *
69
+ * + teardownRecord(record) {
70
+ * + return teardownRecord(record);
71
+ * + }
72
+ * }
73
+ * ```
74
+ *
75
+ * Any Store API that returns a record instance will use the `instantiateRecord`
76
+ * hook configured above to instantiate a SchemaRecord once this is in place.
77
+ * After that, its up to you what SchemaRecord can do.
78
+ *
79
+ *
80
+ * ---
81
+ *
82
+ *
83
+ * ## Start Using
84
+ *
85
+ * ### Modes
86
+ *
87
+ * SchemaRecord has two modes: `legacy` and `polaris`.
88
+ *
89
+ * **LegacyMode** can be used to emulate the behaviors and capabilities of EmberData's `Model` class,
90
+ * and because there is little distinction between Model and SchemaRecord in LegacyMode we refer
91
+ * to both of these approaches as LegacyMode. This mode is the default experience in V5.
92
+ *
93
+ * In LegacyMode:
94
+ *
95
+ * - records are mutable
96
+ * - local changes immediately reflect app wide
97
+ * - records have all the APIs of Model (references, state props, currentState, methods etc)
98
+ * - the continued use of `@ember-data-mirror/model` and `@ember-data-mirror/legacy-compat` packages is required (though most imports from them can be removed)
99
+ * - `async: true` relationships are supported (but not recommended outside of [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
100
+ *
101
+ * ---
102
+ *
103
+ * **PolarisMode** is an upcoming suite of features that will become the default experience in V6.
104
+ *
105
+ * In PolarisMode:
106
+ *
107
+ * - records are immutable, unless creating a new resource or explicitly checking out a record for editing
108
+ * - local changes are isolated until committed, displaying only via the editable version of the record
109
+ * - records have a more limited API, focused on only what is in their schema.
110
+ * - some common operations may have more friction to perform because intended utilities are not yet available
111
+ * - `async: true` relationships are not supported (see [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
112
+ * - `@ember-data-mirror/model` and `@ember-data-mirror/legacy-compat` packages are not required
113
+ *
114
+ * These modes are interopable. The reactive object (record) for a resource in PolarisMode can relate to
115
+ * a record in LegacyMode and vice-versa. This interopability is true whether the record in LegacyMode is
116
+ * a SchemaRecord or a Model.
117
+ *
118
+ * ---
119
+ *
120
+ * ### About
121
+ *
122
+ * SchemaRecord is a reactive object that transforms raw data from an associated
123
+ * cache into reactive data backed by Signals.
124
+ *
125
+ * The shape of the object and the transformation of raw cache data into its
126
+ * reactive form is controlled by a resource schema.
127
+ *
128
+ * For instance, lets say your API is a [{JSON:API}](https://jsonapi.org) and your store is using
129
+ * the Cache provided by [@ember-data-mirror/json-api](../modules/@ember-data%2Fjson-api), and a request
130
+ * returns the following raw data:
131
+ *
132
+ * ```ts
133
+ * {
134
+ * data: {
135
+ * type: 'user',
136
+ * id: '1',
137
+ * attributes: { firstName: 'Chris', lastName: 'Thoburn' },
138
+ * relationships: { pets: { data: [{ type: 'dog', id: '1' }] }}
139
+ * },
140
+ * included: [
141
+ * {
142
+ * type: 'dog',
143
+ * id: '1',
144
+ * attributes: { name: 'Rey' },
145
+ * relationships: { owner: { data: { type: 'user', id: '1' }}}
146
+ * }
147
+ * ]
148
+ * }
149
+ * ```
150
+ *
151
+ * We could describe the `'user'` and `'dog'` resources in the above payload
152
+ * with the following schemas:
153
+ *
154
+ * ```ts
155
+ * store.registerSchemas([
156
+ * {
157
+ * type: 'user',
158
+ * identity: { type: '@id', name: 'id' },
159
+ * fields: [
160
+ * {
161
+ * type: '@identity',
162
+ * name: '$type',
163
+ * kind: 'derived',
164
+ * options: { key: 'type' },
165
+ * },
166
+ * { kind: 'field', name: 'firstName' },
167
+ * { kind: 'field', name: 'lastName' },
168
+ * {
169
+ * kind: 'derived',
170
+ * name: 'name',
171
+ * type: 'concat',
172
+ * options: { fields: ['firstName', 'lastName'], separator: ' ' }
173
+ * },
174
+ * {
175
+ * kind: 'hasMany',
176
+ * name: 'pets',
177
+ * type: 'pet',
178
+ * options: {
179
+ * async: false,
180
+ * inverse: 'owner',
181
+ * polymorphic: true,
182
+ * linksMode: true,
183
+ * }
184
+ * }
185
+ * ]
186
+ * },
187
+ * {
188
+ * type: 'dog',
189
+ * identity: { type: '@id', name: 'id' },
190
+ * fields: [
191
+ * {
192
+ * type: '@identity',
193
+ * name: '$type',
194
+ * kind: 'derived',
195
+ * options: { key: 'type' },
196
+ * },
197
+ * { kind: 'field', name: 'name' },
198
+ * {
199
+ * kind: 'belongsTo',
200
+ * name: 'owner',
201
+ * type: 'user',
202
+ * options: {
203
+ * async: false,
204
+ * inverse: 'pets',
205
+ * as: 'pet',
206
+ * linksMode: true,
207
+ * }
208
+ * }
209
+ * ]
210
+ * }
211
+ * ]);
212
+ * ```
213
+ *
214
+ * With these schemas in place, the reactive objects that the store would
215
+ * provide us whenever we encountered a `'user'` or a `'dog'` would be:
216
+ *
217
+ * ```ts
218
+ *
219
+ * interface Pet {
220
+ * readonly id: string;
221
+ * readonly owner: User;
222
+ * }
223
+ *
224
+ * interface Dog extends Pet {
225
+ * readonly $type: 'dog';
226
+ * readonly name: string;
227
+ * }
228
+ *
229
+ * interface EditableUser {
230
+ * readonly $type: 'user';
231
+ * readonly id: string;
232
+ * firstName: string;
233
+ * lastName: string;
234
+ * readonly name: string;
235
+ * pets: Array<Dog | Pet>;
236
+ * }
237
+ *
238
+ * interface User {
239
+ * readonly $type: 'user';
240
+ * readonly id: string;
241
+ * readonly firstName: string;
242
+ * readonly lastName: string;
243
+ * readonly name: string;
244
+ * readonly pets: Readonly<Array<Dog | Pet>>;
245
+ * [Checkout]: Promise<EditableUser>
246
+ * }>
247
+ * ```
248
+ *
249
+ * Note how based on the schema the reactive object we receive is able to produce
250
+ * `name` on user (despite no name field being in the cache), provide `$type`
251
+ * pulled from the identity of the resource, and flatten the individual attributes
252
+ * and relationships onto the record for easier use.
253
+ *
254
+ * Notice also how we typed this object with `readonly`. This is because while
255
+ * SchemaRecord instances are ***deeply reactive***, they are also ***immutable***.
256
+ *
257
+ * We can mutate a SchemaRecord only be explicitly asking permission to do so, and
258
+ * in the process gaining access to an editable copy. The immutable version will
259
+ * not show any in-process edits made to this editable copy.
260
+ *
261
+ * ```ts
262
+ * import { Checkout } from '@warp-drive-mirror/schema-record';
263
+ *
264
+ * const editable = await user[Checkout]();
265
+ * ```
266
+ *
267
+ * ---
268
+ *
269
+ * ### Utilities
270
+ *
271
+ * SchemaRecord provides a schema builder that simplifies setting up a couple of
272
+ * conventional fields like identity and `$type`. We can rewrite the schema
273
+ * definition above using this utility like so:
274
+ *
275
+ * ```ts
276
+ * import { withDefaults } from '@warp-drive-mirror/schema-record';
277
+ *
278
+ * store.registerSchemas([
279
+ * withDefaults({
280
+ * type: 'user',
281
+ * fields: [
282
+ * { kind: 'field', name: 'firstName' },
283
+ * { kind: 'field', name: 'lastName' },
284
+ * {
285
+ * kind: 'derived',
286
+ * name: 'name',
287
+ * type: 'concat',
288
+ * options: { fields: ['firstName', 'lastName'], separator: ' ' }
289
+ * },
290
+ * {
291
+ * kind: 'hasMany',
292
+ * name: 'pets',
293
+ * type: 'pet',
294
+ * options: {
295
+ * async: false,
296
+ * inverse: 'owner',
297
+ * polymorphic: true,
298
+ * linksMode: true,
299
+ * }
300
+ * }
301
+ * ]
302
+ * }),
303
+ * withDefaults({
304
+ * type: 'dog',
305
+ * fields: [
306
+ * { kind: 'field', name: 'name' },
307
+ * {
308
+ * kind: 'belongsTo',
309
+ * name: 'owner',
310
+ * type: 'user',
311
+ * options: {
312
+ * async: false,
313
+ * inverse: 'pets',
314
+ * as: 'pet',
315
+ * linksMode: true,
316
+ * }
317
+ * }
318
+ * ]
319
+ * })
320
+ * ]);
321
+ * ```
322
+ *
323
+ * Additionally, `@warp-drive-mirror/core-types` provides several utilities for type-checking and narrowing schemas.
324
+ *
325
+ * - (type) [PolarisResourceSchema](../classes/<Type>%20PolarisResourceSchema)
326
+ * - (type) [LegacyResourceSchema](../classes/<Type>%20LegacyResourceSchema)
327
+ * - (type) [ObjectSchema](../classes/<Type>%20ObjectSchema)
328
+ * - [resourceSchema](../functions/@warp-drive%2Fcore-types/resourceSchema)
329
+ * - [objectSchema](../functions/@warp-drive%2Fcore-types/objectSchema)
330
+ * - [isResourceSchema](../functions/@warp-drive%2Fcore-types/isResourceSchema)
331
+ * - [isLegacyResourceSchema](../functions/@warp-drive%2Fcore-types/isLegacyResourceSchema)
332
+ *
333
+ * ---
334
+ *
335
+ * ### Field Schemas
336
+ *
337
+ * LegacyMode
338
+ *
339
+ * - (type) [LegacyModeFieldSchema](../classes/<Type>%20LegacyModeFieldSchema)
340
+ *
341
+ * PolarisMode
342
+ *
343
+ * - (type) [PolarisModeFieldSchema](../classes/<Type>%20PolarisModeFieldSchema)
344
+ *
345
+ * @module @warp-drive-mirror/schema-record
346
+ * @main @warp-drive-mirror/schema-record
347
+ */
11
348
  export { instantiateRecord, teardownRecord } from '@warp-drive-mirror/schema-record/-private/hooks';
12
349
  export { type Transformation, SchemaService, withDefaults, fromIdentity, registerDerivations } from '@warp-drive-mirror/schema-record/-private/schema';
13
350
  export { type SchemaRecord } from '@warp-drive-mirror/schema-record/-private/record';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgVG;AACH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}