typescript-class-helpers 21.0.63 → 21.0.65
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/VERIFIED-BUILD-DATA.jsonc +3 -3
- package/browser/package.json +1 -1
- package/browser-prod/fesm2022/typescript-class-helpers-browser-prod.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/full-dts/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib-esm/lib/build-info._auto-generated_.js +1 -1
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/typescript-class-helpers.js.map +1 -1
- package/package.json +1 -1
- package/ts-source/browser-code/build-info._auto-generated_.ts +13 -0
- package/ts-source/browser-code/index._auto-generated_.ts +7 -0
- package/ts-source/browser-code/index.scss +6 -0
- package/ts-source/browser-code/index.ts +8 -0
- package/ts-source/browser-code/lib-info.md +8 -0
- package/ts-source/browser-code/migrations/migrations-info.md +6 -0
- package/ts-source/browser-code/typescript-class-helpers.ts +155 -0
- package/ts-source/browser-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
- package/ts-source/browser-code-prod/build-info._auto-generated_.ts +13 -0
- package/ts-source/browser-code-prod/index._auto-generated_.split-namespaces.json +4 -0
- package/ts-source/browser-code-prod/index._auto-generated_.ts +7 -0
- package/ts-source/browser-code-prod/index.scss +6 -0
- package/ts-source/browser-code-prod/index.split-namespaces.json +4 -0
- package/ts-source/browser-code-prod/index.ts +8 -0
- package/ts-source/browser-code-prod/lib-info.md +8 -0
- package/ts-source/browser-code-prod/migrations/migrations-info.md +6 -0
- package/ts-source/browser-code-prod/typescript-class-helpers.split-namespaces.json +26 -0
- package/ts-source/browser-code-prod/typescript-class-helpers.ts +153 -0
- package/ts-source/websql-code/build-info._auto-generated_.ts +13 -0
- package/ts-source/websql-code/index._auto-generated_.ts +7 -0
- package/ts-source/websql-code/index.scss +6 -0
- package/ts-source/websql-code/index.ts +8 -0
- package/ts-source/websql-code/lib-info.md +8 -0
- package/ts-source/websql-code/migrations/migrations-info.md +6 -0
- package/ts-source/websql-code/typescript-class-helpers.ts +155 -0
- package/ts-source/websql-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
- package/ts-source/websql-code-prod/build-info._auto-generated_.ts +13 -0
- package/ts-source/websql-code-prod/index._auto-generated_.split-namespaces.json +4 -0
- package/ts-source/websql-code-prod/index._auto-generated_.ts +7 -0
- package/ts-source/websql-code-prod/index.scss +6 -0
- package/ts-source/websql-code-prod/index.split-namespaces.json +4 -0
- package/ts-source/websql-code-prod/index.ts +8 -0
- package/ts-source/websql-code-prod/lib-info.md +8 -0
- package/ts-source/websql-code-prod/migrations/migrations-info.md +6 -0
- package/ts-source/websql-code-prod/typescript-class-helpers.split-namespaces.json +26 -0
- package/ts-source/websql-code-prod/typescript-class-helpers.ts +153 -0
- package/websql/package.json +1 -1
- package/websql-prod/fesm2022/typescript-class-helpers-websql-prod.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
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__isLeafObject, ___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, CoreModels__NS__BaseProjectType, CoreModels__NS__BaseProjectTypeArr, CoreModels__NS__BuildType, CoreModels__NS__BuildTypeArr, CoreModels__NS__buildTypeToWatcherFn, CoreModels__NS__BuildWatcherErrorType, CoreModels__NS__BuildWatcherType, CoreModels__NS__BuildWatcherTypeArr, CoreModels__NS__CfontAlign, CoreModels__NS__CfontStyle, CoreModels__NS__ClassNameStaticProperty, CoreModels__NS__ContentType, CoreModels__NS__ContentTypeKeys, CoreModels__NS__CoreLibCategory, CoreModels__NS__CutableFileExt, CoreModels__NS__DatabaseType, CoreModels__NS__DeepPartial, CoreModels__NS__FileEvent, CoreModels__NS__FileExtension, CoreModels__NS__FirstParamsFrom, CoreModels__NS__FrameworkVersion, CoreModels__NS__GitConnection, CoreModels__NS__GitConnectionArr, CoreModels__NS__GlobalDependencies, CoreModels__NS__hasExitCleaningFunction, CoreModels__NS__HttpCode, CoreModels__NS__HttpMethod, CoreModels__NS__HttpMethodArr, CoreModels__NS__ImageFileExtension, CoreModels__NS__ImageFileExtensionArr, CoreModels__NS__InstalationType, CoreModels__NS__InstalationTypeArr, CoreModels__NS__LibType, CoreModels__NS__localhostDomain, CoreModels__NS__localhostIp127, CoreModels__NS__ManifestIcon, CoreModels__NS__MediaType, CoreModels__NS__MediaTypeAllArr, CoreModels__NS__mimeTypes, CoreModels__NS__NewFactoryType, CoreModels__NS__NpmInstallOptions, CoreModels__NS__NpmPublishOptions, CoreModels__NS__NpmSpecialVersions, CoreModels__NS__OrignalClassKey, CoreModels__NS__OutFolder, CoreModels__NS__Package, CoreModels__NS__ParamType, CoreModels__NS__parentLocation, CoreModels__NS__pathToChildren, CoreModels__NS__Position, CoreModels__NS__PreReleaseVersionTag, CoreModels__NS__PROGRESS_DATA_TYPE, CoreModels__NS__PUSHTYPE, CoreModels__NS__PwaManifest, CoreModels__NS__ReleaseVersionType, CoreModels__NS__ReleaseVersionTypeEnum, CoreModels__NS__RunOptions, CoreModels__NS__Size, CoreModels__NS__SPECIAL_APP_READY_MESSAGE, CoreModels__NS__SPECIAL_WORKER_READY_MESSAGE, CoreModels__NS__StatusCode401, CoreModels__NS__tagForTaskName, CoreModels__NS__TaonHttpErrorCustomProp, CoreModels__NS__TsUsage, CoreModels__NS__UIFramework, CoreModels__NS__ValueOf, CoreModels__NS__VSCodeSettings, UtilsOs__NS__commandExistsAsync, UtilsOs__NS__commandExistsSync, UtilsOs__NS__detectEditor, UtilsOs__NS__drawHorizontalLine, UtilsOs__NS__drawVerticalLine, UtilsOs__NS__Editor, UtilsOs__NS__EDITOR_PROCESSES, UtilsOs__NS__EditorArr, UtilsOs__NS__EditorProcess, UtilsOs__NS__getEditorKeybindingPath, UtilsOs__NS__getEditorSettingsJsonPath, UtilsOs__NS__getInotifyWatchCount, UtilsOs__NS__getRealHomeDir, UtilsOs__NS__isBrowser, UtilsOs__NS__isDockerAvailable, UtilsOs__NS__isElectron, UtilsOs__NS__isNode, UtilsOs__NS__isNodeVersionOk, UtilsOs__NS__isPortInUse, UtilsOs__NS__isRunningInBrowser, UtilsOs__NS__isRunningInCliMode, UtilsOs__NS__isRunningInCloudflareWorker, UtilsOs__NS__isRunningInDocker, UtilsOs__NS__isRunningInElectron, UtilsOs__NS__isRunningInLinuxDistro, UtilsOs__NS__isRunningInLinuxGraphicsCapableEnvironment, UtilsOs__NS__isRunningInMochaTest, UtilsOs__NS__isRunningInNode, UtilsOs__NS__isRunningInOsWithGraphicsCapableEnvironment, UtilsOs__NS__isRunningInSSRMode, UtilsOs__NS__isRunningInVscodeExtension, UtilsOs__NS__isRunningInWebSQL, UtilsOs__NS__isRunningInWindows, UtilsOs__NS__isRunningInWindowsCmd, UtilsOs__NS__isRunningInWindowsGitBash, UtilsOs__NS__isRunningInWindowsPowerShell, UtilsOs__NS__isRunningInWsl, UtilsOs__NS__isRunningNodeDebugger, UtilsOs__NS__isSSRMode, UtilsOs__NS__isVscodeExtension, UtilsOs__NS__isWebSQL, UtilsOs__NS__killAllEditor, UtilsOs__NS__openFolderInFileExplorer, UtilsOs__NS__pipxNestedPackageExists, UtilsOs__NS__pipxPackageExists, UtilsOs__NS__pythonModuleExists, UtilsOs__NS__safeExitProgramCleanUp, UtilsOs__NS__sendNotification, UtilsOs__NS__whichOrWherePackageLocated } from 'tnp-core/browser-prod';
|
|
9
|
+
import { Helpers__NS___fixCommand, Helpers__NS__ActionInstance, Helpers__NS__actionStarted, Helpers__NS__bigMaxBuffer, Helpers__NS__checkProcess, Helpers__NS__cleanExit, Helpers__NS__clearConsole, Helpers__NS__command, Helpers__NS__commandOutputAsString, Helpers__NS__commandOutputAsStringAsync, 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__getIsVerboseModeOrTnp, 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__logTaskDone, Helpers__NS__logTaskStarted, 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/browser-prod';
|
|
10
|
+
const REGISTRY_SYMBOL = Symbol.for('TAON.CLASS_REGISTRY');
|
|
11
|
+
type Registry = Map<string, Function>;
|
|
12
|
+
function getRegistry(): Registry {
|
|
13
|
+
const g = globalThis as any;
|
|
14
|
+
if (!g[REGISTRY_SYMBOL]) {
|
|
15
|
+
g[REGISTRY_SYMBOL] = new Map<string, Function>();
|
|
16
|
+
}
|
|
17
|
+
return g[REGISTRY_SYMBOL];
|
|
18
|
+
}
|
|
19
|
+
const classes = getRegistry();
|
|
20
|
+
export function getClassName(target: Function): string | undefined {
|
|
21
|
+
if (___NS__isNil(target)) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
if (___NS__isString(target)) {
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
if (target === Date) {
|
|
28
|
+
return 'Date';
|
|
29
|
+
}
|
|
30
|
+
if ((target as any) === FormData) {
|
|
31
|
+
return 'FormData';
|
|
32
|
+
}
|
|
33
|
+
if (!___NS__isFunction(target)) {
|
|
34
|
+
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (!___NS__isNil(target[CoreModels__NS__ClassNameStaticProperty])) {
|
|
38
|
+
return target[CoreModels__NS__ClassNameStaticProperty];
|
|
39
|
+
}
|
|
40
|
+
if (target.name?.startsWith('class_')) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
export function getClassFnFromObject(obj: object): Function | undefined {
|
|
46
|
+
if (___NS__isNil(obj)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return Object.getPrototypeOf(obj)?.constructor;
|
|
50
|
+
}
|
|
51
|
+
const notAllowedAsMethodNames = new Set([
|
|
52
|
+
'length',
|
|
53
|
+
'name',
|
|
54
|
+
'arguments',
|
|
55
|
+
'caller',
|
|
56
|
+
'constructor',
|
|
57
|
+
'apply',
|
|
58
|
+
'bind',
|
|
59
|
+
'call',
|
|
60
|
+
'toString',
|
|
61
|
+
'__defineGetter__',
|
|
62
|
+
'__defineSetter__',
|
|
63
|
+
'hasOwnProperty',
|
|
64
|
+
'__lookupGetter__',
|
|
65
|
+
'__lookupSetter__',
|
|
66
|
+
'isPrototypeOf',
|
|
67
|
+
'propertyIsEnumerable',
|
|
68
|
+
'valueOf',
|
|
69
|
+
'__proto__',
|
|
70
|
+
'toLocaleString',
|
|
71
|
+
]);
|
|
72
|
+
export function CLASS__NS__NAME(className: string) {
|
|
73
|
+
return function (target: Function) {
|
|
74
|
+
return CLASS__NS__setClassName(target, className);
|
|
75
|
+
} as any;
|
|
76
|
+
}
|
|
77
|
+
export function CLASS__NS__setName(target: Function, className: string) {
|
|
78
|
+
CLASS__NS__setClassName(target, className);
|
|
79
|
+
}
|
|
80
|
+
export function CLASS__NS__getClassNameFromObjInstanceOrClassFn(target: any): string | undefined {
|
|
81
|
+
if (typeof target === 'object') {
|
|
82
|
+
return CLASS__NS__getNameFromObject(target);
|
|
83
|
+
}
|
|
84
|
+
return getClassName(target);
|
|
85
|
+
}
|
|
86
|
+
export function CLASS__NS__setClassName(target: Function, className: string): void {
|
|
87
|
+
target[CoreModels__NS__ClassNameStaticProperty] = className;
|
|
88
|
+
classes.set(className, target);
|
|
89
|
+
}
|
|
90
|
+
export function CLASS__NS__getBy(className: string | Function): Function | undefined {
|
|
91
|
+
let res;
|
|
92
|
+
if (Array.isArray(className)) {
|
|
93
|
+
if (className.length !== 1) {
|
|
94
|
+
throw new Error(`Mapping error... please use proper class names:
|
|
95
|
+
{
|
|
96
|
+
propertyObject: 'MyClassName',
|
|
97
|
+
propertyWithArray: ['MyClassName']
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
`);
|
|
101
|
+
}
|
|
102
|
+
className = className[0];
|
|
103
|
+
}
|
|
104
|
+
if (typeof className === 'function') {
|
|
105
|
+
res = className;
|
|
106
|
+
}
|
|
107
|
+
if (className === 'Date') {
|
|
108
|
+
res = Date;
|
|
109
|
+
}
|
|
110
|
+
if (className === 'FormData') {
|
|
111
|
+
res = FormData;
|
|
112
|
+
}
|
|
113
|
+
const classFromMap = classes.get(className as string);
|
|
114
|
+
return classFromMap ? classFromMap : res;
|
|
115
|
+
}
|
|
116
|
+
export function CLASS__NS__getFromObject(o: Object): Function | undefined {
|
|
117
|
+
return getClassFnFromObject(o);
|
|
118
|
+
}
|
|
119
|
+
export function CLASS__NS__getName(target: Function): string | undefined {
|
|
120
|
+
return getClassName(target) as string;
|
|
121
|
+
}
|
|
122
|
+
export function CLASS__NS__getNameFromObject(o: Object): string | undefined {
|
|
123
|
+
const fnCLass = CLASS__NS__getFromObject(o);
|
|
124
|
+
return CLASS__NS__getName(fnCLass);
|
|
125
|
+
}
|
|
126
|
+
export const CLASS__NS__getMethodsNames = (classOrClassInstance: any, allMethodsNames = []): string[] => {
|
|
127
|
+
if (!classOrClassInstance) {
|
|
128
|
+
return allMethodsNames;
|
|
129
|
+
}
|
|
130
|
+
const isClassFunction = ___NS__isFunction(classOrClassInstance);
|
|
131
|
+
const classFun = isClassFunction
|
|
132
|
+
? classOrClassInstance
|
|
133
|
+
: Object.getPrototypeOf(classOrClassInstance);
|
|
134
|
+
const objectToCheck = isClassFunction
|
|
135
|
+
? (classOrClassInstance as Function)?.prototype
|
|
136
|
+
: classOrClassInstance;
|
|
137
|
+
const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
|
|
138
|
+
const properties = ___NS__uniq([
|
|
139
|
+
...Object.getOwnPropertyNames(objectToCheck || {}),
|
|
140
|
+
...Object.getOwnPropertyNames(prototypeObj || {}),
|
|
141
|
+
...Object.keys(objectToCheck || {}),
|
|
142
|
+
...Object.keys(prototypeObj || {}),
|
|
143
|
+
]).filter(f => !!f && !notAllowedAsMethodNames.has(f));
|
|
144
|
+
properties
|
|
145
|
+
.filter(methodName => typeof objectToCheck[methodName] === 'function')
|
|
146
|
+
.forEach(p => allMethodsNames.push(p));
|
|
147
|
+
if (!classFun ||
|
|
148
|
+
!classFun.constructor ||
|
|
149
|
+
classFun?.constructor?.name === 'Object') {
|
|
150
|
+
return allMethodsNames;
|
|
151
|
+
}
|
|
152
|
+
return CLASS__NS__getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
|
|
153
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export const BUILD_FRAMEWORK_CLI_NAME = 'tnp';
|
|
9
|
+
export const APP_ID = 'com.domain.example.typescript-class-helpers';
|
|
10
|
+
export const BUILD_BASE_HREF = '';
|
|
11
|
+
export const PROJECT_NPM_NAME = 'typescript-class-helpers';
|
|
12
|
+
export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
13
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.65';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export * from './typescript-class-helpers';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { _, CoreModels, UtilsOs } from 'tnp-core/websql';
|
|
9
|
+
import { Helpers } from 'tnp-core/websql';
|
|
10
|
+
const REGISTRY_SYMBOL = Symbol.for('TAON.CLASS_REGISTRY');
|
|
11
|
+
type Registry = Map<string, Function>;
|
|
12
|
+
function getRegistry(): Registry {
|
|
13
|
+
const g = globalThis as any;
|
|
14
|
+
if (!g[REGISTRY_SYMBOL]) {
|
|
15
|
+
g[REGISTRY_SYMBOL] = new Map<string, Function>();
|
|
16
|
+
}
|
|
17
|
+
return g[REGISTRY_SYMBOL];
|
|
18
|
+
}
|
|
19
|
+
const classes = getRegistry();
|
|
20
|
+
export function getClassName(target: Function): string | undefined {
|
|
21
|
+
if (_.isNil(target)) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
if (_.isString(target)) {
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
if (target === Date) {
|
|
28
|
+
return 'Date';
|
|
29
|
+
}
|
|
30
|
+
if ((target as any) === FormData) {
|
|
31
|
+
return 'FormData';
|
|
32
|
+
}
|
|
33
|
+
if (!_.isFunction(target)) {
|
|
34
|
+
Helpers.log(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (!_.isNil(target[CoreModels.ClassNameStaticProperty])) {
|
|
38
|
+
return target[CoreModels.ClassNameStaticProperty];
|
|
39
|
+
}
|
|
40
|
+
if (target.name?.startsWith('class_')) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
export function getClassFnFromObject(obj: object): Function | undefined {
|
|
46
|
+
if (_.isNil(obj)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return Object.getPrototypeOf(obj)?.constructor;
|
|
50
|
+
}
|
|
51
|
+
const notAllowedAsMethodNames = new Set([
|
|
52
|
+
'length',
|
|
53
|
+
'name',
|
|
54
|
+
'arguments',
|
|
55
|
+
'caller',
|
|
56
|
+
'constructor',
|
|
57
|
+
'apply',
|
|
58
|
+
'bind',
|
|
59
|
+
'call',
|
|
60
|
+
'toString',
|
|
61
|
+
'__defineGetter__',
|
|
62
|
+
'__defineSetter__',
|
|
63
|
+
'hasOwnProperty',
|
|
64
|
+
'__lookupGetter__',
|
|
65
|
+
'__lookupSetter__',
|
|
66
|
+
'isPrototypeOf',
|
|
67
|
+
'propertyIsEnumerable',
|
|
68
|
+
'valueOf',
|
|
69
|
+
'__proto__',
|
|
70
|
+
'toLocaleString',
|
|
71
|
+
]);
|
|
72
|
+
export namespace CLASS {
|
|
73
|
+
export function NAME(className: string) {
|
|
74
|
+
return function (target: Function) {
|
|
75
|
+
return setClassName(target, className);
|
|
76
|
+
} as any;
|
|
77
|
+
}
|
|
78
|
+
export function setName(target: Function, className: string) {
|
|
79
|
+
setClassName(target, className);
|
|
80
|
+
}
|
|
81
|
+
export function getClassNameFromObjInstanceOrClassFn(target: any): string | undefined {
|
|
82
|
+
if (typeof target === 'object') {
|
|
83
|
+
return getNameFromObject(target);
|
|
84
|
+
}
|
|
85
|
+
return getClassName(target);
|
|
86
|
+
}
|
|
87
|
+
export function setClassName(target: Function, className: string): void {
|
|
88
|
+
target[CoreModels.ClassNameStaticProperty] = className;
|
|
89
|
+
classes.set(className, target);
|
|
90
|
+
}
|
|
91
|
+
export function getBy(className: string | Function): Function | undefined {
|
|
92
|
+
let res;
|
|
93
|
+
if (Array.isArray(className)) {
|
|
94
|
+
if (className.length !== 1) {
|
|
95
|
+
throw new Error(`Mapping error... please use proper class names:
|
|
96
|
+
{
|
|
97
|
+
propertyObject: 'MyClassName',
|
|
98
|
+
propertyWithArray: ['MyClassName']
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
`);
|
|
102
|
+
}
|
|
103
|
+
className = className[0];
|
|
104
|
+
}
|
|
105
|
+
if (typeof className === 'function') {
|
|
106
|
+
res = className;
|
|
107
|
+
}
|
|
108
|
+
if (className === 'Date') {
|
|
109
|
+
res = Date;
|
|
110
|
+
}
|
|
111
|
+
if (className === 'FormData') {
|
|
112
|
+
res = FormData;
|
|
113
|
+
}
|
|
114
|
+
const classFromMap = classes.get(className as string);
|
|
115
|
+
return classFromMap ? classFromMap : res;
|
|
116
|
+
}
|
|
117
|
+
export function getFromObject(o: Object): Function | undefined {
|
|
118
|
+
return getClassFnFromObject(o);
|
|
119
|
+
}
|
|
120
|
+
export function getName(target: Function): string | undefined {
|
|
121
|
+
return getClassName(target) as string;
|
|
122
|
+
}
|
|
123
|
+
export function getNameFromObject(o: Object): string | undefined {
|
|
124
|
+
const fnCLass = getFromObject(o);
|
|
125
|
+
return getName(fnCLass);
|
|
126
|
+
}
|
|
127
|
+
export const getMethodsNames = (classOrClassInstance: any, allMethodsNames = []): string[] => {
|
|
128
|
+
if (!classOrClassInstance) {
|
|
129
|
+
return allMethodsNames;
|
|
130
|
+
}
|
|
131
|
+
const isClassFunction = _.isFunction(classOrClassInstance);
|
|
132
|
+
const classFun = isClassFunction
|
|
133
|
+
? classOrClassInstance
|
|
134
|
+
: Object.getPrototypeOf(classOrClassInstance);
|
|
135
|
+
const objectToCheck = isClassFunction
|
|
136
|
+
? (classOrClassInstance as Function)?.prototype
|
|
137
|
+
: classOrClassInstance;
|
|
138
|
+
const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
|
|
139
|
+
const properties = _.uniq([
|
|
140
|
+
...Object.getOwnPropertyNames(objectToCheck || {}),
|
|
141
|
+
...Object.getOwnPropertyNames(prototypeObj || {}),
|
|
142
|
+
...Object.keys(objectToCheck || {}),
|
|
143
|
+
...Object.keys(prototypeObj || {}),
|
|
144
|
+
]).filter(f => !!f && !notAllowedAsMethodNames.has(f));
|
|
145
|
+
properties
|
|
146
|
+
.filter(methodName => typeof objectToCheck[methodName] === 'function')
|
|
147
|
+
.forEach(p => allMethodsNames.push(p));
|
|
148
|
+
if (!classFun ||
|
|
149
|
+
!classFun.constructor ||
|
|
150
|
+
classFun?.constructor?.name === 'Object') {
|
|
151
|
+
return allMethodsNames;
|
|
152
|
+
}
|
|
153
|
+
return getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export const BUILD_FRAMEWORK_CLI_NAME = 'tnp';
|
|
9
|
+
export const APP_ID = 'com.domain.example.typescript-class-helpers';
|
|
10
|
+
export const BUILD_BASE_HREF = '';
|
|
11
|
+
export const PROJECT_NPM_NAME = 'typescript-class-helpers';
|
|
12
|
+
export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
13
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.65';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export * from './typescript-class-helpers';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"namespacesMapObj": {
|
|
3
|
+
"CLASS.NAME": "CLASS__NS__NAME",
|
|
4
|
+
"CLASS.setName": "CLASS__NS__setName",
|
|
5
|
+
"CLASS.getClassNameFromObjInstanceOrClassFn": "CLASS__NS__getClassNameFromObjInstanceOrClassFn",
|
|
6
|
+
"CLASS.setClassName": "CLASS__NS__setClassName",
|
|
7
|
+
"CLASS.getBy": "CLASS__NS__getBy",
|
|
8
|
+
"CLASS.getFromObject": "CLASS__NS__getFromObject",
|
|
9
|
+
"CLASS.getName": "CLASS__NS__getName",
|
|
10
|
+
"CLASS.getNameFromObject": "CLASS__NS__getNameFromObject",
|
|
11
|
+
"CLASS.getMethodsNames": "CLASS__NS__getMethodsNames"
|
|
12
|
+
},
|
|
13
|
+
"namespacesReplace": {
|
|
14
|
+
"CLASS": [
|
|
15
|
+
"CLASS__NS__NAME",
|
|
16
|
+
"CLASS__NS__getBy",
|
|
17
|
+
"CLASS__NS__getClassNameFromObjInstanceOrClassFn",
|
|
18
|
+
"CLASS__NS__getFromObject",
|
|
19
|
+
"CLASS__NS__getMethodsNames",
|
|
20
|
+
"CLASS__NS__getName",
|
|
21
|
+
"CLASS__NS__getNameFromObject",
|
|
22
|
+
"CLASS__NS__setClassName",
|
|
23
|
+
"CLASS__NS__setName"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* TAON READONLY SOURCE
|
|
4
|
+
* DO NOT MODIFY THIS FILE.
|
|
5
|
+
* Changes may be overwritten.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
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__isLeafObject, ___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, CoreModels__NS__BaseProjectType, CoreModels__NS__BaseProjectTypeArr, CoreModels__NS__BuildType, CoreModels__NS__BuildTypeArr, CoreModels__NS__buildTypeToWatcherFn, CoreModels__NS__BuildWatcherErrorType, CoreModels__NS__BuildWatcherType, CoreModels__NS__BuildWatcherTypeArr, CoreModels__NS__CfontAlign, CoreModels__NS__CfontStyle, CoreModels__NS__ClassNameStaticProperty, CoreModels__NS__ContentType, CoreModels__NS__ContentTypeKeys, CoreModels__NS__CoreLibCategory, CoreModels__NS__CutableFileExt, CoreModels__NS__DatabaseType, CoreModels__NS__DeepPartial, CoreModels__NS__FileEvent, CoreModels__NS__FileExtension, CoreModels__NS__FirstParamsFrom, CoreModels__NS__FrameworkVersion, CoreModels__NS__GitConnection, CoreModels__NS__GitConnectionArr, CoreModels__NS__GlobalDependencies, CoreModels__NS__hasExitCleaningFunction, CoreModels__NS__HttpCode, CoreModels__NS__HttpMethod, CoreModels__NS__HttpMethodArr, CoreModels__NS__ImageFileExtension, CoreModels__NS__ImageFileExtensionArr, CoreModels__NS__InstalationType, CoreModels__NS__InstalationTypeArr, CoreModels__NS__LibType, CoreModels__NS__localhostDomain, CoreModels__NS__localhostIp127, CoreModels__NS__ManifestIcon, CoreModels__NS__MediaType, CoreModels__NS__MediaTypeAllArr, CoreModels__NS__mimeTypes, CoreModels__NS__NewFactoryType, CoreModels__NS__NpmInstallOptions, CoreModels__NS__NpmPublishOptions, CoreModels__NS__NpmSpecialVersions, CoreModels__NS__OrignalClassKey, CoreModels__NS__OutFolder, CoreModels__NS__Package, CoreModels__NS__ParamType, CoreModels__NS__parentLocation, CoreModels__NS__pathToChildren, CoreModels__NS__Position, CoreModels__NS__PreReleaseVersionTag, CoreModels__NS__PROGRESS_DATA_TYPE, CoreModels__NS__PUSHTYPE, CoreModels__NS__PwaManifest, CoreModels__NS__ReleaseVersionType, CoreModels__NS__ReleaseVersionTypeEnum, CoreModels__NS__RunOptions, CoreModels__NS__Size, CoreModels__NS__SPECIAL_APP_READY_MESSAGE, CoreModels__NS__SPECIAL_WORKER_READY_MESSAGE, CoreModels__NS__StatusCode401, CoreModels__NS__tagForTaskName, CoreModels__NS__TaonHttpErrorCustomProp, CoreModels__NS__TsUsage, CoreModels__NS__UIFramework, CoreModels__NS__ValueOf, CoreModels__NS__VSCodeSettings, UtilsOs__NS__commandExistsAsync, UtilsOs__NS__commandExistsSync, UtilsOs__NS__detectEditor, UtilsOs__NS__drawHorizontalLine, UtilsOs__NS__drawVerticalLine, UtilsOs__NS__Editor, UtilsOs__NS__EDITOR_PROCESSES, UtilsOs__NS__EditorArr, UtilsOs__NS__EditorProcess, UtilsOs__NS__getEditorKeybindingPath, UtilsOs__NS__getEditorSettingsJsonPath, UtilsOs__NS__getInotifyWatchCount, UtilsOs__NS__getRealHomeDir, UtilsOs__NS__isBrowser, UtilsOs__NS__isDockerAvailable, UtilsOs__NS__isElectron, UtilsOs__NS__isNode, UtilsOs__NS__isNodeVersionOk, UtilsOs__NS__isPortInUse, UtilsOs__NS__isRunningInBrowser, UtilsOs__NS__isRunningInCliMode, UtilsOs__NS__isRunningInCloudflareWorker, UtilsOs__NS__isRunningInDocker, UtilsOs__NS__isRunningInElectron, UtilsOs__NS__isRunningInLinuxDistro, UtilsOs__NS__isRunningInLinuxGraphicsCapableEnvironment, UtilsOs__NS__isRunningInMochaTest, UtilsOs__NS__isRunningInNode, UtilsOs__NS__isRunningInOsWithGraphicsCapableEnvironment, UtilsOs__NS__isRunningInSSRMode, UtilsOs__NS__isRunningInVscodeExtension, UtilsOs__NS__isRunningInWebSQL, UtilsOs__NS__isRunningInWindows, UtilsOs__NS__isRunningInWindowsCmd, UtilsOs__NS__isRunningInWindowsGitBash, UtilsOs__NS__isRunningInWindowsPowerShell, UtilsOs__NS__isRunningInWsl, UtilsOs__NS__isRunningNodeDebugger, UtilsOs__NS__isSSRMode, UtilsOs__NS__isVscodeExtension, UtilsOs__NS__isWebSQL, UtilsOs__NS__killAllEditor, UtilsOs__NS__openFolderInFileExplorer, UtilsOs__NS__pipxNestedPackageExists, UtilsOs__NS__pipxPackageExists, UtilsOs__NS__pythonModuleExists, UtilsOs__NS__safeExitProgramCleanUp, UtilsOs__NS__sendNotification, UtilsOs__NS__whichOrWherePackageLocated } from 'tnp-core/websql-prod';
|
|
9
|
+
import { Helpers__NS___fixCommand, Helpers__NS__ActionInstance, Helpers__NS__actionStarted, Helpers__NS__bigMaxBuffer, Helpers__NS__checkProcess, Helpers__NS__cleanExit, Helpers__NS__clearConsole, Helpers__NS__command, Helpers__NS__commandOutputAsString, Helpers__NS__commandOutputAsStringAsync, 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__getIsVerboseModeOrTnp, 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__logTaskDone, Helpers__NS__logTaskStarted, 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/websql-prod';
|
|
10
|
+
const REGISTRY_SYMBOL = Symbol.for('TAON.CLASS_REGISTRY');
|
|
11
|
+
type Registry = Map<string, Function>;
|
|
12
|
+
function getRegistry(): Registry {
|
|
13
|
+
const g = globalThis as any;
|
|
14
|
+
if (!g[REGISTRY_SYMBOL]) {
|
|
15
|
+
g[REGISTRY_SYMBOL] = new Map<string, Function>();
|
|
16
|
+
}
|
|
17
|
+
return g[REGISTRY_SYMBOL];
|
|
18
|
+
}
|
|
19
|
+
const classes = getRegistry();
|
|
20
|
+
export function getClassName(target: Function): string | undefined {
|
|
21
|
+
if (___NS__isNil(target)) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
if (___NS__isString(target)) {
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
if (target === Date) {
|
|
28
|
+
return 'Date';
|
|
29
|
+
}
|
|
30
|
+
if ((target as any) === FormData) {
|
|
31
|
+
return 'FormData';
|
|
32
|
+
}
|
|
33
|
+
if (!___NS__isFunction(target)) {
|
|
34
|
+
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (!___NS__isNil(target[CoreModels__NS__ClassNameStaticProperty])) {
|
|
38
|
+
return target[CoreModels__NS__ClassNameStaticProperty];
|
|
39
|
+
}
|
|
40
|
+
if (target.name?.startsWith('class_')) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
export function getClassFnFromObject(obj: object): Function | undefined {
|
|
46
|
+
if (___NS__isNil(obj)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return Object.getPrototypeOf(obj)?.constructor;
|
|
50
|
+
}
|
|
51
|
+
const notAllowedAsMethodNames = new Set([
|
|
52
|
+
'length',
|
|
53
|
+
'name',
|
|
54
|
+
'arguments',
|
|
55
|
+
'caller',
|
|
56
|
+
'constructor',
|
|
57
|
+
'apply',
|
|
58
|
+
'bind',
|
|
59
|
+
'call',
|
|
60
|
+
'toString',
|
|
61
|
+
'__defineGetter__',
|
|
62
|
+
'__defineSetter__',
|
|
63
|
+
'hasOwnProperty',
|
|
64
|
+
'__lookupGetter__',
|
|
65
|
+
'__lookupSetter__',
|
|
66
|
+
'isPrototypeOf',
|
|
67
|
+
'propertyIsEnumerable',
|
|
68
|
+
'valueOf',
|
|
69
|
+
'__proto__',
|
|
70
|
+
'toLocaleString',
|
|
71
|
+
]);
|
|
72
|
+
export function CLASS__NS__NAME(className: string) {
|
|
73
|
+
return function (target: Function) {
|
|
74
|
+
return CLASS__NS__setClassName(target, className);
|
|
75
|
+
} as any;
|
|
76
|
+
}
|
|
77
|
+
export function CLASS__NS__setName(target: Function, className: string) {
|
|
78
|
+
CLASS__NS__setClassName(target, className);
|
|
79
|
+
}
|
|
80
|
+
export function CLASS__NS__getClassNameFromObjInstanceOrClassFn(target: any): string | undefined {
|
|
81
|
+
if (typeof target === 'object') {
|
|
82
|
+
return CLASS__NS__getNameFromObject(target);
|
|
83
|
+
}
|
|
84
|
+
return getClassName(target);
|
|
85
|
+
}
|
|
86
|
+
export function CLASS__NS__setClassName(target: Function, className: string): void {
|
|
87
|
+
target[CoreModels__NS__ClassNameStaticProperty] = className;
|
|
88
|
+
classes.set(className, target);
|
|
89
|
+
}
|
|
90
|
+
export function CLASS__NS__getBy(className: string | Function): Function | undefined {
|
|
91
|
+
let res;
|
|
92
|
+
if (Array.isArray(className)) {
|
|
93
|
+
if (className.length !== 1) {
|
|
94
|
+
throw new Error(`Mapping error... please use proper class names:
|
|
95
|
+
{
|
|
96
|
+
propertyObject: 'MyClassName',
|
|
97
|
+
propertyWithArray: ['MyClassName']
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
`);
|
|
101
|
+
}
|
|
102
|
+
className = className[0];
|
|
103
|
+
}
|
|
104
|
+
if (typeof className === 'function') {
|
|
105
|
+
res = className;
|
|
106
|
+
}
|
|
107
|
+
if (className === 'Date') {
|
|
108
|
+
res = Date;
|
|
109
|
+
}
|
|
110
|
+
if (className === 'FormData') {
|
|
111
|
+
res = FormData;
|
|
112
|
+
}
|
|
113
|
+
const classFromMap = classes.get(className as string);
|
|
114
|
+
return classFromMap ? classFromMap : res;
|
|
115
|
+
}
|
|
116
|
+
export function CLASS__NS__getFromObject(o: Object): Function | undefined {
|
|
117
|
+
return getClassFnFromObject(o);
|
|
118
|
+
}
|
|
119
|
+
export function CLASS__NS__getName(target: Function): string | undefined {
|
|
120
|
+
return getClassName(target) as string;
|
|
121
|
+
}
|
|
122
|
+
export function CLASS__NS__getNameFromObject(o: Object): string | undefined {
|
|
123
|
+
const fnCLass = CLASS__NS__getFromObject(o);
|
|
124
|
+
return CLASS__NS__getName(fnCLass);
|
|
125
|
+
}
|
|
126
|
+
export const CLASS__NS__getMethodsNames = (classOrClassInstance: any, allMethodsNames = []): string[] => {
|
|
127
|
+
if (!classOrClassInstance) {
|
|
128
|
+
return allMethodsNames;
|
|
129
|
+
}
|
|
130
|
+
const isClassFunction = ___NS__isFunction(classOrClassInstance);
|
|
131
|
+
const classFun = isClassFunction
|
|
132
|
+
? classOrClassInstance
|
|
133
|
+
: Object.getPrototypeOf(classOrClassInstance);
|
|
134
|
+
const objectToCheck = isClassFunction
|
|
135
|
+
? (classOrClassInstance as Function)?.prototype
|
|
136
|
+
: classOrClassInstance;
|
|
137
|
+
const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
|
|
138
|
+
const properties = ___NS__uniq([
|
|
139
|
+
...Object.getOwnPropertyNames(objectToCheck || {}),
|
|
140
|
+
...Object.getOwnPropertyNames(prototypeObj || {}),
|
|
141
|
+
...Object.keys(objectToCheck || {}),
|
|
142
|
+
...Object.keys(prototypeObj || {}),
|
|
143
|
+
]).filter(f => !!f && !notAllowedAsMethodNames.has(f));
|
|
144
|
+
properties
|
|
145
|
+
.filter(methodName => typeof objectToCheck[methodName] === 'function')
|
|
146
|
+
.forEach(p => allMethodsNames.push(p));
|
|
147
|
+
if (!classFun ||
|
|
148
|
+
!classFun.constructor ||
|
|
149
|
+
classFun?.constructor?.name === 'Object') {
|
|
150
|
+
return allMethodsNames;
|
|
151
|
+
}
|
|
152
|
+
return CLASS__NS__getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
|
|
153
|
+
};
|