silgi 0.24.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { defineCommand, runMain } from 'citty';
2
2
 
3
- const version = "0.24.0";
3
+ const version = "0.24.1";
4
4
  const packageJson = {
5
5
  version: version};
6
6
 
@@ -1 +1,2 @@
1
- export { resolvePreset } from "./_resolve";
1
+ export { resolvePreset } from './_resolve';
2
+ export type { PresetName, PresetNameInput, PresetOptions } from './_types.gen';
@@ -1 +1 @@
1
- export { resolvePreset } from './_resolve.mjs'
1
+ export { resolvePreset } from "./_resolve.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.24.0",
4
+ "version": "0.24.1",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -1,11 +0,0 @@
1
- import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI } from 'silgi/types';
2
- import { TSConfig } from 'pkg-types';
3
-
4
- declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
5
-
6
- declare function silgiGenerateType(silgi: SilgiCLI): Promise<{
7
- declarations: string[];
8
- tsConfig: TSConfig;
9
- }>;
10
-
11
- export { loadOptions, silgiGenerateType };
@@ -1,2 +0,0 @@
1
-
2
- export { };
package/dist/index.d.ts DELETED
@@ -1,268 +0,0 @@
1
- import { SilgiConfig, Silgi, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiEvents, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiCLI, SilgiStorageBase } from 'silgi/types';
2
- export { s as silgi } from './shared/silgi.Cs0ZUUXV.js';
3
- import { StandardSchemaV1 } from '@standard-schema/spec';
4
- import { Storage, StorageValue } from 'unstorage';
5
- import * as unctx from 'unctx';
6
-
7
- declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
8
-
9
- interface RouteTemplateValidator {
10
- (value: string): boolean;
11
- }
12
- interface RouteTemplateConfig {
13
- pattern: string;
14
- validators?: Record<string, RouteTemplateValidator>;
15
- }
16
- type URITemplate = string | RouteTemplateConfig;
17
- declare function parseURI(uri: string, uris: Record<string, URITemplate>): SilgiOperation;
18
-
19
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
20
- declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
21
- declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
22
- declare function mergeShared<T extends SilgiRuntimeSharedsExtend[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
23
-
24
- declare function getEvent<T extends SilgiEvents>(event?: SilgiEvents): T;
25
- declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEvents): T;
26
-
27
- declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>>>>(silgiType: T): {
28
- [K in keyof T]: {
29
- [P in keyof T[K]]: T[K][P];
30
- };
31
- };
32
-
33
- declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
34
-
35
- declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
36
-
37
- /**
38
- * Recursively replaces values starting with 'runtime.' with their actual values from runtime config
39
- */
40
- declare function replaceRuntimeValues(obj: any, runtime: any): any;
41
-
42
- declare function createStorage(silgi: Silgi): Promise<Storage<StorageValue>>;
43
- declare function useSilgiStorage<T extends StorageValue = StorageValue>(base?: StorageConfig<T>['base'] | (string & {})): Storage<T>;
44
-
45
- declare enum HttpStatus {
46
- /** [100] Server has received the request headers and client should proceed to send the request body */
47
- CONTINUE = 100,
48
- /** [101] Server is switching protocols according to Upgrade header */
49
- SWITCHING_PROTOCOLS = 101,
50
- /** [102] Server is processing the request but no response is available yet */
51
- PROCESSING = 102,
52
- /** [103] Server is likely to send a final response with the header fields in the informational response */
53
- EARLY_HINTS = 103,
54
- /** [200] Request succeeded and response contains requested data */
55
- OK = 200,
56
- /** [201] Request succeeded and new resource has been created */
57
- CREATED = 201,
58
- /** [202] Request accepted for processing but processing not completed */
59
- ACCEPTED = 202,
60
- /** [203] Request processed successfully but response may be from another source */
61
- NON_AUTHORITATIVE_INFORMATION = 203,
62
- /** [204] Request processed successfully but response has no content */
63
- NO_CONTENT = 204,
64
- /** [205] Server fulfilled the request and client should reset the document view */
65
- RESET_CONTENT = 205,
66
- /** [206] Server delivered only part of the resource due to range header */
67
- PARTIAL_CONTENT = 206,
68
- /** [207] Response conveys information about multiple resources for XML messages */
69
- MULTI_STATUS = 207,
70
- /** [208] Members of DAV binding have already been enumerated and not included again */
71
- ALREADY_REPORTED = 208,
72
- /** [226] Server has fulfilled a GET request, response is result of transformations */
73
- IM_USED = 226,
74
- /** [300] Multiple options for the resource from which client may choose */
75
- MULTIPLE_CHOICES = 300,
76
- /** [301] Resource permanently moved to new URL */
77
- MOVED_PERMANENTLY = 301,
78
- /** [302] Resource temporarily moved to different URL */
79
- FOUND = 302,
80
- /** [303] Response to request found at another URL using GET */
81
- SEE_OTHER = 303,
82
- /** [304] Resource has not been modified since last requested */
83
- NOT_MODIFIED = 304,
84
- /** [305] Deprecated. Resource must be accessed through proxy */
85
- USE_PROXY = 305,
86
- /** [307] Resource temporarily moved to different URL, keep method */
87
- TEMPORARY_REDIRECT = 307,
88
- /** [308] Resource permanently moved to different URL, keep method */
89
- PERMANENT_REDIRECT = 308,
90
- /** [400] Request malformed, syntax error or invalid request */
91
- BAD_REQUEST = 400,
92
- /** [401] Request requires user authentication or authorization */
93
- UNAUTHORIZED = 401,
94
- /** [402] Reserved for future use, payment required */
95
- PAYMENT_REQUIRED = 402,
96
- /** [403] Server understood request but refuses to authorize it */
97
- FORBIDDEN = 403,
98
- /** [404] Server cannot find the requested resource */
99
- NOT_FOUND = 404,
100
- /** [405] Request method (GET, POST, etc.) not supported for this resource */
101
- METHOD_NOT_ALLOWED = 405,
102
- /** [406] Resource cannot generate response matching accept headers */
103
- NOT_ACCEPTABLE = 406,
104
- /** [407] Client must first authenticate with the proxy */
105
- PROXY_AUTHENTICATION_REQUIRED = 407,
106
- /** [408] Server timed out waiting for the request */
107
- REQUEST_TIMEOUT = 408,
108
- /** [409] Request conflicts with current state of the server */
109
- CONFLICT = 409,
110
- /** [410] Resource requested is no longer available and will not be available again */
111
- GONE = 410,
112
- /** [411] Server requires Content-Length header field */
113
- LENGTH_REQUIRED = 411,
114
- /** [412] Precondition given in request headers evaluated to false */
115
- PRECONDITION_FAILED = 412,
116
- /** [413] Request entity larger than limits defined by server */
117
- PAYLOAD_TOO_LARGE = 413,
118
- /** [414] URI requested by client is longer than server can interpret */
119
- URI_TOO_LONG = 414,
120
- /** [415] Media format of requested data not supported by server */
121
- UNSUPPORTED_MEDIA_TYPE = 415,
122
- /** [416] Range specified by Range header cannot be fulfilled */
123
- RANGE_NOT_SATISFIABLE = 416,
124
- /** [417] Expectation indicated by Expect header cannot be met */
125
- EXPECTATION_FAILED = 417,
126
- /** [418] April Fools' joke by RFC 2324 - Server refuses to brew coffee in a teapot */
127
- IM_A_TEAPOT = 418,
128
- /** [421] Request directed at a server that is not configured to produce a response */
129
- MISDIRECTED_REQUEST = 421,
130
- /** [422] Server understands content type but cannot process contained instructions */
131
- UNPROCESSABLE_ENTITY = 422,
132
- /** [423] Requested resource is currently locked */
133
- LOCKED = 423,
134
- /** [424] Request failed due to failure of a previous request */
135
- FAILED_DEPENDENCY = 424,
136
- /** [425] Server is unwilling to risk processing a request that might be replayed */
137
- TOO_EARLY = 425,
138
- /** [426] Server requires client to upgrade to a different protocol */
139
- UPGRADE_REQUIRED = 426,
140
- /** [428] Origin server requires request to be conditional */
141
- PRECONDITION_REQUIRED = 428,
142
- /** [429] User has sent too many requests in a given time period */
143
- TOO_MANY_REQUESTS = 429,
144
- /** [431] Server refusing to process request due to oversized headers */
145
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
146
- /** [451] Server denies access for legal reasons (e.g., censorship) */
147
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
148
- /** [500] Generic server error, no specific message */
149
- INTERNAL_SERVER_ERROR = 500,
150
- /** [501] Server does not recognize method or lacks ability to fulfill */
151
- NOT_IMPLEMENTED = 501,
152
- /** [502] Bad response received from upstream server */
153
- BAD_GATEWAY = 502,
154
- /** [503] Server temporarily unavailable (overloaded/maintenance) */
155
- SERVICE_UNAVAILABLE = 503,
156
- /** [504] Gateway server did not get response from upstream server */
157
- GATEWAY_TIMEOUT = 504,
158
- /** [505] Server does not support the HTTP protocol version */
159
- HTTP_VERSION_NOT_SUPPORTED = 505,
160
- /** [506] Server has a circular reference in content negotiation */
161
- VARIANT_ALSO_NEGOTIATES = 506,
162
- /** [507] Server has insufficient storage to complete request */
163
- INSUFFICIENT_STORAGE = 507,
164
- /** [508] Server detected an infinite loop while processing request */
165
- LOOP_DETECTED = 508,
166
- /** [510] Further extensions needed for server to fulfill request */
167
- NOT_EXTENDED = 510,
168
- /** [511] Client needs to authenticate to gain network access */
169
- NETWORK_AUTHENTICATION_REQUIRED = 511
170
- }
171
- declare enum ErrorSeverity {
172
- DEBUG = "DEBUG",
173
- INFO = "INFO",
174
- WARNING = "WARNING",
175
- ERROR = "ERROR",
176
- CRITICAL = "CRITICAL"
177
- }
178
- declare enum ErrorCategory {
179
- AUTHENTICATION = "auth",
180
- AUTHORIZATION = "authorization",
181
- VALIDATION = "validation",
182
- BUSINESS = "business",
183
- INFRASTRUCTURE = "infrastructure",
184
- EXTERNAL = "external",
185
- UNKNOWN = "unknown"
186
- }
187
- interface ErrorMetadata {
188
- timestamp: number;
189
- correlationId?: string;
190
- requestId?: string;
191
- userId?: string;
192
- path?: string;
193
- source?: string;
194
- [key: string]: unknown;
195
- }
196
- interface BaseError {
197
- code: number;
198
- message: string;
199
- category: ErrorCategory;
200
- severity: ErrorSeverity;
201
- httpStatus: HttpStatus;
202
- metadata?: ErrorMetadata;
203
- cause?: Error;
204
- context?: Record<string, unknown>;
205
- }
206
- declare class ErrorFactory {
207
- private static createMetadata;
208
- static create(options: Partial<BaseError> & {
209
- message: string;
210
- }): SilgiError;
211
- static authenticationError(message: string, context?: Record<string, unknown>): SilgiError;
212
- static authorizationError(message: string, context?: Record<string, unknown>): SilgiError;
213
- static validationError(message: string, context?: Record<string, unknown>): SilgiError;
214
- static notFoundError(message: string, context?: Record<string, unknown>): SilgiError;
215
- static internalError(message: string, cause?: Error): SilgiError;
216
- }
217
- declare class SilgiError extends Error implements BaseError {
218
- readonly code: number;
219
- readonly category: ErrorCategory;
220
- readonly severity: ErrorSeverity;
221
- readonly httpStatus: HttpStatus;
222
- readonly metadata: ErrorMetadata;
223
- readonly context?: Record<string, unknown>;
224
- readonly cause?: Error;
225
- constructor(error: BaseError);
226
- toString(): string;
227
- toJSON(): Record<string, unknown>;
228
- static isError(error: unknown): error is SilgiError;
229
- static from(error: unknown): SilgiError;
230
- }
231
- declare function isBaseError(error: unknown): error is BaseError;
232
-
233
- declare const silgiCtx: unctx.UseContext<Silgi>;
234
- declare function useSilgi(): Silgi;
235
- /**
236
- * Get access to Nuxt instance.
237
- *
238
- * Returns null if Nuxt instance is unavailable.
239
- * @example
240
- * ```js
241
- * const silgi = tryUseSilgi()
242
- * if (silgi) {
243
- * // Do something
244
- * }
245
- * ```
246
- */
247
- declare function tryUseSilgi(): Silgi | null;
248
-
249
- declare const silgiCLICtx: unctx.UseContext<SilgiCLI>;
250
- declare function useSilgiCLI(): SilgiCLI;
251
- /**
252
- * Get access to Nuxt instance.
253
- *
254
- * Returns null if Nuxt instance is unavailable.
255
- * @example
256
- * ```js
257
- * const silgi = tryUseSilgi()
258
- * if (silgi) {
259
- * // Do something
260
- * }
261
- * ```
262
- */
263
- declare function tryUseSilgiCLI(): SilgiCLI | null;
264
-
265
- declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base: keyof SilgiStorageBase, driver: Parameters<Storage['mount']>[1]) => T;
266
-
267
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, replaceRuntimeValues, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
268
- export type { BaseError, ErrorMetadata };
@@ -1,152 +0,0 @@
1
- import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
2
- import { Buffer } from 'node:buffer';
3
- import * as consola from 'consola';
4
- import { ConsolaOptions } from 'consola';
5
- import { IncomingMessage, ServerResponse } from 'node:http';
6
-
7
- declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
8
-
9
- declare function directoryToURL(dir: string): URL;
10
- /**
11
- * Resolve a module from a given root path using an algorithm patterned on
12
- * the upcoming `import.meta.resolve`. It returns a file URL
13
- *
14
- * @internal
15
- */
16
- declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
17
-
18
- declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
19
- declare function isDirectory(path: string): Promise<boolean>;
20
-
21
- declare function genEnsureSafeVar(name: string | any): string;
22
- declare function getAllEntries(obj: object): [string, any][];
23
-
24
- declare function hash(data: any): string;
25
-
26
- declare function isNuxt(): boolean;
27
- declare function isNitro(): boolean;
28
- declare function isH3(): boolean;
29
-
30
- declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
31
-
32
- /**
33
- * Define a Silgi module, automatically merging defaults with user provided options, installing
34
- * any hooks that are provided, and calling an optional setup function for full control.
35
- */
36
- declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(definition: ModuleDefinition<TOptions, Partial<TOptions>, false> | SilgiModule<TOptions, Partial<TOptions>, false>): SilgiModule<TOptions, TOptions, false>;
37
- declare function defineSilgiModule<TOptions extends ModuleOptionsCustom>(): {
38
- with: <TOptionsDefaults extends Partial<TOptions>>(definition: ModuleDefinition<TOptions, TOptionsDefaults, true> | SilgiModule<TOptions, TOptionsDefaults, true>) => SilgiModule<TOptions, TOptionsDefaults, true>;
39
- };
40
-
41
- /**
42
- *
43
- *
44
- * @example
45
- * srnResorce: 'coreApi.basket.post.createBasket'
46
- * const { namespace, serviceName, action, method } = cliResorceParse(srnResorce)
47
- *
48
- * namespace: 'coreApi'
49
- * serviceName: 'basket'
50
- * action: 'post'
51
- * method: 'createBasket'
52
- *
53
- */
54
-
55
- declare function serviceParseModule(params: ServiceParseModule): ServiceParseModule;
56
- declare function parseServices(silgi: SilgiCLI,
57
- /**
58
- * url: /coreApi/basket/post/createBasket
59
- * pathLength: 4 or [1, 2, 3, 4] to support multiple path depths
60
- * 1: coreApi
61
- * 2: basket
62
- * 3: post
63
- * 4: createBasket
64
- */
65
- pathLength?: number | number[], servicesObject?: Record<string, any>, currentPath?: string[]): Record<string, Record<string, any>>;
66
-
67
- declare function prettyPath(p: string, highlight?: boolean): string;
68
- declare function resolveSilgiPath(path: string, silgiCLIOptions: SilgiCLI['options'], base?: string): string;
69
-
70
- declare function defineSilgiPreset<P extends SilgiPreset, M extends SilgiPresetMeta>(preset: P, meta?: M): P & {
71
- _meta: SilgiPresetMeta;
72
- };
73
-
74
- interface ResolvePathOptions {
75
- modulesDir?: string[];
76
- /** Base for resolving paths from. Default is Nuxt rootDir. */
77
- cwd?: string;
78
- /** An object of aliases. Default is Nuxt configured aliases. */
79
- alias?: Record<string, string>;
80
- /** The file extensions to try. Default is Nuxt configured extensions. */
81
- extensions?: string[];
82
- /**
83
- * Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path.
84
- *
85
- * @default false
86
- */
87
- fallbackToOriginal?: boolean;
88
- }
89
- /**
90
- * Resolve full path to a file or directory respecting Nuxt alias and extensions options
91
- *
92
- * If path could not be resolved, normalized input path will be returned
93
- */
94
- declare function resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
95
- /**
96
- * Resolve path aliases respecting Nuxt alias options
97
- */
98
- declare function resolveAlias(path: string, alias?: Record<string, string>): string;
99
- interface Resolver {
100
- resolve: (...path: string[]) => string;
101
- resolvePath: (path: string, opts?: ResolvePathOptions) => Promise<string>;
102
- }
103
- /**
104
- * Create a relative resolver
105
- */
106
- declare function createResolver(base: string | URL): Resolver;
107
- declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
108
-
109
- /**
110
- * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
111
- */
112
- declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedSilgiTemplate<T>;
113
- /**
114
- * Normalize a silgi template object
115
- */
116
- declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
117
-
118
- declare function useRequest<T extends IncomingMessage>(event: SilgiEvents): T | (IncomingMessage & {
119
- originalUrl?: string;
120
- });
121
- declare function useResponse<T extends ServerResponse>(event: SilgiEvents): ServerResponse<IncomingMessage>;
122
- declare function getIpAddress(event: SilgiEvents): string | false;
123
- /**
124
- * Extract the client's IP address from request headers with high accuracy
125
- * @param req - The incoming HTTP request
126
- * @returns The client's IP address or empty string if not found
127
- */
128
- declare function ipAddress(req: IncomingMessage): string;
129
-
130
- declare function relativeWithDot(from: string, to: string): string;
131
- /** @since 3.9.0 */
132
- declare function toArray<T>(value: T | T[]): T[];
133
- /**
134
- * Filter out items from an array in place. This function mutates the array.
135
- * `predicate` get through the array from the end to the start for performance.
136
- *
137
- * This function should be faster than `Array.prototype.filter` on large arrays.
138
- */
139
- declare function filterInPlace<T>(array: T[], predicate: (item: T, index: number, arr: T[]) => unknown): T[];
140
- declare const MODE_RE: RegExp;
141
- /**
142
- * Check if a Silgi module is installed by name.
143
- *
144
- * This will check both the installed modules and the modules to be installed. Note
145
- * that it cannot detect if a module is _going to be_ installed programmatically by another module.
146
- */
147
- declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
148
- declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
149
- declare const baseHeaderBannerComment: string[];
150
- declare function processFilePath(src: string): string;
151
-
152
- export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
@@ -1,2 +0,0 @@
1
- export { resolvePreset } from './_resolve';
2
- export type { PresetName, PresetNameInput, PresetOptions } from './_types.gen';
@@ -1,7 +0,0 @@
1
- import { SilgiEvents, SilgiURIs, ExtractInputFromURI, ExtractSourceFromURI, ExtractOutputFromURI } from 'silgi/types';
2
-
3
- declare function silgi(event?: SilgiEvents | Record<string, any>): {
4
- execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>, source?: ExtractSourceFromURI<TURI>, queryParams?: Record<string, string>) => Promise<ExtractOutputFromURI<TURI>>;
5
- };
6
-
7
- export { silgi as s };