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.
Files changed (83) hide show
  1. package/dist/_chunks/index.mjs +5 -0
  2. package/dist/cli/{utils/compatibility.mjs → compatibility.mjs} +1 -1
  3. package/dist/cli/config/index.d.mts +11 -0
  4. package/dist/cli/config/index.d.ts +11 -0
  5. package/dist/{core/config/types.mjs → cli/config/index.mjs} +19 -2
  6. package/dist/cli/index.mjs +3 -3
  7. package/dist/cli/loader.mjs +581 -0
  8. package/dist/cli/prepare.mjs +1621 -0
  9. package/dist/core/index.d.mts +2 -37
  10. package/dist/core/index.d.ts +2 -37
  11. package/dist/core/index.mjs +809 -16
  12. package/dist/ecosystem/nitro/index.mjs +62 -1
  13. package/dist/ecosystem/nuxt/module.mjs +1 -1
  14. package/dist/kit/index.mjs +299 -10
  15. package/dist/meta/index.d.mts +1 -1
  16. package/dist/meta/index.d.ts +1 -1
  17. package/dist/meta/index.mjs +1 -1
  18. package/package.json +5 -1
  19. package/dist/cli/build/framework/h3.mjs +0 -46
  20. package/dist/cli/build/framework/index.mjs +0 -7
  21. package/dist/cli/build/framework/nitro.mjs +0 -28
  22. package/dist/cli/build/framework/nuxt.mjs +0 -9
  23. package/dist/cli/build/prepare.mjs +0 -7
  24. package/dist/cli/build/scanURIs.mjs +0 -27
  25. package/dist/cli/build/template/framework.mjs +0 -91
  26. package/dist/cli/build/template/schema.mjs +0 -115
  27. package/dist/cli/build/template/silgi.mjs +0 -149
  28. package/dist/cli/build/types.mjs +0 -130
  29. package/dist/cli/commands/prepare.mjs +0 -49
  30. package/dist/cli/common.mjs +0 -13
  31. package/dist/cli/core/app.mjs +0 -89
  32. package/dist/cli/core/scan.mjs +0 -40
  33. package/dist/cli/core/silgi.mjs +0 -77
  34. package/dist/cli/core/storage.mjs +0 -11
  35. package/dist/cli/core/templates.mjs +0 -29
  36. package/dist/cli/module/exportScan.mjs +0 -69
  37. package/dist/cli/module/install.mjs +0 -52
  38. package/dist/cli/module/scan.mjs +0 -141
  39. package/dist/cli/utils/generateRouterDTS.mjs +0 -84
  40. package/dist/cli/utils/ignore.mjs +0 -46
  41. package/dist/cli/utils/readCoreFile.mjs +0 -47
  42. package/dist/cli/utils/scan.mjs +0 -147
  43. package/dist/cli/utils/storage.mjs +0 -21
  44. package/dist/cli/utils/uri.mjs +0 -71
  45. package/dist/core/config/defaults.mjs +0 -96
  46. package/dist/core/config/loader.mjs +0 -98
  47. package/dist/core/config/resolvers/compatibility.mjs +0 -90
  48. package/dist/core/config/resolvers/imports.mjs +0 -96
  49. package/dist/core/config/resolvers/paths.mjs +0 -194
  50. package/dist/core/config/resolvers/storage.mjs +0 -25
  51. package/dist/core/config/resolvers/url.mjs +0 -7
  52. package/dist/core/createSilgi.mjs +0 -84
  53. package/dist/core/error.mjs +0 -227
  54. package/dist/core/fetch/ofetch.mjs +0 -35
  55. package/dist/core/parser.mjs +0 -136
  56. package/dist/core/silgi.mjs +0 -114
  57. package/dist/core/silgiApp.mjs +0 -15
  58. package/dist/core/unctx.mjs +0 -27
  59. package/dist/core/uris/uri.mjs +0 -33
  60. package/dist/core/uris/utils.mjs +0 -127
  61. package/dist/core/utils/event.mjs +0 -5
  62. package/dist/core/utils/global.mjs +0 -12
  63. package/dist/core/utils/merge.mjs +0 -25
  64. package/dist/core/utils/schema.mjs +0 -5
  65. package/dist/core/utils/service.mjs +0 -5
  66. package/dist/core/utils/shared.mjs +0 -5
  67. package/dist/core/utils/storage.mjs +0 -70
  68. package/dist/ecosystem/nitro/module.mjs +0 -62
  69. package/dist/kit/esm.mjs +0 -10
  70. package/dist/kit/fs.mjs +0 -25
  71. package/dist/kit/isFramework.mjs +0 -25
  72. package/dist/kit/logger.mjs +0 -8
  73. package/dist/kit/module.mjs +0 -73
  74. package/dist/kit/path.mjs +0 -34
  75. package/dist/kit/preset.mjs +0 -6
  76. package/dist/kit/resolve.mjs +0 -78
  77. package/dist/kit/template.mjs +0 -47
  78. package/dist/kit/utils.mjs +0 -20
  79. package/dist/package.json.mjs +0 -5
  80. package/dist/schema/common.mjs +0 -43
  81. package/dist/schema/index.mjs +0 -9
  82. package/dist/schema/internal.mjs +0 -22
  83. /package/dist/cli/{commands/init.mjs → init.mjs} +0 -0
@@ -1,84 +0,0 @@
1
- import { createConsola } from 'consola';
2
- import defu from 'defu';
3
- import { isEvent } from 'h3';
4
- import { createHooks } from 'hookable';
5
- import { applyDefaults } from 'untyped';
6
- import { SilgiConfigSchema } from '../schema/index.mjs';
7
- import { silgiCtx } from './unctx.mjs';
8
- import { scanAction } from './uris/uri.mjs';
9
- import { createStorage, useSilgiStorage } from './utils/storage.mjs';
10
-
11
- async function runSilgiPlugins(silgi) {
12
- for (const plugin of silgi.plugins) {
13
- try {
14
- await plugin(silgi);
15
- } catch (error) {
16
- silgi.captureError(error, { tags: ["plugin"] });
17
- throw error;
18
- }
19
- }
20
- }
21
- async function createSilgi(config) {
22
- const hooks = createHooks();
23
- await applyDefaults(SilgiConfigSchema, config.options);
24
- const silgi = {
25
- schemas: config.schemas,
26
- services: config.services ?? {},
27
- shared: config.shared ?? void 0,
28
- uris: config.uris ?? {},
29
- modulesURIs: config.modulesURIs ?? {},
30
- scannedHandlers: /* @__PURE__ */ new Map(),
31
- plugins: config.plugins ?? [],
32
- framework: config.framework ?? void 0,
33
- storage: config.storage ?? void 0,
34
- options: config.options,
35
- hooks,
36
- callHook: hooks.callHook,
37
- addHooks: hooks.addHooks,
38
- hook: hooks.hook,
39
- ready: () => {
40
- return hooks.callHook("ready", silgi);
41
- },
42
- close: () => hooks.callHook("close", silgi),
43
- logger: createConsola(defu(config.options.consolaOptions, {
44
- tag: "silgi"
45
- })).withTag("silgi"),
46
- captureError: (error, context = {}) => {
47
- const promise = hooks.callHookParallel("error", error, context).catch((error_) => {
48
- console.error("Error while capturing another error", error_);
49
- });
50
- if (context.event && isEvent(context.event)) {
51
- const errors = context.event.context.nitro?.errors;
52
- if (errors) {
53
- errors.push({ error, context });
54
- }
55
- if (context.event.waitUntil) {
56
- context.event.waitUntil(promise);
57
- }
58
- }
59
- }
60
- };
61
- await runSilgiPlugins(silgi);
62
- await scanAction(silgi);
63
- if (!silgi.storage) {
64
- silgi.storage = await createStorage(silgi);
65
- }
66
- silgi.shared.storage = (...data) => {
67
- return useSilgiStorage(...data);
68
- };
69
- if (silgiCtx.tryUse()) {
70
- silgiCtx.unset();
71
- silgiCtx.set(silgi);
72
- } else {
73
- silgiCtx.set(silgi);
74
- silgi.hook("close", () => silgiCtx.unset());
75
- }
76
- silgi.logger.info("Silgi installed");
77
- hooks.hookOnce("close", async () => {
78
- hooks.removeAllHooks();
79
- await silgi.storage.dispose();
80
- });
81
- return silgi;
82
- }
83
-
84
- export { createSilgi };
@@ -1,227 +0,0 @@
1
- var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
2
- HttpStatus2[HttpStatus2["CONTINUE"] = 100] = "CONTINUE";
3
- HttpStatus2[HttpStatus2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
4
- HttpStatus2[HttpStatus2["PROCESSING"] = 102] = "PROCESSING";
5
- HttpStatus2[HttpStatus2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
6
- HttpStatus2[HttpStatus2["OK"] = 200] = "OK";
7
- HttpStatus2[HttpStatus2["CREATED"] = 201] = "CREATED";
8
- HttpStatus2[HttpStatus2["ACCEPTED"] = 202] = "ACCEPTED";
9
- HttpStatus2[HttpStatus2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
10
- HttpStatus2[HttpStatus2["NO_CONTENT"] = 204] = "NO_CONTENT";
11
- HttpStatus2[HttpStatus2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
12
- HttpStatus2[HttpStatus2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
13
- HttpStatus2[HttpStatus2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
14
- HttpStatus2[HttpStatus2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
15
- HttpStatus2[HttpStatus2["IM_USED"] = 226] = "IM_USED";
16
- HttpStatus2[HttpStatus2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
17
- HttpStatus2[HttpStatus2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
18
- HttpStatus2[HttpStatus2["FOUND"] = 302] = "FOUND";
19
- HttpStatus2[HttpStatus2["SEE_OTHER"] = 303] = "SEE_OTHER";
20
- HttpStatus2[HttpStatus2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
21
- HttpStatus2[HttpStatus2["USE_PROXY"] = 305] = "USE_PROXY";
22
- HttpStatus2[HttpStatus2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
23
- HttpStatus2[HttpStatus2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
24
- HttpStatus2[HttpStatus2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
25
- HttpStatus2[HttpStatus2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
26
- HttpStatus2[HttpStatus2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
27
- HttpStatus2[HttpStatus2["FORBIDDEN"] = 403] = "FORBIDDEN";
28
- HttpStatus2[HttpStatus2["NOT_FOUND"] = 404] = "NOT_FOUND";
29
- HttpStatus2[HttpStatus2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
30
- HttpStatus2[HttpStatus2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
31
- HttpStatus2[HttpStatus2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
32
- HttpStatus2[HttpStatus2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
33
- HttpStatus2[HttpStatus2["CONFLICT"] = 409] = "CONFLICT";
34
- HttpStatus2[HttpStatus2["GONE"] = 410] = "GONE";
35
- HttpStatus2[HttpStatus2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
36
- HttpStatus2[HttpStatus2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
37
- HttpStatus2[HttpStatus2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
38
- HttpStatus2[HttpStatus2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
39
- HttpStatus2[HttpStatus2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
40
- HttpStatus2[HttpStatus2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
41
- HttpStatus2[HttpStatus2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
42
- HttpStatus2[HttpStatus2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
43
- HttpStatus2[HttpStatus2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
44
- HttpStatus2[HttpStatus2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
45
- HttpStatus2[HttpStatus2["LOCKED"] = 423] = "LOCKED";
46
- HttpStatus2[HttpStatus2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
47
- HttpStatus2[HttpStatus2["TOO_EARLY"] = 425] = "TOO_EARLY";
48
- HttpStatus2[HttpStatus2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
49
- HttpStatus2[HttpStatus2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
50
- HttpStatus2[HttpStatus2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
51
- HttpStatus2[HttpStatus2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
52
- HttpStatus2[HttpStatus2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
53
- HttpStatus2[HttpStatus2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
54
- HttpStatus2[HttpStatus2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
55
- HttpStatus2[HttpStatus2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
56
- HttpStatus2[HttpStatus2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
57
- HttpStatus2[HttpStatus2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
58
- HttpStatus2[HttpStatus2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
59
- HttpStatus2[HttpStatus2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
60
- HttpStatus2[HttpStatus2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
61
- HttpStatus2[HttpStatus2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
62
- HttpStatus2[HttpStatus2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
63
- HttpStatus2[HttpStatus2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
64
- return HttpStatus2;
65
- })(HttpStatus || {});
66
- var ErrorSeverity = /* @__PURE__ */ ((ErrorSeverity2) => {
67
- ErrorSeverity2["DEBUG"] = "DEBUG";
68
- ErrorSeverity2["INFO"] = "INFO";
69
- ErrorSeverity2["WARNING"] = "WARNING";
70
- ErrorSeverity2["ERROR"] = "ERROR";
71
- ErrorSeverity2["CRITICAL"] = "CRITICAL";
72
- return ErrorSeverity2;
73
- })(ErrorSeverity || {});
74
- var ErrorCategory = /* @__PURE__ */ ((ErrorCategory2) => {
75
- ErrorCategory2["AUTHENTICATION"] = "auth";
76
- ErrorCategory2["AUTHORIZATION"] = "authorization";
77
- ErrorCategory2["VALIDATION"] = "validation";
78
- ErrorCategory2["BUSINESS"] = "business";
79
- ErrorCategory2["INFRASTRUCTURE"] = "infrastructure";
80
- ErrorCategory2["EXTERNAL"] = "external";
81
- ErrorCategory2["UNKNOWN"] = "unknown";
82
- return ErrorCategory2;
83
- })(ErrorCategory || {});
84
- class ErrorFactory {
85
- static createMetadata(metadata) {
86
- return {
87
- timestamp: Date.now(),
88
- ...metadata
89
- };
90
- }
91
- static create(options) {
92
- return new SilgiError({
93
- code: options.code ?? options.httpStatus ?? 500 /* INTERNAL_SERVER_ERROR */,
94
- message: options.message,
95
- category: options.category ?? "unknown" /* UNKNOWN */,
96
- severity: options.severity ?? "ERROR" /* ERROR */,
97
- httpStatus: options.httpStatus ?? 500 /* INTERNAL_SERVER_ERROR */,
98
- metadata: this.createMetadata(options.metadata),
99
- cause: options.cause,
100
- context: options.context
101
- });
102
- }
103
- // Predefined error creators
104
- static authenticationError(message, context) {
105
- return this.create({
106
- message,
107
- code: 401,
108
- category: "auth" /* AUTHENTICATION */,
109
- severity: "ERROR" /* ERROR */,
110
- httpStatus: 401 /* UNAUTHORIZED */,
111
- context
112
- });
113
- }
114
- static authorizationError(message, context) {
115
- return this.create({
116
- message,
117
- code: 403,
118
- category: "authorization" /* AUTHORIZATION */,
119
- severity: "ERROR" /* ERROR */,
120
- httpStatus: 403 /* FORBIDDEN */,
121
- context
122
- });
123
- }
124
- static validationError(message, context) {
125
- return this.create({
126
- message,
127
- code: 400,
128
- category: "validation" /* VALIDATION */,
129
- severity: "WARNING" /* WARNING */,
130
- httpStatus: 400 /* BAD_REQUEST */,
131
- context
132
- });
133
- }
134
- static notFoundError(message, context) {
135
- return this.create({
136
- message,
137
- code: 404,
138
- category: "business" /* BUSINESS */,
139
- severity: "WARNING" /* WARNING */,
140
- httpStatus: 404 /* NOT_FOUND */,
141
- context
142
- });
143
- }
144
- static internalError(message, cause) {
145
- return this.create({
146
- message,
147
- code: 500,
148
- category: "infrastructure" /* INFRASTRUCTURE */,
149
- severity: "CRITICAL" /* CRITICAL */,
150
- httpStatus: 500 /* INTERNAL_SERVER_ERROR */,
151
- cause
152
- });
153
- }
154
- }
155
- class SilgiError extends Error {
156
- code;
157
- category;
158
- severity;
159
- httpStatus;
160
- metadata;
161
- context;
162
- cause;
163
- constructor(error) {
164
- super(error.message);
165
- this.name = "SilgiError";
166
- this.code = error.code;
167
- this.category = error.category;
168
- this.severity = error.severity;
169
- this.httpStatus = error.httpStatus;
170
- this.metadata = error.metadata ?? { timestamp: Date.now() };
171
- this.context = error.context;
172
- this.cause = error.cause;
173
- if (Error.captureStackTrace) {
174
- Error.captureStackTrace(this, this.constructor);
175
- }
176
- }
177
- toString() {
178
- let str = `${this.name} [${this.code}] ${this.severity}: ${this.message}`;
179
- str += `
180
- Category: ${this.category}`;
181
- str += `
182
- HTTP Status: ${this.httpStatus}`;
183
- if (this.context) {
184
- str += `
185
- Context: ${JSON.stringify(this.context, null, 2)}`;
186
- }
187
- if (this.metadata) {
188
- str += `
189
- Metadata: ${JSON.stringify(this.metadata, null, 2)}`;
190
- }
191
- if (this.stack) {
192
- str += `
193
- ${this.stack}`;
194
- }
195
- return str;
196
- }
197
- toJSON() {
198
- return {
199
- name: this.name,
200
- code: this.code,
201
- message: this.message,
202
- category: this.category,
203
- severity: this.severity,
204
- httpStatus: this.httpStatus,
205
- metadata: this.metadata,
206
- context: this.context,
207
- stack: this.stack
208
- };
209
- }
210
- static isError(error) {
211
- return error instanceof SilgiError;
212
- }
213
- static from(error) {
214
- if (error instanceof SilgiError) {
215
- return error;
216
- }
217
- return ErrorFactory.internalError(
218
- error instanceof Error ? error.message : String(error),
219
- error instanceof Error ? error : void 0
220
- );
221
- }
222
- }
223
- function isBaseError(error) {
224
- return typeof error === "object" && error !== null && "code" in error && "message" in error && "category" in error && "severity" in error && "httpStatus" in error;
225
- }
226
-
227
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, isBaseError };
@@ -1,35 +0,0 @@
1
- function createSilgiFetch(options, localFetch) {
2
- return (url, opts) => {
3
- const finalOpts = {
4
- ...typeof options === "function" ? options(opts) : options,
5
- ...opts,
6
- method: opts.method || "get"
7
- };
8
- const $fetch = getFetch(url, finalOpts, localFetch);
9
- return $fetch(fillPath(url, opts.params), finalOpts);
10
- };
11
- }
12
- function getFetch(url, opts, localFetch) {
13
- if (import.meta.server && localFetch) {
14
- const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
15
- if (isLocalFetch)
16
- return localFetch;
17
- }
18
- return globalThis.$fetch;
19
- }
20
- function fillPath(path, params) {
21
- if (!params) {
22
- if (path.includes(":"))
23
- throw new Error("Parametreler dogru kullanmal\u0131s\u0131n\u0131z");
24
- return path;
25
- }
26
- if (!path.includes(":"))
27
- throw new Error("Path parametler : ile belirtilmelidir");
28
- let result = path;
29
- for (const [key, value] of Object.entries(params)) {
30
- result = result.replace(`:${key}`, value);
31
- }
32
- return result;
33
- }
34
-
35
- export { createSilgiFetch };
@@ -1,136 +0,0 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { parseSync } from '@oxc-parser/wasm';
3
-
4
- class SchemaParser {
5
- options = {
6
- debug: false
7
- };
8
- /**
9
- *
10
- */
11
- constructor(options) {
12
- this.options = {
13
- ...this.options,
14
- ...options
15
- };
16
- }
17
- parseExports(content, filePath) {
18
- const ast = parseSync(content, { sourceType: "module", sourceFilename: filePath });
19
- if (this.options.debug)
20
- writeFileSync(`${filePath}.ast.json`, JSON.stringify(ast.program, null, 2));
21
- return {
22
- exportVariables: (search, path) => this.parseTypeDeclarations(ast, search, path),
23
- parseInterfaceDeclarations: (search, path) => this.parseInterfaceDeclarations(ast, search, path)
24
- // parsePlugin: (path: string) => this.parsePlugin(ast, path),
25
- };
26
- }
27
- parseVariableDeclaration(ast) {
28
- return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
29
- }
30
- parseTSInterfaceDeclaration(ast) {
31
- return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
32
- }
33
- parseTypeDeclarations(ast, find = "", path = "") {
34
- const data = [];
35
- for (const item of this.parseVariableDeclaration(ast)) {
36
- for (const declaration of item.declaration.declarations) {
37
- if (declaration.init?.callee?.name === find) {
38
- const options = {};
39
- if (declaration.init.arguments) {
40
- for (const argument of declaration.init.arguments) {
41
- for (const propertie of argument.properties) {
42
- if (propertie.key.name === "name")
43
- options.pluginName = propertie.value.value;
44
- }
45
- }
46
- }
47
- for (const key in declaration.init.properties) {
48
- const property = declaration.init.properties[key];
49
- if (property.type === "ObjectProperty") {
50
- if (property.key.name === "options") {
51
- for (const key2 in property.value.properties) {
52
- const option = property.value.properties[key2];
53
- if (option.type === "ObjectProperty") {
54
- options[option.key.name] = option.value.value;
55
- }
56
- }
57
- }
58
- }
59
- }
60
- options.type = false;
61
- data.push({
62
- exportName: declaration.id.name,
63
- options,
64
- // object: declaration.init,
65
- path
66
- });
67
- }
68
- }
69
- }
70
- return data;
71
- }
72
- parseInterfaceDeclarations(ast, find = "", path = "") {
73
- const data = [];
74
- for (const item of this.parseTSInterfaceDeclaration(ast)) {
75
- if (!item?.declaration?.extends)
76
- continue;
77
- for (const declaration of item?.declaration?.extends) {
78
- if (declaration.expression.name === find) {
79
- const options = {};
80
- options.type = true;
81
- data.push({
82
- exportName: item.declaration.id.name,
83
- options,
84
- // object: declaration.init,
85
- path
86
- });
87
- }
88
- }
89
- }
90
- return data;
91
- }
92
- // private parsePlugin(ast: any, path: string = '') {
93
- // const data = {
94
- // export: [],
95
- // name: '',
96
- // path: '',
97
- // } as DataTypePlugin
98
- // for (const item of this.parseVariableDeclaration(ast)) {
99
- // for (const declaration of item.declaration.declarations) {
100
- // if (declaration.init.callee?.name === 'defineSilgiModule') {
101
- // if (declaration.init.arguments) {
102
- // for (const argument of declaration.init.arguments) {
103
- // for (const propertie of argument.properties) {
104
- // if (propertie.key.name === 'name')
105
- // data.name = propertie.value.value
106
- // }
107
- // }
108
- // }
109
- // data.export.push({
110
- // name: data.name,
111
- // as: camelCase(`${data.name}DefineSilgiModule`),
112
- // type: false,
113
- // })
114
- // }
115
- // }
116
- // }
117
- // for (const item of this.parseTSInterfaceDeclaration(ast)) {
118
- // if (!item?.declaration?.extends)
119
- // continue
120
- // for (const declaration of item?.declaration?.extends) {
121
- // if (declaration.expression.name === 'ModuleOptions') {
122
- // data.export.push({
123
- // name: item.declaration.id.name,
124
- // as: camelCase(`${data.name}ModuleOptions`),
125
- // type: true,
126
- // })
127
- // }
128
- // // TODO add other plugins
129
- // }
130
- // }
131
- // data.path = path
132
- // return data
133
- // }
134
- }
135
-
136
- export { SchemaParser };
@@ -1,114 +0,0 @@
1
- import { ErrorFactory, HttpStatus, SilgiError } from './error.mjs';
2
- import { useSilgi, normalizeResult } from './unctx.mjs';
3
- import { parseURI } from './uris/utils.mjs';
4
- import { useSilgiStorage, generateStorageKey } from './utils/storage.mjs';
5
-
6
- function silgi(event) {
7
- return {
8
- execute: (uriString, input) => {
9
- return execute(uriString, input, event);
10
- }
11
- };
12
- }
13
- async function execute(uriString, input, event) {
14
- const silgiCtx = useSilgi();
15
- if (event) {
16
- await silgiCtx.callHook("event:before", event);
17
- }
18
- let success = false;
19
- let cached = false;
20
- let result;
21
- try {
22
- const operation = parseURI(uriString, silgiCtx.uris);
23
- if (!operation) {
24
- throw ErrorFactory.create({ message: "Invalid URI", httpStatus: HttpStatus.BAD_REQUEST });
25
- }
26
- const handler = silgiCtx.scannedHandlers.get(operation.uri);
27
- if (!handler) {
28
- throw ErrorFactory.create({
29
- message: "Action not found",
30
- httpStatus: HttpStatus.NOT_FOUND,
31
- context: {
32
- uri: uriString
33
- }
34
- });
35
- }
36
- await silgiCtx.callHook("action:before", {
37
- operation,
38
- input,
39
- event,
40
- modules: handler.modules,
41
- result
42
- });
43
- const cacheData = await cacheExecute(input, operation, handler, event);
44
- if (cacheData?.success) {
45
- result = cacheData.data;
46
- success = cacheData.success;
47
- cached = cacheData.cached;
48
- } else {
49
- const router = {
50
- params: operation.routerParams,
51
- query: operation.query
52
- };
53
- silgiCtx.shared.silgi = (_event) => silgi(_event || event);
54
- result = await handler?.handler(router, input, silgiCtx.shared, event);
55
- success = true;
56
- }
57
- await silgiCtx.callHook("action:after", {
58
- operation,
59
- input,
60
- event,
61
- result,
62
- success,
63
- modules: handler.modules
64
- });
65
- if (!cached) {
66
- if (success && cacheData?.cachedKey && handler.storage) {
67
- await useSilgiStorage(handler.storage.base).setItem(cacheData.cachedKey, result, handler.storage.options);
68
- }
69
- }
70
- return result;
71
- } catch (err) {
72
- await silgiCtx.callHook("action:error", {
73
- input,
74
- event,
75
- error: err instanceof Error ? err : new Error(String(err)),
76
- timestamp: Date.now()
77
- });
78
- silgiCtx.captureError(SilgiError.from(err), {
79
- event,
80
- tags: ["execute"]
81
- });
82
- throw err;
83
- }
84
- }
85
- async function cacheExecute(input, operation, handler, event) {
86
- if (!handler.storage)
87
- return;
88
- const cacheKey = handler.storage ? await generateStorageKey({
89
- operation,
90
- input,
91
- keyGenerator: handler.storage.key,
92
- storageOptions: handler.storage,
93
- requestId: event?.requestId
94
- }) : null;
95
- if (cacheKey) {
96
- const cachedResult = await useSilgiStorage(handler.storage.base).getItem(cacheKey);
97
- if (cachedResult !== null) {
98
- return {
99
- success: true,
100
- data: normalizeResult(cachedResult),
101
- cached: true,
102
- cachedKey: cacheKey
103
- };
104
- }
105
- }
106
- return {
107
- success: false,
108
- data: null,
109
- cached: false,
110
- cachedKey: cacheKey
111
- };
112
- }
113
-
114
- export { execute, silgi };
@@ -1,15 +0,0 @@
1
- import { getContext } from 'unctx';
2
-
3
- const silgiCLICtx = getContext("SilgiCLI");
4
- function useSilgiCLI() {
5
- const instance = silgiCLICtx.tryUse();
6
- if (!instance) {
7
- throw new Error("Silgi instance is unavailable!");
8
- }
9
- return instance;
10
- }
11
- function tryUseSilgiCLI() {
12
- return silgiCLICtx.tryUse();
13
- }
14
-
15
- export { silgiCLICtx, tryUseSilgiCLI, useSilgiCLI };
@@ -1,27 +0,0 @@
1
- import { getContext } from 'unctx';
2
-
3
- const silgiCtx = getContext("silgi");
4
- function useSilgi() {
5
- const instance = silgiCtx.tryUse();
6
- if (!instance) {
7
- throw new Error("Silgi instance is unavailable!");
8
- }
9
- return instance;
10
- }
11
- function normalizeResult(result) {
12
- if (Array.isArray(result)) {
13
- return [...result];
14
- }
15
- if (result && typeof result === "object") {
16
- if (Object.keys(result).every((key) => !Number.isNaN(Number(key)))) {
17
- return Object.values(result);
18
- }
19
- return { ...result };
20
- }
21
- return result;
22
- }
23
- function tryUseSilgi() {
24
- return silgiCtx.tryUse();
25
- }
26
-
27
- export { normalizeResult, silgiCtx, tryUseSilgi, useSilgi };
@@ -1,33 +0,0 @@
1
- import { parseURI } from './utils.mjs';
2
-
3
- async function findAction(silgi, uri) {
4
- const { parts } = parseURI(uri, silgi.uris);
5
- let result = silgi.services;
6
- for (const part of parts) {
7
- if (result && Object.prototype.hasOwnProperty.call(result, part)) {
8
- result = Object.assign({}, result[part]);
9
- } else {
10
- console.error("Property not found:", part);
11
- break;
12
- }
13
- }
14
- return result;
15
- }
16
- async function scanAction(silgi) {
17
- for (const [key, _value] of Object.entries(silgi.uris)) {
18
- const segments = key.split("/").filter(Boolean);
19
- if (segments.length !== 4) {
20
- console.error(`Invalid URI format for key "${key}". URI must have exactly 4 segments in format: namespace/service/method/action`);
21
- continue;
22
- }
23
- const [namespace, service, method, action] = segments;
24
- if (!namespace || !service || !method || !action) {
25
- console.error(`Invalid URI segments for key "${key}". All segments must be non-empty`);
26
- continue;
27
- }
28
- const handler = await findAction(silgi, key);
29
- silgi.scannedHandlers.set(key, handler);
30
- }
31
- }
32
-
33
- export { findAction, scanAction };