silgi 0.32.1 → 0.33.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/dist/cli/index.mjs +1 -1
- package/dist/presets/_all.gen.mjs +2 -0
- package/dist/presets/_types.gen.d.mts +2 -2
- package/dist/presets/next/preset.d.mts +3 -0
- package/dist/presets/next/preset.mjs +37 -0
- package/dist/runtime/internal/nextjs.d.mts +4 -0
- package/dist/runtime/internal/nextjs.mjs +58 -0
- package/dist/types/index.d.mts +2 -1
- package/package.json +10 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import _h3 from "./h3/preset.mjs";
|
|
2
|
+
import _next from "./next/preset.mjs";
|
|
2
3
|
import _nitro from "./nitro/preset.mjs";
|
|
3
4
|
import _npmpackage from "./npmpackage/preset.mjs";
|
|
4
5
|
import _nuxt from "./nuxt/preset.mjs";
|
|
5
6
|
const presets = [
|
|
6
7
|
..._h3,
|
|
8
|
+
..._next,
|
|
7
9
|
..._nitro,
|
|
8
10
|
..._npmpackage,
|
|
9
11
|
..._nuxt
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface PresetOptions {
|
|
2
2
|
}
|
|
3
3
|
export declare const presetsWithConfig: readonly [];
|
|
4
|
-
export type PresetName = "h3" | "nitro" | "npm-package" | "nuxt";
|
|
5
|
-
export type PresetNameInput = "h3" | "nitro" | "npm-package" | "nuxt";
|
|
4
|
+
export type PresetName = "h3" | "next" | "nitro" | "npm-package" | "nuxt";
|
|
5
|
+
export type PresetNameInput = "h3" | "next" | "nitro" | "npm-package" | "nuxt";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineSilgiPreset } from "silgi/kit";
|
|
2
|
+
const next = defineSilgiPreset(
|
|
3
|
+
{
|
|
4
|
+
// output: {
|
|
5
|
+
// dir: '{{ rootDir }}/.output',
|
|
6
|
+
// publicDir: '{{ output.dir }}/public',
|
|
7
|
+
// },
|
|
8
|
+
serverDir: "{{ rootDir }}/src/server",
|
|
9
|
+
envOptions: {
|
|
10
|
+
prefix: "NEXT_",
|
|
11
|
+
altPrefix: "NUXT_"
|
|
12
|
+
},
|
|
13
|
+
imports: {
|
|
14
|
+
dirs: [
|
|
15
|
+
"!{{ serverDir }}/runtime/**",
|
|
16
|
+
"!{{ serverDir }}/api/**",
|
|
17
|
+
"!{{ serverDir }}/routes/**",
|
|
18
|
+
"!{{ serverDir }}/modules/**",
|
|
19
|
+
"!{{ serverDir }}/assets/**",
|
|
20
|
+
"!{{ serverDir }}/public/**",
|
|
21
|
+
"!{{ silgi.serverDir }}/**"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
hooks: {
|
|
25
|
+
ready: async () => {
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
storages: []
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "next",
|
|
32
|
+
static: true,
|
|
33
|
+
url: import.meta.url
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
const presets = [next];
|
|
37
|
+
export default presets;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type { Silgi } from 'silgi/types';
|
|
3
|
+
export declare function addNextApp(silgiCtx?: Silgi): Promise<(req: NextApiRequest, res: NextApiResponse) => Promise<void | NextApiResponse<any>>>;
|
|
4
|
+
export default addNextApp;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ErrorFactory, HttpStatus, parseURI, silgi, SilgiError, useSilgi } from "silgi";
|
|
2
|
+
export async function addNextApp(silgiCtx = useSilgi()) {
|
|
3
|
+
return async (req, res) => {
|
|
4
|
+
let operation;
|
|
5
|
+
try {
|
|
6
|
+
const silgiConnect = silgi(req);
|
|
7
|
+
const query = req.query || {};
|
|
8
|
+
const body = req.body || {};
|
|
9
|
+
let path = req.url || "";
|
|
10
|
+
if (path.includes("?")) {
|
|
11
|
+
path = `${path}&method=${req.method}`;
|
|
12
|
+
} else {
|
|
13
|
+
path = `${path}?method=${req.method}`;
|
|
14
|
+
}
|
|
15
|
+
operation = parseURI(path, silgiCtx.uris);
|
|
16
|
+
if (!operation) {
|
|
17
|
+
throw ErrorFactory.create({ message: "Invalid URI", httpStatus: HttpStatus.BAD_REQUEST });
|
|
18
|
+
}
|
|
19
|
+
await silgiCtx.callHook("event:init", req, {
|
|
20
|
+
path,
|
|
21
|
+
queryParams: query,
|
|
22
|
+
operation
|
|
23
|
+
});
|
|
24
|
+
const data = await silgiConnect.execute(path, {
|
|
25
|
+
...body
|
|
26
|
+
}, void 0, query);
|
|
27
|
+
if (data) {
|
|
28
|
+
return res.status(200).json(data);
|
|
29
|
+
}
|
|
30
|
+
return res.status(204).end();
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (SilgiError.isError(err)) {
|
|
33
|
+
return res.status(err.httpStatus).json({
|
|
34
|
+
message: err.message,
|
|
35
|
+
code: err.code,
|
|
36
|
+
category: err.category,
|
|
37
|
+
severity: err.severity,
|
|
38
|
+
context: err.context
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
await silgiCtx.callHook("execute:error", {
|
|
42
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
43
|
+
timestamp: Date.now(),
|
|
44
|
+
operation,
|
|
45
|
+
event: { req, res }
|
|
46
|
+
});
|
|
47
|
+
silgiCtx.captureError(silgiCtx, SilgiError.from(err), {
|
|
48
|
+
event: { req, res },
|
|
49
|
+
operation,
|
|
50
|
+
tags: ["execute"]
|
|
51
|
+
});
|
|
52
|
+
return res.status(500).json({
|
|
53
|
+
message: "Internal Server Error"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export default addNextApp;
|
package/dist/types/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ import * as nitropack_types from 'nitropack/types';
|
|
|
16
16
|
import { NitroRuntimeConfig } from 'nitropack/types';
|
|
17
17
|
import { Defu } from 'defu';
|
|
18
18
|
import { Stats } from 'node:fs';
|
|
19
|
+
import * as next from 'next';
|
|
19
20
|
import { ESMImport, ESMCodeGenOptions } from 'knitwork';
|
|
20
21
|
import { Unimport } from 'unimport';
|
|
21
22
|
import { Storage, TransactionOptions, BuiltinDriverName, StorageValue } from 'unstorage';
|
|
@@ -155,7 +156,7 @@ interface GenImport {
|
|
|
155
156
|
imports: ESMImport | ESMImport[];
|
|
156
157
|
options?: ESMCodeGenOptions;
|
|
157
158
|
}
|
|
158
|
-
type Framework<T extends PresetName> = T extends 'nitro' ? nitropack_types.NitroApp : T extends 'nuxt' ? nitropack_types.NitroApp : T extends 'h3' ? h3.Router : never;
|
|
159
|
+
type Framework<T extends PresetName> = T extends 'nitro' ? nitropack_types.NitroApp : T extends 'nuxt' ? nitropack_types.NitroApp : T extends 'h3' ? h3.Router : T extends 'next' ? next.NextApiHandler : never;
|
|
159
160
|
interface DefineFrameworkOptions<T extends PresetName> extends Omit<BuildSilgi$1, 'framework'> {
|
|
160
161
|
framework: Framework<T>;
|
|
161
162
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"import": "./dist/runtime/internal/index.mjs",
|
|
32
32
|
"silgiDev": "./dist/runtime/internal/index.ts"
|
|
33
33
|
},
|
|
34
|
+
"./runtime/internal/nuxt": {
|
|
35
|
+
"import": "./dist/runtime/internal/nuxt.mjs",
|
|
36
|
+
"silgiDev": "./dist/runtime/internal/nuxt.ts"
|
|
37
|
+
},
|
|
34
38
|
"./runtime/meta": "./lib/runtime-meta.mjs"
|
|
35
39
|
},
|
|
36
40
|
"main": "./dist/core/index.mjs",
|
|
@@ -49,6 +53,7 @@
|
|
|
49
53
|
"@nuxt/schema": ">=3.16.1",
|
|
50
54
|
"@silgi/ecosystem": ">=0.4.4",
|
|
51
55
|
"h3": ">=1.15.1",
|
|
56
|
+
"next": ">=15.3.1",
|
|
52
57
|
"nitropack": ">=2.11.7",
|
|
53
58
|
"nuxt": ">=3.16.1",
|
|
54
59
|
"typescript": ">=5.8.2",
|
|
@@ -65,6 +70,9 @@
|
|
|
65
70
|
"h3": {
|
|
66
71
|
"optional": true
|
|
67
72
|
},
|
|
73
|
+
"next": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
68
76
|
"nitropack": {
|
|
69
77
|
"optional": true
|
|
70
78
|
},
|
|
@@ -129,6 +137,7 @@
|
|
|
129
137
|
"@vitest/coverage-v8": "3.0.5",
|
|
130
138
|
"eslint": "^9.25.1",
|
|
131
139
|
"h3": "^1.15.1",
|
|
140
|
+
"next": "^15.3.1",
|
|
132
141
|
"nitropack": "^2.11.9",
|
|
133
142
|
"nuxt": "^3.16.2",
|
|
134
143
|
"typescript": "^5.8.3",
|