@routier/core 0.4.0 → 0.6.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/index.cjs +88 -438
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +94 -443
- package/dist/index.js.map +1 -1
- package/dist/plugins/TelemetryDbPlugin.d.ts +43 -0
- package/dist/plugins/index.cjs +82 -1
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +88 -3
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/resultShape.d.ts +35 -0
- package/dist/transfer/ChunkEncoder.d.ts +60 -0
- package/dist/transfer/decoder.d.ts +29 -0
- package/dist/transfer/fillers.d.ts +36 -0
- package/dist/transfer/index.cjs +873 -0
- package/dist/transfer/index.cjs.map +1 -0
- package/dist/transfer/index.d.ts +47 -0
- package/dist/transfer/index.js +872 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/transfer/plan.d.ts +94 -0
- package/dist/transfer/types.d.ts +138 -0
- package/package.json +9 -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),
|
|
@@ -3066,6 +3067,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3066
3067
|
executeJoin: () => (/* reexport */ executeJoin),
|
|
3067
3068
|
formatExplanation: () => (/* reexport */ formatExplanation),
|
|
3068
3069
|
serializePersistResult: () => (/* reexport */ serializePersistResult),
|
|
3070
|
+
mappedResultColumns: () => (/* reexport */ mappedResultColumns),
|
|
3069
3071
|
explainQuery: () => (/* reexport */ explainQuery),
|
|
3070
3072
|
cosineDistance: () => (/* reexport */ cosineDistance),
|
|
3071
3073
|
RetryDbPlugin: () => (/* reexport */ RetryDbPlugin),
|
|
@@ -3080,16 +3082,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3080
3082
|
EXECUTED_QUERIES_UNSUPPORTED: () => (/* reexport */ EXECUTED_QUERIES_UNSUPPORTED),
|
|
3081
3083
|
joinInPlugin: () => (/* reexport */ joinInPlugin),
|
|
3082
3084
|
deserializePersistResult: () => (/* reexport */ deserializePersistResult),
|
|
3085
|
+
loggerSink: () => (/* reexport */ loggerSink),
|
|
3083
3086
|
nearestBy: () => (/* reexport */ nearestBy),
|
|
3084
3087
|
readJoinKey: () => (/* reexport */ readJoinKey),
|
|
3085
|
-
serializeBulkPersist: () => (/* reexport */ serializeBulkPersist),
|
|
3086
3088
|
hashJoin: () => (/* reexport */ hashJoin),
|
|
3087
3089
|
EphemeralDataPlugin: () => (/* reexport */ EphemeralDataPlugin),
|
|
3088
3090
|
QueryOptionsCollection: () => (/* reexport */ QueryOptionsCollection/* .QueryOptionsCollection */.H),
|
|
3091
|
+
serializeBulkPersist: () => (/* reexport */ serializeBulkPersist),
|
|
3089
3092
|
toEntityShape: () => (/* reexport */ toEntityShape),
|
|
3090
3093
|
loadJoinInnerSide: () => (/* reexport */ loadJoinInnerSide),
|
|
3091
3094
|
DataTranslator: () => (/* reexport */ DataTranslator),
|
|
3092
3095
|
withExecutedQueries: () => (/* reexport */ withExecutedQueries),
|
|
3096
|
+
TelemetryDbPlugin: () => (/* reexport */ TelemetryDbPlugin),
|
|
3093
3097
|
createRequestHandler: () => (/* reexport */ createRequestHandler),
|
|
3094
3098
|
SqlTranslator: () => (/* reexport */ SqlTranslator),
|
|
3095
3099
|
QueryOrdering: () => (/* reexport */ types_QueryOrdering),
|
|
@@ -3099,6 +3103,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3099
3103
|
deserializeQueryOptions: () => (/* reexport */ deserializeQueryOptions)
|
|
3100
3104
|
});
|
|
3101
3105
|
|
|
3106
|
+
;// CONCATENATED MODULE: ./src/plugins/resultShape.ts
|
|
3107
|
+
/**
|
|
3108
|
+
* The columns a `map` projection selects.
|
|
3109
|
+
*
|
|
3110
|
+
* Named by `sourceName`, which is what the statement actually emits; the rename to
|
|
3111
|
+
* `destinationName` happens in the translator, after the rows come back. A field with no
|
|
3112
|
+
* `property` is an expression.
|
|
3113
|
+
*/ const mappedResultColumns = (fields)=>fields.map((field)=>({
|
|
3114
|
+
name: field.sourceName,
|
|
3115
|
+
property: field.property ?? null
|
|
3116
|
+
}));
|
|
3117
|
+
|
|
3102
3118
|
;// CONCATENATED MODULE: ./src/plugins/translators/TranslatedArrayValue.ts
|
|
3103
3119
|
class TranslatedArrayValue {
|
|
3104
3120
|
value;
|
|
@@ -6080,6 +6096,69 @@ class RetryDbPlugin {
|
|
|
6080
6096
|
}
|
|
6081
6097
|
}
|
|
6082
6098
|
|
|
6099
|
+
;// CONCATENATED MODULE: ./src/plugins/TelemetryDbPlugin.ts
|
|
6100
|
+
|
|
6101
|
+
/** Default sink: writes through the levelled logger, so ROUTIER_LOG_LEVEL governs it. */ const loggerSink = ()=>(e)=>{
|
|
6102
|
+
const line = `[routier] ${e.operation} ${e.schemas.join(",")} ${e.durationMs.toFixed(1)}ms`;
|
|
6103
|
+
if (e.ok === "error") {
|
|
6104
|
+
logger/* .logger.error */.vF.error(line, e.error);
|
|
6105
|
+
return;
|
|
6106
|
+
}
|
|
6107
|
+
logger/* .logger.info */.vF.info(line);
|
|
6108
|
+
};
|
|
6109
|
+
/** Pushes every event into `into`. For tests and custom buffering. */ const collectingSink = (into)=>(e)=>{
|
|
6110
|
+
into.push(e);
|
|
6111
|
+
};
|
|
6112
|
+
class TelemetryDbPlugin {
|
|
6113
|
+
plugin;
|
|
6114
|
+
onEvent;
|
|
6115
|
+
constructor(plugin, options = {}){
|
|
6116
|
+
this.plugin = plugin;
|
|
6117
|
+
this.onEvent = options.onEvent ?? loggerSink();
|
|
6118
|
+
}
|
|
6119
|
+
get databaseName() {
|
|
6120
|
+
return this.plugin.databaseName;
|
|
6121
|
+
}
|
|
6122
|
+
query(event, done) {
|
|
6123
|
+
const start = performance.now();
|
|
6124
|
+
this.plugin.query(event, (result)=>{
|
|
6125
|
+
this.emit("query", event, result, start);
|
|
6126
|
+
done(result);
|
|
6127
|
+
});
|
|
6128
|
+
}
|
|
6129
|
+
bulkPersist(event, done) {
|
|
6130
|
+
const start = performance.now();
|
|
6131
|
+
this.plugin.bulkPersist(event, (result)=>{
|
|
6132
|
+
this.emit("bulkPersist", event, result, start);
|
|
6133
|
+
done(result);
|
|
6134
|
+
});
|
|
6135
|
+
}
|
|
6136
|
+
destroy(event, done) {
|
|
6137
|
+
const start = performance.now();
|
|
6138
|
+
this.plugin.destroy(event, (result)=>{
|
|
6139
|
+
this.emit("destroy", event, result, start);
|
|
6140
|
+
done(result);
|
|
6141
|
+
});
|
|
6142
|
+
}
|
|
6143
|
+
emit(operation, event, result, start) {
|
|
6144
|
+
try {
|
|
6145
|
+
this.onEvent({
|
|
6146
|
+
operation,
|
|
6147
|
+
eventId: event.id,
|
|
6148
|
+
source: event.source,
|
|
6149
|
+
schemas: [
|
|
6150
|
+
...event.schemas.values()
|
|
6151
|
+
].map((s)=>s.collectionName),
|
|
6152
|
+
durationMs: performance.now() - start,
|
|
6153
|
+
ok: result.ok,
|
|
6154
|
+
error: result.ok === "success" ? undefined : result.error
|
|
6155
|
+
});
|
|
6156
|
+
} catch {
|
|
6157
|
+
// A broken sink must never fail the data operation.
|
|
6158
|
+
}
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
|
|
6083
6162
|
;// CONCATENATED MODULE: ./src/plugins/CacheDbPlugin.ts
|
|
6084
6163
|
|
|
6085
6164
|
/**
|
|
@@ -6543,6 +6622,8 @@ const DEFAULT_MAX_BATCH_SIZE = 100;
|
|
|
6543
6622
|
|
|
6544
6623
|
|
|
6545
6624
|
|
|
6625
|
+
|
|
6626
|
+
|
|
6546
6627
|
})();
|
|
6547
6628
|
|
|
6548
6629
|
module.exports = __webpack_exports__;
|