create-apexjs 0.6.7 → 0.6.9

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.
Files changed (54) hide show
  1. package/package.json +1 -1
  2. package/templates/default/layouts/default.alpine +48 -19
  3. package/templates/features/data/db/index.ts +25 -24
  4. package/templates/mobile/android/README.md +53 -0
  5. package/templates/mobile/android/app/build.gradle.kts +30 -0
  6. package/templates/mobile/android/app/src/main/AndroidManifest.xml +24 -0
  7. package/templates/mobile/android/app/src/main/java/site/apexjs/shell/ApexBridge.kt +59 -0
  8. package/templates/mobile/android/app/src/main/java/site/apexjs/shell/ApexDbStore.kt +31 -0
  9. package/templates/mobile/android/app/src/main/java/site/apexjs/shell/ApexEngine.kt +66 -0
  10. package/templates/mobile/android/app/src/main/java/site/apexjs/shell/ApexInterceptor.kt +83 -0
  11. package/templates/mobile/android/app/src/main/java/site/apexjs/shell/MainActivity.kt +96 -0
  12. package/templates/mobile/android/app/src/main/res/drawable-hdpi/splash.png +0 -0
  13. package/templates/mobile/android/app/src/main/res/drawable-mdpi/splash.png +0 -0
  14. package/templates/mobile/android/app/src/main/res/drawable-xhdpi/splash.png +0 -0
  15. package/templates/mobile/android/app/src/main/res/drawable-xxhdpi/splash.png +0 -0
  16. package/templates/mobile/android/app/src/main/res/drawable-xxxhdpi/splash.png +0 -0
  17. package/templates/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
  18. package/templates/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
  19. package/templates/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  20. package/templates/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
  21. package/templates/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  22. package/templates/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  23. package/templates/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
  24. package/templates/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  25. package/templates/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  26. package/templates/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
  27. package/templates/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  28. package/templates/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  29. package/templates/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
  30. package/templates/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  31. package/templates/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  32. package/templates/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
  33. package/templates/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  34. package/templates/mobile/android/app/src/main/res/values/ic_launcher_background.xml +4 -0
  35. package/templates/mobile/android/app/src/main/res/values/strings.xml +4 -0
  36. package/templates/mobile/android/app/src/main/res/values/themes.xml +11 -0
  37. package/templates/mobile/android/build.gradle.kts +4 -0
  38. package/templates/mobile/android/gradle.properties +3 -0
  39. package/templates/mobile/android/play_store_512.png +0 -0
  40. package/templates/mobile/android/settings.gradle.kts +4 -0
  41. package/templates/mobile/apex-bridge.js +22 -0
  42. package/templates/mobile/gen-mobile-assets.mjs +101 -0
  43. package/templates/mobile/ios/ApexApp.swift +106 -0
  44. package/templates/mobile/ios/ApexDbStore.swift +74 -0
  45. package/templates/mobile/ios/ApexEngine.swift +253 -0
  46. package/templates/mobile/ios/ApexSchemeHandler.swift +349 -0
  47. package/templates/mobile/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +14 -0
  48. package/templates/mobile/ios/Assets.xcassets/AppIcon.appiconset/icon-1024.png +0 -0
  49. package/templates/mobile/ios/Assets.xcassets/LaunchBackground.colorset/Contents.json +20 -0
  50. package/templates/mobile/ios/Info.plist +60 -0
  51. package/templates/mobile/ios/README.md +153 -0
  52. package/templates/mobile/ios/Tests/ApexEngineTests.swift +74 -0
  53. package/templates/mobile/ios/project.yml +75 -0
  54. package/templates/mobile/splash.alpine +48 -0
@@ -0,0 +1,74 @@
1
+ // ApexEngineTests — runs on the iOS Simulator in CI (GitHub Actions macOS runner), no Mac needed
2
+ // locally. This is the highest-value iOS check: it proves the `apex build --mobile` bundle — the
3
+ // SHIM, the whole SSR + API pipeline, and the **asm.js SQLite** DB — actually runs under
4
+ // **JavaScriptCore** (iOS's engine, different from Android's V8). It drives ApexEngine directly, so
5
+ // it does NOT depend on WKURLSchemeHandler (the one remaining device-only unknown — POST bodies on
6
+ // a custom scheme — still needs a real device/UI test).
7
+ import JavaScriptCore
8
+ import XCTest
9
+
10
+ @testable import ApexShell
11
+
12
+ final class ApexEngineTests: XCTestCase {
13
+ /// server.mjs + apex-bridge.js are copied into the TEST bundle by CI (see project.yml resources).
14
+ private func makeEngine(snapshot: String? = nil) throws -> ApexEngine {
15
+ try ApexEngine(snapshot: snapshot, bundle: Bundle(for: Self.self))
16
+ }
17
+
18
+ private func request(_ url: String, method: String = "GET", body: String? = nil) -> String {
19
+ let obj: [String: Any] = [
20
+ "url": url,
21
+ "method": method,
22
+ "headers": ["content-type": "application/json"],
23
+ "body": body as Any? ?? NSNull(),
24
+ ]
25
+ let data = try! JSONSerialization.data(withJSONObject: obj)
26
+ return String(data: data, encoding: .utf8)!
27
+ }
28
+
29
+ /// SSR of a DB-backed page renders the seeded rows — proves JSContext runs the bundle + asm.js DB.
30
+ func testGuestbookRendersSeededRowsOnJavaScriptCore() async throws {
31
+ let engine = try makeEngine()
32
+ let res = await engine.handle(request("apex://localhost/guestbook"))
33
+ XCTAssertTrue(res.contains("Ada Lovelace"), "seeded row missing — bundle/DB didn't run on JSCore. Got: \(res.prefix(400))")
34
+ XCTAssertTrue(res.contains("Alan Turing"))
35
+ }
36
+
37
+ /// POST inserts through the Drizzle deferred proxy on asm.js SQLite, and it persists across a
38
+ /// simulated cold start via the snapshot seam.
39
+ func testPostInsertsAndSurvivesSnapshotRestore() async throws {
40
+ let engine = try makeEngine()
41
+ _ = await engine.handle(request("apex://localhost/guestbook")) // lazy-init + seed the DB
42
+
43
+ let post = await engine.handle(
44
+ request(
45
+ "apex://localhost/api/messages",
46
+ method: "POST",
47
+ body: #"{"author":"iOS CI","body":"runs on JavaScriptCore"}"#
48
+ )
49
+ )
50
+ XCTAssertTrue(post.contains("iOS CI"), "POST /api/messages did not echo the created row: \(post.prefix(400))")
51
+
52
+ let after = await engine.handle(request("apex://localhost/guestbook"))
53
+ XCTAssertTrue(after.contains("iOS CI"), "new message not visible after POST")
54
+
55
+ // Cold-start persistence: export bytes, boot a fresh engine with them, data survives.
56
+ let snap = engine.snapshot()
57
+ XCTAssertFalse(snap.isEmpty, "snapshot export returned empty")
58
+ let restored = try makeEngine(snapshot: snap)
59
+ let restoredBody = await restored.handle(request("apex://localhost/guestbook"))
60
+ XCTAssertTrue(restoredBody.contains("iOS CI"), "message did not survive snapshot restore")
61
+ }
62
+
63
+ /// Sealed-cookie auth works on JSCore (HMAC, no WebCrypto): login sets a cookie, whoami is gated.
64
+ func testAuthLoginOnJavaScriptCore() async throws {
65
+ let engine = try makeEngine()
66
+ let anon = await engine.handle(request("apex://localhost/api/whoami"))
67
+ XCTAssertTrue(anon.contains("401"), "gated whoami should be 401 when anonymous: \(anon.prefix(200))")
68
+
69
+ let login = await engine.handle(
70
+ request("apex://localhost/api/login", method: "POST", body: #"{"name":"Ada"}"#)
71
+ )
72
+ XCTAssertTrue(login.contains("apex-session"), "login should set a session cookie: \(login.prefix(300))")
73
+ }
74
+ }
@@ -0,0 +1,75 @@
1
+ # XcodeGen spec — generates ApexShell.xcodeproj from source, so the iOS project can be built on a
2
+ # CI macOS runner (or any Mac) without hand-authoring an .xcodeproj in Xcode.
3
+ # brew install xcodegen && (cd ios && xcodegen generate)
4
+ # The app + test bundle resources (server.mjs, apex-bridge.js, assets/, favicon.svg) are produced by
5
+ # `apex build --mobile` and copied into ios/Generated/ before generating (see .github/workflows/ios.yml).
6
+ name: ApexShell
7
+ options:
8
+ bundleIdPrefix: site.apexjs
9
+ deploymentTarget:
10
+ iOS: "15.0"
11
+ createIntermediateGroups: true
12
+
13
+ settings:
14
+ base:
15
+ SWIFT_VERSION: "5.0"
16
+ CODE_SIGNING_ALLOWED: "NO" # simulator builds/tests need no signing
17
+
18
+ targets:
19
+ ApexShell:
20
+ type: application
21
+ platform: iOS
22
+ sources:
23
+ - path: ApexApp.swift
24
+ - path: ApexEngine.swift
25
+ - path: ApexSchemeHandler.swift
26
+ - path: ApexDbStore.swift
27
+ - path: Assets.xcassets
28
+ - path: Generated/server.mjs
29
+ type: file
30
+ buildPhase: resources
31
+ - path: Generated/apex-bridge.js
32
+ type: file
33
+ buildPhase: resources
34
+ - path: Generated/assets
35
+ type: folder # blue folder reference → served verbatim at /assets/*
36
+ buildPhase: resources
37
+ - path: Generated/favicon.svg
38
+ type: file
39
+ buildPhase: resources
40
+ settings:
41
+ base:
42
+ PRODUCT_BUNDLE_IDENTIFIER: site.apexjs.shell
43
+ INFOPLIST_FILE: Info.plist
44
+ GENERATE_INFOPLIST_FILE: "NO"
45
+ TARGETED_DEVICE_FAMILY: "1,2"
46
+
47
+ ApexShellTests:
48
+ type: bundle.unit-test
49
+ platform: iOS
50
+ sources:
51
+ - path: Tests
52
+ # The engine test loads the bundle from its OWN (test) bundle, so copy the JS here too.
53
+ - path: Generated/server.mjs
54
+ type: file
55
+ buildPhase: resources
56
+ - path: Generated/apex-bridge.js
57
+ type: file
58
+ buildPhase: resources
59
+ dependencies:
60
+ - target: ApexShell
61
+ settings:
62
+ base:
63
+ TEST_HOST: "$(BUILT_PRODUCTS_DIR)/ApexShell.app/ApexShell"
64
+ BUNDLE_LOADER: "$(TEST_HOST)"
65
+ PRODUCT_BUNDLE_IDENTIFIER: site.apexjs.shell.tests
66
+
67
+ schemes:
68
+ ApexShell:
69
+ build:
70
+ targets:
71
+ ApexShell: all
72
+ ApexShellTests: [test]
73
+ test:
74
+ targets:
75
+ - ApexShellTests
@@ -0,0 +1,48 @@
1
+ <!-- Example animated splash — copy to your app's pages/splash.alpine.
2
+ The native shell loads /splash first; icon pops in, then "APEX JS" types out with a
3
+ blinking cursor (CSS-only — flash-free), then it advances to /.
4
+
5
+ Auto-advance is on the root template's x-init (a CLIENT attribute Alpine runs on
6
+ hydration) — NOT <script client>, whose top-level code would run during SSR and crash a
7
+ bare on-device engine. Responsive + reduced-motion aware. -->
8
+ <script server>
9
+ export function head() { return { title: 'Loading…' } }
10
+ </script>
11
+
12
+ <template x-data="{}" x-init="setTimeout(() => { window.location.href = '/' }, 2600)">
13
+ <div class="splash">
14
+ <!-- The app's icon (served from /favicon.svg — swap for your own brand mark). -->
15
+ <img class="mark" src="/favicon.svg" alt="Apex" width="96" height="96" />
16
+ <div class="typed">APEX JS</div>
17
+ </div>
18
+ </template>
19
+
20
+ <style scoped>
21
+ .splash {
22
+ position: fixed; inset: 0;
23
+ display: flex; flex-direction: column; align-items: center; justify-content: center;
24
+ gap: clamp(1rem, 5vw, 1.75rem);
25
+ background: #0b1120; color: #38bdf8;
26
+ padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
27
+ }
28
+ .mark {
29
+ width: clamp(4.5rem, 24vw, 6.5rem); height: auto; aspect-ratio: 1;
30
+ display: block; object-fit: contain;
31
+ animation: pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
32
+ }
33
+ .typed {
34
+ font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
35
+ font-weight: 600; font-size: clamp(1.1rem, 5.5vw, 1.6rem);
36
+ white-space: nowrap; overflow: hidden;
37
+ width: 0; max-width: 7ch;
38
+ border-right: 0.09em solid currentColor;
39
+ animation: type 1.3s steps(7, end) 0.55s forwards, blink 0.85s step-end 0.55s infinite;
40
+ }
41
+ @keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
42
+ @keyframes type { to { width: 7ch; } }
43
+ @keyframes blink { 50% { border-color: transparent; } }
44
+ @media (prefers-reduced-motion: reduce) {
45
+ .mark { animation: none; }
46
+ .typed { width: 7ch; animation: blink 0.85s step-end infinite; }
47
+ }
48
+ </style>