silgi 0.12.4 → 0.14.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/index.mjs +1 -1
- package/dist/cli/loader.mjs +1 -0
- package/dist/cli/writeTypesAndFiles.mjs +18 -8
- package/dist/core/index.mjs +0 -2
- package/dist/kit/index.d.mts +13 -1
- package/dist/kit/index.d.ts +13 -1
- package/dist/kit/index.mjs +82 -1
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/presets/nitro/preset.mjs +2 -1
- package/dist/presets/nuxt/preset.mjs +2 -1
- package/dist/types/index.d.mts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/loader.mjs
CHANGED
|
@@ -1387,7 +1387,6 @@ function useCLIRuntimeConfig(silgi) {
|
|
|
1387
1387
|
const _sharedRuntimeConfig = initRuntimeConfig(silgi.options.envOptions, silgi.options.runtimeConfig);
|
|
1388
1388
|
silgi.options.runtimeConfig = _sharedRuntimeConfig;
|
|
1389
1389
|
silgi.hook("prepare:configs.ts", (data) => {
|
|
1390
|
-
data.storage = silgi.options.storage;
|
|
1391
1390
|
data.runtimeConfig = _sharedRuntimeConfig;
|
|
1392
1391
|
silgi.options.envOptions = silgi.options.envOptions;
|
|
1393
1392
|
});
|
|
@@ -1756,7 +1755,11 @@ async function prepareFramework(silgi) {
|
|
|
1756
1755
|
const importItems = {
|
|
1757
1756
|
"silgi/types": {
|
|
1758
1757
|
import: [
|
|
1759
|
-
{
|
|
1758
|
+
{
|
|
1759
|
+
name: "SilgiRuntimeContext",
|
|
1760
|
+
type: true,
|
|
1761
|
+
key: "SilgiRuntimeContext"
|
|
1762
|
+
}
|
|
1760
1763
|
],
|
|
1761
1764
|
from: "silgi/types"
|
|
1762
1765
|
}
|
|
@@ -1781,7 +1784,11 @@ async function createDTSFramework(silgi) {
|
|
|
1781
1784
|
const importItems = {
|
|
1782
1785
|
"silgi/types": {
|
|
1783
1786
|
import: [
|
|
1784
|
-
{
|
|
1787
|
+
{
|
|
1788
|
+
name: "SilgiRuntimeContext",
|
|
1789
|
+
type: true,
|
|
1790
|
+
key: "SilgiRuntimeContext"
|
|
1791
|
+
}
|
|
1785
1792
|
],
|
|
1786
1793
|
from: "silgi/types"
|
|
1787
1794
|
}
|
|
@@ -1996,11 +2003,14 @@ async function prepareSchema(silgi) {
|
|
|
1996
2003
|
"",
|
|
1997
2004
|
silgi.options.typescript.generateRuntimeConfigTypes ? generateTypes(
|
|
1998
2005
|
await resolveSchema(
|
|
1999
|
-
|
|
2000
|
-
Object.
|
|
2001
|
-
(
|
|
2002
|
-
|
|
2003
|
-
|
|
2006
|
+
{
|
|
2007
|
+
...Object.fromEntries(
|
|
2008
|
+
Object.entries(silgi.options.runtimeConfig).filter(
|
|
2009
|
+
([key]) => !["app", "nitro", "nuxt"].includes(key)
|
|
2010
|
+
)
|
|
2011
|
+
),
|
|
2012
|
+
...silgi.options.storages
|
|
2013
|
+
}
|
|
2004
2014
|
),
|
|
2005
2015
|
{
|
|
2006
2016
|
interfaceName: "SilgiRuntimeConfigExtends",
|
package/dist/core/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { getContext } from 'unctx';
|
|
|
5
5
|
import { Buffer } from 'node:buffer';
|
|
6
6
|
import { klona } from 'klona';
|
|
7
7
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
8
|
-
import memoryDriver from 'unstorage/drivers/memory';
|
|
9
8
|
|
|
10
9
|
const silgiCtx = getContext("silgi");
|
|
11
10
|
function useSilgi() {
|
|
@@ -423,7 +422,6 @@ async function createStorage(silgi) {
|
|
|
423
422
|
for (const [path, opts] of Object.entries(mounts)) {
|
|
424
423
|
if (opts.driver) {
|
|
425
424
|
const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
|
|
426
|
-
storage.mount("/memory:cache", memoryDriver());
|
|
427
425
|
storage.mount(path, driver(opts));
|
|
428
426
|
} else {
|
|
429
427
|
silgi.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPres
|
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
5
|
+
import { IncomingMessage } from 'node:http';
|
|
5
6
|
|
|
6
7
|
declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
|
|
7
8
|
|
|
@@ -93,6 +94,17 @@ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedS
|
|
|
93
94
|
*/
|
|
94
95
|
declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
|
|
95
96
|
|
|
97
|
+
declare function useRequest(event: SilgiEvents): false | (IncomingMessage & {
|
|
98
|
+
originalUrl?: string;
|
|
99
|
+
});
|
|
100
|
+
declare function getIpAddress(event: SilgiEvents): string | false;
|
|
101
|
+
/**
|
|
102
|
+
* Extract the client's IP address from request headers with high accuracy
|
|
103
|
+
* @param req - The incoming HTTP request
|
|
104
|
+
* @returns The client's IP address or empty string if not found
|
|
105
|
+
*/
|
|
106
|
+
declare function ipAddress(req: IncomingMessage): string;
|
|
107
|
+
|
|
96
108
|
declare function relativeWithDot(from: string, to: string): string;
|
|
97
109
|
/** @since 3.9.0 */
|
|
98
110
|
declare function toArray<T>(value: T | T[]): T[];
|
|
@@ -113,4 +125,4 @@ declare const MODE_RE: RegExp;
|
|
|
113
125
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
114
126
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
115
127
|
|
|
116
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
|
128
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPres
|
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
5
|
+
import { IncomingMessage } from 'node:http';
|
|
5
6
|
|
|
6
7
|
declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
|
|
7
8
|
|
|
@@ -93,6 +94,17 @@ declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedS
|
|
|
93
94
|
*/
|
|
94
95
|
declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
|
|
95
96
|
|
|
97
|
+
declare function useRequest(event: SilgiEvents): false | (IncomingMessage & {
|
|
98
|
+
originalUrl?: string;
|
|
99
|
+
});
|
|
100
|
+
declare function getIpAddress(event: SilgiEvents): string | false;
|
|
101
|
+
/**
|
|
102
|
+
* Extract the client's IP address from request headers with high accuracy
|
|
103
|
+
* @param req - The incoming HTTP request
|
|
104
|
+
* @returns The client's IP address or empty string if not found
|
|
105
|
+
*/
|
|
106
|
+
declare function ipAddress(req: IncomingMessage): string;
|
|
107
|
+
|
|
96
108
|
declare function relativeWithDot(from: string, to: string): string;
|
|
97
109
|
/** @since 3.9.0 */
|
|
98
110
|
declare function toArray<T>(value: T | T[]): T[];
|
|
@@ -113,4 +125,4 @@ declare const MODE_RE: RegExp;
|
|
|
113
125
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
114
126
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
115
127
|
|
|
116
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
|
128
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -413,4 +413,85 @@ function normalizeTemplate(template, buildDir) {
|
|
|
413
413
|
return template;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
-
|
|
416
|
+
function useRequest(event) {
|
|
417
|
+
const silgi = useSilgi();
|
|
418
|
+
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
419
|
+
return event.node.req;
|
|
420
|
+
}
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
function getIpAddress(event) {
|
|
424
|
+
const silgi = useSilgi();
|
|
425
|
+
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
426
|
+
const _ipAddress = ipAddress(event.node.req);
|
|
427
|
+
return _ipAddress;
|
|
428
|
+
}
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
function ipAddress(req) {
|
|
432
|
+
const headers = [
|
|
433
|
+
"cf-connecting-ip",
|
|
434
|
+
// Cloudflare
|
|
435
|
+
"true-client-ip",
|
|
436
|
+
// Akamai and Cloudflare
|
|
437
|
+
"x-real-ip",
|
|
438
|
+
// Nginx proxy/FastCGI
|
|
439
|
+
"x-forwarded-for",
|
|
440
|
+
// Standard proxy header
|
|
441
|
+
"x-client-ip",
|
|
442
|
+
// Apache
|
|
443
|
+
"x-forwarded",
|
|
444
|
+
// Alternative format
|
|
445
|
+
"forwarded",
|
|
446
|
+
// RFC 7239 compliant format
|
|
447
|
+
"forwarded-for",
|
|
448
|
+
// RFC 7239 variant
|
|
449
|
+
"x-appengine-user-ip",
|
|
450
|
+
// Google App Engine
|
|
451
|
+
"x-cluster-client-ip",
|
|
452
|
+
// GCP load balancer
|
|
453
|
+
"fastly-client-ip",
|
|
454
|
+
// Fastly CDN
|
|
455
|
+
"x-azure-clientip",
|
|
456
|
+
// Azure
|
|
457
|
+
"x-original-forwarded-for",
|
|
458
|
+
// Secondary forwarded-for header
|
|
459
|
+
"x-lb-forwarded-for",
|
|
460
|
+
// Load balancer specific
|
|
461
|
+
"cdn-loop"
|
|
462
|
+
// Used by some CDNs
|
|
463
|
+
];
|
|
464
|
+
for (const header of headers) {
|
|
465
|
+
const value = req.headers[header];
|
|
466
|
+
if (!value)
|
|
467
|
+
continue;
|
|
468
|
+
let ip;
|
|
469
|
+
if (Array.isArray(value)) {
|
|
470
|
+
ip = value[0];
|
|
471
|
+
} else if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
|
|
472
|
+
ip = value.split(",")[0];
|
|
473
|
+
} else if (header === "forwarded") {
|
|
474
|
+
const match = value.match(/for=([^;]+)/);
|
|
475
|
+
ip = match ? match[1].trim().replace(/^\[|\]$/g, "") : "";
|
|
476
|
+
} else {
|
|
477
|
+
ip = value;
|
|
478
|
+
}
|
|
479
|
+
const cleanIp = ip.trim();
|
|
480
|
+
if (cleanIp && isValidIp(cleanIp)) {
|
|
481
|
+
return cleanIp;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const socketIp = req.socket.remoteAddress ?? "";
|
|
485
|
+
return socketIp && isValidIp(socketIp) ? socketIp : "";
|
|
486
|
+
}
|
|
487
|
+
function isValidIp(ip) {
|
|
488
|
+
if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1")
|
|
489
|
+
return true;
|
|
490
|
+
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip))
|
|
491
|
+
return true;
|
|
492
|
+
if (/^[0-9a-f:]+$/i.test(ip))
|
|
493
|
+
return true;
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, useSilgiRuntimeConfig, writeFile };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -569,6 +569,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
569
569
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
570
570
|
[key: string]: any;
|
|
571
571
|
};
|
|
572
|
+
storages: string[];
|
|
572
573
|
namespaces: string[];
|
|
573
574
|
hooks: NestedHooks<SilgiCLIHooks$1>;
|
|
574
575
|
plugins: {
|
|
@@ -902,7 +903,7 @@ interface SilgiStorageBase {
|
|
|
902
903
|
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
903
904
|
interface StorageConfig<TInput> {
|
|
904
905
|
options: TransactionOptions;
|
|
905
|
-
base: '
|
|
906
|
+
base: 'memory' | keyof SilgiStorageBase;
|
|
906
907
|
key?: StorageKeyGenerator<TInput>;
|
|
907
908
|
scope?: 'request' | 'global';
|
|
908
909
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -569,6 +569,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
569
569
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
570
570
|
[key: string]: any;
|
|
571
571
|
};
|
|
572
|
+
storages: string[];
|
|
572
573
|
namespaces: string[];
|
|
573
574
|
hooks: NestedHooks<SilgiCLIHooks$1>;
|
|
574
575
|
plugins: {
|
|
@@ -902,7 +903,7 @@ interface SilgiStorageBase {
|
|
|
902
903
|
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
903
904
|
interface StorageConfig<TInput> {
|
|
904
905
|
options: TransactionOptions;
|
|
905
|
-
base: '
|
|
906
|
+
base: 'memory' | keyof SilgiStorageBase;
|
|
906
907
|
key?: StorageKeyGenerator<TInput>;
|
|
907
908
|
scope?: 'request' | 'global';
|
|
908
909
|
}
|