@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.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 (393) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +8677 -15318
  4. package/lib/index.js +14507 -21223
  5. package/lib/src/Ad4mClient.d.ts +9 -3
  6. package/lib/src/Ad4mClient.js +40 -13
  7. package/lib/src/Literal.js +6 -5
  8. package/lib/src/agent/Agent.js +26 -272
  9. package/lib/src/agent/AgentClient.d.ts +33 -21
  10. package/lib/src/agent/AgentClient.js +180 -374
  11. package/lib/src/agent/AgentStatus.js +2 -37
  12. package/lib/src/ai/AIClient.d.ts +12 -4
  13. package/lib/src/ai/AIClient.js +81 -285
  14. package/lib/src/ai/AITypes.d.ts +55 -0
  15. package/lib/src/ai/AITypes.js +18 -0
  16. package/lib/src/ai/Tasks.js +10 -133
  17. package/lib/src/apiClient.d.ts +53 -0
  18. package/lib/src/apiClient.js +234 -0
  19. package/lib/src/cache/PersistentCache.d.ts +40 -0
  20. package/lib/src/cache/PersistentCache.js +139 -0
  21. package/lib/src/expression/Expression.d.ts +1 -1
  22. package/lib/src/expression/Expression.js +13 -122
  23. package/lib/src/expression/ExpressionClient.d.ts +11 -3
  24. package/lib/src/expression/ExpressionClient.js +120 -75
  25. package/lib/src/expression/ExpressionRef.js +4 -27
  26. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  27. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  28. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  29. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  30. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  31. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  32. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  33. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  34. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  35. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  36. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  37. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  38. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  39. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  40. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  41. package/lib/src/generated/api/CapabilityInput.js +1 -0
  42. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  43. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  44. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  45. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  46. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  47. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  48. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  49. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  50. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  51. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  52. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  53. package/lib/src/generated/api/EmbedRequest.js +2 -0
  54. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  55. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  56. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  57. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  58. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  59. package/lib/src/generated/api/ExportRequest.js +2 -0
  60. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  61. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  62. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  63. package/lib/src/generated/api/ExpressionProof.js +2 -0
  64. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  65. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  66. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  67. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  68. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  69. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  70. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  71. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  72. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  73. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  74. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  75. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  76. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  77. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  78. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  79. package/lib/src/generated/api/ImportRequest.js +2 -0
  80. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  81. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  82. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  83. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  84. package/lib/src/generated/api/Link.d.ts +5 -0
  85. package/lib/src/generated/api/Link.js +2 -0
  86. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  87. package/lib/src/generated/api/LinkExpression.js +1 -0
  88. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  89. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  90. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  91. package/lib/src/generated/api/LinkInput.js +2 -0
  92. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  93. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  94. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  95. package/lib/src/generated/api/LinkMutations.js +1 -0
  96. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  97. package/lib/src/generated/api/LinkStatus.js +2 -0
  98. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  99. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  100. package/lib/src/generated/api/ModelType.d.ts +1 -0
  101. package/lib/src/generated/api/ModelType.js +2 -0
  102. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  103. package/lib/src/generated/api/NotificationInput.js +2 -0
  104. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  105. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  106. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  107. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  108. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  109. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  110. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  111. package/lib/src/generated/api/PromptRequest.js +2 -0
  112. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  113. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  114. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  115. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  116. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  117. package/lib/src/generated/api/QueryRequest.js +2 -0
  118. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  119. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  120. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  121. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  122. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  123. package/lib/src/generated/api/ResourceInput.js +2 -0
  124. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  125. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  126. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  127. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  128. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  129. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  130. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  131. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  132. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  133. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  134. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  135. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  136. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  137. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  138. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  139. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  140. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  141. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  142. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  143. package/lib/src/generated/api/UserStatistics.js +2 -0
  144. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  145. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  146. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  147. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  148. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  149. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  150. package/lib/src/generated/api/index.d.ts +42 -0
  151. package/lib/src/generated/api/index.js +7 -0
  152. package/lib/src/index.d.ts +8 -2
  153. package/lib/src/index.js +8 -2
  154. package/lib/src/jestSetup.d.ts +0 -1
  155. package/lib/src/jestSetup.js +1 -1
  156. package/lib/src/language/Icon.js +2 -21
  157. package/lib/src/language/Language.d.ts +26 -176
  158. package/lib/src/language/Language.js +32 -72
  159. package/lib/src/language/LanguageClient.d.ts +2 -2
  160. package/lib/src/language/LanguageClient.js +15 -105
  161. package/lib/src/language/LanguageHandle.js +2 -41
  162. package/lib/src/language/LanguageMeta.js +4 -75
  163. package/lib/src/language/LanguageRef.js +2 -25
  164. package/lib/src/links/Links.js +14 -111
  165. package/lib/src/model/Ad4mModel.d.ts +143 -63
  166. package/lib/src/model/Ad4mModel.js +583 -425
  167. package/lib/src/model/Ad4mModel.test.js +1434 -688
  168. package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
  169. package/lib/src/model/ModelQueryBuilder.js +315 -157
  170. package/lib/src/model/Subject.js +6 -6
  171. package/lib/src/model/decorators.d.ts +36 -8
  172. package/lib/src/model/decorators.js +41 -14
  173. package/lib/src/model/hydration-batch.d.ts +34 -0
  174. package/lib/src/model/hydration-batch.js +147 -0
  175. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  176. package/lib/src/model/hydration-batching.test.js +456 -0
  177. package/lib/src/model/hydration.d.ts +3 -92
  178. package/lib/src/model/hydration.js +3 -691
  179. package/lib/src/model/index.d.ts +3 -4
  180. package/lib/src/model/index.js +3 -4
  181. package/lib/src/model/json-schema.js +2 -2
  182. package/lib/src/model/model-manifest.d.ts +41 -0
  183. package/lib/src/model/model-manifest.js +11 -0
  184. package/lib/src/model/query-cache.d.ts +30 -0
  185. package/lib/src/model/query-cache.js +66 -0
  186. package/lib/src/model/query-cache.test.d.ts +1 -0
  187. package/lib/src/model/query-cache.test.js +43 -0
  188. package/lib/src/model/query-common.d.ts +1 -1
  189. package/lib/src/model/query-common.js +1 -1
  190. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  191. package/lib/src/model/query-sparql-batch.js +260 -0
  192. package/lib/src/model/query-sparql.d.ts +51 -0
  193. package/lib/src/model/query-sparql.js +466 -0
  194. package/lib/src/model/query-sparql.test.d.ts +1 -0
  195. package/lib/src/model/query-sparql.test.js +312 -0
  196. package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
  197. package/lib/src/model/query-utils.js +189 -0
  198. package/lib/src/model/relation-filtering.test.js +15 -15
  199. package/lib/src/model/sdna.js +1 -1
  200. package/lib/src/model/shacl-gen.js +154 -57
  201. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  202. package/lib/src/model/subscription-delta.test.js +180 -0
  203. package/lib/src/model/subscription-pool.d.ts +39 -0
  204. package/lib/src/model/subscription-pool.js +165 -0
  205. package/lib/src/model/types.d.ts +195 -5
  206. package/lib/src/model/types.js +5 -2
  207. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  208. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  209. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  210. package/lib/src/perspectives/LinkQuery.js +2 -42
  211. package/lib/src/perspectives/Perspective.d.ts +1 -1
  212. package/lib/src/perspectives/Perspective.js +10 -52
  213. package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
  214. package/lib/src/perspectives/PerspectiveClient.js +188 -454
  215. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  216. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  217. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  218. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  219. package/lib/src/perspectives/PerspectiveProxy.d.ts +157 -78
  220. package/lib/src/perspectives/PerspectiveProxy.js +475 -389
  221. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  222. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  223. package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
  224. package/lib/src/perspectives/SparqlBindings.js +65 -0
  225. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
  226. package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
  227. package/lib/src/runtime/RuntimeClient.d.ts +8 -6
  228. package/lib/src/runtime/RuntimeClient.js +97 -454
  229. package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
  230. package/lib/src/runtime/RuntimeResolver.js +84 -0
  231. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  232. package/lib/src/runtime/RuntimeTypes.js +45 -0
  233. package/lib/src/schema.gql +14 -1
  234. package/lib/src/shacl/SHACLFlow.d.ts +1 -1
  235. package/lib/src/shacl/SHACLFlow.js +9 -9
  236. package/lib/src/shacl/SHACLShape.d.ts +26 -1
  237. package/lib/src/shacl/SHACLShape.js +140 -38
  238. package/lib/src/shacl/SHACLShape.test.js +82 -0
  239. package/lib/src/typeDefs.js +3 -615
  240. package/lib/src/utils.d.ts +6 -6
  241. package/lib/src/utils.js +6 -6
  242. package/package.json +9 -24
  243. package/rollup.config.js +0 -7
  244. package/src/Ad4mClient.test.ts +1192 -1288
  245. package/src/Ad4mClient.ts +46 -15
  246. package/src/Literal.test.ts +10 -5
  247. package/src/Literal.ts +6 -5
  248. package/src/agent/Agent.ts +0 -99
  249. package/src/agent/AgentClient.ts +238 -467
  250. package/src/agent/AgentStatus.ts +0 -12
  251. package/src/ai/AIClient.ts +96 -296
  252. package/src/ai/AITypes.ts +66 -0
  253. package/src/ai/Tasks.ts +0 -52
  254. package/src/apiClient.ts +287 -0
  255. package/src/cache/PersistentCache.ts +145 -0
  256. package/src/cache/cache.test.ts +713 -0
  257. package/src/expression/Expression.ts +3 -43
  258. package/src/expression/ExpressionClient.ts +148 -77
  259. package/src/expression/ExpressionRef.ts +2 -8
  260. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  261. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  262. package/src/generated/api/AddLinkRequest.ts +4 -0
  263. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  264. package/src/generated/api/AddSdnaRequest.ts +3 -0
  265. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  266. package/src/generated/api/AuthInfoInput.ts +4 -0
  267. package/src/generated/api/CapabilityInput.ts +4 -0
  268. package/src/generated/api/CommitBatchRequest.ts +3 -0
  269. package/src/generated/api/ComputeLogEntry.ts +3 -0
  270. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  271. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  272. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  273. package/src/generated/api/EmbedRequest.ts +3 -0
  274. package/src/generated/api/EntanglementProofInput.ts +3 -0
  275. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  276. package/src/generated/api/ExportRequest.ts +3 -0
  277. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  278. package/src/generated/api/ExpressionProof.ts +3 -0
  279. package/src/generated/api/ExpressionProofInput.ts +3 -0
  280. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  281. package/src/generated/api/FriendsListRequest.ts +3 -0
  282. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  283. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  284. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  285. package/src/generated/api/ImportAgentRequest.ts +3 -0
  286. package/src/generated/api/ImportRequest.ts +3 -0
  287. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  288. package/src/generated/api/LanguageMetaInput.ts +3 -0
  289. package/src/generated/api/Link.ts +3 -0
  290. package/src/generated/api/LinkExpression.ts +6 -0
  291. package/src/generated/api/LinkExpressionInput.ts +6 -0
  292. package/src/generated/api/LinkInput.ts +3 -0
  293. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  294. package/src/generated/api/LinkMutations.ts +5 -0
  295. package/src/generated/api/LinkStatus.ts +3 -0
  296. package/src/generated/api/LockAgentRequest.ts +3 -0
  297. package/src/generated/api/ModelType.ts +3 -0
  298. package/src/generated/api/NotificationInput.ts +3 -0
  299. package/src/generated/api/OpenLinkRequest.ts +3 -0
  300. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  301. package/src/generated/api/PerspectiveInput.ts +4 -0
  302. package/src/generated/api/PromptRequest.ts +3 -0
  303. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  304. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  305. package/src/generated/api/QueryRequest.ts +6 -0
  306. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  307. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  308. package/src/generated/api/ResourceInput.ts +3 -0
  309. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  310. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  311. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  312. package/src/generated/api/SetStatusRequest.ts +3 -0
  313. package/src/generated/api/SignMessageRequest.ts +3 -0
  314. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  315. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  316. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  317. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  318. package/src/generated/api/UserStatistics.ts +3 -0
  319. package/src/generated/api/VerificationRequestResult.ts +3 -0
  320. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  321. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  322. package/src/generated/api/index.ts +49 -0
  323. package/src/index.ts +8 -2
  324. package/src/jestSetup.ts +1 -1
  325. package/src/language/Icon.ts +0 -4
  326. package/src/language/Language.ts +51 -248
  327. package/src/language/LanguageClient.ts +21 -132
  328. package/src/language/LanguageHandle.ts +0 -14
  329. package/src/language/LanguageMeta.ts +0 -29
  330. package/src/language/LanguageRef.ts +0 -7
  331. package/src/links/Links.ts +0 -37
  332. package/src/model/Ad4mModel.test.ts +1664 -792
  333. package/src/model/Ad4mModel.ts +664 -499
  334. package/src/model/ModelQueryBuilder.ts +362 -183
  335. package/src/model/decorators.ts +71 -22
  336. package/src/model/hydration.ts +3 -772
  337. package/src/model/index.ts +3 -4
  338. package/src/model/json-schema.ts +2 -2
  339. package/src/model/query-cache.test.ts +54 -0
  340. package/src/model/query-cache.ts +79 -0
  341. package/src/model/query-common.ts +1 -1
  342. package/src/model/query-sparql.test.ts +376 -0
  343. package/src/model/query-sparql.ts +504 -0
  344. package/src/model/query-utils.ts +209 -0
  345. package/src/model/relation-filtering.test.ts +60 -53
  346. package/src/model/sdna.ts +1 -1
  347. package/src/model/shacl-gen.ts +163 -64
  348. package/src/model/shacl-roundtrip.test.ts +197 -0
  349. package/src/model/types-typed-query.test.ts +360 -0
  350. package/src/model/types.ts +256 -5
  351. package/src/neighbourhood/Neighbourhood.ts +0 -9
  352. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  353. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  354. package/src/perspectives/LinkQuery.ts +0 -15
  355. package/src/perspectives/Perspective.ts +1 -12
  356. package/src/perspectives/PerspectiveClient.test.ts +262 -0
  357. package/src/perspectives/PerspectiveClient.ts +252 -468
  358. package/src/perspectives/PerspectiveDiff.ts +0 -8
  359. package/src/perspectives/PerspectiveHandle.ts +1 -12
  360. package/src/perspectives/PerspectiveProxy.test.ts +125 -0
  361. package/src/perspectives/PerspectiveProxy.ts +522 -434
  362. package/src/perspectives/SparqlBindings.ts +79 -0
  363. package/src/perspectives/WakerSubscriptionManager.ts +13 -13
  364. package/src/runtime/RuntimeClient.ts +118 -461
  365. package/src/runtime/RuntimeTypes.ts +144 -0
  366. package/src/shacl/SHACLFlow.ts +9 -9
  367. package/src/shacl/SHACLShape.test.ts +204 -0
  368. package/src/shacl/SHACLShape.ts +191 -39
  369. package/src/typeDefs.ts +3 -5
  370. package/src/utils.ts +6 -6
  371. package/tsconfig.json +3 -7
  372. package/lib/src/model/query-surreal.d.ts +0 -44
  373. package/lib/src/model/query-surreal.js +0 -249
  374. package/lib/src/model/surreal-utils.js +0 -128
  375. package/shims/reflect-metadata.ts +0 -0
  376. package/shims/type-graphql.ts +0 -75
  377. package/src/PubSub.ts +0 -17
  378. package/src/agent/AgentResolver.ts +0 -263
  379. package/src/ai/AIResolver.ts +0 -372
  380. package/src/buildSchema.ts +0 -43
  381. package/src/expression/ExpressionResolver.ts +0 -64
  382. package/src/language/LanguageContext.ts +0 -37
  383. package/src/language/LanguageResolver.ts +0 -98
  384. package/src/model/Subject.ts +0 -159
  385. package/src/model/prolog-facts.ts +0 -145
  386. package/src/model/query-prolog.ts +0 -148
  387. package/src/model/query-surreal.ts +0 -280
  388. package/src/model/surreal-utils.ts +0 -147
  389. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  390. package/src/perspectives/PerspectiveResolver.ts +0 -372
  391. package/src/runtime/RuntimeResolver.ts +0 -691
  392. package/src/unwrapApolloResult.ts +0 -16
  393. package/tsconfig-browser.json +0 -82
@@ -0,0 +1,360 @@
1
+ /**
2
+ * Type-level assertion tests for the TypedQuery / TypedWhere / TypedIncludeMap
3
+ * surface added in PLAN_6.
4
+ *
5
+ * These tests verify the *compile-time* behaviour of the generic query types.
6
+ * Runtime assertions are minimal — the real checks are the `// @ts-expect-error`
7
+ * markers and the `expectAssignable` / `expectExact` helpers, all of which fail
8
+ * loudly under `tsc --noEmit`.
9
+ */
10
+
11
+ import { Ad4mModel } from "./Ad4mModel";
12
+ import { Model, Property, HasMany, BelongsToOne } from "./decorators";
13
+ import type {
14
+ PropertyKeysOf, RelationKeysOf, RelatedModel,
15
+ TypedQuery, TypedWhere, TypedOrder, TypedIncludeMap, TypedIncludeProjection,
16
+ IncludeExtras, Query,
17
+ } from "./types";
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Fixtures
21
+ // ---------------------------------------------------------------------------
22
+
23
+ @Model({ name: "Comment" })
24
+ class Comment extends Ad4mModel {
25
+ @Property({ through: "comment://text" })
26
+ text: string = "";
27
+
28
+ @Property({ through: "comment://likes" })
29
+ likes: number = 0;
30
+ }
31
+
32
+ @Model({ name: "Post" })
33
+ class Post extends Ad4mModel {
34
+ @Property({ through: "post://title", required: true })
35
+ title: string = "";
36
+
37
+ @Property({ through: "post://body" })
38
+ body: string = "";
39
+
40
+ @Property({ through: "post://is_pinned" })
41
+ isPinned: boolean = false;
42
+
43
+ @Property({ through: "post://views" })
44
+ views: number = 0;
45
+
46
+ @HasMany(() => Comment, { through: "post://comment" })
47
+ comments: Comment[] = [];
48
+
49
+ @BelongsToOne({ through: "post://author_of" })
50
+ authorRef: Comment | null = null;
51
+ }
52
+
53
+ // AgentProfile-like fixture: inheritance + optional HasOne relation.
54
+ // This mirrors `we/packages/models/src/entities/AgentProfile.ts` which
55
+ // previously surfaced a type bug in StrictTypedIncludeMap.
56
+ class WeNodeLike extends Ad4mModel {
57
+ @HasMany({ through: "we://signal" })
58
+ signals: string[] = [];
59
+ }
60
+
61
+ class LocationBlockLike extends WeNodeLike {
62
+ @Property({ through: "loc://name" })
63
+ name: string = "";
64
+ }
65
+
66
+ @Model({ name: "AgentProfileLike" })
67
+ class AgentProfileLike extends WeNodeLike {
68
+ @Property({ through: "we://handle" })
69
+ handle: string = "";
70
+
71
+ @Property({ through: "we://avatar" })
72
+ avatar?: string;
73
+
74
+ // Optional HasOne — Ad4mModel | undefined. Was previously not picked up
75
+ // by RelationKeysOf (which only checked `| null`), causing valid
76
+ // `include: { location: true }` calls to be rejected at the type level.
77
+ location?: LocationBlockLike;
78
+ }
79
+
80
+ // Optional-array fixture: covers `?: T[]` and `?: string[]` patterns. Before
81
+ // the `NonNullable<T[K]> extends X[]` change, these optional array relations
82
+ // were silently dropped from RelationKeysOf because `Foo[] | undefined extends
83
+ // Foo[]` evaluates to false.
84
+ @Model({ name: "OptionalArrayLike" })
85
+ class OptionalArrayLike extends Ad4mModel {
86
+ @Property({ through: "x://name" })
87
+ name: string = "";
88
+
89
+ // Optional typed-array relation
90
+ @HasMany(() => Comment, { through: "x://comments" })
91
+ comments?: Comment[];
92
+
93
+ // Optional string[] relation (the `@HasMany` + `string[]` pattern)
94
+ @HasMany({ through: "x://members" })
95
+ members?: string[];
96
+
97
+ // Optional scalar array — also `string[] | undefined`, should appear as a
98
+ // relation too (matches the runtime semantics: any array field can be a
99
+ // link collection unless we have stronger schema info).
100
+ tags?: string[];
101
+ }
102
+
103
+ // ---------------------------------------------------------------------------
104
+ // Type-level helpers
105
+ // ---------------------------------------------------------------------------
106
+
107
+ type Equals<X, Y> =
108
+ (<T>() => T extends X ? 1 : 2) extends
109
+ (<T>() => T extends Y ? 1 : 2) ? true : false;
110
+
111
+ function expectExact<T1, T2>(_: Equals<T1, T2> extends true ? true : never): void {}
112
+ function expectAssignable<T>(_: T): void {}
113
+
114
+ // ---------------------------------------------------------------------------
115
+ // PropertyKeysOf / RelationKeysOf
116
+ // ---------------------------------------------------------------------------
117
+
118
+ type PostProps = PropertyKeysOf<Post>;
119
+ type PostRels = RelationKeysOf<Post>;
120
+
121
+ expectExact<PostProps, "title" | "body" | "isPinned" | "views">(true);
122
+ expectExact<PostRels, "comments" | "authorRef">(true);
123
+
124
+ expectExact<RelatedModel<Post, "comments">, Comment>(true);
125
+ expectExact<RelatedModel<Post, "authorRef">, Comment>(true);
126
+
127
+ // AgentProfileLike — inheritance + optional HasOne via `?: T`
128
+ type AgentRels = RelationKeysOf<AgentProfileLike>;
129
+ type AgentProps = PropertyKeysOf<AgentProfileLike>;
130
+
131
+ // `location?: LocationBlockLike` (i.e. `LocationBlockLike | undefined`) must
132
+ // be recognised as a relation. `signals: string[]` inherited from WeNodeLike
133
+ // also counts (the `@HasMany` + `string[]` pattern).
134
+ expectAssignable<AgentRels>("location");
135
+ expectAssignable<AgentRels>("signals");
136
+ expectAssignable<AgentProps>("handle");
137
+ expectAssignable<AgentProps>("avatar");
138
+
139
+ expectAssignable<TypedIncludeMap<AgentProfileLike>>({ location: true });
140
+ expectAssignable<TypedIncludeMap<AgentProfileLike>>({ signals: true });
141
+
142
+ // Optional-array regression: `comments?: Comment[]`, `members?: string[]`,
143
+ // `tags?: string[]` should all be recognised as relations. Previously
144
+ // rejected because `T[K] = T[] | undefined` doesn't extend `T[]`.
145
+ type OptArrRels = RelationKeysOf<OptionalArrayLike>;
146
+ expectAssignable<OptArrRels>("comments");
147
+ expectAssignable<OptArrRels>("members");
148
+ expectAssignable<OptArrRels>("tags");
149
+
150
+ expectAssignable<TypedIncludeMap<OptionalArrayLike>>({ comments: true });
151
+ expectAssignable<TypedIncludeMap<OptionalArrayLike>>({ members: true });
152
+ expectAssignable<TypedIncludeMap<OptionalArrayLike>>({
153
+ $commentCount: { from: "comments", count: true },
154
+ });
155
+
156
+ // RelatedModel must also peel the optional wrapper before inferring U
157
+ expectExact<RelatedModel<OptionalArrayLike, "comments">, Comment>(true);
158
+
159
+ // ---------------------------------------------------------------------------
160
+ // TypedWhere
161
+ // ---------------------------------------------------------------------------
162
+
163
+ // Valid where shapes
164
+ expectAssignable<TypedWhere<Post>>({ title: "hello" });
165
+ expectAssignable<TypedWhere<Post>>({ title: { contains: "x" } });
166
+ expectAssignable<TypedWhere<Post>>({ views: { gt: 5, lte: 100 } });
167
+ expectAssignable<TypedWhere<Post>>({ isPinned: true });
168
+ expectAssignable<TypedWhere<Post>>({ id: "literal:foo" });
169
+ expectAssignable<TypedWhere<Post>>({ author: "did:key:alice" });
170
+
171
+ // Misspelled property — must error
172
+ // @ts-expect-error
173
+ expectAssignable<TypedWhere<Post>>({ titel: "hello" });
174
+
175
+ // Wrong value type — must error
176
+ // @ts-expect-error
177
+ expectAssignable<TypedWhere<Post>>({ isPinned: "yes" });
178
+
179
+ // Numeric op on string field — must error
180
+ // @ts-expect-error
181
+ expectAssignable<TypedWhere<Post>>({ title: { gt: 5 } });
182
+
183
+ // String op on numeric field — must error
184
+ // @ts-expect-error
185
+ expectAssignable<TypedWhere<Post>>({ views: { contains: "x" } });
186
+
187
+ // ---------------------------------------------------------------------------
188
+ // TypedOrder
189
+ // ---------------------------------------------------------------------------
190
+
191
+ expectAssignable<TypedOrder<Post>>({ title: "ASC" });
192
+ expectAssignable<TypedOrder<Post>>({ views: "DESC", timestamp: "ASC" });
193
+
194
+ // @ts-expect-error — unknown field
195
+ expectAssignable<TypedOrder<Post>>({ titel: "ASC" });
196
+
197
+ // @ts-expect-error — invalid direction
198
+ expectAssignable<TypedOrder<Post>>({ title: "ASCENDING" });
199
+
200
+ // ---------------------------------------------------------------------------
201
+ // TypedIncludeMap — eager-load + nested
202
+ // ---------------------------------------------------------------------------
203
+
204
+ expectAssignable<TypedIncludeMap<Post>>({ comments: true });
205
+ expectAssignable<TypedIncludeMap<Post>>({ authorRef: true });
206
+ expectAssignable<TypedIncludeMap<Post>>({
207
+ comments: { where: { text: "x" }, order: { likes: "DESC" }, limit: 5 },
208
+ });
209
+
210
+ // Misspelled relation — must error
211
+ // @ts-expect-error
212
+ expectAssignable<TypedIncludeMap<Post>>({ commments: true });
213
+
214
+ // Nested where typo — must error
215
+ // @ts-expect-error
216
+ expectAssignable<TypedIncludeMap<Post>>({ comments: { where: { txet: "x" } } });
217
+
218
+ // Nested numeric op on string — must error
219
+ // @ts-expect-error
220
+ expectAssignable<TypedIncludeMap<Post>>({ comments: { where: { text: { gt: 5 } } } });
221
+
222
+ // ---------------------------------------------------------------------------
223
+ // TypedIncludeProjection ($-prefixed keys)
224
+ // ---------------------------------------------------------------------------
225
+
226
+ // Valid: count true projection
227
+ expectAssignable<TypedIncludeMap<Post>>({
228
+ $commentCount: { from: "comments", count: true },
229
+ });
230
+
231
+ // Valid: filtered projection with limit
232
+ expectAssignable<TypedIncludeMap<Post>>({
233
+ $firstComment: { from: "comments", where: { text: "hi" }, limit: 1 },
234
+ });
235
+
236
+ // `from` must reference a real relation
237
+ {
238
+ const _bad1: TypedIncludeMap<Post> = {
239
+ $bogus: {
240
+ // @ts-expect-error — "notARelation" is not in RelationKeysOf<Post>
241
+ from: "notARelation",
242
+ count: true,
243
+ },
244
+ };
245
+ void _bad1;
246
+ }
247
+
248
+ // Projection's nested where uses the *target's* property keys
249
+ expectAssignable<TypedIncludeMap<Post>>({
250
+ $popular: { from: "comments", where: { likes: { gt: 100 } }, limit: 10 },
251
+ });
252
+
253
+ // Wrong nested where key on the target
254
+ {
255
+ const _bad2: TypedIncludeMap<Post> = {
256
+ $bad: {
257
+ from: "comments",
258
+ // @ts-expect-error — "titel" is not a property of Comment
259
+ where: { titel: "x" },
260
+ },
261
+ };
262
+ void _bad2;
263
+ }
264
+
265
+ // ---------------------------------------------------------------------------
266
+ // IncludeExtras — propagating $-keys into the row type
267
+ // ---------------------------------------------------------------------------
268
+
269
+ type CountProjection = { $commentCount: { from: "comments"; count: true } };
270
+ type Limit1Projection = { $firstComment: { from: "comments"; limit: 1 } };
271
+ type ListProjection = { $allComments: { from: "comments" } };
272
+
273
+ expectExact<IncludeExtras<Post, CountProjection>["$commentCount"], number>(true);
274
+ expectExact<IncludeExtras<Post, Limit1Projection>["$firstComment"], Comment | null>(true);
275
+ expectExact<IncludeExtras<Post, ListProjection>["$allComments"], Comment[]>(true);
276
+
277
+ // ---------------------------------------------------------------------------
278
+ // TypedQuery — full shape
279
+ // ---------------------------------------------------------------------------
280
+
281
+ expectAssignable<TypedQuery<Post>>({
282
+ where: { isPinned: true, views: { gt: 10 } },
283
+ order: { views: "DESC" },
284
+ include: { comments: { limit: 5 }, $commentCount: { from: "comments", count: true } },
285
+ includeAll: false,
286
+ deepQuery: true,
287
+ limit: 20,
288
+ offset: 0,
289
+ count: true,
290
+ properties: ["title", "body"],
291
+ });
292
+
293
+ // @ts-expect-error — properties[] only accepts declared property names
294
+ expectAssignable<TypedQuery<Post>>({ properties: ["title", "nonsense"] });
295
+
296
+ // ---------------------------------------------------------------------------
297
+ // fromSHACL escape hatch — TypedQuery<Ad4mModel> collapses to loose Query
298
+ // ---------------------------------------------------------------------------
299
+
300
+ // When T has no declared fields (i.e. Ad4mModel itself), TypedQuery<T> ≡ Query.
301
+ expectExact<TypedQuery<Ad4mModel>, Query>(true);
302
+ expectAssignable<TypedQuery<Ad4mModel>>({ where: { anyKey: "value" } });
303
+
304
+ // ---------------------------------------------------------------------------
305
+ // End-to-end inference through findAll / findOne — verifies that the literal
306
+ // `count: true` propagates through `Q extends TypedQuery<T>` into the return
307
+ // type so callers don't need `(row as any).$xxx` casts.
308
+ // ---------------------------------------------------------------------------
309
+
310
+ import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
311
+ declare const persp: PerspectiveProxy;
312
+
313
+ // Skip async actually-running them — these calls are unreachable at runtime
314
+ // (no perspective). The point is that they compile with correct return types.
315
+ function _typeFlowChecks() {
316
+ return async () => {
317
+ // No include — plain Post[]
318
+ const a = await Post.findAll(persp);
319
+ expectAssignable<Post[]>(a);
320
+
321
+ // Include eager-loaded relation — still Post[]
322
+ const b = await Post.findAll(persp, { include: { comments: true } });
323
+ expectAssignable<Post[]>(b);
324
+
325
+ // Projection: count → number on result rows
326
+ const c = await Post.findAll(persp, {
327
+ include: { $commentCount: { from: "comments", count: true } },
328
+ });
329
+ expectAssignable<number>(c[0].$commentCount);
330
+
331
+ // Projection: limit 1 → scalar | null on result rows
332
+ const d = await Post.findAll(persp, {
333
+ include: { $top: { from: "comments", limit: 1 } },
334
+ });
335
+ expectAssignable<Comment | null>(d[0].$top);
336
+
337
+ // Projection: no limit → array on result rows
338
+ const e = await Post.findAll(persp, {
339
+ include: { $all: { from: "comments" } },
340
+ });
341
+ expectAssignable<Comment[]>(e[0].$all);
342
+
343
+ // findOne — same propagation, nullable wrapper
344
+ const f = await Post.findOne(persp, {
345
+ include: { $commentCount: { from: "comments", count: true } },
346
+ });
347
+ if (f) expectAssignable<number>(f.$commentCount);
348
+ };
349
+ }
350
+
351
+ // ---------------------------------------------------------------------------
352
+ // Runtime placeholder — Jest requires at least one test in the file
353
+ // ---------------------------------------------------------------------------
354
+
355
+ describe("typed-query types (compile-time)", () => {
356
+ it("compiles", () => {
357
+ // All assertions above are at type level; this test passes if tsc passed.
358
+ expect(true).toBe(true);
359
+ });
360
+ });
@@ -2,7 +2,7 @@
2
2
  * Shared type definitions for the Ad4mModel system.
3
3
  *
4
4
  * Extracted into a standalone module so that utility files
5
- * (`surreal-utils.ts`, `decorators.ts`, etc.) can import types without
5
+ * (`query-utils.ts`, `decorators.ts`, etc.) can import types without
6
6
  * creating circular runtime dependencies on `Ad4mModel.ts`.
7
7
  */
8
8
 
@@ -61,7 +61,52 @@ export type ParentScope =
61
61
  * ```
62
62
  */
63
63
  export interface IncludeMap {
64
- [relation: string]: boolean | RelationSubQuery;
64
+ [relation: string]: boolean | RelationSubQuery | IncludeProjection;
65
+ }
66
+
67
+ /**
68
+ * A lightweight projection that computes a scalar or list value from a relation
69
+ * without fully hydrating the linked instances.
70
+ *
71
+ * Keys in `IncludeMap` that begin with `$` are treated as projections.
72
+ * Results are attached directly to each queried instance under the same key.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // Attach a like-count to each post
77
+ * const posts = await Post.findAll(perspective, {
78
+ * include: {
79
+ * $likeCount: { from: 'likes', count: true },
80
+ * $myLike: { from: 'likes', limit: 1 },
81
+ * }
82
+ * });
83
+ * posts[0].$likeCount // number
84
+ * posts[0].$myLike // string ID or null
85
+ * ```
86
+ */
87
+ export interface IncludeProjection {
88
+ /** The relation name on the parent model to project over. */
89
+ from: string;
90
+ /** When true, attaches an integer count instead of a list. */
91
+ count?: true;
92
+ /**
93
+ * Bare class name of the projection target. Set automatically by
94
+ * `prepareModelQueryParams`; the executor resolves the target's shape
95
+ * through its in-memory cache when applying projection where filters.
96
+ * @internal
97
+ */
98
+ targetClassName?: string;
99
+ /** Post-hydration where clause applied to the target instances. */
100
+ where?: Where;
101
+ /** Limit results (when 1, the attached value is unwrapped to a scalar). */
102
+ limit?: number;
103
+ /** Order results before applying limit. */
104
+ order?: Order;
105
+ }
106
+
107
+ /** Type guard for IncludeProjection objects. */
108
+ export function isIncludeProjection(val: unknown): val is IncludeProjection {
109
+ return typeof val === 'object' && val !== null && 'from' in val;
65
110
  }
66
111
 
67
112
  export type Query = {
@@ -69,11 +114,27 @@ export type Query = {
69
114
  parent?: ParentScope;
70
115
  properties?: string[];
71
116
  include?: IncludeMap;
117
+ /**
118
+ * When true, eager-loads every declared forward relation on the model.
119
+ * Equivalent to listing all relation field names in `include: {}` explicitly.
120
+ * Useful for tree-walking and manifest-style inspections.
121
+ * Individual relations can still be overridden via `include` (explicit entries take precedence).
122
+ */
123
+ includeAll?: boolean;
72
124
  where?: Where;
73
125
  order?: Order;
74
126
  offset?: number;
75
127
  limit?: number;
76
128
  count?: boolean;
129
+ /**
130
+ * When true, SPARQL property getters (@Property with `getter`) ARE evaluated
131
+ * during collection hydration. Defaults to true — getters run post-pagination
132
+ * via batched VALUES queries so the cost is O(getters), not O(instances × getters).
133
+ *
134
+ * Set to false to explicitly skip getter evaluation for performance-sensitive
135
+ * queries where getter-backed properties are not needed.
136
+ */
137
+ deepQuery?: boolean;
77
138
  };
78
139
 
79
140
  /**
@@ -89,6 +150,196 @@ export type Query = {
89
150
  */
90
151
  export type RelationSubQuery = Omit<Query, 'parent' | 'count'>;
91
152
 
153
+ // ---------------------------------------------------------------------------
154
+ // Typed Query DSL — Phase 1 of PLAN_6_TYPED_QUERIES.md
155
+ //
156
+ // These types layer compile-time field-name and value-type checking on top of
157
+ // the loose Query/Where/Order/IncludeMap. They infer everything from the
158
+ // model class's declared TS fields — no codegen, no runtime changes.
159
+ //
160
+ // Dynamic models (e.g. produced by `Ad4mModel.fromSHACL()`) carry no
161
+ // field-level type information; for those `TypedQuery<Ad4mModel>` collapses
162
+ // to the loose `Query` shape, which is the correct escape hatch.
163
+ // ---------------------------------------------------------------------------
164
+
165
+ /** Keys of T that are user-declared (not methods, not inherited from Ad4mModel). */
166
+ export type ModelDataKeys<T extends Ad4mModel> = {
167
+ [K in keyof T]: K extends keyof Ad4mModel ? never
168
+ : T[K] extends (...args: any[]) => any ? never
169
+ : K
170
+ }[keyof T];
171
+
172
+ /** Keys of T that can appear in a `where` clause — scalars and scalar arrays.
173
+ * Excludes typed Ad4mModel references (single or array); `string[]`/`number[]`
174
+ * remain included because they're often filterable even when also used as
175
+ * link targets.
176
+ *
177
+ * Iterates over `keyof T` directly (not `ModelDataKeys<T>`) to preserve the
178
+ * key constraint — mapped types over computed type aliases sometimes widen
179
+ * to `string | undefined` in the key position, which then breaks indexing. */
180
+ export type PropertyKeysOf<T extends Ad4mModel> = {
181
+ [K in keyof T]: K extends ModelDataKeys<T>
182
+ ? NonNullable<T[K]> extends Ad4mModel ? never
183
+ : NonNullable<T[K]> extends Ad4mModel[] ? never
184
+ : K
185
+ : never
186
+ }[keyof T];
187
+
188
+ /** Keys of T that can appear in `include` — typed Ad4mModel references AND
189
+ * `string[]` link-target arrays (the `@HasMany` + `string[]` pattern that
190
+ * AD4M uses for relations without a target class thunk). Handles both
191
+ * `?: Foo` (optional → `Foo | undefined`) and `Foo | null` field shapes, and
192
+ * optional/nullable array variants (`?: Foo[]`, `Foo[] | null`). */
193
+ export type RelationKeysOf<T extends Ad4mModel> = {
194
+ [K in keyof T]: K extends ModelDataKeys<T>
195
+ ? NonNullable<T[K]> extends Ad4mModel ? K
196
+ : NonNullable<T[K]> extends Ad4mModel[] ? K
197
+ : NonNullable<T[K]> extends string[] ? K
198
+ : never
199
+ : never
200
+ }[keyof T];
201
+
202
+ /** The model type referenced by a relation field K on T.
203
+ * Falls back to `Ad4mModel` (loose) for the `string[]` relation pattern,
204
+ * since no target class is available at the type level. */
205
+ export type RelatedModel<T extends Ad4mModel, K extends RelationKeysOf<T>> =
206
+ NonNullable<T[K]> extends (infer U)[] ? (U extends Ad4mModel ? U : Ad4mModel)
207
+ : NonNullable<T[K]> extends Ad4mModel ? NonNullable<T[K]>
208
+ : Ad4mModel;
209
+
210
+ /** True when T has no statically-declared data fields (e.g. fromSHACL classes). */
211
+ type HasNoTypedFields<T extends Ad4mModel> =
212
+ [PropertyKeysOf<T> | RelationKeysOf<T>] extends [never] ? true : false;
213
+
214
+ // ---- Typed where conditions --------------------------------------------------
215
+
216
+ export type StringWhereOps = {
217
+ not?: string | string[];
218
+ contains?: string;
219
+ };
220
+
221
+ export type NumericWhereOps = {
222
+ not?: number | number[];
223
+ lt?: number;
224
+ lte?: number;
225
+ gt?: number;
226
+ gte?: number;
227
+ between?: [number, number];
228
+ };
229
+
230
+ export type TypedWhereCondition<V> =
231
+ V extends string ? string | string[] | StringWhereOps
232
+ : V extends number ? number | number[] | NumericWhereOps
233
+ : V extends boolean ? boolean
234
+ : V extends Array<infer U>
235
+ ? U extends string ? string | string[] | StringWhereOps
236
+ : U extends number ? number | number[] | NumericWhereOps
237
+ : WhereCondition
238
+ : WhereCondition;
239
+
240
+ /** Strict Where: keys constrained to T's properties, plus the well-known
241
+ * link-metadata fields (`id`/`author`/`timestamp`). */
242
+ type StrictTypedWhere<T extends Ad4mModel> =
243
+ & { [K in PropertyKeysOf<T>]?: TypedWhereCondition<T[K]> }
244
+ & {
245
+ base?: string | string[];
246
+ id?: string | string[];
247
+ author?: WhereCondition;
248
+ timestamp?: WhereCondition;
249
+ };
250
+
251
+ /** Public typed `where` for a model class. Falls back to the loose `Where`
252
+ * shape when T has no declared fields (e.g. fromSHACL-derived classes). */
253
+ export type TypedWhere<T extends Ad4mModel> =
254
+ HasNoTypedFields<T> extends true ? Where : StrictTypedWhere<T>;
255
+
256
+ // ---- Typed order -------------------------------------------------------------
257
+
258
+ type StrictTypedOrder<T extends Ad4mModel> = {
259
+ [K in PropertyKeysOf<T> | 'timestamp' | 'author' | 'createdAt' | 'updatedAt']?: 'ASC' | 'DESC';
260
+ };
261
+
262
+ export type TypedOrder<T extends Ad4mModel> =
263
+ HasNoTypedFields<T> extends true ? Order : StrictTypedOrder<T>;
264
+
265
+ // ---- Typed include + projection ---------------------------------------------
266
+
267
+ /** Sub-query for an eager-loaded relation — inherits the target model's constraints. */
268
+ export type TypedRelationSubQuery<U extends Ad4mModel> = {
269
+ where?: TypedWhere<U>;
270
+ order?: TypedOrder<U>;
271
+ include?: TypedIncludeMap<U>;
272
+ limit?: number;
273
+ offset?: number;
274
+ };
275
+
276
+ /** Projection — `from` must be a real relation on T; `where`/`order` constrained to that target.
277
+ * Modelled as a discriminated union so the literal `count: true` and `limit: 1`
278
+ * variants narrow inference into `IncludeExtras` (count → number, limit-1 → scalar). */
279
+ export type TypedIncludeProjection<T extends Ad4mModel> = {
280
+ [K in RelationKeysOf<T>]:
281
+ | { from: K; count: true }
282
+ | { from: K; limit: 1; where?: TypedWhere<RelatedModel<T, K>>; order?: TypedOrder<RelatedModel<T, K>> }
283
+ | { from: K; limit?: number; where?: TypedWhere<RelatedModel<T, K>>; order?: TypedOrder<RelatedModel<T, K>> };
284
+ }[RelationKeysOf<T>];
285
+
286
+ type StrictTypedIncludeMap<T extends Ad4mModel> =
287
+ & { [K in RelationKeysOf<T>]?: boolean | TypedRelationSubQuery<RelatedModel<T, K>> }
288
+ & { [K in `$${string}`]?: TypedIncludeProjection<T> };
289
+
290
+ export type TypedIncludeMap<T extends Ad4mModel> =
291
+ HasNoTypedFields<T> extends true ? IncludeMap : StrictTypedIncludeMap<T>;
292
+
293
+ // ---- Result-side: project $-keys into the returned row type ------------------
294
+
295
+ /**
296
+ * Given a model T and an `include` literal I, compute the extra fields
297
+ * contributed by `$`-prefixed projection keys.
298
+ *
299
+ * - `{ count: true }` → `number`
300
+ * - `{ from: R, limit: 1 }` → `RelatedModel<T,R> | null`
301
+ * - `{ from: R }` (no limit/1) → `RelatedModel<T,R>[]`
302
+ *
303
+ * Returns `unknown` (intersection-neutral) when `I` has no `$`-keys, so that
304
+ * `T & IncludeExtras<T, I>` collapses back to `T` and downstream type
305
+ * predicates (`(x): x is T => ...`) keep working unchanged.
306
+ */
307
+ export type IncludeExtras<T extends Ad4mModel, I> =
308
+ I extends Record<string, any>
309
+ ? Extract<keyof I, `$${string}`> extends never
310
+ ? unknown
311
+ : {
312
+ [K in Extract<keyof I, `$${string}`>]:
313
+ I[K] extends { count: true } ? number
314
+ : I[K] extends { from: infer R; limit: 1 }
315
+ ? (R extends RelationKeysOf<T> ? RelatedModel<T, R> | null : never)
316
+ : I[K] extends { from: infer R }
317
+ ? (R extends RelationKeysOf<T> ? RelatedModel<T, R>[] : never)
318
+ : unknown;
319
+ }
320
+ : unknown;
321
+
322
+ // ---- Typed Query -------------------------------------------------------------
323
+
324
+ type StrictTypedQuery<T extends Ad4mModel> = {
325
+ parent?: ParentScope;
326
+ properties?: PropertyKeysOf<T>[];
327
+ include?: TypedIncludeMap<T>;
328
+ includeAll?: boolean;
329
+ where?: TypedWhere<T>;
330
+ order?: TypedOrder<T>;
331
+ offset?: number;
332
+ limit?: number;
333
+ count?: boolean;
334
+ deepQuery?: boolean;
335
+ };
336
+
337
+ export type TypedQuery<T extends Ad4mModel> =
338
+ HasNoTypedFields<T> extends true ? Query : StrictTypedQuery<T>;
339
+
340
+ /** Helper that extracts the `include` literal from a TypedQuery for use with IncludeExtras. */
341
+ export type IncludeOf<Q> = Q extends { include?: infer I } ? I : undefined;
342
+
92
343
  /**
93
344
  * Options accepted by the instance `get()` method.
94
345
  *
@@ -100,7 +351,7 @@ export type GetOptions = Pick<Query, 'include' | 'properties'>;
100
351
  // Result types
101
352
  // ---------------------------------------------------------------------------
102
353
 
103
- export type AllInstancesResult = { AllInstances: Ad4mModel[]; TotalCount?: number; isInit?: boolean };
354
+ export type AllInstancesResult = { AllInstances: Ad4mModel[]; TotalCount?: number };
104
355
  export type ResultsWithTotalCount<T> = { results: T[]; totalCount?: number };
105
356
  export type PaginationResult<T> = { results: T[]; totalCount?: number; pageSize: number; pageNumber: number };
106
357
 
@@ -134,7 +385,7 @@ export interface PropertyMetadata {
134
385
  prologGetter?: string;
135
386
  /** Custom Prolog setter code */
136
387
  prologSetter?: string;
137
- /** Custom SurrealQL getter code */
388
+ /** Custom getter code */
138
389
  getter?: string;
139
390
  /** Whether stored locally only */
140
391
  local?: boolean;
@@ -152,7 +403,7 @@ export interface RelationMetadata {
152
403
  name: string;
153
404
  /** The predicate URI (through value) */
154
405
  predicate: string;
155
- /** Custom SurrealQL getter code */
406
+ /** Custom getter code */
156
407
  getter?: string;
157
408
  /** Whether stored locally only */
158
409
  local?: boolean;
@@ -1,15 +1,8 @@
1
- import { Field, ObjectType } from "type-graphql";
2
1
  import { ExpressionGeneric } from "../expression/Expression";
3
2
  import { LanguageRef } from "../language/LanguageRef";
4
3
  import { Perspective } from "../perspectives/Perspective";
5
-
6
-
7
- @ObjectType()
8
4
  export class Neighbourhood {
9
- @Field()
10
5
  linkLanguage: string
11
-
12
- @Field()
13
6
  meta: Perspective
14
7
 
15
8
  constructor(linkLanguage: string, meta: Perspective) {
@@ -17,6 +10,4 @@ export class Neighbourhood {
17
10
  this.meta = meta;
18
11
  }
19
12
  }
20
-
21
- @ObjectType()
22
13
  export class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {};