refactor the Collection class into multiple manager classes #560
Mergedsamwillismerged 16 commits into
main fromrefs/pull/560/headmerged by samwillis - @@ -0,0 +1,12 @@1+import {2+ CollectionIsInErrorStateError,3+ DuplicateKeySyncError,4+ NoPendingSyncTransactionCommitError,5+ NoPendingSyncTransactionWriteError,6+ SyncCleanupError,7+ SyncTransactionAlreadyCommittedError,8+ SyncTransactionAlreadyCommittedWriteError,9+} from "../errors"10+import type { StandardSchemaV1 } from "@standard-schema/spec"11+import type { ChangeMessage } from "../types"12+import type { CollectionImpl } from "../collection/index.js"@@ -0,0 +1,6 @@1+import { deepEquals } from "../utils"2+import { SortedMap } from "../SortedMap"3+import type { Transaction } from "../transactions"4+import type { StandardSchemaV1 } from "@standard-schema/spec"5+import type { ChangeMessage, OptimisticChangeMessage } from "../types"6+import type { CollectionImpl } from "../collection/index.js"@@ -0,0 +1,5 @@1+import { ensureIndexForExpression } from "../indexes/auto-index.js"2+import { createFilteredCallback } from "../change-events"3+import { NegativeActiveSubscribersError } from "../errors"4+import type { StandardSchemaV1 } from "@standard-schema/spec"5+import type { CollectionImpl } from "../collection/index.js"@@ -0,0 +1,6 @@1+import {2+ CollectionInErrorStateError,3+ InvalidCollectionStatusTransitionError,4+} from "../errors"5+import type { StandardSchemaV1 } from "@standard-schema/spec"6+import type { CollectionImpl } from "../collection/index.js"@@ -0,0 +1,8 @@1+import { IndexProxy, LazyIndexWrapper } from "../indexes/lazy-index"2+import {3+ createSingleRowRefProxy,4+ toExpression,5+} from "../query/builder/ref-proxy"6+import { BTreeIndex } from "../indexes/btree-index"7+import type { StandardSchemaV1 } from "@standard-schema/spec"8+import type { CollectionImpl } from "../collection/index.js"@@ -0,0 +1,19 @@1+import { withArrayChangeTracking, withChangeTracking } from "../proxy"2+import { createTransaction, getActiveTransaction } from "../transactions"3+import {4+ DeleteKeyNotFoundError,5+ DuplicateKeyError,6+ InvalidSchemaError,7+ KeyUpdateNotAllowedError,8+ MissingDeleteHandlerError,9+ MissingInsertHandlerError,10+ MissingUpdateArgumentError,11+ MissingUpdateHandlerError,12+ NoKeysPassedToDeleteError,13+ NoKeysPassedToUpdateError,14+ SchemaMustBeSynchronousError,15+ SchemaValidationError,16+ UndefinedKeyError,17+ UpdateKeyNotFoundError,18+} from "../errors"19+import type { Collection, CollectionImpl } from "../collection/index.js"@@ -0,0 +12,21 @@12+ TSchema extends StandardSchemaV1 = StandardSchemaV1,13+ TInput extends object = TOutput,14+> {15+ public status: CollectionStatus = `idle`16+ public hasBeenReady = false17+ public hasReceivedFirstCommit = false18+ public onFirstReadyCallbacks: Array<() => void> = []19+ public gcTimeoutId: ReturnType<typeof setTimeout> | null = null20+21+ /**22+ * Creates a new CollectionLifecycleManager instance23+ */24+ constructor(25+ public collection: CollectionImpl<TOutput, TKey, any, TSchema, TInput>26+ ) {}27+28+ /**29+ * Validates state transitions to prevent invalid status changes30+ * @private31+ */32+ private validateStatusTransition(
kevin-dp(GitHub profile, opens in a new tab) approved these changes
@@ -0,0 +1,10 @@1+import { NegativeActiveSubscribersError } from "../errors"2+import { CollectionSubscription } from "./subscription.js"3+import type { StandardSchemaV1 } from "@standard-schema/spec"4+import type { ChangeMessage, SubscribeChangesOptions } from "../types"5+import type { CollectionLifecycleManager } from "./lifecycle.js"6+import type { CollectionSyncManager } from "./sync.js"7+import type { CollectionEventsManager } from "./events.js"8+import type { CollectionImpl } from "./index.js"9+10+// depends on:@@ -0,0 +2,21 @@2+ CollectionIsInErrorStateError,3+ DuplicateKeySyncError,4+ NoPendingSyncTransactionCommitError,5+ NoPendingSyncTransactionWriteError,6+ SyncCleanupError,7+ SyncTransactionAlreadyCommittedError,8+ SyncTransactionAlreadyCommittedWriteError,9+} from "../errors"10+import type { StandardSchemaV1 } from "@standard-schema/spec"11+import type { ChangeMessage, CollectionConfig } from "../types"12+import type { CollectionImpl } from "./index.js"13+import type { CollectionStateManager } from "./state"14+import type { CollectionLifecycleManager } from "./lifecycle"15+16+export class CollectionSyncManager<17+ TOutput extends object = Record<string, unknown>,18+ TKey extends string | number = string | number,19+ TSchema extends StandardSchemaV1 = StandardSchemaV1,20+ TInput extends object = TOutput,21+> {22+ private collection!: CollectionImpl<TOutput, TKey, any, TSchema, TInput>samwillis merged thisac6250a
samwillis closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 77e8303ae11357c6864fa7552dc5bb9ae2e094aa
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR