@datocms/cma-client 5.8.1 → 6.1.0
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/cjs/generated/Client.js +1 -1
- package/dist/cjs/resources/Upload.js +139 -0
- package/dist/cjs/resources/Upload.js.map +1 -1
- package/dist/cjs/utilities/defaultFieldMetadata.js +130 -0
- package/dist/cjs/utilities/defaultFieldMetadata.js.map +1 -0
- package/dist/cjs/utilities/environmentSettings.js +65 -0
- package/dist/cjs/utilities/environmentSettings.js.map +1 -0
- package/dist/esm/generated/Client.js +25 -23
- package/dist/esm/generated/Client.js.map +1 -1
- package/dist/esm/generated/resources/BuildEvent.js +5 -44
- package/dist/esm/generated/resources/BuildEvent.js.map +1 -1
- package/dist/esm/generated/resources/Item.js +5 -44
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.js +5 -44
- package/dist/esm/generated/resources/ItemVersion.js.map +1 -1
- package/dist/esm/generated/resources/SearchIndexEvent.js +5 -44
- package/dist/esm/generated/resources/SearchIndexEvent.js.map +1 -1
- package/dist/esm/generated/resources/SearchResult.js +5 -44
- package/dist/esm/generated/resources/SearchResult.js.map +1 -1
- package/dist/esm/generated/resources/Upload.js +5 -44
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/generated/resources/UploadSmartTag.js +5 -44
- package/dist/esm/generated/resources/UploadSmartTag.js.map +1 -1
- package/dist/esm/generated/resources/UploadTag.js +5 -44
- package/dist/esm/generated/resources/UploadTag.js.map +1 -1
- package/dist/esm/generated/resources/WebhookCall.js +5 -44
- package/dist/esm/generated/resources/WebhookCall.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/resources/Role.js +23 -25
- package/dist/esm/resources/Role.js.map +1 -1
- package/dist/esm/resources/Upload.d.ts +53 -40
- package/dist/esm/resources/Upload.js +68 -0
- package/dist/esm/resources/Upload.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.js +4 -1
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/defaultFieldMetadata.d.ts +84 -0
- package/dist/esm/utilities/defaultFieldMetadata.js +113 -0
- package/dist/esm/utilities/defaultFieldMetadata.js.map +1 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +25 -47
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -1
- package/dist/esm/utilities/environmentSettings.d.ts +35 -0
- package/dist/esm/utilities/environmentSettings.js +49 -0
- package/dist/esm/utilities/environmentSettings.js.map +1 -0
- package/dist/esm/utilities/inspectItem.js +1 -12
- package/dist/esm/utilities/inspectItem.js.map +1 -1
- package/dist/esm/utilities/nonRecursiveBlocks.js +109 -260
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/normalizedFieldValues.js +30 -53
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -1
- package/dist/esm/utilities/recursiveBlocks.js +108 -131
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.js +266 -333
- package/dist/esm/utilities/schemaRepository.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/resources/Upload.d.ts +53 -40
- package/dist/types/utilities/defaultFieldMetadata.d.ts +84 -0
- package/dist/types/utilities/environmentSettings.d.ts +35 -0
- package/package.json +3 -3
- package/src/generated/Client.ts +1 -1
- package/src/index.ts +1 -1
- package/src/resources/Upload.ts +87 -31
- package/src/utilities/defaultFieldMetadata.ts +193 -0
- package/src/utilities/environmentSettings.ts +80 -0
|
@@ -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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
180
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
351
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|
|
461
|
-
|
|
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
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
485
|
-
const
|
|
486
|
-
for (const
|
|
487
|
-
|
|
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
|
|
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
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
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
|
-
|
|
583
|
-
|
|
584
|
-
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
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
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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
|
}
|