@routier/core 0.4.0 → 0.5.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/dist/index.cjs +73 -438
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +78 -443
- package/dist/index.js.map +1 -1
- package/dist/plugins/TelemetryDbPlugin.d.ts +43 -0
- package/dist/plugins/index.cjs +68 -1
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +73 -3
- package/dist/plugins/index.js.map +1 -1
- package/package.json +1 -9
- package/dist/capabilities/Capability.d.ts +0 -11
- package/dist/capabilities/PerformanceCapability.d.ts +0 -13
- package/dist/capabilities/TracingCapability.d.ts +0 -11
- package/dist/capabilities/index.cjs +0 -820
- package/dist/capabilities/index.cjs.map +0 -1
- package/dist/capabilities/index.d.ts +0 -4
- package/dist/capabilities/index.js +0 -808
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/performance/PerformanceTracker.d.ts +0 -11
- package/dist/capabilities/tracing/CallTraceManager.d.ts +0 -12
- package/dist/capabilities/types.d.ts +0 -17
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BulkPersistResult } from "../collections";
|
|
2
|
+
import { PluginEventCallbackPartialResult, PluginEventCallbackResult } from "../results";
|
|
3
|
+
import { ITranslatedValue } from "./translators";
|
|
4
|
+
import { DbPluginBulkPersistEvent, DbPluginEvent, DbPluginQueryEvent, IDbPlugin } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Measures every operation an inner plugin performs and hands one event per call to a sink.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const store = new MyStore(new TelemetryDbPlugin(new SomeDbPlugin(...)));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type TelemetryEvent = {
|
|
13
|
+
operation: "query" | "bulkPersist" | "destroy";
|
|
14
|
+
/** `id` of the plugin event that produced this measurement. */
|
|
15
|
+
eventId: string;
|
|
16
|
+
/** The class/component that triggered the operation (`event.source`). */
|
|
17
|
+
source: string;
|
|
18
|
+
/** Collection names involved, from `event.schemas`. */
|
|
19
|
+
schemas: string[];
|
|
20
|
+
durationMs: number;
|
|
21
|
+
ok: "success" | "partial" | "error";
|
|
22
|
+
/** Present when ok is "error" or "partial". */
|
|
23
|
+
error?: unknown;
|
|
24
|
+
};
|
|
25
|
+
export type TelemetrySink = (e: TelemetryEvent) => void;
|
|
26
|
+
export type TelemetryDbPluginOptions = {
|
|
27
|
+
/** Where events go. Default: `loggerSink()`. */
|
|
28
|
+
onEvent?: TelemetrySink;
|
|
29
|
+
};
|
|
30
|
+
/** Default sink: writes through the levelled logger, so ROUTIER_LOG_LEVEL governs it. */
|
|
31
|
+
export declare const loggerSink: () => TelemetrySink;
|
|
32
|
+
/** Pushes every event into `into`. For tests and custom buffering. */
|
|
33
|
+
export declare const collectingSink: (into: TelemetryEvent[]) => TelemetrySink;
|
|
34
|
+
export declare class TelemetryDbPlugin implements IDbPlugin {
|
|
35
|
+
private readonly plugin;
|
|
36
|
+
private readonly onEvent;
|
|
37
|
+
constructor(plugin: IDbPlugin, options?: TelemetryDbPluginOptions);
|
|
38
|
+
get databaseName(): string;
|
|
39
|
+
query<TRoot extends {}, TShape extends any = TRoot>(event: DbPluginQueryEvent<TRoot, TShape>, done: PluginEventCallbackResult<ITranslatedValue<TShape>>): void;
|
|
40
|
+
bulkPersist(event: DbPluginBulkPersistEvent, done: PluginEventCallbackPartialResult<BulkPersistResult>): void;
|
|
41
|
+
destroy(event: DbPluginEvent, done: PluginEventCallbackResult<never>): void;
|
|
42
|
+
private emit;
|
|
43
|
+
}
|
package/dist/plugins/index.cjs
CHANGED
|
@@ -3059,6 +3059,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3059
3059
|
__webpack_require__.d(__webpack_exports__, {
|
|
3060
3060
|
DEFAULT_SEMI_JOIN_KEY_THRESHOLD: () => (/* reexport */ DEFAULT_SEMI_JOIN_KEY_THRESHOLD),
|
|
3061
3061
|
TranslatedArrayValue: () => (/* reexport */ TranslatedArrayValue),
|
|
3062
|
+
collectingSink: () => (/* reexport */ collectingSink),
|
|
3062
3063
|
semiJoinFilter: () => (/* reexport */ semiJoinFilter),
|
|
3063
3064
|
CacheDbPlugin: () => (/* reexport */ CacheDbPlugin),
|
|
3064
3065
|
Query: () => (/* reexport */ Query),
|
|
@@ -3080,16 +3081,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3080
3081
|
EXECUTED_QUERIES_UNSUPPORTED: () => (/* reexport */ EXECUTED_QUERIES_UNSUPPORTED),
|
|
3081
3082
|
joinInPlugin: () => (/* reexport */ joinInPlugin),
|
|
3082
3083
|
deserializePersistResult: () => (/* reexport */ deserializePersistResult),
|
|
3084
|
+
loggerSink: () => (/* reexport */ loggerSink),
|
|
3083
3085
|
nearestBy: () => (/* reexport */ nearestBy),
|
|
3084
3086
|
readJoinKey: () => (/* reexport */ readJoinKey),
|
|
3085
|
-
serializeBulkPersist: () => (/* reexport */ serializeBulkPersist),
|
|
3086
3087
|
hashJoin: () => (/* reexport */ hashJoin),
|
|
3087
3088
|
EphemeralDataPlugin: () => (/* reexport */ EphemeralDataPlugin),
|
|
3088
3089
|
QueryOptionsCollection: () => (/* reexport */ QueryOptionsCollection/* .QueryOptionsCollection */.H),
|
|
3090
|
+
serializeBulkPersist: () => (/* reexport */ serializeBulkPersist),
|
|
3089
3091
|
toEntityShape: () => (/* reexport */ toEntityShape),
|
|
3090
3092
|
loadJoinInnerSide: () => (/* reexport */ loadJoinInnerSide),
|
|
3091
3093
|
DataTranslator: () => (/* reexport */ DataTranslator),
|
|
3092
3094
|
withExecutedQueries: () => (/* reexport */ withExecutedQueries),
|
|
3095
|
+
TelemetryDbPlugin: () => (/* reexport */ TelemetryDbPlugin),
|
|
3093
3096
|
createRequestHandler: () => (/* reexport */ createRequestHandler),
|
|
3094
3097
|
SqlTranslator: () => (/* reexport */ SqlTranslator),
|
|
3095
3098
|
QueryOrdering: () => (/* reexport */ types_QueryOrdering),
|
|
@@ -6080,6 +6083,69 @@ class RetryDbPlugin {
|
|
|
6080
6083
|
}
|
|
6081
6084
|
}
|
|
6082
6085
|
|
|
6086
|
+
;// CONCATENATED MODULE: ./src/plugins/TelemetryDbPlugin.ts
|
|
6087
|
+
|
|
6088
|
+
/** Default sink: writes through the levelled logger, so ROUTIER_LOG_LEVEL governs it. */ const loggerSink = ()=>(e)=>{
|
|
6089
|
+
const line = `[routier] ${e.operation} ${e.schemas.join(",")} ${e.durationMs.toFixed(1)}ms`;
|
|
6090
|
+
if (e.ok === "error") {
|
|
6091
|
+
logger/* .logger.error */.vF.error(line, e.error);
|
|
6092
|
+
return;
|
|
6093
|
+
}
|
|
6094
|
+
logger/* .logger.info */.vF.info(line);
|
|
6095
|
+
};
|
|
6096
|
+
/** Pushes every event into `into`. For tests and custom buffering. */ const collectingSink = (into)=>(e)=>{
|
|
6097
|
+
into.push(e);
|
|
6098
|
+
};
|
|
6099
|
+
class TelemetryDbPlugin {
|
|
6100
|
+
plugin;
|
|
6101
|
+
onEvent;
|
|
6102
|
+
constructor(plugin, options = {}){
|
|
6103
|
+
this.plugin = plugin;
|
|
6104
|
+
this.onEvent = options.onEvent ?? loggerSink();
|
|
6105
|
+
}
|
|
6106
|
+
get databaseName() {
|
|
6107
|
+
return this.plugin.databaseName;
|
|
6108
|
+
}
|
|
6109
|
+
query(event, done) {
|
|
6110
|
+
const start = performance.now();
|
|
6111
|
+
this.plugin.query(event, (result)=>{
|
|
6112
|
+
this.emit("query", event, result, start);
|
|
6113
|
+
done(result);
|
|
6114
|
+
});
|
|
6115
|
+
}
|
|
6116
|
+
bulkPersist(event, done) {
|
|
6117
|
+
const start = performance.now();
|
|
6118
|
+
this.plugin.bulkPersist(event, (result)=>{
|
|
6119
|
+
this.emit("bulkPersist", event, result, start);
|
|
6120
|
+
done(result);
|
|
6121
|
+
});
|
|
6122
|
+
}
|
|
6123
|
+
destroy(event, done) {
|
|
6124
|
+
const start = performance.now();
|
|
6125
|
+
this.plugin.destroy(event, (result)=>{
|
|
6126
|
+
this.emit("destroy", event, result, start);
|
|
6127
|
+
done(result);
|
|
6128
|
+
});
|
|
6129
|
+
}
|
|
6130
|
+
emit(operation, event, result, start) {
|
|
6131
|
+
try {
|
|
6132
|
+
this.onEvent({
|
|
6133
|
+
operation,
|
|
6134
|
+
eventId: event.id,
|
|
6135
|
+
source: event.source,
|
|
6136
|
+
schemas: [
|
|
6137
|
+
...event.schemas.values()
|
|
6138
|
+
].map((s)=>s.collectionName),
|
|
6139
|
+
durationMs: performance.now() - start,
|
|
6140
|
+
ok: result.ok,
|
|
6141
|
+
error: result.ok === "success" ? undefined : result.error
|
|
6142
|
+
});
|
|
6143
|
+
} catch {
|
|
6144
|
+
// A broken sink must never fail the data operation.
|
|
6145
|
+
}
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
|
|
6083
6149
|
;// CONCATENATED MODULE: ./src/plugins/CacheDbPlugin.ts
|
|
6084
6150
|
|
|
6085
6151
|
/**
|
|
@@ -6543,6 +6609,7 @@ const DEFAULT_MAX_BATCH_SIZE = 100;
|
|
|
6543
6609
|
|
|
6544
6610
|
|
|
6545
6611
|
|
|
6612
|
+
|
|
6546
6613
|
})();
|
|
6547
6614
|
|
|
6548
6615
|
module.exports = __webpack_exports__;
|