akanjs 3.0.0-beta.20 → 3.0.0-beta.21
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.ko.md +0 -1
- package/README.md +0 -1
- package/base/baseEnv.ts +40 -3
- package/client/cookie.ts +56 -20
- package/client/device.ts +47 -95
- package/client/frameConfig.ts +2 -2
- package/client/native.ts +44 -0
- package/client/router.ts +11 -1
- package/client/rscNavigation.ts +5 -0
- package/client/storage.ts +68 -39
- package/fetch/client/fetchClient.ts +13 -4
- package/index.ts +47 -46
- package/package.json +6 -87
- package/server/devtools/signalSerializer.ts +1 -2
- package/server/hmr/devHmrController.ts +29 -11
- package/server/resolver/signal.resolver.ts +1 -10
- package/server/routeTreeBuilder.ts +8 -11
- package/server/routing/apiRouter.ts +15 -2
- package/server/rscClient.tsx +1 -2
- package/server/ssrFromRscRenderer.tsx +2 -0
- package/server/webRouter.ts +1 -0
- package/signal/CrossSiteGuard.ts +34 -2
- package/signal/endpoint.ts +12 -7
- package/signal/endpointInfo.ts +13 -0
- package/signal/internal.ts +9 -5
- package/signal/serializer/fetch.serializer.ts +6 -3
- package/signal/slice.ts +34 -24
- package/store/baseSt.ts +0 -1
- package/store/storeInstance.ts +29 -17
- package/types/client/cookie.d.ts +6 -4
- package/types/client/device.d.ts +7 -10
- package/types/client/native.d.ts +26 -0
- package/types/client/rscNavigation.d.ts +4 -0
- package/types/client/storage.d.ts +8 -1
- package/types/index.d.ts +48 -44
- package/types/server/hmr/devHmrController.d.ts +2 -1
- package/types/server/resolver/signal.resolver.d.ts +0 -1
- package/types/server/rscClient.d.ts +0 -3
- package/types/signal/CrossSiteGuard.d.ts +7 -2
- package/types/signal/endpoint.d.ts +1 -1
- package/types/signal/endpointInfo.d.ts +3 -0
- package/types/signal/slice.d.ts +3 -2
- package/types/store/baseSt.d.ts +0 -13
- package/types/vendor/@akanjs/native/packages/cli/src/api.d.ts +182 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/build.d.ts +28 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/compat.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/dev.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/doctor.d.ts +37 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/plugin.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/signing.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/test.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/toolchain.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/commands/update.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/config.d.ts +278 -0
- package/types/vendor/@akanjs/native/packages/cli/src/index.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/acl.d.ts +21 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/apilevel.d.ts +40 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/apk.d.ts +36 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/args.d.ts +9 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/boot.d.ts +32 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/chrome.d.ts +6 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/codegen.d.ts +94 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/compat.d.ts +49 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/configkeys.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/csp.d.ts +51 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/env.d.ts +44 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/exec.d.ts +31 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/googleservices.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/hmr.d.ts +120 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/html.d.ts +20 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/icons.d.ts +44 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/image.d.ts +21 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/iossigning.d.ts +81 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/launch.d.ts +51 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/log.d.ts +42 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/manifestmerge.d.ts +18 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/maven.d.ts +97 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/names.d.ts +45 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.d.ts +67 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/nativeconfig.d.ts +11 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/permissions.d.ts +10 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/plist.d.ts +11 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/png.d.ts +11 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/prepare.d.ts +138 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/privacy.d.ts +13 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +208 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/root.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/routes.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/serve.d.ts +17 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/signing.d.ts +14 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/spec.d.ts +96 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/toolchains.d.ts +150 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +77 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/vectors.d.ts +13 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/xml.d.ts +13 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/android.d.ts +57 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/desktop.d.ts +40 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/index.d.ts +14 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/ios.d.ts +44 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/linux.d.ts +6 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/macos.d.ts +7 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/targets.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/web-run.d.ts +15 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms/windows.d.ts +8 -0
- package/types/vendor/@akanjs/native/packages/cli/src/platforms.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/cli/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/core/src/acl.d.ts +97 -0
- package/types/vendor/@akanjs/native/packages/core/src/boot.d.ts +66 -0
- package/types/vendor/@akanjs/native/packages/core/src/contract.d.ts +35 -0
- package/types/vendor/@akanjs/native/packages/core/src/errors.d.ts +27 -0
- package/types/vendor/@akanjs/native/packages/core/src/files.d.ts +23 -0
- package/types/vendor/@akanjs/native/packages/core/src/index.d.ts +14 -0
- package/types/vendor/@akanjs/native/packages/core/src/kernel.d.ts +112 -0
- package/types/vendor/@akanjs/native/packages/core/src/live.d.ts +12 -0
- package/types/vendor/@akanjs/native/packages/core/src/mime.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/core/src/plugin.d.ts +71 -0
- package/types/vendor/@akanjs/native/packages/core/src/protocol.d.ts +109 -0
- package/types/vendor/@akanjs/native/packages/core/src/runtime.d.ts +66 -0
- package/types/vendor/@akanjs/native/packages/core/src/state.d.ts +28 -0
- package/types/vendor/@akanjs/native/packages/core/src/testing.d.ts +41 -0
- package/types/vendor/@akanjs/native/packages/core/src/version.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/core/src/veto.d.ts +17 -0
- package/types/vendor/@akanjs/native/packages/core/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/deeplinks.d.ts +24 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/delta.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/dispatcher.d.ts +95 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/ffi.d.ts +144 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/host.d.ts +11 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/lifecycle.d.ts +40 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/main.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/page-veto.d.ts +17 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/paths.d.ts +25 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +179 -0
- package/types/vendor/@akanjs/native/packages/react/src/index.d.ts +8 -0
- package/types/vendor/@akanjs/native/packages/react/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/accessibility/src/announce.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/accessibility/src/index.d.ts +47 -0
- package/types/vendor/@akanjs/native/plugins/accessibility/src/web.d.ts +4 -0
- package/types/vendor/@akanjs/native/plugins/accessibility/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/app/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/app/src/index.d.ts +66 -0
- package/types/vendor/@akanjs/native/plugins/app/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/app/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/app-state/src/index.d.ts +19 -0
- package/types/vendor/@akanjs/native/plugins/app-state/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/app-state/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/desktop.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/index.d.ts +32 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/setting.d.ts +6 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src/web.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/appearance/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/auth-session/src/args.d.ts +18 -0
- package/types/vendor/@akanjs/native/plugins/auth-session/src/desktop.d.ts +17 -0
- package/types/vendor/@akanjs/native/plugins/auth-session/src/index.d.ts +41 -0
- package/types/vendor/@akanjs/native/plugins/auth-session/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/autostart/src/desktop.d.ts +44 -0
- package/types/vendor/@akanjs/native/plugins/autostart/src/index.d.ts +44 -0
- package/types/vendor/@akanjs/native/plugins/autostart/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/badge/src/count.d.ts +4 -0
- package/types/vendor/@akanjs/native/plugins/badge/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/badge/src/index.d.ts +37 -0
- package/types/vendor/@akanjs/native/plugins/badge/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/badge/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/biometric/src/index.d.ts +53 -0
- package/types/vendor/@akanjs/native/plugins/biometric/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/browser/src/args.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/browser/src/desktop.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/browser/src/index.d.ts +36 -0
- package/types/vendor/@akanjs/native/plugins/browser/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/browser/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/camera/src/desktop.d.ts +5 -0
- package/types/vendor/@akanjs/native/plugins/camera/src/index.d.ts +55 -0
- package/types/vendor/@akanjs/native/plugins/camera/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/camera/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/clipboard/src/desktop.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/clipboard/src/index.d.ts +40 -0
- package/types/vendor/@akanjs/native/plugins/clipboard/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/clipboard/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/device/src/desktop.d.ts +33 -0
- package/types/vendor/@akanjs/native/plugins/device/src/index.d.ts +55 -0
- package/types/vendor/@akanjs/native/plugins/device/src/web.d.ts +22 -0
- package/types/vendor/@akanjs/native/plugins/device/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/dialog/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/dialog/src/index.d.ts +60 -0
- package/types/vendor/@akanjs/native/plugins/dialog/src/options.d.ts +29 -0
- package/types/vendor/@akanjs/native/plugins/dialog/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/dialog/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/dock/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/dock/src/index.d.ts +46 -0
- package/types/vendor/@akanjs/native/plugins/dock/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/file-picker/src/common.d.ts +33 -0
- package/types/vendor/@akanjs/native/plugins/file-picker/src/desktop.d.ts +9 -0
- package/types/vendor/@akanjs/native/plugins/file-picker/src/index.d.ts +84 -0
- package/types/vendor/@akanjs/native/plugins/file-picker/src/web.d.ts +6 -0
- package/types/vendor/@akanjs/native/plugins/file-picker/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/filesystem/src/common.d.ts +49 -0
- package/types/vendor/@akanjs/native/plugins/filesystem/src/desktop.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/filesystem/src/index.d.ts +123 -0
- package/types/vendor/@akanjs/native/plugins/filesystem/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/filesystem/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/geolocation/src/index.d.ts +93 -0
- package/types/vendor/@akanjs/native/plugins/geolocation/src/web.d.ts +11 -0
- package/types/vendor/@akanjs/native/plugins/geolocation/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/global-shortcut/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/global-shortcut/src/index.d.ts +52 -0
- package/types/vendor/@akanjs/native/plugins/global-shortcut/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/haptics/src/index.d.ts +31 -0
- package/types/vendor/@akanjs/native/plugins/haptics/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/haptics/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/http/src/common.d.ts +71 -0
- package/types/vendor/@akanjs/native/plugins/http/src/desktop.d.ts +5 -0
- package/types/vendor/@akanjs/native/plugins/http/src/index.d.ts +104 -0
- package/types/vendor/@akanjs/native/plugins/http/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/http/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/iap/src/index.d.ts +171 -0
- package/types/vendor/@akanjs/native/plugins/iap/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/desktop.d.ts +15 -0
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/index.d.ts +33 -0
- package/types/vendor/@akanjs/native/plugins/keep-awake/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/keep-awake/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/keyboard/src/index.d.ts +42 -0
- package/types/vendor/@akanjs/native/plugins/keyboard/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/keyboard/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src/desktop.d.ts +29 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src/index.d.ts +126 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src/schedule.d.ts +38 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src/timers.d.ts +25 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src/web.d.ts +4 -0
- package/types/vendor/@akanjs/native/plugins/local-notifications/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/menu/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/menu/src/index.d.ts +85 -0
- package/types/vendor/@akanjs/native/plugins/menu/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/network/src/index.d.ts +22 -0
- package/types/vendor/@akanjs/native/plugins/network/src/web.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/network/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/opener/src/desktop.d.ts +14 -0
- package/types/vendor/@akanjs/native/plugins/opener/src/index.d.ts +33 -0
- package/types/vendor/@akanjs/native/plugins/opener/src/url.d.ts +16 -0
- package/types/vendor/@akanjs/native/plugins/opener/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/opener/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/preferences/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/preferences/src/index.d.ts +26 -0
- package/types/vendor/@akanjs/native/plugins/preferences/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/preferences/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/push/src/index.d.ts +57 -0
- package/types/vendor/@akanjs/native/plugins/push/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/screen/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/screen/src/index.d.ts +70 -0
- package/types/vendor/@akanjs/native/plugins/screen/src/web.d.ts +18 -0
- package/types/vendor/@akanjs/native/plugins/screen/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/screen-orientation/src/index.d.ts +32 -0
- package/types/vendor/@akanjs/native/plugins/screen-orientation/src/types.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/screen-orientation/src/web.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/screen-orientation/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/secure-storage/src/desktop.d.ts +16 -0
- package/types/vendor/@akanjs/native/plugins/secure-storage/src/index.d.ts +39 -0
- package/types/vendor/@akanjs/native/plugins/secure-storage/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/share/src/index.d.ts +55 -0
- package/types/vendor/@akanjs/native/plugins/share/src/options.d.ts +6 -0
- package/types/vendor/@akanjs/native/plugins/share/src/web.d.ts +5 -0
- package/types/vendor/@akanjs/native/plugins/share/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/single-instance/src/desktop.d.ts +8 -0
- package/types/vendor/@akanjs/native/plugins/single-instance/src/index.d.ts +25 -0
- package/types/vendor/@akanjs/native/plugins/single-instance/src/socket.d.ts +46 -0
- package/types/vendor/@akanjs/native/plugins/single-instance/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/splash-screen/src/index.d.ts +19 -0
- package/types/vendor/@akanjs/native/plugins/splash-screen/src/web.d.ts +4 -0
- package/types/vendor/@akanjs/native/plugins/splash-screen/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/sqlite/src/common.d.ts +34 -0
- package/types/vendor/@akanjs/native/plugins/sqlite/src/desktop.d.ts +6 -0
- package/types/vendor/@akanjs/native/plugins/sqlite/src/index.d.ts +115 -0
- package/types/vendor/@akanjs/native/plugins/sqlite/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/toast/src/index.d.ts +30 -0
- package/types/vendor/@akanjs/native/plugins/toast/src/queue.d.ts +23 -0
- package/types/vendor/@akanjs/native/plugins/toast/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/toast/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/tray/src/desktop.d.ts +3 -0
- package/types/vendor/@akanjs/native/plugins/tray/src/index.d.ts +113 -0
- package/types/vendor/@akanjs/native/plugins/tray/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/updates/src/desktop.d.ts +4 -0
- package/types/vendor/@akanjs/native/plugins/updates/src/index.d.ts +68 -0
- package/types/vendor/@akanjs/native/plugins/updates/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/window/src/desktop.d.ts +6 -0
- package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +185 -0
- package/types/vendor/@akanjs/native/plugins/window/src/web.d.ts +2 -0
- package/types/vendor/@akanjs/native/plugins/window/src.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/window-state/src/desktop.d.ts +7 -0
- package/types/vendor/@akanjs/native/plugins/window-state/src/index.d.ts +33 -0
- package/types/vendor/@akanjs/native/plugins/window-state/src/state.d.ts +39 -0
- package/types/vendor/@akanjs/native/plugins/window-state/src.d.ts +1 -0
- package/types/webkit/index.d.ts +0 -2
- package/types/webkit/nativeNavigation.d.ts +25 -0
- package/types/webkit/nativePurchase.d.ts +37 -0
- package/types/webkit/useCamera.d.ts +13 -15
- package/types/webkit/useGeoLocation.d.ts +4 -5
- package/types/webkit/usePurchase.d.ts +12 -16
- package/ui/Link/Anchor.tsx +2 -5
- package/ui/System/Client.tsx +2 -6
- package/vendor/@akanjs/native/LICENSE +21 -0
- package/vendor/@akanjs/native/README.ko.md +88 -0
- package/vendor/@akanjs/native/README.md +93 -0
- package/vendor/@akanjs/native/THIRD_PARTY_NOTICES.md +237 -0
- package/vendor/@akanjs/native/native/android/maven.lock.json +1751 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeAcl.kt +243 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeActivity.kt +936 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeApplication.kt +189 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeAssetServer.kt +225 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeBridge.kt +444 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeCompat.kt +55 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeContract.kt +99 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeEd25519.kt +100 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeFileProvider.kt +71 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeKernel.kt +324 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativePlugin.kt +361 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeSpec.kt +100 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeUpdates.kt +305 -0
- package/vendor/@akanjs/native/native/android/src/com/akanjs/runtime/AkanNativeVectors.kt +132 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.lock +2565 -0
- package/vendor/@akanjs/native/native/desktop/Cargo.toml +49 -0
- package/vendor/@akanjs/native/native/desktop/build.rs +19 -0
- package/vendor/@akanjs/native/native/desktop/rust-toolchain.toml +7 -0
- package/vendor/@akanjs/native/native/desktop/src/accelerator.rs +466 -0
- package/vendor/@akanjs/native/native/desktop/src/autostart.rs +158 -0
- package/vendor/@akanjs/native/native/desktop/src/camera.rs +53 -0
- package/vendor/@akanjs/native/native/desktop/src/chrome.rs +710 -0
- package/vendor/@akanjs/native/native/desktop/src/contract.rs +105 -0
- package/vendor/@akanjs/native/native/desktop/src/devproxy.rs +234 -0
- package/vendor/@akanjs/native/native/desktop/src/dialog_args.rs +189 -0
- package/vendor/@akanjs/native/native/desktop/src/dock.rs +209 -0
- package/vendor/@akanjs/native/native/desktop/src/hotkey.rs +209 -0
- package/vendor/@akanjs/native/native/desktop/src/js_panels.rs +125 -0
- package/vendor/@akanjs/native/native/desktop/src/json.rs +272 -0
- package/vendor/@akanjs/native/native/desktop/src/keychain.rs +151 -0
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +2185 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/appearance.rs +177 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/camera.rs +11 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/clipboard.rs +48 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/device.rs +9 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/dialogs.rs +348 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/dock.rs +146 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/hotkey.rs +228 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/keychain.rs +243 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/menu.rs +445 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +116 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/notify.rs +211 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/open.rs +79 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/power.rs +155 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/screen.rs +158 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/tray.rs +604 -0
- package/vendor/@akanjs/native/native/desktop/src/menu.rs +517 -0
- package/vendor/@akanjs/native/native/desktop/src/navigation.rs +381 -0
- package/vendor/@akanjs/native/native/desktop/src/notify.rs +411 -0
- package/vendor/@akanjs/native/native/desktop/src/notify_schedule.rs +382 -0
- package/vendor/@akanjs/native/native/desktop/src/page_menu.rs +287 -0
- package/vendor/@akanjs/native/native/desktop/src/panels.rs +333 -0
- package/vendor/@akanjs/native/native/desktop/src/placement.rs +92 -0
- package/vendor/@akanjs/native/native/desktop/src/routes.rs +153 -0
- package/vendor/@akanjs/native/native/desktop/src/screen.rs +190 -0
- package/vendor/@akanjs/native/native/desktop/src/tray.rs +279 -0
- package/vendor/@akanjs/native/native/desktop/src/vectors.rs +126 -0
- package/vendor/@akanjs/native/native/desktop/src/win/appearance.rs +51 -0
- package/vendor/@akanjs/native/native/desktop/src/win/autostart.rs +77 -0
- package/vendor/@akanjs/native/native/desktop/src/win/camera.rs +34 -0
- package/vendor/@akanjs/native/native/desktop/src/win/clipboard.rs +106 -0
- package/vendor/@akanjs/native/native/desktop/src/win/device.rs +80 -0
- package/vendor/@akanjs/native/native/desktop/src/win/dialogs.rs +917 -0
- package/vendor/@akanjs/native/native/desktop/src/win/dock.rs +228 -0
- package/vendor/@akanjs/native/native/desktop/src/win/hotkey.rs +110 -0
- package/vendor/@akanjs/native/native/desktop/src/win/keychain.rs +103 -0
- package/vendor/@akanjs/native/native/desktop/src/win/menu.rs +500 -0
- package/vendor/@akanjs/native/native/desktop/src/win/mod.rs +100 -0
- package/vendor/@akanjs/native/native/desktop/src/win/msgwin.rs +86 -0
- package/vendor/@akanjs/native/native/desktop/src/win/notify.rs +334 -0
- package/vendor/@akanjs/native/native/desktop/src/win/open.rs +127 -0
- package/vendor/@akanjs/native/native/desktop/src/win/power.rs +64 -0
- package/vendor/@akanjs/native/native/desktop/src/win/registry.rs +87 -0
- package/vendor/@akanjs/native/native/desktop/src/win/screen.rs +127 -0
- package/vendor/@akanjs/native/native/desktop/src/win/tray.rs +280 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeAcl.swift +241 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeApp.swift +285 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeBridge.swift +407 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeContract.swift +106 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeKernel.swift +317 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativePlugin.swift +250 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeSchemeHandler.swift +209 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeShell.swift +161 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeSpec.swift +143 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeUpdates.swift +270 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeVectors.swift +155 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +371 -0
- package/vendor/@akanjs/native/packages/cli/src/api.ts +600 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/build.ts +101 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/compat.ts +53 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/dev.ts +249 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/doctor.ts +536 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/plugin.ts +164 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/signing.ts +32 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/test.ts +130 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/toolchain.ts +143 -0
- package/vendor/@akanjs/native/packages/cli/src/commands/update.ts +168 -0
- package/vendor/@akanjs/native/packages/cli/src/config.ts +257 -0
- package/vendor/@akanjs/native/packages/cli/src/index.ts +77 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/acl.ts +420 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/apilevel.ts +245 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/apk.ts +203 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/args.ts +44 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/boot.ts +73 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/chrome.ts +89 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/codegen.ts +1128 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/compat.ts +185 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/configkeys.ts +91 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/csp.ts +198 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/env.ts +257 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/exec.ts +104 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/googleservices.ts +53 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/hmr.ts +534 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/html.ts +63 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/icons.ts +316 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/image.ts +175 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/iossigning.ts +295 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/launch.ts +98 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/log.ts +105 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/manifestmerge.ts +107 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/maven.ts +244 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/names.ts +202 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +326 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/nativeconfig.ts +68 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/permissions.ts +80 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/plist.ts +139 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/png.ts +240 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/prepare.ts +290 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/privacy.ts +64 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +710 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/root.ts +18 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/routes.ts +3 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/serve.ts +83 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/signing.ts +117 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/spec.ts +521 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/toolchains.ts +579 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +160 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/vectors.ts +121 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/xml.ts +72 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/android.ts +1320 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.ts +78 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/desktop.ts +279 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/index.ts +31 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/ios.ts +801 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/linux.ts +52 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/macos.ts +97 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/targets.ts +12 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/web-run.ts +69 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/web.ts +28 -0
- package/vendor/@akanjs/native/packages/cli/src/platforms/windows.ts +82 -0
- package/vendor/@akanjs/native/packages/core/contract.json +96 -0
- package/vendor/@akanjs/native/packages/core/src/acl.ts +272 -0
- package/vendor/@akanjs/native/packages/core/src/boot.ts +97 -0
- package/vendor/@akanjs/native/packages/core/src/contract.ts +100 -0
- package/vendor/@akanjs/native/packages/core/src/errors.ts +95 -0
- package/vendor/@akanjs/native/packages/core/src/files.ts +105 -0
- package/vendor/@akanjs/native/packages/core/src/index.ts +35 -0
- package/vendor/@akanjs/native/packages/core/src/kernel.ts +281 -0
- package/vendor/@akanjs/native/packages/core/src/live.ts +62 -0
- package/vendor/@akanjs/native/packages/core/src/mime.ts +8 -0
- package/vendor/@akanjs/native/packages/core/src/plugin.ts +358 -0
- package/vendor/@akanjs/native/packages/core/src/protocol.ts +194 -0
- package/vendor/@akanjs/native/packages/core/src/runtime.ts +520 -0
- package/vendor/@akanjs/native/packages/core/src/state.ts +46 -0
- package/vendor/@akanjs/native/packages/core/src/testing.ts +176 -0
- package/vendor/@akanjs/native/packages/core/src/version.ts +2 -0
- package/vendor/@akanjs/native/packages/core/src/veto.ts +55 -0
- package/vendor/@akanjs/native/packages/core/vectors/acl.json +57 -0
- package/vendor/@akanjs/native/packages/core/vectors/bridge.json +76 -0
- package/vendor/@akanjs/native/packages/core/vectors/ed25519.json +29 -0
- package/vendor/@akanjs/native/packages/core/vectors/ids.json +73 -0
- package/vendor/@akanjs/native/packages/core/vectors/navigation.json +75 -0
- package/vendor/@akanjs/native/packages/core/vectors/ranges.json +39 -0
- package/vendor/@akanjs/native/packages/core/vectors/retained.json +17 -0
- package/vendor/@akanjs/native/packages/core/vectors/routes.json +66 -0
- package/vendor/@akanjs/native/packages/core/vectors/scope.json +143 -0
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +143 -0
- package/vendor/@akanjs/native/packages/desktop/src/delta.ts +174 -0
- package/vendor/@akanjs/native/packages/desktop/src/dispatcher.ts +679 -0
- package/vendor/@akanjs/native/packages/desktop/src/ffi.ts +76 -0
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +355 -0
- package/vendor/@akanjs/native/packages/desktop/src/lifecycle.ts +142 -0
- package/vendor/@akanjs/native/packages/desktop/src/main.ts +133 -0
- package/vendor/@akanjs/native/packages/desktop/src/page-veto.ts +103 -0
- package/vendor/@akanjs/native/packages/desktop/src/paths.ts +59 -0
- package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +232 -0
- package/vendor/@akanjs/native/packages/react/src/index.ts +23 -0
- package/vendor/@akanjs/native/plugins/accessibility/android/AccessibilityPlugin.kt +96 -0
- package/vendor/@akanjs/native/plugins/accessibility/ios/AccessibilityPlugin.swift +92 -0
- package/vendor/@akanjs/native/plugins/accessibility/native-plugin.json +21 -0
- package/vendor/@akanjs/native/plugins/accessibility/src/announce.ts +71 -0
- package/vendor/@akanjs/native/plugins/accessibility/src/index.ts +77 -0
- package/vendor/@akanjs/native/plugins/accessibility/src/web.ts +52 -0
- package/vendor/@akanjs/native/plugins/app/android/AppPlugin.kt +72 -0
- package/vendor/@akanjs/native/plugins/app/ios/AppPlugin.swift +52 -0
- package/vendor/@akanjs/native/plugins/app/native-plugin.json +21 -0
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +64 -0
- package/vendor/@akanjs/native/plugins/app/src/index.ts +77 -0
- package/vendor/@akanjs/native/plugins/app/src/web.ts +12 -0
- package/vendor/@akanjs/native/plugins/app-state/android/AppStatePlugin.kt +54 -0
- package/vendor/@akanjs/native/plugins/app-state/ios/AppStatePlugin.swift +58 -0
- package/vendor/@akanjs/native/plugins/app-state/native-plugin.json +17 -0
- package/vendor/@akanjs/native/plugins/app-state/src/index.ts +42 -0
- package/vendor/@akanjs/native/plugins/app-state/src/web.ts +33 -0
- package/vendor/@akanjs/native/plugins/appearance/android/AppearancePlugin.kt +133 -0
- package/vendor/@akanjs/native/plugins/appearance/ios/AppearancePlugin.swift +109 -0
- package/vendor/@akanjs/native/plugins/appearance/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/appearance/src/desktop.ts +133 -0
- package/vendor/@akanjs/native/plugins/appearance/src/index.ts +62 -0
- package/vendor/@akanjs/native/plugins/appearance/src/setting.ts +18 -0
- package/vendor/@akanjs/native/plugins/appearance/src/web.ts +25 -0
- package/vendor/@akanjs/native/plugins/auth-session/android/AuthSessionPlugin.kt +171 -0
- package/vendor/@akanjs/native/plugins/auth-session/ios/AuthSessionPlugin.swift +112 -0
- package/vendor/@akanjs/native/plugins/auth-session/native-plugin.json +19 -0
- package/vendor/@akanjs/native/plugins/auth-session/src/args.ts +62 -0
- package/vendor/@akanjs/native/plugins/auth-session/src/desktop.ts +133 -0
- package/vendor/@akanjs/native/plugins/auth-session/src/index.ts +39 -0
- package/vendor/@akanjs/native/plugins/autostart/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +189 -0
- package/vendor/@akanjs/native/plugins/autostart/src/index.ts +51 -0
- package/vendor/@akanjs/native/plugins/badge/ios/BadgePlugin.swift +92 -0
- package/vendor/@akanjs/native/plugins/badge/native-plugin.json +15 -0
- package/vendor/@akanjs/native/plugins/badge/src/count.ts +12 -0
- package/vendor/@akanjs/native/plugins/badge/src/desktop.ts +24 -0
- package/vendor/@akanjs/native/plugins/badge/src/index.ts +40 -0
- package/vendor/@akanjs/native/plugins/badge/src/web.ts +37 -0
- package/vendor/@akanjs/native/plugins/biometric/android/BiometricPlugin.kt +179 -0
- package/vendor/@akanjs/native/plugins/biometric/ios/BiometricPlugin.swift +129 -0
- package/vendor/@akanjs/native/plugins/biometric/native-plugin.json +22 -0
- package/vendor/@akanjs/native/plugins/biometric/src/index.ts +100 -0
- package/vendor/@akanjs/native/plugins/browser/android/BrowserPlugin.kt +178 -0
- package/vendor/@akanjs/native/plugins/browser/ios/BrowserPlugin.swift +63 -0
- package/vendor/@akanjs/native/plugins/browser/native-plugin.json +22 -0
- package/vendor/@akanjs/native/plugins/browser/src/args.ts +34 -0
- package/vendor/@akanjs/native/plugins/browser/src/desktop.ts +40 -0
- package/vendor/@akanjs/native/plugins/browser/src/index.ts +47 -0
- package/vendor/@akanjs/native/plugins/browser/src/web.ts +60 -0
- package/vendor/@akanjs/native/plugins/camera/android/CameraPlugin.kt +365 -0
- package/vendor/@akanjs/native/plugins/camera/ios/CameraPlugin.swift +296 -0
- package/vendor/@akanjs/native/plugins/camera/native-plugin.json +32 -0
- package/vendor/@akanjs/native/plugins/camera/src/desktop.ts +27 -0
- package/vendor/@akanjs/native/plugins/camera/src/index.ts +85 -0
- package/vendor/@akanjs/native/plugins/camera/src/web.ts +267 -0
- package/vendor/@akanjs/native/plugins/clipboard/android/ClipboardPlugin.kt +51 -0
- package/vendor/@akanjs/native/plugins/clipboard/ios/ClipboardPlugin.swift +35 -0
- package/vendor/@akanjs/native/plugins/clipboard/native-plugin.json +17 -0
- package/vendor/@akanjs/native/plugins/clipboard/src/desktop.ts +66 -0
- package/vendor/@akanjs/native/plugins/clipboard/src/index.ts +72 -0
- package/vendor/@akanjs/native/plugins/clipboard/src/web.ts +69 -0
- package/vendor/@akanjs/native/plugins/device/android/DevicePlugin.kt +70 -0
- package/vendor/@akanjs/native/plugins/device/ios/DevicePlugin.swift +80 -0
- package/vendor/@akanjs/native/plugins/device/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/device/src/desktop.ts +276 -0
- package/vendor/@akanjs/native/plugins/device/src/index.ts +72 -0
- package/vendor/@akanjs/native/plugins/device/src/web.ts +162 -0
- package/vendor/@akanjs/native/plugins/dialog/android/DialogPlugin.kt +260 -0
- package/vendor/@akanjs/native/plugins/dialog/ios/DialogPlugin.swift +198 -0
- package/vendor/@akanjs/native/plugins/dialog/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/dialog/src/desktop.ts +80 -0
- package/vendor/@akanjs/native/plugins/dialog/src/index.ts +87 -0
- package/vendor/@akanjs/native/plugins/dialog/src/options.ts +111 -0
- package/vendor/@akanjs/native/plugins/dialog/src/web.ts +296 -0
- package/vendor/@akanjs/native/plugins/dock/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/dock/src/desktop.ts +34 -0
- package/vendor/@akanjs/native/plugins/dock/src/index.ts +46 -0
- package/vendor/@akanjs/native/plugins/file-picker/android/FilePickerPlugin.kt +316 -0
- package/vendor/@akanjs/native/plugins/file-picker/ios/FilePickerPlugin.swift +366 -0
- package/vendor/@akanjs/native/plugins/file-picker/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/file-picker/src/common.ts +125 -0
- package/vendor/@akanjs/native/plugins/file-picker/src/desktop.ts +164 -0
- package/vendor/@akanjs/native/plugins/file-picker/src/index.ts +187 -0
- package/vendor/@akanjs/native/plugins/file-picker/src/web.ts +158 -0
- package/vendor/@akanjs/native/plugins/filesystem/android/FilesystemPlugin.kt +561 -0
- package/vendor/@akanjs/native/plugins/filesystem/ios/FilesystemPlugin.swift +596 -0
- package/vendor/@akanjs/native/plugins/filesystem/native-plugin.json +45 -0
- package/vendor/@akanjs/native/plugins/filesystem/src/common.ts +150 -0
- package/vendor/@akanjs/native/plugins/filesystem/src/desktop.ts +438 -0
- package/vendor/@akanjs/native/plugins/filesystem/src/index.ts +179 -0
- package/vendor/@akanjs/native/plugins/filesystem/src/web.ts +334 -0
- package/vendor/@akanjs/native/plugins/geolocation/android/GeolocationPlugin.kt +360 -0
- package/vendor/@akanjs/native/plugins/geolocation/ios/GeolocationPlugin.swift +284 -0
- package/vendor/@akanjs/native/plugins/geolocation/native-plugin.json +23 -0
- package/vendor/@akanjs/native/plugins/geolocation/src/index.ts +155 -0
- package/vendor/@akanjs/native/plugins/geolocation/src/web.ts +132 -0
- package/vendor/@akanjs/native/plugins/global-shortcut/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/global-shortcut/src/desktop.ts +36 -0
- package/vendor/@akanjs/native/plugins/global-shortcut/src/index.ts +55 -0
- package/vendor/@akanjs/native/plugins/haptics/android/HapticsPlugin.kt +127 -0
- package/vendor/@akanjs/native/plugins/haptics/ios/HapticsPlugin.swift +127 -0
- package/vendor/@akanjs/native/plugins/haptics/native-plugin.json +19 -0
- package/vendor/@akanjs/native/plugins/haptics/src/index.ts +34 -0
- package/vendor/@akanjs/native/plugins/haptics/src/web.ts +53 -0
- package/vendor/@akanjs/native/plugins/http/android/HttpPlugin.kt +234 -0
- package/vendor/@akanjs/native/plugins/http/android/HttpUrl.kt +182 -0
- package/vendor/@akanjs/native/plugins/http/ios/HttpPlugin.swift +228 -0
- package/vendor/@akanjs/native/plugins/http/ios/HttpUrl.swift +166 -0
- package/vendor/@akanjs/native/plugins/http/native-plugin.json +27 -0
- package/vendor/@akanjs/native/plugins/http/src/common.ts +294 -0
- package/vendor/@akanjs/native/plugins/http/src/desktop.ts +69 -0
- package/vendor/@akanjs/native/plugins/http/src/index.ts +181 -0
- package/vendor/@akanjs/native/plugins/http/src/web.ts +40 -0
- package/vendor/@akanjs/native/plugins/iap/android/IapPlugin.kt +358 -0
- package/vendor/@akanjs/native/plugins/iap/ios/IapPlugin.swift +306 -0
- package/vendor/@akanjs/native/plugins/iap/native-plugin.json +28 -0
- package/vendor/@akanjs/native/plugins/iap/src/index.ts +206 -0
- package/vendor/@akanjs/native/plugins/keep-awake/android/KeepAwakePlugin.kt +48 -0
- package/vendor/@akanjs/native/plugins/keep-awake/ios/KeepAwakePlugin.swift +36 -0
- package/vendor/@akanjs/native/plugins/keep-awake/native-plugin.json +17 -0
- package/vendor/@akanjs/native/plugins/keep-awake/src/desktop.ts +127 -0
- package/vendor/@akanjs/native/plugins/keep-awake/src/index.ts +79 -0
- package/vendor/@akanjs/native/plugins/keep-awake/src/web.ts +78 -0
- package/vendor/@akanjs/native/plugins/keyboard/android/KeyboardPlugin.kt +77 -0
- package/vendor/@akanjs/native/plugins/keyboard/ios/KeyboardPlugin.swift +93 -0
- package/vendor/@akanjs/native/plugins/keyboard/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/keyboard/src/index.ts +78 -0
- package/vendor/@akanjs/native/plugins/keyboard/src/web.ts +57 -0
- package/vendor/@akanjs/native/plugins/local-notifications/android/LocalNotificationReceiver.kt +38 -0
- package/vendor/@akanjs/native/plugins/local-notifications/android/LocalNotifications.kt +284 -0
- package/vendor/@akanjs/native/plugins/local-notifications/android/LocalNotificationsPlugin.kt +248 -0
- package/vendor/@akanjs/native/plugins/local-notifications/ios/LocalNotificationsPlugin.swift +279 -0
- package/vendor/@akanjs/native/plugins/local-notifications/native-plugin.json +35 -0
- package/vendor/@akanjs/native/plugins/local-notifications/src/desktop.ts +196 -0
- package/vendor/@akanjs/native/plugins/local-notifications/src/index.ts +174 -0
- package/vendor/@akanjs/native/plugins/local-notifications/src/schedule.ts +164 -0
- package/vendor/@akanjs/native/plugins/local-notifications/src/timers.ts +72 -0
- package/vendor/@akanjs/native/plugins/local-notifications/src/web.ts +158 -0
- package/vendor/@akanjs/native/plugins/menu/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/menu/src/desktop.ts +52 -0
- package/vendor/@akanjs/native/plugins/menu/src/index.ts +107 -0
- package/vendor/@akanjs/native/plugins/network/android/NetworkPlugin.kt +124 -0
- package/vendor/@akanjs/native/plugins/network/ios/NetworkPlugin.swift +82 -0
- package/vendor/@akanjs/native/plugins/network/native-plugin.json +19 -0
- package/vendor/@akanjs/native/plugins/network/src/index.ts +59 -0
- package/vendor/@akanjs/native/plugins/network/src/web.ts +43 -0
- package/vendor/@akanjs/native/plugins/opener/android/OpenerPlugin.kt +81 -0
- package/vendor/@akanjs/native/plugins/opener/ios/OpenerPlugin.swift +83 -0
- package/vendor/@akanjs/native/plugins/opener/native-plugin.json +25 -0
- package/vendor/@akanjs/native/plugins/opener/src/desktop.ts +88 -0
- package/vendor/@akanjs/native/plugins/opener/src/index.ts +35 -0
- package/vendor/@akanjs/native/plugins/opener/src/url.ts +39 -0
- package/vendor/@akanjs/native/plugins/opener/src/web.ts +33 -0
- package/vendor/@akanjs/native/plugins/preferences/android/PreferencesPlugin.kt +44 -0
- package/vendor/@akanjs/native/plugins/preferences/ios/PreferencesPlugin.swift +47 -0
- package/vendor/@akanjs/native/plugins/preferences/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/preferences/src/desktop.ts +59 -0
- package/vendor/@akanjs/native/plugins/preferences/src/index.ts +75 -0
- package/vendor/@akanjs/native/plugins/preferences/src/web.ts +55 -0
- package/vendor/@akanjs/native/plugins/push/android/AkanNativeMessagingService.kt +17 -0
- package/vendor/@akanjs/native/plugins/push/android/PushPlugin.kt +257 -0
- package/vendor/@akanjs/native/plugins/push/ios/PushPlugin.swift +169 -0
- package/vendor/@akanjs/native/plugins/push/native-plugin.json +23 -0
- package/vendor/@akanjs/native/plugins/push/src/index.ts +73 -0
- package/vendor/@akanjs/native/plugins/screen/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/screen/src/desktop.ts +50 -0
- package/vendor/@akanjs/native/plugins/screen/src/index.ts +107 -0
- package/vendor/@akanjs/native/plugins/screen/src/web.ts +92 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/android/ScreenOrientationPlugin.kt +113 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/ios/ScreenOrientationPlugin.swift +150 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/native-plugin.json +17 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/src/index.ts +69 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/src/types.ts +26 -0
- package/vendor/@akanjs/native/plugins/screen-orientation/src/web.ts +67 -0
- package/vendor/@akanjs/native/plugins/secure-storage/android/SecureStoragePlugin.kt +184 -0
- package/vendor/@akanjs/native/plugins/secure-storage/ios/SecureStoragePlugin.swift +145 -0
- package/vendor/@akanjs/native/plugins/secure-storage/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/secure-storage/src/desktop.ts +332 -0
- package/vendor/@akanjs/native/plugins/secure-storage/src/index.ts +33 -0
- package/vendor/@akanjs/native/plugins/share/android/SharePlugin.kt +218 -0
- package/vendor/@akanjs/native/plugins/share/ios/SharePlugin.swift +142 -0
- package/vendor/@akanjs/native/plugins/share/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/share/src/index.ts +87 -0
- package/vendor/@akanjs/native/plugins/share/src/options.ts +43 -0
- package/vendor/@akanjs/native/plugins/share/src/web.ts +116 -0
- package/vendor/@akanjs/native/plugins/single-instance/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/single-instance/src/desktop.ts +63 -0
- package/vendor/@akanjs/native/plugins/single-instance/src/index.ts +32 -0
- package/vendor/@akanjs/native/plugins/single-instance/src/socket.ts +248 -0
- package/vendor/@akanjs/native/plugins/splash-screen/android/SplashScreenPlugin.kt +19 -0
- package/vendor/@akanjs/native/plugins/splash-screen/ios/SplashScreenPlugin.swift +20 -0
- package/vendor/@akanjs/native/plugins/splash-screen/native-plugin.json +17 -0
- package/vendor/@akanjs/native/plugins/splash-screen/src/index.ts +24 -0
- package/vendor/@akanjs/native/plugins/splash-screen/src/web.ts +17 -0
- package/vendor/@akanjs/native/plugins/sqlite/android/SqlStatements.kt +121 -0
- package/vendor/@akanjs/native/plugins/sqlite/android/SqlitePlugin.kt +327 -0
- package/vendor/@akanjs/native/plugins/sqlite/ios/SqlitePlugin.swift +361 -0
- package/vendor/@akanjs/native/plugins/sqlite/native-plugin.json +18 -0
- package/vendor/@akanjs/native/plugins/sqlite/src/common.ts +221 -0
- package/vendor/@akanjs/native/plugins/sqlite/src/desktop.ts +140 -0
- package/vendor/@akanjs/native/plugins/sqlite/src/index.ts +114 -0
- package/vendor/@akanjs/native/plugins/toast/android/ToastPlugin.kt +27 -0
- package/vendor/@akanjs/native/plugins/toast/native-plugin.json +14 -0
- package/vendor/@akanjs/native/plugins/toast/src/index.ts +41 -0
- package/vendor/@akanjs/native/plugins/toast/src/queue.ts +77 -0
- package/vendor/@akanjs/native/plugins/toast/src/web.ts +130 -0
- package/vendor/@akanjs/native/plugins/tray/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/tray/src/desktop.ts +73 -0
- package/vendor/@akanjs/native/plugins/tray/src/index.ts +111 -0
- package/vendor/@akanjs/native/plugins/updates/android/UpdatesPlugin.kt +290 -0
- package/vendor/@akanjs/native/plugins/updates/ios/UpdatesPlugin.swift +292 -0
- package/vendor/@akanjs/native/plugins/updates/native-plugin.json +19 -0
- package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +558 -0
- package/vendor/@akanjs/native/plugins/updates/src/index.ts +95 -0
- package/vendor/@akanjs/native/plugins/window/native-plugin.json +32 -0
- package/vendor/@akanjs/native/plugins/window/src/desktop.ts +170 -0
- package/vendor/@akanjs/native/plugins/window/src/index.ts +342 -0
- package/vendor/@akanjs/native/plugins/window/src/web.ts +43 -0
- package/vendor/@akanjs/native/plugins/window-state/native-plugin.json +10 -0
- package/vendor/@akanjs/native/plugins/window-state/src/desktop.ts +73 -0
- package/vendor/@akanjs/native/plugins/window-state/src/index.ts +35 -0
- package/vendor/@akanjs/native/plugins/window-state/src/state.ts +146 -0
- package/webkit/bootCsr.tsx +26 -14
- package/webkit/index.ts +0 -2
- package/webkit/nativeNavigation.ts +116 -0
- package/webkit/nativePurchase.ts +93 -0
- package/webkit/useCamera.tsx +76 -71
- package/webkit/useCsrValues.ts +10 -124
- package/webkit/useGeoLocation.tsx +11 -13
- package/webkit/usePurchase.tsx +68 -123
- package/capacitor.base.config.ts +0 -140
- package/client/capacitor.ts +0 -252
- package/types/capacitor.base.config.d.ts +0 -3
- package/types/client/capacitor.d.ts +0 -290
- package/types/webkit/useCodepush.d.ts +0 -16
- package/types/webkit/useContact.d.ts +0 -11
- package/webkit/useCodepush.tsx +0 -76
- package/webkit/useContact.tsx +0 -45
|
@@ -0,0 +1,1128 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import { CliError } from "./log.ts";
|
|
5
|
+
import type { AndroidManifest, PluginManifest, ResolvedPlugin } from "./project.ts";
|
|
6
|
+
import {
|
|
7
|
+
type Declaration,
|
|
8
|
+
type Field,
|
|
9
|
+
interfaceFields,
|
|
10
|
+
lookup,
|
|
11
|
+
type Method,
|
|
12
|
+
type PluginSpec,
|
|
13
|
+
readPluginSpec,
|
|
14
|
+
type TypeNode,
|
|
15
|
+
} from "./spec.ts";
|
|
16
|
+
|
|
17
|
+
export type GenType =
|
|
18
|
+
| { t: "string" | "number" | "boolean" | "any" }
|
|
19
|
+
| { t: "enum"; name: string }
|
|
20
|
+
| { t: "struct"; name: string }
|
|
21
|
+
| { t: "array"; of: GenType }
|
|
22
|
+
| { t: "map"; of: GenType };
|
|
23
|
+
|
|
24
|
+
export interface GenField {
|
|
25
|
+
/** The JSON key. */
|
|
26
|
+
name: string;
|
|
27
|
+
type: GenType;
|
|
28
|
+
/** `name?:` — may be missing; results leave it out when nil. */
|
|
29
|
+
optional: boolean;
|
|
30
|
+
/** `| null` — results write null when nil. */
|
|
31
|
+
nullable: boolean;
|
|
32
|
+
doc?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface GenStruct {
|
|
36
|
+
name: string;
|
|
37
|
+
doc?: string;
|
|
38
|
+
fields: GenField[];
|
|
39
|
+
/** Extends FileRef: gets a constructor taking the runtime AkanNativeFileRef for url, mime and size. */
|
|
40
|
+
fileRef?: true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface GenEnum {
|
|
44
|
+
name: string;
|
|
45
|
+
doc?: string;
|
|
46
|
+
values: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface GenMethod {
|
|
50
|
+
name: string;
|
|
51
|
+
doc?: string;
|
|
52
|
+
/** Missing for methods without an argument. */
|
|
53
|
+
args?: string;
|
|
54
|
+
/** null for Promise<void>. */
|
|
55
|
+
result: { type: GenType; nullable: boolean } | null;
|
|
56
|
+
/** Set when the types cannot be generated: the method gets the raw AkanNativeCall. */
|
|
57
|
+
untyped?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface GenEvent {
|
|
61
|
+
name: string;
|
|
62
|
+
doc?: string;
|
|
63
|
+
/** null when the payload type cannot be generated (the helper then takes Any). */
|
|
64
|
+
type: GenType | null;
|
|
65
|
+
nullable: boolean;
|
|
66
|
+
untyped?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GenModel {
|
|
70
|
+
pluginId: string;
|
|
71
|
+
/** PascalCase plugin id, the prefix of every generated name (all iOS plugins share one Swift module). */
|
|
72
|
+
prefix: string;
|
|
73
|
+
source: string;
|
|
74
|
+
structs: GenStruct[];
|
|
75
|
+
enums: GenEnum[];
|
|
76
|
+
methods: GenMethod[];
|
|
77
|
+
events: GenEvent[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const pascal = (text: string) =>
|
|
81
|
+
text
|
|
82
|
+
.split(/[^A-Za-z0-9]+/)
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
.map((w) => w[0]!.toUpperCase() + w.slice(1))
|
|
85
|
+
.join("");
|
|
86
|
+
|
|
87
|
+
class Unsupported extends Error {}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resolves the spec's types into named structs and enums. `methods` / `events` limit the model to
|
|
91
|
+
* what a platform implements (the manifest's per-platform subset).
|
|
92
|
+
*/
|
|
93
|
+
export function buildModel(
|
|
94
|
+
spec: PluginSpec,
|
|
95
|
+
pluginId: string,
|
|
96
|
+
options: { methods?: string[]; events?: string[]; source?: string } = {},
|
|
97
|
+
): GenModel {
|
|
98
|
+
const prefix = pascal(pluginId);
|
|
99
|
+
const structs = new Map<string, GenStruct>();
|
|
100
|
+
const enums = new Map<string, GenEnum>();
|
|
101
|
+
/** Named declarations being resolved, so recursive types refer to themselves by name. */
|
|
102
|
+
const resolving = new Set<string>();
|
|
103
|
+
const named = (name: string) => (name.startsWith(prefix) ? name : prefix + name);
|
|
104
|
+
|
|
105
|
+
const addStruct = (struct: GenStruct) => {
|
|
106
|
+
const existing = structs.get(struct.name);
|
|
107
|
+
if (existing && JSON.stringify(existing.fields) !== JSON.stringify(struct.fields)) {
|
|
108
|
+
throw new CliError(
|
|
109
|
+
`plugin ${pluginId}: two different types would both be named ${struct.name}; name one of them with an interface`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (enums.has(struct.name)) throw new CliError(`plugin ${pluginId}: ${struct.name} is both an enum and a struct`);
|
|
113
|
+
structs.set(struct.name, struct);
|
|
114
|
+
};
|
|
115
|
+
const addEnum = (e: GenEnum) => {
|
|
116
|
+
const existing = enums.get(e.name);
|
|
117
|
+
if (existing && existing.values.join("|") !== e.values.join("|"))
|
|
118
|
+
throw new CliError(`plugin ${pluginId}: two different string unions would both be named ${e.name}`);
|
|
119
|
+
if (structs.has(e.name)) throw new CliError(`plugin ${pluginId}: ${e.name} is both an enum and a struct`);
|
|
120
|
+
enums.set(e.name, e);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Object-like nodes (object literal, interface, alias of one, intersection of those) as fields. */
|
|
124
|
+
const objectFields = (node: TypeNode, context: string): Field[] | null => {
|
|
125
|
+
switch (node.kind) {
|
|
126
|
+
case "object":
|
|
127
|
+
return node.fields;
|
|
128
|
+
case "intersection": {
|
|
129
|
+
const merged = new Map<string, Field>();
|
|
130
|
+
for (const part of node.of) {
|
|
131
|
+
const fields = objectFields(part, context);
|
|
132
|
+
if (!fields) {
|
|
133
|
+
const why =
|
|
134
|
+
part.kind === "unsupported"
|
|
135
|
+
? `${part.reason} (${part.text})`
|
|
136
|
+
: part.kind === "union"
|
|
137
|
+
? "unions of object types are not supported"
|
|
138
|
+
: `${part.kind} is not an object type`;
|
|
139
|
+
throw new Unsupported(`${context}: in an intersection, ${why}`);
|
|
140
|
+
}
|
|
141
|
+
for (const f of fields) merged.set(f.name, f);
|
|
142
|
+
}
|
|
143
|
+
return [...merged.values()];
|
|
144
|
+
}
|
|
145
|
+
case "ref": {
|
|
146
|
+
const decl = lookup(spec, node.name);
|
|
147
|
+
if (decl?.kind === "interface") {
|
|
148
|
+
if (decl.methods.length) throw new Unsupported(`${context}: ${node.name} has methods`);
|
|
149
|
+
return interfaceFields(spec, decl);
|
|
150
|
+
}
|
|
151
|
+
if (decl?.kind === "alias") return objectFields(decl.type, context);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const struct = (name: string, fields: Field[], context: string, doc?: string, fileRef = false): GenType => {
|
|
160
|
+
if (!resolving.has(name)) {
|
|
161
|
+
resolving.add(name);
|
|
162
|
+
const genFields = fields.map((f) => {
|
|
163
|
+
if (f.name === "[index]") throw new Unsupported(`${context}: index signatures are not supported`);
|
|
164
|
+
const { type, nullable } = resolve(f.type, `${name}${pascal(f.name)}`, `${context}.${f.name}`);
|
|
165
|
+
return { name: f.name, type, optional: f.optional, nullable, ...(f.doc ? { doc: f.doc } : {}) };
|
|
166
|
+
});
|
|
167
|
+
addStruct({ name, ...(doc ? { doc } : {}), fields: genFields, ...(fileRef ? { fileRef: true as const } : {}) });
|
|
168
|
+
resolving.delete(name);
|
|
169
|
+
}
|
|
170
|
+
return { t: "struct", name };
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** `nameHint` names an anonymous object or string union found here. */
|
|
174
|
+
const resolve = (node: TypeNode, nameHint: string, context: string): { type: GenType; nullable: boolean } => {
|
|
175
|
+
if (node.kind === "nullable") {
|
|
176
|
+
const inner = resolve(node.of, nameHint, context);
|
|
177
|
+
return { type: inner.type, nullable: true };
|
|
178
|
+
}
|
|
179
|
+
return { type: resolveType(node, nameHint, context), nullable: false };
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const resolveType = (node: TypeNode, nameHint: string, context: string): GenType => {
|
|
183
|
+
switch (node.kind) {
|
|
184
|
+
case "string":
|
|
185
|
+
case "number":
|
|
186
|
+
case "boolean":
|
|
187
|
+
return { t: node.kind };
|
|
188
|
+
case "unknown":
|
|
189
|
+
return { t: "any" };
|
|
190
|
+
case "void":
|
|
191
|
+
throw new Unsupported(`${context}: void is only allowed as a Promise result`);
|
|
192
|
+
case "unsupported":
|
|
193
|
+
throw new Unsupported(`${context}: ${node.reason} (${node.text})`);
|
|
194
|
+
case "nullable":
|
|
195
|
+
throw new Unsupported(`${context}: nested null unions are not supported`);
|
|
196
|
+
case "literal":
|
|
197
|
+
addEnum({ name: nameHint, values: node.values });
|
|
198
|
+
return { t: "enum", name: nameHint };
|
|
199
|
+
case "union":
|
|
200
|
+
addEnum({ name: nameHint, values: [...new Set(node.of.flatMap((m) => literalValues(m, context)))] });
|
|
201
|
+
return { t: "enum", name: nameHint };
|
|
202
|
+
case "array":
|
|
203
|
+
return {
|
|
204
|
+
t: "array",
|
|
205
|
+
of: resolveType(
|
|
206
|
+
node.of.kind === "nullable" ? unsupportedNullableItem(context) : node.of,
|
|
207
|
+
`${nameHint}Item`,
|
|
208
|
+
`${context}[]`,
|
|
209
|
+
),
|
|
210
|
+
};
|
|
211
|
+
case "record":
|
|
212
|
+
return {
|
|
213
|
+
t: "map",
|
|
214
|
+
of: resolveType(
|
|
215
|
+
node.of.kind === "nullable" ? unsupportedNullableItem(context) : node.of,
|
|
216
|
+
`${nameHint}Value`,
|
|
217
|
+
`${context}{}`,
|
|
218
|
+
),
|
|
219
|
+
};
|
|
220
|
+
case "object":
|
|
221
|
+
case "intersection":
|
|
222
|
+
return struct(nameHint, objectFields(node, context)!, context);
|
|
223
|
+
case "ref": {
|
|
224
|
+
const decl = lookup(spec, node.name);
|
|
225
|
+
if (!decl)
|
|
226
|
+
throw new Unsupported(`${context}: ${node.name} is not declared in ${spec.file} (or @akanjs/native/core)`);
|
|
227
|
+
|
|
228
|
+
if (decl.kind === "interface" && decl.name === "FileRef" && !spec.declarations.has("FileRef"))
|
|
229
|
+
return { t: "struct", name: "AkanNativeFileRef" };
|
|
230
|
+
if (decl.kind === "interface")
|
|
231
|
+
return struct(named(decl.name), objectFields(node, context)!, context, decl.doc, extendsFileRef(decl.name));
|
|
232
|
+
if (decl.type.kind === "literal" || decl.type.kind === "union") {
|
|
233
|
+
addEnum({
|
|
234
|
+
name: named(decl.name),
|
|
235
|
+
values: [...new Set(literalValues(decl.type, context))],
|
|
236
|
+
...(decl.doc ? { doc: decl.doc } : {}),
|
|
237
|
+
});
|
|
238
|
+
return { t: "enum", name: named(decl.name) };
|
|
239
|
+
}
|
|
240
|
+
const fields = objectFields(decl.type, context);
|
|
241
|
+
if (fields) return struct(named(decl.name), fields, context, decl.doc);
|
|
242
|
+
if (decl.type.kind === "nullable")
|
|
243
|
+
throw new Unsupported(`${context}: ${node.name} includes null; write \`| null\` where it is used`);
|
|
244
|
+
return resolveType(decl.type, named(decl.name), context);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/** The strings of a string union member: a literal or an alias of one (also nested unions). */
|
|
250
|
+
const literalValues = (node: TypeNode, context: string, seen = new Set<string>()): string[] => {
|
|
251
|
+
if (node.kind === "literal") return node.values;
|
|
252
|
+
if (node.kind === "union") return node.of.flatMap((m) => literalValues(m, context, seen));
|
|
253
|
+
if (node.kind === "ref" && !seen.has(node.name)) {
|
|
254
|
+
seen.add(node.name);
|
|
255
|
+
const decl = lookup(spec, node.name);
|
|
256
|
+
if (decl?.kind === "alias") return literalValues(decl.type, context, seen);
|
|
257
|
+
}
|
|
258
|
+
throw new Unsupported(
|
|
259
|
+
`${context}: unions other than string literals and null are not supported (${node.kind === "ref" ? node.name : node.kind})`,
|
|
260
|
+
);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const extendsFileRef = (name: string, seen = new Set<string>()): boolean => {
|
|
264
|
+
const decl = lookup(spec, name);
|
|
265
|
+
if (decl?.kind !== "interface" || seen.has(name)) return false;
|
|
266
|
+
seen.add(name);
|
|
267
|
+
return decl.extends.some((parent) => parent === "FileRef" || extendsFileRef(parent, seen));
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const wanted = (list: string[] | undefined, name: string) => !list || list.includes(name);
|
|
271
|
+
const methods: GenMethod[] = [];
|
|
272
|
+
const counts = new Map<string, number>();
|
|
273
|
+
for (const m of spec.methods) counts.set(m.name, (counts.get(m.name) ?? 0) + 1);
|
|
274
|
+
const seen = new Set<string>();
|
|
275
|
+
for (const m of spec.methods) {
|
|
276
|
+
if (!wanted(options.methods, m.name) || seen.has(m.name)) continue;
|
|
277
|
+
seen.add(m.name);
|
|
278
|
+
methods.push(counts.get(m.name)! > 1 ? untypedMethod(m, "overloaded in the spec") : genMethod(m));
|
|
279
|
+
}
|
|
280
|
+
function genMethod(m: Method): GenMethod {
|
|
281
|
+
const base = { name: m.name, ...(m.doc ? { doc: m.doc } : {}) };
|
|
282
|
+
|
|
283
|
+
const snapshot = { structs: new Map(structs), enums: new Map(enums) };
|
|
284
|
+
try {
|
|
285
|
+
let args: string | undefined;
|
|
286
|
+
if (m.param) {
|
|
287
|
+
const context = `${m.name}(${m.param.name})`;
|
|
288
|
+
if (m.param.type.kind === "nullable") throw new Unsupported(`${context}: the argument cannot be null`);
|
|
289
|
+
const fields = objectFields(m.param.type, context);
|
|
290
|
+
if (!fields) throw new Unsupported(`${context}: the argument must be an object type`);
|
|
291
|
+
const hint = m.param.type.kind === "ref" ? named(m.param.type.name) : `${prefix}${pascal(m.name)}Args`;
|
|
292
|
+
args = (
|
|
293
|
+
struct(
|
|
294
|
+
hint,
|
|
295
|
+
fields,
|
|
296
|
+
context,
|
|
297
|
+
m.param.type.kind === "ref" ? lookup(spec, m.param.type.name)?.doc : undefined,
|
|
298
|
+
) as { name: string }
|
|
299
|
+
).name;
|
|
300
|
+
}
|
|
301
|
+
const result =
|
|
302
|
+
m.returns.kind === "void" ? null : resolve(m.returns, `${prefix}${pascal(m.name)}Result`, `${m.name}() result`);
|
|
303
|
+
return { ...base, ...(args ? { args } : {}), result };
|
|
304
|
+
} catch (error) {
|
|
305
|
+
if (!(error instanceof Unsupported)) throw error;
|
|
306
|
+
structs.clear();
|
|
307
|
+
enums.clear();
|
|
308
|
+
resolving.clear();
|
|
309
|
+
for (const [k, v] of snapshot.structs) structs.set(k, v);
|
|
310
|
+
for (const [k, v] of snapshot.enums) enums.set(k, v);
|
|
311
|
+
return untypedMethod(m, error.message);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function untypedMethod(m: Method, reason: string): GenMethod {
|
|
315
|
+
return { name: m.name, ...(m.doc ? { doc: m.doc } : {}), result: null, untyped: reason };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const events: GenEvent[] = [];
|
|
319
|
+
for (const e of spec.eventTypes) {
|
|
320
|
+
if (!wanted(options.events, e.name)) continue;
|
|
321
|
+
const snapshot = { structs: new Map(structs), enums: new Map(enums) };
|
|
322
|
+
try {
|
|
323
|
+
const { type, nullable } = resolve(e.type, `${prefix}${pascal(e.name)}Event`, `event ${e.name}`);
|
|
324
|
+
events.push({ name: e.name, ...(e.doc ? { doc: e.doc } : {}), type, nullable });
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (!(error instanceof Unsupported)) throw error;
|
|
327
|
+
structs.clear();
|
|
328
|
+
enums.clear();
|
|
329
|
+
resolving.clear();
|
|
330
|
+
for (const [k, v] of snapshot.structs) structs.set(k, v);
|
|
331
|
+
for (const [k, v] of snapshot.enums) enums.set(k, v);
|
|
332
|
+
events.push({
|
|
333
|
+
name: e.name,
|
|
334
|
+
...(e.doc ? { doc: e.doc } : {}),
|
|
335
|
+
type: null,
|
|
336
|
+
nullable: true,
|
|
337
|
+
untyped: error.message,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const sortByName = <T extends { name: string }>(list: Iterable<T>) =>
|
|
343
|
+
[...list].sort((a, b) => a.name.localeCompare(b.name));
|
|
344
|
+
return {
|
|
345
|
+
pluginId,
|
|
346
|
+
prefix,
|
|
347
|
+
source: options.source ?? spec.file,
|
|
348
|
+
structs: sortByName(structs.values()),
|
|
349
|
+
enums: sortByName(enums.values()),
|
|
350
|
+
methods,
|
|
351
|
+
events,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function unsupportedNullableItem(context: string): never {
|
|
356
|
+
throw new Unsupported(`${context}: null items in arrays and records are not supported`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const SWIFT_KEYWORDS = new Set(
|
|
360
|
+
"associatedtype class deinit enum extension fileprivate func import init inout internal let operator private precedencegroup protocol public rethrows static struct subscript typealias var break case catch continue default defer do else fallthrough for guard if in repeat return throw switch where while Any as await false is nil self Self super throws true try".split(
|
|
361
|
+
" ",
|
|
362
|
+
),
|
|
363
|
+
);
|
|
364
|
+
const KOTLIN_KEYWORDS = new Set(
|
|
365
|
+
"as break class continue do else false for fun if in interface is null object package return super this throw true try typealias typeof val var when while".split(
|
|
366
|
+
" ",
|
|
367
|
+
),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const swiftName = (name: string) => (SWIFT_KEYWORDS.has(name) ? `\`${name}\`` : name);
|
|
371
|
+
const kotlinName = (name: string) => (KOTLIN_KEYWORDS.has(name) ? `\`${name}\`` : name);
|
|
372
|
+
|
|
373
|
+
function checkIdentifier(model: GenModel, name: string, what: string) {
|
|
374
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
375
|
+
throw new CliError(`plugin ${model.pluginId}: ${what} "${name}" is not a valid Swift / Kotlin identifier`);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** Enum case names: lowerCamel for Swift, UPPER_SNAKE for Kotlin, unique within the enum. */
|
|
379
|
+
function caseNames(model: GenModel, e: GenEnum, style: "camel" | "snake"): string[] {
|
|
380
|
+
const words = (value: string) =>
|
|
381
|
+
value
|
|
382
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
383
|
+
.split(/[^A-Za-z0-9]+/)
|
|
384
|
+
.filter(Boolean);
|
|
385
|
+
const names = e.values.map((value) => {
|
|
386
|
+
const w = words(value);
|
|
387
|
+
let name =
|
|
388
|
+
style === "camel"
|
|
389
|
+
? w.map((x, i) => (i === 0 ? x.toLowerCase() : x[0]!.toUpperCase() + x.slice(1).toLowerCase())).join("")
|
|
390
|
+
: w.map((x) => x.toUpperCase()).join("_");
|
|
391
|
+
if (!name) name = style === "camel" ? "empty" : "EMPTY";
|
|
392
|
+
if (/^\d/.test(name)) name = `_${name}`;
|
|
393
|
+
|
|
394
|
+
if (style === "camel" && (name === "none" || name === "some")) name = `${name}_`;
|
|
395
|
+
return name;
|
|
396
|
+
});
|
|
397
|
+
const dup = names.find((n, i) => names.indexOf(n) !== i);
|
|
398
|
+
if (dup) throw new CliError(`plugin ${model.pluginId}: the values of ${e.name} map to the same case name ${dup}`);
|
|
399
|
+
return names;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Kotlin block comments nest, so "image/*" in a KDoc would open a comment that never closes. */
|
|
403
|
+
const kdocSafe = (text: string) => text.replaceAll("*/", "*\\/").replaceAll("/*", "/\\*");
|
|
404
|
+
|
|
405
|
+
const docLines = (doc: string | undefined, indent: string, marker: "///" | "*") =>
|
|
406
|
+
doc
|
|
407
|
+
? marker === "///"
|
|
408
|
+
? doc.split("\n").map((l) => `${indent}/// ${l}`.trimEnd())
|
|
409
|
+
: [`${indent}/**`, ...doc.split("\n").map((l) => `${indent} * ${kdocSafe(l)}`.trimEnd()), `${indent} */`]
|
|
410
|
+
: [];
|
|
411
|
+
|
|
412
|
+
const header = (model: GenModel) =>
|
|
413
|
+
`Generated by akan-native from ${model.source} (PL-10). Do not edit: every build rewrites it.`;
|
|
414
|
+
|
|
415
|
+
function methodsCollide(model: GenModel, reserved: string[]) {
|
|
416
|
+
for (const m of model.methods) {
|
|
417
|
+
checkIdentifier(model, m.name, "method");
|
|
418
|
+
if (reserved.includes(m.name))
|
|
419
|
+
throw new CliError(`plugin ${model.pluginId}: method ${m.name} clashes with the plugin protocol's own ${m.name}`);
|
|
420
|
+
}
|
|
421
|
+
for (const e of model.events) checkIdentifier(model, e.name, "event");
|
|
422
|
+
for (const s of model.structs) for (const f of s.fields) checkIdentifier(model, f.name, `field ${s.name}.`);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function swiftType(type: GenType): string {
|
|
426
|
+
switch (type.t) {
|
|
427
|
+
case "string":
|
|
428
|
+
return "String";
|
|
429
|
+
case "number":
|
|
430
|
+
return "Double";
|
|
431
|
+
case "boolean":
|
|
432
|
+
return "Bool";
|
|
433
|
+
case "any":
|
|
434
|
+
return "Any";
|
|
435
|
+
case "enum":
|
|
436
|
+
case "struct":
|
|
437
|
+
return type.name;
|
|
438
|
+
case "array":
|
|
439
|
+
return `[${swiftType(type.of)}]`;
|
|
440
|
+
case "map":
|
|
441
|
+
return `[String: ${swiftType(type.of)}]`;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Expression decoding `value` (an Any?) at `path` (a String expression). */
|
|
446
|
+
function swiftDecode(type: GenType, value: string, path: string, depth = 0): string {
|
|
447
|
+
switch (type.t) {
|
|
448
|
+
case "string":
|
|
449
|
+
return `try AkanNativeJSON.string(${value}, ${path})`;
|
|
450
|
+
case "number":
|
|
451
|
+
return `try AkanNativeJSON.number(${value}, ${path})`;
|
|
452
|
+
case "boolean":
|
|
453
|
+
return `try AkanNativeJSON.bool(${value}, ${path})`;
|
|
454
|
+
case "any":
|
|
455
|
+
return `try AkanNativeJSON.any(${value}, ${path})`;
|
|
456
|
+
case "enum":
|
|
457
|
+
case "struct":
|
|
458
|
+
return `try ${type.name}(akanNative: ${value}, at: ${path})`;
|
|
459
|
+
case "array":
|
|
460
|
+
return `try AkanNativeJSON.array(${value}, ${path}) { v${depth}, p${depth} in ${swiftDecode(type.of, `v${depth}`, `p${depth}`, depth + 1)} }`;
|
|
461
|
+
case "map":
|
|
462
|
+
return `try AkanNativeJSON.map(${value}, ${path}) { v${depth}, p${depth} in ${swiftDecode(type.of, `v${depth}`, `p${depth}`, depth + 1)} }`;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function swiftEncode(type: GenType, value: string, depth = 0): string {
|
|
467
|
+
switch (type.t) {
|
|
468
|
+
case "string":
|
|
469
|
+
case "number":
|
|
470
|
+
case "boolean":
|
|
471
|
+
case "any":
|
|
472
|
+
return value;
|
|
473
|
+
case "enum":
|
|
474
|
+
return `${value}.rawValue`;
|
|
475
|
+
case "struct":
|
|
476
|
+
return `${value}.akanNativeJSON`;
|
|
477
|
+
case "array":
|
|
478
|
+
return type.of.t === "string" || type.of.t === "number" || type.of.t === "boolean"
|
|
479
|
+
? value
|
|
480
|
+
: `${value}.map { e${depth} in ${swiftEncode(type.of, `e${depth}`, depth + 1)} }`;
|
|
481
|
+
case "map":
|
|
482
|
+
return type.of.t === "string" || type.of.t === "number" || type.of.t === "boolean"
|
|
483
|
+
? value
|
|
484
|
+
: `${value}.mapValues { e${depth} in ${swiftEncode(type.of, `e${depth}`, depth + 1)} }`;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const hasAny = (type: GenType, model: GenModel, seen = new Set<string>()): boolean => {
|
|
489
|
+
if (type.t === "any") return true;
|
|
490
|
+
if (type.t === "array" || type.t === "map") return hasAny(type.of, model, seen);
|
|
491
|
+
if (type.t === "struct" && !seen.has(type.name)) {
|
|
492
|
+
seen.add(type.name);
|
|
493
|
+
return model.structs.find((s) => s.name === type.name)?.fields.some((f) => hasAny(f.type, model, seen)) ?? false;
|
|
494
|
+
}
|
|
495
|
+
return false;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
const FILE_REF_FIELDS = ["url", "mime", "size"];
|
|
499
|
+
|
|
500
|
+
const replyType = (m: GenMethod, lang: "swift" | "kotlin") =>
|
|
501
|
+
m.result === null
|
|
502
|
+
? lang === "swift"
|
|
503
|
+
? "Void"
|
|
504
|
+
: "Unit"
|
|
505
|
+
: `${lang === "swift" ? swiftType(m.result.type) : kotlinType(m.result.type)}${m.result.nullable ? "?" : ""}`;
|
|
506
|
+
|
|
507
|
+
export function generateSwift(model: GenModel): string {
|
|
508
|
+
methodsCollide(model, ["handle", "startListening", "stopListening"]);
|
|
509
|
+
const out: string[] = [`// ${header(model)}`, "", "import Foundation", ""];
|
|
510
|
+
|
|
511
|
+
for (const e of model.enums) {
|
|
512
|
+
const cases = caseNames(model, e, "camel");
|
|
513
|
+
out.push(...docLines(e.doc, "", "///"));
|
|
514
|
+
out.push(`enum ${e.name}: String, Sendable, CaseIterable {`);
|
|
515
|
+
for (const [i, value] of e.values.entries())
|
|
516
|
+
out.push(` case ${swiftName(cases[i]!)} = ${JSON.stringify(value)}`);
|
|
517
|
+
out.push(
|
|
518
|
+
"",
|
|
519
|
+
" init(akanNative value: Any?, at path: String) throws {",
|
|
520
|
+
` self = try AkanNativeJSON.literal(value, path, Self.self)`,
|
|
521
|
+
" }",
|
|
522
|
+
"}",
|
|
523
|
+
"",
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
for (const s of model.structs) {
|
|
528
|
+
|
|
529
|
+
const conformances = s.fields.some((f) => hasAny(f.type, model)) ? "@unchecked Sendable" : "Sendable, Equatable";
|
|
530
|
+
out.push(...docLines(s.doc, "", "///"));
|
|
531
|
+
out.push(`struct ${s.name}: ${conformances} {`);
|
|
532
|
+
for (const f of s.fields) {
|
|
533
|
+
out.push(...docLines(f.doc, " ", "///"));
|
|
534
|
+
out.push(
|
|
535
|
+
` var ${swiftName(f.name)}: ${swiftType(f.type)}${f.optional || f.nullable || f.type.t === "any" ? "?" : ""}`,
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const params = s.fields.map(
|
|
540
|
+
(f) =>
|
|
541
|
+
`${swiftName(f.name)}: ${swiftType(f.type)}${f.optional || f.nullable || f.type.t === "any" ? "? = nil" : ""}`,
|
|
542
|
+
);
|
|
543
|
+
if (s.fields.length) {
|
|
544
|
+
out.push("", ` init(${params.join(", ")}) {`);
|
|
545
|
+
for (const f of s.fields) out.push(` self.${f.name} = ${swiftName(f.name)}`);
|
|
546
|
+
out.push(" }", "");
|
|
547
|
+
} else out.push(" init() {}", "");
|
|
548
|
+
if (s.fileRef) {
|
|
549
|
+
const rest = s.fields.filter((f) => !FILE_REF_FIELDS.includes(f.name));
|
|
550
|
+
const restParams = rest.map(
|
|
551
|
+
(f) =>
|
|
552
|
+
`${swiftName(f.name)}: ${swiftType(f.type)}${f.optional || f.nullable || f.type.t === "any" ? "? = nil" : ""}`,
|
|
553
|
+
);
|
|
554
|
+
const args = s.fields.map(
|
|
555
|
+
(f) => `${swiftName(f.name)}: ${FILE_REF_FIELDS.includes(f.name) ? `file.${f.name}` : swiftName(f.name)}`,
|
|
556
|
+
);
|
|
557
|
+
out.push(
|
|
558
|
+
` init(${["file: AkanNativeFileRef", ...restParams].join(", ")}) {`,
|
|
559
|
+
` self.init(${args.join(", ")})`,
|
|
560
|
+
" }",
|
|
561
|
+
"",
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
out.push(
|
|
565
|
+
" init(akanNative value: Any?, at path: String) throws {",
|
|
566
|
+
` ${s.fields.length ? "let o =" : "_ ="} try AkanNativeJSON.object(value, path)`,
|
|
567
|
+
);
|
|
568
|
+
for (const f of s.fields) {
|
|
569
|
+
const key = JSON.stringify(f.name);
|
|
570
|
+
const decode = swiftDecode(f.type, "$0", `AkanNativeJSON.key(path, ${key})`);
|
|
571
|
+
if (f.optional || f.nullable || f.type.t === "any")
|
|
572
|
+
out.push(` self.${f.name} = try AkanNativeJSON.optional(o[${key}]) { ${decode} }`);
|
|
573
|
+
else out.push(` self.${f.name} = ${swiftDecode(f.type, `o[${key}]`, `AkanNativeJSON.key(path, ${key})`)}`);
|
|
574
|
+
}
|
|
575
|
+
out.push(" }", "");
|
|
576
|
+
out.push(
|
|
577
|
+
" var akanNativeJSON: [String: Any] {",
|
|
578
|
+
` ${s.fields.length ? "var" : "let"} o: [String: Any] = [:]`,
|
|
579
|
+
);
|
|
580
|
+
for (const f of s.fields) {
|
|
581
|
+
const key = JSON.stringify(f.name);
|
|
582
|
+
const self = `self.${f.name}`;
|
|
583
|
+
if (f.optional || f.nullable || f.type.t === "any") {
|
|
584
|
+
const nullValue = f.nullable && !f.optional ? "NSNull()" : null;
|
|
585
|
+
out.push(
|
|
586
|
+
` if let v = ${self} { o[${key}] = ${swiftEncode(f.type, "v")} }${nullValue ? ` else { o[${key}] = ${nullValue} }` : ""}`,
|
|
587
|
+
);
|
|
588
|
+
} else out.push(` o[${key}] = ${swiftEncode(f.type, self)}`);
|
|
589
|
+
}
|
|
590
|
+
out.push(" return o", " }", "}", "");
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const protocol = `${model.prefix}PluginSpec`;
|
|
594
|
+
out.push(
|
|
595
|
+
`/// The ${model.pluginId} API as Swift methods. Conform the plugin class to this instead of writing handle(_:).`,
|
|
596
|
+
);
|
|
597
|
+
out.push("@MainActor", `protocol ${protocol}: AkanNativePlugin {`);
|
|
598
|
+
for (const m of model.methods) {
|
|
599
|
+
out.push(...docLines(m.doc, " ", "///"));
|
|
600
|
+
if (m.untyped) {
|
|
601
|
+
out.push(` /// Untyped: ${m.untyped}.`, ` func ${swiftName(m.name)}(_ call: AkanNativeCall)`);
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
const params = [...(m.args ? [`_ args: ${m.args}`] : []), `_ reply: AkanNativeReply<${replyType(m, "swift")}>`];
|
|
605
|
+
out.push(` func ${swiftName(m.name)}(${params.join(", ")})`);
|
|
606
|
+
}
|
|
607
|
+
out.push("}", "");
|
|
608
|
+
out.push(
|
|
609
|
+
`extension ${protocol} {`,
|
|
610
|
+
" func handle(_ call: AkanNativeCall) {",
|
|
611
|
+
" akanNativeDispatch(call)",
|
|
612
|
+
" }",
|
|
613
|
+
"",
|
|
614
|
+
" /// The generated dispatch: a plugin that implements handle(_:) itself can still end with it.",
|
|
615
|
+
" func akanNativeDispatch(_ call: AkanNativeCall) {",
|
|
616
|
+
" switch call.method {",
|
|
617
|
+
);
|
|
618
|
+
for (const m of model.methods) {
|
|
619
|
+
out.push(` case ${JSON.stringify(m.name)}:`);
|
|
620
|
+
if (m.untyped) {
|
|
621
|
+
out.push(` ${swiftName(m.name)}(call)`);
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
const reply =
|
|
625
|
+
m.result === null
|
|
626
|
+
? "AkanNativeReply(call) { _ in nil }"
|
|
627
|
+
: `AkanNativeReply(call) { ${m.result.nullable ? `$0.map { ${swiftEncode(m.result.type, "$0")} } ?? NSNull()` : swiftEncode(m.result.type, "$0")} }`;
|
|
628
|
+
if (m.args) {
|
|
629
|
+
out.push(
|
|
630
|
+
` guard let args = AkanNativeJSON.decode(call, { try ${m.args}(akanNative: $0, at: "") }) else { return }`,
|
|
631
|
+
);
|
|
632
|
+
out.push(` ${swiftName(m.name)}(args, ${reply})`);
|
|
633
|
+
} else out.push(` ${swiftName(m.name)}(${reply})`);
|
|
634
|
+
}
|
|
635
|
+
out.push(
|
|
636
|
+
" default:",
|
|
637
|
+
' call.reject(.notFound, "unknown method \\(call.method)")',
|
|
638
|
+
" }",
|
|
639
|
+
" }",
|
|
640
|
+
"}",
|
|
641
|
+
"",
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
if (model.events.length) {
|
|
645
|
+
out.push(
|
|
646
|
+
`/// Typed emit for the ${model.pluginId} events: \`${model.prefix}Events(context).${model.events[0]!.name}(…)\`.`,
|
|
647
|
+
);
|
|
648
|
+
out.push(
|
|
649
|
+
"@MainActor",
|
|
650
|
+
`struct ${model.prefix}Events {`,
|
|
651
|
+
" let context: AkanNativePluginContext",
|
|
652
|
+
"",
|
|
653
|
+
" init(_ context: AkanNativePluginContext) {",
|
|
654
|
+
" self.context = context",
|
|
655
|
+
" }",
|
|
656
|
+
);
|
|
657
|
+
for (const e of model.events) {
|
|
658
|
+
out.push("");
|
|
659
|
+
out.push(...docLines(e.doc, " ", "///"));
|
|
660
|
+
if (!e.type) {
|
|
661
|
+
out.push(
|
|
662
|
+
` /// Untyped: ${e.untyped}.`,
|
|
663
|
+
` func ${swiftName(e.name)}(_ data: Any?) {`,
|
|
664
|
+
` context.emit(${JSON.stringify(e.name)}, data)`,
|
|
665
|
+
" }",
|
|
666
|
+
);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
const t = `${swiftType(e.type)}${e.nullable ? "?" : ""}`;
|
|
670
|
+
const value = e.nullable ? `data.map { ${swiftEncode(e.type, "$0")} } ?? NSNull()` : swiftEncode(e.type, "data");
|
|
671
|
+
out.push(
|
|
672
|
+
` func ${swiftName(e.name)}(_ data: ${t}) {`,
|
|
673
|
+
` context.emit(${JSON.stringify(e.name)}, ${value})`,
|
|
674
|
+
" }",
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
out.push("}", "");
|
|
678
|
+
}
|
|
679
|
+
return out.join("\n");
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function kotlinType(type: GenType): string {
|
|
683
|
+
switch (type.t) {
|
|
684
|
+
case "string":
|
|
685
|
+
return "String";
|
|
686
|
+
case "number":
|
|
687
|
+
return "Double";
|
|
688
|
+
case "boolean":
|
|
689
|
+
return "Boolean";
|
|
690
|
+
case "any":
|
|
691
|
+
return "Any";
|
|
692
|
+
case "enum":
|
|
693
|
+
case "struct":
|
|
694
|
+
return type.name;
|
|
695
|
+
case "array":
|
|
696
|
+
return `List<${kotlinType(type.of)}>`;
|
|
697
|
+
case "map":
|
|
698
|
+
return `Map<String, ${kotlinType(type.of)}>`;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function kotlinDecode(type: GenType, value: string, path: string, depth = 0): string {
|
|
703
|
+
switch (type.t) {
|
|
704
|
+
case "string":
|
|
705
|
+
return `AkanNativeJson.string(${value}, ${path})`;
|
|
706
|
+
case "number":
|
|
707
|
+
return `AkanNativeJson.number(${value}, ${path})`;
|
|
708
|
+
case "boolean":
|
|
709
|
+
return `AkanNativeJson.bool(${value}, ${path})`;
|
|
710
|
+
case "any":
|
|
711
|
+
return `AkanNativeJson.any(${value}, ${path})`;
|
|
712
|
+
case "enum":
|
|
713
|
+
case "struct":
|
|
714
|
+
return `${type.name}.fromAkanNative(${value}, ${path})`;
|
|
715
|
+
case "array":
|
|
716
|
+
return `AkanNativeJson.array(${value}, ${path}) { v${depth}, p${depth} -> ${kotlinDecode(type.of, `v${depth}`, `p${depth}`, depth + 1)} }`;
|
|
717
|
+
case "map":
|
|
718
|
+
return `AkanNativeJson.map(${value}, ${path}) { v${depth}, p${depth} -> ${kotlinDecode(type.of, `v${depth}`, `p${depth}`, depth + 1)} }`;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function kotlinEncode(type: GenType, value: string, depth = 0): string {
|
|
723
|
+
switch (type.t) {
|
|
724
|
+
case "string":
|
|
725
|
+
case "number":
|
|
726
|
+
case "boolean":
|
|
727
|
+
case "any":
|
|
728
|
+
return value;
|
|
729
|
+
case "enum":
|
|
730
|
+
return `${value}.json`;
|
|
731
|
+
case "struct":
|
|
732
|
+
return `${value}.toAkanNative()`;
|
|
733
|
+
case "array":
|
|
734
|
+
return `AkanNativeJson.list(${value}) { e${depth} -> ${kotlinEncode(type.of, `e${depth}`, depth + 1)} }`;
|
|
735
|
+
case "map":
|
|
736
|
+
return `AkanNativeJson.dict(${value}) { e${depth} -> ${kotlinEncode(type.of, `e${depth}`, depth + 1)} }`;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export function generateKotlin(model: GenModel, pkg: string): string {
|
|
741
|
+
methodsCollide(model, [
|
|
742
|
+
"handle",
|
|
743
|
+
"startListening",
|
|
744
|
+
"stopListening",
|
|
745
|
+
"onNewIntent",
|
|
746
|
+
"onConfigurationChanged",
|
|
747
|
+
"onRestoredActivityResult",
|
|
748
|
+
"destroy",
|
|
749
|
+
]);
|
|
750
|
+
const out: string[] = [
|
|
751
|
+
`// ${header(model)}`,
|
|
752
|
+
`package ${pkg}`,
|
|
753
|
+
"",
|
|
754
|
+
"import com.akanjs.runtime.AkanNativeCall",
|
|
755
|
+
"import com.akanjs.runtime.AkanNativeErrorCode",
|
|
756
|
+
"import com.akanjs.runtime.AkanNativeFileRef",
|
|
757
|
+
"import com.akanjs.runtime.AkanNativeJson",
|
|
758
|
+
"import com.akanjs.runtime.AkanNativePlugin",
|
|
759
|
+
"import com.akanjs.runtime.AkanNativePluginContext",
|
|
760
|
+
"import com.akanjs.runtime.AkanNativeReply",
|
|
761
|
+
"import com.akanjs.runtime.AkanNativeVoidReply",
|
|
762
|
+
"import org.json.JSONObject",
|
|
763
|
+
"",
|
|
764
|
+
];
|
|
765
|
+
|
|
766
|
+
for (const e of model.enums) {
|
|
767
|
+
const cases = caseNames(model, e, "snake");
|
|
768
|
+
out.push(...docLines(e.doc, "", "*"));
|
|
769
|
+
out.push(`enum class ${e.name}(val json: String) {`);
|
|
770
|
+
for (const [i, value] of e.values.entries())
|
|
771
|
+
out.push(` ${kotlinName(cases[i]!)}(${JSON.stringify(value)})${i === e.values.length - 1 ? ";" : ","}`);
|
|
772
|
+
out.push(
|
|
773
|
+
"",
|
|
774
|
+
" companion object {",
|
|
775
|
+
` /** The entry for a JSON value, e.g. a state string from the platform; null if unknown. */`,
|
|
776
|
+
` fun from(json: String): ${e.name}? = entries.firstOrNull { it.json == json }`,
|
|
777
|
+
"",
|
|
778
|
+
` fun fromAkanNative(value: Any?, path: String): ${e.name} {`,
|
|
779
|
+
' if (AkanNativeJson.isNull(value)) AkanNativeJson.string(value, path) // "… is required"',
|
|
780
|
+
` return (value as? String)?.let(::from) ?: throw AkanNativeJson.invalid(path, "one of " + entries.joinToString { it.json })`,
|
|
781
|
+
" }",
|
|
782
|
+
" }",
|
|
783
|
+
"}",
|
|
784
|
+
"",
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
for (const s of model.structs) {
|
|
789
|
+
const nullableType = (f: GenField) => f.optional || f.nullable || f.type.t === "any";
|
|
790
|
+
out.push(...docLines(s.doc, "", "*"));
|
|
791
|
+
if (s.fields.length) {
|
|
792
|
+
out.push(`data class ${s.name}(`);
|
|
793
|
+
for (const f of s.fields) {
|
|
794
|
+
out.push(...docLines(f.doc, " ", "*"));
|
|
795
|
+
out.push(` val ${kotlinName(f.name)}: ${kotlinType(f.type)}${nullableType(f) ? "? = null" : ""},`);
|
|
796
|
+
}
|
|
797
|
+
out.push(") {");
|
|
798
|
+
} else out.push(`class ${s.name} {`);
|
|
799
|
+
if (s.fileRef) {
|
|
800
|
+
const rest = s.fields.filter((f) => !FILE_REF_FIELDS.includes(f.name));
|
|
801
|
+
const restParams = rest.map(
|
|
802
|
+
(f) => `${kotlinName(f.name)}: ${kotlinType(f.type)}${nullableType(f) ? "? = null" : ""}`,
|
|
803
|
+
);
|
|
804
|
+
const args = s.fields.map(
|
|
805
|
+
(f) => `${kotlinName(f.name)} = ${FILE_REF_FIELDS.includes(f.name) ? `file.${f.name}` : kotlinName(f.name)}`,
|
|
806
|
+
);
|
|
807
|
+
out.push(
|
|
808
|
+
` constructor(${["file: AkanNativeFileRef", ...restParams].join(", ")}) : this(${args.join(", ")})`,
|
|
809
|
+
"",
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
out.push(" fun toAkanNative(): JSONObject {", " val o = JSONObject()");
|
|
813
|
+
for (const f of s.fields) {
|
|
814
|
+
const key = JSON.stringify(f.name);
|
|
815
|
+
const self = `this.${kotlinName(f.name)}`;
|
|
816
|
+
if (nullableType(f)) {
|
|
817
|
+
const nullValue = f.nullable && !f.optional ? " ?: JSONObject.NULL" : "";
|
|
818
|
+
const encoded = kotlinEncode(f.type, "it");
|
|
819
|
+
if (nullValue)
|
|
820
|
+
out.push(` o.put(${key}, ${encoded === "it" ? self : `${self}?.let { ${encoded} }`}${nullValue})`);
|
|
821
|
+
else out.push(` ${self}?.let { o.put(${key}, ${kotlinEncode(f.type, "it")}) }`);
|
|
822
|
+
} else out.push(` o.put(${key}, ${kotlinEncode(f.type, self)})`);
|
|
823
|
+
}
|
|
824
|
+
out.push(
|
|
825
|
+
" return o",
|
|
826
|
+
" }",
|
|
827
|
+
"",
|
|
828
|
+
" companion object {",
|
|
829
|
+
` fun fromAkanNative(value: Any?, path: String): ${s.name} {`,
|
|
830
|
+
` ${s.fields.length ? "val o = " : ""}AkanNativeJson.obj(value, path)`,
|
|
831
|
+
);
|
|
832
|
+
out.push(` return ${s.name}(`);
|
|
833
|
+
for (const f of s.fields) {
|
|
834
|
+
const key = JSON.stringify(f.name);
|
|
835
|
+
const decode = kotlinDecode(f.type, "v", `AkanNativeJson.key(path, ${key})`);
|
|
836
|
+
if (nullableType(f))
|
|
837
|
+
out.push(` ${kotlinName(f.name)} = AkanNativeJson.optional(o.opt(${key})) { v -> ${decode} },`);
|
|
838
|
+
else
|
|
839
|
+
out.push(
|
|
840
|
+
` ${kotlinName(f.name)} = ${kotlinDecode(f.type, `o.opt(${key})`, `AkanNativeJson.key(path, ${key})`)},`,
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
out.push(" )", " }", " }", "}", "");
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const iface = `${model.prefix}PluginSpec`;
|
|
847
|
+
out.push(`/** The ${model.pluginId} API as Kotlin methods. Implement this instead of writing handle(call). */`);
|
|
848
|
+
out.push(`interface ${iface} : AkanNativePlugin {`);
|
|
849
|
+
for (const m of model.methods) {
|
|
850
|
+
if (m.untyped) {
|
|
851
|
+
const note = `Untyped: ${m.untyped}.`;
|
|
852
|
+
out.push(
|
|
853
|
+
...docLines(m.doc ? `${m.doc}\n\n${note}` : note, " ", "*"),
|
|
854
|
+
` fun ${kotlinName(m.name)}(call: AkanNativeCall)`,
|
|
855
|
+
"",
|
|
856
|
+
);
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
out.push(...docLines(m.doc, " ", "*"));
|
|
860
|
+
const params = [
|
|
861
|
+
...(m.args ? [`args: ${m.args}`] : []),
|
|
862
|
+
`reply: ${m.result === null ? "AkanNativeVoidReply" : `AkanNativeReply<${replyType(m, "kotlin")}>`}`,
|
|
863
|
+
];
|
|
864
|
+
out.push(` fun ${kotlinName(m.name)}(${params.join(", ")})`, "");
|
|
865
|
+
}
|
|
866
|
+
out.push(
|
|
867
|
+
" override fun handle(call: AkanNativeCall) = akanNativeDispatch(call)",
|
|
868
|
+
"",
|
|
869
|
+
" /** The generated dispatch: a plugin that overrides handle(call) itself can still end with it. */",
|
|
870
|
+
" fun akanNativeDispatch(call: AkanNativeCall) {",
|
|
871
|
+
" when (call.method) {",
|
|
872
|
+
);
|
|
873
|
+
for (const m of model.methods) {
|
|
874
|
+
if (m.untyped) {
|
|
875
|
+
out.push(` ${JSON.stringify(m.name)} -> ${kotlinName(m.name)}(call)`);
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
const reply =
|
|
879
|
+
m.result === null
|
|
880
|
+
? "AkanNativeVoidReply(call)"
|
|
881
|
+
: `AkanNativeReply(call) { ${m.result.nullable ? `it?.let { v -> ${kotlinEncode(m.result.type, "v")} } ?: JSONObject.NULL` : kotlinEncode(m.result.type, "it")} }`;
|
|
882
|
+
if (m.args) {
|
|
883
|
+
out.push(
|
|
884
|
+
` ${JSON.stringify(m.name)} -> {`,
|
|
885
|
+
` val args = AkanNativeJson.decode(call) { ${m.args}.fromAkanNative(it, "") } ?: return`,
|
|
886
|
+
` ${kotlinName(m.name)}(args, ${reply})`,
|
|
887
|
+
" }",
|
|
888
|
+
);
|
|
889
|
+
} else out.push(` ${JSON.stringify(m.name)} -> ${kotlinName(m.name)}(${reply})`);
|
|
890
|
+
}
|
|
891
|
+
out.push(
|
|
892
|
+
' else -> call.reject(AkanNativeErrorCode.NOT_FOUND, "unknown method ${call.method}")',
|
|
893
|
+
" }",
|
|
894
|
+
" }",
|
|
895
|
+
"}",
|
|
896
|
+
"",
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
if (model.events.length) {
|
|
900
|
+
out.push(
|
|
901
|
+
`/** Typed emit for the ${model.pluginId} events: \`${model.prefix}Events(context).${model.events[0]!.name}(…)\`. */`,
|
|
902
|
+
);
|
|
903
|
+
out.push(`class ${model.prefix}Events(private val context: AkanNativePluginContext) {`);
|
|
904
|
+
for (const e of model.events) {
|
|
905
|
+
out.push(...docLines(e.doc, " ", "*"));
|
|
906
|
+
if (!e.type) {
|
|
907
|
+
out.push(
|
|
908
|
+
` /** Untyped: ${kdocSafe(e.untyped!)}. */`,
|
|
909
|
+
` fun ${kotlinName(e.name)}(data: Any?) = context.emit(${JSON.stringify(e.name)}, data)`,
|
|
910
|
+
"",
|
|
911
|
+
);
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
const t = `${kotlinType(e.type)}${e.nullable ? "?" : ""}`;
|
|
915
|
+
const value = e.nullable
|
|
916
|
+
? `data?.let { ${kotlinEncode(e.type, "it")} } ?: JSONObject.NULL`
|
|
917
|
+
: kotlinEncode(e.type, "data");
|
|
918
|
+
out.push(` fun ${kotlinName(e.name)}(data: ${t}) = context.emit(${JSON.stringify(e.name)}, ${value})`, "");
|
|
919
|
+
}
|
|
920
|
+
if (out.at(-1) === "") out.pop();
|
|
921
|
+
out.push("}", "");
|
|
922
|
+
}
|
|
923
|
+
return out.join("\n");
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** Where the spec and the manifest disagree (method and event names, platform subsets). */
|
|
927
|
+
export function specProblems(manifest: PluginManifest, spec: PluginSpec): string[] {
|
|
928
|
+
const problems: string[] = [];
|
|
929
|
+
const names = [...new Set(spec.methods.map((m) => m.name))];
|
|
930
|
+
const events = spec.eventTypes.map((e) => e.name);
|
|
931
|
+
const where = `${spec.api}${spec.events ? ` / ${spec.events}` : ""}`;
|
|
932
|
+
for (const m of manifest.methods)
|
|
933
|
+
if (!names.includes(m)) problems.push(`method ${m} is in native-plugin.json but not in ${where}`);
|
|
934
|
+
for (const m of names)
|
|
935
|
+
if (!manifest.methods.includes(m)) problems.push(`method ${m} is in ${where} but not in native-plugin.json`);
|
|
936
|
+
for (const e of manifest.events)
|
|
937
|
+
if (!events.includes(e))
|
|
938
|
+
problems.push(
|
|
939
|
+
`event ${e} is in native-plugin.json but not in ${spec.events ?? "an Events interface (definePlugin<Api, Events>)"}`,
|
|
940
|
+
);
|
|
941
|
+
for (const e of events)
|
|
942
|
+
if (!manifest.events.includes(e)) problems.push(`event ${e} is in ${spec.events} but not in native-plugin.json`);
|
|
943
|
+
for (const platform of ["ios", "android", "desktop"] as const) {
|
|
944
|
+
const entry = manifest[platform];
|
|
945
|
+
if (!entry || typeof entry !== "object") continue;
|
|
946
|
+
for (const m of entry.methods ?? [])
|
|
947
|
+
if (!manifest.methods.includes(m)) problems.push(`${platform}.methods lists ${m}, which is not a method`);
|
|
948
|
+
for (const e of entry.events ?? [])
|
|
949
|
+
if (!manifest.events.includes(e)) problems.push(`${platform}.events lists ${e}, which is not an event`);
|
|
950
|
+
}
|
|
951
|
+
for (const e of spec.eventTypes) {
|
|
952
|
+
const bytes = byteType(e.type, spec.declarations);
|
|
953
|
+
if (bytes)
|
|
954
|
+
problems.push(
|
|
955
|
+
`event ${e.name} carries ${bytes}: events are JSON; send a FileRef (or base64 for a few bytes) instead`,
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
return problems;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/** Binary types that must not travel in an event (architecture review stage 4: bytes are owned, and only FileRefs carry them). */
|
|
962
|
+
const BYTE_TYPES = new Set([
|
|
963
|
+
"Uint8Array",
|
|
964
|
+
"Uint8ClampedArray",
|
|
965
|
+
"Int8Array",
|
|
966
|
+
"Uint16Array",
|
|
967
|
+
"Int16Array",
|
|
968
|
+
"Uint32Array",
|
|
969
|
+
"Int32Array",
|
|
970
|
+
"Float32Array",
|
|
971
|
+
"Float64Array",
|
|
972
|
+
"BigInt64Array",
|
|
973
|
+
"BigUint64Array",
|
|
974
|
+
"ArrayBuffer",
|
|
975
|
+
"SharedArrayBuffer",
|
|
976
|
+
"DataView",
|
|
977
|
+
"Blob",
|
|
978
|
+
"File",
|
|
979
|
+
"Buffer",
|
|
980
|
+
]);
|
|
981
|
+
|
|
982
|
+
/** The first binary type a payload type reaches, through the spec's own declarations, or null. */
|
|
983
|
+
function byteType(node: TypeNode, declarations: Map<string, Declaration>, seen = new Set<string>()): string | null {
|
|
984
|
+
switch (node.kind) {
|
|
985
|
+
case "ref": {
|
|
986
|
+
if (BYTE_TYPES.has(node.name)) return node.name;
|
|
987
|
+
if (seen.has(node.name)) return null;
|
|
988
|
+
seen.add(node.name);
|
|
989
|
+
const decl = declarations.get(node.name);
|
|
990
|
+
if (!decl) return null;
|
|
991
|
+
if (decl.kind === "alias") return byteType(decl.type, declarations, seen);
|
|
992
|
+
for (const f of decl.fields) {
|
|
993
|
+
const found = byteType(f.type, declarations, seen);
|
|
994
|
+
if (found) return found;
|
|
995
|
+
}
|
|
996
|
+
return null;
|
|
997
|
+
}
|
|
998
|
+
case "array":
|
|
999
|
+
case "record":
|
|
1000
|
+
case "nullable":
|
|
1001
|
+
return byteType(node.of, declarations, seen);
|
|
1002
|
+
case "union":
|
|
1003
|
+
case "intersection":
|
|
1004
|
+
for (const part of node.of) {
|
|
1005
|
+
const found = byteType(part, declarations, seen);
|
|
1006
|
+
if (found) return found;
|
|
1007
|
+
}
|
|
1008
|
+
return null;
|
|
1009
|
+
case "object":
|
|
1010
|
+
for (const f of node.fields) {
|
|
1011
|
+
const found = byteType(f.type, declarations, seen);
|
|
1012
|
+
if (found) return found;
|
|
1013
|
+
}
|
|
1014
|
+
return null;
|
|
1015
|
+
case "unsupported":
|
|
1016
|
+
return [...BYTE_TYPES].find((t) => new RegExp(`\\b${t}\\b`).test(node.text)) ?? null;
|
|
1017
|
+
default:
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/** Methods and events whose types could not be generated, with the reason. */
|
|
1023
|
+
export function untypedMembers(model: GenModel): string[] {
|
|
1024
|
+
return [
|
|
1025
|
+
...model.methods.filter((m) => m.untyped).map((m) => `${m.name}: ${m.untyped}`),
|
|
1026
|
+
...model.events.filter((e) => e.untyped).map((e) => `event ${e.name}: ${e.untyped}`),
|
|
1027
|
+
];
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/** The generated source for one plugin on one platform (file name relative to the gen folder). */
|
|
1031
|
+
export function pluginBindings(
|
|
1032
|
+
plugin: ResolvedPlugin,
|
|
1033
|
+
platform: "ios" | "android",
|
|
1034
|
+
appDir: string,
|
|
1035
|
+
): { file: string; text: string } {
|
|
1036
|
+
const { manifest } = plugin;
|
|
1037
|
+
const native = manifest[platform];
|
|
1038
|
+
if (!native || typeof native !== "object")
|
|
1039
|
+
throw new CliError(`plugin ${manifest.id}: no ${platform} implementation to generate bindings for`);
|
|
1040
|
+
const spec = readPluginSpec(plugin.dir);
|
|
1041
|
+
const problems = specProblems(manifest, spec);
|
|
1042
|
+
if (problems.length)
|
|
1043
|
+
throw new CliError(
|
|
1044
|
+
`plugin ${manifest.id}: the spec does not match native-plugin.json:\n - ${problems.join("\n - ")}`,
|
|
1045
|
+
);
|
|
1046
|
+
const model = buildModel(spec, manifest.id, {
|
|
1047
|
+
methods: native.methods ?? manifest.methods,
|
|
1048
|
+
events: native.events ?? manifest.events,
|
|
1049
|
+
source: relative(appDir, spec.file) || spec.file,
|
|
1050
|
+
});
|
|
1051
|
+
if (platform === "ios") return { file: `${model.prefix}PluginSpec.swift`, text: generateSwift(model) };
|
|
1052
|
+
const pkg = (native as AndroidManifest).class.replace(/\.[^.]+$/, "");
|
|
1053
|
+
return { file: join(...pkg.split("."), `${model.prefix}PluginSpec.kt`), text: generateKotlin(model, pkg) };
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/** A Swift plugin class that conforms to the generated protocol, every method still to write. */
|
|
1057
|
+
export function swiftStub(model: GenModel, className: string): string {
|
|
1058
|
+
const out = [
|
|
1059
|
+
"import Foundation",
|
|
1060
|
+
"",
|
|
1061
|
+
`/// ${model.pluginId}: generated by \`akan-native plugin stub\` from ${model.source}.`,
|
|
1062
|
+
`final class ${className}: ${model.prefix}PluginSpec {`,
|
|
1063
|
+
];
|
|
1064
|
+
out.push(
|
|
1065
|
+
` static let id = ${JSON.stringify(model.pluginId)}`,
|
|
1066
|
+
" private let context: AkanNativePluginContext",
|
|
1067
|
+
"",
|
|
1068
|
+
" init(context: AkanNativePluginContext) {",
|
|
1069
|
+
" self.context = context",
|
|
1070
|
+
" }",
|
|
1071
|
+
);
|
|
1072
|
+
for (const m of model.methods) {
|
|
1073
|
+
out.push("");
|
|
1074
|
+
if (m.untyped) {
|
|
1075
|
+
out.push(
|
|
1076
|
+
` /// Untyped: ${m.untyped}.`,
|
|
1077
|
+
` func ${swiftName(m.name)}(_ call: AkanNativeCall) {`,
|
|
1078
|
+
` call.reject(.unsupported, "${m.name} is not implemented yet")`,
|
|
1079
|
+
" }",
|
|
1080
|
+
);
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
const params = [...(m.args ? [`_ args: ${m.args}`] : []), `_ reply: AkanNativeReply<${replyType(m, "swift")}>`];
|
|
1084
|
+
out.push(
|
|
1085
|
+
` func ${swiftName(m.name)}(${params.join(", ")}) {`,
|
|
1086
|
+
` reply.reject(.unsupported, "${m.name} is not implemented yet")`,
|
|
1087
|
+
" }",
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
out.push("}", "");
|
|
1091
|
+
return out.join("\n");
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** A Kotlin plugin class that implements the generated interface, every method still to write. */
|
|
1095
|
+
export function kotlinStub(model: GenModel, pkg: string, className: string): string {
|
|
1096
|
+
const out = [
|
|
1097
|
+
`package ${pkg}`,
|
|
1098
|
+
"",
|
|
1099
|
+
"import com.akanjs.runtime.AkanNativeCall",
|
|
1100
|
+
"import com.akanjs.runtime.AkanNativeErrorCode",
|
|
1101
|
+
"import com.akanjs.runtime.AkanNativePluginContext",
|
|
1102
|
+
"import com.akanjs.runtime.AkanNativeReply",
|
|
1103
|
+
"import com.akanjs.runtime.AkanNativeVoidReply",
|
|
1104
|
+
"",
|
|
1105
|
+
`/** ${model.pluginId}: generated by \`akan-native plugin stub\` from ${model.source}. */`,
|
|
1106
|
+
`class ${className}(private val context: AkanNativePluginContext) : ${model.prefix}PluginSpec {`,
|
|
1107
|
+
];
|
|
1108
|
+
model.methods.forEach((m, i) => {
|
|
1109
|
+
if (i) out.push("");
|
|
1110
|
+
const todo = `reject(AkanNativeErrorCode.UNSUPPORTED, "${m.name} is not implemented yet")`;
|
|
1111
|
+
if (m.untyped) {
|
|
1112
|
+
out.push(
|
|
1113
|
+
` /** Untyped: ${kdocSafe(m.untyped)}. */`,
|
|
1114
|
+
` override fun ${kotlinName(m.name)}(call: AkanNativeCall) {`,
|
|
1115
|
+
` call.${todo}`,
|
|
1116
|
+
" }",
|
|
1117
|
+
);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const params = [
|
|
1121
|
+
...(m.args ? [`args: ${m.args}`] : []),
|
|
1122
|
+
`reply: ${m.result === null ? "AkanNativeVoidReply" : `AkanNativeReply<${replyType(m, "kotlin")}>`}`,
|
|
1123
|
+
];
|
|
1124
|
+
out.push(` override fun ${kotlinName(m.name)}(${params.join(", ")}) {`, ` reply.${todo}`, " }");
|
|
1125
|
+
});
|
|
1126
|
+
out.push("}", "");
|
|
1127
|
+
return out.join("\n");
|
|
1128
|
+
}
|