silgi 0.41.62 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/build.mjs +35 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.d.mts +3 -2
- package/dist/index.d.mts +1 -0
- package/dist/types/index.d.mts +10 -9
- package/package.json +1 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -744,10 +744,29 @@ async function extractExportEntitiesFromFile(absoluteFilePath, functionExportNam
|
|
|
744
744
|
if (Array.isArray(decls)) {
|
|
745
745
|
for (const decl of decls) {
|
|
746
746
|
if (decl.type === "VariableDeclarator" && decl.id.type === "Identifier" && decl.init && decl.init.type === "CallExpression" && decl.init.callee.type === "Identifier" && functionExportNames.includes(decl.init.callee.name)) {
|
|
747
|
+
let servicePath;
|
|
748
|
+
let serviceMethod;
|
|
749
|
+
if (decl.init.callee.name === "createService") {
|
|
750
|
+
const firstArg = decl.init.arguments?.[0];
|
|
751
|
+
if (firstArg && firstArg.type === "ObjectExpression" && Array.isArray(firstArg.properties)) {
|
|
752
|
+
for (const prop of firstArg.properties) {
|
|
753
|
+
if (prop.type === "Property" && prop.key.type === "Identifier") {
|
|
754
|
+
if (prop.key.name === "path" && prop.value.type === "Literal" && typeof prop.value.value === "string") {
|
|
755
|
+
servicePath = prop.value.value;
|
|
756
|
+
}
|
|
757
|
+
if (prop.key.name === "method" && prop.value.type === "Literal" && typeof prop.value.value === "string") {
|
|
758
|
+
serviceMethod = prop.value.value;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
747
764
|
exportEntities.push({
|
|
748
765
|
name: decl.id.name,
|
|
749
766
|
type: "function",
|
|
750
|
-
funcName: decl.init.callee.name
|
|
767
|
+
funcName: decl.init.callee.name,
|
|
768
|
+
servicePath,
|
|
769
|
+
serviceMethod
|
|
751
770
|
});
|
|
752
771
|
}
|
|
753
772
|
}
|
|
@@ -815,6 +834,21 @@ async function scanSilgiExports(path, packageName, silgiInstance = useSilgiCLI()
|
|
|
815
834
|
functionExportNames,
|
|
816
835
|
interfaceExtendsNames
|
|
817
836
|
);
|
|
837
|
+
const seenServiceSignatures = /* @__PURE__ */ new Map();
|
|
838
|
+
for (const entity of exportEntities) {
|
|
839
|
+
if (entity.funcName === "createService" && entity.servicePath && entity.serviceMethod) {
|
|
840
|
+
const key = `${entity.serviceMethod}:${entity.servicePath}`;
|
|
841
|
+
if (seenServiceSignatures.has(key)) {
|
|
842
|
+
throw new Error(
|
|
843
|
+
`Duplicate createService detected for path "${entity.servicePath}" and method "${entity.serviceMethod}".
|
|
844
|
+
First found in: ${seenServiceSignatures.get(key)}
|
|
845
|
+
Duplicate in: ${absoluteFilePath}
|
|
846
|
+
Please ensure each service path/method combination is unique.`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
seenServiceSignatures.set(key, absoluteFilePath);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
818
852
|
const allExportedEntities = exportEntities;
|
|
819
853
|
const { runtimeExports, typeExports } = categorizeExports(
|
|
820
854
|
allExportedEntities,
|
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { ServerRequest, ServerRuntimeContext } from 'srvx';
|
|
|
3
3
|
import { UseContext } from 'unctx';
|
|
4
4
|
import { Storage, StorageValue } from 'unstorage';
|
|
5
5
|
export { c as createMiddleware } from '../shared/silgi.DTwQEdSr.mjs';
|
|
6
|
+
import { Hooks } from 'crossws';
|
|
6
7
|
|
|
7
8
|
declare function updateRuntimeStorage(runtime: any): void;
|
|
8
9
|
/**
|
|
@@ -304,8 +305,8 @@ declare function createSchema<Key extends string, Schema extends BaseMethodSchem
|
|
|
304
305
|
* ServiceSetup tipinden oluşan bir yardımcı fonksiyon.
|
|
305
306
|
* Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
|
|
306
307
|
*/
|
|
307
|
-
declare function defineServiceSetup<Method extends HTTPMethod, Path extends keyof Routers, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(setup: Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>): Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>;
|
|
308
|
-
declare function createService<Path extends string, Method extends HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(params: ServiceSetupsForMethods<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceDefinitionByMethodAndPath<Path, Method, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
308
|
+
declare function defineServiceSetup<Method extends HTTPMethod, Path extends keyof Routers, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false, Websocket extends Partial<Hooks> | undefined = undefined>(setup: Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>, 'method' | 'path'>): Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>, 'method' | 'path'>;
|
|
309
|
+
declare function createService<Path extends string, Method extends HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false, Websocket extends Partial<Hooks> | undefined = undefined>(params: ServiceSetupsForMethods<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>): ServiceDefinitionByMethodAndPath<Path, Method, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>;
|
|
309
310
|
|
|
310
311
|
declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
|
|
311
312
|
|
package/dist/index.d.mts
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ import { TransactionOptions, BuiltinDriverName, StorageValue, Storage } from 'un
|
|
|
23
23
|
import { ServerRequest } from 'srvx';
|
|
24
24
|
import { C as CreateMiddlewareResult } from '../shared/silgi.DTwQEdSr.mjs';
|
|
25
25
|
import { Defu } from 'defu';
|
|
26
|
-
import
|
|
26
|
+
import { Hooks, ResolveHooks } from 'crossws';
|
|
27
27
|
import { silgiFetch } from 'silgi';
|
|
28
28
|
import { useRuntimeConfig } from 'silgi/runtime';
|
|
29
29
|
import { Unimport } from 'unimport';
|
|
@@ -292,9 +292,9 @@ declare namespace StandardSchemaV1 {
|
|
|
292
292
|
interface ServicesObject {
|
|
293
293
|
}
|
|
294
294
|
interface WebSocketOptions {
|
|
295
|
-
resolve?:
|
|
296
|
-
hooks?: Partial<
|
|
297
|
-
adapterHooks?: Partial<
|
|
295
|
+
resolve?: ResolveHooks;
|
|
296
|
+
hooks?: Partial<Hooks>;
|
|
297
|
+
adapterHooks?: Partial<Hooks>;
|
|
298
298
|
}
|
|
299
299
|
type SlashCount<S extends string, Count extends any[] = []> = S extends `${infer _Prefix}/${infer Rest}` ? SlashCount<Rest, [any, ...Count]> : Count['length'];
|
|
300
300
|
type Max4Slashes<S extends keyof Routers> = SlashCount<S> extends 0 | 1 | 2 | 3 ? S : never;
|
|
@@ -332,11 +332,11 @@ type ServiceHandler<Input extends StandardSchemaV1, Output extends StandardSchem
|
|
|
332
332
|
/**
|
|
333
333
|
* Servis setup tipi
|
|
334
334
|
*/
|
|
335
|
-
interface ServiceSetup<Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> {
|
|
335
|
+
interface ServiceSetup<Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false, Websocket extends Partial<Hooks> | undefined = undefined> {
|
|
336
336
|
path: Path;
|
|
337
337
|
method?: Method;
|
|
338
338
|
handler?: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
339
|
-
websocket?:
|
|
339
|
+
websocket?: Websocket;
|
|
340
340
|
rules?: MergeRouteRules;
|
|
341
341
|
modules?: Partial<SetupModuleOption>;
|
|
342
342
|
storage?: StorageConfig<ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>>;
|
|
@@ -369,7 +369,8 @@ interface SilgiURL {
|
|
|
369
369
|
pathParams?: Record<string, string | undefined>;
|
|
370
370
|
queryParams?: Record<string, string>;
|
|
371
371
|
}
|
|
372
|
-
type
|
|
372
|
+
type IsWebsocketEnabled<T> = [T] extends [undefined] | [never] ? false : true;
|
|
373
|
+
type ServiceSetupsForMethods<Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false, Websocket extends Partial<Hooks> | undefined = undefined> = ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>;
|
|
373
374
|
/**
|
|
374
375
|
* Sadece belirtilen HTTP methodları için anahtar üretir.
|
|
375
376
|
* Varsayılan olarak tüm methodlar çıkar.
|
|
@@ -378,8 +379,8 @@ type ServiceSetupsForMethods<Method extends HTTPMethod = HTTPMethod, Path extend
|
|
|
378
379
|
* ServiceDefinitionByMethodAndPath<'/foo', ..., 'GET' | 'POST'>
|
|
379
380
|
* // Sadece "GET:/foo" ve "POST:/foo" anahtarları olur.
|
|
380
381
|
*/
|
|
381
|
-
type ServiceDefinitionByMethodAndPath<Path extends string, Method extends HTTPMethod = HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
|
|
382
|
-
[M in Method as
|
|
382
|
+
type ServiceDefinitionByMethodAndPath<Path extends string, Method extends HTTPMethod = HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false, Websocket extends Partial<Hooks> | undefined = undefined> = {
|
|
383
|
+
[M in Method as IsWebsocketEnabled<Websocket> extends true ? `websocket:${M}:${Path}` : `http:${M}:${Path}`]: ServiceSetup<M, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters, Websocket>;
|
|
383
384
|
};
|
|
384
385
|
|
|
385
386
|
interface SilgiCLI {
|