silgi 0.1.12 → 0.2.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/chunks/generate.mjs +18 -17
- package/dist/cli/config.d.mts +3 -2
- package/dist/cli/config.d.ts +3 -2
- package/dist/cli/index.mjs +1 -1
- package/dist/index.d.mts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.mjs +14 -10
- package/dist/shared/{silgi.DTGmgpWE.mjs → silgi.BLxo8kmF.mjs} +117 -45
- package/dist/shared/{silgi.BaeZYxPa.d.mts → silgi.wMv9BQmS.d.mts} +59 -49
- package/dist/shared/{silgi.BaeZYxPa.d.ts → silgi.wMv9BQmS.d.ts} +59 -49
- package/package.json +1 -1
package/dist/chunks/generate.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { r as relativeWithDot } from '../shared/silgi.C0NIj2vN.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 {
|
|
12
|
+
import { i as getDirectory, r as resolveSilgiModule, j as resolvePath$1, k as generateUris, m as generateSilgiStorageBaseType } from '../shared/silgi.BLxo8kmF.mjs';
|
|
13
13
|
import { readdir } from 'node:fs/promises';
|
|
14
14
|
import { consola } from 'consola';
|
|
15
15
|
import { globby } from 'globby';
|
|
@@ -157,7 +157,7 @@ async function _generateSchemaFile(silgi) {
|
|
|
157
157
|
...(silgi.options.namespaces || []).map((key) => ` ${key}: string,`),
|
|
158
158
|
"}",
|
|
159
159
|
"",
|
|
160
|
-
`type
|
|
160
|
+
`type SchemaExtends = Namespaces<typeof import('${silgiExport}')['schemas']>`,
|
|
161
161
|
"",
|
|
162
162
|
`type SilgiURIsMerge = URIsTypes<typeof import('${silgiExport}')['uris']>`,
|
|
163
163
|
"",
|
|
@@ -187,7 +187,7 @@ async function _generateSchemaFile(silgi) {
|
|
|
187
187
|
"}",
|
|
188
188
|
"",
|
|
189
189
|
"declare module 'silgi' {",
|
|
190
|
-
" interface
|
|
190
|
+
" interface SilgiSchema extends SchemaExtends {}",
|
|
191
191
|
"",
|
|
192
192
|
" interface SilgiValidationSchema {",
|
|
193
193
|
` validationLibrary: '${silgi.options.validationLibrary}'`,
|
|
@@ -261,7 +261,7 @@ async function _generateSilgiFile(silgi) {
|
|
|
261
261
|
const uris = [];
|
|
262
262
|
const services = [];
|
|
263
263
|
const shareds = [];
|
|
264
|
-
const
|
|
264
|
+
const schemas = [];
|
|
265
265
|
const modules = [];
|
|
266
266
|
await silgi.callHook("prepare:core.ts", {
|
|
267
267
|
importedItems,
|
|
@@ -269,7 +269,7 @@ async function _generateSilgiFile(silgi) {
|
|
|
269
269
|
uris,
|
|
270
270
|
services,
|
|
271
271
|
shareds,
|
|
272
|
-
|
|
272
|
+
schemas,
|
|
273
273
|
modules
|
|
274
274
|
});
|
|
275
275
|
if (services.length > 0) {
|
|
@@ -278,8 +278,8 @@ async function _generateSilgiFile(silgi) {
|
|
|
278
278
|
if (shareds.length > 0) {
|
|
279
279
|
importedItems.silgi.import.push({ name: "mergeShared" });
|
|
280
280
|
}
|
|
281
|
-
if (
|
|
282
|
-
importedItems.silgi.import.push({ name: "
|
|
281
|
+
if (schemas.length > 0) {
|
|
282
|
+
importedItems.silgi.import.push({ name: "mergeSchemas" });
|
|
283
283
|
}
|
|
284
284
|
const importData = [
|
|
285
285
|
...Object.entries(importedItems).map(([_name, { from, import: imports2 }]) => {
|
|
@@ -289,11 +289,11 @@ async function _generateSilgiFile(silgi) {
|
|
|
289
289
|
"",
|
|
290
290
|
"export const uris = {}",
|
|
291
291
|
"",
|
|
292
|
-
|
|
293
|
-
...
|
|
292
|
+
schemas.length > 0 ? "export const schemas = mergeSchemas([" : "export const schemas = {",
|
|
293
|
+
...schemas.map((name) => {
|
|
294
294
|
return ` ${name},`;
|
|
295
295
|
}),
|
|
296
|
-
|
|
296
|
+
schemas.length > 0 ? "])" : "}",
|
|
297
297
|
"",
|
|
298
298
|
services.length > 0 ? "export const services = mergeServices([" : "export const services = {",
|
|
299
299
|
...services.map((name) => {
|
|
@@ -313,7 +313,7 @@ async function _generateSilgiFile(silgi) {
|
|
|
313
313
|
" const silgi = await createSilgi({",
|
|
314
314
|
" shared: shareds as any,",
|
|
315
315
|
" services: services as any,",
|
|
316
|
-
"
|
|
316
|
+
" schemas: schemas as any,",
|
|
317
317
|
" uris,",
|
|
318
318
|
" _initializedModules: {",
|
|
319
319
|
...modules.map((name) => {
|
|
@@ -335,6 +335,7 @@ async function _generateSilgiFile(silgi) {
|
|
|
335
335
|
" uris,",
|
|
336
336
|
" services,",
|
|
337
337
|
" shareds,",
|
|
338
|
+
" schemas,",
|
|
338
339
|
" }",
|
|
339
340
|
" return returnObject",
|
|
340
341
|
"}",
|
|
@@ -790,12 +791,12 @@ async function scanFiles(silgi) {
|
|
|
790
791
|
});
|
|
791
792
|
}
|
|
792
793
|
}
|
|
793
|
-
const
|
|
794
|
-
if (
|
|
795
|
-
for (const
|
|
796
|
-
const { exportName, path } =
|
|
794
|
+
const createSchemas = exportVariables("createSchema", filePath);
|
|
795
|
+
if (createSchemas.length > 0) {
|
|
796
|
+
for (const createSchema of createSchemas) {
|
|
797
|
+
const { exportName, path } = createSchema;
|
|
797
798
|
silgi.hook("prepare:core.ts", (options) => {
|
|
798
|
-
options.
|
|
799
|
+
options.schemas.push(exportName);
|
|
799
800
|
});
|
|
800
801
|
silgi.hook("prepare:core.ts", (options) => {
|
|
801
802
|
options.importedItems[path] ??= {
|
|
@@ -1156,7 +1157,7 @@ async function generate$1(mergeConfig) {
|
|
|
1156
1157
|
uris: {},
|
|
1157
1158
|
_initializedModules: {},
|
|
1158
1159
|
scannedHandlers: /* @__PURE__ */ new Map(),
|
|
1159
|
-
|
|
1160
|
+
schemas: {},
|
|
1160
1161
|
storage: undefined,
|
|
1161
1162
|
hooks,
|
|
1162
1163
|
callHook: hooks.callHook,
|
package/dist/cli/config.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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, V as ValidationLibrary } from '../shared/silgi.
|
|
4
|
+
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions, V as ValidationLibrary } from '../shared/silgi.wMv9BQmS.mjs';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
7
|
import 'defu';
|
|
8
|
+
import 'zod';
|
|
8
9
|
import 'h3';
|
|
9
10
|
import 'pkg-types';
|
|
10
|
-
import 'zod';
|
|
11
11
|
import 'nitropack/types';
|
|
12
12
|
|
|
13
13
|
declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<SilgiModuleOptions>): {
|
|
@@ -1379,6 +1379,7 @@ declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<S
|
|
|
1379
1379
|
shared?: true | undefined;
|
|
1380
1380
|
context?: true | undefined;
|
|
1381
1381
|
method?: true | undefined;
|
|
1382
|
+
schema?: true | undefined;
|
|
1382
1383
|
event?: true | undefined;
|
|
1383
1384
|
} | undefined;
|
|
1384
1385
|
variable?: {
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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, V as ValidationLibrary } from '../shared/silgi.
|
|
4
|
+
import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions, V as ValidationLibrary } from '../shared/silgi.wMv9BQmS.js';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
7
|
import 'defu';
|
|
8
|
+
import 'zod';
|
|
8
9
|
import 'h3';
|
|
9
10
|
import 'pkg-types';
|
|
10
|
-
import 'zod';
|
|
11
11
|
import 'nitropack/types';
|
|
12
12
|
|
|
13
13
|
declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<SilgiModuleOptions>): {
|
|
@@ -1379,6 +1379,7 @@ declare function defineSilgiConfig(config: DeepPartial<SilgiOptions> & Partial<S
|
|
|
1379
1379
|
shared?: true | undefined;
|
|
1380
1380
|
context?: true | undefined;
|
|
1381
1381
|
method?: true | undefined;
|
|
1382
|
+
schema?: true | undefined;
|
|
1382
1383
|
event?: true | undefined;
|
|
1383
1384
|
} | undefined;
|
|
1384
1385
|
variable?: {
|
package/dist/cli/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SelectedValidationLibrary, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as
|
|
2
|
-
export { A as Awaitable, C as CreateScope, D as DeepPartial, z as DefaultHooks, y as DefaultMethods, E as ExtendShared, t as SilgiDefaultShared, o as SilgiEvent, x as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, S as SilgiOptions, v as SilgiStorageBase, u as SilgiURIs, s as SilgiValidationSchema, U as URIsTypes, w as silgi } from './shared/silgi.
|
|
1
|
+
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SelectedValidationLibrary, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as MergedSilgiSchema, l as ServiceType, m as SilgiSchema, R as RequiredServiceType, n as SilgiModuleShared } from './shared/silgi.wMv9BQmS.mjs';
|
|
2
|
+
export { A as Awaitable, C as CreateScope, D as DeepPartial, z as DefaultHooks, y as DefaultMethods, E as ExtendShared, t as SilgiDefaultShared, o as SilgiEvent, x as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, S as SilgiOptions, v as SilgiStorageBase, u as SilgiURIs, s as SilgiValidationSchema, U as URIsTypes, w as silgi } from './shared/silgi.wMv9BQmS.mjs';
|
|
3
3
|
import * as unctx_index from 'unctx/index';
|
|
4
4
|
import 'consola';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
7
|
import 'unstorage';
|
|
8
8
|
import 'defu';
|
|
9
|
+
import 'zod';
|
|
9
10
|
import 'h3';
|
|
10
11
|
import 'pkg-types';
|
|
11
|
-
import 'zod';
|
|
12
12
|
import 'nitropack/types';
|
|
13
13
|
|
|
14
14
|
declare function createSilgi(config: SilgiConfig): Promise<SilgiHelper>;
|
|
@@ -121,7 +121,6 @@ declare function normalizeResult<T>(result: T): T;
|
|
|
121
121
|
*/
|
|
122
122
|
declare function tryUseSilgi(): Silgi | null;
|
|
123
123
|
|
|
124
|
-
declare function generateURI(paths: string[], depth?: number): string;
|
|
125
124
|
/**
|
|
126
125
|
*
|
|
127
126
|
*
|
|
@@ -135,21 +134,21 @@ declare function generateURI(paths: string[], depth?: number): string;
|
|
|
135
134
|
* method: 'createBasket'
|
|
136
135
|
*
|
|
137
136
|
*/
|
|
138
|
-
declare function parseURI(uri: string): SilgiOperation;
|
|
137
|
+
declare function parseURI(uri: string, uris?: object): SilgiOperation;
|
|
139
138
|
|
|
140
139
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
141
|
-
declare function
|
|
142
|
-
declare function mergeServices<T extends ServiceType<
|
|
140
|
+
declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
|
|
141
|
+
declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
|
|
143
142
|
declare function mergeShared<T extends SilgiModuleShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
|
|
144
143
|
|
|
145
|
-
declare function createService<T extends
|
|
144
|
+
declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
|
|
146
145
|
|
|
147
146
|
declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
|
|
148
147
|
|
|
149
|
-
declare function
|
|
148
|
+
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<SelectedValidationLibrary>>>>>(silgiType: T): {
|
|
150
149
|
[K in keyof T]: {
|
|
151
150
|
[P in keyof T[K]]: T[K][P];
|
|
152
151
|
};
|
|
153
152
|
};
|
|
154
153
|
|
|
155
|
-
export { DefaultNamespaces, type ExtendContext,
|
|
154
|
+
export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SelectedValidationLibrary, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as
|
|
2
|
-
export { A as Awaitable, C as CreateScope, D as DeepPartial, z as DefaultHooks, y as DefaultMethods, E as ExtendShared, t as SilgiDefaultShared, o as SilgiEvent, x as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, S as SilgiOptions, v as SilgiStorageBase, u as SilgiURIs, s as SilgiValidationSchema, U as URIsTypes, w as silgi } from './shared/silgi.
|
|
1
|
+
import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SelectedValidationLibrary, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as MergedSilgiSchema, l as ServiceType, m as SilgiSchema, R as RequiredServiceType, n as SilgiModuleShared } from './shared/silgi.wMv9BQmS.js';
|
|
2
|
+
export { A as Awaitable, C as CreateScope, D as DeepPartial, z as DefaultHooks, y as DefaultMethods, E as ExtendShared, t as SilgiDefaultShared, o as SilgiEvent, x as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, S as SilgiOptions, v as SilgiStorageBase, u as SilgiURIs, s as SilgiValidationSchema, U as URIsTypes, w as silgi } from './shared/silgi.wMv9BQmS.js';
|
|
3
3
|
import * as unctx_index from 'unctx/index';
|
|
4
4
|
import 'consola';
|
|
5
5
|
import 'hookable';
|
|
6
6
|
import 'ignore';
|
|
7
7
|
import 'unstorage';
|
|
8
8
|
import 'defu';
|
|
9
|
+
import 'zod';
|
|
9
10
|
import 'h3';
|
|
10
11
|
import 'pkg-types';
|
|
11
|
-
import 'zod';
|
|
12
12
|
import 'nitropack/types';
|
|
13
13
|
|
|
14
14
|
declare function createSilgi(config: SilgiConfig): Promise<SilgiHelper>;
|
|
@@ -121,7 +121,6 @@ declare function normalizeResult<T>(result: T): T;
|
|
|
121
121
|
*/
|
|
122
122
|
declare function tryUseSilgi(): Silgi | null;
|
|
123
123
|
|
|
124
|
-
declare function generateURI(paths: string[], depth?: number): string;
|
|
125
124
|
/**
|
|
126
125
|
*
|
|
127
126
|
*
|
|
@@ -135,21 +134,21 @@ declare function generateURI(paths: string[], depth?: number): string;
|
|
|
135
134
|
* method: 'createBasket'
|
|
136
135
|
*
|
|
137
136
|
*/
|
|
138
|
-
declare function parseURI(uri: string): SilgiOperation;
|
|
137
|
+
declare function parseURI(uri: string, uris?: object): SilgiOperation;
|
|
139
138
|
|
|
140
139
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
141
|
-
declare function
|
|
142
|
-
declare function mergeServices<T extends ServiceType<
|
|
140
|
+
declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
|
|
141
|
+
declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
|
|
143
142
|
declare function mergeShared<T extends SilgiModuleShared[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
|
|
144
143
|
|
|
145
|
-
declare function createService<T extends
|
|
144
|
+
declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
|
|
146
145
|
|
|
147
146
|
declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
|
|
148
147
|
|
|
149
|
-
declare function
|
|
148
|
+
declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<SelectedValidationLibrary>>>>>(silgiType: T): {
|
|
150
149
|
[K in keyof T]: {
|
|
151
150
|
[P in keyof T[K]]: T[K][P];
|
|
152
151
|
};
|
|
153
152
|
};
|
|
154
153
|
|
|
155
|
-
export { DefaultNamespaces, type ExtendContext,
|
|
154
|
+
export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ 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
|
|
6
|
-
export { e as createResolver,
|
|
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.BLxo8kmF.mjs';
|
|
6
|
+
export { e as createResolver, f as useHook, h as useShared } from './shared/silgi.BLxo8kmF.mjs';
|
|
7
7
|
import satisfies from 'semver/functions/satisfies.js';
|
|
8
8
|
import { S as SilgiConfigSchema } from './shared/silgi.C0NIj2vN.mjs';
|
|
9
9
|
export { r as relativeWithDot } from './shared/silgi.C0NIj2vN.mjs';
|
|
@@ -104,7 +104,7 @@ async function execute(uriString, input, event) {
|
|
|
104
104
|
let result;
|
|
105
105
|
let operation;
|
|
106
106
|
try {
|
|
107
|
-
operation = parseURI(uriString);
|
|
107
|
+
operation = parseURI(uriString, silgiCtx.uris);
|
|
108
108
|
} catch {
|
|
109
109
|
throw new SilgiError({
|
|
110
110
|
code: "INVALID_URI",
|
|
@@ -128,7 +128,7 @@ async function execute(uriString, input, event) {
|
|
|
128
128
|
input,
|
|
129
129
|
event
|
|
130
130
|
});
|
|
131
|
-
const handler = silgiCtx.scannedHandlers.get(operation.
|
|
131
|
+
const handler = silgiCtx.scannedHandlers.get(operation.uri);
|
|
132
132
|
if (!handler) {
|
|
133
133
|
return {
|
|
134
134
|
success: false,
|
|
@@ -147,8 +147,12 @@ async function execute(uriString, input, event) {
|
|
|
147
147
|
success = cacheData.success;
|
|
148
148
|
cached = cacheData.cached;
|
|
149
149
|
} else {
|
|
150
|
+
const router = {
|
|
151
|
+
params: operation.routerParams,
|
|
152
|
+
query: operation.query
|
|
153
|
+
};
|
|
150
154
|
silgiCtx.shared.silgi = (_event) => silgi(_event || event);
|
|
151
|
-
result = await handler?.handler(input, silgiCtx.shared, event);
|
|
155
|
+
result = await handler?.handler(router, input, silgiCtx.shared, event);
|
|
152
156
|
success = true;
|
|
153
157
|
}
|
|
154
158
|
await silgiCtx.callHook("method:after", {
|
|
@@ -323,7 +327,7 @@ async function createSilgi(config) {
|
|
|
323
327
|
const hooks = createHooks();
|
|
324
328
|
await applyDefaults(SilgiConfigSchema, config.options);
|
|
325
329
|
const silgi = {
|
|
326
|
-
|
|
330
|
+
schemas: config.schemas,
|
|
327
331
|
_version: version,
|
|
328
332
|
services: config.services,
|
|
329
333
|
shared: config.shared,
|
|
@@ -346,7 +350,7 @@ async function createSilgi(config) {
|
|
|
346
350
|
})).withTag("silgi")
|
|
347
351
|
// TODO: shared, uris, services burada olacak
|
|
348
352
|
};
|
|
349
|
-
await
|
|
353
|
+
await scanAction(silgi);
|
|
350
354
|
silgi.storage = await createStorage(silgi);
|
|
351
355
|
silgi.shared.storage = (...data) => {
|
|
352
356
|
return useStorage(...data);
|
|
@@ -440,7 +444,7 @@ ${issues.toString()}`);
|
|
|
440
444
|
function merge(items) {
|
|
441
445
|
return Object.assign({}, ...Array.isArray(items) ? items : [items]);
|
|
442
446
|
}
|
|
443
|
-
function
|
|
447
|
+
function mergeSchemas(typesOrArray) {
|
|
444
448
|
return merge(typesOrArray);
|
|
445
449
|
}
|
|
446
450
|
function mergeServices(servicesOrArray) {
|
|
@@ -458,8 +462,8 @@ function createShared(shared) {
|
|
|
458
462
|
return shared;
|
|
459
463
|
}
|
|
460
464
|
|
|
461
|
-
function
|
|
465
|
+
function createSchema(silgiType) {
|
|
462
466
|
return silgiType;
|
|
463
467
|
}
|
|
464
468
|
|
|
465
|
-
export { SilgiError, SilgiHelper, createService, createShared, createSilgi,
|
|
469
|
+
export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, tryUseSilgi, useSilgi };
|
|
@@ -139,48 +139,119 @@ ${this.stack}`;
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
+
},
|
|
155
|
+
yup: {
|
|
156
|
+
name: "yup",
|
|
157
|
+
isSchemaType: (obj) => obj?._type !== undefined,
|
|
158
|
+
getRouterParams: (routerObj) => {
|
|
159
|
+
return routerObj?.fields ? Object.keys(routerObj.fields) : null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
class SchemaValidatorRegistry {
|
|
164
|
+
validators = [];
|
|
165
|
+
constructor(validationLibrary = "zod") {
|
|
166
|
+
this.setValidationLibrary(validationLibrary);
|
|
167
|
+
}
|
|
168
|
+
setValidationLibrary(library) {
|
|
169
|
+
this.validators = [];
|
|
170
|
+
const plugin = plugins[library];
|
|
171
|
+
if (plugin) {
|
|
172
|
+
this.register(plugin);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
register(plugin) {
|
|
176
|
+
this.validators.push(plugin);
|
|
177
|
+
}
|
|
178
|
+
getParams(routerObj) {
|
|
179
|
+
for (const validator of this.validators) {
|
|
180
|
+
if (validator.isSchemaType(routerObj)) {
|
|
181
|
+
return validator.getRouterParams(routerObj);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
145
185
|
}
|
|
146
|
-
return paths.join("/");
|
|
147
186
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
187
|
+
const schemaRegistry = new SchemaValidatorRegistry();
|
|
188
|
+
|
|
189
|
+
function traverseObject(silgi, obj, currentPath = []) {
|
|
190
|
+
schemaRegistry.setValidationLibrary(silgi.options.validationLibrary || "zod");
|
|
191
|
+
const uriMap = /* @__PURE__ */ new Map();
|
|
192
|
+
function traverse(node, path = []) {
|
|
193
|
+
if (node && typeof node === "object" && node.input && node.output) {
|
|
194
|
+
const basePath = path.join("/");
|
|
195
|
+
if (node.router) {
|
|
196
|
+
const params = schemaRegistry.getParams(node.router);
|
|
197
|
+
if (params?.length) {
|
|
198
|
+
const paramString = params.map((p) => `:${p}`).join("/");
|
|
199
|
+
uriMap.set(basePath, paramString);
|
|
200
|
+
} else {
|
|
201
|
+
uriMap.set(basePath, "");
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
uriMap.set(basePath, "");
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (node && typeof node === "object") {
|
|
209
|
+
for (const key in node) {
|
|
210
|
+
if (!["router", "input", "output", "_def", "shape"].includes(key)) {
|
|
211
|
+
traverse(node[key], [...path, key]);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
152
214
|
}
|
|
153
|
-
return currentPath.length > 0 ? [generateURI(currentPath, depth)] : [];
|
|
154
215
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
216
|
+
traverse(obj, currentPath);
|
|
217
|
+
return uriMap;
|
|
158
218
|
}
|
|
159
|
-
function parseURI(uri) {
|
|
219
|
+
function parseURI(uri, uris) {
|
|
220
|
+
if (!uris) {
|
|
221
|
+
const silgiCtx = useSilgi();
|
|
222
|
+
uris = silgiCtx.uris;
|
|
223
|
+
}
|
|
160
224
|
uri = uri.replace("/srn", "");
|
|
161
225
|
const [cleanPath, queryString] = uri.split("?");
|
|
162
|
-
const
|
|
163
|
-
|
|
226
|
+
const query = new URLSearchParams(queryString);
|
|
227
|
+
const methodQuery = query.get("method")?.toLowerCase();
|
|
164
228
|
const parts = cleanPath.split("/").filter(Boolean);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
229
|
+
const [namespace, service, methodOrAction, action, ...routerParams] = parts;
|
|
230
|
+
let uriKey = `${namespace}/${service}/${methodOrAction}/${action}`;
|
|
231
|
+
if (methodQuery) {
|
|
232
|
+
uriKey = `${namespace}/${service}/${methodQuery}/${methodOrAction}`;
|
|
233
|
+
routerParams.unshift(action);
|
|
234
|
+
}
|
|
235
|
+
const paramTemplate = uris[uriKey];
|
|
236
|
+
const routerParamsData = {};
|
|
237
|
+
if (paramTemplate && routerParams.length > 0) {
|
|
238
|
+
const paramNames = paramTemplate.split("/").map((p) => p.replace(":", ""));
|
|
239
|
+
routerParams.forEach((value, index) => {
|
|
240
|
+
if (paramNames[index]) {
|
|
241
|
+
routerParamsData[paramNames[index]] = value;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
176
244
|
}
|
|
177
245
|
return {
|
|
178
|
-
namespaceName:
|
|
179
|
-
serviceName:
|
|
180
|
-
|
|
181
|
-
|
|
246
|
+
namespaceName: namespace,
|
|
247
|
+
serviceName: service,
|
|
248
|
+
methodName: methodQuery || methodOrAction,
|
|
249
|
+
actionName: methodQuery ? methodOrAction : action,
|
|
182
250
|
raw: uri,
|
|
183
|
-
parts
|
|
251
|
+
parts: [namespace, service, methodQuery || methodOrAction, action],
|
|
252
|
+
routerParams: routerParamsData,
|
|
253
|
+
query: query.toString() ? Object.fromEntries(query) : undefined,
|
|
254
|
+
uri: uriKey
|
|
184
255
|
};
|
|
185
256
|
}
|
|
186
257
|
|
|
@@ -248,21 +319,22 @@ async function generateSilgiStorageBaseType(silgi) {
|
|
|
248
319
|
});
|
|
249
320
|
}
|
|
250
321
|
|
|
251
|
-
async function generateUris(silgi
|
|
322
|
+
async function generateUris(silgi) {
|
|
252
323
|
silgi.hook("read:core.ts", async (data) => {
|
|
253
324
|
const { context, object, path } = await data();
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
325
|
+
const uriMap = traverseObject(silgi, object.schemas, []);
|
|
326
|
+
const uriContent = Array.from(uriMap.entries()).map(([uri, params]) => ` '${uri}': '${params}',`).join("\n");
|
|
327
|
+
const newContext = context.replace(
|
|
328
|
+
"export const uris = {}",
|
|
329
|
+
`export const uris = {
|
|
330
|
+
${uriContent}
|
|
331
|
+
}`
|
|
332
|
+
);
|
|
333
|
+
await promises.writeFile(path, newContext);
|
|
262
334
|
});
|
|
263
335
|
}
|
|
264
|
-
async function
|
|
265
|
-
const {
|
|
336
|
+
async function findAction(silgi, uri) {
|
|
337
|
+
const { parts } = parseURI(uri, silgi);
|
|
266
338
|
let result = silgi.services;
|
|
267
339
|
for (const part of parts) {
|
|
268
340
|
if (result && Object.prototype.hasOwnProperty.call(result, part)) {
|
|
@@ -274,9 +346,9 @@ async function findHandler(silgi, uri) {
|
|
|
274
346
|
}
|
|
275
347
|
return result;
|
|
276
348
|
}
|
|
277
|
-
async function
|
|
349
|
+
async function scanAction(silgi) {
|
|
278
350
|
for (const [key, _value] of Object.entries(silgi.uris)) {
|
|
279
|
-
const handler = await
|
|
351
|
+
const handler = await findAction(silgi, key);
|
|
280
352
|
silgi.scannedHandlers.set(key, handler);
|
|
281
353
|
}
|
|
282
354
|
}
|
|
@@ -352,4 +424,4 @@ async function resolveSilgiModule(base, paths) {
|
|
|
352
424
|
return resolved;
|
|
353
425
|
}
|
|
354
426
|
|
|
355
|
-
export { SilgiError as S, useStorage as a, SilgiErrorCode as b, createStorage as c, silgiCtx as d, createResolver as e, useHook as f, generateStorageKey as g, useShared as h,
|
|
427
|
+
export { SilgiError as S, useStorage as a, SilgiErrorCode as b, createStorage as c, silgiCtx as d, createResolver as e, useHook as f, generateStorageKey as g, useShared as h, getDirectory as i, resolvePath as j, generateUris as k, loadSilgiModuleInstance as l, generateSilgiStorageBaseType as m, normalizeResult as n, parseURI as p, resolveSilgiModule as r, scanAction as s, tryUseSilgi as t, useSilgi as u };
|
|
@@ -3,14 +3,51 @@ import { Hookable } from 'hookable';
|
|
|
3
3
|
import { Ignore } from 'ignore';
|
|
4
4
|
import { BuiltinDriverName, TransactionOptions, StorageValue, Storage } from 'unstorage';
|
|
5
5
|
import { Defu } from 'defu';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
import { Router, H3Event } from 'h3';
|
|
7
8
|
import { TSConfig } from 'pkg-types';
|
|
8
|
-
import { z } from 'zod';
|
|
9
9
|
import { NitroApp } from 'nitropack/types';
|
|
10
10
|
|
|
11
11
|
interface SilgiEvent extends Record<string, unknown> {
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
interface SilgiMethods {
|
|
15
|
+
}
|
|
16
|
+
interface SilgiNamespaces {
|
|
17
|
+
}
|
|
18
|
+
type BaseSilgiMethodType = 'post' | 'delete' | 'put' | 'get' | keyof SilgiMethods;
|
|
19
|
+
interface DefaultNamespaces extends SilgiNamespaces {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface SilgiSchema {
|
|
23
|
+
}
|
|
24
|
+
interface MergedSilgiSchema {
|
|
25
|
+
}
|
|
26
|
+
interface SilgiValidationSchema {
|
|
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> = {
|
|
44
|
+
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
45
|
+
input?: SchemaTypes[V];
|
|
46
|
+
output?: SchemaTypes[V];
|
|
47
|
+
routerParams?: SchemaTypes[V];
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
|
|
14
51
|
interface SilgiURIs {
|
|
15
52
|
}
|
|
16
53
|
type URIsTypes<T extends Record<string, string>> = {
|
|
@@ -27,22 +64,18 @@ type GetInput<T extends {
|
|
|
27
64
|
entity: string;
|
|
28
65
|
method: string;
|
|
29
66
|
action: string;
|
|
30
|
-
}> = T['service'] extends keyof
|
|
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']]['input'] : never : never : never : never;
|
|
31
68
|
type GetOutput<T extends {
|
|
32
69
|
service: string;
|
|
33
70
|
entity: string;
|
|
34
71
|
method: string;
|
|
35
72
|
action: string;
|
|
36
|
-
}> = T['service'] extends keyof
|
|
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']]['output'] : never : never : never : never;
|
|
37
74
|
type ExtractInputFromURI<TURI extends keyof SilgiURIs> = GetInput<ExtractPath<TURI>>;
|
|
38
75
|
type ExtractOutputFromURI<TURI extends keyof SilgiURIs> = GetOutput<ExtractPath<TURI>>;
|
|
39
76
|
|
|
40
77
|
interface SilgiHook {
|
|
41
78
|
}
|
|
42
|
-
interface SilgiServiceTypes {
|
|
43
|
-
}
|
|
44
|
-
interface MergeSilgiType {
|
|
45
|
-
}
|
|
46
79
|
interface DefaultHooks {
|
|
47
80
|
}
|
|
48
81
|
interface DefaultMethods {
|
|
@@ -117,38 +150,6 @@ declare class SRNManager {
|
|
|
117
150
|
getAllServices(): any;
|
|
118
151
|
}
|
|
119
152
|
|
|
120
|
-
interface SilgiMethods {
|
|
121
|
-
}
|
|
122
|
-
interface SilgiNamespaces {
|
|
123
|
-
}
|
|
124
|
-
type BaseSilgiMethodType = 'post' | 'delete' | 'put' | 'get' | keyof SilgiMethods;
|
|
125
|
-
interface DefaultNamespaces extends SilgiNamespaces {
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface SilgiValidationSchema {
|
|
129
|
-
}
|
|
130
|
-
type ValidationLibrary = 'zod' | 'yup';
|
|
131
|
-
type SelectedValidationLibrary = SilgiValidationSchema extends {
|
|
132
|
-
validationLibrary: infer V;
|
|
133
|
-
} ? V extends ValidationLibrary ? V : 'zod' : 'zod';
|
|
134
|
-
/**
|
|
135
|
-
* A map of validation library names to their type definitions.
|
|
136
|
-
*
|
|
137
|
-
* @see {@link https://zod.dev/ | Zod}
|
|
138
|
-
* @see {@link https://github.com/jquense/yup | Yup}
|
|
139
|
-
*/
|
|
140
|
-
interface SchemaTypes {
|
|
141
|
-
zod: z.ZodTypeAny;
|
|
142
|
-
yup: any;
|
|
143
|
-
}
|
|
144
|
-
type InferSchemaType<V extends SelectedValidationLibrary, T> = V extends 'zod' ? T extends z.ZodTypeAny ? z.infer<T> : never : V extends 'yup' ? any : never;
|
|
145
|
-
type BaseSchemaType<V extends SelectedValidationLibrary> = {
|
|
146
|
-
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
147
|
-
input?: SchemaTypes[V];
|
|
148
|
-
output?: SchemaTypes[V];
|
|
149
|
-
}>;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
153
|
/**
|
|
153
154
|
* @example
|
|
154
155
|
* namespace: 'coreApi'
|
|
@@ -181,7 +182,13 @@ interface SilgiOperation {
|
|
|
181
182
|
* 'coreApi/basket/post/createBasket'
|
|
182
183
|
*/
|
|
183
184
|
raw: keyof SilgiURIs;
|
|
185
|
+
/**
|
|
186
|
+
* '/book/basket/getAllBaskets'
|
|
187
|
+
*/
|
|
188
|
+
uri: string;
|
|
184
189
|
parts: string[];
|
|
190
|
+
routerParams?: Record<string, string>;
|
|
191
|
+
query?: Record<string, string>;
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
type CustomDriverName = string & {
|
|
@@ -517,7 +524,7 @@ interface SilgiHooks {
|
|
|
517
524
|
uris: string[];
|
|
518
525
|
services: string[];
|
|
519
526
|
shareds: string[];
|
|
520
|
-
|
|
527
|
+
schemas: string[];
|
|
521
528
|
modules: string[];
|
|
522
529
|
}) => HookResult;
|
|
523
530
|
'prepare:schema.ts': (options: {
|
|
@@ -573,6 +580,7 @@ interface SilgiHooks {
|
|
|
573
580
|
uris?: string[];
|
|
574
581
|
services?: string[];
|
|
575
582
|
shareds?: string[];
|
|
583
|
+
schemas?: string[];
|
|
576
584
|
};
|
|
577
585
|
path: string;
|
|
578
586
|
}>) => HookResult;
|
|
@@ -607,6 +615,7 @@ interface ModuleMeta {
|
|
|
607
615
|
shared?: true;
|
|
608
616
|
context?: true;
|
|
609
617
|
method?: true;
|
|
618
|
+
schema?: true;
|
|
610
619
|
event?: true;
|
|
611
620
|
};
|
|
612
621
|
variable?: {
|
|
@@ -697,7 +706,7 @@ type MethodHandlerType<T> = {
|
|
|
697
706
|
input?: T[Action][Method]['input'] extends infer U ? U : never;
|
|
698
707
|
output?: T[Action][Method]['output'] extends infer U ? U : never;
|
|
699
708
|
};
|
|
700
|
-
handler: (input: T[Action][Method]['input'], shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<T[Action][Method]['output'] extends infer U ? U : undefined>;
|
|
709
|
+
handler: (router: T[Action][Method]['router'] extends infer U ? U : never, input: T[Action][Method]['input'], shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<T[Action][Method]['output'] extends infer U ? U : undefined>;
|
|
701
710
|
modules?: ModuleConfigurations;
|
|
702
711
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
703
712
|
};
|
|
@@ -706,7 +715,7 @@ type MethodHandlerType<T> = {
|
|
|
706
715
|
interface ResolvedMethodHandlerType {
|
|
707
716
|
input?: Partial<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
708
717
|
output: Partial<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
709
|
-
handler: (input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
718
|
+
handler: (router: InferSchemaType<SelectedValidationLibrary, any>, input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
710
719
|
modules?: ModuleConfigurations;
|
|
711
720
|
storage?: StorageConfig<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
712
721
|
execute: (input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
@@ -735,7 +744,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
735
744
|
entity: Entity;
|
|
736
745
|
method: Method;
|
|
737
746
|
action: Action;
|
|
738
|
-
} : never : never)["entity"] extends keyof
|
|
747
|
+
} : never : never)["entity"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
739
748
|
service: Service;
|
|
740
749
|
entity: Entity;
|
|
741
750
|
method: Method;
|
|
@@ -745,7 +754,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
745
754
|
entity: Entity;
|
|
746
755
|
method: Method;
|
|
747
756
|
action: Action;
|
|
748
|
-
} : never : never)["method"] extends keyof
|
|
757
|
+
} : never : never)["method"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
749
758
|
service: Service;
|
|
750
759
|
entity: Entity;
|
|
751
760
|
method: Method;
|
|
@@ -760,7 +769,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
760
769
|
entity: Entity;
|
|
761
770
|
method: Method;
|
|
762
771
|
action: Action;
|
|
763
|
-
} : never : never)["action"] extends keyof
|
|
772
|
+
} : never : never)["action"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
764
773
|
service: Service;
|
|
765
774
|
entity: Entity;
|
|
766
775
|
method: Method;
|
|
@@ -775,7 +784,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
775
784
|
entity: Entity;
|
|
776
785
|
method: Method;
|
|
777
786
|
action: Action;
|
|
778
|
-
} : never : never)["method"]] ?
|
|
787
|
+
} : never : never)["method"]] ? SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
779
788
|
service: Service;
|
|
780
789
|
entity: Entity;
|
|
781
790
|
method: Method;
|
|
@@ -803,6 +812,7 @@ type SilgiServiceInterface<T extends BaseSchemaType<SelectedValidationLibrary>>
|
|
|
803
812
|
[Method in keyof T[Action]]: {
|
|
804
813
|
input: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['input']>;
|
|
805
814
|
output?: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['output']>;
|
|
815
|
+
router?: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['router']>;
|
|
806
816
|
};
|
|
807
817
|
} : never;
|
|
808
818
|
};
|
|
@@ -840,7 +850,7 @@ type ResolvedServiceType = {
|
|
|
840
850
|
};
|
|
841
851
|
|
|
842
852
|
interface Silgi {
|
|
843
|
-
|
|
853
|
+
schemas: any;
|
|
844
854
|
services: ResolvedServiceType;
|
|
845
855
|
shared: SilgiDefaultShared;
|
|
846
856
|
uris: Record<string, any>;
|
|
@@ -863,9 +873,9 @@ interface Silgi {
|
|
|
863
873
|
storage: Storage;
|
|
864
874
|
options: SilgiOptions;
|
|
865
875
|
}
|
|
866
|
-
interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | '
|
|
876
|
+
interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'schemas' | '_initializedModules'> {
|
|
867
877
|
options: DeepPartial<SilgiOptions>;
|
|
868
878
|
}
|
|
869
879
|
type SilgiFunction = typeof silgi;
|
|
870
880
|
|
|
871
|
-
export { type Awaitable as A, type BaseSchemaType as B, type CreateScope as C, type DeepPartial as D, type ExtendShared as E, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type ValidationLibrary as V, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SelectedValidationLibrary as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type
|
|
881
|
+
export { type Awaitable as A, type BaseSchemaType as B, type CreateScope as C, type DeepPartial as D, type ExtendShared as E, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type ValidationLibrary as V, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SelectedValidationLibrary as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type MergedSilgiSchema as k, type ServiceType as l, type SilgiSchema as m, type SilgiModuleShared as n, type SilgiEvent as o, type SilgiModuleMethods as p, type SilgiModules as q, type SilgiNamespaces as r, type SilgiValidationSchema as s, type SilgiDefaultShared as t, type SilgiURIs as u, type SilgiStorageBase as v, silgi as w, type SilgiHook as x, type DefaultMethods as y, type DefaultHooks as z };
|
|
@@ -3,14 +3,51 @@ import { Hookable } from 'hookable';
|
|
|
3
3
|
import { Ignore } from 'ignore';
|
|
4
4
|
import { BuiltinDriverName, TransactionOptions, StorageValue, Storage } from 'unstorage';
|
|
5
5
|
import { Defu } from 'defu';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
import { Router, H3Event } from 'h3';
|
|
7
8
|
import { TSConfig } from 'pkg-types';
|
|
8
|
-
import { z } from 'zod';
|
|
9
9
|
import { NitroApp } from 'nitropack/types';
|
|
10
10
|
|
|
11
11
|
interface SilgiEvent extends Record<string, unknown> {
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
interface SilgiMethods {
|
|
15
|
+
}
|
|
16
|
+
interface SilgiNamespaces {
|
|
17
|
+
}
|
|
18
|
+
type BaseSilgiMethodType = 'post' | 'delete' | 'put' | 'get' | keyof SilgiMethods;
|
|
19
|
+
interface DefaultNamespaces extends SilgiNamespaces {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface SilgiSchema {
|
|
23
|
+
}
|
|
24
|
+
interface MergedSilgiSchema {
|
|
25
|
+
}
|
|
26
|
+
interface SilgiValidationSchema {
|
|
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> = {
|
|
44
|
+
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
45
|
+
input?: SchemaTypes[V];
|
|
46
|
+
output?: SchemaTypes[V];
|
|
47
|
+
routerParams?: SchemaTypes[V];
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
|
|
14
51
|
interface SilgiURIs {
|
|
15
52
|
}
|
|
16
53
|
type URIsTypes<T extends Record<string, string>> = {
|
|
@@ -27,22 +64,18 @@ type GetInput<T extends {
|
|
|
27
64
|
entity: string;
|
|
28
65
|
method: string;
|
|
29
66
|
action: string;
|
|
30
|
-
}> = T['service'] extends keyof
|
|
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']]['input'] : never : never : never : never;
|
|
31
68
|
type GetOutput<T extends {
|
|
32
69
|
service: string;
|
|
33
70
|
entity: string;
|
|
34
71
|
method: string;
|
|
35
72
|
action: string;
|
|
36
|
-
}> = T['service'] extends keyof
|
|
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']]['output'] : never : never : never : never;
|
|
37
74
|
type ExtractInputFromURI<TURI extends keyof SilgiURIs> = GetInput<ExtractPath<TURI>>;
|
|
38
75
|
type ExtractOutputFromURI<TURI extends keyof SilgiURIs> = GetOutput<ExtractPath<TURI>>;
|
|
39
76
|
|
|
40
77
|
interface SilgiHook {
|
|
41
78
|
}
|
|
42
|
-
interface SilgiServiceTypes {
|
|
43
|
-
}
|
|
44
|
-
interface MergeSilgiType {
|
|
45
|
-
}
|
|
46
79
|
interface DefaultHooks {
|
|
47
80
|
}
|
|
48
81
|
interface DefaultMethods {
|
|
@@ -117,38 +150,6 @@ declare class SRNManager {
|
|
|
117
150
|
getAllServices(): any;
|
|
118
151
|
}
|
|
119
152
|
|
|
120
|
-
interface SilgiMethods {
|
|
121
|
-
}
|
|
122
|
-
interface SilgiNamespaces {
|
|
123
|
-
}
|
|
124
|
-
type BaseSilgiMethodType = 'post' | 'delete' | 'put' | 'get' | keyof SilgiMethods;
|
|
125
|
-
interface DefaultNamespaces extends SilgiNamespaces {
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface SilgiValidationSchema {
|
|
129
|
-
}
|
|
130
|
-
type ValidationLibrary = 'zod' | 'yup';
|
|
131
|
-
type SelectedValidationLibrary = SilgiValidationSchema extends {
|
|
132
|
-
validationLibrary: infer V;
|
|
133
|
-
} ? V extends ValidationLibrary ? V : 'zod' : 'zod';
|
|
134
|
-
/**
|
|
135
|
-
* A map of validation library names to their type definitions.
|
|
136
|
-
*
|
|
137
|
-
* @see {@link https://zod.dev/ | Zod}
|
|
138
|
-
* @see {@link https://github.com/jquense/yup | Yup}
|
|
139
|
-
*/
|
|
140
|
-
interface SchemaTypes {
|
|
141
|
-
zod: z.ZodTypeAny;
|
|
142
|
-
yup: any;
|
|
143
|
-
}
|
|
144
|
-
type InferSchemaType<V extends SelectedValidationLibrary, T> = V extends 'zod' ? T extends z.ZodTypeAny ? z.infer<T> : never : V extends 'yup' ? any : never;
|
|
145
|
-
type BaseSchemaType<V extends SelectedValidationLibrary> = {
|
|
146
|
-
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
147
|
-
input?: SchemaTypes[V];
|
|
148
|
-
output?: SchemaTypes[V];
|
|
149
|
-
}>;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
153
|
/**
|
|
153
154
|
* @example
|
|
154
155
|
* namespace: 'coreApi'
|
|
@@ -181,7 +182,13 @@ interface SilgiOperation {
|
|
|
181
182
|
* 'coreApi/basket/post/createBasket'
|
|
182
183
|
*/
|
|
183
184
|
raw: keyof SilgiURIs;
|
|
185
|
+
/**
|
|
186
|
+
* '/book/basket/getAllBaskets'
|
|
187
|
+
*/
|
|
188
|
+
uri: string;
|
|
184
189
|
parts: string[];
|
|
190
|
+
routerParams?: Record<string, string>;
|
|
191
|
+
query?: Record<string, string>;
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
type CustomDriverName = string & {
|
|
@@ -517,7 +524,7 @@ interface SilgiHooks {
|
|
|
517
524
|
uris: string[];
|
|
518
525
|
services: string[];
|
|
519
526
|
shareds: string[];
|
|
520
|
-
|
|
527
|
+
schemas: string[];
|
|
521
528
|
modules: string[];
|
|
522
529
|
}) => HookResult;
|
|
523
530
|
'prepare:schema.ts': (options: {
|
|
@@ -573,6 +580,7 @@ interface SilgiHooks {
|
|
|
573
580
|
uris?: string[];
|
|
574
581
|
services?: string[];
|
|
575
582
|
shareds?: string[];
|
|
583
|
+
schemas?: string[];
|
|
576
584
|
};
|
|
577
585
|
path: string;
|
|
578
586
|
}>) => HookResult;
|
|
@@ -607,6 +615,7 @@ interface ModuleMeta {
|
|
|
607
615
|
shared?: true;
|
|
608
616
|
context?: true;
|
|
609
617
|
method?: true;
|
|
618
|
+
schema?: true;
|
|
610
619
|
event?: true;
|
|
611
620
|
};
|
|
612
621
|
variable?: {
|
|
@@ -697,7 +706,7 @@ type MethodHandlerType<T> = {
|
|
|
697
706
|
input?: T[Action][Method]['input'] extends infer U ? U : never;
|
|
698
707
|
output?: T[Action][Method]['output'] extends infer U ? U : never;
|
|
699
708
|
};
|
|
700
|
-
handler: (input: T[Action][Method]['input'], shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<T[Action][Method]['output'] extends infer U ? U : undefined>;
|
|
709
|
+
handler: (router: T[Action][Method]['router'] extends infer U ? U : never, input: T[Action][Method]['input'], shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<T[Action][Method]['output'] extends infer U ? U : undefined>;
|
|
701
710
|
modules?: ModuleConfigurations;
|
|
702
711
|
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
703
712
|
};
|
|
@@ -706,7 +715,7 @@ type MethodHandlerType<T> = {
|
|
|
706
715
|
interface ResolvedMethodHandlerType {
|
|
707
716
|
input?: Partial<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
708
717
|
output: Partial<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
709
|
-
handler: (input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
718
|
+
handler: (router: InferSchemaType<SelectedValidationLibrary, any>, input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
710
719
|
modules?: ModuleConfigurations;
|
|
711
720
|
storage?: StorageConfig<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
712
721
|
execute: (input: InferSchemaType<SelectedValidationLibrary, any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<InferSchemaType<SelectedValidationLibrary, any>>;
|
|
@@ -735,7 +744,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
735
744
|
entity: Entity;
|
|
736
745
|
method: Method;
|
|
737
746
|
action: Action;
|
|
738
|
-
} : never : never)["entity"] extends keyof
|
|
747
|
+
} : never : never)["entity"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
739
748
|
service: Service;
|
|
740
749
|
entity: Entity;
|
|
741
750
|
method: Method;
|
|
@@ -745,7 +754,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
745
754
|
entity: Entity;
|
|
746
755
|
method: Method;
|
|
747
756
|
action: Action;
|
|
748
|
-
} : never : never)["method"] extends keyof
|
|
757
|
+
} : never : never)["method"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
749
758
|
service: Service;
|
|
750
759
|
entity: Entity;
|
|
751
760
|
method: Method;
|
|
@@ -760,7 +769,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
760
769
|
entity: Entity;
|
|
761
770
|
method: Method;
|
|
762
771
|
action: Action;
|
|
763
|
-
} : never : never)["action"] extends keyof
|
|
772
|
+
} : never : never)["action"] extends keyof SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
764
773
|
service: Service;
|
|
765
774
|
entity: Entity;
|
|
766
775
|
method: Method;
|
|
@@ -775,7 +784,7 @@ declare function silgi(event?: SilgiEvent | Record<string, any>): {
|
|
|
775
784
|
entity: Entity;
|
|
776
785
|
method: Method;
|
|
777
786
|
action: Action;
|
|
778
|
-
} : never : never)["method"]] ?
|
|
787
|
+
} : never : never)["method"]] ? SilgiSchema[(TURI extends `${infer Path}` ? Path extends `${infer Service}/${infer Entity}/${infer Method}/${infer Action}` ? {
|
|
779
788
|
service: Service;
|
|
780
789
|
entity: Entity;
|
|
781
790
|
method: Method;
|
|
@@ -803,6 +812,7 @@ type SilgiServiceInterface<T extends BaseSchemaType<SelectedValidationLibrary>>
|
|
|
803
812
|
[Method in keyof T[Action]]: {
|
|
804
813
|
input: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['input']>;
|
|
805
814
|
output?: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['output']>;
|
|
815
|
+
router?: InferSchemaType<SelectedValidationLibrary, T[Action][Method]['router']>;
|
|
806
816
|
};
|
|
807
817
|
} : never;
|
|
808
818
|
};
|
|
@@ -840,7 +850,7 @@ type ResolvedServiceType = {
|
|
|
840
850
|
};
|
|
841
851
|
|
|
842
852
|
interface Silgi {
|
|
843
|
-
|
|
853
|
+
schemas: any;
|
|
844
854
|
services: ResolvedServiceType;
|
|
845
855
|
shared: SilgiDefaultShared;
|
|
846
856
|
uris: Record<string, any>;
|
|
@@ -863,9 +873,9 @@ interface Silgi {
|
|
|
863
873
|
storage: Storage;
|
|
864
874
|
options: SilgiOptions;
|
|
865
875
|
}
|
|
866
|
-
interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | '
|
|
876
|
+
interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'schemas' | '_initializedModules'> {
|
|
867
877
|
options: DeepPartial<SilgiOptions>;
|
|
868
878
|
}
|
|
869
879
|
type SilgiFunction = typeof silgi;
|
|
870
880
|
|
|
871
|
-
export { type Awaitable as A, type BaseSchemaType as B, type CreateScope as C, type DeepPartial as D, type ExtendShared as E, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type ValidationLibrary as V, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SelectedValidationLibrary as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type
|
|
881
|
+
export { type Awaitable as A, type BaseSchemaType as B, type CreateScope as C, type DeepPartial as D, type ExtendShared as E, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type ValidationLibrary as V, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SelectedValidationLibrary as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type MergedSilgiSchema as k, type ServiceType as l, type SilgiSchema as m, type SilgiModuleShared as n, type SilgiEvent as o, type SilgiModuleMethods as p, type SilgiModules as q, type SilgiNamespaces as r, type SilgiValidationSchema as s, type SilgiDefaultShared as t, type SilgiURIs as u, type SilgiStorageBase as v, silgi as w, type SilgiHook as x, type DefaultMethods as y, type DefaultHooks as z };
|