a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix some type errors

+35 -10
+7 -2
components/TextBlock.tsx
··· 5 5 import * as Y from "yjs"; 6 6 import { ProseMirror, useEditorState } from "@nytimes/react-prosemirror"; 7 7 import * as base64 from "base64-js"; 8 - import { useReplicache, useEntity, ReplicacheMutators } from "../replicache"; 8 + import { 9 + useReplicache, 10 + useEntity, 11 + ReplicacheMutators, 12 + Fact, 13 + } from "../replicache"; 9 14 10 15 import { EditorState, TextSelection } from "prosemirror-state"; 11 16 import { schema } from "prosemirror-schema-basic"; ··· 47 52 let { initialFacts } = useReplicache(); 48 53 let initialFact = initialFacts.find( 49 54 (f) => f.entity === props.entityID && f.attribute === "block/text", 50 - ); 55 + ) as Fact<"block/text"> | undefined; 51 56 if (!initialFact) return <pre className="min-h-6" />; 52 57 let doc = new Y.Doc(); 53 58 const update = base64.toByteArray(initialFact.data.value);
+5
replicache/attributes.ts
··· 20 20 cardinality: "one", 21 21 }, 22 22 } as const; 23 + 24 + type Attribute = typeof Attributes; 25 + export type FilterAttributes<F extends Partial<Attribute[keyof Attribute]>> = { 26 + [A in keyof Attribute as Attribute[A] extends F ? A : never]: Attribute[A]; 27 + };
+11 -4
replicache/clientMutationContext.ts
··· 2 2 import * as Y from "yjs"; 3 3 import * as base64 from "base64-js"; 4 4 import { FactWithIndexes } from "./utils"; 5 - import { Attributes } from "./attributes"; 5 + import { Attributes, FilterAttributes } from "./attributes"; 6 6 import { Fact } from "."; 7 7 import { MutationContext } from "./mutations"; 8 8 ··· 38 38 id = existingFact[0].id; 39 39 if (attribute.type === "text") { 40 40 const oldUpdate = base64.toByteArray( 41 - (existingFact[0]?.data as Fact<typeof f.attribute>["data"]).value, 41 + ( 42 + existingFact[0]?.data as Fact< 43 + keyof FilterAttributes<{ type: "text" }> 44 + >["data"] 45 + ).value, 42 46 ); 43 - const newUpdate = base64.toByteArray(f.data.value); 47 + let textData = data as Fact< 48 + keyof FilterAttributes<{ type: "text" }> 49 + >["data"]; 50 + const newUpdate = base64.toByteArray(textData.value); 44 51 const updateBytes = Y.mergeUpdates([oldUpdate, newUpdate]); 45 - data.value = base64.fromByteArray(updateBytes); 52 + textData.value = base64.fromByteArray(updateBytes); 46 53 } 47 54 } 48 55 }
+12 -4
replicache/serverMutationContext.ts
··· 4 4 import * as Y from "yjs"; 5 5 import { MutationContext } from "./mutations"; 6 6 import { entities, facts } from "../drizzle/schema"; 7 - import { Attributes } from "./attributes"; 7 + import { Attributes, FilterAttributes } from "./attributes"; 8 8 import { Fact } from "."; 9 9 import { DeepReadonly } from "replicache"; 10 10 export function serverMutationContext(tx: PgTransaction<any, any, any>) { ··· 58 58 id = existingFact[0].id; 59 59 if (attribute.type === "text") { 60 60 const oldUpdate = base64.toByteArray( 61 - (existingFact[0]?.data as Fact<typeof f.attribute>["data"]).value, 61 + ( 62 + existingFact[0]?.data as Fact< 63 + keyof FilterAttributes<{ type: "text" }> 64 + >["data"] 65 + ).value, 62 66 ); 63 - const newUpdate = base64.toByteArray(f.data.value); 67 + 68 + let textData = data as Fact< 69 + keyof FilterAttributes<{ type: "text" }> 70 + >["data"]; 71 + const newUpdate = base64.toByteArray(textData.value); 64 72 const updateBytes = Y.mergeUpdates([oldUpdate, newUpdate]); 65 - data.value = base64.fromByteArray(updateBytes); 73 + textData.value = base64.fromByteArray(updateBytes); 66 74 } 67 75 } 68 76 }