MCPcopy Create free account
hub / github.com/hashintel/hash / createProto

Function createProto

libs/@local/harpc/client/typescript/src/utils.ts:5–42  ·  view source on GitHub ↗
(
  proto: T,
  readableProperties: ReadableProperties,
  writeableProperties?: WriteableProperties,
)

Source from the content-addressed store, hash-verified

3import type { MutableBuffer } from "./binary/index.js";
4
5export const createProto = <
6 T extends object,
7 ReadableProperties extends Readonly<Record<string, unknown>>,
8 WriteableProperties extends Readonly<Record<string, unknown>>,
9>(
10 proto: T,
11 readableProperties: ReadableProperties,
12 writeableProperties?: WriteableProperties,
13): T & Readonly<ReadableProperties> & WriteableProperties => {
14 const readablePropertyDescriptors = Record.map(
15 readableProperties,
16 (value): PropertyDescriptor => ({
17 enumerable: true,
18 configurable: false,
19 writable: false,
20 value,
21 }),
22 );
23
24 const writeablePropertyDescriptors = Record.map(
25 writeableProperties ?? {},
26 (value): PropertyDescriptor => ({
27 enumerable: true,
28 configurable: false,
29 writable: true,
30 value,
31 }),
32 );
33
34 return Object.create(
35 proto,
36 Record.union(
37 readablePropertyDescriptors,
38 writeablePropertyDescriptors,
39 Function.untupled(Tuple.getFirst),
40 ),
41 ) as T & Readonly<ReadableProperties> & WriteableProperties;
42};
43
44/**
45 * This is more strictly typed than necessary, but this allows us to give better type hints.

Callers 15

makeFunction · 0.85
okFunction · 0.85
errFunction · 0.85
makeUncheckedFunction · 0.85
makeFunction · 0.85
makeUncheckedFunction · 0.85
makeFunction · 0.85
makeUncheckedFunction · 0.85
makeFunction · 0.85
makeFunction · 0.85
makeUncheckedFunction · 0.85

Calls 3

mapMethod · 0.45
createMethod · 0.45
unionMethod · 0.45

Tested by

no test coverage detected