silgi 0.38.0 → 0.38.2

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.
@@ -429,18 +429,18 @@ async function registerModuleExportScan(silgi) {
429
429
  });
430
430
  options.runtimeHooks.push({ key: configKey, value: importName });
431
431
  }
432
- if (hasTypeExport("ModuleRuntimeActions")) {
433
- const importName = hash(`${configKey}ModuleRuntimeActions`);
432
+ if (hasTypeExport("SetupModuleOption")) {
433
+ const importName = hash(`${configKey}SetupModuleOption`);
434
434
  options.addImportItemType({
435
435
  imports: [
436
436
  {
437
437
  as: importName,
438
- name: "ModuleRuntimeActions"
438
+ name: "SetupModuleOption"
439
439
  }
440
440
  ],
441
441
  specifier
442
442
  });
443
- options.actions.push({ key: configKey, value: importName });
443
+ options.setupModuleOption.push({ key: configKey, value: importName });
444
444
  }
445
445
  if (hasTypeExport("ModuleRuntimeMethods")) {
446
446
  const importName = hash(`${configKey}ModuleRuntimeMethods`);
@@ -1862,7 +1862,7 @@ async function prepareSchema(silgi) {
1862
1862
  addImportItemType,
1863
1863
  options: [],
1864
1864
  contexts: [],
1865
- actions: [],
1865
+ setupModuleOption: [],
1866
1866
  shareds: [],
1867
1867
  events: [],
1868
1868
  hooks: [],
@@ -1900,7 +1900,7 @@ async function prepareSchema(silgi) {
1900
1900
  }).join(",\n")}
1901
1901
  }` : "interface SilgiModuleEventsExtends {}",
1902
1902
  "",
1903
- `type RuntimeActionExtends = ${data.actions?.length ? data.actions.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
1903
+ `type SetupModuleOptionExtend = ${data.setupModuleOption?.length ? data.setupModuleOption.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
1904
1904
  "",
1905
1905
  `type RuntimeMethodExtends = ${data.methods?.length ? data.methods.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
1906
1906
  "",
@@ -1961,7 +1961,7 @@ async function prepareSchema(silgi) {
1961
1961
  SilgiRuntimeContext: [{}, { extends: ["SilgiModuleContextExtends"] }],
1962
1962
  SilgiEvent: [{}, { extends: ["SilgiModuleEventsExtends"] }],
1963
1963
  SilgiRuntimeSharedsExtend: [{}, { extends: ["SilgiModuleSharedExtends"] }],
1964
- SilgiRuntimeActions: [{}, { extends: ["RuntimeActionExtends"] }],
1964
+ SetupModuleOption: [{}, { extends: ["SetupModuleOptionExtend"] }],
1965
1965
  SilgiRuntimeOptions: [{}, { extends: ["SilgiRuntimeOptionExtends"] }],
1966
1966
  SilgiRuntimeHooks: [{}, { extends: ["SilgiRuntimeHooksExtends"] }],
1967
1967
  SilgiRuntimeConfig: [{}, { extends: ["SilgiRuntimeConfigExtends"] }],
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.38.0";
4
+ const version = "0.38.2";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -282,10 +282,10 @@ declare function useResponse<T extends ServerResponse>(event: SilgiEvent): Serve
282
282
  declare function getIpAddress(event: SilgiEvent): string | boolean;
283
283
  /**
284
284
  * Extract the client's IP address from request headers with high accuracy
285
- * @param req - The incoming HTTP request
285
+ * @param req - The incoming HTTP request (Fetch API Request)
286
286
  * @returns The client's IP address or empty string if not found
287
287
  */
288
- declare function ipAddress(req: IncomingMessage): string;
288
+ declare function ipAddress(req: Request): string;
289
289
 
290
290
  declare function relativeWithDot(from: string, to: string): string;
291
291
  declare function toArray<T>(value: T | T[]): T[];
@@ -940,12 +940,8 @@ function useResponse(event) {
940
940
  return event;
941
941
  }
942
942
  function getIpAddress(event) {
943
- const silgi = useSilgi();
944
- if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
945
- const _ipAddress = ipAddress(event.node.req);
946
- return _ipAddress;
947
- }
948
- return false;
943
+ const _ipAddress = ipAddress(event.req);
944
+ return _ipAddress;
949
945
  }
950
946
  function ipAddress(req) {
951
947
  const headers = [
@@ -981,13 +977,11 @@ function ipAddress(req) {
981
977
  // Used by some CDNs
982
978
  ];
983
979
  for (const header of headers) {
984
- const value = req.headers[header];
980
+ const value = req.headers.get(header);
985
981
  if (!value)
986
982
  continue;
987
983
  let ip;
988
- if (Array.isArray(value)) {
989
- ip = value[0];
990
- } else if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
984
+ if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
991
985
  ip = value.split(",")[0];
992
986
  } else if (header === "forwarded") {
993
987
  const match = value.match(/for=([^;]+)/);
@@ -1000,8 +994,7 @@ function ipAddress(req) {
1000
994
  return cleanIp;
1001
995
  }
1002
996
  }
1003
- const socketIp = req.socket.remoteAddress ?? "";
1004
- return socketIp && isValidIp(socketIp) ? socketIp : "";
997
+ return "";
1005
998
  }
1006
999
  function isValidIp(ip) {
1007
1000
  if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1")
@@ -357,7 +357,7 @@ type ServiceHandler<Schema extends SilgiSchema, Route extends keyof Schema, Meth
357
357
  interface ServiceSetup<Schema extends SilgiSchema = SilgiSchema, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], Resolved extends boolean = false, HiddenParameters extends boolean = false> {
358
358
  handler: ServiceHandler<Schema, Route, Method, Resolved, HiddenParameters>;
359
359
  rules?: RouteConfigService;
360
- modules?: Partial<SilgiRuntimeActions>;
360
+ modules?: Partial<SetupModuleOption>;
361
361
  storage?: StorageConfig<ServiceHandlerInput<Schema, Route, Method, HiddenParameters>>;
362
362
  }
363
363
  /**
@@ -395,7 +395,7 @@ type MiddlewareHandler<Response extends EventHandlerResponse = EventHandlerRespo
395
395
  interface MiddlewareSetup {
396
396
  handler: MiddlewareHandler;
397
397
  rules?: RouteRules;
398
- modules?: Partial<SilgiRuntimeActions>;
398
+ modules?: Partial<SetupModuleOption>;
399
399
  storage?: StorageConfig;
400
400
  }
401
401
  type MiddlewareDefinition = MiddlewareSetup;
@@ -513,7 +513,7 @@ interface ResolvedSilgiTemplate<Options = TemplateDefaultOptions> extends SilgiT
513
513
  modified?: boolean;
514
514
  }
515
515
 
516
- interface SilgiRuntimeActions {
516
+ interface SetupModuleOption {
517
517
  }
518
518
  interface SilgiModuleOptions {
519
519
  }
@@ -873,7 +873,7 @@ interface SilgiCLIHooks extends SilgiHooks {
873
873
  key: string;
874
874
  value: string;
875
875
  }[];
876
- actions: {
876
+ setupModuleOption: {
877
877
  key: string;
878
878
  value: string;
879
879
  }[];
@@ -1229,4 +1229,4 @@ interface LoadConfigOptions {
1229
1229
  consola?: ConsolaInstance;
1230
1230
  }
1231
1231
 
1232
- export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HookResult, HttpMethod, LoadConfigOptions, MergeAll, MergedSilgiSchema, MethodSchemas, MiddlewareDefinition, MiddlewareHandler, MiddlewareRoute, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, RouteConfig, RouteConfigService, RouteRules, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceHandlerOutput, ServiceHandlerSource, ServiceMethods, ServiceSetup, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiMeta, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
1232
+ export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HookResult, HttpMethod, LoadConfigOptions, MergeAll, MergedSilgiSchema, MethodSchemas, MiddlewareDefinition, MiddlewareHandler, MiddlewareRoute, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, RouteConfig, RouteConfigService, RouteRules, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceHandlerOutput, ServiceHandlerSource, ServiceMethods, ServiceSetup, SetupModuleOption, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiMeta, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.38.0",
4
+ "version": "0.38.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {