@coasys/ad4m 0.13.0-test-8 → 0.13.0-test-8-profile-cache-fix

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 (211) hide show
  1. package/lib/index.cjs +14 -9
  2. package/lib/index.js +14 -9
  3. package/lib/src/agent/AgentClient.d.ts +3 -0
  4. package/lib/src/agent/AgentClient.js +12 -7
  5. package/lib/src/model/Ad4mModel.test.js +480 -735
  6. package/lib/src/model/model-manifest.d.ts +41 -0
  7. package/lib/src/model/model-manifest.js +11 -0
  8. package/lib/src/model/query-sparql.js +2 -2
  9. package/lib/src/model/query-sparql.test.js +92 -10
  10. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
  11. package/lib/src/shacl/SHACLShape.test.js +82 -0
  12. package/package.json +8 -11
  13. package/src/agent/AgentClient.ts +14 -9
  14. package/src/model/query-sparql.test.ts +1 -1
  15. package/src/model/query-sparql.ts +2 -2
  16. package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +0 -7
  17. package/lib/src/generated/rest/AIModelLoadingStatus.js +0 -2
  18. package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +0 -3
  19. package/lib/src/generated/rest/AddAgentInfosRequest.js +0 -2
  20. package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +0 -6
  21. package/lib/src/generated/rest/AddLinkExpressionRequest.js +0 -1
  22. package/lib/src/generated/rest/AddLinkRequest.d.ts +0 -6
  23. package/lib/src/generated/rest/AddLinkRequest.js +0 -1
  24. package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +0 -6
  25. package/lib/src/generated/rest/AddLinksBulkRequest.js +0 -1
  26. package/lib/src/generated/rest/AddSdnaRequest.d.ts +0 -6
  27. package/lib/src/generated/rest/AddSdnaRequest.js +0 -2
  28. package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +0 -4
  29. package/lib/src/generated/rest/ApplyTemplateRequest.js +0 -2
  30. package/lib/src/generated/rest/AuthInfoInput.d.ts +0 -10
  31. package/lib/src/generated/rest/AuthInfoInput.js +0 -1
  32. package/lib/src/generated/rest/BroadcastRequest.d.ts +0 -6
  33. package/lib/src/generated/rest/BroadcastRequest.js +0 -1
  34. package/lib/src/generated/rest/CapabilityInput.d.ts +0 -5
  35. package/lib/src/generated/rest/CapabilityInput.js +0 -1
  36. package/lib/src/generated/rest/CommitBatchRequest.d.ts +0 -3
  37. package/lib/src/generated/rest/CommitBatchRequest.js +0 -2
  38. package/lib/src/generated/rest/ComputeLogEntry.d.ts +0 -9
  39. package/lib/src/generated/rest/ComputeLogEntry.js +0 -2
  40. package/lib/src/generated/rest/CreateExpressionRequest.d.ts +0 -4
  41. package/lib/src/generated/rest/CreateExpressionRequest.js +0 -2
  42. package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +0 -3
  43. package/lib/src/generated/rest/CreatePerspectiveRequest.js +0 -2
  44. package/lib/src/generated/rest/CreateSubjectRequest.d.ts +0 -6
  45. package/lib/src/generated/rest/CreateSubjectRequest.js +0 -2
  46. package/lib/src/generated/rest/CreateUserRequest.d.ts +0 -4
  47. package/lib/src/generated/rest/CreateUserRequest.js +0 -2
  48. package/lib/src/generated/rest/CreateUserResponse.d.ts +0 -5
  49. package/lib/src/generated/rest/CreateUserResponse.js +0 -2
  50. package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +0 -6
  51. package/lib/src/generated/rest/DecoratedExpressionProof.js +0 -2
  52. package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +0 -10
  53. package/lib/src/generated/rest/DecoratedLinkExpression.js +0 -1
  54. package/lib/src/generated/rest/DisposeQueryRequest.d.ts +0 -3
  55. package/lib/src/generated/rest/DisposeQueryRequest.js +0 -2
  56. package/lib/src/generated/rest/EmailTestRequest.d.ts +0 -6
  57. package/lib/src/generated/rest/EmailTestRequest.js +0 -2
  58. package/lib/src/generated/rest/EmbedRequest.d.ts +0 -4
  59. package/lib/src/generated/rest/EmbedRequest.js +0 -2
  60. package/lib/src/generated/rest/EntanglementProofInput.d.ts +0 -6
  61. package/lib/src/generated/rest/EntanglementProofInput.js +0 -2
  62. package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +0 -4
  63. package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +0 -2
  64. package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +0 -4
  65. package/lib/src/generated/rest/ExecuteCommandsRequest.js +0 -2
  66. package/lib/src/generated/rest/ExportRequest.d.ts +0 -5
  67. package/lib/src/generated/rest/ExportRequest.js +0 -2
  68. package/lib/src/generated/rest/ExpressionManyRequest.d.ts +0 -3
  69. package/lib/src/generated/rest/ExpressionManyRequest.js +0 -2
  70. package/lib/src/generated/rest/ExpressionProof.d.ts +0 -4
  71. package/lib/src/generated/rest/ExpressionProof.js +0 -2
  72. package/lib/src/generated/rest/ExpressionProofInput.d.ts +0 -6
  73. package/lib/src/generated/rest/ExpressionProofInput.js +0 -2
  74. package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +0 -3
  75. package/lib/src/generated/rest/FriendSendMessageRequest.js +0 -2
  76. package/lib/src/generated/rest/FriendsListRequest.d.ts +0 -3
  77. package/lib/src/generated/rest/FriendsListRequest.js +0 -2
  78. package/lib/src/generated/rest/GenerateAgentRequest.d.ts +0 -3
  79. package/lib/src/generated/rest/GenerateAgentRequest.js +0 -2
  80. package/lib/src/generated/rest/GenerateJwtRequest.d.ts +0 -4
  81. package/lib/src/generated/rest/GenerateJwtRequest.js +0 -2
  82. package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +0 -4
  83. package/lib/src/generated/rest/GetSubjectDataRequest.js +0 -2
  84. package/lib/src/generated/rest/HostingInfoResponse.d.ts +0 -5
  85. package/lib/src/generated/rest/HostingInfoResponse.js +0 -2
  86. package/lib/src/generated/rest/HostingWalletResponse.d.ts +0 -4
  87. package/lib/src/generated/rest/HostingWalletResponse.js +0 -2
  88. package/lib/src/generated/rest/ImportAgentRequest.d.ts +0 -6
  89. package/lib/src/generated/rest/ImportAgentRequest.js +0 -2
  90. package/lib/src/generated/rest/ImportRequest.d.ts +0 -4
  91. package/lib/src/generated/rest/ImportRequest.js +0 -2
  92. package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +0 -3
  93. package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +0 -2
  94. package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +0 -3
  95. package/lib/src/generated/rest/KeepAliveQueryRequest.js +0 -2
  96. package/lib/src/generated/rest/LanguageMetaInput.d.ts +0 -6
  97. package/lib/src/generated/rest/LanguageMetaInput.js +0 -2
  98. package/lib/src/generated/rest/Link.d.ts +0 -5
  99. package/lib/src/generated/rest/Link.js +0 -2
  100. package/lib/src/generated/rest/LinkExpression.d.ts +0 -10
  101. package/lib/src/generated/rest/LinkExpression.js +0 -1
  102. package/lib/src/generated/rest/LinkExpressionInput.d.ts +0 -10
  103. package/lib/src/generated/rest/LinkExpressionInput.js +0 -1
  104. package/lib/src/generated/rest/LinkInput.d.ts +0 -5
  105. package/lib/src/generated/rest/LinkInput.js +0 -2
  106. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +0 -3
  107. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +0 -2
  108. package/lib/src/generated/rest/LinkMutationRequest.d.ts +0 -12
  109. package/lib/src/generated/rest/LinkMutationRequest.js +0 -1
  110. package/lib/src/generated/rest/LinkMutationResponse.d.ts +0 -9
  111. package/lib/src/generated/rest/LinkMutationResponse.js +0 -1
  112. package/lib/src/generated/rest/LinkMutations.d.ts +0 -6
  113. package/lib/src/generated/rest/LinkMutations.js +0 -1
  114. package/lib/src/generated/rest/LinkMutationsRequest.d.ts +0 -5
  115. package/lib/src/generated/rest/LinkMutationsRequest.js +0 -1
  116. package/lib/src/generated/rest/LinkStatus.d.ts +0 -1
  117. package/lib/src/generated/rest/LinkStatus.js +0 -2
  118. package/lib/src/generated/rest/LinkUpdateInput.d.ts +0 -5
  119. package/lib/src/generated/rest/LinkUpdateInput.js +0 -1
  120. package/lib/src/generated/rest/LockAgentRequest.d.ts +0 -3
  121. package/lib/src/generated/rest/LockAgentRequest.js +0 -2
  122. package/lib/src/generated/rest/LoginUserRequest.d.ts +0 -5
  123. package/lib/src/generated/rest/LoginUserRequest.js +0 -2
  124. package/lib/src/generated/rest/ModelType.d.ts +0 -1
  125. package/lib/src/generated/rest/ModelType.js +0 -2
  126. package/lib/src/generated/rest/NotificationGrantRequest.d.ts +0 -3
  127. package/lib/src/generated/rest/NotificationGrantRequest.js +0 -2
  128. package/lib/src/generated/rest/NotificationInput.d.ts +0 -10
  129. package/lib/src/generated/rest/NotificationInput.js +0 -2
  130. package/lib/src/generated/rest/OpenLinkRequest.d.ts +0 -3
  131. package/lib/src/generated/rest/OpenLinkRequest.js +0 -2
  132. package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +0 -3
  133. package/lib/src/generated/rest/PermitCapabilityRequest.js +0 -2
  134. package/lib/src/generated/rest/PerspectiveInput.d.ts +0 -4
  135. package/lib/src/generated/rest/PerspectiveInput.js +0 -1
  136. package/lib/src/generated/rest/PromptRequest.d.ts +0 -4
  137. package/lib/src/generated/rest/PromptRequest.js +0 -2
  138. package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +0 -4
  139. package/lib/src/generated/rest/PublicPerspectiveInput.js +0 -1
  140. package/lib/src/generated/rest/PublishLanguageRequest.d.ts +0 -5
  141. package/lib/src/generated/rest/PublishLanguageRequest.js +0 -1
  142. package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +0 -6
  143. package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +0 -1
  144. package/lib/src/generated/rest/QueryRequest.d.ts +0 -7
  145. package/lib/src/generated/rest/QueryRequest.js +0 -2
  146. package/lib/src/generated/rest/RemoveLinkRequest.d.ts +0 -5
  147. package/lib/src/generated/rest/RemoveLinkRequest.js +0 -1
  148. package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +0 -5
  149. package/lib/src/generated/rest/RemoveLinksBulkRequest.js +0 -1
  150. package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +0 -4
  151. package/lib/src/generated/rest/RequestCapabilityRequest.js +0 -1
  152. package/lib/src/generated/rest/RequestPaymentRequest.d.ts +0 -3
  153. package/lib/src/generated/rest/RequestPaymentRequest.js +0 -2
  154. package/lib/src/generated/rest/RequestVerificationRequest.d.ts +0 -4
  155. package/lib/src/generated/rest/RequestVerificationRequest.js +0 -2
  156. package/lib/src/generated/rest/ResourceInput.d.ts +0 -4
  157. package/lib/src/generated/rest/ResourceInput.js +0 -2
  158. package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +0 -4
  159. package/lib/src/generated/rest/SetDefaultModelRequest.js +0 -1
  160. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +0 -3
  161. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +0 -2
  162. package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +0 -3
  163. package/lib/src/generated/rest/SetHotWalletAddressRequest.js +0 -2
  164. package/lib/src/generated/rest/SetMultiUserRequest.d.ts +0 -3
  165. package/lib/src/generated/rest/SetMultiUserRequest.js +0 -2
  166. package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +0 -5
  167. package/lib/src/generated/rest/SetOnlineStatusRequest.js +0 -1
  168. package/lib/src/generated/rest/SetStatusRequest.d.ts +0 -3
  169. package/lib/src/generated/rest/SetStatusRequest.js +0 -2
  170. package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +0 -4
  171. package/lib/src/generated/rest/SetUserFreeAccessRequest.js +0 -2
  172. package/lib/src/generated/rest/SignMessageRequest.d.ts +0 -3
  173. package/lib/src/generated/rest/SignMessageRequest.js +0 -2
  174. package/lib/src/generated/rest/SignalRequest.d.ts +0 -6
  175. package/lib/src/generated/rest/SignalRequest.js +0 -1
  176. package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +0 -3
  177. package/lib/src/generated/rest/SubscribeQueryRequest.js +0 -2
  178. package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +0 -4
  179. package/lib/src/generated/rest/SubscribeQueryResponse.js +0 -2
  180. package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +0 -3
  181. package/lib/src/generated/rest/TrustedAgentsRequest.js +0 -2
  182. package/lib/src/generated/rest/UnlockAgentRequest.d.ts +0 -4
  183. package/lib/src/generated/rest/UnlockAgentRequest.js +0 -2
  184. package/lib/src/generated/rest/UpdateLinkRequest.d.ts +0 -7
  185. package/lib/src/generated/rest/UpdateLinkRequest.js +0 -1
  186. package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +0 -3
  187. package/lib/src/generated/rest/UpdatePerspectiveRequest.js +0 -2
  188. package/lib/src/generated/rest/UpdateProfileRequest.d.ts +0 -5
  189. package/lib/src/generated/rest/UpdateProfileRequest.js +0 -1
  190. package/lib/src/generated/rest/UserStatistics.d.ts +0 -9
  191. package/lib/src/generated/rest/UserStatistics.js +0 -2
  192. package/lib/src/generated/rest/VerificationRequestResult.d.ts +0 -6
  193. package/lib/src/generated/rest/VerificationRequestResult.js +0 -2
  194. package/lib/src/generated/rest/VerifyEmailRequest.d.ts +0 -6
  195. package/lib/src/generated/rest/VerifyEmailRequest.js +0 -2
  196. package/lib/src/generated/rest/VerifySignatureRequest.d.ts +0 -5
  197. package/lib/src/generated/rest/VerifySignatureRequest.js +0 -2
  198. package/lib/src/generated/rest/WriteSettingsRequest.d.ts +0 -3
  199. package/lib/src/generated/rest/WriteSettingsRequest.js +0 -2
  200. package/lib/src/generated/rest/index.d.ts +0 -73
  201. package/lib/src/generated/rest/index.js +0 -8
  202. package/lib/src/generated/rest/routes.d.ts +0 -587
  203. package/lib/src/generated/rest/routes.js +0 -3
  204. package/lib/src/model/query-surreal.d.ts +0 -44
  205. package/lib/src/model/query-surreal.js +0 -249
  206. package/lib/src/model/surreal-utils.d.ts +0 -42
  207. package/lib/src/model/surreal-utils.js +0 -128
  208. package/lib/src/perspectives/PerspectiveProxy.test.d.ts +0 -1
  209. package/lib/src/perspectives/PerspectiveProxy.test.js +0 -34
  210. package/lib/src/restClient.d.ts +0 -52
  211. package/lib/src/restClient.js +0 -227
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
+ * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
+ *
5
+ * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
+ * injection (`formatManifestForPrompt`) to describe external perspective models
7
+ * to the schema-generation AI.
8
+ *
9
+ * @module
10
+ */
11
+ /** Normalised description of a single property on a model class. */
12
+ export interface ModelManifestProperty {
13
+ /** Property name as declared in the SHACL shape (e.g. "name", "body", "participants"). */
14
+ name: string;
15
+ /** The exact RDF predicate URI (e.g. "flux://has_name"). */
16
+ predicate: string;
17
+ /** Normalised scalar type; inferred from xsd:/sh: datatype + nodeKind. */
18
+ type: 'string' | 'number' | 'boolean' | 'uri';
19
+ /** `true` when maxCount is absent or > 1 (i.e. returned as an array). */
20
+ isCollection: boolean;
21
+ /** `true` when minCount >= 1. */
22
+ required: boolean;
23
+ writable: boolean;
24
+ /** AD4M language used to resolve the value (e.g. "literal"). */
25
+ resolveLanguage?: string;
26
+ /**
27
+ * Local name of the related model class when this is a typed relation property.
28
+ * Derived from `SHACLPropertyShape.class` by stripping the URI prefix.
29
+ * E.g. `flux://Message` → `"Message"`.
30
+ */
31
+ relatedModel?: string;
32
+ }
33
+ /** Normalised description of a single model class stored in a perspective. */
34
+ export interface ModelManifestEntry {
35
+ /** Class name — usable directly as the `model` field in a `$query` token. */
36
+ name: string;
37
+ /** The SHACL `targetClass` URI (e.g. "flux://Channel"). */
38
+ targetClass: string;
39
+ /** All data properties (flag/hasValue properties are excluded). */
40
+ properties: ModelManifestProperty[];
41
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Types for the perspective model manifest — a human-readable, AI-friendly summary
3
+ * of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
4
+ *
5
+ * Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
6
+ * injection (`formatManifestForPrompt`) to describe external perspective models
7
+ * to the schema-generation AI.
8
+ *
9
+ * @module
10
+ */
11
+ export {};
@@ -379,8 +379,8 @@ function buildSPARQLWhereFilters(metadata, _allRelationsMetadata, where) {
379
379
  const useParseLiteral = isLiteralStoredProperty(propMeta);
380
380
  // For literal-stored properties, push equality/IN/NOT filters to SPARQL using
381
381
  // <ad4m://fn/parse_literal>() which extracts the raw value from literal: IRIs.
382
- // The correct SPARQL syntax is <ad4m://fn/parse_literal>(?var) — NOT fn::parse_literal
383
- // (which was SurrealDB syntax that Oxigraph rejects at parse time).
382
+ // Use IRI form <ad4m://fn/parse_literal>(?var); the namespaced form
383
+ // fn::parse_literal is invalid SPARQL and Oxigraph rejects it at parse time.
384
384
  // Comparison operators (gt/lt/gte/lte/between/contains) remain JS-only because
385
385
  // parse_literal returns strings and numeric/date comparisons would be unreliable.
386
386
  // JS post-filter in instancesFromQueryResult remains as a safety net for all cases.
@@ -53,26 +53,28 @@ describe('hasJsOnlyWhereFilters', () => {
53
53
  expect(hasJsOnlyWhereFilters(meta, relMeta, { parent: 'some://id' })).toBe(true);
54
54
  });
55
55
  });
56
- describe('buildSPARQLQuery — pagination handled in JS, not SPARQL', () => {
56
+ describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
57
57
  const modelClass = {};
58
- it('does NOT include LIMIT/OFFSET in SPARQL even when query has them', () => {
58
+ it('includes LIMIT/OFFSET in a pagination subquery when query has them and no JS-only filters', () => {
59
59
  const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
60
60
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
61
- // SPARQL should NOT contain LIMIT/OFFSET — pagination is done in JS
62
- expect(sparql).not.toContain('LIMIT');
63
- expect(sparql).not.toContain('OFFSET');
61
+ // SPARQL should contain LIMIT inside the pagination subquery
62
+ expect(sparql).toContain('LIMIT 10');
64
63
  // The outer query should still exist
65
64
  expect(sparql).toContain('SELECT ?source ?predicate ?target');
65
+ // Should have a subquery pattern
66
+ expect(sparql).toContain('SELECT DISTINCT ?source');
66
67
  });
67
- it('does NOT include LIMIT/OFFSET even with JS-only where filters', () => {
68
- const query = { limit: 10, offset: 0, where: { name: 'Pasta' } };
68
+ it('does NOT include LIMIT/OFFSET when JS-only where filters exist', () => {
69
+ // author is a JS-only filter
70
+ const query = { limit: 10, offset: 0, where: { author: 'did:key:abc' } };
69
71
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
70
72
  expect(sparql).not.toContain('LIMIT');
71
73
  expect(sparql).not.toContain('OFFSET');
72
74
  });
73
75
  });
74
76
  describe('buildSPARQLOrderLimitOffset', () => {
75
- it('always returns empty string (pagination is handled in JS)', () => {
77
+ it('always returns empty string (pagination uses subquery pattern instead)', () => {
76
78
  expect(buildSPARQLOrderLimitOffset(emptyMetadata, {})).toBe('');
77
79
  expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50 })).toBe('');
78
80
  expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50, offset: 100 })).toBe('');
@@ -132,8 +134,9 @@ describe('buildSPARQLQuery — structural correctness', () => {
132
134
  };
133
135
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
134
136
  expect(sparql).toContain('<flux://channel-123>');
135
- // No SPARQL-level pagination
136
- expect(sparql).not.toContain('LIMIT');
137
+ // SPARQL-level pagination via subquery
138
+ expect(sparql).toContain('LIMIT 50');
139
+ expect(sparql).toContain('SELECT DISTINCT ?source');
137
140
  });
138
141
  it('does not allow injection through where clause IRI values', () => {
139
142
  const query = {
@@ -208,6 +211,67 @@ describe('buildSPARQLQuery — IRI correctness', () => {
208
211
  expect(sparql).not.toContain('fn::parse_literal');
209
212
  });
210
213
  });
214
+ // ──────────────────────────────────────────────────────────
215
+ // SPARQL-level pagination (LIMIT/OFFSET in generated queries)
216
+ // ──────────────────────────────────────────────────────────
217
+ describe('SPARQL-level pagination', () => {
218
+ const modelClass = {};
219
+ it('includes LIMIT in SPARQL when query specifies limit', () => {
220
+ const query = { limit: 30 };
221
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
222
+ expect(sparql).toContain('LIMIT 30');
223
+ expect(sparql).toContain('SELECT DISTINCT ?source');
224
+ });
225
+ it('includes OFFSET in SPARQL when query specifies offset > 0', () => {
226
+ const query = { limit: 20, offset: 40 };
227
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
228
+ expect(sparql).toContain('LIMIT 20');
229
+ expect(sparql).toContain('OFFSET 40');
230
+ });
231
+ it('does NOT include OFFSET when offset is 0', () => {
232
+ const query = { limit: 10, offset: 0 };
233
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
234
+ expect(sparql).toContain('LIMIT 10');
235
+ expect(sparql).not.toContain('OFFSET');
236
+ });
237
+ it('includes ORDER BY in subquery when query.order is specified', () => {
238
+ const query = { limit: 10, order: { name: 'DESC' } };
239
+ const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
240
+ expect(sparql).toContain('ORDER BY DESC(');
241
+ expect(sparql).toContain('LIMIT 10');
242
+ });
243
+ it('does NOT default to ORDER BY timestamp when paginating without explicit order', () => {
244
+ const query = { limit: 30 };
245
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
246
+ expect(sparql).not.toContain('ORDER BY');
247
+ expect(sparql).not.toContain('pg_minTs');
248
+ });
249
+ it('does NOT push pagination to SPARQL when JS-only where filters exist (author)', () => {
250
+ const query = { limit: 10, where: { author: 'did:key:abc' } };
251
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
252
+ expect(sparql).not.toContain('LIMIT');
253
+ expect(sparql).not.toContain('OFFSET');
254
+ });
255
+ it('does NOT push pagination to SPARQL when JS-only where filters exist (gt operator)', () => {
256
+ const meta = {
257
+ properties: {
258
+ rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
259
+ },
260
+ relations: {},
261
+ };
262
+ const query = { limit: 10, where: { rating: { gt: 5 } } };
263
+ const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
264
+ expect(sparql).not.toContain('LIMIT');
265
+ });
266
+ it('wraps pagination in a subquery (outer SELECT fetches all links for the page)', () => {
267
+ const query = { limit: 5, offset: 10 };
268
+ const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
269
+ expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
270
+ expect(sparql).toContain('SELECT DISTINCT ?source');
271
+ expect(sparql).toContain('LIMIT 5');
272
+ expect(sparql).toContain('OFFSET 10');
273
+ });
274
+ });
211
275
  describe('buildSPARQLQuery — set-difference patterns', () => {
212
276
  const modelClass = {};
213
277
  // Subgroups are grandchildren of channels (channel → conversation → subgroup).
@@ -228,3 +292,21 @@ describe('buildSPARQLQuery — set-difference patterns', () => {
228
292
  expect(sparql).toContain('SELECT ?source ?predicate ?target');
229
293
  });
230
294
  });
295
+ describe('buildSPARQLQuery — RDF 1.2 reifier patterns', () => {
296
+ const modelClass = {};
297
+ it('uses rdf:reifies instead of GRAPH for link metadata', () => {
298
+ const query = { limit: 10 };
299
+ const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
300
+ expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>');
301
+ expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(');
302
+ expect(sparql).toContain('?_reifier');
303
+ expect(sparql).not.toContain('GRAPH');
304
+ expect(sparql).not.toContain('?linkGraph');
305
+ });
306
+ it('binds author and timestamp on the reifier node', () => {
307
+ const query = {};
308
+ const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
309
+ expect(sparql).toContain('?_reifier <ad4m://ontology/author> ?author');
310
+ expect(sparql).toContain('?_reifier <ad4m://ontology/timestamp> ?timestamp');
311
+ });
312
+ });
@@ -1,21 +1,18 @@
1
1
  import { NeighbourhoodClient } from "./NeighbourhoodClient";
2
2
  import { NeighbourhoodProxy } from "./NeighbourhoodProxy";
3
- // Mock RestClient's subscribe to avoid real WebSocket connections
4
- jest.mock('../restClient', () => {
5
- return {
6
- RestClient: jest.fn().mockImplementation(() => ({
7
- get: jest.fn(),
8
- post: jest.fn(),
9
- put: jest.fn(),
10
- delete: jest.fn(),
11
- subscribe: jest.fn().mockReturnValue(() => { }),
12
- }))
13
- };
14
- });
15
3
  describe("NeighbourhoodProxy", () => {
16
4
  it("should add multiple signal handlers", async () => {
17
5
  const neighbourhoodURI = "did://123";
18
- const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
6
+ const mockApolloClient = {
7
+ subscribe: () => ({
8
+ subscribe: () => new Promise((resolve) => {
9
+ setTimeout(() => {
10
+ resolve({});
11
+ }, 10);
12
+ }),
13
+ }),
14
+ };
15
+ const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
19
16
  const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
20
17
  let callbacks = 0;
21
18
  const handler1 = () => {
@@ -24,7 +21,7 @@ describe("NeighbourhoodProxy", () => {
24
21
  const handler2 = () => {
25
22
  callbacks++;
26
23
  };
27
- // Add multiple signal handlers in parallel
24
+ // Add multiple signal handlers in paralell
28
25
  const promise = neighbourhoodProxy.addSignalHandler(handler1);
29
26
  neighbourhoodProxy.addSignalHandler(handler2);
30
27
  await promise;
@@ -33,20 +30,21 @@ describe("NeighbourhoodProxy", () => {
33
30
  });
34
31
  it("should not add multiple subscriptions when removing and adding another signal handler", async () => {
35
32
  const neighbourhoodURI = "did://123";
36
- // Track subscribe calls via the mock
37
- let subscribeCallCount = 0;
38
- const { RestClient } = jest.requireMock('../restClient');
39
- RestClient.mockImplementation(() => ({
40
- get: jest.fn(),
41
- post: jest.fn(),
42
- put: jest.fn(),
43
- delete: jest.fn(),
44
- subscribe: jest.fn().mockImplementation(() => {
45
- subscribeCallCount++;
46
- return () => { };
33
+ const subscriptions = [];
34
+ const subscribe = (args) => {
35
+ subscriptions.push(args);
36
+ new Promise((resolve) => {
37
+ setTimeout(() => {
38
+ resolve({});
39
+ }, 10);
40
+ });
41
+ };
42
+ const mockApolloClient = {
43
+ subscribe: () => ({
44
+ subscribe,
47
45
  }),
48
- }));
49
- const neighbourhoodClient = new NeighbourhoodClient("http://localhost:0", "test-token");
46
+ };
47
+ const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
50
48
  const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
51
49
  let callbacks1 = 0;
52
50
  let callbacks2 = 0;
@@ -58,15 +56,17 @@ describe("NeighbourhoodProxy", () => {
58
56
  };
59
57
  // Add signal handler 1
60
58
  await neighbourhoodProxy.addSignalHandler(handler1);
61
- // Remove signal handler 1
59
+ // Remove signal handler 2
62
60
  neighbourhoodProxy.removeSignalHandler(handler1);
63
61
  // Add signal handler 2
64
62
  await neighbourhoodProxy.addSignalHandler(handler2);
65
- // Check that only one subscription was added (handlers share subscription per perspective)
66
- expect(subscribeCallCount).toBe(1);
67
- // Dispatch signal
68
- neighbourhoodClient.dispatchSignal(neighbourhoodURI, true);
69
- // Check that only handler2 was called (handler1 was removed)
63
+ // Check that only one subscription was added
64
+ expect(subscriptions.length).toBe(1);
65
+ // mock trigger signal event
66
+ for (const subscription of subscriptions) {
67
+ subscription.next({ data: { signal: { neighbourhoodSignal: true } } });
68
+ }
69
+ // Check that only our second callback was called
70
70
  expect(callbacks1).toBe(0);
71
71
  expect(callbacks2).toBe(1);
72
72
  });
@@ -333,4 +333,86 @@ describe('SHACLShape', () => {
333
333
  expect(prop.remover).toEqual(original.properties[0].remover);
334
334
  });
335
335
  });
336
+ describe('sh:in round-trip', () => {
337
+ it('preserves sh:in enum values through toLinks() → fromLinks()', () => {
338
+ const original = new SHACLShape('test://Model');
339
+ original.addProperty({
340
+ name: 'status',
341
+ path: 'test://status',
342
+ datatype: 'xsd:string',
343
+ in: [
344
+ { value: 'active', label: 'Active' },
345
+ { value: 'inactive', label: 'Inactive' },
346
+ { value: 'archived' },
347
+ ],
348
+ });
349
+ const links = original.toLinks();
350
+ // Verify sh:in link was created
351
+ const inLink = links.find(l => l.predicate === 'sh://in');
352
+ expect(inLink).toBeDefined();
353
+ expect(inLink.target).toContain('literal:string:');
354
+ // Reconstruct and verify
355
+ const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
356
+ expect(reconstructed.properties[0].in).toBeDefined();
357
+ expect(reconstructed.properties[0].in).toEqual([
358
+ { value: 'active', label: 'Active' },
359
+ { value: 'inactive', label: 'Inactive' },
360
+ { value: 'archived' },
361
+ ]);
362
+ });
363
+ it('handles sh:in with special characters in values', () => {
364
+ const original = new SHACLShape('test://Model');
365
+ original.addProperty({
366
+ name: 'category',
367
+ path: 'test://category',
368
+ in: [
369
+ { value: 'food & drink', label: 'Food & Drink' },
370
+ { value: 'arts/crafts' },
371
+ ],
372
+ });
373
+ const links = original.toLinks();
374
+ const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
375
+ expect(reconstructed.properties[0].in).toEqual(original.properties[0].in);
376
+ });
377
+ it('handles sh:in with empty array (no link created)', () => {
378
+ const original = new SHACLShape('test://Model');
379
+ original.addProperty({
380
+ name: 'field',
381
+ path: 'test://field',
382
+ in: [],
383
+ });
384
+ const links = original.toLinks();
385
+ const inLink = links.find(l => l.predicate === 'sh://in');
386
+ expect(inLink).toBeUndefined();
387
+ });
388
+ it('handles sh:in with literal://string: prefix variant', () => {
389
+ // fromLinks should handle both `literal:string:` and `literal://string:` prefixes
390
+ const links = [
391
+ { source: 'test://ModelShape', predicate: 'sh://targetClass', target: 'test://Model' },
392
+ { source: 'test://ModelShape', predicate: 'sh://property', target: 'test://Model.status' },
393
+ { source: 'test://Model.status', predicate: 'sh://path', target: 'test://status' },
394
+ { source: 'test://Model.status', predicate: 'sh://in', target: 'literal://string:[{"value":"a"},{"value":"b"}]' },
395
+ ];
396
+ const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
397
+ expect(reconstructed.properties[0].in).toEqual([
398
+ { value: 'a' },
399
+ { value: 'b' },
400
+ ]);
401
+ });
402
+ it('preserves sh:in through toJSON() → fromJSON()', () => {
403
+ const original = new SHACLShape('test://Model');
404
+ original.addProperty({
405
+ name: 'priority',
406
+ path: 'test://priority',
407
+ in: [
408
+ { value: 'high', label: 'High' },
409
+ { value: 'medium', label: 'Medium' },
410
+ { value: 'low', label: 'Low' },
411
+ ],
412
+ });
413
+ const json = original.toJSON();
414
+ const reconstructed = SHACLShape.fromJSON(json);
415
+ expect(reconstructed.properties[0].in).toEqual(original.properties[0].in);
416
+ });
417
+ });
336
418
  });
package/package.json CHANGED
@@ -5,12 +5,6 @@
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/src/index.d.ts",
7
7
  "type": "module",
8
- "scripts": {
9
- "build": "patch-package && tsc && pnpm run bundle",
10
- "bundle": "rollup -c rollup.config.js",
11
- "test": "jest --forceExit",
12
- "generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
13
- },
14
8
  "repository": {
15
9
  "type": "git",
16
10
  "url": "git+https://github.com/coasys/ad4m.git"
@@ -54,8 +48,11 @@
54
48
  "ws": "8.13.0"
55
49
  },
56
50
  "patchedDependencies": {},
57
- "pnpm": {
58
- "patchedDependencies": {}
59
- },
60
- "version": "0.13.0-test-8"
61
- }
51
+ "version": "0.13.0-test-8-profile-cache-fix",
52
+ "scripts": {
53
+ "build": "patch-package && tsc && pnpm run bundle",
54
+ "bundle": "rollup -c rollup.config.js",
55
+ "test": "jest --forceExit",
56
+ "generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
57
+ }
58
+ }
@@ -53,11 +53,15 @@ export class AgentClient {
53
53
  // L1: in-memory promise cache with timestamps for TTL
54
54
  #memCache = new Map<string, { promise: Promise<Agent>; ts: number }>();
55
55
  // L2: persistent cache (IndexedDB in browser, NullCache in Node)
56
- #persistent: PersistentCache<Agent>;
56
+ // Entries are wrapped with a timestamp so the TTL can be enforced across restarts.
57
+ #persistent: PersistentCache<{ agent: Agent; ts: number }>;
57
58
  // Self-DID for event-driven invalidation (no TTL for own profile)
58
59
  #selfDid: string | null = null;
59
60
  /** TTL for remote (non-self) agent profiles in L1 cache (ms). */
60
61
  static REMOTE_AGENT_TTL_MS = 5 * 60_000; // 5 minutes
62
+ /** TTL for remote agent profiles in the L2 (IndexedDB) cache (ms).
63
+ * After this window any restart triggers a fresh network fetch. */
64
+ static REMOTE_AGENT_TTL_L2_MS = 5 * 60_000; // 5 minutes
61
65
 
62
66
  constructor(baseUrl: string, token?: string, subscribe: boolean = true, sharedApiClient?: ApiClient) {
63
67
  this.#baseUrl = baseUrl;
@@ -69,7 +73,7 @@ export class AgentClient {
69
73
  this.#hostingUserInfoChangedCallbacks = [];
70
74
  this.#computeLogUpdatedCallbacks = [];
71
75
  this.#unsubscribers = [];
72
- this.#persistent = createPersistentCache<Agent>('ad4m-agent-cache', 'agents');
76
+ this.#persistent = createPersistentCache<{ agent: Agent; ts: number }>('ad4m-agent-cache', 'agents');
73
77
 
74
78
  if (subscribe) {
75
79
  this.subscribeAgentUpdated();
@@ -133,14 +137,15 @@ export class AgentClient {
133
137
  // Deduplicate: store the promise immediately so concurrent calls share one RPC
134
138
  const promise = (async () => {
135
139
  // L2: check persistent cache before network
136
- const persisted = await this.#persistent.get(did);
137
- if (persisted) {
138
- return persisted;
140
+ const entry = await this.#persistent.get(did);
141
+ // entry.agent may be undefined for pre-TTL cache entries (migration) — treat as expired
142
+ if (entry?.agent && (now - (entry.ts ?? 0)) < AgentClient.REMOTE_AGENT_TTL_L2_MS) {
143
+ return entry.agent;
139
144
  }
140
145
 
141
146
  // L3: network fetch
142
147
  const result = await this.#apiClient.call<Agent>('agent.byDid', { did });
143
- this.#persistent.put(did, result); // fire-and-forget write to L2
148
+ this.#persistent.put(did, { agent: result, ts: Date.now() }); // fire-and-forget write to L2
144
149
  return result;
145
150
  })();
146
151
 
@@ -198,7 +203,7 @@ export class AgentClient {
198
203
  // return fresh data without waiting for the subscription event
199
204
  if (agent.did) {
200
205
  this.#memCache.set(agent.did, { promise: Promise.resolve(agent), ts: Date.now() });
201
- this.#persistent.put(agent.did, agent); // fire-and-forget
206
+ this.#persistent.put(agent.did, { agent, ts: Date.now() }); // fire-and-forget
202
207
  }
203
208
 
204
209
  return agent;
@@ -236,7 +241,7 @@ export class AgentClient {
236
241
  // return fresh data without waiting for the subscription event
237
242
  if (agent.did) {
238
243
  this.#memCache.set(agent.did, { promise: Promise.resolve(agent), ts: Date.now() });
239
- this.#persistent.put(agent.did, agent); // fire-and-forget
244
+ this.#persistent.put(agent.did, { agent, ts: Date.now() }); // fire-and-forget
240
245
  }
241
246
 
242
247
  return agent;
@@ -277,7 +282,7 @@ export class AgentClient {
277
282
  promise: Promise.resolve(agent),
278
283
  ts: Date.now(),
279
284
  });
280
- this.#persistent.put(agent.did, agent); // fire-and-forget
285
+ this.#persistent.put(agent.did, { agent, ts: Date.now() }); // fire-and-forget
281
286
  }
282
287
 
283
288
  this.#updatedCallbacks.forEach((cb) => cb(agent));
@@ -252,7 +252,7 @@ describe('buildSPARQLQuery — non-literal and flag properties', () => {
252
252
  describe('buildSPARQLQuery — IRI correctness', () => {
253
253
  const modelClass: any = {};
254
254
 
255
- it('uses <ad4m://fn/parse_literal> IRI, not fn::parse_literal SurrealDB syntax', () => {
255
+ it('uses <ad4m://fn/parse_literal> IRI, not invalid fn::parse_literal namespaced form', () => {
256
256
  const query = { where: { name: 'test' } };
257
257
  const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
258
258
  expect(sparql).toContain('<ad4m://fn/parse_literal>');
@@ -422,8 +422,8 @@ function buildSPARQLWhereFilters(
422
422
 
423
423
  // For literal-stored properties, push equality/IN/NOT filters to SPARQL using
424
424
  // <ad4m://fn/parse_literal>() which extracts the raw value from literal: IRIs.
425
- // The correct SPARQL syntax is <ad4m://fn/parse_literal>(?var) — NOT fn::parse_literal
426
- // (which was SurrealDB syntax that Oxigraph rejects at parse time).
425
+ // Use IRI form <ad4m://fn/parse_literal>(?var); the namespaced form
426
+ // fn::parse_literal is invalid SPARQL and Oxigraph rejects it at parse time.
427
427
  // Comparison operators (gt/lt/gte/lte/between/contains) remain JS-only because
428
428
  // parse_literal returns strings and numeric/date comparisons would be unreliable.
429
429
  // JS post-filter in instancesFromQueryResult remains as a safety net for all cases.
@@ -1,7 +0,0 @@
1
- export type AIModelLoadingStatus = {
2
- model: string;
3
- progress: number;
4
- status: string;
5
- downloaded: boolean;
6
- loaded: boolean;
7
- };
@@ -1,2 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- export {};
@@ -1,3 +0,0 @@
1
- export type AddAgentInfosRequest = {
2
- agentInfos: Array<string>;
3
- };
@@ -1,2 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- export {};
@@ -1,6 +0,0 @@
1
- import type { LinkExpression } from "./LinkExpression";
2
- export type AddLinkExpressionRequest = {
3
- link: LinkExpression;
4
- status: string | null;
5
- batchId: string | null;
6
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { LinkInput } from "./LinkInput";
2
- export type AddLinkRequest = {
3
- link: LinkInput;
4
- status: string | null;
5
- batchId: string | null;
6
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { LinkInput } from "./LinkInput";
2
- export type AddLinksBulkRequest = {
3
- links: Array<LinkInput>;
4
- status: string | null;
5
- batchId: string | null;
6
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export type AddSdnaRequest = {
2
- name: string;
3
- sdnaCode: string | null;
4
- sdnaType: string;
5
- shaclJson: string | null;
6
- };
@@ -1,2 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- export {};
@@ -1,4 +0,0 @@
1
- export type ApplyTemplateRequest = {
2
- sourceLanguageHash: string;
3
- templateData: string;
4
- };
@@ -1,2 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- export {};
@@ -1,10 +0,0 @@
1
- import type { CapabilityInput } from "./CapabilityInput";
2
- export type AuthInfoInput = {
3
- appDesc: string;
4
- appDomain: string;
5
- appIconPath: string | null;
6
- appName: string;
7
- appUrl: string | null;
8
- capabilities: Array<CapabilityInput> | null;
9
- userDid: string | null;
10
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { PerspectiveInput } from "./PerspectiveInput";
2
- export type BroadcastRequest = {
3
- payload: PerspectiveInput;
4
- signed: boolean | null;
5
- loopback: boolean | null;
6
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import type { ResourceInput } from "./ResourceInput";
2
- export type CapabilityInput = {
3
- can: Array<string>;
4
- with: ResourceInput;
5
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export type CommitBatchRequest = {
2
- batchId: string;
3
- };