@draht/chord 2026.10.31 → 2026.11.5
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/cell.d.ts +7 -7
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js.map +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/contract.d.ts +51 -52
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +19 -24
- package/dist/contract.js.map +1 -1
- package/dist/delta/apply-immutable-trusted.js +3 -4
- package/dist/delta/apply-immutable-trusted.js.map +1 -1
- package/dist/delta/diff.d.ts.map +1 -1
- package/dist/delta/diff.js +5 -3
- package/dist/delta/diff.js.map +1 -1
- package/dist/delta/index.d.ts +9 -1
- package/dist/delta/index.d.ts.map +1 -1
- package/dist/delta/index.js +15 -11
- package/dist/delta/index.js.map +1 -1
- package/dist/delta/pending.d.ts +36 -0
- package/dist/delta/pending.d.ts.map +1 -0
- package/dist/delta/pending.js +143 -0
- package/dist/delta/pending.js.map +1 -0
- package/dist/delta/tracker.d.ts +12 -0
- package/dist/delta/tracker.d.ts.map +1 -1
- package/dist/delta/tracker.js +109 -39
- package/dist/delta/tracker.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/object.d.ts +4 -4
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +3 -4
- package/dist/object.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +4 -2
- package/dist/output.js.map +1 -1
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +2 -2
- package/dist/remote.js.map +1 -1
- package/dist/schema.d.ts +8 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +180 -5
- package/dist/schema.js.map +1 -1
- package/dist/sqlite/cloudflare.d.ts +2 -0
- package/dist/sqlite/cloudflare.d.ts.map +1 -1
- package/dist/sqlite/cloudflare.js +10 -0
- package/dist/sqlite/cloudflare.js.map +1 -1
- package/dist/sqlite/database.d.ts +5 -2
- package/dist/sqlite/database.d.ts.map +1 -1
- package/dist/sqlite/database.js.map +1 -1
- package/dist/sqlite/node.d.ts +4 -1
- package/dist/sqlite/node.d.ts.map +1 -1
- package/dist/sqlite/node.js +22 -5
- package/dist/sqlite/node.js.map +1 -1
- package/dist/watch.d.ts +194 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +383 -0
- package/dist/watch.js.map +1 -0
- package/dist/wire.d.ts +174 -193
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +81 -80
- package/dist/wire.js.map +1 -1
- package/docs/guide.md +15 -15
- package/docs/spec.md +8 -8
- package/docs/tutorial.md +26 -25
- package/package.json +4 -5
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AA2BtC,MAAM,UAAU,MAAM,CAAC,IAAc,EAAE,MAAgB;IACtD,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAc,EAAU,EAAiB,EAAE;IAChE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,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sB,QAAQ,CAAC,OAAO,sBAAsB,CAClH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AA0BD,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,QAAqB,EAAE,IAAY;IAC9D,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,MAAM,EAAE,IAAI,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { type Static, type TSchema, Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport { canonicalJson, fits, hash64 } from \"./schema.ts\";\nimport type { Ctx, Exposed, Readable, RefBase, StateSource } from \"./types.ts\";\n\nconst MEMBER = Symbol(\"chord.member\");\n\n/** A method's arguments and result; `undefined`: it takes no arguments, or returns nothing (void). */\nexport interface MethodSpec<\n\tA extends TSchema | undefined = TSchema | undefined,\n\tR extends TSchema | undefined = TSchema | undefined,\n> {\n\treadonly [MEMBER]: \"method\";\n\treadonly args: A;\n\treadonly result: R;\n}\n\nexport interface OpaqueSpec<T = unknown> {\n\treadonly [MEMBER]: \"opaque\";\n\treadonly id: string;\n\t/** Type carrier only; never set. */\n\treadonly type?: T;\n}\n\n/**\n * A method. `method()`: no arguments (called as `ref.name(ctx)`, implemented as `(ctx) => …`) and no result.\n * `method(args)`: no result, the handler returns nothing (void). `method(args, result)`, or `method(undefined, result)`\n * for a method without arguments that returns something.\n */\nexport function method(): MethodSpec<undefined, undefined>;\nexport function method<A extends TSchema>(args: A): MethodSpec<A, undefined>;\nexport function method<A extends TSchema | undefined, R extends TSchema>(args: A, result: R): MethodSpec<A, R>;\nexport function method(args?: TSchema, result?: TSchema): MethodSpec {\n\treturn { [MEMBER]: \"method\", args, result };\n}\n\n/** A native in-process object identified by `name@version` (local contracts only). */\nexport const opaque = <T = unknown>(id: string): OpaqueSpec<T> => {\n\tif (!/^[^@\\s]+@\\d+$/.test(id)) throw new TypeError(`opaque id must be name@version: ${id}`);\n\treturn { [MEMBER]: \"opaque\", id };\n};\n\nexport interface VariantDef {\n\treadonly state?: Readonly<Record<string, TSchema>>;\n\treadonly methods?: Readonly<Record<string, MethodSpec>>;\n}\n\n/** Where objects of a remote type live: one named host. */\nexport interface HostNamed {\n\treadonly name: string;\n}\n\n/** Where objects of a remote type live: the host `prefix` + the input's string field `key` (`session:` + `session`). */\nexport interface HostFamily<K extends string = string> {\n\treadonly prefix: string;\n\treadonly key: K;\n}\n\n/** A remote type's placement: data only, so a description carries it and every host can check it. */\nexport type Placement = HostNamed | HostFamily;\n\n/** Objects of the type live on the host named `name` (`hostNamed(\"server\")`). */\nexport function hostNamed(name: string): HostNamed {\n\tif (typeof name !== \"string\" || name === \"\") throw new TypeError(\"hostNamed needs a host name\");\n\treturn { name };\n}\n\n/**\n * Objects of the type live on `prefix` + the value of the input's string field `key`: `hostFamily(\"session:\",\n * \"session\")` puts `{ session: \"S1\", … }` on `session:S1`. The field is required and must be a non-empty string.\n */\nexport function hostFamily<const K extends string>(prefix: string, key: K): HostFamily<K> {\n\tif (typeof prefix !== \"string\" || prefix === \"\") throw new TypeError(\"hostFamily needs a host-name prefix\");\n\tif (typeof key !== \"string\" || key === \"\") throw new TypeError(\"hostFamily needs an input field name\");\n\treturn { prefix, key };\n}\n\n/** Required string fields of `I`: what a `hostFamily` may name. */\ntype StringKeys<I> = { [K in keyof I]-?: I[K] extends string ? K : never }[keyof I] & string;\n/** The placements a remote type with input `I` may have. */\nexport type PlacementFor<I> = HostNamed | HostFamily<StringKeys<I>>;\n\n/** The host an object of `placement` with this (normalized) input lives on. Throws `invalid/placement`. */\nexport function resolveHost(typeName: string, placement: Placement, input: unknown): string {\n\tif (\"name\" in placement) return placement.name;\n\tconst value =\n\t\tinput !== null && typeof input === \"object\" ? (input as Record<string, unknown>)[placement.key] : undefined;\n\tif (typeof value !== \"string\" || value === \"\")\n\t\tthrow invalid(\"placement\", `${typeName}: input field ${placement.key} names no host`);\n\treturn placement.prefix + value;\n}\n\n/** Whether the host named `hostName` may serve a type of `placement`. */\nexport const placedOn = (placement: Placement, hostName: string): boolean =>\n\t\"name\" in placement\n\t\t? placement.name === hostName\n\t\t: hostName.startsWith(placement.prefix) && hostName.length > placement.prefix.length;\n\nexport const placementText = (placement: Placement): string =>\n\t\"name\" in placement ? placement.name : `${placement.prefix}<${placement.key}>`;\n\nexport interface RemoteDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\t/** Where its objects live: `hostNamed(…)` or `hostFamily(…)`. Part of the contract (and its fingerprint). */\n\treadonly host: Placement;\n\treadonly variants: Readonly<Record<string, VariantDef>>;\n}\n\n/** A local member: a method, an opaque native object, or a state member described by its schema. */\nexport type LocalMember = MethodSpec | OpaqueSpec | TSchema;\n\nexport interface LocalDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly members?: Readonly<Record<string, LocalMember>>;\n}\n\n// A description travels as a reference's contract token (wire.ts), so it is declared once, as the schema that validates it.\n// `TSchema` is an empty interface: any object is one, which is all a peer's schema is checked for here.\nconst SchemaObject = Type.Unsafe<TSchema>(Type.Object({}));\n\nconst MemberDescriptionSchema = Type.Union([\n\t// Absent `args`: the method takes none. Absent `result`: it returns nothing.\n\tType.Object({\n\t\tkind: Type.Literal(\"method\"),\n\t\targs: Type.Optional(SchemaObject),\n\t\tresult: Type.Optional(SchemaObject),\n\t}),\n\tType.Object({ kind: Type.Literal(\"state\"), schema: SchemaObject }),\n\tType.Object({ kind: Type.Literal(\"opaque\"), id: Type.String() }),\n]);\nexport type MemberDescription = Static<typeof MemberDescriptionSchema>;\n\n/** Local contracts have one unnamed variant. */\nexport const LOCAL_VARIANT = \"\";\n\nconst PlacementSchema = Type.Union([\n\tType.Object({ name: Type.String({ minLength: 1 }) }, { additionalProperties: false }),\n\tType.Object(\n\t\t{ prefix: Type.String({ minLength: 1 }), key: Type.String({ minLength: 1 }) },\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nexport const DescriptionSchema = Type.Object({\n\tname: Type.String({ minLength: 1 }),\n\tscope: Type.Union([Type.Literal(\"remote\"), Type.Literal(\"local\")]),\n\tversion: Type.Integer(),\n\tinput: SchemaObject,\n\t/** Remote types only (required there): where their objects live. */\n\thost: Type.Optional(PlacementSchema),\n\tvariants: Type.Record(Type.String(), Type.Record(Type.String(), MemberDescriptionSchema)),\n});\nexport type Description = Static<typeof DescriptionSchema>;\n\ninterface ContractBase {\n\treadonly name: string;\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly description: Description;\n\treadonly fingerprint: string;\n}\n\nexport interface RemoteContract<D extends RemoteDef = RemoteDef> extends ContractBase {\n\treadonly scope: \"remote\";\n\treadonly def: D;\n}\n\nexport interface LocalContract<D extends LocalDef = LocalDef> extends ContractBase {\n\treadonly scope: \"local\";\n\treadonly def: D;\n}\n\nexport type AnyContract = RemoteContract | LocalContract;\n\n/** Names a reference uses itself; members may not use them. */\nexport const RESERVED_MEMBERS: ReadonlySet<string> = new Set([\n\t\"variant\",\n\t\"status\",\n\t\"ready\",\n\t\"shape\",\n\t\"error\",\n\t\"onShape\",\n\t\"onStatus\",\n\t\"release\",\n\t\"then\",\n\t\"contract\",\n]);\n\nfunction describeMember(name: string, member: unknown, scope: \"remote\" | \"local\"): MemberDescription {\n\tif (RESERVED_MEMBERS.has(name)) throw new TypeError(`member name is reserved: ${name}`);\n\tconst brand = (member as { [MEMBER]?: string })[MEMBER];\n\tif (brand === \"method\") {\n\t\tconst spec = member as MethodSpec;\n\t\treturn {\n\t\t\tkind: \"method\",\n\t\t\t...(spec.args === undefined ? {} : { args: spec.args }),\n\t\t\t...(spec.result === undefined ? {} : { result: spec.result }),\n\t\t};\n\t}\n\tif (brand === \"opaque\") {\n\t\tif (scope === \"remote\") throw new TypeError(`remote contracts cannot expose opaque members: ${name}`);\n\t\treturn { kind: \"opaque\", id: (member as OpaqueSpec).id };\n\t}\n\treturn { kind: \"state\", schema: member as TSchema };\n}\n\nfunction finish<C extends AnyContract>(contract: Omit<C, \"fingerprint\">): C {\n\treturn { ...contract, fingerprint: hash64(canonicalJson(contract.description)) } as C;\n}\n\nfunction checkHeader(name: string, version: number): void {\n\tif (!name) throw new TypeError(\"contract name is empty\");\n\tif (!Number.isInteger(version) || version < 1) throw new TypeError(`contract version must be a positive integer`);\n}\n\nexport function remote<const D extends RemoteDef>(\n\tname: string,\n\tdef: D & { readonly host: PlacementFor<Static<D[\"input\"]>> },\n): RemoteContract<D> {\n\tcheckHeader(name, def.version);\n\tconst placement = def.host as Placement | undefined;\n\tif (placement === undefined || !Value.Check(PlacementSchema, placement))\n\t\tthrow new TypeError(`remote contract ${name} needs \\`host\\`: hostNamed(…) or hostFamily(…)`);\n\t// A JSON copy: the description travels, and a placement object may carry nothing else.\n\tconst host: Placement =\n\t\t\"name\" in placement ? { name: placement.name } : { prefix: placement.prefix, key: placement.key };\n\tconst variants: Record<string, Record<string, MemberDescription>> = {};\n\tif (Object.keys(def.variants).length === 0) throw new TypeError(`remote contract ${name} has no variants`);\n\tfor (const [kind, variant] of Object.entries(def.variants)) {\n\t\tconst members: Record<string, MemberDescription> = {};\n\t\tfor (const [key, schema] of Object.entries(variant.state ?? {}))\n\t\t\tmembers[key] = describeMember(key, schema, \"remote\");\n\t\tfor (const [key, spec] of Object.entries(variant.methods ?? {})) {\n\t\t\tif (key in members) throw new TypeError(`member ${key} is both state and method in ${name}.${kind}`);\n\t\t\tmembers[key] = describeMember(key, spec, \"remote\");\n\t\t\tif (members[key].kind !== \"method\") throw new TypeError(`methods.${key} is not a method()`);\n\t\t}\n\t\tvariants[kind] = members;\n\t}\n\tconst description: Description = { name, scope: \"remote\", version: def.version, input: def.input, host, variants };\n\treturn finish<RemoteContract<D>>({\n\t\tscope: \"remote\",\n\t\tname,\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tdef,\n\t\tdescription,\n\t});\n}\n\nexport function local<const D extends LocalDef>(name: string, def: D): LocalContract<D> {\n\tcheckHeader(name, def.version);\n\tconst members: Record<string, MemberDescription> = {};\n\tfor (const [key, member] of Object.entries(def.members ?? {})) members[key] = describeMember(key, member, \"local\");\n\tconst description: Description = {\n\t\tname,\n\t\tscope: \"local\",\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tvariants: { [LOCAL_VARIANT]: members },\n\t};\n\treturn finish<LocalContract<D>>({ scope: \"local\", name, version: def.version, input: def.input, def, description });\n}\n\n/**\n * A consumer token received over a link (only its description travels). Has no `def`, so it is only good for binding\n * and validation, never for TypeScript types.\n */\nexport function contractFromDescription(description: Description): AnyContract {\n\tconst { name, scope, version, input, host } = description;\n\tif (\n\t\ttypeof name !== \"string\" ||\n\t\t(scope !== \"remote\" && scope !== \"local\") ||\n\t\t!Number.isInteger(version) ||\n\t\t(scope === \"remote\") !== (host !== undefined)\n\t) {\n\t\tthrow new ChordError(\"invalid\", \"malformed contract token\", { reason: \"token\" });\n\t}\n\tconst base = { name, version, input, description, fingerprint: hash64(canonicalJson(description)) };\n\treturn scope === \"remote\"\n\t\t? { ...base, scope, def: { version, input, host: host!, variants: {} } }\n\t\t: { ...base, scope, def: { version, input } };\n}\n\n/** Returns why `provider` does not cover `consumer`, or undefined when it does. */\nexport function coverage(provider: Description, consumer: Description): string | undefined {\n\tif (provider.name !== consumer.name || provider.scope !== consumer.scope) return \"different type\";\n\tif (!samePlacement(provider, consumer)) return \"host\";\n\tif (!fits(consumer.input, provider.input)) return \"input\";\n\tfor (const [kind, consumerMembers] of Object.entries(consumer.variants)) {\n\t\tconst providerMembers = provider.variants[kind];\n\t\tif (providerMembers === undefined) return `variant ${kind} missing`;\n\t\tfor (const [name, wanted] of Object.entries(consumerMembers)) {\n\t\t\tconst offered = providerMembers[name];\n\t\t\tif (offered === undefined || offered.kind !== wanted.kind) return `${kind}.${name} missing or of another kind`;\n\t\t\tif (offered.kind === \"method\" && wanted.kind === \"method\") {\n\t\t\t\t// Both take arguments or neither does; a consumer that expects no result accepts any.\n\t\t\t\tif ((wanted.args === undefined) !== (offered.args === undefined)) return `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.args !== undefined && offered.args !== undefined && !fits(wanted.args, offered.args))\n\t\t\t\t\treturn `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.result !== undefined && (offered.result === undefined || !fits(offered.result, wanted.result)))\n\t\t\t\t\treturn `${kind}.${name} result`;\n\t\t\t} else if (offered.kind === \"state\" && wanted.kind === \"state\") {\n\t\t\t\tif (!fits(offered.schema, wanted.schema)) return `${kind}.${name} state`;\n\t\t\t} else if (offered.kind === \"opaque\" && wanted.kind === \"opaque\" && offered.id !== wanted.id) {\n\t\t\t\treturn `${kind}.${name} opaque ${offered.id} != ${wanted.id}`;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nconst samePlacement = (a: Description, b: Description): boolean =>\n\tcanonicalJson(a.host ?? null) === canonicalJson(b.host ?? null);\nconst placementOf = (description: Description): string =>\n\tdescription.host === undefined ? \"(local)\" : placementText(description.host);\n\n/** Maps the provider's current implementation to the view a consumer of an older contract version expects. */\nexport type Adapter = (current: Record<string, unknown>) => Record<string, unknown>;\nexport type Accepts = Readonly<Record<number, Adapter>>;\n\n/** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */\nexport function bind(provider: AnyContract, accepts: Accepts | undefined, consumer: AnyContract): Adapter | undefined {\n\tif (provider.fingerprint === consumer.fingerprint) return undefined;\n\t// A moved type is another type for its consumers: no adapter reaches across hosts.\n\tif (!samePlacement(provider.description, consumer.description)) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name} lives on ${placementOf(provider.description)}, the consumer expects ${placementOf(consumer.description)}`,\n\t\t);\n\t}\n\tif (provider.version === consumer.version) {\n\t\tconst reason = coverage(provider.description, consumer.description);\n\t\tif (reason === undefined) return undefined;\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}@${provider.version} does not cover the consumer's description (${reason}); forgotten version bump?`,\n\t\t);\n\t}\n\tconst adapter = accepts?.[consumer.version];\n\tif (adapter === undefined) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}: provider version ${provider.version}, consumer version ${consumer.version}, no accepts adapter`,\n\t\t);\n\t}\n\treturn adapter;\n}\n\n// ─── Static types ────────────────────────────────────────────────────────────\n\ntype Empty = Record<never, never>;\ntype StateOf<V> = V extends { readonly state: infer S extends Readonly<Record<string, TSchema>> } ? S : Empty;\ntype StaticOf<S> = S extends TSchema ? Static<S> : never;\ntype MethodsOf<V> = V extends { readonly methods: infer M extends Readonly<Record<string, MethodSpec>> } ? M : Empty;\n\n/** What a handler returns: the result's value, or nothing for a void method. */\ntype Returned<R> = [R] extends [TSchema] ? Static<R> | Promise<Static<R>> : void | Promise<void>;\n/** What a call resolves to. */\ntype Resolved<R> = [R] extends [TSchema] ? Static<R> : undefined;\n\n/** A method's handler; `P` is the app's principal type (`ctx.principal`). */\nexport type MethodImplementation<M, P = unknown> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [TSchema]\n\t\t? (args: Static<A>, ctx: Ctx<P>) => Returned<R>\n\t\t: (ctx: Ctx<P>) => Returned<R>\n\t: never;\nexport type Call<M> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [TSchema]\n\t\t? (args: Static<A>, ctx?: Ctx) => Promise<Resolved<R>>\n\t\t: (ctx?: Ctx) => Promise<Resolved<R>>\n\t: never;\n\n/** Whether `contract`'s method `name` takes no arguments (it is called as `ref.name(ctx)`). */\nexport function takesNoArgs(contract: AnyContract, name: string): boolean {\n\tfor (const members of Object.values(contract.description.variants)) {\n\t\tconst member = members[name];\n\t\tif (member?.kind === \"method\") return member.args === undefined;\n\t}\n\treturn false;\n}\n\ntype VariantImplementation<K, V, P> = { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: StateSource<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: MethodImplementation<MethodsOf<V>[M], P>;\n};\n/**\n * A reference in one variant: its state members are plain readables (a reference you hold has its state) and its\n * methods calls. `variant` discriminates the union `Ref` is for a multi-variant type.\n */\ntype VariantRef<C extends AnyContract, K, V> = RefBase<C> & { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: Call<MethodsOf<V>[M]>;\n};\n\ntype LocalImplementationMember<M, P> = M extends MethodSpec\n\t? MethodImplementation<M, P>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | Exposed<T>\n\t\t: M extends TSchema\n\t\t\t? StateSource<Static<M>>\n\t\t\t: never;\ntype LocalRefMember<M> = M extends MethodSpec\n\t? Call<M>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | undefined\n\t\t: M extends TSchema\n\t\t\t? Readable<Static<M>>\n\t\t\t: never;\ntype LocalMembers<D> = D extends { readonly members: infer M extends Readonly<Record<string, LocalMember>> }\n\t? M\n\t: Empty;\n\nexport type InputOf<C> = C extends { readonly def: { readonly input: infer I extends TSchema } } ? Static<I> : never;\n\n/** What a factory returns for contract C; its methods' `ctx.principal` is `P`. */\nexport type ImplementationOf<C, P = unknown> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantImplementation<K, D[\"variants\"][K], P> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? { readonly [K in keyof LocalMembers<D>]: LocalImplementationMember<LocalMembers<D>[K], P> } & Record<\n\t\t\t\tstring,\n\t\t\t\tunknown\n\t\t\t>\n\t\t: never;\n\n/**\n * What `get` returns for contract C. A remote type's reference is a union discriminated by `variant`: another variant's\n * members are reachable only after narrowing (`if (ref.variant === \"editor\") ref.add(…)`). A local type's reference has\n * its members.\n */\nexport type Ref<C extends AnyContract = AnyContract> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantRef<C, K, D[\"variants\"][K]> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? RefBase<C> & { readonly [K in keyof LocalMembers<D>]: LocalRefMember<LocalMembers<D>[K]> }\n\t\t: never;\n"]}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAA4B,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGnE,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AA2BtC,MAAM,UAAU,MAAM,CAAC,IAAa,EAAE,MAAe;IACpD,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAc,EAAU,EAAiB,EAAE;IAChE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;IAC5F,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC;AAqBF,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,6BA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AE,CAC3H,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;QACpE,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC3C,MAAM,IAAI,UAAU,CACnB,mBAAmB,EACnB,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,+CAA+C,MAAM,4BAA4B,CACrH,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CACnB,mBAAmB,EACnB,GAAG,QAAQ,CAAC,IAAI,sBAAsB,QAAQ,CAAC,OAAO,sBAAsB,QAAQ,CAAC,OAAO,sBAAsB,CAClH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AA0BD,+FAA+F;AAC/F,MAAM,UAAU,WAAW,CAAC,QAAqB,EAAE,IAAY;IAC9D,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,MAAM,EAAE,IAAI,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { int, lit, map, obj, opt, type Schema, type Static, str, union } from \"@draht/schema\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport { canonicalJson, fits, hash64, isValid } from \"./schema.ts\";\nimport type { Ctx, Exposed, Readable, RefBase, StateSource } from \"./types.ts\";\n\nconst MEMBER = Symbol(\"chord.member\");\n\n/** A method's arguments and result; `undefined`: it takes no arguments, or returns nothing (void). */\nexport interface MethodSpec<\n\tA extends Schema | undefined = Schema | undefined,\n\tR extends Schema | undefined = Schema | undefined,\n> {\n\treadonly [MEMBER]: \"method\";\n\treadonly args: A;\n\treadonly result: R;\n}\n\nexport interface OpaqueSpec<T = unknown> {\n\treadonly [MEMBER]: \"opaque\";\n\treadonly id: string;\n\t/** Type carrier only; never set. */\n\treadonly type?: T;\n}\n\n/**\n * A method. `method()`: no arguments (called as `ref.name(ctx)`, implemented as `(ctx) => …`) and no result.\n * `method(args)`: no result, the handler returns nothing (void). `method(args, result)`, or `method(undefined, result)`\n * for a method without arguments that returns something.\n */\nexport function method(): MethodSpec<undefined, undefined>;\nexport function method<A extends Schema>(args: A): MethodSpec<A, undefined>;\nexport function method<A extends Schema | undefined, R extends Schema>(args: A, result: R): MethodSpec<A, R>;\nexport function method(args?: Schema, result?: Schema): MethodSpec {\n\treturn { [MEMBER]: \"method\", args, result };\n}\n\n/** A native in-process object identified by `name@version` (local contracts only). */\nexport const opaque = <T = unknown>(id: string): OpaqueSpec<T> => {\n\tif (!/^[^@\\s]+@\\d+$/.test(id)) throw new TypeError(`opaque id must be name@version: ${id}`);\n\treturn { [MEMBER]: \"opaque\", id };\n};\n\nexport interface VariantDef {\n\treadonly state?: Readonly<Record<string, Schema>>;\n\treadonly methods?: Readonly<Record<string, MethodSpec>>;\n}\n\n/** Where objects of a remote type live: one named host. */\nexport interface HostNamed {\n\treadonly name: string;\n}\n\n/** Where objects of a remote type live: the host `prefix` + the input's string field `key` (`session:` + `session`). */\nexport interface HostFamily<K extends string = string> {\n\treadonly prefix: string;\n\treadonly key: K;\n}\n\n/** A remote type's placement: data only, so a description carries it and every host can check it. */\nexport type Placement = HostNamed | HostFamily;\n\n/** Objects of the type live on the host named `name` (`hostNamed(\"server\")`). */\nexport function hostNamed(name: string): HostNamed {\n\tif (typeof name !== \"string\" || name === \"\") throw new TypeError(\"hostNamed needs a host name\");\n\treturn { name };\n}\n\n/**\n * Objects of the type live on `prefix` + the value of the input's string field `key`: `hostFamily(\"session:\",\n * \"session\")` puts `{ session: \"S1\", … }` on `session:S1`. The field is required and must be a non-empty string.\n */\nexport function hostFamily<const K extends string>(prefix: string, key: K): HostFamily<K> {\n\tif (typeof prefix !== \"string\" || prefix === \"\") throw new TypeError(\"hostFamily needs a host-name prefix\");\n\tif (typeof key !== \"string\" || key === \"\") throw new TypeError(\"hostFamily needs an input field name\");\n\treturn { prefix, key };\n}\n\n/** Required string fields of `I`: what a `hostFamily` may name. */\ntype StringKeys<I> = { [K in keyof I]-?: I[K] extends string ? K : never }[keyof I] & string;\n/** The placements a remote type with input `I` may have. */\nexport type PlacementFor<I> = HostNamed | HostFamily<StringKeys<I>>;\n\n/** The host an object of `placement` with this (normalized) input lives on. Throws `invalid/placement`. */\nexport function resolveHost(typeName: string, placement: Placement, input: unknown): string {\n\tif (\"name\" in placement) return placement.name;\n\tconst value =\n\t\tinput !== null && typeof input === \"object\" ? (input as Record<string, unknown>)[placement.key] : undefined;\n\tif (typeof value !== \"string\" || value === \"\")\n\t\tthrow invalid(\"placement\", `${typeName}: input field ${placement.key} names no host`);\n\treturn placement.prefix + value;\n}\n\n/** Whether the host named `hostName` may serve a type of `placement`. */\nexport const placedOn = (placement: Placement, hostName: string): boolean =>\n\t\"name\" in placement\n\t\t? placement.name === hostName\n\t\t: hostName.startsWith(placement.prefix) && hostName.length > placement.prefix.length;\n\nexport const placementText = (placement: Placement): string =>\n\t\"name\" in placement ? placement.name : `${placement.prefix}<${placement.key}>`;\n\nexport interface RemoteDef {\n\treadonly version: number;\n\treadonly input: Schema;\n\t/** Where its objects live: `hostNamed(…)` or `hostFamily(…)`. Part of the contract (and its fingerprint). */\n\treadonly host: Placement;\n\treadonly variants: Readonly<Record<string, VariantDef>>;\n}\n\n/** A local member: a method, an opaque native object, or a state member described by its schema. */\nexport type LocalMember = MethodSpec | OpaqueSpec | Schema;\n\nexport interface LocalDef {\n\treadonly version: number;\n\treadonly input: Schema;\n\treadonly members?: Readonly<Record<string, LocalMember>>;\n}\n\n// A description travels as a reference's contract token (wire.ts), so it is declared once, as the schema that validates it.\n// Any object is a schema, which is all a peer's schema is checked for here.\nconst SchemaObject = obj({}, { open: true }) as Schema<Schema>;\n\nconst MemberDescriptionSchema = union([\n\t// Absent `args`: the method takes none. Absent `result`: it returns nothing.\n\tobj({ kind: lit(\"method\"), args: opt(SchemaObject), result: opt(SchemaObject) }, { open: true }),\n\tobj({ kind: lit(\"state\"), schema: SchemaObject }, { open: true }),\n\tobj({ kind: lit(\"opaque\"), id: str() }, { open: true }),\n]);\nexport type MemberDescription = Static<typeof MemberDescriptionSchema>;\n\n/** Local contracts have one unnamed variant. */\nexport const LOCAL_VARIANT = \"\";\n\nconst PlacementSchema = union([\n\tobj({ name: str({ minLength: 1 }) }),\n\tobj({ prefix: str({ minLength: 1 }), key: str({ minLength: 1 }) }),\n]);\n\nexport const DescriptionSchema = obj(\n\t{\n\t\tname: str({ minLength: 1 }),\n\t\tscope: union([lit(\"remote\"), lit(\"local\")]),\n\t\tversion: int(),\n\t\tinput: SchemaObject,\n\t\t/** Remote types only (required there): where their objects live. */\n\t\thost: opt(PlacementSchema),\n\t\tvariants: map(map(MemberDescriptionSchema)),\n\t},\n\t{ open: true },\n);\nexport type Description = Static<typeof DescriptionSchema>;\n\ninterface ContractBase {\n\treadonly name: string;\n\treadonly version: number;\n\treadonly input: Schema;\n\treadonly description: Description;\n\treadonly fingerprint: string;\n}\n\nexport interface RemoteContract<D extends RemoteDef = RemoteDef> extends ContractBase {\n\treadonly scope: \"remote\";\n\treadonly def: D;\n}\n\nexport interface LocalContract<D extends LocalDef = LocalDef> extends ContractBase {\n\treadonly scope: \"local\";\n\treadonly def: D;\n}\n\nexport type AnyContract = RemoteContract | LocalContract;\n\n/** Names a reference uses itself; members may not use them. */\nexport const RESERVED_MEMBERS: ReadonlySet<string> = new Set([\n\t\"variant\",\n\t\"status\",\n\t\"ready\",\n\t\"shape\",\n\t\"error\",\n\t\"onShape\",\n\t\"onStatus\",\n\t\"release\",\n\t\"then\",\n\t\"contract\",\n]);\n\nfunction describeMember(name: string, member: unknown, scope: \"remote\" | \"local\"): MemberDescription {\n\tif (RESERVED_MEMBERS.has(name)) throw new TypeError(`member name is reserved: ${name}`);\n\tconst brand = (member as { [MEMBER]?: string })[MEMBER];\n\tif (brand === \"method\") {\n\t\tconst spec = member as MethodSpec;\n\t\treturn {\n\t\t\tkind: \"method\",\n\t\t\t...(spec.args === undefined ? {} : { args: spec.args }),\n\t\t\t...(spec.result === undefined ? {} : { result: spec.result }),\n\t\t};\n\t}\n\tif (brand === \"opaque\") {\n\t\tif (scope === \"remote\") throw new TypeError(`remote contracts cannot expose opaque members: ${name}`);\n\t\treturn { kind: \"opaque\", id: (member as OpaqueSpec).id };\n\t}\n\treturn { kind: \"state\", schema: member as Schema };\n}\n\nfunction finish<C extends AnyContract>(contract: Omit<C, \"fingerprint\">): C {\n\treturn { ...contract, fingerprint: hash64(canonicalJson(contract.description)) } as C;\n}\n\nfunction checkHeader(name: string, version: number): void {\n\tif (!name) throw new TypeError(\"contract name is empty\");\n\tif (!Number.isInteger(version) || version < 1) throw new TypeError(`contract version must be a positive integer`);\n}\n\nexport function remote<const D extends RemoteDef>(\n\tname: string,\n\tdef: D & { readonly host: PlacementFor<Static<D[\"input\"]>> },\n): RemoteContract<D> {\n\tcheckHeader(name, def.version);\n\tconst placement = def.host as Placement | undefined;\n\tif (placement === undefined || !isValid(PlacementSchema, placement))\n\t\tthrow new TypeError(`remote contract ${name} needs \\`host\\`: hostNamed(…) or hostFamily(…)`);\n\t// A JSON copy: the description travels, and a placement object may carry nothing else.\n\tconst host: Placement =\n\t\t\"name\" in placement ? { name: placement.name } : { prefix: placement.prefix, key: placement.key };\n\tconst variants: Record<string, Record<string, MemberDescription>> = {};\n\tif (Object.keys(def.variants).length === 0) throw new TypeError(`remote contract ${name} has no variants`);\n\tfor (const [kind, variant] of Object.entries(def.variants)) {\n\t\tconst members: Record<string, MemberDescription> = {};\n\t\tfor (const [key, schema] of Object.entries(variant.state ?? {}))\n\t\t\tmembers[key] = describeMember(key, schema, \"remote\");\n\t\tfor (const [key, spec] of Object.entries(variant.methods ?? {})) {\n\t\t\tif (key in members) throw new TypeError(`member ${key} is both state and method in ${name}.${kind}`);\n\t\t\tmembers[key] = describeMember(key, spec, \"remote\");\n\t\t\tif (members[key].kind !== \"method\") throw new TypeError(`methods.${key} is not a method()`);\n\t\t}\n\t\tvariants[kind] = members;\n\t}\n\tconst description: Description = { name, scope: \"remote\", version: def.version, input: def.input, host, variants };\n\treturn finish<RemoteContract<D>>({\n\t\tscope: \"remote\",\n\t\tname,\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tdef,\n\t\tdescription,\n\t});\n}\n\nexport function local<const D extends LocalDef>(name: string, def: D): LocalContract<D> {\n\tcheckHeader(name, def.version);\n\tconst members: Record<string, MemberDescription> = {};\n\tfor (const [key, member] of Object.entries(def.members ?? {})) members[key] = describeMember(key, member, \"local\");\n\tconst description: Description = {\n\t\tname,\n\t\tscope: \"local\",\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tvariants: { [LOCAL_VARIANT]: members },\n\t};\n\treturn finish<LocalContract<D>>({ scope: \"local\", name, version: def.version, input: def.input, def, description });\n}\n\n/**\n * A consumer token received over a link (only its description travels). Has no `def`, so it is only good for binding\n * and validation, never for TypeScript types.\n */\nexport function contractFromDescription(description: Description): AnyContract {\n\tconst { name, scope, version, input, host } = description;\n\tif (\n\t\ttypeof name !== \"string\" ||\n\t\t(scope !== \"remote\" && scope !== \"local\") ||\n\t\t!Number.isInteger(version) ||\n\t\t(scope === \"remote\") !== (host !== undefined)\n\t) {\n\t\tthrow new ChordError(\"invalid\", \"malformed contract token\", { reason: \"token\" });\n\t}\n\tconst base = { name, version, input, description, fingerprint: hash64(canonicalJson(description)) };\n\treturn scope === \"remote\"\n\t\t? { ...base, scope, def: { version, input, host: host!, variants: {} } }\n\t\t: { ...base, scope, def: { version, input } };\n}\n\n/** Returns why `provider` does not cover `consumer`, or undefined when it does. */\nexport function coverage(provider: Description, consumer: Description): string | undefined {\n\tif (provider.name !== consumer.name || provider.scope !== consumer.scope) return \"different type\";\n\tif (!samePlacement(provider, consumer)) return \"host\";\n\tif (!fits(consumer.input, provider.input)) return \"input\";\n\tfor (const [kind, consumerMembers] of Object.entries(consumer.variants)) {\n\t\tconst providerMembers = provider.variants[kind];\n\t\tif (providerMembers === undefined) return `variant ${kind} missing`;\n\t\tfor (const [name, wanted] of Object.entries(consumerMembers)) {\n\t\t\tconst offered = providerMembers[name];\n\t\t\tif (offered === undefined || offered.kind !== wanted.kind) return `${kind}.${name} missing or of another kind`;\n\t\t\tif (offered.kind === \"method\" && wanted.kind === \"method\") {\n\t\t\t\t// Both take arguments or neither does; a consumer that expects no result accepts any.\n\t\t\t\tif ((wanted.args === undefined) !== (offered.args === undefined)) return `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.args !== undefined && offered.args !== undefined && !fits(wanted.args, offered.args))\n\t\t\t\t\treturn `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.result !== undefined && (offered.result === undefined || !fits(offered.result, wanted.result)))\n\t\t\t\t\treturn `${kind}.${name} result`;\n\t\t\t} else if (offered.kind === \"state\" && wanted.kind === \"state\") {\n\t\t\t\tif (!fits(offered.schema, wanted.schema)) return `${kind}.${name} state`;\n\t\t\t} else if (offered.kind === \"opaque\" && wanted.kind === \"opaque\" && offered.id !== wanted.id) {\n\t\t\t\treturn `${kind}.${name} opaque ${offered.id} != ${wanted.id}`;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nconst samePlacement = (a: Description, b: Description): boolean =>\n\tcanonicalJson(a.host ?? null) === canonicalJson(b.host ?? null);\nconst placementOf = (description: Description): string =>\n\tdescription.host === undefined ? \"(local)\" : placementText(description.host);\n\n/** Maps the provider's current implementation to the view a consumer of an older contract version expects. */\nexport type Adapter = (current: Record<string, unknown>) => Record<string, unknown>;\nexport type Accepts = Readonly<Record<number, Adapter>>;\n\n/** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */\nexport function bind(provider: AnyContract, accepts: Accepts | undefined, consumer: AnyContract): Adapter | undefined {\n\tif (provider.fingerprint === consumer.fingerprint) return undefined;\n\t// A moved type is another type for its consumers: no adapter reaches across hosts.\n\tif (!samePlacement(provider.description, consumer.description)) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name} lives on ${placementOf(provider.description)}, the consumer expects ${placementOf(consumer.description)}`,\n\t\t);\n\t}\n\tif (provider.version === consumer.version) {\n\t\tconst reason = coverage(provider.description, consumer.description);\n\t\tif (reason === undefined) return undefined;\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}@${provider.version} does not cover the consumer's description (${reason}); forgotten version bump?`,\n\t\t);\n\t}\n\tconst adapter = accepts?.[consumer.version];\n\tif (adapter === undefined) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}: provider version ${provider.version}, consumer version ${consumer.version}, no accepts adapter`,\n\t\t);\n\t}\n\treturn adapter;\n}\n\n// ─── Static types ────────────────────────────────────────────────────────────\n\ntype Empty = Record<never, never>;\ntype StateOf<V> = V extends { readonly state: infer S extends Readonly<Record<string, Schema>> } ? S : Empty;\ntype StaticOf<S> = S extends Schema ? Static<S> : never;\ntype MethodsOf<V> = V extends { readonly methods: infer M extends Readonly<Record<string, MethodSpec>> } ? M : Empty;\n\n/** What a handler returns: the result's value, or nothing for a void method. */\ntype Returned<R> = [R] extends [Schema] ? Static<R> | Promise<Static<R>> : void | Promise<void>;\n/** What a call resolves to. */\ntype Resolved<R> = [R] extends [Schema] ? Static<R> : undefined;\n\n/** A method's handler; `P` is the app's principal type (`ctx.principal`). */\nexport type MethodImplementation<M, P = unknown> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [Schema]\n\t\t? (args: Static<A>, ctx: Ctx<P>) => Returned<R>\n\t\t: (ctx: Ctx<P>) => Returned<R>\n\t: never;\nexport type Call<M> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [Schema]\n\t\t? (args: Static<A>, ctx?: Ctx) => Promise<Resolved<R>>\n\t\t: (ctx?: Ctx) => Promise<Resolved<R>>\n\t: never;\n\n/** Whether `contract`'s method `name` takes no arguments (it is called as `ref.name(ctx)`). */\nexport function takesNoArgs(contract: AnyContract, name: string): boolean {\n\tfor (const members of Object.values(contract.description.variants)) {\n\t\tconst member = members[name];\n\t\tif (member?.kind === \"method\") return member.args === undefined;\n\t}\n\treturn false;\n}\n\ntype VariantImplementation<K, V, P> = { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: StateSource<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: MethodImplementation<MethodsOf<V>[M], P>;\n};\n/**\n * A reference in one variant: its state members are plain readables (a reference you hold has its state) and its\n * methods calls. `variant` discriminates the union `Ref` is for a multi-variant type.\n */\ntype VariantRef<C extends AnyContract, K, V> = RefBase<C> & { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: Call<MethodsOf<V>[M]>;\n};\n\ntype LocalImplementationMember<M, P> = M extends MethodSpec\n\t? MethodImplementation<M, P>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | Exposed<T>\n\t\t: M extends Schema\n\t\t\t? StateSource<Static<M>>\n\t\t\t: never;\ntype LocalRefMember<M> = M extends MethodSpec\n\t? Call<M>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | undefined\n\t\t: M extends Schema\n\t\t\t? Readable<Static<M>>\n\t\t\t: never;\ntype LocalMembers<D> = D extends { readonly members: infer M extends Readonly<Record<string, LocalMember>> }\n\t? M\n\t: Empty;\n\nexport type InputOf<C> = C extends { readonly def: { readonly input: infer I extends Schema } } ? Static<I> : never;\n\n/** What a factory returns for contract C; its methods' `ctx.principal` is `P`. */\nexport type ImplementationOf<C, P = unknown> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantImplementation<K, D[\"variants\"][K], P> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? { readonly [K in keyof LocalMembers<D>]: LocalImplementationMember<LocalMembers<D>[K], P> } & Record<\n\t\t\t\tstring,\n\t\t\t\tunknown\n\t\t\t>\n\t\t: never;\n\n/**\n * What `get` returns for contract C. A remote type's reference is a union discriminated by `variant`: another variant's\n * members are reachable only after narrowing (`if (ref.variant === \"editor\") ref.add(…)`). A local type's reference has\n * its members.\n */\nexport type Ref<C extends AnyContract = AnyContract> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantRef<C, K, D[\"variants\"][K]> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? RefBase<C> & { readonly [K in keyof LocalMembers<D>]: LocalRefMember<LocalMembers<D>[K]> }\n\t\t: never;\n"]}
|
|
@@ -87,10 +87,9 @@ function copyPath(root, path, length, owned) {
|
|
|
87
87
|
function shallowCopy(value) {
|
|
88
88
|
if (Array.isArray(value))
|
|
89
89
|
return Array.from(value);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return result;
|
|
90
|
+
// Spread and `Object.assign()` onto a null-prototype object define own data properties, `__proto__` included, as
|
|
91
|
+
// `defineData()` per key does, at a fraction of its cost.
|
|
92
|
+
return Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };
|
|
94
93
|
}
|
|
95
94
|
function read(target, key) {
|
|
96
95
|
return target[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-immutable-trusted.js","sourceRoot":"","sources":["../../src/delta/apply-immutable-trusted.ts"],"names":[],"mappings":"AAMA,MAAM,eAAe,GAAuB;IAC3C,K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AAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;SAAM,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC;QACnE,MAAM,CAAC,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC;IACnC,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE;QAAE,UAAU,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC;AACrG,CAAC;AAED,SAAS,cAAc,CAAC,MAAmB,EAAE,WAA8B;IAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM;QAAE,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;IACrG,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IAChC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE;QAAE,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAE,CAAE,CAAC;AACzG,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\nimport type { Op, Path, Seg } from \"./index.ts\";\n\ntype JsonContainer = JsonValue[] | Record<string, JsonValue>;\ntype CopiedPath = { root: JsonValue; target: JsonContainer };\n\nconst DATA_DESCRIPTOR: PropertyDescriptor = {\n\tvalue: undefined,\n\twritable: true,\n\tenumerable: true,\n\tconfigurable: true,\n};\n\n/** Apply self-produced trusted operations while copying each touched container once. */\nexport function applyImmutableTrusted<T>(target: T, operations: readonly Op[]): T {\n\tlet root = target as unknown as JsonValue;\n\tconst owned = new WeakSet<object>();\n\tfor (const operation of operations) {\n\t\tif (operation[0] === \"r\") {\n\t\t\troot = operation[1];\n\t\t\tcontinue;\n\t\t}\n\t\tif (operation[0] === \"p\" || operation[0] === \"m\") {\n\t\t\tconst copied = copyPath(root, operation[1], operation[1].length, owned);\n\t\t\troot = copied.root;\n\t\t\tif (!Array.isArray(copied.target)) throw new TypeError(\"Trusted array operation target is not an array\");\n\t\t\tif (operation[0] === \"p\") spliceTrusted(copied.target, operation[2], operation[3], operation[4]);\n\t\t\telse permuteTrusted(copied.target, operation[2]);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = operation[1];\n\t\tconst copied = copyPath(root, path, path.length - 1, owned);\n\t\troot = copied.root;\n\t\tconst key = path[path.length - 1]!;\n\t\tswitch (operation[0]) {\n\t\t\tcase \"s\":\n\t\t\t\tdefineData(copied.target, key, operation[2]);\n\t\t\t\tbreak;\n\t\t\tcase \"d\":\n\t\t\t\tif (Array.isArray(copied.target)) {\n\t\t\t\t\tif (typeof key !== \"number\") throw new TypeError(\"Trusted array deletion key is not numeric\");\n\t\t\t\t\tspliceTrusted(copied.target, key, 1, []);\n\t\t\t\t} else Reflect.deleteProperty(copied.target, key);\n\t\t\t\tbreak;\n\t\t\tcase \"a\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted append target is not a string\");\n\t\t\t\tdefineData(copied.target, key, `${current}${operation[2]}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"t\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted truncate target is not a string\");\n\t\t\t\tdefineData(copied.target, key, current.slice(operation[2]));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\nfunction copyPath(root: JsonValue, path: Path, length: number, owned: WeakSet<object>): CopiedPath {\n\tif (!isContainer(root)) throw new TypeError(\"Trusted operation root is not a container\");\n\tlet copiedRoot = root;\n\tif (!owned.has(root)) {\n\t\tcopiedRoot = shallowCopy(root);\n\t\towned.add(copiedRoot);\n\t}\n\tlet destination = copiedRoot as JsonContainer;\n\tfor (let index = 0; index < length; index++) {\n\t\tconst segment = path[index]!;\n\t\tconst child = read(destination, segment);\n\t\tif (!isContainer(child)) throw new TypeError(\"Trusted operation path is not a container\");\n\t\tif (owned.has(child)) {\n\t\t\tdestination = child;\n\t\t\tcontinue;\n\t\t}\n\t\tconst copy = shallowCopy(child);\n\t\tdefineData(destination, segment, copy);\n\t\towned.add(copy);\n\t\tdestination = copy;\n\t}\n\treturn { root: copiedRoot, target: destination };\n}\n\nfunction shallowCopy(value: JsonContainer): JsonContainer {\n\tif (Array.isArray(value)) return Array.from(value);\n\tconst result = Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype) as Record<\n\t\tstring,\n\t\tJsonValue\n\t>;\n\tfor (const key of Object.keys(value)) defineData(result, key, value[key]!);\n\treturn result;\n}\n\nfunction read(target: JsonContainer, key: Seg): JsonValue {\n\treturn (target as Record<Seg, JsonValue>)[key]!;\n}\n\nfunction defineData(target: JsonContainer, key: Seg, value: JsonValue): void {\n\tDATA_DESCRIPTOR.value = value;\n\tObject.defineProperty(target, key, DATA_DESCRIPTOR);\n\tDATA_DESCRIPTOR.value = undefined;\n}\n\nfunction spliceTrusted(target: JsonValue[], start: number, remove: number, items: readonly JsonValue[]): void {\n\tconst oldLength = target.length;\n\tconst delta = items.length - remove;\n\tif (delta > 0) {\n\t\ttarget.length = oldLength + delta;\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t} else if (delta < 0) {\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t\ttarget.length = oldLength + delta;\n\t}\n\tfor (let index = 0; index < items.length; index++) defineData(target, start + index, items[index]!);\n}\n\nfunction permuteTrusted(target: JsonValue[], permutation: readonly number[]): void {\n\tif (target.length !== permutation.length) throw new TypeError(\"Trusted permutation length mismatch\");\n\tconst previous = target.slice();\n\tfor (let index = 0; index < permutation.length; index++) target[index] = previous[permutation[index]!]!;\n}\n\nfunction isContainer(value: unknown): value is JsonContainer {\n\treturn value !== null && typeof value === \"object\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"apply-immutable-trusted.js","sourceRoot":"","sources":["../../src/delta/apply-immutable-trusted.ts"],"names":[],"mappings":"AAMA,MAAM,eAAe,GAAuB;IAC3C,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;CAClB,CAAC;AAEF,wFAAwF;AACxF,MAAM,UAAU,qBAAqB,CAAI,MAAS,EAAE,UAAyB;IAC5E,IAAI,IAAI,GAAG,MAA8B,CAAC;IAC1C,MAAM,KAAK,GAAG,IAAI,OAAO,EAAU,CAAC;IACpC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACpB,SAAS;QACV,CAAC;QACD,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACxE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;YACzG,IAAI,S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I,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\nimport type { Op, Path, Seg } from \"./index.ts\";\n\ntype JsonContainer = JsonValue[] | Record<string, JsonValue>;\ntype CopiedPath = { root: JsonValue; target: JsonContainer };\n\nconst DATA_DESCRIPTOR: PropertyDescriptor = {\n\tvalue: undefined,\n\twritable: true,\n\tenumerable: true,\n\tconfigurable: true,\n};\n\n/** Apply self-produced trusted operations while copying each touched container once. */\nexport function applyImmutableTrusted<T>(target: T, operations: readonly Op[]): T {\n\tlet root = target as unknown as JsonValue;\n\tconst owned = new WeakSet<object>();\n\tfor (const operation of operations) {\n\t\tif (operation[0] === \"r\") {\n\t\t\troot = operation[1];\n\t\t\tcontinue;\n\t\t}\n\t\tif (operation[0] === \"p\" || operation[0] === \"m\") {\n\t\t\tconst copied = copyPath(root, operation[1], operation[1].length, owned);\n\t\t\troot = copied.root;\n\t\t\tif (!Array.isArray(copied.target)) throw new TypeError(\"Trusted array operation target is not an array\");\n\t\t\tif (operation[0] === \"p\") spliceTrusted(copied.target, operation[2], operation[3], operation[4]);\n\t\t\telse permuteTrusted(copied.target, operation[2]);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = operation[1];\n\t\tconst copied = copyPath(root, path, path.length - 1, owned);\n\t\troot = copied.root;\n\t\tconst key = path[path.length - 1]!;\n\t\tswitch (operation[0]) {\n\t\t\tcase \"s\":\n\t\t\t\tdefineData(copied.target, key, operation[2]);\n\t\t\t\tbreak;\n\t\t\tcase \"d\":\n\t\t\t\tif (Array.isArray(copied.target)) {\n\t\t\t\t\tif (typeof key !== \"number\") throw new TypeError(\"Trusted array deletion key is not numeric\");\n\t\t\t\t\tspliceTrusted(copied.target, key, 1, []);\n\t\t\t\t} else Reflect.deleteProperty(copied.target, key);\n\t\t\t\tbreak;\n\t\t\tcase \"a\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted append target is not a string\");\n\t\t\t\tdefineData(copied.target, key, `${current}${operation[2]}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"t\": {\n\t\t\t\tconst current = read(copied.target, key);\n\t\t\t\tif (typeof current !== \"string\") throw new TypeError(\"Trusted truncate target is not a string\");\n\t\t\t\tdefineData(copied.target, key, current.slice(operation[2]));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\nfunction copyPath(root: JsonValue, path: Path, length: number, owned: WeakSet<object>): CopiedPath {\n\tif (!isContainer(root)) throw new TypeError(\"Trusted operation root is not a container\");\n\tlet copiedRoot = root;\n\tif (!owned.has(root)) {\n\t\tcopiedRoot = shallowCopy(root);\n\t\towned.add(copiedRoot);\n\t}\n\tlet destination = copiedRoot as JsonContainer;\n\tfor (let index = 0; index < length; index++) {\n\t\tconst segment = path[index]!;\n\t\tconst child = read(destination, segment);\n\t\tif (!isContainer(child)) throw new TypeError(\"Trusted operation path is not a container\");\n\t\tif (owned.has(child)) {\n\t\t\tdestination = child;\n\t\t\tcontinue;\n\t\t}\n\t\tconst copy = shallowCopy(child);\n\t\tdefineData(destination, segment, copy);\n\t\towned.add(copy);\n\t\tdestination = copy;\n\t}\n\treturn { root: copiedRoot, target: destination };\n}\n\nfunction shallowCopy(value: JsonContainer): JsonContainer {\n\tif (Array.isArray(value)) return Array.from(value);\n\t// Spread and `Object.assign()` onto a null-prototype object define own data properties, `__proto__` included, as\n\t// `defineData()` per key does, at a fraction of its cost.\n\treturn Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };\n}\n\nfunction read(target: JsonContainer, key: Seg): JsonValue {\n\treturn (target as Record<Seg, JsonValue>)[key]!;\n}\n\nfunction defineData(target: JsonContainer, key: Seg, value: JsonValue): void {\n\tDATA_DESCRIPTOR.value = value;\n\tObject.defineProperty(target, key, DATA_DESCRIPTOR);\n\tDATA_DESCRIPTOR.value = undefined;\n}\n\nfunction spliceTrusted(target: JsonValue[], start: number, remove: number, items: readonly JsonValue[]): void {\n\tconst oldLength = target.length;\n\tconst delta = items.length - remove;\n\tif (delta > 0) {\n\t\ttarget.length = oldLength + delta;\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t} else if (delta < 0) {\n\t\ttarget.copyWithin(start + items.length, start + remove, oldLength);\n\t\ttarget.length = oldLength + delta;\n\t}\n\tfor (let index = 0; index < items.length; index++) defineData(target, start + index, items[index]!);\n}\n\nfunction permuteTrusted(target: JsonValue[], permutation: readonly number[]): void {\n\tif (target.length !== permutation.length) throw new TypeError(\"Trusted permutation length mismatch\");\n\tconst previous = target.slice();\n\tfor (let index = 0; index < permutation.length; index++) target[index] = previous[permutation[index]!]!;\n}\n\nfunction isContainer(value: unknown): value is JsonContainer {\n\treturn value !== null && typeof value === \"object\";\n}\n"]}
|
package/dist/delta/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/delta/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAqB,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/delta/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAqB,KAAK,EAAE,EAA+D,MAAM,YAAY,CAAC;AAggBrH,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,EAAE,EAAE,CAUvE"}
|
package/dist/delta/diff.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { overlap, RESERVED_SEGMENTS } from "./index.js";
|
|
1
|
+
import { overlap, ownedSlice, RESERVED_SEGMENTS } from "./index.js";
|
|
2
2
|
const DEFAULT_OVERLAP_SCAN = 65_536;
|
|
3
3
|
const MAX_DELTA_OPERATIONS = 4_096;
|
|
4
4
|
const overflowedBatches = new WeakSet();
|
|
@@ -64,11 +64,13 @@ const permutation = (before, after) => {
|
|
|
64
64
|
}
|
|
65
65
|
return result;
|
|
66
66
|
};
|
|
67
|
+
// O(length): comparing two revisions reads both strings, and slicing a rope makes V8 flatten all of it. A writer that
|
|
68
|
+
// knows what it appended records it with appendText() instead of diffing.
|
|
67
69
|
const emitString = (before, after, path, operations) => {
|
|
68
70
|
if (before === after)
|
|
69
71
|
return;
|
|
70
72
|
if (after.length > before.length && after.slice(0, before.length) === before) {
|
|
71
|
-
emitOperation(operations, ["a", path, after
|
|
73
|
+
emitOperation(operations, ["a", path, ownedSlice(after, before.length)]);
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
const shared = overlap(before, after, DEFAULT_OVERLAP_SCAN);
|
|
@@ -78,7 +80,7 @@ const emitString = (before, after, path, operations) => {
|
|
|
78
80
|
}
|
|
79
81
|
emitOperation(operations, ["t", path, before.length - shared]);
|
|
80
82
|
if (after.length > shared)
|
|
81
|
-
emitOperation(operations, ["a", path, after
|
|
83
|
+
emitOperation(operations, ["a", path, ownedSlice(after, shared)]);
|
|
82
84
|
};
|
|
83
85
|
const MAX_IDENTITY_CANDIDATES = 200_000;
|
|
84
86
|
const MAX_SEMANTIC_CELLS = 65_536;
|
package/dist/delta/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/delta/diff.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,OAAO,EAAa,iBAAiB,EAAY,MAAM,YAAY,CAAC;AAEzG,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAQ,CAAC;AAE9C,MAAM,aAAa,GAAG,CAAC,UAAgB,EAAE,SAAa,EAA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,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAChE,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\nimport { type NonEmptyPath, type Op, overlap, type Path, RESERVED_SEGMENTS, type Seg } from \"./index.ts\";\n\nconst DEFAULT_OVERLAP_SCAN = 65_536;\nconst MAX_DELTA_OPERATIONS = 4_096;\nconst overflowedBatches = new WeakSet<Op[]>();\n\nconst emitOperation = (operations: Op[], operation: Op): void => {\n\tif (overflowedBatches.has(operations)) return;\n\tif (operations.length >= MAX_DELTA_OPERATIONS) {\n\t\toverflowedBatches.add(operations);\n\t\treturn;\n\t}\n\toperations.push(operation);\n};\n\nconst isContainer = (value: JsonValue): value is JsonValue[] | Record<string, JsonValue> =>\n\tvalue !== null && typeof value === \"object\";\n\nconst emitSet = (path: Path, value: JsonValue, operations: Op[]): void => {\n\tif (path.length === 0) emitOperation(operations, [\"r\", value]);\n\telse emitOperation(operations, [\"s\", path as NonEmptyPath, value]);\n};\n\nconst equalJson = (left: JsonValue, right: JsonValue): boolean => {\n\tif (left === right) return true;\n\tif (!isContainer(left) || !isContainer(right) || Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (Array.isArray(left)) {\n\t\tconst other = right as JsonValue[];\n\t\tif (left.length !== other.length) return false;\n\t\tfor (let index = 0; index < left.length; index++) {\n\t\t\tif (!equalJson(left[index]!, other[index]!)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\tconst other = right as Record<string, JsonValue>;\n\tconst keys = Object.keys(left);\n\tif (keys.length !== Object.keys(other).length) return false;\n\tfor (const key of keys) {\n\t\tif (!Object.hasOwn(other, key) || !equalJson(left[key]!, other[key]!)) return false;\n\t}\n\treturn true;\n};\n\nconst permutation = (before: readonly JsonValue[], after: readonly JsonValue[]): number[] | undefined => {\n\tif (before.length !== after.length) return undefined;\n\tconst positions = new Map<JsonValue, { indices: number[]; used: number }>();\n\tfor (let index = 0; index < before.length; index++) {\n\t\tconst value = before[index]!;\n\t\tconst entry = positions.get(value);\n\t\tif (entry === undefined) positions.set(value, { indices: [index], used: 0 });\n\t\telse entry.indices.push(index);\n\t}\n\tconst result = new Array<number>(after.length);\n\tfor (let index = 0; index < after.length; index++) {\n\t\tconst entry = positions.get(after[index]!);\n\t\tif (entry === undefined || entry.used === entry.indices.length) return undefined;\n\t\tresult[index] = entry.indices[entry.used++]!;\n\t}\n\treturn result;\n};\n\nconst emitString = (before: string, after: string, path: NonEmptyPath, operations: Op[]): void => {\n\tif (before === after) return;\n\tif (after.length > before.length && after.slice(0, before.length) === before) {\n\t\temitOperation(operations, [\"a\", path, after.slice(before.length)]);\n\t\treturn;\n\t}\n\tconst shared = overlap(before, after, DEFAULT_OVERLAP_SCAN);\n\tif (shared === 0) {\n\t\temitOperation(operations, [\"s\", path, after]);\n\t\treturn;\n\t}\n\temitOperation(operations, [\"t\", path, before.length - shared]);\n\tif (after.length > shared) emitOperation(operations, [\"a\", path, after.slice(shared)]);\n};\n\ntype ArrayMatch = readonly [before: number, after: number];\n\ntype MatchCandidate = {\n\tbefore: number;\n\tafter: number;\n\tprevious: number;\n};\n\nconst MAX_IDENTITY_CANDIDATES = 200_000;\nconst MAX_SEMANTIC_CELLS = 65_536;\n\nconst sameValue = (left: JsonValue, right: JsonValue): boolean => left === right || equalJson(left, right);\n\nconst lcsMatches = (\n\tbefore: readonly JsonValue[],\n\tafter: readonly JsonValue[],\n\tequal: (left: JsonValue, right: JsonValue) => boolean,\n\tmaxCells: number,\n): ArrayMatch[] | undefined => {\n\tif (before.length === 0 || after.length === 0) return [];\n\tif (before.length * after.length > maxCells) return undefined;\n\tconst width = after.length + 1;\n\tconst lengths = new Uint32Array((before.length + 1) * width);\n\tfor (let left = before.length - 1; left >= 0; left--) {\n\t\tfor (let right = after.length - 1; right >= 0; right--) {\n\t\t\tconst at = left * width + right;\n\t\t\tlengths[at] = equal(before[left]!, after[right]!)\n\t\t\t\t? lengths[(left + 1) * width + right + 1]! + 1\n\t\t\t\t: Math.max(lengths[(left + 1) * width + right]!, lengths[left * width + right + 1]!);\n\t\t}\n\t}\n\tconst matches: ArrayMatch[] = [];\n\tlet left = 0;\n\tlet right = 0;\n\twhile (left < before.length && right < after.length) {\n\t\tif (\n\t\t\tequal(before[left]!, after[right]!) &&\n\t\t\tlengths[left * width + right] === lengths[(left + 1) * width + right + 1]! + 1\n\t\t) {\n\t\t\tmatches.push([left++, right++]);\n\t\t} else if (lengths[(left + 1) * width + right]! >= lengths[left * width + right + 1]!) left += 1;\n\t\telse right += 1;\n\t}\n\treturn matches;\n};\n\nconst semanticallyAligned = (left: JsonValue, right: JsonValue): boolean => {\n\tif (sameValue(left, right)) return true;\n\tif (!isContainer(left) || !isContainer(right) || Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (Array.isArray(left) && Array.isArray(right)) {\n\t\tif (left.length !== right.length) return false;\n\t\treturn left.some((value, index) => isContainer(value) && value === right[index]);\n\t}\n\tconst leftObject = left as Record<string, JsonValue>;\n\tconst rightObject = right as Record<string, JsonValue>;\n\tfor (const key of Object.keys(leftObject)) {\n\t\tconst value = leftObject[key];\n\t\tif (isContainer(value) && Object.hasOwn(rightObject, key) && value === rightObject[key]) return true;\n\t}\n\treturn false;\n};\n\nconst lowerBound = (values: readonly number[], value: number): number => {\n\tlet low = 0;\n\tlet high = values.length;\n\twhile (low < high) {\n\t\tconst middle = (low + high) >>> 1;\n\t\tif (values[middle]! < value) low = middle + 1;\n\t\telse high = middle;\n\t}\n\treturn low;\n};\n\nconst identitySubsequence = (\n\tbefore: readonly JsonValue[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] | undefined => {\n\tconst beforeCount = beforeEnd - beforeStart;\n\tconst afterCount = afterEnd - afterStart;\n\tconst matches: ArrayMatch[] = [];\n\tif (afterCount < beforeCount) {\n\t\tlet beforeIndex = beforeStart;\n\t\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\t\twhile (beforeIndex < beforeEnd && before[beforeIndex] !== after[afterIndex]) beforeIndex += 1;\n\t\t\tif (beforeIndex === beforeEnd) return undefined;\n\t\t\tmatches.push([beforeIndex++, afterIndex]);\n\t\t}\n\t\treturn matches;\n\t}\n\tif (beforeCount < afterCount) {\n\t\tlet afterIndex = afterStart;\n\t\tfor (let beforeIndex = beforeStart; beforeIndex < beforeEnd; beforeIndex++) {\n\t\t\twhile (afterIndex < afterEnd && before[beforeIndex] !== after[afterIndex]) afterIndex += 1;\n\t\t\tif (afterIndex === afterEnd) return undefined;\n\t\t\tmatches.push([beforeIndex, afterIndex++]);\n\t\t}\n\t\treturn matches;\n\t}\n\treturn undefined;\n};\n\nconst greedyIdentityAnchors = (\n\tpositions: ReadonlyMap<JsonValue, readonly number[]>,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] => {\n\tconst matches: ArrayMatch[] = [];\n\tlet previous = -1;\n\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\tconst candidates = positions.get(after[afterIndex]!);\n\t\tif (candidates === undefined) continue;\n\t\tconst at = lowerBound(candidates, previous + 1);\n\t\tconst beforeIndex = candidates[at];\n\t\tif (beforeIndex === undefined) continue;\n\t\tmatches.push([beforeIndex, afterIndex]);\n\t\tprevious = beforeIndex;\n\t}\n\treturn matches;\n};\n\nconst identityAnchors = (\n\tbefore: readonly JsonValue[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] => {\n\tconst positions = new Map<JsonValue, number[]>();\n\tfor (let index = beforeStart; index < beforeEnd; index++) {\n\t\tconst value = before[index]!;\n\t\tconst existing = positions.get(value);\n\t\tif (existing === undefined) positions.set(value, [index]);\n\t\telse existing.push(index);\n\t}\n\tlet candidateCount = 0;\n\tfor (let index = afterStart; index < afterEnd; index++) {\n\t\tcandidateCount += positions.get(after[index]!)?.length ?? 0;\n\t\tif (candidateCount > MAX_IDENTITY_CANDIDATES) {\n\t\t\treturn greedyIdentityAnchors(positions, after, afterStart, afterEnd);\n\t\t}\n\t}\n\tif (candidateCount === 0) return [];\n\n\tconst candidates: MatchCandidate[] = [];\n\tconst tails: number[] = [];\n\tconst tailValues: number[] = [];\n\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\tconst beforePositions = positions.get(after[afterIndex]!);\n\t\tif (beforePositions === undefined) continue;\n\t\tfor (let index = beforePositions.length - 1; index >= 0; index--) {\n\t\t\tconst beforeIndex = beforePositions[index]!;\n\t\t\tconst at = lowerBound(tailValues, beforeIndex);\n\t\t\tconst candidateIndex = candidates.length;\n\t\t\tcandidates.push({ before: beforeIndex, after: afterIndex, previous: at === 0 ? -1 : tails[at - 1]! });\n\t\t\ttails[at] = candidateIndex;\n\t\t\ttailValues[at] = beforeIndex;\n\t\t}\n\t}\n\tconst matches: ArrayMatch[] = [];\n\tlet candidateIndex = tails[tails.length - 1] ?? -1;\n\twhile (candidateIndex >= 0) {\n\t\tconst candidate = candidates[candidateIndex]!;\n\t\tmatches.push([candidate.before, candidate.after]);\n\t\tcandidateIndex = candidate.previous;\n\t}\n\tmatches.reverse();\n\treturn matches;\n};\n\nconst processArrayMatches = (\n\tbefore: JsonValue[],\n\tafter: JsonValue[],\n\tpath: Path,\n\toperations: Op[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterEnd: number,\n\toutputStart: number,\n\tmatches: readonly ArrayMatch[],\n): void => {\n\tlet beforeAt = beforeStart;\n\tlet afterAt = afterStart;\n\tlet outputAt = outputStart;\n\tfor (const [beforeMatch, afterMatch] of matches) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tdiffArrayRegion(before, after, path, operations, beforeAt, beforeMatch, afterAt, afterMatch, outputAt);\n\t\toutputAt += afterMatch - afterAt;\n\t\tif (!sameValue(before[beforeMatch]!, after[afterMatch]!)) {\n\t\t\tdiffValue(before[beforeMatch]!, after[afterMatch]!, [...path, outputAt], operations);\n\t\t}\n\t\toutputAt += 1;\n\t\tbeforeAt = beforeMatch + 1;\n\t\tafterAt = afterMatch + 1;\n\t}\n\tif (!overflowedBatches.has(operations)) {\n\t\tdiffArrayRegion(before, after, path, operations, beforeAt, beforeEnd, afterAt, afterEnd, outputAt);\n\t}\n};\n\nfunction diffArrayRegion(\n\tbefore: JsonValue[],\n\tafter: JsonValue[],\n\tpath: Path,\n\toperations: Op[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterEnd: number,\n\toutputStart: number,\n): void {\n\tif (overflowedBatches.has(operations)) return;\n\twhile (beforeStart < beforeEnd && afterStart < afterEnd && sameValue(before[beforeStart]!, after[afterStart]!)) {\n\t\tbeforeStart += 1;\n\t\tafterStart += 1;\n\t\toutputStart += 1;\n\t}\n\twhile (beforeStart < beforeEnd && afterStart < afterEnd && sameValue(before[beforeEnd - 1]!, after[afterEnd - 1]!)) {\n\t\tbeforeEnd -= 1;\n\t\tafterEnd -= 1;\n\t}\n\tconst beforeCount = beforeEnd - beforeStart;\n\tconst afterCount = afterEnd - afterStart;\n\tif (beforeCount === 0 && afterCount === 0) return;\n\tif (beforeCount === 0 || afterCount === 0) {\n\t\temitOperation(operations, [\"p\", path, outputStart, beforeCount, after.slice(afterStart, afterEnd)]);\n\t\treturn;\n\t}\n\n\tif (beforeCount === afterCount) {\n\t\tconst positional: ArrayMatch[] = [];\n\t\tfor (let offset = 0; offset < beforeCount; offset++) {\n\t\t\tif (sameValue(before[beforeStart + offset]!, after[afterStart + offset]!)) {\n\t\t\t\tpositional.push([beforeStart + offset, afterStart + offset]);\n\t\t\t}\n\t\t}\n\t\tif (positional.length > 0) {\n\t\t\tprocessArrayMatches(\n\t\t\t\tbefore,\n\t\t\t\tafter,\n\t\t\t\tpath,\n\t\t\t\toperations,\n\t\t\t\tbeforeStart,\n\t\t\t\tbeforeEnd,\n\t\t\t\tafterStart,\n\t\t\t\tafterEnd,\n\t\t\t\toutputStart,\n\t\t\t\tpositional,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst subsequence = identitySubsequence(before, beforeStart, beforeEnd, after, afterStart, afterEnd);\n\tif (subsequence !== undefined && subsequence.length > 0) {\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tsubsequence,\n\t\t);\n\t\treturn;\n\t}\n\n\tconst identity = identityAnchors(before, beforeStart, beforeEnd, after, afterStart, afterEnd);\n\tif (identity.length > 0) {\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tidentity,\n\t\t);\n\t\treturn;\n\t}\n\n\tconst semantic = lcsMatches(\n\t\tbefore.slice(beforeStart, beforeEnd),\n\t\tafter.slice(afterStart, afterEnd),\n\t\tsemanticallyAligned,\n\t\tMAX_SEMANTIC_CELLS,\n\t);\n\tif (semantic !== undefined && semantic.length > 0) {\n\t\tconst absolute = semantic.map(\n\t\t\t([beforeIndex, afterIndex]) => [beforeStart + beforeIndex, afterStart + afterIndex] as const,\n\t\t);\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tabsolute,\n\t\t);\n\t\treturn;\n\t}\n\n\tif (beforeCount === 1 && afterCount === 1) {\n\t\tdiffValue(before[beforeStart]!, after[afterStart]!, [...path, outputStart], operations);\n\t\treturn;\n\t}\n\temitOperation(operations, [\"p\", path, outputStart, beforeCount, after.slice(afterStart, afterEnd)]);\n}\n\nconst diffArray = (before: JsonValue[], after: JsonValue[], path: Path, operations: Op[]): void => {\n\tif (before === after || equalJson(before, after)) return;\n\tif (\n\t\tbefore.length === after.length &&\n\t\tbefore.length > 1 &&\n\t\t!sameValue(before[0]!, after[0]!) &&\n\t\t!sameValue(before[before.length - 1]!, after[after.length - 1]!)\n\t) {\n\t\tconst order = permutation(before, after);\n\t\tif (order !== undefined) {\n\t\t\temitOperation(operations, [\"m\", path, order]);\n\t\t\treturn;\n\t\t}\n\t}\n\tdiffArrayRegion(before, after, path, operations, 0, before.length, 0, after.length, 0);\n};\n\nconst diffObject = (\n\tbefore: Record<string, JsonValue>,\n\tafter: Record<string, JsonValue>,\n\tpath: Path,\n\toperations: Op[],\n): void => {\n\tconst beforeKeys = Object.keys(before);\n\tconst afterKeys = Object.keys(after);\n\tif ([...beforeKeys, ...afterKeys].some((key) => RESERVED_SEGMENTS.has(key))) {\n\t\tif (!equalJson(before, after)) emitSet(path, after, operations);\n\t\treturn;\n\t}\n\tfor (const key of afterKeys) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tif (Object.hasOwn(before, key)) diffValue(before[key]!, after[key]!, [...path, key], operations);\n\t\telse emitSet([...path, key], after[key]!, operations);\n\t}\n\tfor (const key of beforeKeys) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tif (!Object.hasOwn(after, key)) emitOperation(operations, [\"d\", [...path, key] as unknown as NonEmptyPath]);\n\t}\n};\n\nconst diffValue = (before: JsonValue, after: JsonValue, path: Path, operations: Op[]): void => {\n\tif (before === after || overflowedBatches.has(operations)) return;\n\tif (typeof before === \"string\" && typeof after === \"string\" && path.length > 0) {\n\t\temitString(before, after, path as NonEmptyPath, operations);\n\t\treturn;\n\t}\n\tif (Array.isArray(before) && Array.isArray(after)) {\n\t\tdiffArray(before, after, path, operations);\n\t\treturn;\n\t}\n\tif (isContainer(before) && isContainer(after) && !Array.isArray(before) && !Array.isArray(after)) {\n\t\tdiffObject(before, after, path, operations);\n\t\treturn;\n\t}\n\temitSet(path, after, operations);\n};\n\nconst jsonCost = (value: JsonValue): number => {\n\tif (value === null) return 4;\n\tif (typeof value === \"string\") return value.length + 2;\n\tif (typeof value === \"number\") return String(value).length;\n\tif (typeof value === \"boolean\") return value ? 4 : 5;\n\tif (Array.isArray(value)) {\n\t\tlet cost = 2;\n\t\tfor (let index = 0; index < value.length; index++) cost += jsonCost(value[index]!) + (index === 0 ? 0 : 1);\n\t\treturn cost;\n\t}\n\tlet cost = 2;\n\tlet index = 0;\n\tfor (const key of Object.keys(value)) {\n\t\tcost += key.length + 3 + jsonCost(value[key]!) + (index++ === 0 ? 0 : 1);\n\t}\n\treturn cost;\n};\n\nconst pathCost = (path: Path): number => {\n\tlet cost = 2;\n\tfor (let index = 0; index < path.length; index++) {\n\t\tconst segment: Seg = path[index]!;\n\t\tcost += (typeof segment === \"string\" ? segment.length + 2 : String(segment).length) + (index === 0 ? 0 : 1);\n\t}\n\treturn cost;\n};\n\nconst operationCost = (operation: Op): number => {\n\tswitch (operation[0]) {\n\t\tcase \"r\":\n\t\t\treturn 6 + jsonCost(operation[1]);\n\t\tcase \"s\":\n\t\t\treturn 7 + pathCost(operation[1]) + jsonCost(operation[2]);\n\t\tcase \"d\":\n\t\t\treturn 6 + pathCost(operation[1]);\n\t\tcase \"a\":\n\t\t\treturn 7 + pathCost(operation[1]) + operation[2].length + 2;\n\t\tcase \"t\":\n\t\t\treturn 7 + pathCost(operation[1]) + String(operation[2]).length;\n\t\tcase \"p\":\n\t\t\treturn (\n\t\t\t\t10 +\n\t\t\t\tpathCost(operation[1]) +\n\t\t\t\tString(operation[2]).length +\n\t\t\t\tString(operation[3]).length +\n\t\t\t\tjsonCost(operation[4])\n\t\t\t);\n\t\tcase \"m\":\n\t\t\treturn 7 + pathCost(operation[1]) + jsonCost(operation[2]);\n\t}\n};\n\n/** Compute a compact operation batch from two immutable JSON revisions. */\nexport function diffRevisions(before: JsonValue, after: JsonValue): Op[] {\n\tconst operations: Op[] = [];\n\tdiffValue(before, after, [], operations);\n\tif (overflowedBatches.has(operations)) return [[\"r\", after]];\n\tif (operations.length === 0 || operations[0]?.[0] === \"r\") return operations;\n\tlet deltaCost = 2;\n\tfor (const operation of operations) deltaCost += operationCost(operation) + 1;\n\tif (deltaCost < 65_536) return operations;\n\tconst snapshotCost = jsonCost(after) + 6;\n\treturn deltaCost >= snapshotCost ? [[\"r\", after]] : operations;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/delta/diff.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,OAAO,EAAE,UAAU,EAAa,iBAAiB,EAAY,MAAM,YAAY,CAAC;AAErH,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAQ,CAAC;AAE9C,MAAM,aAAa,GAAG,CAAC,UAAgB,EAAE,SAAa,EAAQ,EAAE;IAC/D,IAAI,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAO;IAC9C,IAAI,UAAU,CAAC,MAAM,IAAI,oBAAoB,EAAE,CAAC;QAC/C,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO;IACR,CAAC;IACD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,KAAgB,EAAoD,EAAE,CAC1F,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE7C,MAAM,OAAO,GAAG,CAAC,IAAU,EAAE,KAAgB,EAAE,UAAgB,EAAQ,EAAE;IACxE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,KAA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C3E,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,KAAgB;IAChE,MAAM,UAAU,GAAS,EAAE,CAAC;IAC5B,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;IACzC,IAAI,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,UAAU,CAAC;IAC7E,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,SAAS,IAAI,UAAU;QAAE,SAAS,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9E,IAAI,SAAS,GAAG,MAAM;QAAE,OAAO,UAAU,CAAC;IAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzC,OAAO,SAAS,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAChE,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\nimport { type NonEmptyPath, type Op, overlap, ownedSlice, type Path, RESERVED_SEGMENTS, type Seg } from \"./index.ts\";\n\nconst DEFAULT_OVERLAP_SCAN = 65_536;\nconst MAX_DELTA_OPERATIONS = 4_096;\nconst overflowedBatches = new WeakSet<Op[]>();\n\nconst emitOperation = (operations: Op[], operation: Op): void => {\n\tif (overflowedBatches.has(operations)) return;\n\tif (operations.length >= MAX_DELTA_OPERATIONS) {\n\t\toverflowedBatches.add(operations);\n\t\treturn;\n\t}\n\toperations.push(operation);\n};\n\nconst isContainer = (value: JsonValue): value is JsonValue[] | Record<string, JsonValue> =>\n\tvalue !== null && typeof value === \"object\";\n\nconst emitSet = (path: Path, value: JsonValue, operations: Op[]): void => {\n\tif (path.length === 0) emitOperation(operations, [\"r\", value]);\n\telse emitOperation(operations, [\"s\", path as NonEmptyPath, value]);\n};\n\nconst equalJson = (left: JsonValue, right: JsonValue): boolean => {\n\tif (left === right) return true;\n\tif (!isContainer(left) || !isContainer(right) || Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (Array.isArray(left)) {\n\t\tconst other = right as JsonValue[];\n\t\tif (left.length !== other.length) return false;\n\t\tfor (let index = 0; index < left.length; index++) {\n\t\t\tif (!equalJson(left[index]!, other[index]!)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\tconst other = right as Record<string, JsonValue>;\n\tconst keys = Object.keys(left);\n\tif (keys.length !== Object.keys(other).length) return false;\n\tfor (const key of keys) {\n\t\tif (!Object.hasOwn(other, key) || !equalJson(left[key]!, other[key]!)) return false;\n\t}\n\treturn true;\n};\n\nconst permutation = (before: readonly JsonValue[], after: readonly JsonValue[]): number[] | undefined => {\n\tif (before.length !== after.length) return undefined;\n\tconst positions = new Map<JsonValue, { indices: number[]; used: number }>();\n\tfor (let index = 0; index < before.length; index++) {\n\t\tconst value = before[index]!;\n\t\tconst entry = positions.get(value);\n\t\tif (entry === undefined) positions.set(value, { indices: [index], used: 0 });\n\t\telse entry.indices.push(index);\n\t}\n\tconst result = new Array<number>(after.length);\n\tfor (let index = 0; index < after.length; index++) {\n\t\tconst entry = positions.get(after[index]!);\n\t\tif (entry === undefined || entry.used === entry.indices.length) return undefined;\n\t\tresult[index] = entry.indices[entry.used++]!;\n\t}\n\treturn result;\n};\n\n// O(length): comparing two revisions reads both strings, and slicing a rope makes V8 flatten all of it. A writer that\n// knows what it appended records it with appendText() instead of diffing.\nconst emitString = (before: string, after: string, path: NonEmptyPath, operations: Op[]): void => {\n\tif (before === after) return;\n\tif (after.length > before.length && after.slice(0, before.length) === before) {\n\t\temitOperation(operations, [\"a\", path, ownedSlice(after, before.length)]);\n\t\treturn;\n\t}\n\tconst shared = overlap(before, after, DEFAULT_OVERLAP_SCAN);\n\tif (shared === 0) {\n\t\temitOperation(operations, [\"s\", path, after]);\n\t\treturn;\n\t}\n\temitOperation(operations, [\"t\", path, before.length - shared]);\n\tif (after.length > shared) emitOperation(operations, [\"a\", path, ownedSlice(after, shared)]);\n};\n\ntype ArrayMatch = readonly [before: number, after: number];\n\ntype MatchCandidate = {\n\tbefore: number;\n\tafter: number;\n\tprevious: number;\n};\n\nconst MAX_IDENTITY_CANDIDATES = 200_000;\nconst MAX_SEMANTIC_CELLS = 65_536;\n\nconst sameValue = (left: JsonValue, right: JsonValue): boolean => left === right || equalJson(left, right);\n\nconst lcsMatches = (\n\tbefore: readonly JsonValue[],\n\tafter: readonly JsonValue[],\n\tequal: (left: JsonValue, right: JsonValue) => boolean,\n\tmaxCells: number,\n): ArrayMatch[] | undefined => {\n\tif (before.length === 0 || after.length === 0) return [];\n\tif (before.length * after.length > maxCells) return undefined;\n\tconst width = after.length + 1;\n\tconst lengths = new Uint32Array((before.length + 1) * width);\n\tfor (let left = before.length - 1; left >= 0; left--) {\n\t\tfor (let right = after.length - 1; right >= 0; right--) {\n\t\t\tconst at = left * width + right;\n\t\t\tlengths[at] = equal(before[left]!, after[right]!)\n\t\t\t\t? lengths[(left + 1) * width + right + 1]! + 1\n\t\t\t\t: Math.max(lengths[(left + 1) * width + right]!, lengths[left * width + right + 1]!);\n\t\t}\n\t}\n\tconst matches: ArrayMatch[] = [];\n\tlet left = 0;\n\tlet right = 0;\n\twhile (left < before.length && right < after.length) {\n\t\tif (\n\t\t\tequal(before[left]!, after[right]!) &&\n\t\t\tlengths[left * width + right] === lengths[(left + 1) * width + right + 1]! + 1\n\t\t) {\n\t\t\tmatches.push([left++, right++]);\n\t\t} else if (lengths[(left + 1) * width + right]! >= lengths[left * width + right + 1]!) left += 1;\n\t\telse right += 1;\n\t}\n\treturn matches;\n};\n\nconst semanticallyAligned = (left: JsonValue, right: JsonValue): boolean => {\n\tif (sameValue(left, right)) return true;\n\tif (!isContainer(left) || !isContainer(right) || Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (Array.isArray(left) && Array.isArray(right)) {\n\t\tif (left.length !== right.length) return false;\n\t\treturn left.some((value, index) => isContainer(value) && value === right[index]);\n\t}\n\tconst leftObject = left as Record<string, JsonValue>;\n\tconst rightObject = right as Record<string, JsonValue>;\n\tfor (const key of Object.keys(leftObject)) {\n\t\tconst value = leftObject[key];\n\t\tif (isContainer(value) && Object.hasOwn(rightObject, key) && value === rightObject[key]) return true;\n\t}\n\treturn false;\n};\n\nconst lowerBound = (values: readonly number[], value: number): number => {\n\tlet low = 0;\n\tlet high = values.length;\n\twhile (low < high) {\n\t\tconst middle = (low + high) >>> 1;\n\t\tif (values[middle]! < value) low = middle + 1;\n\t\telse high = middle;\n\t}\n\treturn low;\n};\n\nconst identitySubsequence = (\n\tbefore: readonly JsonValue[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] | undefined => {\n\tconst beforeCount = beforeEnd - beforeStart;\n\tconst afterCount = afterEnd - afterStart;\n\tconst matches: ArrayMatch[] = [];\n\tif (afterCount < beforeCount) {\n\t\tlet beforeIndex = beforeStart;\n\t\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\t\twhile (beforeIndex < beforeEnd && before[beforeIndex] !== after[afterIndex]) beforeIndex += 1;\n\t\t\tif (beforeIndex === beforeEnd) return undefined;\n\t\t\tmatches.push([beforeIndex++, afterIndex]);\n\t\t}\n\t\treturn matches;\n\t}\n\tif (beforeCount < afterCount) {\n\t\tlet afterIndex = afterStart;\n\t\tfor (let beforeIndex = beforeStart; beforeIndex < beforeEnd; beforeIndex++) {\n\t\t\twhile (afterIndex < afterEnd && before[beforeIndex] !== after[afterIndex]) afterIndex += 1;\n\t\t\tif (afterIndex === afterEnd) return undefined;\n\t\t\tmatches.push([beforeIndex, afterIndex++]);\n\t\t}\n\t\treturn matches;\n\t}\n\treturn undefined;\n};\n\nconst greedyIdentityAnchors = (\n\tpositions: ReadonlyMap<JsonValue, readonly number[]>,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] => {\n\tconst matches: ArrayMatch[] = [];\n\tlet previous = -1;\n\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\tconst candidates = positions.get(after[afterIndex]!);\n\t\tif (candidates === undefined) continue;\n\t\tconst at = lowerBound(candidates, previous + 1);\n\t\tconst beforeIndex = candidates[at];\n\t\tif (beforeIndex === undefined) continue;\n\t\tmatches.push([beforeIndex, afterIndex]);\n\t\tprevious = beforeIndex;\n\t}\n\treturn matches;\n};\n\nconst identityAnchors = (\n\tbefore: readonly JsonValue[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafter: readonly JsonValue[],\n\tafterStart: number,\n\tafterEnd: number,\n): ArrayMatch[] => {\n\tconst positions = new Map<JsonValue, number[]>();\n\tfor (let index = beforeStart; index < beforeEnd; index++) {\n\t\tconst value = before[index]!;\n\t\tconst existing = positions.get(value);\n\t\tif (existing === undefined) positions.set(value, [index]);\n\t\telse existing.push(index);\n\t}\n\tlet candidateCount = 0;\n\tfor (let index = afterStart; index < afterEnd; index++) {\n\t\tcandidateCount += positions.get(after[index]!)?.length ?? 0;\n\t\tif (candidateCount > MAX_IDENTITY_CANDIDATES) {\n\t\t\treturn greedyIdentityAnchors(positions, after, afterStart, afterEnd);\n\t\t}\n\t}\n\tif (candidateCount === 0) return [];\n\n\tconst candidates: MatchCandidate[] = [];\n\tconst tails: number[] = [];\n\tconst tailValues: number[] = [];\n\tfor (let afterIndex = afterStart; afterIndex < afterEnd; afterIndex++) {\n\t\tconst beforePositions = positions.get(after[afterIndex]!);\n\t\tif (beforePositions === undefined) continue;\n\t\tfor (let index = beforePositions.length - 1; index >= 0; index--) {\n\t\t\tconst beforeIndex = beforePositions[index]!;\n\t\t\tconst at = lowerBound(tailValues, beforeIndex);\n\t\t\tconst candidateIndex = candidates.length;\n\t\t\tcandidates.push({ before: beforeIndex, after: afterIndex, previous: at === 0 ? -1 : tails[at - 1]! });\n\t\t\ttails[at] = candidateIndex;\n\t\t\ttailValues[at] = beforeIndex;\n\t\t}\n\t}\n\tconst matches: ArrayMatch[] = [];\n\tlet candidateIndex = tails[tails.length - 1] ?? -1;\n\twhile (candidateIndex >= 0) {\n\t\tconst candidate = candidates[candidateIndex]!;\n\t\tmatches.push([candidate.before, candidate.after]);\n\t\tcandidateIndex = candidate.previous;\n\t}\n\tmatches.reverse();\n\treturn matches;\n};\n\nconst processArrayMatches = (\n\tbefore: JsonValue[],\n\tafter: JsonValue[],\n\tpath: Path,\n\toperations: Op[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterEnd: number,\n\toutputStart: number,\n\tmatches: readonly ArrayMatch[],\n): void => {\n\tlet beforeAt = beforeStart;\n\tlet afterAt = afterStart;\n\tlet outputAt = outputStart;\n\tfor (const [beforeMatch, afterMatch] of matches) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tdiffArrayRegion(before, after, path, operations, beforeAt, beforeMatch, afterAt, afterMatch, outputAt);\n\t\toutputAt += afterMatch - afterAt;\n\t\tif (!sameValue(before[beforeMatch]!, after[afterMatch]!)) {\n\t\t\tdiffValue(before[beforeMatch]!, after[afterMatch]!, [...path, outputAt], operations);\n\t\t}\n\t\toutputAt += 1;\n\t\tbeforeAt = beforeMatch + 1;\n\t\tafterAt = afterMatch + 1;\n\t}\n\tif (!overflowedBatches.has(operations)) {\n\t\tdiffArrayRegion(before, after, path, operations, beforeAt, beforeEnd, afterAt, afterEnd, outputAt);\n\t}\n};\n\nfunction diffArrayRegion(\n\tbefore: JsonValue[],\n\tafter: JsonValue[],\n\tpath: Path,\n\toperations: Op[],\n\tbeforeStart: number,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterEnd: number,\n\toutputStart: number,\n): void {\n\tif (overflowedBatches.has(operations)) return;\n\twhile (beforeStart < beforeEnd && afterStart < afterEnd && sameValue(before[beforeStart]!, after[afterStart]!)) {\n\t\tbeforeStart += 1;\n\t\tafterStart += 1;\n\t\toutputStart += 1;\n\t}\n\twhile (beforeStart < beforeEnd && afterStart < afterEnd && sameValue(before[beforeEnd - 1]!, after[afterEnd - 1]!)) {\n\t\tbeforeEnd -= 1;\n\t\tafterEnd -= 1;\n\t}\n\tconst beforeCount = beforeEnd - beforeStart;\n\tconst afterCount = afterEnd - afterStart;\n\tif (beforeCount === 0 && afterCount === 0) return;\n\tif (beforeCount === 0 || afterCount === 0) {\n\t\temitOperation(operations, [\"p\", path, outputStart, beforeCount, after.slice(afterStart, afterEnd)]);\n\t\treturn;\n\t}\n\n\tif (beforeCount === afterCount) {\n\t\tconst positional: ArrayMatch[] = [];\n\t\tfor (let offset = 0; offset < beforeCount; offset++) {\n\t\t\tif (sameValue(before[beforeStart + offset]!, after[afterStart + offset]!)) {\n\t\t\t\tpositional.push([beforeStart + offset, afterStart + offset]);\n\t\t\t}\n\t\t}\n\t\tif (positional.length > 0) {\n\t\t\tprocessArrayMatches(\n\t\t\t\tbefore,\n\t\t\t\tafter,\n\t\t\t\tpath,\n\t\t\t\toperations,\n\t\t\t\tbeforeStart,\n\t\t\t\tbeforeEnd,\n\t\t\t\tafterStart,\n\t\t\t\tafterEnd,\n\t\t\t\toutputStart,\n\t\t\t\tpositional,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst subsequence = identitySubsequence(before, beforeStart, beforeEnd, after, afterStart, afterEnd);\n\tif (subsequence !== undefined && subsequence.length > 0) {\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tsubsequence,\n\t\t);\n\t\treturn;\n\t}\n\n\tconst identity = identityAnchors(before, beforeStart, beforeEnd, after, afterStart, afterEnd);\n\tif (identity.length > 0) {\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tidentity,\n\t\t);\n\t\treturn;\n\t}\n\n\tconst semantic = lcsMatches(\n\t\tbefore.slice(beforeStart, beforeEnd),\n\t\tafter.slice(afterStart, afterEnd),\n\t\tsemanticallyAligned,\n\t\tMAX_SEMANTIC_CELLS,\n\t);\n\tif (semantic !== undefined && semantic.length > 0) {\n\t\tconst absolute = semantic.map(\n\t\t\t([beforeIndex, afterIndex]) => [beforeStart + beforeIndex, afterStart + afterIndex] as const,\n\t\t);\n\t\tprocessArrayMatches(\n\t\t\tbefore,\n\t\t\tafter,\n\t\t\tpath,\n\t\t\toperations,\n\t\t\tbeforeStart,\n\t\t\tbeforeEnd,\n\t\t\tafterStart,\n\t\t\tafterEnd,\n\t\t\toutputStart,\n\t\t\tabsolute,\n\t\t);\n\t\treturn;\n\t}\n\n\tif (beforeCount === 1 && afterCount === 1) {\n\t\tdiffValue(before[beforeStart]!, after[afterStart]!, [...path, outputStart], operations);\n\t\treturn;\n\t}\n\temitOperation(operations, [\"p\", path, outputStart, beforeCount, after.slice(afterStart, afterEnd)]);\n}\n\nconst diffArray = (before: JsonValue[], after: JsonValue[], path: Path, operations: Op[]): void => {\n\tif (before === after || equalJson(before, after)) return;\n\tif (\n\t\tbefore.length === after.length &&\n\t\tbefore.length > 1 &&\n\t\t!sameValue(before[0]!, after[0]!) &&\n\t\t!sameValue(before[before.length - 1]!, after[after.length - 1]!)\n\t) {\n\t\tconst order = permutation(before, after);\n\t\tif (order !== undefined) {\n\t\t\temitOperation(operations, [\"m\", path, order]);\n\t\t\treturn;\n\t\t}\n\t}\n\tdiffArrayRegion(before, after, path, operations, 0, before.length, 0, after.length, 0);\n};\n\nconst diffObject = (\n\tbefore: Record<string, JsonValue>,\n\tafter: Record<string, JsonValue>,\n\tpath: Path,\n\toperations: Op[],\n): void => {\n\tconst beforeKeys = Object.keys(before);\n\tconst afterKeys = Object.keys(after);\n\tif ([...beforeKeys, ...afterKeys].some((key) => RESERVED_SEGMENTS.has(key))) {\n\t\tif (!equalJson(before, after)) emitSet(path, after, operations);\n\t\treturn;\n\t}\n\tfor (const key of afterKeys) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tif (Object.hasOwn(before, key)) diffValue(before[key]!, after[key]!, [...path, key], operations);\n\t\telse emitSet([...path, key], after[key]!, operations);\n\t}\n\tfor (const key of beforeKeys) {\n\t\tif (overflowedBatches.has(operations)) return;\n\t\tif (!Object.hasOwn(after, key)) emitOperation(operations, [\"d\", [...path, key] as unknown as NonEmptyPath]);\n\t}\n};\n\nconst diffValue = (before: JsonValue, after: JsonValue, path: Path, operations: Op[]): void => {\n\tif (before === after || overflowedBatches.has(operations)) return;\n\tif (typeof before === \"string\" && typeof after === \"string\" && path.length > 0) {\n\t\temitString(before, after, path as NonEmptyPath, operations);\n\t\treturn;\n\t}\n\tif (Array.isArray(before) && Array.isArray(after)) {\n\t\tdiffArray(before, after, path, operations);\n\t\treturn;\n\t}\n\tif (isContainer(before) && isContainer(after) && !Array.isArray(before) && !Array.isArray(after)) {\n\t\tdiffObject(before, after, path, operations);\n\t\treturn;\n\t}\n\temitSet(path, after, operations);\n};\n\nconst jsonCost = (value: JsonValue): number => {\n\tif (value === null) return 4;\n\tif (typeof value === \"string\") return value.length + 2;\n\tif (typeof value === \"number\") return String(value).length;\n\tif (typeof value === \"boolean\") return value ? 4 : 5;\n\tif (Array.isArray(value)) {\n\t\tlet cost = 2;\n\t\tfor (let index = 0; index < value.length; index++) cost += jsonCost(value[index]!) + (index === 0 ? 0 : 1);\n\t\treturn cost;\n\t}\n\tlet cost = 2;\n\tlet index = 0;\n\tfor (const key of Object.keys(value)) {\n\t\tcost += key.length + 3 + jsonCost(value[key]!) + (index++ === 0 ? 0 : 1);\n\t}\n\treturn cost;\n};\n\nconst pathCost = (path: Path): number => {\n\tlet cost = 2;\n\tfor (let index = 0; index < path.length; index++) {\n\t\tconst segment: Seg = path[index]!;\n\t\tcost += (typeof segment === \"string\" ? segment.length + 2 : String(segment).length) + (index === 0 ? 0 : 1);\n\t}\n\treturn cost;\n};\n\nconst operationCost = (operation: Op): number => {\n\tswitch (operation[0]) {\n\t\tcase \"r\":\n\t\t\treturn 6 + jsonCost(operation[1]);\n\t\tcase \"s\":\n\t\t\treturn 7 + pathCost(operation[1]) + jsonCost(operation[2]);\n\t\tcase \"d\":\n\t\t\treturn 6 + pathCost(operation[1]);\n\t\tcase \"a\":\n\t\t\treturn 7 + pathCost(operation[1]) + operation[2].length + 2;\n\t\tcase \"t\":\n\t\t\treturn 7 + pathCost(operation[1]) + String(operation[2]).length;\n\t\tcase \"p\":\n\t\t\treturn (\n\t\t\t\t10 +\n\t\t\t\tpathCost(operation[1]) +\n\t\t\t\tString(operation[2]).length +\n\t\t\t\tString(operation[3]).length +\n\t\t\t\tjsonCost(operation[4])\n\t\t\t);\n\t\tcase \"m\":\n\t\t\treturn 7 + pathCost(operation[1]) + jsonCost(operation[2]);\n\t}\n};\n\n/** Compute a compact operation batch from two immutable JSON revisions. */\nexport function diffRevisions(before: JsonValue, after: JsonValue): Op[] {\n\tconst operations: Op[] = [];\n\tdiffValue(before, after, [], operations);\n\tif (overflowedBatches.has(operations)) return [[\"r\", after]];\n\tif (operations.length === 0 || operations[0]?.[0] === \"r\") return operations;\n\tlet deltaCost = 2;\n\tfor (const operation of operations) deltaCost += operationCost(operation) + 1;\n\tif (deltaCost < 65_536) return operations;\n\tconst snapshotCost = jsonCost(after) + 6;\n\treturn deltaCost >= snapshotCost ? [[\"r\", after]] : operations;\n}\n"]}
|
package/dist/delta/index.d.ts
CHANGED
|
@@ -44,9 +44,17 @@ export declare const isBase: (ops: readonly (Op | WireOp)[]) => boolean;
|
|
|
44
44
|
* Always correct: the returned n satisfies a.slice(a.length - n) === b.slice(0, n).
|
|
45
45
|
*/
|
|
46
46
|
export declare function overlap(a: string, b: string, scan: number, probe?: number, maxCandidates?: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps
|
|
49
|
+
* all of `text` alive, so an append op cut from a long, growing string would retain that whole string for as long as
|
|
50
|
+
* the op lives: in a delta chain, a watch backlog, or a value built by applying the op. Appending a character and
|
|
51
|
+
* slicing it off again makes V8 copy just the slice.
|
|
52
|
+
*/
|
|
53
|
+
export declare function ownedSlice(text: string, start: number, end?: number): string;
|
|
47
54
|
export { diffRevisions } from "./diff.ts";
|
|
48
55
|
export type { Draft } from "./draft.ts";
|
|
49
|
-
export { type Change, type Prepared, type Tracker, track } from "./tracker.ts";
|
|
56
|
+
export { appendText, type Change, type Prepared, type StringKeys, type Tracker, track } from "./tracker.ts";
|
|
57
|
+
export { PendingOps, type PendingTake } from "./pending.ts";
|
|
50
58
|
/**
|
|
51
59
|
* Segments that reach the prototype chain.
|
|
52
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/delta/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,EAAE,CAAC;AAClC,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;AAEpD,qEAAqE;AACrE,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,MAAM,CAAC;AAExD;;;;;;;;;;GAUG;AAC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AM,CAAC;IAC7B,YAAY,IAAI,EAAE,IAAI,GAAG,MAAM,EAI9B;CACD;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CAErE;AAgFD,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAsBnG;AA2GD,MAAM,WAAW,OAAO;IACvB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAgB,OAAO,IAAI,OAAO,CA6FjC;AAED,MAAM,WAAW,OAAO;IACvB,2EAA2E;IAC3E,MAAM,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;CACvC;AAED,wBAAgB,OAAO,IAAI,OAAO,CAwEjC"}
|
package/dist/delta/index.js
CHANGED
|
@@ -41,9 +41,20 @@ export function overlap(a, b, scan, probe = 64, maxCandidates = 8) {
|
|
|
41
41
|
}
|
|
42
42
|
return 0;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps
|
|
46
|
+
* all of `text` alive, so an append op cut from a long, growing string would retain that whole string for as long as
|
|
47
|
+
* the op lives: in a delta chain, a watch backlog, or a value built by applying the op. Appending a character and
|
|
48
|
+
* slicing it off again makes V8 copy just the slice.
|
|
49
|
+
*/
|
|
50
|
+
export function ownedSlice(text, start, end = text.length) {
|
|
51
|
+
return `${text.slice(start, end)} `.slice(0, -1);
|
|
52
|
+
}
|
|
44
53
|
// ─── Immutable revision tracking ─────────────────────────────────────────────
|
|
45
54
|
export { diffRevisions } from "./diff.js";
|
|
46
|
-
export { track } from "./tracker.js";
|
|
55
|
+
export { appendText, track } from "./tracker.js";
|
|
56
|
+
// ─── Pending ops of a slow consumer ──────────────────────────────────────────
|
|
57
|
+
export { PendingOps } from "./pending.js";
|
|
47
58
|
// ─── Path safety ─────────────────────────────────────────────────────────────
|
|
48
59
|
/**
|
|
49
60
|
* Segments that reach the prototype chain.
|
|
@@ -441,16 +452,9 @@ function copyContainers(root, path, owned) {
|
|
|
441
452
|
return value.slice();
|
|
442
453
|
if (!isObj(value))
|
|
443
454
|
throw new PathError(path);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
value: value[key],
|
|
448
|
-
writable: true,
|
|
449
|
-
enumerable: true,
|
|
450
|
-
configurable: true,
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
return result;
|
|
455
|
+
// Spread and `Object.assign()` onto a null-prototype object define own data properties, `__proto__` included,
|
|
456
|
+
// as `Object.defineProperty()` per key does, at a fraction of its cost.
|
|
457
|
+
return Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };
|
|
454
458
|
};
|
|
455
459
|
if (!isObj(root))
|
|
456
460
|
throw new PathError(path);
|