graphddb 0.3.1 → 0.4.0
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/README.md +1 -1
- package/dist/{chunk-YIXXTGZ6.js → chunk-72VZYOSG.js} +191 -239
- package/dist/{chunk-PNIZS37E.js → chunk-GWFZVNAV.js} +8 -118
- package/dist/{chunk-VST3WOK3.js → chunk-PC54CW5P.js} +3 -5
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +298 -104
- package/dist/index.js +279 -37
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +2 -2
- package/dist/{types-DuJ08bgc.d.ts → types-CpCo8yHP.d.ts} +140 -419
- package/package.json +1 -1
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
buildDeleteInput,
|
|
7
7
|
buildMaintenanceGraph,
|
|
8
8
|
buildPutInput,
|
|
9
|
-
isProjectionDefinition,
|
|
10
9
|
resolveModelClass
|
|
11
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-72VZYOSG.js";
|
|
12
11
|
|
|
13
12
|
// src/cdc/prng.ts
|
|
14
13
|
var SeededRandom = class {
|
|
@@ -550,10 +549,13 @@ var MaintenanceDrain = class {
|
|
|
550
549
|
return m;
|
|
551
550
|
}
|
|
552
551
|
});
|
|
553
|
-
const
|
|
554
|
-
const allClasses = [
|
|
552
|
+
const explicitViews = opts.views;
|
|
553
|
+
const allClasses = [
|
|
554
|
+
...classes,
|
|
555
|
+
...(explicitViews ?? []).map((v) => v.viewClass)
|
|
556
|
+
];
|
|
555
557
|
const scoped = allClasses.length > 0 ? new Map(allClasses.map((c) => [c, MetadataRegistry.get(c)])) : void 0;
|
|
556
|
-
this.graph = buildMaintenanceGraph(scoped,
|
|
558
|
+
this.graph = buildMaintenanceGraph(scoped, explicitViews);
|
|
557
559
|
for (const item of this.graph.items) {
|
|
558
560
|
this.ownerByName.set(item.ownerEntity, item.ownerClass);
|
|
559
561
|
}
|
|
@@ -790,114 +792,6 @@ function createMaintenanceDrainHandler(opts = {}) {
|
|
|
790
792
|
return createMaintenanceDrain(opts).handler;
|
|
791
793
|
}
|
|
792
794
|
|
|
793
|
-
// src/cdc/projection-sink.ts
|
|
794
|
-
var EVENT_FOR_CHANGE = {
|
|
795
|
-
INSERT: "created",
|
|
796
|
-
MODIFY: "updated",
|
|
797
|
-
REMOVE: "removed"
|
|
798
|
-
};
|
|
799
|
-
var InMemoryProjectionSink = class {
|
|
800
|
-
/** The current sink contents, keyed by the idempotency key. */
|
|
801
|
-
records = /* @__PURE__ */ new Map();
|
|
802
|
-
/** Total upsert CALLS (including redelivered ones) — distinguishes calls from records. */
|
|
803
|
-
upserts = 0;
|
|
804
|
-
upsert(key, record) {
|
|
805
|
-
this.records.set(key, record);
|
|
806
|
-
this.upserts += 1;
|
|
807
|
-
}
|
|
808
|
-
delete(key) {
|
|
809
|
-
this.records.delete(key);
|
|
810
|
-
}
|
|
811
|
-
/** The number of distinct sink records (the converged projection size). */
|
|
812
|
-
size() {
|
|
813
|
-
return this.records.size;
|
|
814
|
-
}
|
|
815
|
-
/** The total upsert calls (≥ size when redelivery occurred). */
|
|
816
|
-
upsertCount() {
|
|
817
|
-
return this.upserts;
|
|
818
|
-
}
|
|
819
|
-
/** Reset the sink (test). */
|
|
820
|
-
reset() {
|
|
821
|
-
this.records.clear();
|
|
822
|
-
this.upserts = 0;
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
var ProjectionSinkDrain = class {
|
|
826
|
-
sink;
|
|
827
|
-
/** Source-entity CLASS name (the `event.model` the capture seam records) → projections. */
|
|
828
|
-
bySource = /* @__PURE__ */ new Map();
|
|
829
|
-
/** Per-(shard,seq) de-dup within one handler invocation (at-least-once). */
|
|
830
|
-
applied = /* @__PURE__ */ new Set();
|
|
831
|
-
constructor(opts) {
|
|
832
|
-
this.sink = opts.sink;
|
|
833
|
-
for (const proj of opts.projections) {
|
|
834
|
-
if (!isProjectionDefinition(proj)) {
|
|
835
|
-
throw new Error(
|
|
836
|
-
"ProjectionSinkDrain: a non-projection definition was supplied. Build projections with defineProjection(...)."
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
const sourceName = proj.sourceClass.name;
|
|
840
|
-
const bucket = this.bySource.get(sourceName);
|
|
841
|
-
if (bucket) bucket.push(proj);
|
|
842
|
-
else this.bySource.set(sourceName, [proj]);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
/** The CDC {@link ChangeHandler} to subscribe to an emulator / Streams source. */
|
|
846
|
-
handler = async (batch) => {
|
|
847
|
-
const failures = [];
|
|
848
|
-
for (const event of batch.records) {
|
|
849
|
-
try {
|
|
850
|
-
await this.applyOne(event);
|
|
851
|
-
} catch (e) {
|
|
852
|
-
failures.push(event.sequenceNumber);
|
|
853
|
-
if (process.env.GRAPHDDB_PROJECTION_DEBUG) {
|
|
854
|
-
console.error("PROJECTION SINK ERROR", event.keys.pk, e);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return failures.length > 0 ? { batchItemFailures: failures } : {};
|
|
859
|
-
};
|
|
860
|
-
/** Project one source event into the sink for every matching projection. */
|
|
861
|
-
async applyOne(event) {
|
|
862
|
-
const sourceName = event.model;
|
|
863
|
-
if (sourceName === void 0) return;
|
|
864
|
-
const projections = this.bySource.get(sourceName);
|
|
865
|
-
if (projections === void 0 || projections.length === 0) return;
|
|
866
|
-
const lifecycleEvent = EVENT_FOR_CHANGE[event.eventName];
|
|
867
|
-
const image = event.eventName === "REMOVE" ? event.oldImage : event.newImage;
|
|
868
|
-
if (image === void 0) return;
|
|
869
|
-
const eventId = `${event.shardId}#${event.sequenceNumber}`;
|
|
870
|
-
if (this.applied.has(eventId)) return;
|
|
871
|
-
for (const proj of projections) {
|
|
872
|
-
if (!proj.on.includes(lifecycleEvent)) continue;
|
|
873
|
-
const key = image[proj.idempotencyKey];
|
|
874
|
-
if (key === void 0 || key === null) {
|
|
875
|
-
throw new Error(
|
|
876
|
-
`defineProjection '${proj.name}': source event carries no idempotency key attribute '${proj.idempotencyKey}'. Every projected source row must carry it (it folds at-least-once delivery to one sink upsert).`
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
const keyStr = String(key);
|
|
880
|
-
if (lifecycleEvent === "removed") {
|
|
881
|
-
await this.sink.delete?.(keyStr);
|
|
882
|
-
continue;
|
|
883
|
-
}
|
|
884
|
-
const record = Object.keys(proj.project).length === 0 ? image : projectFrom(proj.project, image);
|
|
885
|
-
await this.sink.upsert(keyStr, record);
|
|
886
|
-
}
|
|
887
|
-
this.applied.add(eventId);
|
|
888
|
-
}
|
|
889
|
-
/** Clear the per-delivery de-dup set (test reset). */
|
|
890
|
-
reset() {
|
|
891
|
-
this.applied = /* @__PURE__ */ new Set();
|
|
892
|
-
}
|
|
893
|
-
};
|
|
894
|
-
function createProjectionSinkDrain(opts) {
|
|
895
|
-
return new ProjectionSinkDrain(opts);
|
|
896
|
-
}
|
|
897
|
-
function createProjectionSinkHandler(opts) {
|
|
898
|
-
return createProjectionSinkDrain(opts).handler;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
795
|
export {
|
|
902
796
|
CdcEmulator,
|
|
903
797
|
createCdcEmulator,
|
|
@@ -908,9 +802,5 @@ export {
|
|
|
908
802
|
MAINT_OUTBOX_PK_PREFIX,
|
|
909
803
|
MaintenanceDrain,
|
|
910
804
|
createMaintenanceDrain,
|
|
911
|
-
createMaintenanceDrainHandler
|
|
912
|
-
InMemoryProjectionSink,
|
|
913
|
-
ProjectionSinkDrain,
|
|
914
|
-
createProjectionSinkDrain,
|
|
915
|
-
createProjectionSinkHandler
|
|
805
|
+
createMaintenanceDrainHandler
|
|
916
806
|
};
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
MetadataRegistry,
|
|
7
7
|
NO_MIDDLEWARE,
|
|
8
8
|
TableMapping,
|
|
9
|
-
ViewRegistry,
|
|
10
9
|
attachHiddenKey,
|
|
11
10
|
attachModelClass,
|
|
12
11
|
buildConditionExpression,
|
|
@@ -43,7 +42,7 @@ import {
|
|
|
43
42
|
serializeFieldValue,
|
|
44
43
|
serializeRawCondition,
|
|
45
44
|
skTemplate
|
|
46
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-72VZYOSG.js";
|
|
47
46
|
|
|
48
47
|
// src/spec/types.ts
|
|
49
48
|
var SPEC_VERSION = "1.0";
|
|
@@ -3952,9 +3951,8 @@ var MAINTAIN_ENTITY_PATH_RE = /^\$\.entity\.([A-Za-z_$][\w$]*)$/;
|
|
|
3952
3951
|
var cachedMaintenanceGraph;
|
|
3953
3952
|
function globalMaintenanceGraph() {
|
|
3954
3953
|
const generation = MetadataRegistry.generation;
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
cachedMaintenanceGraph = { graph: buildMaintenanceGraph(), generation, viewGeneration };
|
|
3954
|
+
if (cachedMaintenanceGraph?.generation !== generation) {
|
|
3955
|
+
cachedMaintenanceGraph = { graph: buildMaintenanceGraph(), generation };
|
|
3958
3956
|
}
|
|
3959
3957
|
return cachedMaintenanceGraph.graph;
|
|
3960
3958
|
}
|
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
buildBridgeBundle,
|
|
4
4
|
normalizeSelectSpec
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PC54CW5P.js";
|
|
6
6
|
import {
|
|
7
7
|
MetadataRegistry
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-72VZYOSG.js";
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
11
|
import { createRequire } from "module";
|