@maravilla-labs/adapter-sveltekit 0.1.13 → 0.1.15

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AAEtD,UAAU,cAAc;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAgCD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAoOrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AAEtD,UAAU,cAAc;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAmCD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CA+PrE"}
package/dist/index.js CHANGED
@@ -21,8 +21,10 @@ async function loadFunctionsAPI() {
21
21
  integrateWithManifest: async () => { },
22
22
  };
23
23
  }
24
- // Inline worker template to avoid requiring separate worker.js file at runtime
25
- const INLINE_WORKER_TEMPLATE = `// Maravilla Runtime Worker for SvelteKit\n// This runs inside the Deno isolate with access to platform APIs\n\nimport { Server } from '__SERVER__';\nimport { manifest, prerendered, base } from '__MANIFEST__';\n\n// Initialize the SvelteKit server\nconst server = new Server(manifest);\n\n// Initialize server with platform-specific read function\nconst initialized = server.init({\n env: globalThis.platform?.env || {},\n read: async (file) => {\n // For now, return empty stream for any file read attempts\n // This is a placeholder until we implement proper static file serving\n console.log('Read function called for file:', file);\n \n // Return an empty ReadableStream to prevent errors\n return new ReadableStream({\n start(controller) {\n // Just close the stream immediately\n controller.close();\n }\n });\n }\n});\n\n/**\n * Main request handler for the Maravilla runtime\n * This function is called by the runtime for each incoming request\n */\nasync function handleRequest(request) {\n // Ensure server is initialized\n await initialized;\n\n // Convert the incoming request object to a standard Request\n const url = new URL(request.url, 'http://localhost');\n \n // Prepare the body - handle different types\n let requestBody = undefined;\n if (request.body !== null && request.body !== undefined) {\n // If body is already a string, use it directly\n if (typeof request.body === 'string') {\n requestBody = request.body;\n } else {\n // Otherwise stringify it\n requestBody = JSON.stringify(request.body);\n }\n }\n \n // Create a standard Request object\n const webRequest = new Request(url.toString(), {\n method: request.method,\n headers: request.headers || {},\n body: requestBody\n });\n\n // Check if this is a static asset request\n const pathname = url.pathname;\n const stripped_pathname = pathname.replace(/\\\/$/, '');\n\n // Debug: verify URL.pathname setter works for data requests\n if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {\n try {\n const test = new URL(url.toString());\n const before = test.pathname;\n const candidate = pathname.endsWith('/__data.json')\n ? pathname.slice(0, -'/__data.json'.length)\n : pathname.slice(0, -'.html__data.json'.length) + '.html';\n test.pathname = candidate;\n console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href });\n } catch (e) {\n console.error('Data URL normalization error', e);\n }\n }\n \n // Check if path is prerendered\n if (prerendered.has(pathname)) {\n // For prerendered pages, we could serve from static storage\n // but for now, let SvelteKit handle it\n }\n\n // Handle trailing slash redirects for prerendered pages\n const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';\n if (location && prerendered.has(location)) {\n return new Response('', {\n status: 308,\n headers: {\n location: location + url.search\n }\n });\n }\n\n // Let SvelteKit handle the request\n try {\n console.log('SvelteKit server.respond called with:', {\n url: webRequest.url,\n method: webRequest.method,\n hasBody: requestBody !== undefined,\n platform: {\n hasEnv: !!globalThis.platform?.env,\n hasKv: !!globalThis.platform?.kv,\n hasDb: !!globalThis.platform?.db\n }\n });\n \n const response = await server.respond(webRequest, {\n platform: {\n // Expose Maravilla platform APIs to SvelteKit\n env: globalThis.platform?.env || {},\n context: {\n waitUntil: (promise) => {\n // In Maravilla, we can queue background work\n if (globalThis.platform?.queue) {\n globalThis.platform.queue.send({ type: 'background', promise });\n }\n },\n passThroughOnException: () => {\n // Not applicable in Maravilla runtime\n }\n },\n // Expose platform services\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue\n },\n getClientAddress: () => {\n // Get client IP from request headers\n const forwarded = webRequest.headers.get('x-forwarded-for');\n if (forwarded) {\n return forwarded.split(',')[0].trim();\n }\n return request.headers?.['x-real-ip'] || '127.0.0.1';\n }\n });\n\n // Log response details\n if (response.status >= 400) {\n console.error('SvelteKit returned error:', {\n status: response.status,\n statusText: response.statusText,\n url: webRequest.url\n });\n }\n\n // Return the response in a format the runtime expects\n return response;\n } catch (error) {\n console.error('Error in server.respond:', error);\n console.error('Error stack:', error.stack);\n throw error;\n }\n}\n\n// Export for the Maravilla runtime\nglobalThis.handleRequest = handleRequest;`;
24
+ // Import the worker template from separate file for maintainability
25
+ import { WORKER_TEMPLATE } from './worker-template.js';
26
+ // Use the imported template
27
+ const INLINE_WORKER_TEMPLATE = WORKER_TEMPLATE;
26
28
  export default function adapter(options = {}) {
27
29
  const { out = '.maravilla', precompress = false, envPrefix = 'PUBLIC_', polyfill = true, include = [], exclude = [], external = [] } = options;
28
30
  return {
@@ -193,9 +195,39 @@ export default function adapter(options = {}) {
193
195
  // Integrate functions into manifest if they exist
194
196
  if (functionsManifest) {
195
197
  await integrateWithManifest(`${out}/manifest.json`, functionsManifest);
196
- // Merge functions bundle into server bundle for unified execution
197
- const { mergeFunctions } = await import('./merge-functions.js'); // emitted from TS source merge-functions.ts
198
+ const { mergeFunctions } = await import('./merge-functions.js');
198
199
  mergeFunctions(out);
200
+ try {
201
+ const fsMod = await import('node:fs');
202
+ const pathMod = await import('node:path');
203
+ const mPath = pathMod.join(out, 'manifest.json');
204
+ const raw = fsMod.readFileSync(mPath, 'utf8');
205
+ const m = JSON.parse(raw);
206
+ if (m.functions?.routes) {
207
+ // Build a map from path -> route object with name/file
208
+ const routeMap = new Map(m.functions.routes.map((r) => [r.path, r]));
209
+ if (Array.isArray(m.routing?.functions)) {
210
+ m.routing.functions = m.routing.functions.map((r) => {
211
+ const full = routeMap.get(r.path) || {};
212
+ return { ...r, name: full.name, file: full.file };
213
+ });
214
+ }
215
+ else {
216
+ // If missing, synthesize from functions.routes
217
+ m.routing.functions = m.functions.routes.map((r) => ({
218
+ path: r.path,
219
+ name: r.name,
220
+ methods: r.methods,
221
+ file: r.file,
222
+ handler: 'function'
223
+ }));
224
+ }
225
+ fsMod.writeFileSync(mPath, JSON.stringify(m, null, 2));
226
+ }
227
+ }
228
+ catch (e) {
229
+ builder.log.warn('Failed to augment routing.functions with name/file: ' + e?.message);
230
+ }
199
231
  }
200
232
  builder.log.minor(`Build complete. Output written to ${out}`);
201
233
  builder.log.minor('');
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAmBnC,KAAK,UAAU,gBA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AAE,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,QAAQ,EAAE;YACR,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;SACjB;KACF,CAAC;AACJ,CAAC"}
@@ -1,58 +1,22 @@
1
1
  import { readFileSync, writeFileSync, existsSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  /**
4
- * Merge functions bundle with server bundle
4
+ * Keep functions separate from server bundle for proper routing
5
5
  */
6
6
  export function mergeFunctions(buildDir) {
7
- const serverPath = join(buildDir, 'server.js');
8
7
  const functionsPath = join(buildDir, 'functions.js');
9
8
  const manifestPath = join(buildDir, 'manifest.json');
10
9
  if (!existsSync(functionsPath)) {
11
10
  console.log('No functions bundle found, skipping merge');
12
11
  return;
13
12
  }
14
- const serverCode = readFileSync(serverPath, 'utf8');
15
- const functionsCode = readFileSync(functionsPath, 'utf8');
16
13
  const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
17
- const mergedCode = `
18
- // === FUNCTIONS BUNDLE START ===
19
- ${functionsCode}
20
-
21
- // === SERVER BUNDLE START ===
22
- ${serverCode}
23
-
24
- // === FUNCTION ROUTING INTEGRATION ===
25
- (function() {
26
- const originalHandleRequest = (globalThis as any).handleRequest;
27
- (globalThis as any).handleRequest = async function(request: Request) {
28
- const url = new URL(request.url);
29
- const path = url.pathname;
30
- const functionRoutes = ${'${JSON.stringify(manifest.functions?.routes || [])}'};
31
- for (const route of functionRoutes) {
32
- if (path === route.path || path.startsWith(route.path + '/')) {
33
- console.log('[Functions] Handling function request:', path);
34
- if (typeof (globalThis as any).handleFunctionRequest === 'function') {
35
- try {
36
- return await (globalThis as any).handleFunctionRequest(request);
37
- } catch (error: any) {
38
- console.error('[Functions] Error handling function:', error);
39
- return new Response(
40
- JSON.stringify({ error: 'Function execution failed', message: error.message }),
41
- { status: 500, headers: { 'content-type': 'application/json' } }
42
- );
43
- }
44
- }
45
- }
46
- }
47
- return originalHandleRequest(request);
48
- };
49
- })();
50
- `;
51
- writeFileSync(serverPath, mergedCode);
52
- console.log('✅ Functions merged into server bundle');
14
+ // Mark functions as available but NOT integrated into server bundle
53
15
  if (manifest.functions) {
54
- manifest.functions.integrated = true;
16
+ manifest.functions.integrated = false;
17
+ manifest.functions.available = true;
55
18
  }
56
19
  writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
20
+ console.log('✅ Functions kept separate from server bundle for proper routing');
57
21
  }
58
22
  //# sourceMappingURL=merge-functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-functions.js","sourceRoot":"","sources":["../src/merge-functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAErD,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAA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AAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;IACtC,CAAC;IAED,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC;AACjF,CAAC"}
@@ -0,0 +1,171 @@
1
+ // This file contains the worker template as a proper TypeScript file for easier editing
2
+ // It will be inlined into index.ts during the build
3
+ export const WORKER_TEMPLATE = `// Maravilla Runtime Worker for SvelteKit
4
+ // This runs inside the Deno isolate with access to platform APIs
5
+
6
+ import { Server } from '__SERVER__';
7
+ import { manifest, prerendered, base } from '__MANIFEST__';
8
+
9
+ // Initialize the SvelteKit server
10
+ const server = new Server(manifest);
11
+
12
+ // Initialize server with platform-specific read function
13
+ const initialized = server.init({
14
+ env: globalThis.platform?.env || {},
15
+ read: async (file) => {
16
+ // For now, return empty stream for any file read attempts
17
+ // This is a placeholder until we implement proper static file serving
18
+ console.log('Read function called for file:', file);
19
+
20
+ // Return an empty ReadableStream to prevent errors
21
+ return new ReadableStream({
22
+ start(controller) {
23
+ // Just close the stream immediately
24
+ controller.close();
25
+ }
26
+ });
27
+ }
28
+ });
29
+
30
+ /**
31
+ * Main request handler for the Maravilla runtime
32
+ * This function is called by the runtime for each incoming request
33
+ */
34
+ async function handleRequest(request) {
35
+ // Ensure server is initialized
36
+ await initialized;
37
+
38
+ // Check if request is already a Web API Request object
39
+ let webRequest;
40
+ if (request instanceof Request) {
41
+ // It's already a proper Request object from the runtime
42
+ console.log('Request is already a Web API Request object');
43
+ webRequest = request;
44
+ } else {
45
+ // It's a plain object, convert it to a Request (fallback for older runtime)
46
+ console.log('Converting plain object to Request');
47
+ const url = new URL(request.url, 'http://localhost');
48
+
49
+ // Prepare the body - handle different types
50
+ let requestBody = undefined;
51
+ if (request.body !== null && request.body !== undefined) {
52
+ // If body is already a string, use it directly
53
+ if (typeof request.body === 'string') {
54
+ requestBody = request.body;
55
+ } else {
56
+ // Otherwise stringify it
57
+ requestBody = JSON.stringify(request.body);
58
+ }
59
+ }
60
+
61
+ // Create a standard Request object
62
+ webRequest = new Request(url.toString(), {
63
+ method: request.method,
64
+ headers: request.headers || {},
65
+ body: requestBody
66
+ });
67
+ }
68
+
69
+ // Check if this is a static asset request
70
+ const pathname = new URL(webRequest.url).pathname;
71
+ const stripped_pathname = pathname.replace(/\\/$/, '');
72
+
73
+ // Debug: verify URL.pathname setter works for data requests
74
+ if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {
75
+ try {
76
+ const test = new URL(webRequest.url);
77
+ const before = test.pathname;
78
+ const candidate = pathname.endsWith('/__data.json')
79
+ ? pathname.slice(0, -'/__data.json'.length)
80
+ : pathname.slice(0, -'.html__data.json'.length) + '.html';
81
+ test.pathname = candidate;
82
+ console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href });
83
+ } catch (e) {
84
+ console.error('Data URL normalization error', e);
85
+ }
86
+ }
87
+
88
+ // Check if path is prerendered
89
+ if (prerendered.has(pathname)) {
90
+ // For prerendered pages, we could serve from static storage
91
+ // but for now, let SvelteKit handle it
92
+ }
93
+
94
+ // Handle trailing slash redirects for prerendered pages
95
+ const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';
96
+ if (location && prerendered.has(location)) {
97
+ const urlObj = new URL(webRequest.url);
98
+ return new Response('', {
99
+ status: 308,
100
+ headers: {
101
+ location: location + urlObj.search
102
+ }
103
+ });
104
+ }
105
+
106
+ // Let SvelteKit handle the request
107
+ try {
108
+ console.log('SvelteKit server.respond called with:', {
109
+ url: webRequest.url,
110
+ method: webRequest.method,
111
+ hasBody: webRequest.body !== null,
112
+ platform: {
113
+ hasEnv: !!globalThis.platform?.env,
114
+ hasKv: !!globalThis.platform?.kv,
115
+ hasDb: !!globalThis.platform?.db
116
+ }
117
+ });
118
+
119
+ const response = await server.respond(webRequest, {
120
+ platform: {
121
+ // Expose Maravilla platform APIs to SvelteKit
122
+ env: globalThis.platform?.env || {},
123
+ context: {
124
+ waitUntil: (promise) => {
125
+ // In Maravilla, we can queue background work
126
+ if (globalThis.platform?.queue) {
127
+ globalThis.platform.queue.send({ type: 'background', promise });
128
+ }
129
+ },
130
+ passThroughOnException: () => {
131
+ // Not applicable in Maravilla runtime
132
+ }
133
+ },
134
+ // Expose platform services
135
+ kv: globalThis.platform?.kv,
136
+ db: globalThis.platform?.db,
137
+ storage: globalThis.platform?.storage,
138
+ queue: globalThis.platform?.queue
139
+ },
140
+ getClientAddress: () => {
141
+ // Get client IP from request headers
142
+ const forwarded = webRequest.headers.get('x-forwarded-for');
143
+ if (forwarded) {
144
+ return forwarded.split(',')[0].trim();
145
+ }
146
+ // Fallback for plain object format (shouldn't happen with proper Request)
147
+ return request.headers?.['x-real-ip'] || '127.0.0.1';
148
+ }
149
+ });
150
+
151
+ // Log response details
152
+ if (response.status >= 400) {
153
+ console.error('SvelteKit returned error:', {
154
+ status: response.status,
155
+ statusText: response.statusText,
156
+ url: webRequest.url
157
+ });
158
+ }
159
+
160
+ // Return the response in a format the runtime expects
161
+ return response;
162
+ } catch (error) {
163
+ console.error('Error in server.respond:', error);
164
+ console.error('Error stack:', error.stack);
165
+ throw error;
166
+ }
167
+ }
168
+
169
+ // Export for the Maravilla runtime
170
+ globalThis.handleRequest = handleRequest;`;
171
+ //# sourceMappingURL=worker-template.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/adapter-sveltekit",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "SvelteKit adapter for Maravilla Runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,8 @@
12
12
  "dist/index.d.ts.map",
13
13
  "dist/merge-functions.js",
14
14
  "dist/merge-functions.js.map",
15
- "dist/worker.js"
15
+ "dist/worker.js",
16
+ "worker-template.js"
16
17
  ],
17
18
  "scripts": {
18
19
  "build": "tsc",
@@ -38,7 +39,13 @@
38
39
  "access": "public"
39
40
  },
40
41
  "peerDependencies": {
41
- "@sveltejs/kit": "^2.0.0"
42
+ "@sveltejs/kit": "^2.0.0",
43
+ "@maravilla-labs/functions": "*"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@maravilla-labs/functions": {
47
+ "optional": true
48
+ }
42
49
  },
43
50
  "devDependencies": {
44
51
  "@sveltejs/kit": "^2.0.0",
@@ -47,7 +54,6 @@
47
54
  "vitest": "^1.0.0"
48
55
  },
49
56
  "dependencies": {
50
- "@maravilla-labs/functions": "latest",
51
57
  "esbuild": "^0.25.0",
52
58
  "set-cookie-parser": "^2.6.0"
53
59
  }