silgi 0.3.13 → 0.4.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/README.md +1 -31
- package/cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/core.d.ts +1 -0
- package/dist/_chunks/index.mjs +233 -0
- package/dist/cli/compatibility.mjs +42 -0
- package/dist/cli/index.mjs +3 -184
- package/dist/cli/prepare.mjs +1346 -0
- package/dist/config/index.d.mts +5 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/core/index.d.mts +136 -0
- package/dist/core/index.d.ts +136 -0
- package/dist/core/index.mjs +1444 -0
- package/dist/ecosystem/nitro/index.mjs +21 -29
- package/dist/ecosystem/nuxt/module.mjs +4 -25
- package/dist/kit/index.d.mts +90 -0
- package/dist/kit/index.d.ts +90 -0
- package/dist/kit/index.mjs +316 -0
- package/dist/meta/index.d.mts +3 -0
- package/dist/meta/index.d.ts +3 -0
- package/dist/meta/index.mjs +1 -0
- package/dist/presets/_all.gen.d.ts +2 -0
- package/dist/presets/_all.gen.mjs +8 -0
- package/dist/presets/_resolve.d.ts +8 -0
- package/dist/presets/_resolve.mjs +58 -0
- package/dist/presets/_types.gen.d.ts +5 -0
- package/dist/presets/_types.gen.mjs +1 -0
- package/dist/presets/h3/preset.d.ts +2 -0
- package/dist/presets/h3/preset.mjs +22 -0
- package/dist/presets/index.d.mts +1 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.mjs +1 -0
- package/dist/presets/nitro/preset.d.ts +2 -0
- package/dist/presets/nitro/preset.mjs +26 -0
- package/dist/presets/npmpackage/preset.d.ts +2 -0
- package/dist/presets/npmpackage/preset.mjs +23 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.mjs +1 -0
- package/dist/runtime/internal/debug.d.ts +2 -0
- package/dist/runtime/internal/debug.mjs +5 -0
- package/dist/runtime/internal/nitro.d.ts +2 -0
- package/dist/runtime/internal/nitro.mjs +45 -0
- package/dist/runtime/internal/plugin.d.ts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/shared/silgi.40ZJYm8F.d.mts +11 -0
- package/dist/shared/silgi.40ZJYm8F.d.ts +11 -0
- package/dist/shared/{silgi.ClpvycKI.d.mts → silgi.D8h2AAVk.d.ts} +451 -437
- package/dist/shared/{silgi.ClpvycKI.d.ts → silgi.DSHNePNA.d.mts} +451 -437
- package/dist/types/index.d.mts +42 -0
- package/dist/types/index.d.ts +42 -0
- package/dist/types/index.mjs +1 -0
- package/kit.d.ts +1 -0
- package/meta.d.ts +1 -0
- package/package.json +89 -39
- package/presets.d.ts +1 -0
- package/runtime-meta.d.ts +4 -0
- package/runtime-meta.mjs +32 -0
- package/runtime.d.ts +1 -0
- package/types.d.ts +1 -0
- package/bin/silgi.mjs +0 -3
- package/dist/chunks/generate.mjs +0 -1257
- package/dist/cli/config.d.mts +0 -1633
- package/dist/cli/config.d.ts +0 -1633
- package/dist/index.d.mts +0 -198
- package/dist/index.d.ts +0 -198
- package/dist/index.mjs +0 -503
- package/dist/shared/silgi.D2yb1XAa.mjs +0 -842
- /package/dist/{chunks → cli}/init.mjs +0 -0
- /package/dist/{cli/config.mjs → config/index.mjs} +0 -0
package/dist/index.mjs
DELETED
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
import { createConsola } from 'consola';
|
|
2
|
-
import defu, { defu as defu$1 } from 'defu';
|
|
3
|
-
import { createHooks } from 'hookable';
|
|
4
|
-
import { applyDefaults } from 'untyped';
|
|
5
|
-
import { u as useSilgi, a as loadSilgiModuleInstance, p as parseURI, S as SilgiError, b as useStorage, n as normalizeResult, c as SilgiErrorCode, g as generateStorageKey, d as SilgiConfigSchema, s as scanAction, e as createStorage, f as silgiCtx, t as tryUseSilgi } from './shared/silgi.D2yb1XAa.mjs';
|
|
6
|
-
export { h as createResolver, l as loadSilgiConfig, r as relativeWithDot, i as useHook, j as useShared } from './shared/silgi.D2yb1XAa.mjs';
|
|
7
|
-
import satisfies from 'semver/functions/satisfies.js';
|
|
8
|
-
import { defineEventHandler, getQuery, readBody } from 'h3';
|
|
9
|
-
import 'node:fs';
|
|
10
|
-
import 'pathe';
|
|
11
|
-
import 'node:buffer';
|
|
12
|
-
import 'klona';
|
|
13
|
-
import 'unstorage';
|
|
14
|
-
import 'unstorage/drivers/memory';
|
|
15
|
-
import 'unctx';
|
|
16
|
-
import 'c12';
|
|
17
|
-
import 'std-env';
|
|
18
|
-
import 'node:url';
|
|
19
|
-
import 'mlly';
|
|
20
|
-
import 'pathe/utils';
|
|
21
|
-
|
|
22
|
-
const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
|
|
23
|
-
function normalizeSemanticVersion(version) {
|
|
24
|
-
return version.replace(SEMANTIC_VERSION_RE, "");
|
|
25
|
-
}
|
|
26
|
-
const SILGI_VERSION_RE = /^v/g;
|
|
27
|
-
function getSilgiVersion(silgi = useSilgi()) {
|
|
28
|
-
const rawVersion = silgi?._version || silgi?.version || silgi?.constructor?.version;
|
|
29
|
-
if (typeof rawVersion !== "string") {
|
|
30
|
-
throw new TypeError("Cannot determine silgi version! Is current instance passed?");
|
|
31
|
-
}
|
|
32
|
-
return rawVersion.replace(SILGI_VERSION_RE, "");
|
|
33
|
-
}
|
|
34
|
-
async function checkSilgiCompatibility(constraints, silgi = useSilgi()) {
|
|
35
|
-
const issues = [];
|
|
36
|
-
if (constraints.silgi) {
|
|
37
|
-
const silgiVersion = getSilgiVersion(silgi);
|
|
38
|
-
if (!satisfies(normalizeSemanticVersion(silgiVersion), constraints.silgi, { includePrerelease: true })) {
|
|
39
|
-
issues.push({
|
|
40
|
-
name: "silgi",
|
|
41
|
-
message: `Silgi version \`${constraints.silgi}\` is required but currently using \`${silgiVersion}\``
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
await silgi.callHook("kit:compatibility", constraints, issues);
|
|
46
|
-
issues.toString = () => issues.map((issue) => ` - [${issue.name}] ${issue.message}`).join("\n");
|
|
47
|
-
return issues;
|
|
48
|
-
}
|
|
49
|
-
function hasInstalledModule(moduleKey, silgi = useSilgi()) {
|
|
50
|
-
const find = silgi.options._installedModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
51
|
-
return find?.active ?? false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function installModules(silgi) {
|
|
55
|
-
for (const module of Object.keys(silgi._initializedModules)) {
|
|
56
|
-
if (hasInstalledModule(module)) {
|
|
57
|
-
silgi.logger.info(`Module ${module} installeddddd`);
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const silgiModule = silgi._initializedModules[module];
|
|
61
|
-
await installModule(silgiModule, silgi);
|
|
62
|
-
} catch (err) {
|
|
63
|
-
silgi.logger.error(err);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async function installModule(moduleToInstall, silgi = useSilgi(), inlineOptions) {
|
|
68
|
-
const { silgiModule } = await loadSilgiModuleInstance(moduleToInstall);
|
|
69
|
-
const res = await silgiModule({}, silgi, false) ?? {};
|
|
70
|
-
if (res === false) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
const metaData = await silgiModule.getMeta?.();
|
|
74
|
-
const installedModule = silgi.options._installedModules.find((m) => m.meta.configKey === metaData?.configKey);
|
|
75
|
-
if (installedModule) {
|
|
76
|
-
installedModule.active = true;
|
|
77
|
-
} else {
|
|
78
|
-
throw new Error(`Module ${metaData?.name} not found`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function getModule(configKey, silgi = useSilgi()) {
|
|
82
|
-
if (silgi._initializedModules[configKey]) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function silgi(event) {
|
|
89
|
-
return {
|
|
90
|
-
execute: (uriString, input) => {
|
|
91
|
-
return execute(uriString, input, event);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
async function execute(uriString, input, event) {
|
|
96
|
-
const silgiCtx = useSilgi();
|
|
97
|
-
if (event) {
|
|
98
|
-
silgiCtx.callHook("event:before", event);
|
|
99
|
-
}
|
|
100
|
-
let success = false;
|
|
101
|
-
let cached = false;
|
|
102
|
-
let error;
|
|
103
|
-
let result;
|
|
104
|
-
let operation;
|
|
105
|
-
try {
|
|
106
|
-
operation = parseURI(uriString, silgiCtx.uris);
|
|
107
|
-
} catch {
|
|
108
|
-
throw new SilgiError({
|
|
109
|
-
code: "INVALID_URI",
|
|
110
|
-
message: `Invalid URI: ${uriString}`
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (!operation) {
|
|
114
|
-
throw new SilgiError({
|
|
115
|
-
code: "INVALID_URI",
|
|
116
|
-
message: `Invalid URI: ${uriString}`
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
const hookContext = {
|
|
120
|
-
operation,
|
|
121
|
-
input,
|
|
122
|
-
event
|
|
123
|
-
};
|
|
124
|
-
try {
|
|
125
|
-
await silgiCtx.callHook("method:before", {
|
|
126
|
-
operation,
|
|
127
|
-
input,
|
|
128
|
-
event
|
|
129
|
-
});
|
|
130
|
-
const handler = silgiCtx.scannedHandlers.get(operation.uri);
|
|
131
|
-
if (!handler) {
|
|
132
|
-
return {
|
|
133
|
-
success: false,
|
|
134
|
-
error: {
|
|
135
|
-
code: "METHOD_NOT_FOUND",
|
|
136
|
-
message: `Method ${String(operation.methodName)} not found`
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
if (event)
|
|
141
|
-
await silgiCtx.callHook("event:before", event);
|
|
142
|
-
const cacheData = await cacheExecute(operation.raw, input, operation, handler, event);
|
|
143
|
-
await callModules(operation, handler, input, result, event);
|
|
144
|
-
if (cacheData?.success) {
|
|
145
|
-
result = cacheData.data;
|
|
146
|
-
success = cacheData.success;
|
|
147
|
-
cached = cacheData.cached;
|
|
148
|
-
} else {
|
|
149
|
-
const router = {
|
|
150
|
-
params: operation.routerParams,
|
|
151
|
-
query: operation.query
|
|
152
|
-
};
|
|
153
|
-
silgiCtx.shared.silgi = (_event) => silgi(_event || event);
|
|
154
|
-
result = await handler?.handler(router, input, silgiCtx.shared, event);
|
|
155
|
-
success = true;
|
|
156
|
-
}
|
|
157
|
-
await silgiCtx.callHook("method:after", {
|
|
158
|
-
operation,
|
|
159
|
-
input,
|
|
160
|
-
event,
|
|
161
|
-
result,
|
|
162
|
-
success
|
|
163
|
-
});
|
|
164
|
-
if (!cached) {
|
|
165
|
-
if (success && cacheData?.cachedKey && handler.storage) {
|
|
166
|
-
await useStorage(handler.storage.base).setItem(cacheData.cachedKey, result, handler.storage.options);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return { success: true, data: normalizeResult(result), cached };
|
|
170
|
-
} catch (err) {
|
|
171
|
-
error = err instanceof Error ? err : new Error("Unknown error");
|
|
172
|
-
if (error instanceof SilgiError) {
|
|
173
|
-
return {
|
|
174
|
-
success: false,
|
|
175
|
-
error: {
|
|
176
|
-
code: error.code,
|
|
177
|
-
message: error.message,
|
|
178
|
-
details: error.details
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
await silgiCtx.callHook("method:error", {
|
|
183
|
-
...hookContext,
|
|
184
|
-
error,
|
|
185
|
-
timestamp: Date.now()
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
188
|
-
success: false,
|
|
189
|
-
error: {
|
|
190
|
-
code: SilgiErrorCode.EXECUTION_ERROR,
|
|
191
|
-
message: error.message || String(error)
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async function callModules(operation, handler, input, result, event) {
|
|
197
|
-
const silgi2 = useSilgi();
|
|
198
|
-
if (!handler.modules)
|
|
199
|
-
return;
|
|
200
|
-
for (const [moduleKey, config] of Object.entries(handler.modules)) {
|
|
201
|
-
const pluginConfig = config;
|
|
202
|
-
if (moduleKey) {
|
|
203
|
-
const module = getModule(moduleKey, silgi2);
|
|
204
|
-
if (module) {
|
|
205
|
-
await silgi2.callHook("module:before:excute", {
|
|
206
|
-
operation,
|
|
207
|
-
input,
|
|
208
|
-
event,
|
|
209
|
-
modules: handler.modules,
|
|
210
|
-
config: pluginConfig,
|
|
211
|
-
result
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async function cacheExecute(uriString, input, operation, handler, event) {
|
|
218
|
-
if (!handler.storage)
|
|
219
|
-
return;
|
|
220
|
-
const cacheKey = handler.storage ? await generateStorageKey({
|
|
221
|
-
operation,
|
|
222
|
-
input,
|
|
223
|
-
keyGenerator: handler.storage.key,
|
|
224
|
-
storageOptions: handler.storage,
|
|
225
|
-
requestId: event?.requestId
|
|
226
|
-
}) : null;
|
|
227
|
-
if (cacheKey) {
|
|
228
|
-
const cachedResult = await useStorage(handler.storage.base).getItem(cacheKey);
|
|
229
|
-
if (cachedResult !== null) {
|
|
230
|
-
return {
|
|
231
|
-
success: true,
|
|
232
|
-
data: normalizeResult(cachedResult),
|
|
233
|
-
cached: true,
|
|
234
|
-
cachedKey: cacheKey
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
success: false,
|
|
240
|
-
data: null,
|
|
241
|
-
cached: false,
|
|
242
|
-
cachedKey: cacheKey
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
class SilgiHelper {
|
|
247
|
-
setEvent(key, value) {
|
|
248
|
-
const silgi2 = useSilgi();
|
|
249
|
-
silgi2.options._eventContext ??= /* @__PURE__ */ new Map();
|
|
250
|
-
silgi2.options._eventContext.set(key, value);
|
|
251
|
-
}
|
|
252
|
-
getEvent(key) {
|
|
253
|
-
const silgi2 = useSilgi();
|
|
254
|
-
return silgi2.options._eventContext?.get(key);
|
|
255
|
-
}
|
|
256
|
-
async addH3App(router) {
|
|
257
|
-
const silgi2 = useSilgi();
|
|
258
|
-
silgi2.options.h3Router = router;
|
|
259
|
-
await silgi2.callHook("h3:app:setup", router);
|
|
260
|
-
}
|
|
261
|
-
async addNitroApp(nitro) {
|
|
262
|
-
const ctx = useSilgi();
|
|
263
|
-
ctx.options.nitro = nitro;
|
|
264
|
-
nitro.router.use("/srn/**", defineEventHandler({
|
|
265
|
-
handler: async (event) => {
|
|
266
|
-
const ctx2 = useSilgi();
|
|
267
|
-
if (ctx2.options.environment === "nitrojs" || ctx2.options.environment === "h3") {
|
|
268
|
-
const silgiConnect = silgi(event);
|
|
269
|
-
const query = getQuery(event);
|
|
270
|
-
const body = await readBody(event).catch(() => {
|
|
271
|
-
});
|
|
272
|
-
let newPath = event.path;
|
|
273
|
-
if (event.path.includes("?")) {
|
|
274
|
-
newPath = `${event.path}&method=${event.method}`;
|
|
275
|
-
} else {
|
|
276
|
-
newPath = `${event.path}?method=${event.method}`;
|
|
277
|
-
}
|
|
278
|
-
const data = await silgiConnect.execute(newPath, {
|
|
279
|
-
...query,
|
|
280
|
-
...body
|
|
281
|
-
});
|
|
282
|
-
if (data.success) {
|
|
283
|
-
return data.data;
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
path: event.path,
|
|
287
|
-
method: event.method,
|
|
288
|
-
body,
|
|
289
|
-
query,
|
|
290
|
-
...data
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}));
|
|
295
|
-
await ctx.callHook("h3:app:setup", nitro.router);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* [...router.ts] tum router tarayan ve ona gore isteklere yonlendiren alan.
|
|
299
|
-
*/
|
|
300
|
-
// methods: ["delete", "get", "head", "options", "patch", "post", "put"]
|
|
301
|
-
async handler(_request) {
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const silgiHooks = [
|
|
306
|
-
"close",
|
|
307
|
-
"ready",
|
|
308
|
-
"event:before",
|
|
309
|
-
"app:setup:start",
|
|
310
|
-
/* plugin hooks */
|
|
311
|
-
"module:register:after",
|
|
312
|
-
"module:register:before",
|
|
313
|
-
"module:setup:finish",
|
|
314
|
-
"module:error",
|
|
315
|
-
"module:before:excute",
|
|
316
|
-
"module:after:excute",
|
|
317
|
-
/* method hooks */
|
|
318
|
-
"method:after",
|
|
319
|
-
"method:before",
|
|
320
|
-
"method:error",
|
|
321
|
-
"method:finally",
|
|
322
|
-
"h3:app:setup",
|
|
323
|
-
// Kit
|
|
324
|
-
"kit:compatibility"
|
|
325
|
-
];
|
|
326
|
-
|
|
327
|
-
const version = "0.0.1";
|
|
328
|
-
async function createSilgi(config) {
|
|
329
|
-
const hooks = createHooks();
|
|
330
|
-
await applyDefaults(SilgiConfigSchema, config.options);
|
|
331
|
-
const silgi = {
|
|
332
|
-
schemas: config.schemas,
|
|
333
|
-
_version: version,
|
|
334
|
-
services: config.services,
|
|
335
|
-
shared: config.shared,
|
|
336
|
-
uris: config.uris,
|
|
337
|
-
scannedHandlers: /* @__PURE__ */ new Map(),
|
|
338
|
-
storage: undefined,
|
|
339
|
-
_initializedModules: config._initializedModules,
|
|
340
|
-
options: config.options,
|
|
341
|
-
hooks,
|
|
342
|
-
hooksNames: silgiHooks,
|
|
343
|
-
callHook: hooks.callHook,
|
|
344
|
-
addHooks: hooks.addHooks,
|
|
345
|
-
hook: hooks.hook,
|
|
346
|
-
ready: () => {
|
|
347
|
-
return hooks.callHook("ready", silgi);
|
|
348
|
-
},
|
|
349
|
-
close: () => hooks.callHook("close", silgi),
|
|
350
|
-
logger: createConsola(defu(config.options.consolaOptions, {
|
|
351
|
-
tag: "silgi"
|
|
352
|
-
})).withTag("silgi")
|
|
353
|
-
// TODO: shared, uris, services burada olacak
|
|
354
|
-
};
|
|
355
|
-
await scanAction(silgi);
|
|
356
|
-
silgi.storage = await createStorage(silgi);
|
|
357
|
-
silgi.shared.storage = (...data) => {
|
|
358
|
-
return useStorage(...data);
|
|
359
|
-
};
|
|
360
|
-
if (silgiCtx.tryUse()) {
|
|
361
|
-
silgiCtx.unset();
|
|
362
|
-
silgiCtx.set(silgi);
|
|
363
|
-
} else {
|
|
364
|
-
silgiCtx.set(silgi);
|
|
365
|
-
silgi.hook("close", () => silgiCtx.unset());
|
|
366
|
-
}
|
|
367
|
-
silgi.options.helper = new SilgiHelper();
|
|
368
|
-
await installModules(silgi);
|
|
369
|
-
silgi.logger.info("Silgi installed");
|
|
370
|
-
hooks.hookOnce("close", async () => {
|
|
371
|
-
hooks.removeAllHooks();
|
|
372
|
-
await silgi.storage.dispose();
|
|
373
|
-
});
|
|
374
|
-
return silgi.options.helper;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function silgiFetchRequestInterceptor(ctx) {
|
|
378
|
-
ctx.request = fillPath(ctx.request, ctx.options.path);
|
|
379
|
-
}
|
|
380
|
-
function createSilgiFetch(options, localFetch) {
|
|
381
|
-
return (url, opts = {}) => {
|
|
382
|
-
opts = typeof options === "function" ? options(opts) : { ...options, ...opts };
|
|
383
|
-
if (!opts.method)
|
|
384
|
-
opts.method = "get";
|
|
385
|
-
const $fetch = getFetch(url, opts, localFetch);
|
|
386
|
-
return $fetch(fillPath(url, opts?.path), opts);
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
function getFetch(url, opts, localFetch) {
|
|
390
|
-
if (import.meta.server && localFetch) {
|
|
391
|
-
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
|
|
392
|
-
if (isLocalFetch)
|
|
393
|
-
return localFetch;
|
|
394
|
-
}
|
|
395
|
-
return globalThis.$fetch;
|
|
396
|
-
}
|
|
397
|
-
function fillPath(path, params = {}) {
|
|
398
|
-
for (const [k, v] of Object.entries(params))
|
|
399
|
-
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
|
|
400
|
-
return path;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function defineSilgiModule(definition) {
|
|
404
|
-
if (definition) {
|
|
405
|
-
return _defineSilgiModule(definition);
|
|
406
|
-
}
|
|
407
|
-
return {
|
|
408
|
-
with: (definition2) => _defineSilgiModule(definition2)
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function _defineSilgiModule(definition) {
|
|
412
|
-
if (typeof definition === "function") {
|
|
413
|
-
return _defineSilgiModule({ setup: definition });
|
|
414
|
-
}
|
|
415
|
-
const module = defu$1(definition, { meta: {} });
|
|
416
|
-
module.meta.configKey ||= module.meta.name;
|
|
417
|
-
async function getOptions(inlineOptions, silgi = useSilgi()) {
|
|
418
|
-
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
419
|
-
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
420
|
-
const optionsDefaults = module.defaults instanceof Function ? await module.defaults(silgi) : module.defaults ?? {};
|
|
421
|
-
const options = defu$1(inlineOptions, nuxtConfigOptions, optionsDefaults);
|
|
422
|
-
return Promise.resolve(options);
|
|
423
|
-
}
|
|
424
|
-
async function normalizedModule(inlineOptions, silgi = tryUseSilgi(), cli = false) {
|
|
425
|
-
if (!silgi) {
|
|
426
|
-
throw new TypeError("Cannot use module outside of Silgi context");
|
|
427
|
-
}
|
|
428
|
-
const uniqueKey = module.meta.configKey || module.meta.name;
|
|
429
|
-
if (uniqueKey) {
|
|
430
|
-
silgi.options._requiredModules ||= {};
|
|
431
|
-
if (silgi.options._requiredModules[uniqueKey]) {
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
silgi.options._requiredModules[uniqueKey] = true;
|
|
435
|
-
}
|
|
436
|
-
if (module.meta.compatibility) {
|
|
437
|
-
const issues = await checkSilgiCompatibility(module.meta.compatibility, silgi);
|
|
438
|
-
if (issues.length) {
|
|
439
|
-
silgi.logger.warn(`Module \`${module.meta.name}\` is disabled due to incompatibility issues:
|
|
440
|
-
${issues.toString()}`);
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
const _options = await getOptions(inlineOptions, silgi);
|
|
445
|
-
if (module.hooks) {
|
|
446
|
-
silgi.hooks.addHooks(module.hooks);
|
|
447
|
-
}
|
|
448
|
-
const start = performance.now();
|
|
449
|
-
const res = cli ? await module.cli?.call(null, _options, silgi) ?? {} : await module.setup?.call(null, _options, silgi) ?? {};
|
|
450
|
-
const perf = performance.now() - start;
|
|
451
|
-
const setupTime = Math.round(perf * 100) / 100;
|
|
452
|
-
if (setupTime > 5e3 && uniqueKey !== "@silgi/telemetry") {
|
|
453
|
-
silgi.logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
454
|
-
} else if (silgi.options.debug) {
|
|
455
|
-
silgi.logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
456
|
-
}
|
|
457
|
-
if (res === false) {
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
460
|
-
return defu$1(res, {
|
|
461
|
-
timings: {
|
|
462
|
-
setup: setupTime
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
normalizedModule.getMeta = () => Promise.resolve(module.meta);
|
|
467
|
-
normalizedModule.getOptions = getOptions;
|
|
468
|
-
normalizedModule.cli = normalizedModule;
|
|
469
|
-
return normalizedModule;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function merge(items) {
|
|
473
|
-
return Object.assign({}, ...Array.isArray(items) ? items : [items]);
|
|
474
|
-
}
|
|
475
|
-
function mergeSchemas(typesOrArray) {
|
|
476
|
-
return merge(typesOrArray);
|
|
477
|
-
}
|
|
478
|
-
function mergeServices(servicesOrArray) {
|
|
479
|
-
return merge(servicesOrArray);
|
|
480
|
-
}
|
|
481
|
-
function mergeShared(sharedOrArray) {
|
|
482
|
-
return merge(sharedOrArray);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function createService(variables) {
|
|
486
|
-
return variables;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function createShared(shared) {
|
|
490
|
-
return shared;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function createSchema(silgiType) {
|
|
494
|
-
return silgiType;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
const types = [
|
|
498
|
-
"ExtractInputFromURI",
|
|
499
|
-
"ExtractOutputFromURI",
|
|
500
|
-
"ExtractRouterParamsFromURI"
|
|
501
|
-
];
|
|
502
|
-
|
|
503
|
-
export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, silgiFetchRequestInterceptor, tryUseSilgi, types, useSilgi };
|