@roc-db/in-memory 0.2.0-pre.97 → 0.2.0-pre.99
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 +13 -16
- package/dist/types/createInMemoryAdapter.d.ts +8 -7
- package/dist/types/functions/batchReadEntities.d.ts +3 -2
- package/dist/types/functions/commit.d.ts +3 -6
- package/dist/types/functions/findDebounceMutation.d.ts +2 -2
- package/dist/types/functions/getChangeSetMutations.d.ts +3 -1
- package/dist/types/functions/pageEntities.d.ts +3 -1
- package/dist/types/functions/pageEntitiesByIndex.d.ts +3 -1
- package/dist/types/functions/pageMutations.d.ts +2 -6
- package/dist/types/functions/readEntity.d.ts +3 -2
- package/dist/types/functions/readMutation.d.ts +3 -1
- package/dist/types/functions/refByUniqueField.d.ts +3 -1
- package/dist/types/functions/saveMutation.d.ts +3 -2
- package/dist/types/types/InMemoryEngine.d.ts +4 -2
- package/package.json +7 -3
- package/dist/types/types/InMemoryWriteTransaction.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -55,11 +55,7 @@ var findAddedAndRemovedEntries = (oldArr, newArr) => {
|
|
|
55
55
|
const added = oldArr?.filter(([k1, v1]) => !newArr.some(([k2, v2]) => k1 === k2 && v1 === v2));
|
|
56
56
|
return [added, removed];
|
|
57
57
|
};
|
|
58
|
-
var commit = (txn, mutation, {
|
|
59
|
-
created,
|
|
60
|
-
updated,
|
|
61
|
-
deleted
|
|
62
|
-
}) => {
|
|
58
|
+
var commit = (txn, mutation, { created, updated, deleted }) => {
|
|
63
59
|
const { mutations } = txn.engineOpts;
|
|
64
60
|
const currentMutation = mutations.get(txn.mutation.ref);
|
|
65
61
|
if (currentMutation) {
|
|
@@ -76,6 +72,9 @@ var commit = (txn, mutation, {
|
|
|
76
72
|
if (txn.request.changeSetRef)
|
|
77
73
|
return mutation;
|
|
78
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
|
+
}
|
|
79
78
|
if (doc.__.unique?.length) {
|
|
80
79
|
doc.__.unique.forEach(([key, value]) => {
|
|
81
80
|
const uniqueKey = `${doc.entity}:${key}:${JSON.stringify(value)}`;
|
|
@@ -152,11 +151,12 @@ var commit = (txn, mutation, {
|
|
|
152
151
|
return mutation;
|
|
153
152
|
};
|
|
154
153
|
// src/functions/findDebounceMutation.ts
|
|
155
|
-
var findDebounceMutation = (request, engine, now, mutationName) => {
|
|
154
|
+
var findDebounceMutation = (request, engine, now, mutationName, identityRef) => {
|
|
156
155
|
const debounceTime = request.operation.debounce;
|
|
157
|
-
const thresholdTime = new Date(now - debounceTime * 1000).toISOString();
|
|
156
|
+
const thresholdTime = new Date(now.getTime() - debounceTime * 1000).toISOString();
|
|
157
|
+
const payloadRef = request.payload?.ref;
|
|
158
158
|
const res = engine.mutations.values().find((mutation) => {
|
|
159
|
-
if (mutation.operation.name === mutationName && mutation.timestamp > thresholdTime && mutation.payload
|
|
159
|
+
if (mutation.operation.name === mutationName && mutation.timestamp > thresholdTime && mutation.payload?.ref === payloadRef && mutation.identityRef === identityRef) {
|
|
160
160
|
return true;
|
|
161
161
|
}
|
|
162
162
|
});
|
|
@@ -186,7 +186,7 @@ var pageEntities = (txn, args) => {
|
|
|
186
186
|
continue;
|
|
187
187
|
} else {
|
|
188
188
|
if (childrenOf && childrenOf.length > 0) {
|
|
189
|
-
if (!childrenOf.some((childRef) => doc.__
|
|
189
|
+
if (!childrenOf.some((childRef) => doc.__?.parentRefs?.includes(childRef))) {
|
|
190
190
|
continue;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -203,11 +203,7 @@ var pageEntitiesByIndex = (txn, entity, field, value) => {
|
|
|
203
203
|
return refs.map((ref) => txn.engineOpts.entities.get(ref));
|
|
204
204
|
};
|
|
205
205
|
// src/functions/pageMutations.ts
|
|
206
|
-
var pageMutations = (txn, {
|
|
207
|
-
size = 30,
|
|
208
|
-
skip = 0,
|
|
209
|
-
changeSetRef
|
|
210
|
-
} = {}) => {
|
|
206
|
+
var pageMutations = (txn, { size = 30, skip = 0, changeSetRef } = {}) => {
|
|
211
207
|
const res = [];
|
|
212
208
|
const iterator = txn.engineOpts.mutations.values().drop(skip);
|
|
213
209
|
let next = iterator.next();
|
|
@@ -241,7 +237,8 @@ var createInMemoryAdapter = ({
|
|
|
241
237
|
entities,
|
|
242
238
|
snowflake = new Snowflake(1, 1),
|
|
243
239
|
optimistic = true,
|
|
244
|
-
session
|
|
240
|
+
session,
|
|
241
|
+
engine
|
|
245
242
|
}) => {
|
|
246
243
|
return createAdapter({
|
|
247
244
|
name: "in-memory",
|
|
@@ -251,7 +248,7 @@ var createInMemoryAdapter = ({
|
|
|
251
248
|
snowflake,
|
|
252
249
|
optimistic,
|
|
253
250
|
session
|
|
254
|
-
}, {
|
|
251
|
+
}, engine ?? {
|
|
255
252
|
entities: new Map,
|
|
256
253
|
mutations: new Map,
|
|
257
254
|
entitiesUnique: new Map,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Snowflake, type Adapter, type Operation, type Session } 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, optimistic, session, }: {
|
|
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;
|
|
10
6
|
optimistic?: boolean;
|
|
11
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
|
+
};
|
|
12
14
|
}) => Adapter;
|
|
13
|
-
export {};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { Ref } from "roc-db";
|
|
2
|
-
|
|
1
|
+
import type { Ref, Transaction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const batchReadEntities: (txn: Transaction<InMemoryEngine>, refs: Ref[]) => any[];
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
updated: Entity[];
|
|
5
|
-
deleted: Ref[];
|
|
6
|
-
}) => Mutation;
|
|
1
|
+
import { type CommitFunction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const commit: CommitFunction<InMemoryEngine>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FindDebounceMutationFunction } from "roc-db";
|
|
2
2
|
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
-
export declare const findDebounceMutation:
|
|
3
|
+
export declare const findDebounceMutation: FindDebounceMutationFunction<InMemoryEngine>;
|
|
@@ -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 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PageEntitiesByIndexFunction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const pageEntitiesByIndex: PageEntitiesByIndexFunction<InMemoryEngine>;
|
|
@@ -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
|
-
}) => any[];
|
|
3
|
+
export declare const pageMutations: PageMutationsFunction<InMemoryEngine>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ReadEntityFunctiun } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const readEntity: ReadEntityFunctiun<InMemoryEngine>;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { RefByUniqueFieldFunction } from "roc-db";
|
|
2
|
+
import type { InMemoryEngine } from "../types/InMemoryEngine";
|
|
3
|
+
export declare const refByUniqueField: RefByUniqueFieldFunction<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.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"roc-db": "0.2.0-pre.
|
|
16
|
+
"roc-db": ">=0.2.0-pre.98 <1.0.0",
|
|
17
17
|
"zod": ">=4.0.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [],
|
|
@@ -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
|
}
|