@roc-db/in-memory 0.2.0-pre.2 → 0.2.0-pre.21
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 +47 -25
- package/dist/types/createInMemoryAdapter.d.ts +1 -1
- package/dist/types/functions/batchReadEntities.d.ts +2 -0
- package/dist/types/functions/begin.d.ts +1 -1
- package/dist/types/functions/index.d.ts +1 -0
- package/dist/types/functions/pageMutations.d.ts +2 -1
- package/package.json +7 -14
- package/dist/roc-db-in-memory-0.2.0-pre.2.tgz +0 -0
package/dist/index.js
CHANGED
|
@@ -25,18 +25,36 @@ __export(exports_functions, {
|
|
|
25
25
|
findDebounceMutation: () => findDebounceMutation,
|
|
26
26
|
deleteEntity: () => deleteEntity,
|
|
27
27
|
createEntity: () => createEntity,
|
|
28
|
-
begin: () => begin
|
|
28
|
+
begin: () => begin,
|
|
29
|
+
batchReadEntities: () => batchReadEntities
|
|
29
30
|
});
|
|
30
31
|
|
|
32
|
+
// src/functions/readEntity.ts
|
|
33
|
+
import { DELETED_IN_CHANGE_SET_SYMBOL } from "roc-db";
|
|
34
|
+
var readEntity = (txn, ref) => {
|
|
35
|
+
if (txn.request.changeSetRef) {
|
|
36
|
+
const doc = txn.engineOpts.changeSet.entities.get(ref);
|
|
37
|
+
if (doc === DELETED_IN_CHANGE_SET_SYMBOL)
|
|
38
|
+
return;
|
|
39
|
+
if (doc)
|
|
40
|
+
return doc;
|
|
41
|
+
}
|
|
42
|
+
return txn.engineOpts.entities.get(ref);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/functions/batchReadEntities.ts
|
|
46
|
+
var batchReadEntities = (txn, refs) => {
|
|
47
|
+
return refs.map((ref) => readEntity(txn, ref));
|
|
48
|
+
};
|
|
31
49
|
// src/functions/begin.ts
|
|
32
|
-
var begin = (request, engineOpts) => {
|
|
33
|
-
return {
|
|
50
|
+
var begin = (request, engineOpts, callback) => {
|
|
51
|
+
return callback({
|
|
34
52
|
...engineOpts,
|
|
35
53
|
changeSet: request.changeSetRef ? {
|
|
36
54
|
entities: new Map([]),
|
|
37
55
|
mutations: new Map([])
|
|
38
56
|
} : null
|
|
39
|
-
};
|
|
57
|
+
});
|
|
40
58
|
};
|
|
41
59
|
// src/functions/createEntity.ts
|
|
42
60
|
import { entityFromRef } from "roc-db";
|
|
@@ -80,10 +98,10 @@ var createEntity = (txn, ref, {
|
|
|
80
98
|
}
|
|
81
99
|
};
|
|
82
100
|
// src/functions/deleteEntity.ts
|
|
83
|
-
import { DELETED_IN_CHANGE_SET_SYMBOL } from "roc-db";
|
|
101
|
+
import { DELETED_IN_CHANGE_SET_SYMBOL as DELETED_IN_CHANGE_SET_SYMBOL2 } from "roc-db";
|
|
84
102
|
var deleteEntity = (txn, ref) => {
|
|
85
103
|
if (txn.request.changeSetRef) {
|
|
86
|
-
txn.engineOpts.changeSet.entities.set(ref,
|
|
104
|
+
txn.engineOpts.changeSet.entities.set(ref, DELETED_IN_CHANGE_SET_SYMBOL2);
|
|
87
105
|
return true;
|
|
88
106
|
} else {
|
|
89
107
|
txn.engineOpts.entities.delete(ref);
|
|
@@ -115,26 +133,28 @@ var findDebounceMutation = (request, engine, now) => {
|
|
|
115
133
|
return res;
|
|
116
134
|
};
|
|
117
135
|
// src/functions/pageMutations.ts
|
|
118
|
-
var pageMutations = (txn, {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
var pageMutations = (txn, {
|
|
137
|
+
size = 30,
|
|
138
|
+
skip = 0,
|
|
139
|
+
changeSetRef
|
|
140
|
+
} = {}) => {
|
|
141
|
+
const res = [];
|
|
142
|
+
const iterator = txn.engineOpts.mutations.values().drop(skip);
|
|
143
|
+
let next = iterator.next();
|
|
144
|
+
while (!next.done && res.length < size) {
|
|
145
|
+
if (changeSetRef) {
|
|
146
|
+
if (next.value.changeSetRef === changeSetRef) {
|
|
147
|
+
res.push(next.value);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
res.push(next.value);
|
|
151
|
+
}
|
|
152
|
+
next = iterator.next();
|
|
133
153
|
}
|
|
134
|
-
return
|
|
154
|
+
return res;
|
|
135
155
|
};
|
|
136
|
-
|
|
137
156
|
// src/functions/patchEntity.ts
|
|
157
|
+
import { deepPatch, NotFoundError } from "roc-db";
|
|
138
158
|
var patchEntity = (txn, ref, { data = {}, children = {}, parents = {}, ancestors = {} }) => {
|
|
139
159
|
const existingDocument = readEntity(txn, ref);
|
|
140
160
|
if (!existingDocument)
|
|
@@ -195,14 +215,16 @@ var updateEntity = (txn, ref, { data = {}, children = {}, parents = {}, ancestor
|
|
|
195
215
|
var createInMemoryAdapter = ({
|
|
196
216
|
operations,
|
|
197
217
|
entities,
|
|
198
|
-
snowflake = new Snowflake(1, 1)
|
|
218
|
+
snowflake = new Snowflake(1, 1),
|
|
219
|
+
session
|
|
199
220
|
}) => {
|
|
200
221
|
return createAdapter({
|
|
201
222
|
name: "in-memory",
|
|
202
223
|
operations,
|
|
203
224
|
entities,
|
|
204
225
|
functions: exports_functions,
|
|
205
|
-
snowflake
|
|
226
|
+
snowflake,
|
|
227
|
+
session
|
|
206
228
|
}, {
|
|
207
229
|
entities: new Map,
|
|
208
230
|
mutations: new Map
|
|
@@ -3,7 +3,7 @@ import type { z } from "zod";
|
|
|
3
3
|
type Entity = z.ZodObject<{
|
|
4
4
|
entity: z.ZodLiteral<string>;
|
|
5
5
|
}>;
|
|
6
|
-
export declare const createInMemoryAdapter: <const Name extends string, const Operations extends readonly Operation[], const Entities extends readonly Entity[]>({ operations, entities, snowflake, }: {
|
|
6
|
+
export declare const createInMemoryAdapter: <const Name extends string, const Operations extends readonly Operation[], const Entities extends readonly Entity[]>({ operations, entities, snowflake, session, }: {
|
|
7
7
|
operations: Operations;
|
|
8
8
|
entities: Entities;
|
|
9
9
|
snowflake?: Snowflake;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const begin: (request: any, engineOpts: any) => any;
|
|
1
|
+
export declare const begin: (request: any, engineOpts: any, callback: any) => any;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReadTransaction } from "roc-db";
|
|
2
2
|
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
-
export declare const pageMutations: (txn: ReadTransaction<any, InMemoryEngine, any, any>, { size, skip }?: {
|
|
3
|
+
export declare const pageMutations: (txn: ReadTransaction<any, InMemoryEngine, any, any>, { size, skip, changeSetRef, }?: {
|
|
4
4
|
size?: number;
|
|
5
5
|
skip?: number;
|
|
6
|
+
changeSetRef?: string;
|
|
6
7
|
}) => import("roc-db").Mutation[];
|
package/package.json
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/in-memory",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts"
|
|
9
|
+
}
|
|
7
10
|
},
|
|
8
11
|
"files": [
|
|
9
12
|
"dist"
|
|
10
13
|
],
|
|
11
14
|
"sideEffects": false,
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "NODE_ENV=production bun run scripts/build.ts",
|
|
14
|
-
"build:types": "rm -rf dist/types && bun run tsc --noCheck",
|
|
15
|
-
"test": "bun test"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@roc-db/test-utils": "0.2.0-pre.2",
|
|
19
|
-
"roc-db": "0.2.0-pre.2",
|
|
20
|
-
"zod": "3.24.2"
|
|
21
|
-
},
|
|
22
15
|
"peerDependencies": {
|
|
23
|
-
"roc-db": "0.2.0-pre.
|
|
24
|
-
"zod": "3.
|
|
16
|
+
"roc-db": "0.2.0-pre.21",
|
|
17
|
+
"zod": "^3.0.0"
|
|
25
18
|
},
|
|
26
19
|
"keywords": [],
|
|
27
20
|
"author": "Eigil Sagafos",
|
|
Binary file
|