@primate/go 0.7.0 → 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.
@@ -1,7 +1,6 @@
1
1
  import E from "#errors";
2
2
  import module from "#module";
3
3
  import server from "@primate/core/server";
4
- import assert from "@rcompat/assert";
5
4
  import env from "@rcompat/env";
6
5
  import { CodeError } from "@rcompat/error";
7
6
  import io from "@rcompat/io";
@@ -52,10 +51,10 @@ function wrap(route_id) {
52
51
  import route from "primate/route";
53
52
  import wrapper from "@primate/go/wrapper";
54
53
  import bytes from "app:wasm/${route_id}.wasm" with { type: "bytes" };
55
- import i18n from "app:config:i18n";
54
+ import app from "$:app";
56
55
  import session from "app:config:session";
57
56
  const handlers = await wrapper(bytes, ${JSON.stringify(route_id)}, {
58
- i18n, session,
57
+ i18n: app.i18n, session,
59
58
  });
60
59
  export default route(handlers);
61
60
  `;
@@ -67,26 +66,29 @@ export default function default_module(input = {}) {
67
66
  setup({ onBuild }) {
68
67
  onBuild(async (app) => {
69
68
  await check_version(app);
70
- app.bind(extension, async (route, { context }) => {
71
- assert.true(context === "routes", E.only_route_files());
72
- const relative = route.debase(app.path.routes);
73
- const route_id = relative.path.slice(1, -relative.extension.length);
74
- const build_file = app.runpath("wasm", `${route_id}.go`);
75
- await build_file.directory.create();
76
- await build_file.write(postlude(app, await route.text(), route_id));
77
- const wasm = app.runpath("wasm", `${route_id}.wasm`);
78
- try {
79
- app.log.info `compiling ${(route.debase(app.root))} to WebAssembly`;
80
- await io.run(run(wasm, build_file), {
81
- cwd: build_file.directory.path,
82
- env: ENV,
83
- });
84
- }
85
- catch (error) {
86
- throw E.backend_error(route, error);
87
- }
88
- await build_file.remove();
89
- return wrap(route_id);
69
+ app.register(module.name, {
70
+ type: "backend",
71
+ extensions: [extension],
72
+ async onLoad(route) {
73
+ const relative = route.debase(app.path.routes);
74
+ const route_id = relative.path.slice(1, -relative.extension.length);
75
+ const build_file = app.runpath("wasm", `${route_id}.go`);
76
+ await build_file.directory.create();
77
+ await build_file.write(postlude(app, await route.text(), route_id));
78
+ const wasm = app.runpath("wasm", `${route_id}.wasm`);
79
+ try {
80
+ app.log.info `compiling ${(route.debase(app.root))} to WebAssembly`;
81
+ await io.run(run(wasm, build_file), {
82
+ cwd: build_file.directory.path,
83
+ env: ENV,
84
+ });
85
+ }
86
+ catch (error) {
87
+ throw E.backend_error(route, error);
88
+ }
89
+ await build_file.remove();
90
+ return wrap(route_id);
91
+ },
90
92
  });
91
93
  });
92
94
  },
@@ -1,7 +1,7 @@
1
1
  declare const module: {
2
2
  schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
3
3
  readonly extension: import("pema").OptionalType<import("pema").StringType>;
4
- }>, {
4
+ }>, undefined, {
5
5
  extension: string | undefined;
6
6
  }>;
7
7
  name: string;
@@ -1,3 +1,3 @@
1
- declare function _default(): void;
2
1
  export default _default;
2
+ declare function _default(): void;
3
3
  //# sourceMappingURL=wasm_exec.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/go",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Go backend for Primate",
5
5
  "homepage": "https://primate.run/docs/backend/go",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -17,20 +17,20 @@
17
17
  "!/**/*.spec.*"
18
18
  ],
19
19
  "dependencies": {
20
- "@rcompat/assert": "^0.13.0",
21
- "@rcompat/env": "^0.22.0",
22
- "@rcompat/error": "^0.8.0",
23
- "@rcompat/fs": "^0.33.2",
24
- "@rcompat/io": "^0.10.0",
25
- "@rcompat/is": "^0.11.0",
26
- "@primate/core": "^0.7.0",
27
- "pema": "^0.7.0"
20
+ "@rcompat/assert": "^0.14.0",
21
+ "@rcompat/env": "^0.23.0",
22
+ "@rcompat/error": "^0.9.0",
23
+ "@rcompat/fs": "^0.35.1",
24
+ "@rcompat/io": "^0.11.0",
25
+ "@rcompat/is": "^0.12.0",
26
+ "@primate/core": "^0.9.0",
27
+ "pema": "^0.9.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@rcompat/type": "^0.17.0"
30
+ "@rcompat/type": "^0.18.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "primate": "^0.38.0"
33
+ "primate": "^0.40.0"
34
34
  },
35
35
  "imports": {
36
36
  "#vendored/wasm_exec": "./src/private/vendored/wasm_exec.js",