imodel 0.2.0 → 0.3.0

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * imodel v0.2.0
2
+ * imodel v0.3.0
3
3
  * (c) 2019-2025 undefined
4
4
  * @license undefined
5
5
  */
@@ -18,8 +18,6 @@ declare namespace values {
18
18
  interface Environment<T extends object> {
19
19
  transaction: T | null;
20
20
  isDevelopment: boolean;
21
- names?: Record<string, string> | null;
22
- getName(table: string): string;
23
21
  values: typeof values;
24
22
  }
25
23
 
@@ -570,18 +568,9 @@ interface VirtualTable<E extends object = object> {
570
568
 
571
569
  /** 字段基本类型 */
572
570
  interface FieldType {
573
- /** 基本的 Id 类型,具体数据库实现由数据库决定 */
574
- id: string;
575
- /** 引用类型,具体数据库实现由数据库决定,需要与 id 类型一致 */
576
- rid: string;
577
- /** 弱引用类型,需要考虑跨数据库引擎实现 */
578
- ref: string;
579
571
  i16: number;
580
572
  i32: number;
581
573
  i64: bigint;
582
- u16: number;
583
- u32: number;
584
- u64: bigint;
585
574
  f32: number;
586
575
  f64: number;
587
576
  decimal: number;
@@ -595,12 +584,13 @@ interface FieldType {
595
584
  ip: string;
596
585
  ipv4: string;
597
586
  ipv6: string;
587
+ ipnet: string;
588
+ ipnetv4: string;
589
+ ipnetv6: string;
598
590
  mac48: string;
599
591
  mac64: string;
600
592
  /** 布尔型 */
601
593
  bool: boolean;
602
- /** 二进制类型 */
603
- binary: ArrayBuffer | ArrayBufferView;
604
594
  /** 日期类型 */
605
595
  date: Date;
606
596
  /** 时间类型 */
@@ -630,16 +620,12 @@ type FieldSpecific = FieldSpecificValue | {
630
620
  computed?(): PromiseLike<FieldSpecificValue> | FieldSpecificValue;
631
621
  };
632
622
  interface FieldDefineOption {
633
- /** 精确度 */
634
- precision?: number;
635
623
  /** 缩放比 */
636
624
  scale?: number;
637
625
  /** 占用空间大小 */
638
626
  size?: number;
639
627
  /** 是否为主键 */
640
- primary?: number | boolean;
641
- /** 序列字段 */
642
- serial?: boolean;
628
+ primary?: number;
643
629
  /** 唯一索引? */
644
630
  unique?: boolean;
645
631
  /** 索引信息 */
@@ -812,6 +798,27 @@ interface MatchArg extends Omit<TableDefine<Fields<keyof FieldType>>, 'table'> {
812
798
  where?: WhereValue[];
813
799
  }
814
800
  type BuildValue<T extends TableDefine> = T extends Build<infer R> ? R : object;
801
+ interface DBField {
802
+ type: string;
803
+ size: number;
804
+ scale: number;
805
+ default?: any;
806
+ nullable: boolean;
807
+ array: boolean;
808
+ primary?: number;
809
+ }
810
+ interface DBIndex {
811
+ fields: string[];
812
+ includes: string[];
813
+ unique: boolean;
814
+ name?: string;
815
+ }
816
+ interface DBTable {
817
+ table: string;
818
+ fields: Record<string, DBField>;
819
+ indexes: DBIndex[];
820
+ primary?: string;
821
+ }
815
822
  interface IConnection<E extends object = object> {
816
823
  /** 数据库类型 */
817
824
  readonly dbType: string;
@@ -847,6 +854,8 @@ interface IConnection<E extends object = object> {
847
854
  dropView(environment: Environment<E>, name: string): PromiseLike<number>;
848
855
  createMaterializedView(environment: Environment<E>, name: string, q: SelectArg): PromiseLike<number>;
849
856
  dropMaterializedView(environment: Environment<E>, name: string): PromiseLike<number>;
857
+ loadTables(environment: Environment<E>, tables: string[]): PromiseLike<DBTable[]>;
858
+ syncTables(environment: Environment<E>, tables: DBTable[]): PromiseLike<void>;
850
859
  transaction<R>(environment: Environment<E>, fn: (t: E) => R | PromiseLike<R>): PromiseLike<R>;
851
860
  }
852
861
  interface Skip {
@@ -869,18 +878,13 @@ declare class Connection<E extends {} = {}> {
869
878
  *
870
879
  * @param {PromiseLike<IConnection<E>> | IConnection<E>} connection
871
880
  * @param {E?} [transaction]
872
- * @param {Record<string, string>?} [names]
873
881
  */
874
- constructor(connection: PromiseLike<IConnection<E>> | IConnection<E>, transaction?: E | null, names?: Record<string, string> | null);
882
+ constructor(connection: PromiseLike<IConnection<E>> | IConnection<E>, transaction?: E | null);
875
883
  /**
876
884
  *
877
- * @param {object} [options]
878
- * @param {Record<string, string>?} [options.names]
879
885
  * @returns {Connection<E>}
880
886
  */
881
- clone({ names }?: {
882
- names?: Record<string, string> | null | undefined;
883
- }): Connection<E>;
887
+ clone(): Connection<E>;
884
888
  /** @return {Promise<string>} */
885
889
  dbType(): Promise<string>;
886
890
  /** @return {Promise<string>} */
@@ -1177,6 +1181,21 @@ declare class Connection<E extends {} = {}> {
1177
1181
  */
1178
1182
  dropMaterializedView(view: string): Promise<number>;
1179
1183
  abort(): boolean;
1184
+ /**
1185
+ * @param {string} table
1186
+ * @returns {Promise<DBTable?>}
1187
+ */
1188
+ loadTable(table: string): Promise<DBTable | null>;
1189
+ /**
1190
+ * @param {string[]} tables
1191
+ * @returns {Promise<DBTable[]>}
1192
+ */
1193
+ loadTables(tables: string[]): Promise<DBTable[]>;
1194
+ /**
1195
+ * @param {DBTable[]} tables
1196
+ * @returns {Promise<void>}
1197
+ */
1198
+ syncTables(tables: DBTable[]): Promise<void>;
1180
1199
  /**
1181
1200
  * @template T
1182
1201
  * @overload
@@ -1446,17 +1465,6 @@ declare function field$1<T extends keyof FieldType>(type: T, options: {
1446
1465
  [k: string]: any;
1447
1466
  } & FieldDefineOption): FieldDecorator<ToType<T, boolean, boolean>>;
1448
1467
 
1449
- /** @import { ToFieldType } from '../types' */
1450
- /** @import { FieldDecorator } from './index.mjs' */
1451
- /**
1452
- * @param {object} [options]
1453
- * @param {number?} [options.sort]
1454
- * @returns {FieldDecorator<ToFieldType<'id'>>}
1455
- */
1456
- declare function id({ sort }?: {
1457
- sort?: number | null | undefined;
1458
- }): FieldDecorator<ToFieldType<"id">>;
1459
-
1460
1468
  /** @import { FieldDecorator } from './index.mjs' */
1461
1469
  /**
1462
1470
  * @param {string} prop
@@ -1614,20 +1622,20 @@ declare function submodel<T extends Record<string, any>>(type: TableDefine, cons
1614
1622
  declare function submodel<T extends Record<string, any>, A extends boolean = boolean>(type: TableDefine, constraints: Record<string, Constraint>, array: A, options?: FieldDefineOption | undefined): FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>;
1615
1623
 
1616
1624
  /**
1617
- * @param {number} [precision]
1625
+ * @param {number} [size]
1618
1626
  * @returns {FieldDecorator<Date?>}
1619
1627
  */
1620
- declare function creating(precision?: number): FieldDecorator<Date | null>;
1628
+ declare function creating(size?: number): FieldDecorator<Date | null>;
1621
1629
  /**
1622
- * @param {number} [precision]
1630
+ * @param {number} [size]
1623
1631
  * @returns {FieldDecorator<Date?>}
1624
1632
  */
1625
- declare function updating(precision?: number): FieldDecorator<Date | null>;
1633
+ declare function updating(size?: number): FieldDecorator<Date | null>;
1626
1634
  /**
1627
- * @param {number} [precision]
1635
+ * @param {number} [size]
1628
1636
  * @returns {FieldDecorator<Date?>}
1629
1637
  */
1630
- declare function deleting(precision?: number): FieldDecorator<Date | null>;
1638
+ declare function deleting(size?: number): FieldDecorator<Date | null>;
1631
1639
 
1632
1640
  type ClassDecorator = (val: Function, ctx: ClassDecoratorContext) => any;
1633
1641
  type FieldDecorator<T> = (val: {
@@ -1636,7 +1644,7 @@ type FieldDecorator<T> = (val: {
1636
1644
  }, ctx: ClassAccessorDecoratorContext) => any;
1637
1645
 
1638
1646
  type QueryOptions<T extends Fields, TB extends unknown = any> = {
1639
- table: string;
1647
+ table?: string | VirtualTable<object> | undefined;
1640
1648
  fields: T;
1641
1649
  pseudo?: string | undefined;
1642
1650
  build?: ((a: object, b?: object | boolean) => TB) | null | undefined;
@@ -1645,7 +1653,7 @@ type QueryOptions<T extends Fields, TB extends unknown = any> = {
1645
1653
  * @template {Fields} T
1646
1654
  * @template {object} [TB=object]
1647
1655
  * @typedef {object} QueryOptions
1648
- * @property {string} table
1656
+ * @property {string | VirtualTable} [table]
1649
1657
  * @property {T} fields
1650
1658
  * @property {string} [pseudo]
1651
1659
  * @property {((a: object, b?: object | boolean) => TB)?} [build]
@@ -1670,8 +1678,8 @@ declare class Query<T extends Fields, TB extends unknown = any> implements Query
1670
1678
  * @param {QueryOptions<T, TB> | Query<T, TB>} options
1671
1679
  */
1672
1680
  constructor(options: QueryOptions<T, TB> | Query<T, TB>);
1673
- /** @readonly @type {string} */
1674
- readonly table: string;
1681
+ /** @readonly @type {string | VirtualTable | undefined} */
1682
+ readonly table: string | VirtualTable | undefined;
1675
1683
  /** @readonly @type {T} */
1676
1684
  readonly fields: T;
1677
1685
  /** @readonly @type {string} */
@@ -1831,6 +1839,23 @@ declare class Query<T extends Fields, TB extends unknown = any> implements Query
1831
1839
  #private;
1832
1840
  }
1833
1841
 
1842
+ /** @import { Fields, IndexInfo, FieldDefine } from './types' */
1843
+ /**
1844
+ *
1845
+ * @param {Fields} fields
1846
+ * @returns
1847
+ */
1848
+ declare function getPrimaryFields(fields: Fields): string[];
1849
+ /**
1850
+ * @param {string[]} fields
1851
+ * @param {Record<string, any>} data
1852
+ */
1853
+ declare function toPrimary(fields: string[], data: Record<string, any>): string; /**
1854
+ * @param {{fields: Fields}} model
1855
+ * @param {Record<string, any> | Record<string, any>[]} documents
1856
+ */
1857
+ declare function toPrimaries(model: any, documents: any): string | string[];
1858
+
1834
1859
  /**
1835
1860
  * @implements {Save}
1836
1861
  * @implements {Destroy}
@@ -1895,6 +1920,7 @@ declare class Model implements Save, Destroy, PseudoDestroy {
1895
1920
  [x: string]: any;
1896
1921
  };
1897
1922
  get $fieldChanged(): boolean;
1923
+ $primary(): string;
1898
1924
  /**
1899
1925
  * @overload
1900
1926
  * @param {Record<string, any>} key
@@ -2187,4 +2213,4 @@ declare function field<T extends MainFieldType>(type: T, options: {
2187
2213
  declare function setDevelopment(d?: boolean): void;
2188
2214
  declare let isDevelopment: boolean;
2189
2215
 
2190
- export { Build, type BuildValue, type ClassDecorator, type Column, type ColumnOptions, Connection, type Constraint, type CountArg, Create, Destroy, type Environment, type FieldDecorator, type FieldDefine, type FieldDefineOption, type FieldDefineType, type FieldSpecific, type FieldSpecificValue, type FieldType, type FieldTypeDefine, type FieldValue, type Fields, type FindRange, type GetName, type IConnection, type Index, type IndexInfo, type IndexOptions, type Join, type JoinType, type MainFieldType, type MatchArg, type MaybePromise, Model, type Options, PseudoDestroy, type Querier, Query, type QueryOptions, type Queryable, Save, Select, type SelectArg, SetValue, type Skip, Submodel, type Support, type TableDefine, type TableType, type ToFieldType, type ToType, type TransactionFn, Where, type WhereItem, type WhereLike, type WhereOr, type WhereRaw, type WhereValue, type Wheres, creating, decrement, field as define, deleted, deleting, divide, field$1 as field, getPrimaryKeys, id, immutable, increment, index, isDevelopment, isPseudo, submodel as model, multiply, now, primary, prop, pseudo, setDevelopment, sort, submodel, toNot, undeleted, updating, values, withDeleted };
2216
+ export { Build, type BuildValue, type ClassDecorator, type Column, type ColumnOptions, Connection, type Constraint, type CountArg, Create, type DBField, type DBIndex, type DBTable, Destroy, type Environment, type FieldDecorator, type FieldDefine, type FieldDefineOption, type FieldDefineType, type FieldSpecific, type FieldSpecificValue, type FieldType, type FieldTypeDefine, type FieldValue, type Fields, type FindRange, type GetName, type IConnection, type Index, type IndexInfo, type IndexOptions, type Join, type JoinType, type MainFieldType, type MatchArg, type MaybePromise, Model, type Options, PseudoDestroy, type Querier, Query, type QueryOptions, type Queryable, Save, Select, type SelectArg, SetValue, type Skip, Submodel, type Support, type TableDefine, type TableType, type ToFieldType, type ToType, type TransactionFn, type VirtualTable, Where, type WhereItem, type WhereLike, type WhereOr, type WhereRaw, type WhereValue, type Wheres, creating, decrement, field as define, deleted, deleting, divide, field$1 as field, getPrimaryFields, getPrimaryKeys, immutable, increment, index, isDevelopment, isPseudo, submodel as model, multiply, now, primary, prop, pseudo, setDevelopment, sort, submodel, toNot, toPrimaries, toPrimary, undeleted, updating, values, withDeleted };