@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-4
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 +2406 -11070
- package/lib/index.js +2209 -10925
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- 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 +52 -0
- package/lib/src/apiClient.js +231 -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 +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- 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 +6 -1
- package/lib/src/index.js +6 -1
- 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 +1 -1
- package/lib/src/language/Language.js +10 -76
- 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 +57 -38
- package/lib/src/model/Ad4mModel.js +594 -460
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
- package/lib/src/model/ModelQueryBuilder.js +138 -217
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +7 -60
- package/lib/src/model/hydration.js +7 -716
- package/lib/src/model/index.d.ts +0 -4
- package/lib/src/model/index.js +0 -4
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.d.ts +4 -67
- package/lib/src/model/query-sparql.js +26 -322
- package/lib/src/model/query-sparql.test.js +35 -218
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +47 -38
- package/lib/src/model/types.js +4 -1
- 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 +12 -17
- package/lib/src/perspectives/PerspectiveClient.js +169 -429
- package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +92 -71
- package/lib/src/perspectives/PerspectiveProxy.js +273 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- 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 +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- 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 +6 -1
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +2 -23
- 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 +708 -876
- package/src/model/Ad4mModel.ts +613 -508
- package/src/model/ModelQueryBuilder.ts +178 -244
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +9 -766
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +34 -242
- package/src/model/query-sparql.ts +27 -337
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +51 -39
- 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 +206 -148
- package/src/perspectives/PerspectiveClient.ts +228 -442
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +41 -0
- package/src/perspectives/PerspectiveProxy.ts +307 -348
- package/src/runtime/RuntimeClient.ts +112 -474
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +27 -0
- package/src/typeDefs.ts +3 -5
- package/tsconfig.json +3 -7
- 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/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/hydration-batching.test.ts +0 -563
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-sparql-batch.ts +0 -301
- package/src/model/subscription-delta.test.ts +0 -207
- package/src/model/subscription-pool.ts +0 -211
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -364
- package/src/runtime/RuntimeResolver.ts +0 -749
- package/src/unwrapApolloResult.ts +0 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildSPARQLOrderLimitOffset, buildSPARQLQuery,
|
|
1
|
+
import { buildSPARQLOrderLimitOffset, buildSPARQLQuery, hasJsOnlyWhereFilters } from './query-sparql';
|
|
2
2
|
// Minimal stubs for ModelMetadata — buildSPARQLOrderLimitOffset only uses the query arg
|
|
3
3
|
const emptyMetadata = { properties: {}, relations: {} };
|
|
4
4
|
// Metadata with a required (non-literal) property and a literal-stored property
|
|
@@ -41,10 +41,10 @@ describe('hasJsOnlyWhereFilters', () => {
|
|
|
41
41
|
it('returns false when where only has non-literal property filter', () => {
|
|
42
42
|
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { category: 'some://uri' })).toBe(false);
|
|
43
43
|
});
|
|
44
|
-
it('returns true when where has author filter
|
|
44
|
+
it('returns true when where has author filter', () => {
|
|
45
45
|
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { author: 'did:key:abc' })).toBe(true);
|
|
46
46
|
});
|
|
47
|
-
it('returns true when where has timestamp filter
|
|
47
|
+
it('returns true when where has timestamp filter', () => {
|
|
48
48
|
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { timestamp: { gt: 100 } })).toBe(true);
|
|
49
49
|
});
|
|
50
50
|
it('returns true for belongsToOne reverse relation', () => {
|
|
@@ -55,8 +55,8 @@ describe('hasJsOnlyWhereFilters', () => {
|
|
|
55
55
|
});
|
|
56
56
|
describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
|
|
57
57
|
const modelClass = {};
|
|
58
|
-
it('includes LIMIT/OFFSET in a pagination subquery when query has them
|
|
59
|
-
const query = { limit: 10, offset: 0, where: { category: 'some://uri' }
|
|
58
|
+
it('includes LIMIT/OFFSET in a pagination subquery when query has them and no JS-only filters', () => {
|
|
59
|
+
const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
|
|
60
60
|
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
61
61
|
// SPARQL should contain LIMIT inside the pagination subquery
|
|
62
62
|
expect(sparql).toContain('LIMIT 10');
|
|
@@ -65,20 +65,10 @@ describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
|
|
|
65
65
|
// Should have a subquery pattern
|
|
66
66
|
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
67
67
|
});
|
|
68
|
-
it('does NOT
|
|
69
|
-
|
|
68
|
+
it('does NOT include LIMIT/OFFSET when JS-only where filters exist', () => {
|
|
69
|
+
// author is a JS-only filter
|
|
70
|
+
const query = { limit: 10, offset: 0, where: { author: 'did:key:abc' } };
|
|
70
71
|
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
71
|
-
// Without ORDER BY, SPARQL pagination is not used — JS-level slicing handles it
|
|
72
|
-
expect(sparql).not.toContain('LIMIT');
|
|
73
|
-
expect(sparql).not.toContain('OFFSET');
|
|
74
|
-
// No subquery needed
|
|
75
|
-
expect(sparql).not.toContain('SELECT DISTINCT');
|
|
76
|
-
});
|
|
77
|
-
it('does NOT include LIMIT/OFFSET when JS-only where filters exist (literal gt operator)', () => {
|
|
78
|
-
// gt on a literal-stored property is JS-only, so pagination must not be pushed to SPARQL
|
|
79
|
-
const meta = { properties: { rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' } }, relations: {} };
|
|
80
|
-
const query = { limit: 10, offset: 0, where: { rating: { gt: 3 } } };
|
|
81
|
-
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
82
72
|
expect(sparql).not.toContain('LIMIT');
|
|
83
73
|
expect(sparql).not.toContain('OFFSET');
|
|
84
74
|
});
|
|
@@ -141,7 +131,6 @@ describe('buildSPARQLQuery — structural correctness', () => {
|
|
|
141
131
|
offset: 0,
|
|
142
132
|
parent: { id: 'flux://channel-123', predicate: 'flux://has_message' },
|
|
143
133
|
where: { category: 'some://uri' },
|
|
144
|
-
order: { name: 'ASC' },
|
|
145
134
|
};
|
|
146
135
|
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
147
136
|
expect(sparql).toContain('<flux://channel-123>');
|
|
@@ -227,28 +216,21 @@ describe('buildSPARQLQuery — IRI correctness', () => {
|
|
|
227
216
|
// ──────────────────────────────────────────────────────────
|
|
228
217
|
describe('SPARQL-level pagination', () => {
|
|
229
218
|
const modelClass = {};
|
|
230
|
-
it('includes LIMIT in SPARQL when query specifies limit
|
|
231
|
-
const query = { limit: 30
|
|
232
|
-
const sparql = buildSPARQLQuery(
|
|
219
|
+
it('includes LIMIT in SPARQL when query specifies limit', () => {
|
|
220
|
+
const query = { limit: 30 };
|
|
221
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
233
222
|
expect(sparql).toContain('LIMIT 30');
|
|
234
223
|
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
235
224
|
});
|
|
236
|
-
it('
|
|
237
|
-
const query = { limit:
|
|
225
|
+
it('includes OFFSET in SPARQL when query specifies offset > 0', () => {
|
|
226
|
+
const query = { limit: 20, offset: 40 };
|
|
238
227
|
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
239
|
-
// Without ORDER BY, SPARQL-level pagination is not used
|
|
240
|
-
expect(sparql).not.toContain('LIMIT');
|
|
241
|
-
expect(sparql).not.toContain('SELECT DISTINCT');
|
|
242
|
-
});
|
|
243
|
-
it('includes OFFSET in SPARQL when query specifies offset > 0 with order', () => {
|
|
244
|
-
const query = { limit: 20, offset: 40, order: { name: 'ASC' } };
|
|
245
|
-
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
246
228
|
expect(sparql).toContain('LIMIT 20');
|
|
247
229
|
expect(sparql).toContain('OFFSET 40');
|
|
248
230
|
});
|
|
249
231
|
it('does NOT include OFFSET when offset is 0', () => {
|
|
250
|
-
const query = { limit: 10, offset: 0
|
|
251
|
-
const sparql = buildSPARQLQuery(
|
|
232
|
+
const query = { limit: 10, offset: 0 };
|
|
233
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
252
234
|
expect(sparql).toContain('LIMIT 10');
|
|
253
235
|
expect(sparql).not.toContain('OFFSET');
|
|
254
236
|
});
|
|
@@ -258,38 +240,15 @@ describe('SPARQL-level pagination', () => {
|
|
|
258
240
|
expect(sparql).toContain('ORDER BY DESC(');
|
|
259
241
|
expect(sparql).toContain('LIMIT 10');
|
|
260
242
|
});
|
|
261
|
-
it('uses SAMPLE() aggregate for ORDER BY variables in pagination subquery (SPARQL 1.1 compliance)', () => {
|
|
262
|
-
const query = { limit: 5, order: { name: 'ASC' } };
|
|
263
|
-
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
264
|
-
// Must use SAMPLE() to aggregate the order variable under GROUP BY
|
|
265
|
-
expect(sparql).toMatch(/SAMPLE\(/);
|
|
266
|
-
expect(sparql).toMatch(/AS \?pg_sort_0/);
|
|
267
|
-
expect(sparql).toContain('GROUP BY ?source');
|
|
268
|
-
expect(sparql).toContain('ORDER BY ASC(?pg_sort_0)');
|
|
269
|
-
});
|
|
270
|
-
it('omits GROUP BY when ORDER BY is present (uses SAMPLE() aggregate instead)', () => {
|
|
271
|
-
// When ORDER BY is present, GROUP BY ?source is used with SAMPLE() aggregates.
|
|
272
|
-
// The old redundant GROUP BY (without ORDER BY) no longer applies because
|
|
273
|
-
// SPARQL-level pagination is only used when ORDER BY is present.
|
|
274
|
-
const query = { limit: 10, order: { name: 'ASC' } };
|
|
275
|
-
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
276
|
-
expect(sparql).toContain('GROUP BY ?source');
|
|
277
|
-
expect(sparql).toContain('SAMPLE(');
|
|
278
|
-
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
279
|
-
expect(sparql).toContain('LIMIT 10');
|
|
280
|
-
});
|
|
281
243
|
it('does NOT default to ORDER BY timestamp when paginating without explicit order', () => {
|
|
282
244
|
const query = { limit: 30 };
|
|
283
245
|
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
284
246
|
expect(sparql).not.toContain('ORDER BY');
|
|
285
247
|
expect(sparql).not.toContain('pg_minTs');
|
|
286
|
-
expect(sparql).not.toContain('GRAPH ?pg_g');
|
|
287
248
|
});
|
|
288
|
-
it('does NOT push pagination to SPARQL when JS-only where filters exist (
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
const query = { limit: 10, where: { rating: { gt: 5 } } };
|
|
292
|
-
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
249
|
+
it('does NOT push pagination to SPARQL when JS-only where filters exist (author)', () => {
|
|
250
|
+
const query = { limit: 10, where: { author: 'did:key:abc' } };
|
|
251
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
293
252
|
expect(sparql).not.toContain('LIMIT');
|
|
294
253
|
expect(sparql).not.toContain('OFFSET');
|
|
295
254
|
});
|
|
@@ -305,38 +264,13 @@ describe('SPARQL-level pagination', () => {
|
|
|
305
264
|
expect(sparql).not.toContain('LIMIT');
|
|
306
265
|
});
|
|
307
266
|
it('wraps pagination in a subquery (outer SELECT fetches all links for the page)', () => {
|
|
308
|
-
const query = { limit: 5, offset: 10
|
|
309
|
-
const sparql = buildSPARQLQuery(
|
|
267
|
+
const query = { limit: 5, offset: 10 };
|
|
268
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
310
269
|
expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
|
|
311
270
|
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
312
271
|
expect(sparql).toContain('LIMIT 5');
|
|
313
272
|
expect(sparql).toContain('OFFSET 10');
|
|
314
273
|
});
|
|
315
|
-
it('does NOT wrap pagination in a subquery when no ORDER BY (JS slicing preserves natural order)', () => {
|
|
316
|
-
const query = { limit: 5, offset: 10 };
|
|
317
|
-
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
318
|
-
// Should be a plain SELECT without subquery
|
|
319
|
-
expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
|
|
320
|
-
expect(sparql).not.toContain('SELECT DISTINCT');
|
|
321
|
-
expect(sparql).not.toContain('LIMIT');
|
|
322
|
-
expect(sparql).not.toContain('OFFSET');
|
|
323
|
-
});
|
|
324
|
-
describe('buildSPARQLCountQuery', () => {
|
|
325
|
-
it('returns a COUNT(DISTINCT ?source) query', () => {
|
|
326
|
-
const query = { parent: { id: 'flux://ch-1', predicate: 'flux://has_child' } };
|
|
327
|
-
const countSparql = buildSPARQLCountQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
328
|
-
expect(countSparql).toContain('COUNT(DISTINCT ?source)');
|
|
329
|
-
expect(countSparql).toContain('?count');
|
|
330
|
-
expect(countSparql).toContain('<flux://ch-1>');
|
|
331
|
-
});
|
|
332
|
-
it('does NOT include LIMIT/OFFSET (counts full result set)', () => {
|
|
333
|
-
const query = { limit: 10, offset: 20, parent: { id: 'flux://ch-1', predicate: 'flux://has_child' } };
|
|
334
|
-
const countSparql = buildSPARQLCountQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
335
|
-
expect(countSparql).not.toContain('LIMIT');
|
|
336
|
-
expect(countSparql).not.toContain('OFFSET');
|
|
337
|
-
expect(countSparql).toContain('COUNT(DISTINCT ?source)');
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
274
|
});
|
|
341
275
|
describe('buildSPARQLQuery — set-difference patterns', () => {
|
|
342
276
|
const modelClass = {};
|
|
@@ -358,138 +292,21 @@ describe('buildSPARQLQuery — set-difference patterns', () => {
|
|
|
358
292
|
expect(sparql).toContain('SELECT ?source ?predicate ?target');
|
|
359
293
|
});
|
|
360
294
|
});
|
|
361
|
-
|
|
362
|
-
// buildSPARQLWhereFilters — author / timestamp SPARQL push
|
|
363
|
-
// ─────────────────────────────────────────────────────────────
|
|
364
|
-
describe('buildSPARQLQuery — author/timestamp SPARQL filter push', () => {
|
|
295
|
+
describe('buildSPARQLQuery — RDF 1.2 reifier patterns', () => {
|
|
365
296
|
const modelClass = {};
|
|
366
|
-
it('
|
|
367
|
-
const query = {
|
|
368
|
-
const sparql = buildSPARQLQuery(
|
|
369
|
-
expect(sparql).toContain('
|
|
370
|
-
expect(sparql).toContain('
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const query = { where: { author: { not: 'did:key:zABC' } } };
|
|
381
|
-
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
382
|
-
expect(sparql).toContain('STR(?author) != "did:key:zABC"');
|
|
383
|
-
});
|
|
384
|
-
it('pushes timestamp gt/lt into SPARQL FILTER', () => {
|
|
385
|
-
const query = { where: { timestamp: { gt: 1000, lt: 9000 } } };
|
|
386
|
-
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
387
|
-
expect(sparql).toContain('?timestamp > 1000');
|
|
388
|
-
expect(sparql).toContain('?timestamp < 9000');
|
|
389
|
-
});
|
|
390
|
-
it('pushes timestamp between into SPARQL FILTER', () => {
|
|
391
|
-
const query = { where: { timestamp: { between: [100, 200] } } };
|
|
392
|
-
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
393
|
-
expect(sparql).toContain('?timestamp >= 100');
|
|
394
|
-
expect(sparql).toContain('?timestamp <= 200');
|
|
395
|
-
});
|
|
396
|
-
it('pushes timestamp equality into SPARQL FILTER', () => {
|
|
397
|
-
const query = { where: { timestamp: 1714000000000 } };
|
|
398
|
-
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
399
|
-
expect(sparql).toContain('?timestamp = 1714000000000');
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
// ─────────────────────────────────────────────────────────────
|
|
403
|
-
// buildSPARQLGroupedCountQuery
|
|
404
|
-
// ─────────────────────────────────────────────────────────────
|
|
405
|
-
describe('buildSPARQLGroupedCountQuery', () => {
|
|
406
|
-
const signalMetadata = {
|
|
407
|
-
properties: {
|
|
408
|
-
signalTypeId: {
|
|
409
|
-
name: 'signalTypeId',
|
|
410
|
-
predicate: 'flux://signalTypeId',
|
|
411
|
-
required: true,
|
|
412
|
-
resolveLanguage: 'literal',
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
relations: {},
|
|
416
|
-
};
|
|
417
|
-
it('selects ?parent and COUNT(DISTINCT ?source)', () => {
|
|
418
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
|
|
419
|
-
expect(sparql).toContain('SELECT ?parent (COUNT(DISTINCT ?source) AS ?count)');
|
|
420
|
-
});
|
|
421
|
-
it('groups by ?parent', () => {
|
|
422
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
|
|
423
|
-
expect(sparql).toContain('GROUP BY ?parent');
|
|
424
|
-
});
|
|
425
|
-
it('includes parent → child join with the supplied predicate', () => {
|
|
426
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1', 'flux://post/2'], undefined);
|
|
427
|
-
expect(sparql).toContain('?parent <flux://has-signal> ?source');
|
|
428
|
-
});
|
|
429
|
-
it('includes FILTER(?parent IN (...)) for the supplied parent IDs', () => {
|
|
430
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1', 'flux://post/2'], undefined);
|
|
431
|
-
expect(sparql).toContain('?parent IN (<flux://post/1>, <flux://post/2>)');
|
|
432
|
-
});
|
|
433
|
-
it('includes the full named graph block (GRAPH ?linkGraph + author + timestamp)', () => {
|
|
434
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
|
|
435
|
-
expect(sparql).toContain('GRAPH ?linkGraph');
|
|
436
|
-
expect(sparql).toContain('?linkGraph <ad4m://ontology/author> ?author');
|
|
437
|
-
expect(sparql).toContain('?linkGraph <ad4m://ontology/timestamp> ?timestamp');
|
|
438
|
-
});
|
|
439
|
-
it('includes conformance join for required properties', () => {
|
|
440
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], undefined);
|
|
441
|
-
expect(sparql).toContain('<flux://signalTypeId>');
|
|
442
|
-
});
|
|
443
|
-
it('applies a where clause filter (author equality) via SPARQL FILTER', () => {
|
|
444
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], { author: 'did:key:zABC' });
|
|
445
|
-
expect(sparql).toContain('STR(?author) = "did:key:zABC"');
|
|
446
|
-
});
|
|
447
|
-
it('applies a where clause filter (required property equality) via parse_literal', () => {
|
|
448
|
-
const sparql = buildSPARQLGroupedCountQuery(signalMetadata, emptyRelations, 'flux://has-signal', ['flux://post/1'], { signalTypeId: 'like' });
|
|
449
|
-
expect(sparql).toContain('parse_literal');
|
|
450
|
-
expect(sparql).toContain('"like"');
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
// ─────────────────────────────────────────────────────────────
|
|
454
|
-
// parseSparqlGroupedCount
|
|
455
|
-
// ─────────────────────────────────────────────────────────────
|
|
456
|
-
describe('parseSparqlGroupedCount', () => {
|
|
457
|
-
it('returns an empty map for empty input', () => {
|
|
458
|
-
expect(parseSparqlGroupedCount([]).size).toBe(0);
|
|
459
|
-
});
|
|
460
|
-
it('returns an empty map for non-array input', () => {
|
|
461
|
-
expect(parseSparqlGroupedCount(null).size).toBe(0);
|
|
462
|
-
});
|
|
463
|
-
it('parses RDF binding objects ({ parent: { value: ... }, count: { value: ... } })', () => {
|
|
464
|
-
const rows = [
|
|
465
|
-
{ parent: { value: 'flux://post/1' }, count: { value: '3' } },
|
|
466
|
-
{ parent: { value: 'flux://post/2' }, count: { value: '0' } },
|
|
467
|
-
];
|
|
468
|
-
const map = parseSparqlGroupedCount(rows);
|
|
469
|
-
expect(map.get('flux://post/1')).toBe(3);
|
|
470
|
-
expect(map.get('flux://post/2')).toBe(0);
|
|
471
|
-
});
|
|
472
|
-
it('parses plain string/number values (non-RDF binding format)', () => {
|
|
473
|
-
const rows = [
|
|
474
|
-
{ parent: 'flux://post/1', count: 5 },
|
|
475
|
-
{ parent: 'flux://post/2', count: '2' },
|
|
476
|
-
];
|
|
477
|
-
const map = parseSparqlGroupedCount(rows);
|
|
478
|
-
expect(map.get('flux://post/1')).toBe(5);
|
|
479
|
-
expect(map.get('flux://post/2')).toBe(2);
|
|
480
|
-
});
|
|
481
|
-
it('skips rows with missing parent or count', () => {
|
|
482
|
-
const rows = [
|
|
483
|
-
{ parent: { value: 'flux://post/1' } },
|
|
484
|
-
{ count: { value: '3' } },
|
|
485
|
-
{ parent: { value: 'flux://post/3' }, count: { value: '1' } },
|
|
486
|
-
];
|
|
487
|
-
const map = parseSparqlGroupedCount(rows);
|
|
488
|
-
expect(map.size).toBe(1);
|
|
489
|
-
expect(map.get('flux://post/3')).toBe(1);
|
|
490
|
-
});
|
|
491
|
-
it('skips rows with NaN count', () => {
|
|
492
|
-
const rows = [{ parent: { value: 'flux://post/1' }, count: { value: 'not-a-number' } }];
|
|
493
|
-
expect(parseSparqlGroupedCount(rows).size).toBe(0);
|
|
297
|
+
it('uses rdf:reifies instead of GRAPH for link metadata', () => {
|
|
298
|
+
const query = { limit: 10 };
|
|
299
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
300
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>');
|
|
301
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(');
|
|
302
|
+
expect(sparql).toContain('?_reifier');
|
|
303
|
+
expect(sparql).not.toContain('GRAPH');
|
|
304
|
+
expect(sparql).not.toContain('?linkGraph');
|
|
305
|
+
});
|
|
306
|
+
it('binds author and timestamp on the reifier node', () => {
|
|
307
|
+
const query = {};
|
|
308
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
309
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/author> ?author');
|
|
310
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/timestamp> ?timestamp');
|
|
494
311
|
});
|
|
495
312
|
});
|
|
@@ -101,6 +101,10 @@ export function buildSHACL(subjectName, target, properties, allRelationsMeta, co
|
|
|
101
101
|
if (propMeta.flag && propMeta.initial) {
|
|
102
102
|
propShape.hasValue = propMeta.initial;
|
|
103
103
|
}
|
|
104
|
+
// sh:in — allowed values (enum constraint)
|
|
105
|
+
if (propMeta.options && propMeta.options.length > 0) {
|
|
106
|
+
propShape.in = propMeta.options;
|
|
107
|
+
}
|
|
104
108
|
// AD4M-specific metadata
|
|
105
109
|
if (propMeta.local !== undefined) {
|
|
106
110
|
propShape.local = propMeta.local;
|
package/lib/src/model/types.d.ts
CHANGED
|
@@ -41,47 +41,12 @@ export type ParentScope = {
|
|
|
41
41
|
id: string;
|
|
42
42
|
predicate: string;
|
|
43
43
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Descriptor for a user-named projection — a derived field computed from a
|
|
46
|
-
* relation that is attached to the parent instance under a custom `$`-prefixed
|
|
47
|
-
* key in the `IncludeMap`.
|
|
48
|
-
*
|
|
49
|
-
* The `from` field must name a declared relation on the model.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* include: {
|
|
54
|
-
* $signalCount: { from: 'signals', count: true },
|
|
55
|
-
* $mySignal: { from: 'signals', where: { author: myDid }, limit: 1 },
|
|
56
|
-
* $likeSignals: { from: 'signals', where: { signalTypeId: 'like' } },
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export interface IncludeProjection {
|
|
61
|
-
/** Declared relation name on the model to derive the projection from. */
|
|
62
|
-
from: string;
|
|
63
|
-
/**
|
|
64
|
-
* When true, the projection result is the count of matching instances
|
|
65
|
-
* as a `number`. All other options (`where`, `limit`) are still applied
|
|
66
|
-
* before counting. `count: true` → result type is `number`.
|
|
67
|
-
*/
|
|
68
|
-
count?: true;
|
|
69
|
-
/** Filter applied to the related instances before the projection result is produced. */
|
|
70
|
-
where?: Where;
|
|
71
|
-
/**
|
|
72
|
-
* Maximum number of results to include.
|
|
73
|
-
* When `limit` is `1`, the result type is `T | null` (unwrapped single instance)
|
|
74
|
-
* rather than `T[]`.
|
|
75
|
-
*/
|
|
76
|
-
limit?: number;
|
|
77
|
-
}
|
|
78
44
|
/**
|
|
79
45
|
* Describes which relations to eager-load when querying.
|
|
80
46
|
*
|
|
81
47
|
* Each value is either:
|
|
82
48
|
* - `true` — hydrate the relation one level deep
|
|
83
49
|
* - A `RelationSubQuery` — scoped sub-query (filter / sort / paginate / nested include)
|
|
84
|
-
* - An `IncludeProjection` — user-named derived field (count, filtered subset, single item)
|
|
85
50
|
*
|
|
86
51
|
* @example
|
|
87
52
|
* ```typescript
|
|
@@ -93,19 +58,63 @@ export interface IncludeProjection {
|
|
|
93
58
|
*
|
|
94
59
|
* // Nested eager-load
|
|
95
60
|
* { comments: { include: { author: true } } }
|
|
96
|
-
*
|
|
97
|
-
* // Projection: count + filtered single item
|
|
98
|
-
* { $signalCount: { from: 'signals', count: true }, $mySignal: { from: 'signals', where: { author: myDid }, limit: 1 } }
|
|
99
61
|
* ```
|
|
100
62
|
*/
|
|
101
63
|
export interface IncludeMap {
|
|
102
64
|
[relation: string]: boolean | RelationSubQuery | IncludeProjection;
|
|
103
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* A lightweight projection that computes a scalar or list value from a relation
|
|
68
|
+
* without fully hydrating the linked instances.
|
|
69
|
+
*
|
|
70
|
+
* Keys in `IncludeMap` that begin with `$` are treated as projections.
|
|
71
|
+
* Results are attached directly to each queried instance under the same key.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Attach a like-count to each post
|
|
76
|
+
* const posts = await Post.findAll(perspective, {
|
|
77
|
+
* include: {
|
|
78
|
+
* $likeCount: { from: 'likes', count: true },
|
|
79
|
+
* $myLike: { from: 'likes', limit: 1 },
|
|
80
|
+
* }
|
|
81
|
+
* });
|
|
82
|
+
* posts[0].$likeCount // number
|
|
83
|
+
* posts[0].$myLike // string ID or null
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export interface IncludeProjection {
|
|
87
|
+
/** The relation name on the parent model to project over. */
|
|
88
|
+
from: string;
|
|
89
|
+
/** When true, attaches an integer count instead of a list. */
|
|
90
|
+
count?: true;
|
|
91
|
+
/**
|
|
92
|
+
* Serialised target class shape. Set automatically by `executeModelQuery`
|
|
93
|
+
* when a `where` clause is present and the target class is resolvable.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
targetShape?: ModelMetadata;
|
|
97
|
+
/** Post-hydration where clause applied to the target instances. */
|
|
98
|
+
where?: Where;
|
|
99
|
+
/** Limit results (when 1, the attached value is unwrapped to a scalar). */
|
|
100
|
+
limit?: number;
|
|
101
|
+
/** Order results before applying limit. */
|
|
102
|
+
order?: Order;
|
|
103
|
+
}
|
|
104
|
+
/** Type guard for IncludeProjection objects. */
|
|
105
|
+
export declare function isIncludeProjection(val: unknown): val is IncludeProjection;
|
|
104
106
|
export type Query = {
|
|
105
107
|
/** Filter to instances that are the target of a link from a given parent. */
|
|
106
108
|
parent?: ParentScope;
|
|
107
109
|
properties?: string[];
|
|
108
110
|
include?: IncludeMap;
|
|
111
|
+
/**
|
|
112
|
+
* When true, eager-loads every declared forward relation on the model.
|
|
113
|
+
* Equivalent to listing all relation field names in `include: {}` explicitly.
|
|
114
|
+
* Useful for tree-walking and manifest-style inspections.
|
|
115
|
+
* Individual relations can still be overridden via `include` (explicit entries take precedence).
|
|
116
|
+
*/
|
|
117
|
+
includeAll?: boolean;
|
|
109
118
|
where?: Where;
|
|
110
119
|
order?: Order;
|
|
111
120
|
offset?: number;
|
package/lib/src/model/types.js
CHANGED
|
@@ -5,4 +5,7 @@
|
|
|
5
5
|
* (`query-utils.ts`, `decorators.ts`, etc.) can import types without
|
|
6
6
|
* creating circular runtime dependencies on `Ad4mModel.ts`.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
/** Type guard for IncludeProjection objects. */
|
|
9
|
+
export function isIncludeProjection(val) {
|
|
10
|
+
return typeof val === 'object' && val !== null && 'from' in val;
|
|
11
|
+
}
|
|
@@ -1,38 +1,10 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Field, ObjectType } from "type-graphql";
|
|
11
1
|
import { ExpressionGeneric } from "../expression/Expression";
|
|
12
|
-
|
|
13
|
-
let Neighbourhood = class Neighbourhood {
|
|
2
|
+
export class Neighbourhood {
|
|
14
3
|
constructor(linkLanguage, meta) {
|
|
15
4
|
this.linkLanguage = linkLanguage;
|
|
16
5
|
this.meta = meta;
|
|
17
6
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
__metadata("design:type", String)
|
|
22
|
-
], Neighbourhood.prototype, "linkLanguage", void 0);
|
|
23
|
-
__decorate([
|
|
24
|
-
Field(),
|
|
25
|
-
__metadata("design:type", Perspective)
|
|
26
|
-
], Neighbourhood.prototype, "meta", void 0);
|
|
27
|
-
Neighbourhood = __decorate([
|
|
28
|
-
ObjectType(),
|
|
29
|
-
__metadata("design:paramtypes", [String, Perspective])
|
|
30
|
-
], Neighbourhood);
|
|
31
|
-
export { Neighbourhood };
|
|
32
|
-
let NeighbourhoodExpression = class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {
|
|
33
|
-
};
|
|
34
|
-
NeighbourhoodExpression = __decorate([
|
|
35
|
-
ObjectType()
|
|
36
|
-
], NeighbourhoodExpression);
|
|
37
|
-
export { NeighbourhoodExpression };
|
|
7
|
+
}
|
|
8
|
+
export class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {
|
|
9
|
+
}
|
|
38
10
|
;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiClient } from "../apiClient";
|
|
2
2
|
import { Address } from "../Address";
|
|
3
3
|
import { DID } from "../DID";
|
|
4
4
|
import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language";
|
|
@@ -6,7 +6,7 @@ import { Perspective, PerspectiveUnsignedInput } from "../perspectives/Perspecti
|
|
|
6
6
|
import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
|
|
7
7
|
export declare class NeighbourhoodClient {
|
|
8
8
|
#private;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(baseUrl: string, token?: string, sharedApiClient?: ApiClient);
|
|
10
10
|
publishFromPerspective(perspectiveUUID: string, linkLanguage: Address, meta: Perspective): Promise<string>;
|
|
11
11
|
joinFromUrl(url: string): Promise<PerspectiveHandle>;
|
|
12
12
|
otherAgents(perspectiveUUID: string): Promise<DID[]>;
|
|
@@ -18,7 +18,7 @@ export declare class NeighbourhoodClient {
|
|
|
18
18
|
sendSignalU(perspectiveUUID: string, remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
|
|
19
19
|
sendBroadcast(perspectiveUUID: string, payload: Perspective, loopback?: boolean): Promise<boolean>;
|
|
20
20
|
sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput, loopback?: boolean): Promise<boolean>;
|
|
21
|
-
dispatchSignal(perspectiveUUID: string, signal:
|
|
21
|
+
dispatchSignal(perspectiveUUID: string, signal: unknown): void;
|
|
22
22
|
subscribeToSignals(perspectiveUUID: string): Promise<void>;
|
|
23
23
|
addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void>;
|
|
24
24
|
removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void;
|