taon 21.0.51 → 21.0.53
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/bin/taon +5 -5
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +4 -4
- package/browser/fesm2022/taon-browser.mjs +11 -1
- package/browser/fesm2022/taon-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser-prod/fesm2022/taon-browser.mjs +11 -1
- package/browser-prod/fesm2022/taon-browser.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/icon-menu-taon.svg +15 -15
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/endpoint-context.d.ts +1 -1
- package/lib/endpoint-context.js +11 -6
- package/lib/endpoint-context.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-abstract-entity.js +33 -0
- package/lib-prod/base-classes/base-angular-service.js +56 -0
- package/lib-prod/base-classes/base-class.js +37 -0
- package/lib-prod/base-classes/base-context.js +21 -0
- package/lib-prod/base-classes/base-controller.js +162 -0
- package/lib-prod/base-classes/base-crud-controller.js +235 -0
- package/lib-prod/base-classes/base-custom-repository.js +20 -0
- package/lib-prod/base-classes/base-electron-service.js +0 -0
- package/lib-prod/base-classes/base-entity.js +32 -0
- package/lib-prod/base-classes/base-file-upload.middleware.js +78 -0
- package/lib-prod/base-classes/base-injector.js +202 -0
- package/lib-prod/base-classes/base-middleware.js +6 -0
- package/lib-prod/base-classes/base-migration.js +23 -0
- package/lib-prod/base-classes/base-provider.js +6 -0
- package/lib-prod/base-classes/base-repository.js +589 -0
- package/lib-prod/base-classes/base-subscriber-for-entity.js +154 -0
- package/lib-prod/base-classes/base.js +0 -0
- package/lib-prod/build-info._auto-generated_.js +14 -0
- package/lib-prod/config/controller-config.js +28 -0
- package/lib-prod/config/controller-options.js +6 -0
- package/lib-prod/config/method-config.js +9 -0
- package/lib-prod/config/param-config.js +9 -0
- package/lib-prod/constants.js +29 -0
- package/lib-prod/context-db-migrations.js +339 -0
- package/lib-prod/create-context.js +152 -0
- package/lib-prod/decorators/classes/controller-decorator.js +21 -0
- package/lib-prod/decorators/classes/entity-decorator.js +49 -0
- package/lib-prod/decorators/classes/middleware-decorator.js +26 -0
- package/lib-prod/decorators/classes/migration-decorator.js +24 -0
- package/lib-prod/decorators/classes/provider-decorator.js +25 -0
- package/lib-prod/decorators/classes/repository-decorator.js +24 -0
- package/lib-prod/decorators/classes/subscriber-decorator.js +25 -0
- package/lib-prod/decorators/decorator-abstract-opt.js +5 -0
- package/lib-prod/decorators/http/http-decorators.js +5 -0
- package/lib-prod/decorators/http/http-methods-decorators.js +144 -0
- package/lib-prod/decorators/http/http-params-decorators.js +68 -0
- package/lib-prod/dependency-injection/di-container.js +31 -0
- package/lib-prod/endpoint-context-storage.js +36 -0
- package/lib-prod/endpoint-context.js +2033 -0
- package/lib-prod/entity-process.js +214 -0
- package/lib-prod/env/env.angular-node-app.js +130 -0
- package/lib-prod/env/env.docs-webapp.js +130 -0
- package/lib-prod/env/env.electron-app.js +130 -0
- package/lib-prod/env/env.mobile-app.js +130 -0
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +130 -0
- package/lib-prod/env/env.vscode-plugin.js +130 -0
- package/lib-prod/env/index.js +6 -0
- package/lib-prod/express-types.js +0 -0
- package/lib-prod/formly/formly.models.js +0 -0
- package/lib-prod/formly/fromly.js +184 -0
- package/lib-prod/formly/type-from-entity.js +58 -0
- package/lib-prod/get-response-value.js +19 -0
- package/lib-prod/global-state/taon-global-state/index.js +5 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.js +20 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +10 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +48 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +48 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +22 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +34 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +22 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +47 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +29 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +11 -0
- package/lib-prod/global-state/taon-transaction-registry/index.js +10 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +8 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +41 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +56 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +10 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +29 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +6 -0
- package/lib-prod/helpers/class-helpers.js +195 -0
- package/lib-prod/helpers/clone-obj.js +21 -0
- package/lib-prod/helpers/taon-helpers.js +129 -0
- package/lib-prod/index._auto-generated_.js +0 -0
- package/lib-prod/index.js +231 -0
- package/lib-prod/inject.js +34 -0
- package/lib-prod/migrations/index.js +1 -0
- package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -0
- package/lib-prod/models.js +109 -0
- package/lib-prod/orm/columns.js +124 -0
- package/lib-prod/orm/index.js +1 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +196 -0
- package/lib-prod/realtime/realtime-core.js +82 -0
- package/lib-prod/realtime/realtime-server.js +252 -0
- package/lib-prod/realtime/realtime-strategy/index.js +4 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +226 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +262 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +21 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +14 -0
- package/lib-prod/realtime/realtime-subs-manager.js +96 -0
- package/lib-prod/realtime/realtime.models.js +0 -0
- package/lib-prod/symbols.js +109 -0
- package/lib-prod/ui/index.js +5 -0
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +5 -0
- package/lib-prod/validators.js +74 -0
- package/package.json +1 -1
- package/websql/fesm2022/taon-websql.mjs +11 -1
- package/websql/fesm2022/taon-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/fesm2022/taon-websql.mjs +11 -1
- package/websql-prod/fesm2022/taon-websql.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/base-classes/base-abstract-entity.ts +0 -34
- package/lib-prod/base-classes/base-angular-service.ts +0 -107
- package/lib-prod/base-classes/base-class.ts +0 -46
- package/lib-prod/base-classes/base-context.ts +0 -21
- package/lib-prod/base-classes/base-controller.ts +0 -240
- package/lib-prod/base-classes/base-crud-controller.ts +0 -298
- package/lib-prod/base-classes/base-custom-repository.ts +0 -10
- package/lib-prod/base-classes/base-electron-service.ts +0 -60
- package/lib-prod/base-classes/base-entity.ts +0 -28
- package/lib-prod/base-classes/base-file-upload.middleware.ts +0 -92
- package/lib-prod/base-classes/base-injector.ts +0 -278
- package/lib-prod/base-classes/base-middleware.ts +0 -71
- package/lib-prod/base-classes/base-migration.ts +0 -26
- package/lib-prod/base-classes/base-provider.ts +0 -8
- package/lib-prod/base-classes/base-repository.ts +0 -942
- package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
- package/lib-prod/base-classes/base.ts +0 -31
- package/lib-prod/build-info._auto-generated_.ts +0 -27
- package/lib-prod/config/controller-config.ts +0 -58
- package/lib-prod/config/controller-options.ts +0 -19
- package/lib-prod/config/method-config.ts +0 -55
- package/lib-prod/config/param-config.ts +0 -16
- package/lib-prod/constants.ts +0 -63
- package/lib-prod/context-db-migrations.ts +0 -488
- package/lib-prod/create-context.ts +0 -345
- package/lib-prod/decorators/classes/controller-decorator.ts +0 -25
- package/lib-prod/decorators/classes/entity-decorator.ts +0 -57
- package/lib-prod/decorators/classes/middleware-decorator.ts +0 -29
- package/lib-prod/decorators/classes/migration-decorator.ts +0 -27
- package/lib-prod/decorators/classes/provider-decorator.ts +0 -28
- package/lib-prod/decorators/classes/repository-decorator.ts +0 -26
- package/lib-prod/decorators/classes/subscriber-decorator.ts +0 -28
- package/lib-prod/decorators/decorator-abstract-opt.ts +0 -4
- package/lib-prod/decorators/http/http-decorators.ts +0 -26
- package/lib-prod/decorators/http/http-methods-decorators.ts +0 -275
- package/lib-prod/decorators/http/http-params-decorators.ts +0 -105
- package/lib-prod/dependency-injection/di-container.ts +0 -39
- package/lib-prod/endpoint-context-storage.ts +0 -47
- package/lib-prod/endpoint-context.ts +0 -3105
- package/lib-prod/entity-process.ts +0 -286
- package/lib-prod/env/env.angular-node-app.ts +0 -66
- package/lib-prod/env/env.docs-webapp.ts +0 -66
- package/lib-prod/env/env.electron-app.ts +0 -66
- package/lib-prod/env/env.mobile-app.ts +0 -66
- package/lib-prod/env/env.npm-lib-and-cli-tool.ts +0 -66
- package/lib-prod/env/env.vscode-plugin.ts +0 -66
- package/lib-prod/env/index.ts +0 -6
- package/lib-prod/express-types.ts +0 -4
- package/lib-prod/formly/formly.models.ts +0 -7
- package/lib-prod/formly/fromly.ts +0 -261
- package/lib-prod/formly/type-from-entity.ts +0 -80
- package/lib-prod/get-response-value.ts +0 -30
- package/lib-prod/global-state/taon-global-state/index.ts +0 -6
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.ts +0 -21
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.ts +0 -9
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.ts +0 -44
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.ts +0 -40
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.ts +0 -12
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.ts +0 -48
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.ts +0 -16
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.ts +0 -47
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.ts +0 -18
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.ts +0 -21
- package/lib-prod/global-state/taon-transaction-registry/index.ts +0 -11
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.ts +0 -23
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.ts +0 -7
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.ts +0 -38
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.ts +0 -54
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.ts +0 -12
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.ts +0 -6
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.ts +0 -16
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.ts +0 -29
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.ts +0 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.ts +0 -9
- package/lib-prod/helpers/class-helpers.ts +0 -315
- package/lib-prod/helpers/clone-obj.ts +0 -24
- package/lib-prod/helpers/taon-helpers.ts +0 -181
- package/lib-prod/index._auto-generated_.ts +0 -5
- package/lib-prod/index.ts +0 -323
- package/lib-prod/inject.ts +0 -111
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/migrations/index.ts +0 -2
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/migrations/migrations_index._auto-generated_.ts +0 -5
- package/lib-prod/models.ts +0 -427
- package/lib-prod/orm/columns.ts +0 -121
- package/lib-prod/orm/index.ts +0 -62
- package/lib-prod/realtime/realtime-client.ts +0 -288
- package/lib-prod/realtime/realtime-core.ts +0 -134
- package/lib-prod/realtime/realtime-server.ts +0 -398
- package/lib-prod/realtime/realtime-strategy/index.ts +0 -4
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.ts +0 -344
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.ts +0 -349
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.ts +0 -30
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.ts +0 -21
- package/lib-prod/realtime/realtime-subs-manager.ts +0 -127
- package/lib-prod/realtime/realtime.models.ts +0 -33
- package/lib-prod/symbols.ts +0 -136
- package/lib-prod/ui/index.ts +0 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.ts +0 -1
- package/lib-prod/validators.ts +0 -103
|
@@ -1,942 +0,0 @@
|
|
|
1
|
-
//#region imports
|
|
2
|
-
import { MySqlQuerySource } from 'taon-type-sql/lib-prod';
|
|
3
|
-
import {
|
|
4
|
-
type DataSource,
|
|
5
|
-
type DeepPartial,
|
|
6
|
-
type DeleteResult,
|
|
7
|
-
type FindManyOptions,
|
|
8
|
-
type FindOneOptions,
|
|
9
|
-
type FindOptionsWhere,
|
|
10
|
-
type InsertResult,
|
|
11
|
-
// ObjectID // TODO why is this not in taon-typeorm,
|
|
12
|
-
type RemoveOptions,
|
|
13
|
-
type Repository,
|
|
14
|
-
type SaveOptions,
|
|
15
|
-
type UpdateResult,
|
|
16
|
-
} from 'taon-typeorm/lib-prod';
|
|
17
|
-
import type { QueryDeepPartialEntity } from 'taon-typeorm/lib-prod';
|
|
18
|
-
import type { UpsertOptions } from 'taon-typeorm/lib-prod';
|
|
19
|
-
import type {
|
|
20
|
-
DataSource as DataSourceType,
|
|
21
|
-
QueryRunner,
|
|
22
|
-
SelectQueryBuilder,
|
|
23
|
-
} from 'taon-typeorm/lib-prod';
|
|
24
|
-
import { Helpers__NS___fixCommand, Helpers__NS__bigMaxBuffer, Helpers__NS__checkProcess, Helpers__NS__cleanExit, Helpers__NS__clearConsole, Helpers__NS__command, Helpers__NS__commandOutputAsString, Helpers__NS__commandOutputAsStringAsync, Helpers__NS__compilationWrapper, Helpers__NS__contain, Helpers__NS__createFolder, Helpers__NS__createSymLink, Helpers__NS__error, Helpers__NS__execute, Helpers__NS__exists, Helpers__NS__filesFrom, Helpers__NS__foldersFrom, Helpers__NS__getFilesFrom, Helpers__NS__getFoldersFrom, Helpers__NS__getIsBrowser, Helpers__NS__getIsElectron, Helpers__NS__getIsNode, Helpers__NS__getIsRunningInGitBash, Helpers__NS__getIsSupportedTaonTerminal, Helpers__NS__getIsVerboseMode, Helpers__NS__getIsWebSQL, Helpers__NS__getIsWsl, Helpers__NS__getStdio, Helpers__NS__hideNodeWarnings, Helpers__NS__info, Helpers__NS__isBlob, Helpers__NS__isBuffer, Helpers__NS__isClass, Helpers__NS__isExistedSymlink, Helpers__NS__isFile, Helpers__NS__isFolder, Helpers__NS__isRunningInDocker, Helpers__NS__isRunningInLinuxGraphicsCapableEnvironment, Helpers__NS__isSymlinkFileExitedOrUnexisted, Helpers__NS__isSymlinkThatMatchesUrl, Helpers__NS__isUnexistedLink, Helpers__NS__killOnPort, Helpers__NS__killProcess, Helpers__NS__killProcessByPort, Helpers__NS__linksToFolderFrom, Helpers__NS__linksToFoldersFrom, Helpers__NS__log, Helpers__NS__logError, Helpers__NS__logInfo, Helpers__NS__logProc, Helpers__NS__logSuccess, Helpers__NS__logWarn, Helpers__NS__mediaTypeFromSrc, Helpers__NS__mkdirp, Helpers__NS__modifyLineByLine, Helpers__NS__msgCacheClear, Helpers__NS__openFolderInFileExplorer, Helpers__NS__parse, Helpers__NS__pathContainLink, Helpers__NS__questionYesNo, Helpers__NS__readFile, Helpers__NS__readJson, Helpers__NS__readJson5, Helpers__NS__readJsonC, Helpers__NS__relative, Helpers__NS__remove, Helpers__NS__removeEmptyLineFromString, Helpers__NS__removeFileIfExists, Helpers__NS__removeFolderIfExists, Helpers__NS__removeIfExists, Helpers__NS__removeSlashAtBegin, Helpers__NS__removeSlashAtEnd, Helpers__NS__removeSymlinks, Helpers__NS__renderError, Helpers__NS__replaceLinesInFile, Helpers__NS__run, Helpers__NS__runAsyncIn, Helpers__NS__runSyncIn, Helpers__NS__runSyncOrAsync, Helpers__NS__sleep, Helpers__NS__stopApplication, Helpers__NS__stringify, Helpers__NS__success, Helpers__NS__taskDone, Helpers__NS__taskStarted, Helpers__NS__throwError, Helpers__NS__timeout, Helpers__NS__tryCatchError, Helpers__NS__tryReadFile, Helpers__NS__tryRemoveDir, Helpers__NS__values, Helpers__NS__wait, Helpers__NS__warn, Helpers__NS__writeFile, Helpers__NS__writeJson, Helpers__NS__writeJson5, Helpers__NS__writeJsonC } from 'tnp-core/lib-prod';
|
|
25
|
-
import { ___NS__add, ___NS__after, ___NS__ary, ___NS__assign, ___NS__assignIn, ___NS__assignInWith, ___NS__assignWith, ___NS__at, ___NS__attempt, ___NS__before, ___NS__bind, ___NS__bindAll, ___NS__bindKey, ___NS__camelCase, ___NS__capitalize, ___NS__castArray, ___NS__ceil, ___NS__chain, ___NS__chunk, ___NS__clamp, ___NS__clone, ___NS__cloneDeep, ___NS__cloneDeepWith, ___NS__cloneWith, ___NS__compact, ___NS__concat, ___NS__cond, ___NS__conforms, ___NS__conformsTo, ___NS__constant, ___NS__countBy, ___NS__create, ___NS__curry, ___NS__curryRight, ___NS__debounce, ___NS__deburr, ___NS__defaults, ___NS__defaultsDeep, ___NS__defaultTo, ___NS__defer, ___NS__delay, ___NS__difference, ___NS__differenceBy, ___NS__differenceWith, ___NS__divide, ___NS__drop, ___NS__dropRight, ___NS__dropRightWhile, ___NS__dropWhile, ___NS__each, ___NS__eachRight, ___NS__endsWith, ___NS__entries, ___NS__entriesIn, ___NS__eq, ___NS__escape, ___NS__escapeRegExp, ___NS__every, ___NS__extend, ___NS__extendWith, ___NS__fill, ___NS__filter, ___NS__find, ___NS__findIndex, ___NS__findKey, ___NS__findLast, ___NS__findLastIndex, ___NS__findLastKey, ___NS__first, ___NS__flatMap, ___NS__flatMapDeep, ___NS__flatMapDepth, ___NS__flatten, ___NS__flattenDeep, ___NS__flattenDepth, ___NS__flip, ___NS__floor, ___NS__flow, ___NS__flowRight, ___NS__forEach, ___NS__forEachRight, ___NS__forIn, ___NS__forInRight, ___NS__forOwn, ___NS__forOwnRight, ___NS__fromPairs, ___NS__functions, ___NS__functionsIn, ___NS__get, ___NS__groupBy, ___NS__gt, ___NS__gte, ___NS__has, ___NS__hasIn, ___NS__head, ___NS__identity, ___NS__includes, ___NS__indexOf, ___NS__initial, ___NS__inRange, ___NS__intersection, ___NS__intersectionBy, ___NS__intersectionWith, ___NS__invert, ___NS__invertBy, ___NS__invoke, ___NS__invokeMap, ___NS__isArguments, ___NS__isArray, ___NS__isArrayBuffer, ___NS__isArrayLike, ___NS__isArrayLikeObject, ___NS__isBoolean, ___NS__isBuffer, ___NS__isDate, ___NS__isElement, ___NS__isEmpty, ___NS__isEqual, ___NS__isEqualWith, ___NS__isError, ___NS__isFinite, ___NS__isFunction, ___NS__isInteger, ___NS__isLength, ___NS__isMap, ___NS__isMatch, ___NS__isMatchWith, ___NS__isNaN, ___NS__isNative, ___NS__isNil, ___NS__isNull, ___NS__isNumber, ___NS__isObject, ___NS__isObjectLike, ___NS__isPlainObject, ___NS__isRegExp, ___NS__isSafeInteger, ___NS__isSet, ___NS__isString, ___NS__isSymbol, ___NS__isTypedArray, ___NS__isUndefined, ___NS__isWeakMap, ___NS__isWeakSet, ___NS__iteratee, ___NS__join, ___NS__kebabCase, ___NS__keyBy, ___NS__keys, ___NS__keysIn, ___NS__last, ___NS__lastIndexOf, ___NS__lowerCase, ___NS__lowerFirst, ___NS__lt, ___NS__lte, ___NS__map, ___NS__mapKeys, ___NS__mapValues, ___NS__matches, ___NS__matchesProperty, ___NS__max, ___NS__maxBy, ___NS__mean, ___NS__meanBy, ___NS__memoize, ___NS__merge, ___NS__mergeWith, ___NS__method, ___NS__methodOf, ___NS__min, ___NS__minBy, ___NS__mixin, ___NS__multiply, ___NS__negate, ___NS__noop, ___NS__now, ___NS__nth, ___NS__nthArg, ___NS__omit, ___NS__omitBy, ___NS__once, ___NS__orderBy, ___NS__over, ___NS__overArgs, ___NS__overEvery, ___NS__overSome, ___NS__pad, ___NS__padEnd, ___NS__padStart, ___NS__parseInt, ___NS__partial, ___NS__partialRight, ___NS__partition, ___NS__pick, ___NS__pickBy, ___NS__property, ___NS__propertyOf, ___NS__pull, ___NS__pullAll, ___NS__pullAllBy, ___NS__pullAllWith, ___NS__pullAt, ___NS__random, ___NS__range, ___NS__rangeRight, ___NS__rearg, ___NS__reduce, ___NS__reduceRight, ___NS__reject, ___NS__remove, ___NS__repeat, ___NS__replace, ___NS__rest, ___NS__result, ___NS__reverse, ___NS__round, ___NS__sample, ___NS__sampleSize, ___NS__set, ___NS__setWith, ___NS__shuffle, ___NS__size, ___NS__slice, ___NS__snakeCase, ___NS__some, ___NS__sortBy, ___NS__sortedIndex, ___NS__sortedIndexBy, ___NS__sortedIndexOf, ___NS__sortedLastIndex, ___NS__sortedLastIndexBy, ___NS__sortedLastIndexOf, ___NS__sortedUniq, ___NS__sortedUniqBy, ___NS__split, ___NS__spread, ___NS__startCase, ___NS__startsWith, ___NS__stubArray, ___NS__stubFalse, ___NS__stubObject, ___NS__stubString, ___NS__stubTrue, ___NS__subtract, ___NS__sum, ___NS__sumBy, ___NS__tail, ___NS__take, ___NS__takeRight, ___NS__takeRightWhile, ___NS__takeWhile, ___NS__tap, ___NS__template, ___NS__templateSettings, ___NS__throttle, ___NS__thru, ___NS__times, ___NS__toArray, ___NS__toFinite, ___NS__toInteger, ___NS__toLength, ___NS__toLower, ___NS__toNumber, ___NS__toPairs, ___NS__toPairsIn, ___NS__toPath, ___NS__toPlainObject, ___NS__toSafeInteger, ___NS__toString, ___NS__toUpper, ___NS__transform, ___NS__trim, ___NS__trimEnd, ___NS__trimStart, ___NS__truncate, ___NS__unary, ___NS__unescape, ___NS__union, ___NS__unionBy, ___NS__unionWith, ___NS__uniq, ___NS__uniqBy, ___NS__uniqueId, ___NS__uniqWith, ___NS__unset, ___NS__unzip, ___NS__unzipWith, ___NS__update, ___NS__updateWith, ___NS__upperCase, ___NS__upperFirst, ___NS__values, ___NS__valuesIn, ___NS__without, ___NS__words, ___NS__wrap, ___NS__xor, ___NS__xorBy, ___NS__xorWith, ___NS__zip, ___NS__zipObject, ___NS__zipObjectDeep, ___NS__zipWith } from 'tnp-core/lib-prod';
|
|
26
|
-
|
|
27
|
-
import { TaonRepository } from '../decorators/classes/repository-decorator';
|
|
28
|
-
import { ClassHelpers__NS__asyncHandler, ClassHelpers__NS__ensureClassConfig, ClassHelpers__NS__ensureMethodConfig, ClassHelpers__NS__getClassConfig, ClassHelpers__NS__getClassFnFromObject, ClassHelpers__NS__getControllerConfigs, ClassHelpers__NS__getFullInternalName, ClassHelpers__NS__getMethodsNames, ClassHelpers__NS__getName, ClassHelpers__NS__getOrginalClass, ClassHelpers__NS__getUniqueKey, ClassHelpers__NS__hasParentClassWithName, ClassHelpers__NS__isContextClassObject, ClassHelpers__NS__setName } from '../helpers/class-helpers';
|
|
29
|
-
|
|
30
|
-
import { TaonBaseCustomRepository } from './base-custom-repository';
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
|
|
34
|
-
const INDEX_KEYS_NO_FOR_UPDATE = ['id'];
|
|
35
|
-
|
|
36
|
-
@TaonRepository({ className: 'TaonBaseRepository' })
|
|
37
|
-
export abstract class TaonBaseRepository<
|
|
38
|
-
Entity extends { id?: any },
|
|
39
|
-
> extends TaonBaseCustomRepository {
|
|
40
|
-
private REPOS_CACHE_KEY = Symbol('repository cache inside instance');
|
|
41
|
-
//#region dummy fields
|
|
42
|
-
// static ids:number = 0;
|
|
43
|
-
// id:number = TaonBaseRepository.ids++;
|
|
44
|
-
//#endregion
|
|
45
|
-
|
|
46
|
-
//#region constructor & resolve entity
|
|
47
|
-
abstract entityClassResolveFn: () => any;
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
// Injected through TaonBaseCrudController
|
|
51
|
-
__entityClassResolveFn: () => any,
|
|
52
|
-
) {
|
|
53
|
-
super();
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
this.entityClassResolveFn = __entityClassResolveFn;
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
|
|
59
|
-
//#region db query
|
|
60
|
-
private __dbQuery: MySqlQuerySource;
|
|
61
|
-
|
|
62
|
-
public get dbQuery(): MySqlQuerySource {
|
|
63
|
-
//#region @websqlFunc
|
|
64
|
-
if (!this.__dbQuery) {
|
|
65
|
-
if (!this.ctx) {
|
|
66
|
-
return; // TODO
|
|
67
|
-
throw new Error(
|
|
68
|
-
`[TaonBaseRepository] Context not inited for class ${ClassHelpers__NS__getName(
|
|
69
|
-
this,
|
|
70
|
-
)}`,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
const connection = this.ctx?.connection;
|
|
74
|
-
if (!connection) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`[TaonBaseRepository] Database not inited for context ${this.ctx?.contextName}`,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
this.__dbQuery = new MySqlQuerySource(connection);
|
|
80
|
-
}
|
|
81
|
-
return this.__dbQuery;
|
|
82
|
-
//#endregion
|
|
83
|
-
}
|
|
84
|
-
//#endregion
|
|
85
|
-
|
|
86
|
-
//#region connection
|
|
87
|
-
public get connection(): DataSourceType {
|
|
88
|
-
//#region @websqlFunc
|
|
89
|
-
return this.ctx?.connection;
|
|
90
|
-
//#endregion
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
|
|
94
|
-
//#region repository
|
|
95
|
-
protected get repository(): Repository<Entity> {
|
|
96
|
-
//#region @websqlFunc
|
|
97
|
-
if (this[this.REPOS_CACHE_KEY]) {
|
|
98
|
-
return this[this.REPOS_CACHE_KEY];
|
|
99
|
-
}
|
|
100
|
-
const resolvedRepoClass = this.entityClassResolveFn();
|
|
101
|
-
const resolvedRepoName = ClassHelpers__NS__getName(resolvedRepoClass);
|
|
102
|
-
|
|
103
|
-
const repo = this.ctx.repos.get(resolvedRepoName) as Repository<Entity>;
|
|
104
|
-
|
|
105
|
-
// TODO better recognize what is class in context
|
|
106
|
-
if (!repo) {
|
|
107
|
-
throw `[TaonBaseRepository] Repository for entity "${resolvedRepoName}"
|
|
108
|
-
not found in context "${this.ctx?.contextName}".
|
|
109
|
-
|
|
110
|
-
Is ${resolvedRepoName} a Taon entity class ?
|
|
111
|
-
|
|
112
|
-
OR
|
|
113
|
-
|
|
114
|
-
If ${resolvedRepoName} is a Taon Custom Repository, then use this:
|
|
115
|
-
|
|
116
|
-
...
|
|
117
|
-
${___NS__lowerFirst(resolvedRepoName)} = injectCustomRepository(${resolvedRepoName});
|
|
118
|
-
...
|
|
119
|
-
|
|
120
|
-
`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this[this.REPOS_CACHE_KEY] = repo;
|
|
124
|
-
return this[this.REPOS_CACHE_KEY];
|
|
125
|
-
//#endregion
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* target for repository
|
|
130
|
-
*/
|
|
131
|
-
public get target(): Function {
|
|
132
|
-
//#region @websqlFunc
|
|
133
|
-
return this?.repository?.target as any;
|
|
134
|
-
//#endregion
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* alias to repository
|
|
139
|
-
*/
|
|
140
|
-
protected get repo(): Repository<Entity> {
|
|
141
|
-
//#region @websqlFunc
|
|
142
|
-
return this.repository;
|
|
143
|
-
//#endregion
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public get repositoryExists(): boolean {
|
|
147
|
-
//#region @websqlFunc
|
|
148
|
-
return !!this.repository;
|
|
149
|
-
//#endregion
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
|
|
154
|
-
//#region crud operations / typeorm / has id
|
|
155
|
-
/**
|
|
156
|
-
* Checks if entity has an id.
|
|
157
|
-
* If entity composite compose ids, it will check them all.
|
|
158
|
-
*/
|
|
159
|
-
hasId(entity: Entity): boolean {
|
|
160
|
-
return this.repo.hasId(entity);
|
|
161
|
-
}
|
|
162
|
-
//#endregion
|
|
163
|
-
|
|
164
|
-
//#region crud operations / typeorm / get id
|
|
165
|
-
/**
|
|
166
|
-
* Gets entity mixed id.
|
|
167
|
-
*/
|
|
168
|
-
getId(entity: Entity): any {
|
|
169
|
-
return this.repo.getId(entity);
|
|
170
|
-
}
|
|
171
|
-
//#endregion
|
|
172
|
-
|
|
173
|
-
//#region crud operations / typeorm / create & bulk create
|
|
174
|
-
/**
|
|
175
|
-
Saves a given entity in the database.
|
|
176
|
-
* If entity does not exist in the database then inserts, otherwise updates.
|
|
177
|
-
*/
|
|
178
|
-
async save(
|
|
179
|
-
item: Entity,
|
|
180
|
-
options?: SaveOptions & {
|
|
181
|
-
reload: false;
|
|
182
|
-
},
|
|
183
|
-
): Promise<Entity> {
|
|
184
|
-
//#region @websqlFunc
|
|
185
|
-
// if (!this.repo) {
|
|
186
|
-
// debugger;
|
|
187
|
-
// }
|
|
188
|
-
let model = await this.repo.create(item);
|
|
189
|
-
|
|
190
|
-
model = await this.repo.save(model, options);
|
|
191
|
-
const { id } = model as any;
|
|
192
|
-
|
|
193
|
-
model = await this.repo.findOne({
|
|
194
|
-
where: { id } as any,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return model;
|
|
198
|
-
//#endregion
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* alias to save
|
|
203
|
-
* -> it will actuall create new entity in db
|
|
204
|
-
* in oposite to typeorm create method
|
|
205
|
-
*/
|
|
206
|
-
/**
|
|
207
|
-
* Creates a new entity instance.
|
|
208
|
-
*/
|
|
209
|
-
create(): Entity;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Creates new entities and copies all entity properties from given objects into their new entities.
|
|
213
|
-
* Note that it copies only properties that are present in entity schema.
|
|
214
|
-
*/
|
|
215
|
-
create(entityLikeArray: DeepPartial<Entity>[]): Entity[];
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Creates a new entity instance and copies all entity properties from this object into a new entity.
|
|
219
|
-
* Note that it copies only properties that are present in entity schema.
|
|
220
|
-
*/
|
|
221
|
-
create(entityLike: DeepPartial<Entity>): Entity;
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Creates a new entity instance or instances.
|
|
225
|
-
* Can copy properties from the given object into new entities.
|
|
226
|
-
*/
|
|
227
|
-
create(
|
|
228
|
-
plainEntityLikeOrPlainEntityLikes?:
|
|
229
|
-
| DeepPartial<Entity>
|
|
230
|
-
| DeepPartial<Entity>[],
|
|
231
|
-
): Entity | Entity[] {
|
|
232
|
-
return this.repo.create(plainEntityLikeOrPlainEntityLikes as any);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
async bulkSave(
|
|
236
|
-
items: Entity[],
|
|
237
|
-
options?: SaveOptions & {
|
|
238
|
-
reload: false;
|
|
239
|
-
},
|
|
240
|
-
): Promise<Entity[]> {
|
|
241
|
-
//#region @websqlFunc
|
|
242
|
-
const models = [];
|
|
243
|
-
for (let index = 0; index < items.length; index++) {
|
|
244
|
-
const item = items[index];
|
|
245
|
-
// TODO FIX THIS / REFACTOR
|
|
246
|
-
const model = await this.save(item, options);
|
|
247
|
-
models.push(model);
|
|
248
|
-
}
|
|
249
|
-
return models;
|
|
250
|
-
//#endregion
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* @deprecated use bulkSave instead
|
|
255
|
-
*/
|
|
256
|
-
async bulkCreate(
|
|
257
|
-
items: Entity[],
|
|
258
|
-
options?: SaveOptions & {
|
|
259
|
-
reload: false;
|
|
260
|
-
},
|
|
261
|
-
): Promise<Entity[]> {
|
|
262
|
-
return this.bulkSave(items, options);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
//#region old typeorm version
|
|
266
|
-
/**
|
|
267
|
-
* Saves all given entities in the database.
|
|
268
|
-
* If entities do not exist in the database then inserts, otherwise updates.
|
|
269
|
-
*/
|
|
270
|
-
// save<T extends DeepPartial<Entity>>(
|
|
271
|
-
// entities: T[],
|
|
272
|
-
// options: SaveOptions & {
|
|
273
|
-
// reload: false;
|
|
274
|
-
// },
|
|
275
|
-
// ): Promise<T[]>;
|
|
276
|
-
// /**
|
|
277
|
-
// * Saves all given entities in the database.
|
|
278
|
-
// * If entities do not exist in the database then inserts, otherwise updates.
|
|
279
|
-
// */
|
|
280
|
-
// save<T extends DeepPartial<Entity>>(
|
|
281
|
-
// entities: T[],
|
|
282
|
-
// options?: SaveOptions,
|
|
283
|
-
// ): Promise<(T & Entity)[]>;
|
|
284
|
-
// /**
|
|
285
|
-
// * Saves a given entity in the database.
|
|
286
|
-
// * If entity does not exist in the database then inserts, otherwise updates.
|
|
287
|
-
// */
|
|
288
|
-
// save<T extends DeepPartial<Entity>>(
|
|
289
|
-
// entity: T,
|
|
290
|
-
// options: SaveOptions & {
|
|
291
|
-
// reload: false;
|
|
292
|
-
// },
|
|
293
|
-
// ): Promise<T>;
|
|
294
|
-
// /**
|
|
295
|
-
// * Saves a given entity in the database.
|
|
296
|
-
// * If entity does not exist in the database then inserts, otherwise updates.
|
|
297
|
-
// */
|
|
298
|
-
// save<T extends DeepPartial<Entity>>(
|
|
299
|
-
// entity: T,
|
|
300
|
-
// options?: SaveOptions,
|
|
301
|
-
// ): Promise<T & Entity> {
|
|
302
|
-
// return this.repo.save(entity, options);
|
|
303
|
-
// }
|
|
304
|
-
//#endregion
|
|
305
|
-
|
|
306
|
-
//#endregion
|
|
307
|
-
|
|
308
|
-
//#region crud operations / typeorm / merge
|
|
309
|
-
/**
|
|
310
|
-
* Merges multiple entities (or entity-like objects) into a given entity.
|
|
311
|
-
*/
|
|
312
|
-
merge(mergeIntoEntity: Entity, ...entityLikes: Entity[]): Entity {
|
|
313
|
-
return this.repo.merge(mergeIntoEntity, ...entityLikes);
|
|
314
|
-
}
|
|
315
|
-
//#endregion
|
|
316
|
-
|
|
317
|
-
//#region crud operations / typeorm / preload
|
|
318
|
-
/**
|
|
319
|
-
* Creates a new entity from the given plain javascript object. If entity already exist in the database, then
|
|
320
|
-
* it loads it (and everything related to it), replaces all values with the new ones from the given object
|
|
321
|
-
* and returns this new entity. This new entity is actually a loaded from the db entity with all properties
|
|
322
|
-
* replaced from the new object.
|
|
323
|
-
*
|
|
324
|
-
* Note that given entity-like object must have an entity id / primary key to find entity by.
|
|
325
|
-
* Returns undefined if entity with given id was not found.
|
|
326
|
-
*/
|
|
327
|
-
preload(entityLike: Entity): Promise<Entity | undefined> {
|
|
328
|
-
return this.repo.preload(entityLike);
|
|
329
|
-
}
|
|
330
|
-
//#endregion
|
|
331
|
-
|
|
332
|
-
//#region crud operations / typeorm / remove (delete) & bulk remove (delete)
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Removes a given entities from the database.
|
|
336
|
-
*/
|
|
337
|
-
async remove(idOrEntity: number | string | Entity): Promise<Entity> {
|
|
338
|
-
//#region @websqlFunc
|
|
339
|
-
if (___NS__isObject(idOrEntity)) {
|
|
340
|
-
idOrEntity = (idOrEntity as Entity).id;
|
|
341
|
-
}
|
|
342
|
-
const deletedEntity = await this.repo.findOne({
|
|
343
|
-
where: { id: idOrEntity } as any,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
if (!deletedEntity) {
|
|
347
|
-
Helpers__NS__warn(
|
|
348
|
-
`[TaonBaseRepository] Entity "${ClassHelpers__NS__getName(
|
|
349
|
-
this.repo.target,
|
|
350
|
-
)}" ` + `with id ${idOrEntity} not found, cannot remove`,
|
|
351
|
-
);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const idCopy = deletedEntity.id;
|
|
356
|
-
await this.repo.remove(deletedEntity);
|
|
357
|
-
|
|
358
|
-
deletedEntity.id = idCopy;
|
|
359
|
-
return deletedEntity;
|
|
360
|
-
//#endregion
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* alias to remove
|
|
365
|
-
*/
|
|
366
|
-
async delete(idOrEntity: number | string | Partial<Entity>): Promise<Entity> {
|
|
367
|
-
return this.remove(idOrEntity as any);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* alias to removeById
|
|
372
|
-
*/
|
|
373
|
-
async deleteById(id: number | string): Promise<Entity> {
|
|
374
|
-
return this.remove(id);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
async bulkRemove(
|
|
378
|
-
idsOrEntities: (number | string | Entity)[],
|
|
379
|
-
): Promise<Entity[]> {
|
|
380
|
-
//#region @websqlFunc
|
|
381
|
-
idsOrEntities = idsOrEntities.map(id => {
|
|
382
|
-
return ___NS__isObject(id) ? (id as Entity).id : id;
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
const models = [];
|
|
386
|
-
for (let index = 0; index < idsOrEntities.length; index++) {
|
|
387
|
-
const id = idsOrEntities[index];
|
|
388
|
-
const model = await this.remove(id);
|
|
389
|
-
models.push(model);
|
|
390
|
-
}
|
|
391
|
-
return models;
|
|
392
|
-
//#endregion
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
async bulkDelete(ids: (number | string | Entity)[]): Promise<Entity[]> {
|
|
396
|
-
return this.bulkRemove(ids);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
//#region old typeorm version
|
|
400
|
-
// /**
|
|
401
|
-
// * Deletes entities by a given criteria.
|
|
402
|
-
// * Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
403
|
-
// * Executes fast and efficient DELETE query.
|
|
404
|
-
// * Does not check if entity exist in the database.
|
|
405
|
-
// */
|
|
406
|
-
// delete(
|
|
407
|
-
// criteria:
|
|
408
|
-
// | string
|
|
409
|
-
// | string[]
|
|
410
|
-
// | number
|
|
411
|
-
// | number[]
|
|
412
|
-
// | Date
|
|
413
|
-
// | Date[]
|
|
414
|
-
// | ObjectID
|
|
415
|
-
// | ObjectID[]
|
|
416
|
-
// | FindOptionsWhere<Entity>,
|
|
417
|
-
// ): Promise<DeleteResult> {
|
|
418
|
-
// return this.repo.delete(criteria);
|
|
419
|
-
// }
|
|
420
|
-
|
|
421
|
-
// /**
|
|
422
|
-
// * Removes a given entities from the database.
|
|
423
|
-
// */
|
|
424
|
-
// remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>;
|
|
425
|
-
// /**
|
|
426
|
-
// * Removes a given entity from the database.
|
|
427
|
-
// */
|
|
428
|
-
// remove(entity: Entity, options?: RemoveOptions): Promise<Entity> {
|
|
429
|
-
// return this.repo.remove(entity, options);
|
|
430
|
-
// }
|
|
431
|
-
|
|
432
|
-
//#endregion
|
|
433
|
-
//#endregion
|
|
434
|
-
|
|
435
|
-
//#region crud operations / typeorm / soft remove
|
|
436
|
-
/**
|
|
437
|
-
* Records the delete date of all given entities.
|
|
438
|
-
*/
|
|
439
|
-
softRemove<T extends Entity>(
|
|
440
|
-
entities: T[],
|
|
441
|
-
options: SaveOptions & {
|
|
442
|
-
reload: false;
|
|
443
|
-
},
|
|
444
|
-
): Promise<T[]>;
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Records the delete date of all given entities.
|
|
448
|
-
*/
|
|
449
|
-
softRemove<T extends Entity>(
|
|
450
|
-
entities: T[],
|
|
451
|
-
options?: SaveOptions,
|
|
452
|
-
): Promise<(T & Entity)[]>;
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Records the delete date of a given entity.
|
|
456
|
-
*/
|
|
457
|
-
softRemove<T extends Entity>(
|
|
458
|
-
entity: T,
|
|
459
|
-
options: SaveOptions & {
|
|
460
|
-
reload: false;
|
|
461
|
-
},
|
|
462
|
-
): Promise<T>;
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Records the delete date of a given entity.
|
|
466
|
-
*/
|
|
467
|
-
softRemove<T extends Entity>(
|
|
468
|
-
entity: T,
|
|
469
|
-
options?: SaveOptions,
|
|
470
|
-
): Promise<T & Entity> {
|
|
471
|
-
return this.repo.softRemove(entity, options);
|
|
472
|
-
}
|
|
473
|
-
//#endregion
|
|
474
|
-
|
|
475
|
-
//#region crud operations / typeorm / recover
|
|
476
|
-
/**
|
|
477
|
-
* Recovers all given entities in the database.
|
|
478
|
-
*/
|
|
479
|
-
recover<T extends Entity>(
|
|
480
|
-
entities: T[],
|
|
481
|
-
options: SaveOptions & {
|
|
482
|
-
reload: false;
|
|
483
|
-
},
|
|
484
|
-
): Promise<T[]>;
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Recovers all given entities in the database.
|
|
488
|
-
*/
|
|
489
|
-
recover<T extends Entity>(
|
|
490
|
-
entities: T[],
|
|
491
|
-
options?: SaveOptions,
|
|
492
|
-
): Promise<(T & Entity)[]>;
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Recovers a given entity in the database.
|
|
496
|
-
*/
|
|
497
|
-
recover<T extends Entity>(
|
|
498
|
-
entity: T,
|
|
499
|
-
options: SaveOptions & {
|
|
500
|
-
reload: false;
|
|
501
|
-
},
|
|
502
|
-
): Promise<T>;
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Recovers a given entity in the database.
|
|
506
|
-
*/
|
|
507
|
-
recover<T extends Entity>(
|
|
508
|
-
entity: T,
|
|
509
|
-
options?: SaveOptions,
|
|
510
|
-
): Promise<T & Entity> {
|
|
511
|
-
return this.repo.recover(entity, options);
|
|
512
|
-
}
|
|
513
|
-
//#endregion
|
|
514
|
-
|
|
515
|
-
//#region crud operations / typeorm / insert
|
|
516
|
-
/**
|
|
517
|
-
* Inserts a given entity into the database.
|
|
518
|
-
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
519
|
-
* Executes fast and efficient INSERT query.
|
|
520
|
-
* Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
|
|
521
|
-
*/
|
|
522
|
-
insert(
|
|
523
|
-
entity: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[],
|
|
524
|
-
): Promise<InsertResult> {
|
|
525
|
-
// debugger;
|
|
526
|
-
return this.repo.insert(entity);
|
|
527
|
-
}
|
|
528
|
-
//#endregion
|
|
529
|
-
|
|
530
|
-
//#region crud operations / typeorm / update & build update
|
|
531
|
-
async update(item: Entity) {
|
|
532
|
-
//#region @websqlFunc
|
|
533
|
-
const { id } = item as any;
|
|
534
|
-
return await this.updateById<Entity>(id, item);
|
|
535
|
-
//#endregion
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
private allowedTypesToUpdate = ['simple-json', 'simple-array', 'json'];
|
|
539
|
-
|
|
540
|
-
async updateById<ENTITY = Entity>(
|
|
541
|
-
id: number | string,
|
|
542
|
-
item: Entity,
|
|
543
|
-
): Promise<ENTITY> {
|
|
544
|
-
//#region @websqlFunc
|
|
545
|
-
const allowedPropsToUpdate = [];
|
|
546
|
-
for (const key in item) {
|
|
547
|
-
const metadataColumn = this.repo.metadata.ownColumns.find(
|
|
548
|
-
c => c.propertyName === key,
|
|
549
|
-
);
|
|
550
|
-
if (
|
|
551
|
-
___NS__isObject(item) &&
|
|
552
|
-
item.hasOwnProperty(key) &&
|
|
553
|
-
(typeof item[key] !== 'object' ||
|
|
554
|
-
this.allowedTypesToUpdate.includes(metadataColumn?.type as any)) &&
|
|
555
|
-
!___NS__isUndefined(metadataColumn)
|
|
556
|
-
) {
|
|
557
|
-
allowedPropsToUpdate.push(key);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
for (let i = 0; i < allowedPropsToUpdate.length; i++) {
|
|
562
|
-
const key: string = allowedPropsToUpdate[i];
|
|
563
|
-
if (!INDEX_KEYS_NO_FOR_UPDATE.includes(key.toLowerCase())) {
|
|
564
|
-
// const raw = ___NS__isBoolean(item[key]) || ___NS__isNumber(item[key]) || ___NS__isNull(item[key]); // TODO does this make any sense ?
|
|
565
|
-
const toSet = item[key];
|
|
566
|
-
// const tableName = tableNameFrom(this.entity as any);
|
|
567
|
-
|
|
568
|
-
await this.repo.update(
|
|
569
|
-
{
|
|
570
|
-
id,
|
|
571
|
-
} as any,
|
|
572
|
-
{
|
|
573
|
-
[key]: toSet,
|
|
574
|
-
} as any,
|
|
575
|
-
);
|
|
576
|
-
// await this.repo.query(
|
|
577
|
-
// `UPDATE '${tableName}' as ${table}
|
|
578
|
-
// SET ${key}=${toSet}
|
|
579
|
-
// WHERE ${table}.id='${id}'
|
|
580
|
-
// `);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
let model = await this.repo.findOne({
|
|
584
|
-
where: { id } as any,
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
return model as any as ENTITY;
|
|
588
|
-
//#endregion
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
async bulkUpdate(items: Entity[]) {
|
|
592
|
-
//#region @websqlFunc
|
|
593
|
-
const models = [];
|
|
594
|
-
for (let index = 0; index < items.length; index++) {
|
|
595
|
-
const item = items[index];
|
|
596
|
-
const { id } = item as any; // TOOD
|
|
597
|
-
const model = await this.updateById(id, item);
|
|
598
|
-
models.push(model);
|
|
599
|
-
}
|
|
600
|
-
return { models };
|
|
601
|
-
//#endregion
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
//#region tpeorm update version
|
|
605
|
-
// this version suck and will not return update entity
|
|
606
|
-
// /**
|
|
607
|
-
// * Updates entity partially. Entity can be found by a given conditions.
|
|
608
|
-
// * Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
609
|
-
// * Executes fast and efficient UPDATE query.
|
|
610
|
-
// * Does not check if entity exist in the database.
|
|
611
|
-
// */
|
|
612
|
-
// update(
|
|
613
|
-
// criteria:
|
|
614
|
-
// | string
|
|
615
|
-
// | string[]
|
|
616
|
-
// | number
|
|
617
|
-
// | number[]
|
|
618
|
-
// | Date
|
|
619
|
-
// | Date[]
|
|
620
|
-
// | ObjectID
|
|
621
|
-
// | ObjectID[]
|
|
622
|
-
// | FindOptionsWhere<Entity>,
|
|
623
|
-
// partialEntity: QueryDeepPartialEntity<Entity>,
|
|
624
|
-
// ): Promise<UpdateResult> {
|
|
625
|
-
// return this.repo.update(criteria, partialEntity);
|
|
626
|
-
// }
|
|
627
|
-
//#endregion
|
|
628
|
-
|
|
629
|
-
//#endregion
|
|
630
|
-
|
|
631
|
-
//#region crud operations / typeorm / upsert
|
|
632
|
-
/**
|
|
633
|
-
* Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
|
|
634
|
-
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
635
|
-
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
636
|
-
*/
|
|
637
|
-
upsert(
|
|
638
|
-
entityOrEntities:
|
|
639
|
-
| QueryDeepPartialEntity<Entity>
|
|
640
|
-
| QueryDeepPartialEntity<Entity>[],
|
|
641
|
-
conflictPathsOrOptions: string[] | UpsertOptions<Entity>,
|
|
642
|
-
): Promise<InsertResult> {
|
|
643
|
-
return this.repo.upsert(entityOrEntities, conflictPathsOrOptions);
|
|
644
|
-
}
|
|
645
|
-
//#endregion
|
|
646
|
-
|
|
647
|
-
//#region crud operations / typeorm / soft delete
|
|
648
|
-
/**
|
|
649
|
-
* Records the delete date of entities by a given criteria.
|
|
650
|
-
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
651
|
-
* Executes fast and efficient SOFT-DELETE query.
|
|
652
|
-
* Does not check if entity exist in the database.
|
|
653
|
-
*/
|
|
654
|
-
softDelete(
|
|
655
|
-
criteria:
|
|
656
|
-
| string
|
|
657
|
-
| string[]
|
|
658
|
-
| number
|
|
659
|
-
| number[]
|
|
660
|
-
| Date
|
|
661
|
-
| Date[]
|
|
662
|
-
// | ObjectID
|
|
663
|
-
// | ObjectID[]
|
|
664
|
-
| FindOptionsWhere<Entity>,
|
|
665
|
-
): Promise<UpdateResult> {
|
|
666
|
-
return this.repo.softDelete(criteria);
|
|
667
|
-
}
|
|
668
|
-
//#endregion
|
|
669
|
-
|
|
670
|
-
//#region crud operations / typeorm / restore
|
|
671
|
-
/**
|
|
672
|
-
* Restores entities by a given criteria.
|
|
673
|
-
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
674
|
-
* Executes fast and efficient SOFT-DELETE query.
|
|
675
|
-
* Does not check if entity exist in the database.
|
|
676
|
-
*/
|
|
677
|
-
restore(
|
|
678
|
-
criteria:
|
|
679
|
-
| string
|
|
680
|
-
| string[]
|
|
681
|
-
| number
|
|
682
|
-
| number[]
|
|
683
|
-
| Date
|
|
684
|
-
| Date[]
|
|
685
|
-
// | ObjectID
|
|
686
|
-
// | ObjectID[]
|
|
687
|
-
| FindOptionsWhere<Entity>,
|
|
688
|
-
): Promise<UpdateResult> {
|
|
689
|
-
return this.repo.restore(criteria);
|
|
690
|
-
}
|
|
691
|
-
//#endregion
|
|
692
|
-
|
|
693
|
-
//#region crud operations / typeorm / count
|
|
694
|
-
/**
|
|
695
|
-
* Counts entities that match given options.
|
|
696
|
-
* Useful for pagination.
|
|
697
|
-
*/
|
|
698
|
-
count(options?: FindManyOptions<Entity>): Promise<number> {
|
|
699
|
-
return this.repo.count(options);
|
|
700
|
-
}
|
|
701
|
-
//#endregion
|
|
702
|
-
|
|
703
|
-
//#region crud operations / typeorm / count by
|
|
704
|
-
/**
|
|
705
|
-
* Counts entities that match given conditions.
|
|
706
|
-
* Useful for pagination.
|
|
707
|
-
*/
|
|
708
|
-
countBy(
|
|
709
|
-
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
|
|
710
|
-
): Promise<number> {
|
|
711
|
-
return this.repo.countBy(where);
|
|
712
|
-
}
|
|
713
|
-
//#endregion
|
|
714
|
-
|
|
715
|
-
//#region crud operations / typeorm / find
|
|
716
|
-
/**
|
|
717
|
-
* Finds entities that match given find options.
|
|
718
|
-
*/
|
|
719
|
-
find(options?: FindManyOptions<Entity>): Promise<Entity[]> {
|
|
720
|
-
return this.repo.find(options);
|
|
721
|
-
}
|
|
722
|
-
//#endregion
|
|
723
|
-
|
|
724
|
-
//#region crud operations / typeorm / find by
|
|
725
|
-
/**
|
|
726
|
-
* Finds entities that match given find options.
|
|
727
|
-
*/
|
|
728
|
-
findBy(
|
|
729
|
-
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
|
|
730
|
-
): Promise<Entity[]> {
|
|
731
|
-
return this.repo.findBy(where);
|
|
732
|
-
}
|
|
733
|
-
//#endregion
|
|
734
|
-
|
|
735
|
-
//#region crud operations / typeorm / find and count
|
|
736
|
-
// async findAndCount(options: { take: number; skip: number }) {
|
|
737
|
-
// const { take, skip } = options;
|
|
738
|
-
// const [result, total] = await this.repo.findAndCount({
|
|
739
|
-
// // where: { name: Like('%' + keyword + '%') },
|
|
740
|
-
// // order: { name: "DESC" },
|
|
741
|
-
// take: take,
|
|
742
|
-
// skip: skip,
|
|
743
|
-
// });
|
|
744
|
-
// return { result, total };
|
|
745
|
-
|
|
746
|
-
// }
|
|
747
|
-
//
|
|
748
|
-
/**
|
|
749
|
-
* Finds entities that match given find options.
|
|
750
|
-
* Also counts all entities that match given conditions,
|
|
751
|
-
* but ignores pagination settings (from and take options).
|
|
752
|
-
*/
|
|
753
|
-
findAndCount(options?: FindManyOptions<Entity>): Promise<[Entity[], number]> {
|
|
754
|
-
return this.repo.findAndCount(options);
|
|
755
|
-
}
|
|
756
|
-
//#endregion
|
|
757
|
-
|
|
758
|
-
//#region crud operations / typeorm / find and count by
|
|
759
|
-
/**
|
|
760
|
-
* Finds entities that match given WHERE conditions.
|
|
761
|
-
* Also counts all entities that match given conditions,
|
|
762
|
-
* but ignores pagination settings (from and take options).
|
|
763
|
-
*/
|
|
764
|
-
findAndCountBy(
|
|
765
|
-
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
|
|
766
|
-
): Promise<[Entity[], number]> {
|
|
767
|
-
return this.repo.findAndCountBy(where);
|
|
768
|
-
}
|
|
769
|
-
//#endregion
|
|
770
|
-
|
|
771
|
-
//#region crud operations / typeorm / find by ids
|
|
772
|
-
/**
|
|
773
|
-
* Finds entities with ids.
|
|
774
|
-
* Optionally find options or conditions can be applied.
|
|
775
|
-
*
|
|
776
|
-
* @deprecated use `findBy` method instead in conjunction with `In` operator, for example:
|
|
777
|
-
*
|
|
778
|
-
* .findBy({
|
|
779
|
-
* id: In([1, 2, 3])
|
|
780
|
-
* })
|
|
781
|
-
*/
|
|
782
|
-
findByIds(ids: any[]): Promise<Entity[]> {
|
|
783
|
-
return this.repo.findByIds(ids);
|
|
784
|
-
}
|
|
785
|
-
//#endregion
|
|
786
|
-
|
|
787
|
-
//#region crud operations / typeorm / find one
|
|
788
|
-
/**
|
|
789
|
-
* Finds first entity by a given find options.
|
|
790
|
-
* If entity was not found in the database - returns null.
|
|
791
|
-
*/
|
|
792
|
-
findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {
|
|
793
|
-
return this.repo.findOne(options);
|
|
794
|
-
}
|
|
795
|
-
//#endregion
|
|
796
|
-
|
|
797
|
-
//#region crud operations / typeorm / find one by
|
|
798
|
-
/**
|
|
799
|
-
* Finds first entity that matches given where condition.
|
|
800
|
-
* If entity was not found in the database - returns null.
|
|
801
|
-
*/
|
|
802
|
-
findOneBy(
|
|
803
|
-
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
|
|
804
|
-
): Promise<Entity | null> {
|
|
805
|
-
return this.repo.findOneBy(where);
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
|
|
809
|
-
//#region crud operations / typeorm / find one or fail
|
|
810
|
-
/**
|
|
811
|
-
* Finds first entity that matches given id.
|
|
812
|
-
* If entity was not found in the database - returns null.
|
|
813
|
-
*
|
|
814
|
-
* @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:
|
|
815
|
-
*
|
|
816
|
-
* .findOneBy({
|
|
817
|
-
* id: 1 // where "id" is your primary column name
|
|
818
|
-
* })
|
|
819
|
-
*/
|
|
820
|
-
findOneById(
|
|
821
|
-
id: number | string | Date,
|
|
822
|
-
// | ObjectID
|
|
823
|
-
): Promise<Entity | null> {
|
|
824
|
-
return this.repo.findOneById(id);
|
|
825
|
-
}
|
|
826
|
-
//#endregion
|
|
827
|
-
|
|
828
|
-
//#region crud operations / typeorm / find one or fail
|
|
829
|
-
/**
|
|
830
|
-
* Finds first entity by a given find options.
|
|
831
|
-
* If entity was not found in the database - rejects with error.
|
|
832
|
-
*/
|
|
833
|
-
findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {
|
|
834
|
-
return this.repo.findOneOrFail(options);
|
|
835
|
-
}
|
|
836
|
-
//#endregion
|
|
837
|
-
|
|
838
|
-
//#region crud operations / typeorm / find one by or fail
|
|
839
|
-
/**
|
|
840
|
-
* Finds first entity that matches given where condition.
|
|
841
|
-
* If entity was not found in the database - rejects with error.
|
|
842
|
-
*/
|
|
843
|
-
findOneByOrFail(
|
|
844
|
-
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
|
|
845
|
-
): Promise<Entity> {
|
|
846
|
-
return this.repo.findOneByOrFail(where);
|
|
847
|
-
}
|
|
848
|
-
//#endregion
|
|
849
|
-
|
|
850
|
-
//#region crud operations / typeorm / query
|
|
851
|
-
/**
|
|
852
|
-
* Executes a raw SQL query and returns a raw database results.
|
|
853
|
-
* Raw query execution is supported only by relational databases (MongoDB is not supported).
|
|
854
|
-
*/
|
|
855
|
-
query(query: string, parameters?: any[]): Promise<any> {
|
|
856
|
-
return this.repo.query(query, parameters);
|
|
857
|
-
}
|
|
858
|
-
//#endregion
|
|
859
|
-
|
|
860
|
-
//#region crud operations / typeorm / query
|
|
861
|
-
/**
|
|
862
|
-
* Executes a raw SQL query and returns a raw database results.
|
|
863
|
-
* Raw query execution is supported only by relational databases (MongoDB is not supported).
|
|
864
|
-
*/
|
|
865
|
-
createQueryBuilder(
|
|
866
|
-
alias?: string,
|
|
867
|
-
queryRunner?: QueryRunner,
|
|
868
|
-
): SelectQueryBuilder<Entity> {
|
|
869
|
-
return this.repo.createQueryBuilder(alias, queryRunner);
|
|
870
|
-
}
|
|
871
|
-
//#endregion
|
|
872
|
-
|
|
873
|
-
//#region crud operations / typeorm / clear
|
|
874
|
-
/**
|
|
875
|
-
* Clears all the data from the given table/collection (truncates/drops it).
|
|
876
|
-
*
|
|
877
|
-
* Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
|
|
878
|
-
* @see https://stackoverflow.com/a/5972738/925151
|
|
879
|
-
*/
|
|
880
|
-
clear(): Promise<void> {
|
|
881
|
-
return this.repo.clear();
|
|
882
|
-
}
|
|
883
|
-
//#endregion
|
|
884
|
-
|
|
885
|
-
//#region crud operations / typeorm / increment
|
|
886
|
-
/**
|
|
887
|
-
* Increments some column by provided value of the entities matched given conditions.
|
|
888
|
-
*/
|
|
889
|
-
increment(
|
|
890
|
-
conditions: FindOptionsWhere<Entity>,
|
|
891
|
-
propertyPath: string,
|
|
892
|
-
value: number | string,
|
|
893
|
-
): Promise<UpdateResult> {
|
|
894
|
-
return this.repo.increment(conditions, propertyPath, value);
|
|
895
|
-
}
|
|
896
|
-
//#endregion
|
|
897
|
-
|
|
898
|
-
//#region crud operations / typeorm / decrement
|
|
899
|
-
/**
|
|
900
|
-
* Decrements some column by provided value of the entities matched given conditions.
|
|
901
|
-
*/
|
|
902
|
-
decrement(
|
|
903
|
-
conditions: FindOptionsWhere<Entity>,
|
|
904
|
-
propertyPath: string,
|
|
905
|
-
value: number | string,
|
|
906
|
-
): Promise<UpdateResult> {
|
|
907
|
-
return this.repo.decrement(conditions, propertyPath, value);
|
|
908
|
-
}
|
|
909
|
-
//#endregion
|
|
910
|
-
|
|
911
|
-
//#region crud operations / get all
|
|
912
|
-
/**
|
|
913
|
-
* @deprecated use findAndCount instead
|
|
914
|
-
*/
|
|
915
|
-
async getAll() {
|
|
916
|
-
//#region @websqlFunc
|
|
917
|
-
// console.log('repo', this.__repository);
|
|
918
|
-
// console.log(
|
|
919
|
-
// `repo taget name "${ClassHelpers__NS__getName(this.__repository.target)}"`,
|
|
920
|
-
// );
|
|
921
|
-
// debugger;
|
|
922
|
-
const totalCount = await this.repo.count();
|
|
923
|
-
const models = await this.repo.find();
|
|
924
|
-
// console.log('models', models);
|
|
925
|
-
// console.log('totalCount', totalCount);
|
|
926
|
-
return { models, totalCount };
|
|
927
|
-
//#endregion
|
|
928
|
-
}
|
|
929
|
-
//#endregion
|
|
930
|
-
|
|
931
|
-
//#region crud operations / get by id
|
|
932
|
-
async getBy(id: number | string): Promise<Entity> {
|
|
933
|
-
//#region @websqlFunc
|
|
934
|
-
const model = await await this.repo.findOne({
|
|
935
|
-
where: { id } as any,
|
|
936
|
-
});
|
|
937
|
-
|
|
938
|
-
return model;
|
|
939
|
-
//#endregion
|
|
940
|
-
}
|
|
941
|
-
//#endregion
|
|
942
|
-
}
|