imodel 0.3.1 → 0.4.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,18 +1,20 @@
1
1
  /*!
2
- * imodel v0.3.1
2
+ * imodel v0.4.0
3
3
  * (c) 2019-2025 undefined
4
4
  * @license undefined
5
5
  */
6
6
 
7
7
  declare const now: unique symbol;
8
+ declare const uuid: unique symbol;
8
9
  declare const increment$1: unique symbol;
9
10
  declare const decrement$1: unique symbol;
10
11
  declare const multiply$1: unique symbol;
11
12
  declare const divide$1: unique symbol;
12
13
 
13
14
  declare const values_now: typeof now;
15
+ declare const values_uuid: typeof uuid;
14
16
  declare namespace values {
15
- export { decrement$1 as decrement, divide$1 as divide, increment$1 as increment, multiply$1 as multiply, values_now as now };
17
+ export { decrement$1 as decrement, divide$1 as divide, increment$1 as increment, multiply$1 as multiply, values_now as now, values_uuid as uuid };
16
18
  }
17
19
 
18
20
  interface Environment<T extends object> {
@@ -512,7 +514,7 @@ declare class Where {
512
514
  #private;
513
515
  }
514
516
 
515
- /** @typedef {SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | string | number | bigint | boolean | null | typeof now | (string | number | bigint | boolean)[]} SetValue */
517
+ /** @typedef {SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[]} SetValue */
516
518
  /** @typedef {{[values.increment]: number | bigint}} SetValue.Increment */
517
519
  /** @typedef {{[values.decrement]: number | bigint}} SetValue.Decrement */
518
520
  /** @typedef {{[values.multiply]: number | bigint}} SetValue.Multiply */
@@ -537,8 +539,7 @@ declare function multiply(value: number | bigint): SetValue.Multiply;
537
539
  * @returns {SetValue.Divide}
538
540
  */
539
541
  declare function divide(value: number | bigint): SetValue.Divide;
540
-
541
- type SetValue = SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | string | number | bigint | boolean | null | typeof now | (string | number | bigint | boolean)[];
542
+ type SetValue = SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[];
542
543
  declare namespace SetValue {
543
544
  type Increment = {
544
545
  [increment$1]: number | bigint;
@@ -555,15 +556,15 @@ declare namespace SetValue {
555
556
  }
556
557
 
557
558
  interface VirtualTable<E extends object = object> {
558
- insert(environment: Environment<E>, conn: IConnection<E>, table: string, fields: Fields<keyof FieldType>, data: object[], key: string[]): PromiseLike<any[]>;
559
- update(environment: Environment<E>, conn: IConnection<E>, args: MatchArg, update: Record<string, SetValue>): PromiseLike<number>;
560
- updateReturn(environment: Environment<E>, conn: IConnection<E>, args: MatchArg, update: Record<string, SetValue>, returning: string[]): PromiseLike<any[]>;
561
- updateMany(environment: Environment<E>, conn: IConnection<E>, table: string, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
562
- updateManyReturn(environment: Environment<E>, conn: IConnection<E>, table: string, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
563
- count(environment: Environment<E>, conn: IConnection<E>, argv: CountArg): PromiseLike<number>;
564
- select(environment: Environment<E>, conn: IConnection<E>, argv: SelectArg): PromiseLike<any[]>;
565
- delete(environment: Environment<E>, conn: IConnection<E>, argv: MatchArg): PromiseLike<number>;
566
- deleteReturn(environment: Environment<E>, conn: IConnection<E>, argv: MatchArg, returning: string[]): PromiseLike<any[]>;
559
+ insert(environment: Environment<E>, conn: IConnection<E>, fields: Fields<keyof FieldType>, data: object[], key: string[]): PromiseLike<any[]>;
560
+ update(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
561
+ updateReturn(environment: Environment<E>, conn: IConnection<E>, returning: string[], columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
562
+ updateMany(environment: Environment<E>, conn: IConnection<E>, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
563
+ updateManyReturn(environment: Environment<E>, conn: IConnection<E>, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
564
+ count(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, where: WhereValue[]): PromiseLike<number>;
565
+ find(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, argv: FindArg): PromiseLike<any[]>;
566
+ delete(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
567
+ deleteReturn(environment: Environment<E>, conn: IConnection<E>, returning: string[], columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
567
568
  }
568
569
 
569
570
  /** 字段基本类型 */
@@ -612,14 +613,15 @@ interface Constraint {
612
613
  field?: string;
613
614
  value?: any;
614
615
  }
615
- type MainFieldType = keyof FieldType | TableDefine;
616
+ type MainFieldType = keyof FieldType | TableDefine | null;
616
617
  type ToFieldType<T> = T extends keyof FieldType ? FieldType[T] : unknown;
617
- type FieldSpecificValue = (string | number | bigint | boolean)[] | string | number | bigint | boolean | null | typeof now;
618
+ type FieldSpecificValue = (string | number | bigint | boolean)[] | string | number | bigint | boolean | null | typeof now | typeof uuid;
618
619
  type FieldSpecific = FieldSpecificValue | {
619
620
  value: FieldSpecificValue;
620
621
  computed?(): PromiseLike<FieldSpecificValue> | FieldSpecificValue;
621
622
  };
622
623
  interface FieldDefineOption {
624
+ column?: string;
623
625
  /** 缩放比 */
624
626
  scale?: number;
625
627
  /** 占用空间大小 */
@@ -745,60 +747,24 @@ interface ColumnOptions<T = unknown> extends FieldDefineOption {
745
747
  default?: T extends never ? never : T;
746
748
  }
747
749
  interface Column<T> extends ColumnOptions<T> {
748
- name: string;
750
+ column: string;
749
751
  type: string;
750
752
  }
751
753
 
752
- /** 特性支持情况 */
753
- interface Support {
754
- /** 是否支持 sql 查询 */
755
- sql?: boolean;
756
- /** 是否支持数组类型 */
757
- array?: boolean;
758
- /** 是否支持对象存储 */
759
- object?: boolean;
760
- /** 是否支持递归查询 */
761
- recursive?: boolean;
762
- [key: string]: undefined | boolean;
763
- }
764
-
765
- type MaybePromise<T> = PromiseLike<T> | T;
766
-
767
- declare const Destroy: unique symbol;
768
- interface Destroy {
769
- [Destroy](connection: Connection, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
770
- }
771
- declare const PseudoDestroy: unique symbol;
772
- interface PseudoDestroy {
773
- [PseudoDestroy](connection: Connection, update: Record<string, SetValue>, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
774
- }
775
- declare const Save: unique symbol;
776
- interface Save {
777
- [Save](connection: Connection, run: (data: any, newData?: any) => Promise<object | null>, newData: Record<string, any> | null, table: TableDefine): PromiseLike<this | null>;
778
- }
779
- declare const Create: unique symbol;
780
- interface Create<T = unknown> {
781
- [Create](connection: Connection, data: object, run: (data: any) => Promise<object>, table: TableDefine): PromiseLike<T>;
782
- }
783
- declare const Build: unique symbol;
784
- interface Build<T = unknown> {
785
- [Build](data: object, others: object | boolean): T;
786
- }
787
-
788
754
  type TableType = '' | 'table' | 'view';
789
- interface CountArg extends Omit<TableDefine, 'table'>, Omit<Options, 'select'> {
790
- table: string;
791
- }
792
- interface SelectArg extends CountArg {
755
+ interface FindArg {
756
+ /** 排序配置,true 表示逆序 */
757
+ sort?: [field: string, desc: boolean][];
758
+ /** 匹配信息 */
759
+ where: WhereValue[];
793
760
  select: [string, Select][];
761
+ /** 偏移量 */
762
+ offset?: number;
763
+ /** 最大返回数 */
764
+ limit?: number;
794
765
  }
795
766
  type GetName = (table?: string) => string;
796
- interface MatchArg extends Omit<TableDefine<Fields<keyof FieldType>>, 'table'> {
797
- table: string;
798
- where?: WhereValue[];
799
- }
800
- type BuildValue<T extends TableDefine> = T extends Build<infer R> ? R : object;
801
- interface DBField {
767
+ interface DBColumn {
802
768
  type: string;
803
769
  size?: number;
804
770
  scale?: number;
@@ -815,7 +781,7 @@ interface DBIndex {
815
781
  }
816
782
  interface DBTable {
817
783
  table: string;
818
- fields: Record<string, DBField>;
784
+ fields: Record<string, DBColumn>;
819
785
  indexes?: DBIndex[];
820
786
  primary?: string;
821
787
  }
@@ -831,16 +797,16 @@ interface IConnection<E extends object = object> {
831
797
  */
832
798
  query(environment: Environment<E>, ...values: any): PromiseLike<any[]>;
833
799
  type(environment: Environment<E>, table: string): PromiseLike<TableType | null>;
834
- insert(environment: Environment<E>, table: string, fields: Fields<keyof FieldType>, data: object[], key: string[]): PromiseLike<any[]>;
835
- update(environment: Environment<E>, args: MatchArg, update: Record<string, SetValue>): PromiseLike<number>;
836
- updateReturn(environment: Environment<E>, args: MatchArg, update: Record<string, SetValue>, returning: string[]): PromiseLike<any[]>;
837
- updateMany(environment: Environment<E>, table: string, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
838
- updateManyReturn(environment: Environment<E>, table: string, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
839
- count(environment: Environment<E>, argv: CountArg): PromiseLike<number>;
840
- select(environment: Environment<E>, argv: SelectArg): PromiseLike<any[]>;
841
- delete(environment: Environment<E>, argv: MatchArg): PromiseLike<number>;
842
- deleteReturn(environment: Environment<E>, argv: MatchArg, returning: string[]): PromiseLike<any[]>;
843
- createTable(environment: Environment<E>, table: string, fields: Column<any>[]): PromiseLike<number>;
800
+ insert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], conflict?: boolean | Record<string, SetValue>): PromiseLike<any[]>;
801
+ update(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
802
+ updateReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
803
+ updateMany(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
804
+ updateManyReturn(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
805
+ count(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
806
+ find(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, argv: FindArg): PromiseLike<any[]>;
807
+ delete(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
808
+ deleteReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
809
+ createTable(environment: Environment<E>, table: string, columns: Column<any>[]): PromiseLike<number>;
844
810
  dropTable(environment: Environment<E>, table: string): PromiseLike<number>;
845
811
  renameTable(environment: Environment<E>, table: string, newName: string): PromiseLike<number>;
846
812
  addColumn(environment: Environment<E>, table: string, column: string, type: string, options: ColumnOptions<any>): PromiseLike<number>;
@@ -848,12 +814,8 @@ interface IConnection<E extends object = object> {
848
814
  changeColumnNull(environment: Environment<E>, table: string, column: string, nullable: boolean): PromiseLike<number>;
849
815
  dropColumn(environment: Environment<E>, table: string, column: string): PromiseLike<number>;
850
816
  renameColumn(environment: Environment<E>, table: string, column: string, newName: string): PromiseLike<number>;
851
- addIndex(environment: Environment<E>, table: string, name: string, fields: string[], options: IndexOptions): PromiseLike<number>;
817
+ addIndex(environment: Environment<E>, table: string, name: string, columns: string[], options: IndexOptions): PromiseLike<number>;
852
818
  dropIndex(environment: Environment<E>, table: string, name: string): PromiseLike<number>;
853
- createView(environment: Environment<E>, name: string, q: SelectArg): PromiseLike<number>;
854
- dropView(environment: Environment<E>, name: string): PromiseLike<number>;
855
- createMaterializedView(environment: Environment<E>, name: string, q: SelectArg): PromiseLike<number>;
856
- dropMaterializedView(environment: Environment<E>, name: string): PromiseLike<number>;
857
819
  loadTables(environment: Environment<E>, tables: string[]): PromiseLike<DBTable[]>;
858
820
  syncTables(environment: Environment<E>, tables: DBTable[]): PromiseLike<void>;
859
821
  transaction<R>(environment: Environment<E>, fn: (t: E) => R | PromiseLike<R>): PromiseLike<R>;
@@ -865,9 +827,41 @@ interface Skip {
865
827
  interface TransactionFn {
866
828
  <T>(fn: (t: Connection) => PromiseLike<T> | T): Promise<T>;
867
829
  }
868
- /** @deprecated */
869
- interface Querier<T> {
870
- (t: Connection): PromiseLike<T> | T;
830
+
831
+ /** 特性支持情况 */
832
+ interface Support {
833
+ /** 是否支持 sql 查询 */
834
+ sql?: boolean;
835
+ /** 是否支持数组类型 */
836
+ array?: boolean;
837
+ /** 是否支持对象存储 */
838
+ object?: boolean;
839
+ /** 是否支持递归查询 */
840
+ recursive?: boolean;
841
+ [key: string]: undefined | boolean;
842
+ }
843
+
844
+ type MaybePromise<T> = PromiseLike<T> | T;
845
+
846
+ declare const Destroy: unique symbol;
847
+ interface Destroy {
848
+ [Destroy](connection: Connection, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
849
+ }
850
+ declare const PseudoDestroy: unique symbol;
851
+ interface PseudoDestroy {
852
+ [PseudoDestroy](connection: Connection, update: Record<string, SetValue>, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
853
+ }
854
+ declare const Save: unique symbol;
855
+ interface Save {
856
+ [Save](connection: Connection, run: (data: any, newData?: any) => Promise<object | null>, newData: Record<string, any> | null, table: TableDefine): PromiseLike<this | null>;
857
+ }
858
+ declare const Create: unique symbol;
859
+ interface Create<T = unknown> {
860
+ [Create](connection: Connection, data: object, run: (data: any) => Promise<object>, table: TableDefine): PromiseLike<T>;
861
+ }
862
+ declare const Build: unique symbol;
863
+ interface Build<T = unknown> {
864
+ [Build](data: object, others: object | boolean): T;
871
865
  }
872
866
 
873
867
  /**
@@ -1158,28 +1152,6 @@ declare class Connection<E extends {} = {}> {
1158
1152
  * @returns {Promise<number>}
1159
1153
  */
1160
1154
  renameTable(table: string, newName: string): Promise<number>;
1161
- /**
1162
- * @param {string} view
1163
- * @param {Queryable} queryable
1164
- * @returns {Promise<number>}
1165
- */
1166
- createView(view: string, queryable: Queryable): Promise<number>;
1167
- /**
1168
- * @param {string} view
1169
- * @returns {Promise<number>}
1170
- */
1171
- dropView(view: string): Promise<number>;
1172
- /**
1173
- * @param {string} view
1174
- * @param {Queryable} queryable
1175
- * @returns {Promise<number>}
1176
- */
1177
- createMaterializedView(view: string, queryable: Queryable): Promise<number>;
1178
- /**
1179
- * @param {string} view
1180
- * @returns {Promise<number>}
1181
- */
1182
- dropMaterializedView(view: string): Promise<number>;
1183
1155
  abort(): boolean;
1184
1156
  /**
1185
1157
  * @param {string} table
@@ -1219,10 +1191,10 @@ declare class Connection<E extends {} = {}> {
1219
1191
  /** @import { Fields } from './types' */
1220
1192
  /**
1221
1193
  *
1222
- * @param {Fields} fields
1194
+ * @param {Fields} fieldsOrColumns
1223
1195
  * @returns {string[]}
1224
1196
  */
1225
- declare function getPrimaryKeys(fields: Fields): string[];
1197
+ declare function getPrimaryKeys(fieldsOrColumns: Fields): string[];
1226
1198
 
1227
1199
  /**
1228
1200
  *
@@ -1478,6 +1450,14 @@ declare function field$1<T extends keyof FieldType>(type: T, options: {
1478
1450
  */
1479
1451
  declare function prop(prop: string, value: any): FieldDecorator<any>;
1480
1452
 
1453
+ /** @import { FieldDecorator } from './index.mjs' */
1454
+ /**
1455
+ *
1456
+ * @param {string} [column]
1457
+ * @returns {FieldDecorator<any>}
1458
+ */
1459
+ declare function column(column?: string): FieldDecorator<any>;
1460
+
1481
1461
  /** @import { FieldDecorator } from './index.mjs' */
1482
1462
  /**
1483
1463
  *
@@ -2218,4 +2198,4 @@ declare function field<T extends MainFieldType>(type: T, options: {
2218
2198
  declare function setDevelopment(d?: boolean): void;
2219
2199
  declare let isDevelopment: boolean;
2220
2200
 
2221
- 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 };
2201
+ export { Build, type ClassDecorator, type Column, type ColumnOptions, Connection, type Constraint, Create, type DBColumn, 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 FindArg, type FindRange, type GetName, type IConnection, type Index, type IndexInfo, type IndexOptions, type Join, type JoinType, type MainFieldType, type MaybePromise, Model, type Options, PseudoDestroy, Query, type QueryOptions, type Queryable, Save, Select, 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, column, 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, uuid, values, withDeleted };