@roc-db/in-memory 0.2.0-pre.10 → 0.2.0-pre.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +168 -148
- package/dist/types/createInMemoryAdapter.d.ts +10 -7
- package/dist/types/functions/batchReadEntities.d.ts +3 -0
- package/dist/types/functions/commit.d.ts +3 -0
- package/dist/types/functions/findRecentMutations.d.ts +3 -0
- package/dist/types/functions/getChangeSetMutations.d.ts +3 -1
- package/dist/types/functions/index.d.ts +6 -6
- package/dist/types/functions/pageEntities.d.ts +3 -0
- package/dist/types/functions/pageEntitiesByIndex.d.ts +3 -0
- package/dist/types/functions/pageMutations.d.ts +2 -6
- package/dist/types/functions/readEntity.d.ts +3 -1
- package/dist/types/functions/readMutation.d.ts +3 -1
- package/dist/types/functions/refByUniqueField.d.ts +3 -0
- package/dist/types/functions/saveMutation.d.ts +3 -2
- package/dist/types/types/InMemoryEngine.d.ts +4 -2
- package/package.json +8 -4
- package/dist/types/functions/begin.d.ts +0 -1
- package/dist/types/functions/createEntity.d.ts +0 -24
- package/dist/types/functions/deleteEntity.d.ts +0 -1
- package/dist/types/functions/findDebounceMutation.d.ts +0 -3
- package/dist/types/functions/patchEntity.d.ts +0 -6
- package/dist/types/functions/updateEntity.d.ts +0 -6
- package/dist/types/types/InMemoryWriteTransaction.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -10,86 +10,148 @@ var __export = (target, all) => {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// src/createInMemoryAdapter.ts
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
createAdapter,
|
|
15
|
+
Snowflake
|
|
16
|
+
} from "roc-db";
|
|
14
17
|
|
|
15
18
|
// src/functions/index.ts
|
|
16
19
|
var exports_functions = {};
|
|
17
20
|
__export(exports_functions, {
|
|
18
|
-
updateEntity: () => updateEntity,
|
|
19
21
|
saveMutation: () => saveMutation,
|
|
22
|
+
refByUniqueField: () => refByUniqueField,
|
|
20
23
|
readMutation: () => readMutation,
|
|
21
24
|
readEntity: () => readEntity,
|
|
22
|
-
patchEntity: () => patchEntity,
|
|
23
25
|
pageMutations: () => pageMutations,
|
|
26
|
+
pageEntitiesByIndex: () => pageEntitiesByIndex,
|
|
27
|
+
pageEntities: () => pageEntities,
|
|
24
28
|
getChangeSetMutations: () => getChangeSetMutations,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
begin: () => begin
|
|
29
|
+
findRecentMutations: () => findRecentMutations,
|
|
30
|
+
commit: () => commit,
|
|
31
|
+
batchReadEntities: () => batchReadEntities
|
|
29
32
|
});
|
|
30
33
|
|
|
31
|
-
// src/functions/
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
mutations: new Map([])
|
|
38
|
-
} : null
|
|
39
|
-
});
|
|
34
|
+
// src/functions/readEntity.ts
|
|
35
|
+
var readEntity = (txn, ref) => txn.engineOpts.entities.get(ref);
|
|
36
|
+
|
|
37
|
+
// src/functions/batchReadEntities.ts
|
|
38
|
+
var batchReadEntities = (txn, refs) => {
|
|
39
|
+
return refs.map((ref) => readEntity(txn, ref));
|
|
40
40
|
};
|
|
41
|
-
// src/functions/
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
children,
|
|
67
|
-
parents,
|
|
68
|
-
ancestors
|
|
69
|
-
};
|
|
70
|
-
if (txn.request.changeSetRef) {
|
|
71
|
-
if (txn.engineOpts.changeSet.entities.has(ref)) {
|
|
72
|
-
throw new Error("Entity already exists in changeSet");
|
|
41
|
+
// src/functions/commit.ts
|
|
42
|
+
import {
|
|
43
|
+
createUniqueConstraintConflictError
|
|
44
|
+
} from "roc-db";
|
|
45
|
+
|
|
46
|
+
// src/functions/saveMutation.ts
|
|
47
|
+
var saveMutation = (txn, finalizedMutation) => {
|
|
48
|
+
txn.engineOpts.mutations.set(finalizedMutation.ref, finalizedMutation);
|
|
49
|
+
return finalizedMutation;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/functions/commit.ts
|
|
53
|
+
var findAddedAndRemovedEntries = (oldArr, newArr) => {
|
|
54
|
+
const removed = newArr?.filter(([k1, v1]) => !oldArr.some(([k2, v2]) => k1 === k2 && v1 === v2));
|
|
55
|
+
const added = oldArr?.filter(([k1, v1]) => !newArr.some(([k2, v2]) => k1 === k2 && v1 === v2));
|
|
56
|
+
return [added, removed];
|
|
57
|
+
};
|
|
58
|
+
var commit = (txn, mutation, { created, updated, deleted }) => {
|
|
59
|
+
const { mutations } = txn.engineOpts;
|
|
60
|
+
const currentMutation = mutations.get(txn.mutation.ref);
|
|
61
|
+
if (currentMutation) {
|
|
62
|
+
if (currentMutation && mutation.appliedAt === txn.timestamp) {
|
|
63
|
+
saveMutation(txn, mutation);
|
|
64
|
+
} else if (currentMutation && mutation.debounceCount > currentMutation.debounceCount) {
|
|
65
|
+
saveMutation(txn, mutation);
|
|
73
66
|
} else {
|
|
74
|
-
|
|
75
|
-
return document;
|
|
67
|
+
throw new Error("Mutation already exists");
|
|
76
68
|
}
|
|
77
69
|
} else {
|
|
78
|
-
txn
|
|
79
|
-
return document;
|
|
70
|
+
saveMutation(txn, mutation);
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
if (txn.request.changeSetRef)
|
|
73
|
+
return mutation;
|
|
74
|
+
for (const doc of created) {
|
|
75
|
+
if (txn.adapter.models?.[doc.entity]?.singleton && txn.engineOpts.entities.has(doc.ref)) {
|
|
76
|
+
throw createUniqueConstraintConflictError(doc.entity);
|
|
77
|
+
}
|
|
78
|
+
if (doc.__.unique?.length) {
|
|
79
|
+
doc.__.unique.forEach(([key, value]) => {
|
|
80
|
+
const uniqueKey = `${doc.entity}:${key}:${JSON.stringify(value)}`;
|
|
81
|
+
if (txn.engineOpts.entitiesUnique.has(uniqueKey))
|
|
82
|
+
throw createUniqueConstraintConflictError(doc.entity);
|
|
83
|
+
txn.engineOpts.entitiesUnique.set(uniqueKey, doc.ref);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (doc.__.index?.length) {
|
|
87
|
+
doc.__.index.forEach(([key, value]) => {
|
|
88
|
+
const indexKey = `${doc.entity}:${key}:${JSON.stringify(value)}`;
|
|
89
|
+
const arr = txn.engineOpts.entitiesIndex.get(indexKey) ?? [];
|
|
90
|
+
txn.engineOpts.entitiesIndex.set(indexKey, [...arr, doc.ref]);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
txn.engineOpts.entities.set(doc.ref, doc);
|
|
94
|
+
}
|
|
95
|
+
for (const updatedDocument of updated) {
|
|
96
|
+
const existingDocument = txn.engineOpts.entities.get(updatedDocument.ref);
|
|
97
|
+
if (updatedDocument.__.unique?.length || existingDocument.__.unique?.length) {
|
|
98
|
+
const { ref, entity } = updatedDocument;
|
|
99
|
+
const [added, removed] = findAddedAndRemovedEntries(updatedDocument.__.unique, existingDocument.__.unique);
|
|
100
|
+
removed.forEach(([key, value]) => {
|
|
101
|
+
const uniqueKey = `${updatedDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
102
|
+
txn.engineOpts.entitiesUnique.delete(uniqueKey);
|
|
103
|
+
});
|
|
104
|
+
added.forEach(([key, value]) => {
|
|
105
|
+
const uniqueKey = `${updatedDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
106
|
+
if (txn.engineOpts.entitiesUnique.has(uniqueKey))
|
|
107
|
+
throw createUniqueConstraintConflictError(entity);
|
|
108
|
+
txn.engineOpts.entitiesUnique.set(uniqueKey, ref);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (updatedDocument.__.index?.length || existingDocument.__.index?.length) {
|
|
112
|
+
const { ref, entity } = updatedDocument;
|
|
113
|
+
const [added, removed] = findAddedAndRemovedEntries(updatedDocument.__.index, existingDocument.__.index);
|
|
114
|
+
removed.forEach(([key, value]) => {
|
|
115
|
+
const indexKey = `${updatedDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
116
|
+
const arr = txn.engineOpts.entitiesIndex.get(indexKey);
|
|
117
|
+
txn.engineOpts.entitiesIndex.set(indexKey, arr.filter((ref2) => ref2 !== updatedDocument.ref));
|
|
118
|
+
});
|
|
119
|
+
added.forEach(([key, value]) => {
|
|
120
|
+
const indexKey = `${updatedDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
121
|
+
const arr = txn.engineOpts.entitiesIndex.get(indexKey) ?? [];
|
|
122
|
+
txn.engineOpts.entitiesIndex.set(indexKey, [
|
|
123
|
+
...arr,
|
|
124
|
+
updatedDocument.ref
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
txn.engineOpts.entities.set(updatedDocument.ref, updatedDocument);
|
|
129
|
+
}
|
|
130
|
+
for (const ref of deleted) {
|
|
131
|
+
if (ref.startsWith("Mutation/")) {
|
|
132
|
+
txn.engineOpts.mutations.delete(ref);
|
|
133
|
+
} else {
|
|
134
|
+
const existingDocument = txn.engineOpts.entities.get(ref);
|
|
135
|
+
if (existingDocument.__.unique?.length) {
|
|
136
|
+
existingDocument.__.unique.forEach(([key, value]) => {
|
|
137
|
+
const uniqueKey = `${existingDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
138
|
+
txn.engineOpts.entitiesUnique.delete(uniqueKey);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (existingDocument.__.index?.length) {
|
|
142
|
+
existingDocument.__.index.forEach(([key, value]) => {
|
|
143
|
+
const indexKey = `${existingDocument.entity}:${key}:${JSON.stringify(value)}`;
|
|
144
|
+
const arr = txn.engineOpts.entitiesIndex.get(indexKey) ?? [];
|
|
145
|
+
txn.engineOpts.entitiesIndex.set(indexKey, arr.filter((ref2) => ref2 !== existingDocument.ref));
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
txn.engineOpts.entities.delete(ref);
|
|
149
|
+
}
|
|
91
150
|
}
|
|
151
|
+
return mutation;
|
|
92
152
|
};
|
|
153
|
+
// src/functions/findRecentMutations.ts
|
|
154
|
+
var findRecentMutations = (engine, { changeSetRef, identityRef, since }) => engine.mutations.values().filter((mutation) => (mutation.timestamp > since || !!mutation.persistedAt && mutation.persistedAt > since) && ((mutation.changeSetRef ?? null) === changeSetRef || mutation.identityRef === identityRef)).toArray();
|
|
93
155
|
// src/functions/getChangeSetMutations.ts
|
|
94
156
|
var getChangeSetMutations = (txn, changeSetRef) => {
|
|
95
157
|
if (!changeSetRef)
|
|
@@ -102,24 +164,36 @@ var getChangeSetMutations = (txn, changeSetRef) => {
|
|
|
102
164
|
});
|
|
103
165
|
return res;
|
|
104
166
|
};
|
|
105
|
-
// src/functions/
|
|
106
|
-
var
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return true;
|
|
167
|
+
// src/functions/pageEntities.ts
|
|
168
|
+
var pageEntities = (txn, args) => {
|
|
169
|
+
const { size, entities, childrenOf } = args;
|
|
170
|
+
const result = [];
|
|
171
|
+
for (const [, doc] of txn.engineOpts.entities) {
|
|
172
|
+
if (size && result.length >= size) {
|
|
173
|
+
break;
|
|
113
174
|
}
|
|
114
|
-
|
|
115
|
-
|
|
175
|
+
if (entities && entities !== "*" && !entities.includes(doc.entity)) {
|
|
176
|
+
continue;
|
|
177
|
+
} else {
|
|
178
|
+
if (childrenOf && childrenOf.length > 0) {
|
|
179
|
+
if (!childrenOf.some((childRef) => doc.__?.parentRefs?.includes(childRef))) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
result.push(doc);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
};
|
|
188
|
+
// src/functions/pageEntitiesByIndex.ts
|
|
189
|
+
var pageEntitiesByIndex = (txn, entity, field, value) => {
|
|
190
|
+
const { entitiesIndex } = txn.engineOpts;
|
|
191
|
+
const indexKey = `${entity}:${field}:${JSON.stringify(value)}`;
|
|
192
|
+
const refs = entitiesIndex.get(indexKey) ?? [];
|
|
193
|
+
return refs.map((ref) => txn.engineOpts.entities.get(ref));
|
|
116
194
|
};
|
|
117
195
|
// src/functions/pageMutations.ts
|
|
118
|
-
var pageMutations = (txn, {
|
|
119
|
-
size = 30,
|
|
120
|
-
skip = 0,
|
|
121
|
-
changeSetRef
|
|
122
|
-
} = {}) => {
|
|
196
|
+
var pageMutations = (txn, { size = 30, skip = 0, changeSetRef } = {}) => {
|
|
123
197
|
const res = [];
|
|
124
198
|
const iterator = txn.engineOpts.mutations.values().drop(skip);
|
|
125
199
|
let next = iterator.next();
|
|
@@ -135,94 +209,40 @@ var pageMutations = (txn, {
|
|
|
135
209
|
}
|
|
136
210
|
return res;
|
|
137
211
|
};
|
|
138
|
-
// src/functions/patchEntity.ts
|
|
139
|
-
import { deepPatch, NotFoundError } from "roc-db";
|
|
140
|
-
|
|
141
|
-
// src/functions/readEntity.ts
|
|
142
|
-
import { DELETED_IN_CHANGE_SET_SYMBOL as DELETED_IN_CHANGE_SET_SYMBOL2 } from "roc-db";
|
|
143
|
-
var readEntity = (txn, ref) => {
|
|
144
|
-
if (txn.request.changeSetRef) {
|
|
145
|
-
const doc = txn.engineOpts.changeSet.entities.get(ref);
|
|
146
|
-
if (doc === DELETED_IN_CHANGE_SET_SYMBOL2)
|
|
147
|
-
return;
|
|
148
|
-
if (doc)
|
|
149
|
-
return doc;
|
|
150
|
-
}
|
|
151
|
-
return txn.engineOpts.entities.get(ref);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// src/functions/patchEntity.ts
|
|
155
|
-
var patchEntity = (txn, ref, { data = {}, children = {}, parents = {}, ancestors = {} }) => {
|
|
156
|
-
const existingDocument = readEntity(txn, ref);
|
|
157
|
-
if (!existingDocument)
|
|
158
|
-
throw new NotFoundError(ref);
|
|
159
|
-
const updatedDocument = {
|
|
160
|
-
...existingDocument,
|
|
161
|
-
updated: {
|
|
162
|
-
timestamp: txn.mutation.timestamp,
|
|
163
|
-
mutationRef: txn.mutation.ref
|
|
164
|
-
},
|
|
165
|
-
data: deepPatch(existingDocument.data, data),
|
|
166
|
-
children: deepPatch(existingDocument.children, children),
|
|
167
|
-
parents: deepPatch(existingDocument.parents, parents),
|
|
168
|
-
ancestors: deepPatch(existingDocument.ancestors, ancestors)
|
|
169
|
-
};
|
|
170
|
-
if (txn.request.changeSetRef) {
|
|
171
|
-
txn.engineOpts.changeSet.entities.set(ref, updatedDocument);
|
|
172
|
-
return updatedDocument;
|
|
173
|
-
} else {
|
|
174
|
-
txn.engineOpts.entities.set(ref, updatedDocument);
|
|
175
|
-
return updatedDocument;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
212
|
// src/functions/readMutation.ts
|
|
179
213
|
var readMutation = (engineOpts, ref) => {
|
|
180
214
|
return engineOpts.mutations.get(ref);
|
|
181
215
|
};
|
|
182
|
-
// src/functions/
|
|
183
|
-
var
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
import { NotFoundError as NotFoundError2 } from "roc-db";
|
|
189
|
-
var updateEntity = (txn, ref, { data = {}, children = {}, parents = {}, ancestors = {} }) => {
|
|
190
|
-
const currentEntity = readEntity(txn, ref);
|
|
191
|
-
if (!currentEntity)
|
|
192
|
-
throw new NotFoundError2(ref);
|
|
193
|
-
const document = {
|
|
194
|
-
...currentEntity,
|
|
195
|
-
updated: {
|
|
196
|
-
mutationRef: txn.mutation.ref,
|
|
197
|
-
timestamp: txn.mutation.timestamp
|
|
198
|
-
},
|
|
199
|
-
data,
|
|
200
|
-
children,
|
|
201
|
-
parents,
|
|
202
|
-
ancestors
|
|
203
|
-
};
|
|
204
|
-
if (txn.request.changeSetRef) {
|
|
205
|
-
throw new Error("TODO support changeSetRef");
|
|
206
|
-
} else {
|
|
207
|
-
txn.engineOpts.entities.set(ref, document);
|
|
208
|
-
return document;
|
|
216
|
+
// src/functions/refByUniqueField.ts
|
|
217
|
+
var refByUniqueField = (txn, entity, field, fieldIndex, value) => {
|
|
218
|
+
const key = `${entity}:${field}:${JSON.stringify(value)}`;
|
|
219
|
+
const { entitiesUnique } = txn.engineOpts;
|
|
220
|
+
if (entitiesUnique.has(key)) {
|
|
221
|
+
return entitiesUnique.get(key);
|
|
209
222
|
}
|
|
210
223
|
};
|
|
211
224
|
// src/createInMemoryAdapter.ts
|
|
212
225
|
var createInMemoryAdapter = ({
|
|
213
226
|
operations,
|
|
214
227
|
entities,
|
|
215
|
-
snowflake = new Snowflake(1, 1)
|
|
228
|
+
snowflake = new Snowflake(1, 1),
|
|
229
|
+
optimistic = true,
|
|
230
|
+
session,
|
|
231
|
+
engine
|
|
216
232
|
}) => {
|
|
217
233
|
return createAdapter({
|
|
218
234
|
name: "in-memory",
|
|
219
235
|
operations,
|
|
220
236
|
entities,
|
|
221
237
|
functions: exports_functions,
|
|
222
|
-
snowflake
|
|
223
|
-
|
|
238
|
+
snowflake,
|
|
239
|
+
optimistic,
|
|
240
|
+
session
|
|
241
|
+
}, engine ?? {
|
|
224
242
|
entities: new Map,
|
|
225
|
-
mutations: new Map
|
|
243
|
+
mutations: new Map,
|
|
244
|
+
entitiesUnique: new Map,
|
|
245
|
+
entitiesIndex: new Map
|
|
226
246
|
});
|
|
227
247
|
};
|
|
228
248
|
export {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Snowflake, type Adapter, type Operation } from "roc-db";
|
|
2
|
-
|
|
3
|
-
type Entity = z.ZodObject<{
|
|
4
|
-
entity: z.ZodLiteral<string>;
|
|
5
|
-
}>;
|
|
6
|
-
export declare const createInMemoryAdapter: <const Name extends string, const Operations extends readonly Operation[], const Entities extends readonly Entity[]>({ operations, entities, snowflake, }: {
|
|
1
|
+
import { Snowflake, type Adapter, type Entity, type Operation, type Session } from "roc-db";
|
|
2
|
+
export declare const createInMemoryAdapter: <const Name extends string, const Operations extends readonly Operation[], const Entities extends readonly Entity<any>[]>({ operations, entities, snowflake, optimistic, session, engine, }: {
|
|
7
3
|
operations: Operations;
|
|
8
4
|
entities: Entities;
|
|
9
5
|
snowflake?: Snowflake;
|
|
6
|
+
optimistic?: boolean;
|
|
7
|
+
session: Session;
|
|
8
|
+
engine?: {
|
|
9
|
+
entities: Map<string, any>;
|
|
10
|
+
mutations: Map<string, any>;
|
|
11
|
+
entitiesUnique: Map<string, any>;
|
|
12
|
+
entitiesIndex: Map<string, any>;
|
|
13
|
+
};
|
|
10
14
|
}) => Adapter;
|
|
11
|
-
export {};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { GetChangeSetMutationsFunction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const getChangeSetMutations: GetChangeSetMutationsFunction<InMemoryEngine>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { batchReadEntities } from "./batchReadEntities";
|
|
2
|
+
export { commit } from "./commit";
|
|
3
|
+
export { findRecentMutations } from "./findRecentMutations";
|
|
4
4
|
export { getChangeSetMutations } from "./getChangeSetMutations";
|
|
5
|
-
export {
|
|
5
|
+
export { pageEntities } from "./pageEntities";
|
|
6
|
+
export { pageEntitiesByIndex } from "./pageEntitiesByIndex";
|
|
6
7
|
export { pageMutations } from "./pageMutations";
|
|
7
|
-
export { patchEntity } from "./patchEntity";
|
|
8
8
|
export { readEntity } from "./readEntity";
|
|
9
9
|
export { readMutation } from "./readMutation";
|
|
10
|
+
export { refByUniqueField } from "./refByUniqueField";
|
|
10
11
|
export { saveMutation } from "./saveMutation";
|
|
11
|
-
export { updateEntity } from "./updateEntity";
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PageMutationsFunction } from "roc-db";
|
|
2
2
|
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
-
export declare const pageMutations:
|
|
4
|
-
size?: number;
|
|
5
|
-
skip?: number;
|
|
6
|
-
changeSetRef?: string;
|
|
7
|
-
}) => import("roc-db").Mutation[];
|
|
3
|
+
export declare const pageMutations: PageMutationsFunction<InMemoryEngine>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SaveMutationFunction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const saveMutation: SaveMutationFunction<InMemoryEngine>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityDocument, Mutation, Ref } from "roc-db";
|
|
2
2
|
export type InMemoryEngine = {
|
|
3
|
-
entities: Map<Ref,
|
|
3
|
+
entities: Map<Ref, EntityDocument>;
|
|
4
4
|
mutations: Map<Ref, Mutation>;
|
|
5
|
+
entitiesUnique: Map<string, Ref>;
|
|
6
|
+
entitiesIndex: Map<string, Ref[]>;
|
|
5
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/in-memory",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"roc-db": "0.2.0-pre.
|
|
17
|
-
"zod": "
|
|
16
|
+
"roc-db": ">=0.2.0-pre.98 <1.0.0",
|
|
17
|
+
"zod": ">=4.0.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [],
|
|
20
20
|
"author": "Eigil Sagafos",
|
|
@@ -22,5 +22,9 @@
|
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "git+https://github.com/eigilsagafos/roc-db.git"
|
|
24
24
|
},
|
|
25
|
-
"license": "MIT"
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"registry": "https://registry.npmjs.org/"
|
|
29
|
+
}
|
|
26
30
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const begin: (request: any, engineOpts: any, callback: any) => any;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type Ref } from "roc-db";
|
|
2
|
-
import type { InMemoryWriteTransaction } from "../types/InMemoryWriteTransaction";
|
|
3
|
-
export declare const createEntity: (txn: InMemoryWriteTransaction, ref: Ref, { data, indexedData, children, parents, ancestors, }: {
|
|
4
|
-
data?: {} | undefined;
|
|
5
|
-
indexedData?: {} | undefined;
|
|
6
|
-
children?: {} | undefined;
|
|
7
|
-
parents?: {} | undefined;
|
|
8
|
-
ancestors?: {} | undefined;
|
|
9
|
-
}) => {
|
|
10
|
-
ref: `${string}/${string}`;
|
|
11
|
-
entity: string;
|
|
12
|
-
created: {
|
|
13
|
-
timestamp: any;
|
|
14
|
-
mutationRef: any;
|
|
15
|
-
};
|
|
16
|
-
updated: {
|
|
17
|
-
timestamp: any;
|
|
18
|
-
mutationRef: any;
|
|
19
|
-
};
|
|
20
|
-
data: {};
|
|
21
|
-
children: {};
|
|
22
|
-
parents: {};
|
|
23
|
-
ancestors: {};
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const deleteEntity: (txn: any, ref: any) => boolean;
|