@katakit/persistence 0.2.0 → 0.3.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 +7 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @katakit/persistence
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Make your app’s history durable.** Preserve the events behind your app, ready to rebuild
|
|
4
|
+
its state when needed. Your application chooses the storage and loads history for replay.
|
|
5
|
+
|
|
6
|
+
This plugin persists new event-log entries through an application-supplied append callback.
|
|
4
7
|
The callback receives full recorded events from core's built-in log.
|
|
5
8
|
|
|
6
9
|
```ts
|
|
@@ -37,13 +40,11 @@ Stop producers before shutting down, then stop the timer and request a final
|
|
|
37
40
|
serialized flush:
|
|
38
41
|
|
|
39
42
|
```ts
|
|
40
|
-
|
|
43
|
+
runtime.stop();
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
It also retains the event subscription after stopping the timer. Core does not
|
|
46
|
-
yet provide a general disposal lifecycle.
|
|
46
|
+
Stop the runtime once. `stop()` returns without waiting for the queued write.
|
|
47
|
+
The storage adapter owns acknowledgement; final write failures are logged.
|
|
47
48
|
|
|
48
49
|
Persist the complete history in order, including provisional transcript events.
|
|
49
50
|
JSON encodes `meta.timestamp` as a string; validate it and restore a `Date`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KatakitEvent } from "@katakit/core";
|
|
1
|
+
import { KatakitEvent, START } from "@katakit/core";
|
|
2
2
|
/**
|
|
3
3
|
* Persists an event log's unsaved suffix through a caller-owned storage adapter.
|
|
4
4
|
* Loading history, identifying the stored log, and stopping producers remain host responsibilities.
|
|
@@ -7,7 +7,7 @@ declare const makeEventPersistencePlugin: ({ appendEvents, persistInterval }: {
|
|
|
7
7
|
appendEvents: (events: KatakitEvent[]) => void | Promise<void>;
|
|
8
8
|
persistInterval?: number;
|
|
9
9
|
}) => import("@katakit/core").KatakitPlugin<{}, import("@katakit/core").EmptyObj, {
|
|
10
|
-
|
|
10
|
+
[START]: () => () => Promise<void>;
|
|
11
11
|
}>;
|
|
12
12
|
export { makeEventPersistencePlugin };
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventLogPlugin, makeKatakitPlugin, skipReplay } from "@katakit/core";
|
|
1
|
+
import { EventLogPlugin, START, makeKatakitPlugin, skipReplay } from "@katakit/core";
|
|
2
2
|
import pLimit from "p-limit";
|
|
3
3
|
// src/EventPersistencePlugin/plugin.ts
|
|
4
4
|
/**
|
|
@@ -29,11 +29,10 @@ const makeEventPersistencePlugin = ({ appendEvents, persistInterval }) => makeKa
|
|
|
29
29
|
const intervalId = setInterval(() => {
|
|
30
30
|
flushLimit(flush);
|
|
31
31
|
}, persistInterval ?? 5e3);
|
|
32
|
-
|
|
32
|
+
return { [START]: () => async () => {
|
|
33
33
|
clearInterval(intervalId);
|
|
34
34
|
await flushLimit(flush);
|
|
35
|
-
};
|
|
36
|
-
return { kill };
|
|
35
|
+
} };
|
|
37
36
|
}
|
|
38
37
|
});
|
|
39
38
|
export { makeEventPersistencePlugin };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/EventPersistencePlugin/plugin.ts"],"sourcesContent":["import { EventLogPlugin, KatakitEvent, makeKatakitPlugin, skipReplay } from '@katakit/core';\nimport pLimit from 'p-limit';\n\n/**\n * Persists an event log's unsaved suffix through a caller-owned storage adapter.\n * Loading history, identifying the stored log, and stopping producers remain host responsibilities.\n */\nexport const makeEventPersistencePlugin = ({\n appendEvents,\n persistInterval,\n}: {\n appendEvents: (events: KatakitEvent[]) => void | Promise<void>;\n persistInterval?: number;\n}) =>\n makeKatakitPlugin({\n type: 'EventPersistence',\n configure: (options: {}) => options,\n methods: ({ getObservables }) => {\n const { events$ } = getObservables(EventLogPlugin);\n\n // only one flush should run at a time\n // other invokations are ignored.\n // exception: end of meeting flush is queued instead of being ignored.\n // see p-limit docs for more details.\n // TODO: use an effect instead.\n const flushLimit = pLimit(1);\n\n let pendingEvents: KatakitEvent[] = [];\n\n const flush = async () => {\n if (!pendingEvents.length) return;\n\n const eventsToPersist = pendingEvents;\n pendingEvents = [];\n\n try {\n await appendEvents(eventsToPersist);\n } catch (error) {\n // The transaction rolled back. Retry its events before anything emitted\n // during the failed write, otherwise later slide updates can lose their creation.\n pendingEvents = [...eventsToPersist, ...pendingEvents];\n console.error('Failed to flush events:', error);\n }\n };\n\n events$.pipe(skipReplay()).subscribe(async event => {\n pendingEvents.push(event);\n });\n\n const intervalId = setInterval(() => {\n flushLimit(flush);\n }, persistInterval ?? 5000);\n\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/EventPersistencePlugin/plugin.ts"],"sourcesContent":["import { EventLogPlugin, KatakitEvent, makeKatakitPlugin, skipReplay, START } from '@katakit/core';\nimport pLimit from 'p-limit';\n\n/**\n * Persists an event log's unsaved suffix through a caller-owned storage adapter.\n * Loading history, identifying the stored log, and stopping producers remain host responsibilities.\n */\nexport const makeEventPersistencePlugin = ({\n appendEvents,\n persistInterval,\n}: {\n appendEvents: (events: KatakitEvent[]) => void | Promise<void>;\n persistInterval?: number;\n}) =>\n makeKatakitPlugin({\n type: 'EventPersistence',\n configure: (options: {}) => options,\n methods: ({ getObservables }) => {\n const { events$ } = getObservables(EventLogPlugin);\n\n // only one flush should run at a time\n // other invokations are ignored.\n // exception: end of meeting flush is queued instead of being ignored.\n // see p-limit docs for more details.\n // TODO: use an effect instead.\n const flushLimit = pLimit(1);\n\n let pendingEvents: KatakitEvent[] = [];\n\n const flush = async () => {\n if (!pendingEvents.length) return;\n\n const eventsToPersist = pendingEvents;\n pendingEvents = [];\n\n try {\n await appendEvents(eventsToPersist);\n } catch (error) {\n // The transaction rolled back. Retry its events before anything emitted\n // during the failed write, otherwise later slide updates can lose their creation.\n pendingEvents = [...eventsToPersist, ...pendingEvents];\n console.error('Failed to flush events:', error);\n }\n };\n\n events$.pipe(skipReplay()).subscribe(async event => {\n pendingEvents.push(event);\n });\n\n const intervalId = setInterval(() => {\n flushLimit(flush);\n }, persistInterval ?? 5000);\n\n return {\n [START]: () => async () => {\n clearInterval(intervalId);\n // flush immediately.\n // if there's already a flush happening, this will be queued.\n await flushLimit(flush);\n },\n };\n },\n });\n"],"mappings":";;;;;;;AAOA,MAAa,8BAA8B,EACzC,cACA,sBAKA,kBAAkB;CAChB,MAAM;CACN,YAAY,YAAgB;CAC5B,UAAU,EAAE,qBAAqB;EAC/B,MAAM,EAAE,YAAY,eAAe,cAAc;EAOjD,MAAM,aAAa,OAAO,CAAC;EAE3B,IAAI,gBAAgC,CAAC;EAErC,MAAM,QAAQ,YAAY;GACxB,IAAI,CAAC,cAAc,QAAQ;GAE3B,MAAM,kBAAkB;GACxB,gBAAgB,CAAC;GAEjB,IAAI;IACF,MAAM,aAAa,eAAe;GACpC,SAAS,OAAO;IAGd,gBAAgB,CAAC,GAAG,iBAAiB,GAAG,aAAa;IACrD,QAAQ,MAAM,2BAA2B,KAAK;GAChD;EACF;EAEA,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,UAAU,OAAM,UAAS;GAClD,cAAc,KAAK,KAAK;EAC1B,CAAC;EAED,MAAM,aAAa,kBAAkB;GACnC,WAAW,KAAK;EAClB,GAAG,mBAAmB,GAAI;EAE1B,OAAO,GACJ,cAAc,YAAY;GACzB,cAAc,UAAU;GAGxB,MAAM,WAAW,KAAK;EACxB,EACF;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katakit/persistence",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Adapter-based event persistence for Katakit.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"rxjs": "^7.8.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@katakit/core": "0.
|
|
33
|
+
"@katakit/core": "0.3.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@katakit/core": "^0.
|
|
36
|
+
"@katakit/core": "^0.3.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsdown",
|