rado 0.2.35 → 0.2.36

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.
@@ -56,7 +56,7 @@ export declare class PrimaryColumn<T, K> extends ValueColumn<string extends K ?
56
56
  [Column.IsPrimary]: K;
57
57
  }
58
58
  export interface ObjectColumn<T> {
59
- <X extends T = T>(): Column<T extends null ? X | null : X> & Fields<X>;
59
+ <X extends T = T>(): Column<T extends null ? X | null : X> & Fields<T extends null ? X | null : X>;
60
60
  }
61
61
  export declare class ObjectColumn<T> extends Callable implements Column<T> {
62
62
  [Column.Type]: T;
@@ -162,12 +162,16 @@ export declare class Expr<T> {
162
162
  sure(): Expr<NonNullable<T>>;
163
163
  get<T>(name: string): Expr<T>;
164
164
  }
165
+ export interface ObjectExpr {
166
+ [Expr.Data]: ExprData;
167
+ }
165
168
  export declare namespace Expr {
166
169
  const Data: unique symbol;
167
170
  const IsExpr: unique symbol;
168
171
  const ToExpr: unique symbol;
169
172
  const NULL: Expr<null>;
170
173
  function value<T>(value: T): Expr<T>;
174
+ function get<T = any>(expr: ObjectExpr, field: string): Expr<T>;
171
175
  function create<T>(input: EV<T>): Expr<T>;
172
176
  function and(...conditions: Array<EV<boolean>>): Expr<boolean>;
173
177
  function or(...conditions: Array<EV<boolean>>): Expr<boolean>;
@@ -396,6 +396,10 @@ class Expr {
396
396
  return new Expr2(new ExprData.Param(new ParamData.Value(value2)));
397
397
  }
398
398
  Expr2.value = value;
399
+ function get(expr, field) {
400
+ return new Expr2(new ExprData.Field(expr[Expr2.Data], field));
401
+ }
402
+ Expr2.get = get;
399
403
  function create(input) {
400
404
  if (isExpr(input))
401
405
  return input;
@@ -1,12 +1,18 @@
1
- import { Expr } from './Expr.js';
1
+ import { Column } from './Column.js';
2
+ import { Expr, ObjectExpr } from './Expr.js';
2
3
  type ObjectUnion<T> = {
3
4
  [K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
4
5
  };
5
- type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
6
- type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
6
+ type Expand<T> = {
7
+ [K in keyof T]: T[K];
8
+ } & {};
9
+ type ObjectField<T> = Expand<ObjectExpr & FieldsOf<ObjectUnion<T>>>;
7
10
  type FieldsOf<Row> = [Row] extends [Record<string, any>] ? {
8
11
  [K in keyof Row]-?: Field<Row[K]>;
9
12
  } : never;
13
+ type Field<T> = [NonNullable<T>] extends [{
14
+ [Column.IsPrimary]: any;
15
+ }] ? Expr<T> : [NonNullable<T>] extends [Array<any>] ? Expr<T> : [NonNullable<T>] extends [object] ? ObjectField<T> : Expr<T>;
10
16
  type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
11
- export type Fields<T> = IsStrictlyAny<T> extends true ? any : [T] extends [object] ? FieldsOf<T> : Field<T>;
17
+ export type Fields<T> = IsStrictlyAny<T> extends true ? any : Field<T>;
12
18
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.2.35",
3
+ "version": "0.2.36",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",