silgi 0.7.2 → 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 +1 -1
- package/dist/cli/prepare.mjs +135 -2
- package/dist/core/index.d.mts +1 -28
- package/dist/core/index.d.ts +1 -28
- package/dist/core/index.mjs +1 -135
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { defineCommand } from 'citty';
|
|
|
2
2
|
import { join, resolve, isAbsolute, relative, dirname, basename, extname } from 'pathe';
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
4
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
5
|
-
import { promises, existsSync, readFileSync,
|
|
5
|
+
import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
6
|
import { readdir } from 'node:fs/promises';
|
|
7
7
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
8
8
|
import { resolveAlias } from 'pathe/utils';
|
|
9
|
-
import { silgiGenerateType, useSilgiCLI,
|
|
9
|
+
import { silgiGenerateType, useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
10
10
|
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger } from 'silgi/kit';
|
|
11
11
|
import { toExports, scanExports, createUnimport } from 'unimport';
|
|
12
12
|
import { createJiti } from 'dev-jiti';
|
|
@@ -20,6 +20,7 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
|
20
20
|
import { isRelative, withTrailingSlash } from 'ufo';
|
|
21
21
|
import { globby } from 'globby';
|
|
22
22
|
import ignore from 'ignore';
|
|
23
|
+
import { parseSync } from '@oxc-parser/wasm';
|
|
23
24
|
import { klona } from 'klona';
|
|
24
25
|
import { createStorage, builtinDrivers } from 'unstorage';
|
|
25
26
|
import { l as loadOptions } from './loader.mjs';
|
|
@@ -1081,6 +1082,138 @@ function resolveGroupSyntax(group) {
|
|
|
1081
1082
|
return groups;
|
|
1082
1083
|
}
|
|
1083
1084
|
|
|
1085
|
+
class SchemaParser {
|
|
1086
|
+
options = {
|
|
1087
|
+
debug: false
|
|
1088
|
+
};
|
|
1089
|
+
/**
|
|
1090
|
+
*
|
|
1091
|
+
*/
|
|
1092
|
+
constructor(options) {
|
|
1093
|
+
this.options = {
|
|
1094
|
+
...this.options,
|
|
1095
|
+
...options
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
parseExports(content, filePath) {
|
|
1099
|
+
const ast = parseSync(content, { sourceType: "module", sourceFilename: filePath });
|
|
1100
|
+
if (this.options.debug)
|
|
1101
|
+
writeFileSync(`${filePath}.ast.json`, JSON.stringify(ast.program, null, 2));
|
|
1102
|
+
return {
|
|
1103
|
+
exportVariables: (search, path) => this.parseTypeDeclarations(ast, search, path),
|
|
1104
|
+
parseInterfaceDeclarations: (search, path) => this.parseInterfaceDeclarations(ast, search, path)
|
|
1105
|
+
// parsePlugin: (path: string) => this.parsePlugin(ast, path),
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
parseVariableDeclaration(ast) {
|
|
1109
|
+
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
|
|
1110
|
+
}
|
|
1111
|
+
parseTSInterfaceDeclaration(ast) {
|
|
1112
|
+
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
|
|
1113
|
+
}
|
|
1114
|
+
parseTypeDeclarations(ast, find = "", path = "") {
|
|
1115
|
+
const data = [];
|
|
1116
|
+
for (const item of this.parseVariableDeclaration(ast)) {
|
|
1117
|
+
for (const declaration of item.declaration.declarations) {
|
|
1118
|
+
if (declaration.init?.callee?.name === find) {
|
|
1119
|
+
const options = {};
|
|
1120
|
+
if (declaration.init.arguments) {
|
|
1121
|
+
for (const argument of declaration.init.arguments) {
|
|
1122
|
+
for (const propertie of argument.properties) {
|
|
1123
|
+
if (propertie.key.name === "name")
|
|
1124
|
+
options.pluginName = propertie.value.value;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
for (const key in declaration.init.properties) {
|
|
1129
|
+
const property = declaration.init.properties[key];
|
|
1130
|
+
if (property.type === "ObjectProperty") {
|
|
1131
|
+
if (property.key.name === "options") {
|
|
1132
|
+
for (const key2 in property.value.properties) {
|
|
1133
|
+
const option = property.value.properties[key2];
|
|
1134
|
+
if (option.type === "ObjectProperty") {
|
|
1135
|
+
options[option.key.name] = option.value.value;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
options.type = false;
|
|
1142
|
+
data.push({
|
|
1143
|
+
exportName: declaration.id.name,
|
|
1144
|
+
options,
|
|
1145
|
+
// object: declaration.init,
|
|
1146
|
+
path
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return data;
|
|
1152
|
+
}
|
|
1153
|
+
parseInterfaceDeclarations(ast, find = "", path = "") {
|
|
1154
|
+
const data = [];
|
|
1155
|
+
for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
1156
|
+
if (!item?.declaration?.extends)
|
|
1157
|
+
continue;
|
|
1158
|
+
for (const declaration of item?.declaration?.extends) {
|
|
1159
|
+
if (declaration.expression.name === find) {
|
|
1160
|
+
const options = {};
|
|
1161
|
+
options.type = true;
|
|
1162
|
+
data.push({
|
|
1163
|
+
exportName: item.declaration.id.name,
|
|
1164
|
+
options,
|
|
1165
|
+
// object: declaration.init,
|
|
1166
|
+
path
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return data;
|
|
1172
|
+
}
|
|
1173
|
+
// private parsePlugin(ast: any, path: string = '') {
|
|
1174
|
+
// const data = {
|
|
1175
|
+
// export: [],
|
|
1176
|
+
// name: '',
|
|
1177
|
+
// path: '',
|
|
1178
|
+
// } as DataTypePlugin
|
|
1179
|
+
// for (const item of this.parseVariableDeclaration(ast)) {
|
|
1180
|
+
// for (const declaration of item.declaration.declarations) {
|
|
1181
|
+
// if (declaration.init.callee?.name === 'defineSilgiModule') {
|
|
1182
|
+
// if (declaration.init.arguments) {
|
|
1183
|
+
// for (const argument of declaration.init.arguments) {
|
|
1184
|
+
// for (const propertie of argument.properties) {
|
|
1185
|
+
// if (propertie.key.name === 'name')
|
|
1186
|
+
// data.name = propertie.value.value
|
|
1187
|
+
// }
|
|
1188
|
+
// }
|
|
1189
|
+
// }
|
|
1190
|
+
// data.export.push({
|
|
1191
|
+
// name: data.name,
|
|
1192
|
+
// as: camelCase(`${data.name}DefineSilgiModule`),
|
|
1193
|
+
// type: false,
|
|
1194
|
+
// })
|
|
1195
|
+
// }
|
|
1196
|
+
// }
|
|
1197
|
+
// }
|
|
1198
|
+
// for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
1199
|
+
// if (!item?.declaration?.extends)
|
|
1200
|
+
// continue
|
|
1201
|
+
// for (const declaration of item?.declaration?.extends) {
|
|
1202
|
+
// if (declaration.expression.name === 'ModuleOptions') {
|
|
1203
|
+
// data.export.push({
|
|
1204
|
+
// name: item.declaration.id.name,
|
|
1205
|
+
// as: camelCase(`${data.name}ModuleOptions`),
|
|
1206
|
+
// type: true,
|
|
1207
|
+
// })
|
|
1208
|
+
// }
|
|
1209
|
+
// // TODO add other plugins
|
|
1210
|
+
// }
|
|
1211
|
+
// }
|
|
1212
|
+
// data.path = path
|
|
1213
|
+
// return data
|
|
1214
|
+
// }
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1084
1217
|
async function scanFiles$1(silgi) {
|
|
1085
1218
|
const filePaths = /* @__PURE__ */ new Set();
|
|
1086
1219
|
const scannedPaths = [];
|
package/dist/core/index.d.mts
CHANGED
|
@@ -37,33 +37,6 @@ type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
|
37
37
|
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
38
38
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
39
39
|
|
|
40
|
-
interface Options {
|
|
41
|
-
debug?: boolean;
|
|
42
|
-
}
|
|
43
|
-
interface DataType {
|
|
44
|
-
exportName: string;
|
|
45
|
-
options: {
|
|
46
|
-
type: boolean;
|
|
47
|
-
pluginName?: string;
|
|
48
|
-
};
|
|
49
|
-
path: string;
|
|
50
|
-
}
|
|
51
|
-
declare class SchemaParser {
|
|
52
|
-
options: Options;
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
constructor(options?: Options);
|
|
57
|
-
parseExports(content: string, filePath: string): {
|
|
58
|
-
exportVariables: (search: string, path: string) => DataType[];
|
|
59
|
-
parseInterfaceDeclarations: (search: string, path: string) => DataType[];
|
|
60
|
-
};
|
|
61
|
-
private parseVariableDeclaration;
|
|
62
|
-
private parseTSInterfaceDeclaration;
|
|
63
|
-
private parseTypeDeclarations;
|
|
64
|
-
private parseInterfaceDeclarations;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
40
|
interface RouteTemplateValidator {
|
|
68
41
|
(value: string): boolean;
|
|
69
42
|
}
|
|
@@ -311,4 +284,4 @@ declare function useSilgiCLI(): SilgiCLI;
|
|
|
311
284
|
*/
|
|
312
285
|
declare function tryUseSilgiCLI(): SilgiCLI | null;
|
|
313
286
|
|
|
314
|
-
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus,
|
|
287
|
+
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -37,33 +37,6 @@ type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
|
37
37
|
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
38
38
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
39
39
|
|
|
40
|
-
interface Options {
|
|
41
|
-
debug?: boolean;
|
|
42
|
-
}
|
|
43
|
-
interface DataType {
|
|
44
|
-
exportName: string;
|
|
45
|
-
options: {
|
|
46
|
-
type: boolean;
|
|
47
|
-
pluginName?: string;
|
|
48
|
-
};
|
|
49
|
-
path: string;
|
|
50
|
-
}
|
|
51
|
-
declare class SchemaParser {
|
|
52
|
-
options: Options;
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
constructor(options?: Options);
|
|
57
|
-
parseExports(content: string, filePath: string): {
|
|
58
|
-
exportVariables: (search: string, path: string) => DataType[];
|
|
59
|
-
parseInterfaceDeclarations: (search: string, path: string) => DataType[];
|
|
60
|
-
};
|
|
61
|
-
private parseVariableDeclaration;
|
|
62
|
-
private parseTSInterfaceDeclaration;
|
|
63
|
-
private parseTypeDeclarations;
|
|
64
|
-
private parseInterfaceDeclarations;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
40
|
interface RouteTemplateValidator {
|
|
68
41
|
(value: string): boolean;
|
|
69
42
|
}
|
|
@@ -311,4 +284,4 @@ declare function useSilgiCLI(): SilgiCLI;
|
|
|
311
284
|
*/
|
|
312
285
|
declare function tryUseSilgiCLI(): SilgiCLI | null;
|
|
313
286
|
|
|
314
|
-
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus,
|
|
287
|
+
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
|
package/dist/core/index.mjs
CHANGED
|
@@ -9,8 +9,6 @@ import { Buffer } from 'node:buffer';
|
|
|
9
9
|
import { klona } from 'klona';
|
|
10
10
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
11
11
|
import memoryDriver from 'unstorage/drivers/memory';
|
|
12
|
-
import { writeFileSync } from 'node:fs';
|
|
13
|
-
import { parseSync } from '@oxc-parser/wasm';
|
|
14
12
|
|
|
15
13
|
const common = defineUntypedSchema({
|
|
16
14
|
/**
|
|
@@ -648,138 +646,6 @@ function fillPath(path, params) {
|
|
|
648
646
|
return result;
|
|
649
647
|
}
|
|
650
648
|
|
|
651
|
-
class SchemaParser {
|
|
652
|
-
options = {
|
|
653
|
-
debug: false
|
|
654
|
-
};
|
|
655
|
-
/**
|
|
656
|
-
*
|
|
657
|
-
*/
|
|
658
|
-
constructor(options) {
|
|
659
|
-
this.options = {
|
|
660
|
-
...this.options,
|
|
661
|
-
...options
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
parseExports(content, filePath) {
|
|
665
|
-
const ast = parseSync(content, { sourceType: "module", sourceFilename: filePath });
|
|
666
|
-
if (this.options.debug)
|
|
667
|
-
writeFileSync(`${filePath}.ast.json`, JSON.stringify(ast.program, null, 2));
|
|
668
|
-
return {
|
|
669
|
-
exportVariables: (search, path) => this.parseTypeDeclarations(ast, search, path),
|
|
670
|
-
parseInterfaceDeclarations: (search, path) => this.parseInterfaceDeclarations(ast, search, path)
|
|
671
|
-
// parsePlugin: (path: string) => this.parsePlugin(ast, path),
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
parseVariableDeclaration(ast) {
|
|
675
|
-
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
|
|
676
|
-
}
|
|
677
|
-
parseTSInterfaceDeclaration(ast) {
|
|
678
|
-
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
|
|
679
|
-
}
|
|
680
|
-
parseTypeDeclarations(ast, find = "", path = "") {
|
|
681
|
-
const data = [];
|
|
682
|
-
for (const item of this.parseVariableDeclaration(ast)) {
|
|
683
|
-
for (const declaration of item.declaration.declarations) {
|
|
684
|
-
if (declaration.init?.callee?.name === find) {
|
|
685
|
-
const options = {};
|
|
686
|
-
if (declaration.init.arguments) {
|
|
687
|
-
for (const argument of declaration.init.arguments) {
|
|
688
|
-
for (const propertie of argument.properties) {
|
|
689
|
-
if (propertie.key.name === "name")
|
|
690
|
-
options.pluginName = propertie.value.value;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
for (const key in declaration.init.properties) {
|
|
695
|
-
const property = declaration.init.properties[key];
|
|
696
|
-
if (property.type === "ObjectProperty") {
|
|
697
|
-
if (property.key.name === "options") {
|
|
698
|
-
for (const key2 in property.value.properties) {
|
|
699
|
-
const option = property.value.properties[key2];
|
|
700
|
-
if (option.type === "ObjectProperty") {
|
|
701
|
-
options[option.key.name] = option.value.value;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
options.type = false;
|
|
708
|
-
data.push({
|
|
709
|
-
exportName: declaration.id.name,
|
|
710
|
-
options,
|
|
711
|
-
// object: declaration.init,
|
|
712
|
-
path
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return data;
|
|
718
|
-
}
|
|
719
|
-
parseInterfaceDeclarations(ast, find = "", path = "") {
|
|
720
|
-
const data = [];
|
|
721
|
-
for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
722
|
-
if (!item?.declaration?.extends)
|
|
723
|
-
continue;
|
|
724
|
-
for (const declaration of item?.declaration?.extends) {
|
|
725
|
-
if (declaration.expression.name === find) {
|
|
726
|
-
const options = {};
|
|
727
|
-
options.type = true;
|
|
728
|
-
data.push({
|
|
729
|
-
exportName: item.declaration.id.name,
|
|
730
|
-
options,
|
|
731
|
-
// object: declaration.init,
|
|
732
|
-
path
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return data;
|
|
738
|
-
}
|
|
739
|
-
// private parsePlugin(ast: any, path: string = '') {
|
|
740
|
-
// const data = {
|
|
741
|
-
// export: [],
|
|
742
|
-
// name: '',
|
|
743
|
-
// path: '',
|
|
744
|
-
// } as DataTypePlugin
|
|
745
|
-
// for (const item of this.parseVariableDeclaration(ast)) {
|
|
746
|
-
// for (const declaration of item.declaration.declarations) {
|
|
747
|
-
// if (declaration.init.callee?.name === 'defineSilgiModule') {
|
|
748
|
-
// if (declaration.init.arguments) {
|
|
749
|
-
// for (const argument of declaration.init.arguments) {
|
|
750
|
-
// for (const propertie of argument.properties) {
|
|
751
|
-
// if (propertie.key.name === 'name')
|
|
752
|
-
// data.name = propertie.value.value
|
|
753
|
-
// }
|
|
754
|
-
// }
|
|
755
|
-
// }
|
|
756
|
-
// data.export.push({
|
|
757
|
-
// name: data.name,
|
|
758
|
-
// as: camelCase(`${data.name}DefineSilgiModule`),
|
|
759
|
-
// type: false,
|
|
760
|
-
// })
|
|
761
|
-
// }
|
|
762
|
-
// }
|
|
763
|
-
// }
|
|
764
|
-
// for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
765
|
-
// if (!item?.declaration?.extends)
|
|
766
|
-
// continue
|
|
767
|
-
// for (const declaration of item?.declaration?.extends) {
|
|
768
|
-
// if (declaration.expression.name === 'ModuleOptions') {
|
|
769
|
-
// data.export.push({
|
|
770
|
-
// name: item.declaration.id.name,
|
|
771
|
-
// as: camelCase(`${data.name}ModuleOptions`),
|
|
772
|
-
// type: true,
|
|
773
|
-
// })
|
|
774
|
-
// }
|
|
775
|
-
// // TODO add other plugins
|
|
776
|
-
// }
|
|
777
|
-
// }
|
|
778
|
-
// data.path = path
|
|
779
|
-
// return data
|
|
780
|
-
// }
|
|
781
|
-
}
|
|
782
|
-
|
|
783
649
|
function silgi(event) {
|
|
784
650
|
return {
|
|
785
651
|
execute: (uriString, input) => {
|
|
@@ -940,4 +806,4 @@ function tryUseSilgiCLI() {
|
|
|
940
806
|
return silgiCLICtx.tryUse();
|
|
941
807
|
}
|
|
942
808
|
|
|
943
|
-
export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus,
|
|
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 };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED