@reifydb/core 0.9.0 → 0.9.2
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.d.ts +244 -53
- package/dist/index.js +1181 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
declare const NONE_VALUE = "\u27EAnone\u27EB";
|
|
2
|
+
declare function noneMarker(depth: number): string;
|
|
3
|
+
declare function noneMarkerDepth(payload: string): number | undefined;
|
|
4
|
+
declare const ROW_NUMBER_KEY = "#rownum";
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* A binary large object (BLOB) value that can hold arbitrary byte data.
|
|
@@ -288,7 +291,7 @@ declare class DateTimeValue implements Value {
|
|
|
288
291
|
/**
|
|
289
292
|
* Get Unix timestamp in seconds
|
|
290
293
|
*/
|
|
291
|
-
|
|
294
|
+
toEpochSecs(): number | undefined;
|
|
292
295
|
/**
|
|
293
296
|
* Get Unix timestamp in nanoseconds
|
|
294
297
|
*/
|
|
@@ -708,9 +711,9 @@ declare class Uint16Value implements Value {
|
|
|
708
711
|
|
|
709
712
|
declare class NoneValue implements Value {
|
|
710
713
|
readonly type: Type;
|
|
711
|
-
readonly innerType:
|
|
712
|
-
constructor(innerType?:
|
|
713
|
-
static parse(str: string, innerType?:
|
|
714
|
+
readonly innerType: Type;
|
|
715
|
+
constructor(innerType?: Type);
|
|
716
|
+
static parse(str: string, innerType?: Type): NoneValue;
|
|
714
717
|
isNone(): boolean;
|
|
715
718
|
toString(): string;
|
|
716
719
|
valueOf(): undefined;
|
|
@@ -720,6 +723,25 @@ declare class NoneValue implements Value {
|
|
|
720
723
|
toJSON(): null;
|
|
721
724
|
encode(): TypeValuePair;
|
|
722
725
|
}
|
|
726
|
+
declare function noneDepth(v: NoneValue): number;
|
|
727
|
+
|
|
728
|
+
declare const OPTION_BRAND: unique symbol;
|
|
729
|
+
declare function isOption(value: unknown): value is Option<unknown>;
|
|
730
|
+
declare class Option<T> {
|
|
731
|
+
private readonly state;
|
|
732
|
+
readonly [OPTION_BRAND] = true;
|
|
733
|
+
private constructor();
|
|
734
|
+
static some<T>(value: T): Option<T>;
|
|
735
|
+
static none<T = never>(inner: Type): Option<T>;
|
|
736
|
+
isSome(): boolean;
|
|
737
|
+
isNone(): boolean;
|
|
738
|
+
unwrap(): T;
|
|
739
|
+
unwrapOr(fallback: T): T;
|
|
740
|
+
map<U>(fn: (value: T) => U): Option<U>;
|
|
741
|
+
get type(): OptionType;
|
|
742
|
+
toString(): string;
|
|
743
|
+
toJSON(): unknown;
|
|
744
|
+
}
|
|
723
745
|
|
|
724
746
|
declare class Utf8Value implements Value {
|
|
725
747
|
readonly type: Type;
|
|
@@ -912,6 +934,45 @@ declare class IdentityIdValue implements Value {
|
|
|
912
934
|
encode(): TypeValuePair;
|
|
913
935
|
}
|
|
914
936
|
|
|
937
|
+
/**
|
|
938
|
+
* The wire rendering of a type: an object whose `id` names it, with anything it wraps under `underlying`.
|
|
939
|
+
*
|
|
940
|
+
* The client keeps its own representation, where a base type is the bare string it switches on. These two
|
|
941
|
+
* functions are the only crossing between the two, so a wire descriptor never reaches code that expects
|
|
942
|
+
* `{Option: ...}` and a client type never reaches the server expecting `{id, underlying}`.
|
|
943
|
+
*/
|
|
944
|
+
interface WireType {
|
|
945
|
+
id: string;
|
|
946
|
+
underlying?: WireType;
|
|
947
|
+
}
|
|
948
|
+
declare function typeToWire(type: Type): WireType;
|
|
949
|
+
declare function typeFromWire(wire: WireType): Type;
|
|
950
|
+
/** Reads the column types of a frames payload, leaving the rest of the frame untouched. */
|
|
951
|
+
declare function columnsFromWire<T extends {
|
|
952
|
+
type: any;
|
|
953
|
+
}>(columns: T[]): T[];
|
|
954
|
+
declare function framesFromWire(frames: any[]): any[];
|
|
955
|
+
/**
|
|
956
|
+
* Reads a `format=json` frame envelope into the column shape the decoder works on.
|
|
957
|
+
*
|
|
958
|
+
* The rows carry one value per column and the envelope's `types` says what each column is, so the two
|
|
959
|
+
* together hold everything the frames format carries. Turning them back into columns lets the JSON
|
|
960
|
+
* transports run the same decode and the same shape check as every other transport, instead of handing
|
|
961
|
+
* the caller whatever JSON happened to arrive.
|
|
962
|
+
*/
|
|
963
|
+
declare function envelopeToColumns(envelope: any): {
|
|
964
|
+
name: string;
|
|
965
|
+
type: Type;
|
|
966
|
+
payload: string[];
|
|
967
|
+
}[];
|
|
968
|
+
declare function envelopesToFrames(envelopes: any): {
|
|
969
|
+
columns: {
|
|
970
|
+
name: string;
|
|
971
|
+
type: Type;
|
|
972
|
+
payload: string[];
|
|
973
|
+
}[];
|
|
974
|
+
}[];
|
|
975
|
+
|
|
915
976
|
type BaseType = "Blob" | "Boolean" | "Decimal" | "Float4" | "Float8" | "Int1" | "Int2" | "Int4" | "Int8" | "Int16" | "Uint1" | "Uint2" | "Uint4" | "Uint8" | "Uint16" | "Utf8" | "Date" | "DateTime" | "Time" | "Duration" | "Uuid4" | "Uuid7" | "IdentityId" | "None";
|
|
916
977
|
interface OptionType {
|
|
917
978
|
Option: Type;
|
|
@@ -919,6 +980,8 @@ interface OptionType {
|
|
|
919
980
|
type Type = BaseType | OptionType;
|
|
920
981
|
declare function isOptionType(t: Type): t is OptionType;
|
|
921
982
|
declare function unwrapOptionType(t: Type): BaseType;
|
|
983
|
+
declare function optionDepth(t: Type): number;
|
|
984
|
+
declare function innerOfOption(t: OptionType): Type;
|
|
922
985
|
interface TypeValuePair {
|
|
923
986
|
type: Type;
|
|
924
987
|
value: string;
|
|
@@ -929,50 +992,64 @@ declare abstract class Value {
|
|
|
929
992
|
abstract equals(other: Value): boolean;
|
|
930
993
|
}
|
|
931
994
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
995
|
+
interface PrimitiveTSMap {
|
|
996
|
+
Blob: Uint8Array;
|
|
997
|
+
Boolean: boolean;
|
|
998
|
+
Decimal: string;
|
|
999
|
+
Float4: number;
|
|
1000
|
+
Float8: number;
|
|
1001
|
+
Int1: number;
|
|
1002
|
+
Int2: number;
|
|
1003
|
+
Int4: number;
|
|
1004
|
+
Int8: bigint;
|
|
1005
|
+
Int16: bigint;
|
|
1006
|
+
Uint1: number;
|
|
1007
|
+
Uint2: number;
|
|
1008
|
+
Uint4: number;
|
|
1009
|
+
Uint8: bigint;
|
|
1010
|
+
Uint16: bigint;
|
|
1011
|
+
Utf8: string;
|
|
1012
|
+
Date: Date;
|
|
1013
|
+
DateTime: Date;
|
|
1014
|
+
Time: string;
|
|
1015
|
+
Duration: string;
|
|
1016
|
+
Uuid4: string;
|
|
1017
|
+
Uuid7: string;
|
|
1018
|
+
None: undefined;
|
|
1019
|
+
IdentityId: string;
|
|
1020
|
+
}
|
|
1021
|
+
interface PrimitiveValueMap {
|
|
1022
|
+
Blob: BlobValue;
|
|
1023
|
+
Boolean: BooleanValue;
|
|
1024
|
+
Decimal: DecimalValue;
|
|
1025
|
+
Float4: Float4Value;
|
|
1026
|
+
Float8: Float8Value;
|
|
1027
|
+
Int1: Int1Value;
|
|
1028
|
+
Int2: Int2Value;
|
|
1029
|
+
Int4: Int4Value;
|
|
1030
|
+
Int8: Int8Value;
|
|
1031
|
+
Int16: Int16Value;
|
|
1032
|
+
Uint1: Uint1Value;
|
|
1033
|
+
Uint2: Uint2Value;
|
|
1034
|
+
Uint4: Uint4Value;
|
|
1035
|
+
Uint8: Uint8Value;
|
|
1036
|
+
Uint16: Uint16Value;
|
|
1037
|
+
Utf8: Utf8Value;
|
|
1038
|
+
Date: DateValue;
|
|
1039
|
+
DateTime: DateTimeValue;
|
|
1040
|
+
Time: TimeValue;
|
|
1041
|
+
Duration: DurationValue;
|
|
1042
|
+
Uuid4: Uuid4Value;
|
|
1043
|
+
Uuid7: Uuid7Value;
|
|
1044
|
+
None: NoneValue;
|
|
1045
|
+
IdentityId: IdentityIdValue;
|
|
1046
|
+
}
|
|
1047
|
+
type PrimitiveToTS<T extends BaseType> = PrimitiveTSMap[T];
|
|
1048
|
+
type PrimitiveToValue<T extends BaseType> = PrimitiveValueMap[T];
|
|
1049
|
+
type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
|
|
973
1050
|
type InferShape<S> = S extends PrimitiveShapeNode<infer T> ? T extends BaseType ? PrimitiveToTS<T> : never : S extends ValueShapeNode<infer T> ? T extends BaseType ? PrimitiveToValue<T> : never : S extends ObjectShapeNode<infer P> ? {
|
|
974
|
-
[K in keyof P]: InferShape<P[K]>;
|
|
975
|
-
} : S extends ArrayShapeNode<infer T> ? InferShape<T>[] : S extends
|
|
1051
|
+
[K in keyof P as CamelCase<K & string>]: InferShape<P[K]>;
|
|
1052
|
+
} : S extends ArrayShapeNode<infer T> ? InferShape<T>[] : S extends OptionShapeNode<infer T> ? Option<InferShape<T>> : never;
|
|
976
1053
|
type InferShapes<S extends readonly ShapeNode[]> = {
|
|
977
1054
|
[K in keyof S]: InferShape<S[K]>[];
|
|
978
1055
|
};
|
|
@@ -1011,7 +1088,7 @@ declare class ShapeBuilder {
|
|
|
1011
1088
|
static identityid(): PrimitiveShapeNode<'IdentityId'>;
|
|
1012
1089
|
static object<P extends Record<string, ShapeNode>>(properties: P): ObjectShapeNode<P>;
|
|
1013
1090
|
static array<T extends ShapeNode>(items: T): ArrayShapeNode<T>;
|
|
1014
|
-
static
|
|
1091
|
+
static option<T extends ShapeNode>(inner: T): OptionShapeNode<T>;
|
|
1015
1092
|
static number(): PrimitiveShapeNode<'Float8'>;
|
|
1016
1093
|
static booleanValue(): ValueShapeNode<'Boolean'>;
|
|
1017
1094
|
static decimalValue(): ValueShapeNode<'Decimal'>;
|
|
@@ -1044,6 +1121,15 @@ declare function parseValue(shape: ShapeNode, value: any): any;
|
|
|
1044
1121
|
|
|
1045
1122
|
declare function validateShape(shape: ShapeNode, value: any): boolean;
|
|
1046
1123
|
|
|
1124
|
+
declare function transformFrames<const S extends readonly ShapeNode[]>(frames: any[][], shapes: S): FrameResults<S>;
|
|
1125
|
+
declare function transformResult(row: any, resultShape: any): any;
|
|
1126
|
+
|
|
1127
|
+
declare class ShapeMismatch extends Error {
|
|
1128
|
+
constructor(message: string);
|
|
1129
|
+
}
|
|
1130
|
+
declare function checkFrames(frames: Frame[], shapes: readonly ShapeNode[]): void;
|
|
1131
|
+
declare function checkFrame(columns: Column[], shape: ShapeNode): void;
|
|
1132
|
+
|
|
1047
1133
|
interface PrimitiveShapeNode<T extends string = string> {
|
|
1048
1134
|
kind: 'primitive';
|
|
1049
1135
|
type: T;
|
|
@@ -1056,15 +1142,15 @@ interface ArrayShapeNode<T extends ShapeNode = ShapeNode> {
|
|
|
1056
1142
|
kind: 'array';
|
|
1057
1143
|
items: T;
|
|
1058
1144
|
}
|
|
1059
|
-
interface
|
|
1060
|
-
kind: '
|
|
1061
|
-
|
|
1145
|
+
interface OptionShapeNode<T extends ShapeNode = ShapeNode> {
|
|
1146
|
+
kind: 'option';
|
|
1147
|
+
inner: T;
|
|
1062
1148
|
}
|
|
1063
1149
|
interface ValueShapeNode<T extends string = string> {
|
|
1064
1150
|
kind: 'value';
|
|
1065
1151
|
type: T;
|
|
1066
1152
|
}
|
|
1067
|
-
type ShapeNode = PrimitiveShapeNode | ObjectShapeNode | ArrayShapeNode |
|
|
1153
|
+
type ShapeNode = PrimitiveShapeNode | ObjectShapeNode | ArrayShapeNode | OptionShapeNode | ValueShapeNode;
|
|
1068
1154
|
|
|
1069
1155
|
type Params = (TypeValuePair | null)[] | Record<string, TypeValuePair | null>;
|
|
1070
1156
|
interface Frame {
|
|
@@ -1128,4 +1214,109 @@ type SingleFrameResult<S extends ShapeNode> = InferShape<S>[];
|
|
|
1128
1214
|
*/
|
|
1129
1215
|
declare function asFrameResults<S extends readonly ShapeNode[]>(results: any): FrameResults<S>;
|
|
1130
1216
|
|
|
1131
|
-
|
|
1217
|
+
declare function decode(pair: TypeValuePair): Value;
|
|
1218
|
+
declare function columnsToRows(columns: Column[]): Record<string, Value>[];
|
|
1219
|
+
|
|
1220
|
+
declare function encodeValue(value: any, name?: string): TypeValuePair;
|
|
1221
|
+
/** A parameter as it goes on the wire: the same value, with the type in the wire's own rendering. */
|
|
1222
|
+
interface WireValue {
|
|
1223
|
+
type: WireType;
|
|
1224
|
+
value: string;
|
|
1225
|
+
}
|
|
1226
|
+
declare function encodeParams(params: any): WireValue[] | Record<string, WireValue>;
|
|
1227
|
+
|
|
1228
|
+
declare const TYPE_CODE: {
|
|
1229
|
+
readonly None: 0;
|
|
1230
|
+
readonly Boolean: 1;
|
|
1231
|
+
readonly Float4: 2;
|
|
1232
|
+
readonly Float8: 3;
|
|
1233
|
+
readonly Int1: 4;
|
|
1234
|
+
readonly Int2: 5;
|
|
1235
|
+
readonly Int4: 6;
|
|
1236
|
+
readonly Int8: 7;
|
|
1237
|
+
readonly Int16: 8;
|
|
1238
|
+
readonly Utf8: 9;
|
|
1239
|
+
readonly Uint1: 10;
|
|
1240
|
+
readonly Uint2: 11;
|
|
1241
|
+
readonly Uint4: 12;
|
|
1242
|
+
readonly Uint8: 13;
|
|
1243
|
+
readonly Uint16: 14;
|
|
1244
|
+
readonly Date: 15;
|
|
1245
|
+
readonly DateTime: 16;
|
|
1246
|
+
readonly Time: 17;
|
|
1247
|
+
readonly Duration: 18;
|
|
1248
|
+
readonly IdentityId: 19;
|
|
1249
|
+
readonly Uuid4: 20;
|
|
1250
|
+
readonly Uuid7: 21;
|
|
1251
|
+
readonly Blob: 22;
|
|
1252
|
+
readonly Int: 23;
|
|
1253
|
+
readonly Uint: 24;
|
|
1254
|
+
readonly Decimal: 25;
|
|
1255
|
+
readonly Any: 26;
|
|
1256
|
+
readonly DictionaryId: 27;
|
|
1257
|
+
readonly Type: 28;
|
|
1258
|
+
readonly List: 29;
|
|
1259
|
+
readonly Record: 30;
|
|
1260
|
+
readonly Tuple: 31;
|
|
1261
|
+
};
|
|
1262
|
+
type TypeName = keyof typeof TYPE_CODE;
|
|
1263
|
+
declare function typeNameFromCode(code: number): TypeName;
|
|
1264
|
+
|
|
1265
|
+
interface MissingPresentation {
|
|
1266
|
+
text: string;
|
|
1267
|
+
italic: boolean;
|
|
1268
|
+
muted: boolean;
|
|
1269
|
+
}
|
|
1270
|
+
declare const NONE_PRESENTATION: MissingPresentation;
|
|
1271
|
+
type ValueRole = 'none' | 'boolean' | 'number' | 'temporal' | 'uuid' | 'string' | 'blob' | 'unknown';
|
|
1272
|
+
declare function valueTypeName(value: unknown): string | undefined;
|
|
1273
|
+
declare function valueRole(value: unknown): ValueRole;
|
|
1274
|
+
declare function formatValue(value: unknown): string;
|
|
1275
|
+
|
|
1276
|
+
declare function graphemeWidth(grapheme: string): number;
|
|
1277
|
+
declare function displayWidth(text: string): number;
|
|
1278
|
+
declare function truncateToWidth(text: string, width: number, ellipsis?: string): string;
|
|
1279
|
+
declare function padToWidth(text: string, width: number, align: 'left' | 'right' | 'center'): string;
|
|
1280
|
+
|
|
1281
|
+
type ColumnAlign = 'left' | 'right';
|
|
1282
|
+
interface ResultColumn {
|
|
1283
|
+
name: string;
|
|
1284
|
+
type?: string;
|
|
1285
|
+
role: ValueRole;
|
|
1286
|
+
align: ColumnAlign;
|
|
1287
|
+
}
|
|
1288
|
+
interface PlannedColumn {
|
|
1289
|
+
column: ResultColumn;
|
|
1290
|
+
width: number;
|
|
1291
|
+
}
|
|
1292
|
+
interface TablePlan {
|
|
1293
|
+
columns: PlannedColumn[];
|
|
1294
|
+
dropped: ResultColumn[];
|
|
1295
|
+
truncated: boolean;
|
|
1296
|
+
}
|
|
1297
|
+
interface TableLayoutOptions {
|
|
1298
|
+
width?: number;
|
|
1299
|
+
maxColumnWidth?: number;
|
|
1300
|
+
sample?: number;
|
|
1301
|
+
columnOverhead?: number;
|
|
1302
|
+
tableOverhead?: number;
|
|
1303
|
+
}
|
|
1304
|
+
declare function inferColumns(rows: ReadonlyArray<Record<string, unknown>>): ResultColumn[];
|
|
1305
|
+
declare function planTable(rows: ReadonlyArray<Record<string, unknown>>, columns: ReadonlyArray<ResultColumn>, options?: TableLayoutOptions): TablePlan;
|
|
1306
|
+
declare function cellText(value: unknown, width: number): string;
|
|
1307
|
+
|
|
1308
|
+
declare const RQL_KEYWORDS: readonly string[];
|
|
1309
|
+
declare const RQL_LITERALS: readonly string[];
|
|
1310
|
+
declare const RQL_TYPES: readonly string[];
|
|
1311
|
+
declare const RQL_OPERATORS: readonly string[];
|
|
1312
|
+
declare const RQL_SYSTEM_COLUMNS: readonly string[];
|
|
1313
|
+
|
|
1314
|
+
type RqlTokenKind = 'keyword' | 'type' | 'constant' | 'identifier' | 'namespace' | 'entity' | 'function' | 'key' | 'variable' | 'variable.predefined' | 'comment' | 'string' | 'number' | 'operator' | 'delimiter' | 'bracket' | 'white';
|
|
1315
|
+
interface RqlToken {
|
|
1316
|
+
kind: RqlTokenKind;
|
|
1317
|
+
start: number;
|
|
1318
|
+
end: number;
|
|
1319
|
+
}
|
|
1320
|
+
declare function tokenizeRql(source: string): RqlToken[];
|
|
1321
|
+
|
|
1322
|
+
export { type ArrayShapeNode, type BaseType, BlobValue, BooleanValue, type Column, type ColumnAlign, DateTimeValue, DateValue, DecimalValue, type Diagnostic, type DiagnosticColumn, DurationValue, type ErrorResponse, Float4Value, Float8Value, type Fragment, type Frame, type FrameResults, IdentityIdValue, type InferShape, type InferShapes, Int16Value, Int1Value, Int2Value, Int4Value, Int8Value, type MissingPresentation, NONE_PRESENTATION, NONE_VALUE, NoneValue, type ObjectShapeNode, Option, type OptionShapeNode, type OptionType, type Params, type PlannedColumn, type PrimitiveShapeNode, type PrimitiveToTS, type PrimitiveToValue, ROW_NUMBER_KEY, RQL_KEYWORDS, RQL_LITERALS, RQL_OPERATORS, RQL_SYSTEM_COLUMNS, RQL_TYPES, ReifyError, type ResultColumn, type RqlToken, type RqlTokenKind, Shape, ShapeBuilder, ShapeMismatch, type ShapeNode, type SingleFrameResult, TYPE_CODE, type TableLayoutOptions, type TablePlan, TimeValue, type Type, type TypeName, type TypeValuePair, Uint16Value, Uint1Value, Uint2Value, Uint4Value, Uint8Value, Utf8Value, Uuid4Value, Uuid7Value, Value, type ValueRole, type ValueShapeNode, type WireType, asFrameResults, cellText, checkFrame, checkFrames, columnsFromWire, columnsToRows, decode, displayWidth, encodeParams, encodeValue, envelopeToColumns, envelopesToFrames, formatValue, framesFromWire, graphemeWidth, inferColumns, innerOfOption, isOption, isOptionType, noneDepth, noneMarker, noneMarkerDepth, optionDepth, padToWidth, parseValue, planTable, tokenizeRql, transformFrames, transformResult, truncateToWidth, typeFromWire, typeNameFromCode, typeToWire, unwrapOptionType, validateShape, valueRole, valueTypeName };
|