@manifest-editor/creator-api 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 digirati-co-uk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Creator API
2
+
3
+ - What do you want to create
4
+ - The type + refined type
5
+ - The fields you add
6
+ - Static fields
7
+ - Where is it valid to create
8
+ - Parent type
9
+ - Custom parent supports
10
+ - Parent fields
11
+ - Canvas specific: how does it affect the canvas
12
+ - temporal
13
+ - spatial
14
+ - What can it export as:
15
+ - Canvas
16
+ - Annotation
17
+ - Resource
18
+ - Other
19
+ - Does it replace resources? (e.g. choice)
20
+ - Does it require canvas interaction
21
+
22
+ Examples (cookbook)
23
+
24
+ - Simple image
25
+ - Simple audio
26
+ - Simple video
27
+ - Image with service
28
+ - Cropped image (with service)
29
+ - External HTML link
30
+ - External PDF
31
+ - External XML
32
+ - External plaintext?
33
+ - Commenting annotation on canvas
34
+ - Tagging annotation at box
35
+ - Creating range from canvas selection?
36
+ - Creating choice from list of annotations
37
+
38
+ The creation process is split into two parts:
39
+
40
+ - The UI (e.g. the form that's presented to the user)
41
+ - The building/creation process
42
+
43
+ The creation process is intended to be dual purpose. This is not a great example, but here you can see that you can "call" other creators inside this creator. So they can become composable.
44
+
45
+ ```ts
46
+ async function createThing(ctx) {
47
+ const image = await ctx.create("@manifest-editor/create-image", {
48
+ url: "https://example.org/image-1.jpg",
49
+ });
50
+
51
+ // If you want the underlying resource you just created.
52
+ const previewResource = image.get();
53
+
54
+ // Find a reference to an existing resource.
55
+ const ref = ctx.ref("https://example.org/canvas-1");
56
+
57
+ // Or you can create new resources that will be embedded.
58
+ const image2 = ctx.embed({
59
+ id: "https://example.org/image-2.jpg",
60
+ type: "Image",
61
+ height: 100,
62
+ width: 200,
63
+ });
64
+
65
+ // And then it can be part of a bigger resource:
66
+ // This cannot be a nested tree - it must be a flat resource with linked resources (like thumbnail) as
67
+ // objects like `ctx.create()` or `ctx.embed()`. This makes sure that we can piece together the finaly
68
+ // actions required in the last step.
69
+ return {
70
+ id: "https://example.org/image-3.jpg",
71
+ type: "Image",
72
+ height: ctx.data.height,
73
+ width: ctx.data.width,
74
+ thumbnail: [image],
75
+ };
76
+ }
77
+ ```
78
+
79
+ A "create" callback will be passed to the render, this is when this will be called and the resource will be created. Once created `edit()` will be called on the resource.
package/dist/index.cjs ADDED
@@ -0,0 +1,557 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ Creator: () => Creator,
29
+ CreatorResource: () => CreatorResource
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+
33
+ // src/Creator.ts
34
+ var import_vault = require("@iiif/helpers/vault");
35
+
36
+ // src/CreatorRuntime.ts
37
+ var import_actions = require("@iiif/helpers/vault/actions");
38
+
39
+ // src/CreatorResource.ts
40
+ var import_editor_api = require("@manifest-editor/editor-api");
41
+
42
+ // src/ReferencedResource.ts
43
+ var import_parser = require("@iiif/parser");
44
+ var ReferencedResource = class {
45
+ constructor(reference, vault) {
46
+ __publicField(this, "vault");
47
+ __publicField(this, "original");
48
+ __publicField(this, "reference");
49
+ __publicField(this, "resource");
50
+ this.vault = vault;
51
+ this.original = reference;
52
+ this.reference = (0, import_parser.isSpecificResource)(reference) ? reference.source : reference;
53
+ this.resource = (0, import_parser.isSpecificResource)(reference) ? reference : { type: "SpecificResource", source: this.reference };
54
+ }
55
+ // @todo editable specific resource.
56
+ ref() {
57
+ return this.reference;
58
+ }
59
+ specificResource() {
60
+ return this.resource;
61
+ }
62
+ optionalSpecificResource() {
63
+ if ((0, import_parser.isSpecificResource)(this.original)) {
64
+ return {
65
+ ...this.original,
66
+ source: { id: this.original.source?.id, type: this.original.source?.type }
67
+ };
68
+ }
69
+ return this.original;
70
+ }
71
+ get() {
72
+ return this.vault.get(this.resource);
73
+ }
74
+ };
75
+
76
+ // src/utils.ts
77
+ var import_parser2 = require("@iiif/parser");
78
+ function resolveType(type) {
79
+ switch (type) {
80
+ case "Image":
81
+ case "Video":
82
+ case "Sound":
83
+ case "Dataset":
84
+ case "Text":
85
+ case "TextualBody":
86
+ case "Composite":
87
+ case "List":
88
+ case "Independents":
89
+ case "Audience":
90
+ return "ContentResource";
91
+ case "ImageService1":
92
+ case "ImageService2":
93
+ case "ImageService3":
94
+ return "Service";
95
+ }
96
+ return type;
97
+ }
98
+ var emptyTypes = {
99
+ Annotation: import_parser2.emptyAnnotation,
100
+ AnnotationPage: import_parser2.emptyAnnotationPage,
101
+ Canvas: import_parser2.emptyCanvas,
102
+ Collection: import_parser2.emptyCollection,
103
+ Manifest: import_parser2.emptyManifest,
104
+ Range: import_parser2.emptyRange,
105
+ ResourceProvider: import_parser2.emptyAgent,
106
+ Service: import_parser2.emptyService
107
+ };
108
+ function getEmptyType(type) {
109
+ const key = resolveType(type);
110
+ return emptyTypes[key] || {};
111
+ }
112
+ function randomId() {
113
+ return `${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`;
114
+ }
115
+
116
+ // src/CreatorResource.ts
117
+ var import_parser3 = require("@iiif/parser");
118
+ var CreatorResource = class _CreatorResource {
119
+ constructor(data, vault) {
120
+ __publicField(this, "resource");
121
+ __publicField(this, "warnings", []);
122
+ __publicField(this, "errors", []);
123
+ __publicField(this, "partOf");
124
+ __publicField(this, "references", []);
125
+ __publicField(this, "embedded", []);
126
+ __publicField(this, "vault");
127
+ __publicField(this, "specificResource");
128
+ this.vault = vault;
129
+ if (data.type === "SpecificResource") {
130
+ const source = data.source;
131
+ this.specificResource = { ...data, source: { id: source.id, type: resolveType(source.type) } };
132
+ data = source;
133
+ }
134
+ const properties = Object.keys(data);
135
+ const defaultType = getEmptyType(data.type);
136
+ for (const key of properties) {
137
+ if (import_editor_api.references.inlineProperties.includes(key) || !import_editor_api.references.all.includes(key)) {
138
+ continue;
139
+ }
140
+ if (data.type === "Range" && key === "items") {
141
+ const newRange = [];
142
+ for (const range of data[key]) {
143
+ if (range instanceof ReferencedResource) {
144
+ this.references.push(range);
145
+ newRange.push(range);
146
+ continue;
147
+ }
148
+ const rangeRef = new ReferencedResource(range, vault);
149
+ newRange.push(rangeRef);
150
+ data[key] = rangeRef;
151
+ continue;
152
+ }
153
+ data[key] = newRange;
154
+ continue;
155
+ }
156
+ if (data.type === "Manifest" && key === "start") {
157
+ const start = data[key];
158
+ if (start instanceof ReferencedResource) {
159
+ this.references.push(start);
160
+ continue;
161
+ }
162
+ const startRef = new ReferencedResource(start, vault);
163
+ data[key] = startRef;
164
+ continue;
165
+ }
166
+ if (data.type === "Annotation" && key === "target") {
167
+ let target = data[key];
168
+ if (target instanceof ReferencedResource) {
169
+ this.references.push(target);
170
+ continue;
171
+ }
172
+ if (typeof target === "string") {
173
+ target = { id: target, type: "Canvas" };
174
+ }
175
+ const targetRef = new ReferencedResource(target, vault);
176
+ data[key] = targetRef;
177
+ continue;
178
+ }
179
+ if (import_editor_api.references.single.includes(key)) {
180
+ continue;
181
+ }
182
+ if (import_editor_api.references.externalProperties.includes(key) || import_editor_api.references.internalProperties.includes(key)) {
183
+ const _items = data[key] || [];
184
+ const items = Array.isArray(_items) ? _items : [_items];
185
+ const newItems = [];
186
+ for (const item of items) {
187
+ if (item instanceof ReferencedResource) {
188
+ this.references.push(item);
189
+ newItems.push(item);
190
+ continue;
191
+ }
192
+ if (item instanceof _CreatorResource) {
193
+ this.embedded.push(item);
194
+ newItems.push(item);
195
+ continue;
196
+ }
197
+ const exists = this.vault.get(item, { skipSelfReturn: true });
198
+ if (exists) {
199
+ const type = resolveType(item.type);
200
+ const newItem = new ReferencedResource({ id: item.id, type }, vault);
201
+ this.references.push(newItem);
202
+ newItems.push(newItem);
203
+ } else {
204
+ const newItem = new _CreatorResource(item, vault);
205
+ this.embedded.push(newItem);
206
+ newItems.push(newItem);
207
+ }
208
+ }
209
+ data[key] = newItems;
210
+ }
211
+ }
212
+ this.resource = { ...defaultType, ...data };
213
+ }
214
+ // This is what is returned from the creator instance
215
+ get() {
216
+ return this.resource;
217
+ }
218
+ ref() {
219
+ if (this.specificResource) {
220
+ return this.specificResource;
221
+ }
222
+ return { id: this.resource.id, type: resolveType(this.resource.type) };
223
+ }
224
+ getAllReferencedResources() {
225
+ return this.references;
226
+ }
227
+ getAllEmbeddedResources() {
228
+ const allEmbedded = [];
229
+ for (const resource of this.embedded) {
230
+ allEmbedded.push(...resource.getAllEmbeddedResources());
231
+ }
232
+ allEmbedded.push(...this.embedded);
233
+ return allEmbedded;
234
+ }
235
+ getVaultResource() {
236
+ const resource = this.resource;
237
+ const properties = Object.keys(resource);
238
+ const newResource = {};
239
+ for (const key of properties) {
240
+ if (import_editor_api.references.inlineProperties.includes(key) || !import_editor_api.references.all.includes(key)) {
241
+ newResource[key] = resource[key];
242
+ continue;
243
+ }
244
+ if (import_editor_api.references.single.includes(key)) {
245
+ const ref = resource[key];
246
+ if (ref instanceof ReferencedResource) {
247
+ if (resource.type === "Manifest" && key === "start" || resource.type === "Annotation" && key === "target") {
248
+ newResource[key] = ref.specificResource();
249
+ } else {
250
+ newResource[key] = ref.optionalSpecificResource();
251
+ }
252
+ } else {
253
+ newResource[key] = resource[key];
254
+ }
255
+ continue;
256
+ }
257
+ if (resource[key]) {
258
+ newResource[key] = [];
259
+ for (const item of resource[key] || []) {
260
+ if (item instanceof ReferencedResource) {
261
+ newResource[key].push(item.optionalSpecificResource());
262
+ }
263
+ if (item instanceof _CreatorResource) {
264
+ newResource[key].push(item.ref());
265
+ }
266
+ }
267
+ }
268
+ }
269
+ if (this.partOf) {
270
+ newResource[import_parser3.HAS_PART] = newResource[import_parser3.HAS_PART] || [];
271
+ newResource[import_parser3.HAS_PART].push(this.partOf);
272
+ }
273
+ return newResource;
274
+ }
275
+ setPartOf(id) {
276
+ const ref = this.ref();
277
+ this.partOf = {
278
+ id: ref.id,
279
+ type: resolveType(ref.type),
280
+ [import_parser3.PART_OF]: id
281
+ };
282
+ }
283
+ };
284
+
285
+ // src/CreatorInstance.ts
286
+ var CreatorInstance = class {
287
+ constructor(vault, options, createConfigs, previewVault) {
288
+ __publicField(this, "vault");
289
+ __publicField(this, "previewVault");
290
+ __publicField(this, "configs");
291
+ __publicField(this, "options");
292
+ this.vault = vault;
293
+ this.previewVault = previewVault;
294
+ this.options = options;
295
+ this.configs = createConfigs;
296
+ }
297
+ getPreviewVault() {
298
+ return this.previewVault;
299
+ }
300
+ getTarget() {
301
+ const target = this.options.target || this.options.parent?.resource;
302
+ const position = this.options.initialData?.selector;
303
+ if (position && position.type === "polygon") {
304
+ const position2 = this.options.initialData?.selector;
305
+ const { width, height } = this.options.initialData?.on || {};
306
+ if (position2.shape.points.length === 0) {
307
+ return target;
308
+ }
309
+ if (position2.shape.points.length === 1) {
310
+ const points = position2.shape.points[0];
311
+ return {
312
+ type: "SpecificResource",
313
+ source: target,
314
+ selector: {
315
+ type: "PointSelector",
316
+ x: points[0],
317
+ y: points[1]
318
+ }
319
+ };
320
+ }
321
+ if (position2.shape.points.length === 4) {
322
+ const [topLeft, topRight, bottomRight, bottomLeft] = position2.shape.points;
323
+ if (topLeft[0] === topRight[0] && topLeft[1] === bottomLeft[1] && topRight[1] === bottomRight[1] && bottomLeft[0] === bottomRight[0]) {
324
+ const x = Math.min(topLeft[0], topRight[0], bottomRight[0], bottomLeft[0]);
325
+ const y = Math.min(topLeft[1], topRight[1], bottomRight[1], bottomLeft[1]);
326
+ const x2 = Math.max(topLeft[0], topRight[0], bottomRight[0], bottomLeft[0]);
327
+ const y2 = Math.max(topLeft[1], topRight[1], bottomRight[1], bottomLeft[1]);
328
+ const width2 = x2 - x;
329
+ const height2 = y2 - y;
330
+ return {
331
+ type: "SpecificResource",
332
+ source: target,
333
+ selector: {
334
+ type: "FragmentSelector",
335
+ value: `xywh=${[~~x, ~~y, ~~width2, ~~height2].join(",")}`
336
+ }
337
+ };
338
+ }
339
+ }
340
+ const el = position2.shape.open ? "polyline" : "polygon";
341
+ return {
342
+ type: "SpecificResource",
343
+ source: target,
344
+ selector: {
345
+ type: "SvgSelector",
346
+ value: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}"><${el} points="${position2.shape.points.map((p) => p.join(",")).join(" ")}" /></svg>`
347
+ }
348
+ };
349
+ }
350
+ if (target && position) {
351
+ return {
352
+ type: "SpecificResource",
353
+ source: target,
354
+ selector: {
355
+ type: "FragmentSelector",
356
+ value: `xywh=${[~~position.x, ~~position.y, ~~position.width, ~~position.height].join(",")}`
357
+ }
358
+ };
359
+ }
360
+ return target;
361
+ }
362
+ getParent() {
363
+ return this.options.parent?.resource;
364
+ }
365
+ getParentResource() {
366
+ const parent = this.getParent();
367
+ if (parent) {
368
+ return {
369
+ type: "SpecificResource",
370
+ source: parent
371
+ };
372
+ }
373
+ }
374
+ generateId(type, parent) {
375
+ if (parent && parent instanceof ReferencedResource) {
376
+ parent = parent.ref();
377
+ }
378
+ return `${(parent || this.options.parent?.resource)?.id}/${type}/${randomId()}`;
379
+ }
380
+ ref(idOrRef) {
381
+ let id = "";
382
+ let type = "";
383
+ if (typeof idOrRef === "string") {
384
+ id = idOrRef;
385
+ } else {
386
+ id = idOrRef.id;
387
+ type = idOrRef.type;
388
+ }
389
+ const state = this.vault.getState();
390
+ const realType = state.iiif.mapping[id];
391
+ if (!realType) {
392
+ type = type || "unknown";
393
+ } else {
394
+ type = realType;
395
+ }
396
+ return new ReferencedResource({ id, type }, this.vault);
397
+ }
398
+ embed(data) {
399
+ return new CreatorResource(data, this.vault);
400
+ }
401
+ async create(definition, payload, options) {
402
+ const foundDefinition = this.configs.find((t) => t.id === definition);
403
+ if (!foundDefinition) {
404
+ throw new Error(`Creator config ${definition} not found`);
405
+ }
406
+ const runtime = new CreatorRuntime(this.vault, foundDefinition, payload, this.configs, this.previewVault, options);
407
+ return await runtime.run();
408
+ }
409
+ };
410
+
411
+ // src/CreatorRuntime.ts
412
+ var CreatorRuntime = class {
413
+ constructor(vault, definition, payload, createConfigs, previewVault, options) {
414
+ // This will hold state for the creation process
415
+ __publicField(this, "resource", null);
416
+ __publicField(this, "payload");
417
+ __publicField(this, "vault");
418
+ __publicField(this, "previewVault");
419
+ __publicField(this, "definition");
420
+ __publicField(this, "options");
421
+ __publicField(this, "configs");
422
+ this.vault = vault;
423
+ this.previewVault = previewVault;
424
+ this.definition = definition;
425
+ this.payload = payload;
426
+ this.configs = createConfigs;
427
+ this.options = {
428
+ targetType: (options || {}).targetType || definition.resourceType,
429
+ ...options || {}
430
+ };
431
+ }
432
+ async run() {
433
+ const instance = new CreatorInstance(this.vault, this.options, this.configs, this.previewVault);
434
+ const result = await this.definition.create(this.payload, instance);
435
+ if (result instanceof CreatorResource) {
436
+ this.resource = result;
437
+ } else {
438
+ this.resource = new CreatorResource(result, this.vault);
439
+ }
440
+ return this.resource;
441
+ }
442
+ getActions() {
443
+ if (!this.resource) {
444
+ return [];
445
+ }
446
+ const actions = [];
447
+ const resources = {};
448
+ const mapping = {};
449
+ if (this.options.parent) {
450
+ this.resource.setPartOf(this.options.parent.resource.id);
451
+ }
452
+ const embedded = this.resource.getAllEmbeddedResources();
453
+ const allItems = [...embedded, this.resource];
454
+ for (const item of allItems) {
455
+ const resource = item.getVaultResource();
456
+ if (!resource.type || !resource.id) {
457
+ continue;
458
+ }
459
+ const type = resolveType(resource.type);
460
+ resources[type] = resources[type] ? resources[type] : {};
461
+ resources[type][resource.id] = resource;
462
+ mapping[resource.id] = type;
463
+ }
464
+ actions.push((0, import_actions.importEntities)({ entities: resources }));
465
+ actions.push((0, import_actions.addMappings)({ mapping }));
466
+ return actions;
467
+ }
468
+ commit(afterActions = []) {
469
+ if (!this.resource) {
470
+ throw new Error("Creator has not been run");
471
+ }
472
+ const actions = this.getActions();
473
+ this.vault.dispatch((0, import_actions.batchActions)({ actions: [...actions, ...afterActions] }));
474
+ return this.resource.ref();
475
+ }
476
+ };
477
+
478
+ // src/Creator.ts
479
+ var import_actions2 = require("@iiif/helpers/vault/actions");
480
+ var Creator = class {
481
+ constructor(vault, configs, previewVault) {
482
+ __publicField(this, "configs");
483
+ __publicField(this, "vault");
484
+ __publicField(this, "previewVault");
485
+ this.configs = configs || [];
486
+ this.vault = vault;
487
+ this.previewVault = previewVault || new import_vault.Vault();
488
+ }
489
+ async create(definition, payload, options) {
490
+ const foundDefinition = this.configs.find((t) => t.id === definition);
491
+ if (!foundDefinition) {
492
+ throw new Error(`Creator config ${definition} not found`);
493
+ }
494
+ if (options?.parent) {
495
+ if (foundDefinition.supports.parentTypes) {
496
+ if (!foundDefinition.supports.parentTypes.includes(options.parent.resource.type)) {
497
+ throw new Error(`Definition ${definition} does not support parent type ${options.parent.resource.type}`);
498
+ }
499
+ }
500
+ if (foundDefinition.supports.parentFields) {
501
+ if (!foundDefinition.supports.parentFields.includes(options.parent.property)) {
502
+ throw new Error(`Definition ${definition} does not support parent field ${options.parent.property}`);
503
+ }
504
+ }
505
+ if (foundDefinition.supports.parentFieldMap) {
506
+ const type = foundDefinition.supports.parentFieldMap[options.parent.resource.type];
507
+ if (!type || !type.includes(options.parent.property)) {
508
+ throw new Error(
509
+ `Definition ${definition} does not support parent ${options.parent.property} / ${options.parent.property}`
510
+ );
511
+ }
512
+ }
513
+ if (foundDefinition.supports.custom) {
514
+ const isValid = foundDefinition.supports.custom(options.parent, this.vault);
515
+ if (!isValid) {
516
+ throw new Error(`Definition does not support resource`);
517
+ }
518
+ }
519
+ }
520
+ const runtime = new CreatorRuntime(this.vault, foundDefinition, payload, this.configs, this.previewVault, options);
521
+ const resource = await runtime.run();
522
+ const afterActions = [];
523
+ if (options?.parent) {
524
+ if (options.parent.property === "start" || options.parent.property === "target") {
525
+ afterActions.push(
526
+ import_actions2.entityActions.modifyEntityField({
527
+ id: options.parent.resource.id,
528
+ type: options.parent.resource.type,
529
+ value: resource.ref(),
530
+ key: options.parent.property
531
+ })
532
+ );
533
+ } else {
534
+ afterActions.push(
535
+ import_actions2.entityActions.addReference({
536
+ id: options.parent.resource.id,
537
+ type: options.parent.resource.type,
538
+ reference: resource.ref(),
539
+ key: options.parent.property,
540
+ index: options.parent.atIndex
541
+ })
542
+ );
543
+ }
544
+ }
545
+ const result = runtime.commit(afterActions);
546
+ if (options?.parent) {
547
+ if (foundDefinition.sideEffects) {
548
+ for (const sideEffect of foundDefinition.sideEffects) {
549
+ if (sideEffect.run) {
550
+ await sideEffect.run(result, { vault: this.vault, options });
551
+ }
552
+ }
553
+ }
554
+ }
555
+ return result;
556
+ }
557
+ };