@effing/fn 0.26.1
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/LICENSE +21 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2026, Few Software BV.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EffieSources, EffieData, EffieWebUrl } from '@effing/effie';
|
|
3
|
+
import { AnnieStreamOptions } from '@effing/annie';
|
|
4
|
+
|
|
5
|
+
type Bounds = Readonly<{
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}>;
|
|
9
|
+
type RunnerArgs<P> = {
|
|
10
|
+
props: P;
|
|
11
|
+
bounds: Bounds;
|
|
12
|
+
};
|
|
13
|
+
type FnKind = "image" | "annie" | "effie";
|
|
14
|
+
type BaseFnModule = {
|
|
15
|
+
propsSchema: z.ZodSchema<unknown>;
|
|
16
|
+
previewProps: object;
|
|
17
|
+
};
|
|
18
|
+
type ImageRunnerReturn = Promise<Buffer>;
|
|
19
|
+
type AnnieRunnerReturn = AsyncIterable<Buffer>;
|
|
20
|
+
type EffieRunnerReturn<S extends EffieSources = EffieSources> = Promise<EffieData<S>>;
|
|
21
|
+
type ImageFnModule = BaseFnModule & {
|
|
22
|
+
runner: (args: RunnerArgs<unknown>) => ImageRunnerReturn;
|
|
23
|
+
};
|
|
24
|
+
type AnnieFnModule = BaseFnModule & {
|
|
25
|
+
runner: (args: RunnerArgs<unknown>) => AnnieRunnerReturn;
|
|
26
|
+
};
|
|
27
|
+
type EffieFnModule = BaseFnModule & {
|
|
28
|
+
runner: (args: RunnerArgs<unknown>) => EffieRunnerReturn;
|
|
29
|
+
};
|
|
30
|
+
type FnModule<K extends FnKind> = K extends "image" ? ImageFnModule : K extends "annie" ? AnnieFnModule : EffieFnModule;
|
|
31
|
+
type FnModuleLoader = {
|
|
32
|
+
loadModule<K extends FnKind>(kind: K, id: string): Promise<FnModule<K>>;
|
|
33
|
+
listModules(kind: FnKind): string[];
|
|
34
|
+
hasModule(kind: FnKind, id: string): boolean;
|
|
35
|
+
};
|
|
36
|
+
type FnUrlBuilder = {
|
|
37
|
+
buildUrl<P extends Record<string, unknown>>(kind: FnKind, id: string, props: P, bounds: Bounds): Promise<EffieWebUrl>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare function initFnRuntime(config: {
|
|
41
|
+
moduleLoader: FnModuleLoader;
|
|
42
|
+
urlBuilder: FnUrlBuilder;
|
|
43
|
+
}): void;
|
|
44
|
+
declare function fnModule<K extends FnKind>(kind: K, id: string): Promise<FnModule<K>>;
|
|
45
|
+
declare function fnUrl<P extends Record<string, unknown>>(kind: FnKind, id: string, props: P, bounds: Bounds): Promise<EffieWebUrl>;
|
|
46
|
+
declare function fnModuleIds(kind: FnKind): string[];
|
|
47
|
+
declare function fnModuleExists(kind: FnKind, id: string): boolean;
|
|
48
|
+
|
|
49
|
+
type ImageResponseOptions = {
|
|
50
|
+
headers?: HeadersInit;
|
|
51
|
+
cacheControl?: string;
|
|
52
|
+
};
|
|
53
|
+
declare function imageResponse(bytes: Uint8Array, options?: ImageResponseOptions): Response;
|
|
54
|
+
type AnnieResponseOptions = AnnieStreamOptions & {
|
|
55
|
+
headers?: HeadersInit;
|
|
56
|
+
cacheControl?: string;
|
|
57
|
+
filename?: string;
|
|
58
|
+
};
|
|
59
|
+
declare function annieResponse(frames: AsyncIterable<Buffer>, options?: AnnieResponseOptions): Response;
|
|
60
|
+
type EffieResponseOptions = {
|
|
61
|
+
headers?: HeadersInit;
|
|
62
|
+
cacheControl?: string;
|
|
63
|
+
};
|
|
64
|
+
declare function effieResponse<S extends EffieSources>(data: EffieData<S>, options?: EffieResponseOptions): Response;
|
|
65
|
+
|
|
66
|
+
export { type AnnieFnModule, type AnnieResponseOptions, type AnnieRunnerReturn, type Bounds, type EffieFnModule, type EffieResponseOptions, type EffieRunnerReturn, type FnKind, type FnModule, type FnModuleLoader, type FnUrlBuilder, type ImageFnModule, type ImageResponseOptions, type ImageRunnerReturn, type RunnerArgs, annieResponse, effieResponse, fnModule, fnModuleExists, fnModuleIds, fnUrl, imageResponse, initFnRuntime };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/runtime.ts
|
|
2
|
+
var moduleLoader = null;
|
|
3
|
+
var urlBuilder = null;
|
|
4
|
+
function initFnRuntime(config) {
|
|
5
|
+
moduleLoader = config.moduleLoader;
|
|
6
|
+
urlBuilder = config.urlBuilder;
|
|
7
|
+
}
|
|
8
|
+
function getModuleLoader() {
|
|
9
|
+
if (!moduleLoader) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"attempting to access module loader before initFnRuntime() was called"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return moduleLoader;
|
|
15
|
+
}
|
|
16
|
+
function getUrlBuilder() {
|
|
17
|
+
if (!urlBuilder) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"attempting to access URL builder before initFnRuntime() was called"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return urlBuilder;
|
|
23
|
+
}
|
|
24
|
+
function fnModule(kind, id) {
|
|
25
|
+
return getModuleLoader().loadModule(kind, id);
|
|
26
|
+
}
|
|
27
|
+
function fnUrl(kind, id, props, bounds) {
|
|
28
|
+
return getUrlBuilder().buildUrl(kind, id, props, bounds);
|
|
29
|
+
}
|
|
30
|
+
function fnModuleIds(kind) {
|
|
31
|
+
return getModuleLoader().listModules(kind);
|
|
32
|
+
}
|
|
33
|
+
function fnModuleExists(kind, id) {
|
|
34
|
+
return getModuleLoader().hasModule(kind, id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/responses.ts
|
|
38
|
+
import { annieStream } from "@effing/annie";
|
|
39
|
+
function detectImageContentType(bytes) {
|
|
40
|
+
if (bytes[0] === 137 && bytes[1] === 80) return "image/png";
|
|
41
|
+
if (bytes[0] === 255 && bytes[1] === 216) return "image/jpeg";
|
|
42
|
+
throw new Error("Unsupported image format: expected PNG or JPEG");
|
|
43
|
+
}
|
|
44
|
+
function imageResponse(bytes, options = {}) {
|
|
45
|
+
const { headers: extraHeaders, cacheControl = "public, max-age=3600" } = options;
|
|
46
|
+
const headers = new Headers(extraHeaders);
|
|
47
|
+
headers.set("Content-Type", detectImageContentType(bytes));
|
|
48
|
+
if (cacheControl) {
|
|
49
|
+
headers.set("Cache-Control", cacheControl);
|
|
50
|
+
}
|
|
51
|
+
if (!(bytes.buffer instanceof ArrayBuffer)) {
|
|
52
|
+
throw new TypeError("SharedArrayBuffer is not supported");
|
|
53
|
+
}
|
|
54
|
+
return new Response(bytes.buffer, { status: 200, headers });
|
|
55
|
+
}
|
|
56
|
+
function annieResponse(frames, options = {}) {
|
|
57
|
+
const {
|
|
58
|
+
headers: extraHeaders,
|
|
59
|
+
cacheControl = "public, max-age=3600",
|
|
60
|
+
filename,
|
|
61
|
+
...streamOptions
|
|
62
|
+
} = options;
|
|
63
|
+
const stream = annieStream(frames, streamOptions);
|
|
64
|
+
const headers = new Headers(extraHeaders);
|
|
65
|
+
headers.set("Content-Type", "application/x-tar");
|
|
66
|
+
if (cacheControl) {
|
|
67
|
+
headers.set("Cache-Control", cacheControl);
|
|
68
|
+
}
|
|
69
|
+
if (filename) {
|
|
70
|
+
headers.set("Content-Disposition", `inline; filename="${filename}.tar"`);
|
|
71
|
+
}
|
|
72
|
+
return new Response(stream, { status: 200, headers });
|
|
73
|
+
}
|
|
74
|
+
function effieResponse(data, options = {}) {
|
|
75
|
+
const { headers: extraHeaders, cacheControl = "public, max-age=3600" } = options;
|
|
76
|
+
const headers = new Headers(extraHeaders);
|
|
77
|
+
if (cacheControl) {
|
|
78
|
+
headers.set("Cache-Control", cacheControl);
|
|
79
|
+
}
|
|
80
|
+
return Response.json(data, { status: 200, headers });
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
annieResponse,
|
|
84
|
+
effieResponse,
|
|
85
|
+
fnModule,
|
|
86
|
+
fnModuleExists,
|
|
87
|
+
fnModuleIds,
|
|
88
|
+
fnUrl,
|
|
89
|
+
imageResponse,
|
|
90
|
+
initFnRuntime
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts","../src/responses.ts"],"sourcesContent":["import type { EffieWebUrl } from \"@effing/effie\";\nimport type {\n Bounds,\n FnKind,\n FnModule,\n FnModuleLoader,\n FnUrlBuilder,\n} from \"./types\";\n\nlet moduleLoader: FnModuleLoader | null = null;\nlet urlBuilder: FnUrlBuilder | null = null;\n\nexport function initFnRuntime(config: {\n moduleLoader: FnModuleLoader;\n urlBuilder: FnUrlBuilder;\n}): void {\n moduleLoader = config.moduleLoader;\n urlBuilder = config.urlBuilder;\n}\n\nfunction getModuleLoader(): FnModuleLoader {\n if (!moduleLoader) {\n throw new Error(\n \"attempting to access module loader before initFnRuntime() was called\",\n );\n }\n return moduleLoader;\n}\n\nfunction getUrlBuilder(): FnUrlBuilder {\n if (!urlBuilder) {\n throw new Error(\n \"attempting to access URL builder before initFnRuntime() was called\",\n );\n }\n return urlBuilder;\n}\n\nexport function fnModule<K extends FnKind>(\n kind: K,\n id: string,\n): Promise<FnModule<K>> {\n return getModuleLoader().loadModule(kind, id);\n}\n\nexport function fnUrl<P extends Record<string, unknown>>(\n kind: FnKind,\n id: string,\n props: P,\n bounds: Bounds,\n): Promise<EffieWebUrl> {\n return getUrlBuilder().buildUrl(kind, id, props, bounds);\n}\n\nexport function fnModuleIds(kind: FnKind): string[] {\n return getModuleLoader().listModules(kind);\n}\n\nexport function fnModuleExists(kind: FnKind, id: string): boolean {\n return getModuleLoader().hasModule(kind, id);\n}\n","import type { EffieData, EffieSources } from \"@effing/effie\";\nimport { annieStream } from \"@effing/annie\";\nimport type { AnnieStreamOptions } from \"@effing/annie\";\n\nexport type ImageResponseOptions = {\n headers?: HeadersInit;\n cacheControl?: string;\n};\n\nfunction detectImageContentType(bytes: Uint8Array): string {\n if (bytes[0] === 0x89 && bytes[1] === 0x50) return \"image/png\";\n if (bytes[0] === 0xff && bytes[1] === 0xd8) return \"image/jpeg\";\n throw new Error(\"Unsupported image format: expected PNG or JPEG\");\n}\n\nexport function imageResponse(\n bytes: Uint8Array,\n options: ImageResponseOptions = {},\n): Response {\n const { headers: extraHeaders, cacheControl = \"public, max-age=3600\" } =\n options;\n\n const headers = new Headers(extraHeaders);\n headers.set(\"Content-Type\", detectImageContentType(bytes));\n if (cacheControl) {\n headers.set(\"Cache-Control\", cacheControl);\n }\n\n if (!(bytes.buffer instanceof ArrayBuffer)) {\n throw new TypeError(\"SharedArrayBuffer is not supported\");\n }\n\n return new Response(bytes.buffer, { status: 200, headers });\n}\n\nexport type AnnieResponseOptions = AnnieStreamOptions & {\n headers?: HeadersInit;\n cacheControl?: string;\n filename?: string;\n};\n\nexport function annieResponse(\n frames: AsyncIterable<Buffer>,\n options: AnnieResponseOptions = {},\n): Response {\n const {\n headers: extraHeaders,\n cacheControl = \"public, max-age=3600\",\n filename,\n ...streamOptions\n } = options;\n\n const stream = annieStream(frames, streamOptions);\n\n const headers = new Headers(extraHeaders);\n headers.set(\"Content-Type\", \"application/x-tar\");\n if (cacheControl) {\n headers.set(\"Cache-Control\", cacheControl);\n }\n if (filename) {\n headers.set(\"Content-Disposition\", `inline; filename=\"${filename}.tar\"`);\n }\n\n return new Response(stream, { status: 200, headers });\n}\n\nexport type EffieResponseOptions = {\n headers?: HeadersInit;\n cacheControl?: string;\n};\n\nexport function effieResponse<S extends EffieSources>(\n data: EffieData<S>,\n options: EffieResponseOptions = {},\n): Response {\n const { headers: extraHeaders, cacheControl = \"public, max-age=3600\" } =\n options;\n\n const headers = new Headers(extraHeaders);\n if (cacheControl) {\n headers.set(\"Cache-Control\", cacheControl);\n }\n\n return Response.json(data, { status: 200, headers });\n}\n"],"mappings":";AASA,IAAI,eAAsC;AAC1C,IAAI,aAAkC;AAE/B,SAAS,cAAc,QAGrB;AACP,iBAAe,OAAO;AACtB,eAAa,OAAO;AACtB;AAEA,SAAS,kBAAkC;AACzC,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,gBAA8B;AACrC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAA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I,iBAAiB,YAAY;AAAA,EAC3C;AACA,MAAI,UAAU;AACZ,YAAQ,IAAI,uBAAuB,qBAAqB,QAAQ,OAAO;AAAA,EACzE;AAEA,SAAO,IAAI,SAAS,QAAQ,EAAE,QAAQ,KAAK,QAAQ,CAAC;AACtD;AAOO,SAAS,cACd,MACA,UAAgC,CAAC,GACvB;AACV,QAAM,EAAE,SAAS,cAAc,eAAe,uBAAuB,IACnE;AAEF,QAAM,UAAU,IAAI,QAAQ,YAAY;AACxC,MAAI,cAAc;AAChB,YAAQ,IAAI,iBAAiB,YAAY;AAAA,EAC3C;AAEA,SAAO,SAAS,KAAK,MAAM,EAAE,QAAQ,KAAK,QAAQ,CAAC;AACrD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effing/fn",
|
|
3
|
+
"version": "0.26.1",
|
|
4
|
+
"description": "Effing function runtime — pluggable module loading and URL building",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@effing/annie": "0.27.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "^8.0.0",
|
|
20
|
+
"typescript": "^5.9.3",
|
|
21
|
+
"vitest": "^3.2.4",
|
|
22
|
+
"zod": "^3.25.76",
|
|
23
|
+
"@effing/effie": "0.27.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"zod": "^3.0.0",
|
|
27
|
+
"@effing/effie": "0.27.0"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"effing",
|
|
31
|
+
"functions",
|
|
32
|
+
"runtime"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
}
|
|
43
|
+
}
|