@hulla/api-sveltekit 0.0.0-stage → 2.0.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.
@@ -0,0 +1,14 @@
1
+ import { SvelteKitAdapterContext, SvelteKitRequestEvent } from "./server.js";
2
+ import { ServerExecutableFor } from "@hulla/api/server";
3
+ import { Contract } from "@hulla/api";
4
+ import { ClientTransport } from "@hulla/api/client";
5
+ //#region src/remote.d.ts
6
+ /**
7
+ * Creates a zero-network client transport for use inside SvelteKit remote-function callbacks.
8
+ *
9
+ * An implementation whose context is bound with `svelteKitAdapter().context(...)` receives the current native
10
+ * `RequestEvent`. Context-free implementations do not access request state and can also run during prerendering.
11
+ */
12
+ declare function svelteKitRemoteTransport<const ContractType extends Contract, const Context extends object>(implementation: ServerExecutableFor<ContractType, Context, 'sveltekit', SvelteKitAdapterContext>): ClientTransport;
13
+ //#endregion
14
+ export { type SvelteKitAdapterContext, type SvelteKitRequestEvent, svelteKitRemoteTransport };
package/dist/remote.js ADDED
@@ -0,0 +1,54 @@
1
+ import { getRequestEvent } from "$app/server";
2
+ import { createAdapterHandler } from "@hulla/api/adapters";
3
+ import { assertAdapterContext, serverContextAdapterId } from "@hulla/api/server";
4
+
5
+ //#region src/remote-runtime.ts
6
+ /** Internal provider-injected implementation shared by the public SvelteKit remote entrypoint and unit tests. */
7
+ function createSvelteKitRemoteTransport(implementation, getRequestEvent) {
8
+ assertAdapterContext(implementation.context, "sveltekit");
9
+ const usesSvelteKitContext = serverContextAdapterId(implementation.context) === "sveltekit";
10
+ const dispatch = createAdapterHandler(implementation);
11
+ return async (request) => {
12
+ request.signal?.throwIfAborted();
13
+ const svelteKitEvent = usesSvelteKitContext ? getRequestEvent() : void 0;
14
+ const response = await dispatch({
15
+ request,
16
+ ...svelteKitEvent === void 0 ? {} : { contextInput: {
17
+ request: svelteKitEvent.request,
18
+ svelteKitEvent
19
+ } },
20
+ method: request.method,
21
+ pathname: request.path,
22
+ headers: request.headers,
23
+ ...request.query === void 0 ? {} : { query: request.query },
24
+ ...request.body === void 0 ? {} : { body: {
25
+ value: request.body.value,
26
+ contentType: request.body.contentType
27
+ } }
28
+ });
29
+ return {
30
+ status: response.status,
31
+ headers: response.headers,
32
+ native: response,
33
+ readBody: (kind) => {
34
+ if (response.body.kind !== kind) throw new TypeError(`SvelteKit remote response body is ${response.body.kind}, but the client selected ${kind}`);
35
+ return response.body.value;
36
+ }
37
+ };
38
+ };
39
+ }
40
+
41
+ //#endregion
42
+ //#region src/remote.ts
43
+ /**
44
+ * Creates a zero-network client transport for use inside SvelteKit remote-function callbacks.
45
+ *
46
+ * An implementation whose context is bound with `svelteKitAdapter().context(...)` receives the current native
47
+ * `RequestEvent`. Context-free implementations do not access request state and can also run during prerendering.
48
+ */
49
+ function svelteKitRemoteTransport(implementation) {
50
+ return createSvelteKitRemoteTransport(implementation, getRequestEvent);
51
+ }
52
+
53
+ //#endregion
54
+ export { svelteKitRemoteTransport };
@@ -0,0 +1,25 @@
1
+ import { Awaitable, ServerAdapter, ServerContextInput, ServerExecutableFor } from "@hulla/api/server";
2
+ import { FetchServerErrorInput } from "@hulla/api/fetch";
3
+ import { Contract } from "@hulla/api";
4
+ import { RequestEvent } from "@sveltejs/kit";
5
+ //#region src/server.d.ts
6
+ type SvelteKitRequestEvent = RequestEvent;
7
+ type SvelteKitRouteHandler = (event: SvelteKitRequestEvent) => Promise<Response>;
8
+ type SvelteKitAdapterContext = {
9
+ readonly request: Request;
10
+ readonly svelteKitEvent: SvelteKitRequestEvent;
11
+ };
12
+ type SvelteKitServerErrorInput = Omit<FetchServerErrorInput<SvelteKitRequestEvent>, 'handlerContext'> & {
13
+ readonly svelteKitEvent: SvelteKitRequestEvent;
14
+ };
15
+ type SvelteKitServerOptions = {
16
+ readonly onError?: ((input: SvelteKitServerErrorInput) => Awaitable<Response | undefined | void>) | undefined;
17
+ };
18
+ type SvelteKitContextInput<ContractType extends Contract = Contract> = ServerContextInput<ContractType> & SvelteKitAdapterContext;
19
+ type SvelteKitAdapter = ServerAdapter<'sveltekit', SvelteKitAdapterContext> & {
20
+ readonly mount: <const ContractType extends Contract, const Context extends object>(implementation: ServerExecutableFor<ContractType, Context, 'sveltekit', SvelteKitAdapterContext>, options?: SvelteKitServerOptions) => SvelteKitRouteHandler;
21
+ };
22
+ /** Creates a SvelteKit adapter with native request-event context and mounting operations. */
23
+ declare function svelteKitAdapter(options?: SvelteKitServerOptions): SvelteKitAdapter;
24
+ //#endregion
25
+ export { SvelteKitAdapter, SvelteKitAdapterContext, SvelteKitContextInput, SvelteKitRequestEvent, SvelteKitRouteHandler, SvelteKitServerErrorInput, SvelteKitServerOptions, svelteKitAdapter };
package/dist/server.js ADDED
@@ -0,0 +1,39 @@
1
+ import { createAdapterRuntime } from "@hulla/api/adapters";
2
+ import { createServerAdapter } from "@hulla/api/server";
3
+ import { createFetchHandler } from "@hulla/api/fetch";
4
+
5
+ //#region src/server.ts
6
+ /** Creates a SvelteKit endpoint handler backed by an @hulla/api server implementation. */
7
+ function createRouteHandler(implementation, options = {}) {
8
+ const unsupported = createAdapterRuntime(implementation).routes.filter((route) => route.method === "QUERY");
9
+ if (unsupported.length > 0) throw new TypeError(`SvelteKit endpoints do not support QUERY routes: ${unsupported.map((route) => route.key.join(".")).join(", ")}`);
10
+ const handler = createFetchHandler(implementation, {
11
+ contextAdapter: "sveltekit",
12
+ contextInput: (_request, svelteKitEvent) => ({ svelteKitEvent }),
13
+ ...options.onError === void 0 ? {} : { onError: ({ handlerContext, ...input }) => options.onError?.({
14
+ ...input,
15
+ svelteKitEvent: handlerContext
16
+ }) }
17
+ });
18
+ return async (event) => {
19
+ if (event.request.method !== "HEAD") return handler(event.request, event);
20
+ const response = await handler(new Request(event.request, { method: "GET" }), event);
21
+ return new Response(null, response);
22
+ };
23
+ }
24
+ let svelteKitAdapterValue;
25
+ function createSvelteKitAdapter(defaults) {
26
+ return createServerAdapter("sveltekit", { mount: (implementation, options) => createRouteHandler(implementation, options === void 0 ? defaults : {
27
+ ...defaults,
28
+ ...options
29
+ }) });
30
+ }
31
+ /** Creates a SvelteKit adapter with native request-event context and mounting operations. */
32
+ function svelteKitAdapter(options) {
33
+ if (options !== void 0) return createSvelteKitAdapter({ ...options });
34
+ svelteKitAdapterValue ??= createSvelteKitAdapter({});
35
+ return svelteKitAdapterValue;
36
+ }
37
+
38
+ //#endregion
39
+ export { svelteKitAdapter };
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@hulla/api-sveltekit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.1",
4
+ "description": "SvelteKit endpoint and remote-function integration for @hulla/api",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/hulladev/api.git",
9
+ "directory": "packages/sveltekit"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ "./server": {
18
+ "types": "./dist/server.d.ts",
19
+ "import": "./dist/server.js"
20
+ },
21
+ "./remote": {
22
+ "types": "./dist/remote.d.ts",
23
+ "import": "./dist/remote.js"
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
30
+ "scripts": {
31
+ "build": "tsdown",
32
+ "clean": "rm -rf dist coverage .svelte-kit",
33
+ "test": "bun run build && vitest run",
34
+ "test:coverage": "bun run build && vitest run --coverage",
35
+ "test:watch": "vitest",
36
+ "typecheck": "tsc --noEmit"
37
+ },
38
+ "devDependencies": {
39
+ "@hulla/api": "2.0.1",
40
+ "@sveltejs/kit": "^2.70.3",
41
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
42
+ "svelte": "^5.46.4",
43
+ "vite": "^8.2.2",
44
+ "zod": "^4.4.3"
45
+ },
46
+ "peerDependencies": {
47
+ "@hulla/api": "^2.0.1",
48
+ "@sveltejs/kit": "^2.0.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=22"
52
+ }
53
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.