@reifydb/core 0.9.1 → 0.9.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/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  declare const NONE_VALUE = "\u27EAnone\u27EB";
2
+ declare function noneMarker(depth: number): string;
3
+ declare function noneMarkerDepth(payload: string): number | undefined;
2
4
  declare const ROW_NUMBER_KEY = "#rownum";
3
5
 
4
6
  /**
@@ -709,9 +711,9 @@ declare class Uint16Value implements Value {
709
711
 
710
712
  declare class NoneValue implements Value {
711
713
  readonly type: Type;
712
- readonly innerType: BaseType;
713
- constructor(innerType?: BaseType);
714
- static parse(str: string, innerType?: BaseType): NoneValue;
714
+ readonly innerType: Type;
715
+ constructor(innerType?: Type);
716
+ static parse(str: string, innerType?: Type): NoneValue;
715
717
  isNone(): boolean;
716
718
  toString(): string;
717
719
  valueOf(): undefined;
@@ -721,6 +723,25 @@ declare class NoneValue implements Value {
721
723
  toJSON(): null;
722
724
  encode(): TypeValuePair;
723
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
+ }
724
745
 
725
746
  declare class Utf8Value implements Value {
726
747
  readonly type: Type;
@@ -913,6 +934,45 @@ declare class IdentityIdValue implements Value {
913
934
  encode(): TypeValuePair;
914
935
  }
915
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
+
916
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";
917
977
  interface OptionType {
918
978
  Option: Type;
@@ -920,6 +980,8 @@ interface OptionType {
920
980
  type Type = BaseType | OptionType;
921
981
  declare function isOptionType(t: Type): t is OptionType;
922
982
  declare function unwrapOptionType(t: Type): BaseType;
983
+ declare function optionDepth(t: Type): number;
984
+ declare function innerOfOption(t: OptionType): Type;
923
985
  interface TypeValuePair {
924
986
  type: Type;
925
987
  value: string;
@@ -987,7 +1049,7 @@ type PrimitiveToValue<T extends BaseType> = PrimitiveValueMap[T];
987
1049
  type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
988
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> ? {
989
1051
  [K in keyof P as CamelCase<K & string>]: InferShape<P[K]>;
990
- } : S extends ArrayShapeNode<infer T> ? InferShape<T>[] : S extends OptionalShapeNode<infer T> ? InferShape<T> | undefined : never;
1052
+ } : S extends ArrayShapeNode<infer T> ? InferShape<T>[] : S extends OptionShapeNode<infer T> ? Option<InferShape<T>> : never;
991
1053
  type InferShapes<S extends readonly ShapeNode[]> = {
992
1054
  [K in keyof S]: InferShape<S[K]>[];
993
1055
  };
@@ -1026,7 +1088,7 @@ declare class ShapeBuilder {
1026
1088
  static identityid(): PrimitiveShapeNode<'IdentityId'>;
1027
1089
  static object<P extends Record<string, ShapeNode>>(properties: P): ObjectShapeNode<P>;
1028
1090
  static array<T extends ShapeNode>(items: T): ArrayShapeNode<T>;
1029
- static optional<T extends ShapeNode>(shape: T): OptionalShapeNode<T>;
1091
+ static option<T extends ShapeNode>(inner: T): OptionShapeNode<T>;
1030
1092
  static number(): PrimitiveShapeNode<'Float8'>;
1031
1093
  static booleanValue(): ValueShapeNode<'Boolean'>;
1032
1094
  static decimalValue(): ValueShapeNode<'Decimal'>;
@@ -1062,6 +1124,12 @@ declare function validateShape(shape: ShapeNode, value: any): boolean;
1062
1124
  declare function transformFrames<const S extends readonly ShapeNode[]>(frames: any[][], shapes: S): FrameResults<S>;
1063
1125
  declare function transformResult(row: any, resultShape: any): any;
1064
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
+
1065
1133
  interface PrimitiveShapeNode<T extends string = string> {
1066
1134
  kind: 'primitive';
1067
1135
  type: T;
@@ -1074,15 +1142,15 @@ interface ArrayShapeNode<T extends ShapeNode = ShapeNode> {
1074
1142
  kind: 'array';
1075
1143
  items: T;
1076
1144
  }
1077
- interface OptionalShapeNode<T extends ShapeNode = ShapeNode> {
1078
- kind: 'optional';
1079
- shape: T;
1145
+ interface OptionShapeNode<T extends ShapeNode = ShapeNode> {
1146
+ kind: 'option';
1147
+ inner: T;
1080
1148
  }
1081
1149
  interface ValueShapeNode<T extends string = string> {
1082
1150
  kind: 'value';
1083
1151
  type: T;
1084
1152
  }
1085
- type ShapeNode = PrimitiveShapeNode | ObjectShapeNode | ArrayShapeNode | OptionalShapeNode | ValueShapeNode;
1153
+ type ShapeNode = PrimitiveShapeNode | ObjectShapeNode | ArrayShapeNode | OptionShapeNode | ValueShapeNode;
1086
1154
 
1087
1155
  type Params = (TypeValuePair | null)[] | Record<string, TypeValuePair | null>;
1088
1156
  interface Frame {
@@ -1149,8 +1217,13 @@ declare function asFrameResults<S extends readonly ShapeNode[]>(results: any): F
1149
1217
  declare function decode(pair: TypeValuePair): Value;
1150
1218
  declare function columnsToRows(columns: Column[]): Record<string, Value>[];
1151
1219
 
1152
- declare function encodeValue(value: any): TypeValuePair;
1153
- declare function encodeParams(params: any): TypeValuePair[] | Record<string, TypeValuePair>;
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>;
1154
1227
 
1155
1228
  declare const TYPE_CODE: {
1156
1229
  readonly None: 0;
@@ -1246,4 +1319,4 @@ interface RqlToken {
1246
1319
  }
1247
1320
  declare function tokenizeRql(source: string): RqlToken[];
1248
1321
 
1249
- 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, type OptionType, type OptionalShapeNode, 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, 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, asFrameResults, cellText, columnsToRows, decode, displayWidth, encodeParams, encodeValue, formatValue, graphemeWidth, inferColumns, isOptionType, padToWidth, parseValue, planTable, tokenizeRql, transformFrames, transformResult, truncateToWidth, typeNameFromCode, unwrapOptionType, validateShape, valueRole, valueTypeName };
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 };