imodel 0.15.0 → 0.15.1

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.15.0
2
+ * imodel v0.15.1
3
3
  * (c) 2019-2026 undefined
4
4
  * @license undefined
5
5
  */
@@ -566,7 +566,7 @@ declare namespace SetValue {
566
566
  }
567
567
 
568
568
  interface VirtualTable<E extends object = object> {
569
- insert(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, data: object[], key: string[]): PromiseLike<any[]>;
569
+ insert(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, data: object[], key: string[], ignoreConflict?: boolean): PromiseLike<any[]>;
570
570
  upsert(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, data: object[], key: string[], conflict: true | string[], conflictSet?: Record<string, SetValue>): PromiseLike<any[]>;
571
571
  update(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
572
572
  updateReturn(environment: Environment<E>, conn: IConnection<E>, returning: string[], columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
@@ -629,7 +629,7 @@ type MainFieldType = keyof FieldType | TableDefine | null;
629
629
  type ToFieldType<T> = T extends keyof FieldType ? FieldType[T] : unknown;
630
630
  type FieldSpecificValue = (string | number | bigint | boolean)[] | string | number | bigint | boolean | null | typeof now | typeof uuid;
631
631
  type FieldSpecific = FieldSpecificValue | {
632
- value: FieldSpecificValue;
632
+ value?: FieldSpecificValue;
633
633
  computed?(): PromiseLike<FieldSpecificValue> | FieldSpecificValue;
634
634
  };
635
635
  interface FieldDefineOption {
@@ -821,7 +821,7 @@ interface IConnection<E extends object = object> {
821
821
  */
822
822
  query(environment: Environment<E>, ...values: any): PromiseLike<any[]>;
823
823
  type(environment: Environment<E>, table: string): PromiseLike<TableType | null>;
824
- insert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[]): PromiseLike<any[]>;
824
+ insert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], ignoreConflict?: boolean): PromiseLike<any[]>;
825
825
  upsert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], conflict: true | string[], conflictSet?: Record<string, SetValue>): PromiseLike<any[]>;
826
826
  update(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
827
827
  updateReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
@@ -1534,12 +1534,33 @@ declare class Connection<E extends {} = {}> {
1534
1534
  destroyMany(queryable: Queryable, update?: Record<string, SetValue> | boolean): Promise<number>;
1535
1535
  /**
1536
1536
  * @template {object | object[]} T
1537
+ * @overload
1538
+ * @param {TableDefine} tableDefine
1539
+ * @param {T} data
1540
+ * @param {boolean} [ignoreConflict]
1541
+ * @returns {Promise<T extends object[] ? object[] : object>}
1542
+ */
1543
+ insert<T extends unknown>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean | undefined): Promise<T extends object[] ? object[] : object>;
1544
+ /**
1545
+ * @template {object | object[]} T
1546
+ * @overload
1537
1547
  * @param {TableDefine} tableDefine
1538
1548
  * @param {T} data
1539
1549
  * @param {string[]} [keys]
1550
+ * @param {boolean} [ignoreConflict]
1551
+ * @returns {Promise<T extends object[] ? object[] : object>}
1552
+ */
1553
+ insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T extends object[] ? object[] : object>;
1554
+ /**
1555
+ * @template {object | object[]} T
1556
+ * @overload
1557
+ * @param {TableDefine} tableDefine
1558
+ * @param {T} data
1559
+ * @param {string[] | boolean} [keys]
1560
+ * @param {boolean} [ignoreConflict]
1540
1561
  * @returns {Promise<T extends object[] ? object[] : object>}
1541
1562
  */
1542
- insert<T extends unknown>({ table, fields }: TableDefine, data: T, keys?: string[]): Promise<T extends object[] ? object[] : object>;
1563
+ insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T extends object[] ? object[] : object>;
1543
1564
  /**
1544
1565
  * @template {object | object[]} T
1545
1566
  * @overload
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * imodel v0.15.0
2
+ * imodel v0.15.1
3
3
  * (c) 2019-2026 undefined
4
4
  * @license undefined
5
5
  */
@@ -733,13 +733,10 @@ async function getSpecificValue(val) {
733
733
  computed,
734
734
  value
735
735
  } = val;
736
- if (value === void 0) {
737
- return;
738
- }
739
736
  if (typeof computed === 'function') {
740
737
  const value = await computed();
741
738
  if (value !== void 0) {
742
- return;
739
+ return value;
743
740
  }
744
741
  }
745
742
  return value;
@@ -2938,15 +2935,42 @@ class Connection {
2938
2935
  }
2939
2936
  /**
2940
2937
  * @template {object | object[]} T
2938
+ * @overload
2939
+ * @param {TableDefine} tableDefine
2940
+ * @param {T} data
2941
+ * @param {boolean} [ignoreConflict]
2942
+ * @returns {Promise<T extends object[] ? object[] : object>}
2943
+ */
2944
+ /**
2945
+ * @template {object | object[]} T
2946
+ * @overload
2941
2947
  * @param {TableDefine} tableDefine
2942
2948
  * @param {T} data
2943
2949
  * @param {string[]} [keys]
2950
+ * @param {boolean} [ignoreConflict]
2951
+ * @returns {Promise<T extends object[] ? object[] : object>}
2952
+ */
2953
+ /**
2954
+ * @template {object | object[]} T
2955
+ * @overload
2956
+ * @param {TableDefine} tableDefine
2957
+ * @param {T} data
2958
+ * @param {string[] | boolean} [keys]
2959
+ * @param {boolean} [ignoreConflict]
2960
+ * @returns {Promise<T extends object[] ? object[] : object>}
2961
+ */
2962
+ /**
2963
+ * @template {object | object[]} T
2964
+ * @param {TableDefine} tableDefine
2965
+ * @param {T} data
2966
+ * @param {string[] | boolean} [keys]
2967
+ * @param {boolean} [ignoreConflict]
2944
2968
  * @returns {Promise<T extends object[] ? object[] : object>}
2945
2969
  */
2946
2970
  async insert({
2947
2971
  table,
2948
2972
  fields
2949
- }, data, keys) {
2973
+ }, data, keys, ignoreConflict) {
2950
2974
  const [columns, fieldColumns] = toColumns(fields);
2951
2975
  const isArray = Array.isArray(data);
2952
2976
  const insertValues = (isArray ? data : [data]).map(d => getInsertValue(d, columns, fieldColumns, {
@@ -2955,15 +2979,17 @@ class Connection {
2955
2979
  if (!insertValues.length) {
2956
2980
  throw new Error();
2957
2981
  }
2958
- let insertKeys = fieldColumns ? [...new Set(keys || [])].map(k => fieldColumns[k]).filter(Boolean) : [...new Set(keys || [])].filter(k => k in columns);
2982
+ const allKeys = Array.isArray(keys) ? [...new Set(keys || [])] : [];
2983
+ let insertKeys = fieldColumns ? allKeys.map(k => fieldColumns[k]).filter(Boolean) : allKeys.filter(k => k in columns);
2959
2984
  if (!insertKeys.length && !isArray) {
2960
2985
  insertKeys = Object.entries(insertValues[0]).filter(([k, v]) => v !== undefined && k in columns).map(([k]) => k);
2961
2986
  }
2962
2987
  if (!insertKeys.length) {
2963
2988
  insertKeys = Object.entries(columns).map(v => v[0]);
2964
2989
  }
2990
+ const ignore = Boolean(Array.isArray(keys) ? ignoreConflict : keys);
2965
2991
  const conn = await this.#getConnection();
2966
- const result = table && typeof table === 'object' ? await table.insert(this.#env, conn, columns, insertValues, insertKeys) : await conn.insert(this.#env, table || '', columns, insertValues, insertKeys);
2992
+ const result = table && typeof table === 'object' ? await table.insert(this.#env, conn, columns, insertValues, insertKeys, ignore) : await conn.insert(this.#env, table || '', columns, insertValues, insertKeys, ignore);
2967
2993
  const list = toFieldList(result, fieldColumns);
2968
2994
  // @ts-ignore
2969
2995
  return isArray ? list : list[0];
package/migrate.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * imodel v0.15.0
2
+ * imodel v0.15.1
3
3
  * (c) 2019-2026 undefined
4
4
  * @license undefined
5
5
  */
package/migrate.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * imodel v0.15.0
2
+ * imodel v0.15.1
3
3
  * (c) 2019-2026 undefined
4
4
  * @license undefined
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imodel",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "main": "index.mjs",
5
5
  "type": "module",
6
6
  "repository": {