vivth 1.4.9 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6060 -2037
- package/README.src.md +22 -14
- package/bun.lock +154 -194
- package/dev/auto/.src.ignore +25 -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 +50 -14
- 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} +61 -84
- package/src/class/WorkerMainThread.mjs +103 -102
- 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 -134
- 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/Setup.mjs
CHANGED
|
@@ -4,6 +4,8 @@ import { SafeExit } from './SafeExit.mjs';
|
|
|
4
4
|
import { Paths } from './Paths.mjs';
|
|
5
5
|
import { WorkerMainThread } from './WorkerMainThread.mjs';
|
|
6
6
|
import { WorkerThread } from './WorkerThread.mjs';
|
|
7
|
+
import { EnvMode } from '../common/EnvMode.mjs';
|
|
8
|
+
import { Preferrence } from '../common/Preferrence.mjs';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @description
|
|
@@ -14,27 +16,16 @@ export class Setup {
|
|
|
14
16
|
* @description
|
|
15
17
|
* - proxy `SafeExit_instance` for Setup
|
|
16
18
|
* @example
|
|
17
|
-
* import { Setup
|
|
19
|
+
* import { Setup } from 'vivth/node';
|
|
18
20
|
*
|
|
19
|
-
* new Setup.safeExit(
|
|
20
|
-
* // eventNames are blank by default, you need to manually name them all;
|
|
21
|
-
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
22
|
-
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
23
|
-
* terminator : () => process.exit(0),
|
|
24
|
-
* listener : (eventName) => {
|
|
25
|
-
* process.once(eventName, function () {
|
|
26
|
-
* SafeExit.instance?.exiting.correction(true);
|
|
27
|
-
* Console.log(`safe exit via "${eventName}"`);
|
|
28
|
-
* });
|
|
29
|
-
* }
|
|
30
|
-
* });
|
|
21
|
+
* new Setup.safeExit('SIGINT', 'SIGTERM', ...eventNames);
|
|
31
22
|
*/
|
|
32
23
|
static safeExit = SafeExit;
|
|
33
24
|
/**
|
|
34
25
|
* @description
|
|
35
26
|
* - proxy `Paths_instance` for Setup;
|
|
36
27
|
* @example
|
|
37
|
-
* import { Setup } from 'vivth';
|
|
28
|
+
* import { Setup } from 'vivth/node';
|
|
38
29
|
*
|
|
39
30
|
* new Setup.paths({
|
|
40
31
|
* root: location.origin, // browser example
|
|
@@ -45,7 +36,7 @@ export class Setup {
|
|
|
45
36
|
* @description
|
|
46
37
|
* - proxy `WorkerMainThread_instance` for Setup;
|
|
47
38
|
* @example
|
|
48
|
-
* import { Setup } from 'vivth';
|
|
39
|
+
* import { Setup } from 'vivth/node';
|
|
49
40
|
* import { Worker } from 'node:worker_threads';
|
|
50
41
|
*
|
|
51
42
|
* Setup.workerMain({
|
|
@@ -64,7 +55,7 @@ export class Setup {
|
|
|
64
55
|
* - correct `parentPort` reference when needed;
|
|
65
56
|
* - export to create new reference to be use to create new WorkerThread instance;
|
|
66
57
|
* @example
|
|
67
|
-
* import { Setup } from 'vivth';
|
|
58
|
+
* import { Setup } from 'vivth/node';
|
|
68
59
|
* import { parentPort } from 'node:worker_threads';
|
|
69
60
|
*
|
|
70
61
|
* export const MyWorkerThreadRef = Setup.workerThread({parentPort});
|
|
@@ -72,4 +63,25 @@ export class Setup {
|
|
|
72
63
|
* // you need to call this method;
|
|
73
64
|
*/
|
|
74
65
|
static workerThread = WorkerThread.setup;
|
|
66
|
+
/**
|
|
67
|
+
* @description
|
|
68
|
+
* - setup envMode into `developement`('default') or `production`;
|
|
69
|
+
* @example
|
|
70
|
+
* import { Setup } from 'vivth/node';
|
|
71
|
+
*
|
|
72
|
+
* Setup.enforceEnvMode('prod');
|
|
73
|
+
*
|
|
74
|
+
* // default behaviour, technically only need to be call for reactive functionality;
|
|
75
|
+
* Setup.enforceEnvMode('dev');
|
|
76
|
+
*/
|
|
77
|
+
static enforceEnvMode = EnvMode.enforce;
|
|
78
|
+
/**
|
|
79
|
+
* @description
|
|
80
|
+
* - setup `vivth `preffered encoding;
|
|
81
|
+
* @example
|
|
82
|
+
* import { Setup } from 'vivth/node';
|
|
83
|
+
*
|
|
84
|
+
* Setup.preferrence({ encoding: 'utf-8' });
|
|
85
|
+
*/
|
|
86
|
+
static preferrence = Preferrence.setup;
|
|
75
87
|
}
|
package/src/class/Signal.mjs
CHANGED
|
@@ -6,6 +6,11 @@ import { TryAsync } from '../function/TryAsync.mjs';
|
|
|
6
6
|
import { TrySync } from '../function/TrySync.mjs';
|
|
7
7
|
import { Console } from './Console.mjs';
|
|
8
8
|
import { Effect, mapOfEffects } from './Effect.mjs';
|
|
9
|
+
import { DataLog } from './DataLog.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef { import('../typehints/VivthCleanup.mjs').VivthCleanup } VivthCleanup
|
|
13
|
+
*/
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* @type {Set<Signal<any>>}
|
|
@@ -16,21 +21,33 @@ export const setOFSignals = new Set();
|
|
|
16
21
|
* @description
|
|
17
22
|
* - a class for creating effect to signals;
|
|
18
23
|
* @template VALUE
|
|
24
|
+
* @implements {VivthCleanup}
|
|
19
25
|
*/
|
|
20
26
|
export class Signal {
|
|
27
|
+
vivthCleanup = async () => {
|
|
28
|
+
this.remove.ref();
|
|
29
|
+
};
|
|
21
30
|
/**
|
|
22
31
|
* @description
|
|
23
32
|
* - create a `Signal`;
|
|
24
33
|
* @param {VALUE} value
|
|
34
|
+
* @param {(data:DataLog<VALUE>)=>void} [performanceChangesReport]
|
|
35
|
+
* - callback independent from effect;
|
|
36
|
+
* >- it will always be called when there's value change;
|
|
25
37
|
* @example
|
|
26
|
-
* import { Signal, Effect } from
|
|
38
|
+
* import { Signal, Effect } from 'vivth/neutral';
|
|
27
39
|
*
|
|
28
40
|
* const count = new Signal(0);
|
|
29
41
|
*/
|
|
30
|
-
constructor(value) {
|
|
42
|
+
constructor(value, performanceChangesReport = undefined) {
|
|
31
43
|
this.#value = value;
|
|
44
|
+
this.#performanceChangesReport = performanceChangesReport;
|
|
32
45
|
setOFSignals.add(this);
|
|
33
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @type {ConstructorParameters<typeof Signal<VALUE>>[1]}
|
|
49
|
+
*/
|
|
50
|
+
#performanceChangesReport;
|
|
34
51
|
/**
|
|
35
52
|
* @description
|
|
36
53
|
* - subsrcibers reference of this instance;
|
|
@@ -48,9 +65,10 @@ export class Signal {
|
|
|
48
65
|
* @description
|
|
49
66
|
* - manually notify on non primitive value or value that have depths;
|
|
50
67
|
* @param {(options:{signalInstance:Signal<VALUE>})=>Promise<void>} [callback]
|
|
51
|
-
* @
|
|
68
|
+
* @param {(error:Error|undefined)=>Promise<void>} [afterCompletion]
|
|
69
|
+
* @returns {Promise<void>}
|
|
52
70
|
* @example
|
|
53
|
-
* import { Signal } from 'vivth';
|
|
71
|
+
* import { Signal } from 'vivth/neutral';
|
|
54
72
|
*
|
|
55
73
|
* // for deep signal like array or object you can:
|
|
56
74
|
* const arraySignal = new Signal([1,2]);
|
|
@@ -64,32 +82,41 @@ export class Signal {
|
|
|
64
82
|
* signalInstance.value['d'] = 'testd';
|
|
65
83
|
* });
|
|
66
84
|
*/
|
|
67
|
-
notify: (callback = undefined) => {
|
|
85
|
+
notify: async (callback = undefined, afterCompletion = undefined) => {
|
|
86
|
+
if (this.#performanceChangesReport) {
|
|
87
|
+
this.#performanceChangesReport(new DataLog(this.#value));
|
|
88
|
+
}
|
|
68
89
|
if (callback === undefined) {
|
|
69
|
-
Signal.#notify(this);
|
|
90
|
+
await Signal.#notify(this, afterCompletion);
|
|
70
91
|
return;
|
|
71
92
|
}
|
|
72
|
-
TryAsync(async () => {
|
|
93
|
+
const [, errorRunningCallback] = await TryAsync(async () => {
|
|
73
94
|
await callback({ signalInstance: this });
|
|
74
|
-
}).then(([, error]) => {
|
|
75
|
-
if (error) {
|
|
76
|
-
Console.error({ message: 'unable to run callback', callback, error });
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
Signal.#notify(this);
|
|
80
95
|
});
|
|
96
|
+
if (errorRunningCallback) {
|
|
97
|
+
Console.error({ errorRunningCallback });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
await Signal.#notify(this, afterCompletion);
|
|
81
101
|
},
|
|
82
102
|
}));
|
|
83
103
|
/**
|
|
84
104
|
* @param {Signal<any>} signalInstance
|
|
105
|
+
* @param {(error:Error|undefined)=>void} [afterCompletion]
|
|
106
|
+
* @returns {Promise<void>}
|
|
85
107
|
*/
|
|
86
|
-
static #notify = (
|
|
87
|
-
|
|
108
|
+
static #notify = async (
|
|
109
|
+
signalInstance,
|
|
110
|
+
afterCompletion = async (error) => {
|
|
111
|
+
if (error === undefined) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
Console.error(error);
|
|
115
|
+
},
|
|
116
|
+
) => {
|
|
117
|
+
const [, errorRunningWalkThrough] = TrySync(() => {
|
|
88
118
|
WalkThrough.set(signalInstance.subscribers.setOf, (effectInstance) => {
|
|
89
|
-
if (
|
|
90
|
-
//
|
|
91
|
-
!mapOfEffects.has(effectInstance)
|
|
92
|
-
) {
|
|
119
|
+
if (!mapOfEffects.has(effectInstance)) {
|
|
93
120
|
effectInstance.options.removeSignal(signalInstance);
|
|
94
121
|
return;
|
|
95
122
|
}
|
|
@@ -99,10 +126,7 @@ export class Signal {
|
|
|
99
126
|
effectInstance.run();
|
|
100
127
|
});
|
|
101
128
|
});
|
|
102
|
-
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
Console.error(error);
|
|
129
|
+
afterCompletion(errorRunningWalkThrough);
|
|
106
130
|
};
|
|
107
131
|
/**
|
|
108
132
|
* @description
|
|
@@ -147,7 +171,6 @@ export class Signal {
|
|
|
147
171
|
setOFSignals.delete(this);
|
|
148
172
|
},
|
|
149
173
|
}));
|
|
150
|
-
|
|
151
174
|
/**
|
|
152
175
|
* @type {VALUE|undefined}
|
|
153
176
|
*/
|
|
@@ -169,7 +192,7 @@ export class Signal {
|
|
|
169
192
|
* - value after change;
|
|
170
193
|
* @returns {VALUE}
|
|
171
194
|
* @example
|
|
172
|
-
* import { Signal, Effect, Derived } from
|
|
195
|
+
* import { Signal, Effect, Derived } from 'vivth/neutral';
|
|
173
196
|
*
|
|
174
197
|
* const count = new Signal(0);
|
|
175
198
|
* count.value; // not reactive
|
|
@@ -177,7 +200,7 @@ export class Signal {
|
|
|
177
200
|
* new Effect(async ({ subscribe }) =>{
|
|
178
201
|
* const countValue = subscribe(count).value; // reactive
|
|
179
202
|
* })
|
|
180
|
-
* const oneMoreThanCount = new Derived(async ({ subscribe })
|
|
203
|
+
* const oneMoreThanCount = new Derived(async function({ subscribe }){
|
|
181
204
|
* return subscribe(count).value + 1; // reactive
|
|
182
205
|
* })
|
|
183
206
|
*/
|
|
@@ -189,7 +212,7 @@ export class Signal {
|
|
|
189
212
|
* - assign new value then automatically notify all subscribers;
|
|
190
213
|
* @type {VALUE}
|
|
191
214
|
* @example
|
|
192
|
-
* import { Signal } from
|
|
215
|
+
* import { Signal } from 'vivth/neutral';
|
|
193
216
|
*
|
|
194
217
|
* const count = new Signal(0);
|
|
195
218
|
* count.value++;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { ForInSync } from '../function/ForInSync.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* - class helper for creating Collection of `Signals` for Object of Signals to be subscribed to(on `Effect`/`Derived`) collectively as signals;
|
|
12
|
+
* >- uses as `Facade` Pattern;
|
|
13
|
+
* @template {Record<string, import('./Signal.mjs').Signal<any>>} SIGNALS
|
|
14
|
+
* @implements {VivthCleanup}
|
|
15
|
+
*/
|
|
16
|
+
export class SignalCollection {
|
|
17
|
+
vivthCleanup = async () => {
|
|
18
|
+
this.forInSignals((_key, signal) => {
|
|
19
|
+
signal.remove.ref();
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* - creates instance of `SignalCollection`, by referencing to named Signal;
|
|
25
|
+
* @param {SIGNALS} signalsObject
|
|
26
|
+
* @example
|
|
27
|
+
* import { Signal, Derived, SignalCollection } from 'vivth/neutral';
|
|
28
|
+
*
|
|
29
|
+
* const a = new Signal('a');
|
|
30
|
+
* const b = new Signal('b');
|
|
31
|
+
* const c = new Derived(async ({ subscribe }) => {
|
|
32
|
+
* return `${subscribe(b).value}_b`;
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const f = new SignalCollection({ a, c });
|
|
36
|
+
*/
|
|
37
|
+
constructor(signalsObject) {
|
|
38
|
+
this.#signals = signalsObject;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @type {SIGNALS}
|
|
42
|
+
*/
|
|
43
|
+
#signals;
|
|
44
|
+
/**
|
|
45
|
+
* @description
|
|
46
|
+
* - accessor for signals, to be subscribed to;
|
|
47
|
+
* @param {import('./Effect.mjs').Effect["options"]["subscribe"]} [subscribe]
|
|
48
|
+
* @returns {SIGNALS}
|
|
49
|
+
* @example
|
|
50
|
+
* import { Signal, Derived, Effect, SignalCollection } from 'vivth/neutral';
|
|
51
|
+
*
|
|
52
|
+
* const a = new Signal('a');
|
|
53
|
+
* const b = new Signal('b');
|
|
54
|
+
* const c = new Derived(async ({ subscribe }) => {
|
|
55
|
+
* return `${subscribe(b).value}_b`;
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* const f = new SignalCollection({ a, c });
|
|
59
|
+
*
|
|
60
|
+
* new Effect(async ({ subscribe, isLastCalled }) => {
|
|
61
|
+
* const {
|
|
62
|
+
* a: { value: aa }, // aa is safely desctructured and auto subscribed
|
|
63
|
+
* c: { value: cc }, // cc is safely desctructured and auto subscribed
|
|
64
|
+
* } = f.signals(subscribe);
|
|
65
|
+
* if(!await isLastCalled(100)) {
|
|
66
|
+
* return; // impertaive debounce
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* const d = new Derived(async function({ subscribe, isLastCalled }) {
|
|
71
|
+
* const {
|
|
72
|
+
* a: { value: aa }, // aa is safely desctructured and auto subscribed
|
|
73
|
+
* c: { value: cc }, // cc is safely desctructured and auto subscribed
|
|
74
|
+
* } = f.signals(subscribe);
|
|
75
|
+
* if(!await isLastCalled(100)) {
|
|
76
|
+
* return this.dontUpdate; // impertaive debounce
|
|
77
|
+
* }
|
|
78
|
+
* // return something;
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
81
|
+
signals = (subscribe = undefined) => {
|
|
82
|
+
const signals = this.#signals;
|
|
83
|
+
if (subscribe) {
|
|
84
|
+
ForInSync(signals, (_key, signal) => {
|
|
85
|
+
subscribe(signal);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return signals;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @description
|
|
92
|
+
* - is looping synchronously;
|
|
93
|
+
* >- will not await any async block;
|
|
94
|
+
* - use for operation that doesn't need the value:
|
|
95
|
+
* >- unsub from the signal;
|
|
96
|
+
* @template {keyof SIGNALS} K
|
|
97
|
+
* @param {(key: K,
|
|
98
|
+
* signal: SIGNALS[K]
|
|
99
|
+
* )=>void} callback
|
|
100
|
+
* @returns {void}
|
|
101
|
+
* @example
|
|
102
|
+
* import { Signal, Derived, Effect, SignalCollection } from 'vivth/neutral';
|
|
103
|
+
*
|
|
104
|
+
* const a = new Signal('a');
|
|
105
|
+
* const b = new Signal('b');
|
|
106
|
+
* const c = new Derived(async ({ subscribe }) => {
|
|
107
|
+
* return `${subscribe(b).value}_b`;
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* const f = new SignalCollection({ a, c });
|
|
111
|
+
*
|
|
112
|
+
* f.forInSignals((key, signal)=>{
|
|
113
|
+
* // code
|
|
114
|
+
* })
|
|
115
|
+
*/
|
|
116
|
+
forInSignals(callback) {
|
|
117
|
+
ForInSync(this.#signals, (key, signal) => {
|
|
118
|
+
callback(
|
|
119
|
+
/**
|
|
120
|
+
* @type {K}
|
|
121
|
+
*/
|
|
122
|
+
(key),
|
|
123
|
+
/**
|
|
124
|
+
* @type {SIGNALS[K]}
|
|
125
|
+
*/
|
|
126
|
+
(signal),
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -27,7 +27,7 @@ export class WalkThrough {
|
|
|
27
27
|
* @param {(value:VAL)=>void} callback
|
|
28
28
|
* @returns {void}
|
|
29
29
|
* @example
|
|
30
|
-
* import { WalkThrough } from 'vivth';
|
|
30
|
+
* import { WalkThrough } from 'vivth/neutral';
|
|
31
31
|
*
|
|
32
32
|
* WalkThrough.set(setOfSomething, (value) => {
|
|
33
33
|
* // code
|
|
@@ -35,7 +35,7 @@ export class WalkThrough {
|
|
|
35
35
|
*/
|
|
36
36
|
static set(setInstance, callback) {
|
|
37
37
|
WalkThrough.#handler(setInstance.values(), callback);
|
|
38
|
-
}
|
|
38
|
+
}
|
|
39
39
|
/**
|
|
40
40
|
* @description
|
|
41
41
|
* - method helper to WalkThrough `Map`;
|
|
@@ -44,7 +44,7 @@ export class WalkThrough {
|
|
|
44
44
|
* @param {(res:[key: KEY, value: VAL]) => void} callback
|
|
45
45
|
* @returns {void}
|
|
46
46
|
* @example
|
|
47
|
-
* import { WalkThrough } from 'vivth';
|
|
47
|
+
* import { WalkThrough } from 'vivth/neutral';
|
|
48
48
|
*
|
|
49
49
|
* WalkThrough.map(mapOfSomething, ([key, value]) => {
|
|
50
50
|
* // code
|
|
@@ -52,7 +52,7 @@ export class WalkThrough {
|
|
|
52
52
|
*/
|
|
53
53
|
static map(mapInstance, callback) {
|
|
54
54
|
WalkThrough.#handler(mapInstance.entries(), callback);
|
|
55
|
-
}
|
|
55
|
+
}
|
|
56
56
|
/**
|
|
57
57
|
* @description
|
|
58
58
|
* - method helper to WalkThrough `Array`;
|
|
@@ -61,7 +61,7 @@ export class WalkThrough {
|
|
|
61
61
|
* @param {(res:[value: VAL, index: number]) => void} callback
|
|
62
62
|
* @returns {void}
|
|
63
63
|
* @example
|
|
64
|
-
* import { WalkThrough } from 'vivth';
|
|
64
|
+
* import { WalkThrough } from 'vivth/neutral';
|
|
65
65
|
*
|
|
66
66
|
* WalkThrough.array(arrayOfSomething, ([value, index]) => {
|
|
67
67
|
* // code
|
|
@@ -69,22 +69,5 @@ export class WalkThrough {
|
|
|
69
69
|
*/
|
|
70
70
|
static array(arrayInstance, callback) {
|
|
71
71
|
WalkThrough.#handler(arrayInstance.values(), callback);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @description
|
|
75
|
-
* - method helper to WalkThrough `Generator`;
|
|
76
|
-
* @template T
|
|
77
|
-
* @param {Generator<T, any, any>} generatorInstance
|
|
78
|
-
* @param {(value: T) => void} callback
|
|
79
|
-
* @returns {void}
|
|
80
|
-
* @example
|
|
81
|
-
* import { WalkThrough } from 'vivth';
|
|
82
|
-
*
|
|
83
|
-
* WalkThrough.generator(generatorOfSomething, (value) => {
|
|
84
|
-
* // code
|
|
85
|
-
* })
|
|
86
|
-
*/
|
|
87
|
-
static generator(generatorInstance, callback) {
|
|
88
|
-
WalkThrough.#handler(generatorInstance, callback);
|
|
89
|
-
};
|
|
72
|
+
}
|
|
90
73
|
}
|
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PathFSFile } from '../bundler/adds/PathFSFile.mjs';
|
|
4
|
+
import { FSasar } from '../bundler/FSasar.mjs';
|
|
4
5
|
import { Base64URL } from '../common/Base64URL.mjs';
|
|
5
|
-
import {
|
|
6
|
+
import { Preferrence } from '../common/Preferrence.mjs';
|
|
6
7
|
import { GetRuntime } from '../function/GetRuntime.mjs';
|
|
7
8
|
import { Tries } from '../function/Tries.mjs';
|
|
8
9
|
import { Console } from './Console.mjs';
|
|
9
10
|
import { Derived } from './Derived.mjs';
|
|
10
11
|
import { Effect } from './Effect.mjs';
|
|
11
|
-
import { Paths } from './Paths.mjs';
|
|
12
|
-
import { SafeExit } from './SafeExit.mjs';
|
|
13
12
|
import { Signal } from './Signal.mjs';
|
|
13
|
+
import { closeWorkerThreadEventObject } from '../common/eventObjects.mjs';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @template POST
|
|
22
|
-
* @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
|
|
16
|
+
* it supposed to be able to call on browser too
|
|
17
|
+
* ```js
|
|
18
|
+
* import { SafeExit } from './SafeExit.mjs';
|
|
19
|
+
* ```
|
|
20
|
+
* need to add cleaner for SafeExit.instance?.addCallback
|
|
23
21
|
*/
|
|
22
|
+
|
|
24
23
|
/**
|
|
25
|
-
* @typedef {import('../
|
|
24
|
+
* @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
|
|
26
25
|
*/
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* @template {WorkerThread<any, any>} WT
|
|
29
|
+
* @implements {VivthCleanup}
|
|
30
30
|
*/
|
|
31
31
|
export class WorkerMainThread {
|
|
32
|
+
/**
|
|
33
|
+
* @template POST
|
|
34
|
+
* @typedef {import('./WorkerResult.mjs').WorkerResult<POST>} WorkerResult
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* @template RECEIVE
|
|
38
|
+
* @template POST
|
|
39
|
+
* @typedef {import('./WorkerThread.mjs').WorkerThread<RECEIVE, POST>} WorkerThread
|
|
40
|
+
*/
|
|
32
41
|
/**
|
|
33
42
|
* @type {boolean}
|
|
34
43
|
*/
|
|
@@ -39,9 +48,6 @@ export class WorkerMainThread {
|
|
|
39
48
|
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
40
49
|
*/
|
|
41
50
|
static setup = ({ workerClass, pathValidator }) => {
|
|
42
|
-
if (Paths.root === undefined) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
51
|
if (WorkerMainThread.#isRegistered) {
|
|
46
52
|
Console.warn({ message: 'WorkerMainThread.setup, can only be called once' });
|
|
47
53
|
return;
|
|
@@ -63,17 +69,8 @@ export class WorkerMainThread {
|
|
|
63
69
|
type: 'module',
|
|
64
70
|
});
|
|
65
71
|
/**
|
|
66
|
-
* @
|
|
67
|
-
* @param {
|
|
68
|
-
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
69
|
-
* @returns {WorkerMainThread<WT>}
|
|
70
|
-
*/
|
|
71
|
-
static newVivthWorker(handler, options = {}) {
|
|
72
|
-
return new WorkerMainThread(handler, options);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
76
|
-
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
|
|
72
|
+
* @param {PathFSFile} handler
|
|
73
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} options
|
|
77
74
|
*/
|
|
78
75
|
constructor(handler, options = {}) {
|
|
79
76
|
/**
|
|
@@ -83,7 +80,7 @@ export class WorkerMainThread {
|
|
|
83
80
|
const listener = (ev) => {
|
|
84
81
|
this.#proxyReceiver.value = ev;
|
|
85
82
|
};
|
|
86
|
-
WorkerMainThread.#workerFilehandler(handler, options, this, listener);
|
|
83
|
+
WorkerMainThread.#workerFilehandler(handler.path, options, this, listener);
|
|
87
84
|
}
|
|
88
85
|
/**
|
|
89
86
|
* @type {import('./Signal.mjs').Signal<import('./WorkerResult.mjs').WorkerResult<WT["POST"]>|MessageEvent<import('./WorkerResult.mjs').WorkerResult<WT["POST"]>>>}
|
|
@@ -100,83 +97,62 @@ export class WorkerMainThread {
|
|
|
100
97
|
* @returns {Promise<void>}
|
|
101
98
|
*/
|
|
102
99
|
static async #workerFilehandler(handler, options, worker, listener) {
|
|
103
|
-
let resolvedPath;
|
|
104
100
|
WorkerMainThread.#options.eval = true;
|
|
105
|
-
resolvedPath =
|
|
101
|
+
const resolvedPath =
|
|
102
|
+
(await FSasar.file(PathFSFile.vivthFile(handler)))?.toString(Preferrence.encoding) ?? '';
|
|
106
103
|
const runtime = GetRuntime();
|
|
107
104
|
const workerClass = WorkerMainThread.workerClass;
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
!workerClass
|
|
111
|
-
) {
|
|
112
|
-
Console.error('invalid `Worker` inputed to `WorkerMainThread`;');
|
|
105
|
+
if (!workerClass) {
|
|
106
|
+
Console.error('invalid `Worker` inputed to `WorkerMainThread`;', { now: true });
|
|
113
107
|
return;
|
|
114
108
|
}
|
|
115
|
-
const [, errorCreatingWorker] = await Tries({
|
|
109
|
+
const [[key], errorCreatingWorker] = await Tries({
|
|
116
110
|
browser: async () => {
|
|
117
111
|
if (runtime !== 'browser') {
|
|
118
|
-
throw
|
|
112
|
+
throw 'not a browser';
|
|
119
113
|
}
|
|
120
|
-
let worker_;
|
|
121
114
|
const inlineURL = Base64URL(handler, 'application/javascript', btoa);
|
|
122
|
-
worker_ = worker.#worker.value = new workerClass(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
...options,
|
|
127
|
-
...WorkerMainThread.#options,
|
|
128
|
-
}
|
|
129
|
-
);
|
|
115
|
+
const worker_ = (worker.#worker.value = new workerClass(inlineURL, {
|
|
116
|
+
...options,
|
|
117
|
+
...WorkerMainThread.#options,
|
|
118
|
+
}));
|
|
130
119
|
if ('onmessage' in worker_ === false) {
|
|
131
|
-
throw
|
|
120
|
+
throw 'not a browser';
|
|
132
121
|
}
|
|
133
122
|
worker_.onmessage = listener;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
}
|
|
123
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
124
|
+
// worker_.onmessage = null;
|
|
125
|
+
// });
|
|
139
126
|
},
|
|
140
127
|
nonBrowser: async () => {
|
|
141
|
-
const worker_ = (worker.#worker.value = new workerClass(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
...options,
|
|
146
|
-
...WorkerMainThread.#options,
|
|
147
|
-
}
|
|
148
|
-
));
|
|
128
|
+
const worker_ = (worker.#worker.value = new workerClass(resolvedPath, {
|
|
129
|
+
...options,
|
|
130
|
+
...WorkerMainThread.#options,
|
|
131
|
+
}));
|
|
149
132
|
if ('addEventListener' in worker_) {
|
|
150
133
|
worker_.addEventListener('message', listener);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
134
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
135
|
+
// worker_.removeEventListener('message', listener);
|
|
136
|
+
// });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if ('addListener' in worker_) {
|
|
157
140
|
worker_.addListener('message', listener);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
throw new Error('not a standard non browser');
|
|
141
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
142
|
+
// worker_.removeListener('message', listener);
|
|
143
|
+
// });
|
|
144
|
+
return;
|
|
165
145
|
}
|
|
146
|
+
throw 'not a standard non browser';
|
|
166
147
|
},
|
|
167
148
|
});
|
|
168
|
-
if (
|
|
169
|
-
Console.error(errorCreatingWorker);
|
|
149
|
+
if (!key) {
|
|
150
|
+
Console.error({ errorCreatingWorker }, { now: true });
|
|
170
151
|
return;
|
|
171
152
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
worker.#worker.value.postMessage(closeWorkerThreadEventObject, []);
|
|
176
|
-
}
|
|
177
|
-
await worker.terminate();
|
|
178
|
-
});
|
|
179
|
-
}
|
|
153
|
+
// SafeExit.instance?.addCallback(async () => {
|
|
154
|
+
// worker.terminate();
|
|
155
|
+
// });
|
|
180
156
|
}
|
|
181
157
|
/**
|
|
182
158
|
* lazyly generated because node version need to await
|
|
@@ -197,9 +173,10 @@ export class WorkerMainThread {
|
|
|
197
173
|
worker.postMessage(postData, []);
|
|
198
174
|
});
|
|
199
175
|
/**
|
|
200
|
-
* @return {void}
|
|
176
|
+
* @return {Promise<void>}
|
|
201
177
|
*/
|
|
202
|
-
|
|
178
|
+
vivthCleanup = async () => {
|
|
179
|
+
this.postMessage(closeWorkerThreadEventObject);
|
|
203
180
|
/**
|
|
204
181
|
* this is more for browser, as most of this are automatically cleaned with `SafeExit`;
|
|
205
182
|
*/
|