@reifydb/core 0.9.1 → 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.js CHANGED
@@ -1,5 +1,20 @@
1
1
  // src/constant.ts
2
2
  var NONE_VALUE = "\u27EAnone\u27EB";
3
+ var NONE_MARKER_OPEN = NONE_VALUE.slice(0, -1);
4
+ var NONE_MARKER_CLOSE = NONE_VALUE.slice(-1);
5
+ function noneMarker(depth) {
6
+ return depth === 0 ? NONE_VALUE : `${NONE_MARKER_OPEN}:${depth}${NONE_MARKER_CLOSE}`;
7
+ }
8
+ function noneMarkerDepth(payload) {
9
+ if (payload === NONE_VALUE) {
10
+ return 0;
11
+ }
12
+ if (!payload.startsWith(`${NONE_MARKER_OPEN}:`) || !payload.endsWith(NONE_MARKER_CLOSE)) {
13
+ return void 0;
14
+ }
15
+ const digits = payload.slice(NONE_MARKER_OPEN.length + 1, -NONE_MARKER_CLOSE.length);
16
+ return /^[1-9][0-9]*$/.test(digits) ? Number(digits) : void 0;
17
+ }
3
18
  var ROW_NUMBER_KEY = "#rownum";
4
19
 
5
20
  // src/value/blob.ts
@@ -2286,11 +2301,151 @@ var NoneValue = class _NoneValue {
2286
2301
  }
2287
2302
  encode() {
2288
2303
  return {
2289
- type: "None",
2304
+ type: { Option: this.innerType },
2290
2305
  value: NONE_VALUE
2291
2306
  };
2292
2307
  }
2293
2308
  };
2309
+ function noneDepth(v) {
2310
+ return optionDepth(v.innerType) + 1;
2311
+ }
2312
+
2313
+ // src/present/value.ts
2314
+ var NONE_PRESENTATION = {
2315
+ text: "none",
2316
+ italic: true,
2317
+ muted: true
2318
+ };
2319
+ var ROLE_BY_TYPE = {
2320
+ None: "none",
2321
+ Boolean: "boolean",
2322
+ Int1: "number",
2323
+ Int2: "number",
2324
+ Int4: "number",
2325
+ Int8: "number",
2326
+ Int16: "number",
2327
+ Uint1: "number",
2328
+ Uint2: "number",
2329
+ Uint4: "number",
2330
+ Uint8: "number",
2331
+ Uint16: "number",
2332
+ Float4: "number",
2333
+ Float8: "number",
2334
+ Decimal: "number",
2335
+ Date: "temporal",
2336
+ DateTime: "temporal",
2337
+ Time: "temporal",
2338
+ Duration: "temporal",
2339
+ Uuid4: "uuid",
2340
+ Uuid7: "uuid",
2341
+ IdentityId: "uuid",
2342
+ Utf8: "string",
2343
+ Blob: "blob"
2344
+ };
2345
+ function typeName(value) {
2346
+ if (value === null || typeof value !== "object") return void 0;
2347
+ const candidate = value.type;
2348
+ return typeof candidate === "string" ? candidate : void 0;
2349
+ }
2350
+ function valueTypeName(value) {
2351
+ if (value === null || value === void 0) return "None";
2352
+ return typeName(value);
2353
+ }
2354
+ function valueRole(value) {
2355
+ if (value === null || value === void 0) return "none";
2356
+ const name = typeName(value);
2357
+ if (name !== void 0) {
2358
+ return ROLE_BY_TYPE[name] ?? "unknown";
2359
+ }
2360
+ switch (typeof value) {
2361
+ case "number":
2362
+ case "bigint":
2363
+ return "number";
2364
+ case "boolean":
2365
+ return "boolean";
2366
+ case "string":
2367
+ return "string";
2368
+ default:
2369
+ return "unknown";
2370
+ }
2371
+ }
2372
+ function formatValue(value) {
2373
+ if (value === null || value === void 0) return NONE_PRESENTATION.text;
2374
+ if (typeof value === "bigint") return value.toString();
2375
+ if (typeof value === "object") {
2376
+ const name = typeName(value);
2377
+ if (name === "None") return NONE_PRESENTATION.text;
2378
+ if (name !== void 0) return String(value);
2379
+ return JSON.stringify(value) ?? String(value);
2380
+ }
2381
+ return String(value);
2382
+ }
2383
+
2384
+ // src/value/option.ts
2385
+ function describeType(t) {
2386
+ return isOptionType(t) ? `Option(${describeType(t.Option)})` : t;
2387
+ }
2388
+ function hasType(value) {
2389
+ return typeof value === "object" && value !== null && "type" in value;
2390
+ }
2391
+ function hasToJSON(value) {
2392
+ return typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function";
2393
+ }
2394
+ var OPTION_BRAND = /* @__PURE__ */ Symbol.for("reifydb.option");
2395
+ function isOption(value) {
2396
+ return typeof value === "object" && value !== null && value[OPTION_BRAND] === true;
2397
+ }
2398
+ var _a;
2399
+ _a = OPTION_BRAND;
2400
+ var _Option = class _Option {
2401
+ constructor(state) {
2402
+ this.state = state;
2403
+ this[_a] = true;
2404
+ }
2405
+ static some(value) {
2406
+ return new _Option({ some: true, value });
2407
+ }
2408
+ static none(inner) {
2409
+ return new _Option({ some: false, inner });
2410
+ }
2411
+ isSome() {
2412
+ return this.state.some;
2413
+ }
2414
+ isNone() {
2415
+ return !this.state.some;
2416
+ }
2417
+ unwrap() {
2418
+ if (this.state.some) {
2419
+ return this.state.value;
2420
+ }
2421
+ throw new Error(`unwrap on a None of type ${describeType(this.state.inner)}`);
2422
+ }
2423
+ unwrapOr(fallback) {
2424
+ return this.state.some ? this.state.value : fallback;
2425
+ }
2426
+ map(fn) {
2427
+ return this.state.some ? _Option.some(fn(this.state.value)) : _Option.none(this.state.inner);
2428
+ }
2429
+ get type() {
2430
+ if (!this.state.some) {
2431
+ return { Option: this.state.inner };
2432
+ }
2433
+ if (hasType(this.state.value)) {
2434
+ return { Option: this.state.value.type };
2435
+ }
2436
+ throw new Error(`Option.some over a raw ${typeof this.state.value} has no wire type`);
2437
+ }
2438
+ toString() {
2439
+ return this.state.some ? String(this.state.value) : NONE_PRESENTATION.text;
2440
+ }
2441
+ toJSON() {
2442
+ if (!this.state.some) {
2443
+ return null;
2444
+ }
2445
+ return hasToJSON(this.state.value) ? this.state.value.toJSON() : this.state.value;
2446
+ }
2447
+ };
2448
+ var Option = _Option;
2294
2449
 
2295
2450
  // src/value/utf8.ts
2296
2451
  var Utf8Value = class _Utf8Value {
@@ -2746,6 +2901,49 @@ var IdentityIdValue = class _IdentityIdValue {
2746
2901
  }
2747
2902
  };
2748
2903
 
2904
+ // src/value/wire-type.ts
2905
+ function typeToWire(type) {
2906
+ return isOptionType(type) ? { id: "Option", underlying: typeToWire(type.Option) } : { id: type };
2907
+ }
2908
+ function typeFromWire(wire) {
2909
+ if (!wire || typeof wire !== "object" || typeof wire.id !== "string") {
2910
+ throw new Error(`Expected a type descriptor object, got ${JSON.stringify(wire)}`);
2911
+ }
2912
+ if (wire.id === "Option") {
2913
+ if (!wire.underlying) {
2914
+ throw new Error("Option type descriptor is missing its underlying type");
2915
+ }
2916
+ return { Option: typeFromWire(wire.underlying) };
2917
+ }
2918
+ return wire.id;
2919
+ }
2920
+ function columnsFromWire(columns) {
2921
+ return columns.map((column) => ({ ...column, type: typeFromWire(column.type) }));
2922
+ }
2923
+ function framesFromWire(frames) {
2924
+ return frames.map(
2925
+ (frame) => frame && frame.columns ? { ...frame, columns: columnsFromWire(frame.columns) } : frame
2926
+ );
2927
+ }
2928
+ function envelopeToColumns(envelope) {
2929
+ const types = envelope?.types ?? {};
2930
+ const rows = envelope?.rows ?? [];
2931
+ return Object.keys(types).map((name) => ({
2932
+ name,
2933
+ type: typeFromWire(types[name]),
2934
+ payload: rows.map((row) => payloadOf(row?.[name]))
2935
+ }));
2936
+ }
2937
+ function envelopesToFrames(envelopes) {
2938
+ return Array.isArray(envelopes) ? envelopes.map((envelope) => ({ columns: envelopeToColumns(envelope) })) : [];
2939
+ }
2940
+ function payloadOf(value) {
2941
+ if (value === null || value === void 0) {
2942
+ return NONE_VALUE;
2943
+ }
2944
+ return typeof value === "string" ? value : String(value);
2945
+ }
2946
+
2749
2947
  // src/value/index.ts
2750
2948
  function isOptionType(t) {
2751
2949
  return typeof t === "object" && t !== null && "Option" in t;
@@ -2754,17 +2952,30 @@ function unwrapOptionType(t) {
2754
2952
  if (isOptionType(t)) return unwrapOptionType(t.Option);
2755
2953
  return t;
2756
2954
  }
2757
- var Value = class {
2955
+ function optionDepth(t) {
2956
+ return isOptionType(t) ? optionDepth(t.Option) + 1 : 0;
2957
+ }
2958
+ function innerOfOption(t) {
2959
+ return t.Option;
2960
+ }
2961
+ var Value2 = class {
2758
2962
  };
2759
2963
 
2760
2964
  // src/decoder.ts
2965
+ function stripOptionLayers(type, layers) {
2966
+ return layers === 0 || !isOptionType(type) ? type : stripOptionLayers(innerOfOption(type), layers - 1);
2967
+ }
2761
2968
  function decode(pair) {
2762
2969
  if (isOptionType(pair.type)) {
2763
- const innerType = unwrapOptionType(pair.type);
2764
- if (pair.value === NONE_VALUE || pair.value === "") {
2765
- return new NoneValue(innerType);
2970
+ const noneAt = noneMarkerDepth(pair.value);
2971
+ if (noneAt === void 0) {
2972
+ return decode({ type: unwrapOptionType(pair.type), value: pair.value });
2973
+ }
2974
+ const depth = optionDepth(pair.type);
2975
+ if (noneAt >= depth) {
2976
+ throw new Error(`none under ${noneAt} Some layers cannot fit an option of depth ${depth}`);
2766
2977
  }
2767
- return decode({ type: innerType, value: pair.value });
2978
+ return new NoneValue(stripOptionLayers(pair.type, noneAt + 1));
2768
2979
  }
2769
2980
  switch (pair.type) {
2770
2981
  case "Blob":
@@ -2831,9 +3042,23 @@ function columnsToRows(columns) {
2831
3042
  }
2832
3043
 
2833
3044
  // src/encoder.ts
2834
- function encodeValue(value) {
3045
+ function encodeValue(value, name = "$1") {
2835
3046
  if (value === null || value === void 0) {
2836
- return { type: "None", value: NONE_VALUE };
3047
+ throw new Error(`parameter ${name} is null or undefined, use Option.none(inner)`);
3048
+ }
3049
+ if (value instanceof NoneValue && value.innerType === "None") {
3050
+ throw new Error(`parameter ${name} is a NoneValue without an inner type, use Option.none(inner)`);
3051
+ }
3052
+ if (isOption(value)) {
3053
+ if (value.isNone()) {
3054
+ return { type: value.type, value: NONE_VALUE };
3055
+ }
3056
+ const inner = encodeValue(value.unwrap(), name);
3057
+ const noneAt = noneMarkerDepth(inner.value);
3058
+ return {
3059
+ type: { Option: inner.type },
3060
+ value: noneAt === void 0 ? inner.value : noneMarker(noneAt + 1)
3061
+ };
2837
3062
  }
2838
3063
  if (value && typeof value === "object" && "encode" in value && typeof value.encode === "function") {
2839
3064
  return value.encode();
@@ -2902,16 +3127,19 @@ function encodeValue(value) {
2902
3127
  }
2903
3128
  throw new Error(`Cannot encode value of type ${typeof value}: ${value}`);
2904
3129
  }
3130
+ function toWire(pair) {
3131
+ return { type: typeToWire(pair.type), value: pair.value };
3132
+ }
2905
3133
  function encodeParams(params) {
2906
3134
  if (params === void 0 || params === null) {
2907
3135
  return [];
2908
3136
  }
2909
3137
  if (Array.isArray(params)) {
2910
- return params.map((param) => encodeValue(param));
3138
+ return params.map((param, i) => toWire(encodeValue(param, `$${i + 1}`)));
2911
3139
  } else if (typeof params === "object") {
2912
3140
  const encoded = {};
2913
3141
  for (const [key, value] of Object.entries(params)) {
2914
- encoded[key] = encodeValue(value);
3142
+ encoded[key] = toWire(encodeValue(value, `$${key}`));
2915
3143
  }
2916
3144
  return encoded;
2917
3145
  }
@@ -3063,8 +3291,8 @@ var ShapeBuilder = class {
3063
3291
  static array(items) {
3064
3292
  return { kind: "array", items };
3065
3293
  }
3066
- static optional(shape) {
3067
- return { kind: "optional", shape };
3294
+ static option(inner) {
3295
+ return { kind: "option", inner };
3068
3296
  }
3069
3297
  static number() {
3070
3298
  return { kind: "primitive", type: "Float8" };
@@ -3222,11 +3450,14 @@ function parseValue(shape, value) {
3222
3450
  }
3223
3451
  return value.map((item) => parseValue(shape.items, item));
3224
3452
  }
3225
- if (shape.kind === "optional") {
3226
- if (value === void 0) {
3453
+ if (shape.kind === "option") {
3454
+ if (value === null || value === void 0) {
3227
3455
  return void 0;
3228
3456
  }
3229
- return parseValue(shape.shape, value);
3457
+ if (isOption(value)) {
3458
+ return value.map((item) => parseValue(shape.inner, item));
3459
+ }
3460
+ return Option.some(parseValue(shape.inner, value));
3230
3461
  }
3231
3462
  if (shape.kind === "value") {
3232
3463
  if (value === null || value === void 0) {
@@ -3296,11 +3527,11 @@ function validateShape(shape, value) {
3296
3527
  }
3297
3528
  return value.every((item) => validateShape(shape.items, item));
3298
3529
  }
3299
- if (shape.kind === "optional") {
3300
- if (value === void 0) {
3301
- return true;
3530
+ if (shape.kind === "option") {
3531
+ if (!isOption(value)) {
3532
+ return false;
3302
3533
  }
3303
- return validateShape(shape.shape, value);
3534
+ return value.isNone() || validateShape(shape.inner, value.unwrap());
3304
3535
  }
3305
3536
  if (shape.kind === "value") {
3306
3537
  if (value === null || value === void 0) {
@@ -3314,6 +3545,130 @@ function validateShape(shape, value) {
3314
3545
  return false;
3315
3546
  }
3316
3547
 
3548
+ // src/shape/widen.ts
3549
+ var NUMERIC = {
3550
+ Int1: { kind: "int", bits: 8 },
3551
+ Int2: { kind: "int", bits: 16 },
3552
+ Int4: { kind: "int", bits: 32 },
3553
+ Int8: { kind: "int", bits: 64 },
3554
+ Int16: { kind: "int", bits: 128 },
3555
+ Uint1: { kind: "uint", bits: 8 },
3556
+ Uint2: { kind: "uint", bits: 16 },
3557
+ Uint4: { kind: "uint", bits: 32 },
3558
+ Uint8: { kind: "uint", bits: 64 },
3559
+ Uint16: { kind: "uint", bits: 128 },
3560
+ Float4: { kind: "float", bits: 32 },
3561
+ Float8: { kind: "float", bits: 64 }
3562
+ };
3563
+ function widens(target, actual) {
3564
+ if (isOptionType(actual)) {
3565
+ return false;
3566
+ }
3567
+ const t = NUMERIC[target];
3568
+ const a = NUMERIC[actual];
3569
+ if (!t || !a) {
3570
+ return target === actual;
3571
+ }
3572
+ if (t.kind === "float" || a.kind === "float") {
3573
+ return t.kind === "float" && a.kind === "float" && t.bits >= a.bits;
3574
+ }
3575
+ if (t.kind === "uint") {
3576
+ return a.kind === "uint" && t.bits >= a.bits;
3577
+ }
3578
+ return a.kind === "int" ? t.bits >= a.bits : t.bits > a.bits;
3579
+ }
3580
+ function widen(value, target) {
3581
+ if (!value || typeof value !== "object" || typeof value.type !== "string") {
3582
+ return value;
3583
+ }
3584
+ const actual = value.type;
3585
+ if (actual === target || !widens(target, actual)) {
3586
+ return value;
3587
+ }
3588
+ const inner = value.value;
3589
+ if (inner === void 0 || inner === null) {
3590
+ return value;
3591
+ }
3592
+ return decode({ type: target, value: String(inner) });
3593
+ }
3594
+
3595
+ // src/shape/check.ts
3596
+ var ShapeMismatch = class extends Error {
3597
+ constructor(message) {
3598
+ super(message);
3599
+ this.name = "ShapeMismatch";
3600
+ Object.setPrototypeOf(this, new.target.prototype);
3601
+ }
3602
+ };
3603
+ function checkFrames(frames, shapes) {
3604
+ if (shapes.length === 0) {
3605
+ return;
3606
+ }
3607
+ if (frames.length !== shapes.length) {
3608
+ throw new ShapeMismatch(`expected ${shapes.length} frames for ${shapes.length} shapes, got ${frames.length}`);
3609
+ }
3610
+ frames.forEach((frame, i) => checkFrame(frame.columns, shapes[i]));
3611
+ }
3612
+ function checkFrame(columns, shape) {
3613
+ if (shape.kind !== "object") {
3614
+ throw new ShapeMismatch(`a frame needs an object shape, got ${shape.kind}`);
3615
+ }
3616
+ for (const [name, propertyShape] of Object.entries(shape.properties)) {
3617
+ const column = columns.find((c) => c.name === name);
3618
+ if (!column) {
3619
+ throw new ShapeMismatch(`column "${name}": expected ${describe(propertyShape)}, missing from frame`);
3620
+ }
3621
+ if (!matches(propertyShape, column.type)) {
3622
+ throw new ShapeMismatch(`column "${name}": expected ${describe(propertyShape)}, got ${typeName2(column.type)}`);
3623
+ }
3624
+ }
3625
+ }
3626
+ var FAMILIES = [
3627
+ ["Boolean"],
3628
+ ["Int1", "Int2", "Int4", "Int8", "Int16", "Uint1", "Uint2", "Uint4", "Uint8", "Uint16", "Float4", "Float8"],
3629
+ ["Utf8", "Decimal", "Duration", "Uuid4", "Uuid7", "IdentityId"],
3630
+ ["Date", "DateTime", "Time"],
3631
+ ["Blob"],
3632
+ ["None"]
3633
+ ];
3634
+ function familyOf(type) {
3635
+ return FAMILIES.find((family) => family.includes(type)) ?? [type];
3636
+ }
3637
+ function matches(shape, type) {
3638
+ switch (shape.kind) {
3639
+ case "primitive":
3640
+ if (shape.type === "None") {
3641
+ return type === "None" || isOptionType(type);
3642
+ }
3643
+ return !isOptionType(type) && familyOf(shape.type).includes(type);
3644
+ case "value":
3645
+ if (shape.type === "None") {
3646
+ return type === "None" || isOptionType(type);
3647
+ }
3648
+ return type === shape.type || widens(shape.type, type);
3649
+ case "option":
3650
+ return isOptionType(type) && matches(shape.inner, type.Option);
3651
+ case "object":
3652
+ case "array":
3653
+ return false;
3654
+ }
3655
+ }
3656
+ function describe(shape) {
3657
+ switch (shape.kind) {
3658
+ case "primitive":
3659
+ case "value":
3660
+ return shape.type;
3661
+ case "option":
3662
+ return `Option(${describe(shape.inner)})`;
3663
+ case "object":
3664
+ case "array":
3665
+ return shape.kind;
3666
+ }
3667
+ }
3668
+ function typeName2(type) {
3669
+ return isOptionType(type) ? `Option(${typeName2(type.Option)})` : type;
3670
+ }
3671
+
3317
3672
  // src/shape/transform.ts
3318
3673
  function snakeToCamel(key) {
3319
3674
  return key.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
@@ -3342,7 +3697,7 @@ function transformResult(row, resultShape) {
3342
3697
  transformedRow[outputKey] = coerceToPrimitiveType(value, propertyShape.type);
3343
3698
  }
3344
3699
  } else if (propertyShape && propertyShape.kind === "value") {
3345
- transformedRow[outputKey] = value;
3700
+ transformedRow[outputKey] = widen(value, propertyShape.type);
3346
3701
  } else {
3347
3702
  transformedRow[outputKey] = propertyShape ? transformResult(value, propertyShape) : value;
3348
3703
  }
@@ -3356,7 +3711,7 @@ function transformResult(row, resultShape) {
3356
3711
  return coerceToPrimitiveType(row, resultShape.type);
3357
3712
  }
3358
3713
  if (resultShape && resultShape.kind === "value") {
3359
- return row;
3714
+ return widen(row, resultShape.type);
3360
3715
  }
3361
3716
  if (resultShape && resultShape.kind === "array") {
3362
3717
  if (Array.isArray(row)) {
@@ -3364,17 +3719,24 @@ function transformResult(row, resultShape) {
3364
3719
  }
3365
3720
  return row;
3366
3721
  }
3367
- if (resultShape && resultShape.kind === "optional") {
3368
- if (row === void 0) {
3369
- return void 0;
3370
- }
3371
- if (row === null) {
3372
- return null;
3722
+ if (resultShape && resultShape.kind === "option") {
3723
+ if (row instanceof NoneValue) {
3724
+ const remaining = optionLayers(resultShape);
3725
+ const depth = noneDepth(row);
3726
+ if (depth > remaining) {
3727
+ throw new ShapeMismatch(`a none ${depth} layers deep does not fit a shape with ${remaining} option layers`);
3728
+ }
3729
+ if (depth === remaining) {
3730
+ return Option.none(row.innerType);
3731
+ }
3373
3732
  }
3374
- return transformResult(row, resultShape.shape);
3733
+ return Option.some(transformResult(row, resultShape.inner));
3375
3734
  }
3376
3735
  return row;
3377
3736
  }
3737
+ function optionLayers(shape) {
3738
+ return shape.kind === "option" ? optionLayers(shape.inner) + 1 : 0;
3739
+ }
3378
3740
  function coerceToPrimitiveType(value, valueType) {
3379
3741
  if (value === void 0 || value === null) {
3380
3742
  return value;
@@ -3394,77 +3756,6 @@ function coerceToPrimitiveType(value, valueType) {
3394
3756
  return value;
3395
3757
  }
3396
3758
 
3397
- // src/present/value.ts
3398
- var NONE_PRESENTATION = {
3399
- text: "none",
3400
- italic: true,
3401
- muted: true
3402
- };
3403
- var ROLE_BY_TYPE = {
3404
- None: "none",
3405
- Boolean: "boolean",
3406
- Int1: "number",
3407
- Int2: "number",
3408
- Int4: "number",
3409
- Int8: "number",
3410
- Int16: "number",
3411
- Uint1: "number",
3412
- Uint2: "number",
3413
- Uint4: "number",
3414
- Uint8: "number",
3415
- Uint16: "number",
3416
- Float4: "number",
3417
- Float8: "number",
3418
- Decimal: "number",
3419
- Date: "temporal",
3420
- DateTime: "temporal",
3421
- Time: "temporal",
3422
- Duration: "temporal",
3423
- Uuid4: "uuid",
3424
- Uuid7: "uuid",
3425
- IdentityId: "uuid",
3426
- Utf8: "string",
3427
- Blob: "blob"
3428
- };
3429
- function typeName(value) {
3430
- if (value === null || typeof value !== "object") return void 0;
3431
- const candidate = value.type;
3432
- return typeof candidate === "string" ? candidate : void 0;
3433
- }
3434
- function valueTypeName(value) {
3435
- if (value === null || value === void 0) return "None";
3436
- return typeName(value);
3437
- }
3438
- function valueRole(value) {
3439
- if (value === null || value === void 0) return "none";
3440
- const name = typeName(value);
3441
- if (name !== void 0) {
3442
- return ROLE_BY_TYPE[name] ?? "unknown";
3443
- }
3444
- switch (typeof value) {
3445
- case "number":
3446
- case "bigint":
3447
- return "number";
3448
- case "boolean":
3449
- return "boolean";
3450
- case "string":
3451
- return "string";
3452
- default:
3453
- return "unknown";
3454
- }
3455
- }
3456
- function formatValue(value) {
3457
- if (value === null || value === void 0) return NONE_PRESENTATION.text;
3458
- if (typeof value === "bigint") return value.toString();
3459
- if (typeof value === "object") {
3460
- const name = typeName(value);
3461
- if (name === "None") return NONE_PRESENTATION.text;
3462
- if (name !== void 0) return String(value);
3463
- return JSON.stringify(value) ?? String(value);
3464
- }
3465
- return String(value);
3466
- }
3467
-
3468
3759
  // src/present/width.ts
3469
3760
  var ZERO_WIDTH = [
3470
3761
  [768, 879],
@@ -3794,7 +4085,7 @@ var UNSIGNED_INTEGERS = ["uint1", "uint2", "uint4", "uint8", "uint16", "uint"];
3794
4085
  var FLOATING_POINT = ["float4", "float8"];
3795
4086
  var TEXT_AND_BINARY = ["utf8", "blob", "text"];
3796
4087
  var BOOLEAN = ["bool", "boolean"];
3797
- var NUMERIC = ["decimal"];
4088
+ var NUMERIC2 = ["decimal"];
3798
4089
  var TEMPORAL = ["date", "datetime", "time", "duration", "interval"];
3799
4090
  var IDENTIFIERS_AND_UUIDS = [
3800
4091
  "uuid4",
@@ -3811,7 +4102,7 @@ var RQL_TYPES = [
3811
4102
  ...FLOATING_POINT,
3812
4103
  ...TEXT_AND_BINARY,
3813
4104
  ...BOOLEAN,
3814
- ...NUMERIC,
4105
+ ...NUMERIC2,
3815
4106
  ...TEMPORAL,
3816
4107
  ...IDENTIFIERS_AND_UUIDS,
3817
4108
  ...CONTAINERS,
@@ -4049,6 +4340,7 @@ export {
4049
4340
  NONE_PRESENTATION,
4050
4341
  NONE_VALUE,
4051
4342
  NoneValue,
4343
+ Option,
4052
4344
  ROW_NUMBER_KEY,
4053
4345
  RQL_KEYWORDS,
4054
4346
  RQL_LITERALS,
@@ -4058,6 +4350,7 @@ export {
4058
4350
  ReifyError,
4059
4351
  Shape,
4060
4352
  ShapeBuilder,
4353
+ ShapeMismatch,
4061
4354
  TYPE_CODE,
4062
4355
  TimeValue,
4063
4356
  Uint16Value,
@@ -4068,18 +4361,30 @@ export {
4068
4361
  Utf8Value,
4069
4362
  Uuid4Value,
4070
4363
  Uuid7Value,
4071
- Value,
4364
+ Value2 as Value,
4072
4365
  asFrameResults,
4073
4366
  cellText,
4367
+ checkFrame,
4368
+ checkFrames,
4369
+ columnsFromWire,
4074
4370
  columnsToRows,
4075
4371
  decode,
4076
4372
  displayWidth,
4077
4373
  encodeParams,
4078
4374
  encodeValue,
4375
+ envelopeToColumns,
4376
+ envelopesToFrames,
4079
4377
  formatValue,
4378
+ framesFromWire,
4080
4379
  graphemeWidth,
4081
4380
  inferColumns,
4381
+ innerOfOption,
4382
+ isOption,
4082
4383
  isOptionType,
4384
+ noneDepth,
4385
+ noneMarker,
4386
+ noneMarkerDepth,
4387
+ optionDepth,
4083
4388
  padToWidth,
4084
4389
  parseValue,
4085
4390
  planTable,
@@ -4087,7 +4392,9 @@ export {
4087
4392
  transformFrames,
4088
4393
  transformResult,
4089
4394
  truncateToWidth,
4395
+ typeFromWire,
4090
4396
  typeNameFromCode,
4397
+ typeToWire,
4091
4398
  unwrapOptionType,
4092
4399
  validateShape,
4093
4400
  valueRole,