@skgo/sveltekit-adapter 0.3.7 → 0.9.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @skgo/sveltekit-adapter
2
2
 
3
- The SvelteKit adapter for [skgo](https://github.com/tylergannon/skgo), a
3
+ The runtime SvelteKit adapter for [skgo](https://github.com/tylergannon/skgo), a
4
4
  SvelteKit application server written in Go.
5
5
 
6
6
  The app stays plain SvelteKit. This adapter builds it into the shape a skgo
@@ -16,10 +16,9 @@ pnpm add -D '@skgo/sveltekit-adapter@<=VERSION'
16
16
  without its `v`: for skgo `v0.3.4`, ask for `<=0.3.4`. A skgo release publishes
17
17
  this package only when the package itself changes, so the newest version at or
18
18
  below yours is the one carrying your skgo's adapter, and skgo refuses to start
19
- with any other. A project made by `skgo new` writes that dependency already,
20
- and lists the package under pnpm's `minimumReleaseAgeExclude`: held to a
21
- minimum release age, pnpm would quietly install an older version for a day
22
- after a release that changes this one.
19
+ with any other. If pnpm's minimum release age is enabled, exclude this package;
20
+ otherwise pnpm may quietly install an older adapter immediately after a release
21
+ that changes it.
23
22
 
24
23
  ```js
25
24
  // vite.config.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skgo/sveltekit-adapter",
3
- "version": "0.3.7",
3
+ "version": "0.9.0",
4
4
  "description": "SvelteKit adapter for skgo: builds a frontend that a Go binary renders and answers",
5
5
  "keywords": [
6
6
  "adapter",
@@ -219,6 +219,7 @@ function node_data(node) {
219
219
  }
220
220
 
221
221
  function build_props(req, url) {
222
+ const form = req.form ? devalue.parse(req.form, decoders) : null;
222
223
  const page = {
223
224
  error: req.error ?? null,
224
225
  params: req.params ?? {},
@@ -226,7 +227,7 @@ function build_props(req, url) {
226
227
  status: req.status ?? 200,
227
228
  url,
228
229
  data: {},
229
- form: req.form ?? null,
230
+ form,
230
231
  shallow: null,
231
232
  state: {}
232
233
  };
@@ -239,7 +240,7 @@ function build_props(req, url) {
239
240
  const props = new Props({
240
241
  page,
241
242
  tree: new RenderNode(components[branch[0].node], undefined),
242
- form: req.form ?? null,
243
+ form,
243
244
  error: req.error ?? undefined
244
245
  });
245
246
 
@@ -417,4 +418,4 @@ globalThis.__skgo_render = function (req_json) {
417
418
  // A liveness check Go calls once, when it puts a fresh runtime into the pool.
418
419
  globalThis.__skgo_ping = function () {
419
420
  return 'ok';
420
- };
421
+ };
package/skgo-adapter.js CHANGED
@@ -73,7 +73,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
73
73
 
74
74
  const nodes = await readNodes(builder, source, kit);
75
75
  const serverIds = nodes.map((node) => node.server);
76
- checkServerLoads(serverIds, generated.loads);
76
+ checkServerLoads(serverIds, generated.loads, generated.actions);
77
77
 
78
78
  const endpoints = checkEndpoints(builder, generated.endpoints);
79
79
 
@@ -128,12 +128,15 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
128
128
  appDir: builder.config.appDir,
129
129
  base: builder.config.paths.base,
130
130
  version: builder.config.version.name,
131
+ trustedOrigins: builder.config.csrf.trustedOrigins,
131
132
  // One entry per node, positionally: the vite-root-relative
132
133
  // path of its `+*.server.ts`, or "" for a node that has
133
134
  // none. It is how Go finds the load that answers a slot of
134
135
  // a route's branch, and it is the same key kit itself
135
136
  // records in the node module it builds.
136
137
  nodes: serverIds,
138
+ loads: generated.loads,
139
+ actions: [...new Set(generated.actions)].sort(),
137
140
  ssr: describeSSR(builder, kit, nodes),
138
141
  routes: kit._.routes.map((/** @type {any} */ route) => ({
139
142
  id: route.id,
@@ -199,7 +202,7 @@ export default function skgo({ out = 'build', precompress = true } = {}) {
199
202
  * quietly compares nothing to nothing reports success for an app whose two
200
203
  * halves were never checked against each other.
201
204
  *
202
- * @returns {{ remotes: string[], loads: string[], endpoints: Record<string, string[]> }}
205
+ * @returns {{ remotes: string[], loads: string[], actions: string[], endpoints: Record<string, string[]> }}
203
206
  */
204
207
  function readGenerated() {
205
208
  let raw;
@@ -235,6 +238,14 @@ function readGenerated() {
235
238
  );
236
239
  }
237
240
  }
241
+ if (!Array.isArray(parsed.actions)) {
242
+ throw new Error('skgo: skgo.remotes.json has no `actions` array. Run `go generate ./...` before building the frontend.');
243
+ }
244
+ for (const module of parsed.actions) {
245
+ if (typeof module !== 'string' || !/\/\+page\.server\.ts$/.test(module)) {
246
+ throw new Error(`skgo: skgo.remotes.json lists ${JSON.stringify(module)}, which is not a +page.server.ts action path.`);
247
+ }
248
+ }
238
249
  if (typeof parsed.endpoints !== 'object' || parsed.endpoints === null || Array.isArray(parsed.endpoints)) {
239
250
  throw new Error(
240
251
  'skgo: skgo.remotes.json has no `endpoints` object. Run `go generate ./...` before building the frontend.'
@@ -247,7 +258,7 @@ function readGenerated() {
247
258
  );
248
259
  }
249
260
  }
250
- return { remotes: parsed.remotes, loads: parsed.loads, endpoints: parsed.endpoints };
261
+ return { remotes: parsed.remotes, loads: parsed.loads, actions: parsed.actions, endpoints: parsed.endpoints };
251
262
  }
252
263
 
253
264
  /**
@@ -740,10 +751,11 @@ function* walk(dir) {
740
751
  *
741
752
  * @param {string[]} nodes
742
753
  * @param {string[]} loads
754
+ * @param {string[]} actions
743
755
  */
744
- function checkServerLoads(nodes, loads) {
756
+ function checkServerLoads(nodes, loads, actions) {
745
757
  const built = new Set(nodes.filter(Boolean));
746
- const declared = new Set(loads);
758
+ const declared = new Set([...loads, ...actions]);
747
759
 
748
760
  const missing = [...declared].filter((id) => !built.has(id));
749
761
  const extra = [...built].filter((id) => !declared.has(id));