@datocms/cma-client 6.0.0 → 6.1.3

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 (45) hide show
  1. package/dist/cjs/generated/Client.js +1 -1
  2. package/dist/esm/generated/Client.js +25 -23
  3. package/dist/esm/generated/Client.js.map +1 -1
  4. package/dist/esm/generated/resources/BuildEvent.js +5 -44
  5. package/dist/esm/generated/resources/BuildEvent.js.map +1 -1
  6. package/dist/esm/generated/resources/Item.js +5 -44
  7. package/dist/esm/generated/resources/Item.js.map +1 -1
  8. package/dist/esm/generated/resources/ItemVersion.js +5 -44
  9. package/dist/esm/generated/resources/ItemVersion.js.map +1 -1
  10. package/dist/esm/generated/resources/SearchIndexEvent.js +5 -44
  11. package/dist/esm/generated/resources/SearchIndexEvent.js.map +1 -1
  12. package/dist/esm/generated/resources/SearchResult.js +5 -44
  13. package/dist/esm/generated/resources/SearchResult.js.map +1 -1
  14. package/dist/esm/generated/resources/Upload.js +5 -44
  15. package/dist/esm/generated/resources/Upload.js.map +1 -1
  16. package/dist/esm/generated/resources/UploadSmartTag.js +5 -44
  17. package/dist/esm/generated/resources/UploadSmartTag.js.map +1 -1
  18. package/dist/esm/generated/resources/UploadTag.js +5 -44
  19. package/dist/esm/generated/resources/UploadTag.js.map +1 -1
  20. package/dist/esm/generated/resources/WebhookCall.js +5 -44
  21. package/dist/esm/generated/resources/WebhookCall.js.map +1 -1
  22. package/dist/esm/resources/Role.js +23 -25
  23. package/dist/esm/resources/Role.js.map +1 -1
  24. package/dist/esm/resources/Upload.js +12 -83
  25. package/dist/esm/resources/Upload.js.map +1 -1
  26. package/dist/esm/utilities/buildBlockRecord.js +4 -1
  27. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  28. package/dist/esm/utilities/defaultFieldMetadata.js +16 -25
  29. package/dist/esm/utilities/defaultFieldMetadata.js.map +1 -1
  30. package/dist/esm/utilities/duplicateBlockRecord.js +25 -47
  31. package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -1
  32. package/dist/esm/utilities/environmentSettings.js +3 -14
  33. package/dist/esm/utilities/environmentSettings.js.map +1 -1
  34. package/dist/esm/utilities/inspectItem.js +1 -12
  35. package/dist/esm/utilities/inspectItem.js.map +1 -1
  36. package/dist/esm/utilities/nonRecursiveBlocks.js +109 -260
  37. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -1
  38. package/dist/esm/utilities/normalizedFieldValues.js +30 -53
  39. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -1
  40. package/dist/esm/utilities/recursiveBlocks.js +108 -131
  41. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  42. package/dist/esm/utilities/schemaRepository.js +266 -333
  43. package/dist/esm/utilities/schemaRepository.js.map +1 -1
  44. package/package.json +4 -4
  45. package/src/generated/Client.ts +1 -1
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { deserializeResponseBody } from '@datocms/rest-client-utils';
11
2
  import { blockModelIdsReferencedInField, modelIdsReferencedInField, } from './fieldsContainingReferences.js';
12
3
  /**
@@ -99,87 +90,73 @@ export class SchemaRepository {
99
90
  * This method is called lazily and caches the result for subsequent calls.
100
91
  * @returns Promise that resolves to an array of item types
101
92
  */
102
- loadItemTypes() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- if (!this.itemTypesPromise) {
105
- this.itemTypesPromise = (() => __awaiter(this, void 0, void 0, function* () {
106
- const { data: itemTypes } = yield this.client.itemTypes.rawList();
107
- // Populate the lookup maps
108
- for (const itemType of itemTypes) {
109
- this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
110
- this.itemTypesById.set(itemType.id, itemType);
111
- }
112
- return itemTypes;
113
- }))();
114
- }
115
- return this.itemTypesPromise;
116
- });
93
+ async loadItemTypes() {
94
+ if (!this.itemTypesPromise) {
95
+ this.itemTypesPromise = (async () => {
96
+ const { data: itemTypes } = await this.client.itemTypes.rawList();
97
+ // Populate the lookup maps
98
+ for (const itemType of itemTypes) {
99
+ this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
100
+ this.itemTypesById.set(itemType.id, itemType);
101
+ }
102
+ return itemTypes;
103
+ })();
104
+ }
105
+ return this.itemTypesPromise;
117
106
  }
118
107
  /**
119
108
  * Gets all item types from the DatoCMS project.
120
109
  * @returns Promise that resolves to an array of all item types
121
110
  */
122
- getAllItemTypes() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- const rawResult = yield this.getAllRawItemTypes();
125
- return deserializeResponseBody({
126
- data: rawResult,
127
- });
111
+ async getAllItemTypes() {
112
+ const rawResult = await this.getAllRawItemTypes();
113
+ return deserializeResponseBody({
114
+ data: rawResult,
128
115
  });
129
116
  }
130
117
  /**
131
118
  * Gets all item types from the DatoCMS project.
132
119
  * @returns Promise that resolves to an array of all item types
133
120
  */
134
- getAllRawItemTypes() {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const itemTypes = yield this.loadItemTypes();
137
- return itemTypes;
138
- });
121
+ async getAllRawItemTypes() {
122
+ const itemTypes = await this.loadItemTypes();
123
+ return itemTypes;
139
124
  }
140
125
  /**
141
126
  * Gets all item types that are models (not modular blocks).
142
127
  * @returns Promise that resolves to an array of model item types
143
128
  */
144
- getAllModels() {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- const rawResult = yield this.getAllRawModels();
147
- return deserializeResponseBody({
148
- data: rawResult,
149
- });
129
+ async getAllModels() {
130
+ const rawResult = await this.getAllRawModels();
131
+ return deserializeResponseBody({
132
+ data: rawResult,
150
133
  });
151
134
  }
152
135
  /**
153
136
  * Gets all item types that are models (not modular blocks).
154
137
  * @returns Promise that resolves to an array of model item types
155
138
  */
156
- getAllRawModels() {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- const itemTypes = yield this.loadItemTypes();
159
- return itemTypes.filter((it) => !it.attributes.modular_block);
160
- });
139
+ async getAllRawModels() {
140
+ const itemTypes = await this.loadItemTypes();
141
+ return itemTypes.filter((it) => !it.attributes.modular_block);
161
142
  }
162
143
  /**
163
144
  * Gets all item types that are modular blocks.
164
145
  * @returns Promise that resolves to an array of block model item types
165
146
  */
166
- getAllBlockModels() {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- const rawResult = yield this.getAllRawBlockModels();
169
- return deserializeResponseBody({
170
- data: rawResult,
171
- });
147
+ async getAllBlockModels() {
148
+ const rawResult = await this.getAllRawBlockModels();
149
+ return deserializeResponseBody({
150
+ data: rawResult,
172
151
  });
173
152
  }
174
153
  /**
175
154
  * Gets all item types that are modular blocks.
176
155
  * @returns Promise that resolves to an array of block model item types
177
156
  */
178
- getAllRawBlockModels() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const itemTypes = yield this.loadItemTypes();
181
- return itemTypes.filter((it) => it.attributes.modular_block);
182
- });
157
+ async getAllRawBlockModels() {
158
+ const itemTypes = await this.loadItemTypes();
159
+ return itemTypes.filter((it) => it.attributes.modular_block);
183
160
  }
184
161
  /**
185
162
  * Gets an item type by its API key.
@@ -187,12 +164,10 @@ export class SchemaRepository {
187
164
  * @returns Promise that resolves to the item type
188
165
  * @throws Error if the item type is not found
189
166
  */
190
- getItemTypeByApiKey(apiKey) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- const rawResult = yield this.getRawItemTypeByApiKey(apiKey);
193
- return deserializeResponseBody({
194
- data: rawResult,
195
- });
167
+ async getItemTypeByApiKey(apiKey) {
168
+ const rawResult = await this.getRawItemTypeByApiKey(apiKey);
169
+ return deserializeResponseBody({
170
+ data: rawResult,
196
171
  });
197
172
  }
198
173
  /**
@@ -201,15 +176,13 @@ export class SchemaRepository {
201
176
  * @returns Promise that resolves to the item type
202
177
  * @throws Error if the item type is not found
203
178
  */
204
- getRawItemTypeByApiKey(apiKey) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- yield this.loadItemTypes();
207
- const itemType = this.itemTypesByApiKey.get(apiKey);
208
- if (!itemType) {
209
- throw new Error(`Item type with API key '${apiKey}' not found`);
210
- }
211
- return itemType;
212
- });
179
+ async getRawItemTypeByApiKey(apiKey) {
180
+ await this.loadItemTypes();
181
+ const itemType = this.itemTypesByApiKey.get(apiKey);
182
+ if (!itemType) {
183
+ throw new Error(`Item type with API key '${apiKey}' not found`);
184
+ }
185
+ return itemType;
213
186
  }
214
187
  /**
215
188
  * Gets an item type by its ID.
@@ -217,12 +190,10 @@ export class SchemaRepository {
217
190
  * @returns Promise that resolves to the item type
218
191
  * @throws Error if the item type is not found
219
192
  */
220
- getItemTypeById(id) {
221
- return __awaiter(this, void 0, void 0, function* () {
222
- const rawResult = yield this.getRawItemTypeById(id);
223
- return deserializeResponseBody({
224
- data: rawResult,
225
- });
193
+ async getItemTypeById(id) {
194
+ const rawResult = await this.getRawItemTypeById(id);
195
+ return deserializeResponseBody({
196
+ data: rawResult,
226
197
  });
227
198
  }
228
199
  /**
@@ -231,15 +202,13 @@ export class SchemaRepository {
231
202
  * @returns Promise that resolves to the item type
232
203
  * @throws Error if the item type is not found
233
204
  */
234
- getRawItemTypeById(id) {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- yield this.loadItemTypes();
237
- const itemType = this.itemTypesById.get(id);
238
- if (!itemType) {
239
- throw new Error(`Item type with ID '${id}' not found`);
240
- }
241
- return itemType;
242
- });
205
+ async getRawItemTypeById(id) {
206
+ await this.loadItemTypes();
207
+ const itemType = this.itemTypesById.get(id);
208
+ if (!itemType) {
209
+ throw new Error(`Item type with ID '${id}' not found`);
210
+ }
211
+ return itemType;
243
212
  }
244
213
  /**
245
214
  * Gets all fields for a given item type.
@@ -247,12 +216,10 @@ export class SchemaRepository {
247
216
  * @param itemType - The item type to get fields for
248
217
  * @returns Promise that resolves to an array of fields
249
218
  */
250
- getItemTypeFields(itemType) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const rawResult = yield this.getRawItemTypeFields(itemType);
253
- return deserializeResponseBody({
254
- data: rawResult,
255
- });
219
+ async getItemTypeFields(itemType) {
220
+ const rawResult = await this.getRawItemTypeFields(itemType);
221
+ return deserializeResponseBody({
222
+ data: rawResult,
256
223
  });
257
224
  }
258
225
  /**
@@ -261,18 +228,16 @@ export class SchemaRepository {
261
228
  * @param itemType - The item type to get fields for
262
229
  * @returns Promise that resolves to an array of fields
263
230
  */
264
- getRawItemTypeFields(itemType) {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- // Check if we already have the fields cached
267
- const cachedFields = this.fieldsByItemType.get(itemType.id);
268
- if (cachedFields) {
269
- return cachedFields;
270
- }
271
- // Fetch and cache the fields
272
- const { data: fields } = yield this.client.fields.rawList(itemType.id);
273
- this.fieldsByItemType.set(itemType.id, fields);
274
- return fields;
275
- });
231
+ async getRawItemTypeFields(itemType) {
232
+ // Check if we already have the fields cached
233
+ const cachedFields = this.fieldsByItemType.get(itemType.id);
234
+ if (cachedFields) {
235
+ return cachedFields;
236
+ }
237
+ // Fetch and cache the fields
238
+ const { data: fields } = await this.client.fields.rawList(itemType.id);
239
+ this.fieldsByItemType.set(itemType.id, fields);
240
+ return fields;
276
241
  }
277
242
  /**
278
243
  * Gets all fieldsets for a given item type.
@@ -280,12 +245,10 @@ export class SchemaRepository {
280
245
  * @param itemType - The item type to get fieldsets for
281
246
  * @returns Promise that resolves to an array of fieldsets
282
247
  */
283
- getItemTypeFieldsets(itemType) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- const rawResult = yield this.getRawItemTypeFieldsets(itemType);
286
- return deserializeResponseBody({
287
- data: rawResult,
288
- });
248
+ async getItemTypeFieldsets(itemType) {
249
+ const rawResult = await this.getRawItemTypeFieldsets(itemType);
250
+ return deserializeResponseBody({
251
+ data: rawResult,
289
252
  });
290
253
  }
291
254
  /**
@@ -294,63 +257,55 @@ export class SchemaRepository {
294
257
  * @param itemType - The item type to get fieldsets for
295
258
  * @returns Promise that resolves to an array of fieldsets
296
259
  */
297
- getRawItemTypeFieldsets(itemType) {
298
- return __awaiter(this, void 0, void 0, function* () {
299
- // Check if we already have the fieldsets cached
300
- const cachedFieldsets = this.fieldsetsByItemType.get(itemType.id);
301
- if (cachedFieldsets) {
302
- return cachedFieldsets;
303
- }
304
- // Fetch and cache the fieldsets
305
- const { data: fieldsets } = yield this.client.fieldsets.rawList(itemType.id);
306
- this.fieldsetsByItemType.set(itemType.id, fieldsets);
307
- return fieldsets;
308
- });
260
+ async getRawItemTypeFieldsets(itemType) {
261
+ // Check if we already have the fieldsets cached
262
+ const cachedFieldsets = this.fieldsetsByItemType.get(itemType.id);
263
+ if (cachedFieldsets) {
264
+ return cachedFieldsets;
265
+ }
266
+ // Fetch and cache the fieldsets
267
+ const { data: fieldsets } = await this.client.fieldsets.rawList(itemType.id);
268
+ this.fieldsetsByItemType.set(itemType.id, fieldsets);
269
+ return fieldsets;
309
270
  }
310
271
  /**
311
272
  * Loads and caches all plugins from the DatoCMS API.
312
273
  * This method is called lazily and caches the result for subsequent calls.
313
274
  * @returns Promise that resolves to an array of plugins
314
275
  */
315
- loadPlugins() {
316
- return __awaiter(this, void 0, void 0, function* () {
317
- if (!this.pluginsPromise) {
318
- this.pluginsPromise = (() => __awaiter(this, void 0, void 0, function* () {
319
- const { data: plugins } = yield this.client.plugins.rawList();
320
- // Populate the lookup maps
321
- for (const plugin of plugins) {
322
- this.pluginsById.set(plugin.id, plugin);
323
- if (plugin.attributes.package_name) {
324
- this.pluginsByPackageName.set(plugin.attributes.package_name, plugin);
325
- }
276
+ async loadPlugins() {
277
+ if (!this.pluginsPromise) {
278
+ this.pluginsPromise = (async () => {
279
+ const { data: plugins } = await this.client.plugins.rawList();
280
+ // Populate the lookup maps
281
+ for (const plugin of plugins) {
282
+ this.pluginsById.set(plugin.id, plugin);
283
+ if (plugin.attributes.package_name) {
284
+ this.pluginsByPackageName.set(plugin.attributes.package_name, plugin);
326
285
  }
327
- return plugins;
328
- }))();
329
- }
330
- return this.pluginsPromise;
331
- });
286
+ }
287
+ return plugins;
288
+ })();
289
+ }
290
+ return this.pluginsPromise;
332
291
  }
333
292
  /**
334
293
  * Gets all plugins from the DatoCMS project.
335
294
  * @returns Promise that resolves to an array of all plugins
336
295
  */
337
- getAllPlugins() {
338
- return __awaiter(this, void 0, void 0, function* () {
339
- const rawResult = yield this.getAllRawPlugins();
340
- return deserializeResponseBody({
341
- data: rawResult,
342
- });
296
+ async getAllPlugins() {
297
+ const rawResult = await this.getAllRawPlugins();
298
+ return deserializeResponseBody({
299
+ data: rawResult,
343
300
  });
344
301
  }
345
302
  /**
346
303
  * Gets all plugins from the DatoCMS project.
347
304
  * @returns Promise that resolves to an array of all plugins
348
305
  */
349
- getAllRawPlugins() {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- const plugins = yield this.loadPlugins();
352
- return plugins;
353
- });
306
+ async getAllRawPlugins() {
307
+ const plugins = await this.loadPlugins();
308
+ return plugins;
354
309
  }
355
310
  /**
356
311
  * Gets a plugin by its ID.
@@ -358,12 +313,10 @@ export class SchemaRepository {
358
313
  * @returns Promise that resolves to the plugin
359
314
  * @throws Error if the plugin is not found
360
315
  */
361
- getPluginById(id) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- const rawResult = yield this.getRawPluginById(id);
364
- return deserializeResponseBody({
365
- data: rawResult,
366
- });
316
+ async getPluginById(id) {
317
+ const rawResult = await this.getRawPluginById(id);
318
+ return deserializeResponseBody({
319
+ data: rawResult,
367
320
  });
368
321
  }
369
322
  /**
@@ -372,15 +325,13 @@ export class SchemaRepository {
372
325
  * @returns Promise that resolves to the plugin
373
326
  * @throws Error if the plugin is not found
374
327
  */
375
- getRawPluginById(id) {
376
- return __awaiter(this, void 0, void 0, function* () {
377
- yield this.loadPlugins();
378
- const plugin = this.pluginsById.get(id);
379
- if (!plugin) {
380
- throw new Error(`Plugin with ID '${id}' not found`);
381
- }
382
- return plugin;
383
- });
328
+ async getRawPluginById(id) {
329
+ await this.loadPlugins();
330
+ const plugin = this.pluginsById.get(id);
331
+ if (!plugin) {
332
+ throw new Error(`Plugin with ID '${id}' not found`);
333
+ }
334
+ return plugin;
384
335
  }
385
336
  /**
386
337
  * Gets a plugin by its package name.
@@ -388,12 +339,10 @@ export class SchemaRepository {
388
339
  * @returns Promise that resolves to the plugin
389
340
  * @throws Error if the plugin is not found
390
341
  */
391
- getPluginByPackageName(packageName) {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- const rawResult = yield this.getRawPluginByPackageName(packageName);
394
- return deserializeResponseBody({
395
- data: rawResult,
396
- });
342
+ async getPluginByPackageName(packageName) {
343
+ const rawResult = await this.getRawPluginByPackageName(packageName);
344
+ return deserializeResponseBody({
345
+ data: rawResult,
397
346
  });
398
347
  }
399
348
  /**
@@ -402,15 +351,13 @@ export class SchemaRepository {
402
351
  * @returns Promise that resolves to the plugin
403
352
  * @throws Error if the plugin is not found
404
353
  */
405
- getRawPluginByPackageName(packageName) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- yield this.loadPlugins();
408
- const plugin = this.pluginsByPackageName.get(packageName);
409
- if (!plugin) {
410
- throw new Error(`Plugin with package name '${packageName}' not found`);
411
- }
412
- return plugin;
413
- });
354
+ async getRawPluginByPackageName(packageName) {
355
+ await this.loadPlugins();
356
+ const plugin = this.pluginsByPackageName.get(packageName);
357
+ if (!plugin) {
358
+ throw new Error(`Plugin with package name '${packageName}' not found`);
359
+ }
360
+ return plugin;
414
361
  }
415
362
  /**
416
363
  * Prefetches all models and their fields in a single optimized API call.
@@ -423,43 +370,41 @@ export class SchemaRepository {
423
370
  *
424
371
  * @returns Promise that resolves when all data has been fetched and cached
425
372
  */
426
- prefetchAllModelsAndFields() {
427
- return __awaiter(this, void 0, void 0, function* () {
428
- if (this.prefetchPromise) {
429
- return this.prefetchPromise;
373
+ async prefetchAllModelsAndFields() {
374
+ if (this.prefetchPromise) {
375
+ return this.prefetchPromise;
376
+ }
377
+ const prefetch = async () => {
378
+ const { included } = await this.client.site.rawFind({
379
+ include: 'item_types,item_types.fields',
380
+ });
381
+ if (!included) {
382
+ return;
430
383
  }
431
- const prefetch = () => __awaiter(this, void 0, void 0, function* () {
432
- const { included } = yield this.client.site.rawFind({
433
- include: 'item_types,item_types.fields',
434
- });
435
- if (!included) {
436
- return;
437
- }
438
- const allItemTypes = included.filter((item) => item.type === 'item_type');
439
- const allFields = included.filter((item) => item.type === 'field');
440
- // Populate item types caches
441
- this.itemTypesPromise = Promise.resolve(allItemTypes);
442
- for (const itemType of allItemTypes) {
443
- this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
444
- this.itemTypesById.set(itemType.id, itemType);
445
- }
446
- // Group fields by item type and populate fields cache
447
- const fieldsByItemTypeId = new Map();
448
- for (const field of allFields) {
449
- const itemTypeId = field.relationships.item_type.data.id;
450
- if (!fieldsByItemTypeId.has(itemTypeId)) {
451
- fieldsByItemTypeId.set(itemTypeId, []);
452
- }
453
- fieldsByItemTypeId.get(itemTypeId).push(field);
454
- }
455
- // Populate the fields cache
456
- for (const [itemTypeId, fields] of fieldsByItemTypeId) {
457
- this.fieldsByItemType.set(itemTypeId, fields);
384
+ const allItemTypes = included.filter((item) => item.type === 'item_type');
385
+ const allFields = included.filter((item) => item.type === 'field');
386
+ // Populate item types caches
387
+ this.itemTypesPromise = Promise.resolve(allItemTypes);
388
+ for (const itemType of allItemTypes) {
389
+ this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
390
+ this.itemTypesById.set(itemType.id, itemType);
391
+ }
392
+ // Group fields by item type and populate fields cache
393
+ const fieldsByItemTypeId = new Map();
394
+ for (const field of allFields) {
395
+ const itemTypeId = field.relationships.item_type.data.id;
396
+ if (!fieldsByItemTypeId.has(itemTypeId)) {
397
+ fieldsByItemTypeId.set(itemTypeId, []);
458
398
  }
459
- });
460
- this.prefetchPromise = prefetch();
461
- return this.prefetchPromise;
462
- });
399
+ fieldsByItemTypeId.get(itemTypeId).push(field);
400
+ }
401
+ // Populate the fields cache
402
+ for (const [itemTypeId, fields] of fieldsByItemTypeId) {
403
+ this.fieldsByItemType.set(itemTypeId, fields);
404
+ }
405
+ };
406
+ this.prefetchPromise = prefetch();
407
+ return this.prefetchPromise;
463
408
  }
464
409
  /**
465
410
  * Gets all models that directly or indirectly embed the given block models.
@@ -470,43 +415,41 @@ export class SchemaRepository {
470
415
  * @param blocks - Array of block models to find references to
471
416
  * @returns Promise that resolves to array of models that embed these blocks
472
417
  */
473
- getRawModelsEmbeddingBlocks(blocks) {
474
- return __awaiter(this, void 0, void 0, function* () {
475
- yield this.prefetchAllModelsAndFields();
476
- const allItemTypes = yield this.getAllRawItemTypes();
477
- const blockIds = new Set(blocks.map((block) => block.id));
478
- const embeddingModels = [];
479
- // Helper function to check if a model points to any of the target blocks
480
- const modelPointsToBlocks = (itemType, alreadyExplored = new Set()) => __awaiter(this, void 0, void 0, function* () {
481
- if (alreadyExplored.has(itemType.id)) {
482
- return false;
418
+ async getRawModelsEmbeddingBlocks(blocks) {
419
+ await this.prefetchAllModelsAndFields();
420
+ const allItemTypes = await this.getAllRawItemTypes();
421
+ const blockIds = new Set(blocks.map((block) => block.id));
422
+ const embeddingModels = [];
423
+ // Helper function to check if a model points to any of the target blocks
424
+ const modelPointsToBlocks = async (itemType, alreadyExplored = new Set()) => {
425
+ if (alreadyExplored.has(itemType.id)) {
426
+ return false;
427
+ }
428
+ alreadyExplored.add(itemType.id);
429
+ const fields = await this.getRawItemTypeFields(itemType);
430
+ for (const field of fields) {
431
+ const referencedBlockIds = blockModelIdsReferencedInField(field);
432
+ // Check if this field directly references any of our target blocks
433
+ if (referencedBlockIds.some((id) => blockIds.has(id))) {
434
+ return true;
483
435
  }
484
- alreadyExplored.add(itemType.id);
485
- const fields = yield this.getRawItemTypeFields(itemType);
486
- for (const field of fields) {
487
- const referencedBlockIds = blockModelIdsReferencedInField(field);
488
- // Check if this field directly references any of our target blocks
489
- if (referencedBlockIds.some((id) => blockIds.has(id))) {
436
+ // Check if this field references other block models that might transitively reference our targets
437
+ const referencedBlocks = referencedBlockIds.map((id) => allItemTypes.find((it) => it.id === id));
438
+ for (const linkedBlock of referencedBlocks) {
439
+ if (await modelPointsToBlocks(linkedBlock, new Set(alreadyExplored))) {
490
440
  return true;
491
441
  }
492
- // Check if this field references other block models that might transitively reference our targets
493
- const referencedBlocks = referencedBlockIds.map((id) => allItemTypes.find((it) => it.id === id));
494
- for (const linkedBlock of referencedBlocks) {
495
- if (yield modelPointsToBlocks(linkedBlock, new Set(alreadyExplored))) {
496
- return true;
497
- }
498
- }
499
- }
500
- return false;
501
- });
502
- // Check each model to see if it embeds any of the target blocks
503
- for (const itemType of allItemTypes) {
504
- if (yield modelPointsToBlocks(itemType)) {
505
- embeddingModels.push(itemType);
506
442
  }
507
443
  }
508
- return embeddingModels;
509
- });
444
+ return false;
445
+ };
446
+ // Check each model to see if it embeds any of the target blocks
447
+ for (const itemType of allItemTypes) {
448
+ if (await modelPointsToBlocks(itemType)) {
449
+ embeddingModels.push(itemType);
450
+ }
451
+ }
452
+ return embeddingModels;
510
453
  }
511
454
  /**
512
455
  * Gets all models that directly or indirectly embed the given block models.
@@ -517,12 +460,10 @@ export class SchemaRepository {
517
460
  * @param blocks - Array of block models to find references to
518
461
  * @returns Promise that resolves to array of models that embed these blocks
519
462
  */
520
- getModelsEmbeddingBlocks(blocks) {
521
- return __awaiter(this, void 0, void 0, function* () {
522
- const rawResult = yield this.getRawModelsEmbeddingBlocks(blocks);
523
- return deserializeResponseBody({
524
- data: rawResult,
525
- });
463
+ async getModelsEmbeddingBlocks(blocks) {
464
+ const rawResult = await this.getRawModelsEmbeddingBlocks(blocks);
465
+ return deserializeResponseBody({
466
+ data: rawResult,
526
467
  });
527
468
  }
528
469
  /**
@@ -534,40 +475,38 @@ export class SchemaRepository {
534
475
  * @param itemTypes - Array of item types to find nested blocks for
535
476
  * @returns Promise that resolves to array of all block models nested in these item types
536
477
  */
537
- getRawNestedBlocks(itemTypes) {
538
- return __awaiter(this, void 0, void 0, function* () {
539
- yield this.prefetchAllModelsAndFields();
540
- const allItemTypes = yield this.getAllRawItemTypes();
541
- const visited = new Set();
542
- const nestedBlocks = [];
543
- // Helper function to recursively find nested blocks
544
- const findNestedBlocks = (itemType, alreadyExplored = new Set()) => __awaiter(this, void 0, void 0, function* () {
545
- if (alreadyExplored.has(itemType.id)) {
546
- return;
547
- }
548
- alreadyExplored.add(itemType.id);
549
- const fields = yield this.getRawItemTypeFields(itemType);
550
- for (const field of fields) {
551
- const referencedBlockIds = blockModelIdsReferencedInField(field);
552
- for (const blockId of referencedBlockIds) {
553
- if (!visited.has(blockId)) {
554
- visited.add(blockId);
555
- const nestedBlock = allItemTypes.find((it) => it.id === blockId);
556
- if (nestedBlock) {
557
- nestedBlocks.push(nestedBlock);
558
- // Recursively find blocks nested in this block
559
- yield findNestedBlocks(nestedBlock, new Set(alreadyExplored));
560
- }
478
+ async getRawNestedBlocks(itemTypes) {
479
+ await this.prefetchAllModelsAndFields();
480
+ const allItemTypes = await this.getAllRawItemTypes();
481
+ const visited = new Set();
482
+ const nestedBlocks = [];
483
+ // Helper function to recursively find nested blocks
484
+ const findNestedBlocks = async (itemType, alreadyExplored = new Set()) => {
485
+ if (alreadyExplored.has(itemType.id)) {
486
+ return;
487
+ }
488
+ alreadyExplored.add(itemType.id);
489
+ const fields = await this.getRawItemTypeFields(itemType);
490
+ for (const field of fields) {
491
+ const referencedBlockIds = blockModelIdsReferencedInField(field);
492
+ for (const blockId of referencedBlockIds) {
493
+ if (!visited.has(blockId)) {
494
+ visited.add(blockId);
495
+ const nestedBlock = allItemTypes.find((it) => it.id === blockId);
496
+ if (nestedBlock) {
497
+ nestedBlocks.push(nestedBlock);
498
+ // Recursively find blocks nested in this block
499
+ await findNestedBlocks(nestedBlock, new Set(alreadyExplored));
561
500
  }
562
501
  }
563
502
  }
564
- });
565
- // Find nested blocks for each provided item type
566
- for (const itemType of itemTypes) {
567
- yield findNestedBlocks(itemType);
568
503
  }
569
- return nestedBlocks;
570
- });
504
+ };
505
+ // Find nested blocks for each provided item type
506
+ for (const itemType of itemTypes) {
507
+ await findNestedBlocks(itemType);
508
+ }
509
+ return nestedBlocks;
571
510
  }
572
511
  /**
573
512
  * Gets all block models that are directly or indirectly nested within the given item types.
@@ -578,12 +517,10 @@ export class SchemaRepository {
578
517
  * @param itemTypes - Array of item types to find nested blocks for
579
518
  * @returns Promise that resolves to array of all block models nested in these item types
580
519
  */
581
- getNestedBlocks(itemTypes) {
582
- return __awaiter(this, void 0, void 0, function* () {
583
- const rawResult = yield this.getRawNestedBlocks(itemTypes);
584
- return deserializeResponseBody({
585
- data: rawResult,
586
- });
520
+ async getNestedBlocks(itemTypes) {
521
+ const rawResult = await this.getRawNestedBlocks(itemTypes);
522
+ return deserializeResponseBody({
523
+ data: rawResult,
587
524
  });
588
525
  }
589
526
  /**
@@ -595,49 +532,47 @@ export class SchemaRepository {
595
532
  * @param itemTypes - Array of item types to find nested models for
596
533
  * @returns Promise that resolves to array of all models nested in these item types
597
534
  */
598
- getRawNestedModels(itemTypes) {
599
- return __awaiter(this, void 0, void 0, function* () {
600
- yield this.prefetchAllModelsAndFields();
601
- const allItemTypes = yield this.getAllRawItemTypes();
602
- const visited = new Set();
603
- const nestedModels = [];
604
- // Helper function to recursively find nested models
605
- const findNestedModels = (itemType, alreadyExplored = new Set()) => __awaiter(this, void 0, void 0, function* () {
606
- if (alreadyExplored.has(itemType.id)) {
607
- return;
608
- }
609
- alreadyExplored.add(itemType.id);
610
- const fields = yield this.getRawItemTypeFields(itemType);
611
- for (const field of fields) {
612
- // Find models directly referenced via link fields
613
- const referencedModelIds = modelIdsReferencedInField(field);
614
- for (const modelId of referencedModelIds) {
615
- if (!visited.has(modelId)) {
616
- visited.add(modelId);
617
- const nestedModel = allItemTypes.find((it) => it.id === modelId);
618
- if (nestedModel) {
619
- nestedModels.push(nestedModel);
620
- // Do NOT recurse into models, only into blocks
621
- }
535
+ async getRawNestedModels(itemTypes) {
536
+ await this.prefetchAllModelsAndFields();
537
+ const allItemTypes = await this.getAllRawItemTypes();
538
+ const visited = new Set();
539
+ const nestedModels = [];
540
+ // Helper function to recursively find nested models
541
+ const findNestedModels = async (itemType, alreadyExplored = new Set()) => {
542
+ if (alreadyExplored.has(itemType.id)) {
543
+ return;
544
+ }
545
+ alreadyExplored.add(itemType.id);
546
+ const fields = await this.getRawItemTypeFields(itemType);
547
+ for (const field of fields) {
548
+ // Find models directly referenced via link fields
549
+ const referencedModelIds = modelIdsReferencedInField(field);
550
+ for (const modelId of referencedModelIds) {
551
+ if (!visited.has(modelId)) {
552
+ visited.add(modelId);
553
+ const nestedModel = allItemTypes.find((it) => it.id === modelId);
554
+ if (nestedModel) {
555
+ nestedModels.push(nestedModel);
556
+ // Do NOT recurse into models, only into blocks
622
557
  }
623
558
  }
624
- // Find blocks referenced via block fields, then recursively find models in those blocks
625
- const referencedBlockIds = blockModelIdsReferencedInField(field);
626
- for (const blockId of referencedBlockIds) {
627
- const nestedBlock = allItemTypes.find((it) => it.id === blockId);
628
- if (nestedBlock) {
629
- // Recursively find models nested in this block
630
- yield findNestedModels(nestedBlock, new Set(alreadyExplored));
631
- }
559
+ }
560
+ // Find blocks referenced via block fields, then recursively find models in those blocks
561
+ const referencedBlockIds = blockModelIdsReferencedInField(field);
562
+ for (const blockId of referencedBlockIds) {
563
+ const nestedBlock = allItemTypes.find((it) => it.id === blockId);
564
+ if (nestedBlock) {
565
+ // Recursively find models nested in this block
566
+ await findNestedModels(nestedBlock, new Set(alreadyExplored));
632
567
  }
633
568
  }
634
- });
635
- // Find nested models for each provided item type
636
- for (const itemType of itemTypes) {
637
- yield findNestedModels(itemType);
638
569
  }
639
- return nestedModels;
640
- });
570
+ };
571
+ // Find nested models for each provided item type
572
+ for (const itemType of itemTypes) {
573
+ await findNestedModels(itemType);
574
+ }
575
+ return nestedModels;
641
576
  }
642
577
  /**
643
578
  * Gets all models that are directly or indirectly nested/referenced within the given item types.
@@ -648,12 +583,10 @@ export class SchemaRepository {
648
583
  * @param itemTypes - Array of item types to find nested models for
649
584
  * @returns Promise that resolves to array of all models nested in these item types
650
585
  */
651
- getNestedModels(itemTypes) {
652
- return __awaiter(this, void 0, void 0, function* () {
653
- const rawResult = yield this.getRawNestedModels(itemTypes);
654
- return deserializeResponseBody({
655
- data: rawResult,
656
- });
586
+ async getNestedModels(itemTypes) {
587
+ const rawResult = await this.getRawNestedModels(itemTypes);
588
+ return deserializeResponseBody({
589
+ data: rawResult,
657
590
  });
658
591
  }
659
592
  }