@coasys/ad4m 0.10.1-release-candidate-4 → 0.10.1
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/lib/index.cjs +80 -3
- package/lib/index.js +80 -3
- package/lib/src/model/Ad4mModel.js +20 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +4 -0
- package/lib/src/perspectives/PerspectiveProxy.js +60 -3
- package/package.json +1 -1
- package/src/model/Ad4mModel.ts +20 -0
- package/src/perspectives/PerspectiveProxy.ts +73 -5
package/lib/index.cjs
CHANGED
|
@@ -5304,10 +5304,63 @@ class PerspectiveProxy {
|
|
|
5304
5304
|
* This will return all SDNA code elements in an array.
|
|
5305
5305
|
*/
|
|
5306
5306
|
async getSdna() {
|
|
5307
|
-
|
|
5307
|
+
// First, find all the name literals that are linked from ad4m://self with SDNA predicates
|
|
5308
|
+
const sdnaPredicates = [
|
|
5309
|
+
"ad4m://has_subject_class",
|
|
5310
|
+
"ad4m://has_flow",
|
|
5311
|
+
"ad4m://has_custom_sdna"
|
|
5312
|
+
];
|
|
5313
|
+
const allSdnaCode = [];
|
|
5314
|
+
for (const predicate of sdnaPredicates) {
|
|
5315
|
+
// Find name literals linked from ad4m://self with this predicate
|
|
5316
|
+
const nameLinks = await this.get(new exports.LinkQuery({
|
|
5317
|
+
source: "ad4m://self",
|
|
5318
|
+
predicate: predicate
|
|
5319
|
+
}));
|
|
5320
|
+
// For each name literal found, get the actual SDNA code
|
|
5321
|
+
for (const nameLink of nameLinks) {
|
|
5322
|
+
const nameLiteral = nameLink.data.target;
|
|
5323
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
5324
|
+
const sdnaLinks = await this.get(new exports.LinkQuery({
|
|
5325
|
+
source: nameLiteral,
|
|
5326
|
+
predicate: "ad4m://sdna"
|
|
5327
|
+
}));
|
|
5328
|
+
// Extract the SDNA code from each link
|
|
5329
|
+
for (const sdnaLink of sdnaLinks) {
|
|
5330
|
+
const code = Literal.fromUrl(sdnaLink.data.target).get();
|
|
5331
|
+
if (typeof code === 'string') {
|
|
5332
|
+
allSdnaCode.push(code);
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
return allSdnaCode;
|
|
5338
|
+
}
|
|
5339
|
+
/** Returns the Social DNA code for a specific class
|
|
5340
|
+
* This will return the SDNA code for the specified class, or null if not found.
|
|
5341
|
+
*/
|
|
5342
|
+
async getSdnaForClass(className) {
|
|
5343
|
+
// First, find the name literal for this class that is linked from ad4m://self
|
|
5344
|
+
const nameLiteral = Literal.from(className);
|
|
5345
|
+
const links = await this.get(new exports.LinkQuery({
|
|
5346
|
+
source: "ad4m://self",
|
|
5347
|
+
target: nameLiteral.toUrl(),
|
|
5348
|
+
predicate: "ad4m://has_subject_class"
|
|
5349
|
+
}));
|
|
5350
|
+
if (links.length === 0) {
|
|
5351
|
+
return null;
|
|
5352
|
+
}
|
|
5353
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
5354
|
+
const sdnaLinks = await this.get(new exports.LinkQuery({
|
|
5355
|
+
source: nameLiteral.toUrl(),
|
|
5308
5356
|
predicate: "ad4m://sdna"
|
|
5309
5357
|
}));
|
|
5310
|
-
|
|
5358
|
+
if (sdnaLinks.length === 0) {
|
|
5359
|
+
return null;
|
|
5360
|
+
}
|
|
5361
|
+
// Extract the SDNA code from the first link
|
|
5362
|
+
const code = Literal.fromUrl(sdnaLinks[0].data.target).get();
|
|
5363
|
+
return typeof code === 'string' ? code : null;
|
|
5311
5364
|
}
|
|
5312
5365
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
5313
5366
|
async addSdna(name, sdnaCode, sdnaType) {
|
|
@@ -5488,7 +5541,11 @@ class PerspectiveProxy {
|
|
|
5488
5541
|
}
|
|
5489
5542
|
// Collect all collections of the object in a list
|
|
5490
5543
|
if (Object.getPrototypeOf(obj).__collections) {
|
|
5491
|
-
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c =>
|
|
5544
|
+
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c => {
|
|
5545
|
+
if (!collections.includes(c)) {
|
|
5546
|
+
collections.push(c);
|
|
5547
|
+
}
|
|
5548
|
+
});
|
|
5492
5549
|
}
|
|
5493
5550
|
else {
|
|
5494
5551
|
collections.push(...Object.keys(obj).filter(key => Array.isArray(obj[key])).filter(key => key !== 'isSubjectInstance'));
|
|
@@ -17803,6 +17860,26 @@ class Ad4mModel {
|
|
|
17803
17860
|
// Map properties to object
|
|
17804
17861
|
const propsObject = Object.fromEntries(await Promise.all(values.map(async ([name, value, resolve]) => {
|
|
17805
17862
|
let finalValue = value;
|
|
17863
|
+
// Handle UTF-8 byte sequences from Prolog URL decoding
|
|
17864
|
+
if (!resolve && typeof value === 'string') {
|
|
17865
|
+
// Only attempt reconstruction if the string looks like a byte string (all code points <= 0xFF)
|
|
17866
|
+
// and contains at least one high byte (>= 0x80). This avoids mangling valid Unicode.
|
|
17867
|
+
const codePoints = Array.from(value, ch => ch.codePointAt(0));
|
|
17868
|
+
const looksByteString = codePoints.every(cp => cp <= 0xFF);
|
|
17869
|
+
const hasHighByte = codePoints.some(cp => cp >= 0x80);
|
|
17870
|
+
if (looksByteString && hasHighByte) {
|
|
17871
|
+
try {
|
|
17872
|
+
const bytes = Uint8Array.from(codePoints);
|
|
17873
|
+
const decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
17874
|
+
if (decoded !== value)
|
|
17875
|
+
finalValue = decoded;
|
|
17876
|
+
}
|
|
17877
|
+
catch (error) {
|
|
17878
|
+
// If UTF-8 conversion fails, keep the original value
|
|
17879
|
+
console.warn(`UTF-8 byte reconstruction failed for property "${name}"`, { value, error });
|
|
17880
|
+
}
|
|
17881
|
+
}
|
|
17882
|
+
}
|
|
17806
17883
|
// Resolve the value if necessary
|
|
17807
17884
|
if (resolve) {
|
|
17808
17885
|
let resolvedExpression = await perspective.getExpression(value);
|
package/lib/index.js
CHANGED
|
@@ -5300,10 +5300,63 @@ class PerspectiveProxy {
|
|
|
5300
5300
|
* This will return all SDNA code elements in an array.
|
|
5301
5301
|
*/
|
|
5302
5302
|
async getSdna() {
|
|
5303
|
-
|
|
5303
|
+
// First, find all the name literals that are linked from ad4m://self with SDNA predicates
|
|
5304
|
+
const sdnaPredicates = [
|
|
5305
|
+
"ad4m://has_subject_class",
|
|
5306
|
+
"ad4m://has_flow",
|
|
5307
|
+
"ad4m://has_custom_sdna"
|
|
5308
|
+
];
|
|
5309
|
+
const allSdnaCode = [];
|
|
5310
|
+
for (const predicate of sdnaPredicates) {
|
|
5311
|
+
// Find name literals linked from ad4m://self with this predicate
|
|
5312
|
+
const nameLinks = await this.get(new LinkQuery({
|
|
5313
|
+
source: "ad4m://self",
|
|
5314
|
+
predicate: predicate
|
|
5315
|
+
}));
|
|
5316
|
+
// For each name literal found, get the actual SDNA code
|
|
5317
|
+
for (const nameLink of nameLinks) {
|
|
5318
|
+
const nameLiteral = nameLink.data.target;
|
|
5319
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
5320
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
5321
|
+
source: nameLiteral,
|
|
5322
|
+
predicate: "ad4m://sdna"
|
|
5323
|
+
}));
|
|
5324
|
+
// Extract the SDNA code from each link
|
|
5325
|
+
for (const sdnaLink of sdnaLinks) {
|
|
5326
|
+
const code = Literal.fromUrl(sdnaLink.data.target).get();
|
|
5327
|
+
if (typeof code === 'string') {
|
|
5328
|
+
allSdnaCode.push(code);
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
return allSdnaCode;
|
|
5334
|
+
}
|
|
5335
|
+
/** Returns the Social DNA code for a specific class
|
|
5336
|
+
* This will return the SDNA code for the specified class, or null if not found.
|
|
5337
|
+
*/
|
|
5338
|
+
async getSdnaForClass(className) {
|
|
5339
|
+
// First, find the name literal for this class that is linked from ad4m://self
|
|
5340
|
+
const nameLiteral = Literal.from(className);
|
|
5341
|
+
const links = await this.get(new LinkQuery({
|
|
5342
|
+
source: "ad4m://self",
|
|
5343
|
+
target: nameLiteral.toUrl(),
|
|
5344
|
+
predicate: "ad4m://has_subject_class"
|
|
5345
|
+
}));
|
|
5346
|
+
if (links.length === 0) {
|
|
5347
|
+
return null;
|
|
5348
|
+
}
|
|
5349
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
5350
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
5351
|
+
source: nameLiteral.toUrl(),
|
|
5304
5352
|
predicate: "ad4m://sdna"
|
|
5305
5353
|
}));
|
|
5306
|
-
|
|
5354
|
+
if (sdnaLinks.length === 0) {
|
|
5355
|
+
return null;
|
|
5356
|
+
}
|
|
5357
|
+
// Extract the SDNA code from the first link
|
|
5358
|
+
const code = Literal.fromUrl(sdnaLinks[0].data.target).get();
|
|
5359
|
+
return typeof code === 'string' ? code : null;
|
|
5307
5360
|
}
|
|
5308
5361
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
5309
5362
|
async addSdna(name, sdnaCode, sdnaType) {
|
|
@@ -5484,7 +5537,11 @@ class PerspectiveProxy {
|
|
|
5484
5537
|
}
|
|
5485
5538
|
// Collect all collections of the object in a list
|
|
5486
5539
|
if (Object.getPrototypeOf(obj).__collections) {
|
|
5487
|
-
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c =>
|
|
5540
|
+
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c => {
|
|
5541
|
+
if (!collections.includes(c)) {
|
|
5542
|
+
collections.push(c);
|
|
5543
|
+
}
|
|
5544
|
+
});
|
|
5488
5545
|
}
|
|
5489
5546
|
else {
|
|
5490
5547
|
collections.push(...Object.keys(obj).filter(key => Array.isArray(obj[key])).filter(key => key !== 'isSubjectInstance'));
|
|
@@ -17799,6 +17856,26 @@ class Ad4mModel {
|
|
|
17799
17856
|
// Map properties to object
|
|
17800
17857
|
const propsObject = Object.fromEntries(await Promise.all(values.map(async ([name, value, resolve]) => {
|
|
17801
17858
|
let finalValue = value;
|
|
17859
|
+
// Handle UTF-8 byte sequences from Prolog URL decoding
|
|
17860
|
+
if (!resolve && typeof value === 'string') {
|
|
17861
|
+
// Only attempt reconstruction if the string looks like a byte string (all code points <= 0xFF)
|
|
17862
|
+
// and contains at least one high byte (>= 0x80). This avoids mangling valid Unicode.
|
|
17863
|
+
const codePoints = Array.from(value, ch => ch.codePointAt(0));
|
|
17864
|
+
const looksByteString = codePoints.every(cp => cp <= 0xFF);
|
|
17865
|
+
const hasHighByte = codePoints.some(cp => cp >= 0x80);
|
|
17866
|
+
if (looksByteString && hasHighByte) {
|
|
17867
|
+
try {
|
|
17868
|
+
const bytes = Uint8Array.from(codePoints);
|
|
17869
|
+
const decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
17870
|
+
if (decoded !== value)
|
|
17871
|
+
finalValue = decoded;
|
|
17872
|
+
}
|
|
17873
|
+
catch (error) {
|
|
17874
|
+
// If UTF-8 conversion fails, keep the original value
|
|
17875
|
+
console.warn(`UTF-8 byte reconstruction failed for property "${name}"`, { value, error });
|
|
17876
|
+
}
|
|
17877
|
+
}
|
|
17878
|
+
}
|
|
17802
17879
|
// Resolve the value if necessary
|
|
17803
17880
|
if (resolve) {
|
|
17804
17881
|
let resolvedExpression = await perspective.getExpression(value);
|
|
@@ -314,6 +314,26 @@ export class Ad4mModel {
|
|
|
314
314
|
// Map properties to object
|
|
315
315
|
const propsObject = Object.fromEntries(await Promise.all(values.map(async ([name, value, resolve]) => {
|
|
316
316
|
let finalValue = value;
|
|
317
|
+
// Handle UTF-8 byte sequences from Prolog URL decoding
|
|
318
|
+
if (!resolve && typeof value === 'string') {
|
|
319
|
+
// Only attempt reconstruction if the string looks like a byte string (all code points <= 0xFF)
|
|
320
|
+
// and contains at least one high byte (>= 0x80). This avoids mangling valid Unicode.
|
|
321
|
+
const codePoints = Array.from(value, ch => ch.codePointAt(0));
|
|
322
|
+
const looksByteString = codePoints.every(cp => cp <= 0xFF);
|
|
323
|
+
const hasHighByte = codePoints.some(cp => cp >= 0x80);
|
|
324
|
+
if (looksByteString && hasHighByte) {
|
|
325
|
+
try {
|
|
326
|
+
const bytes = Uint8Array.from(codePoints);
|
|
327
|
+
const decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
328
|
+
if (decoded !== value)
|
|
329
|
+
finalValue = decoded;
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
// If UTF-8 conversion fails, keep the original value
|
|
333
|
+
console.warn(`UTF-8 byte reconstruction failed for property "${name}"`, { value, error });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
317
337
|
// Resolve the value if necessary
|
|
318
338
|
if (resolve) {
|
|
319
339
|
let resolvedExpression = await perspective.getExpression(value);
|
|
@@ -482,6 +482,10 @@ export declare class PerspectiveProxy {
|
|
|
482
482
|
* This will return all SDNA code elements in an array.
|
|
483
483
|
*/
|
|
484
484
|
getSdna(): Promise<string[]>;
|
|
485
|
+
/** Returns the Social DNA code for a specific class
|
|
486
|
+
* This will return the SDNA code for the specified class, or null if not found.
|
|
487
|
+
*/
|
|
488
|
+
getSdnaForClass(className: string): Promise<string | null>;
|
|
485
489
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
486
490
|
addSdna(name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean>;
|
|
487
491
|
/** Returns all the Subject classes defined in this perspectives SDNA */
|
|
@@ -703,10 +703,63 @@ export class PerspectiveProxy {
|
|
|
703
703
|
* This will return all SDNA code elements in an array.
|
|
704
704
|
*/
|
|
705
705
|
async getSdna() {
|
|
706
|
-
|
|
706
|
+
// First, find all the name literals that are linked from ad4m://self with SDNA predicates
|
|
707
|
+
const sdnaPredicates = [
|
|
708
|
+
"ad4m://has_subject_class",
|
|
709
|
+
"ad4m://has_flow",
|
|
710
|
+
"ad4m://has_custom_sdna"
|
|
711
|
+
];
|
|
712
|
+
const allSdnaCode = [];
|
|
713
|
+
for (const predicate of sdnaPredicates) {
|
|
714
|
+
// Find name literals linked from ad4m://self with this predicate
|
|
715
|
+
const nameLinks = await this.get(new LinkQuery({
|
|
716
|
+
source: "ad4m://self",
|
|
717
|
+
predicate: predicate
|
|
718
|
+
}));
|
|
719
|
+
// For each name literal found, get the actual SDNA code
|
|
720
|
+
for (const nameLink of nameLinks) {
|
|
721
|
+
const nameLiteral = nameLink.data.target;
|
|
722
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
723
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
724
|
+
source: nameLiteral,
|
|
725
|
+
predicate: "ad4m://sdna"
|
|
726
|
+
}));
|
|
727
|
+
// Extract the SDNA code from each link
|
|
728
|
+
for (const sdnaLink of sdnaLinks) {
|
|
729
|
+
const code = Literal.fromUrl(sdnaLink.data.target).get();
|
|
730
|
+
if (typeof code === 'string') {
|
|
731
|
+
allSdnaCode.push(code);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return allSdnaCode;
|
|
737
|
+
}
|
|
738
|
+
/** Returns the Social DNA code for a specific class
|
|
739
|
+
* This will return the SDNA code for the specified class, or null if not found.
|
|
740
|
+
*/
|
|
741
|
+
async getSdnaForClass(className) {
|
|
742
|
+
// First, find the name literal for this class that is linked from ad4m://self
|
|
743
|
+
const nameLiteral = Literal.from(className);
|
|
744
|
+
const links = await this.get(new LinkQuery({
|
|
745
|
+
source: "ad4m://self",
|
|
746
|
+
target: nameLiteral.toUrl(),
|
|
747
|
+
predicate: "ad4m://has_subject_class"
|
|
748
|
+
}));
|
|
749
|
+
if (links.length === 0) {
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
753
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
754
|
+
source: nameLiteral.toUrl(),
|
|
707
755
|
predicate: "ad4m://sdna"
|
|
708
756
|
}));
|
|
709
|
-
|
|
757
|
+
if (sdnaLinks.length === 0) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
// Extract the SDNA code from the first link
|
|
761
|
+
const code = Literal.fromUrl(sdnaLinks[0].data.target).get();
|
|
762
|
+
return typeof code === 'string' ? code : null;
|
|
710
763
|
}
|
|
711
764
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
712
765
|
async addSdna(name, sdnaCode, sdnaType) {
|
|
@@ -887,7 +940,11 @@ export class PerspectiveProxy {
|
|
|
887
940
|
}
|
|
888
941
|
// Collect all collections of the object in a list
|
|
889
942
|
if (Object.getPrototypeOf(obj).__collections) {
|
|
890
|
-
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c =>
|
|
943
|
+
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c => {
|
|
944
|
+
if (!collections.includes(c)) {
|
|
945
|
+
collections.push(c);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
891
948
|
}
|
|
892
949
|
else {
|
|
893
950
|
collections.push(...Object.keys(obj).filter(key => Array.isArray(obj[key])).filter(key => key !== 'isSubjectInstance'));
|
package/package.json
CHANGED
package/src/model/Ad4mModel.ts
CHANGED
|
@@ -351,6 +351,26 @@ export class Ad4mModel {
|
|
|
351
351
|
await Promise.all(
|
|
352
352
|
values.map(async ([name, value, resolve]) => {
|
|
353
353
|
let finalValue = value;
|
|
354
|
+
|
|
355
|
+
// Handle UTF-8 byte sequences from Prolog URL decoding
|
|
356
|
+
if (!resolve && typeof value === 'string') {
|
|
357
|
+
// Only attempt reconstruction if the string looks like a byte string (all code points <= 0xFF)
|
|
358
|
+
// and contains at least one high byte (>= 0x80). This avoids mangling valid Unicode.
|
|
359
|
+
const codePoints = Array.from(value, ch => ch.codePointAt(0)!);
|
|
360
|
+
const looksByteString = codePoints.every(cp => cp <= 0xFF);
|
|
361
|
+
const hasHighByte = codePoints.some(cp => cp >= 0x80);
|
|
362
|
+
if (looksByteString && hasHighByte) {
|
|
363
|
+
try {
|
|
364
|
+
const bytes = Uint8Array.from(codePoints);
|
|
365
|
+
const decoded = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
366
|
+
if (decoded !== value) finalValue = decoded;
|
|
367
|
+
} catch (error) {
|
|
368
|
+
// If UTF-8 conversion fails, keep the original value
|
|
369
|
+
console.warn(`UTF-8 byte reconstruction failed for property "${name}"`, { value, error });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
354
374
|
// Resolve the value if necessary
|
|
355
375
|
if (resolve) {
|
|
356
376
|
let resolvedExpression = await perspective.getExpression(value);
|
|
@@ -782,11 +782,75 @@ export class PerspectiveProxy {
|
|
|
782
782
|
* This will return all SDNA code elements in an array.
|
|
783
783
|
*/
|
|
784
784
|
async getSdna(): Promise<string[]> {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
785
|
+
// First, find all the name literals that are linked from ad4m://self with SDNA predicates
|
|
786
|
+
const sdnaPredicates = [
|
|
787
|
+
"ad4m://has_subject_class",
|
|
788
|
+
"ad4m://has_flow",
|
|
789
|
+
"ad4m://has_custom_sdna"
|
|
790
|
+
];
|
|
791
|
+
|
|
792
|
+
const allSdnaCode: string[] = [];
|
|
793
|
+
|
|
794
|
+
for (const predicate of sdnaPredicates) {
|
|
795
|
+
// Find name literals linked from ad4m://self with this predicate
|
|
796
|
+
const nameLinks = await this.get(new LinkQuery({
|
|
797
|
+
source: "ad4m://self",
|
|
798
|
+
predicate: predicate
|
|
799
|
+
}));
|
|
800
|
+
|
|
801
|
+
// For each name literal found, get the actual SDNA code
|
|
802
|
+
for (const nameLink of nameLinks) {
|
|
803
|
+
const nameLiteral = nameLink.data.target;
|
|
804
|
+
|
|
805
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
806
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
807
|
+
source: nameLiteral,
|
|
808
|
+
predicate: "ad4m://sdna"
|
|
809
|
+
}));
|
|
810
|
+
|
|
811
|
+
// Extract the SDNA code from each link
|
|
812
|
+
for (const sdnaLink of sdnaLinks) {
|
|
813
|
+
const code = Literal.fromUrl(sdnaLink.data.target).get();
|
|
814
|
+
if (typeof code === 'string') {
|
|
815
|
+
allSdnaCode.push(code);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return allSdnaCode;
|
|
822
|
+
}
|
|
788
823
|
|
|
789
|
-
|
|
824
|
+
/** Returns the Social DNA code for a specific class
|
|
825
|
+
* This will return the SDNA code for the specified class, or null if not found.
|
|
826
|
+
*/
|
|
827
|
+
async getSdnaForClass(className: string): Promise<string | null> {
|
|
828
|
+
// First, find the name literal for this class that is linked from ad4m://self
|
|
829
|
+
const nameLiteral = Literal.from(className);
|
|
830
|
+
|
|
831
|
+
const links = await this.get(new LinkQuery({
|
|
832
|
+
source: "ad4m://self",
|
|
833
|
+
target: nameLiteral.toUrl(),
|
|
834
|
+
predicate: "ad4m://has_subject_class"
|
|
835
|
+
}));
|
|
836
|
+
|
|
837
|
+
if (links.length === 0) {
|
|
838
|
+
return null;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// Now find the SDNA code linked from this name with predicate "ad4m://sdna"
|
|
842
|
+
const sdnaLinks = await this.get(new LinkQuery({
|
|
843
|
+
source: nameLiteral.toUrl(),
|
|
844
|
+
predicate: "ad4m://sdna"
|
|
845
|
+
}));
|
|
846
|
+
|
|
847
|
+
if (sdnaLinks.length === 0) {
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// Extract the SDNA code from the first link
|
|
852
|
+
const code = Literal.fromUrl(sdnaLinks[0].data.target).get();
|
|
853
|
+
return typeof code === 'string' ? code : null;
|
|
790
854
|
}
|
|
791
855
|
|
|
792
856
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
@@ -1002,7 +1066,11 @@ export class PerspectiveProxy {
|
|
|
1002
1066
|
|
|
1003
1067
|
// Collect all collections of the object in a list
|
|
1004
1068
|
if (Object.getPrototypeOf(obj).__collections) {
|
|
1005
|
-
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c =>
|
|
1069
|
+
Object.keys(Object.getPrototypeOf(obj).__collections).filter(key => key !== 'isSubjectInstance').forEach(c => {
|
|
1070
|
+
if (!collections.includes(c)) {
|
|
1071
|
+
collections.push(c);
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1006
1074
|
} else {
|
|
1007
1075
|
collections.push(...Object.keys(obj).filter(key => Array.isArray(obj[key])).filter(key => key !== 'isSubjectInstance'))
|
|
1008
1076
|
}
|