@earendil-works/chord 0.86.0 → 0.87.0
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/README.md +22 -16
- package/dist/delta/index.d.ts +6 -4
- package/dist/delta/index.d.ts.map +1 -1
- package/dist/delta/index.js +44 -2
- package/dist/delta/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/provider.d.ts.map +1 -1
- package/dist/services/provider.js +46 -16
- package/dist/services/provider.js.map +1 -1
- package/dist/services/state-internals.d.ts +0 -1
- package/dist/services/state-internals.d.ts.map +1 -1
- package/dist/services/state-internals.js.map +1 -1
- package/dist/services/state.d.ts +2 -2
- package/dist/services/state.d.ts.map +1 -1
- package/dist/services/state.js +105 -32
- package/dist/services/state.js.map +1 -1
- package/dist/state/diff.d.ts +5 -0
- package/dist/state/diff.d.ts.map +1 -0
- package/dist/state/diff.js +259 -0
- package/dist/state/diff.js.map +1 -0
- package/dist/state/draft.d.ts +13 -0
- package/dist/state/draft.d.ts.map +1 -0
- package/dist/state/draft.js +540 -0
- package/dist/state/draft.js.map +1 -0
- package/dist/state/value.d.ts +9 -0
- package/dist/state/value.d.ts.map +1 -0
- package/dist/state/value.js +175 -0
- package/dist/state/value.js.map +1 -0
- package/dist/types.d.ts +8 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/delta/README.md +9 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/state/draft.ts"],"names":[],"mappings":"AAmCA,MAAM,aAAa,GAAc,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,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QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC/F,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,SAAS,gBAAgB,CAAC,KAAgB,EAAQ;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,EAAE,CAAC;QACrF,MAAM,IAAI,SAAS,CAAC,6DAA6D,CAAC,CAAC;IACpF,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;YAChE,MAAM,IAAI,SAAS,CAAC,wDAAwD,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["/** A mutable transaction-scoped view of a JSON value, preserving tuple positions. */\nexport type Draft<T, Depth extends readonly unknown[] = []> = Depth[\"length\"] extends 8\n\t? T\n\t: T extends null | boolean | number | string\n\t\t? T\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { -readonly [Key in keyof T]: Draft<T[Key], [...Depth, unknown]> }\n\t\t\t\t: T;\n\nexport type ProduceMetadata<T> = {\n\tvalue: T;\n\towned: WeakSet<object>;\n};\n\ntype Container = Record<string, unknown> | unknown[];\n\ntype DraftState = {\n\tbase: Container;\n\tcontext: DraftContext;\n\tcopy: Container | undefined;\n\tmethods: Map<string, unknown> | undefined;\n\tproxy: object;\n\ttarget: unknown[] | undefined;\n};\n\ntype DraftContext = {\n\tactive: boolean;\n\tcreated: DraftState[];\n\towned: WeakSet<object>;\n\tproxies: WeakMap<object, DraftState>;\n\tstates: WeakMap<object, DraftState>;\n};\n\nconst RELEASED_BASE: Container = Object.freeze({});\nconst ARRAY_MUTATORS = new Set([\"push\", \"pop\", \"shift\", \"unshift\", \"splice\", \"sort\", \"reverse\", \"fill\", \"copyWithin\"]);\n\n/** Run a mutation recipe and return its value with transaction ownership metadata. */\nexport function produceWithMetadata<T extends object>(base: T, recipe: (draft: Draft<T>) => void): ProduceMetadata<T> {\n\tconst context: DraftContext = {\n\t\tactive: true,\n\t\tcreated: [],\n\t\towned: new WeakSet<object>(),\n\t\tproxies: new WeakMap<object, DraftState>(),\n\t\tstates: new WeakMap<object, DraftState>(),\n\t};\n\tconst root = getState(context, base as Container);\n\ttry {\n\t\tconst outcome = (recipe as (draft: Draft<T>) => unknown)(root.proxy as Draft<T>);\n\t\tif (isPromiseLike(outcome)) {\n\t\t\tvoid Promise.resolve(outcome).catch(() => undefined);\n\t\t\tthrow new TypeError(\"Replicated state change callbacks must be synchronous\");\n\t\t}\n\t\treturn {\n\t\t\tvalue: finalize(root, new Set<DraftState>(), new WeakMap<DraftState, Container>()) as T,\n\t\t\towned: context.owned,\n\t\t};\n\t} finally {\n\t\tcontext.active = false;\n\t\tfor (const state of context.created) {\n\t\t\tstate.base = RELEASED_BASE;\n\t\t\tstate.copy = undefined;\n\t\t\tstate.methods = undefined;\n\t\t\tstate.proxy = RELEASED_BASE;\n\t\t\tstate.target = undefined;\n\t\t}\n\t\tcontext.created.length = 0;\n\t\tcontext.proxies = new WeakMap();\n\t\tcontext.states = new WeakMap();\n\t}\n}\n\n/** Run a mutation recipe against a copy-on-write draft of `base`. */\nexport function produce<T extends object>(base: T, recipe: (draft: Draft<T>) => void): T {\n\treturn produceWithMetadata(base, recipe).value;\n}\n\nfunction getState(context: DraftContext, base: Container): DraftState {\n\tconst existing = context.states.get(base);\n\tif (existing !== undefined) return existing;\n\n\tconst target = Array.isArray(base) ? [] : undefined;\n\tif (target !== undefined) Reflect.set(target, \"length\", base.length);\n\tconst state: DraftState = {\n\t\tbase,\n\t\tcontext,\n\t\tcopy: undefined,\n\t\tmethods: undefined,\n\t\tproxy: target ?? {},\n\t\ttarget,\n\t};\n\tstate.proxy = new Proxy(target ?? state, createHandler(state));\n\tcontext.states.set(base, state);\n\tcontext.proxies.set(state.proxy, state);\n\tcontext.created.push(state);\n\treturn state;\n}\n\ntype DraftHandler = ProxyHandler<object> & { state: DraftState };\n\nconst handlerPrototype: ProxyHandler<object> = {\n\tdeleteProperty(this: DraftHandler, _target, property): boolean {\n\t\tconst state = this.state;\n\t\tassertStringWrite(property);\n\t\tconst current = currentValue(state);\n\t\tif (Array.isArray(current)) throw new TypeError(\"Draft arrays cannot contain holes\");\n\t\tif (!Object.hasOwn(current, property)) return true;\n\t\tconst deleted = Reflect.deleteProperty(ensureCopy(state), property);\n\t\tsyncArrayTarget(state);\n\t\treturn deleted;\n\t},\n\tdefineProperty(this: DraftHandler): never {\n\t\tassertActive(this.state.context);\n\t\tthrow new TypeError(\"Defining draft properties is not supported\");\n\t},\n\tget(this: DraftHandler, _target, property): unknown {\n\t\tconst state = this.state;\n\t\tconst current = currentValue(state);\n\t\tconst value = Reflect.get(current, property, state.proxy);\n\t\tif (Array.isArray(current) && typeof property === \"string\" && ARRAY_MUTATORS.has(property)) {\n\t\t\treturn arrayMutator(state, property, value);\n\t\t}\n\t\treturn draftValue(state.context, value);\n\t},\n\tgetOwnPropertyDescriptor(this: DraftHandler, _target, property): PropertyDescriptor | undefined {\n\t\tconst state = this.state;\n\t\tconst current = currentValue(state);\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(current, property);\n\t\tif (descriptor === undefined) return undefined;\n\t\tif (Array.isArray(current) && property === \"length\") {\n\t\t\tsyncArrayTarget(state);\n\t\t\treturn Reflect.getOwnPropertyDescriptor(state.target!, property);\n\t\t}\n\t\treturn {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: descriptor.enumerable,\n\t\t\tvalue: \"value\" in descriptor ? draftValue(state.context, descriptor.value) : undefined,\n\t\t\twritable: true,\n\t\t};\n\t},\n\tgetPrototypeOf(this: DraftHandler): object | null {\n\t\tassertActive(this.state.context);\n\t\treturn Object.getPrototypeOf(this.state.base);\n\t},\n\thas(this: DraftHandler, _target, property): boolean {\n\t\treturn Reflect.has(currentValue(this.state), property);\n\t},\n\tisExtensible(this: DraftHandler): boolean {\n\t\tassertActive(this.state.context);\n\t\treturn true;\n\t},\n\townKeys(this: DraftHandler): ArrayLike<string | symbol> {\n\t\treturn Reflect.ownKeys(currentValue(this.state));\n\t},\n\tpreventExtensions(this: DraftHandler): never {\n\t\tassertActive(this.state.context);\n\t\tthrow new TypeError(\"Drafts cannot be made non-extensible\");\n\t},\n\tset(this: DraftHandler, _target, property, value): boolean {\n\t\tconst state = this.state;\n\t\tassertStringWrite(property);\n\t\tconst current = currentValue(state);\n\t\tlet stored: unknown;\n\t\tif (isContainer(value)) {\n\t\t\tstored = cloneAssigned(value, state.context, new Set<object>());\n\t\t} else {\n\t\t\tassertJsonPrimitive(value);\n\t\t\tstored = value;\n\t\t}\n\t\tif (Object.hasOwn(current, property) && Object.is(Reflect.get(current, property), stored)) return true;\n\t\tconst copy = ensureCopy(state);\n\t\tif (Array.isArray(copy) && property === \"length\") {\n\t\t\tconst written = Reflect.set(copy, property, stored);\n\t\t\tsyncArrayTarget(state);\n\t\t\treturn written;\n\t\t}\n\t\tObject.defineProperty(copy, property, {\n\t\t\tvalue: stored,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t\tsyncArrayTarget(state);\n\t\treturn true;\n\t},\n\tsetPrototypeOf(this: DraftHandler): never {\n\t\tassertActive(this.state.context);\n\t\tthrow new TypeError(\"Changing a draft prototype is not supported\");\n\t},\n};\n\nfunction createHandler(state: DraftState): ProxyHandler<object> {\n\tconst handler = Object.create(handlerPrototype) as DraftHandler;\n\thandler.state = state;\n\treturn handler;\n}\n\nfunction arrayMutator(state: DraftState, property: string, value: unknown): unknown {\n\tassertActive(state.context);\n\tconst cached = state.methods?.get(property);\n\tif (cached !== undefined) return cached;\n\tif (typeof value !== \"function\") return draftValue(state.context, value);\n\tconst wrapped = function (this: unknown, ...args: unknown[]): unknown {\n\t\tassertActive(state.context);\n\t\tconst receiver = isContainer(this) ? state.context.proxies.get(this) : undefined;\n\t\tif (receiver === undefined) return Reflect.apply(value, this, args);\n\t\tconst target = ensureCopy(receiver);\n\t\tif (!Array.isArray(target)) throw new TypeError(\"Array mutator receiver is not an array draft\");\n\t\ttry {\n\t\t\treturn mutateArray(receiver, target, property, args);\n\t\t} finally {\n\t\t\tsyncArrayTarget(receiver);\n\t\t}\n\t};\n\tif (state.methods === undefined) state.methods = new Map();\n\tstate.methods.set(property, wrapped);\n\treturn wrapped;\n}\n\nfunction mutateArray(state: DraftState, target: unknown[], property: string, args: unknown[]): unknown {\n\tconst { context } = state;\n\tswitch (property) {\n\t\tcase \"push\": {\n\t\t\tconst items = cloneArrayItems(args, context);\n\t\t\tfor (const item of items) defineArrayValue(target, target.length, item);\n\t\t\treturn target.length;\n\t\t}\n\t\tcase \"pop\": {\n\t\t\tif (target.length === 0) return undefined;\n\t\t\tconst index = target.length - 1;\n\t\t\tconst removed = target[index];\n\t\t\tReflect.deleteProperty(target, String(index));\n\t\t\ttarget.length = index;\n\t\t\treturn draftValue(context, removed);\n\t\t}\n\t\tcase \"shift\":\n\t\t\treturn draftValue(context, Reflect.apply(Array.prototype.shift, target, []));\n\t\tcase \"unshift\": {\n\t\t\tconst items = cloneArrayItems(args, context);\n\t\t\tif (hasInheritedGrowthIndex(target, target.length + items.length)) {\n\t\t\t\tspliceArray(target, items, 0, 0, context);\n\t\t\t\treturn target.length;\n\t\t\t}\n\t\t\treturn Reflect.apply(Array.prototype.unshift, target, items);\n\t\t}\n\t\tcase \"splice\": {\n\t\t\tconst length = target.length;\n\t\t\tconst start = args.length === 0 ? 0 : clampArrayIndex(toIntegerOrInfinity(args[0]), length);\n\t\t\tconst remove =\n\t\t\t\targs.length === 0\n\t\t\t\t\t? 0\n\t\t\t\t\t: args.length === 1\n\t\t\t\t\t\t? length - start\n\t\t\t\t\t\t: Math.min(Math.max(toIntegerOrInfinity(args[1]), 0), length - start);\n\t\t\tconst items = cloneArrayItems(args.slice(2), context);\n\t\t\tif (\n\t\t\t\t!mayRunCoercionCode(args[0]) &&\n\t\t\t\t!mayRunCoercionCode(args[1]) &&\n\t\t\t\t!hasInheritedGrowthIndex(target, length - remove + items.length)\n\t\t\t) {\n\t\t\t\tconst removed = Reflect.apply(Array.prototype.splice, target, [start, remove, ...items]) as unknown[];\n\t\t\t\treturn removed.map((item) => draftValue(context, item));\n\t\t\t}\n\t\t\treturn spliceArray(target, items, start, remove, context, length);\n\t\t}\n\t\tcase \"sort\": {\n\t\t\tconst comparator = args[0];\n\t\t\tif (comparator !== undefined && typeof comparator !== \"function\") {\n\t\t\t\tReflect.apply(Array.prototype.sort, target, args);\n\t\t\t} else {\n\t\t\t\tReflect.apply(Array.prototype.sort, target, [\n\t\t\t\t\t(left: unknown, right: unknown): number => {\n\t\t\t\t\t\tconst draftedLeft = draftValue(context, left);\n\t\t\t\t\t\tconst draftedRight = draftValue(context, right);\n\t\t\t\t\t\tif (typeof comparator === \"function\") {\n\t\t\t\t\t\t\treturn Reflect.apply(comparator, undefined, [draftedLeft, draftedRight]) as number;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst leftString = String(draftedLeft);\n\t\t\t\t\t\tconst rightString = String(draftedRight);\n\t\t\t\t\t\treturn leftString < rightString ? -1 : leftString > rightString ? 1 : 0;\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t}\n\t\t\treturn state.proxy;\n\t\t}\n\t\tcase \"reverse\":\n\t\t\tReflect.apply(Array.prototype.reverse, target, []);\n\t\t\treturn state.proxy;\n\t\tcase \"fill\": {\n\t\t\tconst length = target.length;\n\t\t\tconst start = args.length > 1 ? clampArrayIndex(toIntegerOrInfinity(args[1]), length) : 0;\n\t\t\tconst end =\n\t\t\t\targs.length > 2 && args[2] !== undefined ? clampArrayIndex(toIntegerOrInfinity(args[2]), length) : length;\n\t\t\tif (end <= start) return state.proxy;\n\t\t\tconst supplied = args[0];\n\t\t\tfor (let index = start; index < end; index++) {\n\t\t\t\tconst item = isContainer(supplied)\n\t\t\t\t\t? cloneAssigned(supplied, context, new Set<object>())\n\t\t\t\t\t: assertJsonPrimitive(supplied);\n\t\t\t\tdefineArrayValue(target, index, item);\n\t\t\t}\n\t\t\treturn state.proxy;\n\t\t}\n\t\tcase \"copyWithin\": {\n\t\t\tconst length = target.length;\n\t\t\tconst to = clampArrayIndex(toIntegerOrInfinity(args[0]), length);\n\t\t\tconst from = clampArrayIndex(toIntegerOrInfinity(args[1]), length);\n\t\t\tconst end =\n\t\t\t\targs.length > 2 && args[2] !== undefined ? clampArrayIndex(toIntegerOrInfinity(args[2]), length) : length;\n\t\t\tconst count = Math.min(Math.max(end - from, 0), length - to);\n\t\t\tconst source = target.slice(from, from + count);\n\t\t\tfor (let offset = 0; offset < count; offset++) {\n\t\t\t\tconst item = source[offset];\n\t\t\t\tconst itemState = isContainer(item) ? context.states.get(item) : undefined;\n\t\t\t\tconst current = (itemState?.proxy as Container | undefined) ?? item;\n\t\t\t\tconst copy = isContainer(current)\n\t\t\t\t\t? cloneAssigned(current, context, new Set<object>())\n\t\t\t\t\t: assertJsonPrimitive(current);\n\t\t\t\tdefineArrayValue(target, to + offset, copy);\n\t\t\t}\n\t\t\treturn state.proxy;\n\t\t}\n\t}\n\tthrow new TypeError(`Unsupported array mutator: ${property}`);\n}\n\nfunction cloneArrayItems(items: readonly unknown[], context: DraftContext): unknown[] {\n\treturn items.map((item) => {\n\t\tif (isContainer(item)) return cloneAssigned(item, context, new Set<object>());\n\t\tassertJsonPrimitive(item);\n\t\treturn item;\n\t});\n}\n\nfunction hasInheritedGrowthIndex(target: unknown[], nextLength: number): boolean {\n\tfor (let index = target.length; index < nextLength; index++) {\n\t\tif (index in target) return true;\n\t}\n\treturn false;\n}\n\nfunction mayRunCoercionCode(value: unknown): boolean {\n\treturn (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n}\n\nfunction spliceArray(\n\ttarget: unknown[],\n\titems: readonly unknown[],\n\tindex: number,\n\tremove: number,\n\tcontext: DraftContext,\n\tlength = target.length,\n): unknown[] {\n\tconst removed = new Array<unknown>(remove);\n\tfor (let offset = 0; offset < remove; offset++) {\n\t\tconst source = index + offset;\n\t\tif (!(source in target)) continue;\n\t\tdefineArrayValue(removed, offset, draftValue(context, target[source]));\n\t}\n\tif (items.length < remove) {\n\t\tfor (let source = index + remove; source < length; source++) {\n\t\t\tdefineArrayValue(target, source - remove + items.length, target[source]);\n\t\t}\n\t} else if (items.length > remove) {\n\t\tfor (let source = length - 1; source >= index + remove; source--) {\n\t\t\tdefineArrayValue(target, source - remove + items.length, target[source]);\n\t\t}\n\t}\n\tfor (let offset = 0; offset < items.length; offset++) defineArrayValue(target, index + offset, items[offset]);\n\ttarget.length = length - remove + items.length;\n\treturn removed;\n}\n\nfunction defineArrayValue(target: unknown[], index: number, value: unknown): void {\n\tObject.defineProperty(target, index, {\n\t\tvalue,\n\t\twritable: true,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t});\n}\n\nfunction toIntegerOrInfinity(value: unknown): number {\n\tconst number = +(value as unknown as number);\n\tif (Number.isNaN(number) || number === 0) return 0;\n\treturn Number.isFinite(number) ? Math.trunc(number) : number;\n}\n\nfunction clampArrayIndex(value: number, length: number): number {\n\tif (value === Number.NEGATIVE_INFINITY) return 0;\n\tif (value < 0) return Math.max(length + value, 0);\n\treturn Math.min(value, length);\n}\n\nfunction currentValue(state: DraftState): Container {\n\tassertActive(state.context);\n\treturn state.copy ?? state.base;\n}\n\nfunction ensureCopy(state: DraftState): Container {\n\tif (state.copy !== undefined) return state.copy;\n\tif (state.context.owned.has(state.base)) {\n\t\tstate.copy = state.base;\n\t} else {\n\t\tstate.copy = shallowOwnedCopy(state.base, state.context);\n\t}\n\treturn state.copy;\n}\n\nfunction shallowOwnedCopy(value: Container, context: DraftContext): Container {\n\tif (Array.isArray(value)) {\n\t\tconst copy = value.slice();\n\t\tcontext.owned.add(copy);\n\t\treturn copy;\n\t}\n\tconst copy = Object.create(Object.getPrototypeOf(value)) as Record<string, unknown>;\n\tfor (const key of Object.keys(value)) {\n\t\tObject.defineProperty(copy, key, {\n\t\t\tvalue: value[key],\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\tcontext.owned.add(copy);\n\treturn copy;\n}\n\nfunction cloneAssigned(value: Container, context: DraftContext, ancestors: Set<object>): Container {\n\tif (ancestors.has(value)) throw new TypeError(\"Assigned JSON values cannot contain cycles\");\n\tancestors.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tassertDenseArray(value);\n\t\t\tconst clone: unknown[] = [];\n\t\t\tcontext.owned.add(clone);\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tclone.push(cloneAssignedValue(Reflect.get(value, String(index)), context, ancestors));\n\t\t\t}\n\t\t\treturn clone;\n\t\t}\n\n\t\tconst prototype = Object.getPrototypeOf(value);\n\t\tif (prototype !== Object.prototype && prototype !== null) {\n\t\t\tthrow new TypeError(\"Assigned JSON containers must be plain objects or arrays\");\n\t\t}\n\t\tconst clone = Object.create(prototype) as Record<string, unknown>;\n\t\tcontext.owned.add(clone);\n\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Assigned JSON objects cannot have symbol properties\");\n\t\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(value, key);\n\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\tthrow new TypeError(\"Assigned JSON objects must contain enumerable data properties\");\n\t\t\t}\n\t\t\tObject.defineProperty(clone, key, {\n\t\t\t\tvalue: cloneAssignedValue(descriptor.value, context, ancestors),\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\treturn clone;\n\t} finally {\n\t\tancestors.delete(value);\n\t}\n}\n\nfunction cloneAssignedValue(value: unknown, context: DraftContext, ancestors: Set<object>): unknown {\n\tif (isContainer(value)) return cloneAssigned(value, context, ancestors);\n\tassertJsonPrimitive(value);\n\treturn value;\n}\n\nfunction assertJsonPrimitive(value: unknown): null | boolean | number | string {\n\tif (value === undefined) throw new TypeError(\"Assigned values cannot be undefined\");\n\tif (\n\t\tvalue !== null &&\n\t\ttypeof value !== \"string\" &&\n\t\ttypeof value !== \"boolean\" &&\n\t\t!(typeof value === \"number\" && Number.isFinite(value))\n\t) {\n\t\tthrow new TypeError(\"Assigned values must be strict JSON values\");\n\t}\n\treturn value;\n}\n\nfunction draftValue(context: DraftContext, value: unknown): unknown {\n\tif (!isContainer(value)) return value;\n\treturn getState(context, value).proxy;\n}\n\nfunction isContainer(value: unknown): value is Container {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n\treturn (\n\t\t((typeof value === \"object\" && value !== null) || typeof value === \"function\") &&\n\t\ttypeof (value as { then?: unknown }).then === \"function\"\n\t);\n}\n\nfunction assertActive(context: DraftContext): void {\n\tif (!context.active) throw new TypeError(\"Cannot use a draft outside its change callback\");\n}\n\nfunction assertStringWrite(property: string | symbol): asserts property is string {\n\tif (typeof property === \"symbol\") throw new TypeError(\"Symbol writes are not supported\");\n}\n\nfunction syncArrayTarget(state: DraftState): void {\n\tconst current = currentValue(state);\n\tif (Array.isArray(current)) Reflect.set(state.target!, \"length\", current.length);\n}\n\nfunction finalize(\n\tstate: DraftState,\n\tfinalizing: Set<DraftState>,\n\tfinalized: WeakMap<DraftState, Container>,\n): Container {\n\tconst cached = finalized.get(state);\n\tif (cached !== undefined) return cached;\n\tif (finalizing.has(state)) throw new TypeError(\"Cyclic draft state is not supported\");\n\tfinalizing.add(state);\n\ttry {\n\t\tif (state.copy !== undefined && shallowEqual(state.base, state.copy)) state.copy = undefined;\n\t\tconst current = currentValue(state);\n\t\tlet result = current;\n\t\tfor (const key of Object.keys(current)) {\n\t\t\tconst value = Reflect.get(current, key);\n\t\t\tif (!isContainer(value)) continue;\n\t\t\tconst child = state.context.states.get(value);\n\t\t\tif (child === undefined) continue;\n\t\t\tconst finalizedChild = finalize(child, finalizing, finalized);\n\t\t\tif (finalizedChild === value) continue;\n\t\t\tif (result === state.base) result = shallowOwnedCopy(state.base, state.context);\n\t\t\tObject.defineProperty(result, key, {\n\t\t\t\tvalue: finalizedChild,\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\tif (state.copy !== undefined && Array.isArray(result)) assertDenseArray(result);\n\t\tfinalized.set(state, result);\n\t\treturn result;\n\t} finally {\n\t\tfinalizing.delete(state);\n\t}\n}\n\nfunction shallowEqual(left: Container, right: Container): boolean {\n\tif (Array.isArray(left) !== Array.isArray(right)) return false;\n\tif (Array.isArray(left) && Array.isArray(right) && left.length !== right.length) return false;\n\tconst leftKeys = Object.keys(left);\n\tconst rightKeys = Object.keys(right);\n\tif (leftKeys.length !== rightKeys.length) return false;\n\tconst leftRecord = left as Record<string, unknown>;\n\tconst rightRecord = right as Record<string, unknown>;\n\tfor (const key of leftKeys) {\n\t\tif (!Object.hasOwn(right, key) || !Object.is(leftRecord[key], rightRecord[key])) return false;\n\t}\n\treturn true;\n}\n\nfunction assertDenseArray(value: unknown[]): void {\n\tconst keys = Reflect.ownKeys(value);\n\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) {\n\t\tthrow new TypeError(\"Draft arrays must be dense and contain only indexed entries\");\n\t}\n\tfor (let index = 0; index < value.length; index++) {\n\t\tif (!Object.hasOwn(value, index) || value[index] === undefined) {\n\t\t\tthrow new TypeError(\"Draft arrays cannot contain holes or undefined entries\");\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonValue } from "../types.ts";
|
|
2
|
+
/** Owns and freezes immutable JSON revisions while reusing already-owned subtrees. */
|
|
3
|
+
export declare class JsonRevisionStore {
|
|
4
|
+
#private;
|
|
5
|
+
import<T extends object>(value: T): T;
|
|
6
|
+
commit<T extends object>(value: T, transactionOwned: WeakSet<object>): T;
|
|
7
|
+
adopt<T extends JsonValue>(value: T): T;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/state/value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,sFAAsF;AACtF,qBAAa,iBAAiB;;IAG7B,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEpC;IAED,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAEvE;IAED,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEtC;CAyHD","sourcesContent":["import type { JsonValue } from \"../types.ts\";\n\ntype JsonContainer = JsonValue[] | Record<string, JsonValue>;\n\nconst isContainer = (value: unknown): value is JsonContainer => typeof value === \"object\" && value !== null;\n\n/** Owns and freezes immutable JSON revisions while reusing already-owned subtrees. */\nexport class JsonRevisionStore {\n\treadonly #owned = new WeakSet<object>();\n\n\timport<T extends object>(value: T): T {\n\t\treturn this.#clone(value, new Set<object>()) as T;\n\t}\n\n\tcommit<T extends object>(value: T, transactionOwned: WeakSet<object>): T {\n\t\treturn this.#finish(value as JsonContainer, transactionOwned, new Set<object>(), new WeakSet<object>()) as T;\n\t}\n\n\tadopt<T extends JsonValue>(value: T): T {\n\t\treturn this.#adopt(value, new Set<object>(), new WeakSet<object>()) as T;\n\t}\n\n\t#clone(value: unknown, ancestors: Set<object>): JsonValue {\n\t\tif (!isContainer(value)) return assertPrimitive(value);\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tconst result = new Array<JsonValue>(value.length);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tObject.defineProperty(result, index, {\n\t\t\t\t\t\tvalue: this.#clone(value[index], ancestors),\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthis.#owned.add(result);\n\t\t\t\treturn Object.freeze(result) as unknown as JsonValue;\n\t\t\t}\n\t\t\tassertPlainObject(value);\n\t\t\tconst result = Object.create(Object.getPrototypeOf(value)) as Record<string, JsonValue>;\n\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(result, key, {\n\t\t\t\t\tvalue: this.#clone(descriptor.value, ancestors),\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.#owned.add(result);\n\t\t\treturn Object.freeze(result) as unknown as JsonValue;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\n\t#adopt(value: JsonValue, ancestors: Set<object>, finished: WeakSet<object>): JsonValue {\n\t\tif (!isContainer(value) || this.#owned.has(value)) return isContainer(value) ? value : assertPrimitive(value);\n\t\tif (finished.has(value)) return value;\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tconst child = this.#adopt(value[index]!, ancestors, finished);\n\t\t\t\t\tif (child !== value[index]) defineValue(value, String(index), child as JsonContainer);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertPlainObject(value);\n\t\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t\t}\n\t\t\t\t\tconst child = this.#adopt(descriptor.value as JsonValue, ancestors, finished);\n\t\t\t\t\tif (child !== descriptor.value && isContainer(child)) defineValue(value, key, child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinished.add(value);\n\t\t\tthis.#owned.add(value);\n\t\t\treturn Object.freeze(value) as unknown as JsonValue;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\n\t#finish(\n\t\tvalue: JsonContainer,\n\t\ttransactionOwned: WeakSet<object>,\n\t\tancestors: Set<object>,\n\t\tplacements: WeakSet<object>,\n\t): JsonContainer {\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tif (placements.has(value)) return this.#clone(value, new Set<object>()) as JsonContainer;\n\t\tplacements.add(value);\n\t\tif (this.#owned.has(value)) return value;\n\t\tif (!transactionOwned.has(value)) return this.#clone(value, ancestors) as JsonContainer;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tconst child = value[index];\n\t\t\t\t\tif (!isContainer(child)) {\n\t\t\t\t\t\tassertPrimitive(child);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst next = this.#finish(child, transactionOwned, ancestors, placements);\n\t\t\t\t\tif (next !== child) defineValue(value, String(index), next);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertPlainObject(value);\n\t\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t\t}\n\t\t\t\t\tif (!isContainer(descriptor.value)) {\n\t\t\t\t\t\tassertPrimitive(descriptor.value);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst next = this.#finish(descriptor.value, transactionOwned, ancestors, placements);\n\t\t\t\t\tif (next !== descriptor.value) defineValue(value, key, next);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.#owned.add(value);\n\t\t\treturn Object.freeze(value) as unknown as JsonContainer;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n}\n\nfunction defineValue(target: object, key: string, value: JsonContainer): void {\n\tObject.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });\n}\n\nfunction assertPrimitive(value: unknown): null | boolean | number | string {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return value;\n\tthrow new TypeError(\"Replicated state values must be strict JSON\");\n}\n\nfunction assertPlainObject(value: object): void {\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new TypeError(\"Replicated state containers must be plain objects or arrays\");\n\t}\n}\n\nfunction assertDenseArray(value: readonly unknown[]): void {\n\tconst keys = Reflect.ownKeys(value);\n\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) {\n\t\tthrow new TypeError(\"Replicated state arrays must be dense and contain only indexed entries\");\n\t}\n\tfor (let index = 0; index < value.length; index++) {\n\t\tif (!Object.hasOwn(value, index) || value[index] === undefined) {\n\t\t\tthrow new TypeError(\"Replicated state arrays cannot contain holes or undefined entries\");\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
const isContainer = (value) => typeof value === "object" && value !== null;
|
|
2
|
+
/** Owns and freezes immutable JSON revisions while reusing already-owned subtrees. */
|
|
3
|
+
export class JsonRevisionStore {
|
|
4
|
+
#owned = new WeakSet();
|
|
5
|
+
import(value) {
|
|
6
|
+
return this.#clone(value, new Set());
|
|
7
|
+
}
|
|
8
|
+
commit(value, transactionOwned) {
|
|
9
|
+
return this.#finish(value, transactionOwned, new Set(), new WeakSet());
|
|
10
|
+
}
|
|
11
|
+
adopt(value) {
|
|
12
|
+
return this.#adopt(value, new Set(), new WeakSet());
|
|
13
|
+
}
|
|
14
|
+
#clone(value, ancestors) {
|
|
15
|
+
if (!isContainer(value))
|
|
16
|
+
return assertPrimitive(value);
|
|
17
|
+
if (ancestors.has(value))
|
|
18
|
+
throw new TypeError("Replicated state cannot contain cycles");
|
|
19
|
+
ancestors.add(value);
|
|
20
|
+
try {
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
assertDenseArray(value);
|
|
23
|
+
const result = new Array(value.length);
|
|
24
|
+
for (let index = 0; index < value.length; index++) {
|
|
25
|
+
Object.defineProperty(result, index, {
|
|
26
|
+
value: this.#clone(value[index], ancestors),
|
|
27
|
+
writable: true,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
this.#owned.add(result);
|
|
33
|
+
return Object.freeze(result);
|
|
34
|
+
}
|
|
35
|
+
assertPlainObject(value);
|
|
36
|
+
const result = Object.create(Object.getPrototypeOf(value));
|
|
37
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
38
|
+
if (typeof key === "symbol")
|
|
39
|
+
throw new TypeError("Replicated state cannot contain symbol properties");
|
|
40
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
41
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor)) {
|
|
42
|
+
throw new TypeError("Replicated state objects must contain enumerable data properties");
|
|
43
|
+
}
|
|
44
|
+
Object.defineProperty(result, key, {
|
|
45
|
+
value: this.#clone(descriptor.value, ancestors),
|
|
46
|
+
writable: true,
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
this.#owned.add(result);
|
|
52
|
+
return Object.freeze(result);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
ancestors.delete(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
#adopt(value, ancestors, finished) {
|
|
59
|
+
if (!isContainer(value) || this.#owned.has(value))
|
|
60
|
+
return isContainer(value) ? value : assertPrimitive(value);
|
|
61
|
+
if (finished.has(value))
|
|
62
|
+
return value;
|
|
63
|
+
if (ancestors.has(value))
|
|
64
|
+
throw new TypeError("Replicated state cannot contain cycles");
|
|
65
|
+
ancestors.add(value);
|
|
66
|
+
try {
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
assertDenseArray(value);
|
|
69
|
+
for (let index = 0; index < value.length; index++) {
|
|
70
|
+
const child = this.#adopt(value[index], ancestors, finished);
|
|
71
|
+
if (child !== value[index])
|
|
72
|
+
defineValue(value, String(index), child);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
assertPlainObject(value);
|
|
77
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
78
|
+
if (typeof key === "symbol")
|
|
79
|
+
throw new TypeError("Replicated state cannot contain symbol properties");
|
|
80
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
81
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor)) {
|
|
82
|
+
throw new TypeError("Replicated state objects must contain enumerable data properties");
|
|
83
|
+
}
|
|
84
|
+
const child = this.#adopt(descriptor.value, ancestors, finished);
|
|
85
|
+
if (child !== descriptor.value && isContainer(child))
|
|
86
|
+
defineValue(value, key, child);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finished.add(value);
|
|
90
|
+
this.#owned.add(value);
|
|
91
|
+
return Object.freeze(value);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
ancestors.delete(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
#finish(value, transactionOwned, ancestors, placements) {
|
|
98
|
+
if (ancestors.has(value))
|
|
99
|
+
throw new TypeError("Replicated state cannot contain cycles");
|
|
100
|
+
if (placements.has(value))
|
|
101
|
+
return this.#clone(value, new Set());
|
|
102
|
+
placements.add(value);
|
|
103
|
+
if (this.#owned.has(value))
|
|
104
|
+
return value;
|
|
105
|
+
if (!transactionOwned.has(value))
|
|
106
|
+
return this.#clone(value, ancestors);
|
|
107
|
+
ancestors.add(value);
|
|
108
|
+
try {
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
assertDenseArray(value);
|
|
111
|
+
for (let index = 0; index < value.length; index++) {
|
|
112
|
+
const child = value[index];
|
|
113
|
+
if (!isContainer(child)) {
|
|
114
|
+
assertPrimitive(child);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const next = this.#finish(child, transactionOwned, ancestors, placements);
|
|
118
|
+
if (next !== child)
|
|
119
|
+
defineValue(value, String(index), next);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
assertPlainObject(value);
|
|
124
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
125
|
+
if (typeof key === "symbol")
|
|
126
|
+
throw new TypeError("Replicated state cannot contain symbol properties");
|
|
127
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
128
|
+
if (descriptor === undefined || !descriptor.enumerable || !("value" in descriptor)) {
|
|
129
|
+
throw new TypeError("Replicated state objects must contain enumerable data properties");
|
|
130
|
+
}
|
|
131
|
+
if (!isContainer(descriptor.value)) {
|
|
132
|
+
assertPrimitive(descriptor.value);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const next = this.#finish(descriptor.value, transactionOwned, ancestors, placements);
|
|
136
|
+
if (next !== descriptor.value)
|
|
137
|
+
defineValue(value, key, next);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.#owned.add(value);
|
|
141
|
+
return Object.freeze(value);
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
ancestors.delete(value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function defineValue(target, key, value) {
|
|
149
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
150
|
+
}
|
|
151
|
+
function assertPrimitive(value) {
|
|
152
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
153
|
+
return value;
|
|
154
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
155
|
+
return value;
|
|
156
|
+
throw new TypeError("Replicated state values must be strict JSON");
|
|
157
|
+
}
|
|
158
|
+
function assertPlainObject(value) {
|
|
159
|
+
const prototype = Object.getPrototypeOf(value);
|
|
160
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
161
|
+
throw new TypeError("Replicated state containers must be plain objects or arrays");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function assertDenseArray(value) {
|
|
165
|
+
const keys = Reflect.ownKeys(value);
|
|
166
|
+
if (keys.length !== value.length + 1 || keys.some((key) => typeof key !== "string")) {
|
|
167
|
+
throw new TypeError("Replicated state arrays must be dense and contain only indexed entries");
|
|
168
|
+
}
|
|
169
|
+
for (let index = 0; index < value.length; index++) {
|
|
170
|
+
if (!Object.hasOwn(value, index) || value[index] === undefined) {
|
|
171
|
+
throw new TypeError("Replicated state arrays cannot contain holes or undefined entries");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/state/value.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,GAAG,CAAC,KAAc,EAA0B,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AAE5G,sFAAsF;AACtF,MAAM,OAAO,iBAAiB;IACpB,MAAM,GAAG,IAAI,OAAO,EAAU,CAAC;IAExC,MAAM,CAAmB,KAAQ,EAAK;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,EAAU,CAAM,CAAC;IAAA,CAClD;IAED,MAAM,CAAmB,KAAQ,EAAE,gBAAiC,EAAK;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,KAAsB,EAAE,gBAAgB,EAAE,IAAI,GAAG,EAAU,EAAE,IAAI,OAAO,EAAU,CAAM,CAAC;IAAA,CAC7G;IAED,KAAK,CAAsB,KAAQ,EAAK;QACvC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,EAAU,EAAE,IAAI,OAAO,EAAU,CAAM,CAAC;IAAA,C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CAAC,wEAAwE,CAAC,CAAC;IAC/F,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;YAChE,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;QAC1F,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import type { JsonValue } from \"../types.ts\";\n\ntype JsonContainer = JsonValue[] | Record<string, JsonValue>;\n\nconst isContainer = (value: unknown): value is JsonContainer => typeof value === \"object\" && value !== null;\n\n/** Owns and freezes immutable JSON revisions while reusing already-owned subtrees. */\nexport class JsonRevisionStore {\n\treadonly #owned = new WeakSet<object>();\n\n\timport<T extends object>(value: T): T {\n\t\treturn this.#clone(value, new Set<object>()) as T;\n\t}\n\n\tcommit<T extends object>(value: T, transactionOwned: WeakSet<object>): T {\n\t\treturn this.#finish(value as JsonContainer, transactionOwned, new Set<object>(), new WeakSet<object>()) as T;\n\t}\n\n\tadopt<T extends JsonValue>(value: T): T {\n\t\treturn this.#adopt(value, new Set<object>(), new WeakSet<object>()) as T;\n\t}\n\n\t#clone(value: unknown, ancestors: Set<object>): JsonValue {\n\t\tif (!isContainer(value)) return assertPrimitive(value);\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tconst result = new Array<JsonValue>(value.length);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tObject.defineProperty(result, index, {\n\t\t\t\t\t\tvalue: this.#clone(value[index], ancestors),\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthis.#owned.add(result);\n\t\t\t\treturn Object.freeze(result) as unknown as JsonValue;\n\t\t\t}\n\t\t\tassertPlainObject(value);\n\t\t\tconst result = Object.create(Object.getPrototypeOf(value)) as Record<string, JsonValue>;\n\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(result, key, {\n\t\t\t\t\tvalue: this.#clone(descriptor.value, ancestors),\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.#owned.add(result);\n\t\t\treturn Object.freeze(result) as unknown as JsonValue;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\n\t#adopt(value: JsonValue, ancestors: Set<object>, finished: WeakSet<object>): JsonValue {\n\t\tif (!isContainer(value) || this.#owned.has(value)) return isContainer(value) ? value : assertPrimitive(value);\n\t\tif (finished.has(value)) return value;\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tconst child = this.#adopt(value[index]!, ancestors, finished);\n\t\t\t\t\tif (child !== value[index]) defineValue(value, String(index), child as JsonContainer);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertPlainObject(value);\n\t\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t\t}\n\t\t\t\t\tconst child = this.#adopt(descriptor.value as JsonValue, ancestors, finished);\n\t\t\t\t\tif (child !== descriptor.value && isContainer(child)) defineValue(value, key, child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinished.add(value);\n\t\t\tthis.#owned.add(value);\n\t\t\treturn Object.freeze(value) as unknown as JsonValue;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\n\t#finish(\n\t\tvalue: JsonContainer,\n\t\ttransactionOwned: WeakSet<object>,\n\t\tancestors: Set<object>,\n\t\tplacements: WeakSet<object>,\n\t): JsonContainer {\n\t\tif (ancestors.has(value)) throw new TypeError(\"Replicated state cannot contain cycles\");\n\t\tif (placements.has(value)) return this.#clone(value, new Set<object>()) as JsonContainer;\n\t\tplacements.add(value);\n\t\tif (this.#owned.has(value)) return value;\n\t\tif (!transactionOwned.has(value)) return this.#clone(value, ancestors) as JsonContainer;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tassertDenseArray(value);\n\t\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\t\tconst child = value[index];\n\t\t\t\t\tif (!isContainer(child)) {\n\t\t\t\t\t\tassertPrimitive(child);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst next = this.#finish(child, transactionOwned, ancestors, placements);\n\t\t\t\t\tif (next !== child) defineValue(value, String(index), next);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertPlainObject(value);\n\t\t\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Replicated state cannot contain symbol properties\");\n\t\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\t\tthrow new TypeError(\"Replicated state objects must contain enumerable data properties\");\n\t\t\t\t\t}\n\t\t\t\t\tif (!isContainer(descriptor.value)) {\n\t\t\t\t\t\tassertPrimitive(descriptor.value);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst next = this.#finish(descriptor.value, transactionOwned, ancestors, placements);\n\t\t\t\t\tif (next !== descriptor.value) defineValue(value, key, next);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.#owned.add(value);\n\t\t\treturn Object.freeze(value) as unknown as JsonContainer;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n}\n\nfunction defineValue(target: object, key: string, value: JsonContainer): void {\n\tObject.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });\n}\n\nfunction assertPrimitive(value: unknown): null | boolean | number | string {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\" && Number.isFinite(value)) return value;\n\tthrow new TypeError(\"Replicated state values must be strict JSON\");\n}\n\nfunction assertPlainObject(value: object): void {\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\tthrow new TypeError(\"Replicated state containers must be plain objects or arrays\");\n\t}\n}\n\nfunction assertDenseArray(value: readonly unknown[]): void {\n\tconst keys = Reflect.ownKeys(value);\n\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) {\n\t\tthrow new TypeError(\"Replicated state arrays must be dense and contain only indexed entries\");\n\t}\n\tfor (let index = 0; index < value.length; index++) {\n\t\tif (!Object.hasOwn(value, index) || value[index] === undefined) {\n\t\t\tthrow new TypeError(\"Replicated state arrays cannot contain holes or undefined entries\");\n\t\t}\n\t}\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Op } from "./delta/index.ts";
|
|
2
2
|
import type { RemoteServiceProvider } from "./services/provider.ts";
|
|
3
|
+
import type { Draft } from "./state/draft.ts";
|
|
3
4
|
export type { RemoteServiceError } from "./services/errors.ts";
|
|
4
5
|
export type { RemoteServiceProvider } from "./services/provider.ts";
|
|
5
6
|
/** Typed identity for one value carried by a {@link Context}. */
|
|
@@ -34,10 +35,13 @@ export interface ReplicatedState<T> {
|
|
|
34
35
|
}
|
|
35
36
|
export interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {
|
|
36
37
|
readonly value: T;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.
|
|
40
|
+
* Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.
|
|
41
|
+
*/
|
|
42
|
+
change(context: Context, mutate: (draft: Draft<T>) => void): void;
|
|
43
|
+
/** Atomically replace the complete value with a detached immutable JSON snapshot. */
|
|
44
|
+
replace(context: Context, value: T): void;
|
|
41
45
|
}
|
|
42
46
|
declare const SERVICE_TYPE: unique symbol;
|
|
43
47
|
export type ServiceMode = "singleton" | "keyed";
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,iEAAiE;AACjE,MAAM,WAAW,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MA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C;IACvE,IAAI,CAAC,OAAO,EAAE;QACb,QAAQ,CAAC,QAAQ,EAAE,SAAS;YAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QACtD,YAAY,IAAI,IAAI,CAAC;QACrB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;KAC5B,GAAG,cAAc,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,oGAAoG;IACpG,MAAM,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9B","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/** Mutable tracked state. All writes must go through this proxy. */\n\treadonly state: T;\n\t/** Publish the changes made through {@link state} since the previous publication. */\n\tpublish(context: Context): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,iEAAiE;AACjE,MAAM,WAAW,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;CACrC;AAED,+EAA+E;AAC/E,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9C,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC5C,QAAQ,IAAI,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE/C,iGAAiG;AACjG,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,KAAK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C,oGAAoG;IACpG,MAAM,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9B","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\nimport type { Draft } from \"./state/draft.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/**\n\t * Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.\n\t * Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.\n\t */\n\tchange(context: Context, mutate: (draft: Draft<T>) => void): void;\n\t/** Atomically replace the complete value with a detached immutable JSON snapshot. */\n\treplace(context: Context, value: T): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/** Mutable tracked state. All writes must go through this proxy. */\n\treadonly state: T;\n\t/** Publish the changes made through {@link state} since the previous publication. */\n\tpublish(context: Context): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\nimport type { Draft } from \"./state/draft.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/**\n\t * Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.\n\t * Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.\n\t */\n\tchange(context: Context, mutate: (draft: Draft<T>) => void): void;\n\t/** Atomically replace the complete value with a detached immutable JSON snapshot. */\n\treplace(context: Context, value: T): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
|
package/package.json
CHANGED
package/src/delta/README.md
CHANGED
|
@@ -4,8 +4,8 @@ Chord Delta synchronizes JSON values from an authoritative producer to an
|
|
|
4
4
|
ordered replica. It is available from `@earendil-works/chord/delta`.
|
|
5
5
|
|
|
6
6
|
A change is represented by an `Op`: a JSON tuple for replacing, setting,
|
|
7
|
-
deleting, updating a string, or
|
|
8
|
-
replicas use `apply()` or `applyImmutable()`.
|
|
7
|
+
deleting, updating a string, splicing an array, or permuting an array. Producers
|
|
8
|
+
use `track()`; replicas use `apply()` or `applyImmutable()`.
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
11
|
import { apply, track } from "@earendil-works/chord/delta";
|
|
@@ -26,8 +26,9 @@ produce a redundant batch.
|
|
|
26
26
|
|
|
27
27
|
`applyImmutable()` copies only containers along changed paths and shares
|
|
28
28
|
unchanged subtrees. It does not mutate, clone, or freeze either complete input.
|
|
29
|
-
Chord's replicated-state producers
|
|
30
|
-
|
|
29
|
+
Chord's replicated-state producers use a separate transaction-scoped
|
|
30
|
+
copy-on-write draft and derive these operation batches from immutable revisions;
|
|
31
|
+
consumers still observe complete immutable values.
|
|
31
32
|
|
|
32
33
|
## Sending or storing changes
|
|
33
34
|
|
|
@@ -87,9 +88,10 @@ A path is an array of object keys and array indices:
|
|
|
87
88
|
| `["a", path, text]` | Append to a string. |
|
|
88
89
|
| `["t", path, count]` | Remove UTF-16 code units from a string's front. |
|
|
89
90
|
| `["p", path, index, remove, items]` | Splice an array. |
|
|
91
|
+
| `["m", path, permutation]` | Reorder an array so `new[i] = old[permutation[i]]`. |
|
|
90
92
|
|
|
91
93
|
Except for `r`, every decoded operation carries its complete path. `s`, `d`,
|
|
92
|
-
`a`, and `t` cannot address the root. `p` may address a root array.
|
|
94
|
+
`a`, and `t` cannot address the root. `p` and `m` may address a root array.
|
|
93
95
|
|
|
94
96
|
### Encoded `WireOp`
|
|
95
97
|
|
|
@@ -110,6 +112,8 @@ A `PathRef` is either an inline path or a non-negative numeric path ID.
|
|
|
110
112
|
| `["t", count]` | Front-truncate using the previous path. |
|
|
111
113
|
| `["p", pathRef, index, remove, items]` | Splice with an inline or interned path. |
|
|
112
114
|
| `["p", index, remove, items]` | Splice using the previous path. |
|
|
115
|
+
| `["m", pathRef, permutation]` | Reorder with an inline or interned path. |
|
|
116
|
+
| `["m", permutation]` | Reorder using the previous path. |
|
|
113
117
|
|
|
114
118
|
For example, adjacent decoded operations on one path:
|
|
115
119
|
|