@serwist/streams 9.0.0-preview.2 → 9.0.0-preview.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/dist/index.js CHANGED
@@ -111,7 +111,7 @@ function isSupported() {
111
111
  return canConstructReadableStream();
112
112
  }
113
113
 
114
- function strategy(sourceFunctions, headersInit) {
114
+ const strategy = (sourceFunctions, headersInit)=>{
115
115
  return async ({ event, request, url, params })=>{
116
116
  const sourcePromises = sourceFunctions.map((fn)=>{
117
117
  return Promise.resolve(fn({
@@ -144,6 +144,6 @@ function strategy(sourceFunctions, headersInit) {
144
144
  headers
145
145
  });
146
146
  };
147
- }
147
+ };
148
148
 
149
149
  export { concatenate, concatenateToResponse, isSupported, strategy };
@@ -1,10 +1,8 @@
1
1
  import type { RouteHandlerCallback, RouteHandlerCallbackOptions } from "@serwist/core";
2
2
  import type { StreamSource } from "./_types.js";
3
- export interface StreamsHandlerCallback {
4
- ({ url, request, event, params }: RouteHandlerCallbackOptions): Promise<StreamSource> | StreamSource;
5
- }
3
+ export type StreamsHandlerCallback = ({ url, request, event, params }: RouteHandlerCallbackOptions) => Promise<StreamSource> | StreamSource;
6
4
  /**
7
- * A shortcut to create a strategy that could be dropped-in to Serwist's router.
5
+ * A shortcut to create a strategy that could be dropped-in to Serwist's `Router`.
8
6
  *
9
7
  * On browsers that do not support constructing new `ReadableStream`s, this
10
8
  * strategy will automatically wait for all the `sourceFunctions` to complete,
@@ -15,6 +13,5 @@ export interface StreamsHandlerCallback {
15
13
  * @param headersInit If there's no `Content-Type` specified, `'text/html'` will be used by default.
16
14
  * @returns
17
15
  */
18
- declare function strategy(sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit): RouteHandlerCallback;
19
- export { strategy };
16
+ export declare const strategy: (sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit) => RouteHandlerCallback;
20
17
  //# sourceMappingURL=strategy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,MAAM,WAAW,sBAAsB;IACrC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,2BAA2B,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;CACtG;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,QAAQ,CAAC,eAAe,EAAE,sBAAsB,EAAE,EAAE,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAwC3G;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,MAAM,MAAM,sBAAsB,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,2BAA2B,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AAE5I;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,oBAAqB,sBAAsB,EAAE,eAAe,WAAW,KAAG,oBAwC9F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/streams",
3
- "version": "9.0.0-preview.2",
3
+ "version": "9.0.0-preview.21",
4
4
  "type": "module",
5
5
  "description": "A library that makes it easier to work with Streams in the browser.",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  ],
18
18
  "author": "Google's Web DevRel Team, Serwist's Team",
19
19
  "license": "MIT",
20
- "repository": "serwist/serwist",
21
- "bugs": "https://github.com/serwist/serwist/issues",
20
+ "repository": "https://gitlab.com/serwist/serwist",
21
+ "bugs": "https://gitlab.com/serwist/serwist/issues",
22
22
  "homepage": "https://serwist.pages.dev",
23
23
  "main": "./dist/index.js",
24
24
  "types": "./dist/index.d.ts",
@@ -30,13 +30,13 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@serwist/core": "9.0.0-preview.2",
34
- "@serwist/routing": "9.0.0-preview.2"
33
+ "@serwist/core": "9.0.0-preview.21",
34
+ "@serwist/routing": "9.0.0-preview.21"
35
35
  },
36
36
  "devDependencies": {
37
- "rollup": "4.9.6",
38
- "typescript": "5.4.0-dev.20240206",
39
- "@serwist/constants": "9.0.0-preview.2"
37
+ "rollup": "4.13.0",
38
+ "typescript": "5.5.0-dev.20240323",
39
+ "@serwist/constants": "9.0.0-preview.21"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "typescript": ">=5.0.0"
package/src/strategy.ts CHANGED
@@ -14,12 +14,10 @@ import { concatenateToResponse } from "./concatenateToResponse.js";
14
14
  import { isSupported } from "./isSupported.js";
15
15
  import { createHeaders } from "./utils/createHeaders.js";
16
16
 
17
- export interface StreamsHandlerCallback {
18
- ({ url, request, event, params }: RouteHandlerCallbackOptions): Promise<StreamSource> | StreamSource;
19
- }
17
+ export type StreamsHandlerCallback = ({ url, request, event, params }: RouteHandlerCallbackOptions) => Promise<StreamSource> | StreamSource;
20
18
 
21
19
  /**
22
- * A shortcut to create a strategy that could be dropped-in to Serwist's router.
20
+ * A shortcut to create a strategy that could be dropped-in to Serwist's `Router`.
23
21
  *
24
22
  * On browsers that do not support constructing new `ReadableStream`s, this
25
23
  * strategy will automatically wait for all the `sourceFunctions` to complete,
@@ -30,7 +28,7 @@ export interface StreamsHandlerCallback {
30
28
  * @param headersInit If there's no `Content-Type` specified, `'text/html'` will be used by default.
31
29
  * @returns
32
30
  */
33
- function strategy(sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit): RouteHandlerCallback {
31
+ export const strategy = (sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit): RouteHandlerCallback => {
34
32
  return async ({ event, request, url, params }: RouteHandlerCallbackOptions) => {
35
33
  const sourcePromises = sourceFunctions.map((fn) => {
36
34
  // Ensure the return value of the function is always a promise.
@@ -70,6 +68,4 @@ function strategy(sourceFunctions: StreamsHandlerCallback[], headersInit: Header
70
68
  // So is constructing a new Blob from multiple source Blobs or strings.
71
69
  return new Response(new Blob(blobParts), { headers });
72
70
  };
73
- }
74
-
75
- export { strategy };
71
+ };