@coasys/ad4m 0.13.0-test-interpretation-2 → 0.13.0-test-model-layer

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 (254) hide show
  1. package/lib/index.cjs +1982 -498
  2. package/lib/index.js +1982 -499
  3. package/lib/src/ai/AIClient.js +6 -3
  4. package/lib/src/apiClient.d.ts +40 -4
  5. package/lib/src/apiClient.js +149 -9
  6. package/lib/src/index.d.ts +3 -1
  7. package/lib/src/index.js +2 -0
  8. package/lib/src/model/Ad4mModel.d.ts +6 -5
  9. package/lib/src/model/Ad4mModel.js +246 -29
  10. package/lib/src/model/Ad4mModel.test.js +480 -735
  11. package/lib/src/model/decorators.d.ts +147 -4
  12. package/lib/src/model/decorators.js +70 -24
  13. package/lib/src/model/model-manifest.d.ts +41 -0
  14. package/lib/src/model/model-manifest.js +11 -0
  15. package/lib/src/model/query-sparql.test.js +92 -10
  16. package/lib/src/model/shacl-gen.js +33 -0
  17. package/lib/src/model/types.d.ts +9 -0
  18. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
  19. package/lib/src/perspectives/AutoProcessor.d.ts +90 -24
  20. package/lib/src/perspectives/FlowInstance.d.ts +187 -0
  21. package/lib/src/perspectives/FlowInstance.js +336 -0
  22. package/lib/src/perspectives/FlowModels.d.ts +94 -0
  23. package/lib/src/perspectives/FlowModels.js +182 -0
  24. package/lib/src/perspectives/InterpretationModels.d.ts +12 -22
  25. package/lib/src/perspectives/InterpretationModels.js +2 -6
  26. package/lib/src/perspectives/PerspectiveClient.d.ts +68 -7
  27. package/lib/src/perspectives/PerspectiveClient.js +105 -10
  28. package/lib/src/perspectives/PerspectiveProxy.d.ts +142 -57
  29. package/lib/src/perspectives/PerspectiveProxy.js +388 -274
  30. package/lib/src/shacl/SHACLFlow.d.ts +273 -47
  31. package/lib/src/shacl/SHACLFlow.js +397 -88
  32. package/lib/src/shacl/SHACLShape.d.ts +8 -0
  33. package/lib/src/shacl/SHACLShape.js +17 -0
  34. package/lib/src/shacl/SHACLShape.test.js +82 -0
  35. package/package.json +2 -2
  36. package/src/ai/AIClient.ts +6 -3
  37. package/src/apiClient.test.ts +227 -0
  38. package/src/apiClient.ts +185 -9
  39. package/src/index.ts +3 -1
  40. package/src/model/Ad4mModel.test.ts +645 -0
  41. package/src/model/Ad4mModel.ts +245 -26
  42. package/src/model/decorators.ts +216 -35
  43. package/src/model/relation-filtering.test.ts +70 -20
  44. package/src/model/shacl-gen.ts +36 -0
  45. package/src/model/shacl-roundtrip.test.ts +130 -0
  46. package/src/model/types.ts +7 -0
  47. package/src/perspectives/AutoProcessor.ts +94 -24
  48. package/src/perspectives/FlowInstance.ts +369 -0
  49. package/src/perspectives/FlowModels.ts +157 -0
  50. package/src/perspectives/InterpretationModels.ts +13 -25
  51. package/src/perspectives/PerspectiveClient.test.ts +67 -6
  52. package/src/perspectives/PerspectiveClient.ts +142 -12
  53. package/src/perspectives/PerspectiveProxy.test.ts +406 -0
  54. package/src/perspectives/PerspectiveProxy.ts +459 -289
  55. package/src/perspectives/shacl-rpc.test.ts +258 -0
  56. package/src/shacl/SHACLFlow.test.ts +762 -35
  57. package/src/shacl/SHACLFlow.ts +680 -112
  58. package/src/shacl/SHACLShape.ts +31 -0
  59. package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +0 -7
  60. package/lib/src/generated/rest/AIModelLoadingStatus.js +0 -2
  61. package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +0 -3
  62. package/lib/src/generated/rest/AddAgentInfosRequest.js +0 -2
  63. package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +0 -6
  64. package/lib/src/generated/rest/AddLinkExpressionRequest.js +0 -1
  65. package/lib/src/generated/rest/AddLinkRequest.d.ts +0 -6
  66. package/lib/src/generated/rest/AddLinkRequest.js +0 -1
  67. package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +0 -6
  68. package/lib/src/generated/rest/AddLinksBulkRequest.js +0 -1
  69. package/lib/src/generated/rest/AddSdnaRequest.d.ts +0 -6
  70. package/lib/src/generated/rest/AddSdnaRequest.js +0 -2
  71. package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +0 -4
  72. package/lib/src/generated/rest/ApplyTemplateRequest.js +0 -2
  73. package/lib/src/generated/rest/AuthInfoInput.d.ts +0 -10
  74. package/lib/src/generated/rest/AuthInfoInput.js +0 -1
  75. package/lib/src/generated/rest/BroadcastRequest.d.ts +0 -6
  76. package/lib/src/generated/rest/BroadcastRequest.js +0 -1
  77. package/lib/src/generated/rest/CapabilityInput.d.ts +0 -5
  78. package/lib/src/generated/rest/CapabilityInput.js +0 -1
  79. package/lib/src/generated/rest/CommitBatchRequest.d.ts +0 -3
  80. package/lib/src/generated/rest/CommitBatchRequest.js +0 -2
  81. package/lib/src/generated/rest/ComputeLogEntry.d.ts +0 -9
  82. package/lib/src/generated/rest/ComputeLogEntry.js +0 -2
  83. package/lib/src/generated/rest/CreateExpressionRequest.d.ts +0 -4
  84. package/lib/src/generated/rest/CreateExpressionRequest.js +0 -2
  85. package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +0 -3
  86. package/lib/src/generated/rest/CreatePerspectiveRequest.js +0 -2
  87. package/lib/src/generated/rest/CreateSubjectRequest.d.ts +0 -6
  88. package/lib/src/generated/rest/CreateSubjectRequest.js +0 -2
  89. package/lib/src/generated/rest/CreateUserRequest.d.ts +0 -4
  90. package/lib/src/generated/rest/CreateUserRequest.js +0 -2
  91. package/lib/src/generated/rest/CreateUserResponse.d.ts +0 -5
  92. package/lib/src/generated/rest/CreateUserResponse.js +0 -2
  93. package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +0 -6
  94. package/lib/src/generated/rest/DecoratedExpressionProof.js +0 -2
  95. package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +0 -10
  96. package/lib/src/generated/rest/DecoratedLinkExpression.js +0 -1
  97. package/lib/src/generated/rest/DisposeQueryRequest.d.ts +0 -3
  98. package/lib/src/generated/rest/DisposeQueryRequest.js +0 -2
  99. package/lib/src/generated/rest/EmailTestRequest.d.ts +0 -6
  100. package/lib/src/generated/rest/EmailTestRequest.js +0 -2
  101. package/lib/src/generated/rest/EmbedRequest.d.ts +0 -4
  102. package/lib/src/generated/rest/EmbedRequest.js +0 -2
  103. package/lib/src/generated/rest/EntanglementProofInput.d.ts +0 -6
  104. package/lib/src/generated/rest/EntanglementProofInput.js +0 -2
  105. package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +0 -4
  106. package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +0 -2
  107. package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +0 -4
  108. package/lib/src/generated/rest/ExecuteCommandsRequest.js +0 -2
  109. package/lib/src/generated/rest/ExportRequest.d.ts +0 -5
  110. package/lib/src/generated/rest/ExportRequest.js +0 -2
  111. package/lib/src/generated/rest/ExpressionManyRequest.d.ts +0 -3
  112. package/lib/src/generated/rest/ExpressionManyRequest.js +0 -2
  113. package/lib/src/generated/rest/ExpressionProof.d.ts +0 -4
  114. package/lib/src/generated/rest/ExpressionProof.js +0 -2
  115. package/lib/src/generated/rest/ExpressionProofInput.d.ts +0 -6
  116. package/lib/src/generated/rest/ExpressionProofInput.js +0 -2
  117. package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +0 -3
  118. package/lib/src/generated/rest/FriendSendMessageRequest.js +0 -2
  119. package/lib/src/generated/rest/FriendsListRequest.d.ts +0 -3
  120. package/lib/src/generated/rest/FriendsListRequest.js +0 -2
  121. package/lib/src/generated/rest/GenerateAgentRequest.d.ts +0 -3
  122. package/lib/src/generated/rest/GenerateAgentRequest.js +0 -2
  123. package/lib/src/generated/rest/GenerateJwtRequest.d.ts +0 -4
  124. package/lib/src/generated/rest/GenerateJwtRequest.js +0 -2
  125. package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +0 -4
  126. package/lib/src/generated/rest/GetSubjectDataRequest.js +0 -2
  127. package/lib/src/generated/rest/HostingInfoResponse.d.ts +0 -5
  128. package/lib/src/generated/rest/HostingInfoResponse.js +0 -2
  129. package/lib/src/generated/rest/HostingWalletResponse.d.ts +0 -4
  130. package/lib/src/generated/rest/HostingWalletResponse.js +0 -2
  131. package/lib/src/generated/rest/ImportAgentRequest.d.ts +0 -6
  132. package/lib/src/generated/rest/ImportAgentRequest.js +0 -2
  133. package/lib/src/generated/rest/ImportRequest.d.ts +0 -4
  134. package/lib/src/generated/rest/ImportRequest.js +0 -2
  135. package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +0 -3
  136. package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +0 -2
  137. package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +0 -3
  138. package/lib/src/generated/rest/KeepAliveQueryRequest.js +0 -2
  139. package/lib/src/generated/rest/LanguageMetaInput.d.ts +0 -6
  140. package/lib/src/generated/rest/LanguageMetaInput.js +0 -2
  141. package/lib/src/generated/rest/Link.d.ts +0 -5
  142. package/lib/src/generated/rest/Link.js +0 -2
  143. package/lib/src/generated/rest/LinkExpression.d.ts +0 -10
  144. package/lib/src/generated/rest/LinkExpression.js +0 -1
  145. package/lib/src/generated/rest/LinkExpressionInput.d.ts +0 -10
  146. package/lib/src/generated/rest/LinkExpressionInput.js +0 -1
  147. package/lib/src/generated/rest/LinkInput.d.ts +0 -5
  148. package/lib/src/generated/rest/LinkInput.js +0 -2
  149. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +0 -3
  150. package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +0 -2
  151. package/lib/src/generated/rest/LinkMutationRequest.d.ts +0 -12
  152. package/lib/src/generated/rest/LinkMutationRequest.js +0 -1
  153. package/lib/src/generated/rest/LinkMutationResponse.d.ts +0 -9
  154. package/lib/src/generated/rest/LinkMutationResponse.js +0 -1
  155. package/lib/src/generated/rest/LinkMutations.d.ts +0 -6
  156. package/lib/src/generated/rest/LinkMutations.js +0 -1
  157. package/lib/src/generated/rest/LinkMutationsRequest.d.ts +0 -5
  158. package/lib/src/generated/rest/LinkMutationsRequest.js +0 -1
  159. package/lib/src/generated/rest/LinkStatus.d.ts +0 -1
  160. package/lib/src/generated/rest/LinkStatus.js +0 -2
  161. package/lib/src/generated/rest/LinkUpdateInput.d.ts +0 -5
  162. package/lib/src/generated/rest/LinkUpdateInput.js +0 -1
  163. package/lib/src/generated/rest/LockAgentRequest.d.ts +0 -3
  164. package/lib/src/generated/rest/LockAgentRequest.js +0 -2
  165. package/lib/src/generated/rest/LoginUserRequest.d.ts +0 -5
  166. package/lib/src/generated/rest/LoginUserRequest.js +0 -2
  167. package/lib/src/generated/rest/ModelType.d.ts +0 -1
  168. package/lib/src/generated/rest/ModelType.js +0 -2
  169. package/lib/src/generated/rest/NotificationGrantRequest.d.ts +0 -3
  170. package/lib/src/generated/rest/NotificationGrantRequest.js +0 -2
  171. package/lib/src/generated/rest/NotificationInput.d.ts +0 -10
  172. package/lib/src/generated/rest/NotificationInput.js +0 -2
  173. package/lib/src/generated/rest/OpenLinkRequest.d.ts +0 -3
  174. package/lib/src/generated/rest/OpenLinkRequest.js +0 -2
  175. package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +0 -3
  176. package/lib/src/generated/rest/PermitCapabilityRequest.js +0 -2
  177. package/lib/src/generated/rest/PerspectiveInput.d.ts +0 -4
  178. package/lib/src/generated/rest/PerspectiveInput.js +0 -1
  179. package/lib/src/generated/rest/PromptRequest.d.ts +0 -4
  180. package/lib/src/generated/rest/PromptRequest.js +0 -2
  181. package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +0 -4
  182. package/lib/src/generated/rest/PublicPerspectiveInput.js +0 -1
  183. package/lib/src/generated/rest/PublishLanguageRequest.d.ts +0 -5
  184. package/lib/src/generated/rest/PublishLanguageRequest.js +0 -1
  185. package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +0 -6
  186. package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +0 -1
  187. package/lib/src/generated/rest/QueryRequest.d.ts +0 -7
  188. package/lib/src/generated/rest/QueryRequest.js +0 -2
  189. package/lib/src/generated/rest/RemoveLinkRequest.d.ts +0 -5
  190. package/lib/src/generated/rest/RemoveLinkRequest.js +0 -1
  191. package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +0 -5
  192. package/lib/src/generated/rest/RemoveLinksBulkRequest.js +0 -1
  193. package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +0 -4
  194. package/lib/src/generated/rest/RequestCapabilityRequest.js +0 -1
  195. package/lib/src/generated/rest/RequestPaymentRequest.d.ts +0 -3
  196. package/lib/src/generated/rest/RequestPaymentRequest.js +0 -2
  197. package/lib/src/generated/rest/RequestVerificationRequest.d.ts +0 -4
  198. package/lib/src/generated/rest/RequestVerificationRequest.js +0 -2
  199. package/lib/src/generated/rest/ResourceInput.d.ts +0 -4
  200. package/lib/src/generated/rest/ResourceInput.js +0 -2
  201. package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +0 -4
  202. package/lib/src/generated/rest/SetDefaultModelRequest.js +0 -1
  203. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +0 -3
  204. package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +0 -2
  205. package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +0 -3
  206. package/lib/src/generated/rest/SetHotWalletAddressRequest.js +0 -2
  207. package/lib/src/generated/rest/SetMultiUserRequest.d.ts +0 -3
  208. package/lib/src/generated/rest/SetMultiUserRequest.js +0 -2
  209. package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +0 -5
  210. package/lib/src/generated/rest/SetOnlineStatusRequest.js +0 -1
  211. package/lib/src/generated/rest/SetStatusRequest.d.ts +0 -3
  212. package/lib/src/generated/rest/SetStatusRequest.js +0 -2
  213. package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +0 -4
  214. package/lib/src/generated/rest/SetUserFreeAccessRequest.js +0 -2
  215. package/lib/src/generated/rest/SignMessageRequest.d.ts +0 -3
  216. package/lib/src/generated/rest/SignMessageRequest.js +0 -2
  217. package/lib/src/generated/rest/SignalRequest.d.ts +0 -6
  218. package/lib/src/generated/rest/SignalRequest.js +0 -1
  219. package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +0 -3
  220. package/lib/src/generated/rest/SubscribeQueryRequest.js +0 -2
  221. package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +0 -4
  222. package/lib/src/generated/rest/SubscribeQueryResponse.js +0 -2
  223. package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +0 -3
  224. package/lib/src/generated/rest/TrustedAgentsRequest.js +0 -2
  225. package/lib/src/generated/rest/UnlockAgentRequest.d.ts +0 -4
  226. package/lib/src/generated/rest/UnlockAgentRequest.js +0 -2
  227. package/lib/src/generated/rest/UpdateLinkRequest.d.ts +0 -7
  228. package/lib/src/generated/rest/UpdateLinkRequest.js +0 -1
  229. package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +0 -3
  230. package/lib/src/generated/rest/UpdatePerspectiveRequest.js +0 -2
  231. package/lib/src/generated/rest/UpdateProfileRequest.d.ts +0 -5
  232. package/lib/src/generated/rest/UpdateProfileRequest.js +0 -1
  233. package/lib/src/generated/rest/UserStatistics.d.ts +0 -9
  234. package/lib/src/generated/rest/UserStatistics.js +0 -2
  235. package/lib/src/generated/rest/VerificationRequestResult.d.ts +0 -6
  236. package/lib/src/generated/rest/VerificationRequestResult.js +0 -2
  237. package/lib/src/generated/rest/VerifyEmailRequest.d.ts +0 -6
  238. package/lib/src/generated/rest/VerifyEmailRequest.js +0 -2
  239. package/lib/src/generated/rest/VerifySignatureRequest.d.ts +0 -5
  240. package/lib/src/generated/rest/VerifySignatureRequest.js +0 -2
  241. package/lib/src/generated/rest/WriteSettingsRequest.d.ts +0 -3
  242. package/lib/src/generated/rest/WriteSettingsRequest.js +0 -2
  243. package/lib/src/generated/rest/index.d.ts +0 -73
  244. package/lib/src/generated/rest/index.js +0 -8
  245. package/lib/src/generated/rest/routes.d.ts +0 -587
  246. package/lib/src/generated/rest/routes.js +0 -3
  247. package/lib/src/model/query-surreal.d.ts +0 -44
  248. package/lib/src/model/query-surreal.js +0 -249
  249. package/lib/src/model/surreal-utils.d.ts +0 -42
  250. package/lib/src/model/surreal-utils.js +0 -128
  251. package/lib/src/perspectives/PerspectiveProxy.test.d.ts +0 -1
  252. package/lib/src/perspectives/PerspectiveProxy.test.js +0 -34
  253. package/lib/src/restClient.d.ts +0 -52
  254. package/lib/src/restClient.js +0 -227
@@ -0,0 +1,258 @@
1
+ import { PerspectiveProxy } from './PerspectiveProxy';
2
+ import { SHACLShape } from '../shacl/SHACLShape';
3
+
4
+ // ── Helpers ──────────────────────────────────────────────────────────────────
5
+
6
+ function createMockClient(overrides: Record<string, jest.Mock> = {}): any {
7
+ return {
8
+ addPerspectiveLinkAddedListener: jest.fn(),
9
+ addPerspectiveLinkRemovedListener: jest.fn(),
10
+ addPerspectiveLinkUpdatedListener: jest.fn(),
11
+ addPerspectiveSyncStateChangeListener: jest.fn(),
12
+ getShaclNames: jest.fn().mockResolvedValue([]),
13
+ // Client contract (post r3897752023): getShaclTargetClass returns
14
+ // `undefined` on "not found", not `null`. Mock the same shape.
15
+ getShaclTargetClass: jest.fn().mockResolvedValue(undefined),
16
+ getShacl: jest.fn().mockResolvedValue(null),
17
+ getAllShacl: jest.fn().mockResolvedValue([]),
18
+ ...overrides,
19
+ };
20
+ }
21
+
22
+ function createProxy(client?: any): PerspectiveProxy {
23
+ const mockClient = client ?? createMockClient();
24
+ return new PerspectiveProxy(
25
+ {
26
+ uuid: 'test-uuid',
27
+ name: 'test',
28
+ owners: [],
29
+ sharedUrl: null,
30
+ neighbourhood: null,
31
+ state: 'Synced',
32
+ } as any,
33
+ mockClient,
34
+ );
35
+ }
36
+
37
+ /** Build the link triples that SHACLShape.fromLinks expects for a minimal shape. */
38
+ function buildShapeLinks(
39
+ shapeUri: string,
40
+ targetClass: string,
41
+ properties: Array<{ name: string; path: string; datatype?: string }>,
42
+ ): Array<{ source: string; predicate: string; target: string }> {
43
+ const links: Array<{ source: string; predicate: string; target: string }> = [
44
+ { source: shapeUri, predicate: 'sh://targetClass', target: targetClass },
45
+ ];
46
+ for (const prop of properties) {
47
+ const propUri = `${shapeUri}.${prop.name}`;
48
+ links.push({ source: shapeUri, predicate: 'sh://property', target: propUri });
49
+ links.push({ source: propUri, predicate: 'sh://path', target: prop.path });
50
+ if (prop.datatype) {
51
+ links.push({ source: propUri, predicate: 'sh://datatype', target: prop.datatype });
52
+ }
53
+ }
54
+ return links;
55
+ }
56
+
57
+ // ── Tests ────────────────────────────────────────────────────────────────────
58
+
59
+ describe('PerspectiveProxy SHACL RPC delegation', () => {
60
+ describe('getShaclNames', () => {
61
+ it('delegates to PerspectiveClient.getShaclNames with the perspective UUID', async () => {
62
+ const client = createMockClient({
63
+ getShaclNames: jest.fn().mockResolvedValue(['Message', 'Channel']),
64
+ });
65
+ const proxy = createProxy(client);
66
+
67
+ const names = await proxy.getShaclNames();
68
+
69
+ expect(client.getShaclNames).toHaveBeenCalledWith('test-uuid');
70
+ expect(names).toEqual(['Message', 'Channel']);
71
+ });
72
+
73
+ it('returns an empty array when no shapes exist', async () => {
74
+ const proxy = createProxy();
75
+ const names = await proxy.getShaclNames();
76
+ expect(names).toEqual([]);
77
+ });
78
+ });
79
+
80
+ describe('getShaclTargetClass', () => {
81
+ it('delegates to PerspectiveClient and returns the target class', async () => {
82
+ const client = createMockClient({
83
+ getShaclTargetClass: jest.fn().mockResolvedValue('flux://Message'),
84
+ });
85
+ const proxy = createProxy(client);
86
+
87
+ const tc = await proxy.getShaclTargetClass('Message');
88
+
89
+ expect(client.getShaclTargetClass).toHaveBeenCalledWith('test-uuid', 'Message');
90
+ expect(tc).toBe('flux://Message');
91
+ });
92
+
93
+ it('returns undefined when the shape does not exist', async () => {
94
+ const client = createMockClient({
95
+ // Post r3897752023 the client itself returns undefined on "not
96
+ // found", so the proxy passthrough must preserve that.
97
+ getShaclTargetClass: jest.fn().mockResolvedValue(undefined),
98
+ });
99
+ const proxy = createProxy(client);
100
+
101
+ const tc = await proxy.getShaclTargetClass('NonExistent');
102
+ expect(tc).toBeUndefined();
103
+ });
104
+ });
105
+
106
+ describe('getShacl', () => {
107
+ it('delegates to PerspectiveClient and reconstructs a SHACLShape', async () => {
108
+ const shapeUri = 'flux://MessageShape';
109
+ const links = buildShapeLinks(shapeUri, 'flux://Message', [
110
+ { name: 'body', path: 'flux://body', datatype: 'xsd:string' },
111
+ { name: 'timestamp', path: 'flux://timestamp', datatype: 'xsd:dateTime' },
112
+ ]);
113
+
114
+ const client = createMockClient({
115
+ getShacl: jest.fn().mockResolvedValue({ shapeUri, links }),
116
+ });
117
+ const proxy = createProxy(client);
118
+
119
+ const shape = await proxy.getShacl('Message');
120
+
121
+ expect(client.getShacl).toHaveBeenCalledWith('test-uuid', 'Message');
122
+ expect(shape).not.toBeNull();
123
+ expect(shape!.nodeShapeUri).toBe(shapeUri);
124
+ expect(shape!.targetClass).toBe('flux://Message');
125
+ expect(shape!.properties.length).toBe(2);
126
+ expect(shape!.properties.map(p => p.name).sort()).toEqual(['body', 'timestamp']);
127
+ });
128
+
129
+ it('returns null when the shape does not exist', async () => {
130
+ const proxy = createProxy();
131
+ const shape = await proxy.getShacl('NonExistent');
132
+ expect(shape).toBeNull();
133
+ });
134
+ });
135
+
136
+ describe('getAllShacl', () => {
137
+ it('delegates to PerspectiveClient and reconstructs all shapes', async () => {
138
+ const msgLinks = buildShapeLinks('flux://MessageShape', 'flux://Message', [
139
+ { name: 'body', path: 'flux://body' },
140
+ ]);
141
+ const chanLinks = buildShapeLinks('flux://ChannelShape', 'flux://Channel', [
142
+ { name: 'name', path: 'flux://name' },
143
+ ]);
144
+
145
+ const client = createMockClient({
146
+ getAllShacl: jest.fn().mockResolvedValue([
147
+ { name: 'Message', shapeUri: 'flux://MessageShape', links: msgLinks },
148
+ { name: 'Channel', shapeUri: 'flux://ChannelShape', links: chanLinks },
149
+ ]),
150
+ });
151
+ const proxy = createProxy(client);
152
+
153
+ const shapes = await proxy.getAllShacl();
154
+
155
+ expect(client.getAllShacl).toHaveBeenCalledWith('test-uuid');
156
+ expect(shapes.length).toBe(2);
157
+ expect(shapes[0].name).toBe('Message');
158
+ expect(shapes[0].shape.targetClass).toBe('flux://Message');
159
+ expect(shapes[1].name).toBe('Channel');
160
+ expect(shapes[1].shape.targetClass).toBe('flux://Channel');
161
+ });
162
+
163
+ it('returns an empty array when no shapes exist', async () => {
164
+ const proxy = createProxy();
165
+ const shapes = await proxy.getAllShacl();
166
+ expect(shapes).toEqual([]);
167
+ });
168
+
169
+ it('passes every entry through when SHACLShape.fromLinks succeeds', async () => {
170
+ // Named for what it actually asserts: `SHACLShape.fromLinks` always
171
+ // returns a shape (even for the empty-links case — an empty shape
172
+ // with no targetClass is still a shape), so the proxy's `s !== null`
173
+ // filter is only reachable if `fromLinks` itself is mocked to return
174
+ // null. The original name ("filters out shapes that fail
175
+ // reconstruction") described a case the production path can't
176
+ // produce; that was dead coverage.
177
+ const client = createMockClient({
178
+ getAllShacl: jest.fn().mockResolvedValue([
179
+ { name: 'Good', shapeUri: 'app://GoodShape', links: buildShapeLinks('app://GoodShape', 'app://Good', [{ name: 'x', path: 'app://x' }]) },
180
+ { name: 'Empty', shapeUri: 'app://EmptyShape', links: [] },
181
+ ]),
182
+ });
183
+ const proxy = createProxy(client);
184
+
185
+ const shapes = await proxy.getAllShacl();
186
+
187
+ expect(shapes.length).toBe(2);
188
+ expect(shapes.map(s => s.name).sort()).toEqual(['Empty', 'Good']);
189
+ });
190
+
191
+ it('drops entries when SHACLShape.fromLinks returns null', async () => {
192
+ // Exercises the actual filter in `PerspectiveProxy.getAllShacl`:
193
+ // `SHACLShape.fromLinks` doesn't currently return null for any
194
+ // input, but the filter is defensive against a future change (or a
195
+ // subclass override), so we pin it by mocking `fromLinks` to
196
+ // simulate that case for one of two entries.
197
+ const goodLinks = buildShapeLinks('app://GoodShape', 'app://Good', [{ name: 'x', path: 'app://x' }]);
198
+ const badLinks = buildShapeLinks('app://BadShape', 'app://Bad', [{ name: 'y', path: 'app://y' }]);
199
+
200
+ const client = createMockClient({
201
+ getAllShacl: jest.fn().mockResolvedValue([
202
+ { name: 'Good', shapeUri: 'app://GoodShape', links: goodLinks },
203
+ { name: 'Bad', shapeUri: 'app://BadShape', links: badLinks },
204
+ ]),
205
+ });
206
+ const proxy = createProxy(client);
207
+
208
+ const fromLinksSpy = jest
209
+ .spyOn(SHACLShape, 'fromLinks')
210
+ .mockImplementation((_links: any, shapeUri: string) => {
211
+ if (shapeUri === 'app://BadShape') return null as unknown as SHACLShape;
212
+ const shape = new SHACLShape(shapeUri, 'app://Good');
213
+ return shape;
214
+ });
215
+
216
+ try {
217
+ const shapes = await proxy.getAllShacl();
218
+ expect(shapes.length).toBe(1);
219
+ expect(shapes[0].name).toBe('Good');
220
+ } finally {
221
+ fromLinksSpy.mockRestore();
222
+ }
223
+ });
224
+ });
225
+ });
226
+
227
+ describe('SHACLShape.fromLinks round-trip with RPC link format', () => {
228
+ it('reconstructs property details from simplified link triples', () => {
229
+ const shapeUri = 'recipe://RecipeShape';
230
+ const links = [
231
+ { source: shapeUri, predicate: 'sh://targetClass', target: 'recipe://Recipe' },
232
+ { source: shapeUri, predicate: 'sh://property', target: `${shapeUri}.title` },
233
+ { source: `${shapeUri}.title`, predicate: 'sh://path', target: 'recipe://title' },
234
+ { source: `${shapeUri}.title`, predicate: 'sh://datatype', target: 'xsd:string' },
235
+ { source: `${shapeUri}.title`, predicate: 'sh://minCount', target: 'literal:number:1' },
236
+ { source: `${shapeUri}.title`, predicate: 'sh://maxCount', target: 'literal:number:1' },
237
+ { source: shapeUri, predicate: 'sh://property', target: `${shapeUri}.servings` },
238
+ { source: `${shapeUri}.servings`, predicate: 'sh://path', target: 'recipe://servings' },
239
+ { source: `${shapeUri}.servings`, predicate: 'sh://datatype', target: 'xsd:integer' },
240
+ ];
241
+
242
+ const shape = SHACLShape.fromLinks(links as any, shapeUri);
243
+
244
+ expect(shape.nodeShapeUri).toBe(shapeUri);
245
+ expect(shape.targetClass).toBe('recipe://Recipe');
246
+ expect(shape.properties.length).toBe(2);
247
+
248
+ const title = shape.properties.find(p => p.name === 'title')!;
249
+ expect(title.path).toBe('recipe://title');
250
+ expect(title.datatype).toBe('xsd:string');
251
+ expect(title.minCount).toBe(1);
252
+ expect(title.maxCount).toBe(1);
253
+
254
+ const servings = shape.properties.find(p => p.name === 'servings')!;
255
+ expect(servings.path).toBe('recipe://servings');
256
+ expect(servings.datatype).toBe('xsd:integer');
257
+ });
258
+ });