@wp-playground/common 1.0.13 → 1.0.14

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.
@@ -0,0 +1,13 @@
1
+ export interface CachedFetchResponse {
2
+ body: ReadableStream<Uint8Array>;
3
+ responseInit: ResponseInit;
4
+ }
5
+ /**
6
+ * Creates a fetch function that memoizes the response stream.
7
+ * Calling it twice will return a response with the same status,
8
+ * headers, and the body stream.
9
+ * Memoization is keyed by URL. Method, headers etc are ignored.
10
+ *
11
+ * @param originalFetch The fetch function to memoize. Defaults to the global fetch.
12
+ */
13
+ export declare function createMemoizedFetch(originalFetch?: typeof fetch): (url: string, options?: RequestInit) => Promise<Response>;
package/index.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * Let's always consider these questions before adding new code here.
10
10
  */
11
11
  import { UniversalPHP } from '@php-wasm/universal';
12
+ export { createMemoizedFetch } from './create-memoized-fetch';
12
13
  export declare const RecommendedPHPVersion = "8.0";
13
14
  export declare const unzipFile: (php: UniversalPHP, zipPath: string | File, extractToPath: string, overwriteFiles?: boolean) => Promise<void>;
14
15
  export declare const zipDirectory: (php: UniversalPHP, directoryPath: string) => Promise<Uint8Array>;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- function s(e){return`json_decode(base64_decode('${$(JSON.stringify(e))}'), true)`}function a(e){const t={};for(const i in e)t[i]=s(e[i]);return t}function $(e){return f(new TextEncoder().encode(e))}function f(e){const t=String.fromCodePoint(...e);return btoa(t)}const l="8.0",n="/tmp/file.zip",u=async(e,t,i,o=!0)=>{if(t instanceof File){const c=t;t=n,await e.writeFile(t,new Uint8Array(await c.arrayBuffer()))}const r=a({zipPath:t,extractToPath:i,overwriteFiles:o});await e.run({code:`<?php
1
+ function l(e){return`json_decode(base64_decode('${d(JSON.stringify(e))}'), true)`}function $(e){const t={};for(const r in e)t[r]=l(e[r]);return t}function d(e){return p(new TextEncoder().encode(e))}function p(e){const t=String.fromCodePoint(...e);return btoa(t)}function h(e=fetch){const t={};return async function(i,n){t[i]||(t[i]=e(i,n).then(o=>({body:o.body,responseInit:{status:o.status,statusText:o.statusText,headers:o.headers}})));const{body:a,responseInit:s}=await t[i],[f,u]=a.tee();return t[i]={body:f,responseInit:s},new Response(u,s)}}const w="8.0",c="/tmp/file.zip",x=async(e,t,r,i=!0)=>{if(t instanceof File){const a=t;t=c,await e.writeFile(t,new Uint8Array(await a.arrayBuffer()))}const n=$({zipPath:t,extractToPath:r,overwriteFiles:i});await e.run({code:`<?php
2
2
  function unzip($zipPath, $extractTo, $overwriteFiles = true)
3
3
  {
4
4
  if (!is_dir($extractTo)) {
@@ -23,8 +23,8 @@ function s(e){return`json_decode(base64_decode('${$(JSON.stringify(e))}'), true)
23
23
  throw new Exception("Could not unzip file");
24
24
  }
25
25
  }
26
- unzip(${r.zipPath}, ${r.extractToPath}, ${r.overwriteFiles});
27
- `}),await e.fileExists(n)&&await e.unlink(n)},p=async(e,t)=>{const i=`/tmp/file${Math.random()}.zip`,o=a({directoryPath:t,outputPath:i});await e.run({code:`<?php
26
+ unzip(${n.zipPath}, ${n.extractToPath}, ${n.overwriteFiles});
27
+ `}),await e.fileExists(c)&&await e.unlink(c)},z=async(e,t)=>{const r=`/tmp/file${Math.random()}.zip`,i=$({directoryPath:t,outputPath:r});await e.run({code:`<?php
28
28
  function zipDirectory($directoryPath, $outputPath) {
29
29
  $zip = new ZipArchive;
30
30
  $res = $zip->open($outputPath, ZipArchive::CREATE);
@@ -44,5 +44,5 @@ function s(e){return`json_decode(base64_decode('${$(JSON.stringify(e))}'), true)
44
44
  $zip->close();
45
45
  chmod($outputPath, 0777);
46
46
  }
47
- zipDirectory(${o.directoryPath}, ${o.outputPath});
48
- `});const r=await e.readFileAsBuffer(i);return e.unlink(i),r};export{l as RecommendedPHPVersion,u as unzipFile,p as zipDirectory};
47
+ zipDirectory(${i.directoryPath}, ${i.outputPath});
48
+ `});const n=await e.readFileAsBuffer(r);return e.unlink(r),n};export{w as RecommendedPHPVersion,h as createMemoizedFetch,x as unzipFile,z as zipDirectory};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/common",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Common exports and utilities for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,11 +27,11 @@
27
27
  "access": "public",
28
28
  "directory": "../../../dist/packages/playground/common"
29
29
  },
30
- "gitHead": "22888c009b54e0b1e5a5c9961b9d97c08b39f672",
30
+ "gitHead": "4d191fdd33db1949e51d54e2b03decbb103db4ac",
31
31
  "dependencies": {
32
32
  "comlink": "^4.4.1",
33
33
  "ini": "4.1.2",
34
- "@php-wasm/universal": "1.0.13",
35
- "@php-wasm/util": "1.0.13"
34
+ "@php-wasm/universal": "1.0.14",
35
+ "@php-wasm/util": "1.0.14"
36
36
  }
37
37
  }