UNPKG

@sanity/mutate

Version:

Experimental toolkit for working with Sanity mutations in JavaScript & TypeScript

225 lines (224 loc) 11.1 kB
import { $ as PathElement, A as SafePath, B as Try, C as ParseInnerExpression, D as ParseProperty, E as ParseObject, F as ToArray, G as AnyEmptyArray, H as Get, I as ToNumber, J as FindBy, K as ByIndex, L as Trim, M as SplitAll, N as StringToPath, O as ParseValue, P as StripError, Q as Path, R as TrimLeft, S as ParseExpressions, T as ParseNumber, U as GetAtPath, V as Unwrap, W as getAtPath, X as Index, Y as FindInArray, Z as KeyedPathElement, _ as MergeInner, a as isKeyElement, b as ParseAllProps, c as startsWith, d as parse, et as PropertyName, f as Concat, g as Merge, h as Err, i as isIndexElement, j as Split, k as Result, l as normalize, m as Digit, n as isElementEqual, o as isKeyedElement, p as ConcatInner, q as ElementType, r as isEqual, s as isPropertyElement, st as Optional, t as isArrayElement, tt as AnyArray, u as stringify, v as Ok, w as ParseKVPair, x as ParseError, y as OnlyDigits, z as TrimRight } from "./_chunks-dts/index2.js"; import { A as StringOp, C as Operation, D as ReplaceOp, E as RemoveOp, M as UnassignOp, N as UnsetOp, O as SetIfMissingOp, P as UpsertOp, S as ObjectOp, T as RelativePosition, _ as DiffMatchPatchOp, b as InsertOp, c as NodePatchList, d as SanityDocumentBase, f as Transaction, g as DecOp, h as AssignOp, i as DeleteMutation, j as TruncateOp, k as SetOp, l as PatchMutation, m as ArrayOp, n as CreateMutation, o as Mutation, p as AnyOp, r as CreateOrReplaceMutation, s as NodePatch, t as CreateIfNotExistsMutation, u as PatchOptions, v as IncOp, w as PrimitiveOp, x as NumberOp, y as InsertIfMissingOp } from "./_chunks-dts/types.js"; import { $ as MutationResult, H as toTransactions, Q as MutationGroup, U as DocumentMap, at as RemoteMutationEvent, ct as TransactionalMutationGroup, et as NonTransactionalMutationGroup, it as RemoteDocumentEvent, lt as RawPatch, ot as RemoteSyncEvent, st as SubmitResult, tt as OptimisticDocumentEvent } from "./_chunks-dts/index3.js"; import * as _$rxjs from "rxjs"; import * as _$_sanity_client0 from "@sanity/client"; import { MutationEvent, ReconnectEvent, SanityClient, SanityDocument, WelcomeEvent } from "@sanity/client"; import * as _$xstate from "xstate"; interface UpdateResult<T extends SanityDocumentBase> { id: string; status: 'created' | 'updated' | 'deleted'; before?: T; after?: T; mutations: Mutation[]; } /** * Takes a list of mutations and applies them to documents in a documentMap */ declare function applyMutations<T extends SanityDocumentBase>(mutations: Mutation[], documentMap: DocumentMap<T>, /** * note: should never be set client side – only for test purposes */ transactionId?: never): UpdateResult<T>[]; declare function commit<Doc extends SanityDocumentBase>(results: UpdateResult<Doc>[], documentMap: DocumentMap<Doc>): void; interface DataStore { get: (id: string) => SanityDocumentBase | undefined; } declare function squashDMPStrings(base: DataStore, mutationGroups: MutationGroup[]): MutationGroup[]; declare function squashMutationGroups(staged: readonly MutationGroup[]): MutationGroup[]; declare function rebase(documentId: string, oldBase: SanityDocumentBase | undefined, newBase: SanityDocumentBase | undefined, localMutations: readonly MutationGroup[]): [newLocal: MutationGroup[], rebased: SanityDocumentBase | undefined]; /** * Creates a single, shared, listener EventSource that strems remote mutations, and notifies when it's online (welcome), offline (reconnect). */ declare function createSharedListener(client: SanityClient): _$rxjs.Observable<WelcomeEvent | ReconnectEvent | MutationEvent>; interface DocumentMutatorMachineInput { id: string; client: SanityClient; /** A shared listener can be provided, if not it'll be created using `client.listen()` */ sharedListener?: ReturnType<typeof createSharedListener>; cache?: Map<string, SanityDocument | null>; } type DocumentMutatorMachineParentEvent = { type: 'sync'; id: string; document: SanityDocumentBase; } | { type: 'mutation'; id: string; effects: { apply: RawPatch; }; previousRev: string; resultRev: string; } | { type: 'rebased.local'; id: string; document: SanityDocumentBase; } | { type: 'rebased.remote'; id: string; document: SanityDocumentBase; } | { type: 'pristine'; id: string; }; declare const documentMutatorMachine: _$xstate.StateMachine<{ client: SanityClient; /** A shared listener can be provided, if not it'll be created using `client.listen()` */ sharedListener?: ReturnType<typeof createSharedListener>; /** The document id */ id: string; cache?: Map<string, SanityDocument | null>; remote: SanityDocument | null | undefined; local: SanityDocument | null | undefined; mutationEvents: MutationEvent[]; stagedChanges: MutationGroup[]; stashedChanges: MutationGroup[]; error: unknown; fetchRemoteSnapshotAttempts: number; submitTransactionsAttempts: number; }, _$_sanity_client0.WelcomeEvent | _$_sanity_client0.ReconnectEvent | MutationEvent | { type: "error"; } | { type: "retry"; } | { type: "connect"; } | { type: "reconnect"; } | { type: "welcome"; } | { type: "mutate"; mutations: Mutation[]; } | { type: "submit"; } | { type: "xstate.done.actor.getDocument"; output: SanityDocument; } | { type: "xstate.done.actor.submitTransactions"; output: undefined; }, { [x: string]: _$xstate.ActorRefFromLogic<_$xstate.PromiseActorLogic<void | SanityDocument<Record<string, any>> | undefined, { client: SanityClient; id: string; }, _$xstate.EventObject>> | _$xstate.ActorRefFromLogic<_$xstate.PromiseActorLogic<void, { client: SanityClient; transactions: Transaction[]; }, _$xstate.EventObject>> | _$xstate.ActorRefFromLogic<_$xstate.ObservableActorLogic<_$_sanity_client0.WelcomeEvent | _$_sanity_client0.ReconnectEvent | MutationEvent, { listener: ReturnType<typeof createSharedListener>; id: string; }, _$xstate.EventObject>> | undefined; getDocument?: _$xstate.ActorRefFromLogic<_$xstate.PromiseActorLogic<void | SanityDocument<Record<string, any>> | undefined, { client: SanityClient; id: string; }, _$xstate.EventObject>> | undefined; submitTransactions?: _$xstate.ActorRefFromLogic<_$xstate.PromiseActorLogic<void, { client: SanityClient; transactions: Transaction[]; }, _$xstate.EventObject>> | undefined; }, { src: "fetch remote snapshot"; logic: _$xstate.PromiseActorLogic<void | SanityDocument<Record<string, any>> | undefined, { client: SanityClient; id: string; }, _$xstate.EventObject>; id: "getDocument"; } | { src: "submit mutations as transactions"; logic: _$xstate.PromiseActorLogic<void, { client: SanityClient; transactions: Transaction[]; }, _$xstate.EventObject>; id: "submitTransactions"; } | { src: "server-sent events"; logic: _$xstate.ObservableActorLogic<_$_sanity_client0.WelcomeEvent | _$_sanity_client0.ReconnectEvent | MutationEvent, { listener: ReturnType<typeof createSharedListener>; id: string; }, _$xstate.EventObject>; id: string | undefined; }, { type: "assign error to context"; params: _$xstate.NonReducibleUnknown; } | { type: "clear error from context"; params: _$xstate.NonReducibleUnknown; } | { type: "connect to server-sent events"; params: _$xstate.NonReducibleUnknown; } | { type: "listen to server-sent events"; params: _$xstate.NonReducibleUnknown; } | { type: "stop listening to server-sent events"; params: _$xstate.NonReducibleUnknown; } | { type: "buffer remote mutation events"; params: _$xstate.NonReducibleUnknown; } | { type: "restore stashed changes"; params: _$xstate.NonReducibleUnknown; } | { type: "rebase fetched remote snapshot"; params: _$xstate.NonReducibleUnknown; } | { type: "apply mendoza patch"; params: _$xstate.NonReducibleUnknown; } | { type: "increment fetch attempts"; params: _$xstate.NonReducibleUnknown; } | { type: "reset fetch attempts"; params: _$xstate.NonReducibleUnknown; } | { type: "increment submit attempts"; params: _$xstate.NonReducibleUnknown; } | { type: "reset submit attempts"; params: _$xstate.NonReducibleUnknown; } | { type: "stage mutation"; params: _$xstate.NonReducibleUnknown; } | { type: "stash mutation"; params: _$xstate.NonReducibleUnknown; } | { type: "rebase local snapshot"; params: _$xstate.NonReducibleUnknown; } | { type: "send pristine event to parent"; params: _$xstate.NonReducibleUnknown; } | { type: "send sync event to parent"; params: _$xstate.NonReducibleUnknown; } | { type: "send mutation event to parent"; params: _$xstate.NonReducibleUnknown; }, never, "fetchRemoteSnapshotTimeout" | "submitTransactionsTimeout", "disconnected" | "connecting" | "reconnecting" | "connectFailure" | { connected: "loading" | "loadFailure" | { loaded: "pristine" | "dirty" | "submitting" | "submitFailure"; }; }, "error" | "busy" | "ready", DocumentMutatorMachineInput, _$xstate.NonReducibleUnknown, _$xstate.EventObject, _$xstate.MetaObject, { id: "document-mutator"; states: { readonly disconnected: {}; readonly connecting: {}; readonly connectFailure: {}; readonly reconnecting: {}; readonly connected: { states: { readonly loading: {}; readonly loaded: { states: { readonly pristine: {}; readonly dirty: {}; readonly submitting: {}; readonly submitFailure: {}; }; }; readonly loadFailure: {}; }; }; }; }>; export { AnyArray, AnyEmptyArray, AnyOp, ArrayOp, AssignOp, ByIndex, Concat, ConcatInner, type CreateIfNotExistsMutation, type CreateMutation, type CreateOrReplaceMutation, type DataStore, DecOp, type DeleteMutation, DiffMatchPatchOp, Digit, type DocumentMap, DocumentMutatorMachineInput, DocumentMutatorMachineParentEvent, ElementType, Err, FindBy, FindInArray, Get, GetAtPath, IncOp, Index, InsertIfMissingOp, InsertOp, KeyedPathElement, Merge, MergeInner, type Mutation, type MutationGroup, type MutationResult, type NodePatch, type NodePatchList, type NonTransactionalMutationGroup, NumberOp, ObjectOp, Ok, OnlyDigits, Operation, type OptimisticDocumentEvent, type Optional, ParseAllProps, ParseError, ParseExpressions, ParseInnerExpression, ParseKVPair, ParseNumber, ParseObject, ParseProperty, ParseValue, type PatchMutation, type PatchOptions, Path, PathElement, PrimitiveOp, PropertyName, RelativePosition, type RemoteDocumentEvent, type RemoteMutationEvent, type RemoteSyncEvent, RemoveOp, ReplaceOp, Result, SafePath, type SanityDocumentBase, SetIfMissingOp, SetOp, Split, SplitAll, StringOp, StringToPath, StripError, type SubmitResult, ToArray, ToNumber, type Transaction, type TransactionalMutationGroup, Trim, TrimLeft, TrimRight, TruncateOp, Try, UnassignOp, UnsetOp, Unwrap, type UpdateResult, UpsertOp, applyMutations, commit, createSharedListener, documentMutatorMachine, getAtPath, isArrayElement, isElementEqual, isEqual, isIndexElement, isKeyElement, isKeyedElement, isPropertyElement, normalize, parse, rebase, squashDMPStrings, squashMutationGroups, startsWith, stringify, toTransactions }; //# sourceMappingURL=_unstable_machine.d.ts.map