imodel 0.19.3 → 0.20.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.
Files changed (5) hide show
  1. package/index.d.mts +1676 -1922
  2. package/index.mjs +3108 -3059
  3. package/migrate.d.mts +5 -4
  4. package/migrate.mjs +31 -12
  5. package/package.json +3 -1
package/migrate.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * imodel v0.19.3
3
- * (c) 2019-2026 undefined
4
- * @license undefined
2
+ * imodel v0.20.1
3
+ * (c) 2019-2026 猛火Fierflame
4
+ * @license MIT
5
5
  */
6
6
 
7
7
  import { TransactionFn, Connection, IndexOptions, FieldType, ColumnOptions, Column, Index, TableDefine } from 'imodel';
@@ -622,4 +622,5 @@ type Migrator = {
622
622
  down: (connection: Connection, echoDescription: Echo) => PromiseLike<void> | void;
623
623
  };
624
624
 
625
- export { Echo, type MigrationDef, type MigrationDefine, type MigrationPromise, type MigrationValue, type Migrator, _default as auto, _default$1 as createEcho, customize, down, create as exec, mysql, postgres, revert, sqlite, sqlite3, table, type, up };
625
+ export { Echo, _default as auto, _default$1 as createEcho, customize, down, create as exec, mysql, postgres, revert, sqlite, sqlite3, table, type, up };
626
+ export type { MigrationDef, MigrationDefine, MigrationPromise, MigrationValue, Migrator };
package/migrate.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  /*!
2
- * imodel v0.19.3
3
- * (c) 2019-2026 undefined
4
- * @license undefined
2
+ * imodel v0.20.1
3
+ * (c) 2019-2026 猛火Fierflame
4
+ * @license MIT
5
5
  */
6
6
 
7
- import { now, Query, define } from 'imodel';
7
+ import { now, Query, define, actions } from 'imodel';
8
8
 
9
9
  /** @import { Connection } from 'imodel' */
10
10
  /** @typedef {import('./index.mjs').Migrator} Migrator */
11
11
  /** @import { Echo } from './createEcho.mjs' */
12
+
12
13
  /** @implements {Migrator} */
13
14
  class Reverter {
14
15
  /** @readonly @type {readonly Migrator[]} */
@@ -56,6 +57,7 @@ class Reverter {
56
57
  }
57
58
 
58
59
  /** @import { IndexOptions, ColumnOptions, FieldType } from 'imodel' */
60
+
59
61
  /**
60
62
  * @abstract
61
63
  */
@@ -143,6 +145,7 @@ class TableAdder {
143
145
  f64(name, options) {
144
146
  return this.field(name, 'f64', options);
145
147
  }
148
+
146
149
  /**
147
150
  * @param {string} name
148
151
  * @param {ColumnOptions<number | bigint>} [options]
@@ -167,6 +170,7 @@ class TableAdder {
167
170
  money(name, options) {
168
171
  return this.field(name, 'money', options);
169
172
  }
173
+
170
174
  /**
171
175
  * @param {string} name
172
176
  * @param {ColumnOptions<never>} [options]
@@ -313,11 +317,13 @@ class TableAdder {
313
317
  /** @typedef {import('./index.mjs').Migrator} Migrator */
314
318
  /** @import { Column, Connection, Index } from 'imodel' */
315
319
  /** @import { Echo } from './createEcho.mjs' */
320
+
316
321
  /**
317
322
  *
318
323
  * @param {TableCreator | TableModifier} v
319
324
  * @returns {string[]}
320
325
  */
326
+
321
327
  function getIndexes(v) {
322
328
  if (v instanceof TableCreator) {
323
329
  return Object.keys(v.indexes);
@@ -383,6 +389,7 @@ function get(v) {
383
389
  }
384
390
  return [fields, indexes, _columns, _indexes];
385
391
  }
392
+
386
393
  /**
387
394
  * @implements {Migrator}
388
395
  */
@@ -410,6 +417,7 @@ class TableDrop {
410
417
  tables(revert) {
411
418
  return revert ? [this.name] : [];
412
419
  }
420
+
413
421
  /**
414
422
  * @param {Connection} connection
415
423
  * @param {Echo} echoDescription
@@ -454,6 +462,7 @@ class TableDrop {
454
462
  /** @typedef {import('./index.mjs').Migrator} Migrator */
455
463
  /** @import { Column, ColumnOptions, Connection, Index, IndexOptions } from 'imodel' */
456
464
  /** @import { Echo } from './createEcho.mjs' */
465
+
457
466
  /**
458
467
  *
459
468
  * @param {string} name
@@ -528,6 +537,7 @@ class TableModifier extends TableAdder {
528
537
  tables(revert) {
529
538
  return revert ? [this.name] : [this.newName || this.name];
530
539
  }
540
+
531
541
  /**
532
542
  * @readonly
533
543
  * @type {(['field', string, Column<any>] | ['index', string, Index] | ['changeColumn', string, Column<any>] | ['removeColumn', string] | ['removeIndex', string] | ['renameColumn', string, string])[]}
@@ -602,6 +612,7 @@ class TableModifier extends TableAdder {
602
612
  this.name = last.name;
603
613
  }
604
614
  }
615
+
605
616
  /**
606
617
  * @param {string} name
607
618
  * @returns {this}
@@ -817,6 +828,7 @@ class TableModifier extends TableAdder {
817
828
  /** @typedef {import('./index.mjs').Migrator} Migrator */
818
829
  /** @import { Column, ColumnOptions, Connection, Index, IndexOptions, TableDefine } from 'imodel' */
819
830
  /** @import { Echo } from './createEcho.mjs' */
831
+
820
832
  /**
821
833
  * @implements {Migrator}
822
834
  */
@@ -977,6 +989,7 @@ class TableCreator extends TableAdder {
977
989
  /** @import { Connection } from 'imodel' */
978
990
  /** @import { Echo } from './createEcho.mjs' */
979
991
  /** @typedef {import('./index.mjs').Migrator} Migrator */
992
+
980
993
  /** @implements {Migrator} */
981
994
  class MigrationType {
982
995
  /** @readonly @type {readonly Migrator[]} */
@@ -1090,6 +1103,7 @@ class Customize {
1090
1103
  }
1091
1104
 
1092
1105
  /** @interface Echo */
1106
+
1093
1107
  /**
1094
1108
  *
1095
1109
  * @param {((v: string) => void) | boolean} [log]
@@ -1174,6 +1188,7 @@ async function create(connection, migrations, log, revert) {
1174
1188
  /** @typedef {MigrationValue | { default: MigrationValue }} MigrationDef */
1175
1189
  /** @typedef {MigrationDef | PromiseLike<MigrationDef>} MigrationPromise */
1176
1190
  /** @typedef {MigrationPromise | (() => MigrationPromise)} MigrationDefine */
1191
+
1177
1192
  const TableMigration = Query.table('__table_migrations', {
1178
1193
  group: define('string', {
1179
1194
  nullable: false,
@@ -1205,10 +1220,10 @@ async function run(t, info, group, revert) {
1205
1220
  title,
1206
1221
  list
1207
1222
  } = info;
1208
- const res = await t.first(TableMigration.where({
1223
+ const res = await t.call(actions.first(TableMigration.where({
1209
1224
  group,
1210
1225
  no
1211
- }));
1226
+ })));
1212
1227
  if (!revert !== !res) {
1213
1228
  return;
1214
1229
  }
@@ -1219,15 +1234,15 @@ async function run(t, info, group, revert) {
1219
1234
  const migrators = 'default' in value ? value.default || value : value;
1220
1235
  await create(t, migrators, console.log, revert);
1221
1236
  if (revert) {
1222
- await t.destroyMany(TableMigration.where({
1237
+ await t.call(actions.destroyMany(TableMigration.where({
1223
1238
  group,
1224
1239
  no
1225
- }));
1240
+ })));
1226
1241
  } else {
1227
- await t.create(TableMigration, {
1242
+ await t.call(actions.create(TableMigration, {
1228
1243
  group,
1229
1244
  no: BigInt(no)
1230
- });
1245
+ }));
1231
1246
  }
1232
1247
  } finally {
1233
1248
  console.groupEnd();
@@ -1289,6 +1304,7 @@ function getUpList(list, target) {
1289
1304
  }
1290
1305
  return list.filter(m => m.no <= target && m.no);
1291
1306
  }
1307
+
1292
1308
  /**
1293
1309
  *
1294
1310
  * @param {Info[]} list
@@ -1322,7 +1338,7 @@ async function initMigrate(connection, list, init, group) {
1322
1338
  group,
1323
1339
  no: BigInt(no)
1324
1340
  }));
1325
- return connection.create(TableMigration, noList);
1341
+ return connection.call(actions.create(TableMigration, noList));
1326
1342
  }
1327
1343
  /**
1328
1344
  *
@@ -1374,7 +1390,7 @@ async function auto (runTransaction, migrations, {
1374
1390
  const noQuery = TableMigration.where({
1375
1391
  group: g
1376
1392
  });
1377
- const n = await runTransaction(t => t.count(noQuery));
1393
+ const n = await runTransaction(t => t.call(actions.count(noQuery)));
1378
1394
  if (n) {
1379
1395
  return autoMigrate(runTransaction, up, down, g);
1380
1396
  }
@@ -1383,12 +1399,14 @@ async function auto (runTransaction, migrations, {
1383
1399
 
1384
1400
  /** @export { Echo } from './createEcho.mjs' */
1385
1401
  /** @export { MigrationValue, MigrationDef, MigrationPromise, MigrationDefine } from './auto.mjs' */
1402
+
1386
1403
  /**
1387
1404
  * @typedef {object} Migrator
1388
1405
  * @property {(revert?: boolean | undefined) => Iterable<string>} tables
1389
1406
  * @property {(connection: Connection, echoDescription: Echo) => PromiseLike<void> | void} up
1390
1407
  * @property {(connection: Connection, echoDescription: Echo) => PromiseLike<void> | void} down
1391
1408
  */
1409
+
1392
1410
  /**
1393
1411
  *
1394
1412
  * @param {((connection: Connection) => void | PromiseLike<void>)?} [up]
@@ -1437,6 +1455,7 @@ function revert(...list) {
1437
1455
  // export {
1438
1456
  // _catch as catch,
1439
1457
  // };
1458
+
1440
1459
  /**
1441
1460
  *
1442
1461
  * @param {string} type
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "imodel",
3
- "version": "0.19.3",
3
+ "version": "0.20.1",
4
4
  "main": "index.mjs",
5
5
  "type": "module",
6
+ "author": "猛火Fierflame",
7
+ "license": "MIT",
6
8
  "repository": {
7
9
  "type": "git",
8
10
  "url": "https://git@gitee.com/fierflame/imodel.git"