@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.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 (124) hide show
  1. package/jest.config.js +8 -1
  2. package/lib/index.cjs +13793 -12854
  3. package/lib/index.js +13782 -12851
  4. package/lib/src/Ad4mClient.test.d.ts +1 -0
  5. package/lib/src/Ad4mClient.test.js +1204 -0
  6. package/lib/src/Literal.test.d.ts +1 -0
  7. package/lib/src/Literal.test.js +41 -0
  8. package/lib/src/model/Ad4mModel.d.ts +528 -101
  9. package/lib/src/model/Ad4mModel.js +1670 -748
  10. package/lib/src/model/Ad4mModel.test.js +140 -156
  11. package/lib/src/model/Subject.d.ts +3 -3
  12. package/lib/src/model/Subject.js +25 -25
  13. package/lib/src/model/decorators.d.ts +259 -247
  14. package/lib/src/model/decorators.js +379 -422
  15. package/lib/src/model/mutation.d.ts +81 -0
  16. package/lib/src/model/mutation.js +317 -0
  17. package/lib/src/model/parentUtils.d.ts +32 -0
  18. package/lib/src/model/parentUtils.js +64 -0
  19. package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
  20. package/lib/src/model/prolog/generatePrologFacts.js +139 -0
  21. package/lib/src/model/prolog/index.d.ts +1 -0
  22. package/lib/src/model/prolog/index.js +1 -0
  23. package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
  24. package/lib/src/model/query/ModelQueryBuilder.js +115 -0
  25. package/lib/src/model/query/QueryBuilder.d.ts +101 -0
  26. package/lib/src/model/query/QueryBuilder.js +193 -0
  27. package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
  28. package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
  29. package/lib/src/model/query/fetchInstance.d.ts +24 -0
  30. package/lib/src/model/query/fetchInstance.js +144 -0
  31. package/lib/src/model/query/hydration.d.ts +54 -0
  32. package/lib/src/model/query/hydration.js +214 -0
  33. package/lib/src/model/query/operations.d.ts +59 -0
  34. package/lib/src/model/query/operations.js +384 -0
  35. package/lib/src/model/query/snapshot.d.ts +59 -0
  36. package/lib/src/model/query/snapshot.js +106 -0
  37. package/lib/src/model/query/surrealCompiler.d.ts +42 -0
  38. package/lib/src/model/query/surrealCompiler.js +304 -0
  39. package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
  40. package/lib/src/model/schema/fromJSONSchema.js +264 -0
  41. package/lib/src/model/schema/metadata.d.ts +15 -0
  42. package/lib/src/model/schema/metadata.js +112 -0
  43. package/lib/src/model/subscription.d.ts +47 -0
  44. package/lib/src/model/subscription.js +231 -0
  45. package/lib/src/model/transaction.d.ts +27 -0
  46. package/lib/src/model/transaction.js +32 -0
  47. package/lib/src/model/types.d.ts +195 -0
  48. package/lib/src/model/types.js +8 -0
  49. package/lib/src/model/util.d.ts +6 -6
  50. package/lib/src/model/util.js +22 -22
  51. package/lib/src/neighbourhood/NeighbourhoodClient.js +31 -12
  52. package/lib/src/perspectives/PerspectiveProxy.d.ts +9 -9
  53. package/lib/src/perspectives/PerspectiveProxy.js +63 -51
  54. package/lib/src/shacl/SHACLShape.d.ts +9 -0
  55. package/lib/src/shacl/SHACLShape.js +28 -4
  56. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  57. package/lib/src/shims/type-graphql.d.ts +32 -0
  58. package/lib/src/src/Ad4mClient.d.ts +28 -0
  59. package/lib/src/src/Address.d.ts +1 -0
  60. package/lib/src/src/DID.d.ts +1 -0
  61. package/lib/src/src/Exception.d.ts +7 -0
  62. package/lib/src/src/Literal.d.ts +7 -0
  63. package/lib/src/src/PubSub.d.ts +17 -0
  64. package/lib/src/src/SmartLiteral.d.ts +12 -0
  65. package/lib/src/src/agent/Agent.d.ts +110 -0
  66. package/lib/src/src/agent/AgentClient.d.ts +62 -0
  67. package/lib/src/src/agent/AgentResolver.d.ts +30 -0
  68. package/lib/src/src/agent/AgentStatus.d.ts +8 -0
  69. package/lib/src/src/ai/AIClient.d.ts +32 -0
  70. package/lib/src/src/ai/AIResolver.d.ts +75 -0
  71. package/lib/src/src/ai/Tasks.d.ts +37 -0
  72. package/lib/src/src/buildSchema.d.ts +1 -0
  73. package/lib/src/src/expression/Expression.d.ts +28 -0
  74. package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
  75. package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
  76. package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
  77. package/lib/src/src/index.d.ts +35 -0
  78. package/lib/src/src/jestSetup.d.ts +1 -0
  79. package/lib/src/src/language/Icon.d.ts +4 -0
  80. package/lib/src/src/language/Language.d.ts +206 -0
  81. package/lib/src/src/language/LanguageClient.d.ts +17 -0
  82. package/lib/src/src/language/LanguageContext.d.ts +37 -0
  83. package/lib/src/src/language/LanguageHandle.d.ts +9 -0
  84. package/lib/src/src/language/LanguageMeta.d.ts +35 -0
  85. package/lib/src/src/language/LanguageRef.d.ts +6 -0
  86. package/lib/src/src/language/LanguageResolver.d.ts +19 -0
  87. package/lib/src/src/links/Links.d.ts +39 -0
  88. package/lib/src/src/links/Links.test.d.ts +1 -0
  89. package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
  90. package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
  91. package/lib/src/src/model/Subject.d.ts +25 -0
  92. package/lib/src/src/model/decorators.d.ts +545 -0
  93. package/lib/src/src/model/util.d.ts +12 -0
  94. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
  95. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  96. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  97. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  98. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  99. package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
  100. package/lib/src/src/perspectives/Perspective.d.ts +38 -0
  101. package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
  102. package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
  103. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
  104. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
  105. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
  106. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
  107. package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
  108. package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
  109. package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
  110. package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
  111. package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
  112. package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
  113. package/lib/src/src/typeDefs.d.ts +1 -0
  114. package/lib/src/src/unwrapApolloResult.d.ts +2 -0
  115. package/lib/src/src/utils.d.ts +25 -0
  116. package/package.json +20 -24
  117. package/src/model/Ad4mModel.test.ts +132 -149
  118. package/src/model/Ad4mModel.ts +1930 -784
  119. package/src/model/Subject.ts +24 -24
  120. package/src/model/decorators.ts +626 -482
  121. package/src/model/util.ts +22 -22
  122. package/src/neighbourhood/NeighbourhoodClient.ts +32 -16
  123. package/src/perspectives/PerspectiveProxy.ts +69 -55
  124. package/src/shacl/SHACLShape.ts +33 -4
@@ -14,6 +14,7 @@ import { Link } from "../links/Links";
14
14
  import { LinkQuery } from "./LinkQuery";
15
15
  import { Literal } from "../Literal";
16
16
  import { Subject } from "../model/Subject";
17
+ import { getPropertiesMetadata, getRelationsMetadata } from "../model/decorators";
17
18
  import { escapeSurrealString } from "../utils";
18
19
  import { SHACLShape } from "../shacl/SHACLShape";
19
20
  import { SHACLFlow } from "../shacl/SHACLFlow";
@@ -392,7 +393,7 @@ export class PerspectiveProxy {
392
393
  * - `addLink`: Creates a new link
393
394
  * - `removeLink`: Removes an existing link
394
395
  * - `setSingleTarget`: Removes all existing links with the same source/predicate and adds a new one
395
- * - `collectionSetter`: Special command for setting collection properties
396
+ * - `collectionSetter`: Special command for setting relation properties
396
397
  *
397
398
  * When used with parameters, the special value "value" in the target field will be
398
399
  * replaced with the actual parameter value.
@@ -1010,7 +1011,7 @@ export class PerspectiveProxy {
1010
1011
  * shape.addProperty({
1011
1012
  * name: 'ingredients',
1012
1013
  * path: 'recipe://has_ingredient',
1013
- * // No maxCount = collection
1014
+ * // No maxCount = relation
1014
1015
  * });
1015
1016
  *
1016
1017
  * await perspective.addShacl('Recipe', shape);
@@ -1416,8 +1417,8 @@ export class PerspectiveProxy {
1416
1417
  const requiredPredicates = [];
1417
1418
  const requiredTriples = [];
1418
1419
  const properties = new Map();
1419
- const collections = new Map();
1420
- // Build property/collection maps and track writable predicates from shape properties
1420
+ const relations = new Map();
1421
+ // Build property/relation maps and track writable predicates from shape properties
1421
1422
  const writablePredicates = new Set();
1422
1423
  for (const prop of shape.properties) {
1423
1424
  if (!prop.path || !prop.name)
@@ -1425,9 +1426,9 @@ export class PerspectiveProxy {
1425
1426
  if (prop.writable) {
1426
1427
  writablePredicates.add(prop.path);
1427
1428
  }
1428
- const isCollection = prop.adder && prop.adder.length > 0;
1429
- if (isCollection) {
1430
- collections.set(prop.name, { predicate: prop.path });
1429
+ const isRelation = prop.adder && prop.adder.length > 0;
1430
+ if (isRelation) {
1431
+ relations.set(prop.name, { predicate: prop.path });
1431
1432
  }
1432
1433
  else {
1433
1434
  properties.set(prop.name, {
@@ -1451,7 +1452,7 @@ export class PerspectiveProxy {
1451
1452
  }
1452
1453
  }
1453
1454
  }
1454
- return { requiredPredicates, requiredTriples, properties, collections };
1455
+ return { requiredPredicates, requiredTriples, properties, relations };
1455
1456
  }
1456
1457
  catch (e) {
1457
1458
  console.error(`Error getting SHACL metadata for ${className}:`, e);
@@ -1520,21 +1521,21 @@ export class PerspectiveProxy {
1520
1521
  return value;
1521
1522
  }
1522
1523
  /**
1523
- * Gets collection values using SurrealDB when Prolog fails.
1524
+ * Gets relation values using SurrealDB when Prolog fails.
1524
1525
  * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
1525
1526
  * Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
1526
1527
  */
1527
- async getCollectionValuesViaSurreal(baseExpression, className, collectionName) {
1528
+ async getRelationValuesViaSurreal(baseExpression, className, relationName) {
1528
1529
  const metadata = await this.getSubjectClassMetadataFromSDNA(className);
1529
1530
  if (!metadata) {
1530
1531
  return [];
1531
1532
  }
1532
- const collMeta = metadata.collections.get(collectionName);
1533
- if (!collMeta) {
1533
+ const relMeta = metadata.relations.get(relationName);
1534
+ if (!relMeta) {
1534
1535
  return [];
1535
1536
  }
1536
1537
  const escapedBaseExpression = escapeSurrealString(baseExpression);
1537
- const escapedPredicate = escapeSurrealString(collMeta.predicate);
1538
+ const escapedPredicate = escapeSurrealString(relMeta.predicate);
1538
1539
  const query = `SELECT out.uri AS value, timestamp FROM link WHERE in.uri = '${escapedBaseExpression}' AND predicate = '${escapedPredicate}' ORDER BY timestamp ASC`;
1539
1540
  const result = await this.querySurrealDB(query);
1540
1541
  if (!result || result.length === 0) {
@@ -1542,11 +1543,11 @@ export class PerspectiveProxy {
1542
1543
  }
1543
1544
  let values = result.map(r => r.value).filter(v => v !== "" && v !== '');
1544
1545
  // Apply condition filtering if present
1545
- if (collMeta.condition && values.length > 0) {
1546
+ if (relMeta.condition && values.length > 0) {
1546
1547
  try {
1547
1548
  const filteredValues = [];
1548
1549
  for (const value of values) {
1549
- let condition = collMeta.condition
1550
+ let condition = relMeta.condition
1550
1551
  .replace(/\$perspective/g, `'${this.uuid}'`)
1551
1552
  .replace(/\$base/g, `'${baseExpression}'`)
1552
1553
  .replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
@@ -1563,22 +1564,22 @@ export class PerspectiveProxy {
1563
1564
  values = filteredValues;
1564
1565
  }
1565
1566
  catch (error) {
1566
- console.warn(`Failed to apply condition filter for ${collectionName}:`, error);
1567
+ console.warn(`Failed to apply condition filter for ${relationName}:`, error);
1567
1568
  }
1568
1569
  }
1569
1570
  // Apply instance filter if present - batch-check all values at once
1570
- if (collMeta.instanceFilter) {
1571
+ if (relMeta.instanceFilter) {
1571
1572
  try {
1572
- const filterMetadata = await this.getSubjectClassMetadataFromSDNA(collMeta.instanceFilter);
1573
+ const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
1573
1574
  if (!filterMetadata) {
1574
1575
  // Fallback to sequential checks if metadata isn't available
1575
- return this.filterInstancesSequential(values, collMeta.instanceFilter);
1576
+ return this.filterInstancesSequential(values, relMeta.instanceFilter);
1576
1577
  }
1577
1578
  return await this.batchCheckSubjectInstances(values, filterMetadata);
1578
1579
  }
1579
1580
  catch (err) {
1580
1581
  // Fallback to sequential checks on error
1581
- return this.filterInstancesSequential(values, collMeta.instanceFilter);
1582
+ return this.filterInstancesSequential(values, relMeta.instanceFilter);
1582
1583
  }
1583
1584
  }
1584
1585
  return values;
@@ -1742,31 +1743,36 @@ export class PerspectiveProxy {
1742
1743
  return instances;
1743
1744
  }
1744
1745
  /**
1745
- * Find a subject class by matching an object's properties/collections against SHACL shapes.
1746
+ * Find a subject class by matching an object's properties/relations against SHACL shapes.
1746
1747
  * Queries SHACL links client-side to find a class whose properties contain all required ones.
1747
1748
  * @returns The matching class name, or null if no match found.
1748
1749
  */
1749
1750
  async findClassByProperties(obj) {
1750
- // Extract properties and collections from the object
1751
+ // Extract properties and relations from the object
1751
1752
  let properties = [];
1752
- let collections = [];
1753
+ let relations = [];
1753
1754
  const proto = Object.getPrototypeOf(obj);
1754
- if (proto?.__properties) {
1755
- properties = Object.keys(proto.__properties);
1755
+ const ctor = proto?.constructor;
1756
+ const registryProps = ctor ? getPropertiesMetadata(ctor) : {};
1757
+ if (Object.keys(registryProps).length > 0) {
1758
+ properties = Object.keys(registryProps);
1756
1759
  }
1757
1760
  else {
1758
1761
  properties = Object.keys(obj).filter(key => !Array.isArray(obj[key]));
1759
1762
  }
1760
- if (proto?.__collections) {
1761
- collections = Object.keys(proto.__collections).filter(key => key !== 'isSubjectInstance');
1763
+ const registryRelations = ctor
1764
+ ? Object.fromEntries(Object.entries(getRelationsMetadata(ctor)).filter(([, r]) => r.kind === 'hasMany' || r.kind === 'belongsToMany'))
1765
+ : {};
1766
+ if (Object.keys(registryRelations).length > 0) {
1767
+ relations = Object.keys(registryRelations).filter(key => key !== 'isSubjectInstance');
1762
1768
  }
1763
1769
  else {
1764
- collections = Object.keys(obj).filter(key => Array.isArray(obj[key]) && key !== 'isSubjectInstance');
1770
+ relations = Object.keys(obj).filter(key => Array.isArray(obj[key]) && key !== 'isSubjectInstance');
1765
1771
  }
1766
- if (properties.length === 0 && collections.length === 0) {
1772
+ if (properties.length === 0 && relations.length === 0) {
1767
1773
  return null;
1768
1774
  }
1769
- // Single SurrealDB query to find all classes and their properties/collections
1775
+ // Single SurrealDB query to find all classes and their properties/relations
1770
1776
  const query = `SELECT
1771
1777
  in.uri AS shape_source,
1772
1778
  predicate,
@@ -1776,7 +1782,7 @@ export class PerspectiveProxy {
1776
1782
  const results = await this.querySurrealDB(query);
1777
1783
  if (!results || results.length === 0)
1778
1784
  return null;
1779
- // Build a map of className -> { properties, collections }
1785
+ // Build a map of className -> { properties, relations }
1780
1786
  const classShapes = new Map();
1781
1787
  // First pass: find all subject classes
1782
1788
  for (const r of results) {
@@ -1788,10 +1794,10 @@ export class PerspectiveProxy {
1788
1794
  const className = source.substring(sepIdx + 3).split('/').pop();
1789
1795
  if (!className)
1790
1796
  continue;
1791
- classShapes.set(className, { shapeUri: source, properties: [], collections: [] });
1797
+ classShapes.set(className, { shapeUri: source, properties: [], relations: [] });
1792
1798
  }
1793
1799
  }
1794
- // Second pass: collect properties and collections for each class
1800
+ // Second pass: collect properties and relations for each class
1795
1801
  for (const r of results) {
1796
1802
  if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
1797
1803
  // Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
@@ -1805,17 +1811,17 @@ export class PerspectiveProxy {
1805
1811
  shape.properties.push(name);
1806
1812
  }
1807
1813
  else {
1808
- shape.collections.push(name);
1814
+ shape.relations.push(name);
1809
1815
  }
1810
1816
  }
1811
1817
  }
1812
1818
  }
1813
1819
  }
1814
- // Find a class that has all required properties and collections
1820
+ // Find a class that has all required properties and relations
1815
1821
  for (const [className, shape] of classShapes) {
1816
1822
  const hasAllProps = properties.every(p => shape.properties.includes(p));
1817
- const hasAllCols = collections.every(c => shape.collections.includes(c));
1818
- if (hasAllProps && hasAllCols) {
1823
+ const hasAllRels = relations.every(c => shape.relations.includes(c));
1824
+ if (hasAllProps && hasAllRels) {
1819
1825
  return className;
1820
1826
  }
1821
1827
  }
@@ -1823,9 +1829,9 @@ export class PerspectiveProxy {
1823
1829
  }
1824
1830
  /** Returns all subject classes that match the given template object.
1825
1831
  * This function looks at the properties of the template object and
1826
- * its setters and collections to create a Prolog query that finds
1832
+ * its setters and relations to create a Prolog query that finds
1827
1833
  * all subject classes that would be converted to a proxy object
1828
- * with exactly the same properties and collections.
1834
+ * with exactly the same properties and relations.
1829
1835
  *
1830
1836
  * Since there could be multiple subject classes that match the given
1831
1837
  * criteria, this function returns a list of class names.
@@ -1833,17 +1839,13 @@ export class PerspectiveProxy {
1833
1839
  * @param obj The template object
1834
1840
  */
1835
1841
  async subjectClassesByTemplate(obj) {
1836
- // SHACL-based lookup: try property matching first (more precise), fall back to className
1837
- try {
1838
- const match = await this.findClassByProperties(obj);
1839
- if (match) {
1840
- return [match];
1841
- }
1842
- }
1843
- catch (e) {
1844
- console.warn('subjectClassesByTemplate: property matching failed:', e);
1845
- }
1846
- // Fall back to className lookup
1842
+ // className lookup first: the @Model decorator sets a precise className on the prototype,
1843
+ // so this is always more specific than property-set matching.
1844
+ // Property matching alone has a superset-ambiguity problem: if DerivedModel adds
1845
+ // properties to BaseModel, then DerivedModel's shape is a superset of BaseModel's
1846
+ // property list, so findClassByProperties could wrongly return DerivedModel for a
1847
+ // BaseModel instance (causing the derived SDNA constructor to fire and inject extra
1848
+ // links into what should be a plain base instance).
1847
1849
  try {
1848
1850
  // @ts-ignore - className is added dynamically by decorators
1849
1851
  const className = obj.className || obj.constructor?.className || obj.constructor?.prototype?.className;
@@ -1857,6 +1859,16 @@ export class PerspectiveProxy {
1857
1859
  catch (e) {
1858
1860
  console.warn('subjectClassesByTemplate: className lookup failed:', e);
1859
1861
  }
1862
+ // Fall back to SHACL-based property matching for undecorated / dynamic objects
1863
+ try {
1864
+ const match = await this.findClassByProperties(obj);
1865
+ if (match) {
1866
+ return [match];
1867
+ }
1868
+ }
1869
+ catch (e) {
1870
+ console.warn('subjectClassesByTemplate: property matching failed:', e);
1871
+ }
1860
1872
  return [];
1861
1873
  }
1862
1874
  /** Takes a JS class (its constructor) and assumes that it was decorated by
@@ -1871,7 +1883,7 @@ export class PerspectiveProxy {
1871
1883
  // Note: Duplicate checking is handled on the Rust side in add_sdna
1872
1884
  // Generate SHACL SDNA (Prolog-free)
1873
1885
  if (!jsClass.generateSHACL) {
1874
- throw new Error(`Class ${jsClass.name} must have generateSHACL(). Use @ModelOptions decorator.`);
1886
+ throw new Error(`Class ${jsClass.name} must have generateSHACL(). Use @Model decorator.`);
1875
1887
  }
1876
1888
  // Get SHACL shape (W3C standard + AD4M action definitions)
1877
1889
  const { shape } = jsClass.generateSHACL();
@@ -62,6 +62,8 @@ export declare class SHACLShape {
62
62
  constructor_actions?: AD4MAction[];
63
63
  /** AD4M-specific: Destructor actions for removing instances */
64
64
  destructor_actions?: AD4MAction[];
65
+ /** Parent shape URIs for model inheritance (sh:node references) */
66
+ parentShapes: string[];
65
67
  /**
66
68
  * Create a new SHACL Shape
67
69
  * @param targetClassOrShapeUri - If one argument: the target class (shape URI auto-derived as {class}Shape)
@@ -69,6 +71,13 @@ export declare class SHACLShape {
69
71
  * @param targetClass - Optional target class when first arg is shape URI
70
72
  */
71
73
  constructor(targetClassOrShapeUri: string, targetClass?: string);
74
+ /**
75
+ * Add a parent shape reference (sh:node) for model inheritance.
76
+ * When a @Model class extends another @Model, the child shape
77
+ * references the parent shape so SHACL validators can walk the
78
+ * class hierarchy.
79
+ */
80
+ addParentShape(parentShapeUri: string): void;
72
81
  /**
73
82
  * Add a property constraint to this shape
74
83
  */
@@ -99,6 +99,18 @@ export class SHACLShape {
99
99
  this.nodeShapeUri = `${namespace}${localName}Shape`;
100
100
  }
101
101
  this.properties = [];
102
+ this.parentShapes = [];
103
+ }
104
+ /**
105
+ * Add a parent shape reference (sh:node) for model inheritance.
106
+ * When a @Model class extends another @Model, the child shape
107
+ * references the parent shape so SHACL validators can walk the
108
+ * class hierarchy.
109
+ */
110
+ addParentShape(parentShapeUri) {
111
+ if (!this.parentShapes.includes(parentShapeUri)) {
112
+ this.parentShapes.push(parentShapeUri);
113
+ }
102
114
  }
103
115
  /**
104
116
  * Add a property constraint to this shape
@@ -131,6 +143,10 @@ export class SHACLShape {
131
143
  if (this.targetClass) {
132
144
  turtle += ` sh:targetClass <${this.targetClass}> ;\n`;
133
145
  }
146
+ // Emit sh:node references for parent shapes (model inheritance)
147
+ for (const parentUri of this.parentShapes) {
148
+ turtle += ` sh:node <${parentUri}> ;\n`;
149
+ }
134
150
  // Add property shapes
135
151
  for (let i = 0; i < this.properties.length; i++) {
136
152
  const prop = this.properties[i];
@@ -194,16 +210,18 @@ export class SHACLShape {
194
210
  target: this.targetClass
195
211
  });
196
212
  }
197
- // Constructor actions
198
- if (this.constructor_actions && this.constructor_actions.length > 0) {
213
+ // Constructor actions — always emit, even for an empty array.
214
+ // An empty `[]` tells the executor the shape is valid but has no
215
+ // required initial links (all-optional model with no @Flag).
216
+ if (this.constructor_actions) {
199
217
  links.push({
200
218
  source: this.nodeShapeUri,
201
219
  predicate: "ad4m://constructor",
202
220
  target: `literal://string:${JSON.stringify(this.constructor_actions)}`
203
221
  });
204
222
  }
205
- // Destructor actions
206
- if (this.destructor_actions && this.destructor_actions.length > 0) {
223
+ // Destructor actions — same rationale as constructor.
224
+ if (this.destructor_actions) {
207
225
  links.push({
208
226
  source: this.nodeShapeUri,
209
227
  predicate: "ad4m://destructor",
@@ -506,6 +524,7 @@ export class SHACLShape {
506
524
  return {
507
525
  node_shape_uri: this.nodeShapeUri,
508
526
  target_class: this.targetClass,
527
+ parent_shapes: this.parentShapes.length > 0 ? this.parentShapes : undefined,
509
528
  properties: this.properties.map(p => ({
510
529
  path: p.path,
511
530
  name: p.name,
@@ -561,6 +580,11 @@ export class SHACLShape {
561
580
  if (json.destructor_actions) {
562
581
  shape.destructor_actions = json.destructor_actions;
563
582
  }
583
+ if (json.parent_shapes) {
584
+ for (const ps of json.parent_shapes) {
585
+ shape.addParentShape(ps);
586
+ }
587
+ }
564
588
  return shape;
565
589
  }
566
590
  }
File without changes
@@ -0,0 +1,32 @@
1
+ import * as src from "../node_modules/type-graphql/dist/index.js";
2
+ export declare const dummyValue = "";
3
+ export declare function dummyFn(): void;
4
+ export declare function dummyDecorator(): typeof dummyFn;
5
+ export declare const Arg: typeof src.Arg;
6
+ export declare const Args: typeof src.Args;
7
+ export declare const ArgsType: typeof src.ArgsType;
8
+ export declare const Authorized: typeof src.Authorized;
9
+ export declare const Ctx: typeof src.Ctx;
10
+ export declare const registerEnumType: typeof src.registerEnumType;
11
+ export declare const Field: typeof src.Field;
12
+ export declare const FieldResolver: typeof src.FieldResolver;
13
+ export declare const Info: typeof src.Info;
14
+ export declare const InputType: typeof src.InputType;
15
+ export declare const InterfaceType: typeof src.InterfaceType;
16
+ export declare const Mutation: typeof src.Mutation;
17
+ export declare const ObjectType: typeof src.ObjectType;
18
+ export declare const PubSub: typeof src.PubSub;
19
+ export declare const Query: typeof src.Query;
20
+ export declare const Resolver: typeof src.Resolver;
21
+ export declare const Root: typeof src.Root;
22
+ export declare const Subscription: typeof src.Subscription;
23
+ export declare const createUnionType: typeof src.createUnionType;
24
+ export declare const UseMiddleware: typeof src.UseMiddleware;
25
+ export declare const PubSubEngine: typeof src.PubSubEngine;
26
+ export declare class ClassType<t> {
27
+ }
28
+ export declare const Int: typeof src.Int;
29
+ export declare const Float: typeof src.Float;
30
+ export declare const ID: typeof src.ID;
31
+ export declare const GraphQLISODateTime: typeof src.GraphQLISODateTime;
32
+ export declare const GraphQLTimestamp: typeof src.GraphQLTimestamp;
@@ -0,0 +1,28 @@
1
+ import { ApolloClient } from '@apollo/client/core';
2
+ import { AgentClient } from './agent/AgentClient';
3
+ import { LanguageClient } from './language/LanguageClient';
4
+ import { NeighbourhoodClient } from './neighbourhood/NeighbourhoodClient';
5
+ import { PerspectiveClient } from './perspectives/PerspectiveClient';
6
+ import { RuntimeClient } from './runtime/RuntimeClient';
7
+ import { ExpressionClient } from './expression/ExpressionClient';
8
+ import { AIClient } from './ai/AIClient';
9
+ /**
10
+ * Client for the Ad4m interface wrapping GraphQL queryies
11
+ * for convenient use in user facing code.
12
+ *
13
+ * Aggregates the six sub-clients:
14
+ * AgentClient, ExpressionClient, LanguageClient,
15
+ * NeighbourhoodClient, PerspectiveClient and RuntimeClient
16
+ * for the respective functionality.
17
+ */
18
+ export declare class Ad4mClient {
19
+ #private;
20
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
21
+ get agent(): AgentClient;
22
+ get expression(): ExpressionClient;
23
+ get languages(): LanguageClient;
24
+ get neighbourhood(): NeighbourhoodClient;
25
+ get perspective(): PerspectiveClient;
26
+ get runtime(): RuntimeClient;
27
+ get ai(): AIClient;
28
+ }
@@ -0,0 +1 @@
1
+ export type Address = string;
@@ -0,0 +1 @@
1
+ export type DID = string;
@@ -0,0 +1,7 @@
1
+ export declare enum ExceptionType {
2
+ LanguageIsNotLoaded = "LANGUAGE_IS_NOT_LOADED",
3
+ ExpressionIsNotVerified = "EXPRESSION_IS_NOT_VERIFIED",
4
+ AgentIsUntrusted = "AGENT_IS_UNTRUSTED",
5
+ CapabilityRequested = "CAPABILITY_REQUESTED",
6
+ InstallNotificationRequest = "INSTALL_NOTIFICATION_REQUEST"
7
+ }
@@ -0,0 +1,7 @@
1
+ export declare class Literal {
2
+ #private;
3
+ static fromUrl(url: string): Literal;
4
+ static from(literal: any): Literal;
5
+ toUrl(): string;
6
+ get(): any;
7
+ }
@@ -0,0 +1,17 @@
1
+ export declare const AGENT_UPDATED = "agent-updated-topic";
2
+ export declare const AGENT_STATUS_CHANGED = "agent-status-changed-topic";
3
+ export declare const RUNTIME_MESSAGED_RECEIVED_TOPIC = "runtime-messaged-received-topic";
4
+ export declare const PERSPECTIVE_ADDED_TOPIC = "perspective-added-topic";
5
+ export declare const PERSPECTIVE_UPDATED_TOPIC = "perspective-updated-topic";
6
+ export declare const PERSPECTIVE_REMOVED_TOPIC = "perspective-removed-topic";
7
+ export declare const LINK_ADDED_TOPIC = "link-added-topic";
8
+ export declare const LINK_REMOVED_TOPIC = "link-removed-topic";
9
+ export declare const LINK_UDATED_TOPIC = "link-updated-topic";
10
+ export declare const SIGNAL = "signal";
11
+ export declare const EXCEPTION_OCCURRED_TOPIC = "exception-occurred-topic";
12
+ export declare const RUNTIME_NOTIFICATION_REQUESTED_TOPIC = "runtime-notification-requested-topic";
13
+ export declare const RUNTIME_NOTIFICATION_TRIGGERED_TOPIC = "runtime-notification-triggered-topic";
14
+ export declare const NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC = "neighbourhood-signal-received-topic";
15
+ export declare const PERSPECTIVE_SYNC_STATE_CHANGE = "perspective-sync-state-change";
16
+ export declare const APPS_CHANGED = "apps-changed";
17
+ export declare const AI_TRANSCRIPTION_TEXT_TOPIC = "ai-transcription-text-topic";
@@ -0,0 +1,12 @@
1
+ import { PerspectiveProxy } from "./perspectives/PerspectiveProxy";
2
+ export declare const SMART_LITERAL_CONTENT_PREDICATE = "smart_literal://content";
3
+ export declare class SmartLiteral {
4
+ #private;
5
+ constructor(perspective: PerspectiveProxy, base: string);
6
+ get base(): string;
7
+ static create(perspective: PerspectiveProxy, literal: any): Promise<SmartLiteral>;
8
+ static isSmartLiteralBase(perspective: PerspectiveProxy, base: string): Promise<boolean>;
9
+ static getAllSmartLiterals(perspective: PerspectiveProxy): Promise<SmartLiteral[]>;
10
+ get(): Promise<any>;
11
+ set(content: any): Promise<void>;
12
+ }
@@ -0,0 +1,110 @@
1
+ import { Perspective } from "../perspectives/Perspective";
2
+ /** AD4M's representation of an Agent
3
+ *
4
+ * AD4M Agents are build around DIDs, which are used to identify and authenticate the Agent.
5
+ * Conceptually, an Agent is regarded as something that can speak and that can listen.
6
+ *
7
+ * Agents speak by creating Expressions in AD4M Languages which are signed by the Agent's DID key,
8
+ * And they also speak (broadcast) by putting semantic statements into their public "Agent Perspective".
9
+ * They listen (can receive messages) through their "direct message Language".
10
+ *
11
+ * These three aspects are represented by the three fields of this class.
12
+ *
13
+ * This class is used as format for the Expressions in the Agent language.
14
+ * Since AD4M treats DID URIs as addresses for the Agent Language,
15
+ * DIDs are resolved to Expressions that are objects of this class.
16
+ * Thus, this is how agents see (other) agents.
17
+ */
18
+ export declare class Agent {
19
+ /** The DID of the Agent
20
+ * All epxressions authored by them are signed with the keys mentioned
21
+ * in the DID document behind this DID URI.
22
+ */
23
+ did: string;
24
+ /** The Perspective that holds the public-facing semantics/statements of the Agent
25
+ * Holds and shares a Perspective that links all information
26
+ * this agent wants to offer as public-facing semantics.
27
+ * This should be used for any kind of user profile information.
28
+ */
29
+ perspective?: Perspective;
30
+ /** Address of the Language by which the Agent will receive DMs */
31
+ directMessageLanguage?: string;
32
+ constructor(did: string, perspective?: Perspective);
33
+ }
34
+ declare const AgentExpression_base: any;
35
+ export declare class AgentExpression extends AgentExpression_base {
36
+ }
37
+ export declare class EntanglementProof {
38
+ did: string;
39
+ didSigningKeyId: string;
40
+ deviceKeyType: string;
41
+ deviceKey: string;
42
+ deviceKeySignedByDid: string;
43
+ didSignedByDeviceKey?: string;
44
+ constructor(did: string, didSigningKeyId: string, deviceKeyType: string, deviceKey: string, deviceKeySignedByDid: string, didSignedByDeviceKey?: string);
45
+ }
46
+ export declare class EntanglementProofInput {
47
+ did: string;
48
+ didSigningKeyId: string;
49
+ deviceKeyType: string;
50
+ deviceKey: string;
51
+ deviceKeySignedByDid: string;
52
+ didSignedByDeviceKey: string;
53
+ constructor(did: string, didSigningKeyId: string, deviceKeyType: string, deviceKey: string, deviceKeySignedByDid: string, didSignedByDeviceKey: string);
54
+ }
55
+ export declare class AgentSignature {
56
+ signature: string;
57
+ publicKey: string;
58
+ constructor(signature: string, publicKey: string);
59
+ }
60
+ export declare class Resource {
61
+ domain: string;
62
+ pointers: string[];
63
+ constructor(domain: string, pointers: string[]);
64
+ }
65
+ export declare class Capability {
66
+ with: Resource;
67
+ can: string[];
68
+ constructor(withF: Resource, can: string[]);
69
+ }
70
+ export declare class AuthInfo {
71
+ appName: string;
72
+ appDesc: string;
73
+ appUrl: string;
74
+ appIconPath?: string;
75
+ capabilities: Capability[];
76
+ constructor(appName: string, appDesc: string, appUrl: string, capabilities: Capability[], appIconPath?: string);
77
+ }
78
+ export declare class Apps {
79
+ requestId: string;
80
+ token: string;
81
+ revoked?: boolean;
82
+ auth: AuthInfo;
83
+ constructor(requestId: string, auth: AuthInfo, token: string, revoked?: boolean);
84
+ }
85
+ export declare class ResourceInput {
86
+ domain: string;
87
+ pointers: string[];
88
+ constructor(domain: string, pointers: string[]);
89
+ }
90
+ export declare class CapabilityInput {
91
+ with: ResourceInput;
92
+ can: string[];
93
+ constructor(withF: ResourceInput, can: string[]);
94
+ }
95
+ export declare class AuthInfoInput {
96
+ appName: string;
97
+ appDesc: string;
98
+ appDomain: string;
99
+ appUrl?: string;
100
+ appIconPath?: string;
101
+ capabilities?: CapabilityInput[];
102
+ constructor(appName: string, appDesc: string, appDomain: string, appUrl?: string, appIconPath?: string, capabilities?: CapabilityInput[]);
103
+ }
104
+ export declare class UserCreationResult {
105
+ did: string;
106
+ success: boolean;
107
+ error?: string;
108
+ constructor(did: string, success: boolean, error?: string);
109
+ }
110
+ export {};