holosphere 1.1.8 → 1.1.10
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/federation.js +67 -21
- package/holosphere.js +601 -455
- package/package.json +1 -1
- package/test/auth.test.js +35 -19
- package/test/delete.test.js +1 -0
- package/test/holosphere.test.js +189 -5
- package/test/reference.test.js +211 -0
- package/test/subscription.test.js +329 -0
- package/babel.config.js +0 -5
- package/babel.config.json +0 -12
package/federation.js
CHANGED
|
@@ -520,13 +520,13 @@ export async function getFederated(holosphere, holon, lens, options = {}) {
|
|
|
520
520
|
|
|
521
521
|
console.log(`Extracting from soul - holon: ${originHolon}, lens: ${originLens}, key: ${originKey}`);
|
|
522
522
|
|
|
523
|
-
// Get original data using the extracted path
|
|
523
|
+
// Get original data using the extracted path - always resolve references
|
|
524
524
|
const originalData = await holosphere.get(
|
|
525
525
|
originHolon,
|
|
526
526
|
originLens,
|
|
527
527
|
originKey,
|
|
528
528
|
null,
|
|
529
|
-
{ resolveReferences:
|
|
529
|
+
{ resolveReferences: true } // Always resolve nested references
|
|
530
530
|
);
|
|
531
531
|
|
|
532
532
|
console.log(`Original data found via soul path:`, JSON.stringify(originalData));
|
|
@@ -545,12 +545,45 @@ export async function getFederated(holosphere, holon, lens, options = {}) {
|
|
|
545
545
|
console.log(`Reference resolved successfully via soul path, processed item:`, JSON.stringify(result[i]));
|
|
546
546
|
} else {
|
|
547
547
|
console.warn(`Could not resolve reference: original data not found at extracted path`);
|
|
548
|
+
// Instead of leaving the original reference, create an error object
|
|
549
|
+
result[i] = {
|
|
550
|
+
id: item.id,
|
|
551
|
+
_federation: {
|
|
552
|
+
isReference: true,
|
|
553
|
+
resolved: false,
|
|
554
|
+
soul: item.soul,
|
|
555
|
+
error: 'Referenced data not found',
|
|
556
|
+
timestamp: Date.now()
|
|
557
|
+
}
|
|
558
|
+
};
|
|
548
559
|
}
|
|
549
560
|
} else {
|
|
550
561
|
console.warn(`Soul doesn't match expected format: ${item.soul}`);
|
|
562
|
+
// Instead of leaving the original reference, create an error object
|
|
563
|
+
result[i] = {
|
|
564
|
+
id: item.id,
|
|
565
|
+
_federation: {
|
|
566
|
+
isReference: true,
|
|
567
|
+
resolved: false,
|
|
568
|
+
soul: item.soul,
|
|
569
|
+
error: 'Invalid soul format',
|
|
570
|
+
timestamp: Date.now()
|
|
571
|
+
}
|
|
572
|
+
};
|
|
551
573
|
}
|
|
552
574
|
} catch (refError) {
|
|
553
575
|
console.warn(`Error resolving reference by soul in getFederated: ${refError.message}`);
|
|
576
|
+
// Instead of leaving the original reference, create an error object
|
|
577
|
+
result[i] = {
|
|
578
|
+
id: item.id,
|
|
579
|
+
_federation: {
|
|
580
|
+
isReference: true,
|
|
581
|
+
resolved: false,
|
|
582
|
+
soul: item.soul,
|
|
583
|
+
error: refError.message || 'Error resolving reference',
|
|
584
|
+
timestamp: Date.now()
|
|
585
|
+
}
|
|
586
|
+
};
|
|
554
587
|
}
|
|
555
588
|
}
|
|
556
589
|
// For backward compatibility, check for old-style references
|
|
@@ -718,37 +751,50 @@ export async function propagate(holosphere, holon, lens, data, options = {}) {
|
|
|
718
751
|
};
|
|
719
752
|
}
|
|
720
753
|
|
|
754
|
+
// Check if data is already a reference
|
|
755
|
+
const isAlreadyReference = holosphere.isReference(data);
|
|
756
|
+
|
|
721
757
|
// For each target space, propagate the data
|
|
722
758
|
const propagatePromises = spaces.map(async (targetSpace) => {
|
|
723
759
|
try {
|
|
724
|
-
//
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
if (useReferences) {
|
|
729
|
-
// Create a soul path that points to the original data
|
|
730
|
-
const soul = `${holosphere.appname}/${holon}/${lens}/${data.id}`;
|
|
760
|
+
// If using references and data isn't already a reference, create a reference
|
|
761
|
+
if (useReferences && !isAlreadyReference) {
|
|
762
|
+
// Create a reference object using the dedicated utility
|
|
763
|
+
const reference = holosphere.createReference(holon, lens, data);
|
|
731
764
|
|
|
732
|
-
//
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
origin: holon,
|
|
738
|
-
lens: lens,
|
|
739
|
-
timestamp: Date.now()
|
|
740
|
-
}
|
|
765
|
+
// Add federation metadata
|
|
766
|
+
reference._federation = {
|
|
767
|
+
origin: holon,
|
|
768
|
+
lens: lens,
|
|
769
|
+
timestamp: Date.now()
|
|
741
770
|
};
|
|
742
771
|
|
|
743
|
-
console.log(`Using
|
|
772
|
+
console.log(`Using reference: ${reference.soul} for data: ${data.id}`);
|
|
744
773
|
|
|
745
774
|
// Store the reference in the target space without propagation
|
|
746
775
|
await holosphere.put(targetSpace, lens, reference, null, { autoPropagate: false });
|
|
747
776
|
|
|
748
777
|
result.success++;
|
|
749
778
|
return true;
|
|
750
|
-
}
|
|
751
|
-
|
|
779
|
+
}
|
|
780
|
+
// If already a reference, propagate it as is
|
|
781
|
+
else if (isAlreadyReference) {
|
|
782
|
+
// Add federation metadata if needed
|
|
783
|
+
const referenceToStore = {
|
|
784
|
+
...data,
|
|
785
|
+
_federation: data._federation || {
|
|
786
|
+
origin: holon,
|
|
787
|
+
lens: lens,
|
|
788
|
+
timestamp: Date.now()
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
await holosphere.put(targetSpace, lens, referenceToStore, null, { autoPropagate: false });
|
|
793
|
+
result.success++;
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
// Otherwise, store a full copy without propagation
|
|
797
|
+
else {
|
|
752
798
|
const dataToStore = {
|
|
753
799
|
...data,
|
|
754
800
|
_federation: {
|