silgi 0.32.1 → 0.33.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.
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +2 -2
- 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 +14 -1
package/dist/cli/index.mjs
CHANGED
package/dist/cli/init.mjs
CHANGED
|
@@ -4,12 +4,12 @@ import * as p from '@clack/prompts';
|
|
|
4
4
|
import { defineCommand, runCommand } from 'citty';
|
|
5
5
|
import consola from 'consola';
|
|
6
6
|
import { dirname } from 'pathe';
|
|
7
|
-
import { isPresents } from 'silgi/kit';
|
|
8
7
|
import { c as cancelOnCancel, a as command$1 } from './prepare.mjs';
|
|
9
8
|
import 'silgi/meta';
|
|
10
9
|
import './build.mjs';
|
|
11
10
|
import 'hookable';
|
|
12
11
|
import 'silgi';
|
|
12
|
+
import 'silgi/kit';
|
|
13
13
|
import 'silgi/runtime/meta';
|
|
14
14
|
import 'unimport';
|
|
15
15
|
import '../_chunks/routeRules.mjs';
|
|
@@ -76,7 +76,7 @@ const command = defineCommand({
|
|
|
76
76
|
"})",
|
|
77
77
|
""
|
|
78
78
|
];
|
|
79
|
-
if (
|
|
79
|
+
if (framework === "nitro" || framework === "nuxt") {
|
|
80
80
|
const plugin = [
|
|
81
81
|
`import { buildSilgi } from '../silgi/core'`,
|
|
82
82
|
"",
|
|
@@ -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.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -27,10 +27,18 @@
|
|
|
27
27
|
"import": "./dist/runtime/internal/nitro.mjs",
|
|
28
28
|
"silgiDev": "./dist/runtime/internal/nitro.ts"
|
|
29
29
|
},
|
|
30
|
+
"./runtime/internal/next": {
|
|
31
|
+
"import": "./dist/runtime/internal/next.mjs",
|
|
32
|
+
"silgiDev": "./dist/runtime/internal/next.ts"
|
|
33
|
+
},
|
|
30
34
|
"./runtime/internal": {
|
|
31
35
|
"import": "./dist/runtime/internal/index.mjs",
|
|
32
36
|
"silgiDev": "./dist/runtime/internal/index.ts"
|
|
33
37
|
},
|
|
38
|
+
"./runtime/internal/nuxt": {
|
|
39
|
+
"import": "./dist/runtime/internal/nuxt.mjs",
|
|
40
|
+
"silgiDev": "./dist/runtime/internal/nuxt.ts"
|
|
41
|
+
},
|
|
34
42
|
"./runtime/meta": "./lib/runtime-meta.mjs"
|
|
35
43
|
},
|
|
36
44
|
"main": "./dist/core/index.mjs",
|
|
@@ -49,6 +57,7 @@
|
|
|
49
57
|
"@nuxt/schema": ">=3.16.1",
|
|
50
58
|
"@silgi/ecosystem": ">=0.4.4",
|
|
51
59
|
"h3": ">=1.15.1",
|
|
60
|
+
"next": ">=15.3.1",
|
|
52
61
|
"nitropack": ">=2.11.7",
|
|
53
62
|
"nuxt": ">=3.16.1",
|
|
54
63
|
"typescript": ">=5.8.2",
|
|
@@ -65,6 +74,9 @@
|
|
|
65
74
|
"h3": {
|
|
66
75
|
"optional": true
|
|
67
76
|
},
|
|
77
|
+
"next": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
68
80
|
"nitropack": {
|
|
69
81
|
"optional": true
|
|
70
82
|
},
|
|
@@ -129,6 +141,7 @@
|
|
|
129
141
|
"@vitest/coverage-v8": "3.0.5",
|
|
130
142
|
"eslint": "^9.25.1",
|
|
131
143
|
"h3": "^1.15.1",
|
|
144
|
+
"next": "^15.3.1",
|
|
132
145
|
"nitropack": "^2.11.9",
|
|
133
146
|
"nuxt": "^3.16.2",
|
|
134
147
|
"typescript": "^5.8.3",
|