MCPcopy
hub / github.com/tinyplex/tinybase / getMockedCustom

Function getMockedCustom

test/unit/persisters/common/mocks.ts:136–177  ·  view source on GitHub ↗
(
  write: (location: string, rawContent: any) => Promise<void>,
  supportsMergeableStore = false,
  isSynchronizer: 0 | 1 = 0,
)

Source from the content-addressed store, hash-verified

134let customPersisterChanges: Changes | MergeableChanges = [{}, {}, 1];
135
136const getMockedCustom = (
137 write: (location: string, rawContent: any) => Promise<void>,
138 supportsMergeableStore = false,
139 isSynchronizer: 0 | 1 = 0,
140): Persistable => ({
141 autoLoadPause: 100,
142 getLocation: async (): Promise<string> => '',
143 getLocationMethod: ['getFoo', () => 'foo'],
144 getPersister: (store: Store) => {
145 customPersister = '';
146 return createCustomPersister(
147 store,
148 async () => jsonParseWithUndefined(customPersister),
149 async (getContent, changes) => {
150 customPersister = jsonStringWithUndefined(getContent());
151 customPersisterChanges = changes ?? [{}, {}, 1];
152 },
153 (listener) => {
154 customPersisterListener = listener;
155 return 1;
156 },
157 () => (customPersisterListener = undefined),
158 undefined,
159 supportsMergeableStore ? 3 : 1,
160 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
161 // @ts-ignore
162 {getFoo: () => 'foo'},
163 isSynchronizer,
164 );
165 },
166 get: async (): Promise<Content | void> =>
167 jsonParseWithUndefined(customPersister),
168 set: (location: string, content: Content | MergeableContent): Promise<void> =>
169 write(location, jsonStringWithUndefined(content)),
170 write,
171 del: async (): Promise<void> => {
172 customPersister = '';
173 },
174 getChanges: () => customPersisterChanges,
175 testMissing: true,
176 testAutoLoad: true,
177});
178
179const getMockedStorage = (
180 storage: Storage,

Callers 1

mocks.tsFile · 0.85

Calls 4

createCustomPersisterFunction · 0.90
jsonParseWithUndefinedFunction · 0.70
jsonStringWithUndefinedFunction · 0.70
getContentFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…