@reifydb/core 0.4.7 → 0.4.9
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 +79 -79
- package/dist/index.js +38 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -910,101 +910,101 @@ declare function decode(pair: TypeValuePair): Value;
|
|
|
910
910
|
|
|
911
911
|
type PrimitiveToTS<T extends BaseType> = T extends 'Blob' ? Uint8Array : T extends 'Boolean' ? boolean : T extends 'Decimal' ? string : T extends 'Float4' ? number : T extends 'Float8' ? number : T extends 'Int1' ? number : T extends 'Int2' ? number : T extends 'Int4' ? number : T extends 'Int8' ? bigint : T extends 'Int16' ? bigint : T extends 'Uint1' ? number : T extends 'Uint2' ? number : T extends 'Uint4' ? number : T extends 'Uint8' ? bigint : T extends 'Uint16' ? bigint : T extends 'Utf8' ? string : T extends 'Date' ? Date : T extends 'DateTime' ? Date : T extends 'Time' ? string : T extends 'Duration' ? string : T extends 'Uuid4' ? string : T extends 'Uuid7' ? string : T extends 'None' ? undefined : T extends 'IdentityId' ? string : never;
|
|
912
912
|
type PrimitiveToValue<T extends BaseType> = T extends 'Blob' ? BlobValue : T extends 'Boolean' ? BooleanValue : T extends 'Decimal' ? DecimalValue : T extends 'Float4' ? Float4Value : T extends 'Float8' ? Float8Value : T extends 'Int1' ? Int1Value : T extends 'Int2' ? Int2Value : T extends 'Int4' ? Int4Value : T extends 'Int8' ? Int8Value : T extends 'Int16' ? Int16Value : T extends 'Uint1' ? Uint1Value : T extends 'Uint2' ? Uint2Value : T extends 'Uint4' ? Uint4Value : T extends 'Uint8' ? Uint8Value : T extends 'Uint16' ? Uint16Value : T extends 'Utf8' ? Utf8Value : T extends 'Date' ? DateValue : T extends 'DateTime' ? DateTimeValue : T extends 'Time' ? TimeValue : T extends 'Duration' ? DurationValue : T extends 'Uuid4' ? Uuid4Value : T extends 'Uuid7' ? Uuid7Value : T extends 'None' ? NoneValue : T extends 'IdentityId' ? IdentityIdValue : never;
|
|
913
|
-
type
|
|
914
|
-
[K in keyof P]:
|
|
915
|
-
} : S extends
|
|
916
|
-
type
|
|
917
|
-
[K in keyof S]:
|
|
913
|
+
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> ? {
|
|
914
|
+
[K in keyof P]: InferShape<P[K]>;
|
|
915
|
+
} : S extends ArrayShapeNode<infer T> ? InferShape<T>[] : S extends OptionalShapeNode<infer T> ? InferShape<T> | undefined : never;
|
|
916
|
+
type InferShapes<S extends readonly ShapeNode[]> = {
|
|
917
|
+
[K in keyof S]: InferShape<S[K]>[];
|
|
918
918
|
};
|
|
919
919
|
|
|
920
|
-
declare class
|
|
921
|
-
static blob():
|
|
922
|
-
static bool():
|
|
923
|
-
static boolean():
|
|
924
|
-
static decimal():
|
|
925
|
-
static float4():
|
|
926
|
-
static float8():
|
|
927
|
-
static float():
|
|
928
|
-
static double():
|
|
929
|
-
static int1():
|
|
930
|
-
static int2():
|
|
931
|
-
static int4():
|
|
932
|
-
static int8():
|
|
933
|
-
static int16():
|
|
934
|
-
static int():
|
|
935
|
-
static bigint():
|
|
936
|
-
static uint1():
|
|
937
|
-
static uint2():
|
|
938
|
-
static uint4():
|
|
939
|
-
static uint8():
|
|
940
|
-
static uint16():
|
|
941
|
-
static utf8():
|
|
942
|
-
static string():
|
|
943
|
-
static date():
|
|
944
|
-
static datetime():
|
|
945
|
-
static time():
|
|
946
|
-
static duration():
|
|
947
|
-
static uuid4():
|
|
948
|
-
static uuid7():
|
|
949
|
-
static uuid():
|
|
950
|
-
static none():
|
|
951
|
-
static identityid():
|
|
952
|
-
static object<P extends Record<string,
|
|
953
|
-
static array<T extends
|
|
954
|
-
static optional<T extends
|
|
955
|
-
static number():
|
|
956
|
-
static booleanValue():
|
|
957
|
-
static decimalValue():
|
|
958
|
-
static int1Value():
|
|
959
|
-
static int2Value():
|
|
960
|
-
static int4Value():
|
|
961
|
-
static int8Value():
|
|
962
|
-
static int16Value():
|
|
963
|
-
static uint1Value():
|
|
964
|
-
static uint2Value():
|
|
965
|
-
static uint4Value():
|
|
966
|
-
static uint8Value():
|
|
967
|
-
static uint16Value():
|
|
968
|
-
static float4Value():
|
|
969
|
-
static float8Value():
|
|
970
|
-
static utf8Value():
|
|
971
|
-
static dateValue():
|
|
972
|
-
static dateTimeValue():
|
|
973
|
-
static timeValue():
|
|
974
|
-
static durationValue():
|
|
975
|
-
static uuid4Value():
|
|
976
|
-
static uuid7Value():
|
|
977
|
-
static noneValue():
|
|
978
|
-
static blobValue():
|
|
979
|
-
static identityIdValue():
|
|
920
|
+
declare class ShapeBuilder {
|
|
921
|
+
static blob(): PrimitiveShapeNode<'Blob'>;
|
|
922
|
+
static bool(): PrimitiveShapeNode<'Boolean'>;
|
|
923
|
+
static boolean(): PrimitiveShapeNode<'Boolean'>;
|
|
924
|
+
static decimal(): PrimitiveShapeNode<'Decimal'>;
|
|
925
|
+
static float4(): PrimitiveShapeNode<'Float4'>;
|
|
926
|
+
static float8(): PrimitiveShapeNode<'Float8'>;
|
|
927
|
+
static float(): PrimitiveShapeNode<'Float8'>;
|
|
928
|
+
static double(): PrimitiveShapeNode<'Float8'>;
|
|
929
|
+
static int1(): PrimitiveShapeNode<'Int1'>;
|
|
930
|
+
static int2(): PrimitiveShapeNode<'Int2'>;
|
|
931
|
+
static int4(): PrimitiveShapeNode<'Int4'>;
|
|
932
|
+
static int8(): PrimitiveShapeNode<'Int8'>;
|
|
933
|
+
static int16(): PrimitiveShapeNode<'Int16'>;
|
|
934
|
+
static int(): PrimitiveShapeNode<'Int4'>;
|
|
935
|
+
static bigint(): PrimitiveShapeNode<'Int8'>;
|
|
936
|
+
static uint1(): PrimitiveShapeNode<'Uint1'>;
|
|
937
|
+
static uint2(): PrimitiveShapeNode<'Uint2'>;
|
|
938
|
+
static uint4(): PrimitiveShapeNode<'Uint4'>;
|
|
939
|
+
static uint8(): PrimitiveShapeNode<'Uint8'>;
|
|
940
|
+
static uint16(): PrimitiveShapeNode<'Uint16'>;
|
|
941
|
+
static utf8(): PrimitiveShapeNode<'Utf8'>;
|
|
942
|
+
static string(): PrimitiveShapeNode<'Utf8'>;
|
|
943
|
+
static date(): PrimitiveShapeNode<'Date'>;
|
|
944
|
+
static datetime(): PrimitiveShapeNode<'DateTime'>;
|
|
945
|
+
static time(): PrimitiveShapeNode<'Time'>;
|
|
946
|
+
static duration(): PrimitiveShapeNode<'Duration'>;
|
|
947
|
+
static uuid4(): PrimitiveShapeNode<'Uuid4'>;
|
|
948
|
+
static uuid7(): PrimitiveShapeNode<'Uuid7'>;
|
|
949
|
+
static uuid(): PrimitiveShapeNode<'Uuid7'>;
|
|
950
|
+
static none(): PrimitiveShapeNode<'None'>;
|
|
951
|
+
static identityid(): PrimitiveShapeNode<'IdentityId'>;
|
|
952
|
+
static object<P extends Record<string, ShapeNode>>(properties: P): ObjectShapeNode<P>;
|
|
953
|
+
static array<T extends ShapeNode>(items: T): ArrayShapeNode<T>;
|
|
954
|
+
static optional<T extends ShapeNode>(shape: T): OptionalShapeNode<T>;
|
|
955
|
+
static number(): PrimitiveShapeNode<'Float8'>;
|
|
956
|
+
static booleanValue(): ValueShapeNode<'Boolean'>;
|
|
957
|
+
static decimalValue(): ValueShapeNode<'Decimal'>;
|
|
958
|
+
static int1Value(): ValueShapeNode<'Int1'>;
|
|
959
|
+
static int2Value(): ValueShapeNode<'Int2'>;
|
|
960
|
+
static int4Value(): ValueShapeNode<'Int4'>;
|
|
961
|
+
static int8Value(): ValueShapeNode<'Int8'>;
|
|
962
|
+
static int16Value(): ValueShapeNode<'Int16'>;
|
|
963
|
+
static uint1Value(): ValueShapeNode<'Uint1'>;
|
|
964
|
+
static uint2Value(): ValueShapeNode<'Uint2'>;
|
|
965
|
+
static uint4Value(): ValueShapeNode<'Uint4'>;
|
|
966
|
+
static uint8Value(): ValueShapeNode<'Uint8'>;
|
|
967
|
+
static uint16Value(): ValueShapeNode<'Uint16'>;
|
|
968
|
+
static float4Value(): ValueShapeNode<'Float4'>;
|
|
969
|
+
static float8Value(): ValueShapeNode<'Float8'>;
|
|
970
|
+
static utf8Value(): ValueShapeNode<'Utf8'>;
|
|
971
|
+
static dateValue(): ValueShapeNode<'Date'>;
|
|
972
|
+
static dateTimeValue(): ValueShapeNode<'DateTime'>;
|
|
973
|
+
static timeValue(): ValueShapeNode<'Time'>;
|
|
974
|
+
static durationValue(): ValueShapeNode<'Duration'>;
|
|
975
|
+
static uuid4Value(): ValueShapeNode<'Uuid4'>;
|
|
976
|
+
static uuid7Value(): ValueShapeNode<'Uuid7'>;
|
|
977
|
+
static noneValue(): ValueShapeNode<'None'>;
|
|
978
|
+
static blobValue(): ValueShapeNode<'Blob'>;
|
|
979
|
+
static identityIdValue(): ValueShapeNode<'IdentityId'>;
|
|
980
980
|
}
|
|
981
|
-
declare const
|
|
981
|
+
declare const Shape: typeof ShapeBuilder;
|
|
982
982
|
|
|
983
|
-
declare function parseValue(
|
|
983
|
+
declare function parseValue(shape: ShapeNode, value: any): any;
|
|
984
984
|
|
|
985
|
-
declare function
|
|
985
|
+
declare function validateShape(shape: ShapeNode, value: any): boolean;
|
|
986
986
|
|
|
987
|
-
interface
|
|
987
|
+
interface PrimitiveShapeNode<T extends string = string> {
|
|
988
988
|
kind: 'primitive';
|
|
989
989
|
type: T;
|
|
990
990
|
}
|
|
991
|
-
interface
|
|
991
|
+
interface ObjectShapeNode<P extends Record<string, ShapeNode> = Record<string, ShapeNode>> {
|
|
992
992
|
kind: 'object';
|
|
993
993
|
properties: P;
|
|
994
994
|
}
|
|
995
|
-
interface
|
|
995
|
+
interface ArrayShapeNode<T extends ShapeNode = ShapeNode> {
|
|
996
996
|
kind: 'array';
|
|
997
997
|
items: T;
|
|
998
998
|
}
|
|
999
|
-
interface
|
|
999
|
+
interface OptionalShapeNode<T extends ShapeNode = ShapeNode> {
|
|
1000
1000
|
kind: 'optional';
|
|
1001
|
-
|
|
1001
|
+
shape: T;
|
|
1002
1002
|
}
|
|
1003
|
-
interface
|
|
1003
|
+
interface ValueShapeNode<T extends string = string> {
|
|
1004
1004
|
kind: 'value';
|
|
1005
1005
|
type: T;
|
|
1006
1006
|
}
|
|
1007
|
-
type
|
|
1007
|
+
type ShapeNode = PrimitiveShapeNode | ObjectShapeNode | ArrayShapeNode | OptionalShapeNode | ValueShapeNode;
|
|
1008
1008
|
|
|
1009
1009
|
type Params = (TypeValuePair | null)[] | Record<string, TypeValuePair | null>;
|
|
1010
1010
|
interface Frame {
|
|
@@ -1058,14 +1058,14 @@ declare class ReifyError extends Error {
|
|
|
1058
1058
|
* Simplified type for inferring frame results to avoid deep instantiation
|
|
1059
1059
|
* This provides a workaround for TypeScript's limitation with deeply nested types
|
|
1060
1060
|
*/
|
|
1061
|
-
type FrameResults<S extends readonly
|
|
1061
|
+
type FrameResults<S extends readonly ShapeNode[]> = S extends readonly [infer First, ...infer Rest] ? First extends ShapeNode ? Rest extends readonly ShapeNode[] ? [InferShape<First>[], ...FrameResults<Rest>] : [InferShape<First>[]] : never : [];
|
|
1062
1062
|
/**
|
|
1063
1063
|
* Helper type to extract a single frame result
|
|
1064
1064
|
*/
|
|
1065
|
-
type SingleFrameResult<S extends
|
|
1065
|
+
type SingleFrameResult<S extends ShapeNode> = InferShape<S>[];
|
|
1066
1066
|
/**
|
|
1067
1067
|
* Type-safe cast helper for frame results
|
|
1068
1068
|
*/
|
|
1069
|
-
declare function asFrameResults<S extends readonly
|
|
1069
|
+
declare function asFrameResults<S extends readonly ShapeNode[]>(results: any): FrameResults<S>;
|
|
1070
1070
|
|
|
1071
|
-
export { type
|
|
1071
|
+
export { type ArrayShapeNode, type BaseType, BlobValue, BooleanValue, type Column, 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, NONE_VALUE, NoneValue, type ObjectShapeNode, type OptionType, type OptionalShapeNode, type Params, type PrimitiveShapeNode, type PrimitiveToTS, type PrimitiveToValue, ReifyError, Shape, ShapeBuilder, type ShapeNode, type SingleFrameResult, TimeValue, type Type, type TypeValuePair, Uint16Value, Uint1Value, Uint2Value, Uint4Value, Uint8Value, Utf8Value, Uuid4Value, Uuid7Value, Value, type ValueShapeNode, asFrameResults, decode, isOptionType, parseValue, unwrapOptionType, validateShape };
|
package/dist/index.js
CHANGED
|
@@ -2744,8 +2744,8 @@ function decode(pair) {
|
|
|
2744
2744
|
}
|
|
2745
2745
|
}
|
|
2746
2746
|
|
|
2747
|
-
// src/
|
|
2748
|
-
var
|
|
2747
|
+
// src/shape/builder.ts
|
|
2748
|
+
var ShapeBuilder = class {
|
|
2749
2749
|
static blob() {
|
|
2750
2750
|
return { kind: "primitive", type: "Blob" };
|
|
2751
2751
|
}
|
|
@@ -2845,8 +2845,8 @@ var SchemaBuilder = class {
|
|
|
2845
2845
|
static array(items) {
|
|
2846
2846
|
return { kind: "array", items };
|
|
2847
2847
|
}
|
|
2848
|
-
static optional(
|
|
2849
|
-
return { kind: "optional",
|
|
2848
|
+
static optional(shape) {
|
|
2849
|
+
return { kind: "optional", shape };
|
|
2850
2850
|
}
|
|
2851
2851
|
static number() {
|
|
2852
2852
|
return { kind: "primitive", type: "Float8" };
|
|
@@ -2924,9 +2924,9 @@ var SchemaBuilder = class {
|
|
|
2924
2924
|
return { kind: "value", type: "IdentityId" };
|
|
2925
2925
|
}
|
|
2926
2926
|
};
|
|
2927
|
-
var
|
|
2927
|
+
var Shape = ShapeBuilder;
|
|
2928
2928
|
|
|
2929
|
-
// src/
|
|
2929
|
+
// src/shape/parser.ts
|
|
2930
2930
|
function createValueInstance(type, value) {
|
|
2931
2931
|
switch (type) {
|
|
2932
2932
|
case "Blob":
|
|
@@ -2981,52 +2981,52 @@ function createValueInstance(type, value) {
|
|
|
2981
2981
|
throw new Error(`Unknown type: ${type}`);
|
|
2982
2982
|
}
|
|
2983
2983
|
}
|
|
2984
|
-
function parseValue(
|
|
2985
|
-
if (
|
|
2984
|
+
function parseValue(shape, value) {
|
|
2985
|
+
if (shape.kind === "primitive") {
|
|
2986
2986
|
if (value === null || value === void 0) {
|
|
2987
2987
|
return void 0;
|
|
2988
2988
|
}
|
|
2989
|
-
return createValueInstance(
|
|
2989
|
+
return createValueInstance(shape.type, value);
|
|
2990
2990
|
}
|
|
2991
|
-
if (
|
|
2991
|
+
if (shape.kind === "object") {
|
|
2992
2992
|
if (value === null || value === void 0) {
|
|
2993
2993
|
return void 0;
|
|
2994
2994
|
}
|
|
2995
2995
|
const result = {};
|
|
2996
|
-
for (const [key,
|
|
2997
|
-
result[key] = parseValue(
|
|
2996
|
+
for (const [key, propShape] of Object.entries(shape.properties)) {
|
|
2997
|
+
result[key] = parseValue(propShape, value[key]);
|
|
2998
2998
|
}
|
|
2999
2999
|
return result;
|
|
3000
3000
|
}
|
|
3001
|
-
if (
|
|
3001
|
+
if (shape.kind === "array") {
|
|
3002
3002
|
if (!Array.isArray(value)) {
|
|
3003
3003
|
return [];
|
|
3004
3004
|
}
|
|
3005
|
-
return value.map((item) => parseValue(
|
|
3005
|
+
return value.map((item) => parseValue(shape.items, item));
|
|
3006
3006
|
}
|
|
3007
|
-
if (
|
|
3007
|
+
if (shape.kind === "optional") {
|
|
3008
3008
|
if (value === void 0) {
|
|
3009
3009
|
return void 0;
|
|
3010
3010
|
}
|
|
3011
|
-
return parseValue(
|
|
3011
|
+
return parseValue(shape.shape, value);
|
|
3012
3012
|
}
|
|
3013
|
-
if (
|
|
3013
|
+
if (shape.kind === "value") {
|
|
3014
3014
|
if (value === null || value === void 0) {
|
|
3015
3015
|
return void 0;
|
|
3016
3016
|
}
|
|
3017
|
-
return createValueInstance(
|
|
3017
|
+
return createValueInstance(shape.type, value);
|
|
3018
3018
|
}
|
|
3019
|
-
throw new Error(`Unknown
|
|
3019
|
+
throw new Error(`Unknown shape kind: ${shape.kind}`);
|
|
3020
3020
|
}
|
|
3021
3021
|
|
|
3022
|
-
// src/
|
|
3023
|
-
function
|
|
3024
|
-
if (
|
|
3025
|
-
const
|
|
3022
|
+
// src/shape/validator.ts
|
|
3023
|
+
function validateShape(shape, value) {
|
|
3024
|
+
if (shape.kind === "primitive") {
|
|
3025
|
+
const shapeType = shape.type;
|
|
3026
3026
|
if (value === null || value === void 0) {
|
|
3027
|
-
return
|
|
3027
|
+
return shapeType === "None";
|
|
3028
3028
|
}
|
|
3029
|
-
switch (
|
|
3029
|
+
switch (shapeType) {
|
|
3030
3030
|
case "Boolean":
|
|
3031
3031
|
return typeof value === "boolean";
|
|
3032
3032
|
case "Float4":
|
|
@@ -3061,35 +3061,35 @@ function validateSchema(schema, value) {
|
|
|
3061
3061
|
return false;
|
|
3062
3062
|
}
|
|
3063
3063
|
}
|
|
3064
|
-
if (
|
|
3064
|
+
if (shape.kind === "object") {
|
|
3065
3065
|
if (typeof value !== "object" || value === null) {
|
|
3066
3066
|
return false;
|
|
3067
3067
|
}
|
|
3068
|
-
for (const [key,
|
|
3069
|
-
if (!
|
|
3068
|
+
for (const [key, propShape] of Object.entries(shape.properties)) {
|
|
3069
|
+
if (!validateShape(propShape, value[key])) {
|
|
3070
3070
|
return false;
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
3073
3073
|
return true;
|
|
3074
3074
|
}
|
|
3075
|
-
if (
|
|
3075
|
+
if (shape.kind === "array") {
|
|
3076
3076
|
if (!Array.isArray(value)) {
|
|
3077
3077
|
return false;
|
|
3078
3078
|
}
|
|
3079
|
-
return value.every((item) =>
|
|
3079
|
+
return value.every((item) => validateShape(shape.items, item));
|
|
3080
3080
|
}
|
|
3081
|
-
if (
|
|
3081
|
+
if (shape.kind === "optional") {
|
|
3082
3082
|
if (value === void 0) {
|
|
3083
3083
|
return true;
|
|
3084
3084
|
}
|
|
3085
|
-
return
|
|
3085
|
+
return validateShape(shape.shape, value);
|
|
3086
3086
|
}
|
|
3087
|
-
if (
|
|
3087
|
+
if (shape.kind === "value") {
|
|
3088
3088
|
if (value === null || value === void 0) {
|
|
3089
|
-
return
|
|
3089
|
+
return shape.type === "None";
|
|
3090
3090
|
}
|
|
3091
3091
|
if (typeof value === "object" && value !== null && "type" in value && "encode" in value) {
|
|
3092
|
-
return value.type ===
|
|
3092
|
+
return value.type === shape.type;
|
|
3093
3093
|
}
|
|
3094
3094
|
return false;
|
|
3095
3095
|
}
|
|
@@ -3145,8 +3145,8 @@ export {
|
|
|
3145
3145
|
NONE_VALUE,
|
|
3146
3146
|
NoneValue,
|
|
3147
3147
|
ReifyError,
|
|
3148
|
-
|
|
3149
|
-
|
|
3148
|
+
Shape,
|
|
3149
|
+
ShapeBuilder,
|
|
3150
3150
|
TimeValue,
|
|
3151
3151
|
Uint16Value,
|
|
3152
3152
|
Uint1Value,
|
|
@@ -3162,6 +3162,6 @@ export {
|
|
|
3162
3162
|
isOptionType,
|
|
3163
3163
|
parseValue,
|
|
3164
3164
|
unwrapOptionType,
|
|
3165
|
-
|
|
3165
|
+
validateShape
|
|
3166
3166
|
};
|
|
3167
3167
|
//# sourceMappingURL=index.js.map
|