vivth 1.4.10 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6060 -2037
- package/README.src.md +22 -14
- package/bun.lock +154 -194
- package/dev/auto/.src.ignore +28 -0
- package/dev/auto-doc.mjs +137 -0
- package/generated/types/generated/vivth/exports/all.d.mts +145 -0
- package/generated/types/generated/vivth/exports/neutral.d.mts +105 -0
- package/generated/types/generated/vivth/exports/node.d.mts +40 -0
- package/generated/types/src/bundler/CompileAS.d.mts +30 -0
- package/generated/types/src/bundler/CompileJS.d.mts +109 -0
- package/{types → generated/types}/src/bundler/CreateESPlugin.d.mts +1 -1
- package/{types → generated/types}/src/bundler/EsBundler.d.mts +9 -7
- package/generated/types/src/bundler/FSAnalyzer.d.mts +58 -0
- package/generated/types/src/bundler/FSasar.bundled.d.mts +28 -0
- package/generated/types/src/bundler/FSasar.d.mts +51 -0
- package/generated/types/src/bundler/FileSelfMapper.d.mts +137 -0
- package/generated/types/src/bundler/JSDirMapper.d.mts +128 -0
- package/generated/types/src/bundler/RunWatchThenCompileJSOnSafeExit.d.mts +63 -0
- package/generated/types/src/bundler/adds/BrowserExternals.d.mts +21 -0
- package/generated/types/src/bundler/adds/CreateTransform.d.mts +26 -0
- package/generated/types/src/bundler/adds/LastEditedUnix.d.mts +5 -0
- package/generated/types/src/bundler/adds/NodeModuleList.d.mts +15 -0
- package/generated/types/src/bundler/adds/PathFSBundles.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSBundles.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSDir.bundled.d.mts +30 -0
- package/generated/types/src/bundler/adds/PathFSDir.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSFile.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSFile.d.mts +40 -0
- package/{types → generated/types}/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -6
- package/generated/types/src/bundler/adds/autoExternalize.d.mts +2 -0
- package/generated/types/src/bundler/adds/emptyBufferValue.d.mts +1 -0
- package/generated/types/src/bundler/adds/isModuleTheBundledVersion.d.mts +1 -0
- package/generated/types/src/bundler/adds/onEndEsBuildErrorLogger.d.mts +1 -0
- package/generated/types/src/bundler/adds/resolveJSDependencyPath.d.mts +1 -0
- package/generated/types/src/class/AwaitSignal.d.mts +48 -0
- package/generated/types/src/class/Console.d.mts +82 -0
- package/generated/types/src/class/DataLog.d.mts +25 -0
- package/generated/types/src/class/Derived.d.mts +74 -0
- package/generated/types/src/class/Effect.d.mts +213 -0
- package/{types → generated/types}/src/class/EnvSignal.d.mts +6 -2
- package/generated/types/src/class/EsWatcher.d.mts +36 -0
- package/{types → generated/types}/src/class/EventSignal.d.mts +39 -39
- package/generated/types/src/class/FSDirArchWatcher.d.mts +110 -0
- package/{types → generated/types}/src/class/FileSafe.d.mts +32 -16
- package/generated/types/src/class/ForEach.d.mts +57 -0
- package/generated/types/src/class/ForSignal.d.mts +63 -0
- package/generated/types/src/class/GetterSetter.d.mts +38 -0
- package/generated/types/src/class/JSONFileHandler.d.mts +50 -0
- package/{types → generated/types}/src/class/ListSignal.d.mts +49 -15
- package/{types → generated/types}/src/class/LitExp.d.mts +18 -18
- package/generated/types/src/class/ObjectSignal.d.mts +267 -0
- package/generated/types/src/class/Paths.d.mts +95 -0
- package/generated/types/src/class/Prettivy.d.mts +26 -0
- package/{types → generated/types}/src/class/QChannel.d.mts +24 -16
- package/generated/types/src/class/SafeExit.d.mts +69 -0
- package/{types → generated/types}/src/class/Setup.d.mts +29 -16
- package/{types → generated/types}/src/class/Signal.d.mts +29 -15
- package/generated/types/src/class/SignalCollection.d.mts +96 -0
- package/{types → generated/types}/src/class/WalkThrough.d.mts +4 -19
- package/generated/types/src/class/WorkerMainThread.bundled.d.mts +83 -0
- package/{types → generated/types}/src/class/WorkerMainThread.d.mts +33 -39
- package/{types → generated/types}/src/class/WorkerThread.d.mts +11 -5
- package/{types → generated/types}/src/common/Base64URL.d.mts +2 -1
- package/generated/types/src/common/Base64URLFromFile.d.mts +20 -0
- package/generated/types/src/common/BundledV.bundled.d.mts +3 -0
- package/generated/types/src/common/BundledV.d.mts +36 -0
- package/{types → generated/types}/src/common/CreateStringID.d.mts +5 -4
- package/generated/types/src/common/EnvMode.d.mts +79 -0
- package/generated/types/src/common/FactoryKey.d.mts +9 -0
- package/generated/types/src/common/Preferrence.d.mts +25 -0
- package/{types → generated/types}/src/common/Trace.d.mts +1 -1
- package/{types → generated/types}/src/common/TracePath.d.mts +1 -1
- package/generated/types/src/common/VivthUnBundledCodeBlock.d.mts +6 -0
- package/generated/types/src/doc/JSautoDOC.d.mts +172 -0
- package/generated/types/src/doc/cleanPreserveTypedef.d.mts +1 -0
- package/{types/src/doc/parsedFile.d.mts → generated/types/src/doc/parsedFileForDOC.d.mts} +56 -27
- package/generated/types/src/function/ClearRequireCache.d.mts +1 -0
- package/{types → generated/types}/src/function/CreateImmutable.d.mts +5 -4
- package/{types → generated/types}/src/function/EventCheck.d.mts +3 -1
- package/{types → generated/types}/src/function/EventObject.d.mts +2 -6
- package/generated/types/src/function/ForInAsync.d.mts +36 -0
- package/generated/types/src/function/ForInSync.d.mts +36 -0
- package/generated/types/src/function/ForOfAsync.d.mts +25 -0
- package/generated/types/src/function/ForOfSync.d.mts +36 -0
- package/generated/types/src/function/GetBufferFromRelativePath.d.mts +15 -0
- package/generated/types/src/function/GetFilesFromDir.d.mts +14 -0
- package/generated/types/src/function/GetMaxFilenameLength.d.mts +9 -0
- package/generated/types/src/function/GetModuleEsbuildPlatform.d.mts +13 -0
- package/{types → generated/types}/src/function/GetNamedImportAlias.d.mts +1 -1
- package/generated/types/src/function/GetRuntime.d.mts +2 -0
- package/generated/types/src/function/InstantiateAssemblyScript.d.mts +15 -0
- package/{types → generated/types}/src/function/IsAsync.d.mts +1 -1
- package/generated/types/src/function/IsInstanceOf.d.mts +25 -0
- package/generated/types/src/function/IsSameFile.d.mts +16 -0
- package/generated/types/src/function/IsStringLooksLikeAPath.d.mts +16 -0
- package/generated/types/src/function/IsTypeOf.d.mts +25 -0
- package/{types → generated/types}/src/function/LazyFactory.d.mts +9 -10
- package/generated/types/src/function/MonkeyPatch.d.mts +33 -0
- package/generated/types/src/function/NewAnimationTimeline.d.mts +24 -0
- package/generated/types/src/function/NewChainable.d.mts +35 -0
- package/generated/types/src/function/NewDynamicsExport.d.mts +49 -0
- package/generated/types/src/function/NewObjectWrapper.d.mts +10 -0
- package/generated/types/src/function/ObjectRegistrar.d.mts +17 -0
- package/generated/types/src/function/ParseSQLFile.d.mts +25 -0
- package/generated/types/src/function/PipeAsync.d.mts +19 -0
- package/generated/types/src/function/PipeSync.d.mts +17 -0
- package/generated/types/src/function/SafeImport.d.mts +21 -0
- package/generated/types/src/function/TemplateLiteral.d.mts +23 -0
- package/{types → generated/types}/src/function/Timeout.d.mts +1 -1
- package/{types → generated/types}/src/function/Tries.d.mts +4 -4
- package/{types → generated/types}/src/function/TryAsync.d.mts +2 -2
- package/{types → generated/types}/src/function/TryNew.d.mts +1 -1
- package/generated/types/src/function/TsToMjs.d.mts +27 -0
- package/generated/types/src/function/UniqueFSTempName.d.mts +9 -0
- package/generated/types/src/function/errorToMessage.d.mts +5 -0
- package/generated/types/src/neinth/VivthyNeinth.d.mts +202 -0
- package/generated/types/src/typehints/ArrayToKeys.d.mts +23 -0
- package/generated/types/src/typehints/AssemblyScriptExportsType.d.mts +4 -0
- package/generated/types/src/typehints/AssemblyScriptLoaderInstantiate.d.mts +4 -0
- package/generated/types/src/typehints/AutoDocASOptions.d.mts +15 -0
- package/generated/types/src/typehints/ChainableType.d.mts +3 -0
- package/generated/types/src/typehints/ComponentDecorator_Constructor.d.mts +3 -0
- package/generated/types/src/typehints/ConsoleAdditionalSettingType.d.mts +3 -0
- package/generated/types/src/typehints/Decorator.d.mts +11 -0
- package/generated/types/src/typehints/DecoratorMonkeyPatch.d.mts +15 -0
- package/{types/src/types → generated/types/src/typehints}/DevTestCB.d.mts +2 -2
- package/generated/types/src/typehints/EnvModeType.d.mts +4 -0
- package/generated/types/src/typehints/ListArg.d.mts +4 -0
- package/generated/types/src/typehints/MonkeyPatchedType.d.mts +1 -0
- package/generated/types/src/typehints/ParametersFollowingN.d.mts +13 -0
- package/generated/types/src/typehints/PrefixedKeysOf.d.mts +1 -0
- package/generated/types/src/typehints/Runtime.d.mts +4 -0
- package/generated/types/src/typehints/SafeImportReturnType.d.mts +1 -0
- package/generated/types/src/typehints/StylePropRefType.d.mts +2 -0
- package/generated/types/src/typehints/TemplateLiteralValueHandler.d.mts +10 -0
- package/generated/types/src/typehints/VLifecycleCallbacks.d.mts +6 -0
- package/generated/types/src/typehints/VivthCleanup.d.mts +12 -0
- package/generated/types/src/web/BrowserDirMapper.d.mts +70 -0
- package/generated/types/src/web/EnsureValidTag.d.mts +7 -0
- package/generated/types/src/web/ViteAddDynamics.d.mts +28 -0
- package/generated/types/src/web/ViteGetAllHTMLFile.d.mts +9 -0
- package/generated/types/src/web/WC_extendsA.d.mts +135 -0
- package/generated/types/src/web/WC_extendsB.d.mts +135 -0
- package/generated/types/src/web/bindings/WC_StyleProp_bind.d.mts +42 -0
- package/generated/types/src/web/bindings/WC_createElement_bind.d.mts +51 -0
- package/generated/types/src/web/bindings/WC_createNamedSlot.d.mts +26 -0
- package/generated/types/src/web/bindings/WC_litRender_bind.d.mts +20 -0
- package/generated/types/src/web/bindings/WC_litStyleMap.d.mts +7 -0
- package/generated/types/src/web/common/CSS.d.mts +23 -0
- package/generated/types/src/web/common/E.d.mts +41 -0
- package/generated/types/src/web/common/NewStyleSheetAsync.d.mts +15 -0
- package/generated/types/src/web/common/NewStyleSheetSync.d.mts +15 -0
- package/generated/types/src/web/common/WC_TagName_type.d.mts +15 -0
- package/generated/types/src/web/signals/IsInViewPortSignal.d.mts +52 -0
- package/generated/types/src/web/signals/ObserverSignal.d.mts +32 -0
- package/generated/types/src/web/signals/WC_litRef.d.mts +26 -0
- package/generated/types/src/web/signals/WC_loopedSiblingsRef.d.mts +44 -0
- package/generated/vivth/exports/all.mjs +233 -0
- package/generated/vivth/exports/neutral.mjs +193 -0
- package/generated/vivth/exports/node.mjs +46 -0
- package/package.json +78 -42
- package/src/bundler/CompileAS.mjs +36 -0
- package/src/bundler/CompileJS.mjs +98 -171
- package/src/bundler/CreateESPlugin.mjs +1 -1
- package/src/bundler/EsBundler.mjs +38 -13
- package/src/bundler/FSAnalyzer.mjs +253 -0
- package/src/bundler/FSasar.bundled.mjs +128 -0
- package/src/bundler/FSasar.mjs +96 -0
- package/src/bundler/FileSelfMapper.mjs +491 -0
- package/src/bundler/JSDirMapper.mjs +528 -0
- package/src/bundler/RunWatchThenCompileJSOnSafeExit.mjs +129 -0
- package/src/bundler/adds/BrowserExternals.mjs +37 -0
- package/src/bundler/adds/CreateTransform.mjs +36 -0
- package/src/bundler/adds/LastEditedUnix.mjs +12 -0
- package/src/bundler/adds/NodeModuleList.mjs +33 -0
- package/src/bundler/adds/PathFSBundles.bundled.mjs +41 -0
- package/src/bundler/adds/PathFSBundles.mjs +91 -0
- package/src/bundler/adds/PathFSDir.bundled.mjs +53 -0
- package/src/bundler/adds/PathFSDir.mjs +100 -0
- package/src/bundler/adds/PathFSFile.bundled.mjs +40 -0
- package/src/bundler/adds/PathFSFile.mjs +85 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +116 -55
- package/src/bundler/adds/autoExternalize.mjs +81 -0
- package/src/bundler/adds/emptyBufferValue.mjs +5 -0
- package/src/bundler/adds/isModuleTheBundledVersion.mjs +10 -0
- package/src/bundler/adds/onEndEsBuildErrorLogger.mjs +34 -0
- package/src/bundler/adds/resolveJSDependencyPath.mjs +17 -0
- package/src/class/AwaitSignal.mjs +119 -0
- package/src/class/Console.mjs +36 -14
- package/src/class/DataLog.mjs +29 -0
- package/src/class/Derived.mjs +67 -55
- package/src/class/Effect.mjs +270 -84
- package/src/class/EnvSignal.mjs +11 -8
- package/src/class/EsWatcher.mjs +60 -0
- package/src/class/EventSignal.mjs +46 -58
- package/src/class/FSDirArchWatcher.mjs +246 -0
- package/src/class/FileSafe.mjs +72 -24
- package/src/class/ForEach.mjs +78 -0
- package/src/class/ForSignal.mjs +115 -0
- package/src/class/GetterSetter.mjs +40 -0
- package/src/class/JSONFileHandler.mjs +90 -0
- package/src/class/ListSignal.mjs +68 -26
- package/src/class/LitExp.mjs +59 -36
- package/src/class/ObjectSignal.mjs +225 -0
- package/src/class/Paths.mjs +56 -20
- package/src/class/Prettivy.mjs +51 -0
- package/src/class/QChannel.mjs +48 -26
- package/src/class/SafeExit.mjs +156 -99
- package/src/class/Setup.mjs +28 -16
- package/src/class/Signal.mjs +50 -27
- package/src/class/SignalCollection.mjs +130 -0
- package/src/class/WalkThrough.mjs +6 -23
- package/src/class/{WorkerMainThreadBundled.mjs → WorkerMainThread.bundled.mjs} +56 -77
- package/src/class/WorkerMainThread.mjs +98 -94
- package/src/class/WorkerThread.mjs +24 -17
- package/src/common/Base64URL.mjs +6 -3
- package/src/common/Base64URLFromFile.mjs +17 -4
- package/src/common/BundledV.bundled.mjs +7 -0
- package/src/common/BundledV.mjs +45 -0
- package/src/common/CreateStringID.mjs +8 -7
- package/src/common/EnvMode.mjs +172 -0
- package/src/common/FactoryKey.mjs +11 -0
- package/src/common/Preferrence.mjs +27 -0
- package/src/common/Trace.mjs +1 -1
- package/src/common/TracePath.mjs +53 -3
- package/src/common/VivthUnBundledCodeBlock.mjs +8 -0
- package/src/doc/JSautoDOC.mjs +673 -284
- package/src/doc/cleanPreserveTypedef.mjs +27 -0
- package/src/doc/correctBeforeParse.mjs +57 -48
- package/src/doc/{parsedFile.mjs → parsedFileForDOC.mjs} +133 -120
- package/src/function/ClearRequireCache.mjs +33 -0
- package/src/function/CreateImmutable.mjs +40 -37
- package/src/function/EventCheck.mjs +5 -2
- package/src/function/EventObject.mjs +2 -6
- package/src/function/ForInAsync.mjs +76 -0
- package/src/function/ForInSync.mjs +87 -0
- package/src/function/ForOfAsync.mjs +61 -0
- package/src/function/ForOfSync.mjs +70 -0
- package/src/function/GetBufferFromRelativePath.mjs +25 -0
- package/src/function/GetFilesFromDir.mjs +49 -0
- package/src/function/GetMaxFilenameLength.mjs +32 -0
- package/src/function/GetModuleEsbuildPlatform.mjs +118 -0
- package/src/function/GetNamedImportAlias.mjs +2 -2
- package/src/function/GetRuntime.mjs +10 -14
- package/src/function/InstantiateAssemblyScript.mjs +22 -0
- package/src/function/IsAsync.mjs +1 -1
- package/src/function/IsInstanceOf.mjs +29 -0
- package/src/function/IsSameFile.mjs +41 -0
- package/src/function/IsStringLooksLikeAPath.mjs +20 -0
- package/src/function/IsTypeOf.mjs +27 -0
- package/src/function/IsTypeOf.mts +31 -0
- package/src/function/LazyFactory.mjs +25 -23
- package/src/function/MonkeyPatch.mjs +38 -0
- package/src/function/NewAnimationTimeline.mjs +55 -0
- package/src/function/NewChainable.mjs +69 -0
- package/src/function/NewDynamicsExport.mjs +312 -0
- package/src/function/NewObjectWrapper.mjs +14 -0
- package/src/function/ObjectRegistrar.mjs +23 -0
- package/src/function/ParseSQLFile.mjs +129 -0
- package/src/function/PipeAsync.mjs +30 -0
- package/src/function/PipeSync.mjs +28 -0
- package/src/function/SafeImport.mjs +77 -0
- package/src/function/TemplateLiteral.mjs +42 -23
- package/src/function/Timeout.mjs +4 -4
- package/src/function/Tries.mjs +22 -16
- package/src/function/TryAsync.mjs +3 -2
- package/src/function/TryNew.mjs +1 -1
- package/src/function/TsToMjs.mjs +184 -21
- package/src/function/UniqueFSTempName.mjs +33 -0
- package/src/function/errorToMessage.mjs +21 -0
- package/src/function/resolveErrorArray.mjs +15 -1
- package/src/neinth/VivthyNeinth.mjs +487 -0
- package/src/typehints/ArrayToKeys.mjs +17 -0
- package/src/typehints/ArrayToKeys.mts +31 -0
- package/src/typehints/AssemblyScriptExportsType.mjs +7 -0
- package/src/typehints/AssemblyScriptLoaderInstantiate.mjs +7 -0
- package/src/typehints/AutoDocASOptions.mjs +14 -0
- package/src/typehints/ChainableType.mjs +11 -0
- package/src/typehints/ComponentDecorator_Constructor.mjs +10 -0
- package/src/typehints/ConsoleAdditionalSettingType.mjs +6 -0
- package/src/typehints/Decorator.mjs +9 -0
- package/src/typehints/Decorator.mts +31 -0
- package/src/typehints/DecoratorMonkeyPatch.mjs +10 -0
- package/src/typehints/DecoratorMonkeyPatch.mts +43 -0
- package/src/{types → typehints}/DevTestCB.mjs +2 -2
- package/src/typehints/EnvModeType.mjs +6 -0
- package/src/{types → typehints}/ListArg.mjs +1 -1
- package/src/{types → typehints}/LitExpResultType.mjs +1 -1
- package/src/typehints/MonkeyPatchedType.mjs +13 -0
- package/src/typehints/ParametersFollowingN.mjs +8 -0
- package/src/typehints/ParametersFollowingN.mts +17 -0
- package/src/typehints/PrefixedKeysOf.mjs +9 -0
- package/src/typehints/Runtime.mjs +6 -0
- package/src/typehints/SafeImportReturnType.mjs +6 -0
- package/src/typehints/StylePropRefType.mjs +12 -0
- package/src/typehints/TemplateLiteralValueHandler.mjs +14 -0
- package/src/typehints/VLifecycleCallbacks.mjs +10 -0
- package/src/typehints/VivthCleanup.mjs +14 -0
- package/src/web/BrowserDirMapper.mjs +255 -0
- package/src/web/EnsureValidTag.mjs +5 -0
- package/src/web/EnsureValidTag.mts +10 -0
- package/src/web/ViteAddDynamics.mjs +34 -0
- package/src/web/ViteGetAllHTMLFile.mjs +97 -0
- package/src/web/WC_extendsA.mjs +330 -0
- package/src/web/WC_extendsB.mjs +332 -0
- package/src/web/bindings/WC_StyleProp_bind.mjs +70 -0
- package/src/web/bindings/WC_createElement_bind.mjs +95 -0
- package/src/web/bindings/WC_createNamedSlot.mjs +29 -0
- package/src/web/bindings/WC_litRender_bind.mjs +26 -0
- package/src/web/bindings/WC_litStyleMap.mjs +14 -0
- package/src/web/common/CSS.mjs +35 -0
- package/src/web/common/E.mjs +126 -0
- package/src/web/common/NewStyleSheetAsync.mjs +21 -0
- package/src/web/common/NewStyleSheetSync.mjs +21 -0
- package/src/web/common/WC_TagName_type.mjs +10 -0
- package/src/web/common/WC_TagName_type.mts +36 -0
- package/src/web/signals/IsInViewPortSignal.mjs +140 -0
- package/src/web/signals/ObserverSignal.mjs +93 -0
- package/src/web/signals/WC_litRef.mjs +61 -0
- package/src/web/signals/WC_loopedSiblingsRef.mjs +100 -0
- package/tsconfig.json +44 -41
- package/index.mjs +0 -91
- package/src/bundler/FSInline.mjs +0 -67
- package/src/bundler/FSInlineAnalyzer.mjs +0 -228
- package/src/bundler/FSInlineBundled.mjs +0 -38
- package/src/bundler/adds/externals.mjs +0 -8
- package/src/class/ListDerived.mjs +0 -42
- package/src/common/Dev.mjs +0 -142
- package/src/common/DevBundled.mjs +0 -5
- package/src/common/lazie.mjs +0 -3
- package/src/types/IsListSignal.mjs +0 -6
- package/src/types/Runtime.mjs +0 -6
- package/src/types/VivthDevCodeBlockStringType.mjs +0 -6
- package/types/index.d.mts +0 -58
- package/types/src/bundler/CompileJS.d.mts +0 -119
- package/types/src/bundler/FSInline.d.mts +0 -50
- package/types/src/bundler/FSInlineAnalyzer.d.mts +0 -37
- package/types/src/bundler/FSInlineBundled.d.mts +0 -22
- package/types/src/bundler/adds/externals.d.mts +0 -1
- package/types/src/class/Console.d.mts +0 -71
- package/types/src/class/Derived.d.mts +0 -98
- package/types/src/class/Effect.d.mts +0 -216
- package/types/src/class/ListDerived.d.mts +0 -38
- package/types/src/class/Paths.d.mts +0 -69
- package/types/src/class/SafeExit.d.mts +0 -103
- package/types/src/class/WorkerMainThreadBundled.d.mts +0 -83
- package/types/src/common/Base64URLFromFile.d.mts +0 -16
- package/types/src/common/Dev.d.mts +0 -68
- package/types/src/common/DevBundled.d.mts +0 -3
- package/types/src/common/lazie.d.mts +0 -1
- package/types/src/doc/JSautoDOC.d.mts +0 -83
- package/types/src/function/GetRuntime.d.mts +0 -2
- package/types/src/function/TemplateLiteral.d.mts +0 -22
- package/types/src/function/TsToMjs.d.mts +0 -23
- package/types/src/types/IsListSignal.d.mts +0 -4
- package/types/src/types/ListArg.d.mts +0 -4
- package/types/src/types/Runtime.d.mts +0 -4
- package/types/src/types/VivthDevCodeBlockStringType.d.mts +0 -4
- /package/{types → generated/types}/src/bundler/adds/pluginVivthBundle.d.mts +0 -0
- /package/{types → generated/types}/src/class/WorkerResult.d.mts +0 -0
- /package/{types → generated/types}/src/common/EventNameSpace.d.mts +0 -0
- /package/{types → generated/types}/src/common/eventObjects.d.mts +0 -0
- /package/{types → generated/types}/src/common/keys.d.mts +0 -0
- /package/{types → generated/types}/src/doc/correctBeforeParse.d.mts +0 -0
- /package/{types → generated/types}/src/function/TrySync.d.mts +0 -0
- /package/{types → generated/types}/src/function/resolveErrorArray.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/AnyButUndefined.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/ExtnameType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpKeyType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpResultType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/MutationType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBFIFOReturn.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBReturn.d.mts +0 -0
- /package/src/{types → typehints}/AnyButUndefined.mjs +0 -0
- /package/src/{types → typehints}/ExtnameType.mjs +0 -0
- /package/src/{types → typehints}/LitExpKeyType.mjs +0 -0
- /package/src/{types → typehints}/MutationType.mjs +0 -0
- /package/src/{types → typehints}/QCBFIFOReturn.mjs +0 -0
- /package/src/{types → typehints}/QCBReturn.mjs +0 -0
package/src/class/FileSafe.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { writeFile, mkdir, copyFile, rename, rm,
|
|
3
|
+
import { writeFile, mkdir, copyFile, rename, rm, readFile, stat } from 'node:fs/promises';
|
|
4
4
|
import { dirname } from 'node:path';
|
|
5
|
-
import { constants } from 'node:fs';
|
|
6
5
|
|
|
7
6
|
import { TryAsync } from '../function/TryAsync.mjs';
|
|
7
|
+
import { Console } from './Console.mjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @description
|
|
@@ -14,29 +14,59 @@ export class FileSafe {
|
|
|
14
14
|
/**
|
|
15
15
|
* @description
|
|
16
16
|
* - method to safely detects whether filePaths exist;
|
|
17
|
-
* - uses fs/promises
|
|
17
|
+
* - uses `'node:fs/promises'.access` under the hood;
|
|
18
18
|
* - also returning promise of result & error as value;
|
|
19
19
|
* @param {string} filePath
|
|
20
|
-
* @returns {
|
|
20
|
+
* @returns {Promise<boolean>}
|
|
21
21
|
* @example
|
|
22
22
|
* import { join } from 'node:path';
|
|
23
|
-
* import { FileSafe
|
|
23
|
+
* import { FileSafe } from 'vivth/node';
|
|
24
|
+
* import { Paths } from 'vivth/neutral';
|
|
24
25
|
*
|
|
25
|
-
* const
|
|
26
|
+
* const isExist = await FileSafe.exist(
|
|
26
27
|
* join(Paths.root, '/some/path.mjs'),
|
|
27
28
|
* );
|
|
28
|
-
* if (!error) {
|
|
29
|
-
* // file exists
|
|
30
|
-
* } else {
|
|
31
|
-
* // file not exists
|
|
32
|
-
* }
|
|
33
29
|
*/
|
|
34
30
|
static exist = async (filePath) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
31
|
+
const [, error] = await TryAsync(async () => {
|
|
32
|
+
const stats = await stat(filePath);
|
|
33
|
+
// Optional: verification that it is a file, not a directory
|
|
34
|
+
return stats.isFile() || stats.isDirectory();
|
|
39
35
|
});
|
|
36
|
+
return !error;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @param { Parameters<writeFile>[1] } string
|
|
40
|
+
* @returns { string }
|
|
41
|
+
*/
|
|
42
|
+
static #normalize = (string) => {
|
|
43
|
+
return string.toString().replace(/\s+/, ' ');
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @param {Parameters<FileSafe.write>[0]} outFile
|
|
47
|
+
* @param {Parameters<FileSafe.write>[1]} content
|
|
48
|
+
* @param {Parameters<FileSafe.write>[2]} [options]
|
|
49
|
+
* @param {Parameters<FileSafe.write>[3]} [checkFuzySame]
|
|
50
|
+
* @returns {Promise<boolean>}
|
|
51
|
+
*/
|
|
52
|
+
static #validToOverWrite = async (outFile, content, options, checkFuzySame = true) => {
|
|
53
|
+
const [isExist, [isSame]] = await Promise.all([
|
|
54
|
+
FileSafe.exist(outFile.toString()),
|
|
55
|
+
TryAsync(async () => {
|
|
56
|
+
if (!checkFuzySame) {
|
|
57
|
+
// code
|
|
58
|
+
return (await readFile(outFile.toString(), options)) === content;
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
FileSafe.#normalize(await readFile(outFile.toString(), options)) ===
|
|
62
|
+
FileSafe.#normalize(content)
|
|
63
|
+
);
|
|
64
|
+
}),
|
|
65
|
+
]);
|
|
66
|
+
if (isExist && isSame) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
40
70
|
};
|
|
41
71
|
/**
|
|
42
72
|
* @description
|
|
@@ -45,10 +75,14 @@ export class FileSafe {
|
|
|
45
75
|
* @param {Parameters<writeFile>[0]} outFile
|
|
46
76
|
* @param {Parameters<writeFile>[1]} content
|
|
47
77
|
* @param {Parameters<writeFile>[2]} [options]
|
|
78
|
+
* @param {boolean} [checkFuzySame]
|
|
79
|
+
* - true: check while normalize consecutive whitespace into singel white space;
|
|
80
|
+
* - false(default): check absolute value;
|
|
48
81
|
* @returns {ReturnType<typeof TryAsync<void>>}
|
|
49
82
|
* @example
|
|
50
83
|
* import { join } from 'node:path';
|
|
51
|
-
* import { FileSafe
|
|
84
|
+
* import { FileSafe } from 'vivth/node';
|
|
85
|
+
* import { Paths } from 'vivth/neutral';
|
|
52
86
|
*
|
|
53
87
|
* const [, errorWrite] = await FileSafe.write(
|
|
54
88
|
* join(Paths.root, '/some/path.mjs'),
|
|
@@ -56,13 +90,24 @@ export class FileSafe {
|
|
|
56
90
|
* { encoding: 'utf-8' }
|
|
57
91
|
* );
|
|
58
92
|
*/
|
|
59
|
-
static write = async (outFile, content, options) => {
|
|
93
|
+
static write = async (outFile, content, options, checkFuzySame = true) => {
|
|
60
94
|
return await TryAsync(async () => {
|
|
61
95
|
const [, errorMkDir] = await FileSafe.mkdir(dirname(outFile.toString()));
|
|
62
96
|
if (errorMkDir) {
|
|
63
|
-
throw
|
|
97
|
+
throw `error mkdir, "${dirname(outFile.toString())}"`;
|
|
98
|
+
}
|
|
99
|
+
if (!(await FileSafe.#validToOverWrite(outFile, content, options, checkFuzySame))) {
|
|
100
|
+
Console.warn(
|
|
101
|
+
{
|
|
102
|
+
[FileSafe.name]: `write file '${outFile}' is canceled, old file are ${checkFuzySame ? 'almost ' : ''}identical`,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
now: true,
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
return;
|
|
64
109
|
}
|
|
65
|
-
return writeFile(outFile, content, options);
|
|
110
|
+
return await writeFile(outFile, content, options);
|
|
66
111
|
});
|
|
67
112
|
};
|
|
68
113
|
/**
|
|
@@ -75,7 +120,8 @@ export class FileSafe {
|
|
|
75
120
|
* @returns {ReturnType<typeof TryAsync<void>>}
|
|
76
121
|
* @example
|
|
77
122
|
* import { join } from 'node:path';
|
|
78
|
-
* import { FileSafe
|
|
123
|
+
* import { FileSafe } from 'vivth/node';
|
|
124
|
+
* import { Paths } from 'vivth/neutral';
|
|
79
125
|
*
|
|
80
126
|
* const [, errorWrite] = await FileSafe.copy(
|
|
81
127
|
* join(Paths.root, '/some/path.mjs'),
|
|
@@ -88,7 +134,7 @@ export class FileSafe {
|
|
|
88
134
|
const dest_ = destinationFile.toString();
|
|
89
135
|
const [, errorMkDir] = await FileSafe.mkdir(dirname(dest_));
|
|
90
136
|
if (errorMkDir) {
|
|
91
|
-
throw
|
|
137
|
+
throw `error mkdir, "${dirname(dest_)}"`;
|
|
92
138
|
}
|
|
93
139
|
return await copyFile(sourceFile, destinationFile, mode);
|
|
94
140
|
});
|
|
@@ -102,7 +148,8 @@ export class FileSafe {
|
|
|
102
148
|
* @returns {ReturnType<typeof TryAsync<void>>}
|
|
103
149
|
* @example
|
|
104
150
|
* import { join } from 'node:path';
|
|
105
|
-
* import { FileSafe
|
|
151
|
+
* import { FileSafe} from 'vivth/node';
|
|
152
|
+
* import { Paths } from 'vivth/neutral';
|
|
106
153
|
*
|
|
107
154
|
* const [, errorRename] = await FileSafe.rename(
|
|
108
155
|
* join(Paths.root, 'some/path'),
|
|
@@ -114,7 +161,7 @@ export class FileSafe {
|
|
|
114
161
|
const dest_ = newPath.toString();
|
|
115
162
|
const [, errorMkDir] = await FileSafe.mkdir(dirname(dest_));
|
|
116
163
|
if (errorMkDir) {
|
|
117
|
-
throw
|
|
164
|
+
throw `error mkdir, "${dirname(dest_)}"`;
|
|
118
165
|
}
|
|
119
166
|
return await rename(oldPath, newPath);
|
|
120
167
|
});
|
|
@@ -141,7 +188,8 @@ export class FileSafe {
|
|
|
141
188
|
* @returns {ReturnType<typeof TryAsync<string|undefined>>}
|
|
142
189
|
* @example
|
|
143
190
|
* import { join } from 'node:path';
|
|
144
|
-
* import { FileSafe
|
|
191
|
+
* import { FileSafe } from 'vivth/node';
|
|
192
|
+
* import { Paths } from 'vivth/neutral';
|
|
145
193
|
*
|
|
146
194
|
* const [str, errorMkDir] = await FileSafe.mkdir(join(Paths.root, '/some/path/example'));
|
|
147
195
|
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { TrySync } from '../function/TrySync.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - is collections of safe `.forEach` wrapper;
|
|
8
|
+
* >- via [TrySync](#trysync);
|
|
9
|
+
*/
|
|
10
|
+
export class ForEach {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
static #handler = (iter, handler) => {
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
const results = [];
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
iter.forEach((...args) => {
|
|
17
|
+
results.push(TrySync(() => handler(...args))[0]);
|
|
18
|
+
});
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
return results;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* - static method helper for `array` to be iterate safely;
|
|
25
|
+
* @template T, R
|
|
26
|
+
* @param {T[]} array
|
|
27
|
+
* @param {(value: T, index: number, array: T[]) => R} handler
|
|
28
|
+
* @returns {Array<ReturnType<typeof TrySync<R>>>}
|
|
29
|
+
* @example
|
|
30
|
+
* import { Foreach } from 'vivth/neutral';
|
|
31
|
+
*
|
|
32
|
+
* const arr = ['a','b'];
|
|
33
|
+
* ForEach(arr, (string, i, arr_)=>{
|
|
34
|
+
* // unsafe Code
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
static array(array, handler) {
|
|
38
|
+
return ForEach.#handler(array, handler);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description
|
|
43
|
+
* - static method helper for `set` to be iterate safely;
|
|
44
|
+
* @template T, R
|
|
45
|
+
* @param {Set<T>} set
|
|
46
|
+
* @param {(value: T, value2: T, set: Set<T>) => R} handler
|
|
47
|
+
* @returns {Array<ReturnType<typeof TrySync<R>>>}
|
|
48
|
+
* @example
|
|
49
|
+
* import { Foreach } from 'vivth/neutral';
|
|
50
|
+
*
|
|
51
|
+
* const set = new Set();
|
|
52
|
+
* ForEach(set, (value, value2, set_)=>{
|
|
53
|
+
* // unsafe Code
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
56
|
+
static set(set, handler) {
|
|
57
|
+
return ForEach.#handler(set, handler);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description
|
|
62
|
+
* - static method helper for `map` to be iterate safely;
|
|
63
|
+
* @template K, V, R
|
|
64
|
+
* @param {Map<K,V>} map
|
|
65
|
+
* @param {(value: V, key: K, map: Map<K,V>) => R} handler
|
|
66
|
+
* @returns {Array<ReturnType<typeof TrySync<R>>>}
|
|
67
|
+
* @example
|
|
68
|
+
* import { Foreach } from 'vivth/neutral';
|
|
69
|
+
*
|
|
70
|
+
* const map = new Map();
|
|
71
|
+
* ForEach(map, (value, key, map_)=>{
|
|
72
|
+
* // unsafe Code
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
static map(map, handler) {
|
|
76
|
+
return ForEach.#handler(map, handler);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
4
|
+
import { Console } from './Console.mjs';
|
|
5
|
+
import { Effect } from './Effect.mjs';
|
|
6
|
+
import { Signal } from './Signal.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* - this class extends `Signal`;
|
|
15
|
+
* - `ForSignal_instance.runCleanUp` still needs to be manually called, when cleaning up this instance;
|
|
16
|
+
* @template {any} TYPE
|
|
17
|
+
* @implements {VivthCleanup}
|
|
18
|
+
* @extends {Signal<Array<TYPE|undefined>>}
|
|
19
|
+
*/
|
|
20
|
+
export class ForSignal extends Signal {
|
|
21
|
+
/**
|
|
22
|
+
* @description
|
|
23
|
+
* @param {(
|
|
24
|
+
* this: ForSignal<TYPE>,
|
|
25
|
+
* arg:{
|
|
26
|
+
* index:number,
|
|
27
|
+
* value:{ value:TYPE, isValueDefined:true, }|
|
|
28
|
+
* { value:undefined, isValueDefined:false, },
|
|
29
|
+
* prev:{ prev:TYPE, isPrevDefined:true, }|
|
|
30
|
+
* { prev:undefined, isPrevDefined:false, },
|
|
31
|
+
* })=>void
|
|
32
|
+
* } loopCallback
|
|
33
|
+
* - the diffence of `current` and `prev` or `isValueDefined` and `isPrevDefined` can be used for sideEffect, such as;
|
|
34
|
+
* >- `adding/removing/modifiying` `childNode`s on a parent element;
|
|
35
|
+
* >- `adding/removing/modifiying` `Signal` instances;
|
|
36
|
+
* @param {()=>void} [additionalCleanUp]
|
|
37
|
+
* - additional callback to be run when runCleanUp is called;
|
|
38
|
+
* @example
|
|
39
|
+
* import { ForSignal } from 'vivth/neutral';
|
|
40
|
+
*
|
|
41
|
+
* const myLoop = new ForSignal(
|
|
42
|
+
* function ({ index, value: {value, isValueDefined}, prev:{ prev, isPrevDefined} }) {
|
|
43
|
+
* // code
|
|
44
|
+
* },
|
|
45
|
+
* () => {
|
|
46
|
+
* // additional cleanup code
|
|
47
|
+
* }
|
|
48
|
+
* )
|
|
49
|
+
* // myLoop.runCleanUp(); // need to be called manually when the instance are to out of scope;
|
|
50
|
+
*/
|
|
51
|
+
constructor(loopCallback, additionalCleanUp) {
|
|
52
|
+
super([]);
|
|
53
|
+
new Effect(async ({ subscribe, isLastCalled, removeEffect }) => {
|
|
54
|
+
const { value: currentValues, prev: prevValues = [] } = subscribe(this);
|
|
55
|
+
if (!(await isLastCalled())) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const length = Math.max(currentValues.length, prevValues?.length ?? 0);
|
|
59
|
+
const isCleanUpRun = this.#isCleanUpRun;
|
|
60
|
+
/**
|
|
61
|
+
* @type {Array<ReturnType<typeof TryAsync<void>>>}
|
|
62
|
+
*/
|
|
63
|
+
const promises = [];
|
|
64
|
+
for (let index = 0; index < length; index++) {
|
|
65
|
+
promises.push(
|
|
66
|
+
TryAsync(async () => {
|
|
67
|
+
const current = currentValues[index];
|
|
68
|
+
const prev = prevValues[index];
|
|
69
|
+
if (current === prev) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await loopCallback.call(this, {
|
|
74
|
+
index,
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
value: { value: current, isValueDefined: current !== undefined },
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
prev: { prev, isPrevDefined: prev !== undefined },
|
|
79
|
+
});
|
|
80
|
+
} catch (errorHandlingForSignal) {
|
|
81
|
+
Console.error({ errorHandlingForSignal, index });
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
await Promise.all(promises);
|
|
87
|
+
if (!isCleanUpRun) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* - the actual cleanup code;
|
|
92
|
+
*/
|
|
93
|
+
removeEffect();
|
|
94
|
+
this.remove.ref();
|
|
95
|
+
if (!additionalCleanUp) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
additionalCleanUp();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @type {boolean}
|
|
103
|
+
*/
|
|
104
|
+
#isCleanUpRun = false;
|
|
105
|
+
/**
|
|
106
|
+
* @description
|
|
107
|
+
* - need to be manually called when disposing/cleaning up this instance;
|
|
108
|
+
* @type {()=>Promise<void>}
|
|
109
|
+
* @override
|
|
110
|
+
*/
|
|
111
|
+
vivthCleanup = async () => {
|
|
112
|
+
this.#isCleanUpRun = true;
|
|
113
|
+
this.value = [];
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* - create getter setter in one place;
|
|
6
|
+
* @template {any} RET
|
|
7
|
+
* @template {((...any:any[])=>RET)} TG
|
|
8
|
+
* @template {((...any:any[])=>void)} TS
|
|
9
|
+
* @example
|
|
10
|
+
* import { GetterSetter } from 'vivth/neutral';
|
|
11
|
+
*
|
|
12
|
+
* const localA = new GetterSetter({
|
|
13
|
+
* get:() => {
|
|
14
|
+
* return localStorage.getItem('myAValue');
|
|
15
|
+
* },
|
|
16
|
+
* set:(newValue) => {
|
|
17
|
+
* return localStorage.setItem('myAValue', newValue);
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* localA.get(); // null;
|
|
21
|
+
* localA.set('my new value');
|
|
22
|
+
* localA.get(); // 'my new value'
|
|
23
|
+
*/
|
|
24
|
+
export class GetterSetter {
|
|
25
|
+
/**
|
|
26
|
+
* @param {{ get?: TG, set?: TS }} options
|
|
27
|
+
*/
|
|
28
|
+
constructor({ get, set }) {
|
|
29
|
+
this.get = get;
|
|
30
|
+
this.set = set;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @type {ConstructorParameters<typeof GetterSetter<RET,TG,TS>>[0]["get"]}
|
|
34
|
+
*/
|
|
35
|
+
get;
|
|
36
|
+
/**
|
|
37
|
+
* @type {ConstructorParameters<typeof GetterSetter<RET,TG,TS>>[0]["set"]}
|
|
38
|
+
*/
|
|
39
|
+
set;
|
|
40
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import prettier from 'prettier';
|
|
5
|
+
import stripJsonComments from 'strip-json-comments';
|
|
6
|
+
|
|
7
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
8
|
+
import { FileSafe } from './FileSafe.mjs';
|
|
9
|
+
import { Preferrence } from '../common/Preferrence.mjs';
|
|
10
|
+
import { Paths } from './Paths.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* - class helper to handle `.json` file;
|
|
15
|
+
* - this class assume, `Paths` already instantiated;
|
|
16
|
+
*/
|
|
17
|
+
export class JSONFileHandler {
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} path
|
|
20
|
+
* - `relative`(to `Paths.root`) OR `absolute`, both are accepted;
|
|
21
|
+
*/
|
|
22
|
+
constructor(path) {
|
|
23
|
+
this.#path = Paths.diskAbsolute(path);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @type {ConstructorParameters<typeof JSONFileHandler>[0]}
|
|
27
|
+
*/
|
|
28
|
+
#path;
|
|
29
|
+
/**
|
|
30
|
+
* @description
|
|
31
|
+
* @returns {ReturnType<typeof TryAsync<Object>>}
|
|
32
|
+
* @example
|
|
33
|
+
* import { JSONFileHandler } from "vivth/node";
|
|
34
|
+
*
|
|
35
|
+
* const packageJSONHandler = new JSONFileHandler('/package.json');
|
|
36
|
+
* const [content, error] = await packageJSONHandler.read();
|
|
37
|
+
*/
|
|
38
|
+
read = async () => {
|
|
39
|
+
return await TryAsync(async () => {
|
|
40
|
+
const strippedContent = stripJsonComments(
|
|
41
|
+
await readFile(this.#path, { encoding: Preferrence.encoding }),
|
|
42
|
+
);
|
|
43
|
+
return JSON.parse(strippedContent);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* @description
|
|
48
|
+
* @param {Object} newObj
|
|
49
|
+
* @return { ReturnType<typeof TryAsync<void>> }
|
|
50
|
+
* @example
|
|
51
|
+
* import { this.writeJSONFileHandler } from "vivth/node";
|
|
52
|
+
*
|
|
53
|
+
* const packageJSONHandler = new JSONFileHandler('/package.json');
|
|
54
|
+
* const [, error] = await packageJSONHandler.write({
|
|
55
|
+
* ...object,
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
write = async (newObj) => {
|
|
59
|
+
const pretified = await prettier.format(JSON.stringify(newObj), { parser: 'json-stringify' });
|
|
60
|
+
return await FileSafe.write(this.#path, pretified, {
|
|
61
|
+
encoding: Preferrence.encoding,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* @description
|
|
66
|
+
* @param {Object} object
|
|
67
|
+
* @return { ReturnType<typeof TryAsync<void>> }
|
|
68
|
+
* @example
|
|
69
|
+
* import { JSONFileHandler } from "vivth/node";
|
|
70
|
+
*
|
|
71
|
+
* const packageJSONHandler = new JSONFileHandler('/package.json');
|
|
72
|
+
* const [, error] = await packageJSONHandler.assign({
|
|
73
|
+
* ...object,
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
76
|
+
assign = async (object) => {
|
|
77
|
+
return await TryAsync(async () => {
|
|
78
|
+
const [jsonFileObject, errorReadJSONFileHandler] = await this.read();
|
|
79
|
+
if (errorReadJSONFileHandler) {
|
|
80
|
+
throw { errorReadJSONFileHandler };
|
|
81
|
+
}
|
|
82
|
+
Object.assign(jsonFileObject, object);
|
|
83
|
+
const [, errorWriteJSONFileHandler] = await this.write(jsonFileObject);
|
|
84
|
+
if (!errorWriteJSONFileHandler) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
throw { errorWriteJSONFileHandler };
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|