fib-orm 2.1.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 +37 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -27
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -32
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -29
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -11
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -34
- 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 -86
- 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 -174
- 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 -69
- 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 -22
- 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 -2
- 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 -25
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -19
- package/lib/db-driver/Typo.d.ts +0 -111
- package/lib/db-driver/Typo.js +0 -2
- package/lib/db-driver/built-ins/base.class.d.ts +0 -91
- package/lib/db-driver/built-ins/base.class.js +0 -187
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-dm.js +0 -54
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -23
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -47
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-mysql.js +0 -38
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -21
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -77
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -11
- package/lib/db-driver/built-ins/driver-redis.js +0 -36
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -16
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -35
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -5
- 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 -4
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -23
- 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 -177
- 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 -16
- 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 -14
- package/lib/orm/Associations/_utils.js +0 -53
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -328
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -74
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -2
- package/lib/orm/Drivers/DB/base.js +0 -4
- package/lib/orm/Drivers/DB/dm.d.ts +0 -9
- package/lib/orm/Drivers/DB/dm.js +0 -24
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -9
- package/lib/orm/Drivers/DB/mysql.js +0 -24
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -9
- package/lib/orm/Drivers/DB/postgres.js +0 -23
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -14
- package/lib/orm/Drivers/DB/sqlite3.js +0 -40
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -52
- 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 -39
- 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 -3
- 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 -7
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -252
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -2
- package/lib/orm/Drivers/DML/postgres.js +0 -277
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -267
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -41
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -234
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -100
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -698
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -6
- package/lib/orm/Model.js +0 -974
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -242
- 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 -14
- 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 -120
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -73
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -2
- package/lib/orm/Typo/DMLDriver.d.ts +0 -209
- package/lib/orm/Typo/DMLDriver.js +0 -2
- package/lib/orm/Typo/Db.d.ts +0 -35
- package/lib/orm/Typo/Db.js +0 -2
- package/lib/orm/Typo/Error.d.ts +0 -29
- package/lib/orm/Typo/Error.js +0 -2
- package/lib/orm/Typo/ORM.d.ts +0 -231
- package/lib/orm/Typo/ORM.js +0 -4
- package/lib/orm/Typo/Validators.d.ts +0 -31
- package/lib/orm/Typo/Validators.js +0 -3
- package/lib/orm/Typo/_common.d.ts +0 -37
- package/lib/orm/Typo/_common.js +0 -2
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -2
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -2
- package/lib/orm/Typo/instance.d.ts +0 -156
- package/lib/orm/Typo/instance.js +0 -2
- package/lib/orm/Typo/model.js +0 -7
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -2
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -2
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -2
- package/lib/orm/Typo/settings.js +0 -6
- package/lib/orm/Typo/synchronous.js +0 -2
- package/lib/orm/Utilities.d.ts +0 -178
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -33
- package/lib/orm/Validators.js +0 -101
- 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 -67
- package/lib/orm/index.js +0 -158
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -2
- package/lib/orm-core/dialect.js +0 -2
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -7
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -2
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -6
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -2
- 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 -23
- 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 -6
- package/lib/orm-property/transformers/mysql.d.ts +0 -101
- package/lib/orm-property/transformers/mysql.js +0 -262
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -190
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -172
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -297
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -6
- package/lib/sql-ddl-sync/Dialects/index.js +0 -8
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -38
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -241
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -287
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -43
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -257
- 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 -2
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -2
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -2
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -2
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -2
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -2
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -2
- package/lib/sql-ddl-sync/Utils.d.ts +0 -39
- 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 -372
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -95
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -78
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -13
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -74
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -101
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -77
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -62
- package/lib/sql-query/Helpers.d.ts +0 -37
- package/lib/sql-query/Helpers.js +0 -260
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -34
- package/lib/sql-query/Query.d.ts +0 -28
- package/lib/sql-query/Query.js +0 -120
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -94
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -534
- 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 -2
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -2
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -2
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -2
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -2
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -2
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -17
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -2
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -2
- package/lib/sql-query/Typo/index.js +0 -2
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -39
- 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
package/lib/knex/knex.d.ts
DELETED
package/lib/knex/knex.js
DELETED
package/lib/knex/sandbox.d.ts
DELETED
package/lib/knex/sandbox.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vm = require("vm");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const uuid = require("uuid");
|
|
6
|
-
const __root = path.resolve(__dirname, '../');
|
|
7
|
-
function patchMods() {
|
|
8
|
-
this.add({
|
|
9
|
-
'uuid': {
|
|
10
|
-
v4() {
|
|
11
|
-
return uuid.snowflake();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
class Box extends vm.SandBox {
|
|
17
|
-
constructor() {
|
|
18
|
-
const [mods = {}, __require = function () { }, __global = undefined] = Array.prototype.slice.apply(arguments);
|
|
19
|
-
super(Object.assign(Object.assign({}, mods), { 'fs': require('fs'), 'path': require('path'), 'os': require('os'), 'url': require('url'), 'tty': require('tty'), 'util': require('util'), 'events': require('events'), 'assert': require('assert'), 'crypto': require('crypto'), 'timers': require('timers'), 'tarn': require('./deps/tarn/dist/tarn') }), __require, __global);
|
|
20
|
-
patchMods.call(this);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.default = Box;
|
package/lib/orm/Adapters.d.ts
DELETED
package/lib/orm/Adapters.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addAdapter = addAdapter;
|
|
4
|
-
exports.getAdapter = getAdapter;
|
|
5
|
-
const DMLs = require("./Drivers/DML");
|
|
6
|
-
const adapters = {};
|
|
7
|
-
function addAdapter(name, constructor) {
|
|
8
|
-
if (adapters.hasOwnProperty(name)) {
|
|
9
|
-
throw new Error(`[addAdapter] adapter '${name}' already exists`);
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(adapters, name, {
|
|
12
|
-
get() {
|
|
13
|
-
return constructor;
|
|
14
|
-
},
|
|
15
|
-
configurable: false
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
addAdapter('mysql', DMLs.mysql.Driver);
|
|
19
|
-
addAdapter('sqlite', DMLs.sqlite.Driver);
|
|
20
|
-
addAdapter('postgres', DMLs.postgres.Driver);
|
|
21
|
-
addAdapter('dm', DMLs.dm.Driver);
|
|
22
|
-
function getAdapter(name) {
|
|
23
|
-
switch (name) {
|
|
24
|
-
case 'mysql':
|
|
25
|
-
case 'sqlite':
|
|
26
|
-
break;
|
|
27
|
-
case 'pg':
|
|
28
|
-
case 'psql':
|
|
29
|
-
case 'postgres':
|
|
30
|
-
case 'postgresql':
|
|
31
|
-
name = 'postgres';
|
|
32
|
-
break;
|
|
33
|
-
case 'dm':
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
// TODO: support install dml driver from node_modules
|
|
37
|
-
if (!(name in adapters)) {
|
|
38
|
-
// trigger error which could be detected by `isDriverNotSupportedError`
|
|
39
|
-
const err = new Error(`No adapter named '${name}' found.`);
|
|
40
|
-
err.code = 'MODULE_NOT_FOUND';
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
return adapters[name];
|
|
44
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const Error_1 = require("./Error");
|
|
3
|
-
const Utilities = require("./Utilities");
|
|
4
|
-
const AggregateFunctions = function (opts) {
|
|
5
|
-
if (typeof opts.driver.getQuery !== "function") {
|
|
6
|
-
throw new Error_1.default("This driver does not support aggregate functions", 'NO_SUPPORT');
|
|
7
|
-
}
|
|
8
|
-
if (!Array.isArray(opts.driver.aggregate_functions)) {
|
|
9
|
-
throw new Error_1.default("This driver does not support aggregate functions", 'NO_SUPPORT');
|
|
10
|
-
}
|
|
11
|
-
const aggregates = [[]];
|
|
12
|
-
let group_by = null;
|
|
13
|
-
let used_distinct = false;
|
|
14
|
-
const aggregationFunc = function (fun) {
|
|
15
|
-
fun = fun.toLocaleLowerCase();
|
|
16
|
-
return function () {
|
|
17
|
-
// select 1st array as args
|
|
18
|
-
var args = (arguments.length && Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.apply(arguments));
|
|
19
|
-
if (args.length > 0) {
|
|
20
|
-
aggregates[aggregates.length - 1].push({ func_name: fun, args: args, as: aggregateAlias(fun, args) });
|
|
21
|
-
// aggregates.push([]);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
aggregates[aggregates.length - 1].push({ func_name: fun, as: aggregateAlias(fun, args) });
|
|
25
|
-
}
|
|
26
|
-
if (fun === "distinct") {
|
|
27
|
-
used_distinct = true;
|
|
28
|
-
}
|
|
29
|
-
return proto;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
const distinct_to_one_row = function () {
|
|
33
|
-
return used_distinct && aggregates.length === 1;
|
|
34
|
-
};
|
|
35
|
-
const proto = {
|
|
36
|
-
groupBy: function (...columns) {
|
|
37
|
-
group_by = columns;
|
|
38
|
-
return this;
|
|
39
|
-
},
|
|
40
|
-
limit: function (offset, limit) {
|
|
41
|
-
if (typeof limit === "number") {
|
|
42
|
-
opts.limit = [offset, limit];
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
opts.limit = [0, offset]; // offset = limit
|
|
46
|
-
}
|
|
47
|
-
return this;
|
|
48
|
-
},
|
|
49
|
-
order: function (...orders) {
|
|
50
|
-
if (!Array.isArray(opts.order)) {
|
|
51
|
-
opts.order = [];
|
|
52
|
-
}
|
|
53
|
-
opts.order = Utilities.standardizeOrder(orders);
|
|
54
|
-
return this;
|
|
55
|
-
},
|
|
56
|
-
select: function (...columns) {
|
|
57
|
-
if (columns.length === 0) {
|
|
58
|
-
throw new Error_1.default("When using append you must at least define one property", 'PARAM_MISMATCH');
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(columns[0])) {
|
|
61
|
-
opts.propertyList = opts.propertyList.concat(columns[0]);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
opts.propertyList = opts.propertyList.concat(Array.prototype.slice.apply(arguments));
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
},
|
|
68
|
-
as: function (alias) {
|
|
69
|
-
if (!aggregates.length || (aggregates.length === 1 && aggregates[0].length === 0)) {
|
|
70
|
-
throw new Error_1.default("No aggregate functions defined yet", 'PARAM_MISMATCH');
|
|
71
|
-
}
|
|
72
|
-
var len = aggregates.length;
|
|
73
|
-
aggregates[len - 1][aggregates[len - 1].length - 1].as = alias;
|
|
74
|
-
return this;
|
|
75
|
-
},
|
|
76
|
-
call: function (fun, args) {
|
|
77
|
-
if (args && args.length > 0) {
|
|
78
|
-
aggregates[aggregates.length - 1].push({ func_name: fun, args: args, as: aggregateAlias(fun, args) });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
aggregates[aggregates.length - 1].push({ func_name: fun, as: aggregateAlias(fun, args) });
|
|
82
|
-
}
|
|
83
|
-
if (fun.toLowerCase() === "distinct") {
|
|
84
|
-
used_distinct = true;
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
},
|
|
88
|
-
getSync: function () {
|
|
89
|
-
if (aggregates[aggregates.length - 1].length === 0) {
|
|
90
|
-
aggregates.length -= 1;
|
|
91
|
-
}
|
|
92
|
-
if (!aggregates.length) {
|
|
93
|
-
throw new Error_1.default("Missing aggregate functions", 'PARAM_MISMATCH');
|
|
94
|
-
}
|
|
95
|
-
const query = opts.driver.getQuery()
|
|
96
|
-
.select()
|
|
97
|
-
.from(opts.table)
|
|
98
|
-
.select(opts.propertyList);
|
|
99
|
-
for (let i = 0; i < aggregates.length; i++) {
|
|
100
|
-
for (let j = 0; j < aggregates[i].length; j++) {
|
|
101
|
-
query.fun(aggregates[i][j].func_name, aggregates[i][j].args, aggregates[i][j].as);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
query.where(opts.conditions);
|
|
105
|
-
if (group_by !== null) {
|
|
106
|
-
query.groupBy.apply(query, group_by);
|
|
107
|
-
}
|
|
108
|
-
if (opts.order) {
|
|
109
|
-
for (let i = 0; i < opts.order.length; i++) {
|
|
110
|
-
query.order(opts.order[i][0], opts.order[i][1]);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (opts.limit) {
|
|
114
|
-
query.offset(opts.limit[0]).limit(opts.limit[1]);
|
|
115
|
-
}
|
|
116
|
-
const q_str = query.build();
|
|
117
|
-
const data = opts.driver.execQuery(q_str);
|
|
118
|
-
if (group_by !== null) {
|
|
119
|
-
return data;
|
|
120
|
-
}
|
|
121
|
-
var items = [];
|
|
122
|
-
if (distinct_to_one_row()) {
|
|
123
|
-
for (let i = 0; i < data.length; i++) {
|
|
124
|
-
items.push(data[i][Object.keys(data[i]).pop()]);
|
|
125
|
-
}
|
|
126
|
-
return items;
|
|
127
|
-
}
|
|
128
|
-
for (let i = 0; i < aggregates.length; i++) {
|
|
129
|
-
for (let j = 0; j < aggregates[i].length; j++) {
|
|
130
|
-
items.push(data[0][aggregates[i][j].as] || null);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return items;
|
|
134
|
-
},
|
|
135
|
-
get: function (cb) {
|
|
136
|
-
if (typeof cb !== "function") {
|
|
137
|
-
throw new Error_1.default("You must pass a callback to Model.aggregate().get()", 'MISSING_CALLBACK');
|
|
138
|
-
}
|
|
139
|
-
const syncReponse = Utilities.catchBlocking(proto.getSync, [], { thisArg: proto });
|
|
140
|
-
if (syncReponse.error instanceof Error_1.default && syncReponse.error.code === Error_1.default.codes['PARAM_MISMATCH']) {
|
|
141
|
-
throw syncReponse.error;
|
|
142
|
-
}
|
|
143
|
-
Utilities.takeAwayResult(syncReponse, {
|
|
144
|
-
callback: cb && function (err, results) {
|
|
145
|
-
if (err)
|
|
146
|
-
return cb(err);
|
|
147
|
-
if (distinct_to_one_row())
|
|
148
|
-
return cb(null, results);
|
|
149
|
-
/**
|
|
150
|
-
* when not used_distinct, support to spread results as callback's arguments
|
|
151
|
-
*/
|
|
152
|
-
results.unshift(null);
|
|
153
|
-
return cb.apply(null, results);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
opts.driver.aggregate_functions.forEach(aggregate_function => {
|
|
159
|
-
addAggregate(proto, aggregate_function, aggregationFunc);
|
|
160
|
-
});
|
|
161
|
-
return proto;
|
|
162
|
-
};
|
|
163
|
-
function addAggregate(proto, fun, builder) {
|
|
164
|
-
let k;
|
|
165
|
-
if (Array.isArray(fun)) {
|
|
166
|
-
k = fun[0].toLowerCase();
|
|
167
|
-
proto[k] = builder(fun[1] || fun[0]);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
k = fun.toLowerCase();
|
|
171
|
-
proto[k] = builder(fun);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function aggregateAlias(fun, fields) {
|
|
175
|
-
return fun + (fields && fields.length ? "_" + fields.join("_") : "");
|
|
176
|
-
}
|
|
177
|
-
module.exports = AggregateFunctions;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { FxOrmInstance } from '../Typo/instance';
|
|
2
|
-
import type { FxOrmAssociation } from '../Typo/assoc';
|
|
3
|
-
import type { FxOrmNS } from '../Typo/ORM';
|
|
4
|
-
import type { FxOrmModel } from '../Typo/model';
|
|
5
|
-
import type { FxOrmDMLDriver } from '../Typo/DMLDriver';
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param db orm instance
|
|
9
|
-
* @param Model model
|
|
10
|
-
* @param associations association definitions
|
|
11
|
-
*/
|
|
12
|
-
export declare function prepare(Model: FxOrmModel.Model, assocs: {
|
|
13
|
-
one_associations: FxOrmAssociation.InstanceAssociationItem_HasOne[];
|
|
14
|
-
many_associations: FxOrmAssociation.InstanceAssociationItem_HasMany[];
|
|
15
|
-
extend_associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[];
|
|
16
|
-
}, opts: {
|
|
17
|
-
db: FxOrmNS.ORM;
|
|
18
|
-
}): void;
|
|
19
|
-
export declare function extend(Model: FxOrmModel.Model, Instance: FxOrmInstance.Instance, Driver: FxOrmDMLDriver.DMLDriver, associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[], cfg: {
|
|
20
|
-
assoc_opts: FxOrmAssociation.AssociationDefinitionOptions_HasOne;
|
|
21
|
-
}): void;
|
|
22
|
-
export declare function autoFetch(Instance: FxOrmInstance.Instance, associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[], opts: FxOrmNS.ModelAutoFetchOptions, parallel?: boolean): void;
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepare = prepare;
|
|
4
|
-
exports.extend = extend;
|
|
5
|
-
exports.autoFetch = autoFetch;
|
|
6
|
-
const util = require("util");
|
|
7
|
-
const Hook = require("../Hook");
|
|
8
|
-
const _cloneDeep = require("lodash.clonedeep");
|
|
9
|
-
const Error_1 = require("../Error");
|
|
10
|
-
const Singleton = require("../Singleton");
|
|
11
|
-
const Utilities = require("../Utilities");
|
|
12
|
-
const Helpers = require("../Helpers");
|
|
13
|
-
const Model_1 = require("../Model");
|
|
14
|
-
const _utils_1 = require("./_utils");
|
|
15
|
-
function noOperation(...args) { }
|
|
16
|
-
;
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param db orm instance
|
|
20
|
-
* @param Model model
|
|
21
|
-
* @param associations association definitions
|
|
22
|
-
*/
|
|
23
|
-
function prepare(Model, assocs, opts) {
|
|
24
|
-
const { extend_associations } = assocs;
|
|
25
|
-
const { db } = opts;
|
|
26
|
-
Model.extendsTo = function (name, properties, assoc_options) {
|
|
27
|
-
Utilities.disAllowOpForVModel(Model, 'model.extendsTo');
|
|
28
|
-
assoc_options = assoc_options || {};
|
|
29
|
-
for (let i = 0; i < db.plugins.length; i++) {
|
|
30
|
-
if (typeof db.plugins[i].beforeExtendsTo === "function") {
|
|
31
|
-
db.plugins[i].beforeExtendsTo(Model, {
|
|
32
|
-
association_name: name,
|
|
33
|
-
properties: properties,
|
|
34
|
-
assoc_options
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const associationSemanticNameCore = assoc_options.name || Utilities.formatNameFor("assoc:extendsTo", name);
|
|
39
|
-
const association = {
|
|
40
|
-
name: name,
|
|
41
|
-
model: null,
|
|
42
|
-
table: assoc_options.table || (0, _utils_1.defineDefaultExtendsToTableName)(Model.table, name),
|
|
43
|
-
reverse: assoc_options.reverse,
|
|
44
|
-
// reversed : assoc_options.reversed,
|
|
45
|
-
autoFetch: assoc_options.autoFetch || false,
|
|
46
|
-
autoFetchLimit: assoc_options.autoFetchLimit || 2,
|
|
47
|
-
field: Utilities.wrapFieldObject({
|
|
48
|
-
field: assoc_options.field,
|
|
49
|
-
model: Model,
|
|
50
|
-
altName: Model.table
|
|
51
|
-
}) || Utilities.formatAssociatedField(Model, Model.table, false, false),
|
|
52
|
-
getAccessor: assoc_options.getAccessor || (0, _utils_1.defineAssociationAccessorMethodName)(_utils_1.ACCESSOR_KEYS.get, associationSemanticNameCore),
|
|
53
|
-
setAccessor: assoc_options.setAccessor || (0, _utils_1.defineAssociationAccessorMethodName)(_utils_1.ACCESSOR_KEYS.set, associationSemanticNameCore),
|
|
54
|
-
hasAccessor: assoc_options.hasAccessor || (0, _utils_1.defineAssociationAccessorMethodName)(_utils_1.ACCESSOR_KEYS.has, associationSemanticNameCore),
|
|
55
|
-
delAccessor: assoc_options.delAccessor || (0, _utils_1.defineAssociationAccessorMethodName)(_utils_1.ACCESSOR_KEYS.del, associationSemanticNameCore),
|
|
56
|
-
modelFindByAccessor: assoc_options.modelFindByAccessor || (0, _utils_1.defineAssociationAccessorMethodName)(_utils_1.ACCESSOR_KEYS.modelFindBy, associationSemanticNameCore),
|
|
57
|
-
hooks: Object.assign({}, assoc_options.hooks),
|
|
58
|
-
};
|
|
59
|
-
Utilities.fillSyncVersionAccessorForAssociation(association);
|
|
60
|
-
Utilities.addHookPatchHelperForAssociation(association);
|
|
61
|
-
const newProperties = _cloneDeep(properties);
|
|
62
|
-
const assoc_field = association.field;
|
|
63
|
-
for (let k in assoc_field) {
|
|
64
|
-
assoc_field[k].klass = 'extendsTo';
|
|
65
|
-
if (assoc_field[k].type === 'serial') {
|
|
66
|
-
assoc_field[k].type = 'integer';
|
|
67
|
-
assoc_field[k].key = true;
|
|
68
|
-
}
|
|
69
|
-
newProperties[k] = assoc_field[k];
|
|
70
|
-
}
|
|
71
|
-
const modelOpts = util.extend(util.pick(assoc_options, 'identityCache', 'autoSave', 'cascadeRemove', 'hooks', 'methods', 'validations'), {
|
|
72
|
-
id: Object.keys(assoc_field),
|
|
73
|
-
__for_extension: true,
|
|
74
|
-
});
|
|
75
|
-
association.model = db.define(association.table, newProperties, modelOpts);
|
|
76
|
-
association.model.hasOne(association.reverse || Model.table, Model, {
|
|
77
|
-
__for_extension: true,
|
|
78
|
-
field: assoc_field,
|
|
79
|
-
reverse: null,
|
|
80
|
-
reversed: false,
|
|
81
|
-
hooks: assoc_options.reverseHooks
|
|
82
|
-
});
|
|
83
|
-
extend_associations.push(association);
|
|
84
|
-
const findByAccessorChainOrRunSync = function (is_sync = false) {
|
|
85
|
-
return function () {
|
|
86
|
-
var cb = null, conditions = null, options = {};
|
|
87
|
-
const args = Array.prototype.slice.apply(arguments);
|
|
88
|
-
Helpers.selectArgs(args, (arg_type, arg) => {
|
|
89
|
-
switch (arg_type) {
|
|
90
|
-
case "function":
|
|
91
|
-
cb = arg;
|
|
92
|
-
break;
|
|
93
|
-
case "object":
|
|
94
|
-
if (conditions === null) {
|
|
95
|
-
conditions = arg;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
options = arg;
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if (conditions === null) {
|
|
104
|
-
throw new Error_1.default(`.${association.modelFindByAccessor}() is missing a conditions object`, 'PARAM_MISMATCH');
|
|
105
|
-
}
|
|
106
|
-
return (0, Model_1.listFindByChainOrRunSync)(Model, {}, [
|
|
107
|
-
{
|
|
108
|
-
association_name: association.name,
|
|
109
|
-
conditions: conditions
|
|
110
|
-
},
|
|
111
|
-
], options, { callback: cb, is_sync });
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
Model[association.modelFindByAccessor] = findByAccessorChainOrRunSync();
|
|
115
|
-
Model[association.modelFindBySyncAccessor] = findByAccessorChainOrRunSync(true);
|
|
116
|
-
(0, _utils_1.addAssociationInfoToModel)(Model, name, {
|
|
117
|
-
type: 'extendsTo',
|
|
118
|
-
association: association
|
|
119
|
-
});
|
|
120
|
-
return association.model;
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
;
|
|
124
|
-
function extend(Model, Instance, Driver, associations, cfg) {
|
|
125
|
-
for (let i = 0; i < associations.length; i++) {
|
|
126
|
-
extendInstance(Model, Instance, Driver, associations[i], cfg);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
;
|
|
130
|
-
function autoFetch(Instance, associations, opts, parallel = false) {
|
|
131
|
-
if (associations.length === 0) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
Utilities.parallelQueryIfPossible(parallel, associations, (item) => autoFetchInstance(Instance, item, opts));
|
|
135
|
-
}
|
|
136
|
-
;
|
|
137
|
-
function extendInstance(Model, Instance, Driver, association, cfg) {
|
|
138
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.hasSyncAccessor, function () {
|
|
139
|
-
if (!Instance[Model.id + ''])
|
|
140
|
-
throw new Error_1.default("Instance not saved, cannot get extension", 'NOT_DEFINED', { model: Model.table });
|
|
141
|
-
try {
|
|
142
|
-
return !!association.model.getSync(Utilities.values(Instance, Model.id));
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
if (!Model.settings.get('extendsTo.throwWhenNotFound') && error.literalCode === 'NOT_FOUND')
|
|
146
|
-
return false;
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.hasAccessor, function (cb) {
|
|
151
|
-
process.nextTick(() => {
|
|
152
|
-
const syncResponse = Utilities.catchBlocking(Instance[association.hasSyncAccessor]);
|
|
153
|
-
syncResponse.result = !!syncResponse.result;
|
|
154
|
-
Utilities.takeAwayResult(syncResponse, { no_throw: true, callback: cb });
|
|
155
|
-
});
|
|
156
|
-
return this;
|
|
157
|
-
});
|
|
158
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.getSyncAccessor, function (opts = {}) {
|
|
159
|
-
if (!Instance[Model.id + ''])
|
|
160
|
-
throw new Error_1.default("Instance not saved, cannot get extension", 'NOT_DEFINED', { model: Model.table });
|
|
161
|
-
try {
|
|
162
|
-
return association.model.getSync(Utilities.values(Instance, Model.id), opts);
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
if (!Model.settings.get('extendsTo.throwWhenNotFound') && error.literalCode === 'NOT_FOUND')
|
|
166
|
-
return null;
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.getAccessor, function () {
|
|
171
|
-
let opts = {};
|
|
172
|
-
let cb;
|
|
173
|
-
const args = Array.prototype.slice.apply(arguments);
|
|
174
|
-
Helpers.selectArgs(args, (arg_type, arg) => {
|
|
175
|
-
switch (arg_type) {
|
|
176
|
-
case "function":
|
|
177
|
-
cb = arg;
|
|
178
|
-
break;
|
|
179
|
-
case "object":
|
|
180
|
-
opts = arg;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
process.nextTick(() => {
|
|
185
|
-
const syncResponse = Utilities.catchBlocking(Instance[association.getSyncAccessor], [opts]);
|
|
186
|
-
Utilities.takeAwayResult(syncResponse, { no_throw: true, callback: cb });
|
|
187
|
-
});
|
|
188
|
-
return this;
|
|
189
|
-
});
|
|
190
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.setSyncAccessor, function (Extension) {
|
|
191
|
-
const $ref = {
|
|
192
|
-
instance: Instance,
|
|
193
|
-
association: Extension,
|
|
194
|
-
useChannel: Utilities.reusableChannelGenerator()
|
|
195
|
-
};
|
|
196
|
-
Hook.wait(Instance, association.hooks[`beforeSet`], Utilities.makeHandlerDecorator({ thisArg: Instance }, () => {
|
|
197
|
-
let Extension = $ref.association;
|
|
198
|
-
Instance.$emit(`before:set:${association.name}`, Extension);
|
|
199
|
-
Instance.saveSync();
|
|
200
|
-
Instance.$emit(`before-del-extension:${association.setAccessor}`);
|
|
201
|
-
Instance[association.delSyncAccessor]();
|
|
202
|
-
Instance.$emit(`after-del-extension:${association.setAccessor}`);
|
|
203
|
-
const fields = Object.keys(association.field);
|
|
204
|
-
if (!Extension.isInstance) {
|
|
205
|
-
$ref.association = Extension = new association.model(Extension);
|
|
206
|
-
}
|
|
207
|
-
for (let i = 0; i < Model.id.length; i++) {
|
|
208
|
-
Extension[fields[i]] = Instance[Model.id[i]];
|
|
209
|
-
}
|
|
210
|
-
Instance.$emit(`before-save-extension:${association.setAccessor}`, Extension);
|
|
211
|
-
Extension.saveSync();
|
|
212
|
-
Instance.$emit(`after-save-extension:${association.setAccessor}`, Extension);
|
|
213
|
-
Instance.$emit(`after:set:${association.name}`, Extension);
|
|
214
|
-
}), Utilities.buildAssocHooksContext('beforeSet', { $ref }));
|
|
215
|
-
Hook.trigger(Instance, association.hooks['afterSet'], Utilities.buildAssocHooksContext('afterSet', { $ref }));
|
|
216
|
-
return $ref.association;
|
|
217
|
-
});
|
|
218
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.setAccessor, function (Extension, cb) {
|
|
219
|
-
process.nextTick(() => {
|
|
220
|
-
const syncResponse = Utilities.catchBlocking(Instance[association.setSyncAccessor], [Extension]);
|
|
221
|
-
Utilities.takeAwayResult(syncResponse, { no_throw: true, callback: cb });
|
|
222
|
-
});
|
|
223
|
-
return this;
|
|
224
|
-
});
|
|
225
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.delSyncAccessor, function () {
|
|
226
|
-
if (!Instance[Model.id + ''])
|
|
227
|
-
throw new Error_1.default("Instance not saved, cannot get extension", 'NOT_DEFINED', { model: Model.table });
|
|
228
|
-
const conditions = {};
|
|
229
|
-
const fields = Object.keys(association.field);
|
|
230
|
-
for (let i = 0; i < Model.id.length; i++) {
|
|
231
|
-
conditions[fields[i]] = Instance[Model.id[i]];
|
|
232
|
-
}
|
|
233
|
-
const $ref = {
|
|
234
|
-
instance: Instance,
|
|
235
|
-
removeConditions: conditions,
|
|
236
|
-
useChannel: Utilities.reusableChannelGenerator()
|
|
237
|
-
};
|
|
238
|
-
Hook.wait(Instance, association.hooks[`beforeRemove`], Utilities.makeHandlerDecorator({ thisArg: Instance }, () => {
|
|
239
|
-
const extensions = association.model.findSync($ref.removeConditions);
|
|
240
|
-
Instance.$emit(`before:del:${association.name}`, extensions);
|
|
241
|
-
for (let i = 0; i < extensions.length; i++) {
|
|
242
|
-
Singleton.clear(extensions[i].__singleton_uid() + '');
|
|
243
|
-
extensions[i].removeSync();
|
|
244
|
-
}
|
|
245
|
-
Instance.$emit(`after:del:${association.name}`, extensions);
|
|
246
|
-
}), Utilities.buildAssocHooksContext('beforeRemove', { $ref }));
|
|
247
|
-
Hook.trigger(Instance, association.hooks['afterRemove'], Utilities.buildAssocHooksContext('afterRemove', { $ref }));
|
|
248
|
-
return;
|
|
249
|
-
});
|
|
250
|
-
Utilities.addHiddenPropertyToInstance(Instance, association.delAccessor, function (cb) {
|
|
251
|
-
process.nextTick(() => {
|
|
252
|
-
const syncResponse = Utilities.catchBlocking(Instance[association.delSyncAccessor]);
|
|
253
|
-
Utilities.takeAwayResult(syncResponse, { no_throw: true, callback: cb });
|
|
254
|
-
});
|
|
255
|
-
return this;
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
function autoFetchInstance(Instance, association, opts) {
|
|
259
|
-
if (!Instance.saved())
|
|
260
|
-
return;
|
|
261
|
-
if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit == "undefined") {
|
|
262
|
-
opts.autoFetchLimit = association.autoFetchLimit;
|
|
263
|
-
}
|
|
264
|
-
if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch))
|
|
265
|
-
return;
|
|
266
|
-
if (Instance.isPersisted()) {
|
|
267
|
-
try {
|
|
268
|
-
const Assoc = Instance[association.getSyncAccessor]({ autoFetchLimit: opts.autoFetchLimit - 1 });
|
|
269
|
-
Instance[association.name] = Assoc;
|
|
270
|
-
}
|
|
271
|
-
catch (err) { }
|
|
272
|
-
}
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { FxOrmInstance } from '../Typo/instance';
|
|
2
|
-
import type { FxOrmAssociation } from '../Typo/assoc';
|
|
3
|
-
import type { FxOrmModel } from '../Typo/model';
|
|
4
|
-
import type { FxOrmDMLDriver } from '../Typo/DMLDriver';
|
|
5
|
-
import type { FxOrmNS } from '../Typo/ORM';
|
|
6
|
-
export declare function prepare(Model: FxOrmModel.Model, assocs: {
|
|
7
|
-
one_associations: FxOrmAssociation.InstanceAssociationItem_HasOne[];
|
|
8
|
-
many_associations: FxOrmAssociation.InstanceAssociationItem_HasMany[];
|
|
9
|
-
extend_associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[];
|
|
10
|
-
}, opts: {
|
|
11
|
-
db: FxOrmNS.ORM;
|
|
12
|
-
}): void;
|
|
13
|
-
export declare function extend(Model: FxOrmModel.Model, Instance: FxOrmInstance.Instance, Driver: FxOrmDMLDriver.DMLDriver, associations: FxOrmAssociation.InstanceAssociationItem_HasMany[], cfg: {
|
|
14
|
-
assoc_opts: FxOrmAssociation.AssociationDefinitionOptions_HasMany;
|
|
15
|
-
}): void;
|
|
16
|
-
export declare function autoFetch(Instance: FxOrmInstance.Instance, associations: FxOrmAssociation.InstanceAssociationItem_HasMany[], opts: FxOrmAssociation.AssociationDefinitionOptions_HasMany, parallel?: boolean): void;
|