peachsim 0.1.2521 → 0.1.2523

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 (141) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +18 -7
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +2 -2
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-4JVXGEDW.mjs → acorn-NXIHV6CW.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-MDWKX5GI.mjs → chunk-25AXI47D.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-NSGZF3QW.mjs → chunk-34NH5JMC.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-HSKIQSPO.mjs → chunk-3FLRJG7Z.mjs} +4 -4
  30. package/dist-lib/esm-chunks/{chunk-3HKF2MNZ.mjs → chunk-4O3KYDK6.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-D37M2XQX.mjs → chunk-564FVBVS.mjs} +13 -13
  32. package/dist-lib/esm-chunks/{chunk-HY6PNY4A.mjs → chunk-5TQINN32.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-FHMICG4V.mjs → chunk-75FOOVTJ.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-EH47OK5J.mjs → chunk-7SYYIUX6.mjs} +3 -3
  35. package/dist-lib/esm-chunks/{chunk-D4MWPIVL.mjs → chunk-7WUGKS76.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-4GCQVV36.mjs → chunk-AJIRKCRD.mjs} +5 -5
  37. package/dist-lib/esm-chunks/{chunk-WCBTD7CJ.mjs → chunk-BIEC4VVJ.mjs} +5 -5
  38. package/dist-lib/esm-chunks/{chunk-HBYQWZJW.mjs → chunk-E3E2UUV3.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-KBUZQIKU.mjs → chunk-ENQ2Y2BX.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-R2D667KZ.mjs → chunk-FA7GRXO4.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-YNLZCNHF.mjs → chunk-MEFRUBSD.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-TIH3DEXP.mjs → chunk-MTA5YBSW.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-X3FFTU6E.mjs → chunk-Q665MVWH.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-BYCC3XF7.mjs → chunk-UIWAOJNG.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-YGYTY5RM.mjs → chunk-UYTMSUTD.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-KFVMTY3M.mjs → chunk-W4IQ4HR4.mjs} +2 -2
  47. package/dist-lib/esm-chunks/{chunk-33NEBPBL.mjs → chunk-ZJNHWIHR.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{metro-layout-parser-VJOMJGRY.mjs → metro-layout-parser-HS2DSJ2U.mjs} +3 -3
  49. package/dist-lib/esm-chunks/{swift-package-prebuilt-WDK4LE54.mjs → swift-package-prebuilt-S6E6UJUN.mjs} +10 -10
  50. package/dist-lib/esm-chunks/{swift-sdk-app-module-W22UVP5E.mjs → swift-sdk-app-module-HCHHQFJW.mjs} +13 -13
  51. package/dist-lib/esm-chunks/{swift-sdk-image-5P6YHUKB.mjs → swift-sdk-image-5HXI7CM7.mjs} +13 -13
  52. package/dist-lib/esm-chunks/{swift-sdk-image-producer-S5ZJTUTW.mjs → swift-sdk-image-producer-Z45DZJKU.mjs} +4 -4
  53. package/dist-lib/expo-swift-bundle.cjs +16 -5
  54. package/dist-lib/expo-swift-metadata.cjs +1 -1
  55. package/dist-lib/expo-swift-metadata.mjs +7 -7
  56. package/dist-lib/home-paths.cjs +1 -1
  57. package/dist-lib/host/bridge-host.cjs +124 -84
  58. package/dist-lib/host/fetch-proxy-handler.cjs +6 -5
  59. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  60. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  61. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  62. package/dist-lib/host/websocket-proxy.cjs +1 -1
  63. package/dist-lib/index.cjs +1 -1
  64. package/dist-lib/kotlin-host.cjs +1 -1
  65. package/dist-lib/menu.cjs +1 -1
  66. package/dist-lib/menu.mjs +3 -3
  67. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  68. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  69. package/dist-lib/metro-production-bundle.cjs +1 -1
  70. package/dist-lib/metro-production-bundle.mjs +4 -4
  71. package/dist-lib/native-app-identity-project.cjs +2 -2
  72. package/dist-lib/native-app-identity-project.mjs +15 -15
  73. package/dist-lib/native-app-identity.cjs +1 -1
  74. package/dist-lib/native-app-identity.mjs +6 -6
  75. package/dist-lib/native-firebase-metadata.cjs +1 -1
  76. package/dist-lib/native-firebase-metadata.mjs +3 -3
  77. package/dist-lib/pdfium-raster.cjs +1 -1
  78. package/dist-lib/pdfium-raster.mjs +2 -2
  79. package/dist-lib/plist.cjs +1 -1
  80. package/dist-lib/plist.mjs +3 -3
  81. package/dist-lib/profiles.cjs +1 -1
  82. package/dist-lib/public-brand.cjs +1 -1
  83. package/dist-lib/public-origins-lib-esm.json +79 -79
  84. package/dist-lib/public-origins-lib.json +69 -69
  85. package/dist-lib/react-native-host-modules.cjs +1 -1
  86. package/dist-lib/react-native-host-modules.mjs +2 -2
  87. package/dist-lib/reap-browser.cjs +1 -1
  88. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  89. package/dist-lib/sdk.cjs +1 -1
  90. package/dist-lib/sdk.mjs +7 -7
  91. package/dist-lib/skills.cjs +144 -104
  92. package/dist-lib/swift-compile.cjs +2 -2
  93. package/dist-lib/swift-compile.mjs +10 -10
  94. package/dist-lib/swift-package.cjs +1 -1
  95. package/dist-lib/swift-package.mjs +3 -3
  96. package/dist-lib/swift-submit.cjs +1 -1
  97. package/dist-lib/swift-submit.mjs +5 -5
  98. package/dist-lib/swift-svg-raster.cjs +1 -1
  99. package/dist-lib/swift-svg-raster.mjs +2 -2
  100. package/dist-lib/swift-toolchain.cjs +1 -1
  101. package/dist-lib/swift.cjs +1 -1
  102. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  103. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  104. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  105. package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
  106. package/dist-lib/vendor/acorn.cjs +1 -1
  107. package/dist-lib/vendor/bplist-parser.cjs +1 -1
  108. package/dist-lib/vendor/ignore.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/plist.cjs +1 -1
  111. package/dist-lib/vendor/smol-toml.cjs +1 -1
  112. package/dist-lib/vendor/stream-json.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  117. package/dist-lib/vendor/sucrase.cjs +1 -1
  118. package/dist-lib/vendor/terser.cjs +1 -1
  119. package/dist-lib/vendor/valibot.cjs +1 -1
  120. package/dist-lib/vendor/ws.cjs +1 -1
  121. package/dist-lib/vendor/zod.cjs +1 -1
  122. package/dist-lib/worklet-executable.cjs +1 -1
  123. package/dist-lib/worklet-executable.mjs +3 -3
  124. package/dist-types/packages/peach-engine/src/engine/image-fetch.d.ts +2 -1
  125. package/dist-types/packages/peach-engine/src/engine/native-image-scope.d.ts +12 -0
  126. package/dist-types/packages/peach-engine/src/engine/native-shell-services.d.ts +1 -0
  127. package/dist-types/packages/peach-engine/src/engine/remote-display-protocol.d.ts +35 -5
  128. package/dist-types/packages/peach-engine/src/engine/scene-stream-decoder.d.ts +62 -0
  129. package/dist-types/packages/peach-engine/src/engine/scene-stream-encoder.d.ts +66 -0
  130. package/dist-types/packages/peach-engine/src/engine/scene-stream-shared.d.ts +28 -0
  131. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  132. package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +2 -2
  133. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +7 -1
  134. package/dist-types/packages/peach-engine/src/render-worker/compositor-surface-host.d.ts +1 -0
  135. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +4 -4
  136. package/kotlin/sdk.tar.gz +0 -0
  137. package/package.json +1 -1
  138. package/runtime-companion.json +1 -1
  139. package/src/host/bridge-host.ts +8 -1
  140. package/src/one-native-source.ts +19 -1
  141. package/src/swift-host.ts +31 -15
@@ -0,0 +1,66 @@
1
+ import { type StreamCodecHooks } from './scene-stream-shared.d.ts';
2
+ import type { RemoteLayoutRect, RemoteSceneNode } from './remote-display-protocol.d.ts';
3
+ export declare class StreamWriter {
4
+ private buf;
5
+ private dv;
6
+ private off;
7
+ constructor(initialBytes?: number);
8
+ reset(): void;
9
+ get length(): number;
10
+ truncate(length: number): void;
11
+ private need;
12
+ u8(value: number): void;
13
+ u16(value: number): void;
14
+ u32(value: number): void;
15
+ i32(value: number): void;
16
+ uvarint(value: number): void;
17
+ svarint(value: number): void;
18
+ f32(value: number): void;
19
+ f64(value: number): void;
20
+ bytes(value: Uint8Array): void;
21
+ utf8Raw(value: string, maxBytes: number): void;
22
+ writeAsciiOrUtf8WithRef(value: string, maxBytes: number, stringTable: Map<string, number>): void;
23
+ view(): Uint8Array;
24
+ finishCopy(): Uint8Array;
25
+ }
26
+ export declare class SceneStreamEncoder {
27
+ private readonly prevNodes;
28
+ private readonly prevLayouts;
29
+ private readonly stringTable;
30
+ private readonly propsTable;
31
+ private readonly styleTable;
32
+ private readonly styleFieldTable;
33
+ private lastStyleFormatId;
34
+ private deflater;
35
+ private deflateChunks;
36
+ private readonly bodyWriter;
37
+ reset(): void;
38
+ private ensureDeflater;
39
+ compressBody(body: Uint8Array, full: boolean): {
40
+ deflated: boolean;
41
+ rolling: boolean;
42
+ payload: Uint8Array;
43
+ };
44
+ private writeFullStyleRecord;
45
+ private writeStyleDeltaPatch;
46
+ private writeStyleRefOrValue;
47
+ private writePropsRefOrValue;
48
+ private writeChildren;
49
+ private writeProbe;
50
+ private writeLayouts;
51
+ encodeCommitCore(input: {
52
+ full: boolean;
53
+ rootId: number | null;
54
+ upserts: readonly RemoteSceneNode[];
55
+ removed: readonly number[];
56
+ layouts: readonly RemoteLayoutRect[];
57
+ requiredFontHashes: readonly string[];
58
+ }, hooks: StreamCodecHooks): StreamWriter | null;
59
+ commitState(input: {
60
+ full: boolean;
61
+ upserts: readonly RemoteSceneNode[];
62
+ removed: readonly number[];
63
+ layouts: readonly RemoteLayoutRect[];
64
+ }, hooks: StreamCodecHooks): void;
65
+ }
66
+ export declare function createSceneStreamEncoder(): SceneStreamEncoder;
@@ -0,0 +1,28 @@
1
+ import type { RemoteLayoutRect } from './remote-display-protocol.d.ts';
2
+ import type { SootSimNodeType } from './types.d.ts';
3
+ export declare const SPARSE_STYLE_LANES = 40;
4
+ export declare const SPARSE_STYLE_HEADER_BYTES: number;
5
+ export declare const STYLE_NAMED_FIELD = 4294967295;
6
+ export declare const STREAM_DEFLATE_MIN_BYTES = 48;
7
+ export declare const MAX_STRING_TABLE = 2048;
8
+ export declare const MAX_PROPS_TABLE = 1024;
9
+ export declare const MAX_STYLE_TABLE = 1024;
10
+ export declare const MAX_STYLE_FIELD_TABLE = 512;
11
+ export declare const MAX_INTERNED_STRING_BYTES = 256;
12
+ export declare const MAX_CACHED_PROPS_BYTES = 4096;
13
+ export declare const MAX_CACHED_STYLE_BYTES = 4096;
14
+ export declare const MAX_VALUE_DEPTH = 64;
15
+ export declare const textEncoder: TextEncoder;
16
+ export declare const textDecoder: TextDecoder;
17
+ export declare const latin1Decoder: TextDecoder;
18
+ export declare function splitProbeGate(probe: string): {
19
+ header: string;
20
+ gate: string;
21
+ } | null;
22
+ export interface StreamCodecHooks {
23
+ nodeTypeList: readonly SootSimNodeType[];
24
+ nodeTypeIndex: ReadonlyMap<string, number>;
25
+ canonicalProbeRecord: (id: number, type: SootSimNodeType, props: Record<string, unknown>, hidden: boolean) => string;
26
+ assertNoLocalHandles: (value: unknown, label: string) => void;
27
+ isLayoutRect: (value: unknown) => value is RemoteLayoutRect;
28
+ }
@@ -1,8 +1,8 @@
1
1
  export declare const DISPLAY_SERVER_VERSION = 29;
2
2
  export declare const DISPLAY_SERVER_MAJOR = 2;
3
- export declare const DISPLAY_SERVER_MINOR = 46;
3
+ export declare const DISPLAY_SERVER_MINOR = 49;
4
4
  export declare const DISPLAY_SERVER_RUNTIME_VERSION_MINOR = 41;
5
- export declare const DISPLAY_SERVER_SUBPROTOCOL = "rnx.display-server.v2.wire29.minor46";
5
+ export declare const DISPLAY_SERVER_SUBPROTOCOL = "rnx.display-server.v2.wire29.minor49";
6
6
  export declare const DISPLAY_SERVER_TOKEN_SUBPROTOCOL_PREFIX = "rnx.sim-token.";
7
7
  export declare const RNX_CLOUD_DISPLAY_GRANT_TTL_MS: number;
8
8
  export declare const RNX_CLOUD_DISPLAY_CLOSE: {
@@ -89,7 +89,7 @@ export interface CompositorGpuFrame {
89
89
  recordProgramInput(target: CompositorGpuTarget): void;
90
90
  readonly programPassCapacity: number;
91
91
  runProgramPass(targets: readonly CompositorGpuTarget[], encode: (encoder: GPUCommandEncoder) => readonly GPUBuffer[]): void;
92
- presentDisplay(display: CompositorGpuDisplay): void;
92
+ presentDisplay(display: CompositorGpuDisplay, hasVisiblePixels?: boolean): void;
93
93
  composeStaleTrees(): void;
94
94
  readPixels: CompositorGpuRead;
95
95
  exportSurfaceImage(display: CompositorGpuDisplay): Promise<ImageBitmap>;
@@ -167,7 +167,7 @@ export interface CompositorGpuBackend {
167
167
  waitForAdmission(source: GpuFrameSource, stillWanted?: () => boolean, graphiteSubmissionBudget?: WebGpuGraphiteSubmissionBudget): Promise<CompositorGpuAdmission>;
168
168
  failPendingAdmissions(error: Error): void;
169
169
  runFrame<T>(admission: CompositorGpuAdmission, options: CompositorFrameOptions, record: (frame: CompositorGpuFrame) => T): CompositorFrameCompletion<T>;
170
- nativeFramePresenter(displays: readonly CompositorGpuDisplay[], sample: (mask: number, read: CompositorGpuRead) => void, presentsToPage: () => boolean): NativeFramePresenter;
170
+ nativeFramePresenter(displays: readonly CompositorGpuDisplay[], sample: (mask: number, read: CompositorGpuRead) => void, presentsToPage: () => boolean, hasVisiblePixels: (index: number) => boolean): NativeFramePresenter;
171
171
  readonly currentFrame: CompositorGpuFrame | null;
172
172
  submittedWorkDone(): Promise<void>;
173
173
  withFullSurfaceReadbacks<T>(surfaceIds: readonly CompositorSurfaceId[], run: () => Promise<T>): Promise<T>;
@@ -1721,7 +1721,10 @@ export type ShellToCompositorMessage = import('./presentationChannelsContract.d.
1721
1721
  active: boolean;
1722
1722
  } | ({
1723
1723
  type: 'remoteFontRegister';
1724
- } & RemoteFontRegistration) | RemoteSceneImageMessage | {
1724
+ } & RemoteFontRegistration) | {
1725
+ type: 'ensureBundledSystemFont';
1726
+ family: string;
1727
+ } | RemoteSceneImageMessage | {
1725
1728
  type: 'capturePublicationBarrier';
1726
1729
  requestId: number;
1727
1730
  origin: CapturePublicationOrigin;
@@ -1962,6 +1965,9 @@ export type CompositorWorkerToHost = {
1962
1965
  } | {
1963
1966
  type: 'nativeWindowOwnership';
1964
1967
  ownership: NativeWindowOwnership | null;
1968
+ } | {
1969
+ type: 'shellOverlayVisibility';
1970
+ visible: boolean;
1965
1971
  } | {
1966
1972
  type: 'displayClockDemand';
1967
1973
  active: boolean;
@@ -98,6 +98,7 @@ export interface CompositorRenderActivity {
98
98
  export type CompositorHostSurfaceId = AuxAppSurfaceId | 'home' | 'shell-overlay';
99
99
  export interface CompositorSurfaceSource {
100
100
  open(surfaceId: CompositorHostSurfaceId, size: CompositorSurfaceResize): OffscreenCanvas | null;
101
+ setOverlayVisible?(visible: boolean): void;
101
102
  close(): void;
102
103
  }
103
104
  export interface CompositorHostPage {
@@ -105,7 +105,10 @@ export type TreeSyncPortMessage = {
105
105
  envelope: NativeAnimMirrorEnvelope;
106
106
  } | ({
107
107
  type: 'remoteFontRegister';
108
- } & RemoteFontRegistration) | RemoteSceneImageMessage | {
108
+ } & RemoteFontRegistration) | {
109
+ type: 'ensureBundledSystemFont';
110
+ family: string;
111
+ } | RemoteSceneImageMessage | {
109
112
  type: 'surfaceTreeApplied';
110
113
  surfaceId: string;
111
114
  generation: number;
@@ -115,9 +118,6 @@ export type TreeSyncPortMessage = {
115
118
  surfaceId: string;
116
119
  generation: number;
117
120
  seq: number;
118
- } | {
119
- type: 'appContentPainted';
120
- appId: string;
121
121
  } | {
122
122
  type: 'capturePublicationBarrier';
123
123
  requestId: number;
package/kotlin/sdk.tar.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peachsim",
3
- "version": "0.1.2521",
3
+ "version": "0.1.2523",
4
4
  "description": "Vite and Metro plugins, testing drivers, and SDK exports for peach.",
5
5
  "author": "Tamagui LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1 +1 @@
1
- {"abi":1,"sha256":"368390e08d3df4162311512f9e518084ee7985676c712668fc9f3f299ddd6a17","file":"node/cli-368390e08d3df4162311512f9e518084ee7985676c712668fc9f3f299ddd6a17.cjs"}
1
+ {"abi":1,"sha256":"20804d67689cee628419f18ac4a7845afcff248ade4ff2fbf1830f109911b778","file":"node/cli-20804d67689cee628419f18ac4a7845afcff248ade4ff2fbf1830f109911b778.cjs"}
@@ -615,7 +615,8 @@ export class SootSimBridgeHost {
615
615
  this.wireWebSocketServer()
616
616
  server.on('upgrade', (req, socket, head) => {
617
617
  if (rejectUntrustedBridgeUpgrade(req, socket)) return
618
- if (new URL(req.url ?? '/', 'http://localhost').pathname === SWIFT_HMR_PATH) {
618
+ const pathname = new URL(req.url ?? '/', 'http://localhost').pathname
619
+ if (pathname === SWIFT_HMR_PATH) {
619
620
  void import('../one-native-source')
620
621
  .then(({ handleOneNativeSourceUpgrade }) => {
621
622
  if (!handleOneNativeSourceUpgrade(req, socket, head)) socket.destroy()
@@ -627,6 +628,12 @@ export class SootSimBridgeHost {
627
628
  }
628
629
  if (handleWebSocketProxyUpgrade(req, socket, head)) return
629
630
  this.wss?.handleUpgrade(req, socket, head, (ws) => {
631
+ // a staged bundle can carry a dev client, but this origin serves a fixed artifact.
632
+ if (pathname === '/hot') {
633
+ ws.on('error', () => {})
634
+ ws.close(1013, 'bundle has no development server')
635
+ return
636
+ }
630
637
  this.wss?.emit('connection', ws, req)
631
638
  })
632
639
  })
@@ -6,6 +6,8 @@ import fs from 'node:fs'
6
6
  import { createRequire } from 'node:module'
7
7
  import path from 'node:path'
8
8
  import { fileURLToPath, pathToFileURL } from 'node:url'
9
+ import { promisify } from 'node:util'
10
+ import { brotliCompress, constants } from 'node:zlib'
9
11
  import { KOTLIN_PACKAGE_PATH } from '@peach/globals/kotlin-discovery'
10
12
  import { WebSocket, WebSocketServer } from 'ws'
11
13
  import { isLoopbackHost } from './backend-origin'
@@ -30,6 +32,7 @@ interface App {
30
32
  }
31
33
 
32
34
  const apps = new Map<string, App>()
35
+ const compressMetadata = promisify(brotliCompress)
33
36
 
34
37
  // the workspace module beside peachsim compiles locally; an install has none,
35
38
  // and its packages compile on Contrast
@@ -208,8 +211,23 @@ export async function handleOneNativeSourceRequest(
208
211
  url.pathname.slice(SWIFT_PACKAGE_PATH.length),
209
212
  )
210
213
  const metadata = await packageMetadata(app, packageName)
214
+ const body = JSON.stringify(metadata)
215
+ const acceptsBrotli = req.headers['accept-encoding']?.split(',').some((value) => {
216
+ const [coding, quality] = value
217
+ .trim()
218
+ .toLowerCase()
219
+ .split(/\s*;\s*q\s*=\s*/)
220
+ return coding === 'br' && (quality === undefined || Number(quality) > 0)
221
+ })
211
222
  res.setHeader('content-type', 'application/json')
212
- res.end(JSON.stringify(metadata))
223
+ res.setHeader('vary', 'origin, accept-encoding')
224
+ if (acceptsBrotli) {
225
+ const compressed = await compressMetadata(body, {
226
+ params: { [constants.BROTLI_PARAM_QUALITY]: 4 },
227
+ })
228
+ res.setHeader('content-encoding', 'br')
229
+ res.end(compressed)
230
+ } else res.end(body)
213
231
  return true
214
232
  }
215
233
  const kotlin = await import('./kotlin-host')
package/src/swift-host.ts CHANGED
@@ -8,6 +8,7 @@ import os from 'node:os'
8
8
  import path from 'node:path'
9
9
  import { readPngDimensions } from '../../../src/ios/pngHeader'
10
10
  import { decodeNativeSdkBinding } from '../../peach-kit/src/nativeSdkBindingContract'
11
+ import { SWIFT_ARTIFACT_SHA256_HEADER } from '../../peach-kit/src/nativeWasmContract'
11
12
  import {
12
13
  bundleImageRenditionKey,
13
14
  enumerateBundleColors,
@@ -267,6 +268,16 @@ export interface SwiftArtifact {
267
268
 
268
269
  // cross-request-promise: startup profiling belongs to the node preview host.
269
270
  const startupImages = new WeakMap<SwiftArtifact, Map<string, Promise<SwiftArtifact>>>()
271
+ const swiftArtifactDigests = new WeakMap<Buffer, string>()
272
+
273
+ function swiftArtifactContentDigest(bytes: Buffer): string {
274
+ let digest = swiftArtifactDigests.get(bytes)
275
+ if (!digest) {
276
+ digest = createHash('sha256').update(bytes).digest('hex')
277
+ swiftArtifactDigests.set(bytes, digest)
278
+ }
279
+ return digest
280
+ }
270
281
 
271
282
  export interface SwiftProject {
272
283
  packagePath: string
@@ -3872,6 +3883,7 @@ function scopedArtifact(
3872
3883
  })
3873
3884
  .then(
3874
3885
  (artifact) => {
3886
+ swiftArtifactContentDigest(artifact.bytes)
3875
3887
  project.artifact = artifact
3876
3888
  project.artifacts = [
3877
3889
  artifact,
@@ -4104,7 +4116,7 @@ export async function swiftPackageMetadata(
4104
4116
  })
4105
4117
  const image: SwiftArtifact = {
4106
4118
  ...artifact,
4107
- hash: createHash('sha256').update(result.primary).digest('hex'),
4119
+ hash: swiftArtifactContentDigest(result.primary),
4108
4120
  bytes: result.primary,
4109
4121
  parts: result.parts,
4110
4122
  }
@@ -4405,22 +4417,26 @@ export async function serveSwiftPackageAsset(
4405
4417
  const address = pathname.slice(ARTIFACT_PATH.length).replace(/\.wasm$/, '')
4406
4418
  for (const project of projects().values()) {
4407
4419
  if (pathname !== `${ARTIFACT_PATH}${address}.wasm`) continue
4408
- const bytes = project.artifacts
4409
- .map((artifact) =>
4410
- artifact.hash === address ? artifact.bytes : artifact.parts?.get(address),
4420
+ for (const artifact of project.artifacts) {
4421
+ const primary = artifact.hash === address
4422
+ const bytes = primary ? artifact.bytes : artifact.parts?.get(address)
4423
+ if (!bytes) continue
4424
+ res.setHeader('access-control-allow-origin', '*')
4425
+ res.setHeader('access-control-expose-headers', SWIFT_ARTIFACT_SHA256_HEADER)
4426
+ res.setHeader(
4427
+ SWIFT_ARTIFACT_SHA256_HEADER,
4428
+ primary ? swiftArtifactContentDigest(bytes) : address,
4411
4429
  )
4412
- .find((bytes) => bytes !== undefined)
4413
- if (!bytes) continue
4414
- res.setHeader('access-control-allow-origin', '*')
4415
- res.setHeader('content-type', 'application/wasm')
4416
- res.setHeader('vary', 'accept-encoding')
4417
- if (acceptsBr) {
4418
- res.setHeader('content-encoding', 'br')
4419
- res.end(await brotliCompressQ4(bytes, address))
4420
- } else {
4421
- res.end(bytes)
4430
+ res.setHeader('content-type', 'application/wasm')
4431
+ res.setHeader('vary', 'accept-encoding')
4432
+ if (acceptsBr) {
4433
+ res.setHeader('content-encoding', 'br')
4434
+ res.end(await brotliCompressQ4(bytes, address))
4435
+ } else {
4436
+ res.end(bytes)
4437
+ }
4438
+ return true
4422
4439
  }
4423
- return true
4424
4440
  }
4425
4441
  res.statusCode = 404
4426
4442
  res.end('swift artifact is stale')