silgi 0.2.3 → 0.3.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/chunks/generate.mjs +82 -31
- package/dist/cli/config.d.mts +2 -3
- package/dist/cli/config.d.ts +2 -3
- package/dist/cli/index.mjs +20 -4
- package/dist/ecosystem/nitro/index.mjs +2 -2
- package/dist/ecosystem/nuxt/module.mjs +10 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/shared/{silgi.DT4okyEE.mjs → silgi.2D3gmgW0.mjs} +1 -1
- package/dist/shared/{silgi.C0NIj2vN.mjs → silgi.BNEdIEZH.mjs} +0 -7
- package/dist/shared/{silgi.wMv9BQmS.d.ts → silgi.DJkQv6rh.d.mts} +36 -109
- package/dist/shared/{silgi.wMv9BQmS.d.mts → silgi.DJkQv6rh.d.ts} +36 -109
- package/dist/shared/{silgi.BxA0HYd5.mjs → silgi.mBwNj1W0.mjs} +18 -66
- package/package.json +18 -4
package/dist/chunks/generate.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
|
-
import { l as loadSilgiConfig } from '../shared/silgi.
|
|
2
|
+
import { l as loadSilgiConfig } from '../shared/silgi.2D3gmgW0.mjs';
|
|
3
3
|
import { createHooks } from 'hookable';
|
|
4
4
|
import ignore from 'ignore';
|
|
5
5
|
import { isAbsolute, resolve, join, relative, dirname, basename, extname } from 'pathe';
|
|
6
6
|
import { promises, existsSync, writeFileSync, readFileSync } from 'node:fs';
|
|
7
7
|
import { readPackageJSON } from 'pkg-types';
|
|
8
|
-
import { r as relativeWithDot } from '../shared/silgi.
|
|
8
|
+
import { r as relativeWithDot } from '../shared/silgi.BNEdIEZH.mjs';
|
|
9
9
|
import { defu } from 'defu';
|
|
10
10
|
import { withTrailingSlash } from 'ufo';
|
|
11
11
|
import { resolvePath, resolve as resolve$1 } from 'mlly';
|
|
12
|
-
import { i as getDirectory, r as resolveSilgiModule, j as resolvePath$1, k as generateUris, m as generateSilgiStorageBaseType } from '../shared/silgi.
|
|
12
|
+
import { i as getDirectory, r as resolveSilgiModule, j as resolvePath$1, k as generateUris, m as generateSilgiStorageBaseType } from '../shared/silgi.mBwNj1W0.mjs';
|
|
13
13
|
import { readdir } from 'node:fs/promises';
|
|
14
14
|
import { consola } from 'consola';
|
|
15
15
|
import { globby } from 'globby';
|
|
@@ -329,16 +329,6 @@ async function _generateSilgiFile(silgi) {
|
|
|
329
329
|
"",
|
|
330
330
|
" return silgi",
|
|
331
331
|
"}",
|
|
332
|
-
"",
|
|
333
|
-
"export default function createSilgiConfig() {",
|
|
334
|
-
" const returnObject = {",
|
|
335
|
-
" uris,",
|
|
336
|
-
" services,",
|
|
337
|
-
" shareds,",
|
|
338
|
-
" schemas,",
|
|
339
|
-
" }",
|
|
340
|
-
" return returnObject",
|
|
341
|
-
"}",
|
|
342
332
|
""
|
|
343
333
|
].join("\n");
|
|
344
334
|
return {
|
|
@@ -558,8 +548,67 @@ async function writeRootTsConfig(silgi) {
|
|
|
558
548
|
await promises.writeFile(tsConfigPath, GeneratedBy);
|
|
559
549
|
}
|
|
560
550
|
|
|
551
|
+
async function generateRouterDTS(silgi) {
|
|
552
|
+
silgi.hook("read:core.ts", async (data) => {
|
|
553
|
+
silgi.hook("close", async () => {
|
|
554
|
+
const { object } = await data();
|
|
555
|
+
const uris = object.uris;
|
|
556
|
+
const tag = "srn";
|
|
557
|
+
const groupedRoutes = Object.entries(uris).reduce((acc, [key, _value]) => {
|
|
558
|
+
const [service, resource, method, action] = key.split("/");
|
|
559
|
+
const routePath = `${tag}/${service}/${resource}/${action}`;
|
|
560
|
+
if (!acc[routePath]) {
|
|
561
|
+
acc[routePath] = {};
|
|
562
|
+
}
|
|
563
|
+
acc[routePath][method] = {
|
|
564
|
+
input: `ExtractInputFromURI<'${key}'>`,
|
|
565
|
+
output: `ExtractOutputFromURI<'${key}'>`,
|
|
566
|
+
params: `ExtractRouterParamsFromURI<'${key}'>['params']`
|
|
567
|
+
};
|
|
568
|
+
return acc;
|
|
569
|
+
}, {});
|
|
570
|
+
const routerTypes = Object.entries(groupedRoutes).map(([path, methods]) => {
|
|
571
|
+
const methodEntries = Object.entries(methods).map(([method, { input, output, params }]) => {
|
|
572
|
+
return ` '${method}': {
|
|
573
|
+
input: ${input},
|
|
574
|
+
output: ${output}
|
|
575
|
+
params: ${params}
|
|
576
|
+
}`;
|
|
577
|
+
}).join(",\n");
|
|
578
|
+
return ` '/${path}': {
|
|
579
|
+
${methodEntries}
|
|
580
|
+
}`;
|
|
581
|
+
});
|
|
582
|
+
const nitro = [
|
|
583
|
+
"declare module 'nitropack/types' {",
|
|
584
|
+
" interface InternalApi extends RouterTypes {}",
|
|
585
|
+
"}"
|
|
586
|
+
];
|
|
587
|
+
const context = [
|
|
588
|
+
"import type { ExtractInputFromURI, ExtractOutputFromURI, ExtractRouterParamsFromURI } from 'silgi'",
|
|
589
|
+
"",
|
|
590
|
+
"export interface RouterTypes {",
|
|
591
|
+
routerTypes.join(",\n"),
|
|
592
|
+
"}",
|
|
593
|
+
"",
|
|
594
|
+
"declare module 'silgi' {",
|
|
595
|
+
" interface SilgiRouterTypes extends RouterTypes {",
|
|
596
|
+
" }",
|
|
597
|
+
"}",
|
|
598
|
+
"",
|
|
599
|
+
silgi.options.environment === "h3" || silgi.options.environment === "nitrojs" ? nitro.join("\n") : "",
|
|
600
|
+
"",
|
|
601
|
+
"export {}"
|
|
602
|
+
].join("\n");
|
|
603
|
+
const outputPath = resolve(silgi.options.buildDir, "silgi-routes.d.ts");
|
|
604
|
+
await promises.writeFile(outputPath, context);
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
561
609
|
async function writeTypes(silgi) {
|
|
562
610
|
await writeH3DTS(silgi);
|
|
611
|
+
await generateRouterDTS(silgi);
|
|
563
612
|
await writeSilgiFile(silgi);
|
|
564
613
|
await writeSchema(silgi);
|
|
565
614
|
await writeTsConfig(silgi);
|
|
@@ -877,25 +926,24 @@ async function scanFiles(silgi) {
|
|
|
877
926
|
}
|
|
878
927
|
|
|
879
928
|
async function readSilgiTs(silgi) {
|
|
880
|
-
const jiti = createJiti(silgi.options.silgiDir);
|
|
881
929
|
const path = resolve(silgi.options.silgiDir, "core.ts");
|
|
930
|
+
const jiti = createJiti(silgi.options.rootDir, {
|
|
931
|
+
fsCache: false,
|
|
932
|
+
interopDefault: true,
|
|
933
|
+
moduleCache: false
|
|
934
|
+
});
|
|
882
935
|
const context = await promises.readFile(path, "utf-8");
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
{
|
|
886
|
-
default: true
|
|
887
|
-
}
|
|
936
|
+
const coreFile = await jiti.import(
|
|
937
|
+
path
|
|
888
938
|
);
|
|
889
|
-
if (typeof silgiTypes === "string") {
|
|
890
|
-
throw new TypeError(`Could not load \`${silgiTypes}\`. Is it installed?`);
|
|
891
|
-
}
|
|
892
|
-
if (typeof silgiTypes !== "function") {
|
|
893
|
-
throw new TypeError(`Nuxt module should be a function: ${silgiTypes}`);
|
|
894
|
-
}
|
|
895
|
-
const object = silgiTypes();
|
|
896
939
|
return {
|
|
897
940
|
context,
|
|
898
|
-
object
|
|
941
|
+
object: {
|
|
942
|
+
schemas: coreFile.schemas,
|
|
943
|
+
uris: coreFile.uris,
|
|
944
|
+
services: coreFile.services,
|
|
945
|
+
shareds: coreFile.shareds
|
|
946
|
+
},
|
|
899
947
|
path
|
|
900
948
|
};
|
|
901
949
|
}
|
|
@@ -1174,18 +1222,20 @@ async function generate$1(mergeConfig) {
|
|
|
1174
1222
|
};
|
|
1175
1223
|
silgi._ignore = ignore(silgi.options.ignoreOptions);
|
|
1176
1224
|
silgi.hook("prepare:types", (opts) => {
|
|
1177
|
-
opts.references.push({ path: resolve(silgi.options.buildDir, "schema.d.ts") });
|
|
1178
|
-
opts.references.push({ path: resolve(silgi.options.buildDir, "h3.d.ts") });
|
|
1225
|
+
opts.references.push({ path: resolve(silgi.options.buildDir, "./schema.d.ts") });
|
|
1226
|
+
opts.references.push({ path: resolve(silgi.options.buildDir, "./h3.d.ts") });
|
|
1227
|
+
opts.references.push({ path: resolve(silgi.options.buildDir, "./silgi-routes.d.ts") });
|
|
1179
1228
|
});
|
|
1180
1229
|
await generateUris(silgi);
|
|
1181
1230
|
await generateSilgiStorageBaseType(silgi);
|
|
1182
1231
|
await installCLIModules(silgi);
|
|
1183
1232
|
await scanFiles(silgi);
|
|
1184
1233
|
await writeTypes(silgi);
|
|
1185
|
-
silgi.callHook("read:core.ts", async () => {
|
|
1234
|
+
await silgi.callHook("read:core.ts", async () => {
|
|
1186
1235
|
const data = await readSilgiTs(silgi);
|
|
1187
1236
|
return data;
|
|
1188
1237
|
});
|
|
1238
|
+
return silgi;
|
|
1189
1239
|
}
|
|
1190
1240
|
|
|
1191
1241
|
const generate = defineCommand({
|
|
@@ -1201,7 +1251,8 @@ const generate = defineCommand({
|
|
|
1201
1251
|
dev: true
|
|
1202
1252
|
}
|
|
1203
1253
|
});
|
|
1204
|
-
await generate$1(mergeConfig);
|
|
1254
|
+
const silgi = await generate$1(mergeConfig);
|
|
1255
|
+
await silgi.close();
|
|
1205
1256
|
}
|
|
1206
1257
|
});
|
|
1207
1258
|
|
package/dist/cli/config.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as unstorage from 'unstorage';
|
|
2
2
|
import * as net from 'net';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
|
-
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions
|
|
4
|
+
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.DJkQv6rh.mjs';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
|
+
import '@standard-schema/spec';
|
|
7
8
|
import 'defu';
|
|
8
|
-
import 'zod';
|
|
9
9
|
import 'h3';
|
|
10
10
|
import 'pkg-types';
|
|
11
11
|
import 'nitropack/types';
|
|
@@ -13,7 +13,6 @@ import 'nitropack/types';
|
|
|
13
13
|
declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<SilgiModuleOptions>): {
|
|
14
14
|
[x: string]: any;
|
|
15
15
|
environment?: ("nitrojs" | "h3" | "undefined") | undefined;
|
|
16
|
-
validationLibrary?: ValidationLibrary | undefined;
|
|
17
16
|
isPackage?: boolean | undefined;
|
|
18
17
|
_eventContext?: {
|
|
19
18
|
clear?: {} | undefined;
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as unstorage from 'unstorage';
|
|
2
2
|
import * as net from 'net';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
|
-
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions
|
|
4
|
+
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.DJkQv6rh.js';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
|
+
import '@standard-schema/spec';
|
|
7
8
|
import 'defu';
|
|
8
|
-
import 'zod';
|
|
9
9
|
import 'h3';
|
|
10
10
|
import 'pkg-types';
|
|
11
11
|
import 'nitropack/types';
|
|
@@ -13,7 +13,6 @@ import 'nitropack/types';
|
|
|
13
13
|
declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<SilgiModuleOptions>): {
|
|
14
14
|
[x: string]: any;
|
|
15
15
|
environment?: ("nitrojs" | "h3" | "undefined") | undefined;
|
|
16
|
-
validationLibrary?: ValidationLibrary | undefined;
|
|
17
16
|
isPackage?: boolean | undefined;
|
|
18
17
|
_eventContext?: {
|
|
19
18
|
clear?: {} | undefined;
|
package/dist/cli/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import consola from 'consola';
|
|
|
3
3
|
|
|
4
4
|
const name = "silgi";
|
|
5
5
|
const type = "module";
|
|
6
|
-
const version = "0.
|
|
6
|
+
const version = "0.3.1";
|
|
7
7
|
const packageManager = "pnpm@9.15.1";
|
|
8
8
|
const sideEffects = false;
|
|
9
9
|
const exports = {
|
|
@@ -67,10 +67,24 @@ const scripts = {
|
|
|
67
67
|
pb: "pnpm unbuild && pnpm publish --no-git-checks --access public",
|
|
68
68
|
generate: "pnpm --filter ./playground... generate && pnpm --filter ./modules... generate && pnpm --filter ./ecosystem... generate && pnpm --filter ./examples/** generate"
|
|
69
69
|
};
|
|
70
|
+
const peerDependencies = {
|
|
71
|
+
"@nuxt/kit": "^3.15.3",
|
|
72
|
+
typescript: "^5.7.3",
|
|
73
|
+
zod: "^3.24.1"
|
|
74
|
+
};
|
|
75
|
+
const peerDependenciesMeta = {
|
|
76
|
+
"@nuxt/kit": {
|
|
77
|
+
optional: true
|
|
78
|
+
},
|
|
79
|
+
zod: {
|
|
80
|
+
optional: true
|
|
81
|
+
}
|
|
82
|
+
};
|
|
70
83
|
const dependencies = {
|
|
71
84
|
"@antfu/eslint-config": "^3.16.0",
|
|
72
85
|
"@nuxt/schema": "^3.15.2",
|
|
73
86
|
"@oxc-parser/wasm": "^0.48.0",
|
|
87
|
+
"@standard-schema/spec": "^1.0.0",
|
|
74
88
|
c12: "^2.0.1",
|
|
75
89
|
citty: "^0.1.6",
|
|
76
90
|
consola: "^3.4.0",
|
|
@@ -96,15 +110,15 @@ const dependencies = {
|
|
|
96
110
|
unctx: "^2.4.1",
|
|
97
111
|
unimport: "^4.0.0",
|
|
98
112
|
unstorage: "^1.14.4",
|
|
99
|
-
untyped: "^1.5.2"
|
|
100
|
-
zod: "^3.24.1"
|
|
113
|
+
untyped: "^1.5.2"
|
|
101
114
|
};
|
|
102
115
|
const devDependencies = {
|
|
103
116
|
"@nuxt/kit": "^3.15.3",
|
|
104
117
|
"@types/node": "^22.10.7",
|
|
105
118
|
"@types/semver": "^7.5.8",
|
|
106
119
|
unbuild: "^3.3.1",
|
|
107
|
-
vitest: "^3.0.3"
|
|
120
|
+
vitest: "^3.0.3",
|
|
121
|
+
zod: "^3.24.1"
|
|
108
122
|
};
|
|
109
123
|
const resolutions = {
|
|
110
124
|
"@silgi/modules": "workspace:*",
|
|
@@ -126,6 +140,8 @@ const packageJson = {
|
|
|
126
140
|
bin: bin,
|
|
127
141
|
files: files,
|
|
128
142
|
scripts: scripts,
|
|
143
|
+
peerDependencies: peerDependencies,
|
|
144
|
+
peerDependenciesMeta: peerDependenciesMeta,
|
|
129
145
|
dependencies: dependencies,
|
|
130
146
|
devDependencies: devDependencies,
|
|
131
147
|
resolutions: resolutions,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { resolve, dirname, join } from 'pathe';
|
|
3
|
-
import { l as loadSilgiConfig } from '../../shared/silgi.
|
|
4
|
-
import { r as relativeWithDot } from '../../shared/silgi.
|
|
3
|
+
import { l as loadSilgiConfig } from '../../shared/silgi.2D3gmgW0.mjs';
|
|
4
|
+
import { r as relativeWithDot } from '../../shared/silgi.BNEdIEZH.mjs';
|
|
5
5
|
import 'c12';
|
|
6
6
|
import 'untyped';
|
|
7
7
|
import 'std-env';
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { defineNuxtModule } from '@nuxt/kit';
|
|
2
2
|
import { resolvePath } from 'mlly';
|
|
3
|
+
import { join } from 'pathe';
|
|
4
|
+
import { l as loadSilgiConfig } from '../../shared/silgi.2D3gmgW0.mjs';
|
|
5
|
+
import { r as relativeWithDot } from '../../shared/silgi.BNEdIEZH.mjs';
|
|
6
|
+
import 'c12';
|
|
7
|
+
import 'untyped';
|
|
8
|
+
import 'std-env';
|
|
3
9
|
|
|
4
10
|
const module = defineNuxtModule({
|
|
5
11
|
meta: {
|
|
@@ -11,9 +17,13 @@ const module = defineNuxtModule({
|
|
|
11
17
|
},
|
|
12
18
|
defaults: {},
|
|
13
19
|
async setup(options, nuxt) {
|
|
20
|
+
const silgi = await loadSilgiConfig({});
|
|
14
21
|
nuxt.options.build.transpile.push("silgi");
|
|
15
22
|
nuxt.options.nitro.modules ||= [];
|
|
16
23
|
nuxt.options.nitro.modules.push(await resolvePath("silgi/ecosystem/nitro"));
|
|
24
|
+
nuxt.hook("prepare:types", ({ references }) => {
|
|
25
|
+
references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.options.buildDir, "silgi.d.ts")) });
|
|
26
|
+
});
|
|
17
27
|
}
|
|
18
28
|
});
|
|
19
29
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as
|
|
2
|
-
export {
|
|
1
|
+
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SilgiServiceInterface, g as DefaultNamespaces, h as Silgi, i as SilgiOperation, j as MergedSilgiSchema, k as ServiceType, l as SilgiSchema, R as RequiredServiceType, m as SilgiModuleShared } from './shared/silgi.DJkQv6rh.mjs';
|
|
2
|
+
export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, t as ExtractInputFromURI, u as ExtractOutputFromURI, v as ExtractRouterParamsFromURI, r as SilgiDefaultShared, n as SilgiEvent, z as SilgiHook, o as SilgiModuleMethods, a as SilgiModuleOptions, p as SilgiModules, q as SilgiNamespaces, S as SilgiOptions, y as SilgiRouterTypes, w as SilgiStorageBase, s as SilgiURIs, U as URIsTypes, x as silgi } from './shared/silgi.DJkQv6rh.mjs';
|
|
3
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
4
|
import * as unctx_index from 'unctx/index';
|
|
4
5
|
import 'consola';
|
|
5
6
|
import 'hookable';
|
|
6
7
|
import 'ignore';
|
|
7
8
|
import 'unstorage';
|
|
8
9
|
import 'defu';
|
|
9
|
-
import 'zod';
|
|
10
10
|
import 'h3';
|
|
11
11
|
import 'pkg-types';
|
|
12
12
|
import 'nitropack/types';
|
|
@@ -94,11 +94,11 @@ interface SilgiModuleContext extends Record<string, any> {
|
|
|
94
94
|
interface ExtendContext {
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<
|
|
97
|
+
interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>> {
|
|
98
98
|
}
|
|
99
99
|
type Namespaces<T extends BaseNamespaceType> = {
|
|
100
100
|
[K in keyof T]: {
|
|
101
|
-
[P in keyof T[K]]: T[K][P] extends BaseSchemaType<
|
|
101
|
+
[P in keyof T[K]]: T[K][P] extends BaseSchemaType<StandardSchemaV1> ? SilgiServiceInterface<T[K][P]> : never;
|
|
102
102
|
};
|
|
103
103
|
};
|
|
104
104
|
|
|
@@ -145,7 +145,7 @@ declare function createService<T extends SilgiSchema>(variables: ServiceType<T>)
|
|
|
145
145
|
|
|
146
146
|
declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
|
|
147
147
|
|
|
148
|
-
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<
|
|
148
|
+
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>>>>(silgiType: T): {
|
|
149
149
|
[K in keyof T]: {
|
|
150
150
|
[P in keyof T[K]]: T[K][P];
|
|
151
151
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as
|
|
2
|
-
export {
|
|
1
|
+
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SilgiServiceInterface, g as DefaultNamespaces, h as Silgi, i as SilgiOperation, j as MergedSilgiSchema, k as ServiceType, l as SilgiSchema, R as RequiredServiceType, m as SilgiModuleShared } from './shared/silgi.DJkQv6rh.js';
|
|
2
|
+
export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, t as ExtractInputFromURI, u as ExtractOutputFromURI, v as ExtractRouterParamsFromURI, r as SilgiDefaultShared, n as SilgiEvent, z as SilgiHook, o as SilgiModuleMethods, a as SilgiModuleOptions, p as SilgiModules, q as SilgiNamespaces, S as SilgiOptions, y as SilgiRouterTypes, w as SilgiStorageBase, s as SilgiURIs, U as URIsTypes, x as silgi } from './shared/silgi.DJkQv6rh.js';
|
|
3
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
4
|
import * as unctx_index from 'unctx/index';
|
|
4
5
|
import 'consola';
|
|
5
6
|
import 'hookable';
|
|
6
7
|
import 'ignore';
|
|
7
8
|
import 'unstorage';
|
|
8
9
|
import 'defu';
|
|
9
|
-
import 'zod';
|
|
10
10
|
import 'h3';
|
|
11
11
|
import 'pkg-types';
|
|
12
12
|
import 'nitropack/types';
|
|
@@ -94,11 +94,11 @@ interface SilgiModuleContext extends Record<string, any> {
|
|
|
94
94
|
interface ExtendContext {
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<
|
|
97
|
+
interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>> {
|
|
98
98
|
}
|
|
99
99
|
type Namespaces<T extends BaseNamespaceType> = {
|
|
100
100
|
[K in keyof T]: {
|
|
101
|
-
[P in keyof T[K]]: T[K][P] extends BaseSchemaType<
|
|
101
|
+
[P in keyof T[K]]: T[K][P] extends BaseSchemaType<StandardSchemaV1> ? SilgiServiceInterface<T[K][P]> : never;
|
|
102
102
|
};
|
|
103
103
|
};
|
|
104
104
|
|
|
@@ -145,7 +145,7 @@ declare function createService<T extends SilgiSchema>(variables: ServiceType<T>)
|
|
|
145
145
|
|
|
146
146
|
declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
|
|
147
147
|
|
|
148
|
-
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<
|
|
148
|
+
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>>>>(silgiType: T): {
|
|
149
149
|
[K in keyof T]: {
|
|
150
150
|
[P in keyof T[K]]: T[K][P];
|
|
151
151
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { createConsola } from 'consola';
|
|
|
2
2
|
import defu, { defu as defu$1 } from 'defu';
|
|
3
3
|
import { createHooks } from 'hookable';
|
|
4
4
|
import { applyDefaults } from 'untyped';
|
|
5
|
-
import { u as useSilgi, l as loadSilgiModuleInstance, p as parseURI, S as SilgiError, a as useStorage, n as normalizeResult, b as SilgiErrorCode, g as generateStorageKey, s as scanAction, c as createStorage, d as silgiCtx, t as tryUseSilgi } from './shared/silgi.
|
|
6
|
-
export { e as createResolver, f as useHook, h as useShared } from './shared/silgi.
|
|
5
|
+
import { u as useSilgi, l as loadSilgiModuleInstance, p as parseURI, S as SilgiError, a as useStorage, n as normalizeResult, b as SilgiErrorCode, g as generateStorageKey, s as scanAction, c as createStorage, d as silgiCtx, t as tryUseSilgi } from './shared/silgi.mBwNj1W0.mjs';
|
|
6
|
+
export { e as createResolver, f as useHook, h as useShared } from './shared/silgi.mBwNj1W0.mjs';
|
|
7
7
|
import satisfies from 'semver/functions/satisfies.js';
|
|
8
|
-
import { S as SilgiConfigSchema } from './shared/silgi.
|
|
9
|
-
export { r as relativeWithDot } from './shared/silgi.
|
|
8
|
+
import { S as SilgiConfigSchema } from './shared/silgi.BNEdIEZH.mjs';
|
|
9
|
+
export { r as relativeWithDot } from './shared/silgi.BNEdIEZH.mjs';
|
|
10
10
|
import { defineEventHandler, getQuery, readBody } from 'h3';
|
|
11
11
|
import 'node:fs';
|
|
12
12
|
import 'pathe';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadConfig } from 'c12';
|
|
2
2
|
import { applyDefaults } from 'untyped';
|
|
3
|
-
import { S as SilgiConfigSchema } from './silgi.
|
|
3
|
+
import { S as SilgiConfigSchema } from './silgi.BNEdIEZH.mjs';
|
|
4
4
|
|
|
5
5
|
async function loadSilgiConfig(opts) {
|
|
6
6
|
globalThis.defineSilgiConfig = (c) => c;
|
|
@@ -11,13 +11,6 @@ const common = defineUntypedSchema({
|
|
|
11
11
|
environment: {
|
|
12
12
|
$resolve: (val) => val ?? "h3"
|
|
13
13
|
},
|
|
14
|
-
/**
|
|
15
|
-
* Validation library to use.
|
|
16
|
-
* @default 'zod'
|
|
17
|
-
*/
|
|
18
|
-
validationLibrary: {
|
|
19
|
-
$resolve: (val) => val ?? "zod"
|
|
20
|
-
},
|
|
21
14
|
/**
|
|
22
15
|
* Define the root directory of your application.
|
|
23
16
|
*
|
|
@@ -2,8 +2,8 @@ import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
|
2
2
|
import { Hookable } from 'hookable';
|
|
3
3
|
import { Ignore } from 'ignore';
|
|
4
4
|
import { BuiltinDriverName, TransactionOptions, StorageValue, Storage } from 'unstorage';
|
|
5
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
6
|
import { Defu } from 'defu';
|
|
6
|
-
import { z } from 'zod';
|
|
7
7
|
import { Router, H3Event } from 'h3';
|
|
8
8
|
import { TSConfig } from 'pkg-types';
|
|
9
9
|
import { NitroApp } from 'nitropack/types';
|
|
@@ -23,28 +23,11 @@ interface SilgiSchema {
|
|
|
23
23
|
}
|
|
24
24
|
interface MergedSilgiSchema {
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
type ValidationLibrary = 'zod' | 'yup';
|
|
29
|
-
type SelectedValidationLibrary = SilgiValidationSchema extends {
|
|
30
|
-
validationLibrary: infer V;
|
|
31
|
-
} ? V extends ValidationLibrary ? V : 'zod' : 'zod';
|
|
32
|
-
/**
|
|
33
|
-
* A map of validation library names to their type definitions.
|
|
34
|
-
*
|
|
35
|
-
* @see {@link https://zod.dev/ | Zod}
|
|
36
|
-
* @see {@link https://github.com/jquense/yup | Yup}
|
|
37
|
-
*/
|
|
38
|
-
interface SchemaTypes {
|
|
39
|
-
zod: z.ZodTypeAny;
|
|
40
|
-
yup: any;
|
|
41
|
-
}
|
|
42
|
-
type InferSchemaType<V extends SelectedValidationLibrary, T> = V extends 'zod' ? T extends z.ZodTypeAny ? z.infer<T> : never : V extends 'yup' ? any : never;
|
|
43
|
-
type BaseSchemaType<V extends SelectedValidationLibrary> = {
|
|
26
|
+
type BaseSchemaType<T extends StandardSchemaV1> = {
|
|
44
27
|
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
45
|
-
input?:
|
|
46
|
-
output?:
|
|
47
|
-
routerParams?:
|
|
28
|
+
input?: T;
|
|
29
|
+
output?: T;
|
|
30
|
+
routerParams?: T;
|
|
48
31
|
}>;
|
|
49
32
|
};
|
|
50
33
|
|
|
@@ -64,16 +47,31 @@ type GetInput<T extends {
|
|
|
64
47
|
entity: string;
|
|
65
48
|
method: string;
|
|
66
49
|
action: string;
|
|
67
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']]
|
|
50
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
51
|
+
input: infer I;
|
|
52
|
+
} ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : never : never : never : never : never : never;
|
|
68
53
|
type GetOutput<T extends {
|
|
69
54
|
service: string;
|
|
70
55
|
entity: string;
|
|
71
56
|
method: string;
|
|
72
57
|
action: string;
|
|
73
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']]
|
|
58
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
59
|
+
output: infer O;
|
|
60
|
+
} ? O extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<O> : never : never : never : never : never : never;
|
|
61
|
+
type GetRouterParams<T extends {
|
|
62
|
+
service: string;
|
|
63
|
+
entity: string;
|
|
64
|
+
method: string;
|
|
65
|
+
action: string;
|
|
66
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
67
|
+
router: infer I;
|
|
68
|
+
} ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : never : never : never : never : never : never;
|
|
74
69
|
type ExtractInputFromURI<TURI extends keyof SilgiURIs> = GetInput<ExtractPath<TURI>>;
|
|
75
70
|
type ExtractOutputFromURI<TURI extends keyof SilgiURIs> = GetOutput<ExtractPath<TURI>>;
|
|
71
|
+
type ExtractRouterParamsFromURI<TURI extends keyof SilgiURIs> = GetRouterParams<ExtractPath<TURI>>;
|
|
76
72
|
|
|
73
|
+
interface SilgiRouterTypes {
|
|
74
|
+
}
|
|
77
75
|
interface SilgiHook {
|
|
78
76
|
}
|
|
79
77
|
interface DefaultHooks {
|
|
@@ -222,7 +220,6 @@ interface SilgiOptions {
|
|
|
222
220
|
* @default 'nitrojs'
|
|
223
221
|
*/
|
|
224
222
|
environment?: ('nitrojs' | 'h3' | 'undefined');
|
|
225
|
-
validationLibrary?: ValidationLibrary;
|
|
226
223
|
isPackage: boolean;
|
|
227
224
|
/**
|
|
228
225
|
*
|
|
@@ -703,22 +700,22 @@ type MethodHandlerType<T> = {
|
|
|
703
700
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
704
701
|
[Method in keyof T[Action]]: {
|
|
705
702
|
default?: {
|
|
706
|
-
input?: T[Action][Method]['input']
|
|
707
|
-
output?: T[Action][Method]['output']
|
|
703
|
+
input?: StandardSchemaV1.InferInput<T[Action][Method]['input']>;
|
|
704
|
+
output?: StandardSchemaV1.InferInput<T[Action][Method]['output']>;
|
|
708
705
|
};
|
|
709
|
-
handler: (router: T[Action][Method]['router']
|
|
706
|
+
handler: (router: StandardSchemaV1.InferInput<T[Action][Method]['router']>, input: StandardSchemaV1.InferInput<T[Action][Method]['input']>, shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
710
707
|
modules?: ModuleConfigurations;
|
|
711
708
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
712
709
|
};
|
|
713
710
|
} : never;
|
|
714
711
|
};
|
|
715
712
|
interface ResolvedMethodHandlerType {
|
|
716
|
-
input?: Partial<
|
|
717
|
-
output: Partial<
|
|
718
|
-
handler: (router:
|
|
713
|
+
input?: Partial<BaseSchemaType<any>>;
|
|
714
|
+
output: Partial<BaseSchemaType<any>>;
|
|
715
|
+
handler: (router: StandardSchemaV1.InferInput<any>, input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
719
716
|
modules?: ModuleConfigurations;
|
|
720
|
-
storage?: StorageConfig<
|
|
721
|
-
execute: (input:
|
|
717
|
+
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
718
|
+
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
722
719
|
}
|
|
723
720
|
type MethodResponse<T> = {
|
|
724
721
|
success: true;
|
|
@@ -734,85 +731,15 @@ type MethodResponse<T> = {
|
|
|
734
731
|
};
|
|
735
732
|
|
|
736
733
|
declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
737
|
-
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>) => Promise<MethodResponse<
|
|
738
|
-
service: Service;
|
|
739
|
-
entity: Entity;
|
|
740
|
-
method: Method;
|
|
741
|
-
action: Action;
|
|
742
|
-
} : never : never)["service"] extends never ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
743
|
-
service: Service;
|
|
744
|
-
entity: Entity;
|
|
745
|
-
method: Method;
|
|
746
|
-
action: Action;
|
|
747
|
-
} : never : never)["entity"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
748
|
-
service: Service;
|
|
749
|
-
entity: Entity;
|
|
750
|
-
method: Method;
|
|
751
|
-
action: Action;
|
|
752
|
-
} : never : never)["service"]] ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
753
|
-
service: Service;
|
|
754
|
-
entity: Entity;
|
|
755
|
-
method: Method;
|
|
756
|
-
action: Action;
|
|
757
|
-
} : never : never)["method"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
758
|
-
service: Service;
|
|
759
|
-
entity: Entity;
|
|
760
|
-
method: Method;
|
|
761
|
-
action: Action;
|
|
762
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
763
|
-
service: Service;
|
|
764
|
-
entity: Entity;
|
|
765
|
-
method: Method;
|
|
766
|
-
action: Action;
|
|
767
|
-
} : never : never)["entity"]] ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
768
|
-
service: Service;
|
|
769
|
-
entity: Entity;
|
|
770
|
-
method: Method;
|
|
771
|
-
action: Action;
|
|
772
|
-
} : never : never)["action"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
773
|
-
service: Service;
|
|
774
|
-
entity: Entity;
|
|
775
|
-
method: Method;
|
|
776
|
-
action: Action;
|
|
777
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
778
|
-
service: Service;
|
|
779
|
-
entity: Entity;
|
|
780
|
-
method: Method;
|
|
781
|
-
action: Action;
|
|
782
|
-
} : never : never)["entity"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
783
|
-
service: Service;
|
|
784
|
-
entity: Entity;
|
|
785
|
-
method: Method;
|
|
786
|
-
action: Action;
|
|
787
|
-
} : never : never)["method"]] ? SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
788
|
-
service: Service;
|
|
789
|
-
entity: Entity;
|
|
790
|
-
method: Method;
|
|
791
|
-
action: Action;
|
|
792
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
793
|
-
service: Service;
|
|
794
|
-
entity: Entity;
|
|
795
|
-
method: Method;
|
|
796
|
-
action: Action;
|
|
797
|
-
} : never : never)["entity"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
798
|
-
service: Service;
|
|
799
|
-
entity: Entity;
|
|
800
|
-
method: Method;
|
|
801
|
-
action: Action;
|
|
802
|
-
} : never : never)["method"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
803
|
-
service: Service;
|
|
804
|
-
entity: Entity;
|
|
805
|
-
method: Method;
|
|
806
|
-
action: Action;
|
|
807
|
-
} : never : never)["action"]]["output"] : never : never : never : never>>;
|
|
734
|
+
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>) => Promise<MethodResponse<ExtractOutputFromURI<TURI>>>;
|
|
808
735
|
};
|
|
809
736
|
|
|
810
|
-
type SilgiServiceInterface<T extends BaseSchemaType<
|
|
737
|
+
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
811
738
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
812
739
|
[Method in keyof T[Action]]: {
|
|
813
|
-
input:
|
|
814
|
-
output
|
|
815
|
-
router
|
|
740
|
+
input: T[Action][Method]['input'];
|
|
741
|
+
output: T[Action][Method]['output'];
|
|
742
|
+
router: T[Action][Method]['router'];
|
|
816
743
|
};
|
|
817
744
|
} : never;
|
|
818
745
|
};
|
|
@@ -878,4 +805,4 @@ interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'sche
|
|
|
878
805
|
}
|
|
879
806
|
type SilgiFunction = typeof silgi;
|
|
880
807
|
|
|
881
|
-
export { type
|
|
808
|
+
export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SilgiServiceInterface as f, type DefaultNamespaces as g, type Silgi as h, type SilgiOperation as i, type MergedSilgiSchema as j, type ServiceType as k, type SilgiSchema as l, type SilgiModuleShared as m, type SilgiEvent as n, type SilgiModuleMethods as o, type SilgiModules as p, type SilgiNamespaces as q, type SilgiDefaultShared as r, type SilgiURIs as s, type ExtractInputFromURI as t, type ExtractOutputFromURI as u, type ExtractRouterParamsFromURI as v, type SilgiStorageBase as w, silgi as x, type SilgiRouterTypes as y, type SilgiHook as z };
|
|
@@ -2,8 +2,8 @@ import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
|
2
2
|
import { Hookable } from 'hookable';
|
|
3
3
|
import { Ignore } from 'ignore';
|
|
4
4
|
import { BuiltinDriverName, TransactionOptions, StorageValue, Storage } from 'unstorage';
|
|
5
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
6
|
import { Defu } from 'defu';
|
|
6
|
-
import { z } from 'zod';
|
|
7
7
|
import { Router, H3Event } from 'h3';
|
|
8
8
|
import { TSConfig } from 'pkg-types';
|
|
9
9
|
import { NitroApp } from 'nitropack/types';
|
|
@@ -23,28 +23,11 @@ interface SilgiSchema {
|
|
|
23
23
|
}
|
|
24
24
|
interface MergedSilgiSchema {
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
type ValidationLibrary = 'zod' | 'yup';
|
|
29
|
-
type SelectedValidationLibrary = SilgiValidationSchema extends {
|
|
30
|
-
validationLibrary: infer V;
|
|
31
|
-
} ? V extends ValidationLibrary ? V : 'zod' : 'zod';
|
|
32
|
-
/**
|
|
33
|
-
* A map of validation library names to their type definitions.
|
|
34
|
-
*
|
|
35
|
-
* @see {@link https://zod.dev/ | Zod}
|
|
36
|
-
* @see {@link https://github.com/jquense/yup | Yup}
|
|
37
|
-
*/
|
|
38
|
-
interface SchemaTypes {
|
|
39
|
-
zod: z.ZodTypeAny;
|
|
40
|
-
yup: any;
|
|
41
|
-
}
|
|
42
|
-
type InferSchemaType<V extends SelectedValidationLibrary, T> = V extends 'zod' ? T extends z.ZodTypeAny ? z.infer<T> : never : V extends 'yup' ? any : never;
|
|
43
|
-
type BaseSchemaType<V extends SelectedValidationLibrary> = {
|
|
26
|
+
type BaseSchemaType<T extends StandardSchemaV1> = {
|
|
44
27
|
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
45
|
-
input?:
|
|
46
|
-
output?:
|
|
47
|
-
routerParams?:
|
|
28
|
+
input?: T;
|
|
29
|
+
output?: T;
|
|
30
|
+
routerParams?: T;
|
|
48
31
|
}>;
|
|
49
32
|
};
|
|
50
33
|
|
|
@@ -64,16 +47,31 @@ type GetInput<T extends {
|
|
|
64
47
|
entity: string;
|
|
65
48
|
method: string;
|
|
66
49
|
action: string;
|
|
67
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']]
|
|
50
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
51
|
+
input: infer I;
|
|
52
|
+
} ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : never : never : never : never : never : never;
|
|
68
53
|
type GetOutput<T extends {
|
|
69
54
|
service: string;
|
|
70
55
|
entity: string;
|
|
71
56
|
method: string;
|
|
72
57
|
action: string;
|
|
73
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']]
|
|
58
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
59
|
+
output: infer O;
|
|
60
|
+
} ? O extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<O> : never : never : never : never : never : never;
|
|
61
|
+
type GetRouterParams<T extends {
|
|
62
|
+
service: string;
|
|
63
|
+
entity: string;
|
|
64
|
+
method: string;
|
|
65
|
+
action: string;
|
|
66
|
+
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
67
|
+
router: infer I;
|
|
68
|
+
} ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : never : never : never : never : never : never;
|
|
74
69
|
type ExtractInputFromURI<TURI extends keyof SilgiURIs> = GetInput<ExtractPath<TURI>>;
|
|
75
70
|
type ExtractOutputFromURI<TURI extends keyof SilgiURIs> = GetOutput<ExtractPath<TURI>>;
|
|
71
|
+
type ExtractRouterParamsFromURI<TURI extends keyof SilgiURIs> = GetRouterParams<ExtractPath<TURI>>;
|
|
76
72
|
|
|
73
|
+
interface SilgiRouterTypes {
|
|
74
|
+
}
|
|
77
75
|
interface SilgiHook {
|
|
78
76
|
}
|
|
79
77
|
interface DefaultHooks {
|
|
@@ -222,7 +220,6 @@ interface SilgiOptions {
|
|
|
222
220
|
* @default 'nitrojs'
|
|
223
221
|
*/
|
|
224
222
|
environment?: ('nitrojs' | 'h3' | 'undefined');
|
|
225
|
-
validationLibrary?: ValidationLibrary;
|
|
226
223
|
isPackage: boolean;
|
|
227
224
|
/**
|
|
228
225
|
*
|
|
@@ -703,22 +700,22 @@ type MethodHandlerType<T> = {
|
|
|
703
700
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
704
701
|
[Method in keyof T[Action]]: {
|
|
705
702
|
default?: {
|
|
706
|
-
input?: T[Action][Method]['input']
|
|
707
|
-
output?: T[Action][Method]['output']
|
|
703
|
+
input?: StandardSchemaV1.InferInput<T[Action][Method]['input']>;
|
|
704
|
+
output?: StandardSchemaV1.InferInput<T[Action][Method]['output']>;
|
|
708
705
|
};
|
|
709
|
-
handler: (router: T[Action][Method]['router']
|
|
706
|
+
handler: (router: StandardSchemaV1.InferInput<T[Action][Method]['router']>, input: StandardSchemaV1.InferInput<T[Action][Method]['input']>, shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
710
707
|
modules?: ModuleConfigurations;
|
|
711
708
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
712
709
|
};
|
|
713
710
|
} : never;
|
|
714
711
|
};
|
|
715
712
|
interface ResolvedMethodHandlerType {
|
|
716
|
-
input?: Partial<
|
|
717
|
-
output: Partial<
|
|
718
|
-
handler: (router:
|
|
713
|
+
input?: Partial<BaseSchemaType<any>>;
|
|
714
|
+
output: Partial<BaseSchemaType<any>>;
|
|
715
|
+
handler: (router: StandardSchemaV1.InferInput<any>, input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
719
716
|
modules?: ModuleConfigurations;
|
|
720
|
-
storage?: StorageConfig<
|
|
721
|
-
execute: (input:
|
|
717
|
+
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
718
|
+
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
722
719
|
}
|
|
723
720
|
type MethodResponse<T> = {
|
|
724
721
|
success: true;
|
|
@@ -734,85 +731,15 @@ type MethodResponse<T> = {
|
|
|
734
731
|
};
|
|
735
732
|
|
|
736
733
|
declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
737
|
-
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>) => Promise<MethodResponse<
|
|
738
|
-
service: Service;
|
|
739
|
-
entity: Entity;
|
|
740
|
-
method: Method;
|
|
741
|
-
action: Action;
|
|
742
|
-
} : never : never)["service"] extends never ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
743
|
-
service: Service;
|
|
744
|
-
entity: Entity;
|
|
745
|
-
method: Method;
|
|
746
|
-
action: Action;
|
|
747
|
-
} : never : never)["entity"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
748
|
-
service: Service;
|
|
749
|
-
entity: Entity;
|
|
750
|
-
method: Method;
|
|
751
|
-
action: Action;
|
|
752
|
-
} : never : never)["service"]] ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
753
|
-
service: Service;
|
|
754
|
-
entity: Entity;
|
|
755
|
-
method: Method;
|
|
756
|
-
action: Action;
|
|
757
|
-
} : never : never)["method"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
758
|
-
service: Service;
|
|
759
|
-
entity: Entity;
|
|
760
|
-
method: Method;
|
|
761
|
-
action: Action;
|
|
762
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
763
|
-
service: Service;
|
|
764
|
-
entity: Entity;
|
|
765
|
-
method: Method;
|
|
766
|
-
action: Action;
|
|
767
|
-
} : never : never)["entity"]] ? (TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
768
|
-
service: Service;
|
|
769
|
-
entity: Entity;
|
|
770
|
-
method: Method;
|
|
771
|
-
action: Action;
|
|
772
|
-
} : never : never)["action"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
773
|
-
service: Service;
|
|
774
|
-
entity: Entity;
|
|
775
|
-
method: Method;
|
|
776
|
-
action: Action;
|
|
777
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
778
|
-
service: Service;
|
|
779
|
-
entity: Entity;
|
|
780
|
-
method: Method;
|
|
781
|
-
action: Action;
|
|
782
|
-
} : never : never)["entity"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
783
|
-
service: Service;
|
|
784
|
-
entity: Entity;
|
|
785
|
-
method: Method;
|
|
786
|
-
action: Action;
|
|
787
|
-
} : never : never)["method"]] ? SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
788
|
-
service: Service;
|
|
789
|
-
entity: Entity;
|
|
790
|
-
method: Method;
|
|
791
|
-
action: Action;
|
|
792
|
-
} : never : never)["service"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
793
|
-
service: Service;
|
|
794
|
-
entity: Entity;
|
|
795
|
-
method: Method;
|
|
796
|
-
action: Action;
|
|
797
|
-
} : never : never)["entity"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
798
|
-
service: Service;
|
|
799
|
-
entity: Entity;
|
|
800
|
-
method: Method;
|
|
801
|
-
action: Action;
|
|
802
|
-
} : never : never)["method"]][(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
803
|
-
service: Service;
|
|
804
|
-
entity: Entity;
|
|
805
|
-
method: Method;
|
|
806
|
-
action: Action;
|
|
807
|
-
} : never : never)["action"]]["output"] : never : never : never : never>>;
|
|
734
|
+
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>) => Promise<MethodResponse<ExtractOutputFromURI<TURI>>>;
|
|
808
735
|
};
|
|
809
736
|
|
|
810
|
-
type SilgiServiceInterface<T extends BaseSchemaType<
|
|
737
|
+
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
811
738
|
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
812
739
|
[Method in keyof T[Action]]: {
|
|
813
|
-
input:
|
|
814
|
-
output
|
|
815
|
-
router
|
|
740
|
+
input: T[Action][Method]['input'];
|
|
741
|
+
output: T[Action][Method]['output'];
|
|
742
|
+
router: T[Action][Method]['router'];
|
|
816
743
|
};
|
|
817
744
|
} : never;
|
|
818
745
|
};
|
|
@@ -878,4 +805,4 @@ interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'sche
|
|
|
878
805
|
}
|
|
879
806
|
type SilgiFunction = typeof silgi;
|
|
880
807
|
|
|
881
|
-
export { type
|
|
808
|
+
export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SilgiServiceInterface as f, type DefaultNamespaces as g, type Silgi as h, type SilgiOperation as i, type MergedSilgiSchema as j, type ServiceType as k, type SilgiSchema as l, type SilgiModuleShared as m, type SilgiEvent as n, type SilgiModuleMethods as o, type SilgiModules as p, type SilgiNamespaces as q, type SilgiDefaultShared as r, type SilgiURIs as s, type ExtractInputFromURI as t, type ExtractOutputFromURI as u, type ExtractRouterParamsFromURI as v, type SilgiStorageBase as w, silgi as x, type SilgiRouterTypes as y, type SilgiHook as z };
|
|
@@ -139,65 +139,7 @@ ${this.stack}`;
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
const plugins = {
|
|
143
|
-
zod: {
|
|
144
|
-
name: "zod",
|
|
145
|
-
isSchemaType: (obj) => obj?._def?.typeName !== undefined,
|
|
146
|
-
getRouterParams: (routerObj) => {
|
|
147
|
-
try {
|
|
148
|
-
const shape = routerObj?.shape?.params?.shape;
|
|
149
|
-
return shape ? Object.keys(shape) : null;
|
|
150
|
-
} catch {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
internalKeys: ["_def", "shape"]
|
|
155
|
-
// Zod-specific internal keys
|
|
156
|
-
},
|
|
157
|
-
yup: {
|
|
158
|
-
name: "yup",
|
|
159
|
-
isSchemaType: (obj) => obj?._type !== undefined,
|
|
160
|
-
getRouterParams: (routerObj) => {
|
|
161
|
-
return routerObj?.fields ? Object.keys(routerObj.fields) : null;
|
|
162
|
-
},
|
|
163
|
-
internalKeys: ["_type", "fields"]
|
|
164
|
-
// Yup-specific internal keys
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
class SchemaValidatorRegistry {
|
|
168
|
-
currentValidator = null;
|
|
169
|
-
validators = [];
|
|
170
|
-
constructor(validationLibrary = "zod") {
|
|
171
|
-
this.setValidationLibrary(validationLibrary);
|
|
172
|
-
}
|
|
173
|
-
isInternalKey(key) {
|
|
174
|
-
if (!this.currentValidator) return false;
|
|
175
|
-
return this.currentValidator.internalKeys.includes(key);
|
|
176
|
-
}
|
|
177
|
-
setValidationLibrary(library) {
|
|
178
|
-
this.validators = [];
|
|
179
|
-
const plugin = plugins[library];
|
|
180
|
-
if (plugin) {
|
|
181
|
-
this.currentValidator = plugin;
|
|
182
|
-
this.register(plugin);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
register(plugin) {
|
|
186
|
-
this.validators.push(plugin);
|
|
187
|
-
}
|
|
188
|
-
getParams(routerObj) {
|
|
189
|
-
for (const validator of this.validators) {
|
|
190
|
-
if (validator.isSchemaType(routerObj)) {
|
|
191
|
-
return validator.getRouterParams(routerObj);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const schemaRegistry = new SchemaValidatorRegistry();
|
|
198
|
-
|
|
199
142
|
function traverseObject(silgi, obj, currentPath = []) {
|
|
200
|
-
schemaRegistry.setValidationLibrary(silgi.options.validationLibrary || "zod");
|
|
201
143
|
const uriMap = /* @__PURE__ */ new Map();
|
|
202
144
|
function traverse(node, path = []) {
|
|
203
145
|
if (!node || typeof node !== "object")
|
|
@@ -206,7 +148,15 @@ function traverseObject(silgi, obj, currentPath = []) {
|
|
|
206
148
|
const basePath = path.join("/");
|
|
207
149
|
let paramString = "";
|
|
208
150
|
if (node.router) {
|
|
209
|
-
|
|
151
|
+
let params = null;
|
|
152
|
+
if (node.router?._def?.typeName !== undefined) {
|
|
153
|
+
try {
|
|
154
|
+
const shape = node.router?.shape?.params?.shape;
|
|
155
|
+
params = shape ? Object.keys(shape) : null;
|
|
156
|
+
} catch {
|
|
157
|
+
params = null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
210
160
|
if (params?.length) {
|
|
211
161
|
paramString = params.map((p) => `:${p}`).join("/");
|
|
212
162
|
}
|
|
@@ -215,7 +165,7 @@ function traverseObject(silgi, obj, currentPath = []) {
|
|
|
215
165
|
return;
|
|
216
166
|
}
|
|
217
167
|
for (const key in node) {
|
|
218
|
-
if (!
|
|
168
|
+
if (!["_type", "fields"].includes(key)) {
|
|
219
169
|
traverse(node[key], [...path, key]);
|
|
220
170
|
}
|
|
221
171
|
}
|
|
@@ -330,14 +280,16 @@ async function generateUris(silgi) {
|
|
|
330
280
|
silgi.hook("read:core.ts", async (data) => {
|
|
331
281
|
const { context, object, path } = await data();
|
|
332
282
|
const uriMap = traverseObject(silgi, object.schemas, []);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
283
|
+
if (uriMap.size > 0) {
|
|
284
|
+
const uriContent = Array.from(uriMap.entries()).map(([uri, params]) => ` '${uri}': '${params}',`).join("\n");
|
|
285
|
+
const newContext = context.replace(
|
|
286
|
+
/export const uris = \{[^}]*\}/,
|
|
287
|
+
`export const uris = {
|
|
337
288
|
${uriContent}
|
|
338
289
|
}`
|
|
339
|
-
|
|
340
|
-
|
|
290
|
+
);
|
|
291
|
+
await promises.writeFile(path, newContext);
|
|
292
|
+
}
|
|
341
293
|
});
|
|
342
294
|
}
|
|
343
295
|
async function findAction(silgi, uri) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -50,10 +50,24 @@
|
|
|
50
50
|
"dist",
|
|
51
51
|
"package.json"
|
|
52
52
|
],
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@nuxt/kit": "^3.15.3",
|
|
55
|
+
"typescript": "^5.7.3",
|
|
56
|
+
"zod": "^3.24.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@nuxt/kit": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"zod": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
53
66
|
"dependencies": {
|
|
54
67
|
"@antfu/eslint-config": "^3.16.0",
|
|
55
68
|
"@nuxt/schema": "^3.15.2",
|
|
56
69
|
"@oxc-parser/wasm": "^0.48.0",
|
|
70
|
+
"@standard-schema/spec": "^1.0.0",
|
|
57
71
|
"c12": "^2.0.1",
|
|
58
72
|
"citty": "^0.1.6",
|
|
59
73
|
"consola": "^3.4.0",
|
|
@@ -79,15 +93,15 @@
|
|
|
79
93
|
"unctx": "^2.4.1",
|
|
80
94
|
"unimport": "^4.0.0",
|
|
81
95
|
"unstorage": "^1.14.4",
|
|
82
|
-
"untyped": "^1.5.2"
|
|
83
|
-
"zod": "^3.24.1"
|
|
96
|
+
"untyped": "^1.5.2"
|
|
84
97
|
},
|
|
85
98
|
"devDependencies": {
|
|
86
99
|
"@nuxt/kit": "^3.15.3",
|
|
87
100
|
"@types/node": "^22.10.7",
|
|
88
101
|
"@types/semver": "^7.5.8",
|
|
89
102
|
"unbuild": "^3.3.1",
|
|
90
|
-
"vitest": "^3.0.3"
|
|
103
|
+
"vitest": "^3.0.3",
|
|
104
|
+
"zod": "^3.24.1"
|
|
91
105
|
},
|
|
92
106
|
"resolutions": {
|
|
93
107
|
"@silgi/modules": "workspace:*",
|