fib-orm 2.0.0 → 3.0.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/README.md +42 -6
- package/index.d.ts +11 -0
- package/index.js +15 -0
- package/package.json +36 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -26
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -31
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -28
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -10
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -33
- package/src/cli/helpers/ddl.ts +84 -0
- package/src/cli/helpers/package.ts +81 -0
- package/src/cli/index.ts +24 -0
- package/src/cli/wrapSubcommand.ts +66 -0
- package/src/db-driver/Typo.d.ts +141 -0
- package/src/db-driver/built-ins/base.class.ts +260 -0
- package/src/db-driver/built-ins/driver-dm.ts +62 -0
- package/src/db-driver/built-ins/driver-mssql.ts +67 -0
- package/src/db-driver/built-ins/driver-mysql.ts +44 -0
- package/src/db-driver/built-ins/driver-postgresql.ts +94 -0
- package/src/db-driver/built-ins/driver-redis.ts +45 -0
- package/src/db-driver/built-ins/driver-sqlite.ts +41 -0
- package/src/db-driver/index.ts +6 -0
- package/src/db-driver/parseQueryString.ts +76 -0
- package/src/db-driver/utils.ts +204 -0
- package/src/knex/deps/tarn/PendingOperation.ts +56 -0
- package/src/knex/deps/tarn/Pool.ts +610 -0
- package/src/knex/deps/tarn/PromiseInspection.ts +29 -0
- package/src/knex/deps/tarn/Resource.ts +22 -0
- package/src/knex/deps/tarn/TimeoutError.ts +1 -0
- package/src/knex/deps/tarn/tarn.ts +7 -0
- package/src/knex/deps/tarn/utils.ts +62 -0
- package/src/knex/knex.ts +11 -0
- package/src/knex/result.d.ts +27 -0
- package/src/knex/sandbox.ts +45 -0
- package/src/knex/tables.d.ts +4 -0
- package/src/knex/types.d.ts +3228 -0
- package/src/orm/Adapters.ts +53 -0
- package/src/orm/AggregateFunctions.ts +254 -0
- package/src/orm/Associations/Extend.ts +405 -0
- package/src/orm/Associations/Many.ts +784 -0
- package/src/orm/Associations/One.ts +494 -0
- package/src/orm/Associations/_utils.ts +72 -0
- package/src/orm/ChainFind.ts +427 -0
- package/src/orm/ChainInstance.ts +97 -0
- package/src/orm/Debug.ts +21 -0
- package/src/orm/Drivers/DB/base.ts +7 -0
- package/src/orm/Drivers/DB/dm.ts +35 -0
- package/src/orm/Drivers/DB/mssql.ts +35 -0
- package/src/orm/Drivers/DB/mysql.ts +35 -0
- package/src/orm/Drivers/DB/postgres.ts +35 -0
- package/src/orm/Drivers/DB/sqlite3.ts +60 -0
- package/src/orm/Drivers/DML/_ddl-sql.ts +85 -0
- package/src/orm/Drivers/DML/_dml-helpers.ts +66 -0
- package/src/orm/Drivers/DML/_shared.ts +61 -0
- package/src/orm/Drivers/DML/_utils.ts +112 -0
- package/{lib/orm/Drivers/DML/dm.js → src/orm/Drivers/DML/dm.ts} +178 -85
- package/src/orm/Drivers/DML/index.ts +10 -0
- package/src/orm/Drivers/DML/mssql.ts +366 -0
- package/src/orm/Drivers/DML/mysql.ts +347 -0
- package/src/orm/Drivers/DML/postgres.ts +382 -0
- package/src/orm/Drivers/DML/sqlite.ts +361 -0
- package/src/orm/Error.ts +49 -0
- package/src/orm/Helpers.ts +297 -0
- package/src/orm/Hook.ts +125 -0
- package/src/orm/Instance.ts +944 -0
- package/src/orm/LazyLoad.ts +117 -0
- package/src/orm/Model.ts +1235 -0
- package/src/orm/ORM.ts +301 -0
- package/src/orm/Patch/fib-cache.ts +7 -0
- package/src/orm/Patch/plugin.ts +25 -0
- package/src/orm/Property.ts +86 -0
- package/src/orm/Settings.ts +134 -0
- package/src/orm/Singleton.ts +97 -0
- package/src/orm/Typo/Adapter.d.ts +5 -0
- package/src/orm/Typo/DMLDriver.d.ts +260 -0
- package/src/orm/Typo/Db.d.ts +100 -0
- package/src/orm/Typo/Error.d.ts +36 -0
- package/src/orm/Typo/ORM.d.ts +315 -0
- package/src/orm/Typo/Validators.d.ts +39 -0
- package/src/orm/Typo/_common.d.ts +44 -0
- package/src/orm/Typo/assoc.d.ts +280 -0
- package/src/orm/Typo/hook.d.ts +68 -0
- package/src/orm/Typo/instance.d.ts +214 -0
- package/{lib → src}/orm/Typo/model.d.ts +297 -176
- package/src/orm/Typo/patch.d.ts +39 -0
- package/src/orm/Typo/property.d.ts +79 -0
- package/src/orm/Typo/query.d.ts +266 -0
- package/{lib → src}/orm/Typo/settings.d.ts +14 -7
- package/{lib → src}/orm/Typo/synchronous.d.ts +51 -26
- package/src/orm/Utilities.ts +1313 -0
- package/src/orm/Validators.ts +127 -0
- package/src/orm/Where/common.ts +8 -0
- package/src/orm/Where/filterDate.ts +74 -0
- package/src/orm/cloneDeep.ts +45 -0
- package/src/orm/index.ts +231 -0
- package/src/orm-core/callback.d.ts +15 -0
- package/{lib → src}/orm-core/dialect.d.ts +75 -52
- package/src/orm-core/error.ts +71 -0
- package/{lib/orm-core/index.d.ts → src/orm-core/index.ts} +8 -2
- package/src/orm-core/sync.d.ts +14 -0
- package/src/orm-core/utils.ts +4 -0
- package/src/orm-property/Property.ts +110 -0
- package/src/orm-property/Utils.ts +26 -0
- package/src/orm-property/customTypes.ts +13 -0
- package/src/orm-property/index.ts +34 -0
- package/src/orm-property/transformer.ts +16 -0
- package/{lib/orm-property/transformers/dm.js → src/orm-property/transformers/dm.ts} +128 -68
- package/src/orm-property/transformers/index.ts +10 -0
- package/src/orm-property/transformers/mssql.ts +285 -0
- package/src/orm-property/transformers/mysql.ts +395 -0
- package/src/orm-property/transformers/postgresql.ts +267 -0
- package/src/orm-property/transformers/sqlite.ts +217 -0
- package/src/plugins/orm-plugin-uacl/Typo.d.ts +173 -0
- package/src/plugins/orm-plugin-uacl/_utils.ts +237 -0
- package/src/plugins/orm-plugin-uacl/acl-tree.ts +440 -0
- package/src/plugins/orm-plugin-uacl/config-acl-tree.ts +592 -0
- package/src/plugins/orm-plugin-uacl/index.ts +180 -0
- package/src/plugins/orm-plugin-uacl/tree.ts +331 -0
- package/src/sql-ddl-sync/Dialects/dm.ts +493 -0
- package/{lib/sql-query/Dialects/index.d.ts → src/sql-ddl-sync/Dialects/index.ts} +3 -3
- package/src/sql-ddl-sync/Dialects/mssql.ts +441 -0
- package/src/sql-ddl-sync/Dialects/mysql.ts +414 -0
- package/src/sql-ddl-sync/Dialects/postgresql.ts +474 -0
- package/src/sql-ddl-sync/Dialects/sqlite.ts +439 -0
- package/src/sql-ddl-sync/SQL.ts +157 -0
- package/src/sql-ddl-sync/Typo/Collection.d.ts +19 -0
- package/src/sql-ddl-sync/Typo/DbIndex.d.ts +11 -0
- package/{lib → src}/sql-ddl-sync/Typo/Dialect.d.ts +67 -52
- package/src/sql-ddl-sync/Typo/Driver.d.ts +67 -0
- package/src/sql-ddl-sync/Typo/Query.d.ts +8 -0
- package/src/sql-ddl-sync/Typo/SQL.d.ts +45 -0
- package/src/sql-ddl-sync/Typo/_common.d.ts +59 -0
- package/src/sql-ddl-sync/Utils.ts +291 -0
- package/src/sql-ddl-sync/index.ts +599 -0
- package/src/sql-query/Comparators.ts +115 -0
- package/src/sql-query/Create.ts +87 -0
- package/{lib/sql-query/Dialects/dm.js → src/sql-query/Dialects/dm.ts} +42 -21
- package/src/sql-query/Dialects/index.ts +14 -0
- package/src/sql-query/Dialects/mssql.ts +91 -0
- package/src/sql-query/Dialects/mysql.ts +120 -0
- package/src/sql-query/Dialects/postgresql.ts +99 -0
- package/src/sql-query/Dialects/sqlite.ts +80 -0
- package/src/sql-query/Helpers.ts +303 -0
- package/src/sql-query/Insert.ts +41 -0
- package/src/sql-query/Query.ts +140 -0
- package/src/sql-query/Remove.ts +111 -0
- package/src/sql-query/Select.ts +719 -0
- package/src/sql-query/Set.ts +25 -0
- package/src/sql-query/Typo/Aggregation.d.ts +34 -0
- package/src/sql-query/Typo/Comparators.d.ts +156 -0
- package/src/sql-query/Typo/Dialect.d.ts +51 -0
- package/src/sql-query/Typo/Field.d.ts +10 -0
- package/src/sql-query/Typo/Helper.d.ts +4 -0
- package/src/sql-query/Typo/Query-ChainBuilder.d.ts +110 -0
- package/src/sql-query/Typo/Query.d.ts +65 -0
- package/src/sql-query/Typo/Sql.d.ts +192 -0
- package/src/sql-query/Typo/SubQuery.d.ts +52 -0
- package/{lib/sql-query/Typo/index.d.ts → src/sql-query/Typo/index.ts} +5 -2
- package/src/sql-query/Update.ts +50 -0
- package/src/sql-query/Where.ts +435 -0
- package/{lib/orm/Patch → src/typings}/fib-cache.d.ts +4 -3
- package/lib/cli/commands/ddlFrom.d.ts +0 -2
- package/lib/cli/commands/dumpModel.d.ts +0 -2
- package/lib/cli/commands/escape.d.ts +0 -2
- package/lib/cli/commands/spinner.d.ts +0 -2
- package/lib/cli/commands/upgrade.d.ts +0 -2
- package/lib/cli/helpers/ddl.d.ts +0 -17
- package/lib/cli/helpers/ddl.js +0 -55
- package/lib/cli/helpers/package.d.ts +0 -26
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -18
- package/lib/db-driver/Typo.d.ts +0 -112
- package/lib/db-driver/Typo.js +0 -1
- package/lib/db-driver/built-ins/base.class.d.ts +0 -96
- package/lib/db-driver/built-ins/base.class.js +0 -186
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-dm.js +0 -53
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -24
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -46
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-mysql.js +0 -37
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -22
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -76
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -12
- package/lib/db-driver/built-ins/driver-redis.js +0 -35
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -34
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -4
- package/lib/db-driver/utils.d.ts +0 -14
- package/lib/db-driver/utils.js +0 -187
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +0 -12
- package/lib/knex/deps/tarn/dist/PendingOperation.js +0 -48
- package/lib/knex/deps/tarn/dist/Pool.d.ts +0 -97
- package/lib/knex/deps/tarn/dist/Pool.js +0 -516
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +0 -16
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +0 -21
- package/lib/knex/deps/tarn/dist/Resource.d.ts +0 -9
- package/lib/knex/deps/tarn/dist/Resource.js +0 -19
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +0 -2
- package/lib/knex/deps/tarn/dist/TimeoutError.js +0 -5
- package/lib/knex/deps/tarn/dist/tarn.d.ts +0 -3
- package/lib/knex/deps/tarn/dist/tarn.js +0 -10
- package/lib/knex/deps/tarn/dist/utils.d.ts +0 -14
- package/lib/knex/deps/tarn/dist/utils.js +0 -60
- package/lib/knex/knex.d.ts +0 -2
- package/lib/knex/knex.js +0 -3
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -22
- package/lib/orm/Adapters.d.ts +0 -3
- package/lib/orm/Adapters.js +0 -44
- package/lib/orm/AggregateFunctions.d.ts +0 -3
- package/lib/orm/AggregateFunctions.js +0 -176
- package/lib/orm/Associations/Extend.d.ts +0 -22
- package/lib/orm/Associations/Extend.js +0 -274
- package/lib/orm/Associations/Many.d.ts +0 -17
- package/lib/orm/Associations/Many.js +0 -569
- package/lib/orm/Associations/One.d.ts +0 -16
- package/lib/orm/Associations/One.js +0 -310
- package/lib/orm/Associations/_utils.d.ts +0 -15
- package/lib/orm/Associations/_utils.js +0 -52
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -327
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -73
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -3
- package/lib/orm/Drivers/DB/base.js +0 -3
- package/lib/orm/Drivers/DB/dm.d.ts +0 -11
- package/lib/orm/Drivers/DB/dm.js +0 -23
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -11
- package/lib/orm/Drivers/DB/mysql.js +0 -23
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -11
- package/lib/orm/Drivers/DB/postgres.js +0 -22
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -16
- package/lib/orm/Drivers/DB/sqlite3.js +0 -39
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -51
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +0 -19
- package/lib/orm/Drivers/DML/_dml-helpers.js +0 -51
- package/lib/orm/Drivers/DML/_shared.d.ts +0 -9
- package/lib/orm/Drivers/DML/_shared.js +0 -38
- package/lib/orm/Drivers/DML/_utils.d.ts +0 -8
- package/lib/orm/Drivers/DML/_utils.js +0 -67
- package/lib/orm/Drivers/DML/constants.d.ts +0 -3
- package/lib/orm/Drivers/DML/constants.js +0 -2
- package/lib/orm/Drivers/DML/dm.d.ts +0 -2
- package/lib/orm/Drivers/DML/index.d.ts +0 -4
- package/lib/orm/Drivers/DML/index.js +0 -6
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -251
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -3
- package/lib/orm/Drivers/DML/postgres.js +0 -276
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -266
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -40
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -233
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -99
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -697
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -7
- package/lib/orm/Model.js +0 -971
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -241
- package/lib/orm/Patch/fib-cache.js +0 -2
- package/lib/orm/Patch/plugin.d.ts +0 -4
- package/lib/orm/Patch/plugin.js +0 -13
- package/lib/orm/Property.d.ts +0 -9
- package/lib/orm/Property.js +0 -71
- package/lib/orm/Settings.d.ts +0 -42
- package/lib/orm/Settings.js +0 -119
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -72
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -1
- package/lib/orm/Typo/DMLDriver.d.ts +0 -210
- package/lib/orm/Typo/DMLDriver.js +0 -1
- package/lib/orm/Typo/Db.d.ts +0 -38
- package/lib/orm/Typo/Db.js +0 -1
- package/lib/orm/Typo/Error.d.ts +0 -31
- package/lib/orm/Typo/Error.js +0 -1
- package/lib/orm/Typo/ORM.d.ts +0 -233
- package/lib/orm/Typo/ORM.js +0 -3
- package/lib/orm/Typo/Validators.d.ts +0 -32
- package/lib/orm/Typo/Validators.js +0 -2
- package/lib/orm/Typo/_common.d.ts +0 -38
- package/lib/orm/Typo/_common.js +0 -1
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -1
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -1
- package/lib/orm/Typo/instance.d.ts +0 -157
- package/lib/orm/Typo/instance.js +0 -1
- package/lib/orm/Typo/model.js +0 -6
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -1
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -1
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -1
- package/lib/orm/Typo/settings.js +0 -5
- package/lib/orm/Typo/synchronous.js +0 -1
- package/lib/orm/Utilities.d.ts +0 -179
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -34
- package/lib/orm/Validators.js +0 -100
- package/lib/orm/Where/common.d.ts +0 -1
- package/lib/orm/Where/common.js +0 -7
- package/lib/orm/Where/filterDate.d.ts +0 -11
- package/lib/orm/Where/filterDate.js +0 -58
- package/lib/orm/index.d.ts +0 -68
- package/lib/orm/index.js +0 -157
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -1
- package/lib/orm-core/dialect.js +0 -1
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -6
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -1
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -5
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -1
- package/lib/orm-property/Utils.d.ts +0 -9
- package/lib/orm-property/Utils.js +0 -13
- package/lib/orm-property/customTypes.d.ts +0 -2
- package/lib/orm-property/customTypes.js +0 -13
- package/lib/orm-property/index.d.ts +0 -10
- package/lib/orm-property/index.js +0 -22
- package/lib/orm-property/transformer.d.ts +0 -5
- package/lib/orm-property/transformer.js +0 -10
- package/lib/orm-property/transformers/dm.d.ts +0 -29
- package/lib/orm-property/transformers/index.d.ts +0 -4
- package/lib/orm-property/transformers/index.js +0 -5
- package/lib/orm-property/transformers/mysql.d.ts +0 -102
- package/lib/orm-property/transformers/mysql.js +0 -261
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -189
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -171
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -296
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -7
- package/lib/sql-ddl-sync/Dialects/index.js +0 -7
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -240
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -286
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -44
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -256
- package/lib/sql-ddl-sync/SQL.d.ts +0 -12
- package/lib/sql-ddl-sync/SQL.js +0 -108
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/Collection.js +0 -1
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -1
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -1
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -1
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -1
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -1
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -1
- package/lib/sql-ddl-sync/Utils.d.ts +0 -40
- package/lib/sql-ddl-sync/Utils.js +0 -217
- package/lib/sql-ddl-sync/index.d.ts +0 -87
- package/lib/sql-ddl-sync/index.js +0 -371
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -94
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -77
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -12
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -73
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -100
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -76
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -61
- package/lib/sql-query/Helpers.d.ts +0 -38
- package/lib/sql-query/Helpers.js +0 -259
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -33
- package/lib/sql-query/Query.d.ts +0 -29
- package/lib/sql-query/Query.js +0 -119
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -93
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -533
- package/lib/sql-query/Set.d.ts +0 -4
- package/lib/sql-query/Set.js +0 -16
- package/lib/sql-query/Typo/Aggregation.d.ts +0 -32
- package/lib/sql-query/Typo/Aggregation.js +0 -1
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -1
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -1
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -1
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -1
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -1
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -16
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -1
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -1
- package/lib/sql-query/Typo/index.js +0 -1
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -38
- package/lib/sql-query/Where.d.ts +0 -4
- package/lib/sql-query/Where.js +0 -280
- /package/{lib → src}/codepoints-map.json +0 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require('util');
|
|
4
|
+
import * as Hook from '../Hook';
|
|
5
|
+
import * as Utilities from '../Utilities';
|
|
6
|
+
import ORMError from "../Error";
|
|
7
|
+
import { ACCESSOR_KEYS, addAssociationInfoToModel } from './_utils';
|
|
8
|
+
import { listFindByChainOrRunSync } from '../Model';
|
|
9
|
+
import * as Helpers from '../Helpers';
|
|
10
|
+
import type { FxOrmInstance } from '../Typo/instance';
|
|
11
|
+
import type { FxOrmAssociation } from '../Typo/assoc';
|
|
12
|
+
import type { FxOrmModel } from '../Typo/model';
|
|
13
|
+
import type { FxOrmNS } from '../Typo/ORM';
|
|
14
|
+
import type { FxOrmDMLDriver } from '../Typo/DMLDriver';
|
|
15
|
+
import type { FxOrmQuery } from '../Typo/query';
|
|
16
|
+
import type { FxOrmCommon } from '../Typo/_common';
|
|
17
|
+
|
|
18
|
+
function noOperation (...args: any[]) {};
|
|
19
|
+
|
|
20
|
+
export function prepare (
|
|
21
|
+
Model: FxOrmModel.Model,
|
|
22
|
+
assocs: {
|
|
23
|
+
one_associations: FxOrmAssociation.InstanceAssociationItem_HasOne[],
|
|
24
|
+
many_associations: FxOrmAssociation.InstanceAssociationItem_HasMany[],
|
|
25
|
+
extend_associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[],
|
|
26
|
+
},
|
|
27
|
+
opts: {
|
|
28
|
+
db: FxOrmNS.ORM
|
|
29
|
+
}
|
|
30
|
+
) {
|
|
31
|
+
const { one_associations } = assocs;
|
|
32
|
+
const { db } = opts;
|
|
33
|
+
|
|
34
|
+
Model.hasOne = function (assoc_name, ext_model, assoc_options) {
|
|
35
|
+
Utilities.disAllowOpForVModel(Model, 'model.hasOne');
|
|
36
|
+
|
|
37
|
+
if (arguments[1] && !arguments[1].table) {
|
|
38
|
+
assoc_options = arguments[1] as FxOrmAssociation.AssociationDefinitionOptions_HasOne
|
|
39
|
+
ext_model = arguments[1] = null as unknown as FxOrmModel.Model
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ext_model = ext_model || Model;
|
|
43
|
+
assoc_name = assoc_name || ext_model.table;
|
|
44
|
+
assoc_options = {...assoc_options};
|
|
45
|
+
|
|
46
|
+
if (!assoc_name) {
|
|
47
|
+
throw new Error(`[hasOne] association's name is required!`)
|
|
48
|
+
} else if (typeof assoc_name !== 'string') {
|
|
49
|
+
throw new Error(`[hasOne] association's name must be string!`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Utilities.disAllowOpForVModel(ext_model, 'associated by model.hasOne');
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < db.plugins.length; i++) {
|
|
55
|
+
if (typeof db.plugins[i].beforeHasOne === "function") {
|
|
56
|
+
(db.plugins[i].beforeHasOne as (...args: any[]) => any)(Model, {
|
|
57
|
+
association_name: assoc_name,
|
|
58
|
+
ext_model: ext_model,
|
|
59
|
+
assoc_options
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const associationSemanticNameCore = Utilities.formatNameFor("assoc:hasOne", assoc_name);
|
|
65
|
+
|
|
66
|
+
const association = {
|
|
67
|
+
name : assoc_name,
|
|
68
|
+
model : ext_model,
|
|
69
|
+
|
|
70
|
+
field : null,
|
|
71
|
+
reversed : false,
|
|
72
|
+
__for_extension: false,
|
|
73
|
+
autoFetch : false,
|
|
74
|
+
autoFetchLimit : 2,
|
|
75
|
+
required : false,
|
|
76
|
+
|
|
77
|
+
setAccessor : ACCESSOR_KEYS.set + associationSemanticNameCore,
|
|
78
|
+
getAccessor : ACCESSOR_KEYS.get + associationSemanticNameCore,
|
|
79
|
+
hasAccessor : ACCESSOR_KEYS.has + associationSemanticNameCore,
|
|
80
|
+
delAccessor : null,
|
|
81
|
+
|
|
82
|
+
modelFindByAccessor : assoc_options.modelFindByAccessor || (ACCESSOR_KEYS.modelFindBy + associationSemanticNameCore),
|
|
83
|
+
|
|
84
|
+
...assoc_options,
|
|
85
|
+
hooks : {...assoc_options.hooks},
|
|
86
|
+
} as FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
87
|
+
|
|
88
|
+
if (!association.reversed)
|
|
89
|
+
association.delAccessor = ACCESSOR_KEYS['del'] + associationSemanticNameCore;
|
|
90
|
+
|
|
91
|
+
Utilities.fillSyncVersionAccessorForAssociation(association);
|
|
92
|
+
Utilities.addHookPatchHelperForAssociation(association);
|
|
93
|
+
|
|
94
|
+
if (!association.field) {
|
|
95
|
+
association.field = Utilities.formatAssociatedField(association.model, association.name, !!association.required, !!association.reversed);
|
|
96
|
+
} else if (!association.__for_extension) {
|
|
97
|
+
association.field = Utilities.wrapFieldObject({
|
|
98
|
+
field: association.field, model: Model, altName: Model.table,
|
|
99
|
+
mapsTo: association.mapsTo
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const normalizedField = association.field
|
|
104
|
+
|
|
105
|
+
Utilities.convertPropToJoinKeyProp(normalizedField, { makeKey: false, required: !!association.required });
|
|
106
|
+
|
|
107
|
+
one_associations.push(association);
|
|
108
|
+
for (let k in normalizedField) {
|
|
109
|
+
if (!normalizedField.hasOwnProperty(k)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!association.reversed && !association.__for_extension) {
|
|
113
|
+
Model.addProperty(
|
|
114
|
+
util.extend({}, normalizedField[k], { klass: 'hasOne' }),
|
|
115
|
+
false
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (association.reverse) {
|
|
121
|
+
association.model.hasOne(association.reverse, Model, {
|
|
122
|
+
reversed : true,
|
|
123
|
+
accessor : association.reverseAccessor,
|
|
124
|
+
reverseAccessor: undefined,
|
|
125
|
+
field : normalizedField,
|
|
126
|
+
autoFetch : association.autoFetch,
|
|
127
|
+
autoFetchLimit : association.autoFetchLimit,
|
|
128
|
+
hooks : assoc_options.reverseHooks
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const findByAccessorChainOrRunSync = function (is_sync: boolean = false) {
|
|
133
|
+
return function () {
|
|
134
|
+
var cb: FxOrmModel.ModelMethodCallback__Find | null = null,
|
|
135
|
+
conditions: FxOrmQuery.QueryConditions__Find | null = null,
|
|
136
|
+
options: FxOrmAssociation.ModelAssociationMethod__FindOptions = {};
|
|
137
|
+
|
|
138
|
+
Helpers.selectArgs(arguments, (arg_type, arg) => {
|
|
139
|
+
switch (arg_type) {
|
|
140
|
+
case "function":
|
|
141
|
+
cb = arg;
|
|
142
|
+
break;
|
|
143
|
+
case "object":
|
|
144
|
+
if (conditions === null) {
|
|
145
|
+
conditions = arg;
|
|
146
|
+
} else {
|
|
147
|
+
options = arg;
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
if (conditions === null) {
|
|
154
|
+
throw new ORMError(`.${association.modelFindByAccessor}() is missing a conditions object`, 'PARAM_MISMATCH');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return listFindByChainOrRunSync(Model,
|
|
158
|
+
{},
|
|
159
|
+
[
|
|
160
|
+
{
|
|
161
|
+
association_name: association.name,
|
|
162
|
+
conditions: conditions!
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
options,
|
|
166
|
+
{ callback: cb || undefined, is_sync }
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Model[association.modelFindByAccessor!] = findByAccessorChainOrRunSync();
|
|
172
|
+
Model[association.modelFindBySyncAccessor!] = findByAccessorChainOrRunSync(true);
|
|
173
|
+
|
|
174
|
+
addAssociationInfoToModel(Model, assoc_name, {
|
|
175
|
+
type: 'hasOne',
|
|
176
|
+
association
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return this;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export function extend (
|
|
184
|
+
Model: FxOrmModel.Model,
|
|
185
|
+
Instance: FxOrmInstance.Instance,
|
|
186
|
+
Driver: FxOrmDMLDriver.DMLDriver,
|
|
187
|
+
// extend target
|
|
188
|
+
associations: FxOrmAssociation.InstanceAssociationItem_HasOne[],
|
|
189
|
+
cfg: {
|
|
190
|
+
assoc_opts: any,
|
|
191
|
+
}
|
|
192
|
+
) {
|
|
193
|
+
for (let i = 0; i < associations.length; i++) {
|
|
194
|
+
extendInstance(Model, Instance, Driver, associations[i], cfg);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function autoFetch (
|
|
199
|
+
Instance: FxOrmInstance.Instance,
|
|
200
|
+
associations: FxOrmAssociation.InstanceAssociationItem[],
|
|
201
|
+
opts: FxOrmAssociation.AutoFetchInstanceOptions,
|
|
202
|
+
parallel: boolean
|
|
203
|
+
) {
|
|
204
|
+
if (associations.length === 0)
|
|
205
|
+
return undefined as any;
|
|
206
|
+
|
|
207
|
+
Utilities.parallelQueryIfPossible(
|
|
208
|
+
parallel,
|
|
209
|
+
associations,
|
|
210
|
+
(item) => autoFetchInstance(Instance, item, opts)
|
|
211
|
+
)
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
function extendInstance(
|
|
215
|
+
Model: FxOrmModel.Model,
|
|
216
|
+
Instance: FxOrmInstance.Instance,
|
|
217
|
+
Driver: FxOrmDMLDriver.DMLDriver,
|
|
218
|
+
// extend target
|
|
219
|
+
association: FxOrmAssociation.InstanceAssociationItem_HasOne,
|
|
220
|
+
cfg: {
|
|
221
|
+
assoc_opts: FxOrmAssociation.AssociationDefinitionOptions_HasOne,
|
|
222
|
+
}
|
|
223
|
+
) {
|
|
224
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.hasSyncAccessor, function (_has_opts?: FxOrmAssociation.AccessorOptions_has) {
|
|
225
|
+
if (!Utilities.hasValues(Instance, Object.keys(association.field)))
|
|
226
|
+
return false;
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const instance = association.model.getSync(
|
|
230
|
+
Utilities.values(Instance, Object.keys(association.field)),
|
|
231
|
+
_has_opts
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
return !!instance;
|
|
235
|
+
} catch (error) {
|
|
236
|
+
return false
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.hasAccessor, function (this: any, _has_opts?: FxOrmAssociation.AccessorOptions_has, cb?: FxOrmCommon.GenericCallback<boolean>) {
|
|
241
|
+
if (typeof _has_opts === "function") {
|
|
242
|
+
cb = _has_opts as any;
|
|
243
|
+
_has_opts = {};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
process.nextTick(() => {
|
|
247
|
+
const syncResponse = Utilities.catchBlocking<boolean>(Instance[association.hasSyncAccessor], [ _has_opts ]);
|
|
248
|
+
Utilities.takeAwayResult(syncResponse as any, { no_throw: true, callback: cb })
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return this;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const getAccessorChainOrRunSync = function (
|
|
255
|
+
opts: FxOrmModel.ModelOptions__Find = {},
|
|
256
|
+
withOutCallbackWhenNonSync: boolean,
|
|
257
|
+
): FxOrmQuery.IChainFind | FxOrmAssociation.InstanceAssociatedInstance | FxOrmAssociation.InstanceAssociatedInstance[] {
|
|
258
|
+
const saveAndReturn = function (Assoc: FxOrmAssociation.InstanceAssociatedInstance | FxOrmAssociation.InstanceAssociatedInstance[]) {
|
|
259
|
+
Instance[association.name] = Assoc;
|
|
260
|
+
|
|
261
|
+
return Assoc;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
let result: FxOrmAssociation.InstanceAssociatedInstance | FxOrmAssociation.InstanceAssociatedInstance[] = undefined as any;
|
|
265
|
+
|
|
266
|
+
// process get reversed instance's original instance
|
|
267
|
+
if (association.reversed) {
|
|
268
|
+
let reverseHostInstances: FxOrmAssociation.InstanceAssociatedInstance[] | null = null;
|
|
269
|
+
|
|
270
|
+
if (Utilities.hasValues(Instance, Model.id)) {
|
|
271
|
+
const query_conds: FxOrmQuery.QueryConditions__Find = Utilities.getConditions(
|
|
272
|
+
Model,
|
|
273
|
+
Object.keys(association.field),
|
|
274
|
+
Instance
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
if (withOutCallbackWhenNonSync) {
|
|
278
|
+
return (association.model.find as any).call(association.model, query_conds, opts);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
reverseHostInstances = association.model.findSync(query_conds, opts);
|
|
282
|
+
result = saveAndReturn(reverseHostInstances || []);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let assocInstance: FxOrmAssociation.InstanceAssociatedInstance | null = null;
|
|
289
|
+
if (Instance.isShell()) {
|
|
290
|
+
Instance = Model.getSync(Utilities.values( Instance, Model.id )) as any
|
|
291
|
+
|
|
292
|
+
if (!Utilities.hasValues(Instance, Object.keys(association.field)))
|
|
293
|
+
return undefined as any;
|
|
294
|
+
|
|
295
|
+
assocInstance = association.model.getSync(Utilities.values(Instance, Object.keys(association.field)), opts) as any;
|
|
296
|
+
return saveAndReturn(assocInstance!);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (Utilities.hasValues(Instance, Object.keys(association.field))) {
|
|
300
|
+
assocInstance = association.model.getSync(
|
|
301
|
+
Utilities.values( Instance, Object.keys(association.field) ),
|
|
302
|
+
opts,
|
|
303
|
+
);
|
|
304
|
+
return saveAndReturn(assocInstance!);
|
|
305
|
+
}
|
|
306
|
+
return result as any;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.getSyncAccessor, function (
|
|
310
|
+
opts: FxOrmModel.ModelOptions__Find = {},
|
|
311
|
+
): FxOrmAssociation.InstanceAssociatedInstance | FxOrmAssociation.InstanceAssociatedInstance[] {
|
|
312
|
+
return getAccessorChainOrRunSync(opts, false) as FxOrmAssociation.InstanceAssociatedInstance | FxOrmAssociation.InstanceAssociatedInstance[];
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.getAccessor, function (this: any,
|
|
316
|
+
opts?: FxOrmModel.ModelOptions__Find,
|
|
317
|
+
cb?: FxOrmCommon.GenericCallback<FxOrmAssociation.InstanceAssociatedInstance>
|
|
318
|
+
): FxOrmQuery.IChainFind {
|
|
319
|
+
if (typeof opts === "function") {
|
|
320
|
+
cb = opts as any;
|
|
321
|
+
opts = {};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const withCallback = typeof cb === 'function';
|
|
325
|
+
|
|
326
|
+
if (withCallback) {
|
|
327
|
+
process.nextTick(() => {
|
|
328
|
+
const syncResponse = Utilities.catchBlocking<FxOrmInstance.Instance>(getAccessorChainOrRunSync, [opts, !withCallback]);
|
|
329
|
+
Utilities.takeAwayResult(syncResponse as any, { no_throw: true, callback: cb });
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return getAccessorChainOrRunSync(opts, !withCallback) as FxOrmQuery.IChainFind;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.setSyncAccessor, function (
|
|
339
|
+
OtherInstance: FxOrmInstance.Instance | FxOrmInstance.Instance[]
|
|
340
|
+
): FxOrmInstance.Instance | FxOrmInstance.Instance[] {
|
|
341
|
+
const inst_arr = Array.isArray(OtherInstance) ? Array.from(OtherInstance) : [ OtherInstance ];
|
|
342
|
+
|
|
343
|
+
let results = [] as FxOrmInstance.Instance[] | FxOrmInstance.Instance;
|
|
344
|
+
let hookHandlr = null;
|
|
345
|
+
|
|
346
|
+
const $ref = {
|
|
347
|
+
instance: Instance,
|
|
348
|
+
association: association.reversed ? null : OtherInstance,
|
|
349
|
+
associations: association.reversed ? inst_arr : null,
|
|
350
|
+
useChannel: Utilities.reusableChannelGenerator()
|
|
351
|
+
} as FxOrmAssociation.__AssocHooksCtx;
|
|
352
|
+
|
|
353
|
+
if (association.reversed) {
|
|
354
|
+
hookHandlr = Utilities.makeHandlerDecorator({ thisArg: Instance }, () => {
|
|
355
|
+
Instance.saveSync();
|
|
356
|
+
|
|
357
|
+
const runReversed = function (other: FxOrmInstance.Instance) {
|
|
358
|
+
Instance.$emit(`before:set:${association.name}`, other)
|
|
359
|
+
|
|
360
|
+
Utilities.populateModelIdKeysConditions(Model, Object.keys(association.field), Instance, other, true);
|
|
361
|
+
// link
|
|
362
|
+
other.saveSync({}, { saveAssociations: false });
|
|
363
|
+
|
|
364
|
+
Instance.$emit(`after:set:${association.name}`, other)
|
|
365
|
+
|
|
366
|
+
return other;
|
|
367
|
+
};
|
|
368
|
+
results = Utilities.parallelQueryIfPossible(
|
|
369
|
+
false,
|
|
370
|
+
$ref.associations!,
|
|
371
|
+
runReversed
|
|
372
|
+
);
|
|
373
|
+
})
|
|
374
|
+
} else {
|
|
375
|
+
hookHandlr = Utilities.makeHandlerDecorator({ thisArg: Instance }, () => {
|
|
376
|
+
const runNonReversed = function (oinst: FxOrmInstance.Instance) {
|
|
377
|
+
Instance.$emit(`before:set:${association.name}`, oinst)
|
|
378
|
+
|
|
379
|
+
oinst.saveSync({}, { saveAssociations: false });
|
|
380
|
+
|
|
381
|
+
Instance[association.name] = oinst;
|
|
382
|
+
|
|
383
|
+
// TODO: on pre normalize stage, record linked associated key property name on build association
|
|
384
|
+
// const idInHostSide = Object.keys(association.field)[0];
|
|
385
|
+
// const idInOtherSide = association.model.keys[0];
|
|
386
|
+
// Instance[idInHostSide] = oinst[idInOtherSide];
|
|
387
|
+
|
|
388
|
+
Utilities.populateModelIdKeysConditions(association.model, Object.keys(association.field), oinst, Instance);
|
|
389
|
+
|
|
390
|
+
Instance.$emit(`after:set:${association.name}`, oinst)
|
|
391
|
+
|
|
392
|
+
return oinst;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
results = runNonReversed($ref.association as FxOrmInstance.Instance)
|
|
396
|
+
|
|
397
|
+
// link
|
|
398
|
+
Instance.saveSync({}, { saveAssociations: false });
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
Hook.wait(
|
|
403
|
+
Instance,
|
|
404
|
+
association.hooks[`beforeSet`],
|
|
405
|
+
hookHandlr,
|
|
406
|
+
Utilities.buildAssocHooksContext('beforeSet', { $ref })
|
|
407
|
+
);
|
|
408
|
+
Hook.trigger(Instance, association.hooks['afterSet'], Utilities.buildAssocHooksContext('afterSet', { $ref }));
|
|
409
|
+
|
|
410
|
+
return results;
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.setAccessor, function (this: any,
|
|
414
|
+
OtherInstance: FxOrmInstance.Instance | FxOrmInstance.Instance[],
|
|
415
|
+
cb?: FxOrmCommon.GenericCallback<FxOrmInstance.Instance>
|
|
416
|
+
) {
|
|
417
|
+
process.nextTick(() => {
|
|
418
|
+
const syncResponse = Utilities.catchBlocking<FxOrmInstance.Instance | FxOrmInstance.Instance[]>(Instance[association.setSyncAccessor], [ OtherInstance ]);
|
|
419
|
+
Utilities.takeAwayResult(syncResponse as any, { no_throw: true, callback: cb })
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
return this;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// only non-reversed could delete associated instance
|
|
426
|
+
if (!association.reversed && !association.__for_extension) {
|
|
427
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.delSyncAccessor, function (this: any,
|
|
428
|
+
) {
|
|
429
|
+
const $ref = {
|
|
430
|
+
instance: Instance,
|
|
431
|
+
useChannel: Utilities.reusableChannelGenerator()
|
|
432
|
+
} as Record<string, any>;
|
|
433
|
+
Hook.wait(
|
|
434
|
+
Instance,
|
|
435
|
+
association.hooks[`beforeRemove`],
|
|
436
|
+
Utilities.makeHandlerDecorator({ thisArg: Instance }, () => {
|
|
437
|
+
Instance.$emit(`before:del:${association.name}`);
|
|
438
|
+
for (let k in association.field) {
|
|
439
|
+
if (association.field.hasOwnProperty(k)) {
|
|
440
|
+
Instance[k] = null;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
Instance.saveSync({}, { saveAssociations: false });
|
|
445
|
+
delete Instance[association.name];
|
|
446
|
+
Instance.$emit(`after:del:${association.name}`)
|
|
447
|
+
}),
|
|
448
|
+
Utilities.buildAssocHooksContext('beforeRemove', { $ref })
|
|
449
|
+
);
|
|
450
|
+
Hook.trigger(Instance, association.hooks['afterRemove'], Utilities.buildAssocHooksContext('afterRemove', { $ref }));
|
|
451
|
+
|
|
452
|
+
return this;
|
|
453
|
+
}, {});
|
|
454
|
+
|
|
455
|
+
Utilities.addHiddenUnwritableMethodToInstance(Instance, association.delAccessor, function (this: any,
|
|
456
|
+
cb?: FxOrmCommon.ExecutionCallback<FxOrmInstance.Instance | FxOrmInstance.Instance[]>
|
|
457
|
+
) {
|
|
458
|
+
process.nextTick(() => {
|
|
459
|
+
const syncResponse = Utilities.catchBlocking<FxOrmInstance.Instance | FxOrmInstance.Instance[]>(Instance[association.delSyncAccessor]);
|
|
460
|
+
Utilities.takeAwayResult(syncResponse as any, { no_throw: true, callback: cb })
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
return this;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function autoFetchInstance(
|
|
469
|
+
Instance: FxOrmInstance.Instance,
|
|
470
|
+
association: FxOrmAssociation.InstanceAssociationItem,
|
|
471
|
+
opts: FxOrmAssociation.AutoFetchInstanceOptions,
|
|
472
|
+
) {
|
|
473
|
+
if (!Instance.saved())
|
|
474
|
+
return undefined as any;
|
|
475
|
+
|
|
476
|
+
if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit === "undefined") {
|
|
477
|
+
opts.autoFetchLimit = association.autoFetchLimit;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch))
|
|
481
|
+
return undefined as any;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* When we have a new non persisted instance for which the association field (eg owner_id)
|
|
485
|
+
* is set, we don't want to auto fetch anything, since `new Model(owner_id: 12)` takes no
|
|
486
|
+
* callback, and hence this lookup would complete at an arbitrary point in the future.
|
|
487
|
+
* The associated entity should probably be fetched when the instance is persisted.
|
|
488
|
+
*/
|
|
489
|
+
if (Instance.isPersisted()) {
|
|
490
|
+
Instance[association.getSyncAccessor]({ autoFetchLimit: opts.autoFetchLimit - 1 });
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return undefined as any;
|
|
494
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference lib="es6" />
|
|
2
|
+
|
|
3
|
+
import type { FxOrmAssociation } from "../Typo/assoc";
|
|
4
|
+
import type { FxOrmModel } from "../Typo/model";
|
|
5
|
+
import type { FxOrmProperty } from "../Typo/property";
|
|
6
|
+
|
|
7
|
+
export function defineDefaultExtendsToTableName (modelTableName: string, assocName: string): string {
|
|
8
|
+
return `${modelTableName}_${assocName}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ACCESSOR_PREFIX = 'add' | 'get' | 'set' | 'has' | 'remove' | 'findBy'
|
|
12
|
+
export function defineAssociationAccessorMethodName (
|
|
13
|
+
prefixer: ACCESSOR_PREFIX,
|
|
14
|
+
assocName: string
|
|
15
|
+
): string {
|
|
16
|
+
return `${prefixer}${assocName}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ACCESSOR_KEYS: {[k: string]: ACCESSOR_PREFIX} = {
|
|
20
|
+
/* common :start */
|
|
21
|
+
"get": "get" as 'get',
|
|
22
|
+
"set": "set" as 'set',
|
|
23
|
+
"has": "has" as 'has',
|
|
24
|
+
"del": "remove" as 'remove',
|
|
25
|
+
"modelFindBy": "findBy" as 'findBy',
|
|
26
|
+
/* common :end */
|
|
27
|
+
|
|
28
|
+
// useful for association `hasMany`
|
|
29
|
+
"add": "add" as 'add',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function getMapsToFromProperty (property: FxOrmProperty.NormalizedProperty, k: string) {
|
|
33
|
+
return property.mapsTo || k
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getMapsToFromPropertyHash (hash: Record<string, FxOrmProperty.NormalizedProperty>) {
|
|
37
|
+
return Object.keys(hash).map(k => {
|
|
38
|
+
const item = hash[k]
|
|
39
|
+
|
|
40
|
+
return item.mapsTo || k
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function cutOffAssociatedModelFindOptions (
|
|
45
|
+
findby_options: FxOrmAssociation.ModelAssociationMethod__FindByOptions,
|
|
46
|
+
association_name: string
|
|
47
|
+
) {
|
|
48
|
+
let opts = null;
|
|
49
|
+
|
|
50
|
+
const k = `find_options:${association_name}`;
|
|
51
|
+
if (findby_options.hasOwnProperty(k)) {
|
|
52
|
+
opts = findby_options[k];
|
|
53
|
+
|
|
54
|
+
delete findby_options[k]
|
|
55
|
+
}
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
return opts
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function addAssociationInfoToModel (
|
|
62
|
+
Model: FxOrmModel.Model,
|
|
63
|
+
association_name: string,
|
|
64
|
+
opts: FxOrmModel.Model['associations'][any]
|
|
65
|
+
): FxOrmModel.Model['associations'][string] {
|
|
66
|
+
Model.associations[association_name] = {
|
|
67
|
+
type: opts.type,
|
|
68
|
+
association: opts.association
|
|
69
|
+
} as FxOrmModel.Model['associations'][any];
|
|
70
|
+
|
|
71
|
+
return Model.associations[association_name];
|
|
72
|
+
}
|