@smthrs/journal 0.0.0-stage → 1.0.0-rc.3
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/CHANGELOG.md +149 -0
- package/LICENSE +21 -0
- package/README.md +206 -2
- package/dist/cjs/CallFact.d.ts +129 -0
- package/dist/cjs/CallFact.d.ts.map +1 -0
- package/dist/cjs/CallFact.js +106 -0
- package/dist/cjs/CallFact.js.map +7 -0
- package/dist/cjs/Consensus.d.ts +440 -0
- package/dist/cjs/Consensus.d.ts.map +1 -0
- package/dist/cjs/Consensus.js +251 -0
- package/dist/cjs/Consensus.js.map +7 -0
- package/dist/cjs/EngineEvent.d.ts +890 -0
- package/dist/cjs/EngineEvent.d.ts.map +1 -0
- package/dist/cjs/EngineEvent.js +383 -0
- package/dist/cjs/EngineEvent.js.map +7 -0
- package/dist/cjs/ExecutionFact.d.ts +216 -0
- package/dist/cjs/ExecutionFact.d.ts.map +1 -0
- package/dist/cjs/ExecutionFact.js +303 -0
- package/dist/cjs/ExecutionFact.js.map +7 -0
- package/dist/cjs/Journal.d.ts +617 -0
- package/dist/cjs/Journal.d.ts.map +1 -0
- package/dist/cjs/Journal.js +190 -0
- package/dist/cjs/Journal.js.map +7 -0
- package/dist/cjs/JournalEvent.d.ts +421 -0
- package/dist/cjs/JournalEvent.d.ts.map +1 -0
- package/dist/cjs/JournalEvent.js +281 -0
- package/dist/cjs/JournalEvent.js.map +7 -0
- package/dist/cjs/JournalGeneration.d.ts +34 -0
- package/dist/cjs/JournalGeneration.d.ts.map +1 -0
- package/dist/cjs/JournalGeneration.js +72 -0
- package/dist/cjs/JournalGeneration.js.map +7 -0
- package/dist/cjs/JournalMetrics.d.ts +72 -0
- package/dist/cjs/JournalMetrics.d.ts.map +1 -0
- package/dist/cjs/JournalMetrics.js +55 -0
- package/dist/cjs/JournalMetrics.js.map +7 -0
- package/dist/cjs/Migrations.d.ts +42 -0
- package/dist/cjs/Migrations.d.ts.map +1 -0
- package/dist/cjs/Migrations.js +58 -0
- package/dist/cjs/Migrations.js.map +7 -0
- package/dist/cjs/OwnerId.d.ts +40 -0
- package/dist/cjs/OwnerId.d.ts.map +1 -0
- package/dist/cjs/OwnerId.js +40 -0
- package/dist/cjs/OwnerId.js.map +7 -0
- package/dist/cjs/Projection.d.ts +29 -0
- package/dist/cjs/Projection.d.ts.map +1 -0
- package/dist/cjs/Projection.js +25 -0
- package/dist/cjs/Projection.js.map +7 -0
- package/dist/cjs/RedactedLogger.d.ts +121 -0
- package/dist/cjs/RedactedLogger.d.ts.map +1 -0
- package/dist/cjs/RedactedLogger.js +235 -0
- package/dist/cjs/RedactedLogger.js.map +7 -0
- package/dist/cjs/Redaction.d.ts +350 -0
- package/dist/cjs/Redaction.d.ts.map +1 -0
- package/dist/cjs/Redaction.js +928 -0
- package/dist/cjs/Redaction.js.map +7 -0
- package/dist/cjs/SqlConsensus.d.ts +44 -0
- package/dist/cjs/SqlConsensus.d.ts.map +1 -0
- package/dist/cjs/SqlConsensus.js +243 -0
- package/dist/cjs/SqlConsensus.js.map +7 -0
- package/dist/cjs/SqlJournal.d.ts +173 -0
- package/dist/cjs/SqlJournal.d.ts.map +1 -0
- package/dist/cjs/SqlJournal.js +1568 -0
- package/dist/cjs/SqlJournal.js.map +7 -0
- package/dist/cjs/StepFact.d.ts +66 -0
- package/dist/cjs/StepFact.d.ts.map +1 -0
- package/dist/cjs/StepFact.js +68 -0
- package/dist/cjs/StepFact.js.map +7 -0
- package/dist/cjs/index.d.ts +95 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/JournalInternalFault.d.ts +37 -0
- package/dist/cjs/internal/JournalInternalFault.d.ts.map +1 -0
- package/dist/cjs/internal/JournalInternalFault.js +43 -0
- package/dist/cjs/internal/JournalInternalFault.js.map +7 -0
- package/dist/cjs/migrations/0001_initial.d.ts +15 -0
- package/dist/cjs/migrations/0001_initial.d.ts.map +1 -0
- package/dist/cjs/migrations/0001_initial.js +54 -0
- package/dist/cjs/migrations/0001_initial.js.map +7 -0
- package/dist/cjs/migrations/0002_checkpoints.d.ts +27 -0
- package/dist/cjs/migrations/0002_checkpoints.d.ts.map +1 -0
- package/dist/cjs/migrations/0002_checkpoints.js +48 -0
- package/dist/cjs/migrations/0002_checkpoints.js.map +7 -0
- package/dist/cjs/migrations/0003_startup_index.d.ts +15 -0
- package/dist/cjs/migrations/0003_startup_index.d.ts.map +1 -0
- package/dist/cjs/migrations/0003_startup_index.js +40 -0
- package/dist/cjs/migrations/0003_startup_index.js.map +7 -0
- package/dist/cjs/migrations/0004_dedup.d.ts +15 -0
- package/dist/cjs/migrations/0004_dedup.d.ts.map +1 -0
- package/dist/cjs/migrations/0004_dedup.js +57 -0
- package/dist/cjs/migrations/0004_dedup.js.map +7 -0
- package/dist/cjs/migrations/0005_run_event_type.d.ts +15 -0
- package/dist/cjs/migrations/0005_run_event_type.d.ts.map +1 -0
- package/dist/cjs/migrations/0005_run_event_type.js +40 -0
- package/dist/cjs/migrations/0005_run_event_type.js.map +7 -0
- package/dist/cjs/migrations/0006_consensus.d.ts +22 -0
- package/dist/cjs/migrations/0006_consensus.d.ts.map +1 -0
- package/dist/cjs/migrations/0006_consensus.js +84 -0
- package/dist/cjs/migrations/0006_consensus.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/Notifying.d.ts +65 -0
- package/dist/cjs/test/Notifying.d.ts.map +1 -0
- package/dist/cjs/test/Notifying.js +62 -0
- package/dist/cjs/test/Notifying.js.map +7 -0
- package/dist/cjs/test/TestJournal.d.ts +43 -0
- package/dist/cjs/test/TestJournal.d.ts.map +1 -0
- package/dist/cjs/test/TestJournal.js +43 -0
- package/dist/cjs/test/TestJournal.js.map +7 -0
- package/dist/esm/CallFact.d.ts +129 -0
- package/dist/esm/CallFact.d.ts.map +1 -0
- package/dist/esm/CallFact.js +96 -0
- package/dist/esm/CallFact.js.map +1 -0
- package/dist/esm/Consensus.d.ts +440 -0
- package/dist/esm/Consensus.d.ts.map +1 -0
- package/dist/esm/Consensus.js +454 -0
- package/dist/esm/Consensus.js.map +1 -0
- package/dist/esm/EngineEvent.d.ts +890 -0
- package/dist/esm/EngineEvent.d.ts.map +1 -0
- package/dist/esm/EngineEvent.js +614 -0
- package/dist/esm/EngineEvent.js.map +1 -0
- package/dist/esm/ExecutionFact.d.ts +216 -0
- package/dist/esm/ExecutionFact.d.ts.map +1 -0
- package/dist/esm/ExecutionFact.js +374 -0
- package/dist/esm/ExecutionFact.js.map +1 -0
- package/dist/esm/Journal.d.ts +617 -0
- package/dist/esm/Journal.d.ts.map +1 -0
- package/dist/esm/Journal.js +323 -0
- package/dist/esm/Journal.js.map +1 -0
- package/dist/esm/JournalEvent.d.ts +421 -0
- package/dist/esm/JournalEvent.d.ts.map +1 -0
- package/dist/esm/JournalEvent.js +517 -0
- package/dist/esm/JournalEvent.js.map +1 -0
- package/dist/esm/JournalGeneration.d.ts +34 -0
- package/dist/esm/JournalGeneration.d.ts.map +1 -0
- package/dist/esm/JournalGeneration.js +65 -0
- package/dist/esm/JournalGeneration.js.map +1 -0
- package/dist/esm/JournalMetrics.d.ts +72 -0
- package/dist/esm/JournalMetrics.d.ts.map +1 -0
- package/dist/esm/JournalMetrics.js +79 -0
- package/dist/esm/JournalMetrics.js.map +1 -0
- package/dist/esm/Migrations.d.ts +42 -0
- package/dist/esm/Migrations.d.ts.map +1 -0
- package/dist/esm/Migrations.js +59 -0
- package/dist/esm/Migrations.js.map +1 -0
- package/dist/esm/OwnerId.d.ts +40 -0
- package/dist/esm/OwnerId.d.ts.map +1 -0
- package/dist/esm/OwnerId.js +33 -0
- package/dist/esm/OwnerId.js.map +1 -0
- package/dist/esm/Projection.d.ts +29 -0
- package/dist/esm/Projection.d.ts.map +1 -0
- package/dist/esm/Projection.js +13 -0
- package/dist/esm/Projection.js.map +1 -0
- package/dist/esm/RedactedLogger.d.ts +121 -0
- package/dist/esm/RedactedLogger.d.ts.map +1 -0
- package/dist/esm/RedactedLogger.js +445 -0
- package/dist/esm/RedactedLogger.js.map +1 -0
- package/dist/esm/Redaction.d.ts +350 -0
- package/dist/esm/Redaction.d.ts.map +1 -0
- package/dist/esm/Redaction.js +1584 -0
- package/dist/esm/Redaction.js.map +1 -0
- package/dist/esm/SqlConsensus.d.ts +44 -0
- package/dist/esm/SqlConsensus.d.ts.map +1 -0
- package/dist/esm/SqlConsensus.js +252 -0
- package/dist/esm/SqlConsensus.js.map +1 -0
- package/dist/esm/SqlJournal.d.ts +173 -0
- package/dist/esm/SqlJournal.d.ts.map +1 -0
- package/dist/esm/SqlJournal.js +1858 -0
- package/dist/esm/SqlJournal.js.map +1 -0
- package/dist/esm/StepFact.d.ts +66 -0
- package/dist/esm/StepFact.d.ts.map +1 -0
- package/dist/esm/StepFact.js +50 -0
- package/dist/esm/StepFact.js.map +1 -0
- package/dist/esm/index.d.ts +95 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +95 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/JournalInternalFault.d.ts +37 -0
- package/dist/esm/internal/JournalInternalFault.d.ts.map +1 -0
- package/dist/esm/internal/JournalInternalFault.js +28 -0
- package/dist/esm/internal/JournalInternalFault.js.map +1 -0
- package/dist/esm/migrations/0001_initial.d.ts +15 -0
- package/dist/esm/migrations/0001_initial.d.ts.map +1 -0
- package/dist/esm/migrations/0001_initial.js +32 -0
- package/dist/esm/migrations/0001_initial.js.map +1 -0
- package/dist/esm/migrations/0002_checkpoints.d.ts +27 -0
- package/dist/esm/migrations/0002_checkpoints.d.ts.map +1 -0
- package/dist/esm/migrations/0002_checkpoints.js +38 -0
- package/dist/esm/migrations/0002_checkpoints.js.map +1 -0
- package/dist/esm/migrations/0003_startup_index.d.ts +15 -0
- package/dist/esm/migrations/0003_startup_index.d.ts.map +1 -0
- package/dist/esm/migrations/0003_startup_index.js +18 -0
- package/dist/esm/migrations/0003_startup_index.js.map +1 -0
- package/dist/esm/migrations/0004_dedup.d.ts +15 -0
- package/dist/esm/migrations/0004_dedup.d.ts.map +1 -0
- package/dist/esm/migrations/0004_dedup.js +38 -0
- package/dist/esm/migrations/0004_dedup.js.map +1 -0
- package/dist/esm/migrations/0005_run_event_type.d.ts +15 -0
- package/dist/esm/migrations/0005_run_event_type.d.ts.map +1 -0
- package/dist/esm/migrations/0005_run_event_type.js +18 -0
- package/dist/esm/migrations/0005_run_event_type.js.map +1 -0
- package/dist/esm/migrations/0006_consensus.d.ts +22 -0
- package/dist/esm/migrations/0006_consensus.d.ts.map +1 -0
- package/dist/esm/migrations/0006_consensus.js +69 -0
- package/dist/esm/migrations/0006_consensus.js.map +1 -0
- package/dist/esm/test/Notifying.d.ts +65 -0
- package/dist/esm/test/Notifying.d.ts.map +1 -0
- package/dist/esm/test/Notifying.js +62 -0
- package/dist/esm/test/Notifying.js.map +1 -0
- package/dist/esm/test/TestJournal.d.ts +43 -0
- package/dist/esm/test/TestJournal.d.ts.map +1 -0
- package/dist/esm/test/TestJournal.js +27 -0
- package/dist/esm/test/TestJournal.js.map +1 -0
- package/docs/README.md +164 -0
- package/docs/api.md +639 -0
- package/docs/concepts/compaction.md +157 -0
- package/docs/concepts/idempotency.md +127 -0
- package/docs/concepts/owner-fence.md +124 -0
- package/docs/concepts/redaction.md +218 -0
- package/docs/concepts/state-event-authority.md +159 -0
- package/docs/concepts/two-channels.md +167 -0
- package/docs/guides/commit-state-and-entry.md +114 -0
- package/docs/guides/compact-a-run.md +134 -0
- package/docs/guides/fold-a-projection.md +106 -0
- package/docs/guides/read-a-run.md +139 -0
- package/docs/guides/redact-log-output.md +94 -0
- package/docs/guides/testing.md +124 -0
- package/docs/guides/write-lifecycle-events.md +110 -0
- package/docs/installation.md +133 -0
- package/docs/quickstart.md +143 -0
- package/docs/troubleshooting.md +214 -0
- package/package.json +263 -3
- package/src/CallFact.ts +117 -0
- package/src/Consensus.ts +683 -0
- package/src/EngineEvent.ts +823 -0
- package/src/ExecutionFact.ts +433 -0
- package/src/Journal.ts +688 -0
- package/src/JournalEvent.ts +654 -0
- package/src/JournalGeneration.ts +77 -0
- package/src/JournalMetrics.ts +89 -0
- package/src/Migrations.ts +62 -0
- package/src/OwnerId.ts +42 -0
- package/src/Projection.ts +31 -0
- package/src/RedactedLogger.ts +483 -0
- package/src/Redaction.ts +1784 -0
- package/src/SqlConsensus.ts +344 -0
- package/src/SqlJournal.ts +2732 -0
- package/src/StepFact.ts +69 -0
- package/src/index.ts +109 -0
- package/src/internal/JournalInternalFault.ts +40 -0
- package/src/migrations/0001_initial.ts +41 -0
- package/src/migrations/0002_checkpoints.ts +46 -0
- package/src/migrations/0003_startup_index.ts +19 -0
- package/src/migrations/0004_dedup.ts +43 -0
- package/src/migrations/0005_run_event_type.ts +19 -0
- package/src/migrations/0006_consensus.ts +83 -0
- package/src/test/Notifying.ts +101 -0
- package/src/test/TestJournal.ts +52 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Journal schema migrations.
|
|
3
|
+
*
|
|
4
|
+
* The journal owns four tables: `flows_journal_events` and its event-type
|
|
5
|
+
* index in `0001_initial`, `flows_journal_checkpoints` in
|
|
6
|
+
* `0002_checkpoints`, the bounded startup ordering index in
|
|
7
|
+
* `0003_startup_index`, compacted producer identities in `0004_dedup`, the
|
|
8
|
+
* per-run exact event-type cursor index in `0005_run_event_type`, and the
|
|
9
|
+
* `SqlConsensus` lease table `flows_consensus_leases` in `0006_consensus`. Run
|
|
10
|
+
* and attempt state migrate from `@smthrs/run-store`, the step cache from
|
|
11
|
+
* `@smthrs/step-cache`, and the durable deferred/clock tables from
|
|
12
|
+
* `@smthrs/engine-store`; an application composes those sets with this one
|
|
13
|
+
* through `@smthrs/database`'s `Migrations.layer`.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.1.0
|
|
16
|
+
*/
|
|
17
|
+
import * as DatabaseMigrations from "@smthrs/database/Migrations";
|
|
18
|
+
import * as Layer from "effect/Layer";
|
|
19
|
+
/**
|
|
20
|
+
* The journal's namespaced migration set, for composition with the other
|
|
21
|
+
* storage packages.
|
|
22
|
+
*
|
|
23
|
+
* @category migrations
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
export declare const set: DatabaseMigrations.MigrationSet;
|
|
27
|
+
/**
|
|
28
|
+
* Creates the journal's authoritative durable schema.
|
|
29
|
+
*
|
|
30
|
+
* @category migrations
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
export declare const run: import("effect/Effect").Effect<readonly (readonly [id: number, name: string])[], import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError, import("effect/unstable/sql/SqlClient").SqlClient>;
|
|
34
|
+
/**
|
|
35
|
+
* Layer that runs journal migrations before exposing the database to journal
|
|
36
|
+
* services.
|
|
37
|
+
*
|
|
38
|
+
* @category layers
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
*/
|
|
41
|
+
export declare const layer: Layer.Layer<never, import("effect/unstable/sql/SqlError").SqlError | import("effect/unstable/sql/Migrator").MigrationError, import("effect/unstable/sql/SqlClient").SqlClient>;
|
|
42
|
+
//# sourceMappingURL=Migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migrations.d.ts","sourceRoot":"","sources":["../../src/Migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,kBAAkB,MAAM,6BAA6B,CAAA;AACjE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAQrC;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAAE,kBAAkB,CAAC,YAWpC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,GAAG,8OAAgC,CAAA;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,gLAA2B,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Migrations_exports = {};
|
|
30
|
+
__export(Migrations_exports, {
|
|
31
|
+
layer: () => layer,
|
|
32
|
+
run: () => run,
|
|
33
|
+
set: () => set
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(Migrations_exports);
|
|
36
|
+
var DatabaseMigrations = __toESM(require("@smthrs/database/Migrations"), 1);
|
|
37
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
38
|
+
var import_initial = require("./migrations/0001_initial.js");
|
|
39
|
+
var import_checkpoints = require("./migrations/0002_checkpoints.js");
|
|
40
|
+
var import_startup_index = require("./migrations/0003_startup_index.js");
|
|
41
|
+
var import_dedup = require("./migrations/0004_dedup.js");
|
|
42
|
+
var import_run_event_type = require("./migrations/0005_run_event_type.js");
|
|
43
|
+
var import_consensus = require("./migrations/0006_consensus.js");
|
|
44
|
+
const set = {
|
|
45
|
+
namespace: "journal",
|
|
46
|
+
idOffset: 0,
|
|
47
|
+
migrations: {
|
|
48
|
+
"0001_initial": import_initial.initial,
|
|
49
|
+
"0002_checkpoints": import_checkpoints.checkpoints,
|
|
50
|
+
"0003_startup_index": import_startup_index.startupIndex,
|
|
51
|
+
"0004_dedup": import_dedup.dedup,
|
|
52
|
+
"0005_run_event_type": import_run_event_type.runEventType,
|
|
53
|
+
"0006_consensus": import_consensus.consensus
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const run = DatabaseMigrations.run([set]);
|
|
57
|
+
const layer = Layer.effectDiscard(run);
|
|
58
|
+
//# sourceMappingURL=Migrations.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Migrations.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Journal schema migrations.\n *\n * The journal owns four tables: `flows_journal_events` and its event-type\n * index in `0001_initial`, `flows_journal_checkpoints` in\n * `0002_checkpoints`, the bounded startup ordering index in\n * `0003_startup_index`, compacted producer identities in `0004_dedup`, the\n * per-run exact event-type cursor index in `0005_run_event_type`, and the\n * `SqlConsensus` lease table `flows_consensus_leases` in `0006_consensus`. Run\n * and attempt state migrate from `@smthrs/run-store`, the step cache from\n * `@smthrs/step-cache`, and the durable deferred/clock tables from\n * `@smthrs/engine-store`; an application composes those sets with this one\n * through `@smthrs/database`'s `Migrations.layer`.\n *\n * @since 0.1.0\n */\n\nimport * as DatabaseMigrations from \"@smthrs/database/Migrations\"\nimport * as Layer from \"effect/Layer\"\nimport { initial } from \"./migrations/0001_initial.ts\"\nimport { checkpoints } from \"./migrations/0002_checkpoints.ts\"\nimport { startupIndex } from \"./migrations/0003_startup_index.ts\"\nimport { dedup } from \"./migrations/0004_dedup.ts\"\nimport { runEventType } from \"./migrations/0005_run_event_type.ts\"\nimport { consensus } from \"./migrations/0006_consensus.ts\"\n\n/**\n * The journal's namespaced migration set, for composition with the other\n * storage packages.\n *\n * @category migrations\n * @since 0.1.0\n */\nexport const set: DatabaseMigrations.MigrationSet = {\n namespace: \"journal\",\n idOffset: 0,\n migrations: {\n \"0001_initial\": initial,\n \"0002_checkpoints\": checkpoints,\n \"0003_startup_index\": startupIndex,\n \"0004_dedup\": dedup,\n \"0005_run_event_type\": runEventType,\n \"0006_consensus\": consensus\n }\n}\n\n/**\n * Creates the journal's authoritative durable schema.\n *\n * @category migrations\n * @since 0.1.0\n */\nexport const run = DatabaseMigrations.run([set])\n\n/**\n * Layer that runs journal migrations before exposing the database to journal\n * services.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = Layer.effectDiscard(run)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,yBAAoC;AACpC,YAAuB;AACvB,qBAAwB;AACxB,yBAA4B;AAC5B,2BAA6B;AAC7B,mBAAsB;AACtB,4BAA6B;AAC7B,uBAA0B;AASnB,MAAM,MAAuC;AAAA,EAClD,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,IACV,gBAAgB;AAAA,IAChB,oBAAoB;AAAA,IACpB,sBAAsB;AAAA,IACtB,cAAc;AAAA,IACd,uBAAuB;AAAA,IACvB,kBAAkB;AAAA,EACpB;AACF;AAQO,MAAM,MAAM,mBAAmB,IAAI,CAAC,GAAG,CAAC;AASxC,MAAM,QAAQ,MAAM,cAAc,GAAG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fencing token the journal accepts on durable appends.
|
|
3
|
+
*
|
|
4
|
+
* `OwnerId` lives here rather than with the ownership *arbitration* in
|
|
5
|
+
* `@smthrs/run-store` because the journal is what it fences: `emitDurable`
|
|
6
|
+
* takes an owner and refuses the append when the persisted fence has moved on.
|
|
7
|
+
* The journal therefore defines the token, and the run store (which stores it
|
|
8
|
+
* on runs and arbitrates who holds it) imports it.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
/**
|
|
14
|
+
* A process identity scoped to a host and a unique ownership nonce.
|
|
15
|
+
*
|
|
16
|
+
* `pid` is a real operating-system process id, so the schema states that: a
|
|
17
|
+
* non-negative integer. A fractional, `NaN`, or negative `pid` is a caller
|
|
18
|
+
* bug, and the fenced methods reject it as `invalid_event` rather than
|
|
19
|
+
* degrading it into `fence_lost`, which would read as "someone else owns this
|
|
20
|
+
* run" and send the caller looking for a race that never happened.
|
|
21
|
+
*
|
|
22
|
+
* `hostId` and `nonce` stay plain strings. An empty one is a legal value that
|
|
23
|
+
* simply matches no persisted owner, which is exactly `fence_lost`.
|
|
24
|
+
*
|
|
25
|
+
* @since 0.1.0
|
|
26
|
+
* @category models
|
|
27
|
+
*/
|
|
28
|
+
export declare const OwnerId: Schema.Struct<{
|
|
29
|
+
readonly hostId: Schema.String;
|
|
30
|
+
readonly pid: Schema.Int;
|
|
31
|
+
readonly nonce: Schema.String;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* A process identity scoped to a host and a unique ownership nonce.
|
|
35
|
+
*
|
|
36
|
+
* @since 0.1.0
|
|
37
|
+
* @category models
|
|
38
|
+
*/
|
|
39
|
+
export type OwnerId = typeof OwnerId.Type;
|
|
40
|
+
//# sourceMappingURL=OwnerId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OwnerId.d.ts","sourceRoot":"","sources":["../../src/OwnerId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO;;;;EAIlB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var OwnerId_exports = {};
|
|
30
|
+
__export(OwnerId_exports, {
|
|
31
|
+
OwnerId: () => OwnerId
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(OwnerId_exports);
|
|
34
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
35
|
+
const OwnerId = Schema.Struct({
|
|
36
|
+
hostId: Schema.String,
|
|
37
|
+
pid: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
38
|
+
nonce: Schema.String
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=OwnerId.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/OwnerId.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The fencing token the journal accepts on durable appends.\n *\n * `OwnerId` lives here rather than with the ownership *arbitration* in\n * `@smthrs/run-store` because the journal is what it fences: `emitDurable`\n * takes an owner and refuses the append when the persisted fence has moved on.\n * The journal therefore defines the token, and the run store (which stores it\n * on runs and arbitrates who holds it) imports it.\n *\n * @since 0.1.0\n */\n\nimport * as Schema from \"effect/Schema\"\n\n/**\n * A process identity scoped to a host and a unique ownership nonce.\n *\n * `pid` is a real operating-system process id, so the schema states that: a\n * non-negative integer. A fractional, `NaN`, or negative `pid` is a caller\n * bug, and the fenced methods reject it as `invalid_event` rather than\n * degrading it into `fence_lost`, which would read as \"someone else owns this\n * run\" and send the caller looking for a race that never happened.\n *\n * `hostId` and `nonce` stay plain strings. An empty one is a legal value that\n * simply matches no persisted owner, which is exactly `fence_lost`.\n *\n * @since 0.1.0\n * @category models\n */\nexport const OwnerId = Schema.Struct({\n hostId: Schema.String,\n pid: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n nonce: Schema.String\n})\n\n/**\n * A process identity scoped to a host and a unique ownership nonce.\n *\n * @since 0.1.0\n * @category models\n */\nexport type OwnerId = typeof OwnerId.Type\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,aAAwB;AAiBjB,MAAM,UAAU,OAAO,OAAO;AAAA,EACnC,QAAQ,OAAO;AAAA,EACf,KAAK,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AAAA,EACtD,OAAO,OAAO;AAChB,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reproducible journal projections.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import type * as Effect from "effect/Effect";
|
|
7
|
+
import type { Entry } from "./JournalEvent.ts";
|
|
8
|
+
/**
|
|
9
|
+
* An effectful fold over committed journal entries.
|
|
10
|
+
*
|
|
11
|
+
* Projections have no independent durable state. Replaying the same entries
|
|
12
|
+
* through the same reducer must reproduce the same result.
|
|
13
|
+
*
|
|
14
|
+
* @category models
|
|
15
|
+
* @since 0.1.0
|
|
16
|
+
*/
|
|
17
|
+
export interface Projection<S, E = never, R = never> {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly initial: S;
|
|
20
|
+
readonly reduce: (state: S, entry: Entry) => Effect.Effect<S, E, R>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a reproducible journal projection.
|
|
24
|
+
*
|
|
25
|
+
* @category constructors
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
export declare const make: <S, E = never, R = never>(projection: Projection<S, E, R>) => Projection<S, E, R>;
|
|
29
|
+
//# sourceMappingURL=Projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Projection.d.ts","sourceRoot":"","sources":["../../src/Projection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CACpE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAe,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Projection_exports = {};
|
|
20
|
+
__export(Projection_exports, {
|
|
21
|
+
make: () => make
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Projection_exports);
|
|
24
|
+
const make = (projection) => projection;
|
|
25
|
+
//# sourceMappingURL=Projection.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Projection.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Reproducible journal projections.\n *\n * @since 0.1.0\n */\n\nimport type * as Effect from \"effect/Effect\"\nimport type { Entry } from \"./JournalEvent.ts\"\n\n/**\n * An effectful fold over committed journal entries.\n *\n * Projections have no independent durable state. Replaying the same entries\n * through the same reducer must reproduce the same result.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Projection<S, E = never, R = never> {\n readonly name: string\n readonly initial: S\n readonly reduce: (state: S, entry: Entry) => Effect.Effect<S, E, R>\n}\n\n/**\n * Constructs a reproducible journal projection.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = <S, E = never, R = never>(projection: Projection<S, E, R>): Projection<S, E, R> => projection\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,MAAM,OAAO,CAA0B,eAAyD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The redacting logger: the journal's redaction rules applied to log output.
|
|
3
|
+
*
|
|
4
|
+
* The journal redacts on the write path, so a credential a cell logs or
|
|
5
|
+
* returns never reaches a committed row (`./Redaction.ts`). The operator's
|
|
6
|
+
* terminal was the other place the same credential surfaces: every built-in
|
|
7
|
+
* Effect logger renders through the fiber's `Console`, so an action that hands
|
|
8
|
+
* a token to `Effect.logInfo` wrote it to stderr in full and it reached
|
|
9
|
+
* whatever collected that stream.
|
|
10
|
+
*
|
|
11
|
+
* This module closes that half with the SAME rules rather than a second rule
|
|
12
|
+
* set. {@link wrap} does not re-implement redaction and does not re-format a
|
|
13
|
+
* log line. It redacts the log event itself — the message, the cause, and the
|
|
14
|
+
* log annotations — before the wrapped logger is handed it, and it hands that
|
|
15
|
+
* logger a view of the fiber whose `Console` is a redacting console, so
|
|
16
|
+
* whatever the logger renders for itself — a pretty line, a JSON document —
|
|
17
|
+
* passes through `Redaction.redact` on its way to the stream as well.
|
|
18
|
+
*
|
|
19
|
+
* Both halves carry load. Most built-in loggers write through the fiber's
|
|
20
|
+
* `Console`, which is what covers the pretty line, the `--json` document, and
|
|
21
|
+
* the `.flows/logs/<runId>.log` stream. But a logger is free to read the event
|
|
22
|
+
* instead of rendering it, and one in Effect's own default logger set does:
|
|
23
|
+
* `Logger.tracerLogger` publishes the message as a span event name and
|
|
24
|
+
* `Cause.pretty` of the cause as the span's `effect.cause` attribute, and
|
|
25
|
+
* never reads `Console` at all. Redacting only the console would hide a
|
|
26
|
+
* credential on stderr and export it in clear to whatever OTLP collector is
|
|
27
|
+
* configured.
|
|
28
|
+
*
|
|
29
|
+
* Cost is bounded by the rules themselves: every alternation inside a
|
|
30
|
+
* repetition in `Redaction.diagnosticRules` starts its branches with disjoint
|
|
31
|
+
* characters, so each rule is linear in the length of the line and no input
|
|
32
|
+
* backtracks catastrophically.
|
|
33
|
+
*
|
|
34
|
+
* One deliberate difference from the journal write path. `Redaction.redact`
|
|
35
|
+
* rebuilds an object from its own enumerable entries, which is right for a row
|
|
36
|
+
* that is about to be JSON-encoded and wrong for a terminal: an `Error` keeps
|
|
37
|
+
* `message` and `stack` on non-enumerable properties, so rebuilding one prints
|
|
38
|
+
* `{}` where the operator expected a failure. An `Error` is rebuilt as a plain
|
|
39
|
+
* `Error` instead, carrying its name, message, stack and own members with the
|
|
40
|
+
* rules applied. Its class is NOT preserved. A copy built on the original's
|
|
41
|
+
* prototype inherits everything the prototype defines, an own-key walk sees
|
|
42
|
+
* none of it, and each of `name`, `cause`, `toJSON`, `Symbol.toStringTag` and
|
|
43
|
+
* `nodejs.util.inspect.custom` carried a credential out that way.
|
|
44
|
+
*
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
*/
|
|
47
|
+
import * as Console from "effect/Console";
|
|
48
|
+
import * as Layer from "effect/Layer";
|
|
49
|
+
import * as Logger from "effect/Logger";
|
|
50
|
+
import * as Redaction from "./Redaction.ts";
|
|
51
|
+
/**
|
|
52
|
+
* Marks a logger this module already wrapped.
|
|
53
|
+
*
|
|
54
|
+
* Both the CLI and the durable runtime install {@link layer}, and a detached
|
|
55
|
+
* `smithers run` is both at once. Wrapping twice would be correct but pay the
|
|
56
|
+
* rules twice per line, so a wrapped logger is returned unchanged.
|
|
57
|
+
*
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
* @category type ids
|
|
60
|
+
*/
|
|
61
|
+
export declare const TypeId: unique symbol;
|
|
62
|
+
/**
|
|
63
|
+
* Whether {@link wrap} already wrapped this logger.
|
|
64
|
+
*
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
* @category predicates
|
|
67
|
+
*/
|
|
68
|
+
export declare const isRedacted: (logger: Logger.Logger<any, any>) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Redacts one value on its way out of the logger.
|
|
71
|
+
*
|
|
72
|
+
* An `Error` is rebuilt as a plain `Error` whose name, message, stack and own
|
|
73
|
+
* members are redacted, so a renderer that special-cases an `Error` still gets
|
|
74
|
+
* one. Everything else goes through the journal's own rules, which rebuild a
|
|
75
|
+
* value from its plain data: a `Date`, a `Map`, a class instance or a host
|
|
76
|
+
* object therefore reaches the operator in that plain form rather than as
|
|
77
|
+
* itself.
|
|
78
|
+
*
|
|
79
|
+
* That collapse is deliberate, and it now covers the `Error` too. An earlier
|
|
80
|
+
* version rebuilt each value on its own prototype to keep the rendering
|
|
81
|
+
* faithful. Three rounds of review found three ways that could kill the run it
|
|
82
|
+
* was logging, because a host class keeps state a property walk cannot see and
|
|
83
|
+
* a copy of one throws the moment a brand check reads it, and four more found
|
|
84
|
+
* that the prototype an `Error` copy kept was itself the leak: everything it
|
|
85
|
+
* defines is read by a renderer and seen by no own-key walk. A log line is not
|
|
86
|
+
* worth a run, and the rendering it buys is cosmetic.
|
|
87
|
+
*
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
* @category redaction
|
|
90
|
+
*/
|
|
91
|
+
export declare const redactArgument: (value: unknown, redactor: Redaction.Redactor) => unknown;
|
|
92
|
+
/**
|
|
93
|
+
* A console that runs every value it is handed through `redactor` and then
|
|
94
|
+
* delegates to `target`.
|
|
95
|
+
*
|
|
96
|
+
* @since 0.1.0
|
|
97
|
+
* @category constructors
|
|
98
|
+
*/
|
|
99
|
+
export declare const redactingConsole: (target: Console.Console, redactor: Redaction.Redactor) => Console.Console;
|
|
100
|
+
/**
|
|
101
|
+
* Returns `logger` with the journal's redaction rules over everything it
|
|
102
|
+
* renders. A logger this module already wrapped is returned unchanged.
|
|
103
|
+
*
|
|
104
|
+
* @since 0.1.0
|
|
105
|
+
* @category combinators
|
|
106
|
+
*/
|
|
107
|
+
export declare const wrap: <Message, Output>(logger: Logger.Logger<Message, Output>, options?: Redaction.Options) => Logger.Logger<Message, Output>;
|
|
108
|
+
/**
|
|
109
|
+
* Replaces the active logger set with redacting wrappers of the same loggers.
|
|
110
|
+
*
|
|
111
|
+
* It composes over whatever loggers are already installed rather than
|
|
112
|
+
* choosing one, so an operator keeps the FORMAT they had, meaning their own
|
|
113
|
+
* logger and its layout, though a value inside a line is rendered from its
|
|
114
|
+
* redacted plain data rather than as its own class, and a host that
|
|
115
|
+
* installed its own logger keeps it too.
|
|
116
|
+
*
|
|
117
|
+
* @since 0.1.0
|
|
118
|
+
* @category layers
|
|
119
|
+
*/
|
|
120
|
+
export declare const layer: (options?: Redaction.Options) => Layer.Layer<never>;
|
|
121
|
+
//# sourceMappingURL=RedactedLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedactedLogger.d.ts","sourceRoot":"","sources":["../../src/RedactedLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAIzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,MAAqD,CAAA;AAEjF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,OAA2B,CAAA;AA2LxF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,UAAU,SAAS,CAAC,QAAQ,KAAG,OAW7E,CAAA;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,OAAO,CAAC,OAAO,EAAE,UAAU,SAAS,CAAC,QAAQ,KAAG,OAAO,CAAC,OA0BhG,CAAA;AAkFD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,GAAI,OAAO,EAAE,MAAM,EAClC,QAAQ,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,EACtC,UAAU,SAAS,CAAC,OAAO,KAC1B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAiC/B,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,GAAI,UAAU,SAAS,CAAC,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAUlE,CAAA"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var RedactedLogger_exports = {};
|
|
30
|
+
__export(RedactedLogger_exports, {
|
|
31
|
+
TypeId: () => TypeId,
|
|
32
|
+
isRedacted: () => isRedacted,
|
|
33
|
+
layer: () => layer,
|
|
34
|
+
redactArgument: () => redactArgument,
|
|
35
|
+
redactingConsole: () => redactingConsole,
|
|
36
|
+
wrap: () => wrap
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(RedactedLogger_exports);
|
|
39
|
+
var Cause = __toESM(require("effect/Cause"), 1);
|
|
40
|
+
var Console = __toESM(require("effect/Console"), 1);
|
|
41
|
+
var Context = __toESM(require("effect/Context"), 1);
|
|
42
|
+
var Effect = __toESM(require("effect/Effect"), 1);
|
|
43
|
+
var Layer = __toESM(require("effect/Layer"), 1);
|
|
44
|
+
var Logger = __toESM(require("effect/Logger"), 1);
|
|
45
|
+
var References = __toESM(require("effect/References"), 1);
|
|
46
|
+
var Redaction = __toESM(require("./Redaction.js"), 1);
|
|
47
|
+
const TypeId = /* @__PURE__ */ Symbol.for("@smthrs/journal/RedactedLogger");
|
|
48
|
+
const isRedacted = (logger) => TypeId in logger;
|
|
49
|
+
const consoleMethods = {
|
|
50
|
+
assert: true,
|
|
51
|
+
clear: false,
|
|
52
|
+
count: true,
|
|
53
|
+
countReset: true,
|
|
54
|
+
debug: true,
|
|
55
|
+
dir: true,
|
|
56
|
+
dirxml: true,
|
|
57
|
+
error: true,
|
|
58
|
+
group: true,
|
|
59
|
+
groupCollapsed: true,
|
|
60
|
+
groupEnd: false,
|
|
61
|
+
info: true,
|
|
62
|
+
log: true,
|
|
63
|
+
table: true,
|
|
64
|
+
time: true,
|
|
65
|
+
timeEnd: true,
|
|
66
|
+
timeLog: true,
|
|
67
|
+
trace: true,
|
|
68
|
+
warn: true
|
|
69
|
+
};
|
|
70
|
+
const renderDepthLimit = 200;
|
|
71
|
+
const renderDepthMarker = "[Deep]";
|
|
72
|
+
const toArray = (message) => Array.isArray(message) ? message : [message];
|
|
73
|
+
const redactedText = (read, redactor, fallback) => {
|
|
74
|
+
try {
|
|
75
|
+
return String(redactor(String(read())));
|
|
76
|
+
} catch {
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const redactedStack = (error, redactor) => {
|
|
81
|
+
try {
|
|
82
|
+
const stack = error.stack;
|
|
83
|
+
return typeof stack === "string" ? String(redactor(stack)) : void 0;
|
|
84
|
+
} catch {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const redactedName = (key, redactor) => {
|
|
89
|
+
const redacted = String(redactor(key));
|
|
90
|
+
return redacted === key ? key : Redaction.placeholder;
|
|
91
|
+
};
|
|
92
|
+
const renderHooks = /* @__PURE__ */ new Set([
|
|
93
|
+
"constructor",
|
|
94
|
+
"message",
|
|
95
|
+
"name",
|
|
96
|
+
"stack",
|
|
97
|
+
"toJSON",
|
|
98
|
+
"toString",
|
|
99
|
+
"valueOf"
|
|
100
|
+
]);
|
|
101
|
+
const redactError = (error, redactor, seen, depth = 0) => {
|
|
102
|
+
const memoized = seen.get(error);
|
|
103
|
+
if (memoized !== void 0) return memoized;
|
|
104
|
+
const clone = new Error();
|
|
105
|
+
seen.set(error, clone);
|
|
106
|
+
const define = (key, value, enumerable) => {
|
|
107
|
+
Object.defineProperty(clone, key, { value, writable: true, enumerable, configurable: true });
|
|
108
|
+
};
|
|
109
|
+
define("name", redactedText(() => error.name, redactor, "Error"), false);
|
|
110
|
+
define("message", redactedText(() => error.message, redactor, ""), false);
|
|
111
|
+
define("stack", redactedStack(error, redactor), false);
|
|
112
|
+
for (const key of Object.getOwnPropertyNames(error)) {
|
|
113
|
+
if (renderHooks.has(key)) continue;
|
|
114
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
115
|
+
const value = "value" in descriptor ? descriptor.value : error[key];
|
|
116
|
+
define(
|
|
117
|
+
redactedName(key, redactor),
|
|
118
|
+
// A credential-named member is replaced wholesale, the way the journal's
|
|
119
|
+
// own walk replaces one, so both halves of the one rule set answer alike.
|
|
120
|
+
Redaction.isSensitiveKey(key) ? Redaction.placeholder : depth + 1 >= renderDepthLimit ? renderDepthMarker : value instanceof Error ? redactError(value, redactor, seen, depth + 1) : redactor(value),
|
|
121
|
+
descriptor.enumerable === true
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return clone;
|
|
125
|
+
};
|
|
126
|
+
const redactArgument = (value, redactor) => {
|
|
127
|
+
try {
|
|
128
|
+
return value instanceof Error ? redactError(value, redactor, /* @__PURE__ */ new WeakMap()) : redactor(value);
|
|
129
|
+
} catch {
|
|
130
|
+
return unrenderableMarker;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const unrenderableMarker = "[Unrenderable]";
|
|
134
|
+
const redactingConsole = (target, redactor) => {
|
|
135
|
+
const methods = target;
|
|
136
|
+
const view = {};
|
|
137
|
+
for (const [name, redacts] of Object.entries(consoleMethods)) {
|
|
138
|
+
const method = methods[name].bind(target);
|
|
139
|
+
view[name] = redacts ? (...args) => {
|
|
140
|
+
const redacted = args.map((value) => redactArgument(value, redactor));
|
|
141
|
+
try {
|
|
142
|
+
return method(...redacted);
|
|
143
|
+
} catch {
|
|
144
|
+
try {
|
|
145
|
+
return method(...redacted.map(() => unrenderableMarker));
|
|
146
|
+
} catch {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} : method;
|
|
151
|
+
}
|
|
152
|
+
return view;
|
|
153
|
+
};
|
|
154
|
+
const redactedFiber = (fiber, redactor) => {
|
|
155
|
+
const view = Object.create(fiber);
|
|
156
|
+
Object.defineProperty(view, "getRef", {
|
|
157
|
+
value: (reference) => {
|
|
158
|
+
const current = fiber.getRef(reference);
|
|
159
|
+
if (reference === Console.Console) {
|
|
160
|
+
return redactingConsole(current, redactor);
|
|
161
|
+
}
|
|
162
|
+
if (reference === References.CurrentLogAnnotations) {
|
|
163
|
+
return redactArgument(current, redactor);
|
|
164
|
+
}
|
|
165
|
+
return current;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return view;
|
|
169
|
+
};
|
|
170
|
+
const redactedFrame = (frame, redactor, depth = 0) => {
|
|
171
|
+
if (frame === void 0) return void 0;
|
|
172
|
+
if (depth >= renderDepthLimit) {
|
|
173
|
+
return { name: renderDepthMarker, stack: () => void 0, parent: void 0 };
|
|
174
|
+
}
|
|
175
|
+
const stack = redactedText(() => frame.stack() ?? "", redactor, unrenderableMarker);
|
|
176
|
+
return {
|
|
177
|
+
name: redactedText(() => frame.name, redactor, unrenderableMarker),
|
|
178
|
+
stack: () => stack,
|
|
179
|
+
parent: redactedFrame(frame.parent, redactor, depth + 1)
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const redactedCause = (cause, redactor) => {
|
|
183
|
+
if (cause.reasons.length === 0) return cause;
|
|
184
|
+
return Cause.fromReasons(cause.reasons.map((reason) => {
|
|
185
|
+
const annotations = new Map(reason.annotations);
|
|
186
|
+
for (const key of [Cause.StackTrace.key, Cause.InterruptorStackTrace.key]) {
|
|
187
|
+
if (annotations.has(key)) {
|
|
188
|
+
annotations.set(key, redactedFrame(annotations.get(key), redactor));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const copy = reason._tag === "Fail" ? Cause.makeFailReason(redactArgument(reason.error, redactor)) : reason._tag === "Die" ? Cause.makeDieReason(redactArgument(reason.defect, redactor)) : Cause.makeInterruptReason(reason.fiberId);
|
|
192
|
+
return copy.annotate(Context.makeUnsafe(annotations));
|
|
193
|
+
}));
|
|
194
|
+
};
|
|
195
|
+
const wrap = (logger, options) => {
|
|
196
|
+
if (isRedacted(logger)) return logger;
|
|
197
|
+
const redactor = Redaction.make({ onTooDeep: "name", rules: Redaction.diagnosticRules, ...options });
|
|
198
|
+
const wrapped = Logger.make(
|
|
199
|
+
(logOptions) => logger.log({
|
|
200
|
+
...logOptions,
|
|
201
|
+
// The message is redacted here, not only behind the fiber's Console,
|
|
202
|
+
// because a logger is free to read it directly: `Logger.tracerLogger`
|
|
203
|
+
// ships in Effect's default set and publishes the message as a span
|
|
204
|
+
// event name, so a Console-only substitution would export a credential
|
|
205
|
+
// in clear to whatever collector is configured.
|
|
206
|
+
//
|
|
207
|
+
// Effect delivers the message as an array of parts, one per argument,
|
|
208
|
+
// including the single-argument case; a non-array reaches here only from
|
|
209
|
+
// a caller that builds `LogOptions` by hand, and `toArray` covers it
|
|
210
|
+
// without a branch no test could reach through the logging API.
|
|
211
|
+
message: toArray(logOptions.message).map((part) => redactArgument(part, redactor)),
|
|
212
|
+
// The cause travels the same way and for the same reason. A failure is
|
|
213
|
+
// logged as a `Cause`, not as message parts (`Effect.logError(cause)`
|
|
214
|
+
// moves it out of the arguments), and `Logger.tracerLogger` renders it
|
|
215
|
+
// itself into the span's `effect.cause` attribute without going near the
|
|
216
|
+
// console, so an error message carrying a token would leave the process
|
|
217
|
+
// in clear.
|
|
218
|
+
cause: redactedCause(logOptions.cause, redactor),
|
|
219
|
+
fiber: redactedFiber(logOptions.fiber, redactor)
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
Object.defineProperty(wrapped, TypeId, { value: true });
|
|
223
|
+
return wrapped;
|
|
224
|
+
};
|
|
225
|
+
const layer = (options) => Layer.effect(
|
|
226
|
+
Logger.CurrentLoggers,
|
|
227
|
+
Effect.withFiber(
|
|
228
|
+
(fiber) => Effect.sync(() => {
|
|
229
|
+
const wrapped = /* @__PURE__ */ new Set();
|
|
230
|
+
for (const logger of fiber.getRef(Logger.CurrentLoggers)) wrapped.add(wrap(logger, options));
|
|
231
|
+
return wrapped;
|
|
232
|
+
})
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
//# sourceMappingURL=RedactedLogger.js.map
|