@ahoo-wang/wow-client 9.9.0 → 10.0.0-alpha.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 +85 -230
- package/README.zh-CN.md +74 -209
- package/dist/commands.cjs +2 -0
- package/dist/commands.cjs.map +1 -0
- package/dist/commands.d.cts +123 -0
- package/dist/commands.d.ts +123 -0
- package/dist/commands.es.js +96 -0
- package/dist/commands.es.js.map +1 -0
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +1 -1
- package/dist/dsl/aggregation/types.d.ts +1 -1
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.d.cts +7 -8
- package/dist/dsl/cursorQuery.d.ts +7 -8
- package/dist/dsl/cursorQuery.es.js.map +1 -1
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +8 -1
- package/dist/dsl/descriptor.d.ts +8 -1
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/documents.d.cts +1 -1
- package/dist/dsl/documents.d.ts +1 -1
- package/dist/dsl/filter/types.d.cts +2 -1
- package/dist/dsl/filter/types.d.ts +2 -1
- package/dist/dsl/projection.cjs.map +1 -1
- package/dist/dsl/projection.d.cts +22 -0
- package/dist/dsl/projection.d.ts +22 -0
- package/dist/dsl/projection.es.js.map +1 -1
- package/dist/dsl/queryErrorCodes.cjs +2 -0
- package/dist/dsl/queryErrorCodes.cjs.map +1 -0
- package/dist/{error → dsl}/queryErrorCodes.d.cts +25 -24
- package/dist/{error → dsl}/queryErrorCodes.d.ts +25 -24
- package/dist/{error → dsl}/queryErrorCodes.es.js +2 -1
- package/dist/{error/queryErrorCodes.cjs.map → dsl/queryErrorCodes.es.js.map} +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.d.cts +1 -2
- package/dist/dsl.d.ts +1 -2
- package/dist/dsl.es.js +2 -3
- package/dist/exactJson.cjs +3 -0
- package/dist/exactJson.cjs.map +1 -0
- package/dist/exactJson.d.cts +54 -0
- package/dist/exactJson.d.ts +54 -0
- package/dist/exactJson.es.js +213 -0
- package/dist/exactJson.es.js.map +1 -0
- package/dist/http.cjs +2 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +96 -0
- package/dist/http.d.ts +96 -0
- package/dist/http.es.js +77 -0
- package/dist/http.es.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +19 -17
- package/dist/index.d.ts +19 -17
- package/dist/index.es.js +10 -36
- package/dist/manifest.cjs +2 -0
- package/dist/manifest.cjs.map +1 -0
- package/dist/manifest.d.cts +109 -0
- package/dist/manifest.d.ts +109 -0
- package/dist/manifest.es.js +14 -0
- package/dist/manifest.es.js.map +1 -0
- package/dist/problem.cjs +2 -0
- package/dist/problem.cjs.map +1 -0
- package/dist/problem.d.cts +211 -0
- package/dist/problem.d.ts +211 -0
- package/dist/problem.es.js +138 -0
- package/dist/problem.es.js.map +1 -0
- package/dist/queries.cjs +2 -0
- package/dist/queries.cjs.map +1 -0
- package/dist/queries.d.cts +182 -0
- package/dist/queries.d.ts +182 -0
- package/dist/queries.es.js +112 -0
- package/dist/queries.es.js.map +1 -0
- package/dist/state.cjs +2 -0
- package/dist/state.cjs.map +1 -0
- package/dist/state.d.cts +75 -0
- package/dist/state.d.ts +75 -0
- package/dist/state.es.js +70 -0
- package/dist/state.es.js.map +1 -0
- package/dist/streams.cjs +2 -0
- package/dist/streams.cjs.map +1 -0
- package/dist/streams.d.cts +74 -0
- package/dist/streams.d.ts +74 -0
- package/dist/streams.es.js +103 -0
- package/dist/streams.es.js.map +1 -0
- package/dist/wait.cjs +2 -0
- package/dist/wait.cjs.map +1 -0
- package/dist/wait.d.cts +61 -0
- package/dist/wait.d.ts +61 -0
- package/dist/wait.es.js +44 -0
- package/dist/wait.es.js.map +1 -0
- package/dist/wire.cjs +2 -0
- package/dist/wire.cjs.map +1 -0
- package/dist/wire.d.cts +326 -0
- package/dist/wire.d.ts +326 -0
- package/dist/wire.es.js +10 -0
- package/dist/wire.es.js.map +1 -0
- package/package.json +4 -16
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorate.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorate.es.js +0 -9
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateMetadata.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateMetadata.es.js +0 -6
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateParam.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateParam.es.js +0 -8
- package/dist/client/bindMethods.cjs +0 -2
- package/dist/client/bindMethods.cjs.map +0 -1
- package/dist/client/bindMethods.d.cts +0 -13
- package/dist/client/bindMethods.d.ts +0 -13
- package/dist/client/bindMethods.es.js +0 -19
- package/dist/client/bindMethods.es.js.map +0 -1
- package/dist/client/command/commandClient.cjs +0 -2
- package/dist/client/command/commandClient.cjs.map +0 -1
- package/dist/client/command/commandClient.d.cts +0 -67
- package/dist/client/command/commandClient.d.ts +0 -67
- package/dist/client/command/commandClient.es.js +0 -38
- package/dist/client/command/commandClient.es.js.map +0 -1
- package/dist/client/command/commandHeaders.cjs +0 -2
- package/dist/client/command/commandHeaders.cjs.map +0 -1
- package/dist/client/command/commandHeaders.d.cts +0 -75
- package/dist/client/command/commandHeaders.d.ts +0 -75
- package/dist/client/command/commandHeaders.es.js +0 -31
- package/dist/client/command/commandHeaders.es.js.map +0 -1
- package/dist/client/command/commandRequest.cjs +0 -2
- package/dist/client/command/commandRequest.cjs.map +0 -1
- package/dist/client/command/commandRequest.d.cts +0 -180
- package/dist/client/command/commandRequest.d.ts +0 -180
- package/dist/client/command/commandRequest.es.js +0 -31
- package/dist/client/command/commandRequest.es.js.map +0 -1
- package/dist/client/command/commandResult.d.cts +0 -15
- package/dist/client/command/commandResult.d.ts +0 -15
- package/dist/client/command/index.d.cts +0 -5
- package/dist/client/command/index.d.ts +0 -5
- package/dist/client/command/types.d.cts +0 -71
- package/dist/client/command/types.d.ts +0 -71
- package/dist/client/metadata/index.d.cts +0 -2
- package/dist/client/metadata/index.d.ts +0 -2
- package/dist/client/metadata/wowMetadata.d.cts +0 -48
- package/dist/client/metadata/wowMetadata.d.ts +0 -48
- package/dist/client/metadata/wowMetadataClient.cjs +0 -2
- package/dist/client/metadata/wowMetadataClient.cjs.map +0 -1
- package/dist/client/metadata/wowMetadataClient.d.cts +0 -23
- package/dist/client/metadata/wowMetadataClient.d.ts +0 -23
- package/dist/client/metadata/wowMetadataClient.es.js +0 -25
- package/dist/client/metadata/wowMetadataClient.es.js.map +0 -1
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs +0 -2
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs.map +0 -1
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.cts +0 -8
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.ts +0 -8
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js +0 -34
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js.map +0 -1
- package/dist/client/query/dataset/datasetDirectoryClient.cjs +0 -2
- package/dist/client/query/dataset/datasetDirectoryClient.cjs.map +0 -1
- package/dist/client/query/dataset/datasetDirectoryClient.d.cts +0 -29
- package/dist/client/query/dataset/datasetDirectoryClient.d.ts +0 -29
- package/dist/client/query/dataset/datasetDirectoryClient.es.js +0 -25
- package/dist/client/query/dataset/datasetDirectoryClient.es.js.map +0 -1
- package/dist/client/query/dataset/datasetQueryApi.d.cts +0 -40
- package/dist/client/query/dataset/datasetQueryApi.d.ts +0 -40
- package/dist/client/query/dataset/datasetQueryClient.cjs +0 -2
- package/dist/client/query/dataset/datasetQueryClient.cjs.map +0 -1
- package/dist/client/query/dataset/datasetQueryClient.d.cts +0 -57
- package/dist/client/query/dataset/datasetQueryClient.d.ts +0 -57
- package/dist/client/query/dataset/datasetQueryClient.es.js +0 -154
- package/dist/client/query/dataset/datasetQueryClient.es.js.map +0 -1
- package/dist/client/query/dataset/endpointPaths.cjs +0 -2
- package/dist/client/query/dataset/endpointPaths.cjs.map +0 -1
- package/dist/client/query/dataset/endpointPaths.d.cts +0 -9
- package/dist/client/query/dataset/endpointPaths.d.ts +0 -9
- package/dist/client/query/dataset/endpointPaths.es.js +0 -14
- package/dist/client/query/dataset/endpointPaths.es.js.map +0 -1
- package/dist/client/query/dataset/index.d.cts +0 -3
- package/dist/client/query/dataset/index.d.ts +0 -3
- package/dist/client/query/descriptor/descriptorEndpoints.cjs +0 -2
- package/dist/client/query/descriptor/descriptorEndpoints.cjs.map +0 -1
- package/dist/client/query/descriptor/descriptorEndpoints.d.cts +0 -29
- package/dist/client/query/descriptor/descriptorEndpoints.d.ts +0 -29
- package/dist/client/query/descriptor/descriptorEndpoints.es.js +0 -69
- package/dist/client/query/descriptor/descriptorEndpoints.es.js.map +0 -1
- package/dist/client/query/descriptor/endpointPaths.cjs +0 -2
- package/dist/client/query/descriptor/endpointPaths.cjs.map +0 -1
- package/dist/client/query/descriptor/endpointPaths.d.cts +0 -4
- package/dist/client/query/descriptor/endpointPaths.d.ts +0 -4
- package/dist/client/query/descriptor/endpointPaths.es.js +0 -9
- package/dist/client/query/descriptor/endpointPaths.es.js.map +0 -1
- package/dist/client/query/descriptor/index.d.cts +0 -2
- package/dist/client/query/descriptor/index.d.ts +0 -2
- package/dist/client/query/descriptor/queryDescriptorApi.d.cts +0 -58
- package/dist/client/query/descriptor/queryDescriptorApi.d.ts +0 -58
- package/dist/client/query/descriptor/queryDescriptorClient.cjs +0 -2
- package/dist/client/query/descriptor/queryDescriptorClient.cjs.map +0 -1
- package/dist/client/query/descriptor/queryDescriptorClient.d.cts +0 -61
- package/dist/client/query/descriptor/queryDescriptorClient.d.ts +0 -61
- package/dist/client/query/descriptor/queryDescriptorClient.es.js +0 -20
- package/dist/client/query/descriptor/queryDescriptorClient.es.js.map +0 -1
- package/dist/client/query/event/endpointPaths.cjs +0 -2
- package/dist/client/query/event/endpointPaths.cjs.map +0 -1
- package/dist/client/query/event/endpointPaths.d.cts +0 -8
- package/dist/client/query/event/endpointPaths.d.ts +0 -8
- package/dist/client/query/event/endpointPaths.es.js +0 -13
- package/dist/client/query/event/endpointPaths.es.js.map +0 -1
- package/dist/client/query/event/eventStreamQueryApi.d.cts +0 -29
- package/dist/client/query/event/eventStreamQueryApi.d.ts +0 -29
- package/dist/client/query/event/eventStreamQueryClient.cjs +0 -2
- package/dist/client/query/event/eventStreamQueryClient.cjs.map +0 -1
- package/dist/client/query/event/eventStreamQueryClient.d.cts +0 -193
- package/dist/client/query/event/eventStreamQueryClient.d.ts +0 -193
- package/dist/client/query/event/eventStreamQueryClient.es.js +0 -160
- package/dist/client/query/event/eventStreamQueryClient.es.js.map +0 -1
- package/dist/client/query/event/index.d.cts +0 -2
- package/dist/client/query/event/index.d.ts +0 -2
- package/dist/client/query/factory.cjs +0 -2
- package/dist/client/query/factory.cjs.map +0 -1
- package/dist/client/query/factory.d.cts +0 -165
- package/dist/client/query/factory.d.ts +0 -165
- package/dist/client/query/factory.es.js +0 -45
- package/dist/client/query/factory.es.js.map +0 -1
- package/dist/client/query/index.d.cts +0 -7
- package/dist/client/query/index.d.ts +0 -7
- package/dist/client/query/queryApi.d.cts +0 -68
- package/dist/client/query/queryApi.d.ts +0 -68
- package/dist/client/query/requests.d.cts +0 -24
- package/dist/client/query/requests.d.ts +0 -24
- package/dist/client/query/snapshot/endpointPaths.cjs +0 -2
- package/dist/client/query/snapshot/endpointPaths.cjs.map +0 -1
- package/dist/client/query/snapshot/endpointPaths.d.cts +0 -12
- package/dist/client/query/snapshot/endpointPaths.d.ts +0 -12
- package/dist/client/query/snapshot/endpointPaths.es.js +0 -17
- package/dist/client/query/snapshot/endpointPaths.es.js.map +0 -1
- package/dist/client/query/snapshot/index.d.cts +0 -2
- package/dist/client/query/snapshot/index.d.ts +0 -2
- package/dist/client/query/snapshot/snapshotQueryApi.d.cts +0 -101
- package/dist/client/query/snapshot/snapshotQueryApi.d.ts +0 -101
- package/dist/client/query/snapshot/snapshotQueryClient.cjs +0 -2
- package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +0 -1
- package/dist/client/query/snapshot/snapshotQueryClient.d.cts +0 -372
- package/dist/client/query/snapshot/snapshotQueryClient.d.ts +0 -372
- package/dist/client/query/snapshot/snapshotQueryClient.es.js +0 -239
- package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +0 -1
- package/dist/client/query/state/endpointPaths.cjs +0 -2
- package/dist/client/query/state/endpointPaths.cjs.map +0 -1
- package/dist/client/query/state/endpointPaths.d.cts +0 -10
- package/dist/client/query/state/endpointPaths.d.ts +0 -10
- package/dist/client/query/state/endpointPaths.es.js +0 -14
- package/dist/client/query/state/endpointPaths.es.js.map +0 -1
- package/dist/client/query/state/index.d.cts +0 -4
- package/dist/client/query/state/index.d.ts +0 -4
- package/dist/client/query/state/loadOwnerStateAggregateApi.d.cts +0 -36
- package/dist/client/query/state/loadOwnerStateAggregateApi.d.ts +0 -36
- package/dist/client/query/state/loadOwnerStateAggregateClient.cjs +0 -2
- package/dist/client/query/state/loadOwnerStateAggregateClient.cjs.map +0 -1
- package/dist/client/query/state/loadOwnerStateAggregateClient.d.cts +0 -58
- package/dist/client/query/state/loadOwnerStateAggregateClient.d.ts +0 -58
- package/dist/client/query/state/loadOwnerStateAggregateClient.es.js +0 -56
- package/dist/client/query/state/loadOwnerStateAggregateClient.es.js.map +0 -1
- package/dist/client/query/state/loadStateAggregateApi.d.cts +0 -37
- package/dist/client/query/state/loadStateAggregateApi.d.ts +0 -37
- package/dist/client/query/state/loadStateAggregateClient.cjs +0 -2
- package/dist/client/query/state/loadStateAggregateClient.cjs.map +0 -1
- package/dist/client/query/state/loadStateAggregateClient.d.cts +0 -62
- package/dist/client/query/state/loadStateAggregateClient.d.ts +0 -62
- package/dist/client/query/state/loadStateAggregateClient.es.js +0 -65
- package/dist/client/query/state/loadStateAggregateClient.es.js.map +0 -1
- package/dist/client/routing.cjs +0 -2
- package/dist/client/routing.cjs.map +0 -1
- package/dist/client/routing.d.cts +0 -47
- package/dist/client/routing.d.ts +0 -47
- package/dist/client/routing.es.js +0 -8
- package/dist/client/routing.es.js.map +0 -1
- package/dist/error/errorInfo.cjs +0 -2
- package/dist/error/errorInfo.cjs.map +0 -1
- package/dist/error/errorInfo.d.cts +0 -139
- package/dist/error/errorInfo.d.ts +0 -139
- package/dist/error/errorInfo.es.js +0 -32
- package/dist/error/errorInfo.es.js.map +0 -1
- package/dist/error/headers.cjs +0 -2
- package/dist/error/headers.cjs.map +0 -1
- package/dist/error/headers.d.cts +0 -39
- package/dist/error/headers.d.ts +0 -39
- package/dist/error/headers.es.js +0 -10
- package/dist/error/headers.es.js.map +0 -1
- package/dist/error/index.d.cts +0 -21
- package/dist/error/index.d.ts +0 -21
- package/dist/error/queryErrorCodes.cjs +0 -2
- package/dist/error/queryErrorCodes.es.js.map +0 -1
- package/dist/error/wowError.cjs +0 -2
- package/dist/error/wowError.cjs.map +0 -1
- package/dist/error/wowError.d.cts +0 -99
- package/dist/error/wowError.d.ts +0 -99
- package/dist/error/wowError.es.js +0 -53
- package/dist/error/wowError.es.js.map +0 -1
- package/dist/legacy/condition.cjs +0 -2
- package/dist/legacy/condition.cjs.map +0 -1
- package/dist/legacy/condition.d.cts +0 -517
- package/dist/legacy/condition.d.ts +0 -517
- package/dist/legacy/condition.es.js +0 -338
- package/dist/legacy/condition.es.js.map +0 -1
- package/dist/legacy/index.d.cts +0 -16
- package/dist/legacy/index.d.ts +0 -16
- package/dist/legacy/locale/en_US.cjs +0 -2
- package/dist/legacy/locale/en_US.cjs.map +0 -1
- package/dist/legacy/locale/en_US.d.cts +0 -7
- package/dist/legacy/locale/en_US.d.ts +0 -7
- package/dist/legacy/locale/en_US.es.js +0 -50
- package/dist/legacy/locale/en_US.es.js.map +0 -1
- package/dist/legacy/locale/operatorLocale.d.cts +0 -10
- package/dist/legacy/locale/operatorLocale.d.ts +0 -10
- package/dist/legacy/locale/zh_CN.cjs +0 -2
- package/dist/legacy/locale/zh_CN.cjs.map +0 -1
- package/dist/legacy/locale/zh_CN.d.cts +0 -7
- package/dist/legacy/locale/zh_CN.d.ts +0 -7
- package/dist/legacy/locale/zh_CN.es.js +0 -50
- package/dist/legacy/locale/zh_CN.es.js.map +0 -1
- package/dist/legacy/operator.cjs +0 -2
- package/dist/legacy/operator.cjs.map +0 -1
- package/dist/legacy/operator.d.cts +0 -218
- package/dist/legacy/operator.d.ts +0 -218
- package/dist/legacy/operator.es.js +0 -25
- package/dist/legacy/operator.es.js.map +0 -1
- package/dist/legacy/queryable.cjs +0 -2
- package/dist/legacy/queryable.cjs.map +0 -1
- package/dist/legacy/queryable.d.cts +0 -61
- package/dist/legacy/queryable.d.ts +0 -61
- package/dist/legacy/queryable.es.js +0 -34
- package/dist/legacy/queryable.es.js.map +0 -1
- package/dist/legacy.cjs +0 -1
- package/dist/legacy.es.js +0 -6
- package/dist/model/abac.cjs +0 -2
- package/dist/model/abac.cjs.map +0 -1
- package/dist/model/abac.d.cts +0 -33
- package/dist/model/abac.d.ts +0 -33
- package/dist/model/abac.es.js +0 -6
- package/dist/model/abac.es.js.map +0 -1
- package/dist/model/bi.cjs +0 -2
- package/dist/model/bi.cjs.map +0 -1
- package/dist/model/bi.d.cts +0 -12
- package/dist/model/bi.d.ts +0 -12
- package/dist/model/bi.es.js +0 -8
- package/dist/model/bi.es.js.map +0 -1
- package/dist/model/command.cjs +0 -2
- package/dist/model/command.cjs.map +0 -1
- package/dist/model/command.d.cts +0 -137
- package/dist/model/command.d.ts +0 -137
- package/dist/model/command.es.js +0 -8
- package/dist/model/command.es.js.map +0 -1
- package/dist/model/common.d.cts +0 -19
- package/dist/model/common.d.ts +0 -19
- package/dist/model/domainEventStream.cjs +0 -2
- package/dist/model/domainEventStream.cjs.map +0 -1
- package/dist/model/domainEventStream.d.cts +0 -109
- package/dist/model/domainEventStream.d.ts +0 -109
- package/dist/model/domainEventStream.es.js +0 -23
- package/dist/model/domainEventStream.es.js.map +0 -1
- package/dist/model/function.cjs +0 -2
- package/dist/model/function.cjs.map +0 -1
- package/dist/model/function.d.cts +0 -41
- package/dist/model/function.d.ts +0 -41
- package/dist/model/function.es.js +0 -8
- package/dist/model/function.es.js.map +0 -1
- package/dist/model/index.d.cts +0 -24
- package/dist/model/index.d.ts +0 -24
- package/dist/model/messaging.d.cts +0 -5
- package/dist/model/messaging.d.ts +0 -5
- package/dist/model/modeling.d.cts +0 -145
- package/dist/model/modeling.d.ts +0 -145
- package/dist/model/naming.d.cts +0 -27
- package/dist/model/naming.d.ts +0 -27
- package/dist/model/snapshot.cjs +0 -2
- package/dist/model/snapshot.cjs.map +0 -1
- package/dist/model/snapshot.d.cts +0 -53
- package/dist/model/snapshot.d.ts +0 -53
- package/dist/model/snapshot.es.js +0 -20
- package/dist/model/snapshot.es.js.map +0 -1
- package/dist/transport/endpoints.cjs +0 -2
- package/dist/transport/endpoints.cjs.map +0 -1
- package/dist/transport/endpoints.d.cts +0 -79
- package/dist/transport/endpoints.d.ts +0 -79
- package/dist/transport/endpoints.es.js +0 -14
- package/dist/transport/endpoints.es.js.map +0 -1
- package/dist/transport/eventStreams.cjs +0 -2
- package/dist/transport/eventStreams.cjs.map +0 -1
- package/dist/transport/eventStreams.d.cts +0 -25
- package/dist/transport/eventStreams.d.ts +0 -25
- package/dist/transport/eventStreams.es.js +0 -21
- package/dist/transport/eventStreams.es.js.map +0 -1
- package/dist/transport/index.d.cts +0 -1
- package/dist/transport/index.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.cjs","names":["json","resumableQueryRows","send","WowHeaders","entityTag","eventNumbers","require_exactJson","require_http","require_streams","QueryModelClient","path","client","numbers","query","options","controller","row","resume","limit","open","received","lastEventId","first","response","version","tag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","events","DatasetClient","context","dataset"],"sources":["../src/queries.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationQuery } from './dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from './dsl/cursorQuery.js';\nimport type { Projected } from './dsl/projection.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type { QueryModelDescriptor } from './dsl/descriptor.js';\nimport type { FilterCapable } from './dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from './dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport {\n resumableQueryRows,\n type StreamedRow,\n type StreamResumeOptions,\n} from './streams.js';\n\n/** How a list is streamed: the request's options, and how it resumes. */\nexport interface ListStreamOptions extends RequestOptions {\n /** How the stream resumes (decision D253); `false` never resumes it. */\n readonly resume?: StreamResumeOptions | false;\n}\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145). A query written with literal `include`\n * paths answers records narrowed to them ({@link Projected}, review R4-Q,\n * Q-14).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n * @param numbers - The numbers of each record read as their exact text\n * (review R4-Q, Q-9)\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n readonly numbers?: TextNumbers,\n ) {}\n\n /** The marks of a list of records. */\n private get listNumbers(): TextNumbers | undefined {\n return this.numbers === undefined ? undefined : { '*': this.numbers };\n }\n\n /** The marks of a page of records. */\n private get pageNumbers(): TextNumbers | undefined {\n return this.numbers === undefined\n ? undefined\n : { list: { '*': this.numbers } };\n }\n\n /** The records that match, at most `limit` (the server's default when absent). */\n list<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>[]>;\n list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R[]>(await this.post('list', query, options), this.listNumbers);\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem. The\n * stream resumes where it stopped (decision D253) when the server ends it\n * to be resumed, when it is cut off and when it fails with a retryable\n * problem: see {@link StreamResumeOptions}. A `limit` counts every record\n * read, resumed or not.\n */\n listStream<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<Projected<R, INCLUDE>>>;\n listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<R>>;\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<unknown> {\n return (await this.listStreamRows(query, options)).pipeThrough(\n new TransformStream<StreamedRow<R>, R>({\n transform(row, controller) {\n controller.enqueue(row.record);\n },\n }),\n );\n }\n\n /**\n * The records that match as {@link listStream} reads them, each with its\n * position: keep the last one read to resume the stream later\n * ({@link StreamResumeOptions.lastEventId}), on another page or after a\n * restart.\n */\n listStreamRows<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;\n listStreamRows(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<R>>>;\n async listStreamRows(\n query: FilterListQuery<FIELDS>,\n options: ListStreamOptions = {},\n ): Promise<ReadableStream<StreamedRow<R>>> {\n const resume =\n options.resume === false ? { maxRetries: 0 } : options.resume;\n const limit = query.limit ?? 0;\n const open = (lastEventId: string | undefined, received: number) => {\n return this.post(\n 'list',\n limit > 0 ? { ...query, limit: limit - received } : query,\n options,\n 'text/event-stream',\n lastEventId,\n );\n };\n const first = await open(resume?.lastEventId, 0);\n return resumableQueryRows<R>(\n first,\n (lastEventId, received) =>\n limit > 0 && received >= limit\n ? Promise.resolve(undefined)\n : open(lastEventId, received),\n {\n ...resume,\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n ...(this.numbers === undefined ? {} : { numbers: this.numbers }),\n },\n );\n }\n\n /** One page of the records that match, and their total. */\n paged<const INCLUDE extends FIELDS>(\n query: Including<PagedQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<PagedResult<Projected<R, INCLUDE>>>;\n paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>>;\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<PagedResult<R>>(\n await this.post('paged', query, options),\n this.pageNumbers,\n );\n }\n\n /** One page of a forward-only cursor over the records that match. */\n cursor<const INCLUDE extends FIELDS>(\n query: Including<CursorQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<CursorPage<Projected<R, INCLUDE>>>;\n cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>>;\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<CursorPage<R>>(\n await this.post('cursor', query, options),\n this.pageNumbers,\n );\n }\n\n /** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */\n single<const INCLUDE extends FIELDS>(\n query: Including<FilterSingleQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>>;\n single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R>;\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R>(await this.post('single', query, options), this.numbers);\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n lastEventId?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept, [WowHeaders.LAST_EVENT_ID]: lastEventId },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/**\n * A query whose projection includes the literal paths `INCLUDE`: a query\n * client narrows its records to them ({@link Projected}).\n */\nexport type Including<Q, INCLUDE extends string> = Q & {\n readonly projection: { readonly include: readonly INCLUDE[] };\n};\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(\n queryPath(type, 'snapshot'),\n client,\n type.textNumbers?.state === undefined\n ? undefined\n : { state: type.textNumbers.state },\n );\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D235) on the same\n * engine as its snapshots: one record per commit, `count` counts commits, a\n * condition on an event is an `elementMatch` on `events`, and per-event\n * analytics expand `events` in an aggregation (`elements`). A filter need\n * not name the aggregate, but one that does not reads the log the service\n * appends to: the budget bounds it.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n const events = eventNumbers(type);\n super(\n queryPath(type, 'events'),\n client,\n events === undefined ? undefined : { events: { '*': events } },\n );\n }\n}\n\n/**\n * The datasets of a Wow service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":"sFA8GA,IAAaS,EAAb,KAAiE,CAO/D,YACE,EACA,EAAoC,CAAC,EACrC,EACA,CAHS,KAAA,KAAAC,EACA,KAAA,OAAAC,E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AAU,EAAqB,EAAuB,CACpE,MAAO,IAAIC,EAAK,QAAQ,GAAGA,EAAK,KAAK,GAAGC,EAAM,OAChD,CASA,IAAaC,EAAb,cAGUrB,CAGR,CAKA,YACE,EACA,EACA,CACA,MACEkB,EAAUC,EAAM,UAAU,EAC1BjB,EACAiB,EAAK,aAAa,QAAU,IAAA,GACxB,IAAA,GACA,CAAE,MAAOA,EAAK,YAAY,KAAM,CACtC,EATS,KAAA,KAAAA,CAUX,CACF,EAYaG,EAAb,cAEUtB,CAAyD,CAKjE,YACE,EACA,EACA,CACA,IAAMuB,EAAS3B,EAAAA,aAAauB,CAAI,EAChC,MACED,EAAUC,EAAM,QAAQ,EACxBjB,EACAqB,IAAW,IAAA,GAAY,IAAA,GAAY,CAAE,OAAQ,CAAE,IAAKA,CAAO,CAAE,CAC/D,EARS,KAAA,KAAAJ,CASX,CACF,EAOaK,EAAb,KAA2B,CAEzB,YAAY,EAAoC,CAAC,EAAG,CAA/B,KAAA,OAAAtB,CAAgC,CAGrD,MAAM,KAAK,EAAmD,CAC5D,OAAOX,EAAAA,KACL,MAAME,EAAAA,KAAK,KAAK,OAAQ,CAAE,OAAQ,MAAO,KAAM,eAAgB,SAAQ,CAAC,CAC1E,CACF,CAQA,QACE,EACA,EAC6B,CAC7B,OAAO,IAAIO,EACT,gBAAgB,mBAAmByB,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,QAC3E,KAAK,MACP,CACF,CACF"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { AggregationQuery } from './dsl/aggregation/index.cjs';
|
|
2
|
+
import { CursorPage, CursorQuery } from './dsl/cursorQuery.cjs';
|
|
3
|
+
import { Projected } from './dsl/projection.cjs';
|
|
4
|
+
import { TextNumbers } from './exactJson.cjs';
|
|
5
|
+
import { QueryModelDescriptor } from './dsl/descriptor.cjs';
|
|
6
|
+
import { FilterCapable } from './dsl/filter/index.cjs';
|
|
7
|
+
import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from './dsl/queryable.cjs';
|
|
8
|
+
import { RequestOptions, WowClientOptions } from './http.cjs';
|
|
9
|
+
import { AggregateType, DatasetEntry, EventStreamField, EventStreamRecord, EventView, SnapshotRecord, SnapshotSystemField } from './wire.cjs';
|
|
10
|
+
import { StreamedRow, StreamResumeOptions } from './streams.cjs';
|
|
11
|
+
/** How a list is streamed: the request's options, and how it resumes. */
|
|
12
|
+
export interface ListStreamOptions extends RequestOptions {
|
|
13
|
+
/** How the stream resumes (decision D253); `false` never resumes it. */
|
|
14
|
+
readonly resume?: StreamResumeOptions | false;
|
|
15
|
+
}
|
|
16
|
+
/** How a paged query counts its total (`TotalMode`, decision D150). */
|
|
17
|
+
export type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';
|
|
18
|
+
/** A paged query of a query route: a page, and how its total is counted. */
|
|
19
|
+
export interface PagedQuery<FIELDS extends string = string> extends FilterPagedQuery<FIELDS> {
|
|
20
|
+
/** `BOUNDED` (the server's default) counts up to the budget's limit. */
|
|
21
|
+
total?: TotalMode;
|
|
22
|
+
}
|
|
23
|
+
/** A count of a query route (decision D150). */
|
|
24
|
+
export interface CountQuery<FIELDS extends string = string> extends FilterCapable<FIELDS> {
|
|
25
|
+
/** The most matches to count; the budget's default when absent. */
|
|
26
|
+
limit?: number;
|
|
27
|
+
}
|
|
28
|
+
/** What a count answers: exact below its limit, else the limit itself. */
|
|
29
|
+
export interface CountResult {
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly exact: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A page of a paged query: `total` is exact when `exact`, a lower bound
|
|
35
|
+
* otherwise, and null for `TotalMode.NONE`.
|
|
36
|
+
*/
|
|
37
|
+
export interface PagedResult<T> {
|
|
38
|
+
readonly total: number | null;
|
|
39
|
+
readonly exact: boolean;
|
|
40
|
+
readonly list: readonly T[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A query model's capability descriptor and its version, the `ETag` of
|
|
44
|
+
* `GET …/query`; `notModified` when the version given is still current.
|
|
45
|
+
*/
|
|
46
|
+
export type DescriptorResult = {
|
|
47
|
+
readonly notModified: false;
|
|
48
|
+
readonly version?: string;
|
|
49
|
+
readonly descriptor: QueryModelDescriptor;
|
|
50
|
+
} | {
|
|
51
|
+
readonly notModified: true;
|
|
52
|
+
readonly version: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Queries one query model of a Wow service: `POST {path}` with a body
|
|
56
|
+
* whose `kind` names the operation, `GET {path}` for the capability
|
|
57
|
+
* descriptor (decisions D127, D145). A query written with literal `include`
|
|
58
|
+
* paths answers records narrowed to them ({@link Projected}, review R4-Q,
|
|
59
|
+
* Q-14).
|
|
60
|
+
*
|
|
61
|
+
* @typeParam R - The record's type.
|
|
62
|
+
* @typeParam FIELDS - The field paths a filter, sort or projection takes.
|
|
63
|
+
*/
|
|
64
|
+
export declare class QueryModelClient<R, FIELDS extends string = string> {
|
|
65
|
+
readonly path: string;
|
|
66
|
+
readonly client: WowClientOptions;
|
|
67
|
+
readonly numbers?: TextNumbers | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* @param path - The query route, `/{context}/{aggregate}/{model}/query`
|
|
70
|
+
* @param client - How the service is reached
|
|
71
|
+
* @param numbers - The numbers of each record read as their exact text
|
|
72
|
+
* (review R4-Q, Q-9)
|
|
73
|
+
*/
|
|
74
|
+
constructor(path: string, client?: WowClientOptions, numbers?: TextNumbers | undefined);
|
|
75
|
+
/** The marks of a list of records. */
|
|
76
|
+
private get listNumbers();
|
|
77
|
+
/** The marks of a page of records. */
|
|
78
|
+
private get pageNumbers();
|
|
79
|
+
/** The records that match, at most `limit` (the server's default when absent). */
|
|
80
|
+
list<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>[]>;
|
|
81
|
+
list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;
|
|
82
|
+
/**
|
|
83
|
+
* The records that match, as server-sent events read one at a time; a
|
|
84
|
+
* failure after the first record errors the stream with its problem. The
|
|
85
|
+
* stream resumes where it stopped (decision D253) when the server ends it
|
|
86
|
+
* to be resumed, when it is cut off and when it fails with a retryable
|
|
87
|
+
* problem: see {@link StreamResumeOptions}. A `limit` counts every record
|
|
88
|
+
* read, resumed or not.
|
|
89
|
+
*/
|
|
90
|
+
listStream<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<Projected<R, INCLUDE>>>;
|
|
91
|
+
listStream(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<R>>;
|
|
92
|
+
/**
|
|
93
|
+
* The records that match as {@link listStream} reads them, each with its
|
|
94
|
+
* position: keep the last one read to resume the stream later
|
|
95
|
+
* ({@link StreamResumeOptions.lastEventId}), on another page or after a
|
|
96
|
+
* restart.
|
|
97
|
+
*/
|
|
98
|
+
listStreamRows<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;
|
|
99
|
+
listStreamRows(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<R>>>;
|
|
100
|
+
/** One page of the records that match, and their total. */
|
|
101
|
+
paged<const INCLUDE extends FIELDS>(query: Including<PagedQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<PagedResult<Projected<R, INCLUDE>>>;
|
|
102
|
+
paged(query: PagedQuery<FIELDS>, options?: RequestOptions): Promise<PagedResult<R>>;
|
|
103
|
+
/** One page of a forward-only cursor over the records that match. */
|
|
104
|
+
cursor<const INCLUDE extends FIELDS>(query: Including<CursorQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<CursorPage<Projected<R, INCLUDE>>>;
|
|
105
|
+
cursor(query: CursorQuery<FIELDS>, options?: RequestOptions): Promise<CursorPage<R>>;
|
|
106
|
+
/** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */
|
|
107
|
+
single<const INCLUDE extends FIELDS>(query: Including<FilterSingleQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>>;
|
|
108
|
+
single(query: FilterSingleQuery<FIELDS>, options?: RequestOptions): Promise<R>;
|
|
109
|
+
/** How many records match, bounded by the count's limit. */
|
|
110
|
+
count(query: CountQuery<FIELDS>, options?: RequestOptions): Promise<CountResult>;
|
|
111
|
+
/** The groups and metrics of an aggregation, one row per group. */
|
|
112
|
+
aggregate<ROW = Record<string, unknown>>(query: AggregationQuery<FIELDS, string>, options?: RequestOptions): Promise<ROW[]>;
|
|
113
|
+
/**
|
|
114
|
+
* The model's capability descriptor; with the `version` already held, a
|
|
115
|
+
* 304 answers `notModified`.
|
|
116
|
+
*/
|
|
117
|
+
describe(version?: string, options?: RequestOptions): Promise<DescriptorResult>;
|
|
118
|
+
private post;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A query whose projection includes the literal paths `INCLUDE`: a query
|
|
122
|
+
* client narrows its records to them ({@link Projected}).
|
|
123
|
+
*/
|
|
124
|
+
export type Including<Q, INCLUDE extends string> = Q & {
|
|
125
|
+
readonly projection: {
|
|
126
|
+
readonly include: readonly INCLUDE[];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/** The query route of a model of an aggregate type. */
|
|
130
|
+
export declare function queryPath(type: AggregateType, model: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Queries an aggregate type's snapshots (decision D128), the default read
|
|
133
|
+
* model; only where the aggregate keeps them.
|
|
134
|
+
*
|
|
135
|
+
* @typeParam S - The state's type.
|
|
136
|
+
* @typeParam STATE_FIELDS - The `state.*` paths of the state.
|
|
137
|
+
*/
|
|
138
|
+
export declare class SnapshotQueryClient<S = unknown, STATE_FIELDS extends string = `state.${string}`> extends QueryModelClient<SnapshotRecord<S>, SnapshotSystemField | STATE_FIELDS> {
|
|
139
|
+
readonly type: AggregateType;
|
|
140
|
+
/**
|
|
141
|
+
* @param type - The aggregate type
|
|
142
|
+
* @param client - How the service is reached
|
|
143
|
+
*/
|
|
144
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Queries an aggregate type's event streams (decision D235) on the same
|
|
148
|
+
* engine as its snapshots: one record per commit, `count` counts commits, a
|
|
149
|
+
* condition on an event is an `elementMatch` on `events`, and per-event
|
|
150
|
+
* analytics expand `events` in an aggregation (`elements`). A filter need
|
|
151
|
+
* not name the aggregate, but one that does not reads the log the service
|
|
152
|
+
* appends to: the budget bounds it.
|
|
153
|
+
*
|
|
154
|
+
* @typeParam E - The events' type.
|
|
155
|
+
*/
|
|
156
|
+
export declare class EventQueryClient<E extends EventView = EventView> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {
|
|
157
|
+
readonly type: AggregateType;
|
|
158
|
+
/**
|
|
159
|
+
* @param type - The aggregate type
|
|
160
|
+
* @param client - How the service is reached
|
|
161
|
+
*/
|
|
162
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The datasets of a Wow service (decisions D75, D145): registered at run
|
|
166
|
+
* time, so not in the Manifest. Lists those the caller sees and queries
|
|
167
|
+
* each as a snapshot model is queried.
|
|
168
|
+
*/
|
|
169
|
+
export declare class DatasetClient {
|
|
170
|
+
readonly client: WowClientOptions;
|
|
171
|
+
/** @param client - How the service is reached */
|
|
172
|
+
constructor(client?: WowClientOptions);
|
|
173
|
+
/** The datasets the caller sees, by name. */
|
|
174
|
+
list(options?: RequestOptions): Promise<DatasetEntry[]>;
|
|
175
|
+
/**
|
|
176
|
+
* The query client of the dataset `context.dataset`.
|
|
177
|
+
*
|
|
178
|
+
* @typeParam R - The row's type.
|
|
179
|
+
* @typeParam FIELDS - The dataset's field paths.
|
|
180
|
+
*/
|
|
181
|
+
dataset<R = Record<string, unknown>, FIELDS extends string = string>(context: string, dataset: string): QueryModelClient<R, FIELDS>;
|
|
182
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { AggregationQuery } from './dsl/aggregation/index.js';
|
|
2
|
+
import { CursorPage, CursorQuery } from './dsl/cursorQuery.js';
|
|
3
|
+
import { Projected } from './dsl/projection.js';
|
|
4
|
+
import { TextNumbers } from './exactJson.js';
|
|
5
|
+
import { QueryModelDescriptor } from './dsl/descriptor.js';
|
|
6
|
+
import { FilterCapable } from './dsl/filter/index.js';
|
|
7
|
+
import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from './dsl/queryable.js';
|
|
8
|
+
import { RequestOptions, WowClientOptions } from './http.js';
|
|
9
|
+
import { AggregateType, DatasetEntry, EventStreamField, EventStreamRecord, EventView, SnapshotRecord, SnapshotSystemField } from './wire.js';
|
|
10
|
+
import { StreamedRow, StreamResumeOptions } from './streams.js';
|
|
11
|
+
/** How a list is streamed: the request's options, and how it resumes. */
|
|
12
|
+
export interface ListStreamOptions extends RequestOptions {
|
|
13
|
+
/** How the stream resumes (decision D253); `false` never resumes it. */
|
|
14
|
+
readonly resume?: StreamResumeOptions | false;
|
|
15
|
+
}
|
|
16
|
+
/** How a paged query counts its total (`TotalMode`, decision D150). */
|
|
17
|
+
export type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';
|
|
18
|
+
/** A paged query of a query route: a page, and how its total is counted. */
|
|
19
|
+
export interface PagedQuery<FIELDS extends string = string> extends FilterPagedQuery<FIELDS> {
|
|
20
|
+
/** `BOUNDED` (the server's default) counts up to the budget's limit. */
|
|
21
|
+
total?: TotalMode;
|
|
22
|
+
}
|
|
23
|
+
/** A count of a query route (decision D150). */
|
|
24
|
+
export interface CountQuery<FIELDS extends string = string> extends FilterCapable<FIELDS> {
|
|
25
|
+
/** The most matches to count; the budget's default when absent. */
|
|
26
|
+
limit?: number;
|
|
27
|
+
}
|
|
28
|
+
/** What a count answers: exact below its limit, else the limit itself. */
|
|
29
|
+
export interface CountResult {
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly exact: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A page of a paged query: `total` is exact when `exact`, a lower bound
|
|
35
|
+
* otherwise, and null for `TotalMode.NONE`.
|
|
36
|
+
*/
|
|
37
|
+
export interface PagedResult<T> {
|
|
38
|
+
readonly total: number | null;
|
|
39
|
+
readonly exact: boolean;
|
|
40
|
+
readonly list: readonly T[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A query model's capability descriptor and its version, the `ETag` of
|
|
44
|
+
* `GET …/query`; `notModified` when the version given is still current.
|
|
45
|
+
*/
|
|
46
|
+
export type DescriptorResult = {
|
|
47
|
+
readonly notModified: false;
|
|
48
|
+
readonly version?: string;
|
|
49
|
+
readonly descriptor: QueryModelDescriptor;
|
|
50
|
+
} | {
|
|
51
|
+
readonly notModified: true;
|
|
52
|
+
readonly version: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Queries one query model of a Wow service: `POST {path}` with a body
|
|
56
|
+
* whose `kind` names the operation, `GET {path}` for the capability
|
|
57
|
+
* descriptor (decisions D127, D145). A query written with literal `include`
|
|
58
|
+
* paths answers records narrowed to them ({@link Projected}, review R4-Q,
|
|
59
|
+
* Q-14).
|
|
60
|
+
*
|
|
61
|
+
* @typeParam R - The record's type.
|
|
62
|
+
* @typeParam FIELDS - The field paths a filter, sort or projection takes.
|
|
63
|
+
*/
|
|
64
|
+
export declare class QueryModelClient<R, FIELDS extends string = string> {
|
|
65
|
+
readonly path: string;
|
|
66
|
+
readonly client: WowClientOptions;
|
|
67
|
+
readonly numbers?: TextNumbers | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* @param path - The query route, `/{context}/{aggregate}/{model}/query`
|
|
70
|
+
* @param client - How the service is reached
|
|
71
|
+
* @param numbers - The numbers of each record read as their exact text
|
|
72
|
+
* (review R4-Q, Q-9)
|
|
73
|
+
*/
|
|
74
|
+
constructor(path: string, client?: WowClientOptions, numbers?: TextNumbers | undefined);
|
|
75
|
+
/** The marks of a list of records. */
|
|
76
|
+
private get listNumbers();
|
|
77
|
+
/** The marks of a page of records. */
|
|
78
|
+
private get pageNumbers();
|
|
79
|
+
/** The records that match, at most `limit` (the server's default when absent). */
|
|
80
|
+
list<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>[]>;
|
|
81
|
+
list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;
|
|
82
|
+
/**
|
|
83
|
+
* The records that match, as server-sent events read one at a time; a
|
|
84
|
+
* failure after the first record errors the stream with its problem. The
|
|
85
|
+
* stream resumes where it stopped (decision D253) when the server ends it
|
|
86
|
+
* to be resumed, when it is cut off and when it fails with a retryable
|
|
87
|
+
* problem: see {@link StreamResumeOptions}. A `limit` counts every record
|
|
88
|
+
* read, resumed or not.
|
|
89
|
+
*/
|
|
90
|
+
listStream<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<Projected<R, INCLUDE>>>;
|
|
91
|
+
listStream(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<R>>;
|
|
92
|
+
/**
|
|
93
|
+
* The records that match as {@link listStream} reads them, each with its
|
|
94
|
+
* position: keep the last one read to resume the stream later
|
|
95
|
+
* ({@link StreamResumeOptions.lastEventId}), on another page or after a
|
|
96
|
+
* restart.
|
|
97
|
+
*/
|
|
98
|
+
listStreamRows<const INCLUDE extends FIELDS>(query: Including<FilterListQuery<FIELDS>, INCLUDE>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;
|
|
99
|
+
listStreamRows(query: FilterListQuery<FIELDS>, options?: ListStreamOptions): Promise<ReadableStream<StreamedRow<R>>>;
|
|
100
|
+
/** One page of the records that match, and their total. */
|
|
101
|
+
paged<const INCLUDE extends FIELDS>(query: Including<PagedQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<PagedResult<Projected<R, INCLUDE>>>;
|
|
102
|
+
paged(query: PagedQuery<FIELDS>, options?: RequestOptions): Promise<PagedResult<R>>;
|
|
103
|
+
/** One page of a forward-only cursor over the records that match. */
|
|
104
|
+
cursor<const INCLUDE extends FIELDS>(query: Including<CursorQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<CursorPage<Projected<R, INCLUDE>>>;
|
|
105
|
+
cursor(query: CursorQuery<FIELDS>, options?: RequestOptions): Promise<CursorPage<R>>;
|
|
106
|
+
/** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */
|
|
107
|
+
single<const INCLUDE extends FIELDS>(query: Including<FilterSingleQuery<FIELDS>, INCLUDE>, options?: RequestOptions): Promise<Projected<R, INCLUDE>>;
|
|
108
|
+
single(query: FilterSingleQuery<FIELDS>, options?: RequestOptions): Promise<R>;
|
|
109
|
+
/** How many records match, bounded by the count's limit. */
|
|
110
|
+
count(query: CountQuery<FIELDS>, options?: RequestOptions): Promise<CountResult>;
|
|
111
|
+
/** The groups and metrics of an aggregation, one row per group. */
|
|
112
|
+
aggregate<ROW = Record<string, unknown>>(query: AggregationQuery<FIELDS, string>, options?: RequestOptions): Promise<ROW[]>;
|
|
113
|
+
/**
|
|
114
|
+
* The model's capability descriptor; with the `version` already held, a
|
|
115
|
+
* 304 answers `notModified`.
|
|
116
|
+
*/
|
|
117
|
+
describe(version?: string, options?: RequestOptions): Promise<DescriptorResult>;
|
|
118
|
+
private post;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A query whose projection includes the literal paths `INCLUDE`: a query
|
|
122
|
+
* client narrows its records to them ({@link Projected}).
|
|
123
|
+
*/
|
|
124
|
+
export type Including<Q, INCLUDE extends string> = Q & {
|
|
125
|
+
readonly projection: {
|
|
126
|
+
readonly include: readonly INCLUDE[];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/** The query route of a model of an aggregate type. */
|
|
130
|
+
export declare function queryPath(type: AggregateType, model: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Queries an aggregate type's snapshots (decision D128), the default read
|
|
133
|
+
* model; only where the aggregate keeps them.
|
|
134
|
+
*
|
|
135
|
+
* @typeParam S - The state's type.
|
|
136
|
+
* @typeParam STATE_FIELDS - The `state.*` paths of the state.
|
|
137
|
+
*/
|
|
138
|
+
export declare class SnapshotQueryClient<S = unknown, STATE_FIELDS extends string = `state.${string}`> extends QueryModelClient<SnapshotRecord<S>, SnapshotSystemField | STATE_FIELDS> {
|
|
139
|
+
readonly type: AggregateType;
|
|
140
|
+
/**
|
|
141
|
+
* @param type - The aggregate type
|
|
142
|
+
* @param client - How the service is reached
|
|
143
|
+
*/
|
|
144
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Queries an aggregate type's event streams (decision D235) on the same
|
|
148
|
+
* engine as its snapshots: one record per commit, `count` counts commits, a
|
|
149
|
+
* condition on an event is an `elementMatch` on `events`, and per-event
|
|
150
|
+
* analytics expand `events` in an aggregation (`elements`). A filter need
|
|
151
|
+
* not name the aggregate, but one that does not reads the log the service
|
|
152
|
+
* appends to: the budget bounds it.
|
|
153
|
+
*
|
|
154
|
+
* @typeParam E - The events' type.
|
|
155
|
+
*/
|
|
156
|
+
export declare class EventQueryClient<E extends EventView = EventView> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {
|
|
157
|
+
readonly type: AggregateType;
|
|
158
|
+
/**
|
|
159
|
+
* @param type - The aggregate type
|
|
160
|
+
* @param client - How the service is reached
|
|
161
|
+
*/
|
|
162
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The datasets of a Wow service (decisions D75, D145): registered at run
|
|
166
|
+
* time, so not in the Manifest. Lists those the caller sees and queries
|
|
167
|
+
* each as a snapshot model is queried.
|
|
168
|
+
*/
|
|
169
|
+
export declare class DatasetClient {
|
|
170
|
+
readonly client: WowClientOptions;
|
|
171
|
+
/** @param client - How the service is reached */
|
|
172
|
+
constructor(client?: WowClientOptions);
|
|
173
|
+
/** The datasets the caller sees, by name. */
|
|
174
|
+
list(options?: RequestOptions): Promise<DatasetEntry[]>;
|
|
175
|
+
/**
|
|
176
|
+
* The query client of the dataset `context.dataset`.
|
|
177
|
+
*
|
|
178
|
+
* @typeParam R - The row's type.
|
|
179
|
+
* @typeParam FIELDS - The dataset's field paths.
|
|
180
|
+
*/
|
|
181
|
+
dataset<R = Record<string, unknown>, FIELDS extends string = string>(context: string, dataset: string): QueryModelClient<R, FIELDS>;
|
|
182
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { eventNumbers as e } from "./exactJson.es.js";
|
|
2
|
+
import { WowHeaders as t, entityTag as n, json as r, send as i } from "./http.es.js";
|
|
3
|
+
import { resumableQueryRows as a } from "./streams.es.js";
|
|
4
|
+
//#region src/queries.ts
|
|
5
|
+
var o = class {
|
|
6
|
+
constructor(e, t = {}, n) {
|
|
7
|
+
this.path = e, this.client = t, this.numbers = n;
|
|
8
|
+
}
|
|
9
|
+
get listNumbers() {
|
|
10
|
+
return this.numbers === void 0 ? void 0 : { "*": this.numbers };
|
|
11
|
+
}
|
|
12
|
+
get pageNumbers() {
|
|
13
|
+
return this.numbers === void 0 ? void 0 : { list: { "*": this.numbers } };
|
|
14
|
+
}
|
|
15
|
+
async list(e, t) {
|
|
16
|
+
return r(await this.post("list", e, t), this.listNumbers);
|
|
17
|
+
}
|
|
18
|
+
async listStream(e, t) {
|
|
19
|
+
return (await this.listStreamRows(e, t)).pipeThrough(new TransformStream({ transform(e, t) {
|
|
20
|
+
t.enqueue(e.record);
|
|
21
|
+
} }));
|
|
22
|
+
}
|
|
23
|
+
async listStreamRows(e, t = {}) {
|
|
24
|
+
let n = t.resume === !1 ? { maxRetries: 0 } : t.resume, r = e.limit ?? 0, i = (n, i) => this.post("list", r > 0 ? {
|
|
25
|
+
...e,
|
|
26
|
+
limit: r - i
|
|
27
|
+
} : e, t, "text/event-stream", n), o = await i(n?.lastEventId, 0);
|
|
28
|
+
return a(o, (e, t) => r > 0 && t >= r ? Promise.resolve(void 0) : i(e, t), {
|
|
29
|
+
...n,
|
|
30
|
+
...t.signal === void 0 ? {} : { signal: t.signal },
|
|
31
|
+
...this.numbers === void 0 ? {} : { numbers: this.numbers }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async paged(e, t) {
|
|
35
|
+
return r(await this.post("paged", e, t), this.pageNumbers);
|
|
36
|
+
}
|
|
37
|
+
async cursor(e, t) {
|
|
38
|
+
return r(await this.post("cursor", e, t), this.pageNumbers);
|
|
39
|
+
}
|
|
40
|
+
async single(e, t) {
|
|
41
|
+
return r(await this.post("single", e, t), this.numbers);
|
|
42
|
+
}
|
|
43
|
+
async count(e, t) {
|
|
44
|
+
return r(await this.post("count", e, t));
|
|
45
|
+
}
|
|
46
|
+
async aggregate(e, t) {
|
|
47
|
+
return r(await this.post("aggregate", e, t));
|
|
48
|
+
}
|
|
49
|
+
async describe(e, a) {
|
|
50
|
+
let o = await i(this.client, {
|
|
51
|
+
method: "GET",
|
|
52
|
+
path: this.path,
|
|
53
|
+
headers: { [t.IF_NONE_MATCH]: e === void 0 ? void 0 : `"${e}"` },
|
|
54
|
+
options: a,
|
|
55
|
+
notModified: !0
|
|
56
|
+
}), s = n(o);
|
|
57
|
+
return o.status === 304 ? {
|
|
58
|
+
notModified: !0,
|
|
59
|
+
version: s ?? e ?? ""
|
|
60
|
+
} : {
|
|
61
|
+
notModified: !1,
|
|
62
|
+
...s === void 0 ? {} : { version: s },
|
|
63
|
+
descriptor: await r(o)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
post(e, n, r, a, o) {
|
|
67
|
+
return i(this.client, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
path: this.path,
|
|
70
|
+
headers: {
|
|
71
|
+
Accept: a,
|
|
72
|
+
[t.LAST_EVENT_ID]: o
|
|
73
|
+
},
|
|
74
|
+
body: {
|
|
75
|
+
...n,
|
|
76
|
+
kind: e
|
|
77
|
+
},
|
|
78
|
+
options: r
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function s(e, t) {
|
|
83
|
+
return `/${e.context}/${e.name}/${t}/query`;
|
|
84
|
+
}
|
|
85
|
+
var c = class extends o {
|
|
86
|
+
constructor(e, t) {
|
|
87
|
+
super(s(e, "snapshot"), t, e.textNumbers?.state === void 0 ? void 0 : { state: e.textNumbers.state }), this.type = e;
|
|
88
|
+
}
|
|
89
|
+
}, l = class extends o {
|
|
90
|
+
constructor(t, n) {
|
|
91
|
+
let r = e(t);
|
|
92
|
+
super(s(t, "events"), n, r === void 0 ? void 0 : { events: { "*": r } }), this.type = t;
|
|
93
|
+
}
|
|
94
|
+
}, u = class {
|
|
95
|
+
constructor(e = {}) {
|
|
96
|
+
this.client = e;
|
|
97
|
+
}
|
|
98
|
+
async list(e) {
|
|
99
|
+
return r(await i(this.client, {
|
|
100
|
+
method: "GET",
|
|
101
|
+
path: "/wow/dataset",
|
|
102
|
+
options: e
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
dataset(e, t) {
|
|
106
|
+
return new o(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`, this.client);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
export { u as DatasetClient, l as EventQueryClient, o as QueryModelClient, c as SnapshotQueryClient, s as queryPath };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=queries.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.es.js","names":["QueryModelClient","path","client","numbers","json","query","options","row","resume","limit","open","received","lastEventId","first","resumableQueryRows","response","send","WowHeaders","version","tag","entityTag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","events","eventNumbers","DatasetClient","context","dataset"],"sources":["../src/queries.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationQuery } from './dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from './dsl/cursorQuery.js';\nimport type { Projected } from './dsl/projection.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type { QueryModelDescriptor } from './dsl/descriptor.js';\nimport type { FilterCapable } from './dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from './dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport {\n resumableQueryRows,\n type StreamedRow,\n type StreamResumeOptions,\n} from './streams.js';\n\n/** How a list is streamed: the request's options, and how it resumes. */\nexport interface ListStreamOptions extends RequestOptions {\n /** How the stream resumes (decision D253); `false` never resumes it. */\n readonly resume?: StreamResumeOptions | false;\n}\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145). A query written with literal `include`\n * paths answers records narrowed to them ({@link Projected}, review R4-Q,\n * Q-14).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n * @param numbers - The numbers of each record read as their exact text\n * (review R4-Q, Q-9)\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n readonly numbers?: TextNumbers,\n ) {}\n\n /** The marks of a list of records. */\n private get listNumbers(): TextNumbers | undefined {\n return this.numbers === undefined ? undefined : { '*': this.numbers };\n }\n\n /** The marks of a page of records. */\n private get pageNumbers(): TextNumbers | undefined {\n return this.numbers === undefined\n ? undefined\n : { list: { '*': this.numbers } };\n }\n\n /** The records that match, at most `limit` (the server's default when absent). */\n list<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>[]>;\n list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R[]>(await this.post('list', query, options), this.listNumbers);\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem. The\n * stream resumes where it stopped (decision D253) when the server ends it\n * to be resumed, when it is cut off and when it fails with a retryable\n * problem: see {@link StreamResumeOptions}. A `limit` counts every record\n * read, resumed or not.\n */\n listStream<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<Projected<R, INCLUDE>>>;\n listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<R>>;\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<unknown> {\n return (await this.listStreamRows(query, options)).pipeThrough(\n new TransformStream<StreamedRow<R>, R>({\n transform(row, controller) {\n controller.enqueue(row.record);\n },\n }),\n );\n }\n\n /**\n * The records that match as {@link listStream} reads them, each with its\n * position: keep the last one read to resume the stream later\n * ({@link StreamResumeOptions.lastEventId}), on another page or after a\n * restart.\n */\n listStreamRows<const INCLUDE extends FIELDS>(\n query: Including<FilterListQuery<FIELDS>, INCLUDE>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<Projected<R, INCLUDE>>>>;\n listStreamRows(\n query: FilterListQuery<FIELDS>,\n options?: ListStreamOptions,\n ): Promise<ReadableStream<StreamedRow<R>>>;\n async listStreamRows(\n query: FilterListQuery<FIELDS>,\n options: ListStreamOptions = {},\n ): Promise<ReadableStream<StreamedRow<R>>> {\n const resume =\n options.resume === false ? { maxRetries: 0 } : options.resume;\n const limit = query.limit ?? 0;\n const open = (lastEventId: string | undefined, received: number) => {\n return this.post(\n 'list',\n limit > 0 ? { ...query, limit: limit - received } : query,\n options,\n 'text/event-stream',\n lastEventId,\n );\n };\n const first = await open(resume?.lastEventId, 0);\n return resumableQueryRows<R>(\n first,\n (lastEventId, received) =>\n limit > 0 && received >= limit\n ? Promise.resolve(undefined)\n : open(lastEventId, received),\n {\n ...resume,\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n ...(this.numbers === undefined ? {} : { numbers: this.numbers }),\n },\n );\n }\n\n /** One page of the records that match, and their total. */\n paged<const INCLUDE extends FIELDS>(\n query: Including<PagedQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<PagedResult<Projected<R, INCLUDE>>>;\n paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>>;\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<PagedResult<R>>(\n await this.post('paged', query, options),\n this.pageNumbers,\n );\n }\n\n /** One page of a forward-only cursor over the records that match. */\n cursor<const INCLUDE extends FIELDS>(\n query: Including<CursorQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<CursorPage<Projected<R, INCLUDE>>>;\n cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>>;\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<CursorPage<R>>(\n await this.post('cursor', query, options),\n this.pageNumbers,\n );\n }\n\n /** The first record that matches; rejects with 404 `wow.query.not-found` when none does. */\n single<const INCLUDE extends FIELDS>(\n query: Including<FilterSingleQuery<FIELDS>, INCLUDE>,\n options?: RequestOptions,\n ): Promise<Projected<R, INCLUDE>>;\n single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R>;\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<unknown> {\n return json<R>(await this.post('single', query, options), this.numbers);\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n lastEventId?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept, [WowHeaders.LAST_EVENT_ID]: lastEventId },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/**\n * A query whose projection includes the literal paths `INCLUDE`: a query\n * client narrows its records to them ({@link Projected}).\n */\nexport type Including<Q, INCLUDE extends string> = Q & {\n readonly projection: { readonly include: readonly INCLUDE[] };\n};\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(\n queryPath(type, 'snapshot'),\n client,\n type.textNumbers?.state === undefined\n ? undefined\n : { state: type.textNumbers.state },\n );\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D235) on the same\n * engine as its snapshots: one record per commit, `count` counts commits, a\n * condition on an event is an `elementMatch` on `events`, and per-event\n * analytics expand `events` in an aggregation (`elements`). A filter need\n * not name the aggregate, but one that does not reads the log the service\n * appends to: the budget bounds it.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n const events = eventNumbers(type);\n super(\n queryPath(type, 'events'),\n client,\n events === undefined ? undefined : { events: { '*': events } },\n );\n }\n}\n\n/**\n * The datasets of a Wow service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":";;;;AA8GA,IAAaA,IAAb,MAAiE;CAO/D,YACE,GACA,IAAoC,CAAC,GACrC,GACA;EADS,AAFA,KAAA,OAAAC,GACA,KAAA,SAAAC,GACA,KAAA,UAAAC;CACR;CAGH,IAA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A,GACA;EAFS,AAGT,MACEsB,EAAUC,GAAM,UAAU,GAC1BrB,GACAqB,EAAK,aAAa,UAAU,KAAA,IACxB,KAAA,IACA,EAAE,OAAOA,EAAK,YAAY,MAAM,CACtC,GATS,KAAA,OAAAA;CAUX;AACF,GAYaG,IAAb,cAEU1B,EAAyD;CAKjE,YACE,GACA,GACA;EACA,IAAM2B,IAASC,EAAaL,CAAI;EAHvB,AAIT,MACED,EAAUC,GAAM,QAAQ,GACxBrB,GACAyB,MAAW,KAAA,IAAY,KAAA,IAAY,EAAE,QAAQ,EAAE,KAAKA,EAAO,EAAE,CAC/D,GARS,KAAA,OAAAJ;CASX;AACF,GAOaM,IAAb,MAA2B;CAEzB,YAAY,IAAoC,CAAC,GAAG;EAA/B,KAAA,SAAA3B;CAAgC;CAGrD,MAAM,KAAK,GAAmD;EAC5D,OAAOE,EACL,MAAMY,EAAK,KAAK,QAAQ;GAAE,QAAQ;GAAO,MAAM;GAAgB;EAAQ,CAAC,CAC1E;CACF;CAQA,QACE,GACA,GAC6B;EAC7B,OAAO,IAAIhB,EACT,gBAAgB,mBAAmB8B,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,SAC3E,KAAK,MACP;CACF;AACF"}
|
package/dist/state.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./exactJson.cjs"),t=require("./http.cjs");var n=class{constructor(e,t={}){this.type=e,this.client=t}async read(e,n={}){let r=n.at instanceof Date?n.at.toISOString():n.at,i=await t.send(this.client,{method:`GET`,path:this.statePath(e),query:{version:n.version,at:r,minVersion:n.minVersion},headers:{[t.WowHeaders.IF_NONE_MATCH]:n.ifNoneMatch===void 0?void 0:`"${n.ifNoneMatch}"`},options:n,notModified:!0});if(i.status===304){let e=t.entityTag(i)??n.ifNoneMatch??``;return{notModified:!0,version:Number.parseInt(e,10),etag:e}}return{notModified:!1,view:await t.json(i,this.stateNumbers),etag:t.entityTag(i)}}async get(e,t={}){let n=await this.read(e,t);if(n.notModified)throw Error(`A read without If-None-Match was answered 304.`);return n.view}async trace(e,n={}){return t.json(await t.send(this.client,{method:`GET`,path:`${this.statePath(e)}/trace`,query:{from:n.from,to:n.to,limit:n.limit},options:n}),this.traceNumbers)}get stateNumbers(){let e=this.type.textNumbers?.state;return e===void 0?void 0:{state:e}}get traceNumbers(){let t=this.type.textNumbers?.state,n=e.eventNumbers(this.type);if(t!==void 0||n!==void 0)return{commits:{"*":{...t===void 0?{}:{state:t},...n===void 0?{}:{events:{"*":n}}}}}}statePath(e){return`/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`}};exports.StateClient=n;
|
|
2
|
+
//# sourceMappingURL=state.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.cjs","names":["send","WowHeaders","entityTag","json","eventNumbers","require_exactJson","require_http","StateClient","type","client","at","options","response","id","etag","result","state","events"],"sources":["../src/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport { eventNumbers, type TextNumbers } from './exactJson.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /**\n * The latest state at this version or later (review R4-Q, Q-13: read your\n * writes), such as the `version` of a command's result: a lagging snapshot is\n * caught up with the log. Not with `version` or `at`. One not reached within\n * the server's wait rejects with 409 `wow.query.min-version-not-reached`,\n * whose `version` is the current one.\n */\n readonly minVersion?: number;\n /**\n * The entity tag of the state already held, as a read answered it\n * (`etag`): a 304 then answers `notModified`. The tag is the version and a\n * digest of the body (`3-<digest>`), so it changes whenever what is read\n * does, not only with the version.\n */\n readonly ifNoneMatch?: string;\n}\n\n/**\n * A state read: the view and its entity tag, or `notModified` when the state\n * held is current, with its tag and the version the tag names.\n */\nexport type StateReadResult<S> =\n | {\n readonly notModified: false;\n readonly view: StateView<S>;\n readonly etag?: string;\n }\n | {\n readonly notModified: true;\n readonly version: number;\n readonly etag: string;\n };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at, minVersion: options.minVersion },\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n const etag = entityTag(response) ?? options.ifNoneMatch ?? '';\n return {\n notModified: true,\n version: Number.parseInt(etag, 10),\n etag,\n };\n }\n return {\n notModified: false,\n view: await json<StateView<S>>(response, this.stateNumbers),\n etag: entityTag(response),\n };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n this.traceNumbers,\n );\n }\n\n /** The exact numbers of a state view: its state's. */\n private get stateNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n return state === undefined ? undefined : { state };\n }\n\n /** The exact numbers of a trace: each commit's state and events. */\n private get traceNumbers(): TextNumbers | undefined {\n const state = this.type.textNumbers?.state;\n const events = eventNumbers(this.type);\n if (state === undefined && events === undefined) return undefined;\n return {\n commits: {\n '*': {\n ...(state === undefined ? {} : { state }),\n ...(events === undefined ? {} : { events: { '*': events } }),\n },\n },\n };\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":"2DAuFA,IAAaO,EAAb,KAAuE,CAKrE,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,KAAA,KAAAC,EACA,KAAA,OAAAC,CACR,CAGH,MAAM,KACJ,EACA,EAA4B,CAAC,EACA,CAC7B,IAAMC,EACJC,EAAQ,cAAc,KAAOA,EAAQ,GAAG,YAAY,EAAIA,EAAQ,GAC5DC,EAAW,MAAMZ,EAAAA,KAAK,KAAK,OAAQ,CACvC,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