@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +5097 -11841
- package/lib/index.js +5289 -12104
- package/lib/src/Ad4mClient.d.ts +9 -3
- package/lib/src/Ad4mClient.js +40 -13
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +33 -21
- package/lib/src/agent/AgentClient.js +180 -374
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +53 -0
- package/lib/src/apiClient.js +234 -0
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +11 -3
- package/lib/src/expression/ExpressionClient.js +120 -75
- package/lib/src/expression/ExpressionRef.js +4 -27
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +7 -2
- package/lib/src/index.js +7 -2
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +26 -176
- package/lib/src/language/Language.js +32 -72
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +150 -62
- package/lib/src/model/Ad4mModel.js +689 -417
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +59 -38
- package/lib/src/model/ModelQueryBuilder.js +317 -153
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +36 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +3 -92
- package/lib/src/model/hydration.js +3 -691
- package/lib/src/model/index.d.ts +3 -4
- package/lib/src/model/index.js +3 -4
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +51 -0
- package/lib/src/model/query-sparql.js +466 -0
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
- package/lib/src/model/query-utils.js +189 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +46 -18
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +60 -5
- package/lib/src/model/types.js +5 -2
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
- package/lib/src/perspectives/PerspectiveClient.js +189 -454
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +156 -78
- package/lib/src/perspectives/PerspectiveProxy.js +474 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
- package/lib/src/runtime/RuntimeClient.d.ts +8 -6
- package/lib/src/runtime/RuntimeClient.js +97 -454
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +84 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +14 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +8 -1
- package/lib/src/shacl/SHACLShape.js +57 -38
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -615
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1192 -1288
- package/src/Ad4mClient.ts +46 -15
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +238 -467
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +287 -0
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +148 -77
- package/src/expression/ExpressionRef.ts +2 -8
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +7 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +51 -248
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +1690 -777
- package/src/model/Ad4mModel.ts +749 -477
- package/src/model/ModelQueryBuilder.ts +356 -171
- package/src/model/decorators.ts +71 -22
- package/src/model/hydration.ts +3 -772
- package/src/model/index.ts +3 -4
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql.test.ts +376 -0
- package/src/model/query-sparql.ts +504 -0
- package/src/model/query-utils.ts +209 -0
- package/src/model/relation-filtering.test.ts +15 -15
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +47 -17
- package/src/model/types.ts +65 -5
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +262 -0
- package/src/perspectives/PerspectiveClient.ts +254 -468
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +125 -0
- package/src/perspectives/PerspectiveProxy.ts +522 -434
- package/src/perspectives/WakerSubscriptionManager.ts +13 -13
- package/src/runtime/RuntimeClient.ts +118 -461
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +66 -39
- package/src/typeDefs.ts +3 -5
- package/src/utils.ts +6 -6
- package/tsconfig.json +3 -7
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.js +0 -128
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageContext.ts +0 -37
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-surreal.ts +0 -280
- package/src/model/surreal-utils.ts +0 -147
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -372
- package/src/runtime/RuntimeResolver.ts +0 -691
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
|
@@ -19,7 +19,7 @@ export interface RelationMetadataEntry {
|
|
|
19
19
|
maxCount?: number;
|
|
20
20
|
local?: boolean;
|
|
21
21
|
/**
|
|
22
|
-
* Custom
|
|
22
|
+
* Custom getter to resolve the relation values.
|
|
23
23
|
* The expression can reference 'Base' which will be replaced with the instance's base expression.
|
|
24
24
|
*/
|
|
25
25
|
getter?: string;
|
|
@@ -39,13 +39,19 @@ export interface RelationMetadataEntry {
|
|
|
39
39
|
/**
|
|
40
40
|
* Retrieve property metadata for a given class constructor.
|
|
41
41
|
* Walks the prototype chain so subclass decorators compose with parent decorators.
|
|
42
|
+
* Results are memoised per class constructor.
|
|
42
43
|
*/
|
|
43
44
|
export declare function getPropertiesMetadata(ctor: Function): Record<string, PropertyMetadataEntry>;
|
|
44
45
|
/**
|
|
45
46
|
* Retrieve relation metadata for a given class constructor.
|
|
46
47
|
* Walks the prototype chain so subclass decorators compose with parent decorators.
|
|
48
|
+
* Results are memoised per class constructor.
|
|
47
49
|
*/
|
|
48
50
|
export declare function getRelationsMetadata(ctor: Function): Record<string, RelationMetadataEntry>;
|
|
51
|
+
/**
|
|
52
|
+
* Get or compute memoised SHACL for a class. Used by @Model decorator.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getMemoizedSHACL(target: Function, compute: () => any): any;
|
|
49
55
|
/**
|
|
50
56
|
* Programmatically register property metadata for a given constructor.
|
|
51
57
|
* Used by `fromJSONSchema()` and other dynamic model builders.
|
|
@@ -72,7 +78,7 @@ export interface Ad4mModelLike {
|
|
|
72
78
|
*
|
|
73
79
|
* Inspects the target class's property metadata to derive:
|
|
74
80
|
* - `conformanceConditions`: Structured, DB-agnostic conditions (flag & required checks)
|
|
75
|
-
* - `getter`: Pre-computed
|
|
81
|
+
* - `getter`: Pre-computed graph traversal expression that traverses outgoing links and filters
|
|
76
82
|
* target nodes to only those conforming to the target shape.
|
|
77
83
|
*
|
|
78
84
|
* @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
|
|
@@ -114,9 +120,9 @@ export interface PropertyOptions {
|
|
|
114
120
|
*/
|
|
115
121
|
prologSetter?: string;
|
|
116
122
|
/**
|
|
117
|
-
* Custom
|
|
123
|
+
* Custom getter to resolve the property value. Use this for custom graph traversals.
|
|
118
124
|
* The expression can reference 'Base' which will be replaced with the instance's base expression.
|
|
119
|
-
* Example: "
|
|
125
|
+
* Example: "SELECT ?target WHERE { <Base> <flux://has_reply> ?target . } LIMIT 1"
|
|
120
126
|
*/
|
|
121
127
|
getter?: string;
|
|
122
128
|
/**
|
|
@@ -129,6 +135,28 @@ export interface PropertyOptions {
|
|
|
129
135
|
* The function takes the raw value as input and returns the transformed value.
|
|
130
136
|
*/
|
|
131
137
|
transform?: (value: any) => any;
|
|
138
|
+
/**
|
|
139
|
+
* Allowed values for this property (enum constraint).
|
|
140
|
+
* Maps to SHACL `sh:in`. Each entry has a `value` (the stored RDF term)
|
|
141
|
+
* and an optional `label` (human-readable display name).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* @Property({
|
|
146
|
+
* through: "task://status",
|
|
147
|
+
* options: [
|
|
148
|
+
* { value: "task://todo", label: "To Do" },
|
|
149
|
+
* { value: "task://doing", label: "Doing" },
|
|
150
|
+
* { value: "task://done", label: "Done" },
|
|
151
|
+
* ]
|
|
152
|
+
* })
|
|
153
|
+
* status: string = "task://todo";
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
options?: Array<{
|
|
157
|
+
value: string;
|
|
158
|
+
label?: string;
|
|
159
|
+
}>;
|
|
132
160
|
}
|
|
133
161
|
/**
|
|
134
162
|
* Convenience decorator for defining optional (not required) properties.
|
|
@@ -294,7 +322,7 @@ export declare function Model(opts: ModelConfig): (target: any) => void;
|
|
|
294
322
|
* Properties are optional by default. When a model instance is created without
|
|
295
323
|
* providing a value for an optional property, no link is added to the graph.
|
|
296
324
|
* Set `required: true` explicitly when a property must always be present (this
|
|
297
|
-
* also adds a `"literal
|
|
325
|
+
* also adds a `"literal:string:uninitialized"` sentinel as the initial value
|
|
298
326
|
* so that the SDNA constructor creates a placeholder link).
|
|
299
327
|
*
|
|
300
328
|
* @example
|
|
@@ -333,7 +361,7 @@ export declare function Model(opts: ModelConfig): (target: any) => void;
|
|
|
333
361
|
* @param {PropertyOptions} opts - Property configuration
|
|
334
362
|
* @param {string} opts.through - The predicate URI for the property
|
|
335
363
|
* @param {boolean} [opts.required=false] - Whether the property is required (adds query filters and sentinel initial value)
|
|
336
|
-
* @param {string} [opts.initial] - Initial value (defaults to "literal
|
|
364
|
+
* @param {string} [opts.initial] - Initial value (defaults to "literal:string:uninitialized" when required)
|
|
337
365
|
* @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
|
|
338
366
|
* @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
|
|
339
367
|
* @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
|
|
@@ -410,9 +438,9 @@ export interface RelationOptions {
|
|
|
410
438
|
* Cannot be combined with `getter`. */
|
|
411
439
|
target?: () => Ad4mModelLike;
|
|
412
440
|
/**
|
|
413
|
-
* Custom
|
|
441
|
+
* Custom getter to resolve the relation values. Use this for custom graph traversals.
|
|
414
442
|
* The expression can reference 'Base' which will be replaced with the instance's base expression.
|
|
415
|
-
* Example: "
|
|
443
|
+
* Example: "SELECT ?target WHERE { ?target <flux://has_reply> <Base> . }"
|
|
416
444
|
*
|
|
417
445
|
* Mutually exclusive with `through` and `target`. When `getter` is provided the
|
|
418
446
|
* relation is read-only (no adder/remover actions are generated).
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { capitalize } from "./util";
|
|
2
2
|
import { buildSDNA } from "./sdna";
|
|
3
3
|
import { buildSHACL } from "./shacl-gen";
|
|
4
|
-
import {
|
|
4
|
+
import { escapeQueryString } from "../utils";
|
|
5
5
|
/** Registry of property metadata keyed by constructor → { propName → metadata } */
|
|
6
6
|
const propertyRegistry = new WeakMap();
|
|
7
7
|
/** Registry of relation metadata keyed by constructor → { propName → metadata } */
|
|
8
8
|
const relationRegistry = new WeakMap();
|
|
9
|
+
/** Memoisation cache for getPropertiesMetadata — avoids repeated prototype-chain walks */
|
|
10
|
+
const propertiesMetadataCache = new WeakMap();
|
|
11
|
+
/** Memoisation cache for getRelationsMetadata — avoids repeated prototype-chain walks */
|
|
12
|
+
const relationsMetadataCache = new WeakMap();
|
|
13
|
+
/** Memoisation cache for generateSHACL — avoids recomputing SHACL shapes */
|
|
14
|
+
const shaclCache = new WeakMap();
|
|
9
15
|
/**
|
|
10
16
|
* Retrieve property metadata for a given class constructor.
|
|
11
17
|
* Walks the prototype chain so subclass decorators compose with parent decorators.
|
|
18
|
+
* Results are memoised per class constructor.
|
|
12
19
|
*/
|
|
13
20
|
export function getPropertiesMetadata(ctor) {
|
|
21
|
+
const cached = propertiesMetadataCache.get(ctor);
|
|
22
|
+
if (cached)
|
|
23
|
+
return cached;
|
|
14
24
|
const result = {};
|
|
15
25
|
const chain = [];
|
|
16
26
|
let current = ctor;
|
|
@@ -23,13 +33,18 @@ export function getPropertiesMetadata(ctor) {
|
|
|
23
33
|
if (meta)
|
|
24
34
|
Object.assign(result, meta);
|
|
25
35
|
}
|
|
36
|
+
propertiesMetadataCache.set(ctor, result);
|
|
26
37
|
return result;
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
29
40
|
* Retrieve relation metadata for a given class constructor.
|
|
30
41
|
* Walks the prototype chain so subclass decorators compose with parent decorators.
|
|
42
|
+
* Results are memoised per class constructor.
|
|
31
43
|
*/
|
|
32
44
|
export function getRelationsMetadata(ctor) {
|
|
45
|
+
const cached = relationsMetadataCache.get(ctor);
|
|
46
|
+
if (cached)
|
|
47
|
+
return cached;
|
|
33
48
|
const result = {};
|
|
34
49
|
const chain = [];
|
|
35
50
|
let current = ctor;
|
|
@@ -42,6 +57,18 @@ export function getRelationsMetadata(ctor) {
|
|
|
42
57
|
if (meta)
|
|
43
58
|
Object.assign(result, meta);
|
|
44
59
|
}
|
|
60
|
+
relationsMetadataCache.set(ctor, result);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get or compute memoised SHACL for a class. Used by @Model decorator.
|
|
65
|
+
*/
|
|
66
|
+
export function getMemoizedSHACL(target, compute) {
|
|
67
|
+
const cached = shaclCache.get(target);
|
|
68
|
+
if (cached)
|
|
69
|
+
return cached;
|
|
70
|
+
const result = compute();
|
|
71
|
+
shaclCache.set(target, result);
|
|
45
72
|
return result;
|
|
46
73
|
}
|
|
47
74
|
/**
|
|
@@ -67,7 +94,7 @@ export function setRelationRegistryEntry(ctor, relName, meta) {
|
|
|
67
94
|
*
|
|
68
95
|
* Inspects the target class's property metadata to derive:
|
|
69
96
|
* - `conformanceConditions`: Structured, DB-agnostic conditions (flag & required checks)
|
|
70
|
-
* - `getter`: Pre-computed
|
|
97
|
+
* - `getter`: Pre-computed graph traversal expression that traverses outgoing links and filters
|
|
71
98
|
* target nodes to only those conforming to the target shape.
|
|
72
99
|
*
|
|
73
100
|
* @param relationPredicate - The relation's predicate URI (e.g. "flux://entry_type")
|
|
@@ -78,7 +105,8 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
|
|
|
78
105
|
try {
|
|
79
106
|
const targetProps = getPropertiesMetadata(targetClass);
|
|
80
107
|
const conditions = [];
|
|
81
|
-
const
|
|
108
|
+
const sparqlConditions = [];
|
|
109
|
+
let varIdx = 0;
|
|
82
110
|
// 1. Flags — check predicate + value
|
|
83
111
|
for (const [_propName, propMeta] of Object.entries(targetProps)) {
|
|
84
112
|
if (propMeta.flag && propMeta.initial && propMeta.through) {
|
|
@@ -87,7 +115,7 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
|
|
|
87
115
|
predicate: propMeta.through,
|
|
88
116
|
value: propMeta.initial,
|
|
89
117
|
});
|
|
90
|
-
|
|
118
|
+
sparqlConditions.push(`?target <${escapeQueryString(propMeta.through)}> <${escapeQueryString(propMeta.initial)}> .`);
|
|
91
119
|
}
|
|
92
120
|
}
|
|
93
121
|
// 2. Required (non-flag) properties — check predicate exists
|
|
@@ -98,14 +126,13 @@ export function buildConformanceFilter(relationPredicate, targetClass) {
|
|
|
98
126
|
type: 'required',
|
|
99
127
|
predicate: propMeta.through,
|
|
100
128
|
});
|
|
101
|
-
|
|
129
|
+
sparqlConditions.push(`?target <${escapeQueryString(propMeta.through)}> ?_v${varIdx++} .`);
|
|
102
130
|
}
|
|
103
131
|
}
|
|
104
132
|
if (conditions.length === 0) {
|
|
105
133
|
return undefined;
|
|
106
134
|
}
|
|
107
|
-
const
|
|
108
|
-
const getter = `(->link[WHERE predicate = '${escapedPredicate}'].out[WHERE ${surrealConditions.join(' AND ')}].uri)`;
|
|
135
|
+
const getter = `SELECT ?target WHERE { <Base> <${escapeQueryString(relationPredicate)}> ?target . ${sparqlConditions.join(' ')} }`;
|
|
109
136
|
return { getter, conformanceConditions: conditions };
|
|
110
137
|
}
|
|
111
138
|
catch (e) {
|
|
@@ -126,8 +153,8 @@ function applyPropertyMetadata(opts) {
|
|
|
126
153
|
if (opts.required && !opts.initial) {
|
|
127
154
|
throw new Error("SubjectProperty requires an 'initial' option if 'required' is true");
|
|
128
155
|
}
|
|
129
|
-
if (!opts.through && !opts.prologGetter) {
|
|
130
|
-
throw new Error("SubjectProperty requires either 'through' or 'prologGetter' option");
|
|
156
|
+
if (!opts.through && !opts.prologGetter && !opts.getter) {
|
|
157
|
+
throw new Error("SubjectProperty requires either 'through' or 'prologGetter' or 'getter' option");
|
|
131
158
|
}
|
|
132
159
|
// Write to WeakMap registry (keyed by constructor)
|
|
133
160
|
const ctor = target.constructor;
|
|
@@ -312,7 +339,7 @@ export function Model(opts) {
|
|
|
312
339
|
return buildSDNA(opts.name, target.prototype, getPropertiesMetadata(target), getRelationsMetadata(target));
|
|
313
340
|
};
|
|
314
341
|
target.generateSHACL = function () {
|
|
315
|
-
return buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter);
|
|
342
|
+
return getMemoizedSHACL(target, () => buildSHACL(opts.name, target, getPropertiesMetadata(target), getRelationsMetadata(target), buildConformanceFilter));
|
|
316
343
|
};
|
|
317
344
|
Object.defineProperty(target, 'type', { configurable: true });
|
|
318
345
|
};
|
|
@@ -335,7 +362,7 @@ export function Model(opts) {
|
|
|
335
362
|
* Properties are optional by default. When a model instance is created without
|
|
336
363
|
* providing a value for an optional property, no link is added to the graph.
|
|
337
364
|
* Set `required: true` explicitly when a property must always be present (this
|
|
338
|
-
* also adds a `"literal
|
|
365
|
+
* also adds a `"literal:string:uninitialized"` sentinel as the initial value
|
|
339
366
|
* so that the SDNA constructor creates a placeholder link).
|
|
340
367
|
*
|
|
341
368
|
* @example
|
|
@@ -374,7 +401,7 @@ export function Model(opts) {
|
|
|
374
401
|
* @param {PropertyOptions} opts - Property configuration
|
|
375
402
|
* @param {string} opts.through - The predicate URI for the property
|
|
376
403
|
* @param {boolean} [opts.required=false] - Whether the property is required (adds query filters and sentinel initial value)
|
|
377
|
-
* @param {string} [opts.initial] - Initial value (defaults to "literal
|
|
404
|
+
* @param {string} [opts.initial] - Initial value (defaults to "literal:string:uninitialized" when required)
|
|
378
405
|
* @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
|
|
379
406
|
* @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
|
|
380
407
|
* @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
|
|
@@ -387,7 +414,7 @@ export function Property(opts) {
|
|
|
387
414
|
required,
|
|
388
415
|
readOnly: opts.readOnly ?? false,
|
|
389
416
|
resolveLanguage: opts.resolveLanguage ?? "literal",
|
|
390
|
-
initial: opts.initial ?? (required ? "literal
|
|
417
|
+
initial: opts.initial ?? (required ? "literal:string:uninitialized" : undefined),
|
|
391
418
|
});
|
|
392
419
|
}
|
|
393
420
|
/**
|
|
@@ -476,7 +503,7 @@ function resolveRelationArgs(first, second) {
|
|
|
476
503
|
}
|
|
477
504
|
if (opts.where) {
|
|
478
505
|
throw new Error('Relation decorator: `where` and `getter` are mutually exclusive. ' +
|
|
479
|
-
'Use `where` for DSL-based filtering, or `getter` for raw
|
|
506
|
+
'Use `where` for DSL-based filtering, or `getter` for raw getter expression.');
|
|
480
507
|
}
|
|
481
508
|
return opts;
|
|
482
509
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch hydration for SPARQL batch query results.
|
|
3
|
+
*
|
|
4
|
+
* Takes the flat rows returned by `buildBatchSPARQLQuery()` (each tagged
|
|
5
|
+
* with ?depth, ?parentBase, ?relationName) and reconstructs a tree of
|
|
6
|
+
* model instances.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { IncludeMap } from "./types";
|
|
11
|
+
/**
|
|
12
|
+
* A row returned by the batch SPARQL query.
|
|
13
|
+
*/
|
|
14
|
+
interface BatchRow {
|
|
15
|
+
depth: string;
|
|
16
|
+
parentBase: string;
|
|
17
|
+
relationName: string;
|
|
18
|
+
source: string;
|
|
19
|
+
predicate: string;
|
|
20
|
+
target: string;
|
|
21
|
+
author: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Hydrate batch SPARQL results into a tree of model instances.
|
|
26
|
+
*
|
|
27
|
+
* @param rows - Flat rows from the batch SPARQL query
|
|
28
|
+
* @param rootClass - The root model class (extends Ad4mModel)
|
|
29
|
+
* @param includeMap - The include specification from the query
|
|
30
|
+
* @param perspective - The PerspectiveProxy for creating instances
|
|
31
|
+
* @returns Array of hydrated root instances with relations populated
|
|
32
|
+
*/
|
|
33
|
+
export declare function hydrateBatchResult<T>(rows: BatchRow[], rootClass: any, includeMap: IncludeMap, perspective: any): Promise<T[]>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch hydration for SPARQL batch query results.
|
|
3
|
+
*
|
|
4
|
+
* Takes the flat rows returned by `buildBatchSPARQLQuery()` (each tagged
|
|
5
|
+
* with ?depth, ?parentBase, ?relationName) and reconstructs a tree of
|
|
6
|
+
* model instances.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { hydrateFromLinks, evaluateCustomGettersForInstance } from "./hydration";
|
|
11
|
+
import { getRelationsMetadata } from "./decorators";
|
|
12
|
+
/**
|
|
13
|
+
* Group batch rows by (depth, source) → array of links, preserving parentBase/relationName.
|
|
14
|
+
*/
|
|
15
|
+
function groupBatchRows(rows) {
|
|
16
|
+
const byDepth = new Map();
|
|
17
|
+
for (const row of rows) {
|
|
18
|
+
const depth = parseInt(row.depth, 10);
|
|
19
|
+
if (!byDepth.has(depth))
|
|
20
|
+
byDepth.set(depth, new Map());
|
|
21
|
+
const depthMap = byDepth.get(depth);
|
|
22
|
+
const key = row.source;
|
|
23
|
+
if (!depthMap.has(key)) {
|
|
24
|
+
depthMap.set(key, {
|
|
25
|
+
source_uri: key,
|
|
26
|
+
parentBase: row.parentBase,
|
|
27
|
+
relationName: row.relationName,
|
|
28
|
+
links: [],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
depthMap.get(key).links.push({
|
|
32
|
+
predicate: row.predicate,
|
|
33
|
+
target: row.target,
|
|
34
|
+
author: row.author,
|
|
35
|
+
timestamp: row.timestamp,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const result = new Map();
|
|
39
|
+
for (const [depth, map] of byDepth) {
|
|
40
|
+
result.set(depth, Array.from(map.values()));
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hydrate batch SPARQL results into a tree of model instances.
|
|
46
|
+
*
|
|
47
|
+
* @param rows - Flat rows from the batch SPARQL query
|
|
48
|
+
* @param rootClass - The root model class (extends Ad4mModel)
|
|
49
|
+
* @param includeMap - The include specification from the query
|
|
50
|
+
* @param perspective - The PerspectiveProxy for creating instances
|
|
51
|
+
* @returns Array of hydrated root instances with relations populated
|
|
52
|
+
*/
|
|
53
|
+
export async function hydrateBatchResult(rows, rootClass, includeMap, perspective) {
|
|
54
|
+
if (!rows || rows.length === 0)
|
|
55
|
+
return [];
|
|
56
|
+
const grouped = groupBatchRows(rows);
|
|
57
|
+
// Hydrate root instances (depth 0)
|
|
58
|
+
const rootInstances = grouped.get(0) || [];
|
|
59
|
+
const metadata = rootClass.getModelMetadata();
|
|
60
|
+
const instances = [];
|
|
61
|
+
const instanceMap = new Map();
|
|
62
|
+
for (const group of rootInstances) {
|
|
63
|
+
const instance = new rootClass(perspective, group.source_uri);
|
|
64
|
+
await hydrateFromLinks(instance, group.links, metadata, perspective);
|
|
65
|
+
await evaluateCustomGettersForInstance(instance, perspective, metadata);
|
|
66
|
+
instances.push(instance);
|
|
67
|
+
instanceMap.set(group.source_uri, instance);
|
|
68
|
+
}
|
|
69
|
+
// Hydrate each depth level and wire to parents
|
|
70
|
+
const relMeta = getRelationsMetadata(rootClass);
|
|
71
|
+
const maxDepth = Math.max(...Array.from(grouped.keys()), 0);
|
|
72
|
+
// Build a map of depth → (class, relMetadata, parentInstanceMap)
|
|
73
|
+
// For depth 1, parents are root instances; for deeper depths, we need
|
|
74
|
+
// the instances from the previous level.
|
|
75
|
+
const depthInstanceMaps = new Map();
|
|
76
|
+
depthInstanceMaps.set(0, instanceMap);
|
|
77
|
+
// Build depth→class mapping from include tree
|
|
78
|
+
const depthClassMap = new Map();
|
|
79
|
+
buildDepthClassMap(rootClass, includeMap, 0, { value: 1 }, depthClassMap);
|
|
80
|
+
for (let depth = 1; depth <= maxDepth; depth++) {
|
|
81
|
+
const depthGroups = grouped.get(depth) || [];
|
|
82
|
+
if (depthGroups.length === 0)
|
|
83
|
+
continue;
|
|
84
|
+
const depthInfo = depthClassMap.get(depth);
|
|
85
|
+
if (!depthInfo)
|
|
86
|
+
continue;
|
|
87
|
+
const TargetClass = depthInfo.targetClass;
|
|
88
|
+
const targetMetadata = TargetClass.getModelMetadata
|
|
89
|
+
? TargetClass.getModelMetadata()
|
|
90
|
+
: { className: "Unknown", properties: {}, relations: {} };
|
|
91
|
+
const currentDepthInstances = new Map();
|
|
92
|
+
// Group by parentBase to wire children to parents
|
|
93
|
+
for (const group of depthGroups) {
|
|
94
|
+
const instance = new TargetClass(perspective, group.source_uri);
|
|
95
|
+
await hydrateFromLinks(instance, group.links, targetMetadata, perspective);
|
|
96
|
+
await evaluateCustomGettersForInstance(instance, perspective, targetMetadata);
|
|
97
|
+
currentDepthInstances.set(group.source_uri, instance);
|
|
98
|
+
// Wire to parent
|
|
99
|
+
// Find the parent depth's instance map
|
|
100
|
+
// The parentBase should exist in one of the prior depth maps
|
|
101
|
+
for (let pd = depth - 1; pd >= 0; pd--) {
|
|
102
|
+
const parentMap = depthInstanceMaps.get(pd);
|
|
103
|
+
if (parentMap && parentMap.has(group.parentBase)) {
|
|
104
|
+
const parent = parentMap.get(group.parentBase);
|
|
105
|
+
const relName = group.relationName;
|
|
106
|
+
// Determine relation metadata to know if it's an array or single
|
|
107
|
+
const parentRelMeta = getRelationsMetadata(pd === 0 ? rootClass : (depthClassMap.get(pd)?.targetClass || rootClass));
|
|
108
|
+
const rel = parentRelMeta[relName];
|
|
109
|
+
if (rel) {
|
|
110
|
+
if (rel.kind === 'hasMany' || rel.kind === 'belongsToMany') {
|
|
111
|
+
if (!Array.isArray(parent[relName])) {
|
|
112
|
+
parent[relName] = [];
|
|
113
|
+
}
|
|
114
|
+
parent[relName].push(instance);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
parent[relName] = instance;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
depthInstanceMaps.set(depth, currentDepthInstances);
|
|
125
|
+
}
|
|
126
|
+
return instances;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build a mapping from depth number to target class info.
|
|
130
|
+
*/
|
|
131
|
+
function buildDepthClassMap(parentClass, includeMap, _parentDepth, nextDepth, result) {
|
|
132
|
+
const relMeta = getRelationsMetadata(parentClass);
|
|
133
|
+
for (const [relName, includeValue] of Object.entries(includeMap)) {
|
|
134
|
+
const meta = relMeta[relName];
|
|
135
|
+
if (!meta || !meta.target)
|
|
136
|
+
continue;
|
|
137
|
+
const TargetClass = meta.target();
|
|
138
|
+
const depth = nextDepth.value++;
|
|
139
|
+
const nestedInclude = typeof includeValue === 'object' && includeValue !== null
|
|
140
|
+
? includeValue.include
|
|
141
|
+
: undefined;
|
|
142
|
+
result.set(depth, { targetClass: TargetClass, includeMap: nestedInclude });
|
|
143
|
+
if (nestedInclude) {
|
|
144
|
+
buildDepthClassMap(TargetClass, nestedInclude, depth, nextDepth, result);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for batched hydrateRelations() — verifies the N+1 → 1 SPARQL optimisation.
|
|
3
|
+
*
|
|
4
|
+
* We mock PerspectiveProxy to count querySparql / get calls and verify
|
|
5
|
+
* that the batched path issues 1 SPARQL query instead of N perspective.get() calls.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|