imodel 0.5.0 → 0.5.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 +38 -8
- package/index.mjs +97 -40
- package/migrate.d.mts +1 -1
- package/migrate.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.5.
|
|
2
|
+
* imodel v0.5.1
|
|
3
3
|
* (c) 2019-2025 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
declare const now: unique symbol;
|
|
8
|
-
|
|
9
|
-
declare const
|
|
8
|
+
/** @type {typeof now} now */
|
|
9
|
+
declare const uuid: symbol;
|
|
10
|
+
/** @type {typeof uuid} uuid */
|
|
11
|
+
declare const increment$1: typeof uuid;
|
|
10
12
|
declare const decrement$1: unique symbol;
|
|
11
13
|
declare const multiply$1: unique symbol;
|
|
12
14
|
declare const divide$1: unique symbol;
|
|
@@ -541,9 +543,7 @@ declare function multiply(value: number | bigint): SetValue.Multiply;
|
|
|
541
543
|
declare function divide(value: number | bigint): SetValue.Divide;
|
|
542
544
|
type SetValue = SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[];
|
|
543
545
|
declare namespace SetValue {
|
|
544
|
-
type Increment = {
|
|
545
|
-
[increment$1]: number | bigint;
|
|
546
|
-
};
|
|
546
|
+
type Increment = {};
|
|
547
547
|
type Decrement = {
|
|
548
548
|
[decrement$1]: number | bigint;
|
|
549
549
|
};
|
|
@@ -639,6 +639,8 @@ interface FieldDefineOption {
|
|
|
639
639
|
updating?: FieldSpecific;
|
|
640
640
|
/** 伪删除时,自定义数据 */
|
|
641
641
|
deleting?: FieldSpecific;
|
|
642
|
+
/** 是否为可创建 */
|
|
643
|
+
uncreatable?: boolean;
|
|
642
644
|
/** 是否为固定值 */
|
|
643
645
|
immutable?: boolean;
|
|
644
646
|
/** 固定值 */
|
|
@@ -824,6 +826,7 @@ interface IConnection<E extends object = object> {
|
|
|
824
826
|
transaction<R>(environment: Environment<E>, fn: (t: E) => R | PromiseLike<R>): PromiseLike<R>;
|
|
825
827
|
}
|
|
826
828
|
interface Skip {
|
|
829
|
+
uncreatable?: boolean;
|
|
827
830
|
immutable?: boolean;
|
|
828
831
|
specific?: boolean;
|
|
829
832
|
}
|
|
@@ -965,9 +968,10 @@ declare class Connection<E extends {} = {}> {
|
|
|
965
968
|
* @param {TableDefine} model
|
|
966
969
|
* @param {T} data
|
|
967
970
|
* @param {Record<string, any>?} [newData]
|
|
971
|
+
* @param {Skip} [skip]
|
|
968
972
|
* @returns {Promise<(T extends Save ? T : object)?>}
|
|
969
973
|
*/
|
|
970
|
-
save<T>(model: TableDefine, data: T, newData?: Record<string, any> | null): Promise<(T extends Save ? T : object) | null>;
|
|
974
|
+
save<T>(model: TableDefine, data: T, newData?: Record<string, any> | null, skip?: Skip): Promise<(T extends Save ? T : object) | null>;
|
|
971
975
|
/**
|
|
972
976
|
*
|
|
973
977
|
* @template T
|
|
@@ -1469,6 +1473,10 @@ declare function column(column?: string): FieldDecorator<any>;
|
|
|
1469
1473
|
*/
|
|
1470
1474
|
declare function primary(primary?: number): FieldDecorator<any>;
|
|
1471
1475
|
|
|
1476
|
+
/** @import { FieldDecorator } from './index.mjs' */
|
|
1477
|
+
/** @returns {FieldDecorator<any>} */
|
|
1478
|
+
declare function uncreatable(): FieldDecorator<any>;
|
|
1479
|
+
|
|
1472
1480
|
/** @import { FieldDecorator } from './index.mjs' */
|
|
1473
1481
|
/** @returns {FieldDecorator<any>} */
|
|
1474
1482
|
declare function immutable(): FieldDecorator<any>;
|
|
@@ -1513,6 +1521,28 @@ declare function sort(sort: number): FieldDecorator<any>;
|
|
|
1513
1521
|
*/
|
|
1514
1522
|
declare function pseudo(pseudo: string): ClassDecorator;
|
|
1515
1523
|
|
|
1524
|
+
/**
|
|
1525
|
+
* @template T
|
|
1526
|
+
* @overload
|
|
1527
|
+
* @param {now} value
|
|
1528
|
+
* @returns {FieldDecorator<string | Date>}
|
|
1529
|
+
*/
|
|
1530
|
+
declare function defaultValue<T>(value: symbol): FieldDecorator<string | Date>;
|
|
1531
|
+
/**
|
|
1532
|
+
* @template T
|
|
1533
|
+
* @overload
|
|
1534
|
+
* @param {uuid} value
|
|
1535
|
+
* @returns {FieldDecorator<string>}
|
|
1536
|
+
*/
|
|
1537
|
+
declare function defaultValue<T>(value: symbol): FieldDecorator<string>;
|
|
1538
|
+
/**
|
|
1539
|
+
* @template T
|
|
1540
|
+
* @overload
|
|
1541
|
+
* @param {T} value
|
|
1542
|
+
* @returns {FieldDecorator<T>}
|
|
1543
|
+
*/
|
|
1544
|
+
declare function defaultValue<T>(value: T): FieldDecorator<T>;
|
|
1545
|
+
|
|
1516
1546
|
/**
|
|
1517
1547
|
*
|
|
1518
1548
|
* @overload
|
|
@@ -2241,4 +2271,4 @@ declare function field<T extends MainFieldType>(type: T, options: {
|
|
|
2241
2271
|
declare function setDevelopment(d?: boolean): void;
|
|
2242
2272
|
declare let isDevelopment: boolean;
|
|
2243
2273
|
|
|
2244
|
-
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, Scene, 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 };
|
|
2274
|
+
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, Scene, 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, defaultValue, 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, uncreatable, undeleted, updating, uuid, values, withDeleted };
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.5.
|
|
2
|
+
* imodel v0.5.1
|
|
3
3
|
* (c) 2019-2025 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
@@ -52,7 +52,9 @@ function isPseudo(model) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const now = Symbol();
|
|
55
|
+
/** @type {typeof now} now */
|
|
55
56
|
const uuid = Symbol();
|
|
57
|
+
/** @type {typeof uuid} uuid */
|
|
56
58
|
const increment$1 = Symbol();
|
|
57
59
|
const decrement$1 = Symbol();
|
|
58
60
|
const multiply$1 = Symbol();
|
|
@@ -135,16 +137,19 @@ async function getSpecificValue(val) {
|
|
|
135
137
|
return value;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
/** @import { Fields } from '../../types' */
|
|
140
|
+
/** @import { Fields, Skip } from '../../types' */
|
|
139
141
|
/**
|
|
140
142
|
*
|
|
141
143
|
* @param {Record<string, any>} data
|
|
142
144
|
* @param {Fields} columns
|
|
143
145
|
* @param {Record<string, string> | null} fieldColumns
|
|
146
|
+
* @param {Skip?} [skip]
|
|
144
147
|
* @param {Set<string>?} [ignore]
|
|
145
148
|
* @returns {Promise<Record<string, any>>}
|
|
146
149
|
*/
|
|
147
|
-
async function getInsertValue(data, columns, fieldColumns, ignore) {
|
|
150
|
+
async function getInsertValue(data, columns, fieldColumns, skip, ignore) {
|
|
151
|
+
const skipSpecific = skip?.specific;
|
|
152
|
+
const skipCreatable = skip?.uncreatable;
|
|
148
153
|
const insertValue = {};
|
|
149
154
|
for (const [k, col] of fieldColumns ? Object.entries(fieldColumns) : Object.keys(columns).map(v => [v, v])) {
|
|
150
155
|
const column = columns[col];
|
|
@@ -158,18 +163,20 @@ async function getInsertValue(data, columns, fieldColumns, ignore) {
|
|
|
158
163
|
insertValue[col] = fixedValue;
|
|
159
164
|
continue;
|
|
160
165
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
if (!skipSpecific) {
|
|
167
|
+
const creating = await getSpecificValue(column.creating);
|
|
168
|
+
if (creating !== void 0) {
|
|
169
|
+
insertValue[col] = creating;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const updating = await getSpecificValue(column.updating);
|
|
173
|
+
if (updating !== void 0) {
|
|
174
|
+
insertValue[col] = updating;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
170
177
|
}
|
|
171
178
|
const val = data[k];
|
|
172
|
-
if (val !== undefined) {
|
|
179
|
+
if (!skipCreatable && !column.uncreatable && val !== undefined) {
|
|
173
180
|
insertValue[col] = val;
|
|
174
181
|
continue;
|
|
175
182
|
}
|
|
@@ -317,7 +324,7 @@ function toFieldList(list, fieldColumns) {
|
|
|
317
324
|
return list.map(it => Object.fromEntries(map.map(([k, v]) => [k, it[v]])));
|
|
318
325
|
}
|
|
319
326
|
|
|
320
|
-
/** @import { Environment, FieldDefine, Fields, IConnection, TableDefine } from '../types' */
|
|
327
|
+
/** @import { Environment, FieldDefine, Fields, IConnection, Skip, TableDefine } from '../types' */
|
|
321
328
|
/**
|
|
322
329
|
*
|
|
323
330
|
* @param {any} p
|
|
@@ -353,9 +360,10 @@ function defaultMap(value, others) {
|
|
|
353
360
|
* @param {[string, FieldDefine<TableDefine>][]} fields
|
|
354
361
|
* @param {Record<string, any>[]} newList
|
|
355
362
|
* @param {Record<string, any>[]} list
|
|
363
|
+
* @param {Skip?} [skip]
|
|
356
364
|
* @returns {Promise<Record<string, any>[]>}
|
|
357
365
|
*/
|
|
358
|
-
async function createSub(conn, env, fields, newList, list) {
|
|
366
|
+
async function createSub(conn, env, fields, newList, list, skip) {
|
|
359
367
|
// TODO: 可创建字段过滤
|
|
360
368
|
if (!list.length) {
|
|
361
369
|
return list;
|
|
@@ -428,12 +436,12 @@ async function createSub(conn, env, fields, newList, list) {
|
|
|
428
436
|
const [columns, fieldColumns, tableFields] = toColumns(fields);
|
|
429
437
|
const insertKeys = Object.entries(columns).map(v => v[0]);
|
|
430
438
|
const ignore = new Set(fieldColumns ? constraintEntries.map(([k]) => fieldColumns[k]) : constraintEntries.map(([k]) => k));
|
|
431
|
-
const insertValues = await Promise.all(fieldValues.map(d => getInsertValue(d, columns, fieldColumns, ignore)));
|
|
439
|
+
const insertValues = await Promise.all(fieldValues.map(d => getInsertValue(d, columns, fieldColumns, skip, ignore)));
|
|
432
440
|
const {
|
|
433
441
|
table
|
|
434
442
|
} = type;
|
|
435
443
|
const result = (table && typeof table === 'object' ? table.insert(env, conn, columns, insertValues, insertKeys) : conn.insert(env, table || '', columns, insertValues, insertKeys)).then(r => toFieldList(r, fieldColumns));
|
|
436
|
-
promises.push(result.then(r => createSub(conn, env, tableFields, fieldValues, r)));
|
|
444
|
+
promises.push(result.then(r => createSub(conn, env, tableFields, fieldValues, r, skip)));
|
|
437
445
|
promises.push(array ? result.then(values => {
|
|
438
446
|
for (const [value] of allList) {
|
|
439
447
|
value[key] = values.filter(createFilter(value, commonKeys));
|
|
@@ -453,10 +461,11 @@ async function createSub(conn, env, fields, newList, list) {
|
|
|
453
461
|
* @param {Environment} env
|
|
454
462
|
* @param {TableDefine} model
|
|
455
463
|
* @param {any} p
|
|
456
|
-
* @param {
|
|
464
|
+
* @param {Skip?} [skip]
|
|
465
|
+
* @param {(a,b) => object} [mapDo]
|
|
457
466
|
* @returns {Promise<any>}
|
|
458
467
|
*/
|
|
459
|
-
async function create(conn, env, model, p, mapDo = defaultMap) {
|
|
468
|
+
async function create(conn, env, model, p, skip, mapDo = defaultMap) {
|
|
460
469
|
const {
|
|
461
470
|
table,
|
|
462
471
|
fields
|
|
@@ -478,7 +487,7 @@ async function create(conn, env, model, p, mapDo = defaultMap) {
|
|
|
478
487
|
records.push(data);
|
|
479
488
|
}
|
|
480
489
|
const [columns, fieldColumns, tableFields] = toColumns(fields);
|
|
481
|
-
const insertValues = await Promise.all(records.map(d => getInsertValue(d, columns, fieldColumns)));
|
|
490
|
+
const insertValues = await Promise.all(records.map(d => getInsertValue(d, columns, fieldColumns, skip)));
|
|
482
491
|
let insertKeys = [];
|
|
483
492
|
if (!insertKeys.length && !isArray) {
|
|
484
493
|
insertKeys = Object.entries(insertValues[0]).filter(([k, v]) => v !== undefined && k in columns).map(([k]) => k);
|
|
@@ -487,7 +496,7 @@ async function create(conn, env, model, p, mapDo = defaultMap) {
|
|
|
487
496
|
insertKeys = Object.entries(columns).map(([k]) => k);
|
|
488
497
|
}
|
|
489
498
|
const list = toFieldList(table && typeof table === 'object' ? await table.insert(env, conn, columns, insertValues, insertKeys) : await conn.insert(env, table || '', columns, insertValues, insertKeys), fieldColumns);
|
|
490
|
-
await createSub(conn, env, tableFields, records, list);
|
|
499
|
+
await createSub(conn, env, tableFields, records, list, skip);
|
|
491
500
|
const value = list.map((v, i) => mapDo(v, getOtherValues(records[i], fields)));
|
|
492
501
|
return isArray ? value : value[0];
|
|
493
502
|
}
|
|
@@ -871,7 +880,7 @@ async function getSetValue$1(columns, fieldColumns, update, skip) {
|
|
|
871
880
|
}
|
|
872
881
|
|
|
873
882
|
/* eslint-disable no-labels */
|
|
874
|
-
/** @import { Constraint, Environment, FieldDefine, IConnection, TableDefine } from '../types' */
|
|
883
|
+
/** @import { Constraint, Environment, FieldDefine, IConnection, Skip, TableDefine } from '../types' */
|
|
875
884
|
/** @import { WhereValue } from '../Where.mjs' */
|
|
876
885
|
/**
|
|
877
886
|
*
|
|
@@ -906,9 +915,10 @@ function classify(newList, oldList, keys, notFound, found) {
|
|
|
906
915
|
* @param {TableDefine} type
|
|
907
916
|
* @param {boolean} array
|
|
908
917
|
* @param {Record<string, Constraint>?} [constraints]
|
|
918
|
+
* @param {Skip} [skip]
|
|
909
919
|
* @returns
|
|
910
920
|
*/
|
|
911
|
-
async function updateItem(conn, env, updatedOldNewList, key, type, array, constraints) {
|
|
921
|
+
async function updateItem(conn, env, updatedOldNewList, key, type, array, constraints, skip) {
|
|
912
922
|
/** @type {any[]} */
|
|
913
923
|
const promises = [];
|
|
914
924
|
const constraintEntries = Object.entries(constraints || {});
|
|
@@ -1074,14 +1084,14 @@ async function updateItem(conn, env, updatedOldNewList, key, type, array, constr
|
|
|
1074
1084
|
}
|
|
1075
1085
|
// 批量新建
|
|
1076
1086
|
if (needCreate.length) {
|
|
1077
|
-
const subColumnData = await Promise.all(needCreate.map(d => getInsertValue(d, columns, fieldColumns, ignore)));
|
|
1087
|
+
const subColumnData = await Promise.all(needCreate.map(d => getInsertValue(d, columns, fieldColumns, skip, ignore)));
|
|
1078
1088
|
const list = (typeof table === 'object' ? table.insert(env, conn, columns, subColumnData, Object.keys(columns)) : conn.insert(env, table || '', columns, subColumnData, Object.keys(columns))).then(l => toFieldList(l, fieldColumns));
|
|
1079
1089
|
listPromises.push(list);
|
|
1080
|
-
promises.push(list.then(list => createSub(conn, env, tableFields, needCreate, list)));
|
|
1090
|
+
promises.push(list.then(list => createSub(conn, env, tableFields, needCreate, list, skip)));
|
|
1081
1091
|
}
|
|
1082
1092
|
promises.push(Promise.all(subPromises).then(
|
|
1083
1093
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1084
|
-
v => updateSub(conn, tableFields, v.flat(), env)));
|
|
1094
|
+
v => updateSub(conn, tableFields, v.flat(), env, skip)));
|
|
1085
1095
|
const allList = Promise.all(listPromises).then(v => v.flat());
|
|
1086
1096
|
promises.push(array ? allList.then(async values => {
|
|
1087
1097
|
for (const [value] of updatedOldNewList) {
|
|
@@ -1108,9 +1118,10 @@ async function updateItem(conn, env, updatedOldNewList, key, type, array, constr
|
|
|
1108
1118
|
* @param {[string, FieldDefine<TableDefine>][]} fields
|
|
1109
1119
|
* @param {[Record<string, any>, Record<string, any>, Record<string, any>][]} list
|
|
1110
1120
|
* @param {Environment} env
|
|
1121
|
+
* @param {Skip} [skip]
|
|
1111
1122
|
* @returns
|
|
1112
1123
|
*/
|
|
1113
|
-
async function updateSub(conn, fields, list, env) {
|
|
1124
|
+
async function updateSub(conn, fields, list, env, skip) {
|
|
1114
1125
|
if (!list.length) {
|
|
1115
1126
|
return;
|
|
1116
1127
|
}
|
|
@@ -1125,7 +1136,7 @@ async function updateSub(conn, fields, list, env) {
|
|
|
1125
1136
|
if (immutable) {
|
|
1126
1137
|
continue;
|
|
1127
1138
|
}
|
|
1128
|
-
promises.push(updateItem(conn, env, list, key, type, array, constraints));
|
|
1139
|
+
promises.push(updateItem(conn, env, list, key, type, array, constraints, skip));
|
|
1129
1140
|
}
|
|
1130
1141
|
await Promise.all(promises);
|
|
1131
1142
|
}
|
|
@@ -1136,9 +1147,10 @@ async function updateSub(conn, fields, list, env) {
|
|
|
1136
1147
|
* @param {Record<string, any>} data
|
|
1137
1148
|
* @param {Record<string, any>} newData
|
|
1138
1149
|
* @param {Environment} env
|
|
1150
|
+
* @param {Skip} [skip]
|
|
1139
1151
|
* @returns
|
|
1140
1152
|
*/
|
|
1141
|
-
async function updateData (conn, model, data, newData, env) {
|
|
1153
|
+
async function updateData (conn, model, data, newData, env, skip) {
|
|
1142
1154
|
const keys = Object.keys(newData);
|
|
1143
1155
|
if (!keys.length) {
|
|
1144
1156
|
return false;
|
|
@@ -1170,7 +1182,7 @@ async function updateData (conn, model, data, newData, env) {
|
|
|
1170
1182
|
const newList = [newData];
|
|
1171
1183
|
/** @type {[Record<string, any>, Record<string, any>, Record<string, any>][]} */
|
|
1172
1184
|
const updatedOldNewList = list.map((v, k) => [v, oldList[k], newList[k]]);
|
|
1173
|
-
await updateSub(conn, tableFields, updatedOldNewList, env);
|
|
1185
|
+
await updateSub(conn, tableFields, updatedOldNewList, env, skip);
|
|
1174
1186
|
return list[0];
|
|
1175
1187
|
}
|
|
1176
1188
|
|
|
@@ -1806,20 +1818,21 @@ class Connection {
|
|
|
1806
1818
|
* @template {TableDefine} T
|
|
1807
1819
|
* @param {T} model
|
|
1808
1820
|
* @param {object | object[]} p
|
|
1821
|
+
* @param {Skip} [skip]
|
|
1809
1822
|
* @returns {Promise<object[] | (T extends Build<infer R> ? R : object)>}
|
|
1810
1823
|
*/
|
|
1811
|
-
async create(model, p) {
|
|
1824
|
+
async create(model, p, skip) {
|
|
1812
1825
|
if (Array.isArray(p) || typeof model[Create] !== 'function') {
|
|
1813
1826
|
const modelBuild = model[Build];
|
|
1814
1827
|
const md = typeof modelBuild === 'function' ? modelBuild.bind(model) : undefined;
|
|
1815
1828
|
const conn = await this.#getConnection();
|
|
1816
|
-
return create(conn, this.#env, model, p, md);
|
|
1829
|
+
return create(conn, this.#env, model, p, skip, md);
|
|
1817
1830
|
}
|
|
1818
1831
|
// @ts-ignore
|
|
1819
1832
|
const m = /** @type {Create} */model;
|
|
1820
1833
|
return m[Create](this, p, async data => {
|
|
1821
1834
|
const conn = await this.#getConnection();
|
|
1822
|
-
return create(conn, this.#env, model, data);
|
|
1835
|
+
return create(conn, this.#env, model, data, skip);
|
|
1823
1836
|
}, model);
|
|
1824
1837
|
}
|
|
1825
1838
|
/**
|
|
@@ -1847,27 +1860,28 @@ class Connection {
|
|
|
1847
1860
|
* @param {TableDefine} model
|
|
1848
1861
|
* @param {T} data
|
|
1849
1862
|
* @param {Record<string, any>?} [newData]
|
|
1863
|
+
* @param {Skip} [skip]
|
|
1850
1864
|
* @returns {Promise<(T extends Save ? T : object)?>}
|
|
1851
1865
|
*/
|
|
1852
|
-
async save(model, data, newData) {
|
|
1866
|
+
async save(model, data, newData, skip) {
|
|
1853
1867
|
if (typeof data[Save] !== 'function') {
|
|
1854
1868
|
const conn = await this.#getConnection();
|
|
1855
1869
|
if (newData) {
|
|
1856
1870
|
/** @type {any} */
|
|
1857
1871
|
const doc = data;
|
|
1858
1872
|
// @ts-ignore
|
|
1859
|
-
return updateData(conn, model, doc, newData, this.#env);
|
|
1873
|
+
return updateData(conn, model, doc, newData, this.#env, skip);
|
|
1860
1874
|
}
|
|
1861
|
-
return create(conn, this.#env, model, data);
|
|
1875
|
+
return create(conn, this.#env, model, data, skip);
|
|
1862
1876
|
}
|
|
1863
1877
|
const r = /** @type {Save}*/data;
|
|
1864
1878
|
// @ts-ignore
|
|
1865
1879
|
return r[Save](this, async (doc, newData) => {
|
|
1866
1880
|
const conn = await this.#getConnection();
|
|
1867
1881
|
if (newData) {
|
|
1868
|
-
return updateData(conn, model, doc, newData, this.#env);
|
|
1882
|
+
return updateData(conn, model, doc, newData, this.#env, skip);
|
|
1869
1883
|
}
|
|
1870
|
-
return create(conn, this.#env, model, doc);
|
|
1884
|
+
return create(conn, this.#env, model, doc, skip);
|
|
1871
1885
|
}, newData || null, model);
|
|
1872
1886
|
}
|
|
1873
1887
|
/**
|
|
@@ -1979,7 +1993,9 @@ class Connection {
|
|
|
1979
1993
|
}, data, keys) {
|
|
1980
1994
|
const [columns, fieldColumns] = toColumns(fields);
|
|
1981
1995
|
const isArray = Array.isArray(data);
|
|
1982
|
-
const insertValues = (isArray ? data : [data]).map(d => getInsertValue(d, columns, fieldColumns
|
|
1996
|
+
const insertValues = (isArray ? data : [data]).map(d => getInsertValue(d, columns, fieldColumns, {
|
|
1997
|
+
uncreatable: true
|
|
1998
|
+
}));
|
|
1983
1999
|
if (!insertValues.length) {
|
|
1984
2000
|
throw new Error();
|
|
1985
2001
|
}
|
|
@@ -2586,6 +2602,7 @@ function submodel(type, constraints, p1, p2) {
|
|
|
2586
2602
|
unique,
|
|
2587
2603
|
index,
|
|
2588
2604
|
primary,
|
|
2605
|
+
uncreatable,
|
|
2589
2606
|
immutable,
|
|
2590
2607
|
text,
|
|
2591
2608
|
sort,
|
|
@@ -2597,6 +2614,7 @@ function submodel(type, constraints, p1, p2) {
|
|
|
2597
2614
|
type,
|
|
2598
2615
|
array,
|
|
2599
2616
|
nullable: false,
|
|
2617
|
+
uncreatable,
|
|
2600
2618
|
immutable
|
|
2601
2619
|
};
|
|
2602
2620
|
/**
|
|
@@ -2815,6 +2833,7 @@ function field$1(type, p1, p2) {
|
|
|
2815
2833
|
unique,
|
|
2816
2834
|
index,
|
|
2817
2835
|
primary,
|
|
2836
|
+
uncreatable,
|
|
2818
2837
|
immutable,
|
|
2819
2838
|
text,
|
|
2820
2839
|
sort,
|
|
@@ -2831,6 +2850,7 @@ function field$1(type, p1, p2) {
|
|
|
2831
2850
|
index,
|
|
2832
2851
|
unique: Boolean(unique),
|
|
2833
2852
|
primary,
|
|
2853
|
+
uncreatable,
|
|
2834
2854
|
immutable,
|
|
2835
2855
|
text,
|
|
2836
2856
|
sort
|
|
@@ -2980,6 +3000,12 @@ function primary(primary) {
|
|
|
2980
3000
|
return (_, ctx) => setProp(ctx, 'primary', primary || 1);
|
|
2981
3001
|
}
|
|
2982
3002
|
|
|
3003
|
+
/** @import { FieldDecorator } from './index.mjs' */
|
|
3004
|
+
/** @returns {FieldDecorator<any>} */
|
|
3005
|
+
function uncreatable() {
|
|
3006
|
+
return (_, ctx) => setProp(ctx, 'uncreatable', true);
|
|
3007
|
+
}
|
|
3008
|
+
|
|
2983
3009
|
/** @import { FieldDecorator } from './index.mjs' */
|
|
2984
3010
|
/** @returns {FieldDecorator<any>} */
|
|
2985
3011
|
function immutable() {
|
|
@@ -3125,6 +3151,35 @@ function pseudo(pseudo) {
|
|
|
3125
3151
|
};
|
|
3126
3152
|
}
|
|
3127
3153
|
|
|
3154
|
+
/** @import { now, uuid } from '../values.mjs' */
|
|
3155
|
+
/** @import { FieldDecorator } from './index.mjs' */
|
|
3156
|
+
/**
|
|
3157
|
+
* @template T
|
|
3158
|
+
* @overload
|
|
3159
|
+
* @param {now} value
|
|
3160
|
+
* @returns {FieldDecorator<string | Date>}
|
|
3161
|
+
*/
|
|
3162
|
+
/**
|
|
3163
|
+
* @template T
|
|
3164
|
+
* @overload
|
|
3165
|
+
* @param {uuid} value
|
|
3166
|
+
* @returns {FieldDecorator<string>}
|
|
3167
|
+
*/
|
|
3168
|
+
/**
|
|
3169
|
+
* @template T
|
|
3170
|
+
* @overload
|
|
3171
|
+
* @param {T} value
|
|
3172
|
+
* @returns {FieldDecorator<T>}
|
|
3173
|
+
*/
|
|
3174
|
+
/**
|
|
3175
|
+
* @template T
|
|
3176
|
+
* @param {T} value
|
|
3177
|
+
* @returns {FieldDecorator<any>}
|
|
3178
|
+
*/
|
|
3179
|
+
function defaultValue(value) {
|
|
3180
|
+
return (_, ctx) => setProp(ctx, 'default', value);
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3128
3183
|
/** @typedef {{toWhereValue(): WhereValue[][]}} WhereLike */
|
|
3129
3184
|
/** @typedef {WhereLike | Record<string, any> | (WhereLike | Record<string, any>)[]} Wheres */
|
|
3130
3185
|
/**
|
|
@@ -5432,6 +5487,7 @@ function field(type, {
|
|
|
5432
5487
|
default: def,
|
|
5433
5488
|
index,
|
|
5434
5489
|
primary,
|
|
5490
|
+
uncreatable,
|
|
5435
5491
|
immutable,
|
|
5436
5492
|
text,
|
|
5437
5493
|
sort,
|
|
@@ -5445,10 +5501,11 @@ function field(type, {
|
|
|
5445
5501
|
default: def,
|
|
5446
5502
|
index,
|
|
5447
5503
|
primary,
|
|
5504
|
+
uncreatable,
|
|
5448
5505
|
immutable,
|
|
5449
5506
|
text,
|
|
5450
5507
|
sort
|
|
5451
5508
|
};
|
|
5452
5509
|
}
|
|
5453
5510
|
|
|
5454
|
-
export { Build, Connection, Create, Destroy, Model, PseudoDestroy, Query, Save, Scene, Submodel, Where, 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 };
|
|
5511
|
+
export { Build, Connection, Create, Destroy, Model, PseudoDestroy, Query, Save, Scene, Submodel, Where, column, creating, decrement, defaultValue, 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, uncreatable, undeleted, updating, uuid, values, withDeleted };
|
package/migrate.d.mts
CHANGED
package/migrate.mjs
CHANGED