eleven / messenger Public

Clone
git clone https://amadan.net/eleven/messenger

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3// đŸ¤– Loads the bundled app schemas (Schemas/<app>.json — byte-identical copies
4// of the canonical web/static/apps/schemas/*.json, drift-gated by
5// test/schema-engine.test.mjs). An app id with a schema here renders natively
6// via SchemaAppView; every other mini-app keeps its webview surface.
7@MainActor
8public enum AppSchemaRegistry {
9 private static var cache: [String: AppJSON?] = [:]
10
11 public static func schema(for appId: String) -> AppJSON? {
12 if let cached = cache[appId] { return cached }
13 var loaded: AppJSON? = nil
14 if let url = Bundle.module.url(forResource: appId, withExtension: "json", subdirectory: "Schemas"),
15 let data = try? Data(contentsOf: url),
16 let json = AppJSON.parse(data),
17 case .object = json {
18 loaded = json
19 }
20 cache[appId] = loaded
21 return loaded
22 }
23
24 public static func hasSchema(for appId: String?) -> Bool {
25 guard let appId, !appId.isEmpty else { return false }
26 return schema(for: appId) != nil
27 }
28}
29