@powerhousedao/reactor 6.2.2-dev.2 → 6.2.2-dev.21
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/{build-worker-executor-BDrPlCJl.js → build-worker-executor-CE-Yyezb.js} +3 -3
- package/dist/{build-worker-executor-BDrPlCJl.js.map → build-worker-executor-CE-Yyezb.js.map} +1 -1
- package/dist/{document-indexer-FGJmRAdX.js → document-indexer-BY-mPXJF.js} +10 -3
- package/dist/document-indexer-BY-mPXJF.js.map +1 -0
- package/dist/{drive-container-types-DpJp2AmE.js → drive-container-types-DrQMmpCa.js} +156 -40
- package/dist/drive-container-types-DrQMmpCa.js.map +1 -0
- package/dist/entry.js +2 -2
- package/dist/index.d.ts +221 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +326 -117
- package/dist/index.js.map +1 -1
- package/dist/projection-entry.js +3 -3
- package/dist/{worker-DBJOv8Gp.js → worker-BEzk4Q1I.js} +2 -2
- package/dist/{worker-DBJOv8Gp.js.map → worker-BEzk4Q1I.js.map} +1 -1
- package/dist/worker-handle-B1w03nRA.js.map +1 -1
- package/package.json +4 -4
- package/dist/document-indexer-FGJmRAdX.js.map +0 -1
- package/dist/drive-container-types-DpJp2AmE.js.map +0 -1
package/dist/entry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as instrumentPgPool } from "./drive-container-types-
|
|
1
|
+
import { o as instrumentPgPool } from "./drive-container-types-DrQMmpCa.js";
|
|
2
2
|
import { n as errorToInfo, t as createForwardingLogger } from "./forwarding-logger-BBkMSxuJ.js";
|
|
3
|
-
import { n as defaultLoadFactory, t as buildWorkerExecutor } from "./build-worker-executor-
|
|
3
|
+
import { n as defaultLoadFactory, t as buildWorkerExecutor } from "./build-worker-executor-CE-Yyezb.js";
|
|
4
4
|
import { ConsoleLogger } from "document-model";
|
|
5
5
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
6
6
|
//#region src/executor/worker/run-worker.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action, CreateDocumentActionInput, DocumentModelModule, ISigner, Operation, OperationContext, OperationWithContext, OperationWithContext as OperationWithContext$1, PHDocument, PHDocumentState, SignatureVerificationHandler, UpgradeDocumentActionInput, UpgradeManifest, UpgradeReducer, UpgradeTransition, actions as documentActions } from "@powerhousedao/shared/document-model";
|
|
1
|
+
import { Action, AuthDecision, AuthRequest, AuthSubject, CreateDocumentActionInput, DocumentModelModule, ISigner, Operation, OperationContext, OperationWithContext, OperationWithContext as OperationWithContext$1, PHDocument, PHDocumentState, SignatureVerificationHandler, UpgradeDocumentActionInput, UpgradeManifest, UpgradeReducer, UpgradeTransition, actions as documentActions } from "@powerhousedao/shared/document-model";
|
|
2
2
|
import { DocumentDriveDocument, DriveInput, FolderNode, Node } from "@powerhousedao/shared/document-drive";
|
|
3
3
|
import { ILogger } from "document-model";
|
|
4
4
|
import * as kysely from "kysely";
|
|
@@ -69,6 +69,17 @@ declare enum JobQueueState {
|
|
|
69
69
|
RUNNING = 3,
|
|
70
70
|
RESOLVED = 4
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* How a retry is accounted against the job's retry limit.
|
|
74
|
+
* - `CountAgainstLimit` (default): a fault; the job eventually exhausts its
|
|
75
|
+
* retries and fails terminally.
|
|
76
|
+
* - `ExemptFromLimit`: not a fault, so the attempt is not charged to the job.
|
|
77
|
+
* Used for concurrency conflicts, where the retry does new work.
|
|
78
|
+
*/
|
|
79
|
+
declare enum RetryAccounting {
|
|
80
|
+
CountAgainstLimit = "count-against-limit",
|
|
81
|
+
ExemptFromLimit = "exempt-from-limit"
|
|
82
|
+
}
|
|
72
83
|
/**
|
|
73
84
|
* Interface for a job execution handle
|
|
74
85
|
*/
|
|
@@ -230,6 +241,11 @@ type ViewFilter = {
|
|
|
230
241
|
branch?: string;
|
|
231
242
|
scopes?: string[];
|
|
232
243
|
revision?: number;
|
|
244
|
+
/**
|
|
245
|
+
* Read subject for the IReactorClient read gate; defaults to the client's
|
|
246
|
+
* signer. Set per request when serving many principals. Ignored by IReactor.
|
|
247
|
+
*/
|
|
248
|
+
subject?: AuthSubject;
|
|
233
249
|
};
|
|
234
250
|
/**
|
|
235
251
|
* Describes filter options for searching documents.
|
|
@@ -328,6 +344,16 @@ interface IReadModelCoordinator {
|
|
|
328
344
|
*/
|
|
329
345
|
getChainDepth(): number;
|
|
330
346
|
}
|
|
347
|
+
type ReadModelRegistrationStage = "pre_ready" | "post_ready";
|
|
348
|
+
/**
|
|
349
|
+
* Optional capability exposed by coordinators that support adding read models
|
|
350
|
+
* after construction. Custom and remote coordinators are not required to
|
|
351
|
+
* implement it.
|
|
352
|
+
*/
|
|
353
|
+
interface ILiveReadModelCoordinator extends IReadModelCoordinator {
|
|
354
|
+
addReadModel(readModel: IReadModel, stage: ReadModelRegistrationStage): void;
|
|
355
|
+
}
|
|
356
|
+
declare function supportsLiveReadModelRegistration(coordinator: IReadModelCoordinator): coordinator is ILiveReadModelCoordinator;
|
|
331
357
|
//#endregion
|
|
332
358
|
//#region src/sync/types.d.ts
|
|
333
359
|
declare enum ChannelScheme {
|
|
@@ -537,6 +563,32 @@ declare class OptimisticLockError extends Error {
|
|
|
537
563
|
declare class RevisionMismatchError extends Error {
|
|
538
564
|
constructor(expected: number, actual: number);
|
|
539
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* One read-set stream and the highest operation index observed on it, or -1
|
|
568
|
+
* if it was observed empty.
|
|
569
|
+
*/
|
|
570
|
+
type AppendConditionStream = {
|
|
571
|
+
documentId: string;
|
|
572
|
+
scope: string;
|
|
573
|
+
branch: string;
|
|
574
|
+
revision: number;
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* A read-set enforced by {@link IOperationStore.apply}: the append fails if
|
|
578
|
+
* any stream has operations past its recorded revision.
|
|
579
|
+
*/
|
|
580
|
+
type AppendCondition = {
|
|
581
|
+
streams: AppendConditionStream[];
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* A read-set stream grew before the append committed. A concurrency
|
|
585
|
+
* conflict, not a fault: the caller retries against the new stream heads.
|
|
586
|
+
*/
|
|
587
|
+
declare class AppendConditionFailedError extends Error {
|
|
588
|
+
readonly condition: AppendCondition;
|
|
589
|
+
constructor(condition: AppendCondition);
|
|
590
|
+
static isError(error: unknown): error is AppendConditionFailedError;
|
|
591
|
+
}
|
|
540
592
|
/**
|
|
541
593
|
* A write transaction passed to {@link IOperationStore.apply}. Accumulates
|
|
542
594
|
* operations that are committed atomically when the callback returns.
|
|
@@ -571,6 +623,12 @@ interface IOperationStore {
|
|
|
571
623
|
* returned instead of throwing. If no matching stored row is found, the
|
|
572
624
|
* original error is propagated unchanged.
|
|
573
625
|
*
|
|
626
|
+
* With an {@link AppendCondition}, the append additionally fails with
|
|
627
|
+
* {@link AppendConditionFailedError} — writing nothing — if any read-set
|
|
628
|
+
* stream has operations past its recorded revision. The written and
|
|
629
|
+
* read-set streams are advisory-locked in sorted key order, so concurrent
|
|
630
|
+
* conditional appends on overlapping streams serialize.
|
|
631
|
+
*
|
|
574
632
|
* @param documentId - The document id
|
|
575
633
|
* @param documentType - The document type identifier
|
|
576
634
|
* @param scope - The operation scope (e.g. "global", "local")
|
|
@@ -578,9 +636,10 @@ interface IOperationStore {
|
|
|
578
636
|
* @param revision - Expected current revision (optimistic lock)
|
|
579
637
|
* @param fn - Callback that stages operations via {@link AtomicTxn}
|
|
580
638
|
* @param signal - Optional abort signal to cancel the request
|
|
639
|
+
* @param condition - Optional read-set to enforce at write time
|
|
581
640
|
* @returns The stored operations; empty array when no operations were staged
|
|
582
641
|
*/
|
|
583
|
-
apply(documentId: string, documentType: string, scope: string, branch: string, revision: number, fn: (txn: AtomicTxn) => void | Promise<void>, signal?: AbortSignal): Promise<Operation[]>;
|
|
642
|
+
apply(documentId: string, documentType: string, scope: string, branch: string, revision: number, fn: (txn: AtomicTxn) => void | Promise<void>, signal?: AbortSignal, condition?: AppendCondition): Promise<Operation[]>;
|
|
584
643
|
/**
|
|
585
644
|
* Returns operations for a document/scope/branch whose index is greater
|
|
586
645
|
* than the given revision.
|
|
@@ -1884,6 +1943,7 @@ declare class ReactorClient implements IReactorClient {
|
|
|
1884
1943
|
private documentView;
|
|
1885
1944
|
readonly drives: IDriveClient;
|
|
1886
1945
|
constructor(logger: ILogger, reactor: IReactor, signer: ISigner, subscriptionManager: IReactorSubscriptionManager, jobAwaiter: IJobAwaiter, documentIndexer: IDocumentIndexer, documentView: IDocumentView);
|
|
1946
|
+
private readSubject;
|
|
1887
1947
|
/**
|
|
1888
1948
|
* Retrieves a list of document model modules.
|
|
1889
1949
|
*/
|
|
@@ -2242,8 +2302,8 @@ type InitMessage = {
|
|
|
2242
2302
|
correlationId: string;
|
|
2243
2303
|
workerId: string;
|
|
2244
2304
|
poolConfig: WorkerPoolConfig;
|
|
2245
|
-
db: DbConfig;
|
|
2246
|
-
signatureVerifier
|
|
2305
|
+
db: DbConfig; /** Omitted = the worker performs no executor-side signature verification. */
|
|
2306
|
+
signatureVerifier?: SignatureVerifierSpec;
|
|
2247
2307
|
models: ModelManifestEntry[];
|
|
2248
2308
|
};
|
|
2249
2309
|
/**
|
|
@@ -2679,9 +2739,11 @@ interface IQueue {
|
|
|
2679
2739
|
* Retry a failed job.
|
|
2680
2740
|
* @param jobId - The ID of the job to retry
|
|
2681
2741
|
* @param error - Optional error information from the failure
|
|
2742
|
+
* @param accounting - Whether the attempt counts against the job's retry
|
|
2743
|
+
* limit; defaults to {@link RetryAccounting.CountAgainstLimit}
|
|
2682
2744
|
* @returns Promise that resolves when the job is requeued for retry
|
|
2683
2745
|
*/
|
|
2684
|
-
retryJob(jobId: string, error?: ErrorInfo$1): Promise<void>;
|
|
2746
|
+
retryJob(jobId: string, error?: ErrorInfo$1, accounting?: RetryAccounting): Promise<void>;
|
|
2685
2747
|
/**
|
|
2686
2748
|
* Returns true if and only if all jobs have been resolved.
|
|
2687
2749
|
*/
|
|
@@ -2749,6 +2811,25 @@ interface DocumentViewDatabase {
|
|
|
2749
2811
|
}
|
|
2750
2812
|
type InsertableDocumentSnapshot = Insertable<DocumentSnapshotTable>;
|
|
2751
2813
|
//#endregion
|
|
2814
|
+
//#region src/core/model-sources.d.ts
|
|
2815
|
+
/** An importable file holding one or more document-model exports. */
|
|
2816
|
+
type FileModelSource = {
|
|
2817
|
+
filePath: string;
|
|
2818
|
+
exportName?: string;
|
|
2819
|
+
};
|
|
2820
|
+
/** An importable package specifier holding one or more document-model exports. */
|
|
2821
|
+
type PackageModelSource = {
|
|
2822
|
+
packageName: string;
|
|
2823
|
+
subpath?: string;
|
|
2824
|
+
exportName?: string;
|
|
2825
|
+
};
|
|
2826
|
+
/**
|
|
2827
|
+
* A source of document models: a live module, an importable file, or an
|
|
2828
|
+
* importable package. File and package sources can cross a worker-thread
|
|
2829
|
+
* boundary (workers re-import them); a live module cannot.
|
|
2830
|
+
*/
|
|
2831
|
+
type DocumentModelSource = DocumentModelModule<any> | FileModelSource | PackageModelSource;
|
|
2832
|
+
//#endregion
|
|
2752
2833
|
//#region src/registry/interfaces.d.ts
|
|
2753
2834
|
type RegistrationResult<T> = {
|
|
2754
2835
|
status: "success";
|
|
@@ -2759,18 +2840,18 @@ type RegistrationResult<T> = {
|
|
|
2759
2840
|
error: Error;
|
|
2760
2841
|
};
|
|
2761
2842
|
/**
|
|
2762
|
-
* Loader that
|
|
2763
|
-
*
|
|
2764
|
-
* until the required model is available in the registry.
|
|
2843
|
+
* Loader that asynchronously resolves a document type to a
|
|
2844
|
+
* {@link DocumentModelSource}. Used by the queue to gate CREATE_DOCUMENT
|
|
2845
|
+
* jobs until the required model is available in the registry.
|
|
2765
2846
|
*
|
|
2766
|
-
*
|
|
2767
|
-
*
|
|
2768
|
-
*
|
|
2769
|
-
*
|
|
2847
|
+
* Return an importable source ({ filePath } or { packageName }) whenever
|
|
2848
|
+
* possible: the resolver registers the resolved models on the host registry
|
|
2849
|
+
* and broadcasts importable sources to executor workers. A live
|
|
2850
|
+
* DocumentModelModule is also valid but host-only — it cannot cross a
|
|
2851
|
+
* worker-thread boundary, so worker pools will not receive it.
|
|
2770
2852
|
*/
|
|
2771
2853
|
interface IDocumentModelLoader {
|
|
2772
|
-
load(documentType: string): Promise<
|
|
2773
|
-
resolveSpec?(documentType: string): Promise<ModelManifestEntry | null>;
|
|
2854
|
+
load(documentType: string): Promise<DocumentModelSource>;
|
|
2774
2855
|
}
|
|
2775
2856
|
/**
|
|
2776
2857
|
* Registry for managing document model modules.
|
|
@@ -3841,7 +3922,6 @@ declare class DocumentModelResolver implements IDocumentModelResolver {
|
|
|
3841
3922
|
ensureModelLoaded(documentType: string): Promise<void>;
|
|
3842
3923
|
private loadRegisterAndBroadcast;
|
|
3843
3924
|
private notifyPeersModelLoaded;
|
|
3844
|
-
private broadcastIfPossible;
|
|
3845
3925
|
}
|
|
3846
3926
|
/**
|
|
3847
3927
|
* No-op resolver used when no document model loader is configured.
|
|
@@ -4144,6 +4224,7 @@ declare class SyncBuilder {
|
|
|
4144
4224
|
* them (`BaseReadModel` subclasses, in particular).
|
|
4145
4225
|
*/
|
|
4146
4226
|
interface ReadModelFactoryDeps {
|
|
4227
|
+
documentModelRegistry: IDocumentModelRegistry;
|
|
4147
4228
|
operationIndex: IOperationIndex;
|
|
4148
4229
|
writeCache: IWriteCache;
|
|
4149
4230
|
processorManagerConsistencyTracker: IConsistencyTracker;
|
|
@@ -4153,16 +4234,28 @@ interface ReadModelFactoryDeps {
|
|
|
4153
4234
|
* dependencies once they are available. Awaited during `buildModule()`.
|
|
4154
4235
|
*/
|
|
4155
4236
|
type ReadModelFactory = (deps: ReadModelFactoryDeps) => IReadModel | Promise<IReadModel>;
|
|
4237
|
+
type WorkerPoolBase = {
|
|
4238
|
+
/** Number of worker threads to spawn; also the sticky-routing modulus. */numWorkers: number;
|
|
4239
|
+
/**
|
|
4240
|
+
* Factory spec the default transport's workers import to instantiate
|
|
4241
|
+
* their signature verifier. Omitted = no executor-side verification,
|
|
4242
|
+
* parity with the in-process executor's default.
|
|
4243
|
+
*/
|
|
4244
|
+
verifier?: SignatureVerifierSpec;
|
|
4245
|
+
};
|
|
4156
4246
|
/**
|
|
4157
|
-
*
|
|
4158
|
-
*
|
|
4247
|
+
* Executor worker-pool configuration. Either `db` (default thread
|
|
4248
|
+
* transport; each worker opens its own Postgres pool) or a custom
|
|
4249
|
+
* `factory` transport is required by construction — an enabled pool
|
|
4250
|
+
* without connection info is unrepresentable.
|
|
4159
4251
|
*/
|
|
4160
|
-
type
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
} | {
|
|
4164
|
-
|
|
4165
|
-
|
|
4252
|
+
type WorkerPoolOptions = (WorkerPoolBase & {
|
|
4253
|
+
db: DbConfig;
|
|
4254
|
+
factory?: WorkerFactory;
|
|
4255
|
+
}) | (WorkerPoolBase & {
|
|
4256
|
+
db?: DbConfig;
|
|
4257
|
+
factory: WorkerFactory;
|
|
4258
|
+
});
|
|
4166
4259
|
/**
|
|
4167
4260
|
* Caller-facing config for {@link ReactorBuilder.withProjectionShards}.
|
|
4168
4261
|
* When set, the builder replaces the in-process
|
|
@@ -4177,6 +4270,12 @@ type ProjectionShardBuilderConfig = {
|
|
|
4177
4270
|
shardCount: number;
|
|
4178
4271
|
preReadyKinds: BuiltInReadModelKind[];
|
|
4179
4272
|
postReadyKinds: BuiltInReadModelKind[];
|
|
4273
|
+
/**
|
|
4274
|
+
* Connection info for the projection workers' own pools. Falls back to
|
|
4275
|
+
* the executor worker pool's `db` when {@link ReactorBuilder.withWorkerPool}
|
|
4276
|
+
* is configured with one.
|
|
4277
|
+
*/
|
|
4278
|
+
db?: DbConfig;
|
|
4180
4279
|
poolSize?: number;
|
|
4181
4280
|
initTimeoutMs?: number;
|
|
4182
4281
|
shutdownGraceMs?: number;
|
|
@@ -4185,7 +4284,7 @@ type ProjectionShardBuilderConfig = {
|
|
|
4185
4284
|
};
|
|
4186
4285
|
declare class ReactorBuilder {
|
|
4187
4286
|
private logger?;
|
|
4188
|
-
private
|
|
4287
|
+
private documentModelSources;
|
|
4189
4288
|
private upgradeManifests;
|
|
4190
4289
|
private features;
|
|
4191
4290
|
private readModels;
|
|
@@ -4206,17 +4305,20 @@ declare class ReactorBuilder {
|
|
|
4206
4305
|
private documentModelLoader?;
|
|
4207
4306
|
private shutdownHooks;
|
|
4208
4307
|
private driveContainerTypes;
|
|
4209
|
-
private
|
|
4210
|
-
private workerPoolConfig?;
|
|
4308
|
+
private workerPool?;
|
|
4211
4309
|
private resolvedModelManifest?;
|
|
4212
|
-
private workerDbConfig?;
|
|
4213
|
-
private workerSignatureVerifierSpec?;
|
|
4214
|
-
private workerFactory?;
|
|
4215
4310
|
private projectionShardConfig?;
|
|
4216
4311
|
private projectionWorkerFactory?;
|
|
4217
4312
|
private instrumentedPools;
|
|
4218
4313
|
withLogger(logger: ILogger): this;
|
|
4219
|
-
|
|
4314
|
+
/**
|
|
4315
|
+
* Register document-model sources: live modules, importable files, or
|
|
4316
|
+
* importable packages. Appends across calls. At `buildModule()` every
|
|
4317
|
+
* source is resolved host-side and registered on the registry; file and
|
|
4318
|
+
* package sources additionally form the worker manifest when the worker
|
|
4319
|
+
* pool is enabled (live modules cannot cross a thread boundary).
|
|
4320
|
+
*/
|
|
4321
|
+
withDocumentModelSources(sources: DocumentModelSource[]): this;
|
|
4220
4322
|
withUpgradeManifests(manifests: UpgradeManifest<readonly number[]>[]): this;
|
|
4221
4323
|
withFeatures(features: ReactorFeatures): this;
|
|
4222
4324
|
withReadModel(readModel: IReadModel): this;
|
|
@@ -4260,43 +4362,27 @@ declare class ReactorBuilder {
|
|
|
4260
4362
|
* shutdown chain.
|
|
4261
4363
|
*/
|
|
4262
4364
|
withShutdownHook(hook: () => Promise<void>): this;
|
|
4263
|
-
withDocumentModelSpecs(specs: DocumentModelSpecInput[]): this;
|
|
4264
|
-
/**
|
|
4265
|
-
* Stores the worker-pool configuration. When `config.enabled === true` the
|
|
4266
|
-
* builder constructs a {@link WorkerPoolJobExecutorManager} in place of the
|
|
4267
|
-
* in-process {@link SimpleJobExecutorManager}.
|
|
4268
|
-
*/
|
|
4269
|
-
withWorkerPool(config: WorkerPoolConfig): this;
|
|
4270
4365
|
/**
|
|
4271
|
-
*
|
|
4272
|
-
*
|
|
4273
|
-
* `
|
|
4366
|
+
* Enable the executor worker pool: N `node:worker_threads` workers with
|
|
4367
|
+
* sticky per-document routing, replacing the in-process executor. Calling
|
|
4368
|
+
* this enables the pool — there is no `enabled` flag. Provide `db`
|
|
4369
|
+
* (each worker opens its own Postgres pool; the parent database is built
|
|
4370
|
+
* from it too unless {@link withKysely} is set) or a custom `factory`
|
|
4371
|
+
* transport. `verifier` is imported by the default transport's workers;
|
|
4372
|
+
* omitted = no executor-side signature verification.
|
|
4274
4373
|
*/
|
|
4275
|
-
|
|
4276
|
-
/**
|
|
4277
|
-
* Factory spec the worker imports to instantiate its signature verifier.
|
|
4278
|
-
* Required when `workerPool.enabled === true` unless a custom
|
|
4279
|
-
* `withWorkerFactory` or `withExecutor` is provided.
|
|
4280
|
-
*/
|
|
4281
|
-
withWorkerSignatureVerifierSpec(spec: SignatureVerifierSpec): this;
|
|
4282
|
-
/**
|
|
4283
|
-
* Inject a custom {@link WorkerFactory}. When set, the builder skips
|
|
4284
|
-
* default thread-transport wiring and hands the factory directly to the
|
|
4285
|
-
* pool manager. Use this in tests or to plug in a different transport
|
|
4286
|
-
* (e.g. a child-process adapter).
|
|
4287
|
-
*/
|
|
4288
|
-
withWorkerFactory(factory: WorkerFactory): this;
|
|
4374
|
+
withWorkerPool(options: WorkerPoolOptions): this;
|
|
4289
4375
|
/**
|
|
4290
4376
|
* Configure N sharded projection workers. When set, the builder replaces
|
|
4291
4377
|
* the default in-process {@link ReadModelCoordinator} with a
|
|
4292
|
-
* {@link ProjectionShardManager}.
|
|
4293
|
-
* {@link withWorkerDbConfig} is reused for the projection workers'
|
|
4294
|
-
* connection info; only the `poolSize` is overridden by
|
|
4295
|
-
* {@link ProjectionShardBuilderConfig.poolSize}.
|
|
4378
|
+
* {@link ProjectionShardManager}.
|
|
4296
4379
|
*
|
|
4297
|
-
*
|
|
4298
|
-
*
|
|
4299
|
-
*
|
|
4380
|
+
* Projection workers open their own Postgres pools from `config.db`,
|
|
4381
|
+
* falling back to the executor worker pool's `db` when
|
|
4382
|
+
* {@link withWorkerPool} is configured with one; only the `poolSize` is
|
|
4383
|
+
* overridden by {@link ProjectionShardBuilderConfig.poolSize}. The same
|
|
4384
|
+
* model manifest resolved from {@link withDocumentModelSources} is
|
|
4385
|
+
* forwarded.
|
|
4300
4386
|
*/
|
|
4301
4387
|
withProjectionShards(config: ProjectionShardBuilderConfig): this;
|
|
4302
4388
|
/**
|
|
@@ -4308,6 +4394,14 @@ declare class ReactorBuilder {
|
|
|
4308
4394
|
getResolvedModelManifest(): ModelManifestEntry[] | undefined;
|
|
4309
4395
|
build(): Promise<IReactor>;
|
|
4310
4396
|
buildModule(): Promise<InProcessReactorModule>;
|
|
4397
|
+
/**
|
|
4398
|
+
* The single Postgres config for the parent, executor workers, and
|
|
4399
|
+
* projection shards. They must share one physical database (the parent
|
|
4400
|
+
* writes operations; workers and shards read them), so divergent
|
|
4401
|
+
* worker/shard targets throw. `withKysely` overrides the parent and is not
|
|
4402
|
+
* validated against a worker/shard `db`.
|
|
4403
|
+
*/
|
|
4404
|
+
private resolveReactorDbConfig;
|
|
4311
4405
|
/**
|
|
4312
4406
|
* Constructs a {@link ProjectionShardManager} bound to the host event
|
|
4313
4407
|
* bus. Builds the default thread-transport factory unless one was
|
|
@@ -4318,9 +4412,9 @@ declare class ReactorBuilder {
|
|
|
4318
4412
|
private createProjectionShardManager;
|
|
4319
4413
|
private createDefaultProjectionWorkerFactory;
|
|
4320
4414
|
/**
|
|
4321
|
-
* Default {@link WorkerFactory} used when
|
|
4322
|
-
*
|
|
4323
|
-
*
|
|
4415
|
+
* Default {@link WorkerFactory} used when the pool options carry no
|
|
4416
|
+
* custom `factory`. Each worker spawns a real `node:worker_threads`
|
|
4417
|
+
* Worker pointing at the compiled `worker/entry.js`.
|
|
4324
4418
|
*/
|
|
4325
4419
|
private createDefaultWorkerFactory;
|
|
4326
4420
|
/**
|
|
@@ -4596,7 +4690,7 @@ declare class InMemoryQueue implements IQueue {
|
|
|
4596
4690
|
completeJob(jobId: string): Promise<void>;
|
|
4597
4691
|
failJob(jobId: string, error?: ErrorInfo$1): Promise<void>;
|
|
4598
4692
|
deferJob(jobId: string): void;
|
|
4599
|
-
retryJob(jobId: string, error?: ErrorInfo$1): Promise<void>;
|
|
4693
|
+
retryJob(jobId: string, error?: ErrorInfo$1, accounting?: RetryAccounting): Promise<void>;
|
|
4600
4694
|
/**
|
|
4601
4695
|
* Check if the queue is drained and call the callback if it is
|
|
4602
4696
|
*/
|
|
@@ -4988,9 +5082,23 @@ declare class KyselyOperationStore implements IOperationStore {
|
|
|
4988
5082
|
constructor(db: Kysely<Database$1>);
|
|
4989
5083
|
private get queryExecutor();
|
|
4990
5084
|
withTransaction(trx: Transaction<Database$1>): KyselyOperationStore;
|
|
4991
|
-
apply(documentId: string, documentType: string, scope: string, branch: string, revision: number, fn: (txn: AtomicTxn) => void | Promise<void>, signal?: AbortSignal): Promise<Operation[]>;
|
|
5085
|
+
apply(documentId: string, documentType: string, scope: string, branch: string, revision: number, fn: (txn: AtomicTxn) => void | Promise<void>, signal?: AbortSignal, condition?: AppendCondition): Promise<Operation[]>;
|
|
4992
5086
|
private resolveUniqueConstraint;
|
|
4993
5087
|
private executeApply;
|
|
5088
|
+
/**
|
|
5089
|
+
* Locks the written stream and every read-set stream, in sorted key order
|
|
5090
|
+
* so that overlapping concurrent appends serialize rather than deadlock.
|
|
5091
|
+
* The locks are still taken one row at a time, so the query preserves that
|
|
5092
|
+
* order. It must stay separate from the guarded insert, which would
|
|
5093
|
+
* otherwise read a snapshot taken before the locks were held.
|
|
5094
|
+
*/
|
|
5095
|
+
private acquireStreamLocks;
|
|
5096
|
+
/**
|
|
5097
|
+
* Inserts the staged operations with the condition compiled in as a WHERE
|
|
5098
|
+
* NOT EXISTS guard, making the check and the append one statement. Returns
|
|
5099
|
+
* the rows inserted; zero means the guard failed and nothing was written.
|
|
5100
|
+
*/
|
|
5101
|
+
private insertGuarded;
|
|
4994
5102
|
private findIdempotentReplay;
|
|
4995
5103
|
getSince(documentId: string, scope: string, branch: string, revision: number, filter?: OperationFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<Operation>>;
|
|
4996
5104
|
getSinceId(id: number, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<OperationWithContext$1>>;
|
|
@@ -5128,6 +5236,50 @@ declare class DocumentModelRegistry implements IDocumentModelRegistry {
|
|
|
5128
5236
|
getUpgradeReducer(documentType: string, fromVersion: number, toVersion: number): UpgradeReducer<any, any>;
|
|
5129
5237
|
}
|
|
5130
5238
|
//#endregion
|
|
5239
|
+
//#region src/decision/types.d.ts
|
|
5240
|
+
/** One operation stream. */
|
|
5241
|
+
type StreamQuery = {
|
|
5242
|
+
documentId: string;
|
|
5243
|
+
branch: string;
|
|
5244
|
+
scope: string;
|
|
5245
|
+
};
|
|
5246
|
+
/** The document and branch a decision model is built for. */
|
|
5247
|
+
type DecisionTarget = {
|
|
5248
|
+
documentId: string;
|
|
5249
|
+
branch: string;
|
|
5250
|
+
};
|
|
5251
|
+
/** The executing scope's own state, for conditions that read it. */
|
|
5252
|
+
type DecisionContext = {
|
|
5253
|
+
scopeState: unknown;
|
|
5254
|
+
};
|
|
5255
|
+
/**
|
|
5256
|
+
* A named stream whose value in the model is that scope's state from the
|
|
5257
|
+
* document rebuild the reactor already performs. A derived query may read
|
|
5258
|
+
* only statically-queried projections, so composition is one layer deep.
|
|
5259
|
+
*/
|
|
5260
|
+
type Projection<M> = {
|
|
5261
|
+
query: StreamQuery | ((model: Partial<M>) => StreamQuery[]);
|
|
5262
|
+
};
|
|
5263
|
+
/** Projections plus a decision function over the built model. */
|
|
5264
|
+
type DecisionModel<M> = {
|
|
5265
|
+
projections: { [K in keyof M]: Projection<M> };
|
|
5266
|
+
decide(model: M, subject: AuthSubject, request: AuthRequest, ctx: DecisionContext): AuthDecision;
|
|
5267
|
+
};
|
|
5268
|
+
/** A built model plus the read-set condition recording what the build read. */
|
|
5269
|
+
type BuiltDecisionModel<M> = {
|
|
5270
|
+
model: M;
|
|
5271
|
+
appendCondition: AppendCondition;
|
|
5272
|
+
};
|
|
5273
|
+
//#endregion
|
|
5274
|
+
//#region src/decision/build-decision-model.d.ts
|
|
5275
|
+
/**
|
|
5276
|
+
* Reads each projection's stream through the write cache, recording the
|
|
5277
|
+
* revision observed. Static projections resolve first; derived projections
|
|
5278
|
+
* see only those and contribute a map from document id to state. Each
|
|
5279
|
+
* distinct stream is read once and yields one append condition entry.
|
|
5280
|
+
*/
|
|
5281
|
+
declare function buildDecisionModel<M>(cache: IWriteCache, definition: (target: DecisionTarget) => DecisionModel<M>, target: DecisionTarget, signal?: AbortSignal): Promise<BuiltDecisionModel<M>>;
|
|
5282
|
+
//#endregion
|
|
5131
5283
|
//#region src/read-models/base-read-model.d.ts
|
|
5132
5284
|
type BaseReadModelConfig = {
|
|
5133
5285
|
readModelId: string;
|
|
@@ -5212,7 +5364,7 @@ declare class KyselyDocumentIndexer extends BaseReadModel implements IDocumentIn
|
|
|
5212
5364
|
* serialized so the executor can return to dispatch without holding ordering
|
|
5213
5365
|
* implicitly.
|
|
5214
5366
|
*/
|
|
5215
|
-
declare class ReadModelCoordinator implements
|
|
5367
|
+
declare class ReadModelCoordinator implements ILiveReadModelCoordinator {
|
|
5216
5368
|
private eventBus;
|
|
5217
5369
|
readonly preReady: IReadModel[];
|
|
5218
5370
|
readonly postReady: IReadModel[];
|
|
@@ -5231,6 +5383,7 @@ declare class ReadModelCoordinator implements IReadModelCoordinator {
|
|
|
5231
5383
|
*/
|
|
5232
5384
|
drain(): Promise<void>;
|
|
5233
5385
|
getChainDepth(): number;
|
|
5386
|
+
addReadModel(readModel: IReadModel, stage: ReadModelRegistrationStage): void;
|
|
5234
5387
|
private handleWriteReady;
|
|
5235
5388
|
private emitEmptyReadReady;
|
|
5236
5389
|
private runChain;
|
|
@@ -5676,5 +5829,5 @@ declare class ProcessorManager extends BaseReadModel implements IProcessorManage
|
|
|
5676
5829
|
private deleteProcessorCursors;
|
|
5677
5830
|
}
|
|
5678
5831
|
//#endregion
|
|
5679
|
-
export { type AbortMessage, type AtomicTxn, type AttachmentHash, type AttachmentRef, BaseReadModel, type BatchExecutionRequest, type BatchExecutionResult, type BatchLoadRequest, type BatchLoadResult, type BuiltInReadModelKind, type CachedSnapshot, type ChannelConfig, ChannelError, ChannelErrorSource, type ChannelHealth, type ChannelMeta, ChannelScheme, type ConnectionState, type ConnectionStateChangeCallback, type ConnectionStateChangedEvent, type ConnectionStateSnapshot, type ConsistencyCoordinate, type ConsistencyKey, type ConsistencyToken, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DRIVE_AUTH_ERROR_MESSAGES, type Database, type DbConfig, type DeadLetterAddedEvent, DefaultSubscriptionErrorHandler, type DocumentChangeEvent, DocumentChangeType, type DocumentGraphEdge, type DocumentIndexerDatabase, DocumentIntegrityService, DocumentModelRegistry, DocumentModelResolver, type
|
|
5832
|
+
export { type AbortMessage, type AppendCondition, AppendConditionFailedError, type AppendConditionStream, type AtomicTxn, type AttachmentHash, type AttachmentRef, BaseReadModel, type BatchExecutionRequest, type BatchExecutionResult, type BatchLoadRequest, type BatchLoadResult, type BuiltDecisionModel, type BuiltInReadModelKind, type CachedSnapshot, type ChannelConfig, ChannelError, ChannelErrorSource, type ChannelHealth, type ChannelMeta, ChannelScheme, type ConnectionState, type ConnectionStateChangeCallback, type ConnectionStateChangedEvent, type ConnectionStateSnapshot, type ConsistencyCoordinate, type ConsistencyKey, type ConsistencyToken, ConsistencyTracker, DEFAULT_DRIVE_CONTAINER_TYPES, DRIVE_AUTH_ERROR_MESSAGES, type Database, type DbConfig, type DeadLetterAddedEvent, type DecisionContext, type DecisionModel, type DecisionTarget, DefaultSubscriptionErrorHandler, type DocumentChangeEvent, DocumentChangeType, type DocumentGraphEdge, type DocumentIndexerDatabase, DocumentIntegrityService, DocumentModelRegistry, DocumentModelResolver, type DocumentModelSource, type DocumentModelSpec, type DocumentRelationship, type DocumentRevisions, type DocumentStreamKey, type DocumentViewDatabase, DriveClient, DriveCollectionId, DuplicateManifestError, DuplicateModuleError, DuplicateOperationError, EventBus, EventBusAggregateError, type ExecuteMessage, type ExecutionJobPlan, type ExecutorStartedEvent, type ExecutorStoppedEvent, type FactorySpec, type FileModelSource, type GqlChannelConfig, GqlRequestChannel, GqlRequestChannelFactory, GqlResponseChannel, GqlResponseChannelFactory, type HeartbeatMessage, type IChannel, type IChannelFactory, type IConsistencyTracker, type IDocumentGraph, type IDocumentIndexer, type IDocumentIntegrityService, type IDocumentModelLoader, type IDocumentModelRegistry, type IDocumentModelResolver, type IDocumentView, type IDriveClient, type IEventBus, type IJobAwaiter, type IJobExecutor, type IJobExecutorManager, type IJobTracker, type IKeyframeStore, type ILiveReadModelCoordinator, type IMailbox, type IOperationIndex, type IOperationStore, type IPollTimer, type IProcessor, type IProcessorHostModule, type IProcessorManager, type IProjectionTransport, type IQueue, type IReactor, type IReactorClient, type IReactorSubscriptionManager, type IReadModel, type IReadModelCoordinator, type IRelationalDb, type ISubscriptionErrorHandler, type ISyncCursorStorage, type ISyncManager, type ISyncRemoteStorage, type ISyncStatusTracker, type IWriteCache, SimpleJobExecutor as InMemoryJobExecutor, SimpleJobExecutor, InMemoryJobTracker, InMemoryQueue, type InProcessReactorClientModule, type InProcessReactorModule, type InProcessSyncModule, type InitMessage, type InsertableDocumentSnapshot, IntervalPollTimer, InvalidModuleError, type Job, type JobAvailableEvent, JobAwaiter, type JobCompletedEvent, type JobExecutorConfig, JobExecutorEventTypes, type JobExecutorFactory, type JobFailedEvent, type JobInfo, type JobPendingEvent, type JobReadReadyEvent, type JobResult, type JobRunningEvent, type JobStartedEvent, JobStatus, type JobWriteReadyEvent, type JobWriteReadyPayload, type JwtHandler, type KeyframeSnapshot, type KeyframeValidationIssue, KyselyDocumentIndexer, KyselyDocumentView, KyselyKeyframeStore, KyselyOperationStore, KyselySyncCursorStorage, KyselySyncRemoteStorage, KyselyWriteCache, type LoadJobPlan, type LoadModelMessage, type LogMessage, Mailbox, type MetricsMessage, type ModelLoadFailedMessage, type ModelLoadedEvent, type ModelLoadedMessage, type ModelManifestEntry, ModuleNotFoundError, type ModuleRef, NullDocumentModelResolver, type OperationBatch, type OperationContext, type OperationFilter, type OperationIndexEntry, type OperationTable, type OperationWithContext, OptimisticLockError, type PackageModelSource, type PagedResults, type PagingOptions, type ParentMessage, type ParsedDriveUrl, type ParsedPaging, PollBehavior, PollingChannelError, type PoolInstrumentation, type PoolStats, type ProcessorApp, type ProcessorFactory, type ProcessorFactoryBuilder, type ProcessorFilter, ProcessorManager, type ProcessorRecord, type ProcessorStatus, type Projection, type ProjectionShardBuilderConfig, type ProjectionShardManagerConfig, type ProjectionWorkerFactory, PropagationMode, QueueEventTypes, REACTOR_SCHEMA, Reactor, ReactorBuilder, ReactorClient, ReactorClientBuilder, type ReactorClientModule, ReactorEventTypes, type ReactorFeatures, type JobFailedEvent$1 as ReactorJobFailedEvent, type ReactorModule, ReactorSubscriptionManager, type ReadModelBatchCompletedEvent, ReadModelCoordinator, type ReadModelFactory, type ReadModelFactoryDeps, type ReadModelIndexedEvent, type ReadModelIndexingStage, type ReadModelRegistrationStage, type ReadModelStage, type ReadyMessage, type RebuildResult, RelationalDbProcessor, RelationshipChangeType, type Remote, type RemoteCursor, type RemoteFilter, type RemoteMeta, type RemoteOptions, type RemoteRecord, type RemoteStatus, type ResultMessage, RetryAccounting, RevisionMismatchError, type SanitizedArg, type SearchFilter, type ShutdownMessage, type ShutdownStatus, type SignatureVerificationHandler, type SignatureVerifierSpec, type SignerConfig, SimpleJobExecutorManager, type SnapshotValidationIssue, type Database$1 as StorageDatabase, type StreamQuery, type SubscriptionErrorContext, SyncBuilder, type SyncEnvelope, type SyncEnvelopeType, SyncEventTypes, type SyncFailedEvent, type SyncModule, SyncOperation, SyncOperationAggregateError, type SyncOperationErrorType, SyncOperationStatus, type SyncPendingEvent, SyncStatus, type SyncStatusChangeCallback, SyncStatusTracker, type SyncSucceededEvent, type TrackedProcessor, type Unsubscribe, type ValidationResult, type ViewFilter, type ErrorInfo as WorkerErrorInfo, type WorkerMessage, type WorkerPoolConfig, type WorkerPoolOptions, type WriteCacheConfig, addRelationshipAction, batchOperationsByDocument, buildDecisionModel, consolidateSyncOperations, createDocumentAction, createForwardingLogger, createMutableShutdownStatus, createRelationalDb, deleteDocumentAction, documentActions, driveIdFromUrl, envelopesToSyncOperations, errorToInfo, getMigrationStatus, instrumentPgPool, isDriveAuthError, makeConsistencyKey, parseDriveUrl, parsePagingOptions, removeRelationshipAction, runMigrations, sanitizeArg, supportsLiveReadModelRegistration, trimMailboxFromAckOrdinal, updateRelationshipAction, upgradeDocumentAction, workerEntryPath };
|
|
5680
5833
|
//# sourceMappingURL=index.d.ts.map
|