@gaganref/confect-server 10.3.1-fork.4 → 10.3.1-fork.41
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/dist/ActionCall.d.ts +30 -0
- package/dist/ActionCall.d.ts.map +1 -0
- package/dist/ActionCall.js +41 -0
- package/dist/ActionCall.js.map +1 -0
- package/dist/ActionCtx.d.ts +1 -1
- package/dist/ActionCtx.d.ts.map +1 -1
- package/dist/ActionCtx.js.map +1 -1
- package/dist/ActionRunner.js +2 -2
- package/dist/AiGatewayDecisionClient.d.ts +2 -2
- package/dist/AiGatewayDecisionClient.d.ts.map +1 -1
- package/dist/AiGatewayDecisionClient.js +1 -1
- package/dist/AiGatewayDecisionClient.js.map +1 -1
- package/dist/AiGatewayLanguageClient.d.ts +2 -2
- package/dist/AiGatewayLanguageClient.d.ts.map +1 -1
- package/dist/AiGatewayLanguageClient.js +1 -1
- package/dist/AiGatewayLanguageClient.js.map +1 -1
- package/dist/Auth.d.ts +14 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +13 -3
- package/dist/Auth.js.map +1 -1
- package/dist/Callback.js +3 -3
- package/dist/ComponentCtx.d.ts +1 -1
- package/dist/ComponentCtx.d.ts.map +1 -1
- package/dist/ConvexConfigProvider.js +2 -2
- package/dist/ConvexFunctionDefinitions.d.ts +4 -4
- package/dist/ConvexFunctionDefinitions.d.ts.map +1 -1
- package/dist/ConvexFunctionDefinitions.js +4 -4
- package/dist/ConvexFunctionDefinitions.js.map +1 -1
- package/dist/ConvexLogger.js +1 -1
- package/dist/CronJobs.d.ts +1 -1
- package/dist/CronJobs.d.ts.map +1 -1
- package/dist/CronJobs.js +6 -6
- package/dist/CronJobs.js.map +1 -1
- package/dist/DataModel.d.ts +3 -3
- package/dist/DataModel.d.ts.map +1 -1
- package/dist/DataModel.js.map +1 -1
- package/dist/DatabaseReader.d.ts +4 -4
- package/dist/DatabaseReader.d.ts.map +1 -1
- package/dist/DatabaseReader.js.map +1 -1
- package/dist/DatabaseSchema.d.ts +1 -1
- package/dist/DatabaseSchema.d.ts.map +1 -1
- package/dist/DatabaseSchema.js +2 -2
- package/dist/DatabaseSchema.js.map +1 -1
- package/dist/DatabaseWriter.d.ts +41 -7
- package/dist/DatabaseWriter.d.ts.map +1 -1
- package/dist/DatabaseWriter.js +55 -8
- package/dist/DatabaseWriter.js.map +1 -1
- package/dist/Document.d.ts +4 -4
- package/dist/Document.d.ts.map +1 -1
- package/dist/Document.js.map +1 -1
- package/dist/ExecutionMetadata.js +1 -1
- package/dist/FunctionImpl.d.ts +2 -2
- package/dist/FunctionImpl.d.ts.map +1 -1
- package/dist/FunctionImpl.js +2 -2
- package/dist/FunctionImpl.js.map +1 -1
- package/dist/FunctionRegistryItem.d.ts +1 -1
- package/dist/FunctionRegistryItem.d.ts.map +1 -1
- package/dist/FunctionRegistryItem.js +1 -1
- package/dist/FunctionRegistryItem.js.map +1 -1
- package/dist/GroupImpl.d.ts +24 -5
- package/dist/GroupImpl.d.ts.map +1 -1
- package/dist/GroupImpl.js +21 -22
- package/dist/GroupImpl.js.map +1 -1
- package/dist/GroupRegistry.d.ts +3 -2
- package/dist/GroupRegistry.d.ts.map +1 -1
- package/dist/GroupRegistry.js +10 -3
- package/dist/GroupRegistry.js.map +1 -1
- package/dist/Handler.d.ts +31 -27
- package/dist/Handler.d.ts.map +1 -1
- package/dist/Handler.js.map +1 -1
- package/dist/HttpRouter.d.ts +15 -13
- package/dist/HttpRouter.d.ts.map +1 -1
- package/dist/HttpRouter.js +16 -7
- package/dist/HttpRouter.js.map +1 -1
- package/dist/MiddlewareImpl.d.ts +14 -14
- package/dist/MiddlewareImpl.d.ts.map +1 -1
- package/dist/MiddlewareImpl.js +1 -1
- package/dist/MiddlewareImpl.js.map +1 -1
- package/dist/MutationCtx.d.ts +1 -1
- package/dist/MutationCtx.d.ts.map +1 -1
- package/dist/MutationCtx.js.map +1 -1
- package/dist/MutationRunner.d.ts +1 -1
- package/dist/MutationRunner.d.ts.map +1 -1
- package/dist/MutationRunner.js +2 -2
- package/dist/MutationRunner.js.map +1 -1
- package/dist/MutationTransactionContext.d.ts +2 -2
- package/dist/MutationTransactionContext.d.ts.map +1 -1
- package/dist/MutationTransactionContext.js +2 -2
- package/dist/MutationTransactionContext.js.map +1 -1
- package/dist/OfficialComponent.d.ts +50 -0
- package/dist/OfficialComponent.d.ts.map +1 -0
- package/dist/OfficialComponent.js +70 -0
- package/dist/OfficialComponent.js.map +1 -0
- package/dist/OrderedQuery.d.ts +4 -4
- package/dist/OrderedQuery.d.ts.map +1 -1
- package/dist/OrderedQuery.js.map +1 -1
- package/dist/QueryCtx.d.ts +1 -1
- package/dist/QueryCtx.d.ts.map +1 -1
- package/dist/QueryCtx.js.map +1 -1
- package/dist/QueryInitializer.d.ts +10 -10
- package/dist/QueryInitializer.d.ts.map +1 -1
- package/dist/QueryInitializer.js +2 -2
- package/dist/QueryInitializer.js.map +1 -1
- package/dist/QueryRunner.d.ts +2 -2
- package/dist/QueryRunner.d.ts.map +1 -1
- package/dist/QueryRunner.js +2 -2
- package/dist/QueryRunner.js.map +1 -1
- package/dist/QueryStream.d.ts +131 -23
- package/dist/QueryStream.d.ts.map +1 -1
- package/dist/QueryStream.js +142 -40
- package/dist/QueryStream.js.map +1 -1
- package/dist/QueryStreamCursor.d.ts +2 -2
- package/dist/QueryStreamCursor.d.ts.map +1 -1
- package/dist/QueryStreamCursor.js +1 -1
- package/dist/QueryStreamCursor.js.map +1 -1
- package/dist/QueryStreamIndexPrefix.d.ts +2 -2
- package/dist/QueryStreamIndexPrefix.d.ts.map +1 -1
- package/dist/QueryStreamIndexPrefix.js +1 -1
- package/dist/QueryStreamIndexPrefix.js.map +1 -1
- package/dist/QueryStreamIndexRange.d.ts +4 -4
- package/dist/QueryStreamIndexRange.d.ts.map +1 -1
- package/dist/QueryStreamIndexRange.js +2 -2
- package/dist/QueryStreamIndexRange.js.map +1 -1
- package/dist/QueryStreamKey.d.ts +2 -2
- package/dist/QueryStreamKey.d.ts.map +1 -1
- package/dist/QueryStreamKey.js +1 -1
- package/dist/QueryStreamKey.js.map +1 -1
- package/dist/QueryStreamKeyBounds.d.ts +3 -3
- package/dist/QueryStreamKeyBounds.d.ts.map +1 -1
- package/dist/QueryStreamKeyBounds.js +2 -2
- package/dist/QueryStreamKeyBounds.js.map +1 -1
- package/dist/QueryStreamKeyLayout.d.ts +1 -1
- package/dist/QueryStreamKeyLayout.d.ts.map +1 -1
- package/dist/QueryStreamKeyLayout.js +2 -2
- package/dist/QueryStreamKeyLayout.js.map +1 -1
- package/dist/QueryStreamKeyValues.d.ts +1 -1
- package/dist/QueryStreamKeyValues.d.ts.map +1 -1
- package/dist/QueryStreamKeyValues.js +1 -1
- package/dist/QueryStreamKeyValues.js.map +1 -1
- package/dist/QueryStreamPagination.d.ts +1 -1
- package/dist/QueryStreamPagination.d.ts.map +1 -1
- package/dist/QueryStreamPagination.js +1 -1
- package/dist/QueryStreamPagination.js.map +1 -1
- package/dist/QueryStreamReadBudget.d.ts +3 -2
- package/dist/QueryStreamReadBudget.d.ts.map +1 -1
- package/dist/QueryStreamReadBudget.js +7 -4
- package/dist/QueryStreamReadBudget.js.map +1 -1
- package/dist/QueryTransactionContext.js +2 -2
- package/dist/RegisteredConvexFunction.d.ts +27 -24
- package/dist/RegisteredConvexFunction.d.ts.map +1 -1
- package/dist/RegisteredConvexFunction.js +39 -26
- package/dist/RegisteredConvexFunction.js.map +1 -1
- package/dist/RegisteredFunction.d.ts +51 -47
- package/dist/RegisteredFunction.d.ts.map +1 -1
- package/dist/RegisteredFunction.js +126 -37
- package/dist/RegisteredFunction.js.map +1 -1
- package/dist/RegisteredFunctions.d.ts +3 -3
- package/dist/RegisteredFunctions.d.ts.map +1 -1
- package/dist/RegisteredFunctions.js.map +1 -1
- package/dist/RegisteredNodeFunction.d.ts +7 -7
- package/dist/RegisteredNodeFunction.d.ts.map +1 -1
- package/dist/RegisteredNodeFunction.js +8 -6
- package/dist/RegisteredNodeFunction.js.map +1 -1
- package/dist/Registry.d.ts +1 -1
- package/dist/Registry.d.ts.map +1 -1
- package/dist/Registry.js.map +1 -1
- package/dist/RegistryItems.d.ts +7 -0
- package/dist/RegistryItems.d.ts.map +1 -1
- package/dist/RegistryItems.js +8 -3
- package/dist/RegistryItems.js.map +1 -1
- package/dist/RequestMetadata.js +1 -1
- package/dist/ResolvedMiddleware.d.ts +2 -2
- package/dist/ResolvedMiddleware.d.ts.map +1 -1
- package/dist/ResolvedMiddleware.js.map +1 -1
- package/dist/Scheduler.js +2 -2
- package/dist/Storage.d.ts +6 -6
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +1 -1
- package/dist/Storage.js.map +1 -1
- package/dist/StorageActionWriter.d.ts +1 -1
- package/dist/StorageActionWriter.d.ts.map +1 -1
- package/dist/StorageActionWriter.js +1 -1
- package/dist/StorageActionWriter.js.map +1 -1
- package/dist/StorageReader.d.ts +1 -1
- package/dist/StorageReader.d.ts.map +1 -1
- package/dist/StorageReader.js +1 -1
- package/dist/StorageReader.js.map +1 -1
- package/dist/StorageWriter.d.ts +1 -1
- package/dist/StorageWriter.d.ts.map +1 -1
- package/dist/StorageWriter.js +1 -1
- package/dist/StorageWriter.js.map +1 -1
- package/dist/TableInfo.d.ts +2 -2
- package/dist/TableInfo.d.ts.map +1 -1
- package/dist/TableInfo.js.map +1 -1
- package/dist/TransactionMetadata.js +1 -1
- package/dist/VectorSearch.d.ts +1 -1
- package/dist/VectorSearch.d.ts.map +1 -1
- package/dist/VectorSearch.js +1 -1
- package/dist/VectorSearch.js.map +1 -1
- package/dist/index.d.ts +62 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -18
- package/dist/internal/AiGatewayDecisionClient.d.ts +1 -1
- package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -1
- package/dist/internal/AiGatewayDecisionClient.js +1 -1
- package/dist/internal/AiGatewayDecisionClient.js.map +1 -1
- package/dist/internal/AiGatewayLanguageClient.d.ts +1 -1
- package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -1
- package/dist/internal/AiGatewayLanguageClient.js +1 -1
- package/dist/internal/AiGatewayLanguageClient.js.map +1 -1
- package/dist/internal/AiGatewayServiceToken.js +1 -1
- package/dist/internal/DocumentPatch.d.ts +16 -0
- package/dist/internal/DocumentPatch.d.ts.map +1 -0
- package/dist/internal/DocumentPatch.js +36 -0
- package/dist/internal/DocumentPatch.js.map +1 -0
- package/dist/internal/observability.d.ts +5 -0
- package/dist/internal/observability.d.ts.map +1 -0
- package/dist/internal/observability.js +21 -0
- package/dist/internal/observability.js.map +1 -0
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ActionCall.ts +82 -0
- package/src/ActionCtx.ts +1 -1
- package/src/AiGatewayDecisionClient.ts +3 -3
- package/src/AiGatewayLanguageClient.ts +3 -3
- package/src/Auth.ts +24 -2
- package/src/ComponentCtx.ts +1 -1
- package/src/ConvexFunctionDefinitions.ts +10 -9
- package/src/CronJobs.ts +1 -1
- package/src/DataModel.ts +3 -3
- package/src/DatabaseReader.ts +4 -4
- package/src/DatabaseSchema.ts +1 -1
- package/src/DatabaseWriter.ts +189 -31
- package/src/Document.ts +4 -4
- package/src/FunctionImpl.ts +5 -5
- package/src/FunctionRegistryItem.ts +1 -1
- package/src/GroupImpl.ts +66 -13
- package/src/GroupRegistry.ts +11 -7
- package/src/Handler.ts +44 -28
- package/src/HttpRouter.ts +71 -21
- package/src/MiddlewareImpl.ts +17 -17
- package/src/MutationCtx.ts +1 -1
- package/src/MutationRunner.ts +1 -1
- package/src/MutationTransactionContext.ts +2 -2
- package/src/OfficialComponent.ts +151 -0
- package/src/OrderedQuery.ts +4 -4
- package/src/QueryCtx.ts +1 -1
- package/src/QueryInitializer.ts +9 -9
- package/src/QueryRunner.ts +2 -2
- package/src/QueryStream.ts +406 -76
- package/src/QueryStreamCursor.ts +3 -3
- package/src/QueryStreamIndexPrefix.ts +2 -2
- package/src/QueryStreamIndexRange.ts +4 -4
- package/src/QueryStreamKey.ts +2 -2
- package/src/QueryStreamKeyBounds.ts +3 -3
- package/src/QueryStreamKeyLayout.ts +1 -1
- package/src/QueryStreamKeyValues.ts +1 -1
- package/src/QueryStreamPagination.ts +2 -2
- package/src/QueryStreamReadBudget.ts +19 -6
- package/src/RegisteredConvexFunction.ts +38 -21
- package/src/RegisteredFunction.ts +209 -60
- package/src/RegisteredFunctions.ts +4 -4
- package/src/RegisteredNodeFunction.ts +15 -9
- package/src/Registry.ts +1 -1
- package/src/RegistryItems.ts +33 -2
- package/src/ResolvedMiddleware.ts +2 -2
- package/src/Storage.ts +3 -3
- package/src/StorageActionWriter.ts +1 -1
- package/src/StorageReader.ts +1 -1
- package/src/StorageWriter.ts +1 -1
- package/src/TableInfo.ts +2 -2
- package/src/VectorSearch.ts +1 -1
- package/src/index.ts +62 -60
- package/src/internal/AiGatewayDecisionClient.ts +2 -2
- package/src/internal/AiGatewayLanguageClient.ts +2 -2
- package/src/internal/DocumentPatch.ts +87 -0
- package/src/internal/observability.ts +27 -0
- package/src/node.ts +1 -1
package/dist/QueryStream.js
CHANGED
|
@@ -11,17 +11,17 @@ import { admittedByLower, admittedByUpper, forLayout, fromParsed, intersect, int
|
|
|
11
11
|
import { apply, equalityPrefixLength, fromBounds, toBounds as toBounds$1 } from "./QueryStreamIndexRange.js";
|
|
12
12
|
import { EmptyInitialPageError, InvalidPageSizeError, Range, Start, finish, initial, parseRequest, record } from "./QueryStreamPagination.js";
|
|
13
13
|
import { InvalidReadLimitError, Limits, QueryStreamReadBudget, make as make$1 } from "./QueryStreamReadBudget.js";
|
|
14
|
+
import * as Data from "effect/Data";
|
|
14
15
|
import * as Effect from "effect/Effect";
|
|
16
|
+
import * as Predicate from "effect/Predicate";
|
|
17
|
+
import * as Array from "effect/Array";
|
|
15
18
|
import * as Schema from "effect/Schema";
|
|
16
19
|
import { dual, identity, pipe } from "effect/Function";
|
|
17
20
|
import * as Match from "effect/Match";
|
|
18
21
|
import * as Option from "effect/Option";
|
|
19
22
|
import { ConvexError } from "convex/values";
|
|
20
|
-
import * as Array from "effect/Array";
|
|
21
23
|
import * as Order from "effect/Order";
|
|
22
|
-
import * as Predicate from "effect/Predicate";
|
|
23
24
|
import * as Result from "effect/Result";
|
|
24
|
-
import * as Data from "effect/Data";
|
|
25
25
|
import * as Stream from "effect/Stream";
|
|
26
26
|
import { pipeArguments } from "effect/Pipeable";
|
|
27
27
|
import * as Chunk from "effect/Chunk";
|
|
@@ -32,6 +32,8 @@ import * as String from "effect/String";
|
|
|
32
32
|
import * as Tuple from "effect/Tuple";
|
|
33
33
|
//#region src/QueryStream.ts
|
|
34
34
|
var QueryStream_exports = /* @__PURE__ */ __exportAll({
|
|
35
|
+
DEFAULT_MAXIMUM_ROWS_READ: () => DEFAULT_MAXIMUM_ROWS_READ,
|
|
36
|
+
DeferredStreamMismatchError: () => DeferredStreamMismatchError,
|
|
35
37
|
Element: () => Element,
|
|
36
38
|
EmptyInitialPageError: () => EmptyInitialPageError,
|
|
37
39
|
IncompatibleStreamsError: () => IncompatibleStreamsError,
|
|
@@ -44,6 +46,8 @@ var QueryStream_exports = /* @__PURE__ */ __exportAll({
|
|
|
44
46
|
QueryStream: () => QueryStream,
|
|
45
47
|
ReadBudgetExceededError: () => ReadBudgetExceededError,
|
|
46
48
|
TypeId: () => TypeId,
|
|
49
|
+
collect: () => collect,
|
|
50
|
+
defer: () => defer,
|
|
47
51
|
distinct: () => distinct,
|
|
48
52
|
empty: () => empty,
|
|
49
53
|
filter: () => filter,
|
|
@@ -61,7 +65,15 @@ var QueryStream_exports = /* @__PURE__ */ __exportAll({
|
|
|
61
65
|
unique: () => unique
|
|
62
66
|
});
|
|
63
67
|
/**
|
|
64
|
-
*
|
|
68
|
+
* Default physical row budget for `paginate` and `collect`. Supply an explicit
|
|
69
|
+
* `maximumRowsRead` to override it. Plain Effect Stream consumers use their
|
|
70
|
+
* enclosing budget and remain unlimited when none is provided.
|
|
71
|
+
*
|
|
72
|
+
* @experimental
|
|
73
|
+
*/
|
|
74
|
+
const DEFAULT_MAXIMUM_ROWS_READ = 2e3;
|
|
75
|
+
/**
|
|
76
|
+
* A query stream exhausted its read budget before its consumer could finish.
|
|
65
77
|
*
|
|
66
78
|
* @experimental
|
|
67
79
|
*/
|
|
@@ -70,7 +82,7 @@ var ReadBudgetExceededError = class extends Schema.TaggedError()("ReadBudgetExce
|
|
|
70
82
|
bytesRead: Schema.Natural
|
|
71
83
|
}) {
|
|
72
84
|
get message() {
|
|
73
|
-
return "The read budget was exhausted before
|
|
85
|
+
return "The read budget was exhausted before the query stream completed; increase the budget or simplify the query";
|
|
74
86
|
}
|
|
75
87
|
};
|
|
76
88
|
/**
|
|
@@ -234,6 +246,40 @@ const empty = () => (keyLayout, orderDirection = "asc") => {
|
|
|
234
246
|
return make(orderDirection);
|
|
235
247
|
};
|
|
236
248
|
/**
|
|
249
|
+
* A deferred stream's resolved direction or layout differs from its
|
|
250
|
+
* declaration. The check runs on consumption, before the resolved source is
|
|
251
|
+
* pulled.
|
|
252
|
+
*
|
|
253
|
+
* @experimental
|
|
254
|
+
*/
|
|
255
|
+
var DeferredStreamMismatchError = class extends Data.TaggedError("DeferredStreamMismatchError") {};
|
|
256
|
+
/**
|
|
257
|
+
* Defer an effect that checks access or constructs a query stream until it is
|
|
258
|
+
* pulled. Supply its layout and direction without reading documents. This lets
|
|
259
|
+
* `flatMap` build and narrow an inner stream before running its checks.
|
|
260
|
+
*
|
|
261
|
+
* The effect runs afresh on each consumption, seek, or reversal. Failures and
|
|
262
|
+
* service requirements are preserved. Its stream must match the declared layout
|
|
263
|
+
* and direction, or consumption dies with `DeferredStreamMismatchError`.
|
|
264
|
+
*
|
|
265
|
+
* @experimental
|
|
266
|
+
*/
|
|
267
|
+
const defer = (options, make) => {
|
|
268
|
+
const checked = Effect.map(make, (stream) => {
|
|
269
|
+
if (stream.orderDirection !== options.orderDirection || !Equivalence(stream.keyLayout, options.keyLayout)) throw new DeferredStreamMismatchError({
|
|
270
|
+
expectedOrderDirection: options.orderDirection,
|
|
271
|
+
actualOrderDirection: stream.orderDirection,
|
|
272
|
+
expectedKeyLayout: options.keyLayout,
|
|
273
|
+
actualKeyLayout: stream.keyLayout
|
|
274
|
+
});
|
|
275
|
+
return stream;
|
|
276
|
+
});
|
|
277
|
+
return new QueryStream(options.orderDirection, options.keyLayout, Stream.unwrap(Effect.map(checked, (stream) => stream.annotated)), void 0, (bounds) => defer(options, Effect.map(checked, (stream) => narrowByParsedBounds(stream, bounds))), () => defer({
|
|
278
|
+
...options,
|
|
279
|
+
orderDirection: flip(options.orderDirection)
|
|
280
|
+
}, Effect.map(checked, reverse)));
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
237
283
|
* Create a reusable query stream from an index-query description. Prefer
|
|
238
284
|
* `reader.table(...).stream(...)` for inferred document and ordering types.
|
|
239
285
|
*
|
|
@@ -297,13 +343,21 @@ const fillMergeSource = (source) => MergeSource.$match(source, {
|
|
|
297
343
|
Exhausted: () => Effect.succeed(source),
|
|
298
344
|
BudgetLimited: () => Effect.succeed(source)
|
|
299
345
|
});
|
|
346
|
+
const consumeMergeHead = (source) => source._tag === "Buffered" ? Option.match(Chunk.head(source.tail), {
|
|
347
|
+
onNone: () => MergeSource.NeedsPull({ pull: source.pull }),
|
|
348
|
+
onSome: (head) => MergeSource.Buffered({
|
|
349
|
+
pull: source.pull,
|
|
350
|
+
head,
|
|
351
|
+
tail: Chunk.drop(source.tail, 1)
|
|
352
|
+
})
|
|
353
|
+
}) : source;
|
|
300
354
|
/**
|
|
301
355
|
* One step of the k-way merge as a pure unfold: fill every source, emit the
|
|
302
356
|
* earliest head (ties go to the earliest source, keeping the merge stable), and
|
|
303
357
|
* return the sources with that head consumed. `undefined` when every source is
|
|
304
358
|
* exhausted or an input stopped before its next key was known.
|
|
305
359
|
*/
|
|
306
|
-
const mergeStep = (keyOrder) => (sources) => Effect.gen(function* () {
|
|
360
|
+
const mergeStep = (keyOrder, dedupe) => (sources) => Effect.gen(function* () {
|
|
307
361
|
const readBudget = yield* QueryStreamReadBudget;
|
|
308
362
|
const filled = yield* Effect.forEach(sources, fillMergeSource, { concurrency: (yield* readBudget.isUnlimited) ? "unbounded" : 1 });
|
|
309
363
|
if (filled.some((source) => MergeSource.$is("BudgetLimited")(source))) return void 0;
|
|
@@ -321,23 +375,35 @@ const mergeStep = (keyOrder) => (sources) => Effect.gen(function* () {
|
|
|
321
375
|
})) : best
|
|
322
376
|
})
|
|
323
377
|
}));
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
378
|
+
if (Option.isNone(earliest)) return void 0;
|
|
379
|
+
if (!dedupe) {
|
|
380
|
+
const { index, element } = earliest.value;
|
|
381
|
+
return Tuple.make(element, Array.map(filled, (source, sourceIndex) => sourceIndex === index ? consumeMergeHead(source) : source));
|
|
382
|
+
}
|
|
383
|
+
const keyValues = earliest.value.element.keyValues;
|
|
384
|
+
const matches = (source) => source._tag === "Buffered" && keyOrder(source.head.keyValues, keyValues) === 0;
|
|
385
|
+
let representative = earliest.value;
|
|
386
|
+
let remaining = filled;
|
|
387
|
+
for (;;) {
|
|
388
|
+
representative = Array.reduce(remaining, representative, (best, source, index) => source._tag === "Buffered" && matches(source) && Option.isSome(source.head.doc) && (Option.isNone(best.element.doc) || index < best.index) ? new MergeCandidate({
|
|
389
|
+
index,
|
|
390
|
+
element: source.head
|
|
391
|
+
}) : best);
|
|
392
|
+
remaining = yield* Effect.forEach(Array.map(remaining, (source) => matches(source) ? consumeMergeHead(source) : source), fillMergeSource, { concurrency: (yield* readBudget.isUnlimited) ? "unbounded" : 1 });
|
|
393
|
+
if (remaining.some((source) => MergeSource.$is("BudgetLimited")(source))) return void 0;
|
|
394
|
+
if (!remaining.some(matches)) return Tuple.make(representative.element, remaining);
|
|
395
|
+
}
|
|
332
396
|
});
|
|
333
397
|
/**
|
|
334
398
|
* Combine streams sharing a key layout into one stream in key order. Use this
|
|
335
399
|
* to query several index ranges at once, such as notes by multiple roles.
|
|
336
400
|
*
|
|
337
401
|
* The merge emits the smallest next key when ascending and the largest when
|
|
338
|
-
* descending. Unlike `Stream.merge`, it does not interleave by arrival time.
|
|
339
|
-
*
|
|
340
|
-
*
|
|
402
|
+
* descending. Unlike `Stream.merge`, it does not interleave by arrival time. By
|
|
403
|
+
* default, a document matched twice appears twice. Pass `{ dedupe: true }` to
|
|
404
|
+
* coalesce equal complete keys, including ID tiebreakers. Resolving a group can
|
|
405
|
+
* prefetch the next key from each input; all such reads count against the
|
|
406
|
+
* shared budget. Supply at least one input; use `empty` for an empty list.
|
|
341
407
|
*
|
|
342
408
|
* Inputs need compatible document types and identical key layouts and
|
|
343
409
|
* directions. TypeScript rejects known mismatches; runtime mismatches throw
|
|
@@ -346,7 +412,7 @@ const mergeStep = (keyOrder) => (sources) => Effect.gen(function* () {
|
|
|
346
412
|
*
|
|
347
413
|
* @experimental
|
|
348
414
|
*/
|
|
349
|
-
const merge = (streams) => {
|
|
415
|
+
const merge = (streams, options) => {
|
|
350
416
|
const head = Array.headNonEmpty(streams);
|
|
351
417
|
const incompatible = Array.findFirst(Array.tailNonEmpty(streams), (stream) => stream.orderDirection !== head.orderDirection || !Equivalence(stream.keyLayout, head.keyLayout));
|
|
352
418
|
if (Option.isSome(incompatible)) throw new IncompatibleStreamsError({
|
|
@@ -355,17 +421,17 @@ const merge = (streams) => {
|
|
|
355
421
|
expectedKeyLayout: head.keyLayout,
|
|
356
422
|
actualKeyLayout: incompatible.value.keyLayout
|
|
357
423
|
});
|
|
358
|
-
return mergeUnchecked(streams);
|
|
424
|
+
return mergeUnchecked(streams, options);
|
|
359
425
|
};
|
|
360
426
|
/**
|
|
361
427
|
* `merge` without the compatibility check—for re-merging branches that were
|
|
362
428
|
* validated when the merge was built (narrowing never changes a branch's order
|
|
363
429
|
* or key layout).
|
|
364
430
|
*/
|
|
365
|
-
const mergeUnchecked = (streams) => {
|
|
431
|
+
const mergeUnchecked = (streams, options) => {
|
|
366
432
|
const head = Array.headNonEmpty(streams);
|
|
367
|
-
const annotated = Stream.unwrap(Effect.map(Effect.forEach(streams, (stream) => Stream.toPull(stream.annotated)), (pulls) => Stream.unfold(Array.map(pulls, (pull) => MergeSource.NeedsPull({ pull })), mergeStep(Order$1(head.orderDirection)))));
|
|
368
|
-
return new QueryStream(head.orderDirection, head.keyLayout, annotated, void 0, (parsedBounds) => mergeUnchecked([narrowByParsedBounds(head, parsedBounds), ...Array.map(Array.tailNonEmpty(streams), (stream) => narrowByParsedBounds(stream, parsedBounds))]), () => mergeUnchecked([reverse(head), ...Array.map(Array.tailNonEmpty(streams), (stream) => reverse(stream))]));
|
|
433
|
+
const annotated = Stream.unwrap(Effect.map(Effect.forEach(streams, (stream) => Stream.toPull(stream.annotated)), (pulls) => Stream.unfold(Array.map(pulls, (pull) => MergeSource.NeedsPull({ pull })), mergeStep(Order$1(head.orderDirection), options?.dedupe === true))));
|
|
434
|
+
return new QueryStream(head.orderDirection, head.keyLayout, annotated, void 0, (parsedBounds) => mergeUnchecked([narrowByParsedBounds(head, parsedBounds), ...Array.map(Array.tailNonEmpty(streams), (stream) => narrowByParsedBounds(stream, parsedBounds))], options), () => mergeUnchecked([reverse(head), ...Array.map(Array.tailNonEmpty(streams), (stream) => reverse(stream))], options));
|
|
369
435
|
};
|
|
370
436
|
/**
|
|
371
437
|
* Derive a stream by transforming each present document into `Some` (keep,
|
|
@@ -782,10 +848,10 @@ const narrowByParsedBounds = (self, parsedBounds) => {
|
|
|
782
848
|
* The fallback for streams that don't know how to rebuild themselves.
|
|
783
849
|
*/
|
|
784
850
|
const keyPredicates = (parsedBounds) => {
|
|
785
|
-
const complete$
|
|
851
|
+
const complete$2 = (keyValues) => Result.getOrThrowWith(complete(parsedBounds.keyLayout, keyValues), identity);
|
|
786
852
|
return {
|
|
787
|
-
aboveLower: (keyValues) => Result.getOrThrowWith(admittedByLower(parsedBounds)(complete$
|
|
788
|
-
belowUpper: (keyValues) => Result.getOrThrowWith(admittedByUpper(parsedBounds)(complete$
|
|
853
|
+
aboveLower: (keyValues) => Result.getOrThrowWith(admittedByLower(parsedBounds)(complete$2(keyValues)), identity),
|
|
854
|
+
belowUpper: (keyValues) => Result.getOrThrowWith(admittedByUpper(parsedBounds)(complete$2(keyValues)), identity)
|
|
789
855
|
};
|
|
790
856
|
};
|
|
791
857
|
const narrowInMemory = (self, parsedBounds) => {
|
|
@@ -795,6 +861,30 @@ const narrowInMemory = (self, parsedBounds) => {
|
|
|
795
861
|
return new QueryStream(self.orderDirection, self.keyLayout, pipe(self.annotated, dropOutOfRange, takeInRange), void 0, void 0, self.reverseWith === void 0 ? void 0 : () => narrowInMemory(reverse(self), parsedBounds));
|
|
796
862
|
};
|
|
797
863
|
/**
|
|
864
|
+
* Collect the whole query stream or fail with `ReadBudgetExceededError` when a
|
|
865
|
+
* read budget stops it. No partial array reaches the caller. Arbitrary I/O in
|
|
866
|
+
* callbacks is not counted. Use `paginate` for data that can grow without
|
|
867
|
+
* bound.
|
|
868
|
+
*
|
|
869
|
+
* With explicit options, each run gets a fresh budget. Without options, use the
|
|
870
|
+
* enclosing budget if present, or the default row budget.
|
|
871
|
+
*
|
|
872
|
+
* @experimental
|
|
873
|
+
*/
|
|
874
|
+
const collect = dual((args) => isQueryStream(args[0]), Effect.fn("QueryStream.collect")(function* (self, options) {
|
|
875
|
+
const makeBudget = Schema.decodeEffect(Limits)({
|
|
876
|
+
maximumRowsRead: DEFAULT_MAXIMUM_ROWS_READ,
|
|
877
|
+
...options
|
|
878
|
+
}).pipe(Effect.catchTag("SchemaError", (cause) => Effect.die(new InvalidReadLimitError({ cause }))), Effect.flatMap(make$1));
|
|
879
|
+
const budget = yield* options === void 0 ? Effect.serviceOption(QueryStreamReadBudget).pipe(Effect.flatMap(Option.match({
|
|
880
|
+
onNone: () => makeBudget,
|
|
881
|
+
onSome: Effect.succeed
|
|
882
|
+
}))) : makeBudget;
|
|
883
|
+
const rows = yield* Stream.runCollect(self.toStream()).pipe(Effect.provideService(QueryStreamReadBudget, budget));
|
|
884
|
+
if (yield* budget.isStopped) return yield* new ReadBudgetExceededError(yield* budget.getReadCounts);
|
|
885
|
+
return rows;
|
|
886
|
+
}));
|
|
887
|
+
/**
|
|
798
888
|
* `unique` found at least two emitted values. Narrow the query if at most one
|
|
799
889
|
* value was expected, or use another consumer to handle multiple results.
|
|
800
890
|
*
|
|
@@ -846,9 +936,9 @@ const unique = Effect.fn("QueryStream.unique")((self) => self.pipe(Stream.take(2
|
|
|
846
936
|
* query semantics change, even if an old cursor is still accepted.
|
|
847
937
|
*
|
|
848
938
|
* Cursors expose boundary field names and key values, including document IDs.
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
939
|
+
* Without a `cursorEnvelope`, clients can read or craft them. Do not publicly
|
|
940
|
+
* paginate over sensitive indexed fields unless pinned with `eq`. Never
|
|
941
|
+
* construct cursors from documents or decode them into `narrow` bounds.
|
|
852
942
|
*
|
|
853
943
|
* Return the whole result to reactive clients. React's
|
|
854
944
|
* `useStreamPaginatedQuery` handles pinning, splitting, and invalid-cursor
|
|
@@ -858,19 +948,28 @@ const unique = Effect.fn("QueryStream.unique")((self) => self.pipe(Stream.take(2
|
|
|
858
948
|
* @experimental
|
|
859
949
|
*/
|
|
860
950
|
const paginate = dual(2, Effect.fn("QueryStream.paginate")(function* (self, options) {
|
|
951
|
+
const seal = (cursor) => options.cursorEnvelope === void 0 ? Effect.succeed(cursor) : options.cursorEnvelope.seal(cursor);
|
|
952
|
+
const open = (cursor) => options.cursorEnvelope === void 0 ? Effect.succeed(cursor) : options.cursorEnvelope.open(cursor).pipe(Effect.flatMap(Option.match({
|
|
953
|
+
onNone: () => Effect.die(new ConvexError({ paginationError: "InvalidCursor" })),
|
|
954
|
+
onSome: Effect.succeed
|
|
955
|
+
})));
|
|
956
|
+
const opened = yield* Effect.all({
|
|
957
|
+
start: options.cursor === null ? Effect.succeed(null) : open(options.cursor),
|
|
958
|
+
end: options.endCursor == null ? Effect.succeed(null) : open(options.endCursor)
|
|
959
|
+
});
|
|
861
960
|
const cursorSchema = fromKeyLayout(self.keyLayout);
|
|
862
961
|
const encodeCursor = Schema.encodeEffect(cursorSchema);
|
|
863
962
|
const decodeCursor = Schema.decodeEffect(cursorSchema);
|
|
864
|
-
const complete$
|
|
963
|
+
const complete$1 = (keyValues) => Result.getOrThrowWith(complete(self.keyLayout, keyValues), identity);
|
|
865
964
|
const decoded = yield* Effect.all({
|
|
866
|
-
start: Option.match(Option.fromNullOr(
|
|
965
|
+
start: Option.match(Option.fromNullOr(opened.start), {
|
|
867
966
|
onNone: () => Effect.succeed(Start.Beginning()),
|
|
868
967
|
onSome: (cursor) => Effect.map(decodeCursor(cursor), (key) => Start.After({
|
|
869
968
|
cursor,
|
|
870
969
|
key
|
|
871
970
|
}))
|
|
872
971
|
}),
|
|
873
|
-
range: Option.match(Option.fromNullishOr(
|
|
972
|
+
range: Option.match(Option.fromNullishOr(opened.end), {
|
|
874
973
|
onNone: () => Effect.succeed(Range.Unpinned()),
|
|
875
974
|
onSome: (cursor) => cursor === "[]" ? Effect.succeed(Range.ThroughEnd()) : Effect.map(decodeCursor(cursor), (key) => Range.ThroughKey({ key }))
|
|
876
975
|
})
|
|
@@ -882,7 +981,7 @@ const paginate = dual(2, Effect.fn("QueryStream.paginate")(function* (self, opti
|
|
|
882
981
|
if (request._tag === "Unchanged") return {
|
|
883
982
|
page: [],
|
|
884
983
|
isDone: false,
|
|
885
|
-
continueCursor: request.cursor
|
|
984
|
+
continueCursor: yield* seal(request.cursor)
|
|
886
985
|
};
|
|
887
986
|
const start = Option.map(request.after, (key) => ({
|
|
888
987
|
key: toPrefix(key),
|
|
@@ -904,14 +1003,14 @@ const paginate = dual(2, Effect.fn("QueryStream.paginate")(function* (self, opti
|
|
|
904
1003
|
upper: start
|
|
905
1004
|
}), identity));
|
|
906
1005
|
const readBudget = yield* QueryStreamReadBudget;
|
|
907
|
-
const collected = yield* Stream.run(narrowed.annotated, Sink.fold(() => initial(), (state) => state._tag === "Reading", (state, { doc, keyValues }) => Effect.map(readBudget.
|
|
1006
|
+
const collected = yield* Stream.run(narrowed.annotated, Sink.fold(() => initial(), (state) => state._tag === "Reading", (state, { doc, keyValues }) => Effect.map(readBudget.isStopped, (hitLimit) => record(request, state, doc, complete$1(keyValues), hitLimit))));
|
|
908
1007
|
const stopped = yield* readBudget.isStopped;
|
|
909
1008
|
const outcome = finish(request, collected, stopped);
|
|
910
1009
|
if (Result.isFailure(outcome)) return yield* new ReadBudgetExceededError(yield* readBudget.getReadCounts);
|
|
911
|
-
const encode = (key) => encodeCursor(key).pipe(Effect.catchTag("SchemaError", Effect.die));
|
|
1010
|
+
const encode = (key) => encodeCursor(key).pipe(Effect.catchTag("SchemaError", Effect.die), Effect.flatMap(seal));
|
|
912
1011
|
const encodeSplit = (result) => Effect.gen(function* () {
|
|
913
1012
|
const continueCursor = yield* Match.value(result.continuation).pipe(Match.tagsExhaustive({
|
|
914
|
-
End: () =>
|
|
1013
|
+
End: () => seal("[]"),
|
|
915
1014
|
Key: ({ key }) => encode(key)
|
|
916
1015
|
}));
|
|
917
1016
|
return {
|
|
@@ -923,11 +1022,11 @@ const paginate = dual(2, Effect.fn("QueryStream.paginate")(function* (self, opti
|
|
|
923
1022
|
};
|
|
924
1023
|
});
|
|
925
1024
|
return yield* Match.value(outcome.success).pipe(Match.tagsExhaustive({
|
|
926
|
-
Done: ({ page }) => Effect.
|
|
1025
|
+
Done: ({ page }) => Effect.map(seal("[]"), (continueCursor) => ({
|
|
927
1026
|
page: Array.fromIterable(page),
|
|
928
1027
|
isDone: true,
|
|
929
|
-
continueCursor
|
|
930
|
-
}),
|
|
1028
|
+
continueCursor
|
|
1029
|
+
})),
|
|
931
1030
|
Continue: ({ page, key }) => Effect.map(encode(key), (continueCursor) => ({
|
|
932
1031
|
page: Array.fromIterable(page),
|
|
933
1032
|
isDone: false,
|
|
@@ -936,8 +1035,11 @@ const paginate = dual(2, Effect.fn("QueryStream.paginate")(function* (self, opti
|
|
|
936
1035
|
SplitRequired: encodeSplit,
|
|
937
1036
|
SplitRecommended: encodeSplit
|
|
938
1037
|
}));
|
|
939
|
-
}, (effect, _self, options) => Effect.provideServiceEffect(effect, QueryStreamReadBudget, Schema.decodeEffect(Limits)(
|
|
1038
|
+
}, (effect, _self, options) => Effect.provideServiceEffect(effect, QueryStreamReadBudget, Schema.decodeEffect(Limits)({
|
|
1039
|
+
maximumRowsRead: DEFAULT_MAXIMUM_ROWS_READ,
|
|
1040
|
+
...options
|
|
1041
|
+
}).pipe(Effect.catchTag("SchemaError", (cause) => Effect.die(new InvalidReadLimitError({ cause }))), Effect.flatMap(make$1)))));
|
|
940
1042
|
//#endregion
|
|
941
|
-
export { Element, EmptyInitialPageError, IncompatibleStreamsError, InnerStreamLayoutMismatchError, InnerStreamOrderMismatchError, InvalidPageSizeError, InvalidReadLimitError, MissingReversalRecipeError, NotUniqueError, QueryStream, QueryStream_exports, ReadBudgetExceededError, TypeId, distinct, empty, filter, filterEffect, flatMap, fromReflection, isQueryStream, map, mapEffect, merge, narrow, paginate, renameKey, reverse, unique };
|
|
1043
|
+
export { DEFAULT_MAXIMUM_ROWS_READ, DeferredStreamMismatchError, Element, EmptyInitialPageError, IncompatibleStreamsError, InnerStreamLayoutMismatchError, InnerStreamOrderMismatchError, InvalidPageSizeError, InvalidReadLimitError, MissingReversalRecipeError, NotUniqueError, QueryStream, QueryStream_exports, ReadBudgetExceededError, TypeId, collect, defer, distinct, empty, filter, filterEffect, flatMap, fromReflection, isQueryStream, map, mapEffect, merge, narrow, paginate, renameKey, reverse, unique };
|
|
942
1044
|
|
|
943
1045
|
//# sourceMappingURL=QueryStream.js.map
|