silgi 0.7.1 → 0.7.3
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 +5 -0
- package/dist/cli/{utils/compatibility.mjs → compatibility.mjs} +1 -1
- package/dist/cli/config/index.d.mts +11 -0
- package/dist/cli/config/index.d.ts +11 -0
- package/dist/{core/config/types.mjs → cli/config/index.mjs} +19 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/loader.mjs +581 -0
- package/dist/cli/prepare.mjs +1621 -0
- package/dist/core/index.d.mts +2 -37
- package/dist/core/index.d.ts +2 -37
- package/dist/core/index.mjs +809 -16
- package/dist/ecosystem/nitro/index.mjs +62 -1
- package/dist/ecosystem/nuxt/module.mjs +1 -1
- package/dist/kit/index.mjs +299 -10
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/meta/index.mjs +1 -1
- package/package.json +5 -1
- package/dist/cli/build/framework/h3.mjs +0 -46
- package/dist/cli/build/framework/index.mjs +0 -7
- package/dist/cli/build/framework/nitro.mjs +0 -28
- package/dist/cli/build/framework/nuxt.mjs +0 -9
- package/dist/cli/build/prepare.mjs +0 -7
- package/dist/cli/build/scanURIs.mjs +0 -27
- package/dist/cli/build/template/framework.mjs +0 -91
- package/dist/cli/build/template/schema.mjs +0 -115
- package/dist/cli/build/template/silgi.mjs +0 -149
- package/dist/cli/build/types.mjs +0 -130
- package/dist/cli/commands/prepare.mjs +0 -49
- package/dist/cli/common.mjs +0 -13
- package/dist/cli/core/app.mjs +0 -89
- package/dist/cli/core/scan.mjs +0 -40
- package/dist/cli/core/silgi.mjs +0 -77
- package/dist/cli/core/storage.mjs +0 -11
- package/dist/cli/core/templates.mjs +0 -29
- package/dist/cli/module/exportScan.mjs +0 -69
- package/dist/cli/module/install.mjs +0 -52
- package/dist/cli/module/scan.mjs +0 -141
- package/dist/cli/utils/generateRouterDTS.mjs +0 -84
- package/dist/cli/utils/ignore.mjs +0 -46
- package/dist/cli/utils/readCoreFile.mjs +0 -47
- package/dist/cli/utils/scan.mjs +0 -147
- package/dist/cli/utils/storage.mjs +0 -21
- package/dist/cli/utils/uri.mjs +0 -71
- package/dist/core/config/defaults.mjs +0 -96
- package/dist/core/config/loader.mjs +0 -98
- package/dist/core/config/resolvers/compatibility.mjs +0 -90
- package/dist/core/config/resolvers/imports.mjs +0 -96
- package/dist/core/config/resolvers/paths.mjs +0 -194
- package/dist/core/config/resolvers/storage.mjs +0 -25
- package/dist/core/config/resolvers/url.mjs +0 -7
- package/dist/core/createSilgi.mjs +0 -84
- package/dist/core/error.mjs +0 -227
- package/dist/core/fetch/ofetch.mjs +0 -35
- package/dist/core/parser.mjs +0 -136
- package/dist/core/silgi.mjs +0 -114
- package/dist/core/silgiApp.mjs +0 -15
- package/dist/core/unctx.mjs +0 -27
- package/dist/core/uris/uri.mjs +0 -33
- package/dist/core/uris/utils.mjs +0 -127
- package/dist/core/utils/event.mjs +0 -5
- package/dist/core/utils/global.mjs +0 -12
- package/dist/core/utils/merge.mjs +0 -25
- package/dist/core/utils/schema.mjs +0 -5
- package/dist/core/utils/service.mjs +0 -5
- package/dist/core/utils/shared.mjs +0 -5
- package/dist/core/utils/storage.mjs +0 -70
- package/dist/ecosystem/nitro/module.mjs +0 -62
- package/dist/kit/esm.mjs +0 -10
- package/dist/kit/fs.mjs +0 -25
- package/dist/kit/isFramework.mjs +0 -25
- package/dist/kit/logger.mjs +0 -8
- package/dist/kit/module.mjs +0 -73
- package/dist/kit/path.mjs +0 -34
- package/dist/kit/preset.mjs +0 -6
- package/dist/kit/resolve.mjs +0 -78
- package/dist/kit/template.mjs +0 -47
- package/dist/kit/utils.mjs +0 -20
- package/dist/package.json.mjs +0 -5
- package/dist/schema/common.mjs +0 -43
- package/dist/schema/index.mjs +0 -9
- package/dist/schema/internal.mjs +0 -22
- /package/dist/cli/{commands/init.mjs → init.mjs} +0 -0
package/dist/core/index.mjs
CHANGED
|
@@ -1,16 +1,809 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { createConsola } from 'consola';
|
|
2
|
+
import defu from 'defu';
|
|
3
|
+
import { isEvent } from 'h3';
|
|
4
|
+
import { createHooks } from 'hookable';
|
|
5
|
+
import { defineUntypedSchema, applyDefaults } from 'untyped';
|
|
6
|
+
import { isDebug, isTest, isDevelopment } from 'std-env';
|
|
7
|
+
import { getContext } from 'unctx';
|
|
8
|
+
import { Buffer } from 'node:buffer';
|
|
9
|
+
import { klona } from 'klona';
|
|
10
|
+
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
11
|
+
import memoryDriver from 'unstorage/drivers/memory';
|
|
12
|
+
|
|
13
|
+
const common = defineUntypedSchema({
|
|
14
|
+
/**
|
|
15
|
+
* Environment to use.
|
|
16
|
+
*
|
|
17
|
+
* @default 'h3'
|
|
18
|
+
*/
|
|
19
|
+
environment: {
|
|
20
|
+
$resolve: (val) => val ?? "h3"
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Whether Nuxt is running in development mode.
|
|
24
|
+
*
|
|
25
|
+
* Normally, you should not need to set this.
|
|
26
|
+
*/
|
|
27
|
+
dev: {
|
|
28
|
+
$resolve: (val) => val ?? Boolean(isDevelopment)
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Whether your app is being unit tested.
|
|
32
|
+
*/
|
|
33
|
+
test: {
|
|
34
|
+
$resolve: (val) => val ?? Boolean(isTest)
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Set to `true` to enable debug mode.
|
|
38
|
+
*
|
|
39
|
+
* At the moment, it prints out hook names and timings on the server, and
|
|
40
|
+
* logs hook arguments as well in the browser.
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
debug: {
|
|
44
|
+
$resolve: (val) => val ?? isDebug
|
|
45
|
+
},
|
|
46
|
+
plugins: {
|
|
47
|
+
$resolve: (val) => (val || []).filter(Boolean)
|
|
48
|
+
},
|
|
49
|
+
$schema: {}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const internal = defineUntypedSchema({
|
|
53
|
+
/** @private */
|
|
54
|
+
_majorVersion: 4,
|
|
55
|
+
/** @private */
|
|
56
|
+
_generate: false,
|
|
57
|
+
/** @private */
|
|
58
|
+
_prepare: false,
|
|
59
|
+
/** @private */
|
|
60
|
+
_requiredPlugins: {},
|
|
61
|
+
/**
|
|
62
|
+
* @private
|
|
63
|
+
* @type {Array<{ meta: ModuleMeta; timings?: Record<string, number | undefined>; entryPath?: string }>}
|
|
64
|
+
*/
|
|
65
|
+
_installedPlugins: [],
|
|
66
|
+
/** @private */
|
|
67
|
+
_plugins: [],
|
|
68
|
+
extensions: [".js", ".mjs", ".ts"]
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const SilgiConfigSchema = {
|
|
72
|
+
...common,
|
|
73
|
+
...internal
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const silgiCtx = getContext("silgi");
|
|
77
|
+
function useSilgi() {
|
|
78
|
+
const instance = silgiCtx.tryUse();
|
|
79
|
+
if (!instance) {
|
|
80
|
+
throw new Error("Silgi instance is unavailable!");
|
|
81
|
+
}
|
|
82
|
+
return instance;
|
|
83
|
+
}
|
|
84
|
+
function normalizeResult(result) {
|
|
85
|
+
if (Array.isArray(result)) {
|
|
86
|
+
return [...result];
|
|
87
|
+
}
|
|
88
|
+
if (result && typeof result === "object") {
|
|
89
|
+
if (Object.keys(result).every((key) => !Number.isNaN(Number(key)))) {
|
|
90
|
+
return Object.values(result);
|
|
91
|
+
}
|
|
92
|
+
return { ...result };
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function tryUseSilgi() {
|
|
97
|
+
return silgiCtx.tryUse();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
|
|
101
|
+
HttpStatus2[HttpStatus2["CONTINUE"] = 100] = "CONTINUE";
|
|
102
|
+
HttpStatus2[HttpStatus2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
103
|
+
HttpStatus2[HttpStatus2["PROCESSING"] = 102] = "PROCESSING";
|
|
104
|
+
HttpStatus2[HttpStatus2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
|
|
105
|
+
HttpStatus2[HttpStatus2["OK"] = 200] = "OK";
|
|
106
|
+
HttpStatus2[HttpStatus2["CREATED"] = 201] = "CREATED";
|
|
107
|
+
HttpStatus2[HttpStatus2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
108
|
+
HttpStatus2[HttpStatus2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
109
|
+
HttpStatus2[HttpStatus2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
110
|
+
HttpStatus2[HttpStatus2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
111
|
+
HttpStatus2[HttpStatus2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
112
|
+
HttpStatus2[HttpStatus2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
113
|
+
HttpStatus2[HttpStatus2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
114
|
+
HttpStatus2[HttpStatus2["IM_USED"] = 226] = "IM_USED";
|
|
115
|
+
HttpStatus2[HttpStatus2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
116
|
+
HttpStatus2[HttpStatus2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
117
|
+
HttpStatus2[HttpStatus2["FOUND"] = 302] = "FOUND";
|
|
118
|
+
HttpStatus2[HttpStatus2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
119
|
+
HttpStatus2[HttpStatus2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
120
|
+
HttpStatus2[HttpStatus2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
121
|
+
HttpStatus2[HttpStatus2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
122
|
+
HttpStatus2[HttpStatus2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
123
|
+
HttpStatus2[HttpStatus2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
124
|
+
HttpStatus2[HttpStatus2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
125
|
+
HttpStatus2[HttpStatus2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
126
|
+
HttpStatus2[HttpStatus2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
127
|
+
HttpStatus2[HttpStatus2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
128
|
+
HttpStatus2[HttpStatus2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
129
|
+
HttpStatus2[HttpStatus2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
130
|
+
HttpStatus2[HttpStatus2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
131
|
+
HttpStatus2[HttpStatus2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
132
|
+
HttpStatus2[HttpStatus2["CONFLICT"] = 409] = "CONFLICT";
|
|
133
|
+
HttpStatus2[HttpStatus2["GONE"] = 410] = "GONE";
|
|
134
|
+
HttpStatus2[HttpStatus2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
135
|
+
HttpStatus2[HttpStatus2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
136
|
+
HttpStatus2[HttpStatus2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
137
|
+
HttpStatus2[HttpStatus2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
138
|
+
HttpStatus2[HttpStatus2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
139
|
+
HttpStatus2[HttpStatus2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
140
|
+
HttpStatus2[HttpStatus2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
141
|
+
HttpStatus2[HttpStatus2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
142
|
+
HttpStatus2[HttpStatus2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
143
|
+
HttpStatus2[HttpStatus2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
144
|
+
HttpStatus2[HttpStatus2["LOCKED"] = 423] = "LOCKED";
|
|
145
|
+
HttpStatus2[HttpStatus2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
146
|
+
HttpStatus2[HttpStatus2["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
147
|
+
HttpStatus2[HttpStatus2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
148
|
+
HttpStatus2[HttpStatus2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
149
|
+
HttpStatus2[HttpStatus2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
150
|
+
HttpStatus2[HttpStatus2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
151
|
+
HttpStatus2[HttpStatus2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
152
|
+
HttpStatus2[HttpStatus2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
153
|
+
HttpStatus2[HttpStatus2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
154
|
+
HttpStatus2[HttpStatus2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
155
|
+
HttpStatus2[HttpStatus2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
156
|
+
HttpStatus2[HttpStatus2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
157
|
+
HttpStatus2[HttpStatus2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
158
|
+
HttpStatus2[HttpStatus2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
159
|
+
HttpStatus2[HttpStatus2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
160
|
+
HttpStatus2[HttpStatus2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
161
|
+
HttpStatus2[HttpStatus2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
162
|
+
HttpStatus2[HttpStatus2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
163
|
+
return HttpStatus2;
|
|
164
|
+
})(HttpStatus || {});
|
|
165
|
+
var ErrorSeverity = /* @__PURE__ */ ((ErrorSeverity2) => {
|
|
166
|
+
ErrorSeverity2["DEBUG"] = "DEBUG";
|
|
167
|
+
ErrorSeverity2["INFO"] = "INFO";
|
|
168
|
+
ErrorSeverity2["WARNING"] = "WARNING";
|
|
169
|
+
ErrorSeverity2["ERROR"] = "ERROR";
|
|
170
|
+
ErrorSeverity2["CRITICAL"] = "CRITICAL";
|
|
171
|
+
return ErrorSeverity2;
|
|
172
|
+
})(ErrorSeverity || {});
|
|
173
|
+
var ErrorCategory = /* @__PURE__ */ ((ErrorCategory2) => {
|
|
174
|
+
ErrorCategory2["AUTHENTICATION"] = "auth";
|
|
175
|
+
ErrorCategory2["AUTHORIZATION"] = "authorization";
|
|
176
|
+
ErrorCategory2["VALIDATION"] = "validation";
|
|
177
|
+
ErrorCategory2["BUSINESS"] = "business";
|
|
178
|
+
ErrorCategory2["INFRASTRUCTURE"] = "infrastructure";
|
|
179
|
+
ErrorCategory2["EXTERNAL"] = "external";
|
|
180
|
+
ErrorCategory2["UNKNOWN"] = "unknown";
|
|
181
|
+
return ErrorCategory2;
|
|
182
|
+
})(ErrorCategory || {});
|
|
183
|
+
class ErrorFactory {
|
|
184
|
+
static createMetadata(metadata) {
|
|
185
|
+
return {
|
|
186
|
+
timestamp: Date.now(),
|
|
187
|
+
...metadata
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
static create(options) {
|
|
191
|
+
return new SilgiError({
|
|
192
|
+
code: options.code ?? options.httpStatus ?? 500 /* INTERNAL_SERVER_ERROR */,
|
|
193
|
+
message: options.message,
|
|
194
|
+
category: options.category ?? "unknown" /* UNKNOWN */,
|
|
195
|
+
severity: options.severity ?? "ERROR" /* ERROR */,
|
|
196
|
+
httpStatus: options.httpStatus ?? 500 /* INTERNAL_SERVER_ERROR */,
|
|
197
|
+
metadata: this.createMetadata(options.metadata),
|
|
198
|
+
cause: options.cause,
|
|
199
|
+
context: options.context
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
// Predefined error creators
|
|
203
|
+
static authenticationError(message, context) {
|
|
204
|
+
return this.create({
|
|
205
|
+
message,
|
|
206
|
+
code: 401,
|
|
207
|
+
category: "auth" /* AUTHENTICATION */,
|
|
208
|
+
severity: "ERROR" /* ERROR */,
|
|
209
|
+
httpStatus: 401 /* UNAUTHORIZED */,
|
|
210
|
+
context
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
static authorizationError(message, context) {
|
|
214
|
+
return this.create({
|
|
215
|
+
message,
|
|
216
|
+
code: 403,
|
|
217
|
+
category: "authorization" /* AUTHORIZATION */,
|
|
218
|
+
severity: "ERROR" /* ERROR */,
|
|
219
|
+
httpStatus: 403 /* FORBIDDEN */,
|
|
220
|
+
context
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
static validationError(message, context) {
|
|
224
|
+
return this.create({
|
|
225
|
+
message,
|
|
226
|
+
code: 400,
|
|
227
|
+
category: "validation" /* VALIDATION */,
|
|
228
|
+
severity: "WARNING" /* WARNING */,
|
|
229
|
+
httpStatus: 400 /* BAD_REQUEST */,
|
|
230
|
+
context
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
static notFoundError(message, context) {
|
|
234
|
+
return this.create({
|
|
235
|
+
message,
|
|
236
|
+
code: 404,
|
|
237
|
+
category: "business" /* BUSINESS */,
|
|
238
|
+
severity: "WARNING" /* WARNING */,
|
|
239
|
+
httpStatus: 404 /* NOT_FOUND */,
|
|
240
|
+
context
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
static internalError(message, cause) {
|
|
244
|
+
return this.create({
|
|
245
|
+
message,
|
|
246
|
+
code: 500,
|
|
247
|
+
category: "infrastructure" /* INFRASTRUCTURE */,
|
|
248
|
+
severity: "CRITICAL" /* CRITICAL */,
|
|
249
|
+
httpStatus: 500 /* INTERNAL_SERVER_ERROR */,
|
|
250
|
+
cause
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
class SilgiError extends Error {
|
|
255
|
+
code;
|
|
256
|
+
category;
|
|
257
|
+
severity;
|
|
258
|
+
httpStatus;
|
|
259
|
+
metadata;
|
|
260
|
+
context;
|
|
261
|
+
cause;
|
|
262
|
+
constructor(error) {
|
|
263
|
+
super(error.message);
|
|
264
|
+
this.name = "SilgiError";
|
|
265
|
+
this.code = error.code;
|
|
266
|
+
this.category = error.category;
|
|
267
|
+
this.severity = error.severity;
|
|
268
|
+
this.httpStatus = error.httpStatus;
|
|
269
|
+
this.metadata = error.metadata ?? { timestamp: Date.now() };
|
|
270
|
+
this.context = error.context;
|
|
271
|
+
this.cause = error.cause;
|
|
272
|
+
if (Error.captureStackTrace) {
|
|
273
|
+
Error.captureStackTrace(this, this.constructor);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
toString() {
|
|
277
|
+
let str = `${this.name} [${this.code}] ${this.severity}: ${this.message}`;
|
|
278
|
+
str += `
|
|
279
|
+
Category: ${this.category}`;
|
|
280
|
+
str += `
|
|
281
|
+
HTTP Status: ${this.httpStatus}`;
|
|
282
|
+
if (this.context) {
|
|
283
|
+
str += `
|
|
284
|
+
Context: ${JSON.stringify(this.context, null, 2)}`;
|
|
285
|
+
}
|
|
286
|
+
if (this.metadata) {
|
|
287
|
+
str += `
|
|
288
|
+
Metadata: ${JSON.stringify(this.metadata, null, 2)}`;
|
|
289
|
+
}
|
|
290
|
+
if (this.stack) {
|
|
291
|
+
str += `
|
|
292
|
+
${this.stack}`;
|
|
293
|
+
}
|
|
294
|
+
return str;
|
|
295
|
+
}
|
|
296
|
+
toJSON() {
|
|
297
|
+
return {
|
|
298
|
+
name: this.name,
|
|
299
|
+
code: this.code,
|
|
300
|
+
message: this.message,
|
|
301
|
+
category: this.category,
|
|
302
|
+
severity: this.severity,
|
|
303
|
+
httpStatus: this.httpStatus,
|
|
304
|
+
metadata: this.metadata,
|
|
305
|
+
context: this.context,
|
|
306
|
+
stack: this.stack
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
static isError(error) {
|
|
310
|
+
return error instanceof SilgiError;
|
|
311
|
+
}
|
|
312
|
+
static from(error) {
|
|
313
|
+
if (error instanceof SilgiError) {
|
|
314
|
+
return error;
|
|
315
|
+
}
|
|
316
|
+
return ErrorFactory.internalError(
|
|
317
|
+
error instanceof Error ? error.message : String(error),
|
|
318
|
+
error instanceof Error ? error : void 0
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function isBaseError(error) {
|
|
323
|
+
return typeof error === "object" && error !== null && "code" in error && "message" in error && "category" in error && "severity" in error && "httpStatus" in error;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function parseURI(uri, uris) {
|
|
327
|
+
if (!uri) {
|
|
328
|
+
throw ErrorFactory.create({
|
|
329
|
+
message: "URI cannot be empty",
|
|
330
|
+
httpStatus: HttpStatus.BAD_REQUEST,
|
|
331
|
+
context: { uri }
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
if (!uris) {
|
|
335
|
+
throw ErrorFactory.create({
|
|
336
|
+
message: "URIs configuration is not provided",
|
|
337
|
+
httpStatus: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
338
|
+
context: { uri }
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
const cleanUri = uri.replace(/^\/*(srn\/)?/, "").replace(/\/*$/, "");
|
|
342
|
+
const [path, queryString] = cleanUri.split("?");
|
|
343
|
+
const parts = path.split("/");
|
|
344
|
+
const query = queryString ? Object.fromEntries(
|
|
345
|
+
queryString.split("&").map((param) => param.split("="))
|
|
346
|
+
) : void 0;
|
|
347
|
+
const method = query?.method ? query?.method.toLowerCase() : void 0;
|
|
348
|
+
const namespaceName = parts[0];
|
|
349
|
+
const serviceName = parts[1];
|
|
350
|
+
const methodName = method || parts[2];
|
|
351
|
+
const actionName = method ? parts[2] : parts[3];
|
|
352
|
+
if (!namespaceName || !serviceName || !methodName || !actionName) {
|
|
353
|
+
throw ErrorFactory.create({
|
|
354
|
+
message: "Invalid URI format: Insufficient path segments",
|
|
355
|
+
httpStatus: HttpStatus.BAD_REQUEST,
|
|
356
|
+
context: {
|
|
357
|
+
uri,
|
|
358
|
+
cleanUri,
|
|
359
|
+
partsLength: parts.length,
|
|
360
|
+
method,
|
|
361
|
+
namespaceName,
|
|
362
|
+
serviceName,
|
|
363
|
+
methodName,
|
|
364
|
+
actionName
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const baseUri = `${namespaceName}/${serviceName}/${methodName}/${actionName}`;
|
|
369
|
+
const paramStartIndex = method ? 3 : 4;
|
|
370
|
+
const parameters = parts.slice(paramStartIndex);
|
|
371
|
+
const normalizedUri = method ? `${namespaceName}/${serviceName}/${method}/${actionName}${parameters.length ? `/${parameters.join("/")}` : ""}` : cleanUri;
|
|
372
|
+
const template = uris[baseUri];
|
|
373
|
+
if (template === void 0) {
|
|
374
|
+
throw ErrorFactory.create({
|
|
375
|
+
message: "No route found for URI",
|
|
376
|
+
httpStatus: HttpStatus.NOT_FOUND,
|
|
377
|
+
context: {
|
|
378
|
+
uri,
|
|
379
|
+
baseUri
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (template === "") {
|
|
384
|
+
if (parameters.length > 0) {
|
|
385
|
+
throw ErrorFactory.create({
|
|
386
|
+
message: "No parameters expected for this route",
|
|
387
|
+
httpStatus: HttpStatus.BAD_REQUEST,
|
|
388
|
+
context: {
|
|
389
|
+
uri,
|
|
390
|
+
baseUri,
|
|
391
|
+
extraParams: parameters
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
namespaceName,
|
|
397
|
+
serviceName,
|
|
398
|
+
methodName,
|
|
399
|
+
actionName,
|
|
400
|
+
raw: normalizedUri,
|
|
401
|
+
parts: [namespaceName, serviceName, methodName, actionName],
|
|
402
|
+
routerParams: {},
|
|
403
|
+
query: method ? void 0 : query,
|
|
404
|
+
uri: baseUri
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
const routeTemplate = typeof template === "string" ? template : template.pattern;
|
|
408
|
+
const validators = typeof template === "string" ? void 0 : template.validators;
|
|
409
|
+
const routerParams = {};
|
|
410
|
+
const templateParts = routeTemplate.split("/").filter(Boolean);
|
|
411
|
+
const paramValues = parameters;
|
|
412
|
+
let valueIndex = 0;
|
|
413
|
+
templateParts.forEach((part) => {
|
|
414
|
+
if (part.startsWith(":")) {
|
|
415
|
+
const paramName = part.substring(1);
|
|
416
|
+
const paramValue = paramValues[valueIndex];
|
|
417
|
+
if (validators?.[paramName] && paramValue) {
|
|
418
|
+
if (!validators[paramName](paramValue)) {
|
|
419
|
+
throw ErrorFactory.create({
|
|
420
|
+
message: "Invalid value for parameter",
|
|
421
|
+
httpStatus: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
422
|
+
context: {
|
|
423
|
+
uri,
|
|
424
|
+
paramName,
|
|
425
|
+
paramValue,
|
|
426
|
+
validatorName: paramName
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
routerParams[paramName] = paramValue || void 0;
|
|
432
|
+
valueIndex++;
|
|
433
|
+
} else if (part && part === paramValues[valueIndex]) {
|
|
434
|
+
valueIndex++;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
return {
|
|
438
|
+
namespaceName,
|
|
439
|
+
serviceName,
|
|
440
|
+
methodName,
|
|
441
|
+
actionName,
|
|
442
|
+
raw: normalizedUri,
|
|
443
|
+
parts: [namespaceName, serviceName, methodName, actionName],
|
|
444
|
+
routerParams,
|
|
445
|
+
query: method ? void 0 : query,
|
|
446
|
+
uri: baseUri
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async function findAction(silgi, uri) {
|
|
451
|
+
const { parts } = parseURI(uri, silgi.uris);
|
|
452
|
+
let result = silgi.services;
|
|
453
|
+
for (const part of parts) {
|
|
454
|
+
if (result && Object.prototype.hasOwnProperty.call(result, part)) {
|
|
455
|
+
result = Object.assign({}, result[part]);
|
|
456
|
+
} else {
|
|
457
|
+
console.error("Property not found:", part);
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
async function scanAction(silgi) {
|
|
464
|
+
for (const [key, _value] of Object.entries(silgi.uris)) {
|
|
465
|
+
const segments = key.split("/").filter(Boolean);
|
|
466
|
+
if (segments.length !== 4) {
|
|
467
|
+
console.error(`Invalid URI format for key "${key}". URI must have exactly 4 segments in format: namespace/service/method/action`);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const [namespace, service, method, action] = segments;
|
|
471
|
+
if (!namespace || !service || !method || !action) {
|
|
472
|
+
console.error(`Invalid URI segments for key "${key}". All segments must be non-empty`);
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const handler = await findAction(silgi, key);
|
|
476
|
+
silgi.scannedHandlers.set(key, handler);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function createStorage(silgi) {
|
|
481
|
+
const storage = createStorage$1();
|
|
482
|
+
const mounts = klona({
|
|
483
|
+
...silgi.options.storage,
|
|
484
|
+
...silgi.options.devStorage
|
|
485
|
+
});
|
|
486
|
+
for (const [path, opts] of Object.entries(mounts)) {
|
|
487
|
+
if (opts.driver) {
|
|
488
|
+
const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
|
|
489
|
+
storage.mount("/memory:cache", memoryDriver());
|
|
490
|
+
storage.mount(path, driver(opts));
|
|
491
|
+
} else {
|
|
492
|
+
silgi.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return storage;
|
|
496
|
+
}
|
|
497
|
+
function useSilgiStorage(base = "/memory:cache") {
|
|
498
|
+
const silgi = useSilgi();
|
|
499
|
+
return base ? prefixStorage(silgi.storage, base) : silgi.storage;
|
|
500
|
+
}
|
|
501
|
+
async function generateStorageKey(params) {
|
|
502
|
+
const {
|
|
503
|
+
operation,
|
|
504
|
+
input,
|
|
505
|
+
keyGenerator,
|
|
506
|
+
requestId,
|
|
507
|
+
storageOptions
|
|
508
|
+
} = params;
|
|
509
|
+
const cacheScopePrefix = storageOptions?.scope === "request" ? "req" : "global";
|
|
510
|
+
const parts = [
|
|
511
|
+
cacheScopePrefix,
|
|
512
|
+
// Always include scope prefix first
|
|
513
|
+
operation.namespaceName,
|
|
514
|
+
operation.serviceName,
|
|
515
|
+
operation.methodName
|
|
516
|
+
].filter(Boolean);
|
|
517
|
+
if (storageOptions?.scope === "request") {
|
|
518
|
+
if (!requestId) {
|
|
519
|
+
throw ErrorFactory.create({
|
|
520
|
+
code: HttpStatus.BAD_REQUEST,
|
|
521
|
+
message: "Request ID is required for request-scoped cache",
|
|
522
|
+
context: {
|
|
523
|
+
requestId,
|
|
524
|
+
operation,
|
|
525
|
+
input,
|
|
526
|
+
storageOptions,
|
|
527
|
+
keyGenerator
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
parts.push(requestId);
|
|
532
|
+
}
|
|
533
|
+
if (keyGenerator) {
|
|
534
|
+
const customKey = await Promise.resolve(keyGenerator(input));
|
|
535
|
+
parts.push(customKey);
|
|
536
|
+
} else {
|
|
537
|
+
parts.push(typeof input === "object" ? JSON.stringify(input) : String(input));
|
|
538
|
+
}
|
|
539
|
+
return Buffer.from(parts.join(":")).toString("base64");
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
async function runSilgiPlugins(silgi) {
|
|
543
|
+
for (const plugin of silgi.plugins) {
|
|
544
|
+
try {
|
|
545
|
+
await plugin(silgi);
|
|
546
|
+
} catch (error) {
|
|
547
|
+
silgi.captureError(error, { tags: ["plugin"] });
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
async function createSilgi(config) {
|
|
553
|
+
const hooks = createHooks();
|
|
554
|
+
await applyDefaults(SilgiConfigSchema, config.options);
|
|
555
|
+
const silgi = {
|
|
556
|
+
schemas: config.schemas,
|
|
557
|
+
services: config.services ?? {},
|
|
558
|
+
shared: config.shared ?? void 0,
|
|
559
|
+
uris: config.uris ?? {},
|
|
560
|
+
modulesURIs: config.modulesURIs ?? {},
|
|
561
|
+
scannedHandlers: /* @__PURE__ */ new Map(),
|
|
562
|
+
plugins: config.plugins ?? [],
|
|
563
|
+
framework: config.framework ?? void 0,
|
|
564
|
+
storage: config.storage ?? void 0,
|
|
565
|
+
options: config.options,
|
|
566
|
+
hooks,
|
|
567
|
+
callHook: hooks.callHook,
|
|
568
|
+
addHooks: hooks.addHooks,
|
|
569
|
+
hook: hooks.hook,
|
|
570
|
+
ready: () => {
|
|
571
|
+
return hooks.callHook("ready", silgi);
|
|
572
|
+
},
|
|
573
|
+
close: () => hooks.callHook("close", silgi),
|
|
574
|
+
logger: createConsola(defu(config.options.consolaOptions, {
|
|
575
|
+
tag: "silgi"
|
|
576
|
+
})).withTag("silgi"),
|
|
577
|
+
captureError: (error, context = {}) => {
|
|
578
|
+
const promise = hooks.callHookParallel("error", error, context).catch((error_) => {
|
|
579
|
+
console.error("Error while capturing another error", error_);
|
|
580
|
+
});
|
|
581
|
+
if (context.event && isEvent(context.event)) {
|
|
582
|
+
const errors = context.event.context.nitro?.errors;
|
|
583
|
+
if (errors) {
|
|
584
|
+
errors.push({ error, context });
|
|
585
|
+
}
|
|
586
|
+
if (context.event.waitUntil) {
|
|
587
|
+
context.event.waitUntil(promise);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
await runSilgiPlugins(silgi);
|
|
593
|
+
await scanAction(silgi);
|
|
594
|
+
if (!silgi.storage) {
|
|
595
|
+
silgi.storage = await createStorage(silgi);
|
|
596
|
+
}
|
|
597
|
+
silgi.shared.storage = (...data) => {
|
|
598
|
+
return useSilgiStorage(...data);
|
|
599
|
+
};
|
|
600
|
+
if (silgiCtx.tryUse()) {
|
|
601
|
+
silgiCtx.unset();
|
|
602
|
+
silgiCtx.set(silgi);
|
|
603
|
+
} else {
|
|
604
|
+
silgiCtx.set(silgi);
|
|
605
|
+
silgi.hook("close", () => silgiCtx.unset());
|
|
606
|
+
}
|
|
607
|
+
silgi.logger.info("Silgi installed");
|
|
608
|
+
hooks.hookOnce("close", async () => {
|
|
609
|
+
hooks.removeAllHooks();
|
|
610
|
+
await silgi.storage.dispose();
|
|
611
|
+
});
|
|
612
|
+
return silgi;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function createSilgiFetch(options, localFetch) {
|
|
616
|
+
return (url, opts) => {
|
|
617
|
+
const finalOpts = {
|
|
618
|
+
...typeof options === "function" ? options(opts) : options,
|
|
619
|
+
...opts,
|
|
620
|
+
method: opts.method || "get"
|
|
621
|
+
};
|
|
622
|
+
const $fetch = getFetch(url, finalOpts, localFetch);
|
|
623
|
+
return $fetch(fillPath(url, opts.params), finalOpts);
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function getFetch(url, opts, localFetch) {
|
|
627
|
+
if (import.meta.server && localFetch) {
|
|
628
|
+
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
|
|
629
|
+
if (isLocalFetch)
|
|
630
|
+
return localFetch;
|
|
631
|
+
}
|
|
632
|
+
return globalThis.$fetch;
|
|
633
|
+
}
|
|
634
|
+
function fillPath(path, params) {
|
|
635
|
+
if (!params) {
|
|
636
|
+
if (path.includes(":"))
|
|
637
|
+
throw new Error("Parametreler dogru kullanmal\u0131s\u0131n\u0131z");
|
|
638
|
+
return path;
|
|
639
|
+
}
|
|
640
|
+
if (!path.includes(":"))
|
|
641
|
+
throw new Error("Path parametler : ile belirtilmelidir");
|
|
642
|
+
let result = path;
|
|
643
|
+
for (const [key, value] of Object.entries(params)) {
|
|
644
|
+
result = result.replace(`:${key}`, value);
|
|
645
|
+
}
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function silgi(event) {
|
|
650
|
+
return {
|
|
651
|
+
execute: (uriString, input) => {
|
|
652
|
+
return execute(uriString, input, event);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
async function execute(uriString, input, event) {
|
|
657
|
+
const silgiCtx = useSilgi();
|
|
658
|
+
if (event) {
|
|
659
|
+
await silgiCtx.callHook("event:before", event);
|
|
660
|
+
}
|
|
661
|
+
let success = false;
|
|
662
|
+
let cached = false;
|
|
663
|
+
let result;
|
|
664
|
+
try {
|
|
665
|
+
const operation = parseURI(uriString, silgiCtx.uris);
|
|
666
|
+
if (!operation) {
|
|
667
|
+
throw ErrorFactory.create({ message: "Invalid URI", httpStatus: HttpStatus.BAD_REQUEST });
|
|
668
|
+
}
|
|
669
|
+
const handler = silgiCtx.scannedHandlers.get(operation.uri);
|
|
670
|
+
if (!handler) {
|
|
671
|
+
throw ErrorFactory.create({
|
|
672
|
+
message: "Action not found",
|
|
673
|
+
httpStatus: HttpStatus.NOT_FOUND,
|
|
674
|
+
context: {
|
|
675
|
+
uri: uriString
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
await silgiCtx.callHook("action:before", {
|
|
680
|
+
operation,
|
|
681
|
+
input,
|
|
682
|
+
event,
|
|
683
|
+
modules: handler.modules,
|
|
684
|
+
result
|
|
685
|
+
});
|
|
686
|
+
const cacheData = await cacheExecute(input, operation, handler, event);
|
|
687
|
+
if (cacheData?.success) {
|
|
688
|
+
result = cacheData.data;
|
|
689
|
+
success = cacheData.success;
|
|
690
|
+
cached = cacheData.cached;
|
|
691
|
+
} else {
|
|
692
|
+
const router = {
|
|
693
|
+
params: operation.routerParams,
|
|
694
|
+
query: operation.query
|
|
695
|
+
};
|
|
696
|
+
silgiCtx.shared.silgi = (_event) => silgi(_event || event);
|
|
697
|
+
result = await handler?.handler(router, input, silgiCtx.shared, event);
|
|
698
|
+
success = true;
|
|
699
|
+
}
|
|
700
|
+
await silgiCtx.callHook("action:after", {
|
|
701
|
+
operation,
|
|
702
|
+
input,
|
|
703
|
+
event,
|
|
704
|
+
result,
|
|
705
|
+
success,
|
|
706
|
+
modules: handler.modules
|
|
707
|
+
});
|
|
708
|
+
if (!cached) {
|
|
709
|
+
if (success && cacheData?.cachedKey && handler.storage) {
|
|
710
|
+
await useSilgiStorage(handler.storage.base).setItem(cacheData.cachedKey, result, handler.storage.options);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return result;
|
|
714
|
+
} catch (err) {
|
|
715
|
+
await silgiCtx.callHook("action:error", {
|
|
716
|
+
input,
|
|
717
|
+
event,
|
|
718
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
719
|
+
timestamp: Date.now()
|
|
720
|
+
});
|
|
721
|
+
silgiCtx.captureError(SilgiError.from(err), {
|
|
722
|
+
event,
|
|
723
|
+
tags: ["execute"]
|
|
724
|
+
});
|
|
725
|
+
throw err;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
async function cacheExecute(input, operation, handler, event) {
|
|
729
|
+
if (!handler.storage)
|
|
730
|
+
return;
|
|
731
|
+
const cacheKey = handler.storage ? await generateStorageKey({
|
|
732
|
+
operation,
|
|
733
|
+
input,
|
|
734
|
+
keyGenerator: handler.storage.key,
|
|
735
|
+
storageOptions: handler.storage,
|
|
736
|
+
requestId: event?.requestId
|
|
737
|
+
}) : null;
|
|
738
|
+
if (cacheKey) {
|
|
739
|
+
const cachedResult = await useSilgiStorage(handler.storage.base).getItem(cacheKey);
|
|
740
|
+
if (cachedResult !== null) {
|
|
741
|
+
return {
|
|
742
|
+
success: true,
|
|
743
|
+
data: normalizeResult(cachedResult),
|
|
744
|
+
cached: true,
|
|
745
|
+
cachedKey: cacheKey
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
success: false,
|
|
751
|
+
data: null,
|
|
752
|
+
cached: false,
|
|
753
|
+
cachedKey: cacheKey
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function merge(items, maxLevel = 4, currentLevel = 3) {
|
|
758
|
+
const arrayItems = Array.isArray(items) ? items : [items];
|
|
759
|
+
return arrayItems.reduce((acc, item) => {
|
|
760
|
+
Object.keys(item).forEach((key) => {
|
|
761
|
+
if (typeof item[key] === "object" && item[key] !== null && currentLevel < maxLevel) {
|
|
762
|
+
acc[key] = acc[key] || {};
|
|
763
|
+
acc[key] = merge([acc[key], item[key]], maxLevel, currentLevel + 1);
|
|
764
|
+
} else {
|
|
765
|
+
acc[key] = item[key];
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
return acc;
|
|
769
|
+
}, {});
|
|
770
|
+
}
|
|
771
|
+
function mergeSchemas(typesOrArray) {
|
|
772
|
+
return merge(typesOrArray);
|
|
773
|
+
}
|
|
774
|
+
function mergeServices(servicesOrArray) {
|
|
775
|
+
return merge(servicesOrArray);
|
|
776
|
+
}
|
|
777
|
+
function mergeShared(sharedOrArray) {
|
|
778
|
+
return merge(sharedOrArray, 1, 1);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function getEvent(event) {
|
|
782
|
+
return event.event || event || {};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function createSchema(silgiType) {
|
|
786
|
+
return silgiType;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function createService(variables) {
|
|
790
|
+
return variables;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function createShared(shared) {
|
|
794
|
+
return shared;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const silgiCLICtx = getContext("SilgiCLI");
|
|
798
|
+
function useSilgiCLI() {
|
|
799
|
+
const instance = silgiCLICtx.tryUse();
|
|
800
|
+
if (!instance) {
|
|
801
|
+
throw new Error("Silgi instance is unavailable!");
|
|
802
|
+
}
|
|
803
|
+
return instance;
|
|
804
|
+
}
|
|
805
|
+
function tryUseSilgiCLI() {
|
|
806
|
+
return silgiCLICtx.tryUse();
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
|